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