]>
Commit | Line | Data |
---|---|---|
f617201f | 1 | /* Data structures and function exported by the C++ Parser. |
818ab71a | 2 | Copyright (C) 2010-2016 Free Software Foundation, Inc. |
f617201f DN |
3 | |
4 | This file is part of GCC. | |
5 | ||
6 | GCC is free software; you can redistribute it and/or modify it | |
7 | under the terms of the GNU General Public License as published by | |
8 | the Free Software Foundation; either version 3, or (at your option) | |
9 | any later version. | |
10 | ||
11 | GCC is distributed in the hope that it will be useful, but | |
12 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | General Public License 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_CP_PARSER_H | |
21 | #define GCC_CP_PARSER_H | |
22 | ||
23 | #include "tree.h" | |
7b3b6ae4 | 24 | #include "cp/cp-tree.h" |
f617201f DN |
25 | #include "c-family/c-pragma.h" |
26 | ||
f617201f DN |
27 | /* A token's value and its associated deferred access checks and |
28 | qualifying scope. */ | |
29 | ||
30 | struct GTY(()) tree_check { | |
31 | /* The value associated with the token. */ | |
32 | tree value; | |
33 | /* The checks that have been associated with value. */ | |
9771b263 | 34 | vec<deferred_access_check, va_gc> *checks; |
f617201f DN |
35 | /* The token's qualifying scope (used when it is a |
36 | CPP_NESTED_NAME_SPECIFIER). */ | |
37 | tree qualifying_scope; | |
38 | }; | |
39 | ||
40 | /* A C++ token. */ | |
41 | ||
a79683d5 | 42 | struct GTY (()) cp_token { |
f617201f DN |
43 | /* The kind of token. */ |
44 | ENUM_BITFIELD (cpp_ttype) type : 8; | |
45 | /* If this token is a keyword, this value indicates which keyword. | |
46 | Otherwise, this value is RID_MAX. */ | |
47 | ENUM_BITFIELD (rid) keyword : 8; | |
48 | /* Token flags. */ | |
49 | unsigned char flags; | |
50 | /* Identifier for the pragma. */ | |
4ac93c7c | 51 | ENUM_BITFIELD (pragma_kind) pragma_kind : 8; |
f617201f DN |
52 | /* True if this token is from a context where it is implicitly extern "C" */ |
53 | BOOL_BITFIELD implicit_extern_c : 1; | |
63620197 JM |
54 | /* True if an error has already been reported for this token, such as a |
55 | CPP_NAME token that is not a keyword (i.e., for which KEYWORD is | |
56 | RID_MAX) iff this name was looked up and found to be ambiguous. */ | |
57 | BOOL_BITFIELD error_reported : 1; | |
f617201f DN |
58 | /* True for a token that has been purged. If a token is purged, |
59 | it is no longer a valid token and it should be considered | |
60 | deleted. */ | |
61 | BOOL_BITFIELD purged_p : 1; | |
62 | /* The location at which this token was found. */ | |
63 | location_t location; | |
64 | /* The value associated with this token, if any. */ | |
65 | union cp_token_value { | |
ca8e4b87 | 66 | /* Used for compound tokens such as CPP_NESTED_NAME_SPECIFIER. */ |
f617201f DN |
67 | struct tree_check* GTY((tag ("1"))) tree_check_value; |
68 | /* Use for all other tokens. */ | |
69 | tree GTY((tag ("0"))) value; | |
ca8e4b87 JM |
70 | } GTY((desc ("(%1.type == CPP_TEMPLATE_ID)" |
71 | "|| (%1.type == CPP_NESTED_NAME_SPECIFIER)" | |
72 | "|| (%1.type == CPP_DECLTYPE)"))) u; | |
a79683d5 | 73 | }; |
f617201f | 74 | |
f617201f DN |
75 | |
76 | /* We use a stack of token pointer for saving token sets. */ | |
77 | typedef struct cp_token *cp_token_position; | |
f617201f DN |
78 | |
79 | /* The cp_lexer structure represents the C++ lexer. It is responsible | |
80 | for managing the token stream from the preprocessor and supplying | |
81 | it to the parser. Tokens are never added to the cp_lexer after | |
82 | it is created. */ | |
83 | ||
a79683d5 | 84 | struct GTY (()) cp_lexer { |
f617201f DN |
85 | /* The memory allocated for the buffer. NULL if this lexer does not |
86 | own the token buffer. */ | |
9771b263 | 87 | vec<cp_token, va_gc> *buffer; |
f617201f DN |
88 | |
89 | /* A pointer just past the last available token. The tokens | |
90 | in this lexer are [buffer, last_token). */ | |
91 | cp_token_position GTY ((skip)) last_token; | |
92 | ||
93 | /* The next available token. If NEXT_TOKEN is &eof_token, then there are | |
94 | no more available tokens. */ | |
95 | cp_token_position GTY ((skip)) next_token; | |
96 | ||
97 | /* A stack indicating positions at which cp_lexer_save_tokens was | |
98 | called. The top entry is the most recent position at which we | |
99 | began saving tokens. If the stack is non-empty, we are saving | |
100 | tokens. */ | |
9771b263 | 101 | vec<cp_token_position> GTY ((skip)) saved_tokens; |
f617201f DN |
102 | |
103 | /* The next lexer in a linked list of lexers. */ | |
104 | struct cp_lexer *next; | |
105 | ||
106 | /* True if we should output debugging information. */ | |
107 | bool debugging_p; | |
108 | ||
109 | /* True if we're in the context of parsing a pragma, and should not | |
110 | increment past the end-of-line marker. */ | |
111 | bool in_pragma; | |
a79683d5 | 112 | }; |
f617201f | 113 | |
f617201f DN |
114 | |
115 | /* cp_token_cache is a range of tokens. There is no need to represent | |
116 | allocate heap memory for it, since tokens are never removed from the | |
117 | lexer's array. There is also no need for the GC to walk through | |
118 | a cp_token_cache, since everything in here is referenced through | |
119 | a lexer. */ | |
120 | ||
a79683d5 | 121 | struct GTY(()) cp_token_cache { |
f617201f DN |
122 | /* The beginning of the token range. */ |
123 | cp_token * GTY((skip)) first; | |
124 | ||
125 | /* Points immediately after the last token in the range. */ | |
126 | cp_token * GTY ((skip)) last; | |
a79683d5 | 127 | }; |
f617201f DN |
128 | |
129 | typedef cp_token_cache *cp_token_cache_ptr; | |
f617201f | 130 | |
a79683d5 | 131 | struct cp_token_ident |
f617201f DN |
132 | { |
133 | unsigned int ident_len; | |
134 | const char *ident_str; | |
135 | unsigned int before_len; | |
136 | const char *before_str; | |
137 | unsigned int after_len; | |
138 | const char *after_str; | |
139 | }; | |
140 | ||
f617201f DN |
141 | /* An entry in a queue of function arguments that require post-processing. */ |
142 | ||
a79683d5 | 143 | struct GTY(()) cp_default_arg_entry { |
f617201f DN |
144 | /* The current_class_type when we parsed this arg. */ |
145 | tree class_type; | |
146 | ||
147 | /* The function decl itself. */ | |
148 | tree decl; | |
a79683d5 | 149 | }; |
f617201f | 150 | |
f617201f | 151 | |
b15ea309 | 152 | /* An entry in a stack for member functions defined within their classes. */ |
f617201f | 153 | |
a79683d5 | 154 | struct GTY(()) cp_unparsed_functions_entry { |
f617201f DN |
155 | /* Functions with default arguments that require post-processing. |
156 | Functions appear in this list in declaration order. */ | |
9771b263 | 157 | vec<cp_default_arg_entry, va_gc> *funs_with_default_args; |
f617201f DN |
158 | |
159 | /* Functions with defintions that require post-processing. Functions | |
160 | appear in this list in declaration order. */ | |
9771b263 | 161 | vec<tree, va_gc> *funs_with_definitions; |
eb026338 JM |
162 | |
163 | /* Non-static data members with initializers that require post-processing. | |
164 | FIELD_DECLs appear in this list in declaration order. */ | |
9771b263 | 165 | vec<tree, va_gc> *nsdmis; |
b15ea309 JM |
166 | |
167 | /* Nested classes go in this vector, so that we can do some final | |
168 | processing after parsing any NSDMIs. */ | |
169 | vec<tree, va_gc> *classes; | |
a79683d5 | 170 | }; |
f617201f | 171 | |
f617201f DN |
172 | |
173 | /* The status of a tentative parse. */ | |
174 | ||
a79683d5 | 175 | enum cp_parser_status_kind |
f617201f DN |
176 | { |
177 | /* No errors have occurred. */ | |
178 | CP_PARSER_STATUS_KIND_NO_ERROR, | |
179 | /* An error has occurred. */ | |
180 | CP_PARSER_STATUS_KIND_ERROR, | |
181 | /* We are committed to this tentative parse, whether or not an error | |
182 | has occurred. */ | |
183 | CP_PARSER_STATUS_KIND_COMMITTED | |
a79683d5 | 184 | }; |
f617201f DN |
185 | |
186 | ||
187 | /* Context that is saved and restored when parsing tentatively. */ | |
a79683d5 | 188 | struct GTY (()) cp_parser_context { |
f617201f DN |
189 | /* If this is a tentative parsing context, the status of the |
190 | tentative parse. */ | |
191 | enum cp_parser_status_kind status; | |
192 | /* If non-NULL, we have just seen a `x->' or `x.' expression. Names | |
193 | that are looked up in this context must be looked up both in the | |
194 | scope given by OBJECT_TYPE (the type of `x' or `*x') and also in | |
195 | the context of the containing expression. */ | |
196 | tree object_type; | |
197 | ||
198 | /* The next parsing context in the stack. */ | |
199 | struct cp_parser_context *next; | |
a79683d5 | 200 | }; |
f617201f DN |
201 | |
202 | ||
acf0174b JJ |
203 | /* Control structure for #pragma omp declare simd parsing. */ |
204 | struct cp_omp_declare_simd_data { | |
205 | bool error_seen; /* Set if error has been reported. */ | |
206 | bool fndecl_seen; /* Set if one fn decl/definition has been seen already. */ | |
207 | vec<cp_token_cache_ptr> tokens; | |
8504d5dd | 208 | tree clauses; |
acf0174b JJ |
209 | }; |
210 | ||
211 | ||
f617201f DN |
212 | /* The cp_parser structure represents the C++ parser. */ |
213 | ||
a79683d5 | 214 | struct GTY(()) cp_parser { |
f617201f DN |
215 | /* The lexer from which we are obtaining tokens. */ |
216 | cp_lexer *lexer; | |
217 | ||
218 | /* The scope in which names should be looked up. If NULL_TREE, then | |
219 | we look up names in the scope that is currently open in the | |
220 | source program. If non-NULL, this is either a TYPE or | |
221 | NAMESPACE_DECL for the scope in which we should look. It can | |
222 | also be ERROR_MARK, when we've parsed a bogus scope. | |
223 | ||
224 | This value is not cleared automatically after a name is looked | |
225 | up, so we must be careful to clear it before starting a new look | |
226 | up sequence. (If it is not cleared, then `X::Y' followed by `Z' | |
227 | will look up `Z' in the scope of `X', rather than the current | |
228 | scope.) Unfortunately, it is difficult to tell when name lookup | |
229 | is complete, because we sometimes peek at a token, look it up, | |
230 | and then decide not to consume it. */ | |
231 | tree scope; | |
232 | ||
233 | /* OBJECT_SCOPE and QUALIFYING_SCOPE give the scopes in which the | |
234 | last lookup took place. OBJECT_SCOPE is used if an expression | |
235 | like "x->y" or "x.y" was used; it gives the type of "*x" or "x", | |
236 | respectively. QUALIFYING_SCOPE is used for an expression of the | |
237 | form "X::Y"; it refers to X. */ | |
238 | tree object_scope; | |
239 | tree qualifying_scope; | |
240 | ||
241 | /* A stack of parsing contexts. All but the bottom entry on the | |
242 | stack will be tentative contexts. | |
243 | ||
244 | We parse tentatively in order to determine which construct is in | |
245 | use in some situations. For example, in order to determine | |
246 | whether a statement is an expression-statement or a | |
247 | declaration-statement we parse it tentatively as a | |
248 | declaration-statement. If that fails, we then reparse the same | |
249 | token stream as an expression-statement. */ | |
250 | cp_parser_context *context; | |
251 | ||
252 | /* True if we are parsing GNU C++. If this flag is not set, then | |
253 | GNU extensions are not recognized. */ | |
254 | bool allow_gnu_extensions_p; | |
255 | ||
256 | /* TRUE if the `>' token should be interpreted as the greater-than | |
257 | operator. FALSE if it is the end of a template-id or | |
258 | template-parameter-list. In C++0x mode, this flag also applies to | |
259 | `>>' tokens, which are viewed as two consecutive `>' tokens when | |
260 | this flag is FALSE. */ | |
261 | bool greater_than_is_operator_p; | |
262 | ||
263 | /* TRUE if default arguments are allowed within a parameter list | |
264 | that starts at this point. FALSE if only a gnu extension makes | |
265 | them permissible. */ | |
266 | bool default_arg_ok_p; | |
267 | ||
268 | /* TRUE if we are parsing an integral constant-expression. See | |
269 | [expr.const] for a precise definition. */ | |
270 | bool integral_constant_expression_p; | |
271 | ||
272 | /* TRUE if we are parsing an integral constant-expression -- but a | |
273 | non-constant expression should be permitted as well. This flag | |
274 | is used when parsing an array bound so that GNU variable-length | |
275 | arrays are tolerated. */ | |
276 | bool allow_non_integral_constant_expression_p; | |
277 | ||
278 | /* TRUE if ALLOW_NON_CONSTANT_EXPRESSION_P is TRUE and something has | |
279 | been seen that makes the expression non-constant. */ | |
280 | bool non_integral_constant_expression_p; | |
281 | ||
282 | /* TRUE if local variable names and `this' are forbidden in the | |
283 | current context. */ | |
284 | bool local_variables_forbidden_p; | |
285 | ||
286 | /* TRUE if the declaration we are parsing is part of a | |
287 | linkage-specification of the form `extern string-literal | |
288 | declaration'. */ | |
289 | bool in_unbraced_linkage_specification_p; | |
290 | ||
291 | /* TRUE if we are presently parsing a declarator, after the | |
292 | direct-declarator. */ | |
293 | bool in_declarator_p; | |
294 | ||
295 | /* TRUE if we are presently parsing a template-argument-list. */ | |
296 | bool in_template_argument_list_p; | |
297 | ||
298 | /* Set to IN_ITERATION_STMT if parsing an iteration-statement, | |
299 | to IN_OMP_BLOCK if parsing OpenMP structured block and | |
300 | IN_OMP_FOR if parsing OpenMP loop. If parsing a switch statement, | |
301 | this is bitwise ORed with IN_SWITCH_STMT, unless parsing an | |
302 | iteration-statement, OpenMP block or loop within that switch. */ | |
303 | #define IN_SWITCH_STMT 1 | |
304 | #define IN_ITERATION_STMT 2 | |
305 | #define IN_OMP_BLOCK 4 | |
306 | #define IN_OMP_FOR 8 | |
307 | #define IN_IF_STMT 16 | |
c02065fc | 308 | #define IN_CILK_SIMD_FOR 32 |
12893402 | 309 | #define IN_CILK_SPAWN 64 |
f617201f DN |
310 | unsigned char in_statement; |
311 | ||
312 | /* TRUE if we are presently parsing the body of a switch statement. | |
313 | Note that this doesn't quite overlap with in_statement above. | |
314 | The difference relates to giving the right sets of error messages: | |
315 | "case not in switch" vs "break statement used with OpenMP...". */ | |
316 | bool in_switch_statement_p; | |
317 | ||
318 | /* TRUE if we are parsing a type-id in an expression context. In | |
319 | such a situation, both "type (expr)" and "type (type)" are valid | |
320 | alternatives. */ | |
321 | bool in_type_id_in_expr_p; | |
322 | ||
323 | /* TRUE if we are currently in a header file where declarations are | |
324 | implicitly extern "C". */ | |
325 | bool implicit_extern_c; | |
326 | ||
327 | /* TRUE if strings in expressions should be translated to the execution | |
328 | character set. */ | |
329 | bool translate_strings_p; | |
330 | ||
331 | /* TRUE if we are presently parsing the body of a function, but not | |
332 | a local class. */ | |
333 | bool in_function_body; | |
0a35513e AH |
334 | |
335 | /* Nonzero if we're processing a __transaction_atomic or | |
336 | __transaction_relaxed statement. */ | |
337 | unsigned char in_transaction; | |
f617201f DN |
338 | |
339 | /* TRUE if we can auto-correct a colon to a scope operator. */ | |
340 | bool colon_corrects_to_scope_p; | |
341 | ||
acf0174b JJ |
342 | /* TRUE if : doesn't start a class definition. Should be only used |
343 | together with type_definition_forbidden_message non-NULL, in | |
344 | contexts where new types may not be defined, and the type list | |
345 | is terminated by colon. */ | |
346 | bool colon_doesnt_start_class_def_p; | |
347 | ||
f617201f DN |
348 | /* If non-NULL, then we are parsing a construct where new type |
349 | definitions are not permitted. The string stored here will be | |
350 | issued as an error message if a type is defined. */ | |
351 | const char *type_definition_forbidden_message; | |
352 | ||
353 | /* A stack used for member functions of local classes. The lists | |
354 | contained in an individual entry can only be processed once the | |
355 | outermost class being defined is complete. */ | |
9771b263 | 356 | vec<cp_unparsed_functions_entry, va_gc> *unparsed_queues; |
f617201f DN |
357 | |
358 | /* The number of classes whose definitions are currently in | |
359 | progress. */ | |
360 | unsigned num_classes_being_defined; | |
361 | ||
362 | /* The number of template parameter lists that apply directly to the | |
363 | current declaration. */ | |
364 | unsigned num_template_parameter_lists; | |
1a11a94f | 365 | |
acf0174b JJ |
366 | /* When parsing #pragma omp declare simd, this is a pointer to a |
367 | data structure with everything needed for parsing the clauses. */ | |
368 | cp_omp_declare_simd_data * GTY((skip)) omp_declare_simd; | |
369 | ||
74558dd9 BI |
370 | /* When parsing the vector attribute in Cilk Plus SIMD-enabled function, |
371 | this is a pointer to data structure with everything needed for parsing | |
372 | the clauses. The cp_omp_declare_simd_data struct will hold all the | |
373 | necessary information, so creating another struct for this is not | |
374 | necessary. */ | |
375 | cp_omp_declare_simd_data * GTY((skip)) cilk_simd_fn_info; | |
376 | ||
8504d5dd CP |
377 | /* Parsing information for #pragma acc routine. */ |
378 | cp_omp_declare_simd_data * GTY((skip)) oacc_routine; | |
3a40d81d | 379 | |
0dca5025 AB |
380 | /* Nonzero if parsing a parameter list where 'auto' should trigger an implicit |
381 | template parameter. */ | |
382 | bool auto_is_implicit_function_template_parm_p; | |
383 | ||
1a11a94f AB |
384 | /* TRUE if the function being declared was made a template due to its |
385 | parameter list containing generic type specifiers (`auto' or concept | |
386 | identifiers) rather than an explicit template parameter list. */ | |
387 | bool fully_implicit_function_template_p; | |
388 | ||
0dca5025 AB |
389 | /* Tracks the function's template parameter list when declaring a function |
390 | using generic type parameters. This is either a new chain in the case of a | |
391 | fully implicit function template or an extension of the function's existing | |
392 | template parameter list. This is tracked to optimize calls subsequent | |
393 | calls to synthesize_implicit_template_parm during | |
394 | cp_parser_parameter_declaration. */ | |
395 | tree implicit_template_parms; | |
396 | ||
397 | /* The scope into which an implicit template parameter list has been | |
398 | introduced or an existing template parameter list is being extended with | |
2ec7e902 | 399 | implicit template parameters. In most cases this is the sk_function_parms |
0dca5025 AB |
400 | scope containing the use of a generic type. In the case of an out-of-line |
401 | member definition using a generic type, it is the sk_class scope. */ | |
402 | cp_binding_level* implicit_template_scope; | |
403 | ||
971e17ff AS |
404 | /* True if parsing a result type in a compound requirement. This permits |
405 | constrained-type-specifiers inside what would normally be a trailing | |
406 | return type. */ | |
407 | bool in_result_type_constraint_p; | |
408 | ||
409 | /* True if a constrained-type-specifier is not allowed in this | |
410 | context e.g., because they could never be deduced. */ | |
411 | int prevent_constrained_type_specifiers; | |
412 | ||
a79683d5 | 413 | }; |
f617201f DN |
414 | |
415 | /* In parser.c */ | |
7b3b6ae4 LC |
416 | extern void debug (cp_token &ref); |
417 | extern void debug (cp_token *ptr); | |
9771b263 | 418 | extern void cp_lexer_debug_tokens (vec<cp_token, va_gc> *); |
7b3b6ae4 LC |
419 | extern void debug (vec<cp_token, va_gc> &ref); |
420 | extern void debug (vec<cp_token, va_gc> *ptr); | |
aa6e7237 | 421 | extern void cp_debug_parser (FILE *, cp_parser *); |
7b3b6ae4 LC |
422 | extern void debug (cp_parser &ref); |
423 | extern void debug (cp_parser *ptr); | |
f617201f DN |
424 | |
425 | #endif /* GCC_CP_PARSER_H */ |