]>
Commit | Line | Data |
---|---|---|
27bf414c | 1 | /* Parser for C and Objective-C. |
23a5b65a | 2 | Copyright (C) 1987-2014 Free Software Foundation, Inc. |
27bf414c JM |
3 | |
4 | Parser actions based on the old Bison parser; structure somewhat | |
5 | influenced by and fragments based on the C++ parser. | |
6 | ||
7 | This file is part of GCC. | |
8 | ||
9 | GCC is free software; you can redistribute it and/or modify it under | |
10 | the terms of the GNU General Public License as published by the Free | |
9dcd6f09 | 11 | Software Foundation; either version 3, or (at your option) any later |
27bf414c JM |
12 | version. |
13 | ||
14 | GCC is distributed in the hope that it will be useful, but WITHOUT ANY | |
15 | WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
16 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
17 | for more details. | |
18 | ||
19 | You should have received a copy of the GNU General Public License | |
9dcd6f09 NC |
20 | along with GCC; see the file COPYING3. If not see |
21 | <http://www.gnu.org/licenses/>. */ | |
27bf414c JM |
22 | |
23 | /* TODO: | |
24 | ||
25 | Make sure all relevant comments, and all relevant code from all | |
26 | actions, brought over from old parser. Verify exact correspondence | |
27 | of syntax accepted. | |
28 | ||
29 | Add testcases covering every input symbol in every state in old and | |
30 | new parsers. | |
31 | ||
32 | Include full syntax for GNU C, including erroneous cases accepted | |
33 | with error messages, in syntax productions in comments. | |
34 | ||
35 | Make more diagnostics in the front end generally take an explicit | |
36 | location rather than implicitly using input_location. */ | |
37 | ||
38 | #include "config.h" | |
39 | #include "system.h" | |
40 | #include "coretypes.h" | |
f4ce02c5 | 41 | #include "tm.h" /* For rtl.h: needs enum reg_class. */ |
27bf414c | 42 | #include "tree.h" |
d8a2d370 DN |
43 | #include "stringpool.h" |
44 | #include "attribs.h" | |
45 | #include "stor-layout.h" | |
46 | #include "varasm.h" | |
47 | #include "trans-mem.h" | |
27bf414c JM |
48 | #include "langhooks.h" |
49 | #include "input.h" | |
50 | #include "cpplib.h" | |
51 | #include "timevar.h" | |
39dabefd | 52 | #include "c-family/c-pragma.h" |
27bf414c | 53 | #include "c-tree.h" |
acf0174b | 54 | #include "c-lang.h" |
27bf414c | 55 | #include "flags.h" |
27bf414c | 56 | #include "ggc.h" |
39dabefd | 57 | #include "c-family/c-common.h" |
61d3ce20 | 58 | #include "c-family/c-objc.h" |
bc4071dd RH |
59 | #include "vec.h" |
60 | #include "target.h" | |
474eccc6 | 61 | #include "cgraph.h" |
68a607d8 | 62 | #include "plugin.h" |
0645c1a2 | 63 | #include "omp-low.h" |
9b2b7279 | 64 | #include "builtins.h" |
27bf414c JM |
65 | |
66 | \f | |
27bf414c JM |
67 | /* Initialization routine for this file. */ |
68 | ||
69 | void | |
70 | c_parse_init (void) | |
71 | { | |
72 | /* The only initialization required is of the reserved word | |
73 | identifiers. */ | |
74 | unsigned int i; | |
75 | tree id; | |
eea1139b | 76 | int mask = 0; |
27bf414c | 77 | |
36c5e70a BE |
78 | /* Make sure RID_MAX hasn't grown past the 8 bits used to hold the keyword in |
79 | the c_token structure. */ | |
80 | gcc_assert (RID_MAX <= 255); | |
81 | ||
eea1139b ILT |
82 | mask |= D_CXXONLY; |
83 | if (!flag_isoc99) | |
84 | mask |= D_C99; | |
85 | if (flag_no_asm) | |
86 | { | |
87 | mask |= D_ASM | D_EXT; | |
88 | if (!flag_isoc99) | |
89 | mask |= D_EXT89; | |
90 | } | |
27bf414c | 91 | if (!c_dialect_objc ()) |
eea1139b | 92 | mask |= D_OBJC | D_CXX_OBJC; |
27bf414c | 93 | |
766090c2 | 94 | ridpointers = ggc_cleared_vec_alloc<tree> ((int) RID_MAX); |
eea1139b | 95 | for (i = 0; i < num_c_common_reswords; i++) |
27bf414c JM |
96 | { |
97 | /* If a keyword is disabled, do not enter it into the table | |
98 | and so create a canonical spelling that isn't a keyword. */ | |
eea1139b ILT |
99 | if (c_common_reswords[i].disable & mask) |
100 | { | |
101 | if (warn_cxx_compat | |
102 | && (c_common_reswords[i].disable & D_CXXWARN)) | |
103 | { | |
104 | id = get_identifier (c_common_reswords[i].word); | |
105 | C_SET_RID_CODE (id, RID_CXX_COMPAT_WARN); | |
106 | C_IS_RESERVED_WORD (id) = 1; | |
107 | } | |
108 | continue; | |
109 | } | |
27bf414c | 110 | |
eea1139b ILT |
111 | id = get_identifier (c_common_reswords[i].word); |
112 | C_SET_RID_CODE (id, c_common_reswords[i].rid); | |
27bf414c | 113 | C_IS_RESERVED_WORD (id) = 1; |
eea1139b | 114 | ridpointers [(int) c_common_reswords[i].rid] = id; |
27bf414c JM |
115 | } |
116 | } | |
117 | \f | |
118 | /* The C lexer intermediates between the lexer in cpplib and c-lex.c | |
119 | and the C parser. Unlike the C++ lexer, the parser structure | |
120 | stores the lexer information instead of using a separate structure. | |
121 | Identifiers are separated into ordinary identifiers, type names, | |
122 | keywords and some other Objective-C types of identifiers, and some | |
123 | look-ahead is maintained. | |
124 | ||
125 | ??? It might be a good idea to lex the whole file up front (as for | |
126 | C++). It would then be possible to share more of the C and C++ | |
127 | lexer code, if desired. */ | |
128 | ||
129 | /* The following local token type is used. */ | |
130 | ||
131 | /* A keyword. */ | |
132 | #define CPP_KEYWORD ((enum cpp_ttype) (N_TTYPES + 1)) | |
133 | ||
27bf414c JM |
134 | /* More information about the type of a CPP_NAME token. */ |
135 | typedef enum c_id_kind { | |
136 | /* An ordinary identifier. */ | |
137 | C_ID_ID, | |
138 | /* An identifier declared as a typedef name. */ | |
139 | C_ID_TYPENAME, | |
140 | /* An identifier declared as an Objective-C class name. */ | |
141 | C_ID_CLASSNAME, | |
36c5e70a BE |
142 | /* An address space identifier. */ |
143 | C_ID_ADDRSPACE, | |
27bf414c JM |
144 | /* Not an identifier. */ |
145 | C_ID_NONE | |
146 | } c_id_kind; | |
147 | ||
148 | /* A single C token after string literal concatenation and conversion | |
149 | of preprocessing tokens to tokens. */ | |
d1b38208 | 150 | typedef struct GTY (()) c_token { |
27bf414c JM |
151 | /* The kind of token. */ |
152 | ENUM_BITFIELD (cpp_ttype) type : 8; | |
153 | /* If this token is a CPP_NAME, this value indicates whether also | |
154 | declared as some kind of type. Otherwise, it is C_ID_NONE. */ | |
155 | ENUM_BITFIELD (c_id_kind) id_kind : 8; | |
156 | /* If this token is a keyword, this value indicates which keyword. | |
157 | Otherwise, this value is RID_MAX. */ | |
158 | ENUM_BITFIELD (rid) keyword : 8; | |
bc4071dd RH |
159 | /* If this token is a CPP_PRAGMA, this indicates the pragma that |
160 | was seen. Otherwise it is PRAGMA_NONE. */ | |
13fa1171 | 161 | ENUM_BITFIELD (pragma_kind) pragma_kind : 8; |
27bf414c JM |
162 | /* The location at which this token was found. */ |
163 | location_t location; | |
8415f317 NF |
164 | /* The value associated with this token, if any. */ |
165 | tree value; | |
27bf414c JM |
166 | } c_token; |
167 | ||
168 | /* A parser structure recording information about the state and | |
169 | context of parsing. Includes lexer information with up to two | |
170 | tokens of look-ahead; more are not needed for C. */ | |
d1b38208 | 171 | typedef struct GTY(()) c_parser { |
27bf414c | 172 | /* The look-ahead tokens. */ |
acf0174b JJ |
173 | c_token * GTY((skip)) tokens; |
174 | /* Buffer for look-ahead tokens. */ | |
175 | c_token tokens_buf[2]; | |
176 | /* How many look-ahead tokens are available (0, 1 or 2, or | |
177 | more if parsing from pre-lexed tokens). */ | |
178 | unsigned int tokens_avail; | |
27bf414c JM |
179 | /* True if a syntax error is being recovered from; false otherwise. |
180 | c_parser_error sets this flag. It should clear this flag when | |
181 | enough tokens have been consumed to recover from the error. */ | |
182 | BOOL_BITFIELD error : 1; | |
bc4071dd RH |
183 | /* True if we're processing a pragma, and shouldn't automatically |
184 | consume CPP_PRAGMA_EOL. */ | |
185 | BOOL_BITFIELD in_pragma : 1; | |
b4b56033 MLI |
186 | /* True if we're parsing the outermost block of an if statement. */ |
187 | BOOL_BITFIELD in_if_block : 1; | |
46c2514e TT |
188 | /* True if we want to lex an untranslated string. */ |
189 | BOOL_BITFIELD lex_untranslated_string : 1; | |
1973201f | 190 | |
0bacb8c7 | 191 | /* Objective-C specific parser/lexer information. */ |
1973201f NP |
192 | |
193 | /* True if we are in a context where the Objective-C "PQ" keywords | |
194 | are considered keywords. */ | |
0bacb8c7 | 195 | BOOL_BITFIELD objc_pq_context : 1; |
f05b9d93 NP |
196 | /* True if we are parsing a (potential) Objective-C foreach |
197 | statement. This is set to true after we parsed 'for (' and while | |
198 | we wait for 'in' or ';' to decide if it's a standard C for loop or an | |
199 | Objective-C foreach loop. */ | |
200 | BOOL_BITFIELD objc_could_be_foreach_context : 1; | |
0bacb8c7 TT |
201 | /* The following flag is needed to contextualize Objective-C lexical |
202 | analysis. In some cases (e.g., 'int NSObject;'), it is | |
203 | undesirable to bind an identifier to an Objective-C class, even | |
204 | if a class with that name exists. */ | |
205 | BOOL_BITFIELD objc_need_raw_identifier : 1; | |
0a35513e AH |
206 | /* Nonzero if we're processing a __transaction statement. The value |
207 | is 1 | TM_STMT_ATTR_*. */ | |
208 | unsigned int in_transaction : 4; | |
668ea4b1 IS |
209 | /* True if we are in a context where the Objective-C "Property attribute" |
210 | keywords are valid. */ | |
211 | BOOL_BITFIELD objc_property_attr_context : 1; | |
41958c28 BI |
212 | |
213 | /* Cilk Plus specific parser/lexer information. */ | |
214 | ||
215 | /* Buffer to hold all the tokens from parsing the vector attribute for the | |
216 | SIMD-enabled functions (formerly known as elemental functions). */ | |
217 | vec <c_token, va_gc> *cilk_simd_fn_tokens; | |
27bf414c JM |
218 | } c_parser; |
219 | ||
bc4071dd RH |
220 | |
221 | /* The actual parser and external interface. ??? Does this need to be | |
222 | garbage-collected? */ | |
223 | ||
224 | static GTY (()) c_parser *the_parser; | |
225 | ||
27bf414c JM |
226 | /* Read in and lex a single token, storing it in *TOKEN. */ |
227 | ||
228 | static void | |
0bacb8c7 | 229 | c_lex_one_token (c_parser *parser, c_token *token) |
27bf414c JM |
230 | { |
231 | timevar_push (TV_LEX); | |
bc4071dd | 232 | |
46c2514e TT |
233 | token->type = c_lex_with_flags (&token->value, &token->location, NULL, |
234 | (parser->lex_untranslated_string | |
235 | ? C_LEX_STRING_NO_TRANSLATE : 0)); | |
bc4071dd RH |
236 | token->id_kind = C_ID_NONE; |
237 | token->keyword = RID_MAX; | |
238 | token->pragma_kind = PRAGMA_NONE; | |
bc4071dd | 239 | |
27bf414c JM |
240 | switch (token->type) |
241 | { | |
242 | case CPP_NAME: | |
27bf414c JM |
243 | { |
244 | tree decl; | |
245 | ||
0bacb8c7 TT |
246 | bool objc_force_identifier = parser->objc_need_raw_identifier; |
247 | if (c_dialect_objc ()) | |
248 | parser->objc_need_raw_identifier = false; | |
27bf414c JM |
249 | |
250 | if (C_IS_RESERVED_WORD (token->value)) | |
251 | { | |
252 | enum rid rid_code = C_RID_CODE (token->value); | |
253 | ||
eea1139b ILT |
254 | if (rid_code == RID_CXX_COMPAT_WARN) |
255 | { | |
3ba09659 AH |
256 | warning_at (token->location, |
257 | OPT_Wc___compat, | |
88388a52 JM |
258 | "identifier %qE conflicts with C++ keyword", |
259 | token->value); | |
eea1139b | 260 | } |
36c5e70a BE |
261 | else if (rid_code >= RID_FIRST_ADDR_SPACE |
262 | && rid_code <= RID_LAST_ADDR_SPACE) | |
263 | { | |
264 | token->id_kind = C_ID_ADDRSPACE; | |
265 | token->keyword = rid_code; | |
266 | break; | |
267 | } | |
1973201f | 268 | else if (c_dialect_objc () && OBJC_IS_PQ_KEYWORD (rid_code)) |
27bf414c | 269 | { |
1973201f NP |
270 | /* We found an Objective-C "pq" keyword (in, out, |
271 | inout, bycopy, byref, oneway). They need special | |
272 | care because the interpretation depends on the | |
d853ee42 | 273 | context. */ |
1973201f | 274 | if (parser->objc_pq_context) |
27bf414c | 275 | { |
27bf414c JM |
276 | token->type = CPP_KEYWORD; |
277 | token->keyword = rid_code; | |
278 | break; | |
279 | } | |
f05b9d93 NP |
280 | else if (parser->objc_could_be_foreach_context |
281 | && rid_code == RID_IN) | |
282 | { | |
283 | /* We are in Objective-C, inside a (potential) | |
284 | foreach context (which means after having | |
285 | parsed 'for (', but before having parsed ';'), | |
286 | and we found 'in'. We consider it the keyword | |
287 | which terminates the declaration at the | |
288 | beginning of a foreach-statement. Note that | |
289 | this means you can't use 'in' for anything else | |
290 | in that context; in particular, in Objective-C | |
291 | you can't use 'in' as the name of the running | |
292 | variable in a C for loop. We could potentially | |
293 | try to add code here to disambiguate, but it | |
d853ee42 | 294 | seems a reasonable limitation. */ |
f05b9d93 NP |
295 | token->type = CPP_KEYWORD; |
296 | token->keyword = rid_code; | |
297 | break; | |
298 | } | |
1973201f NP |
299 | /* Else, "pq" keywords outside of the "pq" context are |
300 | not keywords, and we fall through to the code for | |
d853ee42 | 301 | normal tokens. */ |
1973201f | 302 | } |
668ea4b1 IS |
303 | else if (c_dialect_objc () && OBJC_IS_PATTR_KEYWORD (rid_code)) |
304 | { | |
d853ee42 NP |
305 | /* We found an Objective-C "property attribute" |
306 | keyword (getter, setter, readonly, etc). These are | |
668ea4b1 IS |
307 | only valid in the property context. */ |
308 | if (parser->objc_property_attr_context) | |
309 | { | |
310 | token->type = CPP_KEYWORD; | |
311 | token->keyword = rid_code; | |
312 | break; | |
313 | } | |
314 | /* Else they are not special keywords. | |
315 | */ | |
316 | } | |
1973201f NP |
317 | else if (c_dialect_objc () |
318 | && (OBJC_IS_AT_KEYWORD (rid_code) | |
319 | || OBJC_IS_CXX_KEYWORD (rid_code))) | |
320 | { | |
321 | /* We found one of the Objective-C "@" keywords (defs, | |
322 | selector, synchronized, etc) or one of the | |
323 | Objective-C "cxx" keywords (class, private, | |
324 | protected, public, try, catch, throw) without a | |
325 | preceding '@' sign. Do nothing and fall through to | |
326 | the code for normal tokens (in C++ we would still | |
d853ee42 | 327 | consider the CXX ones keywords, but not in C). */ |
1973201f | 328 | ; |
27bf414c JM |
329 | } |
330 | else | |
331 | { | |
27bf414c JM |
332 | token->type = CPP_KEYWORD; |
333 | token->keyword = rid_code; | |
334 | break; | |
335 | } | |
336 | } | |
337 | ||
338 | decl = lookup_name (token->value); | |
339 | if (decl) | |
340 | { | |
341 | if (TREE_CODE (decl) == TYPE_DECL) | |
342 | { | |
343 | token->id_kind = C_ID_TYPENAME; | |
344 | break; | |
345 | } | |
346 | } | |
347 | else if (c_dialect_objc ()) | |
348 | { | |
349 | tree objc_interface_decl = objc_is_class_name (token->value); | |
350 | /* Objective-C class names are in the same namespace as | |
351 | variables and typedefs, and hence are shadowed by local | |
352 | declarations. */ | |
353 | if (objc_interface_decl | |
0d8a2528 | 354 | && (!objc_force_identifier || global_bindings_p ())) |
27bf414c JM |
355 | { |
356 | token->value = objc_interface_decl; | |
357 | token->id_kind = C_ID_CLASSNAME; | |
358 | break; | |
359 | } | |
360 | } | |
bc4071dd | 361 | token->id_kind = C_ID_ID; |
27bf414c | 362 | } |
27bf414c JM |
363 | break; |
364 | case CPP_AT_NAME: | |
365 | /* This only happens in Objective-C; it must be a keyword. */ | |
366 | token->type = CPP_KEYWORD; | |
49b91f05 NP |
367 | switch (C_RID_CODE (token->value)) |
368 | { | |
369 | /* Replace 'class' with '@class', 'private' with '@private', | |
370 | etc. This prevents confusion with the C++ keyword | |
371 | 'class', and makes the tokens consistent with other | |
372 | Objective-C 'AT' keywords. For example '@class' is | |
373 | reported as RID_AT_CLASS which is consistent with | |
374 | '@synchronized', which is reported as | |
375 | RID_AT_SYNCHRONIZED. | |
376 | */ | |
377 | case RID_CLASS: token->keyword = RID_AT_CLASS; break; | |
378 | case RID_PRIVATE: token->keyword = RID_AT_PRIVATE; break; | |
379 | case RID_PROTECTED: token->keyword = RID_AT_PROTECTED; break; | |
380 | case RID_PUBLIC: token->keyword = RID_AT_PUBLIC; break; | |
381 | case RID_THROW: token->keyword = RID_AT_THROW; break; | |
382 | case RID_TRY: token->keyword = RID_AT_TRY; break; | |
383 | case RID_CATCH: token->keyword = RID_AT_CATCH; break; | |
384 | default: token->keyword = C_RID_CODE (token->value); | |
385 | } | |
27bf414c JM |
386 | break; |
387 | case CPP_COLON: | |
388 | case CPP_COMMA: | |
389 | case CPP_CLOSE_PAREN: | |
390 | case CPP_SEMICOLON: | |
391 | /* These tokens may affect the interpretation of any identifiers | |
392 | following, if doing Objective-C. */ | |
0bacb8c7 TT |
393 | if (c_dialect_objc ()) |
394 | parser->objc_need_raw_identifier = false; | |
bc4071dd RH |
395 | break; |
396 | case CPP_PRAGMA: | |
397 | /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */ | |
d75d71e0 | 398 | token->pragma_kind = (enum pragma_kind) TREE_INT_CST_LOW (token->value); |
bc4071dd | 399 | token->value = NULL; |
27bf414c JM |
400 | break; |
401 | default: | |
27bf414c JM |
402 | break; |
403 | } | |
404 | timevar_pop (TV_LEX); | |
405 | } | |
406 | ||
407 | /* Return a pointer to the next token from PARSER, reading it in if | |
408 | necessary. */ | |
409 | ||
410 | static inline c_token * | |
411 | c_parser_peek_token (c_parser *parser) | |
412 | { | |
413 | if (parser->tokens_avail == 0) | |
414 | { | |
0bacb8c7 | 415 | c_lex_one_token (parser, &parser->tokens[0]); |
27bf414c JM |
416 | parser->tokens_avail = 1; |
417 | } | |
418 | return &parser->tokens[0]; | |
419 | } | |
420 | ||
421 | /* Return true if the next token from PARSER has the indicated | |
422 | TYPE. */ | |
423 | ||
424 | static inline bool | |
425 | c_parser_next_token_is (c_parser *parser, enum cpp_ttype type) | |
426 | { | |
427 | return c_parser_peek_token (parser)->type == type; | |
428 | } | |
429 | ||
430 | /* Return true if the next token from PARSER does not have the | |
431 | indicated TYPE. */ | |
432 | ||
433 | static inline bool | |
434 | c_parser_next_token_is_not (c_parser *parser, enum cpp_ttype type) | |
435 | { | |
436 | return !c_parser_next_token_is (parser, type); | |
437 | } | |
438 | ||
439 | /* Return true if the next token from PARSER is the indicated | |
440 | KEYWORD. */ | |
441 | ||
442 | static inline bool | |
443 | c_parser_next_token_is_keyword (c_parser *parser, enum rid keyword) | |
444 | { | |
dbc518f0 | 445 | return c_parser_peek_token (parser)->keyword == keyword; |
27bf414c JM |
446 | } |
447 | ||
29ce73cb PB |
448 | /* Return a pointer to the next-but-one token from PARSER, reading it |
449 | in if necessary. The next token is already read in. */ | |
450 | ||
451 | static c_token * | |
452 | c_parser_peek_2nd_token (c_parser *parser) | |
453 | { | |
454 | if (parser->tokens_avail >= 2) | |
455 | return &parser->tokens[1]; | |
456 | gcc_assert (parser->tokens_avail == 1); | |
457 | gcc_assert (parser->tokens[0].type != CPP_EOF); | |
458 | gcc_assert (parser->tokens[0].type != CPP_PRAGMA_EOL); | |
459 | c_lex_one_token (parser, &parser->tokens[1]); | |
460 | parser->tokens_avail = 2; | |
461 | return &parser->tokens[1]; | |
462 | } | |
463 | ||
27bf414c JM |
464 | /* Return true if TOKEN can start a type name, |
465 | false otherwise. */ | |
466 | static bool | |
467 | c_token_starts_typename (c_token *token) | |
468 | { | |
469 | switch (token->type) | |
470 | { | |
471 | case CPP_NAME: | |
472 | switch (token->id_kind) | |
473 | { | |
474 | case C_ID_ID: | |
475 | return false; | |
36c5e70a BE |
476 | case C_ID_ADDRSPACE: |
477 | return true; | |
27bf414c JM |
478 | case C_ID_TYPENAME: |
479 | return true; | |
480 | case C_ID_CLASSNAME: | |
481 | gcc_assert (c_dialect_objc ()); | |
482 | return true; | |
483 | default: | |
484 | gcc_unreachable (); | |
485 | } | |
486 | case CPP_KEYWORD: | |
487 | switch (token->keyword) | |
488 | { | |
489 | case RID_UNSIGNED: | |
490 | case RID_LONG: | |
a6766312 | 491 | case RID_INT128: |
27bf414c JM |
492 | case RID_SHORT: |
493 | case RID_SIGNED: | |
494 | case RID_COMPLEX: | |
495 | case RID_INT: | |
496 | case RID_CHAR: | |
497 | case RID_FLOAT: | |
498 | case RID_DOUBLE: | |
499 | case RID_VOID: | |
9a8ce21f JG |
500 | case RID_DFLOAT32: |
501 | case RID_DFLOAT64: | |
502 | case RID_DFLOAT128: | |
27bf414c JM |
503 | case RID_BOOL: |
504 | case RID_ENUM: | |
505 | case RID_STRUCT: | |
506 | case RID_UNION: | |
507 | case RID_TYPEOF: | |
508 | case RID_CONST: | |
267bac10 | 509 | case RID_ATOMIC: |
27bf414c JM |
510 | case RID_VOLATILE: |
511 | case RID_RESTRICT: | |
512 | case RID_ATTRIBUTE: | |
ab22c1fa CF |
513 | case RID_FRACT: |
514 | case RID_ACCUM: | |
515 | case RID_SAT: | |
38b7bc7f | 516 | case RID_AUTO_TYPE: |
27bf414c JM |
517 | return true; |
518 | default: | |
519 | return false; | |
520 | } | |
521 | case CPP_LESS: | |
522 | if (c_dialect_objc ()) | |
523 | return true; | |
524 | return false; | |
525 | default: | |
526 | return false; | |
527 | } | |
528 | } | |
529 | ||
29ce73cb PB |
530 | enum c_lookahead_kind { |
531 | /* Always treat unknown identifiers as typenames. */ | |
532 | cla_prefer_type, | |
533 | ||
534 | /* Could be parsing a nonabstract declarator. Only treat an identifier | |
535 | as a typename if followed by another identifier or a star. */ | |
536 | cla_nonabstract_decl, | |
537 | ||
538 | /* Never treat identifiers as typenames. */ | |
539 | cla_prefer_id | |
540 | }; | |
541 | ||
27bf414c | 542 | /* Return true if the next token from PARSER can start a type name, |
29ce73cb PB |
543 | false otherwise. LA specifies how to do lookahead in order to |
544 | detect unknown type names. If unsure, pick CLA_PREFER_ID. */ | |
545 | ||
27bf414c | 546 | static inline bool |
29ce73cb | 547 | c_parser_next_tokens_start_typename (c_parser *parser, enum c_lookahead_kind la) |
27bf414c JM |
548 | { |
549 | c_token *token = c_parser_peek_token (parser); | |
29ce73cb PB |
550 | if (c_token_starts_typename (token)) |
551 | return true; | |
552 | ||
553 | /* Try a bit harder to detect an unknown typename. */ | |
554 | if (la != cla_prefer_id | |
555 | && token->type == CPP_NAME | |
556 | && token->id_kind == C_ID_ID | |
557 | ||
558 | /* Do not try too hard when we could have "object in array". */ | |
559 | && !parser->objc_could_be_foreach_context | |
560 | ||
561 | && (la == cla_prefer_type | |
562 | || c_parser_peek_2nd_token (parser)->type == CPP_NAME | |
563 | || c_parser_peek_2nd_token (parser)->type == CPP_MULT) | |
564 | ||
565 | /* Only unknown identifiers. */ | |
566 | && !lookup_name (token->value)) | |
567 | return true; | |
568 | ||
569 | return false; | |
27bf414c JM |
570 | } |
571 | ||
f725e721 PB |
572 | /* Return true if TOKEN is a type qualifier, false otherwise. */ |
573 | static bool | |
574 | c_token_is_qualifier (c_token *token) | |
575 | { | |
576 | switch (token->type) | |
577 | { | |
578 | case CPP_NAME: | |
579 | switch (token->id_kind) | |
580 | { | |
581 | case C_ID_ADDRSPACE: | |
582 | return true; | |
583 | default: | |
584 | return false; | |
585 | } | |
586 | case CPP_KEYWORD: | |
587 | switch (token->keyword) | |
588 | { | |
589 | case RID_CONST: | |
590 | case RID_VOLATILE: | |
591 | case RID_RESTRICT: | |
592 | case RID_ATTRIBUTE: | |
267bac10 | 593 | case RID_ATOMIC: |
f725e721 PB |
594 | return true; |
595 | default: | |
596 | return false; | |
597 | } | |
598 | case CPP_LESS: | |
599 | return false; | |
600 | default: | |
601 | gcc_unreachable (); | |
602 | } | |
603 | } | |
604 | ||
605 | /* Return true if the next token from PARSER is a type qualifier, | |
606 | false otherwise. */ | |
607 | static inline bool | |
608 | c_parser_next_token_is_qualifier (c_parser *parser) | |
609 | { | |
610 | c_token *token = c_parser_peek_token (parser); | |
611 | return c_token_is_qualifier (token); | |
612 | } | |
613 | ||
27bf414c JM |
614 | /* Return true if TOKEN can start declaration specifiers, false |
615 | otherwise. */ | |
616 | static bool | |
617 | c_token_starts_declspecs (c_token *token) | |
618 | { | |
619 | switch (token->type) | |
620 | { | |
621 | case CPP_NAME: | |
622 | switch (token->id_kind) | |
623 | { | |
624 | case C_ID_ID: | |
625 | return false; | |
36c5e70a BE |
626 | case C_ID_ADDRSPACE: |
627 | return true; | |
27bf414c JM |
628 | case C_ID_TYPENAME: |
629 | return true; | |
630 | case C_ID_CLASSNAME: | |
631 | gcc_assert (c_dialect_objc ()); | |
632 | return true; | |
633 | default: | |
634 | gcc_unreachable (); | |
635 | } | |
636 | case CPP_KEYWORD: | |
637 | switch (token->keyword) | |
638 | { | |
639 | case RID_STATIC: | |
640 | case RID_EXTERN: | |
641 | case RID_REGISTER: | |
642 | case RID_TYPEDEF: | |
643 | case RID_INLINE: | |
bbceee64 | 644 | case RID_NORETURN: |
27bf414c JM |
645 | case RID_AUTO: |
646 | case RID_THREAD: | |
647 | case RID_UNSIGNED: | |
648 | case RID_LONG: | |
a6766312 | 649 | case RID_INT128: |
27bf414c JM |
650 | case RID_SHORT: |
651 | case RID_SIGNED: | |
652 | case RID_COMPLEX: | |
653 | case RID_INT: | |
654 | case RID_CHAR: | |
655 | case RID_FLOAT: | |
656 | case RID_DOUBLE: | |
657 | case RID_VOID: | |
9a8ce21f JG |
658 | case RID_DFLOAT32: |
659 | case RID_DFLOAT64: | |
660 | case RID_DFLOAT128: | |
27bf414c JM |
661 | case RID_BOOL: |
662 | case RID_ENUM: | |
663 | case RID_STRUCT: | |
664 | case RID_UNION: | |
665 | case RID_TYPEOF: | |
666 | case RID_CONST: | |
667 | case RID_VOLATILE: | |
668 | case RID_RESTRICT: | |
669 | case RID_ATTRIBUTE: | |
ab22c1fa CF |
670 | case RID_FRACT: |
671 | case RID_ACCUM: | |
672 | case RID_SAT: | |
d19fa6b5 | 673 | case RID_ALIGNAS: |
267bac10 | 674 | case RID_ATOMIC: |
38b7bc7f | 675 | case RID_AUTO_TYPE: |
27bf414c JM |
676 | return true; |
677 | default: | |
678 | return false; | |
679 | } | |
680 | case CPP_LESS: | |
681 | if (c_dialect_objc ()) | |
682 | return true; | |
683 | return false; | |
684 | default: | |
685 | return false; | |
686 | } | |
687 | } | |
688 | ||
32912286 JM |
689 | |
690 | /* Return true if TOKEN can start declaration specifiers or a static | |
691 | assertion, false otherwise. */ | |
692 | static bool | |
693 | c_token_starts_declaration (c_token *token) | |
694 | { | |
695 | if (c_token_starts_declspecs (token) | |
696 | || token->keyword == RID_STATIC_ASSERT) | |
697 | return true; | |
698 | else | |
699 | return false; | |
700 | } | |
701 | ||
27bf414c JM |
702 | /* Return true if the next token from PARSER can start declaration |
703 | specifiers, false otherwise. */ | |
704 | static inline bool | |
705 | c_parser_next_token_starts_declspecs (c_parser *parser) | |
706 | { | |
707 | c_token *token = c_parser_peek_token (parser); | |
bede2adc NP |
708 | |
709 | /* In Objective-C, a classname normally starts a declspecs unless it | |
710 | is immediately followed by a dot. In that case, it is the | |
711 | Objective-C 2.0 "dot-syntax" for class objects, ie, calls the | |
712 | setter/getter on the class. c_token_starts_declspecs() can't | |
713 | differentiate between the two cases because it only checks the | |
714 | current token, so we have a special check here. */ | |
715 | if (c_dialect_objc () | |
716 | && token->type == CPP_NAME | |
717 | && token->id_kind == C_ID_CLASSNAME | |
718 | && c_parser_peek_2nd_token (parser)->type == CPP_DOT) | |
719 | return false; | |
720 | ||
27bf414c JM |
721 | return c_token_starts_declspecs (token); |
722 | } | |
723 | ||
2f413185 | 724 | /* Return true if the next tokens from PARSER can start declaration |
32912286 JM |
725 | specifiers or a static assertion, false otherwise. */ |
726 | static inline bool | |
2f413185 | 727 | c_parser_next_tokens_start_declaration (c_parser *parser) |
32912286 JM |
728 | { |
729 | c_token *token = c_parser_peek_token (parser); | |
bede2adc NP |
730 | |
731 | /* Same as above. */ | |
732 | if (c_dialect_objc () | |
733 | && token->type == CPP_NAME | |
734 | && token->id_kind == C_ID_CLASSNAME | |
735 | && c_parser_peek_2nd_token (parser)->type == CPP_DOT) | |
736 | return false; | |
737 | ||
2f413185 PB |
738 | /* Labels do not start declarations. */ |
739 | if (token->type == CPP_NAME | |
740 | && c_parser_peek_2nd_token (parser)->type == CPP_COLON) | |
741 | return false; | |
742 | ||
743 | if (c_token_starts_declaration (token)) | |
744 | return true; | |
745 | ||
29ce73cb | 746 | if (c_parser_next_tokens_start_typename (parser, cla_nonabstract_decl)) |
2f413185 PB |
747 | return true; |
748 | ||
749 | return false; | |
32912286 JM |
750 | } |
751 | ||
27bf414c JM |
752 | /* Consume the next token from PARSER. */ |
753 | ||
754 | static void | |
755 | c_parser_consume_token (c_parser *parser) | |
756 | { | |
bc4071dd RH |
757 | gcc_assert (parser->tokens_avail >= 1); |
758 | gcc_assert (parser->tokens[0].type != CPP_EOF); | |
759 | gcc_assert (!parser->in_pragma || parser->tokens[0].type != CPP_PRAGMA_EOL); | |
760 | gcc_assert (parser->error || parser->tokens[0].type != CPP_PRAGMA); | |
acf0174b JJ |
761 | if (parser->tokens != &parser->tokens_buf[0]) |
762 | parser->tokens++; | |
763 | else if (parser->tokens_avail == 2) | |
27bf414c | 764 | parser->tokens[0] = parser->tokens[1]; |
27bf414c JM |
765 | parser->tokens_avail--; |
766 | } | |
767 | ||
bc4071dd RH |
768 | /* Expect the current token to be a #pragma. Consume it and remember |
769 | that we've begun parsing a pragma. */ | |
770 | ||
771 | static void | |
772 | c_parser_consume_pragma (c_parser *parser) | |
773 | { | |
774 | gcc_assert (!parser->in_pragma); | |
775 | gcc_assert (parser->tokens_avail >= 1); | |
776 | gcc_assert (parser->tokens[0].type == CPP_PRAGMA); | |
acf0174b JJ |
777 | if (parser->tokens != &parser->tokens_buf[0]) |
778 | parser->tokens++; | |
779 | else if (parser->tokens_avail == 2) | |
bc4071dd RH |
780 | parser->tokens[0] = parser->tokens[1]; |
781 | parser->tokens_avail--; | |
782 | parser->in_pragma = true; | |
783 | } | |
784 | ||
8400e75e | 785 | /* Update the global input_location from TOKEN. */ |
27bf414c JM |
786 | static inline void |
787 | c_parser_set_source_position_from_token (c_token *token) | |
788 | { | |
789 | if (token->type != CPP_EOF) | |
790 | { | |
791 | input_location = token->location; | |
27bf414c JM |
792 | } |
793 | } | |
794 | ||
27bf414c JM |
795 | /* Issue a diagnostic of the form |
796 | FILE:LINE: MESSAGE before TOKEN | |
797 | where TOKEN is the next token in the input stream of PARSER. | |
798 | MESSAGE (specified by the caller) is usually of the form "expected | |
799 | OTHER-TOKEN". | |
800 | ||
801 | Do not issue a diagnostic if still recovering from an error. | |
802 | ||
803 | ??? This is taken from the C++ parser, but building up messages in | |
804 | this way is not i18n-friendly and some other approach should be | |
805 | used. */ | |
806 | ||
807 | static void | |
4b794eaf | 808 | c_parser_error (c_parser *parser, const char *gmsgid) |
27bf414c JM |
809 | { |
810 | c_token *token = c_parser_peek_token (parser); | |
811 | if (parser->error) | |
812 | return; | |
813 | parser->error = true; | |
4b794eaf | 814 | if (!gmsgid) |
27bf414c JM |
815 | return; |
816 | /* This diagnostic makes more sense if it is tagged to the line of | |
817 | the token we just peeked at. */ | |
818 | c_parser_set_source_position_from_token (token); | |
4b794eaf | 819 | c_parse_error (gmsgid, |
27bf414c JM |
820 | /* Because c_parse_error does not understand |
821 | CPP_KEYWORD, keywords are treated like | |
822 | identifiers. */ | |
823 | (token->type == CPP_KEYWORD ? CPP_NAME : token->type), | |
cfc93532 MLI |
824 | /* ??? The C parser does not save the cpp flags of a |
825 | token, we need to pass 0 here and we will not get | |
826 | the source spelling of some tokens but rather the | |
827 | canonical spelling. */ | |
828 | token->value, /*flags=*/0); | |
27bf414c JM |
829 | } |
830 | ||
831 | /* If the next token is of the indicated TYPE, consume it. Otherwise, | |
832 | issue the error MSGID. If MSGID is NULL then a message has already | |
833 | been produced and no message will be produced this time. Returns | |
834 | true if found, false otherwise. */ | |
835 | ||
836 | static bool | |
837 | c_parser_require (c_parser *parser, | |
838 | enum cpp_ttype type, | |
839 | const char *msgid) | |
840 | { | |
841 | if (c_parser_next_token_is (parser, type)) | |
842 | { | |
843 | c_parser_consume_token (parser); | |
844 | return true; | |
845 | } | |
846 | else | |
847 | { | |
848 | c_parser_error (parser, msgid); | |
849 | return false; | |
850 | } | |
851 | } | |
852 | ||
853 | /* If the next token is the indicated keyword, consume it. Otherwise, | |
854 | issue the error MSGID. Returns true if found, false otherwise. */ | |
855 | ||
856 | static bool | |
857 | c_parser_require_keyword (c_parser *parser, | |
858 | enum rid keyword, | |
859 | const char *msgid) | |
860 | { | |
861 | if (c_parser_next_token_is_keyword (parser, keyword)) | |
862 | { | |
863 | c_parser_consume_token (parser); | |
864 | return true; | |
865 | } | |
866 | else | |
867 | { | |
868 | c_parser_error (parser, msgid); | |
869 | return false; | |
870 | } | |
871 | } | |
872 | ||
873 | /* Like c_parser_require, except that tokens will be skipped until the | |
874 | desired token is found. An error message is still produced if the | |
875 | next token is not as expected. If MSGID is NULL then a message has | |
876 | already been produced and no message will be produced this | |
877 | time. */ | |
878 | ||
879 | static void | |
880 | c_parser_skip_until_found (c_parser *parser, | |
881 | enum cpp_ttype type, | |
882 | const char *msgid) | |
883 | { | |
884 | unsigned nesting_depth = 0; | |
885 | ||
886 | if (c_parser_require (parser, type, msgid)) | |
887 | return; | |
888 | ||
889 | /* Skip tokens until the desired token is found. */ | |
890 | while (true) | |
891 | { | |
892 | /* Peek at the next token. */ | |
893 | c_token *token = c_parser_peek_token (parser); | |
894 | /* If we've reached the token we want, consume it and stop. */ | |
895 | if (token->type == type && !nesting_depth) | |
896 | { | |
897 | c_parser_consume_token (parser); | |
898 | break; | |
899 | } | |
bc4071dd | 900 | |
27bf414c JM |
901 | /* If we've run out of tokens, stop. */ |
902 | if (token->type == CPP_EOF) | |
903 | return; | |
bc4071dd RH |
904 | if (token->type == CPP_PRAGMA_EOL && parser->in_pragma) |
905 | return; | |
27bf414c JM |
906 | if (token->type == CPP_OPEN_BRACE |
907 | || token->type == CPP_OPEN_PAREN | |
908 | || token->type == CPP_OPEN_SQUARE) | |
909 | ++nesting_depth; | |
910 | else if (token->type == CPP_CLOSE_BRACE | |
911 | || token->type == CPP_CLOSE_PAREN | |
912 | || token->type == CPP_CLOSE_SQUARE) | |
913 | { | |
914 | if (nesting_depth-- == 0) | |
915 | break; | |
916 | } | |
917 | /* Consume this token. */ | |
918 | c_parser_consume_token (parser); | |
919 | } | |
920 | parser->error = false; | |
921 | } | |
922 | ||
923 | /* Skip tokens until the end of a parameter is found, but do not | |
924 | consume the comma, semicolon or closing delimiter. */ | |
925 | ||
926 | static void | |
927 | c_parser_skip_to_end_of_parameter (c_parser *parser) | |
928 | { | |
929 | unsigned nesting_depth = 0; | |
930 | ||
931 | while (true) | |
932 | { | |
933 | c_token *token = c_parser_peek_token (parser); | |
934 | if ((token->type == CPP_COMMA || token->type == CPP_SEMICOLON) | |
935 | && !nesting_depth) | |
936 | break; | |
937 | /* If we've run out of tokens, stop. */ | |
938 | if (token->type == CPP_EOF) | |
939 | return; | |
bc4071dd RH |
940 | if (token->type == CPP_PRAGMA_EOL && parser->in_pragma) |
941 | return; | |
27bf414c JM |
942 | if (token->type == CPP_OPEN_BRACE |
943 | || token->type == CPP_OPEN_PAREN | |
944 | || token->type == CPP_OPEN_SQUARE) | |
945 | ++nesting_depth; | |
946 | else if (token->type == CPP_CLOSE_BRACE | |
947 | || token->type == CPP_CLOSE_PAREN | |
948 | || token->type == CPP_CLOSE_SQUARE) | |
949 | { | |
950 | if (nesting_depth-- == 0) | |
951 | break; | |
952 | } | |
953 | /* Consume this token. */ | |
954 | c_parser_consume_token (parser); | |
955 | } | |
956 | parser->error = false; | |
957 | } | |
958 | ||
bc4071dd RH |
959 | /* Expect to be at the end of the pragma directive and consume an |
960 | end of line marker. */ | |
961 | ||
962 | static void | |
963 | c_parser_skip_to_pragma_eol (c_parser *parser) | |
964 | { | |
965 | gcc_assert (parser->in_pragma); | |
966 | parser->in_pragma = false; | |
967 | ||
968 | if (!c_parser_require (parser, CPP_PRAGMA_EOL, "expected end of line")) | |
969 | while (true) | |
970 | { | |
971 | c_token *token = c_parser_peek_token (parser); | |
972 | if (token->type == CPP_EOF) | |
973 | break; | |
974 | if (token->type == CPP_PRAGMA_EOL) | |
975 | { | |
976 | c_parser_consume_token (parser); | |
977 | break; | |
978 | } | |
979 | c_parser_consume_token (parser); | |
980 | } | |
981 | ||
982 | parser->error = false; | |
983 | } | |
27bf414c | 984 | |
2a83cc52 RH |
985 | /* Skip tokens until we have consumed an entire block, or until we |
986 | have consumed a non-nested ';'. */ | |
987 | ||
988 | static void | |
989 | c_parser_skip_to_end_of_block_or_statement (c_parser *parser) | |
990 | { | |
991 | unsigned nesting_depth = 0; | |
992 | bool save_error = parser->error; | |
993 | ||
994 | while (true) | |
995 | { | |
996 | c_token *token; | |
997 | ||
998 | /* Peek at the next token. */ | |
999 | token = c_parser_peek_token (parser); | |
1000 | ||
1001 | switch (token->type) | |
1002 | { | |
1003 | case CPP_EOF: | |
1004 | return; | |
1005 | ||
1006 | case CPP_PRAGMA_EOL: | |
1007 | if (parser->in_pragma) | |
1008 | return; | |
1009 | break; | |
1010 | ||
1011 | case CPP_SEMICOLON: | |
1012 | /* If the next token is a ';', we have reached the | |
1013 | end of the statement. */ | |
1014 | if (!nesting_depth) | |
1015 | { | |
1016 | /* Consume the ';'. */ | |
1017 | c_parser_consume_token (parser); | |
1018 | goto finished; | |
1019 | } | |
1020 | break; | |
1021 | ||
1022 | case CPP_CLOSE_BRACE: | |
1023 | /* If the next token is a non-nested '}', then we have | |
1024 | reached the end of the current block. */ | |
1025 | if (nesting_depth == 0 || --nesting_depth == 0) | |
1026 | { | |
1027 | c_parser_consume_token (parser); | |
1028 | goto finished; | |
1029 | } | |
1030 | break; | |
1031 | ||
1032 | case CPP_OPEN_BRACE: | |
1033 | /* If it the next token is a '{', then we are entering a new | |
1034 | block. Consume the entire block. */ | |
1035 | ++nesting_depth; | |
1036 | break; | |
1037 | ||
1038 | case CPP_PRAGMA: | |
1039 | /* If we see a pragma, consume the whole thing at once. We | |
1040 | have some safeguards against consuming pragmas willy-nilly. | |
1041 | Normally, we'd expect to be here with parser->error set, | |
1042 | which disables these safeguards. But it's possible to get | |
1043 | here for secondary error recovery, after parser->error has | |
1044 | been cleared. */ | |
1045 | c_parser_consume_pragma (parser); | |
1046 | c_parser_skip_to_pragma_eol (parser); | |
1047 | parser->error = save_error; | |
1048 | continue; | |
9e33de05 RS |
1049 | |
1050 | default: | |
1051 | break; | |
2a83cc52 RH |
1052 | } |
1053 | ||
1054 | c_parser_consume_token (parser); | |
1055 | } | |
1056 | ||
1057 | finished: | |
1058 | parser->error = false; | |
1059 | } | |
1060 | ||
d2e796ad MLI |
1061 | /* CPP's options (initialized by c-opts.c). */ |
1062 | extern cpp_options *cpp_opts; | |
1063 | ||
27bf414c JM |
1064 | /* Save the warning flags which are controlled by __extension__. */ |
1065 | ||
1066 | static inline int | |
1067 | disable_extension_diagnostics (void) | |
1068 | { | |
1069 | int ret = (pedantic | |
1070 | | (warn_pointer_arith << 1) | |
1071 | | (warn_traditional << 2) | |
d2e796ad | 1072 | | (flag_iso << 3) |
24b97832 | 1073 | | (warn_long_long << 4) |
b3ab9ea2 | 1074 | | (warn_cxx_compat << 5) |
f3bede71 MP |
1075 | | (warn_overlength_strings << 6) |
1076 | | (warn_c90_c99_compat << 7)); | |
e3339d0f | 1077 | cpp_opts->cpp_pedantic = pedantic = 0; |
27bf414c | 1078 | warn_pointer_arith = 0; |
e3339d0f | 1079 | cpp_opts->cpp_warn_traditional = warn_traditional = 0; |
27bf414c | 1080 | flag_iso = 0; |
e3339d0f | 1081 | cpp_opts->cpp_warn_long_long = warn_long_long = 0; |
24b97832 | 1082 | warn_cxx_compat = 0; |
b3ab9ea2 | 1083 | warn_overlength_strings = 0; |
f3bede71 | 1084 | warn_c90_c99_compat = 0; |
27bf414c JM |
1085 | return ret; |
1086 | } | |
1087 | ||
1088 | /* Restore the warning flags which are controlled by __extension__. | |
1089 | FLAGS is the return value from disable_extension_diagnostics. */ | |
1090 | ||
1091 | static inline void | |
1092 | restore_extension_diagnostics (int flags) | |
1093 | { | |
e3339d0f | 1094 | cpp_opts->cpp_pedantic = pedantic = flags & 1; |
27bf414c | 1095 | warn_pointer_arith = (flags >> 1) & 1; |
e3339d0f | 1096 | cpp_opts->cpp_warn_traditional = warn_traditional = (flags >> 2) & 1; |
27bf414c | 1097 | flag_iso = (flags >> 3) & 1; |
e3339d0f | 1098 | cpp_opts->cpp_warn_long_long = warn_long_long = (flags >> 4) & 1; |
24b97832 | 1099 | warn_cxx_compat = (flags >> 5) & 1; |
b3ab9ea2 | 1100 | warn_overlength_strings = (flags >> 6) & 1; |
f3bede71 | 1101 | warn_c90_c99_compat = (flags >> 7) & 1; |
27bf414c JM |
1102 | } |
1103 | ||
1104 | /* Possibly kinds of declarator to parse. */ | |
1105 | typedef enum c_dtr_syn { | |
1106 | /* A normal declarator with an identifier. */ | |
1107 | C_DTR_NORMAL, | |
1108 | /* An abstract declarator (maybe empty). */ | |
1109 | C_DTR_ABSTRACT, | |
1110 | /* A parameter declarator: may be either, but after a type name does | |
1111 | not redeclare a typedef name as an identifier if it can | |
1112 | alternatively be interpreted as a typedef name; see DR#009, | |
1113 | applied in C90 TC1, omitted from C99 and reapplied in C99 TC2 | |
1114 | following DR#249. For example, given a typedef T, "int T" and | |
1115 | "int *T" are valid parameter declarations redeclaring T, while | |
1116 | "int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are | |
1117 | abstract declarators rather than involving redundant parentheses; | |
1118 | the same applies with attributes inside the parentheses before | |
1119 | "T". */ | |
1120 | C_DTR_PARM | |
1121 | } c_dtr_syn; | |
1122 | ||
20906c66 JJ |
1123 | /* The binary operation precedence levels, where 0 is a dummy lowest level |
1124 | used for the bottom of the stack. */ | |
1125 | enum c_parser_prec { | |
1126 | PREC_NONE, | |
1127 | PREC_LOGOR, | |
1128 | PREC_LOGAND, | |
1129 | PREC_BITOR, | |
1130 | PREC_BITXOR, | |
1131 | PREC_BITAND, | |
1132 | PREC_EQ, | |
1133 | PREC_REL, | |
1134 | PREC_SHIFT, | |
1135 | PREC_ADD, | |
1136 | PREC_MULT, | |
1137 | NUM_PRECS | |
1138 | }; | |
1139 | ||
27bf414c JM |
1140 | static void c_parser_external_declaration (c_parser *); |
1141 | static void c_parser_asm_definition (c_parser *); | |
32912286 | 1142 | static void c_parser_declaration_or_fndef (c_parser *, bool, bool, bool, |
acf0174b | 1143 | bool, bool, tree *, vec<c_token>); |
32912286 JM |
1144 | static void c_parser_static_assert_declaration_no_semi (c_parser *); |
1145 | static void c_parser_static_assert_declaration (c_parser *); | |
27bf414c | 1146 | static void c_parser_declspecs (c_parser *, struct c_declspecs *, bool, bool, |
38b7bc7f | 1147 | bool, bool, bool, enum c_lookahead_kind); |
27bf414c JM |
1148 | static struct c_typespec c_parser_enum_specifier (c_parser *); |
1149 | static struct c_typespec c_parser_struct_or_union_specifier (c_parser *); | |
1150 | static tree c_parser_struct_declaration (c_parser *); | |
1151 | static struct c_typespec c_parser_typeof_specifier (c_parser *); | |
d19fa6b5 | 1152 | static tree c_parser_alignas_specifier (c_parser *); |
27bf414c JM |
1153 | static struct c_declarator *c_parser_declarator (c_parser *, bool, c_dtr_syn, |
1154 | bool *); | |
1155 | static struct c_declarator *c_parser_direct_declarator (c_parser *, bool, | |
1156 | c_dtr_syn, bool *); | |
1157 | static struct c_declarator *c_parser_direct_declarator_inner (c_parser *, | |
1158 | bool, | |
1159 | struct c_declarator *); | |
1160 | static struct c_arg_info *c_parser_parms_declarator (c_parser *, bool, tree); | |
a04a722b JM |
1161 | static struct c_arg_info *c_parser_parms_list_declarator (c_parser *, tree, |
1162 | tree); | |
27bf414c JM |
1163 | static struct c_parm *c_parser_parameter_declaration (c_parser *, tree); |
1164 | static tree c_parser_simple_asm_expr (c_parser *); | |
1165 | static tree c_parser_attributes (c_parser *); | |
1166 | static struct c_type_name *c_parser_type_name (c_parser *); | |
1167 | static struct c_expr c_parser_initializer (c_parser *); | |
1168 | static struct c_expr c_parser_braced_init (c_parser *, tree, bool); | |
a1e3b3d9 LB |
1169 | static void c_parser_initelt (c_parser *, struct obstack *); |
1170 | static void c_parser_initval (c_parser *, struct c_expr *, | |
1171 | struct obstack *); | |
27bf414c JM |
1172 | static tree c_parser_compound_statement (c_parser *); |
1173 | static void c_parser_compound_statement_nostart (c_parser *); | |
1174 | static void c_parser_label (c_parser *); | |
1175 | static void c_parser_statement (c_parser *); | |
1176 | static void c_parser_statement_after_labels (c_parser *); | |
1177 | static void c_parser_if_statement (c_parser *); | |
1178 | static void c_parser_switch_statement (c_parser *); | |
d4af74d4 TB |
1179 | static void c_parser_while_statement (c_parser *, bool); |
1180 | static void c_parser_do_statement (c_parser *, bool); | |
8170608b | 1181 | static void c_parser_for_statement (c_parser *, bool); |
27bf414c | 1182 | static tree c_parser_asm_statement (c_parser *); |
eadd3d0d | 1183 | static tree c_parser_asm_operands (c_parser *); |
1c384bf1 | 1184 | static tree c_parser_asm_goto_operands (c_parser *); |
27bf414c | 1185 | static tree c_parser_asm_clobbers (c_parser *); |
acf0174b JJ |
1186 | static struct c_expr c_parser_expr_no_commas (c_parser *, struct c_expr *, |
1187 | tree = NULL_TREE); | |
27bf414c | 1188 | static struct c_expr c_parser_conditional_expression (c_parser *, |
acf0174b | 1189 | struct c_expr *, tree); |
20906c66 | 1190 | static struct c_expr c_parser_binary_expression (c_parser *, struct c_expr *, |
acf0174b | 1191 | tree); |
27bf414c JM |
1192 | static struct c_expr c_parser_cast_expression (c_parser *, struct c_expr *); |
1193 | static struct c_expr c_parser_unary_expression (c_parser *); | |
1194 | static struct c_expr c_parser_sizeof_expression (c_parser *); | |
1195 | static struct c_expr c_parser_alignof_expression (c_parser *); | |
1196 | static struct c_expr c_parser_postfix_expression (c_parser *); | |
1197 | static struct c_expr c_parser_postfix_expression_after_paren_type (c_parser *, | |
24b97832 ILT |
1198 | struct c_type_name *, |
1199 | location_t); | |
27bf414c | 1200 | static struct c_expr c_parser_postfix_expression_after_primary (c_parser *, |
c2255bc4 | 1201 | location_t loc, |
27bf414c | 1202 | struct c_expr); |
0a35513e AH |
1203 | static tree c_parser_transaction (c_parser *, enum rid); |
1204 | static struct c_expr c_parser_transaction_expression (c_parser *, enum rid); | |
1205 | static tree c_parser_transaction_cancel (c_parser *); | |
27bf414c | 1206 | static struct c_expr c_parser_expression (c_parser *); |
46bdb9cf | 1207 | static struct c_expr c_parser_expression_conv (c_parser *); |
9771b263 DN |
1208 | static vec<tree, va_gc> *c_parser_expr_list (c_parser *, bool, bool, |
1209 | vec<tree, va_gc> **, location_t *, | |
b108f48f JJ |
1210 | tree *, vec<location_t> *, |
1211 | unsigned int * = NULL); | |
953ff289 DN |
1212 | static void c_parser_omp_construct (c_parser *); |
1213 | static void c_parser_omp_threadprivate (c_parser *); | |
1214 | static void c_parser_omp_barrier (c_parser *); | |
1215 | static void c_parser_omp_flush (c_parser *); | |
a68ab351 | 1216 | static void c_parser_omp_taskwait (c_parser *); |
20906c66 | 1217 | static void c_parser_omp_taskyield (c_parser *); |
acf0174b JJ |
1218 | static void c_parser_omp_cancel (c_parser *); |
1219 | static void c_parser_omp_cancellation_point (c_parser *); | |
27bf414c | 1220 | |
acf0174b JJ |
1221 | enum pragma_context { pragma_external, pragma_struct, pragma_param, |
1222 | pragma_stmt, pragma_compound }; | |
bc4071dd | 1223 | static bool c_parser_pragma (c_parser *, enum pragma_context); |
acf0174b JJ |
1224 | static bool c_parser_omp_target (c_parser *, enum pragma_context); |
1225 | static void c_parser_omp_end_declare_target (c_parser *); | |
1226 | static void c_parser_omp_declare (c_parser *, enum pragma_context); | |
bc4071dd | 1227 | |
27bf414c JM |
1228 | /* These Objective-C parser functions are only ever called when |
1229 | compiling Objective-C. */ | |
c165dca7 | 1230 | static void c_parser_objc_class_definition (c_parser *, tree); |
27bf414c JM |
1231 | static void c_parser_objc_class_instance_variables (c_parser *); |
1232 | static void c_parser_objc_class_declaration (c_parser *); | |
1233 | static void c_parser_objc_alias_declaration (c_parser *); | |
c165dca7 | 1234 | static void c_parser_objc_protocol_definition (c_parser *, tree); |
249a82c4 | 1235 | static bool c_parser_objc_method_type (c_parser *); |
27bf414c JM |
1236 | static void c_parser_objc_method_definition (c_parser *); |
1237 | static void c_parser_objc_methodprotolist (c_parser *); | |
1238 | static void c_parser_objc_methodproto (c_parser *); | |
a04a722b | 1239 | static tree c_parser_objc_method_decl (c_parser *, bool, tree *, tree *); |
27bf414c JM |
1240 | static tree c_parser_objc_type_name (c_parser *); |
1241 | static tree c_parser_objc_protocol_refs (c_parser *); | |
437c2322 | 1242 | static void c_parser_objc_try_catch_finally_statement (c_parser *); |
27bf414c JM |
1243 | static void c_parser_objc_synchronized_statement (c_parser *); |
1244 | static tree c_parser_objc_selector (c_parser *); | |
1245 | static tree c_parser_objc_selector_arg (c_parser *); | |
1246 | static tree c_parser_objc_receiver (c_parser *); | |
1247 | static tree c_parser_objc_message_args (c_parser *); | |
1248 | static tree c_parser_objc_keywordexpr (c_parser *); | |
f614132b | 1249 | static void c_parser_objc_at_property_declaration (c_parser *); |
da57d1b9 NP |
1250 | static void c_parser_objc_at_synthesize_declaration (c_parser *); |
1251 | static void c_parser_objc_at_dynamic_declaration (c_parser *); | |
668ea4b1 | 1252 | static bool c_parser_objc_diagnose_bad_element_prefix |
c165dca7 | 1253 | (c_parser *, struct c_declspecs *); |
27bf414c | 1254 | |
c02065fc AH |
1255 | /* Cilk Plus supporting routines. */ |
1256 | static void c_parser_cilk_simd (c_parser *); | |
1257 | static bool c_parser_cilk_verify_simd (c_parser *, enum pragma_context); | |
36536d79 | 1258 | static tree c_parser_array_notation (location_t, c_parser *, tree, tree); |
41958c28 | 1259 | static tree c_parser_cilk_clause_vectorlength (c_parser *, tree, bool); |
36536d79 | 1260 | |
27bf414c JM |
1261 | /* Parse a translation unit (C90 6.7, C99 6.9). |
1262 | ||
1263 | translation-unit: | |
1264 | external-declarations | |
1265 | ||
1266 | external-declarations: | |
1267 | external-declaration | |
1268 | external-declarations external-declaration | |
1269 | ||
1270 | GNU extensions: | |
1271 | ||
1272 | translation-unit: | |
1273 | empty | |
1274 | */ | |
1275 | ||
1276 | static void | |
1277 | c_parser_translation_unit (c_parser *parser) | |
1278 | { | |
1279 | if (c_parser_next_token_is (parser, CPP_EOF)) | |
1280 | { | |
c1771a20 | 1281 | pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic, |
509c9d60 | 1282 | "ISO C forbids an empty translation unit"); |
27bf414c JM |
1283 | } |
1284 | else | |
1285 | { | |
1286 | void *obstack_position = obstack_alloc (&parser_obstack, 0); | |
6ec637a4 | 1287 | mark_valid_location_for_stdc_pragma (false); |
27bf414c JM |
1288 | do |
1289 | { | |
1290 | ggc_collect (); | |
1291 | c_parser_external_declaration (parser); | |
1292 | obstack_free (&parser_obstack, obstack_position); | |
1293 | } | |
1294 | while (c_parser_next_token_is_not (parser, CPP_EOF)); | |
1295 | } | |
1296 | } | |
1297 | ||
1298 | /* Parse an external declaration (C90 6.7, C99 6.9). | |
1299 | ||
1300 | external-declaration: | |
1301 | function-definition | |
1302 | declaration | |
1303 | ||
1304 | GNU extensions: | |
1305 | ||
1306 | external-declaration: | |
1307 | asm-definition | |
1308 | ; | |
1309 | __extension__ external-declaration | |
1310 | ||
1311 | Objective-C: | |
1312 | ||
1313 | external-declaration: | |
1314 | objc-class-definition | |
1315 | objc-class-declaration | |
1316 | objc-alias-declaration | |
1317 | objc-protocol-definition | |
1318 | objc-method-definition | |
1319 | @end | |
1320 | */ | |
1321 | ||
1322 | static void | |
1323 | c_parser_external_declaration (c_parser *parser) | |
1324 | { | |
1325 | int ext; | |
1326 | switch (c_parser_peek_token (parser)->type) | |
1327 | { | |
1328 | case CPP_KEYWORD: | |
1329 | switch (c_parser_peek_token (parser)->keyword) | |
1330 | { | |
1331 | case RID_EXTENSION: | |
1332 | ext = disable_extension_diagnostics (); | |
1333 | c_parser_consume_token (parser); | |
1334 | c_parser_external_declaration (parser); | |
1335 | restore_extension_diagnostics (ext); | |
1336 | break; | |
1337 | case RID_ASM: | |
1338 | c_parser_asm_definition (parser); | |
1339 | break; | |
1340 | case RID_AT_INTERFACE: | |
1341 | case RID_AT_IMPLEMENTATION: | |
1342 | gcc_assert (c_dialect_objc ()); | |
c165dca7 | 1343 | c_parser_objc_class_definition (parser, NULL_TREE); |
27bf414c | 1344 | break; |
49b91f05 | 1345 | case RID_AT_CLASS: |
27bf414c JM |
1346 | gcc_assert (c_dialect_objc ()); |
1347 | c_parser_objc_class_declaration (parser); | |
1348 | break; | |
1349 | case RID_AT_ALIAS: | |
1350 | gcc_assert (c_dialect_objc ()); | |
1351 | c_parser_objc_alias_declaration (parser); | |
1352 | break; | |
1353 | case RID_AT_PROTOCOL: | |
1354 | gcc_assert (c_dialect_objc ()); | |
c165dca7 | 1355 | c_parser_objc_protocol_definition (parser, NULL_TREE); |
27bf414c | 1356 | break; |
668ea4b1 IS |
1357 | case RID_AT_PROPERTY: |
1358 | gcc_assert (c_dialect_objc ()); | |
f614132b | 1359 | c_parser_objc_at_property_declaration (parser); |
668ea4b1 | 1360 | break; |
da57d1b9 NP |
1361 | case RID_AT_SYNTHESIZE: |
1362 | gcc_assert (c_dialect_objc ()); | |
1363 | c_parser_objc_at_synthesize_declaration (parser); | |
1364 | break; | |
1365 | case RID_AT_DYNAMIC: | |
1366 | gcc_assert (c_dialect_objc ()); | |
1367 | c_parser_objc_at_dynamic_declaration (parser); | |
1368 | break; | |
27bf414c JM |
1369 | case RID_AT_END: |
1370 | gcc_assert (c_dialect_objc ()); | |
1371 | c_parser_consume_token (parser); | |
1372 | objc_finish_implementation (); | |
1373 | break; | |
1374 | default: | |
1375 | goto decl_or_fndef; | |
1376 | } | |
1377 | break; | |
1378 | case CPP_SEMICOLON: | |
c1771a20 | 1379 | pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic, |
509c9d60 | 1380 | "ISO C does not allow extra %<;%> outside of a function"); |
27bf414c JM |
1381 | c_parser_consume_token (parser); |
1382 | break; | |
bc4071dd | 1383 | case CPP_PRAGMA: |
6ec637a4 | 1384 | mark_valid_location_for_stdc_pragma (true); |
bc4071dd | 1385 | c_parser_pragma (parser, pragma_external); |
6ec637a4 | 1386 | mark_valid_location_for_stdc_pragma (false); |
bc4071dd | 1387 | break; |
27bf414c JM |
1388 | case CPP_PLUS: |
1389 | case CPP_MINUS: | |
1390 | if (c_dialect_objc ()) | |
1391 | { | |
1392 | c_parser_objc_method_definition (parser); | |
1393 | break; | |
1394 | } | |
1395 | /* Else fall through, and yield a syntax error trying to parse | |
1396 | as a declaration or function definition. */ | |
1397 | default: | |
1398 | decl_or_fndef: | |
c165dca7 IS |
1399 | /* A declaration or a function definition (or, in Objective-C, |
1400 | an @interface or @protocol with prefix attributes). We can | |
1401 | only tell which after parsing the declaration specifiers, if | |
1402 | any, and the first declarator. */ | |
acf0174b JJ |
1403 | c_parser_declaration_or_fndef (parser, true, true, true, false, true, |
1404 | NULL, vNULL); | |
27bf414c JM |
1405 | break; |
1406 | } | |
1407 | } | |
1408 | ||
acf0174b JJ |
1409 | static void c_finish_omp_declare_simd (c_parser *, tree, tree, vec<c_token>); |
1410 | ||
27bf414c JM |
1411 | /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99 |
1412 | 6.7, 6.9.1). If FNDEF_OK is true, a function definition is | |
1413 | accepted; otherwise (old-style parameter declarations) only other | |
32912286 JM |
1414 | declarations are accepted. If STATIC_ASSERT_OK is true, a static |
1415 | assertion is accepted; otherwise (old-style parameter declarations) | |
1416 | it is not. If NESTED is true, we are inside a function or parsing | |
1417 | old-style parameter declarations; any functions encountered are | |
1418 | nested functions and declaration specifiers are required; otherwise | |
1419 | we are at top level and functions are normal functions and | |
1420 | declaration specifiers may be optional. If EMPTY_OK is true, empty | |
1421 | declarations are OK (subject to all other constraints); otherwise | |
1422 | (old-style parameter declarations) they are diagnosed. If | |
1423 | START_ATTR_OK is true, the declaration specifiers may start with | |
1424 | attributes; otherwise they may not. | |
f05b9d93 NP |
1425 | OBJC_FOREACH_OBJECT_DECLARATION can be used to get back the parsed |
1426 | declaration when parsing an Objective-C foreach statement. | |
27bf414c JM |
1427 | |
1428 | declaration: | |
1429 | declaration-specifiers init-declarator-list[opt] ; | |
32912286 | 1430 | static_assert-declaration |
27bf414c JM |
1431 | |
1432 | function-definition: | |
1433 | declaration-specifiers[opt] declarator declaration-list[opt] | |
1434 | compound-statement | |
1435 | ||
1436 | declaration-list: | |
1437 | declaration | |
1438 | declaration-list declaration | |
1439 | ||
1440 | init-declarator-list: | |
1441 | init-declarator | |
1442 | init-declarator-list , init-declarator | |
1443 | ||
1444 | init-declarator: | |
1445 | declarator simple-asm-expr[opt] attributes[opt] | |
1446 | declarator simple-asm-expr[opt] attributes[opt] = initializer | |
1447 | ||
1448 | GNU extensions: | |
1449 | ||
1450 | nested-function-definition: | |
1451 | declaration-specifiers declarator declaration-list[opt] | |
1452 | compound-statement | |
1453 | ||
c165dca7 IS |
1454 | Objective-C: |
1455 | attributes objc-class-definition | |
1456 | attributes objc-category-definition | |
1457 | attributes objc-protocol-definition | |
1458 | ||
27bf414c JM |
1459 | The simple-asm-expr and attributes are GNU extensions. |
1460 | ||
1461 | This function does not handle __extension__; that is handled in its | |
1462 | callers. ??? Following the old parser, __extension__ may start | |
1463 | external declarations, declarations in functions and declarations | |
1464 | at the start of "for" loops, but not old-style parameter | |
1465 | declarations. | |
1466 | ||
1467 | C99 requires declaration specifiers in a function definition; the | |
1468 | absence is diagnosed through the diagnosis of implicit int. In GNU | |
1469 | C we also allow but diagnose declarations without declaration | |
1470 | specifiers, but only at top level (elsewhere they conflict with | |
953ff289 | 1471 | other syntax). |
b8698a0f | 1472 | |
f05b9d93 NP |
1473 | In Objective-C, declarations of the looping variable in a foreach |
1474 | statement are exceptionally terminated by 'in' (for example, 'for | |
1475 | (NSObject *object in array) { ... }'). | |
1476 | ||
953ff289 | 1477 | OpenMP: |
b8698a0f | 1478 | |
953ff289 DN |
1479 | declaration: |
1480 | threadprivate-directive */ | |
27bf414c JM |
1481 | |
1482 | static void | |
32912286 JM |
1483 | c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok, |
1484 | bool static_assert_ok, bool empty_ok, | |
f05b9d93 | 1485 | bool nested, bool start_attr_ok, |
acf0174b JJ |
1486 | tree *objc_foreach_object_declaration, |
1487 | vec<c_token> omp_declare_simd_clauses) | |
27bf414c JM |
1488 | { |
1489 | struct c_declspecs *specs; | |
1490 | tree prefix_attrs; | |
1491 | tree all_prefix_attrs; | |
1492 | bool diagnosed_no_specs = false; | |
c7412148 | 1493 | location_t here = c_parser_peek_token (parser)->location; |
bc4071dd | 1494 | |
32912286 JM |
1495 | if (static_assert_ok |
1496 | && c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT)) | |
1497 | { | |
1498 | c_parser_static_assert_declaration (parser); | |
1499 | return; | |
1500 | } | |
27bf414c | 1501 | specs = build_null_declspecs (); |
2f413185 PB |
1502 | |
1503 | /* Try to detect an unknown type name when we have "A B" or "A *B". */ | |
1504 | if (c_parser_peek_token (parser)->type == CPP_NAME | |
1505 | && c_parser_peek_token (parser)->id_kind == C_ID_ID | |
1506 | && (c_parser_peek_2nd_token (parser)->type == CPP_NAME | |
1507 | || c_parser_peek_2nd_token (parser)->type == CPP_MULT) | |
1508 | && (!nested || !lookup_name (c_parser_peek_token (parser)->value))) | |
1509 | { | |
1510 | error_at (here, "unknown type name %qE", | |
1511 | c_parser_peek_token (parser)->value); | |
1512 | ||
1513 | /* Parse declspecs normally to get a correct pointer type, but avoid | |
a5812bdc PB |
1514 | a further "fails to be a type name" error. Refuse nested functions |
1515 | since it is not how the user likely wants us to recover. */ | |
2f413185 PB |
1516 | c_parser_peek_token (parser)->type = CPP_KEYWORD; |
1517 | c_parser_peek_token (parser)->keyword = RID_VOID; | |
1518 | c_parser_peek_token (parser)->value = error_mark_node; | |
a5812bdc | 1519 | fndef_ok = !nested; |
2f413185 PB |
1520 | } |
1521 | ||
568a31f2 | 1522 | c_parser_declspecs (parser, specs, true, true, start_attr_ok, |
38b7bc7f | 1523 | true, true, cla_nonabstract_decl); |
27bf414c JM |
1524 | if (parser->error) |
1525 | { | |
1526 | c_parser_skip_to_end_of_block_or_statement (parser); | |
1527 | return; | |
1528 | } | |
1529 | if (nested && !specs->declspecs_seen_p) | |
1530 | { | |
1531 | c_parser_error (parser, "expected declaration specifiers"); | |
1532 | c_parser_skip_to_end_of_block_or_statement (parser); | |
1533 | return; | |
1534 | } | |
1535 | finish_declspecs (specs); | |
38b7bc7f | 1536 | bool auto_type_p = specs->typespec_word == cts_auto_type; |
27bf414c JM |
1537 | if (c_parser_next_token_is (parser, CPP_SEMICOLON)) |
1538 | { | |
38b7bc7f JM |
1539 | if (auto_type_p) |
1540 | error_at (here, "%<__auto_type%> in empty declaration"); | |
1541 | else if (empty_ok) | |
27bf414c JM |
1542 | shadow_tag (specs); |
1543 | else | |
1544 | { | |
1545 | shadow_tag_warned (specs, 1); | |
509c9d60 | 1546 | pedwarn (here, 0, "empty declaration"); |
27bf414c JM |
1547 | } |
1548 | c_parser_consume_token (parser); | |
1549 | return; | |
1550 | } | |
f725e721 PB |
1551 | |
1552 | /* Provide better error recovery. Note that a type name here is usually | |
1553 | better diagnosed as a redeclaration. */ | |
1554 | if (empty_ok | |
1555 | && specs->typespec_kind == ctsk_tagdef | |
1556 | && c_parser_next_token_starts_declspecs (parser) | |
1557 | && !c_parser_next_token_is (parser, CPP_NAME)) | |
1558 | { | |
1559 | c_parser_error (parser, "expected %<;%>, identifier or %<(%>"); | |
1560 | parser->error = false; | |
1561 | shadow_tag_warned (specs, 1); | |
1562 | return; | |
1563 | } | |
38b7bc7f | 1564 | else if (c_dialect_objc () && !auto_type_p) |
c165dca7 | 1565 | { |
f7e71da5 IS |
1566 | /* Prefix attributes are an error on method decls. */ |
1567 | switch (c_parser_peek_token (parser)->type) | |
1568 | { | |
1569 | case CPP_PLUS: | |
1570 | case CPP_MINUS: | |
1571 | if (c_parser_objc_diagnose_bad_element_prefix (parser, specs)) | |
1572 | return; | |
1573 | if (specs->attrs) | |
1574 | { | |
1575 | warning_at (c_parser_peek_token (parser)->location, | |
1576 | OPT_Wattributes, | |
1577 | "prefix attributes are ignored for methods"); | |
1578 | specs->attrs = NULL_TREE; | |
1579 | } | |
1580 | if (fndef_ok) | |
1581 | c_parser_objc_method_definition (parser); | |
1582 | else | |
1583 | c_parser_objc_methodproto (parser); | |
1584 | return; | |
1585 | break; | |
1586 | default: | |
1587 | break; | |
1588 | } | |
c165dca7 IS |
1589 | /* This is where we parse 'attributes @interface ...', |
1590 | 'attributes @implementation ...', 'attributes @protocol ...' | |
1591 | (where attributes could be, for example, __attribute__ | |
1592 | ((deprecated)). | |
1593 | */ | |
1594 | switch (c_parser_peek_token (parser)->keyword) | |
1595 | { | |
1596 | case RID_AT_INTERFACE: | |
1597 | { | |
1598 | if (c_parser_objc_diagnose_bad_element_prefix (parser, specs)) | |
1599 | return; | |
1600 | c_parser_objc_class_definition (parser, specs->attrs); | |
1601 | return; | |
1602 | } | |
1603 | break; | |
1604 | case RID_AT_IMPLEMENTATION: | |
1605 | { | |
1606 | if (c_parser_objc_diagnose_bad_element_prefix (parser, specs)) | |
1607 | return; | |
1608 | if (specs->attrs) | |
1609 | { | |
1610 | warning_at (c_parser_peek_token (parser)->location, | |
1611 | OPT_Wattributes, | |
1612 | "prefix attributes are ignored for implementations"); | |
1613 | specs->attrs = NULL_TREE; | |
1614 | } | |
1615 | c_parser_objc_class_definition (parser, NULL_TREE); | |
1616 | return; | |
1617 | } | |
1618 | break; | |
1619 | case RID_AT_PROTOCOL: | |
1620 | { | |
1621 | if (c_parser_objc_diagnose_bad_element_prefix (parser, specs)) | |
1622 | return; | |
1623 | c_parser_objc_protocol_definition (parser, specs->attrs); | |
1624 | return; | |
1625 | } | |
1626 | break; | |
668ea4b1 IS |
1627 | case RID_AT_ALIAS: |
1628 | case RID_AT_CLASS: | |
1629 | case RID_AT_END: | |
1630 | case RID_AT_PROPERTY: | |
1631 | if (specs->attrs) | |
1632 | { | |
96bbfbac | 1633 | c_parser_error (parser, "unexpected attribute"); |
668ea4b1 IS |
1634 | specs->attrs = NULL; |
1635 | } | |
1636 | break; | |
c165dca7 IS |
1637 | default: |
1638 | break; | |
1639 | } | |
1640 | } | |
1641 | ||
27bf414c JM |
1642 | pending_xref_error (); |
1643 | prefix_attrs = specs->attrs; | |
1644 | all_prefix_attrs = prefix_attrs; | |
1645 | specs->attrs = NULL_TREE; | |
1646 | while (true) | |
1647 | { | |
1648 | struct c_declarator *declarator; | |
1649 | bool dummy = false; | |
575bfb00 | 1650 | timevar_id_t tv; |
27bf414c JM |
1651 | tree fnbody; |
1652 | /* Declaring either one or more declarators (in which case we | |
1653 | should diagnose if there were no declaration specifiers) or a | |
1654 | function definition (in which case the diagnostic for | |
1655 | implicit int suffices). */ | |
9e5b2115 PB |
1656 | declarator = c_parser_declarator (parser, |
1657 | specs->typespec_kind != ctsk_none, | |
27bf414c JM |
1658 | C_DTR_NORMAL, &dummy); |
1659 | if (declarator == NULL) | |
1660 | { | |
41958c28 BI |
1661 | if (omp_declare_simd_clauses.exists () |
1662 | || !vec_safe_is_empty (parser->cilk_simd_fn_tokens)) | |
acf0174b JJ |
1663 | c_finish_omp_declare_simd (parser, NULL_TREE, NULL_TREE, |
1664 | omp_declare_simd_clauses); | |
27bf414c JM |
1665 | c_parser_skip_to_end_of_block_or_statement (parser); |
1666 | return; | |
1667 | } | |
38b7bc7f JM |
1668 | if (auto_type_p && declarator->kind != cdk_id) |
1669 | { | |
1670 | error_at (here, | |
1671 | "%<__auto_type%> requires a plain identifier" | |
1672 | " as declarator"); | |
1673 | c_parser_skip_to_end_of_block_or_statement (parser); | |
1674 | return; | |
1675 | } | |
27bf414c JM |
1676 | if (c_parser_next_token_is (parser, CPP_EQ) |
1677 | || c_parser_next_token_is (parser, CPP_COMMA) | |
1678 | || c_parser_next_token_is (parser, CPP_SEMICOLON) | |
1679 | || c_parser_next_token_is_keyword (parser, RID_ASM) | |
f05b9d93 NP |
1680 | || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE) |
1681 | || c_parser_next_token_is_keyword (parser, RID_IN)) | |
27bf414c JM |
1682 | { |
1683 | tree asm_name = NULL_TREE; | |
1684 | tree postfix_attrs = NULL_TREE; | |
1685 | if (!diagnosed_no_specs && !specs->declspecs_seen_p) | |
1686 | { | |
1687 | diagnosed_no_specs = true; | |
509c9d60 | 1688 | pedwarn (here, 0, "data definition has no type or storage class"); |
27bf414c JM |
1689 | } |
1690 | /* Having seen a data definition, there cannot now be a | |
1691 | function definition. */ | |
1692 | fndef_ok = false; | |
1693 | if (c_parser_next_token_is_keyword (parser, RID_ASM)) | |
1694 | asm_name = c_parser_simple_asm_expr (parser); | |
1695 | if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)) | |
ae5ebda4 MP |
1696 | { |
1697 | postfix_attrs = c_parser_attributes (parser); | |
1698 | if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) | |
1699 | { | |
1700 | /* This means there is an attribute specifier after | |
1701 | the declarator in a function definition. Provide | |
1702 | some more information for the user. */ | |
1703 | error_at (here, "attributes should be specified before the " | |
1704 | "declarator in a function definition"); | |
1705 | c_parser_skip_to_end_of_block_or_statement (parser); | |
1706 | return; | |
1707 | } | |
1708 | } | |
27bf414c JM |
1709 | if (c_parser_next_token_is (parser, CPP_EQ)) |
1710 | { | |
1711 | tree d; | |
1712 | struct c_expr init; | |
c2255bc4 | 1713 | location_t init_loc; |
27bf414c | 1714 | c_parser_consume_token (parser); |
38b7bc7f JM |
1715 | if (auto_type_p) |
1716 | { | |
1717 | start_init (NULL_TREE, asm_name, global_bindings_p ()); | |
1718 | init_loc = c_parser_peek_token (parser)->location; | |
1719 | init = c_parser_expr_no_commas (parser, NULL); | |
1720 | if (TREE_CODE (init.value) == COMPONENT_REF | |
1721 | && DECL_C_BIT_FIELD (TREE_OPERAND (init.value, 1))) | |
1722 | error_at (here, | |
1723 | "%<__auto_type%> used with a bit-field" | |
1724 | " initializer"); | |
1725 | init = convert_lvalue_to_rvalue (init_loc, init, true, true); | |
1726 | tree init_type = TREE_TYPE (init.value); | |
9698b078 | 1727 | /* As with typeof, remove all qualifiers from atomic types. */ |
38b7bc7f JM |
1728 | if (init_type != error_mark_node && TYPE_ATOMIC (init_type)) |
1729 | init_type | |
9698b078 | 1730 | = c_build_qualified_type (init_type, TYPE_UNQUALIFIED); |
38b7bc7f JM |
1731 | bool vm_type = variably_modified_type_p (init_type, |
1732 | NULL_TREE); | |
1733 | if (vm_type) | |
1734 | init.value = c_save_expr (init.value); | |
1735 | finish_init (); | |
1736 | specs->typespec_kind = ctsk_typeof; | |
1737 | specs->locations[cdw_typedef] = init_loc; | |
1738 | specs->typedef_p = true; | |
1739 | specs->type = init_type; | |
1740 | if (vm_type) | |
1741 | { | |
1742 | bool maybe_const = true; | |
1743 | tree type_expr = c_fully_fold (init.value, false, | |
1744 | &maybe_const); | |
1745 | specs->expr_const_operands &= maybe_const; | |
1746 | if (specs->expr) | |
1747 | specs->expr = build2 (COMPOUND_EXPR, | |
1748 | TREE_TYPE (type_expr), | |
1749 | specs->expr, type_expr); | |
1750 | else | |
1751 | specs->expr = type_expr; | |
1752 | } | |
1753 | d = start_decl (declarator, specs, true, | |
1754 | chainon (postfix_attrs, all_prefix_attrs)); | |
1755 | if (!d) | |
1756 | d = error_mark_node; | |
41958c28 BI |
1757 | if (omp_declare_simd_clauses.exists () |
1758 | || !vec_safe_is_empty (parser->cilk_simd_fn_tokens)) | |
38b7bc7f JM |
1759 | c_finish_omp_declare_simd (parser, d, NULL_TREE, |
1760 | omp_declare_simd_clauses); | |
1761 | } | |
1762 | else | |
1763 | { | |
1764 | /* The declaration of the variable is in effect while | |
1765 | its initializer is parsed. */ | |
1766 | d = start_decl (declarator, specs, true, | |
1767 | chainon (postfix_attrs, all_prefix_attrs)); | |
1768 | if (!d) | |
1769 | d = error_mark_node; | |
41958c28 BI |
1770 | if (omp_declare_simd_clauses.exists () |
1771 | || !vec_safe_is_empty (parser->cilk_simd_fn_tokens)) | |
38b7bc7f JM |
1772 | c_finish_omp_declare_simd (parser, d, NULL_TREE, |
1773 | omp_declare_simd_clauses); | |
1774 | start_init (d, asm_name, global_bindings_p ()); | |
1775 | init_loc = c_parser_peek_token (parser)->location; | |
1776 | init = c_parser_initializer (parser); | |
1777 | finish_init (); | |
1778 | } | |
27bf414c JM |
1779 | if (d != error_mark_node) |
1780 | { | |
d033409e | 1781 | maybe_warn_string_init (init_loc, TREE_TYPE (d), init); |
c2255bc4 | 1782 | finish_decl (d, init_loc, init.value, |
d033409e | 1783 | init.original_type, asm_name); |
27bf414c JM |
1784 | } |
1785 | } | |
1786 | else | |
1787 | { | |
38b7bc7f JM |
1788 | if (auto_type_p) |
1789 | { | |
1790 | error_at (here, | |
1791 | "%<__auto_type%> requires an initialized " | |
1792 | "data declaration"); | |
1793 | c_parser_skip_to_end_of_block_or_statement (parser); | |
1794 | return; | |
1795 | } | |
27bf414c JM |
1796 | tree d = start_decl (declarator, specs, false, |
1797 | chainon (postfix_attrs, | |
1798 | all_prefix_attrs)); | |
41958c28 BI |
1799 | if (omp_declare_simd_clauses.exists () |
1800 | || !vec_safe_is_empty (parser->cilk_simd_fn_tokens)) | |
acf0174b JJ |
1801 | { |
1802 | tree parms = NULL_TREE; | |
1803 | if (d && TREE_CODE (d) == FUNCTION_DECL) | |
1804 | { | |
1805 | struct c_declarator *ce = declarator; | |
1806 | while (ce != NULL) | |
1807 | if (ce->kind == cdk_function) | |
1808 | { | |
1809 | parms = ce->u.arg_info->parms; | |
1810 | break; | |
1811 | } | |
1812 | else | |
1813 | ce = ce->declarator; | |
1814 | } | |
1815 | if (parms) | |
1816 | temp_store_parm_decls (d, parms); | |
1817 | c_finish_omp_declare_simd (parser, d, parms, | |
1818 | omp_declare_simd_clauses); | |
1819 | if (parms) | |
1820 | temp_pop_parm_decls (); | |
1821 | } | |
27bf414c | 1822 | if (d) |
c2255bc4 | 1823 | finish_decl (d, UNKNOWN_LOCATION, NULL_TREE, |
f05b9d93 NP |
1824 | NULL_TREE, asm_name); |
1825 | ||
1826 | if (c_parser_next_token_is_keyword (parser, RID_IN)) | |
1827 | { | |
1828 | if (d) | |
1829 | *objc_foreach_object_declaration = d; | |
1830 | else | |
1831 | *objc_foreach_object_declaration = error_mark_node; | |
1832 | } | |
27bf414c JM |
1833 | } |
1834 | if (c_parser_next_token_is (parser, CPP_COMMA)) | |
1835 | { | |
38b7bc7f JM |
1836 | if (auto_type_p) |
1837 | { | |
1838 | error_at (here, | |
1839 | "%<__auto_type%> may only be used with" | |
1840 | " a single declarator"); | |
1841 | c_parser_skip_to_end_of_block_or_statement (parser); | |
1842 | return; | |
1843 | } | |
27bf414c JM |
1844 | c_parser_consume_token (parser); |
1845 | if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)) | |
1846 | all_prefix_attrs = chainon (c_parser_attributes (parser), | |
1847 | prefix_attrs); | |
1848 | else | |
1849 | all_prefix_attrs = prefix_attrs; | |
1850 | continue; | |
1851 | } | |
1852 | else if (c_parser_next_token_is (parser, CPP_SEMICOLON)) | |
1853 | { | |
1854 | c_parser_consume_token (parser); | |
1855 | return; | |
1856 | } | |
f05b9d93 NP |
1857 | else if (c_parser_next_token_is_keyword (parser, RID_IN)) |
1858 | { | |
1859 | /* This can only happen in Objective-C: we found the | |
1860 | 'in' that terminates the declaration inside an | |
1861 | Objective-C foreach statement. Do not consume the | |
1862 | token, so that the caller can use it to determine | |
1863 | that this indeed is a foreach context. */ | |
1864 | return; | |
1865 | } | |
27bf414c JM |
1866 | else |
1867 | { | |
1868 | c_parser_error (parser, "expected %<,%> or %<;%>"); | |
1869 | c_parser_skip_to_end_of_block_or_statement (parser); | |
1870 | return; | |
1871 | } | |
1872 | } | |
38b7bc7f JM |
1873 | else if (auto_type_p) |
1874 | { | |
1875 | error_at (here, | |
1876 | "%<__auto_type%> requires an initialized data declaration"); | |
1877 | c_parser_skip_to_end_of_block_or_statement (parser); | |
1878 | return; | |
1879 | } | |
27bf414c JM |
1880 | else if (!fndef_ok) |
1881 | { | |
1882 | c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, " | |
1883 | "%<asm%> or %<__attribute__%>"); | |
1884 | c_parser_skip_to_end_of_block_or_statement (parser); | |
1885 | return; | |
1886 | } | |
1887 | /* Function definition (nested or otherwise). */ | |
1888 | if (nested) | |
1889 | { | |
c1771a20 | 1890 | pedwarn (here, OPT_Wpedantic, "ISO C forbids nested functions"); |
d2784db4 | 1891 | c_push_function_context (); |
27bf414c JM |
1892 | } |
1893 | if (!start_function (specs, declarator, all_prefix_attrs)) | |
1894 | { | |
1895 | /* This can appear in many cases looking nothing like a | |
1896 | function definition, so we don't give a more specific | |
1897 | error suggesting there was one. */ | |
1898 | c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, %<asm%> " | |
1899 | "or %<__attribute__%>"); | |
1900 | if (nested) | |
d2784db4 | 1901 | c_pop_function_context (); |
27bf414c JM |
1902 | break; |
1903 | } | |
575bfb00 LC |
1904 | |
1905 | if (DECL_DECLARED_INLINE_P (current_function_decl)) | |
1906 | tv = TV_PARSE_INLINE; | |
1907 | else | |
1908 | tv = TV_PARSE_FUNC; | |
1909 | timevar_push (tv); | |
1910 | ||
27bf414c JM |
1911 | /* Parse old-style parameter declarations. ??? Attributes are |
1912 | not allowed to start declaration specifiers here because of a | |
1913 | syntax conflict between a function declaration with attribute | |
1914 | suffix and a function definition with an attribute prefix on | |
1915 | first old-style parameter declaration. Following the old | |
1916 | parser, they are not accepted on subsequent old-style | |
1917 | parameter declarations either. However, there is no | |
1918 | ambiguity after the first declaration, nor indeed on the | |
1919 | first as long as we don't allow postfix attributes after a | |
1920 | declarator with a nonempty identifier list in a definition; | |
1921 | and postfix attributes have never been accepted here in | |
1922 | function definitions either. */ | |
1923 | while (c_parser_next_token_is_not (parser, CPP_EOF) | |
1924 | && c_parser_next_token_is_not (parser, CPP_OPEN_BRACE)) | |
32912286 | 1925 | c_parser_declaration_or_fndef (parser, false, false, false, |
acf0174b | 1926 | true, false, NULL, vNULL); |
27bf414c | 1927 | store_parm_decls (); |
41958c28 BI |
1928 | if (omp_declare_simd_clauses.exists () |
1929 | || !vec_safe_is_empty (parser->cilk_simd_fn_tokens)) | |
acf0174b JJ |
1930 | c_finish_omp_declare_simd (parser, current_function_decl, NULL_TREE, |
1931 | omp_declare_simd_clauses); | |
1751ecd6 AH |
1932 | DECL_STRUCT_FUNCTION (current_function_decl)->function_start_locus |
1933 | = c_parser_peek_token (parser)->location; | |
27bf414c | 1934 | fnbody = c_parser_compound_statement (parser); |
b72271b9 | 1935 | if (flag_cilkplus && contains_array_notation_expr (fnbody)) |
25c22937 | 1936 | fnbody = expand_array_notation_exprs (fnbody); |
27bf414c JM |
1937 | if (nested) |
1938 | { | |
1939 | tree decl = current_function_decl; | |
9f62cb92 JJ |
1940 | /* Mark nested functions as needing static-chain initially. |
1941 | lower_nested_functions will recompute it but the | |
1942 | DECL_STATIC_CHAIN flag is also used before that happens, | |
1943 | by initializer_constant_valid_p. See gcc.dg/nested-fn-2.c. */ | |
1944 | DECL_STATIC_CHAIN (decl) = 1; | |
27bf414c JM |
1945 | add_stmt (fnbody); |
1946 | finish_function (); | |
d2784db4 | 1947 | c_pop_function_context (); |
c2255bc4 | 1948 | add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl), DECL_EXPR, decl)); |
27bf414c JM |
1949 | } |
1950 | else | |
1951 | { | |
1952 | add_stmt (fnbody); | |
1953 | finish_function (); | |
1954 | } | |
575bfb00 LC |
1955 | |
1956 | timevar_pop (tv); | |
27bf414c JM |
1957 | break; |
1958 | } | |
1959 | } | |
1960 | ||
1961 | /* Parse an asm-definition (asm() outside a function body). This is a | |
1962 | GNU extension. | |
1963 | ||
1964 | asm-definition: | |
1965 | simple-asm-expr ; | |
1966 | */ | |
1967 | ||
1968 | static void | |
1969 | c_parser_asm_definition (c_parser *parser) | |
1970 | { | |
1971 | tree asm_str = c_parser_simple_asm_expr (parser); | |
27bf414c | 1972 | if (asm_str) |
65d630d4 | 1973 | add_asm_node (asm_str); |
27bf414c JM |
1974 | c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); |
1975 | } | |
1976 | ||
48b0b196 | 1977 | /* Parse a static assertion (C11 6.7.10). |
32912286 JM |
1978 | |
1979 | static_assert-declaration: | |
1980 | static_assert-declaration-no-semi ; | |
1981 | */ | |
1982 | ||
1983 | static void | |
1984 | c_parser_static_assert_declaration (c_parser *parser) | |
1985 | { | |
1986 | c_parser_static_assert_declaration_no_semi (parser); | |
1987 | if (parser->error | |
1988 | || !c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>")) | |
1989 | c_parser_skip_to_end_of_block_or_statement (parser); | |
1990 | } | |
1991 | ||
48b0b196 | 1992 | /* Parse a static assertion (C11 6.7.10), without the trailing |
32912286 JM |
1993 | semicolon. |
1994 | ||
1995 | static_assert-declaration-no-semi: | |
1996 | _Static_assert ( constant-expression , string-literal ) | |
1997 | */ | |
1998 | ||
1999 | static void | |
2000 | c_parser_static_assert_declaration_no_semi (c_parser *parser) | |
2001 | { | |
2002 | location_t assert_loc, value_loc; | |
2003 | tree value; | |
2004 | tree string; | |
2005 | ||
2006 | gcc_assert (c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT)); | |
2007 | assert_loc = c_parser_peek_token (parser)->location; | |
48b0b196 | 2008 | if (!flag_isoc11) |
32912286 JM |
2009 | { |
2010 | if (flag_isoc99) | |
c1771a20 | 2011 | pedwarn (assert_loc, OPT_Wpedantic, |
32912286 JM |
2012 | "ISO C99 does not support %<_Static_assert%>"); |
2013 | else | |
c1771a20 | 2014 | pedwarn (assert_loc, OPT_Wpedantic, |
32912286 JM |
2015 | "ISO C90 does not support %<_Static_assert%>"); |
2016 | } | |
2017 | c_parser_consume_token (parser); | |
2018 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
2019 | return; | |
2020 | value_loc = c_parser_peek_token (parser)->location; | |
2021 | value = c_parser_expr_no_commas (parser, NULL).value; | |
2022 | parser->lex_untranslated_string = true; | |
2023 | if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>")) | |
2024 | { | |
2025 | parser->lex_untranslated_string = false; | |
2026 | return; | |
2027 | } | |
2028 | switch (c_parser_peek_token (parser)->type) | |
2029 | { | |
2030 | case CPP_STRING: | |
2031 | case CPP_STRING16: | |
2032 | case CPP_STRING32: | |
2033 | case CPP_WSTRING: | |
2034 | case CPP_UTF8STRING: | |
2035 | string = c_parser_peek_token (parser)->value; | |
2036 | c_parser_consume_token (parser); | |
2037 | parser->lex_untranslated_string = false; | |
2038 | break; | |
2039 | default: | |
2040 | c_parser_error (parser, "expected string literal"); | |
2041 | parser->lex_untranslated_string = false; | |
2042 | return; | |
2043 | } | |
2044 | c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
2045 | ||
2046 | if (!INTEGRAL_TYPE_P (TREE_TYPE (value))) | |
2047 | { | |
2048 | error_at (value_loc, "expression in static assertion is not an integer"); | |
2049 | return; | |
2050 | } | |
2051 | if (TREE_CODE (value) != INTEGER_CST) | |
2052 | { | |
2053 | value = c_fully_fold (value, false, NULL); | |
2054 | if (TREE_CODE (value) == INTEGER_CST) | |
c1771a20 | 2055 | pedwarn (value_loc, OPT_Wpedantic, "expression in static assertion " |
32912286 JM |
2056 | "is not an integer constant expression"); |
2057 | } | |
2058 | if (TREE_CODE (value) != INTEGER_CST) | |
2059 | { | |
2060 | error_at (value_loc, "expression in static assertion is not constant"); | |
2061 | return; | |
2062 | } | |
2063 | constant_expression_warning (value); | |
2064 | if (integer_zerop (value)) | |
2065 | error_at (assert_loc, "static assertion failed: %E", string); | |
2066 | } | |
2067 | ||
27bf414c JM |
2068 | /* Parse some declaration specifiers (possibly none) (C90 6.5, C99 |
2069 | 6.7), adding them to SPECS (which may already include some). | |
2070 | Storage class specifiers are accepted iff SCSPEC_OK; type | |
568a31f2 MP |
2071 | specifiers are accepted iff TYPESPEC_OK; alignment specifiers are |
2072 | accepted iff ALIGNSPEC_OK; attributes are accepted at the start | |
38b7bc7f | 2073 | iff START_ATTR_OK; __auto_type is accepted iff AUTO_TYPE_OK. |
27bf414c JM |
2074 | |
2075 | declaration-specifiers: | |
2076 | storage-class-specifier declaration-specifiers[opt] | |
2077 | type-specifier declaration-specifiers[opt] | |
2078 | type-qualifier declaration-specifiers[opt] | |
2079 | function-specifier declaration-specifiers[opt] | |
d19fa6b5 | 2080 | alignment-specifier declaration-specifiers[opt] |
27bf414c JM |
2081 | |
2082 | Function specifiers (inline) are from C99, and are currently | |
d19fa6b5 | 2083 | handled as storage class specifiers, as is __thread. Alignment |
48b0b196 | 2084 | specifiers are from C11. |
27bf414c JM |
2085 | |
2086 | C90 6.5.1, C99 6.7.1: | |
2087 | storage-class-specifier: | |
2088 | typedef | |
2089 | extern | |
2090 | static | |
2091 | auto | |
2092 | register | |
582d9b50 JM |
2093 | _Thread_local |
2094 | ||
2095 | (_Thread_local is new in C11.) | |
27bf414c JM |
2096 | |
2097 | C99 6.7.4: | |
2098 | function-specifier: | |
2099 | inline | |
c4b3a0a0 JM |
2100 | _Noreturn |
2101 | ||
48b0b196 | 2102 | (_Noreturn is new in C11.) |
27bf414c JM |
2103 | |
2104 | C90 6.5.2, C99 6.7.2: | |
2105 | type-specifier: | |
2106 | void | |
2107 | char | |
2108 | short | |
2109 | int | |
2110 | long | |
2111 | float | |
2112 | double | |
2113 | signed | |
2114 | unsigned | |
2115 | _Bool | |
2116 | _Complex | |
2117 | [_Imaginary removed in C99 TC2] | |
2118 | struct-or-union-specifier | |
2119 | enum-specifier | |
2120 | typedef-name | |
267bac10 | 2121 | atomic-type-specifier |
27bf414c JM |
2122 | |
2123 | (_Bool and _Complex are new in C99.) | |
267bac10 | 2124 | (atomic-type-specifier is new in C11.) |
27bf414c JM |
2125 | |
2126 | C90 6.5.3, C99 6.7.3: | |
2127 | ||
2128 | type-qualifier: | |
2129 | const | |
2130 | restrict | |
2131 | volatile | |
36c5e70a | 2132 | address-space-qualifier |
267bac10 | 2133 | _Atomic |
27bf414c JM |
2134 | |
2135 | (restrict is new in C99.) | |
267bac10 | 2136 | (_Atomic is new in C11.) |
27bf414c JM |
2137 | |
2138 | GNU extensions: | |
2139 | ||
2140 | declaration-specifiers: | |
2141 | attributes declaration-specifiers[opt] | |
2142 | ||
36c5e70a BE |
2143 | type-qualifier: |
2144 | address-space | |
2145 | ||
2146 | address-space: | |
2147 | identifier recognized by the target | |
2148 | ||
27bf414c JM |
2149 | storage-class-specifier: |
2150 | __thread | |
2151 | ||
2152 | type-specifier: | |
2153 | typeof-specifier | |
38b7bc7f | 2154 | __auto_type |
a6766312 | 2155 | __int128 |
9a8ce21f JG |
2156 | _Decimal32 |
2157 | _Decimal64 | |
2158 | _Decimal128 | |
ab22c1fa CF |
2159 | _Fract |
2160 | _Accum | |
2161 | _Sat | |
2162 | ||
2163 | (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037: | |
2164 | http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf) | |
27bf414c | 2165 | |
267bac10 JM |
2166 | atomic-type-specifier |
2167 | _Atomic ( type-name ) | |
2168 | ||
27bf414c JM |
2169 | Objective-C: |
2170 | ||
2171 | type-specifier: | |
2172 | class-name objc-protocol-refs[opt] | |
2173 | typedef-name objc-protocol-refs | |
2174 | objc-protocol-refs | |
2175 | */ | |
2176 | ||
2177 | static void | |
2178 | c_parser_declspecs (c_parser *parser, struct c_declspecs *specs, | |
29ce73cb | 2179 | bool scspec_ok, bool typespec_ok, bool start_attr_ok, |
38b7bc7f JM |
2180 | bool alignspec_ok, bool auto_type_ok, |
2181 | enum c_lookahead_kind la) | |
27bf414c JM |
2182 | { |
2183 | bool attrs_ok = start_attr_ok; | |
9e5b2115 | 2184 | bool seen_type = specs->typespec_kind != ctsk_none; |
29ce73cb PB |
2185 | |
2186 | if (!typespec_ok) | |
2187 | gcc_assert (la == cla_prefer_id); | |
2188 | ||
2189 | while (c_parser_next_token_is (parser, CPP_NAME) | |
27bf414c JM |
2190 | || c_parser_next_token_is (parser, CPP_KEYWORD) |
2191 | || (c_dialect_objc () && c_parser_next_token_is (parser, CPP_LESS))) | |
2192 | { | |
2193 | struct c_typespec t; | |
2194 | tree attrs; | |
d19fa6b5 | 2195 | tree align; |
dc491a25 | 2196 | location_t loc = c_parser_peek_token (parser)->location; |
f725e721 | 2197 | |
29ce73cb PB |
2198 | /* If we cannot accept a type, exit if the next token must start |
2199 | one. Also, if we already have seen a tagged definition, | |
2200 | a typename would be an error anyway and likely the user | |
2201 | has simply forgotten a semicolon, so we exit. */ | |
2202 | if ((!typespec_ok || specs->typespec_kind == ctsk_tagdef) | |
2203 | && c_parser_next_tokens_start_typename (parser, la) | |
2204 | && !c_parser_next_token_is_qualifier (parser)) | |
2205 | break; | |
f725e721 | 2206 | |
27bf414c JM |
2207 | if (c_parser_next_token_is (parser, CPP_NAME)) |
2208 | { | |
0b2c4be5 DS |
2209 | c_token *name_token = c_parser_peek_token (parser); |
2210 | tree value = name_token->value; | |
2211 | c_id_kind kind = name_token->id_kind; | |
36c5e70a BE |
2212 | |
2213 | if (kind == C_ID_ADDRSPACE) | |
2214 | { | |
2215 | addr_space_t as | |
0b2c4be5 DS |
2216 | = name_token->keyword - RID_FIRST_ADDR_SPACE; |
2217 | declspecs_add_addrspace (name_token->location, specs, as); | |
36c5e70a BE |
2218 | c_parser_consume_token (parser); |
2219 | attrs_ok = true; | |
2220 | continue; | |
2221 | } | |
2222 | ||
29ce73cb PB |
2223 | gcc_assert (!c_parser_next_token_is_qualifier (parser)); |
2224 | ||
2225 | /* If we cannot accept a type, and the next token must start one, | |
2226 | exit. Do the same if we already have seen a tagged definition, | |
2227 | since it would be an error anyway and likely the user has simply | |
2228 | forgotten a semicolon. */ | |
2229 | if (seen_type || !c_parser_next_tokens_start_typename (parser, la)) | |
2230 | break; | |
2231 | ||
2232 | /* Now at an unknown typename (C_ID_ID), a C_ID_TYPENAME or | |
2233 | a C_ID_CLASSNAME. */ | |
27bf414c JM |
2234 | c_parser_consume_token (parser); |
2235 | seen_type = true; | |
2236 | attrs_ok = true; | |
29ce73cb PB |
2237 | if (kind == C_ID_ID) |
2238 | { | |
1c9f5f33 | 2239 | error_at (loc, "unknown type name %qE", value); |
29ce73cb PB |
2240 | t.kind = ctsk_typedef; |
2241 | t.spec = error_mark_node; | |
2242 | } | |
2243 | else if (kind == C_ID_TYPENAME | |
2244 | && (!c_dialect_objc () | |
2245 | || c_parser_next_token_is_not (parser, CPP_LESS))) | |
27bf414c JM |
2246 | { |
2247 | t.kind = ctsk_typedef; | |
2248 | /* For a typedef name, record the meaning, not the name. | |
2249 | In case of 'foo foo, bar;'. */ | |
2250 | t.spec = lookup_name (value); | |
2251 | } | |
2252 | else | |
2253 | { | |
2254 | tree proto = NULL_TREE; | |
2255 | gcc_assert (c_dialect_objc ()); | |
2256 | t.kind = ctsk_objc; | |
2257 | if (c_parser_next_token_is (parser, CPP_LESS)) | |
2258 | proto = c_parser_objc_protocol_refs (parser); | |
2259 | t.spec = objc_get_protocol_qualified_type (value, proto); | |
2260 | } | |
29ce73cb PB |
2261 | t.expr = NULL_TREE; |
2262 | t.expr_const_operands = true; | |
0b2c4be5 | 2263 | declspecs_add_type (name_token->location, specs, t); |
27bf414c JM |
2264 | continue; |
2265 | } | |
2266 | if (c_parser_next_token_is (parser, CPP_LESS)) | |
2267 | { | |
2268 | /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" - | |
2269 | nisse@lysator.liu.se. */ | |
2270 | tree proto; | |
2271 | gcc_assert (c_dialect_objc ()); | |
2272 | if (!typespec_ok || seen_type) | |
2273 | break; | |
2274 | proto = c_parser_objc_protocol_refs (parser); | |
2275 | t.kind = ctsk_objc; | |
2276 | t.spec = objc_get_protocol_qualified_type (NULL_TREE, proto); | |
928c19bb JM |
2277 | t.expr = NULL_TREE; |
2278 | t.expr_const_operands = true; | |
dc491a25 | 2279 | declspecs_add_type (loc, specs, t); |
27bf414c JM |
2280 | continue; |
2281 | } | |
2282 | gcc_assert (c_parser_next_token_is (parser, CPP_KEYWORD)); | |
2283 | switch (c_parser_peek_token (parser)->keyword) | |
2284 | { | |
2285 | case RID_STATIC: | |
2286 | case RID_EXTERN: | |
2287 | case RID_REGISTER: | |
2288 | case RID_TYPEDEF: | |
2289 | case RID_INLINE: | |
bbceee64 | 2290 | case RID_NORETURN: |
27bf414c JM |
2291 | case RID_AUTO: |
2292 | case RID_THREAD: | |
2293 | if (!scspec_ok) | |
2294 | goto out; | |
2295 | attrs_ok = true; | |
bbceee64 | 2296 | /* TODO: Distinguish between function specifiers (inline, noreturn) |
27bf414c JM |
2297 | and storage class specifiers, either here or in |
2298 | declspecs_add_scspec. */ | |
0b2c4be5 DS |
2299 | declspecs_add_scspec (loc, specs, |
2300 | c_parser_peek_token (parser)->value); | |
27bf414c JM |
2301 | c_parser_consume_token (parser); |
2302 | break; | |
38b7bc7f JM |
2303 | case RID_AUTO_TYPE: |
2304 | if (!auto_type_ok) | |
2305 | goto out; | |
2306 | /* Fall through. */ | |
27bf414c JM |
2307 | case RID_UNSIGNED: |
2308 | case RID_LONG: | |
a6766312 | 2309 | case RID_INT128: |
27bf414c JM |
2310 | case RID_SHORT: |
2311 | case RID_SIGNED: | |
2312 | case RID_COMPLEX: | |
2313 | case RID_INT: | |
2314 | case RID_CHAR: | |
2315 | case RID_FLOAT: | |
2316 | case RID_DOUBLE: | |
2317 | case RID_VOID: | |
9a8ce21f JG |
2318 | case RID_DFLOAT32: |
2319 | case RID_DFLOAT64: | |
2320 | case RID_DFLOAT128: | |
27bf414c | 2321 | case RID_BOOL: |
ab22c1fa CF |
2322 | case RID_FRACT: |
2323 | case RID_ACCUM: | |
2324 | case RID_SAT: | |
27bf414c JM |
2325 | if (!typespec_ok) |
2326 | goto out; | |
2327 | attrs_ok = true; | |
2328 | seen_type = true; | |
0bacb8c7 TT |
2329 | if (c_dialect_objc ()) |
2330 | parser->objc_need_raw_identifier = true; | |
27bf414c JM |
2331 | t.kind = ctsk_resword; |
2332 | t.spec = c_parser_peek_token (parser)->value; | |
928c19bb JM |
2333 | t.expr = NULL_TREE; |
2334 | t.expr_const_operands = true; | |
dc491a25 | 2335 | declspecs_add_type (loc, specs, t); |
27bf414c JM |
2336 | c_parser_consume_token (parser); |
2337 | break; | |
2338 | case RID_ENUM: | |
2339 | if (!typespec_ok) | |
2340 | goto out; | |
2341 | attrs_ok = true; | |
2342 | seen_type = true; | |
2343 | t = c_parser_enum_specifier (parser); | |
dc491a25 | 2344 | declspecs_add_type (loc, specs, t); |
27bf414c JM |
2345 | break; |
2346 | case RID_STRUCT: | |
2347 | case RID_UNION: | |
2348 | if (!typespec_ok) | |
2349 | goto out; | |
2350 | attrs_ok = true; | |
2351 | seen_type = true; | |
2352 | t = c_parser_struct_or_union_specifier (parser); | |
dab71827 | 2353 | invoke_plugin_callbacks (PLUGIN_FINISH_TYPE, t.spec); |
dc491a25 | 2354 | declspecs_add_type (loc, specs, t); |
27bf414c JM |
2355 | break; |
2356 | case RID_TYPEOF: | |
2357 | /* ??? The old parser rejected typeof after other type | |
2358 | specifiers, but is a syntax error the best way of | |
2359 | handling this? */ | |
2360 | if (!typespec_ok || seen_type) | |
2361 | goto out; | |
2362 | attrs_ok = true; | |
2363 | seen_type = true; | |
2364 | t = c_parser_typeof_specifier (parser); | |
dc491a25 | 2365 | declspecs_add_type (loc, specs, t); |
27bf414c | 2366 | break; |
267bac10 JM |
2367 | case RID_ATOMIC: |
2368 | /* C parser handling of Objective-C constructs needs | |
2369 | checking for correct lvalue-to-rvalue conversions, and | |
2370 | the code in build_modify_expr handling various | |
2371 | Objective-C cases, and that in build_unary_op handling | |
2372 | Objective-C cases for increment / decrement, also needs | |
2373 | updating; uses of TYPE_MAIN_VARIANT in objc_compare_types | |
2374 | and objc_types_are_equivalent may also need updates. */ | |
2375 | if (c_dialect_objc ()) | |
2376 | sorry ("%<_Atomic%> in Objective-C"); | |
2377 | /* C parser handling of OpenMP constructs needs checking for | |
2378 | correct lvalue-to-rvalue conversions. */ | |
2379 | if (flag_openmp) | |
2380 | sorry ("%<_Atomic%> with OpenMP"); | |
2381 | if (!flag_isoc11) | |
2382 | { | |
2383 | if (flag_isoc99) | |
2384 | pedwarn (loc, OPT_Wpedantic, | |
2385 | "ISO C99 does not support the %<_Atomic%> qualifier"); | |
2386 | else | |
2387 | pedwarn (loc, OPT_Wpedantic, | |
2388 | "ISO C90 does not support the %<_Atomic%> qualifier"); | |
2389 | } | |
2390 | attrs_ok = true; | |
2391 | tree value; | |
2392 | value = c_parser_peek_token (parser)->value; | |
2393 | c_parser_consume_token (parser); | |
2394 | if (typespec_ok && c_parser_next_token_is (parser, CPP_OPEN_PAREN)) | |
2395 | { | |
2396 | /* _Atomic ( type-name ). */ | |
2397 | seen_type = true; | |
2398 | c_parser_consume_token (parser); | |
2399 | struct c_type_name *type = c_parser_type_name (parser); | |
2400 | t.kind = ctsk_typeof; | |
2401 | t.spec = error_mark_node; | |
2402 | t.expr = NULL_TREE; | |
2403 | t.expr_const_operands = true; | |
2404 | if (type != NULL) | |
2405 | t.spec = groktypename (type, &t.expr, | |
2406 | &t.expr_const_operands); | |
2407 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, | |
2408 | "expected %<)%>"); | |
2409 | if (t.spec != error_mark_node) | |
2410 | { | |
2411 | if (TREE_CODE (t.spec) == ARRAY_TYPE) | |
2412 | error_at (loc, "%<_Atomic%>-qualified array type"); | |
2413 | else if (TREE_CODE (t.spec) == FUNCTION_TYPE) | |
2414 | error_at (loc, "%<_Atomic%>-qualified function type"); | |
2415 | else if (TYPE_QUALS (t.spec) != TYPE_UNQUALIFIED) | |
2416 | error_at (loc, "%<_Atomic%> applied to a qualified type"); | |
2417 | else | |
2418 | t.spec = c_build_qualified_type (t.spec, TYPE_QUAL_ATOMIC); | |
2419 | } | |
2420 | declspecs_add_type (loc, specs, t); | |
2421 | } | |
2422 | else | |
2423 | declspecs_add_qual (loc, specs, value); | |
2424 | break; | |
27bf414c JM |
2425 | case RID_CONST: |
2426 | case RID_VOLATILE: | |
2427 | case RID_RESTRICT: | |
2428 | attrs_ok = true; | |
0b2c4be5 | 2429 | declspecs_add_qual (loc, specs, c_parser_peek_token (parser)->value); |
27bf414c JM |
2430 | c_parser_consume_token (parser); |
2431 | break; | |
2432 | case RID_ATTRIBUTE: | |
2433 | if (!attrs_ok) | |
2434 | goto out; | |
2435 | attrs = c_parser_attributes (parser); | |
0b2c4be5 | 2436 | declspecs_add_attrs (loc, specs, attrs); |
27bf414c | 2437 | break; |
d19fa6b5 | 2438 | case RID_ALIGNAS: |
568a31f2 MP |
2439 | if (!alignspec_ok) |
2440 | goto out; | |
d19fa6b5 | 2441 | align = c_parser_alignas_specifier (parser); |
0b2c4be5 | 2442 | declspecs_add_alignas (loc, specs, align); |
d19fa6b5 | 2443 | break; |
27bf414c JM |
2444 | default: |
2445 | goto out; | |
2446 | } | |
2447 | } | |
2448 | out: ; | |
2449 | } | |
2450 | ||
2451 | /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2). | |
2452 | ||
2453 | enum-specifier: | |
2454 | enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt] | |
2455 | enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt] | |
2456 | enum attributes[opt] identifier | |
2457 | ||
2458 | The form with trailing comma is new in C99. The forms with | |
2459 | attributes are GNU extensions. In GNU C, we accept any expression | |
2460 | without commas in the syntax (assignment expressions, not just | |
2461 | conditional expressions); assignment expressions will be diagnosed | |
2462 | as non-constant. | |
2463 | ||
2464 | enumerator-list: | |
2465 | enumerator | |
2466 | enumerator-list , enumerator | |
2467 | ||
2468 | enumerator: | |
2469 | enumeration-constant | |
2470 | enumeration-constant = constant-expression | |
2471 | */ | |
2472 | ||
2473 | static struct c_typespec | |
2474 | c_parser_enum_specifier (c_parser *parser) | |
2475 | { | |
2476 | struct c_typespec ret; | |
2477 | tree attrs; | |
2478 | tree ident = NULL_TREE; | |
24b97832 | 2479 | location_t enum_loc; |
922f2908 | 2480 | location_t ident_loc = UNKNOWN_LOCATION; /* Quiet warning. */ |
27bf414c | 2481 | gcc_assert (c_parser_next_token_is_keyword (parser, RID_ENUM)); |
24b97832 | 2482 | enum_loc = c_parser_peek_token (parser)->location; |
27bf414c JM |
2483 | c_parser_consume_token (parser); |
2484 | attrs = c_parser_attributes (parser); | |
c2255bc4 | 2485 | enum_loc = c_parser_peek_token (parser)->location; |
5af28c74 TT |
2486 | /* Set the location in case we create a decl now. */ |
2487 | c_parser_set_source_position_from_token (c_parser_peek_token (parser)); | |
27bf414c JM |
2488 | if (c_parser_next_token_is (parser, CPP_NAME)) |
2489 | { | |
2490 | ident = c_parser_peek_token (parser)->value; | |
c7412148 | 2491 | ident_loc = c_parser_peek_token (parser)->location; |
24b97832 | 2492 | enum_loc = ident_loc; |
27bf414c JM |
2493 | c_parser_consume_token (parser); |
2494 | } | |
2495 | if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) | |
2496 | { | |
2497 | /* Parse an enum definition. */ | |
7114359f | 2498 | struct c_enum_contents the_enum; |
575bfb00 | 2499 | tree type; |
27bf414c JM |
2500 | tree postfix_attrs; |
2501 | /* We chain the enumerators in reverse order, then put them in | |
2502 | forward order at the end. */ | |
575bfb00 LC |
2503 | tree values; |
2504 | timevar_push (TV_PARSE_ENUM); | |
2505 | type = start_enum (enum_loc, &the_enum, ident); | |
2506 | values = NULL_TREE; | |
27bf414c JM |
2507 | c_parser_consume_token (parser); |
2508 | while (true) | |
2509 | { | |
2510 | tree enum_id; | |
2511 | tree enum_value; | |
2512 | tree enum_decl; | |
2513 | bool seen_comma; | |
5af28c74 | 2514 | c_token *token; |
922f2908 | 2515 | location_t comma_loc = UNKNOWN_LOCATION; /* Quiet warning. */ |
7370e0da | 2516 | location_t decl_loc, value_loc; |
27bf414c JM |
2517 | if (c_parser_next_token_is_not (parser, CPP_NAME)) |
2518 | { | |
2519 | c_parser_error (parser, "expected identifier"); | |
2520 | c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL); | |
2521 | values = error_mark_node; | |
2522 | break; | |
2523 | } | |
5af28c74 TT |
2524 | token = c_parser_peek_token (parser); |
2525 | enum_id = token->value; | |
2526 | /* Set the location in case we create a decl now. */ | |
2527 | c_parser_set_source_position_from_token (token); | |
7370e0da | 2528 | decl_loc = value_loc = token->location; |
27bf414c JM |
2529 | c_parser_consume_token (parser); |
2530 | if (c_parser_next_token_is (parser, CPP_EQ)) | |
2531 | { | |
2532 | c_parser_consume_token (parser); | |
85790e66 | 2533 | value_loc = c_parser_peek_token (parser)->location; |
27bf414c JM |
2534 | enum_value = c_parser_expr_no_commas (parser, NULL).value; |
2535 | } | |
2536 | else | |
2537 | enum_value = NULL_TREE; | |
7370e0da | 2538 | enum_decl = build_enumerator (decl_loc, value_loc, |
c2255bc4 | 2539 | &the_enum, enum_id, enum_value); |
27bf414c JM |
2540 | TREE_CHAIN (enum_decl) = values; |
2541 | values = enum_decl; | |
2542 | seen_comma = false; | |
2543 | if (c_parser_next_token_is (parser, CPP_COMMA)) | |
2544 | { | |
c7412148 | 2545 | comma_loc = c_parser_peek_token (parser)->location; |
27bf414c JM |
2546 | seen_comma = true; |
2547 | c_parser_consume_token (parser); | |
2548 | } | |
2549 | if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) | |
2550 | { | |
f3bede71 MP |
2551 | if (seen_comma) |
2552 | pedwarn_c90 (comma_loc, OPT_Wpedantic, | |
2553 | "comma at end of enumerator list"); | |
27bf414c JM |
2554 | c_parser_consume_token (parser); |
2555 | break; | |
2556 | } | |
2557 | if (!seen_comma) | |
2558 | { | |
2559 | c_parser_error (parser, "expected %<,%> or %<}%>"); | |
2560 | c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL); | |
2561 | values = error_mark_node; | |
2562 | break; | |
2563 | } | |
2564 | } | |
2565 | postfix_attrs = c_parser_attributes (parser); | |
2566 | ret.spec = finish_enum (type, nreverse (values), | |
2567 | chainon (attrs, postfix_attrs)); | |
2568 | ret.kind = ctsk_tagdef; | |
928c19bb JM |
2569 | ret.expr = NULL_TREE; |
2570 | ret.expr_const_operands = true; | |
575bfb00 | 2571 | timevar_pop (TV_PARSE_ENUM); |
27bf414c JM |
2572 | return ret; |
2573 | } | |
2574 | else if (!ident) | |
2575 | { | |
2576 | c_parser_error (parser, "expected %<{%>"); | |
2577 | ret.spec = error_mark_node; | |
2578 | ret.kind = ctsk_tagref; | |
928c19bb JM |
2579 | ret.expr = NULL_TREE; |
2580 | ret.expr_const_operands = true; | |
27bf414c JM |
2581 | return ret; |
2582 | } | |
c2255bc4 | 2583 | ret = parser_xref_tag (ident_loc, ENUMERAL_TYPE, ident); |
27bf414c JM |
2584 | /* In ISO C, enumerated types can be referred to only if already |
2585 | defined. */ | |
2586 | if (pedantic && !COMPLETE_TYPE_P (ret.spec)) | |
c7412148 TT |
2587 | { |
2588 | gcc_assert (ident); | |
c1771a20 | 2589 | pedwarn (enum_loc, OPT_Wpedantic, |
509c9d60 | 2590 | "ISO C forbids forward references to %<enum%> types"); |
c7412148 | 2591 | } |
27bf414c JM |
2592 | return ret; |
2593 | } | |
2594 | ||
2595 | /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1). | |
2596 | ||
2597 | struct-or-union-specifier: | |
2598 | struct-or-union attributes[opt] identifier[opt] | |
2599 | { struct-contents } attributes[opt] | |
2600 | struct-or-union attributes[opt] identifier | |
2601 | ||
2602 | struct-contents: | |
2603 | struct-declaration-list | |
2604 | ||
2605 | struct-declaration-list: | |
2606 | struct-declaration ; | |
2607 | struct-declaration-list struct-declaration ; | |
2608 | ||
2609 | GNU extensions: | |
2610 | ||
2611 | struct-contents: | |
2612 | empty | |
2613 | struct-declaration | |
2614 | struct-declaration-list struct-declaration | |
2615 | ||
2616 | struct-declaration-list: | |
2617 | struct-declaration-list ; | |
2618 | ; | |
2619 | ||
2620 | (Note that in the syntax here, unlike that in ISO C, the semicolons | |
2621 | are included here rather than in struct-declaration, in order to | |
2622 | describe the syntax with extra semicolons and missing semicolon at | |
2623 | end.) | |
2624 | ||
2625 | Objective-C: | |
2626 | ||
2627 | struct-declaration-list: | |
2628 | @defs ( class-name ) | |
2629 | ||
2630 | (Note this does not include a trailing semicolon, but can be | |
2631 | followed by further declarations, and gets a pedwarn-if-pedantic | |
2632 | when followed by a semicolon.) */ | |
2633 | ||
2634 | static struct c_typespec | |
2635 | c_parser_struct_or_union_specifier (c_parser *parser) | |
2636 | { | |
2637 | struct c_typespec ret; | |
2638 | tree attrs; | |
2639 | tree ident = NULL_TREE; | |
24b97832 ILT |
2640 | location_t struct_loc; |
2641 | location_t ident_loc = UNKNOWN_LOCATION; | |
27bf414c JM |
2642 | enum tree_code code; |
2643 | switch (c_parser_peek_token (parser)->keyword) | |
2644 | { | |
2645 | case RID_STRUCT: | |
2646 | code = RECORD_TYPE; | |
2647 | break; | |
2648 | case RID_UNION: | |
2649 | code = UNION_TYPE; | |
2650 | break; | |
2651 | default: | |
2652 | gcc_unreachable (); | |
2653 | } | |
24b97832 | 2654 | struct_loc = c_parser_peek_token (parser)->location; |
27bf414c JM |
2655 | c_parser_consume_token (parser); |
2656 | attrs = c_parser_attributes (parser); | |
c2255bc4 | 2657 | |
5af28c74 TT |
2658 | /* Set the location in case we create a decl now. */ |
2659 | c_parser_set_source_position_from_token (c_parser_peek_token (parser)); | |
c2255bc4 | 2660 | |
27bf414c JM |
2661 | if (c_parser_next_token_is (parser, CPP_NAME)) |
2662 | { | |
2663 | ident = c_parser_peek_token (parser)->value; | |
24b97832 ILT |
2664 | ident_loc = c_parser_peek_token (parser)->location; |
2665 | struct_loc = ident_loc; | |
27bf414c JM |
2666 | c_parser_consume_token (parser); |
2667 | } | |
2668 | if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) | |
2669 | { | |
2670 | /* Parse a struct or union definition. Start the scope of the | |
2671 | tag before parsing components. */ | |
dc491a25 ILT |
2672 | struct c_struct_parse_info *struct_info; |
2673 | tree type = start_struct (struct_loc, code, ident, &struct_info); | |
27bf414c JM |
2674 | tree postfix_attrs; |
2675 | /* We chain the components in reverse order, then put them in | |
2676 | forward order at the end. Each struct-declaration may | |
2677 | declare multiple components (comma-separated), so we must use | |
2678 | chainon to join them, although when parsing each | |
2679 | struct-declaration we can use TREE_CHAIN directly. | |
2680 | ||
2681 | The theory behind all this is that there will be more | |
2682 | semicolon separated fields than comma separated fields, and | |
2683 | so we'll be minimizing the number of node traversals required | |
2684 | by chainon. */ | |
575bfb00 LC |
2685 | tree contents; |
2686 | timevar_push (TV_PARSE_STRUCT); | |
2687 | contents = NULL_TREE; | |
27bf414c JM |
2688 | c_parser_consume_token (parser); |
2689 | /* Handle the Objective-C @defs construct, | |
2690 | e.g. foo(sizeof(struct{ @defs(ClassName) }));. */ | |
2691 | if (c_parser_next_token_is_keyword (parser, RID_AT_DEFS)) | |
2692 | { | |
2693 | tree name; | |
2694 | gcc_assert (c_dialect_objc ()); | |
2695 | c_parser_consume_token (parser); | |
2696 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
2697 | goto end_at_defs; | |
2698 | if (c_parser_next_token_is (parser, CPP_NAME) | |
2699 | && c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME) | |
2700 | { | |
2701 | name = c_parser_peek_token (parser)->value; | |
2702 | c_parser_consume_token (parser); | |
2703 | } | |
2704 | else | |
2705 | { | |
2706 | c_parser_error (parser, "expected class name"); | |
2707 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); | |
2708 | goto end_at_defs; | |
2709 | } | |
2710 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, | |
2711 | "expected %<)%>"); | |
2712 | contents = nreverse (objc_get_class_ivars (name)); | |
2713 | } | |
2714 | end_at_defs: | |
2715 | /* Parse the struct-declarations and semicolons. Problems with | |
2716 | semicolons are diagnosed here; empty structures are diagnosed | |
2717 | elsewhere. */ | |
2718 | while (true) | |
2719 | { | |
2720 | tree decls; | |
2721 | /* Parse any stray semicolon. */ | |
2722 | if (c_parser_next_token_is (parser, CPP_SEMICOLON)) | |
2723 | { | |
c1771a20 | 2724 | pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic, |
509c9d60 | 2725 | "extra semicolon in struct or union specified"); |
27bf414c JM |
2726 | c_parser_consume_token (parser); |
2727 | continue; | |
2728 | } | |
2729 | /* Stop if at the end of the struct or union contents. */ | |
2730 | if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) | |
2731 | { | |
2732 | c_parser_consume_token (parser); | |
2733 | break; | |
2734 | } | |
bc4071dd RH |
2735 | /* Accept #pragmas at struct scope. */ |
2736 | if (c_parser_next_token_is (parser, CPP_PRAGMA)) | |
2737 | { | |
acf0174b | 2738 | c_parser_pragma (parser, pragma_struct); |
bc4071dd RH |
2739 | continue; |
2740 | } | |
27bf414c JM |
2741 | /* Parse some comma-separated declarations, but not the |
2742 | trailing semicolon if any. */ | |
2743 | decls = c_parser_struct_declaration (parser); | |
2744 | contents = chainon (decls, contents); | |
2745 | /* If no semicolon follows, either we have a parse error or | |
2746 | are at the end of the struct or union and should | |
2747 | pedwarn. */ | |
2748 | if (c_parser_next_token_is (parser, CPP_SEMICOLON)) | |
2749 | c_parser_consume_token (parser); | |
2750 | else | |
2751 | { | |
2752 | if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) | |
b8698a0f | 2753 | pedwarn (c_parser_peek_token (parser)->location, 0, |
509c9d60 | 2754 | "no semicolon at end of struct or union"); |
f725e721 PB |
2755 | else if (parser->error |
2756 | || !c_parser_next_token_starts_declspecs (parser)) | |
27bf414c JM |
2757 | { |
2758 | c_parser_error (parser, "expected %<;%>"); | |
2759 | c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL); | |
2760 | break; | |
2761 | } | |
f725e721 PB |
2762 | |
2763 | /* If we come here, we have already emitted an error | |
2764 | for an expected `;', identifier or `(', and we also | |
2765 | recovered already. Go on with the next field. */ | |
27bf414c JM |
2766 | } |
2767 | } | |
2768 | postfix_attrs = c_parser_attributes (parser); | |
c2255bc4 | 2769 | ret.spec = finish_struct (struct_loc, type, nreverse (contents), |
dc491a25 | 2770 | chainon (attrs, postfix_attrs), struct_info); |
27bf414c | 2771 | ret.kind = ctsk_tagdef; |
928c19bb JM |
2772 | ret.expr = NULL_TREE; |
2773 | ret.expr_const_operands = true; | |
575bfb00 | 2774 | timevar_pop (TV_PARSE_STRUCT); |
27bf414c JM |
2775 | return ret; |
2776 | } | |
2777 | else if (!ident) | |
2778 | { | |
2779 | c_parser_error (parser, "expected %<{%>"); | |
2780 | ret.spec = error_mark_node; | |
2781 | ret.kind = ctsk_tagref; | |
928c19bb JM |
2782 | ret.expr = NULL_TREE; |
2783 | ret.expr_const_operands = true; | |
67c2939d | 2784 | return ret; |
27bf414c | 2785 | } |
c2255bc4 | 2786 | ret = parser_xref_tag (ident_loc, code, ident); |
27bf414c JM |
2787 | return ret; |
2788 | } | |
2789 | ||
2790 | /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without* | |
2791 | the trailing semicolon. | |
2792 | ||
2793 | struct-declaration: | |
2794 | specifier-qualifier-list struct-declarator-list | |
32912286 | 2795 | static_assert-declaration-no-semi |
27bf414c JM |
2796 | |
2797 | specifier-qualifier-list: | |
2798 | type-specifier specifier-qualifier-list[opt] | |
2799 | type-qualifier specifier-qualifier-list[opt] | |
2800 | attributes specifier-qualifier-list[opt] | |
2801 | ||
2802 | struct-declarator-list: | |
2803 | struct-declarator | |
2804 | struct-declarator-list , attributes[opt] struct-declarator | |
2805 | ||
2806 | struct-declarator: | |
2807 | declarator attributes[opt] | |
2808 | declarator[opt] : constant-expression attributes[opt] | |
2809 | ||
2810 | GNU extensions: | |
2811 | ||
2812 | struct-declaration: | |
2813 | __extension__ struct-declaration | |
2814 | specifier-qualifier-list | |
2815 | ||
2816 | Unlike the ISO C syntax, semicolons are handled elsewhere. The use | |
2817 | of attributes where shown is a GNU extension. In GNU C, we accept | |
2818 | any expression without commas in the syntax (assignment | |
2819 | expressions, not just conditional expressions); assignment | |
2820 | expressions will be diagnosed as non-constant. */ | |
2821 | ||
2822 | static tree | |
2823 | c_parser_struct_declaration (c_parser *parser) | |
2824 | { | |
2825 | struct c_declspecs *specs; | |
2826 | tree prefix_attrs; | |
2827 | tree all_prefix_attrs; | |
2828 | tree decls; | |
c7412148 | 2829 | location_t decl_loc; |
27bf414c JM |
2830 | if (c_parser_next_token_is_keyword (parser, RID_EXTENSION)) |
2831 | { | |
2832 | int ext; | |
2833 | tree decl; | |
2834 | ext = disable_extension_diagnostics (); | |
2835 | c_parser_consume_token (parser); | |
2836 | decl = c_parser_struct_declaration (parser); | |
2837 | restore_extension_diagnostics (ext); | |
2838 | return decl; | |
2839 | } | |
32912286 JM |
2840 | if (c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT)) |
2841 | { | |
2842 | c_parser_static_assert_declaration_no_semi (parser); | |
2843 | return NULL_TREE; | |
2844 | } | |
27bf414c | 2845 | specs = build_null_declspecs (); |
c7412148 | 2846 | decl_loc = c_parser_peek_token (parser)->location; |
f28aa681 MP |
2847 | /* Strictly by the standard, we shouldn't allow _Alignas here, |
2848 | but it appears to have been intended to allow it there, so | |
2849 | we're keeping it as it is until WG14 reaches a conclusion | |
2850 | of N1731. | |
2851 | <http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1731.pdf> */ | |
568a31f2 | 2852 | c_parser_declspecs (parser, specs, false, true, true, |
38b7bc7f | 2853 | true, false, cla_nonabstract_decl); |
27bf414c | 2854 | if (parser->error) |
67c2939d | 2855 | return NULL_TREE; |
27bf414c JM |
2856 | if (!specs->declspecs_seen_p) |
2857 | { | |
2858 | c_parser_error (parser, "expected specifier-qualifier-list"); | |
2859 | return NULL_TREE; | |
2860 | } | |
2861 | finish_declspecs (specs); | |
b8cbdff5 JM |
2862 | if (c_parser_next_token_is (parser, CPP_SEMICOLON) |
2863 | || c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) | |
27bf414c JM |
2864 | { |
2865 | tree ret; | |
9e5b2115 | 2866 | if (specs->typespec_kind == ctsk_none) |
27bf414c | 2867 | { |
c1771a20 | 2868 | pedwarn (decl_loc, OPT_Wpedantic, |
509c9d60 | 2869 | "ISO C forbids member declarations with no members"); |
27bf414c JM |
2870 | shadow_tag_warned (specs, pedantic); |
2871 | ret = NULL_TREE; | |
2872 | } | |
2873 | else | |
2874 | { | |
2875 | /* Support for unnamed structs or unions as members of | |
2876 | structs or unions (which is [a] useful and [b] supports | |
2877 | MS P-SDK). */ | |
b9baeecd | 2878 | tree attrs = NULL; |
3d10ed6c AH |
2879 | |
2880 | ret = grokfield (c_parser_peek_token (parser)->location, | |
2881 | build_id_declarator (NULL_TREE), specs, | |
b9baeecd | 2882 | NULL_TREE, &attrs); |
0ad7e054 RS |
2883 | if (ret) |
2884 | decl_attributes (&ret, attrs, 0); | |
27bf414c JM |
2885 | } |
2886 | return ret; | |
2887 | } | |
f725e721 PB |
2888 | |
2889 | /* Provide better error recovery. Note that a type name here is valid, | |
2890 | and will be treated as a field name. */ | |
2891 | if (specs->typespec_kind == ctsk_tagdef | |
2892 | && TREE_CODE (specs->type) != ENUMERAL_TYPE | |
2893 | && c_parser_next_token_starts_declspecs (parser) | |
2894 | && !c_parser_next_token_is (parser, CPP_NAME)) | |
2895 | { | |
2896 | c_parser_error (parser, "expected %<;%>, identifier or %<(%>"); | |
2897 | parser->error = false; | |
2898 | return NULL_TREE; | |
2899 | } | |
2900 | ||
27bf414c JM |
2901 | pending_xref_error (); |
2902 | prefix_attrs = specs->attrs; | |
2903 | all_prefix_attrs = prefix_attrs; | |
2904 | specs->attrs = NULL_TREE; | |
2905 | decls = NULL_TREE; | |
2906 | while (true) | |
2907 | { | |
2908 | /* Declaring one or more declarators or un-named bit-fields. */ | |
2909 | struct c_declarator *declarator; | |
2910 | bool dummy = false; | |
2911 | if (c_parser_next_token_is (parser, CPP_COLON)) | |
2912 | declarator = build_id_declarator (NULL_TREE); | |
2913 | else | |
9e5b2115 PB |
2914 | declarator = c_parser_declarator (parser, |
2915 | specs->typespec_kind != ctsk_none, | |
27bf414c JM |
2916 | C_DTR_NORMAL, &dummy); |
2917 | if (declarator == NULL) | |
2918 | { | |
2919 | c_parser_skip_to_end_of_block_or_statement (parser); | |
2920 | break; | |
2921 | } | |
2922 | if (c_parser_next_token_is (parser, CPP_COLON) | |
2923 | || c_parser_next_token_is (parser, CPP_COMMA) | |
2924 | || c_parser_next_token_is (parser, CPP_SEMICOLON) | |
2925 | || c_parser_next_token_is (parser, CPP_CLOSE_BRACE) | |
2926 | || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)) | |
2927 | { | |
2928 | tree postfix_attrs = NULL_TREE; | |
2929 | tree width = NULL_TREE; | |
2930 | tree d; | |
2931 | if (c_parser_next_token_is (parser, CPP_COLON)) | |
2932 | { | |
2933 | c_parser_consume_token (parser); | |
2934 | width = c_parser_expr_no_commas (parser, NULL).value; | |
2935 | } | |
2936 | if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)) | |
2937 | postfix_attrs = c_parser_attributes (parser); | |
3d10ed6c AH |
2938 | d = grokfield (c_parser_peek_token (parser)->location, |
2939 | declarator, specs, width, &all_prefix_attrs); | |
27bf414c JM |
2940 | decl_attributes (&d, chainon (postfix_attrs, |
2941 | all_prefix_attrs), 0); | |
910ad8de | 2942 | DECL_CHAIN (d) = decls; |
27bf414c JM |
2943 | decls = d; |
2944 | if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)) | |
2945 | all_prefix_attrs = chainon (c_parser_attributes (parser), | |
2946 | prefix_attrs); | |
2947 | else | |
2948 | all_prefix_attrs = prefix_attrs; | |
2949 | if (c_parser_next_token_is (parser, CPP_COMMA)) | |
2950 | c_parser_consume_token (parser); | |
2951 | else if (c_parser_next_token_is (parser, CPP_SEMICOLON) | |
2952 | || c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) | |
2953 | { | |
2954 | /* Semicolon consumed in caller. */ | |
2955 | break; | |
2956 | } | |
2957 | else | |
2958 | { | |
2959 | c_parser_error (parser, "expected %<,%>, %<;%> or %<}%>"); | |
2960 | break; | |
2961 | } | |
2962 | } | |
2963 | else | |
2964 | { | |
2965 | c_parser_error (parser, | |
2966 | "expected %<:%>, %<,%>, %<;%>, %<}%> or " | |
2967 | "%<__attribute__%>"); | |
2968 | break; | |
2969 | } | |
2970 | } | |
2971 | return decls; | |
2972 | } | |
2973 | ||
2974 | /* Parse a typeof specifier (a GNU extension). | |
2975 | ||
2976 | typeof-specifier: | |
2977 | typeof ( expression ) | |
2978 | typeof ( type-name ) | |
2979 | */ | |
2980 | ||
2981 | static struct c_typespec | |
2982 | c_parser_typeof_specifier (c_parser *parser) | |
2983 | { | |
2984 | struct c_typespec ret; | |
2985 | ret.kind = ctsk_typeof; | |
2986 | ret.spec = error_mark_node; | |
928c19bb JM |
2987 | ret.expr = NULL_TREE; |
2988 | ret.expr_const_operands = true; | |
27bf414c JM |
2989 | gcc_assert (c_parser_next_token_is_keyword (parser, RID_TYPEOF)); |
2990 | c_parser_consume_token (parser); | |
7d882b83 | 2991 | c_inhibit_evaluation_warnings++; |
27bf414c JM |
2992 | in_typeof++; |
2993 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
2994 | { | |
7d882b83 | 2995 | c_inhibit_evaluation_warnings--; |
27bf414c JM |
2996 | in_typeof--; |
2997 | return ret; | |
2998 | } | |
29ce73cb | 2999 | if (c_parser_next_tokens_start_typename (parser, cla_prefer_id)) |
27bf414c JM |
3000 | { |
3001 | struct c_type_name *type = c_parser_type_name (parser); | |
7d882b83 | 3002 | c_inhibit_evaluation_warnings--; |
27bf414c JM |
3003 | in_typeof--; |
3004 | if (type != NULL) | |
3005 | { | |
928c19bb | 3006 | ret.spec = groktypename (type, &ret.expr, &ret.expr_const_operands); |
27bf414c JM |
3007 | pop_maybe_used (variably_modified_type_p (ret.spec, NULL_TREE)); |
3008 | } | |
3009 | } | |
3010 | else | |
3011 | { | |
52ffd86e | 3012 | bool was_vm; |
c7412148 | 3013 | location_t here = c_parser_peek_token (parser)->location; |
27bf414c | 3014 | struct c_expr expr = c_parser_expression (parser); |
7d882b83 | 3015 | c_inhibit_evaluation_warnings--; |
27bf414c JM |
3016 | in_typeof--; |
3017 | if (TREE_CODE (expr.value) == COMPONENT_REF | |
3018 | && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1))) | |
3ba09659 | 3019 | error_at (here, "%<typeof%> applied to a bit-field"); |
ebfbbdc5 | 3020 | mark_exp_read (expr.value); |
27bf414c | 3021 | ret.spec = TREE_TYPE (expr.value); |
52ffd86e | 3022 | was_vm = variably_modified_type_p (ret.spec, NULL_TREE); |
928c19bb JM |
3023 | /* This is returned with the type so that when the type is |
3024 | evaluated, this can be evaluated. */ | |
3025 | if (was_vm) | |
3026 | ret.expr = c_fully_fold (expr.value, false, &ret.expr_const_operands); | |
52ffd86e | 3027 | pop_maybe_used (was_vm); |
9698b078 SH |
3028 | /* For use in macros such as those in <stdatomic.h>, remove all |
3029 | qualifiers from atomic types. (const can be an issue for more macros | |
3030 | using typeof than just the <stdatomic.h> ones.) */ | |
267bac10 | 3031 | if (ret.spec != error_mark_node && TYPE_ATOMIC (ret.spec)) |
9698b078 | 3032 | ret.spec = c_build_qualified_type (ret.spec, TYPE_UNQUALIFIED); |
27bf414c JM |
3033 | } |
3034 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
3035 | return ret; | |
3036 | } | |
3037 | ||
d19fa6b5 JM |
3038 | /* Parse an alignment-specifier. |
3039 | ||
48b0b196 | 3040 | C11 6.7.5: |
d19fa6b5 JM |
3041 | |
3042 | alignment-specifier: | |
3043 | _Alignas ( type-name ) | |
3044 | _Alignas ( constant-expression ) | |
3045 | */ | |
3046 | ||
3047 | static tree | |
3048 | c_parser_alignas_specifier (c_parser * parser) | |
3049 | { | |
3050 | tree ret = error_mark_node; | |
3051 | location_t loc = c_parser_peek_token (parser)->location; | |
3052 | gcc_assert (c_parser_next_token_is_keyword (parser, RID_ALIGNAS)); | |
3053 | c_parser_consume_token (parser); | |
48b0b196 | 3054 | if (!flag_isoc11) |
d19fa6b5 JM |
3055 | { |
3056 | if (flag_isoc99) | |
c1771a20 | 3057 | pedwarn (loc, OPT_Wpedantic, |
d19fa6b5 JM |
3058 | "ISO C99 does not support %<_Alignas%>"); |
3059 | else | |
c1771a20 | 3060 | pedwarn (loc, OPT_Wpedantic, |
d19fa6b5 JM |
3061 | "ISO C90 does not support %<_Alignas%>"); |
3062 | } | |
3063 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
3064 | return ret; | |
3065 | if (c_parser_next_tokens_start_typename (parser, cla_prefer_id)) | |
3066 | { | |
3067 | struct c_type_name *type = c_parser_type_name (parser); | |
3068 | if (type != NULL) | |
296674db JM |
3069 | ret = c_sizeof_or_alignof_type (loc, groktypename (type, NULL, NULL), |
3070 | false, true, 1); | |
d19fa6b5 JM |
3071 | } |
3072 | else | |
3073 | ret = c_parser_expr_no_commas (parser, NULL).value; | |
3074 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
3075 | return ret; | |
3076 | } | |
3077 | ||
27bf414c JM |
3078 | /* Parse a declarator, possibly an abstract declarator (C90 6.5.4, |
3079 | 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may | |
3080 | be redeclared; otherwise it may not. KIND indicates which kind of | |
3081 | declarator is wanted. Returns a valid declarator except in the | |
3082 | case of a syntax error in which case NULL is returned. *SEEN_ID is | |
3083 | set to true if an identifier being declared is seen; this is used | |
3084 | to diagnose bad forms of abstract array declarators and to | |
3085 | determine whether an identifier list is syntactically permitted. | |
3086 | ||
3087 | declarator: | |
3088 | pointer[opt] direct-declarator | |
3089 | ||
3090 | direct-declarator: | |
3091 | identifier | |
3092 | ( attributes[opt] declarator ) | |
3093 | direct-declarator array-declarator | |
3094 | direct-declarator ( parameter-type-list ) | |
3095 | direct-declarator ( identifier-list[opt] ) | |
3096 | ||
3097 | pointer: | |
3098 | * type-qualifier-list[opt] | |
3099 | * type-qualifier-list[opt] pointer | |
3100 | ||
3101 | type-qualifier-list: | |
3102 | type-qualifier | |
3103 | attributes | |
3104 | type-qualifier-list type-qualifier | |
3105 | type-qualifier-list attributes | |
3106 | ||
568a31f2 MP |
3107 | array-declarator: |
3108 | [ type-qualifier-list[opt] assignment-expression[opt] ] | |
3109 | [ static type-qualifier-list[opt] assignment-expression ] | |
3110 | [ type-qualifier-list static assignment-expression ] | |
3111 | [ type-qualifier-list[opt] * ] | |
3112 | ||
27bf414c JM |
3113 | parameter-type-list: |
3114 | parameter-list | |
3115 | parameter-list , ... | |
3116 | ||
3117 | parameter-list: | |
3118 | parameter-declaration | |
3119 | parameter-list , parameter-declaration | |
3120 | ||
3121 | parameter-declaration: | |
3122 | declaration-specifiers declarator attributes[opt] | |
3123 | declaration-specifiers abstract-declarator[opt] attributes[opt] | |
3124 | ||
3125 | identifier-list: | |
3126 | identifier | |
3127 | identifier-list , identifier | |
3128 | ||
3129 | abstract-declarator: | |
3130 | pointer | |
3131 | pointer[opt] direct-abstract-declarator | |
3132 | ||
3133 | direct-abstract-declarator: | |
3134 | ( attributes[opt] abstract-declarator ) | |
3135 | direct-abstract-declarator[opt] array-declarator | |
3136 | direct-abstract-declarator[opt] ( parameter-type-list[opt] ) | |
3137 | ||
3138 | GNU extensions: | |
3139 | ||
3140 | direct-declarator: | |
3141 | direct-declarator ( parameter-forward-declarations | |
3142 | parameter-type-list[opt] ) | |
3143 | ||
3144 | direct-abstract-declarator: | |
c22cacf3 | 3145 | direct-abstract-declarator[opt] ( parameter-forward-declarations |
27bf414c JM |
3146 | parameter-type-list[opt] ) |
3147 | ||
3148 | parameter-forward-declarations: | |
3149 | parameter-list ; | |
3150 | parameter-forward-declarations parameter-list ; | |
3151 | ||
3152 | The uses of attributes shown above are GNU extensions. | |
3153 | ||
3154 | Some forms of array declarator are not included in C99 in the | |
3155 | syntax for abstract declarators; these are disallowed elsewhere. | |
3156 | This may be a defect (DR#289). | |
3157 | ||
3158 | This function also accepts an omitted abstract declarator as being | |
3159 | an abstract declarator, although not part of the formal syntax. */ | |
3160 | ||
3161 | static struct c_declarator * | |
3162 | c_parser_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind, | |
3163 | bool *seen_id) | |
3164 | { | |
3165 | /* Parse any initial pointer part. */ | |
3166 | if (c_parser_next_token_is (parser, CPP_MULT)) | |
3167 | { | |
3168 | struct c_declspecs *quals_attrs = build_null_declspecs (); | |
3169 | struct c_declarator *inner; | |
3170 | c_parser_consume_token (parser); | |
568a31f2 | 3171 | c_parser_declspecs (parser, quals_attrs, false, false, true, |
38b7bc7f | 3172 | false, false, cla_prefer_id); |
27bf414c JM |
3173 | inner = c_parser_declarator (parser, type_seen_p, kind, seen_id); |
3174 | if (inner == NULL) | |
3175 | return NULL; | |
3176 | else | |
3177 | return make_pointer_declarator (quals_attrs, inner); | |
3178 | } | |
3179 | /* Now we have a direct declarator, direct abstract declarator or | |
3180 | nothing (which counts as a direct abstract declarator here). */ | |
3181 | return c_parser_direct_declarator (parser, type_seen_p, kind, seen_id); | |
3182 | } | |
3183 | ||
3184 | /* Parse a direct declarator or direct abstract declarator; arguments | |
3185 | as c_parser_declarator. */ | |
3186 | ||
3187 | static struct c_declarator * | |
3188 | c_parser_direct_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind, | |
3189 | bool *seen_id) | |
3190 | { | |
3191 | /* The direct declarator must start with an identifier (possibly | |
3192 | omitted) or a parenthesized declarator (possibly abstract). In | |
3193 | an ordinary declarator, initial parentheses must start a | |
3194 | parenthesized declarator. In an abstract declarator or parameter | |
3195 | declarator, they could start a parenthesized declarator or a | |
3196 | parameter list. To tell which, the open parenthesis and any | |
3197 | following attributes must be read. If a declaration specifier | |
3198 | follows, then it is a parameter list; if the specifier is a | |
3199 | typedef name, there might be an ambiguity about redeclaring it, | |
3200 | which is resolved in the direction of treating it as a typedef | |
3201 | name. If a close parenthesis follows, it is also an empty | |
3202 | parameter list, as the syntax does not permit empty abstract | |
0fa2e4df | 3203 | declarators. Otherwise, it is a parenthesized declarator (in |
27bf414c JM |
3204 | which case the analysis may be repeated inside it, recursively). |
3205 | ||
3206 | ??? There is an ambiguity in a parameter declaration "int | |
3207 | (__attribute__((foo)) x)", where x is not a typedef name: it | |
3208 | could be an abstract declarator for a function, or declare x with | |
3209 | parentheses. The proper resolution of this ambiguity needs | |
3210 | documenting. At present we follow an accident of the old | |
3211 | parser's implementation, whereby the first parameter must have | |
3212 | some declaration specifiers other than just attributes. Thus as | |
0fa2e4df | 3213 | a parameter declaration it is treated as a parenthesized |
27bf414c JM |
3214 | parameter named x, and as an abstract declarator it is |
3215 | rejected. | |
3216 | ||
3217 | ??? Also following the old parser, attributes inside an empty | |
3218 | parameter list are ignored, making it a list not yielding a | |
3219 | prototype, rather than giving an error or making it have one | |
3220 | parameter with implicit type int. | |
3221 | ||
3222 | ??? Also following the old parser, typedef names may be | |
3223 | redeclared in declarators, but not Objective-C class names. */ | |
3224 | ||
3225 | if (kind != C_DTR_ABSTRACT | |
3226 | && c_parser_next_token_is (parser, CPP_NAME) | |
3227 | && ((type_seen_p | |
a6341d57 NP |
3228 | && (c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME |
3229 | || c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME)) | |
27bf414c JM |
3230 | || c_parser_peek_token (parser)->id_kind == C_ID_ID)) |
3231 | { | |
3232 | struct c_declarator *inner | |
3233 | = build_id_declarator (c_parser_peek_token (parser)->value); | |
3234 | *seen_id = true; | |
6037d88d | 3235 | inner->id_loc = c_parser_peek_token (parser)->location; |
27bf414c JM |
3236 | c_parser_consume_token (parser); |
3237 | return c_parser_direct_declarator_inner (parser, *seen_id, inner); | |
3238 | } | |
3239 | ||
3240 | if (kind != C_DTR_NORMAL | |
3241 | && c_parser_next_token_is (parser, CPP_OPEN_SQUARE)) | |
3242 | { | |
3243 | struct c_declarator *inner = build_id_declarator (NULL_TREE); | |
3244 | return c_parser_direct_declarator_inner (parser, *seen_id, inner); | |
3245 | } | |
3246 | ||
3247 | /* Either we are at the end of an abstract declarator, or we have | |
3248 | parentheses. */ | |
3249 | ||
3250 | if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) | |
3251 | { | |
3252 | tree attrs; | |
3253 | struct c_declarator *inner; | |
3254 | c_parser_consume_token (parser); | |
3255 | attrs = c_parser_attributes (parser); | |
3256 | if (kind != C_DTR_NORMAL | |
3257 | && (c_parser_next_token_starts_declspecs (parser) | |
3258 | || c_parser_next_token_is (parser, CPP_CLOSE_PAREN))) | |
3259 | { | |
3260 | struct c_arg_info *args | |
3261 | = c_parser_parms_declarator (parser, kind == C_DTR_NORMAL, | |
3262 | attrs); | |
3263 | if (args == NULL) | |
3264 | return NULL; | |
3265 | else | |
3266 | { | |
3267 | inner | |
3268 | = build_function_declarator (args, | |
3269 | build_id_declarator (NULL_TREE)); | |
3270 | return c_parser_direct_declarator_inner (parser, *seen_id, | |
3271 | inner); | |
3272 | } | |
3273 | } | |
3274 | /* A parenthesized declarator. */ | |
3275 | inner = c_parser_declarator (parser, type_seen_p, kind, seen_id); | |
3276 | if (inner != NULL && attrs != NULL) | |
3277 | inner = build_attrs_declarator (attrs, inner); | |
3278 | if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) | |
3279 | { | |
3280 | c_parser_consume_token (parser); | |
3281 | if (inner == NULL) | |
3282 | return NULL; | |
3283 | else | |
3284 | return c_parser_direct_declarator_inner (parser, *seen_id, inner); | |
3285 | } | |
3286 | else | |
3287 | { | |
3288 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, | |
3289 | "expected %<)%>"); | |
3290 | return NULL; | |
3291 | } | |
3292 | } | |
3293 | else | |
3294 | { | |
3295 | if (kind == C_DTR_NORMAL) | |
3296 | { | |
3297 | c_parser_error (parser, "expected identifier or %<(%>"); | |
3298 | return NULL; | |
3299 | } | |
3300 | else | |
3301 | return build_id_declarator (NULL_TREE); | |
3302 | } | |
3303 | } | |
3304 | ||
3305 | /* Parse part of a direct declarator or direct abstract declarator, | |
3306 | given that some (in INNER) has already been parsed; ID_PRESENT is | |
3307 | true if an identifier is present, false for an abstract | |
3308 | declarator. */ | |
3309 | ||
3310 | static struct c_declarator * | |
3311 | c_parser_direct_declarator_inner (c_parser *parser, bool id_present, | |
3312 | struct c_declarator *inner) | |
3313 | { | |
3314 | /* Parse a sequence of array declarators and parameter lists. */ | |
3315 | if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE)) | |
3316 | { | |
b8698a0f | 3317 | location_t brace_loc = c_parser_peek_token (parser)->location; |
27bf414c JM |
3318 | struct c_declarator *declarator; |
3319 | struct c_declspecs *quals_attrs = build_null_declspecs (); | |
3320 | bool static_seen; | |
3321 | bool star_seen; | |
267bac10 JM |
3322 | struct c_expr dimen; |
3323 | dimen.value = NULL_TREE; | |
3324 | dimen.original_code = ERROR_MARK; | |
3325 | dimen.original_type = NULL_TREE; | |
27bf414c | 3326 | c_parser_consume_token (parser); |
568a31f2 | 3327 | c_parser_declspecs (parser, quals_attrs, false, false, true, |
38b7bc7f | 3328 | false, false, cla_prefer_id); |
27bf414c JM |
3329 | static_seen = c_parser_next_token_is_keyword (parser, RID_STATIC); |
3330 | if (static_seen) | |
3331 | c_parser_consume_token (parser); | |
3332 | if (static_seen && !quals_attrs->declspecs_seen_p) | |
568a31f2 | 3333 | c_parser_declspecs (parser, quals_attrs, false, false, true, |
38b7bc7f | 3334 | false, false, cla_prefer_id); |
27bf414c JM |
3335 | if (!quals_attrs->declspecs_seen_p) |
3336 | quals_attrs = NULL; | |
3337 | /* If "static" is present, there must be an array dimension. | |
3338 | Otherwise, there may be a dimension, "*", or no | |
3339 | dimension. */ | |
3340 | if (static_seen) | |
3341 | { | |
3342 | star_seen = false; | |
267bac10 | 3343 | dimen = c_parser_expr_no_commas (parser, NULL); |
27bf414c JM |
3344 | } |
3345 | else | |
3346 | { | |
3347 | if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE)) | |
3348 | { | |
267bac10 | 3349 | dimen.value = NULL_TREE; |
27bf414c JM |
3350 | star_seen = false; |
3351 | } | |
b72271b9 | 3352 | else if (flag_cilkplus |
36536d79 BI |
3353 | && c_parser_next_token_is (parser, CPP_COLON)) |
3354 | { | |
267bac10 | 3355 | dimen.value = error_mark_node; |
36536d79 BI |
3356 | star_seen = false; |
3357 | error_at (c_parser_peek_token (parser)->location, | |
3358 | "array notations cannot be used in declaration"); | |
3359 | c_parser_consume_token (parser); | |
3360 | } | |
27bf414c JM |
3361 | else if (c_parser_next_token_is (parser, CPP_MULT)) |
3362 | { | |
3363 | if (c_parser_peek_2nd_token (parser)->type == CPP_CLOSE_SQUARE) | |
3364 | { | |
267bac10 | 3365 | dimen.value = NULL_TREE; |
27bf414c JM |
3366 | star_seen = true; |
3367 | c_parser_consume_token (parser); | |
3368 | } | |
3369 | else | |
3370 | { | |
3371 | star_seen = false; | |
267bac10 | 3372 | dimen = c_parser_expr_no_commas (parser, NULL); |
27bf414c JM |
3373 | } |
3374 | } | |
3375 | else | |
3376 | { | |
3377 | star_seen = false; | |
267bac10 | 3378 | dimen = c_parser_expr_no_commas (parser, NULL); |
27bf414c JM |
3379 | } |
3380 | } | |
3381 | if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE)) | |
3382 | c_parser_consume_token (parser); | |
b72271b9 | 3383 | else if (flag_cilkplus |
36536d79 BI |
3384 | && c_parser_next_token_is (parser, CPP_COLON)) |
3385 | { | |
3386 | error_at (c_parser_peek_token (parser)->location, | |
3387 | "array notations cannot be used in declaration"); | |
3388 | c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL); | |
3389 | return NULL; | |
3390 | } | |
27bf414c JM |
3391 | else |
3392 | { | |
3393 | c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, | |
3394 | "expected %<]%>"); | |
3395 | return NULL; | |
3396 | } | |
267bac10 JM |
3397 | if (dimen.value) |
3398 | dimen = convert_lvalue_to_rvalue (brace_loc, dimen, true, true); | |
3399 | declarator = build_array_declarator (brace_loc, dimen.value, quals_attrs, | |
c2255bc4 | 3400 | static_seen, star_seen); |
52ffd86e MS |
3401 | if (declarator == NULL) |
3402 | return NULL; | |
6ac0194d | 3403 | inner = set_array_declarator_inner (declarator, inner); |
27bf414c JM |
3404 | return c_parser_direct_declarator_inner (parser, id_present, inner); |
3405 | } | |
3406 | else if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) | |
3407 | { | |
3408 | tree attrs; | |
3409 | struct c_arg_info *args; | |
3410 | c_parser_consume_token (parser); | |
3411 | attrs = c_parser_attributes (parser); | |
3412 | args = c_parser_parms_declarator (parser, id_present, attrs); | |
3413 | if (args == NULL) | |
3414 | return NULL; | |
3415 | else | |
3416 | { | |
3417 | inner = build_function_declarator (args, inner); | |
3418 | return c_parser_direct_declarator_inner (parser, id_present, inner); | |
3419 | } | |
3420 | } | |
3421 | return inner; | |
3422 | } | |
3423 | ||
3424 | /* Parse a parameter list or identifier list, including the closing | |
3425 | parenthesis but not the opening one. ATTRS are the attributes at | |
3426 | the start of the list. ID_LIST_OK is true if an identifier list is | |
3427 | acceptable; such a list must not have attributes at the start. */ | |
3428 | ||
3429 | static struct c_arg_info * | |
3430 | c_parser_parms_declarator (c_parser *parser, bool id_list_ok, tree attrs) | |
3431 | { | |
3432 | push_scope (); | |
3433 | declare_parm_level (); | |
3434 | /* If the list starts with an identifier, it is an identifier list. | |
3435 | Otherwise, it is either a prototype list or an empty list. */ | |
3436 | if (id_list_ok | |
3437 | && !attrs | |
3438 | && c_parser_next_token_is (parser, CPP_NAME) | |
29ce73cb PB |
3439 | && c_parser_peek_token (parser)->id_kind == C_ID_ID |
3440 | ||
3441 | /* Look ahead to detect typos in type names. */ | |
3442 | && c_parser_peek_2nd_token (parser)->type != CPP_NAME | |
3443 | && c_parser_peek_2nd_token (parser)->type != CPP_MULT | |
3444 | && c_parser_peek_2nd_token (parser)->type != CPP_OPEN_PAREN | |
3445 | && c_parser_peek_2nd_token (parser)->type != CPP_OPEN_SQUARE) | |
27bf414c | 3446 | { |
7fa3585c | 3447 | tree list = NULL_TREE, *nextp = &list; |
27bf414c JM |
3448 | while (c_parser_next_token_is (parser, CPP_NAME) |
3449 | && c_parser_peek_token (parser)->id_kind == C_ID_ID) | |
3450 | { | |
7fa3585c GK |
3451 | *nextp = build_tree_list (NULL_TREE, |
3452 | c_parser_peek_token (parser)->value); | |
3453 | nextp = & TREE_CHAIN (*nextp); | |
27bf414c JM |
3454 | c_parser_consume_token (parser); |
3455 | if (c_parser_next_token_is_not (parser, CPP_COMMA)) | |
3456 | break; | |
3457 | c_parser_consume_token (parser); | |
3458 | if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) | |
3459 | { | |
3460 | c_parser_error (parser, "expected identifier"); | |
3461 | break; | |
3462 | } | |
3463 | } | |
3464 | if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) | |
3465 | { | |
b3399d18 | 3466 | struct c_arg_info *ret = build_arg_info (); |
27bf414c | 3467 | ret->types = list; |
27bf414c JM |
3468 | c_parser_consume_token (parser); |
3469 | pop_scope (); | |
3470 | return ret; | |
3471 | } | |
3472 | else | |
3473 | { | |
3474 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, | |
3475 | "expected %<)%>"); | |
3476 | pop_scope (); | |
3477 | return NULL; | |
3478 | } | |
3479 | } | |
3480 | else | |
3481 | { | |
a04a722b JM |
3482 | struct c_arg_info *ret = c_parser_parms_list_declarator (parser, attrs, |
3483 | NULL); | |
27bf414c JM |
3484 | pop_scope (); |
3485 | return ret; | |
3486 | } | |
3487 | } | |
3488 | ||
3489 | /* Parse a parameter list (possibly empty), including the closing | |
3490 | parenthesis but not the opening one. ATTRS are the attributes at | |
a04a722b JM |
3491 | the start of the list. EXPR is NULL or an expression that needs to |
3492 | be evaluated for the side effects of array size expressions in the | |
3493 | parameters. */ | |
27bf414c JM |
3494 | |
3495 | static struct c_arg_info * | |
a04a722b | 3496 | c_parser_parms_list_declarator (c_parser *parser, tree attrs, tree expr) |
27bf414c | 3497 | { |
09a1e889 | 3498 | bool bad_parm = false; |
a04a722b | 3499 | |
27bf414c JM |
3500 | /* ??? Following the old parser, forward parameter declarations may |
3501 | use abstract declarators, and if no real parameter declarations | |
3502 | follow the forward declarations then this is not diagnosed. Also | |
3503 | note as above that attributes are ignored as the only contents of | |
3504 | the parentheses, or as the only contents after forward | |
3505 | declarations. */ | |
3506 | if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) | |
3507 | { | |
b3399d18 | 3508 | struct c_arg_info *ret = build_arg_info (); |
27bf414c JM |
3509 | c_parser_consume_token (parser); |
3510 | return ret; | |
3511 | } | |
3512 | if (c_parser_next_token_is (parser, CPP_ELLIPSIS)) | |
3513 | { | |
b3399d18 | 3514 | struct c_arg_info *ret = build_arg_info (); |
6637388f TG |
3515 | |
3516 | if (flag_allow_parameterless_variadic_functions) | |
3517 | { | |
3518 | /* F (...) is allowed. */ | |
3519 | ret->types = NULL_TREE; | |
3520 | } | |
3521 | else | |
3522 | { | |
3523 | /* Suppress -Wold-style-definition for this case. */ | |
3524 | ret->types = error_mark_node; | |
3525 | error_at (c_parser_peek_token (parser)->location, | |
3526 | "ISO C requires a named argument before %<...%>"); | |
3527 | } | |
27bf414c JM |
3528 | c_parser_consume_token (parser); |
3529 | if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) | |
3530 | { | |
3531 | c_parser_consume_token (parser); | |
3532 | return ret; | |
3533 | } | |
3534 | else | |
3535 | { | |
3536 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, | |
3537 | "expected %<)%>"); | |
3538 | return NULL; | |
3539 | } | |
3540 | } | |
3541 | /* Nonempty list of parameters, either terminated with semicolon | |
3542 | (forward declarations; recurse) or with close parenthesis (normal | |
3543 | function) or with ", ... )" (variadic function). */ | |
3544 | while (true) | |
3545 | { | |
3546 | /* Parse a parameter. */ | |
3547 | struct c_parm *parm = c_parser_parameter_declaration (parser, attrs); | |
3548 | attrs = NULL_TREE; | |
09a1e889 SZ |
3549 | if (parm == NULL) |
3550 | bad_parm = true; | |
3551 | else | |
a04a722b | 3552 | push_parm_decl (parm, &expr); |
27bf414c JM |
3553 | if (c_parser_next_token_is (parser, CPP_SEMICOLON)) |
3554 | { | |
3555 | tree new_attrs; | |
3556 | c_parser_consume_token (parser); | |
91d975b8 | 3557 | mark_forward_parm_decls (); |
27bf414c | 3558 | new_attrs = c_parser_attributes (parser); |
a04a722b | 3559 | return c_parser_parms_list_declarator (parser, new_attrs, expr); |
27bf414c JM |
3560 | } |
3561 | if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) | |
3562 | { | |
3563 | c_parser_consume_token (parser); | |
09a1e889 | 3564 | if (bad_parm) |
a04a722b | 3565 | return NULL; |
09a1e889 | 3566 | else |
a04a722b | 3567 | return get_parm_info (false, expr); |
27bf414c JM |
3568 | } |
3569 | if (!c_parser_require (parser, CPP_COMMA, | |
3570 | "expected %<;%>, %<,%> or %<)%>")) | |
3571 | { | |
3572 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); | |
3573 | return NULL; | |
3574 | } | |
3575 | if (c_parser_next_token_is (parser, CPP_ELLIPSIS)) | |
3576 | { | |
3577 | c_parser_consume_token (parser); | |
3578 | if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) | |
3579 | { | |
3580 | c_parser_consume_token (parser); | |
09a1e889 | 3581 | if (bad_parm) |
a04a722b | 3582 | return NULL; |
09a1e889 | 3583 | else |
a04a722b | 3584 | return get_parm_info (true, expr); |
27bf414c JM |
3585 | } |
3586 | else | |
3587 | { | |
3588 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, | |
3589 | "expected %<)%>"); | |
3590 | return NULL; | |
3591 | } | |
3592 | } | |
3593 | } | |
3594 | } | |
3595 | ||
3596 | /* Parse a parameter declaration. ATTRS are the attributes at the | |
3597 | start of the declaration if it is the first parameter. */ | |
3598 | ||
3599 | static struct c_parm * | |
3600 | c_parser_parameter_declaration (c_parser *parser, tree attrs) | |
3601 | { | |
3602 | struct c_declspecs *specs; | |
3603 | struct c_declarator *declarator; | |
3604 | tree prefix_attrs; | |
3605 | tree postfix_attrs = NULL_TREE; | |
3606 | bool dummy = false; | |
51a1aacf TG |
3607 | |
3608 | /* Accept #pragmas between parameter declarations. */ | |
3609 | while (c_parser_next_token_is (parser, CPP_PRAGMA)) | |
acf0174b | 3610 | c_parser_pragma (parser, pragma_param); |
51a1aacf | 3611 | |
27bf414c JM |
3612 | if (!c_parser_next_token_starts_declspecs (parser)) |
3613 | { | |
09a1e889 SZ |
3614 | c_token *token = c_parser_peek_token (parser); |
3615 | if (parser->error) | |
3616 | return NULL; | |
3617 | c_parser_set_source_position_from_token (token); | |
29ce73cb | 3618 | if (c_parser_next_tokens_start_typename (parser, cla_prefer_type)) |
09a1e889 | 3619 | { |
1c9f5f33 | 3620 | error_at (token->location, "unknown type name %qE", token->value); |
09a1e889 SZ |
3621 | parser->error = true; |
3622 | } | |
27bf414c JM |
3623 | /* ??? In some Objective-C cases '...' isn't applicable so there |
3624 | should be a different message. */ | |
09a1e889 SZ |
3625 | else |
3626 | c_parser_error (parser, | |
3627 | "expected declaration specifiers or %<...%>"); | |
27bf414c JM |
3628 | c_parser_skip_to_end_of_parameter (parser); |
3629 | return NULL; | |
3630 | } | |
3631 | specs = build_null_declspecs (); | |
3632 | if (attrs) | |
3633 | { | |
0b2c4be5 | 3634 | declspecs_add_attrs (input_location, specs, attrs); |
27bf414c JM |
3635 | attrs = NULL_TREE; |
3636 | } | |
38b7bc7f | 3637 | c_parser_declspecs (parser, specs, true, true, true, true, false, |
568a31f2 | 3638 | cla_nonabstract_decl); |
27bf414c JM |
3639 | finish_declspecs (specs); |
3640 | pending_xref_error (); | |
3641 | prefix_attrs = specs->attrs; | |
3642 | specs->attrs = NULL_TREE; | |
9e5b2115 PB |
3643 | declarator = c_parser_declarator (parser, |
3644 | specs->typespec_kind != ctsk_none, | |
27bf414c JM |
3645 | C_DTR_PARM, &dummy); |
3646 | if (declarator == NULL) | |
3647 | { | |
3648 | c_parser_skip_until_found (parser, CPP_COMMA, NULL); | |
3649 | return NULL; | |
3650 | } | |
3651 | if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)) | |
3652 | postfix_attrs = c_parser_attributes (parser); | |
3653 | return build_c_parm (specs, chainon (postfix_attrs, prefix_attrs), | |
3654 | declarator); | |
3655 | } | |
3656 | ||
3657 | /* Parse a string literal in an asm expression. It should not be | |
3658 | translated, and wide string literals are an error although | |
3659 | permitted by the syntax. This is a GNU extension. | |
3660 | ||
3661 | asm-string-literal: | |
3662 | string-literal | |
3663 | ||
3664 | ??? At present, following the old parser, the caller needs to have | |
46c2514e TT |
3665 | set lex_untranslated_string to 1. It would be better to follow the |
3666 | C++ parser rather than using this kludge. */ | |
27bf414c JM |
3667 | |
3668 | static tree | |
3669 | c_parser_asm_string_literal (c_parser *parser) | |
3670 | { | |
3671 | tree str; | |
87f9e23d TT |
3672 | int save_flag = warn_overlength_strings; |
3673 | warn_overlength_strings = 0; | |
27bf414c JM |
3674 | if (c_parser_next_token_is (parser, CPP_STRING)) |
3675 | { | |
3676 | str = c_parser_peek_token (parser)->value; | |
3677 | c_parser_consume_token (parser); | |
3678 | } | |
3679 | else if (c_parser_next_token_is (parser, CPP_WSTRING)) | |
3680 | { | |
3ba09659 AH |
3681 | error_at (c_parser_peek_token (parser)->location, |
3682 | "wide string literal in %<asm%>"); | |
27bf414c JM |
3683 | str = build_string (1, ""); |
3684 | c_parser_consume_token (parser); | |
3685 | } | |
3686 | else | |
3687 | { | |
3688 | c_parser_error (parser, "expected string literal"); | |
3689 | str = NULL_TREE; | |
3690 | } | |
87f9e23d | 3691 | warn_overlength_strings = save_flag; |
27bf414c JM |
3692 | return str; |
3693 | } | |
3694 | ||
3695 | /* Parse a simple asm expression. This is used in restricted | |
3696 | contexts, where a full expression with inputs and outputs does not | |
3697 | make sense. This is a GNU extension. | |
3698 | ||
3699 | simple-asm-expr: | |
3700 | asm ( asm-string-literal ) | |
3701 | */ | |
3702 | ||
3703 | static tree | |
3704 | c_parser_simple_asm_expr (c_parser *parser) | |
3705 | { | |
3706 | tree str; | |
3707 | gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM)); | |
3708 | /* ??? Follow the C++ parser rather than using the | |
46c2514e TT |
3709 | lex_untranslated_string kludge. */ |
3710 | parser->lex_untranslated_string = true; | |
27bf414c JM |
3711 | c_parser_consume_token (parser); |
3712 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
3713 | { | |
46c2514e | 3714 | parser->lex_untranslated_string = false; |
27bf414c JM |
3715 | return NULL_TREE; |
3716 | } | |
3717 | str = c_parser_asm_string_literal (parser); | |
46c2514e | 3718 | parser->lex_untranslated_string = false; |
27bf414c JM |
3719 | if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>")) |
3720 | { | |
3721 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); | |
3722 | return NULL_TREE; | |
3723 | } | |
3724 | return str; | |
3725 | } | |
3726 | ||
0a35513e AH |
3727 | static tree |
3728 | c_parser_attribute_any_word (c_parser *parser) | |
3729 | { | |
3730 | tree attr_name = NULL_TREE; | |
3731 | ||
3732 | if (c_parser_next_token_is (parser, CPP_KEYWORD)) | |
3733 | { | |
3734 | /* ??? See comment above about what keywords are accepted here. */ | |
3735 | bool ok; | |
3736 | switch (c_parser_peek_token (parser)->keyword) | |
3737 | { | |
3738 | case RID_STATIC: | |
3739 | case RID_UNSIGNED: | |
3740 | case RID_LONG: | |
3741 | case RID_INT128: | |
3742 | case RID_CONST: | |
3743 | case RID_EXTERN: | |
3744 | case RID_REGISTER: | |
3745 | case RID_TYPEDEF: | |
3746 | case RID_SHORT: | |
3747 | case RID_INLINE: | |
3748 | case RID_NORETURN: | |
3749 | case RID_VOLATILE: | |
3750 | case RID_SIGNED: | |
3751 | case RID_AUTO: | |
3752 | case RID_RESTRICT: | |
3753 | case RID_COMPLEX: | |
3754 | case RID_THREAD: | |
3755 | case RID_INT: | |
3756 | case RID_CHAR: | |
3757 | case RID_FLOAT: | |
3758 | case RID_DOUBLE: | |
3759 | case RID_VOID: | |
3760 | case RID_DFLOAT32: | |
3761 | case RID_DFLOAT64: | |
3762 | case RID_DFLOAT128: | |
3763 | case RID_BOOL: | |
3764 | case RID_FRACT: | |
3765 | case RID_ACCUM: | |
3766 | case RID_SAT: | |
3767 | case RID_TRANSACTION_ATOMIC: | |
3768 | case RID_TRANSACTION_CANCEL: | |
267bac10 | 3769 | case RID_ATOMIC: |
38b7bc7f | 3770 | case RID_AUTO_TYPE: |
0a35513e AH |
3771 | ok = true; |
3772 | break; | |
3773 | default: | |
3774 | ok = false; | |
3775 | break; | |
3776 | } | |
3777 | if (!ok) | |
3778 | return NULL_TREE; | |
3779 | ||
3780 | /* Accept __attribute__((__const)) as __attribute__((const)) etc. */ | |
3781 | attr_name = ridpointers[(int) c_parser_peek_token (parser)->keyword]; | |
3782 | } | |
3783 | else if (c_parser_next_token_is (parser, CPP_NAME)) | |
3784 | attr_name = c_parser_peek_token (parser)->value; | |
3785 | ||
3786 | return attr_name; | |
3787 | } | |
3788 | ||
41958c28 BI |
3789 | /* Returns true of NAME is an IDENTIFIER_NODE with identiifer "vector," |
3790 | "__vector" or "__vector__." */ | |
3791 | ||
3792 | static inline bool | |
3793 | is_cilkplus_vector_p (tree name) | |
3794 | { | |
b72271b9 | 3795 | if (flag_cilkplus && is_attribute_p ("vector", name)) |
41958c28 BI |
3796 | return true; |
3797 | return false; | |
3798 | } | |
3799 | ||
3800 | #define CILK_SIMD_FN_CLAUSE_MASK \ | |
3801 | ((OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_VECTORLENGTH) \ | |
3802 | | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_LINEAR) \ | |
3803 | | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_UNIFORM) \ | |
3804 | | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_MASK) \ | |
3805 | | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_NOMASK)) | |
3806 | ||
3807 | /* Parses the vector attribute of SIMD enabled functions in Cilk Plus. | |
3808 | VEC_TOKEN is the "vector" token that is replaced with "simd" and | |
3809 | pushed into the token list. | |
3810 | Syntax: | |
3811 | vector | |
3812 | vector (<vector attributes>). */ | |
3813 | ||
3814 | static void | |
3815 | c_parser_cilk_simd_fn_vector_attrs (c_parser *parser, c_token vec_token) | |
3816 | { | |
3817 | gcc_assert (is_cilkplus_vector_p (vec_token.value)); | |
3818 | ||
3819 | int paren_scope = 0; | |
3820 | vec_safe_push (parser->cilk_simd_fn_tokens, vec_token); | |
3821 | /* Consume the "vector" token. */ | |
3822 | c_parser_consume_token (parser); | |
3823 | ||
3824 | if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) | |
3825 | { | |
3826 | c_parser_consume_token (parser); | |
3827 | paren_scope++; | |
3828 | } | |
3829 | while (paren_scope > 0) | |
3830 | { | |
3831 | c_token *token = c_parser_peek_token (parser); | |
3832 | if (token->type == CPP_OPEN_PAREN) | |
3833 | paren_scope++; | |
3834 | else if (token->type == CPP_CLOSE_PAREN) | |
3835 | paren_scope--; | |
3836 | /* Do not push the last ')' since we are not pushing the '('. */ | |
3837 | if (!(token->type == CPP_CLOSE_PAREN && paren_scope == 0)) | |
3838 | vec_safe_push (parser->cilk_simd_fn_tokens, *token); | |
3839 | c_parser_consume_token (parser); | |
3840 | } | |
3841 | ||
3842 | /* Since we are converting an attribute to a pragma, we need to end the | |
3843 | attribute with PRAGMA_EOL. */ | |
3844 | c_token eol_token; | |
3845 | memset (&eol_token, 0, sizeof (eol_token)); | |
3846 | eol_token.type = CPP_PRAGMA_EOL; | |
3847 | vec_safe_push (parser->cilk_simd_fn_tokens, eol_token); | |
3848 | } | |
3849 | ||
3850 | /* Add 2 CPP_EOF at the end of PARSER->ELEM_FN_TOKENS vector. */ | |
3851 | ||
3852 | static void | |
3853 | c_finish_cilk_simd_fn_tokens (c_parser *parser) | |
3854 | { | |
3855 | c_token last_token = parser->cilk_simd_fn_tokens->last (); | |
3856 | ||
3857 | /* c_parser_attributes is called in several places, so if these EOF | |
3858 | tokens are already inserted, then don't do them again. */ | |
3859 | if (last_token.type == CPP_EOF) | |
3860 | return; | |
3861 | ||
3862 | /* Two CPP_EOF token are added as a safety net since the normal C | |
3863 | front-end has two token look-ahead. */ | |
3864 | c_token eof_token; | |
3865 | eof_token.type = CPP_EOF; | |
3866 | vec_safe_push (parser->cilk_simd_fn_tokens, eof_token); | |
3867 | vec_safe_push (parser->cilk_simd_fn_tokens, eof_token); | |
3868 | } | |
3869 | ||
27bf414c JM |
3870 | /* Parse (possibly empty) attributes. This is a GNU extension. |
3871 | ||
3872 | attributes: | |
3873 | empty | |
3874 | attributes attribute | |
3875 | ||
3876 | attribute: | |
3877 | __attribute__ ( ( attribute-list ) ) | |
3878 | ||
3879 | attribute-list: | |
3880 | attrib | |
3881 | attribute_list , attrib | |
3882 | ||
3883 | attrib: | |
3884 | empty | |
3885 | any-word | |
3886 | any-word ( identifier ) | |
3887 | any-word ( identifier , nonempty-expr-list ) | |
3888 | any-word ( expr-list ) | |
3889 | ||
3890 | where the "identifier" must not be declared as a type, and | |
3891 | "any-word" may be any identifier (including one declared as a | |
3892 | type), a reserved word storage class specifier, type specifier or | |
3893 | type qualifier. ??? This still leaves out most reserved keywords | |
3894 | (following the old parser), shouldn't we include them, and why not | |
3895 | allow identifiers declared as types to start the arguments? */ | |
3896 | ||
3897 | static tree | |
3898 | c_parser_attributes (c_parser *parser) | |
3899 | { | |
3900 | tree attrs = NULL_TREE; | |
3901 | while (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)) | |
3902 | { | |
3903 | /* ??? Follow the C++ parser rather than using the | |
46c2514e TT |
3904 | lex_untranslated_string kludge. */ |
3905 | parser->lex_untranslated_string = true; | |
27bf414c JM |
3906 | c_parser_consume_token (parser); |
3907 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
3908 | { | |
46c2514e | 3909 | parser->lex_untranslated_string = false; |
27bf414c JM |
3910 | return attrs; |
3911 | } | |
3912 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
3913 | { | |
46c2514e | 3914 | parser->lex_untranslated_string = false; |
27bf414c JM |
3915 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); |
3916 | return attrs; | |
3917 | } | |
3918 | /* Parse the attribute list. */ | |
3919 | while (c_parser_next_token_is (parser, CPP_COMMA) | |
3920 | || c_parser_next_token_is (parser, CPP_NAME) | |
3921 | || c_parser_next_token_is (parser, CPP_KEYWORD)) | |
3922 | { | |
3923 | tree attr, attr_name, attr_args; | |
9771b263 | 3924 | vec<tree, va_gc> *expr_list; |
27bf414c JM |
3925 | if (c_parser_next_token_is (parser, CPP_COMMA)) |
3926 | { | |
3927 | c_parser_consume_token (parser); | |
3928 | continue; | |
3929 | } | |
0a35513e AH |
3930 | |
3931 | attr_name = c_parser_attribute_any_word (parser); | |
3932 | if (attr_name == NULL) | |
3933 | break; | |
41958c28 BI |
3934 | if (is_cilkplus_vector_p (attr_name)) |
3935 | { | |
3936 | c_token *v_token = c_parser_peek_token (parser); | |
3937 | c_parser_cilk_simd_fn_vector_attrs (parser, *v_token); | |
3938 | continue; | |
3939 | } | |
27bf414c JM |
3940 | c_parser_consume_token (parser); |
3941 | if (c_parser_next_token_is_not (parser, CPP_OPEN_PAREN)) | |
3942 | { | |
3943 | attr = build_tree_list (attr_name, NULL_TREE); | |
3944 | attrs = chainon (attrs, attr); | |
3945 | continue; | |
3946 | } | |
3947 | c_parser_consume_token (parser); | |
3948 | /* Parse the attribute contents. If they start with an | |
3949 | identifier which is followed by a comma or close | |
3950 | parenthesis, then the arguments start with that | |
91ebb981 IS |
3951 | identifier; otherwise they are an expression list. |
3952 | In objective-c the identifier may be a classname. */ | |
27bf414c | 3953 | if (c_parser_next_token_is (parser, CPP_NAME) |
91ebb981 | 3954 | && (c_parser_peek_token (parser)->id_kind == C_ID_ID |
661a0813 MP |
3955 | || (c_dialect_objc () |
3956 | && c_parser_peek_token (parser)->id_kind | |
3957 | == C_ID_CLASSNAME)) | |
27bf414c JM |
3958 | && ((c_parser_peek_2nd_token (parser)->type == CPP_COMMA) |
3959 | || (c_parser_peek_2nd_token (parser)->type | |
661a0813 MP |
3960 | == CPP_CLOSE_PAREN)) |
3961 | && (attribute_takes_identifier_p (attr_name) | |
3962 | || (c_dialect_objc () | |
3963 | && c_parser_peek_token (parser)->id_kind | |
3964 | == C_ID_CLASSNAME))) | |
27bf414c JM |
3965 | { |
3966 | tree arg1 = c_parser_peek_token (parser)->value; | |
3967 | c_parser_consume_token (parser); | |
3968 | if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) | |
3969 | attr_args = build_tree_list (NULL_TREE, arg1); | |
3970 | else | |
3971 | { | |
bbbbb16a | 3972 | tree tree_list; |
27bf414c | 3973 | c_parser_consume_token (parser); |
1a4049e7 | 3974 | expr_list = c_parser_expr_list (parser, false, true, |
81e5eca8 | 3975 | NULL, NULL, NULL, NULL); |
c166b898 | 3976 | tree_list = build_tree_list_vec (expr_list); |
bbbbb16a | 3977 | attr_args = tree_cons (NULL_TREE, arg1, tree_list); |
c166b898 | 3978 | release_tree_vector (expr_list); |
27bf414c JM |
3979 | } |
3980 | } | |
3981 | else | |
3982 | { | |
3983 | if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) | |
3984 | attr_args = NULL_TREE; | |
3985 | else | |
bbbbb16a | 3986 | { |
1a4049e7 | 3987 | expr_list = c_parser_expr_list (parser, false, true, |
81e5eca8 | 3988 | NULL, NULL, NULL, NULL); |
c166b898 ILT |
3989 | attr_args = build_tree_list_vec (expr_list); |
3990 | release_tree_vector (expr_list); | |
bbbbb16a | 3991 | } |
27bf414c JM |
3992 | } |
3993 | attr = build_tree_list (attr_name, attr_args); | |
3994 | if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) | |
3995 | c_parser_consume_token (parser); | |
3996 | else | |
3997 | { | |
46c2514e | 3998 | parser->lex_untranslated_string = false; |
27bf414c JM |
3999 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, |
4000 | "expected %<)%>"); | |
4001 | return attrs; | |
4002 | } | |
4003 | attrs = chainon (attrs, attr); | |
4004 | } | |
4005 | if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) | |
4006 | c_parser_consume_token (parser); | |
4007 | else | |
4008 | { | |
46c2514e | 4009 | parser->lex_untranslated_string = false; |
27bf414c JM |
4010 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, |
4011 | "expected %<)%>"); | |
4012 | return attrs; | |
4013 | } | |
4014 | if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) | |
4015 | c_parser_consume_token (parser); | |
4016 | else | |
4017 | { | |
46c2514e | 4018 | parser->lex_untranslated_string = false; |
27bf414c JM |
4019 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, |
4020 | "expected %<)%>"); | |
4021 | return attrs; | |
4022 | } | |
46c2514e | 4023 | parser->lex_untranslated_string = false; |
27bf414c | 4024 | } |
41958c28 | 4025 | |
b72271b9 | 4026 | if (flag_cilkplus && !vec_safe_is_empty (parser->cilk_simd_fn_tokens)) |
41958c28 | 4027 | c_finish_cilk_simd_fn_tokens (parser); |
27bf414c JM |
4028 | return attrs; |
4029 | } | |
4030 | ||
4031 | /* Parse a type name (C90 6.5.5, C99 6.7.6). | |
4032 | ||
4033 | type-name: | |
4034 | specifier-qualifier-list abstract-declarator[opt] | |
4035 | */ | |
4036 | ||
4037 | static struct c_type_name * | |
4038 | c_parser_type_name (c_parser *parser) | |
4039 | { | |
4040 | struct c_declspecs *specs = build_null_declspecs (); | |
4041 | struct c_declarator *declarator; | |
4042 | struct c_type_name *ret; | |
4043 | bool dummy = false; | |
38b7bc7f | 4044 | c_parser_declspecs (parser, specs, false, true, true, false, false, |
568a31f2 | 4045 | cla_prefer_type); |
27bf414c JM |
4046 | if (!specs->declspecs_seen_p) |
4047 | { | |
4048 | c_parser_error (parser, "expected specifier-qualifier-list"); | |
4049 | return NULL; | |
4050 | } | |
29ce73cb PB |
4051 | if (specs->type != error_mark_node) |
4052 | { | |
4053 | pending_xref_error (); | |
4054 | finish_declspecs (specs); | |
4055 | } | |
9e5b2115 PB |
4056 | declarator = c_parser_declarator (parser, |
4057 | specs->typespec_kind != ctsk_none, | |
27bf414c JM |
4058 | C_DTR_ABSTRACT, &dummy); |
4059 | if (declarator == NULL) | |
4060 | return NULL; | |
4061 | ret = XOBNEW (&parser_obstack, struct c_type_name); | |
4062 | ret->specs = specs; | |
4063 | ret->declarator = declarator; | |
4064 | return ret; | |
4065 | } | |
4066 | ||
4067 | /* Parse an initializer (C90 6.5.7, C99 6.7.8). | |
4068 | ||
4069 | initializer: | |
4070 | assignment-expression | |
4071 | { initializer-list } | |
4072 | { initializer-list , } | |
4073 | ||
4074 | initializer-list: | |
4075 | designation[opt] initializer | |
4076 | initializer-list , designation[opt] initializer | |
4077 | ||
4078 | designation: | |
4079 | designator-list = | |
4080 | ||
4081 | designator-list: | |
4082 | designator | |
4083 | designator-list designator | |
4084 | ||
4085 | designator: | |
4086 | array-designator | |
4087 | . identifier | |
4088 | ||
4089 | array-designator: | |
4090 | [ constant-expression ] | |
4091 | ||
4092 | GNU extensions: | |
4093 | ||
4094 | initializer: | |
4095 | { } | |
4096 | ||
4097 | designation: | |
4098 | array-designator | |
4099 | identifier : | |
4100 | ||
4101 | array-designator: | |
4102 | [ constant-expression ... constant-expression ] | |
4103 | ||
4104 | Any expression without commas is accepted in the syntax for the | |
4105 | constant-expressions, with non-constant expressions rejected later. | |
4106 | ||
4107 | This function is only used for top-level initializers; for nested | |
4108 | ones, see c_parser_initval. */ | |
4109 | ||
4110 | static struct c_expr | |
4111 | c_parser_initializer (c_parser *parser) | |
4112 | { | |
4113 | if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) | |
4114 | return c_parser_braced_init (parser, NULL_TREE, false); | |
4115 | else | |
46bdb9cf JM |
4116 | { |
4117 | struct c_expr ret; | |
c2255bc4 | 4118 | location_t loc = c_parser_peek_token (parser)->location; |
46bdb9cf JM |
4119 | ret = c_parser_expr_no_commas (parser, NULL); |
4120 | if (TREE_CODE (ret.value) != STRING_CST | |
4121 | && TREE_CODE (ret.value) != COMPOUND_LITERAL_EXPR) | |
267bac10 | 4122 | ret = convert_lvalue_to_rvalue (loc, ret, true, true); |
46bdb9cf JM |
4123 | return ret; |
4124 | } | |
27bf414c JM |
4125 | } |
4126 | ||
4127 | /* Parse a braced initializer list. TYPE is the type specified for a | |
4128 | compound literal, and NULL_TREE for other initializers and for | |
4129 | nested braced lists. NESTED_P is true for nested braced lists, | |
4130 | false for the list of a compound literal or the list that is the | |
4131 | top-level initializer in a declaration. */ | |
4132 | ||
4133 | static struct c_expr | |
4134 | c_parser_braced_init (c_parser *parser, tree type, bool nested_p) | |
4135 | { | |
a1e3b3d9 LB |
4136 | struct c_expr ret; |
4137 | struct obstack braced_init_obstack; | |
c7412148 | 4138 | location_t brace_loc = c_parser_peek_token (parser)->location; |
a1e3b3d9 | 4139 | gcc_obstack_init (&braced_init_obstack); |
27bf414c JM |
4140 | gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE)); |
4141 | c_parser_consume_token (parser); | |
4142 | if (nested_p) | |
ea58ef42 | 4143 | push_init_level (brace_loc, 0, &braced_init_obstack); |
27bf414c JM |
4144 | else |
4145 | really_start_incremental_init (type); | |
4146 | if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) | |
4147 | { | |
c1771a20 | 4148 | pedwarn (brace_loc, OPT_Wpedantic, "ISO C forbids empty initializer braces"); |
27bf414c JM |
4149 | } |
4150 | else | |
4151 | { | |
4152 | /* Parse a non-empty initializer list, possibly with a trailing | |
4153 | comma. */ | |
4154 | while (true) | |
4155 | { | |
a1e3b3d9 | 4156 | c_parser_initelt (parser, &braced_init_obstack); |
27bf414c JM |
4157 | if (parser->error) |
4158 | break; | |
4159 | if (c_parser_next_token_is (parser, CPP_COMMA)) | |
4160 | c_parser_consume_token (parser); | |
4161 | else | |
4162 | break; | |
4163 | if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) | |
4164 | break; | |
4165 | } | |
4166 | } | |
4167 | if (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE)) | |
4168 | { | |
27bf414c JM |
4169 | ret.value = error_mark_node; |
4170 | ret.original_code = ERROR_MARK; | |
6866c6e8 | 4171 | ret.original_type = NULL; |
27bf414c | 4172 | c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, "expected %<}%>"); |
ea58ef42 | 4173 | pop_init_level (brace_loc, 0, &braced_init_obstack); |
a1e3b3d9 | 4174 | obstack_free (&braced_init_obstack, NULL); |
27bf414c JM |
4175 | return ret; |
4176 | } | |
4177 | c_parser_consume_token (parser); | |
ea58ef42 | 4178 | ret = pop_init_level (brace_loc, 0, &braced_init_obstack); |
a1e3b3d9 LB |
4179 | obstack_free (&braced_init_obstack, NULL); |
4180 | return ret; | |
27bf414c JM |
4181 | } |
4182 | ||
4183 | /* Parse a nested initializer, including designators. */ | |
4184 | ||
4185 | static void | |
a1e3b3d9 | 4186 | c_parser_initelt (c_parser *parser, struct obstack * braced_init_obstack) |
27bf414c JM |
4187 | { |
4188 | /* Parse any designator or designator list. A single array | |
4189 | designator may have the subsequent "=" omitted in GNU C, but a | |
4190 | longer list or a structure member designator may not. */ | |
4191 | if (c_parser_next_token_is (parser, CPP_NAME) | |
4192 | && c_parser_peek_2nd_token (parser)->type == CPP_COLON) | |
4193 | { | |
4194 | /* Old-style structure member designator. */ | |
ea58ef42 MP |
4195 | set_init_label (c_parser_peek_token (parser)->location, |
4196 | c_parser_peek_token (parser)->value, | |
a1e3b3d9 | 4197 | braced_init_obstack); |
fcf73884 | 4198 | /* Use the colon as the error location. */ |
c1771a20 | 4199 | pedwarn (c_parser_peek_2nd_token (parser)->location, OPT_Wpedantic, |
509c9d60 | 4200 | "obsolete use of designated initializer with %<:%>"); |
27bf414c JM |
4201 | c_parser_consume_token (parser); |
4202 | c_parser_consume_token (parser); | |
4203 | } | |
4204 | else | |
4205 | { | |
4206 | /* des_seen is 0 if there have been no designators, 1 if there | |
4207 | has been a single array designator and 2 otherwise. */ | |
4208 | int des_seen = 0; | |
c7412148 | 4209 | /* Location of a designator. */ |
922f2908 | 4210 | location_t des_loc = UNKNOWN_LOCATION; /* Quiet warning. */ |
27bf414c JM |
4211 | while (c_parser_next_token_is (parser, CPP_OPEN_SQUARE) |
4212 | || c_parser_next_token_is (parser, CPP_DOT)) | |
4213 | { | |
4214 | int des_prev = des_seen; | |
c7412148 TT |
4215 | if (!des_seen) |
4216 | des_loc = c_parser_peek_token (parser)->location; | |
27bf414c JM |
4217 | if (des_seen < 2) |
4218 | des_seen++; | |
4219 | if (c_parser_next_token_is (parser, CPP_DOT)) | |
4220 | { | |
4221 | des_seen = 2; | |
4222 | c_parser_consume_token (parser); | |
4223 | if (c_parser_next_token_is (parser, CPP_NAME)) | |
4224 | { | |
ea58ef42 | 4225 | set_init_label (des_loc, c_parser_peek_token (parser)->value, |
a1e3b3d9 | 4226 | braced_init_obstack); |
27bf414c JM |
4227 | c_parser_consume_token (parser); |
4228 | } | |
4229 | else | |
4230 | { | |
4231 | struct c_expr init; | |
4232 | init.value = error_mark_node; | |
4233 | init.original_code = ERROR_MARK; | |
6866c6e8 | 4234 | init.original_type = NULL; |
27bf414c JM |
4235 | c_parser_error (parser, "expected identifier"); |
4236 | c_parser_skip_until_found (parser, CPP_COMMA, NULL); | |
34cf811f MP |
4237 | process_init_element (input_location, init, false, |
4238 | braced_init_obstack); | |
27bf414c JM |
4239 | return; |
4240 | } | |
4241 | } | |
4242 | else | |
4243 | { | |
4244 | tree first, second; | |
922f2908 | 4245 | location_t ellipsis_loc = UNKNOWN_LOCATION; /* Quiet warning. */ |
ea58ef42 | 4246 | location_t array_index_loc = UNKNOWN_LOCATION; |
27bf414c JM |
4247 | /* ??? Following the old parser, [ objc-receiver |
4248 | objc-message-args ] is accepted as an initializer, | |
4249 | being distinguished from a designator by what follows | |
4250 | the first assignment expression inside the square | |
4251 | brackets, but after a first array designator a | |
4252 | subsequent square bracket is for Objective-C taken to | |
4253 | start an expression, using the obsolete form of | |
4254 | designated initializer without '=', rather than | |
4255 | possibly being a second level of designation: in LALR | |
4256 | terms, the '[' is shifted rather than reducing | |
4257 | designator to designator-list. */ | |
4258 | if (des_prev == 1 && c_dialect_objc ()) | |
4259 | { | |
4260 | des_seen = des_prev; | |
4261 | break; | |
4262 | } | |
4263 | if (des_prev == 0 && c_dialect_objc ()) | |
4264 | { | |
4265 | /* This might be an array designator or an | |
4266 | Objective-C message expression. If the former, | |
4267 | continue parsing here; if the latter, parse the | |
4268 | remainder of the initializer given the starting | |
4269 | primary-expression. ??? It might make sense to | |
4270 | distinguish when des_prev == 1 as well; see | |
4271 | previous comment. */ | |
4272 | tree rec, args; | |
4273 | struct c_expr mexpr; | |
4274 | c_parser_consume_token (parser); | |
4275 | if (c_parser_peek_token (parser)->type == CPP_NAME | |
4276 | && ((c_parser_peek_token (parser)->id_kind | |
4277 | == C_ID_TYPENAME) | |
4278 | || (c_parser_peek_token (parser)->id_kind | |
4279 | == C_ID_CLASSNAME))) | |
4280 | { | |
4281 | /* Type name receiver. */ | |
4282 | tree id = c_parser_peek_token (parser)->value; | |
4283 | c_parser_consume_token (parser); | |
4284 | rec = objc_get_class_reference (id); | |
4285 | goto parse_message_args; | |
4286 | } | |
4287 | first = c_parser_expr_no_commas (parser, NULL).value; | |
ebfbbdc5 | 4288 | mark_exp_read (first); |
27bf414c JM |
4289 | if (c_parser_next_token_is (parser, CPP_ELLIPSIS) |
4290 | || c_parser_next_token_is (parser, CPP_CLOSE_SQUARE)) | |
4291 | goto array_desig_after_first; | |
4292 | /* Expression receiver. So far only one part | |
4293 | without commas has been parsed; there might be | |
4294 | more of the expression. */ | |
4295 | rec = first; | |
4296 | while (c_parser_next_token_is (parser, CPP_COMMA)) | |
4297 | { | |
f2a71bbc | 4298 | struct c_expr next; |
c2255bc4 AH |
4299 | location_t comma_loc, exp_loc; |
4300 | comma_loc = c_parser_peek_token (parser)->location; | |
27bf414c | 4301 | c_parser_consume_token (parser); |
c2255bc4 | 4302 | exp_loc = c_parser_peek_token (parser)->location; |
f2a71bbc | 4303 | next = c_parser_expr_no_commas (parser, NULL); |
267bac10 JM |
4304 | next = convert_lvalue_to_rvalue (exp_loc, next, |
4305 | true, true); | |
c2255bc4 | 4306 | rec = build_compound_expr (comma_loc, rec, next.value); |
27bf414c JM |
4307 | } |
4308 | parse_message_args: | |
4309 | /* Now parse the objc-message-args. */ | |
4310 | args = c_parser_objc_message_args (parser); | |
4311 | c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, | |
4312 | "expected %<]%>"); | |
4313 | mexpr.value | |
eb345401 | 4314 | = objc_build_message_expr (rec, args); |
27bf414c | 4315 | mexpr.original_code = ERROR_MARK; |
6866c6e8 | 4316 | mexpr.original_type = NULL; |
27bf414c JM |
4317 | /* Now parse and process the remainder of the |
4318 | initializer, starting with this message | |
4319 | expression as a primary-expression. */ | |
a1e3b3d9 | 4320 | c_parser_initval (parser, &mexpr, braced_init_obstack); |
27bf414c JM |
4321 | return; |
4322 | } | |
4323 | c_parser_consume_token (parser); | |
ea58ef42 | 4324 | array_index_loc = c_parser_peek_token (parser)->location; |
27bf414c | 4325 | first = c_parser_expr_no_commas (parser, NULL).value; |
ebfbbdc5 | 4326 | mark_exp_read (first); |
27bf414c JM |
4327 | array_desig_after_first: |
4328 | if (c_parser_next_token_is (parser, CPP_ELLIPSIS)) | |
4329 | { | |
c7412148 | 4330 | ellipsis_loc = c_parser_peek_token (parser)->location; |
27bf414c JM |
4331 | c_parser_consume_token (parser); |
4332 | second = c_parser_expr_no_commas (parser, NULL).value; | |
ebfbbdc5 | 4333 | mark_exp_read (second); |
27bf414c JM |
4334 | } |
4335 | else | |
4336 | second = NULL_TREE; | |
4337 | if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE)) | |
4338 | { | |
4339 | c_parser_consume_token (parser); | |
ea58ef42 MP |
4340 | set_init_index (array_index_loc, first, second, |
4341 | braced_init_obstack); | |
fcf73884 | 4342 | if (second) |
c1771a20 | 4343 | pedwarn (ellipsis_loc, OPT_Wpedantic, |
509c9d60 | 4344 | "ISO C forbids specifying range of elements to initialize"); |
27bf414c JM |
4345 | } |
4346 | else | |
4347 | c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, | |
4348 | "expected %<]%>"); | |
4349 | } | |
4350 | } | |
4351 | if (des_seen >= 1) | |
4352 | { | |
4353 | if (c_parser_next_token_is (parser, CPP_EQ)) | |
4354 | { | |
f3bede71 MP |
4355 | pedwarn_c90 (des_loc, OPT_Wpedantic, |
4356 | "ISO C90 forbids specifying subobject " | |
4357 | "to initialize"); | |
27bf414c JM |
4358 | c_parser_consume_token (parser); |
4359 | } | |
4360 | else | |
4361 | { | |
4362 | if (des_seen == 1) | |
c1771a20 | 4363 | pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic, |
509c9d60 | 4364 | "obsolete use of designated initializer without %<=%>"); |
27bf414c JM |
4365 | else |
4366 | { | |
4367 | struct c_expr init; | |
4368 | init.value = error_mark_node; | |
4369 | init.original_code = ERROR_MARK; | |
6866c6e8 | 4370 | init.original_type = NULL; |
27bf414c JM |
4371 | c_parser_error (parser, "expected %<=%>"); |
4372 | c_parser_skip_until_found (parser, CPP_COMMA, NULL); | |
34cf811f MP |
4373 | process_init_element (input_location, init, false, |
4374 | braced_init_obstack); | |
27bf414c JM |
4375 | return; |
4376 | } | |
4377 | } | |
4378 | } | |
4379 | } | |
a1e3b3d9 | 4380 | c_parser_initval (parser, NULL, braced_init_obstack); |
27bf414c JM |
4381 | } |
4382 | ||
4383 | /* Parse a nested initializer; as c_parser_initializer but parses | |
4384 | initializers within braced lists, after any designators have been | |
4385 | applied. If AFTER is not NULL then it is an Objective-C message | |
4386 | expression which is the primary-expression starting the | |
4387 | initializer. */ | |
4388 | ||
4389 | static void | |
a1e3b3d9 LB |
4390 | c_parser_initval (c_parser *parser, struct c_expr *after, |
4391 | struct obstack * braced_init_obstack) | |
27bf414c JM |
4392 | { |
4393 | struct c_expr init; | |
4394 | gcc_assert (!after || c_dialect_objc ()); | |
34cf811f MP |
4395 | location_t loc = c_parser_peek_token (parser)->location; |
4396 | ||
27bf414c JM |
4397 | if (c_parser_next_token_is (parser, CPP_OPEN_BRACE) && !after) |
4398 | init = c_parser_braced_init (parser, NULL_TREE, true); | |
4399 | else | |
46bdb9cf JM |
4400 | { |
4401 | init = c_parser_expr_no_commas (parser, after); | |
4402 | if (init.value != NULL_TREE | |
4403 | && TREE_CODE (init.value) != STRING_CST | |
4404 | && TREE_CODE (init.value) != COMPOUND_LITERAL_EXPR) | |
267bac10 | 4405 | init = convert_lvalue_to_rvalue (loc, init, true, true); |
46bdb9cf | 4406 | } |
34cf811f | 4407 | process_init_element (loc, init, false, braced_init_obstack); |
27bf414c JM |
4408 | } |
4409 | ||
4410 | /* Parse a compound statement (possibly a function body) (C90 6.6.2, | |
4411 | C99 6.8.2). | |
4412 | ||
4413 | compound-statement: | |
4414 | { block-item-list[opt] } | |
4415 | { label-declarations block-item-list } | |
4416 | ||
4417 | block-item-list: | |
4418 | block-item | |
4419 | block-item-list block-item | |
4420 | ||
4421 | block-item: | |
4422 | nested-declaration | |
4423 | statement | |
4424 | ||
4425 | nested-declaration: | |
4426 | declaration | |
4427 | ||
4428 | GNU extensions: | |
4429 | ||
4430 | compound-statement: | |
4431 | { label-declarations block-item-list } | |
4432 | ||
4433 | nested-declaration: | |
4434 | __extension__ nested-declaration | |
4435 | nested-function-definition | |
4436 | ||
4437 | label-declarations: | |
4438 | label-declaration | |
4439 | label-declarations label-declaration | |
4440 | ||
4441 | label-declaration: | |
4442 | __label__ identifier-list ; | |
4443 | ||
4444 | Allowing the mixing of declarations and code is new in C99. The | |
4445 | GNU syntax also permits (not shown above) labels at the end of | |
4446 | compound statements, which yield an error. We don't allow labels | |
4447 | on declarations; this might seem like a natural extension, but | |
4448 | there would be a conflict between attributes on the label and | |
4449 | prefix attributes on the declaration. ??? The syntax follows the | |
4450 | old parser in requiring something after label declarations. | |
4451 | Although they are erroneous if the labels declared aren't defined, | |
953ff289 | 4452 | is it useful for the syntax to be this way? |
b8698a0f | 4453 | |
953ff289 | 4454 | OpenMP: |
b8698a0f | 4455 | |
953ff289 DN |
4456 | block-item: |
4457 | openmp-directive | |
4458 | ||
4459 | openmp-directive: | |
4460 | barrier-directive | |
acf0174b JJ |
4461 | flush-directive |
4462 | taskwait-directive | |
4463 | taskyield-directive | |
4464 | cancel-directive | |
4465 | cancellation-point-directive */ | |
27bf414c JM |
4466 | |
4467 | static tree | |
4468 | c_parser_compound_statement (c_parser *parser) | |
4469 | { | |
4470 | tree stmt; | |
c2255bc4 AH |
4471 | location_t brace_loc; |
4472 | brace_loc = c_parser_peek_token (parser)->location; | |
27bf414c | 4473 | if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>")) |
5600f233 JM |
4474 | { |
4475 | /* Ensure a scope is entered and left anyway to avoid confusion | |
4476 | if we have just prepared to enter a function body. */ | |
4477 | stmt = c_begin_compound_stmt (true); | |
c2255bc4 | 4478 | c_end_compound_stmt (brace_loc, stmt, true); |
5600f233 JM |
4479 | return error_mark_node; |
4480 | } | |
27bf414c JM |
4481 | stmt = c_begin_compound_stmt (true); |
4482 | c_parser_compound_statement_nostart (parser); | |
36536d79 BI |
4483 | |
4484 | /* If the compound stmt contains array notations, then we expand them. */ | |
b72271b9 | 4485 | if (flag_cilkplus && contains_array_notation_expr (stmt)) |
36536d79 | 4486 | stmt = expand_array_notation_exprs (stmt); |
c2255bc4 | 4487 | return c_end_compound_stmt (brace_loc, stmt, true); |
27bf414c JM |
4488 | } |
4489 | ||
4490 | /* Parse a compound statement except for the opening brace. This is | |
4491 | used for parsing both compound statements and statement expressions | |
4492 | (which follow different paths to handling the opening). */ | |
4493 | ||
4494 | static void | |
4495 | c_parser_compound_statement_nostart (c_parser *parser) | |
4496 | { | |
4497 | bool last_stmt = false; | |
4498 | bool last_label = false; | |
6ec637a4 | 4499 | bool save_valid_for_pragma = valid_location_for_stdc_pragma_p (); |
3ba09659 | 4500 | location_t label_loc = UNKNOWN_LOCATION; /* Quiet warning. */ |
27bf414c JM |
4501 | if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) |
4502 | { | |
4503 | c_parser_consume_token (parser); | |
4504 | return; | |
4505 | } | |
6ec637a4 | 4506 | mark_valid_location_for_stdc_pragma (true); |
27bf414c JM |
4507 | if (c_parser_next_token_is_keyword (parser, RID_LABEL)) |
4508 | { | |
4509 | /* Read zero or more forward-declarations for labels that nested | |
4510 | functions can jump to. */ | |
6ec637a4 | 4511 | mark_valid_location_for_stdc_pragma (false); |
27bf414c JM |
4512 | while (c_parser_next_token_is_keyword (parser, RID_LABEL)) |
4513 | { | |
c2255bc4 | 4514 | label_loc = c_parser_peek_token (parser)->location; |
27bf414c JM |
4515 | c_parser_consume_token (parser); |
4516 | /* Any identifiers, including those declared as type names, | |
4517 | are OK here. */ | |
4518 | while (true) | |
4519 | { | |
4520 | tree label; | |
4521 | if (c_parser_next_token_is_not (parser, CPP_NAME)) | |
4522 | { | |
4523 | c_parser_error (parser, "expected identifier"); | |
4524 | break; | |
4525 | } | |
4526 | label | |
4527 | = declare_label (c_parser_peek_token (parser)->value); | |
4528 | C_DECLARED_LABEL_FLAG (label) = 1; | |
c2255bc4 | 4529 | add_stmt (build_stmt (label_loc, DECL_EXPR, label)); |
27bf414c JM |
4530 | c_parser_consume_token (parser); |
4531 | if (c_parser_next_token_is (parser, CPP_COMMA)) | |
4532 | c_parser_consume_token (parser); | |
4533 | else | |
4534 | break; | |
4535 | } | |
4536 | c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); | |
4537 | } | |
c1771a20 | 4538 | pedwarn (label_loc, OPT_Wpedantic, "ISO C forbids label declarations"); |
27bf414c JM |
4539 | } |
4540 | /* We must now have at least one statement, label or declaration. */ | |
4541 | if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) | |
4542 | { | |
6ec637a4 | 4543 | mark_valid_location_for_stdc_pragma (save_valid_for_pragma); |
27bf414c JM |
4544 | c_parser_error (parser, "expected declaration or statement"); |
4545 | c_parser_consume_token (parser); | |
4546 | return; | |
4547 | } | |
4548 | while (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE)) | |
4549 | { | |
4550 | location_t loc = c_parser_peek_token (parser)->location; | |
27bf414c JM |
4551 | if (c_parser_next_token_is_keyword (parser, RID_CASE) |
4552 | || c_parser_next_token_is_keyword (parser, RID_DEFAULT) | |
4553 | || (c_parser_next_token_is (parser, CPP_NAME) | |
4554 | && c_parser_peek_2nd_token (parser)->type == CPP_COLON)) | |
4555 | { | |
c7412148 TT |
4556 | if (c_parser_next_token_is_keyword (parser, RID_CASE)) |
4557 | label_loc = c_parser_peek_2nd_token (parser)->location; | |
4558 | else | |
4559 | label_loc = c_parser_peek_token (parser)->location; | |
27bf414c JM |
4560 | last_label = true; |
4561 | last_stmt = false; | |
6ec637a4 | 4562 | mark_valid_location_for_stdc_pragma (false); |
27bf414c JM |
4563 | c_parser_label (parser); |
4564 | } | |
4565 | else if (!last_label | |
2f413185 | 4566 | && c_parser_next_tokens_start_declaration (parser)) |
27bf414c JM |
4567 | { |
4568 | last_label = false; | |
6ec637a4 | 4569 | mark_valid_location_for_stdc_pragma (false); |
acf0174b JJ |
4570 | c_parser_declaration_or_fndef (parser, true, true, true, true, |
4571 | true, NULL, vNULL); | |
fcf73884 | 4572 | if (last_stmt) |
f3bede71 MP |
4573 | pedwarn_c90 (loc, (pedantic && !flag_isoc99) |
4574 | ? OPT_Wpedantic | |
4575 | : OPT_Wdeclaration_after_statement, | |
509c9d60 | 4576 | "ISO C90 forbids mixed declarations and code"); |
27bf414c JM |
4577 | last_stmt = false; |
4578 | } | |
4579 | else if (!last_label | |
4580 | && c_parser_next_token_is_keyword (parser, RID_EXTENSION)) | |
4581 | { | |
4582 | /* __extension__ can start a declaration, but is also an | |
4583 | unary operator that can start an expression. Consume all | |
4584 | but the last of a possible series of __extension__ to | |
4585 | determine which. */ | |
4586 | while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD | |
4587 | && (c_parser_peek_2nd_token (parser)->keyword | |
4588 | == RID_EXTENSION)) | |
4589 | c_parser_consume_token (parser); | |
32912286 | 4590 | if (c_token_starts_declaration (c_parser_peek_2nd_token (parser))) |
27bf414c JM |
4591 | { |
4592 | int ext; | |
4593 | ext = disable_extension_diagnostics (); | |
4594 | c_parser_consume_token (parser); | |
4595 | last_label = false; | |
6ec637a4 | 4596 | mark_valid_location_for_stdc_pragma (false); |
32912286 | 4597 | c_parser_declaration_or_fndef (parser, true, true, true, true, |
acf0174b | 4598 | true, NULL, vNULL); |
27bf414c JM |
4599 | /* Following the old parser, __extension__ does not |
4600 | disable this diagnostic. */ | |
4601 | restore_extension_diagnostics (ext); | |
fcf73884 | 4602 | if (last_stmt) |
509c9d60 | 4603 | pedwarn_c90 (loc, (pedantic && !flag_isoc99) |
f3bede71 MP |
4604 | ? OPT_Wpedantic |
4605 | : OPT_Wdeclaration_after_statement, | |
509c9d60 | 4606 | "ISO C90 forbids mixed declarations and code"); |
27bf414c JM |
4607 | last_stmt = false; |
4608 | } | |
4609 | else | |
4610 | goto statement; | |
4611 | } | |
bc4071dd RH |
4612 | else if (c_parser_next_token_is (parser, CPP_PRAGMA)) |
4613 | { | |
4614 | /* External pragmas, and some omp pragmas, are not associated | |
4615 | with regular c code, and so are not to be considered statements | |
4616 | syntactically. This ensures that the user doesn't put them | |
4617 | places that would turn into syntax errors if the directive | |
4618 | were ignored. */ | |
4619 | if (c_parser_pragma (parser, pragma_compound)) | |
4620 | last_label = false, last_stmt = true; | |
4621 | } | |
4622 | else if (c_parser_next_token_is (parser, CPP_EOF)) | |
4623 | { | |
6ec637a4 | 4624 | mark_valid_location_for_stdc_pragma (save_valid_for_pragma); |
bc4071dd RH |
4625 | c_parser_error (parser, "expected declaration or statement"); |
4626 | return; | |
4627 | } | |
b4b56033 MLI |
4628 | else if (c_parser_next_token_is_keyword (parser, RID_ELSE)) |
4629 | { | |
b8698a0f | 4630 | if (parser->in_if_block) |
b4b56033 | 4631 | { |
6ec637a4 | 4632 | mark_valid_location_for_stdc_pragma (save_valid_for_pragma); |
3ba09659 | 4633 | error_at (loc, """expected %<}%> before %<else%>"); |
b4b56033 MLI |
4634 | return; |
4635 | } | |
b8698a0f | 4636 | else |
b4b56033 | 4637 | { |
3ba09659 | 4638 | error_at (loc, "%<else%> without a previous %<if%>"); |
b4b56033 MLI |
4639 | c_parser_consume_token (parser); |
4640 | continue; | |
4641 | } | |
4642 | } | |
27bf414c JM |
4643 | else |
4644 | { | |
4645 | statement: | |
4646 | last_label = false; | |
4647 | last_stmt = true; | |
6ec637a4 | 4648 | mark_valid_location_for_stdc_pragma (false); |
27bf414c JM |
4649 | c_parser_statement_after_labels (parser); |
4650 | } | |
2c14ae9a VR |
4651 | |
4652 | parser->error = false; | |
27bf414c JM |
4653 | } |
4654 | if (last_label) | |
3ba09659 | 4655 | error_at (label_loc, "label at end of compound statement"); |
27bf414c | 4656 | c_parser_consume_token (parser); |
6ec637a4 JJ |
4657 | /* Restore the value we started with. */ |
4658 | mark_valid_location_for_stdc_pragma (save_valid_for_pragma); | |
27bf414c JM |
4659 | } |
4660 | ||
4661 | /* Parse a label (C90 6.6.1, C99 6.8.1). | |
4662 | ||
4663 | label: | |
4664 | identifier : attributes[opt] | |
4665 | case constant-expression : | |
4666 | default : | |
4667 | ||
4668 | GNU extensions: | |
4669 | ||
4670 | label: | |
4671 | case constant-expression ... constant-expression : | |
4672 | ||
4673 | The use of attributes on labels is a GNU extension. The syntax in | |
4674 | GNU C accepts any expressions without commas, non-constant | |
4675 | expressions being rejected later. */ | |
4676 | ||
4677 | static void | |
4678 | c_parser_label (c_parser *parser) | |
4679 | { | |
4680 | location_t loc1 = c_parser_peek_token (parser)->location; | |
4681 | tree label = NULL_TREE; | |
4682 | if (c_parser_next_token_is_keyword (parser, RID_CASE)) | |
4683 | { | |
4684 | tree exp1, exp2; | |
4685 | c_parser_consume_token (parser); | |
4686 | exp1 = c_parser_expr_no_commas (parser, NULL).value; | |
4687 | if (c_parser_next_token_is (parser, CPP_COLON)) | |
4688 | { | |
4689 | c_parser_consume_token (parser); | |
c2255bc4 | 4690 | label = do_case (loc1, exp1, NULL_TREE); |
27bf414c JM |
4691 | } |
4692 | else if (c_parser_next_token_is (parser, CPP_ELLIPSIS)) | |
4693 | { | |
4694 | c_parser_consume_token (parser); | |
4695 | exp2 = c_parser_expr_no_commas (parser, NULL).value; | |
4696 | if (c_parser_require (parser, CPP_COLON, "expected %<:%>")) | |
c2255bc4 | 4697 | label = do_case (loc1, exp1, exp2); |
27bf414c JM |
4698 | } |
4699 | else | |
4700 | c_parser_error (parser, "expected %<:%> or %<...%>"); | |
4701 | } | |
4702 | else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT)) | |
4703 | { | |
4704 | c_parser_consume_token (parser); | |
4705 | if (c_parser_require (parser, CPP_COLON, "expected %<:%>")) | |
c2255bc4 | 4706 | label = do_case (loc1, NULL_TREE, NULL_TREE); |
27bf414c JM |
4707 | } |
4708 | else | |
4709 | { | |
4710 | tree name = c_parser_peek_token (parser)->value; | |
4711 | tree tlab; | |
27bf414c | 4712 | tree attrs; |
c7412148 | 4713 | location_t loc2 = c_parser_peek_token (parser)->location; |
27bf414c JM |
4714 | gcc_assert (c_parser_next_token_is (parser, CPP_NAME)); |
4715 | c_parser_consume_token (parser); | |
4716 | gcc_assert (c_parser_next_token_is (parser, CPP_COLON)); | |
27bf414c JM |
4717 | c_parser_consume_token (parser); |
4718 | attrs = c_parser_attributes (parser); | |
4719 | tlab = define_label (loc2, name); | |
4720 | if (tlab) | |
4721 | { | |
4722 | decl_attributes (&tlab, attrs, 0); | |
c2255bc4 | 4723 | label = add_stmt (build_stmt (loc1, LABEL_EXPR, tlab)); |
27bf414c JM |
4724 | } |
4725 | } | |
4726 | if (label) | |
3d57f0f0 | 4727 | { |
2f413185 | 4728 | if (c_parser_next_tokens_start_declaration (parser)) |
3d57f0f0 | 4729 | { |
3ba09659 AH |
4730 | error_at (c_parser_peek_token (parser)->location, |
4731 | "a label can only be part of a statement and " | |
4732 | "a declaration is not a statement"); | |
b8698a0f | 4733 | c_parser_declaration_or_fndef (parser, /*fndef_ok*/ false, |
32912286 | 4734 | /*static_assert_ok*/ true, |
6265d07c | 4735 | /*empty_ok*/ true, /*nested*/ true, |
acf0174b JJ |
4736 | /*start_attr_ok*/ true, NULL, |
4737 | vNULL); | |
3d57f0f0 MLI |
4738 | } |
4739 | } | |
27bf414c JM |
4740 | } |
4741 | ||
4742 | /* Parse a statement (C90 6.6, C99 6.8). | |
4743 | ||
4744 | statement: | |
4745 | labeled-statement | |
4746 | compound-statement | |
4747 | expression-statement | |
4748 | selection-statement | |
4749 | iteration-statement | |
4750 | jump-statement | |
4751 | ||
4752 | labeled-statement: | |
4753 | label statement | |
4754 | ||
4755 | expression-statement: | |
4756 | expression[opt] ; | |
4757 | ||
4758 | selection-statement: | |
4759 | if-statement | |
4760 | switch-statement | |
4761 | ||
4762 | iteration-statement: | |
4763 | while-statement | |
4764 | do-statement | |
4765 | for-statement | |
4766 | ||
4767 | jump-statement: | |
4768 | goto identifier ; | |
4769 | continue ; | |
4770 | break ; | |
4771 | return expression[opt] ; | |
4772 | ||
4773 | GNU extensions: | |
4774 | ||
4775 | statement: | |
4776 | asm-statement | |
4777 | ||
4778 | jump-statement: | |
4779 | goto * expression ; | |
4780 | ||
4781 | Objective-C: | |
4782 | ||
4783 | statement: | |
4784 | objc-throw-statement | |
4785 | objc-try-catch-statement | |
4786 | objc-synchronized-statement | |
4787 | ||
4788 | objc-throw-statement: | |
4789 | @throw expression ; | |
4790 | @throw ; | |
953ff289 DN |
4791 | |
4792 | OpenMP: | |
4793 | ||
4794 | statement: | |
4795 | openmp-construct | |
4796 | ||
4797 | openmp-construct: | |
4798 | parallel-construct | |
4799 | for-construct | |
acf0174b JJ |
4800 | simd-construct |
4801 | for-simd-construct | |
953ff289 DN |
4802 | sections-construct |
4803 | single-construct | |
4804 | parallel-for-construct | |
acf0174b | 4805 | parallel-for-simd-construct |
953ff289 DN |
4806 | parallel-sections-construct |
4807 | master-construct | |
4808 | critical-construct | |
4809 | atomic-construct | |
4810 | ordered-construct | |
4811 | ||
4812 | parallel-construct: | |
4813 | parallel-directive structured-block | |
4814 | ||
4815 | for-construct: | |
4816 | for-directive iteration-statement | |
4817 | ||
acf0174b JJ |
4818 | simd-construct: |
4819 | simd-directive iteration-statements | |
4820 | ||
4821 | for-simd-construct: | |
4822 | for-simd-directive iteration-statements | |
4823 | ||
953ff289 DN |
4824 | sections-construct: |
4825 | sections-directive section-scope | |
4826 | ||
4827 | single-construct: | |
4828 | single-directive structured-block | |
4829 | ||
4830 | parallel-for-construct: | |
4831 | parallel-for-directive iteration-statement | |
4832 | ||
acf0174b JJ |
4833 | parallel-for-simd-construct: |
4834 | parallel-for-simd-directive iteration-statement | |
4835 | ||
953ff289 DN |
4836 | parallel-sections-construct: |
4837 | parallel-sections-directive section-scope | |
4838 | ||
4839 | master-construct: | |
4840 | master-directive structured-block | |
4841 | ||
4842 | critical-construct: | |
4843 | critical-directive structured-block | |
4844 | ||
4845 | atomic-construct: | |
4846 | atomic-directive expression-statement | |
4847 | ||
4848 | ordered-construct: | |
0a35513e AH |
4849 | ordered-directive structured-block |
4850 | ||
4851 | Transactional Memory: | |
4852 | ||
4853 | statement: | |
4854 | transaction-statement | |
4855 | transaction-cancel-statement | |
4856 | */ | |
27bf414c JM |
4857 | |
4858 | static void | |
4859 | c_parser_statement (c_parser *parser) | |
4860 | { | |
4861 | while (c_parser_next_token_is_keyword (parser, RID_CASE) | |
4862 | || c_parser_next_token_is_keyword (parser, RID_DEFAULT) | |
4863 | || (c_parser_next_token_is (parser, CPP_NAME) | |
4864 | && c_parser_peek_2nd_token (parser)->type == CPP_COLON)) | |
4865 | c_parser_label (parser); | |
4866 | c_parser_statement_after_labels (parser); | |
4867 | } | |
4868 | ||
4869 | /* Parse a statement, other than a labeled statement. */ | |
4870 | ||
4871 | static void | |
4872 | c_parser_statement_after_labels (c_parser *parser) | |
4873 | { | |
4874 | location_t loc = c_parser_peek_token (parser)->location; | |
4875 | tree stmt = NULL_TREE; | |
b4b56033 MLI |
4876 | bool in_if_block = parser->in_if_block; |
4877 | parser->in_if_block = false; | |
27bf414c JM |
4878 | switch (c_parser_peek_token (parser)->type) |
4879 | { | |
4880 | case CPP_OPEN_BRACE: | |
4881 | add_stmt (c_parser_compound_statement (parser)); | |
4882 | break; | |
4883 | case CPP_KEYWORD: | |
4884 | switch (c_parser_peek_token (parser)->keyword) | |
4885 | { | |
4886 | case RID_IF: | |
4887 | c_parser_if_statement (parser); | |
4888 | break; | |
4889 | case RID_SWITCH: | |
4890 | c_parser_switch_statement (parser); | |
4891 | break; | |
4892 | case RID_WHILE: | |
d4af74d4 | 4893 | c_parser_while_statement (parser, false); |
27bf414c JM |
4894 | break; |
4895 | case RID_DO: | |
d4af74d4 | 4896 | c_parser_do_statement (parser, false); |
27bf414c JM |
4897 | break; |
4898 | case RID_FOR: | |
8170608b | 4899 | c_parser_for_statement (parser, false); |
27bf414c | 4900 | break; |
939b37da BI |
4901 | case RID_CILK_SYNC: |
4902 | c_parser_consume_token (parser); | |
4903 | c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); | |
b72271b9 | 4904 | if (!flag_cilkplus) |
939b37da BI |
4905 | error_at (loc, "-fcilkplus must be enabled to use %<_Cilk_sync%>"); |
4906 | else | |
4907 | add_stmt (build_cilk_sync ()); | |
4908 | break; | |
27bf414c JM |
4909 | case RID_GOTO: |
4910 | c_parser_consume_token (parser); | |
4911 | if (c_parser_next_token_is (parser, CPP_NAME)) | |
4912 | { | |
c2255bc4 AH |
4913 | stmt = c_finish_goto_label (loc, |
4914 | c_parser_peek_token (parser)->value); | |
27bf414c JM |
4915 | c_parser_consume_token (parser); |
4916 | } | |
4917 | else if (c_parser_next_token_is (parser, CPP_MULT)) | |
4918 | { | |
267bac10 | 4919 | struct c_expr val; |
84628aa8 | 4920 | |
27bf414c | 4921 | c_parser_consume_token (parser); |
267bac10 JM |
4922 | val = c_parser_expression (parser); |
4923 | val = convert_lvalue_to_rvalue (loc, val, false, true); | |
4924 | stmt = c_finish_goto_ptr (loc, val.value); | |
27bf414c JM |
4925 | } |
4926 | else | |
4927 | c_parser_error (parser, "expected identifier or %<*%>"); | |
4928 | goto expect_semicolon; | |
4929 | case RID_CONTINUE: | |
4930 | c_parser_consume_token (parser); | |
c2255bc4 | 4931 | stmt = c_finish_bc_stmt (loc, &c_cont_label, false); |
27bf414c JM |
4932 | goto expect_semicolon; |
4933 | case RID_BREAK: | |
4934 | c_parser_consume_token (parser); | |
c2255bc4 | 4935 | stmt = c_finish_bc_stmt (loc, &c_break_label, true); |
27bf414c JM |
4936 | goto expect_semicolon; |
4937 | case RID_RETURN: | |
4938 | c_parser_consume_token (parser); | |
4939 | if (c_parser_next_token_is (parser, CPP_SEMICOLON)) | |
4940 | { | |
c2255bc4 | 4941 | stmt = c_finish_return (loc, NULL_TREE, NULL_TREE); |
27bf414c JM |
4942 | c_parser_consume_token (parser); |
4943 | } | |
4944 | else | |
4945 | { | |
6e07c515 | 4946 | location_t xloc = c_parser_peek_token (parser)->location; |
bbbbb16a | 4947 | struct c_expr expr = c_parser_expression_conv (parser); |
ebfbbdc5 | 4948 | mark_exp_read (expr.value); |
6e07c515 | 4949 | stmt = c_finish_return (xloc, expr.value, expr.original_type); |
27bf414c JM |
4950 | goto expect_semicolon; |
4951 | } | |
4952 | break; | |
4953 | case RID_ASM: | |
4954 | stmt = c_parser_asm_statement (parser); | |
4955 | break; | |
0a35513e AH |
4956 | case RID_TRANSACTION_ATOMIC: |
4957 | case RID_TRANSACTION_RELAXED: | |
4958 | stmt = c_parser_transaction (parser, | |
4959 | c_parser_peek_token (parser)->keyword); | |
4960 | break; | |
4961 | case RID_TRANSACTION_CANCEL: | |
4962 | stmt = c_parser_transaction_cancel (parser); | |
4963 | goto expect_semicolon; | |
49b91f05 | 4964 | case RID_AT_THROW: |
27bf414c JM |
4965 | gcc_assert (c_dialect_objc ()); |
4966 | c_parser_consume_token (parser); | |
4967 | if (c_parser_next_token_is (parser, CPP_SEMICOLON)) | |
4968 | { | |
c2255bc4 | 4969 | stmt = objc_build_throw_stmt (loc, NULL_TREE); |
27bf414c JM |
4970 | c_parser_consume_token (parser); |
4971 | } | |
4972 | else | |
4973 | { | |
267bac10 JM |
4974 | struct c_expr expr = c_parser_expression (parser); |
4975 | expr = convert_lvalue_to_rvalue (loc, expr, false, false); | |
4976 | expr.value = c_fully_fold (expr.value, false, NULL); | |
4977 | stmt = objc_build_throw_stmt (loc, expr.value); | |
27bf414c JM |
4978 | goto expect_semicolon; |
4979 | } | |
4980 | break; | |
49b91f05 | 4981 | case RID_AT_TRY: |
27bf414c | 4982 | gcc_assert (c_dialect_objc ()); |
437c2322 | 4983 | c_parser_objc_try_catch_finally_statement (parser); |
27bf414c JM |
4984 | break; |
4985 | case RID_AT_SYNCHRONIZED: | |
4986 | gcc_assert (c_dialect_objc ()); | |
4987 | c_parser_objc_synchronized_statement (parser); | |
4988 | break; | |
4989 | default: | |
4990 | goto expr_stmt; | |
4991 | } | |
4992 | break; | |
4993 | case CPP_SEMICOLON: | |
4994 | c_parser_consume_token (parser); | |
4995 | break; | |
4996 | case CPP_CLOSE_PAREN: | |
4997 | case CPP_CLOSE_SQUARE: | |
4998 | /* Avoid infinite loop in error recovery: | |
4999 | c_parser_skip_until_found stops at a closing nesting | |
5000 | delimiter without consuming it, but here we need to consume | |
5001 | it to proceed further. */ | |
5002 | c_parser_error (parser, "expected statement"); | |
5003 | c_parser_consume_token (parser); | |
5004 | break; | |
bc4071dd RH |
5005 | case CPP_PRAGMA: |
5006 | c_parser_pragma (parser, pragma_stmt); | |
5007 | break; | |
27bf414c JM |
5008 | default: |
5009 | expr_stmt: | |
c2255bc4 | 5010 | stmt = c_finish_expr_stmt (loc, c_parser_expression_conv (parser).value); |
27bf414c JM |
5011 | expect_semicolon: |
5012 | c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); | |
5013 | break; | |
5014 | } | |
5015 | /* Two cases cannot and do not have line numbers associated: If stmt | |
5016 | is degenerate, such as "2;", then stmt is an INTEGER_CST, which | |
5017 | cannot hold line numbers. But that's OK because the statement | |
5018 | will either be changed to a MODIFY_EXPR during gimplification of | |
5019 | the statement expr, or discarded. If stmt was compound, but | |
5020 | without new variables, we will have skipped the creation of a | |
5021 | BIND and will have a bare STATEMENT_LIST. But that's OK because | |
5022 | (recursively) all of the component statements should already have | |
5023 | line numbers assigned. ??? Can we discard no-op statements | |
5024 | earlier? */ | |
c2255bc4 AH |
5025 | if (CAN_HAVE_LOCATION_P (stmt) |
5026 | && EXPR_LOCATION (stmt) == UNKNOWN_LOCATION) | |
5027 | SET_EXPR_LOCATION (stmt, loc); | |
b4b56033 MLI |
5028 | |
5029 | parser->in_if_block = in_if_block; | |
27bf414c JM |
5030 | } |
5031 | ||
ca085fd7 MLI |
5032 | /* Parse the condition from an if, do, while or for statements. */ |
5033 | ||
5034 | static tree | |
5035 | c_parser_condition (c_parser *parser) | |
5036 | { | |
c2255bc4 | 5037 | location_t loc = c_parser_peek_token (parser)->location; |
ca085fd7 | 5038 | tree cond; |
928c19bb JM |
5039 | cond = c_parser_expression_conv (parser).value; |
5040 | cond = c_objc_common_truthvalue_conversion (loc, cond); | |
5041 | cond = c_fully_fold (cond, false, NULL); | |
ca085fd7 MLI |
5042 | if (warn_sequence_point) |
5043 | verify_sequence_points (cond); | |
5044 | return cond; | |
5045 | } | |
5046 | ||
27bf414c JM |
5047 | /* Parse a parenthesized condition from an if, do or while statement. |
5048 | ||
5049 | condition: | |
5050 | ( expression ) | |
5051 | */ | |
5052 | static tree | |
5053 | c_parser_paren_condition (c_parser *parser) | |
5054 | { | |
27bf414c JM |
5055 | tree cond; |
5056 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
5057 | return error_mark_node; | |
ca085fd7 | 5058 | cond = c_parser_condition (parser); |
27bf414c JM |
5059 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); |
5060 | return cond; | |
5061 | } | |
5062 | ||
5063 | /* Parse a statement which is a block in C99. */ | |
5064 | ||
5065 | static tree | |
5066 | c_parser_c99_block_statement (c_parser *parser) | |
5067 | { | |
5068 | tree block = c_begin_compound_stmt (flag_isoc99); | |
c2255bc4 | 5069 | location_t loc = c_parser_peek_token (parser)->location; |
27bf414c | 5070 | c_parser_statement (parser); |
c2255bc4 | 5071 | return c_end_compound_stmt (loc, block, flag_isoc99); |
27bf414c JM |
5072 | } |
5073 | ||
b4b56033 MLI |
5074 | /* Parse the body of an if statement. This is just parsing a |
5075 | statement but (a) it is a block in C99, (b) we track whether the | |
5076 | body is an if statement for the sake of -Wparentheses warnings, (c) | |
5077 | we handle an empty body specially for the sake of -Wempty-body | |
5078 | warnings, and (d) we call parser_compound_statement directly | |
5079 | because c_parser_statement_after_labels resets | |
5080 | parser->in_if_block. */ | |
27bf414c JM |
5081 | |
5082 | static tree | |
5083 | c_parser_if_body (c_parser *parser, bool *if_p) | |
5084 | { | |
5085 | tree block = c_begin_compound_stmt (flag_isoc99); | |
c2255bc4 | 5086 | location_t body_loc = c_parser_peek_token (parser)->location; |
27bf414c JM |
5087 | while (c_parser_next_token_is_keyword (parser, RID_CASE) |
5088 | || c_parser_next_token_is_keyword (parser, RID_DEFAULT) | |
5089 | || (c_parser_next_token_is (parser, CPP_NAME) | |
5090 | && c_parser_peek_2nd_token (parser)->type == CPP_COLON)) | |
5091 | c_parser_label (parser); | |
5092 | *if_p = c_parser_next_token_is_keyword (parser, RID_IF); | |
62e00e94 | 5093 | if (c_parser_next_token_is (parser, CPP_SEMICOLON)) |
b4b56033 | 5094 | { |
626c34b5 | 5095 | location_t loc = c_parser_peek_token (parser)->location; |
c2255bc4 | 5096 | add_stmt (build_empty_stmt (loc)); |
b4b56033 | 5097 | c_parser_consume_token (parser); |
626c34b5 PB |
5098 | if (!c_parser_next_token_is_keyword (parser, RID_ELSE)) |
5099 | warning_at (loc, OPT_Wempty_body, | |
5100 | "suggest braces around empty body in an %<if%> statement"); | |
b4b56033 MLI |
5101 | } |
5102 | else if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) | |
5103 | add_stmt (c_parser_compound_statement (parser)); | |
5104 | else | |
5105 | c_parser_statement_after_labels (parser); | |
c2255bc4 | 5106 | return c_end_compound_stmt (body_loc, block, flag_isoc99); |
b4b56033 MLI |
5107 | } |
5108 | ||
5109 | /* Parse the else body of an if statement. This is just parsing a | |
5110 | statement but (a) it is a block in C99, (b) we handle an empty body | |
5111 | specially for the sake of -Wempty-body warnings. */ | |
5112 | ||
5113 | static tree | |
5114 | c_parser_else_body (c_parser *parser) | |
5115 | { | |
c2255bc4 | 5116 | location_t else_loc = c_parser_peek_token (parser)->location; |
b4b56033 MLI |
5117 | tree block = c_begin_compound_stmt (flag_isoc99); |
5118 | while (c_parser_next_token_is_keyword (parser, RID_CASE) | |
5119 | || c_parser_next_token_is_keyword (parser, RID_DEFAULT) | |
5120 | || (c_parser_next_token_is (parser, CPP_NAME) | |
5121 | && c_parser_peek_2nd_token (parser)->type == CPP_COLON)) | |
5122 | c_parser_label (parser); | |
5123 | if (c_parser_next_token_is (parser, CPP_SEMICOLON)) | |
5124 | { | |
c2255bc4 AH |
5125 | location_t loc = c_parser_peek_token (parser)->location; |
5126 | warning_at (loc, | |
626c34b5 PB |
5127 | OPT_Wempty_body, |
5128 | "suggest braces around empty body in an %<else%> statement"); | |
c2255bc4 | 5129 | add_stmt (build_empty_stmt (loc)); |
b4b56033 MLI |
5130 | c_parser_consume_token (parser); |
5131 | } | |
b8698a0f | 5132 | else |
b4b56033 | 5133 | c_parser_statement_after_labels (parser); |
c2255bc4 | 5134 | return c_end_compound_stmt (else_loc, block, flag_isoc99); |
27bf414c JM |
5135 | } |
5136 | ||
5137 | /* Parse an if statement (C90 6.6.4, C99 6.8.4). | |
5138 | ||
5139 | if-statement: | |
5140 | if ( expression ) statement | |
5141 | if ( expression ) statement else statement | |
5142 | */ | |
5143 | ||
5144 | static void | |
5145 | c_parser_if_statement (c_parser *parser) | |
5146 | { | |
5147 | tree block; | |
5148 | location_t loc; | |
5149 | tree cond; | |
b4b56033 | 5150 | bool first_if = false; |
27bf414c | 5151 | tree first_body, second_body; |
b4b56033 | 5152 | bool in_if_block; |
36536d79 | 5153 | tree if_stmt; |
b4b56033 | 5154 | |
27bf414c JM |
5155 | gcc_assert (c_parser_next_token_is_keyword (parser, RID_IF)); |
5156 | c_parser_consume_token (parser); | |
5157 | block = c_begin_compound_stmt (flag_isoc99); | |
5158 | loc = c_parser_peek_token (parser)->location; | |
5159 | cond = c_parser_paren_condition (parser); | |
b4b56033 MLI |
5160 | in_if_block = parser->in_if_block; |
5161 | parser->in_if_block = true; | |
27bf414c | 5162 | first_body = c_parser_if_body (parser, &first_if); |
b4b56033 | 5163 | parser->in_if_block = in_if_block; |
27bf414c JM |
5164 | if (c_parser_next_token_is_keyword (parser, RID_ELSE)) |
5165 | { | |
5166 | c_parser_consume_token (parser); | |
b4b56033 | 5167 | second_body = c_parser_else_body (parser); |
27bf414c JM |
5168 | } |
5169 | else | |
5170 | second_body = NULL_TREE; | |
5171 | c_finish_if_stmt (loc, cond, first_body, second_body, first_if); | |
36536d79 BI |
5172 | if_stmt = c_end_compound_stmt (loc, block, flag_isoc99); |
5173 | ||
5174 | /* If the if statement contains array notations, then we expand them. */ | |
b72271b9 | 5175 | if (flag_cilkplus && contains_array_notation_expr (if_stmt)) |
36536d79 BI |
5176 | if_stmt = fix_conditional_array_notations (if_stmt); |
5177 | add_stmt (if_stmt); | |
27bf414c JM |
5178 | } |
5179 | ||
5180 | /* Parse a switch statement (C90 6.6.4, C99 6.8.4). | |
5181 | ||
5182 | switch-statement: | |
5183 | switch (expression) statement | |
5184 | */ | |
5185 | ||
5186 | static void | |
5187 | c_parser_switch_statement (c_parser *parser) | |
5188 | { | |
267bac10 | 5189 | struct c_expr ce; |
27bf414c | 5190 | tree block, expr, body, save_break; |
c2255bc4 AH |
5191 | location_t switch_loc = c_parser_peek_token (parser)->location; |
5192 | location_t switch_cond_loc; | |
27bf414c JM |
5193 | gcc_assert (c_parser_next_token_is_keyword (parser, RID_SWITCH)); |
5194 | c_parser_consume_token (parser); | |
5195 | block = c_begin_compound_stmt (flag_isoc99); | |
fedfecef | 5196 | bool explicit_cast_p = false; |
27bf414c JM |
5197 | if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) |
5198 | { | |
c2255bc4 | 5199 | switch_cond_loc = c_parser_peek_token (parser)->location; |
fedfecef MP |
5200 | if (c_parser_next_token_is (parser, CPP_OPEN_PAREN) |
5201 | && c_token_starts_typename (c_parser_peek_2nd_token (parser))) | |
5202 | explicit_cast_p = true; | |
267bac10 JM |
5203 | ce = c_parser_expression (parser); |
5204 | ce = convert_lvalue_to_rvalue (switch_cond_loc, ce, true, false); | |
5205 | expr = ce.value; | |
b72271b9 | 5206 | if (flag_cilkplus && contains_array_notation_expr (expr)) |
36536d79 BI |
5207 | { |
5208 | error_at (switch_cond_loc, | |
5209 | "array notations cannot be used as a condition for switch " | |
5210 | "statement"); | |
5211 | expr = error_mark_node; | |
5212 | } | |
27bf414c JM |
5213 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); |
5214 | } | |
5215 | else | |
c2255bc4 AH |
5216 | { |
5217 | switch_cond_loc = UNKNOWN_LOCATION; | |
5218 | expr = error_mark_node; | |
5219 | } | |
fedfecef | 5220 | c_start_case (switch_loc, switch_cond_loc, expr, explicit_cast_p); |
27bf414c JM |
5221 | save_break = c_break_label; |
5222 | c_break_label = NULL_TREE; | |
5223 | body = c_parser_c99_block_statement (parser); | |
5224 | c_finish_case (body); | |
5225 | if (c_break_label) | |
c2255bc4 AH |
5226 | { |
5227 | location_t here = c_parser_peek_token (parser)->location; | |
5228 | tree t = build1 (LABEL_EXPR, void_type_node, c_break_label); | |
5229 | SET_EXPR_LOCATION (t, here); | |
5230 | add_stmt (t); | |
5231 | } | |
27bf414c | 5232 | c_break_label = save_break; |
c2255bc4 | 5233 | add_stmt (c_end_compound_stmt (switch_loc, block, flag_isoc99)); |
27bf414c JM |
5234 | } |
5235 | ||
5236 | /* Parse a while statement (C90 6.6.5, C99 6.8.5). | |
5237 | ||
5238 | while-statement: | |
5239 | while (expression) statement | |
5240 | */ | |
5241 | ||
5242 | static void | |
d4af74d4 | 5243 | c_parser_while_statement (c_parser *parser, bool ivdep) |
27bf414c JM |
5244 | { |
5245 | tree block, cond, body, save_break, save_cont; | |
5246 | location_t loc; | |
5247 | gcc_assert (c_parser_next_token_is_keyword (parser, RID_WHILE)); | |
5248 | c_parser_consume_token (parser); | |
5249 | block = c_begin_compound_stmt (flag_isoc99); | |
5250 | loc = c_parser_peek_token (parser)->location; | |
5251 | cond = c_parser_paren_condition (parser); | |
b72271b9 | 5252 | if (flag_cilkplus && contains_array_notation_expr (cond)) |
36536d79 BI |
5253 | { |
5254 | error_at (loc, "array notations cannot be used as a condition for while " | |
5255 | "statement"); | |
5256 | cond = error_mark_node; | |
5257 | } | |
d4af74d4 TB |
5258 | |
5259 | if (ivdep && cond != error_mark_node) | |
5260 | cond = build2 (ANNOTATE_EXPR, TREE_TYPE (cond), cond, | |
5261 | build_int_cst (integer_type_node, | |
5262 | annot_expr_ivdep_kind)); | |
27bf414c JM |
5263 | save_break = c_break_label; |
5264 | c_break_label = NULL_TREE; | |
5265 | save_cont = c_cont_label; | |
5266 | c_cont_label = NULL_TREE; | |
5267 | body = c_parser_c99_block_statement (parser); | |
5268 | c_finish_loop (loc, cond, NULL, body, c_break_label, c_cont_label, true); | |
c2255bc4 | 5269 | add_stmt (c_end_compound_stmt (loc, block, flag_isoc99)); |
27bf414c JM |
5270 | c_break_label = save_break; |
5271 | c_cont_label = save_cont; | |
5272 | } | |
5273 | ||
5274 | /* Parse a do statement (C90 6.6.5, C99 6.8.5). | |
5275 | ||
5276 | do-statement: | |
5277 | do statement while ( expression ) ; | |
5278 | */ | |
5279 | ||
5280 | static void | |
d4af74d4 | 5281 | c_parser_do_statement (c_parser *parser, bool ivdep) |
27bf414c JM |
5282 | { |
5283 | tree block, cond, body, save_break, save_cont, new_break, new_cont; | |
5284 | location_t loc; | |
5285 | gcc_assert (c_parser_next_token_is_keyword (parser, RID_DO)); | |
5286 | c_parser_consume_token (parser); | |
62e00e94 | 5287 | if (c_parser_next_token_is (parser, CPP_SEMICOLON)) |
3ba09659 AH |
5288 | warning_at (c_parser_peek_token (parser)->location, |
5289 | OPT_Wempty_body, | |
5290 | "suggest braces around empty body in %<do%> statement"); | |
27bf414c JM |
5291 | block = c_begin_compound_stmt (flag_isoc99); |
5292 | loc = c_parser_peek_token (parser)->location; | |
5293 | save_break = c_break_label; | |
5294 | c_break_label = NULL_TREE; | |
5295 | save_cont = c_cont_label; | |
5296 | c_cont_label = NULL_TREE; | |
5297 | body = c_parser_c99_block_statement (parser); | |
5298 | c_parser_require_keyword (parser, RID_WHILE, "expected %<while%>"); | |
5299 | new_break = c_break_label; | |
5300 | c_break_label = save_break; | |
5301 | new_cont = c_cont_label; | |
5302 | c_cont_label = save_cont; | |
5303 | cond = c_parser_paren_condition (parser); | |
b72271b9 | 5304 | if (flag_cilkplus && contains_array_notation_expr (cond)) |
36536d79 BI |
5305 | { |
5306 | error_at (loc, "array notations cannot be used as a condition for a " | |
5307 | "do-while statement"); | |
5308 | cond = error_mark_node; | |
5309 | } | |
d4af74d4 TB |
5310 | if (ivdep && cond != error_mark_node) |
5311 | cond = build2 (ANNOTATE_EXPR, TREE_TYPE (cond), cond, | |
5312 | build_int_cst (integer_type_node, | |
5313 | annot_expr_ivdep_kind)); | |
27bf414c JM |
5314 | if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>")) |
5315 | c_parser_skip_to_end_of_block_or_statement (parser); | |
5316 | c_finish_loop (loc, cond, NULL, body, new_break, new_cont, false); | |
c2255bc4 | 5317 | add_stmt (c_end_compound_stmt (loc, block, flag_isoc99)); |
27bf414c JM |
5318 | } |
5319 | ||
5320 | /* Parse a for statement (C90 6.6.5, C99 6.8.5). | |
5321 | ||
5322 | for-statement: | |
5323 | for ( expression[opt] ; expression[opt] ; expression[opt] ) statement | |
5324 | for ( nested-declaration expression[opt] ; expression[opt] ) statement | |
5325 | ||
5326 | The form with a declaration is new in C99. | |
5327 | ||
5328 | ??? In accordance with the old parser, the declaration may be a | |
5329 | nested function, which is then rejected in check_for_loop_decls, | |
5330 | but does it make any sense for this to be included in the grammar? | |
5331 | Note in particular that the nested function does not include a | |
5332 | trailing ';', whereas the "declaration" production includes one. | |
5333 | Also, can we reject bad declarations earlier and cheaper than | |
f05b9d93 NP |
5334 | check_for_loop_decls? |
5335 | ||
5336 | In Objective-C, there are two additional variants: | |
5337 | ||
5338 | foreach-statement: | |
5339 | for ( expression in expresssion ) statement | |
5340 | for ( declaration in expression ) statement | |
5341 | ||
5342 | This is inconsistent with C, because the second variant is allowed | |
5343 | even if c99 is not enabled. | |
5344 | ||
5345 | The rest of the comment documents these Objective-C foreach-statement. | |
5346 | ||
5347 | Here is the canonical example of the first variant: | |
5348 | for (object in array) { do something with object } | |
5349 | we call the first expression ("object") the "object_expression" and | |
5350 | the second expression ("array") the "collection_expression". | |
5351 | object_expression must be an lvalue of type "id" (a generic Objective-C | |
5352 | object) because the loop works by assigning to object_expression the | |
5353 | various objects from the collection_expression. collection_expression | |
5354 | must evaluate to something of type "id" which responds to the method | |
5355 | countByEnumeratingWithState:objects:count:. | |
5356 | ||
5357 | The canonical example of the second variant is: | |
5358 | for (id object in array) { do something with object } | |
5359 | which is completely equivalent to | |
5360 | { | |
5361 | id object; | |
5362 | for (object in array) { do something with object } | |
5363 | } | |
5364 | Note that initizializing 'object' in some way (eg, "for ((object = | |
5365 | xxx) in array) { do something with object }") is possibly | |
5366 | technically valid, but completely pointless as 'object' will be | |
5367 | assigned to something else as soon as the loop starts. We should | |
5368 | most likely reject it (TODO). | |
5369 | ||
5370 | The beginning of the Objective-C foreach-statement looks exactly | |
5371 | like the beginning of the for-statement, and we can tell it is a | |
5372 | foreach-statement only because the initial declaration or | |
5373 | expression is terminated by 'in' instead of ';'. | |
5374 | */ | |
27bf414c JM |
5375 | |
5376 | static void | |
8170608b | 5377 | c_parser_for_statement (c_parser *parser, bool ivdep) |
27bf414c JM |
5378 | { |
5379 | tree block, cond, incr, save_break, save_cont, body; | |
f05b9d93 | 5380 | /* The following are only used when parsing an ObjC foreach statement. */ |
689f2c82 AO |
5381 | tree object_expression; |
5382 | /* Silence the bogus uninitialized warning. */ | |
5383 | tree collection_expression = NULL; | |
c2255bc4 AH |
5384 | location_t loc = c_parser_peek_token (parser)->location; |
5385 | location_t for_loc = c_parser_peek_token (parser)->location; | |
f05b9d93 | 5386 | bool is_foreach_statement = false; |
27bf414c JM |
5387 | gcc_assert (c_parser_next_token_is_keyword (parser, RID_FOR)); |
5388 | c_parser_consume_token (parser); | |
f05b9d93 NP |
5389 | /* Open a compound statement in Objective-C as well, just in case this is |
5390 | as foreach expression. */ | |
5391 | block = c_begin_compound_stmt (flag_isoc99 || c_dialect_objc ()); | |
91b90ead UB |
5392 | cond = error_mark_node; |
5393 | incr = error_mark_node; | |
27bf414c JM |
5394 | if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) |
5395 | { | |
5396 | /* Parse the initialization declaration or expression. */ | |
f05b9d93 | 5397 | object_expression = error_mark_node; |
a5812bdc | 5398 | parser->objc_could_be_foreach_context = c_dialect_objc (); |
27bf414c JM |
5399 | if (c_parser_next_token_is (parser, CPP_SEMICOLON)) |
5400 | { | |
a5812bdc | 5401 | parser->objc_could_be_foreach_context = false; |
27bf414c | 5402 | c_parser_consume_token (parser); |
c2255bc4 | 5403 | c_finish_expr_stmt (loc, NULL_TREE); |
27bf414c | 5404 | } |
2f413185 | 5405 | else if (c_parser_next_tokens_start_declaration (parser)) |
27bf414c | 5406 | { |
f05b9d93 | 5407 | c_parser_declaration_or_fndef (parser, true, true, true, true, true, |
acf0174b | 5408 | &object_expression, vNULL); |
f05b9d93 NP |
5409 | parser->objc_could_be_foreach_context = false; |
5410 | ||
5411 | if (c_parser_next_token_is_keyword (parser, RID_IN)) | |
5412 | { | |
5413 | c_parser_consume_token (parser); | |
5414 | is_foreach_statement = true; | |
5415 | if (check_for_loop_decls (for_loc, true) == NULL_TREE) | |
5416 | c_parser_error (parser, "multiple iterating variables in fast enumeration"); | |
5417 | } | |
5418 | else | |
5419 | check_for_loop_decls (for_loc, flag_isoc99); | |
27bf414c JM |
5420 | } |
5421 | else if (c_parser_next_token_is_keyword (parser, RID_EXTENSION)) | |
5422 | { | |
5423 | /* __extension__ can start a declaration, but is also an | |
5424 | unary operator that can start an expression. Consume all | |
5425 | but the last of a possible series of __extension__ to | |
5426 | determine which. */ | |
5427 | while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD | |
5428 | && (c_parser_peek_2nd_token (parser)->keyword | |
5429 | == RID_EXTENSION)) | |
5430 | c_parser_consume_token (parser); | |
32912286 | 5431 | if (c_token_starts_declaration (c_parser_peek_2nd_token (parser))) |
27bf414c JM |
5432 | { |
5433 | int ext; | |
5434 | ext = disable_extension_diagnostics (); | |
5435 | c_parser_consume_token (parser); | |
32912286 | 5436 | c_parser_declaration_or_fndef (parser, true, true, true, true, |
acf0174b | 5437 | true, &object_expression, vNULL); |
f05b9d93 NP |
5438 | parser->objc_could_be_foreach_context = false; |
5439 | ||
27bf414c | 5440 | restore_extension_diagnostics (ext); |
f05b9d93 NP |
5441 | if (c_parser_next_token_is_keyword (parser, RID_IN)) |
5442 | { | |
5443 | c_parser_consume_token (parser); | |
5444 | is_foreach_statement = true; | |
5445 | if (check_for_loop_decls (for_loc, true) == NULL_TREE) | |
5446 | c_parser_error (parser, "multiple iterating variables in fast enumeration"); | |
5447 | } | |
5448 | else | |
5449 | check_for_loop_decls (for_loc, flag_isoc99); | |
27bf414c JM |
5450 | } |
5451 | else | |
5452 | goto init_expr; | |
5453 | } | |
5454 | else | |
5455 | { | |
5456 | init_expr: | |
f05b9d93 | 5457 | { |
267bac10 | 5458 | struct c_expr ce; |
f05b9d93 | 5459 | tree init_expression; |
267bac10 JM |
5460 | ce = c_parser_expression (parser); |
5461 | init_expression = ce.value; | |
f05b9d93 NP |
5462 | parser->objc_could_be_foreach_context = false; |
5463 | if (c_parser_next_token_is_keyword (parser, RID_IN)) | |
5464 | { | |
5465 | c_parser_consume_token (parser); | |
5466 | is_foreach_statement = true; | |
5467 | if (! lvalue_p (init_expression)) | |
5468 | c_parser_error (parser, "invalid iterating variable in fast enumeration"); | |
69a97201 | 5469 | object_expression = c_fully_fold (init_expression, false, NULL); |
f05b9d93 NP |
5470 | } |
5471 | else | |
5472 | { | |
267bac10 JM |
5473 | ce = convert_lvalue_to_rvalue (loc, ce, true, false); |
5474 | init_expression = ce.value; | |
f05b9d93 NP |
5475 | c_finish_expr_stmt (loc, init_expression); |
5476 | c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); | |
5477 | } | |
5478 | } | |
27bf414c | 5479 | } |
f05b9d93 NP |
5480 | /* Parse the loop condition. In the case of a foreach |
5481 | statement, there is no loop condition. */ | |
a5812bdc | 5482 | gcc_assert (!parser->objc_could_be_foreach_context); |
f05b9d93 | 5483 | if (!is_foreach_statement) |
27bf414c | 5484 | { |
f05b9d93 NP |
5485 | if (c_parser_next_token_is (parser, CPP_SEMICOLON)) |
5486 | { | |
8170608b TB |
5487 | if (ivdep) |
5488 | { | |
5489 | c_parser_error (parser, "missing loop condition in loop with " | |
5490 | "%<GCC ivdep%> pragma"); | |
5491 | cond = error_mark_node; | |
5492 | } | |
5493 | else | |
5494 | { | |
5495 | c_parser_consume_token (parser); | |
5496 | cond = NULL_TREE; | |
5497 | } | |
f05b9d93 NP |
5498 | } |
5499 | else | |
5500 | { | |
5501 | cond = c_parser_condition (parser); | |
b72271b9 | 5502 | if (flag_cilkplus && contains_array_notation_expr (cond)) |
36536d79 BI |
5503 | { |
5504 | error_at (loc, "array notations cannot be used in a " | |
5505 | "condition for a for-loop"); | |
5506 | cond = error_mark_node; | |
5507 | } | |
5508 | c_parser_skip_until_found (parser, CPP_SEMICOLON, | |
5509 | "expected %<;%>"); | |
f05b9d93 | 5510 | } |
8170608b TB |
5511 | if (ivdep && cond != error_mark_node) |
5512 | cond = build2 (ANNOTATE_EXPR, TREE_TYPE (cond), cond, | |
5513 | build_int_cst (integer_type_node, | |
5514 | annot_expr_ivdep_kind)); | |
27bf414c | 5515 | } |
f05b9d93 NP |
5516 | /* Parse the increment expression (the third expression in a |
5517 | for-statement). In the case of a foreach-statement, this is | |
5518 | the expression that follows the 'in'. */ | |
5519 | if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) | |
27bf414c | 5520 | { |
f05b9d93 NP |
5521 | if (is_foreach_statement) |
5522 | { | |
5523 | c_parser_error (parser, "missing collection in fast enumeration"); | |
5524 | collection_expression = error_mark_node; | |
5525 | } | |
5526 | else | |
5527 | incr = c_process_expr_stmt (loc, NULL_TREE); | |
27bf414c | 5528 | } |
27bf414c | 5529 | else |
f05b9d93 NP |
5530 | { |
5531 | if (is_foreach_statement) | |
69a97201 NP |
5532 | collection_expression = c_fully_fold (c_parser_expression (parser).value, |
5533 | false, NULL); | |
f05b9d93 | 5534 | else |
267bac10 JM |
5535 | { |
5536 | struct c_expr ce = c_parser_expression (parser); | |
5537 | ce = convert_lvalue_to_rvalue (loc, ce, true, false); | |
5538 | incr = c_process_expr_stmt (loc, ce.value); | |
5539 | } | |
f05b9d93 | 5540 | } |
27bf414c JM |
5541 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); |
5542 | } | |
27bf414c JM |
5543 | save_break = c_break_label; |
5544 | c_break_label = NULL_TREE; | |
5545 | save_cont = c_cont_label; | |
5546 | c_cont_label = NULL_TREE; | |
5547 | body = c_parser_c99_block_statement (parser); | |
f05b9d93 NP |
5548 | if (is_foreach_statement) |
5549 | objc_finish_foreach_loop (loc, object_expression, collection_expression, body, c_break_label, c_cont_label); | |
5550 | else | |
5551 | c_finish_loop (loc, cond, incr, body, c_break_label, c_cont_label, true); | |
5552 | add_stmt (c_end_compound_stmt (loc, block, flag_isoc99 || c_dialect_objc ())); | |
27bf414c JM |
5553 | c_break_label = save_break; |
5554 | c_cont_label = save_cont; | |
5555 | } | |
5556 | ||
5557 | /* Parse an asm statement, a GNU extension. This is a full-blown asm | |
5558 | statement with inputs, outputs, clobbers, and volatile tag | |
5559 | allowed. | |
5560 | ||
5561 | asm-statement: | |
5562 | asm type-qualifier[opt] ( asm-argument ) ; | |
1c384bf1 | 5563 | asm type-qualifier[opt] goto ( asm-goto-argument ) ; |
27bf414c JM |
5564 | |
5565 | asm-argument: | |
5566 | asm-string-literal | |
5567 | asm-string-literal : asm-operands[opt] | |
5568 | asm-string-literal : asm-operands[opt] : asm-operands[opt] | |
1c384bf1 RH |
5569 | asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers[opt] |
5570 | ||
5571 | asm-goto-argument: | |
5572 | asm-string-literal : : asm-operands[opt] : asm-clobbers[opt] \ | |
5573 | : asm-goto-operands | |
27bf414c JM |
5574 | |
5575 | Qualifiers other than volatile are accepted in the syntax but | |
5576 | warned for. */ | |
5577 | ||
5578 | static tree | |
5579 | c_parser_asm_statement (c_parser *parser) | |
5580 | { | |
1c384bf1 RH |
5581 | tree quals, str, outputs, inputs, clobbers, labels, ret; |
5582 | bool simple, is_goto; | |
c2255bc4 | 5583 | location_t asm_loc = c_parser_peek_token (parser)->location; |
1c384bf1 RH |
5584 | int section, nsections; |
5585 | ||
27bf414c JM |
5586 | gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM)); |
5587 | c_parser_consume_token (parser); | |
5588 | if (c_parser_next_token_is_keyword (parser, RID_VOLATILE)) | |
5589 | { | |
5590 | quals = c_parser_peek_token (parser)->value; | |
5591 | c_parser_consume_token (parser); | |
5592 | } | |
5593 | else if (c_parser_next_token_is_keyword (parser, RID_CONST) | |
5594 | || c_parser_next_token_is_keyword (parser, RID_RESTRICT)) | |
5595 | { | |
3ba09659 AH |
5596 | warning_at (c_parser_peek_token (parser)->location, |
5597 | 0, | |
5598 | "%E qualifier ignored on asm", | |
5599 | c_parser_peek_token (parser)->value); | |
27bf414c JM |
5600 | quals = NULL_TREE; |
5601 | c_parser_consume_token (parser); | |
5602 | } | |
5603 | else | |
5604 | quals = NULL_TREE; | |
1c384bf1 RH |
5605 | |
5606 | is_goto = false; | |
5607 | if (c_parser_next_token_is_keyword (parser, RID_GOTO)) | |
5608 | { | |
5609 | c_parser_consume_token (parser); | |
5610 | is_goto = true; | |
5611 | } | |
5612 | ||
27bf414c | 5613 | /* ??? Follow the C++ parser rather than using the |
46c2514e TT |
5614 | lex_untranslated_string kludge. */ |
5615 | parser->lex_untranslated_string = true; | |
1c384bf1 RH |
5616 | ret = NULL; |
5617 | ||
27bf414c | 5618 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) |
1c384bf1 RH |
5619 | goto error; |
5620 | ||
27bf414c | 5621 | str = c_parser_asm_string_literal (parser); |
b85eb797 | 5622 | if (str == NULL_TREE) |
1c384bf1 RH |
5623 | goto error_close_paren; |
5624 | ||
5625 | simple = true; | |
5626 | outputs = NULL_TREE; | |
5627 | inputs = NULL_TREE; | |
5628 | clobbers = NULL_TREE; | |
5629 | labels = NULL_TREE; | |
5630 | ||
5631 | if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN) && !is_goto) | |
5632 | goto done_asm; | |
5633 | ||
5634 | /* Parse each colon-delimited section of operands. */ | |
5635 | nsections = 3 + is_goto; | |
5636 | for (section = 0; section < nsections; ++section) | |
b85eb797 | 5637 | { |
1c384bf1 RH |
5638 | if (!c_parser_require (parser, CPP_COLON, |
5639 | is_goto | |
5640 | ? "expected %<:%>" | |
5641 | : "expected %<:%> or %<)%>")) | |
5642 | goto error_close_paren; | |
5643 | ||
5644 | /* Once past any colon, we're no longer a simple asm. */ | |
5645 | simple = false; | |
5646 | ||
5647 | if ((!c_parser_next_token_is (parser, CPP_COLON) | |
5648 | && !c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) | |
5649 | || section == 3) | |
5650 | switch (section) | |
5651 | { | |
5652 | case 0: | |
5653 | /* For asm goto, we don't allow output operands, but reserve | |
5654 | the slot for a future extension that does allow them. */ | |
5655 | if (!is_goto) | |
eadd3d0d | 5656 | outputs = c_parser_asm_operands (parser); |
1c384bf1 RH |
5657 | break; |
5658 | case 1: | |
eadd3d0d | 5659 | inputs = c_parser_asm_operands (parser); |
1c384bf1 RH |
5660 | break; |
5661 | case 2: | |
5662 | clobbers = c_parser_asm_clobbers (parser); | |
5663 | break; | |
5664 | case 3: | |
5665 | labels = c_parser_asm_goto_operands (parser); | |
5666 | break; | |
5667 | default: | |
5668 | gcc_unreachable (); | |
5669 | } | |
5670 | ||
5671 | if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN) && !is_goto) | |
5672 | goto done_asm; | |
27bf414c | 5673 | } |
1c384bf1 | 5674 | |
27bf414c | 5675 | done_asm: |
27bf414c JM |
5676 | if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>")) |
5677 | { | |
5678 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); | |
1c384bf1 | 5679 | goto error; |
27bf414c | 5680 | } |
1c384bf1 | 5681 | |
27bf414c JM |
5682 | if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>")) |
5683 | c_parser_skip_to_end_of_block_or_statement (parser); | |
1c384bf1 | 5684 | |
c2255bc4 | 5685 | ret = build_asm_stmt (quals, build_asm_expr (asm_loc, str, outputs, inputs, |
1c384bf1 RH |
5686 | clobbers, labels, simple)); |
5687 | ||
5688 | error: | |
5689 | parser->lex_untranslated_string = false; | |
27bf414c | 5690 | return ret; |
1c384bf1 RH |
5691 | |
5692 | error_close_paren: | |
5693 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); | |
5694 | goto error; | |
27bf414c JM |
5695 | } |
5696 | ||
eadd3d0d | 5697 | /* Parse asm operands, a GNU extension. |
27bf414c JM |
5698 | |
5699 | asm-operands: | |
5700 | asm-operand | |
5701 | asm-operands , asm-operand | |
5702 | ||
5703 | asm-operand: | |
5704 | asm-string-literal ( expression ) | |
5705 | [ identifier ] asm-string-literal ( expression ) | |
5706 | */ | |
5707 | ||
5708 | static tree | |
eadd3d0d | 5709 | c_parser_asm_operands (c_parser *parser) |
27bf414c JM |
5710 | { |
5711 | tree list = NULL_TREE; | |
5712 | while (true) | |
5713 | { | |
f2a71bbc JM |
5714 | tree name, str; |
5715 | struct c_expr expr; | |
27bf414c JM |
5716 | if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE)) |
5717 | { | |
5718 | c_parser_consume_token (parser); | |
5719 | if (c_parser_next_token_is (parser, CPP_NAME)) | |
5720 | { | |
5721 | tree id = c_parser_peek_token (parser)->value; | |
5722 | c_parser_consume_token (parser); | |
5723 | name = build_string (IDENTIFIER_LENGTH (id), | |
5724 | IDENTIFIER_POINTER (id)); | |
5725 | } | |
5726 | else | |
5727 | { | |
5728 | c_parser_error (parser, "expected identifier"); | |
5729 | c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL); | |
5730 | return NULL_TREE; | |
5731 | } | |
5732 | c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, | |
5733 | "expected %<]%>"); | |
5734 | } | |
5735 | else | |
5736 | name = NULL_TREE; | |
5737 | str = c_parser_asm_string_literal (parser); | |
5738 | if (str == NULL_TREE) | |
5739 | return NULL_TREE; | |
46c2514e | 5740 | parser->lex_untranslated_string = false; |
27bf414c JM |
5741 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) |
5742 | { | |
46c2514e | 5743 | parser->lex_untranslated_string = true; |
27bf414c JM |
5744 | return NULL_TREE; |
5745 | } | |
f2a71bbc | 5746 | expr = c_parser_expression (parser); |
ebfbbdc5 | 5747 | mark_exp_read (expr.value); |
46c2514e | 5748 | parser->lex_untranslated_string = true; |
27bf414c JM |
5749 | if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>")) |
5750 | { | |
5751 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); | |
5752 | return NULL_TREE; | |
5753 | } | |
5754 | list = chainon (list, build_tree_list (build_tree_list (name, str), | |
f2a71bbc | 5755 | expr.value)); |
27bf414c JM |
5756 | if (c_parser_next_token_is (parser, CPP_COMMA)) |
5757 | c_parser_consume_token (parser); | |
5758 | else | |
5759 | break; | |
5760 | } | |
5761 | return list; | |
5762 | } | |
5763 | ||
5764 | /* Parse asm clobbers, a GNU extension. | |
5765 | ||
5766 | asm-clobbers: | |
5767 | asm-string-literal | |
5768 | asm-clobbers , asm-string-literal | |
5769 | */ | |
5770 | ||
5771 | static tree | |
5772 | c_parser_asm_clobbers (c_parser *parser) | |
5773 | { | |
5774 | tree list = NULL_TREE; | |
5775 | while (true) | |
5776 | { | |
5777 | tree str = c_parser_asm_string_literal (parser); | |
5778 | if (str) | |
5779 | list = tree_cons (NULL_TREE, str, list); | |
5780 | else | |
5781 | return NULL_TREE; | |
5782 | if (c_parser_next_token_is (parser, CPP_COMMA)) | |
5783 | c_parser_consume_token (parser); | |
5784 | else | |
5785 | break; | |
5786 | } | |
5787 | return list; | |
5788 | } | |
5789 | ||
1c384bf1 | 5790 | /* Parse asm goto labels, a GNU extension. |
b8698a0f | 5791 | |
1c384bf1 RH |
5792 | asm-goto-operands: |
5793 | identifier | |
5794 | asm-goto-operands , identifier | |
5795 | */ | |
5796 | ||
5797 | static tree | |
5798 | c_parser_asm_goto_operands (c_parser *parser) | |
5799 | { | |
5800 | tree list = NULL_TREE; | |
5801 | while (true) | |
5802 | { | |
5803 | tree name, label; | |
5804 | ||
5805 | if (c_parser_next_token_is (parser, CPP_NAME)) | |
5806 | { | |
5807 | c_token *tok = c_parser_peek_token (parser); | |
5808 | name = tok->value; | |
5809 | label = lookup_label_for_goto (tok->location, name); | |
5810 | c_parser_consume_token (parser); | |
5811 | TREE_USED (label) = 1; | |
5812 | } | |
5813 | else | |
5814 | { | |
5815 | c_parser_error (parser, "expected identifier"); | |
5816 | return NULL_TREE; | |
5817 | } | |
5818 | ||
5819 | name = build_string (IDENTIFIER_LENGTH (name), | |
5820 | IDENTIFIER_POINTER (name)); | |
5821 | list = tree_cons (name, label, list); | |
5822 | if (c_parser_next_token_is (parser, CPP_COMMA)) | |
5823 | c_parser_consume_token (parser); | |
5824 | else | |
5825 | return nreverse (list); | |
5826 | } | |
5827 | } | |
5828 | ||
27bf414c JM |
5829 | /* Parse an expression other than a compound expression; that is, an |
5830 | assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not | |
5831 | NULL then it is an Objective-C message expression which is the | |
5832 | primary-expression starting the expression as an initializer. | |
5833 | ||
5834 | assignment-expression: | |
5835 | conditional-expression | |
5836 | unary-expression assignment-operator assignment-expression | |
5837 | ||
5838 | assignment-operator: one of | |
5839 | = *= /= %= += -= <<= >>= &= ^= |= | |
5840 | ||
5841 | In GNU C we accept any conditional expression on the LHS and | |
5842 | diagnose the invalid lvalue rather than producing a syntax | |
5843 | error. */ | |
5844 | ||
5845 | static struct c_expr | |
acf0174b JJ |
5846 | c_parser_expr_no_commas (c_parser *parser, struct c_expr *after, |
5847 | tree omp_atomic_lhs) | |
27bf414c JM |
5848 | { |
5849 | struct c_expr lhs, rhs, ret; | |
5850 | enum tree_code code; | |
c2255bc4 | 5851 | location_t op_location, exp_location; |
27bf414c | 5852 | gcc_assert (!after || c_dialect_objc ()); |
acf0174b | 5853 | lhs = c_parser_conditional_expression (parser, after, omp_atomic_lhs); |
c9f9eb5d | 5854 | op_location = c_parser_peek_token (parser)->location; |
27bf414c JM |
5855 | switch (c_parser_peek_token (parser)->type) |
5856 | { | |
5857 | case CPP_EQ: | |
5858 | code = NOP_EXPR; | |
5859 | break; | |
5860 | case CPP_MULT_EQ: | |
5861 | code = MULT_EXPR; | |
5862 | break; | |
5863 | case CPP_DIV_EQ: | |
5864 | code = TRUNC_DIV_EXPR; | |
5865 | break; | |
5866 | case CPP_MOD_EQ: | |
5867 | code = TRUNC_MOD_EXPR; | |
5868 | break; | |
5869 | case CPP_PLUS_EQ: | |
5870 | code = PLUS_EXPR; | |
5871 | break; | |
5872 | case CPP_MINUS_EQ: | |
5873 | code = MINUS_EXPR; | |
5874 | break; | |
5875 | case CPP_LSHIFT_EQ: | |
5876 | code = LSHIFT_EXPR; | |
5877 | break; | |
5878 | case CPP_RSHIFT_EQ: | |
5879 | code = RSHIFT_EXPR; | |
5880 | break; | |
5881 | case CPP_AND_EQ: | |
5882 | code = BIT_AND_EXPR; | |
5883 | break; | |
5884 | case CPP_XOR_EQ: | |
5885 | code = BIT_XOR_EXPR; | |
5886 | break; | |
5887 | case CPP_OR_EQ: | |
5888 | code = BIT_IOR_EXPR; | |
5889 | break; | |
5890 | default: | |
5891 | return lhs; | |
5892 | } | |
5893 | c_parser_consume_token (parser); | |
c2255bc4 | 5894 | exp_location = c_parser_peek_token (parser)->location; |
27bf414c | 5895 | rhs = c_parser_expr_no_commas (parser, NULL); |
267bac10 | 5896 | rhs = convert_lvalue_to_rvalue (exp_location, rhs, true, true); |
36536d79 | 5897 | |
25c22937 BI |
5898 | ret.value = build_modify_expr (op_location, lhs.value, lhs.original_type, |
5899 | code, exp_location, rhs.value, | |
5900 | rhs.original_type); | |
27bf414c JM |
5901 | if (code == NOP_EXPR) |
5902 | ret.original_code = MODIFY_EXPR; | |
5903 | else | |
5904 | { | |
5905 | TREE_NO_WARNING (ret.value) = 1; | |
5906 | ret.original_code = ERROR_MARK; | |
5907 | } | |
6866c6e8 | 5908 | ret.original_type = NULL; |
27bf414c JM |
5909 | return ret; |
5910 | } | |
5911 | ||
5912 | /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER | |
5913 | is not NULL then it is an Objective-C message expression which is | |
5914 | the primary-expression starting the expression as an initializer. | |
5915 | ||
5916 | conditional-expression: | |
5917 | logical-OR-expression | |
5918 | logical-OR-expression ? expression : conditional-expression | |
5919 | ||
5920 | GNU extensions: | |
5921 | ||
5922 | conditional-expression: | |
5923 | logical-OR-expression ? : conditional-expression | |
5924 | */ | |
5925 | ||
5926 | static struct c_expr | |
acf0174b JJ |
5927 | c_parser_conditional_expression (c_parser *parser, struct c_expr *after, |
5928 | tree omp_atomic_lhs) | |
27bf414c JM |
5929 | { |
5930 | struct c_expr cond, exp1, exp2, ret; | |
d166d4c3 | 5931 | location_t cond_loc, colon_loc, middle_loc; |
ba47d38d | 5932 | |
27bf414c | 5933 | gcc_assert (!after || c_dialect_objc ()); |
ba47d38d | 5934 | |
acf0174b | 5935 | cond = c_parser_binary_expression (parser, after, omp_atomic_lhs); |
ba47d38d | 5936 | |
27bf414c JM |
5937 | if (c_parser_next_token_is_not (parser, CPP_QUERY)) |
5938 | return cond; | |
c2255bc4 | 5939 | cond_loc = c_parser_peek_token (parser)->location; |
267bac10 | 5940 | cond = convert_lvalue_to_rvalue (cond_loc, cond, true, true); |
27bf414c JM |
5941 | c_parser_consume_token (parser); |
5942 | if (c_parser_next_token_is (parser, CPP_COLON)) | |
5943 | { | |
8ce94e44 | 5944 | tree eptype = NULL_TREE; |
d166d4c3 AK |
5945 | |
5946 | middle_loc = c_parser_peek_token (parser)->location; | |
c1771a20 | 5947 | pedwarn (middle_loc, OPT_Wpedantic, |
509c9d60 | 5948 | "ISO C forbids omitting the middle term of a ?: expression"); |
d166d4c3 | 5949 | warn_for_omitted_condop (middle_loc, cond.value); |
8ce94e44 JM |
5950 | if (TREE_CODE (cond.value) == EXCESS_PRECISION_EXPR) |
5951 | { | |
5952 | eptype = TREE_TYPE (cond.value); | |
5953 | cond.value = TREE_OPERAND (cond.value, 0); | |
5954 | } | |
27bf414c | 5955 | /* Make sure first operand is calculated only once. */ |
928c19bb | 5956 | exp1.value = c_save_expr (default_conversion (cond.value)); |
8ce94e44 JM |
5957 | if (eptype) |
5958 | exp1.value = build1 (EXCESS_PRECISION_EXPR, eptype, exp1.value); | |
6866c6e8 | 5959 | exp1.original_type = NULL; |
ba47d38d | 5960 | cond.value = c_objc_common_truthvalue_conversion (cond_loc, exp1.value); |
7d882b83 | 5961 | c_inhibit_evaluation_warnings += cond.value == truthvalue_true_node; |
27bf414c JM |
5962 | } |
5963 | else | |
5964 | { | |
5965 | cond.value | |
85498824 | 5966 | = c_objc_common_truthvalue_conversion |
ba47d38d | 5967 | (cond_loc, default_conversion (cond.value)); |
7d882b83 | 5968 | c_inhibit_evaluation_warnings += cond.value == truthvalue_false_node; |
46bdb9cf | 5969 | exp1 = c_parser_expression_conv (parser); |
ebfbbdc5 | 5970 | mark_exp_read (exp1.value); |
7d882b83 ILT |
5971 | c_inhibit_evaluation_warnings += |
5972 | ((cond.value == truthvalue_true_node) | |
5973 | - (cond.value == truthvalue_false_node)); | |
27bf414c | 5974 | } |
744aa42f ILT |
5975 | |
5976 | colon_loc = c_parser_peek_token (parser)->location; | |
27bf414c JM |
5977 | if (!c_parser_require (parser, CPP_COLON, "expected %<:%>")) |
5978 | { | |
7d882b83 | 5979 | c_inhibit_evaluation_warnings -= cond.value == truthvalue_true_node; |
27bf414c JM |
5980 | ret.value = error_mark_node; |
5981 | ret.original_code = ERROR_MARK; | |
6866c6e8 | 5982 | ret.original_type = NULL; |
27bf414c JM |
5983 | return ret; |
5984 | } | |
c2255bc4 AH |
5985 | { |
5986 | location_t exp2_loc = c_parser_peek_token (parser)->location; | |
acf0174b | 5987 | exp2 = c_parser_conditional_expression (parser, NULL, NULL_TREE); |
267bac10 | 5988 | exp2 = convert_lvalue_to_rvalue (exp2_loc, exp2, true, true); |
c2255bc4 | 5989 | } |
7d882b83 | 5990 | c_inhibit_evaluation_warnings -= cond.value == truthvalue_true_node; |
744aa42f | 5991 | ret.value = build_conditional_expr (colon_loc, cond.value, |
928c19bb | 5992 | cond.original_code == C_MAYBE_CONST_EXPR, |
d130ae11 ILT |
5993 | exp1.value, exp1.original_type, |
5994 | exp2.value, exp2.original_type); | |
27bf414c | 5995 | ret.original_code = ERROR_MARK; |
6866c6e8 ILT |
5996 | if (exp1.value == error_mark_node || exp2.value == error_mark_node) |
5997 | ret.original_type = NULL; | |
5998 | else | |
5999 | { | |
6000 | tree t1, t2; | |
6001 | ||
6002 | /* If both sides are enum type, the default conversion will have | |
6003 | made the type of the result be an integer type. We want to | |
6004 | remember the enum types we started with. */ | |
6005 | t1 = exp1.original_type ? exp1.original_type : TREE_TYPE (exp1.value); | |
6006 | t2 = exp2.original_type ? exp2.original_type : TREE_TYPE (exp2.value); | |
6007 | ret.original_type = ((t1 != error_mark_node | |
6008 | && t2 != error_mark_node | |
6009 | && (TYPE_MAIN_VARIANT (t1) | |
6010 | == TYPE_MAIN_VARIANT (t2))) | |
6011 | ? t1 | |
6012 | : NULL); | |
6013 | } | |
27bf414c JM |
6014 | return ret; |
6015 | } | |
6016 | ||
6017 | /* Parse a binary expression; that is, a logical-OR-expression (C90 | |
6018 | 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is | |
6019 | an Objective-C message expression which is the primary-expression | |
acf0174b JJ |
6020 | starting the expression as an initializer. |
6021 | ||
6022 | OMP_ATOMIC_LHS is NULL, unless parsing OpenMP #pragma omp atomic, | |
6023 | when it should be the unfolded lhs. In a valid OpenMP source, | |
6024 | one of the operands of the toplevel binary expression must be equal | |
6025 | to it. In that case, just return a build2 created binary operation | |
6026 | rather than result of parser_build_binary_op. | |
27bf414c JM |
6027 | |
6028 | multiplicative-expression: | |
6029 | cast-expression | |
6030 | multiplicative-expression * cast-expression | |
6031 | multiplicative-expression / cast-expression | |
6032 | multiplicative-expression % cast-expression | |
6033 | ||
6034 | additive-expression: | |
6035 | multiplicative-expression | |
6036 | additive-expression + multiplicative-expression | |
6037 | additive-expression - multiplicative-expression | |
6038 | ||
6039 | shift-expression: | |
6040 | additive-expression | |
6041 | shift-expression << additive-expression | |
6042 | shift-expression >> additive-expression | |
6043 | ||
6044 | relational-expression: | |
6045 | shift-expression | |
6046 | relational-expression < shift-expression | |
6047 | relational-expression > shift-expression | |
6048 | relational-expression <= shift-expression | |
6049 | relational-expression >= shift-expression | |
6050 | ||
6051 | equality-expression: | |
6052 | relational-expression | |
6053 | equality-expression == relational-expression | |
6054 | equality-expression != relational-expression | |
6055 | ||
6056 | AND-expression: | |
6057 | equality-expression | |
6058 | AND-expression & equality-expression | |
6059 | ||
6060 | exclusive-OR-expression: | |
6061 | AND-expression | |
6062 | exclusive-OR-expression ^ AND-expression | |
6063 | ||
6064 | inclusive-OR-expression: | |
6065 | exclusive-OR-expression | |
6066 | inclusive-OR-expression | exclusive-OR-expression | |
6067 | ||
6068 | logical-AND-expression: | |
6069 | inclusive-OR-expression | |
6070 | logical-AND-expression && inclusive-OR-expression | |
6071 | ||
6072 | logical-OR-expression: | |
6073 | logical-AND-expression | |
6074 | logical-OR-expression || logical-AND-expression | |
6075 | */ | |
6076 | ||
6077 | static struct c_expr | |
20906c66 | 6078 | c_parser_binary_expression (c_parser *parser, struct c_expr *after, |
acf0174b | 6079 | tree omp_atomic_lhs) |
27bf414c JM |
6080 | { |
6081 | /* A binary expression is parsed using operator-precedence parsing, | |
6082 | with the operands being cast expressions. All the binary | |
6083 | operators are left-associative. Thus a binary expression is of | |
6084 | form: | |
6085 | ||
6086 | E0 op1 E1 op2 E2 ... | |
6087 | ||
6088 | which we represent on a stack. On the stack, the precedence | |
6089 | levels are strictly increasing. When a new operator is | |
6090 | encountered of higher precedence than that at the top of the | |
6091 | stack, it is pushed; its LHS is the top expression, and its RHS | |
6092 | is everything parsed until it is popped. When a new operator is | |
6093 | encountered with precedence less than or equal to that at the top | |
6094 | of the stack, triples E[i-1] op[i] E[i] are popped and replaced | |
6095 | by the result of the operation until the operator at the top of | |
6096 | the stack has lower precedence than the new operator or there is | |
6097 | only one element on the stack; then the top expression is the LHS | |
6098 | of the new operator. In the case of logical AND and OR | |
7d882b83 ILT |
6099 | expressions, we also need to adjust c_inhibit_evaluation_warnings |
6100 | as appropriate when the operators are pushed and popped. */ | |
27bf414c | 6101 | |
27bf414c JM |
6102 | struct { |
6103 | /* The expression at this stack level. */ | |
6104 | struct c_expr expr; | |
6105 | /* The precedence of the operator on its left, PREC_NONE at the | |
6106 | bottom of the stack. */ | |
20906c66 | 6107 | enum c_parser_prec prec; |
27bf414c JM |
6108 | /* The operation on its left. */ |
6109 | enum tree_code op; | |
ca80e52b EB |
6110 | /* The source location of this operation. */ |
6111 | location_t loc; | |
27bf414c JM |
6112 | } stack[NUM_PRECS]; |
6113 | int sp; | |
ba47d38d | 6114 | /* Location of the binary operator. */ |
1f6d0c60 | 6115 | location_t binary_loc = UNKNOWN_LOCATION; /* Quiet warning. */ |
27bf414c JM |
6116 | #define POP \ |
6117 | do { \ | |
6118 | switch (stack[sp].op) \ | |
6119 | { \ | |
6120 | case TRUTH_ANDIF_EXPR: \ | |
7d882b83 ILT |
6121 | c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \ |
6122 | == truthvalue_false_node); \ | |
27bf414c JM |
6123 | break; \ |
6124 | case TRUTH_ORIF_EXPR: \ | |
7d882b83 ILT |
6125 | c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \ |
6126 | == truthvalue_true_node); \ | |
27bf414c JM |
6127 | break; \ |
6128 | default: \ | |
6129 | break; \ | |
6130 | } \ | |
f2a71bbc | 6131 | stack[sp - 1].expr \ |
267bac10 JM |
6132 | = convert_lvalue_to_rvalue (stack[sp - 1].loc, \ |
6133 | stack[sp - 1].expr, true, true); \ | |
f2a71bbc | 6134 | stack[sp].expr \ |
267bac10 JM |
6135 | = convert_lvalue_to_rvalue (stack[sp].loc, \ |
6136 | stack[sp].expr, true, true); \ | |
acf0174b JJ |
6137 | if (__builtin_expect (omp_atomic_lhs != NULL_TREE, 0) && sp == 1 \ |
6138 | && c_parser_peek_token (parser)->type == CPP_SEMICOLON \ | |
6139 | && ((1 << stack[sp].prec) \ | |
6140 | & (1 << (PREC_BITOR | PREC_BITXOR | PREC_BITAND | PREC_SHIFT \ | |
6141 | | PREC_ADD | PREC_MULT))) \ | |
6142 | && stack[sp].op != TRUNC_MOD_EXPR \ | |
6143 | && stack[0].expr.value != error_mark_node \ | |
6144 | && stack[1].expr.value != error_mark_node \ | |
6145 | && (c_tree_equal (stack[0].expr.value, omp_atomic_lhs) \ | |
6146 | || c_tree_equal (stack[1].expr.value, omp_atomic_lhs))) \ | |
6147 | stack[0].expr.value \ | |
6148 | = build2 (stack[1].op, TREE_TYPE (stack[0].expr.value), \ | |
6149 | stack[0].expr.value, stack[1].expr.value); \ | |
6150 | else \ | |
6151 | stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc, \ | |
6152 | stack[sp].op, \ | |
6153 | stack[sp - 1].expr, \ | |
6154 | stack[sp].expr); \ | |
27bf414c JM |
6155 | sp--; \ |
6156 | } while (0) | |
6157 | gcc_assert (!after || c_dialect_objc ()); | |
ca80e52b | 6158 | stack[0].loc = c_parser_peek_token (parser)->location; |
27bf414c | 6159 | stack[0].expr = c_parser_cast_expression (parser, after); |
acf0174b | 6160 | stack[0].prec = PREC_NONE; |
27bf414c JM |
6161 | sp = 0; |
6162 | while (true) | |
6163 | { | |
20906c66 | 6164 | enum c_parser_prec oprec; |
27bf414c JM |
6165 | enum tree_code ocode; |
6166 | if (parser->error) | |
6167 | goto out; | |
6168 | switch (c_parser_peek_token (parser)->type) | |
6169 | { | |
6170 | case CPP_MULT: | |
6171 | oprec = PREC_MULT; | |
6172 | ocode = MULT_EXPR; | |
6173 | break; | |
6174 | case CPP_DIV: | |
6175 | oprec = PREC_MULT; | |
6176 | ocode = TRUNC_DIV_EXPR; | |
6177 | break; | |
6178 | case CPP_MOD: | |
6179 | oprec = PREC_MULT; | |
6180 | ocode = TRUNC_MOD_EXPR; | |
6181 | break; | |
6182 | case CPP_PLUS: | |
6183 | oprec = PREC_ADD; | |
6184 | ocode = PLUS_EXPR; | |
6185 | break; | |
6186 | case CPP_MINUS: | |
6187 | oprec = PREC_ADD; | |
6188 | ocode = MINUS_EXPR; | |
6189 | break; | |
6190 | case CPP_LSHIFT: | |
6191 | oprec = PREC_SHIFT; | |
6192 | ocode = LSHIFT_EXPR; | |
6193 | break; | |
6194 | case CPP_RSHIFT: | |
6195 | oprec = PREC_SHIFT; | |
6196 | ocode = RSHIFT_EXPR; | |
6197 | break; | |
6198 | case CPP_LESS: | |
6199 | oprec = PREC_REL; | |
6200 | ocode = LT_EXPR; | |
6201 | break; | |
6202 | case CPP_GREATER: | |
6203 | oprec = PREC_REL; | |
6204 | ocode = GT_EXPR; | |
6205 | break; | |
6206 | case CPP_LESS_EQ: | |
6207 | oprec = PREC_REL; | |
6208 | ocode = LE_EXPR; | |
6209 | break; | |
6210 | case CPP_GREATER_EQ: | |
6211 | oprec = PREC_REL; | |
6212 | ocode = GE_EXPR; | |
6213 | break; | |
6214 | case CPP_EQ_EQ: | |
6215 | oprec = PREC_EQ; | |
6216 | ocode = EQ_EXPR; | |
6217 | break; | |
6218 | case CPP_NOT_EQ: | |
6219 | oprec = PREC_EQ; | |
6220 | ocode = NE_EXPR; | |
6221 | break; | |
6222 | case CPP_AND: | |
6223 | oprec = PREC_BITAND; | |
6224 | ocode = BIT_AND_EXPR; | |
6225 | break; | |
6226 | case CPP_XOR: | |
6227 | oprec = PREC_BITXOR; | |
6228 | ocode = BIT_XOR_EXPR; | |
6229 | break; | |
6230 | case CPP_OR: | |
6231 | oprec = PREC_BITOR; | |
6232 | ocode = BIT_IOR_EXPR; | |
6233 | break; | |
6234 | case CPP_AND_AND: | |
6235 | oprec = PREC_LOGAND; | |
6236 | ocode = TRUTH_ANDIF_EXPR; | |
6237 | break; | |
6238 | case CPP_OR_OR: | |
6239 | oprec = PREC_LOGOR; | |
6240 | ocode = TRUTH_ORIF_EXPR; | |
6241 | break; | |
6242 | default: | |
6243 | /* Not a binary operator, so end of the binary | |
6244 | expression. */ | |
6245 | goto out; | |
6246 | } | |
ba47d38d | 6247 | binary_loc = c_parser_peek_token (parser)->location; |
27bf414c | 6248 | while (oprec <= stack[sp].prec) |
acf0174b | 6249 | POP; |
20906c66 | 6250 | c_parser_consume_token (parser); |
27bf414c JM |
6251 | switch (ocode) |
6252 | { | |
6253 | case TRUTH_ANDIF_EXPR: | |
f2a71bbc | 6254 | stack[sp].expr |
267bac10 JM |
6255 | = convert_lvalue_to_rvalue (stack[sp].loc, |
6256 | stack[sp].expr, true, true); | |
85498824 | 6257 | stack[sp].expr.value = c_objc_common_truthvalue_conversion |
ca80e52b | 6258 | (stack[sp].loc, default_conversion (stack[sp].expr.value)); |
7d882b83 ILT |
6259 | c_inhibit_evaluation_warnings += (stack[sp].expr.value |
6260 | == truthvalue_false_node); | |
27bf414c JM |
6261 | break; |
6262 | case TRUTH_ORIF_EXPR: | |
f2a71bbc | 6263 | stack[sp].expr |
267bac10 JM |
6264 | = convert_lvalue_to_rvalue (stack[sp].loc, |
6265 | stack[sp].expr, true, true); | |
85498824 | 6266 | stack[sp].expr.value = c_objc_common_truthvalue_conversion |
ca80e52b | 6267 | (stack[sp].loc, default_conversion (stack[sp].expr.value)); |
7d882b83 ILT |
6268 | c_inhibit_evaluation_warnings += (stack[sp].expr.value |
6269 | == truthvalue_true_node); | |
27bf414c JM |
6270 | break; |
6271 | default: | |
6272 | break; | |
6273 | } | |
6274 | sp++; | |
ca80e52b | 6275 | stack[sp].loc = binary_loc; |
27bf414c JM |
6276 | stack[sp].expr = c_parser_cast_expression (parser, NULL); |
6277 | stack[sp].prec = oprec; | |
6278 | stack[sp].op = ocode; | |
c2255bc4 | 6279 | stack[sp].loc = binary_loc; |
27bf414c JM |
6280 | } |
6281 | out: | |
6282 | while (sp > 0) | |
6283 | POP; | |
6284 | return stack[0].expr; | |
6285 | #undef POP | |
6286 | } | |
6287 | ||
6288 | /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not | |
6289 | NULL then it is an Objective-C message expression which is the | |
6290 | primary-expression starting the expression as an initializer. | |
6291 | ||
6292 | cast-expression: | |
6293 | unary-expression | |
6294 | ( type-name ) unary-expression | |
6295 | */ | |
6296 | ||
6297 | static struct c_expr | |
6298 | c_parser_cast_expression (c_parser *parser, struct c_expr *after) | |
6299 | { | |
c2255bc4 | 6300 | location_t cast_loc = c_parser_peek_token (parser)->location; |
27bf414c JM |
6301 | gcc_assert (!after || c_dialect_objc ()); |
6302 | if (after) | |
c2255bc4 AH |
6303 | return c_parser_postfix_expression_after_primary (parser, |
6304 | cast_loc, *after); | |
27bf414c JM |
6305 | /* If the expression begins with a parenthesized type name, it may |
6306 | be either a cast or a compound literal; we need to see whether | |
6307 | the next character is '{' to tell the difference. If not, it is | |
29ce73cb PB |
6308 | an unary expression. Full detection of unknown typenames here |
6309 | would require a 3-token lookahead. */ | |
27bf414c JM |
6310 | if (c_parser_next_token_is (parser, CPP_OPEN_PAREN) |
6311 | && c_token_starts_typename (c_parser_peek_2nd_token (parser))) | |
6312 | { | |
6313 | struct c_type_name *type_name; | |
6314 | struct c_expr ret; | |
f2a71bbc | 6315 | struct c_expr expr; |
27bf414c JM |
6316 | c_parser_consume_token (parser); |
6317 | type_name = c_parser_type_name (parser); | |
6318 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
6319 | if (type_name == NULL) | |
6320 | { | |
6321 | ret.value = error_mark_node; | |
6322 | ret.original_code = ERROR_MARK; | |
6866c6e8 | 6323 | ret.original_type = NULL; |
27bf414c JM |
6324 | return ret; |
6325 | } | |
33c9159e AH |
6326 | |
6327 | /* Save casted types in the function's used types hash table. */ | |
8d8d1a28 | 6328 | used_types_insert (type_name->specs->type); |
33c9159e | 6329 | |
27bf414c | 6330 | if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) |
24b97832 | 6331 | return c_parser_postfix_expression_after_paren_type (parser, type_name, |
c2255bc4 AH |
6332 | cast_loc); |
6333 | { | |
6334 | location_t expr_loc = c_parser_peek_token (parser)->location; | |
6335 | expr = c_parser_cast_expression (parser, NULL); | |
267bac10 | 6336 | expr = convert_lvalue_to_rvalue (expr_loc, expr, true, true); |
c2255bc4 AH |
6337 | } |
6338 | ret.value = c_cast_expr (cast_loc, type_name, expr.value); | |
27bf414c | 6339 | ret.original_code = ERROR_MARK; |
6866c6e8 | 6340 | ret.original_type = NULL; |
27bf414c JM |
6341 | return ret; |
6342 | } | |
6343 | else | |
6344 | return c_parser_unary_expression (parser); | |
6345 | } | |
6346 | ||
6347 | /* Parse an unary expression (C90 6.3.3, C99 6.5.3). | |
6348 | ||
6349 | unary-expression: | |
6350 | postfix-expression | |
6351 | ++ unary-expression | |
6352 | -- unary-expression | |
6353 | unary-operator cast-expression | |
6354 | sizeof unary-expression | |
6355 | sizeof ( type-name ) | |
6356 | ||
6357 | unary-operator: one of | |
6358 | & * + - ~ ! | |
6359 | ||
6360 | GNU extensions: | |
6361 | ||
6362 | unary-expression: | |
6363 | __alignof__ unary-expression | |
6364 | __alignof__ ( type-name ) | |
6365 | && identifier | |
6366 | ||
48b0b196 | 6367 | (C11 permits _Alignof with type names only.) |
d19fa6b5 | 6368 | |
27bf414c JM |
6369 | unary-operator: one of |
6370 | __extension__ __real__ __imag__ | |
6371 | ||
0a35513e AH |
6372 | Transactional Memory: |
6373 | ||
6374 | unary-expression: | |
6375 | transaction-expression | |
6376 | ||
27bf414c JM |
6377 | In addition, the GNU syntax treats ++ and -- as unary operators, so |
6378 | they may be applied to cast expressions with errors for non-lvalues | |
6379 | given later. */ | |
6380 | ||
6381 | static struct c_expr | |
6382 | c_parser_unary_expression (c_parser *parser) | |
6383 | { | |
6384 | int ext; | |
46bdb9cf | 6385 | struct c_expr ret, op; |
c2255bc4 AH |
6386 | location_t op_loc = c_parser_peek_token (parser)->location; |
6387 | location_t exp_loc; | |
6866c6e8 ILT |
6388 | ret.original_code = ERROR_MARK; |
6389 | ret.original_type = NULL; | |
27bf414c JM |
6390 | switch (c_parser_peek_token (parser)->type) |
6391 | { | |
6392 | case CPP_PLUS_PLUS: | |
6393 | c_parser_consume_token (parser); | |
c2255bc4 | 6394 | exp_loc = c_parser_peek_token (parser)->location; |
46bdb9cf | 6395 | op = c_parser_cast_expression (parser, NULL); |
36536d79 BI |
6396 | |
6397 | /* If there is array notations in op, we expand them. */ | |
b72271b9 | 6398 | if (flag_cilkplus && TREE_CODE (op.value) == ARRAY_NOTATION_REF) |
36536d79 BI |
6399 | return fix_array_notation_expr (exp_loc, PREINCREMENT_EXPR, op); |
6400 | else | |
6401 | { | |
6402 | op = default_function_array_read_conversion (exp_loc, op); | |
6403 | return parser_build_unary_op (op_loc, PREINCREMENT_EXPR, op); | |
6404 | } | |
27bf414c JM |
6405 | case CPP_MINUS_MINUS: |
6406 | c_parser_consume_token (parser); | |
c2255bc4 | 6407 | exp_loc = c_parser_peek_token (parser)->location; |
46bdb9cf | 6408 | op = c_parser_cast_expression (parser, NULL); |
36536d79 BI |
6409 | |
6410 | /* If there is array notations in op, we expand them. */ | |
b72271b9 | 6411 | if (flag_cilkplus && TREE_CODE (op.value) == ARRAY_NOTATION_REF) |
36536d79 BI |
6412 | return fix_array_notation_expr (exp_loc, PREDECREMENT_EXPR, op); |
6413 | else | |
6414 | { | |
6415 | op = default_function_array_read_conversion (exp_loc, op); | |
6416 | return parser_build_unary_op (op_loc, PREDECREMENT_EXPR, op); | |
6417 | } | |
27bf414c JM |
6418 | case CPP_AND: |
6419 | c_parser_consume_token (parser); | |
ebfbbdc5 JJ |
6420 | op = c_parser_cast_expression (parser, NULL); |
6421 | mark_exp_read (op.value); | |
6422 | return parser_build_unary_op (op_loc, ADDR_EXPR, op); | |
27bf414c JM |
6423 | case CPP_MULT: |
6424 | c_parser_consume_token (parser); | |
c2255bc4 | 6425 | exp_loc = c_parser_peek_token (parser)->location; |
46bdb9cf | 6426 | op = c_parser_cast_expression (parser, NULL); |
267bac10 | 6427 | op = convert_lvalue_to_rvalue (exp_loc, op, true, true); |
dd865ef6 | 6428 | ret.value = build_indirect_ref (op_loc, op.value, RO_UNARY_STAR); |
27bf414c JM |
6429 | return ret; |
6430 | case CPP_PLUS: | |
8400e75e | 6431 | if (!c_dialect_objc () && !in_system_header_at (input_location)) |
c2255bc4 | 6432 | warning_at (op_loc, |
3ba09659 AH |
6433 | OPT_Wtraditional, |
6434 | "traditional C rejects the unary plus operator"); | |
c7412148 | 6435 | c_parser_consume_token (parser); |
c2255bc4 | 6436 | exp_loc = c_parser_peek_token (parser)->location; |
46bdb9cf | 6437 | op = c_parser_cast_expression (parser, NULL); |
267bac10 | 6438 | op = convert_lvalue_to_rvalue (exp_loc, op, true, true); |
c2255bc4 | 6439 | return parser_build_unary_op (op_loc, CONVERT_EXPR, op); |
27bf414c JM |
6440 | case CPP_MINUS: |
6441 | c_parser_consume_token (parser); | |
c2255bc4 | 6442 | exp_loc = c_parser_peek_token (parser)->location; |
46bdb9cf | 6443 | op = c_parser_cast_expression (parser, NULL); |
267bac10 | 6444 | op = convert_lvalue_to_rvalue (exp_loc, op, true, true); |
c2255bc4 | 6445 | return parser_build_unary_op (op_loc, NEGATE_EXPR, op); |
27bf414c JM |
6446 | case CPP_COMPL: |
6447 | c_parser_consume_token (parser); | |
c2255bc4 | 6448 | exp_loc = c_parser_peek_token (parser)->location; |
46bdb9cf | 6449 | op = c_parser_cast_expression (parser, NULL); |
267bac10 | 6450 | op = convert_lvalue_to_rvalue (exp_loc, op, true, true); |
c2255bc4 | 6451 | return parser_build_unary_op (op_loc, BIT_NOT_EXPR, op); |
27bf414c JM |
6452 | case CPP_NOT: |
6453 | c_parser_consume_token (parser); | |
c2255bc4 | 6454 | exp_loc = c_parser_peek_token (parser)->location; |
46bdb9cf | 6455 | op = c_parser_cast_expression (parser, NULL); |
267bac10 | 6456 | op = convert_lvalue_to_rvalue (exp_loc, op, true, true); |
c2255bc4 | 6457 | return parser_build_unary_op (op_loc, TRUTH_NOT_EXPR, op); |
27bf414c JM |
6458 | case CPP_AND_AND: |
6459 | /* Refer to the address of a label as a pointer. */ | |
6460 | c_parser_consume_token (parser); | |
6461 | if (c_parser_next_token_is (parser, CPP_NAME)) | |
6462 | { | |
6463 | ret.value = finish_label_address_expr | |
c2255bc4 | 6464 | (c_parser_peek_token (parser)->value, op_loc); |
27bf414c | 6465 | c_parser_consume_token (parser); |
27bf414c JM |
6466 | } |
6467 | else | |
6468 | { | |
6469 | c_parser_error (parser, "expected identifier"); | |
6470 | ret.value = error_mark_node; | |
27bf414c | 6471 | } |
43f6dfd3 | 6472 | return ret; |
27bf414c JM |
6473 | case CPP_KEYWORD: |
6474 | switch (c_parser_peek_token (parser)->keyword) | |
6475 | { | |
6476 | case RID_SIZEOF: | |
6477 | return c_parser_sizeof_expression (parser); | |
6478 | case RID_ALIGNOF: | |
6479 | return c_parser_alignof_expression (parser); | |
6480 | case RID_EXTENSION: | |
6481 | c_parser_consume_token (parser); | |
6482 | ext = disable_extension_diagnostics (); | |
6483 | ret = c_parser_cast_expression (parser, NULL); | |
6484 | restore_extension_diagnostics (ext); | |
6485 | return ret; | |
6486 | case RID_REALPART: | |
6487 | c_parser_consume_token (parser); | |
c2255bc4 | 6488 | exp_loc = c_parser_peek_token (parser)->location; |
46bdb9cf | 6489 | op = c_parser_cast_expression (parser, NULL); |
c2255bc4 AH |
6490 | op = default_function_array_conversion (exp_loc, op); |
6491 | return parser_build_unary_op (op_loc, REALPART_EXPR, op); | |
27bf414c JM |
6492 | case RID_IMAGPART: |
6493 | c_parser_consume_token (parser); | |
c2255bc4 | 6494 | exp_loc = c_parser_peek_token (parser)->location; |
46bdb9cf | 6495 | op = c_parser_cast_expression (parser, NULL); |
c2255bc4 AH |
6496 | op = default_function_array_conversion (exp_loc, op); |
6497 | return parser_build_unary_op (op_loc, IMAGPART_EXPR, op); | |
0a35513e AH |
6498 | case RID_TRANSACTION_ATOMIC: |
6499 | case RID_TRANSACTION_RELAXED: | |
6500 | return c_parser_transaction_expression (parser, | |
6501 | c_parser_peek_token (parser)->keyword); | |
27bf414c JM |
6502 | default: |
6503 | return c_parser_postfix_expression (parser); | |
6504 | } | |
6505 | default: | |
6506 | return c_parser_postfix_expression (parser); | |
6507 | } | |
6508 | } | |
6509 | ||
6510 | /* Parse a sizeof expression. */ | |
6511 | ||
6512 | static struct c_expr | |
6513 | c_parser_sizeof_expression (c_parser *parser) | |
6514 | { | |
6515 | struct c_expr expr; | |
c7412148 | 6516 | location_t expr_loc; |
27bf414c JM |
6517 | gcc_assert (c_parser_next_token_is_keyword (parser, RID_SIZEOF)); |
6518 | c_parser_consume_token (parser); | |
7d882b83 | 6519 | c_inhibit_evaluation_warnings++; |
27bf414c JM |
6520 | in_sizeof++; |
6521 | if (c_parser_next_token_is (parser, CPP_OPEN_PAREN) | |
6522 | && c_token_starts_typename (c_parser_peek_2nd_token (parser))) | |
6523 | { | |
6524 | /* Either sizeof ( type-name ) or sizeof unary-expression | |
6525 | starting with a compound literal. */ | |
6526 | struct c_type_name *type_name; | |
6527 | c_parser_consume_token (parser); | |
c7412148 | 6528 | expr_loc = c_parser_peek_token (parser)->location; |
27bf414c JM |
6529 | type_name = c_parser_type_name (parser); |
6530 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
6531 | if (type_name == NULL) | |
6532 | { | |
6533 | struct c_expr ret; | |
7d882b83 | 6534 | c_inhibit_evaluation_warnings--; |
27bf414c JM |
6535 | in_sizeof--; |
6536 | ret.value = error_mark_node; | |
6537 | ret.original_code = ERROR_MARK; | |
6866c6e8 | 6538 | ret.original_type = NULL; |
27bf414c JM |
6539 | return ret; |
6540 | } | |
6541 | if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) | |
6542 | { | |
4bd2511b JL |
6543 | expr = c_parser_postfix_expression_after_paren_type (parser, |
6544 | type_name, | |
6545 | expr_loc); | |
6546 | goto sizeof_expr; | |
27bf414c | 6547 | } |
4bd2511b JL |
6548 | /* sizeof ( type-name ). */ |
6549 | c_inhibit_evaluation_warnings--; | |
6550 | in_sizeof--; | |
6551 | return c_expr_sizeof_type (expr_loc, type_name); | |
27bf414c JM |
6552 | } |
6553 | else | |
6554 | { | |
c7412148 | 6555 | expr_loc = c_parser_peek_token (parser)->location; |
27bf414c | 6556 | expr = c_parser_unary_expression (parser); |
4bd2511b JL |
6557 | sizeof_expr: |
6558 | c_inhibit_evaluation_warnings--; | |
6559 | in_sizeof--; | |
6560 | mark_exp_read (expr.value); | |
6561 | if (TREE_CODE (expr.value) == COMPONENT_REF | |
6562 | && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1))) | |
6563 | error_at (expr_loc, "%<sizeof%> applied to a bit-field"); | |
6564 | return c_expr_sizeof_expr (expr_loc, expr); | |
27bf414c JM |
6565 | } |
6566 | } | |
6567 | ||
6568 | /* Parse an alignof expression. */ | |
6569 | ||
6570 | static struct c_expr | |
6571 | c_parser_alignof_expression (c_parser *parser) | |
6572 | { | |
6573 | struct c_expr expr; | |
c2255bc4 | 6574 | location_t loc = c_parser_peek_token (parser)->location; |
d19fa6b5 | 6575 | tree alignof_spelling = c_parser_peek_token (parser)->value; |
27bf414c | 6576 | gcc_assert (c_parser_next_token_is_keyword (parser, RID_ALIGNOF)); |
296674db JM |
6577 | bool is_c11_alignof = strcmp (IDENTIFIER_POINTER (alignof_spelling), |
6578 | "_Alignof") == 0; | |
d19fa6b5 | 6579 | /* A diagnostic is not required for the use of this identifier in |
48b0b196 | 6580 | the implementation namespace; only diagnose it for the C11 |
d19fa6b5 | 6581 | spelling because of existing code using the other spellings. */ |
296674db | 6582 | if (!flag_isoc11 && is_c11_alignof) |
d19fa6b5 JM |
6583 | { |
6584 | if (flag_isoc99) | |
c1771a20 | 6585 | pedwarn (loc, OPT_Wpedantic, "ISO C99 does not support %qE", |
d19fa6b5 JM |
6586 | alignof_spelling); |
6587 | else | |
c1771a20 | 6588 | pedwarn (loc, OPT_Wpedantic, "ISO C90 does not support %qE", |
d19fa6b5 JM |
6589 | alignof_spelling); |
6590 | } | |
27bf414c | 6591 | c_parser_consume_token (parser); |
7d882b83 | 6592 | c_inhibit_evaluation_warnings++; |
27bf414c JM |
6593 | in_alignof++; |
6594 | if (c_parser_next_token_is (parser, CPP_OPEN_PAREN) | |
6595 | && c_token_starts_typename (c_parser_peek_2nd_token (parser))) | |
6596 | { | |
6597 | /* Either __alignof__ ( type-name ) or __alignof__ | |
6598 | unary-expression starting with a compound literal. */ | |
24b97832 | 6599 | location_t loc; |
27bf414c JM |
6600 | struct c_type_name *type_name; |
6601 | struct c_expr ret; | |
6602 | c_parser_consume_token (parser); | |
24b97832 | 6603 | loc = c_parser_peek_token (parser)->location; |
27bf414c JM |
6604 | type_name = c_parser_type_name (parser); |
6605 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
6606 | if (type_name == NULL) | |
6607 | { | |
6608 | struct c_expr ret; | |
7d882b83 | 6609 | c_inhibit_evaluation_warnings--; |
27bf414c JM |
6610 | in_alignof--; |
6611 | ret.value = error_mark_node; | |
6612 | ret.original_code = ERROR_MARK; | |
6866c6e8 | 6613 | ret.original_type = NULL; |
27bf414c JM |
6614 | return ret; |
6615 | } | |
6616 | if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) | |
6617 | { | |
6618 | expr = c_parser_postfix_expression_after_paren_type (parser, | |
24b97832 ILT |
6619 | type_name, |
6620 | loc); | |
27bf414c JM |
6621 | goto alignof_expr; |
6622 | } | |
6623 | /* alignof ( type-name ). */ | |
7d882b83 | 6624 | c_inhibit_evaluation_warnings--; |
27bf414c | 6625 | in_alignof--; |
296674db JM |
6626 | ret.value = c_sizeof_or_alignof_type (loc, groktypename (type_name, |
6627 | NULL, NULL), | |
6628 | false, is_c11_alignof, 1); | |
27bf414c | 6629 | ret.original_code = ERROR_MARK; |
6866c6e8 | 6630 | ret.original_type = NULL; |
27bf414c JM |
6631 | return ret; |
6632 | } | |
6633 | else | |
6634 | { | |
6635 | struct c_expr ret; | |
6636 | expr = c_parser_unary_expression (parser); | |
6637 | alignof_expr: | |
ebfbbdc5 | 6638 | mark_exp_read (expr.value); |
7d882b83 | 6639 | c_inhibit_evaluation_warnings--; |
27bf414c | 6640 | in_alignof--; |
c1771a20 | 6641 | pedwarn (loc, OPT_Wpedantic, "ISO C does not allow %<%E (expression)%>", |
d19fa6b5 | 6642 | alignof_spelling); |
c2255bc4 | 6643 | ret.value = c_alignof_expr (loc, expr.value); |
27bf414c | 6644 | ret.original_code = ERROR_MARK; |
6866c6e8 | 6645 | ret.original_type = NULL; |
27bf414c JM |
6646 | return ret; |
6647 | } | |
6648 | } | |
6649 | ||
f90e8e2e | 6650 | /* Helper function to read arguments of builtins which are interfaces |
2205ed25 | 6651 | for the middle-end nodes like COMPLEX_EXPR, VEC_PERM_EXPR and |
f90e8e2e AS |
6652 | others. The name of the builtin is passed using BNAME parameter. |
6653 | Function returns true if there were no errors while parsing and | |
86785830 | 6654 | stores the arguments in CEXPR_LIST. */ |
f90e8e2e AS |
6655 | static bool |
6656 | c_parser_get_builtin_args (c_parser *parser, const char *bname, | |
4e7d7b3d JJ |
6657 | vec<c_expr_t, va_gc> **ret_cexpr_list, |
6658 | bool choose_expr_p) | |
f90e8e2e AS |
6659 | { |
6660 | location_t loc = c_parser_peek_token (parser)->location; | |
9771b263 | 6661 | vec<c_expr_t, va_gc> *cexpr_list; |
86785830 | 6662 | c_expr_t expr; |
4e7d7b3d | 6663 | bool saved_force_folding_builtin_constant_p; |
f90e8e2e | 6664 | |
86785830 | 6665 | *ret_cexpr_list = NULL; |
f90e8e2e AS |
6666 | if (c_parser_next_token_is_not (parser, CPP_OPEN_PAREN)) |
6667 | { | |
6668 | error_at (loc, "cannot take address of %qs", bname); | |
6669 | return false; | |
6670 | } | |
6671 | ||
6672 | c_parser_consume_token (parser); | |
6673 | ||
6674 | if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) | |
6675 | { | |
6676 | c_parser_consume_token (parser); | |
6677 | return true; | |
6678 | } | |
86785830 | 6679 | |
4e7d7b3d JJ |
6680 | saved_force_folding_builtin_constant_p |
6681 | = force_folding_builtin_constant_p; | |
6682 | force_folding_builtin_constant_p |= choose_expr_p; | |
86785830 | 6683 | expr = c_parser_expr_no_commas (parser, NULL); |
4e7d7b3d JJ |
6684 | force_folding_builtin_constant_p |
6685 | = saved_force_folding_builtin_constant_p; | |
9771b263 | 6686 | vec_alloc (cexpr_list, 1); |
b581c05c | 6687 | vec_safe_push (cexpr_list, expr); |
86785830 AS |
6688 | while (c_parser_next_token_is (parser, CPP_COMMA)) |
6689 | { | |
6690 | c_parser_consume_token (parser); | |
6691 | expr = c_parser_expr_no_commas (parser, NULL); | |
b581c05c | 6692 | vec_safe_push (cexpr_list, expr); |
86785830 | 6693 | } |
f90e8e2e AS |
6694 | |
6695 | if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>")) | |
6696 | return false; | |
6697 | ||
86785830 | 6698 | *ret_cexpr_list = cexpr_list; |
f90e8e2e AS |
6699 | return true; |
6700 | } | |
6701 | ||
433cc7b0 TT |
6702 | /* This represents a single generic-association. */ |
6703 | ||
6704 | struct c_generic_association | |
6705 | { | |
6706 | /* The location of the starting token of the type. */ | |
6707 | location_t type_location; | |
fb48aadc | 6708 | /* The association's type, or NULL_TREE for 'default'. */ |
433cc7b0 TT |
6709 | tree type; |
6710 | /* The association's expression. */ | |
6711 | struct c_expr expression; | |
6712 | }; | |
6713 | ||
6714 | /* Parse a generic-selection. (C11 6.5.1.1). | |
6715 | ||
6716 | generic-selection: | |
6717 | _Generic ( assignment-expression , generic-assoc-list ) | |
6718 | ||
6719 | generic-assoc-list: | |
6720 | generic-association | |
6721 | generic-assoc-list , generic-association | |
6722 | ||
6723 | generic-association: | |
6724 | type-name : assignment-expression | |
6725 | default : assignment-expression | |
6726 | */ | |
6727 | ||
6728 | static struct c_expr | |
6729 | c_parser_generic_selection (c_parser *parser) | |
6730 | { | |
6731 | vec<c_generic_association> associations = vNULL; | |
6732 | struct c_expr selector, error_expr; | |
6733 | tree selector_type; | |
6734 | struct c_generic_association matched_assoc; | |
6735 | bool match_found = false; | |
6736 | location_t generic_loc, selector_loc; | |
6737 | ||
6738 | error_expr.original_code = ERROR_MARK; | |
6739 | error_expr.original_type = NULL; | |
6740 | error_expr.value = error_mark_node; | |
6741 | matched_assoc.type_location = UNKNOWN_LOCATION; | |
6742 | matched_assoc.type = NULL_TREE; | |
6743 | matched_assoc.expression = error_expr; | |
6744 | ||
6745 | gcc_assert (c_parser_next_token_is_keyword (parser, RID_GENERIC)); | |
6746 | generic_loc = c_parser_peek_token (parser)->location; | |
6747 | c_parser_consume_token (parser); | |
6748 | if (!flag_isoc11) | |
6749 | { | |
6750 | if (flag_isoc99) | |
6751 | pedwarn (generic_loc, OPT_Wpedantic, | |
6752 | "ISO C99 does not support %<_Generic%>"); | |
6753 | else | |
6754 | pedwarn (generic_loc, OPT_Wpedantic, | |
6755 | "ISO C90 does not support %<_Generic%>"); | |
6756 | } | |
6757 | ||
6758 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
6759 | return error_expr; | |
6760 | ||
6761 | c_inhibit_evaluation_warnings++; | |
6762 | selector_loc = c_parser_peek_token (parser)->location; | |
6763 | selector = c_parser_expr_no_commas (parser, NULL); | |
6764 | selector = default_function_array_conversion (selector_loc, selector); | |
6765 | c_inhibit_evaluation_warnings--; | |
6766 | ||
6767 | if (selector.value == error_mark_node) | |
6768 | { | |
6769 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); | |
6770 | return selector; | |
6771 | } | |
6772 | selector_type = TREE_TYPE (selector.value); | |
6773 | /* In ISO C terms, rvalues (including the controlling expression of | |
6774 | _Generic) do not have qualified types. */ | |
6775 | if (TREE_CODE (selector_type) != ARRAY_TYPE) | |
6776 | selector_type = TYPE_MAIN_VARIANT (selector_type); | |
6777 | /* In ISO C terms, _Noreturn is not part of the type of expressions | |
6778 | such as &abort, but in GCC it is represented internally as a type | |
6779 | qualifier. */ | |
6780 | if (FUNCTION_POINTER_TYPE_P (selector_type) | |
6781 | && TYPE_QUALS (TREE_TYPE (selector_type)) != TYPE_UNQUALIFIED) | |
6782 | selector_type | |
6783 | = build_pointer_type (TYPE_MAIN_VARIANT (TREE_TYPE (selector_type))); | |
6784 | ||
6785 | if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>")) | |
6786 | { | |
6787 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); | |
6788 | return error_expr; | |
6789 | } | |
6790 | ||
6791 | while (1) | |
6792 | { | |
6793 | struct c_generic_association assoc, *iter; | |
6794 | unsigned int ix; | |
6795 | c_token *token = c_parser_peek_token (parser); | |
6796 | ||
6797 | assoc.type_location = token->location; | |
6798 | if (token->type == CPP_KEYWORD && token->keyword == RID_DEFAULT) | |
6799 | { | |
6800 | c_parser_consume_token (parser); | |
6801 | assoc.type = NULL_TREE; | |
6802 | } | |
6803 | else | |
6804 | { | |
6805 | struct c_type_name *type_name; | |
6806 | ||
6807 | type_name = c_parser_type_name (parser); | |
6808 | if (type_name == NULL) | |
6809 | { | |
6810 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); | |
6811 | goto error_exit; | |
6812 | } | |
6813 | assoc.type = groktypename (type_name, NULL, NULL); | |
6814 | if (assoc.type == error_mark_node) | |
6815 | { | |
6816 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); | |
6817 | goto error_exit; | |
6818 | } | |
6819 | ||
6820 | if (TREE_CODE (assoc.type) == FUNCTION_TYPE) | |
6821 | error_at (assoc.type_location, | |
6822 | "%<_Generic%> association has function type"); | |
6823 | else if (!COMPLETE_TYPE_P (assoc.type)) | |
6824 | error_at (assoc.type_location, | |
6825 | "%<_Generic%> association has incomplete type"); | |
6826 | ||
6827 | if (variably_modified_type_p (assoc.type, NULL_TREE)) | |
6828 | error_at (assoc.type_location, | |
6829 | "%<_Generic%> association has " | |
6830 | "variable length type"); | |
6831 | } | |
6832 | ||
6833 | if (!c_parser_require (parser, CPP_COLON, "expected %<:%>")) | |
6834 | { | |
6835 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); | |
6836 | goto error_exit; | |
6837 | } | |
6838 | ||
6839 | assoc.expression = c_parser_expr_no_commas (parser, NULL); | |
6840 | if (assoc.expression.value == error_mark_node) | |
6841 | { | |
6842 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); | |
6843 | goto error_exit; | |
6844 | } | |
6845 | ||
6846 | for (ix = 0; associations.iterate (ix, &iter); ++ix) | |
6847 | { | |
6848 | if (assoc.type == NULL_TREE) | |
6849 | { | |
6850 | if (iter->type == NULL_TREE) | |
6851 | { | |
6852 | error_at (assoc.type_location, | |
6853 | "duplicate %<default%> case in %<_Generic%>"); | |
6854 | inform (iter->type_location, "original %<default%> is here"); | |
6855 | } | |
6856 | } | |
6857 | else if (iter->type != NULL_TREE) | |
6858 | { | |
6859 | if (comptypes (assoc.type, iter->type)) | |
6860 | { | |
6861 | error_at (assoc.type_location, | |
6862 | "%<_Generic%> specifies two compatible types"); | |
6863 | inform (iter->type_location, "compatible type is here"); | |
6864 | } | |
6865 | } | |
6866 | } | |
6867 | ||
6868 | if (assoc.type == NULL_TREE) | |
6869 | { | |
6870 | if (!match_found) | |
6871 | { | |
6872 | matched_assoc = assoc; | |
6873 | match_found = true; | |
6874 | } | |
6875 | } | |
6876 | else if (comptypes (assoc.type, selector_type)) | |
6877 | { | |
6878 | if (!match_found || matched_assoc.type == NULL_TREE) | |
6879 | { | |
6880 | matched_assoc = assoc; | |
6881 | match_found = true; | |
6882 | } | |
6883 | else | |
6884 | { | |
6885 | error_at (assoc.type_location, | |
6886 | "%<_Generic> selector matches multiple associations"); | |
6887 | inform (matched_assoc.type_location, | |
6888 | "other match is here"); | |
6889 | } | |
6890 | } | |
6891 | ||
6892 | associations.safe_push (assoc); | |
6893 | ||
6894 | if (c_parser_peek_token (parser)->type != CPP_COMMA) | |
6895 | break; | |
6896 | c_parser_consume_token (parser); | |
6897 | } | |
6898 | ||
6899 | associations.release (); | |
6900 | ||
6901 | if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>")) | |
6902 | { | |
6903 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); | |
6904 | return error_expr; | |
6905 | } | |
6906 | ||
6907 | if (!match_found) | |
6908 | { | |
6909 | error_at (selector_loc, "%<_Generic%> selector of type %qT is not " | |
6910 | "compatible with any association", | |
6911 | selector_type); | |
6912 | return error_expr; | |
6913 | } | |
6914 | ||
6915 | return matched_assoc.expression; | |
6916 | ||
6917 | error_exit: | |
6918 | associations.release (); | |
6919 | return error_expr; | |
6920 | } | |
f90e8e2e | 6921 | |
27bf414c JM |
6922 | /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2). |
6923 | ||
6924 | postfix-expression: | |
6925 | primary-expression | |
6926 | postfix-expression [ expression ] | |
6927 | postfix-expression ( argument-expression-list[opt] ) | |
6928 | postfix-expression . identifier | |
6929 | postfix-expression -> identifier | |
6930 | postfix-expression ++ | |
6931 | postfix-expression -- | |
6932 | ( type-name ) { initializer-list } | |
6933 | ( type-name ) { initializer-list , } | |
6934 | ||
6935 | argument-expression-list: | |
6936 | argument-expression | |
6937 | argument-expression-list , argument-expression | |
6938 | ||
6939 | primary-expression: | |
6940 | identifier | |
6941 | constant | |
6942 | string-literal | |
6943 | ( expression ) | |
433cc7b0 | 6944 | generic-selection |
27bf414c JM |
6945 | |
6946 | GNU extensions: | |
6947 | ||
6948 | primary-expression: | |
6949 | __func__ | |
6950 | (treated as a keyword in GNU C) | |
6951 | __FUNCTION__ | |
6952 | __PRETTY_FUNCTION__ | |
6953 | ( compound-statement ) | |
6954 | __builtin_va_arg ( assignment-expression , type-name ) | |
6955 | __builtin_offsetof ( type-name , offsetof-member-designator ) | |
6956 | __builtin_choose_expr ( assignment-expression , | |
6957 | assignment-expression , | |
6958 | assignment-expression ) | |
6959 | __builtin_types_compatible_p ( type-name , type-name ) | |
d4a83c10 | 6960 | __builtin_complex ( assignment-expression , assignment-expression ) |
f90e8e2e AS |
6961 | __builtin_shuffle ( assignment-expression , assignment-expression ) |
6962 | __builtin_shuffle ( assignment-expression , | |
6963 | assignment-expression , | |
6964 | assignment-expression, ) | |
27bf414c JM |
6965 | |
6966 | offsetof-member-designator: | |
6967 | identifier | |
6968 | offsetof-member-designator . identifier | |
6969 | offsetof-member-designator [ expression ] | |
6970 | ||
6971 | Objective-C: | |
6972 | ||
6973 | primary-expression: | |
6974 | [ objc-receiver objc-message-args ] | |
6975 | @selector ( objc-selector-arg ) | |
6976 | @protocol ( identifier ) | |
6977 | @encode ( type-name ) | |
6978 | objc-string-literal | |
bede2adc | 6979 | Classname . identifier |
27bf414c JM |
6980 | */ |
6981 | ||
6982 | static struct c_expr | |
6983 | c_parser_postfix_expression (c_parser *parser) | |
6984 | { | |
f90e8e2e | 6985 | struct c_expr expr, e1; |
27bf414c | 6986 | struct c_type_name *t1, *t2; |
c2255bc4 | 6987 | location_t loc = c_parser_peek_token (parser)->location;; |
6866c6e8 ILT |
6988 | expr.original_code = ERROR_MARK; |
6989 | expr.original_type = NULL; | |
27bf414c JM |
6990 | switch (c_parser_peek_token (parser)->type) |
6991 | { | |
6992 | case CPP_NUMBER: | |
754ccf7c | 6993 | expr.value = c_parser_peek_token (parser)->value; |
754ccf7c JJ |
6994 | loc = c_parser_peek_token (parser)->location; |
6995 | c_parser_consume_token (parser); | |
6996 | if (TREE_CODE (expr.value) == FIXED_CST | |
6997 | && !targetm.fixed_point_supported_p ()) | |
6998 | { | |
6999 | error_at (loc, "fixed-point types not supported for this target"); | |
7000 | expr.value = error_mark_node; | |
7001 | } | |
7002 | break; | |
27bf414c | 7003 | case CPP_CHAR: |
b6baa67d KVH |
7004 | case CPP_CHAR16: |
7005 | case CPP_CHAR32: | |
27bf414c JM |
7006 | case CPP_WCHAR: |
7007 | expr.value = c_parser_peek_token (parser)->value; | |
27bf414c JM |
7008 | c_parser_consume_token (parser); |
7009 | break; | |
7010 | case CPP_STRING: | |
b6baa67d KVH |
7011 | case CPP_STRING16: |
7012 | case CPP_STRING32: | |
27bf414c | 7013 | case CPP_WSTRING: |
2c6e3f55 | 7014 | case CPP_UTF8STRING: |
27bf414c JM |
7015 | expr.value = c_parser_peek_token (parser)->value; |
7016 | expr.original_code = STRING_CST; | |
7017 | c_parser_consume_token (parser); | |
7018 | break; | |
7019 | case CPP_OBJC_STRING: | |
7020 | gcc_assert (c_dialect_objc ()); | |
7021 | expr.value | |
7022 | = objc_build_string_object (c_parser_peek_token (parser)->value); | |
27bf414c JM |
7023 | c_parser_consume_token (parser); |
7024 | break; | |
7025 | case CPP_NAME: | |
bede2adc | 7026 | switch (c_parser_peek_token (parser)->id_kind) |
27bf414c | 7027 | { |
bede2adc NP |
7028 | case C_ID_ID: |
7029 | { | |
7030 | tree id = c_parser_peek_token (parser)->value; | |
7031 | c_parser_consume_token (parser); | |
7032 | expr.value = build_external_ref (loc, id, | |
7033 | (c_parser_peek_token (parser)->type | |
7034 | == CPP_OPEN_PAREN), | |
7035 | &expr.original_type); | |
7036 | break; | |
7037 | } | |
7038 | case C_ID_CLASSNAME: | |
7039 | { | |
7040 | /* Here we parse the Objective-C 2.0 Class.name dot | |
7041 | syntax. */ | |
7042 | tree class_name = c_parser_peek_token (parser)->value; | |
7043 | tree component; | |
7044 | c_parser_consume_token (parser); | |
7045 | gcc_assert (c_dialect_objc ()); | |
7046 | if (!c_parser_require (parser, CPP_DOT, "expected %<.%>")) | |
7047 | { | |
7048 | expr.value = error_mark_node; | |
7049 | break; | |
7050 | } | |
7051 | if (c_parser_next_token_is_not (parser, CPP_NAME)) | |
7052 | { | |
7053 | c_parser_error (parser, "expected identifier"); | |
7054 | expr.value = error_mark_node; | |
7055 | break; | |
7056 | } | |
7057 | component = c_parser_peek_token (parser)->value; | |
7058 | c_parser_consume_token (parser); | |
7059 | expr.value = objc_build_class_component_ref (class_name, | |
7060 | component); | |
7061 | break; | |
7062 | } | |
7063 | default: | |
27bf414c JM |
7064 | c_parser_error (parser, "expected expression"); |
7065 | expr.value = error_mark_node; | |
27bf414c JM |
7066 | break; |
7067 | } | |
27bf414c JM |
7068 | break; |
7069 | case CPP_OPEN_PAREN: | |
7070 | /* A parenthesized expression, statement expression or compound | |
7071 | literal. */ | |
7072 | if (c_parser_peek_2nd_token (parser)->type == CPP_OPEN_BRACE) | |
7073 | { | |
7074 | /* A statement expression. */ | |
7075 | tree stmt; | |
c2255bc4 | 7076 | location_t brace_loc; |
27bf414c | 7077 | c_parser_consume_token (parser); |
c2255bc4 | 7078 | brace_loc = c_parser_peek_token (parser)->location; |
27bf414c | 7079 | c_parser_consume_token (parser); |
38e01f9e | 7080 | if (!building_stmt_list_p ()) |
27bf414c | 7081 | { |
c2255bc4 | 7082 | error_at (loc, "braced-group within expression allowed " |
3ba09659 | 7083 | "only inside a function"); |
27bf414c JM |
7084 | parser->error = true; |
7085 | c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL); | |
7086 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); | |
7087 | expr.value = error_mark_node; | |
27bf414c JM |
7088 | break; |
7089 | } | |
7090 | stmt = c_begin_stmt_expr (); | |
7091 | c_parser_compound_statement_nostart (parser); | |
7092 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, | |
7093 | "expected %<)%>"); | |
c1771a20 | 7094 | pedwarn (loc, OPT_Wpedantic, |
509c9d60 | 7095 | "ISO C forbids braced-groups within expressions"); |
c2255bc4 | 7096 | expr.value = c_finish_stmt_expr (brace_loc, stmt); |
82c3c067 | 7097 | mark_exp_read (expr.value); |
27bf414c JM |
7098 | } |
7099 | else if (c_token_starts_typename (c_parser_peek_2nd_token (parser))) | |
7100 | { | |
7101 | /* A compound literal. ??? Can we actually get here rather | |
7102 | than going directly to | |
7103 | c_parser_postfix_expression_after_paren_type from | |
7104 | elsewhere? */ | |
24b97832 | 7105 | location_t loc; |
27bf414c JM |
7106 | struct c_type_name *type_name; |
7107 | c_parser_consume_token (parser); | |
24b97832 | 7108 | loc = c_parser_peek_token (parser)->location; |
27bf414c JM |
7109 | type_name = c_parser_type_name (parser); |
7110 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, | |
7111 | "expected %<)%>"); | |
7112 | if (type_name == NULL) | |
7113 | { | |
7114 | expr.value = error_mark_node; | |
27bf414c JM |
7115 | } |
7116 | else | |
7117 | expr = c_parser_postfix_expression_after_paren_type (parser, | |
24b97832 ILT |
7118 | type_name, |
7119 | loc); | |
27bf414c JM |
7120 | } |
7121 | else | |
7122 | { | |
7123 | /* A parenthesized expression. */ | |
7124 | c_parser_consume_token (parser); | |
7125 | expr = c_parser_expression (parser); | |
7126 | if (TREE_CODE (expr.value) == MODIFY_EXPR) | |
7127 | TREE_NO_WARNING (expr.value) = 1; | |
928c19bb JM |
7128 | if (expr.original_code != C_MAYBE_CONST_EXPR) |
7129 | expr.original_code = ERROR_MARK; | |
6866c6e8 | 7130 | /* Don't change EXPR.ORIGINAL_TYPE. */ |
27bf414c JM |
7131 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, |
7132 | "expected %<)%>"); | |
7133 | } | |
7134 | break; | |
7135 | case CPP_KEYWORD: | |
7136 | switch (c_parser_peek_token (parser)->keyword) | |
7137 | { | |
7138 | case RID_FUNCTION_NAME: | |
7139 | case RID_PRETTY_FUNCTION_NAME: | |
7140 | case RID_C99_FUNCTION_NAME: | |
c2255bc4 | 7141 | expr.value = fname_decl (loc, |
3ba09659 | 7142 | c_parser_peek_token (parser)->keyword, |
27bf414c | 7143 | c_parser_peek_token (parser)->value); |
27bf414c JM |
7144 | c_parser_consume_token (parser); |
7145 | break; | |
7146 | case RID_VA_ARG: | |
7147 | c_parser_consume_token (parser); | |
7148 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
7149 | { | |
7150 | expr.value = error_mark_node; | |
27bf414c JM |
7151 | break; |
7152 | } | |
7153 | e1 = c_parser_expr_no_commas (parser, NULL); | |
ebfbbdc5 | 7154 | mark_exp_read (e1.value); |
928c19bb | 7155 | e1.value = c_fully_fold (e1.value, false, NULL); |
27bf414c JM |
7156 | if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>")) |
7157 | { | |
7158 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); | |
7159 | expr.value = error_mark_node; | |
27bf414c JM |
7160 | break; |
7161 | } | |
72b5577d | 7162 | loc = c_parser_peek_token (parser)->location; |
27bf414c JM |
7163 | t1 = c_parser_type_name (parser); |
7164 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, | |
7165 | "expected %<)%>"); | |
7166 | if (t1 == NULL) | |
7167 | { | |
7168 | expr.value = error_mark_node; | |
27bf414c JM |
7169 | } |
7170 | else | |
7171 | { | |
928c19bb | 7172 | tree type_expr = NULL_TREE; |
c2255bc4 AH |
7173 | expr.value = c_build_va_arg (loc, e1.value, |
7174 | groktypename (t1, &type_expr, NULL)); | |
928c19bb JM |
7175 | if (type_expr) |
7176 | { | |
7177 | expr.value = build2 (C_MAYBE_CONST_EXPR, | |
7178 | TREE_TYPE (expr.value), type_expr, | |
7179 | expr.value); | |
7180 | C_MAYBE_CONST_EXPR_NON_CONST (expr.value) = true; | |
7181 | } | |
27bf414c JM |
7182 | } |
7183 | break; | |
7184 | case RID_OFFSETOF: | |
7185 | c_parser_consume_token (parser); | |
7186 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
7187 | { | |
7188 | expr.value = error_mark_node; | |
27bf414c JM |
7189 | break; |
7190 | } | |
7191 | t1 = c_parser_type_name (parser); | |
7192 | if (t1 == NULL) | |
29ce73cb | 7193 | parser->error = true; |
27bf414c | 7194 | if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>")) |
29ce73cb PB |
7195 | gcc_assert (parser->error); |
7196 | if (parser->error) | |
27bf414c JM |
7197 | { |
7198 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); | |
7199 | expr.value = error_mark_node; | |
27bf414c JM |
7200 | break; |
7201 | } | |
29ce73cb | 7202 | |
27bf414c | 7203 | { |
928c19bb | 7204 | tree type = groktypename (t1, NULL, NULL); |
27bf414c JM |
7205 | tree offsetof_ref; |
7206 | if (type == error_mark_node) | |
7207 | offsetof_ref = error_mark_node; | |
7208 | else | |
c2255bc4 AH |
7209 | { |
7210 | offsetof_ref = build1 (INDIRECT_REF, type, null_pointer_node); | |
7211 | SET_EXPR_LOCATION (offsetof_ref, loc); | |
7212 | } | |
27bf414c JM |
7213 | /* Parse the second argument to __builtin_offsetof. We |
7214 | must have one identifier, and beyond that we want to | |
7215 | accept sub structure and sub array references. */ | |
7216 | if (c_parser_next_token_is (parser, CPP_NAME)) | |
7217 | { | |
7218 | offsetof_ref = build_component_ref | |
c2255bc4 | 7219 | (loc, offsetof_ref, c_parser_peek_token (parser)->value); |
27bf414c JM |
7220 | c_parser_consume_token (parser); |
7221 | while (c_parser_next_token_is (parser, CPP_DOT) | |
7222 | || c_parser_next_token_is (parser, | |
634b5df5 JJ |
7223 | CPP_OPEN_SQUARE) |
7224 | || c_parser_next_token_is (parser, | |
7225 | CPP_DEREF)) | |
27bf414c | 7226 | { |
634b5df5 JJ |
7227 | if (c_parser_next_token_is (parser, CPP_DEREF)) |
7228 | { | |
7229 | loc = c_parser_peek_token (parser)->location; | |
c2255bc4 AH |
7230 | offsetof_ref = build_array_ref (loc, |
7231 | offsetof_ref, | |
7232 | integer_zero_node); | |
634b5df5 JJ |
7233 | goto do_dot; |
7234 | } | |
7235 | else if (c_parser_next_token_is (parser, CPP_DOT)) | |
27bf414c | 7236 | { |
634b5df5 | 7237 | do_dot: |
27bf414c JM |
7238 | c_parser_consume_token (parser); |
7239 | if (c_parser_next_token_is_not (parser, | |
7240 | CPP_NAME)) | |
7241 | { | |
7242 | c_parser_error (parser, "expected identifier"); | |
7243 | break; | |
7244 | } | |
7245 | offsetof_ref = build_component_ref | |
c2255bc4 | 7246 | (loc, offsetof_ref, |
27bf414c JM |
7247 | c_parser_peek_token (parser)->value); |
7248 | c_parser_consume_token (parser); | |
7249 | } | |
7250 | else | |
7251 | { | |
267bac10 | 7252 | struct c_expr ce; |
27bf414c | 7253 | tree idx; |
6a3799eb | 7254 | loc = c_parser_peek_token (parser)->location; |
27bf414c | 7255 | c_parser_consume_token (parser); |
267bac10 JM |
7256 | ce = c_parser_expression (parser); |
7257 | ce = convert_lvalue_to_rvalue (loc, ce, false, false); | |
7258 | idx = ce.value; | |
928c19bb | 7259 | idx = c_fully_fold (idx, false, NULL); |
27bf414c JM |
7260 | c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, |
7261 | "expected %<]%>"); | |
c2255bc4 | 7262 | offsetof_ref = build_array_ref (loc, offsetof_ref, idx); |
27bf414c JM |
7263 | } |
7264 | } | |
7265 | } | |
7266 | else | |
7267 | c_parser_error (parser, "expected identifier"); | |
7268 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, | |
7269 | "expected %<)%>"); | |
cf9e9959 | 7270 | expr.value = fold_offsetof (offsetof_ref); |
27bf414c JM |
7271 | } |
7272 | break; | |
7273 | case RID_CHOOSE_EXPR: | |
27bf414c | 7274 | { |
9771b263 | 7275 | vec<c_expr_t, va_gc> *cexpr_list; |
86785830 AS |
7276 | c_expr_t *e1_p, *e2_p, *e3_p; |
7277 | tree c; | |
27bf414c | 7278 | |
f90e8e2e AS |
7279 | c_parser_consume_token (parser); |
7280 | if (!c_parser_get_builtin_args (parser, | |
7281 | "__builtin_choose_expr", | |
4e7d7b3d | 7282 | &cexpr_list, true)) |
f90e8e2e AS |
7283 | { |
7284 | expr.value = error_mark_node; | |
7285 | break; | |
7286 | } | |
7287 | ||
9771b263 | 7288 | if (vec_safe_length (cexpr_list) != 3) |
f90e8e2e AS |
7289 | { |
7290 | error_at (loc, "wrong number of arguments to " | |
7291 | "%<__builtin_choose_expr%>"); | |
7292 | expr.value = error_mark_node; | |
7293 | break; | |
7294 | } | |
86785830 | 7295 | |
9771b263 DN |
7296 | e1_p = &(*cexpr_list)[0]; |
7297 | e2_p = &(*cexpr_list)[1]; | |
7298 | e3_p = &(*cexpr_list)[2]; | |
86785830 AS |
7299 | |
7300 | c = e1_p->value; | |
7301 | mark_exp_read (e2_p->value); | |
7302 | mark_exp_read (e3_p->value); | |
928c19bb JM |
7303 | if (TREE_CODE (c) != INTEGER_CST |
7304 | || !INTEGRAL_TYPE_P (TREE_TYPE (c))) | |
3ba09659 AH |
7305 | error_at (loc, |
7306 | "first argument to %<__builtin_choose_expr%> not" | |
7307 | " a constant"); | |
928c19bb | 7308 | constant_expression_warning (c); |
86785830 | 7309 | expr = integer_zerop (c) ? *e3_p : *e2_p; |
f90e8e2e | 7310 | break; |
27bf414c | 7311 | } |
27bf414c JM |
7312 | case RID_TYPES_COMPATIBLE_P: |
7313 | c_parser_consume_token (parser); | |
7314 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
7315 | { | |
7316 | expr.value = error_mark_node; | |
27bf414c JM |
7317 | break; |
7318 | } | |
7319 | t1 = c_parser_type_name (parser); | |
7320 | if (t1 == NULL) | |
7321 | { | |
7322 | expr.value = error_mark_node; | |
27bf414c JM |
7323 | break; |
7324 | } | |
7325 | if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>")) | |
7326 | { | |
7327 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); | |
7328 | expr.value = error_mark_node; | |
27bf414c JM |
7329 | break; |
7330 | } | |
7331 | t2 = c_parser_type_name (parser); | |
7332 | if (t2 == NULL) | |
7333 | { | |
7334 | expr.value = error_mark_node; | |
27bf414c JM |
7335 | break; |
7336 | } | |
7337 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, | |
7338 | "expected %<)%>"); | |
7339 | { | |
7340 | tree e1, e2; | |
9abfe986 AP |
7341 | e1 = groktypename (t1, NULL, NULL); |
7342 | e2 = groktypename (t2, NULL, NULL); | |
7343 | if (e1 == error_mark_node || e2 == error_mark_node) | |
7344 | { | |
7345 | expr.value = error_mark_node; | |
7346 | break; | |
7347 | } | |
27bf414c | 7348 | |
9abfe986 AP |
7349 | e1 = TYPE_MAIN_VARIANT (e1); |
7350 | e2 = TYPE_MAIN_VARIANT (e2); | |
27bf414c | 7351 | |
9a9d280e AS |
7352 | expr.value |
7353 | = comptypes (e1, e2) ? integer_one_node : integer_zero_node; | |
27bf414c JM |
7354 | } |
7355 | break; | |
d4a83c10 | 7356 | case RID_BUILTIN_COMPLEX: |
86785830 | 7357 | { |
9771b263 | 7358 | vec<c_expr_t, va_gc> *cexpr_list; |
86785830 AS |
7359 | c_expr_t *e1_p, *e2_p; |
7360 | ||
f90e8e2e AS |
7361 | c_parser_consume_token (parser); |
7362 | if (!c_parser_get_builtin_args (parser, | |
7363 | "__builtin_complex", | |
4e7d7b3d | 7364 | &cexpr_list, false)) |
f90e8e2e AS |
7365 | { |
7366 | expr.value = error_mark_node; | |
7367 | break; | |
7368 | } | |
7369 | ||
9771b263 | 7370 | if (vec_safe_length (cexpr_list) != 2) |
f90e8e2e AS |
7371 | { |
7372 | error_at (loc, "wrong number of arguments to " | |
7373 | "%<__builtin_complex%>"); | |
7374 | expr.value = error_mark_node; | |
7375 | break; | |
7376 | } | |
86785830 | 7377 | |
9771b263 DN |
7378 | e1_p = &(*cexpr_list)[0]; |
7379 | e2_p = &(*cexpr_list)[1]; | |
86785830 | 7380 | |
267bac10 | 7381 | *e1_p = convert_lvalue_to_rvalue (loc, *e1_p, true, true); |
86785830 AS |
7382 | if (TREE_CODE (e1_p->value) == EXCESS_PRECISION_EXPR) |
7383 | e1_p->value = convert (TREE_TYPE (e1_p->value), | |
7384 | TREE_OPERAND (e1_p->value, 0)); | |
267bac10 | 7385 | *e2_p = convert_lvalue_to_rvalue (loc, *e2_p, true, true); |
86785830 AS |
7386 | if (TREE_CODE (e2_p->value) == EXCESS_PRECISION_EXPR) |
7387 | e2_p->value = convert (TREE_TYPE (e2_p->value), | |
7388 | TREE_OPERAND (e2_p->value, 0)); | |
7389 | if (!SCALAR_FLOAT_TYPE_P (TREE_TYPE (e1_p->value)) | |
7390 | || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e1_p->value)) | |
7391 | || !SCALAR_FLOAT_TYPE_P (TREE_TYPE (e2_p->value)) | |
7392 | || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e2_p->value))) | |
f90e8e2e AS |
7393 | { |
7394 | error_at (loc, "%<__builtin_complex%> operand " | |
7395 | "not of real binary floating-point type"); | |
7396 | expr.value = error_mark_node; | |
7397 | break; | |
7398 | } | |
86785830 AS |
7399 | if (TYPE_MAIN_VARIANT (TREE_TYPE (e1_p->value)) |
7400 | != TYPE_MAIN_VARIANT (TREE_TYPE (e2_p->value))) | |
f90e8e2e AS |
7401 | { |
7402 | error_at (loc, | |
7403 | "%<__builtin_complex%> operands of different types"); | |
7404 | expr.value = error_mark_node; | |
7405 | break; | |
7406 | } | |
f3bede71 MP |
7407 | pedwarn_c90 (loc, OPT_Wpedantic, |
7408 | "ISO C90 does not support complex types"); | |
f90e8e2e | 7409 | expr.value = build2 (COMPLEX_EXPR, |
86785830 AS |
7410 | build_complex_type |
7411 | (TYPE_MAIN_VARIANT | |
7412 | (TREE_TYPE (e1_p->value))), | |
7413 | e1_p->value, e2_p->value); | |
f90e8e2e AS |
7414 | break; |
7415 | } | |
7416 | case RID_BUILTIN_SHUFFLE: | |
7417 | { | |
9771b263 | 7418 | vec<c_expr_t, va_gc> *cexpr_list; |
9243c51d JJ |
7419 | unsigned int i; |
7420 | c_expr_t *p; | |
86785830 | 7421 | |
f90e8e2e AS |
7422 | c_parser_consume_token (parser); |
7423 | if (!c_parser_get_builtin_args (parser, | |
7424 | "__builtin_shuffle", | |
4e7d7b3d | 7425 | &cexpr_list, false)) |
f90e8e2e AS |
7426 | { |
7427 | expr.value = error_mark_node; | |
7428 | break; | |
7429 | } | |
7430 | ||
9771b263 | 7431 | FOR_EACH_VEC_SAFE_ELT (cexpr_list, i, p) |
267bac10 | 7432 | *p = convert_lvalue_to_rvalue (loc, *p, true, true); |
9243c51d | 7433 | |
9771b263 | 7434 | if (vec_safe_length (cexpr_list) == 2) |
86785830 | 7435 | expr.value = |
2205ed25 | 7436 | c_build_vec_perm_expr |
9771b263 DN |
7437 | (loc, (*cexpr_list)[0].value, |
7438 | NULL_TREE, (*cexpr_list)[1].value); | |
86785830 | 7439 | |
9771b263 | 7440 | else if (vec_safe_length (cexpr_list) == 3) |
86785830 | 7441 | expr.value = |
2205ed25 | 7442 | c_build_vec_perm_expr |
9771b263 DN |
7443 | (loc, (*cexpr_list)[0].value, |
7444 | (*cexpr_list)[1].value, | |
7445 | (*cexpr_list)[2].value); | |
f90e8e2e AS |
7446 | else |
7447 | { | |
7448 | error_at (loc, "wrong number of arguments to " | |
7449 | "%<__builtin_shuffle%>"); | |
7450 | expr.value = error_mark_node; | |
7451 | } | |
7452 | break; | |
7453 | } | |
27bf414c JM |
7454 | case RID_AT_SELECTOR: |
7455 | gcc_assert (c_dialect_objc ()); | |
7456 | c_parser_consume_token (parser); | |
7457 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
7458 | { | |
7459 | expr.value = error_mark_node; | |
27bf414c JM |
7460 | break; |
7461 | } | |
7462 | { | |
7463 | tree sel = c_parser_objc_selector_arg (parser); | |
7464 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, | |
7465 | "expected %<)%>"); | |
c2255bc4 | 7466 | expr.value = objc_build_selector_expr (loc, sel); |
27bf414c JM |
7467 | } |
7468 | break; | |
7469 | case RID_AT_PROTOCOL: | |
7470 | gcc_assert (c_dialect_objc ()); | |
7471 | c_parser_consume_token (parser); | |
7472 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
7473 | { | |
7474 | expr.value = error_mark_node; | |
27bf414c JM |
7475 | break; |
7476 | } | |
7477 | if (c_parser_next_token_is_not (parser, CPP_NAME)) | |
7478 | { | |
7479 | c_parser_error (parser, "expected identifier"); | |
7480 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); | |
7481 | expr.value = error_mark_node; | |
27bf414c JM |
7482 | break; |
7483 | } | |
7484 | { | |
7485 | tree id = c_parser_peek_token (parser)->value; | |
7486 | c_parser_consume_token (parser); | |
7487 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, | |
7488 | "expected %<)%>"); | |
7489 | expr.value = objc_build_protocol_expr (id); | |
27bf414c JM |
7490 | } |
7491 | break; | |
7492 | case RID_AT_ENCODE: | |
7493 | /* Extension to support C-structures in the archiver. */ | |
7494 | gcc_assert (c_dialect_objc ()); | |
7495 | c_parser_consume_token (parser); | |
7496 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
7497 | { | |
7498 | expr.value = error_mark_node; | |
27bf414c JM |
7499 | break; |
7500 | } | |
7501 | t1 = c_parser_type_name (parser); | |
7502 | if (t1 == NULL) | |
7503 | { | |
7504 | expr.value = error_mark_node; | |
27bf414c JM |
7505 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); |
7506 | break; | |
7507 | } | |
7508 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, | |
7509 | "expected %<)%>"); | |
7510 | { | |
928c19bb | 7511 | tree type = groktypename (t1, NULL, NULL); |
27bf414c | 7512 | expr.value = objc_build_encode_expr (type); |
27bf414c JM |
7513 | } |
7514 | break; | |
433cc7b0 TT |
7515 | case RID_GENERIC: |
7516 | expr = c_parser_generic_selection (parser); | |
7517 | break; | |
939b37da BI |
7518 | case RID_CILK_SPAWN: |
7519 | c_parser_consume_token (parser); | |
b72271b9 | 7520 | if (!flag_cilkplus) |
939b37da BI |
7521 | { |
7522 | error_at (loc, "-fcilkplus must be enabled to use " | |
7523 | "%<_Cilk_spawn%>"); | |
7524 | expr = c_parser_postfix_expression (parser); | |
7525 | expr.value = error_mark_node; | |
7526 | } | |
9a74f20c | 7527 | else if (c_parser_peek_token (parser)->keyword == RID_CILK_SPAWN) |
939b37da BI |
7528 | { |
7529 | error_at (loc, "consecutive %<_Cilk_spawn%> keywords " | |
7530 | "are not permitted"); | |
7531 | /* Now flush out all the _Cilk_spawns. */ | |
7532 | while (c_parser_peek_token (parser)->keyword == RID_CILK_SPAWN) | |
7533 | c_parser_consume_token (parser); | |
7534 | expr = c_parser_postfix_expression (parser); | |
7535 | } | |
7536 | else | |
7537 | { | |
7538 | expr = c_parser_postfix_expression (parser); | |
7539 | expr.value = build_cilk_spawn (loc, expr.value); | |
7540 | } | |
7541 | break; | |
27bf414c JM |
7542 | default: |
7543 | c_parser_error (parser, "expected expression"); | |
7544 | expr.value = error_mark_node; | |
27bf414c JM |
7545 | break; |
7546 | } | |
7547 | break; | |
7548 | case CPP_OPEN_SQUARE: | |
7549 | if (c_dialect_objc ()) | |
7550 | { | |
7551 | tree receiver, args; | |
7552 | c_parser_consume_token (parser); | |
7553 | receiver = c_parser_objc_receiver (parser); | |
7554 | args = c_parser_objc_message_args (parser); | |
7555 | c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, | |
7556 | "expected %<]%>"); | |
eb345401 | 7557 | expr.value = objc_build_message_expr (receiver, args); |
27bf414c JM |
7558 | break; |
7559 | } | |
7560 | /* Else fall through to report error. */ | |
7561 | default: | |
7562 | c_parser_error (parser, "expected expression"); | |
7563 | expr.value = error_mark_node; | |
27bf414c JM |
7564 | break; |
7565 | } | |
c2255bc4 | 7566 | return c_parser_postfix_expression_after_primary (parser, loc, expr); |
27bf414c JM |
7567 | } |
7568 | ||
7569 | /* Parse a postfix expression after a parenthesized type name: the | |
7570 | brace-enclosed initializer of a compound literal, possibly followed | |
7571 | by some postfix operators. This is separate because it is not | |
7572 | possible to tell until after the type name whether a cast | |
7573 | expression has a cast or a compound literal, or whether the operand | |
7574 | of sizeof is a parenthesized type name or starts with a compound | |
24b97832 ILT |
7575 | literal. TYPE_LOC is the location where TYPE_NAME starts--the |
7576 | location of the first token after the parentheses around the type | |
7577 | name. */ | |
27bf414c JM |
7578 | |
7579 | static struct c_expr | |
7580 | c_parser_postfix_expression_after_paren_type (c_parser *parser, | |
24b97832 ILT |
7581 | struct c_type_name *type_name, |
7582 | location_t type_loc) | |
27bf414c JM |
7583 | { |
7584 | tree type; | |
7585 | struct c_expr init; | |
928c19bb | 7586 | bool non_const; |
27bf414c | 7587 | struct c_expr expr; |
c7412148 | 7588 | location_t start_loc; |
928c19bb JM |
7589 | tree type_expr = NULL_TREE; |
7590 | bool type_expr_const = true; | |
c2255bc4 | 7591 | check_compound_literal_type (type_loc, type_name); |
27bf414c | 7592 | start_init (NULL_TREE, NULL, 0); |
928c19bb | 7593 | type = groktypename (type_name, &type_expr, &type_expr_const); |
c7412148 | 7594 | start_loc = c_parser_peek_token (parser)->location; |
85cad37c | 7595 | if (type != error_mark_node && C_TYPE_VARIABLE_SIZE (type)) |
27bf414c | 7596 | { |
24b97832 | 7597 | error_at (type_loc, "compound literal has variable size"); |
27bf414c JM |
7598 | type = error_mark_node; |
7599 | } | |
7600 | init = c_parser_braced_init (parser, type, false); | |
7601 | finish_init (); | |
d033409e | 7602 | maybe_warn_string_init (type_loc, type, init); |
27bf414c | 7603 | |
36c5e70a BE |
7604 | if (type != error_mark_node |
7605 | && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type)) | |
7606 | && current_function_decl) | |
7607 | { | |
7608 | error ("compound literal qualified by address-space qualifier"); | |
7609 | type = error_mark_node; | |
7610 | } | |
7611 | ||
f3bede71 | 7612 | pedwarn_c90 (start_loc, OPT_Wpedantic, "ISO C90 forbids compound literals"); |
928c19bb JM |
7613 | non_const = ((init.value && TREE_CODE (init.value) == CONSTRUCTOR) |
7614 | ? CONSTRUCTOR_NON_CONST (init.value) | |
7615 | : init.original_code == C_MAYBE_CONST_EXPR); | |
7616 | non_const |= !type_expr_const; | |
c2255bc4 | 7617 | expr.value = build_compound_literal (start_loc, type, init.value, non_const); |
27bf414c | 7618 | expr.original_code = ERROR_MARK; |
6866c6e8 | 7619 | expr.original_type = NULL; |
928c19bb JM |
7620 | if (type_expr) |
7621 | { | |
7622 | if (TREE_CODE (expr.value) == C_MAYBE_CONST_EXPR) | |
7623 | { | |
7624 | gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr.value) == NULL_TREE); | |
7625 | C_MAYBE_CONST_EXPR_PRE (expr.value) = type_expr; | |
7626 | } | |
7627 | else | |
7628 | { | |
7629 | gcc_assert (!non_const); | |
7630 | expr.value = build2 (C_MAYBE_CONST_EXPR, type, | |
7631 | type_expr, expr.value); | |
7632 | } | |
7633 | } | |
c2255bc4 | 7634 | return c_parser_postfix_expression_after_primary (parser, start_loc, expr); |
27bf414c JM |
7635 | } |
7636 | ||
1a4049e7 JJ |
7637 | /* Callback function for sizeof_pointer_memaccess_warning to compare |
7638 | types. */ | |
7639 | ||
7640 | static bool | |
7641 | sizeof_ptr_memacc_comptypes (tree type1, tree type2) | |
7642 | { | |
7643 | return comptypes (type1, type2) == 1; | |
7644 | } | |
7645 | ||
27bf414c | 7646 | /* Parse a postfix expression after the initial primary or compound |
c2255bc4 AH |
7647 | literal; that is, parse a series of postfix operators. |
7648 | ||
7649 | EXPR_LOC is the location of the primary expression. */ | |
27bf414c JM |
7650 | |
7651 | static struct c_expr | |
7652 | c_parser_postfix_expression_after_primary (c_parser *parser, | |
c2255bc4 | 7653 | location_t expr_loc, |
27bf414c JM |
7654 | struct c_expr expr) |
7655 | { | |
928c19bb | 7656 | struct c_expr orig_expr; |
bbbbb16a | 7657 | tree ident, idx; |
3a785c97 JJ |
7658 | location_t sizeof_arg_loc[3]; |
7659 | tree sizeof_arg[3]; | |
b108f48f | 7660 | unsigned int literal_zero_mask; |
3a785c97 | 7661 | unsigned int i; |
9771b263 | 7662 | vec<tree, va_gc> *exprlist; |
2ee028f1 | 7663 | vec<tree, va_gc> *origtypes = NULL; |
81e5eca8 MP |
7664 | vec<location_t> arg_loc = vNULL; |
7665 | ||
27bf414c JM |
7666 | while (true) |
7667 | { | |
c2255bc4 | 7668 | location_t op_loc = c_parser_peek_token (parser)->location; |
27bf414c JM |
7669 | switch (c_parser_peek_token (parser)->type) |
7670 | { | |
7671 | case CPP_OPEN_SQUARE: | |
7672 | /* Array reference. */ | |
7673 | c_parser_consume_token (parser); | |
b72271b9 | 7674 | if (flag_cilkplus |
36536d79 BI |
7675 | && c_parser_peek_token (parser)->type == CPP_COLON) |
7676 | /* If we are here, then we have something like this: | |
7677 | Array [ : ] | |
7678 | */ | |
7679 | expr.value = c_parser_array_notation (expr_loc, parser, NULL_TREE, | |
7680 | expr.value); | |
7681 | else | |
7682 | { | |
7683 | idx = c_parser_expression (parser).value; | |
7684 | /* Here we have 3 options: | |
7685 | 1. Array [EXPR] -- Normal Array call. | |
7686 | 2. Array [EXPR : EXPR] -- Array notation without stride. | |
7687 | 3. Array [EXPR : EXPR : EXPR] -- Array notation with stride. | |
7688 | ||
7689 | For 1, we just handle it just like a normal array expression. | |
7690 | For 2 and 3 we handle it like we handle array notations. The | |
7691 | idx value we have above becomes the initial/start index. | |
7692 | */ | |
b72271b9 | 7693 | if (flag_cilkplus |
36536d79 BI |
7694 | && c_parser_peek_token (parser)->type == CPP_COLON) |
7695 | expr.value = c_parser_array_notation (expr_loc, parser, idx, | |
7696 | expr.value); | |
7697 | else | |
7698 | { | |
7699 | c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, | |
7700 | "expected %<]%>"); | |
7701 | expr.value = build_array_ref (op_loc, expr.value, idx); | |
7702 | } | |
7703 | } | |
27bf414c | 7704 | expr.original_code = ERROR_MARK; |
6866c6e8 | 7705 | expr.original_type = NULL; |
27bf414c JM |
7706 | break; |
7707 | case CPP_OPEN_PAREN: | |
7708 | /* Function call. */ | |
7709 | c_parser_consume_token (parser); | |
3a785c97 JJ |
7710 | for (i = 0; i < 3; i++) |
7711 | { | |
7712 | sizeof_arg[i] = NULL_TREE; | |
7713 | sizeof_arg_loc[i] = UNKNOWN_LOCATION; | |
7714 | } | |
b108f48f | 7715 | literal_zero_mask = 0; |
27bf414c | 7716 | if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) |
bbbbb16a | 7717 | exprlist = NULL; |
27bf414c | 7718 | else |
1a4049e7 | 7719 | exprlist = c_parser_expr_list (parser, true, false, &origtypes, |
81e5eca8 | 7720 | sizeof_arg_loc, sizeof_arg, |
b108f48f | 7721 | &arg_loc, &literal_zero_mask); |
27bf414c JM |
7722 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, |
7723 | "expected %<)%>"); | |
928c19bb | 7724 | orig_expr = expr; |
ebfbbdc5 | 7725 | mark_exp_read (expr.value); |
3a785c97 JJ |
7726 | if (warn_sizeof_pointer_memaccess) |
7727 | sizeof_pointer_memaccess_warning (sizeof_arg_loc, | |
1a4049e7 | 7728 | expr.value, exprlist, |
3a785c97 | 7729 | sizeof_arg, |
1a4049e7 | 7730 | sizeof_ptr_memacc_comptypes); |
b108f48f JJ |
7731 | if (warn_memset_transposed_args |
7732 | && TREE_CODE (expr.value) == FUNCTION_DECL | |
7733 | && DECL_BUILT_IN_CLASS (expr.value) == BUILT_IN_NORMAL | |
7734 | && DECL_FUNCTION_CODE (expr.value) == BUILT_IN_MEMSET | |
7735 | && vec_safe_length (exprlist) == 3 | |
7736 | && integer_zerop ((*exprlist)[2]) | |
7737 | && (literal_zero_mask & (1 << 2)) != 0 | |
7738 | && (!integer_zerop ((*exprlist)[1]) | |
7739 | || (literal_zero_mask & (1 << 1)) == 0)) | |
7740 | warning_at (expr_loc, OPT_Wmemset_transposed_args, | |
7741 | "%<memset%> used with constant zero length parameter; " | |
7742 | "this could be due to transposed parameters"); | |
7743 | ||
8edbfaa6 JJ |
7744 | expr.value |
7745 | = c_build_function_call_vec (expr_loc, arg_loc, expr.value, | |
7746 | exprlist, origtypes); | |
27bf414c | 7747 | expr.original_code = ERROR_MARK; |
928c19bb JM |
7748 | if (TREE_CODE (expr.value) == INTEGER_CST |
7749 | && TREE_CODE (orig_expr.value) == FUNCTION_DECL | |
7750 | && DECL_BUILT_IN_CLASS (orig_expr.value) == BUILT_IN_NORMAL | |
7751 | && DECL_FUNCTION_CODE (orig_expr.value) == BUILT_IN_CONSTANT_P) | |
7752 | expr.original_code = C_MAYBE_CONST_EXPR; | |
6866c6e8 | 7753 | expr.original_type = NULL; |
9771b263 | 7754 | if (exprlist) |
bbbbb16a | 7755 | { |
c166b898 ILT |
7756 | release_tree_vector (exprlist); |
7757 | release_tree_vector (origtypes); | |
bbbbb16a | 7758 | } |
81e5eca8 | 7759 | arg_loc.release (); |
27bf414c JM |
7760 | break; |
7761 | case CPP_DOT: | |
7762 | /* Structure element reference. */ | |
7763 | c_parser_consume_token (parser); | |
c2255bc4 | 7764 | expr = default_function_array_conversion (expr_loc, expr); |
27bf414c JM |
7765 | if (c_parser_next_token_is (parser, CPP_NAME)) |
7766 | ident = c_parser_peek_token (parser)->value; | |
7767 | else | |
7768 | { | |
7769 | c_parser_error (parser, "expected identifier"); | |
7770 | expr.value = error_mark_node; | |
7771 | expr.original_code = ERROR_MARK; | |
6866c6e8 | 7772 | expr.original_type = NULL; |
27bf414c JM |
7773 | return expr; |
7774 | } | |
7775 | c_parser_consume_token (parser); | |
c2255bc4 | 7776 | expr.value = build_component_ref (op_loc, expr.value, ident); |
27bf414c | 7777 | expr.original_code = ERROR_MARK; |
6866c6e8 ILT |
7778 | if (TREE_CODE (expr.value) != COMPONENT_REF) |
7779 | expr.original_type = NULL; | |
7780 | else | |
7781 | { | |
7782 | /* Remember the original type of a bitfield. */ | |
7783 | tree field = TREE_OPERAND (expr.value, 1); | |
7784 | if (TREE_CODE (field) != FIELD_DECL) | |
7785 | expr.original_type = NULL; | |
7786 | else | |
7787 | expr.original_type = DECL_BIT_FIELD_TYPE (field); | |
7788 | } | |
27bf414c JM |
7789 | break; |
7790 | case CPP_DEREF: | |
7791 | /* Structure element reference. */ | |
7792 | c_parser_consume_token (parser); | |
267bac10 | 7793 | expr = convert_lvalue_to_rvalue (expr_loc, expr, true, false); |
27bf414c JM |
7794 | if (c_parser_next_token_is (parser, CPP_NAME)) |
7795 | ident = c_parser_peek_token (parser)->value; | |
7796 | else | |
7797 | { | |
7798 | c_parser_error (parser, "expected identifier"); | |
7799 | expr.value = error_mark_node; | |
7800 | expr.original_code = ERROR_MARK; | |
6866c6e8 | 7801 | expr.original_type = NULL; |
27bf414c JM |
7802 | return expr; |
7803 | } | |
7804 | c_parser_consume_token (parser); | |
c2255bc4 AH |
7805 | expr.value = build_component_ref (op_loc, |
7806 | build_indirect_ref (op_loc, | |
c9f9eb5d | 7807 | expr.value, |
dd865ef6 | 7808 | RO_ARROW), |
6a3799eb | 7809 | ident); |
27bf414c | 7810 | expr.original_code = ERROR_MARK; |
6866c6e8 ILT |
7811 | if (TREE_CODE (expr.value) != COMPONENT_REF) |
7812 | expr.original_type = NULL; | |
7813 | else | |
7814 | { | |
7815 | /* Remember the original type of a bitfield. */ | |
7816 | tree field = TREE_OPERAND (expr.value, 1); | |
7817 | if (TREE_CODE (field) != FIELD_DECL) | |
7818 | expr.original_type = NULL; | |
7819 | else | |
7820 | expr.original_type = DECL_BIT_FIELD_TYPE (field); | |
7821 | } | |
27bf414c JM |
7822 | break; |
7823 | case CPP_PLUS_PLUS: | |
7824 | /* Postincrement. */ | |
7825 | c_parser_consume_token (parser); | |
36536d79 | 7826 | /* If the expressions have array notations, we expand them. */ |
b72271b9 | 7827 | if (flag_cilkplus |
36536d79 BI |
7828 | && TREE_CODE (expr.value) == ARRAY_NOTATION_REF) |
7829 | expr = fix_array_notation_expr (expr_loc, POSTINCREMENT_EXPR, expr); | |
7830 | else | |
7831 | { | |
7832 | expr = default_function_array_read_conversion (expr_loc, expr); | |
7833 | expr.value = build_unary_op (op_loc, | |
7834 | POSTINCREMENT_EXPR, expr.value, 0); | |
7835 | } | |
27bf414c | 7836 | expr.original_code = ERROR_MARK; |
6866c6e8 | 7837 | expr.original_type = NULL; |
27bf414c JM |
7838 | break; |
7839 | case CPP_MINUS_MINUS: | |
7840 | /* Postdecrement. */ | |
7841 | c_parser_consume_token (parser); | |
36536d79 | 7842 | /* If the expressions have array notations, we expand them. */ |
b72271b9 | 7843 | if (flag_cilkplus |
36536d79 BI |
7844 | && TREE_CODE (expr.value) == ARRAY_NOTATION_REF) |
7845 | expr = fix_array_notation_expr (expr_loc, POSTDECREMENT_EXPR, expr); | |
7846 | else | |
7847 | { | |
7848 | expr = default_function_array_read_conversion (expr_loc, expr); | |
7849 | expr.value = build_unary_op (op_loc, | |
7850 | POSTDECREMENT_EXPR, expr.value, 0); | |
7851 | } | |
27bf414c | 7852 | expr.original_code = ERROR_MARK; |
6866c6e8 | 7853 | expr.original_type = NULL; |
27bf414c JM |
7854 | break; |
7855 | default: | |
7856 | return expr; | |
7857 | } | |
7858 | } | |
7859 | } | |
7860 | ||
7861 | /* Parse an expression (C90 6.3.17, C99 6.5.17). | |
7862 | ||
7863 | expression: | |
7864 | assignment-expression | |
7865 | expression , assignment-expression | |
7866 | */ | |
7867 | ||
7868 | static struct c_expr | |
7869 | c_parser_expression (c_parser *parser) | |
7870 | { | |
267bac10 | 7871 | location_t tloc = c_parser_peek_token (parser)->location; |
27bf414c JM |
7872 | struct c_expr expr; |
7873 | expr = c_parser_expr_no_commas (parser, NULL); | |
267bac10 JM |
7874 | if (c_parser_next_token_is (parser, CPP_COMMA)) |
7875 | expr = convert_lvalue_to_rvalue (tloc, expr, true, false); | |
27bf414c JM |
7876 | while (c_parser_next_token_is (parser, CPP_COMMA)) |
7877 | { | |
7878 | struct c_expr next; | |
056928b2 | 7879 | tree lhsval; |
c2255bc4 AH |
7880 | location_t loc = c_parser_peek_token (parser)->location; |
7881 | location_t expr_loc; | |
27bf414c | 7882 | c_parser_consume_token (parser); |
c2255bc4 | 7883 | expr_loc = c_parser_peek_token (parser)->location; |
056928b2 JJ |
7884 | lhsval = expr.value; |
7885 | while (TREE_CODE (lhsval) == COMPOUND_EXPR) | |
7886 | lhsval = TREE_OPERAND (lhsval, 1); | |
7887 | if (DECL_P (lhsval) || handled_component_p (lhsval)) | |
7888 | mark_exp_read (lhsval); | |
27bf414c | 7889 | next = c_parser_expr_no_commas (parser, NULL); |
267bac10 | 7890 | next = convert_lvalue_to_rvalue (expr_loc, next, true, false); |
c2255bc4 | 7891 | expr.value = build_compound_expr (loc, expr.value, next.value); |
27bf414c | 7892 | expr.original_code = COMPOUND_EXPR; |
81f40b79 | 7893 | expr.original_type = next.original_type; |
27bf414c JM |
7894 | } |
7895 | return expr; | |
7896 | } | |
7897 | ||
267bac10 JM |
7898 | /* Parse an expression and convert functions or arrays to pointers and |
7899 | lvalues to rvalues. */ | |
46bdb9cf JM |
7900 | |
7901 | static struct c_expr | |
7902 | c_parser_expression_conv (c_parser *parser) | |
7903 | { | |
7904 | struct c_expr expr; | |
c2255bc4 | 7905 | location_t loc = c_parser_peek_token (parser)->location; |
46bdb9cf | 7906 | expr = c_parser_expression (parser); |
267bac10 | 7907 | expr = convert_lvalue_to_rvalue (loc, expr, true, false); |
46bdb9cf JM |
7908 | return expr; |
7909 | } | |
7910 | ||
b108f48f JJ |
7911 | /* Helper function of c_parser_expr_list. Check if IDXth (0 based) |
7912 | argument is a literal zero alone and if so, set it in literal_zero_mask. */ | |
7913 | ||
7914 | static inline void | |
7915 | c_parser_check_literal_zero (c_parser *parser, unsigned *literal_zero_mask, | |
7916 | unsigned int idx) | |
7917 | { | |
7918 | if (idx >= HOST_BITS_PER_INT) | |
7919 | return; | |
7920 | ||
7921 | c_token *tok = c_parser_peek_token (parser); | |
7922 | switch (tok->type) | |
7923 | { | |
7924 | case CPP_NUMBER: | |
7925 | case CPP_CHAR: | |
7926 | case CPP_WCHAR: | |
7927 | case CPP_CHAR16: | |
7928 | case CPP_CHAR32: | |
7929 | /* If a parameter is literal zero alone, remember it | |
7930 | for -Wmemset-transposed-args warning. */ | |
7931 | if (integer_zerop (tok->value) | |
7932 | && !TREE_OVERFLOW (tok->value) | |
7933 | && (c_parser_peek_2nd_token (parser)->type == CPP_COMMA | |
7934 | || c_parser_peek_2nd_token (parser)->type == CPP_CLOSE_PAREN)) | |
7935 | *literal_zero_mask |= 1U << idx; | |
7936 | default: | |
7937 | break; | |
7938 | } | |
7939 | } | |
7940 | ||
46bdb9cf | 7941 | /* Parse a non-empty list of expressions. If CONVERT_P, convert |
267bac10 | 7942 | functions and arrays to pointers and lvalues to rvalues. If |
81e5eca8 MP |
7943 | FOLD_P, fold the expressions. If LOCATIONS is non-NULL, save the |
7944 | locations of function arguments into this vector. | |
27bf414c JM |
7945 | |
7946 | nonempty-expr-list: | |
7947 | assignment-expression | |
7948 | nonempty-expr-list , assignment-expression | |
7949 | */ | |
7950 | ||
9771b263 | 7951 | static vec<tree, va_gc> * |
bbbbb16a | 7952 | c_parser_expr_list (c_parser *parser, bool convert_p, bool fold_p, |
9771b263 | 7953 | vec<tree, va_gc> **p_orig_types, |
81e5eca8 | 7954 | location_t *sizeof_arg_loc, tree *sizeof_arg, |
b108f48f JJ |
7955 | vec<location_t> *locations, |
7956 | unsigned int *literal_zero_mask) | |
27bf414c | 7957 | { |
9771b263 DN |
7958 | vec<tree, va_gc> *ret; |
7959 | vec<tree, va_gc> *orig_types; | |
27bf414c | 7960 | struct c_expr expr; |
c2255bc4 | 7961 | location_t loc = c_parser_peek_token (parser)->location; |
3a785c97 JJ |
7962 | location_t cur_sizeof_arg_loc = UNKNOWN_LOCATION; |
7963 | unsigned int idx = 0; | |
bbbbb16a | 7964 | |
c166b898 | 7965 | ret = make_tree_vector (); |
bbbbb16a ILT |
7966 | if (p_orig_types == NULL) |
7967 | orig_types = NULL; | |
7968 | else | |
c166b898 | 7969 | orig_types = make_tree_vector (); |
bbbbb16a | 7970 | |
1a4049e7 JJ |
7971 | if (sizeof_arg != NULL |
7972 | && c_parser_next_token_is_keyword (parser, RID_SIZEOF)) | |
3a785c97 | 7973 | cur_sizeof_arg_loc = c_parser_peek_2nd_token (parser)->location; |
b108f48f JJ |
7974 | if (literal_zero_mask) |
7975 | c_parser_check_literal_zero (parser, literal_zero_mask, 0); | |
27bf414c | 7976 | expr = c_parser_expr_no_commas (parser, NULL); |
46bdb9cf | 7977 | if (convert_p) |
267bac10 | 7978 | expr = convert_lvalue_to_rvalue (loc, expr, true, true); |
928c19bb JM |
7979 | if (fold_p) |
7980 | expr.value = c_fully_fold (expr.value, false, NULL); | |
9771b263 DN |
7981 | ret->quick_push (expr.value); |
7982 | if (orig_types) | |
7983 | orig_types->quick_push (expr.original_type); | |
81e5eca8 MP |
7984 | if (locations) |
7985 | locations->safe_push (loc); | |
3a785c97 JJ |
7986 | if (sizeof_arg != NULL |
7987 | && cur_sizeof_arg_loc != UNKNOWN_LOCATION | |
7988 | && expr.original_code == SIZEOF_EXPR) | |
7989 | { | |
7990 | sizeof_arg[0] = c_last_sizeof_arg; | |
7991 | sizeof_arg_loc[0] = cur_sizeof_arg_loc; | |
7992 | } | |
27bf414c JM |
7993 | while (c_parser_next_token_is (parser, CPP_COMMA)) |
7994 | { | |
7995 | c_parser_consume_token (parser); | |
c2255bc4 | 7996 | loc = c_parser_peek_token (parser)->location; |
1a4049e7 JJ |
7997 | if (sizeof_arg != NULL |
7998 | && c_parser_next_token_is_keyword (parser, RID_SIZEOF)) | |
3a785c97 | 7999 | cur_sizeof_arg_loc = c_parser_peek_2nd_token (parser)->location; |
1a4049e7 | 8000 | else |
3a785c97 | 8001 | cur_sizeof_arg_loc = UNKNOWN_LOCATION; |
b108f48f JJ |
8002 | if (literal_zero_mask) |
8003 | c_parser_check_literal_zero (parser, literal_zero_mask, idx + 1); | |
27bf414c | 8004 | expr = c_parser_expr_no_commas (parser, NULL); |
46bdb9cf | 8005 | if (convert_p) |
267bac10 | 8006 | expr = convert_lvalue_to_rvalue (loc, expr, true, true); |
928c19bb JM |
8007 | if (fold_p) |
8008 | expr.value = c_fully_fold (expr.value, false, NULL); | |
9771b263 DN |
8009 | vec_safe_push (ret, expr.value); |
8010 | if (orig_types) | |
8011 | vec_safe_push (orig_types, expr.original_type); | |
81e5eca8 MP |
8012 | if (locations) |
8013 | locations->safe_push (loc); | |
3a785c97 JJ |
8014 | if (++idx < 3 |
8015 | && sizeof_arg != NULL | |
8016 | && cur_sizeof_arg_loc != UNKNOWN_LOCATION | |
1a4049e7 JJ |
8017 | && expr.original_code == SIZEOF_EXPR) |
8018 | { | |
3a785c97 JJ |
8019 | sizeof_arg[idx] = c_last_sizeof_arg; |
8020 | sizeof_arg_loc[idx] = cur_sizeof_arg_loc; | |
1a4049e7 JJ |
8021 | } |
8022 | } | |
9771b263 | 8023 | if (orig_types) |
bbbbb16a | 8024 | *p_orig_types = orig_types; |
27bf414c JM |
8025 | return ret; |
8026 | } | |
27bf414c JM |
8027 | \f |
8028 | /* Parse Objective-C-specific constructs. */ | |
8029 | ||
8030 | /* Parse an objc-class-definition. | |
8031 | ||
8032 | objc-class-definition: | |
8033 | @interface identifier objc-superclass[opt] objc-protocol-refs[opt] | |
8034 | objc-class-instance-variables[opt] objc-methodprotolist @end | |
8035 | @implementation identifier objc-superclass[opt] | |
8036 | objc-class-instance-variables[opt] | |
8037 | @interface identifier ( identifier ) objc-protocol-refs[opt] | |
8038 | objc-methodprotolist @end | |
ec3e9f82 NP |
8039 | @interface identifier ( ) objc-protocol-refs[opt] |
8040 | objc-methodprotolist @end | |
27bf414c JM |
8041 | @implementation identifier ( identifier ) |
8042 | ||
8043 | objc-superclass: | |
8044 | : identifier | |
8045 | ||
8046 | "@interface identifier (" must start "@interface identifier ( | |
8047 | identifier ) ...": objc-methodprotolist in the first production may | |
0fa2e4df | 8048 | not start with a parenthesized identifier as a declarator of a data |
27bf414c JM |
8049 | definition with no declaration specifiers if the objc-superclass, |
8050 | objc-protocol-refs and objc-class-instance-variables are omitted. */ | |
8051 | ||
8052 | static void | |
c165dca7 | 8053 | c_parser_objc_class_definition (c_parser *parser, tree attributes) |
27bf414c JM |
8054 | { |
8055 | bool iface_p; | |
8056 | tree id1; | |
8057 | tree superclass; | |
8058 | if (c_parser_next_token_is_keyword (parser, RID_AT_INTERFACE)) | |
8059 | iface_p = true; | |
8060 | else if (c_parser_next_token_is_keyword (parser, RID_AT_IMPLEMENTATION)) | |
8061 | iface_p = false; | |
8062 | else | |
8063 | gcc_unreachable (); | |
c165dca7 | 8064 | |
27bf414c JM |
8065 | c_parser_consume_token (parser); |
8066 | if (c_parser_next_token_is_not (parser, CPP_NAME)) | |
8067 | { | |
8068 | c_parser_error (parser, "expected identifier"); | |
8069 | return; | |
8070 | } | |
8071 | id1 = c_parser_peek_token (parser)->value; | |
8072 | c_parser_consume_token (parser); | |
8073 | if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) | |
8074 | { | |
ec3e9f82 | 8075 | /* We have a category or class extension. */ |
27bf414c JM |
8076 | tree id2; |
8077 | tree proto = NULL_TREE; | |
8078 | c_parser_consume_token (parser); | |
8079 | if (c_parser_next_token_is_not (parser, CPP_NAME)) | |
8080 | { | |
ec3e9f82 NP |
8081 | if (iface_p && c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) |
8082 | { | |
8083 | /* We have a class extension. */ | |
8084 | id2 = NULL_TREE; | |
8085 | } | |
8086 | else | |
8087 | { | |
8088 | c_parser_error (parser, "expected identifier or %<)%>"); | |
8089 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); | |
8090 | return; | |
8091 | } | |
8092 | } | |
8093 | else | |
8094 | { | |
8095 | id2 = c_parser_peek_token (parser)->value; | |
8096 | c_parser_consume_token (parser); | |
27bf414c | 8097 | } |
27bf414c JM |
8098 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); |
8099 | if (!iface_p) | |
8100 | { | |
8101 | objc_start_category_implementation (id1, id2); | |
8102 | return; | |
8103 | } | |
8104 | if (c_parser_next_token_is (parser, CPP_LESS)) | |
8105 | proto = c_parser_objc_protocol_refs (parser); | |
c165dca7 | 8106 | objc_start_category_interface (id1, id2, proto, attributes); |
27bf414c JM |
8107 | c_parser_objc_methodprotolist (parser); |
8108 | c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>"); | |
8109 | objc_finish_interface (); | |
8110 | return; | |
8111 | } | |
8112 | if (c_parser_next_token_is (parser, CPP_COLON)) | |
8113 | { | |
8114 | c_parser_consume_token (parser); | |
8115 | if (c_parser_next_token_is_not (parser, CPP_NAME)) | |
8116 | { | |
8117 | c_parser_error (parser, "expected identifier"); | |
8118 | return; | |
8119 | } | |
8120 | superclass = c_parser_peek_token (parser)->value; | |
8121 | c_parser_consume_token (parser); | |
8122 | } | |
8123 | else | |
8124 | superclass = NULL_TREE; | |
8125 | if (iface_p) | |
8126 | { | |
8127 | tree proto = NULL_TREE; | |
8128 | if (c_parser_next_token_is (parser, CPP_LESS)) | |
8129 | proto = c_parser_objc_protocol_refs (parser); | |
c165dca7 | 8130 | objc_start_class_interface (id1, superclass, proto, attributes); |
27bf414c JM |
8131 | } |
8132 | else | |
8133 | objc_start_class_implementation (id1, superclass); | |
8134 | if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) | |
8135 | c_parser_objc_class_instance_variables (parser); | |
8136 | if (iface_p) | |
8137 | { | |
8138 | objc_continue_interface (); | |
8139 | c_parser_objc_methodprotolist (parser); | |
8140 | c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>"); | |
8141 | objc_finish_interface (); | |
8142 | } | |
8143 | else | |
8144 | { | |
8145 | objc_continue_implementation (); | |
8146 | return; | |
8147 | } | |
8148 | } | |
8149 | ||
8150 | /* Parse objc-class-instance-variables. | |
8151 | ||
8152 | objc-class-instance-variables: | |
8153 | { objc-instance-variable-decl-list[opt] } | |
8154 | ||
8155 | objc-instance-variable-decl-list: | |
8156 | objc-visibility-spec | |
8157 | objc-instance-variable-decl ; | |
8158 | ; | |
8159 | objc-instance-variable-decl-list objc-visibility-spec | |
8160 | objc-instance-variable-decl-list objc-instance-variable-decl ; | |
8161 | objc-instance-variable-decl-list ; | |
8162 | ||
8163 | objc-visibility-spec: | |
8164 | @private | |
8165 | @protected | |
8166 | @public | |
8167 | ||
8168 | objc-instance-variable-decl: | |
8169 | struct-declaration | |
8170 | */ | |
8171 | ||
8172 | static void | |
8173 | c_parser_objc_class_instance_variables (c_parser *parser) | |
8174 | { | |
8175 | gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE)); | |
8176 | c_parser_consume_token (parser); | |
8177 | while (c_parser_next_token_is_not (parser, CPP_EOF)) | |
8178 | { | |
8179 | tree decls; | |
8180 | /* Parse any stray semicolon. */ | |
8181 | if (c_parser_next_token_is (parser, CPP_SEMICOLON)) | |
8182 | { | |
c1771a20 | 8183 | pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic, |
4e26ba90 | 8184 | "extra semicolon"); |
27bf414c JM |
8185 | c_parser_consume_token (parser); |
8186 | continue; | |
8187 | } | |
8188 | /* Stop if at the end of the instance variables. */ | |
8189 | if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) | |
8190 | { | |
8191 | c_parser_consume_token (parser); | |
8192 | break; | |
8193 | } | |
8194 | /* Parse any objc-visibility-spec. */ | |
49b91f05 | 8195 | if (c_parser_next_token_is_keyword (parser, RID_AT_PRIVATE)) |
27bf414c JM |
8196 | { |
8197 | c_parser_consume_token (parser); | |
c37d8c30 | 8198 | objc_set_visibility (OBJC_IVAR_VIS_PRIVATE); |
27bf414c JM |
8199 | continue; |
8200 | } | |
49b91f05 | 8201 | else if (c_parser_next_token_is_keyword (parser, RID_AT_PROTECTED)) |
27bf414c JM |
8202 | { |
8203 | c_parser_consume_token (parser); | |
c37d8c30 | 8204 | objc_set_visibility (OBJC_IVAR_VIS_PROTECTED); |
27bf414c JM |
8205 | continue; |
8206 | } | |
49b91f05 | 8207 | else if (c_parser_next_token_is_keyword (parser, RID_AT_PUBLIC)) |
27bf414c JM |
8208 | { |
8209 | c_parser_consume_token (parser); | |
c37d8c30 IS |
8210 | objc_set_visibility (OBJC_IVAR_VIS_PUBLIC); |
8211 | continue; | |
8212 | } | |
8213 | else if (c_parser_next_token_is_keyword (parser, RID_AT_PACKAGE)) | |
8214 | { | |
8215 | c_parser_consume_token (parser); | |
8216 | objc_set_visibility (OBJC_IVAR_VIS_PACKAGE); | |
27bf414c JM |
8217 | continue; |
8218 | } | |
bc4071dd RH |
8219 | else if (c_parser_next_token_is (parser, CPP_PRAGMA)) |
8220 | { | |
8221 | c_parser_pragma (parser, pragma_external); | |
8222 | continue; | |
8223 | } | |
8224 | ||
27bf414c JM |
8225 | /* Parse some comma-separated declarations. */ |
8226 | decls = c_parser_struct_declaration (parser); | |
4e26ba90 NP |
8227 | if (decls == NULL) |
8228 | { | |
8229 | /* There is a syntax error. We want to skip the offending | |
8230 | tokens up to the next ';' (included) or '}' | |
8231 | (excluded). */ | |
8232 | ||
8233 | /* First, skip manually a ')' or ']'. This is because they | |
8234 | reduce the nesting level, so c_parser_skip_until_found() | |
8235 | wouldn't be able to skip past them. */ | |
8236 | c_token *token = c_parser_peek_token (parser); | |
8237 | if (token->type == CPP_CLOSE_PAREN || token->type == CPP_CLOSE_SQUARE) | |
8238 | c_parser_consume_token (parser); | |
8239 | ||
8240 | /* Then, do the standard skipping. */ | |
8241 | c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL); | |
8242 | ||
8243 | /* We hopefully recovered. Start normal parsing again. */ | |
8244 | parser->error = false; | |
8245 | continue; | |
8246 | } | |
8247 | else | |
8248 | { | |
8249 | /* Comma-separated instance variables are chained together | |
8250 | in reverse order; add them one by one. */ | |
8251 | tree ivar = nreverse (decls); | |
8252 | for (; ivar; ivar = DECL_CHAIN (ivar)) | |
8253 | objc_add_instance_variable (copy_node (ivar)); | |
8254 | } | |
27bf414c JM |
8255 | c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); |
8256 | } | |
8257 | } | |
8258 | ||
8259 | /* Parse an objc-class-declaration. | |
8260 | ||
8261 | objc-class-declaration: | |
8262 | @class identifier-list ; | |
8263 | */ | |
8264 | ||
8265 | static void | |
8266 | c_parser_objc_class_declaration (c_parser *parser) | |
8267 | { | |
49b91f05 | 8268 | gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_CLASS)); |
27bf414c JM |
8269 | c_parser_consume_token (parser); |
8270 | /* Any identifiers, including those declared as type names, are OK | |
8271 | here. */ | |
8272 | while (true) | |
8273 | { | |
8274 | tree id; | |
8275 | if (c_parser_next_token_is_not (parser, CPP_NAME)) | |
8276 | { | |
8277 | c_parser_error (parser, "expected identifier"); | |
da57d1b9 NP |
8278 | c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL); |
8279 | parser->error = false; | |
8280 | return; | |
27bf414c JM |
8281 | } |
8282 | id = c_parser_peek_token (parser)->value; | |
32dabdaf | 8283 | objc_declare_class (id); |
27bf414c JM |
8284 | c_parser_consume_token (parser); |
8285 | if (c_parser_next_token_is (parser, CPP_COMMA)) | |
8286 | c_parser_consume_token (parser); | |
8287 | else | |
8288 | break; | |
8289 | } | |
8290 | c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); | |
27bf414c JM |
8291 | } |
8292 | ||
8293 | /* Parse an objc-alias-declaration. | |
8294 | ||
8295 | objc-alias-declaration: | |
8296 | @compatibility_alias identifier identifier ; | |
8297 | */ | |
8298 | ||
8299 | static void | |
8300 | c_parser_objc_alias_declaration (c_parser *parser) | |
8301 | { | |
8302 | tree id1, id2; | |
8303 | gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_ALIAS)); | |
8304 | c_parser_consume_token (parser); | |
8305 | if (c_parser_next_token_is_not (parser, CPP_NAME)) | |
8306 | { | |
8307 | c_parser_error (parser, "expected identifier"); | |
8308 | c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL); | |
8309 | return; | |
8310 | } | |
8311 | id1 = c_parser_peek_token (parser)->value; | |
8312 | c_parser_consume_token (parser); | |
8313 | if (c_parser_next_token_is_not (parser, CPP_NAME)) | |
8314 | { | |
8315 | c_parser_error (parser, "expected identifier"); | |
8316 | c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL); | |
8317 | return; | |
8318 | } | |
8319 | id2 = c_parser_peek_token (parser)->value; | |
8320 | c_parser_consume_token (parser); | |
8321 | c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); | |
8322 | objc_declare_alias (id1, id2); | |
8323 | } | |
8324 | ||
8325 | /* Parse an objc-protocol-definition. | |
8326 | ||
8327 | objc-protocol-definition: | |
8328 | @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end | |
8329 | @protocol identifier-list ; | |
8330 | ||
8331 | "@protocol identifier ;" should be resolved as "@protocol | |
8332 | identifier-list ;": objc-methodprotolist may not start with a | |
8333 | semicolon in the first alternative if objc-protocol-refs are | |
8334 | omitted. */ | |
8335 | ||
8336 | static void | |
c165dca7 | 8337 | c_parser_objc_protocol_definition (c_parser *parser, tree attributes) |
27bf414c JM |
8338 | { |
8339 | gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_PROTOCOL)); | |
c165dca7 | 8340 | |
27bf414c JM |
8341 | c_parser_consume_token (parser); |
8342 | if (c_parser_next_token_is_not (parser, CPP_NAME)) | |
8343 | { | |
8344 | c_parser_error (parser, "expected identifier"); | |
8345 | return; | |
8346 | } | |
8347 | if (c_parser_peek_2nd_token (parser)->type == CPP_COMMA | |
8348 | || c_parser_peek_2nd_token (parser)->type == CPP_SEMICOLON) | |
8349 | { | |
27bf414c JM |
8350 | /* Any identifiers, including those declared as type names, are |
8351 | OK here. */ | |
8352 | while (true) | |
8353 | { | |
8354 | tree id; | |
8355 | if (c_parser_next_token_is_not (parser, CPP_NAME)) | |
8356 | { | |
8357 | c_parser_error (parser, "expected identifier"); | |
8358 | break; | |
8359 | } | |
8360 | id = c_parser_peek_token (parser)->value; | |
c59633d9 | 8361 | objc_declare_protocol (id, attributes); |
27bf414c JM |
8362 | c_parser_consume_token (parser); |
8363 | if (c_parser_next_token_is (parser, CPP_COMMA)) | |
8364 | c_parser_consume_token (parser); | |
8365 | else | |
8366 | break; | |
8367 | } | |
8368 | c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); | |
27bf414c JM |
8369 | } |
8370 | else | |
8371 | { | |
8372 | tree id = c_parser_peek_token (parser)->value; | |
8373 | tree proto = NULL_TREE; | |
8374 | c_parser_consume_token (parser); | |
8375 | if (c_parser_next_token_is (parser, CPP_LESS)) | |
8376 | proto = c_parser_objc_protocol_refs (parser); | |
0bacb8c7 | 8377 | parser->objc_pq_context = true; |
c165dca7 | 8378 | objc_start_protocol (id, proto, attributes); |
27bf414c JM |
8379 | c_parser_objc_methodprotolist (parser); |
8380 | c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>"); | |
0bacb8c7 | 8381 | parser->objc_pq_context = false; |
27bf414c JM |
8382 | objc_finish_interface (); |
8383 | } | |
8384 | } | |
8385 | ||
8386 | /* Parse an objc-method-type. | |
8387 | ||
8388 | objc-method-type: | |
8389 | + | |
8390 | - | |
27bf414c | 8391 | |
249a82c4 NP |
8392 | Return true if it is a class method (+) and false if it is |
8393 | an instance method (-). | |
8394 | */ | |
8395 | static inline bool | |
27bf414c JM |
8396 | c_parser_objc_method_type (c_parser *parser) |
8397 | { | |
8398 | switch (c_parser_peek_token (parser)->type) | |
8399 | { | |
8400 | case CPP_PLUS: | |
8401 | c_parser_consume_token (parser); | |
249a82c4 | 8402 | return true; |
27bf414c JM |
8403 | case CPP_MINUS: |
8404 | c_parser_consume_token (parser); | |
249a82c4 | 8405 | return false; |
27bf414c JM |
8406 | default: |
8407 | gcc_unreachable (); | |
8408 | } | |
8409 | } | |
8410 | ||
8411 | /* Parse an objc-method-definition. | |
8412 | ||
8413 | objc-method-definition: | |
8414 | objc-method-type objc-method-decl ;[opt] compound-statement | |
8415 | */ | |
8416 | ||
8417 | static void | |
8418 | c_parser_objc_method_definition (c_parser *parser) | |
8419 | { | |
249a82c4 | 8420 | bool is_class_method = c_parser_objc_method_type (parser); |
a04a722b | 8421 | tree decl, attributes = NULL_TREE, expr = NULL_TREE; |
0bacb8c7 | 8422 | parser->objc_pq_context = true; |
a04a722b JM |
8423 | decl = c_parser_objc_method_decl (parser, is_class_method, &attributes, |
8424 | &expr); | |
f7e71da5 IS |
8425 | if (decl == error_mark_node) |
8426 | return; /* Bail here. */ | |
8427 | ||
27bf414c JM |
8428 | if (c_parser_next_token_is (parser, CPP_SEMICOLON)) |
8429 | { | |
8430 | c_parser_consume_token (parser); | |
c1771a20 | 8431 | pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic, |
509c9d60 | 8432 | "extra semicolon in method definition specified"); |
27bf414c | 8433 | } |
f7e71da5 | 8434 | |
8f078c08 AP |
8435 | if (!c_parser_next_token_is (parser, CPP_OPEN_BRACE)) |
8436 | { | |
8437 | c_parser_error (parser, "expected %<{%>"); | |
8438 | return; | |
8439 | } | |
f7e71da5 | 8440 | |
0bacb8c7 | 8441 | parser->objc_pq_context = false; |
a04a722b | 8442 | if (objc_start_method_definition (is_class_method, decl, attributes, expr)) |
45547c7f NP |
8443 | { |
8444 | add_stmt (c_parser_compound_statement (parser)); | |
8445 | objc_finish_method_definition (current_function_decl); | |
8446 | } | |
8447 | else | |
8448 | { | |
8449 | /* This code is executed when we find a method definition | |
a26d8862 NP |
8450 | outside of an @implementation context (or invalid for other |
8451 | reasons). Parse the method (to keep going) but do not emit | |
8452 | any code. | |
45547c7f NP |
8453 | */ |
8454 | c_parser_compound_statement (parser); | |
8455 | } | |
27bf414c JM |
8456 | } |
8457 | ||
8458 | /* Parse an objc-methodprotolist. | |
8459 | ||
8460 | objc-methodprotolist: | |
8461 | empty | |
8462 | objc-methodprotolist objc-methodproto | |
8463 | objc-methodprotolist declaration | |
8464 | objc-methodprotolist ; | |
92902b1b IS |
8465 | @optional |
8466 | @required | |
27bf414c JM |
8467 | |
8468 | The declaration is a data definition, which may be missing | |
8469 | declaration specifiers under the same rules and diagnostics as | |
8470 | other data definitions outside functions, and the stray semicolon | |
8471 | is diagnosed the same way as a stray semicolon outside a | |
8472 | function. */ | |
8473 | ||
8474 | static void | |
8475 | c_parser_objc_methodprotolist (c_parser *parser) | |
8476 | { | |
8477 | while (true) | |
8478 | { | |
8479 | /* The list is terminated by @end. */ | |
8480 | switch (c_parser_peek_token (parser)->type) | |
8481 | { | |
8482 | case CPP_SEMICOLON: | |
c1771a20 | 8483 | pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic, |
509c9d60 | 8484 | "ISO C does not allow extra %<;%> outside of a function"); |
27bf414c JM |
8485 | c_parser_consume_token (parser); |
8486 | break; | |
8487 | case CPP_PLUS: | |
8488 | case CPP_MINUS: | |
8489 | c_parser_objc_methodproto (parser); | |
8490 | break; | |
b9b58168 RH |
8491 | case CPP_PRAGMA: |
8492 | c_parser_pragma (parser, pragma_external); | |
8493 | break; | |
27bf414c JM |
8494 | case CPP_EOF: |
8495 | return; | |
8496 | default: | |
8497 | if (c_parser_next_token_is_keyword (parser, RID_AT_END)) | |
8498 | return; | |
668ea4b1 | 8499 | else if (c_parser_next_token_is_keyword (parser, RID_AT_PROPERTY)) |
f614132b | 8500 | c_parser_objc_at_property_declaration (parser); |
92902b1b IS |
8501 | else if (c_parser_next_token_is_keyword (parser, RID_AT_OPTIONAL)) |
8502 | { | |
8503 | objc_set_method_opt (true); | |
8504 | c_parser_consume_token (parser); | |
8505 | } | |
8506 | else if (c_parser_next_token_is_keyword (parser, RID_AT_REQUIRED)) | |
8507 | { | |
8508 | objc_set_method_opt (false); | |
8509 | c_parser_consume_token (parser); | |
8510 | } | |
8511 | else | |
8512 | c_parser_declaration_or_fndef (parser, false, false, true, | |
acf0174b | 8513 | false, true, NULL, vNULL); |
27bf414c JM |
8514 | break; |
8515 | } | |
8516 | } | |
8517 | } | |
8518 | ||
8519 | /* Parse an objc-methodproto. | |
8520 | ||
8521 | objc-methodproto: | |
8522 | objc-method-type objc-method-decl ; | |
8523 | */ | |
8524 | ||
8525 | static void | |
8526 | c_parser_objc_methodproto (c_parser *parser) | |
8527 | { | |
249a82c4 | 8528 | bool is_class_method = c_parser_objc_method_type (parser); |
f7e71da5 | 8529 | tree decl, attributes = NULL_TREE; |
249a82c4 | 8530 | |
27bf414c | 8531 | /* Remember protocol qualifiers in prototypes. */ |
0bacb8c7 | 8532 | parser->objc_pq_context = true; |
a04a722b JM |
8533 | decl = c_parser_objc_method_decl (parser, is_class_method, &attributes, |
8534 | NULL); | |
f7e71da5 | 8535 | /* Forget protocol qualifiers now. */ |
0bacb8c7 | 8536 | parser->objc_pq_context = false; |
f7e71da5 IS |
8537 | |
8538 | /* Do not allow the presence of attributes to hide an erroneous | |
8539 | method implementation in the interface section. */ | |
8540 | if (!c_parser_next_token_is (parser, CPP_SEMICOLON)) | |
8541 | { | |
8542 | c_parser_error (parser, "expected %<;%>"); | |
8543 | return; | |
8544 | } | |
8545 | ||
8546 | if (decl != error_mark_node) | |
249a82c4 | 8547 | objc_add_method_declaration (is_class_method, decl, attributes); |
f7e71da5 | 8548 | |
27bf414c JM |
8549 | c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); |
8550 | } | |
8551 | ||
f7e71da5 IS |
8552 | /* If we are at a position that method attributes may be present, check that |
8553 | there are not any parsed already (a syntax error) and then collect any | |
8554 | specified at the current location. Finally, if new attributes were present, | |
8555 | check that the next token is legal ( ';' for decls and '{' for defs). */ | |
8556 | ||
8557 | static bool | |
8558 | c_parser_objc_maybe_method_attributes (c_parser* parser, tree* attributes) | |
8559 | { | |
8560 | bool bad = false; | |
8561 | if (*attributes) | |
8562 | { | |
8563 | c_parser_error (parser, | |
8564 | "method attributes must be specified at the end only"); | |
8565 | *attributes = NULL_TREE; | |
8566 | bad = true; | |
8567 | } | |
8568 | ||
8569 | if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)) | |
8570 | *attributes = c_parser_attributes (parser); | |
8571 | ||
8572 | /* If there were no attributes here, just report any earlier error. */ | |
8573 | if (*attributes == NULL_TREE || bad) | |
8574 | return bad; | |
8575 | ||
8576 | /* If the attributes are followed by a ; or {, then just report any earlier | |
8577 | error. */ | |
8578 | if (c_parser_next_token_is (parser, CPP_SEMICOLON) | |
8579 | || c_parser_next_token_is (parser, CPP_OPEN_BRACE)) | |
8580 | return bad; | |
8581 | ||
8582 | /* We've got attributes, but not at the end. */ | |
8583 | c_parser_error (parser, | |
8584 | "expected %<;%> or %<{%> after method attribute definition"); | |
8585 | return true; | |
8586 | } | |
8587 | ||
27bf414c JM |
8588 | /* Parse an objc-method-decl. |
8589 | ||
8590 | objc-method-decl: | |
8591 | ( objc-type-name ) objc-selector | |
8592 | objc-selector | |
8593 | ( objc-type-name ) objc-keyword-selector objc-optparmlist | |
8594 | objc-keyword-selector objc-optparmlist | |
f7e71da5 | 8595 | attributes |
27bf414c JM |
8596 | |
8597 | objc-keyword-selector: | |
8598 | objc-keyword-decl | |
8599 | objc-keyword-selector objc-keyword-decl | |
8600 | ||
8601 | objc-keyword-decl: | |
8602 | objc-selector : ( objc-type-name ) identifier | |
8603 | objc-selector : identifier | |
8604 | : ( objc-type-name ) identifier | |
8605 | : identifier | |
8606 | ||
8607 | objc-optparmlist: | |
8608 | objc-optparms objc-optellipsis | |
8609 | ||
8610 | objc-optparms: | |
8611 | empty | |
8612 | objc-opt-parms , parameter-declaration | |
8613 | ||
8614 | objc-optellipsis: | |
8615 | empty | |
8616 | , ... | |
8617 | */ | |
8618 | ||
8619 | static tree | |
a04a722b JM |
8620 | c_parser_objc_method_decl (c_parser *parser, bool is_class_method, |
8621 | tree *attributes, tree *expr) | |
27bf414c JM |
8622 | { |
8623 | tree type = NULL_TREE; | |
8624 | tree sel; | |
8625 | tree parms = NULL_TREE; | |
dbb74365 | 8626 | bool ellipsis = false; |
f7e71da5 | 8627 | bool attr_err = false; |
dbb74365 | 8628 | |
f7e71da5 | 8629 | *attributes = NULL_TREE; |
27bf414c JM |
8630 | if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) |
8631 | { | |
8632 | c_parser_consume_token (parser); | |
8633 | type = c_parser_objc_type_name (parser); | |
8634 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
8635 | } | |
8636 | sel = c_parser_objc_selector (parser); | |
8637 | /* If there is no selector, or a colon follows, we have an | |
8638 | objc-keyword-selector. If there is a selector, and a colon does | |
8639 | not follow, that selector ends the objc-method-decl. */ | |
8640 | if (!sel || c_parser_next_token_is (parser, CPP_COLON)) | |
8641 | { | |
8642 | tree tsel = sel; | |
8643 | tree list = NULL_TREE; | |
27bf414c JM |
8644 | while (true) |
8645 | { | |
8646 | tree atype = NULL_TREE, id, keyworddecl; | |
f7e71da5 | 8647 | tree param_attr = NULL_TREE; |
27bf414c JM |
8648 | if (!c_parser_require (parser, CPP_COLON, "expected %<:%>")) |
8649 | break; | |
8650 | if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) | |
8651 | { | |
8652 | c_parser_consume_token (parser); | |
8653 | atype = c_parser_objc_type_name (parser); | |
8654 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, | |
8655 | "expected %<)%>"); | |
8656 | } | |
f7e71da5 IS |
8657 | /* New ObjC allows attributes on method parameters. */ |
8658 | if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)) | |
8659 | param_attr = c_parser_attributes (parser); | |
27bf414c JM |
8660 | if (c_parser_next_token_is_not (parser, CPP_NAME)) |
8661 | { | |
8662 | c_parser_error (parser, "expected identifier"); | |
8663 | return error_mark_node; | |
8664 | } | |
8665 | id = c_parser_peek_token (parser)->value; | |
8666 | c_parser_consume_token (parser); | |
f7e71da5 | 8667 | keyworddecl = objc_build_keyword_decl (tsel, atype, id, param_attr); |
27bf414c JM |
8668 | list = chainon (list, keyworddecl); |
8669 | tsel = c_parser_objc_selector (parser); | |
8670 | if (!tsel && c_parser_next_token_is_not (parser, CPP_COLON)) | |
8671 | break; | |
8672 | } | |
f7e71da5 IS |
8673 | |
8674 | attr_err |= c_parser_objc_maybe_method_attributes (parser, attributes) ; | |
8675 | ||
27bf414c JM |
8676 | /* Parse the optional parameter list. Optional Objective-C |
8677 | method parameters follow the C syntax, and may include '...' | |
8678 | to denote a variable number of arguments. */ | |
8679 | parms = make_node (TREE_LIST); | |
27bf414c JM |
8680 | while (c_parser_next_token_is (parser, CPP_COMMA)) |
8681 | { | |
8682 | struct c_parm *parm; | |
8683 | c_parser_consume_token (parser); | |
8684 | if (c_parser_next_token_is (parser, CPP_ELLIPSIS)) | |
8685 | { | |
8686 | ellipsis = true; | |
8687 | c_parser_consume_token (parser); | |
f7e71da5 IS |
8688 | attr_err |= c_parser_objc_maybe_method_attributes |
8689 | (parser, attributes) ; | |
27bf414c JM |
8690 | break; |
8691 | } | |
8692 | parm = c_parser_parameter_declaration (parser, NULL_TREE); | |
8693 | if (parm == NULL) | |
8694 | break; | |
8695 | parms = chainon (parms, | |
a04a722b | 8696 | build_tree_list (NULL_TREE, grokparm (parm, expr))); |
27bf414c | 8697 | } |
27bf414c JM |
8698 | sel = list; |
8699 | } | |
f7e71da5 IS |
8700 | else |
8701 | attr_err |= c_parser_objc_maybe_method_attributes (parser, attributes) ; | |
8702 | ||
8703 | if (sel == NULL) | |
8704 | { | |
8705 | c_parser_error (parser, "objective-c method declaration is expected"); | |
8706 | return error_mark_node; | |
8707 | } | |
8708 | ||
8709 | if (attr_err) | |
8710 | return error_mark_node; | |
8711 | ||
249a82c4 | 8712 | return objc_build_method_signature (is_class_method, type, sel, parms, ellipsis); |
27bf414c JM |
8713 | } |
8714 | ||
8715 | /* Parse an objc-type-name. | |
8716 | ||
8717 | objc-type-name: | |
8718 | objc-type-qualifiers[opt] type-name | |
8719 | objc-type-qualifiers[opt] | |
8720 | ||
8721 | objc-type-qualifiers: | |
8722 | objc-type-qualifier | |
8723 | objc-type-qualifiers objc-type-qualifier | |
8724 | ||
8725 | objc-type-qualifier: one of | |
8726 | in out inout bycopy byref oneway | |
8727 | */ | |
8728 | ||
8729 | static tree | |
8730 | c_parser_objc_type_name (c_parser *parser) | |
8731 | { | |
8732 | tree quals = NULL_TREE; | |
d75d71e0 | 8733 | struct c_type_name *type_name = NULL; |
27bf414c JM |
8734 | tree type = NULL_TREE; |
8735 | while (true) | |
8736 | { | |
8737 | c_token *token = c_parser_peek_token (parser); | |
8738 | if (token->type == CPP_KEYWORD | |
8739 | && (token->keyword == RID_IN | |
8740 | || token->keyword == RID_OUT | |
8741 | || token->keyword == RID_INOUT | |
8742 | || token->keyword == RID_BYCOPY | |
8743 | || token->keyword == RID_BYREF | |
8744 | || token->keyword == RID_ONEWAY)) | |
8745 | { | |
71fc71d8 | 8746 | quals = chainon (build_tree_list (NULL_TREE, token->value), quals); |
27bf414c JM |
8747 | c_parser_consume_token (parser); |
8748 | } | |
8749 | else | |
8750 | break; | |
8751 | } | |
29ce73cb | 8752 | if (c_parser_next_tokens_start_typename (parser, cla_prefer_type)) |
d75d71e0 ILT |
8753 | type_name = c_parser_type_name (parser); |
8754 | if (type_name) | |
928c19bb | 8755 | type = groktypename (type_name, NULL, NULL); |
046608a3 NP |
8756 | |
8757 | /* If the type is unknown, and error has already been produced and | |
8758 | we need to recover from the error. In that case, use NULL_TREE | |
8759 | for the type, as if no type had been specified; this will use the | |
8760 | default type ('id') which is good for error recovery. */ | |
8761 | if (type == error_mark_node) | |
8762 | type = NULL_TREE; | |
8763 | ||
27bf414c JM |
8764 | return build_tree_list (quals, type); |
8765 | } | |
8766 | ||
8767 | /* Parse objc-protocol-refs. | |
8768 | ||
8769 | objc-protocol-refs: | |
8770 | < identifier-list > | |
8771 | */ | |
8772 | ||
8773 | static tree | |
8774 | c_parser_objc_protocol_refs (c_parser *parser) | |
8775 | { | |
8776 | tree list = NULL_TREE; | |
8777 | gcc_assert (c_parser_next_token_is (parser, CPP_LESS)); | |
8778 | c_parser_consume_token (parser); | |
8779 | /* Any identifiers, including those declared as type names, are OK | |
8780 | here. */ | |
8781 | while (true) | |
8782 | { | |
8783 | tree id; | |
8784 | if (c_parser_next_token_is_not (parser, CPP_NAME)) | |
8785 | { | |
8786 | c_parser_error (parser, "expected identifier"); | |
8787 | break; | |
8788 | } | |
8789 | id = c_parser_peek_token (parser)->value; | |
8790 | list = chainon (list, build_tree_list (NULL_TREE, id)); | |
8791 | c_parser_consume_token (parser); | |
8792 | if (c_parser_next_token_is (parser, CPP_COMMA)) | |
8793 | c_parser_consume_token (parser); | |
8794 | else | |
8795 | break; | |
8796 | } | |
8797 | c_parser_require (parser, CPP_GREATER, "expected %<>%>"); | |
8798 | return list; | |
8799 | } | |
8800 | ||
437c2322 | 8801 | /* Parse an objc-try-catch-finally-statement. |
27bf414c | 8802 | |
437c2322 | 8803 | objc-try-catch-finally-statement: |
27bf414c JM |
8804 | @try compound-statement objc-catch-list[opt] |
8805 | @try compound-statement objc-catch-list[opt] @finally compound-statement | |
8806 | ||
8807 | objc-catch-list: | |
437c2322 NP |
8808 | @catch ( objc-catch-parameter-declaration ) compound-statement |
8809 | objc-catch-list @catch ( objc-catch-parameter-declaration ) compound-statement | |
8810 | ||
8811 | objc-catch-parameter-declaration: | |
8812 | parameter-declaration | |
8813 | '...' | |
8814 | ||
8815 | where '...' is to be interpreted literally, that is, it means CPP_ELLIPSIS. | |
8816 | ||
8817 | PS: This function is identical to cp_parser_objc_try_catch_finally_statement | |
8818 | for C++. Keep them in sync. */ | |
27bf414c JM |
8819 | |
8820 | static void | |
437c2322 | 8821 | c_parser_objc_try_catch_finally_statement (c_parser *parser) |
27bf414c | 8822 | { |
437c2322 | 8823 | location_t location; |
27bf414c | 8824 | tree stmt; |
437c2322 | 8825 | |
49b91f05 | 8826 | gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_TRY)); |
27bf414c | 8827 | c_parser_consume_token (parser); |
437c2322 | 8828 | location = c_parser_peek_token (parser)->location; |
46270f14 | 8829 | objc_maybe_warn_exceptions (location); |
27bf414c | 8830 | stmt = c_parser_compound_statement (parser); |
437c2322 NP |
8831 | objc_begin_try_stmt (location, stmt); |
8832 | ||
49b91f05 | 8833 | while (c_parser_next_token_is_keyword (parser, RID_AT_CATCH)) |
27bf414c JM |
8834 | { |
8835 | struct c_parm *parm; | |
437c2322 NP |
8836 | tree parameter_declaration = error_mark_node; |
8837 | bool seen_open_paren = false; | |
8838 | ||
27bf414c JM |
8839 | c_parser_consume_token (parser); |
8840 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
437c2322 NP |
8841 | seen_open_paren = true; |
8842 | if (c_parser_next_token_is (parser, CPP_ELLIPSIS)) | |
27bf414c | 8843 | { |
437c2322 NP |
8844 | /* We have "@catch (...)" (where the '...' are literally |
8845 | what is in the code). Skip the '...'. | |
8846 | parameter_declaration is set to NULL_TREE, and | |
8847 | objc_being_catch_clauses() knows that that means | |
8848 | '...'. */ | |
8849 | c_parser_consume_token (parser); | |
8850 | parameter_declaration = NULL_TREE; | |
27bf414c | 8851 | } |
437c2322 NP |
8852 | else |
8853 | { | |
8854 | /* We have "@catch (NSException *exception)" or something | |
8855 | like that. Parse the parameter declaration. */ | |
8856 | parm = c_parser_parameter_declaration (parser, NULL_TREE); | |
8857 | if (parm == NULL) | |
8858 | parameter_declaration = error_mark_node; | |
8859 | else | |
a04a722b | 8860 | parameter_declaration = grokparm (parm, NULL); |
437c2322 NP |
8861 | } |
8862 | if (seen_open_paren) | |
8863 | c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
8864 | else | |
8865 | { | |
8866 | /* If there was no open parenthesis, we are recovering from | |
8867 | an error, and we are trying to figure out what mistake | |
8868 | the user has made. */ | |
8869 | ||
8870 | /* If there is an immediate closing parenthesis, the user | |
8871 | probably forgot the opening one (ie, they typed "@catch | |
8872 | NSException *e)". Parse the closing parenthesis and keep | |
8873 | going. */ | |
8874 | if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) | |
8875 | c_parser_consume_token (parser); | |
8876 | ||
8877 | /* If these is no immediate closing parenthesis, the user | |
8878 | probably doesn't know that parenthesis are required at | |
8879 | all (ie, they typed "@catch NSException *e"). So, just | |
8880 | forget about the closing parenthesis and keep going. */ | |
8881 | } | |
8882 | objc_begin_catch_clause (parameter_declaration); | |
27bf414c JM |
8883 | if (c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>")) |
8884 | c_parser_compound_statement_nostart (parser); | |
8885 | objc_finish_catch_clause (); | |
8886 | } | |
8887 | if (c_parser_next_token_is_keyword (parser, RID_AT_FINALLY)) | |
8888 | { | |
27bf414c | 8889 | c_parser_consume_token (parser); |
437c2322 NP |
8890 | location = c_parser_peek_token (parser)->location; |
8891 | stmt = c_parser_compound_statement (parser); | |
8892 | objc_build_finally_clause (location, stmt); | |
27bf414c JM |
8893 | } |
8894 | objc_finish_try_stmt (); | |
8895 | } | |
8896 | ||
8897 | /* Parse an objc-synchronized-statement. | |
8898 | ||
8899 | objc-synchronized-statement: | |
8900 | @synchronized ( expression ) compound-statement | |
8901 | */ | |
8902 | ||
8903 | static void | |
8904 | c_parser_objc_synchronized_statement (c_parser *parser) | |
8905 | { | |
8906 | location_t loc; | |
8907 | tree expr, stmt; | |
8908 | gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_SYNCHRONIZED)); | |
8909 | c_parser_consume_token (parser); | |
8910 | loc = c_parser_peek_token (parser)->location; | |
46270f14 | 8911 | objc_maybe_warn_exceptions (loc); |
27bf414c JM |
8912 | if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) |
8913 | { | |
267bac10 JM |
8914 | struct c_expr ce = c_parser_expression (parser); |
8915 | ce = convert_lvalue_to_rvalue (loc, ce, false, false); | |
8916 | expr = ce.value; | |
928c19bb | 8917 | expr = c_fully_fold (expr, false, NULL); |
27bf414c JM |
8918 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); |
8919 | } | |
8920 | else | |
8921 | expr = error_mark_node; | |
8922 | stmt = c_parser_compound_statement (parser); | |
8923 | objc_build_synchronized (loc, expr, stmt); | |
8924 | } | |
8925 | ||
8926 | /* Parse an objc-selector; return NULL_TREE without an error if the | |
8927 | next token is not an objc-selector. | |
8928 | ||
8929 | objc-selector: | |
8930 | identifier | |
8931 | one of | |
8932 | enum struct union if else while do for switch case default | |
8933 | break continue return goto asm sizeof typeof __alignof | |
8934 | unsigned long const short volatile signed restrict _Complex | |
8935 | in out inout bycopy byref oneway int char float double void _Bool | |
267bac10 | 8936 | _Atomic |
27bf414c JM |
8937 | |
8938 | ??? Why this selection of keywords but not, for example, storage | |
8939 | class specifiers? */ | |
8940 | ||
8941 | static tree | |
8942 | c_parser_objc_selector (c_parser *parser) | |
8943 | { | |
8944 | c_token *token = c_parser_peek_token (parser); | |
8945 | tree value = token->value; | |
8946 | if (token->type == CPP_NAME) | |
8947 | { | |
8948 | c_parser_consume_token (parser); | |
8949 | return value; | |
8950 | } | |
8951 | if (token->type != CPP_KEYWORD) | |
8952 | return NULL_TREE; | |
8953 | switch (token->keyword) | |
8954 | { | |
8955 | case RID_ENUM: | |
8956 | case RID_STRUCT: | |
8957 | case RID_UNION: | |
8958 | case RID_IF: | |
8959 | case RID_ELSE: | |
8960 | case RID_WHILE: | |
8961 | case RID_DO: | |
8962 | case RID_FOR: | |
8963 | case RID_SWITCH: | |
8964 | case RID_CASE: | |
8965 | case RID_DEFAULT: | |
8966 | case RID_BREAK: | |
8967 | case RID_CONTINUE: | |
8968 | case RID_RETURN: | |
8969 | case RID_GOTO: | |
8970 | case RID_ASM: | |
8971 | case RID_SIZEOF: | |
8972 | case RID_TYPEOF: | |
8973 | case RID_ALIGNOF: | |
8974 | case RID_UNSIGNED: | |
8975 | case RID_LONG: | |
a6766312 | 8976 | case RID_INT128: |
27bf414c JM |
8977 | case RID_CONST: |
8978 | case RID_SHORT: | |
8979 | case RID_VOLATILE: | |
8980 | case RID_SIGNED: | |
8981 | case RID_RESTRICT: | |
8982 | case RID_COMPLEX: | |
8983 | case RID_IN: | |
8984 | case RID_OUT: | |
8985 | case RID_INOUT: | |
8986 | case RID_BYCOPY: | |
8987 | case RID_BYREF: | |
8988 | case RID_ONEWAY: | |
8989 | case RID_INT: | |
8990 | case RID_CHAR: | |
8991 | case RID_FLOAT: | |
8992 | case RID_DOUBLE: | |
8993 | case RID_VOID: | |
8994 | case RID_BOOL: | |
267bac10 | 8995 | case RID_ATOMIC: |
38b7bc7f | 8996 | case RID_AUTO_TYPE: |
27bf414c JM |
8997 | c_parser_consume_token (parser); |
8998 | return value; | |
8999 | default: | |
9000 | return NULL_TREE; | |
9001 | } | |
9002 | } | |
9003 | ||
9004 | /* Parse an objc-selector-arg. | |
9005 | ||
9006 | objc-selector-arg: | |
9007 | objc-selector | |
9008 | objc-keywordname-list | |
9009 | ||
9010 | objc-keywordname-list: | |
9011 | objc-keywordname | |
9012 | objc-keywordname-list objc-keywordname | |
9013 | ||
9014 | objc-keywordname: | |
9015 | objc-selector : | |
9016 | : | |
9017 | */ | |
9018 | ||
9019 | static tree | |
9020 | c_parser_objc_selector_arg (c_parser *parser) | |
9021 | { | |
9022 | tree sel = c_parser_objc_selector (parser); | |
9023 | tree list = NULL_TREE; | |
9024 | if (sel && c_parser_next_token_is_not (parser, CPP_COLON)) | |
9025 | return sel; | |
9026 | while (true) | |
9027 | { | |
9028 | if (!c_parser_require (parser, CPP_COLON, "expected %<:%>")) | |
9029 | return list; | |
9030 | list = chainon (list, build_tree_list (sel, NULL_TREE)); | |
9031 | sel = c_parser_objc_selector (parser); | |
9032 | if (!sel && c_parser_next_token_is_not (parser, CPP_COLON)) | |
9033 | break; | |
9034 | } | |
9035 | return list; | |
9036 | } | |
9037 | ||
9038 | /* Parse an objc-receiver. | |
9039 | ||
9040 | objc-receiver: | |
9041 | expression | |
9042 | class-name | |
9043 | type-name | |
9044 | */ | |
9045 | ||
9046 | static tree | |
9047 | c_parser_objc_receiver (c_parser *parser) | |
9048 | { | |
267bac10 JM |
9049 | location_t loc = c_parser_peek_token (parser)->location; |
9050 | ||
27bf414c JM |
9051 | if (c_parser_peek_token (parser)->type == CPP_NAME |
9052 | && (c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME | |
9053 | || c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME)) | |
9054 | { | |
9055 | tree id = c_parser_peek_token (parser)->value; | |
9056 | c_parser_consume_token (parser); | |
9057 | return objc_get_class_reference (id); | |
9058 | } | |
267bac10 JM |
9059 | struct c_expr ce = c_parser_expression (parser); |
9060 | ce = convert_lvalue_to_rvalue (loc, ce, false, false); | |
9061 | return c_fully_fold (ce.value, false, NULL); | |
27bf414c JM |
9062 | } |
9063 | ||
9064 | /* Parse objc-message-args. | |
9065 | ||
9066 | objc-message-args: | |
9067 | objc-selector | |
9068 | objc-keywordarg-list | |
9069 | ||
9070 | objc-keywordarg-list: | |
9071 | objc-keywordarg | |
9072 | objc-keywordarg-list objc-keywordarg | |
9073 | ||
9074 | objc-keywordarg: | |
9075 | objc-selector : objc-keywordexpr | |
9076 | : objc-keywordexpr | |
9077 | */ | |
9078 | ||
9079 | static tree | |
9080 | c_parser_objc_message_args (c_parser *parser) | |
9081 | { | |
9082 | tree sel = c_parser_objc_selector (parser); | |
9083 | tree list = NULL_TREE; | |
9084 | if (sel && c_parser_next_token_is_not (parser, CPP_COLON)) | |
9085 | return sel; | |
9086 | while (true) | |
9087 | { | |
9088 | tree keywordexpr; | |
9089 | if (!c_parser_require (parser, CPP_COLON, "expected %<:%>")) | |
0a7d7dea | 9090 | return error_mark_node; |
27bf414c JM |
9091 | keywordexpr = c_parser_objc_keywordexpr (parser); |
9092 | list = chainon (list, build_tree_list (sel, keywordexpr)); | |
9093 | sel = c_parser_objc_selector (parser); | |
9094 | if (!sel && c_parser_next_token_is_not (parser, CPP_COLON)) | |
9095 | break; | |
9096 | } | |
9097 | return list; | |
9098 | } | |
9099 | ||
9100 | /* Parse an objc-keywordexpr. | |
9101 | ||
9102 | objc-keywordexpr: | |
9103 | nonempty-expr-list | |
9104 | */ | |
9105 | ||
9106 | static tree | |
9107 | c_parser_objc_keywordexpr (c_parser *parser) | |
9108 | { | |
bbbbb16a | 9109 | tree ret; |
9771b263 | 9110 | vec<tree, va_gc> *expr_list = c_parser_expr_list (parser, true, true, |
81e5eca8 | 9111 | NULL, NULL, NULL, NULL); |
9771b263 | 9112 | if (vec_safe_length (expr_list) == 1) |
27bf414c JM |
9113 | { |
9114 | /* Just return the expression, remove a level of | |
9115 | indirection. */ | |
9771b263 | 9116 | ret = (*expr_list)[0]; |
27bf414c JM |
9117 | } |
9118 | else | |
9119 | { | |
9120 | /* We have a comma expression, we will collapse later. */ | |
c166b898 | 9121 | ret = build_tree_list_vec (expr_list); |
27bf414c | 9122 | } |
c166b898 | 9123 | release_tree_vector (expr_list); |
bbbbb16a | 9124 | return ret; |
27bf414c JM |
9125 | } |
9126 | ||
c165dca7 IS |
9127 | /* A check, needed in several places, that ObjC interface, implementation or |
9128 | method definitions are not prefixed by incorrect items. */ | |
9129 | static bool | |
9130 | c_parser_objc_diagnose_bad_element_prefix (c_parser *parser, | |
9131 | struct c_declspecs *specs) | |
9132 | { | |
9e5b2115 PB |
9133 | if (!specs->declspecs_seen_p || specs->non_sc_seen_p |
9134 | || specs->typespec_kind != ctsk_none) | |
c165dca7 IS |
9135 | { |
9136 | c_parser_error (parser, | |
9137 | "no type or storage class may be specified here,"); | |
9138 | c_parser_skip_to_end_of_block_or_statement (parser); | |
9139 | return true; | |
9140 | } | |
9141 | return false; | |
9142 | } | |
668ea4b1 | 9143 | |
f614132b | 9144 | /* Parse an Objective-C @property declaration. The syntax is: |
668ea4b1 | 9145 | |
f614132b NP |
9146 | objc-property-declaration: |
9147 | '@property' objc-property-attributes[opt] struct-declaration ; | |
668ea4b1 | 9148 | |
f614132b NP |
9149 | objc-property-attributes: |
9150 | '(' objc-property-attribute-list ')' | |
9151 | ||
9152 | objc-property-attribute-list: | |
9153 | objc-property-attribute | |
9154 | objc-property-attribute-list, objc-property-attribute | |
9155 | ||
9156 | objc-property-attribute | |
9157 | 'getter' = identifier | |
9158 | 'setter' = identifier | |
9159 | 'readonly' | |
9160 | 'readwrite' | |
9161 | 'assign' | |
9162 | 'retain' | |
9163 | 'copy' | |
9164 | 'nonatomic' | |
9165 | ||
9166 | For example: | |
9167 | @property NSString *name; | |
9168 | @property (readonly) id object; | |
9169 | @property (retain, nonatomic, getter=getTheName) id name; | |
9170 | @property int a, b, c; | |
9171 | ||
9172 | PS: This function is identical to cp_parser_objc_at_propery_declaration | |
200290f2 | 9173 | for C++. Keep them in sync. */ |
668ea4b1 | 9174 | static void |
f614132b | 9175 | c_parser_objc_at_property_declaration (c_parser *parser) |
668ea4b1 | 9176 | { |
200290f2 NP |
9177 | /* The following variables hold the attributes of the properties as |
9178 | parsed. They are 'false' or 'NULL_TREE' if the attribute was not | |
9179 | seen. When we see an attribute, we set them to 'true' (if they | |
9180 | are boolean properties) or to the identifier (if they have an | |
9181 | argument, ie, for getter and setter). Note that here we only | |
9182 | parse the list of attributes, check the syntax and accumulate the | |
9183 | attributes that we find. objc_add_property_declaration() will | |
9184 | then process the information. */ | |
9185 | bool property_assign = false; | |
9186 | bool property_copy = false; | |
9187 | tree property_getter_ident = NULL_TREE; | |
9188 | bool property_nonatomic = false; | |
9189 | bool property_readonly = false; | |
9190 | bool property_readwrite = false; | |
9191 | bool property_retain = false; | |
9192 | tree property_setter_ident = NULL_TREE; | |
200290f2 NP |
9193 | |
9194 | /* 'properties' is the list of properties that we read. Usually a | |
9195 | single one, but maybe more (eg, in "@property int a, b, c;" there | |
9196 | are three). */ | |
f614132b NP |
9197 | tree properties; |
9198 | location_t loc; | |
200290f2 | 9199 | |
f614132b NP |
9200 | loc = c_parser_peek_token (parser)->location; |
9201 | gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_PROPERTY)); | |
668ea4b1 | 9202 | |
f614132b | 9203 | c_parser_consume_token (parser); /* Eat '@property'. */ |
668ea4b1 | 9204 | |
f614132b NP |
9205 | /* Parse the optional attribute list... */ |
9206 | if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) | |
668ea4b1 | 9207 | { |
f614132b NP |
9208 | /* Eat the '(' */ |
9209 | c_parser_consume_token (parser); | |
9210 | ||
9211 | /* Property attribute keywords are valid now. */ | |
9212 | parser->objc_property_attr_context = true; | |
9213 | ||
9214 | while (true) | |
668ea4b1 | 9215 | { |
f614132b NP |
9216 | bool syntax_error = false; |
9217 | c_token *token = c_parser_peek_token (parser); | |
9218 | enum rid keyword; | |
9219 | ||
9220 | if (token->type != CPP_KEYWORD) | |
9221 | { | |
9222 | if (token->type == CPP_CLOSE_PAREN) | |
9223 | c_parser_error (parser, "expected identifier"); | |
9224 | else | |
9225 | { | |
9226 | c_parser_consume_token (parser); | |
9227 | c_parser_error (parser, "unknown property attribute"); | |
9228 | } | |
9229 | break; | |
9230 | } | |
9231 | keyword = token->keyword; | |
200290f2 | 9232 | c_parser_consume_token (parser); |
f614132b NP |
9233 | switch (keyword) |
9234 | { | |
200290f2 | 9235 | case RID_ASSIGN: property_assign = true; break; |
200290f2 NP |
9236 | case RID_COPY: property_copy = true; break; |
9237 | case RID_NONATOMIC: property_nonatomic = true; break; | |
9238 | case RID_READONLY: property_readonly = true; break; | |
9239 | case RID_READWRITE: property_readwrite = true; break; | |
9240 | case RID_RETAIN: property_retain = true; break; | |
9241 | ||
f614132b NP |
9242 | case RID_GETTER: |
9243 | case RID_SETTER: | |
f614132b NP |
9244 | if (c_parser_next_token_is_not (parser, CPP_EQ)) |
9245 | { | |
d853ee42 NP |
9246 | if (keyword == RID_GETTER) |
9247 | c_parser_error (parser, | |
9248 | "missing %<=%> (after %<getter%> attribute)"); | |
9249 | else | |
9250 | c_parser_error (parser, | |
9251 | "missing %<=%> (after %<setter%> attribute)"); | |
f614132b NP |
9252 | syntax_error = true; |
9253 | break; | |
9254 | } | |
9255 | c_parser_consume_token (parser); /* eat the = */ | |
9256 | if (c_parser_next_token_is_not (parser, CPP_NAME)) | |
9257 | { | |
9258 | c_parser_error (parser, "expected identifier"); | |
9259 | syntax_error = true; | |
9260 | break; | |
9261 | } | |
f614132b NP |
9262 | if (keyword == RID_SETTER) |
9263 | { | |
200290f2 NP |
9264 | if (property_setter_ident != NULL_TREE) |
9265 | c_parser_error (parser, "the %<setter%> attribute may only be specified once"); | |
9266 | else | |
9267 | property_setter_ident = c_parser_peek_token (parser)->value; | |
f614132b | 9268 | c_parser_consume_token (parser); |
200290f2 NP |
9269 | if (c_parser_next_token_is_not (parser, CPP_COLON)) |
9270 | c_parser_error (parser, "setter name must terminate with %<:%>"); | |
9271 | else | |
9272 | c_parser_consume_token (parser); | |
f614132b | 9273 | } |
46a88c12 | 9274 | else |
f614132b | 9275 | { |
200290f2 NP |
9276 | if (property_getter_ident != NULL_TREE) |
9277 | c_parser_error (parser, "the %<getter%> attribute may only be specified once"); | |
9278 | else | |
9279 | property_getter_ident = c_parser_peek_token (parser)->value; | |
f614132b | 9280 | c_parser_consume_token (parser); |
f614132b | 9281 | } |
200290f2 NP |
9282 | break; |
9283 | default: | |
9284 | c_parser_error (parser, "unknown property attribute"); | |
f614132b NP |
9285 | syntax_error = true; |
9286 | break; | |
9287 | } | |
9288 | ||
9289 | if (syntax_error) | |
668ea4b1 | 9290 | break; |
f614132b NP |
9291 | |
9292 | if (c_parser_next_token_is (parser, CPP_COMMA)) | |
668ea4b1 | 9293 | c_parser_consume_token (parser); |
f614132b | 9294 | else |
668ea4b1 IS |
9295 | break; |
9296 | } | |
f614132b NP |
9297 | parser->objc_property_attr_context = false; |
9298 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
9299 | } | |
9300 | /* ... and the property declaration(s). */ | |
9301 | properties = c_parser_struct_declaration (parser); | |
668ea4b1 | 9302 | |
f614132b NP |
9303 | if (properties == error_mark_node) |
9304 | { | |
9305 | c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL); | |
9306 | parser->error = false; | |
9307 | return; | |
9308 | } | |
668ea4b1 | 9309 | |
f614132b NP |
9310 | if (properties == NULL_TREE) |
9311 | c_parser_error (parser, "expected identifier"); | |
9312 | else | |
9313 | { | |
9314 | /* Comma-separated properties are chained together in | |
9315 | reverse order; add them one by one. */ | |
9316 | properties = nreverse (properties); | |
9317 | ||
9318 | for (; properties; properties = TREE_CHAIN (properties)) | |
200290f2 NP |
9319 | objc_add_property_declaration (loc, copy_node (properties), |
9320 | property_readonly, property_readwrite, | |
9321 | property_assign, property_retain, | |
9322 | property_copy, property_nonatomic, | |
46a88c12 | 9323 | property_getter_ident, property_setter_ident); |
f614132b | 9324 | } |
668ea4b1 IS |
9325 | |
9326 | c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); | |
f614132b | 9327 | parser->error = false; |
668ea4b1 IS |
9328 | } |
9329 | ||
da57d1b9 NP |
9330 | /* Parse an Objective-C @synthesize declaration. The syntax is: |
9331 | ||
9332 | objc-synthesize-declaration: | |
9333 | @synthesize objc-synthesize-identifier-list ; | |
9334 | ||
9335 | objc-synthesize-identifier-list: | |
9336 | objc-synthesize-identifier | |
9337 | objc-synthesize-identifier-list, objc-synthesize-identifier | |
9338 | ||
9339 | objc-synthesize-identifier | |
9340 | identifier | |
9341 | identifier = identifier | |
9342 | ||
9343 | For example: | |
9344 | @synthesize MyProperty; | |
9345 | @synthesize OneProperty, AnotherProperty=MyIvar, YetAnotherProperty; | |
9346 | ||
9347 | PS: This function is identical to cp_parser_objc_at_synthesize_declaration | |
9348 | for C++. Keep them in sync. | |
9349 | */ | |
9350 | static void | |
9351 | c_parser_objc_at_synthesize_declaration (c_parser *parser) | |
9352 | { | |
9353 | tree list = NULL_TREE; | |
9354 | location_t loc; | |
9355 | gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_SYNTHESIZE)); | |
9356 | loc = c_parser_peek_token (parser)->location; | |
9357 | ||
9358 | c_parser_consume_token (parser); | |
9359 | while (true) | |
9360 | { | |
9361 | tree property, ivar; | |
9362 | if (c_parser_next_token_is_not (parser, CPP_NAME)) | |
9363 | { | |
9364 | c_parser_error (parser, "expected identifier"); | |
9365 | c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL); | |
9366 | /* Once we find the semicolon, we can resume normal parsing. | |
9367 | We have to reset parser->error manually because | |
9368 | c_parser_skip_until_found() won't reset it for us if the | |
9369 | next token is precisely a semicolon. */ | |
9370 | parser->error = false; | |
9371 | return; | |
9372 | } | |
9373 | property = c_parser_peek_token (parser)->value; | |
9374 | c_parser_consume_token (parser); | |
9375 | if (c_parser_next_token_is (parser, CPP_EQ)) | |
9376 | { | |
9377 | c_parser_consume_token (parser); | |
9378 | if (c_parser_next_token_is_not (parser, CPP_NAME)) | |
9379 | { | |
9380 | c_parser_error (parser, "expected identifier"); | |
9381 | c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL); | |
9382 | parser->error = false; | |
9383 | return; | |
9384 | } | |
9385 | ivar = c_parser_peek_token (parser)->value; | |
9386 | c_parser_consume_token (parser); | |
9387 | } | |
9388 | else | |
9389 | ivar = NULL_TREE; | |
9390 | list = chainon (list, build_tree_list (ivar, property)); | |
9391 | if (c_parser_next_token_is (parser, CPP_COMMA)) | |
9392 | c_parser_consume_token (parser); | |
9393 | else | |
9394 | break; | |
9395 | } | |
9396 | c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); | |
9397 | objc_add_synthesize_declaration (loc, list); | |
9398 | } | |
9399 | ||
9400 | /* Parse an Objective-C @dynamic declaration. The syntax is: | |
9401 | ||
9402 | objc-dynamic-declaration: | |
9403 | @dynamic identifier-list ; | |
9404 | ||
9405 | For example: | |
9406 | @dynamic MyProperty; | |
9407 | @dynamic MyProperty, AnotherProperty; | |
9408 | ||
9409 | PS: This function is identical to cp_parser_objc_at_dynamic_declaration | |
9410 | for C++. Keep them in sync. | |
9411 | */ | |
9412 | static void | |
9413 | c_parser_objc_at_dynamic_declaration (c_parser *parser) | |
9414 | { | |
9415 | tree list = NULL_TREE; | |
9416 | location_t loc; | |
9417 | gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_DYNAMIC)); | |
9418 | loc = c_parser_peek_token (parser)->location; | |
9419 | ||
9420 | c_parser_consume_token (parser); | |
9421 | while (true) | |
9422 | { | |
9423 | tree property; | |
9424 | if (c_parser_next_token_is_not (parser, CPP_NAME)) | |
9425 | { | |
9426 | c_parser_error (parser, "expected identifier"); | |
9427 | c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL); | |
9428 | parser->error = false; | |
9429 | return; | |
9430 | } | |
9431 | property = c_parser_peek_token (parser)->value; | |
9432 | list = chainon (list, build_tree_list (NULL_TREE, property)); | |
9433 | c_parser_consume_token (parser); | |
9434 | if (c_parser_next_token_is (parser, CPP_COMMA)) | |
9435 | c_parser_consume_token (parser); | |
9436 | else | |
9437 | break; | |
9438 | } | |
9439 | c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); | |
9440 | objc_add_dynamic_declaration (loc, list); | |
9441 | } | |
9442 | ||
27bf414c | 9443 | \f |
953ff289 DN |
9444 | /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore |
9445 | should be considered, statements. ALLOW_STMT is true if we're within | |
9446 | the context of a function and such pragmas are to be allowed. Returns | |
9447 | true if we actually parsed such a pragma. */ | |
27bf414c | 9448 | |
bc4071dd | 9449 | static bool |
953ff289 | 9450 | c_parser_pragma (c_parser *parser, enum pragma_context context) |
bc4071dd RH |
9451 | { |
9452 | unsigned int id; | |
9453 | ||
9454 | id = c_parser_peek_token (parser)->pragma_kind; | |
9455 | gcc_assert (id != PRAGMA_NONE); | |
9456 | ||
9457 | switch (id) | |
9458 | { | |
953ff289 DN |
9459 | case PRAGMA_OMP_BARRIER: |
9460 | if (context != pragma_compound) | |
9461 | { | |
9462 | if (context == pragma_stmt) | |
9463 | c_parser_error (parser, "%<#pragma omp barrier%> may only be " | |
9464 | "used in compound statements"); | |
9465 | goto bad_stmt; | |
9466 | } | |
9467 | c_parser_omp_barrier (parser); | |
9468 | return false; | |
9469 | ||
9470 | case PRAGMA_OMP_FLUSH: | |
9471 | if (context != pragma_compound) | |
9472 | { | |
9473 | if (context == pragma_stmt) | |
9474 | c_parser_error (parser, "%<#pragma omp flush%> may only be " | |
9475 | "used in compound statements"); | |
9476 | goto bad_stmt; | |
9477 | } | |
9478 | c_parser_omp_flush (parser); | |
9479 | return false; | |
9480 | ||
a68ab351 JJ |
9481 | case PRAGMA_OMP_TASKWAIT: |
9482 | if (context != pragma_compound) | |
9483 | { | |
9484 | if (context == pragma_stmt) | |
9485 | c_parser_error (parser, "%<#pragma omp taskwait%> may only be " | |
9486 | "used in compound statements"); | |
9487 | goto bad_stmt; | |
9488 | } | |
9489 | c_parser_omp_taskwait (parser); | |
9490 | return false; | |
9491 | ||
20906c66 JJ |
9492 | case PRAGMA_OMP_TASKYIELD: |
9493 | if (context != pragma_compound) | |
9494 | { | |
9495 | if (context == pragma_stmt) | |
9496 | c_parser_error (parser, "%<#pragma omp taskyield%> may only be " | |
9497 | "used in compound statements"); | |
9498 | goto bad_stmt; | |
9499 | } | |
9500 | c_parser_omp_taskyield (parser); | |
9501 | return false; | |
9502 | ||
acf0174b JJ |
9503 | case PRAGMA_OMP_CANCEL: |
9504 | if (context != pragma_compound) | |
9505 | { | |
9506 | if (context == pragma_stmt) | |
9507 | c_parser_error (parser, "%<#pragma omp cancel%> may only be " | |
9508 | "used in compound statements"); | |
9509 | goto bad_stmt; | |
9510 | } | |
9511 | c_parser_omp_cancel (parser); | |
9512 | return false; | |
9513 | ||
9514 | case PRAGMA_OMP_CANCELLATION_POINT: | |
9515 | if (context != pragma_compound) | |
9516 | { | |
9517 | if (context == pragma_stmt) | |
9518 | c_parser_error (parser, "%<#pragma omp cancellation point%> may " | |
9519 | "only be used in compound statements"); | |
9520 | goto bad_stmt; | |
9521 | } | |
9522 | c_parser_omp_cancellation_point (parser); | |
9523 | return false; | |
9524 | ||
953ff289 DN |
9525 | case PRAGMA_OMP_THREADPRIVATE: |
9526 | c_parser_omp_threadprivate (parser); | |
9527 | return false; | |
9528 | ||
acf0174b JJ |
9529 | case PRAGMA_OMP_TARGET: |
9530 | return c_parser_omp_target (parser, context); | |
9531 | ||
9532 | case PRAGMA_OMP_END_DECLARE_TARGET: | |
9533 | c_parser_omp_end_declare_target (parser); | |
9534 | return false; | |
9535 | ||
953ff289 | 9536 | case PRAGMA_OMP_SECTION: |
3ba09659 AH |
9537 | error_at (c_parser_peek_token (parser)->location, |
9538 | "%<#pragma omp section%> may only be used in " | |
9539 | "%<#pragma omp sections%> construct"); | |
953ff289 DN |
9540 | c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL); |
9541 | return false; | |
9542 | ||
acf0174b JJ |
9543 | case PRAGMA_OMP_DECLARE_REDUCTION: |
9544 | c_parser_omp_declare (parser, context); | |
9545 | return false; | |
8170608b TB |
9546 | case PRAGMA_IVDEP: |
9547 | c_parser_consume_pragma (parser); | |
9548 | c_parser_skip_to_pragma_eol (parser); | |
d4af74d4 TB |
9549 | if (!c_parser_next_token_is_keyword (parser, RID_FOR) |
9550 | && !c_parser_next_token_is_keyword (parser, RID_WHILE) | |
9551 | && !c_parser_next_token_is_keyword (parser, RID_DO)) | |
8170608b | 9552 | { |
d4af74d4 | 9553 | c_parser_error (parser, "for, while or do statement expected"); |
8170608b TB |
9554 | return false; |
9555 | } | |
d4af74d4 TB |
9556 | if (c_parser_next_token_is_keyword (parser, RID_FOR)) |
9557 | c_parser_for_statement (parser, true); | |
9558 | else if (c_parser_next_token_is_keyword (parser, RID_WHILE)) | |
9559 | c_parser_while_statement (parser, true); | |
9560 | else | |
9561 | c_parser_do_statement (parser, true); | |
8170608b | 9562 | return false; |
acf0174b | 9563 | |
bc4071dd RH |
9564 | case PRAGMA_GCC_PCH_PREPROCESS: |
9565 | c_parser_error (parser, "%<#pragma GCC pch_preprocess%> must be first"); | |
9566 | c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL); | |
9567 | return false; | |
9568 | ||
c02065fc AH |
9569 | case PRAGMA_CILK_SIMD: |
9570 | if (!c_parser_cilk_verify_simd (parser, context)) | |
9571 | return false; | |
9572 | c_parser_consume_pragma (parser); | |
9573 | c_parser_cilk_simd (parser); | |
9574 | return false; | |
9575 | ||
bc4071dd | 9576 | default: |
953ff289 DN |
9577 | if (id < PRAGMA_FIRST_EXTERNAL) |
9578 | { | |
acf0174b | 9579 | if (context != pragma_stmt && context != pragma_compound) |
953ff289 DN |
9580 | { |
9581 | bad_stmt: | |
9582 | c_parser_error (parser, "expected declaration specifiers"); | |
9583 | c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL); | |
9584 | return false; | |
9585 | } | |
9586 | c_parser_omp_construct (parser); | |
9587 | return true; | |
9588 | } | |
bc4071dd RH |
9589 | break; |
9590 | } | |
9591 | ||
9592 | c_parser_consume_pragma (parser); | |
9593 | c_invoke_pragma_handler (id); | |
27bf414c | 9594 | |
b8698a0f | 9595 | /* Skip to EOL, but suppress any error message. Those will have been |
bc4071dd RH |
9596 | generated by the handler routine through calling error, as opposed |
9597 | to calling c_parser_error. */ | |
9598 | parser->error = true; | |
9599 | c_parser_skip_to_pragma_eol (parser); | |
9600 | ||
9601 | return false; | |
9602 | } | |
9603 | ||
9604 | /* The interface the pragma parsers have to the lexer. */ | |
9605 | ||
9606 | enum cpp_ttype | |
9607 | pragma_lex (tree *value) | |
9608 | { | |
9609 | c_token *tok = c_parser_peek_token (the_parser); | |
9610 | enum cpp_ttype ret = tok->type; | |
9611 | ||
9612 | *value = tok->value; | |
9613 | if (ret == CPP_PRAGMA_EOL || ret == CPP_EOF) | |
9614 | ret = CPP_EOF; | |
9615 | else | |
9616 | { | |
9617 | if (ret == CPP_KEYWORD) | |
9618 | ret = CPP_NAME; | |
9619 | c_parser_consume_token (the_parser); | |
9620 | } | |
9621 | ||
9622 | return ret; | |
9623 | } | |
9624 | ||
9625 | static void | |
9626 | c_parser_pragma_pch_preprocess (c_parser *parser) | |
9627 | { | |
9628 | tree name = NULL; | |
9629 | ||
9630 | c_parser_consume_pragma (parser); | |
9631 | if (c_parser_next_token_is (parser, CPP_STRING)) | |
9632 | { | |
9633 | name = c_parser_peek_token (parser)->value; | |
9634 | c_parser_consume_token (parser); | |
9635 | } | |
9636 | else | |
9637 | c_parser_error (parser, "expected string literal"); | |
9638 | c_parser_skip_to_pragma_eol (parser); | |
9639 | ||
9640 | if (name) | |
9641 | c_common_pch_pragma (parse_in, TREE_STRING_POINTER (name)); | |
9642 | } | |
953ff289 | 9643 | \f |
acf0174b | 9644 | /* OpenMP 2.5 / 3.0 / 3.1 / 4.0 parsing routines. */ |
953ff289 DN |
9645 | |
9646 | /* Returns name of the next clause. | |
9647 | If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and | |
9648 | the token is not consumed. Otherwise appropriate pragma_omp_clause is | |
9649 | returned and the token is consumed. */ | |
9650 | ||
9651 | static pragma_omp_clause | |
9652 | c_parser_omp_clause_name (c_parser *parser) | |
9653 | { | |
9654 | pragma_omp_clause result = PRAGMA_OMP_CLAUSE_NONE; | |
9655 | ||
9656 | if (c_parser_next_token_is_keyword (parser, RID_IF)) | |
9657 | result = PRAGMA_OMP_CLAUSE_IF; | |
9658 | else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT)) | |
9659 | result = PRAGMA_OMP_CLAUSE_DEFAULT; | |
acf0174b JJ |
9660 | else if (c_parser_next_token_is_keyword (parser, RID_FOR)) |
9661 | result = PRAGMA_OMP_CLAUSE_FOR; | |
953ff289 DN |
9662 | else if (c_parser_next_token_is (parser, CPP_NAME)) |
9663 | { | |
9664 | const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); | |
9665 | ||
9666 | switch (p[0]) | |
9667 | { | |
acf0174b JJ |
9668 | case 'a': |
9669 | if (!strcmp ("aligned", p)) | |
9670 | result = PRAGMA_OMP_CLAUSE_ALIGNED; | |
9671 | break; | |
953ff289 | 9672 | case 'c': |
a68ab351 JJ |
9673 | if (!strcmp ("collapse", p)) |
9674 | result = PRAGMA_OMP_CLAUSE_COLLAPSE; | |
9675 | else if (!strcmp ("copyin", p)) | |
953ff289 DN |
9676 | result = PRAGMA_OMP_CLAUSE_COPYIN; |
9677 | else if (!strcmp ("copyprivate", p)) | |
9678 | result = PRAGMA_OMP_CLAUSE_COPYPRIVATE; | |
9679 | break; | |
acf0174b JJ |
9680 | case 'd': |
9681 | if (!strcmp ("depend", p)) | |
9682 | result = PRAGMA_OMP_CLAUSE_DEPEND; | |
9683 | else if (!strcmp ("device", p)) | |
9684 | result = PRAGMA_OMP_CLAUSE_DEVICE; | |
9685 | else if (!strcmp ("dist_schedule", p)) | |
9686 | result = PRAGMA_OMP_CLAUSE_DIST_SCHEDULE; | |
9687 | break; | |
953ff289 | 9688 | case 'f': |
20906c66 JJ |
9689 | if (!strcmp ("final", p)) |
9690 | result = PRAGMA_OMP_CLAUSE_FINAL; | |
9691 | else if (!strcmp ("firstprivate", p)) | |
953ff289 | 9692 | result = PRAGMA_OMP_CLAUSE_FIRSTPRIVATE; |
acf0174b JJ |
9693 | else if (!strcmp ("from", p)) |
9694 | result = PRAGMA_OMP_CLAUSE_FROM; | |
9695 | break; | |
9696 | case 'i': | |
9697 | if (!strcmp ("inbranch", p)) | |
9698 | result = PRAGMA_OMP_CLAUSE_INBRANCH; | |
953ff289 DN |
9699 | break; |
9700 | case 'l': | |
9701 | if (!strcmp ("lastprivate", p)) | |
9702 | result = PRAGMA_OMP_CLAUSE_LASTPRIVATE; | |
acf0174b JJ |
9703 | else if (!strcmp ("linear", p)) |
9704 | result = PRAGMA_OMP_CLAUSE_LINEAR; | |
953ff289 | 9705 | break; |
20906c66 | 9706 | case 'm': |
acf0174b JJ |
9707 | if (!strcmp ("map", p)) |
9708 | result = PRAGMA_OMP_CLAUSE_MAP; | |
9709 | else if (!strcmp ("mergeable", p)) | |
20906c66 | 9710 | result = PRAGMA_OMP_CLAUSE_MERGEABLE; |
b72271b9 | 9711 | else if (flag_cilkplus && !strcmp ("mask", p)) |
41958c28 | 9712 | result = PRAGMA_CILK_CLAUSE_MASK; |
20906c66 | 9713 | break; |
953ff289 | 9714 | case 'n': |
acf0174b JJ |
9715 | if (!strcmp ("notinbranch", p)) |
9716 | result = PRAGMA_OMP_CLAUSE_NOTINBRANCH; | |
9717 | else if (!strcmp ("nowait", p)) | |
953ff289 | 9718 | result = PRAGMA_OMP_CLAUSE_NOWAIT; |
acf0174b JJ |
9719 | else if (!strcmp ("num_teams", p)) |
9720 | result = PRAGMA_OMP_CLAUSE_NUM_TEAMS; | |
953ff289 DN |
9721 | else if (!strcmp ("num_threads", p)) |
9722 | result = PRAGMA_OMP_CLAUSE_NUM_THREADS; | |
b72271b9 | 9723 | else if (flag_cilkplus && !strcmp ("nomask", p)) |
41958c28 | 9724 | result = PRAGMA_CILK_CLAUSE_NOMASK; |
953ff289 DN |
9725 | break; |
9726 | case 'o': | |
9727 | if (!strcmp ("ordered", p)) | |
9728 | result = PRAGMA_OMP_CLAUSE_ORDERED; | |
9729 | break; | |
9730 | case 'p': | |
acf0174b JJ |
9731 | if (!strcmp ("parallel", p)) |
9732 | result = PRAGMA_OMP_CLAUSE_PARALLEL; | |
9733 | else if (!strcmp ("private", p)) | |
953ff289 | 9734 | result = PRAGMA_OMP_CLAUSE_PRIVATE; |
acf0174b JJ |
9735 | else if (!strcmp ("proc_bind", p)) |
9736 | result = PRAGMA_OMP_CLAUSE_PROC_BIND; | |
953ff289 DN |
9737 | break; |
9738 | case 'r': | |
9739 | if (!strcmp ("reduction", p)) | |
9740 | result = PRAGMA_OMP_CLAUSE_REDUCTION; | |
9741 | break; | |
9742 | case 's': | |
acf0174b JJ |
9743 | if (!strcmp ("safelen", p)) |
9744 | result = PRAGMA_OMP_CLAUSE_SAFELEN; | |
9745 | else if (!strcmp ("schedule", p)) | |
953ff289 | 9746 | result = PRAGMA_OMP_CLAUSE_SCHEDULE; |
acf0174b JJ |
9747 | else if (!strcmp ("sections", p)) |
9748 | result = PRAGMA_OMP_CLAUSE_SECTIONS; | |
953ff289 DN |
9749 | else if (!strcmp ("shared", p)) |
9750 | result = PRAGMA_OMP_CLAUSE_SHARED; | |
acf0174b JJ |
9751 | else if (!strcmp ("simdlen", p)) |
9752 | result = PRAGMA_OMP_CLAUSE_SIMDLEN; | |
9753 | break; | |
9754 | case 't': | |
9755 | if (!strcmp ("taskgroup", p)) | |
9756 | result = PRAGMA_OMP_CLAUSE_TASKGROUP; | |
9757 | else if (!strcmp ("thread_limit", p)) | |
9758 | result = PRAGMA_OMP_CLAUSE_THREAD_LIMIT; | |
9759 | else if (!strcmp ("to", p)) | |
9760 | result = PRAGMA_OMP_CLAUSE_TO; | |
953ff289 | 9761 | break; |
a68ab351 | 9762 | case 'u': |
acf0174b JJ |
9763 | if (!strcmp ("uniform", p)) |
9764 | result = PRAGMA_OMP_CLAUSE_UNIFORM; | |
9765 | else if (!strcmp ("untied", p)) | |
a68ab351 JJ |
9766 | result = PRAGMA_OMP_CLAUSE_UNTIED; |
9767 | break; | |
41958c28 | 9768 | case 'v': |
b72271b9 | 9769 | if (flag_cilkplus && !strcmp ("vectorlength", p)) |
41958c28 BI |
9770 | result = PRAGMA_CILK_CLAUSE_VECTORLENGTH; |
9771 | break; | |
953ff289 DN |
9772 | } |
9773 | } | |
9774 | ||
9775 | if (result != PRAGMA_OMP_CLAUSE_NONE) | |
9776 | c_parser_consume_token (parser); | |
9777 | ||
9778 | return result; | |
9779 | } | |
9780 | ||
9781 | /* Validate that a clause of the given type does not already exist. */ | |
9782 | ||
9783 | static void | |
d75d71e0 ILT |
9784 | check_no_duplicate_clause (tree clauses, enum omp_clause_code code, |
9785 | const char *name) | |
953ff289 DN |
9786 | { |
9787 | tree c; | |
9788 | ||
9789 | for (c = clauses; c ; c = OMP_CLAUSE_CHAIN (c)) | |
aaf46ef9 | 9790 | if (OMP_CLAUSE_CODE (c) == code) |
953ff289 | 9791 | { |
c2255bc4 AH |
9792 | location_t loc = OMP_CLAUSE_LOCATION (c); |
9793 | error_at (loc, "too many %qs clauses", name); | |
953ff289 DN |
9794 | break; |
9795 | } | |
9796 | } | |
9797 | ||
9798 | /* OpenMP 2.5: | |
9799 | variable-list: | |
9800 | identifier | |
9801 | variable-list , identifier | |
9802 | ||
c2255bc4 AH |
9803 | If KIND is nonzero, create the appropriate node and install the |
9804 | decl in OMP_CLAUSE_DECL and add the node to the head of the list. | |
9805 | If KIND is nonzero, CLAUSE_LOC is the location of the clause. | |
953ff289 DN |
9806 | |
9807 | If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE; | |
9808 | return the list created. */ | |
9809 | ||
9810 | static tree | |
c2255bc4 AH |
9811 | c_parser_omp_variable_list (c_parser *parser, |
9812 | location_t clause_loc, | |
acf0174b | 9813 | enum omp_clause_code kind, tree list) |
953ff289 DN |
9814 | { |
9815 | if (c_parser_next_token_is_not (parser, CPP_NAME) | |
9816 | || c_parser_peek_token (parser)->id_kind != C_ID_ID) | |
9817 | c_parser_error (parser, "expected identifier"); | |
9818 | ||
9819 | while (c_parser_next_token_is (parser, CPP_NAME) | |
9820 | && c_parser_peek_token (parser)->id_kind == C_ID_ID) | |
9821 | { | |
9822 | tree t = lookup_name (c_parser_peek_token (parser)->value); | |
9823 | ||
9824 | if (t == NULL_TREE) | |
acf0174b JJ |
9825 | { |
9826 | undeclared_variable (c_parser_peek_token (parser)->location, | |
9827 | c_parser_peek_token (parser)->value); | |
9828 | t = error_mark_node; | |
9829 | } | |
9830 | ||
9831 | c_parser_consume_token (parser); | |
9832 | ||
9833 | if (t == error_mark_node) | |
953ff289 DN |
9834 | ; |
9835 | else if (kind != 0) | |
9836 | { | |
acf0174b JJ |
9837 | switch (kind) |
9838 | { | |
9839 | case OMP_CLAUSE_MAP: | |
9840 | case OMP_CLAUSE_FROM: | |
9841 | case OMP_CLAUSE_TO: | |
9842 | case OMP_CLAUSE_DEPEND: | |
9843 | while (c_parser_next_token_is (parser, CPP_OPEN_SQUARE)) | |
9844 | { | |
9845 | tree low_bound = NULL_TREE, length = NULL_TREE; | |
9846 | ||
9847 | c_parser_consume_token (parser); | |
9848 | if (!c_parser_next_token_is (parser, CPP_COLON)) | |
9849 | low_bound = c_parser_expression (parser).value; | |
9850 | if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE)) | |
9851 | length = integer_one_node; | |
9852 | else | |
9853 | { | |
9854 | /* Look for `:'. */ | |
9855 | if (!c_parser_require (parser, CPP_COLON, | |
9856 | "expected %<:%>")) | |
9857 | { | |
9858 | t = error_mark_node; | |
9859 | break; | |
9860 | } | |
9861 | if (!c_parser_next_token_is (parser, CPP_CLOSE_SQUARE)) | |
9862 | length = c_parser_expression (parser).value; | |
9863 | } | |
9864 | /* Look for the closing `]'. */ | |
9865 | if (!c_parser_require (parser, CPP_CLOSE_SQUARE, | |
9866 | "expected %<]%>")) | |
9867 | { | |
9868 | t = error_mark_node; | |
9869 | break; | |
9870 | } | |
9871 | t = tree_cons (low_bound, length, t); | |
9872 | } | |
9873 | break; | |
9874 | default: | |
9875 | break; | |
9876 | } | |
9877 | ||
9878 | if (t != error_mark_node) | |
9879 | { | |
9880 | tree u = build_omp_clause (clause_loc, kind); | |
9881 | OMP_CLAUSE_DECL (u) = t; | |
9882 | OMP_CLAUSE_CHAIN (u) = list; | |
9883 | list = u; | |
9884 | } | |
953ff289 DN |
9885 | } |
9886 | else | |
9887 | list = tree_cons (t, NULL_TREE, list); | |
9888 | ||
953ff289 DN |
9889 | if (c_parser_next_token_is_not (parser, CPP_COMMA)) |
9890 | break; | |
9891 | ||
9892 | c_parser_consume_token (parser); | |
9893 | } | |
9894 | ||
9895 | return list; | |
9896 | } | |
9897 | ||
9898 | /* Similarly, but expect leading and trailing parenthesis. This is a very | |
9899 | common case for omp clauses. */ | |
9900 | ||
9901 | static tree | |
d75d71e0 ILT |
9902 | c_parser_omp_var_list_parens (c_parser *parser, enum omp_clause_code kind, |
9903 | tree list) | |
953ff289 | 9904 | { |
c2255bc4 AH |
9905 | /* The clauses location. */ |
9906 | location_t loc = c_parser_peek_token (parser)->location; | |
9907 | ||
953ff289 DN |
9908 | if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) |
9909 | { | |
c2255bc4 | 9910 | list = c_parser_omp_variable_list (parser, loc, kind, list); |
953ff289 DN |
9911 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); |
9912 | } | |
9913 | return list; | |
9914 | } | |
9915 | ||
a68ab351 JJ |
9916 | /* OpenMP 3.0: |
9917 | collapse ( constant-expression ) */ | |
9918 | ||
9919 | static tree | |
9920 | c_parser_omp_clause_collapse (c_parser *parser, tree list) | |
9921 | { | |
9922 | tree c, num = error_mark_node; | |
9923 | HOST_WIDE_INT n; | |
9924 | location_t loc; | |
9925 | ||
9926 | check_no_duplicate_clause (list, OMP_CLAUSE_COLLAPSE, "collapse"); | |
9927 | ||
9928 | loc = c_parser_peek_token (parser)->location; | |
9929 | if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
9930 | { | |
9931 | num = c_parser_expr_no_commas (parser, NULL).value; | |
9932 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
9933 | } | |
9934 | if (num == error_mark_node) | |
9935 | return list; | |
acf0174b JJ |
9936 | mark_exp_read (num); |
9937 | num = c_fully_fold (num, false, NULL); | |
a68ab351 | 9938 | if (!INTEGRAL_TYPE_P (TREE_TYPE (num)) |
9541ffee | 9939 | || !tree_fits_shwi_p (num) |
9439e9a1 | 9940 | || (n = tree_to_shwi (num)) <= 0 |
a68ab351 JJ |
9941 | || (int) n != n) |
9942 | { | |
3ba09659 AH |
9943 | error_at (loc, |
9944 | "collapse argument needs positive constant integer expression"); | |
a68ab351 JJ |
9945 | return list; |
9946 | } | |
c2255bc4 | 9947 | c = build_omp_clause (loc, OMP_CLAUSE_COLLAPSE); |
a68ab351 JJ |
9948 | OMP_CLAUSE_COLLAPSE_EXPR (c) = num; |
9949 | OMP_CLAUSE_CHAIN (c) = list; | |
9950 | return c; | |
9951 | } | |
9952 | ||
953ff289 DN |
9953 | /* OpenMP 2.5: |
9954 | copyin ( variable-list ) */ | |
9955 | ||
9956 | static tree | |
9957 | c_parser_omp_clause_copyin (c_parser *parser, tree list) | |
9958 | { | |
9959 | return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYIN, list); | |
9960 | } | |
9961 | ||
9962 | /* OpenMP 2.5: | |
9963 | copyprivate ( variable-list ) */ | |
9964 | ||
9965 | static tree | |
9966 | c_parser_omp_clause_copyprivate (c_parser *parser, tree list) | |
9967 | { | |
9968 | return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYPRIVATE, list); | |
9969 | } | |
9970 | ||
9971 | /* OpenMP 2.5: | |
9972 | default ( shared | none ) */ | |
9973 | ||
9974 | static tree | |
9975 | c_parser_omp_clause_default (c_parser *parser, tree list) | |
9976 | { | |
9977 | enum omp_clause_default_kind kind = OMP_CLAUSE_DEFAULT_UNSPECIFIED; | |
c2255bc4 | 9978 | location_t loc = c_parser_peek_token (parser)->location; |
953ff289 DN |
9979 | tree c; |
9980 | ||
9981 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
9982 | return list; | |
9983 | if (c_parser_next_token_is (parser, CPP_NAME)) | |
9984 | { | |
9985 | const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); | |
9986 | ||
9987 | switch (p[0]) | |
9988 | { | |
9989 | case 'n': | |
9990 | if (strcmp ("none", p) != 0) | |
9991 | goto invalid_kind; | |
9992 | kind = OMP_CLAUSE_DEFAULT_NONE; | |
9993 | break; | |
9994 | ||
9995 | case 's': | |
9996 | if (strcmp ("shared", p) != 0) | |
9997 | goto invalid_kind; | |
9998 | kind = OMP_CLAUSE_DEFAULT_SHARED; | |
9999 | break; | |
10000 | ||
10001 | default: | |
10002 | goto invalid_kind; | |
10003 | } | |
10004 | ||
10005 | c_parser_consume_token (parser); | |
10006 | } | |
10007 | else | |
10008 | { | |
10009 | invalid_kind: | |
10010 | c_parser_error (parser, "expected %<none%> or %<shared%>"); | |
10011 | } | |
10012 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
10013 | ||
10014 | if (kind == OMP_CLAUSE_DEFAULT_UNSPECIFIED) | |
10015 | return list; | |
10016 | ||
10017 | check_no_duplicate_clause (list, OMP_CLAUSE_DEFAULT, "default"); | |
c2255bc4 | 10018 | c = build_omp_clause (loc, OMP_CLAUSE_DEFAULT); |
953ff289 DN |
10019 | OMP_CLAUSE_CHAIN (c) = list; |
10020 | OMP_CLAUSE_DEFAULT_KIND (c) = kind; | |
10021 | ||
10022 | return c; | |
10023 | } | |
10024 | ||
10025 | /* OpenMP 2.5: | |
10026 | firstprivate ( variable-list ) */ | |
10027 | ||
10028 | static tree | |
10029 | c_parser_omp_clause_firstprivate (c_parser *parser, tree list) | |
10030 | { | |
10031 | return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_FIRSTPRIVATE, list); | |
10032 | } | |
10033 | ||
20906c66 JJ |
10034 | /* OpenMP 3.1: |
10035 | final ( expression ) */ | |
10036 | ||
10037 | static tree | |
10038 | c_parser_omp_clause_final (c_parser *parser, tree list) | |
10039 | { | |
10040 | location_t loc = c_parser_peek_token (parser)->location; | |
10041 | if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) | |
10042 | { | |
10043 | tree t = c_parser_paren_condition (parser); | |
10044 | tree c; | |
10045 | ||
10046 | check_no_duplicate_clause (list, OMP_CLAUSE_FINAL, "final"); | |
10047 | ||
10048 | c = build_omp_clause (loc, OMP_CLAUSE_FINAL); | |
10049 | OMP_CLAUSE_FINAL_EXPR (c) = t; | |
10050 | OMP_CLAUSE_CHAIN (c) = list; | |
10051 | list = c; | |
10052 | } | |
10053 | else | |
10054 | c_parser_error (parser, "expected %<(%>"); | |
10055 | ||
10056 | return list; | |
10057 | } | |
10058 | ||
953ff289 DN |
10059 | /* OpenMP 2.5: |
10060 | if ( expression ) */ | |
10061 | ||
10062 | static tree | |
10063 | c_parser_omp_clause_if (c_parser *parser, tree list) | |
10064 | { | |
c2255bc4 | 10065 | location_t loc = c_parser_peek_token (parser)->location; |
953ff289 DN |
10066 | if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) |
10067 | { | |
10068 | tree t = c_parser_paren_condition (parser); | |
10069 | tree c; | |
10070 | ||
10071 | check_no_duplicate_clause (list, OMP_CLAUSE_IF, "if"); | |
10072 | ||
c2255bc4 | 10073 | c = build_omp_clause (loc, OMP_CLAUSE_IF); |
953ff289 DN |
10074 | OMP_CLAUSE_IF_EXPR (c) = t; |
10075 | OMP_CLAUSE_CHAIN (c) = list; | |
10076 | list = c; | |
10077 | } | |
10078 | else | |
10079 | c_parser_error (parser, "expected %<(%>"); | |
10080 | ||
10081 | return list; | |
10082 | } | |
10083 | ||
10084 | /* OpenMP 2.5: | |
10085 | lastprivate ( variable-list ) */ | |
10086 | ||
10087 | static tree | |
10088 | c_parser_omp_clause_lastprivate (c_parser *parser, tree list) | |
10089 | { | |
10090 | return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_LASTPRIVATE, list); | |
10091 | } | |
10092 | ||
20906c66 JJ |
10093 | /* OpenMP 3.1: |
10094 | mergeable */ | |
10095 | ||
10096 | static tree | |
10097 | c_parser_omp_clause_mergeable (c_parser *parser ATTRIBUTE_UNUSED, tree list) | |
10098 | { | |
10099 | tree c; | |
10100 | ||
10101 | /* FIXME: Should we allow duplicates? */ | |
10102 | check_no_duplicate_clause (list, OMP_CLAUSE_MERGEABLE, "mergeable"); | |
10103 | ||
10104 | c = build_omp_clause (c_parser_peek_token (parser)->location, | |
10105 | OMP_CLAUSE_MERGEABLE); | |
10106 | OMP_CLAUSE_CHAIN (c) = list; | |
10107 | ||
10108 | return c; | |
10109 | } | |
10110 | ||
953ff289 DN |
10111 | /* OpenMP 2.5: |
10112 | nowait */ | |
10113 | ||
10114 | static tree | |
10115 | c_parser_omp_clause_nowait (c_parser *parser ATTRIBUTE_UNUSED, tree list) | |
10116 | { | |
10117 | tree c; | |
c2255bc4 | 10118 | location_t loc = c_parser_peek_token (parser)->location; |
953ff289 DN |
10119 | |
10120 | check_no_duplicate_clause (list, OMP_CLAUSE_NOWAIT, "nowait"); | |
10121 | ||
c2255bc4 | 10122 | c = build_omp_clause (loc, OMP_CLAUSE_NOWAIT); |
953ff289 DN |
10123 | OMP_CLAUSE_CHAIN (c) = list; |
10124 | return c; | |
10125 | } | |
10126 | ||
10127 | /* OpenMP 2.5: | |
10128 | num_threads ( expression ) */ | |
10129 | ||
10130 | static tree | |
10131 | c_parser_omp_clause_num_threads (c_parser *parser, tree list) | |
10132 | { | |
c2255bc4 | 10133 | location_t num_threads_loc = c_parser_peek_token (parser)->location; |
953ff289 DN |
10134 | if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) |
10135 | { | |
c7412148 | 10136 | location_t expr_loc = c_parser_peek_token (parser)->location; |
953ff289 | 10137 | tree c, t = c_parser_expression (parser).value; |
7d1362bc | 10138 | mark_exp_read (t); |
928c19bb | 10139 | t = c_fully_fold (t, false, NULL); |
953ff289 DN |
10140 | |
10141 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
10142 | ||
10143 | if (!INTEGRAL_TYPE_P (TREE_TYPE (t))) | |
10144 | { | |
10145 | c_parser_error (parser, "expected integer expression"); | |
10146 | return list; | |
10147 | } | |
10148 | ||
10149 | /* Attempt to statically determine when the number isn't positive. */ | |
db3927fb | 10150 | c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t, |
953ff289 | 10151 | build_int_cst (TREE_TYPE (t), 0)); |
c2255bc4 AH |
10152 | if (CAN_HAVE_LOCATION_P (c)) |
10153 | SET_EXPR_LOCATION (c, expr_loc); | |
953ff289 DN |
10154 | if (c == boolean_true_node) |
10155 | { | |
3ba09659 AH |
10156 | warning_at (expr_loc, 0, |
10157 | "%<num_threads%> value must be positive"); | |
953ff289 DN |
10158 | t = integer_one_node; |
10159 | } | |
10160 | ||
10161 | check_no_duplicate_clause (list, OMP_CLAUSE_NUM_THREADS, "num_threads"); | |
10162 | ||
c2255bc4 | 10163 | c = build_omp_clause (num_threads_loc, OMP_CLAUSE_NUM_THREADS); |
953ff289 DN |
10164 | OMP_CLAUSE_NUM_THREADS_EXPR (c) = t; |
10165 | OMP_CLAUSE_CHAIN (c) = list; | |
10166 | list = c; | |
10167 | } | |
10168 | ||
10169 | return list; | |
10170 | } | |
10171 | ||
10172 | /* OpenMP 2.5: | |
10173 | ordered */ | |
10174 | ||
10175 | static tree | |
c2255bc4 | 10176 | c_parser_omp_clause_ordered (c_parser *parser, tree list) |
953ff289 DN |
10177 | { |
10178 | tree c; | |
10179 | ||
10180 | check_no_duplicate_clause (list, OMP_CLAUSE_ORDERED, "ordered"); | |
10181 | ||
c2255bc4 AH |
10182 | c = build_omp_clause (c_parser_peek_token (parser)->location, |
10183 | OMP_CLAUSE_ORDERED); | |
953ff289 | 10184 | OMP_CLAUSE_CHAIN (c) = list; |
c2255bc4 | 10185 | |
953ff289 DN |
10186 | return c; |
10187 | } | |
10188 | ||
10189 | /* OpenMP 2.5: | |
10190 | private ( variable-list ) */ | |
10191 | ||
10192 | static tree | |
10193 | c_parser_omp_clause_private (c_parser *parser, tree list) | |
10194 | { | |
10195 | return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_PRIVATE, list); | |
10196 | } | |
10197 | ||
10198 | /* OpenMP 2.5: | |
10199 | reduction ( reduction-operator : variable-list ) | |
10200 | ||
10201 | reduction-operator: | |
20906c66 | 10202 | One of: + * - & ^ | && || |
acf0174b | 10203 | |
20906c66 JJ |
10204 | OpenMP 3.1: |
10205 | ||
10206 | reduction-operator: | |
acf0174b JJ |
10207 | One of: + * - & ^ | && || max min |
10208 | ||
10209 | OpenMP 4.0: | |
10210 | ||
10211 | reduction-operator: | |
10212 | One of: + * - & ^ | && || | |
10213 | identifier */ | |
953ff289 DN |
10214 | |
10215 | static tree | |
10216 | c_parser_omp_clause_reduction (c_parser *parser, tree list) | |
10217 | { | |
c2255bc4 | 10218 | location_t clause_loc = c_parser_peek_token (parser)->location; |
953ff289 DN |
10219 | if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) |
10220 | { | |
acf0174b JJ |
10221 | enum tree_code code = ERROR_MARK; |
10222 | tree reduc_id = NULL_TREE; | |
953ff289 DN |
10223 | |
10224 | switch (c_parser_peek_token (parser)->type) | |
10225 | { | |
10226 | case CPP_PLUS: | |
10227 | code = PLUS_EXPR; | |
10228 | break; | |
10229 | case CPP_MULT: | |
10230 | code = MULT_EXPR; | |
10231 | break; | |
10232 | case CPP_MINUS: | |
10233 | code = MINUS_EXPR; | |
10234 | break; | |
10235 | case CPP_AND: | |
10236 | code = BIT_AND_EXPR; | |
10237 | break; | |
10238 | case CPP_XOR: | |
10239 | code = BIT_XOR_EXPR; | |
10240 | break; | |
10241 | case CPP_OR: | |
10242 | code = BIT_IOR_EXPR; | |
10243 | break; | |
10244 | case CPP_AND_AND: | |
10245 | code = TRUTH_ANDIF_EXPR; | |
10246 | break; | |
10247 | case CPP_OR_OR: | |
10248 | code = TRUTH_ORIF_EXPR; | |
10249 | break; | |
20906c66 JJ |
10250 | case CPP_NAME: |
10251 | { | |
10252 | const char *p | |
10253 | = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); | |
10254 | if (strcmp (p, "min") == 0) | |
10255 | { | |
10256 | code = MIN_EXPR; | |
10257 | break; | |
10258 | } | |
10259 | if (strcmp (p, "max") == 0) | |
10260 | { | |
10261 | code = MAX_EXPR; | |
10262 | break; | |
10263 | } | |
acf0174b JJ |
10264 | reduc_id = c_parser_peek_token (parser)->value; |
10265 | break; | |
20906c66 | 10266 | } |
953ff289 DN |
10267 | default: |
10268 | c_parser_error (parser, | |
10269 | "expected %<+%>, %<*%>, %<-%>, %<&%>, " | |
20906c66 | 10270 | "%<^%>, %<|%>, %<&&%>, %<||%>, %<min%> or %<max%>"); |
953ff289 DN |
10271 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0); |
10272 | return list; | |
10273 | } | |
10274 | c_parser_consume_token (parser); | |
acf0174b | 10275 | reduc_id = c_omp_reduction_id (code, reduc_id); |
953ff289 DN |
10276 | if (c_parser_require (parser, CPP_COLON, "expected %<:%>")) |
10277 | { | |
10278 | tree nl, c; | |
10279 | ||
c2255bc4 AH |
10280 | nl = c_parser_omp_variable_list (parser, clause_loc, |
10281 | OMP_CLAUSE_REDUCTION, list); | |
953ff289 | 10282 | for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c)) |
acf0174b JJ |
10283 | { |
10284 | tree type = TREE_TYPE (OMP_CLAUSE_DECL (c)); | |
10285 | OMP_CLAUSE_REDUCTION_CODE (c) = code; | |
10286 | if (code == ERROR_MARK | |
10287 | || !(INTEGRAL_TYPE_P (type) | |
10288 | || TREE_CODE (type) == REAL_TYPE | |
10289 | || TREE_CODE (type) == COMPLEX_TYPE)) | |
10290 | OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) | |
10291 | = c_omp_reduction_lookup (reduc_id, | |
10292 | TYPE_MAIN_VARIANT (type)); | |
10293 | } | |
953ff289 DN |
10294 | |
10295 | list = nl; | |
10296 | } | |
10297 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
10298 | } | |
10299 | return list; | |
10300 | } | |
10301 | ||
10302 | /* OpenMP 2.5: | |
10303 | schedule ( schedule-kind ) | |
10304 | schedule ( schedule-kind , expression ) | |
10305 | ||
10306 | schedule-kind: | |
a68ab351 | 10307 | static | dynamic | guided | runtime | auto |
953ff289 DN |
10308 | */ |
10309 | ||
10310 | static tree | |
10311 | c_parser_omp_clause_schedule (c_parser *parser, tree list) | |
10312 | { | |
10313 | tree c, t; | |
c2255bc4 | 10314 | location_t loc = c_parser_peek_token (parser)->location; |
953ff289 DN |
10315 | |
10316 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
10317 | return list; | |
10318 | ||
c2255bc4 | 10319 | c = build_omp_clause (loc, OMP_CLAUSE_SCHEDULE); |
953ff289 DN |
10320 | |
10321 | if (c_parser_next_token_is (parser, CPP_NAME)) | |
10322 | { | |
10323 | tree kind = c_parser_peek_token (parser)->value; | |
10324 | const char *p = IDENTIFIER_POINTER (kind); | |
10325 | ||
10326 | switch (p[0]) | |
10327 | { | |
10328 | case 'd': | |
10329 | if (strcmp ("dynamic", p) != 0) | |
10330 | goto invalid_kind; | |
10331 | OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_DYNAMIC; | |
10332 | break; | |
10333 | ||
10334 | case 'g': | |
10335 | if (strcmp ("guided", p) != 0) | |
10336 | goto invalid_kind; | |
10337 | OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_GUIDED; | |
10338 | break; | |
10339 | ||
10340 | case 'r': | |
10341 | if (strcmp ("runtime", p) != 0) | |
10342 | goto invalid_kind; | |
10343 | OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_RUNTIME; | |
10344 | break; | |
10345 | ||
10346 | default: | |
10347 | goto invalid_kind; | |
10348 | } | |
10349 | } | |
10350 | else if (c_parser_next_token_is_keyword (parser, RID_STATIC)) | |
10351 | OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_STATIC; | |
a68ab351 JJ |
10352 | else if (c_parser_next_token_is_keyword (parser, RID_AUTO)) |
10353 | OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_AUTO; | |
953ff289 DN |
10354 | else |
10355 | goto invalid_kind; | |
10356 | ||
10357 | c_parser_consume_token (parser); | |
10358 | if (c_parser_next_token_is (parser, CPP_COMMA)) | |
10359 | { | |
c7412148 | 10360 | location_t here; |
953ff289 DN |
10361 | c_parser_consume_token (parser); |
10362 | ||
c7412148 | 10363 | here = c_parser_peek_token (parser)->location; |
953ff289 | 10364 | t = c_parser_expr_no_commas (parser, NULL).value; |
7d1362bc | 10365 | mark_exp_read (t); |
928c19bb | 10366 | t = c_fully_fold (t, false, NULL); |
953ff289 DN |
10367 | |
10368 | if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_RUNTIME) | |
3ba09659 AH |
10369 | error_at (here, "schedule %<runtime%> does not take " |
10370 | "a %<chunk_size%> parameter"); | |
a68ab351 | 10371 | else if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_AUTO) |
3ba09659 AH |
10372 | error_at (here, |
10373 | "schedule %<auto%> does not take " | |
10374 | "a %<chunk_size%> parameter"); | |
953ff289 DN |
10375 | else if (TREE_CODE (TREE_TYPE (t)) == INTEGER_TYPE) |
10376 | OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c) = t; | |
10377 | else | |
10378 | c_parser_error (parser, "expected integer expression"); | |
10379 | ||
10380 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
10381 | } | |
10382 | else | |
10383 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, | |
10384 | "expected %<,%> or %<)%>"); | |
10385 | ||
10386 | check_no_duplicate_clause (list, OMP_CLAUSE_SCHEDULE, "schedule"); | |
10387 | OMP_CLAUSE_CHAIN (c) = list; | |
10388 | return c; | |
10389 | ||
10390 | invalid_kind: | |
10391 | c_parser_error (parser, "invalid schedule kind"); | |
10392 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0); | |
10393 | return list; | |
10394 | } | |
10395 | ||
10396 | /* OpenMP 2.5: | |
10397 | shared ( variable-list ) */ | |
10398 | ||
10399 | static tree | |
10400 | c_parser_omp_clause_shared (c_parser *parser, tree list) | |
10401 | { | |
10402 | return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_SHARED, list); | |
10403 | } | |
10404 | ||
a68ab351 JJ |
10405 | /* OpenMP 3.0: |
10406 | untied */ | |
10407 | ||
10408 | static tree | |
10409 | c_parser_omp_clause_untied (c_parser *parser ATTRIBUTE_UNUSED, tree list) | |
10410 | { | |
10411 | tree c; | |
10412 | ||
10413 | /* FIXME: Should we allow duplicates? */ | |
10414 | check_no_duplicate_clause (list, OMP_CLAUSE_UNTIED, "untied"); | |
10415 | ||
c2255bc4 AH |
10416 | c = build_omp_clause (c_parser_peek_token (parser)->location, |
10417 | OMP_CLAUSE_UNTIED); | |
a68ab351 | 10418 | OMP_CLAUSE_CHAIN (c) = list; |
c2255bc4 | 10419 | |
a68ab351 JJ |
10420 | return c; |
10421 | } | |
10422 | ||
acf0174b JJ |
10423 | /* OpenMP 4.0: |
10424 | inbranch | |
10425 | notinbranch */ | |
953ff289 DN |
10426 | |
10427 | static tree | |
acf0174b JJ |
10428 | c_parser_omp_clause_branch (c_parser *parser ATTRIBUTE_UNUSED, |
10429 | enum omp_clause_code code, tree list) | |
953ff289 | 10430 | { |
acf0174b | 10431 | check_no_duplicate_clause (list, code, omp_clause_code_name[code]); |
953ff289 | 10432 | |
acf0174b JJ |
10433 | tree c = build_omp_clause (c_parser_peek_token (parser)->location, code); |
10434 | OMP_CLAUSE_CHAIN (c) = list; | |
953ff289 | 10435 | |
acf0174b JJ |
10436 | return c; |
10437 | } | |
8085ca15 | 10438 | |
acf0174b JJ |
10439 | /* OpenMP 4.0: |
10440 | parallel | |
10441 | for | |
10442 | sections | |
10443 | taskgroup */ | |
8085ca15 | 10444 | |
acf0174b JJ |
10445 | static tree |
10446 | c_parser_omp_clause_cancelkind (c_parser *parser ATTRIBUTE_UNUSED, | |
10447 | enum omp_clause_code code, tree list) | |
10448 | { | |
10449 | tree c = build_omp_clause (c_parser_peek_token (parser)->location, code); | |
10450 | OMP_CLAUSE_CHAIN (c) = list; | |
10451 | ||
10452 | return c; | |
10453 | } | |
10454 | ||
10455 | /* OpenMP 4.0: | |
10456 | num_teams ( expression ) */ | |
10457 | ||
10458 | static tree | |
10459 | c_parser_omp_clause_num_teams (c_parser *parser, tree list) | |
10460 | { | |
10461 | location_t num_teams_loc = c_parser_peek_token (parser)->location; | |
10462 | if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
10463 | { | |
10464 | location_t expr_loc = c_parser_peek_token (parser)->location; | |
10465 | tree c, t = c_parser_expression (parser).value; | |
10466 | mark_exp_read (t); | |
10467 | t = c_fully_fold (t, false, NULL); | |
10468 | ||
10469 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
10470 | ||
10471 | if (!INTEGRAL_TYPE_P (TREE_TYPE (t))) | |
953ff289 | 10472 | { |
acf0174b JJ |
10473 | c_parser_error (parser, "expected integer expression"); |
10474 | return list; | |
953ff289 DN |
10475 | } |
10476 | ||
acf0174b JJ |
10477 | /* Attempt to statically determine when the number isn't positive. */ |
10478 | c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t, | |
10479 | build_int_cst (TREE_TYPE (t), 0)); | |
10480 | if (CAN_HAVE_LOCATION_P (c)) | |
10481 | SET_EXPR_LOCATION (c, expr_loc); | |
10482 | if (c == boolean_true_node) | |
953ff289 | 10483 | { |
acf0174b JJ |
10484 | warning_at (expr_loc, 0, "%<num_teams%> value must be positive"); |
10485 | t = integer_one_node; | |
953ff289 | 10486 | } |
953ff289 | 10487 | |
acf0174b | 10488 | check_no_duplicate_clause (list, OMP_CLAUSE_NUM_TEAMS, "num_teams"); |
953ff289 | 10489 | |
acf0174b JJ |
10490 | c = build_omp_clause (num_teams_loc, OMP_CLAUSE_NUM_TEAMS); |
10491 | OMP_CLAUSE_NUM_TEAMS_EXPR (c) = t; | |
10492 | OMP_CLAUSE_CHAIN (c) = list; | |
10493 | list = c; | |
10494 | } | |
953ff289 | 10495 | |
acf0174b JJ |
10496 | return list; |
10497 | } | |
953ff289 | 10498 | |
acf0174b JJ |
10499 | /* OpenMP 4.0: |
10500 | thread_limit ( expression ) */ | |
953ff289 DN |
10501 | |
10502 | static tree | |
acf0174b | 10503 | c_parser_omp_clause_thread_limit (c_parser *parser, tree list) |
953ff289 | 10504 | { |
68c81f24 | 10505 | location_t num_thread_limit_loc = c_parser_peek_token (parser)->location; |
acf0174b JJ |
10506 | if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) |
10507 | { | |
10508 | location_t expr_loc = c_parser_peek_token (parser)->location; | |
10509 | tree c, t = c_parser_expression (parser).value; | |
10510 | mark_exp_read (t); | |
10511 | t = c_fully_fold (t, false, NULL); | |
953ff289 | 10512 | |
acf0174b | 10513 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); |
953ff289 | 10514 | |
acf0174b JJ |
10515 | if (!INTEGRAL_TYPE_P (TREE_TYPE (t))) |
10516 | { | |
10517 | c_parser_error (parser, "expected integer expression"); | |
10518 | return list; | |
10519 | } | |
c2255bc4 | 10520 | |
acf0174b JJ |
10521 | /* Attempt to statically determine when the number isn't positive. */ |
10522 | c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t, | |
10523 | build_int_cst (TREE_TYPE (t), 0)); | |
10524 | if (CAN_HAVE_LOCATION_P (c)) | |
10525 | SET_EXPR_LOCATION (c, expr_loc); | |
10526 | if (c == boolean_true_node) | |
10527 | { | |
10528 | warning_at (expr_loc, 0, "%<thread_limit%> value must be positive"); | |
10529 | t = integer_one_node; | |
10530 | } | |
20906c66 | 10531 | |
acf0174b JJ |
10532 | check_no_duplicate_clause (list, OMP_CLAUSE_THREAD_LIMIT, |
10533 | "thread_limit"); | |
20906c66 | 10534 | |
68c81f24 | 10535 | c = build_omp_clause (num_thread_limit_loc, OMP_CLAUSE_THREAD_LIMIT); |
acf0174b JJ |
10536 | OMP_CLAUSE_THREAD_LIMIT_EXPR (c) = t; |
10537 | OMP_CLAUSE_CHAIN (c) = list; | |
10538 | list = c; | |
10539 | } | |
20906c66 | 10540 | |
acf0174b JJ |
10541 | return list; |
10542 | } | |
20906c66 | 10543 | |
acf0174b JJ |
10544 | /* OpenMP 4.0: |
10545 | aligned ( variable-list ) | |
10546 | aligned ( variable-list : constant-expression ) */ | |
20906c66 | 10547 | |
acf0174b JJ |
10548 | static tree |
10549 | c_parser_omp_clause_aligned (c_parser *parser, tree list) | |
10550 | { | |
10551 | location_t clause_loc = c_parser_peek_token (parser)->location; | |
10552 | tree nl, c; | |
20906c66 | 10553 | |
acf0174b JJ |
10554 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) |
10555 | return list; | |
20906c66 | 10556 | |
acf0174b JJ |
10557 | nl = c_parser_omp_variable_list (parser, clause_loc, |
10558 | OMP_CLAUSE_ALIGNED, list); | |
20906c66 | 10559 | |
acf0174b JJ |
10560 | if (c_parser_next_token_is (parser, CPP_COLON)) |
10561 | { | |
10562 | c_parser_consume_token (parser); | |
10563 | tree alignment = c_parser_expr_no_commas (parser, NULL).value; | |
10564 | mark_exp_read (alignment); | |
10565 | alignment = c_fully_fold (alignment, false, NULL); | |
10566 | if (!INTEGRAL_TYPE_P (TREE_TYPE (alignment)) | |
10567 | && TREE_CODE (alignment) != INTEGER_CST | |
10568 | && tree_int_cst_sgn (alignment) != 1) | |
10569 | { | |
10570 | error_at (clause_loc, "%<aligned%> clause alignment expression must " | |
10571 | "be positive constant integer expression"); | |
10572 | alignment = NULL_TREE; | |
10573 | } | |
953ff289 | 10574 | |
acf0174b JJ |
10575 | for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c)) |
10576 | OMP_CLAUSE_ALIGNED_ALIGNMENT (c) = alignment; | |
10577 | } | |
10578 | ||
10579 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
10580 | return nl; | |
10581 | } | |
10582 | ||
10583 | /* OpenMP 4.0: | |
10584 | linear ( variable-list ) | |
10585 | linear ( variable-list : expression ) */ | |
10586 | ||
10587 | static tree | |
41958c28 | 10588 | c_parser_omp_clause_linear (c_parser *parser, tree list, bool is_cilk_simd_fn) |
953ff289 | 10589 | { |
acf0174b JJ |
10590 | location_t clause_loc = c_parser_peek_token (parser)->location; |
10591 | tree nl, c, step; | |
10592 | ||
10593 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
10594 | return list; | |
10595 | ||
10596 | nl = c_parser_omp_variable_list (parser, clause_loc, | |
10597 | OMP_CLAUSE_LINEAR, list); | |
10598 | ||
10599 | if (c_parser_next_token_is (parser, CPP_COLON)) | |
10600 | { | |
10601 | c_parser_consume_token (parser); | |
10602 | step = c_parser_expression (parser).value; | |
10603 | mark_exp_read (step); | |
10604 | step = c_fully_fold (step, false, NULL); | |
41958c28 BI |
10605 | if (is_cilk_simd_fn && TREE_CODE (step) == PARM_DECL) |
10606 | { | |
10607 | sorry ("using parameters for %<linear%> step is not supported yet"); | |
10608 | step = integer_one_node; | |
10609 | } | |
acf0174b JJ |
10610 | if (!INTEGRAL_TYPE_P (TREE_TYPE (step))) |
10611 | { | |
10612 | error_at (clause_loc, "%<linear%> clause step expression must " | |
10613 | "be integral"); | |
10614 | step = integer_one_node; | |
10615 | } | |
10616 | ||
10617 | } | |
10618 | else | |
10619 | step = integer_one_node; | |
10620 | ||
10621 | for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c)) | |
10622 | { | |
10623 | OMP_CLAUSE_LINEAR_STEP (c) = step; | |
10624 | } | |
10625 | ||
10626 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
10627 | return nl; | |
10628 | } | |
10629 | ||
10630 | /* OpenMP 4.0: | |
10631 | safelen ( constant-expression ) */ | |
10632 | ||
10633 | static tree | |
10634 | c_parser_omp_clause_safelen (c_parser *parser, tree list) | |
10635 | { | |
10636 | location_t clause_loc = c_parser_peek_token (parser)->location; | |
10637 | tree c, t; | |
10638 | ||
10639 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
10640 | return list; | |
10641 | ||
10642 | t = c_parser_expr_no_commas (parser, NULL).value; | |
10643 | mark_exp_read (t); | |
10644 | t = c_fully_fold (t, false, NULL); | |
10645 | if (!INTEGRAL_TYPE_P (TREE_TYPE (t)) | |
10646 | && TREE_CODE (t) != INTEGER_CST | |
10647 | && tree_int_cst_sgn (t) != 1) | |
10648 | { | |
10649 | error_at (clause_loc, "%<safelen%> clause expression must " | |
10650 | "be positive constant integer expression"); | |
10651 | t = NULL_TREE; | |
10652 | } | |
10653 | ||
10654 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
10655 | if (t == NULL_TREE || t == error_mark_node) | |
10656 | return list; | |
10657 | ||
10658 | check_no_duplicate_clause (list, OMP_CLAUSE_SAFELEN, "safelen"); | |
10659 | ||
10660 | c = build_omp_clause (clause_loc, OMP_CLAUSE_SAFELEN); | |
10661 | OMP_CLAUSE_SAFELEN_EXPR (c) = t; | |
10662 | OMP_CLAUSE_CHAIN (c) = list; | |
10663 | return c; | |
10664 | } | |
10665 | ||
10666 | /* OpenMP 4.0: | |
10667 | simdlen ( constant-expression ) */ | |
10668 | ||
10669 | static tree | |
10670 | c_parser_omp_clause_simdlen (c_parser *parser, tree list) | |
10671 | { | |
10672 | location_t clause_loc = c_parser_peek_token (parser)->location; | |
10673 | tree c, t; | |
10674 | ||
10675 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
10676 | return list; | |
10677 | ||
10678 | t = c_parser_expr_no_commas (parser, NULL).value; | |
10679 | mark_exp_read (t); | |
10680 | t = c_fully_fold (t, false, NULL); | |
10681 | if (!INTEGRAL_TYPE_P (TREE_TYPE (t)) | |
10682 | && TREE_CODE (t) != INTEGER_CST | |
10683 | && tree_int_cst_sgn (t) != 1) | |
10684 | { | |
10685 | error_at (clause_loc, "%<simdlen%> clause expression must " | |
10686 | "be positive constant integer expression"); | |
10687 | t = NULL_TREE; | |
10688 | } | |
10689 | ||
10690 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
10691 | if (t == NULL_TREE || t == error_mark_node) | |
10692 | return list; | |
10693 | ||
10694 | check_no_duplicate_clause (list, OMP_CLAUSE_SIMDLEN, "simdlen"); | |
10695 | ||
10696 | c = build_omp_clause (clause_loc, OMP_CLAUSE_SIMDLEN); | |
10697 | OMP_CLAUSE_SIMDLEN_EXPR (c) = t; | |
10698 | OMP_CLAUSE_CHAIN (c) = list; | |
10699 | return c; | |
10700 | } | |
10701 | ||
10702 | /* OpenMP 4.0: | |
10703 | depend ( depend-kind: variable-list ) | |
10704 | ||
10705 | depend-kind: | |
10706 | in | out | inout */ | |
10707 | ||
10708 | static tree | |
10709 | c_parser_omp_clause_depend (c_parser *parser, tree list) | |
10710 | { | |
10711 | location_t clause_loc = c_parser_peek_token (parser)->location; | |
10712 | enum omp_clause_depend_kind kind = OMP_CLAUSE_DEPEND_INOUT; | |
10713 | tree nl, c; | |
10714 | ||
10715 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
10716 | return list; | |
953ff289 | 10717 | |
20906c66 JJ |
10718 | if (c_parser_next_token_is (parser, CPP_NAME)) |
10719 | { | |
10720 | const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); | |
acf0174b JJ |
10721 | if (strcmp ("in", p) == 0) |
10722 | kind = OMP_CLAUSE_DEPEND_IN; | |
10723 | else if (strcmp ("inout", p) == 0) | |
10724 | kind = OMP_CLAUSE_DEPEND_INOUT; | |
10725 | else if (strcmp ("out", p) == 0) | |
10726 | kind = OMP_CLAUSE_DEPEND_OUT; | |
20906c66 | 10727 | else |
acf0174b | 10728 | goto invalid_kind; |
20906c66 | 10729 | } |
acf0174b JJ |
10730 | else |
10731 | goto invalid_kind; | |
953ff289 | 10732 | |
acf0174b JJ |
10733 | c_parser_consume_token (parser); |
10734 | if (!c_parser_require (parser, CPP_COLON, "expected %<:%>")) | |
10735 | goto resync_fail; | |
10736 | ||
10737 | nl = c_parser_omp_variable_list (parser, clause_loc, | |
10738 | OMP_CLAUSE_DEPEND, list); | |
10739 | ||
10740 | for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c)) | |
10741 | OMP_CLAUSE_DEPEND_KIND (c) = kind; | |
10742 | ||
10743 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
10744 | return nl; | |
10745 | ||
10746 | invalid_kind: | |
10747 | c_parser_error (parser, "invalid depend kind"); | |
10748 | resync_fail: | |
10749 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
10750 | return list; | |
10751 | } | |
10752 | ||
10753 | /* OpenMP 4.0: | |
10754 | map ( map-kind: variable-list ) | |
10755 | map ( variable-list ) | |
10756 | ||
10757 | map-kind: | |
10758 | alloc | to | from | tofrom */ | |
10759 | ||
10760 | static tree | |
10761 | c_parser_omp_clause_map (c_parser *parser, tree list) | |
10762 | { | |
10763 | location_t clause_loc = c_parser_peek_token (parser)->location; | |
10764 | enum omp_clause_map_kind kind = OMP_CLAUSE_MAP_TOFROM; | |
10765 | tree nl, c; | |
10766 | ||
10767 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
10768 | return list; | |
10769 | ||
10770 | if (c_parser_next_token_is (parser, CPP_NAME) | |
10771 | && c_parser_peek_2nd_token (parser)->type == CPP_COLON) | |
20906c66 | 10772 | { |
acf0174b JJ |
10773 | const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
10774 | if (strcmp ("alloc", p) == 0) | |
10775 | kind = OMP_CLAUSE_MAP_ALLOC; | |
10776 | else if (strcmp ("to", p) == 0) | |
10777 | kind = OMP_CLAUSE_MAP_TO; | |
10778 | else if (strcmp ("from", p) == 0) | |
10779 | kind = OMP_CLAUSE_MAP_FROM; | |
10780 | else if (strcmp ("tofrom", p) == 0) | |
10781 | kind = OMP_CLAUSE_MAP_TOFROM; | |
20906c66 JJ |
10782 | else |
10783 | { | |
acf0174b JJ |
10784 | c_parser_error (parser, "invalid map kind"); |
10785 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, | |
10786 | "expected %<)%>"); | |
10787 | return list; | |
20906c66 | 10788 | } |
acf0174b JJ |
10789 | c_parser_consume_token (parser); |
10790 | c_parser_consume_token (parser); | |
20906c66 JJ |
10791 | } |
10792 | ||
acf0174b JJ |
10793 | nl = c_parser_omp_variable_list (parser, clause_loc, OMP_CLAUSE_MAP, list); |
10794 | ||
10795 | for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c)) | |
10796 | OMP_CLAUSE_MAP_KIND (c) = kind; | |
10797 | ||
10798 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
10799 | return nl; | |
10800 | } | |
10801 | ||
10802 | /* OpenMP 4.0: | |
10803 | device ( expression ) */ | |
10804 | ||
10805 | static tree | |
10806 | c_parser_omp_clause_device (c_parser *parser, tree list) | |
10807 | { | |
10808 | location_t clause_loc = c_parser_peek_token (parser)->location; | |
10809 | if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
953ff289 | 10810 | { |
acf0174b JJ |
10811 | tree c, t = c_parser_expr_no_commas (parser, NULL).value; |
10812 | mark_exp_read (t); | |
10813 | t = c_fully_fold (t, false, NULL); | |
10814 | ||
10815 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
10816 | ||
10817 | if (!INTEGRAL_TYPE_P (TREE_TYPE (t))) | |
20906c66 | 10818 | { |
acf0174b JJ |
10819 | c_parser_error (parser, "expected integer expression"); |
10820 | return list; | |
20906c66 | 10821 | } |
953ff289 | 10822 | |
acf0174b | 10823 | check_no_duplicate_clause (list, OMP_CLAUSE_DEVICE, "device"); |
953ff289 | 10824 | |
acf0174b JJ |
10825 | c = build_omp_clause (clause_loc, OMP_CLAUSE_DEVICE); |
10826 | OMP_CLAUSE_DEVICE_ID (c) = t; | |
10827 | OMP_CLAUSE_CHAIN (c) = list; | |
10828 | list = c; | |
10829 | } | |
953ff289 | 10830 | |
acf0174b JJ |
10831 | return list; |
10832 | } | |
10833 | ||
10834 | /* OpenMP 4.0: | |
10835 | dist_schedule ( static ) | |
10836 | dist_schedule ( static , expression ) */ | |
10837 | ||
10838 | static tree | |
10839 | c_parser_omp_clause_dist_schedule (c_parser *parser, tree list) | |
10840 | { | |
10841 | tree c, t = NULL_TREE; | |
10842 | location_t loc = c_parser_peek_token (parser)->location; | |
10843 | ||
10844 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
10845 | return list; | |
10846 | ||
10847 | if (!c_parser_next_token_is_keyword (parser, RID_STATIC)) | |
10848 | { | |
10849 | c_parser_error (parser, "invalid dist_schedule kind"); | |
10850 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, | |
10851 | "expected %<)%>"); | |
10852 | return list; | |
10853 | } | |
10854 | ||
10855 | c_parser_consume_token (parser); | |
10856 | if (c_parser_next_token_is (parser, CPP_COMMA)) | |
10857 | { | |
10858 | c_parser_consume_token (parser); | |
10859 | ||
10860 | t = c_parser_expr_no_commas (parser, NULL).value; | |
10861 | mark_exp_read (t); | |
10862 | t = c_fully_fold (t, false, NULL); | |
10863 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
10864 | } | |
10865 | else | |
10866 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, | |
10867 | "expected %<,%> or %<)%>"); | |
10868 | ||
10869 | check_no_duplicate_clause (list, OMP_CLAUSE_SCHEDULE, "schedule"); | |
10870 | if (t == error_mark_node) | |
10871 | return list; | |
10872 | ||
10873 | c = build_omp_clause (loc, OMP_CLAUSE_DIST_SCHEDULE); | |
10874 | OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c) = t; | |
10875 | OMP_CLAUSE_CHAIN (c) = list; | |
10876 | return c; | |
10877 | } | |
10878 | ||
10879 | /* OpenMP 4.0: | |
10880 | proc_bind ( proc-bind-kind ) | |
10881 | ||
10882 | proc-bind-kind: | |
10883 | master | close | spread */ | |
10884 | ||
10885 | static tree | |
10886 | c_parser_omp_clause_proc_bind (c_parser *parser, tree list) | |
10887 | { | |
10888 | location_t clause_loc = c_parser_peek_token (parser)->location; | |
10889 | enum omp_clause_proc_bind_kind kind; | |
10890 | tree c; | |
10891 | ||
10892 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
10893 | return list; | |
10894 | ||
10895 | if (c_parser_next_token_is (parser, CPP_NAME)) | |
10896 | { | |
10897 | const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); | |
10898 | if (strcmp ("master", p) == 0) | |
10899 | kind = OMP_CLAUSE_PROC_BIND_MASTER; | |
10900 | else if (strcmp ("close", p) == 0) | |
10901 | kind = OMP_CLAUSE_PROC_BIND_CLOSE; | |
10902 | else if (strcmp ("spread", p) == 0) | |
10903 | kind = OMP_CLAUSE_PROC_BIND_SPREAD; | |
10904 | else | |
10905 | goto invalid_kind; | |
10906 | } | |
10907 | else | |
10908 | goto invalid_kind; | |
10909 | ||
10910 | c_parser_consume_token (parser); | |
10911 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
10912 | c = build_omp_clause (clause_loc, OMP_CLAUSE_PROC_BIND); | |
10913 | OMP_CLAUSE_PROC_BIND_KIND (c) = kind; | |
10914 | OMP_CLAUSE_CHAIN (c) = list; | |
10915 | return c; | |
10916 | ||
10917 | invalid_kind: | |
10918 | c_parser_error (parser, "invalid proc_bind kind"); | |
10919 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
10920 | return list; | |
10921 | } | |
10922 | ||
10923 | /* OpenMP 4.0: | |
10924 | to ( variable-list ) */ | |
10925 | ||
10926 | static tree | |
10927 | c_parser_omp_clause_to (c_parser *parser, tree list) | |
10928 | { | |
10929 | return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_TO, list); | |
10930 | } | |
10931 | ||
10932 | /* OpenMP 4.0: | |
10933 | from ( variable-list ) */ | |
10934 | ||
10935 | static tree | |
10936 | c_parser_omp_clause_from (c_parser *parser, tree list) | |
10937 | { | |
10938 | return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_FROM, list); | |
10939 | } | |
10940 | ||
10941 | /* OpenMP 4.0: | |
10942 | uniform ( variable-list ) */ | |
10943 | ||
10944 | static tree | |
10945 | c_parser_omp_clause_uniform (c_parser *parser, tree list) | |
10946 | { | |
10947 | /* The clauses location. */ | |
10948 | location_t loc = c_parser_peek_token (parser)->location; | |
10949 | ||
10950 | if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
10951 | { | |
10952 | list = c_parser_omp_variable_list (parser, loc, OMP_CLAUSE_UNIFORM, | |
10953 | list); | |
10954 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
10955 | } | |
10956 | return list; | |
10957 | } | |
10958 | ||
10959 | /* Parse all OpenMP clauses. The set clauses allowed by the directive | |
10960 | is a bitmask in MASK. Return the list of clauses found; the result | |
10961 | of clause default goes in *pdefault. */ | |
10962 | ||
10963 | static tree | |
10964 | c_parser_omp_all_clauses (c_parser *parser, omp_clause_mask mask, | |
10965 | const char *where, bool finish_p = true) | |
10966 | { | |
10967 | tree clauses = NULL; | |
41958c28 | 10968 | bool first = true, cilk_simd_fn = false; |
acf0174b JJ |
10969 | |
10970 | while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL)) | |
10971 | { | |
10972 | location_t here; | |
10973 | pragma_omp_clause c_kind; | |
10974 | const char *c_name; | |
10975 | tree prev = clauses; | |
10976 | ||
10977 | if (!first && c_parser_next_token_is (parser, CPP_COMMA)) | |
10978 | c_parser_consume_token (parser); | |
10979 | ||
10980 | here = c_parser_peek_token (parser)->location; | |
10981 | c_kind = c_parser_omp_clause_name (parser); | |
10982 | ||
10983 | switch (c_kind) | |
953ff289 | 10984 | { |
acf0174b JJ |
10985 | case PRAGMA_OMP_CLAUSE_COLLAPSE: |
10986 | clauses = c_parser_omp_clause_collapse (parser, clauses); | |
10987 | c_name = "collapse"; | |
953ff289 | 10988 | break; |
acf0174b JJ |
10989 | case PRAGMA_OMP_CLAUSE_COPYIN: |
10990 | clauses = c_parser_omp_clause_copyin (parser, clauses); | |
10991 | c_name = "copyin"; | |
953ff289 | 10992 | break; |
acf0174b JJ |
10993 | case PRAGMA_OMP_CLAUSE_COPYPRIVATE: |
10994 | clauses = c_parser_omp_clause_copyprivate (parser, clauses); | |
10995 | c_name = "copyprivate"; | |
953ff289 | 10996 | break; |
acf0174b JJ |
10997 | case PRAGMA_OMP_CLAUSE_DEFAULT: |
10998 | clauses = c_parser_omp_clause_default (parser, clauses); | |
10999 | c_name = "default"; | |
953ff289 | 11000 | break; |
acf0174b JJ |
11001 | case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE: |
11002 | clauses = c_parser_omp_clause_firstprivate (parser, clauses); | |
11003 | c_name = "firstprivate"; | |
953ff289 | 11004 | break; |
acf0174b JJ |
11005 | case PRAGMA_OMP_CLAUSE_FINAL: |
11006 | clauses = c_parser_omp_clause_final (parser, clauses); | |
11007 | c_name = "final"; | |
953ff289 | 11008 | break; |
acf0174b JJ |
11009 | case PRAGMA_OMP_CLAUSE_IF: |
11010 | clauses = c_parser_omp_clause_if (parser, clauses); | |
11011 | c_name = "if"; | |
953ff289 | 11012 | break; |
acf0174b JJ |
11013 | case PRAGMA_OMP_CLAUSE_LASTPRIVATE: |
11014 | clauses = c_parser_omp_clause_lastprivate (parser, clauses); | |
11015 | c_name = "lastprivate"; | |
953ff289 | 11016 | break; |
acf0174b JJ |
11017 | case PRAGMA_OMP_CLAUSE_MERGEABLE: |
11018 | clauses = c_parser_omp_clause_mergeable (parser, clauses); | |
11019 | c_name = "mergeable"; | |
953ff289 | 11020 | break; |
acf0174b JJ |
11021 | case PRAGMA_OMP_CLAUSE_NOWAIT: |
11022 | clauses = c_parser_omp_clause_nowait (parser, clauses); | |
11023 | c_name = "nowait"; | |
11024 | break; | |
11025 | case PRAGMA_OMP_CLAUSE_NUM_THREADS: | |
11026 | clauses = c_parser_omp_clause_num_threads (parser, clauses); | |
11027 | c_name = "num_threads"; | |
11028 | break; | |
11029 | case PRAGMA_OMP_CLAUSE_ORDERED: | |
11030 | clauses = c_parser_omp_clause_ordered (parser, clauses); | |
11031 | c_name = "ordered"; | |
11032 | break; | |
11033 | case PRAGMA_OMP_CLAUSE_PRIVATE: | |
11034 | clauses = c_parser_omp_clause_private (parser, clauses); | |
11035 | c_name = "private"; | |
11036 | break; | |
11037 | case PRAGMA_OMP_CLAUSE_REDUCTION: | |
11038 | clauses = c_parser_omp_clause_reduction (parser, clauses); | |
11039 | c_name = "reduction"; | |
11040 | break; | |
11041 | case PRAGMA_OMP_CLAUSE_SCHEDULE: | |
11042 | clauses = c_parser_omp_clause_schedule (parser, clauses); | |
11043 | c_name = "schedule"; | |
11044 | break; | |
11045 | case PRAGMA_OMP_CLAUSE_SHARED: | |
11046 | clauses = c_parser_omp_clause_shared (parser, clauses); | |
11047 | c_name = "shared"; | |
11048 | break; | |
11049 | case PRAGMA_OMP_CLAUSE_UNTIED: | |
11050 | clauses = c_parser_omp_clause_untied (parser, clauses); | |
11051 | c_name = "untied"; | |
11052 | break; | |
11053 | case PRAGMA_OMP_CLAUSE_INBRANCH: | |
41958c28 | 11054 | case PRAGMA_CILK_CLAUSE_MASK: |
acf0174b JJ |
11055 | clauses = c_parser_omp_clause_branch (parser, OMP_CLAUSE_INBRANCH, |
11056 | clauses); | |
11057 | c_name = "inbranch"; | |
11058 | break; | |
11059 | case PRAGMA_OMP_CLAUSE_NOTINBRANCH: | |
41958c28 | 11060 | case PRAGMA_CILK_CLAUSE_NOMASK: |
acf0174b JJ |
11061 | clauses = c_parser_omp_clause_branch (parser, OMP_CLAUSE_NOTINBRANCH, |
11062 | clauses); | |
11063 | c_name = "notinbranch"; | |
11064 | break; | |
11065 | case PRAGMA_OMP_CLAUSE_PARALLEL: | |
11066 | clauses | |
11067 | = c_parser_omp_clause_cancelkind (parser, OMP_CLAUSE_PARALLEL, | |
11068 | clauses); | |
11069 | c_name = "parallel"; | |
11070 | if (!first) | |
20906c66 | 11071 | { |
acf0174b JJ |
11072 | clause_not_first: |
11073 | error_at (here, "%qs must be the first clause of %qs", | |
11074 | c_name, where); | |
11075 | clauses = prev; | |
11076 | } | |
11077 | break; | |
11078 | case PRAGMA_OMP_CLAUSE_FOR: | |
11079 | clauses | |
11080 | = c_parser_omp_clause_cancelkind (parser, OMP_CLAUSE_FOR, | |
11081 | clauses); | |
11082 | c_name = "for"; | |
11083 | if (!first) | |
11084 | goto clause_not_first; | |
11085 | break; | |
11086 | case PRAGMA_OMP_CLAUSE_SECTIONS: | |
11087 | clauses | |
11088 | = c_parser_omp_clause_cancelkind (parser, OMP_CLAUSE_SECTIONS, | |
11089 | clauses); | |
11090 | c_name = "sections"; | |
11091 | if (!first) | |
11092 | goto clause_not_first; | |
11093 | break; | |
11094 | case PRAGMA_OMP_CLAUSE_TASKGROUP: | |
11095 | clauses | |
11096 | = c_parser_omp_clause_cancelkind (parser, OMP_CLAUSE_TASKGROUP, | |
11097 | clauses); | |
11098 | c_name = "taskgroup"; | |
11099 | if (!first) | |
11100 | goto clause_not_first; | |
11101 | break; | |
11102 | case PRAGMA_OMP_CLAUSE_TO: | |
11103 | clauses = c_parser_omp_clause_to (parser, clauses); | |
11104 | c_name = "to"; | |
11105 | break; | |
11106 | case PRAGMA_OMP_CLAUSE_FROM: | |
11107 | clauses = c_parser_omp_clause_from (parser, clauses); | |
11108 | c_name = "from"; | |
11109 | break; | |
11110 | case PRAGMA_OMP_CLAUSE_UNIFORM: | |
11111 | clauses = c_parser_omp_clause_uniform (parser, clauses); | |
11112 | c_name = "uniform"; | |
11113 | break; | |
11114 | case PRAGMA_OMP_CLAUSE_NUM_TEAMS: | |
11115 | clauses = c_parser_omp_clause_num_teams (parser, clauses); | |
11116 | c_name = "num_teams"; | |
11117 | break; | |
11118 | case PRAGMA_OMP_CLAUSE_THREAD_LIMIT: | |
11119 | clauses = c_parser_omp_clause_thread_limit (parser, clauses); | |
11120 | c_name = "thread_limit"; | |
11121 | break; | |
11122 | case PRAGMA_OMP_CLAUSE_ALIGNED: | |
11123 | clauses = c_parser_omp_clause_aligned (parser, clauses); | |
11124 | c_name = "aligned"; | |
11125 | break; | |
41958c28 BI |
11126 | case PRAGMA_OMP_CLAUSE_LINEAR: |
11127 | if (((mask >> PRAGMA_CILK_CLAUSE_VECTORLENGTH) & 1) != 0) | |
11128 | cilk_simd_fn = true; | |
11129 | clauses = c_parser_omp_clause_linear (parser, clauses, cilk_simd_fn); | |
acf0174b JJ |
11130 | c_name = "linear"; |
11131 | break; | |
11132 | case PRAGMA_OMP_CLAUSE_DEPEND: | |
11133 | clauses = c_parser_omp_clause_depend (parser, clauses); | |
11134 | c_name = "depend"; | |
11135 | break; | |
11136 | case PRAGMA_OMP_CLAUSE_MAP: | |
11137 | clauses = c_parser_omp_clause_map (parser, clauses); | |
11138 | c_name = "map"; | |
11139 | break; | |
11140 | case PRAGMA_OMP_CLAUSE_DEVICE: | |
11141 | clauses = c_parser_omp_clause_device (parser, clauses); | |
11142 | c_name = "device"; | |
11143 | break; | |
11144 | case PRAGMA_OMP_CLAUSE_DIST_SCHEDULE: | |
11145 | clauses = c_parser_omp_clause_dist_schedule (parser, clauses); | |
11146 | c_name = "dist_schedule"; | |
11147 | break; | |
11148 | case PRAGMA_OMP_CLAUSE_PROC_BIND: | |
11149 | clauses = c_parser_omp_clause_proc_bind (parser, clauses); | |
11150 | c_name = "proc_bind"; | |
11151 | break; | |
11152 | case PRAGMA_OMP_CLAUSE_SAFELEN: | |
11153 | clauses = c_parser_omp_clause_safelen (parser, clauses); | |
11154 | c_name = "safelen"; | |
11155 | break; | |
41958c28 BI |
11156 | case PRAGMA_CILK_CLAUSE_VECTORLENGTH: |
11157 | clauses = c_parser_cilk_clause_vectorlength (parser, clauses, true); | |
11158 | c_name = "simdlen"; | |
11159 | break; | |
acf0174b JJ |
11160 | case PRAGMA_OMP_CLAUSE_SIMDLEN: |
11161 | clauses = c_parser_omp_clause_simdlen (parser, clauses); | |
11162 | c_name = "simdlen"; | |
11163 | break; | |
953ff289 | 11164 | default: |
acf0174b | 11165 | c_parser_error (parser, "expected %<#pragma omp%> clause"); |
953ff289 DN |
11166 | goto saw_error; |
11167 | } | |
11168 | ||
acf0174b JJ |
11169 | first = false; |
11170 | ||
11171 | if (((mask >> c_kind) & 1) == 0 && !parser->error) | |
11172 | { | |
11173 | /* Remove the invalid clause(s) from the list to avoid | |
11174 | confusing the rest of the compiler. */ | |
11175 | clauses = prev; | |
11176 | error_at (here, "%qs is not valid for %qs", c_name, where); | |
11177 | } | |
11178 | } | |
11179 | ||
11180 | saw_error: | |
11181 | c_parser_skip_to_pragma_eol (parser); | |
11182 | ||
11183 | if (finish_p) | |
11184 | return c_finish_omp_clauses (clauses); | |
11185 | ||
11186 | return clauses; | |
11187 | } | |
11188 | ||
11189 | /* OpenMP 2.5: | |
11190 | structured-block: | |
11191 | statement | |
11192 | ||
11193 | In practice, we're also interested in adding the statement to an | |
11194 | outer node. So it is convenient if we work around the fact that | |
11195 | c_parser_statement calls add_stmt. */ | |
11196 | ||
11197 | static tree | |
11198 | c_parser_omp_structured_block (c_parser *parser) | |
11199 | { | |
11200 | tree stmt = push_stmt_list (); | |
11201 | c_parser_statement (parser); | |
11202 | return pop_stmt_list (stmt); | |
11203 | } | |
11204 | ||
11205 | /* OpenMP 2.5: | |
11206 | # pragma omp atomic new-line | |
11207 | expression-stmt | |
11208 | ||
11209 | expression-stmt: | |
11210 | x binop= expr | x++ | ++x | x-- | --x | |
11211 | binop: | |
11212 | +, *, -, /, &, ^, |, <<, >> | |
11213 | ||
11214 | where x is an lvalue expression with scalar type. | |
11215 | ||
11216 | OpenMP 3.1: | |
11217 | # pragma omp atomic new-line | |
11218 | update-stmt | |
11219 | ||
11220 | # pragma omp atomic read new-line | |
11221 | read-stmt | |
11222 | ||
11223 | # pragma omp atomic write new-line | |
11224 | write-stmt | |
11225 | ||
11226 | # pragma omp atomic update new-line | |
11227 | update-stmt | |
11228 | ||
11229 | # pragma omp atomic capture new-line | |
11230 | capture-stmt | |
11231 | ||
11232 | # pragma omp atomic capture new-line | |
11233 | capture-block | |
11234 | ||
11235 | read-stmt: | |
11236 | v = x | |
11237 | write-stmt: | |
11238 | x = expr | |
11239 | update-stmt: | |
11240 | expression-stmt | x = x binop expr | |
11241 | capture-stmt: | |
11242 | v = expression-stmt | |
11243 | capture-block: | |
11244 | { v = x; update-stmt; } | { update-stmt; v = x; } | |
11245 | ||
11246 | OpenMP 4.0: | |
11247 | update-stmt: | |
11248 | expression-stmt | x = x binop expr | x = expr binop x | |
11249 | capture-stmt: | |
11250 | v = update-stmt | |
11251 | capture-block: | |
11252 | { v = x; update-stmt; } | { update-stmt; v = x; } | { v = x; x = expr; } | |
11253 | ||
11254 | where x and v are lvalue expressions with scalar type. | |
11255 | ||
11256 | LOC is the location of the #pragma token. */ | |
11257 | ||
11258 | static void | |
11259 | c_parser_omp_atomic (location_t loc, c_parser *parser) | |
11260 | { | |
11261 | tree lhs = NULL_TREE, rhs = NULL_TREE, v = NULL_TREE; | |
11262 | tree lhs1 = NULL_TREE, rhs1 = NULL_TREE; | |
11263 | tree stmt, orig_lhs, unfolded_lhs = NULL_TREE, unfolded_lhs1 = NULL_TREE; | |
11264 | enum tree_code code = OMP_ATOMIC, opcode = NOP_EXPR; | |
11265 | struct c_expr expr; | |
11266 | location_t eloc; | |
11267 | bool structured_block = false; | |
11268 | bool swapped = false; | |
11269 | bool seq_cst = false; | |
11270 | ||
42056eac JJ |
11271 | if (c_parser_next_token_is (parser, CPP_NAME)) |
11272 | { | |
11273 | const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); | |
11274 | if (!strcmp (p, "seq_cst")) | |
11275 | { | |
11276 | seq_cst = true; | |
11277 | c_parser_consume_token (parser); | |
11278 | if (c_parser_next_token_is (parser, CPP_COMMA) | |
11279 | && c_parser_peek_2nd_token (parser)->type == CPP_NAME) | |
11280 | c_parser_consume_token (parser); | |
11281 | } | |
11282 | } | |
acf0174b JJ |
11283 | if (c_parser_next_token_is (parser, CPP_NAME)) |
11284 | { | |
11285 | const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); | |
11286 | ||
11287 | if (!strcmp (p, "read")) | |
11288 | code = OMP_ATOMIC_READ; | |
11289 | else if (!strcmp (p, "write")) | |
11290 | code = NOP_EXPR; | |
11291 | else if (!strcmp (p, "update")) | |
11292 | code = OMP_ATOMIC; | |
11293 | else if (!strcmp (p, "capture")) | |
11294 | code = OMP_ATOMIC_CAPTURE_NEW; | |
11295 | else | |
11296 | p = NULL; | |
11297 | if (p) | |
11298 | c_parser_consume_token (parser); | |
11299 | } | |
42056eac | 11300 | if (!seq_cst) |
acf0174b | 11301 | { |
42056eac JJ |
11302 | if (c_parser_next_token_is (parser, CPP_COMMA) |
11303 | && c_parser_peek_2nd_token (parser)->type == CPP_NAME) | |
11304 | c_parser_consume_token (parser); | |
11305 | ||
11306 | if (c_parser_next_token_is (parser, CPP_NAME)) | |
acf0174b | 11307 | { |
42056eac JJ |
11308 | const char *p |
11309 | = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); | |
11310 | if (!strcmp (p, "seq_cst")) | |
11311 | { | |
11312 | seq_cst = true; | |
11313 | c_parser_consume_token (parser); | |
11314 | } | |
acf0174b JJ |
11315 | } |
11316 | } | |
11317 | c_parser_skip_to_pragma_eol (parser); | |
11318 | ||
11319 | switch (code) | |
11320 | { | |
11321 | case OMP_ATOMIC_READ: | |
11322 | case NOP_EXPR: /* atomic write */ | |
11323 | v = c_parser_unary_expression (parser).value; | |
11324 | v = c_fully_fold (v, false, NULL); | |
11325 | if (v == error_mark_node) | |
11326 | goto saw_error; | |
11327 | loc = c_parser_peek_token (parser)->location; | |
11328 | if (!c_parser_require (parser, CPP_EQ, "expected %<=%>")) | |
11329 | goto saw_error; | |
11330 | if (code == NOP_EXPR) | |
11331 | lhs = c_parser_expression (parser).value; | |
11332 | else | |
11333 | lhs = c_parser_unary_expression (parser).value; | |
11334 | lhs = c_fully_fold (lhs, false, NULL); | |
11335 | if (lhs == error_mark_node) | |
11336 | goto saw_error; | |
11337 | if (code == NOP_EXPR) | |
11338 | { | |
11339 | /* atomic write is represented by OMP_ATOMIC with NOP_EXPR | |
11340 | opcode. */ | |
11341 | code = OMP_ATOMIC; | |
11342 | rhs = lhs; | |
11343 | lhs = v; | |
11344 | v = NULL_TREE; | |
11345 | } | |
11346 | goto done; | |
11347 | case OMP_ATOMIC_CAPTURE_NEW: | |
11348 | if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) | |
11349 | { | |
11350 | c_parser_consume_token (parser); | |
11351 | structured_block = true; | |
11352 | } | |
11353 | else | |
11354 | { | |
11355 | v = c_parser_unary_expression (parser).value; | |
11356 | v = c_fully_fold (v, false, NULL); | |
11357 | if (v == error_mark_node) | |
11358 | goto saw_error; | |
11359 | if (!c_parser_require (parser, CPP_EQ, "expected %<=%>")) | |
11360 | goto saw_error; | |
11361 | } | |
11362 | break; | |
11363 | default: | |
11364 | break; | |
11365 | } | |
11366 | ||
11367 | /* For structured_block case we don't know yet whether | |
11368 | old or new x should be captured. */ | |
11369 | restart: | |
11370 | eloc = c_parser_peek_token (parser)->location; | |
11371 | expr = c_parser_unary_expression (parser); | |
11372 | lhs = expr.value; | |
11373 | expr = default_function_array_conversion (eloc, expr); | |
11374 | unfolded_lhs = expr.value; | |
11375 | lhs = c_fully_fold (lhs, false, NULL); | |
11376 | orig_lhs = lhs; | |
11377 | switch (TREE_CODE (lhs)) | |
11378 | { | |
11379 | case ERROR_MARK: | |
11380 | saw_error: | |
11381 | c_parser_skip_to_end_of_block_or_statement (parser); | |
11382 | if (structured_block) | |
11383 | { | |
11384 | if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) | |
11385 | c_parser_consume_token (parser); | |
11386 | else if (code == OMP_ATOMIC_CAPTURE_NEW) | |
11387 | { | |
11388 | c_parser_skip_to_end_of_block_or_statement (parser); | |
11389 | if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) | |
11390 | c_parser_consume_token (parser); | |
11391 | } | |
11392 | } | |
11393 | return; | |
11394 | ||
11395 | case POSTINCREMENT_EXPR: | |
11396 | if (code == OMP_ATOMIC_CAPTURE_NEW && !structured_block) | |
11397 | code = OMP_ATOMIC_CAPTURE_OLD; | |
11398 | /* FALLTHROUGH */ | |
11399 | case PREINCREMENT_EXPR: | |
11400 | lhs = TREE_OPERAND (lhs, 0); | |
11401 | unfolded_lhs = NULL_TREE; | |
11402 | opcode = PLUS_EXPR; | |
11403 | rhs = integer_one_node; | |
11404 | break; | |
11405 | ||
11406 | case POSTDECREMENT_EXPR: | |
11407 | if (code == OMP_ATOMIC_CAPTURE_NEW && !structured_block) | |
11408 | code = OMP_ATOMIC_CAPTURE_OLD; | |
11409 | /* FALLTHROUGH */ | |
11410 | case PREDECREMENT_EXPR: | |
11411 | lhs = TREE_OPERAND (lhs, 0); | |
11412 | unfolded_lhs = NULL_TREE; | |
11413 | opcode = MINUS_EXPR; | |
11414 | rhs = integer_one_node; | |
11415 | break; | |
11416 | ||
11417 | case COMPOUND_EXPR: | |
11418 | if (TREE_CODE (TREE_OPERAND (lhs, 0)) == SAVE_EXPR | |
11419 | && TREE_CODE (TREE_OPERAND (lhs, 1)) == COMPOUND_EXPR | |
11420 | && TREE_CODE (TREE_OPERAND (TREE_OPERAND (lhs, 1), 0)) == MODIFY_EXPR | |
11421 | && TREE_OPERAND (TREE_OPERAND (lhs, 1), 1) == TREE_OPERAND (lhs, 0) | |
11422 | && TREE_CODE (TREE_TYPE (TREE_OPERAND (TREE_OPERAND | |
11423 | (TREE_OPERAND (lhs, 1), 0), 0))) | |
11424 | == BOOLEAN_TYPE) | |
11425 | /* Undo effects of boolean_increment for post {in,de}crement. */ | |
11426 | lhs = TREE_OPERAND (TREE_OPERAND (lhs, 1), 0); | |
11427 | /* FALLTHRU */ | |
11428 | case MODIFY_EXPR: | |
11429 | if (TREE_CODE (lhs) == MODIFY_EXPR | |
11430 | && TREE_CODE (TREE_TYPE (TREE_OPERAND (lhs, 0))) == BOOLEAN_TYPE) | |
11431 | { | |
11432 | /* Undo effects of boolean_increment. */ | |
11433 | if (integer_onep (TREE_OPERAND (lhs, 1))) | |
11434 | { | |
11435 | /* This is pre or post increment. */ | |
11436 | rhs = TREE_OPERAND (lhs, 1); | |
11437 | lhs = TREE_OPERAND (lhs, 0); | |
11438 | unfolded_lhs = NULL_TREE; | |
11439 | opcode = NOP_EXPR; | |
11440 | if (code == OMP_ATOMIC_CAPTURE_NEW | |
11441 | && !structured_block | |
11442 | && TREE_CODE (orig_lhs) == COMPOUND_EXPR) | |
11443 | code = OMP_ATOMIC_CAPTURE_OLD; | |
11444 | break; | |
11445 | } | |
11446 | if (TREE_CODE (TREE_OPERAND (lhs, 1)) == TRUTH_NOT_EXPR | |
11447 | && TREE_OPERAND (lhs, 0) | |
11448 | == TREE_OPERAND (TREE_OPERAND (lhs, 1), 0)) | |
11449 | { | |
11450 | /* This is pre or post decrement. */ | |
11451 | rhs = TREE_OPERAND (lhs, 1); | |
11452 | lhs = TREE_OPERAND (lhs, 0); | |
11453 | unfolded_lhs = NULL_TREE; | |
11454 | opcode = NOP_EXPR; | |
11455 | if (code == OMP_ATOMIC_CAPTURE_NEW | |
11456 | && !structured_block | |
11457 | && TREE_CODE (orig_lhs) == COMPOUND_EXPR) | |
11458 | code = OMP_ATOMIC_CAPTURE_OLD; | |
11459 | break; | |
11460 | } | |
11461 | } | |
11462 | /* FALLTHRU */ | |
11463 | default: | |
11464 | switch (c_parser_peek_token (parser)->type) | |
11465 | { | |
11466 | case CPP_MULT_EQ: | |
11467 | opcode = MULT_EXPR; | |
11468 | break; | |
11469 | case CPP_DIV_EQ: | |
11470 | opcode = TRUNC_DIV_EXPR; | |
11471 | break; | |
11472 | case CPP_PLUS_EQ: | |
11473 | opcode = PLUS_EXPR; | |
11474 | break; | |
11475 | case CPP_MINUS_EQ: | |
11476 | opcode = MINUS_EXPR; | |
11477 | break; | |
11478 | case CPP_LSHIFT_EQ: | |
11479 | opcode = LSHIFT_EXPR; | |
11480 | break; | |
11481 | case CPP_RSHIFT_EQ: | |
11482 | opcode = RSHIFT_EXPR; | |
11483 | break; | |
11484 | case CPP_AND_EQ: | |
11485 | opcode = BIT_AND_EXPR; | |
11486 | break; | |
11487 | case CPP_OR_EQ: | |
11488 | opcode = BIT_IOR_EXPR; | |
11489 | break; | |
11490 | case CPP_XOR_EQ: | |
11491 | opcode = BIT_XOR_EXPR; | |
11492 | break; | |
11493 | case CPP_EQ: | |
11494 | c_parser_consume_token (parser); | |
11495 | eloc = c_parser_peek_token (parser)->location; | |
11496 | expr = c_parser_expr_no_commas (parser, NULL, unfolded_lhs); | |
11497 | rhs1 = expr.value; | |
11498 | switch (TREE_CODE (rhs1)) | |
11499 | { | |
11500 | case MULT_EXPR: | |
11501 | case TRUNC_DIV_EXPR: | |
11502 | case PLUS_EXPR: | |
11503 | case MINUS_EXPR: | |
11504 | case LSHIFT_EXPR: | |
11505 | case RSHIFT_EXPR: | |
11506 | case BIT_AND_EXPR: | |
11507 | case BIT_IOR_EXPR: | |
11508 | case BIT_XOR_EXPR: | |
11509 | if (c_tree_equal (TREE_OPERAND (rhs1, 0), unfolded_lhs)) | |
11510 | { | |
11511 | opcode = TREE_CODE (rhs1); | |
11512 | rhs = c_fully_fold (TREE_OPERAND (rhs1, 1), false, NULL); | |
11513 | rhs1 = c_fully_fold (TREE_OPERAND (rhs1, 0), false, NULL); | |
11514 | goto stmt_done; | |
11515 | } | |
11516 | if (c_tree_equal (TREE_OPERAND (rhs1, 1), unfolded_lhs)) | |
11517 | { | |
11518 | opcode = TREE_CODE (rhs1); | |
11519 | rhs = c_fully_fold (TREE_OPERAND (rhs1, 0), false, NULL); | |
11520 | rhs1 = c_fully_fold (TREE_OPERAND (rhs1, 1), false, NULL); | |
11521 | swapped = !commutative_tree_code (opcode); | |
11522 | goto stmt_done; | |
11523 | } | |
11524 | break; | |
11525 | case ERROR_MARK: | |
11526 | goto saw_error; | |
11527 | default: | |
11528 | break; | |
11529 | } | |
11530 | if (c_parser_peek_token (parser)->type == CPP_SEMICOLON) | |
11531 | { | |
11532 | if (structured_block && code == OMP_ATOMIC_CAPTURE_NEW) | |
11533 | { | |
11534 | code = OMP_ATOMIC_CAPTURE_OLD; | |
11535 | v = lhs; | |
11536 | lhs = NULL_TREE; | |
11537 | expr = default_function_array_read_conversion (eloc, expr); | |
11538 | unfolded_lhs1 = expr.value; | |
11539 | lhs1 = c_fully_fold (unfolded_lhs1, false, NULL); | |
11540 | rhs1 = NULL_TREE; | |
11541 | c_parser_consume_token (parser); | |
11542 | goto restart; | |
11543 | } | |
11544 | if (structured_block) | |
11545 | { | |
11546 | opcode = NOP_EXPR; | |
11547 | expr = default_function_array_read_conversion (eloc, expr); | |
11548 | rhs = c_fully_fold (expr.value, false, NULL); | |
11549 | rhs1 = NULL_TREE; | |
11550 | goto stmt_done; | |
11551 | } | |
11552 | } | |
11553 | c_parser_error (parser, "invalid form of %<#pragma omp atomic%>"); | |
11554 | goto saw_error; | |
11555 | default: | |
11556 | c_parser_error (parser, | |
11557 | "invalid operator for %<#pragma omp atomic%>"); | |
11558 | goto saw_error; | |
11559 | } | |
11560 | ||
11561 | /* Arrange to pass the location of the assignment operator to | |
11562 | c_finish_omp_atomic. */ | |
11563 | loc = c_parser_peek_token (parser)->location; | |
11564 | c_parser_consume_token (parser); | |
11565 | eloc = c_parser_peek_token (parser)->location; | |
11566 | expr = c_parser_expression (parser); | |
11567 | expr = default_function_array_read_conversion (eloc, expr); | |
11568 | rhs = expr.value; | |
11569 | rhs = c_fully_fold (rhs, false, NULL); | |
11570 | break; | |
11571 | } | |
11572 | stmt_done: | |
11573 | if (structured_block && code == OMP_ATOMIC_CAPTURE_NEW) | |
11574 | { | |
11575 | if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>")) | |
11576 | goto saw_error; | |
11577 | v = c_parser_unary_expression (parser).value; | |
11578 | v = c_fully_fold (v, false, NULL); | |
11579 | if (v == error_mark_node) | |
11580 | goto saw_error; | |
11581 | if (!c_parser_require (parser, CPP_EQ, "expected %<=%>")) | |
11582 | goto saw_error; | |
11583 | eloc = c_parser_peek_token (parser)->location; | |
11584 | expr = c_parser_unary_expression (parser); | |
11585 | lhs1 = expr.value; | |
11586 | expr = default_function_array_read_conversion (eloc, expr); | |
11587 | unfolded_lhs1 = expr.value; | |
11588 | lhs1 = c_fully_fold (lhs1, false, NULL); | |
11589 | if (lhs1 == error_mark_node) | |
11590 | goto saw_error; | |
11591 | } | |
11592 | if (structured_block) | |
11593 | { | |
11594 | c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); | |
11595 | c_parser_require (parser, CPP_CLOSE_BRACE, "expected %<}%>"); | |
11596 | } | |
11597 | done: | |
11598 | if (unfolded_lhs && unfolded_lhs1 | |
11599 | && !c_tree_equal (unfolded_lhs, unfolded_lhs1)) | |
11600 | { | |
11601 | error ("%<#pragma omp atomic capture%> uses two different " | |
11602 | "expressions for memory"); | |
11603 | stmt = error_mark_node; | |
11604 | } | |
11605 | else | |
11606 | stmt = c_finish_omp_atomic (loc, code, opcode, lhs, rhs, v, lhs1, rhs1, | |
11607 | swapped, seq_cst); | |
11608 | if (stmt != error_mark_node) | |
11609 | add_stmt (stmt); | |
11610 | ||
11611 | if (!structured_block) | |
11612 | c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); | |
11613 | } | |
11614 | ||
11615 | ||
11616 | /* OpenMP 2.5: | |
11617 | # pragma omp barrier new-line | |
11618 | */ | |
11619 | ||
11620 | static void | |
11621 | c_parser_omp_barrier (c_parser *parser) | |
11622 | { | |
11623 | location_t loc = c_parser_peek_token (parser)->location; | |
11624 | c_parser_consume_pragma (parser); | |
11625 | c_parser_skip_to_pragma_eol (parser); | |
11626 | ||
11627 | c_finish_omp_barrier (loc); | |
11628 | } | |
11629 | ||
11630 | /* OpenMP 2.5: | |
11631 | # pragma omp critical [(name)] new-line | |
11632 | structured-block | |
11633 | ||
11634 | LOC is the location of the #pragma itself. */ | |
11635 | ||
11636 | static tree | |
11637 | c_parser_omp_critical (location_t loc, c_parser *parser) | |
11638 | { | |
11639 | tree stmt, name = NULL; | |
11640 | ||
11641 | if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) | |
11642 | { | |
11643 | c_parser_consume_token (parser); | |
11644 | if (c_parser_next_token_is (parser, CPP_NAME)) | |
11645 | { | |
11646 | name = c_parser_peek_token (parser)->value; | |
11647 | c_parser_consume_token (parser); | |
11648 | c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
11649 | } | |
11650 | else | |
11651 | c_parser_error (parser, "expected identifier"); | |
11652 | } | |
11653 | else if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL)) | |
11654 | c_parser_error (parser, "expected %<(%> or end of line"); | |
11655 | c_parser_skip_to_pragma_eol (parser); | |
11656 | ||
11657 | stmt = c_parser_omp_structured_block (parser); | |
11658 | return c_finish_omp_critical (loc, stmt, name); | |
11659 | } | |
11660 | ||
11661 | /* OpenMP 2.5: | |
11662 | # pragma omp flush flush-vars[opt] new-line | |
11663 | ||
11664 | flush-vars: | |
11665 | ( variable-list ) */ | |
11666 | ||
11667 | static void | |
11668 | c_parser_omp_flush (c_parser *parser) | |
11669 | { | |
11670 | location_t loc = c_parser_peek_token (parser)->location; | |
11671 | c_parser_consume_pragma (parser); | |
11672 | if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) | |
11673 | c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL); | |
11674 | else if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL)) | |
11675 | c_parser_error (parser, "expected %<(%> or end of line"); | |
11676 | c_parser_skip_to_pragma_eol (parser); | |
11677 | ||
11678 | c_finish_omp_flush (loc); | |
11679 | } | |
11680 | ||
11681 | /* Parse the restricted form of the for statement allowed by OpenMP. | |
11682 | The real trick here is to determine the loop control variable early | |
11683 | so that we can push a new decl if necessary to make it private. | |
11684 | LOC is the location of the OMP in "#pragma omp". */ | |
11685 | ||
11686 | static tree | |
11687 | c_parser_omp_for_loop (location_t loc, c_parser *parser, enum tree_code code, | |
11688 | tree clauses, tree *cclauses) | |
11689 | { | |
11690 | tree decl, cond, incr, save_break, save_cont, body, init, stmt, cl; | |
11691 | tree declv, condv, incrv, initv, ret = NULL; | |
11692 | bool fail = false, open_brace_parsed = false; | |
11693 | int i, collapse = 1, nbraces = 0; | |
11694 | location_t for_loc; | |
11695 | vec<tree, va_gc> *for_block = make_tree_vector (); | |
11696 | ||
11697 | for (cl = clauses; cl; cl = OMP_CLAUSE_CHAIN (cl)) | |
11698 | if (OMP_CLAUSE_CODE (cl) == OMP_CLAUSE_COLLAPSE) | |
9439e9a1 | 11699 | collapse = tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (cl)); |
acf0174b JJ |
11700 | |
11701 | gcc_assert (collapse >= 1); | |
11702 | ||
11703 | declv = make_tree_vec (collapse); | |
11704 | initv = make_tree_vec (collapse); | |
11705 | condv = make_tree_vec (collapse); | |
11706 | incrv = make_tree_vec (collapse); | |
11707 | ||
11708 | if (!c_parser_next_token_is_keyword (parser, RID_FOR)) | |
11709 | { | |
11710 | c_parser_error (parser, "for statement expected"); | |
11711 | return NULL; | |
11712 | } | |
11713 | for_loc = c_parser_peek_token (parser)->location; | |
11714 | c_parser_consume_token (parser); | |
11715 | ||
11716 | for (i = 0; i < collapse; i++) | |
11717 | { | |
11718 | int bracecount = 0; | |
11719 | ||
11720 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
11721 | goto pop_scopes; | |
11722 | ||
11723 | /* Parse the initialization declaration or expression. */ | |
11724 | if (c_parser_next_tokens_start_declaration (parser)) | |
11725 | { | |
11726 | if (i > 0) | |
11727 | vec_safe_push (for_block, c_begin_compound_stmt (true)); | |
11728 | c_parser_declaration_or_fndef (parser, true, true, true, true, true, | |
11729 | NULL, vNULL); | |
11730 | decl = check_for_loop_decls (for_loc, flag_isoc99); | |
11731 | if (decl == NULL) | |
11732 | goto error_init; | |
11733 | if (DECL_INITIAL (decl) == error_mark_node) | |
11734 | decl = error_mark_node; | |
11735 | init = decl; | |
11736 | } | |
11737 | else if (c_parser_next_token_is (parser, CPP_NAME) | |
11738 | && c_parser_peek_2nd_token (parser)->type == CPP_EQ) | |
11739 | { | |
11740 | struct c_expr decl_exp; | |
11741 | struct c_expr init_exp; | |
11742 | location_t init_loc; | |
11743 | ||
11744 | decl_exp = c_parser_postfix_expression (parser); | |
11745 | decl = decl_exp.value; | |
11746 | ||
11747 | c_parser_require (parser, CPP_EQ, "expected %<=%>"); | |
11748 | ||
11749 | init_loc = c_parser_peek_token (parser)->location; | |
11750 | init_exp = c_parser_expr_no_commas (parser, NULL); | |
11751 | init_exp = default_function_array_read_conversion (init_loc, | |
11752 | init_exp); | |
11753 | init = build_modify_expr (init_loc, decl, decl_exp.original_type, | |
11754 | NOP_EXPR, init_loc, init_exp.value, | |
11755 | init_exp.original_type); | |
11756 | init = c_process_expr_stmt (init_loc, init); | |
11757 | ||
11758 | c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); | |
11759 | } | |
11760 | else | |
11761 | { | |
11762 | error_init: | |
11763 | c_parser_error (parser, | |
11764 | "expected iteration declaration or initialization"); | |
11765 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, | |
11766 | "expected %<)%>"); | |
11767 | fail = true; | |
11768 | goto parse_next; | |
11769 | } | |
11770 | ||
11771 | /* Parse the loop condition. */ | |
11772 | cond = NULL_TREE; | |
11773 | if (c_parser_next_token_is_not (parser, CPP_SEMICOLON)) | |
11774 | { | |
11775 | location_t cond_loc = c_parser_peek_token (parser)->location; | |
11776 | struct c_expr cond_expr | |
11777 | = c_parser_binary_expression (parser, NULL, NULL_TREE); | |
11778 | ||
11779 | cond = cond_expr.value; | |
11780 | cond = c_objc_common_truthvalue_conversion (cond_loc, cond); | |
11781 | cond = c_fully_fold (cond, false, NULL); | |
11782 | switch (cond_expr.original_code) | |
11783 | { | |
11784 | case GT_EXPR: | |
11785 | case GE_EXPR: | |
11786 | case LT_EXPR: | |
11787 | case LE_EXPR: | |
11788 | break; | |
c02065fc AH |
11789 | case NE_EXPR: |
11790 | if (code == CILK_SIMD) | |
11791 | break; | |
11792 | /* FALLTHRU. */ | |
acf0174b JJ |
11793 | default: |
11794 | /* Can't be cond = error_mark_node, because we want to preserve | |
11795 | the location until c_finish_omp_for. */ | |
11796 | cond = build1 (NOP_EXPR, boolean_type_node, error_mark_node); | |
11797 | break; | |
11798 | } | |
11799 | protected_set_expr_location (cond, cond_loc); | |
11800 | } | |
11801 | c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); | |
11802 | ||
11803 | /* Parse the increment expression. */ | |
11804 | incr = NULL_TREE; | |
11805 | if (c_parser_next_token_is_not (parser, CPP_CLOSE_PAREN)) | |
11806 | { | |
11807 | location_t incr_loc = c_parser_peek_token (parser)->location; | |
11808 | ||
11809 | incr = c_process_expr_stmt (incr_loc, | |
11810 | c_parser_expression (parser).value); | |
11811 | } | |
11812 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
11813 | ||
11814 | if (decl == NULL || decl == error_mark_node || init == error_mark_node) | |
11815 | fail = true; | |
11816 | else | |
11817 | { | |
11818 | TREE_VEC_ELT (declv, i) = decl; | |
11819 | TREE_VEC_ELT (initv, i) = init; | |
11820 | TREE_VEC_ELT (condv, i) = cond; | |
11821 | TREE_VEC_ELT (incrv, i) = incr; | |
11822 | } | |
11823 | ||
11824 | parse_next: | |
11825 | if (i == collapse - 1) | |
11826 | break; | |
11827 | ||
11828 | /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed | |
11829 | in between the collapsed for loops to be still considered perfectly | |
11830 | nested. Hopefully the final version clarifies this. | |
11831 | For now handle (multiple) {'s and empty statements. */ | |
11832 | do | |
11833 | { | |
11834 | if (c_parser_next_token_is_keyword (parser, RID_FOR)) | |
11835 | { | |
11836 | c_parser_consume_token (parser); | |
11837 | break; | |
11838 | } | |
11839 | else if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) | |
11840 | { | |
11841 | c_parser_consume_token (parser); | |
11842 | bracecount++; | |
11843 | } | |
11844 | else if (bracecount | |
11845 | && c_parser_next_token_is (parser, CPP_SEMICOLON)) | |
11846 | c_parser_consume_token (parser); | |
11847 | else | |
11848 | { | |
11849 | c_parser_error (parser, "not enough perfectly nested loops"); | |
11850 | if (bracecount) | |
11851 | { | |
11852 | open_brace_parsed = true; | |
11853 | bracecount--; | |
11854 | } | |
11855 | fail = true; | |
11856 | collapse = 0; | |
11857 | break; | |
11858 | } | |
11859 | } | |
11860 | while (1); | |
11861 | ||
11862 | nbraces += bracecount; | |
11863 | } | |
11864 | ||
11865 | save_break = c_break_label; | |
c02065fc AH |
11866 | if (code == CILK_SIMD) |
11867 | c_break_label = build_int_cst (size_type_node, 2); | |
11868 | else | |
11869 | c_break_label = size_one_node; | |
acf0174b JJ |
11870 | save_cont = c_cont_label; |
11871 | c_cont_label = NULL_TREE; | |
11872 | body = push_stmt_list (); | |
11873 | ||
11874 | if (open_brace_parsed) | |
11875 | { | |
11876 | location_t here = c_parser_peek_token (parser)->location; | |
11877 | stmt = c_begin_compound_stmt (true); | |
11878 | c_parser_compound_statement_nostart (parser); | |
11879 | add_stmt (c_end_compound_stmt (here, stmt, true)); | |
11880 | } | |
11881 | else | |
11882 | add_stmt (c_parser_c99_block_statement (parser)); | |
11883 | if (c_cont_label) | |
11884 | { | |
11885 | tree t = build1 (LABEL_EXPR, void_type_node, c_cont_label); | |
11886 | SET_EXPR_LOCATION (t, loc); | |
11887 | add_stmt (t); | |
11888 | } | |
11889 | ||
11890 | body = pop_stmt_list (body); | |
11891 | c_break_label = save_break; | |
11892 | c_cont_label = save_cont; | |
11893 | ||
11894 | while (nbraces) | |
11895 | { | |
11896 | if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) | |
11897 | { | |
11898 | c_parser_consume_token (parser); | |
11899 | nbraces--; | |
11900 | } | |
11901 | else if (c_parser_next_token_is (parser, CPP_SEMICOLON)) | |
11902 | c_parser_consume_token (parser); | |
11903 | else | |
11904 | { | |
11905 | c_parser_error (parser, "collapsed loops not perfectly nested"); | |
11906 | while (nbraces) | |
11907 | { | |
11908 | location_t here = c_parser_peek_token (parser)->location; | |
11909 | stmt = c_begin_compound_stmt (true); | |
11910 | add_stmt (body); | |
11911 | c_parser_compound_statement_nostart (parser); | |
11912 | body = c_end_compound_stmt (here, stmt, true); | |
11913 | nbraces--; | |
11914 | } | |
11915 | goto pop_scopes; | |
11916 | } | |
11917 | } | |
11918 | ||
11919 | /* Only bother calling c_finish_omp_for if we haven't already generated | |
11920 | an error from the initialization parsing. */ | |
11921 | if (!fail) | |
11922 | { | |
11923 | stmt = c_finish_omp_for (loc, code, declv, initv, condv, | |
11924 | incrv, body, NULL); | |
11925 | if (stmt) | |
11926 | { | |
11927 | if (cclauses != NULL | |
11928 | && cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL] != NULL) | |
11929 | { | |
11930 | tree *c; | |
11931 | for (c = &cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL]; *c ; ) | |
11932 | if (OMP_CLAUSE_CODE (*c) != OMP_CLAUSE_FIRSTPRIVATE | |
11933 | && OMP_CLAUSE_CODE (*c) != OMP_CLAUSE_LASTPRIVATE) | |
11934 | c = &OMP_CLAUSE_CHAIN (*c); | |
11935 | else | |
11936 | { | |
11937 | for (i = 0; i < collapse; i++) | |
11938 | if (TREE_VEC_ELT (declv, i) == OMP_CLAUSE_DECL (*c)) | |
11939 | break; | |
11940 | if (i == collapse) | |
11941 | c = &OMP_CLAUSE_CHAIN (*c); | |
11942 | else if (OMP_CLAUSE_CODE (*c) == OMP_CLAUSE_FIRSTPRIVATE) | |
11943 | { | |
11944 | error_at (loc, | |
11945 | "iteration variable %qD should not be firstprivate", | |
11946 | OMP_CLAUSE_DECL (*c)); | |
11947 | *c = OMP_CLAUSE_CHAIN (*c); | |
11948 | } | |
11949 | else | |
11950 | { | |
11951 | /* Copy lastprivate (decl) clause to OMP_FOR_CLAUSES, | |
11952 | change it to shared (decl) in | |
11953 | OMP_PARALLEL_CLAUSES. */ | |
11954 | tree l = build_omp_clause (OMP_CLAUSE_LOCATION (*c), | |
11955 | OMP_CLAUSE_LASTPRIVATE); | |
11956 | OMP_CLAUSE_DECL (l) = OMP_CLAUSE_DECL (*c); | |
56ad0e38 JJ |
11957 | if (code == OMP_SIMD) |
11958 | { | |
11959 | OMP_CLAUSE_CHAIN (l) | |
11960 | = cclauses[C_OMP_CLAUSE_SPLIT_FOR]; | |
11961 | cclauses[C_OMP_CLAUSE_SPLIT_FOR] = l; | |
11962 | } | |
11963 | else | |
11964 | { | |
11965 | OMP_CLAUSE_CHAIN (l) = clauses; | |
11966 | clauses = l; | |
11967 | } | |
acf0174b JJ |
11968 | OMP_CLAUSE_SET_CODE (*c, OMP_CLAUSE_SHARED); |
11969 | } | |
11970 | } | |
11971 | } | |
11972 | OMP_FOR_CLAUSES (stmt) = clauses; | |
11973 | } | |
11974 | ret = stmt; | |
11975 | } | |
11976 | pop_scopes: | |
11977 | while (!for_block->is_empty ()) | |
11978 | { | |
11979 | /* FIXME diagnostics: LOC below should be the actual location of | |
11980 | this particular for block. We need to build a list of | |
11981 | locations to go along with FOR_BLOCK. */ | |
11982 | stmt = c_end_compound_stmt (loc, for_block->pop (), true); | |
11983 | add_stmt (stmt); | |
11984 | } | |
11985 | release_tree_vector (for_block); | |
11986 | return ret; | |
11987 | } | |
11988 | ||
11989 | /* Helper function for OpenMP parsing, split clauses and call | |
11990 | finish_omp_clauses on each of the set of clauses afterwards. */ | |
11991 | ||
11992 | static void | |
11993 | omp_split_clauses (location_t loc, enum tree_code code, | |
11994 | omp_clause_mask mask, tree clauses, tree *cclauses) | |
11995 | { | |
11996 | int i; | |
11997 | c_omp_split_clauses (loc, code, mask, clauses, cclauses); | |
11998 | for (i = 0; i < C_OMP_CLAUSE_SPLIT_COUNT; i++) | |
11999 | if (cclauses[i]) | |
12000 | cclauses[i] = c_finish_omp_clauses (cclauses[i]); | |
12001 | } | |
12002 | ||
12003 | /* OpenMP 4.0: | |
12004 | #pragma omp simd simd-clause[optseq] new-line | |
12005 | for-loop | |
12006 | ||
12007 | LOC is the location of the #pragma token. | |
12008 | */ | |
12009 | ||
12010 | #define OMP_SIMD_CLAUSE_MASK \ | |
12011 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SAFELEN) \ | |
12012 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \ | |
12013 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \ | |
12014 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \ | |
12015 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \ | |
12016 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \ | |
12017 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE)) | |
12018 | ||
12019 | static tree | |
12020 | c_parser_omp_simd (location_t loc, c_parser *parser, | |
12021 | char *p_name, omp_clause_mask mask, tree *cclauses) | |
12022 | { | |
12023 | tree block, clauses, ret; | |
12024 | ||
12025 | strcat (p_name, " simd"); | |
12026 | mask |= OMP_SIMD_CLAUSE_MASK; | |
12027 | mask &= ~(OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ORDERED); | |
12028 | ||
12029 | clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL); | |
12030 | if (cclauses) | |
12031 | { | |
12032 | omp_split_clauses (loc, OMP_SIMD, mask, clauses, cclauses); | |
12033 | clauses = cclauses[C_OMP_CLAUSE_SPLIT_SIMD]; | |
12034 | } | |
12035 | ||
12036 | block = c_begin_compound_stmt (true); | |
12037 | ret = c_parser_omp_for_loop (loc, parser, OMP_SIMD, clauses, cclauses); | |
12038 | block = c_end_compound_stmt (loc, block, true); | |
12039 | add_stmt (block); | |
12040 | ||
12041 | return ret; | |
12042 | } | |
12043 | ||
12044 | /* OpenMP 2.5: | |
12045 | #pragma omp for for-clause[optseq] new-line | |
12046 | for-loop | |
12047 | ||
12048 | OpenMP 4.0: | |
12049 | #pragma omp for simd for-simd-clause[optseq] new-line | |
12050 | for-loop | |
12051 | ||
12052 | LOC is the location of the #pragma token. | |
12053 | */ | |
12054 | ||
12055 | #define OMP_FOR_CLAUSE_MASK \ | |
12056 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \ | |
12057 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \ | |
12058 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \ | |
12059 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \ | |
12060 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ORDERED) \ | |
12061 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SCHEDULE) \ | |
12062 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE) \ | |
12063 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT)) | |
12064 | ||
12065 | static tree | |
12066 | c_parser_omp_for (location_t loc, c_parser *parser, | |
12067 | char *p_name, omp_clause_mask mask, tree *cclauses) | |
12068 | { | |
12069 | tree block, clauses, ret; | |
12070 | ||
12071 | strcat (p_name, " for"); | |
12072 | mask |= OMP_FOR_CLAUSE_MASK; | |
12073 | if (cclauses) | |
12074 | mask &= ~(OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT); | |
12075 | ||
12076 | if (c_parser_next_token_is (parser, CPP_NAME)) | |
20906c66 | 12077 | { |
acf0174b JJ |
12078 | const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
12079 | ||
12080 | if (strcmp (p, "simd") == 0) | |
12081 | { | |
12082 | tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT]; | |
12083 | if (cclauses == NULL) | |
12084 | cclauses = cclauses_buf; | |
12085 | ||
12086 | c_parser_consume_token (parser); | |
6d7f7e0a TB |
12087 | if (!flag_openmp) /* flag_openmp_simd */ |
12088 | return c_parser_omp_simd (loc, parser, p_name, mask, cclauses); | |
acf0174b JJ |
12089 | block = c_begin_compound_stmt (true); |
12090 | ret = c_parser_omp_simd (loc, parser, p_name, mask, cclauses); | |
12091 | block = c_end_compound_stmt (loc, block, true); | |
12092 | if (ret == NULL_TREE) | |
12093 | return ret; | |
12094 | ret = make_node (OMP_FOR); | |
12095 | TREE_TYPE (ret) = void_type_node; | |
12096 | OMP_FOR_BODY (ret) = block; | |
12097 | OMP_FOR_CLAUSES (ret) = cclauses[C_OMP_CLAUSE_SPLIT_FOR]; | |
12098 | SET_EXPR_LOCATION (ret, loc); | |
12099 | add_stmt (ret); | |
12100 | return ret; | |
12101 | } | |
20906c66 | 12102 | } |
6d7f7e0a TB |
12103 | if (!flag_openmp) /* flag_openmp_simd */ |
12104 | { | |
12105 | c_parser_skip_to_pragma_eol (parser); | |
12106 | return NULL_TREE; | |
12107 | } | |
acf0174b JJ |
12108 | |
12109 | clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL); | |
12110 | if (cclauses) | |
20906c66 | 12111 | { |
acf0174b JJ |
12112 | omp_split_clauses (loc, OMP_FOR, mask, clauses, cclauses); |
12113 | clauses = cclauses[C_OMP_CLAUSE_SPLIT_FOR]; | |
20906c66 | 12114 | } |
20906c66 | 12115 | |
acf0174b JJ |
12116 | block = c_begin_compound_stmt (true); |
12117 | ret = c_parser_omp_for_loop (loc, parser, OMP_FOR, clauses, cclauses); | |
12118 | block = c_end_compound_stmt (loc, block, true); | |
12119 | add_stmt (block); | |
12120 | ||
12121 | return ret; | |
953ff289 DN |
12122 | } |
12123 | ||
acf0174b JJ |
12124 | /* OpenMP 2.5: |
12125 | # pragma omp master new-line | |
12126 | structured-block | |
12127 | ||
12128 | LOC is the location of the #pragma token. | |
12129 | */ | |
12130 | ||
12131 | static tree | |
12132 | c_parser_omp_master (location_t loc, c_parser *parser) | |
12133 | { | |
12134 | c_parser_skip_to_pragma_eol (parser); | |
12135 | return c_finish_omp_master (loc, c_parser_omp_structured_block (parser)); | |
12136 | } | |
953ff289 DN |
12137 | |
12138 | /* OpenMP 2.5: | |
acf0174b JJ |
12139 | # pragma omp ordered new-line |
12140 | structured-block | |
12141 | ||
12142 | LOC is the location of the #pragma itself. | |
953ff289 DN |
12143 | */ |
12144 | ||
acf0174b JJ |
12145 | static tree |
12146 | c_parser_omp_ordered (location_t loc, c_parser *parser) | |
953ff289 | 12147 | { |
953ff289 | 12148 | c_parser_skip_to_pragma_eol (parser); |
acf0174b JJ |
12149 | return c_finish_omp_ordered (loc, c_parser_omp_structured_block (parser)); |
12150 | } | |
953ff289 | 12151 | |
acf0174b JJ |
12152 | /* OpenMP 2.5: |
12153 | ||
12154 | section-scope: | |
12155 | { section-sequence } | |
12156 | ||
12157 | section-sequence: | |
12158 | section-directive[opt] structured-block | |
12159 | section-sequence section-directive structured-block | |
12160 | ||
12161 | SECTIONS_LOC is the location of the #pragma omp sections. */ | |
12162 | ||
12163 | static tree | |
12164 | c_parser_omp_sections_scope (location_t sections_loc, c_parser *parser) | |
12165 | { | |
12166 | tree stmt, substmt; | |
12167 | bool error_suppress = false; | |
12168 | location_t loc; | |
12169 | ||
12170 | loc = c_parser_peek_token (parser)->location; | |
12171 | if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>")) | |
12172 | { | |
12173 | /* Avoid skipping until the end of the block. */ | |
12174 | parser->error = false; | |
12175 | return NULL_TREE; | |
12176 | } | |
12177 | ||
12178 | stmt = push_stmt_list (); | |
12179 | ||
12180 | if (c_parser_peek_token (parser)->pragma_kind != PRAGMA_OMP_SECTION) | |
12181 | { | |
12182 | substmt = c_parser_omp_structured_block (parser); | |
12183 | substmt = build1 (OMP_SECTION, void_type_node, substmt); | |
12184 | SET_EXPR_LOCATION (substmt, loc); | |
12185 | add_stmt (substmt); | |
12186 | } | |
12187 | ||
12188 | while (1) | |
12189 | { | |
12190 | if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) | |
12191 | break; | |
12192 | if (c_parser_next_token_is (parser, CPP_EOF)) | |
12193 | break; | |
12194 | ||
12195 | loc = c_parser_peek_token (parser)->location; | |
12196 | if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_OMP_SECTION) | |
12197 | { | |
12198 | c_parser_consume_pragma (parser); | |
12199 | c_parser_skip_to_pragma_eol (parser); | |
12200 | error_suppress = false; | |
12201 | } | |
12202 | else if (!error_suppress) | |
12203 | { | |
12204 | error_at (loc, "expected %<#pragma omp section%> or %<}%>"); | |
12205 | error_suppress = true; | |
12206 | } | |
12207 | ||
12208 | substmt = c_parser_omp_structured_block (parser); | |
12209 | substmt = build1 (OMP_SECTION, void_type_node, substmt); | |
12210 | SET_EXPR_LOCATION (substmt, loc); | |
12211 | add_stmt (substmt); | |
12212 | } | |
12213 | c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, | |
12214 | "expected %<#pragma omp section%> or %<}%>"); | |
12215 | ||
12216 | substmt = pop_stmt_list (stmt); | |
12217 | ||
12218 | stmt = make_node (OMP_SECTIONS); | |
12219 | SET_EXPR_LOCATION (stmt, sections_loc); | |
12220 | TREE_TYPE (stmt) = void_type_node; | |
12221 | OMP_SECTIONS_BODY (stmt) = substmt; | |
12222 | ||
12223 | return add_stmt (stmt); | |
953ff289 DN |
12224 | } |
12225 | ||
12226 | /* OpenMP 2.5: | |
acf0174b JJ |
12227 | # pragma omp sections sections-clause[optseq] newline |
12228 | sections-scope | |
c2255bc4 | 12229 | |
acf0174b JJ |
12230 | LOC is the location of the #pragma token. |
12231 | */ | |
12232 | ||
12233 | #define OMP_SECTIONS_CLAUSE_MASK \ | |
12234 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \ | |
12235 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \ | |
12236 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \ | |
12237 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \ | |
12238 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT)) | |
953ff289 DN |
12239 | |
12240 | static tree | |
acf0174b JJ |
12241 | c_parser_omp_sections (location_t loc, c_parser *parser, |
12242 | char *p_name, omp_clause_mask mask, tree *cclauses) | |
953ff289 | 12243 | { |
acf0174b | 12244 | tree block, clauses, ret; |
953ff289 | 12245 | |
acf0174b JJ |
12246 | strcat (p_name, " sections"); |
12247 | mask |= OMP_SECTIONS_CLAUSE_MASK; | |
12248 | if (cclauses) | |
12249 | mask &= ~(OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT); | |
12250 | ||
12251 | clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL); | |
12252 | if (cclauses) | |
12253 | { | |
12254 | omp_split_clauses (loc, OMP_SECTIONS, mask, clauses, cclauses); | |
12255 | clauses = cclauses[C_OMP_CLAUSE_SPLIT_SECTIONS]; | |
12256 | } | |
12257 | ||
12258 | block = c_begin_compound_stmt (true); | |
12259 | ret = c_parser_omp_sections_scope (loc, parser); | |
12260 | if (ret) | |
12261 | OMP_SECTIONS_CLAUSES (ret) = clauses; | |
12262 | block = c_end_compound_stmt (loc, block, true); | |
12263 | add_stmt (block); | |
12264 | ||
12265 | return ret; | |
12266 | } | |
12267 | ||
12268 | /* OpenMP 2.5: | |
cef0fd0e TS |
12269 | # pragma omp parallel parallel-clause[optseq] new-line |
12270 | structured-block | |
12271 | # pragma omp parallel for parallel-for-clause[optseq] new-line | |
12272 | structured-block | |
12273 | # pragma omp parallel sections parallel-sections-clause[optseq] new-line | |
12274 | structured-block | |
12275 | ||
12276 | OpenMP 4.0: | |
12277 | # pragma omp parallel for simd parallel-for-simd-clause[optseq] new-line | |
12278 | structured-block | |
acf0174b JJ |
12279 | |
12280 | LOC is the location of the #pragma token. | |
12281 | */ | |
12282 | ||
12283 | #define OMP_PARALLEL_CLAUSE_MASK \ | |
12284 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \ | |
12285 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \ | |
12286 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \ | |
12287 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \ | |
12288 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \ | |
12289 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYIN) \ | |
12290 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \ | |
12291 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_THREADS) \ | |
12292 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PROC_BIND)) | |
12293 | ||
12294 | static tree | |
12295 | c_parser_omp_parallel (location_t loc, c_parser *parser, | |
12296 | char *p_name, omp_clause_mask mask, tree *cclauses) | |
12297 | { | |
12298 | tree stmt, clauses, block; | |
12299 | ||
12300 | strcat (p_name, " parallel"); | |
12301 | mask |= OMP_PARALLEL_CLAUSE_MASK; | |
12302 | ||
12303 | if (c_parser_next_token_is_keyword (parser, RID_FOR)) | |
953ff289 | 12304 | { |
acf0174b JJ |
12305 | tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT]; |
12306 | if (cclauses == NULL) | |
12307 | cclauses = cclauses_buf; | |
12308 | ||
953ff289 | 12309 | c_parser_consume_token (parser); |
6d7f7e0a TB |
12310 | if (!flag_openmp) /* flag_openmp_simd */ |
12311 | return c_parser_omp_for (loc, parser, p_name, mask, cclauses); | |
acf0174b | 12312 | block = c_begin_omp_parallel (); |
e162a134 | 12313 | tree ret = c_parser_omp_for (loc, parser, p_name, mask, cclauses); |
acf0174b JJ |
12314 | stmt |
12315 | = c_finish_omp_parallel (loc, cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL], | |
12316 | block); | |
e162a134 JJ |
12317 | if (ret == NULL_TREE) |
12318 | return ret; | |
acf0174b JJ |
12319 | OMP_PARALLEL_COMBINED (stmt) = 1; |
12320 | return stmt; | |
12321 | } | |
12322 | else if (cclauses) | |
12323 | { | |
12324 | error_at (loc, "expected %<for%> after %qs", p_name); | |
12325 | c_parser_skip_to_pragma_eol (parser); | |
12326 | return NULL_TREE; | |
12327 | } | |
6d7f7e0a TB |
12328 | else if (!flag_openmp) /* flag_openmp_simd */ |
12329 | { | |
12330 | c_parser_skip_to_pragma_eol (parser); | |
12331 | return NULL_TREE; | |
12332 | } | |
acf0174b JJ |
12333 | else if (c_parser_next_token_is (parser, CPP_NAME)) |
12334 | { | |
12335 | const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); | |
12336 | if (strcmp (p, "sections") == 0) | |
953ff289 | 12337 | { |
acf0174b JJ |
12338 | tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT]; |
12339 | if (cclauses == NULL) | |
12340 | cclauses = cclauses_buf; | |
12341 | ||
953ff289 | 12342 | c_parser_consume_token (parser); |
acf0174b JJ |
12343 | block = c_begin_omp_parallel (); |
12344 | c_parser_omp_sections (loc, parser, p_name, mask, cclauses); | |
12345 | stmt = c_finish_omp_parallel (loc, | |
12346 | cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL], | |
12347 | block); | |
12348 | OMP_PARALLEL_COMBINED (stmt) = 1; | |
12349 | return stmt; | |
953ff289 | 12350 | } |
953ff289 | 12351 | } |
953ff289 | 12352 | |
acf0174b JJ |
12353 | clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL); |
12354 | ||
12355 | block = c_begin_omp_parallel (); | |
12356 | c_parser_statement (parser); | |
12357 | stmt = c_finish_omp_parallel (loc, clauses, block); | |
12358 | ||
12359 | return stmt; | |
12360 | } | |
12361 | ||
12362 | /* OpenMP 2.5: | |
12363 | # pragma omp single single-clause[optseq] new-line | |
12364 | structured-block | |
12365 | ||
12366 | LOC is the location of the #pragma. | |
12367 | */ | |
12368 | ||
12369 | #define OMP_SINGLE_CLAUSE_MASK \ | |
12370 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \ | |
12371 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \ | |
12372 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \ | |
12373 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT)) | |
12374 | ||
12375 | static tree | |
12376 | c_parser_omp_single (location_t loc, c_parser *parser) | |
12377 | { | |
12378 | tree stmt = make_node (OMP_SINGLE); | |
12379 | SET_EXPR_LOCATION (stmt, loc); | |
12380 | TREE_TYPE (stmt) = void_type_node; | |
12381 | ||
12382 | OMP_SINGLE_CLAUSES (stmt) | |
12383 | = c_parser_omp_all_clauses (parser, OMP_SINGLE_CLAUSE_MASK, | |
12384 | "#pragma omp single"); | |
12385 | OMP_SINGLE_BODY (stmt) = c_parser_omp_structured_block (parser); | |
12386 | ||
12387 | return add_stmt (stmt); | |
12388 | } | |
12389 | ||
12390 | /* OpenMP 3.0: | |
12391 | # pragma omp task task-clause[optseq] new-line | |
12392 | ||
12393 | LOC is the location of the #pragma. | |
12394 | */ | |
12395 | ||
12396 | #define OMP_TASK_CLAUSE_MASK \ | |
12397 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \ | |
12398 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNTIED) \ | |
12399 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \ | |
12400 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \ | |
12401 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \ | |
12402 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \ | |
12403 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FINAL) \ | |
12404 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MERGEABLE) \ | |
12405 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND)) | |
12406 | ||
12407 | static tree | |
12408 | c_parser_omp_task (location_t loc, c_parser *parser) | |
12409 | { | |
12410 | tree clauses, block; | |
12411 | ||
12412 | clauses = c_parser_omp_all_clauses (parser, OMP_TASK_CLAUSE_MASK, | |
12413 | "#pragma omp task"); | |
12414 | ||
12415 | block = c_begin_omp_task (); | |
12416 | c_parser_statement (parser); | |
12417 | return c_finish_omp_task (loc, clauses, block); | |
953ff289 DN |
12418 | } |
12419 | ||
acf0174b JJ |
12420 | /* OpenMP 3.0: |
12421 | # pragma omp taskwait new-line | |
12422 | */ | |
953ff289 DN |
12423 | |
12424 | static void | |
acf0174b | 12425 | c_parser_omp_taskwait (c_parser *parser) |
953ff289 | 12426 | { |
c2255bc4 | 12427 | location_t loc = c_parser_peek_token (parser)->location; |
953ff289 | 12428 | c_parser_consume_pragma (parser); |
953ff289 DN |
12429 | c_parser_skip_to_pragma_eol (parser); |
12430 | ||
acf0174b | 12431 | c_finish_omp_taskwait (loc); |
953ff289 DN |
12432 | } |
12433 | ||
acf0174b JJ |
12434 | /* OpenMP 3.1: |
12435 | # pragma omp taskyield new-line | |
12436 | */ | |
953ff289 | 12437 | |
acf0174b JJ |
12438 | static void |
12439 | c_parser_omp_taskyield (c_parser *parser) | |
953ff289 | 12440 | { |
acf0174b JJ |
12441 | location_t loc = c_parser_peek_token (parser)->location; |
12442 | c_parser_consume_pragma (parser); | |
12443 | c_parser_skip_to_pragma_eol (parser); | |
a68ab351 | 12444 | |
acf0174b JJ |
12445 | c_finish_omp_taskyield (loc); |
12446 | } | |
3ba09659 | 12447 | |
acf0174b JJ |
12448 | /* OpenMP 4.0: |
12449 | # pragma omp taskgroup new-line | |
12450 | */ | |
953ff289 | 12451 | |
acf0174b JJ |
12452 | static tree |
12453 | c_parser_omp_taskgroup (c_parser *parser) | |
12454 | { | |
12455 | location_t loc = c_parser_peek_token (parser)->location; | |
12456 | c_parser_skip_to_pragma_eol (parser); | |
12457 | return c_finish_omp_taskgroup (loc, c_parser_omp_structured_block (parser)); | |
12458 | } | |
c9f9eb5d | 12459 | |
acf0174b JJ |
12460 | /* OpenMP 4.0: |
12461 | # pragma omp cancel cancel-clause[optseq] new-line | |
953ff289 | 12462 | |
acf0174b JJ |
12463 | LOC is the location of the #pragma. |
12464 | */ | |
a68ab351 | 12465 | |
acf0174b JJ |
12466 | #define OMP_CANCEL_CLAUSE_MASK \ |
12467 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \ | |
12468 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \ | |
12469 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \ | |
12470 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP) \ | |
12471 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF)) | |
a68ab351 | 12472 | |
acf0174b JJ |
12473 | static void |
12474 | c_parser_omp_cancel (c_parser *parser) | |
12475 | { | |
12476 | location_t loc = c_parser_peek_token (parser)->location; | |
a68ab351 | 12477 | |
acf0174b JJ |
12478 | c_parser_consume_pragma (parser); |
12479 | tree clauses = c_parser_omp_all_clauses (parser, OMP_CANCEL_CLAUSE_MASK, | |
12480 | "#pragma omp cancel"); | |
953ff289 | 12481 | |
acf0174b JJ |
12482 | c_finish_omp_cancel (loc, clauses); |
12483 | } | |
953ff289 | 12484 | |
acf0174b JJ |
12485 | /* OpenMP 4.0: |
12486 | # pragma omp cancellation point cancelpt-clause[optseq] new-line | |
953ff289 | 12487 | |
acf0174b JJ |
12488 | LOC is the location of the #pragma. |
12489 | */ | |
953ff289 | 12490 | |
acf0174b JJ |
12491 | #define OMP_CANCELLATION_POINT_CLAUSE_MASK \ |
12492 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \ | |
12493 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \ | |
12494 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \ | |
12495 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP)) | |
a68ab351 | 12496 | |
acf0174b JJ |
12497 | static void |
12498 | c_parser_omp_cancellation_point (c_parser *parser) | |
12499 | { | |
12500 | location_t loc = c_parser_peek_token (parser)->location; | |
12501 | tree clauses; | |
12502 | bool point_seen = false; | |
12503 | ||
12504 | c_parser_consume_pragma (parser); | |
12505 | if (c_parser_next_token_is (parser, CPP_NAME)) | |
a68ab351 | 12506 | { |
acf0174b JJ |
12507 | const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
12508 | if (strcmp (p, "point") == 0) | |
a68ab351 | 12509 | { |
acf0174b JJ |
12510 | c_parser_consume_token (parser); |
12511 | point_seen = true; | |
a68ab351 | 12512 | } |
a68ab351 | 12513 | } |
acf0174b | 12514 | if (!point_seen) |
a68ab351 | 12515 | { |
acf0174b JJ |
12516 | c_parser_error (parser, "expected %<point%>"); |
12517 | c_parser_skip_to_pragma_eol (parser); | |
12518 | return; | |
a68ab351 | 12519 | } |
953ff289 | 12520 | |
acf0174b JJ |
12521 | clauses |
12522 | = c_parser_omp_all_clauses (parser, OMP_CANCELLATION_POINT_CLAUSE_MASK, | |
12523 | "#pragma omp cancellation point"); | |
c2255bc4 | 12524 | |
acf0174b JJ |
12525 | c_finish_omp_cancellation_point (loc, clauses); |
12526 | } | |
953ff289 | 12527 | |
acf0174b JJ |
12528 | /* OpenMP 4.0: |
12529 | #pragma omp distribute distribute-clause[optseq] new-line | |
12530 | for-loop */ | |
12531 | ||
12532 | #define OMP_DISTRIBUTE_CLAUSE_MASK \ | |
12533 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \ | |
12534 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \ | |
12535 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)\ | |
12536 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE)) | |
953ff289 DN |
12537 | |
12538 | static tree | |
acf0174b JJ |
12539 | c_parser_omp_distribute (location_t loc, c_parser *parser, |
12540 | char *p_name, omp_clause_mask mask, tree *cclauses) | |
953ff289 | 12541 | { |
acf0174b JJ |
12542 | tree clauses, block, ret; |
12543 | ||
12544 | strcat (p_name, " distribute"); | |
12545 | mask |= OMP_DISTRIBUTE_CLAUSE_MASK; | |
12546 | ||
12547 | if (c_parser_next_token_is (parser, CPP_NAME)) | |
12548 | { | |
12549 | const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); | |
12550 | bool simd = false; | |
12551 | bool parallel = false; | |
12552 | ||
12553 | if (strcmp (p, "simd") == 0) | |
12554 | simd = true; | |
12555 | else | |
12556 | parallel = strcmp (p, "parallel") == 0; | |
12557 | if (parallel || simd) | |
12558 | { | |
12559 | tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT]; | |
12560 | if (cclauses == NULL) | |
12561 | cclauses = cclauses_buf; | |
12562 | c_parser_consume_token (parser); | |
6d7f7e0a TB |
12563 | if (!flag_openmp) /* flag_openmp_simd */ |
12564 | { | |
12565 | if (simd) | |
12566 | return c_parser_omp_simd (loc, parser, p_name, mask, cclauses); | |
12567 | else | |
12568 | return c_parser_omp_parallel (loc, parser, p_name, mask, | |
12569 | cclauses); | |
12570 | } | |
acf0174b JJ |
12571 | block = c_begin_compound_stmt (true); |
12572 | if (simd) | |
12573 | ret = c_parser_omp_simd (loc, parser, p_name, mask, cclauses); | |
12574 | else | |
12575 | ret = c_parser_omp_parallel (loc, parser, p_name, mask, cclauses); | |
12576 | block = c_end_compound_stmt (loc, block, true); | |
12577 | if (ret == NULL) | |
12578 | return ret; | |
12579 | ret = make_node (OMP_DISTRIBUTE); | |
12580 | TREE_TYPE (ret) = void_type_node; | |
12581 | OMP_FOR_BODY (ret) = block; | |
12582 | OMP_FOR_CLAUSES (ret) = cclauses[C_OMP_CLAUSE_SPLIT_DISTRIBUTE]; | |
12583 | SET_EXPR_LOCATION (ret, loc); | |
12584 | add_stmt (ret); | |
12585 | return ret; | |
12586 | } | |
12587 | } | |
6d7f7e0a TB |
12588 | if (!flag_openmp) /* flag_openmp_simd */ |
12589 | { | |
12590 | c_parser_skip_to_pragma_eol (parser); | |
12591 | return NULL_TREE; | |
12592 | } | |
953ff289 | 12593 | |
acf0174b JJ |
12594 | clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL); |
12595 | if (cclauses) | |
12596 | { | |
12597 | omp_split_clauses (loc, OMP_DISTRIBUTE, mask, clauses, cclauses); | |
12598 | clauses = cclauses[C_OMP_CLAUSE_SPLIT_DISTRIBUTE]; | |
12599 | } | |
953ff289 DN |
12600 | |
12601 | block = c_begin_compound_stmt (true); | |
acf0174b | 12602 | ret = c_parser_omp_for_loop (loc, parser, OMP_DISTRIBUTE, clauses, NULL); |
c2255bc4 | 12603 | block = c_end_compound_stmt (loc, block, true); |
953ff289 DN |
12604 | add_stmt (block); |
12605 | ||
12606 | return ret; | |
12607 | } | |
12608 | ||
acf0174b JJ |
12609 | /* OpenMP 4.0: |
12610 | # pragma omp teams teams-clause[optseq] new-line | |
12611 | structured-block */ | |
c2255bc4 | 12612 | |
acf0174b JJ |
12613 | #define OMP_TEAMS_CLAUSE_MASK \ |
12614 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \ | |
12615 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \ | |
12616 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \ | |
12617 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \ | |
12618 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_TEAMS) \ | |
12619 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_THREAD_LIMIT) \ | |
12620 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT)) | |
953ff289 DN |
12621 | |
12622 | static tree | |
acf0174b JJ |
12623 | c_parser_omp_teams (location_t loc, c_parser *parser, |
12624 | char *p_name, omp_clause_mask mask, tree *cclauses) | |
953ff289 | 12625 | { |
acf0174b JJ |
12626 | tree clauses, block, ret; |
12627 | ||
12628 | strcat (p_name, " teams"); | |
12629 | mask |= OMP_TEAMS_CLAUSE_MASK; | |
12630 | ||
12631 | if (c_parser_next_token_is (parser, CPP_NAME)) | |
12632 | { | |
12633 | const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); | |
12634 | if (strcmp (p, "distribute") == 0) | |
12635 | { | |
12636 | tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT]; | |
12637 | if (cclauses == NULL) | |
12638 | cclauses = cclauses_buf; | |
12639 | ||
12640 | c_parser_consume_token (parser); | |
6d7f7e0a TB |
12641 | if (!flag_openmp) /* flag_openmp_simd */ |
12642 | return c_parser_omp_distribute (loc, parser, p_name, mask, cclauses); | |
acf0174b JJ |
12643 | block = c_begin_compound_stmt (true); |
12644 | ret = c_parser_omp_distribute (loc, parser, p_name, mask, cclauses); | |
12645 | block = c_end_compound_stmt (loc, block, true); | |
12646 | if (ret == NULL) | |
12647 | return ret; | |
12648 | clauses = cclauses[C_OMP_CLAUSE_SPLIT_TEAMS]; | |
12649 | ret = make_node (OMP_TEAMS); | |
12650 | TREE_TYPE (ret) = void_type_node; | |
12651 | OMP_TEAMS_CLAUSES (ret) = clauses; | |
12652 | OMP_TEAMS_BODY (ret) = block; | |
12653 | return add_stmt (ret); | |
12654 | } | |
12655 | } | |
6d7f7e0a TB |
12656 | if (!flag_openmp) /* flag_openmp_simd */ |
12657 | { | |
12658 | c_parser_skip_to_pragma_eol (parser); | |
12659 | return NULL_TREE; | |
12660 | } | |
acf0174b JJ |
12661 | |
12662 | clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL); | |
12663 | if (cclauses) | |
12664 | { | |
12665 | omp_split_clauses (loc, OMP_TEAMS, mask, clauses, cclauses); | |
12666 | clauses = cclauses[C_OMP_CLAUSE_SPLIT_TEAMS]; | |
12667 | } | |
12668 | ||
12669 | tree stmt = make_node (OMP_TEAMS); | |
12670 | TREE_TYPE (stmt) = void_type_node; | |
12671 | OMP_TEAMS_CLAUSES (stmt) = clauses; | |
12672 | OMP_TEAMS_BODY (stmt) = c_parser_omp_structured_block (parser); | |
12673 | ||
12674 | return add_stmt (stmt); | |
953ff289 DN |
12675 | } |
12676 | ||
acf0174b JJ |
12677 | /* OpenMP 4.0: |
12678 | # pragma omp target data target-data-clause[optseq] new-line | |
12679 | structured-block */ | |
c2255bc4 | 12680 | |
acf0174b JJ |
12681 | #define OMP_TARGET_DATA_CLAUSE_MASK \ |
12682 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \ | |
12683 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \ | |
12684 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF)) | |
953ff289 DN |
12685 | |
12686 | static tree | |
acf0174b | 12687 | c_parser_omp_target_data (location_t loc, c_parser *parser) |
953ff289 | 12688 | { |
acf0174b JJ |
12689 | tree stmt = make_node (OMP_TARGET_DATA); |
12690 | TREE_TYPE (stmt) = void_type_node; | |
953ff289 | 12691 | |
acf0174b JJ |
12692 | OMP_TARGET_DATA_CLAUSES (stmt) |
12693 | = c_parser_omp_all_clauses (parser, OMP_TARGET_DATA_CLAUSE_MASK, | |
12694 | "#pragma omp target data"); | |
12695 | keep_next_level (); | |
12696 | tree block = c_begin_compound_stmt (true); | |
12697 | add_stmt (c_parser_omp_structured_block (parser)); | |
12698 | OMP_TARGET_DATA_BODY (stmt) = c_end_compound_stmt (loc, block, true); | |
953ff289 | 12699 | |
acf0174b JJ |
12700 | SET_EXPR_LOCATION (stmt, loc); |
12701 | return add_stmt (stmt); | |
12702 | } | |
953ff289 | 12703 | |
acf0174b JJ |
12704 | /* OpenMP 4.0: |
12705 | # pragma omp target update target-update-clause[optseq] new-line */ | |
c2255bc4 | 12706 | |
acf0174b JJ |
12707 | #define OMP_TARGET_UPDATE_CLAUSE_MASK \ |
12708 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FROM) \ | |
12709 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TO) \ | |
12710 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \ | |
12711 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF)) | |
953ff289 | 12712 | |
acf0174b JJ |
12713 | static bool |
12714 | c_parser_omp_target_update (location_t loc, c_parser *parser, | |
12715 | enum pragma_context context) | |
953ff289 | 12716 | { |
acf0174b JJ |
12717 | if (context == pragma_stmt) |
12718 | { | |
12719 | error_at (loc, | |
12720 | "%<#pragma omp target update%> may only be " | |
12721 | "used in compound statements"); | |
12722 | c_parser_skip_to_pragma_eol (parser); | |
12723 | return false; | |
12724 | } | |
953ff289 | 12725 | |
acf0174b JJ |
12726 | tree clauses |
12727 | = c_parser_omp_all_clauses (parser, OMP_TARGET_UPDATE_CLAUSE_MASK, | |
12728 | "#pragma omp target update"); | |
12729 | if (find_omp_clause (clauses, OMP_CLAUSE_TO) == NULL_TREE | |
12730 | && find_omp_clause (clauses, OMP_CLAUSE_FROM) == NULL_TREE) | |
953ff289 | 12731 | { |
acf0174b JJ |
12732 | error_at (loc, |
12733 | "%<#pragma omp target update must contain at least one " | |
12734 | "%<from%> or %<to%> clauses"); | |
12735 | return false; | |
953ff289 DN |
12736 | } |
12737 | ||
acf0174b JJ |
12738 | tree stmt = make_node (OMP_TARGET_UPDATE); |
12739 | TREE_TYPE (stmt) = void_type_node; | |
12740 | OMP_TARGET_UPDATE_CLAUSES (stmt) = clauses; | |
12741 | SET_EXPR_LOCATION (stmt, loc); | |
12742 | add_stmt (stmt); | |
12743 | return false; | |
12744 | } | |
953ff289 | 12745 | |
acf0174b JJ |
12746 | /* OpenMP 4.0: |
12747 | # pragma omp target target-clause[optseq] new-line | |
12748 | structured-block */ | |
953ff289 | 12749 | |
acf0174b JJ |
12750 | #define OMP_TARGET_CLAUSE_MASK \ |
12751 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \ | |
12752 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \ | |
12753 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF)) | |
953ff289 | 12754 | |
acf0174b JJ |
12755 | static bool |
12756 | c_parser_omp_target (c_parser *parser, enum pragma_context context) | |
12757 | { | |
12758 | location_t loc = c_parser_peek_token (parser)->location; | |
12759 | c_parser_consume_pragma (parser); | |
953ff289 | 12760 | |
acf0174b JJ |
12761 | if (context != pragma_stmt && context != pragma_compound) |
12762 | { | |
12763 | c_parser_error (parser, "expected declaration specifiers"); | |
12764 | c_parser_skip_to_pragma_eol (parser); | |
12765 | return false; | |
953ff289 DN |
12766 | } |
12767 | ||
acf0174b | 12768 | if (c_parser_next_token_is (parser, CPP_NAME)) |
953ff289 | 12769 | { |
acf0174b | 12770 | const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
953ff289 | 12771 | |
6d7f7e0a | 12772 | if (strcmp (p, "teams") == 0) |
acf0174b JJ |
12773 | { |
12774 | tree cclauses[C_OMP_CLAUSE_SPLIT_COUNT]; | |
12775 | char p_name[sizeof ("#pragma omp target teams distribute " | |
12776 | "parallel for simd")]; | |
953ff289 | 12777 | |
acf0174b | 12778 | c_parser_consume_token (parser); |
e7bd1de1 | 12779 | strcpy (p_name, "#pragma omp target"); |
6d7f7e0a | 12780 | if (!flag_openmp) /* flag_openmp_simd */ |
edbba2ce TS |
12781 | { |
12782 | tree stmt = c_parser_omp_teams (loc, parser, p_name, | |
12783 | OMP_TARGET_CLAUSE_MASK, | |
12784 | cclauses); | |
12785 | return stmt != NULL_TREE; | |
12786 | } | |
acf0174b JJ |
12787 | keep_next_level (); |
12788 | tree block = c_begin_compound_stmt (true); | |
12789 | tree ret = c_parser_omp_teams (loc, parser, p_name, | |
12790 | OMP_TARGET_CLAUSE_MASK, cclauses); | |
12791 | block = c_end_compound_stmt (loc, block, true); | |
edbba2ce TS |
12792 | if (ret == NULL_TREE) |
12793 | return false; | |
acf0174b JJ |
12794 | tree stmt = make_node (OMP_TARGET); |
12795 | TREE_TYPE (stmt) = void_type_node; | |
12796 | OMP_TARGET_CLAUSES (stmt) = cclauses[C_OMP_CLAUSE_SPLIT_TARGET]; | |
12797 | OMP_TARGET_BODY (stmt) = block; | |
12798 | add_stmt (stmt); | |
12799 | return true; | |
12800 | } | |
6d7f7e0a TB |
12801 | else if (!flag_openmp) /* flag_openmp_simd */ |
12802 | { | |
12803 | c_parser_skip_to_pragma_eol (parser); | |
edbba2ce | 12804 | return false; |
6d7f7e0a TB |
12805 | } |
12806 | else if (strcmp (p, "data") == 0) | |
12807 | { | |
12808 | c_parser_consume_token (parser); | |
12809 | c_parser_omp_target_data (loc, parser); | |
12810 | return true; | |
12811 | } | |
12812 | else if (strcmp (p, "update") == 0) | |
12813 | { | |
12814 | c_parser_consume_token (parser); | |
12815 | return c_parser_omp_target_update (loc, parser, context); | |
12816 | } | |
953ff289 | 12817 | } |
953ff289 | 12818 | |
acf0174b | 12819 | tree stmt = make_node (OMP_TARGET); |
953ff289 | 12820 | TREE_TYPE (stmt) = void_type_node; |
953ff289 | 12821 | |
acf0174b JJ |
12822 | OMP_TARGET_CLAUSES (stmt) |
12823 | = c_parser_omp_all_clauses (parser, OMP_TARGET_CLAUSE_MASK, | |
12824 | "#pragma omp target"); | |
12825 | keep_next_level (); | |
12826 | tree block = c_begin_compound_stmt (true); | |
12827 | add_stmt (c_parser_omp_structured_block (parser)); | |
12828 | OMP_TARGET_BODY (stmt) = c_end_compound_stmt (loc, block, true); | |
12829 | ||
12830 | SET_EXPR_LOCATION (stmt, loc); | |
12831 | add_stmt (stmt); | |
12832 | return true; | |
12833 | } | |
12834 | ||
12835 | /* OpenMP 4.0: | |
12836 | # pragma omp declare simd declare-simd-clauses[optseq] new-line */ | |
12837 | ||
12838 | #define OMP_DECLARE_SIMD_CLAUSE_MASK \ | |
12839 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMDLEN) \ | |
12840 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \ | |
12841 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \ | |
12842 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNIFORM) \ | |
12843 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_INBRANCH) \ | |
12844 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOTINBRANCH)) | |
12845 | ||
12846 | static void | |
12847 | c_parser_omp_declare_simd (c_parser *parser, enum pragma_context context) | |
12848 | { | |
12849 | vec<c_token> clauses = vNULL; | |
12850 | while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL)) | |
12851 | { | |
12852 | c_token *token = c_parser_peek_token (parser); | |
12853 | if (token->type == CPP_EOF) | |
12854 | { | |
12855 | c_parser_skip_to_pragma_eol (parser); | |
12856 | clauses.release (); | |
12857 | return; | |
12858 | } | |
12859 | clauses.safe_push (*token); | |
12860 | c_parser_consume_token (parser); | |
12861 | } | |
12862 | clauses.safe_push (*c_parser_peek_token (parser)); | |
12863 | c_parser_skip_to_pragma_eol (parser); | |
12864 | ||
12865 | while (c_parser_next_token_is (parser, CPP_PRAGMA)) | |
12866 | { | |
12867 | if (c_parser_peek_token (parser)->pragma_kind | |
12868 | != PRAGMA_OMP_DECLARE_REDUCTION | |
12869 | || c_parser_peek_2nd_token (parser)->type != CPP_NAME | |
12870 | || strcmp (IDENTIFIER_POINTER | |
12871 | (c_parser_peek_2nd_token (parser)->value), | |
12872 | "simd") != 0) | |
12873 | { | |
12874 | c_parser_error (parser, | |
12875 | "%<#pragma omp declare simd%> must be followed by " | |
12876 | "function declaration or definition or another " | |
12877 | "%<#pragma omp declare simd%>"); | |
12878 | clauses.release (); | |
12879 | return; | |
12880 | } | |
12881 | c_parser_consume_pragma (parser); | |
12882 | while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL)) | |
12883 | { | |
12884 | c_token *token = c_parser_peek_token (parser); | |
12885 | if (token->type == CPP_EOF) | |
12886 | { | |
12887 | c_parser_skip_to_pragma_eol (parser); | |
12888 | clauses.release (); | |
12889 | return; | |
12890 | } | |
12891 | clauses.safe_push (*token); | |
12892 | c_parser_consume_token (parser); | |
12893 | } | |
12894 | clauses.safe_push (*c_parser_peek_token (parser)); | |
12895 | c_parser_skip_to_pragma_eol (parser); | |
12896 | } | |
12897 | ||
12898 | /* Make sure nothing tries to read past the end of the tokens. */ | |
12899 | c_token eof_token; | |
12900 | memset (&eof_token, 0, sizeof (eof_token)); | |
12901 | eof_token.type = CPP_EOF; | |
12902 | clauses.safe_push (eof_token); | |
12903 | clauses.safe_push (eof_token); | |
12904 | ||
12905 | switch (context) | |
12906 | { | |
12907 | case pragma_external: | |
12908 | if (c_parser_next_token_is (parser, CPP_KEYWORD) | |
12909 | && c_parser_peek_token (parser)->keyword == RID_EXTENSION) | |
12910 | { | |
12911 | int ext = disable_extension_diagnostics (); | |
12912 | do | |
12913 | c_parser_consume_token (parser); | |
12914 | while (c_parser_next_token_is (parser, CPP_KEYWORD) | |
12915 | && c_parser_peek_token (parser)->keyword == RID_EXTENSION); | |
12916 | c_parser_declaration_or_fndef (parser, true, true, true, false, true, | |
12917 | NULL, clauses); | |
12918 | restore_extension_diagnostics (ext); | |
12919 | } | |
12920 | else | |
12921 | c_parser_declaration_or_fndef (parser, true, true, true, false, true, | |
12922 | NULL, clauses); | |
12923 | break; | |
12924 | case pragma_struct: | |
12925 | case pragma_param: | |
12926 | c_parser_error (parser, "%<#pragma omp declare simd%> must be followed by " | |
12927 | "function declaration or definition"); | |
12928 | break; | |
12929 | case pragma_compound: | |
12930 | case pragma_stmt: | |
12931 | if (c_parser_next_token_is (parser, CPP_KEYWORD) | |
12932 | && c_parser_peek_token (parser)->keyword == RID_EXTENSION) | |
12933 | { | |
12934 | int ext = disable_extension_diagnostics (); | |
12935 | do | |
12936 | c_parser_consume_token (parser); | |
12937 | while (c_parser_next_token_is (parser, CPP_KEYWORD) | |
12938 | && c_parser_peek_token (parser)->keyword == RID_EXTENSION); | |
12939 | if (c_parser_next_tokens_start_declaration (parser)) | |
12940 | { | |
12941 | c_parser_declaration_or_fndef (parser, true, true, true, true, | |
12942 | true, NULL, clauses); | |
12943 | restore_extension_diagnostics (ext); | |
12944 | break; | |
12945 | } | |
12946 | restore_extension_diagnostics (ext); | |
12947 | } | |
12948 | else if (c_parser_next_tokens_start_declaration (parser)) | |
12949 | { | |
12950 | c_parser_declaration_or_fndef (parser, true, true, true, true, true, | |
12951 | NULL, clauses); | |
12952 | break; | |
12953 | } | |
12954 | c_parser_error (parser, "%<#pragma omp declare simd%> must be followed by " | |
12955 | "function declaration or definition"); | |
12956 | break; | |
12957 | default: | |
12958 | gcc_unreachable (); | |
12959 | } | |
12960 | clauses.release (); | |
953ff289 DN |
12961 | } |
12962 | ||
acf0174b JJ |
12963 | /* Finalize #pragma omp declare simd clauses after FNDECL has been parsed, |
12964 | and put that into "omp declare simd" attribute. */ | |
c2255bc4 | 12965 | |
acf0174b JJ |
12966 | static void |
12967 | c_finish_omp_declare_simd (c_parser *parser, tree fndecl, tree parms, | |
12968 | vec<c_token> clauses) | |
12969 | { | |
b72271b9 | 12970 | if (flag_cilkplus |
41958c28 BI |
12971 | && clauses.exists () && !vec_safe_is_empty (parser->cilk_simd_fn_tokens)) |
12972 | { | |
12973 | error ("%<#pragma omp declare simd%> cannot be used in the same " | |
12974 | "function marked as a Cilk Plus SIMD-enabled function"); | |
12975 | vec_free (parser->cilk_simd_fn_tokens); | |
12976 | return; | |
12977 | } | |
12978 | ||
acf0174b JJ |
12979 | /* Normally first token is CPP_NAME "simd". CPP_EOF there indicates |
12980 | error has been reported and CPP_PRAGMA that c_finish_omp_declare_simd | |
12981 | has already processed the tokens. */ | |
41958c28 | 12982 | if (clauses.exists () && clauses[0].type == CPP_EOF) |
acf0174b JJ |
12983 | return; |
12984 | if (fndecl == NULL_TREE || TREE_CODE (fndecl) != FUNCTION_DECL) | |
12985 | { | |
12986 | error ("%<#pragma omp declare simd%> not immediately followed by " | |
12987 | "a function declaration or definition"); | |
12988 | clauses[0].type = CPP_EOF; | |
12989 | return; | |
12990 | } | |
41958c28 | 12991 | if (clauses.exists () && clauses[0].type != CPP_NAME) |
acf0174b JJ |
12992 | { |
12993 | error_at (DECL_SOURCE_LOCATION (fndecl), | |
12994 | "%<#pragma omp declare simd%> not immediately followed by " | |
12995 | "a single function declaration or definition"); | |
12996 | clauses[0].type = CPP_EOF; | |
12997 | return; | |
12998 | } | |
953ff289 | 12999 | |
acf0174b JJ |
13000 | if (parms == NULL_TREE) |
13001 | parms = DECL_ARGUMENTS (fndecl); | |
953ff289 | 13002 | |
acf0174b JJ |
13003 | unsigned int tokens_avail = parser->tokens_avail; |
13004 | gcc_assert (parser->tokens == &parser->tokens_buf[0]); | |
41958c28 BI |
13005 | bool is_cilkplus_cilk_simd_fn = false; |
13006 | ||
b72271b9 | 13007 | if (flag_cilkplus && !vec_safe_is_empty (parser->cilk_simd_fn_tokens)) |
41958c28 BI |
13008 | { |
13009 | parser->tokens = parser->cilk_simd_fn_tokens->address (); | |
13010 | parser->tokens_avail = vec_safe_length (parser->cilk_simd_fn_tokens); | |
13011 | is_cilkplus_cilk_simd_fn = true; | |
13012 | } | |
13013 | else | |
13014 | { | |
13015 | parser->tokens = clauses.address (); | |
13016 | parser->tokens_avail = clauses.length (); | |
13017 | } | |
13018 | ||
acf0174b JJ |
13019 | /* c_parser_omp_declare_simd pushed 2 extra CPP_EOF tokens at the end. */ |
13020 | while (parser->tokens_avail > 3) | |
13021 | { | |
13022 | c_token *token = c_parser_peek_token (parser); | |
41958c28 BI |
13023 | if (!is_cilkplus_cilk_simd_fn) |
13024 | gcc_assert (token->type == CPP_NAME | |
13025 | && strcmp (IDENTIFIER_POINTER (token->value), "simd") == 0); | |
13026 | else | |
13027 | gcc_assert (token->type == CPP_NAME | |
13028 | && is_cilkplus_vector_p (token->value)); | |
acf0174b JJ |
13029 | c_parser_consume_token (parser); |
13030 | parser->in_pragma = true; | |
953ff289 | 13031 | |
41958c28 BI |
13032 | tree c = NULL_TREE; |
13033 | if (is_cilkplus_cilk_simd_fn) | |
13034 | c = c_parser_omp_all_clauses (parser, CILK_SIMD_FN_CLAUSE_MASK, | |
13035 | "SIMD-enabled functions attribute"); | |
13036 | else | |
13037 | c = c_parser_omp_all_clauses (parser, OMP_DECLARE_SIMD_CLAUSE_MASK, | |
13038 | "#pragma omp declare simd"); | |
acf0174b JJ |
13039 | c = c_omp_declare_simd_clauses_to_numbers (parms, c); |
13040 | if (c != NULL_TREE) | |
13041 | c = tree_cons (NULL_TREE, c, NULL_TREE); | |
41958c28 BI |
13042 | if (is_cilkplus_cilk_simd_fn) |
13043 | { | |
74558dd9 BI |
13044 | tree k = build_tree_list (get_identifier ("cilk simd function"), |
13045 | NULL_TREE); | |
41958c28 BI |
13046 | TREE_CHAIN (k) = DECL_ATTRIBUTES (fndecl); |
13047 | DECL_ATTRIBUTES (fndecl) = k; | |
13048 | } | |
acf0174b JJ |
13049 | c = build_tree_list (get_identifier ("omp declare simd"), c); |
13050 | TREE_CHAIN (c) = DECL_ATTRIBUTES (fndecl); | |
13051 | DECL_ATTRIBUTES (fndecl) = c; | |
13052 | } | |
953ff289 | 13053 | |
acf0174b JJ |
13054 | parser->tokens = &parser->tokens_buf[0]; |
13055 | parser->tokens_avail = tokens_avail; | |
41958c28 BI |
13056 | if (clauses.exists ()) |
13057 | clauses[0].type = CPP_PRAGMA; | |
13058 | ||
13059 | if (!vec_safe_is_empty (parser->cilk_simd_fn_tokens)) | |
13060 | vec_free (parser->cilk_simd_fn_tokens); | |
953ff289 DN |
13061 | } |
13062 | ||
953ff289 | 13063 | |
acf0174b JJ |
13064 | /* OpenMP 4.0: |
13065 | # pragma omp declare target new-line | |
13066 | declarations and definitions | |
13067 | # pragma omp end declare target new-line */ | |
953ff289 | 13068 | |
acf0174b JJ |
13069 | static void |
13070 | c_parser_omp_declare_target (c_parser *parser) | |
953ff289 | 13071 | { |
acf0174b JJ |
13072 | c_parser_skip_to_pragma_eol (parser); |
13073 | current_omp_declare_target_attribute++; | |
13074 | } | |
953ff289 | 13075 | |
acf0174b JJ |
13076 | static void |
13077 | c_parser_omp_end_declare_target (c_parser *parser) | |
13078 | { | |
13079 | location_t loc = c_parser_peek_token (parser)->location; | |
13080 | c_parser_consume_pragma (parser); | |
13081 | if (c_parser_next_token_is (parser, CPP_NAME) | |
13082 | && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser)->value), | |
13083 | "declare") == 0) | |
953ff289 DN |
13084 | { |
13085 | c_parser_consume_token (parser); | |
acf0174b JJ |
13086 | if (c_parser_next_token_is (parser, CPP_NAME) |
13087 | && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser)->value), | |
13088 | "target") == 0) | |
13089 | c_parser_consume_token (parser); | |
13090 | else | |
953ff289 | 13091 | { |
acf0174b JJ |
13092 | c_parser_error (parser, "expected %<target%>"); |
13093 | c_parser_skip_to_pragma_eol (parser); | |
13094 | return; | |
953ff289 DN |
13095 | } |
13096 | } | |
acf0174b JJ |
13097 | else |
13098 | { | |
13099 | c_parser_error (parser, "expected %<declare%>"); | |
13100 | c_parser_skip_to_pragma_eol (parser); | |
13101 | return; | |
13102 | } | |
13103 | c_parser_skip_to_pragma_eol (parser); | |
13104 | if (!current_omp_declare_target_attribute) | |
13105 | error_at (loc, "%<#pragma omp end declare target%> without corresponding " | |
13106 | "%<#pragma omp declare target%>"); | |
13107 | else | |
13108 | current_omp_declare_target_attribute--; | |
13109 | } | |
953ff289 | 13110 | |
953ff289 | 13111 | |
acf0174b JJ |
13112 | /* OpenMP 4.0 |
13113 | #pragma omp declare reduction (reduction-id : typename-list : expression) \ | |
13114 | initializer-clause[opt] new-line | |
13115 | ||
13116 | initializer-clause: | |
13117 | initializer (omp_priv = initializer) | |
13118 | initializer (function-name (argument-list)) */ | |
13119 | ||
13120 | static void | |
13121 | c_parser_omp_declare_reduction (c_parser *parser, enum pragma_context context) | |
13122 | { | |
13123 | unsigned int tokens_avail = 0, i; | |
13124 | vec<tree> types = vNULL; | |
13125 | vec<c_token> clauses = vNULL; | |
13126 | enum tree_code reduc_code = ERROR_MARK; | |
13127 | tree reduc_id = NULL_TREE; | |
13128 | tree type; | |
13129 | location_t rloc = c_parser_peek_token (parser)->location; | |
13130 | ||
13131 | if (context == pragma_struct || context == pragma_param) | |
953ff289 | 13132 | { |
acf0174b JJ |
13133 | error ("%<#pragma omp declare reduction%> not at file or block scope"); |
13134 | goto fail; | |
13135 | } | |
953ff289 | 13136 | |
acf0174b JJ |
13137 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) |
13138 | goto fail; | |
953ff289 | 13139 | |
acf0174b JJ |
13140 | switch (c_parser_peek_token (parser)->type) |
13141 | { | |
13142 | case CPP_PLUS: | |
13143 | reduc_code = PLUS_EXPR; | |
13144 | break; | |
13145 | case CPP_MULT: | |
13146 | reduc_code = MULT_EXPR; | |
13147 | break; | |
13148 | case CPP_MINUS: | |
13149 | reduc_code = MINUS_EXPR; | |
13150 | break; | |
13151 | case CPP_AND: | |
13152 | reduc_code = BIT_AND_EXPR; | |
13153 | break; | |
13154 | case CPP_XOR: | |
13155 | reduc_code = BIT_XOR_EXPR; | |
13156 | break; | |
13157 | case CPP_OR: | |
13158 | reduc_code = BIT_IOR_EXPR; | |
13159 | break; | |
13160 | case CPP_AND_AND: | |
13161 | reduc_code = TRUTH_ANDIF_EXPR; | |
13162 | break; | |
13163 | case CPP_OR_OR: | |
13164 | reduc_code = TRUTH_ORIF_EXPR; | |
13165 | break; | |
13166 | case CPP_NAME: | |
13167 | const char *p; | |
13168 | p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); | |
13169 | if (strcmp (p, "min") == 0) | |
13170 | { | |
13171 | reduc_code = MIN_EXPR; | |
13172 | break; | |
13173 | } | |
13174 | if (strcmp (p, "max") == 0) | |
13175 | { | |
13176 | reduc_code = MAX_EXPR; | |
13177 | break; | |
13178 | } | |
13179 | reduc_id = c_parser_peek_token (parser)->value; | |
953ff289 | 13180 | break; |
953ff289 | 13181 | default: |
acf0174b JJ |
13182 | c_parser_error (parser, |
13183 | "expected %<+%>, %<*%>, %<-%>, %<&%>, " | |
13184 | "%<^%>, %<|%>, %<&&%>, %<||%>, %<min%> or identifier"); | |
13185 | goto fail; | |
953ff289 DN |
13186 | } |
13187 | ||
acf0174b JJ |
13188 | tree orig_reduc_id, reduc_decl; |
13189 | orig_reduc_id = reduc_id; | |
13190 | reduc_id = c_omp_reduction_id (reduc_code, reduc_id); | |
13191 | reduc_decl = c_omp_reduction_decl (reduc_id); | |
13192 | c_parser_consume_token (parser); | |
953ff289 | 13193 | |
acf0174b JJ |
13194 | if (!c_parser_require (parser, CPP_COLON, "expected %<:%>")) |
13195 | goto fail; | |
c2255bc4 | 13196 | |
acf0174b JJ |
13197 | while (true) |
13198 | { | |
13199 | location_t loc = c_parser_peek_token (parser)->location; | |
13200 | struct c_type_name *ctype = c_parser_type_name (parser); | |
13201 | if (ctype != NULL) | |
13202 | { | |
13203 | type = groktypename (ctype, NULL, NULL); | |
13204 | if (type == error_mark_node) | |
13205 | ; | |
13206 | else if ((INTEGRAL_TYPE_P (type) | |
13207 | || TREE_CODE (type) == REAL_TYPE | |
13208 | || TREE_CODE (type) == COMPLEX_TYPE) | |
13209 | && orig_reduc_id == NULL_TREE) | |
13210 | error_at (loc, "predeclared arithmetic type in " | |
13211 | "%<#pragma omp declare reduction%>"); | |
13212 | else if (TREE_CODE (type) == FUNCTION_TYPE | |
13213 | || TREE_CODE (type) == ARRAY_TYPE) | |
13214 | error_at (loc, "function or array type in " | |
13215 | "%<#pragma omp declare reduction%>"); | |
13216 | else if (TYPE_QUALS_NO_ADDR_SPACE (type)) | |
13217 | error_at (loc, "const, volatile or restrict qualified type in " | |
13218 | "%<#pragma omp declare reduction%>"); | |
13219 | else | |
13220 | { | |
13221 | tree t; | |
13222 | for (t = DECL_INITIAL (reduc_decl); t; t = TREE_CHAIN (t)) | |
13223 | if (comptypes (TREE_PURPOSE (t), type)) | |
13224 | { | |
13225 | error_at (loc, "redeclaration of %qs " | |
13226 | "%<#pragma omp declare reduction%> for " | |
13227 | "type %qT", | |
13228 | IDENTIFIER_POINTER (reduc_id) | |
13229 | + sizeof ("omp declare reduction ") - 1, | |
13230 | type); | |
13231 | location_t ploc | |
13232 | = DECL_SOURCE_LOCATION (TREE_VEC_ELT (TREE_VALUE (t), | |
13233 | 0)); | |
13234 | error_at (ploc, "previous %<#pragma omp declare " | |
13235 | "reduction%>"); | |
13236 | break; | |
13237 | } | |
13238 | if (t == NULL_TREE) | |
13239 | types.safe_push (type); | |
13240 | } | |
13241 | if (c_parser_next_token_is (parser, CPP_COMMA)) | |
13242 | c_parser_consume_token (parser); | |
13243 | else | |
13244 | break; | |
13245 | } | |
13246 | else | |
13247 | break; | |
13248 | } | |
953ff289 | 13249 | |
acf0174b JJ |
13250 | if (!c_parser_require (parser, CPP_COLON, "expected %<:%>") |
13251 | || types.is_empty ()) | |
13252 | { | |
13253 | fail: | |
13254 | clauses.release (); | |
13255 | types.release (); | |
13256 | while (true) | |
13257 | { | |
13258 | c_token *token = c_parser_peek_token (parser); | |
13259 | if (token->type == CPP_EOF || token->type == CPP_PRAGMA_EOL) | |
13260 | break; | |
13261 | c_parser_consume_token (parser); | |
13262 | } | |
13263 | c_parser_skip_to_pragma_eol (parser); | |
13264 | return; | |
13265 | } | |
953ff289 | 13266 | |
acf0174b JJ |
13267 | if (types.length () > 1) |
13268 | { | |
13269 | while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL)) | |
13270 | { | |
13271 | c_token *token = c_parser_peek_token (parser); | |
13272 | if (token->type == CPP_EOF) | |
13273 | goto fail; | |
13274 | clauses.safe_push (*token); | |
13275 | c_parser_consume_token (parser); | |
13276 | } | |
13277 | clauses.safe_push (*c_parser_peek_token (parser)); | |
13278 | c_parser_skip_to_pragma_eol (parser); | |
953ff289 | 13279 | |
acf0174b JJ |
13280 | /* Make sure nothing tries to read past the end of the tokens. */ |
13281 | c_token eof_token; | |
13282 | memset (&eof_token, 0, sizeof (eof_token)); | |
13283 | eof_token.type = CPP_EOF; | |
13284 | clauses.safe_push (eof_token); | |
13285 | clauses.safe_push (eof_token); | |
13286 | } | |
953ff289 | 13287 | |
acf0174b JJ |
13288 | int errs = errorcount; |
13289 | FOR_EACH_VEC_ELT (types, i, type) | |
13290 | { | |
13291 | tokens_avail = parser->tokens_avail; | |
13292 | gcc_assert (parser->tokens == &parser->tokens_buf[0]); | |
13293 | if (!clauses.is_empty ()) | |
13294 | { | |
13295 | parser->tokens = clauses.address (); | |
13296 | parser->tokens_avail = clauses.length (); | |
13297 | parser->in_pragma = true; | |
13298 | } | |
953ff289 | 13299 | |
acf0174b JJ |
13300 | bool nested = current_function_decl != NULL_TREE; |
13301 | if (nested) | |
13302 | c_push_function_context (); | |
13303 | tree fndecl = build_decl (BUILTINS_LOCATION, FUNCTION_DECL, | |
13304 | reduc_id, default_function_type); | |
13305 | current_function_decl = fndecl; | |
13306 | allocate_struct_function (fndecl, true); | |
13307 | push_scope (); | |
13308 | tree stmt = push_stmt_list (); | |
13309 | /* Intentionally BUILTINS_LOCATION, so that -Wshadow doesn't | |
13310 | warn about these. */ | |
13311 | tree omp_out = build_decl (BUILTINS_LOCATION, VAR_DECL, | |
13312 | get_identifier ("omp_out"), type); | |
13313 | DECL_ARTIFICIAL (omp_out) = 1; | |
13314 | DECL_CONTEXT (omp_out) = fndecl; | |
13315 | pushdecl (omp_out); | |
13316 | tree omp_in = build_decl (BUILTINS_LOCATION, VAR_DECL, | |
13317 | get_identifier ("omp_in"), type); | |
13318 | DECL_ARTIFICIAL (omp_in) = 1; | |
13319 | DECL_CONTEXT (omp_in) = fndecl; | |
13320 | pushdecl (omp_in); | |
13321 | struct c_expr combiner = c_parser_expression (parser); | |
13322 | struct c_expr initializer; | |
13323 | tree omp_priv = NULL_TREE, omp_orig = NULL_TREE; | |
13324 | bool bad = false; | |
13325 | initializer.value = error_mark_node; | |
13326 | if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>")) | |
13327 | bad = true; | |
13328 | else if (c_parser_next_token_is (parser, CPP_NAME) | |
13329 | && strcmp (IDENTIFIER_POINTER | |
13330 | (c_parser_peek_token (parser)->value), | |
13331 | "initializer") == 0) | |
13332 | { | |
13333 | c_parser_consume_token (parser); | |
13334 | pop_scope (); | |
13335 | push_scope (); | |
13336 | omp_priv = build_decl (BUILTINS_LOCATION, VAR_DECL, | |
13337 | get_identifier ("omp_priv"), type); | |
13338 | DECL_ARTIFICIAL (omp_priv) = 1; | |
13339 | DECL_INITIAL (omp_priv) = error_mark_node; | |
13340 | DECL_CONTEXT (omp_priv) = fndecl; | |
13341 | pushdecl (omp_priv); | |
13342 | omp_orig = build_decl (BUILTINS_LOCATION, VAR_DECL, | |
13343 | get_identifier ("omp_orig"), type); | |
13344 | DECL_ARTIFICIAL (omp_orig) = 1; | |
13345 | DECL_CONTEXT (omp_orig) = fndecl; | |
13346 | pushdecl (omp_orig); | |
13347 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
13348 | bad = true; | |
13349 | else if (!c_parser_next_token_is (parser, CPP_NAME)) | |
13350 | { | |
13351 | c_parser_error (parser, "expected %<omp_priv%> or " | |
13352 | "function-name"); | |
13353 | bad = true; | |
13354 | } | |
13355 | else if (strcmp (IDENTIFIER_POINTER | |
13356 | (c_parser_peek_token (parser)->value), | |
13357 | "omp_priv") != 0) | |
13358 | { | |
13359 | if (c_parser_peek_2nd_token (parser)->type != CPP_OPEN_PAREN | |
13360 | || c_parser_peek_token (parser)->id_kind != C_ID_ID) | |
13361 | { | |
13362 | c_parser_error (parser, "expected function-name %<(%>"); | |
13363 | bad = true; | |
13364 | } | |
13365 | else | |
13366 | initializer = c_parser_postfix_expression (parser); | |
13367 | if (initializer.value | |
13368 | && TREE_CODE (initializer.value) == CALL_EXPR) | |
13369 | { | |
13370 | int j; | |
13371 | tree c = initializer.value; | |
13372 | for (j = 0; j < call_expr_nargs (c); j++) | |
13373 | if (TREE_CODE (CALL_EXPR_ARG (c, j)) == ADDR_EXPR | |
13374 | && TREE_OPERAND (CALL_EXPR_ARG (c, j), 0) == omp_priv) | |
13375 | break; | |
13376 | if (j == call_expr_nargs (c)) | |
13377 | error ("one of the initializer call arguments should be " | |
13378 | "%<&omp_priv%>"); | |
13379 | } | |
13380 | } | |
13381 | else | |
13382 | { | |
13383 | c_parser_consume_token (parser); | |
13384 | if (!c_parser_require (parser, CPP_EQ, "expected %<=%>")) | |
13385 | bad = true; | |
13386 | else | |
13387 | { | |
13388 | tree st = push_stmt_list (); | |
13389 | start_init (omp_priv, NULL_TREE, 0); | |
13390 | location_t loc = c_parser_peek_token (parser)->location; | |
13391 | struct c_expr init = c_parser_initializer (parser); | |
13392 | finish_init (); | |
13393 | finish_decl (omp_priv, loc, init.value, | |
13394 | init.original_type, NULL_TREE); | |
13395 | pop_stmt_list (st); | |
13396 | } | |
13397 | } | |
13398 | if (!bad | |
13399 | && !c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>")) | |
13400 | bad = true; | |
13401 | } | |
c2255bc4 | 13402 | |
acf0174b JJ |
13403 | if (!bad) |
13404 | { | |
13405 | c_parser_skip_to_pragma_eol (parser); | |
a68ab351 | 13406 | |
acf0174b JJ |
13407 | tree t = tree_cons (type, make_tree_vec (omp_priv ? 6 : 3), |
13408 | DECL_INITIAL (reduc_decl)); | |
13409 | DECL_INITIAL (reduc_decl) = t; | |
13410 | DECL_SOURCE_LOCATION (omp_out) = rloc; | |
13411 | TREE_VEC_ELT (TREE_VALUE (t), 0) = omp_out; | |
13412 | TREE_VEC_ELT (TREE_VALUE (t), 1) = omp_in; | |
13413 | TREE_VEC_ELT (TREE_VALUE (t), 2) = combiner.value; | |
13414 | walk_tree (&combiner.value, c_check_omp_declare_reduction_r, | |
13415 | &TREE_VEC_ELT (TREE_VALUE (t), 0), NULL); | |
13416 | if (omp_priv) | |
13417 | { | |
13418 | DECL_SOURCE_LOCATION (omp_priv) = rloc; | |
13419 | TREE_VEC_ELT (TREE_VALUE (t), 3) = omp_priv; | |
13420 | TREE_VEC_ELT (TREE_VALUE (t), 4) = omp_orig; | |
13421 | TREE_VEC_ELT (TREE_VALUE (t), 5) = initializer.value; | |
13422 | walk_tree (&initializer.value, c_check_omp_declare_reduction_r, | |
13423 | &TREE_VEC_ELT (TREE_VALUE (t), 3), NULL); | |
13424 | walk_tree (&DECL_INITIAL (omp_priv), | |
13425 | c_check_omp_declare_reduction_r, | |
13426 | &TREE_VEC_ELT (TREE_VALUE (t), 3), NULL); | |
13427 | } | |
13428 | } | |
a68ab351 | 13429 | |
acf0174b JJ |
13430 | pop_stmt_list (stmt); |
13431 | pop_scope (); | |
13432 | if (cfun->language != NULL) | |
13433 | { | |
13434 | ggc_free (cfun->language); | |
13435 | cfun->language = NULL; | |
13436 | } | |
13437 | set_cfun (NULL); | |
13438 | current_function_decl = NULL_TREE; | |
13439 | if (nested) | |
13440 | c_pop_function_context (); | |
a68ab351 | 13441 | |
acf0174b JJ |
13442 | if (!clauses.is_empty ()) |
13443 | { | |
13444 | parser->tokens = &parser->tokens_buf[0]; | |
13445 | parser->tokens_avail = tokens_avail; | |
13446 | } | |
13447 | if (bad) | |
13448 | goto fail; | |
13449 | if (errs != errorcount) | |
13450 | break; | |
13451 | } | |
a68ab351 | 13452 | |
acf0174b JJ |
13453 | clauses.release (); |
13454 | types.release (); | |
a68ab351 JJ |
13455 | } |
13456 | ||
953ff289 | 13457 | |
acf0174b JJ |
13458 | /* OpenMP 4.0 |
13459 | #pragma omp declare simd declare-simd-clauses[optseq] new-line | |
13460 | #pragma omp declare reduction (reduction-id : typename-list : expression) \ | |
13461 | initializer-clause[opt] new-line | |
13462 | #pragma omp declare target new-line */ | |
20906c66 JJ |
13463 | |
13464 | static void | |
acf0174b | 13465 | c_parser_omp_declare (c_parser *parser, enum pragma_context context) |
20906c66 | 13466 | { |
20906c66 | 13467 | c_parser_consume_pragma (parser); |
acf0174b JJ |
13468 | if (c_parser_next_token_is (parser, CPP_NAME)) |
13469 | { | |
13470 | const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); | |
13471 | if (strcmp (p, "simd") == 0) | |
13472 | { | |
13473 | /* c_parser_consume_token (parser); done in | |
13474 | c_parser_omp_declare_simd. */ | |
13475 | c_parser_omp_declare_simd (parser, context); | |
13476 | return; | |
13477 | } | |
13478 | if (strcmp (p, "reduction") == 0) | |
13479 | { | |
13480 | c_parser_consume_token (parser); | |
13481 | c_parser_omp_declare_reduction (parser, context); | |
13482 | return; | |
13483 | } | |
6d7f7e0a TB |
13484 | if (!flag_openmp) /* flag_openmp_simd */ |
13485 | { | |
13486 | c_parser_skip_to_pragma_eol (parser); | |
13487 | return; | |
13488 | } | |
acf0174b JJ |
13489 | if (strcmp (p, "target") == 0) |
13490 | { | |
13491 | c_parser_consume_token (parser); | |
13492 | c_parser_omp_declare_target (parser); | |
13493 | return; | |
13494 | } | |
13495 | } | |
20906c66 | 13496 | |
acf0174b JJ |
13497 | c_parser_error (parser, "expected %<simd%> or %<reduction%> " |
13498 | "or %<target%>"); | |
13499 | c_parser_skip_to_pragma_eol (parser); | |
20906c66 JJ |
13500 | } |
13501 | ||
953ff289 DN |
13502 | /* Main entry point to parsing most OpenMP pragmas. */ |
13503 | ||
13504 | static void | |
13505 | c_parser_omp_construct (c_parser *parser) | |
13506 | { | |
13507 | enum pragma_kind p_kind; | |
13508 | location_t loc; | |
13509 | tree stmt; | |
acf0174b JJ |
13510 | char p_name[sizeof "#pragma omp teams distribute parallel for simd"]; |
13511 | omp_clause_mask mask (0); | |
953ff289 DN |
13512 | |
13513 | loc = c_parser_peek_token (parser)->location; | |
13514 | p_kind = c_parser_peek_token (parser)->pragma_kind; | |
13515 | c_parser_consume_pragma (parser); | |
13516 | ||
13517 | switch (p_kind) | |
13518 | { | |
13519 | case PRAGMA_OMP_ATOMIC: | |
c2255bc4 | 13520 | c_parser_omp_atomic (loc, parser); |
953ff289 DN |
13521 | return; |
13522 | case PRAGMA_OMP_CRITICAL: | |
c2255bc4 | 13523 | stmt = c_parser_omp_critical (loc, parser); |
953ff289 | 13524 | break; |
acf0174b JJ |
13525 | case PRAGMA_OMP_DISTRIBUTE: |
13526 | strcpy (p_name, "#pragma omp"); | |
13527 | stmt = c_parser_omp_distribute (loc, parser, p_name, mask, NULL); | |
13528 | break; | |
953ff289 | 13529 | case PRAGMA_OMP_FOR: |
acf0174b JJ |
13530 | strcpy (p_name, "#pragma omp"); |
13531 | stmt = c_parser_omp_for (loc, parser, p_name, mask, NULL); | |
953ff289 DN |
13532 | break; |
13533 | case PRAGMA_OMP_MASTER: | |
c2255bc4 | 13534 | stmt = c_parser_omp_master (loc, parser); |
953ff289 DN |
13535 | break; |
13536 | case PRAGMA_OMP_ORDERED: | |
c2255bc4 | 13537 | stmt = c_parser_omp_ordered (loc, parser); |
953ff289 DN |
13538 | break; |
13539 | case PRAGMA_OMP_PARALLEL: | |
acf0174b JJ |
13540 | strcpy (p_name, "#pragma omp"); |
13541 | stmt = c_parser_omp_parallel (loc, parser, p_name, mask, NULL); | |
953ff289 DN |
13542 | break; |
13543 | case PRAGMA_OMP_SECTIONS: | |
acf0174b JJ |
13544 | strcpy (p_name, "#pragma omp"); |
13545 | stmt = c_parser_omp_sections (loc, parser, p_name, mask, NULL); | |
13546 | break; | |
13547 | case PRAGMA_OMP_SIMD: | |
13548 | strcpy (p_name, "#pragma omp"); | |
13549 | stmt = c_parser_omp_simd (loc, parser, p_name, mask, NULL); | |
953ff289 DN |
13550 | break; |
13551 | case PRAGMA_OMP_SINGLE: | |
c2255bc4 | 13552 | stmt = c_parser_omp_single (loc, parser); |
953ff289 | 13553 | break; |
a68ab351 | 13554 | case PRAGMA_OMP_TASK: |
c2255bc4 | 13555 | stmt = c_parser_omp_task (loc, parser); |
a68ab351 | 13556 | break; |
acf0174b JJ |
13557 | case PRAGMA_OMP_TASKGROUP: |
13558 | stmt = c_parser_omp_taskgroup (parser); | |
13559 | break; | |
13560 | case PRAGMA_OMP_TEAMS: | |
13561 | strcpy (p_name, "#pragma omp"); | |
13562 | stmt = c_parser_omp_teams (loc, parser, p_name, mask, NULL); | |
13563 | break; | |
953ff289 DN |
13564 | default: |
13565 | gcc_unreachable (); | |
13566 | } | |
13567 | ||
13568 | if (stmt) | |
c2255bc4 | 13569 | gcc_assert (EXPR_LOCATION (stmt) != UNKNOWN_LOCATION); |
953ff289 DN |
13570 | } |
13571 | ||
13572 | ||
13573 | /* OpenMP 2.5: | |
13574 | # pragma omp threadprivate (variable-list) */ | |
13575 | ||
13576 | static void | |
13577 | c_parser_omp_threadprivate (c_parser *parser) | |
13578 | { | |
13579 | tree vars, t; | |
c2255bc4 | 13580 | location_t loc; |
953ff289 DN |
13581 | |
13582 | c_parser_consume_pragma (parser); | |
c2255bc4 | 13583 | loc = c_parser_peek_token (parser)->location; |
d75d71e0 | 13584 | vars = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL); |
953ff289 | 13585 | |
953ff289 DN |
13586 | /* Mark every variable in VARS to be assigned thread local storage. */ |
13587 | for (t = vars; t; t = TREE_CHAIN (t)) | |
13588 | { | |
13589 | tree v = TREE_PURPOSE (t); | |
13590 | ||
c2255bc4 AH |
13591 | /* FIXME diagnostics: Ideally we should keep individual |
13592 | locations for all the variables in the var list to make the | |
13593 | following errors more precise. Perhaps | |
13594 | c_parser_omp_var_list_parens() should construct a list of | |
13595 | locations to go along with the var list. */ | |
13596 | ||
953ff289 DN |
13597 | /* If V had already been marked threadprivate, it doesn't matter |
13598 | whether it had been used prior to this point. */ | |
5df27e4a | 13599 | if (TREE_CODE (v) != VAR_DECL) |
c2255bc4 | 13600 | error_at (loc, "%qD is not a variable", v); |
5df27e4a | 13601 | else if (TREE_USED (v) && !C_DECL_THREADPRIVATE_P (v)) |
c2255bc4 | 13602 | error_at (loc, "%qE declared %<threadprivate%> after first use", v); |
953ff289 | 13603 | else if (! TREE_STATIC (v) && ! DECL_EXTERNAL (v)) |
c2255bc4 | 13604 | error_at (loc, "automatic variable %qE cannot be %<threadprivate%>", v); |
5df27e4a JJ |
13605 | else if (TREE_TYPE (v) == error_mark_node) |
13606 | ; | |
953ff289 | 13607 | else if (! COMPLETE_TYPE_P (TREE_TYPE (v))) |
c2255bc4 | 13608 | error_at (loc, "%<threadprivate%> %qE has incomplete type", v); |
953ff289 DN |
13609 | else |
13610 | { | |
13611 | if (! DECL_THREAD_LOCAL_P (v)) | |
13612 | { | |
56363ffd | 13613 | set_decl_tls_model (v, decl_default_tls_model (v)); |
953ff289 DN |
13614 | /* If rtl has been already set for this var, call |
13615 | make_decl_rtl once again, so that encode_section_info | |
13616 | has a chance to look at the new decl flags. */ | |
13617 | if (DECL_RTL_SET_P (v)) | |
13618 | make_decl_rtl (v); | |
13619 | } | |
13620 | C_DECL_THREADPRIVATE_P (v) = 1; | |
13621 | } | |
13622 | } | |
13623 | ||
13624 | c_parser_skip_to_pragma_eol (parser); | |
13625 | } | |
c02065fc AH |
13626 | \f |
13627 | /* Cilk Plus <#pragma simd> parsing routines. */ | |
13628 | ||
13629 | /* Helper function for c_parser_pragma. Perform some sanity checking | |
13630 | for <#pragma simd> constructs. Returns FALSE if there was a | |
13631 | problem. */ | |
13632 | ||
13633 | static bool | |
13634 | c_parser_cilk_verify_simd (c_parser *parser, | |
13635 | enum pragma_context context) | |
13636 | { | |
b72271b9 | 13637 | if (!flag_cilkplus) |
c02065fc AH |
13638 | { |
13639 | warning (0, "pragma simd ignored because -fcilkplus is not enabled"); | |
13640 | c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL); | |
13641 | return false; | |
13642 | } | |
13643 | if (context == pragma_external) | |
13644 | { | |
13645 | c_parser_error (parser,"pragma simd must be inside a function"); | |
13646 | c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL); | |
13647 | return false; | |
13648 | } | |
13649 | return true; | |
13650 | } | |
13651 | ||
13652 | /* Cilk Plus: | |
41958c28 BI |
13653 | This function is shared by SIMD-enabled functions and #pragma simd. |
13654 | If IS_SIMD_FN is true then it is parsing a SIMD-enabled function and | |
13655 | CLAUSES is unused. The main purpose of this function is to parse a | |
13656 | vectorlength attribute or clause and check for parse errors. | |
13657 | When IS_SIMD_FN is true then the function is merely caching the tokens | |
13658 | in PARSER->CILK_SIMD_FN_TOKENS. If errors are found then the token | |
13659 | cache is cleared since there is no reason to continue. | |
13660 | Syntax: | |
13661 | vectorlength ( constant-expression ) */ | |
c02065fc AH |
13662 | |
13663 | static tree | |
41958c28 BI |
13664 | c_parser_cilk_clause_vectorlength (c_parser *parser, tree clauses, |
13665 | bool is_simd_fn) | |
c02065fc | 13666 | { |
41958c28 BI |
13667 | if (is_simd_fn) |
13668 | check_no_duplicate_clause (clauses, OMP_CLAUSE_SIMDLEN, "vectorlength"); | |
13669 | else | |
c02065fc AH |
13670 | /* The vectorlength clause behaves exactly like OpenMP's safelen |
13671 | clause. Represent it in OpenMP terms. */ | |
41958c28 | 13672 | check_no_duplicate_clause (clauses, OMP_CLAUSE_SAFELEN, "vectorlength"); |
c02065fc AH |
13673 | |
13674 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
13675 | return clauses; | |
13676 | ||
13677 | location_t loc = c_parser_peek_token (parser)->location; | |
13678 | tree expr = c_parser_expr_no_commas (parser, NULL).value; | |
13679 | expr = c_fully_fold (expr, false, NULL); | |
13680 | ||
41958c28 BI |
13681 | /* If expr is an error_mark_node then the above function would have |
13682 | emitted an error. No reason to do it twice. */ | |
13683 | if (expr == error_mark_node) | |
13684 | ; | |
13685 | else if (!TREE_TYPE (expr) | |
13686 | || !TREE_CONSTANT (expr) | |
13687 | || !INTEGRAL_TYPE_P (TREE_TYPE (expr))) | |
13688 | ||
13689 | error_at (loc, "vectorlength must be an integer constant"); | |
807e902e | 13690 | else if (wi::exact_log2 (expr) == -1) |
c02065fc AH |
13691 | error_at (loc, "vectorlength must be a power of 2"); |
13692 | else | |
13693 | { | |
41958c28 BI |
13694 | if (is_simd_fn) |
13695 | { | |
13696 | tree u = build_omp_clause (loc, OMP_CLAUSE_SIMDLEN); | |
13697 | OMP_CLAUSE_SIMDLEN_EXPR (u) = expr; | |
13698 | OMP_CLAUSE_CHAIN (u) = clauses; | |
13699 | clauses = u; | |
13700 | } | |
13701 | else | |
13702 | { | |
13703 | tree u = build_omp_clause (loc, OMP_CLAUSE_SAFELEN); | |
13704 | OMP_CLAUSE_SAFELEN_EXPR (u) = expr; | |
13705 | OMP_CLAUSE_CHAIN (u) = clauses; | |
13706 | clauses = u; | |
13707 | } | |
c02065fc AH |
13708 | } |
13709 | ||
13710 | c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
13711 | ||
13712 | return clauses; | |
13713 | } | |
13714 | ||
13715 | /* Cilk Plus: | |
13716 | linear ( simd-linear-variable-list ) | |
13717 | ||
13718 | simd-linear-variable-list: | |
13719 | simd-linear-variable | |
13720 | simd-linear-variable-list , simd-linear-variable | |
13721 | ||
13722 | simd-linear-variable: | |
13723 | id-expression | |
13724 | id-expression : simd-linear-step | |
13725 | ||
13726 | simd-linear-step: | |
13727 | conditional-expression */ | |
13728 | ||
13729 | static tree | |
13730 | c_parser_cilk_clause_linear (c_parser *parser, tree clauses) | |
13731 | { | |
13732 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
13733 | return clauses; | |
13734 | ||
13735 | location_t loc = c_parser_peek_token (parser)->location; | |
13736 | ||
13737 | if (c_parser_next_token_is_not (parser, CPP_NAME) | |
13738 | || c_parser_peek_token (parser)->id_kind != C_ID_ID) | |
13739 | c_parser_error (parser, "expected identifier"); | |
13740 | ||
13741 | while (c_parser_next_token_is (parser, CPP_NAME) | |
13742 | && c_parser_peek_token (parser)->id_kind == C_ID_ID) | |
13743 | { | |
13744 | tree var = lookup_name (c_parser_peek_token (parser)->value); | |
13745 | ||
13746 | if (var == NULL) | |
13747 | { | |
13748 | undeclared_variable (c_parser_peek_token (parser)->location, | |
13749 | c_parser_peek_token (parser)->value); | |
13750 | c_parser_consume_token (parser); | |
13751 | } | |
13752 | else if (var == error_mark_node) | |
13753 | c_parser_consume_token (parser); | |
13754 | else | |
13755 | { | |
13756 | tree step = integer_one_node; | |
13757 | ||
13758 | /* Parse the linear step if present. */ | |
13759 | if (c_parser_peek_2nd_token (parser)->type == CPP_COLON) | |
13760 | { | |
13761 | c_parser_consume_token (parser); | |
13762 | c_parser_consume_token (parser); | |
13763 | ||
13764 | tree expr = c_parser_expr_no_commas (parser, NULL).value; | |
13765 | expr = c_fully_fold (expr, false, NULL); | |
13766 | ||
13767 | if (TREE_TYPE (expr) | |
13768 | && INTEGRAL_TYPE_P (TREE_TYPE (expr)) | |
13769 | && (TREE_CONSTANT (expr) | |
13770 | || DECL_P (expr))) | |
13771 | step = expr; | |
13772 | else | |
13773 | c_parser_error (parser, | |
13774 | "step size must be an integer constant " | |
13775 | "expression or an integer variable"); | |
13776 | } | |
13777 | else | |
13778 | c_parser_consume_token (parser); | |
13779 | ||
13780 | /* Use OMP_CLAUSE_LINEAR, which has the same semantics. */ | |
13781 | tree u = build_omp_clause (loc, OMP_CLAUSE_LINEAR); | |
13782 | OMP_CLAUSE_DECL (u) = var; | |
13783 | OMP_CLAUSE_LINEAR_STEP (u) = step; | |
13784 | OMP_CLAUSE_CHAIN (u) = clauses; | |
13785 | clauses = u; | |
13786 | } | |
13787 | ||
13788 | if (c_parser_next_token_is_not (parser, CPP_COMMA)) | |
13789 | break; | |
13790 | ||
13791 | c_parser_consume_token (parser); | |
13792 | } | |
13793 | ||
13794 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
13795 | ||
13796 | return clauses; | |
13797 | } | |
13798 | ||
13799 | /* Returns the name of the next clause. If the clause is not | |
13800 | recognized SIMD_OMP_CLAUSE_NONE is returned and the next token is | |
13801 | not consumed. Otherwise, the appropriate pragma_simd_clause is | |
13802 | returned and the token is consumed. */ | |
13803 | ||
41958c28 | 13804 | static pragma_omp_clause |
c02065fc AH |
13805 | c_parser_cilk_clause_name (c_parser *parser) |
13806 | { | |
41958c28 | 13807 | pragma_omp_clause result; |
c02065fc AH |
13808 | c_token *token = c_parser_peek_token (parser); |
13809 | ||
13810 | if (!token->value || token->type != CPP_NAME) | |
13811 | return PRAGMA_CILK_CLAUSE_NONE; | |
13812 | ||
13813 | const char *p = IDENTIFIER_POINTER (token->value); | |
13814 | ||
13815 | if (!strcmp (p, "vectorlength")) | |
13816 | result = PRAGMA_CILK_CLAUSE_VECTORLENGTH; | |
13817 | else if (!strcmp (p, "linear")) | |
13818 | result = PRAGMA_CILK_CLAUSE_LINEAR; | |
13819 | else if (!strcmp (p, "private")) | |
13820 | result = PRAGMA_CILK_CLAUSE_PRIVATE; | |
13821 | else if (!strcmp (p, "firstprivate")) | |
13822 | result = PRAGMA_CILK_CLAUSE_FIRSTPRIVATE; | |
13823 | else if (!strcmp (p, "lastprivate")) | |
13824 | result = PRAGMA_CILK_CLAUSE_LASTPRIVATE; | |
13825 | else if (!strcmp (p, "reduction")) | |
13826 | result = PRAGMA_CILK_CLAUSE_REDUCTION; | |
13827 | else | |
13828 | return PRAGMA_CILK_CLAUSE_NONE; | |
13829 | ||
13830 | c_parser_consume_token (parser); | |
13831 | return result; | |
13832 | } | |
13833 | ||
13834 | /* Parse all #<pragma simd> clauses. Return the list of clauses | |
13835 | found. */ | |
13836 | ||
13837 | static tree | |
13838 | c_parser_cilk_all_clauses (c_parser *parser) | |
13839 | { | |
13840 | tree clauses = NULL; | |
13841 | ||
13842 | while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL)) | |
13843 | { | |
41958c28 | 13844 | pragma_omp_clause c_kind; |
c02065fc AH |
13845 | |
13846 | c_kind = c_parser_cilk_clause_name (parser); | |
13847 | ||
13848 | switch (c_kind) | |
13849 | { | |
13850 | case PRAGMA_CILK_CLAUSE_VECTORLENGTH: | |
41958c28 | 13851 | clauses = c_parser_cilk_clause_vectorlength (parser, clauses, false); |
c02065fc AH |
13852 | break; |
13853 | case PRAGMA_CILK_CLAUSE_LINEAR: | |
13854 | clauses = c_parser_cilk_clause_linear (parser, clauses); | |
13855 | break; | |
13856 | case PRAGMA_CILK_CLAUSE_PRIVATE: | |
13857 | /* Use the OpenMP counterpart. */ | |
13858 | clauses = c_parser_omp_clause_private (parser, clauses); | |
13859 | break; | |
13860 | case PRAGMA_CILK_CLAUSE_FIRSTPRIVATE: | |
13861 | /* Use the OpenMP counterpart. */ | |
13862 | clauses = c_parser_omp_clause_firstprivate (parser, clauses); | |
13863 | break; | |
13864 | case PRAGMA_CILK_CLAUSE_LASTPRIVATE: | |
13865 | /* Use the OpenMP counterpart. */ | |
13866 | clauses = c_parser_omp_clause_lastprivate (parser, clauses); | |
13867 | break; | |
13868 | case PRAGMA_CILK_CLAUSE_REDUCTION: | |
13869 | /* Use the OpenMP counterpart. */ | |
13870 | clauses = c_parser_omp_clause_reduction (parser, clauses); | |
13871 | break; | |
13872 | default: | |
13873 | c_parser_error (parser, "expected %<#pragma simd%> clause"); | |
13874 | goto saw_error; | |
13875 | } | |
13876 | } | |
13877 | ||
13878 | saw_error: | |
13879 | c_parser_skip_to_pragma_eol (parser); | |
13880 | return c_finish_cilk_clauses (clauses); | |
13881 | } | |
13882 | ||
13883 | /* Main entry point for parsing Cilk Plus <#pragma simd> for | |
13884 | loops. */ | |
953ff289 | 13885 | |
c02065fc | 13886 | static void |
e7bd1de1 | 13887 | c_parser_cilk_simd (c_parser *parser) |
c02065fc | 13888 | { |
c02065fc AH |
13889 | tree clauses = c_parser_cilk_all_clauses (parser); |
13890 | tree block = c_begin_compound_stmt (true); | |
13891 | location_t loc = c_parser_peek_token (parser)->location; | |
13892 | c_parser_omp_for_loop (loc, parser, CILK_SIMD, clauses, NULL); | |
13893 | block = c_end_compound_stmt (loc, block, true); | |
13894 | add_stmt (block); | |
13895 | } | |
13896 | \f | |
0a35513e AH |
13897 | /* Parse a transaction attribute (GCC Extension). |
13898 | ||
13899 | transaction-attribute: | |
13900 | attributes | |
13901 | [ [ any-word ] ] | |
13902 | ||
13903 | The transactional memory language description is written for C++, | |
13904 | and uses the C++0x attribute syntax. For compatibility, allow the | |
13905 | bracket style for transactions in C as well. */ | |
13906 | ||
13907 | static tree | |
13908 | c_parser_transaction_attributes (c_parser *parser) | |
13909 | { | |
13910 | tree attr_name, attr = NULL; | |
13911 | ||
13912 | if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)) | |
13913 | return c_parser_attributes (parser); | |
13914 | ||
13915 | if (!c_parser_next_token_is (parser, CPP_OPEN_SQUARE)) | |
13916 | return NULL_TREE; | |
13917 | c_parser_consume_token (parser); | |
13918 | if (!c_parser_require (parser, CPP_OPEN_SQUARE, "expected %<[%>")) | |
13919 | goto error1; | |
13920 | ||
13921 | attr_name = c_parser_attribute_any_word (parser); | |
13922 | if (attr_name) | |
13923 | { | |
13924 | c_parser_consume_token (parser); | |
13925 | attr = build_tree_list (attr_name, NULL_TREE); | |
13926 | } | |
13927 | else | |
13928 | c_parser_error (parser, "expected identifier"); | |
13929 | ||
13930 | c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, "expected %<]%>"); | |
13931 | error1: | |
13932 | c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, "expected %<]%>"); | |
13933 | return attr; | |
13934 | } | |
13935 | ||
13936 | /* Parse a __transaction_atomic or __transaction_relaxed statement | |
13937 | (GCC Extension). | |
13938 | ||
13939 | transaction-statement: | |
13940 | __transaction_atomic transaction-attribute[opt] compound-statement | |
13941 | __transaction_relaxed compound-statement | |
13942 | ||
13943 | Note that the only valid attribute is: "outer". | |
13944 | */ | |
13945 | ||
13946 | static tree | |
13947 | c_parser_transaction (c_parser *parser, enum rid keyword) | |
13948 | { | |
13949 | unsigned int old_in = parser->in_transaction; | |
13950 | unsigned int this_in = 1, new_in; | |
13951 | location_t loc = c_parser_peek_token (parser)->location; | |
13952 | tree stmt, attrs; | |
13953 | ||
13954 | gcc_assert ((keyword == RID_TRANSACTION_ATOMIC | |
13955 | || keyword == RID_TRANSACTION_RELAXED) | |
13956 | && c_parser_next_token_is_keyword (parser, keyword)); | |
13957 | c_parser_consume_token (parser); | |
13958 | ||
13959 | if (keyword == RID_TRANSACTION_RELAXED) | |
13960 | this_in |= TM_STMT_ATTR_RELAXED; | |
13961 | else | |
13962 | { | |
13963 | attrs = c_parser_transaction_attributes (parser); | |
13964 | if (attrs) | |
13965 | this_in |= parse_tm_stmt_attr (attrs, TM_STMT_ATTR_OUTER); | |
13966 | } | |
13967 | ||
13968 | /* Keep track if we're in the lexical scope of an outer transaction. */ | |
13969 | new_in = this_in | (old_in & TM_STMT_ATTR_OUTER); | |
13970 | ||
13971 | parser->in_transaction = new_in; | |
13972 | stmt = c_parser_compound_statement (parser); | |
13973 | parser->in_transaction = old_in; | |
13974 | ||
13975 | if (flag_tm) | |
13976 | stmt = c_finish_transaction (loc, stmt, this_in); | |
13977 | else | |
13978 | error_at (loc, (keyword == RID_TRANSACTION_ATOMIC ? | |
13979 | "%<__transaction_atomic%> without transactional memory support enabled" | |
13980 | : "%<__transaction_relaxed %> " | |
13981 | "without transactional memory support enabled")); | |
13982 | ||
13983 | return stmt; | |
13984 | } | |
13985 | ||
13986 | /* Parse a __transaction_atomic or __transaction_relaxed expression | |
13987 | (GCC Extension). | |
13988 | ||
13989 | transaction-expression: | |
13990 | __transaction_atomic ( expression ) | |
13991 | __transaction_relaxed ( expression ) | |
13992 | */ | |
13993 | ||
13994 | static struct c_expr | |
13995 | c_parser_transaction_expression (c_parser *parser, enum rid keyword) | |
13996 | { | |
13997 | struct c_expr ret; | |
13998 | unsigned int old_in = parser->in_transaction; | |
13999 | unsigned int this_in = 1; | |
14000 | location_t loc = c_parser_peek_token (parser)->location; | |
14001 | tree attrs; | |
14002 | ||
14003 | gcc_assert ((keyword == RID_TRANSACTION_ATOMIC | |
14004 | || keyword == RID_TRANSACTION_RELAXED) | |
14005 | && c_parser_next_token_is_keyword (parser, keyword)); | |
14006 | c_parser_consume_token (parser); | |
14007 | ||
14008 | if (keyword == RID_TRANSACTION_RELAXED) | |
14009 | this_in |= TM_STMT_ATTR_RELAXED; | |
14010 | else | |
14011 | { | |
14012 | attrs = c_parser_transaction_attributes (parser); | |
14013 | if (attrs) | |
14014 | this_in |= parse_tm_stmt_attr (attrs, 0); | |
14015 | } | |
14016 | ||
14017 | parser->in_transaction = this_in; | |
69b76518 | 14018 | if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) |
0a35513e AH |
14019 | { |
14020 | tree expr = c_parser_expression (parser).value; | |
14021 | ret.original_type = TREE_TYPE (expr); | |
14022 | ret.value = build1 (TRANSACTION_EXPR, ret.original_type, expr); | |
14023 | if (this_in & TM_STMT_ATTR_RELAXED) | |
14024 | TRANSACTION_EXPR_RELAXED (ret.value) = 1; | |
14025 | SET_EXPR_LOCATION (ret.value, loc); | |
14026 | ret.original_code = TRANSACTION_EXPR; | |
69b76518 TR |
14027 | if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>")) |
14028 | { | |
14029 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); | |
14030 | goto error; | |
14031 | } | |
0a35513e AH |
14032 | } |
14033 | else | |
14034 | { | |
69b76518 | 14035 | error: |
0a35513e AH |
14036 | ret.value = error_mark_node; |
14037 | ret.original_code = ERROR_MARK; | |
14038 | ret.original_type = NULL; | |
14039 | } | |
14040 | parser->in_transaction = old_in; | |
14041 | ||
14042 | if (!flag_tm) | |
14043 | error_at (loc, (keyword == RID_TRANSACTION_ATOMIC ? | |
14044 | "%<__transaction_atomic%> without transactional memory support enabled" | |
14045 | : "%<__transaction_relaxed %> " | |
14046 | "without transactional memory support enabled")); | |
14047 | ||
14048 | return ret; | |
14049 | } | |
14050 | ||
14051 | /* Parse a __transaction_cancel statement (GCC Extension). | |
14052 | ||
14053 | transaction-cancel-statement: | |
14054 | __transaction_cancel transaction-attribute[opt] ; | |
14055 | ||
14056 | Note that the only valid attribute is "outer". | |
14057 | */ | |
14058 | ||
14059 | static tree | |
acf0174b | 14060 | c_parser_transaction_cancel (c_parser *parser) |
0a35513e AH |
14061 | { |
14062 | location_t loc = c_parser_peek_token (parser)->location; | |
14063 | tree attrs; | |
14064 | bool is_outer = false; | |
14065 | ||
14066 | gcc_assert (c_parser_next_token_is_keyword (parser, RID_TRANSACTION_CANCEL)); | |
14067 | c_parser_consume_token (parser); | |
14068 | ||
14069 | attrs = c_parser_transaction_attributes (parser); | |
14070 | if (attrs) | |
14071 | is_outer = (parse_tm_stmt_attr (attrs, TM_STMT_ATTR_OUTER) != 0); | |
14072 | ||
14073 | if (!flag_tm) | |
14074 | { | |
14075 | error_at (loc, "%<__transaction_cancel%> without " | |
14076 | "transactional memory support enabled"); | |
14077 | goto ret_error; | |
14078 | } | |
14079 | else if (parser->in_transaction & TM_STMT_ATTR_RELAXED) | |
14080 | { | |
14081 | error_at (loc, "%<__transaction_cancel%> within a " | |
14082 | "%<__transaction_relaxed%>"); | |
14083 | goto ret_error; | |
14084 | } | |
14085 | else if (is_outer) | |
14086 | { | |
14087 | if ((parser->in_transaction & TM_STMT_ATTR_OUTER) == 0 | |
14088 | && !is_tm_may_cancel_outer (current_function_decl)) | |
14089 | { | |
14090 | error_at (loc, "outer %<__transaction_cancel%> not " | |
14091 | "within outer %<__transaction_atomic%>"); | |
14092 | error_at (loc, " or a %<transaction_may_cancel_outer%> function"); | |
14093 | goto ret_error; | |
14094 | } | |
14095 | } | |
14096 | else if (parser->in_transaction == 0) | |
14097 | { | |
14098 | error_at (loc, "%<__transaction_cancel%> not within " | |
14099 | "%<__transaction_atomic%>"); | |
14100 | goto ret_error; | |
14101 | } | |
14102 | ||
14103 | return add_stmt (build_tm_abort_call (loc, is_outer)); | |
14104 | ||
14105 | ret_error: | |
14106 | return build1 (NOP_EXPR, void_type_node, error_mark_node); | |
14107 | } | |
bc4071dd | 14108 | \f |
27bf414c JM |
14109 | /* Parse a single source file. */ |
14110 | ||
14111 | void | |
14112 | c_parse_file (void) | |
14113 | { | |
bc4071dd RH |
14114 | /* Use local storage to begin. If the first token is a pragma, parse it. |
14115 | If it is #pragma GCC pch_preprocess, then this will load a PCH file | |
14116 | which will cause garbage collection. */ | |
14117 | c_parser tparser; | |
14118 | ||
14119 | memset (&tparser, 0, sizeof tparser); | |
acf0174b | 14120 | tparser.tokens = &tparser.tokens_buf[0]; |
bc4071dd RH |
14121 | the_parser = &tparser; |
14122 | ||
14123 | if (c_parser_peek_token (&tparser)->pragma_kind == PRAGMA_GCC_PCH_PREPROCESS) | |
14124 | c_parser_pragma_pch_preprocess (&tparser); | |
14125 | ||
766090c2 | 14126 | the_parser = ggc_alloc<c_parser> (); |
bc4071dd | 14127 | *the_parser = tparser; |
acf0174b JJ |
14128 | if (tparser.tokens == &tparser.tokens_buf[0]) |
14129 | the_parser->tokens = &the_parser->tokens_buf[0]; | |
bc4071dd | 14130 | |
f9417da1 RG |
14131 | /* Initialize EH, if we've been told to do so. */ |
14132 | if (flag_exceptions) | |
1d65f45c | 14133 | using_eh_for_cleanups (); |
f9417da1 | 14134 | |
27bf414c JM |
14135 | c_parser_translation_unit (the_parser); |
14136 | the_parser = NULL; | |
14137 | } | |
14138 | ||
36536d79 BI |
14139 | /* This function parses Cilk Plus array notation. The starting index is |
14140 | passed in INITIAL_INDEX and the array name is passes in ARRAY_VALUE. The | |
14141 | return value of this function is a tree_node called VALUE_TREE of type | |
14142 | ARRAY_NOTATION_REF. */ | |
14143 | ||
14144 | static tree | |
14145 | c_parser_array_notation (location_t loc, c_parser *parser, tree initial_index, | |
14146 | tree array_value) | |
14147 | { | |
14148 | c_token *token = NULL; | |
14149 | tree start_index = NULL_TREE, end_index = NULL_TREE, stride = NULL_TREE; | |
14150 | tree value_tree = NULL_TREE, type = NULL_TREE, array_type = NULL_TREE; | |
14151 | tree array_type_domain = NULL_TREE; | |
14152 | ||
5e88a8f4 | 14153 | if (array_value == error_mark_node || initial_index == error_mark_node) |
36536d79 BI |
14154 | { |
14155 | /* No need to continue. If either of these 2 were true, then an error | |
14156 | must be emitted already. Thus, no need to emit them twice. */ | |
14157 | c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL); | |
14158 | return error_mark_node; | |
14159 | } | |
14160 | ||
14161 | array_type = TREE_TYPE (array_value); | |
14162 | gcc_assert (array_type); | |
14163 | type = TREE_TYPE (array_type); | |
14164 | token = c_parser_peek_token (parser); | |
14165 | ||
14166 | if (token->type == CPP_EOF) | |
14167 | { | |
14168 | c_parser_error (parser, "expected %<:%> or numeral"); | |
14169 | return value_tree; | |
14170 | } | |
14171 | else if (token->type == CPP_COLON) | |
14172 | { | |
14173 | if (!initial_index) | |
14174 | { | |
14175 | /* If we are here, then we have a case like this A[:]. */ | |
14176 | c_parser_consume_token (parser); | |
14177 | if (TREE_CODE (array_type) == POINTER_TYPE) | |
14178 | { | |
14179 | error_at (loc, "start-index and length fields necessary for " | |
14180 | "using array notations in pointers"); | |
14181 | c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL); | |
14182 | return error_mark_node; | |
14183 | } | |
14184 | if (TREE_CODE (array_type) == FUNCTION_TYPE) | |
14185 | { | |
14186 | error_at (loc, "array notations cannot be used with function " | |
14187 | "type"); | |
14188 | c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL); | |
14189 | return error_mark_node; | |
14190 | } | |
36536d79 BI |
14191 | array_type_domain = TYPE_DOMAIN (array_type); |
14192 | ||
14193 | if (!array_type_domain) | |
14194 | { | |
14195 | error_at (loc, "start-index and length fields necessary for " | |
14196 | "using array notations in dimensionless arrays"); | |
14197 | c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL); | |
14198 | return error_mark_node; | |
14199 | } | |
14200 | ||
14201 | start_index = TYPE_MINVAL (array_type_domain); | |
14202 | start_index = fold_build1 (CONVERT_EXPR, ptrdiff_type_node, | |
14203 | start_index); | |
14204 | if (!TYPE_MAXVAL (array_type_domain) | |
14205 | || !TREE_CONSTANT (TYPE_MAXVAL (array_type_domain))) | |
14206 | { | |
14207 | error_at (loc, "start-index and length fields necessary for " | |
14208 | "using array notations in variable-length arrays"); | |
14209 | c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL); | |
14210 | return error_mark_node; | |
14211 | } | |
14212 | end_index = TYPE_MAXVAL (array_type_domain); | |
14213 | end_index = fold_build2 (PLUS_EXPR, TREE_TYPE (end_index), | |
14214 | end_index, integer_one_node); | |
14215 | end_index = fold_build1 (CONVERT_EXPR, ptrdiff_type_node, end_index); | |
14216 | stride = build_int_cst (integer_type_node, 1); | |
14217 | stride = fold_build1 (CONVERT_EXPR, ptrdiff_type_node, stride); | |
14218 | } | |
14219 | else if (initial_index != error_mark_node) | |
14220 | { | |
14221 | /* If we are here, then there should be 2 possibilities: | |
14222 | 1. Array [EXPR : EXPR] | |
14223 | 2. Array [EXPR : EXPR : EXPR] | |
14224 | */ | |
14225 | start_index = initial_index; | |
14226 | ||
14227 | if (TREE_CODE (array_type) == FUNCTION_TYPE) | |
14228 | { | |
14229 | error_at (loc, "array notations cannot be used with function " | |
14230 | "type"); | |
14231 | c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL); | |
14232 | return error_mark_node; | |
14233 | } | |
36536d79 | 14234 | c_parser_consume_token (parser); /* consume the ':' */ |
267bac10 JM |
14235 | struct c_expr ce = c_parser_expression (parser); |
14236 | ce = convert_lvalue_to_rvalue (loc, ce, false, false); | |
14237 | end_index = ce.value; | |
36536d79 BI |
14238 | if (!end_index || end_index == error_mark_node) |
14239 | { | |
14240 | c_parser_skip_to_end_of_block_or_statement (parser); | |
14241 | return error_mark_node; | |
14242 | } | |
14243 | if (c_parser_peek_token (parser)->type == CPP_COLON) | |
14244 | { | |
14245 | c_parser_consume_token (parser); | |
267bac10 JM |
14246 | ce = c_parser_expression (parser); |
14247 | ce = convert_lvalue_to_rvalue (loc, ce, false, false); | |
14248 | stride = ce.value; | |
36536d79 BI |
14249 | if (!stride || stride == error_mark_node) |
14250 | { | |
14251 | c_parser_skip_to_end_of_block_or_statement (parser); | |
14252 | return error_mark_node; | |
14253 | } | |
14254 | } | |
14255 | } | |
14256 | else | |
14257 | c_parser_error (parser, "expected array notation expression"); | |
14258 | } | |
14259 | else | |
14260 | c_parser_error (parser, "expected array notation expression"); | |
14261 | ||
14262 | c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, "expected %<]%>"); | |
14263 | ||
14264 | value_tree = build_array_notation_ref (loc, array_value, start_index, | |
14265 | end_index, stride, type); | |
14266 | if (value_tree != error_mark_node) | |
14267 | SET_EXPR_LOCATION (value_tree, loc); | |
14268 | return value_tree; | |
14269 | } | |
14270 | ||
d4a10d0a | 14271 | #include "gt-c-c-parser.h" |