[AArch64, ARM] Introduce "mrs" type attribute.
[official-gcc.git] / gcc / cp / parser.h
blob3d8bb742d221c4bf3814257ac9adb9f81ba8eedd
1 /* Data structures and function exported by the C++ Parser.
2 Copyright (C) 2010-2013 Free Software Foundation, Inc.
4 This file is part of GCC.
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.
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.
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/>. */
20 #ifndef GCC_CP_PARSER_H
21 #define GCC_CP_PARSER_H
23 #include "tree.h"
24 #include "cp/cp-tree.h"
25 #include "c-family/c-pragma.h"
27 /* A token's value and its associated deferred access checks and
28 qualifying scope. */
30 struct GTY(()) tree_check {
31 /* The value associated with the token. */
32 tree value;
33 /* The checks that have been associated with value. */
34 vec<deferred_access_check, va_gc> *checks;
35 /* The token's qualifying scope (used when it is a
36 CPP_NESTED_NAME_SPECIFIER). */
37 tree qualifying_scope;
40 /* A C++ token. */
42 typedef struct GTY (()) cp_token {
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. */
51 ENUM_BITFIELD (pragma_kind) pragma_kind : 6;
52 /* True if this token is from a context where it is implicitly extern "C" */
53 BOOL_BITFIELD implicit_extern_c : 1;
54 /* True for a CPP_NAME token that is not a keyword (i.e., for which
55 KEYWORD is RID_MAX) iff this name was looked up and found to be
56 ambiguous. An error has already been reported. */
57 BOOL_BITFIELD ambiguous_p : 1;
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 {
66 /* Used for CPP_NESTED_NAME_SPECIFIER and CPP_TEMPLATE_ID. */
67 struct tree_check* GTY((tag ("1"))) tree_check_value;
68 /* Use for all other tokens. */
69 tree GTY((tag ("0"))) value;
70 } GTY((desc ("(%1.type == CPP_TEMPLATE_ID) || (%1.type == CPP_NESTED_NAME_SPECIFIER)"))) u;
71 } cp_token;
74 /* We use a stack of token pointer for saving token sets. */
75 typedef struct cp_token *cp_token_position;
77 /* The cp_lexer structure represents the C++ lexer. It is responsible
78 for managing the token stream from the preprocessor and supplying
79 it to the parser. Tokens are never added to the cp_lexer after
80 it is created. */
82 typedef struct GTY (()) cp_lexer {
83 /* The memory allocated for the buffer. NULL if this lexer does not
84 own the token buffer. */
85 vec<cp_token, va_gc> *buffer;
87 /* A pointer just past the last available token. The tokens
88 in this lexer are [buffer, last_token). */
89 cp_token_position GTY ((skip)) last_token;
91 /* The next available token. If NEXT_TOKEN is &eof_token, then there are
92 no more available tokens. */
93 cp_token_position GTY ((skip)) next_token;
95 /* A stack indicating positions at which cp_lexer_save_tokens was
96 called. The top entry is the most recent position at which we
97 began saving tokens. If the stack is non-empty, we are saving
98 tokens. */
99 vec<cp_token_position> GTY ((skip)) saved_tokens;
101 /* The next lexer in a linked list of lexers. */
102 struct cp_lexer *next;
104 /* True if we should output debugging information. */
105 bool debugging_p;
107 /* True if we're in the context of parsing a pragma, and should not
108 increment past the end-of-line marker. */
109 bool in_pragma;
110 } cp_lexer;
113 /* cp_token_cache is a range of tokens. There is no need to represent
114 allocate heap memory for it, since tokens are never removed from the
115 lexer's array. There is also no need for the GC to walk through
116 a cp_token_cache, since everything in here is referenced through
117 a lexer. */
119 typedef struct GTY(()) cp_token_cache {
120 /* The beginning of the token range. */
121 cp_token * GTY((skip)) first;
123 /* Points immediately after the last token in the range. */
124 cp_token * GTY ((skip)) last;
125 } cp_token_cache;
127 typedef cp_token_cache *cp_token_cache_ptr;
129 struct cp_token_ident_d
131 unsigned int ident_len;
132 const char *ident_str;
133 unsigned int before_len;
134 const char *before_str;
135 unsigned int after_len;
136 const char *after_str;
139 typedef struct cp_token_ident_d cp_token_ident;
141 /* An entry in a queue of function arguments that require post-processing. */
143 typedef struct GTY(()) cp_default_arg_entry_d {
144 /* The current_class_type when we parsed this arg. */
145 tree class_type;
147 /* The function decl itself. */
148 tree decl;
149 } cp_default_arg_entry;
152 /* An entry in a stack for member functions of local classes. */
154 typedef struct GTY(()) cp_unparsed_functions_entry_d {
155 /* Functions with default arguments that require post-processing.
156 Functions appear in this list in declaration order. */
157 vec<cp_default_arg_entry, va_gc> *funs_with_default_args;
159 /* Functions with defintions that require post-processing. Functions
160 appear in this list in declaration order. */
161 vec<tree, va_gc> *funs_with_definitions;
163 /* Non-static data members with initializers that require post-processing.
164 FIELD_DECLs appear in this list in declaration order. */
165 vec<tree, va_gc> *nsdmis;
166 } cp_unparsed_functions_entry;
169 /* The status of a tentative parse. */
171 typedef enum cp_parser_status_kind
173 /* No errors have occurred. */
174 CP_PARSER_STATUS_KIND_NO_ERROR,
175 /* An error has occurred. */
176 CP_PARSER_STATUS_KIND_ERROR,
177 /* We are committed to this tentative parse, whether or not an error
178 has occurred. */
179 CP_PARSER_STATUS_KIND_COMMITTED
180 } cp_parser_status_kind;
183 /* Context that is saved and restored when parsing tentatively. */
184 typedef struct GTY (()) cp_parser_context {
185 /* If this is a tentative parsing context, the status of the
186 tentative parse. */
187 enum cp_parser_status_kind status;
188 /* If non-NULL, we have just seen a `x->' or `x.' expression. Names
189 that are looked up in this context must be looked up both in the
190 scope given by OBJECT_TYPE (the type of `x' or `*x') and also in
191 the context of the containing expression. */
192 tree object_type;
194 /* The next parsing context in the stack. */
195 struct cp_parser_context *next;
196 } cp_parser_context;
199 /* The cp_parser structure represents the C++ parser. */
201 typedef struct GTY(()) cp_parser {
202 /* The lexer from which we are obtaining tokens. */
203 cp_lexer *lexer;
205 /* The scope in which names should be looked up. If NULL_TREE, then
206 we look up names in the scope that is currently open in the
207 source program. If non-NULL, this is either a TYPE or
208 NAMESPACE_DECL for the scope in which we should look. It can
209 also be ERROR_MARK, when we've parsed a bogus scope.
211 This value is not cleared automatically after a name is looked
212 up, so we must be careful to clear it before starting a new look
213 up sequence. (If it is not cleared, then `X::Y' followed by `Z'
214 will look up `Z' in the scope of `X', rather than the current
215 scope.) Unfortunately, it is difficult to tell when name lookup
216 is complete, because we sometimes peek at a token, look it up,
217 and then decide not to consume it. */
218 tree scope;
220 /* OBJECT_SCOPE and QUALIFYING_SCOPE give the scopes in which the
221 last lookup took place. OBJECT_SCOPE is used if an expression
222 like "x->y" or "x.y" was used; it gives the type of "*x" or "x",
223 respectively. QUALIFYING_SCOPE is used for an expression of the
224 form "X::Y"; it refers to X. */
225 tree object_scope;
226 tree qualifying_scope;
228 /* A stack of parsing contexts. All but the bottom entry on the
229 stack will be tentative contexts.
231 We parse tentatively in order to determine which construct is in
232 use in some situations. For example, in order to determine
233 whether a statement is an expression-statement or a
234 declaration-statement we parse it tentatively as a
235 declaration-statement. If that fails, we then reparse the same
236 token stream as an expression-statement. */
237 cp_parser_context *context;
239 /* True if we are parsing GNU C++. If this flag is not set, then
240 GNU extensions are not recognized. */
241 bool allow_gnu_extensions_p;
243 /* TRUE if the `>' token should be interpreted as the greater-than
244 operator. FALSE if it is the end of a template-id or
245 template-parameter-list. In C++0x mode, this flag also applies to
246 `>>' tokens, which are viewed as two consecutive `>' tokens when
247 this flag is FALSE. */
248 bool greater_than_is_operator_p;
250 /* TRUE if default arguments are allowed within a parameter list
251 that starts at this point. FALSE if only a gnu extension makes
252 them permissible. */
253 bool default_arg_ok_p;
255 /* TRUE if we are parsing an integral constant-expression. See
256 [expr.const] for a precise definition. */
257 bool integral_constant_expression_p;
259 /* TRUE if we are parsing an integral constant-expression -- but a
260 non-constant expression should be permitted as well. This flag
261 is used when parsing an array bound so that GNU variable-length
262 arrays are tolerated. */
263 bool allow_non_integral_constant_expression_p;
265 /* TRUE if ALLOW_NON_CONSTANT_EXPRESSION_P is TRUE and something has
266 been seen that makes the expression non-constant. */
267 bool non_integral_constant_expression_p;
269 /* TRUE if local variable names and `this' are forbidden in the
270 current context. */
271 bool local_variables_forbidden_p;
273 /* TRUE if the declaration we are parsing is part of a
274 linkage-specification of the form `extern string-literal
275 declaration'. */
276 bool in_unbraced_linkage_specification_p;
278 /* TRUE if we are presently parsing a declarator, after the
279 direct-declarator. */
280 bool in_declarator_p;
282 /* TRUE if we are presently parsing a template-argument-list. */
283 bool in_template_argument_list_p;
285 /* Set to IN_ITERATION_STMT if parsing an iteration-statement,
286 to IN_OMP_BLOCK if parsing OpenMP structured block and
287 IN_OMP_FOR if parsing OpenMP loop. If parsing a switch statement,
288 this is bitwise ORed with IN_SWITCH_STMT, unless parsing an
289 iteration-statement, OpenMP block or loop within that switch. */
290 #define IN_SWITCH_STMT 1
291 #define IN_ITERATION_STMT 2
292 #define IN_OMP_BLOCK 4
293 #define IN_OMP_FOR 8
294 #define IN_IF_STMT 16
295 unsigned char in_statement;
297 /* TRUE if we are presently parsing the body of a switch statement.
298 Note that this doesn't quite overlap with in_statement above.
299 The difference relates to giving the right sets of error messages:
300 "case not in switch" vs "break statement used with OpenMP...". */
301 bool in_switch_statement_p;
303 /* TRUE if we are parsing a type-id in an expression context. In
304 such a situation, both "type (expr)" and "type (type)" are valid
305 alternatives. */
306 bool in_type_id_in_expr_p;
308 /* TRUE if we are currently in a header file where declarations are
309 implicitly extern "C". */
310 bool implicit_extern_c;
312 /* TRUE if strings in expressions should be translated to the execution
313 character set. */
314 bool translate_strings_p;
316 /* TRUE if we are presently parsing the body of a function, but not
317 a local class. */
318 bool in_function_body;
320 /* Nonzero if we're processing a __transaction_atomic or
321 __transaction_relaxed statement. */
322 unsigned char in_transaction;
324 /* TRUE if we can auto-correct a colon to a scope operator. */
325 bool colon_corrects_to_scope_p;
327 /* If non-NULL, then we are parsing a construct where new type
328 definitions are not permitted. The string stored here will be
329 issued as an error message if a type is defined. */
330 const char *type_definition_forbidden_message;
332 /* A stack used for member functions of local classes. The lists
333 contained in an individual entry can only be processed once the
334 outermost class being defined is complete. */
335 vec<cp_unparsed_functions_entry, va_gc> *unparsed_queues;
337 /* The number of classes whose definitions are currently in
338 progress. */
339 unsigned num_classes_being_defined;
341 /* The number of template parameter lists that apply directly to the
342 current declaration. */
343 unsigned num_template_parameter_lists;
344 } cp_parser;
346 /* In parser.c */
347 extern void debug (cp_token &ref);
348 extern void debug (cp_token *ptr);
349 extern void cp_lexer_debug_tokens (vec<cp_token, va_gc> *);
350 extern void debug (vec<cp_token, va_gc> &ref);
351 extern void debug (vec<cp_token, va_gc> *ptr);
352 extern void cp_debug_parser (FILE *, cp_parser *);
353 extern void debug (cp_parser &ref);
354 extern void debug (cp_parser *ptr);
356 #endif /* GCC_CP_PARSER_H */