]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/attribs.h
[Ada] Fix small oversight in latest change for Replace_Discriminants
[thirdparty/gcc.git] / gcc / attribs.h
CommitLineData
d8a2d370 1/* Declarations and definitions dealing with attribute handling.
8d9254fc 2 Copyright (C) 2013-2020 Free Software Foundation, Inc.
d8a2d370
DN
3
4This file is part of GCC.
5
6GCC is free software; you can redistribute it and/or modify it under
7the terms of the GNU General Public License as published by the Free
8Software Foundation; either version 3, or (at your option) any later
9version.
10
11GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12WARRANTY; without even the implied warranty of MERCHANTABILITY or
13FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14for more details.
15
16You should have received a copy of the GNU General Public License
17along 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
23extern const struct attribute_spec *lookup_attribute_spec (const_tree);
24extern 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). */
5d9ae53d 34extern tree decl_attributes (tree *, tree, int, tree = NULL_TREE);
d8a2d370
DN
35
36extern bool cxx11_attribute_p (const_tree);
37extern tree get_attribute_name (const_tree);
1bf32c11 38extern tree get_attribute_namespace (const_tree);
d8a2d370 39extern void apply_tm_attr (tree, tree);
3b1661a9 40extern tree make_attribute (const char *, const char *, tree);
d8a2d370 41
d067e05f
JM
42extern struct scoped_attributes* register_scoped_attributes (const struct attribute_spec *,
43 const char *);
44
1b062c1a
MM
45extern char *sorted_attr_string (tree);
46extern bool common_function_versions (tree, tree);
47extern char *make_unique_name (tree, const char *, bool);
48extern tree make_dispatcher_decl (const tree);
49extern bool is_function_default_version (const tree);
50
314e6352
ML
51/* Return a type like TTYPE except that its TYPE_ATTRIBUTES
52 is ATTRIBUTE.
53
54 Such modified types already made are recorded so that duplicates
55 are not made. */
56
57extern tree build_type_attribute_variant (tree, tree);
58extern tree build_decl_attribute_variant (tree, tree);
59extern tree build_type_attribute_qual_variant (tree, tree, int);
60
61extern bool attribute_value_equal (const_tree, const_tree);
62
63/* Return 0 if the attributes for two types are incompatible, 1 if they
64 are compatible, and 2 if they are nearly compatible (which causes a
65 warning to be generated). */
66extern int comp_type_attributes (const_tree, const_tree);
67
68/* Default versions of target-overridable functions. */
69extern tree merge_decl_attributes (tree, tree);
70extern tree merge_type_attributes (tree, tree);
71
72/* Remove any instances of attribute ATTR_NAME in LIST and return the
73 modified list. */
74
75extern tree remove_attribute (const char *, tree);
76
77/* Given two attributes lists, return a list of their union. */
78
79extern tree merge_attributes (tree, tree);
80
bc1a75dd
JJ
81/* Duplicate all attributes with name NAME in ATTR list to *ATTRS if
82 they are missing there. */
83
84extern void duplicate_one_attribute (tree *, tree, const char *);
85
86/* Duplicate all attributes from user DECL to the corresponding
87 builtin that should be propagated. */
88
89extern void copy_attributes_to_builtin (tree);
90
314e6352
ML
91/* Given two Windows decl attributes lists, possibly including
92 dllimport, return a list of their union . */
93extern tree merge_dllimport_decl_attributes (tree, tree);
94
95/* Handle a "dllimport" or "dllexport" attribute. */
96extern tree handle_dll_attribute (tree *, tree, tree, int, bool *);
97
98extern int attribute_list_equal (const_tree, const_tree);
99extern int attribute_list_contained (const_tree, const_tree);
100
13bdca74
ML
101/* The backbone of lookup_attribute(). ATTR_LEN is the string length
102 of ATTR_NAME, and LIST is not NULL_TREE.
103
104 The function is called from lookup_attribute in order to optimize
105 for size. */
106extern tree private_lookup_attribute (const char *attr_name, size_t attr_len,
107 tree list);
108
79a2c428
MS
109extern unsigned decls_mismatched_attributes (tree, tree, tree,
110 const char* const[],
111 pretty_printer*);
112
113extern void maybe_diag_alias_attributes (tree, tree);
114
577eec56
ML
115/* For a given IDENTIFIER_NODE, strip leading and trailing '_' characters
116 so that we have a canonical form of attribute names. */
117
118static inline tree
119canonicalize_attr_name (tree attr_name)
120{
121 const size_t l = IDENTIFIER_LENGTH (attr_name);
122 const char *s = IDENTIFIER_POINTER (attr_name);
123
124 if (l > 4 && s[0] == '_' && s[1] == '_' && s[l - 1] == '_' && s[l - 2] == '_')
125 return get_identifier_with_length (s + 2, l - 4);
126
127 return attr_name;
128}
129
130/* Compare attribute identifiers ATTR1 and ATTR2 with length ATTR1_LEN and
131 ATTR2_LEN. */
132
133static inline bool
134cmp_attribs (const char *attr1, size_t attr1_len,
135 const char *attr2, size_t attr2_len)
136{
137 return attr1_len == attr2_len && strncmp (attr1, attr2, attr1_len) == 0;
138}
139
140/* Compare attribute identifiers ATTR1 and ATTR2. */
141
142static inline bool
143cmp_attribs (const char *attr1, const char *attr2)
144{
145 return cmp_attribs (attr1, strlen (attr1), attr2, strlen (attr2));
146}
147
148/* Given an identifier node IDENT and a string ATTR_NAME, return true
149 if the identifier node is a valid attribute name for the string. */
150
151static inline bool
152is_attribute_p (const char *attr_name, const_tree ident)
153{
154 return cmp_attribs (attr_name, strlen (attr_name),
155 IDENTIFIER_POINTER (ident), IDENTIFIER_LENGTH (ident));
156}
157
314e6352
ML
158/* Given an attribute name ATTR_NAME and a list of attributes LIST,
159 return a pointer to the attribute's list element if the attribute
160 is part of the list, or NULL_TREE if not found. If the attribute
161 appears more than once, this only returns the first occurrence; the
162 TREE_CHAIN of the return value should be passed back in if further
163 occurrences are wanted. ATTR_NAME must be in the form 'text' (not
164 '__text__'). */
165
166static inline tree
167lookup_attribute (const char *attr_name, tree list)
168{
169 gcc_checking_assert (attr_name[0] != '_');
170 /* In most cases, list is NULL_TREE. */
171 if (list == NULL_TREE)
172 return NULL_TREE;
173 else
174 {
175 size_t attr_len = strlen (attr_name);
176 /* Do the strlen() before calling the out-of-line implementation.
177 In most cases attr_name is a string constant, and the compiler
178 will optimize the strlen() away. */
13bdca74 179 return private_lookup_attribute (attr_name, attr_len, list);
314e6352
ML
180 }
181}
182
183/* Given an attribute name ATTR_NAME and a list of attributes LIST,
184 return a pointer to the attribute's list first element if the attribute
185 starts with ATTR_NAME. ATTR_NAME must be in the form 'text' (not
186 '__text__'). */
187
188static inline tree
189lookup_attribute_by_prefix (const char *attr_name, tree list)
190{
191 gcc_checking_assert (attr_name[0] != '_');
192 /* In most cases, list is NULL_TREE. */
193 if (list == NULL_TREE)
194 return NULL_TREE;
195 else
196 {
197 size_t attr_len = strlen (attr_name);
198 while (list)
199 {
200 size_t ident_len = IDENTIFIER_LENGTH (get_attribute_name (list));
201
202 if (attr_len > ident_len)
203 {
204 list = TREE_CHAIN (list);
205 continue;
206 }
207
208 const char *p = IDENTIFIER_POINTER (get_attribute_name (list));
209 gcc_checking_assert (attr_len == 0 || p[0] != '_');
210
211 if (strncmp (attr_name, p, attr_len) == 0)
212 break;
213
214 list = TREE_CHAIN (list);
215 }
216
217 return list;
218 }
219}
220
54aa6b58
MS
221/* Description of a function argument declared with attribute access.
222 Used as an "iterator" over all such arguments in a function declaration
223 or call. */
224
225struct attr_access
226{
227 /* The attribute pointer argument. */
228 tree ptr;
229 /* The size of the pointed-to object or NULL when not specified. */
230 tree size;
231
232 /* The zero-based number of each of the formal function arguments. */
233 unsigned ptrarg;
234 unsigned sizarg;
235
236 /* The access mode. */
237 enum access_mode { read_only, write_only, read_write };
238 access_mode mode;
239};
240
d8a2d370 241#endif // GCC_ATTRIBS_H