Skip to content

Commit

Permalink
Add enumerator attributes to parser and Cabs
Browse files Browse the repository at this point in the history
  • Loading branch information
sim642 committed Aug 2, 2024
1 parent f3f2177 commit 53872de
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/frontc/cabs.ml
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ and init_name = name * init_expression
and single_name = specifier * name


and enum_item = string * expression * cabsloc
and enum_item = string * attribute list * expression * cabsloc

(*
** Declaration definition (at toplevel)
Expand Down
6 changes: 3 additions & 3 deletions src/frontc/cabs2cil.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2675,7 +2675,7 @@ let rec doSpecList (suggestedAnonName: string) (* This string will be part of
| [A.Tenum (n, Some eil, extraAttrs)] -> (* A definition of an enum *)
let rec justNames eil = match eil with
[] -> []
| (str, expr, loc) :: eis -> str :: justNames eis
| (str, attrs, expr, loc) :: eis -> str :: justNames eis (* TODO: use attrs *)
in
let names = justNames eil in
let n' =
Expand Down Expand Up @@ -2736,11 +2736,11 @@ let rec doSpecList (suggestedAnonName: string) (* This string will be part of

and loop i = function
[] -> []
| (kname, A.NOTHING, cloc) :: rest ->
| (kname, attrs, A.NOTHING, cloc) :: rest -> (* TODO: use attrs *)
(* use the passed-in 'i' as the value, since none specified *)
processName kname i (convLoc cloc) rest

| (kname, e, cloc) :: rest ->
| (kname, attrs, e, cloc) :: rest -> (* TODO: use attrs *)
(* constant-eval 'e' to determine tag value *)
let e' = getIntConstExp e in
let e'' =
Expand Down
4 changes: 2 additions & 2 deletions src/frontc/cabsvisit.ml
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,9 @@ and childrenTypeSpecifier vis ts =
let fg' = mapNoCopy childrenFieldGroup fg in
if fg' != fg then Tunion( n, Some fg', extraAttrs) else ts
| Tenum (n, Some ei, extraAttrs) ->
let doOneEnumItem ((s, e, loc) as ei) =
let doOneEnumItem ((s, attrs, e, loc) as ei) =
let e' = visitCabsExpression vis e in
if e' != e then (s, e', loc) else ei
if e' != e then (s, attrs, e', loc) else ei (* TODO: visit attrs? *)
in
vis#vEnterScope ();
let ei' = mapNoCopy doOneEnumItem ei in
Expand Down
4 changes: 2 additions & 2 deletions src/frontc/cparser.mly
Original file line number Diff line number Diff line change
Expand Up @@ -1188,8 +1188,8 @@ enum_list: /* (* ISO 6.7.2.2 *) */
| enum_list COMMA error { $1 }
;
enumerator:
IDENT {(fst $1, NOTHING, snd $1)}
| IDENT EQ expression {(fst $1, fst $3, snd $1)}
IDENT attributes {(fst $1, $2, NOTHING, snd $1)}
| IDENT attributes EQ expression {(fst $1, $2, fst $4, snd $1)}
;


Expand Down
3 changes: 2 additions & 1 deletion src/frontc/cprint.ml
Original file line number Diff line number Diff line change
Expand Up @@ -262,10 +262,11 @@ and print_enum_items items =
indent ();
print_commas
true
(fun (id, exp, loc) -> print id;
(fun (id, attrs, exp, loc) -> print id;
if exp = NOTHING then ()
else begin
space ();
print_attributes attrs;
print "= ";
print_expression exp
end)
Expand Down

0 comments on commit 53872de

Please sign in to comment.