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/Cutil.mli | |
parent | 47c82de6010935d11c3d64f6d06c2061c34dc091 (diff) | |
download | compcert-3babd253e1d194549294c282e1b0c60097b26b07.tar.gz compcert-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/Cutil.mli')
-rw-r--r-- | cparser/Cutil.mli | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/cparser/Cutil.mli b/cparser/Cutil.mli index 4906a8a8..4e62879b 100644 --- a/cparser/Cutil.mli +++ b/cparser/Cutil.mli @@ -52,17 +52,32 @@ val erase_attributes_type : Env.t -> typ -> typ (* Erase the attributes of the given type. *) val change_attributes_type : Env.t -> (attributes -> attributes) -> typ -> typ (* Apply the given function to the top-level attributes of the given type *) -val attr_is_type_related: attribute -> bool - (* Is an attribute type-related (true) or variable-related (false)? *) -val attr_is_struct_related: attribute -> bool - (* Is an attribute related to structs, unions and enum (true) or not (false)? *) + +type attribute_class = + | Attr_name (* Attribute applies to the names being declared *) + | Attr_type (* Attribute applies to types *) + | Attr_struct (* Attribute applies to struct, union and enum *) + | Attr_function (* Attribute applies to function types and decls *) + | Attr_unknown (* Not a declared attribute *) + +val declare_attribute: string -> attribute_class -> unit +val declare_attributes: (string * attribute_class) list -> unit + (* Register the given custom attribute names with the given classes. *) +val class_of_attribute: attribute -> attribute_class + (* Return the class of the given attribute. Standard attributes + have class [Attr_type]. Custom attributes have the class that + was given to them using [declare_attribute], or [Attr_unknown] + if not declared. *) val attr_inherited_by_members: attribute -> bool (* Is an attribute of a composite inherited by members of the composite? *) + + val strip_attributes_type: typ -> attribute list -> typ (* Remove all attributes from the given type that are not contained in the list *) val strip_last_attribute: typ -> attribute option * typ (* Remove the last top level attribute and return it *) + (* Type compatibility *) type attr_handling = |