annotate gcc/attribs.h @ 145:1830386684a0

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