Skip to content

Commit

Permalink
Add enumerator attributes to CIL
Browse files Browse the repository at this point in the history
  • Loading branch information
sim642 committed Aug 2, 2024
1 parent 53872de commit ead4987
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/check.ml
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ and checkEnumInfo (isadef: defuse) enum =
(* Add it to the map before we go on *)
H.add enumUsed enum.ename (enum, ref isadef);
checkAttributes enum.eattr;
List.iter (fun (tn, _, _) -> defineName tn) enum.eitems;
List.iter (fun (tn, attrs, _, _) -> defineName tn; checkAttributes attrs) enum.eitems;
end

and checkTypeInfo (isadef: defuse) ti =
Expand Down
10 changes: 6 additions & 4 deletions src/cil.ml
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ and fieldinfo = {
enumeration. Make sure you have a [GEnumTag] for each of of these. *)
and enuminfo = {
mutable ename: string; (** The name. Always non-empty *)
mutable eitems: (string * exp * location) list; (** Items with names
mutable eitems: (string * attributes * exp * location) list; (** Items with names
and values. This list
should be
non-empty. The item
Expand Down Expand Up @@ -4014,8 +4014,10 @@ class defaultCilPrinterClass : cilPrinter = object (self)
text "enum" ++ align ++ text (" " ^ enum.ename) ++
text " {" ++ line
++ (docList ~sep:(chr ',' ++ line)
(fun (n,i, loc) ->
text (n ^ " = ")
(fun (n, attrs, i, loc) ->
text n
++ self#pAttrs () attrs
++ text (n ^ " = ")
++ self#pExp () i)
() enum.eitems)
++ unalign ++ line ++ text "} "
Expand Down Expand Up @@ -5622,7 +5624,7 @@ and childrenGlobal (vis: cilVisitor) (g: global) : global =
| GEnumTag (enum, _) ->
(* (trace "visit" (dprintf "visiting global enum %s\n" enum.ename)); *)
(* Do the values and attributes of the enumerated items *)
let itemVisit (name, exp, loc) = (name, visitCilExpr vis exp, loc) in
let itemVisit (name, attrs, exp, loc) = (name, visitCilAttributes vis attrs, visitCilExpr vis exp, loc) in
enum.eitems <- mapNoCopy itemVisit enum.eitems;
enum.eattr <- visitCilAttributes vis enum.eattr;
g
Expand Down
2 changes: 1 addition & 1 deletion src/cil.mli
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ and fieldinfo = {
and enuminfo = {
mutable ename: string;
(** The name. Always non-empty. *)
mutable eitems: (string * exp * location) list;
mutable eitems: (string * attributes * exp * location) list;
(** Items with names and values. This list should be non-empty. The item
values must be compile-time constants. *)
mutable eattr: attributes;
Expand Down
6 changes: 4 additions & 2 deletions src/ext/zrapp/zrapp.ml
Original file line number Diff line number Diff line change
Expand Up @@ -412,8 +412,10 @@ class zraCilPrinterClass : cilPrinter = object (self)
text "enum" ++ align ++ text (" " ^ enum.ename) ++
self#pAttrs () enum.eattr ++ text " {" ++ line
++ (docList ~sep:(chr ',' ++ line)
(fun (n,i, loc) ->
text (n ^ " = ")
(fun (n, attrs, i, loc) ->
text n
++ self#pAttrs () attrs
++ text (n ^ " = ")
++ self#pExp () i)
() enum.eitems)
++ unalign ++ line ++ text "};\n"
Expand Down
14 changes: 7 additions & 7 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, attrs, expr, loc) :: eis -> str :: justNames eis (* TODO: use attrs *)
| (str, attrs, expr, loc) :: eis -> str :: justNames eis
in
let names = justNames eil in
let n' =
Expand Down Expand Up @@ -2721,7 +2721,7 @@ let rec doSpecList (suggestedAnonName: string) (* This string will be part of
else IULongLong (* assume there can be not enum constants that don't fit in long long since there can only be 128bit constants if long long is also 128bit *)
in
(* as each name,value pair is determined, this is called *)
let rec processName kname (i: exp) loc rest = begin
let rec processName kname attrs (i: exp) loc rest = begin
(* add the name to the environment, but with a faked 'typ' field;
we don't know the full type yet (since that includes all of the
tag values), but we won't need them in here *)
Expand All @@ -2731,16 +2731,16 @@ let rec doSpecList (suggestedAnonName: string) (* This string will be part of
environment when we're finished *)
let newname, _ = newAlphaName true "" kname in

(kname, (newname, i, loc)) :: loop (increm i 1) rest
(kname, (newname, doAttributes attrs, i, loc)) :: loop (increm i 1) rest
end

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

| (kname, attrs, e, cloc) :: rest -> (* TODO: use attrs *)
| (kname, attrs, e, cloc) :: rest ->
(* constant-eval 'e' to determine tag value *)
let e' = getIntConstExp e in
let e'' =
Expand All @@ -2750,7 +2750,7 @@ let rec doSpecList (suggestedAnonName: string) (* This string will be part of
if !lowerConstants then kintegerCilint ik n else e'
| _ -> E.s (error "Constant initializer %a not an integer" d_exp e')
in
processName kname e'' (convLoc cloc) rest
processName kname attrs e'' (convLoc cloc) rest
in

let fields = loop zero eil in
Expand Down
6 changes: 3 additions & 3 deletions src/mergecil.ml
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@
(* We check that they are defined in the same way. This is a fairly
conservative check. *)
List.iter2
(fun (old_iname, old_iv, _) (iname, iv, _) ->
(fun (old_iname, old_attrs, old_iv, _) (iname, attrs, iv, _) -> (* TODO: combine attributes somewhere? *)
if old_iname <> iname then
raise (Failure "(different names for enumeration items)");
let samev =
Expand Down Expand Up @@ -1545,12 +1545,12 @@
as the variables *)
ei.eitems <-
Util.list_map
(fun (n, i, loc) ->
(fun (n, attrs, i, loc) ->
let newname, _ =
A.newAlphaName ~alphaTable:vtAlpha ~undolist:None
~lookupname:n ~data:!currentLoc
in
(newname, i, loc))
(newname, attrs, i, loc))
ei.eitems;
mergePushGlobals (visitCilGlobal renameVisitor g)
| Some (ei', _) ->
Expand Down

0 comments on commit ead4987

Please sign in to comment.