aboutsummaryrefslogtreecommitdiffstats
path: root/cparser/Cutil.ml
diff options
context:
space:
mode:
authorXavier Leroy <xavier.leroy@inria.fr>2017-02-06 16:53:12 +0100
committerXavier Leroy <xavier.leroy@inria.fr>2017-02-06 16:53:12 +0100
commit8ace28abf0c70ebdc423baea9ae0e8c68e0b60ed (patch)
tree43e89a45ed321081cbcaaac06165a7e62b84a34b /cparser/Cutil.ml
parent9d4bb7ec914566b3920cca3c6823515448fb65c1 (diff)
parent4afaf8c23274752c8a6067bd785e114578068702 (diff)
downloadcompcert-kvx-8ace28abf0c70ebdc423baea9ae0e8c68e0b60ed.tar.gz
compcert-kvx-8ace28abf0c70ebdc423baea9ae0e8c68e0b60ed.zip
Merge branch 'elaboration-of-attributes'
Diffstat (limited to 'cparser/Cutil.ml')
-rw-r--r--cparser/Cutil.ml38
1 files changed, 32 insertions, 6 deletions
diff --git a/cparser/Cutil.ml b/cparser/Cutil.ml
index 9f893fb0..8a59c147 100644
--- a/cparser/Cutil.ml
+++ b/cparser/Cutil.ml
@@ -37,6 +37,15 @@ module IdentMap = Map.Make(Ident)
(* Operations on attributes *)
+(* Normalize the name of an attribute, removing starting and trailing '__' *)
+
+let re_normalize_attrname = Str.regexp "^__\\(.*\\)__$"
+
+let normalize_attrname a =
+ if Str.string_match re_normalize_attrname a 0
+ then Str.matched_group 1 a
+ else a
+
(* Lists of attributes are kept sorted in increasing order *)
let rec add_attributes (al1: attributes) (al2: attributes) =
@@ -83,18 +92,35 @@ let rec remove_custom_attributes (names: string list) (al: attributes) =
| a :: tl ->
a :: remove_custom_attributes names tl
+(* Classification of attributes *)
+
+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 (* Unknown attribute *)
+
+let attr_class : (string, attribute_class) Hashtbl.t = Hashtbl.create 32
+
+let declare_attribute name cls =
+ Hashtbl.replace attr_class (normalize_attrname name) cls
+
+let declare_attributes l =
+ List.iter (fun (n,c) -> declare_attribute n c) l
+
+let class_of_attribute = function
+ | AConst | AVolatile | ARestrict | AAlignas _ -> Attr_type
+ | Attr(name, args) ->
+ try Hashtbl.find attr_class (normalize_attrname name)
+ with Not_found -> Attr_unknown
+
(* Is an attribute a ISO C standard attribute? *)
let attr_is_standard = function
| AConst | AVolatile | ARestrict -> true
| AAlignas _ | Attr _ -> false
-(* Is an attribute type-related (true) or variable-related (false)? *)
-
-let attr_is_type_related = function
- | Attr(("packed" | "__packed__"), _) -> true
- | _ -> false
-
(* Is an attribute applicable to a whole array (true) or only to
array elements (false)? *)