1 |
280 |
jeremybenn |
/* Parser for C and Objective-C.
|
2 |
|
|
Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
|
3 |
|
|
1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009
|
4 |
|
|
Free Software Foundation, Inc.
|
5 |
|
|
|
6 |
|
|
Parser actions based on the old Bison parser; structure somewhat
|
7 |
|
|
influenced by and fragments based on the C++ parser.
|
8 |
|
|
|
9 |
|
|
This file is part of GCC.
|
10 |
|
|
|
11 |
|
|
GCC is free software; you can redistribute it and/or modify it under
|
12 |
|
|
the terms of the GNU General Public License as published by the Free
|
13 |
|
|
Software Foundation; either version 3, or (at your option) any later
|
14 |
|
|
version.
|
15 |
|
|
|
16 |
|
|
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
|
17 |
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
18 |
|
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
19 |
|
|
for more details.
|
20 |
|
|
|
21 |
|
|
You should have received a copy of the GNU General Public License
|
22 |
|
|
along with GCC; see the file COPYING3. If not see
|
23 |
|
|
<http://www.gnu.org/licenses/>. */
|
24 |
|
|
|
25 |
|
|
/* TODO:
|
26 |
|
|
|
27 |
|
|
Make sure all relevant comments, and all relevant code from all
|
28 |
|
|
actions, brought over from old parser. Verify exact correspondence
|
29 |
|
|
of syntax accepted.
|
30 |
|
|
|
31 |
|
|
Add testcases covering every input symbol in every state in old and
|
32 |
|
|
new parsers.
|
33 |
|
|
|
34 |
|
|
Include full syntax for GNU C, including erroneous cases accepted
|
35 |
|
|
with error messages, in syntax productions in comments.
|
36 |
|
|
|
37 |
|
|
Make more diagnostics in the front end generally take an explicit
|
38 |
|
|
location rather than implicitly using input_location. */
|
39 |
|
|
|
40 |
|
|
#include "config.h"
|
41 |
|
|
#include "system.h"
|
42 |
|
|
#include "coretypes.h"
|
43 |
|
|
#include "tm.h"
|
44 |
|
|
#include "tree.h"
|
45 |
|
|
#include "rtl.h"
|
46 |
|
|
#include "langhooks.h"
|
47 |
|
|
#include "input.h"
|
48 |
|
|
#include "cpplib.h"
|
49 |
|
|
#include "timevar.h"
|
50 |
|
|
#include "c-pragma.h"
|
51 |
|
|
#include "c-tree.h"
|
52 |
|
|
#include "flags.h"
|
53 |
|
|
#include "output.h"
|
54 |
|
|
#include "toplev.h"
|
55 |
|
|
#include "ggc.h"
|
56 |
|
|
#include "c-common.h"
|
57 |
|
|
#include "vec.h"
|
58 |
|
|
#include "target.h"
|
59 |
|
|
#include "cgraph.h"
|
60 |
|
|
#include "plugin.h"
|
61 |
|
|
#include "except.h"
|
62 |
|
|
|
63 |
|
|
|
64 |
|
|
/* Initialization routine for this file. */
|
65 |
|
|
|
66 |
|
|
void
|
67 |
|
|
c_parse_init (void)
|
68 |
|
|
{
|
69 |
|
|
/* The only initialization required is of the reserved word
|
70 |
|
|
identifiers. */
|
71 |
|
|
unsigned int i;
|
72 |
|
|
tree id;
|
73 |
|
|
int mask = 0;
|
74 |
|
|
|
75 |
|
|
/* Make sure RID_MAX hasn't grown past the 8 bits used to hold the keyword in
|
76 |
|
|
the c_token structure. */
|
77 |
|
|
gcc_assert (RID_MAX <= 255);
|
78 |
|
|
|
79 |
|
|
mask |= D_CXXONLY;
|
80 |
|
|
if (!flag_isoc99)
|
81 |
|
|
mask |= D_C99;
|
82 |
|
|
if (flag_no_asm)
|
83 |
|
|
{
|
84 |
|
|
mask |= D_ASM | D_EXT;
|
85 |
|
|
if (!flag_isoc99)
|
86 |
|
|
mask |= D_EXT89;
|
87 |
|
|
}
|
88 |
|
|
if (!c_dialect_objc ())
|
89 |
|
|
mask |= D_OBJC | D_CXX_OBJC;
|
90 |
|
|
|
91 |
|
|
ridpointers = GGC_CNEWVEC (tree, (int) RID_MAX);
|
92 |
|
|
for (i = 0; i < num_c_common_reswords; i++)
|
93 |
|
|
{
|
94 |
|
|
/* If a keyword is disabled, do not enter it into the table
|
95 |
|
|
and so create a canonical spelling that isn't a keyword. */
|
96 |
|
|
if (c_common_reswords[i].disable & mask)
|
97 |
|
|
{
|
98 |
|
|
if (warn_cxx_compat
|
99 |
|
|
&& (c_common_reswords[i].disable & D_CXXWARN))
|
100 |
|
|
{
|
101 |
|
|
id = get_identifier (c_common_reswords[i].word);
|
102 |
|
|
C_SET_RID_CODE (id, RID_CXX_COMPAT_WARN);
|
103 |
|
|
C_IS_RESERVED_WORD (id) = 1;
|
104 |
|
|
}
|
105 |
|
|
continue;
|
106 |
|
|
}
|
107 |
|
|
|
108 |
|
|
id = get_identifier (c_common_reswords[i].word);
|
109 |
|
|
C_SET_RID_CODE (id, c_common_reswords[i].rid);
|
110 |
|
|
C_IS_RESERVED_WORD (id) = 1;
|
111 |
|
|
ridpointers [(int) c_common_reswords[i].rid] = id;
|
112 |
|
|
}
|
113 |
|
|
}
|
114 |
|
|
|
115 |
|
|
/* The C lexer intermediates between the lexer in cpplib and c-lex.c
|
116 |
|
|
and the C parser. Unlike the C++ lexer, the parser structure
|
117 |
|
|
stores the lexer information instead of using a separate structure.
|
118 |
|
|
Identifiers are separated into ordinary identifiers, type names,
|
119 |
|
|
keywords and some other Objective-C types of identifiers, and some
|
120 |
|
|
look-ahead is maintained.
|
121 |
|
|
|
122 |
|
|
??? It might be a good idea to lex the whole file up front (as for
|
123 |
|
|
C++). It would then be possible to share more of the C and C++
|
124 |
|
|
lexer code, if desired. */
|
125 |
|
|
|
126 |
|
|
/* The following local token type is used. */
|
127 |
|
|
|
128 |
|
|
/* A keyword. */
|
129 |
|
|
#define CPP_KEYWORD ((enum cpp_ttype) (N_TTYPES + 1))
|
130 |
|
|
|
131 |
|
|
/* More information about the type of a CPP_NAME token. */
|
132 |
|
|
typedef enum c_id_kind {
|
133 |
|
|
/* An ordinary identifier. */
|
134 |
|
|
C_ID_ID,
|
135 |
|
|
/* An identifier declared as a typedef name. */
|
136 |
|
|
C_ID_TYPENAME,
|
137 |
|
|
/* An identifier declared as an Objective-C class name. */
|
138 |
|
|
C_ID_CLASSNAME,
|
139 |
|
|
/* An address space identifier. */
|
140 |
|
|
C_ID_ADDRSPACE,
|
141 |
|
|
/* Not an identifier. */
|
142 |
|
|
C_ID_NONE
|
143 |
|
|
} c_id_kind;
|
144 |
|
|
|
145 |
|
|
/* A single C token after string literal concatenation and conversion
|
146 |
|
|
of preprocessing tokens to tokens. */
|
147 |
|
|
typedef struct GTY (()) c_token {
|
148 |
|
|
/* The kind of token. */
|
149 |
|
|
ENUM_BITFIELD (cpp_ttype) type : 8;
|
150 |
|
|
/* If this token is a CPP_NAME, this value indicates whether also
|
151 |
|
|
declared as some kind of type. Otherwise, it is C_ID_NONE. */
|
152 |
|
|
ENUM_BITFIELD (c_id_kind) id_kind : 8;
|
153 |
|
|
/* If this token is a keyword, this value indicates which keyword.
|
154 |
|
|
Otherwise, this value is RID_MAX. */
|
155 |
|
|
ENUM_BITFIELD (rid) keyword : 8;
|
156 |
|
|
/* If this token is a CPP_PRAGMA, this indicates the pragma that
|
157 |
|
|
was seen. Otherwise it is PRAGMA_NONE. */
|
158 |
|
|
ENUM_BITFIELD (pragma_kind) pragma_kind : 8;
|
159 |
|
|
/* The value associated with this token, if any. */
|
160 |
|
|
tree value;
|
161 |
|
|
/* The location at which this token was found. */
|
162 |
|
|
location_t location;
|
163 |
|
|
} c_token;
|
164 |
|
|
|
165 |
|
|
/* A parser structure recording information about the state and
|
166 |
|
|
context of parsing. Includes lexer information with up to two
|
167 |
|
|
tokens of look-ahead; more are not needed for C. */
|
168 |
|
|
typedef struct GTY(()) c_parser {
|
169 |
|
|
/* The look-ahead tokens. */
|
170 |
|
|
c_token tokens[2];
|
171 |
|
|
/* How many look-ahead tokens are available (0, 1 or 2). */
|
172 |
|
|
short tokens_avail;
|
173 |
|
|
/* True if a syntax error is being recovered from; false otherwise.
|
174 |
|
|
c_parser_error sets this flag. It should clear this flag when
|
175 |
|
|
enough tokens have been consumed to recover from the error. */
|
176 |
|
|
BOOL_BITFIELD error : 1;
|
177 |
|
|
/* True if we're processing a pragma, and shouldn't automatically
|
178 |
|
|
consume CPP_PRAGMA_EOL. */
|
179 |
|
|
BOOL_BITFIELD in_pragma : 1;
|
180 |
|
|
/* True if we're parsing the outermost block of an if statement. */
|
181 |
|
|
BOOL_BITFIELD in_if_block : 1;
|
182 |
|
|
/* True if we want to lex an untranslated string. */
|
183 |
|
|
BOOL_BITFIELD lex_untranslated_string : 1;
|
184 |
|
|
/* Objective-C specific parser/lexer information. */
|
185 |
|
|
BOOL_BITFIELD objc_pq_context : 1;
|
186 |
|
|
/* The following flag is needed to contextualize Objective-C lexical
|
187 |
|
|
analysis. In some cases (e.g., 'int NSObject;'), it is
|
188 |
|
|
undesirable to bind an identifier to an Objective-C class, even
|
189 |
|
|
if a class with that name exists. */
|
190 |
|
|
BOOL_BITFIELD objc_need_raw_identifier : 1;
|
191 |
|
|
} c_parser;
|
192 |
|
|
|
193 |
|
|
|
194 |
|
|
/* The actual parser and external interface. ??? Does this need to be
|
195 |
|
|
garbage-collected? */
|
196 |
|
|
|
197 |
|
|
static GTY (()) c_parser *the_parser;
|
198 |
|
|
|
199 |
|
|
|
200 |
|
|
/* Read in and lex a single token, storing it in *TOKEN. */
|
201 |
|
|
|
202 |
|
|
static void
|
203 |
|
|
c_lex_one_token (c_parser *parser, c_token *token)
|
204 |
|
|
{
|
205 |
|
|
timevar_push (TV_LEX);
|
206 |
|
|
|
207 |
|
|
token->type = c_lex_with_flags (&token->value, &token->location, NULL,
|
208 |
|
|
(parser->lex_untranslated_string
|
209 |
|
|
? C_LEX_STRING_NO_TRANSLATE : 0));
|
210 |
|
|
token->id_kind = C_ID_NONE;
|
211 |
|
|
token->keyword = RID_MAX;
|
212 |
|
|
token->pragma_kind = PRAGMA_NONE;
|
213 |
|
|
|
214 |
|
|
switch (token->type)
|
215 |
|
|
{
|
216 |
|
|
case CPP_NAME:
|
217 |
|
|
{
|
218 |
|
|
tree decl;
|
219 |
|
|
|
220 |
|
|
bool objc_force_identifier = parser->objc_need_raw_identifier;
|
221 |
|
|
if (c_dialect_objc ())
|
222 |
|
|
parser->objc_need_raw_identifier = false;
|
223 |
|
|
|
224 |
|
|
if (C_IS_RESERVED_WORD (token->value))
|
225 |
|
|
{
|
226 |
|
|
enum rid rid_code = C_RID_CODE (token->value);
|
227 |
|
|
|
228 |
|
|
if (rid_code == RID_CXX_COMPAT_WARN)
|
229 |
|
|
{
|
230 |
|
|
warning_at (token->location,
|
231 |
|
|
OPT_Wc___compat,
|
232 |
|
|
"identifier %qE conflicts with C++ keyword",
|
233 |
|
|
token->value);
|
234 |
|
|
}
|
235 |
|
|
else if (rid_code >= RID_FIRST_ADDR_SPACE
|
236 |
|
|
&& rid_code <= RID_LAST_ADDR_SPACE)
|
237 |
|
|
{
|
238 |
|
|
token->id_kind = C_ID_ADDRSPACE;
|
239 |
|
|
token->keyword = rid_code;
|
240 |
|
|
break;
|
241 |
|
|
}
|
242 |
|
|
else if (c_dialect_objc ())
|
243 |
|
|
{
|
244 |
|
|
if (!objc_is_reserved_word (token->value)
|
245 |
|
|
&& (!OBJC_IS_PQ_KEYWORD (rid_code)
|
246 |
|
|
|| parser->objc_pq_context))
|
247 |
|
|
{
|
248 |
|
|
/* Return the canonical spelling for this keyword. */
|
249 |
|
|
token->value = ridpointers[(int) rid_code];
|
250 |
|
|
token->type = CPP_KEYWORD;
|
251 |
|
|
token->keyword = rid_code;
|
252 |
|
|
break;
|
253 |
|
|
}
|
254 |
|
|
}
|
255 |
|
|
else
|
256 |
|
|
{
|
257 |
|
|
token->type = CPP_KEYWORD;
|
258 |
|
|
token->keyword = rid_code;
|
259 |
|
|
break;
|
260 |
|
|
}
|
261 |
|
|
}
|
262 |
|
|
|
263 |
|
|
decl = lookup_name (token->value);
|
264 |
|
|
if (decl)
|
265 |
|
|
{
|
266 |
|
|
if (TREE_CODE (decl) == TYPE_DECL)
|
267 |
|
|
{
|
268 |
|
|
token->id_kind = C_ID_TYPENAME;
|
269 |
|
|
break;
|
270 |
|
|
}
|
271 |
|
|
}
|
272 |
|
|
else if (c_dialect_objc ())
|
273 |
|
|
{
|
274 |
|
|
tree objc_interface_decl = objc_is_class_name (token->value);
|
275 |
|
|
/* Objective-C class names are in the same namespace as
|
276 |
|
|
variables and typedefs, and hence are shadowed by local
|
277 |
|
|
declarations. */
|
278 |
|
|
if (objc_interface_decl
|
279 |
|
|
&& (global_bindings_p ()
|
280 |
|
|
|| (!objc_force_identifier && !decl)))
|
281 |
|
|
{
|
282 |
|
|
token->value = objc_interface_decl;
|
283 |
|
|
token->id_kind = C_ID_CLASSNAME;
|
284 |
|
|
break;
|
285 |
|
|
}
|
286 |
|
|
}
|
287 |
|
|
token->id_kind = C_ID_ID;
|
288 |
|
|
}
|
289 |
|
|
break;
|
290 |
|
|
case CPP_AT_NAME:
|
291 |
|
|
/* This only happens in Objective-C; it must be a keyword. */
|
292 |
|
|
token->type = CPP_KEYWORD;
|
293 |
|
|
token->keyword = C_RID_CODE (token->value);
|
294 |
|
|
break;
|
295 |
|
|
case CPP_COLON:
|
296 |
|
|
case CPP_COMMA:
|
297 |
|
|
case CPP_CLOSE_PAREN:
|
298 |
|
|
case CPP_SEMICOLON:
|
299 |
|
|
/* These tokens may affect the interpretation of any identifiers
|
300 |
|
|
following, if doing Objective-C. */
|
301 |
|
|
if (c_dialect_objc ())
|
302 |
|
|
parser->objc_need_raw_identifier = false;
|
303 |
|
|
break;
|
304 |
|
|
case CPP_PRAGMA:
|
305 |
|
|
/* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */
|
306 |
|
|
token->pragma_kind = (enum pragma_kind) TREE_INT_CST_LOW (token->value);
|
307 |
|
|
token->value = NULL;
|
308 |
|
|
break;
|
309 |
|
|
default:
|
310 |
|
|
break;
|
311 |
|
|
}
|
312 |
|
|
timevar_pop (TV_LEX);
|
313 |
|
|
}
|
314 |
|
|
|
315 |
|
|
/* Return a pointer to the next token from PARSER, reading it in if
|
316 |
|
|
necessary. */
|
317 |
|
|
|
318 |
|
|
static inline c_token *
|
319 |
|
|
c_parser_peek_token (c_parser *parser)
|
320 |
|
|
{
|
321 |
|
|
if (parser->tokens_avail == 0)
|
322 |
|
|
{
|
323 |
|
|
c_lex_one_token (parser, &parser->tokens[0]);
|
324 |
|
|
parser->tokens_avail = 1;
|
325 |
|
|
}
|
326 |
|
|
return &parser->tokens[0];
|
327 |
|
|
}
|
328 |
|
|
|
329 |
|
|
/* Return true if the next token from PARSER has the indicated
|
330 |
|
|
TYPE. */
|
331 |
|
|
|
332 |
|
|
static inline bool
|
333 |
|
|
c_parser_next_token_is (c_parser *parser, enum cpp_ttype type)
|
334 |
|
|
{
|
335 |
|
|
return c_parser_peek_token (parser)->type == type;
|
336 |
|
|
}
|
337 |
|
|
|
338 |
|
|
/* Return true if the next token from PARSER does not have the
|
339 |
|
|
indicated TYPE. */
|
340 |
|
|
|
341 |
|
|
static inline bool
|
342 |
|
|
c_parser_next_token_is_not (c_parser *parser, enum cpp_ttype type)
|
343 |
|
|
{
|
344 |
|
|
return !c_parser_next_token_is (parser, type);
|
345 |
|
|
}
|
346 |
|
|
|
347 |
|
|
/* Return true if the next token from PARSER is the indicated
|
348 |
|
|
KEYWORD. */
|
349 |
|
|
|
350 |
|
|
static inline bool
|
351 |
|
|
c_parser_next_token_is_keyword (c_parser *parser, enum rid keyword)
|
352 |
|
|
{
|
353 |
|
|
return c_parser_peek_token (parser)->keyword == keyword;
|
354 |
|
|
}
|
355 |
|
|
|
356 |
|
|
/* Return true if TOKEN can start a type name,
|
357 |
|
|
false otherwise. */
|
358 |
|
|
static bool
|
359 |
|
|
c_token_starts_typename (c_token *token)
|
360 |
|
|
{
|
361 |
|
|
switch (token->type)
|
362 |
|
|
{
|
363 |
|
|
case CPP_NAME:
|
364 |
|
|
switch (token->id_kind)
|
365 |
|
|
{
|
366 |
|
|
case C_ID_ID:
|
367 |
|
|
return false;
|
368 |
|
|
case C_ID_ADDRSPACE:
|
369 |
|
|
return true;
|
370 |
|
|
case C_ID_TYPENAME:
|
371 |
|
|
return true;
|
372 |
|
|
case C_ID_CLASSNAME:
|
373 |
|
|
gcc_assert (c_dialect_objc ());
|
374 |
|
|
return true;
|
375 |
|
|
default:
|
376 |
|
|
gcc_unreachable ();
|
377 |
|
|
}
|
378 |
|
|
case CPP_KEYWORD:
|
379 |
|
|
switch (token->keyword)
|
380 |
|
|
{
|
381 |
|
|
case RID_UNSIGNED:
|
382 |
|
|
case RID_LONG:
|
383 |
|
|
case RID_SHORT:
|
384 |
|
|
case RID_SIGNED:
|
385 |
|
|
case RID_COMPLEX:
|
386 |
|
|
case RID_INT:
|
387 |
|
|
case RID_CHAR:
|
388 |
|
|
case RID_FLOAT:
|
389 |
|
|
case RID_DOUBLE:
|
390 |
|
|
case RID_VOID:
|
391 |
|
|
case RID_DFLOAT32:
|
392 |
|
|
case RID_DFLOAT64:
|
393 |
|
|
case RID_DFLOAT128:
|
394 |
|
|
case RID_BOOL:
|
395 |
|
|
case RID_ENUM:
|
396 |
|
|
case RID_STRUCT:
|
397 |
|
|
case RID_UNION:
|
398 |
|
|
case RID_TYPEOF:
|
399 |
|
|
case RID_CONST:
|
400 |
|
|
case RID_VOLATILE:
|
401 |
|
|
case RID_RESTRICT:
|
402 |
|
|
case RID_ATTRIBUTE:
|
403 |
|
|
case RID_FRACT:
|
404 |
|
|
case RID_ACCUM:
|
405 |
|
|
case RID_SAT:
|
406 |
|
|
return true;
|
407 |
|
|
default:
|
408 |
|
|
return false;
|
409 |
|
|
}
|
410 |
|
|
case CPP_LESS:
|
411 |
|
|
if (c_dialect_objc ())
|
412 |
|
|
return true;
|
413 |
|
|
return false;
|
414 |
|
|
default:
|
415 |
|
|
return false;
|
416 |
|
|
}
|
417 |
|
|
}
|
418 |
|
|
|
419 |
|
|
/* Return true if the next token from PARSER can start a type name,
|
420 |
|
|
false otherwise. */
|
421 |
|
|
static inline bool
|
422 |
|
|
c_parser_next_token_starts_typename (c_parser *parser)
|
423 |
|
|
{
|
424 |
|
|
c_token *token = c_parser_peek_token (parser);
|
425 |
|
|
return c_token_starts_typename (token);
|
426 |
|
|
}
|
427 |
|
|
|
428 |
|
|
/* Return true if TOKEN can start declaration specifiers, false
|
429 |
|
|
otherwise. */
|
430 |
|
|
static bool
|
431 |
|
|
c_token_starts_declspecs (c_token *token)
|
432 |
|
|
{
|
433 |
|
|
switch (token->type)
|
434 |
|
|
{
|
435 |
|
|
case CPP_NAME:
|
436 |
|
|
switch (token->id_kind)
|
437 |
|
|
{
|
438 |
|
|
case C_ID_ID:
|
439 |
|
|
return false;
|
440 |
|
|
case C_ID_ADDRSPACE:
|
441 |
|
|
return true;
|
442 |
|
|
case C_ID_TYPENAME:
|
443 |
|
|
return true;
|
444 |
|
|
case C_ID_CLASSNAME:
|
445 |
|
|
gcc_assert (c_dialect_objc ());
|
446 |
|
|
return true;
|
447 |
|
|
default:
|
448 |
|
|
gcc_unreachable ();
|
449 |
|
|
}
|
450 |
|
|
case CPP_KEYWORD:
|
451 |
|
|
switch (token->keyword)
|
452 |
|
|
{
|
453 |
|
|
case RID_STATIC:
|
454 |
|
|
case RID_EXTERN:
|
455 |
|
|
case RID_REGISTER:
|
456 |
|
|
case RID_TYPEDEF:
|
457 |
|
|
case RID_INLINE:
|
458 |
|
|
case RID_AUTO:
|
459 |
|
|
case RID_THREAD:
|
460 |
|
|
case RID_UNSIGNED:
|
461 |
|
|
case RID_LONG:
|
462 |
|
|
case RID_SHORT:
|
463 |
|
|
case RID_SIGNED:
|
464 |
|
|
case RID_COMPLEX:
|
465 |
|
|
case RID_INT:
|
466 |
|
|
case RID_CHAR:
|
467 |
|
|
case RID_FLOAT:
|
468 |
|
|
case RID_DOUBLE:
|
469 |
|
|
case RID_VOID:
|
470 |
|
|
case RID_DFLOAT32:
|
471 |
|
|
case RID_DFLOAT64:
|
472 |
|
|
case RID_DFLOAT128:
|
473 |
|
|
case RID_BOOL:
|
474 |
|
|
case RID_ENUM:
|
475 |
|
|
case RID_STRUCT:
|
476 |
|
|
case RID_UNION:
|
477 |
|
|
case RID_TYPEOF:
|
478 |
|
|
case RID_CONST:
|
479 |
|
|
case RID_VOLATILE:
|
480 |
|
|
case RID_RESTRICT:
|
481 |
|
|
case RID_ATTRIBUTE:
|
482 |
|
|
case RID_FRACT:
|
483 |
|
|
case RID_ACCUM:
|
484 |
|
|
case RID_SAT:
|
485 |
|
|
return true;
|
486 |
|
|
default:
|
487 |
|
|
return false;
|
488 |
|
|
}
|
489 |
|
|
case CPP_LESS:
|
490 |
|
|
if (c_dialect_objc ())
|
491 |
|
|
return true;
|
492 |
|
|
return false;
|
493 |
|
|
default:
|
494 |
|
|
return false;
|
495 |
|
|
}
|
496 |
|
|
}
|
497 |
|
|
|
498 |
|
|
/* Return true if the next token from PARSER can start declaration
|
499 |
|
|
specifiers, false otherwise. */
|
500 |
|
|
static inline bool
|
501 |
|
|
c_parser_next_token_starts_declspecs (c_parser *parser)
|
502 |
|
|
{
|
503 |
|
|
c_token *token = c_parser_peek_token (parser);
|
504 |
|
|
return c_token_starts_declspecs (token);
|
505 |
|
|
}
|
506 |
|
|
|
507 |
|
|
/* Return a pointer to the next-but-one token from PARSER, reading it
|
508 |
|
|
in if necessary. The next token is already read in. */
|
509 |
|
|
|
510 |
|
|
static c_token *
|
511 |
|
|
c_parser_peek_2nd_token (c_parser *parser)
|
512 |
|
|
{
|
513 |
|
|
if (parser->tokens_avail >= 2)
|
514 |
|
|
return &parser->tokens[1];
|
515 |
|
|
gcc_assert (parser->tokens_avail == 1);
|
516 |
|
|
gcc_assert (parser->tokens[0].type != CPP_EOF);
|
517 |
|
|
gcc_assert (parser->tokens[0].type != CPP_PRAGMA_EOL);
|
518 |
|
|
c_lex_one_token (parser, &parser->tokens[1]);
|
519 |
|
|
parser->tokens_avail = 2;
|
520 |
|
|
return &parser->tokens[1];
|
521 |
|
|
}
|
522 |
|
|
|
523 |
|
|
/* Consume the next token from PARSER. */
|
524 |
|
|
|
525 |
|
|
static void
|
526 |
|
|
c_parser_consume_token (c_parser *parser)
|
527 |
|
|
{
|
528 |
|
|
gcc_assert (parser->tokens_avail >= 1);
|
529 |
|
|
gcc_assert (parser->tokens[0].type != CPP_EOF);
|
530 |
|
|
gcc_assert (!parser->in_pragma || parser->tokens[0].type != CPP_PRAGMA_EOL);
|
531 |
|
|
gcc_assert (parser->error || parser->tokens[0].type != CPP_PRAGMA);
|
532 |
|
|
if (parser->tokens_avail == 2)
|
533 |
|
|
parser->tokens[0] = parser->tokens[1];
|
534 |
|
|
parser->tokens_avail--;
|
535 |
|
|
}
|
536 |
|
|
|
537 |
|
|
/* Expect the current token to be a #pragma. Consume it and remember
|
538 |
|
|
that we've begun parsing a pragma. */
|
539 |
|
|
|
540 |
|
|
static void
|
541 |
|
|
c_parser_consume_pragma (c_parser *parser)
|
542 |
|
|
{
|
543 |
|
|
gcc_assert (!parser->in_pragma);
|
544 |
|
|
gcc_assert (parser->tokens_avail >= 1);
|
545 |
|
|
gcc_assert (parser->tokens[0].type == CPP_PRAGMA);
|
546 |
|
|
if (parser->tokens_avail == 2)
|
547 |
|
|
parser->tokens[0] = parser->tokens[1];
|
548 |
|
|
parser->tokens_avail--;
|
549 |
|
|
parser->in_pragma = true;
|
550 |
|
|
}
|
551 |
|
|
|
552 |
|
|
/* Update the globals input_location and in_system_header from
|
553 |
|
|
TOKEN. */
|
554 |
|
|
static inline void
|
555 |
|
|
c_parser_set_source_position_from_token (c_token *token)
|
556 |
|
|
{
|
557 |
|
|
if (token->type != CPP_EOF)
|
558 |
|
|
{
|
559 |
|
|
input_location = token->location;
|
560 |
|
|
}
|
561 |
|
|
}
|
562 |
|
|
|
563 |
|
|
/* Issue a diagnostic of the form
|
564 |
|
|
FILE:LINE: MESSAGE before TOKEN
|
565 |
|
|
where TOKEN is the next token in the input stream of PARSER.
|
566 |
|
|
MESSAGE (specified by the caller) is usually of the form "expected
|
567 |
|
|
OTHER-TOKEN".
|
568 |
|
|
|
569 |
|
|
Do not issue a diagnostic if still recovering from an error.
|
570 |
|
|
|
571 |
|
|
??? This is taken from the C++ parser, but building up messages in
|
572 |
|
|
this way is not i18n-friendly and some other approach should be
|
573 |
|
|
used. */
|
574 |
|
|
|
575 |
|
|
static void
|
576 |
|
|
c_parser_error (c_parser *parser, const char *gmsgid)
|
577 |
|
|
{
|
578 |
|
|
c_token *token = c_parser_peek_token (parser);
|
579 |
|
|
if (parser->error)
|
580 |
|
|
return;
|
581 |
|
|
parser->error = true;
|
582 |
|
|
if (!gmsgid)
|
583 |
|
|
return;
|
584 |
|
|
/* This diagnostic makes more sense if it is tagged to the line of
|
585 |
|
|
the token we just peeked at. */
|
586 |
|
|
c_parser_set_source_position_from_token (token);
|
587 |
|
|
c_parse_error (gmsgid,
|
588 |
|
|
/* Because c_parse_error does not understand
|
589 |
|
|
CPP_KEYWORD, keywords are treated like
|
590 |
|
|
identifiers. */
|
591 |
|
|
(token->type == CPP_KEYWORD ? CPP_NAME : token->type),
|
592 |
|
|
/* ??? The C parser does not save the cpp flags of a
|
593 |
|
|
token, we need to pass 0 here and we will not get
|
594 |
|
|
the source spelling of some tokens but rather the
|
595 |
|
|
canonical spelling. */
|
596 |
|
|
token->value, /*flags=*/0);
|
597 |
|
|
}
|
598 |
|
|
|
599 |
|
|
/* If the next token is of the indicated TYPE, consume it. Otherwise,
|
600 |
|
|
issue the error MSGID. If MSGID is NULL then a message has already
|
601 |
|
|
been produced and no message will be produced this time. Returns
|
602 |
|
|
true if found, false otherwise. */
|
603 |
|
|
|
604 |
|
|
static bool
|
605 |
|
|
c_parser_require (c_parser *parser,
|
606 |
|
|
enum cpp_ttype type,
|
607 |
|
|
const char *msgid)
|
608 |
|
|
{
|
609 |
|
|
if (c_parser_next_token_is (parser, type))
|
610 |
|
|
{
|
611 |
|
|
c_parser_consume_token (parser);
|
612 |
|
|
return true;
|
613 |
|
|
}
|
614 |
|
|
else
|
615 |
|
|
{
|
616 |
|
|
c_parser_error (parser, msgid);
|
617 |
|
|
return false;
|
618 |
|
|
}
|
619 |
|
|
}
|
620 |
|
|
|
621 |
|
|
/* If the next token is the indicated keyword, consume it. Otherwise,
|
622 |
|
|
issue the error MSGID. Returns true if found, false otherwise. */
|
623 |
|
|
|
624 |
|
|
static bool
|
625 |
|
|
c_parser_require_keyword (c_parser *parser,
|
626 |
|
|
enum rid keyword,
|
627 |
|
|
const char *msgid)
|
628 |
|
|
{
|
629 |
|
|
if (c_parser_next_token_is_keyword (parser, keyword))
|
630 |
|
|
{
|
631 |
|
|
c_parser_consume_token (parser);
|
632 |
|
|
return true;
|
633 |
|
|
}
|
634 |
|
|
else
|
635 |
|
|
{
|
636 |
|
|
c_parser_error (parser, msgid);
|
637 |
|
|
return false;
|
638 |
|
|
}
|
639 |
|
|
}
|
640 |
|
|
|
641 |
|
|
/* Like c_parser_require, except that tokens will be skipped until the
|
642 |
|
|
desired token is found. An error message is still produced if the
|
643 |
|
|
next token is not as expected. If MSGID is NULL then a message has
|
644 |
|
|
already been produced and no message will be produced this
|
645 |
|
|
time. */
|
646 |
|
|
|
647 |
|
|
static void
|
648 |
|
|
c_parser_skip_until_found (c_parser *parser,
|
649 |
|
|
enum cpp_ttype type,
|
650 |
|
|
const char *msgid)
|
651 |
|
|
{
|
652 |
|
|
unsigned nesting_depth = 0;
|
653 |
|
|
|
654 |
|
|
if (c_parser_require (parser, type, msgid))
|
655 |
|
|
return;
|
656 |
|
|
|
657 |
|
|
/* Skip tokens until the desired token is found. */
|
658 |
|
|
while (true)
|
659 |
|
|
{
|
660 |
|
|
/* Peek at the next token. */
|
661 |
|
|
c_token *token = c_parser_peek_token (parser);
|
662 |
|
|
/* If we've reached the token we want, consume it and stop. */
|
663 |
|
|
if (token->type == type && !nesting_depth)
|
664 |
|
|
{
|
665 |
|
|
c_parser_consume_token (parser);
|
666 |
|
|
break;
|
667 |
|
|
}
|
668 |
|
|
|
669 |
|
|
/* If we've run out of tokens, stop. */
|
670 |
|
|
if (token->type == CPP_EOF)
|
671 |
|
|
return;
|
672 |
|
|
if (token->type == CPP_PRAGMA_EOL && parser->in_pragma)
|
673 |
|
|
return;
|
674 |
|
|
if (token->type == CPP_OPEN_BRACE
|
675 |
|
|
|| token->type == CPP_OPEN_PAREN
|
676 |
|
|
|| token->type == CPP_OPEN_SQUARE)
|
677 |
|
|
++nesting_depth;
|
678 |
|
|
else if (token->type == CPP_CLOSE_BRACE
|
679 |
|
|
|| token->type == CPP_CLOSE_PAREN
|
680 |
|
|
|| token->type == CPP_CLOSE_SQUARE)
|
681 |
|
|
{
|
682 |
|
|
if (nesting_depth-- == 0)
|
683 |
|
|
break;
|
684 |
|
|
}
|
685 |
|
|
/* Consume this token. */
|
686 |
|
|
c_parser_consume_token (parser);
|
687 |
|
|
}
|
688 |
|
|
parser->error = false;
|
689 |
|
|
}
|
690 |
|
|
|
691 |
|
|
/* Skip tokens until the end of a parameter is found, but do not
|
692 |
|
|
consume the comma, semicolon or closing delimiter. */
|
693 |
|
|
|
694 |
|
|
static void
|
695 |
|
|
c_parser_skip_to_end_of_parameter (c_parser *parser)
|
696 |
|
|
{
|
697 |
|
|
unsigned nesting_depth = 0;
|
698 |
|
|
|
699 |
|
|
while (true)
|
700 |
|
|
{
|
701 |
|
|
c_token *token = c_parser_peek_token (parser);
|
702 |
|
|
if ((token->type == CPP_COMMA || token->type == CPP_SEMICOLON)
|
703 |
|
|
&& !nesting_depth)
|
704 |
|
|
break;
|
705 |
|
|
/* If we've run out of tokens, stop. */
|
706 |
|
|
if (token->type == CPP_EOF)
|
707 |
|
|
return;
|
708 |
|
|
if (token->type == CPP_PRAGMA_EOL && parser->in_pragma)
|
709 |
|
|
return;
|
710 |
|
|
if (token->type == CPP_OPEN_BRACE
|
711 |
|
|
|| token->type == CPP_OPEN_PAREN
|
712 |
|
|
|| token->type == CPP_OPEN_SQUARE)
|
713 |
|
|
++nesting_depth;
|
714 |
|
|
else if (token->type == CPP_CLOSE_BRACE
|
715 |
|
|
|| token->type == CPP_CLOSE_PAREN
|
716 |
|
|
|| token->type == CPP_CLOSE_SQUARE)
|
717 |
|
|
{
|
718 |
|
|
if (nesting_depth-- == 0)
|
719 |
|
|
break;
|
720 |
|
|
}
|
721 |
|
|
/* Consume this token. */
|
722 |
|
|
c_parser_consume_token (parser);
|
723 |
|
|
}
|
724 |
|
|
parser->error = false;
|
725 |
|
|
}
|
726 |
|
|
|
727 |
|
|
/* Expect to be at the end of the pragma directive and consume an
|
728 |
|
|
end of line marker. */
|
729 |
|
|
|
730 |
|
|
static void
|
731 |
|
|
c_parser_skip_to_pragma_eol (c_parser *parser)
|
732 |
|
|
{
|
733 |
|
|
gcc_assert (parser->in_pragma);
|
734 |
|
|
parser->in_pragma = false;
|
735 |
|
|
|
736 |
|
|
if (!c_parser_require (parser, CPP_PRAGMA_EOL, "expected end of line"))
|
737 |
|
|
while (true)
|
738 |
|
|
{
|
739 |
|
|
c_token *token = c_parser_peek_token (parser);
|
740 |
|
|
if (token->type == CPP_EOF)
|
741 |
|
|
break;
|
742 |
|
|
if (token->type == CPP_PRAGMA_EOL)
|
743 |
|
|
{
|
744 |
|
|
c_parser_consume_token (parser);
|
745 |
|
|
break;
|
746 |
|
|
}
|
747 |
|
|
c_parser_consume_token (parser);
|
748 |
|
|
}
|
749 |
|
|
|
750 |
|
|
parser->error = false;
|
751 |
|
|
}
|
752 |
|
|
|
753 |
|
|
/* Skip tokens until we have consumed an entire block, or until we
|
754 |
|
|
have consumed a non-nested ';'. */
|
755 |
|
|
|
756 |
|
|
static void
|
757 |
|
|
c_parser_skip_to_end_of_block_or_statement (c_parser *parser)
|
758 |
|
|
{
|
759 |
|
|
unsigned nesting_depth = 0;
|
760 |
|
|
bool save_error = parser->error;
|
761 |
|
|
|
762 |
|
|
while (true)
|
763 |
|
|
{
|
764 |
|
|
c_token *token;
|
765 |
|
|
|
766 |
|
|
/* Peek at the next token. */
|
767 |
|
|
token = c_parser_peek_token (parser);
|
768 |
|
|
|
769 |
|
|
switch (token->type)
|
770 |
|
|
{
|
771 |
|
|
case CPP_EOF:
|
772 |
|
|
return;
|
773 |
|
|
|
774 |
|
|
case CPP_PRAGMA_EOL:
|
775 |
|
|
if (parser->in_pragma)
|
776 |
|
|
return;
|
777 |
|
|
break;
|
778 |
|
|
|
779 |
|
|
case CPP_SEMICOLON:
|
780 |
|
|
/* If the next token is a ';', we have reached the
|
781 |
|
|
end of the statement. */
|
782 |
|
|
if (!nesting_depth)
|
783 |
|
|
{
|
784 |
|
|
/* Consume the ';'. */
|
785 |
|
|
c_parser_consume_token (parser);
|
786 |
|
|
goto finished;
|
787 |
|
|
}
|
788 |
|
|
break;
|
789 |
|
|
|
790 |
|
|
case CPP_CLOSE_BRACE:
|
791 |
|
|
/* If the next token is a non-nested '}', then we have
|
792 |
|
|
reached the end of the current block. */
|
793 |
|
|
if (nesting_depth == 0 || --nesting_depth == 0)
|
794 |
|
|
{
|
795 |
|
|
c_parser_consume_token (parser);
|
796 |
|
|
goto finished;
|
797 |
|
|
}
|
798 |
|
|
break;
|
799 |
|
|
|
800 |
|
|
case CPP_OPEN_BRACE:
|
801 |
|
|
/* If it the next token is a '{', then we are entering a new
|
802 |
|
|
block. Consume the entire block. */
|
803 |
|
|
++nesting_depth;
|
804 |
|
|
break;
|
805 |
|
|
|
806 |
|
|
case CPP_PRAGMA:
|
807 |
|
|
/* If we see a pragma, consume the whole thing at once. We
|
808 |
|
|
have some safeguards against consuming pragmas willy-nilly.
|
809 |
|
|
Normally, we'd expect to be here with parser->error set,
|
810 |
|
|
which disables these safeguards. But it's possible to get
|
811 |
|
|
here for secondary error recovery, after parser->error has
|
812 |
|
|
been cleared. */
|
813 |
|
|
c_parser_consume_pragma (parser);
|
814 |
|
|
c_parser_skip_to_pragma_eol (parser);
|
815 |
|
|
parser->error = save_error;
|
816 |
|
|
continue;
|
817 |
|
|
|
818 |
|
|
default:
|
819 |
|
|
break;
|
820 |
|
|
}
|
821 |
|
|
|
822 |
|
|
c_parser_consume_token (parser);
|
823 |
|
|
}
|
824 |
|
|
|
825 |
|
|
finished:
|
826 |
|
|
parser->error = false;
|
827 |
|
|
}
|
828 |
|
|
|
829 |
|
|
/* CPP's options (initialized by c-opts.c). */
|
830 |
|
|
extern cpp_options *cpp_opts;
|
831 |
|
|
|
832 |
|
|
/* Save the warning flags which are controlled by __extension__. */
|
833 |
|
|
|
834 |
|
|
static inline int
|
835 |
|
|
disable_extension_diagnostics (void)
|
836 |
|
|
{
|
837 |
|
|
int ret = (pedantic
|
838 |
|
|
| (warn_pointer_arith << 1)
|
839 |
|
|
| (warn_traditional << 2)
|
840 |
|
|
| (flag_iso << 3)
|
841 |
|
|
| (warn_long_long << 4)
|
842 |
|
|
| (warn_cxx_compat << 5));
|
843 |
|
|
cpp_opts->pedantic = pedantic = 0;
|
844 |
|
|
warn_pointer_arith = 0;
|
845 |
|
|
cpp_opts->warn_traditional = warn_traditional = 0;
|
846 |
|
|
flag_iso = 0;
|
847 |
|
|
cpp_opts->warn_long_long = warn_long_long = 0;
|
848 |
|
|
warn_cxx_compat = 0;
|
849 |
|
|
return ret;
|
850 |
|
|
}
|
851 |
|
|
|
852 |
|
|
/* Restore the warning flags which are controlled by __extension__.
|
853 |
|
|
FLAGS is the return value from disable_extension_diagnostics. */
|
854 |
|
|
|
855 |
|
|
static inline void
|
856 |
|
|
restore_extension_diagnostics (int flags)
|
857 |
|
|
{
|
858 |
|
|
cpp_opts->pedantic = pedantic = flags & 1;
|
859 |
|
|
warn_pointer_arith = (flags >> 1) & 1;
|
860 |
|
|
cpp_opts->warn_traditional = warn_traditional = (flags >> 2) & 1;
|
861 |
|
|
flag_iso = (flags >> 3) & 1;
|
862 |
|
|
cpp_opts->warn_long_long = warn_long_long = (flags >> 4) & 1;
|
863 |
|
|
warn_cxx_compat = (flags >> 5) & 1;
|
864 |
|
|
}
|
865 |
|
|
|
866 |
|
|
/* Possibly kinds of declarator to parse. */
|
867 |
|
|
typedef enum c_dtr_syn {
|
868 |
|
|
/* A normal declarator with an identifier. */
|
869 |
|
|
C_DTR_NORMAL,
|
870 |
|
|
/* An abstract declarator (maybe empty). */
|
871 |
|
|
C_DTR_ABSTRACT,
|
872 |
|
|
/* A parameter declarator: may be either, but after a type name does
|
873 |
|
|
not redeclare a typedef name as an identifier if it can
|
874 |
|
|
alternatively be interpreted as a typedef name; see DR#009,
|
875 |
|
|
applied in C90 TC1, omitted from C99 and reapplied in C99 TC2
|
876 |
|
|
following DR#249. For example, given a typedef T, "int T" and
|
877 |
|
|
"int *T" are valid parameter declarations redeclaring T, while
|
878 |
|
|
"int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are
|
879 |
|
|
abstract declarators rather than involving redundant parentheses;
|
880 |
|
|
the same applies with attributes inside the parentheses before
|
881 |
|
|
"T". */
|
882 |
|
|
C_DTR_PARM
|
883 |
|
|
} c_dtr_syn;
|
884 |
|
|
|
885 |
|
|
static void c_parser_external_declaration (c_parser *);
|
886 |
|
|
static void c_parser_asm_definition (c_parser *);
|
887 |
|
|
static void c_parser_declaration_or_fndef (c_parser *, bool, bool, bool, bool);
|
888 |
|
|
static void c_parser_declspecs (c_parser *, struct c_declspecs *, bool, bool,
|
889 |
|
|
bool);
|
890 |
|
|
static struct c_typespec c_parser_enum_specifier (c_parser *);
|
891 |
|
|
static struct c_typespec c_parser_struct_or_union_specifier (c_parser *);
|
892 |
|
|
static tree c_parser_struct_declaration (c_parser *);
|
893 |
|
|
static struct c_typespec c_parser_typeof_specifier (c_parser *);
|
894 |
|
|
static struct c_declarator *c_parser_declarator (c_parser *, bool, c_dtr_syn,
|
895 |
|
|
bool *);
|
896 |
|
|
static struct c_declarator *c_parser_direct_declarator (c_parser *, bool,
|
897 |
|
|
c_dtr_syn, bool *);
|
898 |
|
|
static struct c_declarator *c_parser_direct_declarator_inner (c_parser *,
|
899 |
|
|
bool,
|
900 |
|
|
struct c_declarator *);
|
901 |
|
|
static struct c_arg_info *c_parser_parms_declarator (c_parser *, bool, tree);
|
902 |
|
|
static struct c_arg_info *c_parser_parms_list_declarator (c_parser *, tree);
|
903 |
|
|
static struct c_parm *c_parser_parameter_declaration (c_parser *, tree);
|
904 |
|
|
static tree c_parser_simple_asm_expr (c_parser *);
|
905 |
|
|
static tree c_parser_attributes (c_parser *);
|
906 |
|
|
static struct c_type_name *c_parser_type_name (c_parser *);
|
907 |
|
|
static struct c_expr c_parser_initializer (c_parser *);
|
908 |
|
|
static struct c_expr c_parser_braced_init (c_parser *, tree, bool);
|
909 |
|
|
static void c_parser_initelt (c_parser *);
|
910 |
|
|
static void c_parser_initval (c_parser *, struct c_expr *);
|
911 |
|
|
static tree c_parser_compound_statement (c_parser *);
|
912 |
|
|
static void c_parser_compound_statement_nostart (c_parser *);
|
913 |
|
|
static void c_parser_label (c_parser *);
|
914 |
|
|
static void c_parser_statement (c_parser *);
|
915 |
|
|
static void c_parser_statement_after_labels (c_parser *);
|
916 |
|
|
static void c_parser_if_statement (c_parser *);
|
917 |
|
|
static void c_parser_switch_statement (c_parser *);
|
918 |
|
|
static void c_parser_while_statement (c_parser *);
|
919 |
|
|
static void c_parser_do_statement (c_parser *);
|
920 |
|
|
static void c_parser_for_statement (c_parser *);
|
921 |
|
|
static tree c_parser_asm_statement (c_parser *);
|
922 |
|
|
static tree c_parser_asm_operands (c_parser *, bool);
|
923 |
|
|
static tree c_parser_asm_goto_operands (c_parser *);
|
924 |
|
|
static tree c_parser_asm_clobbers (c_parser *);
|
925 |
|
|
static struct c_expr c_parser_expr_no_commas (c_parser *, struct c_expr *);
|
926 |
|
|
static struct c_expr c_parser_conditional_expression (c_parser *,
|
927 |
|
|
struct c_expr *);
|
928 |
|
|
static struct c_expr c_parser_binary_expression (c_parser *, struct c_expr *);
|
929 |
|
|
static struct c_expr c_parser_cast_expression (c_parser *, struct c_expr *);
|
930 |
|
|
static struct c_expr c_parser_unary_expression (c_parser *);
|
931 |
|
|
static struct c_expr c_parser_sizeof_expression (c_parser *);
|
932 |
|
|
static struct c_expr c_parser_alignof_expression (c_parser *);
|
933 |
|
|
static struct c_expr c_parser_postfix_expression (c_parser *);
|
934 |
|
|
static struct c_expr c_parser_postfix_expression_after_paren_type (c_parser *,
|
935 |
|
|
struct c_type_name *,
|
936 |
|
|
location_t);
|
937 |
|
|
static struct c_expr c_parser_postfix_expression_after_primary (c_parser *,
|
938 |
|
|
location_t loc,
|
939 |
|
|
struct c_expr);
|
940 |
|
|
static struct c_expr c_parser_expression (c_parser *);
|
941 |
|
|
static struct c_expr c_parser_expression_conv (c_parser *);
|
942 |
|
|
static VEC(tree,gc) *c_parser_expr_list (c_parser *, bool, bool,
|
943 |
|
|
VEC(tree,gc) **);
|
944 |
|
|
static void c_parser_omp_construct (c_parser *);
|
945 |
|
|
static void c_parser_omp_threadprivate (c_parser *);
|
946 |
|
|
static void c_parser_omp_barrier (c_parser *);
|
947 |
|
|
static void c_parser_omp_flush (c_parser *);
|
948 |
|
|
static void c_parser_omp_taskwait (c_parser *);
|
949 |
|
|
|
950 |
|
|
enum pragma_context { pragma_external, pragma_stmt, pragma_compound };
|
951 |
|
|
static bool c_parser_pragma (c_parser *, enum pragma_context);
|
952 |
|
|
|
953 |
|
|
/* These Objective-C parser functions are only ever called when
|
954 |
|
|
compiling Objective-C. */
|
955 |
|
|
static void c_parser_objc_class_definition (c_parser *);
|
956 |
|
|
static void c_parser_objc_class_instance_variables (c_parser *);
|
957 |
|
|
static void c_parser_objc_class_declaration (c_parser *);
|
958 |
|
|
static void c_parser_objc_alias_declaration (c_parser *);
|
959 |
|
|
static void c_parser_objc_protocol_definition (c_parser *);
|
960 |
|
|
static enum tree_code c_parser_objc_method_type (c_parser *);
|
961 |
|
|
static void c_parser_objc_method_definition (c_parser *);
|
962 |
|
|
static void c_parser_objc_methodprotolist (c_parser *);
|
963 |
|
|
static void c_parser_objc_methodproto (c_parser *);
|
964 |
|
|
static tree c_parser_objc_method_decl (c_parser *);
|
965 |
|
|
static tree c_parser_objc_type_name (c_parser *);
|
966 |
|
|
static tree c_parser_objc_protocol_refs (c_parser *);
|
967 |
|
|
static void c_parser_objc_try_catch_statement (c_parser *);
|
968 |
|
|
static void c_parser_objc_synchronized_statement (c_parser *);
|
969 |
|
|
static tree c_parser_objc_selector (c_parser *);
|
970 |
|
|
static tree c_parser_objc_selector_arg (c_parser *);
|
971 |
|
|
static tree c_parser_objc_receiver (c_parser *);
|
972 |
|
|
static tree c_parser_objc_message_args (c_parser *);
|
973 |
|
|
static tree c_parser_objc_keywordexpr (c_parser *);
|
974 |
|
|
|
975 |
|
|
/* Parse a translation unit (C90 6.7, C99 6.9).
|
976 |
|
|
|
977 |
|
|
translation-unit:
|
978 |
|
|
external-declarations
|
979 |
|
|
|
980 |
|
|
external-declarations:
|
981 |
|
|
external-declaration
|
982 |
|
|
external-declarations external-declaration
|
983 |
|
|
|
984 |
|
|
GNU extensions:
|
985 |
|
|
|
986 |
|
|
translation-unit:
|
987 |
|
|
empty
|
988 |
|
|
*/
|
989 |
|
|
|
990 |
|
|
static void
|
991 |
|
|
c_parser_translation_unit (c_parser *parser)
|
992 |
|
|
{
|
993 |
|
|
if (c_parser_next_token_is (parser, CPP_EOF))
|
994 |
|
|
{
|
995 |
|
|
pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
|
996 |
|
|
"ISO C forbids an empty translation unit");
|
997 |
|
|
}
|
998 |
|
|
else
|
999 |
|
|
{
|
1000 |
|
|
void *obstack_position = obstack_alloc (&parser_obstack, 0);
|
1001 |
|
|
mark_valid_location_for_stdc_pragma (false);
|
1002 |
|
|
do
|
1003 |
|
|
{
|
1004 |
|
|
ggc_collect ();
|
1005 |
|
|
c_parser_external_declaration (parser);
|
1006 |
|
|
obstack_free (&parser_obstack, obstack_position);
|
1007 |
|
|
}
|
1008 |
|
|
while (c_parser_next_token_is_not (parser, CPP_EOF));
|
1009 |
|
|
}
|
1010 |
|
|
}
|
1011 |
|
|
|
1012 |
|
|
/* Parse an external declaration (C90 6.7, C99 6.9).
|
1013 |
|
|
|
1014 |
|
|
external-declaration:
|
1015 |
|
|
function-definition
|
1016 |
|
|
declaration
|
1017 |
|
|
|
1018 |
|
|
GNU extensions:
|
1019 |
|
|
|
1020 |
|
|
external-declaration:
|
1021 |
|
|
asm-definition
|
1022 |
|
|
;
|
1023 |
|
|
__extension__ external-declaration
|
1024 |
|
|
|
1025 |
|
|
Objective-C:
|
1026 |
|
|
|
1027 |
|
|
external-declaration:
|
1028 |
|
|
objc-class-definition
|
1029 |
|
|
objc-class-declaration
|
1030 |
|
|
objc-alias-declaration
|
1031 |
|
|
objc-protocol-definition
|
1032 |
|
|
objc-method-definition
|
1033 |
|
|
@end
|
1034 |
|
|
*/
|
1035 |
|
|
|
1036 |
|
|
static void
|
1037 |
|
|
c_parser_external_declaration (c_parser *parser)
|
1038 |
|
|
{
|
1039 |
|
|
int ext;
|
1040 |
|
|
switch (c_parser_peek_token (parser)->type)
|
1041 |
|
|
{
|
1042 |
|
|
case CPP_KEYWORD:
|
1043 |
|
|
switch (c_parser_peek_token (parser)->keyword)
|
1044 |
|
|
{
|
1045 |
|
|
case RID_EXTENSION:
|
1046 |
|
|
ext = disable_extension_diagnostics ();
|
1047 |
|
|
c_parser_consume_token (parser);
|
1048 |
|
|
c_parser_external_declaration (parser);
|
1049 |
|
|
restore_extension_diagnostics (ext);
|
1050 |
|
|
break;
|
1051 |
|
|
case RID_ASM:
|
1052 |
|
|
c_parser_asm_definition (parser);
|
1053 |
|
|
break;
|
1054 |
|
|
case RID_AT_INTERFACE:
|
1055 |
|
|
case RID_AT_IMPLEMENTATION:
|
1056 |
|
|
gcc_assert (c_dialect_objc ());
|
1057 |
|
|
c_parser_objc_class_definition (parser);
|
1058 |
|
|
break;
|
1059 |
|
|
case RID_CLASS:
|
1060 |
|
|
gcc_assert (c_dialect_objc ());
|
1061 |
|
|
c_parser_objc_class_declaration (parser);
|
1062 |
|
|
break;
|
1063 |
|
|
case RID_AT_ALIAS:
|
1064 |
|
|
gcc_assert (c_dialect_objc ());
|
1065 |
|
|
c_parser_objc_alias_declaration (parser);
|
1066 |
|
|
break;
|
1067 |
|
|
case RID_AT_PROTOCOL:
|
1068 |
|
|
gcc_assert (c_dialect_objc ());
|
1069 |
|
|
c_parser_objc_protocol_definition (parser);
|
1070 |
|
|
break;
|
1071 |
|
|
case RID_AT_END:
|
1072 |
|
|
gcc_assert (c_dialect_objc ());
|
1073 |
|
|
c_parser_consume_token (parser);
|
1074 |
|
|
objc_finish_implementation ();
|
1075 |
|
|
break;
|
1076 |
|
|
default:
|
1077 |
|
|
goto decl_or_fndef;
|
1078 |
|
|
}
|
1079 |
|
|
break;
|
1080 |
|
|
case CPP_SEMICOLON:
|
1081 |
|
|
pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
|
1082 |
|
|
"ISO C does not allow extra %<;%> outside of a function");
|
1083 |
|
|
c_parser_consume_token (parser);
|
1084 |
|
|
break;
|
1085 |
|
|
case CPP_PRAGMA:
|
1086 |
|
|
mark_valid_location_for_stdc_pragma (true);
|
1087 |
|
|
c_parser_pragma (parser, pragma_external);
|
1088 |
|
|
mark_valid_location_for_stdc_pragma (false);
|
1089 |
|
|
break;
|
1090 |
|
|
case CPP_PLUS:
|
1091 |
|
|
case CPP_MINUS:
|
1092 |
|
|
if (c_dialect_objc ())
|
1093 |
|
|
{
|
1094 |
|
|
c_parser_objc_method_definition (parser);
|
1095 |
|
|
break;
|
1096 |
|
|
}
|
1097 |
|
|
/* Else fall through, and yield a syntax error trying to parse
|
1098 |
|
|
as a declaration or function definition. */
|
1099 |
|
|
default:
|
1100 |
|
|
decl_or_fndef:
|
1101 |
|
|
/* A declaration or a function definition. We can only tell
|
1102 |
|
|
which after parsing the declaration specifiers, if any, and
|
1103 |
|
|
the first declarator. */
|
1104 |
|
|
c_parser_declaration_or_fndef (parser, true, true, false, true);
|
1105 |
|
|
break;
|
1106 |
|
|
}
|
1107 |
|
|
}
|
1108 |
|
|
|
1109 |
|
|
|
1110 |
|
|
/* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
|
1111 |
|
|
6.7, 6.9.1). If FNDEF_OK is true, a function definition is
|
1112 |
|
|
accepted; otherwise (old-style parameter declarations) only other
|
1113 |
|
|
declarations are accepted. If NESTED is true, we are inside a
|
1114 |
|
|
function or parsing old-style parameter declarations; any functions
|
1115 |
|
|
encountered are nested functions and declaration specifiers are
|
1116 |
|
|
required; otherwise we are at top level and functions are normal
|
1117 |
|
|
functions and declaration specifiers may be optional. If EMPTY_OK
|
1118 |
|
|
is true, empty declarations are OK (subject to all other
|
1119 |
|
|
constraints); otherwise (old-style parameter declarations) they are
|
1120 |
|
|
diagnosed. If START_ATTR_OK is true, the declaration specifiers
|
1121 |
|
|
may start with attributes; otherwise they may not.
|
1122 |
|
|
|
1123 |
|
|
declaration:
|
1124 |
|
|
declaration-specifiers init-declarator-list[opt] ;
|
1125 |
|
|
|
1126 |
|
|
function-definition:
|
1127 |
|
|
declaration-specifiers[opt] declarator declaration-list[opt]
|
1128 |
|
|
compound-statement
|
1129 |
|
|
|
1130 |
|
|
declaration-list:
|
1131 |
|
|
declaration
|
1132 |
|
|
declaration-list declaration
|
1133 |
|
|
|
1134 |
|
|
init-declarator-list:
|
1135 |
|
|
init-declarator
|
1136 |
|
|
init-declarator-list , init-declarator
|
1137 |
|
|
|
1138 |
|
|
init-declarator:
|
1139 |
|
|
declarator simple-asm-expr[opt] attributes[opt]
|
1140 |
|
|
declarator simple-asm-expr[opt] attributes[opt] = initializer
|
1141 |
|
|
|
1142 |
|
|
GNU extensions:
|
1143 |
|
|
|
1144 |
|
|
nested-function-definition:
|
1145 |
|
|
declaration-specifiers declarator declaration-list[opt]
|
1146 |
|
|
compound-statement
|
1147 |
|
|
|
1148 |
|
|
The simple-asm-expr and attributes are GNU extensions.
|
1149 |
|
|
|
1150 |
|
|
This function does not handle __extension__; that is handled in its
|
1151 |
|
|
callers. ??? Following the old parser, __extension__ may start
|
1152 |
|
|
external declarations, declarations in functions and declarations
|
1153 |
|
|
at the start of "for" loops, but not old-style parameter
|
1154 |
|
|
declarations.
|
1155 |
|
|
|
1156 |
|
|
C99 requires declaration specifiers in a function definition; the
|
1157 |
|
|
absence is diagnosed through the diagnosis of implicit int. In GNU
|
1158 |
|
|
C we also allow but diagnose declarations without declaration
|
1159 |
|
|
specifiers, but only at top level (elsewhere they conflict with
|
1160 |
|
|
other syntax).
|
1161 |
|
|
|
1162 |
|
|
OpenMP:
|
1163 |
|
|
|
1164 |
|
|
declaration:
|
1165 |
|
|
threadprivate-directive */
|
1166 |
|
|
|
1167 |
|
|
static void
|
1168 |
|
|
c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok, bool empty_ok,
|
1169 |
|
|
bool nested, bool start_attr_ok)
|
1170 |
|
|
{
|
1171 |
|
|
struct c_declspecs *specs;
|
1172 |
|
|
tree prefix_attrs;
|
1173 |
|
|
tree all_prefix_attrs;
|
1174 |
|
|
bool diagnosed_no_specs = false;
|
1175 |
|
|
location_t here = c_parser_peek_token (parser)->location;
|
1176 |
|
|
|
1177 |
|
|
specs = build_null_declspecs ();
|
1178 |
|
|
c_parser_declspecs (parser, specs, true, true, start_attr_ok);
|
1179 |
|
|
if (parser->error)
|
1180 |
|
|
{
|
1181 |
|
|
c_parser_skip_to_end_of_block_or_statement (parser);
|
1182 |
|
|
return;
|
1183 |
|
|
}
|
1184 |
|
|
if (nested && !specs->declspecs_seen_p)
|
1185 |
|
|
{
|
1186 |
|
|
c_parser_error (parser, "expected declaration specifiers");
|
1187 |
|
|
c_parser_skip_to_end_of_block_or_statement (parser);
|
1188 |
|
|
return;
|
1189 |
|
|
}
|
1190 |
|
|
finish_declspecs (specs);
|
1191 |
|
|
if (c_parser_next_token_is (parser, CPP_SEMICOLON))
|
1192 |
|
|
{
|
1193 |
|
|
if (empty_ok)
|
1194 |
|
|
shadow_tag (specs);
|
1195 |
|
|
else
|
1196 |
|
|
{
|
1197 |
|
|
shadow_tag_warned (specs, 1);
|
1198 |
|
|
pedwarn (here, 0, "empty declaration");
|
1199 |
|
|
}
|
1200 |
|
|
c_parser_consume_token (parser);
|
1201 |
|
|
return;
|
1202 |
|
|
}
|
1203 |
|
|
pending_xref_error ();
|
1204 |
|
|
prefix_attrs = specs->attrs;
|
1205 |
|
|
all_prefix_attrs = prefix_attrs;
|
1206 |
|
|
specs->attrs = NULL_TREE;
|
1207 |
|
|
while (true)
|
1208 |
|
|
{
|
1209 |
|
|
struct c_declarator *declarator;
|
1210 |
|
|
bool dummy = false;
|
1211 |
|
|
tree fnbody;
|
1212 |
|
|
/* Declaring either one or more declarators (in which case we
|
1213 |
|
|
should diagnose if there were no declaration specifiers) or a
|
1214 |
|
|
function definition (in which case the diagnostic for
|
1215 |
|
|
implicit int suffices). */
|
1216 |
|
|
declarator = c_parser_declarator (parser, specs->type_seen_p,
|
1217 |
|
|
C_DTR_NORMAL, &dummy);
|
1218 |
|
|
if (declarator == NULL)
|
1219 |
|
|
{
|
1220 |
|
|
c_parser_skip_to_end_of_block_or_statement (parser);
|
1221 |
|
|
return;
|
1222 |
|
|
}
|
1223 |
|
|
if (c_parser_next_token_is (parser, CPP_EQ)
|
1224 |
|
|
|| c_parser_next_token_is (parser, CPP_COMMA)
|
1225 |
|
|
|| c_parser_next_token_is (parser, CPP_SEMICOLON)
|
1226 |
|
|
|| c_parser_next_token_is_keyword (parser, RID_ASM)
|
1227 |
|
|
|| c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
|
1228 |
|
|
{
|
1229 |
|
|
tree asm_name = NULL_TREE;
|
1230 |
|
|
tree postfix_attrs = NULL_TREE;
|
1231 |
|
|
if (!diagnosed_no_specs && !specs->declspecs_seen_p)
|
1232 |
|
|
{
|
1233 |
|
|
diagnosed_no_specs = true;
|
1234 |
|
|
pedwarn (here, 0, "data definition has no type or storage class");
|
1235 |
|
|
}
|
1236 |
|
|
/* Having seen a data definition, there cannot now be a
|
1237 |
|
|
function definition. */
|
1238 |
|
|
fndef_ok = false;
|
1239 |
|
|
if (c_parser_next_token_is_keyword (parser, RID_ASM))
|
1240 |
|
|
asm_name = c_parser_simple_asm_expr (parser);
|
1241 |
|
|
if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
|
1242 |
|
|
postfix_attrs = c_parser_attributes (parser);
|
1243 |
|
|
if (c_parser_next_token_is (parser, CPP_EQ))
|
1244 |
|
|
{
|
1245 |
|
|
tree d;
|
1246 |
|
|
struct c_expr init;
|
1247 |
|
|
location_t init_loc;
|
1248 |
|
|
c_parser_consume_token (parser);
|
1249 |
|
|
/* The declaration of the variable is in effect while
|
1250 |
|
|
its initializer is parsed. */
|
1251 |
|
|
d = start_decl (declarator, specs, true,
|
1252 |
|
|
chainon (postfix_attrs, all_prefix_attrs));
|
1253 |
|
|
if (!d)
|
1254 |
|
|
d = error_mark_node;
|
1255 |
|
|
start_init (d, asm_name, global_bindings_p ());
|
1256 |
|
|
init_loc = c_parser_peek_token (parser)->location;
|
1257 |
|
|
init = c_parser_initializer (parser);
|
1258 |
|
|
finish_init ();
|
1259 |
|
|
if (d != error_mark_node)
|
1260 |
|
|
{
|
1261 |
|
|
maybe_warn_string_init (TREE_TYPE (d), init);
|
1262 |
|
|
finish_decl (d, init_loc, init.value,
|
1263 |
|
|
init.original_type, asm_name);
|
1264 |
|
|
}
|
1265 |
|
|
}
|
1266 |
|
|
else
|
1267 |
|
|
{
|
1268 |
|
|
tree d = start_decl (declarator, specs, false,
|
1269 |
|
|
chainon (postfix_attrs,
|
1270 |
|
|
all_prefix_attrs));
|
1271 |
|
|
if (d)
|
1272 |
|
|
finish_decl (d, UNKNOWN_LOCATION, NULL_TREE,
|
1273 |
|
|
NULL_TREE, asm_name);
|
1274 |
|
|
}
|
1275 |
|
|
if (c_parser_next_token_is (parser, CPP_COMMA))
|
1276 |
|
|
{
|
1277 |
|
|
c_parser_consume_token (parser);
|
1278 |
|
|
if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
|
1279 |
|
|
all_prefix_attrs = chainon (c_parser_attributes (parser),
|
1280 |
|
|
prefix_attrs);
|
1281 |
|
|
else
|
1282 |
|
|
all_prefix_attrs = prefix_attrs;
|
1283 |
|
|
continue;
|
1284 |
|
|
}
|
1285 |
|
|
else if (c_parser_next_token_is (parser, CPP_SEMICOLON))
|
1286 |
|
|
{
|
1287 |
|
|
c_parser_consume_token (parser);
|
1288 |
|
|
return;
|
1289 |
|
|
}
|
1290 |
|
|
else
|
1291 |
|
|
{
|
1292 |
|
|
c_parser_error (parser, "expected %<,%> or %<;%>");
|
1293 |
|
|
c_parser_skip_to_end_of_block_or_statement (parser);
|
1294 |
|
|
return;
|
1295 |
|
|
}
|
1296 |
|
|
}
|
1297 |
|
|
else if (!fndef_ok)
|
1298 |
|
|
{
|
1299 |
|
|
c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, "
|
1300 |
|
|
"%<asm%> or %<__attribute__%>");
|
1301 |
|
|
c_parser_skip_to_end_of_block_or_statement (parser);
|
1302 |
|
|
return;
|
1303 |
|
|
}
|
1304 |
|
|
/* Function definition (nested or otherwise). */
|
1305 |
|
|
if (nested)
|
1306 |
|
|
{
|
1307 |
|
|
pedwarn (here, OPT_pedantic, "ISO C forbids nested functions");
|
1308 |
|
|
c_push_function_context ();
|
1309 |
|
|
}
|
1310 |
|
|
if (!start_function (specs, declarator, all_prefix_attrs))
|
1311 |
|
|
{
|
1312 |
|
|
/* This can appear in many cases looking nothing like a
|
1313 |
|
|
function definition, so we don't give a more specific
|
1314 |
|
|
error suggesting there was one. */
|
1315 |
|
|
c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
|
1316 |
|
|
"or %<__attribute__%>");
|
1317 |
|
|
if (nested)
|
1318 |
|
|
c_pop_function_context ();
|
1319 |
|
|
break;
|
1320 |
|
|
}
|
1321 |
|
|
/* Parse old-style parameter declarations. ??? Attributes are
|
1322 |
|
|
not allowed to start declaration specifiers here because of a
|
1323 |
|
|
syntax conflict between a function declaration with attribute
|
1324 |
|
|
suffix and a function definition with an attribute prefix on
|
1325 |
|
|
first old-style parameter declaration. Following the old
|
1326 |
|
|
parser, they are not accepted on subsequent old-style
|
1327 |
|
|
parameter declarations either. However, there is no
|
1328 |
|
|
ambiguity after the first declaration, nor indeed on the
|
1329 |
|
|
first as long as we don't allow postfix attributes after a
|
1330 |
|
|
declarator with a nonempty identifier list in a definition;
|
1331 |
|
|
and postfix attributes have never been accepted here in
|
1332 |
|
|
function definitions either. */
|
1333 |
|
|
while (c_parser_next_token_is_not (parser, CPP_EOF)
|
1334 |
|
|
&& c_parser_next_token_is_not (parser, CPP_OPEN_BRACE))
|
1335 |
|
|
c_parser_declaration_or_fndef (parser, false, false, true, false);
|
1336 |
|
|
store_parm_decls ();
|
1337 |
|
|
DECL_STRUCT_FUNCTION (current_function_decl)->function_start_locus
|
1338 |
|
|
= c_parser_peek_token (parser)->location;
|
1339 |
|
|
fnbody = c_parser_compound_statement (parser);
|
1340 |
|
|
if (nested)
|
1341 |
|
|
{
|
1342 |
|
|
tree decl = current_function_decl;
|
1343 |
|
|
/* Mark nested functions as needing static-chain initially.
|
1344 |
|
|
lower_nested_functions will recompute it but the
|
1345 |
|
|
DECL_STATIC_CHAIN flag is also used before that happens,
|
1346 |
|
|
by initializer_constant_valid_p. See gcc.dg/nested-fn-2.c. */
|
1347 |
|
|
DECL_STATIC_CHAIN (decl) = 1;
|
1348 |
|
|
add_stmt (fnbody);
|
1349 |
|
|
finish_function ();
|
1350 |
|
|
c_pop_function_context ();
|
1351 |
|
|
add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl), DECL_EXPR, decl));
|
1352 |
|
|
}
|
1353 |
|
|
else
|
1354 |
|
|
{
|
1355 |
|
|
add_stmt (fnbody);
|
1356 |
|
|
finish_function ();
|
1357 |
|
|
}
|
1358 |
|
|
break;
|
1359 |
|
|
}
|
1360 |
|
|
}
|
1361 |
|
|
|
1362 |
|
|
/* Parse an asm-definition (asm() outside a function body). This is a
|
1363 |
|
|
GNU extension.
|
1364 |
|
|
|
1365 |
|
|
asm-definition:
|
1366 |
|
|
simple-asm-expr ;
|
1367 |
|
|
*/
|
1368 |
|
|
|
1369 |
|
|
static void
|
1370 |
|
|
c_parser_asm_definition (c_parser *parser)
|
1371 |
|
|
{
|
1372 |
|
|
tree asm_str = c_parser_simple_asm_expr (parser);
|
1373 |
|
|
if (asm_str)
|
1374 |
|
|
cgraph_add_asm_node (asm_str);
|
1375 |
|
|
c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
|
1376 |
|
|
}
|
1377 |
|
|
|
1378 |
|
|
/* Parse some declaration specifiers (possibly none) (C90 6.5, C99
|
1379 |
|
|
6.7), adding them to SPECS (which may already include some).
|
1380 |
|
|
Storage class specifiers are accepted iff SCSPEC_OK; type
|
1381 |
|
|
specifiers are accepted iff TYPESPEC_OK; attributes are accepted at
|
1382 |
|
|
the start iff START_ATTR_OK.
|
1383 |
|
|
|
1384 |
|
|
declaration-specifiers:
|
1385 |
|
|
storage-class-specifier declaration-specifiers[opt]
|
1386 |
|
|
type-specifier declaration-specifiers[opt]
|
1387 |
|
|
type-qualifier declaration-specifiers[opt]
|
1388 |
|
|
function-specifier declaration-specifiers[opt]
|
1389 |
|
|
|
1390 |
|
|
Function specifiers (inline) are from C99, and are currently
|
1391 |
|
|
handled as storage class specifiers, as is __thread.
|
1392 |
|
|
|
1393 |
|
|
C90 6.5.1, C99 6.7.1:
|
1394 |
|
|
storage-class-specifier:
|
1395 |
|
|
typedef
|
1396 |
|
|
extern
|
1397 |
|
|
static
|
1398 |
|
|
auto
|
1399 |
|
|
register
|
1400 |
|
|
|
1401 |
|
|
C99 6.7.4:
|
1402 |
|
|
function-specifier:
|
1403 |
|
|
inline
|
1404 |
|
|
|
1405 |
|
|
C90 6.5.2, C99 6.7.2:
|
1406 |
|
|
type-specifier:
|
1407 |
|
|
void
|
1408 |
|
|
char
|
1409 |
|
|
short
|
1410 |
|
|
int
|
1411 |
|
|
long
|
1412 |
|
|
float
|
1413 |
|
|
double
|
1414 |
|
|
signed
|
1415 |
|
|
unsigned
|
1416 |
|
|
_Bool
|
1417 |
|
|
_Complex
|
1418 |
|
|
[_Imaginary removed in C99 TC2]
|
1419 |
|
|
struct-or-union-specifier
|
1420 |
|
|
enum-specifier
|
1421 |
|
|
typedef-name
|
1422 |
|
|
|
1423 |
|
|
(_Bool and _Complex are new in C99.)
|
1424 |
|
|
|
1425 |
|
|
C90 6.5.3, C99 6.7.3:
|
1426 |
|
|
|
1427 |
|
|
type-qualifier:
|
1428 |
|
|
const
|
1429 |
|
|
restrict
|
1430 |
|
|
volatile
|
1431 |
|
|
address-space-qualifier
|
1432 |
|
|
|
1433 |
|
|
(restrict is new in C99.)
|
1434 |
|
|
|
1435 |
|
|
GNU extensions:
|
1436 |
|
|
|
1437 |
|
|
declaration-specifiers:
|
1438 |
|
|
attributes declaration-specifiers[opt]
|
1439 |
|
|
|
1440 |
|
|
type-qualifier:
|
1441 |
|
|
address-space
|
1442 |
|
|
|
1443 |
|
|
address-space:
|
1444 |
|
|
identifier recognized by the target
|
1445 |
|
|
|
1446 |
|
|
storage-class-specifier:
|
1447 |
|
|
__thread
|
1448 |
|
|
|
1449 |
|
|
type-specifier:
|
1450 |
|
|
typeof-specifier
|
1451 |
|
|
_Decimal32
|
1452 |
|
|
_Decimal64
|
1453 |
|
|
_Decimal128
|
1454 |
|
|
_Fract
|
1455 |
|
|
_Accum
|
1456 |
|
|
_Sat
|
1457 |
|
|
|
1458 |
|
|
(_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
|
1459 |
|
|
http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
|
1460 |
|
|
|
1461 |
|
|
Objective-C:
|
1462 |
|
|
|
1463 |
|
|
type-specifier:
|
1464 |
|
|
class-name objc-protocol-refs[opt]
|
1465 |
|
|
typedef-name objc-protocol-refs
|
1466 |
|
|
objc-protocol-refs
|
1467 |
|
|
*/
|
1468 |
|
|
|
1469 |
|
|
static void
|
1470 |
|
|
c_parser_declspecs (c_parser *parser, struct c_declspecs *specs,
|
1471 |
|
|
bool scspec_ok, bool typespec_ok, bool start_attr_ok)
|
1472 |
|
|
{
|
1473 |
|
|
bool attrs_ok = start_attr_ok;
|
1474 |
|
|
bool seen_type = specs->type_seen_p;
|
1475 |
|
|
while (c_parser_next_token_is (parser, CPP_NAME)
|
1476 |
|
|
|| c_parser_next_token_is (parser, CPP_KEYWORD)
|
1477 |
|
|
|| (c_dialect_objc () && c_parser_next_token_is (parser, CPP_LESS)))
|
1478 |
|
|
{
|
1479 |
|
|
struct c_typespec t;
|
1480 |
|
|
tree attrs;
|
1481 |
|
|
location_t loc = c_parser_peek_token (parser)->location;
|
1482 |
|
|
if (c_parser_next_token_is (parser, CPP_NAME))
|
1483 |
|
|
{
|
1484 |
|
|
tree value = c_parser_peek_token (parser)->value;
|
1485 |
|
|
c_id_kind kind = c_parser_peek_token (parser)->id_kind;
|
1486 |
|
|
|
1487 |
|
|
if (kind == C_ID_ADDRSPACE)
|
1488 |
|
|
{
|
1489 |
|
|
addr_space_t as
|
1490 |
|
|
= c_parser_peek_token (parser)->keyword - RID_FIRST_ADDR_SPACE;
|
1491 |
|
|
declspecs_add_addrspace (specs, as);
|
1492 |
|
|
c_parser_consume_token (parser);
|
1493 |
|
|
attrs_ok = true;
|
1494 |
|
|
continue;
|
1495 |
|
|
}
|
1496 |
|
|
|
1497 |
|
|
/* This finishes the specifiers unless a type name is OK, it
|
1498 |
|
|
is declared as a type name and a type name hasn't yet
|
1499 |
|
|
been seen. */
|
1500 |
|
|
if (!typespec_ok || seen_type
|
1501 |
|
|
|| (kind != C_ID_TYPENAME && kind != C_ID_CLASSNAME))
|
1502 |
|
|
break;
|
1503 |
|
|
c_parser_consume_token (parser);
|
1504 |
|
|
seen_type = true;
|
1505 |
|
|
attrs_ok = true;
|
1506 |
|
|
if (kind == C_ID_TYPENAME
|
1507 |
|
|
&& (!c_dialect_objc ()
|
1508 |
|
|
|| c_parser_next_token_is_not (parser, CPP_LESS)))
|
1509 |
|
|
{
|
1510 |
|
|
t.kind = ctsk_typedef;
|
1511 |
|
|
/* For a typedef name, record the meaning, not the name.
|
1512 |
|
|
In case of 'foo foo, bar;'. */
|
1513 |
|
|
t.spec = lookup_name (value);
|
1514 |
|
|
t.expr = NULL_TREE;
|
1515 |
|
|
t.expr_const_operands = true;
|
1516 |
|
|
}
|
1517 |
|
|
else
|
1518 |
|
|
{
|
1519 |
|
|
tree proto = NULL_TREE;
|
1520 |
|
|
gcc_assert (c_dialect_objc ());
|
1521 |
|
|
t.kind = ctsk_objc;
|
1522 |
|
|
if (c_parser_next_token_is (parser, CPP_LESS))
|
1523 |
|
|
proto = c_parser_objc_protocol_refs (parser);
|
1524 |
|
|
t.spec = objc_get_protocol_qualified_type (value, proto);
|
1525 |
|
|
t.expr = NULL_TREE;
|
1526 |
|
|
t.expr_const_operands = true;
|
1527 |
|
|
}
|
1528 |
|
|
declspecs_add_type (loc, specs, t);
|
1529 |
|
|
continue;
|
1530 |
|
|
}
|
1531 |
|
|
if (c_parser_next_token_is (parser, CPP_LESS))
|
1532 |
|
|
{
|
1533 |
|
|
/* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
|
1534 |
|
|
nisse@lysator.liu.se. */
|
1535 |
|
|
tree proto;
|
1536 |
|
|
gcc_assert (c_dialect_objc ());
|
1537 |
|
|
if (!typespec_ok || seen_type)
|
1538 |
|
|
break;
|
1539 |
|
|
proto = c_parser_objc_protocol_refs (parser);
|
1540 |
|
|
t.kind = ctsk_objc;
|
1541 |
|
|
t.spec = objc_get_protocol_qualified_type (NULL_TREE, proto);
|
1542 |
|
|
t.expr = NULL_TREE;
|
1543 |
|
|
t.expr_const_operands = true;
|
1544 |
|
|
declspecs_add_type (loc, specs, t);
|
1545 |
|
|
continue;
|
1546 |
|
|
}
|
1547 |
|
|
gcc_assert (c_parser_next_token_is (parser, CPP_KEYWORD));
|
1548 |
|
|
switch (c_parser_peek_token (parser)->keyword)
|
1549 |
|
|
{
|
1550 |
|
|
case RID_STATIC:
|
1551 |
|
|
case RID_EXTERN:
|
1552 |
|
|
case RID_REGISTER:
|
1553 |
|
|
case RID_TYPEDEF:
|
1554 |
|
|
case RID_INLINE:
|
1555 |
|
|
case RID_AUTO:
|
1556 |
|
|
case RID_THREAD:
|
1557 |
|
|
if (!scspec_ok)
|
1558 |
|
|
goto out;
|
1559 |
|
|
attrs_ok = true;
|
1560 |
|
|
/* TODO: Distinguish between function specifiers (inline)
|
1561 |
|
|
and storage class specifiers, either here or in
|
1562 |
|
|
declspecs_add_scspec. */
|
1563 |
|
|
declspecs_add_scspec (specs, c_parser_peek_token (parser)->value);
|
1564 |
|
|
c_parser_consume_token (parser);
|
1565 |
|
|
break;
|
1566 |
|
|
case RID_UNSIGNED:
|
1567 |
|
|
case RID_LONG:
|
1568 |
|
|
case RID_SHORT:
|
1569 |
|
|
case RID_SIGNED:
|
1570 |
|
|
case RID_COMPLEX:
|
1571 |
|
|
case RID_INT:
|
1572 |
|
|
case RID_CHAR:
|
1573 |
|
|
case RID_FLOAT:
|
1574 |
|
|
case RID_DOUBLE:
|
1575 |
|
|
case RID_VOID:
|
1576 |
|
|
case RID_DFLOAT32:
|
1577 |
|
|
case RID_DFLOAT64:
|
1578 |
|
|
case RID_DFLOAT128:
|
1579 |
|
|
case RID_BOOL:
|
1580 |
|
|
case RID_FRACT:
|
1581 |
|
|
case RID_ACCUM:
|
1582 |
|
|
case RID_SAT:
|
1583 |
|
|
if (!typespec_ok)
|
1584 |
|
|
goto out;
|
1585 |
|
|
attrs_ok = true;
|
1586 |
|
|
seen_type = true;
|
1587 |
|
|
if (c_dialect_objc ())
|
1588 |
|
|
parser->objc_need_raw_identifier = true;
|
1589 |
|
|
t.kind = ctsk_resword;
|
1590 |
|
|
t.spec = c_parser_peek_token (parser)->value;
|
1591 |
|
|
t.expr = NULL_TREE;
|
1592 |
|
|
t.expr_const_operands = true;
|
1593 |
|
|
declspecs_add_type (loc, specs, t);
|
1594 |
|
|
c_parser_consume_token (parser);
|
1595 |
|
|
break;
|
1596 |
|
|
case RID_ENUM:
|
1597 |
|
|
if (!typespec_ok)
|
1598 |
|
|
goto out;
|
1599 |
|
|
attrs_ok = true;
|
1600 |
|
|
seen_type = true;
|
1601 |
|
|
t = c_parser_enum_specifier (parser);
|
1602 |
|
|
declspecs_add_type (loc, specs, t);
|
1603 |
|
|
break;
|
1604 |
|
|
case RID_STRUCT:
|
1605 |
|
|
case RID_UNION:
|
1606 |
|
|
if (!typespec_ok)
|
1607 |
|
|
goto out;
|
1608 |
|
|
attrs_ok = true;
|
1609 |
|
|
seen_type = true;
|
1610 |
|
|
t = c_parser_struct_or_union_specifier (parser);
|
1611 |
|
|
invoke_plugin_callbacks (PLUGIN_FINISH_TYPE, t.spec);
|
1612 |
|
|
declspecs_add_type (loc, specs, t);
|
1613 |
|
|
break;
|
1614 |
|
|
case RID_TYPEOF:
|
1615 |
|
|
/* ??? The old parser rejected typeof after other type
|
1616 |
|
|
specifiers, but is a syntax error the best way of
|
1617 |
|
|
handling this? */
|
1618 |
|
|
if (!typespec_ok || seen_type)
|
1619 |
|
|
goto out;
|
1620 |
|
|
attrs_ok = true;
|
1621 |
|
|
seen_type = true;
|
1622 |
|
|
t = c_parser_typeof_specifier (parser);
|
1623 |
|
|
declspecs_add_type (loc, specs, t);
|
1624 |
|
|
break;
|
1625 |
|
|
case RID_CONST:
|
1626 |
|
|
case RID_VOLATILE:
|
1627 |
|
|
case RID_RESTRICT:
|
1628 |
|
|
attrs_ok = true;
|
1629 |
|
|
declspecs_add_qual (specs, c_parser_peek_token (parser)->value);
|
1630 |
|
|
c_parser_consume_token (parser);
|
1631 |
|
|
break;
|
1632 |
|
|
case RID_ATTRIBUTE:
|
1633 |
|
|
if (!attrs_ok)
|
1634 |
|
|
goto out;
|
1635 |
|
|
attrs = c_parser_attributes (parser);
|
1636 |
|
|
declspecs_add_attrs (specs, attrs);
|
1637 |
|
|
break;
|
1638 |
|
|
default:
|
1639 |
|
|
goto out;
|
1640 |
|
|
}
|
1641 |
|
|
}
|
1642 |
|
|
out: ;
|
1643 |
|
|
}
|
1644 |
|
|
|
1645 |
|
|
/* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
|
1646 |
|
|
|
1647 |
|
|
enum-specifier:
|
1648 |
|
|
enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
|
1649 |
|
|
enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
|
1650 |
|
|
enum attributes[opt] identifier
|
1651 |
|
|
|
1652 |
|
|
The form with trailing comma is new in C99. The forms with
|
1653 |
|
|
attributes are GNU extensions. In GNU C, we accept any expression
|
1654 |
|
|
without commas in the syntax (assignment expressions, not just
|
1655 |
|
|
conditional expressions); assignment expressions will be diagnosed
|
1656 |
|
|
as non-constant.
|
1657 |
|
|
|
1658 |
|
|
enumerator-list:
|
1659 |
|
|
enumerator
|
1660 |
|
|
enumerator-list , enumerator
|
1661 |
|
|
|
1662 |
|
|
enumerator:
|
1663 |
|
|
enumeration-constant
|
1664 |
|
|
enumeration-constant = constant-expression
|
1665 |
|
|
*/
|
1666 |
|
|
|
1667 |
|
|
static struct c_typespec
|
1668 |
|
|
c_parser_enum_specifier (c_parser *parser)
|
1669 |
|
|
{
|
1670 |
|
|
struct c_typespec ret;
|
1671 |
|
|
tree attrs;
|
1672 |
|
|
tree ident = NULL_TREE;
|
1673 |
|
|
location_t enum_loc;
|
1674 |
|
|
location_t ident_loc = UNKNOWN_LOCATION; /* Quiet warning. */
|
1675 |
|
|
gcc_assert (c_parser_next_token_is_keyword (parser, RID_ENUM));
|
1676 |
|
|
enum_loc = c_parser_peek_token (parser)->location;
|
1677 |
|
|
c_parser_consume_token (parser);
|
1678 |
|
|
attrs = c_parser_attributes (parser);
|
1679 |
|
|
enum_loc = c_parser_peek_token (parser)->location;
|
1680 |
|
|
/* Set the location in case we create a decl now. */
|
1681 |
|
|
c_parser_set_source_position_from_token (c_parser_peek_token (parser));
|
1682 |
|
|
if (c_parser_next_token_is (parser, CPP_NAME))
|
1683 |
|
|
{
|
1684 |
|
|
ident = c_parser_peek_token (parser)->value;
|
1685 |
|
|
ident_loc = c_parser_peek_token (parser)->location;
|
1686 |
|
|
enum_loc = ident_loc;
|
1687 |
|
|
c_parser_consume_token (parser);
|
1688 |
|
|
}
|
1689 |
|
|
if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
|
1690 |
|
|
{
|
1691 |
|
|
/* Parse an enum definition. */
|
1692 |
|
|
struct c_enum_contents the_enum;
|
1693 |
|
|
tree type = start_enum (enum_loc, &the_enum, ident);
|
1694 |
|
|
tree postfix_attrs;
|
1695 |
|
|
/* We chain the enumerators in reverse order, then put them in
|
1696 |
|
|
forward order at the end. */
|
1697 |
|
|
tree values = NULL_TREE;
|
1698 |
|
|
c_parser_consume_token (parser);
|
1699 |
|
|
while (true)
|
1700 |
|
|
{
|
1701 |
|
|
tree enum_id;
|
1702 |
|
|
tree enum_value;
|
1703 |
|
|
tree enum_decl;
|
1704 |
|
|
bool seen_comma;
|
1705 |
|
|
c_token *token;
|
1706 |
|
|
location_t comma_loc = UNKNOWN_LOCATION; /* Quiet warning. */
|
1707 |
|
|
location_t value_loc;
|
1708 |
|
|
if (c_parser_next_token_is_not (parser, CPP_NAME))
|
1709 |
|
|
{
|
1710 |
|
|
c_parser_error (parser, "expected identifier");
|
1711 |
|
|
c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
|
1712 |
|
|
values = error_mark_node;
|
1713 |
|
|
break;
|
1714 |
|
|
}
|
1715 |
|
|
token = c_parser_peek_token (parser);
|
1716 |
|
|
enum_id = token->value;
|
1717 |
|
|
/* Set the location in case we create a decl now. */
|
1718 |
|
|
c_parser_set_source_position_from_token (token);
|
1719 |
|
|
value_loc = token->location;
|
1720 |
|
|
c_parser_consume_token (parser);
|
1721 |
|
|
if (c_parser_next_token_is (parser, CPP_EQ))
|
1722 |
|
|
{
|
1723 |
|
|
c_parser_consume_token (parser);
|
1724 |
|
|
value_loc = c_parser_peek_token (parser)->location;
|
1725 |
|
|
enum_value = c_parser_expr_no_commas (parser, NULL).value;
|
1726 |
|
|
}
|
1727 |
|
|
else
|
1728 |
|
|
enum_value = NULL_TREE;
|
1729 |
|
|
enum_decl = build_enumerator (value_loc,
|
1730 |
|
|
&the_enum, enum_id, enum_value);
|
1731 |
|
|
TREE_CHAIN (enum_decl) = values;
|
1732 |
|
|
values = enum_decl;
|
1733 |
|
|
seen_comma = false;
|
1734 |
|
|
if (c_parser_next_token_is (parser, CPP_COMMA))
|
1735 |
|
|
{
|
1736 |
|
|
comma_loc = c_parser_peek_token (parser)->location;
|
1737 |
|
|
seen_comma = true;
|
1738 |
|
|
c_parser_consume_token (parser);
|
1739 |
|
|
}
|
1740 |
|
|
if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
|
1741 |
|
|
{
|
1742 |
|
|
if (seen_comma && !flag_isoc99)
|
1743 |
|
|
pedwarn (comma_loc, OPT_pedantic, "comma at end of enumerator list");
|
1744 |
|
|
c_parser_consume_token (parser);
|
1745 |
|
|
break;
|
1746 |
|
|
}
|
1747 |
|
|
if (!seen_comma)
|
1748 |
|
|
{
|
1749 |
|
|
c_parser_error (parser, "expected %<,%> or %<}%>");
|
1750 |
|
|
c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
|
1751 |
|
|
values = error_mark_node;
|
1752 |
|
|
break;
|
1753 |
|
|
}
|
1754 |
|
|
}
|
1755 |
|
|
postfix_attrs = c_parser_attributes (parser);
|
1756 |
|
|
ret.spec = finish_enum (type, nreverse (values),
|
1757 |
|
|
chainon (attrs, postfix_attrs));
|
1758 |
|
|
ret.kind = ctsk_tagdef;
|
1759 |
|
|
ret.expr = NULL_TREE;
|
1760 |
|
|
ret.expr_const_operands = true;
|
1761 |
|
|
return ret;
|
1762 |
|
|
}
|
1763 |
|
|
else if (!ident)
|
1764 |
|
|
{
|
1765 |
|
|
c_parser_error (parser, "expected %<{%>");
|
1766 |
|
|
ret.spec = error_mark_node;
|
1767 |
|
|
ret.kind = ctsk_tagref;
|
1768 |
|
|
ret.expr = NULL_TREE;
|
1769 |
|
|
ret.expr_const_operands = true;
|
1770 |
|
|
return ret;
|
1771 |
|
|
}
|
1772 |
|
|
ret = parser_xref_tag (ident_loc, ENUMERAL_TYPE, ident);
|
1773 |
|
|
/* In ISO C, enumerated types can be referred to only if already
|
1774 |
|
|
defined. */
|
1775 |
|
|
if (pedantic && !COMPLETE_TYPE_P (ret.spec))
|
1776 |
|
|
{
|
1777 |
|
|
gcc_assert (ident);
|
1778 |
|
|
pedwarn (enum_loc, OPT_pedantic,
|
1779 |
|
|
"ISO C forbids forward references to %<enum%> types");
|
1780 |
|
|
}
|
1781 |
|
|
return ret;
|
1782 |
|
|
}
|
1783 |
|
|
|
1784 |
|
|
/* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
|
1785 |
|
|
|
1786 |
|
|
struct-or-union-specifier:
|
1787 |
|
|
struct-or-union attributes[opt] identifier[opt]
|
1788 |
|
|
{ struct-contents } attributes[opt]
|
1789 |
|
|
struct-or-union attributes[opt] identifier
|
1790 |
|
|
|
1791 |
|
|
struct-contents:
|
1792 |
|
|
struct-declaration-list
|
1793 |
|
|
|
1794 |
|
|
struct-declaration-list:
|
1795 |
|
|
struct-declaration ;
|
1796 |
|
|
struct-declaration-list struct-declaration ;
|
1797 |
|
|
|
1798 |
|
|
GNU extensions:
|
1799 |
|
|
|
1800 |
|
|
struct-contents:
|
1801 |
|
|
empty
|
1802 |
|
|
struct-declaration
|
1803 |
|
|
struct-declaration-list struct-declaration
|
1804 |
|
|
|
1805 |
|
|
struct-declaration-list:
|
1806 |
|
|
struct-declaration-list ;
|
1807 |
|
|
;
|
1808 |
|
|
|
1809 |
|
|
(Note that in the syntax here, unlike that in ISO C, the semicolons
|
1810 |
|
|
are included here rather than in struct-declaration, in order to
|
1811 |
|
|
describe the syntax with extra semicolons and missing semicolon at
|
1812 |
|
|
end.)
|
1813 |
|
|
|
1814 |
|
|
Objective-C:
|
1815 |
|
|
|
1816 |
|
|
struct-declaration-list:
|
1817 |
|
|
@defs ( class-name )
|
1818 |
|
|
|
1819 |
|
|
(Note this does not include a trailing semicolon, but can be
|
1820 |
|
|
followed by further declarations, and gets a pedwarn-if-pedantic
|
1821 |
|
|
when followed by a semicolon.) */
|
1822 |
|
|
|
1823 |
|
|
static struct c_typespec
|
1824 |
|
|
c_parser_struct_or_union_specifier (c_parser *parser)
|
1825 |
|
|
{
|
1826 |
|
|
struct c_typespec ret;
|
1827 |
|
|
tree attrs;
|
1828 |
|
|
tree ident = NULL_TREE;
|
1829 |
|
|
location_t struct_loc;
|
1830 |
|
|
location_t ident_loc = UNKNOWN_LOCATION;
|
1831 |
|
|
enum tree_code code;
|
1832 |
|
|
switch (c_parser_peek_token (parser)->keyword)
|
1833 |
|
|
{
|
1834 |
|
|
case RID_STRUCT:
|
1835 |
|
|
code = RECORD_TYPE;
|
1836 |
|
|
break;
|
1837 |
|
|
case RID_UNION:
|
1838 |
|
|
code = UNION_TYPE;
|
1839 |
|
|
break;
|
1840 |
|
|
default:
|
1841 |
|
|
gcc_unreachable ();
|
1842 |
|
|
}
|
1843 |
|
|
struct_loc = c_parser_peek_token (parser)->location;
|
1844 |
|
|
c_parser_consume_token (parser);
|
1845 |
|
|
attrs = c_parser_attributes (parser);
|
1846 |
|
|
|
1847 |
|
|
/* Set the location in case we create a decl now. */
|
1848 |
|
|
c_parser_set_source_position_from_token (c_parser_peek_token (parser));
|
1849 |
|
|
|
1850 |
|
|
if (c_parser_next_token_is (parser, CPP_NAME))
|
1851 |
|
|
{
|
1852 |
|
|
ident = c_parser_peek_token (parser)->value;
|
1853 |
|
|
ident_loc = c_parser_peek_token (parser)->location;
|
1854 |
|
|
struct_loc = ident_loc;
|
1855 |
|
|
c_parser_consume_token (parser);
|
1856 |
|
|
}
|
1857 |
|
|
if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
|
1858 |
|
|
{
|
1859 |
|
|
/* Parse a struct or union definition. Start the scope of the
|
1860 |
|
|
tag before parsing components. */
|
1861 |
|
|
struct c_struct_parse_info *struct_info;
|
1862 |
|
|
tree type = start_struct (struct_loc, code, ident, &struct_info);
|
1863 |
|
|
tree postfix_attrs;
|
1864 |
|
|
/* We chain the components in reverse order, then put them in
|
1865 |
|
|
forward order at the end. Each struct-declaration may
|
1866 |
|
|
declare multiple components (comma-separated), so we must use
|
1867 |
|
|
chainon to join them, although when parsing each
|
1868 |
|
|
struct-declaration we can use TREE_CHAIN directly.
|
1869 |
|
|
|
1870 |
|
|
The theory behind all this is that there will be more
|
1871 |
|
|
semicolon separated fields than comma separated fields, and
|
1872 |
|
|
so we'll be minimizing the number of node traversals required
|
1873 |
|
|
by chainon. */
|
1874 |
|
|
tree contents = NULL_TREE;
|
1875 |
|
|
c_parser_consume_token (parser);
|
1876 |
|
|
/* Handle the Objective-C @defs construct,
|
1877 |
|
|
e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
|
1878 |
|
|
if (c_parser_next_token_is_keyword (parser, RID_AT_DEFS))
|
1879 |
|
|
{
|
1880 |
|
|
tree name;
|
1881 |
|
|
gcc_assert (c_dialect_objc ());
|
1882 |
|
|
c_parser_consume_token (parser);
|
1883 |
|
|
if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
|
1884 |
|
|
goto end_at_defs;
|
1885 |
|
|
if (c_parser_next_token_is (parser, CPP_NAME)
|
1886 |
|
|
&& c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME)
|
1887 |
|
|
{
|
1888 |
|
|
name = c_parser_peek_token (parser)->value;
|
1889 |
|
|
c_parser_consume_token (parser);
|
1890 |
|
|
}
|
1891 |
|
|
else
|
1892 |
|
|
{
|
1893 |
|
|
c_parser_error (parser, "expected class name");
|
1894 |
|
|
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
|
1895 |
|
|
goto end_at_defs;
|
1896 |
|
|
}
|
1897 |
|
|
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
|
1898 |
|
|
"expected %<)%>");
|
1899 |
|
|
contents = nreverse (objc_get_class_ivars (name));
|
1900 |
|
|
}
|
1901 |
|
|
end_at_defs:
|
1902 |
|
|
/* Parse the struct-declarations and semicolons. Problems with
|
1903 |
|
|
semicolons are diagnosed here; empty structures are diagnosed
|
1904 |
|
|
elsewhere. */
|
1905 |
|
|
while (true)
|
1906 |
|
|
{
|
1907 |
|
|
tree decls;
|
1908 |
|
|
/* Parse any stray semicolon. */
|
1909 |
|
|
if (c_parser_next_token_is (parser, CPP_SEMICOLON))
|
1910 |
|
|
{
|
1911 |
|
|
pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
|
1912 |
|
|
"extra semicolon in struct or union specified");
|
1913 |
|
|
c_parser_consume_token (parser);
|
1914 |
|
|
continue;
|
1915 |
|
|
}
|
1916 |
|
|
/* Stop if at the end of the struct or union contents. */
|
1917 |
|
|
if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
|
1918 |
|
|
{
|
1919 |
|
|
c_parser_consume_token (parser);
|
1920 |
|
|
break;
|
1921 |
|
|
}
|
1922 |
|
|
/* Accept #pragmas at struct scope. */
|
1923 |
|
|
if (c_parser_next_token_is (parser, CPP_PRAGMA))
|
1924 |
|
|
{
|
1925 |
|
|
c_parser_pragma (parser, pragma_external);
|
1926 |
|
|
continue;
|
1927 |
|
|
}
|
1928 |
|
|
/* Parse some comma-separated declarations, but not the
|
1929 |
|
|
trailing semicolon if any. */
|
1930 |
|
|
decls = c_parser_struct_declaration (parser);
|
1931 |
|
|
contents = chainon (decls, contents);
|
1932 |
|
|
/* If no semicolon follows, either we have a parse error or
|
1933 |
|
|
are at the end of the struct or union and should
|
1934 |
|
|
pedwarn. */
|
1935 |
|
|
if (c_parser_next_token_is (parser, CPP_SEMICOLON))
|
1936 |
|
|
c_parser_consume_token (parser);
|
1937 |
|
|
else
|
1938 |
|
|
{
|
1939 |
|
|
if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
|
1940 |
|
|
pedwarn (c_parser_peek_token (parser)->location, 0,
|
1941 |
|
|
"no semicolon at end of struct or union");
|
1942 |
|
|
else
|
1943 |
|
|
{
|
1944 |
|
|
c_parser_error (parser, "expected %<;%>");
|
1945 |
|
|
c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
|
1946 |
|
|
break;
|
1947 |
|
|
}
|
1948 |
|
|
}
|
1949 |
|
|
}
|
1950 |
|
|
postfix_attrs = c_parser_attributes (parser);
|
1951 |
|
|
ret.spec = finish_struct (struct_loc, type, nreverse (contents),
|
1952 |
|
|
chainon (attrs, postfix_attrs), struct_info);
|
1953 |
|
|
ret.kind = ctsk_tagdef;
|
1954 |
|
|
ret.expr = NULL_TREE;
|
1955 |
|
|
ret.expr_const_operands = true;
|
1956 |
|
|
return ret;
|
1957 |
|
|
}
|
1958 |
|
|
else if (!ident)
|
1959 |
|
|
{
|
1960 |
|
|
c_parser_error (parser, "expected %<{%>");
|
1961 |
|
|
ret.spec = error_mark_node;
|
1962 |
|
|
ret.kind = ctsk_tagref;
|
1963 |
|
|
ret.expr = NULL_TREE;
|
1964 |
|
|
ret.expr_const_operands = true;
|
1965 |
|
|
return ret;
|
1966 |
|
|
}
|
1967 |
|
|
ret = parser_xref_tag (ident_loc, code, ident);
|
1968 |
|
|
return ret;
|
1969 |
|
|
}
|
1970 |
|
|
|
1971 |
|
|
/* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
|
1972 |
|
|
the trailing semicolon.
|
1973 |
|
|
|
1974 |
|
|
struct-declaration:
|
1975 |
|
|
specifier-qualifier-list struct-declarator-list
|
1976 |
|
|
|
1977 |
|
|
specifier-qualifier-list:
|
1978 |
|
|
type-specifier specifier-qualifier-list[opt]
|
1979 |
|
|
type-qualifier specifier-qualifier-list[opt]
|
1980 |
|
|
attributes specifier-qualifier-list[opt]
|
1981 |
|
|
|
1982 |
|
|
struct-declarator-list:
|
1983 |
|
|
struct-declarator
|
1984 |
|
|
struct-declarator-list , attributes[opt] struct-declarator
|
1985 |
|
|
|
1986 |
|
|
struct-declarator:
|
1987 |
|
|
declarator attributes[opt]
|
1988 |
|
|
declarator[opt] : constant-expression attributes[opt]
|
1989 |
|
|
|
1990 |
|
|
GNU extensions:
|
1991 |
|
|
|
1992 |
|
|
struct-declaration:
|
1993 |
|
|
__extension__ struct-declaration
|
1994 |
|
|
specifier-qualifier-list
|
1995 |
|
|
|
1996 |
|
|
Unlike the ISO C syntax, semicolons are handled elsewhere. The use
|
1997 |
|
|
of attributes where shown is a GNU extension. In GNU C, we accept
|
1998 |
|
|
any expression without commas in the syntax (assignment
|
1999 |
|
|
expressions, not just conditional expressions); assignment
|
2000 |
|
|
expressions will be diagnosed as non-constant. */
|
2001 |
|
|
|
2002 |
|
|
static tree
|
2003 |
|
|
c_parser_struct_declaration (c_parser *parser)
|
2004 |
|
|
{
|
2005 |
|
|
struct c_declspecs *specs;
|
2006 |
|
|
tree prefix_attrs;
|
2007 |
|
|
tree all_prefix_attrs;
|
2008 |
|
|
tree decls;
|
2009 |
|
|
location_t decl_loc;
|
2010 |
|
|
if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
|
2011 |
|
|
{
|
2012 |
|
|
int ext;
|
2013 |
|
|
tree decl;
|
2014 |
|
|
ext = disable_extension_diagnostics ();
|
2015 |
|
|
c_parser_consume_token (parser);
|
2016 |
|
|
decl = c_parser_struct_declaration (parser);
|
2017 |
|
|
restore_extension_diagnostics (ext);
|
2018 |
|
|
return decl;
|
2019 |
|
|
}
|
2020 |
|
|
specs = build_null_declspecs ();
|
2021 |
|
|
decl_loc = c_parser_peek_token (parser)->location;
|
2022 |
|
|
c_parser_declspecs (parser, specs, false, true, true);
|
2023 |
|
|
if (parser->error)
|
2024 |
|
|
return NULL_TREE;
|
2025 |
|
|
if (!specs->declspecs_seen_p)
|
2026 |
|
|
{
|
2027 |
|
|
c_parser_error (parser, "expected specifier-qualifier-list");
|
2028 |
|
|
return NULL_TREE;
|
2029 |
|
|
}
|
2030 |
|
|
finish_declspecs (specs);
|
2031 |
|
|
if (c_parser_next_token_is (parser, CPP_SEMICOLON))
|
2032 |
|
|
{
|
2033 |
|
|
tree ret;
|
2034 |
|
|
if (!specs->type_seen_p)
|
2035 |
|
|
{
|
2036 |
|
|
pedwarn (decl_loc, OPT_pedantic,
|
2037 |
|
|
"ISO C forbids member declarations with no members");
|
2038 |
|
|
shadow_tag_warned (specs, pedantic);
|
2039 |
|
|
ret = NULL_TREE;
|
2040 |
|
|
}
|
2041 |
|
|
else
|
2042 |
|
|
{
|
2043 |
|
|
/* Support for unnamed structs or unions as members of
|
2044 |
|
|
structs or unions (which is [a] useful and [b] supports
|
2045 |
|
|
MS P-SDK). */
|
2046 |
|
|
tree attrs = NULL;
|
2047 |
|
|
|
2048 |
|
|
ret = grokfield (c_parser_peek_token (parser)->location,
|
2049 |
|
|
build_id_declarator (NULL_TREE), specs,
|
2050 |
|
|
NULL_TREE, &attrs);
|
2051 |
|
|
if (ret)
|
2052 |
|
|
decl_attributes (&ret, attrs, 0);
|
2053 |
|
|
}
|
2054 |
|
|
return ret;
|
2055 |
|
|
}
|
2056 |
|
|
pending_xref_error ();
|
2057 |
|
|
prefix_attrs = specs->attrs;
|
2058 |
|
|
all_prefix_attrs = prefix_attrs;
|
2059 |
|
|
specs->attrs = NULL_TREE;
|
2060 |
|
|
decls = NULL_TREE;
|
2061 |
|
|
while (true)
|
2062 |
|
|
{
|
2063 |
|
|
/* Declaring one or more declarators or un-named bit-fields. */
|
2064 |
|
|
struct c_declarator *declarator;
|
2065 |
|
|
bool dummy = false;
|
2066 |
|
|
if (c_parser_next_token_is (parser, CPP_COLON))
|
2067 |
|
|
declarator = build_id_declarator (NULL_TREE);
|
2068 |
|
|
else
|
2069 |
|
|
declarator = c_parser_declarator (parser, specs->type_seen_p,
|
2070 |
|
|
C_DTR_NORMAL, &dummy);
|
2071 |
|
|
if (declarator == NULL)
|
2072 |
|
|
{
|
2073 |
|
|
c_parser_skip_to_end_of_block_or_statement (parser);
|
2074 |
|
|
break;
|
2075 |
|
|
}
|
2076 |
|
|
if (c_parser_next_token_is (parser, CPP_COLON)
|
2077 |
|
|
|| c_parser_next_token_is (parser, CPP_COMMA)
|
2078 |
|
|
|| c_parser_next_token_is (parser, CPP_SEMICOLON)
|
2079 |
|
|
|| c_parser_next_token_is (parser, CPP_CLOSE_BRACE)
|
2080 |
|
|
|| c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
|
2081 |
|
|
{
|
2082 |
|
|
tree postfix_attrs = NULL_TREE;
|
2083 |
|
|
tree width = NULL_TREE;
|
2084 |
|
|
tree d;
|
2085 |
|
|
if (c_parser_next_token_is (parser, CPP_COLON))
|
2086 |
|
|
{
|
2087 |
|
|
c_parser_consume_token (parser);
|
2088 |
|
|
width = c_parser_expr_no_commas (parser, NULL).value;
|
2089 |
|
|
}
|
2090 |
|
|
if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
|
2091 |
|
|
postfix_attrs = c_parser_attributes (parser);
|
2092 |
|
|
d = grokfield (c_parser_peek_token (parser)->location,
|
2093 |
|
|
declarator, specs, width, &all_prefix_attrs);
|
2094 |
|
|
decl_attributes (&d, chainon (postfix_attrs,
|
2095 |
|
|
all_prefix_attrs), 0);
|
2096 |
|
|
TREE_CHAIN (d) = decls;
|
2097 |
|
|
decls = d;
|
2098 |
|
|
if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
|
2099 |
|
|
all_prefix_attrs = chainon (c_parser_attributes (parser),
|
2100 |
|
|
prefix_attrs);
|
2101 |
|
|
else
|
2102 |
|
|
all_prefix_attrs = prefix_attrs;
|
2103 |
|
|
if (c_parser_next_token_is (parser, CPP_COMMA))
|
2104 |
|
|
c_parser_consume_token (parser);
|
2105 |
|
|
else if (c_parser_next_token_is (parser, CPP_SEMICOLON)
|
2106 |
|
|
|| c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
|
2107 |
|
|
{
|
2108 |
|
|
/* Semicolon consumed in caller. */
|
2109 |
|
|
break;
|
2110 |
|
|
}
|
2111 |
|
|
else
|
2112 |
|
|
{
|
2113 |
|
|
c_parser_error (parser, "expected %<,%>, %<;%> or %<}%>");
|
2114 |
|
|
break;
|
2115 |
|
|
}
|
2116 |
|
|
}
|
2117 |
|
|
else
|
2118 |
|
|
{
|
2119 |
|
|
c_parser_error (parser,
|
2120 |
|
|
"expected %<:%>, %<,%>, %<;%>, %<}%> or "
|
2121 |
|
|
"%<__attribute__%>");
|
2122 |
|
|
break;
|
2123 |
|
|
}
|
2124 |
|
|
}
|
2125 |
|
|
return decls;
|
2126 |
|
|
}
|
2127 |
|
|
|
2128 |
|
|
/* Parse a typeof specifier (a GNU extension).
|
2129 |
|
|
|
2130 |
|
|
typeof-specifier:
|
2131 |
|
|
typeof ( expression )
|
2132 |
|
|
typeof ( type-name )
|
2133 |
|
|
*/
|
2134 |
|
|
|
2135 |
|
|
static struct c_typespec
|
2136 |
|
|
c_parser_typeof_specifier (c_parser *parser)
|
2137 |
|
|
{
|
2138 |
|
|
struct c_typespec ret;
|
2139 |
|
|
ret.kind = ctsk_typeof;
|
2140 |
|
|
ret.spec = error_mark_node;
|
2141 |
|
|
ret.expr = NULL_TREE;
|
2142 |
|
|
ret.expr_const_operands = true;
|
2143 |
|
|
gcc_assert (c_parser_next_token_is_keyword (parser, RID_TYPEOF));
|
2144 |
|
|
c_parser_consume_token (parser);
|
2145 |
|
|
c_inhibit_evaluation_warnings++;
|
2146 |
|
|
in_typeof++;
|
2147 |
|
|
if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
|
2148 |
|
|
{
|
2149 |
|
|
c_inhibit_evaluation_warnings--;
|
2150 |
|
|
in_typeof--;
|
2151 |
|
|
return ret;
|
2152 |
|
|
}
|
2153 |
|
|
if (c_parser_next_token_starts_typename (parser))
|
2154 |
|
|
{
|
2155 |
|
|
struct c_type_name *type = c_parser_type_name (parser);
|
2156 |
|
|
c_inhibit_evaluation_warnings--;
|
2157 |
|
|
in_typeof--;
|
2158 |
|
|
if (type != NULL)
|
2159 |
|
|
{
|
2160 |
|
|
ret.spec = groktypename (type, &ret.expr, &ret.expr_const_operands);
|
2161 |
|
|
pop_maybe_used (variably_modified_type_p (ret.spec, NULL_TREE));
|
2162 |
|
|
}
|
2163 |
|
|
}
|
2164 |
|
|
else
|
2165 |
|
|
{
|
2166 |
|
|
bool was_vm;
|
2167 |
|
|
location_t here = c_parser_peek_token (parser)->location;
|
2168 |
|
|
struct c_expr expr = c_parser_expression (parser);
|
2169 |
|
|
c_inhibit_evaluation_warnings--;
|
2170 |
|
|
in_typeof--;
|
2171 |
|
|
if (TREE_CODE (expr.value) == COMPONENT_REF
|
2172 |
|
|
&& DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
|
2173 |
|
|
error_at (here, "%<typeof%> applied to a bit-field");
|
2174 |
|
|
ret.spec = TREE_TYPE (expr.value);
|
2175 |
|
|
was_vm = variably_modified_type_p (ret.spec, NULL_TREE);
|
2176 |
|
|
/* This is returned with the type so that when the type is
|
2177 |
|
|
evaluated, this can be evaluated. */
|
2178 |
|
|
if (was_vm)
|
2179 |
|
|
ret.expr = c_fully_fold (expr.value, false, &ret.expr_const_operands);
|
2180 |
|
|
pop_maybe_used (was_vm);
|
2181 |
|
|
}
|
2182 |
|
|
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
|
2183 |
|
|
return ret;
|
2184 |
|
|
}
|
2185 |
|
|
|
2186 |
|
|
/* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
|
2187 |
|
|
6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
|
2188 |
|
|
be redeclared; otherwise it may not. KIND indicates which kind of
|
2189 |
|
|
declarator is wanted. Returns a valid declarator except in the
|
2190 |
|
|
case of a syntax error in which case NULL is returned. *SEEN_ID is
|
2191 |
|
|
set to true if an identifier being declared is seen; this is used
|
2192 |
|
|
to diagnose bad forms of abstract array declarators and to
|
2193 |
|
|
determine whether an identifier list is syntactically permitted.
|
2194 |
|
|
|
2195 |
|
|
declarator:
|
2196 |
|
|
pointer[opt] direct-declarator
|
2197 |
|
|
|
2198 |
|
|
direct-declarator:
|
2199 |
|
|
identifier
|
2200 |
|
|
( attributes[opt] declarator )
|
2201 |
|
|
direct-declarator array-declarator
|
2202 |
|
|
direct-declarator ( parameter-type-list )
|
2203 |
|
|
direct-declarator ( identifier-list[opt] )
|
2204 |
|
|
|
2205 |
|
|
pointer:
|
2206 |
|
|
* type-qualifier-list[opt]
|
2207 |
|
|
* type-qualifier-list[opt] pointer
|
2208 |
|
|
|
2209 |
|
|
type-qualifier-list:
|
2210 |
|
|
type-qualifier
|
2211 |
|
|
attributes
|
2212 |
|
|
type-qualifier-list type-qualifier
|
2213 |
|
|
type-qualifier-list attributes
|
2214 |
|
|
|
2215 |
|
|
parameter-type-list:
|
2216 |
|
|
parameter-list
|
2217 |
|
|
parameter-list , ...
|
2218 |
|
|
|
2219 |
|
|
parameter-list:
|
2220 |
|
|
parameter-declaration
|
2221 |
|
|
parameter-list , parameter-declaration
|
2222 |
|
|
|
2223 |
|
|
parameter-declaration:
|
2224 |
|
|
declaration-specifiers declarator attributes[opt]
|
2225 |
|
|
declaration-specifiers abstract-declarator[opt] attributes[opt]
|
2226 |
|
|
|
2227 |
|
|
identifier-list:
|
2228 |
|
|
identifier
|
2229 |
|
|
identifier-list , identifier
|
2230 |
|
|
|
2231 |
|
|
abstract-declarator:
|
2232 |
|
|
pointer
|
2233 |
|
|
pointer[opt] direct-abstract-declarator
|
2234 |
|
|
|
2235 |
|
|
direct-abstract-declarator:
|
2236 |
|
|
( attributes[opt] abstract-declarator )
|
2237 |
|
|
direct-abstract-declarator[opt] array-declarator
|
2238 |
|
|
direct-abstract-declarator[opt] ( parameter-type-list[opt] )
|
2239 |
|
|
|
2240 |
|
|
GNU extensions:
|
2241 |
|
|
|
2242 |
|
|
direct-declarator:
|
2243 |
|
|
direct-declarator ( parameter-forward-declarations
|
2244 |
|
|
parameter-type-list[opt] )
|
2245 |
|
|
|
2246 |
|
|
direct-abstract-declarator:
|
2247 |
|
|
direct-abstract-declarator[opt] ( parameter-forward-declarations
|
2248 |
|
|
parameter-type-list[opt] )
|
2249 |
|
|
|
2250 |
|
|
parameter-forward-declarations:
|
2251 |
|
|
parameter-list ;
|
2252 |
|
|
parameter-forward-declarations parameter-list ;
|
2253 |
|
|
|
2254 |
|
|
The uses of attributes shown above are GNU extensions.
|
2255 |
|
|
|
2256 |
|
|
Some forms of array declarator are not included in C99 in the
|
2257 |
|
|
syntax for abstract declarators; these are disallowed elsewhere.
|
2258 |
|
|
This may be a defect (DR#289).
|
2259 |
|
|
|
2260 |
|
|
This function also accepts an omitted abstract declarator as being
|
2261 |
|
|
an abstract declarator, although not part of the formal syntax. */
|
2262 |
|
|
|
2263 |
|
|
static struct c_declarator *
|
2264 |
|
|
c_parser_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
|
2265 |
|
|
bool *seen_id)
|
2266 |
|
|
{
|
2267 |
|
|
/* Parse any initial pointer part. */
|
2268 |
|
|
if (c_parser_next_token_is (parser, CPP_MULT))
|
2269 |
|
|
{
|
2270 |
|
|
struct c_declspecs *quals_attrs = build_null_declspecs ();
|
2271 |
|
|
struct c_declarator *inner;
|
2272 |
|
|
c_parser_consume_token (parser);
|
2273 |
|
|
c_parser_declspecs (parser, quals_attrs, false, false, true);
|
2274 |
|
|
inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
|
2275 |
|
|
if (inner == NULL)
|
2276 |
|
|
return NULL;
|
2277 |
|
|
else
|
2278 |
|
|
return make_pointer_declarator (quals_attrs, inner);
|
2279 |
|
|
}
|
2280 |
|
|
/* Now we have a direct declarator, direct abstract declarator or
|
2281 |
|
|
nothing (which counts as a direct abstract declarator here). */
|
2282 |
|
|
return c_parser_direct_declarator (parser, type_seen_p, kind, seen_id);
|
2283 |
|
|
}
|
2284 |
|
|
|
2285 |
|
|
/* Parse a direct declarator or direct abstract declarator; arguments
|
2286 |
|
|
as c_parser_declarator. */
|
2287 |
|
|
|
2288 |
|
|
static struct c_declarator *
|
2289 |
|
|
c_parser_direct_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
|
2290 |
|
|
bool *seen_id)
|
2291 |
|
|
{
|
2292 |
|
|
/* The direct declarator must start with an identifier (possibly
|
2293 |
|
|
omitted) or a parenthesized declarator (possibly abstract). In
|
2294 |
|
|
an ordinary declarator, initial parentheses must start a
|
2295 |
|
|
parenthesized declarator. In an abstract declarator or parameter
|
2296 |
|
|
declarator, they could start a parenthesized declarator or a
|
2297 |
|
|
parameter list. To tell which, the open parenthesis and any
|
2298 |
|
|
following attributes must be read. If a declaration specifier
|
2299 |
|
|
follows, then it is a parameter list; if the specifier is a
|
2300 |
|
|
typedef name, there might be an ambiguity about redeclaring it,
|
2301 |
|
|
which is resolved in the direction of treating it as a typedef
|
2302 |
|
|
name. If a close parenthesis follows, it is also an empty
|
2303 |
|
|
parameter list, as the syntax does not permit empty abstract
|
2304 |
|
|
declarators. Otherwise, it is a parenthesized declarator (in
|
2305 |
|
|
which case the analysis may be repeated inside it, recursively).
|
2306 |
|
|
|
2307 |
|
|
??? There is an ambiguity in a parameter declaration "int
|
2308 |
|
|
(__attribute__((foo)) x)", where x is not a typedef name: it
|
2309 |
|
|
could be an abstract declarator for a function, or declare x with
|
2310 |
|
|
parentheses. The proper resolution of this ambiguity needs
|
2311 |
|
|
documenting. At present we follow an accident of the old
|
2312 |
|
|
parser's implementation, whereby the first parameter must have
|
2313 |
|
|
some declaration specifiers other than just attributes. Thus as
|
2314 |
|
|
a parameter declaration it is treated as a parenthesized
|
2315 |
|
|
parameter named x, and as an abstract declarator it is
|
2316 |
|
|
rejected.
|
2317 |
|
|
|
2318 |
|
|
??? Also following the old parser, attributes inside an empty
|
2319 |
|
|
parameter list are ignored, making it a list not yielding a
|
2320 |
|
|
prototype, rather than giving an error or making it have one
|
2321 |
|
|
parameter with implicit type int.
|
2322 |
|
|
|
2323 |
|
|
??? Also following the old parser, typedef names may be
|
2324 |
|
|
redeclared in declarators, but not Objective-C class names. */
|
2325 |
|
|
|
2326 |
|
|
if (kind != C_DTR_ABSTRACT
|
2327 |
|
|
&& c_parser_next_token_is (parser, CPP_NAME)
|
2328 |
|
|
&& ((type_seen_p
|
2329 |
|
|
&& c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME)
|
2330 |
|
|
|| c_parser_peek_token (parser)->id_kind == C_ID_ID))
|
2331 |
|
|
{
|
2332 |
|
|
struct c_declarator *inner
|
2333 |
|
|
= build_id_declarator (c_parser_peek_token (parser)->value);
|
2334 |
|
|
*seen_id = true;
|
2335 |
|
|
inner->id_loc = c_parser_peek_token (parser)->location;
|
2336 |
|
|
c_parser_consume_token (parser);
|
2337 |
|
|
return c_parser_direct_declarator_inner (parser, *seen_id, inner);
|
2338 |
|
|
}
|
2339 |
|
|
|
2340 |
|
|
if (kind != C_DTR_NORMAL
|
2341 |
|
|
&& c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
|
2342 |
|
|
{
|
2343 |
|
|
struct c_declarator *inner = build_id_declarator (NULL_TREE);
|
2344 |
|
|
return c_parser_direct_declarator_inner (parser, *seen_id, inner);
|
2345 |
|
|
}
|
2346 |
|
|
|
2347 |
|
|
/* Either we are at the end of an abstract declarator, or we have
|
2348 |
|
|
parentheses. */
|
2349 |
|
|
|
2350 |
|
|
if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
|
2351 |
|
|
{
|
2352 |
|
|
tree attrs;
|
2353 |
|
|
struct c_declarator *inner;
|
2354 |
|
|
c_parser_consume_token (parser);
|
2355 |
|
|
attrs = c_parser_attributes (parser);
|
2356 |
|
|
if (kind != C_DTR_NORMAL
|
2357 |
|
|
&& (c_parser_next_token_starts_declspecs (parser)
|
2358 |
|
|
|| c_parser_next_token_is (parser, CPP_CLOSE_PAREN)))
|
2359 |
|
|
{
|
2360 |
|
|
struct c_arg_info *args
|
2361 |
|
|
= c_parser_parms_declarator (parser, kind == C_DTR_NORMAL,
|
2362 |
|
|
attrs);
|
2363 |
|
|
if (args == NULL)
|
2364 |
|
|
return NULL;
|
2365 |
|
|
else
|
2366 |
|
|
{
|
2367 |
|
|
inner
|
2368 |
|
|
= build_function_declarator (args,
|
2369 |
|
|
build_id_declarator (NULL_TREE));
|
2370 |
|
|
return c_parser_direct_declarator_inner (parser, *seen_id,
|
2371 |
|
|
inner);
|
2372 |
|
|
}
|
2373 |
|
|
}
|
2374 |
|
|
/* A parenthesized declarator. */
|
2375 |
|
|
inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
|
2376 |
|
|
if (inner != NULL && attrs != NULL)
|
2377 |
|
|
inner = build_attrs_declarator (attrs, inner);
|
2378 |
|
|
if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
|
2379 |
|
|
{
|
2380 |
|
|
c_parser_consume_token (parser);
|
2381 |
|
|
if (inner == NULL)
|
2382 |
|
|
return NULL;
|
2383 |
|
|
else
|
2384 |
|
|
return c_parser_direct_declarator_inner (parser, *seen_id, inner);
|
2385 |
|
|
}
|
2386 |
|
|
else
|
2387 |
|
|
{
|
2388 |
|
|
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
|
2389 |
|
|
"expected %<)%>");
|
2390 |
|
|
return NULL;
|
2391 |
|
|
}
|
2392 |
|
|
}
|
2393 |
|
|
else
|
2394 |
|
|
{
|
2395 |
|
|
if (kind == C_DTR_NORMAL)
|
2396 |
|
|
{
|
2397 |
|
|
c_parser_error (parser, "expected identifier or %<(%>");
|
2398 |
|
|
return NULL;
|
2399 |
|
|
}
|
2400 |
|
|
else
|
2401 |
|
|
return build_id_declarator (NULL_TREE);
|
2402 |
|
|
}
|
2403 |
|
|
}
|
2404 |
|
|
|
2405 |
|
|
/* Parse part of a direct declarator or direct abstract declarator,
|
2406 |
|
|
given that some (in INNER) has already been parsed; ID_PRESENT is
|
2407 |
|
|
true if an identifier is present, false for an abstract
|
2408 |
|
|
declarator. */
|
2409 |
|
|
|
2410 |
|
|
static struct c_declarator *
|
2411 |
|
|
c_parser_direct_declarator_inner (c_parser *parser, bool id_present,
|
2412 |
|
|
struct c_declarator *inner)
|
2413 |
|
|
{
|
2414 |
|
|
/* Parse a sequence of array declarators and parameter lists. */
|
2415 |
|
|
if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
|
2416 |
|
|
{
|
2417 |
|
|
location_t brace_loc = c_parser_peek_token (parser)->location;
|
2418 |
|
|
struct c_declarator *declarator;
|
2419 |
|
|
struct c_declspecs *quals_attrs = build_null_declspecs ();
|
2420 |
|
|
bool static_seen;
|
2421 |
|
|
bool star_seen;
|
2422 |
|
|
tree dimen;
|
2423 |
|
|
c_parser_consume_token (parser);
|
2424 |
|
|
c_parser_declspecs (parser, quals_attrs, false, false, true);
|
2425 |
|
|
static_seen = c_parser_next_token_is_keyword (parser, RID_STATIC);
|
2426 |
|
|
if (static_seen)
|
2427 |
|
|
c_parser_consume_token (parser);
|
2428 |
|
|
if (static_seen && !quals_attrs->declspecs_seen_p)
|
2429 |
|
|
c_parser_declspecs (parser, quals_attrs, false, false, true);
|
2430 |
|
|
if (!quals_attrs->declspecs_seen_p)
|
2431 |
|
|
quals_attrs = NULL;
|
2432 |
|
|
/* If "static" is present, there must be an array dimension.
|
2433 |
|
|
Otherwise, there may be a dimension, "*", or no
|
2434 |
|
|
dimension. */
|
2435 |
|
|
if (static_seen)
|
2436 |
|
|
{
|
2437 |
|
|
star_seen = false;
|
2438 |
|
|
dimen = c_parser_expr_no_commas (parser, NULL).value;
|
2439 |
|
|
}
|
2440 |
|
|
else
|
2441 |
|
|
{
|
2442 |
|
|
if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
|
2443 |
|
|
{
|
2444 |
|
|
dimen = NULL_TREE;
|
2445 |
|
|
star_seen = false;
|
2446 |
|
|
}
|
2447 |
|
|
else if (c_parser_next_token_is (parser, CPP_MULT))
|
2448 |
|
|
{
|
2449 |
|
|
if (c_parser_peek_2nd_token (parser)->type == CPP_CLOSE_SQUARE)
|
2450 |
|
|
{
|
2451 |
|
|
dimen = NULL_TREE;
|
2452 |
|
|
star_seen = true;
|
2453 |
|
|
c_parser_consume_token (parser);
|
2454 |
|
|
}
|
2455 |
|
|
else
|
2456 |
|
|
{
|
2457 |
|
|
star_seen = false;
|
2458 |
|
|
dimen = c_parser_expr_no_commas (parser, NULL).value;
|
2459 |
|
|
}
|
2460 |
|
|
}
|
2461 |
|
|
else
|
2462 |
|
|
{
|
2463 |
|
|
star_seen = false;
|
2464 |
|
|
dimen = c_parser_expr_no_commas (parser, NULL).value;
|
2465 |
|
|
}
|
2466 |
|
|
}
|
2467 |
|
|
if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
|
2468 |
|
|
c_parser_consume_token (parser);
|
2469 |
|
|
else
|
2470 |
|
|
{
|
2471 |
|
|
c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
|
2472 |
|
|
"expected %<]%>");
|
2473 |
|
|
return NULL;
|
2474 |
|
|
}
|
2475 |
|
|
declarator = build_array_declarator (brace_loc, dimen, quals_attrs,
|
2476 |
|
|
static_seen, star_seen);
|
2477 |
|
|
if (declarator == NULL)
|
2478 |
|
|
return NULL;
|
2479 |
|
|
inner = set_array_declarator_inner (declarator, inner);
|
2480 |
|
|
return c_parser_direct_declarator_inner (parser, id_present, inner);
|
2481 |
|
|
}
|
2482 |
|
|
else if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
|
2483 |
|
|
{
|
2484 |
|
|
tree attrs;
|
2485 |
|
|
struct c_arg_info *args;
|
2486 |
|
|
c_parser_consume_token (parser);
|
2487 |
|
|
attrs = c_parser_attributes (parser);
|
2488 |
|
|
args = c_parser_parms_declarator (parser, id_present, attrs);
|
2489 |
|
|
if (args == NULL)
|
2490 |
|
|
return NULL;
|
2491 |
|
|
else
|
2492 |
|
|
{
|
2493 |
|
|
inner = build_function_declarator (args, inner);
|
2494 |
|
|
return c_parser_direct_declarator_inner (parser, id_present, inner);
|
2495 |
|
|
}
|
2496 |
|
|
}
|
2497 |
|
|
return inner;
|
2498 |
|
|
}
|
2499 |
|
|
|
2500 |
|
|
/* Parse a parameter list or identifier list, including the closing
|
2501 |
|
|
parenthesis but not the opening one. ATTRS are the attributes at
|
2502 |
|
|
the start of the list. ID_LIST_OK is true if an identifier list is
|
2503 |
|
|
acceptable; such a list must not have attributes at the start. */
|
2504 |
|
|
|
2505 |
|
|
static struct c_arg_info *
|
2506 |
|
|
c_parser_parms_declarator (c_parser *parser, bool id_list_ok, tree attrs)
|
2507 |
|
|
{
|
2508 |
|
|
push_scope ();
|
2509 |
|
|
declare_parm_level ();
|
2510 |
|
|
/* If the list starts with an identifier, it is an identifier list.
|
2511 |
|
|
Otherwise, it is either a prototype list or an empty list. */
|
2512 |
|
|
if (id_list_ok
|
2513 |
|
|
&& !attrs
|
2514 |
|
|
&& c_parser_next_token_is (parser, CPP_NAME)
|
2515 |
|
|
&& c_parser_peek_token (parser)->id_kind == C_ID_ID)
|
2516 |
|
|
{
|
2517 |
|
|
tree list = NULL_TREE, *nextp = &list;
|
2518 |
|
|
while (c_parser_next_token_is (parser, CPP_NAME)
|
2519 |
|
|
&& c_parser_peek_token (parser)->id_kind == C_ID_ID)
|
2520 |
|
|
{
|
2521 |
|
|
*nextp = build_tree_list (NULL_TREE,
|
2522 |
|
|
c_parser_peek_token (parser)->value);
|
2523 |
|
|
nextp = & TREE_CHAIN (*nextp);
|
2524 |
|
|
c_parser_consume_token (parser);
|
2525 |
|
|
if (c_parser_next_token_is_not (parser, CPP_COMMA))
|
2526 |
|
|
break;
|
2527 |
|
|
c_parser_consume_token (parser);
|
2528 |
|
|
if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
|
2529 |
|
|
{
|
2530 |
|
|
c_parser_error (parser, "expected identifier");
|
2531 |
|
|
break;
|
2532 |
|
|
}
|
2533 |
|
|
}
|
2534 |
|
|
if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
|
2535 |
|
|
{
|
2536 |
|
|
struct c_arg_info *ret = XOBNEW (&parser_obstack, struct c_arg_info);
|
2537 |
|
|
ret->parms = 0;
|
2538 |
|
|
ret->tags = 0;
|
2539 |
|
|
ret->types = list;
|
2540 |
|
|
ret->others = 0;
|
2541 |
|
|
ret->pending_sizes = 0;
|
2542 |
|
|
ret->had_vla_unspec = 0;
|
2543 |
|
|
c_parser_consume_token (parser);
|
2544 |
|
|
pop_scope ();
|
2545 |
|
|
return ret;
|
2546 |
|
|
}
|
2547 |
|
|
else
|
2548 |
|
|
{
|
2549 |
|
|
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
|
2550 |
|
|
"expected %<)%>");
|
2551 |
|
|
pop_scope ();
|
2552 |
|
|
return NULL;
|
2553 |
|
|
}
|
2554 |
|
|
}
|
2555 |
|
|
else
|
2556 |
|
|
{
|
2557 |
|
|
struct c_arg_info *ret = c_parser_parms_list_declarator (parser, attrs);
|
2558 |
|
|
pop_scope ();
|
2559 |
|
|
return ret;
|
2560 |
|
|
}
|
2561 |
|
|
}
|
2562 |
|
|
|
2563 |
|
|
/* Parse a parameter list (possibly empty), including the closing
|
2564 |
|
|
parenthesis but not the opening one. ATTRS are the attributes at
|
2565 |
|
|
the start of the list. */
|
2566 |
|
|
|
2567 |
|
|
static struct c_arg_info *
|
2568 |
|
|
c_parser_parms_list_declarator (c_parser *parser, tree attrs)
|
2569 |
|
|
{
|
2570 |
|
|
bool good_parm = false;
|
2571 |
|
|
/* ??? Following the old parser, forward parameter declarations may
|
2572 |
|
|
use abstract declarators, and if no real parameter declarations
|
2573 |
|
|
follow the forward declarations then this is not diagnosed. Also
|
2574 |
|
|
note as above that attributes are ignored as the only contents of
|
2575 |
|
|
the parentheses, or as the only contents after forward
|
2576 |
|
|
declarations. */
|
2577 |
|
|
if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
|
2578 |
|
|
{
|
2579 |
|
|
struct c_arg_info *ret = XOBNEW (&parser_obstack, struct c_arg_info);
|
2580 |
|
|
ret->parms = 0;
|
2581 |
|
|
ret->tags = 0;
|
2582 |
|
|
ret->types = 0;
|
2583 |
|
|
ret->others = 0;
|
2584 |
|
|
ret->pending_sizes = 0;
|
2585 |
|
|
ret->had_vla_unspec = 0;
|
2586 |
|
|
c_parser_consume_token (parser);
|
2587 |
|
|
return ret;
|
2588 |
|
|
}
|
2589 |
|
|
if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
|
2590 |
|
|
{
|
2591 |
|
|
struct c_arg_info *ret = XOBNEW (&parser_obstack, struct c_arg_info);
|
2592 |
|
|
ret->parms = 0;
|
2593 |
|
|
ret->tags = 0;
|
2594 |
|
|
ret->others = 0;
|
2595 |
|
|
ret->pending_sizes = 0;
|
2596 |
|
|
ret->had_vla_unspec = 0;
|
2597 |
|
|
/* Suppress -Wold-style-definition for this case. */
|
2598 |
|
|
ret->types = error_mark_node;
|
2599 |
|
|
error_at (c_parser_peek_token (parser)->location,
|
2600 |
|
|
"ISO C requires a named argument before %<...%>");
|
2601 |
|
|
c_parser_consume_token (parser);
|
2602 |
|
|
if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
|
2603 |
|
|
{
|
2604 |
|
|
c_parser_consume_token (parser);
|
2605 |
|
|
return ret;
|
2606 |
|
|
}
|
2607 |
|
|
else
|
2608 |
|
|
{
|
2609 |
|
|
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
|
2610 |
|
|
"expected %<)%>");
|
2611 |
|
|
return NULL;
|
2612 |
|
|
}
|
2613 |
|
|
}
|
2614 |
|
|
/* Nonempty list of parameters, either terminated with semicolon
|
2615 |
|
|
(forward declarations; recurse) or with close parenthesis (normal
|
2616 |
|
|
function) or with ", ... )" (variadic function). */
|
2617 |
|
|
while (true)
|
2618 |
|
|
{
|
2619 |
|
|
/* Parse a parameter. */
|
2620 |
|
|
struct c_parm *parm = c_parser_parameter_declaration (parser, attrs);
|
2621 |
|
|
attrs = NULL_TREE;
|
2622 |
|
|
if (parm != NULL)
|
2623 |
|
|
{
|
2624 |
|
|
good_parm = true;
|
2625 |
|
|
push_parm_decl (parm);
|
2626 |
|
|
}
|
2627 |
|
|
if (c_parser_next_token_is (parser, CPP_SEMICOLON))
|
2628 |
|
|
{
|
2629 |
|
|
tree new_attrs;
|
2630 |
|
|
c_parser_consume_token (parser);
|
2631 |
|
|
mark_forward_parm_decls ();
|
2632 |
|
|
new_attrs = c_parser_attributes (parser);
|
2633 |
|
|
return c_parser_parms_list_declarator (parser, new_attrs);
|
2634 |
|
|
}
|
2635 |
|
|
if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
|
2636 |
|
|
{
|
2637 |
|
|
c_parser_consume_token (parser);
|
2638 |
|
|
if (good_parm)
|
2639 |
|
|
return get_parm_info (false);
|
2640 |
|
|
else
|
2641 |
|
|
{
|
2642 |
|
|
struct c_arg_info *ret
|
2643 |
|
|
= XOBNEW (&parser_obstack, struct c_arg_info);
|
2644 |
|
|
ret->parms = 0;
|
2645 |
|
|
ret->tags = 0;
|
2646 |
|
|
ret->types = 0;
|
2647 |
|
|
ret->others = 0;
|
2648 |
|
|
ret->pending_sizes = 0;
|
2649 |
|
|
ret->had_vla_unspec = 0;
|
2650 |
|
|
return ret;
|
2651 |
|
|
}
|
2652 |
|
|
}
|
2653 |
|
|
if (!c_parser_require (parser, CPP_COMMA,
|
2654 |
|
|
"expected %<;%>, %<,%> or %<)%>"))
|
2655 |
|
|
{
|
2656 |
|
|
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
|
2657 |
|
|
get_pending_sizes ();
|
2658 |
|
|
return NULL;
|
2659 |
|
|
}
|
2660 |
|
|
if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
|
2661 |
|
|
{
|
2662 |
|
|
c_parser_consume_token (parser);
|
2663 |
|
|
if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
|
2664 |
|
|
{
|
2665 |
|
|
c_parser_consume_token (parser);
|
2666 |
|
|
if (good_parm)
|
2667 |
|
|
return get_parm_info (true);
|
2668 |
|
|
else
|
2669 |
|
|
{
|
2670 |
|
|
struct c_arg_info *ret
|
2671 |
|
|
= XOBNEW (&parser_obstack, struct c_arg_info);
|
2672 |
|
|
ret->parms = 0;
|
2673 |
|
|
ret->tags = 0;
|
2674 |
|
|
ret->types = 0;
|
2675 |
|
|
ret->others = 0;
|
2676 |
|
|
ret->pending_sizes = 0;
|
2677 |
|
|
ret->had_vla_unspec = 0;
|
2678 |
|
|
return ret;
|
2679 |
|
|
}
|
2680 |
|
|
}
|
2681 |
|
|
else
|
2682 |
|
|
{
|
2683 |
|
|
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
|
2684 |
|
|
"expected %<)%>");
|
2685 |
|
|
get_pending_sizes ();
|
2686 |
|
|
return NULL;
|
2687 |
|
|
}
|
2688 |
|
|
}
|
2689 |
|
|
}
|
2690 |
|
|
}
|
2691 |
|
|
|
2692 |
|
|
/* Parse a parameter declaration. ATTRS are the attributes at the
|
2693 |
|
|
start of the declaration if it is the first parameter. */
|
2694 |
|
|
|
2695 |
|
|
static struct c_parm *
|
2696 |
|
|
c_parser_parameter_declaration (c_parser *parser, tree attrs)
|
2697 |
|
|
{
|
2698 |
|
|
struct c_declspecs *specs;
|
2699 |
|
|
struct c_declarator *declarator;
|
2700 |
|
|
tree prefix_attrs;
|
2701 |
|
|
tree postfix_attrs = NULL_TREE;
|
2702 |
|
|
bool dummy = false;
|
2703 |
|
|
if (!c_parser_next_token_starts_declspecs (parser))
|
2704 |
|
|
{
|
2705 |
|
|
/* ??? In some Objective-C cases '...' isn't applicable so there
|
2706 |
|
|
should be a different message. */
|
2707 |
|
|
c_parser_error (parser,
|
2708 |
|
|
"expected declaration specifiers or %<...%>");
|
2709 |
|
|
c_parser_skip_to_end_of_parameter (parser);
|
2710 |
|
|
return NULL;
|
2711 |
|
|
}
|
2712 |
|
|
specs = build_null_declspecs ();
|
2713 |
|
|
if (attrs)
|
2714 |
|
|
{
|
2715 |
|
|
declspecs_add_attrs (specs, attrs);
|
2716 |
|
|
attrs = NULL_TREE;
|
2717 |
|
|
}
|
2718 |
|
|
c_parser_declspecs (parser, specs, true, true, true);
|
2719 |
|
|
finish_declspecs (specs);
|
2720 |
|
|
pending_xref_error ();
|
2721 |
|
|
prefix_attrs = specs->attrs;
|
2722 |
|
|
specs->attrs = NULL_TREE;
|
2723 |
|
|
declarator = c_parser_declarator (parser, specs->type_seen_p,
|
2724 |
|
|
C_DTR_PARM, &dummy);
|
2725 |
|
|
if (declarator == NULL)
|
2726 |
|
|
{
|
2727 |
|
|
c_parser_skip_until_found (parser, CPP_COMMA, NULL);
|
2728 |
|
|
return NULL;
|
2729 |
|
|
}
|
2730 |
|
|
if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
|
2731 |
|
|
postfix_attrs = c_parser_attributes (parser);
|
2732 |
|
|
return build_c_parm (specs, chainon (postfix_attrs, prefix_attrs),
|
2733 |
|
|
declarator);
|
2734 |
|
|
}
|
2735 |
|
|
|
2736 |
|
|
/* Parse a string literal in an asm expression. It should not be
|
2737 |
|
|
translated, and wide string literals are an error although
|
2738 |
|
|
permitted by the syntax. This is a GNU extension.
|
2739 |
|
|
|
2740 |
|
|
asm-string-literal:
|
2741 |
|
|
string-literal
|
2742 |
|
|
|
2743 |
|
|
??? At present, following the old parser, the caller needs to have
|
2744 |
|
|
set lex_untranslated_string to 1. It would be better to follow the
|
2745 |
|
|
C++ parser rather than using this kludge. */
|
2746 |
|
|
|
2747 |
|
|
static tree
|
2748 |
|
|
c_parser_asm_string_literal (c_parser *parser)
|
2749 |
|
|
{
|
2750 |
|
|
tree str;
|
2751 |
|
|
if (c_parser_next_token_is (parser, CPP_STRING))
|
2752 |
|
|
{
|
2753 |
|
|
str = c_parser_peek_token (parser)->value;
|
2754 |
|
|
c_parser_consume_token (parser);
|
2755 |
|
|
}
|
2756 |
|
|
else if (c_parser_next_token_is (parser, CPP_WSTRING))
|
2757 |
|
|
{
|
2758 |
|
|
error_at (c_parser_peek_token (parser)->location,
|
2759 |
|
|
"wide string literal in %<asm%>");
|
2760 |
|
|
str = build_string (1, "");
|
2761 |
|
|
c_parser_consume_token (parser);
|
2762 |
|
|
}
|
2763 |
|
|
else
|
2764 |
|
|
{
|
2765 |
|
|
c_parser_error (parser, "expected string literal");
|
2766 |
|
|
str = NULL_TREE;
|
2767 |
|
|
}
|
2768 |
|
|
return str;
|
2769 |
|
|
}
|
2770 |
|
|
|
2771 |
|
|
/* Parse a simple asm expression. This is used in restricted
|
2772 |
|
|
contexts, where a full expression with inputs and outputs does not
|
2773 |
|
|
make sense. This is a GNU extension.
|
2774 |
|
|
|
2775 |
|
|
simple-asm-expr:
|
2776 |
|
|
asm ( asm-string-literal )
|
2777 |
|
|
*/
|
2778 |
|
|
|
2779 |
|
|
static tree
|
2780 |
|
|
c_parser_simple_asm_expr (c_parser *parser)
|
2781 |
|
|
{
|
2782 |
|
|
tree str;
|
2783 |
|
|
gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
|
2784 |
|
|
/* ??? Follow the C++ parser rather than using the
|
2785 |
|
|
lex_untranslated_string kludge. */
|
2786 |
|
|
parser->lex_untranslated_string = true;
|
2787 |
|
|
c_parser_consume_token (parser);
|
2788 |
|
|
if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
|
2789 |
|
|
{
|
2790 |
|
|
parser->lex_untranslated_string = false;
|
2791 |
|
|
return NULL_TREE;
|
2792 |
|
|
}
|
2793 |
|
|
str = c_parser_asm_string_literal (parser);
|
2794 |
|
|
parser->lex_untranslated_string = false;
|
2795 |
|
|
if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
|
2796 |
|
|
{
|
2797 |
|
|
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
|
2798 |
|
|
return NULL_TREE;
|
2799 |
|
|
}
|
2800 |
|
|
return str;
|
2801 |
|
|
}
|
2802 |
|
|
|
2803 |
|
|
/* Parse (possibly empty) attributes. This is a GNU extension.
|
2804 |
|
|
|
2805 |
|
|
attributes:
|
2806 |
|
|
empty
|
2807 |
|
|
attributes attribute
|
2808 |
|
|
|
2809 |
|
|
attribute:
|
2810 |
|
|
__attribute__ ( ( attribute-list ) )
|
2811 |
|
|
|
2812 |
|
|
attribute-list:
|
2813 |
|
|
attrib
|
2814 |
|
|
attribute_list , attrib
|
2815 |
|
|
|
2816 |
|
|
attrib:
|
2817 |
|
|
empty
|
2818 |
|
|
any-word
|
2819 |
|
|
any-word ( identifier )
|
2820 |
|
|
any-word ( identifier , nonempty-expr-list )
|
2821 |
|
|
any-word ( expr-list )
|
2822 |
|
|
|
2823 |
|
|
where the "identifier" must not be declared as a type, and
|
2824 |
|
|
"any-word" may be any identifier (including one declared as a
|
2825 |
|
|
type), a reserved word storage class specifier, type specifier or
|
2826 |
|
|
type qualifier. ??? This still leaves out most reserved keywords
|
2827 |
|
|
(following the old parser), shouldn't we include them, and why not
|
2828 |
|
|
allow identifiers declared as types to start the arguments? */
|
2829 |
|
|
|
2830 |
|
|
static tree
|
2831 |
|
|
c_parser_attributes (c_parser *parser)
|
2832 |
|
|
{
|
2833 |
|
|
tree attrs = NULL_TREE;
|
2834 |
|
|
while (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
|
2835 |
|
|
{
|
2836 |
|
|
/* ??? Follow the C++ parser rather than using the
|
2837 |
|
|
lex_untranslated_string kludge. */
|
2838 |
|
|
parser->lex_untranslated_string = true;
|
2839 |
|
|
c_parser_consume_token (parser);
|
2840 |
|
|
if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
|
2841 |
|
|
{
|
2842 |
|
|
parser->lex_untranslated_string = false;
|
2843 |
|
|
return attrs;
|
2844 |
|
|
}
|
2845 |
|
|
if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
|
2846 |
|
|
{
|
2847 |
|
|
parser->lex_untranslated_string = false;
|
2848 |
|
|
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
|
2849 |
|
|
return attrs;
|
2850 |
|
|
}
|
2851 |
|
|
/* Parse the attribute list. */
|
2852 |
|
|
while (c_parser_next_token_is (parser, CPP_COMMA)
|
2853 |
|
|
|| c_parser_next_token_is (parser, CPP_NAME)
|
2854 |
|
|
|| c_parser_next_token_is (parser, CPP_KEYWORD))
|
2855 |
|
|
{
|
2856 |
|
|
tree attr, attr_name, attr_args;
|
2857 |
|
|
VEC(tree,gc) *expr_list;
|
2858 |
|
|
if (c_parser_next_token_is (parser, CPP_COMMA))
|
2859 |
|
|
{
|
2860 |
|
|
c_parser_consume_token (parser);
|
2861 |
|
|
continue;
|
2862 |
|
|
}
|
2863 |
|
|
if (c_parser_next_token_is (parser, CPP_KEYWORD))
|
2864 |
|
|
{
|
2865 |
|
|
/* ??? See comment above about what keywords are
|
2866 |
|
|
accepted here. */
|
2867 |
|
|
bool ok;
|
2868 |
|
|
switch (c_parser_peek_token (parser)->keyword)
|
2869 |
|
|
{
|
2870 |
|
|
case RID_STATIC:
|
2871 |
|
|
case RID_UNSIGNED:
|
2872 |
|
|
case RID_LONG:
|
2873 |
|
|
case RID_CONST:
|
2874 |
|
|
case RID_EXTERN:
|
2875 |
|
|
case RID_REGISTER:
|
2876 |
|
|
case RID_TYPEDEF:
|
2877 |
|
|
case RID_SHORT:
|
2878 |
|
|
case RID_INLINE:
|
2879 |
|
|
case RID_VOLATILE:
|
2880 |
|
|
case RID_SIGNED:
|
2881 |
|
|
case RID_AUTO:
|
2882 |
|
|
case RID_RESTRICT:
|
2883 |
|
|
case RID_COMPLEX:
|
2884 |
|
|
case RID_THREAD:
|
2885 |
|
|
case RID_INT:
|
2886 |
|
|
case RID_CHAR:
|
2887 |
|
|
case RID_FLOAT:
|
2888 |
|
|
case RID_DOUBLE:
|
2889 |
|
|
case RID_VOID:
|
2890 |
|
|
case RID_DFLOAT32:
|
2891 |
|
|
case RID_DFLOAT64:
|
2892 |
|
|
case RID_DFLOAT128:
|
2893 |
|
|
case RID_BOOL:
|
2894 |
|
|
case RID_FRACT:
|
2895 |
|
|
case RID_ACCUM:
|
2896 |
|
|
case RID_SAT:
|
2897 |
|
|
ok = true;
|
2898 |
|
|
break;
|
2899 |
|
|
default:
|
2900 |
|
|
ok = false;
|
2901 |
|
|
break;
|
2902 |
|
|
}
|
2903 |
|
|
if (!ok)
|
2904 |
|
|
break;
|
2905 |
|
|
/* Accept __attribute__((__const)) as __attribute__((const))
|
2906 |
|
|
etc. */
|
2907 |
|
|
attr_name
|
2908 |
|
|
= ridpointers[(int) c_parser_peek_token (parser)->keyword];
|
2909 |
|
|
}
|
2910 |
|
|
else
|
2911 |
|
|
attr_name = c_parser_peek_token (parser)->value;
|
2912 |
|
|
c_parser_consume_token (parser);
|
2913 |
|
|
if (c_parser_next_token_is_not (parser, CPP_OPEN_PAREN))
|
2914 |
|
|
{
|
2915 |
|
|
attr = build_tree_list (attr_name, NULL_TREE);
|
2916 |
|
|
attrs = chainon (attrs, attr);
|
2917 |
|
|
continue;
|
2918 |
|
|
}
|
2919 |
|
|
c_parser_consume_token (parser);
|
2920 |
|
|
/* Parse the attribute contents. If they start with an
|
2921 |
|
|
identifier which is followed by a comma or close
|
2922 |
|
|
parenthesis, then the arguments start with that
|
2923 |
|
|
identifier; otherwise they are an expression list. */
|
2924 |
|
|
if (c_parser_next_token_is (parser, CPP_NAME)
|
2925 |
|
|
&& c_parser_peek_token (parser)->id_kind == C_ID_ID
|
2926 |
|
|
&& ((c_parser_peek_2nd_token (parser)->type == CPP_COMMA)
|
2927 |
|
|
|| (c_parser_peek_2nd_token (parser)->type
|
2928 |
|
|
== CPP_CLOSE_PAREN)))
|
2929 |
|
|
{
|
2930 |
|
|
tree arg1 = c_parser_peek_token (parser)->value;
|
2931 |
|
|
c_parser_consume_token (parser);
|
2932 |
|
|
if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
|
2933 |
|
|
attr_args = build_tree_list (NULL_TREE, arg1);
|
2934 |
|
|
else
|
2935 |
|
|
{
|
2936 |
|
|
tree tree_list;
|
2937 |
|
|
c_parser_consume_token (parser);
|
2938 |
|
|
expr_list = c_parser_expr_list (parser, false, true, NULL);
|
2939 |
|
|
tree_list = build_tree_list_vec (expr_list);
|
2940 |
|
|
attr_args = tree_cons (NULL_TREE, arg1, tree_list);
|
2941 |
|
|
release_tree_vector (expr_list);
|
2942 |
|
|
}
|
2943 |
|
|
}
|
2944 |
|
|
else
|
2945 |
|
|
{
|
2946 |
|
|
if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
|
2947 |
|
|
attr_args = NULL_TREE;
|
2948 |
|
|
else
|
2949 |
|
|
{
|
2950 |
|
|
expr_list = c_parser_expr_list (parser, false, true, NULL);
|
2951 |
|
|
attr_args = build_tree_list_vec (expr_list);
|
2952 |
|
|
release_tree_vector (expr_list);
|
2953 |
|
|
}
|
2954 |
|
|
}
|
2955 |
|
|
attr = build_tree_list (attr_name, attr_args);
|
2956 |
|
|
if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
|
2957 |
|
|
c_parser_consume_token (parser);
|
2958 |
|
|
else
|
2959 |
|
|
{
|
2960 |
|
|
parser->lex_untranslated_string = false;
|
2961 |
|
|
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
|
2962 |
|
|
"expected %<)%>");
|
2963 |
|
|
return attrs;
|
2964 |
|
|
}
|
2965 |
|
|
attrs = chainon (attrs, attr);
|
2966 |
|
|
}
|
2967 |
|
|
if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
|
2968 |
|
|
c_parser_consume_token (parser);
|
2969 |
|
|
else
|
2970 |
|
|
{
|
2971 |
|
|
parser->lex_untranslated_string = false;
|
2972 |
|
|
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
|
2973 |
|
|
"expected %<)%>");
|
2974 |
|
|
return attrs;
|
2975 |
|
|
}
|
2976 |
|
|
if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
|
2977 |
|
|
c_parser_consume_token (parser);
|
2978 |
|
|
else
|
2979 |
|
|
{
|
2980 |
|
|
parser->lex_untranslated_string = false;
|
2981 |
|
|
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
|
2982 |
|
|
"expected %<)%>");
|
2983 |
|
|
return attrs;
|
2984 |
|
|
}
|
2985 |
|
|
parser->lex_untranslated_string = false;
|
2986 |
|
|
}
|
2987 |
|
|
return attrs;
|
2988 |
|
|
}
|
2989 |
|
|
|
2990 |
|
|
/* Parse a type name (C90 6.5.5, C99 6.7.6).
|
2991 |
|
|
|
2992 |
|
|
type-name:
|
2993 |
|
|
specifier-qualifier-list abstract-declarator[opt]
|
2994 |
|
|
*/
|
2995 |
|
|
|
2996 |
|
|
static struct c_type_name *
|
2997 |
|
|
c_parser_type_name (c_parser *parser)
|
2998 |
|
|
{
|
2999 |
|
|
struct c_declspecs *specs = build_null_declspecs ();
|
3000 |
|
|
struct c_declarator *declarator;
|
3001 |
|
|
struct c_type_name *ret;
|
3002 |
|
|
bool dummy = false;
|
3003 |
|
|
c_parser_declspecs (parser, specs, false, true, true);
|
3004 |
|
|
if (!specs->declspecs_seen_p)
|
3005 |
|
|
{
|
3006 |
|
|
c_parser_error (parser, "expected specifier-qualifier-list");
|
3007 |
|
|
return NULL;
|
3008 |
|
|
}
|
3009 |
|
|
pending_xref_error ();
|
3010 |
|
|
finish_declspecs (specs);
|
3011 |
|
|
declarator = c_parser_declarator (parser, specs->type_seen_p,
|
3012 |
|
|
C_DTR_ABSTRACT, &dummy);
|
3013 |
|
|
if (declarator == NULL)
|
3014 |
|
|
return NULL;
|
3015 |
|
|
ret = XOBNEW (&parser_obstack, struct c_type_name);
|
3016 |
|
|
ret->specs = specs;
|
3017 |
|
|
ret->declarator = declarator;
|
3018 |
|
|
return ret;
|
3019 |
|
|
}
|
3020 |
|
|
|
3021 |
|
|
/* Parse an initializer (C90 6.5.7, C99 6.7.8).
|
3022 |
|
|
|
3023 |
|
|
initializer:
|
3024 |
|
|
assignment-expression
|
3025 |
|
|
{ initializer-list }
|
3026 |
|
|
{ initializer-list , }
|
3027 |
|
|
|
3028 |
|
|
initializer-list:
|
3029 |
|
|
designation[opt] initializer
|
3030 |
|
|
initializer-list , designation[opt] initializer
|
3031 |
|
|
|
3032 |
|
|
designation:
|
3033 |
|
|
designator-list =
|
3034 |
|
|
|
3035 |
|
|
designator-list:
|
3036 |
|
|
designator
|
3037 |
|
|
designator-list designator
|
3038 |
|
|
|
3039 |
|
|
designator:
|
3040 |
|
|
array-designator
|
3041 |
|
|
. identifier
|
3042 |
|
|
|
3043 |
|
|
array-designator:
|
3044 |
|
|
[ constant-expression ]
|
3045 |
|
|
|
3046 |
|
|
GNU extensions:
|
3047 |
|
|
|
3048 |
|
|
initializer:
|
3049 |
|
|
{ }
|
3050 |
|
|
|
3051 |
|
|
designation:
|
3052 |
|
|
array-designator
|
3053 |
|
|
identifier :
|
3054 |
|
|
|
3055 |
|
|
array-designator:
|
3056 |
|
|
[ constant-expression ... constant-expression ]
|
3057 |
|
|
|
3058 |
|
|
Any expression without commas is accepted in the syntax for the
|
3059 |
|
|
constant-expressions, with non-constant expressions rejected later.
|
3060 |
|
|
|
3061 |
|
|
This function is only used for top-level initializers; for nested
|
3062 |
|
|
ones, see c_parser_initval. */
|
3063 |
|
|
|
3064 |
|
|
static struct c_expr
|
3065 |
|
|
c_parser_initializer (c_parser *parser)
|
3066 |
|
|
{
|
3067 |
|
|
if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
|
3068 |
|
|
return c_parser_braced_init (parser, NULL_TREE, false);
|
3069 |
|
|
else
|
3070 |
|
|
{
|
3071 |
|
|
struct c_expr ret;
|
3072 |
|
|
location_t loc = c_parser_peek_token (parser)->location;
|
3073 |
|
|
ret = c_parser_expr_no_commas (parser, NULL);
|
3074 |
|
|
if (TREE_CODE (ret.value) != STRING_CST
|
3075 |
|
|
&& TREE_CODE (ret.value) != COMPOUND_LITERAL_EXPR)
|
3076 |
|
|
ret = default_function_array_conversion (loc, ret);
|
3077 |
|
|
return ret;
|
3078 |
|
|
}
|
3079 |
|
|
}
|
3080 |
|
|
|
3081 |
|
|
/* Parse a braced initializer list. TYPE is the type specified for a
|
3082 |
|
|
compound literal, and NULL_TREE for other initializers and for
|
3083 |
|
|
nested braced lists. NESTED_P is true for nested braced lists,
|
3084 |
|
|
false for the list of a compound literal or the list that is the
|
3085 |
|
|
top-level initializer in a declaration. */
|
3086 |
|
|
|
3087 |
|
|
static struct c_expr
|
3088 |
|
|
c_parser_braced_init (c_parser *parser, tree type, bool nested_p)
|
3089 |
|
|
{
|
3090 |
|
|
location_t brace_loc = c_parser_peek_token (parser)->location;
|
3091 |
|
|
gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE));
|
3092 |
|
|
c_parser_consume_token (parser);
|
3093 |
|
|
if (nested_p)
|
3094 |
|
|
push_init_level (0);
|
3095 |
|
|
else
|
3096 |
|
|
really_start_incremental_init (type);
|
3097 |
|
|
if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
|
3098 |
|
|
{
|
3099 |
|
|
pedwarn (brace_loc, OPT_pedantic, "ISO C forbids empty initializer braces");
|
3100 |
|
|
}
|
3101 |
|
|
else
|
3102 |
|
|
{
|
3103 |
|
|
/* Parse a non-empty initializer list, possibly with a trailing
|
3104 |
|
|
comma. */
|
3105 |
|
|
while (true)
|
3106 |
|
|
{
|
3107 |
|
|
c_parser_initelt (parser);
|
3108 |
|
|
if (parser->error)
|
3109 |
|
|
break;
|
3110 |
|
|
if (c_parser_next_token_is (parser, CPP_COMMA))
|
3111 |
|
|
c_parser_consume_token (parser);
|
3112 |
|
|
else
|
3113 |
|
|
break;
|
3114 |
|
|
if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
|
3115 |
|
|
break;
|
3116 |
|
|
}
|
3117 |
|
|
}
|
3118 |
|
|
if (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE))
|
3119 |
|
|
{
|
3120 |
|
|
struct c_expr ret;
|
3121 |
|
|
ret.value = error_mark_node;
|
3122 |
|
|
ret.original_code = ERROR_MARK;
|
3123 |
|
|
ret.original_type = NULL;
|
3124 |
|
|
c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, "expected %<}%>");
|
3125 |
|
|
pop_init_level (0);
|
3126 |
|
|
return ret;
|
3127 |
|
|
}
|
3128 |
|
|
c_parser_consume_token (parser);
|
3129 |
|
|
return pop_init_level (0);
|
3130 |
|
|
}
|
3131 |
|
|
|
3132 |
|
|
/* Parse a nested initializer, including designators. */
|
3133 |
|
|
|
3134 |
|
|
static void
|
3135 |
|
|
c_parser_initelt (c_parser *parser)
|
3136 |
|
|
{
|
3137 |
|
|
/* Parse any designator or designator list. A single array
|
3138 |
|
|
designator may have the subsequent "=" omitted in GNU C, but a
|
3139 |
|
|
longer list or a structure member designator may not. */
|
3140 |
|
|
if (c_parser_next_token_is (parser, CPP_NAME)
|
3141 |
|
|
&& c_parser_peek_2nd_token (parser)->type == CPP_COLON)
|
3142 |
|
|
{
|
3143 |
|
|
/* Old-style structure member designator. */
|
3144 |
|
|
set_init_label (c_parser_peek_token (parser)->value);
|
3145 |
|
|
/* Use the colon as the error location. */
|
3146 |
|
|
pedwarn (c_parser_peek_2nd_token (parser)->location, OPT_pedantic,
|
3147 |
|
|
"obsolete use of designated initializer with %<:%>");
|
3148 |
|
|
c_parser_consume_token (parser);
|
3149 |
|
|
c_parser_consume_token (parser);
|
3150 |
|
|
}
|
3151 |
|
|
else
|
3152 |
|
|
{
|
3153 |
|
|
/* des_seen is 0 if there have been no designators, 1 if there
|
3154 |
|
|
has been a single array designator and 2 otherwise. */
|
3155 |
|
|
int des_seen = 0;
|
3156 |
|
|
/* Location of a designator. */
|
3157 |
|
|
location_t des_loc = UNKNOWN_LOCATION; /* Quiet warning. */
|
3158 |
|
|
while (c_parser_next_token_is (parser, CPP_OPEN_SQUARE)
|
3159 |
|
|
|| c_parser_next_token_is (parser, CPP_DOT))
|
3160 |
|
|
{
|
3161 |
|
|
int des_prev = des_seen;
|
3162 |
|
|
if (!des_seen)
|
3163 |
|
|
des_loc = c_parser_peek_token (parser)->location;
|
3164 |
|
|
if (des_seen < 2)
|
3165 |
|
|
des_seen++;
|
3166 |
|
|
if (c_parser_next_token_is (parser, CPP_DOT))
|
3167 |
|
|
{
|
3168 |
|
|
des_seen = 2;
|
3169 |
|
|
c_parser_consume_token (parser);
|
3170 |
|
|
if (c_parser_next_token_is (parser, CPP_NAME))
|
3171 |
|
|
{
|
3172 |
|
|
set_init_label (c_parser_peek_token (parser)->value);
|
3173 |
|
|
c_parser_consume_token (parser);
|
3174 |
|
|
}
|
3175 |
|
|
else
|
3176 |
|
|
{
|
3177 |
|
|
struct c_expr init;
|
3178 |
|
|
init.value = error_mark_node;
|
3179 |
|
|
init.original_code = ERROR_MARK;
|
3180 |
|
|
init.original_type = NULL;
|
3181 |
|
|
c_parser_error (parser, "expected identifier");
|
3182 |
|
|
c_parser_skip_until_found (parser, CPP_COMMA, NULL);
|
3183 |
|
|
process_init_element (init, false);
|
3184 |
|
|
return;
|
3185 |
|
|
}
|
3186 |
|
|
}
|
3187 |
|
|
else
|
3188 |
|
|
{
|
3189 |
|
|
tree first, second;
|
3190 |
|
|
location_t ellipsis_loc = UNKNOWN_LOCATION; /* Quiet warning. */
|
3191 |
|
|
/* ??? Following the old parser, [ objc-receiver
|
3192 |
|
|
objc-message-args ] is accepted as an initializer,
|
3193 |
|
|
being distinguished from a designator by what follows
|
3194 |
|
|
the first assignment expression inside the square
|
3195 |
|
|
brackets, but after a first array designator a
|
3196 |
|
|
subsequent square bracket is for Objective-C taken to
|
3197 |
|
|
start an expression, using the obsolete form of
|
3198 |
|
|
designated initializer without '=', rather than
|
3199 |
|
|
possibly being a second level of designation: in LALR
|
3200 |
|
|
terms, the '[' is shifted rather than reducing
|
3201 |
|
|
designator to designator-list. */
|
3202 |
|
|
if (des_prev == 1 && c_dialect_objc ())
|
3203 |
|
|
{
|
3204 |
|
|
des_seen = des_prev;
|
3205 |
|
|
break;
|
3206 |
|
|
}
|
3207 |
|
|
if (des_prev == 0 && c_dialect_objc ())
|
3208 |
|
|
{
|
3209 |
|
|
/* This might be an array designator or an
|
3210 |
|
|
Objective-C message expression. If the former,
|
3211 |
|
|
continue parsing here; if the latter, parse the
|
3212 |
|
|
remainder of the initializer given the starting
|
3213 |
|
|
primary-expression. ??? It might make sense to
|
3214 |
|
|
distinguish when des_prev == 1 as well; see
|
3215 |
|
|
previous comment. */
|
3216 |
|
|
tree rec, args;
|
3217 |
|
|
struct c_expr mexpr;
|
3218 |
|
|
c_parser_consume_token (parser);
|
3219 |
|
|
if (c_parser_peek_token (parser)->type == CPP_NAME
|
3220 |
|
|
&& ((c_parser_peek_token (parser)->id_kind
|
3221 |
|
|
== C_ID_TYPENAME)
|
3222 |
|
|
|| (c_parser_peek_token (parser)->id_kind
|
3223 |
|
|
== C_ID_CLASSNAME)))
|
3224 |
|
|
{
|
3225 |
|
|
/* Type name receiver. */
|
3226 |
|
|
tree id = c_parser_peek_token (parser)->value;
|
3227 |
|
|
c_parser_consume_token (parser);
|
3228 |
|
|
rec = objc_get_class_reference (id);
|
3229 |
|
|
goto parse_message_args;
|
3230 |
|
|
}
|
3231 |
|
|
first = c_parser_expr_no_commas (parser, NULL).value;
|
3232 |
|
|
if (c_parser_next_token_is (parser, CPP_ELLIPSIS)
|
3233 |
|
|
|| c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
|
3234 |
|
|
goto array_desig_after_first;
|
3235 |
|
|
/* Expression receiver. So far only one part
|
3236 |
|
|
without commas has been parsed; there might be
|
3237 |
|
|
more of the expression. */
|
3238 |
|
|
rec = first;
|
3239 |
|
|
while (c_parser_next_token_is (parser, CPP_COMMA))
|
3240 |
|
|
{
|
3241 |
|
|
struct c_expr next;
|
3242 |
|
|
location_t comma_loc, exp_loc;
|
3243 |
|
|
comma_loc = c_parser_peek_token (parser)->location;
|
3244 |
|
|
c_parser_consume_token (parser);
|
3245 |
|
|
exp_loc = c_parser_peek_token (parser)->location;
|
3246 |
|
|
next = c_parser_expr_no_commas (parser, NULL);
|
3247 |
|
|
next = default_function_array_conversion (exp_loc, next);
|
3248 |
|
|
rec = build_compound_expr (comma_loc, rec, next.value);
|
3249 |
|
|
}
|
3250 |
|
|
parse_message_args:
|
3251 |
|
|
/* Now parse the objc-message-args. */
|
3252 |
|
|
args = c_parser_objc_message_args (parser);
|
3253 |
|
|
c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
|
3254 |
|
|
"expected %<]%>");
|
3255 |
|
|
mexpr.value
|
3256 |
|
|
= objc_build_message_expr (build_tree_list (rec, args));
|
3257 |
|
|
mexpr.original_code = ERROR_MARK;
|
3258 |
|
|
mexpr.original_type = NULL;
|
3259 |
|
|
/* Now parse and process the remainder of the
|
3260 |
|
|
initializer, starting with this message
|
3261 |
|
|
expression as a primary-expression. */
|
3262 |
|
|
c_parser_initval (parser, &mexpr);
|
3263 |
|
|
return;
|
3264 |
|
|
}
|
3265 |
|
|
c_parser_consume_token (parser);
|
3266 |
|
|
first = c_parser_expr_no_commas (parser, NULL).value;
|
3267 |
|
|
array_desig_after_first:
|
3268 |
|
|
if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
|
3269 |
|
|
{
|
3270 |
|
|
ellipsis_loc = c_parser_peek_token (parser)->location;
|
3271 |
|
|
c_parser_consume_token (parser);
|
3272 |
|
|
second = c_parser_expr_no_commas (parser, NULL).value;
|
3273 |
|
|
}
|
3274 |
|
|
else
|
3275 |
|
|
second = NULL_TREE;
|
3276 |
|
|
if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
|
3277 |
|
|
{
|
3278 |
|
|
c_parser_consume_token (parser);
|
3279 |
|
|
set_init_index (first, second);
|
3280 |
|
|
if (second)
|
3281 |
|
|
pedwarn (ellipsis_loc, OPT_pedantic,
|
3282 |
|
|
"ISO C forbids specifying range of elements to initialize");
|
3283 |
|
|
}
|
3284 |
|
|
else
|
3285 |
|
|
c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
|
3286 |
|
|
"expected %<]%>");
|
3287 |
|
|
}
|
3288 |
|
|
}
|
3289 |
|
|
if (des_seen >= 1)
|
3290 |
|
|
{
|
3291 |
|
|
if (c_parser_next_token_is (parser, CPP_EQ))
|
3292 |
|
|
{
|
3293 |
|
|
if (!flag_isoc99)
|
3294 |
|
|
pedwarn (des_loc, OPT_pedantic,
|
3295 |
|
|
"ISO C90 forbids specifying subobject to initialize");
|
3296 |
|
|
c_parser_consume_token (parser);
|
3297 |
|
|
}
|
3298 |
|
|
else
|
3299 |
|
|
{
|
3300 |
|
|
if (des_seen == 1)
|
3301 |
|
|
pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
|
3302 |
|
|
"obsolete use of designated initializer without %<=%>");
|
3303 |
|
|
else
|
3304 |
|
|
{
|
3305 |
|
|
struct c_expr init;
|
3306 |
|
|
init.value = error_mark_node;
|
3307 |
|
|
init.original_code = ERROR_MARK;
|
3308 |
|
|
init.original_type = NULL;
|
3309 |
|
|
c_parser_error (parser, "expected %<=%>");
|
3310 |
|
|
c_parser_skip_until_found (parser, CPP_COMMA, NULL);
|
3311 |
|
|
process_init_element (init, false);
|
3312 |
|
|
return;
|
3313 |
|
|
}
|
3314 |
|
|
}
|
3315 |
|
|
}
|
3316 |
|
|
}
|
3317 |
|
|
c_parser_initval (parser, NULL);
|
3318 |
|
|
}
|
3319 |
|
|
|
3320 |
|
|
/* Parse a nested initializer; as c_parser_initializer but parses
|
3321 |
|
|
initializers within braced lists, after any designators have been
|
3322 |
|
|
applied. If AFTER is not NULL then it is an Objective-C message
|
3323 |
|
|
expression which is the primary-expression starting the
|
3324 |
|
|
initializer. */
|
3325 |
|
|
|
3326 |
|
|
static void
|
3327 |
|
|
c_parser_initval (c_parser *parser, struct c_expr *after)
|
3328 |
|
|
{
|
3329 |
|
|
struct c_expr init;
|
3330 |
|
|
gcc_assert (!after || c_dialect_objc ());
|
3331 |
|
|
if (c_parser_next_token_is (parser, CPP_OPEN_BRACE) && !after)
|
3332 |
|
|
init = c_parser_braced_init (parser, NULL_TREE, true);
|
3333 |
|
|
else
|
3334 |
|
|
{
|
3335 |
|
|
location_t loc = c_parser_peek_token (parser)->location;
|
3336 |
|
|
init = c_parser_expr_no_commas (parser, after);
|
3337 |
|
|
if (init.value != NULL_TREE
|
3338 |
|
|
&& TREE_CODE (init.value) != STRING_CST
|
3339 |
|
|
&& TREE_CODE (init.value) != COMPOUND_LITERAL_EXPR)
|
3340 |
|
|
init = default_function_array_conversion (loc, init);
|
3341 |
|
|
}
|
3342 |
|
|
process_init_element (init, false);
|
3343 |
|
|
}
|
3344 |
|
|
|
3345 |
|
|
/* Parse a compound statement (possibly a function body) (C90 6.6.2,
|
3346 |
|
|
C99 6.8.2).
|
3347 |
|
|
|
3348 |
|
|
compound-statement:
|
3349 |
|
|
{ block-item-list[opt] }
|
3350 |
|
|
{ label-declarations block-item-list }
|
3351 |
|
|
|
3352 |
|
|
block-item-list:
|
3353 |
|
|
block-item
|
3354 |
|
|
block-item-list block-item
|
3355 |
|
|
|
3356 |
|
|
block-item:
|
3357 |
|
|
nested-declaration
|
3358 |
|
|
statement
|
3359 |
|
|
|
3360 |
|
|
nested-declaration:
|
3361 |
|
|
declaration
|
3362 |
|
|
|
3363 |
|
|
GNU extensions:
|
3364 |
|
|
|
3365 |
|
|
compound-statement:
|
3366 |
|
|
{ label-declarations block-item-list }
|
3367 |
|
|
|
3368 |
|
|
nested-declaration:
|
3369 |
|
|
__extension__ nested-declaration
|
3370 |
|
|
nested-function-definition
|
3371 |
|
|
|
3372 |
|
|
label-declarations:
|
3373 |
|
|
label-declaration
|
3374 |
|
|
label-declarations label-declaration
|
3375 |
|
|
|
3376 |
|
|
label-declaration:
|
3377 |
|
|
__label__ identifier-list ;
|
3378 |
|
|
|
3379 |
|
|
Allowing the mixing of declarations and code is new in C99. The
|
3380 |
|
|
GNU syntax also permits (not shown above) labels at the end of
|
3381 |
|
|
compound statements, which yield an error. We don't allow labels
|
3382 |
|
|
on declarations; this might seem like a natural extension, but
|
3383 |
|
|
there would be a conflict between attributes on the label and
|
3384 |
|
|
prefix attributes on the declaration. ??? The syntax follows the
|
3385 |
|
|
old parser in requiring something after label declarations.
|
3386 |
|
|
Although they are erroneous if the labels declared aren't defined,
|
3387 |
|
|
is it useful for the syntax to be this way?
|
3388 |
|
|
|
3389 |
|
|
OpenMP:
|
3390 |
|
|
|
3391 |
|
|
block-item:
|
3392 |
|
|
openmp-directive
|
3393 |
|
|
|
3394 |
|
|
openmp-directive:
|
3395 |
|
|
barrier-directive
|
3396 |
|
|
flush-directive */
|
3397 |
|
|
|
3398 |
|
|
static tree
|
3399 |
|
|
c_parser_compound_statement (c_parser *parser)
|
3400 |
|
|
{
|
3401 |
|
|
tree stmt;
|
3402 |
|
|
location_t brace_loc;
|
3403 |
|
|
brace_loc = c_parser_peek_token (parser)->location;
|
3404 |
|
|
if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
|
3405 |
|
|
{
|
3406 |
|
|
/* Ensure a scope is entered and left anyway to avoid confusion
|
3407 |
|
|
if we have just prepared to enter a function body. */
|
3408 |
|
|
stmt = c_begin_compound_stmt (true);
|
3409 |
|
|
c_end_compound_stmt (brace_loc, stmt, true);
|
3410 |
|
|
return error_mark_node;
|
3411 |
|
|
}
|
3412 |
|
|
stmt = c_begin_compound_stmt (true);
|
3413 |
|
|
c_parser_compound_statement_nostart (parser);
|
3414 |
|
|
return c_end_compound_stmt (brace_loc, stmt, true);
|
3415 |
|
|
}
|
3416 |
|
|
|
3417 |
|
|
/* Parse a compound statement except for the opening brace. This is
|
3418 |
|
|
used for parsing both compound statements and statement expressions
|
3419 |
|
|
(which follow different paths to handling the opening). */
|
3420 |
|
|
|
3421 |
|
|
static void
|
3422 |
|
|
c_parser_compound_statement_nostart (c_parser *parser)
|
3423 |
|
|
{
|
3424 |
|
|
bool last_stmt = false;
|
3425 |
|
|
bool last_label = false;
|
3426 |
|
|
bool save_valid_for_pragma = valid_location_for_stdc_pragma_p ();
|
3427 |
|
|
location_t label_loc = UNKNOWN_LOCATION; /* Quiet warning. */
|
3428 |
|
|
if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
|
3429 |
|
|
{
|
3430 |
|
|
c_parser_consume_token (parser);
|
3431 |
|
|
return;
|
3432 |
|
|
}
|
3433 |
|
|
mark_valid_location_for_stdc_pragma (true);
|
3434 |
|
|
if (c_parser_next_token_is_keyword (parser, RID_LABEL))
|
3435 |
|
|
{
|
3436 |
|
|
/* Read zero or more forward-declarations for labels that nested
|
3437 |
|
|
functions can jump to. */
|
3438 |
|
|
mark_valid_location_for_stdc_pragma (false);
|
3439 |
|
|
while (c_parser_next_token_is_keyword (parser, RID_LABEL))
|
3440 |
|
|
{
|
3441 |
|
|
label_loc = c_parser_peek_token (parser)->location;
|
3442 |
|
|
c_parser_consume_token (parser);
|
3443 |
|
|
/* Any identifiers, including those declared as type names,
|
3444 |
|
|
are OK here. */
|
3445 |
|
|
while (true)
|
3446 |
|
|
{
|
3447 |
|
|
tree label;
|
3448 |
|
|
if (c_parser_next_token_is_not (parser, CPP_NAME))
|
3449 |
|
|
{
|
3450 |
|
|
c_parser_error (parser, "expected identifier");
|
3451 |
|
|
break;
|
3452 |
|
|
}
|
3453 |
|
|
label
|
3454 |
|
|
= declare_label (c_parser_peek_token (parser)->value);
|
3455 |
|
|
C_DECLARED_LABEL_FLAG (label) = 1;
|
3456 |
|
|
add_stmt (build_stmt (label_loc, DECL_EXPR, label));
|
3457 |
|
|
c_parser_consume_token (parser);
|
3458 |
|
|
if (c_parser_next_token_is (parser, CPP_COMMA))
|
3459 |
|
|
c_parser_consume_token (parser);
|
3460 |
|
|
else
|
3461 |
|
|
break;
|
3462 |
|
|
}
|
3463 |
|
|
c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
|
3464 |
|
|
}
|
3465 |
|
|
pedwarn (label_loc, OPT_pedantic, "ISO C forbids label declarations");
|
3466 |
|
|
}
|
3467 |
|
|
/* We must now have at least one statement, label or declaration. */
|
3468 |
|
|
if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
|
3469 |
|
|
{
|
3470 |
|
|
mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
|
3471 |
|
|
c_parser_error (parser, "expected declaration or statement");
|
3472 |
|
|
c_parser_consume_token (parser);
|
3473 |
|
|
return;
|
3474 |
|
|
}
|
3475 |
|
|
while (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE))
|
3476 |
|
|
{
|
3477 |
|
|
location_t loc = c_parser_peek_token (parser)->location;
|
3478 |
|
|
if (c_parser_next_token_is_keyword (parser, RID_CASE)
|
3479 |
|
|
|| c_parser_next_token_is_keyword (parser, RID_DEFAULT)
|
3480 |
|
|
|| (c_parser_next_token_is (parser, CPP_NAME)
|
3481 |
|
|
&& c_parser_peek_2nd_token (parser)->type == CPP_COLON))
|
3482 |
|
|
{
|
3483 |
|
|
if (c_parser_next_token_is_keyword (parser, RID_CASE))
|
3484 |
|
|
label_loc = c_parser_peek_2nd_token (parser)->location;
|
3485 |
|
|
else
|
3486 |
|
|
label_loc = c_parser_peek_token (parser)->location;
|
3487 |
|
|
last_label = true;
|
3488 |
|
|
last_stmt = false;
|
3489 |
|
|
mark_valid_location_for_stdc_pragma (false);
|
3490 |
|
|
c_parser_label (parser);
|
3491 |
|
|
}
|
3492 |
|
|
else if (!last_label
|
3493 |
|
|
&& c_parser_next_token_starts_declspecs (parser))
|
3494 |
|
|
{
|
3495 |
|
|
last_label = false;
|
3496 |
|
|
mark_valid_location_for_stdc_pragma (false);
|
3497 |
|
|
c_parser_declaration_or_fndef (parser, true, true, true, true);
|
3498 |
|
|
if (last_stmt)
|
3499 |
|
|
pedwarn_c90 (loc,
|
3500 |
|
|
(pedantic && !flag_isoc99)
|
3501 |
|
|
? OPT_pedantic
|
3502 |
|
|
: OPT_Wdeclaration_after_statement,
|
3503 |
|
|
"ISO C90 forbids mixed declarations and code");
|
3504 |
|
|
last_stmt = false;
|
3505 |
|
|
}
|
3506 |
|
|
else if (!last_label
|
3507 |
|
|
&& c_parser_next_token_is_keyword (parser, RID_EXTENSION))
|
3508 |
|
|
{
|
3509 |
|
|
/* __extension__ can start a declaration, but is also an
|
3510 |
|
|
unary operator that can start an expression. Consume all
|
3511 |
|
|
but the last of a possible series of __extension__ to
|
3512 |
|
|
determine which. */
|
3513 |
|
|
while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD
|
3514 |
|
|
&& (c_parser_peek_2nd_token (parser)->keyword
|
3515 |
|
|
== RID_EXTENSION))
|
3516 |
|
|
c_parser_consume_token (parser);
|
3517 |
|
|
if (c_token_starts_declspecs (c_parser_peek_2nd_token (parser)))
|
3518 |
|
|
{
|
3519 |
|
|
int ext;
|
3520 |
|
|
ext = disable_extension_diagnostics ();
|
3521 |
|
|
c_parser_consume_token (parser);
|
3522 |
|
|
last_label = false;
|
3523 |
|
|
mark_valid_location_for_stdc_pragma (false);
|
3524 |
|
|
c_parser_declaration_or_fndef (parser, true, true, true, true);
|
3525 |
|
|
/* Following the old parser, __extension__ does not
|
3526 |
|
|
disable this diagnostic. */
|
3527 |
|
|
restore_extension_diagnostics (ext);
|
3528 |
|
|
if (last_stmt)
|
3529 |
|
|
pedwarn_c90 (loc, (pedantic && !flag_isoc99)
|
3530 |
|
|
? OPT_pedantic
|
3531 |
|
|
: OPT_Wdeclaration_after_statement,
|
3532 |
|
|
"ISO C90 forbids mixed declarations and code");
|
3533 |
|
|
last_stmt = false;
|
3534 |
|
|
}
|
3535 |
|
|
else
|
3536 |
|
|
goto statement;
|
3537 |
|
|
}
|
3538 |
|
|
else if (c_parser_next_token_is (parser, CPP_PRAGMA))
|
3539 |
|
|
{
|
3540 |
|
|
/* External pragmas, and some omp pragmas, are not associated
|
3541 |
|
|
with regular c code, and so are not to be considered statements
|
3542 |
|
|
syntactically. This ensures that the user doesn't put them
|
3543 |
|
|
places that would turn into syntax errors if the directive
|
3544 |
|
|
were ignored. */
|
3545 |
|
|
if (c_parser_pragma (parser, pragma_compound))
|
3546 |
|
|
last_label = false, last_stmt = true;
|
3547 |
|
|
}
|
3548 |
|
|
else if (c_parser_next_token_is (parser, CPP_EOF))
|
3549 |
|
|
{
|
3550 |
|
|
mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
|
3551 |
|
|
c_parser_error (parser, "expected declaration or statement");
|
3552 |
|
|
return;
|
3553 |
|
|
}
|
3554 |
|
|
else if (c_parser_next_token_is_keyword (parser, RID_ELSE))
|
3555 |
|
|
{
|
3556 |
|
|
if (parser->in_if_block)
|
3557 |
|
|
{
|
3558 |
|
|
mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
|
3559 |
|
|
error_at (loc, """expected %<}%> before %<else%>");
|
3560 |
|
|
return;
|
3561 |
|
|
}
|
3562 |
|
|
else
|
3563 |
|
|
{
|
3564 |
|
|
error_at (loc, "%<else%> without a previous %<if%>");
|
3565 |
|
|
c_parser_consume_token (parser);
|
3566 |
|
|
continue;
|
3567 |
|
|
}
|
3568 |
|
|
}
|
3569 |
|
|
else
|
3570 |
|
|
{
|
3571 |
|
|
statement:
|
3572 |
|
|
last_label = false;
|
3573 |
|
|
last_stmt = true;
|
3574 |
|
|
mark_valid_location_for_stdc_pragma (false);
|
3575 |
|
|
c_parser_statement_after_labels (parser);
|
3576 |
|
|
}
|
3577 |
|
|
|
3578 |
|
|
parser->error = false;
|
3579 |
|
|
}
|
3580 |
|
|
if (last_label)
|
3581 |
|
|
error_at (label_loc, "label at end of compound statement");
|
3582 |
|
|
c_parser_consume_token (parser);
|
3583 |
|
|
/* Restore the value we started with. */
|
3584 |
|
|
mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
|
3585 |
|
|
}
|
3586 |
|
|
|
3587 |
|
|
/* Parse a label (C90 6.6.1, C99 6.8.1).
|
3588 |
|
|
|
3589 |
|
|
label:
|
3590 |
|
|
identifier : attributes[opt]
|
3591 |
|
|
case constant-expression :
|
3592 |
|
|
default :
|
3593 |
|
|
|
3594 |
|
|
GNU extensions:
|
3595 |
|
|
|
3596 |
|
|
label:
|
3597 |
|
|
case constant-expression ... constant-expression :
|
3598 |
|
|
|
3599 |
|
|
The use of attributes on labels is a GNU extension. The syntax in
|
3600 |
|
|
GNU C accepts any expressions without commas, non-constant
|
3601 |
|
|
expressions being rejected later. */
|
3602 |
|
|
|
3603 |
|
|
static void
|
3604 |
|
|
c_parser_label (c_parser *parser)
|
3605 |
|
|
{
|
3606 |
|
|
location_t loc1 = c_parser_peek_token (parser)->location;
|
3607 |
|
|
tree label = NULL_TREE;
|
3608 |
|
|
if (c_parser_next_token_is_keyword (parser, RID_CASE))
|
3609 |
|
|
{
|
3610 |
|
|
tree exp1, exp2;
|
3611 |
|
|
c_parser_consume_token (parser);
|
3612 |
|
|
exp1 = c_parser_expr_no_commas (parser, NULL).value;
|
3613 |
|
|
if (c_parser_next_token_is (parser, CPP_COLON))
|
3614 |
|
|
{
|
3615 |
|
|
c_parser_consume_token (parser);
|
3616 |
|
|
label = do_case (loc1, exp1, NULL_TREE);
|
3617 |
|
|
}
|
3618 |
|
|
else if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
|
3619 |
|
|
{
|
3620 |
|
|
c_parser_consume_token (parser);
|
3621 |
|
|
exp2 = c_parser_expr_no_commas (parser, NULL).value;
|
3622 |
|
|
if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
|
3623 |
|
|
label = do_case (loc1, exp1, exp2);
|
3624 |
|
|
}
|
3625 |
|
|
else
|
3626 |
|
|
c_parser_error (parser, "expected %<:%> or %<...%>");
|
3627 |
|
|
}
|
3628 |
|
|
else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT))
|
3629 |
|
|
{
|
3630 |
|
|
c_parser_consume_token (parser);
|
3631 |
|
|
if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
|
3632 |
|
|
label = do_case (loc1, NULL_TREE, NULL_TREE);
|
3633 |
|
|
}
|
3634 |
|
|
else
|
3635 |
|
|
{
|
3636 |
|
|
tree name = c_parser_peek_token (parser)->value;
|
3637 |
|
|
tree tlab;
|
3638 |
|
|
tree attrs;
|
3639 |
|
|
location_t loc2 = c_parser_peek_token (parser)->location;
|
3640 |
|
|
gcc_assert (c_parser_next_token_is (parser, CPP_NAME));
|
3641 |
|
|
c_parser_consume_token (parser);
|
3642 |
|
|
gcc_assert (c_parser_next_token_is (parser, CPP_COLON));
|
3643 |
|
|
c_parser_consume_token (parser);
|
3644 |
|
|
attrs = c_parser_attributes (parser);
|
3645 |
|
|
tlab = define_label (loc2, name);
|
3646 |
|
|
if (tlab)
|
3647 |
|
|
{
|
3648 |
|
|
decl_attributes (&tlab, attrs, 0);
|
3649 |
|
|
label = add_stmt (build_stmt (loc1, LABEL_EXPR, tlab));
|
3650 |
|
|
}
|
3651 |
|
|
}
|
3652 |
|
|
if (label)
|
3653 |
|
|
{
|
3654 |
|
|
if (c_parser_next_token_starts_declspecs (parser)
|
3655 |
|
|
&& !(c_parser_next_token_is (parser, CPP_NAME)
|
3656 |
|
|
&& c_parser_peek_2nd_token (parser)->type == CPP_COLON))
|
3657 |
|
|
{
|
3658 |
|
|
error_at (c_parser_peek_token (parser)->location,
|
3659 |
|
|
"a label can only be part of a statement and "
|
3660 |
|
|
"a declaration is not a statement");
|
3661 |
|
|
c_parser_declaration_or_fndef (parser, /*fndef_ok*/ false,
|
3662 |
|
|
/*nested*/ true, /*empty_ok*/ false,
|
3663 |
|
|
/*start_attr_ok*/ true);
|
3664 |
|
|
}
|
3665 |
|
|
}
|
3666 |
|
|
}
|
3667 |
|
|
|
3668 |
|
|
/* Parse a statement (C90 6.6, C99 6.8).
|
3669 |
|
|
|
3670 |
|
|
statement:
|
3671 |
|
|
labeled-statement
|
3672 |
|
|
compound-statement
|
3673 |
|
|
expression-statement
|
3674 |
|
|
selection-statement
|
3675 |
|
|
iteration-statement
|
3676 |
|
|
jump-statement
|
3677 |
|
|
|
3678 |
|
|
labeled-statement:
|
3679 |
|
|
label statement
|
3680 |
|
|
|
3681 |
|
|
expression-statement:
|
3682 |
|
|
expression[opt] ;
|
3683 |
|
|
|
3684 |
|
|
selection-statement:
|
3685 |
|
|
if-statement
|
3686 |
|
|
switch-statement
|
3687 |
|
|
|
3688 |
|
|
iteration-statement:
|
3689 |
|
|
while-statement
|
3690 |
|
|
do-statement
|
3691 |
|
|
for-statement
|
3692 |
|
|
|
3693 |
|
|
jump-statement:
|
3694 |
|
|
goto identifier ;
|
3695 |
|
|
continue ;
|
3696 |
|
|
break ;
|
3697 |
|
|
return expression[opt] ;
|
3698 |
|
|
|
3699 |
|
|
GNU extensions:
|
3700 |
|
|
|
3701 |
|
|
statement:
|
3702 |
|
|
asm-statement
|
3703 |
|
|
|
3704 |
|
|
jump-statement:
|
3705 |
|
|
goto * expression ;
|
3706 |
|
|
|
3707 |
|
|
Objective-C:
|
3708 |
|
|
|
3709 |
|
|
statement:
|
3710 |
|
|
objc-throw-statement
|
3711 |
|
|
objc-try-catch-statement
|
3712 |
|
|
objc-synchronized-statement
|
3713 |
|
|
|
3714 |
|
|
objc-throw-statement:
|
3715 |
|
|
@throw expression ;
|
3716 |
|
|
@throw ;
|
3717 |
|
|
|
3718 |
|
|
OpenMP:
|
3719 |
|
|
|
3720 |
|
|
statement:
|
3721 |
|
|
openmp-construct
|
3722 |
|
|
|
3723 |
|
|
openmp-construct:
|
3724 |
|
|
parallel-construct
|
3725 |
|
|
for-construct
|
3726 |
|
|
sections-construct
|
3727 |
|
|
single-construct
|
3728 |
|
|
parallel-for-construct
|
3729 |
|
|
parallel-sections-construct
|
3730 |
|
|
master-construct
|
3731 |
|
|
critical-construct
|
3732 |
|
|
atomic-construct
|
3733 |
|
|
ordered-construct
|
3734 |
|
|
|
3735 |
|
|
parallel-construct:
|
3736 |
|
|
parallel-directive structured-block
|
3737 |
|
|
|
3738 |
|
|
for-construct:
|
3739 |
|
|
for-directive iteration-statement
|
3740 |
|
|
|
3741 |
|
|
sections-construct:
|
3742 |
|
|
sections-directive section-scope
|
3743 |
|
|
|
3744 |
|
|
single-construct:
|
3745 |
|
|
single-directive structured-block
|
3746 |
|
|
|
3747 |
|
|
parallel-for-construct:
|
3748 |
|
|
parallel-for-directive iteration-statement
|
3749 |
|
|
|
3750 |
|
|
parallel-sections-construct:
|
3751 |
|
|
parallel-sections-directive section-scope
|
3752 |
|
|
|
3753 |
|
|
master-construct:
|
3754 |
|
|
master-directive structured-block
|
3755 |
|
|
|
3756 |
|
|
critical-construct:
|
3757 |
|
|
critical-directive structured-block
|
3758 |
|
|
|
3759 |
|
|
atomic-construct:
|
3760 |
|
|
atomic-directive expression-statement
|
3761 |
|
|
|
3762 |
|
|
ordered-construct:
|
3763 |
|
|
ordered-directive structured-block */
|
3764 |
|
|
|
3765 |
|
|
static void
|
3766 |
|
|
c_parser_statement (c_parser *parser)
|
3767 |
|
|
{
|
3768 |
|
|
while (c_parser_next_token_is_keyword (parser, RID_CASE)
|
3769 |
|
|
|| c_parser_next_token_is_keyword (parser, RID_DEFAULT)
|
3770 |
|
|
|| (c_parser_next_token_is (parser, CPP_NAME)
|
3771 |
|
|
&& c_parser_peek_2nd_token (parser)->type == CPP_COLON))
|
3772 |
|
|
c_parser_label (parser);
|
3773 |
|
|
c_parser_statement_after_labels (parser);
|
3774 |
|
|
}
|
3775 |
|
|
|
3776 |
|
|
/* Parse a statement, other than a labeled statement. */
|
3777 |
|
|
|
3778 |
|
|
static void
|
3779 |
|
|
c_parser_statement_after_labels (c_parser *parser)
|
3780 |
|
|
{
|
3781 |
|
|
location_t loc = c_parser_peek_token (parser)->location;
|
3782 |
|
|
tree stmt = NULL_TREE;
|
3783 |
|
|
bool in_if_block = parser->in_if_block;
|
3784 |
|
|
parser->in_if_block = false;
|
3785 |
|
|
switch (c_parser_peek_token (parser)->type)
|
3786 |
|
|
{
|
3787 |
|
|
case CPP_OPEN_BRACE:
|
3788 |
|
|
add_stmt (c_parser_compound_statement (parser));
|
3789 |
|
|
break;
|
3790 |
|
|
case CPP_KEYWORD:
|
3791 |
|
|
switch (c_parser_peek_token (parser)->keyword)
|
3792 |
|
|
{
|
3793 |
|
|
case RID_IF:
|
3794 |
|
|
c_parser_if_statement (parser);
|
3795 |
|
|
break;
|
3796 |
|
|
case RID_SWITCH:
|
3797 |
|
|
c_parser_switch_statement (parser);
|
3798 |
|
|
break;
|
3799 |
|
|
case RID_WHILE:
|
3800 |
|
|
c_parser_while_statement (parser);
|
3801 |
|
|
break;
|
3802 |
|
|
case RID_DO:
|
3803 |
|
|
c_parser_do_statement (parser);
|
3804 |
|
|
break;
|
3805 |
|
|
case RID_FOR:
|
3806 |
|
|
c_parser_for_statement (parser);
|
3807 |
|
|
break;
|
3808 |
|
|
case RID_GOTO:
|
3809 |
|
|
c_parser_consume_token (parser);
|
3810 |
|
|
if (c_parser_next_token_is (parser, CPP_NAME))
|
3811 |
|
|
{
|
3812 |
|
|
stmt = c_finish_goto_label (loc,
|
3813 |
|
|
c_parser_peek_token (parser)->value);
|
3814 |
|
|
c_parser_consume_token (parser);
|
3815 |
|
|
}
|
3816 |
|
|
else if (c_parser_next_token_is (parser, CPP_MULT))
|
3817 |
|
|
{
|
3818 |
|
|
c_parser_consume_token (parser);
|
3819 |
|
|
stmt = c_finish_goto_ptr (loc,
|
3820 |
|
|
c_parser_expression (parser).value);
|
3821 |
|
|
}
|
3822 |
|
|
else
|
3823 |
|
|
c_parser_error (parser, "expected identifier or %<*%>");
|
3824 |
|
|
goto expect_semicolon;
|
3825 |
|
|
case RID_CONTINUE:
|
3826 |
|
|
c_parser_consume_token (parser);
|
3827 |
|
|
stmt = c_finish_bc_stmt (loc, &c_cont_label, false);
|
3828 |
|
|
goto expect_semicolon;
|
3829 |
|
|
case RID_BREAK:
|
3830 |
|
|
c_parser_consume_token (parser);
|
3831 |
|
|
stmt = c_finish_bc_stmt (loc, &c_break_label, true);
|
3832 |
|
|
goto expect_semicolon;
|
3833 |
|
|
case RID_RETURN:
|
3834 |
|
|
c_parser_consume_token (parser);
|
3835 |
|
|
if (c_parser_next_token_is (parser, CPP_SEMICOLON))
|
3836 |
|
|
{
|
3837 |
|
|
stmt = c_finish_return (loc, NULL_TREE, NULL_TREE);
|
3838 |
|
|
c_parser_consume_token (parser);
|
3839 |
|
|
}
|
3840 |
|
|
else
|
3841 |
|
|
{
|
3842 |
|
|
struct c_expr expr = c_parser_expression_conv (parser);
|
3843 |
|
|
stmt = c_finish_return (loc, expr.value, expr.original_type);
|
3844 |
|
|
goto expect_semicolon;
|
3845 |
|
|
}
|
3846 |
|
|
break;
|
3847 |
|
|
case RID_ASM:
|
3848 |
|
|
stmt = c_parser_asm_statement (parser);
|
3849 |
|
|
break;
|
3850 |
|
|
case RID_THROW:
|
3851 |
|
|
gcc_assert (c_dialect_objc ());
|
3852 |
|
|
c_parser_consume_token (parser);
|
3853 |
|
|
if (c_parser_next_token_is (parser, CPP_SEMICOLON))
|
3854 |
|
|
{
|
3855 |
|
|
stmt = objc_build_throw_stmt (loc, NULL_TREE);
|
3856 |
|
|
c_parser_consume_token (parser);
|
3857 |
|
|
}
|
3858 |
|
|
else
|
3859 |
|
|
{
|
3860 |
|
|
tree expr = c_parser_expression (parser).value;
|
3861 |
|
|
expr = c_fully_fold (expr, false, NULL);
|
3862 |
|
|
stmt = objc_build_throw_stmt (loc, expr);
|
3863 |
|
|
goto expect_semicolon;
|
3864 |
|
|
}
|
3865 |
|
|
break;
|
3866 |
|
|
case RID_TRY:
|
3867 |
|
|
gcc_assert (c_dialect_objc ());
|
3868 |
|
|
c_parser_objc_try_catch_statement (parser);
|
3869 |
|
|
break;
|
3870 |
|
|
case RID_AT_SYNCHRONIZED:
|
3871 |
|
|
gcc_assert (c_dialect_objc ());
|
3872 |
|
|
c_parser_objc_synchronized_statement (parser);
|
3873 |
|
|
break;
|
3874 |
|
|
default:
|
3875 |
|
|
goto expr_stmt;
|
3876 |
|
|
}
|
3877 |
|
|
break;
|
3878 |
|
|
case CPP_SEMICOLON:
|
3879 |
|
|
c_parser_consume_token (parser);
|
3880 |
|
|
break;
|
3881 |
|
|
case CPP_CLOSE_PAREN:
|
3882 |
|
|
case CPP_CLOSE_SQUARE:
|
3883 |
|
|
/* Avoid infinite loop in error recovery:
|
3884 |
|
|
c_parser_skip_until_found stops at a closing nesting
|
3885 |
|
|
delimiter without consuming it, but here we need to consume
|
3886 |
|
|
it to proceed further. */
|
3887 |
|
|
c_parser_error (parser, "expected statement");
|
3888 |
|
|
c_parser_consume_token (parser);
|
3889 |
|
|
break;
|
3890 |
|
|
case CPP_PRAGMA:
|
3891 |
|
|
c_parser_pragma (parser, pragma_stmt);
|
3892 |
|
|
break;
|
3893 |
|
|
default:
|
3894 |
|
|
expr_stmt:
|
3895 |
|
|
stmt = c_finish_expr_stmt (loc, c_parser_expression_conv (parser).value);
|
3896 |
|
|
expect_semicolon:
|
3897 |
|
|
c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
|
3898 |
|
|
break;
|
3899 |
|
|
}
|
3900 |
|
|
/* Two cases cannot and do not have line numbers associated: If stmt
|
3901 |
|
|
is degenerate, such as "2;", then stmt is an INTEGER_CST, which
|
3902 |
|
|
cannot hold line numbers. But that's OK because the statement
|
3903 |
|
|
will either be changed to a MODIFY_EXPR during gimplification of
|
3904 |
|
|
the statement expr, or discarded. If stmt was compound, but
|
3905 |
|
|
without new variables, we will have skipped the creation of a
|
3906 |
|
|
BIND and will have a bare STATEMENT_LIST. But that's OK because
|
3907 |
|
|
(recursively) all of the component statements should already have
|
3908 |
|
|
line numbers assigned. ??? Can we discard no-op statements
|
3909 |
|
|
earlier? */
|
3910 |
|
|
if (CAN_HAVE_LOCATION_P (stmt)
|
3911 |
|
|
&& EXPR_LOCATION (stmt) == UNKNOWN_LOCATION)
|
3912 |
|
|
SET_EXPR_LOCATION (stmt, loc);
|
3913 |
|
|
|
3914 |
|
|
parser->in_if_block = in_if_block;
|
3915 |
|
|
}
|
3916 |
|
|
|
3917 |
|
|
/* Parse the condition from an if, do, while or for statements. */
|
3918 |
|
|
|
3919 |
|
|
static tree
|
3920 |
|
|
c_parser_condition (c_parser *parser)
|
3921 |
|
|
{
|
3922 |
|
|
location_t loc = c_parser_peek_token (parser)->location;
|
3923 |
|
|
tree cond;
|
3924 |
|
|
cond = c_parser_expression_conv (parser).value;
|
3925 |
|
|
cond = c_objc_common_truthvalue_conversion (loc, cond);
|
3926 |
|
|
cond = c_fully_fold (cond, false, NULL);
|
3927 |
|
|
if (warn_sequence_point)
|
3928 |
|
|
verify_sequence_points (cond);
|
3929 |
|
|
return cond;
|
3930 |
|
|
}
|
3931 |
|
|
|
3932 |
|
|
/* Parse a parenthesized condition from an if, do or while statement.
|
3933 |
|
|
|
3934 |
|
|
condition:
|
3935 |
|
|
( expression )
|
3936 |
|
|
*/
|
3937 |
|
|
static tree
|
3938 |
|
|
c_parser_paren_condition (c_parser *parser)
|
3939 |
|
|
{
|
3940 |
|
|
tree cond;
|
3941 |
|
|
if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
|
3942 |
|
|
return error_mark_node;
|
3943 |
|
|
cond = c_parser_condition (parser);
|
3944 |
|
|
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
|
3945 |
|
|
return cond;
|
3946 |
|
|
}
|
3947 |
|
|
|
3948 |
|
|
/* Parse a statement which is a block in C99. */
|
3949 |
|
|
|
3950 |
|
|
static tree
|
3951 |
|
|
c_parser_c99_block_statement (c_parser *parser)
|
3952 |
|
|
{
|
3953 |
|
|
tree block = c_begin_compound_stmt (flag_isoc99);
|
3954 |
|
|
location_t loc = c_parser_peek_token (parser)->location;
|
3955 |
|
|
c_parser_statement (parser);
|
3956 |
|
|
return c_end_compound_stmt (loc, block, flag_isoc99);
|
3957 |
|
|
}
|
3958 |
|
|
|
3959 |
|
|
/* Parse the body of an if statement. This is just parsing a
|
3960 |
|
|
statement but (a) it is a block in C99, (b) we track whether the
|
3961 |
|
|
body is an if statement for the sake of -Wparentheses warnings, (c)
|
3962 |
|
|
we handle an empty body specially for the sake of -Wempty-body
|
3963 |
|
|
warnings, and (d) we call parser_compound_statement directly
|
3964 |
|
|
because c_parser_statement_after_labels resets
|
3965 |
|
|
parser->in_if_block. */
|
3966 |
|
|
|
3967 |
|
|
static tree
|
3968 |
|
|
c_parser_if_body (c_parser *parser, bool *if_p)
|
3969 |
|
|
{
|
3970 |
|
|
tree block = c_begin_compound_stmt (flag_isoc99);
|
3971 |
|
|
location_t body_loc = c_parser_peek_token (parser)->location;
|
3972 |
|
|
while (c_parser_next_token_is_keyword (parser, RID_CASE)
|
3973 |
|
|
|| c_parser_next_token_is_keyword (parser, RID_DEFAULT)
|
3974 |
|
|
|| (c_parser_next_token_is (parser, CPP_NAME)
|
3975 |
|
|
&& c_parser_peek_2nd_token (parser)->type == CPP_COLON))
|
3976 |
|
|
c_parser_label (parser);
|
3977 |
|
|
*if_p = c_parser_next_token_is_keyword (parser, RID_IF);
|
3978 |
|
|
if (c_parser_next_token_is (parser, CPP_SEMICOLON))
|
3979 |
|
|
{
|
3980 |
|
|
location_t loc = c_parser_peek_token (parser)->location;
|
3981 |
|
|
add_stmt (build_empty_stmt (loc));
|
3982 |
|
|
c_parser_consume_token (parser);
|
3983 |
|
|
if (!c_parser_next_token_is_keyword (parser, RID_ELSE))
|
3984 |
|
|
warning_at (loc, OPT_Wempty_body,
|
3985 |
|
|
"suggest braces around empty body in an %<if%> statement");
|
3986 |
|
|
}
|
3987 |
|
|
else if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
|
3988 |
|
|
add_stmt (c_parser_compound_statement (parser));
|
3989 |
|
|
else
|
3990 |
|
|
c_parser_statement_after_labels (parser);
|
3991 |
|
|
return c_end_compound_stmt (body_loc, block, flag_isoc99);
|
3992 |
|
|
}
|
3993 |
|
|
|
3994 |
|
|
/* Parse the else body of an if statement. This is just parsing a
|
3995 |
|
|
statement but (a) it is a block in C99, (b) we handle an empty body
|
3996 |
|
|
specially for the sake of -Wempty-body warnings. */
|
3997 |
|
|
|
3998 |
|
|
static tree
|
3999 |
|
|
c_parser_else_body (c_parser *parser)
|
4000 |
|
|
{
|
4001 |
|
|
location_t else_loc = c_parser_peek_token (parser)->location;
|
4002 |
|
|
tree block = c_begin_compound_stmt (flag_isoc99);
|
4003 |
|
|
while (c_parser_next_token_is_keyword (parser, RID_CASE)
|
4004 |
|
|
|| c_parser_next_token_is_keyword (parser, RID_DEFAULT)
|
4005 |
|
|
|| (c_parser_next_token_is (parser, CPP_NAME)
|
4006 |
|
|
&& c_parser_peek_2nd_token (parser)->type == CPP_COLON))
|
4007 |
|
|
c_parser_label (parser);
|
4008 |
|
|
if (c_parser_next_token_is (parser, CPP_SEMICOLON))
|
4009 |
|
|
{
|
4010 |
|
|
location_t loc = c_parser_peek_token (parser)->location;
|
4011 |
|
|
warning_at (loc,
|
4012 |
|
|
OPT_Wempty_body,
|
4013 |
|
|
"suggest braces around empty body in an %<else%> statement");
|
4014 |
|
|
add_stmt (build_empty_stmt (loc));
|
4015 |
|
|
c_parser_consume_token (parser);
|
4016 |
|
|
}
|
4017 |
|
|
else
|
4018 |
|
|
c_parser_statement_after_labels (parser);
|
4019 |
|
|
return c_end_compound_stmt (else_loc, block, flag_isoc99);
|
4020 |
|
|
}
|
4021 |
|
|
|
4022 |
|
|
/* Parse an if statement (C90 6.6.4, C99 6.8.4).
|
4023 |
|
|
|
4024 |
|
|
if-statement:
|
4025 |
|
|
if ( expression ) statement
|
4026 |
|
|
if ( expression ) statement else statement
|
4027 |
|
|
*/
|
4028 |
|
|
|
4029 |
|
|
static void
|
4030 |
|
|
c_parser_if_statement (c_parser *parser)
|
4031 |
|
|
{
|
4032 |
|
|
tree block;
|
4033 |
|
|
location_t loc;
|
4034 |
|
|
tree cond;
|
4035 |
|
|
bool first_if = false;
|
4036 |
|
|
tree first_body, second_body;
|
4037 |
|
|
bool in_if_block;
|
4038 |
|
|
|
4039 |
|
|
gcc_assert (c_parser_next_token_is_keyword (parser, RID_IF));
|
4040 |
|
|
c_parser_consume_token (parser);
|
4041 |
|
|
block = c_begin_compound_stmt (flag_isoc99);
|
4042 |
|
|
loc = c_parser_peek_token (parser)->location;
|
4043 |
|
|
cond = c_parser_paren_condition (parser);
|
4044 |
|
|
in_if_block = parser->in_if_block;
|
4045 |
|
|
parser->in_if_block = true;
|
4046 |
|
|
first_body = c_parser_if_body (parser, &first_if);
|
4047 |
|
|
parser->in_if_block = in_if_block;
|
4048 |
|
|
if (c_parser_next_token_is_keyword (parser, RID_ELSE))
|
4049 |
|
|
{
|
4050 |
|
|
c_parser_consume_token (parser);
|
4051 |
|
|
second_body = c_parser_else_body (parser);
|
4052 |
|
|
}
|
4053 |
|
|
else
|
4054 |
|
|
second_body = NULL_TREE;
|
4055 |
|
|
c_finish_if_stmt (loc, cond, first_body, second_body, first_if);
|
4056 |
|
|
add_stmt (c_end_compound_stmt (loc, block, flag_isoc99));
|
4057 |
|
|
}
|
4058 |
|
|
|
4059 |
|
|
/* Parse a switch statement (C90 6.6.4, C99 6.8.4).
|
4060 |
|
|
|
4061 |
|
|
switch-statement:
|
4062 |
|
|
switch (expression) statement
|
4063 |
|
|
*/
|
4064 |
|
|
|
4065 |
|
|
static void
|
4066 |
|
|
c_parser_switch_statement (c_parser *parser)
|
4067 |
|
|
{
|
4068 |
|
|
tree block, expr, body, save_break;
|
4069 |
|
|
location_t switch_loc = c_parser_peek_token (parser)->location;
|
4070 |
|
|
location_t switch_cond_loc;
|
4071 |
|
|
gcc_assert (c_parser_next_token_is_keyword (parser, RID_SWITCH));
|
4072 |
|
|
c_parser_consume_token (parser);
|
4073 |
|
|
block = c_begin_compound_stmt (flag_isoc99);
|
4074 |
|
|
if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
|
4075 |
|
|
{
|
4076 |
|
|
switch_cond_loc = c_parser_peek_token (parser)->location;
|
4077 |
|
|
expr = c_parser_expression (parser).value;
|
4078 |
|
|
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
|
4079 |
|
|
}
|
4080 |
|
|
else
|
4081 |
|
|
{
|
4082 |
|
|
switch_cond_loc = UNKNOWN_LOCATION;
|
4083 |
|
|
expr = error_mark_node;
|
4084 |
|
|
}
|
4085 |
|
|
c_start_case (switch_loc, switch_cond_loc, expr);
|
4086 |
|
|
save_break = c_break_label;
|
4087 |
|
|
c_break_label = NULL_TREE;
|
4088 |
|
|
body = c_parser_c99_block_statement (parser);
|
4089 |
|
|
c_finish_case (body);
|
4090 |
|
|
if (c_break_label)
|
4091 |
|
|
{
|
4092 |
|
|
location_t here = c_parser_peek_token (parser)->location;
|
4093 |
|
|
tree t = build1 (LABEL_EXPR, void_type_node, c_break_label);
|
4094 |
|
|
SET_EXPR_LOCATION (t, here);
|
4095 |
|
|
add_stmt (t);
|
4096 |
|
|
}
|
4097 |
|
|
c_break_label = save_break;
|
4098 |
|
|
add_stmt (c_end_compound_stmt (switch_loc, block, flag_isoc99));
|
4099 |
|
|
}
|
4100 |
|
|
|
4101 |
|
|
/* Parse a while statement (C90 6.6.5, C99 6.8.5).
|
4102 |
|
|
|
4103 |
|
|
while-statement:
|
4104 |
|
|
while (expression) statement
|
4105 |
|
|
*/
|
4106 |
|
|
|
4107 |
|
|
static void
|
4108 |
|
|
c_parser_while_statement (c_parser *parser)
|
4109 |
|
|
{
|
4110 |
|
|
tree block, cond, body, save_break, save_cont;
|
4111 |
|
|
location_t loc;
|
4112 |
|
|
gcc_assert (c_parser_next_token_is_keyword (parser, RID_WHILE));
|
4113 |
|
|
c_parser_consume_token (parser);
|
4114 |
|
|
block = c_begin_compound_stmt (flag_isoc99);
|
4115 |
|
|
loc = c_parser_peek_token (parser)->location;
|
4116 |
|
|
cond = c_parser_paren_condition (parser);
|
4117 |
|
|
save_break = c_break_label;
|
4118 |
|
|
c_break_label = NULL_TREE;
|
4119 |
|
|
save_cont = c_cont_label;
|
4120 |
|
|
c_cont_label = NULL_TREE;
|
4121 |
|
|
body = c_parser_c99_block_statement (parser);
|
4122 |
|
|
c_finish_loop (loc, cond, NULL, body, c_break_label, c_cont_label, true);
|
4123 |
|
|
add_stmt (c_end_compound_stmt (loc, block, flag_isoc99));
|
4124 |
|
|
c_break_label = save_break;
|
4125 |
|
|
c_cont_label = save_cont;
|
4126 |
|
|
}
|
4127 |
|
|
|
4128 |
|
|
/* Parse a do statement (C90 6.6.5, C99 6.8.5).
|
4129 |
|
|
|
4130 |
|
|
do-statement:
|
4131 |
|
|
do statement while ( expression ) ;
|
4132 |
|
|
*/
|
4133 |
|
|
|
4134 |
|
|
static void
|
4135 |
|
|
c_parser_do_statement (c_parser *parser)
|
4136 |
|
|
{
|
4137 |
|
|
tree block, cond, body, save_break, save_cont, new_break, new_cont;
|
4138 |
|
|
location_t loc;
|
4139 |
|
|
gcc_assert (c_parser_next_token_is_keyword (parser, RID_DO));
|
4140 |
|
|
c_parser_consume_token (parser);
|
4141 |
|
|
if (c_parser_next_token_is (parser, CPP_SEMICOLON))
|
4142 |
|
|
warning_at (c_parser_peek_token (parser)->location,
|
4143 |
|
|
OPT_Wempty_body,
|
4144 |
|
|
"suggest braces around empty body in %<do%> statement");
|
4145 |
|
|
block = c_begin_compound_stmt (flag_isoc99);
|
4146 |
|
|
loc = c_parser_peek_token (parser)->location;
|
4147 |
|
|
save_break = c_break_label;
|
4148 |
|
|
c_break_label = NULL_TREE;
|
4149 |
|
|
save_cont = c_cont_label;
|
4150 |
|
|
c_cont_label = NULL_TREE;
|
4151 |
|
|
body = c_parser_c99_block_statement (parser);
|
4152 |
|
|
c_parser_require_keyword (parser, RID_WHILE, "expected %<while%>");
|
4153 |
|
|
new_break = c_break_label;
|
4154 |
|
|
c_break_label = save_break;
|
4155 |
|
|
new_cont = c_cont_label;
|
4156 |
|
|
c_cont_label = save_cont;
|
4157 |
|
|
cond = c_parser_paren_condition (parser);
|
4158 |
|
|
if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
|
4159 |
|
|
c_parser_skip_to_end_of_block_or_statement (parser);
|
4160 |
|
|
c_finish_loop (loc, cond, NULL, body, new_break, new_cont, false);
|
4161 |
|
|
add_stmt (c_end_compound_stmt (loc, block, flag_isoc99));
|
4162 |
|
|
}
|
4163 |
|
|
|
4164 |
|
|
/* Parse a for statement (C90 6.6.5, C99 6.8.5).
|
4165 |
|
|
|
4166 |
|
|
for-statement:
|
4167 |
|
|
for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
|
4168 |
|
|
for ( nested-declaration expression[opt] ; expression[opt] ) statement
|
4169 |
|
|
|
4170 |
|
|
The form with a declaration is new in C99.
|
4171 |
|
|
|
4172 |
|
|
??? In accordance with the old parser, the declaration may be a
|
4173 |
|
|
nested function, which is then rejected in check_for_loop_decls,
|
4174 |
|
|
but does it make any sense for this to be included in the grammar?
|
4175 |
|
|
Note in particular that the nested function does not include a
|
4176 |
|
|
trailing ';', whereas the "declaration" production includes one.
|
4177 |
|
|
Also, can we reject bad declarations earlier and cheaper than
|
4178 |
|
|
check_for_loop_decls? */
|
4179 |
|
|
|
4180 |
|
|
static void
|
4181 |
|
|
c_parser_for_statement (c_parser *parser)
|
4182 |
|
|
{
|
4183 |
|
|
tree block, cond, incr, save_break, save_cont, body;
|
4184 |
|
|
location_t loc = c_parser_peek_token (parser)->location;
|
4185 |
|
|
location_t for_loc = c_parser_peek_token (parser)->location;
|
4186 |
|
|
gcc_assert (c_parser_next_token_is_keyword (parser, RID_FOR));
|
4187 |
|
|
c_parser_consume_token (parser);
|
4188 |
|
|
block = c_begin_compound_stmt (flag_isoc99);
|
4189 |
|
|
if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
|
4190 |
|
|
{
|
4191 |
|
|
/* Parse the initialization declaration or expression. */
|
4192 |
|
|
if (c_parser_next_token_is (parser, CPP_SEMICOLON))
|
4193 |
|
|
{
|
4194 |
|
|
c_parser_consume_token (parser);
|
4195 |
|
|
c_finish_expr_stmt (loc, NULL_TREE);
|
4196 |
|
|
}
|
4197 |
|
|
else if (c_parser_next_token_starts_declspecs (parser))
|
4198 |
|
|
{
|
4199 |
|
|
c_parser_declaration_or_fndef (parser, true, true, true, true);
|
4200 |
|
|
check_for_loop_decls (for_loc);
|
4201 |
|
|
}
|
4202 |
|
|
else if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
|
4203 |
|
|
{
|
4204 |
|
|
/* __extension__ can start a declaration, but is also an
|
4205 |
|
|
unary operator that can start an expression. Consume all
|
4206 |
|
|
but the last of a possible series of __extension__ to
|
4207 |
|
|
determine which. */
|
4208 |
|
|
while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD
|
4209 |
|
|
&& (c_parser_peek_2nd_token (parser)->keyword
|
4210 |
|
|
== RID_EXTENSION))
|
4211 |
|
|
c_parser_consume_token (parser);
|
4212 |
|
|
if (c_token_starts_declspecs (c_parser_peek_2nd_token (parser)))
|
4213 |
|
|
{
|
4214 |
|
|
int ext;
|
4215 |
|
|
ext = disable_extension_diagnostics ();
|
4216 |
|
|
c_parser_consume_token (parser);
|
4217 |
|
|
c_parser_declaration_or_fndef (parser, true, true, true, true);
|
4218 |
|
|
restore_extension_diagnostics (ext);
|
4219 |
|
|
check_for_loop_decls (for_loc);
|
4220 |
|
|
}
|
4221 |
|
|
else
|
4222 |
|
|
goto init_expr;
|
4223 |
|
|
}
|
4224 |
|
|
else
|
4225 |
|
|
{
|
4226 |
|
|
init_expr:
|
4227 |
|
|
c_finish_expr_stmt (loc, c_parser_expression (parser).value);
|
4228 |
|
|
c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
|
4229 |
|
|
}
|
4230 |
|
|
/* Parse the loop condition. */
|
4231 |
|
|
if (c_parser_next_token_is (parser, CPP_SEMICOLON))
|
4232 |
|
|
{
|
4233 |
|
|
c_parser_consume_token (parser);
|
4234 |
|
|
cond = NULL_TREE;
|
4235 |
|
|
}
|
4236 |
|
|
else
|
4237 |
|
|
{
|
4238 |
|
|
cond = c_parser_condition (parser);
|
4239 |
|
|
c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
|
4240 |
|
|
}
|
4241 |
|
|
/* Parse the increment expression. */
|
4242 |
|
|
if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
|
4243 |
|
|
incr = c_process_expr_stmt (loc, NULL_TREE);
|
4244 |
|
|
else
|
4245 |
|
|
incr = c_process_expr_stmt (loc, c_parser_expression (parser).value);
|
4246 |
|
|
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
|
4247 |
|
|
}
|
4248 |
|
|
else
|
4249 |
|
|
{
|
4250 |
|
|
cond = error_mark_node;
|
4251 |
|
|
incr = error_mark_node;
|
4252 |
|
|
}
|
4253 |
|
|
save_break = c_break_label;
|
4254 |
|
|
c_break_label = NULL_TREE;
|
4255 |
|
|
save_cont = c_cont_label;
|
4256 |
|
|
c_cont_label = NULL_TREE;
|
4257 |
|
|
body = c_parser_c99_block_statement (parser);
|
4258 |
|
|
c_finish_loop (loc, cond, incr, body, c_break_label, c_cont_label, true);
|
4259 |
|
|
add_stmt (c_end_compound_stmt (loc, block, flag_isoc99));
|
4260 |
|
|
c_break_label = save_break;
|
4261 |
|
|
c_cont_label = save_cont;
|
4262 |
|
|
}
|
4263 |
|
|
|
4264 |
|
|
/* Parse an asm statement, a GNU extension. This is a full-blown asm
|
4265 |
|
|
statement with inputs, outputs, clobbers, and volatile tag
|
4266 |
|
|
allowed.
|
4267 |
|
|
|
4268 |
|
|
asm-statement:
|
4269 |
|
|
asm type-qualifier[opt] ( asm-argument ) ;
|
4270 |
|
|
asm type-qualifier[opt] goto ( asm-goto-argument ) ;
|
4271 |
|
|
|
4272 |
|
|
asm-argument:
|
4273 |
|
|
asm-string-literal
|
4274 |
|
|
asm-string-literal : asm-operands[opt]
|
4275 |
|
|
asm-string-literal : asm-operands[opt] : asm-operands[opt]
|
4276 |
|
|
asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers[opt]
|
4277 |
|
|
|
4278 |
|
|
asm-goto-argument:
|
4279 |
|
|
asm-string-literal : : asm-operands[opt] : asm-clobbers[opt] \
|
4280 |
|
|
: asm-goto-operands
|
4281 |
|
|
|
4282 |
|
|
Qualifiers other than volatile are accepted in the syntax but
|
4283 |
|
|
warned for. */
|
4284 |
|
|
|
4285 |
|
|
static tree
|
4286 |
|
|
c_parser_asm_statement (c_parser *parser)
|
4287 |
|
|
{
|
4288 |
|
|
tree quals, str, outputs, inputs, clobbers, labels, ret;
|
4289 |
|
|
bool simple, is_goto;
|
4290 |
|
|
location_t asm_loc = c_parser_peek_token (parser)->location;
|
4291 |
|
|
int section, nsections;
|
4292 |
|
|
|
4293 |
|
|
gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
|
4294 |
|
|
c_parser_consume_token (parser);
|
4295 |
|
|
if (c_parser_next_token_is_keyword (parser, RID_VOLATILE))
|
4296 |
|
|
{
|
4297 |
|
|
quals = c_parser_peek_token (parser)->value;
|
4298 |
|
|
c_parser_consume_token (parser);
|
4299 |
|
|
}
|
4300 |
|
|
else if (c_parser_next_token_is_keyword (parser, RID_CONST)
|
4301 |
|
|
|| c_parser_next_token_is_keyword (parser, RID_RESTRICT))
|
4302 |
|
|
{
|
4303 |
|
|
warning_at (c_parser_peek_token (parser)->location,
|
4304 |
|
|
0,
|
4305 |
|
|
"%E qualifier ignored on asm",
|
4306 |
|
|
c_parser_peek_token (parser)->value);
|
4307 |
|
|
quals = NULL_TREE;
|
4308 |
|
|
c_parser_consume_token (parser);
|
4309 |
|
|
}
|
4310 |
|
|
else
|
4311 |
|
|
quals = NULL_TREE;
|
4312 |
|
|
|
4313 |
|
|
is_goto = false;
|
4314 |
|
|
if (c_parser_next_token_is_keyword (parser, RID_GOTO))
|
4315 |
|
|
{
|
4316 |
|
|
c_parser_consume_token (parser);
|
4317 |
|
|
is_goto = true;
|
4318 |
|
|
}
|
4319 |
|
|
|
4320 |
|
|
/* ??? Follow the C++ parser rather than using the
|
4321 |
|
|
lex_untranslated_string kludge. */
|
4322 |
|
|
parser->lex_untranslated_string = true;
|
4323 |
|
|
ret = NULL;
|
4324 |
|
|
|
4325 |
|
|
if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
|
4326 |
|
|
goto error;
|
4327 |
|
|
|
4328 |
|
|
str = c_parser_asm_string_literal (parser);
|
4329 |
|
|
if (str == NULL_TREE)
|
4330 |
|
|
goto error_close_paren;
|
4331 |
|
|
|
4332 |
|
|
simple = true;
|
4333 |
|
|
outputs = NULL_TREE;
|
4334 |
|
|
inputs = NULL_TREE;
|
4335 |
|
|
clobbers = NULL_TREE;
|
4336 |
|
|
labels = NULL_TREE;
|
4337 |
|
|
|
4338 |
|
|
if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN) && !is_goto)
|
4339 |
|
|
goto done_asm;
|
4340 |
|
|
|
4341 |
|
|
/* Parse each colon-delimited section of operands. */
|
4342 |
|
|
nsections = 3 + is_goto;
|
4343 |
|
|
for (section = 0; section < nsections; ++section)
|
4344 |
|
|
{
|
4345 |
|
|
if (!c_parser_require (parser, CPP_COLON,
|
4346 |
|
|
is_goto
|
4347 |
|
|
? "expected %<:%>"
|
4348 |
|
|
: "expected %<:%> or %<)%>"))
|
4349 |
|
|
goto error_close_paren;
|
4350 |
|
|
|
4351 |
|
|
/* Once past any colon, we're no longer a simple asm. */
|
4352 |
|
|
simple = false;
|
4353 |
|
|
|
4354 |
|
|
if ((!c_parser_next_token_is (parser, CPP_COLON)
|
4355 |
|
|
&& !c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
|
4356 |
|
|
|| section == 3)
|
4357 |
|
|
switch (section)
|
4358 |
|
|
{
|
4359 |
|
|
case 0:
|
4360 |
|
|
/* For asm goto, we don't allow output operands, but reserve
|
4361 |
|
|
the slot for a future extension that does allow them. */
|
4362 |
|
|
if (!is_goto)
|
4363 |
|
|
outputs = c_parser_asm_operands (parser, false);
|
4364 |
|
|
break;
|
4365 |
|
|
case 1:
|
4366 |
|
|
inputs = c_parser_asm_operands (parser, true);
|
4367 |
|
|
break;
|
4368 |
|
|
case 2:
|
4369 |
|
|
clobbers = c_parser_asm_clobbers (parser);
|
4370 |
|
|
break;
|
4371 |
|
|
case 3:
|
4372 |
|
|
labels = c_parser_asm_goto_operands (parser);
|
4373 |
|
|
break;
|
4374 |
|
|
default:
|
4375 |
|
|
gcc_unreachable ();
|
4376 |
|
|
}
|
4377 |
|
|
|
4378 |
|
|
if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN) && !is_goto)
|
4379 |
|
|
goto done_asm;
|
4380 |
|
|
}
|
4381 |
|
|
|
4382 |
|
|
done_asm:
|
4383 |
|
|
if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
|
4384 |
|
|
{
|
4385 |
|
|
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
|
4386 |
|
|
goto error;
|
4387 |
|
|
}
|
4388 |
|
|
|
4389 |
|
|
if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
|
4390 |
|
|
c_parser_skip_to_end_of_block_or_statement (parser);
|
4391 |
|
|
|
4392 |
|
|
ret = build_asm_stmt (quals, build_asm_expr (asm_loc, str, outputs, inputs,
|
4393 |
|
|
clobbers, labels, simple));
|
4394 |
|
|
|
4395 |
|
|
error:
|
4396 |
|
|
parser->lex_untranslated_string = false;
|
4397 |
|
|
return ret;
|
4398 |
|
|
|
4399 |
|
|
error_close_paren:
|
4400 |
|
|
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
|
4401 |
|
|
goto error;
|
4402 |
|
|
}
|
4403 |
|
|
|
4404 |
|
|
/* Parse asm operands, a GNU extension. If CONVERT_P (for inputs but
|
4405 |
|
|
not outputs), apply the default conversion of functions and arrays
|
4406 |
|
|
to pointers.
|
4407 |
|
|
|
4408 |
|
|
asm-operands:
|
4409 |
|
|
asm-operand
|
4410 |
|
|
asm-operands , asm-operand
|
4411 |
|
|
|
4412 |
|
|
asm-operand:
|
4413 |
|
|
asm-string-literal ( expression )
|
4414 |
|
|
[ identifier ] asm-string-literal ( expression )
|
4415 |
|
|
*/
|
4416 |
|
|
|
4417 |
|
|
static tree
|
4418 |
|
|
c_parser_asm_operands (c_parser *parser, bool convert_p)
|
4419 |
|
|
{
|
4420 |
|
|
tree list = NULL_TREE;
|
4421 |
|
|
location_t loc;
|
4422 |
|
|
while (true)
|
4423 |
|
|
{
|
4424 |
|
|
tree name, str;
|
4425 |
|
|
struct c_expr expr;
|
4426 |
|
|
if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
|
4427 |
|
|
{
|
4428 |
|
|
c_parser_consume_token (parser);
|
4429 |
|
|
if (c_parser_next_token_is (parser, CPP_NAME))
|
4430 |
|
|
{
|
4431 |
|
|
tree id = c_parser_peek_token (parser)->value;
|
4432 |
|
|
c_parser_consume_token (parser);
|
4433 |
|
|
name = build_string (IDENTIFIER_LENGTH (id),
|
4434 |
|
|
IDENTIFIER_POINTER (id));
|
4435 |
|
|
}
|
4436 |
|
|
else
|
4437 |
|
|
{
|
4438 |
|
|
c_parser_error (parser, "expected identifier");
|
4439 |
|
|
c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
|
4440 |
|
|
return NULL_TREE;
|
4441 |
|
|
}
|
4442 |
|
|
c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
|
4443 |
|
|
"expected %<]%>");
|
4444 |
|
|
}
|
4445 |
|
|
else
|
4446 |
|
|
name = NULL_TREE;
|
4447 |
|
|
str = c_parser_asm_string_literal (parser);
|
4448 |
|
|
if (str == NULL_TREE)
|
4449 |
|
|
return NULL_TREE;
|
4450 |
|
|
parser->lex_untranslated_string = false;
|
4451 |
|
|
if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
|
4452 |
|
|
{
|
4453 |
|
|
parser->lex_untranslated_string = true;
|
4454 |
|
|
return NULL_TREE;
|
4455 |
|
|
}
|
4456 |
|
|
loc = c_parser_peek_token (parser)->location;
|
4457 |
|
|
expr = c_parser_expression (parser);
|
4458 |
|
|
if (convert_p)
|
4459 |
|
|
expr = default_function_array_conversion (loc, expr);
|
4460 |
|
|
expr.value = c_fully_fold (expr.value, false, NULL);
|
4461 |
|
|
parser->lex_untranslated_string = true;
|
4462 |
|
|
if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
|
4463 |
|
|
{
|
4464 |
|
|
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
|
4465 |
|
|
return NULL_TREE;
|
4466 |
|
|
}
|
4467 |
|
|
list = chainon (list, build_tree_list (build_tree_list (name, str),
|
4468 |
|
|
expr.value));
|
4469 |
|
|
if (c_parser_next_token_is (parser, CPP_COMMA))
|
4470 |
|
|
c_parser_consume_token (parser);
|
4471 |
|
|
else
|
4472 |
|
|
break;
|
4473 |
|
|
}
|
4474 |
|
|
return list;
|
4475 |
|
|
}
|
4476 |
|
|
|
4477 |
|
|
/* Parse asm clobbers, a GNU extension.
|
4478 |
|
|
|
4479 |
|
|
asm-clobbers:
|
4480 |
|
|
asm-string-literal
|
4481 |
|
|
asm-clobbers , asm-string-literal
|
4482 |
|
|
*/
|
4483 |
|
|
|
4484 |
|
|
static tree
|
4485 |
|
|
c_parser_asm_clobbers (c_parser *parser)
|
4486 |
|
|
{
|
4487 |
|
|
tree list = NULL_TREE;
|
4488 |
|
|
while (true)
|
4489 |
|
|
{
|
4490 |
|
|
tree str = c_parser_asm_string_literal (parser);
|
4491 |
|
|
if (str)
|
4492 |
|
|
list = tree_cons (NULL_TREE, str, list);
|
4493 |
|
|
else
|
4494 |
|
|
return NULL_TREE;
|
4495 |
|
|
if (c_parser_next_token_is (parser, CPP_COMMA))
|
4496 |
|
|
c_parser_consume_token (parser);
|
4497 |
|
|
else
|
4498 |
|
|
break;
|
4499 |
|
|
}
|
4500 |
|
|
return list;
|
4501 |
|
|
}
|
4502 |
|
|
|
4503 |
|
|
/* Parse asm goto labels, a GNU extension.
|
4504 |
|
|
|
4505 |
|
|
asm-goto-operands:
|
4506 |
|
|
identifier
|
4507 |
|
|
asm-goto-operands , identifier
|
4508 |
|
|
*/
|
4509 |
|
|
|
4510 |
|
|
static tree
|
4511 |
|
|
c_parser_asm_goto_operands (c_parser *parser)
|
4512 |
|
|
{
|
4513 |
|
|
tree list = NULL_TREE;
|
4514 |
|
|
while (true)
|
4515 |
|
|
{
|
4516 |
|
|
tree name, label;
|
4517 |
|
|
|
4518 |
|
|
if (c_parser_next_token_is (parser, CPP_NAME))
|
4519 |
|
|
{
|
4520 |
|
|
c_token *tok = c_parser_peek_token (parser);
|
4521 |
|
|
name = tok->value;
|
4522 |
|
|
label = lookup_label_for_goto (tok->location, name);
|
4523 |
|
|
c_parser_consume_token (parser);
|
4524 |
|
|
TREE_USED (label) = 1;
|
4525 |
|
|
}
|
4526 |
|
|
else
|
4527 |
|
|
{
|
4528 |
|
|
c_parser_error (parser, "expected identifier");
|
4529 |
|
|
return NULL_TREE;
|
4530 |
|
|
}
|
4531 |
|
|
|
4532 |
|
|
name = build_string (IDENTIFIER_LENGTH (name),
|
4533 |
|
|
IDENTIFIER_POINTER (name));
|
4534 |
|
|
list = tree_cons (name, label, list);
|
4535 |
|
|
if (c_parser_next_token_is (parser, CPP_COMMA))
|
4536 |
|
|
c_parser_consume_token (parser);
|
4537 |
|
|
else
|
4538 |
|
|
return nreverse (list);
|
4539 |
|
|
}
|
4540 |
|
|
}
|
4541 |
|
|
|
4542 |
|
|
/* Parse an expression other than a compound expression; that is, an
|
4543 |
|
|
assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
|
4544 |
|
|
NULL then it is an Objective-C message expression which is the
|
4545 |
|
|
primary-expression starting the expression as an initializer.
|
4546 |
|
|
|
4547 |
|
|
assignment-expression:
|
4548 |
|
|
conditional-expression
|
4549 |
|
|
unary-expression assignment-operator assignment-expression
|
4550 |
|
|
|
4551 |
|
|
assignment-operator: one of
|
4552 |
|
|
= *= /= %= += -= <<= >>= &= ^= |=
|
4553 |
|
|
|
4554 |
|
|
In GNU C we accept any conditional expression on the LHS and
|
4555 |
|
|
diagnose the invalid lvalue rather than producing a syntax
|
4556 |
|
|
error. */
|
4557 |
|
|
|
4558 |
|
|
static struct c_expr
|
4559 |
|
|
c_parser_expr_no_commas (c_parser *parser, struct c_expr *after)
|
4560 |
|
|
{
|
4561 |
|
|
struct c_expr lhs, rhs, ret;
|
4562 |
|
|
enum tree_code code;
|
4563 |
|
|
location_t op_location, exp_location;
|
4564 |
|
|
gcc_assert (!after || c_dialect_objc ());
|
4565 |
|
|
lhs = c_parser_conditional_expression (parser, after);
|
4566 |
|
|
op_location = c_parser_peek_token (parser)->location;
|
4567 |
|
|
switch (c_parser_peek_token (parser)->type)
|
4568 |
|
|
{
|
4569 |
|
|
case CPP_EQ:
|
4570 |
|
|
code = NOP_EXPR;
|
4571 |
|
|
break;
|
4572 |
|
|
case CPP_MULT_EQ:
|
4573 |
|
|
code = MULT_EXPR;
|
4574 |
|
|
break;
|
4575 |
|
|
case CPP_DIV_EQ:
|
4576 |
|
|
code = TRUNC_DIV_EXPR;
|
4577 |
|
|
break;
|
4578 |
|
|
case CPP_MOD_EQ:
|
4579 |
|
|
code = TRUNC_MOD_EXPR;
|
4580 |
|
|
break;
|
4581 |
|
|
case CPP_PLUS_EQ:
|
4582 |
|
|
code = PLUS_EXPR;
|
4583 |
|
|
break;
|
4584 |
|
|
case CPP_MINUS_EQ:
|
4585 |
|
|
code = MINUS_EXPR;
|
4586 |
|
|
break;
|
4587 |
|
|
case CPP_LSHIFT_EQ:
|
4588 |
|
|
code = LSHIFT_EXPR;
|
4589 |
|
|
break;
|
4590 |
|
|
case CPP_RSHIFT_EQ:
|
4591 |
|
|
code = RSHIFT_EXPR;
|
4592 |
|
|
break;
|
4593 |
|
|
case CPP_AND_EQ:
|
4594 |
|
|
code = BIT_AND_EXPR;
|
4595 |
|
|
break;
|
4596 |
|
|
case CPP_XOR_EQ:
|
4597 |
|
|
code = BIT_XOR_EXPR;
|
4598 |
|
|
break;
|
4599 |
|
|
case CPP_OR_EQ:
|
4600 |
|
|
code = BIT_IOR_EXPR;
|
4601 |
|
|
break;
|
4602 |
|
|
default:
|
4603 |
|
|
return lhs;
|
4604 |
|
|
}
|
4605 |
|
|
c_parser_consume_token (parser);
|
4606 |
|
|
exp_location = c_parser_peek_token (parser)->location;
|
4607 |
|
|
rhs = c_parser_expr_no_commas (parser, NULL);
|
4608 |
|
|
rhs = default_function_array_conversion (exp_location, rhs);
|
4609 |
|
|
ret.value = build_modify_expr (op_location, lhs.value, lhs.original_type,
|
4610 |
|
|
code, exp_location, rhs.value,
|
4611 |
|
|
rhs.original_type);
|
4612 |
|
|
if (code == NOP_EXPR)
|
4613 |
|
|
ret.original_code = MODIFY_EXPR;
|
4614 |
|
|
else
|
4615 |
|
|
{
|
4616 |
|
|
TREE_NO_WARNING (ret.value) = 1;
|
4617 |
|
|
ret.original_code = ERROR_MARK;
|
4618 |
|
|
}
|
4619 |
|
|
ret.original_type = NULL;
|
4620 |
|
|
return ret;
|
4621 |
|
|
}
|
4622 |
|
|
|
4623 |
|
|
/* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
|
4624 |
|
|
is not NULL then it is an Objective-C message expression which is
|
4625 |
|
|
the primary-expression starting the expression as an initializer.
|
4626 |
|
|
|
4627 |
|
|
conditional-expression:
|
4628 |
|
|
logical-OR-expression
|
4629 |
|
|
logical-OR-expression ? expression : conditional-expression
|
4630 |
|
|
|
4631 |
|
|
GNU extensions:
|
4632 |
|
|
|
4633 |
|
|
conditional-expression:
|
4634 |
|
|
logical-OR-expression ? : conditional-expression
|
4635 |
|
|
*/
|
4636 |
|
|
|
4637 |
|
|
static struct c_expr
|
4638 |
|
|
c_parser_conditional_expression (c_parser *parser, struct c_expr *after)
|
4639 |
|
|
{
|
4640 |
|
|
struct c_expr cond, exp1, exp2, ret;
|
4641 |
|
|
location_t cond_loc, colon_loc;
|
4642 |
|
|
|
4643 |
|
|
gcc_assert (!after || c_dialect_objc ());
|
4644 |
|
|
|
4645 |
|
|
cond = c_parser_binary_expression (parser, after);
|
4646 |
|
|
|
4647 |
|
|
if (c_parser_next_token_is_not (parser, CPP_QUERY))
|
4648 |
|
|
return cond;
|
4649 |
|
|
cond_loc = c_parser_peek_token (parser)->location;
|
4650 |
|
|
cond = default_function_array_conversion (cond_loc, cond);
|
4651 |
|
|
c_parser_consume_token (parser);
|
4652 |
|
|
if (c_parser_next_token_is (parser, CPP_COLON))
|
4653 |
|
|
{
|
4654 |
|
|
tree eptype = NULL_TREE;
|
4655 |
|
|
pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
|
4656 |
|
|
"ISO C forbids omitting the middle term of a ?: expression");
|
4657 |
|
|
if (TREE_CODE (cond.value) == EXCESS_PRECISION_EXPR)
|
4658 |
|
|
{
|
4659 |
|
|
eptype = TREE_TYPE (cond.value);
|
4660 |
|
|
cond.value = TREE_OPERAND (cond.value, 0);
|
4661 |
|
|
}
|
4662 |
|
|
/* Make sure first operand is calculated only once. */
|
4663 |
|
|
exp1.value = c_save_expr (default_conversion (cond.value));
|
4664 |
|
|
if (eptype)
|
4665 |
|
|
exp1.value = build1 (EXCESS_PRECISION_EXPR, eptype, exp1.value);
|
4666 |
|
|
exp1.original_type = NULL;
|
4667 |
|
|
cond.value = c_objc_common_truthvalue_conversion (cond_loc, exp1.value);
|
4668 |
|
|
c_inhibit_evaluation_warnings += cond.value == truthvalue_true_node;
|
4669 |
|
|
}
|
4670 |
|
|
else
|
4671 |
|
|
{
|
4672 |
|
|
cond.value
|
4673 |
|
|
= c_objc_common_truthvalue_conversion
|
4674 |
|
|
(cond_loc, default_conversion (cond.value));
|
4675 |
|
|
c_inhibit_evaluation_warnings += cond.value == truthvalue_false_node;
|
4676 |
|
|
exp1 = c_parser_expression_conv (parser);
|
4677 |
|
|
c_inhibit_evaluation_warnings +=
|
4678 |
|
|
((cond.value == truthvalue_true_node)
|
4679 |
|
|
- (cond.value == truthvalue_false_node));
|
4680 |
|
|
}
|
4681 |
|
|
|
4682 |
|
|
colon_loc = c_parser_peek_token (parser)->location;
|
4683 |
|
|
if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
|
4684 |
|
|
{
|
4685 |
|
|
c_inhibit_evaluation_warnings -= cond.value == truthvalue_true_node;
|
4686 |
|
|
ret.value = error_mark_node;
|
4687 |
|
|
ret.original_code = ERROR_MARK;
|
4688 |
|
|
ret.original_type = NULL;
|
4689 |
|
|
return ret;
|
4690 |
|
|
}
|
4691 |
|
|
{
|
4692 |
|
|
location_t exp2_loc = c_parser_peek_token (parser)->location;
|
4693 |
|
|
exp2 = c_parser_conditional_expression (parser, NULL);
|
4694 |
|
|
exp2 = default_function_array_conversion (exp2_loc, exp2);
|
4695 |
|
|
}
|
4696 |
|
|
c_inhibit_evaluation_warnings -= cond.value == truthvalue_true_node;
|
4697 |
|
|
ret.value = build_conditional_expr (colon_loc, cond.value,
|
4698 |
|
|
cond.original_code == C_MAYBE_CONST_EXPR,
|
4699 |
|
|
exp1.value, exp1.original_type,
|
4700 |
|
|
exp2.value, exp2.original_type);
|
4701 |
|
|
ret.original_code = ERROR_MARK;
|
4702 |
|
|
if (exp1.value == error_mark_node || exp2.value == error_mark_node)
|
4703 |
|
|
ret.original_type = NULL;
|
4704 |
|
|
else
|
4705 |
|
|
{
|
4706 |
|
|
tree t1, t2;
|
4707 |
|
|
|
4708 |
|
|
/* If both sides are enum type, the default conversion will have
|
4709 |
|
|
made the type of the result be an integer type. We want to
|
4710 |
|
|
remember the enum types we started with. */
|
4711 |
|
|
t1 = exp1.original_type ? exp1.original_type : TREE_TYPE (exp1.value);
|
4712 |
|
|
t2 = exp2.original_type ? exp2.original_type : TREE_TYPE (exp2.value);
|
4713 |
|
|
ret.original_type = ((t1 != error_mark_node
|
4714 |
|
|
&& t2 != error_mark_node
|
4715 |
|
|
&& (TYPE_MAIN_VARIANT (t1)
|
4716 |
|
|
== TYPE_MAIN_VARIANT (t2)))
|
4717 |
|
|
? t1
|
4718 |
|
|
: NULL);
|
4719 |
|
|
}
|
4720 |
|
|
return ret;
|
4721 |
|
|
}
|
4722 |
|
|
|
4723 |
|
|
/* Parse a binary expression; that is, a logical-OR-expression (C90
|
4724 |
|
|
6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
|
4725 |
|
|
an Objective-C message expression which is the primary-expression
|
4726 |
|
|
starting the expression as an initializer.
|
4727 |
|
|
|
4728 |
|
|
multiplicative-expression:
|
4729 |
|
|
cast-expression
|
4730 |
|
|
multiplicative-expression * cast-expression
|
4731 |
|
|
multiplicative-expression / cast-expression
|
4732 |
|
|
multiplicative-expression % cast-expression
|
4733 |
|
|
|
4734 |
|
|
additive-expression:
|
4735 |
|
|
multiplicative-expression
|
4736 |
|
|
additive-expression + multiplicative-expression
|
4737 |
|
|
additive-expression - multiplicative-expression
|
4738 |
|
|
|
4739 |
|
|
shift-expression:
|
4740 |
|
|
additive-expression
|
4741 |
|
|
shift-expression << additive-expression
|
4742 |
|
|
shift-expression >> additive-expression
|
4743 |
|
|
|
4744 |
|
|
relational-expression:
|
4745 |
|
|
shift-expression
|
4746 |
|
|
relational-expression < shift-expression
|
4747 |
|
|
relational-expression > shift-expression
|
4748 |
|
|
relational-expression <= shift-expression
|
4749 |
|
|
relational-expression >= shift-expression
|
4750 |
|
|
|
4751 |
|
|
equality-expression:
|
4752 |
|
|
relational-expression
|
4753 |
|
|
equality-expression == relational-expression
|
4754 |
|
|
equality-expression != relational-expression
|
4755 |
|
|
|
4756 |
|
|
AND-expression:
|
4757 |
|
|
equality-expression
|
4758 |
|
|
AND-expression & equality-expression
|
4759 |
|
|
|
4760 |
|
|
exclusive-OR-expression:
|
4761 |
|
|
AND-expression
|
4762 |
|
|
exclusive-OR-expression ^ AND-expression
|
4763 |
|
|
|
4764 |
|
|
inclusive-OR-expression:
|
4765 |
|
|
exclusive-OR-expression
|
4766 |
|
|
inclusive-OR-expression | exclusive-OR-expression
|
4767 |
|
|
|
4768 |
|
|
logical-AND-expression:
|
4769 |
|
|
inclusive-OR-expression
|
4770 |
|
|
logical-AND-expression && inclusive-OR-expression
|
4771 |
|
|
|
4772 |
|
|
logical-OR-expression:
|
4773 |
|
|
logical-AND-expression
|
4774 |
|
|
logical-OR-expression || logical-AND-expression
|
4775 |
|
|
*/
|
4776 |
|
|
|
4777 |
|
|
static struct c_expr
|
4778 |
|
|
c_parser_binary_expression (c_parser *parser, struct c_expr *after)
|
4779 |
|
|
{
|
4780 |
|
|
/* A binary expression is parsed using operator-precedence parsing,
|
4781 |
|
|
with the operands being cast expressions. All the binary
|
4782 |
|
|
operators are left-associative. Thus a binary expression is of
|
4783 |
|
|
form:
|
4784 |
|
|
|
4785 |
|
|
E0 op1 E1 op2 E2 ...
|
4786 |
|
|
|
4787 |
|
|
which we represent on a stack. On the stack, the precedence
|
4788 |
|
|
levels are strictly increasing. When a new operator is
|
4789 |
|
|
encountered of higher precedence than that at the top of the
|
4790 |
|
|
stack, it is pushed; its LHS is the top expression, and its RHS
|
4791 |
|
|
is everything parsed until it is popped. When a new operator is
|
4792 |
|
|
encountered with precedence less than or equal to that at the top
|
4793 |
|
|
of the stack, triples E[i-1] op[i] E[i] are popped and replaced
|
4794 |
|
|
by the result of the operation until the operator at the top of
|
4795 |
|
|
the stack has lower precedence than the new operator or there is
|
4796 |
|
|
only one element on the stack; then the top expression is the LHS
|
4797 |
|
|
of the new operator. In the case of logical AND and OR
|
4798 |
|
|
expressions, we also need to adjust c_inhibit_evaluation_warnings
|
4799 |
|
|
as appropriate when the operators are pushed and popped. */
|
4800 |
|
|
|
4801 |
|
|
/* The precedence levels, where 0 is a dummy lowest level used for
|
4802 |
|
|
the bottom of the stack. */
|
4803 |
|
|
enum prec {
|
4804 |
|
|
PREC_NONE,
|
4805 |
|
|
PREC_LOGOR,
|
4806 |
|
|
PREC_LOGAND,
|
4807 |
|
|
PREC_BITOR,
|
4808 |
|
|
PREC_BITXOR,
|
4809 |
|
|
PREC_BITAND,
|
4810 |
|
|
PREC_EQ,
|
4811 |
|
|
PREC_REL,
|
4812 |
|
|
PREC_SHIFT,
|
4813 |
|
|
PREC_ADD,
|
4814 |
|
|
PREC_MULT,
|
4815 |
|
|
NUM_PRECS
|
4816 |
|
|
};
|
4817 |
|
|
struct {
|
4818 |
|
|
/* The expression at this stack level. */
|
4819 |
|
|
struct c_expr expr;
|
4820 |
|
|
/* The precedence of the operator on its left, PREC_NONE at the
|
4821 |
|
|
bottom of the stack. */
|
4822 |
|
|
enum prec prec;
|
4823 |
|
|
/* The operation on its left. */
|
4824 |
|
|
enum tree_code op;
|
4825 |
|
|
/* The source location of this operation. */
|
4826 |
|
|
location_t loc;
|
4827 |
|
|
} stack[NUM_PRECS];
|
4828 |
|
|
int sp;
|
4829 |
|
|
/* Location of the binary operator. */
|
4830 |
|
|
location_t binary_loc = UNKNOWN_LOCATION; /* Quiet warning. */
|
4831 |
|
|
#define POP \
|
4832 |
|
|
do { \
|
4833 |
|
|
switch (stack[sp].op) \
|
4834 |
|
|
{ \
|
4835 |
|
|
case TRUTH_ANDIF_EXPR: \
|
4836 |
|
|
c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
|
4837 |
|
|
== truthvalue_false_node); \
|
4838 |
|
|
break; \
|
4839 |
|
|
case TRUTH_ORIF_EXPR: \
|
4840 |
|
|
c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
|
4841 |
|
|
== truthvalue_true_node); \
|
4842 |
|
|
break; \
|
4843 |
|
|
default: \
|
4844 |
|
|
break; \
|
4845 |
|
|
} \
|
4846 |
|
|
stack[sp - 1].expr \
|
4847 |
|
|
= default_function_array_conversion (stack[sp - 1].loc, \
|
4848 |
|
|
stack[sp - 1].expr); \
|
4849 |
|
|
stack[sp].expr \
|
4850 |
|
|
= default_function_array_conversion (stack[sp].loc, stack[sp].expr); \
|
4851 |
|
|
stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc, \
|
4852 |
|
|
stack[sp].op, \
|
4853 |
|
|
stack[sp - 1].expr, \
|
4854 |
|
|
stack[sp].expr); \
|
4855 |
|
|
sp--; \
|
4856 |
|
|
} while (0)
|
4857 |
|
|
gcc_assert (!after || c_dialect_objc ());
|
4858 |
|
|
stack[0].loc = c_parser_peek_token (parser)->location;
|
4859 |
|
|
stack[0].expr = c_parser_cast_expression (parser, after);
|
4860 |
|
|
stack[0].prec = PREC_NONE;
|
4861 |
|
|
sp = 0;
|
4862 |
|
|
while (true)
|
4863 |
|
|
{
|
4864 |
|
|
enum prec oprec;
|
4865 |
|
|
enum tree_code ocode;
|
4866 |
|
|
if (parser->error)
|
4867 |
|
|
goto out;
|
4868 |
|
|
switch (c_parser_peek_token (parser)->type)
|
4869 |
|
|
{
|
4870 |
|
|
case CPP_MULT:
|
4871 |
|
|
oprec = PREC_MULT;
|
4872 |
|
|
ocode = MULT_EXPR;
|
4873 |
|
|
break;
|
4874 |
|
|
case CPP_DIV:
|
4875 |
|
|
oprec = PREC_MULT;
|
4876 |
|
|
ocode = TRUNC_DIV_EXPR;
|
4877 |
|
|
break;
|
4878 |
|
|
case CPP_MOD:
|
4879 |
|
|
oprec = PREC_MULT;
|
4880 |
|
|
ocode = TRUNC_MOD_EXPR;
|
4881 |
|
|
break;
|
4882 |
|
|
case CPP_PLUS:
|
4883 |
|
|
oprec = PREC_ADD;
|
4884 |
|
|
ocode = PLUS_EXPR;
|
4885 |
|
|
break;
|
4886 |
|
|
case CPP_MINUS:
|
4887 |
|
|
oprec = PREC_ADD;
|
4888 |
|
|
ocode = MINUS_EXPR;
|
4889 |
|
|
break;
|
4890 |
|
|
case CPP_LSHIFT:
|
4891 |
|
|
oprec = PREC_SHIFT;
|
4892 |
|
|
ocode = LSHIFT_EXPR;
|
4893 |
|
|
break;
|
4894 |
|
|
case CPP_RSHIFT:
|
4895 |
|
|
oprec = PREC_SHIFT;
|
4896 |
|
|
ocode = RSHIFT_EXPR;
|
4897 |
|
|
break;
|
4898 |
|
|
case CPP_LESS:
|
4899 |
|
|
oprec = PREC_REL;
|
4900 |
|
|
ocode = LT_EXPR;
|
4901 |
|
|
break;
|
4902 |
|
|
case CPP_GREATER:
|
4903 |
|
|
oprec = PREC_REL;
|
4904 |
|
|
ocode = GT_EXPR;
|
4905 |
|
|
break;
|
4906 |
|
|
case CPP_LESS_EQ:
|
4907 |
|
|
oprec = PREC_REL;
|
4908 |
|
|
ocode = LE_EXPR;
|
4909 |
|
|
break;
|
4910 |
|
|
case CPP_GREATER_EQ:
|
4911 |
|
|
oprec = PREC_REL;
|
4912 |
|
|
ocode = GE_EXPR;
|
4913 |
|
|
break;
|
4914 |
|
|
case CPP_EQ_EQ:
|
4915 |
|
|
oprec = PREC_EQ;
|
4916 |
|
|
ocode = EQ_EXPR;
|
4917 |
|
|
break;
|
4918 |
|
|
case CPP_NOT_EQ:
|
4919 |
|
|
oprec = PREC_EQ;
|
4920 |
|
|
ocode = NE_EXPR;
|
4921 |
|
|
break;
|
4922 |
|
|
case CPP_AND:
|
4923 |
|
|
oprec = PREC_BITAND;
|
4924 |
|
|
ocode = BIT_AND_EXPR;
|
4925 |
|
|
break;
|
4926 |
|
|
case CPP_XOR:
|
4927 |
|
|
oprec = PREC_BITXOR;
|
4928 |
|
|
ocode = BIT_XOR_EXPR;
|
4929 |
|
|
break;
|
4930 |
|
|
case CPP_OR:
|
4931 |
|
|
oprec = PREC_BITOR;
|
4932 |
|
|
ocode = BIT_IOR_EXPR;
|
4933 |
|
|
break;
|
4934 |
|
|
case CPP_AND_AND:
|
4935 |
|
|
oprec = PREC_LOGAND;
|
4936 |
|
|
ocode = TRUTH_ANDIF_EXPR;
|
4937 |
|
|
break;
|
4938 |
|
|
case CPP_OR_OR:
|
4939 |
|
|
oprec = PREC_LOGOR;
|
4940 |
|
|
ocode = TRUTH_ORIF_EXPR;
|
4941 |
|
|
break;
|
4942 |
|
|
default:
|
4943 |
|
|
/* Not a binary operator, so end of the binary
|
4944 |
|
|
expression. */
|
4945 |
|
|
goto out;
|
4946 |
|
|
}
|
4947 |
|
|
binary_loc = c_parser_peek_token (parser)->location;
|
4948 |
|
|
c_parser_consume_token (parser);
|
4949 |
|
|
while (oprec <= stack[sp].prec)
|
4950 |
|
|
POP;
|
4951 |
|
|
switch (ocode)
|
4952 |
|
|
{
|
4953 |
|
|
case TRUTH_ANDIF_EXPR:
|
4954 |
|
|
stack[sp].expr
|
4955 |
|
|
= default_function_array_conversion (stack[sp].loc,
|
4956 |
|
|
stack[sp].expr);
|
4957 |
|
|
stack[sp].expr.value = c_objc_common_truthvalue_conversion
|
4958 |
|
|
(stack[sp].loc, default_conversion (stack[sp].expr.value));
|
4959 |
|
|
c_inhibit_evaluation_warnings += (stack[sp].expr.value
|
4960 |
|
|
== truthvalue_false_node);
|
4961 |
|
|
break;
|
4962 |
|
|
case TRUTH_ORIF_EXPR:
|
4963 |
|
|
stack[sp].expr
|
4964 |
|
|
= default_function_array_conversion (stack[sp].loc,
|
4965 |
|
|
stack[sp].expr);
|
4966 |
|
|
stack[sp].expr.value = c_objc_common_truthvalue_conversion
|
4967 |
|
|
(stack[sp].loc, default_conversion (stack[sp].expr.value));
|
4968 |
|
|
c_inhibit_evaluation_warnings += (stack[sp].expr.value
|
4969 |
|
|
== truthvalue_true_node);
|
4970 |
|
|
break;
|
4971 |
|
|
default:
|
4972 |
|
|
break;
|
4973 |
|
|
}
|
4974 |
|
|
sp++;
|
4975 |
|
|
stack[sp].loc = binary_loc;
|
4976 |
|
|
stack[sp].expr = c_parser_cast_expression (parser, NULL);
|
4977 |
|
|
stack[sp].prec = oprec;
|
4978 |
|
|
stack[sp].op = ocode;
|
4979 |
|
|
stack[sp].loc = binary_loc;
|
4980 |
|
|
}
|
4981 |
|
|
out:
|
4982 |
|
|
while (sp > 0)
|
4983 |
|
|
POP;
|
4984 |
|
|
return stack[0].expr;
|
4985 |
|
|
#undef POP
|
4986 |
|
|
}
|
4987 |
|
|
|
4988 |
|
|
/* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
|
4989 |
|
|
NULL then it is an Objective-C message expression which is the
|
4990 |
|
|
primary-expression starting the expression as an initializer.
|
4991 |
|
|
|
4992 |
|
|
cast-expression:
|
4993 |
|
|
unary-expression
|
4994 |
|
|
( type-name ) unary-expression
|
4995 |
|
|
*/
|
4996 |
|
|
|
4997 |
|
|
static struct c_expr
|
4998 |
|
|
c_parser_cast_expression (c_parser *parser, struct c_expr *after)
|
4999 |
|
|
{
|
5000 |
|
|
location_t cast_loc = c_parser_peek_token (parser)->location;
|
5001 |
|
|
gcc_assert (!after || c_dialect_objc ());
|
5002 |
|
|
if (after)
|
5003 |
|
|
return c_parser_postfix_expression_after_primary (parser,
|
5004 |
|
|
cast_loc, *after);
|
5005 |
|
|
/* If the expression begins with a parenthesized type name, it may
|
5006 |
|
|
be either a cast or a compound literal; we need to see whether
|
5007 |
|
|
the next character is '{' to tell the difference. If not, it is
|
5008 |
|
|
an unary expression. */
|
5009 |
|
|
if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
|
5010 |
|
|
&& c_token_starts_typename (c_parser_peek_2nd_token (parser)))
|
5011 |
|
|
{
|
5012 |
|
|
struct c_type_name *type_name;
|
5013 |
|
|
struct c_expr ret;
|
5014 |
|
|
struct c_expr expr;
|
5015 |
|
|
c_parser_consume_token (parser);
|
5016 |
|
|
type_name = c_parser_type_name (parser);
|
5017 |
|
|
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
|
5018 |
|
|
if (type_name == NULL)
|
5019 |
|
|
{
|
5020 |
|
|
ret.value = error_mark_node;
|
5021 |
|
|
ret.original_code = ERROR_MARK;
|
5022 |
|
|
ret.original_type = NULL;
|
5023 |
|
|
return ret;
|
5024 |
|
|
}
|
5025 |
|
|
|
5026 |
|
|
/* Save casted types in the function's used types hash table. */
|
5027 |
|
|
used_types_insert (type_name->specs->type);
|
5028 |
|
|
|
5029 |
|
|
if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
|
5030 |
|
|
return c_parser_postfix_expression_after_paren_type (parser, type_name,
|
5031 |
|
|
cast_loc);
|
5032 |
|
|
{
|
5033 |
|
|
location_t expr_loc = c_parser_peek_token (parser)->location;
|
5034 |
|
|
expr = c_parser_cast_expression (parser, NULL);
|
5035 |
|
|
expr = default_function_array_conversion (expr_loc, expr);
|
5036 |
|
|
}
|
5037 |
|
|
ret.value = c_cast_expr (cast_loc, type_name, expr.value);
|
5038 |
|
|
ret.original_code = ERROR_MARK;
|
5039 |
|
|
ret.original_type = NULL;
|
5040 |
|
|
return ret;
|
5041 |
|
|
}
|
5042 |
|
|
else
|
5043 |
|
|
return c_parser_unary_expression (parser);
|
5044 |
|
|
}
|
5045 |
|
|
|
5046 |
|
|
/* Parse an unary expression (C90 6.3.3, C99 6.5.3).
|
5047 |
|
|
|
5048 |
|
|
unary-expression:
|
5049 |
|
|
postfix-expression
|
5050 |
|
|
++ unary-expression
|
5051 |
|
|
-- unary-expression
|
5052 |
|
|
unary-operator cast-expression
|
5053 |
|
|
sizeof unary-expression
|
5054 |
|
|
sizeof ( type-name )
|
5055 |
|
|
|
5056 |
|
|
unary-operator: one of
|
5057 |
|
|
& * + - ~ !
|
5058 |
|
|
|
5059 |
|
|
GNU extensions:
|
5060 |
|
|
|
5061 |
|
|
unary-expression:
|
5062 |
|
|
__alignof__ unary-expression
|
5063 |
|
|
__alignof__ ( type-name )
|
5064 |
|
|
&& identifier
|
5065 |
|
|
|
5066 |
|
|
unary-operator: one of
|
5067 |
|
|
__extension__ __real__ __imag__
|
5068 |
|
|
|
5069 |
|
|
In addition, the GNU syntax treats ++ and -- as unary operators, so
|
5070 |
|
|
they may be applied to cast expressions with errors for non-lvalues
|
5071 |
|
|
given later. */
|
5072 |
|
|
|
5073 |
|
|
static struct c_expr
|
5074 |
|
|
c_parser_unary_expression (c_parser *parser)
|
5075 |
|
|
{
|
5076 |
|
|
int ext;
|
5077 |
|
|
struct c_expr ret, op;
|
5078 |
|
|
location_t op_loc = c_parser_peek_token (parser)->location;
|
5079 |
|
|
location_t exp_loc;
|
5080 |
|
|
ret.original_code = ERROR_MARK;
|
5081 |
|
|
ret.original_type = NULL;
|
5082 |
|
|
switch (c_parser_peek_token (parser)->type)
|
5083 |
|
|
{
|
5084 |
|
|
case CPP_PLUS_PLUS:
|
5085 |
|
|
c_parser_consume_token (parser);
|
5086 |
|
|
exp_loc = c_parser_peek_token (parser)->location;
|
5087 |
|
|
op = c_parser_cast_expression (parser, NULL);
|
5088 |
|
|
op = default_function_array_conversion (exp_loc, op);
|
5089 |
|
|
return parser_build_unary_op (op_loc, PREINCREMENT_EXPR, op);
|
5090 |
|
|
case CPP_MINUS_MINUS:
|
5091 |
|
|
c_parser_consume_token (parser);
|
5092 |
|
|
exp_loc = c_parser_peek_token (parser)->location;
|
5093 |
|
|
op = c_parser_cast_expression (parser, NULL);
|
5094 |
|
|
op = default_function_array_conversion (exp_loc, op);
|
5095 |
|
|
return parser_build_unary_op (op_loc, PREDECREMENT_EXPR, op);
|
5096 |
|
|
case CPP_AND:
|
5097 |
|
|
c_parser_consume_token (parser);
|
5098 |
|
|
return parser_build_unary_op (op_loc, ADDR_EXPR,
|
5099 |
|
|
c_parser_cast_expression (parser, NULL));
|
5100 |
|
|
case CPP_MULT:
|
5101 |
|
|
c_parser_consume_token (parser);
|
5102 |
|
|
exp_loc = c_parser_peek_token (parser)->location;
|
5103 |
|
|
op = c_parser_cast_expression (parser, NULL);
|
5104 |
|
|
op = default_function_array_conversion (exp_loc, op);
|
5105 |
|
|
ret.value = build_indirect_ref (op_loc, op.value, RO_UNARY_STAR);
|
5106 |
|
|
return ret;
|
5107 |
|
|
case CPP_PLUS:
|
5108 |
|
|
if (!c_dialect_objc () && !in_system_header)
|
5109 |
|
|
warning_at (op_loc,
|
5110 |
|
|
OPT_Wtraditional,
|
5111 |
|
|
"traditional C rejects the unary plus operator");
|
5112 |
|
|
c_parser_consume_token (parser);
|
5113 |
|
|
exp_loc = c_parser_peek_token (parser)->location;
|
5114 |
|
|
op = c_parser_cast_expression (parser, NULL);
|
5115 |
|
|
op = default_function_array_conversion (exp_loc, op);
|
5116 |
|
|
return parser_build_unary_op (op_loc, CONVERT_EXPR, op);
|
5117 |
|
|
case CPP_MINUS:
|
5118 |
|
|
c_parser_consume_token (parser);
|
5119 |
|
|
exp_loc = c_parser_peek_token (parser)->location;
|
5120 |
|
|
op = c_parser_cast_expression (parser, NULL);
|
5121 |
|
|
op = default_function_array_conversion (exp_loc, op);
|
5122 |
|
|
return parser_build_unary_op (op_loc, NEGATE_EXPR, op);
|
5123 |
|
|
case CPP_COMPL:
|
5124 |
|
|
c_parser_consume_token (parser);
|
5125 |
|
|
exp_loc = c_parser_peek_token (parser)->location;
|
5126 |
|
|
op = c_parser_cast_expression (parser, NULL);
|
5127 |
|
|
op = default_function_array_conversion (exp_loc, op);
|
5128 |
|
|
return parser_build_unary_op (op_loc, BIT_NOT_EXPR, op);
|
5129 |
|
|
case CPP_NOT:
|
5130 |
|
|
c_parser_consume_token (parser);
|
5131 |
|
|
exp_loc = c_parser_peek_token (parser)->location;
|
5132 |
|
|
op = c_parser_cast_expression (parser, NULL);
|
5133 |
|
|
op = default_function_array_conversion (exp_loc, op);
|
5134 |
|
|
return parser_build_unary_op (op_loc, TRUTH_NOT_EXPR, op);
|
5135 |
|
|
case CPP_AND_AND:
|
5136 |
|
|
/* Refer to the address of a label as a pointer. */
|
5137 |
|
|
c_parser_consume_token (parser);
|
5138 |
|
|
if (c_parser_next_token_is (parser, CPP_NAME))
|
5139 |
|
|
{
|
5140 |
|
|
ret.value = finish_label_address_expr
|
5141 |
|
|
(c_parser_peek_token (parser)->value, op_loc);
|
5142 |
|
|
c_parser_consume_token (parser);
|
5143 |
|
|
}
|
5144 |
|
|
else
|
5145 |
|
|
{
|
5146 |
|
|
c_parser_error (parser, "expected identifier");
|
5147 |
|
|
ret.value = error_mark_node;
|
5148 |
|
|
}
|
5149 |
|
|
return ret;
|
5150 |
|
|
case CPP_KEYWORD:
|
5151 |
|
|
switch (c_parser_peek_token (parser)->keyword)
|
5152 |
|
|
{
|
5153 |
|
|
case RID_SIZEOF:
|
5154 |
|
|
return c_parser_sizeof_expression (parser);
|
5155 |
|
|
case RID_ALIGNOF:
|
5156 |
|
|
return c_parser_alignof_expression (parser);
|
5157 |
|
|
case RID_EXTENSION:
|
5158 |
|
|
c_parser_consume_token (parser);
|
5159 |
|
|
ext = disable_extension_diagnostics ();
|
5160 |
|
|
ret = c_parser_cast_expression (parser, NULL);
|
5161 |
|
|
restore_extension_diagnostics (ext);
|
5162 |
|
|
return ret;
|
5163 |
|
|
case RID_REALPART:
|
5164 |
|
|
c_parser_consume_token (parser);
|
5165 |
|
|
exp_loc = c_parser_peek_token (parser)->location;
|
5166 |
|
|
op = c_parser_cast_expression (parser, NULL);
|
5167 |
|
|
op = default_function_array_conversion (exp_loc, op);
|
5168 |
|
|
return parser_build_unary_op (op_loc, REALPART_EXPR, op);
|
5169 |
|
|
case RID_IMAGPART:
|
5170 |
|
|
c_parser_consume_token (parser);
|
5171 |
|
|
exp_loc = c_parser_peek_token (parser)->location;
|
5172 |
|
|
op = c_parser_cast_expression (parser, NULL);
|
5173 |
|
|
op = default_function_array_conversion (exp_loc, op);
|
5174 |
|
|
return parser_build_unary_op (op_loc, IMAGPART_EXPR, op);
|
5175 |
|
|
default:
|
5176 |
|
|
return c_parser_postfix_expression (parser);
|
5177 |
|
|
}
|
5178 |
|
|
default:
|
5179 |
|
|
return c_parser_postfix_expression (parser);
|
5180 |
|
|
}
|
5181 |
|
|
}
|
5182 |
|
|
|
5183 |
|
|
/* Parse a sizeof expression. */
|
5184 |
|
|
|
5185 |
|
|
static struct c_expr
|
5186 |
|
|
c_parser_sizeof_expression (c_parser *parser)
|
5187 |
|
|
{
|
5188 |
|
|
struct c_expr expr;
|
5189 |
|
|
location_t expr_loc;
|
5190 |
|
|
gcc_assert (c_parser_next_token_is_keyword (parser, RID_SIZEOF));
|
5191 |
|
|
c_parser_consume_token (parser);
|
5192 |
|
|
c_inhibit_evaluation_warnings++;
|
5193 |
|
|
in_sizeof++;
|
5194 |
|
|
if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
|
5195 |
|
|
&& c_token_starts_typename (c_parser_peek_2nd_token (parser)))
|
5196 |
|
|
{
|
5197 |
|
|
/* Either sizeof ( type-name ) or sizeof unary-expression
|
5198 |
|
|
starting with a compound literal. */
|
5199 |
|
|
struct c_type_name *type_name;
|
5200 |
|
|
c_parser_consume_token (parser);
|
5201 |
|
|
expr_loc = c_parser_peek_token (parser)->location;
|
5202 |
|
|
type_name = c_parser_type_name (parser);
|
5203 |
|
|
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
|
5204 |
|
|
if (type_name == NULL)
|
5205 |
|
|
{
|
5206 |
|
|
struct c_expr ret;
|
5207 |
|
|
c_inhibit_evaluation_warnings--;
|
5208 |
|
|
in_sizeof--;
|
5209 |
|
|
ret.value = error_mark_node;
|
5210 |
|
|
ret.original_code = ERROR_MARK;
|
5211 |
|
|
ret.original_type = NULL;
|
5212 |
|
|
return ret;
|
5213 |
|
|
}
|
5214 |
|
|
if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
|
5215 |
|
|
{
|
5216 |
|
|
expr = c_parser_postfix_expression_after_paren_type (parser,
|
5217 |
|
|
type_name,
|
5218 |
|
|
expr_loc);
|
5219 |
|
|
goto sizeof_expr;
|
5220 |
|
|
}
|
5221 |
|
|
/* sizeof ( type-name ). */
|
5222 |
|
|
c_inhibit_evaluation_warnings--;
|
5223 |
|
|
in_sizeof--;
|
5224 |
|
|
return c_expr_sizeof_type (expr_loc, type_name);
|
5225 |
|
|
}
|
5226 |
|
|
else
|
5227 |
|
|
{
|
5228 |
|
|
expr_loc = c_parser_peek_token (parser)->location;
|
5229 |
|
|
expr = c_parser_unary_expression (parser);
|
5230 |
|
|
sizeof_expr:
|
5231 |
|
|
c_inhibit_evaluation_warnings--;
|
5232 |
|
|
in_sizeof--;
|
5233 |
|
|
if (TREE_CODE (expr.value) == COMPONENT_REF
|
5234 |
|
|
&& DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
|
5235 |
|
|
error_at (expr_loc, "%<sizeof%> applied to a bit-field");
|
5236 |
|
|
return c_expr_sizeof_expr (expr_loc, expr);
|
5237 |
|
|
}
|
5238 |
|
|
}
|
5239 |
|
|
|
5240 |
|
|
/* Parse an alignof expression. */
|
5241 |
|
|
|
5242 |
|
|
static struct c_expr
|
5243 |
|
|
c_parser_alignof_expression (c_parser *parser)
|
5244 |
|
|
{
|
5245 |
|
|
struct c_expr expr;
|
5246 |
|
|
location_t loc = c_parser_peek_token (parser)->location;
|
5247 |
|
|
gcc_assert (c_parser_next_token_is_keyword (parser, RID_ALIGNOF));
|
5248 |
|
|
c_parser_consume_token (parser);
|
5249 |
|
|
c_inhibit_evaluation_warnings++;
|
5250 |
|
|
in_alignof++;
|
5251 |
|
|
if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
|
5252 |
|
|
&& c_token_starts_typename (c_parser_peek_2nd_token (parser)))
|
5253 |
|
|
{
|
5254 |
|
|
/* Either __alignof__ ( type-name ) or __alignof__
|
5255 |
|
|
unary-expression starting with a compound literal. */
|
5256 |
|
|
location_t loc;
|
5257 |
|
|
struct c_type_name *type_name;
|
5258 |
|
|
struct c_expr ret;
|
5259 |
|
|
c_parser_consume_token (parser);
|
5260 |
|
|
loc = c_parser_peek_token (parser)->location;
|
5261 |
|
|
type_name = c_parser_type_name (parser);
|
5262 |
|
|
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
|
5263 |
|
|
if (type_name == NULL)
|
5264 |
|
|
{
|
5265 |
|
|
struct c_expr ret;
|
5266 |
|
|
c_inhibit_evaluation_warnings--;
|
5267 |
|
|
in_alignof--;
|
5268 |
|
|
ret.value = error_mark_node;
|
5269 |
|
|
ret.original_code = ERROR_MARK;
|
5270 |
|
|
ret.original_type = NULL;
|
5271 |
|
|
return ret;
|
5272 |
|
|
}
|
5273 |
|
|
if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
|
5274 |
|
|
{
|
5275 |
|
|
expr = c_parser_postfix_expression_after_paren_type (parser,
|
5276 |
|
|
type_name,
|
5277 |
|
|
loc);
|
5278 |
|
|
goto alignof_expr;
|
5279 |
|
|
}
|
5280 |
|
|
/* alignof ( type-name ). */
|
5281 |
|
|
c_inhibit_evaluation_warnings--;
|
5282 |
|
|
in_alignof--;
|
5283 |
|
|
ret.value = c_alignof (loc, groktypename (type_name, NULL, NULL));
|
5284 |
|
|
ret.original_code = ERROR_MARK;
|
5285 |
|
|
ret.original_type = NULL;
|
5286 |
|
|
return ret;
|
5287 |
|
|
}
|
5288 |
|
|
else
|
5289 |
|
|
{
|
5290 |
|
|
struct c_expr ret;
|
5291 |
|
|
expr = c_parser_unary_expression (parser);
|
5292 |
|
|
alignof_expr:
|
5293 |
|
|
c_inhibit_evaluation_warnings--;
|
5294 |
|
|
in_alignof--;
|
5295 |
|
|
ret.value = c_alignof_expr (loc, expr.value);
|
5296 |
|
|
ret.original_code = ERROR_MARK;
|
5297 |
|
|
ret.original_type = NULL;
|
5298 |
|
|
return ret;
|
5299 |
|
|
}
|
5300 |
|
|
}
|
5301 |
|
|
|
5302 |
|
|
/* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
|
5303 |
|
|
|
5304 |
|
|
postfix-expression:
|
5305 |
|
|
primary-expression
|
5306 |
|
|
postfix-expression [ expression ]
|
5307 |
|
|
postfix-expression ( argument-expression-list[opt] )
|
5308 |
|
|
postfix-expression . identifier
|
5309 |
|
|
postfix-expression -> identifier
|
5310 |
|
|
postfix-expression ++
|
5311 |
|
|
postfix-expression --
|
5312 |
|
|
( type-name ) { initializer-list }
|
5313 |
|
|
( type-name ) { initializer-list , }
|
5314 |
|
|
|
5315 |
|
|
argument-expression-list:
|
5316 |
|
|
argument-expression
|
5317 |
|
|
argument-expression-list , argument-expression
|
5318 |
|
|
|
5319 |
|
|
primary-expression:
|
5320 |
|
|
identifier
|
5321 |
|
|
constant
|
5322 |
|
|
string-literal
|
5323 |
|
|
( expression )
|
5324 |
|
|
|
5325 |
|
|
GNU extensions:
|
5326 |
|
|
|
5327 |
|
|
primary-expression:
|
5328 |
|
|
__func__
|
5329 |
|
|
(treated as a keyword in GNU C)
|
5330 |
|
|
__FUNCTION__
|
5331 |
|
|
__PRETTY_FUNCTION__
|
5332 |
|
|
( compound-statement )
|
5333 |
|
|
__builtin_va_arg ( assignment-expression , type-name )
|
5334 |
|
|
__builtin_offsetof ( type-name , offsetof-member-designator )
|
5335 |
|
|
__builtin_choose_expr ( assignment-expression ,
|
5336 |
|
|
assignment-expression ,
|
5337 |
|
|
assignment-expression )
|
5338 |
|
|
__builtin_types_compatible_p ( type-name , type-name )
|
5339 |
|
|
|
5340 |
|
|
offsetof-member-designator:
|
5341 |
|
|
identifier
|
5342 |
|
|
offsetof-member-designator . identifier
|
5343 |
|
|
offsetof-member-designator [ expression ]
|
5344 |
|
|
|
5345 |
|
|
Objective-C:
|
5346 |
|
|
|
5347 |
|
|
primary-expression:
|
5348 |
|
|
[ objc-receiver objc-message-args ]
|
5349 |
|
|
@selector ( objc-selector-arg )
|
5350 |
|
|
@protocol ( identifier )
|
5351 |
|
|
@encode ( type-name )
|
5352 |
|
|
objc-string-literal
|
5353 |
|
|
*/
|
5354 |
|
|
|
5355 |
|
|
static struct c_expr
|
5356 |
|
|
c_parser_postfix_expression (c_parser *parser)
|
5357 |
|
|
{
|
5358 |
|
|
struct c_expr expr, e1, e2, e3;
|
5359 |
|
|
struct c_type_name *t1, *t2;
|
5360 |
|
|
location_t loc = c_parser_peek_token (parser)->location;;
|
5361 |
|
|
expr.original_code = ERROR_MARK;
|
5362 |
|
|
expr.original_type = NULL;
|
5363 |
|
|
switch (c_parser_peek_token (parser)->type)
|
5364 |
|
|
{
|
5365 |
|
|
case CPP_NUMBER:
|
5366 |
|
|
expr.value = c_parser_peek_token (parser)->value;
|
5367 |
|
|
loc = c_parser_peek_token (parser)->location;
|
5368 |
|
|
c_parser_consume_token (parser);
|
5369 |
|
|
if (TREE_CODE (expr.value) == FIXED_CST
|
5370 |
|
|
&& !targetm.fixed_point_supported_p ())
|
5371 |
|
|
{
|
5372 |
|
|
error_at (loc, "fixed-point types not supported for this target");
|
5373 |
|
|
expr.value = error_mark_node;
|
5374 |
|
|
}
|
5375 |
|
|
break;
|
5376 |
|
|
case CPP_CHAR:
|
5377 |
|
|
case CPP_CHAR16:
|
5378 |
|
|
case CPP_CHAR32:
|
5379 |
|
|
case CPP_WCHAR:
|
5380 |
|
|
expr.value = c_parser_peek_token (parser)->value;
|
5381 |
|
|
c_parser_consume_token (parser);
|
5382 |
|
|
break;
|
5383 |
|
|
case CPP_STRING:
|
5384 |
|
|
case CPP_STRING16:
|
5385 |
|
|
case CPP_STRING32:
|
5386 |
|
|
case CPP_WSTRING:
|
5387 |
|
|
case CPP_UTF8STRING:
|
5388 |
|
|
expr.value = c_parser_peek_token (parser)->value;
|
5389 |
|
|
expr.original_code = STRING_CST;
|
5390 |
|
|
c_parser_consume_token (parser);
|
5391 |
|
|
break;
|
5392 |
|
|
case CPP_OBJC_STRING:
|
5393 |
|
|
gcc_assert (c_dialect_objc ());
|
5394 |
|
|
expr.value
|
5395 |
|
|
= objc_build_string_object (c_parser_peek_token (parser)->value);
|
5396 |
|
|
c_parser_consume_token (parser);
|
5397 |
|
|
break;
|
5398 |
|
|
case CPP_NAME:
|
5399 |
|
|
if (c_parser_peek_token (parser)->id_kind != C_ID_ID)
|
5400 |
|
|
{
|
5401 |
|
|
c_parser_error (parser, "expected expression");
|
5402 |
|
|
expr.value = error_mark_node;
|
5403 |
|
|
break;
|
5404 |
|
|
}
|
5405 |
|
|
{
|
5406 |
|
|
tree id = c_parser_peek_token (parser)->value;
|
5407 |
|
|
c_parser_consume_token (parser);
|
5408 |
|
|
expr.value = build_external_ref (loc, id,
|
5409 |
|
|
(c_parser_peek_token (parser)->type
|
5410 |
|
|
== CPP_OPEN_PAREN),
|
5411 |
|
|
&expr.original_type);
|
5412 |
|
|
}
|
5413 |
|
|
break;
|
5414 |
|
|
case CPP_OPEN_PAREN:
|
5415 |
|
|
/* A parenthesized expression, statement expression or compound
|
5416 |
|
|
literal. */
|
5417 |
|
|
if (c_parser_peek_2nd_token (parser)->type == CPP_OPEN_BRACE)
|
5418 |
|
|
{
|
5419 |
|
|
/* A statement expression. */
|
5420 |
|
|
tree stmt;
|
5421 |
|
|
location_t brace_loc;
|
5422 |
|
|
c_parser_consume_token (parser);
|
5423 |
|
|
brace_loc = c_parser_peek_token (parser)->location;
|
5424 |
|
|
c_parser_consume_token (parser);
|
5425 |
|
|
if (cur_stmt_list == NULL)
|
5426 |
|
|
{
|
5427 |
|
|
error_at (loc, "braced-group within expression allowed "
|
5428 |
|
|
"only inside a function");
|
5429 |
|
|
parser->error = true;
|
5430 |
|
|
c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
|
5431 |
|
|
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
|
5432 |
|
|
expr.value = error_mark_node;
|
5433 |
|
|
break;
|
5434 |
|
|
}
|
5435 |
|
|
stmt = c_begin_stmt_expr ();
|
5436 |
|
|
c_parser_compound_statement_nostart (parser);
|
5437 |
|
|
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
|
5438 |
|
|
"expected %<)%>");
|
5439 |
|
|
pedwarn (loc, OPT_pedantic,
|
5440 |
|
|
"ISO C forbids braced-groups within expressions");
|
5441 |
|
|
expr.value = c_finish_stmt_expr (brace_loc, stmt);
|
5442 |
|
|
}
|
5443 |
|
|
else if (c_token_starts_typename (c_parser_peek_2nd_token (parser)))
|
5444 |
|
|
{
|
5445 |
|
|
/* A compound literal. ??? Can we actually get here rather
|
5446 |
|
|
than going directly to
|
5447 |
|
|
c_parser_postfix_expression_after_paren_type from
|
5448 |
|
|
elsewhere? */
|
5449 |
|
|
location_t loc;
|
5450 |
|
|
struct c_type_name *type_name;
|
5451 |
|
|
c_parser_consume_token (parser);
|
5452 |
|
|
loc = c_parser_peek_token (parser)->location;
|
5453 |
|
|
type_name = c_parser_type_name (parser);
|
5454 |
|
|
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
|
5455 |
|
|
"expected %<)%>");
|
5456 |
|
|
if (type_name == NULL)
|
5457 |
|
|
{
|
5458 |
|
|
expr.value = error_mark_node;
|
5459 |
|
|
}
|
5460 |
|
|
else
|
5461 |
|
|
expr = c_parser_postfix_expression_after_paren_type (parser,
|
5462 |
|
|
type_name,
|
5463 |
|
|
loc);
|
5464 |
|
|
}
|
5465 |
|
|
else
|
5466 |
|
|
{
|
5467 |
|
|
/* A parenthesized expression. */
|
5468 |
|
|
c_parser_consume_token (parser);
|
5469 |
|
|
expr = c_parser_expression (parser);
|
5470 |
|
|
if (TREE_CODE (expr.value) == MODIFY_EXPR)
|
5471 |
|
|
TREE_NO_WARNING (expr.value) = 1;
|
5472 |
|
|
if (expr.original_code != C_MAYBE_CONST_EXPR)
|
5473 |
|
|
expr.original_code = ERROR_MARK;
|
5474 |
|
|
/* Don't change EXPR.ORIGINAL_TYPE. */
|
5475 |
|
|
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
|
5476 |
|
|
"expected %<)%>");
|
5477 |
|
|
}
|
5478 |
|
|
break;
|
5479 |
|
|
case CPP_KEYWORD:
|
5480 |
|
|
switch (c_parser_peek_token (parser)->keyword)
|
5481 |
|
|
{
|
5482 |
|
|
case RID_FUNCTION_NAME:
|
5483 |
|
|
case RID_PRETTY_FUNCTION_NAME:
|
5484 |
|
|
case RID_C99_FUNCTION_NAME:
|
5485 |
|
|
expr.value = fname_decl (loc,
|
5486 |
|
|
c_parser_peek_token (parser)->keyword,
|
5487 |
|
|
c_parser_peek_token (parser)->value);
|
5488 |
|
|
c_parser_consume_token (parser);
|
5489 |
|
|
break;
|
5490 |
|
|
case RID_VA_ARG:
|
5491 |
|
|
c_parser_consume_token (parser);
|
5492 |
|
|
if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
|
5493 |
|
|
{
|
5494 |
|
|
expr.value = error_mark_node;
|
5495 |
|
|
break;
|
5496 |
|
|
}
|
5497 |
|
|
e1 = c_parser_expr_no_commas (parser, NULL);
|
5498 |
|
|
e1.value = c_fully_fold (e1.value, false, NULL);
|
5499 |
|
|
if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
|
5500 |
|
|
{
|
5501 |
|
|
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
|
5502 |
|
|
expr.value = error_mark_node;
|
5503 |
|
|
break;
|
5504 |
|
|
}
|
5505 |
|
|
loc = c_parser_peek_token (parser)->location;
|
5506 |
|
|
t1 = c_parser_type_name (parser);
|
5507 |
|
|
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
|
5508 |
|
|
"expected %<)%>");
|
5509 |
|
|
if (t1 == NULL)
|
5510 |
|
|
{
|
5511 |
|
|
expr.value = error_mark_node;
|
5512 |
|
|
}
|
5513 |
|
|
else
|
5514 |
|
|
{
|
5515 |
|
|
tree type_expr = NULL_TREE;
|
5516 |
|
|
expr.value = c_build_va_arg (loc, e1.value,
|
5517 |
|
|
groktypename (t1, &type_expr, NULL));
|
5518 |
|
|
if (type_expr)
|
5519 |
|
|
{
|
5520 |
|
|
expr.value = build2 (C_MAYBE_CONST_EXPR,
|
5521 |
|
|
TREE_TYPE (expr.value), type_expr,
|
5522 |
|
|
expr.value);
|
5523 |
|
|
C_MAYBE_CONST_EXPR_NON_CONST (expr.value) = true;
|
5524 |
|
|
}
|
5525 |
|
|
}
|
5526 |
|
|
break;
|
5527 |
|
|
case RID_OFFSETOF:
|
5528 |
|
|
c_parser_consume_token (parser);
|
5529 |
|
|
if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
|
5530 |
|
|
{
|
5531 |
|
|
expr.value = error_mark_node;
|
5532 |
|
|
break;
|
5533 |
|
|
}
|
5534 |
|
|
t1 = c_parser_type_name (parser);
|
5535 |
|
|
if (t1 == NULL)
|
5536 |
|
|
{
|
5537 |
|
|
expr.value = error_mark_node;
|
5538 |
|
|
break;
|
5539 |
|
|
}
|
5540 |
|
|
if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
|
5541 |
|
|
{
|
5542 |
|
|
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
|
5543 |
|
|
expr.value = error_mark_node;
|
5544 |
|
|
break;
|
5545 |
|
|
}
|
5546 |
|
|
{
|
5547 |
|
|
tree type = groktypename (t1, NULL, NULL);
|
5548 |
|
|
tree offsetof_ref;
|
5549 |
|
|
if (type == error_mark_node)
|
5550 |
|
|
offsetof_ref = error_mark_node;
|
5551 |
|
|
else
|
5552 |
|
|
{
|
5553 |
|
|
offsetof_ref = build1 (INDIRECT_REF, type, null_pointer_node);
|
5554 |
|
|
SET_EXPR_LOCATION (offsetof_ref, loc);
|
5555 |
|
|
}
|
5556 |
|
|
/* Parse the second argument to __builtin_offsetof. We
|
5557 |
|
|
must have one identifier, and beyond that we want to
|
5558 |
|
|
accept sub structure and sub array references. */
|
5559 |
|
|
if (c_parser_next_token_is (parser, CPP_NAME))
|
5560 |
|
|
{
|
5561 |
|
|
offsetof_ref = build_component_ref
|
5562 |
|
|
(loc, offsetof_ref, c_parser_peek_token (parser)->value);
|
5563 |
|
|
c_parser_consume_token (parser);
|
5564 |
|
|
while (c_parser_next_token_is (parser, CPP_DOT)
|
5565 |
|
|
|| c_parser_next_token_is (parser,
|
5566 |
|
|
CPP_OPEN_SQUARE)
|
5567 |
|
|
|| c_parser_next_token_is (parser,
|
5568 |
|
|
CPP_DEREF))
|
5569 |
|
|
{
|
5570 |
|
|
if (c_parser_next_token_is (parser, CPP_DEREF))
|
5571 |
|
|
{
|
5572 |
|
|
loc = c_parser_peek_token (parser)->location;
|
5573 |
|
|
offsetof_ref = build_array_ref (loc,
|
5574 |
|
|
offsetof_ref,
|
5575 |
|
|
integer_zero_node);
|
5576 |
|
|
goto do_dot;
|
5577 |
|
|
}
|
5578 |
|
|
else if (c_parser_next_token_is (parser, CPP_DOT))
|
5579 |
|
|
{
|
5580 |
|
|
do_dot:
|
5581 |
|
|
c_parser_consume_token (parser);
|
5582 |
|
|
if (c_parser_next_token_is_not (parser,
|
5583 |
|
|
CPP_NAME))
|
5584 |
|
|
{
|
5585 |
|
|
c_parser_error (parser, "expected identifier");
|
5586 |
|
|
break;
|
5587 |
|
|
}
|
5588 |
|
|
offsetof_ref = build_component_ref
|
5589 |
|
|
(loc, offsetof_ref,
|
5590 |
|
|
c_parser_peek_token (parser)->value);
|
5591 |
|
|
c_parser_consume_token (parser);
|
5592 |
|
|
}
|
5593 |
|
|
else
|
5594 |
|
|
{
|
5595 |
|
|
tree idx;
|
5596 |
|
|
loc = c_parser_peek_token (parser)->location;
|
5597 |
|
|
c_parser_consume_token (parser);
|
5598 |
|
|
idx = c_parser_expression (parser).value;
|
5599 |
|
|
idx = c_fully_fold (idx, false, NULL);
|
5600 |
|
|
c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
|
5601 |
|
|
"expected %<]%>");
|
5602 |
|
|
offsetof_ref = build_array_ref (loc, offsetof_ref, idx);
|
5603 |
|
|
}
|
5604 |
|
|
}
|
5605 |
|
|
}
|
5606 |
|
|
else
|
5607 |
|
|
c_parser_error (parser, "expected identifier");
|
5608 |
|
|
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
|
5609 |
|
|
"expected %<)%>");
|
5610 |
|
|
expr.value = fold_offsetof (offsetof_ref, NULL_TREE);
|
5611 |
|
|
}
|
5612 |
|
|
break;
|
5613 |
|
|
case RID_CHOOSE_EXPR:
|
5614 |
|
|
c_parser_consume_token (parser);
|
5615 |
|
|
if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
|
5616 |
|
|
{
|
5617 |
|
|
expr.value = error_mark_node;
|
5618 |
|
|
break;
|
5619 |
|
|
}
|
5620 |
|
|
loc = c_parser_peek_token (parser)->location;
|
5621 |
|
|
e1 = c_parser_expr_no_commas (parser, NULL);
|
5622 |
|
|
if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
|
5623 |
|
|
{
|
5624 |
|
|
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
|
5625 |
|
|
expr.value = error_mark_node;
|
5626 |
|
|
break;
|
5627 |
|
|
}
|
5628 |
|
|
e2 = c_parser_expr_no_commas (parser, NULL);
|
5629 |
|
|
if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
|
5630 |
|
|
{
|
5631 |
|
|
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
|
5632 |
|
|
expr.value = error_mark_node;
|
5633 |
|
|
break;
|
5634 |
|
|
}
|
5635 |
|
|
e3 = c_parser_expr_no_commas (parser, NULL);
|
5636 |
|
|
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
|
5637 |
|
|
"expected %<)%>");
|
5638 |
|
|
{
|
5639 |
|
|
tree c;
|
5640 |
|
|
|
5641 |
|
|
c = e1.value;
|
5642 |
|
|
if (TREE_CODE (c) != INTEGER_CST
|
5643 |
|
|
|| !INTEGRAL_TYPE_P (TREE_TYPE (c)))
|
5644 |
|
|
error_at (loc,
|
5645 |
|
|
"first argument to %<__builtin_choose_expr%> not"
|
5646 |
|
|
" a constant");
|
5647 |
|
|
constant_expression_warning (c);
|
5648 |
|
|
expr = integer_zerop (c) ? e3 : e2;
|
5649 |
|
|
}
|
5650 |
|
|
break;
|
5651 |
|
|
case RID_TYPES_COMPATIBLE_P:
|
5652 |
|
|
c_parser_consume_token (parser);
|
5653 |
|
|
if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
|
5654 |
|
|
{
|
5655 |
|
|
expr.value = error_mark_node;
|
5656 |
|
|
break;
|
5657 |
|
|
}
|
5658 |
|
|
t1 = c_parser_type_name (parser);
|
5659 |
|
|
if (t1 == NULL)
|
5660 |
|
|
{
|
5661 |
|
|
expr.value = error_mark_node;
|
5662 |
|
|
break;
|
5663 |
|
|
}
|
5664 |
|
|
if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
|
5665 |
|
|
{
|
5666 |
|
|
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
|
5667 |
|
|
expr.value = error_mark_node;
|
5668 |
|
|
break;
|
5669 |
|
|
}
|
5670 |
|
|
t2 = c_parser_type_name (parser);
|
5671 |
|
|
if (t2 == NULL)
|
5672 |
|
|
{
|
5673 |
|
|
expr.value = error_mark_node;
|
5674 |
|
|
break;
|
5675 |
|
|
}
|
5676 |
|
|
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
|
5677 |
|
|
"expected %<)%>");
|
5678 |
|
|
{
|
5679 |
|
|
tree e1, e2;
|
5680 |
|
|
|
5681 |
|
|
e1 = TYPE_MAIN_VARIANT (groktypename (t1, NULL, NULL));
|
5682 |
|
|
e2 = TYPE_MAIN_VARIANT (groktypename (t2, NULL, NULL));
|
5683 |
|
|
|
5684 |
|
|
expr.value = comptypes (e1, e2)
|
5685 |
|
|
? build_int_cst (NULL_TREE, 1)
|
5686 |
|
|
: build_int_cst (NULL_TREE, 0);
|
5687 |
|
|
}
|
5688 |
|
|
break;
|
5689 |
|
|
case RID_AT_SELECTOR:
|
5690 |
|
|
gcc_assert (c_dialect_objc ());
|
5691 |
|
|
c_parser_consume_token (parser);
|
5692 |
|
|
if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
|
5693 |
|
|
{
|
5694 |
|
|
expr.value = error_mark_node;
|
5695 |
|
|
break;
|
5696 |
|
|
}
|
5697 |
|
|
{
|
5698 |
|
|
tree sel = c_parser_objc_selector_arg (parser);
|
5699 |
|
|
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
|
5700 |
|
|
"expected %<)%>");
|
5701 |
|
|
expr.value = objc_build_selector_expr (loc, sel);
|
5702 |
|
|
}
|
5703 |
|
|
break;
|
5704 |
|
|
case RID_AT_PROTOCOL:
|
5705 |
|
|
gcc_assert (c_dialect_objc ());
|
5706 |
|
|
c_parser_consume_token (parser);
|
5707 |
|
|
if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
|
5708 |
|
|
{
|
5709 |
|
|
expr.value = error_mark_node;
|
5710 |
|
|
break;
|
5711 |
|
|
}
|
5712 |
|
|
if (c_parser_next_token_is_not (parser, CPP_NAME))
|
5713 |
|
|
{
|
5714 |
|
|
c_parser_error (parser, "expected identifier");
|
5715 |
|
|
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
|
5716 |
|
|
expr.value = error_mark_node;
|
5717 |
|
|
break;
|
5718 |
|
|
}
|
5719 |
|
|
{
|
5720 |
|
|
tree id = c_parser_peek_token (parser)->value;
|
5721 |
|
|
c_parser_consume_token (parser);
|
5722 |
|
|
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
|
5723 |
|
|
"expected %<)%>");
|
5724 |
|
|
expr.value = objc_build_protocol_expr (id);
|
5725 |
|
|
}
|
5726 |
|
|
break;
|
5727 |
|
|
case RID_AT_ENCODE:
|
5728 |
|
|
/* Extension to support C-structures in the archiver. */
|
5729 |
|
|
gcc_assert (c_dialect_objc ());
|
5730 |
|
|
c_parser_consume_token (parser);
|
5731 |
|
|
if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
|
5732 |
|
|
{
|
5733 |
|
|
expr.value = error_mark_node;
|
5734 |
|
|
break;
|
5735 |
|
|
}
|
5736 |
|
|
t1 = c_parser_type_name (parser);
|
5737 |
|
|
if (t1 == NULL)
|
5738 |
|
|
{
|
5739 |
|
|
expr.value = error_mark_node;
|
5740 |
|
|
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
|
5741 |
|
|
break;
|
5742 |
|
|
}
|
5743 |
|
|
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
|
5744 |
|
|
"expected %<)%>");
|
5745 |
|
|
{
|
5746 |
|
|
tree type = groktypename (t1, NULL, NULL);
|
5747 |
|
|
expr.value = objc_build_encode_expr (type);
|
5748 |
|
|
}
|
5749 |
|
|
break;
|
5750 |
|
|
default:
|
5751 |
|
|
c_parser_error (parser, "expected expression");
|
5752 |
|
|
expr.value = error_mark_node;
|
5753 |
|
|
break;
|
5754 |
|
|
}
|
5755 |
|
|
break;
|
5756 |
|
|
case CPP_OPEN_SQUARE:
|
5757 |
|
|
if (c_dialect_objc ())
|
5758 |
|
|
{
|
5759 |
|
|
tree receiver, args;
|
5760 |
|
|
c_parser_consume_token (parser);
|
5761 |
|
|
receiver = c_parser_objc_receiver (parser);
|
5762 |
|
|
args = c_parser_objc_message_args (parser);
|
5763 |
|
|
c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
|
5764 |
|
|
"expected %<]%>");
|
5765 |
|
|
expr.value = objc_build_message_expr (build_tree_list (receiver,
|
5766 |
|
|
args));
|
5767 |
|
|
break;
|
5768 |
|
|
}
|
5769 |
|
|
/* Else fall through to report error. */
|
5770 |
|
|
default:
|
5771 |
|
|
c_parser_error (parser, "expected expression");
|
5772 |
|
|
expr.value = error_mark_node;
|
5773 |
|
|
break;
|
5774 |
|
|
}
|
5775 |
|
|
return c_parser_postfix_expression_after_primary (parser, loc, expr);
|
5776 |
|
|
}
|
5777 |
|
|
|
5778 |
|
|
/* Parse a postfix expression after a parenthesized type name: the
|
5779 |
|
|
brace-enclosed initializer of a compound literal, possibly followed
|
5780 |
|
|
by some postfix operators. This is separate because it is not
|
5781 |
|
|
possible to tell until after the type name whether a cast
|
5782 |
|
|
expression has a cast or a compound literal, or whether the operand
|
5783 |
|
|
of sizeof is a parenthesized type name or starts with a compound
|
5784 |
|
|
literal. TYPE_LOC is the location where TYPE_NAME starts--the
|
5785 |
|
|
location of the first token after the parentheses around the type
|
5786 |
|
|
name. */
|
5787 |
|
|
|
5788 |
|
|
static struct c_expr
|
5789 |
|
|
c_parser_postfix_expression_after_paren_type (c_parser *parser,
|
5790 |
|
|
struct c_type_name *type_name,
|
5791 |
|
|
location_t type_loc)
|
5792 |
|
|
{
|
5793 |
|
|
tree type;
|
5794 |
|
|
struct c_expr init;
|
5795 |
|
|
bool non_const;
|
5796 |
|
|
struct c_expr expr;
|
5797 |
|
|
location_t start_loc;
|
5798 |
|
|
tree type_expr = NULL_TREE;
|
5799 |
|
|
bool type_expr_const = true;
|
5800 |
|
|
check_compound_literal_type (type_loc, type_name);
|
5801 |
|
|
start_init (NULL_TREE, NULL, 0);
|
5802 |
|
|
type = groktypename (type_name, &type_expr, &type_expr_const);
|
5803 |
|
|
start_loc = c_parser_peek_token (parser)->location;
|
5804 |
|
|
if (type != error_mark_node && C_TYPE_VARIABLE_SIZE (type))
|
5805 |
|
|
{
|
5806 |
|
|
error_at (type_loc, "compound literal has variable size");
|
5807 |
|
|
type = error_mark_node;
|
5808 |
|
|
}
|
5809 |
|
|
init = c_parser_braced_init (parser, type, false);
|
5810 |
|
|
finish_init ();
|
5811 |
|
|
maybe_warn_string_init (type, init);
|
5812 |
|
|
|
5813 |
|
|
if (type != error_mark_node
|
5814 |
|
|
&& !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type))
|
5815 |
|
|
&& current_function_decl)
|
5816 |
|
|
{
|
5817 |
|
|
error ("compound literal qualified by address-space qualifier");
|
5818 |
|
|
type = error_mark_node;
|
5819 |
|
|
}
|
5820 |
|
|
|
5821 |
|
|
if (!flag_isoc99)
|
5822 |
|
|
pedwarn (start_loc, OPT_pedantic, "ISO C90 forbids compound literals");
|
5823 |
|
|
non_const = ((init.value && TREE_CODE (init.value) == CONSTRUCTOR)
|
5824 |
|
|
? CONSTRUCTOR_NON_CONST (init.value)
|
5825 |
|
|
: init.original_code == C_MAYBE_CONST_EXPR);
|
5826 |
|
|
non_const |= !type_expr_const;
|
5827 |
|
|
expr.value = build_compound_literal (start_loc, type, init.value, non_const);
|
5828 |
|
|
expr.original_code = ERROR_MARK;
|
5829 |
|
|
expr.original_type = NULL;
|
5830 |
|
|
if (type_expr)
|
5831 |
|
|
{
|
5832 |
|
|
if (TREE_CODE (expr.value) == C_MAYBE_CONST_EXPR)
|
5833 |
|
|
{
|
5834 |
|
|
gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr.value) == NULL_TREE);
|
5835 |
|
|
C_MAYBE_CONST_EXPR_PRE (expr.value) = type_expr;
|
5836 |
|
|
}
|
5837 |
|
|
else
|
5838 |
|
|
{
|
5839 |
|
|
gcc_assert (!non_const);
|
5840 |
|
|
expr.value = build2 (C_MAYBE_CONST_EXPR, type,
|
5841 |
|
|
type_expr, expr.value);
|
5842 |
|
|
}
|
5843 |
|
|
}
|
5844 |
|
|
return c_parser_postfix_expression_after_primary (parser, start_loc, expr);
|
5845 |
|
|
}
|
5846 |
|
|
|
5847 |
|
|
/* Parse a postfix expression after the initial primary or compound
|
5848 |
|
|
literal; that is, parse a series of postfix operators.
|
5849 |
|
|
|
5850 |
|
|
EXPR_LOC is the location of the primary expression. */
|
5851 |
|
|
|
5852 |
|
|
static struct c_expr
|
5853 |
|
|
c_parser_postfix_expression_after_primary (c_parser *parser,
|
5854 |
|
|
location_t expr_loc,
|
5855 |
|
|
struct c_expr expr)
|
5856 |
|
|
{
|
5857 |
|
|
struct c_expr orig_expr;
|
5858 |
|
|
tree ident, idx;
|
5859 |
|
|
VEC(tree,gc) *exprlist;
|
5860 |
|
|
VEC(tree,gc) *origtypes;
|
5861 |
|
|
while (true)
|
5862 |
|
|
{
|
5863 |
|
|
location_t op_loc = c_parser_peek_token (parser)->location;
|
5864 |
|
|
switch (c_parser_peek_token (parser)->type)
|
5865 |
|
|
{
|
5866 |
|
|
case CPP_OPEN_SQUARE:
|
5867 |
|
|
/* Array reference. */
|
5868 |
|
|
c_parser_consume_token (parser);
|
5869 |
|
|
idx = c_parser_expression (parser).value;
|
5870 |
|
|
c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
|
5871 |
|
|
"expected %<]%>");
|
5872 |
|
|
expr.value = build_array_ref (op_loc, expr.value, idx);
|
5873 |
|
|
expr.original_code = ERROR_MARK;
|
5874 |
|
|
expr.original_type = NULL;
|
5875 |
|
|
break;
|
5876 |
|
|
case CPP_OPEN_PAREN:
|
5877 |
|
|
/* Function call. */
|
5878 |
|
|
c_parser_consume_token (parser);
|
5879 |
|
|
if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
|
5880 |
|
|
exprlist = NULL;
|
5881 |
|
|
else
|
5882 |
|
|
exprlist = c_parser_expr_list (parser, true, false, &origtypes);
|
5883 |
|
|
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
|
5884 |
|
|
"expected %<)%>");
|
5885 |
|
|
orig_expr = expr;
|
5886 |
|
|
/* FIXME diagnostics: Ideally we want the FUNCNAME, not the
|
5887 |
|
|
"(" after the FUNCNAME, which is what we have now. */
|
5888 |
|
|
expr.value = build_function_call_vec (op_loc, expr.value, exprlist,
|
5889 |
|
|
origtypes);
|
5890 |
|
|
expr.original_code = ERROR_MARK;
|
5891 |
|
|
if (TREE_CODE (expr.value) == INTEGER_CST
|
5892 |
|
|
&& TREE_CODE (orig_expr.value) == FUNCTION_DECL
|
5893 |
|
|
&& DECL_BUILT_IN_CLASS (orig_expr.value) == BUILT_IN_NORMAL
|
5894 |
|
|
&& DECL_FUNCTION_CODE (orig_expr.value) == BUILT_IN_CONSTANT_P)
|
5895 |
|
|
expr.original_code = C_MAYBE_CONST_EXPR;
|
5896 |
|
|
expr.original_type = NULL;
|
5897 |
|
|
if (exprlist != NULL)
|
5898 |
|
|
{
|
5899 |
|
|
release_tree_vector (exprlist);
|
5900 |
|
|
release_tree_vector (origtypes);
|
5901 |
|
|
}
|
5902 |
|
|
break;
|
5903 |
|
|
case CPP_DOT:
|
5904 |
|
|
/* Structure element reference. */
|
5905 |
|
|
c_parser_consume_token (parser);
|
5906 |
|
|
expr = default_function_array_conversion (expr_loc, expr);
|
5907 |
|
|
if (c_parser_next_token_is (parser, CPP_NAME))
|
5908 |
|
|
ident = c_parser_peek_token (parser)->value;
|
5909 |
|
|
else
|
5910 |
|
|
{
|
5911 |
|
|
c_parser_error (parser, "expected identifier");
|
5912 |
|
|
expr.value = error_mark_node;
|
5913 |
|
|
expr.original_code = ERROR_MARK;
|
5914 |
|
|
expr.original_type = NULL;
|
5915 |
|
|
return expr;
|
5916 |
|
|
}
|
5917 |
|
|
c_parser_consume_token (parser);
|
5918 |
|
|
expr.value = build_component_ref (op_loc, expr.value, ident);
|
5919 |
|
|
expr.original_code = ERROR_MARK;
|
5920 |
|
|
if (TREE_CODE (expr.value) != COMPONENT_REF)
|
5921 |
|
|
expr.original_type = NULL;
|
5922 |
|
|
else
|
5923 |
|
|
{
|
5924 |
|
|
/* Remember the original type of a bitfield. */
|
5925 |
|
|
tree field = TREE_OPERAND (expr.value, 1);
|
5926 |
|
|
if (TREE_CODE (field) != FIELD_DECL)
|
5927 |
|
|
expr.original_type = NULL;
|
5928 |
|
|
else
|
5929 |
|
|
expr.original_type = DECL_BIT_FIELD_TYPE (field);
|
5930 |
|
|
}
|
5931 |
|
|
break;
|
5932 |
|
|
case CPP_DEREF:
|
5933 |
|
|
/* Structure element reference. */
|
5934 |
|
|
c_parser_consume_token (parser);
|
5935 |
|
|
expr = default_function_array_conversion (expr_loc, expr);
|
5936 |
|
|
if (c_parser_next_token_is (parser, CPP_NAME))
|
5937 |
|
|
ident = c_parser_peek_token (parser)->value;
|
5938 |
|
|
else
|
5939 |
|
|
{
|
5940 |
|
|
c_parser_error (parser, "expected identifier");
|
5941 |
|
|
expr.value = error_mark_node;
|
5942 |
|
|
expr.original_code = ERROR_MARK;
|
5943 |
|
|
expr.original_type = NULL;
|
5944 |
|
|
return expr;
|
5945 |
|
|
}
|
5946 |
|
|
c_parser_consume_token (parser);
|
5947 |
|
|
expr.value = build_component_ref (op_loc,
|
5948 |
|
|
build_indirect_ref (op_loc,
|
5949 |
|
|
expr.value,
|
5950 |
|
|
RO_ARROW),
|
5951 |
|
|
ident);
|
5952 |
|
|
expr.original_code = ERROR_MARK;
|
5953 |
|
|
if (TREE_CODE (expr.value) != COMPONENT_REF)
|
5954 |
|
|
expr.original_type = NULL;
|
5955 |
|
|
else
|
5956 |
|
|
{
|
5957 |
|
|
/* Remember the original type of a bitfield. */
|
5958 |
|
|
tree field = TREE_OPERAND (expr.value, 1);
|
5959 |
|
|
if (TREE_CODE (field) != FIELD_DECL)
|
5960 |
|
|
expr.original_type = NULL;
|
5961 |
|
|
else
|
5962 |
|
|
expr.original_type = DECL_BIT_FIELD_TYPE (field);
|
5963 |
|
|
}
|
5964 |
|
|
break;
|
5965 |
|
|
case CPP_PLUS_PLUS:
|
5966 |
|
|
/* Postincrement. */
|
5967 |
|
|
c_parser_consume_token (parser);
|
5968 |
|
|
expr = default_function_array_conversion (expr_loc, expr);
|
5969 |
|
|
expr.value = build_unary_op (op_loc,
|
5970 |
|
|
POSTINCREMENT_EXPR, expr.value, 0);
|
5971 |
|
|
expr.original_code = ERROR_MARK;
|
5972 |
|
|
expr.original_type = NULL;
|
5973 |
|
|
break;
|
5974 |
|
|
case CPP_MINUS_MINUS:
|
5975 |
|
|
/* Postdecrement. */
|
5976 |
|
|
c_parser_consume_token (parser);
|
5977 |
|
|
expr = default_function_array_conversion (expr_loc, expr);
|
5978 |
|
|
expr.value = build_unary_op (op_loc,
|
5979 |
|
|
POSTDECREMENT_EXPR, expr.value, 0);
|
5980 |
|
|
expr.original_code = ERROR_MARK;
|
5981 |
|
|
expr.original_type = NULL;
|
5982 |
|
|
break;
|
5983 |
|
|
default:
|
5984 |
|
|
return expr;
|
5985 |
|
|
}
|
5986 |
|
|
}
|
5987 |
|
|
}
|
5988 |
|
|
|
5989 |
|
|
/* Parse an expression (C90 6.3.17, C99 6.5.17).
|
5990 |
|
|
|
5991 |
|
|
expression:
|
5992 |
|
|
assignment-expression
|
5993 |
|
|
expression , assignment-expression
|
5994 |
|
|
*/
|
5995 |
|
|
|
5996 |
|
|
static struct c_expr
|
5997 |
|
|
c_parser_expression (c_parser *parser)
|
5998 |
|
|
{
|
5999 |
|
|
struct c_expr expr;
|
6000 |
|
|
expr = c_parser_expr_no_commas (parser, NULL);
|
6001 |
|
|
while (c_parser_next_token_is (parser, CPP_COMMA))
|
6002 |
|
|
{
|
6003 |
|
|
struct c_expr next;
|
6004 |
|
|
location_t loc = c_parser_peek_token (parser)->location;
|
6005 |
|
|
location_t expr_loc;
|
6006 |
|
|
c_parser_consume_token (parser);
|
6007 |
|
|
expr_loc = c_parser_peek_token (parser)->location;
|
6008 |
|
|
next = c_parser_expr_no_commas (parser, NULL);
|
6009 |
|
|
next = default_function_array_conversion (expr_loc, next);
|
6010 |
|
|
expr.value = build_compound_expr (loc, expr.value, next.value);
|
6011 |
|
|
expr.original_code = COMPOUND_EXPR;
|
6012 |
|
|
expr.original_type = next.original_type;
|
6013 |
|
|
}
|
6014 |
|
|
return expr;
|
6015 |
|
|
}
|
6016 |
|
|
|
6017 |
|
|
/* Parse an expression and convert functions or arrays to
|
6018 |
|
|
pointers. */
|
6019 |
|
|
|
6020 |
|
|
static struct c_expr
|
6021 |
|
|
c_parser_expression_conv (c_parser *parser)
|
6022 |
|
|
{
|
6023 |
|
|
struct c_expr expr;
|
6024 |
|
|
location_t loc = c_parser_peek_token (parser)->location;
|
6025 |
|
|
expr = c_parser_expression (parser);
|
6026 |
|
|
expr = default_function_array_conversion (loc, expr);
|
6027 |
|
|
return expr;
|
6028 |
|
|
}
|
6029 |
|
|
|
6030 |
|
|
/* Parse a non-empty list of expressions. If CONVERT_P, convert
|
6031 |
|
|
functions and arrays to pointers. If FOLD_P, fold the expressions.
|
6032 |
|
|
|
6033 |
|
|
nonempty-expr-list:
|
6034 |
|
|
assignment-expression
|
6035 |
|
|
nonempty-expr-list , assignment-expression
|
6036 |
|
|
*/
|
6037 |
|
|
|
6038 |
|
|
static VEC(tree,gc) *
|
6039 |
|
|
c_parser_expr_list (c_parser *parser, bool convert_p, bool fold_p,
|
6040 |
|
|
VEC(tree,gc) **p_orig_types)
|
6041 |
|
|
{
|
6042 |
|
|
VEC(tree,gc) *ret;
|
6043 |
|
|
VEC(tree,gc) *orig_types;
|
6044 |
|
|
struct c_expr expr;
|
6045 |
|
|
location_t loc = c_parser_peek_token (parser)->location;
|
6046 |
|
|
|
6047 |
|
|
ret = make_tree_vector ();
|
6048 |
|
|
if (p_orig_types == NULL)
|
6049 |
|
|
orig_types = NULL;
|
6050 |
|
|
else
|
6051 |
|
|
orig_types = make_tree_vector ();
|
6052 |
|
|
|
6053 |
|
|
expr = c_parser_expr_no_commas (parser, NULL);
|
6054 |
|
|
if (convert_p)
|
6055 |
|
|
expr = default_function_array_conversion (loc, expr);
|
6056 |
|
|
if (fold_p)
|
6057 |
|
|
expr.value = c_fully_fold (expr.value, false, NULL);
|
6058 |
|
|
VEC_quick_push (tree, ret, expr.value);
|
6059 |
|
|
if (orig_types != NULL)
|
6060 |
|
|
VEC_quick_push (tree, orig_types, expr.original_type);
|
6061 |
|
|
while (c_parser_next_token_is (parser, CPP_COMMA))
|
6062 |
|
|
{
|
6063 |
|
|
c_parser_consume_token (parser);
|
6064 |
|
|
loc = c_parser_peek_token (parser)->location;
|
6065 |
|
|
expr = c_parser_expr_no_commas (parser, NULL);
|
6066 |
|
|
if (convert_p)
|
6067 |
|
|
expr = default_function_array_conversion (loc, expr);
|
6068 |
|
|
if (fold_p)
|
6069 |
|
|
expr.value = c_fully_fold (expr.value, false, NULL);
|
6070 |
|
|
VEC_safe_push (tree, gc, ret, expr.value);
|
6071 |
|
|
if (orig_types != NULL)
|
6072 |
|
|
VEC_safe_push (tree, gc, orig_types, expr.original_type);
|
6073 |
|
|
}
|
6074 |
|
|
if (orig_types != NULL)
|
6075 |
|
|
*p_orig_types = orig_types;
|
6076 |
|
|
return ret;
|
6077 |
|
|
}
|
6078 |
|
|
|
6079 |
|
|
/* Parse Objective-C-specific constructs. */
|
6080 |
|
|
|
6081 |
|
|
/* Parse an objc-class-definition.
|
6082 |
|
|
|
6083 |
|
|
objc-class-definition:
|
6084 |
|
|
@interface identifier objc-superclass[opt] objc-protocol-refs[opt]
|
6085 |
|
|
objc-class-instance-variables[opt] objc-methodprotolist @end
|
6086 |
|
|
@implementation identifier objc-superclass[opt]
|
6087 |
|
|
objc-class-instance-variables[opt]
|
6088 |
|
|
@interface identifier ( identifier ) objc-protocol-refs[opt]
|
6089 |
|
|
objc-methodprotolist @end
|
6090 |
|
|
@implementation identifier ( identifier )
|
6091 |
|
|
|
6092 |
|
|
objc-superclass:
|
6093 |
|
|
: identifier
|
6094 |
|
|
|
6095 |
|
|
"@interface identifier (" must start "@interface identifier (
|
6096 |
|
|
identifier ) ...": objc-methodprotolist in the first production may
|
6097 |
|
|
not start with a parenthesized identifier as a declarator of a data
|
6098 |
|
|
definition with no declaration specifiers if the objc-superclass,
|
6099 |
|
|
objc-protocol-refs and objc-class-instance-variables are omitted. */
|
6100 |
|
|
|
6101 |
|
|
static void
|
6102 |
|
|
c_parser_objc_class_definition (c_parser *parser)
|
6103 |
|
|
{
|
6104 |
|
|
bool iface_p;
|
6105 |
|
|
tree id1;
|
6106 |
|
|
tree superclass;
|
6107 |
|
|
if (c_parser_next_token_is_keyword (parser, RID_AT_INTERFACE))
|
6108 |
|
|
iface_p = true;
|
6109 |
|
|
else if (c_parser_next_token_is_keyword (parser, RID_AT_IMPLEMENTATION))
|
6110 |
|
|
iface_p = false;
|
6111 |
|
|
else
|
6112 |
|
|
gcc_unreachable ();
|
6113 |
|
|
c_parser_consume_token (parser);
|
6114 |
|
|
if (c_parser_next_token_is_not (parser, CPP_NAME))
|
6115 |
|
|
{
|
6116 |
|
|
c_parser_error (parser, "expected identifier");
|
6117 |
|
|
return;
|
6118 |
|
|
}
|
6119 |
|
|
id1 = c_parser_peek_token (parser)->value;
|
6120 |
|
|
c_parser_consume_token (parser);
|
6121 |
|
|
if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
|
6122 |
|
|
{
|
6123 |
|
|
tree id2;
|
6124 |
|
|
tree proto = NULL_TREE;
|
6125 |
|
|
c_parser_consume_token (parser);
|
6126 |
|
|
if (c_parser_next_token_is_not (parser, CPP_NAME))
|
6127 |
|
|
{
|
6128 |
|
|
c_parser_error (parser, "expected identifier");
|
6129 |
|
|
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
|
6130 |
|
|
return;
|
6131 |
|
|
}
|
6132 |
|
|
id2 = c_parser_peek_token (parser)->value;
|
6133 |
|
|
c_parser_consume_token (parser);
|
6134 |
|
|
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
|
6135 |
|
|
if (!iface_p)
|
6136 |
|
|
{
|
6137 |
|
|
objc_start_category_implementation (id1, id2);
|
6138 |
|
|
return;
|
6139 |
|
|
}
|
6140 |
|
|
if (c_parser_next_token_is (parser, CPP_LESS))
|
6141 |
|
|
proto = c_parser_objc_protocol_refs (parser);
|
6142 |
|
|
objc_start_category_interface (id1, id2, proto);
|
6143 |
|
|
c_parser_objc_methodprotolist (parser);
|
6144 |
|
|
c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
|
6145 |
|
|
objc_finish_interface ();
|
6146 |
|
|
return;
|
6147 |
|
|
}
|
6148 |
|
|
if (c_parser_next_token_is (parser, CPP_COLON))
|
6149 |
|
|
{
|
6150 |
|
|
c_parser_consume_token (parser);
|
6151 |
|
|
if (c_parser_next_token_is_not (parser, CPP_NAME))
|
6152 |
|
|
{
|
6153 |
|
|
c_parser_error (parser, "expected identifier");
|
6154 |
|
|
return;
|
6155 |
|
|
}
|
6156 |
|
|
superclass = c_parser_peek_token (parser)->value;
|
6157 |
|
|
c_parser_consume_token (parser);
|
6158 |
|
|
}
|
6159 |
|
|
else
|
6160 |
|
|
superclass = NULL_TREE;
|
6161 |
|
|
if (iface_p)
|
6162 |
|
|
{
|
6163 |
|
|
tree proto = NULL_TREE;
|
6164 |
|
|
if (c_parser_next_token_is (parser, CPP_LESS))
|
6165 |
|
|
proto = c_parser_objc_protocol_refs (parser);
|
6166 |
|
|
objc_start_class_interface (id1, superclass, proto);
|
6167 |
|
|
}
|
6168 |
|
|
else
|
6169 |
|
|
objc_start_class_implementation (id1, superclass);
|
6170 |
|
|
if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
|
6171 |
|
|
c_parser_objc_class_instance_variables (parser);
|
6172 |
|
|
if (iface_p)
|
6173 |
|
|
{
|
6174 |
|
|
objc_continue_interface ();
|
6175 |
|
|
c_parser_objc_methodprotolist (parser);
|
6176 |
|
|
c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
|
6177 |
|
|
objc_finish_interface ();
|
6178 |
|
|
}
|
6179 |
|
|
else
|
6180 |
|
|
{
|
6181 |
|
|
objc_continue_implementation ();
|
6182 |
|
|
return;
|
6183 |
|
|
}
|
6184 |
|
|
}
|
6185 |
|
|
|
6186 |
|
|
/* Parse objc-class-instance-variables.
|
6187 |
|
|
|
6188 |
|
|
objc-class-instance-variables:
|
6189 |
|
|
{ objc-instance-variable-decl-list[opt] }
|
6190 |
|
|
|
6191 |
|
|
objc-instance-variable-decl-list:
|
6192 |
|
|
objc-visibility-spec
|
6193 |
|
|
objc-instance-variable-decl ;
|
6194 |
|
|
;
|
6195 |
|
|
objc-instance-variable-decl-list objc-visibility-spec
|
6196 |
|
|
objc-instance-variable-decl-list objc-instance-variable-decl ;
|
6197 |
|
|
objc-instance-variable-decl-list ;
|
6198 |
|
|
|
6199 |
|
|
objc-visibility-spec:
|
6200 |
|
|
@private
|
6201 |
|
|
@protected
|
6202 |
|
|
@public
|
6203 |
|
|
|
6204 |
|
|
objc-instance-variable-decl:
|
6205 |
|
|
struct-declaration
|
6206 |
|
|
*/
|
6207 |
|
|
|
6208 |
|
|
static void
|
6209 |
|
|
c_parser_objc_class_instance_variables (c_parser *parser)
|
6210 |
|
|
{
|
6211 |
|
|
gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE));
|
6212 |
|
|
c_parser_consume_token (parser);
|
6213 |
|
|
while (c_parser_next_token_is_not (parser, CPP_EOF))
|
6214 |
|
|
{
|
6215 |
|
|
tree decls;
|
6216 |
|
|
/* Parse any stray semicolon. */
|
6217 |
|
|
if (c_parser_next_token_is (parser, CPP_SEMICOLON))
|
6218 |
|
|
{
|
6219 |
|
|
pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
|
6220 |
|
|
"extra semicolon in struct or union specified");
|
6221 |
|
|
c_parser_consume_token (parser);
|
6222 |
|
|
continue;
|
6223 |
|
|
}
|
6224 |
|
|
/* Stop if at the end of the instance variables. */
|
6225 |
|
|
if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
|
6226 |
|
|
{
|
6227 |
|
|
c_parser_consume_token (parser);
|
6228 |
|
|
break;
|
6229 |
|
|
}
|
6230 |
|
|
/* Parse any objc-visibility-spec. */
|
6231 |
|
|
if (c_parser_next_token_is_keyword (parser, RID_PRIVATE))
|
6232 |
|
|
{
|
6233 |
|
|
c_parser_consume_token (parser);
|
6234 |
|
|
objc_set_visibility (2);
|
6235 |
|
|
continue;
|
6236 |
|
|
}
|
6237 |
|
|
else if (c_parser_next_token_is_keyword (parser, RID_PROTECTED))
|
6238 |
|
|
{
|
6239 |
|
|
c_parser_consume_token (parser);
|
6240 |
|
|
objc_set_visibility (0);
|
6241 |
|
|
continue;
|
6242 |
|
|
}
|
6243 |
|
|
else if (c_parser_next_token_is_keyword (parser, RID_PUBLIC))
|
6244 |
|
|
{
|
6245 |
|
|
c_parser_consume_token (parser);
|
6246 |
|
|
objc_set_visibility (1);
|
6247 |
|
|
continue;
|
6248 |
|
|
}
|
6249 |
|
|
else if (c_parser_next_token_is (parser, CPP_PRAGMA))
|
6250 |
|
|
{
|
6251 |
|
|
c_parser_pragma (parser, pragma_external);
|
6252 |
|
|
continue;
|
6253 |
|
|
}
|
6254 |
|
|
|
6255 |
|
|
/* Parse some comma-separated declarations. */
|
6256 |
|
|
decls = c_parser_struct_declaration (parser);
|
6257 |
|
|
{
|
6258 |
|
|
/* Comma-separated instance variables are chained together in
|
6259 |
|
|
reverse order; add them one by one. */
|
6260 |
|
|
tree ivar = nreverse (decls);
|
6261 |
|
|
for (; ivar; ivar = TREE_CHAIN (ivar))
|
6262 |
|
|
objc_add_instance_variable (copy_node (ivar));
|
6263 |
|
|
}
|
6264 |
|
|
c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
|
6265 |
|
|
}
|
6266 |
|
|
}
|
6267 |
|
|
|
6268 |
|
|
/* Parse an objc-class-declaration.
|
6269 |
|
|
|
6270 |
|
|
objc-class-declaration:
|
6271 |
|
|
@class identifier-list ;
|
6272 |
|
|
*/
|
6273 |
|
|
|
6274 |
|
|
static void
|
6275 |
|
|
c_parser_objc_class_declaration (c_parser *parser)
|
6276 |
|
|
{
|
6277 |
|
|
tree list = NULL_TREE;
|
6278 |
|
|
gcc_assert (c_parser_next_token_is_keyword (parser, RID_CLASS));
|
6279 |
|
|
c_parser_consume_token (parser);
|
6280 |
|
|
/* Any identifiers, including those declared as type names, are OK
|
6281 |
|
|
here. */
|
6282 |
|
|
while (true)
|
6283 |
|
|
{
|
6284 |
|
|
tree id;
|
6285 |
|
|
if (c_parser_next_token_is_not (parser, CPP_NAME))
|
6286 |
|
|
{
|
6287 |
|
|
c_parser_error (parser, "expected identifier");
|
6288 |
|
|
break;
|
6289 |
|
|
}
|
6290 |
|
|
id = c_parser_peek_token (parser)->value;
|
6291 |
|
|
list = chainon (list, build_tree_list (NULL_TREE, id));
|
6292 |
|
|
c_parser_consume_token (parser);
|
6293 |
|
|
if (c_parser_next_token_is (parser, CPP_COMMA))
|
6294 |
|
|
c_parser_consume_token (parser);
|
6295 |
|
|
else
|
6296 |
|
|
break;
|
6297 |
|
|
}
|
6298 |
|
|
c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
|
6299 |
|
|
objc_declare_class (list);
|
6300 |
|
|
}
|
6301 |
|
|
|
6302 |
|
|
/* Parse an objc-alias-declaration.
|
6303 |
|
|
|
6304 |
|
|
objc-alias-declaration:
|
6305 |
|
|
@compatibility_alias identifier identifier ;
|
6306 |
|
|
*/
|
6307 |
|
|
|
6308 |
|
|
static void
|
6309 |
|
|
c_parser_objc_alias_declaration (c_parser *parser)
|
6310 |
|
|
{
|
6311 |
|
|
tree id1, id2;
|
6312 |
|
|
gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_ALIAS));
|
6313 |
|
|
c_parser_consume_token (parser);
|
6314 |
|
|
if (c_parser_next_token_is_not (parser, CPP_NAME))
|
6315 |
|
|
{
|
6316 |
|
|
c_parser_error (parser, "expected identifier");
|
6317 |
|
|
c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
|
6318 |
|
|
return;
|
6319 |
|
|
}
|
6320 |
|
|
id1 = c_parser_peek_token (parser)->value;
|
6321 |
|
|
c_parser_consume_token (parser);
|
6322 |
|
|
if (c_parser_next_token_is_not (parser, CPP_NAME))
|
6323 |
|
|
{
|
6324 |
|
|
c_parser_error (parser, "expected identifier");
|
6325 |
|
|
c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
|
6326 |
|
|
return;
|
6327 |
|
|
}
|
6328 |
|
|
id2 = c_parser_peek_token (parser)->value;
|
6329 |
|
|
c_parser_consume_token (parser);
|
6330 |
|
|
c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
|
6331 |
|
|
objc_declare_alias (id1, id2);
|
6332 |
|
|
}
|
6333 |
|
|
|
6334 |
|
|
/* Parse an objc-protocol-definition.
|
6335 |
|
|
|
6336 |
|
|
objc-protocol-definition:
|
6337 |
|
|
@protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
|
6338 |
|
|
@protocol identifier-list ;
|
6339 |
|
|
|
6340 |
|
|
"@protocol identifier ;" should be resolved as "@protocol
|
6341 |
|
|
identifier-list ;": objc-methodprotolist may not start with a
|
6342 |
|
|
semicolon in the first alternative if objc-protocol-refs are
|
6343 |
|
|
omitted. */
|
6344 |
|
|
|
6345 |
|
|
static void
|
6346 |
|
|
c_parser_objc_protocol_definition (c_parser *parser)
|
6347 |
|
|
{
|
6348 |
|
|
gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_PROTOCOL));
|
6349 |
|
|
c_parser_consume_token (parser);
|
6350 |
|
|
if (c_parser_next_token_is_not (parser, CPP_NAME))
|
6351 |
|
|
{
|
6352 |
|
|
c_parser_error (parser, "expected identifier");
|
6353 |
|
|
return;
|
6354 |
|
|
}
|
6355 |
|
|
if (c_parser_peek_2nd_token (parser)->type == CPP_COMMA
|
6356 |
|
|
|| c_parser_peek_2nd_token (parser)->type == CPP_SEMICOLON)
|
6357 |
|
|
{
|
6358 |
|
|
tree list = NULL_TREE;
|
6359 |
|
|
/* Any identifiers, including those declared as type names, are
|
6360 |
|
|
OK here. */
|
6361 |
|
|
while (true)
|
6362 |
|
|
{
|
6363 |
|
|
tree id;
|
6364 |
|
|
if (c_parser_next_token_is_not (parser, CPP_NAME))
|
6365 |
|
|
{
|
6366 |
|
|
c_parser_error (parser, "expected identifier");
|
6367 |
|
|
break;
|
6368 |
|
|
}
|
6369 |
|
|
id = c_parser_peek_token (parser)->value;
|
6370 |
|
|
list = chainon (list, build_tree_list (NULL_TREE, id));
|
6371 |
|
|
c_parser_consume_token (parser);
|
6372 |
|
|
if (c_parser_next_token_is (parser, CPP_COMMA))
|
6373 |
|
|
c_parser_consume_token (parser);
|
6374 |
|
|
else
|
6375 |
|
|
break;
|
6376 |
|
|
}
|
6377 |
|
|
c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
|
6378 |
|
|
objc_declare_protocols (list);
|
6379 |
|
|
}
|
6380 |
|
|
else
|
6381 |
|
|
{
|
6382 |
|
|
tree id = c_parser_peek_token (parser)->value;
|
6383 |
|
|
tree proto = NULL_TREE;
|
6384 |
|
|
c_parser_consume_token (parser);
|
6385 |
|
|
if (c_parser_next_token_is (parser, CPP_LESS))
|
6386 |
|
|
proto = c_parser_objc_protocol_refs (parser);
|
6387 |
|
|
parser->objc_pq_context = true;
|
6388 |
|
|
objc_start_protocol (id, proto);
|
6389 |
|
|
c_parser_objc_methodprotolist (parser);
|
6390 |
|
|
c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
|
6391 |
|
|
parser->objc_pq_context = false;
|
6392 |
|
|
objc_finish_interface ();
|
6393 |
|
|
}
|
6394 |
|
|
}
|
6395 |
|
|
|
6396 |
|
|
/* Parse an objc-method-type.
|
6397 |
|
|
|
6398 |
|
|
objc-method-type:
|
6399 |
|
|
+
|
6400 |
|
|
-
|
6401 |
|
|
*/
|
6402 |
|
|
|
6403 |
|
|
static enum tree_code
|
6404 |
|
|
c_parser_objc_method_type (c_parser *parser)
|
6405 |
|
|
{
|
6406 |
|
|
switch (c_parser_peek_token (parser)->type)
|
6407 |
|
|
{
|
6408 |
|
|
case CPP_PLUS:
|
6409 |
|
|
c_parser_consume_token (parser);
|
6410 |
|
|
return PLUS_EXPR;
|
6411 |
|
|
case CPP_MINUS:
|
6412 |
|
|
c_parser_consume_token (parser);
|
6413 |
|
|
return MINUS_EXPR;
|
6414 |
|
|
default:
|
6415 |
|
|
gcc_unreachable ();
|
6416 |
|
|
}
|
6417 |
|
|
}
|
6418 |
|
|
|
6419 |
|
|
/* Parse an objc-method-definition.
|
6420 |
|
|
|
6421 |
|
|
objc-method-definition:
|
6422 |
|
|
objc-method-type objc-method-decl ;[opt] compound-statement
|
6423 |
|
|
*/
|
6424 |
|
|
|
6425 |
|
|
static void
|
6426 |
|
|
c_parser_objc_method_definition (c_parser *parser)
|
6427 |
|
|
{
|
6428 |
|
|
enum tree_code type = c_parser_objc_method_type (parser);
|
6429 |
|
|
tree decl;
|
6430 |
|
|
objc_set_method_type (type);
|
6431 |
|
|
parser->objc_pq_context = true;
|
6432 |
|
|
decl = c_parser_objc_method_decl (parser);
|
6433 |
|
|
if (c_parser_next_token_is (parser, CPP_SEMICOLON))
|
6434 |
|
|
{
|
6435 |
|
|
c_parser_consume_token (parser);
|
6436 |
|
|
pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
|
6437 |
|
|
"extra semicolon in method definition specified");
|
6438 |
|
|
}
|
6439 |
|
|
if (!c_parser_next_token_is (parser, CPP_OPEN_BRACE))
|
6440 |
|
|
{
|
6441 |
|
|
c_parser_error (parser, "expected %<{%>");
|
6442 |
|
|
return;
|
6443 |
|
|
}
|
6444 |
|
|
parser->objc_pq_context = false;
|
6445 |
|
|
objc_start_method_definition (decl);
|
6446 |
|
|
add_stmt (c_parser_compound_statement (parser));
|
6447 |
|
|
objc_finish_method_definition (current_function_decl);
|
6448 |
|
|
}
|
6449 |
|
|
|
6450 |
|
|
/* Parse an objc-methodprotolist.
|
6451 |
|
|
|
6452 |
|
|
objc-methodprotolist:
|
6453 |
|
|
empty
|
6454 |
|
|
objc-methodprotolist objc-methodproto
|
6455 |
|
|
objc-methodprotolist declaration
|
6456 |
|
|
objc-methodprotolist ;
|
6457 |
|
|
|
6458 |
|
|
The declaration is a data definition, which may be missing
|
6459 |
|
|
declaration specifiers under the same rules and diagnostics as
|
6460 |
|
|
other data definitions outside functions, and the stray semicolon
|
6461 |
|
|
is diagnosed the same way as a stray semicolon outside a
|
6462 |
|
|
function. */
|
6463 |
|
|
|
6464 |
|
|
static void
|
6465 |
|
|
c_parser_objc_methodprotolist (c_parser *parser)
|
6466 |
|
|
{
|
6467 |
|
|
while (true)
|
6468 |
|
|
{
|
6469 |
|
|
/* The list is terminated by @end. */
|
6470 |
|
|
switch (c_parser_peek_token (parser)->type)
|
6471 |
|
|
{
|
6472 |
|
|
case CPP_SEMICOLON:
|
6473 |
|
|
pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
|
6474 |
|
|
"ISO C does not allow extra %<;%> outside of a function");
|
6475 |
|
|
c_parser_consume_token (parser);
|
6476 |
|
|
break;
|
6477 |
|
|
case CPP_PLUS:
|
6478 |
|
|
case CPP_MINUS:
|
6479 |
|
|
c_parser_objc_methodproto (parser);
|
6480 |
|
|
break;
|
6481 |
|
|
case CPP_PRAGMA:
|
6482 |
|
|
c_parser_pragma (parser, pragma_external);
|
6483 |
|
|
break;
|
6484 |
|
|
case CPP_EOF:
|
6485 |
|
|
return;
|
6486 |
|
|
default:
|
6487 |
|
|
if (c_parser_next_token_is_keyword (parser, RID_AT_END))
|
6488 |
|
|
return;
|
6489 |
|
|
c_parser_declaration_or_fndef (parser, false, true, false, true);
|
6490 |
|
|
break;
|
6491 |
|
|
}
|
6492 |
|
|
}
|
6493 |
|
|
}
|
6494 |
|
|
|
6495 |
|
|
/* Parse an objc-methodproto.
|
6496 |
|
|
|
6497 |
|
|
objc-methodproto:
|
6498 |
|
|
objc-method-type objc-method-decl ;
|
6499 |
|
|
*/
|
6500 |
|
|
|
6501 |
|
|
static void
|
6502 |
|
|
c_parser_objc_methodproto (c_parser *parser)
|
6503 |
|
|
{
|
6504 |
|
|
enum tree_code type = c_parser_objc_method_type (parser);
|
6505 |
|
|
tree decl;
|
6506 |
|
|
objc_set_method_type (type);
|
6507 |
|
|
/* Remember protocol qualifiers in prototypes. */
|
6508 |
|
|
parser->objc_pq_context = true;
|
6509 |
|
|
decl = c_parser_objc_method_decl (parser);
|
6510 |
|
|
/* Forget protocol qualifiers here. */
|
6511 |
|
|
parser->objc_pq_context = false;
|
6512 |
|
|
objc_add_method_declaration (decl);
|
6513 |
|
|
c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
|
6514 |
|
|
}
|
6515 |
|
|
|
6516 |
|
|
/* Parse an objc-method-decl.
|
6517 |
|
|
|
6518 |
|
|
objc-method-decl:
|
6519 |
|
|
( objc-type-name ) objc-selector
|
6520 |
|
|
objc-selector
|
6521 |
|
|
( objc-type-name ) objc-keyword-selector objc-optparmlist
|
6522 |
|
|
objc-keyword-selector objc-optparmlist
|
6523 |
|
|
|
6524 |
|
|
objc-keyword-selector:
|
6525 |
|
|
objc-keyword-decl
|
6526 |
|
|
objc-keyword-selector objc-keyword-decl
|
6527 |
|
|
|
6528 |
|
|
objc-keyword-decl:
|
6529 |
|
|
objc-selector : ( objc-type-name ) identifier
|
6530 |
|
|
objc-selector : identifier
|
6531 |
|
|
: ( objc-type-name ) identifier
|
6532 |
|
|
: identifier
|
6533 |
|
|
|
6534 |
|
|
objc-optparmlist:
|
6535 |
|
|
objc-optparms objc-optellipsis
|
6536 |
|
|
|
6537 |
|
|
objc-optparms:
|
6538 |
|
|
empty
|
6539 |
|
|
objc-opt-parms , parameter-declaration
|
6540 |
|
|
|
6541 |
|
|
objc-optellipsis:
|
6542 |
|
|
empty
|
6543 |
|
|
, ...
|
6544 |
|
|
*/
|
6545 |
|
|
|
6546 |
|
|
static tree
|
6547 |
|
|
c_parser_objc_method_decl (c_parser *parser)
|
6548 |
|
|
{
|
6549 |
|
|
tree type = NULL_TREE;
|
6550 |
|
|
tree sel;
|
6551 |
|
|
tree parms = NULL_TREE;
|
6552 |
|
|
bool ellipsis = false;
|
6553 |
|
|
|
6554 |
|
|
if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
|
6555 |
|
|
{
|
6556 |
|
|
c_parser_consume_token (parser);
|
6557 |
|
|
type = c_parser_objc_type_name (parser);
|
6558 |
|
|
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
|
6559 |
|
|
}
|
6560 |
|
|
sel = c_parser_objc_selector (parser);
|
6561 |
|
|
/* If there is no selector, or a colon follows, we have an
|
6562 |
|
|
objc-keyword-selector. If there is a selector, and a colon does
|
6563 |
|
|
not follow, that selector ends the objc-method-decl. */
|
6564 |
|
|
if (!sel || c_parser_next_token_is (parser, CPP_COLON))
|
6565 |
|
|
{
|
6566 |
|
|
tree tsel = sel;
|
6567 |
|
|
tree list = NULL_TREE;
|
6568 |
|
|
while (true)
|
6569 |
|
|
{
|
6570 |
|
|
tree atype = NULL_TREE, id, keyworddecl;
|
6571 |
|
|
if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
|
6572 |
|
|
break;
|
6573 |
|
|
if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
|
6574 |
|
|
{
|
6575 |
|
|
c_parser_consume_token (parser);
|
6576 |
|
|
atype = c_parser_objc_type_name (parser);
|
6577 |
|
|
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
|
6578 |
|
|
"expected %<)%>");
|
6579 |
|
|
}
|
6580 |
|
|
if (c_parser_next_token_is_not (parser, CPP_NAME))
|
6581 |
|
|
{
|
6582 |
|
|
c_parser_error (parser, "expected identifier");
|
6583 |
|
|
return error_mark_node;
|
6584 |
|
|
}
|
6585 |
|
|
id = c_parser_peek_token (parser)->value;
|
6586 |
|
|
c_parser_consume_token (parser);
|
6587 |
|
|
keyworddecl = objc_build_keyword_decl (tsel, atype, id);
|
6588 |
|
|
list = chainon (list, keyworddecl);
|
6589 |
|
|
tsel = c_parser_objc_selector (parser);
|
6590 |
|
|
if (!tsel && c_parser_next_token_is_not (parser, CPP_COLON))
|
6591 |
|
|
break;
|
6592 |
|
|
}
|
6593 |
|
|
/* Parse the optional parameter list. Optional Objective-C
|
6594 |
|
|
method parameters follow the C syntax, and may include '...'
|
6595 |
|
|
to denote a variable number of arguments. */
|
6596 |
|
|
parms = make_node (TREE_LIST);
|
6597 |
|
|
while (c_parser_next_token_is (parser, CPP_COMMA))
|
6598 |
|
|
{
|
6599 |
|
|
struct c_parm *parm;
|
6600 |
|
|
c_parser_consume_token (parser);
|
6601 |
|
|
if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
|
6602 |
|
|
{
|
6603 |
|
|
ellipsis = true;
|
6604 |
|
|
c_parser_consume_token (parser);
|
6605 |
|
|
break;
|
6606 |
|
|
}
|
6607 |
|
|
parm = c_parser_parameter_declaration (parser, NULL_TREE);
|
6608 |
|
|
if (parm == NULL)
|
6609 |
|
|
break;
|
6610 |
|
|
parms = chainon (parms,
|
6611 |
|
|
build_tree_list (NULL_TREE, grokparm (parm)));
|
6612 |
|
|
}
|
6613 |
|
|
sel = list;
|
6614 |
|
|
}
|
6615 |
|
|
return objc_build_method_signature (type, sel, parms, ellipsis);
|
6616 |
|
|
}
|
6617 |
|
|
|
6618 |
|
|
/* Parse an objc-type-name.
|
6619 |
|
|
|
6620 |
|
|
objc-type-name:
|
6621 |
|
|
objc-type-qualifiers[opt] type-name
|
6622 |
|
|
objc-type-qualifiers[opt]
|
6623 |
|
|
|
6624 |
|
|
objc-type-qualifiers:
|
6625 |
|
|
objc-type-qualifier
|
6626 |
|
|
objc-type-qualifiers objc-type-qualifier
|
6627 |
|
|
|
6628 |
|
|
objc-type-qualifier: one of
|
6629 |
|
|
in out inout bycopy byref oneway
|
6630 |
|
|
*/
|
6631 |
|
|
|
6632 |
|
|
static tree
|
6633 |
|
|
c_parser_objc_type_name (c_parser *parser)
|
6634 |
|
|
{
|
6635 |
|
|
tree quals = NULL_TREE;
|
6636 |
|
|
struct c_type_name *type_name = NULL;
|
6637 |
|
|
tree type = NULL_TREE;
|
6638 |
|
|
while (true)
|
6639 |
|
|
{
|
6640 |
|
|
c_token *token = c_parser_peek_token (parser);
|
6641 |
|
|
if (token->type == CPP_KEYWORD
|
6642 |
|
|
&& (token->keyword == RID_IN
|
6643 |
|
|
|| token->keyword == RID_OUT
|
6644 |
|
|
|| token->keyword == RID_INOUT
|
6645 |
|
|
|| token->keyword == RID_BYCOPY
|
6646 |
|
|
|| token->keyword == RID_BYREF
|
6647 |
|
|
|| token->keyword == RID_ONEWAY))
|
6648 |
|
|
{
|
6649 |
|
|
quals = chainon (quals, build_tree_list (NULL_TREE, token->value));
|
6650 |
|
|
c_parser_consume_token (parser);
|
6651 |
|
|
}
|
6652 |
|
|
else
|
6653 |
|
|
break;
|
6654 |
|
|
}
|
6655 |
|
|
if (c_parser_next_token_starts_typename (parser))
|
6656 |
|
|
type_name = c_parser_type_name (parser);
|
6657 |
|
|
if (type_name)
|
6658 |
|
|
type = groktypename (type_name, NULL, NULL);
|
6659 |
|
|
return build_tree_list (quals, type);
|
6660 |
|
|
}
|
6661 |
|
|
|
6662 |
|
|
/* Parse objc-protocol-refs.
|
6663 |
|
|
|
6664 |
|
|
objc-protocol-refs:
|
6665 |
|
|
< identifier-list >
|
6666 |
|
|
*/
|
6667 |
|
|
|
6668 |
|
|
static tree
|
6669 |
|
|
c_parser_objc_protocol_refs (c_parser *parser)
|
6670 |
|
|
{
|
6671 |
|
|
tree list = NULL_TREE;
|
6672 |
|
|
gcc_assert (c_parser_next_token_is (parser, CPP_LESS));
|
6673 |
|
|
c_parser_consume_token (parser);
|
6674 |
|
|
/* Any identifiers, including those declared as type names, are OK
|
6675 |
|
|
here. */
|
6676 |
|
|
while (true)
|
6677 |
|
|
{
|
6678 |
|
|
tree id;
|
6679 |
|
|
if (c_parser_next_token_is_not (parser, CPP_NAME))
|
6680 |
|
|
{
|
6681 |
|
|
c_parser_error (parser, "expected identifier");
|
6682 |
|
|
break;
|
6683 |
|
|
}
|
6684 |
|
|
id = c_parser_peek_token (parser)->value;
|
6685 |
|
|
list = chainon (list, build_tree_list (NULL_TREE, id));
|
6686 |
|
|
c_parser_consume_token (parser);
|
6687 |
|
|
if (c_parser_next_token_is (parser, CPP_COMMA))
|
6688 |
|
|
c_parser_consume_token (parser);
|
6689 |
|
|
else
|
6690 |
|
|
break;
|
6691 |
|
|
}
|
6692 |
|
|
c_parser_require (parser, CPP_GREATER, "expected %<>%>");
|
6693 |
|
|
return list;
|
6694 |
|
|
}
|
6695 |
|
|
|
6696 |
|
|
/* Parse an objc-try-catch-statement.
|
6697 |
|
|
|
6698 |
|
|
objc-try-catch-statement:
|
6699 |
|
|
@try compound-statement objc-catch-list[opt]
|
6700 |
|
|
@try compound-statement objc-catch-list[opt] @finally compound-statement
|
6701 |
|
|
|
6702 |
|
|
objc-catch-list:
|
6703 |
|
|
@catch ( parameter-declaration ) compound-statement
|
6704 |
|
|
objc-catch-list @catch ( parameter-declaration ) compound-statement
|
6705 |
|
|
*/
|
6706 |
|
|
|
6707 |
|
|
static void
|
6708 |
|
|
c_parser_objc_try_catch_statement (c_parser *parser)
|
6709 |
|
|
{
|
6710 |
|
|
location_t loc;
|
6711 |
|
|
tree stmt;
|
6712 |
|
|
gcc_assert (c_parser_next_token_is_keyword (parser, RID_TRY));
|
6713 |
|
|
c_parser_consume_token (parser);
|
6714 |
|
|
loc = c_parser_peek_token (parser)->location;
|
6715 |
|
|
stmt = c_parser_compound_statement (parser);
|
6716 |
|
|
objc_begin_try_stmt (loc, stmt);
|
6717 |
|
|
while (c_parser_next_token_is_keyword (parser, RID_CATCH))
|
6718 |
|
|
{
|
6719 |
|
|
struct c_parm *parm;
|
6720 |
|
|
c_parser_consume_token (parser);
|
6721 |
|
|
if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
|
6722 |
|
|
break;
|
6723 |
|
|
parm = c_parser_parameter_declaration (parser, NULL_TREE);
|
6724 |
|
|
if (parm == NULL)
|
6725 |
|
|
{
|
6726 |
|
|
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
|
6727 |
|
|
break;
|
6728 |
|
|
}
|
6729 |
|
|
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
|
6730 |
|
|
objc_begin_catch_clause (grokparm (parm));
|
6731 |
|
|
if (c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
|
6732 |
|
|
c_parser_compound_statement_nostart (parser);
|
6733 |
|
|
objc_finish_catch_clause ();
|
6734 |
|
|
}
|
6735 |
|
|
if (c_parser_next_token_is_keyword (parser, RID_AT_FINALLY))
|
6736 |
|
|
{
|
6737 |
|
|
location_t finloc;
|
6738 |
|
|
tree finstmt;
|
6739 |
|
|
c_parser_consume_token (parser);
|
6740 |
|
|
finloc = c_parser_peek_token (parser)->location;
|
6741 |
|
|
finstmt = c_parser_compound_statement (parser);
|
6742 |
|
|
objc_build_finally_clause (finloc, finstmt);
|
6743 |
|
|
}
|
6744 |
|
|
objc_finish_try_stmt ();
|
6745 |
|
|
}
|
6746 |
|
|
|
6747 |
|
|
/* Parse an objc-synchronized-statement.
|
6748 |
|
|
|
6749 |
|
|
objc-synchronized-statement:
|
6750 |
|
|
@synchronized ( expression ) compound-statement
|
6751 |
|
|
*/
|
6752 |
|
|
|
6753 |
|
|
static void
|
6754 |
|
|
c_parser_objc_synchronized_statement (c_parser *parser)
|
6755 |
|
|
{
|
6756 |
|
|
location_t loc;
|
6757 |
|
|
tree expr, stmt;
|
6758 |
|
|
gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_SYNCHRONIZED));
|
6759 |
|
|
c_parser_consume_token (parser);
|
6760 |
|
|
loc = c_parser_peek_token (parser)->location;
|
6761 |
|
|
if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
|
6762 |
|
|
{
|
6763 |
|
|
expr = c_parser_expression (parser).value;
|
6764 |
|
|
expr = c_fully_fold (expr, false, NULL);
|
6765 |
|
|
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
|
6766 |
|
|
}
|
6767 |
|
|
else
|
6768 |
|
|
expr = error_mark_node;
|
6769 |
|
|
stmt = c_parser_compound_statement (parser);
|
6770 |
|
|
objc_build_synchronized (loc, expr, stmt);
|
6771 |
|
|
}
|
6772 |
|
|
|
6773 |
|
|
/* Parse an objc-selector; return NULL_TREE without an error if the
|
6774 |
|
|
next token is not an objc-selector.
|
6775 |
|
|
|
6776 |
|
|
objc-selector:
|
6777 |
|
|
identifier
|
6778 |
|
|
one of
|
6779 |
|
|
enum struct union if else while do for switch case default
|
6780 |
|
|
break continue return goto asm sizeof typeof __alignof
|
6781 |
|
|
unsigned long const short volatile signed restrict _Complex
|
6782 |
|
|
in out inout bycopy byref oneway int char float double void _Bool
|
6783 |
|
|
|
6784 |
|
|
??? Why this selection of keywords but not, for example, storage
|
6785 |
|
|
class specifiers? */
|
6786 |
|
|
|
6787 |
|
|
static tree
|
6788 |
|
|
c_parser_objc_selector (c_parser *parser)
|
6789 |
|
|
{
|
6790 |
|
|
c_token *token = c_parser_peek_token (parser);
|
6791 |
|
|
tree value = token->value;
|
6792 |
|
|
if (token->type == CPP_NAME)
|
6793 |
|
|
{
|
6794 |
|
|
c_parser_consume_token (parser);
|
6795 |
|
|
return value;
|
6796 |
|
|
}
|
6797 |
|
|
if (token->type != CPP_KEYWORD)
|
6798 |
|
|
return NULL_TREE;
|
6799 |
|
|
switch (token->keyword)
|
6800 |
|
|
{
|
6801 |
|
|
case RID_ENUM:
|
6802 |
|
|
case RID_STRUCT:
|
6803 |
|
|
case RID_UNION:
|
6804 |
|
|
case RID_IF:
|
6805 |
|
|
case RID_ELSE:
|
6806 |
|
|
case RID_WHILE:
|
6807 |
|
|
case RID_DO:
|
6808 |
|
|
case RID_FOR:
|
6809 |
|
|
case RID_SWITCH:
|
6810 |
|
|
case RID_CASE:
|
6811 |
|
|
case RID_DEFAULT:
|
6812 |
|
|
case RID_BREAK:
|
6813 |
|
|
case RID_CONTINUE:
|
6814 |
|
|
case RID_RETURN:
|
6815 |
|
|
case RID_GOTO:
|
6816 |
|
|
case RID_ASM:
|
6817 |
|
|
case RID_SIZEOF:
|
6818 |
|
|
case RID_TYPEOF:
|
6819 |
|
|
case RID_ALIGNOF:
|
6820 |
|
|
case RID_UNSIGNED:
|
6821 |
|
|
case RID_LONG:
|
6822 |
|
|
case RID_CONST:
|
6823 |
|
|
case RID_SHORT:
|
6824 |
|
|
case RID_VOLATILE:
|
6825 |
|
|
case RID_SIGNED:
|
6826 |
|
|
case RID_RESTRICT:
|
6827 |
|
|
case RID_COMPLEX:
|
6828 |
|
|
case RID_IN:
|
6829 |
|
|
case RID_OUT:
|
6830 |
|
|
case RID_INOUT:
|
6831 |
|
|
case RID_BYCOPY:
|
6832 |
|
|
case RID_BYREF:
|
6833 |
|
|
case RID_ONEWAY:
|
6834 |
|
|
case RID_INT:
|
6835 |
|
|
case RID_CHAR:
|
6836 |
|
|
case RID_FLOAT:
|
6837 |
|
|
case RID_DOUBLE:
|
6838 |
|
|
case RID_VOID:
|
6839 |
|
|
case RID_BOOL:
|
6840 |
|
|
c_parser_consume_token (parser);
|
6841 |
|
|
return value;
|
6842 |
|
|
default:
|
6843 |
|
|
return NULL_TREE;
|
6844 |
|
|
}
|
6845 |
|
|
}
|
6846 |
|
|
|
6847 |
|
|
/* Parse an objc-selector-arg.
|
6848 |
|
|
|
6849 |
|
|
objc-selector-arg:
|
6850 |
|
|
objc-selector
|
6851 |
|
|
objc-keywordname-list
|
6852 |
|
|
|
6853 |
|
|
objc-keywordname-list:
|
6854 |
|
|
objc-keywordname
|
6855 |
|
|
objc-keywordname-list objc-keywordname
|
6856 |
|
|
|
6857 |
|
|
objc-keywordname:
|
6858 |
|
|
objc-selector :
|
6859 |
|
|
:
|
6860 |
|
|
*/
|
6861 |
|
|
|
6862 |
|
|
static tree
|
6863 |
|
|
c_parser_objc_selector_arg (c_parser *parser)
|
6864 |
|
|
{
|
6865 |
|
|
tree sel = c_parser_objc_selector (parser);
|
6866 |
|
|
tree list = NULL_TREE;
|
6867 |
|
|
if (sel && c_parser_next_token_is_not (parser, CPP_COLON))
|
6868 |
|
|
return sel;
|
6869 |
|
|
while (true)
|
6870 |
|
|
{
|
6871 |
|
|
if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
|
6872 |
|
|
return list;
|
6873 |
|
|
list = chainon (list, build_tree_list (sel, NULL_TREE));
|
6874 |
|
|
sel = c_parser_objc_selector (parser);
|
6875 |
|
|
if (!sel && c_parser_next_token_is_not (parser, CPP_COLON))
|
6876 |
|
|
break;
|
6877 |
|
|
}
|
6878 |
|
|
return list;
|
6879 |
|
|
}
|
6880 |
|
|
|
6881 |
|
|
/* Parse an objc-receiver.
|
6882 |
|
|
|
6883 |
|
|
objc-receiver:
|
6884 |
|
|
expression
|
6885 |
|
|
class-name
|
6886 |
|
|
type-name
|
6887 |
|
|
*/
|
6888 |
|
|
|
6889 |
|
|
static tree
|
6890 |
|
|
c_parser_objc_receiver (c_parser *parser)
|
6891 |
|
|
{
|
6892 |
|
|
if (c_parser_peek_token (parser)->type == CPP_NAME
|
6893 |
|
|
&& (c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME
|
6894 |
|
|
|| c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME))
|
6895 |
|
|
{
|
6896 |
|
|
tree id = c_parser_peek_token (parser)->value;
|
6897 |
|
|
c_parser_consume_token (parser);
|
6898 |
|
|
return objc_get_class_reference (id);
|
6899 |
|
|
}
|
6900 |
|
|
return c_fully_fold (c_parser_expression (parser).value, false, NULL);
|
6901 |
|
|
}
|
6902 |
|
|
|
6903 |
|
|
/* Parse objc-message-args.
|
6904 |
|
|
|
6905 |
|
|
objc-message-args:
|
6906 |
|
|
objc-selector
|
6907 |
|
|
objc-keywordarg-list
|
6908 |
|
|
|
6909 |
|
|
objc-keywordarg-list:
|
6910 |
|
|
objc-keywordarg
|
6911 |
|
|
objc-keywordarg-list objc-keywordarg
|
6912 |
|
|
|
6913 |
|
|
objc-keywordarg:
|
6914 |
|
|
objc-selector : objc-keywordexpr
|
6915 |
|
|
: objc-keywordexpr
|
6916 |
|
|
*/
|
6917 |
|
|
|
6918 |
|
|
static tree
|
6919 |
|
|
c_parser_objc_message_args (c_parser *parser)
|
6920 |
|
|
{
|
6921 |
|
|
tree sel = c_parser_objc_selector (parser);
|
6922 |
|
|
tree list = NULL_TREE;
|
6923 |
|
|
if (sel && c_parser_next_token_is_not (parser, CPP_COLON))
|
6924 |
|
|
return sel;
|
6925 |
|
|
while (true)
|
6926 |
|
|
{
|
6927 |
|
|
tree keywordexpr;
|
6928 |
|
|
if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
|
6929 |
|
|
return error_mark_node;
|
6930 |
|
|
keywordexpr = c_parser_objc_keywordexpr (parser);
|
6931 |
|
|
list = chainon (list, build_tree_list (sel, keywordexpr));
|
6932 |
|
|
sel = c_parser_objc_selector (parser);
|
6933 |
|
|
if (!sel && c_parser_next_token_is_not (parser, CPP_COLON))
|
6934 |
|
|
break;
|
6935 |
|
|
}
|
6936 |
|
|
return list;
|
6937 |
|
|
}
|
6938 |
|
|
|
6939 |
|
|
/* Parse an objc-keywordexpr.
|
6940 |
|
|
|
6941 |
|
|
objc-keywordexpr:
|
6942 |
|
|
nonempty-expr-list
|
6943 |
|
|
*/
|
6944 |
|
|
|
6945 |
|
|
static tree
|
6946 |
|
|
c_parser_objc_keywordexpr (c_parser *parser)
|
6947 |
|
|
{
|
6948 |
|
|
tree ret;
|
6949 |
|
|
VEC(tree,gc) *expr_list = c_parser_expr_list (parser, true, true, NULL);
|
6950 |
|
|
if (VEC_length (tree, expr_list) == 1)
|
6951 |
|
|
{
|
6952 |
|
|
/* Just return the expression, remove a level of
|
6953 |
|
|
indirection. */
|
6954 |
|
|
ret = VEC_index (tree, expr_list, 0);
|
6955 |
|
|
}
|
6956 |
|
|
else
|
6957 |
|
|
{
|
6958 |
|
|
/* We have a comma expression, we will collapse later. */
|
6959 |
|
|
ret = build_tree_list_vec (expr_list);
|
6960 |
|
|
}
|
6961 |
|
|
release_tree_vector (expr_list);
|
6962 |
|
|
return ret;
|
6963 |
|
|
}
|
6964 |
|
|
|
6965 |
|
|
|
6966 |
|
|
/* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
|
6967 |
|
|
should be considered, statements. ALLOW_STMT is true if we're within
|
6968 |
|
|
the context of a function and such pragmas are to be allowed. Returns
|
6969 |
|
|
true if we actually parsed such a pragma. */
|
6970 |
|
|
|
6971 |
|
|
static bool
|
6972 |
|
|
c_parser_pragma (c_parser *parser, enum pragma_context context)
|
6973 |
|
|
{
|
6974 |
|
|
unsigned int id;
|
6975 |
|
|
|
6976 |
|
|
id = c_parser_peek_token (parser)->pragma_kind;
|
6977 |
|
|
gcc_assert (id != PRAGMA_NONE);
|
6978 |
|
|
|
6979 |
|
|
switch (id)
|
6980 |
|
|
{
|
6981 |
|
|
case PRAGMA_OMP_BARRIER:
|
6982 |
|
|
if (context != pragma_compound)
|
6983 |
|
|
{
|
6984 |
|
|
if (context == pragma_stmt)
|
6985 |
|
|
c_parser_error (parser, "%<#pragma omp barrier%> may only be "
|
6986 |
|
|
"used in compound statements");
|
6987 |
|
|
goto bad_stmt;
|
6988 |
|
|
}
|
6989 |
|
|
c_parser_omp_barrier (parser);
|
6990 |
|
|
return false;
|
6991 |
|
|
|
6992 |
|
|
case PRAGMA_OMP_FLUSH:
|
6993 |
|
|
if (context != pragma_compound)
|
6994 |
|
|
{
|
6995 |
|
|
if (context == pragma_stmt)
|
6996 |
|
|
c_parser_error (parser, "%<#pragma omp flush%> may only be "
|
6997 |
|
|
"used in compound statements");
|
6998 |
|
|
goto bad_stmt;
|
6999 |
|
|
}
|
7000 |
|
|
c_parser_omp_flush (parser);
|
7001 |
|
|
return false;
|
7002 |
|
|
|
7003 |
|
|
case PRAGMA_OMP_TASKWAIT:
|
7004 |
|
|
if (context != pragma_compound)
|
7005 |
|
|
{
|
7006 |
|
|
if (context == pragma_stmt)
|
7007 |
|
|
c_parser_error (parser, "%<#pragma omp taskwait%> may only be "
|
7008 |
|
|
"used in compound statements");
|
7009 |
|
|
goto bad_stmt;
|
7010 |
|
|
}
|
7011 |
|
|
c_parser_omp_taskwait (parser);
|
7012 |
|
|
return false;
|
7013 |
|
|
|
7014 |
|
|
case PRAGMA_OMP_THREADPRIVATE:
|
7015 |
|
|
c_parser_omp_threadprivate (parser);
|
7016 |
|
|
return false;
|
7017 |
|
|
|
7018 |
|
|
case PRAGMA_OMP_SECTION:
|
7019 |
|
|
error_at (c_parser_peek_token (parser)->location,
|
7020 |
|
|
"%<#pragma omp section%> may only be used in "
|
7021 |
|
|
"%<#pragma omp sections%> construct");
|
7022 |
|
|
c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
|
7023 |
|
|
return false;
|
7024 |
|
|
|
7025 |
|
|
case PRAGMA_GCC_PCH_PREPROCESS:
|
7026 |
|
|
c_parser_error (parser, "%<#pragma GCC pch_preprocess%> must be first");
|
7027 |
|
|
c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
|
7028 |
|
|
return false;
|
7029 |
|
|
|
7030 |
|
|
default:
|
7031 |
|
|
if (id < PRAGMA_FIRST_EXTERNAL)
|
7032 |
|
|
{
|
7033 |
|
|
if (context == pragma_external)
|
7034 |
|
|
{
|
7035 |
|
|
bad_stmt:
|
7036 |
|
|
c_parser_error (parser, "expected declaration specifiers");
|
7037 |
|
|
c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
|
7038 |
|
|
return false;
|
7039 |
|
|
}
|
7040 |
|
|
c_parser_omp_construct (parser);
|
7041 |
|
|
return true;
|
7042 |
|
|
}
|
7043 |
|
|
break;
|
7044 |
|
|
}
|
7045 |
|
|
|
7046 |
|
|
c_parser_consume_pragma (parser);
|
7047 |
|
|
c_invoke_pragma_handler (id);
|
7048 |
|
|
|
7049 |
|
|
/* Skip to EOL, but suppress any error message. Those will have been
|
7050 |
|
|
generated by the handler routine through calling error, as opposed
|
7051 |
|
|
to calling c_parser_error. */
|
7052 |
|
|
parser->error = true;
|
7053 |
|
|
c_parser_skip_to_pragma_eol (parser);
|
7054 |
|
|
|
7055 |
|
|
return false;
|
7056 |
|
|
}
|
7057 |
|
|
|
7058 |
|
|
/* The interface the pragma parsers have to the lexer. */
|
7059 |
|
|
|
7060 |
|
|
enum cpp_ttype
|
7061 |
|
|
pragma_lex (tree *value)
|
7062 |
|
|
{
|
7063 |
|
|
c_token *tok = c_parser_peek_token (the_parser);
|
7064 |
|
|
enum cpp_ttype ret = tok->type;
|
7065 |
|
|
|
7066 |
|
|
*value = tok->value;
|
7067 |
|
|
if (ret == CPP_PRAGMA_EOL || ret == CPP_EOF)
|
7068 |
|
|
ret = CPP_EOF;
|
7069 |
|
|
else
|
7070 |
|
|
{
|
7071 |
|
|
if (ret == CPP_KEYWORD)
|
7072 |
|
|
ret = CPP_NAME;
|
7073 |
|
|
c_parser_consume_token (the_parser);
|
7074 |
|
|
}
|
7075 |
|
|
|
7076 |
|
|
return ret;
|
7077 |
|
|
}
|
7078 |
|
|
|
7079 |
|
|
static void
|
7080 |
|
|
c_parser_pragma_pch_preprocess (c_parser *parser)
|
7081 |
|
|
{
|
7082 |
|
|
tree name = NULL;
|
7083 |
|
|
|
7084 |
|
|
c_parser_consume_pragma (parser);
|
7085 |
|
|
if (c_parser_next_token_is (parser, CPP_STRING))
|
7086 |
|
|
{
|
7087 |
|
|
name = c_parser_peek_token (parser)->value;
|
7088 |
|
|
c_parser_consume_token (parser);
|
7089 |
|
|
}
|
7090 |
|
|
else
|
7091 |
|
|
c_parser_error (parser, "expected string literal");
|
7092 |
|
|
c_parser_skip_to_pragma_eol (parser);
|
7093 |
|
|
|
7094 |
|
|
if (name)
|
7095 |
|
|
c_common_pch_pragma (parse_in, TREE_STRING_POINTER (name));
|
7096 |
|
|
}
|
7097 |
|
|
|
7098 |
|
|
/* OpenMP 2.5 parsing routines. */
|
7099 |
|
|
|
7100 |
|
|
/* Returns name of the next clause.
|
7101 |
|
|
If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
|
7102 |
|
|
the token is not consumed. Otherwise appropriate pragma_omp_clause is
|
7103 |
|
|
returned and the token is consumed. */
|
7104 |
|
|
|
7105 |
|
|
static pragma_omp_clause
|
7106 |
|
|
c_parser_omp_clause_name (c_parser *parser)
|
7107 |
|
|
{
|
7108 |
|
|
pragma_omp_clause result = PRAGMA_OMP_CLAUSE_NONE;
|
7109 |
|
|
|
7110 |
|
|
if (c_parser_next_token_is_keyword (parser, RID_IF))
|
7111 |
|
|
result = PRAGMA_OMP_CLAUSE_IF;
|
7112 |
|
|
else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT))
|
7113 |
|
|
result = PRAGMA_OMP_CLAUSE_DEFAULT;
|
7114 |
|
|
else if (c_parser_next_token_is (parser, CPP_NAME))
|
7115 |
|
|
{
|
7116 |
|
|
const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
|
7117 |
|
|
|
7118 |
|
|
switch (p[0])
|
7119 |
|
|
{
|
7120 |
|
|
case 'c':
|
7121 |
|
|
if (!strcmp ("collapse", p))
|
7122 |
|
|
result = PRAGMA_OMP_CLAUSE_COLLAPSE;
|
7123 |
|
|
else if (!strcmp ("copyin", p))
|
7124 |
|
|
result = PRAGMA_OMP_CLAUSE_COPYIN;
|
7125 |
|
|
else if (!strcmp ("copyprivate", p))
|
7126 |
|
|
result = PRAGMA_OMP_CLAUSE_COPYPRIVATE;
|
7127 |
|
|
break;
|
7128 |
|
|
case 'f':
|
7129 |
|
|
if (!strcmp ("firstprivate", p))
|
7130 |
|
|
result = PRAGMA_OMP_CLAUSE_FIRSTPRIVATE;
|
7131 |
|
|
break;
|
7132 |
|
|
case 'l':
|
7133 |
|
|
if (!strcmp ("lastprivate", p))
|
7134 |
|
|
result = PRAGMA_OMP_CLAUSE_LASTPRIVATE;
|
7135 |
|
|
break;
|
7136 |
|
|
case 'n':
|
7137 |
|
|
if (!strcmp ("nowait", p))
|
7138 |
|
|
result = PRAGMA_OMP_CLAUSE_NOWAIT;
|
7139 |
|
|
else if (!strcmp ("num_threads", p))
|
7140 |
|
|
result = PRAGMA_OMP_CLAUSE_NUM_THREADS;
|
7141 |
|
|
break;
|
7142 |
|
|
case 'o':
|
7143 |
|
|
if (!strcmp ("ordered", p))
|
7144 |
|
|
result = PRAGMA_OMP_CLAUSE_ORDERED;
|
7145 |
|
|
break;
|
7146 |
|
|
case 'p':
|
7147 |
|
|
if (!strcmp ("private", p))
|
7148 |
|
|
result = PRAGMA_OMP_CLAUSE_PRIVATE;
|
7149 |
|
|
break;
|
7150 |
|
|
case 'r':
|
7151 |
|
|
if (!strcmp ("reduction", p))
|
7152 |
|
|
result = PRAGMA_OMP_CLAUSE_REDUCTION;
|
7153 |
|
|
break;
|
7154 |
|
|
case 's':
|
7155 |
|
|
if (!strcmp ("schedule", p))
|
7156 |
|
|
result = PRAGMA_OMP_CLAUSE_SCHEDULE;
|
7157 |
|
|
else if (!strcmp ("shared", p))
|
7158 |
|
|
result = PRAGMA_OMP_CLAUSE_SHARED;
|
7159 |
|
|
break;
|
7160 |
|
|
case 'u':
|
7161 |
|
|
if (!strcmp ("untied", p))
|
7162 |
|
|
result = PRAGMA_OMP_CLAUSE_UNTIED;
|
7163 |
|
|
break;
|
7164 |
|
|
}
|
7165 |
|
|
}
|
7166 |
|
|
|
7167 |
|
|
if (result != PRAGMA_OMP_CLAUSE_NONE)
|
7168 |
|
|
c_parser_consume_token (parser);
|
7169 |
|
|
|
7170 |
|
|
return result;
|
7171 |
|
|
}
|
7172 |
|
|
|
7173 |
|
|
/* Validate that a clause of the given type does not already exist. */
|
7174 |
|
|
|
7175 |
|
|
static void
|
7176 |
|
|
check_no_duplicate_clause (tree clauses, enum omp_clause_code code,
|
7177 |
|
|
const char *name)
|
7178 |
|
|
{
|
7179 |
|
|
tree c;
|
7180 |
|
|
|
7181 |
|
|
for (c = clauses; c ; c = OMP_CLAUSE_CHAIN (c))
|
7182 |
|
|
if (OMP_CLAUSE_CODE (c) == code)
|
7183 |
|
|
{
|
7184 |
|
|
location_t loc = OMP_CLAUSE_LOCATION (c);
|
7185 |
|
|
error_at (loc, "too many %qs clauses", name);
|
7186 |
|
|
break;
|
7187 |
|
|
}
|
7188 |
|
|
}
|
7189 |
|
|
|
7190 |
|
|
/* OpenMP 2.5:
|
7191 |
|
|
variable-list:
|
7192 |
|
|
identifier
|
7193 |
|
|
variable-list , identifier
|
7194 |
|
|
|
7195 |
|
|
If KIND is nonzero, create the appropriate node and install the
|
7196 |
|
|
decl in OMP_CLAUSE_DECL and add the node to the head of the list.
|
7197 |
|
|
If KIND is nonzero, CLAUSE_LOC is the location of the clause.
|
7198 |
|
|
|
7199 |
|
|
If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
|
7200 |
|
|
return the list created. */
|
7201 |
|
|
|
7202 |
|
|
static tree
|
7203 |
|
|
c_parser_omp_variable_list (c_parser *parser,
|
7204 |
|
|
location_t clause_loc,
|
7205 |
|
|
enum omp_clause_code kind,
|
7206 |
|
|
tree list)
|
7207 |
|
|
{
|
7208 |
|
|
if (c_parser_next_token_is_not (parser, CPP_NAME)
|
7209 |
|
|
|| c_parser_peek_token (parser)->id_kind != C_ID_ID)
|
7210 |
|
|
c_parser_error (parser, "expected identifier");
|
7211 |
|
|
|
7212 |
|
|
while (c_parser_next_token_is (parser, CPP_NAME)
|
7213 |
|
|
&& c_parser_peek_token (parser)->id_kind == C_ID_ID)
|
7214 |
|
|
{
|
7215 |
|
|
tree t = lookup_name (c_parser_peek_token (parser)->value);
|
7216 |
|
|
|
7217 |
|
|
if (t == NULL_TREE)
|
7218 |
|
|
undeclared_variable (c_parser_peek_token (parser)->location,
|
7219 |
|
|
c_parser_peek_token (parser)->value);
|
7220 |
|
|
else if (t == error_mark_node)
|
7221 |
|
|
;
|
7222 |
|
|
else if (kind != 0)
|
7223 |
|
|
{
|
7224 |
|
|
tree u = build_omp_clause (clause_loc, kind);
|
7225 |
|
|
OMP_CLAUSE_DECL (u) = t;
|
7226 |
|
|
OMP_CLAUSE_CHAIN (u) = list;
|
7227 |
|
|
list = u;
|
7228 |
|
|
}
|
7229 |
|
|
else
|
7230 |
|
|
list = tree_cons (t, NULL_TREE, list);
|
7231 |
|
|
|
7232 |
|
|
c_parser_consume_token (parser);
|
7233 |
|
|
|
7234 |
|
|
if (c_parser_next_token_is_not (parser, CPP_COMMA))
|
7235 |
|
|
break;
|
7236 |
|
|
|
7237 |
|
|
c_parser_consume_token (parser);
|
7238 |
|
|
}
|
7239 |
|
|
|
7240 |
|
|
return list;
|
7241 |
|
|
}
|
7242 |
|
|
|
7243 |
|
|
/* Similarly, but expect leading and trailing parenthesis. This is a very
|
7244 |
|
|
common case for omp clauses. */
|
7245 |
|
|
|
7246 |
|
|
static tree
|
7247 |
|
|
c_parser_omp_var_list_parens (c_parser *parser, enum omp_clause_code kind,
|
7248 |
|
|
tree list)
|
7249 |
|
|
{
|
7250 |
|
|
/* The clauses location. */
|
7251 |
|
|
location_t loc = c_parser_peek_token (parser)->location;
|
7252 |
|
|
|
7253 |
|
|
if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
|
7254 |
|
|
{
|
7255 |
|
|
list = c_parser_omp_variable_list (parser, loc, kind, list);
|
7256 |
|
|
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
|
7257 |
|
|
}
|
7258 |
|
|
return list;
|
7259 |
|
|
}
|
7260 |
|
|
|
7261 |
|
|
/* OpenMP 3.0:
|
7262 |
|
|
collapse ( constant-expression ) */
|
7263 |
|
|
|
7264 |
|
|
static tree
|
7265 |
|
|
c_parser_omp_clause_collapse (c_parser *parser, tree list)
|
7266 |
|
|
{
|
7267 |
|
|
tree c, num = error_mark_node;
|
7268 |
|
|
HOST_WIDE_INT n;
|
7269 |
|
|
location_t loc;
|
7270 |
|
|
|
7271 |
|
|
check_no_duplicate_clause (list, OMP_CLAUSE_COLLAPSE, "collapse");
|
7272 |
|
|
|
7273 |
|
|
loc = c_parser_peek_token (parser)->location;
|
7274 |
|
|
if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
|
7275 |
|
|
{
|
7276 |
|
|
num = c_parser_expr_no_commas (parser, NULL).value;
|
7277 |
|
|
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
|
7278 |
|
|
}
|
7279 |
|
|
if (num == error_mark_node)
|
7280 |
|
|
return list;
|
7281 |
|
|
if (!INTEGRAL_TYPE_P (TREE_TYPE (num))
|
7282 |
|
|
|| !host_integerp (num, 0)
|
7283 |
|
|
|| (n = tree_low_cst (num, 0)) <= 0
|
7284 |
|
|
|| (int) n != n)
|
7285 |
|
|
{
|
7286 |
|
|
error_at (loc,
|
7287 |
|
|
"collapse argument needs positive constant integer expression");
|
7288 |
|
|
return list;
|
7289 |
|
|
}
|
7290 |
|
|
c = build_omp_clause (loc, OMP_CLAUSE_COLLAPSE);
|
7291 |
|
|
OMP_CLAUSE_COLLAPSE_EXPR (c) = num;
|
7292 |
|
|
OMP_CLAUSE_CHAIN (c) = list;
|
7293 |
|
|
return c;
|
7294 |
|
|
}
|
7295 |
|
|
|
7296 |
|
|
/* OpenMP 2.5:
|
7297 |
|
|
copyin ( variable-list ) */
|
7298 |
|
|
|
7299 |
|
|
static tree
|
7300 |
|
|
c_parser_omp_clause_copyin (c_parser *parser, tree list)
|
7301 |
|
|
{
|
7302 |
|
|
return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYIN, list);
|
7303 |
|
|
}
|
7304 |
|
|
|
7305 |
|
|
/* OpenMP 2.5:
|
7306 |
|
|
copyprivate ( variable-list ) */
|
7307 |
|
|
|
7308 |
|
|
static tree
|
7309 |
|
|
c_parser_omp_clause_copyprivate (c_parser *parser, tree list)
|
7310 |
|
|
{
|
7311 |
|
|
return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYPRIVATE, list);
|
7312 |
|
|
}
|
7313 |
|
|
|
7314 |
|
|
/* OpenMP 2.5:
|
7315 |
|
|
default ( shared | none ) */
|
7316 |
|
|
|
7317 |
|
|
static tree
|
7318 |
|
|
c_parser_omp_clause_default (c_parser *parser, tree list)
|
7319 |
|
|
{
|
7320 |
|
|
enum omp_clause_default_kind kind = OMP_CLAUSE_DEFAULT_UNSPECIFIED;
|
7321 |
|
|
location_t loc = c_parser_peek_token (parser)->location;
|
7322 |
|
|
tree c;
|
7323 |
|
|
|
7324 |
|
|
if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
|
7325 |
|
|
return list;
|
7326 |
|
|
if (c_parser_next_token_is (parser, CPP_NAME))
|
7327 |
|
|
{
|
7328 |
|
|
const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
|
7329 |
|
|
|
7330 |
|
|
switch (p[0])
|
7331 |
|
|
{
|
7332 |
|
|
case 'n':
|
7333 |
|
|
if (strcmp ("none", p) != 0)
|
7334 |
|
|
goto invalid_kind;
|
7335 |
|
|
kind = OMP_CLAUSE_DEFAULT_NONE;
|
7336 |
|
|
break;
|
7337 |
|
|
|
7338 |
|
|
case 's':
|
7339 |
|
|
if (strcmp ("shared", p) != 0)
|
7340 |
|
|
goto invalid_kind;
|
7341 |
|
|
kind = OMP_CLAUSE_DEFAULT_SHARED;
|
7342 |
|
|
break;
|
7343 |
|
|
|
7344 |
|
|
default:
|
7345 |
|
|
goto invalid_kind;
|
7346 |
|
|
}
|
7347 |
|
|
|
7348 |
|
|
c_parser_consume_token (parser);
|
7349 |
|
|
}
|
7350 |
|
|
else
|
7351 |
|
|
{
|
7352 |
|
|
invalid_kind:
|
7353 |
|
|
c_parser_error (parser, "expected %<none%> or %<shared%>");
|
7354 |
|
|
}
|
7355 |
|
|
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
|
7356 |
|
|
|
7357 |
|
|
if (kind == OMP_CLAUSE_DEFAULT_UNSPECIFIED)
|
7358 |
|
|
return list;
|
7359 |
|
|
|
7360 |
|
|
check_no_duplicate_clause (list, OMP_CLAUSE_DEFAULT, "default");
|
7361 |
|
|
c = build_omp_clause (loc, OMP_CLAUSE_DEFAULT);
|
7362 |
|
|
OMP_CLAUSE_CHAIN (c) = list;
|
7363 |
|
|
OMP_CLAUSE_DEFAULT_KIND (c) = kind;
|
7364 |
|
|
|
7365 |
|
|
return c;
|
7366 |
|
|
}
|
7367 |
|
|
|
7368 |
|
|
/* OpenMP 2.5:
|
7369 |
|
|
firstprivate ( variable-list ) */
|
7370 |
|
|
|
7371 |
|
|
static tree
|
7372 |
|
|
c_parser_omp_clause_firstprivate (c_parser *parser, tree list)
|
7373 |
|
|
{
|
7374 |
|
|
return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_FIRSTPRIVATE, list);
|
7375 |
|
|
}
|
7376 |
|
|
|
7377 |
|
|
/* OpenMP 2.5:
|
7378 |
|
|
if ( expression ) */
|
7379 |
|
|
|
7380 |
|
|
static tree
|
7381 |
|
|
c_parser_omp_clause_if (c_parser *parser, tree list)
|
7382 |
|
|
{
|
7383 |
|
|
location_t loc = c_parser_peek_token (parser)->location;
|
7384 |
|
|
if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
|
7385 |
|
|
{
|
7386 |
|
|
tree t = c_parser_paren_condition (parser);
|
7387 |
|
|
tree c;
|
7388 |
|
|
|
7389 |
|
|
check_no_duplicate_clause (list, OMP_CLAUSE_IF, "if");
|
7390 |
|
|
|
7391 |
|
|
c = build_omp_clause (loc, OMP_CLAUSE_IF);
|
7392 |
|
|
OMP_CLAUSE_IF_EXPR (c) = t;
|
7393 |
|
|
OMP_CLAUSE_CHAIN (c) = list;
|
7394 |
|
|
list = c;
|
7395 |
|
|
}
|
7396 |
|
|
else
|
7397 |
|
|
c_parser_error (parser, "expected %<(%>");
|
7398 |
|
|
|
7399 |
|
|
return list;
|
7400 |
|
|
}
|
7401 |
|
|
|
7402 |
|
|
/* OpenMP 2.5:
|
7403 |
|
|
lastprivate ( variable-list ) */
|
7404 |
|
|
|
7405 |
|
|
static tree
|
7406 |
|
|
c_parser_omp_clause_lastprivate (c_parser *parser, tree list)
|
7407 |
|
|
{
|
7408 |
|
|
return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_LASTPRIVATE, list);
|
7409 |
|
|
}
|
7410 |
|
|
|
7411 |
|
|
/* OpenMP 2.5:
|
7412 |
|
|
nowait */
|
7413 |
|
|
|
7414 |
|
|
static tree
|
7415 |
|
|
c_parser_omp_clause_nowait (c_parser *parser ATTRIBUTE_UNUSED, tree list)
|
7416 |
|
|
{
|
7417 |
|
|
tree c;
|
7418 |
|
|
location_t loc = c_parser_peek_token (parser)->location;
|
7419 |
|
|
|
7420 |
|
|
check_no_duplicate_clause (list, OMP_CLAUSE_NOWAIT, "nowait");
|
7421 |
|
|
|
7422 |
|
|
c = build_omp_clause (loc, OMP_CLAUSE_NOWAIT);
|
7423 |
|
|
OMP_CLAUSE_CHAIN (c) = list;
|
7424 |
|
|
return c;
|
7425 |
|
|
}
|
7426 |
|
|
|
7427 |
|
|
/* OpenMP 2.5:
|
7428 |
|
|
num_threads ( expression ) */
|
7429 |
|
|
|
7430 |
|
|
static tree
|
7431 |
|
|
c_parser_omp_clause_num_threads (c_parser *parser, tree list)
|
7432 |
|
|
{
|
7433 |
|
|
location_t num_threads_loc = c_parser_peek_token (parser)->location;
|
7434 |
|
|
if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
|
7435 |
|
|
{
|
7436 |
|
|
location_t expr_loc = c_parser_peek_token (parser)->location;
|
7437 |
|
|
tree c, t = c_parser_expression (parser).value;
|
7438 |
|
|
t = c_fully_fold (t, false, NULL);
|
7439 |
|
|
|
7440 |
|
|
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
|
7441 |
|
|
|
7442 |
|
|
if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
|
7443 |
|
|
{
|
7444 |
|
|
c_parser_error (parser, "expected integer expression");
|
7445 |
|
|
return list;
|
7446 |
|
|
}
|
7447 |
|
|
|
7448 |
|
|
/* Attempt to statically determine when the number isn't positive. */
|
7449 |
|
|
c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t,
|
7450 |
|
|
build_int_cst (TREE_TYPE (t), 0));
|
7451 |
|
|
if (CAN_HAVE_LOCATION_P (c))
|
7452 |
|
|
SET_EXPR_LOCATION (c, expr_loc);
|
7453 |
|
|
if (c == boolean_true_node)
|
7454 |
|
|
{
|
7455 |
|
|
warning_at (expr_loc, 0,
|
7456 |
|
|
"%<num_threads%> value must be positive");
|
7457 |
|
|
t = integer_one_node;
|
7458 |
|
|
}
|
7459 |
|
|
|
7460 |
|
|
check_no_duplicate_clause (list, OMP_CLAUSE_NUM_THREADS, "num_threads");
|
7461 |
|
|
|
7462 |
|
|
c = build_omp_clause (num_threads_loc, OMP_CLAUSE_NUM_THREADS);
|
7463 |
|
|
OMP_CLAUSE_NUM_THREADS_EXPR (c) = t;
|
7464 |
|
|
OMP_CLAUSE_CHAIN (c) = list;
|
7465 |
|
|
list = c;
|
7466 |
|
|
}
|
7467 |
|
|
|
7468 |
|
|
return list;
|
7469 |
|
|
}
|
7470 |
|
|
|
7471 |
|
|
/* OpenMP 2.5:
|
7472 |
|
|
ordered */
|
7473 |
|
|
|
7474 |
|
|
static tree
|
7475 |
|
|
c_parser_omp_clause_ordered (c_parser *parser, tree list)
|
7476 |
|
|
{
|
7477 |
|
|
tree c;
|
7478 |
|
|
|
7479 |
|
|
check_no_duplicate_clause (list, OMP_CLAUSE_ORDERED, "ordered");
|
7480 |
|
|
|
7481 |
|
|
c = build_omp_clause (c_parser_peek_token (parser)->location,
|
7482 |
|
|
OMP_CLAUSE_ORDERED);
|
7483 |
|
|
OMP_CLAUSE_CHAIN (c) = list;
|
7484 |
|
|
|
7485 |
|
|
return c;
|
7486 |
|
|
}
|
7487 |
|
|
|
7488 |
|
|
/* OpenMP 2.5:
|
7489 |
|
|
private ( variable-list ) */
|
7490 |
|
|
|
7491 |
|
|
static tree
|
7492 |
|
|
c_parser_omp_clause_private (c_parser *parser, tree list)
|
7493 |
|
|
{
|
7494 |
|
|
return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_PRIVATE, list);
|
7495 |
|
|
}
|
7496 |
|
|
|
7497 |
|
|
/* OpenMP 2.5:
|
7498 |
|
|
reduction ( reduction-operator : variable-list )
|
7499 |
|
|
|
7500 |
|
|
reduction-operator:
|
7501 |
|
|
One of: + * - & ^ | && || */
|
7502 |
|
|
|
7503 |
|
|
static tree
|
7504 |
|
|
c_parser_omp_clause_reduction (c_parser *parser, tree list)
|
7505 |
|
|
{
|
7506 |
|
|
location_t clause_loc = c_parser_peek_token (parser)->location;
|
7507 |
|
|
if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
|
7508 |
|
|
{
|
7509 |
|
|
enum tree_code code;
|
7510 |
|
|
|
7511 |
|
|
switch (c_parser_peek_token (parser)->type)
|
7512 |
|
|
{
|
7513 |
|
|
case CPP_PLUS:
|
7514 |
|
|
code = PLUS_EXPR;
|
7515 |
|
|
break;
|
7516 |
|
|
case CPP_MULT:
|
7517 |
|
|
code = MULT_EXPR;
|
7518 |
|
|
break;
|
7519 |
|
|
case CPP_MINUS:
|
7520 |
|
|
code = MINUS_EXPR;
|
7521 |
|
|
break;
|
7522 |
|
|
case CPP_AND:
|
7523 |
|
|
code = BIT_AND_EXPR;
|
7524 |
|
|
break;
|
7525 |
|
|
case CPP_XOR:
|
7526 |
|
|
code = BIT_XOR_EXPR;
|
7527 |
|
|
break;
|
7528 |
|
|
case CPP_OR:
|
7529 |
|
|
code = BIT_IOR_EXPR;
|
7530 |
|
|
break;
|
7531 |
|
|
case CPP_AND_AND:
|
7532 |
|
|
code = TRUTH_ANDIF_EXPR;
|
7533 |
|
|
break;
|
7534 |
|
|
case CPP_OR_OR:
|
7535 |
|
|
code = TRUTH_ORIF_EXPR;
|
7536 |
|
|
break;
|
7537 |
|
|
default:
|
7538 |
|
|
c_parser_error (parser,
|
7539 |
|
|
"expected %<+%>, %<*%>, %<-%>, %<&%>, "
|
7540 |
|
|
"%<^%>, %<|%>, %<&&%>, or %<||%>");
|
7541 |
|
|
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0);
|
7542 |
|
|
return list;
|
7543 |
|
|
}
|
7544 |
|
|
c_parser_consume_token (parser);
|
7545 |
|
|
if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
|
7546 |
|
|
{
|
7547 |
|
|
tree nl, c;
|
7548 |
|
|
|
7549 |
|
|
nl = c_parser_omp_variable_list (parser, clause_loc,
|
7550 |
|
|
OMP_CLAUSE_REDUCTION, list);
|
7551 |
|
|
for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
|
7552 |
|
|
OMP_CLAUSE_REDUCTION_CODE (c) = code;
|
7553 |
|
|
|
7554 |
|
|
list = nl;
|
7555 |
|
|
}
|
7556 |
|
|
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
|
7557 |
|
|
}
|
7558 |
|
|
return list;
|
7559 |
|
|
}
|
7560 |
|
|
|
7561 |
|
|
/* OpenMP 2.5:
|
7562 |
|
|
schedule ( schedule-kind )
|
7563 |
|
|
schedule ( schedule-kind , expression )
|
7564 |
|
|
|
7565 |
|
|
schedule-kind:
|
7566 |
|
|
static | dynamic | guided | runtime | auto
|
7567 |
|
|
*/
|
7568 |
|
|
|
7569 |
|
|
static tree
|
7570 |
|
|
c_parser_omp_clause_schedule (c_parser *parser, tree list)
|
7571 |
|
|
{
|
7572 |
|
|
tree c, t;
|
7573 |
|
|
location_t loc = c_parser_peek_token (parser)->location;
|
7574 |
|
|
|
7575 |
|
|
if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
|
7576 |
|
|
return list;
|
7577 |
|
|
|
7578 |
|
|
c = build_omp_clause (loc, OMP_CLAUSE_SCHEDULE);
|
7579 |
|
|
|
7580 |
|
|
if (c_parser_next_token_is (parser, CPP_NAME))
|
7581 |
|
|
{
|
7582 |
|
|
tree kind = c_parser_peek_token (parser)->value;
|
7583 |
|
|
const char *p = IDENTIFIER_POINTER (kind);
|
7584 |
|
|
|
7585 |
|
|
switch (p[0])
|
7586 |
|
|
{
|
7587 |
|
|
case 'd':
|
7588 |
|
|
if (strcmp ("dynamic", p) != 0)
|
7589 |
|
|
goto invalid_kind;
|
7590 |
|
|
OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_DYNAMIC;
|
7591 |
|
|
break;
|
7592 |
|
|
|
7593 |
|
|
case 'g':
|
7594 |
|
|
if (strcmp ("guided", p) != 0)
|
7595 |
|
|
goto invalid_kind;
|
7596 |
|
|
OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_GUIDED;
|
7597 |
|
|
break;
|
7598 |
|
|
|
7599 |
|
|
case 'r':
|
7600 |
|
|
if (strcmp ("runtime", p) != 0)
|
7601 |
|
|
goto invalid_kind;
|
7602 |
|
|
OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_RUNTIME;
|
7603 |
|
|
break;
|
7604 |
|
|
|
7605 |
|
|
default:
|
7606 |
|
|
goto invalid_kind;
|
7607 |
|
|
}
|
7608 |
|
|
}
|
7609 |
|
|
else if (c_parser_next_token_is_keyword (parser, RID_STATIC))
|
7610 |
|
|
OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_STATIC;
|
7611 |
|
|
else if (c_parser_next_token_is_keyword (parser, RID_AUTO))
|
7612 |
|
|
OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_AUTO;
|
7613 |
|
|
else
|
7614 |
|
|
goto invalid_kind;
|
7615 |
|
|
|
7616 |
|
|
c_parser_consume_token (parser);
|
7617 |
|
|
if (c_parser_next_token_is (parser, CPP_COMMA))
|
7618 |
|
|
{
|
7619 |
|
|
location_t here;
|
7620 |
|
|
c_parser_consume_token (parser);
|
7621 |
|
|
|
7622 |
|
|
here = c_parser_peek_token (parser)->location;
|
7623 |
|
|
t = c_parser_expr_no_commas (parser, NULL).value;
|
7624 |
|
|
t = c_fully_fold (t, false, NULL);
|
7625 |
|
|
|
7626 |
|
|
if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_RUNTIME)
|
7627 |
|
|
error_at (here, "schedule %<runtime%> does not take "
|
7628 |
|
|
"a %<chunk_size%> parameter");
|
7629 |
|
|
else if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_AUTO)
|
7630 |
|
|
error_at (here,
|
7631 |
|
|
"schedule %<auto%> does not take "
|
7632 |
|
|
"a %<chunk_size%> parameter");
|
7633 |
|
|
else if (TREE_CODE (TREE_TYPE (t)) == INTEGER_TYPE)
|
7634 |
|
|
OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c) = t;
|
7635 |
|
|
else
|
7636 |
|
|
c_parser_error (parser, "expected integer expression");
|
7637 |
|
|
|
7638 |
|
|
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
|
7639 |
|
|
}
|
7640 |
|
|
else
|
7641 |
|
|
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
|
7642 |
|
|
"expected %<,%> or %<)%>");
|
7643 |
|
|
|
7644 |
|
|
check_no_duplicate_clause (list, OMP_CLAUSE_SCHEDULE, "schedule");
|
7645 |
|
|
OMP_CLAUSE_CHAIN (c) = list;
|
7646 |
|
|
return c;
|
7647 |
|
|
|
7648 |
|
|
invalid_kind:
|
7649 |
|
|
c_parser_error (parser, "invalid schedule kind");
|
7650 |
|
|
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0);
|
7651 |
|
|
return list;
|
7652 |
|
|
}
|
7653 |
|
|
|
7654 |
|
|
/* OpenMP 2.5:
|
7655 |
|
|
shared ( variable-list ) */
|
7656 |
|
|
|
7657 |
|
|
static tree
|
7658 |
|
|
c_parser_omp_clause_shared (c_parser *parser, tree list)
|
7659 |
|
|
{
|
7660 |
|
|
return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_SHARED, list);
|
7661 |
|
|
}
|
7662 |
|
|
|
7663 |
|
|
/* OpenMP 3.0:
|
7664 |
|
|
untied */
|
7665 |
|
|
|
7666 |
|
|
static tree
|
7667 |
|
|
c_parser_omp_clause_untied (c_parser *parser ATTRIBUTE_UNUSED, tree list)
|
7668 |
|
|
{
|
7669 |
|
|
tree c;
|
7670 |
|
|
|
7671 |
|
|
/* FIXME: Should we allow duplicates? */
|
7672 |
|
|
check_no_duplicate_clause (list, OMP_CLAUSE_UNTIED, "untied");
|
7673 |
|
|
|
7674 |
|
|
c = build_omp_clause (c_parser_peek_token (parser)->location,
|
7675 |
|
|
OMP_CLAUSE_UNTIED);
|
7676 |
|
|
OMP_CLAUSE_CHAIN (c) = list;
|
7677 |
|
|
|
7678 |
|
|
return c;
|
7679 |
|
|
}
|
7680 |
|
|
|
7681 |
|
|
/* Parse all OpenMP clauses. The set clauses allowed by the directive
|
7682 |
|
|
is a bitmask in MASK. Return the list of clauses found; the result
|
7683 |
|
|
of clause default goes in *pdefault. */
|
7684 |
|
|
|
7685 |
|
|
static tree
|
7686 |
|
|
c_parser_omp_all_clauses (c_parser *parser, unsigned int mask,
|
7687 |
|
|
const char *where)
|
7688 |
|
|
{
|
7689 |
|
|
tree clauses = NULL;
|
7690 |
|
|
bool first = true;
|
7691 |
|
|
|
7692 |
|
|
while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
|
7693 |
|
|
{
|
7694 |
|
|
location_t here;
|
7695 |
|
|
pragma_omp_clause c_kind;
|
7696 |
|
|
const char *c_name;
|
7697 |
|
|
tree prev = clauses;
|
7698 |
|
|
|
7699 |
|
|
if (!first && c_parser_next_token_is (parser, CPP_COMMA))
|
7700 |
|
|
c_parser_consume_token (parser);
|
7701 |
|
|
|
7702 |
|
|
first = false;
|
7703 |
|
|
here = c_parser_peek_token (parser)->location;
|
7704 |
|
|
c_kind = c_parser_omp_clause_name (parser);
|
7705 |
|
|
|
7706 |
|
|
switch (c_kind)
|
7707 |
|
|
{
|
7708 |
|
|
case PRAGMA_OMP_CLAUSE_COLLAPSE:
|
7709 |
|
|
clauses = c_parser_omp_clause_collapse (parser, clauses);
|
7710 |
|
|
c_name = "collapse";
|
7711 |
|
|
break;
|
7712 |
|
|
case PRAGMA_OMP_CLAUSE_COPYIN:
|
7713 |
|
|
clauses = c_parser_omp_clause_copyin (parser, clauses);
|
7714 |
|
|
c_name = "copyin";
|
7715 |
|
|
break;
|
7716 |
|
|
case PRAGMA_OMP_CLAUSE_COPYPRIVATE:
|
7717 |
|
|
clauses = c_parser_omp_clause_copyprivate (parser, clauses);
|
7718 |
|
|
c_name = "copyprivate";
|
7719 |
|
|
break;
|
7720 |
|
|
case PRAGMA_OMP_CLAUSE_DEFAULT:
|
7721 |
|
|
clauses = c_parser_omp_clause_default (parser, clauses);
|
7722 |
|
|
c_name = "default";
|
7723 |
|
|
break;
|
7724 |
|
|
case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE:
|
7725 |
|
|
clauses = c_parser_omp_clause_firstprivate (parser, clauses);
|
7726 |
|
|
c_name = "firstprivate";
|
7727 |
|
|
break;
|
7728 |
|
|
case PRAGMA_OMP_CLAUSE_IF:
|
7729 |
|
|
clauses = c_parser_omp_clause_if (parser, clauses);
|
7730 |
|
|
c_name = "if";
|
7731 |
|
|
break;
|
7732 |
|
|
case PRAGMA_OMP_CLAUSE_LASTPRIVATE:
|
7733 |
|
|
clauses = c_parser_omp_clause_lastprivate (parser, clauses);
|
7734 |
|
|
c_name = "lastprivate";
|
7735 |
|
|
break;
|
7736 |
|
|
case PRAGMA_OMP_CLAUSE_NOWAIT:
|
7737 |
|
|
clauses = c_parser_omp_clause_nowait (parser, clauses);
|
7738 |
|
|
c_name = "nowait";
|
7739 |
|
|
break;
|
7740 |
|
|
case PRAGMA_OMP_CLAUSE_NUM_THREADS:
|
7741 |
|
|
clauses = c_parser_omp_clause_num_threads (parser, clauses);
|
7742 |
|
|
c_name = "num_threads";
|
7743 |
|
|
break;
|
7744 |
|
|
case PRAGMA_OMP_CLAUSE_ORDERED:
|
7745 |
|
|
clauses = c_parser_omp_clause_ordered (parser, clauses);
|
7746 |
|
|
c_name = "ordered";
|
7747 |
|
|
break;
|
7748 |
|
|
case PRAGMA_OMP_CLAUSE_PRIVATE:
|
7749 |
|
|
clauses = c_parser_omp_clause_private (parser, clauses);
|
7750 |
|
|
c_name = "private";
|
7751 |
|
|
break;
|
7752 |
|
|
case PRAGMA_OMP_CLAUSE_REDUCTION:
|
7753 |
|
|
clauses = c_parser_omp_clause_reduction (parser, clauses);
|
7754 |
|
|
c_name = "reduction";
|
7755 |
|
|
break;
|
7756 |
|
|
case PRAGMA_OMP_CLAUSE_SCHEDULE:
|
7757 |
|
|
clauses = c_parser_omp_clause_schedule (parser, clauses);
|
7758 |
|
|
c_name = "schedule";
|
7759 |
|
|
break;
|
7760 |
|
|
case PRAGMA_OMP_CLAUSE_SHARED:
|
7761 |
|
|
clauses = c_parser_omp_clause_shared (parser, clauses);
|
7762 |
|
|
c_name = "shared";
|
7763 |
|
|
break;
|
7764 |
|
|
case PRAGMA_OMP_CLAUSE_UNTIED:
|
7765 |
|
|
clauses = c_parser_omp_clause_untied (parser, clauses);
|
7766 |
|
|
c_name = "untied";
|
7767 |
|
|
break;
|
7768 |
|
|
default:
|
7769 |
|
|
c_parser_error (parser, "expected %<#pragma omp%> clause");
|
7770 |
|
|
goto saw_error;
|
7771 |
|
|
}
|
7772 |
|
|
|
7773 |
|
|
if (((mask >> c_kind) & 1) == 0 && !parser->error)
|
7774 |
|
|
{
|
7775 |
|
|
/* Remove the invalid clause(s) from the list to avoid
|
7776 |
|
|
confusing the rest of the compiler. */
|
7777 |
|
|
clauses = prev;
|
7778 |
|
|
error_at (here, "%qs is not valid for %qs", c_name, where);
|
7779 |
|
|
}
|
7780 |
|
|
}
|
7781 |
|
|
|
7782 |
|
|
saw_error:
|
7783 |
|
|
c_parser_skip_to_pragma_eol (parser);
|
7784 |
|
|
|
7785 |
|
|
return c_finish_omp_clauses (clauses);
|
7786 |
|
|
}
|
7787 |
|
|
|
7788 |
|
|
/* OpenMP 2.5:
|
7789 |
|
|
structured-block:
|
7790 |
|
|
statement
|
7791 |
|
|
|
7792 |
|
|
In practice, we're also interested in adding the statement to an
|
7793 |
|
|
outer node. So it is convenient if we work around the fact that
|
7794 |
|
|
c_parser_statement calls add_stmt. */
|
7795 |
|
|
|
7796 |
|
|
static tree
|
7797 |
|
|
c_parser_omp_structured_block (c_parser *parser)
|
7798 |
|
|
{
|
7799 |
|
|
tree stmt = push_stmt_list ();
|
7800 |
|
|
c_parser_statement (parser);
|
7801 |
|
|
return pop_stmt_list (stmt);
|
7802 |
|
|
}
|
7803 |
|
|
|
7804 |
|
|
/* OpenMP 2.5:
|
7805 |
|
|
# pragma omp atomic new-line
|
7806 |
|
|
expression-stmt
|
7807 |
|
|
|
7808 |
|
|
expression-stmt:
|
7809 |
|
|
x binop= expr | x++ | ++x | x-- | --x
|
7810 |
|
|
binop:
|
7811 |
|
|
+, *, -, /, &, ^, |, <<, >>
|
7812 |
|
|
|
7813 |
|
|
where x is an lvalue expression with scalar type.
|
7814 |
|
|
|
7815 |
|
|
LOC is the location of the #pragma token. */
|
7816 |
|
|
|
7817 |
|
|
static void
|
7818 |
|
|
c_parser_omp_atomic (location_t loc, c_parser *parser)
|
7819 |
|
|
{
|
7820 |
|
|
tree lhs, rhs;
|
7821 |
|
|
tree stmt;
|
7822 |
|
|
enum tree_code code;
|
7823 |
|
|
struct c_expr rhs_expr;
|
7824 |
|
|
|
7825 |
|
|
c_parser_skip_to_pragma_eol (parser);
|
7826 |
|
|
|
7827 |
|
|
lhs = c_parser_unary_expression (parser).value;
|
7828 |
|
|
lhs = c_fully_fold (lhs, false, NULL);
|
7829 |
|
|
switch (TREE_CODE (lhs))
|
7830 |
|
|
{
|
7831 |
|
|
case ERROR_MARK:
|
7832 |
|
|
saw_error:
|
7833 |
|
|
c_parser_skip_to_end_of_block_or_statement (parser);
|
7834 |
|
|
return;
|
7835 |
|
|
|
7836 |
|
|
case PREINCREMENT_EXPR:
|
7837 |
|
|
case POSTINCREMENT_EXPR:
|
7838 |
|
|
lhs = TREE_OPERAND (lhs, 0);
|
7839 |
|
|
code = PLUS_EXPR;
|
7840 |
|
|
rhs = integer_one_node;
|
7841 |
|
|
break;
|
7842 |
|
|
|
7843 |
|
|
case PREDECREMENT_EXPR:
|
7844 |
|
|
case POSTDECREMENT_EXPR:
|
7845 |
|
|
lhs = TREE_OPERAND (lhs, 0);
|
7846 |
|
|
code = MINUS_EXPR;
|
7847 |
|
|
rhs = integer_one_node;
|
7848 |
|
|
break;
|
7849 |
|
|
|
7850 |
|
|
default:
|
7851 |
|
|
switch (c_parser_peek_token (parser)->type)
|
7852 |
|
|
{
|
7853 |
|
|
case CPP_MULT_EQ:
|
7854 |
|
|
code = MULT_EXPR;
|
7855 |
|
|
break;
|
7856 |
|
|
case CPP_DIV_EQ:
|
7857 |
|
|
code = TRUNC_DIV_EXPR;
|
7858 |
|
|
break;
|
7859 |
|
|
case CPP_PLUS_EQ:
|
7860 |
|
|
code = PLUS_EXPR;
|
7861 |
|
|
break;
|
7862 |
|
|
case CPP_MINUS_EQ:
|
7863 |
|
|
code = MINUS_EXPR;
|
7864 |
|
|
break;
|
7865 |
|
|
case CPP_LSHIFT_EQ:
|
7866 |
|
|
code = LSHIFT_EXPR;
|
7867 |
|
|
break;
|
7868 |
|
|
case CPP_RSHIFT_EQ:
|
7869 |
|
|
code = RSHIFT_EXPR;
|
7870 |
|
|
break;
|
7871 |
|
|
case CPP_AND_EQ:
|
7872 |
|
|
code = BIT_AND_EXPR;
|
7873 |
|
|
break;
|
7874 |
|
|
case CPP_OR_EQ:
|
7875 |
|
|
code = BIT_IOR_EXPR;
|
7876 |
|
|
break;
|
7877 |
|
|
case CPP_XOR_EQ:
|
7878 |
|
|
code = BIT_XOR_EXPR;
|
7879 |
|
|
break;
|
7880 |
|
|
default:
|
7881 |
|
|
c_parser_error (parser,
|
7882 |
|
|
"invalid operator for %<#pragma omp atomic%>");
|
7883 |
|
|
goto saw_error;
|
7884 |
|
|
}
|
7885 |
|
|
|
7886 |
|
|
c_parser_consume_token (parser);
|
7887 |
|
|
{
|
7888 |
|
|
location_t rhs_loc = c_parser_peek_token (parser)->location;
|
7889 |
|
|
rhs_expr = c_parser_expression (parser);
|
7890 |
|
|
rhs_expr = default_function_array_conversion (rhs_loc, rhs_expr);
|
7891 |
|
|
}
|
7892 |
|
|
rhs = rhs_expr.value;
|
7893 |
|
|
rhs = c_fully_fold (rhs, false, NULL);
|
7894 |
|
|
break;
|
7895 |
|
|
}
|
7896 |
|
|
stmt = c_finish_omp_atomic (loc, code, lhs, rhs);
|
7897 |
|
|
if (stmt != error_mark_node)
|
7898 |
|
|
add_stmt (stmt);
|
7899 |
|
|
c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
|
7900 |
|
|
}
|
7901 |
|
|
|
7902 |
|
|
|
7903 |
|
|
/* OpenMP 2.5:
|
7904 |
|
|
# pragma omp barrier new-line
|
7905 |
|
|
*/
|
7906 |
|
|
|
7907 |
|
|
static void
|
7908 |
|
|
c_parser_omp_barrier (c_parser *parser)
|
7909 |
|
|
{
|
7910 |
|
|
location_t loc = c_parser_peek_token (parser)->location;
|
7911 |
|
|
c_parser_consume_pragma (parser);
|
7912 |
|
|
c_parser_skip_to_pragma_eol (parser);
|
7913 |
|
|
|
7914 |
|
|
c_finish_omp_barrier (loc);
|
7915 |
|
|
}
|
7916 |
|
|
|
7917 |
|
|
/* OpenMP 2.5:
|
7918 |
|
|
# pragma omp critical [(name)] new-line
|
7919 |
|
|
structured-block
|
7920 |
|
|
|
7921 |
|
|
LOC is the location of the #pragma itself. */
|
7922 |
|
|
|
7923 |
|
|
static tree
|
7924 |
|
|
c_parser_omp_critical (location_t loc, c_parser *parser)
|
7925 |
|
|
{
|
7926 |
|
|
tree stmt, name = NULL;
|
7927 |
|
|
|
7928 |
|
|
if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
|
7929 |
|
|
{
|
7930 |
|
|
c_parser_consume_token (parser);
|
7931 |
|
|
if (c_parser_next_token_is (parser, CPP_NAME))
|
7932 |
|
|
{
|
7933 |
|
|
name = c_parser_peek_token (parser)->value;
|
7934 |
|
|
c_parser_consume_token (parser);
|
7935 |
|
|
c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
|
7936 |
|
|
}
|
7937 |
|
|
else
|
7938 |
|
|
c_parser_error (parser, "expected identifier");
|
7939 |
|
|
}
|
7940 |
|
|
else if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
|
7941 |
|
|
c_parser_error (parser, "expected %<(%> or end of line");
|
7942 |
|
|
c_parser_skip_to_pragma_eol (parser);
|
7943 |
|
|
|
7944 |
|
|
stmt = c_parser_omp_structured_block (parser);
|
7945 |
|
|
return c_finish_omp_critical (loc, stmt, name);
|
7946 |
|
|
}
|
7947 |
|
|
|
7948 |
|
|
/* OpenMP 2.5:
|
7949 |
|
|
# pragma omp flush flush-vars[opt] new-line
|
7950 |
|
|
|
7951 |
|
|
flush-vars:
|
7952 |
|
|
( variable-list ) */
|
7953 |
|
|
|
7954 |
|
|
static void
|
7955 |
|
|
c_parser_omp_flush (c_parser *parser)
|
7956 |
|
|
{
|
7957 |
|
|
location_t loc = c_parser_peek_token (parser)->location;
|
7958 |
|
|
c_parser_consume_pragma (parser);
|
7959 |
|
|
if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
|
7960 |
|
|
c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL);
|
7961 |
|
|
else if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
|
7962 |
|
|
c_parser_error (parser, "expected %<(%> or end of line");
|
7963 |
|
|
c_parser_skip_to_pragma_eol (parser);
|
7964 |
|
|
|
7965 |
|
|
c_finish_omp_flush (loc);
|
7966 |
|
|
}
|
7967 |
|
|
|
7968 |
|
|
/* Parse the restricted form of the for statement allowed by OpenMP.
|
7969 |
|
|
The real trick here is to determine the loop control variable early
|
7970 |
|
|
so that we can push a new decl if necessary to make it private.
|
7971 |
|
|
LOC is the location of the OMP in "#pragma omp". */
|
7972 |
|
|
|
7973 |
|
|
static tree
|
7974 |
|
|
c_parser_omp_for_loop (location_t loc,
|
7975 |
|
|
c_parser *parser, tree clauses, tree *par_clauses)
|
7976 |
|
|
{
|
7977 |
|
|
tree decl, cond, incr, save_break, save_cont, body, init, stmt, cl;
|
7978 |
|
|
tree declv, condv, incrv, initv, for_block = NULL, ret = NULL;
|
7979 |
|
|
bool fail = false, open_brace_parsed = false;
|
7980 |
|
|
int i, collapse = 1, nbraces = 0;
|
7981 |
|
|
location_t for_loc;
|
7982 |
|
|
|
7983 |
|
|
for (cl = clauses; cl; cl = OMP_CLAUSE_CHAIN (cl))
|
7984 |
|
|
if (OMP_CLAUSE_CODE (cl) == OMP_CLAUSE_COLLAPSE)
|
7985 |
|
|
collapse = tree_low_cst (OMP_CLAUSE_COLLAPSE_EXPR (cl), 0);
|
7986 |
|
|
|
7987 |
|
|
gcc_assert (collapse >= 1);
|
7988 |
|
|
|
7989 |
|
|
declv = make_tree_vec (collapse);
|
7990 |
|
|
initv = make_tree_vec (collapse);
|
7991 |
|
|
condv = make_tree_vec (collapse);
|
7992 |
|
|
incrv = make_tree_vec (collapse);
|
7993 |
|
|
|
7994 |
|
|
if (!c_parser_next_token_is_keyword (parser, RID_FOR))
|
7995 |
|
|
{
|
7996 |
|
|
c_parser_error (parser, "for statement expected");
|
7997 |
|
|
return NULL;
|
7998 |
|
|
}
|
7999 |
|
|
for_loc = c_parser_peek_token (parser)->location;
|
8000 |
|
|
c_parser_consume_token (parser);
|
8001 |
|
|
|
8002 |
|
|
for (i = 0; i < collapse; i++)
|
8003 |
|
|
{
|
8004 |
|
|
int bracecount = 0;
|
8005 |
|
|
|
8006 |
|
|
if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
|
8007 |
|
|
goto pop_scopes;
|
8008 |
|
|
|
8009 |
|
|
/* Parse the initialization declaration or expression. */
|
8010 |
|
|
if (c_parser_next_token_starts_declspecs (parser))
|
8011 |
|
|
{
|
8012 |
|
|
if (i > 0)
|
8013 |
|
|
for_block
|
8014 |
|
|
= tree_cons (NULL, c_begin_compound_stmt (true), for_block);
|
8015 |
|
|
c_parser_declaration_or_fndef (parser, true, true, true, true);
|
8016 |
|
|
decl = check_for_loop_decls (for_loc);
|
8017 |
|
|
if (decl == NULL)
|
8018 |
|
|
goto error_init;
|
8019 |
|
|
if (DECL_INITIAL (decl) == error_mark_node)
|
8020 |
|
|
decl = error_mark_node;
|
8021 |
|
|
init = decl;
|
8022 |
|
|
}
|
8023 |
|
|
else if (c_parser_next_token_is (parser, CPP_NAME)
|
8024 |
|
|
&& c_parser_peek_2nd_token (parser)->type == CPP_EQ)
|
8025 |
|
|
{
|
8026 |
|
|
struct c_expr decl_exp;
|
8027 |
|
|
struct c_expr init_exp;
|
8028 |
|
|
location_t init_loc;
|
8029 |
|
|
|
8030 |
|
|
decl_exp = c_parser_postfix_expression (parser);
|
8031 |
|
|
decl = decl_exp.value;
|
8032 |
|
|
|
8033 |
|
|
c_parser_require (parser, CPP_EQ, "expected %<=%>");
|
8034 |
|
|
|
8035 |
|
|
init_loc = c_parser_peek_token (parser)->location;
|
8036 |
|
|
init_exp = c_parser_expr_no_commas (parser, NULL);
|
8037 |
|
|
init_exp = default_function_array_conversion (init_loc, init_exp);
|
8038 |
|
|
init = build_modify_expr (init_loc, decl, decl_exp.original_type,
|
8039 |
|
|
NOP_EXPR, init_loc, init_exp.value,
|
8040 |
|
|
init_exp.original_type);
|
8041 |
|
|
init = c_process_expr_stmt (init_loc, init);
|
8042 |
|
|
|
8043 |
|
|
c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
|
8044 |
|
|
}
|
8045 |
|
|
else
|
8046 |
|
|
{
|
8047 |
|
|
error_init:
|
8048 |
|
|
c_parser_error (parser,
|
8049 |
|
|
"expected iteration declaration or initialization");
|
8050 |
|
|
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
|
8051 |
|
|
"expected %<)%>");
|
8052 |
|
|
fail = true;
|
8053 |
|
|
goto parse_next;
|
8054 |
|
|
}
|
8055 |
|
|
|
8056 |
|
|
/* Parse the loop condition. */
|
8057 |
|
|
cond = NULL_TREE;
|
8058 |
|
|
if (c_parser_next_token_is_not (parser, CPP_SEMICOLON))
|
8059 |
|
|
{
|
8060 |
|
|
location_t cond_loc = c_parser_peek_token (parser)->location;
|
8061 |
|
|
struct c_expr cond_expr = c_parser_binary_expression (parser, NULL);
|
8062 |
|
|
|
8063 |
|
|
cond = cond_expr.value;
|
8064 |
|
|
cond = c_objc_common_truthvalue_conversion (cond_loc, cond);
|
8065 |
|
|
cond = c_fully_fold (cond, false, NULL);
|
8066 |
|
|
switch (cond_expr.original_code)
|
8067 |
|
|
{
|
8068 |
|
|
case GT_EXPR:
|
8069 |
|
|
case GE_EXPR:
|
8070 |
|
|
case LT_EXPR:
|
8071 |
|
|
case LE_EXPR:
|
8072 |
|
|
break;
|
8073 |
|
|
default:
|
8074 |
|
|
/* Can't be cond = error_mark_node, because we want to preserve
|
8075 |
|
|
the location until c_finish_omp_for. */
|
8076 |
|
|
cond = build1 (NOP_EXPR, boolean_type_node, error_mark_node);
|
8077 |
|
|
break;
|
8078 |
|
|
}
|
8079 |
|
|
protected_set_expr_location (cond, cond_loc);
|
8080 |
|
|
}
|
8081 |
|
|
c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
|
8082 |
|
|
|
8083 |
|
|
/* Parse the increment expression. */
|
8084 |
|
|
incr = NULL_TREE;
|
8085 |
|
|
if (c_parser_next_token_is_not (parser, CPP_CLOSE_PAREN))
|
8086 |
|
|
{
|
8087 |
|
|
location_t incr_loc = c_parser_peek_token (parser)->location;
|
8088 |
|
|
|
8089 |
|
|
incr = c_process_expr_stmt (incr_loc,
|
8090 |
|
|
c_parser_expression (parser).value);
|
8091 |
|
|
}
|
8092 |
|
|
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
|
8093 |
|
|
|
8094 |
|
|
if (decl == NULL || decl == error_mark_node || init == error_mark_node)
|
8095 |
|
|
fail = true;
|
8096 |
|
|
else
|
8097 |
|
|
{
|
8098 |
|
|
TREE_VEC_ELT (declv, i) = decl;
|
8099 |
|
|
TREE_VEC_ELT (initv, i) = init;
|
8100 |
|
|
TREE_VEC_ELT (condv, i) = cond;
|
8101 |
|
|
TREE_VEC_ELT (incrv, i) = incr;
|
8102 |
|
|
}
|
8103 |
|
|
|
8104 |
|
|
parse_next:
|
8105 |
|
|
if (i == collapse - 1)
|
8106 |
|
|
break;
|
8107 |
|
|
|
8108 |
|
|
/* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
|
8109 |
|
|
in between the collapsed for loops to be still considered perfectly
|
8110 |
|
|
nested. Hopefully the final version clarifies this.
|
8111 |
|
|
For now handle (multiple) {'s and empty statements. */
|
8112 |
|
|
do
|
8113 |
|
|
{
|
8114 |
|
|
if (c_parser_next_token_is_keyword (parser, RID_FOR))
|
8115 |
|
|
{
|
8116 |
|
|
c_parser_consume_token (parser);
|
8117 |
|
|
break;
|
8118 |
|
|
}
|
8119 |
|
|
else if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
|
8120 |
|
|
{
|
8121 |
|
|
c_parser_consume_token (parser);
|
8122 |
|
|
bracecount++;
|
8123 |
|
|
}
|
8124 |
|
|
else if (bracecount
|
8125 |
|
|
&& c_parser_next_token_is (parser, CPP_SEMICOLON))
|
8126 |
|
|
c_parser_consume_token (parser);
|
8127 |
|
|
else
|
8128 |
|
|
{
|
8129 |
|
|
c_parser_error (parser, "not enough perfectly nested loops");
|
8130 |
|
|
if (bracecount)
|
8131 |
|
|
{
|
8132 |
|
|
open_brace_parsed = true;
|
8133 |
|
|
bracecount--;
|
8134 |
|
|
}
|
8135 |
|
|
fail = true;
|
8136 |
|
|
collapse = 0;
|
8137 |
|
|
break;
|
8138 |
|
|
}
|
8139 |
|
|
}
|
8140 |
|
|
while (1);
|
8141 |
|
|
|
8142 |
|
|
nbraces += bracecount;
|
8143 |
|
|
}
|
8144 |
|
|
|
8145 |
|
|
save_break = c_break_label;
|
8146 |
|
|
c_break_label = size_one_node;
|
8147 |
|
|
save_cont = c_cont_label;
|
8148 |
|
|
c_cont_label = NULL_TREE;
|
8149 |
|
|
body = push_stmt_list ();
|
8150 |
|
|
|
8151 |
|
|
if (open_brace_parsed)
|
8152 |
|
|
{
|
8153 |
|
|
location_t here = c_parser_peek_token (parser)->location;
|
8154 |
|
|
stmt = c_begin_compound_stmt (true);
|
8155 |
|
|
c_parser_compound_statement_nostart (parser);
|
8156 |
|
|
add_stmt (c_end_compound_stmt (here, stmt, true));
|
8157 |
|
|
}
|
8158 |
|
|
else
|
8159 |
|
|
add_stmt (c_parser_c99_block_statement (parser));
|
8160 |
|
|
if (c_cont_label)
|
8161 |
|
|
{
|
8162 |
|
|
tree t = build1 (LABEL_EXPR, void_type_node, c_cont_label);
|
8163 |
|
|
SET_EXPR_LOCATION (t, loc);
|
8164 |
|
|
add_stmt (t);
|
8165 |
|
|
}
|
8166 |
|
|
|
8167 |
|
|
body = pop_stmt_list (body);
|
8168 |
|
|
c_break_label = save_break;
|
8169 |
|
|
c_cont_label = save_cont;
|
8170 |
|
|
|
8171 |
|
|
while (nbraces)
|
8172 |
|
|
{
|
8173 |
|
|
if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
|
8174 |
|
|
{
|
8175 |
|
|
c_parser_consume_token (parser);
|
8176 |
|
|
nbraces--;
|
8177 |
|
|
}
|
8178 |
|
|
else if (c_parser_next_token_is (parser, CPP_SEMICOLON))
|
8179 |
|
|
c_parser_consume_token (parser);
|
8180 |
|
|
else
|
8181 |
|
|
{
|
8182 |
|
|
c_parser_error (parser, "collapsed loops not perfectly nested");
|
8183 |
|
|
while (nbraces)
|
8184 |
|
|
{
|
8185 |
|
|
location_t here = c_parser_peek_token (parser)->location;
|
8186 |
|
|
stmt = c_begin_compound_stmt (true);
|
8187 |
|
|
add_stmt (body);
|
8188 |
|
|
c_parser_compound_statement_nostart (parser);
|
8189 |
|
|
body = c_end_compound_stmt (here, stmt, true);
|
8190 |
|
|
nbraces--;
|
8191 |
|
|
}
|
8192 |
|
|
goto pop_scopes;
|
8193 |
|
|
}
|
8194 |
|
|
}
|
8195 |
|
|
|
8196 |
|
|
/* Only bother calling c_finish_omp_for if we haven't already generated
|
8197 |
|
|
an error from the initialization parsing. */
|
8198 |
|
|
if (!fail)
|
8199 |
|
|
{
|
8200 |
|
|
stmt = c_finish_omp_for (loc, declv, initv, condv, incrv, body, NULL);
|
8201 |
|
|
if (stmt)
|
8202 |
|
|
{
|
8203 |
|
|
if (par_clauses != NULL)
|
8204 |
|
|
{
|
8205 |
|
|
tree *c;
|
8206 |
|
|
for (c = par_clauses; *c ; )
|
8207 |
|
|
if (OMP_CLAUSE_CODE (*c) != OMP_CLAUSE_FIRSTPRIVATE
|
8208 |
|
|
&& OMP_CLAUSE_CODE (*c) != OMP_CLAUSE_LASTPRIVATE)
|
8209 |
|
|
c = &OMP_CLAUSE_CHAIN (*c);
|
8210 |
|
|
else
|
8211 |
|
|
{
|
8212 |
|
|
for (i = 0; i < collapse; i++)
|
8213 |
|
|
if (TREE_VEC_ELT (declv, i) == OMP_CLAUSE_DECL (*c))
|
8214 |
|
|
break;
|
8215 |
|
|
if (i == collapse)
|
8216 |
|
|
c = &OMP_CLAUSE_CHAIN (*c);
|
8217 |
|
|
else if (OMP_CLAUSE_CODE (*c) == OMP_CLAUSE_FIRSTPRIVATE)
|
8218 |
|
|
{
|
8219 |
|
|
error_at (loc,
|
8220 |
|
|
"iteration variable %qD should not be firstprivate",
|
8221 |
|
|
OMP_CLAUSE_DECL (*c));
|
8222 |
|
|
*c = OMP_CLAUSE_CHAIN (*c);
|
8223 |
|
|
}
|
8224 |
|
|
else
|
8225 |
|
|
{
|
8226 |
|
|
/* Copy lastprivate (decl) clause to OMP_FOR_CLAUSES,
|
8227 |
|
|
change it to shared (decl) in
|
8228 |
|
|
OMP_PARALLEL_CLAUSES. */
|
8229 |
|
|
tree l = build_omp_clause (OMP_CLAUSE_LOCATION (*c),
|
8230 |
|
|
OMP_CLAUSE_LASTPRIVATE);
|
8231 |
|
|
OMP_CLAUSE_DECL (l) = OMP_CLAUSE_DECL (*c);
|
8232 |
|
|
OMP_CLAUSE_CHAIN (l) = clauses;
|
8233 |
|
|
clauses = l;
|
8234 |
|
|
OMP_CLAUSE_SET_CODE (*c, OMP_CLAUSE_SHARED);
|
8235 |
|
|
}
|
8236 |
|
|
}
|
8237 |
|
|
}
|
8238 |
|
|
OMP_FOR_CLAUSES (stmt) = clauses;
|
8239 |
|
|
}
|
8240 |
|
|
ret = stmt;
|
8241 |
|
|
}
|
8242 |
|
|
pop_scopes:
|
8243 |
|
|
while (for_block)
|
8244 |
|
|
{
|
8245 |
|
|
/* FIXME diagnostics: LOC below should be the actual location of
|
8246 |
|
|
this particular for block. We need to build a list of
|
8247 |
|
|
locations to go along with FOR_BLOCK. */
|
8248 |
|
|
stmt = c_end_compound_stmt (loc, TREE_VALUE (for_block), true);
|
8249 |
|
|
add_stmt (stmt);
|
8250 |
|
|
for_block = TREE_CHAIN (for_block);
|
8251 |
|
|
}
|
8252 |
|
|
return ret;
|
8253 |
|
|
}
|
8254 |
|
|
|
8255 |
|
|
/* OpenMP 2.5:
|
8256 |
|
|
#pragma omp for for-clause[optseq] new-line
|
8257 |
|
|
for-loop
|
8258 |
|
|
|
8259 |
|
|
LOC is the location of the #pragma token.
|
8260 |
|
|
*/
|
8261 |
|
|
|
8262 |
|
|
#define OMP_FOR_CLAUSE_MASK \
|
8263 |
|
|
( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
|
8264 |
|
|
| (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
|
8265 |
|
|
| (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
|
8266 |
|
|
| (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
|
8267 |
|
|
| (1u << PRAGMA_OMP_CLAUSE_ORDERED) \
|
8268 |
|
|
| (1u << PRAGMA_OMP_CLAUSE_SCHEDULE) \
|
8269 |
|
|
| (1u << PRAGMA_OMP_CLAUSE_COLLAPSE) \
|
8270 |
|
|
| (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
|
8271 |
|
|
|
8272 |
|
|
static tree
|
8273 |
|
|
c_parser_omp_for (location_t loc, c_parser *parser)
|
8274 |
|
|
{
|
8275 |
|
|
tree block, clauses, ret;
|
8276 |
|
|
|
8277 |
|
|
clauses = c_parser_omp_all_clauses (parser, OMP_FOR_CLAUSE_MASK,
|
8278 |
|
|
"#pragma omp for");
|
8279 |
|
|
|
8280 |
|
|
block = c_begin_compound_stmt (true);
|
8281 |
|
|
ret = c_parser_omp_for_loop (loc, parser, clauses, NULL);
|
8282 |
|
|
block = c_end_compound_stmt (loc, block, true);
|
8283 |
|
|
add_stmt (block);
|
8284 |
|
|
|
8285 |
|
|
return ret;
|
8286 |
|
|
}
|
8287 |
|
|
|
8288 |
|
|
/* OpenMP 2.5:
|
8289 |
|
|
# pragma omp master new-line
|
8290 |
|
|
structured-block
|
8291 |
|
|
|
8292 |
|
|
LOC is the location of the #pragma token.
|
8293 |
|
|
*/
|
8294 |
|
|
|
8295 |
|
|
static tree
|
8296 |
|
|
c_parser_omp_master (location_t loc, c_parser *parser)
|
8297 |
|
|
{
|
8298 |
|
|
c_parser_skip_to_pragma_eol (parser);
|
8299 |
|
|
return c_finish_omp_master (loc, c_parser_omp_structured_block (parser));
|
8300 |
|
|
}
|
8301 |
|
|
|
8302 |
|
|
/* OpenMP 2.5:
|
8303 |
|
|
# pragma omp ordered new-line
|
8304 |
|
|
structured-block
|
8305 |
|
|
|
8306 |
|
|
LOC is the location of the #pragma itself.
|
8307 |
|
|
*/
|
8308 |
|
|
|
8309 |
|
|
static tree
|
8310 |
|
|
c_parser_omp_ordered (location_t loc, c_parser *parser)
|
8311 |
|
|
{
|
8312 |
|
|
c_parser_skip_to_pragma_eol (parser);
|
8313 |
|
|
return c_finish_omp_ordered (loc, c_parser_omp_structured_block (parser));
|
8314 |
|
|
}
|
8315 |
|
|
|
8316 |
|
|
/* OpenMP 2.5:
|
8317 |
|
|
|
8318 |
|
|
section-scope:
|
8319 |
|
|
{ section-sequence }
|
8320 |
|
|
|
8321 |
|
|
section-sequence:
|
8322 |
|
|
section-directive[opt] structured-block
|
8323 |
|
|
section-sequence section-directive structured-block
|
8324 |
|
|
|
8325 |
|
|
SECTIONS_LOC is the location of the #pragma omp sections. */
|
8326 |
|
|
|
8327 |
|
|
static tree
|
8328 |
|
|
c_parser_omp_sections_scope (location_t sections_loc, c_parser *parser)
|
8329 |
|
|
{
|
8330 |
|
|
tree stmt, substmt;
|
8331 |
|
|
bool error_suppress = false;
|
8332 |
|
|
location_t loc;
|
8333 |
|
|
|
8334 |
|
|
loc = c_parser_peek_token (parser)->location;
|
8335 |
|
|
if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
|
8336 |
|
|
{
|
8337 |
|
|
/* Avoid skipping until the end of the block. */
|
8338 |
|
|
parser->error = false;
|
8339 |
|
|
return NULL_TREE;
|
8340 |
|
|
}
|
8341 |
|
|
|
8342 |
|
|
stmt = push_stmt_list ();
|
8343 |
|
|
|
8344 |
|
|
if (c_parser_peek_token (parser)->pragma_kind != PRAGMA_OMP_SECTION)
|
8345 |
|
|
{
|
8346 |
|
|
substmt = push_stmt_list ();
|
8347 |
|
|
|
8348 |
|
|
while (1)
|
8349 |
|
|
{
|
8350 |
|
|
c_parser_statement (parser);
|
8351 |
|
|
|
8352 |
|
|
if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_OMP_SECTION)
|
8353 |
|
|
break;
|
8354 |
|
|
if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
|
8355 |
|
|
break;
|
8356 |
|
|
if (c_parser_next_token_is (parser, CPP_EOF))
|
8357 |
|
|
break;
|
8358 |
|
|
}
|
8359 |
|
|
|
8360 |
|
|
substmt = pop_stmt_list (substmt);
|
8361 |
|
|
substmt = build1 (OMP_SECTION, void_type_node, substmt);
|
8362 |
|
|
SET_EXPR_LOCATION (substmt, loc);
|
8363 |
|
|
add_stmt (substmt);
|
8364 |
|
|
}
|
8365 |
|
|
|
8366 |
|
|
while (1)
|
8367 |
|
|
{
|
8368 |
|
|
if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
|
8369 |
|
|
break;
|
8370 |
|
|
if (c_parser_next_token_is (parser, CPP_EOF))
|
8371 |
|
|
break;
|
8372 |
|
|
|
8373 |
|
|
loc = c_parser_peek_token (parser)->location;
|
8374 |
|
|
if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_OMP_SECTION)
|
8375 |
|
|
{
|
8376 |
|
|
c_parser_consume_pragma (parser);
|
8377 |
|
|
c_parser_skip_to_pragma_eol (parser);
|
8378 |
|
|
error_suppress = false;
|
8379 |
|
|
}
|
8380 |
|
|
else if (!error_suppress)
|
8381 |
|
|
{
|
8382 |
|
|
error_at (loc, "expected %<#pragma omp section%> or %<}%>");
|
8383 |
|
|
error_suppress = true;
|
8384 |
|
|
}
|
8385 |
|
|
|
8386 |
|
|
substmt = c_parser_omp_structured_block (parser);
|
8387 |
|
|
substmt = build1 (OMP_SECTION, void_type_node, substmt);
|
8388 |
|
|
SET_EXPR_LOCATION (substmt, loc);
|
8389 |
|
|
add_stmt (substmt);
|
8390 |
|
|
}
|
8391 |
|
|
c_parser_skip_until_found (parser, CPP_CLOSE_BRACE,
|
8392 |
|
|
"expected %<#pragma omp section%> or %<}%>");
|
8393 |
|
|
|
8394 |
|
|
substmt = pop_stmt_list (stmt);
|
8395 |
|
|
|
8396 |
|
|
stmt = make_node (OMP_SECTIONS);
|
8397 |
|
|
SET_EXPR_LOCATION (stmt, sections_loc);
|
8398 |
|
|
TREE_TYPE (stmt) = void_type_node;
|
8399 |
|
|
OMP_SECTIONS_BODY (stmt) = substmt;
|
8400 |
|
|
|
8401 |
|
|
return add_stmt (stmt);
|
8402 |
|
|
}
|
8403 |
|
|
|
8404 |
|
|
/* OpenMP 2.5:
|
8405 |
|
|
# pragma omp sections sections-clause[optseq] newline
|
8406 |
|
|
sections-scope
|
8407 |
|
|
|
8408 |
|
|
LOC is the location of the #pragma token.
|
8409 |
|
|
*/
|
8410 |
|
|
|
8411 |
|
|
#define OMP_SECTIONS_CLAUSE_MASK \
|
8412 |
|
|
( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
|
8413 |
|
|
| (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
|
8414 |
|
|
| (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
|
8415 |
|
|
| (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
|
8416 |
|
|
| (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
|
8417 |
|
|
|
8418 |
|
|
static tree
|
8419 |
|
|
c_parser_omp_sections (location_t loc, c_parser *parser)
|
8420 |
|
|
{
|
8421 |
|
|
tree block, clauses, ret;
|
8422 |
|
|
|
8423 |
|
|
clauses = c_parser_omp_all_clauses (parser, OMP_SECTIONS_CLAUSE_MASK,
|
8424 |
|
|
"#pragma omp sections");
|
8425 |
|
|
|
8426 |
|
|
block = c_begin_compound_stmt (true);
|
8427 |
|
|
ret = c_parser_omp_sections_scope (loc, parser);
|
8428 |
|
|
if (ret)
|
8429 |
|
|
OMP_SECTIONS_CLAUSES (ret) = clauses;
|
8430 |
|
|
block = c_end_compound_stmt (loc, block, true);
|
8431 |
|
|
add_stmt (block);
|
8432 |
|
|
|
8433 |
|
|
return ret;
|
8434 |
|
|
}
|
8435 |
|
|
|
8436 |
|
|
/* OpenMP 2.5:
|
8437 |
|
|
# pragma parallel parallel-clause new-line
|
8438 |
|
|
# pragma parallel for parallel-for-clause new-line
|
8439 |
|
|
# pragma parallel sections parallel-sections-clause new-line
|
8440 |
|
|
|
8441 |
|
|
LOC is the location of the #pragma token.
|
8442 |
|
|
*/
|
8443 |
|
|
|
8444 |
|
|
#define OMP_PARALLEL_CLAUSE_MASK \
|
8445 |
|
|
( (1u << PRAGMA_OMP_CLAUSE_IF) \
|
8446 |
|
|
| (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
|
8447 |
|
|
| (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
|
8448 |
|
|
| (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
|
8449 |
|
|
| (1u << PRAGMA_OMP_CLAUSE_SHARED) \
|
8450 |
|
|
| (1u << PRAGMA_OMP_CLAUSE_COPYIN) \
|
8451 |
|
|
| (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
|
8452 |
|
|
| (1u << PRAGMA_OMP_CLAUSE_NUM_THREADS))
|
8453 |
|
|
|
8454 |
|
|
static tree
|
8455 |
|
|
c_parser_omp_parallel (location_t loc, c_parser *parser)
|
8456 |
|
|
{
|
8457 |
|
|
enum pragma_kind p_kind = PRAGMA_OMP_PARALLEL;
|
8458 |
|
|
const char *p_name = "#pragma omp parallel";
|
8459 |
|
|
tree stmt, clauses, par_clause, ws_clause, block;
|
8460 |
|
|
unsigned int mask = OMP_PARALLEL_CLAUSE_MASK;
|
8461 |
|
|
|
8462 |
|
|
if (c_parser_next_token_is_keyword (parser, RID_FOR))
|
8463 |
|
|
{
|
8464 |
|
|
c_parser_consume_token (parser);
|
8465 |
|
|
p_kind = PRAGMA_OMP_PARALLEL_FOR;
|
8466 |
|
|
p_name = "#pragma omp parallel for";
|
8467 |
|
|
mask |= OMP_FOR_CLAUSE_MASK;
|
8468 |
|
|
mask &= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT);
|
8469 |
|
|
}
|
8470 |
|
|
else if (c_parser_next_token_is (parser, CPP_NAME))
|
8471 |
|
|
{
|
8472 |
|
|
const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
|
8473 |
|
|
if (strcmp (p, "sections") == 0)
|
8474 |
|
|
{
|
8475 |
|
|
c_parser_consume_token (parser);
|
8476 |
|
|
p_kind = PRAGMA_OMP_PARALLEL_SECTIONS;
|
8477 |
|
|
p_name = "#pragma omp parallel sections";
|
8478 |
|
|
mask |= OMP_SECTIONS_CLAUSE_MASK;
|
8479 |
|
|
mask &= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT);
|
8480 |
|
|
}
|
8481 |
|
|
}
|
8482 |
|
|
|
8483 |
|
|
clauses = c_parser_omp_all_clauses (parser, mask, p_name);
|
8484 |
|
|
|
8485 |
|
|
switch (p_kind)
|
8486 |
|
|
{
|
8487 |
|
|
case PRAGMA_OMP_PARALLEL:
|
8488 |
|
|
block = c_begin_omp_parallel ();
|
8489 |
|
|
c_parser_statement (parser);
|
8490 |
|
|
stmt = c_finish_omp_parallel (loc, clauses, block);
|
8491 |
|
|
break;
|
8492 |
|
|
|
8493 |
|
|
case PRAGMA_OMP_PARALLEL_FOR:
|
8494 |
|
|
block = c_begin_omp_parallel ();
|
8495 |
|
|
c_split_parallel_clauses (loc, clauses, &par_clause, &ws_clause);
|
8496 |
|
|
c_parser_omp_for_loop (loc, parser, ws_clause, &par_clause);
|
8497 |
|
|
stmt = c_finish_omp_parallel (loc, par_clause, block);
|
8498 |
|
|
OMP_PARALLEL_COMBINED (stmt) = 1;
|
8499 |
|
|
break;
|
8500 |
|
|
|
8501 |
|
|
case PRAGMA_OMP_PARALLEL_SECTIONS:
|
8502 |
|
|
block = c_begin_omp_parallel ();
|
8503 |
|
|
c_split_parallel_clauses (loc, clauses, &par_clause, &ws_clause);
|
8504 |
|
|
stmt = c_parser_omp_sections_scope (loc, parser);
|
8505 |
|
|
if (stmt)
|
8506 |
|
|
OMP_SECTIONS_CLAUSES (stmt) = ws_clause;
|
8507 |
|
|
stmt = c_finish_omp_parallel (loc, par_clause, block);
|
8508 |
|
|
OMP_PARALLEL_COMBINED (stmt) = 1;
|
8509 |
|
|
break;
|
8510 |
|
|
|
8511 |
|
|
default:
|
8512 |
|
|
gcc_unreachable ();
|
8513 |
|
|
}
|
8514 |
|
|
|
8515 |
|
|
return stmt;
|
8516 |
|
|
}
|
8517 |
|
|
|
8518 |
|
|
/* OpenMP 2.5:
|
8519 |
|
|
# pragma omp single single-clause[optseq] new-line
|
8520 |
|
|
structured-block
|
8521 |
|
|
|
8522 |
|
|
LOC is the location of the #pragma.
|
8523 |
|
|
*/
|
8524 |
|
|
|
8525 |
|
|
#define OMP_SINGLE_CLAUSE_MASK \
|
8526 |
|
|
( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
|
8527 |
|
|
| (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
|
8528 |
|
|
| (1u << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
|
8529 |
|
|
| (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
|
8530 |
|
|
|
8531 |
|
|
static tree
|
8532 |
|
|
c_parser_omp_single (location_t loc, c_parser *parser)
|
8533 |
|
|
{
|
8534 |
|
|
tree stmt = make_node (OMP_SINGLE);
|
8535 |
|
|
SET_EXPR_LOCATION (stmt, loc);
|
8536 |
|
|
TREE_TYPE (stmt) = void_type_node;
|
8537 |
|
|
|
8538 |
|
|
OMP_SINGLE_CLAUSES (stmt)
|
8539 |
|
|
= c_parser_omp_all_clauses (parser, OMP_SINGLE_CLAUSE_MASK,
|
8540 |
|
|
"#pragma omp single");
|
8541 |
|
|
OMP_SINGLE_BODY (stmt) = c_parser_omp_structured_block (parser);
|
8542 |
|
|
|
8543 |
|
|
return add_stmt (stmt);
|
8544 |
|
|
}
|
8545 |
|
|
|
8546 |
|
|
/* OpenMP 3.0:
|
8547 |
|
|
# pragma omp task task-clause[optseq] new-line
|
8548 |
|
|
|
8549 |
|
|
LOC is the location of the #pragma.
|
8550 |
|
|
*/
|
8551 |
|
|
|
8552 |
|
|
#define OMP_TASK_CLAUSE_MASK \
|
8553 |
|
|
( (1u << PRAGMA_OMP_CLAUSE_IF) \
|
8554 |
|
|
| (1u << PRAGMA_OMP_CLAUSE_UNTIED) \
|
8555 |
|
|
| (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
|
8556 |
|
|
| (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
|
8557 |
|
|
| (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
|
8558 |
|
|
| (1u << PRAGMA_OMP_CLAUSE_SHARED))
|
8559 |
|
|
|
8560 |
|
|
static tree
|
8561 |
|
|
c_parser_omp_task (location_t loc, c_parser *parser)
|
8562 |
|
|
{
|
8563 |
|
|
tree clauses, block;
|
8564 |
|
|
|
8565 |
|
|
clauses = c_parser_omp_all_clauses (parser, OMP_TASK_CLAUSE_MASK,
|
8566 |
|
|
"#pragma omp task");
|
8567 |
|
|
|
8568 |
|
|
block = c_begin_omp_task ();
|
8569 |
|
|
c_parser_statement (parser);
|
8570 |
|
|
return c_finish_omp_task (loc, clauses, block);
|
8571 |
|
|
}
|
8572 |
|
|
|
8573 |
|
|
/* OpenMP 3.0:
|
8574 |
|
|
# pragma omp taskwait new-line
|
8575 |
|
|
*/
|
8576 |
|
|
|
8577 |
|
|
static void
|
8578 |
|
|
c_parser_omp_taskwait (c_parser *parser)
|
8579 |
|
|
{
|
8580 |
|
|
location_t loc = c_parser_peek_token (parser)->location;
|
8581 |
|
|
c_parser_consume_pragma (parser);
|
8582 |
|
|
c_parser_skip_to_pragma_eol (parser);
|
8583 |
|
|
|
8584 |
|
|
c_finish_omp_taskwait (loc);
|
8585 |
|
|
}
|
8586 |
|
|
|
8587 |
|
|
/* Main entry point to parsing most OpenMP pragmas. */
|
8588 |
|
|
|
8589 |
|
|
static void
|
8590 |
|
|
c_parser_omp_construct (c_parser *parser)
|
8591 |
|
|
{
|
8592 |
|
|
enum pragma_kind p_kind;
|
8593 |
|
|
location_t loc;
|
8594 |
|
|
tree stmt;
|
8595 |
|
|
|
8596 |
|
|
loc = c_parser_peek_token (parser)->location;
|
8597 |
|
|
p_kind = c_parser_peek_token (parser)->pragma_kind;
|
8598 |
|
|
c_parser_consume_pragma (parser);
|
8599 |
|
|
|
8600 |
|
|
switch (p_kind)
|
8601 |
|
|
{
|
8602 |
|
|
case PRAGMA_OMP_ATOMIC:
|
8603 |
|
|
c_parser_omp_atomic (loc, parser);
|
8604 |
|
|
return;
|
8605 |
|
|
case PRAGMA_OMP_CRITICAL:
|
8606 |
|
|
stmt = c_parser_omp_critical (loc, parser);
|
8607 |
|
|
break;
|
8608 |
|
|
case PRAGMA_OMP_FOR:
|
8609 |
|
|
stmt = c_parser_omp_for (loc, parser);
|
8610 |
|
|
break;
|
8611 |
|
|
case PRAGMA_OMP_MASTER:
|
8612 |
|
|
stmt = c_parser_omp_master (loc, parser);
|
8613 |
|
|
break;
|
8614 |
|
|
case PRAGMA_OMP_ORDERED:
|
8615 |
|
|
stmt = c_parser_omp_ordered (loc, parser);
|
8616 |
|
|
break;
|
8617 |
|
|
case PRAGMA_OMP_PARALLEL:
|
8618 |
|
|
stmt = c_parser_omp_parallel (loc, parser);
|
8619 |
|
|
break;
|
8620 |
|
|
case PRAGMA_OMP_SECTIONS:
|
8621 |
|
|
stmt = c_parser_omp_sections (loc, parser);
|
8622 |
|
|
break;
|
8623 |
|
|
case PRAGMA_OMP_SINGLE:
|
8624 |
|
|
stmt = c_parser_omp_single (loc, parser);
|
8625 |
|
|
break;
|
8626 |
|
|
case PRAGMA_OMP_TASK:
|
8627 |
|
|
stmt = c_parser_omp_task (loc, parser);
|
8628 |
|
|
break;
|
8629 |
|
|
default:
|
8630 |
|
|
gcc_unreachable ();
|
8631 |
|
|
}
|
8632 |
|
|
|
8633 |
|
|
if (stmt)
|
8634 |
|
|
gcc_assert (EXPR_LOCATION (stmt) != UNKNOWN_LOCATION);
|
8635 |
|
|
}
|
8636 |
|
|
|
8637 |
|
|
|
8638 |
|
|
/* OpenMP 2.5:
|
8639 |
|
|
# pragma omp threadprivate (variable-list) */
|
8640 |
|
|
|
8641 |
|
|
static void
|
8642 |
|
|
c_parser_omp_threadprivate (c_parser *parser)
|
8643 |
|
|
{
|
8644 |
|
|
tree vars, t;
|
8645 |
|
|
location_t loc;
|
8646 |
|
|
|
8647 |
|
|
c_parser_consume_pragma (parser);
|
8648 |
|
|
loc = c_parser_peek_token (parser)->location;
|
8649 |
|
|
vars = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL);
|
8650 |
|
|
|
8651 |
|
|
/* Mark every variable in VARS to be assigned thread local storage. */
|
8652 |
|
|
for (t = vars; t; t = TREE_CHAIN (t))
|
8653 |
|
|
{
|
8654 |
|
|
tree v = TREE_PURPOSE (t);
|
8655 |
|
|
|
8656 |
|
|
/* FIXME diagnostics: Ideally we should keep individual
|
8657 |
|
|
locations for all the variables in the var list to make the
|
8658 |
|
|
following errors more precise. Perhaps
|
8659 |
|
|
c_parser_omp_var_list_parens() should construct a list of
|
8660 |
|
|
locations to go along with the var list. */
|
8661 |
|
|
|
8662 |
|
|
/* If V had already been marked threadprivate, it doesn't matter
|
8663 |
|
|
whether it had been used prior to this point. */
|
8664 |
|
|
if (TREE_CODE (v) != VAR_DECL)
|
8665 |
|
|
error_at (loc, "%qD is not a variable", v);
|
8666 |
|
|
else if (TREE_USED (v) && !C_DECL_THREADPRIVATE_P (v))
|
8667 |
|
|
error_at (loc, "%qE declared %<threadprivate%> after first use", v);
|
8668 |
|
|
else if (! TREE_STATIC (v) && ! DECL_EXTERNAL (v))
|
8669 |
|
|
error_at (loc, "automatic variable %qE cannot be %<threadprivate%>", v);
|
8670 |
|
|
else if (TREE_TYPE (v) == error_mark_node)
|
8671 |
|
|
;
|
8672 |
|
|
else if (! COMPLETE_TYPE_P (TREE_TYPE (v)))
|
8673 |
|
|
error_at (loc, "%<threadprivate%> %qE has incomplete type", v);
|
8674 |
|
|
else
|
8675 |
|
|
{
|
8676 |
|
|
if (! DECL_THREAD_LOCAL_P (v))
|
8677 |
|
|
{
|
8678 |
|
|
DECL_TLS_MODEL (v) = decl_default_tls_model (v);
|
8679 |
|
|
/* If rtl has been already set for this var, call
|
8680 |
|
|
make_decl_rtl once again, so that encode_section_info
|
8681 |
|
|
has a chance to look at the new decl flags. */
|
8682 |
|
|
if (DECL_RTL_SET_P (v))
|
8683 |
|
|
make_decl_rtl (v);
|
8684 |
|
|
}
|
8685 |
|
|
C_DECL_THREADPRIVATE_P (v) = 1;
|
8686 |
|
|
}
|
8687 |
|
|
}
|
8688 |
|
|
|
8689 |
|
|
c_parser_skip_to_pragma_eol (parser);
|
8690 |
|
|
}
|
8691 |
|
|
|
8692 |
|
|
|
8693 |
|
|
/* Parse a single source file. */
|
8694 |
|
|
|
8695 |
|
|
void
|
8696 |
|
|
c_parse_file (void)
|
8697 |
|
|
{
|
8698 |
|
|
/* Use local storage to begin. If the first token is a pragma, parse it.
|
8699 |
|
|
If it is #pragma GCC pch_preprocess, then this will load a PCH file
|
8700 |
|
|
which will cause garbage collection. */
|
8701 |
|
|
c_parser tparser;
|
8702 |
|
|
|
8703 |
|
|
memset (&tparser, 0, sizeof tparser);
|
8704 |
|
|
the_parser = &tparser;
|
8705 |
|
|
|
8706 |
|
|
if (c_parser_peek_token (&tparser)->pragma_kind == PRAGMA_GCC_PCH_PREPROCESS)
|
8707 |
|
|
c_parser_pragma_pch_preprocess (&tparser);
|
8708 |
|
|
|
8709 |
|
|
the_parser = GGC_NEW (c_parser);
|
8710 |
|
|
*the_parser = tparser;
|
8711 |
|
|
|
8712 |
|
|
/* Initialize EH, if we've been told to do so. */
|
8713 |
|
|
if (flag_exceptions)
|
8714 |
|
|
using_eh_for_cleanups ();
|
8715 |
|
|
|
8716 |
|
|
c_parser_translation_unit (the_parser);
|
8717 |
|
|
the_parser = NULL;
|
8718 |
|
|
}
|
8719 |
|
|
|
8720 |
|
|
#include "gt-c-parser.h"
|