diff options
author | Xavier Leroy <xavier.leroy@inria.fr> | 2017-02-03 14:12:32 +0100 |
---|---|---|
committer | Xavier Leroy <xavier.leroy@inria.fr> | 2017-02-03 14:12:32 +0100 |
commit | 3babd253e1d194549294c282e1b0c60097b26b07 (patch) | |
tree | f6a4ed3152aafdac8474350c31a9e7a5fcdb20c6 /cparser/Elab.ml | |
parent | 47c82de6010935d11c3d64f6d06c2061c34dc091 (diff) | |
download | compcert-kvx-3babd253e1d194549294c282e1b0c60097b26b07.tar.gz compcert-kvx-3babd253e1d194549294c282e1b0c60097b26b07.zip |
Refactor the classification of attributes
Introduce Cutil.class_of_attribute to return the class of the given attribute: one among
Attr_type attribute related to types (e.g. "aligned")
Attr_struct attribute related to struct/union/enum types (e.g. "packed")
Attr_function attribute related to function types (e.g. "noreturn")
Attr_name attribute related to variable and function declarations (e.g. "section")
Attr_unknown attribute was not declared
Cutil.declare_attribute is used to associate a class to a custom attribute.
Standard attributes (const, volatile, _Alignas, etc) are Attr_type.
cfronted/C2C.ml: declare the few attributes that CompCert honors currently.
cparser/GCC.ml: a bigger list of attributes taken from GCC, for reference only.
Diffstat (limited to 'cparser/Elab.ml')
-rw-r--r-- | cparser/Elab.ml | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/cparser/Elab.ml b/cparser/Elab.ml index cc66f04b..5d2a5cfe 100644 --- a/cparser/Elab.ml +++ b/cparser/Elab.ml @@ -478,12 +478,17 @@ let typespec_rank = function (* Don't change this *) let typespec_order t1 t2 = compare (typespec_rank t1) (typespec_rank t2) (* Auxiliary for type declarator elaboration. Remove the non-type-related - attributes from the given type and return those attributes separately. *) + attributes from the given type and return those attributes separately. + If the type is a function type, keep function-related attributes + attached to the type. *) let get_nontype_attrs env ty = - let nta = - List.filter (fun a -> not (attr_is_type_related a)) - (attributes_of_type env ty) in + let to_be_removed a = + match class_of_attribute a with + | Attr_type -> false + | Attr_function -> not (is_function_type env ty) + | _ -> true in + let nta = List.filter to_be_removed (attributes_of_type env ty) in (remove_attributes_type env nta ty, nta) (* Is a specifier an anonymous struct/union in the sense of ISO C2011? *) @@ -544,7 +549,8 @@ let rec elab_specifier keep_ty ?(only = false) loc env specifier = The leftover non-struct-related attributes will be applied to the variable being defined. *) let get_struct_attrs () = - let (ta, nta) = List.partition attr_is_struct_related !attr in + let (ta, nta) = + List.partition (fun a -> class_of_attribute a = Attr_struct) !attr in attr := nta; ta in |