From 3babd253e1d194549294c282e1b0c60097b26b07 Mon Sep 17 00:00:00 2001 From: Xavier Leroy Date: Fri, 3 Feb 2017 14:12:32 +0100 Subject: 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. --- cparser/Elab.ml | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'cparser/Elab.ml') 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 -- cgit