Canonicalize names of attributes.
[platform/upstream/gcc.git] / gcc / attribs.h
1 /* Declarations and definitions dealing with attribute handling.
2    Copyright (C) 2013-2017 Free Software Foundation, Inc.
3
4 This file is part of GCC.
5
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
9 version.
10
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3.  If not see
18 <http://www.gnu.org/licenses/>.  */
19
20 #ifndef GCC_ATTRIBS_H
21 #define GCC_ATTRIBS_H
22
23 extern const struct attribute_spec *lookup_attribute_spec (const_tree);
24 extern void init_attributes (void);
25
26 /* Process the attributes listed in ATTRIBUTES and install them in *NODE,
27    which is either a DECL (including a TYPE_DECL) or a TYPE.  If a DECL,
28    it should be modified in place; if a TYPE, a copy should be created
29    unless ATTR_FLAG_TYPE_IN_PLACE is set in FLAGS.  FLAGS gives further
30    information, in the form of a bitwise OR of flags in enum attribute_flags
31    from tree.h.  Depending on these flags, some attributes may be
32    returned to be applied at a later stage (for example, to apply
33    a decl attribute to the declaration rather than to its type).  */
34 extern tree decl_attributes (tree *, tree, int);
35
36 extern bool cxx11_attribute_p (const_tree);
37 extern tree get_attribute_name (const_tree);
38 extern void apply_tm_attr (tree, tree);
39 extern tree make_attribute (const char *, const char *, tree);
40
41 extern struct scoped_attributes* register_scoped_attributes (const struct attribute_spec *,
42                                                              const char *);
43
44 extern char *sorted_attr_string (tree);
45 extern bool common_function_versions (tree, tree);
46 extern char *make_unique_name (tree, const char *, bool);
47 extern tree make_dispatcher_decl (const tree);
48 extern bool is_function_default_version (const tree);
49
50 /* For a given IDENTIFIER_NODE, strip leading and trailing '_' characters
51    so that we have a canonical form of attribute names.  */
52
53 static inline tree
54 canonicalize_attr_name (tree attr_name)
55 {
56   const size_t l = IDENTIFIER_LENGTH (attr_name);
57   const char *s = IDENTIFIER_POINTER (attr_name);
58
59   if (l > 4 && s[0] == '_' && s[1] == '_' && s[l - 1] == '_' && s[l - 2] == '_')
60     return get_identifier_with_length (s + 2, l - 4);
61
62   return attr_name;
63 }
64
65 /* Compare attribute identifiers ATTR1 and ATTR2 with length ATTR1_LEN and
66    ATTR2_LEN.  */
67
68 static inline bool
69 cmp_attribs (const char *attr1, size_t attr1_len,
70              const char *attr2, size_t attr2_len)
71 {
72   return attr1_len == attr2_len && strncmp (attr1, attr2, attr1_len) == 0;
73 }
74
75 /* Compare attribute identifiers ATTR1 and ATTR2.  */
76
77 static inline bool
78 cmp_attribs (const char *attr1, const char *attr2)
79 {
80   return cmp_attribs (attr1, strlen (attr1), attr2, strlen (attr2));
81 }
82
83 /* Given an identifier node IDENT and a string ATTR_NAME, return true
84    if the identifier node is a valid attribute name for the string.  */
85
86 static inline bool
87 is_attribute_p (const char *attr_name, const_tree ident)
88 {
89   return cmp_attribs (attr_name, strlen (attr_name),
90                       IDENTIFIER_POINTER (ident), IDENTIFIER_LENGTH (ident));
91 }
92
93 #endif // GCC_ATTRIBS_H