]>
Commit | Line | Data |
---|---|---|
1576dec7 | 1 | /* Parser for C and Objective-C. |
d353bf18 | 2 | Copyright (C) 1987-2015 Free Software Foundation, Inc. |
1576dec7 | 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 | |
8c4c00c1 | 11 | Software Foundation; either version 3, or (at your option) any later |
1576dec7 | 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 | |
8c4c00c1 | 20 | along with GCC; see the file COPYING3. If not see |
21 | <http://www.gnu.org/licenses/>. */ | |
1576dec7 | 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" | |
115133dd | 41 | #include "tm.h" /* For rtl.h: needs enum reg_class. */ |
b20a8bb4 | 42 | #include "hash-set.h" |
43 | #include "vec.h" | |
44 | #include "symtab.h" | |
45 | #include "input.h" | |
46 | #include "alias.h" | |
47 | #include "double-int.h" | |
48 | #include "machmode.h" | |
49 | #include "flags.h" | |
50 | #include "inchash.h" | |
1576dec7 | 51 | #include "tree.h" |
b20a8bb4 | 52 | #include "fold-const.h" |
9ed99284 | 53 | #include "stringpool.h" |
54 | #include "attribs.h" | |
55 | #include "stor-layout.h" | |
56 | #include "varasm.h" | |
57 | #include "trans-mem.h" | |
1576dec7 | 58 | #include "langhooks.h" |
59 | #include "input.h" | |
60 | #include "cpplib.h" | |
61 | #include "timevar.h" | |
7bedc3a0 | 62 | #include "c-family/c-pragma.h" |
1576dec7 | 63 | #include "c-tree.h" |
bc7bff74 | 64 | #include "c-lang.h" |
1576dec7 | 65 | #include "flags.h" |
1576dec7 | 66 | #include "ggc.h" |
7bedc3a0 | 67 | #include "c-family/c-common.h" |
6c536c4f | 68 | #include "c-family/c-objc.h" |
b75b98aa | 69 | #include "vec.h" |
70 | #include "target.h" | |
1140c305 | 71 | #include "hash-map.h" |
72 | #include "is-a.h" | |
73 | #include "plugin-api.h" | |
74 | #include "hashtab.h" | |
75 | #include "hash-set.h" | |
76 | #include "machmode.h" | |
77 | #include "hard-reg-set.h" | |
78 | #include "function.h" | |
79 | #include "ipa-ref.h" | |
56af936e | 80 | #include "cgraph.h" |
9227b6fc | 81 | #include "plugin.h" |
7740abd8 | 82 | #include "omp-low.h" |
f7715905 | 83 | #include "builtins.h" |
ca4c3545 | 84 | #include "gomp-constants.h" |
1576dec7 | 85 | |
86 | \f | |
1576dec7 | 87 | /* Initialization routine for this file. */ |
88 | ||
89 | void | |
90 | c_parse_init (void) | |
91 | { | |
92 | /* The only initialization required is of the reserved word | |
93 | identifiers. */ | |
94 | unsigned int i; | |
95 | tree id; | |
5c6e5756 | 96 | int mask = 0; |
1576dec7 | 97 | |
6d5d708e | 98 | /* Make sure RID_MAX hasn't grown past the 8 bits used to hold the keyword in |
99 | the c_token structure. */ | |
100 | gcc_assert (RID_MAX <= 255); | |
101 | ||
5c6e5756 | 102 | mask |= D_CXXONLY; |
103 | if (!flag_isoc99) | |
104 | mask |= D_C99; | |
105 | if (flag_no_asm) | |
106 | { | |
107 | mask |= D_ASM | D_EXT; | |
108 | if (!flag_isoc99) | |
109 | mask |= D_EXT89; | |
110 | } | |
1576dec7 | 111 | if (!c_dialect_objc ()) |
5c6e5756 | 112 | mask |= D_OBJC | D_CXX_OBJC; |
1576dec7 | 113 | |
25a27413 | 114 | ridpointers = ggc_cleared_vec_alloc<tree> ((int) RID_MAX); |
5c6e5756 | 115 | for (i = 0; i < num_c_common_reswords; i++) |
1576dec7 | 116 | { |
117 | /* If a keyword is disabled, do not enter it into the table | |
118 | and so create a canonical spelling that isn't a keyword. */ | |
5c6e5756 | 119 | if (c_common_reswords[i].disable & mask) |
120 | { | |
121 | if (warn_cxx_compat | |
122 | && (c_common_reswords[i].disable & D_CXXWARN)) | |
123 | { | |
124 | id = get_identifier (c_common_reswords[i].word); | |
125 | C_SET_RID_CODE (id, RID_CXX_COMPAT_WARN); | |
126 | C_IS_RESERVED_WORD (id) = 1; | |
127 | } | |
128 | continue; | |
129 | } | |
1576dec7 | 130 | |
5c6e5756 | 131 | id = get_identifier (c_common_reswords[i].word); |
132 | C_SET_RID_CODE (id, c_common_reswords[i].rid); | |
1576dec7 | 133 | C_IS_RESERVED_WORD (id) = 1; |
5c6e5756 | 134 | ridpointers [(int) c_common_reswords[i].rid] = id; |
1576dec7 | 135 | } |
9f75f026 | 136 | |
137 | for (i = 0; i < NUM_INT_N_ENTS; i++) | |
138 | { | |
139 | /* We always create the symbols but they aren't always supported. */ | |
140 | char name[50]; | |
141 | sprintf (name, "__int%d", int_n_data[i].bitsize); | |
76738f56 | 142 | id = get_identifier (name); |
9f75f026 | 143 | C_SET_RID_CODE (id, RID_FIRST_INT_N + i); |
144 | C_IS_RESERVED_WORD (id) = 1; | |
145 | } | |
1576dec7 | 146 | } |
147 | \f | |
148 | /* The C lexer intermediates between the lexer in cpplib and c-lex.c | |
149 | and the C parser. Unlike the C++ lexer, the parser structure | |
150 | stores the lexer information instead of using a separate structure. | |
151 | Identifiers are separated into ordinary identifiers, type names, | |
152 | keywords and some other Objective-C types of identifiers, and some | |
153 | look-ahead is maintained. | |
154 | ||
155 | ??? It might be a good idea to lex the whole file up front (as for | |
156 | C++). It would then be possible to share more of the C and C++ | |
157 | lexer code, if desired. */ | |
158 | ||
1576dec7 | 159 | /* More information about the type of a CPP_NAME token. */ |
160 | typedef enum c_id_kind { | |
161 | /* An ordinary identifier. */ | |
162 | C_ID_ID, | |
163 | /* An identifier declared as a typedef name. */ | |
164 | C_ID_TYPENAME, | |
165 | /* An identifier declared as an Objective-C class name. */ | |
166 | C_ID_CLASSNAME, | |
6d5d708e | 167 | /* An address space identifier. */ |
168 | C_ID_ADDRSPACE, | |
1576dec7 | 169 | /* Not an identifier. */ |
170 | C_ID_NONE | |
171 | } c_id_kind; | |
172 | ||
173 | /* A single C token after string literal concatenation and conversion | |
174 | of preprocessing tokens to tokens. */ | |
fb1e4f4a | 175 | typedef struct GTY (()) c_token { |
1576dec7 | 176 | /* The kind of token. */ |
177 | ENUM_BITFIELD (cpp_ttype) type : 8; | |
178 | /* If this token is a CPP_NAME, this value indicates whether also | |
179 | declared as some kind of type. Otherwise, it is C_ID_NONE. */ | |
180 | ENUM_BITFIELD (c_id_kind) id_kind : 8; | |
181 | /* If this token is a keyword, this value indicates which keyword. | |
182 | Otherwise, this value is RID_MAX. */ | |
183 | ENUM_BITFIELD (rid) keyword : 8; | |
b75b98aa | 184 | /* If this token is a CPP_PRAGMA, this indicates the pragma that |
185 | was seen. Otherwise it is PRAGMA_NONE. */ | |
a7bf9930 | 186 | ENUM_BITFIELD (pragma_kind) pragma_kind : 8; |
1576dec7 | 187 | /* The location at which this token was found. */ |
188 | location_t location; | |
561ba0aa | 189 | /* The value associated with this token, if any. */ |
190 | tree value; | |
1576dec7 | 191 | } c_token; |
192 | ||
193 | /* A parser structure recording information about the state and | |
194 | context of parsing. Includes lexer information with up to two | |
195 | tokens of look-ahead; more are not needed for C. */ | |
fb1e4f4a | 196 | typedef struct GTY(()) c_parser { |
1576dec7 | 197 | /* The look-ahead tokens. */ |
bc7bff74 | 198 | c_token * GTY((skip)) tokens; |
199 | /* Buffer for look-ahead tokens. */ | |
200 | c_token tokens_buf[2]; | |
201 | /* How many look-ahead tokens are available (0, 1 or 2, or | |
202 | more if parsing from pre-lexed tokens). */ | |
203 | unsigned int tokens_avail; | |
1576dec7 | 204 | /* True if a syntax error is being recovered from; false otherwise. |
205 | c_parser_error sets this flag. It should clear this flag when | |
206 | enough tokens have been consumed to recover from the error. */ | |
207 | BOOL_BITFIELD error : 1; | |
b75b98aa | 208 | /* True if we're processing a pragma, and shouldn't automatically |
209 | consume CPP_PRAGMA_EOL. */ | |
210 | BOOL_BITFIELD in_pragma : 1; | |
10c93a35 | 211 | /* True if we're parsing the outermost block of an if statement. */ |
212 | BOOL_BITFIELD in_if_block : 1; | |
8115b8be | 213 | /* True if we want to lex an untranslated string. */ |
214 | BOOL_BITFIELD lex_untranslated_string : 1; | |
b27e241e | 215 | |
920d59b0 | 216 | /* Objective-C specific parser/lexer information. */ |
b27e241e | 217 | |
218 | /* True if we are in a context where the Objective-C "PQ" keywords | |
219 | are considered keywords. */ | |
920d59b0 | 220 | BOOL_BITFIELD objc_pq_context : 1; |
0a65c3bb | 221 | /* True if we are parsing a (potential) Objective-C foreach |
222 | statement. This is set to true after we parsed 'for (' and while | |
223 | we wait for 'in' or ';' to decide if it's a standard C for loop or an | |
224 | Objective-C foreach loop. */ | |
225 | BOOL_BITFIELD objc_could_be_foreach_context : 1; | |
920d59b0 | 226 | /* The following flag is needed to contextualize Objective-C lexical |
227 | analysis. In some cases (e.g., 'int NSObject;'), it is | |
228 | undesirable to bind an identifier to an Objective-C class, even | |
229 | if a class with that name exists. */ | |
230 | BOOL_BITFIELD objc_need_raw_identifier : 1; | |
4c0315d0 | 231 | /* Nonzero if we're processing a __transaction statement. The value |
232 | is 1 | TM_STMT_ATTR_*. */ | |
233 | unsigned int in_transaction : 4; | |
86c110ac | 234 | /* True if we are in a context where the Objective-C "Property attribute" |
235 | keywords are valid. */ | |
236 | BOOL_BITFIELD objc_property_attr_context : 1; | |
74acc703 | 237 | |
238 | /* Cilk Plus specific parser/lexer information. */ | |
239 | ||
240 | /* Buffer to hold all the tokens from parsing the vector attribute for the | |
241 | SIMD-enabled functions (formerly known as elemental functions). */ | |
242 | vec <c_token, va_gc> *cilk_simd_fn_tokens; | |
1576dec7 | 243 | } c_parser; |
244 | ||
b75b98aa | 245 | |
246 | /* The actual parser and external interface. ??? Does this need to be | |
247 | garbage-collected? */ | |
248 | ||
249 | static GTY (()) c_parser *the_parser; | |
250 | ||
1576dec7 | 251 | /* Read in and lex a single token, storing it in *TOKEN. */ |
252 | ||
253 | static void | |
920d59b0 | 254 | c_lex_one_token (c_parser *parser, c_token *token) |
1576dec7 | 255 | { |
256 | timevar_push (TV_LEX); | |
b75b98aa | 257 | |
8115b8be | 258 | token->type = c_lex_with_flags (&token->value, &token->location, NULL, |
259 | (parser->lex_untranslated_string | |
260 | ? C_LEX_STRING_NO_TRANSLATE : 0)); | |
b75b98aa | 261 | token->id_kind = C_ID_NONE; |
262 | token->keyword = RID_MAX; | |
263 | token->pragma_kind = PRAGMA_NONE; | |
b75b98aa | 264 | |
1576dec7 | 265 | switch (token->type) |
266 | { | |
267 | case CPP_NAME: | |
1576dec7 | 268 | { |
269 | tree decl; | |
270 | ||
920d59b0 | 271 | bool objc_force_identifier = parser->objc_need_raw_identifier; |
272 | if (c_dialect_objc ()) | |
273 | parser->objc_need_raw_identifier = false; | |
1576dec7 | 274 | |
275 | if (C_IS_RESERVED_WORD (token->value)) | |
276 | { | |
277 | enum rid rid_code = C_RID_CODE (token->value); | |
278 | ||
5c6e5756 | 279 | if (rid_code == RID_CXX_COMPAT_WARN) |
280 | { | |
e3b80d49 | 281 | warning_at (token->location, |
282 | OPT_Wc___compat, | |
d1dd9ac0 | 283 | "identifier %qE conflicts with C++ keyword", |
284 | token->value); | |
5c6e5756 | 285 | } |
6d5d708e | 286 | else if (rid_code >= RID_FIRST_ADDR_SPACE |
287 | && rid_code <= RID_LAST_ADDR_SPACE) | |
288 | { | |
289 | token->id_kind = C_ID_ADDRSPACE; | |
290 | token->keyword = rid_code; | |
291 | break; | |
292 | } | |
b27e241e | 293 | else if (c_dialect_objc () && OBJC_IS_PQ_KEYWORD (rid_code)) |
1576dec7 | 294 | { |
b27e241e | 295 | /* We found an Objective-C "pq" keyword (in, out, |
296 | inout, bycopy, byref, oneway). They need special | |
297 | care because the interpretation depends on the | |
ffbb3d61 | 298 | context. */ |
b27e241e | 299 | if (parser->objc_pq_context) |
1576dec7 | 300 | { |
1576dec7 | 301 | token->type = CPP_KEYWORD; |
302 | token->keyword = rid_code; | |
303 | break; | |
304 | } | |
0a65c3bb | 305 | else if (parser->objc_could_be_foreach_context |
306 | && rid_code == RID_IN) | |
307 | { | |
308 | /* We are in Objective-C, inside a (potential) | |
309 | foreach context (which means after having | |
310 | parsed 'for (', but before having parsed ';'), | |
311 | and we found 'in'. We consider it the keyword | |
312 | which terminates the declaration at the | |
313 | beginning of a foreach-statement. Note that | |
314 | this means you can't use 'in' for anything else | |
315 | in that context; in particular, in Objective-C | |
316 | you can't use 'in' as the name of the running | |
317 | variable in a C for loop. We could potentially | |
318 | try to add code here to disambiguate, but it | |
ffbb3d61 | 319 | seems a reasonable limitation. */ |
0a65c3bb | 320 | token->type = CPP_KEYWORD; |
321 | token->keyword = rid_code; | |
322 | break; | |
323 | } | |
b27e241e | 324 | /* Else, "pq" keywords outside of the "pq" context are |
325 | not keywords, and we fall through to the code for | |
ffbb3d61 | 326 | normal tokens. */ |
b27e241e | 327 | } |
86c110ac | 328 | else if (c_dialect_objc () && OBJC_IS_PATTR_KEYWORD (rid_code)) |
329 | { | |
ffbb3d61 | 330 | /* We found an Objective-C "property attribute" |
331 | keyword (getter, setter, readonly, etc). These are | |
86c110ac | 332 | only valid in the property context. */ |
333 | if (parser->objc_property_attr_context) | |
334 | { | |
335 | token->type = CPP_KEYWORD; | |
336 | token->keyword = rid_code; | |
337 | break; | |
338 | } | |
339 | /* Else they are not special keywords. | |
340 | */ | |
341 | } | |
b27e241e | 342 | else if (c_dialect_objc () |
343 | && (OBJC_IS_AT_KEYWORD (rid_code) | |
344 | || OBJC_IS_CXX_KEYWORD (rid_code))) | |
345 | { | |
346 | /* We found one of the Objective-C "@" keywords (defs, | |
347 | selector, synchronized, etc) or one of the | |
348 | Objective-C "cxx" keywords (class, private, | |
349 | protected, public, try, catch, throw) without a | |
350 | preceding '@' sign. Do nothing and fall through to | |
351 | the code for normal tokens (in C++ we would still | |
ffbb3d61 | 352 | consider the CXX ones keywords, but not in C). */ |
b27e241e | 353 | ; |
1576dec7 | 354 | } |
355 | else | |
356 | { | |
1576dec7 | 357 | token->type = CPP_KEYWORD; |
358 | token->keyword = rid_code; | |
359 | break; | |
360 | } | |
361 | } | |
362 | ||
363 | decl = lookup_name (token->value); | |
364 | if (decl) | |
365 | { | |
366 | if (TREE_CODE (decl) == TYPE_DECL) | |
367 | { | |
368 | token->id_kind = C_ID_TYPENAME; | |
369 | break; | |
370 | } | |
371 | } | |
372 | else if (c_dialect_objc ()) | |
373 | { | |
374 | tree objc_interface_decl = objc_is_class_name (token->value); | |
375 | /* Objective-C class names are in the same namespace as | |
376 | variables and typedefs, and hence are shadowed by local | |
377 | declarations. */ | |
378 | if (objc_interface_decl | |
05ca272f | 379 | && (!objc_force_identifier || global_bindings_p ())) |
1576dec7 | 380 | { |
381 | token->value = objc_interface_decl; | |
382 | token->id_kind = C_ID_CLASSNAME; | |
383 | break; | |
384 | } | |
385 | } | |
b75b98aa | 386 | token->id_kind = C_ID_ID; |
1576dec7 | 387 | } |
1576dec7 | 388 | break; |
389 | case CPP_AT_NAME: | |
390 | /* This only happens in Objective-C; it must be a keyword. */ | |
391 | token->type = CPP_KEYWORD; | |
e5c75ac3 | 392 | switch (C_RID_CODE (token->value)) |
393 | { | |
394 | /* Replace 'class' with '@class', 'private' with '@private', | |
395 | etc. This prevents confusion with the C++ keyword | |
396 | 'class', and makes the tokens consistent with other | |
397 | Objective-C 'AT' keywords. For example '@class' is | |
398 | reported as RID_AT_CLASS which is consistent with | |
399 | '@synchronized', which is reported as | |
400 | RID_AT_SYNCHRONIZED. | |
401 | */ | |
402 | case RID_CLASS: token->keyword = RID_AT_CLASS; break; | |
403 | case RID_PRIVATE: token->keyword = RID_AT_PRIVATE; break; | |
404 | case RID_PROTECTED: token->keyword = RID_AT_PROTECTED; break; | |
405 | case RID_PUBLIC: token->keyword = RID_AT_PUBLIC; break; | |
406 | case RID_THROW: token->keyword = RID_AT_THROW; break; | |
407 | case RID_TRY: token->keyword = RID_AT_TRY; break; | |
408 | case RID_CATCH: token->keyword = RID_AT_CATCH; break; | |
409 | default: token->keyword = C_RID_CODE (token->value); | |
410 | } | |
1576dec7 | 411 | break; |
412 | case CPP_COLON: | |
413 | case CPP_COMMA: | |
414 | case CPP_CLOSE_PAREN: | |
415 | case CPP_SEMICOLON: | |
416 | /* These tokens may affect the interpretation of any identifiers | |
417 | following, if doing Objective-C. */ | |
920d59b0 | 418 | if (c_dialect_objc ()) |
419 | parser->objc_need_raw_identifier = false; | |
b75b98aa | 420 | break; |
421 | case CPP_PRAGMA: | |
422 | /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */ | |
f9ae6f95 | 423 | token->pragma_kind = (enum pragma_kind) TREE_INT_CST_LOW (token->value); |
b75b98aa | 424 | token->value = NULL; |
1576dec7 | 425 | break; |
426 | default: | |
1576dec7 | 427 | break; |
428 | } | |
429 | timevar_pop (TV_LEX); | |
430 | } | |
431 | ||
432 | /* Return a pointer to the next token from PARSER, reading it in if | |
433 | necessary. */ | |
434 | ||
435 | static inline c_token * | |
436 | c_parser_peek_token (c_parser *parser) | |
437 | { | |
438 | if (parser->tokens_avail == 0) | |
439 | { | |
920d59b0 | 440 | c_lex_one_token (parser, &parser->tokens[0]); |
1576dec7 | 441 | parser->tokens_avail = 1; |
442 | } | |
443 | return &parser->tokens[0]; | |
444 | } | |
445 | ||
446 | /* Return true if the next token from PARSER has the indicated | |
447 | TYPE. */ | |
448 | ||
449 | static inline bool | |
450 | c_parser_next_token_is (c_parser *parser, enum cpp_ttype type) | |
451 | { | |
452 | return c_parser_peek_token (parser)->type == type; | |
453 | } | |
454 | ||
455 | /* Return true if the next token from PARSER does not have the | |
456 | indicated TYPE. */ | |
457 | ||
458 | static inline bool | |
459 | c_parser_next_token_is_not (c_parser *parser, enum cpp_ttype type) | |
460 | { | |
461 | return !c_parser_next_token_is (parser, type); | |
462 | } | |
463 | ||
464 | /* Return true if the next token from PARSER is the indicated | |
465 | KEYWORD. */ | |
466 | ||
467 | static inline bool | |
468 | c_parser_next_token_is_keyword (c_parser *parser, enum rid keyword) | |
469 | { | |
b3cafa91 | 470 | return c_parser_peek_token (parser)->keyword == keyword; |
1576dec7 | 471 | } |
472 | ||
26ee9e7a | 473 | /* Return a pointer to the next-but-one token from PARSER, reading it |
474 | in if necessary. The next token is already read in. */ | |
475 | ||
476 | static c_token * | |
477 | c_parser_peek_2nd_token (c_parser *parser) | |
478 | { | |
479 | if (parser->tokens_avail >= 2) | |
480 | return &parser->tokens[1]; | |
481 | gcc_assert (parser->tokens_avail == 1); | |
482 | gcc_assert (parser->tokens[0].type != CPP_EOF); | |
483 | gcc_assert (parser->tokens[0].type != CPP_PRAGMA_EOL); | |
484 | c_lex_one_token (parser, &parser->tokens[1]); | |
485 | parser->tokens_avail = 2; | |
486 | return &parser->tokens[1]; | |
487 | } | |
488 | ||
1576dec7 | 489 | /* Return true if TOKEN can start a type name, |
490 | false otherwise. */ | |
491 | static bool | |
492 | c_token_starts_typename (c_token *token) | |
493 | { | |
494 | switch (token->type) | |
495 | { | |
496 | case CPP_NAME: | |
497 | switch (token->id_kind) | |
498 | { | |
499 | case C_ID_ID: | |
500 | return false; | |
6d5d708e | 501 | case C_ID_ADDRSPACE: |
502 | return true; | |
1576dec7 | 503 | case C_ID_TYPENAME: |
504 | return true; | |
505 | case C_ID_CLASSNAME: | |
506 | gcc_assert (c_dialect_objc ()); | |
507 | return true; | |
508 | default: | |
509 | gcc_unreachable (); | |
510 | } | |
511 | case CPP_KEYWORD: | |
512 | switch (token->keyword) | |
513 | { | |
514 | case RID_UNSIGNED: | |
515 | case RID_LONG: | |
516 | case RID_SHORT: | |
517 | case RID_SIGNED: | |
518 | case RID_COMPLEX: | |
519 | case RID_INT: | |
520 | case RID_CHAR: | |
521 | case RID_FLOAT: | |
522 | case RID_DOUBLE: | |
523 | case RID_VOID: | |
c4503c0a | 524 | case RID_DFLOAT32: |
525 | case RID_DFLOAT64: | |
526 | case RID_DFLOAT128: | |
1576dec7 | 527 | case RID_BOOL: |
528 | case RID_ENUM: | |
529 | case RID_STRUCT: | |
530 | case RID_UNION: | |
531 | case RID_TYPEOF: | |
532 | case RID_CONST: | |
b560fabd | 533 | case RID_ATOMIC: |
1576dec7 | 534 | case RID_VOLATILE: |
535 | case RID_RESTRICT: | |
536 | case RID_ATTRIBUTE: | |
9421ebb9 | 537 | case RID_FRACT: |
538 | case RID_ACCUM: | |
539 | case RID_SAT: | |
4fba5eb9 | 540 | case RID_AUTO_TYPE: |
1576dec7 | 541 | return true; |
542 | default: | |
9f75f026 | 543 | if (token->keyword >= RID_FIRST_INT_N |
544 | && token->keyword < RID_FIRST_INT_N + NUM_INT_N_ENTS | |
545 | && int_n_enabled_p[token->keyword - RID_FIRST_INT_N]) | |
546 | return true; | |
1576dec7 | 547 | return false; |
548 | } | |
549 | case CPP_LESS: | |
550 | if (c_dialect_objc ()) | |
551 | return true; | |
552 | return false; | |
553 | default: | |
554 | return false; | |
555 | } | |
556 | } | |
557 | ||
26ee9e7a | 558 | enum c_lookahead_kind { |
559 | /* Always treat unknown identifiers as typenames. */ | |
560 | cla_prefer_type, | |
561 | ||
562 | /* Could be parsing a nonabstract declarator. Only treat an identifier | |
563 | as a typename if followed by another identifier or a star. */ | |
564 | cla_nonabstract_decl, | |
565 | ||
566 | /* Never treat identifiers as typenames. */ | |
567 | cla_prefer_id | |
568 | }; | |
569 | ||
1576dec7 | 570 | /* Return true if the next token from PARSER can start a type name, |
26ee9e7a | 571 | false otherwise. LA specifies how to do lookahead in order to |
572 | detect unknown type names. If unsure, pick CLA_PREFER_ID. */ | |
573 | ||
1576dec7 | 574 | static inline bool |
26ee9e7a | 575 | c_parser_next_tokens_start_typename (c_parser *parser, enum c_lookahead_kind la) |
1576dec7 | 576 | { |
577 | c_token *token = c_parser_peek_token (parser); | |
26ee9e7a | 578 | if (c_token_starts_typename (token)) |
579 | return true; | |
580 | ||
581 | /* Try a bit harder to detect an unknown typename. */ | |
582 | if (la != cla_prefer_id | |
583 | && token->type == CPP_NAME | |
584 | && token->id_kind == C_ID_ID | |
585 | ||
586 | /* Do not try too hard when we could have "object in array". */ | |
587 | && !parser->objc_could_be_foreach_context | |
588 | ||
589 | && (la == cla_prefer_type | |
590 | || c_parser_peek_2nd_token (parser)->type == CPP_NAME | |
591 | || c_parser_peek_2nd_token (parser)->type == CPP_MULT) | |
592 | ||
593 | /* Only unknown identifiers. */ | |
594 | && !lookup_name (token->value)) | |
595 | return true; | |
596 | ||
597 | return false; | |
1576dec7 | 598 | } |
599 | ||
b02d8973 | 600 | /* Return true if TOKEN is a type qualifier, false otherwise. */ |
601 | static bool | |
602 | c_token_is_qualifier (c_token *token) | |
603 | { | |
604 | switch (token->type) | |
605 | { | |
606 | case CPP_NAME: | |
607 | switch (token->id_kind) | |
608 | { | |
609 | case C_ID_ADDRSPACE: | |
610 | return true; | |
611 | default: | |
612 | return false; | |
613 | } | |
614 | case CPP_KEYWORD: | |
615 | switch (token->keyword) | |
616 | { | |
617 | case RID_CONST: | |
618 | case RID_VOLATILE: | |
619 | case RID_RESTRICT: | |
620 | case RID_ATTRIBUTE: | |
b560fabd | 621 | case RID_ATOMIC: |
b02d8973 | 622 | return true; |
623 | default: | |
624 | return false; | |
625 | } | |
626 | case CPP_LESS: | |
627 | return false; | |
628 | default: | |
629 | gcc_unreachable (); | |
630 | } | |
631 | } | |
632 | ||
633 | /* Return true if the next token from PARSER is a type qualifier, | |
634 | false otherwise. */ | |
635 | static inline bool | |
636 | c_parser_next_token_is_qualifier (c_parser *parser) | |
637 | { | |
638 | c_token *token = c_parser_peek_token (parser); | |
639 | return c_token_is_qualifier (token); | |
640 | } | |
641 | ||
1576dec7 | 642 | /* Return true if TOKEN can start declaration specifiers, false |
643 | otherwise. */ | |
644 | static bool | |
645 | c_token_starts_declspecs (c_token *token) | |
646 | { | |
647 | switch (token->type) | |
648 | { | |
649 | case CPP_NAME: | |
650 | switch (token->id_kind) | |
651 | { | |
652 | case C_ID_ID: | |
653 | return false; | |
6d5d708e | 654 | case C_ID_ADDRSPACE: |
655 | return true; | |
1576dec7 | 656 | case C_ID_TYPENAME: |
657 | return true; | |
658 | case C_ID_CLASSNAME: | |
659 | gcc_assert (c_dialect_objc ()); | |
660 | return true; | |
661 | default: | |
662 | gcc_unreachable (); | |
663 | } | |
664 | case CPP_KEYWORD: | |
665 | switch (token->keyword) | |
666 | { | |
667 | case RID_STATIC: | |
668 | case RID_EXTERN: | |
669 | case RID_REGISTER: | |
670 | case RID_TYPEDEF: | |
671 | case RID_INLINE: | |
985c6e3a | 672 | case RID_NORETURN: |
1576dec7 | 673 | case RID_AUTO: |
674 | case RID_THREAD: | |
675 | case RID_UNSIGNED: | |
676 | case RID_LONG: | |
677 | case RID_SHORT: | |
678 | case RID_SIGNED: | |
679 | case RID_COMPLEX: | |
680 | case RID_INT: | |
681 | case RID_CHAR: | |
682 | case RID_FLOAT: | |
683 | case RID_DOUBLE: | |
684 | case RID_VOID: | |
c4503c0a | 685 | case RID_DFLOAT32: |
686 | case RID_DFLOAT64: | |
687 | case RID_DFLOAT128: | |
1576dec7 | 688 | case RID_BOOL: |
689 | case RID_ENUM: | |
690 | case RID_STRUCT: | |
691 | case RID_UNION: | |
692 | case RID_TYPEOF: | |
693 | case RID_CONST: | |
694 | case RID_VOLATILE: | |
695 | case RID_RESTRICT: | |
696 | case RID_ATTRIBUTE: | |
9421ebb9 | 697 | case RID_FRACT: |
698 | case RID_ACCUM: | |
699 | case RID_SAT: | |
83e25171 | 700 | case RID_ALIGNAS: |
b560fabd | 701 | case RID_ATOMIC: |
4fba5eb9 | 702 | case RID_AUTO_TYPE: |
1576dec7 | 703 | return true; |
704 | default: | |
9f75f026 | 705 | if (token->keyword >= RID_FIRST_INT_N |
706 | && token->keyword < RID_FIRST_INT_N + NUM_INT_N_ENTS | |
707 | && int_n_enabled_p[token->keyword - RID_FIRST_INT_N]) | |
708 | return true; | |
1576dec7 | 709 | return false; |
710 | } | |
711 | case CPP_LESS: | |
712 | if (c_dialect_objc ()) | |
713 | return true; | |
714 | return false; | |
715 | default: | |
716 | return false; | |
717 | } | |
718 | } | |
719 | ||
f80e7755 | 720 | |
721 | /* Return true if TOKEN can start declaration specifiers or a static | |
722 | assertion, false otherwise. */ | |
723 | static bool | |
724 | c_token_starts_declaration (c_token *token) | |
725 | { | |
726 | if (c_token_starts_declspecs (token) | |
727 | || token->keyword == RID_STATIC_ASSERT) | |
728 | return true; | |
729 | else | |
730 | return false; | |
731 | } | |
732 | ||
1576dec7 | 733 | /* Return true if the next token from PARSER can start declaration |
734 | specifiers, false otherwise. */ | |
735 | static inline bool | |
736 | c_parser_next_token_starts_declspecs (c_parser *parser) | |
737 | { | |
738 | c_token *token = c_parser_peek_token (parser); | |
b0d0931f | 739 | |
740 | /* In Objective-C, a classname normally starts a declspecs unless it | |
741 | is immediately followed by a dot. In that case, it is the | |
742 | Objective-C 2.0 "dot-syntax" for class objects, ie, calls the | |
743 | setter/getter on the class. c_token_starts_declspecs() can't | |
744 | differentiate between the two cases because it only checks the | |
745 | current token, so we have a special check here. */ | |
746 | if (c_dialect_objc () | |
747 | && token->type == CPP_NAME | |
748 | && token->id_kind == C_ID_CLASSNAME | |
749 | && c_parser_peek_2nd_token (parser)->type == CPP_DOT) | |
750 | return false; | |
751 | ||
1576dec7 | 752 | return c_token_starts_declspecs (token); |
753 | } | |
754 | ||
71bb4bc6 | 755 | /* Return true if the next tokens from PARSER can start declaration |
f80e7755 | 756 | specifiers or a static assertion, false otherwise. */ |
757 | static inline bool | |
71bb4bc6 | 758 | c_parser_next_tokens_start_declaration (c_parser *parser) |
f80e7755 | 759 | { |
760 | c_token *token = c_parser_peek_token (parser); | |
b0d0931f | 761 | |
762 | /* Same as above. */ | |
763 | if (c_dialect_objc () | |
764 | && token->type == CPP_NAME | |
765 | && token->id_kind == C_ID_CLASSNAME | |
766 | && c_parser_peek_2nd_token (parser)->type == CPP_DOT) | |
767 | return false; | |
768 | ||
71bb4bc6 | 769 | /* Labels do not start declarations. */ |
770 | if (token->type == CPP_NAME | |
771 | && c_parser_peek_2nd_token (parser)->type == CPP_COLON) | |
772 | return false; | |
773 | ||
774 | if (c_token_starts_declaration (token)) | |
775 | return true; | |
776 | ||
26ee9e7a | 777 | if (c_parser_next_tokens_start_typename (parser, cla_nonabstract_decl)) |
71bb4bc6 | 778 | return true; |
779 | ||
780 | return false; | |
f80e7755 | 781 | } |
782 | ||
1576dec7 | 783 | /* Consume the next token from PARSER. */ |
784 | ||
785 | static void | |
786 | c_parser_consume_token (c_parser *parser) | |
787 | { | |
b75b98aa | 788 | gcc_assert (parser->tokens_avail >= 1); |
789 | gcc_assert (parser->tokens[0].type != CPP_EOF); | |
790 | gcc_assert (!parser->in_pragma || parser->tokens[0].type != CPP_PRAGMA_EOL); | |
791 | gcc_assert (parser->error || parser->tokens[0].type != CPP_PRAGMA); | |
bc7bff74 | 792 | if (parser->tokens != &parser->tokens_buf[0]) |
793 | parser->tokens++; | |
794 | else if (parser->tokens_avail == 2) | |
1576dec7 | 795 | parser->tokens[0] = parser->tokens[1]; |
1576dec7 | 796 | parser->tokens_avail--; |
797 | } | |
798 | ||
b75b98aa | 799 | /* Expect the current token to be a #pragma. Consume it and remember |
800 | that we've begun parsing a pragma. */ | |
801 | ||
802 | static void | |
803 | c_parser_consume_pragma (c_parser *parser) | |
804 | { | |
805 | gcc_assert (!parser->in_pragma); | |
806 | gcc_assert (parser->tokens_avail >= 1); | |
807 | gcc_assert (parser->tokens[0].type == CPP_PRAGMA); | |
bc7bff74 | 808 | if (parser->tokens != &parser->tokens_buf[0]) |
809 | parser->tokens++; | |
810 | else if (parser->tokens_avail == 2) | |
b75b98aa | 811 | parser->tokens[0] = parser->tokens[1]; |
812 | parser->tokens_avail--; | |
813 | parser->in_pragma = true; | |
814 | } | |
815 | ||
3df42822 | 816 | /* Update the global input_location from TOKEN. */ |
1576dec7 | 817 | static inline void |
818 | c_parser_set_source_position_from_token (c_token *token) | |
819 | { | |
820 | if (token->type != CPP_EOF) | |
821 | { | |
822 | input_location = token->location; | |
1576dec7 | 823 | } |
824 | } | |
825 | ||
1576dec7 | 826 | /* Issue a diagnostic of the form |
827 | FILE:LINE: MESSAGE before TOKEN | |
828 | where TOKEN is the next token in the input stream of PARSER. | |
829 | MESSAGE (specified by the caller) is usually of the form "expected | |
830 | OTHER-TOKEN". | |
831 | ||
832 | Do not issue a diagnostic if still recovering from an error. | |
833 | ||
834 | ??? This is taken from the C++ parser, but building up messages in | |
835 | this way is not i18n-friendly and some other approach should be | |
836 | used. */ | |
837 | ||
838 | static void | |
380c6697 | 839 | c_parser_error (c_parser *parser, const char *gmsgid) |
1576dec7 | 840 | { |
841 | c_token *token = c_parser_peek_token (parser); | |
842 | if (parser->error) | |
843 | return; | |
844 | parser->error = true; | |
380c6697 | 845 | if (!gmsgid) |
1576dec7 | 846 | return; |
847 | /* This diagnostic makes more sense if it is tagged to the line of | |
848 | the token we just peeked at. */ | |
849 | c_parser_set_source_position_from_token (token); | |
380c6697 | 850 | c_parse_error (gmsgid, |
1576dec7 | 851 | /* Because c_parse_error does not understand |
852 | CPP_KEYWORD, keywords are treated like | |
853 | identifiers. */ | |
854 | (token->type == CPP_KEYWORD ? CPP_NAME : token->type), | |
ba99525e | 855 | /* ??? The C parser does not save the cpp flags of a |
856 | token, we need to pass 0 here and we will not get | |
857 | the source spelling of some tokens but rather the | |
858 | canonical spelling. */ | |
859 | token->value, /*flags=*/0); | |
1576dec7 | 860 | } |
861 | ||
862 | /* If the next token is of the indicated TYPE, consume it. Otherwise, | |
863 | issue the error MSGID. If MSGID is NULL then a message has already | |
864 | been produced and no message will be produced this time. Returns | |
865 | true if found, false otherwise. */ | |
866 | ||
867 | static bool | |
868 | c_parser_require (c_parser *parser, | |
869 | enum cpp_ttype type, | |
870 | const char *msgid) | |
871 | { | |
872 | if (c_parser_next_token_is (parser, type)) | |
873 | { | |
874 | c_parser_consume_token (parser); | |
875 | return true; | |
876 | } | |
877 | else | |
878 | { | |
879 | c_parser_error (parser, msgid); | |
880 | return false; | |
881 | } | |
882 | } | |
883 | ||
884 | /* If the next token is the indicated keyword, consume it. Otherwise, | |
885 | issue the error MSGID. Returns true if found, false otherwise. */ | |
886 | ||
887 | static bool | |
888 | c_parser_require_keyword (c_parser *parser, | |
889 | enum rid keyword, | |
890 | const char *msgid) | |
891 | { | |
892 | if (c_parser_next_token_is_keyword (parser, keyword)) | |
893 | { | |
894 | c_parser_consume_token (parser); | |
895 | return true; | |
896 | } | |
897 | else | |
898 | { | |
899 | c_parser_error (parser, msgid); | |
900 | return false; | |
901 | } | |
902 | } | |
903 | ||
904 | /* Like c_parser_require, except that tokens will be skipped until the | |
905 | desired token is found. An error message is still produced if the | |
906 | next token is not as expected. If MSGID is NULL then a message has | |
907 | already been produced and no message will be produced this | |
908 | time. */ | |
909 | ||
910 | static void | |
911 | c_parser_skip_until_found (c_parser *parser, | |
912 | enum cpp_ttype type, | |
913 | const char *msgid) | |
914 | { | |
915 | unsigned nesting_depth = 0; | |
916 | ||
917 | if (c_parser_require (parser, type, msgid)) | |
918 | return; | |
919 | ||
920 | /* Skip tokens until the desired token is found. */ | |
921 | while (true) | |
922 | { | |
923 | /* Peek at the next token. */ | |
924 | c_token *token = c_parser_peek_token (parser); | |
925 | /* If we've reached the token we want, consume it and stop. */ | |
926 | if (token->type == type && !nesting_depth) | |
927 | { | |
928 | c_parser_consume_token (parser); | |
929 | break; | |
930 | } | |
b75b98aa | 931 | |
1576dec7 | 932 | /* If we've run out of tokens, stop. */ |
933 | if (token->type == CPP_EOF) | |
934 | return; | |
b75b98aa | 935 | if (token->type == CPP_PRAGMA_EOL && parser->in_pragma) |
936 | return; | |
1576dec7 | 937 | if (token->type == CPP_OPEN_BRACE |
938 | || token->type == CPP_OPEN_PAREN | |
939 | || token->type == CPP_OPEN_SQUARE) | |
940 | ++nesting_depth; | |
941 | else if (token->type == CPP_CLOSE_BRACE | |
942 | || token->type == CPP_CLOSE_PAREN | |
943 | || token->type == CPP_CLOSE_SQUARE) | |
944 | { | |
945 | if (nesting_depth-- == 0) | |
946 | break; | |
947 | } | |
948 | /* Consume this token. */ | |
949 | c_parser_consume_token (parser); | |
950 | } | |
951 | parser->error = false; | |
952 | } | |
953 | ||
954 | /* Skip tokens until the end of a parameter is found, but do not | |
955 | consume the comma, semicolon or closing delimiter. */ | |
956 | ||
957 | static void | |
958 | c_parser_skip_to_end_of_parameter (c_parser *parser) | |
959 | { | |
960 | unsigned nesting_depth = 0; | |
961 | ||
962 | while (true) | |
963 | { | |
964 | c_token *token = c_parser_peek_token (parser); | |
965 | if ((token->type == CPP_COMMA || token->type == CPP_SEMICOLON) | |
966 | && !nesting_depth) | |
967 | break; | |
968 | /* If we've run out of tokens, stop. */ | |
969 | if (token->type == CPP_EOF) | |
970 | return; | |
b75b98aa | 971 | if (token->type == CPP_PRAGMA_EOL && parser->in_pragma) |
972 | return; | |
1576dec7 | 973 | if (token->type == CPP_OPEN_BRACE |
974 | || token->type == CPP_OPEN_PAREN | |
975 | || token->type == CPP_OPEN_SQUARE) | |
976 | ++nesting_depth; | |
977 | else if (token->type == CPP_CLOSE_BRACE | |
978 | || token->type == CPP_CLOSE_PAREN | |
979 | || token->type == CPP_CLOSE_SQUARE) | |
980 | { | |
981 | if (nesting_depth-- == 0) | |
982 | break; | |
983 | } | |
984 | /* Consume this token. */ | |
985 | c_parser_consume_token (parser); | |
986 | } | |
987 | parser->error = false; | |
988 | } | |
989 | ||
b75b98aa | 990 | /* Expect to be at the end of the pragma directive and consume an |
991 | end of line marker. */ | |
992 | ||
993 | static void | |
994 | c_parser_skip_to_pragma_eol (c_parser *parser) | |
995 | { | |
996 | gcc_assert (parser->in_pragma); | |
997 | parser->in_pragma = false; | |
998 | ||
999 | if (!c_parser_require (parser, CPP_PRAGMA_EOL, "expected end of line")) | |
1000 | while (true) | |
1001 | { | |
1002 | c_token *token = c_parser_peek_token (parser); | |
1003 | if (token->type == CPP_EOF) | |
1004 | break; | |
1005 | if (token->type == CPP_PRAGMA_EOL) | |
1006 | { | |
1007 | c_parser_consume_token (parser); | |
1008 | break; | |
1009 | } | |
1010 | c_parser_consume_token (parser); | |
1011 | } | |
1012 | ||
1013 | parser->error = false; | |
1014 | } | |
1576dec7 | 1015 | |
adcd0e5f | 1016 | /* Skip tokens until we have consumed an entire block, or until we |
1017 | have consumed a non-nested ';'. */ | |
1018 | ||
1019 | static void | |
1020 | c_parser_skip_to_end_of_block_or_statement (c_parser *parser) | |
1021 | { | |
1022 | unsigned nesting_depth = 0; | |
1023 | bool save_error = parser->error; | |
1024 | ||
1025 | while (true) | |
1026 | { | |
1027 | c_token *token; | |
1028 | ||
1029 | /* Peek at the next token. */ | |
1030 | token = c_parser_peek_token (parser); | |
1031 | ||
1032 | switch (token->type) | |
1033 | { | |
1034 | case CPP_EOF: | |
1035 | return; | |
1036 | ||
1037 | case CPP_PRAGMA_EOL: | |
1038 | if (parser->in_pragma) | |
1039 | return; | |
1040 | break; | |
1041 | ||
1042 | case CPP_SEMICOLON: | |
1043 | /* If the next token is a ';', we have reached the | |
1044 | end of the statement. */ | |
1045 | if (!nesting_depth) | |
1046 | { | |
1047 | /* Consume the ';'. */ | |
1048 | c_parser_consume_token (parser); | |
1049 | goto finished; | |
1050 | } | |
1051 | break; | |
1052 | ||
1053 | case CPP_CLOSE_BRACE: | |
1054 | /* If the next token is a non-nested '}', then we have | |
1055 | reached the end of the current block. */ | |
1056 | if (nesting_depth == 0 || --nesting_depth == 0) | |
1057 | { | |
1058 | c_parser_consume_token (parser); | |
1059 | goto finished; | |
1060 | } | |
1061 | break; | |
1062 | ||
1063 | case CPP_OPEN_BRACE: | |
1064 | /* If it the next token is a '{', then we are entering a new | |
1065 | block. Consume the entire block. */ | |
1066 | ++nesting_depth; | |
1067 | break; | |
1068 | ||
1069 | case CPP_PRAGMA: | |
1070 | /* If we see a pragma, consume the whole thing at once. We | |
1071 | have some safeguards against consuming pragmas willy-nilly. | |
1072 | Normally, we'd expect to be here with parser->error set, | |
1073 | which disables these safeguards. But it's possible to get | |
1074 | here for secondary error recovery, after parser->error has | |
1075 | been cleared. */ | |
1076 | c_parser_consume_pragma (parser); | |
1077 | c_parser_skip_to_pragma_eol (parser); | |
1078 | parser->error = save_error; | |
1079 | continue; | |
3ab72ef0 | 1080 | |
1081 | default: | |
1082 | break; | |
adcd0e5f | 1083 | } |
1084 | ||
1085 | c_parser_consume_token (parser); | |
1086 | } | |
1087 | ||
1088 | finished: | |
1089 | parser->error = false; | |
1090 | } | |
1091 | ||
caefd295 | 1092 | /* CPP's options (initialized by c-opts.c). */ |
1093 | extern cpp_options *cpp_opts; | |
1094 | ||
1576dec7 | 1095 | /* Save the warning flags which are controlled by __extension__. */ |
1096 | ||
1097 | static inline int | |
1098 | disable_extension_diagnostics (void) | |
1099 | { | |
1100 | int ret = (pedantic | |
1101 | | (warn_pointer_arith << 1) | |
1102 | | (warn_traditional << 2) | |
caefd295 | 1103 | | (flag_iso << 3) |
0b09525f | 1104 | | (warn_long_long << 4) |
4e9eacab | 1105 | | (warn_cxx_compat << 5) |
890c2e2f | 1106 | | (warn_overlength_strings << 6) |
806fe15e | 1107 | /* warn_c90_c99_compat has three states: -1/0/1, so we must |
1108 | play tricks to properly restore it. */ | |
1109 | | ((warn_c90_c99_compat == 1) << 7) | |
508ea33a | 1110 | | ((warn_c90_c99_compat == -1) << 8) |
1111 | /* Similarly for warn_c99_c11_compat. */ | |
1112 | | ((warn_c99_c11_compat == 1) << 9) | |
1113 | | ((warn_c99_c11_compat == -1) << 10) | |
1114 | ); | |
5ae82d58 | 1115 | cpp_opts->cpp_pedantic = pedantic = 0; |
1576dec7 | 1116 | warn_pointer_arith = 0; |
5ae82d58 | 1117 | cpp_opts->cpp_warn_traditional = warn_traditional = 0; |
1576dec7 | 1118 | flag_iso = 0; |
5ae82d58 | 1119 | cpp_opts->cpp_warn_long_long = warn_long_long = 0; |
0b09525f | 1120 | warn_cxx_compat = 0; |
4e9eacab | 1121 | warn_overlength_strings = 0; |
890c2e2f | 1122 | warn_c90_c99_compat = 0; |
508ea33a | 1123 | warn_c99_c11_compat = 0; |
1576dec7 | 1124 | return ret; |
1125 | } | |
1126 | ||
1127 | /* Restore the warning flags which are controlled by __extension__. | |
1128 | FLAGS is the return value from disable_extension_diagnostics. */ | |
1129 | ||
1130 | static inline void | |
1131 | restore_extension_diagnostics (int flags) | |
1132 | { | |
5ae82d58 | 1133 | cpp_opts->cpp_pedantic = pedantic = flags & 1; |
1576dec7 | 1134 | warn_pointer_arith = (flags >> 1) & 1; |
5ae82d58 | 1135 | cpp_opts->cpp_warn_traditional = warn_traditional = (flags >> 2) & 1; |
1576dec7 | 1136 | flag_iso = (flags >> 3) & 1; |
5ae82d58 | 1137 | cpp_opts->cpp_warn_long_long = warn_long_long = (flags >> 4) & 1; |
0b09525f | 1138 | warn_cxx_compat = (flags >> 5) & 1; |
4e9eacab | 1139 | warn_overlength_strings = (flags >> 6) & 1; |
806fe15e | 1140 | /* See above for why is this needed. */ |
1141 | warn_c90_c99_compat = (flags >> 7) & 1 ? 1 : ((flags >> 8) & 1 ? -1 : 0); | |
508ea33a | 1142 | warn_c99_c11_compat = (flags >> 9) & 1 ? 1 : ((flags >> 10) & 1 ? -1 : 0); |
1576dec7 | 1143 | } |
1144 | ||
1145 | /* Possibly kinds of declarator to parse. */ | |
1146 | typedef enum c_dtr_syn { | |
1147 | /* A normal declarator with an identifier. */ | |
1148 | C_DTR_NORMAL, | |
1149 | /* An abstract declarator (maybe empty). */ | |
1150 | C_DTR_ABSTRACT, | |
1151 | /* A parameter declarator: may be either, but after a type name does | |
1152 | not redeclare a typedef name as an identifier if it can | |
1153 | alternatively be interpreted as a typedef name; see DR#009, | |
1154 | applied in C90 TC1, omitted from C99 and reapplied in C99 TC2 | |
1155 | following DR#249. For example, given a typedef T, "int T" and | |
1156 | "int *T" are valid parameter declarations redeclaring T, while | |
1157 | "int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are | |
1158 | abstract declarators rather than involving redundant parentheses; | |
1159 | the same applies with attributes inside the parentheses before | |
1160 | "T". */ | |
1161 | C_DTR_PARM | |
1162 | } c_dtr_syn; | |
1163 | ||
2169f33b | 1164 | /* The binary operation precedence levels, where 0 is a dummy lowest level |
1165 | used for the bottom of the stack. */ | |
1166 | enum c_parser_prec { | |
1167 | PREC_NONE, | |
1168 | PREC_LOGOR, | |
1169 | PREC_LOGAND, | |
1170 | PREC_BITOR, | |
1171 | PREC_BITXOR, | |
1172 | PREC_BITAND, | |
1173 | PREC_EQ, | |
1174 | PREC_REL, | |
1175 | PREC_SHIFT, | |
1176 | PREC_ADD, | |
1177 | PREC_MULT, | |
1178 | NUM_PRECS | |
1179 | }; | |
1180 | ||
1576dec7 | 1181 | static void c_parser_external_declaration (c_parser *); |
1182 | static void c_parser_asm_definition (c_parser *); | |
f80e7755 | 1183 | static void c_parser_declaration_or_fndef (c_parser *, bool, bool, bool, |
bc7bff74 | 1184 | bool, bool, tree *, vec<c_token>); |
f80e7755 | 1185 | static void c_parser_static_assert_declaration_no_semi (c_parser *); |
1186 | static void c_parser_static_assert_declaration (c_parser *); | |
1576dec7 | 1187 | static void c_parser_declspecs (c_parser *, struct c_declspecs *, bool, bool, |
4fba5eb9 | 1188 | bool, bool, bool, enum c_lookahead_kind); |
1576dec7 | 1189 | static struct c_typespec c_parser_enum_specifier (c_parser *); |
1190 | static struct c_typespec c_parser_struct_or_union_specifier (c_parser *); | |
1191 | static tree c_parser_struct_declaration (c_parser *); | |
1192 | static struct c_typespec c_parser_typeof_specifier (c_parser *); | |
83e25171 | 1193 | static tree c_parser_alignas_specifier (c_parser *); |
1576dec7 | 1194 | static struct c_declarator *c_parser_declarator (c_parser *, bool, c_dtr_syn, |
1195 | bool *); | |
1196 | static struct c_declarator *c_parser_direct_declarator (c_parser *, bool, | |
1197 | c_dtr_syn, bool *); | |
1198 | static struct c_declarator *c_parser_direct_declarator_inner (c_parser *, | |
1199 | bool, | |
1200 | struct c_declarator *); | |
1201 | static struct c_arg_info *c_parser_parms_declarator (c_parser *, bool, tree); | |
4232a958 | 1202 | static struct c_arg_info *c_parser_parms_list_declarator (c_parser *, tree, |
1203 | tree); | |
1576dec7 | 1204 | static struct c_parm *c_parser_parameter_declaration (c_parser *, tree); |
1205 | static tree c_parser_simple_asm_expr (c_parser *); | |
1206 | static tree c_parser_attributes (c_parser *); | |
1207 | static struct c_type_name *c_parser_type_name (c_parser *); | |
1208 | static struct c_expr c_parser_initializer (c_parser *); | |
1209 | static struct c_expr c_parser_braced_init (c_parser *, tree, bool); | |
759791ee | 1210 | static void c_parser_initelt (c_parser *, struct obstack *); |
1211 | static void c_parser_initval (c_parser *, struct c_expr *, | |
1212 | struct obstack *); | |
1576dec7 | 1213 | static tree c_parser_compound_statement (c_parser *); |
1214 | static void c_parser_compound_statement_nostart (c_parser *); | |
1215 | static void c_parser_label (c_parser *); | |
1216 | static void c_parser_statement (c_parser *); | |
1217 | static void c_parser_statement_after_labels (c_parser *); | |
1218 | static void c_parser_if_statement (c_parser *); | |
1219 | static void c_parser_switch_statement (c_parser *); | |
4c90c04c | 1220 | static void c_parser_while_statement (c_parser *, bool); |
1221 | static void c_parser_do_statement (c_parser *, bool); | |
4644b593 | 1222 | static void c_parser_for_statement (c_parser *, bool); |
1576dec7 | 1223 | static tree c_parser_asm_statement (c_parser *); |
035b65e2 | 1224 | static tree c_parser_asm_operands (c_parser *); |
78f55ca8 | 1225 | static tree c_parser_asm_goto_operands (c_parser *); |
1576dec7 | 1226 | static tree c_parser_asm_clobbers (c_parser *); |
bc7bff74 | 1227 | static struct c_expr c_parser_expr_no_commas (c_parser *, struct c_expr *, |
1228 | tree = NULL_TREE); | |
1576dec7 | 1229 | static struct c_expr c_parser_conditional_expression (c_parser *, |
bc7bff74 | 1230 | struct c_expr *, tree); |
2169f33b | 1231 | static struct c_expr c_parser_binary_expression (c_parser *, struct c_expr *, |
bc7bff74 | 1232 | tree); |
1576dec7 | 1233 | static struct c_expr c_parser_cast_expression (c_parser *, struct c_expr *); |
1234 | static struct c_expr c_parser_unary_expression (c_parser *); | |
1235 | static struct c_expr c_parser_sizeof_expression (c_parser *); | |
1236 | static struct c_expr c_parser_alignof_expression (c_parser *); | |
1237 | static struct c_expr c_parser_postfix_expression (c_parser *); | |
1238 | static struct c_expr c_parser_postfix_expression_after_paren_type (c_parser *, | |
0b09525f | 1239 | struct c_type_name *, |
1240 | location_t); | |
1576dec7 | 1241 | static struct c_expr c_parser_postfix_expression_after_primary (c_parser *, |
e60a6f7b | 1242 | location_t loc, |
1576dec7 | 1243 | struct c_expr); |
4c0315d0 | 1244 | static tree c_parser_transaction (c_parser *, enum rid); |
1245 | static struct c_expr c_parser_transaction_expression (c_parser *, enum rid); | |
1246 | static tree c_parser_transaction_cancel (c_parser *); | |
1576dec7 | 1247 | static struct c_expr c_parser_expression (c_parser *); |
f14c8207 | 1248 | static struct c_expr c_parser_expression_conv (c_parser *); |
f1f41a6c | 1249 | static vec<tree, va_gc> *c_parser_expr_list (c_parser *, bool, bool, |
1250 | vec<tree, va_gc> **, location_t *, | |
305d96bc | 1251 | tree *, vec<location_t> *, |
1252 | unsigned int * = NULL); | |
ca4c3545 | 1253 | static void c_parser_oacc_enter_exit_data (c_parser *, bool); |
1254 | static void c_parser_oacc_update (c_parser *); | |
1255 | static tree c_parser_oacc_loop (location_t, c_parser *, char *); | |
1e8e9920 | 1256 | static void c_parser_omp_construct (c_parser *); |
1257 | static void c_parser_omp_threadprivate (c_parser *); | |
1258 | static void c_parser_omp_barrier (c_parser *); | |
1259 | static void c_parser_omp_flush (c_parser *); | |
ca4c3545 | 1260 | static tree c_parser_omp_for_loop (location_t, c_parser *, enum tree_code, |
1261 | tree, tree *); | |
fd6481cf | 1262 | static void c_parser_omp_taskwait (c_parser *); |
2169f33b | 1263 | static void c_parser_omp_taskyield (c_parser *); |
bc7bff74 | 1264 | static void c_parser_omp_cancel (c_parser *); |
1265 | static void c_parser_omp_cancellation_point (c_parser *); | |
1576dec7 | 1266 | |
bc7bff74 | 1267 | enum pragma_context { pragma_external, pragma_struct, pragma_param, |
1268 | pragma_stmt, pragma_compound }; | |
b75b98aa | 1269 | static bool c_parser_pragma (c_parser *, enum pragma_context); |
bc7bff74 | 1270 | static bool c_parser_omp_target (c_parser *, enum pragma_context); |
1271 | static void c_parser_omp_end_declare_target (c_parser *); | |
1272 | static void c_parser_omp_declare (c_parser *, enum pragma_context); | |
b75b98aa | 1273 | |
1576dec7 | 1274 | /* These Objective-C parser functions are only ever called when |
1275 | compiling Objective-C. */ | |
a336eb4b | 1276 | static void c_parser_objc_class_definition (c_parser *, tree); |
1576dec7 | 1277 | static void c_parser_objc_class_instance_variables (c_parser *); |
1278 | static void c_parser_objc_class_declaration (c_parser *); | |
1279 | static void c_parser_objc_alias_declaration (c_parser *); | |
a336eb4b | 1280 | static void c_parser_objc_protocol_definition (c_parser *, tree); |
45b2b110 | 1281 | static bool c_parser_objc_method_type (c_parser *); |
1576dec7 | 1282 | static void c_parser_objc_method_definition (c_parser *); |
1283 | static void c_parser_objc_methodprotolist (c_parser *); | |
1284 | static void c_parser_objc_methodproto (c_parser *); | |
4232a958 | 1285 | static tree c_parser_objc_method_decl (c_parser *, bool, tree *, tree *); |
1576dec7 | 1286 | static tree c_parser_objc_type_name (c_parser *); |
1287 | static tree c_parser_objc_protocol_refs (c_parser *); | |
b3d2d312 | 1288 | static void c_parser_objc_try_catch_finally_statement (c_parser *); |
1576dec7 | 1289 | static void c_parser_objc_synchronized_statement (c_parser *); |
1290 | static tree c_parser_objc_selector (c_parser *); | |
1291 | static tree c_parser_objc_selector_arg (c_parser *); | |
1292 | static tree c_parser_objc_receiver (c_parser *); | |
1293 | static tree c_parser_objc_message_args (c_parser *); | |
1294 | static tree c_parser_objc_keywordexpr (c_parser *); | |
1d894bcf | 1295 | static void c_parser_objc_at_property_declaration (c_parser *); |
e1f293c0 | 1296 | static void c_parser_objc_at_synthesize_declaration (c_parser *); |
1297 | static void c_parser_objc_at_dynamic_declaration (c_parser *); | |
86c110ac | 1298 | static bool c_parser_objc_diagnose_bad_element_prefix |
a336eb4b | 1299 | (c_parser *, struct c_declspecs *); |
1576dec7 | 1300 | |
f2697631 | 1301 | /* Cilk Plus supporting routines. */ |
1302 | static void c_parser_cilk_simd (c_parser *); | |
40750995 | 1303 | static void c_parser_cilk_for (c_parser *, tree); |
f2697631 | 1304 | static bool c_parser_cilk_verify_simd (c_parser *, enum pragma_context); |
3c6d4197 | 1305 | static tree c_parser_array_notation (location_t, c_parser *, tree, tree); |
74acc703 | 1306 | static tree c_parser_cilk_clause_vectorlength (c_parser *, tree, bool); |
40750995 | 1307 | static void c_parser_cilk_grainsize (c_parser *); |
3c6d4197 | 1308 | |
1576dec7 | 1309 | /* Parse a translation unit (C90 6.7, C99 6.9). |
1310 | ||
1311 | translation-unit: | |
1312 | external-declarations | |
1313 | ||
1314 | external-declarations: | |
1315 | external-declaration | |
1316 | external-declarations external-declaration | |
1317 | ||
1318 | GNU extensions: | |
1319 | ||
1320 | translation-unit: | |
1321 | empty | |
1322 | */ | |
1323 | ||
1324 | static void | |
1325 | c_parser_translation_unit (c_parser *parser) | |
1326 | { | |
1327 | if (c_parser_next_token_is (parser, CPP_EOF)) | |
1328 | { | |
29438999 | 1329 | pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic, |
21ca8540 | 1330 | "ISO C forbids an empty translation unit"); |
1576dec7 | 1331 | } |
1332 | else | |
1333 | { | |
1334 | void *obstack_position = obstack_alloc (&parser_obstack, 0); | |
3ae3a17f | 1335 | mark_valid_location_for_stdc_pragma (false); |
1576dec7 | 1336 | do |
1337 | { | |
1338 | ggc_collect (); | |
1339 | c_parser_external_declaration (parser); | |
1340 | obstack_free (&parser_obstack, obstack_position); | |
1341 | } | |
1342 | while (c_parser_next_token_is_not (parser, CPP_EOF)); | |
1343 | } | |
1344 | } | |
1345 | ||
1346 | /* Parse an external declaration (C90 6.7, C99 6.9). | |
1347 | ||
1348 | external-declaration: | |
1349 | function-definition | |
1350 | declaration | |
1351 | ||
1352 | GNU extensions: | |
1353 | ||
1354 | external-declaration: | |
1355 | asm-definition | |
1356 | ; | |
1357 | __extension__ external-declaration | |
1358 | ||
1359 | Objective-C: | |
1360 | ||
1361 | external-declaration: | |
1362 | objc-class-definition | |
1363 | objc-class-declaration | |
1364 | objc-alias-declaration | |
1365 | objc-protocol-definition | |
1366 | objc-method-definition | |
1367 | @end | |
1368 | */ | |
1369 | ||
1370 | static void | |
1371 | c_parser_external_declaration (c_parser *parser) | |
1372 | { | |
1373 | int ext; | |
1374 | switch (c_parser_peek_token (parser)->type) | |
1375 | { | |
1376 | case CPP_KEYWORD: | |
1377 | switch (c_parser_peek_token (parser)->keyword) | |
1378 | { | |
1379 | case RID_EXTENSION: | |
1380 | ext = disable_extension_diagnostics (); | |
1381 | c_parser_consume_token (parser); | |
1382 | c_parser_external_declaration (parser); | |
1383 | restore_extension_diagnostics (ext); | |
1384 | break; | |
1385 | case RID_ASM: | |
1386 | c_parser_asm_definition (parser); | |
1387 | break; | |
1388 | case RID_AT_INTERFACE: | |
1389 | case RID_AT_IMPLEMENTATION: | |
1390 | gcc_assert (c_dialect_objc ()); | |
a336eb4b | 1391 | c_parser_objc_class_definition (parser, NULL_TREE); |
1576dec7 | 1392 | break; |
e5c75ac3 | 1393 | case RID_AT_CLASS: |
1576dec7 | 1394 | gcc_assert (c_dialect_objc ()); |
1395 | c_parser_objc_class_declaration (parser); | |
1396 | break; | |
1397 | case RID_AT_ALIAS: | |
1398 | gcc_assert (c_dialect_objc ()); | |
1399 | c_parser_objc_alias_declaration (parser); | |
1400 | break; | |
1401 | case RID_AT_PROTOCOL: | |
1402 | gcc_assert (c_dialect_objc ()); | |
a336eb4b | 1403 | c_parser_objc_protocol_definition (parser, NULL_TREE); |
1576dec7 | 1404 | break; |
86c110ac | 1405 | case RID_AT_PROPERTY: |
1406 | gcc_assert (c_dialect_objc ()); | |
1d894bcf | 1407 | c_parser_objc_at_property_declaration (parser); |
86c110ac | 1408 | break; |
e1f293c0 | 1409 | case RID_AT_SYNTHESIZE: |
1410 | gcc_assert (c_dialect_objc ()); | |
1411 | c_parser_objc_at_synthesize_declaration (parser); | |
1412 | break; | |
1413 | case RID_AT_DYNAMIC: | |
1414 | gcc_assert (c_dialect_objc ()); | |
1415 | c_parser_objc_at_dynamic_declaration (parser); | |
1416 | break; | |
1576dec7 | 1417 | case RID_AT_END: |
1418 | gcc_assert (c_dialect_objc ()); | |
1419 | c_parser_consume_token (parser); | |
1420 | objc_finish_implementation (); | |
1421 | break; | |
1422 | default: | |
1423 | goto decl_or_fndef; | |
1424 | } | |
1425 | break; | |
1426 | case CPP_SEMICOLON: | |
29438999 | 1427 | pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic, |
21ca8540 | 1428 | "ISO C does not allow extra %<;%> outside of a function"); |
1576dec7 | 1429 | c_parser_consume_token (parser); |
1430 | break; | |
b75b98aa | 1431 | case CPP_PRAGMA: |
3ae3a17f | 1432 | mark_valid_location_for_stdc_pragma (true); |
b75b98aa | 1433 | c_parser_pragma (parser, pragma_external); |
3ae3a17f | 1434 | mark_valid_location_for_stdc_pragma (false); |
b75b98aa | 1435 | break; |
1576dec7 | 1436 | case CPP_PLUS: |
1437 | case CPP_MINUS: | |
1438 | if (c_dialect_objc ()) | |
1439 | { | |
1440 | c_parser_objc_method_definition (parser); | |
1441 | break; | |
1442 | } | |
1443 | /* Else fall through, and yield a syntax error trying to parse | |
1444 | as a declaration or function definition. */ | |
1445 | default: | |
1446 | decl_or_fndef: | |
a336eb4b | 1447 | /* A declaration or a function definition (or, in Objective-C, |
1448 | an @interface or @protocol with prefix attributes). We can | |
1449 | only tell which after parsing the declaration specifiers, if | |
1450 | any, and the first declarator. */ | |
bc7bff74 | 1451 | c_parser_declaration_or_fndef (parser, true, true, true, false, true, |
1452 | NULL, vNULL); | |
1576dec7 | 1453 | break; |
1454 | } | |
1455 | } | |
1456 | ||
bc7bff74 | 1457 | static void c_finish_omp_declare_simd (c_parser *, tree, tree, vec<c_token>); |
1458 | ||
1576dec7 | 1459 | /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99 |
1460 | 6.7, 6.9.1). If FNDEF_OK is true, a function definition is | |
1461 | accepted; otherwise (old-style parameter declarations) only other | |
f80e7755 | 1462 | declarations are accepted. If STATIC_ASSERT_OK is true, a static |
1463 | assertion is accepted; otherwise (old-style parameter declarations) | |
1464 | it is not. If NESTED is true, we are inside a function or parsing | |
1465 | old-style parameter declarations; any functions encountered are | |
1466 | nested functions and declaration specifiers are required; otherwise | |
1467 | we are at top level and functions are normal functions and | |
1468 | declaration specifiers may be optional. If EMPTY_OK is true, empty | |
1469 | declarations are OK (subject to all other constraints); otherwise | |
1470 | (old-style parameter declarations) they are diagnosed. If | |
1471 | START_ATTR_OK is true, the declaration specifiers may start with | |
1472 | attributes; otherwise they may not. | |
0a65c3bb | 1473 | OBJC_FOREACH_OBJECT_DECLARATION can be used to get back the parsed |
1474 | declaration when parsing an Objective-C foreach statement. | |
1576dec7 | 1475 | |
1476 | declaration: | |
1477 | declaration-specifiers init-declarator-list[opt] ; | |
f80e7755 | 1478 | static_assert-declaration |
1576dec7 | 1479 | |
1480 | function-definition: | |
1481 | declaration-specifiers[opt] declarator declaration-list[opt] | |
1482 | compound-statement | |
1483 | ||
1484 | declaration-list: | |
1485 | declaration | |
1486 | declaration-list declaration | |
1487 | ||
1488 | init-declarator-list: | |
1489 | init-declarator | |
1490 | init-declarator-list , init-declarator | |
1491 | ||
1492 | init-declarator: | |
1493 | declarator simple-asm-expr[opt] attributes[opt] | |
1494 | declarator simple-asm-expr[opt] attributes[opt] = initializer | |
1495 | ||
1496 | GNU extensions: | |
1497 | ||
1498 | nested-function-definition: | |
1499 | declaration-specifiers declarator declaration-list[opt] | |
1500 | compound-statement | |
1501 | ||
a336eb4b | 1502 | Objective-C: |
1503 | attributes objc-class-definition | |
1504 | attributes objc-category-definition | |
1505 | attributes objc-protocol-definition | |
1506 | ||
1576dec7 | 1507 | The simple-asm-expr and attributes are GNU extensions. |
1508 | ||
1509 | This function does not handle __extension__; that is handled in its | |
1510 | callers. ??? Following the old parser, __extension__ may start | |
1511 | external declarations, declarations in functions and declarations | |
1512 | at the start of "for" loops, but not old-style parameter | |
1513 | declarations. | |
1514 | ||
1515 | C99 requires declaration specifiers in a function definition; the | |
1516 | absence is diagnosed through the diagnosis of implicit int. In GNU | |
1517 | C we also allow but diagnose declarations without declaration | |
1518 | specifiers, but only at top level (elsewhere they conflict with | |
1e8e9920 | 1519 | other syntax). |
48e1416a | 1520 | |
0a65c3bb | 1521 | In Objective-C, declarations of the looping variable in a foreach |
1522 | statement are exceptionally terminated by 'in' (for example, 'for | |
1523 | (NSObject *object in array) { ... }'). | |
1524 | ||
1e8e9920 | 1525 | OpenMP: |
48e1416a | 1526 | |
1e8e9920 | 1527 | declaration: |
1528 | threadprivate-directive */ | |
1576dec7 | 1529 | |
1530 | static void | |
f80e7755 | 1531 | c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok, |
1532 | bool static_assert_ok, bool empty_ok, | |
0a65c3bb | 1533 | bool nested, bool start_attr_ok, |
bc7bff74 | 1534 | tree *objc_foreach_object_declaration, |
1535 | vec<c_token> omp_declare_simd_clauses) | |
1576dec7 | 1536 | { |
1537 | struct c_declspecs *specs; | |
1538 | tree prefix_attrs; | |
1539 | tree all_prefix_attrs; | |
1540 | bool diagnosed_no_specs = false; | |
be9eba16 | 1541 | location_t here = c_parser_peek_token (parser)->location; |
b75b98aa | 1542 | |
f80e7755 | 1543 | if (static_assert_ok |
1544 | && c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT)) | |
1545 | { | |
1546 | c_parser_static_assert_declaration (parser); | |
1547 | return; | |
1548 | } | |
1576dec7 | 1549 | specs = build_null_declspecs (); |
71bb4bc6 | 1550 | |
1551 | /* Try to detect an unknown type name when we have "A B" or "A *B". */ | |
1552 | if (c_parser_peek_token (parser)->type == CPP_NAME | |
1553 | && c_parser_peek_token (parser)->id_kind == C_ID_ID | |
1554 | && (c_parser_peek_2nd_token (parser)->type == CPP_NAME | |
1555 | || c_parser_peek_2nd_token (parser)->type == CPP_MULT) | |
1556 | && (!nested || !lookup_name (c_parser_peek_token (parser)->value))) | |
1557 | { | |
1558 | error_at (here, "unknown type name %qE", | |
1559 | c_parser_peek_token (parser)->value); | |
1560 | ||
1561 | /* Parse declspecs normally to get a correct pointer type, but avoid | |
21e609c5 | 1562 | a further "fails to be a type name" error. Refuse nested functions |
1563 | since it is not how the user likely wants us to recover. */ | |
71bb4bc6 | 1564 | c_parser_peek_token (parser)->type = CPP_KEYWORD; |
1565 | c_parser_peek_token (parser)->keyword = RID_VOID; | |
1566 | c_parser_peek_token (parser)->value = error_mark_node; | |
21e609c5 | 1567 | fndef_ok = !nested; |
71bb4bc6 | 1568 | } |
1569 | ||
43d03c23 | 1570 | c_parser_declspecs (parser, specs, true, true, start_attr_ok, |
4fba5eb9 | 1571 | true, true, cla_nonabstract_decl); |
1576dec7 | 1572 | if (parser->error) |
1573 | { | |
1574 | c_parser_skip_to_end_of_block_or_statement (parser); | |
1575 | return; | |
1576 | } | |
1577 | if (nested && !specs->declspecs_seen_p) | |
1578 | { | |
1579 | c_parser_error (parser, "expected declaration specifiers"); | |
1580 | c_parser_skip_to_end_of_block_or_statement (parser); | |
1581 | return; | |
1582 | } | |
1583 | finish_declspecs (specs); | |
4fba5eb9 | 1584 | bool auto_type_p = specs->typespec_word == cts_auto_type; |
1576dec7 | 1585 | if (c_parser_next_token_is (parser, CPP_SEMICOLON)) |
1586 | { | |
4fba5eb9 | 1587 | if (auto_type_p) |
1588 | error_at (here, "%<__auto_type%> in empty declaration"); | |
1589 | else if (empty_ok) | |
1576dec7 | 1590 | shadow_tag (specs); |
1591 | else | |
1592 | { | |
1593 | shadow_tag_warned (specs, 1); | |
21ca8540 | 1594 | pedwarn (here, 0, "empty declaration"); |
1576dec7 | 1595 | } |
1596 | c_parser_consume_token (parser); | |
1597 | return; | |
1598 | } | |
b02d8973 | 1599 | |
1600 | /* Provide better error recovery. Note that a type name here is usually | |
1601 | better diagnosed as a redeclaration. */ | |
1602 | if (empty_ok | |
1603 | && specs->typespec_kind == ctsk_tagdef | |
1604 | && c_parser_next_token_starts_declspecs (parser) | |
1605 | && !c_parser_next_token_is (parser, CPP_NAME)) | |
1606 | { | |
1607 | c_parser_error (parser, "expected %<;%>, identifier or %<(%>"); | |
1608 | parser->error = false; | |
1609 | shadow_tag_warned (specs, 1); | |
1610 | return; | |
1611 | } | |
4fba5eb9 | 1612 | else if (c_dialect_objc () && !auto_type_p) |
a336eb4b | 1613 | { |
03fc2271 | 1614 | /* Prefix attributes are an error on method decls. */ |
1615 | switch (c_parser_peek_token (parser)->type) | |
1616 | { | |
1617 | case CPP_PLUS: | |
1618 | case CPP_MINUS: | |
1619 | if (c_parser_objc_diagnose_bad_element_prefix (parser, specs)) | |
1620 | return; | |
1621 | if (specs->attrs) | |
1622 | { | |
1623 | warning_at (c_parser_peek_token (parser)->location, | |
1624 | OPT_Wattributes, | |
1625 | "prefix attributes are ignored for methods"); | |
1626 | specs->attrs = NULL_TREE; | |
1627 | } | |
1628 | if (fndef_ok) | |
1629 | c_parser_objc_method_definition (parser); | |
1630 | else | |
1631 | c_parser_objc_methodproto (parser); | |
1632 | return; | |
1633 | break; | |
1634 | default: | |
1635 | break; | |
1636 | } | |
a336eb4b | 1637 | /* This is where we parse 'attributes @interface ...', |
1638 | 'attributes @implementation ...', 'attributes @protocol ...' | |
1639 | (where attributes could be, for example, __attribute__ | |
1640 | ((deprecated)). | |
1641 | */ | |
1642 | switch (c_parser_peek_token (parser)->keyword) | |
1643 | { | |
1644 | case RID_AT_INTERFACE: | |
1645 | { | |
1646 | if (c_parser_objc_diagnose_bad_element_prefix (parser, specs)) | |
1647 | return; | |
1648 | c_parser_objc_class_definition (parser, specs->attrs); | |
1649 | return; | |
1650 | } | |
1651 | break; | |
1652 | case RID_AT_IMPLEMENTATION: | |
1653 | { | |
1654 | if (c_parser_objc_diagnose_bad_element_prefix (parser, specs)) | |
1655 | return; | |
1656 | if (specs->attrs) | |
1657 | { | |
1658 | warning_at (c_parser_peek_token (parser)->location, | |
1659 | OPT_Wattributes, | |
1660 | "prefix attributes are ignored for implementations"); | |
1661 | specs->attrs = NULL_TREE; | |
1662 | } | |
1663 | c_parser_objc_class_definition (parser, NULL_TREE); | |
1664 | return; | |
1665 | } | |
1666 | break; | |
1667 | case RID_AT_PROTOCOL: | |
1668 | { | |
1669 | if (c_parser_objc_diagnose_bad_element_prefix (parser, specs)) | |
1670 | return; | |
1671 | c_parser_objc_protocol_definition (parser, specs->attrs); | |
1672 | return; | |
1673 | } | |
1674 | break; | |
86c110ac | 1675 | case RID_AT_ALIAS: |
1676 | case RID_AT_CLASS: | |
1677 | case RID_AT_END: | |
1678 | case RID_AT_PROPERTY: | |
1679 | if (specs->attrs) | |
1680 | { | |
3b77900e | 1681 | c_parser_error (parser, "unexpected attribute"); |
86c110ac | 1682 | specs->attrs = NULL; |
1683 | } | |
1684 | break; | |
a336eb4b | 1685 | default: |
1686 | break; | |
1687 | } | |
1688 | } | |
1689 | ||
1576dec7 | 1690 | pending_xref_error (); |
1691 | prefix_attrs = specs->attrs; | |
1692 | all_prefix_attrs = prefix_attrs; | |
1693 | specs->attrs = NULL_TREE; | |
1694 | while (true) | |
1695 | { | |
1696 | struct c_declarator *declarator; | |
1697 | bool dummy = false; | |
6198e8f6 | 1698 | timevar_id_t tv; |
1576dec7 | 1699 | tree fnbody; |
1700 | /* Declaring either one or more declarators (in which case we | |
1701 | should diagnose if there were no declaration specifiers) or a | |
1702 | function definition (in which case the diagnostic for | |
1703 | implicit int suffices). */ | |
ae5ead32 | 1704 | declarator = c_parser_declarator (parser, |
1705 | specs->typespec_kind != ctsk_none, | |
1576dec7 | 1706 | C_DTR_NORMAL, &dummy); |
1707 | if (declarator == NULL) | |
1708 | { | |
74acc703 | 1709 | if (omp_declare_simd_clauses.exists () |
1710 | || !vec_safe_is_empty (parser->cilk_simd_fn_tokens)) | |
bc7bff74 | 1711 | c_finish_omp_declare_simd (parser, NULL_TREE, NULL_TREE, |
1712 | omp_declare_simd_clauses); | |
1576dec7 | 1713 | c_parser_skip_to_end_of_block_or_statement (parser); |
1714 | return; | |
1715 | } | |
4fba5eb9 | 1716 | if (auto_type_p && declarator->kind != cdk_id) |
1717 | { | |
1718 | error_at (here, | |
1719 | "%<__auto_type%> requires a plain identifier" | |
1720 | " as declarator"); | |
1721 | c_parser_skip_to_end_of_block_or_statement (parser); | |
1722 | return; | |
1723 | } | |
1576dec7 | 1724 | if (c_parser_next_token_is (parser, CPP_EQ) |
1725 | || c_parser_next_token_is (parser, CPP_COMMA) | |
1726 | || c_parser_next_token_is (parser, CPP_SEMICOLON) | |
1727 | || c_parser_next_token_is_keyword (parser, RID_ASM) | |
0a65c3bb | 1728 | || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE) |
1729 | || c_parser_next_token_is_keyword (parser, RID_IN)) | |
1576dec7 | 1730 | { |
1731 | tree asm_name = NULL_TREE; | |
1732 | tree postfix_attrs = NULL_TREE; | |
1733 | if (!diagnosed_no_specs && !specs->declspecs_seen_p) | |
1734 | { | |
1735 | diagnosed_no_specs = true; | |
21ca8540 | 1736 | pedwarn (here, 0, "data definition has no type or storage class"); |
1576dec7 | 1737 | } |
1738 | /* Having seen a data definition, there cannot now be a | |
1739 | function definition. */ | |
1740 | fndef_ok = false; | |
1741 | if (c_parser_next_token_is_keyword (parser, RID_ASM)) | |
1742 | asm_name = c_parser_simple_asm_expr (parser); | |
1743 | if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)) | |
d44f2f7c | 1744 | { |
1745 | postfix_attrs = c_parser_attributes (parser); | |
1746 | if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) | |
1747 | { | |
1748 | /* This means there is an attribute specifier after | |
1749 | the declarator in a function definition. Provide | |
1750 | some more information for the user. */ | |
1751 | error_at (here, "attributes should be specified before the " | |
1752 | "declarator in a function definition"); | |
1753 | c_parser_skip_to_end_of_block_or_statement (parser); | |
1754 | return; | |
1755 | } | |
1756 | } | |
1576dec7 | 1757 | if (c_parser_next_token_is (parser, CPP_EQ)) |
1758 | { | |
1759 | tree d; | |
1760 | struct c_expr init; | |
e60a6f7b | 1761 | location_t init_loc; |
1576dec7 | 1762 | c_parser_consume_token (parser); |
4fba5eb9 | 1763 | if (auto_type_p) |
1764 | { | |
1765 | start_init (NULL_TREE, asm_name, global_bindings_p ()); | |
1766 | init_loc = c_parser_peek_token (parser)->location; | |
1767 | init = c_parser_expr_no_commas (parser, NULL); | |
1768 | if (TREE_CODE (init.value) == COMPONENT_REF | |
1769 | && DECL_C_BIT_FIELD (TREE_OPERAND (init.value, 1))) | |
1770 | error_at (here, | |
1771 | "%<__auto_type%> used with a bit-field" | |
1772 | " initializer"); | |
1773 | init = convert_lvalue_to_rvalue (init_loc, init, true, true); | |
1774 | tree init_type = TREE_TYPE (init.value); | |
45c5b823 | 1775 | /* As with typeof, remove all qualifiers from atomic types. */ |
4fba5eb9 | 1776 | if (init_type != error_mark_node && TYPE_ATOMIC (init_type)) |
1777 | init_type | |
45c5b823 | 1778 | = c_build_qualified_type (init_type, TYPE_UNQUALIFIED); |
4fba5eb9 | 1779 | bool vm_type = variably_modified_type_p (init_type, |
1780 | NULL_TREE); | |
1781 | if (vm_type) | |
1782 | init.value = c_save_expr (init.value); | |
1783 | finish_init (); | |
1784 | specs->typespec_kind = ctsk_typeof; | |
1785 | specs->locations[cdw_typedef] = init_loc; | |
1786 | specs->typedef_p = true; | |
1787 | specs->type = init_type; | |
1788 | if (vm_type) | |
1789 | { | |
1790 | bool maybe_const = true; | |
1791 | tree type_expr = c_fully_fold (init.value, false, | |
1792 | &maybe_const); | |
1793 | specs->expr_const_operands &= maybe_const; | |
1794 | if (specs->expr) | |
1795 | specs->expr = build2 (COMPOUND_EXPR, | |
1796 | TREE_TYPE (type_expr), | |
1797 | specs->expr, type_expr); | |
1798 | else | |
1799 | specs->expr = type_expr; | |
1800 | } | |
1801 | d = start_decl (declarator, specs, true, | |
1802 | chainon (postfix_attrs, all_prefix_attrs)); | |
1803 | if (!d) | |
1804 | d = error_mark_node; | |
74acc703 | 1805 | if (omp_declare_simd_clauses.exists () |
1806 | || !vec_safe_is_empty (parser->cilk_simd_fn_tokens)) | |
4fba5eb9 | 1807 | c_finish_omp_declare_simd (parser, d, NULL_TREE, |
1808 | omp_declare_simd_clauses); | |
1809 | } | |
1810 | else | |
1811 | { | |
1812 | /* The declaration of the variable is in effect while | |
1813 | its initializer is parsed. */ | |
1814 | d = start_decl (declarator, specs, true, | |
1815 | chainon (postfix_attrs, all_prefix_attrs)); | |
1816 | if (!d) | |
1817 | d = error_mark_node; | |
74acc703 | 1818 | if (omp_declare_simd_clauses.exists () |
1819 | || !vec_safe_is_empty (parser->cilk_simd_fn_tokens)) | |
4fba5eb9 | 1820 | c_finish_omp_declare_simd (parser, d, NULL_TREE, |
1821 | omp_declare_simd_clauses); | |
1822 | start_init (d, asm_name, global_bindings_p ()); | |
1823 | init_loc = c_parser_peek_token (parser)->location; | |
1824 | init = c_parser_initializer (parser); | |
1825 | finish_init (); | |
1826 | } | |
1576dec7 | 1827 | if (d != error_mark_node) |
1828 | { | |
c9e51d25 | 1829 | maybe_warn_string_init (init_loc, TREE_TYPE (d), init); |
e60a6f7b | 1830 | finish_decl (d, init_loc, init.value, |
c9e51d25 | 1831 | init.original_type, asm_name); |
1576dec7 | 1832 | } |
1833 | } | |
1834 | else | |
1835 | { | |
4fba5eb9 | 1836 | if (auto_type_p) |
1837 | { | |
1838 | error_at (here, | |
1839 | "%<__auto_type%> requires an initialized " | |
1840 | "data declaration"); | |
1841 | c_parser_skip_to_end_of_block_or_statement (parser); | |
1842 | return; | |
1843 | } | |
1576dec7 | 1844 | tree d = start_decl (declarator, specs, false, |
1845 | chainon (postfix_attrs, | |
1846 | all_prefix_attrs)); | |
74acc703 | 1847 | if (omp_declare_simd_clauses.exists () |
1848 | || !vec_safe_is_empty (parser->cilk_simd_fn_tokens)) | |
bc7bff74 | 1849 | { |
1850 | tree parms = NULL_TREE; | |
1851 | if (d && TREE_CODE (d) == FUNCTION_DECL) | |
1852 | { | |
1853 | struct c_declarator *ce = declarator; | |
1854 | while (ce != NULL) | |
1855 | if (ce->kind == cdk_function) | |
1856 | { | |
1857 | parms = ce->u.arg_info->parms; | |
1858 | break; | |
1859 | } | |
1860 | else | |
1861 | ce = ce->declarator; | |
1862 | } | |
1863 | if (parms) | |
1864 | temp_store_parm_decls (d, parms); | |
1865 | c_finish_omp_declare_simd (parser, d, parms, | |
1866 | omp_declare_simd_clauses); | |
1867 | if (parms) | |
1868 | temp_pop_parm_decls (); | |
1869 | } | |
1576dec7 | 1870 | if (d) |
e60a6f7b | 1871 | finish_decl (d, UNKNOWN_LOCATION, NULL_TREE, |
0a65c3bb | 1872 | NULL_TREE, asm_name); |
1873 | ||
1874 | if (c_parser_next_token_is_keyword (parser, RID_IN)) | |
1875 | { | |
1876 | if (d) | |
1877 | *objc_foreach_object_declaration = d; | |
1878 | else | |
1879 | *objc_foreach_object_declaration = error_mark_node; | |
1880 | } | |
1576dec7 | 1881 | } |
1882 | if (c_parser_next_token_is (parser, CPP_COMMA)) | |
1883 | { | |
4fba5eb9 | 1884 | if (auto_type_p) |
1885 | { | |
1886 | error_at (here, | |
1887 | "%<__auto_type%> may only be used with" | |
1888 | " a single declarator"); | |
1889 | c_parser_skip_to_end_of_block_or_statement (parser); | |
1890 | return; | |
1891 | } | |
1576dec7 | 1892 | c_parser_consume_token (parser); |
1893 | if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)) | |
1894 | all_prefix_attrs = chainon (c_parser_attributes (parser), | |
1895 | prefix_attrs); | |
1896 | else | |
1897 | all_prefix_attrs = prefix_attrs; | |
1898 | continue; | |
1899 | } | |
1900 | else if (c_parser_next_token_is (parser, CPP_SEMICOLON)) | |
1901 | { | |
1902 | c_parser_consume_token (parser); | |
1903 | return; | |
1904 | } | |
0a65c3bb | 1905 | else if (c_parser_next_token_is_keyword (parser, RID_IN)) |
1906 | { | |
1907 | /* This can only happen in Objective-C: we found the | |
1908 | 'in' that terminates the declaration inside an | |
1909 | Objective-C foreach statement. Do not consume the | |
1910 | token, so that the caller can use it to determine | |
1911 | that this indeed is a foreach context. */ | |
1912 | return; | |
1913 | } | |
1576dec7 | 1914 | else |
1915 | { | |
1916 | c_parser_error (parser, "expected %<,%> or %<;%>"); | |
1917 | c_parser_skip_to_end_of_block_or_statement (parser); | |
1918 | return; | |
1919 | } | |
1920 | } | |
4fba5eb9 | 1921 | else if (auto_type_p) |
1922 | { | |
1923 | error_at (here, | |
1924 | "%<__auto_type%> requires an initialized data declaration"); | |
1925 | c_parser_skip_to_end_of_block_or_statement (parser); | |
1926 | return; | |
1927 | } | |
1576dec7 | 1928 | else if (!fndef_ok) |
1929 | { | |
1930 | c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, " | |
1931 | "%<asm%> or %<__attribute__%>"); | |
1932 | c_parser_skip_to_end_of_block_or_statement (parser); | |
1933 | return; | |
1934 | } | |
1935 | /* Function definition (nested or otherwise). */ | |
1936 | if (nested) | |
1937 | { | |
29438999 | 1938 | pedwarn (here, OPT_Wpedantic, "ISO C forbids nested functions"); |
d2764e2d | 1939 | c_push_function_context (); |
1576dec7 | 1940 | } |
1941 | if (!start_function (specs, declarator, all_prefix_attrs)) | |
1942 | { | |
1943 | /* This can appear in many cases looking nothing like a | |
1944 | function definition, so we don't give a more specific | |
1945 | error suggesting there was one. */ | |
1946 | c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, %<asm%> " | |
1947 | "or %<__attribute__%>"); | |
1948 | if (nested) | |
d2764e2d | 1949 | c_pop_function_context (); |
1576dec7 | 1950 | break; |
1951 | } | |
6198e8f6 | 1952 | |
1953 | if (DECL_DECLARED_INLINE_P (current_function_decl)) | |
1954 | tv = TV_PARSE_INLINE; | |
1955 | else | |
1956 | tv = TV_PARSE_FUNC; | |
1957 | timevar_push (tv); | |
1958 | ||
1576dec7 | 1959 | /* Parse old-style parameter declarations. ??? Attributes are |
1960 | not allowed to start declaration specifiers here because of a | |
1961 | syntax conflict between a function declaration with attribute | |
1962 | suffix and a function definition with an attribute prefix on | |
1963 | first old-style parameter declaration. Following the old | |
1964 | parser, they are not accepted on subsequent old-style | |
1965 | parameter declarations either. However, there is no | |
1966 | ambiguity after the first declaration, nor indeed on the | |
1967 | first as long as we don't allow postfix attributes after a | |
1968 | declarator with a nonempty identifier list in a definition; | |
1969 | and postfix attributes have never been accepted here in | |
1970 | function definitions either. */ | |
1971 | while (c_parser_next_token_is_not (parser, CPP_EOF) | |
1972 | && c_parser_next_token_is_not (parser, CPP_OPEN_BRACE)) | |
f80e7755 | 1973 | c_parser_declaration_or_fndef (parser, false, false, false, |
bc7bff74 | 1974 | true, false, NULL, vNULL); |
1576dec7 | 1975 | store_parm_decls (); |
74acc703 | 1976 | if (omp_declare_simd_clauses.exists () |
1977 | || !vec_safe_is_empty (parser->cilk_simd_fn_tokens)) | |
bc7bff74 | 1978 | c_finish_omp_declare_simd (parser, current_function_decl, NULL_TREE, |
1979 | omp_declare_simd_clauses); | |
30099c0c | 1980 | DECL_STRUCT_FUNCTION (current_function_decl)->function_start_locus |
1981 | = c_parser_peek_token (parser)->location; | |
1576dec7 | 1982 | fnbody = c_parser_compound_statement (parser); |
a89e6c15 | 1983 | if (flag_cilkplus && contains_array_notation_expr (fnbody)) |
cc92dddc | 1984 | fnbody = expand_array_notation_exprs (fnbody); |
1576dec7 | 1985 | if (nested) |
1986 | { | |
1987 | tree decl = current_function_decl; | |
3bb63aeb | 1988 | /* Mark nested functions as needing static-chain initially. |
1989 | lower_nested_functions will recompute it but the | |
1990 | DECL_STATIC_CHAIN flag is also used before that happens, | |
1991 | by initializer_constant_valid_p. See gcc.dg/nested-fn-2.c. */ | |
1992 | DECL_STATIC_CHAIN (decl) = 1; | |
1576dec7 | 1993 | add_stmt (fnbody); |
1994 | finish_function (); | |
d2764e2d | 1995 | c_pop_function_context (); |
e60a6f7b | 1996 | add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl), DECL_EXPR, decl)); |
1576dec7 | 1997 | } |
1998 | else | |
1999 | { | |
2000 | add_stmt (fnbody); | |
2001 | finish_function (); | |
2002 | } | |
6198e8f6 | 2003 | |
2004 | timevar_pop (tv); | |
1576dec7 | 2005 | break; |
2006 | } | |
2007 | } | |
2008 | ||
2009 | /* Parse an asm-definition (asm() outside a function body). This is a | |
2010 | GNU extension. | |
2011 | ||
2012 | asm-definition: | |
2013 | simple-asm-expr ; | |
2014 | */ | |
2015 | ||
2016 | static void | |
2017 | c_parser_asm_definition (c_parser *parser) | |
2018 | { | |
2019 | tree asm_str = c_parser_simple_asm_expr (parser); | |
1576dec7 | 2020 | if (asm_str) |
35ee1c66 | 2021 | symtab->finalize_toplevel_asm (asm_str); |
1576dec7 | 2022 | c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); |
2023 | } | |
2024 | ||
32074525 | 2025 | /* Parse a static assertion (C11 6.7.10). |
f80e7755 | 2026 | |
2027 | static_assert-declaration: | |
2028 | static_assert-declaration-no-semi ; | |
2029 | */ | |
2030 | ||
2031 | static void | |
2032 | c_parser_static_assert_declaration (c_parser *parser) | |
2033 | { | |
2034 | c_parser_static_assert_declaration_no_semi (parser); | |
2035 | if (parser->error | |
2036 | || !c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>")) | |
2037 | c_parser_skip_to_end_of_block_or_statement (parser); | |
2038 | } | |
2039 | ||
32074525 | 2040 | /* Parse a static assertion (C11 6.7.10), without the trailing |
f80e7755 | 2041 | semicolon. |
2042 | ||
2043 | static_assert-declaration-no-semi: | |
2044 | _Static_assert ( constant-expression , string-literal ) | |
2045 | */ | |
2046 | ||
2047 | static void | |
2048 | c_parser_static_assert_declaration_no_semi (c_parser *parser) | |
2049 | { | |
2050 | location_t assert_loc, value_loc; | |
2051 | tree value; | |
2052 | tree string; | |
2053 | ||
2054 | gcc_assert (c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT)); | |
2055 | assert_loc = c_parser_peek_token (parser)->location; | |
508ea33a | 2056 | if (flag_isoc99) |
2057 | pedwarn_c99 (assert_loc, OPT_Wpedantic, | |
f80e7755 | 2058 | "ISO C99 does not support %<_Static_assert%>"); |
508ea33a | 2059 | else |
2060 | pedwarn_c99 (assert_loc, OPT_Wpedantic, | |
f80e7755 | 2061 | "ISO C90 does not support %<_Static_assert%>"); |
f80e7755 | 2062 | c_parser_consume_token (parser); |
2063 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
2064 | return; | |
2065 | value_loc = c_parser_peek_token (parser)->location; | |
2066 | value = c_parser_expr_no_commas (parser, NULL).value; | |
2067 | parser->lex_untranslated_string = true; | |
2068 | if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>")) | |
2069 | { | |
2070 | parser->lex_untranslated_string = false; | |
2071 | return; | |
2072 | } | |
2073 | switch (c_parser_peek_token (parser)->type) | |
2074 | { | |
2075 | case CPP_STRING: | |
2076 | case CPP_STRING16: | |
2077 | case CPP_STRING32: | |
2078 | case CPP_WSTRING: | |
2079 | case CPP_UTF8STRING: | |
2080 | string = c_parser_peek_token (parser)->value; | |
2081 | c_parser_consume_token (parser); | |
2082 | parser->lex_untranslated_string = false; | |
2083 | break; | |
2084 | default: | |
2085 | c_parser_error (parser, "expected string literal"); | |
2086 | parser->lex_untranslated_string = false; | |
2087 | return; | |
2088 | } | |
2089 | c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
2090 | ||
2091 | if (!INTEGRAL_TYPE_P (TREE_TYPE (value))) | |
2092 | { | |
2093 | error_at (value_loc, "expression in static assertion is not an integer"); | |
2094 | return; | |
2095 | } | |
2096 | if (TREE_CODE (value) != INTEGER_CST) | |
2097 | { | |
2098 | value = c_fully_fold (value, false, NULL); | |
6ea2b1bc | 2099 | /* Strip no-op conversions. */ |
2100 | STRIP_TYPE_NOPS (value); | |
f80e7755 | 2101 | if (TREE_CODE (value) == INTEGER_CST) |
29438999 | 2102 | pedwarn (value_loc, OPT_Wpedantic, "expression in static assertion " |
f80e7755 | 2103 | "is not an integer constant expression"); |
2104 | } | |
2105 | if (TREE_CODE (value) != INTEGER_CST) | |
2106 | { | |
2107 | error_at (value_loc, "expression in static assertion is not constant"); | |
2108 | return; | |
2109 | } | |
2110 | constant_expression_warning (value); | |
2111 | if (integer_zerop (value)) | |
2112 | error_at (assert_loc, "static assertion failed: %E", string); | |
2113 | } | |
2114 | ||
1576dec7 | 2115 | /* Parse some declaration specifiers (possibly none) (C90 6.5, C99 |
2116 | 6.7), adding them to SPECS (which may already include some). | |
2117 | Storage class specifiers are accepted iff SCSPEC_OK; type | |
43d03c23 | 2118 | specifiers are accepted iff TYPESPEC_OK; alignment specifiers are |
2119 | accepted iff ALIGNSPEC_OK; attributes are accepted at the start | |
4fba5eb9 | 2120 | iff START_ATTR_OK; __auto_type is accepted iff AUTO_TYPE_OK. |
1576dec7 | 2121 | |
2122 | declaration-specifiers: | |
2123 | storage-class-specifier declaration-specifiers[opt] | |
2124 | type-specifier declaration-specifiers[opt] | |
2125 | type-qualifier declaration-specifiers[opt] | |
2126 | function-specifier declaration-specifiers[opt] | |
83e25171 | 2127 | alignment-specifier declaration-specifiers[opt] |
1576dec7 | 2128 | |
2129 | Function specifiers (inline) are from C99, and are currently | |
83e25171 | 2130 | handled as storage class specifiers, as is __thread. Alignment |
32074525 | 2131 | specifiers are from C11. |
1576dec7 | 2132 | |
2133 | C90 6.5.1, C99 6.7.1: | |
2134 | storage-class-specifier: | |
2135 | typedef | |
2136 | extern | |
2137 | static | |
2138 | auto | |
2139 | register | |
d184e0c0 | 2140 | _Thread_local |
2141 | ||
2142 | (_Thread_local is new in C11.) | |
1576dec7 | 2143 | |
2144 | C99 6.7.4: | |
2145 | function-specifier: | |
2146 | inline | |
4755ceab | 2147 | _Noreturn |
2148 | ||
32074525 | 2149 | (_Noreturn is new in C11.) |
1576dec7 | 2150 | |
2151 | C90 6.5.2, C99 6.7.2: | |
2152 | type-specifier: | |
2153 | void | |
2154 | char | |
2155 | short | |
2156 | int | |
2157 | long | |
2158 | float | |
2159 | double | |
2160 | signed | |
2161 | unsigned | |
2162 | _Bool | |
2163 | _Complex | |
2164 | [_Imaginary removed in C99 TC2] | |
2165 | struct-or-union-specifier | |
2166 | enum-specifier | |
2167 | typedef-name | |
b560fabd | 2168 | atomic-type-specifier |
1576dec7 | 2169 | |
2170 | (_Bool and _Complex are new in C99.) | |
b560fabd | 2171 | (atomic-type-specifier is new in C11.) |
1576dec7 | 2172 | |
2173 | C90 6.5.3, C99 6.7.3: | |
2174 | ||
2175 | type-qualifier: | |
2176 | const | |
2177 | restrict | |
2178 | volatile | |
6d5d708e | 2179 | address-space-qualifier |
b560fabd | 2180 | _Atomic |
1576dec7 | 2181 | |
2182 | (restrict is new in C99.) | |
b560fabd | 2183 | (_Atomic is new in C11.) |
1576dec7 | 2184 | |
2185 | GNU extensions: | |
2186 | ||
2187 | declaration-specifiers: | |
2188 | attributes declaration-specifiers[opt] | |
2189 | ||
6d5d708e | 2190 | type-qualifier: |
2191 | address-space | |
2192 | ||
2193 | address-space: | |
2194 | identifier recognized by the target | |
2195 | ||
1576dec7 | 2196 | storage-class-specifier: |
2197 | __thread | |
2198 | ||
2199 | type-specifier: | |
2200 | typeof-specifier | |
4fba5eb9 | 2201 | __auto_type |
9f75f026 | 2202 | __intN |
c4503c0a | 2203 | _Decimal32 |
2204 | _Decimal64 | |
2205 | _Decimal128 | |
9421ebb9 | 2206 | _Fract |
2207 | _Accum | |
2208 | _Sat | |
2209 | ||
2210 | (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037: | |
2211 | http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf) | |
1576dec7 | 2212 | |
b560fabd | 2213 | atomic-type-specifier |
2214 | _Atomic ( type-name ) | |
2215 | ||
1576dec7 | 2216 | Objective-C: |
2217 | ||
2218 | type-specifier: | |
2219 | class-name objc-protocol-refs[opt] | |
2220 | typedef-name objc-protocol-refs | |
2221 | objc-protocol-refs | |
2222 | */ | |
2223 | ||
2224 | static void | |
2225 | c_parser_declspecs (c_parser *parser, struct c_declspecs *specs, | |
26ee9e7a | 2226 | bool scspec_ok, bool typespec_ok, bool start_attr_ok, |
4fba5eb9 | 2227 | bool alignspec_ok, bool auto_type_ok, |
2228 | enum c_lookahead_kind la) | |
1576dec7 | 2229 | { |
2230 | bool attrs_ok = start_attr_ok; | |
ae5ead32 | 2231 | bool seen_type = specs->typespec_kind != ctsk_none; |
26ee9e7a | 2232 | |
2233 | if (!typespec_ok) | |
2234 | gcc_assert (la == cla_prefer_id); | |
2235 | ||
2236 | while (c_parser_next_token_is (parser, CPP_NAME) | |
1576dec7 | 2237 | || c_parser_next_token_is (parser, CPP_KEYWORD) |
2238 | || (c_dialect_objc () && c_parser_next_token_is (parser, CPP_LESS))) | |
2239 | { | |
2240 | struct c_typespec t; | |
2241 | tree attrs; | |
83e25171 | 2242 | tree align; |
843bd2fa | 2243 | location_t loc = c_parser_peek_token (parser)->location; |
b02d8973 | 2244 | |
26ee9e7a | 2245 | /* If we cannot accept a type, exit if the next token must start |
2246 | one. Also, if we already have seen a tagged definition, | |
2247 | a typename would be an error anyway and likely the user | |
2248 | has simply forgotten a semicolon, so we exit. */ | |
2249 | if ((!typespec_ok || specs->typespec_kind == ctsk_tagdef) | |
2250 | && c_parser_next_tokens_start_typename (parser, la) | |
2251 | && !c_parser_next_token_is_qualifier (parser)) | |
2252 | break; | |
b02d8973 | 2253 | |
1576dec7 | 2254 | if (c_parser_next_token_is (parser, CPP_NAME)) |
2255 | { | |
a60f3e81 | 2256 | c_token *name_token = c_parser_peek_token (parser); |
2257 | tree value = name_token->value; | |
2258 | c_id_kind kind = name_token->id_kind; | |
6d5d708e | 2259 | |
2260 | if (kind == C_ID_ADDRSPACE) | |
2261 | { | |
2262 | addr_space_t as | |
a60f3e81 | 2263 | = name_token->keyword - RID_FIRST_ADDR_SPACE; |
2264 | declspecs_add_addrspace (name_token->location, specs, as); | |
6d5d708e | 2265 | c_parser_consume_token (parser); |
2266 | attrs_ok = true; | |
2267 | continue; | |
2268 | } | |
2269 | ||
26ee9e7a | 2270 | gcc_assert (!c_parser_next_token_is_qualifier (parser)); |
2271 | ||
2272 | /* If we cannot accept a type, and the next token must start one, | |
2273 | exit. Do the same if we already have seen a tagged definition, | |
2274 | since it would be an error anyway and likely the user has simply | |
2275 | forgotten a semicolon. */ | |
2276 | if (seen_type || !c_parser_next_tokens_start_typename (parser, la)) | |
2277 | break; | |
2278 | ||
2279 | /* Now at an unknown typename (C_ID_ID), a C_ID_TYPENAME or | |
2280 | a C_ID_CLASSNAME. */ | |
1576dec7 | 2281 | c_parser_consume_token (parser); |
2282 | seen_type = true; | |
2283 | attrs_ok = true; | |
26ee9e7a | 2284 | if (kind == C_ID_ID) |
2285 | { | |
8f1128f8 | 2286 | error_at (loc, "unknown type name %qE", value); |
26ee9e7a | 2287 | t.kind = ctsk_typedef; |
2288 | t.spec = error_mark_node; | |
2289 | } | |
2290 | else if (kind == C_ID_TYPENAME | |
2291 | && (!c_dialect_objc () | |
2292 | || c_parser_next_token_is_not (parser, CPP_LESS))) | |
1576dec7 | 2293 | { |
2294 | t.kind = ctsk_typedef; | |
2295 | /* For a typedef name, record the meaning, not the name. | |
2296 | In case of 'foo foo, bar;'. */ | |
2297 | t.spec = lookup_name (value); | |
2298 | } | |
2299 | else | |
2300 | { | |
2301 | tree proto = NULL_TREE; | |
2302 | gcc_assert (c_dialect_objc ()); | |
2303 | t.kind = ctsk_objc; | |
2304 | if (c_parser_next_token_is (parser, CPP_LESS)) | |
2305 | proto = c_parser_objc_protocol_refs (parser); | |
2306 | t.spec = objc_get_protocol_qualified_type (value, proto); | |
2307 | } | |
26ee9e7a | 2308 | t.expr = NULL_TREE; |
2309 | t.expr_const_operands = true; | |
a60f3e81 | 2310 | declspecs_add_type (name_token->location, specs, t); |
1576dec7 | 2311 | continue; |
2312 | } | |
2313 | if (c_parser_next_token_is (parser, CPP_LESS)) | |
2314 | { | |
2315 | /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" - | |
2316 | nisse@lysator.liu.se. */ | |
2317 | tree proto; | |
2318 | gcc_assert (c_dialect_objc ()); | |
2319 | if (!typespec_ok || seen_type) | |
2320 | break; | |
2321 | proto = c_parser_objc_protocol_refs (parser); | |
2322 | t.kind = ctsk_objc; | |
2323 | t.spec = objc_get_protocol_qualified_type (NULL_TREE, proto); | |
a75b1c71 | 2324 | t.expr = NULL_TREE; |
2325 | t.expr_const_operands = true; | |
843bd2fa | 2326 | declspecs_add_type (loc, specs, t); |
1576dec7 | 2327 | continue; |
2328 | } | |
2329 | gcc_assert (c_parser_next_token_is (parser, CPP_KEYWORD)); | |
2330 | switch (c_parser_peek_token (parser)->keyword) | |
2331 | { | |
2332 | case RID_STATIC: | |
2333 | case RID_EXTERN: | |
2334 | case RID_REGISTER: | |
2335 | case RID_TYPEDEF: | |
2336 | case RID_INLINE: | |
985c6e3a | 2337 | case RID_NORETURN: |
1576dec7 | 2338 | case RID_AUTO: |
2339 | case RID_THREAD: | |
2340 | if (!scspec_ok) | |
2341 | goto out; | |
2342 | attrs_ok = true; | |
985c6e3a | 2343 | /* TODO: Distinguish between function specifiers (inline, noreturn) |
1576dec7 | 2344 | and storage class specifiers, either here or in |
2345 | declspecs_add_scspec. */ | |
a60f3e81 | 2346 | declspecs_add_scspec (loc, specs, |
2347 | c_parser_peek_token (parser)->value); | |
1576dec7 | 2348 | c_parser_consume_token (parser); |
2349 | break; | |
4fba5eb9 | 2350 | case RID_AUTO_TYPE: |
2351 | if (!auto_type_ok) | |
2352 | goto out; | |
2353 | /* Fall through. */ | |
1576dec7 | 2354 | case RID_UNSIGNED: |
2355 | case RID_LONG: | |
2356 | case RID_SHORT: | |
2357 | case RID_SIGNED: | |
2358 | case RID_COMPLEX: | |
2359 | case RID_INT: | |
2360 | case RID_CHAR: | |
2361 | case RID_FLOAT: | |
2362 | case RID_DOUBLE: | |
2363 | case RID_VOID: | |
c4503c0a | 2364 | case RID_DFLOAT32: |
2365 | case RID_DFLOAT64: | |
2366 | case RID_DFLOAT128: | |
1576dec7 | 2367 | case RID_BOOL: |
9421ebb9 | 2368 | case RID_FRACT: |
2369 | case RID_ACCUM: | |
2370 | case RID_SAT: | |
9f75f026 | 2371 | case RID_INT_N_0: |
2372 | case RID_INT_N_1: | |
2373 | case RID_INT_N_2: | |
2374 | case RID_INT_N_3: | |
1576dec7 | 2375 | if (!typespec_ok) |
2376 | goto out; | |
2377 | attrs_ok = true; | |
2378 | seen_type = true; | |
920d59b0 | 2379 | if (c_dialect_objc ()) |
2380 | parser->objc_need_raw_identifier = true; | |
1576dec7 | 2381 | t.kind = ctsk_resword; |
2382 | t.spec = c_parser_peek_token (parser)->value; | |
a75b1c71 | 2383 | t.expr = NULL_TREE; |
2384 | t.expr_const_operands = true; | |
843bd2fa | 2385 | declspecs_add_type (loc, specs, t); |
1576dec7 | 2386 | c_parser_consume_token (parser); |
2387 | break; | |
2388 | case RID_ENUM: | |
2389 | if (!typespec_ok) | |
2390 | goto out; | |
2391 | attrs_ok = true; | |
2392 | seen_type = true; | |
2393 | t = c_parser_enum_specifier (parser); | |
1f0ce3ac | 2394 | invoke_plugin_callbacks (PLUGIN_FINISH_TYPE, t.spec); |
843bd2fa | 2395 | declspecs_add_type (loc, specs, t); |
1576dec7 | 2396 | break; |
2397 | case RID_STRUCT: | |
2398 | case RID_UNION: | |
2399 | if (!typespec_ok) | |
2400 | goto out; | |
2401 | attrs_ok = true; | |
2402 | seen_type = true; | |
2403 | t = c_parser_struct_or_union_specifier (parser); | |
dd2b35f1 | 2404 | invoke_plugin_callbacks (PLUGIN_FINISH_TYPE, t.spec); |
843bd2fa | 2405 | declspecs_add_type (loc, specs, t); |
1576dec7 | 2406 | break; |
2407 | case RID_TYPEOF: | |
2408 | /* ??? The old parser rejected typeof after other type | |
2409 | specifiers, but is a syntax error the best way of | |
2410 | handling this? */ | |
2411 | if (!typespec_ok || seen_type) | |
2412 | goto out; | |
2413 | attrs_ok = true; | |
2414 | seen_type = true; | |
2415 | t = c_parser_typeof_specifier (parser); | |
843bd2fa | 2416 | declspecs_add_type (loc, specs, t); |
1576dec7 | 2417 | break; |
b560fabd | 2418 | case RID_ATOMIC: |
2419 | /* C parser handling of Objective-C constructs needs | |
2420 | checking for correct lvalue-to-rvalue conversions, and | |
2421 | the code in build_modify_expr handling various | |
2422 | Objective-C cases, and that in build_unary_op handling | |
2423 | Objective-C cases for increment / decrement, also needs | |
2424 | updating; uses of TYPE_MAIN_VARIANT in objc_compare_types | |
2425 | and objc_types_are_equivalent may also need updates. */ | |
2426 | if (c_dialect_objc ()) | |
2427 | sorry ("%<_Atomic%> in Objective-C"); | |
2428 | /* C parser handling of OpenMP constructs needs checking for | |
2429 | correct lvalue-to-rvalue conversions. */ | |
2430 | if (flag_openmp) | |
2431 | sorry ("%<_Atomic%> with OpenMP"); | |
508ea33a | 2432 | if (flag_isoc99) |
2433 | pedwarn_c99 (loc, OPT_Wpedantic, | |
b560fabd | 2434 | "ISO C99 does not support the %<_Atomic%> qualifier"); |
508ea33a | 2435 | else |
2436 | pedwarn_c99 (loc, OPT_Wpedantic, | |
b560fabd | 2437 | "ISO C90 does not support the %<_Atomic%> qualifier"); |
b560fabd | 2438 | attrs_ok = true; |
2439 | tree value; | |
2440 | value = c_parser_peek_token (parser)->value; | |
2441 | c_parser_consume_token (parser); | |
2442 | if (typespec_ok && c_parser_next_token_is (parser, CPP_OPEN_PAREN)) | |
2443 | { | |
2444 | /* _Atomic ( type-name ). */ | |
2445 | seen_type = true; | |
2446 | c_parser_consume_token (parser); | |
2447 | struct c_type_name *type = c_parser_type_name (parser); | |
2448 | t.kind = ctsk_typeof; | |
2449 | t.spec = error_mark_node; | |
2450 | t.expr = NULL_TREE; | |
2451 | t.expr_const_operands = true; | |
2452 | if (type != NULL) | |
2453 | t.spec = groktypename (type, &t.expr, | |
2454 | &t.expr_const_operands); | |
2455 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, | |
2456 | "expected %<)%>"); | |
2457 | if (t.spec != error_mark_node) | |
2458 | { | |
2459 | if (TREE_CODE (t.spec) == ARRAY_TYPE) | |
2460 | error_at (loc, "%<_Atomic%>-qualified array type"); | |
2461 | else if (TREE_CODE (t.spec) == FUNCTION_TYPE) | |
2462 | error_at (loc, "%<_Atomic%>-qualified function type"); | |
2463 | else if (TYPE_QUALS (t.spec) != TYPE_UNQUALIFIED) | |
2464 | error_at (loc, "%<_Atomic%> applied to a qualified type"); | |
2465 | else | |
2466 | t.spec = c_build_qualified_type (t.spec, TYPE_QUAL_ATOMIC); | |
2467 | } | |
2468 | declspecs_add_type (loc, specs, t); | |
2469 | } | |
2470 | else | |
2471 | declspecs_add_qual (loc, specs, value); | |
2472 | break; | |
1576dec7 | 2473 | case RID_CONST: |
2474 | case RID_VOLATILE: | |
2475 | case RID_RESTRICT: | |
2476 | attrs_ok = true; | |
a60f3e81 | 2477 | declspecs_add_qual (loc, specs, c_parser_peek_token (parser)->value); |
1576dec7 | 2478 | c_parser_consume_token (parser); |
2479 | break; | |
2480 | case RID_ATTRIBUTE: | |
2481 | if (!attrs_ok) | |
2482 | goto out; | |
2483 | attrs = c_parser_attributes (parser); | |
a60f3e81 | 2484 | declspecs_add_attrs (loc, specs, attrs); |
1576dec7 | 2485 | break; |
83e25171 | 2486 | case RID_ALIGNAS: |
43d03c23 | 2487 | if (!alignspec_ok) |
2488 | goto out; | |
83e25171 | 2489 | align = c_parser_alignas_specifier (parser); |
a60f3e81 | 2490 | declspecs_add_alignas (loc, specs, align); |
83e25171 | 2491 | break; |
1576dec7 | 2492 | default: |
2493 | goto out; | |
2494 | } | |
2495 | } | |
2496 | out: ; | |
2497 | } | |
2498 | ||
2499 | /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2). | |
2500 | ||
2501 | enum-specifier: | |
2502 | enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt] | |
2503 | enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt] | |
2504 | enum attributes[opt] identifier | |
2505 | ||
2506 | The form with trailing comma is new in C99. The forms with | |
2507 | attributes are GNU extensions. In GNU C, we accept any expression | |
2508 | without commas in the syntax (assignment expressions, not just | |
2509 | conditional expressions); assignment expressions will be diagnosed | |
2510 | as non-constant. | |
2511 | ||
2512 | enumerator-list: | |
2513 | enumerator | |
2514 | enumerator-list , enumerator | |
2515 | ||
2516 | enumerator: | |
2517 | enumeration-constant | |
2518 | enumeration-constant = constant-expression | |
2519 | */ | |
2520 | ||
2521 | static struct c_typespec | |
2522 | c_parser_enum_specifier (c_parser *parser) | |
2523 | { | |
2524 | struct c_typespec ret; | |
2525 | tree attrs; | |
2526 | tree ident = NULL_TREE; | |
0b09525f | 2527 | location_t enum_loc; |
019abced | 2528 | location_t ident_loc = UNKNOWN_LOCATION; /* Quiet warning. */ |
1576dec7 | 2529 | gcc_assert (c_parser_next_token_is_keyword (parser, RID_ENUM)); |
0b09525f | 2530 | enum_loc = c_parser_peek_token (parser)->location; |
1576dec7 | 2531 | c_parser_consume_token (parser); |
2532 | attrs = c_parser_attributes (parser); | |
e60a6f7b | 2533 | enum_loc = c_parser_peek_token (parser)->location; |
8c37d359 | 2534 | /* Set the location in case we create a decl now. */ |
2535 | c_parser_set_source_position_from_token (c_parser_peek_token (parser)); | |
1576dec7 | 2536 | if (c_parser_next_token_is (parser, CPP_NAME)) |
2537 | { | |
2538 | ident = c_parser_peek_token (parser)->value; | |
be9eba16 | 2539 | ident_loc = c_parser_peek_token (parser)->location; |
0b09525f | 2540 | enum_loc = ident_loc; |
1576dec7 | 2541 | c_parser_consume_token (parser); |
2542 | } | |
2543 | if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) | |
2544 | { | |
2545 | /* Parse an enum definition. */ | |
13c7079e | 2546 | struct c_enum_contents the_enum; |
6198e8f6 | 2547 | tree type; |
1576dec7 | 2548 | tree postfix_attrs; |
2549 | /* We chain the enumerators in reverse order, then put them in | |
2550 | forward order at the end. */ | |
6198e8f6 | 2551 | tree values; |
2552 | timevar_push (TV_PARSE_ENUM); | |
2553 | type = start_enum (enum_loc, &the_enum, ident); | |
2554 | values = NULL_TREE; | |
1576dec7 | 2555 | c_parser_consume_token (parser); |
2556 | while (true) | |
2557 | { | |
2558 | tree enum_id; | |
2559 | tree enum_value; | |
2560 | tree enum_decl; | |
2561 | bool seen_comma; | |
8c37d359 | 2562 | c_token *token; |
019abced | 2563 | location_t comma_loc = UNKNOWN_LOCATION; /* Quiet warning. */ |
5a7ce2ec | 2564 | location_t decl_loc, value_loc; |
1576dec7 | 2565 | if (c_parser_next_token_is_not (parser, CPP_NAME)) |
2566 | { | |
2567 | c_parser_error (parser, "expected identifier"); | |
2568 | c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL); | |
2569 | values = error_mark_node; | |
2570 | break; | |
2571 | } | |
8c37d359 | 2572 | token = c_parser_peek_token (parser); |
2573 | enum_id = token->value; | |
2574 | /* Set the location in case we create a decl now. */ | |
2575 | c_parser_set_source_position_from_token (token); | |
5a7ce2ec | 2576 | decl_loc = value_loc = token->location; |
1576dec7 | 2577 | c_parser_consume_token (parser); |
2578 | if (c_parser_next_token_is (parser, CPP_EQ)) | |
2579 | { | |
2580 | c_parser_consume_token (parser); | |
e8fc0d34 | 2581 | value_loc = c_parser_peek_token (parser)->location; |
1576dec7 | 2582 | enum_value = c_parser_expr_no_commas (parser, NULL).value; |
2583 | } | |
2584 | else | |
2585 | enum_value = NULL_TREE; | |
5a7ce2ec | 2586 | enum_decl = build_enumerator (decl_loc, value_loc, |
e60a6f7b | 2587 | &the_enum, enum_id, enum_value); |
1576dec7 | 2588 | TREE_CHAIN (enum_decl) = values; |
2589 | values = enum_decl; | |
2590 | seen_comma = false; | |
2591 | if (c_parser_next_token_is (parser, CPP_COMMA)) | |
2592 | { | |
be9eba16 | 2593 | comma_loc = c_parser_peek_token (parser)->location; |
1576dec7 | 2594 | seen_comma = true; |
2595 | c_parser_consume_token (parser); | |
2596 | } | |
2597 | if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) | |
2598 | { | |
890c2e2f | 2599 | if (seen_comma) |
2600 | pedwarn_c90 (comma_loc, OPT_Wpedantic, | |
2601 | "comma at end of enumerator list"); | |
1576dec7 | 2602 | c_parser_consume_token (parser); |
2603 | break; | |
2604 | } | |
2605 | if (!seen_comma) | |
2606 | { | |
2607 | c_parser_error (parser, "expected %<,%> or %<}%>"); | |
2608 | c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL); | |
2609 | values = error_mark_node; | |
2610 | break; | |
2611 | } | |
2612 | } | |
2613 | postfix_attrs = c_parser_attributes (parser); | |
2614 | ret.spec = finish_enum (type, nreverse (values), | |
2615 | chainon (attrs, postfix_attrs)); | |
2616 | ret.kind = ctsk_tagdef; | |
a75b1c71 | 2617 | ret.expr = NULL_TREE; |
2618 | ret.expr_const_operands = true; | |
6198e8f6 | 2619 | timevar_pop (TV_PARSE_ENUM); |
1576dec7 | 2620 | return ret; |
2621 | } | |
2622 | else if (!ident) | |
2623 | { | |
2624 | c_parser_error (parser, "expected %<{%>"); | |
2625 | ret.spec = error_mark_node; | |
2626 | ret.kind = ctsk_tagref; | |
a75b1c71 | 2627 | ret.expr = NULL_TREE; |
2628 | ret.expr_const_operands = true; | |
1576dec7 | 2629 | return ret; |
2630 | } | |
e60a6f7b | 2631 | ret = parser_xref_tag (ident_loc, ENUMERAL_TYPE, ident); |
1576dec7 | 2632 | /* In ISO C, enumerated types can be referred to only if already |
2633 | defined. */ | |
2634 | if (pedantic && !COMPLETE_TYPE_P (ret.spec)) | |
be9eba16 | 2635 | { |
2636 | gcc_assert (ident); | |
29438999 | 2637 | pedwarn (enum_loc, OPT_Wpedantic, |
21ca8540 | 2638 | "ISO C forbids forward references to %<enum%> types"); |
be9eba16 | 2639 | } |
1576dec7 | 2640 | return ret; |
2641 | } | |
2642 | ||
2643 | /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1). | |
2644 | ||
2645 | struct-or-union-specifier: | |
2646 | struct-or-union attributes[opt] identifier[opt] | |
2647 | { struct-contents } attributes[opt] | |
2648 | struct-or-union attributes[opt] identifier | |
2649 | ||
2650 | struct-contents: | |
2651 | struct-declaration-list | |
2652 | ||
2653 | struct-declaration-list: | |
2654 | struct-declaration ; | |
2655 | struct-declaration-list struct-declaration ; | |
2656 | ||
2657 | GNU extensions: | |
2658 | ||
2659 | struct-contents: | |
2660 | empty | |
2661 | struct-declaration | |
2662 | struct-declaration-list struct-declaration | |
2663 | ||
2664 | struct-declaration-list: | |
2665 | struct-declaration-list ; | |
2666 | ; | |
2667 | ||
2668 | (Note that in the syntax here, unlike that in ISO C, the semicolons | |
2669 | are included here rather than in struct-declaration, in order to | |
2670 | describe the syntax with extra semicolons and missing semicolon at | |
2671 | end.) | |
2672 | ||
2673 | Objective-C: | |
2674 | ||
2675 | struct-declaration-list: | |
2676 | @defs ( class-name ) | |
2677 | ||
2678 | (Note this does not include a trailing semicolon, but can be | |
2679 | followed by further declarations, and gets a pedwarn-if-pedantic | |
2680 | when followed by a semicolon.) */ | |
2681 | ||
2682 | static struct c_typespec | |
2683 | c_parser_struct_or_union_specifier (c_parser *parser) | |
2684 | { | |
2685 | struct c_typespec ret; | |
2686 | tree attrs; | |
2687 | tree ident = NULL_TREE; | |
0b09525f | 2688 | location_t struct_loc; |
2689 | location_t ident_loc = UNKNOWN_LOCATION; | |
1576dec7 | 2690 | enum tree_code code; |
2691 | switch (c_parser_peek_token (parser)->keyword) | |
2692 | { | |
2693 | case RID_STRUCT: | |
2694 | code = RECORD_TYPE; | |
2695 | break; | |
2696 | case RID_UNION: | |
2697 | code = UNION_TYPE; | |
2698 | break; | |
2699 | default: | |
2700 | gcc_unreachable (); | |
2701 | } | |
0b09525f | 2702 | struct_loc = c_parser_peek_token (parser)->location; |
1576dec7 | 2703 | c_parser_consume_token (parser); |
2704 | attrs = c_parser_attributes (parser); | |
e60a6f7b | 2705 | |
8c37d359 | 2706 | /* Set the location in case we create a decl now. */ |
2707 | c_parser_set_source_position_from_token (c_parser_peek_token (parser)); | |
e60a6f7b | 2708 | |
1576dec7 | 2709 | if (c_parser_next_token_is (parser, CPP_NAME)) |
2710 | { | |
2711 | ident = c_parser_peek_token (parser)->value; | |
0b09525f | 2712 | ident_loc = c_parser_peek_token (parser)->location; |
2713 | struct_loc = ident_loc; | |
1576dec7 | 2714 | c_parser_consume_token (parser); |
2715 | } | |
2716 | if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) | |
2717 | { | |
2718 | /* Parse a struct or union definition. Start the scope of the | |
2719 | tag before parsing components. */ | |
843bd2fa | 2720 | struct c_struct_parse_info *struct_info; |
2721 | tree type = start_struct (struct_loc, code, ident, &struct_info); | |
1576dec7 | 2722 | tree postfix_attrs; |
2723 | /* We chain the components in reverse order, then put them in | |
2724 | forward order at the end. Each struct-declaration may | |
2725 | declare multiple components (comma-separated), so we must use | |
2726 | chainon to join them, although when parsing each | |
2727 | struct-declaration we can use TREE_CHAIN directly. | |
2728 | ||
2729 | The theory behind all this is that there will be more | |
2730 | semicolon separated fields than comma separated fields, and | |
2731 | so we'll be minimizing the number of node traversals required | |
2732 | by chainon. */ | |
6198e8f6 | 2733 | tree contents; |
2734 | timevar_push (TV_PARSE_STRUCT); | |
2735 | contents = NULL_TREE; | |
1576dec7 | 2736 | c_parser_consume_token (parser); |
2737 | /* Handle the Objective-C @defs construct, | |
2738 | e.g. foo(sizeof(struct{ @defs(ClassName) }));. */ | |
2739 | if (c_parser_next_token_is_keyword (parser, RID_AT_DEFS)) | |
2740 | { | |
2741 | tree name; | |
2742 | gcc_assert (c_dialect_objc ()); | |
2743 | c_parser_consume_token (parser); | |
2744 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
2745 | goto end_at_defs; | |
2746 | if (c_parser_next_token_is (parser, CPP_NAME) | |
2747 | && c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME) | |
2748 | { | |
2749 | name = c_parser_peek_token (parser)->value; | |
2750 | c_parser_consume_token (parser); | |
2751 | } | |
2752 | else | |
2753 | { | |
2754 | c_parser_error (parser, "expected class name"); | |
2755 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); | |
2756 | goto end_at_defs; | |
2757 | } | |
2758 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, | |
2759 | "expected %<)%>"); | |
2760 | contents = nreverse (objc_get_class_ivars (name)); | |
2761 | } | |
2762 | end_at_defs: | |
2763 | /* Parse the struct-declarations and semicolons. Problems with | |
2764 | semicolons are diagnosed here; empty structures are diagnosed | |
2765 | elsewhere. */ | |
2766 | while (true) | |
2767 | { | |
2768 | tree decls; | |
2769 | /* Parse any stray semicolon. */ | |
2770 | if (c_parser_next_token_is (parser, CPP_SEMICOLON)) | |
2771 | { | |
29438999 | 2772 | pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic, |
21ca8540 | 2773 | "extra semicolon in struct or union specified"); |
1576dec7 | 2774 | c_parser_consume_token (parser); |
2775 | continue; | |
2776 | } | |
2777 | /* Stop if at the end of the struct or union contents. */ | |
2778 | if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) | |
2779 | { | |
2780 | c_parser_consume_token (parser); | |
2781 | break; | |
2782 | } | |
b75b98aa | 2783 | /* Accept #pragmas at struct scope. */ |
2784 | if (c_parser_next_token_is (parser, CPP_PRAGMA)) | |
2785 | { | |
bc7bff74 | 2786 | c_parser_pragma (parser, pragma_struct); |
b75b98aa | 2787 | continue; |
2788 | } | |
1576dec7 | 2789 | /* Parse some comma-separated declarations, but not the |
2790 | trailing semicolon if any. */ | |
2791 | decls = c_parser_struct_declaration (parser); | |
2792 | contents = chainon (decls, contents); | |
2793 | /* If no semicolon follows, either we have a parse error or | |
2794 | are at the end of the struct or union and should | |
2795 | pedwarn. */ | |
2796 | if (c_parser_next_token_is (parser, CPP_SEMICOLON)) | |
2797 | c_parser_consume_token (parser); | |
2798 | else | |
2799 | { | |
2800 | if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) | |
48e1416a | 2801 | pedwarn (c_parser_peek_token (parser)->location, 0, |
21ca8540 | 2802 | "no semicolon at end of struct or union"); |
b02d8973 | 2803 | else if (parser->error |
2804 | || !c_parser_next_token_starts_declspecs (parser)) | |
1576dec7 | 2805 | { |
2806 | c_parser_error (parser, "expected %<;%>"); | |
2807 | c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL); | |
2808 | break; | |
2809 | } | |
b02d8973 | 2810 | |
2811 | /* If we come here, we have already emitted an error | |
2812 | for an expected `;', identifier or `(', and we also | |
2813 | recovered already. Go on with the next field. */ | |
1576dec7 | 2814 | } |
2815 | } | |
2816 | postfix_attrs = c_parser_attributes (parser); | |
e60a6f7b | 2817 | ret.spec = finish_struct (struct_loc, type, nreverse (contents), |
843bd2fa | 2818 | chainon (attrs, postfix_attrs), struct_info); |
1576dec7 | 2819 | ret.kind = ctsk_tagdef; |
a75b1c71 | 2820 | ret.expr = NULL_TREE; |
2821 | ret.expr_const_operands = true; | |
6198e8f6 | 2822 | timevar_pop (TV_PARSE_STRUCT); |
1576dec7 | 2823 | return ret; |
2824 | } | |
2825 | else if (!ident) | |
2826 | { | |
2827 | c_parser_error (parser, "expected %<{%>"); | |
2828 | ret.spec = error_mark_node; | |
2829 | ret.kind = ctsk_tagref; | |
a75b1c71 | 2830 | ret.expr = NULL_TREE; |
2831 | ret.expr_const_operands = true; | |
b6903102 | 2832 | return ret; |
1576dec7 | 2833 | } |
e60a6f7b | 2834 | ret = parser_xref_tag (ident_loc, code, ident); |
1576dec7 | 2835 | return ret; |
2836 | } | |
2837 | ||
2838 | /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without* | |
2839 | the trailing semicolon. | |
2840 | ||
2841 | struct-declaration: | |
2842 | specifier-qualifier-list struct-declarator-list | |
f80e7755 | 2843 | static_assert-declaration-no-semi |
1576dec7 | 2844 | |
2845 | specifier-qualifier-list: | |
2846 | type-specifier specifier-qualifier-list[opt] | |
2847 | type-qualifier specifier-qualifier-list[opt] | |
2848 | attributes specifier-qualifier-list[opt] | |
2849 | ||
2850 | struct-declarator-list: | |
2851 | struct-declarator | |
2852 | struct-declarator-list , attributes[opt] struct-declarator | |
2853 | ||
2854 | struct-declarator: | |
2855 | declarator attributes[opt] | |
2856 | declarator[opt] : constant-expression attributes[opt] | |
2857 | ||
2858 | GNU extensions: | |
2859 | ||
2860 | struct-declaration: | |
2861 | __extension__ struct-declaration | |
2862 | specifier-qualifier-list | |
2863 | ||
2864 | Unlike the ISO C syntax, semicolons are handled elsewhere. The use | |
2865 | of attributes where shown is a GNU extension. In GNU C, we accept | |
2866 | any expression without commas in the syntax (assignment | |
2867 | expressions, not just conditional expressions); assignment | |
2868 | expressions will be diagnosed as non-constant. */ | |
2869 | ||
2870 | static tree | |
2871 | c_parser_struct_declaration (c_parser *parser) | |
2872 | { | |
2873 | struct c_declspecs *specs; | |
2874 | tree prefix_attrs; | |
2875 | tree all_prefix_attrs; | |
2876 | tree decls; | |
be9eba16 | 2877 | location_t decl_loc; |
1576dec7 | 2878 | if (c_parser_next_token_is_keyword (parser, RID_EXTENSION)) |
2879 | { | |
2880 | int ext; | |
2881 | tree decl; | |
2882 | ext = disable_extension_diagnostics (); | |
2883 | c_parser_consume_token (parser); | |
2884 | decl = c_parser_struct_declaration (parser); | |
2885 | restore_extension_diagnostics (ext); | |
2886 | return decl; | |
2887 | } | |
f80e7755 | 2888 | if (c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT)) |
2889 | { | |
2890 | c_parser_static_assert_declaration_no_semi (parser); | |
2891 | return NULL_TREE; | |
2892 | } | |
1576dec7 | 2893 | specs = build_null_declspecs (); |
be9eba16 | 2894 | decl_loc = c_parser_peek_token (parser)->location; |
12f86df0 | 2895 | /* Strictly by the standard, we shouldn't allow _Alignas here, |
2896 | but it appears to have been intended to allow it there, so | |
2897 | we're keeping it as it is until WG14 reaches a conclusion | |
2898 | of N1731. | |
2899 | <http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1731.pdf> */ | |
43d03c23 | 2900 | c_parser_declspecs (parser, specs, false, true, true, |
4fba5eb9 | 2901 | true, false, cla_nonabstract_decl); |
1576dec7 | 2902 | if (parser->error) |
b6903102 | 2903 | return NULL_TREE; |
1576dec7 | 2904 | if (!specs->declspecs_seen_p) |
2905 | { | |
2906 | c_parser_error (parser, "expected specifier-qualifier-list"); | |
2907 | return NULL_TREE; | |
2908 | } | |
2909 | finish_declspecs (specs); | |
a25b333d | 2910 | if (c_parser_next_token_is (parser, CPP_SEMICOLON) |
2911 | || c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) | |
1576dec7 | 2912 | { |
2913 | tree ret; | |
ae5ead32 | 2914 | if (specs->typespec_kind == ctsk_none) |
1576dec7 | 2915 | { |
29438999 | 2916 | pedwarn (decl_loc, OPT_Wpedantic, |
21ca8540 | 2917 | "ISO C forbids member declarations with no members"); |
1576dec7 | 2918 | shadow_tag_warned (specs, pedantic); |
2919 | ret = NULL_TREE; | |
2920 | } | |
2921 | else | |
2922 | { | |
2923 | /* Support for unnamed structs or unions as members of | |
2924 | structs or unions (which is [a] useful and [b] supports | |
2925 | MS P-SDK). */ | |
e47ffaae | 2926 | tree attrs = NULL; |
d520c1f2 | 2927 | |
2928 | ret = grokfield (c_parser_peek_token (parser)->location, | |
2929 | build_id_declarator (NULL_TREE), specs, | |
e47ffaae | 2930 | NULL_TREE, &attrs); |
9a21152d | 2931 | if (ret) |
2932 | decl_attributes (&ret, attrs, 0); | |
1576dec7 | 2933 | } |
2934 | return ret; | |
2935 | } | |
b02d8973 | 2936 | |
2937 | /* Provide better error recovery. Note that a type name here is valid, | |
2938 | and will be treated as a field name. */ | |
2939 | if (specs->typespec_kind == ctsk_tagdef | |
2940 | && TREE_CODE (specs->type) != ENUMERAL_TYPE | |
2941 | && c_parser_next_token_starts_declspecs (parser) | |
2942 | && !c_parser_next_token_is (parser, CPP_NAME)) | |
2943 | { | |
2944 | c_parser_error (parser, "expected %<;%>, identifier or %<(%>"); | |
2945 | parser->error = false; | |
2946 | return NULL_TREE; | |
2947 | } | |
2948 | ||
1576dec7 | 2949 | pending_xref_error (); |
2950 | prefix_attrs = specs->attrs; | |
2951 | all_prefix_attrs = prefix_attrs; | |
2952 | specs->attrs = NULL_TREE; | |
2953 | decls = NULL_TREE; | |
2954 | while (true) | |
2955 | { | |
2956 | /* Declaring one or more declarators or un-named bit-fields. */ | |
2957 | struct c_declarator *declarator; | |
2958 | bool dummy = false; | |
2959 | if (c_parser_next_token_is (parser, CPP_COLON)) | |
2960 | declarator = build_id_declarator (NULL_TREE); | |
2961 | else | |
ae5ead32 | 2962 | declarator = c_parser_declarator (parser, |
2963 | specs->typespec_kind != ctsk_none, | |
1576dec7 | 2964 | C_DTR_NORMAL, &dummy); |
2965 | if (declarator == NULL) | |
2966 | { | |
2967 | c_parser_skip_to_end_of_block_or_statement (parser); | |
2968 | break; | |
2969 | } | |
2970 | if (c_parser_next_token_is (parser, CPP_COLON) | |
2971 | || c_parser_next_token_is (parser, CPP_COMMA) | |
2972 | || c_parser_next_token_is (parser, CPP_SEMICOLON) | |
2973 | || c_parser_next_token_is (parser, CPP_CLOSE_BRACE) | |
2974 | || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)) | |
2975 | { | |
2976 | tree postfix_attrs = NULL_TREE; | |
2977 | tree width = NULL_TREE; | |
2978 | tree d; | |
2979 | if (c_parser_next_token_is (parser, CPP_COLON)) | |
2980 | { | |
2981 | c_parser_consume_token (parser); | |
2982 | width = c_parser_expr_no_commas (parser, NULL).value; | |
2983 | } | |
2984 | if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)) | |
2985 | postfix_attrs = c_parser_attributes (parser); | |
d520c1f2 | 2986 | d = grokfield (c_parser_peek_token (parser)->location, |
2987 | declarator, specs, width, &all_prefix_attrs); | |
1576dec7 | 2988 | decl_attributes (&d, chainon (postfix_attrs, |
2989 | all_prefix_attrs), 0); | |
1767a056 | 2990 | DECL_CHAIN (d) = decls; |
1576dec7 | 2991 | decls = d; |
2992 | if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)) | |
2993 | all_prefix_attrs = chainon (c_parser_attributes (parser), | |
2994 | prefix_attrs); | |
2995 | else | |
2996 | all_prefix_attrs = prefix_attrs; | |
2997 | if (c_parser_next_token_is (parser, CPP_COMMA)) | |
2998 | c_parser_consume_token (parser); | |
2999 | else if (c_parser_next_token_is (parser, CPP_SEMICOLON) | |
3000 | || c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) | |
3001 | { | |
3002 | /* Semicolon consumed in caller. */ | |
3003 | break; | |
3004 | } | |
3005 | else | |
3006 | { | |
3007 | c_parser_error (parser, "expected %<,%>, %<;%> or %<}%>"); | |
3008 | break; | |
3009 | } | |
3010 | } | |
3011 | else | |
3012 | { | |
3013 | c_parser_error (parser, | |
3014 | "expected %<:%>, %<,%>, %<;%>, %<}%> or " | |
3015 | "%<__attribute__%>"); | |
3016 | break; | |
3017 | } | |
3018 | } | |
3019 | return decls; | |
3020 | } | |
3021 | ||
3022 | /* Parse a typeof specifier (a GNU extension). | |
3023 | ||
3024 | typeof-specifier: | |
3025 | typeof ( expression ) | |
3026 | typeof ( type-name ) | |
3027 | */ | |
3028 | ||
3029 | static struct c_typespec | |
3030 | c_parser_typeof_specifier (c_parser *parser) | |
3031 | { | |
3032 | struct c_typespec ret; | |
3033 | ret.kind = ctsk_typeof; | |
3034 | ret.spec = error_mark_node; | |
a75b1c71 | 3035 | ret.expr = NULL_TREE; |
3036 | ret.expr_const_operands = true; | |
1576dec7 | 3037 | gcc_assert (c_parser_next_token_is_keyword (parser, RID_TYPEOF)); |
3038 | c_parser_consume_token (parser); | |
48d94ede | 3039 | c_inhibit_evaluation_warnings++; |
1576dec7 | 3040 | in_typeof++; |
3041 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
3042 | { | |
48d94ede | 3043 | c_inhibit_evaluation_warnings--; |
1576dec7 | 3044 | in_typeof--; |
3045 | return ret; | |
3046 | } | |
26ee9e7a | 3047 | if (c_parser_next_tokens_start_typename (parser, cla_prefer_id)) |
1576dec7 | 3048 | { |
3049 | struct c_type_name *type = c_parser_type_name (parser); | |
48d94ede | 3050 | c_inhibit_evaluation_warnings--; |
1576dec7 | 3051 | in_typeof--; |
3052 | if (type != NULL) | |
3053 | { | |
a75b1c71 | 3054 | ret.spec = groktypename (type, &ret.expr, &ret.expr_const_operands); |
1576dec7 | 3055 | pop_maybe_used (variably_modified_type_p (ret.spec, NULL_TREE)); |
3056 | } | |
3057 | } | |
3058 | else | |
3059 | { | |
32d33ab2 | 3060 | bool was_vm; |
be9eba16 | 3061 | location_t here = c_parser_peek_token (parser)->location; |
1576dec7 | 3062 | struct c_expr expr = c_parser_expression (parser); |
48d94ede | 3063 | c_inhibit_evaluation_warnings--; |
1576dec7 | 3064 | in_typeof--; |
3065 | if (TREE_CODE (expr.value) == COMPONENT_REF | |
3066 | && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1))) | |
e3b80d49 | 3067 | error_at (here, "%<typeof%> applied to a bit-field"); |
abc6c64f | 3068 | mark_exp_read (expr.value); |
1576dec7 | 3069 | ret.spec = TREE_TYPE (expr.value); |
32d33ab2 | 3070 | was_vm = variably_modified_type_p (ret.spec, NULL_TREE); |
a75b1c71 | 3071 | /* This is returned with the type so that when the type is |
3072 | evaluated, this can be evaluated. */ | |
3073 | if (was_vm) | |
3074 | ret.expr = c_fully_fold (expr.value, false, &ret.expr_const_operands); | |
32d33ab2 | 3075 | pop_maybe_used (was_vm); |
45c5b823 | 3076 | /* For use in macros such as those in <stdatomic.h>, remove all |
3077 | qualifiers from atomic types. (const can be an issue for more macros | |
3078 | using typeof than just the <stdatomic.h> ones.) */ | |
b560fabd | 3079 | if (ret.spec != error_mark_node && TYPE_ATOMIC (ret.spec)) |
45c5b823 | 3080 | ret.spec = c_build_qualified_type (ret.spec, TYPE_UNQUALIFIED); |
1576dec7 | 3081 | } |
3082 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
3083 | return ret; | |
3084 | } | |
3085 | ||
83e25171 | 3086 | /* Parse an alignment-specifier. |
3087 | ||
32074525 | 3088 | C11 6.7.5: |
83e25171 | 3089 | |
3090 | alignment-specifier: | |
3091 | _Alignas ( type-name ) | |
3092 | _Alignas ( constant-expression ) | |
3093 | */ | |
3094 | ||
3095 | static tree | |
3096 | c_parser_alignas_specifier (c_parser * parser) | |
3097 | { | |
3098 | tree ret = error_mark_node; | |
3099 | location_t loc = c_parser_peek_token (parser)->location; | |
3100 | gcc_assert (c_parser_next_token_is_keyword (parser, RID_ALIGNAS)); | |
3101 | c_parser_consume_token (parser); | |
508ea33a | 3102 | if (flag_isoc99) |
3103 | pedwarn_c99 (loc, OPT_Wpedantic, | |
83e25171 | 3104 | "ISO C99 does not support %<_Alignas%>"); |
508ea33a | 3105 | else |
3106 | pedwarn_c99 (loc, OPT_Wpedantic, | |
83e25171 | 3107 | "ISO C90 does not support %<_Alignas%>"); |
83e25171 | 3108 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) |
3109 | return ret; | |
3110 | if (c_parser_next_tokens_start_typename (parser, cla_prefer_id)) | |
3111 | { | |
3112 | struct c_type_name *type = c_parser_type_name (parser); | |
3113 | if (type != NULL) | |
a179a7dc | 3114 | ret = c_sizeof_or_alignof_type (loc, groktypename (type, NULL, NULL), |
3115 | false, true, 1); | |
83e25171 | 3116 | } |
3117 | else | |
3118 | ret = c_parser_expr_no_commas (parser, NULL).value; | |
3119 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
3120 | return ret; | |
3121 | } | |
3122 | ||
1576dec7 | 3123 | /* Parse a declarator, possibly an abstract declarator (C90 6.5.4, |
3124 | 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may | |
3125 | be redeclared; otherwise it may not. KIND indicates which kind of | |
3126 | declarator is wanted. Returns a valid declarator except in the | |
3127 | case of a syntax error in which case NULL is returned. *SEEN_ID is | |
3128 | set to true if an identifier being declared is seen; this is used | |
3129 | to diagnose bad forms of abstract array declarators and to | |
3130 | determine whether an identifier list is syntactically permitted. | |
3131 | ||
3132 | declarator: | |
3133 | pointer[opt] direct-declarator | |
3134 | ||
3135 | direct-declarator: | |
3136 | identifier | |
3137 | ( attributes[opt] declarator ) | |
3138 | direct-declarator array-declarator | |
3139 | direct-declarator ( parameter-type-list ) | |
3140 | direct-declarator ( identifier-list[opt] ) | |
3141 | ||
3142 | pointer: | |
3143 | * type-qualifier-list[opt] | |
3144 | * type-qualifier-list[opt] pointer | |
3145 | ||
3146 | type-qualifier-list: | |
3147 | type-qualifier | |
3148 | attributes | |
3149 | type-qualifier-list type-qualifier | |
3150 | type-qualifier-list attributes | |
3151 | ||
43d03c23 | 3152 | array-declarator: |
3153 | [ type-qualifier-list[opt] assignment-expression[opt] ] | |
3154 | [ static type-qualifier-list[opt] assignment-expression ] | |
3155 | [ type-qualifier-list static assignment-expression ] | |
3156 | [ type-qualifier-list[opt] * ] | |
3157 | ||
1576dec7 | 3158 | parameter-type-list: |
3159 | parameter-list | |
3160 | parameter-list , ... | |
3161 | ||
3162 | parameter-list: | |
3163 | parameter-declaration | |
3164 | parameter-list , parameter-declaration | |
3165 | ||
3166 | parameter-declaration: | |
3167 | declaration-specifiers declarator attributes[opt] | |
3168 | declaration-specifiers abstract-declarator[opt] attributes[opt] | |
3169 | ||
3170 | identifier-list: | |
3171 | identifier | |
3172 | identifier-list , identifier | |
3173 | ||
3174 | abstract-declarator: | |
3175 | pointer | |
3176 | pointer[opt] direct-abstract-declarator | |
3177 | ||
3178 | direct-abstract-declarator: | |
3179 | ( attributes[opt] abstract-declarator ) | |
3180 | direct-abstract-declarator[opt] array-declarator | |
3181 | direct-abstract-declarator[opt] ( parameter-type-list[opt] ) | |
3182 | ||
3183 | GNU extensions: | |
3184 | ||
3185 | direct-declarator: | |
3186 | direct-declarator ( parameter-forward-declarations | |
3187 | parameter-type-list[opt] ) | |
3188 | ||
3189 | direct-abstract-declarator: | |
a0c938f0 | 3190 | direct-abstract-declarator[opt] ( parameter-forward-declarations |
1576dec7 | 3191 | parameter-type-list[opt] ) |
3192 | ||
3193 | parameter-forward-declarations: | |
3194 | parameter-list ; | |
3195 | parameter-forward-declarations parameter-list ; | |
3196 | ||
3197 | The uses of attributes shown above are GNU extensions. | |
3198 | ||
3199 | Some forms of array declarator are not included in C99 in the | |
3200 | syntax for abstract declarators; these are disallowed elsewhere. | |
3201 | This may be a defect (DR#289). | |
3202 | ||
3203 | This function also accepts an omitted abstract declarator as being | |
3204 | an abstract declarator, although not part of the formal syntax. */ | |
3205 | ||
3206 | static struct c_declarator * | |
3207 | c_parser_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind, | |
3208 | bool *seen_id) | |
3209 | { | |
3210 | /* Parse any initial pointer part. */ | |
3211 | if (c_parser_next_token_is (parser, CPP_MULT)) | |
3212 | { | |
3213 | struct c_declspecs *quals_attrs = build_null_declspecs (); | |
3214 | struct c_declarator *inner; | |
3215 | c_parser_consume_token (parser); | |
43d03c23 | 3216 | c_parser_declspecs (parser, quals_attrs, false, false, true, |
4fba5eb9 | 3217 | false, false, cla_prefer_id); |
1576dec7 | 3218 | inner = c_parser_declarator (parser, type_seen_p, kind, seen_id); |
3219 | if (inner == NULL) | |
3220 | return NULL; | |
3221 | else | |
3222 | return make_pointer_declarator (quals_attrs, inner); | |
3223 | } | |
3224 | /* Now we have a direct declarator, direct abstract declarator or | |
3225 | nothing (which counts as a direct abstract declarator here). */ | |
3226 | return c_parser_direct_declarator (parser, type_seen_p, kind, seen_id); | |
3227 | } | |
3228 | ||
3229 | /* Parse a direct declarator or direct abstract declarator; arguments | |
3230 | as c_parser_declarator. */ | |
3231 | ||
3232 | static struct c_declarator * | |
3233 | c_parser_direct_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind, | |
3234 | bool *seen_id) | |
3235 | { | |
3236 | /* The direct declarator must start with an identifier (possibly | |
3237 | omitted) or a parenthesized declarator (possibly abstract). In | |
3238 | an ordinary declarator, initial parentheses must start a | |
3239 | parenthesized declarator. In an abstract declarator or parameter | |
3240 | declarator, they could start a parenthesized declarator or a | |
3241 | parameter list. To tell which, the open parenthesis and any | |
3242 | following attributes must be read. If a declaration specifier | |
3243 | follows, then it is a parameter list; if the specifier is a | |
3244 | typedef name, there might be an ambiguity about redeclaring it, | |
3245 | which is resolved in the direction of treating it as a typedef | |
3246 | name. If a close parenthesis follows, it is also an empty | |
3247 | parameter list, as the syntax does not permit empty abstract | |
442e3cb9 | 3248 | declarators. Otherwise, it is a parenthesized declarator (in |
1576dec7 | 3249 | which case the analysis may be repeated inside it, recursively). |
3250 | ||
3251 | ??? There is an ambiguity in a parameter declaration "int | |
3252 | (__attribute__((foo)) x)", where x is not a typedef name: it | |
3253 | could be an abstract declarator for a function, or declare x with | |
3254 | parentheses. The proper resolution of this ambiguity needs | |
3255 | documenting. At present we follow an accident of the old | |
3256 | parser's implementation, whereby the first parameter must have | |
3257 | some declaration specifiers other than just attributes. Thus as | |
442e3cb9 | 3258 | a parameter declaration it is treated as a parenthesized |
1576dec7 | 3259 | parameter named x, and as an abstract declarator it is |
3260 | rejected. | |
3261 | ||
3262 | ??? Also following the old parser, attributes inside an empty | |
3263 | parameter list are ignored, making it a list not yielding a | |
3264 | prototype, rather than giving an error or making it have one | |
3265 | parameter with implicit type int. | |
3266 | ||
3267 | ??? Also following the old parser, typedef names may be | |
3268 | redeclared in declarators, but not Objective-C class names. */ | |
3269 | ||
3270 | if (kind != C_DTR_ABSTRACT | |
3271 | && c_parser_next_token_is (parser, CPP_NAME) | |
3272 | && ((type_seen_p | |
e147d6aa | 3273 | && (c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME |
3274 | || c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME)) | |
1576dec7 | 3275 | || c_parser_peek_token (parser)->id_kind == C_ID_ID)) |
3276 | { | |
3277 | struct c_declarator *inner | |
3278 | = build_id_declarator (c_parser_peek_token (parser)->value); | |
3279 | *seen_id = true; | |
6342afac | 3280 | inner->id_loc = c_parser_peek_token (parser)->location; |
1576dec7 | 3281 | c_parser_consume_token (parser); |
3282 | return c_parser_direct_declarator_inner (parser, *seen_id, inner); | |
3283 | } | |
3284 | ||
3285 | if (kind != C_DTR_NORMAL | |
3286 | && c_parser_next_token_is (parser, CPP_OPEN_SQUARE)) | |
3287 | { | |
3288 | struct c_declarator *inner = build_id_declarator (NULL_TREE); | |
3289 | return c_parser_direct_declarator_inner (parser, *seen_id, inner); | |
3290 | } | |
3291 | ||
3292 | /* Either we are at the end of an abstract declarator, or we have | |
3293 | parentheses. */ | |
3294 | ||
3295 | if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) | |
3296 | { | |
3297 | tree attrs; | |
3298 | struct c_declarator *inner; | |
3299 | c_parser_consume_token (parser); | |
3300 | attrs = c_parser_attributes (parser); | |
3301 | if (kind != C_DTR_NORMAL | |
3302 | && (c_parser_next_token_starts_declspecs (parser) | |
3303 | || c_parser_next_token_is (parser, CPP_CLOSE_PAREN))) | |
3304 | { | |
3305 | struct c_arg_info *args | |
3306 | = c_parser_parms_declarator (parser, kind == C_DTR_NORMAL, | |
3307 | attrs); | |
3308 | if (args == NULL) | |
3309 | return NULL; | |
3310 | else | |
3311 | { | |
3312 | inner | |
3313 | = build_function_declarator (args, | |
3314 | build_id_declarator (NULL_TREE)); | |
3315 | return c_parser_direct_declarator_inner (parser, *seen_id, | |
3316 | inner); | |
3317 | } | |
3318 | } | |
3319 | /* A parenthesized declarator. */ | |
3320 | inner = c_parser_declarator (parser, type_seen_p, kind, seen_id); | |
3321 | if (inner != NULL && attrs != NULL) | |
3322 | inner = build_attrs_declarator (attrs, inner); | |
3323 | if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) | |
3324 | { | |
3325 | c_parser_consume_token (parser); | |
3326 | if (inner == NULL) | |
3327 | return NULL; | |
3328 | else | |
3329 | return c_parser_direct_declarator_inner (parser, *seen_id, inner); | |
3330 | } | |
3331 | else | |
3332 | { | |
3333 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, | |
3334 | "expected %<)%>"); | |
3335 | return NULL; | |
3336 | } | |
3337 | } | |
3338 | else | |
3339 | { | |
3340 | if (kind == C_DTR_NORMAL) | |
3341 | { | |
3342 | c_parser_error (parser, "expected identifier or %<(%>"); | |
3343 | return NULL; | |
3344 | } | |
3345 | else | |
3346 | return build_id_declarator (NULL_TREE); | |
3347 | } | |
3348 | } | |
3349 | ||
3350 | /* Parse part of a direct declarator or direct abstract declarator, | |
3351 | given that some (in INNER) has already been parsed; ID_PRESENT is | |
3352 | true if an identifier is present, false for an abstract | |
3353 | declarator. */ | |
3354 | ||
3355 | static struct c_declarator * | |
3356 | c_parser_direct_declarator_inner (c_parser *parser, bool id_present, | |
3357 | struct c_declarator *inner) | |
3358 | { | |
3359 | /* Parse a sequence of array declarators and parameter lists. */ | |
3360 | if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE)) | |
3361 | { | |
48e1416a | 3362 | location_t brace_loc = c_parser_peek_token (parser)->location; |
1576dec7 | 3363 | struct c_declarator *declarator; |
3364 | struct c_declspecs *quals_attrs = build_null_declspecs (); | |
3365 | bool static_seen; | |
3366 | bool star_seen; | |
b560fabd | 3367 | struct c_expr dimen; |
3368 | dimen.value = NULL_TREE; | |
3369 | dimen.original_code = ERROR_MARK; | |
3370 | dimen.original_type = NULL_TREE; | |
1576dec7 | 3371 | c_parser_consume_token (parser); |
43d03c23 | 3372 | c_parser_declspecs (parser, quals_attrs, false, false, true, |
4fba5eb9 | 3373 | false, false, cla_prefer_id); |
1576dec7 | 3374 | static_seen = c_parser_next_token_is_keyword (parser, RID_STATIC); |
3375 | if (static_seen) | |
3376 | c_parser_consume_token (parser); | |
3377 | if (static_seen && !quals_attrs->declspecs_seen_p) | |
43d03c23 | 3378 | c_parser_declspecs (parser, quals_attrs, false, false, true, |
4fba5eb9 | 3379 | false, false, cla_prefer_id); |
1576dec7 | 3380 | if (!quals_attrs->declspecs_seen_p) |
3381 | quals_attrs = NULL; | |
3382 | /* If "static" is present, there must be an array dimension. | |
3383 | Otherwise, there may be a dimension, "*", or no | |
3384 | dimension. */ | |
3385 | if (static_seen) | |
3386 | { | |
3387 | star_seen = false; | |
b560fabd | 3388 | dimen = c_parser_expr_no_commas (parser, NULL); |
1576dec7 | 3389 | } |
3390 | else | |
3391 | { | |
3392 | if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE)) | |
3393 | { | |
b560fabd | 3394 | dimen.value = NULL_TREE; |
1576dec7 | 3395 | star_seen = false; |
3396 | } | |
a89e6c15 | 3397 | else if (flag_cilkplus |
3c6d4197 | 3398 | && c_parser_next_token_is (parser, CPP_COLON)) |
3399 | { | |
b560fabd | 3400 | dimen.value = error_mark_node; |
3c6d4197 | 3401 | star_seen = false; |
3402 | error_at (c_parser_peek_token (parser)->location, | |
3403 | "array notations cannot be used in declaration"); | |
3404 | c_parser_consume_token (parser); | |
3405 | } | |
1576dec7 | 3406 | else if (c_parser_next_token_is (parser, CPP_MULT)) |
3407 | { | |
3408 | if (c_parser_peek_2nd_token (parser)->type == CPP_CLOSE_SQUARE) | |
3409 | { | |
b560fabd | 3410 | dimen.value = NULL_TREE; |
1576dec7 | 3411 | star_seen = true; |
3412 | c_parser_consume_token (parser); | |
3413 | } | |
3414 | else | |
3415 | { | |
3416 | star_seen = false; | |
b560fabd | 3417 | dimen = c_parser_expr_no_commas (parser, NULL); |
1576dec7 | 3418 | } |
3419 | } | |
3420 | else | |
3421 | { | |
3422 | star_seen = false; | |
b560fabd | 3423 | dimen = c_parser_expr_no_commas (parser, NULL); |
1576dec7 | 3424 | } |
3425 | } | |
3426 | if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE)) | |
3427 | c_parser_consume_token (parser); | |
a89e6c15 | 3428 | else if (flag_cilkplus |
3c6d4197 | 3429 | && c_parser_next_token_is (parser, CPP_COLON)) |
3430 | { | |
3431 | error_at (c_parser_peek_token (parser)->location, | |
3432 | "array notations cannot be used in declaration"); | |
3433 | c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL); | |
3434 | return NULL; | |
3435 | } | |
1576dec7 | 3436 | else |
3437 | { | |
3438 | c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, | |
3439 | "expected %<]%>"); | |
3440 | return NULL; | |
3441 | } | |
b560fabd | 3442 | if (dimen.value) |
3443 | dimen = convert_lvalue_to_rvalue (brace_loc, dimen, true, true); | |
3444 | declarator = build_array_declarator (brace_loc, dimen.value, quals_attrs, | |
e60a6f7b | 3445 | static_seen, star_seen); |
32d33ab2 | 3446 | if (declarator == NULL) |
3447 | return NULL; | |
e6c172ed | 3448 | inner = set_array_declarator_inner (declarator, inner); |
1576dec7 | 3449 | return c_parser_direct_declarator_inner (parser, id_present, inner); |
3450 | } | |
3451 | else if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) | |
3452 | { | |
3453 | tree attrs; | |
3454 | struct c_arg_info *args; | |
3455 | c_parser_consume_token (parser); | |
3456 | attrs = c_parser_attributes (parser); | |
3457 | args = c_parser_parms_declarator (parser, id_present, attrs); | |
3458 | if (args == NULL) | |
3459 | return NULL; | |
3460 | else | |
3461 | { | |
3462 | inner = build_function_declarator (args, inner); | |
3463 | return c_parser_direct_declarator_inner (parser, id_present, inner); | |
3464 | } | |
3465 | } | |
3466 | return inner; | |
3467 | } | |
3468 | ||
3469 | /* Parse a parameter list or identifier list, including the closing | |
3470 | parenthesis but not the opening one. ATTRS are the attributes at | |
3471 | the start of the list. ID_LIST_OK is true if an identifier list is | |
3472 | acceptable; such a list must not have attributes at the start. */ | |
3473 | ||
3474 | static struct c_arg_info * | |
3475 | c_parser_parms_declarator (c_parser *parser, bool id_list_ok, tree attrs) | |
3476 | { | |
3477 | push_scope (); | |
3478 | declare_parm_level (); | |
3479 | /* If the list starts with an identifier, it is an identifier list. | |
3480 | Otherwise, it is either a prototype list or an empty list. */ | |
3481 | if (id_list_ok | |
3482 | && !attrs | |
3483 | && c_parser_next_token_is (parser, CPP_NAME) | |
26ee9e7a | 3484 | && c_parser_peek_token (parser)->id_kind == C_ID_ID |
3485 | ||
3486 | /* Look ahead to detect typos in type names. */ | |
3487 | && c_parser_peek_2nd_token (parser)->type != CPP_NAME | |
3488 | && c_parser_peek_2nd_token (parser)->type != CPP_MULT | |
3489 | && c_parser_peek_2nd_token (parser)->type != CPP_OPEN_PAREN | |
3490 | && c_parser_peek_2nd_token (parser)->type != CPP_OPEN_SQUARE) | |
1576dec7 | 3491 | { |
caa9f6a7 | 3492 | tree list = NULL_TREE, *nextp = &list; |
1576dec7 | 3493 | while (c_parser_next_token_is (parser, CPP_NAME) |
3494 | && c_parser_peek_token (parser)->id_kind == C_ID_ID) | |
3495 | { | |
caa9f6a7 | 3496 | *nextp = build_tree_list (NULL_TREE, |
3497 | c_parser_peek_token (parser)->value); | |
3498 | nextp = & TREE_CHAIN (*nextp); | |
1576dec7 | 3499 | c_parser_consume_token (parser); |
3500 | if (c_parser_next_token_is_not (parser, CPP_COMMA)) | |
3501 | break; | |
3502 | c_parser_consume_token (parser); | |
3503 | if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) | |
3504 | { | |
3505 | c_parser_error (parser, "expected identifier"); | |
3506 | break; | |
3507 | } | |
3508 | } | |
3509 | if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) | |
3510 | { | |
cfbfcd0b | 3511 | struct c_arg_info *ret = build_arg_info (); |
1576dec7 | 3512 | ret->types = list; |
1576dec7 | 3513 | c_parser_consume_token (parser); |
3514 | pop_scope (); | |
3515 | return ret; | |
3516 | } | |
3517 | else | |
3518 | { | |
3519 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, | |
3520 | "expected %<)%>"); | |
3521 | pop_scope (); | |
3522 | return NULL; | |
3523 | } | |
3524 | } | |
3525 | else | |
3526 | { | |
4232a958 | 3527 | struct c_arg_info *ret = c_parser_parms_list_declarator (parser, attrs, |
3528 | NULL); | |
1576dec7 | 3529 | pop_scope (); |
3530 | return ret; | |
3531 | } | |
3532 | } | |
3533 | ||
3534 | /* Parse a parameter list (possibly empty), including the closing | |
3535 | parenthesis but not the opening one. ATTRS are the attributes at | |
4232a958 | 3536 | the start of the list. EXPR is NULL or an expression that needs to |
3537 | be evaluated for the side effects of array size expressions in the | |
3538 | parameters. */ | |
1576dec7 | 3539 | |
3540 | static struct c_arg_info * | |
4232a958 | 3541 | c_parser_parms_list_declarator (c_parser *parser, tree attrs, tree expr) |
1576dec7 | 3542 | { |
0e28b26d | 3543 | bool bad_parm = false; |
4232a958 | 3544 | |
1576dec7 | 3545 | /* ??? Following the old parser, forward parameter declarations may |
3546 | use abstract declarators, and if no real parameter declarations | |
3547 | follow the forward declarations then this is not diagnosed. Also | |
3548 | note as above that attributes are ignored as the only contents of | |
3549 | the parentheses, or as the only contents after forward | |
3550 | declarations. */ | |
3551 | if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) | |
3552 | { | |
cfbfcd0b | 3553 | struct c_arg_info *ret = build_arg_info (); |
1576dec7 | 3554 | c_parser_consume_token (parser); |
3555 | return ret; | |
3556 | } | |
3557 | if (c_parser_next_token_is (parser, CPP_ELLIPSIS)) | |
3558 | { | |
cfbfcd0b | 3559 | struct c_arg_info *ret = build_arg_info (); |
c7964868 | 3560 | |
3561 | if (flag_allow_parameterless_variadic_functions) | |
3562 | { | |
3563 | /* F (...) is allowed. */ | |
3564 | ret->types = NULL_TREE; | |
3565 | } | |
3566 | else | |
3567 | { | |
3568 | /* Suppress -Wold-style-definition for this case. */ | |
3569 | ret->types = error_mark_node; | |
3570 | error_at (c_parser_peek_token (parser)->location, | |
3571 | "ISO C requires a named argument before %<...%>"); | |
3572 | } | |
1576dec7 | 3573 | c_parser_consume_token (parser); |
3574 | if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) | |
3575 | { | |
3576 | c_parser_consume_token (parser); | |
3577 | return ret; | |
3578 | } | |
3579 | else | |
3580 | { | |
3581 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, | |
3582 | "expected %<)%>"); | |
3583 | return NULL; | |
3584 | } | |
3585 | } | |
3586 | /* Nonempty list of parameters, either terminated with semicolon | |
3587 | (forward declarations; recurse) or with close parenthesis (normal | |
3588 | function) or with ", ... )" (variadic function). */ | |
3589 | while (true) | |
3590 | { | |
3591 | /* Parse a parameter. */ | |
3592 | struct c_parm *parm = c_parser_parameter_declaration (parser, attrs); | |
3593 | attrs = NULL_TREE; | |
0e28b26d | 3594 | if (parm == NULL) |
3595 | bad_parm = true; | |
3596 | else | |
4232a958 | 3597 | push_parm_decl (parm, &expr); |
1576dec7 | 3598 | if (c_parser_next_token_is (parser, CPP_SEMICOLON)) |
3599 | { | |
3600 | tree new_attrs; | |
3601 | c_parser_consume_token (parser); | |
c4a8f0ba | 3602 | mark_forward_parm_decls (); |
1576dec7 | 3603 | new_attrs = c_parser_attributes (parser); |
4232a958 | 3604 | return c_parser_parms_list_declarator (parser, new_attrs, expr); |
1576dec7 | 3605 | } |
3606 | if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) | |
3607 | { | |
3608 | c_parser_consume_token (parser); | |
0e28b26d | 3609 | if (bad_parm) |
4232a958 | 3610 | return NULL; |
0e28b26d | 3611 | else |
4232a958 | 3612 | return get_parm_info (false, expr); |
1576dec7 | 3613 | } |
3614 | if (!c_parser_require (parser, CPP_COMMA, | |
3615 | "expected %<;%>, %<,%> or %<)%>")) | |
3616 | { | |
3617 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); | |
3618 | return NULL; | |
3619 | } | |
3620 | if (c_parser_next_token_is (parser, CPP_ELLIPSIS)) | |
3621 | { | |
3622 | c_parser_consume_token (parser); | |
3623 | if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) | |
3624 | { | |
3625 | c_parser_consume_token (parser); | |
0e28b26d | 3626 | if (bad_parm) |
4232a958 | 3627 | return NULL; |
0e28b26d | 3628 | else |
4232a958 | 3629 | return get_parm_info (true, expr); |
1576dec7 | 3630 | } |
3631 | else | |
3632 | { | |
3633 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, | |
3634 | "expected %<)%>"); | |
3635 | return NULL; | |
3636 | } | |
3637 | } | |
3638 | } | |
3639 | } | |
3640 | ||
3641 | /* Parse a parameter declaration. ATTRS are the attributes at the | |
3642 | start of the declaration if it is the first parameter. */ | |
3643 | ||
3644 | static struct c_parm * | |
3645 | c_parser_parameter_declaration (c_parser *parser, tree attrs) | |
3646 | { | |
3647 | struct c_declspecs *specs; | |
3648 | struct c_declarator *declarator; | |
3649 | tree prefix_attrs; | |
3650 | tree postfix_attrs = NULL_TREE; | |
3651 | bool dummy = false; | |
dd8e8868 | 3652 | |
3653 | /* Accept #pragmas between parameter declarations. */ | |
3654 | while (c_parser_next_token_is (parser, CPP_PRAGMA)) | |
bc7bff74 | 3655 | c_parser_pragma (parser, pragma_param); |
dd8e8868 | 3656 | |
1576dec7 | 3657 | if (!c_parser_next_token_starts_declspecs (parser)) |
3658 | { | |
0e28b26d | 3659 | c_token *token = c_parser_peek_token (parser); |
3660 | if (parser->error) | |
3661 | return NULL; | |
3662 | c_parser_set_source_position_from_token (token); | |
26ee9e7a | 3663 | if (c_parser_next_tokens_start_typename (parser, cla_prefer_type)) |
0e28b26d | 3664 | { |
8f1128f8 | 3665 | error_at (token->location, "unknown type name %qE", token->value); |
0e28b26d | 3666 | parser->error = true; |
3667 | } | |
1576dec7 | 3668 | /* ??? In some Objective-C cases '...' isn't applicable so there |
3669 | should be a different message. */ | |
0e28b26d | 3670 | else |
3671 | c_parser_error (parser, | |
3672 | "expected declaration specifiers or %<...%>"); | |
1576dec7 | 3673 | c_parser_skip_to_end_of_parameter (parser); |
3674 | return NULL; | |
3675 | } | |
3676 | specs = build_null_declspecs (); | |
3677 | if (attrs) | |
3678 | { | |
a60f3e81 | 3679 | declspecs_add_attrs (input_location, specs, attrs); |
1576dec7 | 3680 | attrs = NULL_TREE; |
3681 | } | |
4fba5eb9 | 3682 | c_parser_declspecs (parser, specs, true, true, true, true, false, |
43d03c23 | 3683 | cla_nonabstract_decl); |
1576dec7 | 3684 | finish_declspecs (specs); |
3685 | pending_xref_error (); | |
3686 | prefix_attrs = specs->attrs; | |
3687 | specs->attrs = NULL_TREE; | |
ae5ead32 | 3688 | declarator = c_parser_declarator (parser, |
3689 | specs->typespec_kind != ctsk_none, | |
1576dec7 | 3690 | C_DTR_PARM, &dummy); |
3691 | if (declarator == NULL) | |
3692 | { | |
3693 | c_parser_skip_until_found (parser, CPP_COMMA, NULL); | |
3694 | return NULL; | |
3695 | } | |
3696 | if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)) | |
3697 | postfix_attrs = c_parser_attributes (parser); | |
3698 | return build_c_parm (specs, chainon (postfix_attrs, prefix_attrs), | |
3699 | declarator); | |
3700 | } | |
3701 | ||
3702 | /* Parse a string literal in an asm expression. It should not be | |
3703 | translated, and wide string literals are an error although | |
3704 | permitted by the syntax. This is a GNU extension. | |
3705 | ||
3706 | asm-string-literal: | |
3707 | string-literal | |
3708 | ||
3709 | ??? At present, following the old parser, the caller needs to have | |
8115b8be | 3710 | set lex_untranslated_string to 1. It would be better to follow the |
3711 | C++ parser rather than using this kludge. */ | |
1576dec7 | 3712 | |
3713 | static tree | |
3714 | c_parser_asm_string_literal (c_parser *parser) | |
3715 | { | |
3716 | tree str; | |
88c86c27 | 3717 | int save_flag = warn_overlength_strings; |
3718 | warn_overlength_strings = 0; | |
1576dec7 | 3719 | if (c_parser_next_token_is (parser, CPP_STRING)) |
3720 | { | |
3721 | str = c_parser_peek_token (parser)->value; | |
3722 | c_parser_consume_token (parser); | |
3723 | } | |
3724 | else if (c_parser_next_token_is (parser, CPP_WSTRING)) | |
3725 | { | |
e3b80d49 | 3726 | error_at (c_parser_peek_token (parser)->location, |
3727 | "wide string literal in %<asm%>"); | |
1576dec7 | 3728 | str = build_string (1, ""); |
3729 | c_parser_consume_token (parser); | |
3730 | } | |
3731 | else | |
3732 | { | |
3733 | c_parser_error (parser, "expected string literal"); | |
3734 | str = NULL_TREE; | |
3735 | } | |
88c86c27 | 3736 | warn_overlength_strings = save_flag; |
1576dec7 | 3737 | return str; |
3738 | } | |
3739 | ||
3740 | /* Parse a simple asm expression. This is used in restricted | |
3741 | contexts, where a full expression with inputs and outputs does not | |
3742 | make sense. This is a GNU extension. | |
3743 | ||
3744 | simple-asm-expr: | |
3745 | asm ( asm-string-literal ) | |
3746 | */ | |
3747 | ||
3748 | static tree | |
3749 | c_parser_simple_asm_expr (c_parser *parser) | |
3750 | { | |
3751 | tree str; | |
3752 | gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM)); | |
3753 | /* ??? Follow the C++ parser rather than using the | |
8115b8be | 3754 | lex_untranslated_string kludge. */ |
3755 | parser->lex_untranslated_string = true; | |
1576dec7 | 3756 | c_parser_consume_token (parser); |
3757 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
3758 | { | |
8115b8be | 3759 | parser->lex_untranslated_string = false; |
1576dec7 | 3760 | return NULL_TREE; |
3761 | } | |
3762 | str = c_parser_asm_string_literal (parser); | |
8115b8be | 3763 | parser->lex_untranslated_string = false; |
1576dec7 | 3764 | if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>")) |
3765 | { | |
3766 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); | |
3767 | return NULL_TREE; | |
3768 | } | |
3769 | return str; | |
3770 | } | |
3771 | ||
4c0315d0 | 3772 | static tree |
3773 | c_parser_attribute_any_word (c_parser *parser) | |
3774 | { | |
3775 | tree attr_name = NULL_TREE; | |
3776 | ||
3777 | if (c_parser_next_token_is (parser, CPP_KEYWORD)) | |
3778 | { | |
3779 | /* ??? See comment above about what keywords are accepted here. */ | |
3780 | bool ok; | |
3781 | switch (c_parser_peek_token (parser)->keyword) | |
3782 | { | |
3783 | case RID_STATIC: | |
3784 | case RID_UNSIGNED: | |
3785 | case RID_LONG: | |
4c0315d0 | 3786 | case RID_CONST: |
3787 | case RID_EXTERN: | |
3788 | case RID_REGISTER: | |
3789 | case RID_TYPEDEF: | |
3790 | case RID_SHORT: | |
3791 | case RID_INLINE: | |
3792 | case RID_NORETURN: | |
3793 | case RID_VOLATILE: | |
3794 | case RID_SIGNED: | |
3795 | case RID_AUTO: | |
3796 | case RID_RESTRICT: | |
3797 | case RID_COMPLEX: | |
3798 | case RID_THREAD: | |
3799 | case RID_INT: | |
3800 | case RID_CHAR: | |
3801 | case RID_FLOAT: | |
3802 | case RID_DOUBLE: | |
3803 | case RID_VOID: | |
3804 | case RID_DFLOAT32: | |
3805 | case RID_DFLOAT64: | |
3806 | case RID_DFLOAT128: | |
3807 | case RID_BOOL: | |
3808 | case RID_FRACT: | |
3809 | case RID_ACCUM: | |
3810 | case RID_SAT: | |
3811 | case RID_TRANSACTION_ATOMIC: | |
3812 | case RID_TRANSACTION_CANCEL: | |
b560fabd | 3813 | case RID_ATOMIC: |
4fba5eb9 | 3814 | case RID_AUTO_TYPE: |
9f75f026 | 3815 | case RID_INT_N_0: |
3816 | case RID_INT_N_1: | |
3817 | case RID_INT_N_2: | |
3818 | case RID_INT_N_3: | |
4c0315d0 | 3819 | ok = true; |
3820 | break; | |
3821 | default: | |
3822 | ok = false; | |
3823 | break; | |
3824 | } | |
3825 | if (!ok) | |
3826 | return NULL_TREE; | |
3827 | ||
3828 | /* Accept __attribute__((__const)) as __attribute__((const)) etc. */ | |
3829 | attr_name = ridpointers[(int) c_parser_peek_token (parser)->keyword]; | |
3830 | } | |
3831 | else if (c_parser_next_token_is (parser, CPP_NAME)) | |
3832 | attr_name = c_parser_peek_token (parser)->value; | |
3833 | ||
3834 | return attr_name; | |
3835 | } | |
3836 | ||
74acc703 | 3837 | /* Returns true of NAME is an IDENTIFIER_NODE with identiifer "vector," |
3838 | "__vector" or "__vector__." */ | |
3839 | ||
3840 | static inline bool | |
3841 | is_cilkplus_vector_p (tree name) | |
3842 | { | |
a89e6c15 | 3843 | if (flag_cilkplus && is_attribute_p ("vector", name)) |
74acc703 | 3844 | return true; |
3845 | return false; | |
3846 | } | |
3847 | ||
3848 | #define CILK_SIMD_FN_CLAUSE_MASK \ | |
3849 | ((OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_VECTORLENGTH) \ | |
3850 | | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_LINEAR) \ | |
3851 | | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_UNIFORM) \ | |
3852 | | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_MASK) \ | |
3853 | | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_NOMASK)) | |
3854 | ||
3855 | /* Parses the vector attribute of SIMD enabled functions in Cilk Plus. | |
3856 | VEC_TOKEN is the "vector" token that is replaced with "simd" and | |
3857 | pushed into the token list. | |
3858 | Syntax: | |
3859 | vector | |
3860 | vector (<vector attributes>). */ | |
3861 | ||
3862 | static void | |
3863 | c_parser_cilk_simd_fn_vector_attrs (c_parser *parser, c_token vec_token) | |
3864 | { | |
3865 | gcc_assert (is_cilkplus_vector_p (vec_token.value)); | |
3866 | ||
3867 | int paren_scope = 0; | |
3868 | vec_safe_push (parser->cilk_simd_fn_tokens, vec_token); | |
3869 | /* Consume the "vector" token. */ | |
3870 | c_parser_consume_token (parser); | |
3871 | ||
3872 | if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) | |
3873 | { | |
3874 | c_parser_consume_token (parser); | |
3875 | paren_scope++; | |
3876 | } | |
3877 | while (paren_scope > 0) | |
3878 | { | |
3879 | c_token *token = c_parser_peek_token (parser); | |
3880 | if (token->type == CPP_OPEN_PAREN) | |
3881 | paren_scope++; | |
3882 | else if (token->type == CPP_CLOSE_PAREN) | |
3883 | paren_scope--; | |
3884 | /* Do not push the last ')' since we are not pushing the '('. */ | |
3885 | if (!(token->type == CPP_CLOSE_PAREN && paren_scope == 0)) | |
3886 | vec_safe_push (parser->cilk_simd_fn_tokens, *token); | |
3887 | c_parser_consume_token (parser); | |
3888 | } | |
3889 | ||
3890 | /* Since we are converting an attribute to a pragma, we need to end the | |
3891 | attribute with PRAGMA_EOL. */ | |
3892 | c_token eol_token; | |
3893 | memset (&eol_token, 0, sizeof (eol_token)); | |
3894 | eol_token.type = CPP_PRAGMA_EOL; | |
3895 | vec_safe_push (parser->cilk_simd_fn_tokens, eol_token); | |
3896 | } | |
3897 | ||
3898 | /* Add 2 CPP_EOF at the end of PARSER->ELEM_FN_TOKENS vector. */ | |
3899 | ||
3900 | static void | |
3901 | c_finish_cilk_simd_fn_tokens (c_parser *parser) | |
3902 | { | |
3903 | c_token last_token = parser->cilk_simd_fn_tokens->last (); | |
3904 | ||
3905 | /* c_parser_attributes is called in several places, so if these EOF | |
3906 | tokens are already inserted, then don't do them again. */ | |
3907 | if (last_token.type == CPP_EOF) | |
3908 | return; | |
3909 | ||
3910 | /* Two CPP_EOF token are added as a safety net since the normal C | |
3911 | front-end has two token look-ahead. */ | |
3912 | c_token eof_token; | |
3913 | eof_token.type = CPP_EOF; | |
3914 | vec_safe_push (parser->cilk_simd_fn_tokens, eof_token); | |
3915 | vec_safe_push (parser->cilk_simd_fn_tokens, eof_token); | |
3916 | } | |
3917 | ||
1576dec7 | 3918 | /* Parse (possibly empty) attributes. This is a GNU extension. |
3919 | ||
3920 | attributes: | |
3921 | empty | |
3922 | attributes attribute | |
3923 | ||
3924 | attribute: | |
3925 | __attribute__ ( ( attribute-list ) ) | |
3926 | ||
3927 | attribute-list: | |
3928 | attrib | |
3929 | attribute_list , attrib | |
3930 | ||
3931 | attrib: | |
3932 | empty | |
3933 | any-word | |
3934 | any-word ( identifier ) | |
3935 | any-word ( identifier , nonempty-expr-list ) | |
3936 | any-word ( expr-list ) | |
3937 | ||
3938 | where the "identifier" must not be declared as a type, and | |
3939 | "any-word" may be any identifier (including one declared as a | |
3940 | type), a reserved word storage class specifier, type specifier or | |
3941 | type qualifier. ??? This still leaves out most reserved keywords | |
3942 | (following the old parser), shouldn't we include them, and why not | |
3943 | allow identifiers declared as types to start the arguments? */ | |
3944 | ||
3945 | static tree | |
3946 | c_parser_attributes (c_parser *parser) | |
3947 | { | |
3948 | tree attrs = NULL_TREE; | |
3949 | while (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)) | |
3950 | { | |
3951 | /* ??? Follow the C++ parser rather than using the | |
8115b8be | 3952 | lex_untranslated_string kludge. */ |
3953 | parser->lex_untranslated_string = true; | |
1576dec7 | 3954 | c_parser_consume_token (parser); |
3955 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
3956 | { | |
8115b8be | 3957 | parser->lex_untranslated_string = false; |
1576dec7 | 3958 | return attrs; |
3959 | } | |
3960 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
3961 | { | |
8115b8be | 3962 | parser->lex_untranslated_string = false; |
1576dec7 | 3963 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); |
3964 | return attrs; | |
3965 | } | |
3966 | /* Parse the attribute list. */ | |
3967 | while (c_parser_next_token_is (parser, CPP_COMMA) | |
3968 | || c_parser_next_token_is (parser, CPP_NAME) | |
3969 | || c_parser_next_token_is (parser, CPP_KEYWORD)) | |
3970 | { | |
3971 | tree attr, attr_name, attr_args; | |
f1f41a6c | 3972 | vec<tree, va_gc> *expr_list; |
1576dec7 | 3973 | if (c_parser_next_token_is (parser, CPP_COMMA)) |
3974 | { | |
3975 | c_parser_consume_token (parser); | |
3976 | continue; | |
3977 | } | |
4c0315d0 | 3978 | |
3979 | attr_name = c_parser_attribute_any_word (parser); | |
3980 | if (attr_name == NULL) | |
3981 | break; | |
74acc703 | 3982 | if (is_cilkplus_vector_p (attr_name)) |
3983 | { | |
3984 | c_token *v_token = c_parser_peek_token (parser); | |
3985 | c_parser_cilk_simd_fn_vector_attrs (parser, *v_token); | |
3986 | continue; | |
3987 | } | |
1576dec7 | 3988 | c_parser_consume_token (parser); |
3989 | if (c_parser_next_token_is_not (parser, CPP_OPEN_PAREN)) | |
3990 | { | |
3991 | attr = build_tree_list (attr_name, NULL_TREE); | |
3992 | attrs = chainon (attrs, attr); | |
3993 | continue; | |
3994 | } | |
3995 | c_parser_consume_token (parser); | |
3996 | /* Parse the attribute contents. If they start with an | |
3997 | identifier which is followed by a comma or close | |
3998 | parenthesis, then the arguments start with that | |
1f6616ee | 3999 | identifier; otherwise they are an expression list. |
4000 | In objective-c the identifier may be a classname. */ | |
1576dec7 | 4001 | if (c_parser_next_token_is (parser, CPP_NAME) |
1f6616ee | 4002 | && (c_parser_peek_token (parser)->id_kind == C_ID_ID |
3e5a8b00 | 4003 | || (c_dialect_objc () |
4004 | && c_parser_peek_token (parser)->id_kind | |
4005 | == C_ID_CLASSNAME)) | |
1576dec7 | 4006 | && ((c_parser_peek_2nd_token (parser)->type == CPP_COMMA) |
4007 | || (c_parser_peek_2nd_token (parser)->type | |
3e5a8b00 | 4008 | == CPP_CLOSE_PAREN)) |
4009 | && (attribute_takes_identifier_p (attr_name) | |
4010 | || (c_dialect_objc () | |
4011 | && c_parser_peek_token (parser)->id_kind | |
4012 | == C_ID_CLASSNAME))) | |
1576dec7 | 4013 | { |
4014 | tree arg1 = c_parser_peek_token (parser)->value; | |
4015 | c_parser_consume_token (parser); | |
4016 | if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) | |
4017 | attr_args = build_tree_list (NULL_TREE, arg1); | |
4018 | else | |
4019 | { | |
b9c74b4d | 4020 | tree tree_list; |
1576dec7 | 4021 | c_parser_consume_token (parser); |
f003f5dc | 4022 | expr_list = c_parser_expr_list (parser, false, true, |
ec761d5a | 4023 | NULL, NULL, NULL, NULL); |
f352a3fb | 4024 | tree_list = build_tree_list_vec (expr_list); |
b9c74b4d | 4025 | attr_args = tree_cons (NULL_TREE, arg1, tree_list); |
f352a3fb | 4026 | release_tree_vector (expr_list); |
1576dec7 | 4027 | } |
4028 | } | |
4029 | else | |
4030 | { | |
4031 | if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) | |
4032 | attr_args = NULL_TREE; | |
4033 | else | |
b9c74b4d | 4034 | { |
f003f5dc | 4035 | expr_list = c_parser_expr_list (parser, false, true, |
ec761d5a | 4036 | NULL, NULL, NULL, NULL); |
f352a3fb | 4037 | attr_args = build_tree_list_vec (expr_list); |
4038 | release_tree_vector (expr_list); | |
b9c74b4d | 4039 | } |
1576dec7 | 4040 | } |
4041 | attr = build_tree_list (attr_name, attr_args); | |
4042 | if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) | |
4043 | c_parser_consume_token (parser); | |
4044 | else | |
4045 | { | |
8115b8be | 4046 | parser->lex_untranslated_string = false; |
1576dec7 | 4047 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, |
4048 | "expected %<)%>"); | |
4049 | return attrs; | |
4050 | } | |
4051 | attrs = chainon (attrs, attr); | |
4052 | } | |
4053 | if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) | |
4054 | c_parser_consume_token (parser); | |
4055 | else | |
4056 | { | |
8115b8be | 4057 | parser->lex_untranslated_string = false; |
1576dec7 | 4058 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, |
4059 | "expected %<)%>"); | |
4060 | return attrs; | |
4061 | } | |
4062 | if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) | |
4063 | c_parser_consume_token (parser); | |
4064 | else | |
4065 | { | |
8115b8be | 4066 | parser->lex_untranslated_string = false; |
1576dec7 | 4067 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, |
4068 | "expected %<)%>"); | |
4069 | return attrs; | |
4070 | } | |
8115b8be | 4071 | parser->lex_untranslated_string = false; |
1576dec7 | 4072 | } |
74acc703 | 4073 | |
a89e6c15 | 4074 | if (flag_cilkplus && !vec_safe_is_empty (parser->cilk_simd_fn_tokens)) |
74acc703 | 4075 | c_finish_cilk_simd_fn_tokens (parser); |
1576dec7 | 4076 | return attrs; |
4077 | } | |
4078 | ||
4079 | /* Parse a type name (C90 6.5.5, C99 6.7.6). | |
4080 | ||
4081 | type-name: | |
4082 | specifier-qualifier-list abstract-declarator[opt] | |
4083 | */ | |
4084 | ||
4085 | static struct c_type_name * | |
4086 | c_parser_type_name (c_parser *parser) | |
4087 | { | |
4088 | struct c_declspecs *specs = build_null_declspecs (); | |
4089 | struct c_declarator *declarator; | |
4090 | struct c_type_name *ret; | |
4091 | bool dummy = false; | |
4fba5eb9 | 4092 | c_parser_declspecs (parser, specs, false, true, true, false, false, |
43d03c23 | 4093 | cla_prefer_type); |
1576dec7 | 4094 | if (!specs->declspecs_seen_p) |
4095 | { | |
4096 | c_parser_error (parser, "expected specifier-qualifier-list"); | |
4097 | return NULL; | |
4098 | } | |
26ee9e7a | 4099 | if (specs->type != error_mark_node) |
4100 | { | |
4101 | pending_xref_error (); | |
4102 | finish_declspecs (specs); | |
4103 | } | |
ae5ead32 | 4104 | declarator = c_parser_declarator (parser, |
4105 | specs->typespec_kind != ctsk_none, | |
1576dec7 | 4106 | C_DTR_ABSTRACT, &dummy); |
4107 | if (declarator == NULL) | |
4108 | return NULL; | |
4109 | ret = XOBNEW (&parser_obstack, struct c_type_name); | |
4110 | ret->specs = specs; | |
4111 | ret->declarator = declarator; | |
4112 | return ret; | |
4113 | } | |
4114 | ||
4115 | /* Parse an initializer (C90 6.5.7, C99 6.7.8). | |
4116 | ||
4117 | initializer: | |
4118 | assignment-expression | |
4119 | { initializer-list } | |
4120 | { initializer-list , } | |
4121 | ||
4122 | initializer-list: | |
4123 | designation[opt] initializer | |
4124 | initializer-list , designation[opt] initializer | |
4125 | ||
4126 | designation: | |
4127 | designator-list = | |
4128 | ||
4129 | designator-list: | |
4130 | designator | |
4131 | designator-list designator | |
4132 | ||
4133 | designator: | |
4134 | array-designator | |
4135 | . identifier | |
4136 | ||
4137 | array-designator: | |
4138 | [ constant-expression ] | |
4139 | ||
4140 | GNU extensions: | |
4141 | ||
4142 | initializer: | |
4143 | { } | |
4144 | ||
4145 | designation: | |
4146 | array-designator | |
4147 | identifier : | |
4148 | ||
4149 | array-designator: | |
4150 | [ constant-expression ... constant-expression ] | |
4151 | ||
4152 | Any expression without commas is accepted in the syntax for the | |
4153 | constant-expressions, with non-constant expressions rejected later. | |
4154 | ||
4155 | This function is only used for top-level initializers; for nested | |
4156 | ones, see c_parser_initval. */ | |
4157 | ||
4158 | static struct c_expr | |
4159 | c_parser_initializer (c_parser *parser) | |
4160 | { | |
4161 | if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) | |
4162 | return c_parser_braced_init (parser, NULL_TREE, false); | |
4163 | else | |
f14c8207 | 4164 | { |
4165 | struct c_expr ret; | |
e60a6f7b | 4166 | location_t loc = c_parser_peek_token (parser)->location; |
f14c8207 | 4167 | ret = c_parser_expr_no_commas (parser, NULL); |
4168 | if (TREE_CODE (ret.value) != STRING_CST | |
4169 | && TREE_CODE (ret.value) != COMPOUND_LITERAL_EXPR) | |
b560fabd | 4170 | ret = convert_lvalue_to_rvalue (loc, ret, true, true); |
f14c8207 | 4171 | return ret; |
4172 | } | |
1576dec7 | 4173 | } |
4174 | ||
4175 | /* Parse a braced initializer list. TYPE is the type specified for a | |
4176 | compound literal, and NULL_TREE for other initializers and for | |
4177 | nested braced lists. NESTED_P is true for nested braced lists, | |
4178 | false for the list of a compound literal or the list that is the | |
4179 | top-level initializer in a declaration. */ | |
4180 | ||
4181 | static struct c_expr | |
4182 | c_parser_braced_init (c_parser *parser, tree type, bool nested_p) | |
4183 | { | |
759791ee | 4184 | struct c_expr ret; |
4185 | struct obstack braced_init_obstack; | |
be9eba16 | 4186 | location_t brace_loc = c_parser_peek_token (parser)->location; |
759791ee | 4187 | gcc_obstack_init (&braced_init_obstack); |
1576dec7 | 4188 | gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE)); |
4189 | c_parser_consume_token (parser); | |
4190 | if (nested_p) | |
53de1631 | 4191 | push_init_level (brace_loc, 0, &braced_init_obstack); |
1576dec7 | 4192 | else |
4193 | really_start_incremental_init (type); | |
4194 | if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) | |
4195 | { | |
29438999 | 4196 | pedwarn (brace_loc, OPT_Wpedantic, "ISO C forbids empty initializer braces"); |
1576dec7 | 4197 | } |
4198 | else | |
4199 | { | |
4200 | /* Parse a non-empty initializer list, possibly with a trailing | |
4201 | comma. */ | |
4202 | while (true) | |
4203 | { | |
759791ee | 4204 | c_parser_initelt (parser, &braced_init_obstack); |
1576dec7 | 4205 | if (parser->error) |
4206 | break; | |
4207 | if (c_parser_next_token_is (parser, CPP_COMMA)) | |
4208 | c_parser_consume_token (parser); | |
4209 | else | |
4210 | break; | |
4211 | if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) | |
4212 | break; | |
4213 | } | |
4214 | } | |
4215 | if (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE)) | |
4216 | { | |
1576dec7 | 4217 | ret.value = error_mark_node; |
4218 | ret.original_code = ERROR_MARK; | |
841fdaa6 | 4219 | ret.original_type = NULL; |
1576dec7 | 4220 | c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, "expected %<}%>"); |
53de1631 | 4221 | pop_init_level (brace_loc, 0, &braced_init_obstack); |
759791ee | 4222 | obstack_free (&braced_init_obstack, NULL); |
1576dec7 | 4223 | return ret; |
4224 | } | |
4225 | c_parser_consume_token (parser); | |
53de1631 | 4226 | ret = pop_init_level (brace_loc, 0, &braced_init_obstack); |
759791ee | 4227 | obstack_free (&braced_init_obstack, NULL); |
4228 | return ret; | |
1576dec7 | 4229 | } |
4230 | ||
4231 | /* Parse a nested initializer, including designators. */ | |
4232 | ||
4233 | static void | |
759791ee | 4234 | c_parser_initelt (c_parser *parser, struct obstack * braced_init_obstack) |
1576dec7 | 4235 | { |
4236 | /* Parse any designator or designator list. A single array | |
4237 | designator may have the subsequent "=" omitted in GNU C, but a | |
4238 | longer list or a structure member designator may not. */ | |
4239 | if (c_parser_next_token_is (parser, CPP_NAME) | |
4240 | && c_parser_peek_2nd_token (parser)->type == CPP_COLON) | |
4241 | { | |
4242 | /* Old-style structure member designator. */ | |
53de1631 | 4243 | set_init_label (c_parser_peek_token (parser)->location, |
4244 | c_parser_peek_token (parser)->value, | |
759791ee | 4245 | braced_init_obstack); |
8864917d | 4246 | /* Use the colon as the error location. */ |
29438999 | 4247 | pedwarn (c_parser_peek_2nd_token (parser)->location, OPT_Wpedantic, |
21ca8540 | 4248 | "obsolete use of designated initializer with %<:%>"); |
1576dec7 | 4249 | c_parser_consume_token (parser); |
4250 | c_parser_consume_token (parser); | |
4251 | } | |
4252 | else | |
4253 | { | |
4254 | /* des_seen is 0 if there have been no designators, 1 if there | |
4255 | has been a single array designator and 2 otherwise. */ | |
4256 | int des_seen = 0; | |
be9eba16 | 4257 | /* Location of a designator. */ |
019abced | 4258 | location_t des_loc = UNKNOWN_LOCATION; /* Quiet warning. */ |
1576dec7 | 4259 | while (c_parser_next_token_is (parser, CPP_OPEN_SQUARE) |
4260 | || c_parser_next_token_is (parser, CPP_DOT)) | |
4261 | { | |
4262 | int des_prev = des_seen; | |
be9eba16 | 4263 | if (!des_seen) |
4264 | des_loc = c_parser_peek_token (parser)->location; | |
1576dec7 | 4265 | if (des_seen < 2) |
4266 | des_seen++; | |
4267 | if (c_parser_next_token_is (parser, CPP_DOT)) | |
4268 | { | |
4269 | des_seen = 2; | |
4270 | c_parser_consume_token (parser); | |
4271 | if (c_parser_next_token_is (parser, CPP_NAME)) | |
4272 | { | |
53de1631 | 4273 | set_init_label (des_loc, c_parser_peek_token (parser)->value, |
759791ee | 4274 | braced_init_obstack); |
1576dec7 | 4275 | c_parser_consume_token (parser); |
4276 | } | |
4277 | else | |
4278 | { | |
4279 | struct c_expr init; | |
4280 | init.value = error_mark_node; | |
4281 | init.original_code = ERROR_MARK; | |
841fdaa6 | 4282 | init.original_type = NULL; |
1576dec7 | 4283 | c_parser_error (parser, "expected identifier"); |
4284 | c_parser_skip_until_found (parser, CPP_COMMA, NULL); | |
adc93f31 | 4285 | process_init_element (input_location, init, false, |
4286 | braced_init_obstack); | |
1576dec7 | 4287 | return; |
4288 | } | |
4289 | } | |
4290 | else | |
4291 | { | |
4292 | tree first, second; | |
019abced | 4293 | location_t ellipsis_loc = UNKNOWN_LOCATION; /* Quiet warning. */ |
53de1631 | 4294 | location_t array_index_loc = UNKNOWN_LOCATION; |
1576dec7 | 4295 | /* ??? Following the old parser, [ objc-receiver |
4296 | objc-message-args ] is accepted as an initializer, | |
4297 | being distinguished from a designator by what follows | |
4298 | the first assignment expression inside the square | |
4299 | brackets, but after a first array designator a | |
4300 | subsequent square bracket is for Objective-C taken to | |
4301 | start an expression, using the obsolete form of | |
4302 | designated initializer without '=', rather than | |
4303 | possibly being a second level of designation: in LALR | |
4304 | terms, the '[' is shifted rather than reducing | |
4305 | designator to designator-list. */ | |
4306 | if (des_prev == 1 && c_dialect_objc ()) | |
4307 | { | |
4308 | des_seen = des_prev; | |
4309 | break; | |
4310 | } | |
4311 | if (des_prev == 0 && c_dialect_objc ()) | |
4312 | { | |
4313 | /* This might be an array designator or an | |
4314 | Objective-C message expression. If the former, | |
4315 | continue parsing here; if the latter, parse the | |
4316 | remainder of the initializer given the starting | |
4317 | primary-expression. ??? It might make sense to | |
4318 | distinguish when des_prev == 1 as well; see | |
4319 | previous comment. */ | |
4320 | tree rec, args; | |
4321 | struct c_expr mexpr; | |
4322 | c_parser_consume_token (parser); | |
4323 | if (c_parser_peek_token (parser)->type == CPP_NAME | |
4324 | && ((c_parser_peek_token (parser)->id_kind | |
4325 | == C_ID_TYPENAME) | |
4326 | || (c_parser_peek_token (parser)->id_kind | |
4327 | == C_ID_CLASSNAME))) | |
4328 | { | |
4329 | /* Type name receiver. */ | |
4330 | tree id = c_parser_peek_token (parser)->value; | |
4331 | c_parser_consume_token (parser); | |
4332 | rec = objc_get_class_reference (id); | |
4333 | goto parse_message_args; | |
4334 | } | |
4335 | first = c_parser_expr_no_commas (parser, NULL).value; | |
abc6c64f | 4336 | mark_exp_read (first); |
1576dec7 | 4337 | if (c_parser_next_token_is (parser, CPP_ELLIPSIS) |
4338 | || c_parser_next_token_is (parser, CPP_CLOSE_SQUARE)) | |
4339 | goto array_desig_after_first; | |
4340 | /* Expression receiver. So far only one part | |
4341 | without commas has been parsed; there might be | |
4342 | more of the expression. */ | |
4343 | rec = first; | |
4344 | while (c_parser_next_token_is (parser, CPP_COMMA)) | |
4345 | { | |
e78cf9a7 | 4346 | struct c_expr next; |
e60a6f7b | 4347 | location_t comma_loc, exp_loc; |
4348 | comma_loc = c_parser_peek_token (parser)->location; | |
1576dec7 | 4349 | c_parser_consume_token (parser); |
e60a6f7b | 4350 | exp_loc = c_parser_peek_token (parser)->location; |
e78cf9a7 | 4351 | next = c_parser_expr_no_commas (parser, NULL); |
b560fabd | 4352 | next = convert_lvalue_to_rvalue (exp_loc, next, |
4353 | true, true); | |
e60a6f7b | 4354 | rec = build_compound_expr (comma_loc, rec, next.value); |
1576dec7 | 4355 | } |
4356 | parse_message_args: | |
4357 | /* Now parse the objc-message-args. */ | |
4358 | args = c_parser_objc_message_args (parser); | |
4359 | c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, | |
4360 | "expected %<]%>"); | |
4361 | mexpr.value | |
4185cf58 | 4362 | = objc_build_message_expr (rec, args); |
1576dec7 | 4363 | mexpr.original_code = ERROR_MARK; |
841fdaa6 | 4364 | mexpr.original_type = NULL; |
1576dec7 | 4365 | /* Now parse and process the remainder of the |
4366 | initializer, starting with this message | |
4367 | expression as a primary-expression. */ | |
759791ee | 4368 | c_parser_initval (parser, &mexpr, braced_init_obstack); |
1576dec7 | 4369 | return; |
4370 | } | |
4371 | c_parser_consume_token (parser); | |
53de1631 | 4372 | array_index_loc = c_parser_peek_token (parser)->location; |
1576dec7 | 4373 | first = c_parser_expr_no_commas (parser, NULL).value; |
abc6c64f | 4374 | mark_exp_read (first); |
1576dec7 | 4375 | array_desig_after_first: |
4376 | if (c_parser_next_token_is (parser, CPP_ELLIPSIS)) | |
4377 | { | |
be9eba16 | 4378 | ellipsis_loc = c_parser_peek_token (parser)->location; |
1576dec7 | 4379 | c_parser_consume_token (parser); |
4380 | second = c_parser_expr_no_commas (parser, NULL).value; | |
abc6c64f | 4381 | mark_exp_read (second); |
1576dec7 | 4382 | } |
4383 | else | |
4384 | second = NULL_TREE; | |
4385 | if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE)) | |
4386 | { | |
4387 | c_parser_consume_token (parser); | |
53de1631 | 4388 | set_init_index (array_index_loc, first, second, |
4389 | braced_init_obstack); | |
8864917d | 4390 | if (second) |
29438999 | 4391 | pedwarn (ellipsis_loc, OPT_Wpedantic, |
21ca8540 | 4392 | "ISO C forbids specifying range of elements to initialize"); |
1576dec7 | 4393 | } |
4394 | else | |
4395 | c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, | |
4396 | "expected %<]%>"); | |
4397 | } | |
4398 | } | |
4399 | if (des_seen >= 1) | |
4400 | { | |
4401 | if (c_parser_next_token_is (parser, CPP_EQ)) | |
4402 | { | |
890c2e2f | 4403 | pedwarn_c90 (des_loc, OPT_Wpedantic, |
4404 | "ISO C90 forbids specifying subobject " | |
4405 | "to initialize"); | |
1576dec7 | 4406 | c_parser_consume_token (parser); |
4407 | } | |
4408 | else | |
4409 | { | |
4410 | if (des_seen == 1) | |
29438999 | 4411 | pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic, |
21ca8540 | 4412 | "obsolete use of designated initializer without %<=%>"); |
1576dec7 | 4413 | else |
4414 | { | |
4415 | struct c_expr init; | |
4416 | init.value = error_mark_node; | |
4417 | init.original_code = ERROR_MARK; | |
841fdaa6 | 4418 | init.original_type = NULL; |
1576dec7 | 4419 | c_parser_error (parser, "expected %<=%>"); |
4420 | c_parser_skip_until_found (parser, CPP_COMMA, NULL); | |
adc93f31 | 4421 | process_init_element (input_location, init, false, |
4422 | braced_init_obstack); | |
1576dec7 | 4423 | return; |
4424 | } | |
4425 | } | |
4426 | } | |
4427 | } | |
759791ee | 4428 | c_parser_initval (parser, NULL, braced_init_obstack); |
1576dec7 | 4429 | } |
4430 | ||
4431 | /* Parse a nested initializer; as c_parser_initializer but parses | |
4432 | initializers within braced lists, after any designators have been | |
4433 | applied. If AFTER is not NULL then it is an Objective-C message | |
4434 | expression which is the primary-expression starting the | |
4435 | initializer. */ | |
4436 | ||
4437 | static void | |
759791ee | 4438 | c_parser_initval (c_parser *parser, struct c_expr *after, |
4439 | struct obstack * braced_init_obstack) | |
1576dec7 | 4440 | { |
4441 | struct c_expr init; | |
4442 | gcc_assert (!after || c_dialect_objc ()); | |
adc93f31 | 4443 | location_t loc = c_parser_peek_token (parser)->location; |
4444 | ||
1576dec7 | 4445 | if (c_parser_next_token_is (parser, CPP_OPEN_BRACE) && !after) |
4446 | init = c_parser_braced_init (parser, NULL_TREE, true); | |
4447 | else | |
f14c8207 | 4448 | { |
4449 | init = c_parser_expr_no_commas (parser, after); | |
4450 | if (init.value != NULL_TREE | |
4451 | && TREE_CODE (init.value) != STRING_CST | |
4452 | && TREE_CODE (init.value) != COMPOUND_LITERAL_EXPR) | |
b560fabd | 4453 | init = convert_lvalue_to_rvalue (loc, init, true, true); |
f14c8207 | 4454 | } |
adc93f31 | 4455 | process_init_element (loc, init, false, braced_init_obstack); |
1576dec7 | 4456 | } |
4457 | ||
4458 | /* Parse a compound statement (possibly a function body) (C90 6.6.2, | |
4459 | C99 6.8.2). | |
4460 | ||
4461 | compound-statement: | |
4462 | { block-item-list[opt] } | |
4463 | { label-declarations block-item-list } | |
4464 | ||
4465 | block-item-list: | |
4466 | block-item | |
4467 | block-item-list block-item | |
4468 | ||
4469 | block-item: | |
4470 | nested-declaration | |
4471 | statement | |
4472 | ||
4473 | nested-declaration: | |
4474 | declaration | |
4475 | ||
4476 | GNU extensions: | |
4477 | ||
4478 | compound-statement: | |
4479 | { label-declarations block-item-list } | |
4480 | ||
4481 | nested-declaration: | |
4482 | __extension__ nested-declaration | |
4483 | nested-function-definition | |
4484 | ||
4485 | label-declarations: | |
4486 | label-declaration | |
4487 | label-declarations label-declaration | |
4488 | ||
4489 | label-declaration: | |
4490 | __label__ identifier-list ; | |
4491 | ||
4492 | Allowing the mixing of declarations and code is new in C99. The | |
4493 | GNU syntax also permits (not shown above) labels at the end of | |
4494 | compound statements, which yield an error. We don't allow labels | |
4495 | on declarations; this might seem like a natural extension, but | |
4496 | there would be a conflict between attributes on the label and | |
4497 | prefix attributes on the declaration. ??? The syntax follows the | |
4498 | old parser in requiring something after label declarations. | |
4499 | Although they are erroneous if the labels declared aren't defined, | |
1e8e9920 | 4500 | is it useful for the syntax to be this way? |
48e1416a | 4501 | |
ca4c3545 | 4502 | OpenACC: |
4503 | ||
4504 | block-item: | |
4505 | openacc-directive | |
4506 | ||
4507 | openacc-directive: | |
4508 | update-directive | |
4509 | ||
1e8e9920 | 4510 | OpenMP: |
48e1416a | 4511 | |
1e8e9920 | 4512 | block-item: |
4513 | openmp-directive | |
4514 | ||
4515 | openmp-directive: | |
4516 | barrier-directive | |
bc7bff74 | 4517 | flush-directive |
4518 | taskwait-directive | |
4519 | taskyield-directive | |
4520 | cancel-directive | |
4521 | cancellation-point-directive */ | |
1576dec7 | 4522 | |
4523 | static tree | |
4524 | c_parser_compound_statement (c_parser *parser) | |
4525 | { | |
4526 | tree stmt; | |
e60a6f7b | 4527 | location_t brace_loc; |
4528 | brace_loc = c_parser_peek_token (parser)->location; | |
1576dec7 | 4529 | if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>")) |
22d77a94 | 4530 | { |
4531 | /* Ensure a scope is entered and left anyway to avoid confusion | |
4532 | if we have just prepared to enter a function body. */ | |
4533 | stmt = c_begin_compound_stmt (true); | |
e60a6f7b | 4534 | c_end_compound_stmt (brace_loc, stmt, true); |
22d77a94 | 4535 | return error_mark_node; |
4536 | } | |
1576dec7 | 4537 | stmt = c_begin_compound_stmt (true); |
4538 | c_parser_compound_statement_nostart (parser); | |
3c6d4197 | 4539 | |
4540 | /* If the compound stmt contains array notations, then we expand them. */ | |
a89e6c15 | 4541 | if (flag_cilkplus && contains_array_notation_expr (stmt)) |
3c6d4197 | 4542 | stmt = expand_array_notation_exprs (stmt); |
e60a6f7b | 4543 | return c_end_compound_stmt (brace_loc, stmt, true); |
1576dec7 | 4544 | } |
4545 | ||
4546 | /* Parse a compound statement except for the opening brace. This is | |
4547 | used for parsing both compound statements and statement expressions | |
4548 | (which follow different paths to handling the opening). */ | |
4549 | ||
4550 | static void | |
4551 | c_parser_compound_statement_nostart (c_parser *parser) | |
4552 | { | |
4553 | bool last_stmt = false; | |
4554 | bool last_label = false; | |
3ae3a17f | 4555 | bool save_valid_for_pragma = valid_location_for_stdc_pragma_p (); |
e3b80d49 | 4556 | location_t label_loc = UNKNOWN_LOCATION; /* Quiet warning. */ |
1576dec7 | 4557 | if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) |
4558 | { | |
4559 | c_parser_consume_token (parser); | |
4560 | return; | |
4561 | } | |
3ae3a17f | 4562 | mark_valid_location_for_stdc_pragma (true); |
1576dec7 | 4563 | if (c_parser_next_token_is_keyword (parser, RID_LABEL)) |
4564 | { | |
4565 | /* Read zero or more forward-declarations for labels that nested | |
4566 | functions can jump to. */ | |
3ae3a17f | 4567 | mark_valid_location_for_stdc_pragma (false); |
1576dec7 | 4568 | while (c_parser_next_token_is_keyword (parser, RID_LABEL)) |
4569 | { | |
e60a6f7b | 4570 | label_loc = c_parser_peek_token (parser)->location; |
1576dec7 | 4571 | c_parser_consume_token (parser); |
4572 | /* Any identifiers, including those declared as type names, | |
4573 | are OK here. */ | |
4574 | while (true) | |
4575 | { | |
4576 | tree label; | |
4577 | if (c_parser_next_token_is_not (parser, CPP_NAME)) | |
4578 | { | |
4579 | c_parser_error (parser, "expected identifier"); | |
4580 | break; | |
4581 | } | |
4582 | label | |
4583 | = declare_label (c_parser_peek_token (parser)->value); | |
4584 | C_DECLARED_LABEL_FLAG (label) = 1; | |
e60a6f7b | 4585 | add_stmt (build_stmt (label_loc, DECL_EXPR, label)); |
1576dec7 | 4586 | c_parser_consume_token (parser); |
4587 | if (c_parser_next_token_is (parser, CPP_COMMA)) | |
4588 | c_parser_consume_token (parser); | |
4589 | else | |
4590 | break; | |
4591 | } | |
4592 | c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); | |
4593 | } | |
29438999 | 4594 | pedwarn (label_loc, OPT_Wpedantic, "ISO C forbids label declarations"); |
1576dec7 | 4595 | } |
4596 | /* We must now have at least one statement, label or declaration. */ | |
4597 | if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) | |
4598 | { | |
3ae3a17f | 4599 | mark_valid_location_for_stdc_pragma (save_valid_for_pragma); |
1576dec7 | 4600 | c_parser_error (parser, "expected declaration or statement"); |
4601 | c_parser_consume_token (parser); | |
4602 | return; | |
4603 | } | |
4604 | while (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE)) | |
4605 | { | |
4606 | location_t loc = c_parser_peek_token (parser)->location; | |
1576dec7 | 4607 | if (c_parser_next_token_is_keyword (parser, RID_CASE) |
4608 | || c_parser_next_token_is_keyword (parser, RID_DEFAULT) | |
4609 | || (c_parser_next_token_is (parser, CPP_NAME) | |
4610 | && c_parser_peek_2nd_token (parser)->type == CPP_COLON)) | |
4611 | { | |
be9eba16 | 4612 | if (c_parser_next_token_is_keyword (parser, RID_CASE)) |
4613 | label_loc = c_parser_peek_2nd_token (parser)->location; | |
4614 | else | |
4615 | label_loc = c_parser_peek_token (parser)->location; | |
1576dec7 | 4616 | last_label = true; |
4617 | last_stmt = false; | |
3ae3a17f | 4618 | mark_valid_location_for_stdc_pragma (false); |
1576dec7 | 4619 | c_parser_label (parser); |
4620 | } | |
4621 | else if (!last_label | |
71bb4bc6 | 4622 | && c_parser_next_tokens_start_declaration (parser)) |
1576dec7 | 4623 | { |
4624 | last_label = false; | |
3ae3a17f | 4625 | mark_valid_location_for_stdc_pragma (false); |
bc7bff74 | 4626 | c_parser_declaration_or_fndef (parser, true, true, true, true, |
4627 | true, NULL, vNULL); | |
8864917d | 4628 | if (last_stmt) |
806fe15e | 4629 | pedwarn_c90 (loc, OPT_Wdeclaration_after_statement, |
21ca8540 | 4630 | "ISO C90 forbids mixed declarations and code"); |
1576dec7 | 4631 | last_stmt = false; |
4632 | } | |
4633 | else if (!last_label | |
4634 | && c_parser_next_token_is_keyword (parser, RID_EXTENSION)) | |
4635 | { | |
4636 | /* __extension__ can start a declaration, but is also an | |
4637 | unary operator that can start an expression. Consume all | |
4638 | but the last of a possible series of __extension__ to | |
4639 | determine which. */ | |
4640 | while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD | |
4641 | && (c_parser_peek_2nd_token (parser)->keyword | |
4642 | == RID_EXTENSION)) | |
4643 | c_parser_consume_token (parser); | |
f80e7755 | 4644 | if (c_token_starts_declaration (c_parser_peek_2nd_token (parser))) |
1576dec7 | 4645 | { |
4646 | int ext; | |
4647 | ext = disable_extension_diagnostics (); | |
4648 | c_parser_consume_token (parser); | |
4649 | last_label = false; | |
3ae3a17f | 4650 | mark_valid_location_for_stdc_pragma (false); |
f80e7755 | 4651 | c_parser_declaration_or_fndef (parser, true, true, true, true, |
bc7bff74 | 4652 | true, NULL, vNULL); |
1576dec7 | 4653 | /* Following the old parser, __extension__ does not |
4654 | disable this diagnostic. */ | |
4655 | restore_extension_diagnostics (ext); | |
8864917d | 4656 | if (last_stmt) |
806fe15e | 4657 | pedwarn_c90 (loc, OPT_Wdeclaration_after_statement, |
21ca8540 | 4658 | "ISO C90 forbids mixed declarations and code"); |
1576dec7 | 4659 | last_stmt = false; |
4660 | } | |
4661 | else | |
4662 | goto statement; | |
4663 | } | |
b75b98aa | 4664 | else if (c_parser_next_token_is (parser, CPP_PRAGMA)) |
4665 | { | |
4666 | /* External pragmas, and some omp pragmas, are not associated | |
4667 | with regular c code, and so are not to be considered statements | |
4668 | syntactically. This ensures that the user doesn't put them | |
4669 | places that would turn into syntax errors if the directive | |
4670 | were ignored. */ | |
4671 | if (c_parser_pragma (parser, pragma_compound)) | |
4672 | last_label = false, last_stmt = true; | |
4673 | } | |
4674 | else if (c_parser_next_token_is (parser, CPP_EOF)) | |
4675 | { | |
3ae3a17f | 4676 | mark_valid_location_for_stdc_pragma (save_valid_for_pragma); |
b75b98aa | 4677 | c_parser_error (parser, "expected declaration or statement"); |
4678 | return; | |
4679 | } | |
10c93a35 | 4680 | else if (c_parser_next_token_is_keyword (parser, RID_ELSE)) |
4681 | { | |
48e1416a | 4682 | if (parser->in_if_block) |
10c93a35 | 4683 | { |
3ae3a17f | 4684 | mark_valid_location_for_stdc_pragma (save_valid_for_pragma); |
e3b80d49 | 4685 | error_at (loc, """expected %<}%> before %<else%>"); |
10c93a35 | 4686 | return; |
4687 | } | |
48e1416a | 4688 | else |
10c93a35 | 4689 | { |
e3b80d49 | 4690 | error_at (loc, "%<else%> without a previous %<if%>"); |
10c93a35 | 4691 | c_parser_consume_token (parser); |
4692 | continue; | |
4693 | } | |
4694 | } | |
1576dec7 | 4695 | else |
4696 | { | |
4697 | statement: | |
4698 | last_label = false; | |
4699 | last_stmt = true; | |
3ae3a17f | 4700 | mark_valid_location_for_stdc_pragma (false); |
1576dec7 | 4701 | c_parser_statement_after_labels (parser); |
4702 | } | |
d038ab63 | 4703 | |
4704 | parser->error = false; | |
1576dec7 | 4705 | } |
4706 | if (last_label) | |
e3b80d49 | 4707 | error_at (label_loc, "label at end of compound statement"); |
1576dec7 | 4708 | c_parser_consume_token (parser); |
3ae3a17f | 4709 | /* Restore the value we started with. */ |
4710 | mark_valid_location_for_stdc_pragma (save_valid_for_pragma); | |
1576dec7 | 4711 | } |
4712 | ||
4f284d4a | 4713 | /* Parse all consecutive labels. */ |
4714 | ||
4715 | static void | |
4716 | c_parser_all_labels (c_parser *parser) | |
4717 | { | |
4718 | while (c_parser_next_token_is_keyword (parser, RID_CASE) | |
4719 | || c_parser_next_token_is_keyword (parser, RID_DEFAULT) | |
4720 | || (c_parser_next_token_is (parser, CPP_NAME) | |
4721 | && c_parser_peek_2nd_token (parser)->type == CPP_COLON)) | |
4722 | c_parser_label (parser); | |
4723 | } | |
4724 | ||
1576dec7 | 4725 | /* Parse a label (C90 6.6.1, C99 6.8.1). |
4726 | ||
4727 | label: | |
4728 | identifier : attributes[opt] | |
4729 | case constant-expression : | |
4730 | default : | |
4731 | ||
4732 | GNU extensions: | |
4733 | ||
4734 | label: | |
4735 | case constant-expression ... constant-expression : | |
4736 | ||
4737 | The use of attributes on labels is a GNU extension. The syntax in | |
4738 | GNU C accepts any expressions without commas, non-constant | |
4739 | expressions being rejected later. */ | |
4740 | ||
4741 | static void | |
4742 | c_parser_label (c_parser *parser) | |
4743 | { | |
4744 | location_t loc1 = c_parser_peek_token (parser)->location; | |
4745 | tree label = NULL_TREE; | |
4746 | if (c_parser_next_token_is_keyword (parser, RID_CASE)) | |
4747 | { | |
4748 | tree exp1, exp2; | |
4749 | c_parser_consume_token (parser); | |
4750 | exp1 = c_parser_expr_no_commas (parser, NULL).value; | |
4751 | if (c_parser_next_token_is (parser, CPP_COLON)) | |
4752 | { | |
4753 | c_parser_consume_token (parser); | |
e60a6f7b | 4754 | label = do_case (loc1, exp1, NULL_TREE); |
1576dec7 | 4755 | } |
4756 | else if (c_parser_next_token_is (parser, CPP_ELLIPSIS)) | |
4757 | { | |
4758 | c_parser_consume_token (parser); | |
4759 | exp2 = c_parser_expr_no_commas (parser, NULL).value; | |
4760 | if (c_parser_require (parser, CPP_COLON, "expected %<:%>")) | |
e60a6f7b | 4761 | label = do_case (loc1, exp1, exp2); |
1576dec7 | 4762 | } |
4763 | else | |
4764 | c_parser_error (parser, "expected %<:%> or %<...%>"); | |
4765 | } | |
4766 | else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT)) | |
4767 | { | |
4768 | c_parser_consume_token (parser); | |
4769 | if (c_parser_require (parser, CPP_COLON, "expected %<:%>")) | |
e60a6f7b | 4770 | label = do_case (loc1, NULL_TREE, NULL_TREE); |
1576dec7 | 4771 | } |
4772 | else | |
4773 | { | |
4774 | tree name = c_parser_peek_token (parser)->value; | |
4775 | tree tlab; | |
1576dec7 | 4776 | tree attrs; |
be9eba16 | 4777 | location_t loc2 = c_parser_peek_token (parser)->location; |
1576dec7 | 4778 | gcc_assert (c_parser_next_token_is (parser, CPP_NAME)); |
4779 | c_parser_consume_token (parser); | |
4780 | gcc_assert (c_parser_next_token_is (parser, CPP_COLON)); | |
1576dec7 | 4781 | c_parser_consume_token (parser); |
4782 | attrs = c_parser_attributes (parser); | |
4783 | tlab = define_label (loc2, name); | |
4784 | if (tlab) | |
4785 | { | |
4786 | decl_attributes (&tlab, attrs, 0); | |
e60a6f7b | 4787 | label = add_stmt (build_stmt (loc1, LABEL_EXPR, tlab)); |
1576dec7 | 4788 | } |
4789 | } | |
4790 | if (label) | |
7561efef | 4791 | { |
71bb4bc6 | 4792 | if (c_parser_next_tokens_start_declaration (parser)) |
7561efef | 4793 | { |
e3b80d49 | 4794 | error_at (c_parser_peek_token (parser)->location, |
4795 | "a label can only be part of a statement and " | |
4796 | "a declaration is not a statement"); | |
48e1416a | 4797 | c_parser_declaration_or_fndef (parser, /*fndef_ok*/ false, |
f80e7755 | 4798 | /*static_assert_ok*/ true, |
a90d57ed | 4799 | /*empty_ok*/ true, /*nested*/ true, |
bc7bff74 | 4800 | /*start_attr_ok*/ true, NULL, |
4801 | vNULL); | |
7561efef | 4802 | } |
4803 | } | |
1576dec7 | 4804 | } |
4805 | ||
4806 | /* Parse a statement (C90 6.6, C99 6.8). | |
4807 | ||
4808 | statement: | |
4809 | labeled-statement | |
4810 | compound-statement | |
4811 | expression-statement | |
4812 | selection-statement | |
4813 | iteration-statement | |
4814 | jump-statement | |
4815 | ||
4816 | labeled-statement: | |
4817 | label statement | |
4818 | ||
4819 | expression-statement: | |
4820 | expression[opt] ; | |
4821 | ||
4822 | selection-statement: | |
4823 | if-statement | |
4824 | switch-statement | |
4825 | ||
4826 | iteration-statement: | |
4827 | while-statement | |
4828 | do-statement | |
4829 | for-statement | |
4830 | ||
4831 | jump-statement: | |
4832 | goto identifier ; | |
4833 | continue ; | |
4834 | break ; | |
4835 | return expression[opt] ; | |
4836 | ||
4837 | GNU extensions: | |
4838 | ||
4839 | statement: | |
4840 | asm-statement | |
4841 | ||
4842 | jump-statement: | |
4843 | goto * expression ; | |
4844 | ||
4845 | Objective-C: | |
4846 | ||
4847 | statement: | |
4848 | objc-throw-statement | |
4849 | objc-try-catch-statement | |
4850 | objc-synchronized-statement | |
4851 | ||
4852 | objc-throw-statement: | |
4853 | @throw expression ; | |
4854 | @throw ; | |
1e8e9920 | 4855 | |
ca4c3545 | 4856 | OpenACC: |
4857 | ||
4858 | statement: | |
4859 | openacc-construct | |
4860 | ||
4861 | openacc-construct: | |
4862 | parallel-construct | |
4863 | kernels-construct | |
4864 | data-construct | |
4865 | loop-construct | |
4866 | ||
4867 | parallel-construct: | |
4868 | parallel-directive structured-block | |
4869 | ||
4870 | kernels-construct: | |
4871 | kernels-directive structured-block | |
4872 | ||
4873 | data-construct: | |
4874 | data-directive structured-block | |
4875 | ||
4876 | loop-construct: | |
4877 | loop-directive structured-block | |
4878 | ||
1e8e9920 | 4879 | OpenMP: |
4880 | ||
4881 | statement: | |
4882 | openmp-construct | |
4883 | ||
4884 | openmp-construct: | |
4885 | parallel-construct | |
4886 | for-construct | |
bc7bff74 | 4887 | simd-construct |
4888 | for-simd-construct | |
1e8e9920 | 4889 | sections-construct |
4890 | single-construct | |
4891 | parallel-for-construct | |
bc7bff74 | 4892 | parallel-for-simd-construct |
1e8e9920 | 4893 | parallel-sections-construct |
4894 | master-construct | |
4895 | critical-construct | |
4896 | atomic-construct | |
4897 | ordered-construct | |
4898 | ||
4899 | parallel-construct: | |
4900 | parallel-directive structured-block | |
4901 | ||
4902 | for-construct: | |
4903 | for-directive iteration-statement | |
4904 | ||
bc7bff74 | 4905 | simd-construct: |
4906 | simd-directive iteration-statements | |
4907 | ||
4908 | for-simd-construct: | |
4909 | for-simd-directive iteration-statements | |
4910 | ||
1e8e9920 | 4911 | sections-construct: |
4912 | sections-directive section-scope | |
4913 | ||
4914 | single-construct: | |
4915 | single-directive structured-block | |
4916 | ||
4917 | parallel-for-construct: | |
4918 | parallel-for-directive iteration-statement | |
4919 | ||
bc7bff74 | 4920 | parallel-for-simd-construct: |
4921 | parallel-for-simd-directive iteration-statement | |
4922 | ||
1e8e9920 | 4923 | parallel-sections-construct: |
4924 | parallel-sections-directive section-scope | |
4925 | ||
4926 | master-construct: | |
4927 | master-directive structured-block | |
4928 | ||
4929 | critical-construct: | |
4930 | critical-directive structured-block | |
4931 | ||
4932 | atomic-construct: | |
4933 | atomic-directive expression-statement | |
4934 | ||
4935 | ordered-construct: | |
4c0315d0 | 4936 | ordered-directive structured-block |
4937 | ||
4938 | Transactional Memory: | |
4939 | ||
4940 | statement: | |
4941 | transaction-statement | |
4942 | transaction-cancel-statement | |
4943 | */ | |
1576dec7 | 4944 | |
4945 | static void | |
4946 | c_parser_statement (c_parser *parser) | |
4947 | { | |
4f284d4a | 4948 | c_parser_all_labels (parser); |
1576dec7 | 4949 | c_parser_statement_after_labels (parser); |
4950 | } | |
4951 | ||
4952 | /* Parse a statement, other than a labeled statement. */ | |
4953 | ||
4954 | static void | |
4955 | c_parser_statement_after_labels (c_parser *parser) | |
4956 | { | |
4957 | location_t loc = c_parser_peek_token (parser)->location; | |
4958 | tree stmt = NULL_TREE; | |
10c93a35 | 4959 | bool in_if_block = parser->in_if_block; |
4960 | parser->in_if_block = false; | |
1576dec7 | 4961 | switch (c_parser_peek_token (parser)->type) |
4962 | { | |
4963 | case CPP_OPEN_BRACE: | |
4964 | add_stmt (c_parser_compound_statement (parser)); | |
4965 | break; | |
4966 | case CPP_KEYWORD: | |
4967 | switch (c_parser_peek_token (parser)->keyword) | |
4968 | { | |
4969 | case RID_IF: | |
4970 | c_parser_if_statement (parser); | |
4971 | break; | |
4972 | case RID_SWITCH: | |
4973 | c_parser_switch_statement (parser); | |
4974 | break; | |
4975 | case RID_WHILE: | |
4c90c04c | 4976 | c_parser_while_statement (parser, false); |
1576dec7 | 4977 | break; |
4978 | case RID_DO: | |
4c90c04c | 4979 | c_parser_do_statement (parser, false); |
1576dec7 | 4980 | break; |
4981 | case RID_FOR: | |
4644b593 | 4982 | c_parser_for_statement (parser, false); |
1576dec7 | 4983 | break; |
40750995 | 4984 | case RID_CILK_FOR: |
4985 | if (!flag_cilkplus) | |
4986 | { | |
4987 | error_at (c_parser_peek_token (parser)->location, | |
4988 | "-fcilkplus must be enabled to use %<_Cilk_for%>"); | |
4989 | c_parser_skip_to_end_of_block_or_statement (parser); | |
4990 | } | |
4991 | else | |
4992 | c_parser_cilk_for (parser, integer_zero_node); | |
4993 | break; | |
d037099f | 4994 | case RID_CILK_SYNC: |
4995 | c_parser_consume_token (parser); | |
4996 | c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); | |
a89e6c15 | 4997 | if (!flag_cilkplus) |
d037099f | 4998 | error_at (loc, "-fcilkplus must be enabled to use %<_Cilk_sync%>"); |
4999 | else | |
5000 | add_stmt (build_cilk_sync ()); | |
1576dec7 | 5001 | break; |
5002 | case RID_GOTO: | |
5003 | c_parser_consume_token (parser); | |
5004 | if (c_parser_next_token_is (parser, CPP_NAME)) | |
5005 | { | |
e60a6f7b | 5006 | stmt = c_finish_goto_label (loc, |
5007 | c_parser_peek_token (parser)->value); | |
1576dec7 | 5008 | c_parser_consume_token (parser); |
5009 | } | |
5010 | else if (c_parser_next_token_is (parser, CPP_MULT)) | |
5011 | { | |
b560fabd | 5012 | struct c_expr val; |
95f11b21 | 5013 | |
1576dec7 | 5014 | c_parser_consume_token (parser); |
b560fabd | 5015 | val = c_parser_expression (parser); |
fdd735a7 | 5016 | if (check_no_cilk (val.value, |
5017 | "Cilk array notation cannot be used as a computed goto expression", | |
5018 | "%<_Cilk_spawn%> statement cannot be used as a computed goto expression", | |
5019 | loc)) | |
5020 | val.value = error_mark_node; | |
b560fabd | 5021 | val = convert_lvalue_to_rvalue (loc, val, false, true); |
5022 | stmt = c_finish_goto_ptr (loc, val.value); | |
1576dec7 | 5023 | } |
5024 | else | |
5025 | c_parser_error (parser, "expected identifier or %<*%>"); | |
5026 | goto expect_semicolon; | |
5027 | case RID_CONTINUE: | |
5028 | c_parser_consume_token (parser); | |
e60a6f7b | 5029 | stmt = c_finish_bc_stmt (loc, &c_cont_label, false); |
1576dec7 | 5030 | goto expect_semicolon; |
5031 | case RID_BREAK: | |
5032 | c_parser_consume_token (parser); | |
e60a6f7b | 5033 | stmt = c_finish_bc_stmt (loc, &c_break_label, true); |
1576dec7 | 5034 | goto expect_semicolon; |
5035 | case RID_RETURN: | |
5036 | c_parser_consume_token (parser); | |
5037 | if (c_parser_next_token_is (parser, CPP_SEMICOLON)) | |
5038 | { | |
e60a6f7b | 5039 | stmt = c_finish_return (loc, NULL_TREE, NULL_TREE); |
1576dec7 | 5040 | c_parser_consume_token (parser); |
5041 | } | |
5042 | else | |
5043 | { | |
430b73ee | 5044 | location_t xloc = c_parser_peek_token (parser)->location; |
b9c74b4d | 5045 | struct c_expr expr = c_parser_expression_conv (parser); |
abc6c64f | 5046 | mark_exp_read (expr.value); |
430b73ee | 5047 | stmt = c_finish_return (xloc, expr.value, expr.original_type); |
1576dec7 | 5048 | goto expect_semicolon; |
5049 | } | |
5050 | break; | |
5051 | case RID_ASM: | |
5052 | stmt = c_parser_asm_statement (parser); | |
5053 | break; | |
4c0315d0 | 5054 | case RID_TRANSACTION_ATOMIC: |
5055 | case RID_TRANSACTION_RELAXED: | |
5056 | stmt = c_parser_transaction (parser, | |
5057 | c_parser_peek_token (parser)->keyword); | |
5058 | break; | |
5059 | case RID_TRANSACTION_CANCEL: | |
5060 | stmt = c_parser_transaction_cancel (parser); | |
5061 | goto expect_semicolon; | |
e5c75ac3 | 5062 | case RID_AT_THROW: |
1576dec7 | 5063 | gcc_assert (c_dialect_objc ()); |
5064 | c_parser_consume_token (parser); | |
5065 | if (c_parser_next_token_is (parser, CPP_SEMICOLON)) | |
5066 | { | |
e60a6f7b | 5067 | stmt = objc_build_throw_stmt (loc, NULL_TREE); |
1576dec7 | 5068 | c_parser_consume_token (parser); |
5069 | } | |
5070 | else | |
5071 | { | |
b560fabd | 5072 | struct c_expr expr = c_parser_expression (parser); |
5073 | expr = convert_lvalue_to_rvalue (loc, expr, false, false); | |
fdd735a7 | 5074 | if (check_no_cilk (expr.value, |
5075 | "Cilk array notation cannot be used for a throw expression", | |
5076 | "%<_Cilk_spawn%> statement cannot be used for a throw expression")) | |
5077 | expr.value = error_mark_node; | |
5078 | else | |
5079 | { | |
5080 | expr.value = c_fully_fold (expr.value, false, NULL); | |
5081 | stmt = objc_build_throw_stmt (loc, expr.value); | |
5082 | } | |
1576dec7 | 5083 | goto expect_semicolon; |
5084 | } | |
5085 | break; | |
e5c75ac3 | 5086 | case RID_AT_TRY: |
1576dec7 | 5087 | gcc_assert (c_dialect_objc ()); |
b3d2d312 | 5088 | c_parser_objc_try_catch_finally_statement (parser); |
1576dec7 | 5089 | break; |
5090 | case RID_AT_SYNCHRONIZED: | |
5091 | gcc_assert (c_dialect_objc ()); | |
5092 | c_parser_objc_synchronized_statement (parser); | |
5093 | break; | |
5094 | default: | |
5095 | goto expr_stmt; | |
5096 | } | |
5097 | break; | |
5098 | case CPP_SEMICOLON: | |
5099 | c_parser_consume_token (parser); | |
5100 | break; | |
5101 | case CPP_CLOSE_PAREN: | |
5102 | case CPP_CLOSE_SQUARE: | |
5103 | /* Avoid infinite loop in error recovery: | |
5104 | c_parser_skip_until_found stops at a closing nesting | |
5105 | delimiter without consuming it, but here we need to consume | |
5106 | it to proceed further. */ | |
5107 | c_parser_error (parser, "expected statement"); | |
5108 | c_parser_consume_token (parser); | |
5109 | break; | |
b75b98aa | 5110 | case CPP_PRAGMA: |
5111 | c_parser_pragma (parser, pragma_stmt); | |
5112 | break; | |
1576dec7 | 5113 | default: |
5114 | expr_stmt: | |
e60a6f7b | 5115 | stmt = c_finish_expr_stmt (loc, c_parser_expression_conv (parser).value); |
1576dec7 | 5116 | expect_semicolon: |
5117 | c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); | |
5118 | break; | |
5119 | } | |
5120 | /* Two cases cannot and do not have line numbers associated: If stmt | |
5121 | is degenerate, such as "2;", then stmt is an INTEGER_CST, which | |
5122 | cannot hold line numbers. But that's OK because the statement | |
5123 | will either be changed to a MODIFY_EXPR during gimplification of | |
5124 | the statement expr, or discarded. If stmt was compound, but | |
5125 | without new variables, we will have skipped the creation of a | |
5126 | BIND and will have a bare STATEMENT_LIST. But that's OK because | |
5127 | (recursively) all of the component statements should already have | |
5128 | line numbers assigned. ??? Can we discard no-op statements | |
5129 | earlier? */ | |
e60a6f7b | 5130 | if (CAN_HAVE_LOCATION_P (stmt) |
5131 | && EXPR_LOCATION (stmt) == UNKNOWN_LOCATION) | |
5132 | SET_EXPR_LOCATION (stmt, loc); | |
10c93a35 | 5133 | |
5134 | parser->in_if_block = in_if_block; | |
1576dec7 | 5135 | } |
5136 | ||
6513b50d | 5137 | /* Parse the condition from an if, do, while or for statements. */ |
5138 | ||
5139 | static tree | |
5140 | c_parser_condition (c_parser *parser) | |
5141 | { | |
e60a6f7b | 5142 | location_t loc = c_parser_peek_token (parser)->location; |
6513b50d | 5143 | tree cond; |
a75b1c71 | 5144 | cond = c_parser_expression_conv (parser).value; |
5145 | cond = c_objc_common_truthvalue_conversion (loc, cond); | |
5146 | cond = c_fully_fold (cond, false, NULL); | |
6513b50d | 5147 | if (warn_sequence_point) |
5148 | verify_sequence_points (cond); | |
5149 | return cond; | |
5150 | } | |
5151 | ||
1576dec7 | 5152 | /* Parse a parenthesized condition from an if, do or while statement. |
5153 | ||
5154 | condition: | |
5155 | ( expression ) | |
5156 | */ | |
5157 | static tree | |
5158 | c_parser_paren_condition (c_parser *parser) | |
5159 | { | |
1576dec7 | 5160 | tree cond; |
5161 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
5162 | return error_mark_node; | |
6513b50d | 5163 | cond = c_parser_condition (parser); |
1576dec7 | 5164 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); |
5165 | return cond; | |
5166 | } | |
5167 | ||
5168 | /* Parse a statement which is a block in C99. */ | |
5169 | ||
5170 | static tree | |
5171 | c_parser_c99_block_statement (c_parser *parser) | |
5172 | { | |
5173 | tree block = c_begin_compound_stmt (flag_isoc99); | |
e60a6f7b | 5174 | location_t loc = c_parser_peek_token (parser)->location; |
1576dec7 | 5175 | c_parser_statement (parser); |
e60a6f7b | 5176 | return c_end_compound_stmt (loc, block, flag_isoc99); |
1576dec7 | 5177 | } |
5178 | ||
10c93a35 | 5179 | /* Parse the body of an if statement. This is just parsing a |
5180 | statement but (a) it is a block in C99, (b) we track whether the | |
5181 | body is an if statement for the sake of -Wparentheses warnings, (c) | |
5182 | we handle an empty body specially for the sake of -Wempty-body | |
5183 | warnings, and (d) we call parser_compound_statement directly | |
5184 | because c_parser_statement_after_labels resets | |
5185 | parser->in_if_block. */ | |
1576dec7 | 5186 | |
5187 | static tree | |
5188 | c_parser_if_body (c_parser *parser, bool *if_p) | |
5189 | { | |
5190 | tree block = c_begin_compound_stmt (flag_isoc99); | |
e60a6f7b | 5191 | location_t body_loc = c_parser_peek_token (parser)->location; |
4f284d4a | 5192 | c_parser_all_labels (parser); |
1576dec7 | 5193 | *if_p = c_parser_next_token_is_keyword (parser, RID_IF); |
ffe8fd56 | 5194 | if (c_parser_next_token_is (parser, CPP_SEMICOLON)) |
10c93a35 | 5195 | { |
c2c7830b | 5196 | location_t loc = c_parser_peek_token (parser)->location; |
e60a6f7b | 5197 | add_stmt (build_empty_stmt (loc)); |
10c93a35 | 5198 | c_parser_consume_token (parser); |
c2c7830b | 5199 | if (!c_parser_next_token_is_keyword (parser, RID_ELSE)) |
5200 | warning_at (loc, OPT_Wempty_body, | |
5201 | "suggest braces around empty body in an %<if%> statement"); | |
10c93a35 | 5202 | } |
5203 | else if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) | |
5204 | add_stmt (c_parser_compound_statement (parser)); | |
5205 | else | |
5206 | c_parser_statement_after_labels (parser); | |
e60a6f7b | 5207 | return c_end_compound_stmt (body_loc, block, flag_isoc99); |
10c93a35 | 5208 | } |
5209 | ||
5210 | /* Parse the else body of an if statement. This is just parsing a | |
5211 | statement but (a) it is a block in C99, (b) we handle an empty body | |
5212 | specially for the sake of -Wempty-body warnings. */ | |
5213 | ||
5214 | static tree | |
5215 | c_parser_else_body (c_parser *parser) | |
5216 | { | |
e60a6f7b | 5217 | location_t else_loc = c_parser_peek_token (parser)->location; |
10c93a35 | 5218 | tree block = c_begin_compound_stmt (flag_isoc99); |
4f284d4a | 5219 | c_parser_all_labels (parser); |
10c93a35 | 5220 | if (c_parser_next_token_is (parser, CPP_SEMICOLON)) |
5221 | { | |
e60a6f7b | 5222 | location_t loc = c_parser_peek_token (parser)->location; |
5223 | warning_at (loc, | |
c2c7830b | 5224 | OPT_Wempty_body, |
5225 | "suggest braces around empty body in an %<else%> statement"); | |
e60a6f7b | 5226 | add_stmt (build_empty_stmt (loc)); |
10c93a35 | 5227 | c_parser_consume_token (parser); |
5228 | } | |
48e1416a | 5229 | else |
10c93a35 | 5230 | c_parser_statement_after_labels (parser); |
e60a6f7b | 5231 | return c_end_compound_stmt (else_loc, block, flag_isoc99); |
1576dec7 | 5232 | } |
5233 | ||
5234 | /* Parse an if statement (C90 6.6.4, C99 6.8.4). | |
5235 | ||
5236 | if-statement: | |
5237 | if ( expression ) statement | |
5238 | if ( expression ) statement else statement | |
5239 | */ | |
5240 | ||
5241 | static void | |
5242 | c_parser_if_statement (c_parser *parser) | |
5243 | { | |
5244 | tree block; | |
5245 | location_t loc; | |
5246 | tree cond; | |
10c93a35 | 5247 | bool first_if = false; |
1576dec7 | 5248 | tree first_body, second_body; |
10c93a35 | 5249 | bool in_if_block; |
3c6d4197 | 5250 | tree if_stmt; |
10c93a35 | 5251 | |
1576dec7 | 5252 | gcc_assert (c_parser_next_token_is_keyword (parser, RID_IF)); |
5253 | c_parser_consume_token (parser); | |
5254 | block = c_begin_compound_stmt (flag_isoc99); | |
5255 | loc = c_parser_peek_token (parser)->location; | |
5256 | cond = c_parser_paren_condition (parser); | |
fdd735a7 | 5257 | if (flag_cilkplus && contains_cilk_spawn_stmt (cond)) |
5258 | { | |
5259 | error_at (loc, "if statement cannot contain %<Cilk_spawn%>"); | |
5260 | cond = error_mark_node; | |
5261 | } | |
10c93a35 | 5262 | in_if_block = parser->in_if_block; |
5263 | parser->in_if_block = true; | |
1576dec7 | 5264 | first_body = c_parser_if_body (parser, &first_if); |
10c93a35 | 5265 | parser->in_if_block = in_if_block; |
1576dec7 | 5266 | if (c_parser_next_token_is_keyword (parser, RID_ELSE)) |
5267 | { | |
5268 | c_parser_consume_token (parser); | |
10c93a35 | 5269 | second_body = c_parser_else_body (parser); |
1576dec7 | 5270 | } |
5271 | else | |
5272 | second_body = NULL_TREE; | |
5273 | c_finish_if_stmt (loc, cond, first_body, second_body, first_if); | |
3c6d4197 | 5274 | if_stmt = c_end_compound_stmt (loc, block, flag_isoc99); |
5275 | ||
5276 | /* If the if statement contains array notations, then we expand them. */ | |
a89e6c15 | 5277 | if (flag_cilkplus && contains_array_notation_expr (if_stmt)) |
3c6d4197 | 5278 | if_stmt = fix_conditional_array_notations (if_stmt); |
5279 | add_stmt (if_stmt); | |
1576dec7 | 5280 | } |
5281 | ||
5282 | /* Parse a switch statement (C90 6.6.4, C99 6.8.4). | |
5283 | ||
5284 | switch-statement: | |
5285 | switch (expression) statement | |
5286 | */ | |
5287 | ||
5288 | static void | |
5289 | c_parser_switch_statement (c_parser *parser) | |
5290 | { | |
b560fabd | 5291 | struct c_expr ce; |
1576dec7 | 5292 | tree block, expr, body, save_break; |
e60a6f7b | 5293 | location_t switch_loc = c_parser_peek_token (parser)->location; |
5294 | location_t switch_cond_loc; | |
1576dec7 | 5295 | gcc_assert (c_parser_next_token_is_keyword (parser, RID_SWITCH)); |
5296 | c_parser_consume_token (parser); | |
5297 | block = c_begin_compound_stmt (flag_isoc99); | |
c69ec07d | 5298 | bool explicit_cast_p = false; |
1576dec7 | 5299 | if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) |
5300 | { | |
e60a6f7b | 5301 | switch_cond_loc = c_parser_peek_token (parser)->location; |
c69ec07d | 5302 | if (c_parser_next_token_is (parser, CPP_OPEN_PAREN) |
5303 | && c_token_starts_typename (c_parser_peek_2nd_token (parser))) | |
5304 | explicit_cast_p = true; | |
b560fabd | 5305 | ce = c_parser_expression (parser); |
5306 | ce = convert_lvalue_to_rvalue (switch_cond_loc, ce, true, false); | |
5307 | expr = ce.value; | |
fdd735a7 | 5308 | /* ??? expr has no valid location? */ |
5309 | if (check_no_cilk (expr, | |
5310 | "Cilk array notation cannot be used as a condition for switch statement", | |
5311 | "%<_Cilk_spawn%> statement cannot be used as a condition for switch statement", | |
5312 | switch_cond_loc)) | |
5313 | expr = error_mark_node; | |
1576dec7 | 5314 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); |
5315 | } | |
5316 | else | |
e60a6f7b | 5317 | { |
5318 | switch_cond_loc = UNKNOWN_LOCATION; | |
5319 | expr = error_mark_node; | |
5320 | } | |
c69ec07d | 5321 | c_start_case (switch_loc, switch_cond_loc, expr, explicit_cast_p); |
1576dec7 | 5322 | save_break = c_break_label; |
5323 | c_break_label = NULL_TREE; | |
5324 | body = c_parser_c99_block_statement (parser); | |
5213d6c9 | 5325 | c_finish_case (body, ce.original_type); |
1576dec7 | 5326 | if (c_break_label) |
e60a6f7b | 5327 | { |
5328 | location_t here = c_parser_peek_token (parser)->location; | |
5329 | tree t = build1 (LABEL_EXPR, void_type_node, c_break_label); | |
5330 | SET_EXPR_LOCATION (t, here); | |
5331 | add_stmt (t); | |
5332 | } | |
1576dec7 | 5333 | c_break_label = save_break; |
e60a6f7b | 5334 | add_stmt (c_end_compound_stmt (switch_loc, block, flag_isoc99)); |
1576dec7 | 5335 | } |
5336 | ||
5337 | /* Parse a while statement (C90 6.6.5, C99 6.8.5). | |
5338 | ||
5339 | while-statement: | |
5340 | while (expression) statement | |
5341 | */ | |
5342 | ||
5343 | static void | |
4c90c04c | 5344 | c_parser_while_statement (c_parser *parser, bool ivdep) |
1576dec7 | 5345 | { |
5346 | tree block, cond, body, save_break, save_cont; | |
5347 | location_t loc; | |
5348 | gcc_assert (c_parser_next_token_is_keyword (parser, RID_WHILE)); | |
5349 | c_parser_consume_token (parser); | |
5350 | block = c_begin_compound_stmt (flag_isoc99); | |
5351 | loc = c_parser_peek_token (parser)->location; | |
5352 | cond = c_parser_paren_condition (parser); | |
fdd735a7 | 5353 | if (check_no_cilk (cond, |
5354 | "Cilk array notation cannot be used as a condition for while statement", | |
5355 | "%<_Cilk_spawn%> statement cannot be used as a condition for while statement")) | |
5356 | cond = error_mark_node; | |
4c90c04c | 5357 | if (ivdep && cond != error_mark_node) |
5358 | cond = build2 (ANNOTATE_EXPR, TREE_TYPE (cond), cond, | |
5359 | build_int_cst (integer_type_node, | |
5360 | annot_expr_ivdep_kind)); | |
1576dec7 | 5361 | save_break = c_break_label; |
5362 | c_break_label = NULL_TREE; | |
5363 | save_cont = c_cont_label; | |
5364 | c_cont_label = NULL_TREE; | |
5365 | body = c_parser_c99_block_statement (parser); | |
5366 | c_finish_loop (loc, cond, NULL, body, c_break_label, c_cont_label, true); | |
e60a6f7b | 5367 | add_stmt (c_end_compound_stmt (loc, block, flag_isoc99)); |
1576dec7 | 5368 | c_break_label = save_break; |
5369 | c_cont_label = save_cont; | |
5370 | } | |
5371 | ||
5372 | /* Parse a do statement (C90 6.6.5, C99 6.8.5). | |
5373 | ||
5374 | do-statement: | |
5375 | do statement while ( expression ) ; | |
5376 | */ | |
5377 | ||
5378 | static void | |
4c90c04c | 5379 | c_parser_do_statement (c_parser *parser, bool ivdep) |
1576dec7 | 5380 | { |
5381 | tree block, cond, body, save_break, save_cont, new_break, new_cont; | |
5382 | location_t loc; | |
5383 | gcc_assert (c_parser_next_token_is_keyword (parser, RID_DO)); | |
5384 | c_parser_consume_token (parser); | |
ffe8fd56 | 5385 | if (c_parser_next_token_is (parser, CPP_SEMICOLON)) |
e3b80d49 | 5386 | warning_at (c_parser_peek_token (parser)->location, |
5387 | OPT_Wempty_body, | |
5388 | "suggest braces around empty body in %<do%> statement"); | |
1576dec7 | 5389 | block = c_begin_compound_stmt (flag_isoc99); |
5390 | loc = c_parser_peek_token (parser)->location; | |
5391 | save_break = c_break_label; | |
5392 | c_break_label = NULL_TREE; | |
5393 | save_cont = c_cont_label; | |
5394 | c_cont_label = NULL_TREE; | |
5395 | body = c_parser_c99_block_statement (parser); | |
5396 | c_parser_require_keyword (parser, RID_WHILE, "expected %<while%>"); | |
5397 | new_break = c_break_label; | |
5398 | c_break_label = save_break; | |
5399 | new_cont = c_cont_label; | |
5400 | c_cont_label = save_cont; | |
5401 | cond = c_parser_paren_condition (parser); | |
fdd735a7 | 5402 | if (check_no_cilk (cond, |
5403 | "Cilk array notation cannot be used as a condition for a do-while statement", | |
5404 | "%<_Cilk_spawn%> statement cannot be used as a condition for a do-while statement")) | |
5405 | cond = error_mark_node; | |
4c90c04c | 5406 | if (ivdep && cond != error_mark_node) |
5407 | cond = build2 (ANNOTATE_EXPR, TREE_TYPE (cond), cond, | |
5408 | build_int_cst (integer_type_node, | |
5409 | annot_expr_ivdep_kind)); | |
1576dec7 | 5410 | if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>")) |
5411 | c_parser_skip_to_end_of_block_or_statement (parser); | |
5412 | c_finish_loop (loc, cond, NULL, body, new_break, new_cont, false); | |
e60a6f7b | 5413 | add_stmt (c_end_compound_stmt (loc, block, flag_isoc99)); |
1576dec7 | 5414 | } |
5415 | ||
5416 | /* Parse a for statement (C90 6.6.5, C99 6.8.5). | |
5417 | ||
5418 | for-statement: | |
5419 | for ( expression[opt] ; expression[opt] ; expression[opt] ) statement | |
5420 | for ( nested-declaration expression[opt] ; expression[opt] ) statement | |
5421 | ||
5422 | The form with a declaration is new in C99. | |
5423 | ||
5424 | ??? In accordance with the old parser, the declaration may be a | |
5425 | nested function, which is then rejected in check_for_loop_decls, | |
5426 | but does it make any sense for this to be included in the grammar? | |
5427 | Note in particular that the nested function does not include a | |
5428 | trailing ';', whereas the "declaration" production includes one. | |
5429 | Also, can we reject bad declarations earlier and cheaper than | |
0a65c3bb | 5430 | check_for_loop_decls? |
5431 | ||
5432 | In Objective-C, there are two additional variants: | |
5433 | ||
5434 | foreach-statement: | |
5435 | for ( expression in expresssion ) statement | |
5436 | for ( declaration in expression ) statement | |
5437 | ||
5438 | This is inconsistent with C, because the second variant is allowed | |
5439 | even if c99 is not enabled. | |
5440 | ||
5441 | The rest of the comment documents these Objective-C foreach-statement. | |
5442 | ||
5443 | Here is the canonical example of the first variant: | |
5444 | for (object in array) { do something with object } | |
5445 | we call the first expression ("object") the "object_expression" and | |
5446 | the second expression ("array") the "collection_expression". | |
5447 | object_expression must be an lvalue of type "id" (a generic Objective-C | |
5448 | object) because the loop works by assigning to object_expression the | |
5449 | various objects from the collection_expression. collection_expression | |
5450 | must evaluate to something of type "id" which responds to the method | |
5451 | countByEnumeratingWithState:objects:count:. | |
5452 | ||
5453 | The canonical example of the second variant is: | |
5454 | for (id object in array) { do something with object } | |
5455 | which is completely equivalent to | |
5456 | { | |
5457 | id object; | |
5458 | for (object in array) { do something with object } | |
5459 | } | |
5460 | Note that initizializing 'object' in some way (eg, "for ((object = | |
5461 | xxx) in array) { do something with object }") is possibly | |
5462 | technically valid, but completely pointless as 'object' will be | |
5463 | assigned to something else as soon as the loop starts. We should | |
5464 | most likely reject it (TODO). | |
5465 | ||
5466 | The beginning of the Objective-C foreach-statement looks exactly | |
5467 | like the beginning of the for-statement, and we can tell it is a | |
5468 | foreach-statement only because the initial declaration or | |
5469 | expression is terminated by 'in' instead of ';'. | |
5470 | */ | |
1576dec7 | 5471 | |
5472 | static void | |
4644b593 | 5473 | c_parser_for_statement (c_parser *parser, bool ivdep) |
1576dec7 | 5474 | { |
5475 | tree block, cond, incr, save_break, save_cont, body; | |
0a65c3bb | 5476 | /* The following are only used when parsing an ObjC foreach statement. */ |
65d95190 | 5477 | tree object_expression; |
5478 | /* Silence the bogus uninitialized warning. */ | |
5479 | tree collection_expression = NULL; | |
e60a6f7b | 5480 | location_t loc = c_parser_peek_token (parser)->location; |
5481 | location_t for_loc = c_parser_peek_token (parser)->location; | |
0a65c3bb | 5482 | bool is_foreach_statement = false; |
1576dec7 | 5483 | gcc_assert (c_parser_next_token_is_keyword (parser, RID_FOR)); |
5484 | c_parser_consume_token (parser); | |
0a65c3bb | 5485 | /* Open a compound statement in Objective-C as well, just in case this is |
5486 | as foreach expression. */ | |
5487 | block = c_begin_compound_stmt (flag_isoc99 || c_dialect_objc ()); | |
b54b6a4d | 5488 | cond = error_mark_node; |
5489 | incr = error_mark_node; | |
1576dec7 | 5490 | if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) |
5491 | { | |
5492 | /* Parse the initialization declaration or expression. */ | |
0a65c3bb | 5493 | object_expression = error_mark_node; |
21e609c5 | 5494 | parser->objc_could_be_foreach_context = c_dialect_objc (); |
1576dec7 | 5495 | if (c_parser_next_token_is (parser, CPP_SEMICOLON)) |
5496 | { | |
21e609c5 | 5497 | parser->objc_could_be_foreach_context = false; |
1576dec7 | 5498 | c_parser_consume_token (parser); |
e60a6f7b | 5499 | c_finish_expr_stmt (loc, NULL_TREE); |
1576dec7 | 5500 | } |
71bb4bc6 | 5501 | else if (c_parser_next_tokens_start_declaration (parser)) |
1576dec7 | 5502 | { |
0a65c3bb | 5503 | c_parser_declaration_or_fndef (parser, true, true, true, true, true, |
bc7bff74 | 5504 | &object_expression, vNULL); |
0a65c3bb | 5505 | parser->objc_could_be_foreach_context = false; |
5506 | ||
5507 | if (c_parser_next_token_is_keyword (parser, RID_IN)) | |
5508 | { | |
5509 | c_parser_consume_token (parser); | |
5510 | is_foreach_statement = true; | |
5511 | if (check_for_loop_decls (for_loc, true) == NULL_TREE) | |
5512 | c_parser_error (parser, "multiple iterating variables in fast enumeration"); | |
5513 | } | |
5514 | else | |
5515 | check_for_loop_decls (for_loc, flag_isoc99); | |
1576dec7 | 5516 | } |
5517 | else if (c_parser_next_token_is_keyword (parser, RID_EXTENSION)) | |
5518 | { | |
5519 | /* __extension__ can start a declaration, but is also an | |
5520 | unary operator that can start an expression. Consume all | |
5521 | but the last of a possible series of __extension__ to | |
5522 | determine which. */ | |
5523 | while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD | |
5524 | && (c_parser_peek_2nd_token (parser)->keyword | |
5525 | == RID_EXTENSION)) | |
5526 | c_parser_consume_token (parser); | |
f80e7755 | 5527 | if (c_token_starts_declaration (c_parser_peek_2nd_token (parser))) |
1576dec7 | 5528 | { |
5529 | int ext; | |
5530 | ext = disable_extension_diagnostics (); | |
5531 | c_parser_consume_token (parser); | |
f80e7755 | 5532 | c_parser_declaration_or_fndef (parser, true, true, true, true, |
bc7bff74 | 5533 | true, &object_expression, vNULL); |
0a65c3bb | 5534 | parser->objc_could_be_foreach_context = false; |
5535 | ||
1576dec7 | 5536 | restore_extension_diagnostics (ext); |
0a65c3bb | 5537 | if (c_parser_next_token_is_keyword (parser, RID_IN)) |
5538 | { | |
5539 | c_parser_consume_token (parser); | |
5540 | is_foreach_statement = true; | |
5541 | if (check_for_loop_decls (for_loc, true) == NULL_TREE) | |
5542 | c_parser_error (parser, "multiple iterating variables in fast enumeration"); | |
5543 | } | |
5544 | else | |
5545 | check_for_loop_decls (for_loc, flag_isoc99); | |
1576dec7 | 5546 | } |
5547 | else | |
5548 | goto init_expr; | |
5549 | } | |
5550 | else | |
5551 | { | |
5552 | init_expr: | |
0a65c3bb | 5553 | { |
b560fabd | 5554 | struct c_expr ce; |
0a65c3bb | 5555 | tree init_expression; |
b560fabd | 5556 | ce = c_parser_expression (parser); |
fdd735a7 | 5557 | /* In theory we could forbid _Cilk_spawn here, as the spec says "only in top |
5558 | level statement", but it works just fine, so allow it. */ | |
b560fabd | 5559 | init_expression = ce.value; |
0a65c3bb | 5560 | parser->objc_could_be_foreach_context = false; |
5561 | if (c_parser_next_token_is_keyword (parser, RID_IN)) | |
5562 | { | |
5563 | c_parser_consume_token (parser); | |
5564 | is_foreach_statement = true; | |
5565 | if (! lvalue_p (init_expression)) | |
5566 | c_parser_error (parser, "invalid iterating variable in fast enumeration"); | |
81976f54 | 5567 | object_expression = c_fully_fold (init_expression, false, NULL); |
0a65c3bb | 5568 | } |
5569 | else | |
5570 | { | |
b560fabd | 5571 | ce = convert_lvalue_to_rvalue (loc, ce, true, false); |
5572 | init_expression = ce.value; | |
0a65c3bb | 5573 | c_finish_expr_stmt (loc, init_expression); |
5574 | c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); | |
5575 | } | |
5576 | } | |
1576dec7 | 5577 | } |
0a65c3bb | 5578 | /* Parse the loop condition. In the case of a foreach |
5579 | statement, there is no loop condition. */ | |
21e609c5 | 5580 | gcc_assert (!parser->objc_could_be_foreach_context); |
0a65c3bb | 5581 | if (!is_foreach_statement) |
1576dec7 | 5582 | { |
0a65c3bb | 5583 | if (c_parser_next_token_is (parser, CPP_SEMICOLON)) |
5584 | { | |
4644b593 | 5585 | if (ivdep) |
5586 | { | |
5587 | c_parser_error (parser, "missing loop condition in loop with " | |
5588 | "%<GCC ivdep%> pragma"); | |
5589 | cond = error_mark_node; | |
5590 | } | |
5591 | else | |
5592 | { | |
5593 | c_parser_consume_token (parser); | |
5594 | cond = NULL_TREE; | |
5595 | } | |
0a65c3bb | 5596 | } |
5597 | else | |
5598 | { | |
5599 | cond = c_parser_condition (parser); | |
fdd735a7 | 5600 | if (check_no_cilk (cond, |
5601 | "Cilk array notation cannot be used in a condition for a for-loop", | |
5602 | "%<_Cilk_spawn%> statement cannot be used in a condition for a for-loop")) | |
5603 | cond = error_mark_node; | |
3c6d4197 | 5604 | c_parser_skip_until_found (parser, CPP_SEMICOLON, |
5605 | "expected %<;%>"); | |
0a65c3bb | 5606 | } |
4644b593 | 5607 | if (ivdep && cond != error_mark_node) |
5608 | cond = build2 (ANNOTATE_EXPR, TREE_TYPE (cond), cond, | |
5609 | build_int_cst (integer_type_node, | |
5610 | annot_expr_ivdep_kind)); | |
1576dec7 | 5611 | } |
0a65c3bb | 5612 | /* Parse the increment expression (the third expression in a |
5613 | for-statement). In the case of a foreach-statement, this is | |
5614 | the expression that follows the 'in'. */ | |
5615 | if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) | |
1576dec7 | 5616 | { |
0a65c3bb | 5617 | if (is_foreach_statement) |
5618 | { | |
5619 | c_parser_error (parser, "missing collection in fast enumeration"); | |
5620 | collection_expression = error_mark_node; | |
5621 | } | |
5622 | else | |
5623 | incr = c_process_expr_stmt (loc, NULL_TREE); | |
1576dec7 | 5624 | } |
1576dec7 | 5625 | else |
0a65c3bb | 5626 | { |
5627 | if (is_foreach_statement) | |
81976f54 | 5628 | collection_expression = c_fully_fold (c_parser_expression (parser).value, |
5629 | false, NULL); | |
0a65c3bb | 5630 | else |
b560fabd | 5631 | { |
5632 | struct c_expr ce = c_parser_expression (parser); | |
5633 | ce = convert_lvalue_to_rvalue (loc, ce, true, false); | |
5634 | incr = c_process_expr_stmt (loc, ce.value); | |
5635 | } | |
0a65c3bb | 5636 | } |
1576dec7 | 5637 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); |
5638 | } | |
1576dec7 | 5639 | save_break = c_break_label; |
5640 | c_break_label = NULL_TREE; | |
5641 | save_cont = c_cont_label; | |
5642 | c_cont_label = NULL_TREE; | |
5643 | body = c_parser_c99_block_statement (parser); | |
0a65c3bb | 5644 | if (is_foreach_statement) |
5645 | objc_finish_foreach_loop (loc, object_expression, collection_expression, body, c_break_label, c_cont_label); | |
5646 | else | |
5647 | c_finish_loop (loc, cond, incr, body, c_break_label, c_cont_label, true); | |
5648 | add_stmt (c_end_compound_stmt (loc, block, flag_isoc99 || c_dialect_objc ())); | |
1576dec7 | 5649 | c_break_label = save_break; |
5650 | c_cont_label = save_cont; | |
5651 | } | |
5652 | ||
5653 | /* Parse an asm statement, a GNU extension. This is a full-blown asm | |
5654 | statement with inputs, outputs, clobbers, and volatile tag | |
5655 | allowed. | |
5656 | ||
5657 | asm-statement: | |
5658 | asm type-qualifier[opt] ( asm-argument ) ; | |
78f55ca8 | 5659 | asm type-qualifier[opt] goto ( asm-goto-argument ) ; |
1576dec7 | 5660 | |
5661 | asm-argument: | |
5662 | asm-string-literal | |
5663 | asm-string-literal : asm-operands[opt] | |
5664 | asm-string-literal : asm-operands[opt] : asm-operands[opt] | |
78f55ca8 | 5665 | asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers[opt] |
5666 | ||
5667 | asm-goto-argument: | |
5668 | asm-string-literal : : asm-operands[opt] : asm-clobbers[opt] \ | |
5669 | : asm-goto-operands | |
1576dec7 | 5670 | |
5671 | Qualifiers other than volatile are accepted in the syntax but | |
5672 | warned for. */ | |
5673 | ||
5674 | static tree | |
5675 | c_parser_asm_statement (c_parser *parser) | |
5676 | { | |
78f55ca8 | 5677 | tree quals, str, outputs, inputs, clobbers, labels, ret; |
5678 | bool simple, is_goto; | |
e60a6f7b | 5679 | location_t asm_loc = c_parser_peek_token (parser)->location; |
78f55ca8 | 5680 | int section, nsections; |
5681 | ||
1576dec7 | 5682 | gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM)); |
5683 | c_parser_consume_token (parser); | |
5684 | if (c_parser_next_token_is_keyword (parser, RID_VOLATILE)) | |
5685 | { | |
5686 | quals = c_parser_peek_token (parser)->value; | |
5687 | c_parser_consume_token (parser); | |
5688 | } | |
5689 | else if (c_parser_next_token_is_keyword (parser, RID_CONST) | |
5690 | || c_parser_next_token_is_keyword (parser, RID_RESTRICT)) | |
5691 | { | |
e3b80d49 | 5692 | warning_at (c_parser_peek_token (parser)->location, |
5693 | 0, | |
5694 | "%E qualifier ignored on asm", | |
5695 | c_parser_peek_token (parser)->value); | |
1576dec7 | 5696 | quals = NULL_TREE; |
5697 | c_parser_consume_token (parser); | |
5698 | } | |
5699 | else | |
5700 | quals = NULL_TREE; | |
78f55ca8 | 5701 | |
5702 | is_goto = false; | |
5703 | if (c_parser_next_token_is_keyword (parser, RID_GOTO)) | |
5704 | { | |
5705 | c_parser_consume_token (parser); | |
5706 | is_goto = true; | |
5707 | } | |
5708 | ||
1576dec7 | 5709 | /* ??? Follow the C++ parser rather than using the |
8115b8be | 5710 | lex_untranslated_string kludge. */ |
5711 | parser->lex_untranslated_string = true; | |
78f55ca8 | 5712 | ret = NULL; |
5713 | ||
1576dec7 | 5714 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) |
78f55ca8 | 5715 | goto error; |
5716 | ||
1576dec7 | 5717 | str = c_parser_asm_string_literal (parser); |
0930c694 | 5718 | if (str == NULL_TREE) |
78f55ca8 | 5719 | goto error_close_paren; |
5720 | ||
5721 | simple = true; | |
5722 | outputs = NULL_TREE; | |
5723 | inputs = NULL_TREE; | |
5724 | clobbers = NULL_TREE; | |
5725 | labels = NULL_TREE; | |
5726 | ||
5727 | if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN) && !is_goto) | |
5728 | goto done_asm; | |
5729 | ||
5730 | /* Parse each colon-delimited section of operands. */ | |
5731 | nsections = 3 + is_goto; | |
5732 | for (section = 0; section < nsections; ++section) | |
0930c694 | 5733 | { |
78f55ca8 | 5734 | if (!c_parser_require (parser, CPP_COLON, |
5735 | is_goto | |
5736 | ? "expected %<:%>" | |
5737 | : "expected %<:%> or %<)%>")) | |
5738 | goto error_close_paren; | |
5739 | ||
5740 | /* Once past any colon, we're no longer a simple asm. */ | |
5741 | simple = false; | |
5742 | ||
5743 | if ((!c_parser_next_token_is (parser, CPP_COLON) | |
5744 | && !c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) | |
5745 | || section == 3) | |
5746 | switch (section) | |
5747 | { | |
5748 | case 0: | |
5749 | /* For asm goto, we don't allow output operands, but reserve | |
5750 | the slot for a future extension that does allow them. */ | |
5751 | if (!is_goto) | |
035b65e2 | 5752 | outputs = c_parser_asm_operands (parser); |
78f55ca8 | 5753 | break; |
5754 | case 1: | |
035b65e2 | 5755 | inputs = c_parser_asm_operands (parser); |
78f55ca8 | 5756 | break; |
5757 | case 2: | |
5758 | clobbers = c_parser_asm_clobbers (parser); | |
5759 | break; | |
5760 | case 3: | |
5761 | labels = c_parser_asm_goto_operands (parser); | |
5762 | break; | |
5763 | default: | |
5764 | gcc_unreachable (); | |
5765 | } | |
5766 | ||
5767 | if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN) && !is_goto) | |
5768 | goto done_asm; | |
1576dec7 | 5769 | } |
78f55ca8 | 5770 | |
1576dec7 | 5771 | done_asm: |
1576dec7 | 5772 | if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>")) |
5773 | { | |
5774 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); | |
78f55ca8 | 5775 | goto error; |
1576dec7 | 5776 | } |
78f55ca8 | 5777 | |
1576dec7 | 5778 | if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>")) |
5779 | c_parser_skip_to_end_of_block_or_statement (parser); | |
78f55ca8 | 5780 | |
e60a6f7b | 5781 | ret = build_asm_stmt (quals, build_asm_expr (asm_loc, str, outputs, inputs, |
78f55ca8 | 5782 | clobbers, labels, simple)); |
5783 | ||
5784 | error: | |
5785 | parser->lex_untranslated_string = false; | |
1576dec7 | 5786 | return ret; |
78f55ca8 | 5787 | |
5788 | error_close_paren: | |
5789 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); | |
5790 | goto error; | |
1576dec7 | 5791 | } |
5792 | ||
035b65e2 | 5793 | /* Parse asm operands, a GNU extension. |
1576dec7 | 5794 | |
5795 | asm-operands: | |
5796 | asm-operand | |
5797 | asm-operands , asm-operand | |
5798 | ||
5799 | asm-operand: | |
5800 | asm-string-literal ( expression ) | |
5801 | [ identifier ] asm-string-literal ( expression ) | |
5802 | */ | |
5803 | ||
5804 | static tree | |
035b65e2 | 5805 | c_parser_asm_operands (c_parser *parser) |
1576dec7 | 5806 | { |
5807 | tree list = NULL_TREE; | |
5808 | while (true) | |
5809 | { | |
e78cf9a7 | 5810 | tree name, str; |
5811 | struct c_expr expr; | |
1576dec7 | 5812 | if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE)) |
5813 | { | |
5814 | c_parser_consume_token (parser); | |
5815 | if (c_parser_next_token_is (parser, CPP_NAME)) | |
5816 | { | |
5817 | tree id = c_parser_peek_token (parser)->value; | |
5818 | c_parser_consume_token (parser); | |
5819 | name = build_string (IDENTIFIER_LENGTH (id), | |
5820 | IDENTIFIER_POINTER (id)); | |
5821 | } | |
5822 | else | |
5823 | { | |
5824 | c_parser_error (parser, "expected identifier"); | |
5825 | c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL); | |
5826 | return NULL_TREE; | |
5827 | } | |
5828 | c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, | |
5829 | "expected %<]%>"); | |
5830 | } | |
5831 | else | |
5832 | name = NULL_TREE; | |
5833 | str = c_parser_asm_string_literal (parser); | |
5834 | if (str == NULL_TREE) | |
5835 | return NULL_TREE; | |
8115b8be | 5836 | parser->lex_untranslated_string = false; |
1576dec7 | 5837 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) |
5838 | { | |
8115b8be | 5839 | parser->lex_untranslated_string = true; |
1576dec7 | 5840 | return NULL_TREE; |
5841 | } | |
e78cf9a7 | 5842 | expr = c_parser_expression (parser); |
abc6c64f | 5843 | mark_exp_read (expr.value); |
8115b8be | 5844 | parser->lex_untranslated_string = true; |
1576dec7 | 5845 | if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>")) |
5846 | { | |
5847 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); | |
5848 | return NULL_TREE; | |
5849 | } | |
5850 | list = chainon (list, build_tree_list (build_tree_list (name, str), | |
e78cf9a7 | 5851 | expr.value)); |
1576dec7 | 5852 | if (c_parser_next_token_is (parser, CPP_COMMA)) |
5853 | c_parser_consume_token (parser); | |
5854 | else | |
5855 | break; | |
5856 | } | |
5857 | return list; | |
5858 | } | |
5859 | ||
5860 | /* Parse asm clobbers, a GNU extension. | |
5861 | ||
5862 | asm-clobbers: | |
5863 | asm-string-literal | |
5864 | asm-clobbers , asm-string-literal | |
5865 | */ | |
5866 | ||
5867 | static tree | |
5868 | c_parser_asm_clobbers (c_parser *parser) | |
5869 | { | |
5870 | tree list = NULL_TREE; | |
5871 | while (true) | |
5872 | { | |
5873 | tree str = c_parser_asm_string_literal (parser); | |
5874 | if (str) | |
5875 | list = tree_cons (NULL_TREE, str, list); | |
5876 | else | |
5877 | return NULL_TREE; | |
5878 | if (c_parser_next_token_is (parser, CPP_COMMA)) | |
5879 | c_parser_consume_token (parser); | |
5880 | else | |
5881 | break; | |
5882 | } | |
5883 | return list; | |
5884 | } | |
5885 | ||
78f55ca8 | 5886 | /* Parse asm goto labels, a GNU extension. |
48e1416a | 5887 | |
78f55ca8 | 5888 | asm-goto-operands: |
5889 | identifier | |
5890 | asm-goto-operands , identifier | |
5891 | */ | |
5892 | ||
5893 | static tree | |
5894 | c_parser_asm_goto_operands (c_parser *parser) | |
5895 | { | |
5896 | tree list = NULL_TREE; | |
5897 | while (true) | |
5898 | { | |
5899 | tree name, label; | |
5900 | ||
5901 | if (c_parser_next_token_is (parser, CPP_NAME)) | |
5902 | { | |
5903 | c_token *tok = c_parser_peek_token (parser); | |
5904 | name = tok->value; | |
5905 | label = lookup_label_for_goto (tok->location, name); | |
5906 | c_parser_consume_token (parser); | |
5907 | TREE_USED (label) = 1; | |
5908 | } | |
5909 | else | |
5910 | { | |
5911 | c_parser_error (parser, "expected identifier"); | |
5912 | return NULL_TREE; | |
5913 | } | |
5914 | ||
5915 | name = build_string (IDENTIFIER_LENGTH (name), | |
5916 | IDENTIFIER_POINTER (name)); | |
5917 | list = tree_cons (name, label, list); | |
5918 | if (c_parser_next_token_is (parser, CPP_COMMA)) | |
5919 | c_parser_consume_token (parser); | |
5920 | else | |
5921 | return nreverse (list); | |
5922 | } | |
5923 | } | |
5924 | ||
1576dec7 | 5925 | /* Parse an expression other than a compound expression; that is, an |
5926 | assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not | |
5927 | NULL then it is an Objective-C message expression which is the | |
5928 | primary-expression starting the expression as an initializer. | |
5929 | ||
5930 | assignment-expression: | |
5931 | conditional-expression | |
5932 | unary-expression assignment-operator assignment-expression | |
5933 | ||
5934 | assignment-operator: one of | |
5935 | = *= /= %= += -= <<= >>= &= ^= |= | |
5936 | ||
5937 | In GNU C we accept any conditional expression on the LHS and | |
5938 | diagnose the invalid lvalue rather than producing a syntax | |
5939 | error. */ | |
5940 | ||
5941 | static struct c_expr | |
bc7bff74 | 5942 | c_parser_expr_no_commas (c_parser *parser, struct c_expr *after, |
5943 | tree omp_atomic_lhs) | |
1576dec7 | 5944 | { |
5945 | struct c_expr lhs, rhs, ret; | |
5946 | enum tree_code code; | |
e60a6f7b | 5947 | location_t op_location, exp_location; |
1576dec7 | 5948 | gcc_assert (!after || c_dialect_objc ()); |
bc7bff74 | 5949 | lhs = c_parser_conditional_expression (parser, after, omp_atomic_lhs); |
b6889cb0 | 5950 | op_location = c_parser_peek_token (parser)->location; |
1576dec7 | 5951 | switch (c_parser_peek_token (parser)->type) |
5952 | { | |
5953 | case CPP_EQ: | |
5954 | code = NOP_EXPR; | |
5955 | break; | |
5956 | case CPP_MULT_EQ: | |
5957 | code = MULT_EXPR; | |
5958 | break; | |
5959 | case CPP_DIV_EQ: | |
5960 | code = TRUNC_DIV_EXPR; | |
5961 | break; | |
5962 | case CPP_MOD_EQ: | |
5963 | code = TRUNC_MOD_EXPR; | |
5964 | break; | |
5965 | case CPP_PLUS_EQ: | |
5966 | code = PLUS_EXPR; | |
5967 | break; | |
5968 | case CPP_MINUS_EQ: | |
5969 | code = MINUS_EXPR; | |
5970 | break; | |
5971 | case CPP_LSHIFT_EQ: | |
5972 | code = LSHIFT_EXPR; | |
5973 | break; | |
5974 | case CPP_RSHIFT_EQ: | |
5975 | code = RSHIFT_EXPR; | |
5976 | break; | |
5977 | case CPP_AND_EQ: | |
5978 | code = BIT_AND_EXPR; | |
5979 | break; | |
5980 | case CPP_XOR_EQ: | |
5981 | code = BIT_XOR_EXPR; | |
5982 | break; | |
5983 | case CPP_OR_EQ: | |
5984 | code = BIT_IOR_EXPR; | |
5985 | break; | |
5986 | default: | |
5987 | return lhs; | |
5988 | } | |
5989 | c_parser_consume_token (parser); | |
e60a6f7b | 5990 | exp_location = c_parser_peek_token (parser)->location; |
1576dec7 | 5991 | rhs = c_parser_expr_no_commas (parser, NULL); |
b560fabd | 5992 | rhs = convert_lvalue_to_rvalue (exp_location, rhs, true, true); |
3c6d4197 | 5993 | |
cc92dddc | 5994 | ret.value = build_modify_expr (op_location, lhs.value, lhs.original_type, |
5995 | code, exp_location, rhs.value, | |
5996 | rhs.original_type); | |
1576dec7 | 5997 | if (code == NOP_EXPR) |
5998 | ret.original_code = MODIFY_EXPR; | |
5999 | else | |
6000 | { | |
6001 | TREE_NO_WARNING (ret.value) = 1; | |
6002 | ret.original_code = ERROR_MARK; | |
6003 | } | |
841fdaa6 | 6004 | ret.original_type = NULL; |
1576dec7 | 6005 | return ret; |
6006 | } | |
6007 | ||
6008 | /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER | |
6009 | is not NULL then it is an Objective-C message expression which is | |
6010 | the primary-expression starting the expression as an initializer. | |
6011 | ||
6012 | conditional-expression: | |
6013 | logical-OR-expression | |
6014 | logical-OR-expression ? expression : conditional-expression | |
6015 | ||
6016 | GNU extensions: | |
6017 | ||
6018 | conditional-expression: | |
6019 | logical-OR-expression ? : conditional-expression | |
6020 | */ | |
6021 | ||
6022 | static struct c_expr | |
bc7bff74 | 6023 | c_parser_conditional_expression (c_parser *parser, struct c_expr *after, |
6024 | tree omp_atomic_lhs) | |
1576dec7 | 6025 | { |
6026 | struct c_expr cond, exp1, exp2, ret; | |
b9bdfa0b | 6027 | location_t cond_loc, colon_loc, middle_loc; |
8e70fb09 | 6028 | |
1576dec7 | 6029 | gcc_assert (!after || c_dialect_objc ()); |
8e70fb09 | 6030 | |
bc7bff74 | 6031 | cond = c_parser_binary_expression (parser, after, omp_atomic_lhs); |
8e70fb09 | 6032 | |
1576dec7 | 6033 | if (c_parser_next_token_is_not (parser, CPP_QUERY)) |
6034 | return cond; | |
e60a6f7b | 6035 | cond_loc = c_parser_peek_token (parser)->location; |
b560fabd | 6036 | cond = convert_lvalue_to_rvalue (cond_loc, cond, true, true); |
1576dec7 | 6037 | c_parser_consume_token (parser); |
6038 | if (c_parser_next_token_is (parser, CPP_COLON)) | |
6039 | { | |
c6418a4e | 6040 | tree eptype = NULL_TREE; |
b9bdfa0b | 6041 | |
6042 | middle_loc = c_parser_peek_token (parser)->location; | |
29438999 | 6043 | pedwarn (middle_loc, OPT_Wpedantic, |
21ca8540 | 6044 | "ISO C forbids omitting the middle term of a ?: expression"); |
b9bdfa0b | 6045 | warn_for_omitted_condop (middle_loc, cond.value); |
c6418a4e | 6046 | if (TREE_CODE (cond.value) == EXCESS_PRECISION_EXPR) |
6047 | { | |
6048 | eptype = TREE_TYPE (cond.value); | |
6049 | cond.value = TREE_OPERAND (cond.value, 0); | |
6050 | } | |
1576dec7 | 6051 | /* Make sure first operand is calculated only once. */ |
a75b1c71 | 6052 | exp1.value = c_save_expr (default_conversion (cond.value)); |
c6418a4e | 6053 | if (eptype) |
6054 | exp1.value = build1 (EXCESS_PRECISION_EXPR, eptype, exp1.value); | |
841fdaa6 | 6055 | exp1.original_type = NULL; |
8e70fb09 | 6056 | cond.value = c_objc_common_truthvalue_conversion (cond_loc, exp1.value); |
48d94ede | 6057 | c_inhibit_evaluation_warnings += cond.value == truthvalue_true_node; |
1576dec7 | 6058 | } |
6059 | else | |
6060 | { | |
6061 | cond.value | |
45a78cc0 | 6062 | = c_objc_common_truthvalue_conversion |
8e70fb09 | 6063 | (cond_loc, default_conversion (cond.value)); |
48d94ede | 6064 | c_inhibit_evaluation_warnings += cond.value == truthvalue_false_node; |
f14c8207 | 6065 | exp1 = c_parser_expression_conv (parser); |
abc6c64f | 6066 | mark_exp_read (exp1.value); |
48d94ede | 6067 | c_inhibit_evaluation_warnings += |
6068 | ((cond.value == truthvalue_true_node) | |
6069 | - (cond.value == truthvalue_false_node)); | |
1576dec7 | 6070 | } |
d5b637fa | 6071 | |
6072 | colon_loc = c_parser_peek_token (parser)->location; | |
1576dec7 | 6073 | if (!c_parser_require (parser, CPP_COLON, "expected %<:%>")) |
6074 | { | |
48d94ede | 6075 | c_inhibit_evaluation_warnings -= cond.value == truthvalue_true_node; |
1576dec7 | 6076 | ret.value = error_mark_node; |
6077 | ret.original_code = ERROR_MARK; | |
841fdaa6 | 6078 | ret.original_type = NULL; |
1576dec7 | 6079 | return ret; |
6080 | } | |
e60a6f7b | 6081 | { |
6082 | location_t exp2_loc = c_parser_peek_token (parser)->location; | |
bc7bff74 | 6083 | exp2 = c_parser_conditional_expression (parser, NULL, NULL_TREE); |
b560fabd | 6084 | exp2 = convert_lvalue_to_rvalue (exp2_loc, exp2, true, true); |
e60a6f7b | 6085 | } |
48d94ede | 6086 | c_inhibit_evaluation_warnings -= cond.value == truthvalue_true_node; |
d5b637fa | 6087 | ret.value = build_conditional_expr (colon_loc, cond.value, |
a75b1c71 | 6088 | cond.original_code == C_MAYBE_CONST_EXPR, |
6163a125 | 6089 | exp1.value, exp1.original_type, |
6090 | exp2.value, exp2.original_type); | |
1576dec7 | 6091 | ret.original_code = ERROR_MARK; |
841fdaa6 | 6092 | if (exp1.value == error_mark_node || exp2.value == error_mark_node) |
6093 | ret.original_type = NULL; | |
6094 | else | |
6095 | { | |
6096 | tree t1, t2; | |
6097 | ||
6098 | /* If both sides are enum type, the default conversion will have | |
6099 | made the type of the result be an integer type. We want to | |
6100 | remember the enum types we started with. */ | |
6101 | t1 = exp1.original_type ? exp1.original_type : TREE_TYPE (exp1.value); | |
6102 | t2 = exp2.original_type ? exp2.original_type : TREE_TYPE (exp2.value); | |
6103 | ret.original_type = ((t1 != error_mark_node | |
6104 | && t2 != error_mark_node | |
6105 | && (TYPE_MAIN_VARIANT (t1) | |
6106 | == TYPE_MAIN_VARIANT (t2))) | |
6107 | ? t1 | |
6108 | : NULL); | |
6109 | } | |
1576dec7 | 6110 | return ret; |
6111 | } | |
6112 | ||
6113 | /* Parse a binary expression; that is, a logical-OR-expression (C90 | |
6114 | 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is | |
6115 | an Objective-C message expression which is the primary-expression | |
bc7bff74 | 6116 | starting the expression as an initializer. |
6117 | ||
6118 | OMP_ATOMIC_LHS is NULL, unless parsing OpenMP #pragma omp atomic, | |
6119 | when it should be the unfolded lhs. In a valid OpenMP source, | |
6120 | one of the operands of the toplevel binary expression must be equal | |
6121 | to it. In that case, just return a build2 created binary operation | |
6122 | rather than result of parser_build_binary_op. | |
1576dec7 | 6123 | |
6124 | multiplicative-expression: | |
6125 | cast-expression | |
6126 | multiplicative-expression * cast-expression | |
6127 | multiplicative-expression / cast-expression | |
6128 | multiplicative-expression % cast-expression | |
6129 | ||
6130 | additive-expression: | |
6131 | multiplicative-expression | |
6132 | additive-expression + multiplicative-expression | |
6133 | additive-expression - multiplicative-expression | |
6134 | ||
6135 | shift-expression: | |
6136 | additive-expression | |
6137 | shift-expression << additive-expression | |
6138 | shift-expression >> additive-expression | |
6139 | ||
6140 | relational-expression: | |
6141 | shift-expression | |
6142 | relational-expression < shift-expression | |
6143 | relational-expression > shift-expression | |
6144 | relational-expression <= shift-expression | |
6145 | relational-expression >= shift-expression | |
6146 | ||
6147 | equality-expression: | |
6148 | relational-expression | |
6149 | equality-expression == relational-expression | |
6150 | equality-expression != relational-expression | |
6151 | ||
6152 | AND-expression: | |
6153 | equality-expression | |
6154 | AND-expression & equality-expression | |
6155 | ||
6156 | exclusive-OR-expression: | |
6157 | AND-expression | |
6158 | exclusive-OR-expression ^ AND-expression | |
6159 | ||
6160 | inclusive-OR-expression: | |
6161 | exclusive-OR-expression | |
6162 | inclusive-OR-expression | exclusive-OR-expression | |
6163 | ||
6164 | logical-AND-expression: | |
6165 | inclusive-OR-expression | |
6166 | logical-AND-expression && inclusive-OR-expression | |
6167 | ||
6168 | logical-OR-expression: | |
6169 | logical-AND-expression | |
6170 | logical-OR-expression || logical-AND-expression | |
6171 | */ | |
6172 | ||
6173 | static struct c_expr | |
2169f33b | 6174 | c_parser_binary_expression (c_parser *parser, struct c_expr *after, |
bc7bff74 | 6175 | tree omp_atomic_lhs) |
1576dec7 | 6176 | { |
6177 | /* A binary expression is parsed using operator-precedence parsing, | |
6178 | with the operands being cast expressions. All the binary | |
6179 | operators are left-associative. Thus a binary expression is of | |
6180 | form: | |
6181 | ||
6182 | E0 op1 E1 op2 E2 ... | |
6183 | ||
6184 | which we represent on a stack. On the stack, the precedence | |
6185 | levels are strictly increasing. When a new operator is | |
6186 | encountered of higher precedence than that at the top of the | |
6187 | stack, it is pushed; its LHS is the top expression, and its RHS | |
6188 | is everything parsed until it is popped. When a new operator is | |
6189 | encountered with precedence less than or equal to that at the top | |
6190 | of the stack, triples E[i-1] op[i] E[i] are popped and replaced | |
6191 | by the result of the operation until the operator at the top of | |
6192 | the stack has lower precedence than the new operator or there is | |
6193 | only one element on the stack; then the top expression is the LHS | |
6194 | of the new operator. In the case of logical AND and OR | |
48d94ede | 6195 | expressions, we also need to adjust c_inhibit_evaluation_warnings |
6196 | as appropriate when the operators are pushed and popped. */ | |
1576dec7 | 6197 | |
1576dec7 | 6198 | struct { |
6199 | /* The expression at this stack level. */ | |
6200 | struct c_expr expr; | |
6201 | /* The precedence of the operator on its left, PREC_NONE at the | |
6202 | bottom of the stack. */ | |
2169f33b | 6203 | enum c_parser_prec prec; |
1576dec7 | 6204 | /* The operation on its left. */ |
6205 | enum tree_code op; | |
43158006 | 6206 | /* The source location of this operation. */ |
6207 | location_t loc; | |
1576dec7 | 6208 | } stack[NUM_PRECS]; |
6209 | int sp; | |
8e70fb09 | 6210 | /* Location of the binary operator. */ |
0eaffeb7 | 6211 | location_t binary_loc = UNKNOWN_LOCATION; /* Quiet warning. */ |
1576dec7 | 6212 | #define POP \ |
6213 | do { \ | |
6214 | switch (stack[sp].op) \ | |
6215 | { \ | |
6216 | case TRUTH_ANDIF_EXPR: \ | |
48d94ede | 6217 | c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \ |
6218 | == truthvalue_false_node); \ | |
1576dec7 | 6219 | break; \ |
6220 | case TRUTH_ORIF_EXPR: \ | |
48d94ede | 6221 | c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \ |
6222 | == truthvalue_true_node); \ | |
1576dec7 | 6223 | break; \ |
6224 | default: \ | |
6225 | break; \ | |
6226 | } \ | |
e78cf9a7 | 6227 | stack[sp - 1].expr \ |
b560fabd | 6228 | = convert_lvalue_to_rvalue (stack[sp - 1].loc, \ |
6229 | stack[sp - 1].expr, true, true); \ | |
e78cf9a7 | 6230 | stack[sp].expr \ |
b560fabd | 6231 | = convert_lvalue_to_rvalue (stack[sp].loc, \ |
6232 | stack[sp].expr, true, true); \ | |
bc7bff74 | 6233 | if (__builtin_expect (omp_atomic_lhs != NULL_TREE, 0) && sp == 1 \ |
6234 | && c_parser_peek_token (parser)->type == CPP_SEMICOLON \ | |
6235 | && ((1 << stack[sp].prec) \ | |
35ff54b5 | 6236 | & ((1 << PREC_BITOR) | (1 << PREC_BITXOR) | (1 << PREC_BITAND) \ |
6237 | | (1 << PREC_SHIFT) | (1 << PREC_ADD) | (1 << PREC_MULT))) \ | |
bc7bff74 | 6238 | && stack[sp].op != TRUNC_MOD_EXPR \ |
6239 | && stack[0].expr.value != error_mark_node \ | |
6240 | && stack[1].expr.value != error_mark_node \ | |
6241 | && (c_tree_equal (stack[0].expr.value, omp_atomic_lhs) \ | |
6242 | || c_tree_equal (stack[1].expr.value, omp_atomic_lhs))) \ | |
6243 | stack[0].expr.value \ | |
6244 | = build2 (stack[1].op, TREE_TYPE (stack[0].expr.value), \ | |
6245 | stack[0].expr.value, stack[1].expr.value); \ | |
6246 | else \ | |
6247 | stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc, \ | |
6248 | stack[sp].op, \ | |
6249 | stack[sp - 1].expr, \ | |
6250 | stack[sp].expr); \ | |
1576dec7 | 6251 | sp--; \ |
6252 | } while (0) | |
6253 | gcc_assert (!after || c_dialect_objc ()); | |
43158006 | 6254 | stack[0].loc = c_parser_peek_token (parser)->location; |
1576dec7 | 6255 | stack[0].expr = c_parser_cast_expression (parser, after); |
bc7bff74 | 6256 | stack[0].prec = PREC_NONE; |
1576dec7 | 6257 | sp = 0; |
6258 | while (true) | |
6259 | { | |
2169f33b | 6260 | enum c_parser_prec oprec; |
1576dec7 | 6261 | enum tree_code ocode; |
6262 | if (parser->error) | |
6263 | goto out; | |
6264 | switch (c_parser_peek_token (parser)->type) | |
6265 | { | |
6266 | case CPP_MULT: | |
6267 | oprec = PREC_MULT; | |
6268 | ocode = MULT_EXPR; | |
6269 | break; | |
6270 | case CPP_DIV: | |
6271 | oprec = PREC_MULT; | |
6272 | ocode = TRUNC_DIV_EXPR; | |
6273 | break; | |
6274 | case CPP_MOD: | |
6275 | oprec = PREC_MULT; | |
6276 | ocode = TRUNC_MOD_EXPR; | |
6277 | break; | |
6278 | case CPP_PLUS: | |
6279 | oprec = PREC_ADD; | |
6280 | ocode = PLUS_EXPR; | |
6281 | break; | |
6282 | case CPP_MINUS: | |
6283 | oprec = PREC_ADD; | |
6284 | ocode = MINUS_EXPR; | |
6285 | break; | |
6286 | case CPP_LSHIFT: | |
6287 | oprec = PREC_SHIFT; | |
6288 | ocode = LSHIFT_EXPR; | |
6289 | break; | |
6290 | case CPP_RSHIFT: | |
6291 | oprec = PREC_SHIFT; | |
6292 | ocode = RSHIFT_EXPR; | |
6293 | break; | |
6294 | case CPP_LESS: | |
6295 | oprec = PREC_REL; | |
6296 | ocode = LT_EXPR; | |
6297 | break; | |
6298 | case CPP_GREATER: | |
6299 | oprec = PREC_REL; | |
6300 | ocode = GT_EXPR; | |
6301 | break; | |
6302 | case CPP_LESS_EQ: | |
6303 | oprec = PREC_REL; | |
6304 | ocode = LE_EXPR; | |
6305 | break; | |
6306 | case CPP_GREATER_EQ: | |
6307 | oprec = PREC_REL; | |
6308 | ocode = GE_EXPR; | |
6309 | break; | |
6310 | case CPP_EQ_EQ: | |
6311 | oprec = PREC_EQ; | |
6312 | ocode = EQ_EXPR; | |
6313 | break; | |
6314 | case CPP_NOT_EQ: | |
6315 | oprec = PREC_EQ; | |
6316 | ocode = NE_EXPR; | |
6317 | break; | |
6318 | case CPP_AND: | |
6319 | oprec = PREC_BITAND; | |
6320 | ocode = BIT_AND_EXPR; | |
6321 | break; | |
6322 | case CPP_XOR: | |
6323 | oprec = PREC_BITXOR; | |
6324 | ocode = BIT_XOR_EXPR; | |
6325 | break; | |
6326 | case CPP_OR: | |
6327 | oprec = PREC_BITOR; | |
6328 | ocode = BIT_IOR_EXPR; | |
6329 | break; | |
6330 | case CPP_AND_AND: | |
6331 | oprec = PREC_LOGAND; | |
6332 | ocode = TRUTH_ANDIF_EXPR; | |
6333 | break; | |
6334 | case CPP_OR_OR: | |
6335 | oprec = PREC_LOGOR; | |
6336 | ocode = TRUTH_ORIF_EXPR; | |
6337 | break; | |
6338 | default: | |
6339 | /* Not a binary operator, so end of the binary | |
6340 | expression. */ | |
6341 | goto out; | |
6342 | } | |
8e70fb09 | 6343 | binary_loc = c_parser_peek_token (parser)->location; |
1576dec7 | 6344 | while (oprec <= stack[sp].prec) |
bc7bff74 | 6345 | POP; |
2169f33b | 6346 | c_parser_consume_token (parser); |
1576dec7 | 6347 | switch (ocode) |
6348 | { | |
6349 | case TRUTH_ANDIF_EXPR: | |
e78cf9a7 | 6350 | stack[sp].expr |
b560fabd | 6351 | = convert_lvalue_to_rvalue (stack[sp].loc, |
6352 | stack[sp].expr, true, true); | |
45a78cc0 | 6353 | stack[sp].expr.value = c_objc_common_truthvalue_conversion |
43158006 | 6354 | (stack[sp].loc, default_conversion (stack[sp].expr.value)); |
48d94ede | 6355 | c_inhibit_evaluation_warnings += (stack[sp].expr.value |
6356 | == truthvalue_false_node); | |
1576dec7 | 6357 | break; |
6358 | case TRUTH_ORIF_EXPR: | |
e78cf9a7 | 6359 | stack[sp].expr |
b560fabd | 6360 | = convert_lvalue_to_rvalue (stack[sp].loc, |
6361 | stack[sp].expr, true, true); | |
45a78cc0 | 6362 | stack[sp].expr.value = c_objc_common_truthvalue_conversion |
43158006 | 6363 | (stack[sp].loc, default_conversion (stack[sp].expr.value)); |
48d94ede | 6364 | c_inhibit_evaluation_warnings += (stack[sp].expr.value |
6365 | == truthvalue_true_node); | |
1576dec7 | 6366 | break; |
6367 | default: | |
6368 | break; | |
6369 | } | |
6370 | sp++; | |
43158006 | 6371 | stack[sp].loc = binary_loc; |
1576dec7 | 6372 | stack[sp].expr = c_parser_cast_expression (parser, NULL); |
6373 | stack[sp].prec = oprec; | |
6374 | stack[sp].op = ocode; | |
e60a6f7b | 6375 | stack[sp].loc = binary_loc; |
1576dec7 | 6376 | } |
6377 | out: | |
6378 | while (sp > 0) | |
6379 | POP; | |
6380 | return stack[0].expr; | |
6381 | #undef POP | |
6382 | } | |
6383 | ||
6384 | /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not | |
6385 | NULL then it is an Objective-C message expression which is the | |
6386 | primary-expression starting the expression as an initializer. | |
6387 | ||
6388 | cast-expression: | |
6389 | unary-expression | |
6390 | ( type-name ) unary-expression | |
6391 | */ | |
6392 | ||
6393 | static struct c_expr | |
6394 | c_parser_cast_expression (c_parser *parser, struct c_expr *after) | |
6395 | { | |
e60a6f7b | 6396 | location_t cast_loc = c_parser_peek_token (parser)->location; |
1576dec7 | 6397 | gcc_assert (!after || c_dialect_objc ()); |
6398 | if (after) | |
e60a6f7b | 6399 | return c_parser_postfix_expression_after_primary (parser, |
6400 | cast_loc, *after); | |
1576dec7 | 6401 | /* If the expression begins with a parenthesized type name, it may |
6402 | be either a cast or a compound literal; we need to see whether | |
6403 | the next character is '{' to tell the difference. If not, it is | |
26ee9e7a | 6404 | an unary expression. Full detection of unknown typenames here |
6405 | would require a 3-token lookahead. */ | |
1576dec7 | 6406 | if (c_parser_next_token_is (parser, CPP_OPEN_PAREN) |
6407 | && c_token_starts_typename (c_parser_peek_2nd_token (parser))) | |
6408 | { | |
6409 | struct c_type_name *type_name; | |
6410 | struct c_expr ret; | |
e78cf9a7 | 6411 | struct c_expr expr; |
1576dec7 | 6412 | c_parser_consume_token (parser); |
6413 | type_name = c_parser_type_name (parser); | |
6414 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
6415 | if (type_name == NULL) | |
6416 | { | |
6417 | ret.value = error_mark_node; | |
6418 | ret.original_code = ERROR_MARK; | |
841fdaa6 | 6419 | ret.original_type = NULL; |
1576dec7 | 6420 | return ret; |
6421 | } | |
f6e59711 | 6422 | |
6423 | /* Save casted types in the function's used types hash table. */ | |
35df6eb4 | 6424 | used_types_insert (type_name->specs->type); |
f6e59711 | 6425 | |
1576dec7 | 6426 | if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) |
0b09525f | 6427 | return c_parser_postfix_expression_after_paren_type (parser, type_name, |
e60a6f7b | 6428 | cast_loc); |
6429 | { | |
6430 | location_t expr_loc = c_parser_peek_token (parser)->location; | |
6431 | expr = c_parser_cast_expression (parser, NULL); | |
b560fabd | 6432 | expr = convert_lvalue_to_rvalue (expr_loc, expr, true, true); |
e60a6f7b | 6433 | } |
6434 | ret.value = c_cast_expr (cast_loc, type_name, expr.value); | |
1576dec7 | 6435 | ret.original_code = ERROR_MARK; |
841fdaa6 | 6436 | ret.original_type = NULL; |
1576dec7 | 6437 | return ret; |
6438 | } | |
6439 | else | |
6440 | return c_parser_unary_expression (parser); | |
6441 | } | |
6442 | ||
6443 | /* Parse an unary expression (C90 6.3.3, C99 6.5.3). | |
6444 | ||
6445 | unary-expression: | |
6446 | postfix-expression | |
6447 | ++ unary-expression | |
6448 | -- unary-expression | |
6449 | unary-operator cast-expression | |
6450 | sizeof unary-expression | |
6451 | sizeof ( type-name ) | |
6452 | ||
6453 | unary-operator: one of | |
6454 | & * + - ~ ! | |
6455 | ||
6456 | GNU extensions: | |
6457 | ||
6458 | unary-expression: | |
6459 | __alignof__ unary-expression | |
6460 | __alignof__ ( type-name ) | |
6461 | && identifier | |
6462 | ||
32074525 | 6463 | (C11 permits _Alignof with type names only.) |
83e25171 | 6464 | |
1576dec7 | 6465 | unary-operator: one of |
6466 | __extension__ __real__ __imag__ | |
6467 | ||
4c0315d0 | 6468 | Transactional Memory: |
6469 | ||
6470 | unary-expression: | |
6471 | transaction-expression | |
6472 | ||
1576dec7 | 6473 | In addition, the GNU syntax treats ++ and -- as unary operators, so |
6474 | they may be applied to cast expressions with errors for non-lvalues | |
6475 | given later. */ | |
6476 | ||
6477 | static struct c_expr | |
6478 | c_parser_unary_expression (c_parser *parser) | |
6479 | { | |
6480 | int ext; | |
f14c8207 | 6481 | struct c_expr ret, op; |
e60a6f7b | 6482 | location_t op_loc = c_parser_peek_token (parser)->location; |
6483 | location_t exp_loc; | |
841fdaa6 | 6484 | ret.original_code = ERROR_MARK; |
6485 | ret.original_type = NULL; | |
1576dec7 | 6486 | switch (c_parser_peek_token (parser)->type) |
6487 | { | |
6488 | case CPP_PLUS_PLUS: | |
6489 | c_parser_consume_token (parser); | |
e60a6f7b | 6490 | exp_loc = c_parser_peek_token (parser)->location; |
f14c8207 | 6491 | op = c_parser_cast_expression (parser, NULL); |
3c6d4197 | 6492 | |
6493 | /* If there is array notations in op, we expand them. */ | |
a89e6c15 | 6494 | if (flag_cilkplus && TREE_CODE (op.value) == ARRAY_NOTATION_REF) |
3c6d4197 | 6495 | return fix_array_notation_expr (exp_loc, PREINCREMENT_EXPR, op); |
6496 | else | |
6497 | { | |
6498 | op = default_function_array_read_conversion (exp_loc, op); | |
6499 | return parser_build_unary_op (op_loc, PREINCREMENT_EXPR, op); | |
6500 | } | |
1576dec7 | 6501 | case CPP_MINUS_MINUS: |
6502 | c_parser_consume_token (parser); | |
e60a6f7b | 6503 | exp_loc = c_parser_peek_token (parser)->location; |
f14c8207 | 6504 | op = c_parser_cast_expression (parser, NULL); |
3c6d4197 | 6505 | |
6506 | /* If there is array notations in op, we expand them. */ | |
a89e6c15 | 6507 | if (flag_cilkplus && TREE_CODE (op.value) == ARRAY_NOTATION_REF) |
3c6d4197 | 6508 | return fix_array_notation_expr (exp_loc, PREDECREMENT_EXPR, op); |
6509 | else | |
6510 | { | |
6511 | op = default_function_array_read_conversion (exp_loc, op); | |
6512 | return parser_build_unary_op (op_loc, PREDECREMENT_EXPR, op); | |
6513 | } | |
1576dec7 | 6514 | case CPP_AND: |
6515 | c_parser_consume_token (parser); | |
abc6c64f | 6516 | op = c_parser_cast_expression (parser, NULL); |
6517 | mark_exp_read (op.value); | |
6518 | return parser_build_unary_op (op_loc, ADDR_EXPR, op); | |
1576dec7 | 6519 | case CPP_MULT: |
6520 | c_parser_consume_token (parser); | |
e60a6f7b | 6521 | exp_loc = c_parser_peek_token (parser)->location; |
f14c8207 | 6522 | op = c_parser_cast_expression (parser, NULL); |
b560fabd | 6523 | op = convert_lvalue_to_rvalue (exp_loc, op, true, true); |
f08923b3 | 6524 | ret.value = build_indirect_ref (op_loc, op.value, RO_UNARY_STAR); |
1576dec7 | 6525 | return ret; |
6526 | case CPP_PLUS: | |
3df42822 | 6527 | if (!c_dialect_objc () && !in_system_header_at (input_location)) |
e60a6f7b | 6528 | warning_at (op_loc, |
e3b80d49 | 6529 | OPT_Wtraditional, |
6530 | "traditional C rejects the unary plus operator"); | |
be9eba16 | 6531 | c_parser_consume_token (parser); |
e60a6f7b | 6532 | exp_loc = c_parser_peek_token (parser)->location; |
f14c8207 | 6533 | op = c_parser_cast_expression (parser, NULL); |
b560fabd | 6534 | op = convert_lvalue_to_rvalue (exp_loc, op, true, true); |
e60a6f7b | 6535 | return parser_build_unary_op (op_loc, CONVERT_EXPR, op); |
1576dec7 | 6536 | case CPP_MINUS: |
6537 | c_parser_consume_token (parser); | |
e60a6f7b | 6538 | exp_loc = c_parser_peek_token (parser)->location; |
f14c8207 | 6539 | op = c_parser_cast_expression (parser, NULL); |
b560fabd | 6540 | op = convert_lvalue_to_rvalue (exp_loc, op, true, true); |
e60a6f7b | 6541 | return parser_build_unary_op (op_loc, NEGATE_EXPR, op); |
1576dec7 | 6542 | case CPP_COMPL: |
6543 | c_parser_consume_token (parser); | |
e60a6f7b | 6544 | exp_loc = c_parser_peek_token (parser)->location; |
f14c8207 | 6545 | op = c_parser_cast_expression (parser, NULL); |
b560fabd | 6546 | op = convert_lvalue_to_rvalue (exp_loc, op, true, true); |
e60a6f7b | 6547 | return parser_build_unary_op (op_loc, BIT_NOT_EXPR, op); |
1576dec7 | 6548 | case CPP_NOT: |
6549 | c_parser_consume_token (parser); | |
e60a6f7b | 6550 | exp_loc = c_parser_peek_token (parser)->location; |
f14c8207 | 6551 | op = c_parser_cast_expression (parser, NULL); |
b560fabd | 6552 | op = convert_lvalue_to_rvalue (exp_loc, op, true, true); |
e60a6f7b | 6553 | return parser_build_unary_op (op_loc, TRUTH_NOT_EXPR, op); |
1576dec7 | 6554 | case CPP_AND_AND: |
6555 | /* Refer to the address of a label as a pointer. */ | |
6556 | c_parser_consume_token (parser); | |
6557 | if (c_parser_next_token_is (parser, CPP_NAME)) | |
6558 | { | |
6559 | ret.value = finish_label_address_expr | |
e60a6f7b | 6560 | (c_parser_peek_token (parser)->value, op_loc); |
1576dec7 | 6561 | c_parser_consume_token (parser); |
1576dec7 | 6562 | } |
6563 | else | |
6564 | { | |
6565 | c_parser_error (parser, "expected identifier"); | |
6566 | ret.value = error_mark_node; | |
1576dec7 | 6567 | } |
5381eb98 | 6568 | return ret; |
1576dec7 | 6569 | case CPP_KEYWORD: |
6570 | switch (c_parser_peek_token (parser)->keyword) | |
6571 | { | |
6572 | case RID_SIZEOF: | |
6573 | return c_parser_sizeof_expression (parser); | |
6574 | case RID_ALIGNOF: | |
6575 | return c_parser_alignof_expression (parser); | |
6576 | case RID_EXTENSION: | |
6577 | c_parser_consume_token (parser); | |
6578 | ext = disable_extension_diagnostics (); | |
6579 | ret = c_parser_cast_expression (parser, NULL); | |
6580 | restore_extension_diagnostics (ext); | |
6581 | return ret; | |
6582 | case RID_REALPART: | |
6583 | c_parser_consume_token (parser); | |
e60a6f7b | 6584 | exp_loc = c_parser_peek_token (parser)->location; |
f14c8207 | 6585 | op = c_parser_cast_expression (parser, NULL); |
e60a6f7b | 6586 | op = default_function_array_conversion (exp_loc, op); |
6587 | return parser_build_unary_op (op_loc, REALPART_EXPR, op); | |
1576dec7 | 6588 | case RID_IMAGPART: |
6589 | c_parser_consume_token (parser); | |
e60a6f7b | 6590 | exp_loc = c_parser_peek_token (parser)->location; |
f14c8207 | 6591 | op = c_parser_cast_expression (parser, NULL); |
e60a6f7b | 6592 | op = default_function_array_conversion (exp_loc, op); |
6593 | return parser_build_unary_op (op_loc, IMAGPART_EXPR, op); | |
4c0315d0 | 6594 | case RID_TRANSACTION_ATOMIC: |
6595 | case RID_TRANSACTION_RELAXED: | |
6596 | return c_parser_transaction_expression (parser, | |
6597 | c_parser_peek_token (parser)->keyword); | |
1576dec7 | 6598 | default: |
6599 | return c_parser_postfix_expression (parser); | |
6600 | } | |
6601 | default: | |
6602 | return c_parser_postfix_expression (parser); | |
6603 | } | |
6604 | } | |
6605 | ||
6606 | /* Parse a sizeof expression. */ | |
6607 | ||
6608 | static struct c_expr | |
6609 | c_parser_sizeof_expression (c_parser *parser) | |
6610 | { | |
6611 | struct c_expr expr; | |
be9eba16 | 6612 | location_t expr_loc; |
1576dec7 | 6613 | gcc_assert (c_parser_next_token_is_keyword (parser, RID_SIZEOF)); |
6614 | c_parser_consume_token (parser); | |
48d94ede | 6615 | c_inhibit_evaluation_warnings++; |
1576dec7 | 6616 | in_sizeof++; |
6617 | if (c_parser_next_token_is (parser, CPP_OPEN_PAREN) | |
6618 | && c_token_starts_typename (c_parser_peek_2nd_token (parser))) | |
6619 | { | |
6620 | /* Either sizeof ( type-name ) or sizeof unary-expression | |
6621 | starting with a compound literal. */ | |
6622 | struct c_type_name *type_name; | |
6623 | c_parser_consume_token (parser); | |
be9eba16 | 6624 | expr_loc = c_parser_peek_token (parser)->location; |
1576dec7 | 6625 | type_name = c_parser_type_name (parser); |
6626 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
6627 | if (type_name == NULL) | |
6628 | { | |
6629 | struct c_expr ret; | |
48d94ede | 6630 | c_inhibit_evaluation_warnings--; |
1576dec7 | 6631 | in_sizeof--; |
6632 | ret.value = error_mark_node; | |
6633 | ret.original_code = ERROR_MARK; | |
841fdaa6 | 6634 | ret.original_type = NULL; |
1576dec7 | 6635 | return ret; |
6636 | } | |
6637 | if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) | |
6638 | { | |
d44f2f7c | 6639 | expr = c_parser_postfix_expression_after_paren_type (parser, |
6640 | type_name, | |
6641 | expr_loc); | |
6642 | goto sizeof_expr; | |
1576dec7 | 6643 | } |
d44f2f7c | 6644 | /* sizeof ( type-name ). */ |
6645 | c_inhibit_evaluation_warnings--; | |
6646 | in_sizeof--; | |
6647 | return c_expr_sizeof_type (expr_loc, type_name); | |
1576dec7 | 6648 | } |
6649 | else | |
6650 | { | |
be9eba16 | 6651 | expr_loc = c_parser_peek_token (parser)->location; |
1576dec7 | 6652 | expr = c_parser_unary_expression (parser); |
d44f2f7c | 6653 | sizeof_expr: |
6654 | c_inhibit_evaluation_warnings--; | |
6655 | in_sizeof--; | |
6656 | mark_exp_read (expr.value); | |
6657 | if (TREE_CODE (expr.value) == COMPONENT_REF | |
6658 | && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1))) | |
6659 | error_at (expr_loc, "%<sizeof%> applied to a bit-field"); | |
6660 | return c_expr_sizeof_expr (expr_loc, expr); | |
1576dec7 | 6661 | } |
6662 | } | |
6663 | ||
6664 | /* Parse an alignof expression. */ | |
6665 | ||
6666 | static struct c_expr | |
6667 | c_parser_alignof_expression (c_parser *parser) | |
6668 | { | |
6669 | struct c_expr expr; | |
e60a6f7b | 6670 | location_t loc = c_parser_peek_token (parser)->location; |
83e25171 | 6671 | tree alignof_spelling = c_parser_peek_token (parser)->value; |
1576dec7 | 6672 | gcc_assert (c_parser_next_token_is_keyword (parser, RID_ALIGNOF)); |
a179a7dc | 6673 | bool is_c11_alignof = strcmp (IDENTIFIER_POINTER (alignof_spelling), |
6674 | "_Alignof") == 0; | |
83e25171 | 6675 | /* A diagnostic is not required for the use of this identifier in |
32074525 | 6676 | the implementation namespace; only diagnose it for the C11 |
83e25171 | 6677 | spelling because of existing code using the other spellings. */ |
508ea33a | 6678 | if (is_c11_alignof) |
83e25171 | 6679 | { |
6680 | if (flag_isoc99) | |
508ea33a | 6681 | pedwarn_c99 (loc, OPT_Wpedantic, "ISO C99 does not support %qE", |
6682 | alignof_spelling); | |
83e25171 | 6683 | else |
508ea33a | 6684 | pedwarn_c99 (loc, OPT_Wpedantic, "ISO C90 does not support %qE", |
6685 | alignof_spelling); | |
83e25171 | 6686 | } |
1576dec7 | 6687 | c_parser_consume_token (parser); |
48d94ede | 6688 | c_inhibit_evaluation_warnings++; |
1576dec7 | 6689 | in_alignof++; |
6690 | if (c_parser_next_token_is (parser, CPP_OPEN_PAREN) | |
6691 | && c_token_starts_typename (c_parser_peek_2nd_token (parser))) | |
6692 | { | |
6693 | /* Either __alignof__ ( type-name ) or __alignof__ | |
6694 | unary-expression starting with a compound literal. */ | |
0b09525f | 6695 | location_t loc; |
1576dec7 | 6696 | struct c_type_name *type_name; |
6697 | struct c_expr ret; | |
6698 | c_parser_consume_token (parser); | |
0b09525f | 6699 | loc = c_parser_peek_token (parser)->location; |
1576dec7 | 6700 | type_name = c_parser_type_name (parser); |
6701 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
6702 | if (type_name == NULL) | |
6703 | { | |
6704 | struct c_expr ret; | |
48d94ede | 6705 | c_inhibit_evaluation_warnings--; |
1576dec7 | 6706 | in_alignof--; |
6707 | ret.value = error_mark_node; | |
6708 | ret.original_code = ERROR_MARK; | |
841fdaa6 | 6709 | ret.original_type = NULL; |
1576dec7 | 6710 | return ret; |
6711 | } | |
6712 | if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) | |
6713 | { | |
6714 | expr = c_parser_postfix_expression_after_paren_type (parser, | |
0b09525f | 6715 | type_name, |
6716 | loc); | |
1576dec7 | 6717 | goto alignof_expr; |
6718 | } | |
6719 | /* alignof ( type-name ). */ | |
48d94ede | 6720 | c_inhibit_evaluation_warnings--; |
1576dec7 | 6721 | in_alignof--; |
a179a7dc | 6722 | ret.value = c_sizeof_or_alignof_type (loc, groktypename (type_name, |
6723 | NULL, NULL), | |
6724 | false, is_c11_alignof, 1); | |
1576dec7 | 6725 | ret.original_code = ERROR_MARK; |
841fdaa6 | 6726 | ret.original_type = NULL; |
1576dec7 | 6727 | return ret; |
6728 | } | |
6729 | else | |
6730 | { | |
6731 | struct c_expr ret; | |
6732 | expr = c_parser_unary_expression (parser); | |
6733 | alignof_expr: | |
abc6c64f | 6734 | mark_exp_read (expr.value); |
48d94ede | 6735 | c_inhibit_evaluation_warnings--; |
1576dec7 | 6736 | in_alignof--; |
29438999 | 6737 | pedwarn (loc, OPT_Wpedantic, "ISO C does not allow %<%E (expression)%>", |
83e25171 | 6738 | alignof_spelling); |
e60a6f7b | 6739 | ret.value = c_alignof_expr (loc, expr.value); |
1576dec7 | 6740 | ret.original_code = ERROR_MARK; |
841fdaa6 | 6741 | ret.original_type = NULL; |
1576dec7 | 6742 | return ret; |
6743 | } | |
6744 | } | |
6745 | ||
6cf89e04 | 6746 | /* Helper function to read arguments of builtins which are interfaces |
f4803722 | 6747 | for the middle-end nodes like COMPLEX_EXPR, VEC_PERM_EXPR and |
6cf89e04 | 6748 | others. The name of the builtin is passed using BNAME parameter. |
6749 | Function returns true if there were no errors while parsing and | |
a11dda8e | 6750 | stores the arguments in CEXPR_LIST. */ |
6cf89e04 | 6751 | static bool |
6752 | c_parser_get_builtin_args (c_parser *parser, const char *bname, | |
0b049e15 | 6753 | vec<c_expr_t, va_gc> **ret_cexpr_list, |
6754 | bool choose_expr_p) | |
6cf89e04 | 6755 | { |
6756 | location_t loc = c_parser_peek_token (parser)->location; | |
f1f41a6c | 6757 | vec<c_expr_t, va_gc> *cexpr_list; |
a11dda8e | 6758 | c_expr_t expr; |
0b049e15 | 6759 | bool saved_force_folding_builtin_constant_p; |
6cf89e04 | 6760 | |
a11dda8e | 6761 | *ret_cexpr_list = NULL; |
6cf89e04 | 6762 | if (c_parser_next_token_is_not (parser, CPP_OPEN_PAREN)) |
6763 | { | |
6764 | error_at (loc, "cannot take address of %qs", bname); | |
6765 | return false; | |
6766 | } | |
6767 | ||
6768 | c_parser_consume_token (parser); | |
6769 | ||
6770 | if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) | |
6771 | { | |
6772 | c_parser_consume_token (parser); | |
6773 | return true; | |
6774 | } | |
a11dda8e | 6775 | |
0b049e15 | 6776 | saved_force_folding_builtin_constant_p |
6777 | = force_folding_builtin_constant_p; | |
6778 | force_folding_builtin_constant_p |= choose_expr_p; | |
a11dda8e | 6779 | expr = c_parser_expr_no_commas (parser, NULL); |
0b049e15 | 6780 | force_folding_builtin_constant_p |
6781 | = saved_force_folding_builtin_constant_p; | |
f1f41a6c | 6782 | vec_alloc (cexpr_list, 1); |
825cd6ef | 6783 | vec_safe_push (cexpr_list, expr); |
a11dda8e | 6784 | while (c_parser_next_token_is (parser, CPP_COMMA)) |
6785 | { | |
6786 | c_parser_consume_token (parser); | |
6787 | expr = c_parser_expr_no_commas (parser, NULL); | |
825cd6ef | 6788 | vec_safe_push (cexpr_list, expr); |
a11dda8e | 6789 | } |
6cf89e04 | 6790 | |
6791 | if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>")) | |
6792 | return false; | |
6793 | ||
a11dda8e | 6794 | *ret_cexpr_list = cexpr_list; |
6cf89e04 | 6795 | return true; |
6796 | } | |
6797 | ||
7aa04c8d | 6798 | /* This represents a single generic-association. */ |
6799 | ||
6800 | struct c_generic_association | |
6801 | { | |
6802 | /* The location of the starting token of the type. */ | |
6803 | location_t type_location; | |
e76163a9 | 6804 | /* The association's type, or NULL_TREE for 'default'. */ |
7aa04c8d | 6805 | tree type; |
6806 | /* The association's expression. */ | |
6807 | struct c_expr expression; | |
6808 | }; | |
6809 | ||
6810 | /* Parse a generic-selection. (C11 6.5.1.1). | |
6811 | ||
6812 | generic-selection: | |
6813 | _Generic ( assignment-expression , generic-assoc-list ) | |
6814 | ||
6815 | generic-assoc-list: | |
6816 | generic-association | |
6817 | generic-assoc-list , generic-association | |
6818 | ||
6819 | generic-association: | |
6820 | type-name : assignment-expression | |
6821 | default : assignment-expression | |
6822 | */ | |
6823 | ||
6824 | static struct c_expr | |
6825 | c_parser_generic_selection (c_parser *parser) | |
6826 | { | |
6827 | vec<c_generic_association> associations = vNULL; | |
6828 | struct c_expr selector, error_expr; | |
6829 | tree selector_type; | |
6830 | struct c_generic_association matched_assoc; | |
6831 | bool match_found = false; | |
6832 | location_t generic_loc, selector_loc; | |
6833 | ||
6834 | error_expr.original_code = ERROR_MARK; | |
6835 | error_expr.original_type = NULL; | |
6836 | error_expr.value = error_mark_node; | |
6837 | matched_assoc.type_location = UNKNOWN_LOCATION; | |
6838 | matched_assoc.type = NULL_TREE; | |
6839 | matched_assoc.expression = error_expr; | |
6840 | ||
6841 | gcc_assert (c_parser_next_token_is_keyword (parser, RID_GENERIC)); | |
6842 | generic_loc = c_parser_peek_token (parser)->location; | |
6843 | c_parser_consume_token (parser); | |
508ea33a | 6844 | if (flag_isoc99) |
6845 | pedwarn_c99 (generic_loc, OPT_Wpedantic, | |
7aa04c8d | 6846 | "ISO C99 does not support %<_Generic%>"); |
508ea33a | 6847 | else |
6848 | pedwarn_c99 (generic_loc, OPT_Wpedantic, | |
7aa04c8d | 6849 | "ISO C90 does not support %<_Generic%>"); |
7aa04c8d | 6850 | |
6851 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
6852 | return error_expr; | |
6853 | ||
6854 | c_inhibit_evaluation_warnings++; | |
6855 | selector_loc = c_parser_peek_token (parser)->location; | |
6856 | selector = c_parser_expr_no_commas (parser, NULL); | |
6857 | selector = default_function_array_conversion (selector_loc, selector); | |
6858 | c_inhibit_evaluation_warnings--; | |
6859 | ||
6860 | if (selector.value == error_mark_node) | |
6861 | { | |
6862 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); | |
6863 | return selector; | |
6864 | } | |
6865 | selector_type = TREE_TYPE (selector.value); | |
6866 | /* In ISO C terms, rvalues (including the controlling expression of | |
6867 | _Generic) do not have qualified types. */ | |
6868 | if (TREE_CODE (selector_type) != ARRAY_TYPE) | |
6869 | selector_type = TYPE_MAIN_VARIANT (selector_type); | |
6870 | /* In ISO C terms, _Noreturn is not part of the type of expressions | |
6871 | such as &abort, but in GCC it is represented internally as a type | |
6872 | qualifier. */ | |
6873 | if (FUNCTION_POINTER_TYPE_P (selector_type) | |
6874 | && TYPE_QUALS (TREE_TYPE (selector_type)) != TYPE_UNQUALIFIED) | |
6875 | selector_type | |
6876 | = build_pointer_type (TYPE_MAIN_VARIANT (TREE_TYPE (selector_type))); | |
6877 | ||
6878 | if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>")) | |
6879 | { | |
6880 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); | |
6881 | return error_expr; | |
6882 | } | |
6883 | ||
6884 | while (1) | |
6885 | { | |
6886 | struct c_generic_association assoc, *iter; | |
6887 | unsigned int ix; | |
6888 | c_token *token = c_parser_peek_token (parser); | |
6889 | ||
6890 | assoc.type_location = token->location; | |
6891 | if (token->type == CPP_KEYWORD && token->keyword == RID_DEFAULT) | |
6892 | { | |
6893 | c_parser_consume_token (parser); | |
6894 | assoc.type = NULL_TREE; | |
6895 | } | |
6896 | else | |
6897 | { | |
6898 | struct c_type_name *type_name; | |
6899 | ||
6900 | type_name = c_parser_type_name (parser); | |
6901 | if (type_name == NULL) | |
6902 | { | |
6903 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); | |
6904 | goto error_exit; | |
6905 | } | |
6906 | assoc.type = groktypename (type_name, NULL, NULL); | |
6907 | if (assoc.type == error_mark_node) | |
6908 | { | |
6909 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); | |
6910 | goto error_exit; | |
6911 | } | |
6912 | ||
6913 | if (TREE_CODE (assoc.type) == FUNCTION_TYPE) | |
6914 | error_at (assoc.type_location, | |
6915 | "%<_Generic%> association has function type"); | |
6916 | else if (!COMPLETE_TYPE_P (assoc.type)) | |
6917 | error_at (assoc.type_location, | |
6918 | "%<_Generic%> association has incomplete type"); | |
6919 | ||
6920 | if (variably_modified_type_p (assoc.type, NULL_TREE)) | |
6921 | error_at (assoc.type_location, | |
6922 | "%<_Generic%> association has " | |
6923 | "variable length type"); | |
6924 | } | |
6925 | ||
6926 | if (!c_parser_require (parser, CPP_COLON, "expected %<:%>")) | |
6927 | { | |
6928 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); | |
6929 | goto error_exit; | |
6930 | } | |
6931 | ||
6932 | assoc.expression = c_parser_expr_no_commas (parser, NULL); | |
6933 | if (assoc.expression.value == error_mark_node) | |
6934 | { | |
6935 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); | |
6936 | goto error_exit; | |
6937 | } | |
6938 | ||
6939 | for (ix = 0; associations.iterate (ix, &iter); ++ix) | |
6940 | { | |
6941 | if (assoc.type == NULL_TREE) | |
6942 | { | |
6943 | if (iter->type == NULL_TREE) | |
6944 | { | |
6945 | error_at (assoc.type_location, | |
6946 | "duplicate %<default%> case in %<_Generic%>"); | |
6947 | inform (iter->type_location, "original %<default%> is here"); | |
6948 | } | |
6949 | } | |
6950 | else if (iter->type != NULL_TREE) | |
6951 | { | |
6952 | if (comptypes (assoc.type, iter->type)) | |
6953 | { | |
6954 | error_at (assoc.type_location, | |
6955 | "%<_Generic%> specifies two compatible types"); | |
6956 | inform (iter->type_location, "compatible type is here"); | |
6957 | } | |
6958 | } | |
6959 | } | |
6960 | ||
6961 | if (assoc.type == NULL_TREE) | |
6962 | { | |
6963 | if (!match_found) | |
6964 | { | |
6965 | matched_assoc = assoc; | |
6966 | match_found = true; | |
6967 | } | |
6968 | } | |
6969 | else if (comptypes (assoc.type, selector_type)) | |
6970 | { | |
6971 | if (!match_found || matched_assoc.type == NULL_TREE) | |
6972 | { | |
6973 | matched_assoc = assoc; | |
6974 | match_found = true; | |
6975 | } | |
6976 | else | |
6977 | { | |
6978 | error_at (assoc.type_location, | |
6979 | "%<_Generic> selector matches multiple associations"); | |
6980 | inform (matched_assoc.type_location, | |
6981 | "other match is here"); | |
6982 | } | |
6983 | } | |
6984 | ||
6985 | associations.safe_push (assoc); | |
6986 | ||
6987 | if (c_parser_peek_token (parser)->type != CPP_COMMA) | |
6988 | break; | |
6989 | c_parser_consume_token (parser); | |
6990 | } | |
6991 | ||
6992 | associations.release (); | |
6993 | ||
6994 | if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>")) | |
6995 | { | |
6996 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); | |
6997 | return error_expr; | |
6998 | } | |
6999 | ||
7000 | if (!match_found) | |
7001 | { | |
7002 | error_at (selector_loc, "%<_Generic%> selector of type %qT is not " | |
7003 | "compatible with any association", | |
7004 | selector_type); | |
7005 | return error_expr; | |
7006 | } | |
7007 | ||
7008 | return matched_assoc.expression; | |
7009 | ||
7010 | error_exit: | |
7011 | associations.release (); | |
7012 | return error_expr; | |
7013 | } | |
6cf89e04 | 7014 | |
1576dec7 | 7015 | /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2). |
7016 | ||
7017 | postfix-expression: | |
7018 | primary-expression | |
7019 | postfix-expression [ expression ] | |
7020 | postfix-expression ( argument-expression-list[opt] ) | |
7021 | postfix-expression . identifier | |
7022 | postfix-expression -> identifier | |
7023 | postfix-expression ++ | |
7024 | postfix-expression -- | |
7025 | ( type-name ) { initializer-list } | |
7026 | ( type-name ) { initializer-list , } | |
7027 | ||
7028 | argument-expression-list: | |
7029 | argument-expression | |
7030 | argument-expression-list , argument-expression | |
7031 | ||
7032 | primary-expression: | |
7033 | identifier | |
7034 | constant | |
7035 | string-literal | |
7036 | ( expression ) | |
7aa04c8d | 7037 | generic-selection |
1576dec7 | 7038 | |
7039 | GNU extensions: | |
7040 | ||
7041 | primary-expression: | |
7042 | __func__ | |
7043 | (treated as a keyword in GNU C) | |
7044 | __FUNCTION__ | |
7045 | __PRETTY_FUNCTION__ | |
7046 | ( compound-statement ) | |
7047 | __builtin_va_arg ( assignment-expression , type-name ) | |
7048 | __builtin_offsetof ( type-name , offsetof-member-designator ) | |
7049 | __builtin_choose_expr ( assignment-expression , | |
7050 | assignment-expression , | |
7051 | assignment-expression ) | |
7052 | __builtin_types_compatible_p ( type-name , type-name ) | |
bff4ad11 | 7053 | __builtin_complex ( assignment-expression , assignment-expression ) |
6cf89e04 | 7054 | __builtin_shuffle ( assignment-expression , assignment-expression ) |
7055 | __builtin_shuffle ( assignment-expression , | |
7056 | assignment-expression , | |
7057 | assignment-expression, ) | |
1576dec7 | 7058 | |
7059 | offsetof-member-designator: | |
7060 | identifier | |
7061 | offsetof-member-designator . identifier | |
7062 | offsetof-member-designator [ expression ] | |
7063 | ||
7064 | Objective-C: | |
7065 | ||
7066 | primary-expression: | |
7067 | [ objc-receiver objc-message-args ] | |
7068 | @selector ( objc-selector-arg ) | |
7069 | @protocol ( identifier ) | |
7070 | @encode ( type-name ) | |
7071 | objc-string-literal | |
b0d0931f | 7072 | Classname . identifier |
1576dec7 | 7073 | */ |
7074 | ||
7075 | static struct c_expr | |
7076 | c_parser_postfix_expression (c_parser *parser) | |
7077 | { | |
6cf89e04 | 7078 | struct c_expr expr, e1; |
1576dec7 | 7079 | struct c_type_name *t1, *t2; |
e60a6f7b | 7080 | location_t loc = c_parser_peek_token (parser)->location;; |
841fdaa6 | 7081 | expr.original_code = ERROR_MARK; |
7082 | expr.original_type = NULL; | |
1576dec7 | 7083 | switch (c_parser_peek_token (parser)->type) |
7084 | { | |
7085 | case CPP_NUMBER: | |
14e882ea | 7086 | expr.value = c_parser_peek_token (parser)->value; |
14e882ea | 7087 | loc = c_parser_peek_token (parser)->location; |
7088 | c_parser_consume_token (parser); | |
7089 | if (TREE_CODE (expr.value) == FIXED_CST | |
7090 | && !targetm.fixed_point_supported_p ()) | |
7091 | { | |
7092 | error_at (loc, "fixed-point types not supported for this target"); | |
7093 | expr.value = error_mark_node; | |
7094 | } | |
7095 | break; | |
1576dec7 | 7096 | case CPP_CHAR: |
924bbf02 | 7097 | case CPP_CHAR16: |
7098 | case CPP_CHAR32: | |
1576dec7 | 7099 | case CPP_WCHAR: |
7100 | expr.value = c_parser_peek_token (parser)->value; | |
1576dec7 | 7101 | c_parser_consume_token (parser); |
7102 | break; | |
7103 | case CPP_STRING: | |
924bbf02 | 7104 | case CPP_STRING16: |
7105 | case CPP_STRING32: | |
1576dec7 | 7106 | case CPP_WSTRING: |
538ba11a | 7107 | case CPP_UTF8STRING: |
1576dec7 | 7108 | expr.value = c_parser_peek_token (parser)->value; |
7109 | expr.original_code = STRING_CST; | |
7110 | c_parser_consume_token (parser); | |
7111 | break; | |
7112 | case CPP_OBJC_STRING: | |
7113 | gcc_assert (c_dialect_objc ()); | |
7114 | expr.value | |
7115 | = objc_build_string_object (c_parser_peek_token (parser)->value); | |
1576dec7 | 7116 | c_parser_consume_token (parser); |
7117 | break; | |
7118 | case CPP_NAME: | |
b0d0931f | 7119 | switch (c_parser_peek_token (parser)->id_kind) |
1576dec7 | 7120 | { |
b0d0931f | 7121 | case C_ID_ID: |
7122 | { | |
7123 | tree id = c_parser_peek_token (parser)->value; | |
7124 | c_parser_consume_token (parser); | |
7125 | expr.value = build_external_ref (loc, id, | |
7126 | (c_parser_peek_token (parser)->type | |
7127 | == CPP_OPEN_PAREN), | |
7128 | &expr.original_type); | |
7129 | break; | |
7130 | } | |
7131 | case C_ID_CLASSNAME: | |
7132 | { | |
7133 | /* Here we parse the Objective-C 2.0 Class.name dot | |
7134 | syntax. */ | |
7135 | tree class_name = c_parser_peek_token (parser)->value; | |
7136 | tree component; | |
7137 | c_parser_consume_token (parser); | |
7138 | gcc_assert (c_dialect_objc ()); | |
7139 | if (!c_parser_require (parser, CPP_DOT, "expected %<.%>")) | |
7140 | { | |
7141 | expr.value = error_mark_node; | |
7142 | break; | |
7143 | } | |
7144 | if (c_parser_next_token_is_not (parser, CPP_NAME)) | |
7145 | { | |
7146 | c_parser_error (parser, "expected identifier"); | |
7147 | expr.value = error_mark_node; | |
7148 | break; | |
7149 | } | |
7150 | component = c_parser_peek_token (parser)->value; | |
7151 | c_parser_consume_token (parser); | |
7152 | expr.value = objc_build_class_component_ref (class_name, | |
7153 | component); | |
7154 | break; | |
7155 | } | |
7156 | default: | |
1576dec7 | 7157 | c_parser_error (parser, "expected expression"); |
7158 | expr.value = error_mark_node; | |
1576dec7 | 7159 | break; |
7160 | } | |
1576dec7 | 7161 | break; |
7162 | case CPP_OPEN_PAREN: | |
7163 | /* A parenthesized expression, statement expression or compound | |
7164 | literal. */ | |
7165 | if (c_parser_peek_2nd_token (parser)->type == CPP_OPEN_BRACE) | |
7166 | { | |
7167 | /* A statement expression. */ | |
7168 | tree stmt; | |
e60a6f7b | 7169 | location_t brace_loc; |
1576dec7 | 7170 | c_parser_consume_token (parser); |
e60a6f7b | 7171 | brace_loc = c_parser_peek_token (parser)->location; |
1576dec7 | 7172 | c_parser_consume_token (parser); |
cacfdc02 | 7173 | if (!building_stmt_list_p ()) |
1576dec7 | 7174 | { |
e60a6f7b | 7175 | error_at (loc, "braced-group within expression allowed " |
e3b80d49 | 7176 | "only inside a function"); |
1576dec7 | 7177 | parser->error = true; |
7178 | c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL); | |
7179 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); | |
7180 | expr.value = error_mark_node; | |
1576dec7 | 7181 | break; |
7182 | } | |
7183 | stmt = c_begin_stmt_expr (); | |
7184 | c_parser_compound_statement_nostart (parser); | |
7185 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, | |
7186 | "expected %<)%>"); | |
29438999 | 7187 | pedwarn (loc, OPT_Wpedantic, |
21ca8540 | 7188 | "ISO C forbids braced-groups within expressions"); |
e60a6f7b | 7189 | expr.value = c_finish_stmt_expr (brace_loc, stmt); |
062966c1 | 7190 | mark_exp_read (expr.value); |
1576dec7 | 7191 | } |
7192 | else if (c_token_starts_typename (c_parser_peek_2nd_token (parser))) | |
7193 | { | |
7194 | /* A compound literal. ??? Can we actually get here rather | |
7195 | than going directly to | |
7196 | c_parser_postfix_expression_after_paren_type from | |
7197 | elsewhere? */ | |
0b09525f | 7198 | location_t loc; |
1576dec7 | 7199 | struct c_type_name *type_name; |
7200 | c_parser_consume_token (parser); | |
0b09525f | 7201 | loc = c_parser_peek_token (parser)->location; |
1576dec7 | 7202 | type_name = c_parser_type_name (parser); |
7203 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, | |
7204 | "expected %<)%>"); | |
7205 | if (type_name == NULL) | |
7206 | { | |
7207 | expr.value = error_mark_node; | |
1576dec7 | 7208 | } |
7209 | else | |
7210 | expr = c_parser_postfix_expression_after_paren_type (parser, | |
0b09525f | 7211 | type_name, |
7212 | loc); | |
1576dec7 | 7213 | } |
7214 | else | |
7215 | { | |
7216 | /* A parenthesized expression. */ | |
7217 | c_parser_consume_token (parser); | |
7218 | expr = c_parser_expression (parser); | |
7219 | if (TREE_CODE (expr.value) == MODIFY_EXPR) | |
7220 | TREE_NO_WARNING (expr.value) = 1; | |
a75b1c71 | 7221 | if (expr.original_code != C_MAYBE_CONST_EXPR) |
7222 | expr.original_code = ERROR_MARK; | |
841fdaa6 | 7223 | /* Don't change EXPR.ORIGINAL_TYPE. */ |
1576dec7 | 7224 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, |
7225 | "expected %<)%>"); | |
7226 | } | |
7227 | break; | |
7228 | case CPP_KEYWORD: | |
7229 | switch (c_parser_peek_token (parser)->keyword) | |
7230 | { | |
7231 | case RID_FUNCTION_NAME: | |
89868e45 | 7232 | pedwarn (loc, OPT_Wpedantic, "ISO C does not support " |
7233 | "%<__FUNCTION__%> predefined identifier"); | |
7234 | expr.value = fname_decl (loc, | |
7235 | c_parser_peek_token (parser)->keyword, | |
7236 | c_parser_peek_token (parser)->value); | |
7237 | c_parser_consume_token (parser); | |
7238 | break; | |
1576dec7 | 7239 | case RID_PRETTY_FUNCTION_NAME: |
89868e45 | 7240 | pedwarn (loc, OPT_Wpedantic, "ISO C does not support " |
7241 | "%<__PRETTY_FUNCTION__%> predefined identifier"); | |
7242 | expr.value = fname_decl (loc, | |
7243 | c_parser_peek_token (parser)->keyword, | |
7244 | c_parser_peek_token (parser)->value); | |
7245 | c_parser_consume_token (parser); | |
7246 | break; | |
1576dec7 | 7247 | case RID_C99_FUNCTION_NAME: |
89868e45 | 7248 | pedwarn_c90 (loc, OPT_Wpedantic, "ISO C90 does not support " |
7249 | "%<__func__%> predefined identifier"); | |
e60a6f7b | 7250 | expr.value = fname_decl (loc, |
e3b80d49 | 7251 | c_parser_peek_token (parser)->keyword, |
1576dec7 | 7252 | c_parser_peek_token (parser)->value); |
1576dec7 | 7253 | c_parser_consume_token (parser); |
7254 | break; | |
7255 | case RID_VA_ARG: | |
7256 | c_parser_consume_token (parser); | |
7257 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
7258 | { | |
7259 | expr.value = error_mark_node; | |
1576dec7 | 7260 | break; |
7261 | } | |
7262 | e1 = c_parser_expr_no_commas (parser, NULL); | |
abc6c64f | 7263 | mark_exp_read (e1.value); |
a75b1c71 | 7264 | e1.value = c_fully_fold (e1.value, false, NULL); |
1576dec7 | 7265 | if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>")) |
7266 | { | |
7267 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); | |
7268 | expr.value = error_mark_node; | |
1576dec7 | 7269 | break; |
7270 | } | |
d62e827b | 7271 | loc = c_parser_peek_token (parser)->location; |
1576dec7 | 7272 | t1 = c_parser_type_name (parser); |
7273 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, | |
7274 | "expected %<)%>"); | |
7275 | if (t1 == NULL) | |
7276 | { | |
7277 | expr.value = error_mark_node; | |
1576dec7 | 7278 | } |
7279 | else | |
7280 | { | |
a75b1c71 | 7281 | tree type_expr = NULL_TREE; |
e60a6f7b | 7282 | expr.value = c_build_va_arg (loc, e1.value, |
7283 | groktypename (t1, &type_expr, NULL)); | |
a75b1c71 | 7284 | if (type_expr) |
7285 | { | |
7286 | expr.value = build2 (C_MAYBE_CONST_EXPR, | |
7287 | TREE_TYPE (expr.value), type_expr, | |
7288 | expr.value); | |
7289 | C_MAYBE_CONST_EXPR_NON_CONST (expr.value) = true; | |
7290 | } | |
1576dec7 | 7291 | } |
7292 | break; | |
7293 | case RID_OFFSETOF: | |
7294 | c_parser_consume_token (parser); | |
7295 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
7296 | { | |
7297 | expr.value = error_mark_node; | |
1576dec7 | 7298 | break; |
7299 | } | |
7300 | t1 = c_parser_type_name (parser); | |
7301 | if (t1 == NULL) | |
26ee9e7a | 7302 | parser->error = true; |
1576dec7 | 7303 | if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>")) |
26ee9e7a | 7304 | gcc_assert (parser->error); |
7305 | if (parser->error) | |
1576dec7 | 7306 | { |
7307 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); | |
7308 | expr.value = error_mark_node; | |
1576dec7 | 7309 | break; |
7310 | } | |
26ee9e7a | 7311 | |
1576dec7 | 7312 | { |
a75b1c71 | 7313 | tree type = groktypename (t1, NULL, NULL); |
1576dec7 | 7314 | tree offsetof_ref; |
7315 | if (type == error_mark_node) | |
7316 | offsetof_ref = error_mark_node; | |
7317 | else | |
e60a6f7b | 7318 | { |
7319 | offsetof_ref = build1 (INDIRECT_REF, type, null_pointer_node); | |
7320 | SET_EXPR_LOCATION (offsetof_ref, loc); | |
7321 | } | |
1576dec7 | 7322 | /* Parse the second argument to __builtin_offsetof. We |
7323 | must have one identifier, and beyond that we want to | |
7324 | accept sub structure and sub array references. */ | |
7325 | if (c_parser_next_token_is (parser, CPP_NAME)) | |
7326 | { | |
7327 | offsetof_ref = build_component_ref | |
e60a6f7b | 7328 | (loc, offsetof_ref, c_parser_peek_token (parser)->value); |
1576dec7 | 7329 | c_parser_consume_token (parser); |
7330 | while (c_parser_next_token_is (parser, CPP_DOT) | |
7331 | || c_parser_next_token_is (parser, | |
f0d0d842 | 7332 | CPP_OPEN_SQUARE) |
7333 | || c_parser_next_token_is (parser, | |
7334 | CPP_DEREF)) | |
1576dec7 | 7335 | { |
f0d0d842 | 7336 | if (c_parser_next_token_is (parser, CPP_DEREF)) |
7337 | { | |
7338 | loc = c_parser_peek_token (parser)->location; | |
e60a6f7b | 7339 | offsetof_ref = build_array_ref (loc, |
7340 | offsetof_ref, | |
7341 | integer_zero_node); | |
f0d0d842 | 7342 | goto do_dot; |
7343 | } | |
7344 | else if (c_parser_next_token_is (parser, CPP_DOT)) | |
1576dec7 | 7345 | { |
f0d0d842 | 7346 | do_dot: |
1576dec7 | 7347 | c_parser_consume_token (parser); |
7348 | if (c_parser_next_token_is_not (parser, | |
7349 | CPP_NAME)) | |
7350 | { | |
7351 | c_parser_error (parser, "expected identifier"); | |
7352 | break; | |
7353 | } | |
7354 | offsetof_ref = build_component_ref | |
e60a6f7b | 7355 | (loc, offsetof_ref, |
1576dec7 | 7356 | c_parser_peek_token (parser)->value); |
7357 | c_parser_consume_token (parser); | |
7358 | } | |
7359 | else | |
7360 | { | |
b560fabd | 7361 | struct c_expr ce; |
1576dec7 | 7362 | tree idx; |
dda49785 | 7363 | loc = c_parser_peek_token (parser)->location; |
1576dec7 | 7364 | c_parser_consume_token (parser); |
b560fabd | 7365 | ce = c_parser_expression (parser); |
7366 | ce = convert_lvalue_to_rvalue (loc, ce, false, false); | |
7367 | idx = ce.value; | |
a75b1c71 | 7368 | idx = c_fully_fold (idx, false, NULL); |
1576dec7 | 7369 | c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, |
7370 | "expected %<]%>"); | |
e60a6f7b | 7371 | offsetof_ref = build_array_ref (loc, offsetof_ref, idx); |
1576dec7 | 7372 | } |
7373 | } | |
7374 | } | |
7375 | else | |
7376 | c_parser_error (parser, "expected identifier"); | |
7377 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, | |
7378 | "expected %<)%>"); | |
7549df0d | 7379 | expr.value = fold_offsetof (offsetof_ref); |
1576dec7 | 7380 | } |
7381 | break; | |
7382 | case RID_CHOOSE_EXPR: | |
1576dec7 | 7383 | { |
f1f41a6c | 7384 | vec<c_expr_t, va_gc> *cexpr_list; |
a11dda8e | 7385 | c_expr_t *e1_p, *e2_p, *e3_p; |
7386 | tree c; | |
1576dec7 | 7387 | |
6cf89e04 | 7388 | c_parser_consume_token (parser); |
7389 | if (!c_parser_get_builtin_args (parser, | |
7390 | "__builtin_choose_expr", | |
0b049e15 | 7391 | &cexpr_list, true)) |
6cf89e04 | 7392 | { |
7393 | expr.value = error_mark_node; | |
7394 | break; | |
7395 | } | |
7396 | ||
f1f41a6c | 7397 | if (vec_safe_length (cexpr_list) != 3) |
6cf89e04 | 7398 | { |
7399 | error_at (loc, "wrong number of arguments to " | |
7400 | "%<__builtin_choose_expr%>"); | |
7401 | expr.value = error_mark_node; | |
7402 | break; | |
7403 | } | |
a11dda8e | 7404 | |
f1f41a6c | 7405 | e1_p = &(*cexpr_list)[0]; |
7406 | e2_p = &(*cexpr_list)[1]; | |
7407 | e3_p = &(*cexpr_list)[2]; | |
a11dda8e | 7408 | |
7409 | c = e1_p->value; | |
7410 | mark_exp_read (e2_p->value); | |
7411 | mark_exp_read (e3_p->value); | |
a75b1c71 | 7412 | if (TREE_CODE (c) != INTEGER_CST |
7413 | || !INTEGRAL_TYPE_P (TREE_TYPE (c))) | |
e3b80d49 | 7414 | error_at (loc, |
7415 | "first argument to %<__builtin_choose_expr%> not" | |
7416 | " a constant"); | |
a75b1c71 | 7417 | constant_expression_warning (c); |
a11dda8e | 7418 | expr = integer_zerop (c) ? *e3_p : *e2_p; |
6cf89e04 | 7419 | break; |
1576dec7 | 7420 | } |
1576dec7 | 7421 | case RID_TYPES_COMPATIBLE_P: |
7422 | c_parser_consume_token (parser); | |
7423 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
7424 | { | |
7425 | expr.value = error_mark_node; | |
1576dec7 | 7426 | break; |
7427 | } | |
7428 | t1 = c_parser_type_name (parser); | |
7429 | if (t1 == NULL) | |
7430 | { | |
7431 | expr.value = error_mark_node; | |
1576dec7 | 7432 | break; |
7433 | } | |
7434 | if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>")) | |
7435 | { | |
7436 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); | |
7437 | expr.value = error_mark_node; | |
1576dec7 | 7438 | break; |
7439 | } | |
7440 | t2 = c_parser_type_name (parser); | |
7441 | if (t2 == NULL) | |
7442 | { | |
7443 | expr.value = error_mark_node; | |
1576dec7 | 7444 | break; |
7445 | } | |
7446 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, | |
7447 | "expected %<)%>"); | |
7448 | { | |
7449 | tree e1, e2; | |
94b5c9e7 | 7450 | e1 = groktypename (t1, NULL, NULL); |
7451 | e2 = groktypename (t2, NULL, NULL); | |
7452 | if (e1 == error_mark_node || e2 == error_mark_node) | |
7453 | { | |
7454 | expr.value = error_mark_node; | |
7455 | break; | |
7456 | } | |
1576dec7 | 7457 | |
94b5c9e7 | 7458 | e1 = TYPE_MAIN_VARIANT (e1); |
7459 | e2 = TYPE_MAIN_VARIANT (e2); | |
1576dec7 | 7460 | |
2512209b | 7461 | expr.value |
7462 | = comptypes (e1, e2) ? integer_one_node : integer_zero_node; | |
1576dec7 | 7463 | } |
7464 | break; | |
6f58cf06 | 7465 | case RID_BUILTIN_CALL_WITH_STATIC_CHAIN: |
7466 | { | |
7467 | vec<c_expr_t, va_gc> *cexpr_list; | |
7468 | c_expr_t *e2_p; | |
7469 | tree chain_value; | |
7470 | ||
7471 | c_parser_consume_token (parser); | |
7472 | if (!c_parser_get_builtin_args (parser, | |
7473 | "__builtin_call_with_static_chain", | |
7474 | &cexpr_list, false)) | |
7475 | { | |
7476 | expr.value = error_mark_node; | |
7477 | break; | |
7478 | } | |
7479 | if (vec_safe_length (cexpr_list) != 2) | |
7480 | { | |
7481 | error_at (loc, "wrong number of arguments to " | |
7482 | "%<__builtin_call_with_static_chain%>"); | |
7483 | expr.value = error_mark_node; | |
7484 | break; | |
7485 | } | |
7486 | ||
7487 | expr = (*cexpr_list)[0]; | |
7488 | e2_p = &(*cexpr_list)[1]; | |
7489 | *e2_p = convert_lvalue_to_rvalue (loc, *e2_p, true, true); | |
7490 | chain_value = e2_p->value; | |
7491 | mark_exp_read (chain_value); | |
7492 | ||
7493 | if (TREE_CODE (expr.value) != CALL_EXPR) | |
7494 | error_at (loc, "first argument to " | |
7495 | "%<__builtin_call_with_static_chain%> " | |
7496 | "must be a call expression"); | |
7497 | else if (TREE_CODE (TREE_TYPE (chain_value)) != POINTER_TYPE) | |
7498 | error_at (loc, "second argument to " | |
7499 | "%<__builtin_call_with_static_chain%> " | |
7500 | "must be a pointer type"); | |
7501 | else | |
7502 | CALL_EXPR_STATIC_CHAIN (expr.value) = chain_value; | |
7503 | break; | |
7504 | } | |
bff4ad11 | 7505 | case RID_BUILTIN_COMPLEX: |
a11dda8e | 7506 | { |
f1f41a6c | 7507 | vec<c_expr_t, va_gc> *cexpr_list; |
a11dda8e | 7508 | c_expr_t *e1_p, *e2_p; |
7509 | ||
6cf89e04 | 7510 | c_parser_consume_token (parser); |
7511 | if (!c_parser_get_builtin_args (parser, | |
7512 | "__builtin_complex", | |
0b049e15 | 7513 | &cexpr_list, false)) |
6cf89e04 | 7514 | { |
7515 | expr.value = error_mark_node; | |
7516 | break; | |
7517 | } | |
7518 | ||
f1f41a6c | 7519 | if (vec_safe_length (cexpr_list) != 2) |
6cf89e04 | 7520 | { |
7521 | error_at (loc, "wrong number of arguments to " | |
7522 | "%<__builtin_complex%>"); | |
7523 | expr.value = error_mark_node; | |
7524 | break; | |
7525 | } | |
a11dda8e | 7526 | |
f1f41a6c | 7527 | e1_p = &(*cexpr_list)[0]; |
7528 | e2_p = &(*cexpr_list)[1]; | |
a11dda8e | 7529 | |
b560fabd | 7530 | *e1_p = convert_lvalue_to_rvalue (loc, *e1_p, true, true); |
a11dda8e | 7531 | if (TREE_CODE (e1_p->value) == EXCESS_PRECISION_EXPR) |
7532 | e1_p->value = convert (TREE_TYPE (e1_p->value), | |
7533 | TREE_OPERAND (e1_p->value, 0)); | |
b560fabd | 7534 | *e2_p = convert_lvalue_to_rvalue (loc, *e2_p, true, true); |
a11dda8e | 7535 | if (TREE_CODE (e2_p->value) == EXCESS_PRECISION_EXPR) |
7536 | e2_p->value = convert (TREE_TYPE (e2_p->value), | |
7537 | TREE_OPERAND (e2_p->value, 0)); | |
7538 | if (!SCALAR_FLOAT_TYPE_P (TREE_TYPE (e1_p->value)) | |
7539 | || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e1_p->value)) | |
7540 | || !SCALAR_FLOAT_TYPE_P (TREE_TYPE (e2_p->value)) | |
7541 | || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e2_p->value))) | |
6cf89e04 | 7542 | { |
7543 | error_at (loc, "%<__builtin_complex%> operand " | |
7544 | "not of real binary floating-point type"); | |
7545 | expr.value = error_mark_node; | |
7546 | break; | |
7547 | } | |
a11dda8e | 7548 | if (TYPE_MAIN_VARIANT (TREE_TYPE (e1_p->value)) |
7549 | != TYPE_MAIN_VARIANT (TREE_TYPE (e2_p->value))) | |
6cf89e04 | 7550 | { |
7551 | error_at (loc, | |
7552 | "%<__builtin_complex%> operands of different types"); | |
7553 | expr.value = error_mark_node; | |
7554 | break; | |
7555 | } | |
890c2e2f | 7556 | pedwarn_c90 (loc, OPT_Wpedantic, |
7557 | "ISO C90 does not support complex types"); | |
6cf89e04 | 7558 | expr.value = build2 (COMPLEX_EXPR, |
a11dda8e | 7559 | build_complex_type |
7560 | (TYPE_MAIN_VARIANT | |
7561 | (TREE_TYPE (e1_p->value))), | |
7562 | e1_p->value, e2_p->value); | |
6cf89e04 | 7563 | break; |
7564 | } | |
7565 | case RID_BUILTIN_SHUFFLE: | |
7566 | { | |
f1f41a6c | 7567 | vec<c_expr_t, va_gc> *cexpr_list; |
e739f10c | 7568 | unsigned int i; |
7569 | c_expr_t *p; | |
a11dda8e | 7570 | |
6cf89e04 | 7571 | c_parser_consume_token (parser); |
7572 | if (!c_parser_get_builtin_args (parser, | |
7573 | "__builtin_shuffle", | |
0b049e15 | 7574 | &cexpr_list, false)) |
6cf89e04 | 7575 | { |
7576 | expr.value = error_mark_node; | |
7577 | break; | |
7578 | } | |
7579 | ||
f1f41a6c | 7580 | FOR_EACH_VEC_SAFE_ELT (cexpr_list, i, p) |
b560fabd | 7581 | *p = convert_lvalue_to_rvalue (loc, *p, true, true); |
e739f10c | 7582 | |
f1f41a6c | 7583 | if (vec_safe_length (cexpr_list) == 2) |
a11dda8e | 7584 | expr.value = |
f4803722 | 7585 | c_build_vec_perm_expr |
f1f41a6c | 7586 | (loc, (*cexpr_list)[0].value, |
7587 | NULL_TREE, (*cexpr_list)[1].value); | |
a11dda8e | 7588 | |
f1f41a6c | 7589 | else if (vec_safe_length (cexpr_list) == 3) |
a11dda8e | 7590 | expr.value = |
f4803722 | 7591 | c_build_vec_perm_expr |
f1f41a6c | 7592 | (loc, (*cexpr_list)[0].value, |
7593 | (*cexpr_list)[1].value, | |
7594 | (*cexpr_list)[2].value); | |
6cf89e04 | 7595 | else |
7596 | { | |
7597 | error_at (loc, "wrong number of arguments to " | |
7598 | "%<__builtin_shuffle%>"); | |
7599 | expr.value = error_mark_node; | |
7600 | } | |
7601 | break; | |
7602 | } | |
1576dec7 | 7603 | case RID_AT_SELECTOR: |
7604 | gcc_assert (c_dialect_objc ()); | |
7605 | c_parser_consume_token (parser); | |
7606 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
7607 | { | |
7608 | expr.value = error_mark_node; | |
1576dec7 | 7609 | break; |
7610 | } | |
7611 | { | |
7612 | tree sel = c_parser_objc_selector_arg (parser); | |
7613 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, | |
7614 | "expected %<)%>"); | |
e60a6f7b | 7615 | expr.value = objc_build_selector_expr (loc, sel); |
1576dec7 | 7616 | } |
7617 | break; | |
7618 | case RID_AT_PROTOCOL: | |
7619 | gcc_assert (c_dialect_objc ()); | |
7620 | c_parser_consume_token (parser); | |
7621 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
7622 | { | |
7623 | expr.value = error_mark_node; | |
1576dec7 | 7624 | break; |
7625 | } | |
7626 | if (c_parser_next_token_is_not (parser, CPP_NAME)) | |
7627 | { | |
7628 | c_parser_error (parser, "expected identifier"); | |
7629 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); | |
7630 | expr.value = error_mark_node; | |
1576dec7 | 7631 | break; |
7632 | } | |
7633 | { | |
7634 | tree id = c_parser_peek_token (parser)->value; | |
7635 | c_parser_consume_token (parser); | |
7636 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, | |
7637 | "expected %<)%>"); | |
7638 | expr.value = objc_build_protocol_expr (id); | |
1576dec7 | 7639 | } |
7640 | break; | |
7641 | case RID_AT_ENCODE: | |
7642 | /* Extension to support C-structures in the archiver. */ | |
7643 | gcc_assert (c_dialect_objc ()); | |
7644 | c_parser_consume_token (parser); | |
7645 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
7646 | { | |
7647 | expr.value = error_mark_node; | |
1576dec7 | 7648 | break; |
7649 | } | |
7650 | t1 = c_parser_type_name (parser); | |
7651 | if (t1 == NULL) | |
7652 | { | |
7653 | expr.value = error_mark_node; | |
1576dec7 | 7654 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); |
7655 | break; | |
7656 | } | |
7657 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, | |
7658 | "expected %<)%>"); | |
7659 | { | |
a75b1c71 | 7660 | tree type = groktypename (t1, NULL, NULL); |
1576dec7 | 7661 | expr.value = objc_build_encode_expr (type); |
1576dec7 | 7662 | } |
7663 | break; | |
7aa04c8d | 7664 | case RID_GENERIC: |
7665 | expr = c_parser_generic_selection (parser); | |
7666 | break; | |
d037099f | 7667 | case RID_CILK_SPAWN: |
7668 | c_parser_consume_token (parser); | |
a89e6c15 | 7669 | if (!flag_cilkplus) |
d037099f | 7670 | { |
7671 | error_at (loc, "-fcilkplus must be enabled to use " | |
7672 | "%<_Cilk_spawn%>"); | |
7673 | expr = c_parser_postfix_expression (parser); | |
7674 | expr.value = error_mark_node; | |
7675 | } | |
0bc789fc | 7676 | else if (c_parser_peek_token (parser)->keyword == RID_CILK_SPAWN) |
d037099f | 7677 | { |
7678 | error_at (loc, "consecutive %<_Cilk_spawn%> keywords " | |
7679 | "are not permitted"); | |
7680 | /* Now flush out all the _Cilk_spawns. */ | |
7681 | while (c_parser_peek_token (parser)->keyword == RID_CILK_SPAWN) | |
7682 | c_parser_consume_token (parser); | |
7683 | expr = c_parser_postfix_expression (parser); | |
7684 | } | |
7685 | else | |
7686 | { | |
7687 | expr = c_parser_postfix_expression (parser); | |
7688 | expr.value = build_cilk_spawn (loc, expr.value); | |
7689 | } | |
7690 | break; | |
1576dec7 | 7691 | default: |
7692 | c_parser_error (parser, "expected expression"); | |
7693 | expr.value = error_mark_node; | |
1576dec7 | 7694 | break; |
7695 | } | |
7696 | break; | |
7697 | case CPP_OPEN_SQUARE: | |
7698 | if (c_dialect_objc ()) | |
7699 | { | |
7700 | tree receiver, args; | |
7701 | c_parser_consume_token (parser); | |
7702 | receiver = c_parser_objc_receiver (parser); | |
7703 | args = c_parser_objc_message_args (parser); | |
7704 | c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, | |
7705 | "expected %<]%>"); | |
4185cf58 | 7706 | expr.value = objc_build_message_expr (receiver, args); |
1576dec7 | 7707 | break; |
7708 | } | |
7709 | /* Else fall through to report error. */ | |
7710 | default: | |
7711 | c_parser_error (parser, "expected expression"); | |
7712 | expr.value = error_mark_node; | |
1576dec7 | 7713 | break; |
7714 | } | |
e60a6f7b | 7715 | return c_parser_postfix_expression_after_primary (parser, loc, expr); |
1576dec7 | 7716 | } |
7717 | ||
7718 | /* Parse a postfix expression after a parenthesized type name: the | |
7719 | brace-enclosed initializer of a compound literal, possibly followed | |
7720 | by some postfix operators. This is separate because it is not | |
7721 | possible to tell until after the type name whether a cast | |
7722 | expression has a cast or a compound literal, or whether the operand | |
7723 | of sizeof is a parenthesized type name or starts with a compound | |
0b09525f | 7724 | literal. TYPE_LOC is the location where TYPE_NAME starts--the |
7725 | location of the first token after the parentheses around the type | |
7726 | name. */ | |
1576dec7 | 7727 | |
7728 | static struct c_expr | |
7729 | c_parser_postfix_expression_after_paren_type (c_parser *parser, | |
0b09525f | 7730 | struct c_type_name *type_name, |
7731 | location_t type_loc) | |
1576dec7 | 7732 | { |
7733 | tree type; | |
7734 | struct c_expr init; | |
a75b1c71 | 7735 | bool non_const; |
1576dec7 | 7736 | struct c_expr expr; |
be9eba16 | 7737 | location_t start_loc; |
a75b1c71 | 7738 | tree type_expr = NULL_TREE; |
7739 | bool type_expr_const = true; | |
e60a6f7b | 7740 | check_compound_literal_type (type_loc, type_name); |
1576dec7 | 7741 | start_init (NULL_TREE, NULL, 0); |
a75b1c71 | 7742 | type = groktypename (type_name, &type_expr, &type_expr_const); |
be9eba16 | 7743 | start_loc = c_parser_peek_token (parser)->location; |
481f0237 | 7744 | if (type != error_mark_node && C_TYPE_VARIABLE_SIZE (type)) |
1576dec7 | 7745 | { |
0b09525f | 7746 | error_at (type_loc, "compound literal has variable size"); |
1576dec7 | 7747 | type = error_mark_node; |
7748 | } | |
7749 | init = c_parser_braced_init (parser, type, false); | |
7750 | finish_init (); | |
c9e51d25 | 7751 | maybe_warn_string_init (type_loc, type, init); |
1576dec7 | 7752 | |
6d5d708e | 7753 | if (type != error_mark_node |
7754 | && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type)) | |
7755 | && current_function_decl) | |
7756 | { | |
7757 | error ("compound literal qualified by address-space qualifier"); | |
7758 | type = error_mark_node; | |
7759 | } | |
7760 | ||
890c2e2f | 7761 | pedwarn_c90 (start_loc, OPT_Wpedantic, "ISO C90 forbids compound literals"); |
a75b1c71 | 7762 | non_const = ((init.value && TREE_CODE (init.value) == CONSTRUCTOR) |
7763 | ? CONSTRUCTOR_NON_CONST (init.value) | |
7764 | : init.original_code == C_MAYBE_CONST_EXPR); | |
7765 | non_const |= !type_expr_const; | |
e60a6f7b | 7766 | expr.value = build_compound_literal (start_loc, type, init.value, non_const); |
1576dec7 | 7767 | expr.original_code = ERROR_MARK; |
841fdaa6 | 7768 | expr.original_type = NULL; |
a75b1c71 | 7769 | if (type_expr) |
7770 | { | |
7771 | if (TREE_CODE (expr.value) == C_MAYBE_CONST_EXPR) | |
7772 | { | |
7773 | gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr.value) == NULL_TREE); | |
7774 | C_MAYBE_CONST_EXPR_PRE (expr.value) = type_expr; | |
7775 | } | |
7776 | else | |
7777 | { | |
7778 | gcc_assert (!non_const); | |
7779 | expr.value = build2 (C_MAYBE_CONST_EXPR, type, | |
7780 | type_expr, expr.value); | |
7781 | } | |
7782 | } | |
e60a6f7b | 7783 | return c_parser_postfix_expression_after_primary (parser, start_loc, expr); |
1576dec7 | 7784 | } |
7785 | ||
f003f5dc | 7786 | /* Callback function for sizeof_pointer_memaccess_warning to compare |
7787 | types. */ | |
7788 | ||
7789 | static bool | |
7790 | sizeof_ptr_memacc_comptypes (tree type1, tree type2) | |
7791 | { | |
7792 | return comptypes (type1, type2) == 1; | |
7793 | } | |
7794 | ||
1576dec7 | 7795 | /* Parse a postfix expression after the initial primary or compound |
e60a6f7b | 7796 | literal; that is, parse a series of postfix operators. |
7797 | ||
7798 | EXPR_LOC is the location of the primary expression. */ | |
1576dec7 | 7799 | |
7800 | static struct c_expr | |
7801 | c_parser_postfix_expression_after_primary (c_parser *parser, | |
e60a6f7b | 7802 | location_t expr_loc, |
1576dec7 | 7803 | struct c_expr expr) |
7804 | { | |
a75b1c71 | 7805 | struct c_expr orig_expr; |
b9c74b4d | 7806 | tree ident, idx; |
57f872a2 | 7807 | location_t sizeof_arg_loc[3]; |
7808 | tree sizeof_arg[3]; | |
305d96bc | 7809 | unsigned int literal_zero_mask; |
57f872a2 | 7810 | unsigned int i; |
f1f41a6c | 7811 | vec<tree, va_gc> *exprlist; |
b862f263 | 7812 | vec<tree, va_gc> *origtypes = NULL; |
ec761d5a | 7813 | vec<location_t> arg_loc = vNULL; |
7814 | ||
1576dec7 | 7815 | while (true) |
7816 | { | |
e60a6f7b | 7817 | location_t op_loc = c_parser_peek_token (parser)->location; |
1576dec7 | 7818 | switch (c_parser_peek_token (parser)->type) |
7819 | { | |
7820 | case CPP_OPEN_SQUARE: | |
7821 | /* Array reference. */ | |
7822 | c_parser_consume_token (parser); | |
a89e6c15 | 7823 | if (flag_cilkplus |
3c6d4197 | 7824 | && c_parser_peek_token (parser)->type == CPP_COLON) |
7825 | /* If we are here, then we have something like this: | |
7826 | Array [ : ] | |
7827 | */ | |
7828 | expr.value = c_parser_array_notation (expr_loc, parser, NULL_TREE, | |
7829 | expr.value); | |
7830 | else | |
7831 | { | |
7832 | idx = c_parser_expression (parser).value; | |
7833 | /* Here we have 3 options: | |
7834 | 1. Array [EXPR] -- Normal Array call. | |
7835 | 2. Array [EXPR : EXPR] -- Array notation without stride. | |
7836 | 3. Array [EXPR : EXPR : EXPR] -- Array notation with stride. | |
7837 | ||
7838 | For 1, we just handle it just like a normal array expression. | |
7839 | For 2 and 3 we handle it like we handle array notations. The | |
7840 | idx value we have above becomes the initial/start index. | |
7841 | */ | |
a89e6c15 | 7842 | if (flag_cilkplus |
3c6d4197 | 7843 | && c_parser_peek_token (parser)->type == CPP_COLON) |
7844 | expr.value = c_parser_array_notation (expr_loc, parser, idx, | |
7845 | expr.value); | |
7846 | else | |
7847 | { | |
7848 | c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, | |
7849 | "expected %<]%>"); | |
7850 | expr.value = build_array_ref (op_loc, expr.value, idx); | |
7851 | } | |
7852 | } | |
1576dec7 | 7853 | expr.original_code = ERROR_MARK; |
841fdaa6 | 7854 | expr.original_type = NULL; |
1576dec7 | 7855 | break; |
7856 | case CPP_OPEN_PAREN: | |
7857 | /* Function call. */ | |
7858 | c_parser_consume_token (parser); | |
57f872a2 | 7859 | for (i = 0; i < 3; i++) |
7860 | { | |
7861 | sizeof_arg[i] = NULL_TREE; | |
7862 | sizeof_arg_loc[i] = UNKNOWN_LOCATION; | |
7863 | } | |
305d96bc | 7864 | literal_zero_mask = 0; |
1576dec7 | 7865 | if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) |
b9c74b4d | 7866 | exprlist = NULL; |
1576dec7 | 7867 | else |
f003f5dc | 7868 | exprlist = c_parser_expr_list (parser, true, false, &origtypes, |
ec761d5a | 7869 | sizeof_arg_loc, sizeof_arg, |
305d96bc | 7870 | &arg_loc, &literal_zero_mask); |
1576dec7 | 7871 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, |
7872 | "expected %<)%>"); | |
a75b1c71 | 7873 | orig_expr = expr; |
abc6c64f | 7874 | mark_exp_read (expr.value); |
57f872a2 | 7875 | if (warn_sizeof_pointer_memaccess) |
7876 | sizeof_pointer_memaccess_warning (sizeof_arg_loc, | |
f003f5dc | 7877 | expr.value, exprlist, |
57f872a2 | 7878 | sizeof_arg, |
f003f5dc | 7879 | sizeof_ptr_memacc_comptypes); |
305d96bc | 7880 | if (warn_memset_transposed_args |
7881 | && TREE_CODE (expr.value) == FUNCTION_DECL | |
7882 | && DECL_BUILT_IN_CLASS (expr.value) == BUILT_IN_NORMAL | |
7883 | && DECL_FUNCTION_CODE (expr.value) == BUILT_IN_MEMSET | |
7884 | && vec_safe_length (exprlist) == 3 | |
7885 | && integer_zerop ((*exprlist)[2]) | |
7886 | && (literal_zero_mask & (1 << 2)) != 0 | |
7887 | && (!integer_zerop ((*exprlist)[1]) | |
7888 | || (literal_zero_mask & (1 << 1)) == 0)) | |
7889 | warning_at (expr_loc, OPT_Wmemset_transposed_args, | |
7890 | "%<memset%> used with constant zero length parameter; " | |
7891 | "this could be due to transposed parameters"); | |
7892 | ||
5a672e62 | 7893 | expr.value |
7894 | = c_build_function_call_vec (expr_loc, arg_loc, expr.value, | |
7895 | exprlist, origtypes); | |
1576dec7 | 7896 | expr.original_code = ERROR_MARK; |
a75b1c71 | 7897 | if (TREE_CODE (expr.value) == INTEGER_CST |
7898 | && TREE_CODE (orig_expr.value) == FUNCTION_DECL | |
7899 | && DECL_BUILT_IN_CLASS (orig_expr.value) == BUILT_IN_NORMAL | |
7900 | && DECL_FUNCTION_CODE (orig_expr.value) == BUILT_IN_CONSTANT_P) | |
7901 | expr.original_code = C_MAYBE_CONST_EXPR; | |
841fdaa6 | 7902 | expr.original_type = NULL; |
f1f41a6c | 7903 | if (exprlist) |
b9c74b4d | 7904 | { |
f352a3fb | 7905 | release_tree_vector (exprlist); |
7906 | release_tree_vector (origtypes); | |
b9c74b4d | 7907 | } |
ec761d5a | 7908 | arg_loc.release (); |
1576dec7 | 7909 | break; |
7910 | case CPP_DOT: | |
7911 | /* Structure element reference. */ | |
7912 | c_parser_consume_token (parser); | |
e60a6f7b | 7913 | expr = default_function_array_conversion (expr_loc, expr); |
1576dec7 | 7914 | if (c_parser_next_token_is (parser, CPP_NAME)) |
7915 | ident = c_parser_peek_token (parser)->value; | |
7916 | else | |
7917 | { | |
7918 | c_parser_error (parser, "expected identifier"); | |
7919 | expr.value = error_mark_node; | |
7920 | expr.original_code = ERROR_MARK; | |
841fdaa6 | 7921 | expr.original_type = NULL; |
1576dec7 | 7922 | return expr; |
7923 | } | |
7924 | c_parser_consume_token (parser); | |
e60a6f7b | 7925 | expr.value = build_component_ref (op_loc, expr.value, ident); |
1576dec7 | 7926 | expr.original_code = ERROR_MARK; |
841fdaa6 | 7927 | if (TREE_CODE (expr.value) != COMPONENT_REF) |
7928 | expr.original_type = NULL; | |
7929 | else | |
7930 | { | |
7931 | /* Remember the original type of a bitfield. */ | |
7932 | tree field = TREE_OPERAND (expr.value, 1); | |
7933 | if (TREE_CODE (field) != FIELD_DECL) | |
7934 | expr.original_type = NULL; | |
7935 | else | |
7936 | expr.original_type = DECL_BIT_FIELD_TYPE (field); | |
7937 | } | |
1576dec7 | 7938 | break; |
7939 | case CPP_DEREF: | |
7940 | /* Structure element reference. */ | |
7941 | c_parser_consume_token (parser); | |
b560fabd | 7942 | expr = convert_lvalue_to_rvalue (expr_loc, expr, true, false); |
1576dec7 | 7943 | if (c_parser_next_token_is (parser, CPP_NAME)) |
7944 | ident = c_parser_peek_token (parser)->value; | |
7945 | else | |
7946 | { | |
7947 | c_parser_error (parser, "expected identifier"); | |
7948 | expr.value = error_mark_node; | |
7949 | expr.original_code = ERROR_MARK; | |
841fdaa6 | 7950 | expr.original_type = NULL; |
1576dec7 | 7951 | return expr; |
7952 | } | |
7953 | c_parser_consume_token (parser); | |
e60a6f7b | 7954 | expr.value = build_component_ref (op_loc, |
7955 | build_indirect_ref (op_loc, | |
b6889cb0 | 7956 | expr.value, |
f08923b3 | 7957 | RO_ARROW), |
dda49785 | 7958 | ident); |
1576dec7 | 7959 | expr.original_code = ERROR_MARK; |
841fdaa6 | 7960 | if (TREE_CODE (expr.value) != COMPONENT_REF) |
7961 | expr.original_type = NULL; | |
7962 | else | |
7963 | { | |
7964 | /* Remember the original type of a bitfield. */ | |
7965 | tree field = TREE_OPERAND (expr.value, 1); | |
7966 | if (TREE_CODE (field) != FIELD_DECL) | |
7967 | expr.original_type = NULL; | |
7968 | else | |
7969 | expr.original_type = DECL_BIT_FIELD_TYPE (field); | |
7970 | } | |
1576dec7 | 7971 | break; |
7972 | case CPP_PLUS_PLUS: | |
7973 | /* Postincrement. */ | |
7974 | c_parser_consume_token (parser); | |
3c6d4197 | 7975 | /* If the expressions have array notations, we expand them. */ |
a89e6c15 | 7976 | if (flag_cilkplus |
3c6d4197 | 7977 | && TREE_CODE (expr.value) == ARRAY_NOTATION_REF) |
7978 | expr = fix_array_notation_expr (expr_loc, POSTINCREMENT_EXPR, expr); | |
7979 | else | |
7980 | { | |
7981 | expr = default_function_array_read_conversion (expr_loc, expr); | |
7982 | expr.value = build_unary_op (op_loc, | |
7983 | POSTINCREMENT_EXPR, expr.value, 0); | |
7984 | } | |
1576dec7 | 7985 | expr.original_code = ERROR_MARK; |
841fdaa6 | 7986 | expr.original_type = NULL; |
1576dec7 | 7987 | break; |
7988 | case CPP_MINUS_MINUS: | |
7989 | /* Postdecrement. */ | |
7990 | c_parser_consume_token (parser); | |
3c6d4197 | 7991 | /* If the expressions have array notations, we expand them. */ |
a89e6c15 | 7992 | if (flag_cilkplus |
3c6d4197 | 7993 | && TREE_CODE (expr.value) == ARRAY_NOTATION_REF) |
7994 | expr = fix_array_notation_expr (expr_loc, POSTDECREMENT_EXPR, expr); | |
7995 | else | |
7996 | { | |
7997 | expr = default_function_array_read_conversion (expr_loc, expr); | |
7998 | expr.value = build_unary_op (op_loc, | |
7999 | POSTDECREMENT_EXPR, expr.value, 0); | |
8000 | } | |
1576dec7 | 8001 | expr.original_code = ERROR_MARK; |
841fdaa6 | 8002 | expr.original_type = NULL; |
1576dec7 | 8003 | break; |
8004 | default: | |
8005 | return expr; | |
8006 | } | |
8007 | } | |
8008 | } | |
8009 | ||
8010 | /* Parse an expression (C90 6.3.17, C99 6.5.17). | |
8011 | ||
8012 | expression: | |
8013 | assignment-expression | |
8014 | expression , assignment-expression | |
8015 | */ | |
8016 | ||
8017 | static struct c_expr | |
8018 | c_parser_expression (c_parser *parser) | |
8019 | { | |
b560fabd | 8020 | location_t tloc = c_parser_peek_token (parser)->location; |
1576dec7 | 8021 | struct c_expr expr; |
8022 | expr = c_parser_expr_no_commas (parser, NULL); | |
b560fabd | 8023 | if (c_parser_next_token_is (parser, CPP_COMMA)) |
8024 | expr = convert_lvalue_to_rvalue (tloc, expr, true, false); | |
1576dec7 | 8025 | while (c_parser_next_token_is (parser, CPP_COMMA)) |
8026 | { | |
8027 | struct c_expr next; | |
b2af2a93 | 8028 | tree lhsval; |
e60a6f7b | 8029 | location_t loc = c_parser_peek_token (parser)->location; |
8030 | location_t expr_loc; | |
1576dec7 | 8031 | c_parser_consume_token (parser); |
e60a6f7b | 8032 | expr_loc = c_parser_peek_token (parser)->location; |
b2af2a93 | 8033 | lhsval = expr.value; |
8034 | while (TREE_CODE (lhsval) == COMPOUND_EXPR) | |
8035 | lhsval = TREE_OPERAND (lhsval, 1); | |
8036 | if (DECL_P (lhsval) || handled_component_p (lhsval)) | |
8037 | mark_exp_read (lhsval); | |
1576dec7 | 8038 | next = c_parser_expr_no_commas (parser, NULL); |
b560fabd | 8039 | next = convert_lvalue_to_rvalue (expr_loc, next, true, false); |
e60a6f7b | 8040 | expr.value = build_compound_expr (loc, expr.value, next.value); |
1576dec7 | 8041 | expr.original_code = COMPOUND_EXPR; |
bc620c5c | 8042 | expr.original_type = next.original_type; |
1576dec7 | 8043 | } |
8044 | return expr; | |
8045 | } | |
8046 | ||
b560fabd | 8047 | /* Parse an expression and convert functions or arrays to pointers and |
8048 | lvalues to rvalues. */ | |
f14c8207 | 8049 | |
8050 | static struct c_expr | |
8051 | c_parser_expression_conv (c_parser *parser) | |
8052 | { | |
8053 | struct c_expr expr; | |
e60a6f7b | 8054 | location_t loc = c_parser_peek_token (parser)->location; |
f14c8207 | 8055 | expr = c_parser_expression (parser); |
b560fabd | 8056 | expr = convert_lvalue_to_rvalue (loc, expr, true, false); |
f14c8207 | 8057 | return expr; |
8058 | } | |
8059 | ||
305d96bc | 8060 | /* Helper function of c_parser_expr_list. Check if IDXth (0 based) |
8061 | argument is a literal zero alone and if so, set it in literal_zero_mask. */ | |
8062 | ||
8063 | static inline void | |
8064 | c_parser_check_literal_zero (c_parser *parser, unsigned *literal_zero_mask, | |
8065 | unsigned int idx) | |
8066 | { | |
8067 | if (idx >= HOST_BITS_PER_INT) | |
8068 | return; | |
8069 | ||
8070 | c_token *tok = c_parser_peek_token (parser); | |
8071 | switch (tok->type) | |
8072 | { | |
8073 | case CPP_NUMBER: | |
8074 | case CPP_CHAR: | |
8075 | case CPP_WCHAR: | |
8076 | case CPP_CHAR16: | |
8077 | case CPP_CHAR32: | |
8078 | /* If a parameter is literal zero alone, remember it | |
8079 | for -Wmemset-transposed-args warning. */ | |
8080 | if (integer_zerop (tok->value) | |
8081 | && !TREE_OVERFLOW (tok->value) | |
8082 | && (c_parser_peek_2nd_token (parser)->type == CPP_COMMA | |
8083 | || c_parser_peek_2nd_token (parser)->type == CPP_CLOSE_PAREN)) | |
8084 | *literal_zero_mask |= 1U << idx; | |
8085 | default: | |
8086 | break; | |
8087 | } | |
8088 | } | |
8089 | ||
f14c8207 | 8090 | /* Parse a non-empty list of expressions. If CONVERT_P, convert |
b560fabd | 8091 | functions and arrays to pointers and lvalues to rvalues. If |
ec761d5a | 8092 | FOLD_P, fold the expressions. If LOCATIONS is non-NULL, save the |
8093 | locations of function arguments into this vector. | |
1576dec7 | 8094 | |
8095 | nonempty-expr-list: | |
8096 | assignment-expression | |
8097 | nonempty-expr-list , assignment-expression | |
8098 | */ | |
8099 | ||
f1f41a6c | 8100 | static vec<tree, va_gc> * |
b9c74b4d | 8101 | c_parser_expr_list (c_parser *parser, bool convert_p, bool fold_p, |
f1f41a6c | 8102 | vec<tree, va_gc> **p_orig_types, |
ec761d5a | 8103 | location_t *sizeof_arg_loc, tree *sizeof_arg, |
305d96bc | 8104 | vec<location_t> *locations, |
8105 | unsigned int *literal_zero_mask) | |
1576dec7 | 8106 | { |
f1f41a6c | 8107 | vec<tree, va_gc> *ret; |
8108 | vec<tree, va_gc> *orig_types; | |
1576dec7 | 8109 | struct c_expr expr; |
e60a6f7b | 8110 | location_t loc = c_parser_peek_token (parser)->location; |
57f872a2 | 8111 | location_t cur_sizeof_arg_loc = UNKNOWN_LOCATION; |
8112 | unsigned int idx = 0; | |
b9c74b4d | 8113 | |
f352a3fb | 8114 | ret = make_tree_vector (); |
b9c74b4d | 8115 | if (p_orig_types == NULL) |
8116 | orig_types = NULL; | |
8117 | else | |
f352a3fb | 8118 | orig_types = make_tree_vector (); |
b9c74b4d | 8119 | |
f003f5dc | 8120 | if (sizeof_arg != NULL |
8121 | && c_parser_next_token_is_keyword (parser, RID_SIZEOF)) | |
57f872a2 | 8122 | cur_sizeof_arg_loc = c_parser_peek_2nd_token (parser)->location; |
305d96bc | 8123 | if (literal_zero_mask) |
8124 | c_parser_check_literal_zero (parser, literal_zero_mask, 0); | |
1576dec7 | 8125 | expr = c_parser_expr_no_commas (parser, NULL); |
f14c8207 | 8126 | if (convert_p) |
b560fabd | 8127 | expr = convert_lvalue_to_rvalue (loc, expr, true, true); |
a75b1c71 | 8128 | if (fold_p) |
8129 | expr.value = c_fully_fold (expr.value, false, NULL); | |
f1f41a6c | 8130 | ret->quick_push (expr.value); |
8131 | if (orig_types) | |
8132 | orig_types->quick_push (expr.original_type); | |
ec761d5a | 8133 | if (locations) |
8134 | locations->safe_push (loc); | |
57f872a2 | 8135 | if (sizeof_arg != NULL |
8136 | && cur_sizeof_arg_loc != UNKNOWN_LOCATION | |
8137 | && expr.original_code == SIZEOF_EXPR) | |
8138 | { | |
8139 | sizeof_arg[0] = c_last_sizeof_arg; | |
8140 | sizeof_arg_loc[0] = cur_sizeof_arg_loc; | |
8141 | } | |
1576dec7 | 8142 | while (c_parser_next_token_is (parser, CPP_COMMA)) |
8143 | { | |
8144 | c_parser_consume_token (parser); | |
e60a6f7b | 8145 | loc = c_parser_peek_token (parser)->location; |
f003f5dc | 8146 | if (sizeof_arg != NULL |
8147 | && c_parser_next_token_is_keyword (parser, RID_SIZEOF)) | |
57f872a2 | 8148 | cur_sizeof_arg_loc = c_parser_peek_2nd_token (parser)->location; |
f003f5dc | 8149 | else |
57f872a2 | 8150 | cur_sizeof_arg_loc = UNKNOWN_LOCATION; |
305d96bc | 8151 | if (literal_zero_mask) |
8152 | c_parser_check_literal_zero (parser, literal_zero_mask, idx + 1); | |
1576dec7 | 8153 | expr = c_parser_expr_no_commas (parser, NULL); |
f14c8207 | 8154 | if (convert_p) |
b560fabd | 8155 | expr = convert_lvalue_to_rvalue (loc, expr, true, true); |
a75b1c71 | 8156 | if (fold_p) |
8157 | expr.value = c_fully_fold (expr.value, false, NULL); | |
f1f41a6c | 8158 | vec_safe_push (ret, expr.value); |
8159 | if (orig_types) | |
8160 | vec_safe_push (orig_types, expr.original_type); | |
ec761d5a | 8161 | if (locations) |
8162 | locations->safe_push (loc); | |
57f872a2 | 8163 | if (++idx < 3 |
8164 | && sizeof_arg != NULL | |
8165 | && cur_sizeof_arg_loc != UNKNOWN_LOCATION | |
f003f5dc | 8166 | && expr.original_code == SIZEOF_EXPR) |
8167 | { | |
57f872a2 | 8168 | sizeof_arg[idx] = c_last_sizeof_arg; |
8169 | sizeof_arg_loc[idx] = cur_sizeof_arg_loc; | |
f003f5dc | 8170 | } |
8171 | } | |
f1f41a6c | 8172 | if (orig_types) |
b9c74b4d | 8173 | *p_orig_types = orig_types; |
1576dec7 | 8174 | return ret; |
8175 | } | |
1576dec7 | 8176 | \f |
8177 | /* Parse Objective-C-specific constructs. */ | |
8178 | ||
8179 | /* Parse an objc-class-definition. | |
8180 | ||
8181 | objc-class-definition: | |
8182 | @interface identifier objc-superclass[opt] objc-protocol-refs[opt] | |
8183 | objc-class-instance-variables[opt] objc-methodprotolist @end | |
8184 | @implementation identifier objc-superclass[opt] | |
8185 | objc-class-instance-variables[opt] | |
8186 | @interface identifier ( identifier ) objc-protocol-refs[opt] | |
8187 | objc-methodprotolist @end | |
e16610d0 | 8188 | @interface identifier ( ) objc-protocol-refs[opt] |
8189 | objc-methodprotolist @end | |
1576dec7 | 8190 | @implementation identifier ( identifier ) |
8191 | ||
8192 | objc-superclass: | |
8193 | : identifier | |
8194 | ||
8195 | "@interface identifier (" must start "@interface identifier ( | |
8196 | identifier ) ...": objc-methodprotolist in the first production may | |
442e3cb9 | 8197 | not start with a parenthesized identifier as a declarator of a data |
1576dec7 | 8198 | definition with no declaration specifiers if the objc-superclass, |
8199 | objc-protocol-refs and objc-class-instance-variables are omitted. */ | |
8200 | ||
8201 | static void | |
a336eb4b | 8202 | c_parser_objc_class_definition (c_parser *parser, tree attributes) |
1576dec7 | 8203 | { |
8204 | bool iface_p; | |
8205 | tree id1; | |
8206 | tree superclass; | |
8207 | if (c_parser_next_token_is_keyword (parser, RID_AT_INTERFACE)) | |
8208 | iface_p = true; | |
8209 | else if (c_parser_next_token_is_keyword (parser, RID_AT_IMPLEMENTATION)) | |
8210 | iface_p = false; | |
8211 | else | |
8212 | gcc_unreachable (); | |
a336eb4b | 8213 | |
1576dec7 | 8214 | c_parser_consume_token (parser); |
8215 | if (c_parser_next_token_is_not (parser, CPP_NAME)) | |
8216 | { | |
8217 | c_parser_error (parser, "expected identifier"); | |
8218 | return; | |
8219 | } | |
8220 | id1 = c_parser_peek_token (parser)->value; | |
8221 | c_parser_consume_token (parser); | |
8222 | if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) | |
8223 | { | |
e16610d0 | 8224 | /* We have a category or class extension. */ |
1576dec7 | 8225 | tree id2; |
8226 | tree proto = NULL_TREE; | |
8227 | c_parser_consume_token (parser); | |
8228 | if (c_parser_next_token_is_not (parser, CPP_NAME)) | |
8229 | { | |
e16610d0 | 8230 | if (iface_p && c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) |
8231 | { | |
8232 | /* We have a class extension. */ | |
8233 | id2 = NULL_TREE; | |
8234 | } | |
8235 | else | |
8236 | { | |
8237 | c_parser_error (parser, "expected identifier or %<)%>"); | |
8238 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); | |
8239 | return; | |
8240 | } | |
8241 | } | |
8242 | else | |
8243 | { | |
8244 | id2 = c_parser_peek_token (parser)->value; | |
8245 | c_parser_consume_token (parser); | |
1576dec7 | 8246 | } |
1576dec7 | 8247 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); |
8248 | if (!iface_p) | |
8249 | { | |
8250 | objc_start_category_implementation (id1, id2); | |
8251 | return; | |
8252 | } | |
8253 | if (c_parser_next_token_is (parser, CPP_LESS)) | |
8254 | proto = c_parser_objc_protocol_refs (parser); | |
a336eb4b | 8255 | objc_start_category_interface (id1, id2, proto, attributes); |
1576dec7 | 8256 | c_parser_objc_methodprotolist (parser); |
8257 | c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>"); | |
8258 | objc_finish_interface (); | |
8259 | return; | |
8260 | } | |
8261 | if (c_parser_next_token_is (parser, CPP_COLON)) | |
8262 | { | |
8263 | c_parser_consume_token (parser); | |
8264 | if (c_parser_next_token_is_not (parser, CPP_NAME)) | |
8265 | { | |
8266 | c_parser_error (parser, "expected identifier"); | |
8267 | return; | |
8268 | } | |
8269 | superclass = c_parser_peek_token (parser)->value; | |
8270 | c_parser_consume_token (parser); | |
8271 | } | |
8272 | else | |
8273 | superclass = NULL_TREE; | |
8274 | if (iface_p) | |
8275 | { | |
8276 | tree proto = NULL_TREE; | |
8277 | if (c_parser_next_token_is (parser, CPP_LESS)) | |
8278 | proto = c_parser_objc_protocol_refs (parser); | |
a336eb4b | 8279 | objc_start_class_interface (id1, superclass, proto, attributes); |
1576dec7 | 8280 | } |
8281 | else | |
8282 | objc_start_class_implementation (id1, superclass); | |
8283 | if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) | |
8284 | c_parser_objc_class_instance_variables (parser); | |
8285 | if (iface_p) | |
8286 | { | |
8287 | objc_continue_interface (); | |
8288 | c_parser_objc_methodprotolist (parser); | |
8289 | c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>"); | |
8290 | objc_finish_interface (); | |
8291 | } | |
8292 | else | |
8293 | { | |
8294 | objc_continue_implementation (); | |
8295 | return; | |
8296 | } | |
8297 | } | |
8298 | ||
8299 | /* Parse objc-class-instance-variables. | |
8300 | ||
8301 | objc-class-instance-variables: | |
8302 | { objc-instance-variable-decl-list[opt] } | |
8303 | ||
8304 | objc-instance-variable-decl-list: | |
8305 | objc-visibility-spec | |
8306 | objc-instance-variable-decl ; | |
8307 | ; | |
8308 | objc-instance-variable-decl-list objc-visibility-spec | |
8309 | objc-instance-variable-decl-list objc-instance-variable-decl ; | |
8310 | objc-instance-variable-decl-list ; | |
8311 | ||
8312 | objc-visibility-spec: | |
8313 | @private | |
8314 | @protected | |
8315 | @public | |
8316 | ||
8317 | objc-instance-variable-decl: | |
8318 | struct-declaration | |
8319 | */ | |
8320 | ||
8321 | static void | |
8322 | c_parser_objc_class_instance_variables (c_parser *parser) | |
8323 | { | |
8324 | gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE)); | |
8325 | c_parser_consume_token (parser); | |
8326 | while (c_parser_next_token_is_not (parser, CPP_EOF)) | |
8327 | { | |
8328 | tree decls; | |
8329 | /* Parse any stray semicolon. */ | |
8330 | if (c_parser_next_token_is (parser, CPP_SEMICOLON)) | |
8331 | { | |
29438999 | 8332 | pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic, |
7ef1fa91 | 8333 | "extra semicolon"); |
1576dec7 | 8334 | c_parser_consume_token (parser); |
8335 | continue; | |
8336 | } | |
8337 | /* Stop if at the end of the instance variables. */ | |
8338 | if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) | |
8339 | { | |
8340 | c_parser_consume_token (parser); | |
8341 | break; | |
8342 | } | |
8343 | /* Parse any objc-visibility-spec. */ | |
e5c75ac3 | 8344 | if (c_parser_next_token_is_keyword (parser, RID_AT_PRIVATE)) |
1576dec7 | 8345 | { |
8346 | c_parser_consume_token (parser); | |
4a8875ed | 8347 | objc_set_visibility (OBJC_IVAR_VIS_PRIVATE); |
1576dec7 | 8348 | continue; |
8349 | } | |
e5c75ac3 | 8350 | else if (c_parser_next_token_is_keyword (parser, RID_AT_PROTECTED)) |
1576dec7 | 8351 | { |
8352 | c_parser_consume_token (parser); | |
4a8875ed | 8353 | objc_set_visibility (OBJC_IVAR_VIS_PROTECTED); |
1576dec7 | 8354 | continue; |
8355 | } | |
e5c75ac3 | 8356 | else if (c_parser_next_token_is_keyword (parser, RID_AT_PUBLIC)) |
1576dec7 | 8357 | { |
8358 | c_parser_consume_token (parser); | |
4a8875ed | 8359 | objc_set_visibility (OBJC_IVAR_VIS_PUBLIC); |
8360 | continue; | |
8361 | } | |
8362 | else if (c_parser_next_token_is_keyword (parser, RID_AT_PACKAGE)) | |
8363 | { | |
8364 | c_parser_consume_token (parser); | |
8365 | objc_set_visibility (OBJC_IVAR_VIS_PACKAGE); | |
1576dec7 | 8366 | continue; |
8367 | } | |
b75b98aa | 8368 | else if (c_parser_next_token_is (parser, CPP_PRAGMA)) |
8369 | { | |
8370 | c_parser_pragma (parser, pragma_external); | |
8371 | continue; | |
8372 | } | |
8373 | ||
1576dec7 | 8374 | /* Parse some comma-separated declarations. */ |
8375 | decls = c_parser_struct_declaration (parser); | |
7ef1fa91 | 8376 | if (decls == NULL) |
8377 | { | |
8378 | /* There is a syntax error. We want to skip the offending | |
8379 | tokens up to the next ';' (included) or '}' | |
8380 | (excluded). */ | |
8381 | ||
8382 | /* First, skip manually a ')' or ']'. This is because they | |
8383 | reduce the nesting level, so c_parser_skip_until_found() | |
8384 | wouldn't be able to skip past them. */ | |
8385 | c_token *token = c_parser_peek_token (parser); | |
8386 | if (token->type == CPP_CLOSE_PAREN || token->type == CPP_CLOSE_SQUARE) | |
8387 | c_parser_consume_token (parser); | |
8388 | ||
8389 | /* Then, do the standard skipping. */ | |
8390 | c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL); | |
8391 | ||
8392 | /* We hopefully recovered. Start normal parsing again. */ | |
8393 | parser->error = false; | |
8394 | continue; | |
8395 | } | |
8396 | else | |
8397 | { | |
8398 | /* Comma-separated instance variables are chained together | |
8399 | in reverse order; add them one by one. */ | |
8400 | tree ivar = nreverse (decls); | |
8401 | for (; ivar; ivar = DECL_CHAIN (ivar)) | |
8402 | objc_add_instance_variable (copy_node (ivar)); | |
8403 | } | |
1576dec7 | 8404 | c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); |
8405 | } | |
8406 | } | |
8407 | ||
8408 | /* Parse an objc-class-declaration. | |
8409 | ||
8410 | objc-class-declaration: | |
8411 | @class identifier-list ; | |
8412 | */ | |
8413 | ||
8414 | static void | |
8415 | c_parser_objc_class_declaration (c_parser *parser) | |
8416 | { | |
e5c75ac3 | 8417 | gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_CLASS)); |
1576dec7 | 8418 | c_parser_consume_token (parser); |
8419 | /* Any identifiers, including those declared as type names, are OK | |
8420 | here. */ | |
8421 | while (true) | |
8422 | { | |
8423 | tree id; | |
8424 | if (c_parser_next_token_is_not (parser, CPP_NAME)) | |
8425 | { | |
8426 | c_parser_error (parser, "expected identifier"); | |
e1f293c0 | 8427 | c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL); |
8428 | parser->error = false; | |
8429 | return; | |
1576dec7 | 8430 | } |
8431 | id = c_parser_peek_token (parser)->value; | |
29d7200d | 8432 | objc_declare_class (id); |
1576dec7 | 8433 | c_parser_consume_token (parser); |
8434 | if (c_parser_next_token_is (parser, CPP_COMMA)) | |
8435 | c_parser_consume_token (parser); | |
8436 | else | |
8437 | break; | |
8438 | } | |
8439 | c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); | |
1576dec7 | 8440 | } |
8441 | ||
8442 | /* Parse an objc-alias-declaration. | |
8443 | ||
8444 | objc-alias-declaration: | |
8445 | @compatibility_alias identifier identifier ; | |
8446 | */ | |
8447 | ||
8448 | static void | |
8449 | c_parser_objc_alias_declaration (c_parser *parser) | |
8450 | { | |
8451 | tree id1, id2; | |
8452 | gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_ALIAS)); | |
8453 | c_parser_consume_token (parser); | |
8454 | if (c_parser_next_token_is_not (parser, CPP_NAME)) | |
8455 | { | |
8456 | c_parser_error (parser, "expected identifier"); | |
8457 | c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL); | |
8458 | return; | |
8459 | } | |
8460 | id1 = c_parser_peek_token (parser)->value; | |
8461 | c_parser_consume_token (parser); | |
8462 | if (c_parser_next_token_is_not (parser, CPP_NAME)) | |
8463 | { | |
8464 | c_parser_error (parser, "expected identifier"); | |
8465 | c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL); | |
8466 | return; | |
8467 | } | |
8468 | id2 = c_parser_peek_token (parser)->value; | |
8469 | c_parser_consume_token (parser); | |
8470 | c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); | |
8471 | objc_declare_alias (id1, id2); | |
8472 | } | |
8473 | ||
8474 | /* Parse an objc-protocol-definition. | |
8475 | ||
8476 | objc-protocol-definition: | |
8477 | @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end | |
8478 | @protocol identifier-list ; | |
8479 | ||
8480 | "@protocol identifier ;" should be resolved as "@protocol | |
8481 | identifier-list ;": objc-methodprotolist may not start with a | |
8482 | semicolon in the first alternative if objc-protocol-refs are | |
8483 | omitted. */ | |
8484 | ||
8485 | static void | |
a336eb4b | 8486 | c_parser_objc_protocol_definition (c_parser *parser, tree attributes) |
1576dec7 | 8487 | { |
8488 | gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_PROTOCOL)); | |
a336eb4b | 8489 | |
1576dec7 | 8490 | c_parser_consume_token (parser); |
8491 | if (c_parser_next_token_is_not (parser, CPP_NAME)) | |
8492 | { | |
8493 | c_parser_error (parser, "expected identifier"); | |
8494 | return; | |
8495 | } | |
8496 | if (c_parser_peek_2nd_token (parser)->type == CPP_COMMA | |
8497 | || c_parser_peek_2nd_token (parser)->type == CPP_SEMICOLON) | |
8498 | { | |
1576dec7 | 8499 | /* Any identifiers, including those declared as type names, are |
8500 | OK here. */ | |
8501 | while (true) | |
8502 | { | |
8503 | tree id; | |
8504 | if (c_parser_next_token_is_not (parser, CPP_NAME)) | |
8505 | { | |
8506 | c_parser_error (parser, "expected identifier"); | |
8507 | break; | |
8508 | } | |
8509 | id = c_parser_peek_token (parser)->value; | |
a758bf7d | 8510 | objc_declare_protocol (id, attributes); |
1576dec7 | 8511 | c_parser_consume_token (parser); |
8512 | if (c_parser_next_token_is (parser, CPP_COMMA)) | |
8513 | c_parser_consume_token (parser); | |
8514 | else | |
8515 | break; | |
8516 | } | |
8517 | c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); | |
1576dec7 | 8518 | } |
8519 | else | |
8520 | { | |
8521 | tree id = c_parser_peek_token (parser)->value; | |
8522 | tree proto = NULL_TREE; | |
8523 | c_parser_consume_token (parser); | |
8524 | if (c_parser_next_token_is (parser, CPP_LESS)) | |
8525 | proto = c_parser_objc_protocol_refs (parser); | |
920d59b0 | 8526 | parser->objc_pq_context = true; |
a336eb4b | 8527 | objc_start_protocol (id, proto, attributes); |
1576dec7 | 8528 | c_parser_objc_methodprotolist (parser); |
8529 | c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>"); | |
920d59b0 | 8530 | parser->objc_pq_context = false; |
1576dec7 | 8531 | objc_finish_interface (); |
8532 | } | |
8533 | } | |
8534 | ||
8535 | /* Parse an objc-method-type. | |
8536 | ||
8537 | objc-method-type: | |
8538 | + | |
8539 | - | |
1576dec7 | 8540 | |
45b2b110 | 8541 | Return true if it is a class method (+) and false if it is |
8542 | an instance method (-). | |
8543 | */ | |
8544 | static inline bool | |
1576dec7 | 8545 | c_parser_objc_method_type (c_parser *parser) |
8546 | { | |
8547 | switch (c_parser_peek_token (parser)->type) | |
8548 | { | |
8549 | case CPP_PLUS: | |
8550 | c_parser_consume_token (parser); | |
45b2b110 | 8551 | return true; |
1576dec7 | 8552 | case CPP_MINUS: |
8553 | c_parser_consume_token (parser); | |
45b2b110 | 8554 | return false; |
1576dec7 | 8555 | default: |
8556 | gcc_unreachable (); | |
8557 | } | |
8558 | } | |
8559 | ||
8560 | /* Parse an objc-method-definition. | |
8561 | ||
8562 | objc-method-definition: | |
8563 | objc-method-type objc-method-decl ;[opt] compound-statement | |
8564 | */ | |
8565 | ||
8566 | static void | |
8567 | c_parser_objc_method_definition (c_parser *parser) | |
8568 | { | |
45b2b110 | 8569 | bool is_class_method = c_parser_objc_method_type (parser); |
4232a958 | 8570 | tree decl, attributes = NULL_TREE, expr = NULL_TREE; |
920d59b0 | 8571 | parser->objc_pq_context = true; |
4232a958 | 8572 | decl = c_parser_objc_method_decl (parser, is_class_method, &attributes, |
8573 | &expr); | |
03fc2271 | 8574 | if (decl == error_mark_node) |
8575 | return; /* Bail here. */ | |
8576 | ||
1576dec7 | 8577 | if (c_parser_next_token_is (parser, CPP_SEMICOLON)) |
8578 | { | |
8579 | c_parser_consume_token (parser); | |
29438999 | 8580 | pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic, |
21ca8540 | 8581 | "extra semicolon in method definition specified"); |
1576dec7 | 8582 | } |
03fc2271 | 8583 | |
169987fa | 8584 | if (!c_parser_next_token_is (parser, CPP_OPEN_BRACE)) |
8585 | { | |
8586 | c_parser_error (parser, "expected %<{%>"); | |
8587 | return; | |
8588 | } | |
03fc2271 | 8589 | |
920d59b0 | 8590 | parser->objc_pq_context = false; |
4232a958 | 8591 | if (objc_start_method_definition (is_class_method, decl, attributes, expr)) |
d4a8fb25 | 8592 | { |
8593 | add_stmt (c_parser_compound_statement (parser)); | |
8594 | objc_finish_method_definition (current_function_decl); | |
8595 | } | |
8596 | else | |
8597 | { | |
8598 | /* This code is executed when we find a method definition | |
06517bd4 | 8599 | outside of an @implementation context (or invalid for other |
8600 | reasons). Parse the method (to keep going) but do not emit | |
8601 | any code. | |
d4a8fb25 | 8602 | */ |
8603 | c_parser_compound_statement (parser); | |
8604 | } | |
1576dec7 | 8605 | } |
8606 | ||
8607 | /* Parse an objc-methodprotolist. | |
8608 | ||
8609 | objc-methodprotolist: | |
8610 | empty | |
8611 | objc-methodprotolist objc-methodproto | |
8612 | objc-methodprotolist declaration | |
8613 | objc-methodprotolist ; | |
069761fb | 8614 | @optional |
8615 | @required | |
1576dec7 | 8616 | |
8617 | The declaration is a data definition, which may be missing | |
8618 | declaration specifiers under the same rules and diagnostics as | |
8619 | other data definitions outside functions, and the stray semicolon | |
8620 | is diagnosed the same way as a stray semicolon outside a | |
8621 | function. */ | |
8622 | ||
8623 | static void | |
8624 | c_parser_objc_methodprotolist (c_parser *parser) | |
8625 | { | |
8626 | while (true) | |
8627 | { | |
8628 | /* The list is terminated by @end. */ | |
8629 | switch (c_parser_peek_token (parser)->type) | |
8630 | { | |
8631 | case CPP_SEMICOLON: | |
29438999 | 8632 | pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic, |
21ca8540 | 8633 | "ISO C does not allow extra %<;%> outside of a function"); |
1576dec7 | 8634 | c_parser_consume_token (parser); |
8635 | break; | |
8636 | case CPP_PLUS: | |
8637 | case CPP_MINUS: | |
8638 | c_parser_objc_methodproto (parser); | |
8639 | break; | |
a2952f2e | 8640 | case CPP_PRAGMA: |
8641 | c_parser_pragma (parser, pragma_external); | |
8642 | break; | |
1576dec7 | 8643 | case CPP_EOF: |
8644 | return; | |
8645 | default: | |
8646 | if (c_parser_next_token_is_keyword (parser, RID_AT_END)) | |
8647 | return; | |
86c110ac | 8648 | else if (c_parser_next_token_is_keyword (parser, RID_AT_PROPERTY)) |
1d894bcf | 8649 | c_parser_objc_at_property_declaration (parser); |
069761fb | 8650 | else if (c_parser_next_token_is_keyword (parser, RID_AT_OPTIONAL)) |
8651 | { | |
8652 | objc_set_method_opt (true); | |
8653 | c_parser_consume_token (parser); | |
8654 | } | |
8655 | else if (c_parser_next_token_is_keyword (parser, RID_AT_REQUIRED)) | |
8656 | { | |
8657 | objc_set_method_opt (false); | |
8658 | c_parser_consume_token (parser); | |
8659 | } | |
8660 | else | |
8661 | c_parser_declaration_or_fndef (parser, false, false, true, | |
bc7bff74 | 8662 | false, true, NULL, vNULL); |
1576dec7 | 8663 | break; |
8664 | } | |
8665 | } | |
8666 | } | |
8667 | ||
8668 | /* Parse an objc-methodproto. | |
8669 | ||
8670 | objc-methodproto: | |
8671 | objc-method-type objc-method-decl ; | |
8672 | */ | |
8673 | ||
8674 | static void | |
8675 | c_parser_objc_methodproto (c_parser *parser) | |
8676 | { | |
45b2b110 | 8677 | bool is_class_method = c_parser_objc_method_type (parser); |
03fc2271 | 8678 | tree decl, attributes = NULL_TREE; |
45b2b110 | 8679 | |
1576dec7 | 8680 | /* Remember protocol qualifiers in prototypes. */ |
920d59b0 | 8681 | parser->objc_pq_context = true; |
4232a958 | 8682 | decl = c_parser_objc_method_decl (parser, is_class_method, &attributes, |
8683 | NULL); | |
03fc2271 | 8684 | /* Forget protocol qualifiers now. */ |
920d59b0 | 8685 | parser->objc_pq_context = false; |
03fc2271 | 8686 | |
8687 | /* Do not allow the presence of attributes to hide an erroneous | |
8688 | method implementation in the interface section. */ | |
8689 | if (!c_parser_next_token_is (parser, CPP_SEMICOLON)) | |
8690 | { | |
8691 | c_parser_error (parser, "expected %<;%>"); | |
8692 | return; | |
8693 | } | |
8694 | ||
8695 | if (decl != error_mark_node) | |
45b2b110 | 8696 | objc_add_method_declaration (is_class_method, decl, attributes); |
03fc2271 | 8697 | |
1576dec7 | 8698 | c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); |
8699 | } | |
8700 | ||
03fc2271 | 8701 | /* If we are at a position that method attributes may be present, check that |
8702 | there are not any parsed already (a syntax error) and then collect any | |
8703 | specified at the current location. Finally, if new attributes were present, | |
8704 | check that the next token is legal ( ';' for decls and '{' for defs). */ | |
8705 | ||
8706 | static bool | |
8707 | c_parser_objc_maybe_method_attributes (c_parser* parser, tree* attributes) | |
8708 | { | |
8709 | bool bad = false; | |
8710 | if (*attributes) | |
8711 | { | |
8712 | c_parser_error (parser, | |
8713 | "method attributes must be specified at the end only"); | |
8714 | *attributes = NULL_TREE; | |
8715 | bad = true; | |
8716 | } | |
8717 | ||
8718 | if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)) | |
8719 | *attributes = c_parser_attributes (parser); | |
8720 | ||
8721 | /* If there were no attributes here, just report any earlier error. */ | |
8722 | if (*attributes == NULL_TREE || bad) | |
8723 | return bad; | |
8724 | ||
8725 | /* If the attributes are followed by a ; or {, then just report any earlier | |
8726 | error. */ | |
8727 | if (c_parser_next_token_is (parser, CPP_SEMICOLON) | |
8728 | || c_parser_next_token_is (parser, CPP_OPEN_BRACE)) | |
8729 | return bad; | |
8730 | ||
8731 | /* We've got attributes, but not at the end. */ | |
8732 | c_parser_error (parser, | |
8733 | "expected %<;%> or %<{%> after method attribute definition"); | |
8734 | return true; | |
8735 | } | |
8736 | ||
1576dec7 | 8737 | /* Parse an objc-method-decl. |
8738 | ||
8739 | objc-method-decl: | |
8740 | ( objc-type-name ) objc-selector | |
8741 | objc-selector | |
8742 | ( objc-type-name ) objc-keyword-selector objc-optparmlist | |
8743 | objc-keyword-selector objc-optparmlist | |
03fc2271 | 8744 | attributes |
1576dec7 | 8745 | |
8746 | objc-keyword-selector: | |
8747 | objc-keyword-decl | |
8748 | objc-keyword-selector objc-keyword-decl | |
8749 | ||
8750 | objc-keyword-decl: | |
8751 | objc-selector : ( objc-type-name ) identifier | |
8752 | objc-selector : identifier | |
8753 | : ( objc-type-name ) identifier | |
8754 | : identifier | |
8755 | ||
8756 | objc-optparmlist: | |
8757 | objc-optparms objc-optellipsis | |
8758 | ||
8759 | objc-optparms: | |
8760 | empty | |
8761 | objc-opt-parms , parameter-declaration | |
8762 | ||
8763 | objc-optellipsis: | |
8764 | empty | |
8765 | , ... | |
8766 | */ | |
8767 | ||
8768 | static tree | |
4232a958 | 8769 | c_parser_objc_method_decl (c_parser *parser, bool is_class_method, |
8770 | tree *attributes, tree *expr) | |
1576dec7 | 8771 | { |
8772 | tree type = NULL_TREE; | |
8773 | tree sel; | |
8774 | tree parms = NULL_TREE; | |
450302fe | 8775 | bool ellipsis = false; |
03fc2271 | 8776 | bool attr_err = false; |
450302fe | 8777 | |
03fc2271 | 8778 | *attributes = NULL_TREE; |
1576dec7 | 8779 | if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) |
8780 | { | |
8781 | c_parser_consume_token (parser); | |
8782 | type = c_parser_objc_type_name (parser); | |
8783 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
8784 | } | |
8785 | sel = c_parser_objc_selector (parser); | |
8786 | /* If there is no selector, or a colon follows, we have an | |
8787 | objc-keyword-selector. If there is a selector, and a colon does | |
8788 | not follow, that selector ends the objc-method-decl. */ | |
8789 | if (!sel || c_parser_next_token_is (parser, CPP_COLON)) | |
8790 | { | |
8791 | tree tsel = sel; | |
8792 | tree list = NULL_TREE; | |
1576dec7 | 8793 | while (true) |
8794 | { | |
8795 | tree atype = NULL_TREE, id, keyworddecl; | |
03fc2271 | 8796 | tree param_attr = NULL_TREE; |
1576dec7 | 8797 | if (!c_parser_require (parser, CPP_COLON, "expected %<:%>")) |
8798 | break; | |
8799 | if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) | |
8800 | { | |
8801 | c_parser_consume_token (parser); | |
8802 | atype = c_parser_objc_type_name (parser); | |
8803 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, | |
8804 | "expected %<)%>"); | |
8805 | } | |
03fc2271 | 8806 | /* New ObjC allows attributes on method parameters. */ |
8807 | if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)) | |
8808 | param_attr = c_parser_attributes (parser); | |
1576dec7 | 8809 | if (c_parser_next_token_is_not (parser, CPP_NAME)) |
8810 | { | |
8811 | c_parser_error (parser, "expected identifier"); | |
8812 | return error_mark_node; | |
8813 | } | |
8814 | id = c_parser_peek_token (parser)->value; | |
8815 | c_parser_consume_token (parser); | |
03fc2271 | 8816 | keyworddecl = objc_build_keyword_decl (tsel, atype, id, param_attr); |
1576dec7 | 8817 | list = chainon (list, keyworddecl); |
8818 | tsel = c_parser_objc_selector (parser); | |
8819 | if (!tsel && c_parser_next_token_is_not (parser, CPP_COLON)) | |
8820 | break; | |
8821 | } | |
03fc2271 | 8822 | |
8823 | attr_err |= c_parser_objc_maybe_method_attributes (parser, attributes) ; | |
8824 | ||
1576dec7 | 8825 | /* Parse the optional parameter list. Optional Objective-C |
8826 | method parameters follow the C syntax, and may include '...' | |
8827 | to denote a variable number of arguments. */ | |
8828 | parms = make_node (TREE_LIST); | |
1576dec7 | 8829 | while (c_parser_next_token_is (parser, CPP_COMMA)) |
8830 | { | |
8831 | struct c_parm *parm; | |
8832 | c_parser_consume_token (parser); | |
8833 | if (c_parser_next_token_is (parser, CPP_ELLIPSIS)) | |
8834 | { | |
8835 | ellipsis = true; | |
8836 | c_parser_consume_token (parser); | |
03fc2271 | 8837 | attr_err |= c_parser_objc_maybe_method_attributes |
8838 | (parser, attributes) ; | |
1576dec7 | 8839 | break; |
8840 | } | |
8841 | parm = c_parser_parameter_declaration (parser, NULL_TREE); | |
8842 | if (parm == NULL) | |
8843 | break; | |
8844 | parms = chainon (parms, | |
4232a958 | 8845 | build_tree_list (NULL_TREE, grokparm (parm, expr))); |
1576dec7 | 8846 | } |
1576dec7 | 8847 | sel = list; |
8848 | } | |
03fc2271 | 8849 | else |
8850 | attr_err |= c_parser_objc_maybe_method_attributes (parser, attributes) ; | |
8851 | ||
8852 | if (sel == NULL) | |
8853 | { | |
8854 | c_parser_error (parser, "objective-c method declaration is expected"); | |
8855 | return error_mark_node; | |
8856 | } | |
8857 | ||
8858 | if (attr_err) | |
8859 | return error_mark_node; | |
8860 | ||
45b2b110 | 8861 | return objc_build_method_signature (is_class_method, type, sel, parms, ellipsis); |
1576dec7 | 8862 | } |
8863 | ||
8864 | /* Parse an objc-type-name. | |
8865 | ||
8866 | objc-type-name: | |
8867 | objc-type-qualifiers[opt] type-name | |
8868 | objc-type-qualifiers[opt] | |
8869 | ||
8870 | objc-type-qualifiers: | |
8871 | objc-type-qualifier | |
8872 | objc-type-qualifiers objc-type-qualifier | |
8873 | ||
8874 | objc-type-qualifier: one of | |
8875 | in out inout bycopy byref oneway | |
8876 | */ | |
8877 | ||
8878 | static tree | |
8879 | c_parser_objc_type_name (c_parser *parser) | |
8880 | { | |
8881 | tree quals = NULL_TREE; | |
7d339f93 | 8882 | struct c_type_name *type_name = NULL; |
1576dec7 | 8883 | tree type = NULL_TREE; |
8884 | while (true) | |
8885 | { | |
8886 | c_token *token = c_parser_peek_token (parser); | |
8887 | if (token->type == CPP_KEYWORD | |
8888 | && (token->keyword == RID_IN | |
8889 | || token->keyword == RID_OUT | |
8890 | || token->keyword == RID_INOUT | |
8891 | || token->keyword == RID_BYCOPY | |
8892 | || token->keyword == RID_BYREF | |
8893 | || token->keyword == RID_ONEWAY)) | |
8894 | { | |
dd26ec9b | 8895 | quals = chainon (build_tree_list (NULL_TREE, token->value), quals); |
1576dec7 | 8896 | c_parser_consume_token (parser); |
8897 | } | |
8898 | else | |
8899 | break; | |
8900 | } | |
26ee9e7a | 8901 | if (c_parser_next_tokens_start_typename (parser, cla_prefer_type)) |
7d339f93 | 8902 | type_name = c_parser_type_name (parser); |
8903 | if (type_name) | |
a75b1c71 | 8904 | type = groktypename (type_name, NULL, NULL); |
14a3bc63 | 8905 | |
8906 | /* If the type is unknown, and error has already been produced and | |
8907 | we need to recover from the error. In that case, use NULL_TREE | |
8908 | for the type, as if no type had been specified; this will use the | |
8909 | default type ('id') which is good for error recovery. */ | |
8910 | if (type == error_mark_node) | |
8911 | type = NULL_TREE; | |
8912 | ||
1576dec7 | 8913 | return build_tree_list (quals, type); |
8914 | } | |
8915 | ||
8916 | /* Parse objc-protocol-refs. | |
8917 | ||
8918 | objc-protocol-refs: | |
8919 | < identifier-list > | |
8920 | */ | |
8921 | ||
8922 | static tree | |
8923 | c_parser_objc_protocol_refs (c_parser *parser) | |
8924 | { | |
8925 | tree list = NULL_TREE; | |
8926 | gcc_assert (c_parser_next_token_is (parser, CPP_LESS)); | |
8927 | c_parser_consume_token (parser); | |
8928 | /* Any identifiers, including those declared as type names, are OK | |
8929 | here. */ | |
8930 | while (true) | |
8931 | { | |
8932 | tree id; | |
8933 | if (c_parser_next_token_is_not (parser, CPP_NAME)) | |
8934 | { | |
8935 | c_parser_error (parser, "expected identifier"); | |
8936 | break; | |
8937 | } | |
8938 | id = c_parser_peek_token (parser)->value; | |
8939 | list = chainon (list, build_tree_list (NULL_TREE, id)); | |
8940 | c_parser_consume_token (parser); | |
8941 | if (c_parser_next_token_is (parser, CPP_COMMA)) | |
8942 | c_parser_consume_token (parser); | |
8943 | else | |
8944 | break; | |
8945 | } | |
8946 | c_parser_require (parser, CPP_GREATER, "expected %<>%>"); | |
8947 | return list; | |
8948 | } | |
8949 | ||
b3d2d312 | 8950 | /* Parse an objc-try-catch-finally-statement. |
1576dec7 | 8951 | |
b3d2d312 | 8952 | objc-try-catch-finally-statement: |
1576dec7 | 8953 | @try compound-statement objc-catch-list[opt] |
8954 | @try compound-statement objc-catch-list[opt] @finally compound-statement | |
8955 | ||
8956 | objc-catch-list: | |
b3d2d312 | 8957 | @catch ( objc-catch-parameter-declaration ) compound-statement |
8958 | objc-catch-list @catch ( objc-catch-parameter-declaration ) compound-statement | |
8959 | ||
8960 | objc-catch-parameter-declaration: | |
8961 | parameter-declaration | |
8962 | '...' | |
8963 | ||
8964 | where '...' is to be interpreted literally, that is, it means CPP_ELLIPSIS. | |
8965 | ||
8966 | PS: This function is identical to cp_parser_objc_try_catch_finally_statement | |
8967 | for C++. Keep them in sync. */ | |
1576dec7 | 8968 | |
8969 | static void | |
b3d2d312 | 8970 | c_parser_objc_try_catch_finally_statement (c_parser *parser) |
1576dec7 | 8971 | { |
b3d2d312 | 8972 | location_t location; |
1576dec7 | 8973 | tree stmt; |
b3d2d312 | 8974 | |
e5c75ac3 | 8975 | gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_TRY)); |
1576dec7 | 8976 | c_parser_consume_token (parser); |
b3d2d312 | 8977 | location = c_parser_peek_token (parser)->location; |
33b3681f | 8978 | objc_maybe_warn_exceptions (location); |
1576dec7 | 8979 | stmt = c_parser_compound_statement (parser); |
b3d2d312 | 8980 | objc_begin_try_stmt (location, stmt); |
8981 | ||
e5c75ac3 | 8982 | while (c_parser_next_token_is_keyword (parser, RID_AT_CATCH)) |
1576dec7 | 8983 | { |
8984 | struct c_parm *parm; | |
b3d2d312 | 8985 | tree parameter_declaration = error_mark_node; |
8986 | bool seen_open_paren = false; | |
8987 | ||
1576dec7 | 8988 | c_parser_consume_token (parser); |
8989 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
b3d2d312 | 8990 | seen_open_paren = true; |
8991 | if (c_parser_next_token_is (parser, CPP_ELLIPSIS)) | |
1576dec7 | 8992 | { |
b3d2d312 | 8993 | /* We have "@catch (...)" (where the '...' are literally |
8994 | what is in the code). Skip the '...'. | |
8995 | parameter_declaration is set to NULL_TREE, and | |
8996 | objc_being_catch_clauses() knows that that means | |
8997 | '...'. */ | |
8998 | c_parser_consume_token (parser); | |
8999 | parameter_declaration = NULL_TREE; | |
1576dec7 | 9000 | } |
b3d2d312 | 9001 | else |
9002 | { | |
9003 | /* We have "@catch (NSException *exception)" or something | |
9004 | like that. Parse the parameter declaration. */ | |
9005 | parm = c_parser_parameter_declaration (parser, NULL_TREE); | |
9006 | if (parm == NULL) | |
9007 | parameter_declaration = error_mark_node; | |
9008 | else | |
4232a958 | 9009 | parameter_declaration = grokparm (parm, NULL); |
b3d2d312 | 9010 | } |
9011 | if (seen_open_paren) | |
9012 | c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
9013 | else | |
9014 | { | |
9015 | /* If there was no open parenthesis, we are recovering from | |
9016 | an error, and we are trying to figure out what mistake | |
9017 | the user has made. */ | |
9018 | ||
9019 | /* If there is an immediate closing parenthesis, the user | |
9020 | probably forgot the opening one (ie, they typed "@catch | |
9021 | NSException *e)". Parse the closing parenthesis and keep | |
9022 | going. */ | |
9023 | if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) | |
9024 | c_parser_consume_token (parser); | |
9025 | ||
9026 | /* If these is no immediate closing parenthesis, the user | |
9027 | probably doesn't know that parenthesis are required at | |
9028 | all (ie, they typed "@catch NSException *e"). So, just | |
9029 | forget about the closing parenthesis and keep going. */ | |
9030 | } | |
9031 | objc_begin_catch_clause (parameter_declaration); | |
1576dec7 | 9032 | if (c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>")) |
9033 | c_parser_compound_statement_nostart (parser); | |
9034 | objc_finish_catch_clause (); | |
9035 | } | |
9036 | if (c_parser_next_token_is_keyword (parser, RID_AT_FINALLY)) | |
9037 | { | |
1576dec7 | 9038 | c_parser_consume_token (parser); |
b3d2d312 | 9039 | location = c_parser_peek_token (parser)->location; |
9040 | stmt = c_parser_compound_statement (parser); | |
9041 | objc_build_finally_clause (location, stmt); | |
1576dec7 | 9042 | } |
9043 | objc_finish_try_stmt (); | |
9044 | } | |
9045 | ||
9046 | /* Parse an objc-synchronized-statement. | |
9047 | ||
9048 | objc-synchronized-statement: | |
9049 | @synchronized ( expression ) compound-statement | |
9050 | */ | |
9051 | ||
9052 | static void | |
9053 | c_parser_objc_synchronized_statement (c_parser *parser) | |
9054 | { | |
9055 | location_t loc; | |
9056 | tree expr, stmt; | |
9057 | gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_SYNCHRONIZED)); | |
9058 | c_parser_consume_token (parser); | |
9059 | loc = c_parser_peek_token (parser)->location; | |
33b3681f | 9060 | objc_maybe_warn_exceptions (loc); |
1576dec7 | 9061 | if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) |
9062 | { | |
b560fabd | 9063 | struct c_expr ce = c_parser_expression (parser); |
9064 | ce = convert_lvalue_to_rvalue (loc, ce, false, false); | |
9065 | expr = ce.value; | |
a75b1c71 | 9066 | expr = c_fully_fold (expr, false, NULL); |
1576dec7 | 9067 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); |
9068 | } | |
9069 | else | |
9070 | expr = error_mark_node; | |
9071 | stmt = c_parser_compound_statement (parser); | |
9072 | objc_build_synchronized (loc, expr, stmt); | |
9073 | } | |
9074 | ||
9075 | /* Parse an objc-selector; return NULL_TREE without an error if the | |
9076 | next token is not an objc-selector. | |
9077 | ||
9078 | objc-selector: | |
9079 | identifier | |
9080 | one of | |
9081 | enum struct union if else while do for switch case default | |
9082 | break continue return goto asm sizeof typeof __alignof | |
9083 | unsigned long const short volatile signed restrict _Complex | |
9084 | in out inout bycopy byref oneway int char float double void _Bool | |
b560fabd | 9085 | _Atomic |
1576dec7 | 9086 | |
9087 | ??? Why this selection of keywords but not, for example, storage | |
9088 | class specifiers? */ | |
9089 | ||
9090 | static tree | |
9091 | c_parser_objc_selector (c_parser *parser) | |
9092 | { | |
9093 | c_token *token = c_parser_peek_token (parser); | |
9094 | tree value = token->value; | |
9095 | if (token->type == CPP_NAME) | |
9096 | { | |
9097 | c_parser_consume_token (parser); | |
9098 | return value; | |
9099 | } | |
9100 | if (token->type != CPP_KEYWORD) | |
9101 | return NULL_TREE; | |
9102 | switch (token->keyword) | |
9103 | { | |
9104 | case RID_ENUM: | |
9105 | case RID_STRUCT: | |
9106 | case RID_UNION: | |
9107 | case RID_IF: | |
9108 | case RID_ELSE: | |
9109 | case RID_WHILE: | |
9110 | case RID_DO: | |
9111 | case RID_FOR: | |
9112 | case RID_SWITCH: | |
9113 | case RID_CASE: | |
9114 | case RID_DEFAULT: | |
9115 | case RID_BREAK: | |
9116 | case RID_CONTINUE: | |
9117 | case RID_RETURN: | |
9118 | case RID_GOTO: | |
9119 | case RID_ASM: | |
9120 | case RID_SIZEOF: | |
9121 | case RID_TYPEOF: | |
9122 | case RID_ALIGNOF: | |
9123 | case RID_UNSIGNED: | |
9124 | case RID_LONG: | |
9125 | case RID_CONST: | |
9126 | case RID_SHORT: | |
9127 | case RID_VOLATILE: | |
9128 | case RID_SIGNED: | |
9129 | case RID_RESTRICT: | |
9130 | case RID_COMPLEX: | |
9131 | case RID_IN: | |
9132 | case RID_OUT: | |
9133 | case RID_INOUT: | |
9134 | case RID_BYCOPY: | |
9135 | case RID_BYREF: | |
9136 | case RID_ONEWAY: | |
9137 | case RID_INT: | |
9138 | case RID_CHAR: | |
9139 | case RID_FLOAT: | |
9140 | case RID_DOUBLE: | |
9141 | case RID_VOID: | |
9142 | case RID_BOOL: | |
b560fabd | 9143 | case RID_ATOMIC: |
4fba5eb9 | 9144 | case RID_AUTO_TYPE: |
9f75f026 | 9145 | case RID_INT_N_0: |
9146 | case RID_INT_N_1: | |
9147 | case RID_INT_N_2: | |
9148 | case RID_INT_N_3: | |
1576dec7 | 9149 | c_parser_consume_token (parser); |
9150 | return value; | |
9151 | default: | |
9152 | return NULL_TREE; | |
9153 | } | |
9154 | } | |
9155 | ||
9156 | /* Parse an objc-selector-arg. | |
9157 | ||
9158 | objc-selector-arg: | |
9159 | objc-selector | |
9160 | objc-keywordname-list | |
9161 | ||
9162 | objc-keywordname-list: | |
9163 | objc-keywordname | |
9164 | objc-keywordname-list objc-keywordname | |
9165 | ||
9166 | objc-keywordname: | |
9167 | objc-selector : | |
9168 | : | |
9169 | */ | |
9170 | ||
9171 | static tree | |
9172 | c_parser_objc_selector_arg (c_parser *parser) | |
9173 | { | |
9174 | tree sel = c_parser_objc_selector (parser); | |
9175 | tree list = NULL_TREE; | |
9176 | if (sel && c_parser_next_token_is_not (parser, CPP_COLON)) | |
9177 | return sel; | |
9178 | while (true) | |
9179 | { | |
9180 | if (!c_parser_require (parser, CPP_COLON, "expected %<:%>")) | |
9181 | return list; | |
9182 | list = chainon (list, build_tree_list (sel, NULL_TREE)); | |
9183 | sel = c_parser_objc_selector (parser); | |
9184 | if (!sel && c_parser_next_token_is_not (parser, CPP_COLON)) | |
9185 | break; | |
9186 | } | |
9187 | return list; | |
9188 | } | |
9189 | ||
9190 | /* Parse an objc-receiver. | |
9191 | ||
9192 | objc-receiver: | |
9193 | expression | |
9194 | class-name | |
9195 | type-name | |
9196 | */ | |
9197 | ||
9198 | static tree | |
9199 | c_parser_objc_receiver (c_parser *parser) | |
9200 | { | |
b560fabd | 9201 | location_t loc = c_parser_peek_token (parser)->location; |
9202 | ||
1576dec7 | 9203 | if (c_parser_peek_token (parser)->type == CPP_NAME |
9204 | && (c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME | |
9205 | || c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME)) | |
9206 | { | |
9207 | tree id = c_parser_peek_token (parser)->value; | |
9208 | c_parser_consume_token (parser); | |
9209 | return objc_get_class_reference (id); | |
9210 | } | |
b560fabd | 9211 | struct c_expr ce = c_parser_expression (parser); |
9212 | ce = convert_lvalue_to_rvalue (loc, ce, false, false); | |
9213 | return c_fully_fold (ce.value, false, NULL); | |
1576dec7 | 9214 | } |
9215 | ||
9216 | /* Parse objc-message-args. | |
9217 | ||
9218 | objc-message-args: | |
9219 | objc-selector | |
9220 | objc-keywordarg-list | |
9221 | ||
9222 | objc-keywordarg-list: | |
9223 | objc-keywordarg | |
9224 | objc-keywordarg-list objc-keywordarg | |
9225 | ||
9226 | objc-keywordarg: | |
9227 | objc-selector : objc-keywordexpr | |
9228 | : objc-keywordexpr | |
9229 | */ | |
9230 | ||
9231 | static tree | |
9232 | c_parser_objc_message_args (c_parser *parser) | |
9233 | { | |
9234 | tree sel = c_parser_objc_selector (parser); | |
9235 | tree list = NULL_TREE; | |
9236 | if (sel && c_parser_next_token_is_not (parser, CPP_COLON)) | |
9237 | return sel; | |
9238 | while (true) | |
9239 | { | |
9240 | tree keywordexpr; | |
9241 | if (!c_parser_require (parser, CPP_COLON, "expected %<:%>")) | |
61a9d3ca | 9242 | return error_mark_node; |
1576dec7 | 9243 | keywordexpr = c_parser_objc_keywordexpr (parser); |
9244 | list = chainon (list, build_tree_list (sel, keywordexpr)); | |
9245 | sel = c_parser_objc_selector (parser); | |
9246 | if (!sel && c_parser_next_token_is_not (parser, CPP_COLON)) | |
9247 | break; | |
9248 | } | |
9249 | return list; | |
9250 | } | |
9251 | ||
9252 | /* Parse an objc-keywordexpr. | |
9253 | ||
9254 | objc-keywordexpr: | |
9255 | nonempty-expr-list | |
9256 | */ | |
9257 | ||
9258 | static tree | |
9259 | c_parser_objc_keywordexpr (c_parser *parser) | |
9260 | { | |
b9c74b4d | 9261 | tree ret; |
f1f41a6c | 9262 | vec<tree, va_gc> *expr_list = c_parser_expr_list (parser, true, true, |
ec761d5a | 9263 | NULL, NULL, NULL, NULL); |
f1f41a6c | 9264 | if (vec_safe_length (expr_list) == 1) |
1576dec7 | 9265 | { |
9266 | /* Just return the expression, remove a level of | |
9267 | indirection. */ | |
f1f41a6c | 9268 | ret = (*expr_list)[0]; |
1576dec7 | 9269 | } |
9270 | else | |
9271 | { | |
9272 | /* We have a comma expression, we will collapse later. */ | |
f352a3fb | 9273 | ret = build_tree_list_vec (expr_list); |
1576dec7 | 9274 | } |
f352a3fb | 9275 | release_tree_vector (expr_list); |
b9c74b4d | 9276 | return ret; |
1576dec7 | 9277 | } |
9278 | ||
a336eb4b | 9279 | /* A check, needed in several places, that ObjC interface, implementation or |
9280 | method definitions are not prefixed by incorrect items. */ | |
9281 | static bool | |
9282 | c_parser_objc_diagnose_bad_element_prefix (c_parser *parser, | |
9283 | struct c_declspecs *specs) | |
9284 | { | |
ae5ead32 | 9285 | if (!specs->declspecs_seen_p || specs->non_sc_seen_p |
9286 | || specs->typespec_kind != ctsk_none) | |
a336eb4b | 9287 | { |
9288 | c_parser_error (parser, | |
9289 | "no type or storage class may be specified here,"); | |
9290 | c_parser_skip_to_end_of_block_or_statement (parser); | |
9291 | return true; | |
9292 | } | |
9293 | return false; | |
9294 | } | |
86c110ac | 9295 | |
1d894bcf | 9296 | /* Parse an Objective-C @property declaration. The syntax is: |
86c110ac | 9297 | |
1d894bcf | 9298 | objc-property-declaration: |
9299 | '@property' objc-property-attributes[opt] struct-declaration ; | |
86c110ac | 9300 | |
1d894bcf | 9301 | objc-property-attributes: |
9302 | '(' objc-property-attribute-list ')' | |
9303 | ||
9304 | objc-property-attribute-list: | |
9305 | objc-property-attribute | |
9306 | objc-property-attribute-list, objc-property-attribute | |
9307 | ||
9308 | objc-property-attribute | |
9309 | 'getter' = identifier | |
9310 | 'setter' = identifier | |
9311 | 'readonly' | |
9312 | 'readwrite' | |
9313 | 'assign' | |
9314 | 'retain' | |
9315 | 'copy' | |
9316 | 'nonatomic' | |
9317 | ||
9318 | For example: | |
9319 | @property NSString *name; | |
9320 | @property (readonly) id object; | |
9321 | @property (retain, nonatomic, getter=getTheName) id name; | |
9322 | @property int a, b, c; | |
9323 | ||
9324 | PS: This function is identical to cp_parser_objc_at_propery_declaration | |
7590f0e5 | 9325 | for C++. Keep them in sync. */ |
86c110ac | 9326 | static void |
1d894bcf | 9327 | c_parser_objc_at_property_declaration (c_parser *parser) |
86c110ac | 9328 | { |
7590f0e5 | 9329 | /* The following variables hold the attributes of the properties as |
9330 | parsed. They are 'false' or 'NULL_TREE' if the attribute was not | |
9331 | seen. When we see an attribute, we set them to 'true' (if they | |
9332 | are boolean properties) or to the identifier (if they have an | |
9333 | argument, ie, for getter and setter). Note that here we only | |
9334 | parse the list of attributes, check the syntax and accumulate the | |
9335 | attributes that we find. objc_add_property_declaration() will | |
9336 | then process the information. */ | |
9337 | bool property_assign = false; | |
9338 | bool property_copy = false; | |
9339 | tree property_getter_ident = NULL_TREE; | |
9340 | bool property_nonatomic = false; | |
9341 | bool property_readonly = false; | |
9342 | bool property_readwrite = false; | |
9343 | bool property_retain = false; | |
9344 | tree property_setter_ident = NULL_TREE; | |
7590f0e5 | 9345 | |
9346 | /* 'properties' is the list of properties that we read. Usually a | |
9347 | single one, but maybe more (eg, in "@property int a, b, c;" there | |
9348 | are three). */ | |
1d894bcf | 9349 | tree properties; |
9350 | location_t loc; | |
7590f0e5 | 9351 | |
1d894bcf | 9352 | loc = c_parser_peek_token (parser)->location; |
9353 | gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_PROPERTY)); | |
86c110ac | 9354 | |
1d894bcf | 9355 | c_parser_consume_token (parser); /* Eat '@property'. */ |
86c110ac | 9356 | |
1d894bcf | 9357 | /* Parse the optional attribute list... */ |
9358 | if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) | |
86c110ac | 9359 | { |
1d894bcf | 9360 | /* Eat the '(' */ |
9361 | c_parser_consume_token (parser); | |
9362 | ||
9363 | /* Property attribute keywords are valid now. */ | |
9364 | parser->objc_property_attr_context = true; | |
9365 | ||
9366 | while (true) | |
86c110ac | 9367 | { |
1d894bcf | 9368 | bool syntax_error = false; |
9369 | c_token *token = c_parser_peek_token (parser); | |
9370 | enum rid keyword; | |
9371 | ||
9372 | if (token->type != CPP_KEYWORD) | |
9373 | { | |
9374 | if (token->type == CPP_CLOSE_PAREN) | |
9375 | c_parser_error (parser, "expected identifier"); | |
9376 | else | |
9377 | { | |
9378 | c_parser_consume_token (parser); | |
9379 | c_parser_error (parser, "unknown property attribute"); | |
9380 | } | |
9381 | break; | |
9382 | } | |
9383 | keyword = token->keyword; | |
7590f0e5 | 9384 | c_parser_consume_token (parser); |
1d894bcf | 9385 | switch (keyword) |
9386 | { | |
7590f0e5 | 9387 | case RID_ASSIGN: property_assign = true; break; |
7590f0e5 | 9388 | case RID_COPY: property_copy = true; break; |
9389 | case RID_NONATOMIC: property_nonatomic = true; break; | |
9390 | case RID_READONLY: property_readonly = true; break; | |
9391 | case RID_READWRITE: property_readwrite = true; break; | |
9392 | case RID_RETAIN: property_retain = true; break; | |
9393 | ||
1d894bcf | 9394 | case RID_GETTER: |
9395 | case RID_SETTER: | |
1d894bcf | 9396 | if (c_parser_next_token_is_not (parser, CPP_EQ)) |
9397 | { | |
ffbb3d61 | 9398 | if (keyword == RID_GETTER) |
9399 | c_parser_error (parser, | |
9400 | "missing %<=%> (after %<getter%> attribute)"); | |
9401 | else | |
9402 | c_parser_error (parser, | |
9403 | "missing %<=%> (after %<setter%> attribute)"); | |
1d894bcf | 9404 | syntax_error = true; |
9405 | break; | |
9406 | } | |
9407 | c_parser_consume_token (parser); /* eat the = */ | |
9408 | if (c_parser_next_token_is_not (parser, CPP_NAME)) | |
9409 | { | |
9410 | c_parser_error (parser, "expected identifier"); | |
9411 | syntax_error = true; | |
9412 | break; | |
9413 | } | |
1d894bcf | 9414 | if (keyword == RID_SETTER) |
9415 | { | |
7590f0e5 | 9416 | if (property_setter_ident != NULL_TREE) |
9417 | c_parser_error (parser, "the %<setter%> attribute may only be specified once"); | |
9418 | else | |
9419 | property_setter_ident = c_parser_peek_token (parser)->value; | |
1d894bcf | 9420 | c_parser_consume_token (parser); |
7590f0e5 | 9421 | if (c_parser_next_token_is_not (parser, CPP_COLON)) |
9422 | c_parser_error (parser, "setter name must terminate with %<:%>"); | |
9423 | else | |
9424 | c_parser_consume_token (parser); | |
1d894bcf | 9425 | } |
9d9f5bb3 | 9426 | else |
1d894bcf | 9427 | { |
7590f0e5 | 9428 | if (property_getter_ident != NULL_TREE) |
9429 | c_parser_error (parser, "the %<getter%> attribute may only be specified once"); | |
9430 | else | |
9431 | property_getter_ident = c_parser_peek_token (parser)->value; | |
1d894bcf | 9432 | c_parser_consume_token (parser); |
1d894bcf | 9433 | } |
7590f0e5 | 9434 | break; |
9435 | default: | |
9436 | c_parser_error (parser, "unknown property attribute"); | |
1d894bcf | 9437 | syntax_error = true; |
9438 | break; | |
9439 | } | |
9440 | ||
9441 | if (syntax_error) | |
86c110ac | 9442 | break; |
1d894bcf | 9443 | |
9444 | if (c_parser_next_token_is (parser, CPP_COMMA)) | |
86c110ac | 9445 | c_parser_consume_token (parser); |
1d894bcf | 9446 | else |
86c110ac | 9447 | break; |
9448 | } | |
1d894bcf | 9449 | parser->objc_property_attr_context = false; |
9450 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
9451 | } | |
9452 | /* ... and the property declaration(s). */ | |
9453 | properties = c_parser_struct_declaration (parser); | |
86c110ac | 9454 | |
1d894bcf | 9455 | if (properties == error_mark_node) |
9456 | { | |
9457 | c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL); | |
9458 | parser->error = false; | |
9459 | return; | |
9460 | } | |
86c110ac | 9461 | |
1d894bcf | 9462 | if (properties == NULL_TREE) |
9463 | c_parser_error (parser, "expected identifier"); | |
9464 | else | |
9465 | { | |
9466 | /* Comma-separated properties are chained together in | |
9467 | reverse order; add them one by one. */ | |
9468 | properties = nreverse (properties); | |
9469 | ||
9470 | for (; properties; properties = TREE_CHAIN (properties)) | |
7590f0e5 | 9471 | objc_add_property_declaration (loc, copy_node (properties), |
9472 | property_readonly, property_readwrite, | |
9473 | property_assign, property_retain, | |
9474 | property_copy, property_nonatomic, | |
9d9f5bb3 | 9475 | property_getter_ident, property_setter_ident); |
1d894bcf | 9476 | } |
86c110ac | 9477 | |
9478 | c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); | |
1d894bcf | 9479 | parser->error = false; |
86c110ac | 9480 | } |
9481 | ||
e1f293c0 | 9482 | /* Parse an Objective-C @synthesize declaration. The syntax is: |
9483 | ||
9484 | objc-synthesize-declaration: | |
9485 | @synthesize objc-synthesize-identifier-list ; | |
9486 | ||
9487 | objc-synthesize-identifier-list: | |
9488 | objc-synthesize-identifier | |
9489 | objc-synthesize-identifier-list, objc-synthesize-identifier | |
9490 | ||
9491 | objc-synthesize-identifier | |
9492 | identifier | |
9493 | identifier = identifier | |
9494 | ||
9495 | For example: | |
9496 | @synthesize MyProperty; | |
9497 | @synthesize OneProperty, AnotherProperty=MyIvar, YetAnotherProperty; | |
9498 | ||
9499 | PS: This function is identical to cp_parser_objc_at_synthesize_declaration | |
9500 | for C++. Keep them in sync. | |
9501 | */ | |
9502 | static void | |
9503 | c_parser_objc_at_synthesize_declaration (c_parser *parser) | |
9504 | { | |
9505 | tree list = NULL_TREE; | |
9506 | location_t loc; | |
9507 | gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_SYNTHESIZE)); | |
9508 | loc = c_parser_peek_token (parser)->location; | |
9509 | ||
9510 | c_parser_consume_token (parser); | |
9511 | while (true) | |
9512 | { | |
9513 | tree property, ivar; | |
9514 | if (c_parser_next_token_is_not (parser, CPP_NAME)) | |
9515 | { | |
9516 | c_parser_error (parser, "expected identifier"); | |
9517 | c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL); | |
9518 | /* Once we find the semicolon, we can resume normal parsing. | |
9519 | We have to reset parser->error manually because | |
9520 | c_parser_skip_until_found() won't reset it for us if the | |
9521 | next token is precisely a semicolon. */ | |
9522 | parser->error = false; | |
9523 | return; | |
9524 | } | |
9525 | property = c_parser_peek_token (parser)->value; | |
9526 | c_parser_consume_token (parser); | |
9527 | if (c_parser_next_token_is (parser, CPP_EQ)) | |
9528 | { | |
9529 | c_parser_consume_token (parser); | |
9530 | if (c_parser_next_token_is_not (parser, CPP_NAME)) | |
9531 | { | |
9532 | c_parser_error (parser, "expected identifier"); | |
9533 | c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL); | |
9534 | parser->error = false; | |
9535 | return; | |
9536 | } | |
9537 | ivar = c_parser_peek_token (parser)->value; | |
9538 | c_parser_consume_token (parser); | |
9539 | } | |
9540 | else | |
9541 | ivar = NULL_TREE; | |
9542 | list = chainon (list, build_tree_list (ivar, property)); | |
9543 | if (c_parser_next_token_is (parser, CPP_COMMA)) | |
9544 | c_parser_consume_token (parser); | |
9545 | else | |
9546 | break; | |
9547 | } | |
9548 | c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); | |
9549 | objc_add_synthesize_declaration (loc, list); | |
9550 | } | |
9551 | ||
9552 | /* Parse an Objective-C @dynamic declaration. The syntax is: | |
9553 | ||
9554 | objc-dynamic-declaration: | |
9555 | @dynamic identifier-list ; | |
9556 | ||
9557 | For example: | |
9558 | @dynamic MyProperty; | |
9559 | @dynamic MyProperty, AnotherProperty; | |
9560 | ||
9561 | PS: This function is identical to cp_parser_objc_at_dynamic_declaration | |
9562 | for C++. Keep them in sync. | |
9563 | */ | |
9564 | static void | |
9565 | c_parser_objc_at_dynamic_declaration (c_parser *parser) | |
9566 | { | |
9567 | tree list = NULL_TREE; | |
9568 | location_t loc; | |
9569 | gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_DYNAMIC)); | |
9570 | loc = c_parser_peek_token (parser)->location; | |
9571 | ||
9572 | c_parser_consume_token (parser); | |
9573 | while (true) | |
9574 | { | |
9575 | tree property; | |
9576 | if (c_parser_next_token_is_not (parser, CPP_NAME)) | |
9577 | { | |
9578 | c_parser_error (parser, "expected identifier"); | |
9579 | c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL); | |
9580 | parser->error = false; | |
9581 | return; | |
9582 | } | |
9583 | property = c_parser_peek_token (parser)->value; | |
9584 | list = chainon (list, build_tree_list (NULL_TREE, property)); | |
9585 | c_parser_consume_token (parser); | |
9586 | if (c_parser_next_token_is (parser, CPP_COMMA)) | |
9587 | c_parser_consume_token (parser); | |
9588 | else | |
9589 | break; | |
9590 | } | |
9591 | c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); | |
9592 | objc_add_dynamic_declaration (loc, list); | |
9593 | } | |
9594 | ||
1576dec7 | 9595 | \f |
1e8e9920 | 9596 | /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore |
9597 | should be considered, statements. ALLOW_STMT is true if we're within | |
9598 | the context of a function and such pragmas are to be allowed. Returns | |
9599 | true if we actually parsed such a pragma. */ | |
1576dec7 | 9600 | |
b75b98aa | 9601 | static bool |
1e8e9920 | 9602 | c_parser_pragma (c_parser *parser, enum pragma_context context) |
b75b98aa | 9603 | { |
9604 | unsigned int id; | |
9605 | ||
9606 | id = c_parser_peek_token (parser)->pragma_kind; | |
9607 | gcc_assert (id != PRAGMA_NONE); | |
9608 | ||
9609 | switch (id) | |
9610 | { | |
ca4c3545 | 9611 | case PRAGMA_OACC_ENTER_DATA: |
9612 | c_parser_oacc_enter_exit_data (parser, true); | |
9613 | return false; | |
9614 | ||
9615 | case PRAGMA_OACC_EXIT_DATA: | |
9616 | c_parser_oacc_enter_exit_data (parser, false); | |
9617 | return false; | |
9618 | ||
9619 | case PRAGMA_OACC_UPDATE: | |
9620 | if (context != pragma_compound) | |
9621 | { | |
9622 | if (context == pragma_stmt) | |
9623 | c_parser_error (parser, "%<#pragma acc update%> may only be " | |
9624 | "used in compound statements"); | |
9625 | goto bad_stmt; | |
9626 | } | |
9627 | c_parser_oacc_update (parser); | |
9628 | return false; | |
9629 | ||
1e8e9920 | 9630 | case PRAGMA_OMP_BARRIER: |
9631 | if (context != pragma_compound) | |
9632 | { | |
9633 | if (context == pragma_stmt) | |
9634 | c_parser_error (parser, "%<#pragma omp barrier%> may only be " | |
9635 | "used in compound statements"); | |
9636 | goto bad_stmt; | |
9637 | } | |
9638 | c_parser_omp_barrier (parser); | |
9639 | return false; | |
9640 | ||
9641 | case PRAGMA_OMP_FLUSH: | |
9642 | if (context != pragma_compound) | |
9643 | { | |
9644 | if (context == pragma_stmt) | |
9645 | c_parser_error (parser, "%<#pragma omp flush%> may only be " | |
9646 | "used in compound statements"); | |
9647 | goto bad_stmt; | |
9648 | } | |
9649 | c_parser_omp_flush (parser); | |
9650 | return false; | |
9651 | ||
fd6481cf | 9652 | case PRAGMA_OMP_TASKWAIT: |
9653 | if (context != pragma_compound) | |
9654 | { | |
9655 | if (context == pragma_stmt) | |
9656 | c_parser_error (parser, "%<#pragma omp taskwait%> may only be " | |
9657 | "used in compound statements"); | |
9658 | goto bad_stmt; | |
9659 | } | |
9660 | c_parser_omp_taskwait (parser); | |
9661 | return false; | |
9662 | ||
2169f33b | 9663 | case PRAGMA_OMP_TASKYIELD: |
9664 | if (context != pragma_compound) | |
9665 | { | |
9666 | if (context == pragma_stmt) | |
9667 | c_parser_error (parser, "%<#pragma omp taskyield%> may only be " | |
9668 | "used in compound statements"); | |
9669 | goto bad_stmt; | |
9670 | } | |
9671 | c_parser_omp_taskyield (parser); | |
9672 | return false; | |
9673 | ||
bc7bff74 | 9674 | case PRAGMA_OMP_CANCEL: |
9675 | if (context != pragma_compound) | |
9676 | { | |
9677 | if (context == pragma_stmt) | |
9678 | c_parser_error (parser, "%<#pragma omp cancel%> may only be " | |
9679 | "used in compound statements"); | |
9680 | goto bad_stmt; | |
9681 | } | |
9682 | c_parser_omp_cancel (parser); | |
9683 | return false; | |
9684 | ||
9685 | case PRAGMA_OMP_CANCELLATION_POINT: | |
9686 | if (context != pragma_compound) | |
9687 | { | |
9688 | if (context == pragma_stmt) | |
9689 | c_parser_error (parser, "%<#pragma omp cancellation point%> may " | |
9690 | "only be used in compound statements"); | |
9691 | goto bad_stmt; | |
9692 | } | |
9693 | c_parser_omp_cancellation_point (parser); | |
9694 | return false; | |
9695 | ||
1e8e9920 | 9696 | case PRAGMA_OMP_THREADPRIVATE: |
9697 | c_parser_omp_threadprivate (parser); | |
9698 | return false; | |
9699 | ||
bc7bff74 | 9700 | case PRAGMA_OMP_TARGET: |
9701 | return c_parser_omp_target (parser, context); | |
9702 | ||
9703 | case PRAGMA_OMP_END_DECLARE_TARGET: | |
9704 | c_parser_omp_end_declare_target (parser); | |
9705 | return false; | |
9706 | ||
1e8e9920 | 9707 | case PRAGMA_OMP_SECTION: |
e3b80d49 | 9708 | error_at (c_parser_peek_token (parser)->location, |
9709 | "%<#pragma omp section%> may only be used in " | |
9710 | "%<#pragma omp sections%> construct"); | |
1e8e9920 | 9711 | c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL); |
9712 | return false; | |
9713 | ||
bc7bff74 | 9714 | case PRAGMA_OMP_DECLARE_REDUCTION: |
9715 | c_parser_omp_declare (parser, context); | |
9716 | return false; | |
4644b593 | 9717 | case PRAGMA_IVDEP: |
9718 | c_parser_consume_pragma (parser); | |
9719 | c_parser_skip_to_pragma_eol (parser); | |
4c90c04c | 9720 | if (!c_parser_next_token_is_keyword (parser, RID_FOR) |
9721 | && !c_parser_next_token_is_keyword (parser, RID_WHILE) | |
9722 | && !c_parser_next_token_is_keyword (parser, RID_DO)) | |
4644b593 | 9723 | { |
4c90c04c | 9724 | c_parser_error (parser, "for, while or do statement expected"); |
4644b593 | 9725 | return false; |
9726 | } | |
4c90c04c | 9727 | if (c_parser_next_token_is_keyword (parser, RID_FOR)) |
9728 | c_parser_for_statement (parser, true); | |
9729 | else if (c_parser_next_token_is_keyword (parser, RID_WHILE)) | |
9730 | c_parser_while_statement (parser, true); | |
9731 | else | |
9732 | c_parser_do_statement (parser, true); | |
4644b593 | 9733 | return false; |
bc7bff74 | 9734 | |
b75b98aa | 9735 | case PRAGMA_GCC_PCH_PREPROCESS: |
9736 | c_parser_error (parser, "%<#pragma GCC pch_preprocess%> must be first"); | |
9737 | c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL); | |
9738 | return false; | |
9739 | ||
f2697631 | 9740 | case PRAGMA_CILK_SIMD: |
9741 | if (!c_parser_cilk_verify_simd (parser, context)) | |
9742 | return false; | |
9743 | c_parser_consume_pragma (parser); | |
9744 | c_parser_cilk_simd (parser); | |
9745 | return false; | |
40750995 | 9746 | case PRAGMA_CILK_GRAINSIZE: |
9747 | if (!flag_cilkplus) | |
9748 | { | |
9749 | warning (0, "%<#pragma grainsize%> ignored because -fcilkplus is not" | |
9750 | " enabled"); | |
9751 | c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL); | |
9752 | return false; | |
9753 | } | |
9754 | if (context == pragma_external) | |
9755 | { | |
9756 | error_at (c_parser_peek_token (parser)->location, | |
9757 | "%<#pragma grainsize%> must be inside a function"); | |
9758 | c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL); | |
9759 | return false; | |
9760 | } | |
9761 | c_parser_cilk_grainsize (parser); | |
9762 | return false; | |
f2697631 | 9763 | |
b75b98aa | 9764 | default: |
1e8e9920 | 9765 | if (id < PRAGMA_FIRST_EXTERNAL) |
9766 | { | |
bc7bff74 | 9767 | if (context != pragma_stmt && context != pragma_compound) |
1e8e9920 | 9768 | { |
9769 | bad_stmt: | |
9770 | c_parser_error (parser, "expected declaration specifiers"); | |
9771 | c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL); | |
9772 | return false; | |
9773 | } | |
9774 | c_parser_omp_construct (parser); | |
9775 | return true; | |
9776 | } | |
b75b98aa | 9777 | break; |
9778 | } | |
9779 | ||
9780 | c_parser_consume_pragma (parser); | |
9781 | c_invoke_pragma_handler (id); | |
1576dec7 | 9782 | |
48e1416a | 9783 | /* Skip to EOL, but suppress any error message. Those will have been |
b75b98aa | 9784 | generated by the handler routine through calling error, as opposed |
9785 | to calling c_parser_error. */ | |
9786 | parser->error = true; | |
9787 | c_parser_skip_to_pragma_eol (parser); | |
9788 | ||
9789 | return false; | |
9790 | } | |
9791 | ||
9792 | /* The interface the pragma parsers have to the lexer. */ | |
9793 | ||
9794 | enum cpp_ttype | |
9795 | pragma_lex (tree *value) | |
9796 | { | |
9797 | c_token *tok = c_parser_peek_token (the_parser); | |
9798 | enum cpp_ttype ret = tok->type; | |
9799 | ||
9800 | *value = tok->value; | |
9801 | if (ret == CPP_PRAGMA_EOL || ret == CPP_EOF) | |
9802 | ret = CPP_EOF; | |
9803 | else | |
9804 | { | |
9805 | if (ret == CPP_KEYWORD) | |
9806 | ret = CPP_NAME; | |
9807 | c_parser_consume_token (the_parser); | |
9808 | } | |
9809 | ||
9810 | return ret; | |
9811 | } | |
9812 | ||
9813 | static void | |
9814 | c_parser_pragma_pch_preprocess (c_parser *parser) | |
9815 | { | |
9816 | tree name = NULL; | |
9817 | ||
9818 | c_parser_consume_pragma (parser); | |
9819 | if (c_parser_next_token_is (parser, CPP_STRING)) | |
9820 | { | |
9821 | name = c_parser_peek_token (parser)->value; | |
9822 | c_parser_consume_token (parser); | |
9823 | } | |
9824 | else | |
9825 | c_parser_error (parser, "expected string literal"); | |
9826 | c_parser_skip_to_pragma_eol (parser); | |
9827 | ||
9828 | if (name) | |
9829 | c_common_pch_pragma (parse_in, TREE_STRING_POINTER (name)); | |
9830 | } | |
1e8e9920 | 9831 | \f |
ca4c3545 | 9832 | /* OpenACC and OpenMP parsing routines. */ |
1e8e9920 | 9833 | |
9834 | /* Returns name of the next clause. | |
9835 | If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and | |
9836 | the token is not consumed. Otherwise appropriate pragma_omp_clause is | |
9837 | returned and the token is consumed. */ | |
9838 | ||
9839 | static pragma_omp_clause | |
9840 | c_parser_omp_clause_name (c_parser *parser) | |
9841 | { | |
9842 | pragma_omp_clause result = PRAGMA_OMP_CLAUSE_NONE; | |
9843 | ||
ca4c3545 | 9844 | if (c_parser_next_token_is_keyword (parser, RID_AUTO)) |
9845 | result = PRAGMA_OACC_CLAUSE_AUTO; | |
9846 | else if (c_parser_next_token_is_keyword (parser, RID_IF)) | |
1e8e9920 | 9847 | result = PRAGMA_OMP_CLAUSE_IF; |
9848 | else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT)) | |
9849 | result = PRAGMA_OMP_CLAUSE_DEFAULT; | |
bc7bff74 | 9850 | else if (c_parser_next_token_is_keyword (parser, RID_FOR)) |
9851 | result = PRAGMA_OMP_CLAUSE_FOR; | |
1e8e9920 | 9852 | else if (c_parser_next_token_is (parser, CPP_NAME)) |
9853 | { | |
9854 | const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); | |
9855 | ||
9856 | switch (p[0]) | |
9857 | { | |
bc7bff74 | 9858 | case 'a': |
9859 | if (!strcmp ("aligned", p)) | |
9860 | result = PRAGMA_OMP_CLAUSE_ALIGNED; | |
ca4c3545 | 9861 | else if (!strcmp ("async", p)) |
9862 | result = PRAGMA_OACC_CLAUSE_ASYNC; | |
bc7bff74 | 9863 | break; |
1e8e9920 | 9864 | case 'c': |
fd6481cf | 9865 | if (!strcmp ("collapse", p)) |
9866 | result = PRAGMA_OMP_CLAUSE_COLLAPSE; | |
ca4c3545 | 9867 | else if (!strcmp ("copy", p)) |
9868 | result = PRAGMA_OACC_CLAUSE_COPY; | |
fd6481cf | 9869 | else if (!strcmp ("copyin", p)) |
1e8e9920 | 9870 | result = PRAGMA_OMP_CLAUSE_COPYIN; |
ca4c3545 | 9871 | else if (!strcmp ("copyout", p)) |
9872 | result = PRAGMA_OACC_CLAUSE_COPYOUT; | |
1e8e9920 | 9873 | else if (!strcmp ("copyprivate", p)) |
9874 | result = PRAGMA_OMP_CLAUSE_COPYPRIVATE; | |
ca4c3545 | 9875 | else if (!strcmp ("create", p)) |
9876 | result = PRAGMA_OACC_CLAUSE_CREATE; | |
1e8e9920 | 9877 | break; |
bc7bff74 | 9878 | case 'd': |
ca4c3545 | 9879 | if (!strcmp ("delete", p)) |
9880 | result = PRAGMA_OACC_CLAUSE_DELETE; | |
9881 | else if (!strcmp ("depend", p)) | |
bc7bff74 | 9882 | result = PRAGMA_OMP_CLAUSE_DEPEND; |
9883 | else if (!strcmp ("device", p)) | |
9884 | result = PRAGMA_OMP_CLAUSE_DEVICE; | |
ca4c3545 | 9885 | else if (!strcmp ("deviceptr", p)) |
9886 | result = PRAGMA_OACC_CLAUSE_DEVICEPTR; | |
bc7bff74 | 9887 | else if (!strcmp ("dist_schedule", p)) |
9888 | result = PRAGMA_OMP_CLAUSE_DIST_SCHEDULE; | |
9889 | break; | |
1e8e9920 | 9890 | case 'f': |
2169f33b | 9891 | if (!strcmp ("final", p)) |
9892 | result = PRAGMA_OMP_CLAUSE_FINAL; | |
9893 | else if (!strcmp ("firstprivate", p)) | |
1e8e9920 | 9894 | result = PRAGMA_OMP_CLAUSE_FIRSTPRIVATE; |
bc7bff74 | 9895 | else if (!strcmp ("from", p)) |
9896 | result = PRAGMA_OMP_CLAUSE_FROM; | |
9897 | break; | |
ca4c3545 | 9898 | case 'g': |
9899 | if (!strcmp ("gang", p)) | |
9900 | result = PRAGMA_OACC_CLAUSE_GANG; | |
9901 | break; | |
9902 | case 'h': | |
9903 | if (!strcmp ("host", p)) | |
9904 | result = PRAGMA_OACC_CLAUSE_HOST; | |
9905 | break; | |
bc7bff74 | 9906 | case 'i': |
9907 | if (!strcmp ("inbranch", p)) | |
9908 | result = PRAGMA_OMP_CLAUSE_INBRANCH; | |
1e8e9920 | 9909 | break; |
9910 | case 'l': | |
9911 | if (!strcmp ("lastprivate", p)) | |
9912 | result = PRAGMA_OMP_CLAUSE_LASTPRIVATE; | |
bc7bff74 | 9913 | else if (!strcmp ("linear", p)) |
9914 | result = PRAGMA_OMP_CLAUSE_LINEAR; | |
1e8e9920 | 9915 | break; |
2169f33b | 9916 | case 'm': |
bc7bff74 | 9917 | if (!strcmp ("map", p)) |
9918 | result = PRAGMA_OMP_CLAUSE_MAP; | |
9919 | else if (!strcmp ("mergeable", p)) | |
2169f33b | 9920 | result = PRAGMA_OMP_CLAUSE_MERGEABLE; |
a89e6c15 | 9921 | else if (flag_cilkplus && !strcmp ("mask", p)) |
74acc703 | 9922 | result = PRAGMA_CILK_CLAUSE_MASK; |
2169f33b | 9923 | break; |
1e8e9920 | 9924 | case 'n': |
bc7bff74 | 9925 | if (!strcmp ("notinbranch", p)) |
9926 | result = PRAGMA_OMP_CLAUSE_NOTINBRANCH; | |
9927 | else if (!strcmp ("nowait", p)) | |
1e8e9920 | 9928 | result = PRAGMA_OMP_CLAUSE_NOWAIT; |
ca4c3545 | 9929 | else if (!strcmp ("num_gangs", p)) |
9930 | result = PRAGMA_OACC_CLAUSE_NUM_GANGS; | |
bc7bff74 | 9931 | else if (!strcmp ("num_teams", p)) |
9932 | result = PRAGMA_OMP_CLAUSE_NUM_TEAMS; | |
1e8e9920 | 9933 | else if (!strcmp ("num_threads", p)) |
9934 | result = PRAGMA_OMP_CLAUSE_NUM_THREADS; | |
ca4c3545 | 9935 | else if (!strcmp ("num_workers", p)) |
9936 | result = PRAGMA_OACC_CLAUSE_NUM_WORKERS; | |
a89e6c15 | 9937 | else if (flag_cilkplus && !strcmp ("nomask", p)) |
74acc703 | 9938 | result = PRAGMA_CILK_CLAUSE_NOMASK; |
1e8e9920 | 9939 | break; |
9940 | case 'o': | |
9941 | if (!strcmp ("ordered", p)) | |
9942 | result = PRAGMA_OMP_CLAUSE_ORDERED; | |
9943 | break; | |
9944 | case 'p': | |
bc7bff74 | 9945 | if (!strcmp ("parallel", p)) |
9946 | result = PRAGMA_OMP_CLAUSE_PARALLEL; | |
ca4c3545 | 9947 | else if (!strcmp ("present", p)) |
9948 | result = PRAGMA_OACC_CLAUSE_PRESENT; | |
9949 | else if (!strcmp ("present_or_copy", p) | |
9950 | || !strcmp ("pcopy", p)) | |
9951 | result = PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY; | |
9952 | else if (!strcmp ("present_or_copyin", p) | |
9953 | || !strcmp ("pcopyin", p)) | |
9954 | result = PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN; | |
9955 | else if (!strcmp ("present_or_copyout", p) | |
9956 | || !strcmp ("pcopyout", p)) | |
9957 | result = PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT; | |
9958 | else if (!strcmp ("present_or_create", p) | |
9959 | || !strcmp ("pcreate", p)) | |
9960 | result = PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE; | |
bc7bff74 | 9961 | else if (!strcmp ("private", p)) |
1e8e9920 | 9962 | result = PRAGMA_OMP_CLAUSE_PRIVATE; |
bc7bff74 | 9963 | else if (!strcmp ("proc_bind", p)) |
9964 | result = PRAGMA_OMP_CLAUSE_PROC_BIND; | |
1e8e9920 | 9965 | break; |
9966 | case 'r': | |
9967 | if (!strcmp ("reduction", p)) | |
9968 | result = PRAGMA_OMP_CLAUSE_REDUCTION; | |
9969 | break; | |
9970 | case 's': | |
bc7bff74 | 9971 | if (!strcmp ("safelen", p)) |
9972 | result = PRAGMA_OMP_CLAUSE_SAFELEN; | |
9973 | else if (!strcmp ("schedule", p)) | |
1e8e9920 | 9974 | result = PRAGMA_OMP_CLAUSE_SCHEDULE; |
bc7bff74 | 9975 | else if (!strcmp ("sections", p)) |
9976 | result = PRAGMA_OMP_CLAUSE_SECTIONS; | |
ca4c3545 | 9977 | else if (!strcmp ("seq", p)) |
9978 | result = PRAGMA_OACC_CLAUSE_SEQ; | |
1e8e9920 | 9979 | else if (!strcmp ("shared", p)) |
9980 | result = PRAGMA_OMP_CLAUSE_SHARED; | |
bc7bff74 | 9981 | else if (!strcmp ("simdlen", p)) |
9982 | result = PRAGMA_OMP_CLAUSE_SIMDLEN; | |
ca4c3545 | 9983 | else if (!strcmp ("self", p)) |
9984 | result = PRAGMA_OACC_CLAUSE_SELF; | |
bc7bff74 | 9985 | break; |
9986 | case 't': | |
9987 | if (!strcmp ("taskgroup", p)) | |
9988 | result = PRAGMA_OMP_CLAUSE_TASKGROUP; | |
9989 | else if (!strcmp ("thread_limit", p)) | |
9990 | result = PRAGMA_OMP_CLAUSE_THREAD_LIMIT; | |
9991 | else if (!strcmp ("to", p)) | |
9992 | result = PRAGMA_OMP_CLAUSE_TO; | |
1e8e9920 | 9993 | break; |
fd6481cf | 9994 | case 'u': |
bc7bff74 | 9995 | if (!strcmp ("uniform", p)) |
9996 | result = PRAGMA_OMP_CLAUSE_UNIFORM; | |
9997 | else if (!strcmp ("untied", p)) | |
fd6481cf | 9998 | result = PRAGMA_OMP_CLAUSE_UNTIED; |
9999 | break; | |
74acc703 | 10000 | case 'v': |
ca4c3545 | 10001 | if (!strcmp ("vector", p)) |
10002 | result = PRAGMA_OACC_CLAUSE_VECTOR; | |
10003 | else if (!strcmp ("vector_length", p)) | |
10004 | result = PRAGMA_OACC_CLAUSE_VECTOR_LENGTH; | |
10005 | else if (flag_cilkplus && !strcmp ("vectorlength", p)) | |
74acc703 | 10006 | result = PRAGMA_CILK_CLAUSE_VECTORLENGTH; |
10007 | break; | |
ca4c3545 | 10008 | case 'w': |
10009 | if (!strcmp ("wait", p)) | |
10010 | result = PRAGMA_OACC_CLAUSE_WAIT; | |
10011 | else if (!strcmp ("worker", p)) | |
10012 | result = PRAGMA_OACC_CLAUSE_WORKER; | |
10013 | break; | |
1e8e9920 | 10014 | } |
10015 | } | |
10016 | ||
10017 | if (result != PRAGMA_OMP_CLAUSE_NONE) | |
10018 | c_parser_consume_token (parser); | |
10019 | ||
10020 | return result; | |
10021 | } | |
10022 | ||
10023 | /* Validate that a clause of the given type does not already exist. */ | |
10024 | ||
10025 | static void | |
7d339f93 | 10026 | check_no_duplicate_clause (tree clauses, enum omp_clause_code code, |
10027 | const char *name) | |
1e8e9920 | 10028 | { |
10029 | tree c; | |
10030 | ||
10031 | for (c = clauses; c ; c = OMP_CLAUSE_CHAIN (c)) | |
55d6e7cd | 10032 | if (OMP_CLAUSE_CODE (c) == code) |
1e8e9920 | 10033 | { |
e60a6f7b | 10034 | location_t loc = OMP_CLAUSE_LOCATION (c); |
10035 | error_at (loc, "too many %qs clauses", name); | |
1e8e9920 | 10036 | break; |
10037 | } | |
10038 | } | |
10039 | ||
ca4c3545 | 10040 | /* OpenACC 2.0 |
10041 | Parse wait clause or wait directive parameters. */ | |
10042 | ||
10043 | static tree | |
10044 | c_parser_oacc_wait_list (c_parser *parser, location_t clause_loc, tree list) | |
10045 | { | |
10046 | vec<tree, va_gc> *args; | |
10047 | tree t, args_tree; | |
10048 | ||
10049 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
10050 | return list; | |
10051 | ||
10052 | args = c_parser_expr_list (parser, false, true, NULL, NULL, NULL, NULL); | |
10053 | ||
10054 | if (args->length () == 0) | |
10055 | { | |
10056 | c_parser_error (parser, "expected integer expression before ')'"); | |
10057 | release_tree_vector (args); | |
10058 | return list; | |
10059 | } | |
10060 | ||
10061 | args_tree = build_tree_list_vec (args); | |
10062 | ||
10063 | for (t = args_tree; t; t = TREE_CHAIN (t)) | |
10064 | { | |
10065 | tree targ = TREE_VALUE (t); | |
10066 | ||
10067 | if (targ != error_mark_node) | |
10068 | { | |
10069 | if (!INTEGRAL_TYPE_P (TREE_TYPE (targ))) | |
10070 | { | |
10071 | c_parser_error (parser, "expression must be integral"); | |
10072 | targ = error_mark_node; | |
10073 | } | |
10074 | else | |
10075 | { | |
10076 | tree c = build_omp_clause (clause_loc, OMP_CLAUSE_WAIT); | |
10077 | ||
10078 | OMP_CLAUSE_DECL (c) = targ; | |
10079 | OMP_CLAUSE_CHAIN (c) = list; | |
10080 | list = c; | |
10081 | } | |
10082 | } | |
10083 | } | |
10084 | ||
10085 | release_tree_vector (args); | |
10086 | c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
10087 | return list; | |
10088 | } | |
10089 | ||
10090 | /* OpenACC 2.0, OpenMP 2.5: | |
1e8e9920 | 10091 | variable-list: |
10092 | identifier | |
10093 | variable-list , identifier | |
10094 | ||
e60a6f7b | 10095 | If KIND is nonzero, create the appropriate node and install the |
10096 | decl in OMP_CLAUSE_DECL and add the node to the head of the list. | |
10097 | If KIND is nonzero, CLAUSE_LOC is the location of the clause. | |
1e8e9920 | 10098 | |
10099 | If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE; | |
10100 | return the list created. */ | |
10101 | ||
10102 | static tree | |
e60a6f7b | 10103 | c_parser_omp_variable_list (c_parser *parser, |
10104 | location_t clause_loc, | |
bc7bff74 | 10105 | enum omp_clause_code kind, tree list) |
1e8e9920 | 10106 | { |
10107 | if (c_parser_next_token_is_not (parser, CPP_NAME) | |
10108 | || c_parser_peek_token (parser)->id_kind != C_ID_ID) | |
10109 | c_parser_error (parser, "expected identifier"); | |
10110 | ||
10111 | while (c_parser_next_token_is (parser, CPP_NAME) | |
10112 | && c_parser_peek_token (parser)->id_kind == C_ID_ID) | |
10113 | { | |
10114 | tree t = lookup_name (c_parser_peek_token (parser)->value); | |
10115 | ||
10116 | if (t == NULL_TREE) | |
bc7bff74 | 10117 | { |
10118 | undeclared_variable (c_parser_peek_token (parser)->location, | |
10119 | c_parser_peek_token (parser)->value); | |
10120 | t = error_mark_node; | |
10121 | } | |
10122 | ||
10123 | c_parser_consume_token (parser); | |
10124 | ||
10125 | if (t == error_mark_node) | |
1e8e9920 | 10126 | ; |
10127 | else if (kind != 0) | |
10128 | { | |
bc7bff74 | 10129 | switch (kind) |
10130 | { | |
ca4c3545 | 10131 | case OMP_CLAUSE__CACHE_: |
10132 | if (c_parser_peek_token (parser)->type != CPP_OPEN_SQUARE) | |
10133 | { | |
10134 | c_parser_error (parser, "expected %<[%>"); | |
10135 | t = error_mark_node; | |
10136 | break; | |
10137 | } | |
10138 | /* FALL THROUGH. */ | |
bc7bff74 | 10139 | case OMP_CLAUSE_MAP: |
10140 | case OMP_CLAUSE_FROM: | |
10141 | case OMP_CLAUSE_TO: | |
10142 | case OMP_CLAUSE_DEPEND: | |
10143 | while (c_parser_next_token_is (parser, CPP_OPEN_SQUARE)) | |
10144 | { | |
10145 | tree low_bound = NULL_TREE, length = NULL_TREE; | |
10146 | ||
10147 | c_parser_consume_token (parser); | |
10148 | if (!c_parser_next_token_is (parser, CPP_COLON)) | |
4fc4088b | 10149 | { |
10150 | low_bound = c_parser_expression (parser).value; | |
10151 | mark_exp_read (low_bound); | |
10152 | } | |
bc7bff74 | 10153 | if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE)) |
10154 | length = integer_one_node; | |
10155 | else | |
10156 | { | |
10157 | /* Look for `:'. */ | |
10158 | if (!c_parser_require (parser, CPP_COLON, | |
10159 | "expected %<:%>")) | |
10160 | { | |
10161 | t = error_mark_node; | |
10162 | break; | |
10163 | } | |
10164 | if (!c_parser_next_token_is (parser, CPP_CLOSE_SQUARE)) | |
4fc4088b | 10165 | { |
10166 | length = c_parser_expression (parser).value; | |
10167 | mark_exp_read (length); | |
10168 | } | |
bc7bff74 | 10169 | } |
10170 | /* Look for the closing `]'. */ | |
10171 | if (!c_parser_require (parser, CPP_CLOSE_SQUARE, | |
10172 | "expected %<]%>")) | |
10173 | { | |
10174 | t = error_mark_node; | |
10175 | break; | |
10176 | } | |
ca4c3545 | 10177 | |
10178 | if (kind == OMP_CLAUSE__CACHE_) | |
10179 | { | |
10180 | if (TREE_CODE (low_bound) != INTEGER_CST | |
10181 | && !TREE_READONLY (low_bound)) | |
10182 | { | |
10183 | error_at (clause_loc, | |
10184 | "%qD is not a constant", low_bound); | |
10185 | t = error_mark_node; | |
10186 | } | |
10187 | ||
10188 | if (TREE_CODE (length) != INTEGER_CST | |
10189 | && !TREE_READONLY (length)) | |
10190 | { | |
10191 | error_at (clause_loc, | |
10192 | "%qD is not a constant", length); | |
10193 | t = error_mark_node; | |
10194 | } | |
10195 | } | |
10196 | ||
bc7bff74 | 10197 | t = tree_cons (low_bound, length, t); |
10198 | } | |
10199 | break; | |
10200 | default: | |
10201 | break; | |
10202 | } | |
10203 | ||
10204 | if (t != error_mark_node) | |
10205 | { | |
10206 | tree u = build_omp_clause (clause_loc, kind); | |
10207 | OMP_CLAUSE_DECL (u) = t; | |
10208 | OMP_CLAUSE_CHAIN (u) = list; | |
10209 | list = u; | |
10210 | } | |
1e8e9920 | 10211 | } |
10212 | else | |
10213 | list = tree_cons (t, NULL_TREE, list); | |
10214 | ||
1e8e9920 | 10215 | if (c_parser_next_token_is_not (parser, CPP_COMMA)) |
10216 | break; | |
10217 | ||
10218 | c_parser_consume_token (parser); | |
10219 | } | |
10220 | ||
10221 | return list; | |
10222 | } | |
10223 | ||
10224 | /* Similarly, but expect leading and trailing parenthesis. This is a very | |
ca4c3545 | 10225 | common case for OpenACC and OpenMP clauses. */ |
1e8e9920 | 10226 | |
10227 | static tree | |
7d339f93 | 10228 | c_parser_omp_var_list_parens (c_parser *parser, enum omp_clause_code kind, |
10229 | tree list) | |
1e8e9920 | 10230 | { |
e60a6f7b | 10231 | /* The clauses location. */ |
10232 | location_t loc = c_parser_peek_token (parser)->location; | |
10233 | ||
1e8e9920 | 10234 | if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) |
10235 | { | |
e60a6f7b | 10236 | list = c_parser_omp_variable_list (parser, loc, kind, list); |
1e8e9920 | 10237 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); |
10238 | } | |
10239 | return list; | |
10240 | } | |
10241 | ||
ca4c3545 | 10242 | /* OpenACC 2.0: |
10243 | copy ( variable-list ) | |
10244 | copyin ( variable-list ) | |
10245 | copyout ( variable-list ) | |
10246 | create ( variable-list ) | |
10247 | delete ( variable-list ) | |
10248 | present ( variable-list ) | |
10249 | present_or_copy ( variable-list ) | |
10250 | pcopy ( variable-list ) | |
10251 | present_or_copyin ( variable-list ) | |
10252 | pcopyin ( variable-list ) | |
10253 | present_or_copyout ( variable-list ) | |
10254 | pcopyout ( variable-list ) | |
10255 | present_or_create ( variable-list ) | |
10256 | pcreate ( variable-list ) */ | |
10257 | ||
10258 | static tree | |
10259 | c_parser_oacc_data_clause (c_parser *parser, pragma_omp_clause c_kind, | |
10260 | tree list) | |
10261 | { | |
10262 | enum gomp_map_kind kind; | |
10263 | switch (c_kind) | |
10264 | { | |
10265 | case PRAGMA_OACC_CLAUSE_COPY: | |
10266 | kind = GOMP_MAP_FORCE_TOFROM; | |
10267 | break; | |
10268 | case PRAGMA_OACC_CLAUSE_COPYIN: | |
10269 | kind = GOMP_MAP_FORCE_TO; | |
10270 | break; | |
10271 | case PRAGMA_OACC_CLAUSE_COPYOUT: | |
10272 | kind = GOMP_MAP_FORCE_FROM; | |
10273 | break; | |
10274 | case PRAGMA_OACC_CLAUSE_CREATE: | |
10275 | kind = GOMP_MAP_FORCE_ALLOC; | |
10276 | break; | |
10277 | case PRAGMA_OACC_CLAUSE_DELETE: | |
10278 | kind = GOMP_MAP_FORCE_DEALLOC; | |
10279 | break; | |
10280 | case PRAGMA_OACC_CLAUSE_DEVICE: | |
10281 | kind = GOMP_MAP_FORCE_TO; | |
10282 | break; | |
10283 | case PRAGMA_OACC_CLAUSE_HOST: | |
10284 | case PRAGMA_OACC_CLAUSE_SELF: | |
10285 | kind = GOMP_MAP_FORCE_FROM; | |
10286 | break; | |
10287 | case PRAGMA_OACC_CLAUSE_PRESENT: | |
10288 | kind = GOMP_MAP_FORCE_PRESENT; | |
10289 | break; | |
10290 | case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY: | |
10291 | kind = GOMP_MAP_TOFROM; | |
10292 | break; | |
10293 | case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN: | |
10294 | kind = GOMP_MAP_TO; | |
10295 | break; | |
10296 | case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT: | |
10297 | kind = GOMP_MAP_FROM; | |
10298 | break; | |
10299 | case PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE: | |
10300 | kind = GOMP_MAP_ALLOC; | |
10301 | break; | |
10302 | default: | |
10303 | gcc_unreachable (); | |
10304 | } | |
10305 | tree nl, c; | |
10306 | nl = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_MAP, list); | |
10307 | ||
10308 | for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c)) | |
10309 | OMP_CLAUSE_SET_MAP_KIND (c, kind); | |
10310 | ||
10311 | return nl; | |
10312 | } | |
10313 | ||
10314 | /* OpenACC 2.0: | |
10315 | deviceptr ( variable-list ) */ | |
10316 | ||
10317 | static tree | |
10318 | c_parser_oacc_data_clause_deviceptr (c_parser *parser, tree list) | |
10319 | { | |
10320 | location_t loc = c_parser_peek_token (parser)->location; | |
10321 | tree vars, t; | |
10322 | ||
10323 | /* Can't use OMP_CLAUSE_MAP here (that is, can't use the generic | |
10324 | c_parser_oacc_data_clause), as for PRAGMA_OACC_CLAUSE_DEVICEPTR, | |
10325 | variable-list must only allow for pointer variables. */ | |
10326 | vars = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL); | |
10327 | for (t = vars; t && t; t = TREE_CHAIN (t)) | |
10328 | { | |
10329 | tree v = TREE_PURPOSE (t); | |
10330 | ||
10331 | /* FIXME diagnostics: Ideally we should keep individual | |
10332 | locations for all the variables in the var list to make the | |
10333 | following errors more precise. Perhaps | |
10334 | c_parser_omp_var_list_parens() should construct a list of | |
10335 | locations to go along with the var list. */ | |
10336 | ||
10337 | if (TREE_CODE (v) != VAR_DECL) | |
10338 | error_at (loc, "%qD is not a variable", v); | |
10339 | else if (TREE_TYPE (v) == error_mark_node) | |
10340 | ; | |
10341 | else if (!POINTER_TYPE_P (TREE_TYPE (v))) | |
10342 | error_at (loc, "%qD is not a pointer variable", v); | |
10343 | ||
10344 | tree u = build_omp_clause (loc, OMP_CLAUSE_MAP); | |
10345 | OMP_CLAUSE_SET_MAP_KIND (u, GOMP_MAP_FORCE_DEVICEPTR); | |
10346 | OMP_CLAUSE_DECL (u) = v; | |
10347 | OMP_CLAUSE_CHAIN (u) = list; | |
10348 | list = u; | |
10349 | } | |
10350 | ||
10351 | return list; | |
10352 | } | |
10353 | ||
10354 | /* OpenACC 2.0, OpenMP 3.0: | |
fd6481cf | 10355 | collapse ( constant-expression ) */ |
10356 | ||
10357 | static tree | |
10358 | c_parser_omp_clause_collapse (c_parser *parser, tree list) | |
10359 | { | |
10360 | tree c, num = error_mark_node; | |
10361 | HOST_WIDE_INT n; | |
10362 | location_t loc; | |
10363 | ||
10364 | check_no_duplicate_clause (list, OMP_CLAUSE_COLLAPSE, "collapse"); | |
10365 | ||
10366 | loc = c_parser_peek_token (parser)->location; | |
10367 | if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
10368 | { | |
10369 | num = c_parser_expr_no_commas (parser, NULL).value; | |
10370 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
10371 | } | |
10372 | if (num == error_mark_node) | |
10373 | return list; | |
bc7bff74 | 10374 | mark_exp_read (num); |
10375 | num = c_fully_fold (num, false, NULL); | |
fd6481cf | 10376 | if (!INTEGRAL_TYPE_P (TREE_TYPE (num)) |
e913b5cd | 10377 | || !tree_fits_shwi_p (num) |
10378 | || (n = tree_to_shwi (num)) <= 0 | |
fd6481cf | 10379 | || (int) n != n) |
10380 | { | |
e3b80d49 | 10381 | error_at (loc, |
10382 | "collapse argument needs positive constant integer expression"); | |
fd6481cf | 10383 | return list; |
10384 | } | |
e60a6f7b | 10385 | c = build_omp_clause (loc, OMP_CLAUSE_COLLAPSE); |
fd6481cf | 10386 | OMP_CLAUSE_COLLAPSE_EXPR (c) = num; |
10387 | OMP_CLAUSE_CHAIN (c) = list; | |
10388 | return c; | |
10389 | } | |
10390 | ||
1e8e9920 | 10391 | /* OpenMP 2.5: |
10392 | copyin ( variable-list ) */ | |
10393 | ||
10394 | static tree | |
10395 | c_parser_omp_clause_copyin (c_parser *parser, tree list) | |
10396 | { | |
10397 | return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYIN, list); | |
10398 | } | |
10399 | ||
10400 | /* OpenMP 2.5: | |
10401 | copyprivate ( variable-list ) */ | |
10402 | ||
10403 | static tree | |
10404 | c_parser_omp_clause_copyprivate (c_parser *parser, tree list) | |
10405 | { | |
10406 | return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYPRIVATE, list); | |
10407 | } | |
10408 | ||
10409 | /* OpenMP 2.5: | |
10410 | default ( shared | none ) */ | |
10411 | ||
10412 | static tree | |
10413 | c_parser_omp_clause_default (c_parser *parser, tree list) | |
10414 | { | |
10415 | enum omp_clause_default_kind kind = OMP_CLAUSE_DEFAULT_UNSPECIFIED; | |
e60a6f7b | 10416 | location_t loc = c_parser_peek_token (parser)->location; |
1e8e9920 | 10417 | tree c; |
10418 | ||
10419 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
10420 | return list; | |
10421 | if (c_parser_next_token_is (parser, CPP_NAME)) | |
10422 | { | |
10423 | const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); | |
10424 | ||
10425 | switch (p[0]) | |
10426 | { | |
10427 | case 'n': | |
10428 | if (strcmp ("none", p) != 0) | |
10429 | goto invalid_kind; | |
10430 | kind = OMP_CLAUSE_DEFAULT_NONE; | |
10431 | break; | |
10432 | ||
10433 | case 's': | |
10434 | if (strcmp ("shared", p) != 0) | |
10435 | goto invalid_kind; | |
10436 | kind = OMP_CLAUSE_DEFAULT_SHARED; | |
10437 | break; | |
10438 | ||
10439 | default: | |
10440 | goto invalid_kind; | |
10441 | } | |
10442 | ||
10443 | c_parser_consume_token (parser); | |
10444 | } | |
10445 | else | |
10446 | { | |
10447 | invalid_kind: | |
10448 | c_parser_error (parser, "expected %<none%> or %<shared%>"); | |
10449 | } | |
10450 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
10451 | ||
10452 | if (kind == OMP_CLAUSE_DEFAULT_UNSPECIFIED) | |
10453 | return list; | |
10454 | ||
10455 | check_no_duplicate_clause (list, OMP_CLAUSE_DEFAULT, "default"); | |
e60a6f7b | 10456 | c = build_omp_clause (loc, OMP_CLAUSE_DEFAULT); |
1e8e9920 | 10457 | OMP_CLAUSE_CHAIN (c) = list; |
10458 | OMP_CLAUSE_DEFAULT_KIND (c) = kind; | |
10459 | ||
10460 | return c; | |
10461 | } | |
10462 | ||
10463 | /* OpenMP 2.5: | |
10464 | firstprivate ( variable-list ) */ | |
10465 | ||
10466 | static tree | |
10467 | c_parser_omp_clause_firstprivate (c_parser *parser, tree list) | |
10468 | { | |
10469 | return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_FIRSTPRIVATE, list); | |
10470 | } | |
10471 | ||
2169f33b | 10472 | /* OpenMP 3.1: |
10473 | final ( expression ) */ | |
10474 | ||
10475 | static tree | |
10476 | c_parser_omp_clause_final (c_parser *parser, tree list) | |
10477 | { | |
10478 | location_t loc = c_parser_peek_token (parser)->location; | |
10479 | if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) | |
10480 | { | |
10481 | tree t = c_parser_paren_condition (parser); | |
10482 | tree c; | |
10483 | ||
10484 | check_no_duplicate_clause (list, OMP_CLAUSE_FINAL, "final"); | |
10485 | ||
10486 | c = build_omp_clause (loc, OMP_CLAUSE_FINAL); | |
10487 | OMP_CLAUSE_FINAL_EXPR (c) = t; | |
10488 | OMP_CLAUSE_CHAIN (c) = list; | |
10489 | list = c; | |
10490 | } | |
10491 | else | |
10492 | c_parser_error (parser, "expected %<(%>"); | |
10493 | ||
10494 | return list; | |
10495 | } | |
10496 | ||
ca4c3545 | 10497 | /* OpenACC, OpenMP 2.5: |
1e8e9920 | 10498 | if ( expression ) */ |
10499 | ||
10500 | static tree | |
10501 | c_parser_omp_clause_if (c_parser *parser, tree list) | |
10502 | { | |
e60a6f7b | 10503 | location_t loc = c_parser_peek_token (parser)->location; |
1e8e9920 | 10504 | if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) |
10505 | { | |
10506 | tree t = c_parser_paren_condition (parser); | |
10507 | tree c; | |
10508 | ||
10509 | check_no_duplicate_clause (list, OMP_CLAUSE_IF, "if"); | |
10510 | ||
e60a6f7b | 10511 | c = build_omp_clause (loc, OMP_CLAUSE_IF); |
1e8e9920 | 10512 | OMP_CLAUSE_IF_EXPR (c) = t; |
10513 | OMP_CLAUSE_CHAIN (c) = list; | |
10514 | list = c; | |
10515 | } | |
10516 | else | |
10517 | c_parser_error (parser, "expected %<(%>"); | |
10518 | ||
10519 | return list; | |
10520 | } | |
10521 | ||
10522 | /* OpenMP 2.5: | |
10523 | lastprivate ( variable-list ) */ | |
10524 | ||
10525 | static tree | |
10526 | c_parser_omp_clause_lastprivate (c_parser *parser, tree list) | |
10527 | { | |
10528 | return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_LASTPRIVATE, list); | |
10529 | } | |
10530 | ||
2169f33b | 10531 | /* OpenMP 3.1: |
10532 | mergeable */ | |
10533 | ||
10534 | static tree | |
10535 | c_parser_omp_clause_mergeable (c_parser *parser ATTRIBUTE_UNUSED, tree list) | |
10536 | { | |
10537 | tree c; | |
10538 | ||
10539 | /* FIXME: Should we allow duplicates? */ | |
10540 | check_no_duplicate_clause (list, OMP_CLAUSE_MERGEABLE, "mergeable"); | |
10541 | ||
10542 | c = build_omp_clause (c_parser_peek_token (parser)->location, | |
10543 | OMP_CLAUSE_MERGEABLE); | |
10544 | OMP_CLAUSE_CHAIN (c) = list; | |
10545 | ||
10546 | return c; | |
10547 | } | |
10548 | ||
1e8e9920 | 10549 | /* OpenMP 2.5: |
10550 | nowait */ | |
10551 | ||
10552 | static tree | |
10553 | c_parser_omp_clause_nowait (c_parser *parser ATTRIBUTE_UNUSED, tree list) | |
10554 | { | |
10555 | tree c; | |
e60a6f7b | 10556 | location_t loc = c_parser_peek_token (parser)->location; |
1e8e9920 | 10557 | |
10558 | check_no_duplicate_clause (list, OMP_CLAUSE_NOWAIT, "nowait"); | |
10559 | ||
e60a6f7b | 10560 | c = build_omp_clause (loc, OMP_CLAUSE_NOWAIT); |
1e8e9920 | 10561 | OMP_CLAUSE_CHAIN (c) = list; |
10562 | return c; | |
10563 | } | |
10564 | ||
ca4c3545 | 10565 | /* OpenACC: |
10566 | num_gangs ( expression ) */ | |
10567 | ||
10568 | static tree | |
10569 | c_parser_omp_clause_num_gangs (c_parser *parser, tree list) | |
10570 | { | |
10571 | location_t num_gangs_loc = c_parser_peek_token (parser)->location; | |
10572 | if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
10573 | { | |
10574 | location_t expr_loc = c_parser_peek_token (parser)->location; | |
10575 | tree c, t = c_parser_expression (parser).value; | |
10576 | mark_exp_read (t); | |
10577 | t = c_fully_fold (t, false, NULL); | |
10578 | ||
10579 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
10580 | ||
10581 | if (!INTEGRAL_TYPE_P (TREE_TYPE (t))) | |
10582 | { | |
10583 | c_parser_error (parser, "expected integer expression"); | |
10584 | return list; | |
10585 | } | |
10586 | ||
10587 | /* Attempt to statically determine when the number isn't positive. */ | |
10588 | c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t, | |
10589 | build_int_cst (TREE_TYPE (t), 0)); | |
10590 | if (CAN_HAVE_LOCATION_P (c)) | |
10591 | SET_EXPR_LOCATION (c, expr_loc); | |
10592 | if (c == boolean_true_node) | |
10593 | { | |
10594 | warning_at (expr_loc, 0, | |
10595 | "%<num_gangs%> value must be positive"); | |
10596 | t = integer_one_node; | |
10597 | } | |
10598 | ||
10599 | check_no_duplicate_clause (list, OMP_CLAUSE_NUM_GANGS, "num_gangs"); | |
10600 | ||
10601 | c = build_omp_clause (num_gangs_loc, OMP_CLAUSE_NUM_GANGS); | |
10602 | OMP_CLAUSE_NUM_GANGS_EXPR (c) = t; | |
10603 | OMP_CLAUSE_CHAIN (c) = list; | |
10604 | list = c; | |
10605 | } | |
10606 | ||
10607 | return list; | |
10608 | } | |
10609 | ||
1e8e9920 | 10610 | /* OpenMP 2.5: |
10611 | num_threads ( expression ) */ | |
10612 | ||
10613 | static tree | |
10614 | c_parser_omp_clause_num_threads (c_parser *parser, tree list) | |
10615 | { | |
e60a6f7b | 10616 | location_t num_threads_loc = c_parser_peek_token (parser)->location; |
1e8e9920 | 10617 | if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) |
10618 | { | |
be9eba16 | 10619 | location_t expr_loc = c_parser_peek_token (parser)->location; |
1e8e9920 | 10620 | tree c, t = c_parser_expression (parser).value; |
80678da6 | 10621 | mark_exp_read (t); |
a75b1c71 | 10622 | t = c_fully_fold (t, false, NULL); |
1e8e9920 | 10623 | |
10624 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
10625 | ||
10626 | if (!INTEGRAL_TYPE_P (TREE_TYPE (t))) | |
10627 | { | |
10628 | c_parser_error (parser, "expected integer expression"); | |
10629 | return list; | |
10630 | } | |
10631 | ||
10632 | /* Attempt to statically determine when the number isn't positive. */ | |
389dd41b | 10633 | c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t, |
1e8e9920 | 10634 | build_int_cst (TREE_TYPE (t), 0)); |
e60a6f7b | 10635 | if (CAN_HAVE_LOCATION_P (c)) |
10636 | SET_EXPR_LOCATION (c, expr_loc); | |
1e8e9920 | 10637 | if (c == boolean_true_node) |
10638 | { | |
e3b80d49 | 10639 | warning_at (expr_loc, 0, |
10640 | "%<num_threads%> value must be positive"); | |
1e8e9920 | 10641 | t = integer_one_node; |
10642 | } | |
10643 | ||
10644 | check_no_duplicate_clause (list, OMP_CLAUSE_NUM_THREADS, "num_threads"); | |
10645 | ||
e60a6f7b | 10646 | c = build_omp_clause (num_threads_loc, OMP_CLAUSE_NUM_THREADS); |
1e8e9920 | 10647 | OMP_CLAUSE_NUM_THREADS_EXPR (c) = t; |
10648 | OMP_CLAUSE_CHAIN (c) = list; | |
10649 | list = c; | |
10650 | } | |
10651 | ||
10652 | return list; | |
10653 | } | |
10654 | ||
ca4c3545 | 10655 | /* OpenACC: |
10656 | num_workers ( expression ) */ | |
10657 | ||
10658 | static tree | |
10659 | c_parser_omp_clause_num_workers (c_parser *parser, tree list) | |
10660 | { | |
10661 | location_t num_workers_loc = c_parser_peek_token (parser)->location; | |
10662 | if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
10663 | { | |
10664 | location_t expr_loc = c_parser_peek_token (parser)->location; | |
10665 | tree c, t = c_parser_expression (parser).value; | |
10666 | mark_exp_read (t); | |
10667 | t = c_fully_fold (t, false, NULL); | |
10668 | ||
10669 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
10670 | ||
10671 | if (!INTEGRAL_TYPE_P (TREE_TYPE (t))) | |
10672 | { | |
10673 | c_parser_error (parser, "expected integer expression"); | |
10674 | return list; | |
10675 | } | |
10676 | ||
10677 | /* Attempt to statically determine when the number isn't positive. */ | |
10678 | c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t, | |
10679 | build_int_cst (TREE_TYPE (t), 0)); | |
10680 | if (CAN_HAVE_LOCATION_P (c)) | |
10681 | SET_EXPR_LOCATION (c, expr_loc); | |
10682 | if (c == boolean_true_node) | |
10683 | { | |
10684 | warning_at (expr_loc, 0, | |
10685 | "%<num_workers%> value must be positive"); | |
10686 | t = integer_one_node; | |
10687 | } | |
10688 | ||
10689 | check_no_duplicate_clause (list, OMP_CLAUSE_NUM_WORKERS, "num_workers"); | |
10690 | ||
10691 | c = build_omp_clause (num_workers_loc, OMP_CLAUSE_NUM_WORKERS); | |
10692 | OMP_CLAUSE_NUM_WORKERS_EXPR (c) = t; | |
10693 | OMP_CLAUSE_CHAIN (c) = list; | |
10694 | list = c; | |
10695 | } | |
10696 | ||
10697 | return list; | |
10698 | } | |
10699 | ||
10700 | /* OpenACC: | |
10701 | async [( int-expr )] */ | |
10702 | ||
10703 | static tree | |
10704 | c_parser_oacc_clause_async (c_parser *parser, tree list) | |
10705 | { | |
10706 | tree c, t; | |
10707 | location_t loc = c_parser_peek_token (parser)->location; | |
10708 | ||
10709 | t = build_int_cst (integer_type_node, GOMP_ASYNC_NOVAL); | |
10710 | ||
10711 | if (c_parser_peek_token (parser)->type == CPP_OPEN_PAREN) | |
10712 | { | |
10713 | c_parser_consume_token (parser); | |
10714 | ||
10715 | t = c_parser_expression (parser).value; | |
10716 | if (!INTEGRAL_TYPE_P (TREE_TYPE (t))) | |
10717 | c_parser_error (parser, "expected integer expression"); | |
10718 | else if (t == error_mark_node | |
10719 | || !c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>")) | |
10720 | return list; | |
10721 | } | |
10722 | else | |
10723 | t = c_fully_fold (t, false, NULL); | |
10724 | ||
10725 | check_no_duplicate_clause (list, OMP_CLAUSE_ASYNC, "async"); | |
10726 | ||
10727 | c = build_omp_clause (loc, OMP_CLAUSE_ASYNC); | |
10728 | OMP_CLAUSE_ASYNC_EXPR (c) = t; | |
10729 | OMP_CLAUSE_CHAIN (c) = list; | |
10730 | list = c; | |
10731 | ||
10732 | return list; | |
10733 | } | |
10734 | ||
10735 | /* OpenACC: | |
10736 | wait ( int-expr-list ) */ | |
10737 | ||
10738 | static tree | |
10739 | c_parser_oacc_clause_wait (c_parser *parser, tree list) | |
10740 | { | |
10741 | location_t clause_loc = c_parser_peek_token (parser)->location; | |
10742 | ||
10743 | if (c_parser_peek_token (parser)->type == CPP_OPEN_PAREN) | |
10744 | list = c_parser_oacc_wait_list (parser, clause_loc, list); | |
10745 | ||
10746 | return list; | |
10747 | } | |
10748 | ||
1e8e9920 | 10749 | /* OpenMP 2.5: |
10750 | ordered */ | |
10751 | ||
10752 | static tree | |
e60a6f7b | 10753 | c_parser_omp_clause_ordered (c_parser *parser, tree list) |
1e8e9920 | 10754 | { |
10755 | tree c; | |
10756 | ||
10757 | check_no_duplicate_clause (list, OMP_CLAUSE_ORDERED, "ordered"); | |
10758 | ||
e60a6f7b | 10759 | c = build_omp_clause (c_parser_peek_token (parser)->location, |
10760 | OMP_CLAUSE_ORDERED); | |
1e8e9920 | 10761 | OMP_CLAUSE_CHAIN (c) = list; |
e60a6f7b | 10762 | |
1e8e9920 | 10763 | return c; |
10764 | } | |
10765 | ||
10766 | /* OpenMP 2.5: | |
10767 | private ( variable-list ) */ | |
10768 | ||
10769 | static tree | |
10770 | c_parser_omp_clause_private (c_parser *parser, tree list) | |
10771 | { | |
10772 | return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_PRIVATE, list); | |
10773 | } | |
10774 | ||
10775 | /* OpenMP 2.5: | |
10776 | reduction ( reduction-operator : variable-list ) | |
10777 | ||
10778 | reduction-operator: | |
2169f33b | 10779 | One of: + * - & ^ | && || |
bc7bff74 | 10780 | |
2169f33b | 10781 | OpenMP 3.1: |
10782 | ||
10783 | reduction-operator: | |
bc7bff74 | 10784 | One of: + * - & ^ | && || max min |
10785 | ||
10786 | OpenMP 4.0: | |
10787 | ||
10788 | reduction-operator: | |
10789 | One of: + * - & ^ | && || | |
10790 | identifier */ | |
1e8e9920 | 10791 | |
10792 | static tree | |
10793 | c_parser_omp_clause_reduction (c_parser *parser, tree list) | |
10794 | { | |
e60a6f7b | 10795 | location_t clause_loc = c_parser_peek_token (parser)->location; |
1e8e9920 | 10796 | if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) |
10797 | { | |
bc7bff74 | 10798 | enum tree_code code = ERROR_MARK; |
10799 | tree reduc_id = NULL_TREE; | |
1e8e9920 | 10800 | |
10801 | switch (c_parser_peek_token (parser)->type) | |
10802 | { | |
10803 | case CPP_PLUS: | |
10804 | code = PLUS_EXPR; | |
10805 | break; | |
10806 | case CPP_MULT: | |
10807 | code = MULT_EXPR; | |
10808 | break; | |
10809 | case CPP_MINUS: | |
10810 | code = MINUS_EXPR; | |
10811 | break; | |
10812 | case CPP_AND: | |
10813 | code = BIT_AND_EXPR; | |
10814 | break; | |
10815 | case CPP_XOR: | |
10816 | code = BIT_XOR_EXPR; | |
10817 | break; | |
10818 | case CPP_OR: | |
10819 | code = BIT_IOR_EXPR; | |
10820 | break; | |
10821 | case CPP_AND_AND: | |
10822 | code = TRUTH_ANDIF_EXPR; | |
10823 | break; | |
10824 | case CPP_OR_OR: | |
10825 | code = TRUTH_ORIF_EXPR; | |
10826 | break; | |
2169f33b | 10827 | case CPP_NAME: |
10828 | { | |
10829 | const char *p | |
10830 | = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); | |
10831 | if (strcmp (p, "min") == 0) | |
10832 | { | |
10833 | code = MIN_EXPR; | |
10834 | break; | |
10835 | } | |
10836 | if (strcmp (p, "max") == 0) | |
10837 | { | |
10838 | code = MAX_EXPR; | |
10839 | break; | |
10840 | } | |
bc7bff74 | 10841 | reduc_id = c_parser_peek_token (parser)->value; |
10842 | break; | |
2169f33b | 10843 | } |
1e8e9920 | 10844 | default: |
10845 | c_parser_error (parser, | |
10846 | "expected %<+%>, %<*%>, %<-%>, %<&%>, " | |
2169f33b | 10847 | "%<^%>, %<|%>, %<&&%>, %<||%>, %<min%> or %<max%>"); |
1e8e9920 | 10848 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0); |
10849 | return list; | |
10850 | } | |
10851 | c_parser_consume_token (parser); | |
bc7bff74 | 10852 | reduc_id = c_omp_reduction_id (code, reduc_id); |
1e8e9920 | 10853 | if (c_parser_require (parser, CPP_COLON, "expected %<:%>")) |
10854 | { | |
10855 | tree nl, c; | |
10856 | ||
e60a6f7b | 10857 | nl = c_parser_omp_variable_list (parser, clause_loc, |
10858 | OMP_CLAUSE_REDUCTION, list); | |
1e8e9920 | 10859 | for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c)) |
bc7bff74 | 10860 | { |
10861 | tree type = TREE_TYPE (OMP_CLAUSE_DECL (c)); | |
10862 | OMP_CLAUSE_REDUCTION_CODE (c) = code; | |
10863 | if (code == ERROR_MARK | |
10864 | || !(INTEGRAL_TYPE_P (type) | |
10865 | || TREE_CODE (type) == REAL_TYPE | |
10866 | || TREE_CODE (type) == COMPLEX_TYPE)) | |
10867 | OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) | |
10868 | = c_omp_reduction_lookup (reduc_id, | |
10869 | TYPE_MAIN_VARIANT (type)); | |
10870 | } | |
1e8e9920 | 10871 | |
10872 | list = nl; | |
10873 | } | |
10874 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
10875 | } | |
10876 | return list; | |
10877 | } | |
10878 | ||
10879 | /* OpenMP 2.5: | |
10880 | schedule ( schedule-kind ) | |
10881 | schedule ( schedule-kind , expression ) | |
10882 | ||
10883 | schedule-kind: | |
fd6481cf | 10884 | static | dynamic | guided | runtime | auto |
1e8e9920 | 10885 | */ |
10886 | ||
10887 | static tree | |
10888 | c_parser_omp_clause_schedule (c_parser *parser, tree list) | |
10889 | { | |
10890 | tree c, t; | |
e60a6f7b | 10891 | location_t loc = c_parser_peek_token (parser)->location; |
1e8e9920 | 10892 | |
10893 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
10894 | return list; | |
10895 | ||
e60a6f7b | 10896 | c = build_omp_clause (loc, OMP_CLAUSE_SCHEDULE); |
1e8e9920 | 10897 | |
10898 | if (c_parser_next_token_is (parser, CPP_NAME)) | |
10899 | { | |
10900 | tree kind = c_parser_peek_token (parser)->value; | |
10901 | const char *p = IDENTIFIER_POINTER (kind); | |
10902 | ||
10903 | switch (p[0]) | |
10904 | { | |
10905 | case 'd': | |
10906 | if (strcmp ("dynamic", p) != 0) | |
10907 | goto invalid_kind; | |
10908 | OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_DYNAMIC; | |
10909 | break; | |
10910 | ||
10911 | case 'g': | |
10912 | if (strcmp ("guided", p) != 0) | |
10913 | goto invalid_kind; | |
10914 | OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_GUIDED; | |
10915 | break; | |
10916 | ||
10917 | case 'r': | |
10918 | if (strcmp ("runtime", p) != 0) | |
10919 | goto invalid_kind; | |
10920 | OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_RUNTIME; | |
10921 | break; | |
10922 | ||
10923 | default: | |
10924 | goto invalid_kind; | |
10925 | } | |
10926 | } | |
10927 | else if (c_parser_next_token_is_keyword (parser, RID_STATIC)) | |
10928 | OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_STATIC; | |
fd6481cf | 10929 | else if (c_parser_next_token_is_keyword (parser, RID_AUTO)) |
10930 | OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_AUTO; | |
1e8e9920 | 10931 | else |
10932 | goto invalid_kind; | |
10933 | ||
10934 | c_parser_consume_token (parser); | |
10935 | if (c_parser_next_token_is (parser, CPP_COMMA)) | |
10936 | { | |
be9eba16 | 10937 | location_t here; |
1e8e9920 | 10938 | c_parser_consume_token (parser); |
10939 | ||
be9eba16 | 10940 | here = c_parser_peek_token (parser)->location; |
1e8e9920 | 10941 | t = c_parser_expr_no_commas (parser, NULL).value; |
80678da6 | 10942 | mark_exp_read (t); |
a75b1c71 | 10943 | t = c_fully_fold (t, false, NULL); |
1e8e9920 | 10944 | |
10945 | if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_RUNTIME) | |
e3b80d49 | 10946 | error_at (here, "schedule %<runtime%> does not take " |
10947 | "a %<chunk_size%> parameter"); | |
fd6481cf | 10948 | else if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_AUTO) |
e3b80d49 | 10949 | error_at (here, |
10950 | "schedule %<auto%> does not take " | |
10951 | "a %<chunk_size%> parameter"); | |
1e8e9920 | 10952 | else if (TREE_CODE (TREE_TYPE (t)) == INTEGER_TYPE) |
10953 | OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c) = t; | |
10954 | else | |
10955 | c_parser_error (parser, "expected integer expression"); | |
10956 | ||
10957 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
10958 | } | |
10959 | else | |
10960 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, | |
10961 | "expected %<,%> or %<)%>"); | |
10962 | ||
10963 | check_no_duplicate_clause (list, OMP_CLAUSE_SCHEDULE, "schedule"); | |
10964 | OMP_CLAUSE_CHAIN (c) = list; | |
10965 | return c; | |
10966 | ||
10967 | invalid_kind: | |
10968 | c_parser_error (parser, "invalid schedule kind"); | |
10969 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0); | |
10970 | return list; | |
10971 | } | |
10972 | ||
10973 | /* OpenMP 2.5: | |
10974 | shared ( variable-list ) */ | |
10975 | ||
10976 | static tree | |
10977 | c_parser_omp_clause_shared (c_parser *parser, tree list) | |
10978 | { | |
10979 | return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_SHARED, list); | |
10980 | } | |
10981 | ||
fd6481cf | 10982 | /* OpenMP 3.0: |
10983 | untied */ | |
10984 | ||
10985 | static tree | |
10986 | c_parser_omp_clause_untied (c_parser *parser ATTRIBUTE_UNUSED, tree list) | |
10987 | { | |
10988 | tree c; | |
10989 | ||
10990 | /* FIXME: Should we allow duplicates? */ | |
10991 | check_no_duplicate_clause (list, OMP_CLAUSE_UNTIED, "untied"); | |
10992 | ||
e60a6f7b | 10993 | c = build_omp_clause (c_parser_peek_token (parser)->location, |
10994 | OMP_CLAUSE_UNTIED); | |
fd6481cf | 10995 | OMP_CLAUSE_CHAIN (c) = list; |
e60a6f7b | 10996 | |
fd6481cf | 10997 | return c; |
10998 | } | |
10999 | ||
ca4c3545 | 11000 | /* OpenACC: |
11001 | vector_length ( expression ) */ | |
1e8e9920 | 11002 | |
11003 | static tree | |
ca4c3545 | 11004 | c_parser_omp_clause_vector_length (c_parser *parser, tree list) |
1e8e9920 | 11005 | { |
ca4c3545 | 11006 | location_t vector_length_loc = c_parser_peek_token (parser)->location; |
11007 | if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
11008 | { | |
11009 | location_t expr_loc = c_parser_peek_token (parser)->location; | |
11010 | tree c, t = c_parser_expression (parser).value; | |
11011 | mark_exp_read (t); | |
11012 | t = c_fully_fold (t, false, NULL); | |
1e8e9920 | 11013 | |
ca4c3545 | 11014 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); |
77c8bed2 | 11015 | |
ca4c3545 | 11016 | if (!INTEGRAL_TYPE_P (TREE_TYPE (t))) |
11017 | { | |
11018 | c_parser_error (parser, "expected integer expression"); | |
11019 | return list; | |
11020 | } | |
77c8bed2 | 11021 | |
ca4c3545 | 11022 | /* Attempt to statically determine when the number isn't positive. */ |
11023 | c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t, | |
11024 | build_int_cst (TREE_TYPE (t), 0)); | |
11025 | if (CAN_HAVE_LOCATION_P (c)) | |
11026 | SET_EXPR_LOCATION (c, expr_loc); | |
11027 | if (c == boolean_true_node) | |
11028 | { | |
11029 | warning_at (expr_loc, 0, | |
11030 | "%<vector_length%> value must be positive"); | |
11031 | t = integer_one_node; | |
11032 | } | |
11033 | ||
11034 | check_no_duplicate_clause (list, OMP_CLAUSE_VECTOR_LENGTH, "vector_length"); | |
11035 | ||
11036 | c = build_omp_clause (vector_length_loc, OMP_CLAUSE_VECTOR_LENGTH); | |
11037 | OMP_CLAUSE_VECTOR_LENGTH_EXPR (c) = t; | |
11038 | OMP_CLAUSE_CHAIN (c) = list; | |
11039 | list = c; | |
11040 | } | |
11041 | ||
11042 | return list; | |
11043 | } | |
11044 | ||
11045 | /* OpenMP 4.0: | |
11046 | inbranch | |
11047 | notinbranch */ | |
11048 | ||
11049 | static tree | |
11050 | c_parser_omp_clause_branch (c_parser *parser ATTRIBUTE_UNUSED, | |
11051 | enum omp_clause_code code, tree list) | |
11052 | { | |
11053 | check_no_duplicate_clause (list, code, omp_clause_code_name[code]); | |
11054 | ||
11055 | tree c = build_omp_clause (c_parser_peek_token (parser)->location, code); | |
11056 | OMP_CLAUSE_CHAIN (c) = list; | |
11057 | ||
11058 | return c; | |
11059 | } | |
11060 | ||
11061 | /* OpenMP 4.0: | |
11062 | parallel | |
11063 | for | |
11064 | sections | |
11065 | taskgroup */ | |
11066 | ||
11067 | static tree | |
11068 | c_parser_omp_clause_cancelkind (c_parser *parser ATTRIBUTE_UNUSED, | |
11069 | enum omp_clause_code code, tree list) | |
11070 | { | |
11071 | tree c = build_omp_clause (c_parser_peek_token (parser)->location, code); | |
11072 | OMP_CLAUSE_CHAIN (c) = list; | |
bc7bff74 | 11073 | |
11074 | return c; | |
11075 | } | |
11076 | ||
11077 | /* OpenMP 4.0: | |
11078 | num_teams ( expression ) */ | |
11079 | ||
11080 | static tree | |
11081 | c_parser_omp_clause_num_teams (c_parser *parser, tree list) | |
11082 | { | |
11083 | location_t num_teams_loc = c_parser_peek_token (parser)->location; | |
11084 | if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
11085 | { | |
11086 | location_t expr_loc = c_parser_peek_token (parser)->location; | |
11087 | tree c, t = c_parser_expression (parser).value; | |
11088 | mark_exp_read (t); | |
11089 | t = c_fully_fold (t, false, NULL); | |
11090 | ||
11091 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
11092 | ||
11093 | if (!INTEGRAL_TYPE_P (TREE_TYPE (t))) | |
1e8e9920 | 11094 | { |
bc7bff74 | 11095 | c_parser_error (parser, "expected integer expression"); |
11096 | return list; | |
1e8e9920 | 11097 | } |
11098 | ||
bc7bff74 | 11099 | /* Attempt to statically determine when the number isn't positive. */ |
11100 | c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t, | |
11101 | build_int_cst (TREE_TYPE (t), 0)); | |
11102 | if (CAN_HAVE_LOCATION_P (c)) | |
11103 | SET_EXPR_LOCATION (c, expr_loc); | |
11104 | if (c == boolean_true_node) | |
1e8e9920 | 11105 | { |
bc7bff74 | 11106 | warning_at (expr_loc, 0, "%<num_teams%> value must be positive"); |
11107 | t = integer_one_node; | |
1e8e9920 | 11108 | } |
1e8e9920 | 11109 | |
bc7bff74 | 11110 | check_no_duplicate_clause (list, OMP_CLAUSE_NUM_TEAMS, "num_teams"); |
1e8e9920 | 11111 | |
bc7bff74 | 11112 | c = build_omp_clause (num_teams_loc, OMP_CLAUSE_NUM_TEAMS); |
11113 | OMP_CLAUSE_NUM_TEAMS_EXPR (c) = t; | |
11114 | OMP_CLAUSE_CHAIN (c) = list; | |
11115 | list = c; | |
11116 | } | |
1e8e9920 | 11117 | |
bc7bff74 | 11118 | return list; |
11119 | } | |
1e8e9920 | 11120 | |
bc7bff74 | 11121 | /* OpenMP 4.0: |
11122 | thread_limit ( expression ) */ | |
1e8e9920 | 11123 | |
11124 | static tree | |
bc7bff74 | 11125 | c_parser_omp_clause_thread_limit (c_parser *parser, tree list) |
1e8e9920 | 11126 | { |
22ac3f78 | 11127 | location_t num_thread_limit_loc = c_parser_peek_token (parser)->location; |
bc7bff74 | 11128 | if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) |
11129 | { | |
11130 | location_t expr_loc = c_parser_peek_token (parser)->location; | |
11131 | tree c, t = c_parser_expression (parser).value; | |
11132 | mark_exp_read (t); | |
11133 | t = c_fully_fold (t, false, NULL); | |
1e8e9920 | 11134 | |
bc7bff74 | 11135 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); |
1e8e9920 | 11136 | |
bc7bff74 | 11137 | if (!INTEGRAL_TYPE_P (TREE_TYPE (t))) |
11138 | { | |
11139 | c_parser_error (parser, "expected integer expression"); | |
11140 | return list; | |
11141 | } | |
1e8e9920 | 11142 | |
bc7bff74 | 11143 | /* Attempt to statically determine when the number isn't positive. */ |
11144 | c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t, | |
11145 | build_int_cst (TREE_TYPE (t), 0)); | |
11146 | if (CAN_HAVE_LOCATION_P (c)) | |
11147 | SET_EXPR_LOCATION (c, expr_loc); | |
11148 | if (c == boolean_true_node) | |
11149 | { | |
11150 | warning_at (expr_loc, 0, "%<thread_limit%> value must be positive"); | |
11151 | t = integer_one_node; | |
11152 | } | |
e60a6f7b | 11153 | |
bc7bff74 | 11154 | check_no_duplicate_clause (list, OMP_CLAUSE_THREAD_LIMIT, |
11155 | "thread_limit"); | |
2169f33b | 11156 | |
22ac3f78 | 11157 | c = build_omp_clause (num_thread_limit_loc, OMP_CLAUSE_THREAD_LIMIT); |
bc7bff74 | 11158 | OMP_CLAUSE_THREAD_LIMIT_EXPR (c) = t; |
11159 | OMP_CLAUSE_CHAIN (c) = list; | |
11160 | list = c; | |
11161 | } | |
2169f33b | 11162 | |
bc7bff74 | 11163 | return list; |
11164 | } | |
2169f33b | 11165 | |
bc7bff74 | 11166 | /* OpenMP 4.0: |
11167 | aligned ( variable-list ) | |
11168 | aligned ( variable-list : constant-expression ) */ | |
2169f33b | 11169 | |
bc7bff74 | 11170 | static tree |
11171 | c_parser_omp_clause_aligned (c_parser *parser, tree list) | |
11172 | { | |
11173 | location_t clause_loc = c_parser_peek_token (parser)->location; | |
11174 | tree nl, c; | |
2169f33b | 11175 | |
bc7bff74 | 11176 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) |
11177 | return list; | |
2169f33b | 11178 | |
bc7bff74 | 11179 | nl = c_parser_omp_variable_list (parser, clause_loc, |
11180 | OMP_CLAUSE_ALIGNED, list); | |
2169f33b | 11181 | |
bc7bff74 | 11182 | if (c_parser_next_token_is (parser, CPP_COLON)) |
11183 | { | |
11184 | c_parser_consume_token (parser); | |
11185 | tree alignment = c_parser_expr_no_commas (parser, NULL).value; | |
11186 | mark_exp_read (alignment); | |
11187 | alignment = c_fully_fold (alignment, false, NULL); | |
11188 | if (!INTEGRAL_TYPE_P (TREE_TYPE (alignment)) | |
11189 | && TREE_CODE (alignment) != INTEGER_CST | |
11190 | && tree_int_cst_sgn (alignment) != 1) | |
11191 | { | |
11192 | error_at (clause_loc, "%<aligned%> clause alignment expression must " | |
11193 | "be positive constant integer expression"); | |
11194 | alignment = NULL_TREE; | |
11195 | } | |
2169f33b | 11196 | |
bc7bff74 | 11197 | for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c)) |
11198 | OMP_CLAUSE_ALIGNED_ALIGNMENT (c) = alignment; | |
11199 | } | |
1e8e9920 | 11200 | |
bc7bff74 | 11201 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); |
11202 | return nl; | |
11203 | } | |
11204 | ||
11205 | /* OpenMP 4.0: | |
11206 | linear ( variable-list ) | |
11207 | linear ( variable-list : expression ) */ | |
11208 | ||
11209 | static tree | |
74acc703 | 11210 | c_parser_omp_clause_linear (c_parser *parser, tree list, bool is_cilk_simd_fn) |
1e8e9920 | 11211 | { |
bc7bff74 | 11212 | location_t clause_loc = c_parser_peek_token (parser)->location; |
11213 | tree nl, c, step; | |
11214 | ||
11215 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
11216 | return list; | |
11217 | ||
11218 | nl = c_parser_omp_variable_list (parser, clause_loc, | |
11219 | OMP_CLAUSE_LINEAR, list); | |
11220 | ||
11221 | if (c_parser_next_token_is (parser, CPP_COLON)) | |
11222 | { | |
11223 | c_parser_consume_token (parser); | |
11224 | step = c_parser_expression (parser).value; | |
11225 | mark_exp_read (step); | |
11226 | step = c_fully_fold (step, false, NULL); | |
74acc703 | 11227 | if (is_cilk_simd_fn && TREE_CODE (step) == PARM_DECL) |
11228 | { | |
11229 | sorry ("using parameters for %<linear%> step is not supported yet"); | |
11230 | step = integer_one_node; | |
11231 | } | |
bc7bff74 | 11232 | if (!INTEGRAL_TYPE_P (TREE_TYPE (step))) |
11233 | { | |
11234 | error_at (clause_loc, "%<linear%> clause step expression must " | |
11235 | "be integral"); | |
11236 | step = integer_one_node; | |
11237 | } | |
11238 | ||
11239 | } | |
11240 | else | |
11241 | step = integer_one_node; | |
11242 | ||
11243 | for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c)) | |
11244 | { | |
11245 | OMP_CLAUSE_LINEAR_STEP (c) = step; | |
11246 | } | |
11247 | ||
11248 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
11249 | return nl; | |
11250 | } | |
11251 | ||
11252 | /* OpenMP 4.0: | |
11253 | safelen ( constant-expression ) */ | |
11254 | ||
11255 | static tree | |
11256 | c_parser_omp_clause_safelen (c_parser *parser, tree list) | |
11257 | { | |
11258 | location_t clause_loc = c_parser_peek_token (parser)->location; | |
11259 | tree c, t; | |
11260 | ||
11261 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
11262 | return list; | |
11263 | ||
11264 | t = c_parser_expr_no_commas (parser, NULL).value; | |
11265 | mark_exp_read (t); | |
11266 | t = c_fully_fold (t, false, NULL); | |
11267 | if (!INTEGRAL_TYPE_P (TREE_TYPE (t)) | |
11268 | && TREE_CODE (t) != INTEGER_CST | |
11269 | && tree_int_cst_sgn (t) != 1) | |
11270 | { | |
11271 | error_at (clause_loc, "%<safelen%> clause expression must " | |
11272 | "be positive constant integer expression"); | |
11273 | t = NULL_TREE; | |
11274 | } | |
11275 | ||
11276 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
11277 | if (t == NULL_TREE || t == error_mark_node) | |
11278 | return list; | |
11279 | ||
11280 | check_no_duplicate_clause (list, OMP_CLAUSE_SAFELEN, "safelen"); | |
11281 | ||
11282 | c = build_omp_clause (clause_loc, OMP_CLAUSE_SAFELEN); | |
11283 | OMP_CLAUSE_SAFELEN_EXPR (c) = t; | |
11284 | OMP_CLAUSE_CHAIN (c) = list; | |
11285 | return c; | |
11286 | } | |
11287 | ||
11288 | /* OpenMP 4.0: | |
11289 | simdlen ( constant-expression ) */ | |
11290 | ||
11291 | static tree | |
11292 | c_parser_omp_clause_simdlen (c_parser *parser, tree list) | |
11293 | { | |
11294 | location_t clause_loc = c_parser_peek_token (parser)->location; | |
11295 | tree c, t; | |
11296 | ||
11297 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
11298 | return list; | |
11299 | ||
11300 | t = c_parser_expr_no_commas (parser, NULL).value; | |
11301 | mark_exp_read (t); | |
11302 | t = c_fully_fold (t, false, NULL); | |
11303 | if (!INTEGRAL_TYPE_P (TREE_TYPE (t)) | |
11304 | && TREE_CODE (t) != INTEGER_CST | |
11305 | && tree_int_cst_sgn (t) != 1) | |
11306 | { | |
11307 | error_at (clause_loc, "%<simdlen%> clause expression must " | |
11308 | "be positive constant integer expression"); | |
11309 | t = NULL_TREE; | |
11310 | } | |
11311 | ||
11312 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
11313 | if (t == NULL_TREE || t == error_mark_node) | |
11314 | return list; | |
11315 | ||
11316 | check_no_duplicate_clause (list, OMP_CLAUSE_SIMDLEN, "simdlen"); | |
11317 | ||
11318 | c = build_omp_clause (clause_loc, OMP_CLAUSE_SIMDLEN); | |
11319 | OMP_CLAUSE_SIMDLEN_EXPR (c) = t; | |
11320 | OMP_CLAUSE_CHAIN (c) = list; | |
11321 | return c; | |
11322 | } | |
11323 | ||
11324 | /* OpenMP 4.0: | |
11325 | depend ( depend-kind: variable-list ) | |
11326 | ||
11327 | depend-kind: | |
11328 | in | out | inout */ | |
11329 | ||
11330 | static tree | |
11331 | c_parser_omp_clause_depend (c_parser *parser, tree list) | |
11332 | { | |
11333 | location_t clause_loc = c_parser_peek_token (parser)->location; | |
11334 | enum omp_clause_depend_kind kind = OMP_CLAUSE_DEPEND_INOUT; | |
11335 | tree nl, c; | |
11336 | ||
11337 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
11338 | return list; | |
1e8e9920 | 11339 | |
2169f33b | 11340 | if (c_parser_next_token_is (parser, CPP_NAME)) |
11341 | { | |
11342 | const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); | |
bc7bff74 | 11343 | if (strcmp ("in", p) == 0) |
11344 | kind = OMP_CLAUSE_DEPEND_IN; | |
11345 | else if (strcmp ("inout", p) == 0) | |
11346 | kind = OMP_CLAUSE_DEPEND_INOUT; | |
11347 | else if (strcmp ("out", p) == 0) | |
11348 | kind = OMP_CLAUSE_DEPEND_OUT; | |
2169f33b | 11349 | else |
bc7bff74 | 11350 | goto invalid_kind; |
2169f33b | 11351 | } |
bc7bff74 | 11352 | else |
11353 | goto invalid_kind; | |
1e8e9920 | 11354 | |
bc7bff74 | 11355 | c_parser_consume_token (parser); |
11356 | if (!c_parser_require (parser, CPP_COLON, "expected %<:%>")) | |
11357 | goto resync_fail; | |
11358 | ||
11359 | nl = c_parser_omp_variable_list (parser, clause_loc, | |
11360 | OMP_CLAUSE_DEPEND, list); | |
11361 | ||
11362 | for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c)) | |
11363 | OMP_CLAUSE_DEPEND_KIND (c) = kind; | |
11364 | ||
11365 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
11366 | return nl; | |
11367 | ||
11368 | invalid_kind: | |
11369 | c_parser_error (parser, "invalid depend kind"); | |
11370 | resync_fail: | |
11371 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
11372 | return list; | |
11373 | } | |
11374 | ||
11375 | /* OpenMP 4.0: | |
11376 | map ( map-kind: variable-list ) | |
11377 | map ( variable-list ) | |
11378 | ||
11379 | map-kind: | |
11380 | alloc | to | from | tofrom */ | |
11381 | ||
11382 | static tree | |
11383 | c_parser_omp_clause_map (c_parser *parser, tree list) | |
11384 | { | |
11385 | location_t clause_loc = c_parser_peek_token (parser)->location; | |
ca4c3545 | 11386 | enum gomp_map_kind kind = GOMP_MAP_TOFROM; |
bc7bff74 | 11387 | tree nl, c; |
11388 | ||
11389 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
11390 | return list; | |
11391 | ||
11392 | if (c_parser_next_token_is (parser, CPP_NAME) | |
11393 | && c_parser_peek_2nd_token (parser)->type == CPP_COLON) | |
2169f33b | 11394 | { |
bc7bff74 | 11395 | const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
11396 | if (strcmp ("alloc", p) == 0) | |
ca4c3545 | 11397 | kind = GOMP_MAP_ALLOC; |
bc7bff74 | 11398 | else if (strcmp ("to", p) == 0) |
ca4c3545 | 11399 | kind = GOMP_MAP_TO; |
bc7bff74 | 11400 | else if (strcmp ("from", p) == 0) |
ca4c3545 | 11401 | kind = GOMP_MAP_FROM; |
bc7bff74 | 11402 | else if (strcmp ("tofrom", p) == 0) |
ca4c3545 | 11403 | kind = GOMP_MAP_TOFROM; |
2169f33b | 11404 | else |
11405 | { | |
bc7bff74 | 11406 | c_parser_error (parser, "invalid map kind"); |
11407 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, | |
11408 | "expected %<)%>"); | |
11409 | return list; | |
2169f33b | 11410 | } |
bc7bff74 | 11411 | c_parser_consume_token (parser); |
11412 | c_parser_consume_token (parser); | |
2169f33b | 11413 | } |
11414 | ||
bc7bff74 | 11415 | nl = c_parser_omp_variable_list (parser, clause_loc, OMP_CLAUSE_MAP, list); |
11416 | ||
11417 | for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c)) | |
ca4c3545 | 11418 | OMP_CLAUSE_SET_MAP_KIND (c, kind); |
bc7bff74 | 11419 | |
11420 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
11421 | return nl; | |
11422 | } | |
11423 | ||
11424 | /* OpenMP 4.0: | |
11425 | device ( expression ) */ | |
11426 | ||
11427 | static tree | |
11428 | c_parser_omp_clause_device (c_parser *parser, tree list) | |
11429 | { | |
11430 | location_t clause_loc = c_parser_peek_token (parser)->location; | |
11431 | if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
1e8e9920 | 11432 | { |
bc7bff74 | 11433 | tree c, t = c_parser_expr_no_commas (parser, NULL).value; |
11434 | mark_exp_read (t); | |
11435 | t = c_fully_fold (t, false, NULL); | |
11436 | ||
11437 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
11438 | ||
11439 | if (!INTEGRAL_TYPE_P (TREE_TYPE (t))) | |
2169f33b | 11440 | { |
bc7bff74 | 11441 | c_parser_error (parser, "expected integer expression"); |
11442 | return list; | |
2169f33b | 11443 | } |
1e8e9920 | 11444 | |
bc7bff74 | 11445 | check_no_duplicate_clause (list, OMP_CLAUSE_DEVICE, "device"); |
1e8e9920 | 11446 | |
bc7bff74 | 11447 | c = build_omp_clause (clause_loc, OMP_CLAUSE_DEVICE); |
11448 | OMP_CLAUSE_DEVICE_ID (c) = t; | |
11449 | OMP_CLAUSE_CHAIN (c) = list; | |
11450 | list = c; | |
11451 | } | |
1e8e9920 | 11452 | |
bc7bff74 | 11453 | return list; |
11454 | } | |
2169f33b | 11455 | |
bc7bff74 | 11456 | /* OpenMP 4.0: |
11457 | dist_schedule ( static ) | |
11458 | dist_schedule ( static , expression ) */ | |
1e8e9920 | 11459 | |
bc7bff74 | 11460 | static tree |
11461 | c_parser_omp_clause_dist_schedule (c_parser *parser, tree list) | |
11462 | { | |
11463 | tree c, t = NULL_TREE; | |
11464 | location_t loc = c_parser_peek_token (parser)->location; | |
11465 | ||
11466 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
11467 | return list; | |
11468 | ||
11469 | if (!c_parser_next_token_is_keyword (parser, RID_STATIC)) | |
2169f33b | 11470 | { |
bc7bff74 | 11471 | c_parser_error (parser, "invalid dist_schedule kind"); |
11472 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, | |
11473 | "expected %<)%>"); | |
11474 | return list; | |
2169f33b | 11475 | } |
1e8e9920 | 11476 | |
bc7bff74 | 11477 | c_parser_consume_token (parser); |
11478 | if (c_parser_next_token_is (parser, CPP_COMMA)) | |
11479 | { | |
11480 | c_parser_consume_token (parser); | |
1e8e9920 | 11481 | |
bc7bff74 | 11482 | t = c_parser_expr_no_commas (parser, NULL).value; |
11483 | mark_exp_read (t); | |
11484 | t = c_fully_fold (t, false, NULL); | |
11485 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
11486 | } | |
11487 | else | |
11488 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, | |
11489 | "expected %<,%> or %<)%>"); | |
1e8e9920 | 11490 | |
bc7bff74 | 11491 | check_no_duplicate_clause (list, OMP_CLAUSE_SCHEDULE, "schedule"); |
11492 | if (t == error_mark_node) | |
11493 | return list; | |
1e8e9920 | 11494 | |
bc7bff74 | 11495 | c = build_omp_clause (loc, OMP_CLAUSE_DIST_SCHEDULE); |
11496 | OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c) = t; | |
11497 | OMP_CLAUSE_CHAIN (c) = list; | |
11498 | return c; | |
1e8e9920 | 11499 | } |
11500 | ||
bc7bff74 | 11501 | /* OpenMP 4.0: |
11502 | proc_bind ( proc-bind-kind ) | |
e60a6f7b | 11503 | |
bc7bff74 | 11504 | proc-bind-kind: |
11505 | master | close | spread */ | |
1e8e9920 | 11506 | |
11507 | static tree | |
bc7bff74 | 11508 | c_parser_omp_clause_proc_bind (c_parser *parser, tree list) |
1e8e9920 | 11509 | { |
bc7bff74 | 11510 | location_t clause_loc = c_parser_peek_token (parser)->location; |
11511 | enum omp_clause_proc_bind_kind kind; | |
11512 | tree c; | |
1e8e9920 | 11513 | |
bc7bff74 | 11514 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) |
11515 | return list; | |
11516 | ||
11517 | if (c_parser_next_token_is (parser, CPP_NAME)) | |
1e8e9920 | 11518 | { |
bc7bff74 | 11519 | const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
11520 | if (strcmp ("master", p) == 0) | |
11521 | kind = OMP_CLAUSE_PROC_BIND_MASTER; | |
11522 | else if (strcmp ("close", p) == 0) | |
11523 | kind = OMP_CLAUSE_PROC_BIND_CLOSE; | |
11524 | else if (strcmp ("spread", p) == 0) | |
11525 | kind = OMP_CLAUSE_PROC_BIND_SPREAD; | |
1e8e9920 | 11526 | else |
bc7bff74 | 11527 | goto invalid_kind; |
1e8e9920 | 11528 | } |
bc7bff74 | 11529 | else |
11530 | goto invalid_kind; | |
1e8e9920 | 11531 | |
bc7bff74 | 11532 | c_parser_consume_token (parser); |
11533 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
11534 | c = build_omp_clause (clause_loc, OMP_CLAUSE_PROC_BIND); | |
11535 | OMP_CLAUSE_PROC_BIND_KIND (c) = kind; | |
11536 | OMP_CLAUSE_CHAIN (c) = list; | |
11537 | return c; | |
1e8e9920 | 11538 | |
bc7bff74 | 11539 | invalid_kind: |
11540 | c_parser_error (parser, "invalid proc_bind kind"); | |
11541 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
11542 | return list; | |
11543 | } | |
1e8e9920 | 11544 | |
bc7bff74 | 11545 | /* OpenMP 4.0: |
11546 | to ( variable-list ) */ | |
1e8e9920 | 11547 | |
bc7bff74 | 11548 | static tree |
11549 | c_parser_omp_clause_to (c_parser *parser, tree list) | |
1e8e9920 | 11550 | { |
bc7bff74 | 11551 | return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_TO, list); |
1e8e9920 | 11552 | } |
11553 | ||
bc7bff74 | 11554 | /* OpenMP 4.0: |
11555 | from ( variable-list ) */ | |
1e8e9920 | 11556 | |
11557 | static tree | |
bc7bff74 | 11558 | c_parser_omp_clause_from (c_parser *parser, tree list) |
1e8e9920 | 11559 | { |
bc7bff74 | 11560 | return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_FROM, list); |
11561 | } | |
fd6481cf | 11562 | |
bc7bff74 | 11563 | /* OpenMP 4.0: |
11564 | uniform ( variable-list ) */ | |
fd6481cf | 11565 | |
bc7bff74 | 11566 | static tree |
11567 | c_parser_omp_clause_uniform (c_parser *parser, tree list) | |
11568 | { | |
11569 | /* The clauses location. */ | |
11570 | location_t loc = c_parser_peek_token (parser)->location; | |
1e8e9920 | 11571 | |
bc7bff74 | 11572 | if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) |
1e8e9920 | 11573 | { |
bc7bff74 | 11574 | list = c_parser_omp_variable_list (parser, loc, OMP_CLAUSE_UNIFORM, |
11575 | list); | |
11576 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
1e8e9920 | 11577 | } |
bc7bff74 | 11578 | return list; |
11579 | } | |
1e8e9920 | 11580 | |
ca4c3545 | 11581 | /* Parse all OpenACC clauses. The set clauses allowed by the directive |
11582 | is a bitmask in MASK. Return the list of clauses found. */ | |
11583 | ||
11584 | static tree | |
11585 | c_parser_oacc_all_clauses (c_parser *parser, omp_clause_mask mask, | |
11586 | const char *where, bool finish_p = true) | |
11587 | { | |
11588 | tree clauses = NULL; | |
11589 | bool first = true; | |
11590 | ||
11591 | while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL)) | |
11592 | { | |
11593 | location_t here; | |
11594 | pragma_omp_clause c_kind; | |
11595 | const char *c_name; | |
11596 | tree prev = clauses; | |
11597 | ||
11598 | if (!first && c_parser_next_token_is (parser, CPP_COMMA)) | |
11599 | c_parser_consume_token (parser); | |
11600 | ||
11601 | here = c_parser_peek_token (parser)->location; | |
11602 | c_kind = c_parser_omp_clause_name (parser); | |
11603 | ||
11604 | switch (c_kind) | |
11605 | { | |
11606 | case PRAGMA_OACC_CLAUSE_ASYNC: | |
11607 | clauses = c_parser_oacc_clause_async (parser, clauses); | |
11608 | c_name = "async"; | |
11609 | break; | |
11610 | case PRAGMA_OACC_CLAUSE_COLLAPSE: | |
11611 | clauses = c_parser_omp_clause_collapse (parser, clauses); | |
11612 | c_name = "collapse"; | |
11613 | break; | |
11614 | case PRAGMA_OACC_CLAUSE_COPY: | |
11615 | clauses = c_parser_oacc_data_clause (parser, c_kind, clauses); | |
11616 | c_name = "copy"; | |
11617 | break; | |
11618 | case PRAGMA_OACC_CLAUSE_COPYIN: | |
11619 | clauses = c_parser_oacc_data_clause (parser, c_kind, clauses); | |
11620 | c_name = "copyin"; | |
11621 | break; | |
11622 | case PRAGMA_OACC_CLAUSE_COPYOUT: | |
11623 | clauses = c_parser_oacc_data_clause (parser, c_kind, clauses); | |
11624 | c_name = "copyout"; | |
11625 | break; | |
11626 | case PRAGMA_OACC_CLAUSE_CREATE: | |
11627 | clauses = c_parser_oacc_data_clause (parser, c_kind, clauses); | |
11628 | c_name = "create"; | |
11629 | break; | |
11630 | case PRAGMA_OACC_CLAUSE_DELETE: | |
11631 | clauses = c_parser_oacc_data_clause (parser, c_kind, clauses); | |
11632 | c_name = "delete"; | |
11633 | break; | |
11634 | case PRAGMA_OACC_CLAUSE_DEVICE: | |
11635 | clauses = c_parser_oacc_data_clause (parser, c_kind, clauses); | |
11636 | c_name = "device"; | |
11637 | break; | |
11638 | case PRAGMA_OACC_CLAUSE_DEVICEPTR: | |
11639 | clauses = c_parser_oacc_data_clause_deviceptr (parser, clauses); | |
11640 | c_name = "deviceptr"; | |
11641 | break; | |
11642 | case PRAGMA_OACC_CLAUSE_FIRSTPRIVATE: | |
11643 | clauses = c_parser_omp_clause_firstprivate (parser, clauses); | |
11644 | c_name = "firstprivate"; | |
11645 | break; | |
11646 | case PRAGMA_OACC_CLAUSE_HOST: | |
11647 | clauses = c_parser_oacc_data_clause (parser, c_kind, clauses); | |
11648 | c_name = "host"; | |
11649 | break; | |
11650 | case PRAGMA_OACC_CLAUSE_IF: | |
11651 | clauses = c_parser_omp_clause_if (parser, clauses); | |
11652 | c_name = "if"; | |
11653 | break; | |
11654 | case PRAGMA_OACC_CLAUSE_NUM_GANGS: | |
11655 | clauses = c_parser_omp_clause_num_gangs (parser, clauses); | |
11656 | c_name = "num_gangs"; | |
11657 | break; | |
11658 | case PRAGMA_OACC_CLAUSE_NUM_WORKERS: | |
11659 | clauses = c_parser_omp_clause_num_workers (parser, clauses); | |
11660 | c_name = "num_workers"; | |
11661 | break; | |
11662 | case PRAGMA_OACC_CLAUSE_PRESENT: | |
11663 | clauses = c_parser_oacc_data_clause (parser, c_kind, clauses); | |
11664 | c_name = "present"; | |
11665 | break; | |
11666 | case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY: | |
11667 | clauses = c_parser_oacc_data_clause (parser, c_kind, clauses); | |
11668 | c_name = "present_or_copy"; | |
11669 | break; | |
11670 | case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN: | |
11671 | clauses = c_parser_oacc_data_clause (parser, c_kind, clauses); | |
11672 | c_name = "present_or_copyin"; | |
11673 | break; | |
11674 | case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT: | |
11675 | clauses = c_parser_oacc_data_clause (parser, c_kind, clauses); | |
11676 | c_name = "present_or_copyout"; | |
11677 | break; | |
11678 | case PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE: | |
11679 | clauses = c_parser_oacc_data_clause (parser, c_kind, clauses); | |
11680 | c_name = "present_or_create"; | |
11681 | break; | |
11682 | case PRAGMA_OACC_CLAUSE_PRIVATE: | |
11683 | clauses = c_parser_omp_clause_private (parser, clauses); | |
11684 | c_name = "private"; | |
11685 | break; | |
11686 | case PRAGMA_OACC_CLAUSE_REDUCTION: | |
11687 | clauses = c_parser_omp_clause_reduction (parser, clauses); | |
11688 | c_name = "reduction"; | |
11689 | break; | |
11690 | case PRAGMA_OACC_CLAUSE_SELF: | |
11691 | clauses = c_parser_oacc_data_clause (parser, c_kind, clauses); | |
11692 | c_name = "self"; | |
11693 | break; | |
11694 | case PRAGMA_OACC_CLAUSE_VECTOR_LENGTH: | |
11695 | clauses = c_parser_omp_clause_vector_length (parser, clauses); | |
11696 | c_name = "vector_length"; | |
11697 | break; | |
11698 | case PRAGMA_OACC_CLAUSE_WAIT: | |
11699 | clauses = c_parser_oacc_clause_wait (parser, clauses); | |
11700 | c_name = "wait"; | |
11701 | break; | |
11702 | default: | |
11703 | c_parser_error (parser, "expected %<#pragma acc%> clause"); | |
11704 | goto saw_error; | |
11705 | } | |
11706 | ||
11707 | first = false; | |
11708 | ||
11709 | if (((mask >> c_kind) & 1) == 0 && !parser->error) | |
11710 | { | |
11711 | /* Remove the invalid clause(s) from the list to avoid | |
11712 | confusing the rest of the compiler. */ | |
11713 | clauses = prev; | |
11714 | error_at (here, "%qs is not valid for %qs", c_name, where); | |
11715 | } | |
11716 | } | |
11717 | ||
11718 | saw_error: | |
11719 | c_parser_skip_to_pragma_eol (parser); | |
11720 | ||
11721 | if (finish_p) | |
11722 | return c_finish_omp_clauses (clauses); | |
11723 | ||
11724 | return clauses; | |
11725 | } | |
11726 | ||
bc7bff74 | 11727 | /* Parse all OpenMP clauses. The set clauses allowed by the directive |
ca4c3545 | 11728 | is a bitmask in MASK. Return the list of clauses found. */ |
1e8e9920 | 11729 | |
bc7bff74 | 11730 | static tree |
11731 | c_parser_omp_all_clauses (c_parser *parser, omp_clause_mask mask, | |
11732 | const char *where, bool finish_p = true) | |
11733 | { | |
11734 | tree clauses = NULL; | |
74acc703 | 11735 | bool first = true, cilk_simd_fn = false; |
1e8e9920 | 11736 | |
bc7bff74 | 11737 | while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL)) |
11738 | { | |
11739 | location_t here; | |
11740 | pragma_omp_clause c_kind; | |
11741 | const char *c_name; | |
11742 | tree prev = clauses; | |
11743 | ||
11744 | if (!first && c_parser_next_token_is (parser, CPP_COMMA)) | |
11745 | c_parser_consume_token (parser); | |
11746 | ||
11747 | here = c_parser_peek_token (parser)->location; | |
11748 | c_kind = c_parser_omp_clause_name (parser); | |
11749 | ||
11750 | switch (c_kind) | |
fd6481cf | 11751 | { |
bc7bff74 | 11752 | case PRAGMA_OMP_CLAUSE_COLLAPSE: |
11753 | clauses = c_parser_omp_clause_collapse (parser, clauses); | |
11754 | c_name = "collapse"; | |
1e8e9920 | 11755 | break; |
bc7bff74 | 11756 | case PRAGMA_OMP_CLAUSE_COPYIN: |
11757 | clauses = c_parser_omp_clause_copyin (parser, clauses); | |
11758 | c_name = "copyin"; | |
1e8e9920 | 11759 | break; |
bc7bff74 | 11760 | case PRAGMA_OMP_CLAUSE_COPYPRIVATE: |
11761 | clauses = c_parser_omp_clause_copyprivate (parser, clauses); | |
11762 | c_name = "copyprivate"; | |
1e8e9920 | 11763 | break; |
bc7bff74 | 11764 | case PRAGMA_OMP_CLAUSE_DEFAULT: |
11765 | clauses = c_parser_omp_clause_default (parser, clauses); | |
11766 | c_name = "default"; | |
1e8e9920 | 11767 | break; |
bc7bff74 | 11768 | case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE: |
11769 | clauses = c_parser_omp_clause_firstprivate (parser, clauses); | |
11770 | c_name = "firstprivate"; | |
1e8e9920 | 11771 | break; |
bc7bff74 | 11772 | case PRAGMA_OMP_CLAUSE_FINAL: |
11773 | clauses = c_parser_omp_clause_final (parser, clauses); | |
11774 | c_name = "final"; | |
1e8e9920 | 11775 | break; |
bc7bff74 | 11776 | case PRAGMA_OMP_CLAUSE_IF: |
11777 | clauses = c_parser_omp_clause_if (parser, clauses); | |
11778 | c_name = "if"; | |
1e8e9920 | 11779 | break; |
bc7bff74 | 11780 | case PRAGMA_OMP_CLAUSE_LASTPRIVATE: |
11781 | clauses = c_parser_omp_clause_lastprivate (parser, clauses); | |
11782 | c_name = "lastprivate"; | |
1e8e9920 | 11783 | break; |
bc7bff74 | 11784 | case PRAGMA_OMP_CLAUSE_MERGEABLE: |
11785 | clauses = c_parser_omp_clause_mergeable (parser, clauses); | |
11786 | c_name = "mergeable"; | |
1e8e9920 | 11787 | break; |
bc7bff74 | 11788 | case PRAGMA_OMP_CLAUSE_NOWAIT: |
11789 | clauses = c_parser_omp_clause_nowait (parser, clauses); | |
11790 | c_name = "nowait"; | |
11791 | break; | |
11792 | case PRAGMA_OMP_CLAUSE_NUM_THREADS: | |
11793 | clauses = c_parser_omp_clause_num_threads (parser, clauses); | |
11794 | c_name = "num_threads"; | |
11795 | break; | |
11796 | case PRAGMA_OMP_CLAUSE_ORDERED: | |
11797 | clauses = c_parser_omp_clause_ordered (parser, clauses); | |
11798 | c_name = "ordered"; | |
11799 | break; | |
11800 | case PRAGMA_OMP_CLAUSE_PRIVATE: | |
11801 | clauses = c_parser_omp_clause_private (parser, clauses); | |
11802 | c_name = "private"; | |
11803 | break; | |
11804 | case PRAGMA_OMP_CLAUSE_REDUCTION: | |
11805 | clauses = c_parser_omp_clause_reduction (parser, clauses); | |
11806 | c_name = "reduction"; | |
11807 | break; | |
11808 | case PRAGMA_OMP_CLAUSE_SCHEDULE: | |
11809 | clauses = c_parser_omp_clause_schedule (parser, clauses); | |
11810 | c_name = "schedule"; | |
11811 | break; | |
11812 | case PRAGMA_OMP_CLAUSE_SHARED: | |
11813 | clauses = c_parser_omp_clause_shared (parser, clauses); | |
11814 | c_name = "shared"; | |
11815 | break; | |
11816 | case PRAGMA_OMP_CLAUSE_UNTIED: | |
11817 | clauses = c_parser_omp_clause_untied (parser, clauses); | |
11818 | c_name = "untied"; | |
11819 | break; | |
11820 | case PRAGMA_OMP_CLAUSE_INBRANCH: | |
74acc703 | 11821 | case PRAGMA_CILK_CLAUSE_MASK: |
bc7bff74 | 11822 | clauses = c_parser_omp_clause_branch (parser, OMP_CLAUSE_INBRANCH, |
11823 | clauses); | |
11824 | c_name = "inbranch"; | |
11825 | break; | |
11826 | case PRAGMA_OMP_CLAUSE_NOTINBRANCH: | |
74acc703 | 11827 | case PRAGMA_CILK_CLAUSE_NOMASK: |
bc7bff74 | 11828 | clauses = c_parser_omp_clause_branch (parser, OMP_CLAUSE_NOTINBRANCH, |
11829 | clauses); | |
11830 | c_name = "notinbranch"; | |
11831 | break; | |
11832 | case PRAGMA_OMP_CLAUSE_PARALLEL: | |
11833 | clauses | |
11834 | = c_parser_omp_clause_cancelkind (parser, OMP_CLAUSE_PARALLEL, | |
11835 | clauses); | |
11836 | c_name = "parallel"; | |
11837 | if (!first) | |
2169f33b | 11838 | { |
bc7bff74 | 11839 | clause_not_first: |
11840 | error_at (here, "%qs must be the first clause of %qs", | |
11841 | c_name, where); | |
11842 | clauses = prev; | |
11843 | } | |
11844 | break; | |
11845 | case PRAGMA_OMP_CLAUSE_FOR: | |
11846 | clauses | |
11847 | = c_parser_omp_clause_cancelkind (parser, OMP_CLAUSE_FOR, | |
11848 | clauses); | |
11849 | c_name = "for"; | |
11850 | if (!first) | |
11851 | goto clause_not_first; | |
11852 | break; | |
11853 | case PRAGMA_OMP_CLAUSE_SECTIONS: | |
11854 | clauses | |
11855 | = c_parser_omp_clause_cancelkind (parser, OMP_CLAUSE_SECTIONS, | |
11856 | clauses); | |
11857 | c_name = "sections"; | |
11858 | if (!first) | |
11859 | goto clause_not_first; | |
11860 | break; | |
11861 | case PRAGMA_OMP_CLAUSE_TASKGROUP: | |
11862 | clauses | |
11863 | = c_parser_omp_clause_cancelkind (parser, OMP_CLAUSE_TASKGROUP, | |
11864 | clauses); | |
11865 | c_name = "taskgroup"; | |
11866 | if (!first) | |
11867 | goto clause_not_first; | |
11868 | break; | |
11869 | case PRAGMA_OMP_CLAUSE_TO: | |
11870 | clauses = c_parser_omp_clause_to (parser, clauses); | |
11871 | c_name = "to"; | |
11872 | break; | |
11873 | case PRAGMA_OMP_CLAUSE_FROM: | |
11874 | clauses = c_parser_omp_clause_from (parser, clauses); | |
11875 | c_name = "from"; | |
11876 | break; | |
11877 | case PRAGMA_OMP_CLAUSE_UNIFORM: | |
11878 | clauses = c_parser_omp_clause_uniform (parser, clauses); | |
11879 | c_name = "uniform"; | |
11880 | break; | |
11881 | case PRAGMA_OMP_CLAUSE_NUM_TEAMS: | |
11882 | clauses = c_parser_omp_clause_num_teams (parser, clauses); | |
11883 | c_name = "num_teams"; | |
11884 | break; | |
11885 | case PRAGMA_OMP_CLAUSE_THREAD_LIMIT: | |
11886 | clauses = c_parser_omp_clause_thread_limit (parser, clauses); | |
11887 | c_name = "thread_limit"; | |
11888 | break; | |
11889 | case PRAGMA_OMP_CLAUSE_ALIGNED: | |
11890 | clauses = c_parser_omp_clause_aligned (parser, clauses); | |
11891 | c_name = "aligned"; | |
11892 | break; | |
74acc703 | 11893 | case PRAGMA_OMP_CLAUSE_LINEAR: |
11894 | if (((mask >> PRAGMA_CILK_CLAUSE_VECTORLENGTH) & 1) != 0) | |
11895 | cilk_simd_fn = true; | |
11896 | clauses = c_parser_omp_clause_linear (parser, clauses, cilk_simd_fn); | |
bc7bff74 | 11897 | c_name = "linear"; |
11898 | break; | |
11899 | case PRAGMA_OMP_CLAUSE_DEPEND: | |
11900 | clauses = c_parser_omp_clause_depend (parser, clauses); | |
11901 | c_name = "depend"; | |
11902 | break; | |
11903 | case PRAGMA_OMP_CLAUSE_MAP: | |
11904 | clauses = c_parser_omp_clause_map (parser, clauses); | |
11905 | c_name = "map"; | |
11906 | break; | |
11907 | case PRAGMA_OMP_CLAUSE_DEVICE: | |
11908 | clauses = c_parser_omp_clause_device (parser, clauses); | |
11909 | c_name = "device"; | |
11910 | break; | |
11911 | case PRAGMA_OMP_CLAUSE_DIST_SCHEDULE: | |
11912 | clauses = c_parser_omp_clause_dist_schedule (parser, clauses); | |
11913 | c_name = "dist_schedule"; | |
11914 | break; | |
11915 | case PRAGMA_OMP_CLAUSE_PROC_BIND: | |
11916 | clauses = c_parser_omp_clause_proc_bind (parser, clauses); | |
11917 | c_name = "proc_bind"; | |
11918 | break; | |
11919 | case PRAGMA_OMP_CLAUSE_SAFELEN: | |
11920 | clauses = c_parser_omp_clause_safelen (parser, clauses); | |
11921 | c_name = "safelen"; | |
11922 | break; | |
74acc703 | 11923 | case PRAGMA_CILK_CLAUSE_VECTORLENGTH: |
11924 | clauses = c_parser_cilk_clause_vectorlength (parser, clauses, true); | |
11925 | c_name = "simdlen"; | |
11926 | break; | |
bc7bff74 | 11927 | case PRAGMA_OMP_CLAUSE_SIMDLEN: |
11928 | clauses = c_parser_omp_clause_simdlen (parser, clauses); | |
11929 | c_name = "simdlen"; | |
11930 | break; | |
1e8e9920 | 11931 | default: |
bc7bff74 | 11932 | c_parser_error (parser, "expected %<#pragma omp%> clause"); |
1e8e9920 | 11933 | goto saw_error; |
fd6481cf | 11934 | } |
1e8e9920 | 11935 | |
bc7bff74 | 11936 | first = false; |
11937 | ||
11938 | if (((mask >> c_kind) & 1) == 0 && !parser->error) | |
fd6481cf | 11939 | { |
bc7bff74 | 11940 | /* Remove the invalid clause(s) from the list to avoid |
11941 | confusing the rest of the compiler. */ | |
11942 | clauses = prev; | |
11943 | error_at (here, "%qs is not valid for %qs", c_name, where); | |
11944 | } | |
11945 | } | |
fd6481cf | 11946 | |
bc7bff74 | 11947 | saw_error: |
11948 | c_parser_skip_to_pragma_eol (parser); | |
fd6481cf | 11949 | |
bc7bff74 | 11950 | if (finish_p) |
11951 | return c_finish_omp_clauses (clauses); | |
fd6481cf | 11952 | |
bc7bff74 | 11953 | return clauses; |
11954 | } | |
1e8e9920 | 11955 | |
ca4c3545 | 11956 | /* OpenACC 2.0, OpenMP 2.5: |
bc7bff74 | 11957 | structured-block: |
11958 | statement | |
11959 | ||
11960 | In practice, we're also interested in adding the statement to an | |
11961 | outer node. So it is convenient if we work around the fact that | |
11962 | c_parser_statement calls add_stmt. */ | |
11963 | ||
11964 | static tree | |
11965 | c_parser_omp_structured_block (c_parser *parser) | |
11966 | { | |
11967 | tree stmt = push_stmt_list (); | |
11968 | c_parser_statement (parser); | |
11969 | return pop_stmt_list (stmt); | |
11970 | } | |
11971 | ||
ca4c3545 | 11972 | /* OpenACC 2.0: |
11973 | # pragma acc cache (variable-list) new-line | |
11974 | ||
11975 | LOC is the location of the #pragma token. | |
11976 | */ | |
11977 | ||
11978 | static tree | |
11979 | c_parser_oacc_cache (location_t loc, c_parser *parser) | |
11980 | { | |
11981 | tree stmt, clauses; | |
11982 | ||
11983 | clauses = c_parser_omp_var_list_parens (parser, OMP_CLAUSE__CACHE_, NULL); | |
11984 | clauses = c_finish_omp_clauses (clauses); | |
11985 | ||
11986 | c_parser_skip_to_pragma_eol (parser); | |
11987 | ||
11988 | stmt = make_node (OACC_CACHE); | |
11989 | TREE_TYPE (stmt) = void_type_node; | |
11990 | OACC_CACHE_CLAUSES (stmt) = clauses; | |
11991 | SET_EXPR_LOCATION (stmt, loc); | |
11992 | add_stmt (stmt); | |
11993 | ||
11994 | return stmt; | |
11995 | } | |
11996 | ||
11997 | /* OpenACC 2.0: | |
11998 | # pragma acc data oacc-data-clause[optseq] new-line | |
11999 | structured-block | |
12000 | ||
12001 | LOC is the location of the #pragma token. | |
12002 | */ | |
12003 | ||
12004 | #define OACC_DATA_CLAUSE_MASK \ | |
12005 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \ | |
12006 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \ | |
12007 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \ | |
12008 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \ | |
12009 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \ | |
12010 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \ | |
12011 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \ | |
12012 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY) \ | |
12013 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \ | |
12014 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT) \ | |
12015 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) ) | |
12016 | ||
12017 | static tree | |
12018 | c_parser_oacc_data (location_t loc, c_parser *parser) | |
12019 | { | |
12020 | tree stmt, clauses, block; | |
12021 | ||
12022 | clauses = c_parser_oacc_all_clauses (parser, OACC_DATA_CLAUSE_MASK, | |
12023 | "#pragma acc data"); | |
12024 | ||
12025 | block = c_begin_omp_parallel (); | |
12026 | add_stmt (c_parser_omp_structured_block (parser)); | |
12027 | ||
12028 | stmt = c_finish_oacc_data (loc, clauses, block); | |
12029 | ||
12030 | return stmt; | |
12031 | } | |
12032 | ||
12033 | /* OpenACC 2.0: | |
12034 | # pragma acc kernels oacc-kernels-clause[optseq] new-line | |
12035 | structured-block | |
12036 | ||
12037 | LOC is the location of the #pragma token. | |
12038 | */ | |
12039 | ||
12040 | #define OACC_KERNELS_CLAUSE_MASK \ | |
12041 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \ | |
12042 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \ | |
12043 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \ | |
12044 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \ | |
12045 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \ | |
12046 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \ | |
12047 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \ | |
12048 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \ | |
12049 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY) \ | |
12050 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \ | |
12051 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT) \ | |
12052 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) \ | |
12053 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) ) | |
12054 | ||
12055 | static tree | |
12056 | c_parser_oacc_kernels (location_t loc, c_parser *parser, char *p_name) | |
12057 | { | |
12058 | tree stmt, clauses = NULL_TREE, block; | |
12059 | ||
12060 | strcat (p_name, " kernels"); | |
12061 | ||
12062 | if (c_parser_next_token_is (parser, CPP_NAME)) | |
12063 | { | |
12064 | const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); | |
12065 | if (strcmp (p, "loop") == 0) | |
12066 | { | |
12067 | c_parser_consume_token (parser); | |
12068 | block = c_begin_omp_parallel (); | |
12069 | c_parser_oacc_loop (loc, parser, p_name); | |
12070 | stmt = c_finish_oacc_kernels (loc, clauses, block); | |
12071 | OACC_KERNELS_COMBINED (stmt) = 1; | |
12072 | return stmt; | |
12073 | } | |
12074 | } | |
12075 | ||
12076 | clauses = c_parser_oacc_all_clauses (parser, OACC_KERNELS_CLAUSE_MASK, | |
12077 | p_name); | |
12078 | ||
12079 | block = c_begin_omp_parallel (); | |
12080 | add_stmt (c_parser_omp_structured_block (parser)); | |
12081 | ||
12082 | stmt = c_finish_oacc_kernels (loc, clauses, block); | |
12083 | ||
12084 | return stmt; | |
12085 | } | |
12086 | ||
12087 | /* OpenACC 2.0: | |
12088 | # pragma acc enter data oacc-enter-data-clause[optseq] new-line | |
12089 | ||
12090 | or | |
12091 | ||
12092 | # pragma acc exit data oacc-exit-data-clause[optseq] new-line | |
12093 | ||
12094 | ||
12095 | LOC is the location of the #pragma token. | |
12096 | */ | |
12097 | ||
12098 | #define OACC_ENTER_DATA_CLAUSE_MASK \ | |
12099 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \ | |
12100 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \ | |
12101 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \ | |
12102 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \ | |
12103 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \ | |
12104 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) \ | |
12105 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) ) | |
12106 | ||
12107 | #define OACC_EXIT_DATA_CLAUSE_MASK \ | |
12108 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \ | |
12109 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \ | |
12110 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \ | |
12111 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DELETE) \ | |
12112 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) ) | |
12113 | ||
12114 | static void | |
12115 | c_parser_oacc_enter_exit_data (c_parser *parser, bool enter) | |
12116 | { | |
12117 | location_t loc = c_parser_peek_token (parser)->location; | |
12118 | tree clauses, stmt; | |
12119 | ||
12120 | c_parser_consume_pragma (parser); | |
12121 | ||
12122 | if (!c_parser_next_token_is (parser, CPP_NAME)) | |
12123 | { | |
12124 | c_parser_error (parser, enter | |
12125 | ? "expected %<data%> in %<#pragma acc enter data%>" | |
12126 | : "expected %<data%> in %<#pragma acc exit data%>"); | |
12127 | c_parser_skip_to_pragma_eol (parser); | |
12128 | return; | |
12129 | } | |
12130 | ||
12131 | const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); | |
12132 | if (strcmp (p, "data") != 0) | |
12133 | { | |
12134 | c_parser_error (parser, "invalid pragma"); | |
12135 | c_parser_skip_to_pragma_eol (parser); | |
12136 | return; | |
12137 | } | |
12138 | ||
12139 | c_parser_consume_token (parser); | |
12140 | ||
12141 | if (enter) | |
12142 | clauses = c_parser_oacc_all_clauses (parser, OACC_ENTER_DATA_CLAUSE_MASK, | |
12143 | "#pragma acc enter data"); | |
12144 | else | |
12145 | clauses = c_parser_oacc_all_clauses (parser, OACC_EXIT_DATA_CLAUSE_MASK, | |
12146 | "#pragma acc exit data"); | |
12147 | ||
12148 | if (find_omp_clause (clauses, OMP_CLAUSE_MAP) == NULL_TREE) | |
12149 | { | |
12150 | error_at (loc, enter | |
12151 | ? "%<#pragma acc enter data%> has no data movement clause" | |
12152 | : "%<#pragma acc exit data%> has no data movement clause"); | |
12153 | return; | |
12154 | } | |
12155 | ||
12156 | stmt = enter ? make_node (OACC_ENTER_DATA) : make_node (OACC_EXIT_DATA);; | |
12157 | TREE_TYPE (stmt) = void_type_node; | |
12158 | if (enter) | |
12159 | OACC_ENTER_DATA_CLAUSES (stmt) = clauses; | |
12160 | else | |
12161 | OACC_EXIT_DATA_CLAUSES (stmt) = clauses; | |
12162 | SET_EXPR_LOCATION (stmt, loc); | |
12163 | add_stmt (stmt); | |
12164 | } | |
12165 | ||
12166 | ||
12167 | /* OpenACC 2.0: | |
12168 | ||
12169 | # pragma acc loop oacc-loop-clause[optseq] new-line | |
12170 | structured-block | |
12171 | ||
12172 | LOC is the location of the #pragma token. | |
12173 | */ | |
12174 | ||
12175 | #define OACC_LOOP_CLAUSE_MASK \ | |
12176 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COLLAPSE) \ | |
12177 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_REDUCTION) ) | |
12178 | ||
12179 | static tree | |
12180 | c_parser_oacc_loop (location_t loc, c_parser *parser, char *p_name) | |
12181 | { | |
12182 | tree stmt, clauses, block; | |
12183 | ||
12184 | strcat (p_name, " loop"); | |
12185 | ||
12186 | clauses = c_parser_oacc_all_clauses (parser, OACC_LOOP_CLAUSE_MASK, p_name); | |
12187 | ||
12188 | block = c_begin_compound_stmt (true); | |
12189 | stmt = c_parser_omp_for_loop (loc, parser, OACC_LOOP, clauses, NULL); | |
12190 | block = c_end_compound_stmt (loc, block, true); | |
12191 | add_stmt (block); | |
12192 | ||
12193 | return stmt; | |
12194 | } | |
12195 | ||
12196 | /* OpenACC 2.0: | |
12197 | # pragma acc parallel oacc-parallel-clause[optseq] new-line | |
12198 | structured-block | |
12199 | ||
12200 | LOC is the location of the #pragma token. | |
12201 | */ | |
12202 | ||
12203 | #define OACC_PARALLEL_CLAUSE_MASK \ | |
12204 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \ | |
12205 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \ | |
12206 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \ | |
12207 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \ | |
12208 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \ | |
12209 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \ | |
12210 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \ | |
12211 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_GANGS) \ | |
12212 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_WORKERS) \ | |
12213 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \ | |
12214 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY) \ | |
12215 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \ | |
12216 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT) \ | |
12217 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) \ | |
12218 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_REDUCTION) \ | |
12219 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR_LENGTH) \ | |
12220 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) ) | |
12221 | ||
12222 | static tree | |
12223 | c_parser_oacc_parallel (location_t loc, c_parser *parser, char *p_name) | |
12224 | { | |
12225 | tree stmt, clauses = NULL_TREE, block; | |
12226 | ||
12227 | strcat (p_name, " parallel"); | |
12228 | ||
12229 | if (c_parser_next_token_is (parser, CPP_NAME)) | |
12230 | { | |
12231 | const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); | |
12232 | if (strcmp (p, "loop") == 0) | |
12233 | { | |
12234 | c_parser_consume_token (parser); | |
12235 | block = c_begin_omp_parallel (); | |
12236 | c_parser_oacc_loop (loc, parser, p_name); | |
12237 | stmt = c_finish_oacc_parallel (loc, clauses, block); | |
12238 | OACC_PARALLEL_COMBINED (stmt) = 1; | |
12239 | return stmt; | |
12240 | } | |
12241 | } | |
12242 | ||
12243 | clauses = c_parser_oacc_all_clauses (parser, OACC_PARALLEL_CLAUSE_MASK, | |
12244 | p_name); | |
12245 | ||
12246 | block = c_begin_omp_parallel (); | |
12247 | add_stmt (c_parser_omp_structured_block (parser)); | |
12248 | ||
12249 | stmt = c_finish_oacc_parallel (loc, clauses, block); | |
12250 | ||
12251 | return stmt; | |
12252 | } | |
12253 | ||
12254 | /* OpenACC 2.0: | |
12255 | # pragma acc update oacc-update-clause[optseq] new-line | |
12256 | */ | |
12257 | ||
12258 | #define OACC_UPDATE_CLAUSE_MASK \ | |
12259 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \ | |
12260 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICE) \ | |
12261 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_HOST) \ | |
12262 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \ | |
12263 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SELF) \ | |
12264 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) ) | |
12265 | ||
12266 | static void | |
12267 | c_parser_oacc_update (c_parser *parser) | |
12268 | { | |
12269 | location_t loc = c_parser_peek_token (parser)->location; | |
12270 | ||
12271 | c_parser_consume_pragma (parser); | |
12272 | ||
12273 | tree clauses = c_parser_oacc_all_clauses (parser, OACC_UPDATE_CLAUSE_MASK, | |
12274 | "#pragma acc update"); | |
12275 | if (find_omp_clause (clauses, OMP_CLAUSE_MAP) == NULL_TREE) | |
12276 | { | |
12277 | error_at (loc, | |
12278 | "%<#pragma acc update%> must contain at least one " | |
12279 | "%<device%> or %<host/self%> clause"); | |
12280 | return; | |
12281 | } | |
12282 | ||
12283 | if (parser->error) | |
12284 | return; | |
12285 | ||
12286 | tree stmt = make_node (OACC_UPDATE); | |
12287 | TREE_TYPE (stmt) = void_type_node; | |
12288 | OACC_UPDATE_CLAUSES (stmt) = clauses; | |
12289 | SET_EXPR_LOCATION (stmt, loc); | |
12290 | add_stmt (stmt); | |
12291 | } | |
12292 | ||
12293 | /* OpenACC 2.0: | |
12294 | # pragma acc wait [(intseq)] oacc-wait-clause[optseq] new-line | |
12295 | ||
12296 | LOC is the location of the #pragma token. | |
12297 | */ | |
12298 | ||
12299 | #define OACC_WAIT_CLAUSE_MASK \ | |
12300 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) ) | |
12301 | ||
12302 | static tree | |
12303 | c_parser_oacc_wait (location_t loc, c_parser *parser, char *p_name) | |
12304 | { | |
12305 | tree clauses, list = NULL_TREE, stmt = NULL_TREE; | |
12306 | ||
12307 | if (c_parser_peek_token (parser)->type == CPP_OPEN_PAREN) | |
12308 | list = c_parser_oacc_wait_list (parser, loc, list); | |
12309 | ||
12310 | strcpy (p_name, " wait"); | |
12311 | clauses = c_parser_oacc_all_clauses (parser, OACC_WAIT_CLAUSE_MASK, p_name); | |
12312 | stmt = c_finish_oacc_wait (loc, list, clauses); | |
12313 | ||
12314 | return stmt; | |
12315 | } | |
12316 | ||
bc7bff74 | 12317 | /* OpenMP 2.5: |
12318 | # pragma omp atomic new-line | |
12319 | expression-stmt | |
12320 | ||
12321 | expression-stmt: | |
12322 | x binop= expr | x++ | ++x | x-- | --x | |
12323 | binop: | |
12324 | +, *, -, /, &, ^, |, <<, >> | |
12325 | ||
12326 | where x is an lvalue expression with scalar type. | |
12327 | ||
12328 | OpenMP 3.1: | |
12329 | # pragma omp atomic new-line | |
12330 | update-stmt | |
12331 | ||
12332 | # pragma omp atomic read new-line | |
12333 | read-stmt | |
12334 | ||
12335 | # pragma omp atomic write new-line | |
12336 | write-stmt | |
12337 | ||
12338 | # pragma omp atomic update new-line | |
12339 | update-stmt | |
12340 | ||
12341 | # pragma omp atomic capture new-line | |
12342 | capture-stmt | |
12343 | ||
12344 | # pragma omp atomic capture new-line | |
12345 | capture-block | |
12346 | ||
12347 | read-stmt: | |
12348 | v = x | |
12349 | write-stmt: | |
12350 | x = expr | |
12351 | update-stmt: | |
12352 | expression-stmt | x = x binop expr | |
12353 | capture-stmt: | |
12354 | v = expression-stmt | |
12355 | capture-block: | |
12356 | { v = x; update-stmt; } | { update-stmt; v = x; } | |
12357 | ||
12358 | OpenMP 4.0: | |
12359 | update-stmt: | |
12360 | expression-stmt | x = x binop expr | x = expr binop x | |
12361 | capture-stmt: | |
12362 | v = update-stmt | |
12363 | capture-block: | |
12364 | { v = x; update-stmt; } | { update-stmt; v = x; } | { v = x; x = expr; } | |
12365 | ||
12366 | where x and v are lvalue expressions with scalar type. | |
12367 | ||
12368 | LOC is the location of the #pragma token. */ | |
12369 | ||
12370 | static void | |
12371 | c_parser_omp_atomic (location_t loc, c_parser *parser) | |
12372 | { | |
12373 | tree lhs = NULL_TREE, rhs = NULL_TREE, v = NULL_TREE; | |
12374 | tree lhs1 = NULL_TREE, rhs1 = NULL_TREE; | |
12375 | tree stmt, orig_lhs, unfolded_lhs = NULL_TREE, unfolded_lhs1 = NULL_TREE; | |
12376 | enum tree_code code = OMP_ATOMIC, opcode = NOP_EXPR; | |
12377 | struct c_expr expr; | |
12378 | location_t eloc; | |
12379 | bool structured_block = false; | |
12380 | bool swapped = false; | |
12381 | bool seq_cst = false; | |
12382 | ||
e1029911 | 12383 | if (c_parser_next_token_is (parser, CPP_NAME)) |
12384 | { | |
12385 | const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); | |
12386 | if (!strcmp (p, "seq_cst")) | |
12387 | { | |
12388 | seq_cst = true; | |
12389 | c_parser_consume_token (parser); | |
12390 | if (c_parser_next_token_is (parser, CPP_COMMA) | |
12391 | && c_parser_peek_2nd_token (parser)->type == CPP_NAME) | |
12392 | c_parser_consume_token (parser); | |
12393 | } | |
12394 | } | |
bc7bff74 | 12395 | if (c_parser_next_token_is (parser, CPP_NAME)) |
12396 | { | |
12397 | const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); | |
12398 | ||
12399 | if (!strcmp (p, "read")) | |
12400 | code = OMP_ATOMIC_READ; | |
12401 | else if (!strcmp (p, "write")) | |
12402 | code = NOP_EXPR; | |
12403 | else if (!strcmp (p, "update")) | |
12404 | code = OMP_ATOMIC; | |
12405 | else if (!strcmp (p, "capture")) | |
12406 | code = OMP_ATOMIC_CAPTURE_NEW; | |
fd6481cf | 12407 | else |
bc7bff74 | 12408 | p = NULL; |
12409 | if (p) | |
12410 | c_parser_consume_token (parser); | |
12411 | } | |
e1029911 | 12412 | if (!seq_cst) |
bc7bff74 | 12413 | { |
e1029911 | 12414 | if (c_parser_next_token_is (parser, CPP_COMMA) |
12415 | && c_parser_peek_2nd_token (parser)->type == CPP_NAME) | |
12416 | c_parser_consume_token (parser); | |
12417 | ||
12418 | if (c_parser_next_token_is (parser, CPP_NAME)) | |
fd6481cf | 12419 | { |
e1029911 | 12420 | const char *p |
12421 | = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); | |
12422 | if (!strcmp (p, "seq_cst")) | |
12423 | { | |
12424 | seq_cst = true; | |
12425 | c_parser_consume_token (parser); | |
12426 | } | |
fd6481cf | 12427 | } |
bc7bff74 | 12428 | } |
12429 | c_parser_skip_to_pragma_eol (parser); | |
12430 | ||
12431 | switch (code) | |
12432 | { | |
12433 | case OMP_ATOMIC_READ: | |
12434 | case NOP_EXPR: /* atomic write */ | |
12435 | v = c_parser_unary_expression (parser).value; | |
12436 | v = c_fully_fold (v, false, NULL); | |
12437 | if (v == error_mark_node) | |
12438 | goto saw_error; | |
12439 | loc = c_parser_peek_token (parser)->location; | |
12440 | if (!c_parser_require (parser, CPP_EQ, "expected %<=%>")) | |
12441 | goto saw_error; | |
12442 | if (code == NOP_EXPR) | |
12443 | lhs = c_parser_expression (parser).value; | |
12444 | else | |
12445 | lhs = c_parser_unary_expression (parser).value; | |
12446 | lhs = c_fully_fold (lhs, false, NULL); | |
12447 | if (lhs == error_mark_node) | |
12448 | goto saw_error; | |
12449 | if (code == NOP_EXPR) | |
12450 | { | |
12451 | /* atomic write is represented by OMP_ATOMIC with NOP_EXPR | |
12452 | opcode. */ | |
12453 | code = OMP_ATOMIC; | |
12454 | rhs = lhs; | |
12455 | lhs = v; | |
12456 | v = NULL_TREE; | |
12457 | } | |
12458 | goto done; | |
12459 | case OMP_ATOMIC_CAPTURE_NEW: | |
12460 | if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) | |
12461 | { | |
12462 | c_parser_consume_token (parser); | |
12463 | structured_block = true; | |
12464 | } | |
12465 | else | |
12466 | { | |
12467 | v = c_parser_unary_expression (parser).value; | |
12468 | v = c_fully_fold (v, false, NULL); | |
12469 | if (v == error_mark_node) | |
12470 | goto saw_error; | |
12471 | if (!c_parser_require (parser, CPP_EQ, "expected %<=%>")) | |
12472 | goto saw_error; | |
12473 | } | |
12474 | break; | |
12475 | default: | |
12476 | break; | |
12477 | } | |
12478 | ||
12479 | /* For structured_block case we don't know yet whether | |
12480 | old or new x should be captured. */ | |
12481 | restart: | |
12482 | eloc = c_parser_peek_token (parser)->location; | |
12483 | expr = c_parser_unary_expression (parser); | |
12484 | lhs = expr.value; | |
12485 | expr = default_function_array_conversion (eloc, expr); | |
12486 | unfolded_lhs = expr.value; | |
12487 | lhs = c_fully_fold (lhs, false, NULL); | |
12488 | orig_lhs = lhs; | |
12489 | switch (TREE_CODE (lhs)) | |
12490 | { | |
12491 | case ERROR_MARK: | |
12492 | saw_error: | |
12493 | c_parser_skip_to_end_of_block_or_statement (parser); | |
12494 | if (structured_block) | |
12495 | { | |
12496 | if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) | |
12497 | c_parser_consume_token (parser); | |
12498 | else if (code == OMP_ATOMIC_CAPTURE_NEW) | |
12499 | { | |
12500 | c_parser_skip_to_end_of_block_or_statement (parser); | |
12501 | if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) | |
12502 | c_parser_consume_token (parser); | |
12503 | } | |
12504 | } | |
12505 | return; | |
12506 | ||
12507 | case POSTINCREMENT_EXPR: | |
12508 | if (code == OMP_ATOMIC_CAPTURE_NEW && !structured_block) | |
12509 | code = OMP_ATOMIC_CAPTURE_OLD; | |
12510 | /* FALLTHROUGH */ | |
12511 | case PREINCREMENT_EXPR: | |
12512 | lhs = TREE_OPERAND (lhs, 0); | |
12513 | unfolded_lhs = NULL_TREE; | |
12514 | opcode = PLUS_EXPR; | |
12515 | rhs = integer_one_node; | |
12516 | break; | |
12517 | ||
12518 | case POSTDECREMENT_EXPR: | |
12519 | if (code == OMP_ATOMIC_CAPTURE_NEW && !structured_block) | |
12520 | code = OMP_ATOMIC_CAPTURE_OLD; | |
12521 | /* FALLTHROUGH */ | |
12522 | case PREDECREMENT_EXPR: | |
12523 | lhs = TREE_OPERAND (lhs, 0); | |
12524 | unfolded_lhs = NULL_TREE; | |
12525 | opcode = MINUS_EXPR; | |
12526 | rhs = integer_one_node; | |
12527 | break; | |
12528 | ||
12529 | case COMPOUND_EXPR: | |
12530 | if (TREE_CODE (TREE_OPERAND (lhs, 0)) == SAVE_EXPR | |
12531 | && TREE_CODE (TREE_OPERAND (lhs, 1)) == COMPOUND_EXPR | |
12532 | && TREE_CODE (TREE_OPERAND (TREE_OPERAND (lhs, 1), 0)) == MODIFY_EXPR | |
12533 | && TREE_OPERAND (TREE_OPERAND (lhs, 1), 1) == TREE_OPERAND (lhs, 0) | |
12534 | && TREE_CODE (TREE_TYPE (TREE_OPERAND (TREE_OPERAND | |
12535 | (TREE_OPERAND (lhs, 1), 0), 0))) | |
12536 | == BOOLEAN_TYPE) | |
12537 | /* Undo effects of boolean_increment for post {in,de}crement. */ | |
12538 | lhs = TREE_OPERAND (TREE_OPERAND (lhs, 1), 0); | |
12539 | /* FALLTHRU */ | |
12540 | case MODIFY_EXPR: | |
12541 | if (TREE_CODE (lhs) == MODIFY_EXPR | |
12542 | && TREE_CODE (TREE_TYPE (TREE_OPERAND (lhs, 0))) == BOOLEAN_TYPE) | |
12543 | { | |
12544 | /* Undo effects of boolean_increment. */ | |
12545 | if (integer_onep (TREE_OPERAND (lhs, 1))) | |
12546 | { | |
12547 | /* This is pre or post increment. */ | |
12548 | rhs = TREE_OPERAND (lhs, 1); | |
12549 | lhs = TREE_OPERAND (lhs, 0); | |
12550 | unfolded_lhs = NULL_TREE; | |
12551 | opcode = NOP_EXPR; | |
12552 | if (code == OMP_ATOMIC_CAPTURE_NEW | |
12553 | && !structured_block | |
12554 | && TREE_CODE (orig_lhs) == COMPOUND_EXPR) | |
12555 | code = OMP_ATOMIC_CAPTURE_OLD; | |
12556 | break; | |
12557 | } | |
12558 | if (TREE_CODE (TREE_OPERAND (lhs, 1)) == TRUTH_NOT_EXPR | |
12559 | && TREE_OPERAND (lhs, 0) | |
12560 | == TREE_OPERAND (TREE_OPERAND (lhs, 1), 0)) | |
12561 | { | |
12562 | /* This is pre or post decrement. */ | |
12563 | rhs = TREE_OPERAND (lhs, 1); | |
12564 | lhs = TREE_OPERAND (lhs, 0); | |
12565 | unfolded_lhs = NULL_TREE; | |
12566 | opcode = NOP_EXPR; | |
12567 | if (code == OMP_ATOMIC_CAPTURE_NEW | |
12568 | && !structured_block | |
12569 | && TREE_CODE (orig_lhs) == COMPOUND_EXPR) | |
12570 | code = OMP_ATOMIC_CAPTURE_OLD; | |
12571 | break; | |
12572 | } | |
12573 | } | |
12574 | /* FALLTHRU */ | |
12575 | default: | |
12576 | switch (c_parser_peek_token (parser)->type) | |
12577 | { | |
12578 | case CPP_MULT_EQ: | |
12579 | opcode = MULT_EXPR; | |
12580 | break; | |
12581 | case CPP_DIV_EQ: | |
12582 | opcode = TRUNC_DIV_EXPR; | |
12583 | break; | |
12584 | case CPP_PLUS_EQ: | |
12585 | opcode = PLUS_EXPR; | |
12586 | break; | |
12587 | case CPP_MINUS_EQ: | |
12588 | opcode = MINUS_EXPR; | |
12589 | break; | |
12590 | case CPP_LSHIFT_EQ: | |
12591 | opcode = LSHIFT_EXPR; | |
12592 | break; | |
12593 | case CPP_RSHIFT_EQ: | |
12594 | opcode = RSHIFT_EXPR; | |
12595 | break; | |
12596 | case CPP_AND_EQ: | |
12597 | opcode = BIT_AND_EXPR; | |
12598 | break; | |
12599 | case CPP_OR_EQ: | |
12600 | opcode = BIT_IOR_EXPR; | |
12601 | break; | |
12602 | case CPP_XOR_EQ: | |
12603 | opcode = BIT_XOR_EXPR; | |
12604 | break; | |
12605 | case CPP_EQ: | |
12606 | c_parser_consume_token (parser); | |
12607 | eloc = c_parser_peek_token (parser)->location; | |
12608 | expr = c_parser_expr_no_commas (parser, NULL, unfolded_lhs); | |
12609 | rhs1 = expr.value; | |
12610 | switch (TREE_CODE (rhs1)) | |
12611 | { | |
12612 | case MULT_EXPR: | |
12613 | case TRUNC_DIV_EXPR: | |
bbf8fbec | 12614 | case RDIV_EXPR: |
bc7bff74 | 12615 | case PLUS_EXPR: |
12616 | case MINUS_EXPR: | |
12617 | case LSHIFT_EXPR: | |
12618 | case RSHIFT_EXPR: | |
12619 | case BIT_AND_EXPR: | |
12620 | case BIT_IOR_EXPR: | |
12621 | case BIT_XOR_EXPR: | |
12622 | if (c_tree_equal (TREE_OPERAND (rhs1, 0), unfolded_lhs)) | |
12623 | { | |
12624 | opcode = TREE_CODE (rhs1); | |
12625 | rhs = c_fully_fold (TREE_OPERAND (rhs1, 1), false, NULL); | |
12626 | rhs1 = c_fully_fold (TREE_OPERAND (rhs1, 0), false, NULL); | |
12627 | goto stmt_done; | |
12628 | } | |
12629 | if (c_tree_equal (TREE_OPERAND (rhs1, 1), unfolded_lhs)) | |
12630 | { | |
12631 | opcode = TREE_CODE (rhs1); | |
12632 | rhs = c_fully_fold (TREE_OPERAND (rhs1, 0), false, NULL); | |
12633 | rhs1 = c_fully_fold (TREE_OPERAND (rhs1, 1), false, NULL); | |
12634 | swapped = !commutative_tree_code (opcode); | |
12635 | goto stmt_done; | |
12636 | } | |
12637 | break; | |
12638 | case ERROR_MARK: | |
12639 | goto saw_error; | |
12640 | default: | |
12641 | break; | |
12642 | } | |
12643 | if (c_parser_peek_token (parser)->type == CPP_SEMICOLON) | |
12644 | { | |
12645 | if (structured_block && code == OMP_ATOMIC_CAPTURE_NEW) | |
12646 | { | |
12647 | code = OMP_ATOMIC_CAPTURE_OLD; | |
12648 | v = lhs; | |
12649 | lhs = NULL_TREE; | |
12650 | expr = default_function_array_read_conversion (eloc, expr); | |
12651 | unfolded_lhs1 = expr.value; | |
12652 | lhs1 = c_fully_fold (unfolded_lhs1, false, NULL); | |
12653 | rhs1 = NULL_TREE; | |
12654 | c_parser_consume_token (parser); | |
12655 | goto restart; | |
12656 | } | |
12657 | if (structured_block) | |
12658 | { | |
12659 | opcode = NOP_EXPR; | |
12660 | expr = default_function_array_read_conversion (eloc, expr); | |
12661 | rhs = c_fully_fold (expr.value, false, NULL); | |
12662 | rhs1 = NULL_TREE; | |
12663 | goto stmt_done; | |
12664 | } | |
12665 | } | |
12666 | c_parser_error (parser, "invalid form of %<#pragma omp atomic%>"); | |
12667 | goto saw_error; | |
12668 | default: | |
12669 | c_parser_error (parser, | |
12670 | "invalid operator for %<#pragma omp atomic%>"); | |
12671 | goto saw_error; | |
12672 | } | |
12673 | ||
12674 | /* Arrange to pass the location of the assignment operator to | |
12675 | c_finish_omp_atomic. */ | |
12676 | loc = c_parser_peek_token (parser)->location; | |
12677 | c_parser_consume_token (parser); | |
12678 | eloc = c_parser_peek_token (parser)->location; | |
12679 | expr = c_parser_expression (parser); | |
12680 | expr = default_function_array_read_conversion (eloc, expr); | |
12681 | rhs = expr.value; | |
12682 | rhs = c_fully_fold (rhs, false, NULL); | |
12683 | break; | |
12684 | } | |
12685 | stmt_done: | |
12686 | if (structured_block && code == OMP_ATOMIC_CAPTURE_NEW) | |
12687 | { | |
12688 | if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>")) | |
12689 | goto saw_error; | |
12690 | v = c_parser_unary_expression (parser).value; | |
12691 | v = c_fully_fold (v, false, NULL); | |
12692 | if (v == error_mark_node) | |
12693 | goto saw_error; | |
12694 | if (!c_parser_require (parser, CPP_EQ, "expected %<=%>")) | |
12695 | goto saw_error; | |
12696 | eloc = c_parser_peek_token (parser)->location; | |
12697 | expr = c_parser_unary_expression (parser); | |
12698 | lhs1 = expr.value; | |
12699 | expr = default_function_array_read_conversion (eloc, expr); | |
12700 | unfolded_lhs1 = expr.value; | |
12701 | lhs1 = c_fully_fold (lhs1, false, NULL); | |
12702 | if (lhs1 == error_mark_node) | |
12703 | goto saw_error; | |
12704 | } | |
12705 | if (structured_block) | |
12706 | { | |
12707 | c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); | |
12708 | c_parser_require (parser, CPP_CLOSE_BRACE, "expected %<}%>"); | |
12709 | } | |
12710 | done: | |
12711 | if (unfolded_lhs && unfolded_lhs1 | |
12712 | && !c_tree_equal (unfolded_lhs, unfolded_lhs1)) | |
12713 | { | |
12714 | error ("%<#pragma omp atomic capture%> uses two different " | |
12715 | "expressions for memory"); | |
12716 | stmt = error_mark_node; | |
12717 | } | |
12718 | else | |
12719 | stmt = c_finish_omp_atomic (loc, code, opcode, lhs, rhs, v, lhs1, rhs1, | |
12720 | swapped, seq_cst); | |
12721 | if (stmt != error_mark_node) | |
12722 | add_stmt (stmt); | |
12723 | ||
12724 | if (!structured_block) | |
12725 | c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); | |
12726 | } | |
12727 | ||
12728 | ||
12729 | /* OpenMP 2.5: | |
12730 | # pragma omp barrier new-line | |
12731 | */ | |
12732 | ||
12733 | static void | |
12734 | c_parser_omp_barrier (c_parser *parser) | |
12735 | { | |
12736 | location_t loc = c_parser_peek_token (parser)->location; | |
12737 | c_parser_consume_pragma (parser); | |
12738 | c_parser_skip_to_pragma_eol (parser); | |
12739 | ||
12740 | c_finish_omp_barrier (loc); | |
12741 | } | |
12742 | ||
12743 | /* OpenMP 2.5: | |
12744 | # pragma omp critical [(name)] new-line | |
12745 | structured-block | |
12746 | ||
12747 | LOC is the location of the #pragma itself. */ | |
12748 | ||
12749 | static tree | |
12750 | c_parser_omp_critical (location_t loc, c_parser *parser) | |
12751 | { | |
12752 | tree stmt, name = NULL; | |
12753 | ||
12754 | if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) | |
12755 | { | |
12756 | c_parser_consume_token (parser); | |
12757 | if (c_parser_next_token_is (parser, CPP_NAME)) | |
12758 | { | |
12759 | name = c_parser_peek_token (parser)->value; | |
12760 | c_parser_consume_token (parser); | |
12761 | c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
12762 | } | |
12763 | else | |
12764 | c_parser_error (parser, "expected identifier"); | |
12765 | } | |
12766 | else if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL)) | |
12767 | c_parser_error (parser, "expected %<(%> or end of line"); | |
12768 | c_parser_skip_to_pragma_eol (parser); | |
12769 | ||
12770 | stmt = c_parser_omp_structured_block (parser); | |
12771 | return c_finish_omp_critical (loc, stmt, name); | |
12772 | } | |
12773 | ||
12774 | /* OpenMP 2.5: | |
12775 | # pragma omp flush flush-vars[opt] new-line | |
12776 | ||
12777 | flush-vars: | |
12778 | ( variable-list ) */ | |
12779 | ||
12780 | static void | |
12781 | c_parser_omp_flush (c_parser *parser) | |
12782 | { | |
12783 | location_t loc = c_parser_peek_token (parser)->location; | |
12784 | c_parser_consume_pragma (parser); | |
12785 | if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) | |
12786 | c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL); | |
12787 | else if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL)) | |
12788 | c_parser_error (parser, "expected %<(%> or end of line"); | |
12789 | c_parser_skip_to_pragma_eol (parser); | |
12790 | ||
12791 | c_finish_omp_flush (loc); | |
12792 | } | |
12793 | ||
ca4c3545 | 12794 | /* Parse the restricted form of loop statements allowed by OpenACC and OpenMP. |
bc7bff74 | 12795 | The real trick here is to determine the loop control variable early |
12796 | so that we can push a new decl if necessary to make it private. | |
ca4c3545 | 12797 | LOC is the location of the "acc" or "omp" in "#pragma acc" or "#pragma omp", |
12798 | respectively. */ | |
bc7bff74 | 12799 | |
12800 | static tree | |
12801 | c_parser_omp_for_loop (location_t loc, c_parser *parser, enum tree_code code, | |
12802 | tree clauses, tree *cclauses) | |
12803 | { | |
12804 | tree decl, cond, incr, save_break, save_cont, body, init, stmt, cl; | |
12805 | tree declv, condv, incrv, initv, ret = NULL; | |
12806 | bool fail = false, open_brace_parsed = false; | |
12807 | int i, collapse = 1, nbraces = 0; | |
12808 | location_t for_loc; | |
12809 | vec<tree, va_gc> *for_block = make_tree_vector (); | |
12810 | ||
12811 | for (cl = clauses; cl; cl = OMP_CLAUSE_CHAIN (cl)) | |
12812 | if (OMP_CLAUSE_CODE (cl) == OMP_CLAUSE_COLLAPSE) | |
6b409616 | 12813 | collapse = tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (cl)); |
bc7bff74 | 12814 | |
12815 | gcc_assert (collapse >= 1); | |
12816 | ||
12817 | declv = make_tree_vec (collapse); | |
12818 | initv = make_tree_vec (collapse); | |
12819 | condv = make_tree_vec (collapse); | |
12820 | incrv = make_tree_vec (collapse); | |
12821 | ||
40750995 | 12822 | if (code != CILK_FOR |
12823 | && !c_parser_next_token_is_keyword (parser, RID_FOR)) | |
bc7bff74 | 12824 | { |
12825 | c_parser_error (parser, "for statement expected"); | |
12826 | return NULL; | |
12827 | } | |
40750995 | 12828 | if (code == CILK_FOR |
12829 | && !c_parser_next_token_is_keyword (parser, RID_CILK_FOR)) | |
12830 | { | |
12831 | c_parser_error (parser, "_Cilk_for statement expected"); | |
12832 | return NULL; | |
12833 | } | |
bc7bff74 | 12834 | for_loc = c_parser_peek_token (parser)->location; |
12835 | c_parser_consume_token (parser); | |
12836 | ||
12837 | for (i = 0; i < collapse; i++) | |
12838 | { | |
12839 | int bracecount = 0; | |
12840 | ||
12841 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
12842 | goto pop_scopes; | |
12843 | ||
12844 | /* Parse the initialization declaration or expression. */ | |
12845 | if (c_parser_next_tokens_start_declaration (parser)) | |
12846 | { | |
12847 | if (i > 0) | |
12848 | vec_safe_push (for_block, c_begin_compound_stmt (true)); | |
12849 | c_parser_declaration_or_fndef (parser, true, true, true, true, true, | |
12850 | NULL, vNULL); | |
12851 | decl = check_for_loop_decls (for_loc, flag_isoc99); | |
12852 | if (decl == NULL) | |
12853 | goto error_init; | |
12854 | if (DECL_INITIAL (decl) == error_mark_node) | |
12855 | decl = error_mark_node; | |
12856 | init = decl; | |
12857 | } | |
12858 | else if (c_parser_next_token_is (parser, CPP_NAME) | |
12859 | && c_parser_peek_2nd_token (parser)->type == CPP_EQ) | |
12860 | { | |
12861 | struct c_expr decl_exp; | |
12862 | struct c_expr init_exp; | |
12863 | location_t init_loc; | |
12864 | ||
12865 | decl_exp = c_parser_postfix_expression (parser); | |
12866 | decl = decl_exp.value; | |
12867 | ||
12868 | c_parser_require (parser, CPP_EQ, "expected %<=%>"); | |
12869 | ||
12870 | init_loc = c_parser_peek_token (parser)->location; | |
12871 | init_exp = c_parser_expr_no_commas (parser, NULL); | |
12872 | init_exp = default_function_array_read_conversion (init_loc, | |
12873 | init_exp); | |
12874 | init = build_modify_expr (init_loc, decl, decl_exp.original_type, | |
12875 | NOP_EXPR, init_loc, init_exp.value, | |
12876 | init_exp.original_type); | |
12877 | init = c_process_expr_stmt (init_loc, init); | |
12878 | ||
12879 | c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); | |
12880 | } | |
12881 | else | |
12882 | { | |
12883 | error_init: | |
12884 | c_parser_error (parser, | |
12885 | "expected iteration declaration or initialization"); | |
12886 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, | |
12887 | "expected %<)%>"); | |
12888 | fail = true; | |
12889 | goto parse_next; | |
12890 | } | |
12891 | ||
12892 | /* Parse the loop condition. */ | |
12893 | cond = NULL_TREE; | |
12894 | if (c_parser_next_token_is_not (parser, CPP_SEMICOLON)) | |
12895 | { | |
12896 | location_t cond_loc = c_parser_peek_token (parser)->location; | |
12897 | struct c_expr cond_expr | |
12898 | = c_parser_binary_expression (parser, NULL, NULL_TREE); | |
12899 | ||
12900 | cond = cond_expr.value; | |
12901 | cond = c_objc_common_truthvalue_conversion (cond_loc, cond); | |
12902 | cond = c_fully_fold (cond, false, NULL); | |
12903 | switch (cond_expr.original_code) | |
12904 | { | |
12905 | case GT_EXPR: | |
12906 | case GE_EXPR: | |
12907 | case LT_EXPR: | |
12908 | case LE_EXPR: | |
12909 | break; | |
f2697631 | 12910 | case NE_EXPR: |
40750995 | 12911 | if (code == CILK_SIMD || code == CILK_FOR) |
f2697631 | 12912 | break; |
12913 | /* FALLTHRU. */ | |
bc7bff74 | 12914 | default: |
12915 | /* Can't be cond = error_mark_node, because we want to preserve | |
12916 | the location until c_finish_omp_for. */ | |
12917 | cond = build1 (NOP_EXPR, boolean_type_node, error_mark_node); | |
12918 | break; | |
12919 | } | |
12920 | protected_set_expr_location (cond, cond_loc); | |
12921 | } | |
12922 | c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); | |
12923 | ||
12924 | /* Parse the increment expression. */ | |
12925 | incr = NULL_TREE; | |
12926 | if (c_parser_next_token_is_not (parser, CPP_CLOSE_PAREN)) | |
12927 | { | |
12928 | location_t incr_loc = c_parser_peek_token (parser)->location; | |
12929 | ||
12930 | incr = c_process_expr_stmt (incr_loc, | |
12931 | c_parser_expression (parser).value); | |
12932 | } | |
12933 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
12934 | ||
12935 | if (decl == NULL || decl == error_mark_node || init == error_mark_node) | |
12936 | fail = true; | |
12937 | else | |
12938 | { | |
12939 | TREE_VEC_ELT (declv, i) = decl; | |
12940 | TREE_VEC_ELT (initv, i) = init; | |
12941 | TREE_VEC_ELT (condv, i) = cond; | |
12942 | TREE_VEC_ELT (incrv, i) = incr; | |
12943 | } | |
12944 | ||
12945 | parse_next: | |
12946 | if (i == collapse - 1) | |
12947 | break; | |
12948 | ||
12949 | /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed | |
12950 | in between the collapsed for loops to be still considered perfectly | |
12951 | nested. Hopefully the final version clarifies this. | |
12952 | For now handle (multiple) {'s and empty statements. */ | |
12953 | do | |
12954 | { | |
12955 | if (c_parser_next_token_is_keyword (parser, RID_FOR)) | |
12956 | { | |
12957 | c_parser_consume_token (parser); | |
12958 | break; | |
12959 | } | |
12960 | else if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) | |
12961 | { | |
12962 | c_parser_consume_token (parser); | |
12963 | bracecount++; | |
12964 | } | |
12965 | else if (bracecount | |
12966 | && c_parser_next_token_is (parser, CPP_SEMICOLON)) | |
12967 | c_parser_consume_token (parser); | |
12968 | else | |
12969 | { | |
12970 | c_parser_error (parser, "not enough perfectly nested loops"); | |
12971 | if (bracecount) | |
12972 | { | |
12973 | open_brace_parsed = true; | |
12974 | bracecount--; | |
12975 | } | |
12976 | fail = true; | |
12977 | collapse = 0; | |
12978 | break; | |
12979 | } | |
12980 | } | |
12981 | while (1); | |
12982 | ||
12983 | nbraces += bracecount; | |
12984 | } | |
12985 | ||
12986 | save_break = c_break_label; | |
f2697631 | 12987 | if (code == CILK_SIMD) |
12988 | c_break_label = build_int_cst (size_type_node, 2); | |
12989 | else | |
12990 | c_break_label = size_one_node; | |
bc7bff74 | 12991 | save_cont = c_cont_label; |
12992 | c_cont_label = NULL_TREE; | |
12993 | body = push_stmt_list (); | |
12994 | ||
12995 | if (open_brace_parsed) | |
12996 | { | |
12997 | location_t here = c_parser_peek_token (parser)->location; | |
12998 | stmt = c_begin_compound_stmt (true); | |
12999 | c_parser_compound_statement_nostart (parser); | |
13000 | add_stmt (c_end_compound_stmt (here, stmt, true)); | |
13001 | } | |
13002 | else | |
13003 | add_stmt (c_parser_c99_block_statement (parser)); | |
13004 | if (c_cont_label) | |
13005 | { | |
13006 | tree t = build1 (LABEL_EXPR, void_type_node, c_cont_label); | |
13007 | SET_EXPR_LOCATION (t, loc); | |
13008 | add_stmt (t); | |
13009 | } | |
13010 | ||
13011 | body = pop_stmt_list (body); | |
13012 | c_break_label = save_break; | |
13013 | c_cont_label = save_cont; | |
13014 | ||
13015 | while (nbraces) | |
13016 | { | |
13017 | if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) | |
13018 | { | |
13019 | c_parser_consume_token (parser); | |
13020 | nbraces--; | |
13021 | } | |
13022 | else if (c_parser_next_token_is (parser, CPP_SEMICOLON)) | |
13023 | c_parser_consume_token (parser); | |
13024 | else | |
13025 | { | |
13026 | c_parser_error (parser, "collapsed loops not perfectly nested"); | |
13027 | while (nbraces) | |
13028 | { | |
13029 | location_t here = c_parser_peek_token (parser)->location; | |
13030 | stmt = c_begin_compound_stmt (true); | |
13031 | add_stmt (body); | |
13032 | c_parser_compound_statement_nostart (parser); | |
13033 | body = c_end_compound_stmt (here, stmt, true); | |
13034 | nbraces--; | |
13035 | } | |
13036 | goto pop_scopes; | |
13037 | } | |
13038 | } | |
13039 | ||
13040 | /* Only bother calling c_finish_omp_for if we haven't already generated | |
13041 | an error from the initialization parsing. */ | |
13042 | if (!fail) | |
13043 | { | |
13044 | stmt = c_finish_omp_for (loc, code, declv, initv, condv, | |
13045 | incrv, body, NULL); | |
13046 | if (stmt) | |
13047 | { | |
13048 | if (cclauses != NULL | |
13049 | && cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL] != NULL) | |
13050 | { | |
13051 | tree *c; | |
13052 | for (c = &cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL]; *c ; ) | |
13053 | if (OMP_CLAUSE_CODE (*c) != OMP_CLAUSE_FIRSTPRIVATE | |
13054 | && OMP_CLAUSE_CODE (*c) != OMP_CLAUSE_LASTPRIVATE) | |
13055 | c = &OMP_CLAUSE_CHAIN (*c); | |
13056 | else | |
13057 | { | |
13058 | for (i = 0; i < collapse; i++) | |
13059 | if (TREE_VEC_ELT (declv, i) == OMP_CLAUSE_DECL (*c)) | |
13060 | break; | |
13061 | if (i == collapse) | |
13062 | c = &OMP_CLAUSE_CHAIN (*c); | |
13063 | else if (OMP_CLAUSE_CODE (*c) == OMP_CLAUSE_FIRSTPRIVATE) | |
13064 | { | |
13065 | error_at (loc, | |
13066 | "iteration variable %qD should not be firstprivate", | |
13067 | OMP_CLAUSE_DECL (*c)); | |
13068 | *c = OMP_CLAUSE_CHAIN (*c); | |
13069 | } | |
13070 | else | |
13071 | { | |
13072 | /* Copy lastprivate (decl) clause to OMP_FOR_CLAUSES, | |
13073 | change it to shared (decl) in | |
13074 | OMP_PARALLEL_CLAUSES. */ | |
13075 | tree l = build_omp_clause (OMP_CLAUSE_LOCATION (*c), | |
13076 | OMP_CLAUSE_LASTPRIVATE); | |
13077 | OMP_CLAUSE_DECL (l) = OMP_CLAUSE_DECL (*c); | |
e471cc6f | 13078 | if (code == OMP_SIMD) |
13079 | { | |
13080 | OMP_CLAUSE_CHAIN (l) | |
13081 | = cclauses[C_OMP_CLAUSE_SPLIT_FOR]; | |
13082 | cclauses[C_OMP_CLAUSE_SPLIT_FOR] = l; | |
13083 | } | |
13084 | else | |
13085 | { | |
13086 | OMP_CLAUSE_CHAIN (l) = clauses; | |
13087 | clauses = l; | |
13088 | } | |
bc7bff74 | 13089 | OMP_CLAUSE_SET_CODE (*c, OMP_CLAUSE_SHARED); |
13090 | } | |
13091 | } | |
13092 | } | |
13093 | OMP_FOR_CLAUSES (stmt) = clauses; | |
13094 | } | |
13095 | ret = stmt; | |
13096 | } | |
13097 | pop_scopes: | |
13098 | while (!for_block->is_empty ()) | |
13099 | { | |
13100 | /* FIXME diagnostics: LOC below should be the actual location of | |
13101 | this particular for block. We need to build a list of | |
13102 | locations to go along with FOR_BLOCK. */ | |
13103 | stmt = c_end_compound_stmt (loc, for_block->pop (), true); | |
13104 | add_stmt (stmt); | |
13105 | } | |
13106 | release_tree_vector (for_block); | |
13107 | return ret; | |
13108 | } | |
13109 | ||
13110 | /* Helper function for OpenMP parsing, split clauses and call | |
13111 | finish_omp_clauses on each of the set of clauses afterwards. */ | |
13112 | ||
13113 | static void | |
13114 | omp_split_clauses (location_t loc, enum tree_code code, | |
13115 | omp_clause_mask mask, tree clauses, tree *cclauses) | |
13116 | { | |
13117 | int i; | |
13118 | c_omp_split_clauses (loc, code, mask, clauses, cclauses); | |
13119 | for (i = 0; i < C_OMP_CLAUSE_SPLIT_COUNT; i++) | |
13120 | if (cclauses[i]) | |
13121 | cclauses[i] = c_finish_omp_clauses (cclauses[i]); | |
13122 | } | |
13123 | ||
13124 | /* OpenMP 4.0: | |
13125 | #pragma omp simd simd-clause[optseq] new-line | |
13126 | for-loop | |
13127 | ||
13128 | LOC is the location of the #pragma token. | |
13129 | */ | |
13130 | ||
13131 | #define OMP_SIMD_CLAUSE_MASK \ | |
13132 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SAFELEN) \ | |
13133 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \ | |
13134 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \ | |
13135 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \ | |
13136 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \ | |
13137 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \ | |
13138 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE)) | |
13139 | ||
13140 | static tree | |
13141 | c_parser_omp_simd (location_t loc, c_parser *parser, | |
13142 | char *p_name, omp_clause_mask mask, tree *cclauses) | |
13143 | { | |
13144 | tree block, clauses, ret; | |
13145 | ||
13146 | strcat (p_name, " simd"); | |
13147 | mask |= OMP_SIMD_CLAUSE_MASK; | |
13148 | mask &= ~(OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ORDERED); | |
13149 | ||
13150 | clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL); | |
13151 | if (cclauses) | |
13152 | { | |
13153 | omp_split_clauses (loc, OMP_SIMD, mask, clauses, cclauses); | |
13154 | clauses = cclauses[C_OMP_CLAUSE_SPLIT_SIMD]; | |
13155 | } | |
13156 | ||
13157 | block = c_begin_compound_stmt (true); | |
13158 | ret = c_parser_omp_for_loop (loc, parser, OMP_SIMD, clauses, cclauses); | |
13159 | block = c_end_compound_stmt (loc, block, true); | |
13160 | add_stmt (block); | |
13161 | ||
13162 | return ret; | |
13163 | } | |
13164 | ||
13165 | /* OpenMP 2.5: | |
13166 | #pragma omp for for-clause[optseq] new-line | |
13167 | for-loop | |
13168 | ||
13169 | OpenMP 4.0: | |
13170 | #pragma omp for simd for-simd-clause[optseq] new-line | |
13171 | for-loop | |
13172 | ||
13173 | LOC is the location of the #pragma token. | |
13174 | */ | |
13175 | ||
13176 | #define OMP_FOR_CLAUSE_MASK \ | |
13177 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \ | |
13178 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \ | |
13179 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \ | |
13180 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \ | |
13181 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ORDERED) \ | |
13182 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SCHEDULE) \ | |
13183 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE) \ | |
13184 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT)) | |
13185 | ||
13186 | static tree | |
13187 | c_parser_omp_for (location_t loc, c_parser *parser, | |
13188 | char *p_name, omp_clause_mask mask, tree *cclauses) | |
13189 | { | |
13190 | tree block, clauses, ret; | |
13191 | ||
13192 | strcat (p_name, " for"); | |
13193 | mask |= OMP_FOR_CLAUSE_MASK; | |
13194 | if (cclauses) | |
13195 | mask &= ~(OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT); | |
13196 | ||
13197 | if (c_parser_next_token_is (parser, CPP_NAME)) | |
2169f33b | 13198 | { |
bc7bff74 | 13199 | const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
13200 | ||
13201 | if (strcmp (p, "simd") == 0) | |
13202 | { | |
13203 | tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT]; | |
13204 | if (cclauses == NULL) | |
13205 | cclauses = cclauses_buf; | |
13206 | ||
13207 | c_parser_consume_token (parser); | |
c630ef93 | 13208 | if (!flag_openmp) /* flag_openmp_simd */ |
13209 | return c_parser_omp_simd (loc, parser, p_name, mask, cclauses); | |
bc7bff74 | 13210 | block = c_begin_compound_stmt (true); |
13211 | ret = c_parser_omp_simd (loc, parser, p_name, mask, cclauses); | |
13212 | block = c_end_compound_stmt (loc, block, true); | |
13213 | if (ret == NULL_TREE) | |
13214 | return ret; | |
13215 | ret = make_node (OMP_FOR); | |
13216 | TREE_TYPE (ret) = void_type_node; | |
13217 | OMP_FOR_BODY (ret) = block; | |
13218 | OMP_FOR_CLAUSES (ret) = cclauses[C_OMP_CLAUSE_SPLIT_FOR]; | |
13219 | SET_EXPR_LOCATION (ret, loc); | |
13220 | add_stmt (ret); | |
13221 | return ret; | |
13222 | } | |
2169f33b | 13223 | } |
c630ef93 | 13224 | if (!flag_openmp) /* flag_openmp_simd */ |
13225 | { | |
13226 | c_parser_skip_to_pragma_eol (parser); | |
13227 | return NULL_TREE; | |
13228 | } | |
bc7bff74 | 13229 | |
13230 | clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL); | |
13231 | if (cclauses) | |
2169f33b | 13232 | { |
bc7bff74 | 13233 | omp_split_clauses (loc, OMP_FOR, mask, clauses, cclauses); |
13234 | clauses = cclauses[C_OMP_CLAUSE_SPLIT_FOR]; | |
2169f33b | 13235 | } |
2169f33b | 13236 | |
bc7bff74 | 13237 | block = c_begin_compound_stmt (true); |
13238 | ret = c_parser_omp_for_loop (loc, parser, OMP_FOR, clauses, cclauses); | |
13239 | block = c_end_compound_stmt (loc, block, true); | |
13240 | add_stmt (block); | |
13241 | ||
13242 | return ret; | |
1e8e9920 | 13243 | } |
13244 | ||
bc7bff74 | 13245 | /* OpenMP 2.5: |
13246 | # pragma omp master new-line | |
13247 | structured-block | |
13248 | ||
13249 | LOC is the location of the #pragma token. | |
13250 | */ | |
13251 | ||
13252 | static tree | |
13253 | c_parser_omp_master (location_t loc, c_parser *parser) | |
13254 | { | |
13255 | c_parser_skip_to_pragma_eol (parser); | |
13256 | return c_finish_omp_master (loc, c_parser_omp_structured_block (parser)); | |
13257 | } | |
1e8e9920 | 13258 | |
13259 | /* OpenMP 2.5: | |
bc7bff74 | 13260 | # pragma omp ordered new-line |
13261 | structured-block | |
13262 | ||
13263 | LOC is the location of the #pragma itself. | |
1e8e9920 | 13264 | */ |
13265 | ||
bc7bff74 | 13266 | static tree |
13267 | c_parser_omp_ordered (location_t loc, c_parser *parser) | |
1e8e9920 | 13268 | { |
1e8e9920 | 13269 | c_parser_skip_to_pragma_eol (parser); |
bc7bff74 | 13270 | return c_finish_omp_ordered (loc, c_parser_omp_structured_block (parser)); |
13271 | } | |
1e8e9920 | 13272 | |
bc7bff74 | 13273 | /* OpenMP 2.5: |
13274 | ||
13275 | section-scope: | |
13276 | { section-sequence } | |
13277 | ||
13278 | section-sequence: | |
13279 | section-directive[opt] structured-block | |
13280 | section-sequence section-directive structured-block | |
13281 | ||
13282 | SECTIONS_LOC is the location of the #pragma omp sections. */ | |
13283 | ||
13284 | static tree | |
13285 | c_parser_omp_sections_scope (location_t sections_loc, c_parser *parser) | |
13286 | { | |
13287 | tree stmt, substmt; | |
13288 | bool error_suppress = false; | |
13289 | location_t loc; | |
13290 | ||
13291 | loc = c_parser_peek_token (parser)->location; | |
13292 | if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>")) | |
13293 | { | |
13294 | /* Avoid skipping until the end of the block. */ | |
13295 | parser->error = false; | |
13296 | return NULL_TREE; | |
13297 | } | |
13298 | ||
13299 | stmt = push_stmt_list (); | |
13300 | ||
13301 | if (c_parser_peek_token (parser)->pragma_kind != PRAGMA_OMP_SECTION) | |
13302 | { | |
13303 | substmt = c_parser_omp_structured_block (parser); | |
13304 | substmt = build1 (OMP_SECTION, void_type_node, substmt); | |
13305 | SET_EXPR_LOCATION (substmt, loc); | |
13306 | add_stmt (substmt); | |
13307 | } | |
13308 | ||
13309 | while (1) | |
13310 | { | |
13311 | if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) | |
13312 | break; | |
13313 | if (c_parser_next_token_is (parser, CPP_EOF)) | |
13314 | break; | |
13315 | ||
13316 | loc = c_parser_peek_token (parser)->location; | |
13317 | if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_OMP_SECTION) | |
13318 | { | |
13319 | c_parser_consume_pragma (parser); | |
13320 | c_parser_skip_to_pragma_eol (parser); | |
13321 | error_suppress = false; | |
13322 | } | |
13323 | else if (!error_suppress) | |
13324 | { | |
13325 | error_at (loc, "expected %<#pragma omp section%> or %<}%>"); | |
13326 | error_suppress = true; | |
13327 | } | |
13328 | ||
13329 | substmt = c_parser_omp_structured_block (parser); | |
13330 | substmt = build1 (OMP_SECTION, void_type_node, substmt); | |
13331 | SET_EXPR_LOCATION (substmt, loc); | |
13332 | add_stmt (substmt); | |
13333 | } | |
13334 | c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, | |
13335 | "expected %<#pragma omp section%> or %<}%>"); | |
13336 | ||
13337 | substmt = pop_stmt_list (stmt); | |
13338 | ||
13339 | stmt = make_node (OMP_SECTIONS); | |
13340 | SET_EXPR_LOCATION (stmt, sections_loc); | |
13341 | TREE_TYPE (stmt) = void_type_node; | |
13342 | OMP_SECTIONS_BODY (stmt) = substmt; | |
13343 | ||
13344 | return add_stmt (stmt); | |
1e8e9920 | 13345 | } |
13346 | ||
13347 | /* OpenMP 2.5: | |
bc7bff74 | 13348 | # pragma omp sections sections-clause[optseq] newline |
13349 | sections-scope | |
e60a6f7b | 13350 | |
bc7bff74 | 13351 | LOC is the location of the #pragma token. |
13352 | */ | |
fd6481cf | 13353 | |
bc7bff74 | 13354 | #define OMP_SECTIONS_CLAUSE_MASK \ |
13355 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \ | |
13356 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \ | |
13357 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \ | |
13358 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \ | |
13359 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT)) | |
e3b80d49 | 13360 | |
1e8e9920 | 13361 | static tree |
bc7bff74 | 13362 | c_parser_omp_sections (location_t loc, c_parser *parser, |
13363 | char *p_name, omp_clause_mask mask, tree *cclauses) | |
1e8e9920 | 13364 | { |
bc7bff74 | 13365 | tree block, clauses, ret; |
1e8e9920 | 13366 | |
bc7bff74 | 13367 | strcat (p_name, " sections"); |
13368 | mask |= OMP_SECTIONS_CLAUSE_MASK; | |
13369 | if (cclauses) | |
13370 | mask &= ~(OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT); | |
b6889cb0 | 13371 | |
bc7bff74 | 13372 | clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL); |
13373 | if (cclauses) | |
13374 | { | |
13375 | omp_split_clauses (loc, OMP_SECTIONS, mask, clauses, cclauses); | |
13376 | clauses = cclauses[C_OMP_CLAUSE_SPLIT_SECTIONS]; | |
13377 | } | |
1e8e9920 | 13378 | |
bc7bff74 | 13379 | block = c_begin_compound_stmt (true); |
13380 | ret = c_parser_omp_sections_scope (loc, parser); | |
13381 | if (ret) | |
13382 | OMP_SECTIONS_CLAUSES (ret) = clauses; | |
13383 | block = c_end_compound_stmt (loc, block, true); | |
13384 | add_stmt (block); | |
fd6481cf | 13385 | |
bc7bff74 | 13386 | return ret; |
13387 | } | |
fd6481cf | 13388 | |
bc7bff74 | 13389 | /* OpenMP 2.5: |
395dc01c | 13390 | # pragma omp parallel parallel-clause[optseq] new-line |
13391 | structured-block | |
13392 | # pragma omp parallel for parallel-for-clause[optseq] new-line | |
13393 | structured-block | |
13394 | # pragma omp parallel sections parallel-sections-clause[optseq] new-line | |
13395 | structured-block | |
13396 | ||
13397 | OpenMP 4.0: | |
13398 | # pragma omp parallel for simd parallel-for-simd-clause[optseq] new-line | |
13399 | structured-block | |
fd6481cf | 13400 | |
bc7bff74 | 13401 | LOC is the location of the #pragma token. |
13402 | */ | |
1e8e9920 | 13403 | |
bc7bff74 | 13404 | #define OMP_PARALLEL_CLAUSE_MASK \ |
13405 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \ | |
13406 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \ | |
13407 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \ | |
13408 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \ | |
13409 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \ | |
13410 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYIN) \ | |
13411 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \ | |
13412 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_THREADS) \ | |
13413 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PROC_BIND)) | |
1e8e9920 | 13414 | |
bc7bff74 | 13415 | static tree |
13416 | c_parser_omp_parallel (location_t loc, c_parser *parser, | |
13417 | char *p_name, omp_clause_mask mask, tree *cclauses) | |
13418 | { | |
13419 | tree stmt, clauses, block; | |
13420 | ||
13421 | strcat (p_name, " parallel"); | |
13422 | mask |= OMP_PARALLEL_CLAUSE_MASK; | |
13423 | ||
13424 | if (c_parser_next_token_is_keyword (parser, RID_FOR)) | |
fd6481cf | 13425 | { |
bc7bff74 | 13426 | tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT]; |
13427 | if (cclauses == NULL) | |
13428 | cclauses = cclauses_buf; | |
13429 | ||
1e8e9920 | 13430 | c_parser_consume_token (parser); |
c630ef93 | 13431 | if (!flag_openmp) /* flag_openmp_simd */ |
13432 | return c_parser_omp_for (loc, parser, p_name, mask, cclauses); | |
bc7bff74 | 13433 | block = c_begin_omp_parallel (); |
9f0a7bc6 | 13434 | tree ret = c_parser_omp_for (loc, parser, p_name, mask, cclauses); |
bc7bff74 | 13435 | stmt |
13436 | = c_finish_omp_parallel (loc, cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL], | |
13437 | block); | |
9f0a7bc6 | 13438 | if (ret == NULL_TREE) |
13439 | return ret; | |
bc7bff74 | 13440 | OMP_PARALLEL_COMBINED (stmt) = 1; |
13441 | return stmt; | |
fd6481cf | 13442 | } |
bc7bff74 | 13443 | else if (cclauses) |
e60a6f7b | 13444 | { |
bc7bff74 | 13445 | error_at (loc, "expected %<for%> after %qs", p_name); |
13446 | c_parser_skip_to_pragma_eol (parser); | |
13447 | return NULL_TREE; | |
e60a6f7b | 13448 | } |
c630ef93 | 13449 | else if (!flag_openmp) /* flag_openmp_simd */ |
13450 | { | |
13451 | c_parser_skip_to_pragma_eol (parser); | |
13452 | return NULL_TREE; | |
13453 | } | |
bc7bff74 | 13454 | else if (c_parser_next_token_is (parser, CPP_NAME)) |
fd6481cf | 13455 | { |
bc7bff74 | 13456 | const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
13457 | if (strcmp (p, "sections") == 0) | |
fd6481cf | 13458 | { |
bc7bff74 | 13459 | tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT]; |
13460 | if (cclauses == NULL) | |
13461 | cclauses = cclauses_buf; | |
13462 | ||
fd6481cf | 13463 | c_parser_consume_token (parser); |
bc7bff74 | 13464 | block = c_begin_omp_parallel (); |
13465 | c_parser_omp_sections (loc, parser, p_name, mask, cclauses); | |
13466 | stmt = c_finish_omp_parallel (loc, | |
13467 | cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL], | |
13468 | block); | |
13469 | OMP_PARALLEL_COMBINED (stmt) = 1; | |
13470 | return stmt; | |
fd6481cf | 13471 | } |
13472 | } | |
13473 | ||
bc7bff74 | 13474 | clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL); |
13475 | ||
13476 | block = c_begin_omp_parallel (); | |
13477 | c_parser_statement (parser); | |
13478 | stmt = c_finish_omp_parallel (loc, clauses, block); | |
13479 | ||
13480 | return stmt; | |
13481 | } | |
13482 | ||
13483 | /* OpenMP 2.5: | |
13484 | # pragma omp single single-clause[optseq] new-line | |
13485 | structured-block | |
13486 | ||
13487 | LOC is the location of the #pragma. | |
13488 | */ | |
13489 | ||
13490 | #define OMP_SINGLE_CLAUSE_MASK \ | |
13491 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \ | |
13492 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \ | |
13493 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \ | |
13494 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT)) | |
13495 | ||
13496 | static tree | |
13497 | c_parser_omp_single (location_t loc, c_parser *parser) | |
13498 | { | |
13499 | tree stmt = make_node (OMP_SINGLE); | |
13500 | SET_EXPR_LOCATION (stmt, loc); | |
13501 | TREE_TYPE (stmt) = void_type_node; | |
13502 | ||
13503 | OMP_SINGLE_CLAUSES (stmt) | |
13504 | = c_parser_omp_all_clauses (parser, OMP_SINGLE_CLAUSE_MASK, | |
13505 | "#pragma omp single"); | |
13506 | OMP_SINGLE_BODY (stmt) = c_parser_omp_structured_block (parser); | |
13507 | ||
13508 | return add_stmt (stmt); | |
13509 | } | |
13510 | ||
13511 | /* OpenMP 3.0: | |
13512 | # pragma omp task task-clause[optseq] new-line | |
13513 | ||
13514 | LOC is the location of the #pragma. | |
13515 | */ | |
13516 | ||
13517 | #define OMP_TASK_CLAUSE_MASK \ | |
13518 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \ | |
13519 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNTIED) \ | |
13520 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \ | |
13521 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \ | |
13522 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \ | |
13523 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \ | |
13524 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FINAL) \ | |
13525 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MERGEABLE) \ | |
13526 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND)) | |
13527 | ||
13528 | static tree | |
13529 | c_parser_omp_task (location_t loc, c_parser *parser) | |
13530 | { | |
13531 | tree clauses, block; | |
13532 | ||
13533 | clauses = c_parser_omp_all_clauses (parser, OMP_TASK_CLAUSE_MASK, | |
13534 | "#pragma omp task"); | |
13535 | ||
13536 | block = c_begin_omp_task (); | |
13537 | c_parser_statement (parser); | |
13538 | return c_finish_omp_task (loc, clauses, block); | |
1e8e9920 | 13539 | } |
13540 | ||
bc7bff74 | 13541 | /* OpenMP 3.0: |
13542 | # pragma omp taskwait new-line | |
13543 | */ | |
1e8e9920 | 13544 | |
13545 | static void | |
bc7bff74 | 13546 | c_parser_omp_taskwait (c_parser *parser) |
1e8e9920 | 13547 | { |
e60a6f7b | 13548 | location_t loc = c_parser_peek_token (parser)->location; |
1e8e9920 | 13549 | c_parser_consume_pragma (parser); |
1e8e9920 | 13550 | c_parser_skip_to_pragma_eol (parser); |
13551 | ||
bc7bff74 | 13552 | c_finish_omp_taskwait (loc); |
1e8e9920 | 13553 | } |
13554 | ||
bc7bff74 | 13555 | /* OpenMP 3.1: |
13556 | # pragma omp taskyield new-line | |
13557 | */ | |
1e8e9920 | 13558 | |
bc7bff74 | 13559 | static void |
13560 | c_parser_omp_taskyield (c_parser *parser) | |
1e8e9920 | 13561 | { |
bc7bff74 | 13562 | location_t loc = c_parser_peek_token (parser)->location; |
13563 | c_parser_consume_pragma (parser); | |
13564 | c_parser_skip_to_pragma_eol (parser); | |
fd6481cf | 13565 | |
bc7bff74 | 13566 | c_finish_omp_taskyield (loc); |
13567 | } | |
e3b80d49 | 13568 | |
bc7bff74 | 13569 | /* OpenMP 4.0: |
13570 | # pragma omp taskgroup new-line | |
13571 | */ | |
1e8e9920 | 13572 | |
bc7bff74 | 13573 | static tree |
13574 | c_parser_omp_taskgroup (c_parser *parser) | |
13575 | { | |
13576 | location_t loc = c_parser_peek_token (parser)->location; | |
13577 | c_parser_skip_to_pragma_eol (parser); | |
13578 | return c_finish_omp_taskgroup (loc, c_parser_omp_structured_block (parser)); | |
13579 | } | |
b6889cb0 | 13580 | |
bc7bff74 | 13581 | /* OpenMP 4.0: |
13582 | # pragma omp cancel cancel-clause[optseq] new-line | |
1e8e9920 | 13583 | |
bc7bff74 | 13584 | LOC is the location of the #pragma. |
13585 | */ | |
fd6481cf | 13586 | |
bc7bff74 | 13587 | #define OMP_CANCEL_CLAUSE_MASK \ |
13588 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \ | |
13589 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \ | |
13590 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \ | |
13591 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP) \ | |
13592 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF)) | |
fd6481cf | 13593 | |
bc7bff74 | 13594 | static void |
13595 | c_parser_omp_cancel (c_parser *parser) | |
13596 | { | |
13597 | location_t loc = c_parser_peek_token (parser)->location; | |
fd6481cf | 13598 | |
bc7bff74 | 13599 | c_parser_consume_pragma (parser); |
13600 | tree clauses = c_parser_omp_all_clauses (parser, OMP_CANCEL_CLAUSE_MASK, | |
13601 | "#pragma omp cancel"); | |
1e8e9920 | 13602 | |
bc7bff74 | 13603 | c_finish_omp_cancel (loc, clauses); |
13604 | } | |
1e8e9920 | 13605 | |
bc7bff74 | 13606 | /* OpenMP 4.0: |
13607 | # pragma omp cancellation point cancelpt-clause[optseq] new-line | |
1e8e9920 | 13608 | |
bc7bff74 | 13609 | LOC is the location of the #pragma. |
13610 | */ | |
1e8e9920 | 13611 | |
bc7bff74 | 13612 | #define OMP_CANCELLATION_POINT_CLAUSE_MASK \ |
13613 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \ | |
13614 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \ | |
13615 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \ | |
13616 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP)) | |
fd6481cf | 13617 | |
bc7bff74 | 13618 | static void |
13619 | c_parser_omp_cancellation_point (c_parser *parser) | |
13620 | { | |
13621 | location_t loc = c_parser_peek_token (parser)->location; | |
13622 | tree clauses; | |
13623 | bool point_seen = false; | |
13624 | ||
13625 | c_parser_consume_pragma (parser); | |
13626 | if (c_parser_next_token_is (parser, CPP_NAME)) | |
fd6481cf | 13627 | { |
bc7bff74 | 13628 | const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
13629 | if (strcmp (p, "point") == 0) | |
fd6481cf | 13630 | { |
bc7bff74 | 13631 | c_parser_consume_token (parser); |
13632 | point_seen = true; | |
fd6481cf | 13633 | } |
fd6481cf | 13634 | } |
bc7bff74 | 13635 | if (!point_seen) |
fd6481cf | 13636 | { |
bc7bff74 | 13637 | c_parser_error (parser, "expected %<point%>"); |
13638 | c_parser_skip_to_pragma_eol (parser); | |
13639 | return; | |
fd6481cf | 13640 | } |
1e8e9920 | 13641 | |
bc7bff74 | 13642 | clauses |
13643 | = c_parser_omp_all_clauses (parser, OMP_CANCELLATION_POINT_CLAUSE_MASK, | |
13644 | "#pragma omp cancellation point"); | |
e60a6f7b | 13645 | |
bc7bff74 | 13646 | c_finish_omp_cancellation_point (loc, clauses); |
13647 | } | |
1e8e9920 | 13648 | |
bc7bff74 | 13649 | /* OpenMP 4.0: |
13650 | #pragma omp distribute distribute-clause[optseq] new-line | |
13651 | for-loop */ | |
13652 | ||
13653 | #define OMP_DISTRIBUTE_CLAUSE_MASK \ | |
13654 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \ | |
13655 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \ | |
13656 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)\ | |
13657 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE)) | |
1e8e9920 | 13658 | |
13659 | static tree | |
bc7bff74 | 13660 | c_parser_omp_distribute (location_t loc, c_parser *parser, |
13661 | char *p_name, omp_clause_mask mask, tree *cclauses) | |
1e8e9920 | 13662 | { |
bc7bff74 | 13663 | tree clauses, block, ret; |
13664 | ||
13665 | strcat (p_name, " distribute"); | |
13666 | mask |= OMP_DISTRIBUTE_CLAUSE_MASK; | |
13667 | ||
13668 | if (c_parser_next_token_is (parser, CPP_NAME)) | |
13669 | { | |
13670 | const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); | |
13671 | bool simd = false; | |
13672 | bool parallel = false; | |
13673 | ||
13674 | if (strcmp (p, "simd") == 0) | |
13675 | simd = true; | |
13676 | else | |
13677 | parallel = strcmp (p, "parallel") == 0; | |
13678 | if (parallel || simd) | |
13679 | { | |
13680 | tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT]; | |
13681 | if (cclauses == NULL) | |
13682 | cclauses = cclauses_buf; | |
13683 | c_parser_consume_token (parser); | |
c630ef93 | 13684 | if (!flag_openmp) /* flag_openmp_simd */ |
13685 | { | |
13686 | if (simd) | |
13687 | return c_parser_omp_simd (loc, parser, p_name, mask, cclauses); | |
13688 | else | |
13689 | return c_parser_omp_parallel (loc, parser, p_name, mask, | |
13690 | cclauses); | |
13691 | } | |
bc7bff74 | 13692 | block = c_begin_compound_stmt (true); |
13693 | if (simd) | |
13694 | ret = c_parser_omp_simd (loc, parser, p_name, mask, cclauses); | |
13695 | else | |
13696 | ret = c_parser_omp_parallel (loc, parser, p_name, mask, cclauses); | |
13697 | block = c_end_compound_stmt (loc, block, true); | |
13698 | if (ret == NULL) | |
13699 | return ret; | |
13700 | ret = make_node (OMP_DISTRIBUTE); | |
13701 | TREE_TYPE (ret) = void_type_node; | |
13702 | OMP_FOR_BODY (ret) = block; | |
13703 | OMP_FOR_CLAUSES (ret) = cclauses[C_OMP_CLAUSE_SPLIT_DISTRIBUTE]; | |
13704 | SET_EXPR_LOCATION (ret, loc); | |
13705 | add_stmt (ret); | |
13706 | return ret; | |
13707 | } | |
13708 | } | |
c630ef93 | 13709 | if (!flag_openmp) /* flag_openmp_simd */ |
13710 | { | |
13711 | c_parser_skip_to_pragma_eol (parser); | |
13712 | return NULL_TREE; | |
13713 | } | |
1e8e9920 | 13714 | |
bc7bff74 | 13715 | clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL); |
13716 | if (cclauses) | |
13717 | { | |
13718 | omp_split_clauses (loc, OMP_DISTRIBUTE, mask, clauses, cclauses); | |
13719 | clauses = cclauses[C_OMP_CLAUSE_SPLIT_DISTRIBUTE]; | |
13720 | } | |
1e8e9920 | 13721 | |
13722 | block = c_begin_compound_stmt (true); | |
bc7bff74 | 13723 | ret = c_parser_omp_for_loop (loc, parser, OMP_DISTRIBUTE, clauses, NULL); |
e60a6f7b | 13724 | block = c_end_compound_stmt (loc, block, true); |
1e8e9920 | 13725 | add_stmt (block); |
13726 | ||
13727 | return ret; | |
13728 | } | |
13729 | ||
bc7bff74 | 13730 | /* OpenMP 4.0: |
13731 | # pragma omp teams teams-clause[optseq] new-line | |
13732 | structured-block */ | |
e60a6f7b | 13733 | |
bc7bff74 | 13734 | #define OMP_TEAMS_CLAUSE_MASK \ |
13735 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \ | |
13736 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \ | |
13737 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \ | |
13738 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \ | |
13739 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_TEAMS) \ | |
13740 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_THREAD_LIMIT) \ | |
13741 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT)) | |
1e8e9920 | 13742 | |
13743 | static tree | |
bc7bff74 | 13744 | c_parser_omp_teams (location_t loc, c_parser *parser, |
13745 | char *p_name, omp_clause_mask mask, tree *cclauses) | |
1e8e9920 | 13746 | { |
bc7bff74 | 13747 | tree clauses, block, ret; |
13748 | ||
13749 | strcat (p_name, " teams"); | |
13750 | mask |= OMP_TEAMS_CLAUSE_MASK; | |
13751 | ||
13752 | if (c_parser_next_token_is (parser, CPP_NAME)) | |
13753 | { | |
13754 | const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); | |
13755 | if (strcmp (p, "distribute") == 0) | |
13756 | { | |
13757 | tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT]; | |
13758 | if (cclauses == NULL) | |
13759 | cclauses = cclauses_buf; | |
13760 | ||
13761 | c_parser_consume_token (parser); | |
c630ef93 | 13762 | if (!flag_openmp) /* flag_openmp_simd */ |
13763 | return c_parser_omp_distribute (loc, parser, p_name, mask, cclauses); | |
bc7bff74 | 13764 | block = c_begin_compound_stmt (true); |
13765 | ret = c_parser_omp_distribute (loc, parser, p_name, mask, cclauses); | |
13766 | block = c_end_compound_stmt (loc, block, true); | |
13767 | if (ret == NULL) | |
13768 | return ret; | |
13769 | clauses = cclauses[C_OMP_CLAUSE_SPLIT_TEAMS]; | |
13770 | ret = make_node (OMP_TEAMS); | |
13771 | TREE_TYPE (ret) = void_type_node; | |
13772 | OMP_TEAMS_CLAUSES (ret) = clauses; | |
13773 | OMP_TEAMS_BODY (ret) = block; | |
13774 | return add_stmt (ret); | |
13775 | } | |
13776 | } | |
c630ef93 | 13777 | if (!flag_openmp) /* flag_openmp_simd */ |
13778 | { | |
13779 | c_parser_skip_to_pragma_eol (parser); | |
13780 | return NULL_TREE; | |
13781 | } | |
bc7bff74 | 13782 | |
13783 | clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL); | |
13784 | if (cclauses) | |
13785 | { | |
13786 | omp_split_clauses (loc, OMP_TEAMS, mask, clauses, cclauses); | |
13787 | clauses = cclauses[C_OMP_CLAUSE_SPLIT_TEAMS]; | |
13788 | } | |
13789 | ||
13790 | tree stmt = make_node (OMP_TEAMS); | |
13791 | TREE_TYPE (stmt) = void_type_node; | |
13792 | OMP_TEAMS_CLAUSES (stmt) = clauses; | |
13793 | OMP_TEAMS_BODY (stmt) = c_parser_omp_structured_block (parser); | |
13794 | ||
13795 | return add_stmt (stmt); | |
1e8e9920 | 13796 | } |
13797 | ||
bc7bff74 | 13798 | /* OpenMP 4.0: |
13799 | # pragma omp target data target-data-clause[optseq] new-line | |
13800 | structured-block */ | |
e60a6f7b | 13801 | |
bc7bff74 | 13802 | #define OMP_TARGET_DATA_CLAUSE_MASK \ |
13803 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \ | |
13804 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \ | |
13805 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF)) | |
1e8e9920 | 13806 | |
13807 | static tree | |
bc7bff74 | 13808 | c_parser_omp_target_data (location_t loc, c_parser *parser) |
1e8e9920 | 13809 | { |
bc7bff74 | 13810 | tree stmt = make_node (OMP_TARGET_DATA); |
13811 | TREE_TYPE (stmt) = void_type_node; | |
1e8e9920 | 13812 | |
bc7bff74 | 13813 | OMP_TARGET_DATA_CLAUSES (stmt) |
13814 | = c_parser_omp_all_clauses (parser, OMP_TARGET_DATA_CLAUSE_MASK, | |
13815 | "#pragma omp target data"); | |
13816 | keep_next_level (); | |
13817 | tree block = c_begin_compound_stmt (true); | |
13818 | add_stmt (c_parser_omp_structured_block (parser)); | |
13819 | OMP_TARGET_DATA_BODY (stmt) = c_end_compound_stmt (loc, block, true); | |
1e8e9920 | 13820 | |
bc7bff74 | 13821 | SET_EXPR_LOCATION (stmt, loc); |
13822 | return add_stmt (stmt); | |
13823 | } | |
1e8e9920 | 13824 | |
bc7bff74 | 13825 | /* OpenMP 4.0: |
13826 | # pragma omp target update target-update-clause[optseq] new-line */ | |
e60a6f7b | 13827 | |
bc7bff74 | 13828 | #define OMP_TARGET_UPDATE_CLAUSE_MASK \ |
13829 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FROM) \ | |
13830 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TO) \ | |
13831 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \ | |
13832 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF)) | |
1e8e9920 | 13833 | |
bc7bff74 | 13834 | static bool |
13835 | c_parser_omp_target_update (location_t loc, c_parser *parser, | |
13836 | enum pragma_context context) | |
1e8e9920 | 13837 | { |
bc7bff74 | 13838 | if (context == pragma_stmt) |
13839 | { | |
13840 | error_at (loc, | |
13841 | "%<#pragma omp target update%> may only be " | |
13842 | "used in compound statements"); | |
13843 | c_parser_skip_to_pragma_eol (parser); | |
13844 | return false; | |
13845 | } | |
1e8e9920 | 13846 | |
bc7bff74 | 13847 | tree clauses |
13848 | = c_parser_omp_all_clauses (parser, OMP_TARGET_UPDATE_CLAUSE_MASK, | |
13849 | "#pragma omp target update"); | |
13850 | if (find_omp_clause (clauses, OMP_CLAUSE_TO) == NULL_TREE | |
13851 | && find_omp_clause (clauses, OMP_CLAUSE_FROM) == NULL_TREE) | |
1e8e9920 | 13852 | { |
bc7bff74 | 13853 | error_at (loc, |
13854 | "%<#pragma omp target update must contain at least one " | |
13855 | "%<from%> or %<to%> clauses"); | |
13856 | return false; | |
1e8e9920 | 13857 | } |
13858 | ||
bc7bff74 | 13859 | tree stmt = make_node (OMP_TARGET_UPDATE); |
13860 | TREE_TYPE (stmt) = void_type_node; | |
13861 | OMP_TARGET_UPDATE_CLAUSES (stmt) = clauses; | |
13862 | SET_EXPR_LOCATION (stmt, loc); | |
13863 | add_stmt (stmt); | |
13864 | return false; | |
13865 | } | |
1e8e9920 | 13866 | |
bc7bff74 | 13867 | /* OpenMP 4.0: |
13868 | # pragma omp target target-clause[optseq] new-line | |
13869 | structured-block */ | |
1e8e9920 | 13870 | |
bc7bff74 | 13871 | #define OMP_TARGET_CLAUSE_MASK \ |
13872 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \ | |
13873 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \ | |
13874 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF)) | |
1e8e9920 | 13875 | |
bc7bff74 | 13876 | static bool |
13877 | c_parser_omp_target (c_parser *parser, enum pragma_context context) | |
13878 | { | |
13879 | location_t loc = c_parser_peek_token (parser)->location; | |
13880 | c_parser_consume_pragma (parser); | |
1e8e9920 | 13881 | |
bc7bff74 | 13882 | if (context != pragma_stmt && context != pragma_compound) |
13883 | { | |
13884 | c_parser_error (parser, "expected declaration specifiers"); | |
13885 | c_parser_skip_to_pragma_eol (parser); | |
13886 | return false; | |
1e8e9920 | 13887 | } |
13888 | ||
bc7bff74 | 13889 | if (c_parser_next_token_is (parser, CPP_NAME)) |
1e8e9920 | 13890 | { |
bc7bff74 | 13891 | const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
1e8e9920 | 13892 | |
c630ef93 | 13893 | if (strcmp (p, "teams") == 0) |
bc7bff74 | 13894 | { |
13895 | tree cclauses[C_OMP_CLAUSE_SPLIT_COUNT]; | |
13896 | char p_name[sizeof ("#pragma omp target teams distribute " | |
13897 | "parallel for simd")]; | |
1e8e9920 | 13898 | |
bc7bff74 | 13899 | c_parser_consume_token (parser); |
dc133326 | 13900 | strcpy (p_name, "#pragma omp target"); |
c630ef93 | 13901 | if (!flag_openmp) /* flag_openmp_simd */ |
184a718f | 13902 | { |
13903 | tree stmt = c_parser_omp_teams (loc, parser, p_name, | |
13904 | OMP_TARGET_CLAUSE_MASK, | |
13905 | cclauses); | |
13906 | return stmt != NULL_TREE; | |
13907 | } | |
bc7bff74 | 13908 | keep_next_level (); |
13909 | tree block = c_begin_compound_stmt (true); | |
13910 | tree ret = c_parser_omp_teams (loc, parser, p_name, | |
13911 | OMP_TARGET_CLAUSE_MASK, cclauses); | |
13912 | block = c_end_compound_stmt (loc, block, true); | |
184a718f | 13913 | if (ret == NULL_TREE) |
13914 | return false; | |
bc7bff74 | 13915 | tree stmt = make_node (OMP_TARGET); |
13916 | TREE_TYPE (stmt) = void_type_node; | |
13917 | OMP_TARGET_CLAUSES (stmt) = cclauses[C_OMP_CLAUSE_SPLIT_TARGET]; | |
13918 | OMP_TARGET_BODY (stmt) = block; | |
13919 | add_stmt (stmt); | |
13920 | return true; | |
13921 | } | |
c630ef93 | 13922 | else if (!flag_openmp) /* flag_openmp_simd */ |
13923 | { | |
13924 | c_parser_skip_to_pragma_eol (parser); | |
184a718f | 13925 | return false; |
c630ef93 | 13926 | } |
13927 | else if (strcmp (p, "data") == 0) | |
13928 | { | |
13929 | c_parser_consume_token (parser); | |
13930 | c_parser_omp_target_data (loc, parser); | |
13931 | return true; | |
13932 | } | |
13933 | else if (strcmp (p, "update") == 0) | |
13934 | { | |
13935 | c_parser_consume_token (parser); | |
13936 | return c_parser_omp_target_update (loc, parser, context); | |
13937 | } | |
1e8e9920 | 13938 | } |
1e8e9920 | 13939 | |
bc7bff74 | 13940 | tree stmt = make_node (OMP_TARGET); |
1e8e9920 | 13941 | TREE_TYPE (stmt) = void_type_node; |
1e8e9920 | 13942 | |
bc7bff74 | 13943 | OMP_TARGET_CLAUSES (stmt) |
13944 | = c_parser_omp_all_clauses (parser, OMP_TARGET_CLAUSE_MASK, | |
13945 | "#pragma omp target"); | |
13946 | keep_next_level (); | |
13947 | tree block = c_begin_compound_stmt (true); | |
13948 | add_stmt (c_parser_omp_structured_block (parser)); | |
13949 | OMP_TARGET_BODY (stmt) = c_end_compound_stmt (loc, block, true); | |
13950 | ||
13951 | SET_EXPR_LOCATION (stmt, loc); | |
13952 | add_stmt (stmt); | |
13953 | return true; | |
13954 | } | |
13955 | ||
13956 | /* OpenMP 4.0: | |
13957 | # pragma omp declare simd declare-simd-clauses[optseq] new-line */ | |
13958 | ||
13959 | #define OMP_DECLARE_SIMD_CLAUSE_MASK \ | |
13960 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMDLEN) \ | |
13961 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \ | |
13962 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \ | |
13963 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNIFORM) \ | |
13964 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_INBRANCH) \ | |
13965 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOTINBRANCH)) | |
13966 | ||
13967 | static void | |
13968 | c_parser_omp_declare_simd (c_parser *parser, enum pragma_context context) | |
13969 | { | |
13970 | vec<c_token> clauses = vNULL; | |
13971 | while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL)) | |
13972 | { | |
13973 | c_token *token = c_parser_peek_token (parser); | |
13974 | if (token->type == CPP_EOF) | |
13975 | { | |
13976 | c_parser_skip_to_pragma_eol (parser); | |
13977 | clauses.release (); | |
13978 | return; | |
13979 | } | |
13980 | clauses.safe_push (*token); | |
13981 | c_parser_consume_token (parser); | |
13982 | } | |
13983 | clauses.safe_push (*c_parser_peek_token (parser)); | |
13984 | c_parser_skip_to_pragma_eol (parser); | |
13985 | ||
13986 | while (c_parser_next_token_is (parser, CPP_PRAGMA)) | |
13987 | { | |
13988 | if (c_parser_peek_token (parser)->pragma_kind | |
13989 | != PRAGMA_OMP_DECLARE_REDUCTION | |
13990 | || c_parser_peek_2nd_token (parser)->type != CPP_NAME | |
13991 | || strcmp (IDENTIFIER_POINTER | |
13992 | (c_parser_peek_2nd_token (parser)->value), | |
13993 | "simd") != 0) | |
13994 | { | |
13995 | c_parser_error (parser, | |
13996 | "%<#pragma omp declare simd%> must be followed by " | |
13997 | "function declaration or definition or another " | |
13998 | "%<#pragma omp declare simd%>"); | |
13999 | clauses.release (); | |
14000 | return; | |
14001 | } | |
14002 | c_parser_consume_pragma (parser); | |
14003 | while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL)) | |
14004 | { | |
14005 | c_token *token = c_parser_peek_token (parser); | |
14006 | if (token->type == CPP_EOF) | |
14007 | { | |
14008 | c_parser_skip_to_pragma_eol (parser); | |
14009 | clauses.release (); | |
14010 | return; | |
14011 | } | |
14012 | clauses.safe_push (*token); | |
14013 | c_parser_consume_token (parser); | |
14014 | } | |
14015 | clauses.safe_push (*c_parser_peek_token (parser)); | |
14016 | c_parser_skip_to_pragma_eol (parser); | |
14017 | } | |
14018 | ||
14019 | /* Make sure nothing tries to read past the end of the tokens. */ | |
14020 | c_token eof_token; | |
14021 | memset (&eof_token, 0, sizeof (eof_token)); | |
14022 | eof_token.type = CPP_EOF; | |
14023 | clauses.safe_push (eof_token); | |
14024 | clauses.safe_push (eof_token); | |
14025 | ||
14026 | switch (context) | |
14027 | { | |
14028 | case pragma_external: | |
14029 | if (c_parser_next_token_is (parser, CPP_KEYWORD) | |
14030 | && c_parser_peek_token (parser)->keyword == RID_EXTENSION) | |
14031 | { | |
14032 | int ext = disable_extension_diagnostics (); | |
14033 | do | |
14034 | c_parser_consume_token (parser); | |
14035 | while (c_parser_next_token_is (parser, CPP_KEYWORD) | |
14036 | && c_parser_peek_token (parser)->keyword == RID_EXTENSION); | |
14037 | c_parser_declaration_or_fndef (parser, true, true, true, false, true, | |
14038 | NULL, clauses); | |
14039 | restore_extension_diagnostics (ext); | |
14040 | } | |
14041 | else | |
14042 | c_parser_declaration_or_fndef (parser, true, true, true, false, true, | |
14043 | NULL, clauses); | |
14044 | break; | |
14045 | case pragma_struct: | |
14046 | case pragma_param: | |
14047 | c_parser_error (parser, "%<#pragma omp declare simd%> must be followed by " | |
14048 | "function declaration or definition"); | |
14049 | break; | |
14050 | case pragma_compound: | |
14051 | case pragma_stmt: | |
14052 | if (c_parser_next_token_is (parser, CPP_KEYWORD) | |
14053 | && c_parser_peek_token (parser)->keyword == RID_EXTENSION) | |
14054 | { | |
14055 | int ext = disable_extension_diagnostics (); | |
14056 | do | |
14057 | c_parser_consume_token (parser); | |
14058 | while (c_parser_next_token_is (parser, CPP_KEYWORD) | |
14059 | && c_parser_peek_token (parser)->keyword == RID_EXTENSION); | |
14060 | if (c_parser_next_tokens_start_declaration (parser)) | |
14061 | { | |
14062 | c_parser_declaration_or_fndef (parser, true, true, true, true, | |
14063 | true, NULL, clauses); | |
14064 | restore_extension_diagnostics (ext); | |
14065 | break; | |
14066 | } | |
14067 | restore_extension_diagnostics (ext); | |
14068 | } | |
14069 | else if (c_parser_next_tokens_start_declaration (parser)) | |
14070 | { | |
14071 | c_parser_declaration_or_fndef (parser, true, true, true, true, true, | |
14072 | NULL, clauses); | |
14073 | break; | |
14074 | } | |
14075 | c_parser_error (parser, "%<#pragma omp declare simd%> must be followed by " | |
14076 | "function declaration or definition"); | |
14077 | break; | |
14078 | default: | |
14079 | gcc_unreachable (); | |
14080 | } | |
14081 | clauses.release (); | |
1e8e9920 | 14082 | } |
14083 | ||
bc7bff74 | 14084 | /* Finalize #pragma omp declare simd clauses after FNDECL has been parsed, |
14085 | and put that into "omp declare simd" attribute. */ | |
e60a6f7b | 14086 | |
bc7bff74 | 14087 | static void |
14088 | c_finish_omp_declare_simd (c_parser *parser, tree fndecl, tree parms, | |
14089 | vec<c_token> clauses) | |
14090 | { | |
a89e6c15 | 14091 | if (flag_cilkplus |
74acc703 | 14092 | && clauses.exists () && !vec_safe_is_empty (parser->cilk_simd_fn_tokens)) |
14093 | { | |
14094 | error ("%<#pragma omp declare simd%> cannot be used in the same " | |
14095 | "function marked as a Cilk Plus SIMD-enabled function"); | |
14096 | vec_free (parser->cilk_simd_fn_tokens); | |
14097 | return; | |
14098 | } | |
14099 | ||
bc7bff74 | 14100 | /* Normally first token is CPP_NAME "simd". CPP_EOF there indicates |
14101 | error has been reported and CPP_PRAGMA that c_finish_omp_declare_simd | |
14102 | has already processed the tokens. */ | |
74acc703 | 14103 | if (clauses.exists () && clauses[0].type == CPP_EOF) |
bc7bff74 | 14104 | return; |
14105 | if (fndecl == NULL_TREE || TREE_CODE (fndecl) != FUNCTION_DECL) | |
14106 | { | |
14107 | error ("%<#pragma omp declare simd%> not immediately followed by " | |
14108 | "a function declaration or definition"); | |
14109 | clauses[0].type = CPP_EOF; | |
14110 | return; | |
14111 | } | |
74acc703 | 14112 | if (clauses.exists () && clauses[0].type != CPP_NAME) |
bc7bff74 | 14113 | { |
14114 | error_at (DECL_SOURCE_LOCATION (fndecl), | |
14115 | "%<#pragma omp declare simd%> not immediately followed by " | |
14116 | "a single function declaration or definition"); | |
14117 | clauses[0].type = CPP_EOF; | |
14118 | return; | |
14119 | } | |
1e8e9920 | 14120 | |
bc7bff74 | 14121 | if (parms == NULL_TREE) |
14122 | parms = DECL_ARGUMENTS (fndecl); | |
1e8e9920 | 14123 | |
bc7bff74 | 14124 | unsigned int tokens_avail = parser->tokens_avail; |
14125 | gcc_assert (parser->tokens == &parser->tokens_buf[0]); | |
74acc703 | 14126 | bool is_cilkplus_cilk_simd_fn = false; |
14127 | ||
a89e6c15 | 14128 | if (flag_cilkplus && !vec_safe_is_empty (parser->cilk_simd_fn_tokens)) |
74acc703 | 14129 | { |
14130 | parser->tokens = parser->cilk_simd_fn_tokens->address (); | |
14131 | parser->tokens_avail = vec_safe_length (parser->cilk_simd_fn_tokens); | |
14132 | is_cilkplus_cilk_simd_fn = true; | |
14133 | } | |
14134 | else | |
14135 | { | |
14136 | parser->tokens = clauses.address (); | |
14137 | parser->tokens_avail = clauses.length (); | |
14138 | } | |
14139 | ||
bc7bff74 | 14140 | /* c_parser_omp_declare_simd pushed 2 extra CPP_EOF tokens at the end. */ |
14141 | while (parser->tokens_avail > 3) | |
14142 | { | |
14143 | c_token *token = c_parser_peek_token (parser); | |
74acc703 | 14144 | if (!is_cilkplus_cilk_simd_fn) |
14145 | gcc_assert (token->type == CPP_NAME | |
14146 | && strcmp (IDENTIFIER_POINTER (token->value), "simd") == 0); | |
14147 | else | |
14148 | gcc_assert (token->type == CPP_NAME | |
14149 | && is_cilkplus_vector_p (token->value)); | |
bc7bff74 | 14150 | c_parser_consume_token (parser); |
14151 | parser->in_pragma = true; | |
1e8e9920 | 14152 | |
74acc703 | 14153 | tree c = NULL_TREE; |
14154 | if (is_cilkplus_cilk_simd_fn) | |
14155 | c = c_parser_omp_all_clauses (parser, CILK_SIMD_FN_CLAUSE_MASK, | |
14156 | "SIMD-enabled functions attribute"); | |
14157 | else | |
14158 | c = c_parser_omp_all_clauses (parser, OMP_DECLARE_SIMD_CLAUSE_MASK, | |
14159 | "#pragma omp declare simd"); | |
bc7bff74 | 14160 | c = c_omp_declare_simd_clauses_to_numbers (parms, c); |
14161 | if (c != NULL_TREE) | |
14162 | c = tree_cons (NULL_TREE, c, NULL_TREE); | |
74acc703 | 14163 | if (is_cilkplus_cilk_simd_fn) |
14164 | { | |
7e005ab5 | 14165 | tree k = build_tree_list (get_identifier ("cilk simd function"), |
14166 | NULL_TREE); | |
74acc703 | 14167 | TREE_CHAIN (k) = DECL_ATTRIBUTES (fndecl); |
14168 | DECL_ATTRIBUTES (fndecl) = k; | |
14169 | } | |
bc7bff74 | 14170 | c = build_tree_list (get_identifier ("omp declare simd"), c); |
14171 | TREE_CHAIN (c) = DECL_ATTRIBUTES (fndecl); | |
14172 | DECL_ATTRIBUTES (fndecl) = c; | |
14173 | } | |
1e8e9920 | 14174 | |
bc7bff74 | 14175 | parser->tokens = &parser->tokens_buf[0]; |
14176 | parser->tokens_avail = tokens_avail; | |
74acc703 | 14177 | if (clauses.exists ()) |
14178 | clauses[0].type = CPP_PRAGMA; | |
14179 | ||
14180 | if (!vec_safe_is_empty (parser->cilk_simd_fn_tokens)) | |
14181 | vec_free (parser->cilk_simd_fn_tokens); | |
1e8e9920 | 14182 | } |
14183 | ||
1e8e9920 | 14184 | |
bc7bff74 | 14185 | /* OpenMP 4.0: |
14186 | # pragma omp declare target new-line | |
14187 | declarations and definitions | |
14188 | # pragma omp end declare target new-line */ | |
1e8e9920 | 14189 | |
bc7bff74 | 14190 | static void |
14191 | c_parser_omp_declare_target (c_parser *parser) | |
1e8e9920 | 14192 | { |
bc7bff74 | 14193 | c_parser_skip_to_pragma_eol (parser); |
14194 | current_omp_declare_target_attribute++; | |
14195 | } | |
1e8e9920 | 14196 | |
bc7bff74 | 14197 | static void |
14198 | c_parser_omp_end_declare_target (c_parser *parser) | |
14199 | { | |
14200 | location_t loc = c_parser_peek_token (parser)->location; | |
14201 | c_parser_consume_pragma (parser); | |
14202 | if (c_parser_next_token_is (parser, CPP_NAME) | |
14203 | && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser)->value), | |
14204 | "declare") == 0) | |
1e8e9920 | 14205 | { |
14206 | c_parser_consume_token (parser); | |
bc7bff74 | 14207 | if (c_parser_next_token_is (parser, CPP_NAME) |
14208 | && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser)->value), | |
14209 | "target") == 0) | |
14210 | c_parser_consume_token (parser); | |
14211 | else | |
1e8e9920 | 14212 | { |
bc7bff74 | 14213 | c_parser_error (parser, "expected %<target%>"); |
14214 | c_parser_skip_to_pragma_eol (parser); | |
14215 | return; | |
1e8e9920 | 14216 | } |
14217 | } | |
bc7bff74 | 14218 | else |
14219 | { | |
14220 | c_parser_error (parser, "expected %<declare%>"); | |
14221 | c_parser_skip_to_pragma_eol (parser); | |
14222 | return; | |
14223 | } | |
14224 | c_parser_skip_to_pragma_eol (parser); | |
14225 | if (!current_omp_declare_target_attribute) | |
14226 | error_at (loc, "%<#pragma omp end declare target%> without corresponding " | |
14227 | "%<#pragma omp declare target%>"); | |
14228 | else | |
14229 | current_omp_declare_target_attribute--; | |
14230 | } | |
1e8e9920 | 14231 | |
1e8e9920 | 14232 | |
bc7bff74 | 14233 | /* OpenMP 4.0 |
14234 | #pragma omp declare reduction (reduction-id : typename-list : expression) \ | |
14235 | initializer-clause[opt] new-line | |
14236 | ||
14237 | initializer-clause: | |
14238 | initializer (omp_priv = initializer) | |
14239 | initializer (function-name (argument-list)) */ | |
14240 | ||
14241 | static void | |
14242 | c_parser_omp_declare_reduction (c_parser *parser, enum pragma_context context) | |
14243 | { | |
14244 | unsigned int tokens_avail = 0, i; | |
14245 | vec<tree> types = vNULL; | |
14246 | vec<c_token> clauses = vNULL; | |
14247 | enum tree_code reduc_code = ERROR_MARK; | |
14248 | tree reduc_id = NULL_TREE; | |
14249 | tree type; | |
14250 | location_t rloc = c_parser_peek_token (parser)->location; | |
14251 | ||
14252 | if (context == pragma_struct || context == pragma_param) | |
1e8e9920 | 14253 | { |
bc7bff74 | 14254 | error ("%<#pragma omp declare reduction%> not at file or block scope"); |
14255 | goto fail; | |
14256 | } | |
1e8e9920 | 14257 | |
bc7bff74 | 14258 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) |
14259 | goto fail; | |
1e8e9920 | 14260 | |
bc7bff74 | 14261 | switch (c_parser_peek_token (parser)->type) |
14262 | { | |
14263 | case CPP_PLUS: | |
14264 | reduc_code = PLUS_EXPR; | |
14265 | break; | |
14266 | case CPP_MULT: | |
14267 | reduc_code = MULT_EXPR; | |
14268 | break; | |
14269 | case CPP_MINUS: | |
14270 | reduc_code = MINUS_EXPR; | |
14271 | break; | |
14272 | case CPP_AND: | |
14273 | reduc_code = BIT_AND_EXPR; | |
14274 | break; | |
14275 | case CPP_XOR: | |
14276 | reduc_code = BIT_XOR_EXPR; | |
14277 | break; | |
14278 | case CPP_OR: | |
14279 | reduc_code = BIT_IOR_EXPR; | |
14280 | break; | |
14281 | case CPP_AND_AND: | |
14282 | reduc_code = TRUTH_ANDIF_EXPR; | |
14283 | break; | |
14284 | case CPP_OR_OR: | |
14285 | reduc_code = TRUTH_ORIF_EXPR; | |
14286 | break; | |
14287 | case CPP_NAME: | |
14288 | const char *p; | |
14289 | p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); | |
14290 | if (strcmp (p, "min") == 0) | |
14291 | { | |
14292 | reduc_code = MIN_EXPR; | |
14293 | break; | |
14294 | } | |
14295 | if (strcmp (p, "max") == 0) | |
14296 | { | |
14297 | reduc_code = MAX_EXPR; | |
14298 | break; | |
14299 | } | |
14300 | reduc_id = c_parser_peek_token (parser)->value; | |
1e8e9920 | 14301 | break; |
1e8e9920 | 14302 | default: |
bc7bff74 | 14303 | c_parser_error (parser, |
14304 | "expected %<+%>, %<*%>, %<-%>, %<&%>, " | |
14305 | "%<^%>, %<|%>, %<&&%>, %<||%>, %<min%> or identifier"); | |
14306 | goto fail; | |
1e8e9920 | 14307 | } |
14308 | ||
bc7bff74 | 14309 | tree orig_reduc_id, reduc_decl; |
14310 | orig_reduc_id = reduc_id; | |
14311 | reduc_id = c_omp_reduction_id (reduc_code, reduc_id); | |
14312 | reduc_decl = c_omp_reduction_decl (reduc_id); | |
14313 | c_parser_consume_token (parser); | |
1e8e9920 | 14314 | |
bc7bff74 | 14315 | if (!c_parser_require (parser, CPP_COLON, "expected %<:%>")) |
14316 | goto fail; | |
e60a6f7b | 14317 | |
bc7bff74 | 14318 | while (true) |
14319 | { | |
14320 | location_t loc = c_parser_peek_token (parser)->location; | |
14321 | struct c_type_name *ctype = c_parser_type_name (parser); | |
14322 | if (ctype != NULL) | |
14323 | { | |
14324 | type = groktypename (ctype, NULL, NULL); | |
14325 | if (type == error_mark_node) | |
14326 | ; | |
14327 | else if ((INTEGRAL_TYPE_P (type) | |
14328 | || TREE_CODE (type) == REAL_TYPE | |
14329 | || TREE_CODE (type) == COMPLEX_TYPE) | |
14330 | && orig_reduc_id == NULL_TREE) | |
14331 | error_at (loc, "predeclared arithmetic type in " | |
14332 | "%<#pragma omp declare reduction%>"); | |
14333 | else if (TREE_CODE (type) == FUNCTION_TYPE | |
14334 | || TREE_CODE (type) == ARRAY_TYPE) | |
14335 | error_at (loc, "function or array type in " | |
14336 | "%<#pragma omp declare reduction%>"); | |
14337 | else if (TYPE_QUALS_NO_ADDR_SPACE (type)) | |
14338 | error_at (loc, "const, volatile or restrict qualified type in " | |
14339 | "%<#pragma omp declare reduction%>"); | |
14340 | else | |
14341 | { | |
14342 | tree t; | |
14343 | for (t = DECL_INITIAL (reduc_decl); t; t = TREE_CHAIN (t)) | |
14344 | if (comptypes (TREE_PURPOSE (t), type)) | |
14345 | { | |
14346 | error_at (loc, "redeclaration of %qs " | |
14347 | "%<#pragma omp declare reduction%> for " | |
14348 | "type %qT", | |
14349 | IDENTIFIER_POINTER (reduc_id) | |
14350 | + sizeof ("omp declare reduction ") - 1, | |
14351 | type); | |
14352 | location_t ploc | |
14353 | = DECL_SOURCE_LOCATION (TREE_VEC_ELT (TREE_VALUE (t), | |
14354 | 0)); | |
14355 | error_at (ploc, "previous %<#pragma omp declare " | |
14356 | "reduction%>"); | |
14357 | break; | |
14358 | } | |
14359 | if (t == NULL_TREE) | |
14360 | types.safe_push (type); | |
14361 | } | |
14362 | if (c_parser_next_token_is (parser, CPP_COMMA)) | |
14363 | c_parser_consume_token (parser); | |
14364 | else | |
14365 | break; | |
14366 | } | |
14367 | else | |
14368 | break; | |
14369 | } | |
1e8e9920 | 14370 | |
bc7bff74 | 14371 | if (!c_parser_require (parser, CPP_COLON, "expected %<:%>") |
14372 | || types.is_empty ()) | |
14373 | { | |
14374 | fail: | |
14375 | clauses.release (); | |
14376 | types.release (); | |
14377 | while (true) | |
14378 | { | |
14379 | c_token *token = c_parser_peek_token (parser); | |
14380 | if (token->type == CPP_EOF || token->type == CPP_PRAGMA_EOL) | |
14381 | break; | |
14382 | c_parser_consume_token (parser); | |
14383 | } | |
14384 | c_parser_skip_to_pragma_eol (parser); | |
14385 | return; | |
14386 | } | |
1e8e9920 | 14387 | |
bc7bff74 | 14388 | if (types.length () > 1) |
14389 | { | |
14390 | while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL)) | |
14391 | { | |
14392 | c_token *token = c_parser_peek_token (parser); | |
14393 | if (token->type == CPP_EOF) | |
14394 | goto fail; | |
14395 | clauses.safe_push (*token); | |
14396 | c_parser_consume_token (parser); | |
14397 | } | |
14398 | clauses.safe_push (*c_parser_peek_token (parser)); | |
14399 | c_parser_skip_to_pragma_eol (parser); | |
1e8e9920 | 14400 | |
bc7bff74 | 14401 | /* Make sure nothing tries to read past the end of the tokens. */ |
14402 | c_token eof_token; | |
14403 | memset (&eof_token, 0, sizeof (eof_token)); | |
14404 | eof_token.type = CPP_EOF; | |
14405 | clauses.safe_push (eof_token); | |
14406 | clauses.safe_push (eof_token); | |
14407 | } | |
1e8e9920 | 14408 | |
bc7bff74 | 14409 | int errs = errorcount; |
14410 | FOR_EACH_VEC_ELT (types, i, type) | |
14411 | { | |
14412 | tokens_avail = parser->tokens_avail; | |
14413 | gcc_assert (parser->tokens == &parser->tokens_buf[0]); | |
14414 | if (!clauses.is_empty ()) | |
14415 | { | |
14416 | parser->tokens = clauses.address (); | |
14417 | parser->tokens_avail = clauses.length (); | |
14418 | parser->in_pragma = true; | |
14419 | } | |
1e8e9920 | 14420 | |
bc7bff74 | 14421 | bool nested = current_function_decl != NULL_TREE; |
14422 | if (nested) | |
14423 | c_push_function_context (); | |
14424 | tree fndecl = build_decl (BUILTINS_LOCATION, FUNCTION_DECL, | |
14425 | reduc_id, default_function_type); | |
14426 | current_function_decl = fndecl; | |
14427 | allocate_struct_function (fndecl, true); | |
14428 | push_scope (); | |
14429 | tree stmt = push_stmt_list (); | |
14430 | /* Intentionally BUILTINS_LOCATION, so that -Wshadow doesn't | |
14431 | warn about these. */ | |
14432 | tree omp_out = build_decl (BUILTINS_LOCATION, VAR_DECL, | |
14433 | get_identifier ("omp_out"), type); | |
14434 | DECL_ARTIFICIAL (omp_out) = 1; | |
14435 | DECL_CONTEXT (omp_out) = fndecl; | |
14436 | pushdecl (omp_out); | |
14437 | tree omp_in = build_decl (BUILTINS_LOCATION, VAR_DECL, | |
14438 | get_identifier ("omp_in"), type); | |
14439 | DECL_ARTIFICIAL (omp_in) = 1; | |
14440 | DECL_CONTEXT (omp_in) = fndecl; | |
14441 | pushdecl (omp_in); | |
14442 | struct c_expr combiner = c_parser_expression (parser); | |
14443 | struct c_expr initializer; | |
14444 | tree omp_priv = NULL_TREE, omp_orig = NULL_TREE; | |
14445 | bool bad = false; | |
14446 | initializer.value = error_mark_node; | |
14447 | if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>")) | |
14448 | bad = true; | |
14449 | else if (c_parser_next_token_is (parser, CPP_NAME) | |
14450 | && strcmp (IDENTIFIER_POINTER | |
14451 | (c_parser_peek_token (parser)->value), | |
14452 | "initializer") == 0) | |
14453 | { | |
14454 | c_parser_consume_token (parser); | |
14455 | pop_scope (); | |
14456 | push_scope (); | |
14457 | omp_priv = build_decl (BUILTINS_LOCATION, VAR_DECL, | |
14458 | get_identifier ("omp_priv"), type); | |
14459 | DECL_ARTIFICIAL (omp_priv) = 1; | |
14460 | DECL_INITIAL (omp_priv) = error_mark_node; | |
14461 | DECL_CONTEXT (omp_priv) = fndecl; | |
14462 | pushdecl (omp_priv); | |
14463 | omp_orig = build_decl (BUILTINS_LOCATION, VAR_DECL, | |
14464 | get_identifier ("omp_orig"), type); | |
14465 | DECL_ARTIFICIAL (omp_orig) = 1; | |
14466 | DECL_CONTEXT (omp_orig) = fndecl; | |
14467 | pushdecl (omp_orig); | |
14468 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
14469 | bad = true; | |
14470 | else if (!c_parser_next_token_is (parser, CPP_NAME)) | |
14471 | { | |
14472 | c_parser_error (parser, "expected %<omp_priv%> or " | |
14473 | "function-name"); | |
14474 | bad = true; | |
14475 | } | |
14476 | else if (strcmp (IDENTIFIER_POINTER | |
14477 | (c_parser_peek_token (parser)->value), | |
14478 | "omp_priv") != 0) | |
14479 | { | |
14480 | if (c_parser_peek_2nd_token (parser)->type != CPP_OPEN_PAREN | |
14481 | || c_parser_peek_token (parser)->id_kind != C_ID_ID) | |
14482 | { | |
14483 | c_parser_error (parser, "expected function-name %<(%>"); | |
14484 | bad = true; | |
14485 | } | |
14486 | else | |
14487 | initializer = c_parser_postfix_expression (parser); | |
14488 | if (initializer.value | |
14489 | && TREE_CODE (initializer.value) == CALL_EXPR) | |
14490 | { | |
14491 | int j; | |
14492 | tree c = initializer.value; | |
14493 | for (j = 0; j < call_expr_nargs (c); j++) | |
14494 | if (TREE_CODE (CALL_EXPR_ARG (c, j)) == ADDR_EXPR | |
14495 | && TREE_OPERAND (CALL_EXPR_ARG (c, j), 0) == omp_priv) | |
14496 | break; | |
14497 | if (j == call_expr_nargs (c)) | |
14498 | error ("one of the initializer call arguments should be " | |
14499 | "%<&omp_priv%>"); | |
14500 | } | |
14501 | } | |
14502 | else | |
14503 | { | |
14504 | c_parser_consume_token (parser); | |
14505 | if (!c_parser_require (parser, CPP_EQ, "expected %<=%>")) | |
14506 | bad = true; | |
14507 | else | |
14508 | { | |
14509 | tree st = push_stmt_list (); | |
14510 | start_init (omp_priv, NULL_TREE, 0); | |
14511 | location_t loc = c_parser_peek_token (parser)->location; | |
14512 | struct c_expr init = c_parser_initializer (parser); | |
14513 | finish_init (); | |
14514 | finish_decl (omp_priv, loc, init.value, | |
14515 | init.original_type, NULL_TREE); | |
14516 | pop_stmt_list (st); | |
14517 | } | |
14518 | } | |
14519 | if (!bad | |
14520 | && !c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>")) | |
14521 | bad = true; | |
14522 | } | |
e60a6f7b | 14523 | |
bc7bff74 | 14524 | if (!bad) |
14525 | { | |
14526 | c_parser_skip_to_pragma_eol (parser); | |
fd6481cf | 14527 | |
bc7bff74 | 14528 | tree t = tree_cons (type, make_tree_vec (omp_priv ? 6 : 3), |
14529 | DECL_INITIAL (reduc_decl)); | |
14530 | DECL_INITIAL (reduc_decl) = t; | |
14531 | DECL_SOURCE_LOCATION (omp_out) = rloc; | |
14532 | TREE_VEC_ELT (TREE_VALUE (t), 0) = omp_out; | |
14533 | TREE_VEC_ELT (TREE_VALUE (t), 1) = omp_in; | |
14534 | TREE_VEC_ELT (TREE_VALUE (t), 2) = combiner.value; | |
14535 | walk_tree (&combiner.value, c_check_omp_declare_reduction_r, | |
14536 | &TREE_VEC_ELT (TREE_VALUE (t), 0), NULL); | |
14537 | if (omp_priv) | |
14538 | { | |
14539 | DECL_SOURCE_LOCATION (omp_priv) = rloc; | |
14540 | TREE_VEC_ELT (TREE_VALUE (t), 3) = omp_priv; | |
14541 | TREE_VEC_ELT (TREE_VALUE (t), 4) = omp_orig; | |
14542 | TREE_VEC_ELT (TREE_VALUE (t), 5) = initializer.value; | |
14543 | walk_tree (&initializer.value, c_check_omp_declare_reduction_r, | |
14544 | &TREE_VEC_ELT (TREE_VALUE (t), 3), NULL); | |
14545 | walk_tree (&DECL_INITIAL (omp_priv), | |
14546 | c_check_omp_declare_reduction_r, | |
14547 | &TREE_VEC_ELT (TREE_VALUE (t), 3), NULL); | |
14548 | } | |
14549 | } | |
fd6481cf | 14550 | |
bc7bff74 | 14551 | pop_stmt_list (stmt); |
14552 | pop_scope (); | |
14553 | if (cfun->language != NULL) | |
14554 | { | |
14555 | ggc_free (cfun->language); | |
14556 | cfun->language = NULL; | |
14557 | } | |
14558 | set_cfun (NULL); | |
14559 | current_function_decl = NULL_TREE; | |
14560 | if (nested) | |
14561 | c_pop_function_context (); | |
fd6481cf | 14562 | |
bc7bff74 | 14563 | if (!clauses.is_empty ()) |
14564 | { | |
14565 | parser->tokens = &parser->tokens_buf[0]; | |
14566 | parser->tokens_avail = tokens_avail; | |
14567 | } | |
14568 | if (bad) | |
14569 | goto fail; | |
14570 | if (errs != errorcount) | |
14571 | break; | |
14572 | } | |
fd6481cf | 14573 | |
bc7bff74 | 14574 | clauses.release (); |
14575 | types.release (); | |
fd6481cf | 14576 | } |
14577 | ||
1e8e9920 | 14578 | |
bc7bff74 | 14579 | /* OpenMP 4.0 |
14580 | #pragma omp declare simd declare-simd-clauses[optseq] new-line | |
14581 | #pragma omp declare reduction (reduction-id : typename-list : expression) \ | |
14582 | initializer-clause[opt] new-line | |
14583 | #pragma omp declare target new-line */ | |
2169f33b | 14584 | |
14585 | static void | |
bc7bff74 | 14586 | c_parser_omp_declare (c_parser *parser, enum pragma_context context) |
2169f33b | 14587 | { |
2169f33b | 14588 | c_parser_consume_pragma (parser); |
bc7bff74 | 14589 | if (c_parser_next_token_is (parser, CPP_NAME)) |
14590 | { | |
14591 | const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); | |
14592 | if (strcmp (p, "simd") == 0) | |
14593 | { | |
14594 | /* c_parser_consume_token (parser); done in | |
14595 | c_parser_omp_declare_simd. */ | |
14596 | c_parser_omp_declare_simd (parser, context); | |
14597 | return; | |
14598 | } | |
14599 | if (strcmp (p, "reduction") == 0) | |
14600 | { | |
14601 | c_parser_consume_token (parser); | |
14602 | c_parser_omp_declare_reduction (parser, context); | |
14603 | return; | |
14604 | } | |
c630ef93 | 14605 | if (!flag_openmp) /* flag_openmp_simd */ |
14606 | { | |
14607 | c_parser_skip_to_pragma_eol (parser); | |
14608 | return; | |
14609 | } | |
bc7bff74 | 14610 | if (strcmp (p, "target") == 0) |
14611 | { | |
14612 | c_parser_consume_token (parser); | |
14613 | c_parser_omp_declare_target (parser); | |
14614 | return; | |
14615 | } | |
14616 | } | |
2169f33b | 14617 | |
bc7bff74 | 14618 | c_parser_error (parser, "expected %<simd%> or %<reduction%> " |
14619 | "or %<target%>"); | |
14620 | c_parser_skip_to_pragma_eol (parser); | |
2169f33b | 14621 | } |
14622 | ||
1e8e9920 | 14623 | /* Main entry point to parsing most OpenMP pragmas. */ |
14624 | ||
14625 | static void | |
14626 | c_parser_omp_construct (c_parser *parser) | |
14627 | { | |
14628 | enum pragma_kind p_kind; | |
14629 | location_t loc; | |
14630 | tree stmt; | |
bc7bff74 | 14631 | char p_name[sizeof "#pragma omp teams distribute parallel for simd"]; |
14632 | omp_clause_mask mask (0); | |
1e8e9920 | 14633 | |
14634 | loc = c_parser_peek_token (parser)->location; | |
14635 | p_kind = c_parser_peek_token (parser)->pragma_kind; | |
14636 | c_parser_consume_pragma (parser); | |
14637 | ||
14638 | switch (p_kind) | |
14639 | { | |
ca4c3545 | 14640 | case PRAGMA_OACC_CACHE: |
14641 | strcpy (p_name, "#pragma acc"); | |
14642 | stmt = c_parser_oacc_cache (loc, parser); | |
14643 | break; | |
14644 | case PRAGMA_OACC_DATA: | |
14645 | stmt = c_parser_oacc_data (loc, parser); | |
14646 | break; | |
14647 | case PRAGMA_OACC_KERNELS: | |
14648 | strcpy (p_name, "#pragma acc"); | |
14649 | stmt = c_parser_oacc_kernels (loc, parser, p_name); | |
14650 | break; | |
14651 | case PRAGMA_OACC_LOOP: | |
14652 | strcpy (p_name, "#pragma acc"); | |
14653 | stmt = c_parser_oacc_loop (loc, parser, p_name); | |
14654 | break; | |
14655 | case PRAGMA_OACC_PARALLEL: | |
14656 | strcpy (p_name, "#pragma acc"); | |
14657 | stmt = c_parser_oacc_parallel (loc, parser, p_name); | |
14658 | break; | |
14659 | case PRAGMA_OACC_WAIT: | |
14660 | strcpy (p_name, "#pragma wait"); | |
14661 | stmt = c_parser_oacc_wait (loc, parser, p_name); | |
14662 | break; | |
1e8e9920 | 14663 | case PRAGMA_OMP_ATOMIC: |
e60a6f7b | 14664 | c_parser_omp_atomic (loc, parser); |
1e8e9920 | 14665 | return; |
14666 | case PRAGMA_OMP_CRITICAL: | |
e60a6f7b | 14667 | stmt = c_parser_omp_critical (loc, parser); |
1e8e9920 | 14668 | break; |
bc7bff74 | 14669 | case PRAGMA_OMP_DISTRIBUTE: |
14670 | strcpy (p_name, "#pragma omp"); | |
14671 | stmt = c_parser_omp_distribute (loc, parser, p_name, mask, NULL); | |
14672 | break; | |
1e8e9920 | 14673 | case PRAGMA_OMP_FOR: |
bc7bff74 | 14674 | strcpy (p_name, "#pragma omp"); |
14675 | stmt = c_parser_omp_for (loc, parser, p_name, mask, NULL); | |
1e8e9920 | 14676 | break; |
14677 | case PRAGMA_OMP_MASTER: | |
e60a6f7b | 14678 | stmt = c_parser_omp_master (loc, parser); |
1e8e9920 | 14679 | break; |
14680 | case PRAGMA_OMP_ORDERED: | |
e60a6f7b | 14681 | stmt = c_parser_omp_ordered (loc, parser); |
1e8e9920 | 14682 | break; |
14683 | case PRAGMA_OMP_PARALLEL: | |
bc7bff74 | 14684 | strcpy (p_name, "#pragma omp"); |
14685 | stmt = c_parser_omp_parallel (loc, parser, p_name, mask, NULL); | |
1e8e9920 | 14686 | break; |
14687 | case PRAGMA_OMP_SECTIONS: | |
bc7bff74 | 14688 | strcpy (p_name, "#pragma omp"); |
14689 | stmt = c_parser_omp_sections (loc, parser, p_name, mask, NULL); | |
14690 | break; | |
14691 | case PRAGMA_OMP_SIMD: | |
14692 | strcpy (p_name, "#pragma omp"); | |
14693 | stmt = c_parser_omp_simd (loc, parser, p_name, mask, NULL); | |
1e8e9920 | 14694 | break; |
14695 | case PRAGMA_OMP_SINGLE: | |
e60a6f7b | 14696 | stmt = c_parser_omp_single (loc, parser); |
1e8e9920 | 14697 | break; |
fd6481cf | 14698 | case PRAGMA_OMP_TASK: |
e60a6f7b | 14699 | stmt = c_parser_omp_task (loc, parser); |
fd6481cf | 14700 | break; |
bc7bff74 | 14701 | case PRAGMA_OMP_TASKGROUP: |
14702 | stmt = c_parser_omp_taskgroup (parser); | |
14703 | break; | |
14704 | case PRAGMA_OMP_TEAMS: | |
14705 | strcpy (p_name, "#pragma omp"); | |
14706 | stmt = c_parser_omp_teams (loc, parser, p_name, mask, NULL); | |
14707 | break; | |
1e8e9920 | 14708 | default: |
14709 | gcc_unreachable (); | |
14710 | } | |
14711 | ||
14712 | if (stmt) | |
e60a6f7b | 14713 | gcc_assert (EXPR_LOCATION (stmt) != UNKNOWN_LOCATION); |
1e8e9920 | 14714 | } |
14715 | ||
14716 | ||
14717 | /* OpenMP 2.5: | |
14718 | # pragma omp threadprivate (variable-list) */ | |
14719 | ||
14720 | static void | |
14721 | c_parser_omp_threadprivate (c_parser *parser) | |
14722 | { | |
14723 | tree vars, t; | |
e60a6f7b | 14724 | location_t loc; |
1e8e9920 | 14725 | |
14726 | c_parser_consume_pragma (parser); | |
e60a6f7b | 14727 | loc = c_parser_peek_token (parser)->location; |
7d339f93 | 14728 | vars = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL); |
1e8e9920 | 14729 | |
1e8e9920 | 14730 | /* Mark every variable in VARS to be assigned thread local storage. */ |
14731 | for (t = vars; t; t = TREE_CHAIN (t)) | |
14732 | { | |
14733 | tree v = TREE_PURPOSE (t); | |
14734 | ||
e60a6f7b | 14735 | /* FIXME diagnostics: Ideally we should keep individual |
14736 | locations for all the variables in the var list to make the | |
14737 | following errors more precise. Perhaps | |
14738 | c_parser_omp_var_list_parens() should construct a list of | |
14739 | locations to go along with the var list. */ | |
14740 | ||
1e8e9920 | 14741 | /* If V had already been marked threadprivate, it doesn't matter |
14742 | whether it had been used prior to this point. */ | |
50389d5d | 14743 | if (TREE_CODE (v) != VAR_DECL) |
e60a6f7b | 14744 | error_at (loc, "%qD is not a variable", v); |
50389d5d | 14745 | else if (TREE_USED (v) && !C_DECL_THREADPRIVATE_P (v)) |
e60a6f7b | 14746 | error_at (loc, "%qE declared %<threadprivate%> after first use", v); |
1e8e9920 | 14747 | else if (! TREE_STATIC (v) && ! DECL_EXTERNAL (v)) |
e60a6f7b | 14748 | error_at (loc, "automatic variable %qE cannot be %<threadprivate%>", v); |
50389d5d | 14749 | else if (TREE_TYPE (v) == error_mark_node) |
14750 | ; | |
1e8e9920 | 14751 | else if (! COMPLETE_TYPE_P (TREE_TYPE (v))) |
e60a6f7b | 14752 | error_at (loc, "%<threadprivate%> %qE has incomplete type", v); |
1e8e9920 | 14753 | else |
14754 | { | |
14755 | if (! DECL_THREAD_LOCAL_P (v)) | |
14756 | { | |
5e68df57 | 14757 | set_decl_tls_model (v, decl_default_tls_model (v)); |
1e8e9920 | 14758 | /* If rtl has been already set for this var, call |
14759 | make_decl_rtl once again, so that encode_section_info | |
14760 | has a chance to look at the new decl flags. */ | |
14761 | if (DECL_RTL_SET_P (v)) | |
14762 | make_decl_rtl (v); | |
14763 | } | |
14764 | C_DECL_THREADPRIVATE_P (v) = 1; | |
14765 | } | |
14766 | } | |
14767 | ||
14768 | c_parser_skip_to_pragma_eol (parser); | |
14769 | } | |
f2697631 | 14770 | \f |
14771 | /* Cilk Plus <#pragma simd> parsing routines. */ | |
14772 | ||
14773 | /* Helper function for c_parser_pragma. Perform some sanity checking | |
14774 | for <#pragma simd> constructs. Returns FALSE if there was a | |
14775 | problem. */ | |
14776 | ||
14777 | static bool | |
14778 | c_parser_cilk_verify_simd (c_parser *parser, | |
14779 | enum pragma_context context) | |
14780 | { | |
a89e6c15 | 14781 | if (!flag_cilkplus) |
f2697631 | 14782 | { |
14783 | warning (0, "pragma simd ignored because -fcilkplus is not enabled"); | |
14784 | c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL); | |
14785 | return false; | |
14786 | } | |
14787 | if (context == pragma_external) | |
14788 | { | |
14789 | c_parser_error (parser,"pragma simd must be inside a function"); | |
14790 | c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL); | |
14791 | return false; | |
14792 | } | |
14793 | return true; | |
14794 | } | |
14795 | ||
14796 | /* Cilk Plus: | |
74acc703 | 14797 | This function is shared by SIMD-enabled functions and #pragma simd. |
14798 | If IS_SIMD_FN is true then it is parsing a SIMD-enabled function and | |
14799 | CLAUSES is unused. The main purpose of this function is to parse a | |
14800 | vectorlength attribute or clause and check for parse errors. | |
14801 | When IS_SIMD_FN is true then the function is merely caching the tokens | |
14802 | in PARSER->CILK_SIMD_FN_TOKENS. If errors are found then the token | |
14803 | cache is cleared since there is no reason to continue. | |
14804 | Syntax: | |
14805 | vectorlength ( constant-expression ) */ | |
f2697631 | 14806 | |
14807 | static tree | |
74acc703 | 14808 | c_parser_cilk_clause_vectorlength (c_parser *parser, tree clauses, |
14809 | bool is_simd_fn) | |
f2697631 | 14810 | { |
74acc703 | 14811 | if (is_simd_fn) |
14812 | check_no_duplicate_clause (clauses, OMP_CLAUSE_SIMDLEN, "vectorlength"); | |
14813 | else | |
f2697631 | 14814 | /* The vectorlength clause behaves exactly like OpenMP's safelen |
14815 | clause. Represent it in OpenMP terms. */ | |
74acc703 | 14816 | check_no_duplicate_clause (clauses, OMP_CLAUSE_SAFELEN, "vectorlength"); |
f2697631 | 14817 | |
14818 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
14819 | return clauses; | |
14820 | ||
14821 | location_t loc = c_parser_peek_token (parser)->location; | |
14822 | tree expr = c_parser_expr_no_commas (parser, NULL).value; | |
14823 | expr = c_fully_fold (expr, false, NULL); | |
14824 | ||
74acc703 | 14825 | /* If expr is an error_mark_node then the above function would have |
14826 | emitted an error. No reason to do it twice. */ | |
14827 | if (expr == error_mark_node) | |
14828 | ; | |
14829 | else if (!TREE_TYPE (expr) | |
14830 | || !TREE_CONSTANT (expr) | |
14831 | || !INTEGRAL_TYPE_P (TREE_TYPE (expr))) | |
14832 | ||
14833 | error_at (loc, "vectorlength must be an integer constant"); | |
cc69d08a | 14834 | else if (wi::exact_log2 (expr) == -1) |
f2697631 | 14835 | error_at (loc, "vectorlength must be a power of 2"); |
14836 | else | |
14837 | { | |
74acc703 | 14838 | if (is_simd_fn) |
14839 | { | |
14840 | tree u = build_omp_clause (loc, OMP_CLAUSE_SIMDLEN); | |
14841 | OMP_CLAUSE_SIMDLEN_EXPR (u) = expr; | |
14842 | OMP_CLAUSE_CHAIN (u) = clauses; | |
14843 | clauses = u; | |
14844 | } | |
14845 | else | |
14846 | { | |
14847 | tree u = build_omp_clause (loc, OMP_CLAUSE_SAFELEN); | |
14848 | OMP_CLAUSE_SAFELEN_EXPR (u) = expr; | |
14849 | OMP_CLAUSE_CHAIN (u) = clauses; | |
14850 | clauses = u; | |
14851 | } | |
f2697631 | 14852 | } |
14853 | ||
14854 | c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
14855 | ||
14856 | return clauses; | |
14857 | } | |
14858 | ||
14859 | /* Cilk Plus: | |
14860 | linear ( simd-linear-variable-list ) | |
14861 | ||
14862 | simd-linear-variable-list: | |
14863 | simd-linear-variable | |
14864 | simd-linear-variable-list , simd-linear-variable | |
14865 | ||
14866 | simd-linear-variable: | |
14867 | id-expression | |
14868 | id-expression : simd-linear-step | |
14869 | ||
14870 | simd-linear-step: | |
14871 | conditional-expression */ | |
14872 | ||
14873 | static tree | |
14874 | c_parser_cilk_clause_linear (c_parser *parser, tree clauses) | |
14875 | { | |
14876 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
14877 | return clauses; | |
14878 | ||
14879 | location_t loc = c_parser_peek_token (parser)->location; | |
14880 | ||
14881 | if (c_parser_next_token_is_not (parser, CPP_NAME) | |
14882 | || c_parser_peek_token (parser)->id_kind != C_ID_ID) | |
14883 | c_parser_error (parser, "expected identifier"); | |
14884 | ||
14885 | while (c_parser_next_token_is (parser, CPP_NAME) | |
14886 | && c_parser_peek_token (parser)->id_kind == C_ID_ID) | |
14887 | { | |
14888 | tree var = lookup_name (c_parser_peek_token (parser)->value); | |
14889 | ||
14890 | if (var == NULL) | |
14891 | { | |
14892 | undeclared_variable (c_parser_peek_token (parser)->location, | |
14893 | c_parser_peek_token (parser)->value); | |
14894 | c_parser_consume_token (parser); | |
14895 | } | |
14896 | else if (var == error_mark_node) | |
14897 | c_parser_consume_token (parser); | |
14898 | else | |
14899 | { | |
14900 | tree step = integer_one_node; | |
14901 | ||
14902 | /* Parse the linear step if present. */ | |
14903 | if (c_parser_peek_2nd_token (parser)->type == CPP_COLON) | |
14904 | { | |
14905 | c_parser_consume_token (parser); | |
14906 | c_parser_consume_token (parser); | |
14907 | ||
14908 | tree expr = c_parser_expr_no_commas (parser, NULL).value; | |
14909 | expr = c_fully_fold (expr, false, NULL); | |
14910 | ||
14911 | if (TREE_TYPE (expr) | |
14912 | && INTEGRAL_TYPE_P (TREE_TYPE (expr)) | |
14913 | && (TREE_CONSTANT (expr) | |
14914 | || DECL_P (expr))) | |
14915 | step = expr; | |
14916 | else | |
14917 | c_parser_error (parser, | |
14918 | "step size must be an integer constant " | |
14919 | "expression or an integer variable"); | |
14920 | } | |
14921 | else | |
14922 | c_parser_consume_token (parser); | |
14923 | ||
14924 | /* Use OMP_CLAUSE_LINEAR, which has the same semantics. */ | |
14925 | tree u = build_omp_clause (loc, OMP_CLAUSE_LINEAR); | |
14926 | OMP_CLAUSE_DECL (u) = var; | |
14927 | OMP_CLAUSE_LINEAR_STEP (u) = step; | |
14928 | OMP_CLAUSE_CHAIN (u) = clauses; | |
14929 | clauses = u; | |
14930 | } | |
14931 | ||
14932 | if (c_parser_next_token_is_not (parser, CPP_COMMA)) | |
14933 | break; | |
14934 | ||
14935 | c_parser_consume_token (parser); | |
14936 | } | |
14937 | ||
14938 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
14939 | ||
14940 | return clauses; | |
14941 | } | |
14942 | ||
14943 | /* Returns the name of the next clause. If the clause is not | |
14944 | recognized SIMD_OMP_CLAUSE_NONE is returned and the next token is | |
14945 | not consumed. Otherwise, the appropriate pragma_simd_clause is | |
14946 | returned and the token is consumed. */ | |
14947 | ||
74acc703 | 14948 | static pragma_omp_clause |
f2697631 | 14949 | c_parser_cilk_clause_name (c_parser *parser) |
14950 | { | |
74acc703 | 14951 | pragma_omp_clause result; |
f2697631 | 14952 | c_token *token = c_parser_peek_token (parser); |
14953 | ||
14954 | if (!token->value || token->type != CPP_NAME) | |
14955 | return PRAGMA_CILK_CLAUSE_NONE; | |
14956 | ||
14957 | const char *p = IDENTIFIER_POINTER (token->value); | |
14958 | ||
14959 | if (!strcmp (p, "vectorlength")) | |
14960 | result = PRAGMA_CILK_CLAUSE_VECTORLENGTH; | |
14961 | else if (!strcmp (p, "linear")) | |
14962 | result = PRAGMA_CILK_CLAUSE_LINEAR; | |
14963 | else if (!strcmp (p, "private")) | |
14964 | result = PRAGMA_CILK_CLAUSE_PRIVATE; | |
14965 | else if (!strcmp (p, "firstprivate")) | |
14966 | result = PRAGMA_CILK_CLAUSE_FIRSTPRIVATE; | |
14967 | else if (!strcmp (p, "lastprivate")) | |
14968 | result = PRAGMA_CILK_CLAUSE_LASTPRIVATE; | |
14969 | else if (!strcmp (p, "reduction")) | |
14970 | result = PRAGMA_CILK_CLAUSE_REDUCTION; | |
14971 | else | |
14972 | return PRAGMA_CILK_CLAUSE_NONE; | |
14973 | ||
14974 | c_parser_consume_token (parser); | |
14975 | return result; | |
14976 | } | |
14977 | ||
14978 | /* Parse all #<pragma simd> clauses. Return the list of clauses | |
14979 | found. */ | |
14980 | ||
14981 | static tree | |
14982 | c_parser_cilk_all_clauses (c_parser *parser) | |
14983 | { | |
14984 | tree clauses = NULL; | |
14985 | ||
14986 | while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL)) | |
14987 | { | |
74acc703 | 14988 | pragma_omp_clause c_kind; |
f2697631 | 14989 | |
14990 | c_kind = c_parser_cilk_clause_name (parser); | |
14991 | ||
14992 | switch (c_kind) | |
14993 | { | |
14994 | case PRAGMA_CILK_CLAUSE_VECTORLENGTH: | |
74acc703 | 14995 | clauses = c_parser_cilk_clause_vectorlength (parser, clauses, false); |
f2697631 | 14996 | break; |
14997 | case PRAGMA_CILK_CLAUSE_LINEAR: | |
14998 | clauses = c_parser_cilk_clause_linear (parser, clauses); | |
14999 | break; | |
15000 | case PRAGMA_CILK_CLAUSE_PRIVATE: | |
15001 | /* Use the OpenMP counterpart. */ | |
15002 | clauses = c_parser_omp_clause_private (parser, clauses); | |
15003 | break; | |
15004 | case PRAGMA_CILK_CLAUSE_FIRSTPRIVATE: | |
15005 | /* Use the OpenMP counterpart. */ | |
15006 | clauses = c_parser_omp_clause_firstprivate (parser, clauses); | |
15007 | break; | |
15008 | case PRAGMA_CILK_CLAUSE_LASTPRIVATE: | |
15009 | /* Use the OpenMP counterpart. */ | |
15010 | clauses = c_parser_omp_clause_lastprivate (parser, clauses); | |
15011 | break; | |
15012 | case PRAGMA_CILK_CLAUSE_REDUCTION: | |
15013 | /* Use the OpenMP counterpart. */ | |
15014 | clauses = c_parser_omp_clause_reduction (parser, clauses); | |
15015 | break; | |
15016 | default: | |
15017 | c_parser_error (parser, "expected %<#pragma simd%> clause"); | |
15018 | goto saw_error; | |
15019 | } | |
15020 | } | |
15021 | ||
15022 | saw_error: | |
15023 | c_parser_skip_to_pragma_eol (parser); | |
15024 | return c_finish_cilk_clauses (clauses); | |
15025 | } | |
15026 | ||
40750995 | 15027 | /* This function helps parse the grainsize pragma for a _Cilk_for statement. |
15028 | Here is the correct syntax of this pragma: | |
15029 | #pragma cilk grainsize = <EXP> | |
15030 | */ | |
15031 | ||
15032 | static void | |
15033 | c_parser_cilk_grainsize (c_parser *parser) | |
15034 | { | |
15035 | extern tree convert_to_integer (tree, tree); | |
15036 | ||
15037 | /* consume the 'grainsize' keyword. */ | |
15038 | c_parser_consume_pragma (parser); | |
15039 | ||
15040 | if (c_parser_require (parser, CPP_EQ, "expected %<=%>") != 0) | |
15041 | { | |
15042 | struct c_expr g_expr = c_parser_binary_expression (parser, NULL, NULL); | |
15043 | if (g_expr.value == error_mark_node) | |
15044 | { | |
15045 | c_parser_skip_to_pragma_eol (parser); | |
15046 | return; | |
15047 | } | |
15048 | tree grain = convert_to_integer (long_integer_type_node, | |
15049 | c_fully_fold (g_expr.value, false, | |
15050 | NULL)); | |
15051 | c_parser_skip_to_pragma_eol (parser); | |
15052 | c_token *token = c_parser_peek_token (parser); | |
15053 | if (token && token->type == CPP_KEYWORD | |
15054 | && token->keyword == RID_CILK_FOR) | |
15055 | { | |
15056 | if (grain == NULL_TREE || grain == error_mark_node) | |
15057 | grain = integer_zero_node; | |
15058 | c_parser_cilk_for (parser, grain); | |
15059 | } | |
15060 | else | |
15061 | warning (0, "%<#pragma cilk grainsize%> is not followed by " | |
15062 | "%<_Cilk_for%>"); | |
15063 | } | |
15064 | else | |
15065 | c_parser_skip_to_pragma_eol (parser); | |
15066 | } | |
15067 | ||
15068 | /* Main entry point for parsing Cilk Plus <#pragma simd> for loops. */ | |
1e8e9920 | 15069 | |
f2697631 | 15070 | static void |
dc133326 | 15071 | c_parser_cilk_simd (c_parser *parser) |
f2697631 | 15072 | { |
f2697631 | 15073 | tree clauses = c_parser_cilk_all_clauses (parser); |
15074 | tree block = c_begin_compound_stmt (true); | |
15075 | location_t loc = c_parser_peek_token (parser)->location; | |
15076 | c_parser_omp_for_loop (loc, parser, CILK_SIMD, clauses, NULL); | |
15077 | block = c_end_compound_stmt (loc, block, true); | |
15078 | add_stmt (block); | |
15079 | } | |
40750995 | 15080 | |
15081 | /* Create an artificial decl with TYPE and emit initialization of it with | |
15082 | INIT. */ | |
15083 | ||
15084 | static tree | |
15085 | c_get_temp_regvar (tree type, tree init) | |
15086 | { | |
15087 | location_t loc = EXPR_LOCATION (init); | |
15088 | tree decl = build_decl (loc, VAR_DECL, NULL_TREE, type); | |
15089 | DECL_ARTIFICIAL (decl) = 1; | |
15090 | DECL_IGNORED_P (decl) = 1; | |
15091 | pushdecl (decl); | |
15092 | tree t = build2 (INIT_EXPR, type, decl, init); | |
15093 | add_stmt (t); | |
15094 | return decl; | |
15095 | } | |
15096 | ||
15097 | /* Main entry point for parsing Cilk Plus _Cilk_for loops. | |
15098 | GRAIN is the grain value passed in through pragma or 0. */ | |
15099 | ||
15100 | static void | |
15101 | c_parser_cilk_for (c_parser *parser, tree grain) | |
15102 | { | |
15103 | tree clauses = build_omp_clause (EXPR_LOCATION (grain), OMP_CLAUSE_SCHEDULE); | |
15104 | OMP_CLAUSE_SCHEDULE_KIND (clauses) = OMP_CLAUSE_SCHEDULE_CILKFOR; | |
15105 | OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (clauses) = grain; | |
15106 | clauses = c_finish_omp_clauses (clauses); | |
15107 | ||
15108 | tree block = c_begin_compound_stmt (true); | |
15109 | tree sb = push_stmt_list (); | |
15110 | location_t loc = c_parser_peek_token (parser)->location; | |
15111 | tree omp_for = c_parser_omp_for_loop (loc, parser, CILK_FOR, clauses, NULL); | |
15112 | sb = pop_stmt_list (sb); | |
15113 | ||
15114 | if (omp_for) | |
15115 | { | |
15116 | tree omp_par = make_node (OMP_PARALLEL); | |
15117 | TREE_TYPE (omp_par) = void_type_node; | |
15118 | OMP_PARALLEL_CLAUSES (omp_par) = NULL_TREE; | |
15119 | tree bind = build3 (BIND_EXPR, void_type_node, NULL, NULL, NULL); | |
15120 | TREE_SIDE_EFFECTS (bind) = 1; | |
15121 | BIND_EXPR_BODY (bind) = sb; | |
15122 | OMP_PARALLEL_BODY (omp_par) = bind; | |
15123 | if (OMP_FOR_PRE_BODY (omp_for)) | |
15124 | { | |
15125 | add_stmt (OMP_FOR_PRE_BODY (omp_for)); | |
15126 | OMP_FOR_PRE_BODY (omp_for) = NULL_TREE; | |
15127 | } | |
15128 | tree init = TREE_VEC_ELT (OMP_FOR_INIT (omp_for), 0); | |
15129 | tree decl = TREE_OPERAND (init, 0); | |
15130 | tree cond = TREE_VEC_ELT (OMP_FOR_COND (omp_for), 0); | |
15131 | tree incr = TREE_VEC_ELT (OMP_FOR_INCR (omp_for), 0); | |
15132 | tree t = TREE_OPERAND (cond, 1), c, clauses = NULL_TREE; | |
15133 | if (TREE_CODE (t) != INTEGER_CST) | |
15134 | { | |
15135 | TREE_OPERAND (cond, 1) = c_get_temp_regvar (TREE_TYPE (t), t); | |
15136 | c = build_omp_clause (input_location, OMP_CLAUSE_FIRSTPRIVATE); | |
15137 | OMP_CLAUSE_DECL (c) = TREE_OPERAND (cond, 1); | |
15138 | OMP_CLAUSE_CHAIN (c) = clauses; | |
15139 | clauses = c; | |
15140 | } | |
15141 | if (TREE_CODE (incr) == MODIFY_EXPR) | |
15142 | { | |
15143 | t = TREE_OPERAND (TREE_OPERAND (incr, 1), 1); | |
15144 | if (TREE_CODE (t) != INTEGER_CST) | |
15145 | { | |
15146 | TREE_OPERAND (TREE_OPERAND (incr, 1), 1) | |
15147 | = c_get_temp_regvar (TREE_TYPE (t), t); | |
15148 | c = build_omp_clause (input_location, OMP_CLAUSE_FIRSTPRIVATE); | |
15149 | OMP_CLAUSE_DECL (c) = TREE_OPERAND (TREE_OPERAND (incr, 1), 1); | |
15150 | OMP_CLAUSE_CHAIN (c) = clauses; | |
15151 | clauses = c; | |
15152 | } | |
15153 | } | |
15154 | t = TREE_OPERAND (init, 1); | |
15155 | if (TREE_CODE (t) != INTEGER_CST) | |
15156 | { | |
15157 | TREE_OPERAND (init, 1) = c_get_temp_regvar (TREE_TYPE (t), t); | |
15158 | c = build_omp_clause (input_location, OMP_CLAUSE_FIRSTPRIVATE); | |
15159 | OMP_CLAUSE_DECL (c) = TREE_OPERAND (init, 1); | |
15160 | OMP_CLAUSE_CHAIN (c) = clauses; | |
15161 | clauses = c; | |
15162 | } | |
15163 | c = build_omp_clause (input_location, OMP_CLAUSE_PRIVATE); | |
15164 | OMP_CLAUSE_DECL (c) = decl; | |
15165 | OMP_CLAUSE_CHAIN (c) = clauses; | |
15166 | clauses = c; | |
15167 | c = build_omp_clause (input_location, OMP_CLAUSE__CILK_FOR_COUNT_); | |
15168 | OMP_CLAUSE_OPERAND (c, 0) | |
15169 | = cilk_for_number_of_iterations (omp_for); | |
15170 | OMP_CLAUSE_CHAIN (c) = clauses; | |
15171 | OMP_PARALLEL_CLAUSES (omp_par) = c_finish_omp_clauses (c); | |
15172 | add_stmt (omp_par); | |
15173 | } | |
15174 | ||
15175 | block = c_end_compound_stmt (loc, block, true); | |
15176 | add_stmt (block); | |
15177 | } | |
15178 | ||
f2697631 | 15179 | \f |
4c0315d0 | 15180 | /* Parse a transaction attribute (GCC Extension). |
15181 | ||
15182 | transaction-attribute: | |
15183 | attributes | |
15184 | [ [ any-word ] ] | |
15185 | ||
15186 | The transactional memory language description is written for C++, | |
15187 | and uses the C++0x attribute syntax. For compatibility, allow the | |
15188 | bracket style for transactions in C as well. */ | |
15189 | ||
15190 | static tree | |
15191 | c_parser_transaction_attributes (c_parser *parser) | |
15192 | { | |
15193 | tree attr_name, attr = NULL; | |
15194 | ||
15195 | if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)) | |
15196 | return c_parser_attributes (parser); | |
15197 | ||
15198 | if (!c_parser_next_token_is (parser, CPP_OPEN_SQUARE)) | |
15199 | return NULL_TREE; | |
15200 | c_parser_consume_token (parser); | |
15201 | if (!c_parser_require (parser, CPP_OPEN_SQUARE, "expected %<[%>")) | |
15202 | goto error1; | |
15203 | ||
15204 | attr_name = c_parser_attribute_any_word (parser); | |
15205 | if (attr_name) | |
15206 | { | |
15207 | c_parser_consume_token (parser); | |
15208 | attr = build_tree_list (attr_name, NULL_TREE); | |
15209 | } | |
15210 | else | |
15211 | c_parser_error (parser, "expected identifier"); | |
15212 | ||
15213 | c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, "expected %<]%>"); | |
15214 | error1: | |
15215 | c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, "expected %<]%>"); | |
15216 | return attr; | |
15217 | } | |
15218 | ||
15219 | /* Parse a __transaction_atomic or __transaction_relaxed statement | |
15220 | (GCC Extension). | |
15221 | ||
15222 | transaction-statement: | |
15223 | __transaction_atomic transaction-attribute[opt] compound-statement | |
15224 | __transaction_relaxed compound-statement | |
15225 | ||
15226 | Note that the only valid attribute is: "outer". | |
15227 | */ | |
15228 | ||
15229 | static tree | |
15230 | c_parser_transaction (c_parser *parser, enum rid keyword) | |
15231 | { | |
15232 | unsigned int old_in = parser->in_transaction; | |
15233 | unsigned int this_in = 1, new_in; | |
15234 | location_t loc = c_parser_peek_token (parser)->location; | |
15235 | tree stmt, attrs; | |
15236 | ||
15237 | gcc_assert ((keyword == RID_TRANSACTION_ATOMIC | |
15238 | || keyword == RID_TRANSACTION_RELAXED) | |
15239 | && c_parser_next_token_is_keyword (parser, keyword)); | |
15240 | c_parser_consume_token (parser); | |
15241 | ||
15242 | if (keyword == RID_TRANSACTION_RELAXED) | |
15243 | this_in |= TM_STMT_ATTR_RELAXED; | |
15244 | else | |
15245 | { | |
15246 | attrs = c_parser_transaction_attributes (parser); | |
15247 | if (attrs) | |
15248 | this_in |= parse_tm_stmt_attr (attrs, TM_STMT_ATTR_OUTER); | |
15249 | } | |
15250 | ||
15251 | /* Keep track if we're in the lexical scope of an outer transaction. */ | |
15252 | new_in = this_in | (old_in & TM_STMT_ATTR_OUTER); | |
15253 | ||
15254 | parser->in_transaction = new_in; | |
15255 | stmt = c_parser_compound_statement (parser); | |
15256 | parser->in_transaction = old_in; | |
15257 | ||
15258 | if (flag_tm) | |
15259 | stmt = c_finish_transaction (loc, stmt, this_in); | |
15260 | else | |
15261 | error_at (loc, (keyword == RID_TRANSACTION_ATOMIC ? | |
15262 | "%<__transaction_atomic%> without transactional memory support enabled" | |
15263 | : "%<__transaction_relaxed %> " | |
15264 | "without transactional memory support enabled")); | |
15265 | ||
15266 | return stmt; | |
15267 | } | |
15268 | ||
15269 | /* Parse a __transaction_atomic or __transaction_relaxed expression | |
15270 | (GCC Extension). | |
15271 | ||
15272 | transaction-expression: | |
15273 | __transaction_atomic ( expression ) | |
15274 | __transaction_relaxed ( expression ) | |
15275 | */ | |
15276 | ||
15277 | static struct c_expr | |
15278 | c_parser_transaction_expression (c_parser *parser, enum rid keyword) | |
15279 | { | |
15280 | struct c_expr ret; | |
15281 | unsigned int old_in = parser->in_transaction; | |
15282 | unsigned int this_in = 1; | |
15283 | location_t loc = c_parser_peek_token (parser)->location; | |
15284 | tree attrs; | |
15285 | ||
15286 | gcc_assert ((keyword == RID_TRANSACTION_ATOMIC | |
15287 | || keyword == RID_TRANSACTION_RELAXED) | |
15288 | && c_parser_next_token_is_keyword (parser, keyword)); | |
15289 | c_parser_consume_token (parser); | |
15290 | ||
15291 | if (keyword == RID_TRANSACTION_RELAXED) | |
15292 | this_in |= TM_STMT_ATTR_RELAXED; | |
15293 | else | |
15294 | { | |
15295 | attrs = c_parser_transaction_attributes (parser); | |
15296 | if (attrs) | |
15297 | this_in |= parse_tm_stmt_attr (attrs, 0); | |
15298 | } | |
15299 | ||
15300 | parser->in_transaction = this_in; | |
bdd07b44 | 15301 | if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) |
4c0315d0 | 15302 | { |
15303 | tree expr = c_parser_expression (parser).value; | |
15304 | ret.original_type = TREE_TYPE (expr); | |
15305 | ret.value = build1 (TRANSACTION_EXPR, ret.original_type, expr); | |
15306 | if (this_in & TM_STMT_ATTR_RELAXED) | |
15307 | TRANSACTION_EXPR_RELAXED (ret.value) = 1; | |
15308 | SET_EXPR_LOCATION (ret.value, loc); | |
15309 | ret.original_code = TRANSACTION_EXPR; | |
bdd07b44 | 15310 | if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>")) |
15311 | { | |
15312 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); | |
15313 | goto error; | |
15314 | } | |
4c0315d0 | 15315 | } |
15316 | else | |
15317 | { | |
bdd07b44 | 15318 | error: |
4c0315d0 | 15319 | ret.value = error_mark_node; |
15320 | ret.original_code = ERROR_MARK; | |
15321 | ret.original_type = NULL; | |
15322 | } | |
15323 | parser->in_transaction = old_in; | |
15324 | ||
15325 | if (!flag_tm) | |
15326 | error_at (loc, (keyword == RID_TRANSACTION_ATOMIC ? | |
15327 | "%<__transaction_atomic%> without transactional memory support enabled" | |
15328 | : "%<__transaction_relaxed %> " | |
15329 | "without transactional memory support enabled")); | |
15330 | ||
15331 | return ret; | |
15332 | } | |
15333 | ||
15334 | /* Parse a __transaction_cancel statement (GCC Extension). | |
15335 | ||
15336 | transaction-cancel-statement: | |
15337 | __transaction_cancel transaction-attribute[opt] ; | |
15338 | ||
15339 | Note that the only valid attribute is "outer". | |
15340 | */ | |
15341 | ||
15342 | static tree | |
bc7bff74 | 15343 | c_parser_transaction_cancel (c_parser *parser) |
4c0315d0 | 15344 | { |
15345 | location_t loc = c_parser_peek_token (parser)->location; | |
15346 | tree attrs; | |
15347 | bool is_outer = false; | |
15348 | ||
15349 | gcc_assert (c_parser_next_token_is_keyword (parser, RID_TRANSACTION_CANCEL)); | |
15350 | c_parser_consume_token (parser); | |
15351 | ||
15352 | attrs = c_parser_transaction_attributes (parser); | |
15353 | if (attrs) | |
15354 | is_outer = (parse_tm_stmt_attr (attrs, TM_STMT_ATTR_OUTER) != 0); | |
15355 | ||
15356 | if (!flag_tm) | |
15357 | { | |
15358 | error_at (loc, "%<__transaction_cancel%> without " | |
15359 | "transactional memory support enabled"); | |
15360 | goto ret_error; | |
15361 | } | |
15362 | else if (parser->in_transaction & TM_STMT_ATTR_RELAXED) | |
15363 | { | |
15364 | error_at (loc, "%<__transaction_cancel%> within a " | |
15365 | "%<__transaction_relaxed%>"); | |
15366 | goto ret_error; | |
15367 | } | |
15368 | else if (is_outer) | |
15369 | { | |
15370 | if ((parser->in_transaction & TM_STMT_ATTR_OUTER) == 0 | |
15371 | && !is_tm_may_cancel_outer (current_function_decl)) | |
15372 | { | |
15373 | error_at (loc, "outer %<__transaction_cancel%> not " | |
15374 | "within outer %<__transaction_atomic%>"); | |
15375 | error_at (loc, " or a %<transaction_may_cancel_outer%> function"); | |
15376 | goto ret_error; | |
15377 | } | |
15378 | } | |
15379 | else if (parser->in_transaction == 0) | |
15380 | { | |
15381 | error_at (loc, "%<__transaction_cancel%> not within " | |
15382 | "%<__transaction_atomic%>"); | |
15383 | goto ret_error; | |
15384 | } | |
15385 | ||
15386 | return add_stmt (build_tm_abort_call (loc, is_outer)); | |
15387 | ||
15388 | ret_error: | |
15389 | return build1 (NOP_EXPR, void_type_node, error_mark_node); | |
15390 | } | |
b75b98aa | 15391 | \f |
1576dec7 | 15392 | /* Parse a single source file. */ |
15393 | ||
15394 | void | |
15395 | c_parse_file (void) | |
15396 | { | |
b75b98aa | 15397 | /* Use local storage to begin. If the first token is a pragma, parse it. |
15398 | If it is #pragma GCC pch_preprocess, then this will load a PCH file | |
15399 | which will cause garbage collection. */ | |
15400 | c_parser tparser; | |
15401 | ||
15402 | memset (&tparser, 0, sizeof tparser); | |
bc7bff74 | 15403 | tparser.tokens = &tparser.tokens_buf[0]; |
b75b98aa | 15404 | the_parser = &tparser; |
15405 | ||
15406 | if (c_parser_peek_token (&tparser)->pragma_kind == PRAGMA_GCC_PCH_PREPROCESS) | |
15407 | c_parser_pragma_pch_preprocess (&tparser); | |
15408 | ||
25a27413 | 15409 | the_parser = ggc_alloc<c_parser> (); |
b75b98aa | 15410 | *the_parser = tparser; |
bc7bff74 | 15411 | if (tparser.tokens == &tparser.tokens_buf[0]) |
15412 | the_parser->tokens = &the_parser->tokens_buf[0]; | |
b75b98aa | 15413 | |
58d82cd0 | 15414 | /* Initialize EH, if we've been told to do so. */ |
15415 | if (flag_exceptions) | |
e38def9c | 15416 | using_eh_for_cleanups (); |
58d82cd0 | 15417 | |
1576dec7 | 15418 | c_parser_translation_unit (the_parser); |
15419 | the_parser = NULL; | |
15420 | } | |
15421 | ||
3c6d4197 | 15422 | /* This function parses Cilk Plus array notation. The starting index is |
15423 | passed in INITIAL_INDEX and the array name is passes in ARRAY_VALUE. The | |
15424 | return value of this function is a tree_node called VALUE_TREE of type | |
15425 | ARRAY_NOTATION_REF. */ | |
15426 | ||
15427 | static tree | |
15428 | c_parser_array_notation (location_t loc, c_parser *parser, tree initial_index, | |
15429 | tree array_value) | |
15430 | { | |
15431 | c_token *token = NULL; | |
15432 | tree start_index = NULL_TREE, end_index = NULL_TREE, stride = NULL_TREE; | |
15433 | tree value_tree = NULL_TREE, type = NULL_TREE, array_type = NULL_TREE; | |
15434 | tree array_type_domain = NULL_TREE; | |
15435 | ||
4879e4cf | 15436 | if (array_value == error_mark_node || initial_index == error_mark_node) |
3c6d4197 | 15437 | { |
15438 | /* No need to continue. If either of these 2 were true, then an error | |
15439 | must be emitted already. Thus, no need to emit them twice. */ | |
15440 | c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL); | |
15441 | return error_mark_node; | |
15442 | } | |
15443 | ||
15444 | array_type = TREE_TYPE (array_value); | |
15445 | gcc_assert (array_type); | |
5fdda74b | 15446 | if (TREE_CODE (array_type) != ARRAY_TYPE |
15447 | && TREE_CODE (array_type) != POINTER_TYPE) | |
15448 | { | |
15449 | error_at (loc, "base of array section must be pointer or array type"); | |
15450 | c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL); | |
15451 | return error_mark_node; | |
15452 | } | |
3c6d4197 | 15453 | type = TREE_TYPE (array_type); |
15454 | token = c_parser_peek_token (parser); | |
15455 | ||
15456 | if (token->type == CPP_EOF) | |
15457 | { | |
15458 | c_parser_error (parser, "expected %<:%> or numeral"); | |
15459 | return value_tree; | |
15460 | } | |
15461 | else if (token->type == CPP_COLON) | |
15462 | { | |
15463 | if (!initial_index) | |
15464 | { | |
15465 | /* If we are here, then we have a case like this A[:]. */ | |
15466 | c_parser_consume_token (parser); | |
15467 | if (TREE_CODE (array_type) == POINTER_TYPE) | |
15468 | { | |
15469 | error_at (loc, "start-index and length fields necessary for " | |
15470 | "using array notations in pointers"); | |
15471 | c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL); | |
15472 | return error_mark_node; | |
15473 | } | |
15474 | if (TREE_CODE (array_type) == FUNCTION_TYPE) | |
15475 | { | |
15476 | error_at (loc, "array notations cannot be used with function " | |
15477 | "type"); | |
15478 | c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL); | |
15479 | return error_mark_node; | |
15480 | } | |
3c6d4197 | 15481 | array_type_domain = TYPE_DOMAIN (array_type); |
15482 | ||
15483 | if (!array_type_domain) | |
15484 | { | |
15485 | error_at (loc, "start-index and length fields necessary for " | |
15486 | "using array notations in dimensionless arrays"); | |
15487 | c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL); | |
15488 | return error_mark_node; | |
15489 | } | |
15490 | ||
15491 | start_index = TYPE_MINVAL (array_type_domain); | |
15492 | start_index = fold_build1 (CONVERT_EXPR, ptrdiff_type_node, | |
15493 | start_index); | |
15494 | if (!TYPE_MAXVAL (array_type_domain) | |
15495 | || !TREE_CONSTANT (TYPE_MAXVAL (array_type_domain))) | |
15496 | { | |
15497 | error_at (loc, "start-index and length fields necessary for " | |
15498 | "using array notations in variable-length arrays"); | |
15499 | c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL); | |
15500 | return error_mark_node; | |
15501 | } | |
15502 | end_index = TYPE_MAXVAL (array_type_domain); | |
15503 | end_index = fold_build2 (PLUS_EXPR, TREE_TYPE (end_index), | |
15504 | end_index, integer_one_node); | |
15505 | end_index = fold_build1 (CONVERT_EXPR, ptrdiff_type_node, end_index); | |
15506 | stride = build_int_cst (integer_type_node, 1); | |
15507 | stride = fold_build1 (CONVERT_EXPR, ptrdiff_type_node, stride); | |
15508 | } | |
15509 | else if (initial_index != error_mark_node) | |
15510 | { | |
15511 | /* If we are here, then there should be 2 possibilities: | |
15512 | 1. Array [EXPR : EXPR] | |
15513 | 2. Array [EXPR : EXPR : EXPR] | |
15514 | */ | |
15515 | start_index = initial_index; | |
15516 | ||
15517 | if (TREE_CODE (array_type) == FUNCTION_TYPE) | |
15518 | { | |
15519 | error_at (loc, "array notations cannot be used with function " | |
15520 | "type"); | |
15521 | c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL); | |
15522 | return error_mark_node; | |
15523 | } | |
3c6d4197 | 15524 | c_parser_consume_token (parser); /* consume the ':' */ |
b560fabd | 15525 | struct c_expr ce = c_parser_expression (parser); |
15526 | ce = convert_lvalue_to_rvalue (loc, ce, false, false); | |
15527 | end_index = ce.value; | |
3c6d4197 | 15528 | if (!end_index || end_index == error_mark_node) |
15529 | { | |
15530 | c_parser_skip_to_end_of_block_or_statement (parser); | |
15531 | return error_mark_node; | |
15532 | } | |
15533 | if (c_parser_peek_token (parser)->type == CPP_COLON) | |
15534 | { | |
15535 | c_parser_consume_token (parser); | |
b560fabd | 15536 | ce = c_parser_expression (parser); |
15537 | ce = convert_lvalue_to_rvalue (loc, ce, false, false); | |
15538 | stride = ce.value; | |
3c6d4197 | 15539 | if (!stride || stride == error_mark_node) |
15540 | { | |
15541 | c_parser_skip_to_end_of_block_or_statement (parser); | |
15542 | return error_mark_node; | |
15543 | } | |
15544 | } | |
15545 | } | |
15546 | else | |
15547 | c_parser_error (parser, "expected array notation expression"); | |
15548 | } | |
15549 | else | |
15550 | c_parser_error (parser, "expected array notation expression"); | |
15551 | ||
15552 | c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, "expected %<]%>"); | |
15553 | ||
15554 | value_tree = build_array_notation_ref (loc, array_value, start_index, | |
15555 | end_index, stride, type); | |
15556 | if (value_tree != error_mark_node) | |
15557 | SET_EXPR_LOCATION (value_tree, loc); | |
15558 | return value_tree; | |
15559 | } | |
15560 | ||
e53d55e7 | 15561 | #include "gt-c-c-parser.h" |