diff --git a/src/check.ml b/src/check.ml index 06a030223..1fc37396f 100644 --- a/src/check.ml +++ b/src/check.ml @@ -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 = diff --git a/src/cil.ml b/src/cil.ml index 53bed82eb..b40466fe8 100755 --- a/src/cil.ml +++ b/src/cil.ml @@ -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 @@ -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 "} " @@ -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 diff --git a/src/cil.mli b/src/cil.mli index 4464d4c20..d63e5535f 100644 --- a/src/cil.mli +++ b/src/cil.mli @@ -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; diff --git a/src/ext/zrapp/zrapp.ml b/src/ext/zrapp/zrapp.ml index a1fd7e498..bd3fef444 100644 --- a/src/ext/zrapp/zrapp.ml +++ b/src/ext/zrapp/zrapp.ml @@ -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" diff --git a/src/frontc/cabs2cil.ml b/src/frontc/cabs2cil.ml index 686acb5e4..707612f6b 100644 --- a/src/frontc/cabs2cil.ml +++ b/src/frontc/cabs2cil.ml @@ -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' = @@ -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 *) @@ -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'' = @@ -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 diff --git a/src/mergecil.ml b/src/mergecil.ml index 028649c7b..04801c0f9 100644 --- a/src/mergecil.ml +++ b/src/mergecil.ml @@ -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 = @@ -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', _) ->