]>
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. */ |
9ef16211 | 42 | #include "tree.h" |
b20a8bb4 | 43 | #include "alias.h" |
b20a8bb4 | 44 | #include "flags.h" |
b20a8bb4 | 45 | #include "fold-const.h" |
9ed99284 | 46 | #include "stringpool.h" |
47 | #include "attribs.h" | |
48 | #include "stor-layout.h" | |
49 | #include "varasm.h" | |
50 | #include "trans-mem.h" | |
1576dec7 | 51 | #include "langhooks.h" |
1576dec7 | 52 | #include "cpplib.h" |
53 | #include "timevar.h" | |
7bedc3a0 | 54 | #include "c-family/c-pragma.h" |
1576dec7 | 55 | #include "c-tree.h" |
bc7bff74 | 56 | #include "c-lang.h" |
1576dec7 | 57 | #include "flags.h" |
7bedc3a0 | 58 | #include "c-family/c-common.h" |
6c536c4f | 59 | #include "c-family/c-objc.h" |
b75b98aa | 60 | #include "target.h" |
1140c305 | 61 | #include "hard-reg-set.h" |
62 | #include "function.h" | |
56af936e | 63 | #include "cgraph.h" |
9227b6fc | 64 | #include "plugin.h" |
7740abd8 | 65 | #include "omp-low.h" |
f7715905 | 66 | #include "builtins.h" |
ca4c3545 | 67 | #include "gomp-constants.h" |
9255be07 | 68 | #include "c-family/c-indentation.h" |
1576dec7 | 69 | |
70 | \f | |
1576dec7 | 71 | /* Initialization routine for this file. */ |
72 | ||
73 | void | |
74 | c_parse_init (void) | |
75 | { | |
76 | /* The only initialization required is of the reserved word | |
77 | identifiers. */ | |
78 | unsigned int i; | |
79 | tree id; | |
5c6e5756 | 80 | int mask = 0; |
1576dec7 | 81 | |
6d5d708e | 82 | /* Make sure RID_MAX hasn't grown past the 8 bits used to hold the keyword in |
83 | the c_token structure. */ | |
84 | gcc_assert (RID_MAX <= 255); | |
85 | ||
5c6e5756 | 86 | mask |= D_CXXONLY; |
87 | if (!flag_isoc99) | |
88 | mask |= D_C99; | |
89 | if (flag_no_asm) | |
90 | { | |
91 | mask |= D_ASM | D_EXT; | |
92 | if (!flag_isoc99) | |
93 | mask |= D_EXT89; | |
94 | } | |
1576dec7 | 95 | if (!c_dialect_objc ()) |
5c6e5756 | 96 | mask |= D_OBJC | D_CXX_OBJC; |
1576dec7 | 97 | |
25a27413 | 98 | ridpointers = ggc_cleared_vec_alloc<tree> ((int) RID_MAX); |
5c6e5756 | 99 | for (i = 0; i < num_c_common_reswords; i++) |
1576dec7 | 100 | { |
101 | /* If a keyword is disabled, do not enter it into the table | |
102 | and so create a canonical spelling that isn't a keyword. */ | |
5c6e5756 | 103 | if (c_common_reswords[i].disable & mask) |
104 | { | |
105 | if (warn_cxx_compat | |
106 | && (c_common_reswords[i].disable & D_CXXWARN)) | |
107 | { | |
108 | id = get_identifier (c_common_reswords[i].word); | |
109 | C_SET_RID_CODE (id, RID_CXX_COMPAT_WARN); | |
110 | C_IS_RESERVED_WORD (id) = 1; | |
111 | } | |
112 | continue; | |
113 | } | |
1576dec7 | 114 | |
5c6e5756 | 115 | id = get_identifier (c_common_reswords[i].word); |
116 | C_SET_RID_CODE (id, c_common_reswords[i].rid); | |
1576dec7 | 117 | C_IS_RESERVED_WORD (id) = 1; |
5c6e5756 | 118 | ridpointers [(int) c_common_reswords[i].rid] = id; |
1576dec7 | 119 | } |
9f75f026 | 120 | |
121 | for (i = 0; i < NUM_INT_N_ENTS; i++) | |
122 | { | |
123 | /* We always create the symbols but they aren't always supported. */ | |
124 | char name[50]; | |
125 | sprintf (name, "__int%d", int_n_data[i].bitsize); | |
76738f56 | 126 | id = get_identifier (name); |
9f75f026 | 127 | C_SET_RID_CODE (id, RID_FIRST_INT_N + i); |
128 | C_IS_RESERVED_WORD (id) = 1; | |
129 | } | |
1576dec7 | 130 | } |
131 | \f | |
132 | /* The C lexer intermediates between the lexer in cpplib and c-lex.c | |
133 | and the C parser. Unlike the C++ lexer, the parser structure | |
134 | stores the lexer information instead of using a separate structure. | |
135 | Identifiers are separated into ordinary identifiers, type names, | |
136 | keywords and some other Objective-C types of identifiers, and some | |
137 | look-ahead is maintained. | |
138 | ||
139 | ??? It might be a good idea to lex the whole file up front (as for | |
140 | C++). It would then be possible to share more of the C and C++ | |
141 | lexer code, if desired. */ | |
142 | ||
1576dec7 | 143 | /* More information about the type of a CPP_NAME token. */ |
6dc50383 | 144 | enum c_id_kind { |
1576dec7 | 145 | /* An ordinary identifier. */ |
146 | C_ID_ID, | |
147 | /* An identifier declared as a typedef name. */ | |
148 | C_ID_TYPENAME, | |
149 | /* An identifier declared as an Objective-C class name. */ | |
150 | C_ID_CLASSNAME, | |
6d5d708e | 151 | /* An address space identifier. */ |
152 | C_ID_ADDRSPACE, | |
1576dec7 | 153 | /* Not an identifier. */ |
154 | C_ID_NONE | |
6dc50383 | 155 | }; |
1576dec7 | 156 | |
157 | /* A single C token after string literal concatenation and conversion | |
158 | of preprocessing tokens to tokens. */ | |
6dc50383 | 159 | struct GTY (()) c_token { |
1576dec7 | 160 | /* The kind of token. */ |
161 | ENUM_BITFIELD (cpp_ttype) type : 8; | |
162 | /* If this token is a CPP_NAME, this value indicates whether also | |
163 | declared as some kind of type. Otherwise, it is C_ID_NONE. */ | |
164 | ENUM_BITFIELD (c_id_kind) id_kind : 8; | |
165 | /* If this token is a keyword, this value indicates which keyword. | |
166 | Otherwise, this value is RID_MAX. */ | |
167 | ENUM_BITFIELD (rid) keyword : 8; | |
b75b98aa | 168 | /* If this token is a CPP_PRAGMA, this indicates the pragma that |
169 | was seen. Otherwise it is PRAGMA_NONE. */ | |
a7bf9930 | 170 | ENUM_BITFIELD (pragma_kind) pragma_kind : 8; |
1576dec7 | 171 | /* The location at which this token was found. */ |
172 | location_t location; | |
561ba0aa | 173 | /* The value associated with this token, if any. */ |
174 | tree value; | |
6dc50383 | 175 | }; |
1576dec7 | 176 | |
177 | /* A parser structure recording information about the state and | |
178 | context of parsing. Includes lexer information with up to two | |
179 | tokens of look-ahead; more are not needed for C. */ | |
6dc50383 | 180 | struct GTY(()) c_parser { |
1576dec7 | 181 | /* The look-ahead tokens. */ |
bc7bff74 | 182 | c_token * GTY((skip)) tokens; |
183 | /* Buffer for look-ahead tokens. */ | |
184 | c_token tokens_buf[2]; | |
185 | /* How many look-ahead tokens are available (0, 1 or 2, or | |
186 | more if parsing from pre-lexed tokens). */ | |
187 | unsigned int tokens_avail; | |
1576dec7 | 188 | /* True if a syntax error is being recovered from; false otherwise. |
189 | c_parser_error sets this flag. It should clear this flag when | |
190 | enough tokens have been consumed to recover from the error. */ | |
191 | BOOL_BITFIELD error : 1; | |
b75b98aa | 192 | /* True if we're processing a pragma, and shouldn't automatically |
193 | consume CPP_PRAGMA_EOL. */ | |
194 | BOOL_BITFIELD in_pragma : 1; | |
10c93a35 | 195 | /* True if we're parsing the outermost block of an if statement. */ |
196 | BOOL_BITFIELD in_if_block : 1; | |
8115b8be | 197 | /* True if we want to lex an untranslated string. */ |
198 | BOOL_BITFIELD lex_untranslated_string : 1; | |
b27e241e | 199 | |
920d59b0 | 200 | /* Objective-C specific parser/lexer information. */ |
b27e241e | 201 | |
202 | /* True if we are in a context where the Objective-C "PQ" keywords | |
203 | are considered keywords. */ | |
920d59b0 | 204 | BOOL_BITFIELD objc_pq_context : 1; |
0a65c3bb | 205 | /* True if we are parsing a (potential) Objective-C foreach |
206 | statement. This is set to true after we parsed 'for (' and while | |
207 | we wait for 'in' or ';' to decide if it's a standard C for loop or an | |
208 | Objective-C foreach loop. */ | |
209 | BOOL_BITFIELD objc_could_be_foreach_context : 1; | |
920d59b0 | 210 | /* The following flag is needed to contextualize Objective-C lexical |
211 | analysis. In some cases (e.g., 'int NSObject;'), it is | |
212 | undesirable to bind an identifier to an Objective-C class, even | |
213 | if a class with that name exists. */ | |
214 | BOOL_BITFIELD objc_need_raw_identifier : 1; | |
4c0315d0 | 215 | /* Nonzero if we're processing a __transaction statement. The value |
216 | is 1 | TM_STMT_ATTR_*. */ | |
217 | unsigned int in_transaction : 4; | |
86c110ac | 218 | /* True if we are in a context where the Objective-C "Property attribute" |
219 | keywords are valid. */ | |
220 | BOOL_BITFIELD objc_property_attr_context : 1; | |
74acc703 | 221 | |
222 | /* Cilk Plus specific parser/lexer information. */ | |
223 | ||
224 | /* Buffer to hold all the tokens from parsing the vector attribute for the | |
225 | SIMD-enabled functions (formerly known as elemental functions). */ | |
226 | vec <c_token, va_gc> *cilk_simd_fn_tokens; | |
6dc50383 | 227 | }; |
1576dec7 | 228 | |
b75b98aa | 229 | |
230 | /* The actual parser and external interface. ??? Does this need to be | |
231 | garbage-collected? */ | |
232 | ||
233 | static GTY (()) c_parser *the_parser; | |
234 | ||
1576dec7 | 235 | /* Read in and lex a single token, storing it in *TOKEN. */ |
236 | ||
237 | static void | |
920d59b0 | 238 | c_lex_one_token (c_parser *parser, c_token *token) |
1576dec7 | 239 | { |
240 | timevar_push (TV_LEX); | |
b75b98aa | 241 | |
8115b8be | 242 | token->type = c_lex_with_flags (&token->value, &token->location, NULL, |
243 | (parser->lex_untranslated_string | |
244 | ? C_LEX_STRING_NO_TRANSLATE : 0)); | |
b75b98aa | 245 | token->id_kind = C_ID_NONE; |
246 | token->keyword = RID_MAX; | |
247 | token->pragma_kind = PRAGMA_NONE; | |
b75b98aa | 248 | |
1576dec7 | 249 | switch (token->type) |
250 | { | |
251 | case CPP_NAME: | |
1576dec7 | 252 | { |
253 | tree decl; | |
254 | ||
920d59b0 | 255 | bool objc_force_identifier = parser->objc_need_raw_identifier; |
256 | if (c_dialect_objc ()) | |
257 | parser->objc_need_raw_identifier = false; | |
1576dec7 | 258 | |
259 | if (C_IS_RESERVED_WORD (token->value)) | |
260 | { | |
261 | enum rid rid_code = C_RID_CODE (token->value); | |
262 | ||
5c6e5756 | 263 | if (rid_code == RID_CXX_COMPAT_WARN) |
264 | { | |
e3b80d49 | 265 | warning_at (token->location, |
266 | OPT_Wc___compat, | |
d1dd9ac0 | 267 | "identifier %qE conflicts with C++ keyword", |
268 | token->value); | |
5c6e5756 | 269 | } |
6d5d708e | 270 | else if (rid_code >= RID_FIRST_ADDR_SPACE |
271 | && rid_code <= RID_LAST_ADDR_SPACE) | |
272 | { | |
273 | token->id_kind = C_ID_ADDRSPACE; | |
274 | token->keyword = rid_code; | |
275 | break; | |
276 | } | |
b27e241e | 277 | else if (c_dialect_objc () && OBJC_IS_PQ_KEYWORD (rid_code)) |
1576dec7 | 278 | { |
b27e241e | 279 | /* We found an Objective-C "pq" keyword (in, out, |
280 | inout, bycopy, byref, oneway). They need special | |
281 | care because the interpretation depends on the | |
ffbb3d61 | 282 | context. */ |
b27e241e | 283 | if (parser->objc_pq_context) |
1576dec7 | 284 | { |
1576dec7 | 285 | token->type = CPP_KEYWORD; |
286 | token->keyword = rid_code; | |
287 | break; | |
288 | } | |
0a65c3bb | 289 | else if (parser->objc_could_be_foreach_context |
290 | && rid_code == RID_IN) | |
291 | { | |
292 | /* We are in Objective-C, inside a (potential) | |
293 | foreach context (which means after having | |
294 | parsed 'for (', but before having parsed ';'), | |
295 | and we found 'in'. We consider it the keyword | |
296 | which terminates the declaration at the | |
297 | beginning of a foreach-statement. Note that | |
298 | this means you can't use 'in' for anything else | |
299 | in that context; in particular, in Objective-C | |
300 | you can't use 'in' as the name of the running | |
301 | variable in a C for loop. We could potentially | |
302 | try to add code here to disambiguate, but it | |
ffbb3d61 | 303 | seems a reasonable limitation. */ |
0a65c3bb | 304 | token->type = CPP_KEYWORD; |
305 | token->keyword = rid_code; | |
306 | break; | |
307 | } | |
b27e241e | 308 | /* Else, "pq" keywords outside of the "pq" context are |
309 | not keywords, and we fall through to the code for | |
ffbb3d61 | 310 | normal tokens. */ |
b27e241e | 311 | } |
86c110ac | 312 | else if (c_dialect_objc () && OBJC_IS_PATTR_KEYWORD (rid_code)) |
313 | { | |
ffbb3d61 | 314 | /* We found an Objective-C "property attribute" |
315 | keyword (getter, setter, readonly, etc). These are | |
86c110ac | 316 | only valid in the property context. */ |
317 | if (parser->objc_property_attr_context) | |
318 | { | |
319 | token->type = CPP_KEYWORD; | |
320 | token->keyword = rid_code; | |
321 | break; | |
322 | } | |
323 | /* Else they are not special keywords. | |
324 | */ | |
325 | } | |
b27e241e | 326 | else if (c_dialect_objc () |
327 | && (OBJC_IS_AT_KEYWORD (rid_code) | |
328 | || OBJC_IS_CXX_KEYWORD (rid_code))) | |
329 | { | |
330 | /* We found one of the Objective-C "@" keywords (defs, | |
331 | selector, synchronized, etc) or one of the | |
332 | Objective-C "cxx" keywords (class, private, | |
333 | protected, public, try, catch, throw) without a | |
334 | preceding '@' sign. Do nothing and fall through to | |
335 | the code for normal tokens (in C++ we would still | |
ffbb3d61 | 336 | consider the CXX ones keywords, but not in C). */ |
b27e241e | 337 | ; |
1576dec7 | 338 | } |
339 | else | |
340 | { | |
1576dec7 | 341 | token->type = CPP_KEYWORD; |
342 | token->keyword = rid_code; | |
343 | break; | |
344 | } | |
345 | } | |
346 | ||
347 | decl = lookup_name (token->value); | |
348 | if (decl) | |
349 | { | |
350 | if (TREE_CODE (decl) == TYPE_DECL) | |
351 | { | |
352 | token->id_kind = C_ID_TYPENAME; | |
353 | break; | |
354 | } | |
355 | } | |
356 | else if (c_dialect_objc ()) | |
357 | { | |
358 | tree objc_interface_decl = objc_is_class_name (token->value); | |
359 | /* Objective-C class names are in the same namespace as | |
360 | variables and typedefs, and hence are shadowed by local | |
361 | declarations. */ | |
362 | if (objc_interface_decl | |
05ca272f | 363 | && (!objc_force_identifier || global_bindings_p ())) |
1576dec7 | 364 | { |
365 | token->value = objc_interface_decl; | |
366 | token->id_kind = C_ID_CLASSNAME; | |
367 | break; | |
368 | } | |
369 | } | |
b75b98aa | 370 | token->id_kind = C_ID_ID; |
1576dec7 | 371 | } |
1576dec7 | 372 | break; |
373 | case CPP_AT_NAME: | |
374 | /* This only happens in Objective-C; it must be a keyword. */ | |
375 | token->type = CPP_KEYWORD; | |
e5c75ac3 | 376 | switch (C_RID_CODE (token->value)) |
377 | { | |
378 | /* Replace 'class' with '@class', 'private' with '@private', | |
379 | etc. This prevents confusion with the C++ keyword | |
380 | 'class', and makes the tokens consistent with other | |
381 | Objective-C 'AT' keywords. For example '@class' is | |
382 | reported as RID_AT_CLASS which is consistent with | |
383 | '@synchronized', which is reported as | |
384 | RID_AT_SYNCHRONIZED. | |
385 | */ | |
386 | case RID_CLASS: token->keyword = RID_AT_CLASS; break; | |
387 | case RID_PRIVATE: token->keyword = RID_AT_PRIVATE; break; | |
388 | case RID_PROTECTED: token->keyword = RID_AT_PROTECTED; break; | |
389 | case RID_PUBLIC: token->keyword = RID_AT_PUBLIC; break; | |
390 | case RID_THROW: token->keyword = RID_AT_THROW; break; | |
391 | case RID_TRY: token->keyword = RID_AT_TRY; break; | |
392 | case RID_CATCH: token->keyword = RID_AT_CATCH; break; | |
6d02e6b2 | 393 | case RID_SYNCHRONIZED: token->keyword = RID_AT_SYNCHRONIZED; break; |
e5c75ac3 | 394 | default: token->keyword = C_RID_CODE (token->value); |
395 | } | |
1576dec7 | 396 | break; |
397 | case CPP_COLON: | |
398 | case CPP_COMMA: | |
399 | case CPP_CLOSE_PAREN: | |
400 | case CPP_SEMICOLON: | |
401 | /* These tokens may affect the interpretation of any identifiers | |
402 | following, if doing Objective-C. */ | |
920d59b0 | 403 | if (c_dialect_objc ()) |
404 | parser->objc_need_raw_identifier = false; | |
b75b98aa | 405 | break; |
406 | case CPP_PRAGMA: | |
407 | /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */ | |
f9ae6f95 | 408 | token->pragma_kind = (enum pragma_kind) TREE_INT_CST_LOW (token->value); |
b75b98aa | 409 | token->value = NULL; |
1576dec7 | 410 | break; |
411 | default: | |
1576dec7 | 412 | break; |
413 | } | |
414 | timevar_pop (TV_LEX); | |
415 | } | |
416 | ||
417 | /* Return a pointer to the next token from PARSER, reading it in if | |
418 | necessary. */ | |
419 | ||
420 | static inline c_token * | |
421 | c_parser_peek_token (c_parser *parser) | |
422 | { | |
423 | if (parser->tokens_avail == 0) | |
424 | { | |
920d59b0 | 425 | c_lex_one_token (parser, &parser->tokens[0]); |
1576dec7 | 426 | parser->tokens_avail = 1; |
427 | } | |
428 | return &parser->tokens[0]; | |
429 | } | |
430 | ||
431 | /* Return true if the next token from PARSER has the indicated | |
432 | TYPE. */ | |
433 | ||
434 | static inline bool | |
435 | c_parser_next_token_is (c_parser *parser, enum cpp_ttype type) | |
436 | { | |
437 | return c_parser_peek_token (parser)->type == type; | |
438 | } | |
439 | ||
440 | /* Return true if the next token from PARSER does not have the | |
441 | indicated TYPE. */ | |
442 | ||
443 | static inline bool | |
444 | c_parser_next_token_is_not (c_parser *parser, enum cpp_ttype type) | |
445 | { | |
446 | return !c_parser_next_token_is (parser, type); | |
447 | } | |
448 | ||
449 | /* Return true if the next token from PARSER is the indicated | |
450 | KEYWORD. */ | |
451 | ||
452 | static inline bool | |
453 | c_parser_next_token_is_keyword (c_parser *parser, enum rid keyword) | |
454 | { | |
b3cafa91 | 455 | return c_parser_peek_token (parser)->keyword == keyword; |
1576dec7 | 456 | } |
457 | ||
26ee9e7a | 458 | /* Return a pointer to the next-but-one token from PARSER, reading it |
459 | in if necessary. The next token is already read in. */ | |
460 | ||
461 | static c_token * | |
462 | c_parser_peek_2nd_token (c_parser *parser) | |
463 | { | |
464 | if (parser->tokens_avail >= 2) | |
465 | return &parser->tokens[1]; | |
466 | gcc_assert (parser->tokens_avail == 1); | |
467 | gcc_assert (parser->tokens[0].type != CPP_EOF); | |
468 | gcc_assert (parser->tokens[0].type != CPP_PRAGMA_EOL); | |
469 | c_lex_one_token (parser, &parser->tokens[1]); | |
470 | parser->tokens_avail = 2; | |
471 | return &parser->tokens[1]; | |
472 | } | |
473 | ||
1576dec7 | 474 | /* Return true if TOKEN can start a type name, |
475 | false otherwise. */ | |
476 | static bool | |
477 | c_token_starts_typename (c_token *token) | |
478 | { | |
479 | switch (token->type) | |
480 | { | |
481 | case CPP_NAME: | |
482 | switch (token->id_kind) | |
483 | { | |
484 | case C_ID_ID: | |
485 | return false; | |
6d5d708e | 486 | case C_ID_ADDRSPACE: |
487 | return true; | |
1576dec7 | 488 | case C_ID_TYPENAME: |
489 | return true; | |
490 | case C_ID_CLASSNAME: | |
491 | gcc_assert (c_dialect_objc ()); | |
492 | return true; | |
493 | default: | |
494 | gcc_unreachable (); | |
495 | } | |
496 | case CPP_KEYWORD: | |
497 | switch (token->keyword) | |
498 | { | |
499 | case RID_UNSIGNED: | |
500 | case RID_LONG: | |
501 | case RID_SHORT: | |
502 | case RID_SIGNED: | |
503 | case RID_COMPLEX: | |
504 | case RID_INT: | |
505 | case RID_CHAR: | |
506 | case RID_FLOAT: | |
507 | case RID_DOUBLE: | |
508 | case RID_VOID: | |
c4503c0a | 509 | case RID_DFLOAT32: |
510 | case RID_DFLOAT64: | |
511 | case RID_DFLOAT128: | |
1576dec7 | 512 | case RID_BOOL: |
513 | case RID_ENUM: | |
514 | case RID_STRUCT: | |
515 | case RID_UNION: | |
516 | case RID_TYPEOF: | |
517 | case RID_CONST: | |
b560fabd | 518 | case RID_ATOMIC: |
1576dec7 | 519 | case RID_VOLATILE: |
520 | case RID_RESTRICT: | |
521 | case RID_ATTRIBUTE: | |
9421ebb9 | 522 | case RID_FRACT: |
523 | case RID_ACCUM: | |
524 | case RID_SAT: | |
4fba5eb9 | 525 | case RID_AUTO_TYPE: |
1576dec7 | 526 | return true; |
527 | default: | |
9f75f026 | 528 | if (token->keyword >= RID_FIRST_INT_N |
529 | && token->keyword < RID_FIRST_INT_N + NUM_INT_N_ENTS | |
530 | && int_n_enabled_p[token->keyword - RID_FIRST_INT_N]) | |
531 | return true; | |
1576dec7 | 532 | return false; |
533 | } | |
534 | case CPP_LESS: | |
535 | if (c_dialect_objc ()) | |
536 | return true; | |
537 | return false; | |
538 | default: | |
539 | return false; | |
540 | } | |
541 | } | |
542 | ||
26ee9e7a | 543 | enum c_lookahead_kind { |
544 | /* Always treat unknown identifiers as typenames. */ | |
545 | cla_prefer_type, | |
546 | ||
547 | /* Could be parsing a nonabstract declarator. Only treat an identifier | |
548 | as a typename if followed by another identifier or a star. */ | |
549 | cla_nonabstract_decl, | |
550 | ||
551 | /* Never treat identifiers as typenames. */ | |
552 | cla_prefer_id | |
553 | }; | |
554 | ||
1576dec7 | 555 | /* Return true if the next token from PARSER can start a type name, |
26ee9e7a | 556 | false otherwise. LA specifies how to do lookahead in order to |
557 | detect unknown type names. If unsure, pick CLA_PREFER_ID. */ | |
558 | ||
1576dec7 | 559 | static inline bool |
26ee9e7a | 560 | c_parser_next_tokens_start_typename (c_parser *parser, enum c_lookahead_kind la) |
1576dec7 | 561 | { |
562 | c_token *token = c_parser_peek_token (parser); | |
26ee9e7a | 563 | if (c_token_starts_typename (token)) |
564 | return true; | |
565 | ||
566 | /* Try a bit harder to detect an unknown typename. */ | |
567 | if (la != cla_prefer_id | |
568 | && token->type == CPP_NAME | |
569 | && token->id_kind == C_ID_ID | |
570 | ||
571 | /* Do not try too hard when we could have "object in array". */ | |
572 | && !parser->objc_could_be_foreach_context | |
573 | ||
574 | && (la == cla_prefer_type | |
575 | || c_parser_peek_2nd_token (parser)->type == CPP_NAME | |
576 | || c_parser_peek_2nd_token (parser)->type == CPP_MULT) | |
577 | ||
578 | /* Only unknown identifiers. */ | |
579 | && !lookup_name (token->value)) | |
580 | return true; | |
581 | ||
582 | return false; | |
1576dec7 | 583 | } |
584 | ||
b02d8973 | 585 | /* Return true if TOKEN is a type qualifier, false otherwise. */ |
586 | static bool | |
587 | c_token_is_qualifier (c_token *token) | |
588 | { | |
589 | switch (token->type) | |
590 | { | |
591 | case CPP_NAME: | |
592 | switch (token->id_kind) | |
593 | { | |
594 | case C_ID_ADDRSPACE: | |
595 | return true; | |
596 | default: | |
597 | return false; | |
598 | } | |
599 | case CPP_KEYWORD: | |
600 | switch (token->keyword) | |
601 | { | |
602 | case RID_CONST: | |
603 | case RID_VOLATILE: | |
604 | case RID_RESTRICT: | |
605 | case RID_ATTRIBUTE: | |
b560fabd | 606 | case RID_ATOMIC: |
b02d8973 | 607 | return true; |
608 | default: | |
609 | return false; | |
610 | } | |
611 | case CPP_LESS: | |
612 | return false; | |
613 | default: | |
614 | gcc_unreachable (); | |
615 | } | |
616 | } | |
617 | ||
618 | /* Return true if the next token from PARSER is a type qualifier, | |
619 | false otherwise. */ | |
620 | static inline bool | |
621 | c_parser_next_token_is_qualifier (c_parser *parser) | |
622 | { | |
623 | c_token *token = c_parser_peek_token (parser); | |
624 | return c_token_is_qualifier (token); | |
625 | } | |
626 | ||
1576dec7 | 627 | /* Return true if TOKEN can start declaration specifiers, false |
628 | otherwise. */ | |
629 | static bool | |
630 | c_token_starts_declspecs (c_token *token) | |
631 | { | |
632 | switch (token->type) | |
633 | { | |
634 | case CPP_NAME: | |
635 | switch (token->id_kind) | |
636 | { | |
637 | case C_ID_ID: | |
638 | return false; | |
6d5d708e | 639 | case C_ID_ADDRSPACE: |
640 | return true; | |
1576dec7 | 641 | case C_ID_TYPENAME: |
642 | return true; | |
643 | case C_ID_CLASSNAME: | |
644 | gcc_assert (c_dialect_objc ()); | |
645 | return true; | |
646 | default: | |
647 | gcc_unreachable (); | |
648 | } | |
649 | case CPP_KEYWORD: | |
650 | switch (token->keyword) | |
651 | { | |
652 | case RID_STATIC: | |
653 | case RID_EXTERN: | |
654 | case RID_REGISTER: | |
655 | case RID_TYPEDEF: | |
656 | case RID_INLINE: | |
985c6e3a | 657 | case RID_NORETURN: |
1576dec7 | 658 | case RID_AUTO: |
659 | case RID_THREAD: | |
660 | case RID_UNSIGNED: | |
661 | case RID_LONG: | |
662 | case RID_SHORT: | |
663 | case RID_SIGNED: | |
664 | case RID_COMPLEX: | |
665 | case RID_INT: | |
666 | case RID_CHAR: | |
667 | case RID_FLOAT: | |
668 | case RID_DOUBLE: | |
669 | case RID_VOID: | |
c4503c0a | 670 | case RID_DFLOAT32: |
671 | case RID_DFLOAT64: | |
672 | case RID_DFLOAT128: | |
1576dec7 | 673 | case RID_BOOL: |
674 | case RID_ENUM: | |
675 | case RID_STRUCT: | |
676 | case RID_UNION: | |
677 | case RID_TYPEOF: | |
678 | case RID_CONST: | |
679 | case RID_VOLATILE: | |
680 | case RID_RESTRICT: | |
681 | case RID_ATTRIBUTE: | |
9421ebb9 | 682 | case RID_FRACT: |
683 | case RID_ACCUM: | |
684 | case RID_SAT: | |
83e25171 | 685 | case RID_ALIGNAS: |
b560fabd | 686 | case RID_ATOMIC: |
4fba5eb9 | 687 | case RID_AUTO_TYPE: |
1576dec7 | 688 | return true; |
689 | default: | |
9f75f026 | 690 | if (token->keyword >= RID_FIRST_INT_N |
691 | && token->keyword < RID_FIRST_INT_N + NUM_INT_N_ENTS | |
692 | && int_n_enabled_p[token->keyword - RID_FIRST_INT_N]) | |
693 | return true; | |
1576dec7 | 694 | return false; |
695 | } | |
696 | case CPP_LESS: | |
697 | if (c_dialect_objc ()) | |
698 | return true; | |
699 | return false; | |
700 | default: | |
701 | return false; | |
702 | } | |
703 | } | |
704 | ||
f80e7755 | 705 | |
706 | /* Return true if TOKEN can start declaration specifiers or a static | |
707 | assertion, false otherwise. */ | |
708 | static bool | |
709 | c_token_starts_declaration (c_token *token) | |
710 | { | |
711 | if (c_token_starts_declspecs (token) | |
712 | || token->keyword == RID_STATIC_ASSERT) | |
713 | return true; | |
714 | else | |
715 | return false; | |
716 | } | |
717 | ||
1576dec7 | 718 | /* Return true if the next token from PARSER can start declaration |
719 | specifiers, false otherwise. */ | |
720 | static inline bool | |
721 | c_parser_next_token_starts_declspecs (c_parser *parser) | |
722 | { | |
723 | c_token *token = c_parser_peek_token (parser); | |
b0d0931f | 724 | |
725 | /* In Objective-C, a classname normally starts a declspecs unless it | |
726 | is immediately followed by a dot. In that case, it is the | |
727 | Objective-C 2.0 "dot-syntax" for class objects, ie, calls the | |
728 | setter/getter on the class. c_token_starts_declspecs() can't | |
729 | differentiate between the two cases because it only checks the | |
730 | current token, so we have a special check here. */ | |
731 | if (c_dialect_objc () | |
732 | && token->type == CPP_NAME | |
733 | && token->id_kind == C_ID_CLASSNAME | |
734 | && c_parser_peek_2nd_token (parser)->type == CPP_DOT) | |
735 | return false; | |
736 | ||
1576dec7 | 737 | return c_token_starts_declspecs (token); |
738 | } | |
739 | ||
71bb4bc6 | 740 | /* Return true if the next tokens from PARSER can start declaration |
f80e7755 | 741 | specifiers or a static assertion, false otherwise. */ |
742 | static inline bool | |
71bb4bc6 | 743 | c_parser_next_tokens_start_declaration (c_parser *parser) |
f80e7755 | 744 | { |
745 | c_token *token = c_parser_peek_token (parser); | |
b0d0931f | 746 | |
747 | /* Same as above. */ | |
748 | if (c_dialect_objc () | |
749 | && token->type == CPP_NAME | |
750 | && token->id_kind == C_ID_CLASSNAME | |
751 | && c_parser_peek_2nd_token (parser)->type == CPP_DOT) | |
752 | return false; | |
753 | ||
71bb4bc6 | 754 | /* Labels do not start declarations. */ |
755 | if (token->type == CPP_NAME | |
756 | && c_parser_peek_2nd_token (parser)->type == CPP_COLON) | |
757 | return false; | |
758 | ||
759 | if (c_token_starts_declaration (token)) | |
760 | return true; | |
761 | ||
26ee9e7a | 762 | if (c_parser_next_tokens_start_typename (parser, cla_nonabstract_decl)) |
71bb4bc6 | 763 | return true; |
764 | ||
765 | return false; | |
f80e7755 | 766 | } |
767 | ||
1576dec7 | 768 | /* Consume the next token from PARSER. */ |
769 | ||
770 | static void | |
771 | c_parser_consume_token (c_parser *parser) | |
772 | { | |
b75b98aa | 773 | gcc_assert (parser->tokens_avail >= 1); |
774 | gcc_assert (parser->tokens[0].type != CPP_EOF); | |
775 | gcc_assert (!parser->in_pragma || parser->tokens[0].type != CPP_PRAGMA_EOL); | |
776 | gcc_assert (parser->error || parser->tokens[0].type != CPP_PRAGMA); | |
bc7bff74 | 777 | if (parser->tokens != &parser->tokens_buf[0]) |
778 | parser->tokens++; | |
779 | else if (parser->tokens_avail == 2) | |
1576dec7 | 780 | parser->tokens[0] = parser->tokens[1]; |
1576dec7 | 781 | parser->tokens_avail--; |
782 | } | |
783 | ||
b75b98aa | 784 | /* Expect the current token to be a #pragma. Consume it and remember |
785 | that we've begun parsing a pragma. */ | |
786 | ||
787 | static void | |
788 | c_parser_consume_pragma (c_parser *parser) | |
789 | { | |
790 | gcc_assert (!parser->in_pragma); | |
791 | gcc_assert (parser->tokens_avail >= 1); | |
792 | gcc_assert (parser->tokens[0].type == CPP_PRAGMA); | |
bc7bff74 | 793 | if (parser->tokens != &parser->tokens_buf[0]) |
794 | parser->tokens++; | |
795 | else if (parser->tokens_avail == 2) | |
b75b98aa | 796 | parser->tokens[0] = parser->tokens[1]; |
797 | parser->tokens_avail--; | |
798 | parser->in_pragma = true; | |
799 | } | |
800 | ||
3df42822 | 801 | /* Update the global input_location from TOKEN. */ |
1576dec7 | 802 | static inline void |
803 | c_parser_set_source_position_from_token (c_token *token) | |
804 | { | |
805 | if (token->type != CPP_EOF) | |
806 | { | |
807 | input_location = token->location; | |
1576dec7 | 808 | } |
809 | } | |
810 | ||
1576dec7 | 811 | /* Issue a diagnostic of the form |
812 | FILE:LINE: MESSAGE before TOKEN | |
813 | where TOKEN is the next token in the input stream of PARSER. | |
814 | MESSAGE (specified by the caller) is usually of the form "expected | |
815 | OTHER-TOKEN". | |
816 | ||
817 | Do not issue a diagnostic if still recovering from an error. | |
818 | ||
819 | ??? This is taken from the C++ parser, but building up messages in | |
820 | this way is not i18n-friendly and some other approach should be | |
821 | used. */ | |
822 | ||
823 | static void | |
380c6697 | 824 | c_parser_error (c_parser *parser, const char *gmsgid) |
1576dec7 | 825 | { |
826 | c_token *token = c_parser_peek_token (parser); | |
827 | if (parser->error) | |
828 | return; | |
829 | parser->error = true; | |
380c6697 | 830 | if (!gmsgid) |
1576dec7 | 831 | return; |
832 | /* This diagnostic makes more sense if it is tagged to the line of | |
833 | the token we just peeked at. */ | |
834 | c_parser_set_source_position_from_token (token); | |
380c6697 | 835 | c_parse_error (gmsgid, |
1576dec7 | 836 | /* Because c_parse_error does not understand |
837 | CPP_KEYWORD, keywords are treated like | |
838 | identifiers. */ | |
839 | (token->type == CPP_KEYWORD ? CPP_NAME : token->type), | |
ba99525e | 840 | /* ??? The C parser does not save the cpp flags of a |
841 | token, we need to pass 0 here and we will not get | |
842 | the source spelling of some tokens but rather the | |
843 | canonical spelling. */ | |
844 | token->value, /*flags=*/0); | |
1576dec7 | 845 | } |
846 | ||
847 | /* If the next token is of the indicated TYPE, consume it. Otherwise, | |
848 | issue the error MSGID. If MSGID is NULL then a message has already | |
849 | been produced and no message will be produced this time. Returns | |
850 | true if found, false otherwise. */ | |
851 | ||
852 | static bool | |
853 | c_parser_require (c_parser *parser, | |
854 | enum cpp_ttype type, | |
855 | const char *msgid) | |
856 | { | |
857 | if (c_parser_next_token_is (parser, type)) | |
858 | { | |
859 | c_parser_consume_token (parser); | |
860 | return true; | |
861 | } | |
862 | else | |
863 | { | |
864 | c_parser_error (parser, msgid); | |
865 | return false; | |
866 | } | |
867 | } | |
868 | ||
869 | /* If the next token is the indicated keyword, consume it. Otherwise, | |
870 | issue the error MSGID. Returns true if found, false otherwise. */ | |
871 | ||
872 | static bool | |
873 | c_parser_require_keyword (c_parser *parser, | |
874 | enum rid keyword, | |
875 | const char *msgid) | |
876 | { | |
877 | if (c_parser_next_token_is_keyword (parser, keyword)) | |
878 | { | |
879 | c_parser_consume_token (parser); | |
880 | return true; | |
881 | } | |
882 | else | |
883 | { | |
884 | c_parser_error (parser, msgid); | |
885 | return false; | |
886 | } | |
887 | } | |
888 | ||
889 | /* Like c_parser_require, except that tokens will be skipped until the | |
890 | desired token is found. An error message is still produced if the | |
891 | next token is not as expected. If MSGID is NULL then a message has | |
892 | already been produced and no message will be produced this | |
893 | time. */ | |
894 | ||
895 | static void | |
896 | c_parser_skip_until_found (c_parser *parser, | |
897 | enum cpp_ttype type, | |
898 | const char *msgid) | |
899 | { | |
900 | unsigned nesting_depth = 0; | |
901 | ||
902 | if (c_parser_require (parser, type, msgid)) | |
903 | return; | |
904 | ||
905 | /* Skip tokens until the desired token is found. */ | |
906 | while (true) | |
907 | { | |
908 | /* Peek at the next token. */ | |
909 | c_token *token = c_parser_peek_token (parser); | |
910 | /* If we've reached the token we want, consume it and stop. */ | |
911 | if (token->type == type && !nesting_depth) | |
912 | { | |
913 | c_parser_consume_token (parser); | |
914 | break; | |
915 | } | |
b75b98aa | 916 | |
1576dec7 | 917 | /* If we've run out of tokens, stop. */ |
918 | if (token->type == CPP_EOF) | |
919 | return; | |
b75b98aa | 920 | if (token->type == CPP_PRAGMA_EOL && parser->in_pragma) |
921 | return; | |
1576dec7 | 922 | if (token->type == CPP_OPEN_BRACE |
923 | || token->type == CPP_OPEN_PAREN | |
924 | || token->type == CPP_OPEN_SQUARE) | |
925 | ++nesting_depth; | |
926 | else if (token->type == CPP_CLOSE_BRACE | |
927 | || token->type == CPP_CLOSE_PAREN | |
928 | || token->type == CPP_CLOSE_SQUARE) | |
929 | { | |
930 | if (nesting_depth-- == 0) | |
931 | break; | |
932 | } | |
933 | /* Consume this token. */ | |
934 | c_parser_consume_token (parser); | |
935 | } | |
936 | parser->error = false; | |
937 | } | |
938 | ||
939 | /* Skip tokens until the end of a parameter is found, but do not | |
940 | consume the comma, semicolon or closing delimiter. */ | |
941 | ||
942 | static void | |
943 | c_parser_skip_to_end_of_parameter (c_parser *parser) | |
944 | { | |
945 | unsigned nesting_depth = 0; | |
946 | ||
947 | while (true) | |
948 | { | |
949 | c_token *token = c_parser_peek_token (parser); | |
950 | if ((token->type == CPP_COMMA || token->type == CPP_SEMICOLON) | |
951 | && !nesting_depth) | |
952 | break; | |
953 | /* If we've run out of tokens, stop. */ | |
954 | if (token->type == CPP_EOF) | |
955 | return; | |
b75b98aa | 956 | if (token->type == CPP_PRAGMA_EOL && parser->in_pragma) |
957 | return; | |
1576dec7 | 958 | if (token->type == CPP_OPEN_BRACE |
959 | || token->type == CPP_OPEN_PAREN | |
960 | || token->type == CPP_OPEN_SQUARE) | |
961 | ++nesting_depth; | |
962 | else if (token->type == CPP_CLOSE_BRACE | |
963 | || token->type == CPP_CLOSE_PAREN | |
964 | || token->type == CPP_CLOSE_SQUARE) | |
965 | { | |
966 | if (nesting_depth-- == 0) | |
967 | break; | |
968 | } | |
969 | /* Consume this token. */ | |
970 | c_parser_consume_token (parser); | |
971 | } | |
972 | parser->error = false; | |
973 | } | |
974 | ||
b75b98aa | 975 | /* Expect to be at the end of the pragma directive and consume an |
976 | end of line marker. */ | |
977 | ||
978 | static void | |
c3b1dca4 | 979 | c_parser_skip_to_pragma_eol (c_parser *parser, bool error_if_not_eol = true) |
b75b98aa | 980 | { |
981 | gcc_assert (parser->in_pragma); | |
982 | parser->in_pragma = false; | |
983 | ||
c3b1dca4 | 984 | if (error_if_not_eol && c_parser_peek_token (parser)->type != CPP_PRAGMA_EOL) |
985 | c_parser_error (parser, "expected end of line"); | |
986 | ||
987 | cpp_ttype token_type; | |
988 | do | |
989 | { | |
990 | c_token *token = c_parser_peek_token (parser); | |
991 | token_type = token->type; | |
992 | if (token_type == CPP_EOF) | |
993 | break; | |
994 | c_parser_consume_token (parser); | |
995 | } | |
996 | while (token_type != CPP_PRAGMA_EOL); | |
b75b98aa | 997 | |
998 | parser->error = false; | |
999 | } | |
1576dec7 | 1000 | |
adcd0e5f | 1001 | /* Skip tokens until we have consumed an entire block, or until we |
1002 | have consumed a non-nested ';'. */ | |
1003 | ||
1004 | static void | |
1005 | c_parser_skip_to_end_of_block_or_statement (c_parser *parser) | |
1006 | { | |
1007 | unsigned nesting_depth = 0; | |
1008 | bool save_error = parser->error; | |
1009 | ||
1010 | while (true) | |
1011 | { | |
1012 | c_token *token; | |
1013 | ||
1014 | /* Peek at the next token. */ | |
1015 | token = c_parser_peek_token (parser); | |
1016 | ||
1017 | switch (token->type) | |
1018 | { | |
1019 | case CPP_EOF: | |
1020 | return; | |
1021 | ||
1022 | case CPP_PRAGMA_EOL: | |
1023 | if (parser->in_pragma) | |
1024 | return; | |
1025 | break; | |
1026 | ||
1027 | case CPP_SEMICOLON: | |
1028 | /* If the next token is a ';', we have reached the | |
1029 | end of the statement. */ | |
1030 | if (!nesting_depth) | |
1031 | { | |
1032 | /* Consume the ';'. */ | |
1033 | c_parser_consume_token (parser); | |
1034 | goto finished; | |
1035 | } | |
1036 | break; | |
1037 | ||
1038 | case CPP_CLOSE_BRACE: | |
1039 | /* If the next token is a non-nested '}', then we have | |
1040 | reached the end of the current block. */ | |
1041 | if (nesting_depth == 0 || --nesting_depth == 0) | |
1042 | { | |
1043 | c_parser_consume_token (parser); | |
1044 | goto finished; | |
1045 | } | |
1046 | break; | |
1047 | ||
1048 | case CPP_OPEN_BRACE: | |
1049 | /* If it the next token is a '{', then we are entering a new | |
1050 | block. Consume the entire block. */ | |
1051 | ++nesting_depth; | |
1052 | break; | |
1053 | ||
1054 | case CPP_PRAGMA: | |
1055 | /* If we see a pragma, consume the whole thing at once. We | |
1056 | have some safeguards against consuming pragmas willy-nilly. | |
1057 | Normally, we'd expect to be here with parser->error set, | |
1058 | which disables these safeguards. But it's possible to get | |
1059 | here for secondary error recovery, after parser->error has | |
1060 | been cleared. */ | |
1061 | c_parser_consume_pragma (parser); | |
1062 | c_parser_skip_to_pragma_eol (parser); | |
1063 | parser->error = save_error; | |
1064 | continue; | |
3ab72ef0 | 1065 | |
1066 | default: | |
1067 | break; | |
adcd0e5f | 1068 | } |
1069 | ||
1070 | c_parser_consume_token (parser); | |
1071 | } | |
1072 | ||
1073 | finished: | |
1074 | parser->error = false; | |
1075 | } | |
1076 | ||
caefd295 | 1077 | /* CPP's options (initialized by c-opts.c). */ |
1078 | extern cpp_options *cpp_opts; | |
1079 | ||
1576dec7 | 1080 | /* Save the warning flags which are controlled by __extension__. */ |
1081 | ||
1082 | static inline int | |
1083 | disable_extension_diagnostics (void) | |
1084 | { | |
1085 | int ret = (pedantic | |
1086 | | (warn_pointer_arith << 1) | |
1087 | | (warn_traditional << 2) | |
caefd295 | 1088 | | (flag_iso << 3) |
0b09525f | 1089 | | (warn_long_long << 4) |
4e9eacab | 1090 | | (warn_cxx_compat << 5) |
890c2e2f | 1091 | | (warn_overlength_strings << 6) |
806fe15e | 1092 | /* warn_c90_c99_compat has three states: -1/0/1, so we must |
1093 | play tricks to properly restore it. */ | |
1094 | | ((warn_c90_c99_compat == 1) << 7) | |
508ea33a | 1095 | | ((warn_c90_c99_compat == -1) << 8) |
1096 | /* Similarly for warn_c99_c11_compat. */ | |
1097 | | ((warn_c99_c11_compat == 1) << 9) | |
1098 | | ((warn_c99_c11_compat == -1) << 10) | |
1099 | ); | |
5ae82d58 | 1100 | cpp_opts->cpp_pedantic = pedantic = 0; |
1576dec7 | 1101 | warn_pointer_arith = 0; |
5ae82d58 | 1102 | cpp_opts->cpp_warn_traditional = warn_traditional = 0; |
1576dec7 | 1103 | flag_iso = 0; |
5ae82d58 | 1104 | cpp_opts->cpp_warn_long_long = warn_long_long = 0; |
0b09525f | 1105 | warn_cxx_compat = 0; |
4e9eacab | 1106 | warn_overlength_strings = 0; |
890c2e2f | 1107 | warn_c90_c99_compat = 0; |
508ea33a | 1108 | warn_c99_c11_compat = 0; |
1576dec7 | 1109 | return ret; |
1110 | } | |
1111 | ||
1112 | /* Restore the warning flags which are controlled by __extension__. | |
1113 | FLAGS is the return value from disable_extension_diagnostics. */ | |
1114 | ||
1115 | static inline void | |
1116 | restore_extension_diagnostics (int flags) | |
1117 | { | |
5ae82d58 | 1118 | cpp_opts->cpp_pedantic = pedantic = flags & 1; |
1576dec7 | 1119 | warn_pointer_arith = (flags >> 1) & 1; |
5ae82d58 | 1120 | cpp_opts->cpp_warn_traditional = warn_traditional = (flags >> 2) & 1; |
1576dec7 | 1121 | flag_iso = (flags >> 3) & 1; |
5ae82d58 | 1122 | cpp_opts->cpp_warn_long_long = warn_long_long = (flags >> 4) & 1; |
0b09525f | 1123 | warn_cxx_compat = (flags >> 5) & 1; |
4e9eacab | 1124 | warn_overlength_strings = (flags >> 6) & 1; |
806fe15e | 1125 | /* See above for why is this needed. */ |
1126 | warn_c90_c99_compat = (flags >> 7) & 1 ? 1 : ((flags >> 8) & 1 ? -1 : 0); | |
508ea33a | 1127 | warn_c99_c11_compat = (flags >> 9) & 1 ? 1 : ((flags >> 10) & 1 ? -1 : 0); |
1576dec7 | 1128 | } |
1129 | ||
1130 | /* Possibly kinds of declarator to parse. */ | |
6dc50383 | 1131 | enum c_dtr_syn { |
1576dec7 | 1132 | /* A normal declarator with an identifier. */ |
1133 | C_DTR_NORMAL, | |
1134 | /* An abstract declarator (maybe empty). */ | |
1135 | C_DTR_ABSTRACT, | |
1136 | /* A parameter declarator: may be either, but after a type name does | |
1137 | not redeclare a typedef name as an identifier if it can | |
1138 | alternatively be interpreted as a typedef name; see DR#009, | |
1139 | applied in C90 TC1, omitted from C99 and reapplied in C99 TC2 | |
1140 | following DR#249. For example, given a typedef T, "int T" and | |
1141 | "int *T" are valid parameter declarations redeclaring T, while | |
1142 | "int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are | |
1143 | abstract declarators rather than involving redundant parentheses; | |
1144 | the same applies with attributes inside the parentheses before | |
1145 | "T". */ | |
1146 | C_DTR_PARM | |
6dc50383 | 1147 | }; |
1576dec7 | 1148 | |
2169f33b | 1149 | /* The binary operation precedence levels, where 0 is a dummy lowest level |
1150 | used for the bottom of the stack. */ | |
1151 | enum c_parser_prec { | |
1152 | PREC_NONE, | |
1153 | PREC_LOGOR, | |
1154 | PREC_LOGAND, | |
1155 | PREC_BITOR, | |
1156 | PREC_BITXOR, | |
1157 | PREC_BITAND, | |
1158 | PREC_EQ, | |
1159 | PREC_REL, | |
1160 | PREC_SHIFT, | |
1161 | PREC_ADD, | |
1162 | PREC_MULT, | |
1163 | NUM_PRECS | |
1164 | }; | |
1165 | ||
1576dec7 | 1166 | static void c_parser_external_declaration (c_parser *); |
1167 | static void c_parser_asm_definition (c_parser *); | |
f80e7755 | 1168 | static void c_parser_declaration_or_fndef (c_parser *, bool, bool, bool, |
bc7bff74 | 1169 | bool, bool, tree *, vec<c_token>); |
f80e7755 | 1170 | static void c_parser_static_assert_declaration_no_semi (c_parser *); |
1171 | static void c_parser_static_assert_declaration (c_parser *); | |
1576dec7 | 1172 | static void c_parser_declspecs (c_parser *, struct c_declspecs *, bool, bool, |
4fba5eb9 | 1173 | bool, bool, bool, enum c_lookahead_kind); |
1576dec7 | 1174 | static struct c_typespec c_parser_enum_specifier (c_parser *); |
1175 | static struct c_typespec c_parser_struct_or_union_specifier (c_parser *); | |
1176 | static tree c_parser_struct_declaration (c_parser *); | |
1177 | static struct c_typespec c_parser_typeof_specifier (c_parser *); | |
83e25171 | 1178 | static tree c_parser_alignas_specifier (c_parser *); |
1576dec7 | 1179 | static struct c_declarator *c_parser_declarator (c_parser *, bool, c_dtr_syn, |
1180 | bool *); | |
1181 | static struct c_declarator *c_parser_direct_declarator (c_parser *, bool, | |
1182 | c_dtr_syn, bool *); | |
1183 | static struct c_declarator *c_parser_direct_declarator_inner (c_parser *, | |
1184 | bool, | |
1185 | struct c_declarator *); | |
1186 | static struct c_arg_info *c_parser_parms_declarator (c_parser *, bool, tree); | |
4232a958 | 1187 | static struct c_arg_info *c_parser_parms_list_declarator (c_parser *, tree, |
1188 | tree); | |
1576dec7 | 1189 | static struct c_parm *c_parser_parameter_declaration (c_parser *, tree); |
1190 | static tree c_parser_simple_asm_expr (c_parser *); | |
1191 | static tree c_parser_attributes (c_parser *); | |
1192 | static struct c_type_name *c_parser_type_name (c_parser *); | |
1193 | static struct c_expr c_parser_initializer (c_parser *); | |
1194 | static struct c_expr c_parser_braced_init (c_parser *, tree, bool); | |
759791ee | 1195 | static void c_parser_initelt (c_parser *, struct obstack *); |
1196 | static void c_parser_initval (c_parser *, struct c_expr *, | |
1197 | struct obstack *); | |
1576dec7 | 1198 | static tree c_parser_compound_statement (c_parser *); |
1199 | static void c_parser_compound_statement_nostart (c_parser *); | |
1200 | static void c_parser_label (c_parser *); | |
1201 | static void c_parser_statement (c_parser *); | |
ef17a71a | 1202 | static void c_parser_statement_after_labels (c_parser *, vec<tree> * = NULL); |
1203 | static void c_parser_if_statement (c_parser *, vec<tree> *); | |
1576dec7 | 1204 | static void c_parser_switch_statement (c_parser *); |
4c90c04c | 1205 | static void c_parser_while_statement (c_parser *, bool); |
1206 | static void c_parser_do_statement (c_parser *, bool); | |
4644b593 | 1207 | static void c_parser_for_statement (c_parser *, bool); |
1576dec7 | 1208 | static tree c_parser_asm_statement (c_parser *); |
035b65e2 | 1209 | static tree c_parser_asm_operands (c_parser *); |
78f55ca8 | 1210 | static tree c_parser_asm_goto_operands (c_parser *); |
1576dec7 | 1211 | static tree c_parser_asm_clobbers (c_parser *); |
bc7bff74 | 1212 | static struct c_expr c_parser_expr_no_commas (c_parser *, struct c_expr *, |
1213 | tree = NULL_TREE); | |
1576dec7 | 1214 | static struct c_expr c_parser_conditional_expression (c_parser *, |
bc7bff74 | 1215 | struct c_expr *, tree); |
2169f33b | 1216 | static struct c_expr c_parser_binary_expression (c_parser *, struct c_expr *, |
bc7bff74 | 1217 | tree); |
1576dec7 | 1218 | static struct c_expr c_parser_cast_expression (c_parser *, struct c_expr *); |
1219 | static struct c_expr c_parser_unary_expression (c_parser *); | |
1220 | static struct c_expr c_parser_sizeof_expression (c_parser *); | |
1221 | static struct c_expr c_parser_alignof_expression (c_parser *); | |
1222 | static struct c_expr c_parser_postfix_expression (c_parser *); | |
1223 | static struct c_expr c_parser_postfix_expression_after_paren_type (c_parser *, | |
0b09525f | 1224 | struct c_type_name *, |
1225 | location_t); | |
1576dec7 | 1226 | static struct c_expr c_parser_postfix_expression_after_primary (c_parser *, |
e60a6f7b | 1227 | location_t loc, |
1576dec7 | 1228 | struct c_expr); |
4c0315d0 | 1229 | static tree c_parser_transaction (c_parser *, enum rid); |
1230 | static struct c_expr c_parser_transaction_expression (c_parser *, enum rid); | |
1231 | static tree c_parser_transaction_cancel (c_parser *); | |
1576dec7 | 1232 | static struct c_expr c_parser_expression (c_parser *); |
f14c8207 | 1233 | static struct c_expr c_parser_expression_conv (c_parser *); |
f1f41a6c | 1234 | static vec<tree, va_gc> *c_parser_expr_list (c_parser *, bool, bool, |
1235 | vec<tree, va_gc> **, location_t *, | |
305d96bc | 1236 | tree *, vec<location_t> *, |
1237 | unsigned int * = NULL); | |
ca4c3545 | 1238 | static void c_parser_oacc_enter_exit_data (c_parser *, bool); |
1239 | static void c_parser_oacc_update (c_parser *); | |
1240 | static tree c_parser_oacc_loop (location_t, c_parser *, char *); | |
1e8e9920 | 1241 | static void c_parser_omp_construct (c_parser *); |
1242 | static void c_parser_omp_threadprivate (c_parser *); | |
1243 | static void c_parser_omp_barrier (c_parser *); | |
1244 | static void c_parser_omp_flush (c_parser *); | |
ca4c3545 | 1245 | static tree c_parser_omp_for_loop (location_t, c_parser *, enum tree_code, |
1246 | tree, tree *); | |
fd6481cf | 1247 | static void c_parser_omp_taskwait (c_parser *); |
2169f33b | 1248 | static void c_parser_omp_taskyield (c_parser *); |
bc7bff74 | 1249 | static void c_parser_omp_cancel (c_parser *); |
1250 | static void c_parser_omp_cancellation_point (c_parser *); | |
1576dec7 | 1251 | |
bc7bff74 | 1252 | enum pragma_context { pragma_external, pragma_struct, pragma_param, |
1253 | pragma_stmt, pragma_compound }; | |
b75b98aa | 1254 | static bool c_parser_pragma (c_parser *, enum pragma_context); |
bc7bff74 | 1255 | static bool c_parser_omp_target (c_parser *, enum pragma_context); |
1256 | static void c_parser_omp_end_declare_target (c_parser *); | |
1257 | static void c_parser_omp_declare (c_parser *, enum pragma_context); | |
43895be5 | 1258 | static bool c_parser_omp_ordered (c_parser *, enum pragma_context); |
b75b98aa | 1259 | |
1576dec7 | 1260 | /* These Objective-C parser functions are only ever called when |
1261 | compiling Objective-C. */ | |
a336eb4b | 1262 | static void c_parser_objc_class_definition (c_parser *, tree); |
1576dec7 | 1263 | static void c_parser_objc_class_instance_variables (c_parser *); |
1264 | static void c_parser_objc_class_declaration (c_parser *); | |
1265 | static void c_parser_objc_alias_declaration (c_parser *); | |
a336eb4b | 1266 | static void c_parser_objc_protocol_definition (c_parser *, tree); |
45b2b110 | 1267 | static bool c_parser_objc_method_type (c_parser *); |
1576dec7 | 1268 | static void c_parser_objc_method_definition (c_parser *); |
1269 | static void c_parser_objc_methodprotolist (c_parser *); | |
1270 | static void c_parser_objc_methodproto (c_parser *); | |
4232a958 | 1271 | static tree c_parser_objc_method_decl (c_parser *, bool, tree *, tree *); |
1576dec7 | 1272 | static tree c_parser_objc_type_name (c_parser *); |
1273 | static tree c_parser_objc_protocol_refs (c_parser *); | |
b3d2d312 | 1274 | static void c_parser_objc_try_catch_finally_statement (c_parser *); |
1576dec7 | 1275 | static void c_parser_objc_synchronized_statement (c_parser *); |
1276 | static tree c_parser_objc_selector (c_parser *); | |
1277 | static tree c_parser_objc_selector_arg (c_parser *); | |
1278 | static tree c_parser_objc_receiver (c_parser *); | |
1279 | static tree c_parser_objc_message_args (c_parser *); | |
1280 | static tree c_parser_objc_keywordexpr (c_parser *); | |
1d894bcf | 1281 | static void c_parser_objc_at_property_declaration (c_parser *); |
e1f293c0 | 1282 | static void c_parser_objc_at_synthesize_declaration (c_parser *); |
1283 | static void c_parser_objc_at_dynamic_declaration (c_parser *); | |
86c110ac | 1284 | static bool c_parser_objc_diagnose_bad_element_prefix |
a336eb4b | 1285 | (c_parser *, struct c_declspecs *); |
1576dec7 | 1286 | |
f2697631 | 1287 | /* Cilk Plus supporting routines. */ |
1288 | static void c_parser_cilk_simd (c_parser *); | |
40750995 | 1289 | static void c_parser_cilk_for (c_parser *, tree); |
f2697631 | 1290 | static bool c_parser_cilk_verify_simd (c_parser *, enum pragma_context); |
3c6d4197 | 1291 | static tree c_parser_array_notation (location_t, c_parser *, tree, tree); |
74acc703 | 1292 | static tree c_parser_cilk_clause_vectorlength (c_parser *, tree, bool); |
40750995 | 1293 | static void c_parser_cilk_grainsize (c_parser *); |
3c6d4197 | 1294 | |
1576dec7 | 1295 | /* Parse a translation unit (C90 6.7, C99 6.9). |
1296 | ||
1297 | translation-unit: | |
1298 | external-declarations | |
1299 | ||
1300 | external-declarations: | |
1301 | external-declaration | |
1302 | external-declarations external-declaration | |
1303 | ||
1304 | GNU extensions: | |
1305 | ||
1306 | translation-unit: | |
1307 | empty | |
1308 | */ | |
1309 | ||
1310 | static void | |
1311 | c_parser_translation_unit (c_parser *parser) | |
1312 | { | |
1313 | if (c_parser_next_token_is (parser, CPP_EOF)) | |
1314 | { | |
29438999 | 1315 | pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic, |
21ca8540 | 1316 | "ISO C forbids an empty translation unit"); |
1576dec7 | 1317 | } |
1318 | else | |
1319 | { | |
1320 | void *obstack_position = obstack_alloc (&parser_obstack, 0); | |
3ae3a17f | 1321 | mark_valid_location_for_stdc_pragma (false); |
1576dec7 | 1322 | do |
1323 | { | |
1324 | ggc_collect (); | |
1325 | c_parser_external_declaration (parser); | |
1326 | obstack_free (&parser_obstack, obstack_position); | |
1327 | } | |
1328 | while (c_parser_next_token_is_not (parser, CPP_EOF)); | |
1329 | } | |
1330 | } | |
1331 | ||
1332 | /* Parse an external declaration (C90 6.7, C99 6.9). | |
1333 | ||
1334 | external-declaration: | |
1335 | function-definition | |
1336 | declaration | |
1337 | ||
1338 | GNU extensions: | |
1339 | ||
1340 | external-declaration: | |
1341 | asm-definition | |
1342 | ; | |
1343 | __extension__ external-declaration | |
1344 | ||
1345 | Objective-C: | |
1346 | ||
1347 | external-declaration: | |
1348 | objc-class-definition | |
1349 | objc-class-declaration | |
1350 | objc-alias-declaration | |
1351 | objc-protocol-definition | |
1352 | objc-method-definition | |
1353 | @end | |
1354 | */ | |
1355 | ||
1356 | static void | |
1357 | c_parser_external_declaration (c_parser *parser) | |
1358 | { | |
1359 | int ext; | |
1360 | switch (c_parser_peek_token (parser)->type) | |
1361 | { | |
1362 | case CPP_KEYWORD: | |
1363 | switch (c_parser_peek_token (parser)->keyword) | |
1364 | { | |
1365 | case RID_EXTENSION: | |
1366 | ext = disable_extension_diagnostics (); | |
1367 | c_parser_consume_token (parser); | |
1368 | c_parser_external_declaration (parser); | |
1369 | restore_extension_diagnostics (ext); | |
1370 | break; | |
1371 | case RID_ASM: | |
1372 | c_parser_asm_definition (parser); | |
1373 | break; | |
1374 | case RID_AT_INTERFACE: | |
1375 | case RID_AT_IMPLEMENTATION: | |
1376 | gcc_assert (c_dialect_objc ()); | |
a336eb4b | 1377 | c_parser_objc_class_definition (parser, NULL_TREE); |
1576dec7 | 1378 | break; |
e5c75ac3 | 1379 | case RID_AT_CLASS: |
1576dec7 | 1380 | gcc_assert (c_dialect_objc ()); |
1381 | c_parser_objc_class_declaration (parser); | |
1382 | break; | |
1383 | case RID_AT_ALIAS: | |
1384 | gcc_assert (c_dialect_objc ()); | |
1385 | c_parser_objc_alias_declaration (parser); | |
1386 | break; | |
1387 | case RID_AT_PROTOCOL: | |
1388 | gcc_assert (c_dialect_objc ()); | |
a336eb4b | 1389 | c_parser_objc_protocol_definition (parser, NULL_TREE); |
1576dec7 | 1390 | break; |
86c110ac | 1391 | case RID_AT_PROPERTY: |
1392 | gcc_assert (c_dialect_objc ()); | |
1d894bcf | 1393 | c_parser_objc_at_property_declaration (parser); |
86c110ac | 1394 | break; |
e1f293c0 | 1395 | case RID_AT_SYNTHESIZE: |
1396 | gcc_assert (c_dialect_objc ()); | |
1397 | c_parser_objc_at_synthesize_declaration (parser); | |
1398 | break; | |
1399 | case RID_AT_DYNAMIC: | |
1400 | gcc_assert (c_dialect_objc ()); | |
1401 | c_parser_objc_at_dynamic_declaration (parser); | |
1402 | break; | |
1576dec7 | 1403 | case RID_AT_END: |
1404 | gcc_assert (c_dialect_objc ()); | |
1405 | c_parser_consume_token (parser); | |
1406 | objc_finish_implementation (); | |
1407 | break; | |
1408 | default: | |
1409 | goto decl_or_fndef; | |
1410 | } | |
1411 | break; | |
1412 | case CPP_SEMICOLON: | |
29438999 | 1413 | pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic, |
21ca8540 | 1414 | "ISO C does not allow extra %<;%> outside of a function"); |
1576dec7 | 1415 | c_parser_consume_token (parser); |
1416 | break; | |
b75b98aa | 1417 | case CPP_PRAGMA: |
3ae3a17f | 1418 | mark_valid_location_for_stdc_pragma (true); |
b75b98aa | 1419 | c_parser_pragma (parser, pragma_external); |
3ae3a17f | 1420 | mark_valid_location_for_stdc_pragma (false); |
b75b98aa | 1421 | break; |
1576dec7 | 1422 | case CPP_PLUS: |
1423 | case CPP_MINUS: | |
1424 | if (c_dialect_objc ()) | |
1425 | { | |
1426 | c_parser_objc_method_definition (parser); | |
1427 | break; | |
1428 | } | |
1429 | /* Else fall through, and yield a syntax error trying to parse | |
1430 | as a declaration or function definition. */ | |
1431 | default: | |
1432 | decl_or_fndef: | |
a336eb4b | 1433 | /* A declaration or a function definition (or, in Objective-C, |
1434 | an @interface or @protocol with prefix attributes). We can | |
1435 | only tell which after parsing the declaration specifiers, if | |
1436 | any, and the first declarator. */ | |
bc7bff74 | 1437 | c_parser_declaration_or_fndef (parser, true, true, true, false, true, |
1438 | NULL, vNULL); | |
1576dec7 | 1439 | break; |
1440 | } | |
1441 | } | |
1442 | ||
bc7bff74 | 1443 | static void c_finish_omp_declare_simd (c_parser *, tree, tree, vec<c_token>); |
1444 | ||
1576dec7 | 1445 | /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99 |
1446 | 6.7, 6.9.1). If FNDEF_OK is true, a function definition is | |
1447 | accepted; otherwise (old-style parameter declarations) only other | |
f80e7755 | 1448 | declarations are accepted. If STATIC_ASSERT_OK is true, a static |
1449 | assertion is accepted; otherwise (old-style parameter declarations) | |
1450 | it is not. If NESTED is true, we are inside a function or parsing | |
1451 | old-style parameter declarations; any functions encountered are | |
1452 | nested functions and declaration specifiers are required; otherwise | |
1453 | we are at top level and functions are normal functions and | |
1454 | declaration specifiers may be optional. If EMPTY_OK is true, empty | |
1455 | declarations are OK (subject to all other constraints); otherwise | |
1456 | (old-style parameter declarations) they are diagnosed. If | |
1457 | START_ATTR_OK is true, the declaration specifiers may start with | |
1458 | attributes; otherwise they may not. | |
0a65c3bb | 1459 | OBJC_FOREACH_OBJECT_DECLARATION can be used to get back the parsed |
1460 | declaration when parsing an Objective-C foreach statement. | |
1576dec7 | 1461 | |
1462 | declaration: | |
1463 | declaration-specifiers init-declarator-list[opt] ; | |
f80e7755 | 1464 | static_assert-declaration |
1576dec7 | 1465 | |
1466 | function-definition: | |
1467 | declaration-specifiers[opt] declarator declaration-list[opt] | |
1468 | compound-statement | |
1469 | ||
1470 | declaration-list: | |
1471 | declaration | |
1472 | declaration-list declaration | |
1473 | ||
1474 | init-declarator-list: | |
1475 | init-declarator | |
1476 | init-declarator-list , init-declarator | |
1477 | ||
1478 | init-declarator: | |
1479 | declarator simple-asm-expr[opt] attributes[opt] | |
1480 | declarator simple-asm-expr[opt] attributes[opt] = initializer | |
1481 | ||
1482 | GNU extensions: | |
1483 | ||
1484 | nested-function-definition: | |
1485 | declaration-specifiers declarator declaration-list[opt] | |
1486 | compound-statement | |
1487 | ||
a336eb4b | 1488 | Objective-C: |
1489 | attributes objc-class-definition | |
1490 | attributes objc-category-definition | |
1491 | attributes objc-protocol-definition | |
1492 | ||
1576dec7 | 1493 | The simple-asm-expr and attributes are GNU extensions. |
1494 | ||
1495 | This function does not handle __extension__; that is handled in its | |
1496 | callers. ??? Following the old parser, __extension__ may start | |
1497 | external declarations, declarations in functions and declarations | |
1498 | at the start of "for" loops, but not old-style parameter | |
1499 | declarations. | |
1500 | ||
1501 | C99 requires declaration specifiers in a function definition; the | |
1502 | absence is diagnosed through the diagnosis of implicit int. In GNU | |
1503 | C we also allow but diagnose declarations without declaration | |
1504 | specifiers, but only at top level (elsewhere they conflict with | |
1e8e9920 | 1505 | other syntax). |
48e1416a | 1506 | |
0a65c3bb | 1507 | In Objective-C, declarations of the looping variable in a foreach |
1508 | statement are exceptionally terminated by 'in' (for example, 'for | |
1509 | (NSObject *object in array) { ... }'). | |
1510 | ||
1e8e9920 | 1511 | OpenMP: |
48e1416a | 1512 | |
1e8e9920 | 1513 | declaration: |
1514 | threadprivate-directive */ | |
1576dec7 | 1515 | |
1516 | static void | |
f80e7755 | 1517 | c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok, |
1518 | bool static_assert_ok, bool empty_ok, | |
0a65c3bb | 1519 | bool nested, bool start_attr_ok, |
bc7bff74 | 1520 | tree *objc_foreach_object_declaration, |
1521 | vec<c_token> omp_declare_simd_clauses) | |
1576dec7 | 1522 | { |
1523 | struct c_declspecs *specs; | |
1524 | tree prefix_attrs; | |
1525 | tree all_prefix_attrs; | |
1526 | bool diagnosed_no_specs = false; | |
be9eba16 | 1527 | location_t here = c_parser_peek_token (parser)->location; |
b75b98aa | 1528 | |
f80e7755 | 1529 | if (static_assert_ok |
1530 | && c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT)) | |
1531 | { | |
1532 | c_parser_static_assert_declaration (parser); | |
1533 | return; | |
1534 | } | |
1576dec7 | 1535 | specs = build_null_declspecs (); |
71bb4bc6 | 1536 | |
1537 | /* Try to detect an unknown type name when we have "A B" or "A *B". */ | |
1538 | if (c_parser_peek_token (parser)->type == CPP_NAME | |
1539 | && c_parser_peek_token (parser)->id_kind == C_ID_ID | |
1540 | && (c_parser_peek_2nd_token (parser)->type == CPP_NAME | |
1541 | || c_parser_peek_2nd_token (parser)->type == CPP_MULT) | |
1542 | && (!nested || !lookup_name (c_parser_peek_token (parser)->value))) | |
1543 | { | |
03e8b174 | 1544 | tree name = c_parser_peek_token (parser)->value; |
1545 | error_at (here, "unknown type name %qE", name); | |
1546 | /* Give a hint to the user. This is not C++ with its implicit | |
1547 | typedef. */ | |
1548 | if (tag_exists_p (RECORD_TYPE, name)) | |
1549 | inform (here, "use %<struct%> keyword to refer to the type"); | |
1550 | else if (tag_exists_p (UNION_TYPE, name)) | |
1551 | inform (here, "use %<union%> keyword to refer to the type"); | |
1552 | else if (tag_exists_p (ENUMERAL_TYPE, name)) | |
1553 | inform (here, "use %<enum%> keyword to refer to the type"); | |
71bb4bc6 | 1554 | |
1555 | /* Parse declspecs normally to get a correct pointer type, but avoid | |
21e609c5 | 1556 | a further "fails to be a type name" error. Refuse nested functions |
1557 | since it is not how the user likely wants us to recover. */ | |
71bb4bc6 | 1558 | c_parser_peek_token (parser)->type = CPP_KEYWORD; |
1559 | c_parser_peek_token (parser)->keyword = RID_VOID; | |
1560 | c_parser_peek_token (parser)->value = error_mark_node; | |
21e609c5 | 1561 | fndef_ok = !nested; |
71bb4bc6 | 1562 | } |
1563 | ||
43d03c23 | 1564 | c_parser_declspecs (parser, specs, true, true, start_attr_ok, |
4fba5eb9 | 1565 | true, true, cla_nonabstract_decl); |
1576dec7 | 1566 | if (parser->error) |
1567 | { | |
1568 | c_parser_skip_to_end_of_block_or_statement (parser); | |
1569 | return; | |
1570 | } | |
1571 | if (nested && !specs->declspecs_seen_p) | |
1572 | { | |
1573 | c_parser_error (parser, "expected declaration specifiers"); | |
1574 | c_parser_skip_to_end_of_block_or_statement (parser); | |
1575 | return; | |
1576 | } | |
1577 | finish_declspecs (specs); | |
4fba5eb9 | 1578 | bool auto_type_p = specs->typespec_word == cts_auto_type; |
1576dec7 | 1579 | if (c_parser_next_token_is (parser, CPP_SEMICOLON)) |
1580 | { | |
4fba5eb9 | 1581 | if (auto_type_p) |
1582 | error_at (here, "%<__auto_type%> in empty declaration"); | |
1583 | else if (empty_ok) | |
1576dec7 | 1584 | shadow_tag (specs); |
1585 | else | |
1586 | { | |
1587 | shadow_tag_warned (specs, 1); | |
21ca8540 | 1588 | pedwarn (here, 0, "empty declaration"); |
1576dec7 | 1589 | } |
1590 | c_parser_consume_token (parser); | |
1591 | return; | |
1592 | } | |
b02d8973 | 1593 | |
1594 | /* Provide better error recovery. Note that a type name here is usually | |
1595 | better diagnosed as a redeclaration. */ | |
1596 | if (empty_ok | |
1597 | && specs->typespec_kind == ctsk_tagdef | |
1598 | && c_parser_next_token_starts_declspecs (parser) | |
1599 | && !c_parser_next_token_is (parser, CPP_NAME)) | |
1600 | { | |
1601 | c_parser_error (parser, "expected %<;%>, identifier or %<(%>"); | |
1602 | parser->error = false; | |
1603 | shadow_tag_warned (specs, 1); | |
1604 | return; | |
1605 | } | |
4fba5eb9 | 1606 | else if (c_dialect_objc () && !auto_type_p) |
a336eb4b | 1607 | { |
03fc2271 | 1608 | /* Prefix attributes are an error on method decls. */ |
1609 | switch (c_parser_peek_token (parser)->type) | |
1610 | { | |
1611 | case CPP_PLUS: | |
1612 | case CPP_MINUS: | |
1613 | if (c_parser_objc_diagnose_bad_element_prefix (parser, specs)) | |
1614 | return; | |
1615 | if (specs->attrs) | |
1616 | { | |
1617 | warning_at (c_parser_peek_token (parser)->location, | |
1618 | OPT_Wattributes, | |
1619 | "prefix attributes are ignored for methods"); | |
1620 | specs->attrs = NULL_TREE; | |
1621 | } | |
1622 | if (fndef_ok) | |
1623 | c_parser_objc_method_definition (parser); | |
1624 | else | |
1625 | c_parser_objc_methodproto (parser); | |
1626 | return; | |
1627 | break; | |
1628 | default: | |
1629 | break; | |
1630 | } | |
a336eb4b | 1631 | /* This is where we parse 'attributes @interface ...', |
1632 | 'attributes @implementation ...', 'attributes @protocol ...' | |
1633 | (where attributes could be, for example, __attribute__ | |
1634 | ((deprecated)). | |
1635 | */ | |
1636 | switch (c_parser_peek_token (parser)->keyword) | |
1637 | { | |
1638 | case RID_AT_INTERFACE: | |
1639 | { | |
1640 | if (c_parser_objc_diagnose_bad_element_prefix (parser, specs)) | |
1641 | return; | |
1642 | c_parser_objc_class_definition (parser, specs->attrs); | |
1643 | return; | |
1644 | } | |
1645 | break; | |
1646 | case RID_AT_IMPLEMENTATION: | |
1647 | { | |
1648 | if (c_parser_objc_diagnose_bad_element_prefix (parser, specs)) | |
1649 | return; | |
1650 | if (specs->attrs) | |
1651 | { | |
1652 | warning_at (c_parser_peek_token (parser)->location, | |
1653 | OPT_Wattributes, | |
1654 | "prefix attributes are ignored for implementations"); | |
1655 | specs->attrs = NULL_TREE; | |
1656 | } | |
1657 | c_parser_objc_class_definition (parser, NULL_TREE); | |
1658 | return; | |
1659 | } | |
1660 | break; | |
1661 | case RID_AT_PROTOCOL: | |
1662 | { | |
1663 | if (c_parser_objc_diagnose_bad_element_prefix (parser, specs)) | |
1664 | return; | |
1665 | c_parser_objc_protocol_definition (parser, specs->attrs); | |
1666 | return; | |
1667 | } | |
1668 | break; | |
86c110ac | 1669 | case RID_AT_ALIAS: |
1670 | case RID_AT_CLASS: | |
1671 | case RID_AT_END: | |
1672 | case RID_AT_PROPERTY: | |
1673 | if (specs->attrs) | |
1674 | { | |
3b77900e | 1675 | c_parser_error (parser, "unexpected attribute"); |
86c110ac | 1676 | specs->attrs = NULL; |
1677 | } | |
1678 | break; | |
a336eb4b | 1679 | default: |
1680 | break; | |
1681 | } | |
1682 | } | |
1683 | ||
1576dec7 | 1684 | pending_xref_error (); |
1685 | prefix_attrs = specs->attrs; | |
1686 | all_prefix_attrs = prefix_attrs; | |
1687 | specs->attrs = NULL_TREE; | |
1688 | while (true) | |
1689 | { | |
1690 | struct c_declarator *declarator; | |
1691 | bool dummy = false; | |
6198e8f6 | 1692 | timevar_id_t tv; |
1576dec7 | 1693 | tree fnbody; |
1694 | /* Declaring either one or more declarators (in which case we | |
1695 | should diagnose if there were no declaration specifiers) or a | |
1696 | function definition (in which case the diagnostic for | |
1697 | implicit int suffices). */ | |
ae5ead32 | 1698 | declarator = c_parser_declarator (parser, |
1699 | specs->typespec_kind != ctsk_none, | |
1576dec7 | 1700 | C_DTR_NORMAL, &dummy); |
1701 | if (declarator == NULL) | |
1702 | { | |
74acc703 | 1703 | if (omp_declare_simd_clauses.exists () |
1704 | || !vec_safe_is_empty (parser->cilk_simd_fn_tokens)) | |
bc7bff74 | 1705 | c_finish_omp_declare_simd (parser, NULL_TREE, NULL_TREE, |
1706 | omp_declare_simd_clauses); | |
1576dec7 | 1707 | c_parser_skip_to_end_of_block_or_statement (parser); |
1708 | return; | |
1709 | } | |
4fba5eb9 | 1710 | if (auto_type_p && declarator->kind != cdk_id) |
1711 | { | |
1712 | error_at (here, | |
1713 | "%<__auto_type%> requires a plain identifier" | |
1714 | " as declarator"); | |
1715 | c_parser_skip_to_end_of_block_or_statement (parser); | |
1716 | return; | |
1717 | } | |
1576dec7 | 1718 | if (c_parser_next_token_is (parser, CPP_EQ) |
1719 | || c_parser_next_token_is (parser, CPP_COMMA) | |
1720 | || c_parser_next_token_is (parser, CPP_SEMICOLON) | |
1721 | || c_parser_next_token_is_keyword (parser, RID_ASM) | |
0a65c3bb | 1722 | || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE) |
1723 | || c_parser_next_token_is_keyword (parser, RID_IN)) | |
1576dec7 | 1724 | { |
1725 | tree asm_name = NULL_TREE; | |
1726 | tree postfix_attrs = NULL_TREE; | |
1727 | if (!diagnosed_no_specs && !specs->declspecs_seen_p) | |
1728 | { | |
1729 | diagnosed_no_specs = true; | |
21ca8540 | 1730 | pedwarn (here, 0, "data definition has no type or storage class"); |
1576dec7 | 1731 | } |
1732 | /* Having seen a data definition, there cannot now be a | |
1733 | function definition. */ | |
1734 | fndef_ok = false; | |
1735 | if (c_parser_next_token_is_keyword (parser, RID_ASM)) | |
1736 | asm_name = c_parser_simple_asm_expr (parser); | |
1737 | if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)) | |
d44f2f7c | 1738 | { |
1739 | postfix_attrs = c_parser_attributes (parser); | |
1740 | if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) | |
1741 | { | |
1742 | /* This means there is an attribute specifier after | |
1743 | the declarator in a function definition. Provide | |
1744 | some more information for the user. */ | |
1745 | error_at (here, "attributes should be specified before the " | |
1746 | "declarator in a function definition"); | |
1747 | c_parser_skip_to_end_of_block_or_statement (parser); | |
1748 | return; | |
1749 | } | |
1750 | } | |
1576dec7 | 1751 | if (c_parser_next_token_is (parser, CPP_EQ)) |
1752 | { | |
1753 | tree d; | |
1754 | struct c_expr init; | |
e60a6f7b | 1755 | location_t init_loc; |
1576dec7 | 1756 | c_parser_consume_token (parser); |
4fba5eb9 | 1757 | if (auto_type_p) |
1758 | { | |
1759 | start_init (NULL_TREE, asm_name, global_bindings_p ()); | |
1760 | init_loc = c_parser_peek_token (parser)->location; | |
1761 | init = c_parser_expr_no_commas (parser, NULL); | |
1762 | if (TREE_CODE (init.value) == COMPONENT_REF | |
1763 | && DECL_C_BIT_FIELD (TREE_OPERAND (init.value, 1))) | |
1764 | error_at (here, | |
1765 | "%<__auto_type%> used with a bit-field" | |
1766 | " initializer"); | |
1767 | init = convert_lvalue_to_rvalue (init_loc, init, true, true); | |
1768 | tree init_type = TREE_TYPE (init.value); | |
45c5b823 | 1769 | /* As with typeof, remove all qualifiers from atomic types. */ |
4fba5eb9 | 1770 | if (init_type != error_mark_node && TYPE_ATOMIC (init_type)) |
1771 | init_type | |
45c5b823 | 1772 | = c_build_qualified_type (init_type, TYPE_UNQUALIFIED); |
4fba5eb9 | 1773 | bool vm_type = variably_modified_type_p (init_type, |
1774 | NULL_TREE); | |
1775 | if (vm_type) | |
1776 | init.value = c_save_expr (init.value); | |
1777 | finish_init (); | |
1778 | specs->typespec_kind = ctsk_typeof; | |
1779 | specs->locations[cdw_typedef] = init_loc; | |
1780 | specs->typedef_p = true; | |
1781 | specs->type = init_type; | |
1782 | if (vm_type) | |
1783 | { | |
1784 | bool maybe_const = true; | |
1785 | tree type_expr = c_fully_fold (init.value, false, | |
1786 | &maybe_const); | |
1787 | specs->expr_const_operands &= maybe_const; | |
1788 | if (specs->expr) | |
1789 | specs->expr = build2 (COMPOUND_EXPR, | |
1790 | TREE_TYPE (type_expr), | |
1791 | specs->expr, type_expr); | |
1792 | else | |
1793 | specs->expr = type_expr; | |
1794 | } | |
1795 | d = start_decl (declarator, specs, true, | |
1796 | chainon (postfix_attrs, all_prefix_attrs)); | |
1797 | if (!d) | |
1798 | d = error_mark_node; | |
74acc703 | 1799 | if (omp_declare_simd_clauses.exists () |
1800 | || !vec_safe_is_empty (parser->cilk_simd_fn_tokens)) | |
4fba5eb9 | 1801 | c_finish_omp_declare_simd (parser, d, NULL_TREE, |
1802 | omp_declare_simd_clauses); | |
1803 | } | |
1804 | else | |
1805 | { | |
1806 | /* The declaration of the variable is in effect while | |
1807 | its initializer is parsed. */ | |
1808 | d = start_decl (declarator, specs, true, | |
1809 | chainon (postfix_attrs, all_prefix_attrs)); | |
1810 | if (!d) | |
1811 | d = error_mark_node; | |
74acc703 | 1812 | if (omp_declare_simd_clauses.exists () |
1813 | || !vec_safe_is_empty (parser->cilk_simd_fn_tokens)) | |
4fba5eb9 | 1814 | c_finish_omp_declare_simd (parser, d, NULL_TREE, |
1815 | omp_declare_simd_clauses); | |
1816 | start_init (d, asm_name, global_bindings_p ()); | |
1817 | init_loc = c_parser_peek_token (parser)->location; | |
1818 | init = c_parser_initializer (parser); | |
1819 | finish_init (); | |
1820 | } | |
1576dec7 | 1821 | if (d != error_mark_node) |
1822 | { | |
c9e51d25 | 1823 | maybe_warn_string_init (init_loc, TREE_TYPE (d), init); |
e60a6f7b | 1824 | finish_decl (d, init_loc, init.value, |
c9e51d25 | 1825 | init.original_type, asm_name); |
1576dec7 | 1826 | } |
1827 | } | |
1828 | else | |
1829 | { | |
4fba5eb9 | 1830 | if (auto_type_p) |
1831 | { | |
1832 | error_at (here, | |
1833 | "%<__auto_type%> requires an initialized " | |
1834 | "data declaration"); | |
1835 | c_parser_skip_to_end_of_block_or_statement (parser); | |
1836 | return; | |
1837 | } | |
1576dec7 | 1838 | tree d = start_decl (declarator, specs, false, |
1839 | chainon (postfix_attrs, | |
1840 | all_prefix_attrs)); | |
74acc703 | 1841 | if (omp_declare_simd_clauses.exists () |
1842 | || !vec_safe_is_empty (parser->cilk_simd_fn_tokens)) | |
bc7bff74 | 1843 | { |
1844 | tree parms = NULL_TREE; | |
1845 | if (d && TREE_CODE (d) == FUNCTION_DECL) | |
1846 | { | |
1847 | struct c_declarator *ce = declarator; | |
1848 | while (ce != NULL) | |
1849 | if (ce->kind == cdk_function) | |
1850 | { | |
1851 | parms = ce->u.arg_info->parms; | |
1852 | break; | |
1853 | } | |
1854 | else | |
1855 | ce = ce->declarator; | |
1856 | } | |
1857 | if (parms) | |
1858 | temp_store_parm_decls (d, parms); | |
1859 | c_finish_omp_declare_simd (parser, d, parms, | |
1860 | omp_declare_simd_clauses); | |
1861 | if (parms) | |
1862 | temp_pop_parm_decls (); | |
1863 | } | |
1576dec7 | 1864 | if (d) |
e60a6f7b | 1865 | finish_decl (d, UNKNOWN_LOCATION, NULL_TREE, |
0a65c3bb | 1866 | NULL_TREE, asm_name); |
1867 | ||
1868 | if (c_parser_next_token_is_keyword (parser, RID_IN)) | |
1869 | { | |
1870 | if (d) | |
1871 | *objc_foreach_object_declaration = d; | |
1872 | else | |
1873 | *objc_foreach_object_declaration = error_mark_node; | |
1874 | } | |
1576dec7 | 1875 | } |
1876 | if (c_parser_next_token_is (parser, CPP_COMMA)) | |
1877 | { | |
4fba5eb9 | 1878 | if (auto_type_p) |
1879 | { | |
1880 | error_at (here, | |
1881 | "%<__auto_type%> may only be used with" | |
1882 | " a single declarator"); | |
1883 | c_parser_skip_to_end_of_block_or_statement (parser); | |
1884 | return; | |
1885 | } | |
1576dec7 | 1886 | c_parser_consume_token (parser); |
1887 | if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)) | |
1888 | all_prefix_attrs = chainon (c_parser_attributes (parser), | |
1889 | prefix_attrs); | |
1890 | else | |
1891 | all_prefix_attrs = prefix_attrs; | |
1892 | continue; | |
1893 | } | |
1894 | else if (c_parser_next_token_is (parser, CPP_SEMICOLON)) | |
1895 | { | |
1896 | c_parser_consume_token (parser); | |
1897 | return; | |
1898 | } | |
0a65c3bb | 1899 | else if (c_parser_next_token_is_keyword (parser, RID_IN)) |
1900 | { | |
1901 | /* This can only happen in Objective-C: we found the | |
1902 | 'in' that terminates the declaration inside an | |
1903 | Objective-C foreach statement. Do not consume the | |
1904 | token, so that the caller can use it to determine | |
1905 | that this indeed is a foreach context. */ | |
1906 | return; | |
1907 | } | |
1576dec7 | 1908 | else |
1909 | { | |
1910 | c_parser_error (parser, "expected %<,%> or %<;%>"); | |
1911 | c_parser_skip_to_end_of_block_or_statement (parser); | |
1912 | return; | |
1913 | } | |
1914 | } | |
4fba5eb9 | 1915 | else if (auto_type_p) |
1916 | { | |
1917 | error_at (here, | |
1918 | "%<__auto_type%> requires an initialized data declaration"); | |
1919 | c_parser_skip_to_end_of_block_or_statement (parser); | |
1920 | return; | |
1921 | } | |
1576dec7 | 1922 | else if (!fndef_ok) |
1923 | { | |
1924 | c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, " | |
1925 | "%<asm%> or %<__attribute__%>"); | |
1926 | c_parser_skip_to_end_of_block_or_statement (parser); | |
1927 | return; | |
1928 | } | |
1929 | /* Function definition (nested or otherwise). */ | |
1930 | if (nested) | |
1931 | { | |
29438999 | 1932 | pedwarn (here, OPT_Wpedantic, "ISO C forbids nested functions"); |
d2764e2d | 1933 | c_push_function_context (); |
1576dec7 | 1934 | } |
1935 | if (!start_function (specs, declarator, all_prefix_attrs)) | |
1936 | { | |
1937 | /* This can appear in many cases looking nothing like a | |
1938 | function definition, so we don't give a more specific | |
1939 | error suggesting there was one. */ | |
1940 | c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, %<asm%> " | |
1941 | "or %<__attribute__%>"); | |
1942 | if (nested) | |
d2764e2d | 1943 | c_pop_function_context (); |
1576dec7 | 1944 | break; |
1945 | } | |
6198e8f6 | 1946 | |
1947 | if (DECL_DECLARED_INLINE_P (current_function_decl)) | |
1948 | tv = TV_PARSE_INLINE; | |
1949 | else | |
1950 | tv = TV_PARSE_FUNC; | |
1951 | timevar_push (tv); | |
1952 | ||
1576dec7 | 1953 | /* Parse old-style parameter declarations. ??? Attributes are |
1954 | not allowed to start declaration specifiers here because of a | |
1955 | syntax conflict between a function declaration with attribute | |
1956 | suffix and a function definition with an attribute prefix on | |
1957 | first old-style parameter declaration. Following the old | |
1958 | parser, they are not accepted on subsequent old-style | |
1959 | parameter declarations either. However, there is no | |
1960 | ambiguity after the first declaration, nor indeed on the | |
1961 | first as long as we don't allow postfix attributes after a | |
1962 | declarator with a nonempty identifier list in a definition; | |
1963 | and postfix attributes have never been accepted here in | |
1964 | function definitions either. */ | |
1965 | while (c_parser_next_token_is_not (parser, CPP_EOF) | |
1966 | && c_parser_next_token_is_not (parser, CPP_OPEN_BRACE)) | |
f80e7755 | 1967 | c_parser_declaration_or_fndef (parser, false, false, false, |
bc7bff74 | 1968 | true, false, NULL, vNULL); |
1576dec7 | 1969 | store_parm_decls (); |
74acc703 | 1970 | if (omp_declare_simd_clauses.exists () |
1971 | || !vec_safe_is_empty (parser->cilk_simd_fn_tokens)) | |
bc7bff74 | 1972 | c_finish_omp_declare_simd (parser, current_function_decl, NULL_TREE, |
1973 | omp_declare_simd_clauses); | |
30099c0c | 1974 | DECL_STRUCT_FUNCTION (current_function_decl)->function_start_locus |
1975 | = c_parser_peek_token (parser)->location; | |
1576dec7 | 1976 | fnbody = c_parser_compound_statement (parser); |
a89e6c15 | 1977 | if (flag_cilkplus && contains_array_notation_expr (fnbody)) |
cc92dddc | 1978 | fnbody = expand_array_notation_exprs (fnbody); |
1576dec7 | 1979 | if (nested) |
1980 | { | |
1981 | tree decl = current_function_decl; | |
3bb63aeb | 1982 | /* Mark nested functions as needing static-chain initially. |
1983 | lower_nested_functions will recompute it but the | |
1984 | DECL_STATIC_CHAIN flag is also used before that happens, | |
1985 | by initializer_constant_valid_p. See gcc.dg/nested-fn-2.c. */ | |
1986 | DECL_STATIC_CHAIN (decl) = 1; | |
1576dec7 | 1987 | add_stmt (fnbody); |
1988 | finish_function (); | |
d2764e2d | 1989 | c_pop_function_context (); |
e60a6f7b | 1990 | add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl), DECL_EXPR, decl)); |
1576dec7 | 1991 | } |
1992 | else | |
1993 | { | |
1994 | add_stmt (fnbody); | |
1995 | finish_function (); | |
1996 | } | |
6198e8f6 | 1997 | |
1998 | timevar_pop (tv); | |
1576dec7 | 1999 | break; |
2000 | } | |
2001 | } | |
2002 | ||
2003 | /* Parse an asm-definition (asm() outside a function body). This is a | |
2004 | GNU extension. | |
2005 | ||
2006 | asm-definition: | |
2007 | simple-asm-expr ; | |
2008 | */ | |
2009 | ||
2010 | static void | |
2011 | c_parser_asm_definition (c_parser *parser) | |
2012 | { | |
2013 | tree asm_str = c_parser_simple_asm_expr (parser); | |
1576dec7 | 2014 | if (asm_str) |
35ee1c66 | 2015 | symtab->finalize_toplevel_asm (asm_str); |
1576dec7 | 2016 | c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); |
2017 | } | |
2018 | ||
32074525 | 2019 | /* Parse a static assertion (C11 6.7.10). |
f80e7755 | 2020 | |
2021 | static_assert-declaration: | |
2022 | static_assert-declaration-no-semi ; | |
2023 | */ | |
2024 | ||
2025 | static void | |
2026 | c_parser_static_assert_declaration (c_parser *parser) | |
2027 | { | |
2028 | c_parser_static_assert_declaration_no_semi (parser); | |
2029 | if (parser->error | |
2030 | || !c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>")) | |
2031 | c_parser_skip_to_end_of_block_or_statement (parser); | |
2032 | } | |
2033 | ||
32074525 | 2034 | /* Parse a static assertion (C11 6.7.10), without the trailing |
f80e7755 | 2035 | semicolon. |
2036 | ||
2037 | static_assert-declaration-no-semi: | |
2038 | _Static_assert ( constant-expression , string-literal ) | |
2039 | */ | |
2040 | ||
2041 | static void | |
2042 | c_parser_static_assert_declaration_no_semi (c_parser *parser) | |
2043 | { | |
2044 | location_t assert_loc, value_loc; | |
2045 | tree value; | |
2046 | tree string; | |
2047 | ||
2048 | gcc_assert (c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT)); | |
2049 | assert_loc = c_parser_peek_token (parser)->location; | |
508ea33a | 2050 | if (flag_isoc99) |
2051 | pedwarn_c99 (assert_loc, OPT_Wpedantic, | |
f80e7755 | 2052 | "ISO C99 does not support %<_Static_assert%>"); |
508ea33a | 2053 | else |
2054 | pedwarn_c99 (assert_loc, OPT_Wpedantic, | |
f80e7755 | 2055 | "ISO C90 does not support %<_Static_assert%>"); |
f80e7755 | 2056 | c_parser_consume_token (parser); |
2057 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
2058 | return; | |
2059 | value_loc = c_parser_peek_token (parser)->location; | |
2060 | value = c_parser_expr_no_commas (parser, NULL).value; | |
2061 | parser->lex_untranslated_string = true; | |
2062 | if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>")) | |
2063 | { | |
2064 | parser->lex_untranslated_string = false; | |
2065 | return; | |
2066 | } | |
2067 | switch (c_parser_peek_token (parser)->type) | |
2068 | { | |
2069 | case CPP_STRING: | |
2070 | case CPP_STRING16: | |
2071 | case CPP_STRING32: | |
2072 | case CPP_WSTRING: | |
2073 | case CPP_UTF8STRING: | |
2074 | string = c_parser_peek_token (parser)->value; | |
2075 | c_parser_consume_token (parser); | |
2076 | parser->lex_untranslated_string = false; | |
2077 | break; | |
2078 | default: | |
2079 | c_parser_error (parser, "expected string literal"); | |
2080 | parser->lex_untranslated_string = false; | |
2081 | return; | |
2082 | } | |
2083 | c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
2084 | ||
2085 | if (!INTEGRAL_TYPE_P (TREE_TYPE (value))) | |
2086 | { | |
2087 | error_at (value_loc, "expression in static assertion is not an integer"); | |
2088 | return; | |
2089 | } | |
2090 | if (TREE_CODE (value) != INTEGER_CST) | |
2091 | { | |
2092 | value = c_fully_fold (value, false, NULL); | |
6ea2b1bc | 2093 | /* Strip no-op conversions. */ |
2094 | STRIP_TYPE_NOPS (value); | |
f80e7755 | 2095 | if (TREE_CODE (value) == INTEGER_CST) |
29438999 | 2096 | pedwarn (value_loc, OPT_Wpedantic, "expression in static assertion " |
f80e7755 | 2097 | "is not an integer constant expression"); |
2098 | } | |
2099 | if (TREE_CODE (value) != INTEGER_CST) | |
2100 | { | |
2101 | error_at (value_loc, "expression in static assertion is not constant"); | |
2102 | return; | |
2103 | } | |
2104 | constant_expression_warning (value); | |
2105 | if (integer_zerop (value)) | |
2106 | error_at (assert_loc, "static assertion failed: %E", string); | |
2107 | } | |
2108 | ||
1576dec7 | 2109 | /* Parse some declaration specifiers (possibly none) (C90 6.5, C99 |
2110 | 6.7), adding them to SPECS (which may already include some). | |
2111 | Storage class specifiers are accepted iff SCSPEC_OK; type | |
43d03c23 | 2112 | specifiers are accepted iff TYPESPEC_OK; alignment specifiers are |
2113 | accepted iff ALIGNSPEC_OK; attributes are accepted at the start | |
4fba5eb9 | 2114 | iff START_ATTR_OK; __auto_type is accepted iff AUTO_TYPE_OK. |
1576dec7 | 2115 | |
2116 | declaration-specifiers: | |
2117 | storage-class-specifier declaration-specifiers[opt] | |
2118 | type-specifier declaration-specifiers[opt] | |
2119 | type-qualifier declaration-specifiers[opt] | |
2120 | function-specifier declaration-specifiers[opt] | |
83e25171 | 2121 | alignment-specifier declaration-specifiers[opt] |
1576dec7 | 2122 | |
2123 | Function specifiers (inline) are from C99, and are currently | |
83e25171 | 2124 | handled as storage class specifiers, as is __thread. Alignment |
32074525 | 2125 | specifiers are from C11. |
1576dec7 | 2126 | |
2127 | C90 6.5.1, C99 6.7.1: | |
2128 | storage-class-specifier: | |
2129 | typedef | |
2130 | extern | |
2131 | static | |
2132 | auto | |
2133 | register | |
d184e0c0 | 2134 | _Thread_local |
2135 | ||
2136 | (_Thread_local is new in C11.) | |
1576dec7 | 2137 | |
2138 | C99 6.7.4: | |
2139 | function-specifier: | |
2140 | inline | |
4755ceab | 2141 | _Noreturn |
2142 | ||
32074525 | 2143 | (_Noreturn is new in C11.) |
1576dec7 | 2144 | |
2145 | C90 6.5.2, C99 6.7.2: | |
2146 | type-specifier: | |
2147 | void | |
2148 | char | |
2149 | short | |
2150 | int | |
2151 | long | |
2152 | float | |
2153 | double | |
2154 | signed | |
2155 | unsigned | |
2156 | _Bool | |
2157 | _Complex | |
2158 | [_Imaginary removed in C99 TC2] | |
2159 | struct-or-union-specifier | |
2160 | enum-specifier | |
2161 | typedef-name | |
b560fabd | 2162 | atomic-type-specifier |
1576dec7 | 2163 | |
2164 | (_Bool and _Complex are new in C99.) | |
b560fabd | 2165 | (atomic-type-specifier is new in C11.) |
1576dec7 | 2166 | |
2167 | C90 6.5.3, C99 6.7.3: | |
2168 | ||
2169 | type-qualifier: | |
2170 | const | |
2171 | restrict | |
2172 | volatile | |
6d5d708e | 2173 | address-space-qualifier |
b560fabd | 2174 | _Atomic |
1576dec7 | 2175 | |
2176 | (restrict is new in C99.) | |
b560fabd | 2177 | (_Atomic is new in C11.) |
1576dec7 | 2178 | |
2179 | GNU extensions: | |
2180 | ||
2181 | declaration-specifiers: | |
2182 | attributes declaration-specifiers[opt] | |
2183 | ||
6d5d708e | 2184 | type-qualifier: |
2185 | address-space | |
2186 | ||
2187 | address-space: | |
2188 | identifier recognized by the target | |
2189 | ||
1576dec7 | 2190 | storage-class-specifier: |
2191 | __thread | |
2192 | ||
2193 | type-specifier: | |
2194 | typeof-specifier | |
4fba5eb9 | 2195 | __auto_type |
9f75f026 | 2196 | __intN |
c4503c0a | 2197 | _Decimal32 |
2198 | _Decimal64 | |
2199 | _Decimal128 | |
9421ebb9 | 2200 | _Fract |
2201 | _Accum | |
2202 | _Sat | |
2203 | ||
2204 | (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037: | |
2205 | http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf) | |
1576dec7 | 2206 | |
b560fabd | 2207 | atomic-type-specifier |
2208 | _Atomic ( type-name ) | |
2209 | ||
1576dec7 | 2210 | Objective-C: |
2211 | ||
2212 | type-specifier: | |
2213 | class-name objc-protocol-refs[opt] | |
2214 | typedef-name objc-protocol-refs | |
2215 | objc-protocol-refs | |
2216 | */ | |
2217 | ||
2218 | static void | |
2219 | c_parser_declspecs (c_parser *parser, struct c_declspecs *specs, | |
26ee9e7a | 2220 | bool scspec_ok, bool typespec_ok, bool start_attr_ok, |
4fba5eb9 | 2221 | bool alignspec_ok, bool auto_type_ok, |
2222 | enum c_lookahead_kind la) | |
1576dec7 | 2223 | { |
2224 | bool attrs_ok = start_attr_ok; | |
ae5ead32 | 2225 | bool seen_type = specs->typespec_kind != ctsk_none; |
26ee9e7a | 2226 | |
2227 | if (!typespec_ok) | |
2228 | gcc_assert (la == cla_prefer_id); | |
2229 | ||
2230 | while (c_parser_next_token_is (parser, CPP_NAME) | |
1576dec7 | 2231 | || c_parser_next_token_is (parser, CPP_KEYWORD) |
2232 | || (c_dialect_objc () && c_parser_next_token_is (parser, CPP_LESS))) | |
2233 | { | |
2234 | struct c_typespec t; | |
2235 | tree attrs; | |
83e25171 | 2236 | tree align; |
843bd2fa | 2237 | location_t loc = c_parser_peek_token (parser)->location; |
b02d8973 | 2238 | |
26ee9e7a | 2239 | /* If we cannot accept a type, exit if the next token must start |
2240 | one. Also, if we already have seen a tagged definition, | |
2241 | a typename would be an error anyway and likely the user | |
2242 | has simply forgotten a semicolon, so we exit. */ | |
2243 | if ((!typespec_ok || specs->typespec_kind == ctsk_tagdef) | |
2244 | && c_parser_next_tokens_start_typename (parser, la) | |
2245 | && !c_parser_next_token_is_qualifier (parser)) | |
2246 | break; | |
b02d8973 | 2247 | |
1576dec7 | 2248 | if (c_parser_next_token_is (parser, CPP_NAME)) |
2249 | { | |
a60f3e81 | 2250 | c_token *name_token = c_parser_peek_token (parser); |
2251 | tree value = name_token->value; | |
2252 | c_id_kind kind = name_token->id_kind; | |
6d5d708e | 2253 | |
2254 | if (kind == C_ID_ADDRSPACE) | |
2255 | { | |
2256 | addr_space_t as | |
a60f3e81 | 2257 | = name_token->keyword - RID_FIRST_ADDR_SPACE; |
2258 | declspecs_add_addrspace (name_token->location, specs, as); | |
6d5d708e | 2259 | c_parser_consume_token (parser); |
2260 | attrs_ok = true; | |
2261 | continue; | |
2262 | } | |
2263 | ||
26ee9e7a | 2264 | gcc_assert (!c_parser_next_token_is_qualifier (parser)); |
2265 | ||
2266 | /* If we cannot accept a type, and the next token must start one, | |
2267 | exit. Do the same if we already have seen a tagged definition, | |
2268 | since it would be an error anyway and likely the user has simply | |
2269 | forgotten a semicolon. */ | |
2270 | if (seen_type || !c_parser_next_tokens_start_typename (parser, la)) | |
2271 | break; | |
2272 | ||
2273 | /* Now at an unknown typename (C_ID_ID), a C_ID_TYPENAME or | |
2274 | a C_ID_CLASSNAME. */ | |
1576dec7 | 2275 | c_parser_consume_token (parser); |
2276 | seen_type = true; | |
2277 | attrs_ok = true; | |
26ee9e7a | 2278 | if (kind == C_ID_ID) |
2279 | { | |
8f1128f8 | 2280 | error_at (loc, "unknown type name %qE", value); |
26ee9e7a | 2281 | t.kind = ctsk_typedef; |
2282 | t.spec = error_mark_node; | |
2283 | } | |
2284 | else if (kind == C_ID_TYPENAME | |
2285 | && (!c_dialect_objc () | |
2286 | || c_parser_next_token_is_not (parser, CPP_LESS))) | |
1576dec7 | 2287 | { |
2288 | t.kind = ctsk_typedef; | |
2289 | /* For a typedef name, record the meaning, not the name. | |
2290 | In case of 'foo foo, bar;'. */ | |
2291 | t.spec = lookup_name (value); | |
2292 | } | |
2293 | else | |
2294 | { | |
2295 | tree proto = NULL_TREE; | |
2296 | gcc_assert (c_dialect_objc ()); | |
2297 | t.kind = ctsk_objc; | |
2298 | if (c_parser_next_token_is (parser, CPP_LESS)) | |
2299 | proto = c_parser_objc_protocol_refs (parser); | |
2300 | t.spec = objc_get_protocol_qualified_type (value, proto); | |
2301 | } | |
26ee9e7a | 2302 | t.expr = NULL_TREE; |
2303 | t.expr_const_operands = true; | |
a60f3e81 | 2304 | declspecs_add_type (name_token->location, specs, t); |
1576dec7 | 2305 | continue; |
2306 | } | |
2307 | if (c_parser_next_token_is (parser, CPP_LESS)) | |
2308 | { | |
2309 | /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" - | |
2310 | nisse@lysator.liu.se. */ | |
2311 | tree proto; | |
2312 | gcc_assert (c_dialect_objc ()); | |
2313 | if (!typespec_ok || seen_type) | |
2314 | break; | |
2315 | proto = c_parser_objc_protocol_refs (parser); | |
2316 | t.kind = ctsk_objc; | |
2317 | t.spec = objc_get_protocol_qualified_type (NULL_TREE, proto); | |
a75b1c71 | 2318 | t.expr = NULL_TREE; |
2319 | t.expr_const_operands = true; | |
843bd2fa | 2320 | declspecs_add_type (loc, specs, t); |
1576dec7 | 2321 | continue; |
2322 | } | |
2323 | gcc_assert (c_parser_next_token_is (parser, CPP_KEYWORD)); | |
2324 | switch (c_parser_peek_token (parser)->keyword) | |
2325 | { | |
2326 | case RID_STATIC: | |
2327 | case RID_EXTERN: | |
2328 | case RID_REGISTER: | |
2329 | case RID_TYPEDEF: | |
2330 | case RID_INLINE: | |
985c6e3a | 2331 | case RID_NORETURN: |
1576dec7 | 2332 | case RID_AUTO: |
2333 | case RID_THREAD: | |
2334 | if (!scspec_ok) | |
2335 | goto out; | |
2336 | attrs_ok = true; | |
985c6e3a | 2337 | /* TODO: Distinguish between function specifiers (inline, noreturn) |
1576dec7 | 2338 | and storage class specifiers, either here or in |
2339 | declspecs_add_scspec. */ | |
a60f3e81 | 2340 | declspecs_add_scspec (loc, specs, |
2341 | c_parser_peek_token (parser)->value); | |
1576dec7 | 2342 | c_parser_consume_token (parser); |
2343 | break; | |
4fba5eb9 | 2344 | case RID_AUTO_TYPE: |
2345 | if (!auto_type_ok) | |
2346 | goto out; | |
2347 | /* Fall through. */ | |
1576dec7 | 2348 | case RID_UNSIGNED: |
2349 | case RID_LONG: | |
2350 | case RID_SHORT: | |
2351 | case RID_SIGNED: | |
2352 | case RID_COMPLEX: | |
2353 | case RID_INT: | |
2354 | case RID_CHAR: | |
2355 | case RID_FLOAT: | |
2356 | case RID_DOUBLE: | |
2357 | case RID_VOID: | |
c4503c0a | 2358 | case RID_DFLOAT32: |
2359 | case RID_DFLOAT64: | |
2360 | case RID_DFLOAT128: | |
1576dec7 | 2361 | case RID_BOOL: |
9421ebb9 | 2362 | case RID_FRACT: |
2363 | case RID_ACCUM: | |
2364 | case RID_SAT: | |
9f75f026 | 2365 | case RID_INT_N_0: |
2366 | case RID_INT_N_1: | |
2367 | case RID_INT_N_2: | |
2368 | case RID_INT_N_3: | |
1576dec7 | 2369 | if (!typespec_ok) |
2370 | goto out; | |
2371 | attrs_ok = true; | |
2372 | seen_type = true; | |
920d59b0 | 2373 | if (c_dialect_objc ()) |
2374 | parser->objc_need_raw_identifier = true; | |
1576dec7 | 2375 | t.kind = ctsk_resword; |
2376 | t.spec = c_parser_peek_token (parser)->value; | |
a75b1c71 | 2377 | t.expr = NULL_TREE; |
2378 | t.expr_const_operands = true; | |
843bd2fa | 2379 | declspecs_add_type (loc, specs, t); |
1576dec7 | 2380 | c_parser_consume_token (parser); |
2381 | break; | |
2382 | case RID_ENUM: | |
2383 | if (!typespec_ok) | |
2384 | goto out; | |
2385 | attrs_ok = true; | |
2386 | seen_type = true; | |
2387 | t = c_parser_enum_specifier (parser); | |
1f0ce3ac | 2388 | invoke_plugin_callbacks (PLUGIN_FINISH_TYPE, t.spec); |
843bd2fa | 2389 | declspecs_add_type (loc, specs, t); |
1576dec7 | 2390 | break; |
2391 | case RID_STRUCT: | |
2392 | case RID_UNION: | |
2393 | if (!typespec_ok) | |
2394 | goto out; | |
2395 | attrs_ok = true; | |
2396 | seen_type = true; | |
2397 | t = c_parser_struct_or_union_specifier (parser); | |
dd2b35f1 | 2398 | invoke_plugin_callbacks (PLUGIN_FINISH_TYPE, t.spec); |
843bd2fa | 2399 | declspecs_add_type (loc, specs, t); |
1576dec7 | 2400 | break; |
2401 | case RID_TYPEOF: | |
2402 | /* ??? The old parser rejected typeof after other type | |
2403 | specifiers, but is a syntax error the best way of | |
2404 | handling this? */ | |
2405 | if (!typespec_ok || seen_type) | |
2406 | goto out; | |
2407 | attrs_ok = true; | |
2408 | seen_type = true; | |
2409 | t = c_parser_typeof_specifier (parser); | |
843bd2fa | 2410 | declspecs_add_type (loc, specs, t); |
1576dec7 | 2411 | break; |
b560fabd | 2412 | case RID_ATOMIC: |
2413 | /* C parser handling of Objective-C constructs needs | |
2414 | checking for correct lvalue-to-rvalue conversions, and | |
2415 | the code in build_modify_expr handling various | |
2416 | Objective-C cases, and that in build_unary_op handling | |
2417 | Objective-C cases for increment / decrement, also needs | |
2418 | updating; uses of TYPE_MAIN_VARIANT in objc_compare_types | |
2419 | and objc_types_are_equivalent may also need updates. */ | |
2420 | if (c_dialect_objc ()) | |
2421 | sorry ("%<_Atomic%> in Objective-C"); | |
2422 | /* C parser handling of OpenMP constructs needs checking for | |
2423 | correct lvalue-to-rvalue conversions. */ | |
2424 | if (flag_openmp) | |
2425 | sorry ("%<_Atomic%> with OpenMP"); | |
508ea33a | 2426 | if (flag_isoc99) |
2427 | pedwarn_c99 (loc, OPT_Wpedantic, | |
b560fabd | 2428 | "ISO C99 does not support the %<_Atomic%> qualifier"); |
508ea33a | 2429 | else |
2430 | pedwarn_c99 (loc, OPT_Wpedantic, | |
b560fabd | 2431 | "ISO C90 does not support the %<_Atomic%> qualifier"); |
b560fabd | 2432 | attrs_ok = true; |
2433 | tree value; | |
2434 | value = c_parser_peek_token (parser)->value; | |
2435 | c_parser_consume_token (parser); | |
2436 | if (typespec_ok && c_parser_next_token_is (parser, CPP_OPEN_PAREN)) | |
2437 | { | |
2438 | /* _Atomic ( type-name ). */ | |
2439 | seen_type = true; | |
2440 | c_parser_consume_token (parser); | |
2441 | struct c_type_name *type = c_parser_type_name (parser); | |
2442 | t.kind = ctsk_typeof; | |
2443 | t.spec = error_mark_node; | |
2444 | t.expr = NULL_TREE; | |
2445 | t.expr_const_operands = true; | |
2446 | if (type != NULL) | |
2447 | t.spec = groktypename (type, &t.expr, | |
2448 | &t.expr_const_operands); | |
2449 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, | |
2450 | "expected %<)%>"); | |
2451 | if (t.spec != error_mark_node) | |
2452 | { | |
2453 | if (TREE_CODE (t.spec) == ARRAY_TYPE) | |
2454 | error_at (loc, "%<_Atomic%>-qualified array type"); | |
2455 | else if (TREE_CODE (t.spec) == FUNCTION_TYPE) | |
2456 | error_at (loc, "%<_Atomic%>-qualified function type"); | |
2457 | else if (TYPE_QUALS (t.spec) != TYPE_UNQUALIFIED) | |
2458 | error_at (loc, "%<_Atomic%> applied to a qualified type"); | |
2459 | else | |
2460 | t.spec = c_build_qualified_type (t.spec, TYPE_QUAL_ATOMIC); | |
2461 | } | |
2462 | declspecs_add_type (loc, specs, t); | |
2463 | } | |
2464 | else | |
2465 | declspecs_add_qual (loc, specs, value); | |
2466 | break; | |
1576dec7 | 2467 | case RID_CONST: |
2468 | case RID_VOLATILE: | |
2469 | case RID_RESTRICT: | |
2470 | attrs_ok = true; | |
a60f3e81 | 2471 | declspecs_add_qual (loc, specs, c_parser_peek_token (parser)->value); |
1576dec7 | 2472 | c_parser_consume_token (parser); |
2473 | break; | |
2474 | case RID_ATTRIBUTE: | |
2475 | if (!attrs_ok) | |
2476 | goto out; | |
2477 | attrs = c_parser_attributes (parser); | |
a60f3e81 | 2478 | declspecs_add_attrs (loc, specs, attrs); |
1576dec7 | 2479 | break; |
83e25171 | 2480 | case RID_ALIGNAS: |
43d03c23 | 2481 | if (!alignspec_ok) |
2482 | goto out; | |
83e25171 | 2483 | align = c_parser_alignas_specifier (parser); |
a60f3e81 | 2484 | declspecs_add_alignas (loc, specs, align); |
83e25171 | 2485 | break; |
1576dec7 | 2486 | default: |
2487 | goto out; | |
2488 | } | |
2489 | } | |
2490 | out: ; | |
2491 | } | |
2492 | ||
2493 | /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2). | |
2494 | ||
2495 | enum-specifier: | |
2496 | enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt] | |
2497 | enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt] | |
2498 | enum attributes[opt] identifier | |
2499 | ||
2500 | The form with trailing comma is new in C99. The forms with | |
2501 | attributes are GNU extensions. In GNU C, we accept any expression | |
2502 | without commas in the syntax (assignment expressions, not just | |
2503 | conditional expressions); assignment expressions will be diagnosed | |
2504 | as non-constant. | |
2505 | ||
2506 | enumerator-list: | |
2507 | enumerator | |
2508 | enumerator-list , enumerator | |
2509 | ||
2510 | enumerator: | |
2511 | enumeration-constant | |
2512 | enumeration-constant = constant-expression | |
5a4c69dd | 2513 | |
2514 | GNU Extensions: | |
2515 | ||
2516 | enumerator: | |
2517 | enumeration-constant attributes[opt] | |
2518 | enumeration-constant attributes[opt] = constant-expression | |
2519 | ||
1576dec7 | 2520 | */ |
2521 | ||
2522 | static struct c_typespec | |
2523 | c_parser_enum_specifier (c_parser *parser) | |
2524 | { | |
2525 | struct c_typespec ret; | |
2526 | tree attrs; | |
2527 | tree ident = NULL_TREE; | |
0b09525f | 2528 | location_t enum_loc; |
019abced | 2529 | location_t ident_loc = UNKNOWN_LOCATION; /* Quiet warning. */ |
1576dec7 | 2530 | gcc_assert (c_parser_next_token_is_keyword (parser, RID_ENUM)); |
0b09525f | 2531 | enum_loc = c_parser_peek_token (parser)->location; |
1576dec7 | 2532 | c_parser_consume_token (parser); |
2533 | attrs = c_parser_attributes (parser); | |
e60a6f7b | 2534 | enum_loc = c_parser_peek_token (parser)->location; |
8c37d359 | 2535 | /* Set the location in case we create a decl now. */ |
2536 | c_parser_set_source_position_from_token (c_parser_peek_token (parser)); | |
1576dec7 | 2537 | if (c_parser_next_token_is (parser, CPP_NAME)) |
2538 | { | |
2539 | ident = c_parser_peek_token (parser)->value; | |
be9eba16 | 2540 | ident_loc = c_parser_peek_token (parser)->location; |
0b09525f | 2541 | enum_loc = ident_loc; |
1576dec7 | 2542 | c_parser_consume_token (parser); |
2543 | } | |
2544 | if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) | |
2545 | { | |
2546 | /* Parse an enum definition. */ | |
13c7079e | 2547 | struct c_enum_contents the_enum; |
6198e8f6 | 2548 | tree type; |
1576dec7 | 2549 | tree postfix_attrs; |
2550 | /* We chain the enumerators in reverse order, then put them in | |
2551 | forward order at the end. */ | |
6198e8f6 | 2552 | tree values; |
2553 | timevar_push (TV_PARSE_ENUM); | |
2554 | type = start_enum (enum_loc, &the_enum, ident); | |
2555 | values = NULL_TREE; | |
1576dec7 | 2556 | c_parser_consume_token (parser); |
2557 | while (true) | |
2558 | { | |
2559 | tree enum_id; | |
2560 | tree enum_value; | |
2561 | tree enum_decl; | |
2562 | bool seen_comma; | |
8c37d359 | 2563 | c_token *token; |
019abced | 2564 | location_t comma_loc = UNKNOWN_LOCATION; /* Quiet warning. */ |
5a7ce2ec | 2565 | location_t decl_loc, value_loc; |
1576dec7 | 2566 | if (c_parser_next_token_is_not (parser, CPP_NAME)) |
2567 | { | |
bd66724c | 2568 | /* Give a nicer error for "enum {}". */ |
2569 | if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE) | |
2570 | && !parser->error) | |
2571 | { | |
2572 | error_at (c_parser_peek_token (parser)->location, | |
2573 | "empty enum is invalid"); | |
2574 | parser->error = true; | |
2575 | } | |
2576 | else | |
2577 | c_parser_error (parser, "expected identifier"); | |
1576dec7 | 2578 | c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL); |
2579 | values = error_mark_node; | |
2580 | break; | |
2581 | } | |
8c37d359 | 2582 | token = c_parser_peek_token (parser); |
2583 | enum_id = token->value; | |
2584 | /* Set the location in case we create a decl now. */ | |
2585 | c_parser_set_source_position_from_token (token); | |
5a7ce2ec | 2586 | decl_loc = value_loc = token->location; |
1576dec7 | 2587 | c_parser_consume_token (parser); |
5a4c69dd | 2588 | /* Parse any specified attributes. */ |
2589 | tree enum_attrs = c_parser_attributes (parser); | |
1576dec7 | 2590 | if (c_parser_next_token_is (parser, CPP_EQ)) |
2591 | { | |
2592 | c_parser_consume_token (parser); | |
e8fc0d34 | 2593 | value_loc = c_parser_peek_token (parser)->location; |
1576dec7 | 2594 | enum_value = c_parser_expr_no_commas (parser, NULL).value; |
2595 | } | |
2596 | else | |
2597 | enum_value = NULL_TREE; | |
5a7ce2ec | 2598 | enum_decl = build_enumerator (decl_loc, value_loc, |
5a4c69dd | 2599 | &the_enum, enum_id, enum_value); |
2600 | if (enum_attrs) | |
2601 | decl_attributes (&TREE_PURPOSE (enum_decl), enum_attrs, 0); | |
1576dec7 | 2602 | TREE_CHAIN (enum_decl) = values; |
2603 | values = enum_decl; | |
2604 | seen_comma = false; | |
2605 | if (c_parser_next_token_is (parser, CPP_COMMA)) | |
2606 | { | |
be9eba16 | 2607 | comma_loc = c_parser_peek_token (parser)->location; |
1576dec7 | 2608 | seen_comma = true; |
2609 | c_parser_consume_token (parser); | |
2610 | } | |
2611 | if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) | |
2612 | { | |
890c2e2f | 2613 | if (seen_comma) |
2614 | pedwarn_c90 (comma_loc, OPT_Wpedantic, | |
2615 | "comma at end of enumerator list"); | |
1576dec7 | 2616 | c_parser_consume_token (parser); |
2617 | break; | |
2618 | } | |
2619 | if (!seen_comma) | |
2620 | { | |
2621 | c_parser_error (parser, "expected %<,%> or %<}%>"); | |
2622 | c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL); | |
2623 | values = error_mark_node; | |
2624 | break; | |
2625 | } | |
2626 | } | |
2627 | postfix_attrs = c_parser_attributes (parser); | |
2628 | ret.spec = finish_enum (type, nreverse (values), | |
2629 | chainon (attrs, postfix_attrs)); | |
2630 | ret.kind = ctsk_tagdef; | |
a75b1c71 | 2631 | ret.expr = NULL_TREE; |
2632 | ret.expr_const_operands = true; | |
6198e8f6 | 2633 | timevar_pop (TV_PARSE_ENUM); |
1576dec7 | 2634 | return ret; |
2635 | } | |
2636 | else if (!ident) | |
2637 | { | |
2638 | c_parser_error (parser, "expected %<{%>"); | |
2639 | ret.spec = error_mark_node; | |
2640 | ret.kind = ctsk_tagref; | |
a75b1c71 | 2641 | ret.expr = NULL_TREE; |
2642 | ret.expr_const_operands = true; | |
1576dec7 | 2643 | return ret; |
2644 | } | |
e60a6f7b | 2645 | ret = parser_xref_tag (ident_loc, ENUMERAL_TYPE, ident); |
1576dec7 | 2646 | /* In ISO C, enumerated types can be referred to only if already |
2647 | defined. */ | |
2648 | if (pedantic && !COMPLETE_TYPE_P (ret.spec)) | |
be9eba16 | 2649 | { |
2650 | gcc_assert (ident); | |
29438999 | 2651 | pedwarn (enum_loc, OPT_Wpedantic, |
21ca8540 | 2652 | "ISO C forbids forward references to %<enum%> types"); |
be9eba16 | 2653 | } |
1576dec7 | 2654 | return ret; |
2655 | } | |
2656 | ||
2657 | /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1). | |
2658 | ||
2659 | struct-or-union-specifier: | |
2660 | struct-or-union attributes[opt] identifier[opt] | |
2661 | { struct-contents } attributes[opt] | |
2662 | struct-or-union attributes[opt] identifier | |
2663 | ||
2664 | struct-contents: | |
2665 | struct-declaration-list | |
2666 | ||
2667 | struct-declaration-list: | |
2668 | struct-declaration ; | |
2669 | struct-declaration-list struct-declaration ; | |
2670 | ||
2671 | GNU extensions: | |
2672 | ||
2673 | struct-contents: | |
2674 | empty | |
2675 | struct-declaration | |
2676 | struct-declaration-list struct-declaration | |
2677 | ||
2678 | struct-declaration-list: | |
2679 | struct-declaration-list ; | |
2680 | ; | |
2681 | ||
2682 | (Note that in the syntax here, unlike that in ISO C, the semicolons | |
2683 | are included here rather than in struct-declaration, in order to | |
2684 | describe the syntax with extra semicolons and missing semicolon at | |
2685 | end.) | |
2686 | ||
2687 | Objective-C: | |
2688 | ||
2689 | struct-declaration-list: | |
2690 | @defs ( class-name ) | |
2691 | ||
2692 | (Note this does not include a trailing semicolon, but can be | |
2693 | followed by further declarations, and gets a pedwarn-if-pedantic | |
2694 | when followed by a semicolon.) */ | |
2695 | ||
2696 | static struct c_typespec | |
2697 | c_parser_struct_or_union_specifier (c_parser *parser) | |
2698 | { | |
2699 | struct c_typespec ret; | |
2700 | tree attrs; | |
2701 | tree ident = NULL_TREE; | |
0b09525f | 2702 | location_t struct_loc; |
2703 | location_t ident_loc = UNKNOWN_LOCATION; | |
1576dec7 | 2704 | enum tree_code code; |
2705 | switch (c_parser_peek_token (parser)->keyword) | |
2706 | { | |
2707 | case RID_STRUCT: | |
2708 | code = RECORD_TYPE; | |
2709 | break; | |
2710 | case RID_UNION: | |
2711 | code = UNION_TYPE; | |
2712 | break; | |
2713 | default: | |
2714 | gcc_unreachable (); | |
2715 | } | |
0b09525f | 2716 | struct_loc = c_parser_peek_token (parser)->location; |
1576dec7 | 2717 | c_parser_consume_token (parser); |
2718 | attrs = c_parser_attributes (parser); | |
e60a6f7b | 2719 | |
8c37d359 | 2720 | /* Set the location in case we create a decl now. */ |
2721 | c_parser_set_source_position_from_token (c_parser_peek_token (parser)); | |
e60a6f7b | 2722 | |
1576dec7 | 2723 | if (c_parser_next_token_is (parser, CPP_NAME)) |
2724 | { | |
2725 | ident = c_parser_peek_token (parser)->value; | |
0b09525f | 2726 | ident_loc = c_parser_peek_token (parser)->location; |
2727 | struct_loc = ident_loc; | |
1576dec7 | 2728 | c_parser_consume_token (parser); |
2729 | } | |
2730 | if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) | |
2731 | { | |
2732 | /* Parse a struct or union definition. Start the scope of the | |
2733 | tag before parsing components. */ | |
843bd2fa | 2734 | struct c_struct_parse_info *struct_info; |
2735 | tree type = start_struct (struct_loc, code, ident, &struct_info); | |
1576dec7 | 2736 | tree postfix_attrs; |
2737 | /* We chain the components in reverse order, then put them in | |
2738 | forward order at the end. Each struct-declaration may | |
2739 | declare multiple components (comma-separated), so we must use | |
2740 | chainon to join them, although when parsing each | |
2741 | struct-declaration we can use TREE_CHAIN directly. | |
2742 | ||
2743 | The theory behind all this is that there will be more | |
2744 | semicolon separated fields than comma separated fields, and | |
2745 | so we'll be minimizing the number of node traversals required | |
2746 | by chainon. */ | |
6198e8f6 | 2747 | tree contents; |
2748 | timevar_push (TV_PARSE_STRUCT); | |
2749 | contents = NULL_TREE; | |
1576dec7 | 2750 | c_parser_consume_token (parser); |
2751 | /* Handle the Objective-C @defs construct, | |
2752 | e.g. foo(sizeof(struct{ @defs(ClassName) }));. */ | |
2753 | if (c_parser_next_token_is_keyword (parser, RID_AT_DEFS)) | |
2754 | { | |
2755 | tree name; | |
2756 | gcc_assert (c_dialect_objc ()); | |
2757 | c_parser_consume_token (parser); | |
2758 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
2759 | goto end_at_defs; | |
2760 | if (c_parser_next_token_is (parser, CPP_NAME) | |
2761 | && c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME) | |
2762 | { | |
2763 | name = c_parser_peek_token (parser)->value; | |
2764 | c_parser_consume_token (parser); | |
2765 | } | |
2766 | else | |
2767 | { | |
2768 | c_parser_error (parser, "expected class name"); | |
2769 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); | |
2770 | goto end_at_defs; | |
2771 | } | |
2772 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, | |
2773 | "expected %<)%>"); | |
2774 | contents = nreverse (objc_get_class_ivars (name)); | |
2775 | } | |
2776 | end_at_defs: | |
2777 | /* Parse the struct-declarations and semicolons. Problems with | |
2778 | semicolons are diagnosed here; empty structures are diagnosed | |
2779 | elsewhere. */ | |
2780 | while (true) | |
2781 | { | |
2782 | tree decls; | |
2783 | /* Parse any stray semicolon. */ | |
2784 | if (c_parser_next_token_is (parser, CPP_SEMICOLON)) | |
2785 | { | |
29438999 | 2786 | pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic, |
21ca8540 | 2787 | "extra semicolon in struct or union specified"); |
1576dec7 | 2788 | c_parser_consume_token (parser); |
2789 | continue; | |
2790 | } | |
2791 | /* Stop if at the end of the struct or union contents. */ | |
2792 | if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) | |
2793 | { | |
2794 | c_parser_consume_token (parser); | |
2795 | break; | |
2796 | } | |
b75b98aa | 2797 | /* Accept #pragmas at struct scope. */ |
2798 | if (c_parser_next_token_is (parser, CPP_PRAGMA)) | |
2799 | { | |
bc7bff74 | 2800 | c_parser_pragma (parser, pragma_struct); |
b75b98aa | 2801 | continue; |
2802 | } | |
1576dec7 | 2803 | /* Parse some comma-separated declarations, but not the |
2804 | trailing semicolon if any. */ | |
2805 | decls = c_parser_struct_declaration (parser); | |
2806 | contents = chainon (decls, contents); | |
2807 | /* If no semicolon follows, either we have a parse error or | |
2808 | are at the end of the struct or union and should | |
2809 | pedwarn. */ | |
2810 | if (c_parser_next_token_is (parser, CPP_SEMICOLON)) | |
2811 | c_parser_consume_token (parser); | |
2812 | else | |
2813 | { | |
2814 | if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) | |
48e1416a | 2815 | pedwarn (c_parser_peek_token (parser)->location, 0, |
21ca8540 | 2816 | "no semicolon at end of struct or union"); |
b02d8973 | 2817 | else if (parser->error |
2818 | || !c_parser_next_token_starts_declspecs (parser)) | |
1576dec7 | 2819 | { |
2820 | c_parser_error (parser, "expected %<;%>"); | |
2821 | c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL); | |
2822 | break; | |
2823 | } | |
b02d8973 | 2824 | |
2825 | /* If we come here, we have already emitted an error | |
2826 | for an expected `;', identifier or `(', and we also | |
2827 | recovered already. Go on with the next field. */ | |
1576dec7 | 2828 | } |
2829 | } | |
2830 | postfix_attrs = c_parser_attributes (parser); | |
e60a6f7b | 2831 | ret.spec = finish_struct (struct_loc, type, nreverse (contents), |
843bd2fa | 2832 | chainon (attrs, postfix_attrs), struct_info); |
1576dec7 | 2833 | ret.kind = ctsk_tagdef; |
a75b1c71 | 2834 | ret.expr = NULL_TREE; |
2835 | ret.expr_const_operands = true; | |
6198e8f6 | 2836 | timevar_pop (TV_PARSE_STRUCT); |
1576dec7 | 2837 | return ret; |
2838 | } | |
2839 | else if (!ident) | |
2840 | { | |
2841 | c_parser_error (parser, "expected %<{%>"); | |
2842 | ret.spec = error_mark_node; | |
2843 | ret.kind = ctsk_tagref; | |
a75b1c71 | 2844 | ret.expr = NULL_TREE; |
2845 | ret.expr_const_operands = true; | |
b6903102 | 2846 | return ret; |
1576dec7 | 2847 | } |
e60a6f7b | 2848 | ret = parser_xref_tag (ident_loc, code, ident); |
1576dec7 | 2849 | return ret; |
2850 | } | |
2851 | ||
2852 | /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without* | |
2853 | the trailing semicolon. | |
2854 | ||
2855 | struct-declaration: | |
2856 | specifier-qualifier-list struct-declarator-list | |
f80e7755 | 2857 | static_assert-declaration-no-semi |
1576dec7 | 2858 | |
2859 | specifier-qualifier-list: | |
2860 | type-specifier specifier-qualifier-list[opt] | |
2861 | type-qualifier specifier-qualifier-list[opt] | |
2862 | attributes specifier-qualifier-list[opt] | |
2863 | ||
2864 | struct-declarator-list: | |
2865 | struct-declarator | |
2866 | struct-declarator-list , attributes[opt] struct-declarator | |
2867 | ||
2868 | struct-declarator: | |
2869 | declarator attributes[opt] | |
2870 | declarator[opt] : constant-expression attributes[opt] | |
2871 | ||
2872 | GNU extensions: | |
2873 | ||
2874 | struct-declaration: | |
2875 | __extension__ struct-declaration | |
2876 | specifier-qualifier-list | |
2877 | ||
2878 | Unlike the ISO C syntax, semicolons are handled elsewhere. The use | |
2879 | of attributes where shown is a GNU extension. In GNU C, we accept | |
2880 | any expression without commas in the syntax (assignment | |
2881 | expressions, not just conditional expressions); assignment | |
2882 | expressions will be diagnosed as non-constant. */ | |
2883 | ||
2884 | static tree | |
2885 | c_parser_struct_declaration (c_parser *parser) | |
2886 | { | |
2887 | struct c_declspecs *specs; | |
2888 | tree prefix_attrs; | |
2889 | tree all_prefix_attrs; | |
2890 | tree decls; | |
be9eba16 | 2891 | location_t decl_loc; |
1576dec7 | 2892 | if (c_parser_next_token_is_keyword (parser, RID_EXTENSION)) |
2893 | { | |
2894 | int ext; | |
2895 | tree decl; | |
2896 | ext = disable_extension_diagnostics (); | |
2897 | c_parser_consume_token (parser); | |
2898 | decl = c_parser_struct_declaration (parser); | |
2899 | restore_extension_diagnostics (ext); | |
2900 | return decl; | |
2901 | } | |
f80e7755 | 2902 | if (c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT)) |
2903 | { | |
2904 | c_parser_static_assert_declaration_no_semi (parser); | |
2905 | return NULL_TREE; | |
2906 | } | |
1576dec7 | 2907 | specs = build_null_declspecs (); |
be9eba16 | 2908 | decl_loc = c_parser_peek_token (parser)->location; |
12f86df0 | 2909 | /* Strictly by the standard, we shouldn't allow _Alignas here, |
2910 | but it appears to have been intended to allow it there, so | |
2911 | we're keeping it as it is until WG14 reaches a conclusion | |
2912 | of N1731. | |
2913 | <http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1731.pdf> */ | |
43d03c23 | 2914 | c_parser_declspecs (parser, specs, false, true, true, |
4fba5eb9 | 2915 | true, false, cla_nonabstract_decl); |
1576dec7 | 2916 | if (parser->error) |
b6903102 | 2917 | return NULL_TREE; |
1576dec7 | 2918 | if (!specs->declspecs_seen_p) |
2919 | { | |
2920 | c_parser_error (parser, "expected specifier-qualifier-list"); | |
2921 | return NULL_TREE; | |
2922 | } | |
2923 | finish_declspecs (specs); | |
a25b333d | 2924 | if (c_parser_next_token_is (parser, CPP_SEMICOLON) |
2925 | || c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) | |
1576dec7 | 2926 | { |
2927 | tree ret; | |
ae5ead32 | 2928 | if (specs->typespec_kind == ctsk_none) |
1576dec7 | 2929 | { |
29438999 | 2930 | pedwarn (decl_loc, OPT_Wpedantic, |
21ca8540 | 2931 | "ISO C forbids member declarations with no members"); |
1576dec7 | 2932 | shadow_tag_warned (specs, pedantic); |
2933 | ret = NULL_TREE; | |
2934 | } | |
2935 | else | |
2936 | { | |
2937 | /* Support for unnamed structs or unions as members of | |
2938 | structs or unions (which is [a] useful and [b] supports | |
2939 | MS P-SDK). */ | |
e47ffaae | 2940 | tree attrs = NULL; |
d520c1f2 | 2941 | |
2942 | ret = grokfield (c_parser_peek_token (parser)->location, | |
2943 | build_id_declarator (NULL_TREE), specs, | |
e47ffaae | 2944 | NULL_TREE, &attrs); |
9a21152d | 2945 | if (ret) |
2946 | decl_attributes (&ret, attrs, 0); | |
1576dec7 | 2947 | } |
2948 | return ret; | |
2949 | } | |
b02d8973 | 2950 | |
2951 | /* Provide better error recovery. Note that a type name here is valid, | |
2952 | and will be treated as a field name. */ | |
2953 | if (specs->typespec_kind == ctsk_tagdef | |
2954 | && TREE_CODE (specs->type) != ENUMERAL_TYPE | |
2955 | && c_parser_next_token_starts_declspecs (parser) | |
2956 | && !c_parser_next_token_is (parser, CPP_NAME)) | |
2957 | { | |
2958 | c_parser_error (parser, "expected %<;%>, identifier or %<(%>"); | |
2959 | parser->error = false; | |
2960 | return NULL_TREE; | |
2961 | } | |
2962 | ||
1576dec7 | 2963 | pending_xref_error (); |
2964 | prefix_attrs = specs->attrs; | |
2965 | all_prefix_attrs = prefix_attrs; | |
2966 | specs->attrs = NULL_TREE; | |
2967 | decls = NULL_TREE; | |
2968 | while (true) | |
2969 | { | |
2970 | /* Declaring one or more declarators or un-named bit-fields. */ | |
2971 | struct c_declarator *declarator; | |
2972 | bool dummy = false; | |
2973 | if (c_parser_next_token_is (parser, CPP_COLON)) | |
2974 | declarator = build_id_declarator (NULL_TREE); | |
2975 | else | |
ae5ead32 | 2976 | declarator = c_parser_declarator (parser, |
2977 | specs->typespec_kind != ctsk_none, | |
1576dec7 | 2978 | C_DTR_NORMAL, &dummy); |
2979 | if (declarator == NULL) | |
2980 | { | |
2981 | c_parser_skip_to_end_of_block_or_statement (parser); | |
2982 | break; | |
2983 | } | |
2984 | if (c_parser_next_token_is (parser, CPP_COLON) | |
2985 | || c_parser_next_token_is (parser, CPP_COMMA) | |
2986 | || c_parser_next_token_is (parser, CPP_SEMICOLON) | |
2987 | || c_parser_next_token_is (parser, CPP_CLOSE_BRACE) | |
2988 | || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)) | |
2989 | { | |
2990 | tree postfix_attrs = NULL_TREE; | |
2991 | tree width = NULL_TREE; | |
2992 | tree d; | |
2993 | if (c_parser_next_token_is (parser, CPP_COLON)) | |
2994 | { | |
2995 | c_parser_consume_token (parser); | |
2996 | width = c_parser_expr_no_commas (parser, NULL).value; | |
2997 | } | |
2998 | if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)) | |
2999 | postfix_attrs = c_parser_attributes (parser); | |
d520c1f2 | 3000 | d = grokfield (c_parser_peek_token (parser)->location, |
3001 | declarator, specs, width, &all_prefix_attrs); | |
1576dec7 | 3002 | decl_attributes (&d, chainon (postfix_attrs, |
3003 | all_prefix_attrs), 0); | |
1767a056 | 3004 | DECL_CHAIN (d) = decls; |
1576dec7 | 3005 | decls = d; |
3006 | if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)) | |
3007 | all_prefix_attrs = chainon (c_parser_attributes (parser), | |
3008 | prefix_attrs); | |
3009 | else | |
3010 | all_prefix_attrs = prefix_attrs; | |
3011 | if (c_parser_next_token_is (parser, CPP_COMMA)) | |
3012 | c_parser_consume_token (parser); | |
3013 | else if (c_parser_next_token_is (parser, CPP_SEMICOLON) | |
3014 | || c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) | |
3015 | { | |
3016 | /* Semicolon consumed in caller. */ | |
3017 | break; | |
3018 | } | |
3019 | else | |
3020 | { | |
3021 | c_parser_error (parser, "expected %<,%>, %<;%> or %<}%>"); | |
3022 | break; | |
3023 | } | |
3024 | } | |
3025 | else | |
3026 | { | |
3027 | c_parser_error (parser, | |
3028 | "expected %<:%>, %<,%>, %<;%>, %<}%> or " | |
3029 | "%<__attribute__%>"); | |
3030 | break; | |
3031 | } | |
3032 | } | |
3033 | return decls; | |
3034 | } | |
3035 | ||
3036 | /* Parse a typeof specifier (a GNU extension). | |
3037 | ||
3038 | typeof-specifier: | |
3039 | typeof ( expression ) | |
3040 | typeof ( type-name ) | |
3041 | */ | |
3042 | ||
3043 | static struct c_typespec | |
3044 | c_parser_typeof_specifier (c_parser *parser) | |
3045 | { | |
3046 | struct c_typespec ret; | |
3047 | ret.kind = ctsk_typeof; | |
3048 | ret.spec = error_mark_node; | |
a75b1c71 | 3049 | ret.expr = NULL_TREE; |
3050 | ret.expr_const_operands = true; | |
1576dec7 | 3051 | gcc_assert (c_parser_next_token_is_keyword (parser, RID_TYPEOF)); |
3052 | c_parser_consume_token (parser); | |
48d94ede | 3053 | c_inhibit_evaluation_warnings++; |
1576dec7 | 3054 | in_typeof++; |
3055 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
3056 | { | |
48d94ede | 3057 | c_inhibit_evaluation_warnings--; |
1576dec7 | 3058 | in_typeof--; |
3059 | return ret; | |
3060 | } | |
26ee9e7a | 3061 | if (c_parser_next_tokens_start_typename (parser, cla_prefer_id)) |
1576dec7 | 3062 | { |
3063 | struct c_type_name *type = c_parser_type_name (parser); | |
48d94ede | 3064 | c_inhibit_evaluation_warnings--; |
1576dec7 | 3065 | in_typeof--; |
3066 | if (type != NULL) | |
3067 | { | |
a75b1c71 | 3068 | ret.spec = groktypename (type, &ret.expr, &ret.expr_const_operands); |
1576dec7 | 3069 | pop_maybe_used (variably_modified_type_p (ret.spec, NULL_TREE)); |
3070 | } | |
3071 | } | |
3072 | else | |
3073 | { | |
32d33ab2 | 3074 | bool was_vm; |
be9eba16 | 3075 | location_t here = c_parser_peek_token (parser)->location; |
1576dec7 | 3076 | struct c_expr expr = c_parser_expression (parser); |
48d94ede | 3077 | c_inhibit_evaluation_warnings--; |
1576dec7 | 3078 | in_typeof--; |
3079 | if (TREE_CODE (expr.value) == COMPONENT_REF | |
3080 | && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1))) | |
e3b80d49 | 3081 | error_at (here, "%<typeof%> applied to a bit-field"); |
abc6c64f | 3082 | mark_exp_read (expr.value); |
1576dec7 | 3083 | ret.spec = TREE_TYPE (expr.value); |
32d33ab2 | 3084 | was_vm = variably_modified_type_p (ret.spec, NULL_TREE); |
a75b1c71 | 3085 | /* This is returned with the type so that when the type is |
3086 | evaluated, this can be evaluated. */ | |
3087 | if (was_vm) | |
3088 | ret.expr = c_fully_fold (expr.value, false, &ret.expr_const_operands); | |
32d33ab2 | 3089 | pop_maybe_used (was_vm); |
45c5b823 | 3090 | /* For use in macros such as those in <stdatomic.h>, remove all |
3091 | qualifiers from atomic types. (const can be an issue for more macros | |
3092 | using typeof than just the <stdatomic.h> ones.) */ | |
b560fabd | 3093 | if (ret.spec != error_mark_node && TYPE_ATOMIC (ret.spec)) |
45c5b823 | 3094 | ret.spec = c_build_qualified_type (ret.spec, TYPE_UNQUALIFIED); |
1576dec7 | 3095 | } |
3096 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
3097 | return ret; | |
3098 | } | |
3099 | ||
83e25171 | 3100 | /* Parse an alignment-specifier. |
3101 | ||
32074525 | 3102 | C11 6.7.5: |
83e25171 | 3103 | |
3104 | alignment-specifier: | |
3105 | _Alignas ( type-name ) | |
3106 | _Alignas ( constant-expression ) | |
3107 | */ | |
3108 | ||
3109 | static tree | |
3110 | c_parser_alignas_specifier (c_parser * parser) | |
3111 | { | |
3112 | tree ret = error_mark_node; | |
3113 | location_t loc = c_parser_peek_token (parser)->location; | |
3114 | gcc_assert (c_parser_next_token_is_keyword (parser, RID_ALIGNAS)); | |
3115 | c_parser_consume_token (parser); | |
508ea33a | 3116 | if (flag_isoc99) |
3117 | pedwarn_c99 (loc, OPT_Wpedantic, | |
83e25171 | 3118 | "ISO C99 does not support %<_Alignas%>"); |
508ea33a | 3119 | else |
3120 | pedwarn_c99 (loc, OPT_Wpedantic, | |
83e25171 | 3121 | "ISO C90 does not support %<_Alignas%>"); |
83e25171 | 3122 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) |
3123 | return ret; | |
3124 | if (c_parser_next_tokens_start_typename (parser, cla_prefer_id)) | |
3125 | { | |
3126 | struct c_type_name *type = c_parser_type_name (parser); | |
3127 | if (type != NULL) | |
a179a7dc | 3128 | ret = c_sizeof_or_alignof_type (loc, groktypename (type, NULL, NULL), |
3129 | false, true, 1); | |
83e25171 | 3130 | } |
3131 | else | |
3132 | ret = c_parser_expr_no_commas (parser, NULL).value; | |
3133 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
3134 | return ret; | |
3135 | } | |
3136 | ||
1576dec7 | 3137 | /* Parse a declarator, possibly an abstract declarator (C90 6.5.4, |
3138 | 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may | |
3139 | be redeclared; otherwise it may not. KIND indicates which kind of | |
3140 | declarator is wanted. Returns a valid declarator except in the | |
3141 | case of a syntax error in which case NULL is returned. *SEEN_ID is | |
3142 | set to true if an identifier being declared is seen; this is used | |
3143 | to diagnose bad forms of abstract array declarators and to | |
3144 | determine whether an identifier list is syntactically permitted. | |
3145 | ||
3146 | declarator: | |
3147 | pointer[opt] direct-declarator | |
3148 | ||
3149 | direct-declarator: | |
3150 | identifier | |
3151 | ( attributes[opt] declarator ) | |
3152 | direct-declarator array-declarator | |
3153 | direct-declarator ( parameter-type-list ) | |
3154 | direct-declarator ( identifier-list[opt] ) | |
3155 | ||
3156 | pointer: | |
3157 | * type-qualifier-list[opt] | |
3158 | * type-qualifier-list[opt] pointer | |
3159 | ||
3160 | type-qualifier-list: | |
3161 | type-qualifier | |
3162 | attributes | |
3163 | type-qualifier-list type-qualifier | |
3164 | type-qualifier-list attributes | |
3165 | ||
43d03c23 | 3166 | array-declarator: |
3167 | [ type-qualifier-list[opt] assignment-expression[opt] ] | |
3168 | [ static type-qualifier-list[opt] assignment-expression ] | |
3169 | [ type-qualifier-list static assignment-expression ] | |
3170 | [ type-qualifier-list[opt] * ] | |
3171 | ||
1576dec7 | 3172 | parameter-type-list: |
3173 | parameter-list | |
3174 | parameter-list , ... | |
3175 | ||
3176 | parameter-list: | |
3177 | parameter-declaration | |
3178 | parameter-list , parameter-declaration | |
3179 | ||
3180 | parameter-declaration: | |
3181 | declaration-specifiers declarator attributes[opt] | |
3182 | declaration-specifiers abstract-declarator[opt] attributes[opt] | |
3183 | ||
3184 | identifier-list: | |
3185 | identifier | |
3186 | identifier-list , identifier | |
3187 | ||
3188 | abstract-declarator: | |
3189 | pointer | |
3190 | pointer[opt] direct-abstract-declarator | |
3191 | ||
3192 | direct-abstract-declarator: | |
3193 | ( attributes[opt] abstract-declarator ) | |
3194 | direct-abstract-declarator[opt] array-declarator | |
3195 | direct-abstract-declarator[opt] ( parameter-type-list[opt] ) | |
3196 | ||
3197 | GNU extensions: | |
3198 | ||
3199 | direct-declarator: | |
3200 | direct-declarator ( parameter-forward-declarations | |
3201 | parameter-type-list[opt] ) | |
3202 | ||
3203 | direct-abstract-declarator: | |
a0c938f0 | 3204 | direct-abstract-declarator[opt] ( parameter-forward-declarations |
1576dec7 | 3205 | parameter-type-list[opt] ) |
3206 | ||
3207 | parameter-forward-declarations: | |
3208 | parameter-list ; | |
3209 | parameter-forward-declarations parameter-list ; | |
3210 | ||
3211 | The uses of attributes shown above are GNU extensions. | |
3212 | ||
3213 | Some forms of array declarator are not included in C99 in the | |
3214 | syntax for abstract declarators; these are disallowed elsewhere. | |
3215 | This may be a defect (DR#289). | |
3216 | ||
3217 | This function also accepts an omitted abstract declarator as being | |
3218 | an abstract declarator, although not part of the formal syntax. */ | |
3219 | ||
3220 | static struct c_declarator * | |
3221 | c_parser_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind, | |
3222 | bool *seen_id) | |
3223 | { | |
3224 | /* Parse any initial pointer part. */ | |
3225 | if (c_parser_next_token_is (parser, CPP_MULT)) | |
3226 | { | |
3227 | struct c_declspecs *quals_attrs = build_null_declspecs (); | |
3228 | struct c_declarator *inner; | |
3229 | c_parser_consume_token (parser); | |
43d03c23 | 3230 | c_parser_declspecs (parser, quals_attrs, false, false, true, |
4fba5eb9 | 3231 | false, false, cla_prefer_id); |
1576dec7 | 3232 | inner = c_parser_declarator (parser, type_seen_p, kind, seen_id); |
3233 | if (inner == NULL) | |
3234 | return NULL; | |
3235 | else | |
3236 | return make_pointer_declarator (quals_attrs, inner); | |
3237 | } | |
3238 | /* Now we have a direct declarator, direct abstract declarator or | |
3239 | nothing (which counts as a direct abstract declarator here). */ | |
3240 | return c_parser_direct_declarator (parser, type_seen_p, kind, seen_id); | |
3241 | } | |
3242 | ||
3243 | /* Parse a direct declarator or direct abstract declarator; arguments | |
3244 | as c_parser_declarator. */ | |
3245 | ||
3246 | static struct c_declarator * | |
3247 | c_parser_direct_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind, | |
3248 | bool *seen_id) | |
3249 | { | |
3250 | /* The direct declarator must start with an identifier (possibly | |
3251 | omitted) or a parenthesized declarator (possibly abstract). In | |
3252 | an ordinary declarator, initial parentheses must start a | |
3253 | parenthesized declarator. In an abstract declarator or parameter | |
3254 | declarator, they could start a parenthesized declarator or a | |
3255 | parameter list. To tell which, the open parenthesis and any | |
3256 | following attributes must be read. If a declaration specifier | |
3257 | follows, then it is a parameter list; if the specifier is a | |
3258 | typedef name, there might be an ambiguity about redeclaring it, | |
3259 | which is resolved in the direction of treating it as a typedef | |
3260 | name. If a close parenthesis follows, it is also an empty | |
3261 | parameter list, as the syntax does not permit empty abstract | |
442e3cb9 | 3262 | declarators. Otherwise, it is a parenthesized declarator (in |
1576dec7 | 3263 | which case the analysis may be repeated inside it, recursively). |
3264 | ||
3265 | ??? There is an ambiguity in a parameter declaration "int | |
3266 | (__attribute__((foo)) x)", where x is not a typedef name: it | |
3267 | could be an abstract declarator for a function, or declare x with | |
3268 | parentheses. The proper resolution of this ambiguity needs | |
3269 | documenting. At present we follow an accident of the old | |
3270 | parser's implementation, whereby the first parameter must have | |
3271 | some declaration specifiers other than just attributes. Thus as | |
442e3cb9 | 3272 | a parameter declaration it is treated as a parenthesized |
1576dec7 | 3273 | parameter named x, and as an abstract declarator it is |
3274 | rejected. | |
3275 | ||
3276 | ??? Also following the old parser, attributes inside an empty | |
3277 | parameter list are ignored, making it a list not yielding a | |
3278 | prototype, rather than giving an error or making it have one | |
3279 | parameter with implicit type int. | |
3280 | ||
3281 | ??? Also following the old parser, typedef names may be | |
3282 | redeclared in declarators, but not Objective-C class names. */ | |
3283 | ||
3284 | if (kind != C_DTR_ABSTRACT | |
3285 | && c_parser_next_token_is (parser, CPP_NAME) | |
3286 | && ((type_seen_p | |
e147d6aa | 3287 | && (c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME |
3288 | || c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME)) | |
1576dec7 | 3289 | || c_parser_peek_token (parser)->id_kind == C_ID_ID)) |
3290 | { | |
3291 | struct c_declarator *inner | |
3292 | = build_id_declarator (c_parser_peek_token (parser)->value); | |
3293 | *seen_id = true; | |
6342afac | 3294 | inner->id_loc = c_parser_peek_token (parser)->location; |
1576dec7 | 3295 | c_parser_consume_token (parser); |
3296 | return c_parser_direct_declarator_inner (parser, *seen_id, inner); | |
3297 | } | |
3298 | ||
3299 | if (kind != C_DTR_NORMAL | |
3300 | && c_parser_next_token_is (parser, CPP_OPEN_SQUARE)) | |
3301 | { | |
3302 | struct c_declarator *inner = build_id_declarator (NULL_TREE); | |
3303 | return c_parser_direct_declarator_inner (parser, *seen_id, inner); | |
3304 | } | |
3305 | ||
3306 | /* Either we are at the end of an abstract declarator, or we have | |
3307 | parentheses. */ | |
3308 | ||
3309 | if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) | |
3310 | { | |
3311 | tree attrs; | |
3312 | struct c_declarator *inner; | |
3313 | c_parser_consume_token (parser); | |
3314 | attrs = c_parser_attributes (parser); | |
3315 | if (kind != C_DTR_NORMAL | |
3316 | && (c_parser_next_token_starts_declspecs (parser) | |
3317 | || c_parser_next_token_is (parser, CPP_CLOSE_PAREN))) | |
3318 | { | |
3319 | struct c_arg_info *args | |
3320 | = c_parser_parms_declarator (parser, kind == C_DTR_NORMAL, | |
3321 | attrs); | |
3322 | if (args == NULL) | |
3323 | return NULL; | |
3324 | else | |
3325 | { | |
3326 | inner | |
3327 | = build_function_declarator (args, | |
3328 | build_id_declarator (NULL_TREE)); | |
3329 | return c_parser_direct_declarator_inner (parser, *seen_id, | |
3330 | inner); | |
3331 | } | |
3332 | } | |
3333 | /* A parenthesized declarator. */ | |
3334 | inner = c_parser_declarator (parser, type_seen_p, kind, seen_id); | |
3335 | if (inner != NULL && attrs != NULL) | |
3336 | inner = build_attrs_declarator (attrs, inner); | |
3337 | if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) | |
3338 | { | |
3339 | c_parser_consume_token (parser); | |
3340 | if (inner == NULL) | |
3341 | return NULL; | |
3342 | else | |
3343 | return c_parser_direct_declarator_inner (parser, *seen_id, inner); | |
3344 | } | |
3345 | else | |
3346 | { | |
3347 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, | |
3348 | "expected %<)%>"); | |
3349 | return NULL; | |
3350 | } | |
3351 | } | |
3352 | else | |
3353 | { | |
3354 | if (kind == C_DTR_NORMAL) | |
3355 | { | |
3356 | c_parser_error (parser, "expected identifier or %<(%>"); | |
3357 | return NULL; | |
3358 | } | |
3359 | else | |
3360 | return build_id_declarator (NULL_TREE); | |
3361 | } | |
3362 | } | |
3363 | ||
3364 | /* Parse part of a direct declarator or direct abstract declarator, | |
3365 | given that some (in INNER) has already been parsed; ID_PRESENT is | |
3366 | true if an identifier is present, false for an abstract | |
3367 | declarator. */ | |
3368 | ||
3369 | static struct c_declarator * | |
3370 | c_parser_direct_declarator_inner (c_parser *parser, bool id_present, | |
3371 | struct c_declarator *inner) | |
3372 | { | |
3373 | /* Parse a sequence of array declarators and parameter lists. */ | |
3374 | if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE)) | |
3375 | { | |
48e1416a | 3376 | location_t brace_loc = c_parser_peek_token (parser)->location; |
1576dec7 | 3377 | struct c_declarator *declarator; |
3378 | struct c_declspecs *quals_attrs = build_null_declspecs (); | |
3379 | bool static_seen; | |
3380 | bool star_seen; | |
b560fabd | 3381 | struct c_expr dimen; |
3382 | dimen.value = NULL_TREE; | |
3383 | dimen.original_code = ERROR_MARK; | |
3384 | dimen.original_type = NULL_TREE; | |
1576dec7 | 3385 | c_parser_consume_token (parser); |
43d03c23 | 3386 | c_parser_declspecs (parser, quals_attrs, false, false, true, |
4fba5eb9 | 3387 | false, false, cla_prefer_id); |
1576dec7 | 3388 | static_seen = c_parser_next_token_is_keyword (parser, RID_STATIC); |
3389 | if (static_seen) | |
3390 | c_parser_consume_token (parser); | |
3391 | if (static_seen && !quals_attrs->declspecs_seen_p) | |
43d03c23 | 3392 | c_parser_declspecs (parser, quals_attrs, false, false, true, |
4fba5eb9 | 3393 | false, false, cla_prefer_id); |
1576dec7 | 3394 | if (!quals_attrs->declspecs_seen_p) |
3395 | quals_attrs = NULL; | |
3396 | /* If "static" is present, there must be an array dimension. | |
3397 | Otherwise, there may be a dimension, "*", or no | |
3398 | dimension. */ | |
3399 | if (static_seen) | |
3400 | { | |
3401 | star_seen = false; | |
b560fabd | 3402 | dimen = c_parser_expr_no_commas (parser, NULL); |
1576dec7 | 3403 | } |
3404 | else | |
3405 | { | |
3406 | if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE)) | |
3407 | { | |
b560fabd | 3408 | dimen.value = NULL_TREE; |
1576dec7 | 3409 | star_seen = false; |
3410 | } | |
a89e6c15 | 3411 | else if (flag_cilkplus |
3c6d4197 | 3412 | && c_parser_next_token_is (parser, CPP_COLON)) |
3413 | { | |
b560fabd | 3414 | dimen.value = error_mark_node; |
3c6d4197 | 3415 | star_seen = false; |
3416 | error_at (c_parser_peek_token (parser)->location, | |
3417 | "array notations cannot be used in declaration"); | |
3418 | c_parser_consume_token (parser); | |
3419 | } | |
1576dec7 | 3420 | else if (c_parser_next_token_is (parser, CPP_MULT)) |
3421 | { | |
3422 | if (c_parser_peek_2nd_token (parser)->type == CPP_CLOSE_SQUARE) | |
3423 | { | |
b560fabd | 3424 | dimen.value = NULL_TREE; |
1576dec7 | 3425 | star_seen = true; |
3426 | c_parser_consume_token (parser); | |
3427 | } | |
3428 | else | |
3429 | { | |
3430 | star_seen = false; | |
b560fabd | 3431 | dimen = c_parser_expr_no_commas (parser, NULL); |
1576dec7 | 3432 | } |
3433 | } | |
3434 | else | |
3435 | { | |
3436 | star_seen = false; | |
b560fabd | 3437 | dimen = c_parser_expr_no_commas (parser, NULL); |
1576dec7 | 3438 | } |
3439 | } | |
3440 | if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE)) | |
3441 | c_parser_consume_token (parser); | |
a89e6c15 | 3442 | else if (flag_cilkplus |
3c6d4197 | 3443 | && c_parser_next_token_is (parser, CPP_COLON)) |
3444 | { | |
3445 | error_at (c_parser_peek_token (parser)->location, | |
3446 | "array notations cannot be used in declaration"); | |
3447 | c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL); | |
3448 | return NULL; | |
3449 | } | |
1576dec7 | 3450 | else |
3451 | { | |
3452 | c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, | |
3453 | "expected %<]%>"); | |
3454 | return NULL; | |
3455 | } | |
b560fabd | 3456 | if (dimen.value) |
3457 | dimen = convert_lvalue_to_rvalue (brace_loc, dimen, true, true); | |
3458 | declarator = build_array_declarator (brace_loc, dimen.value, quals_attrs, | |
e60a6f7b | 3459 | static_seen, star_seen); |
32d33ab2 | 3460 | if (declarator == NULL) |
3461 | return NULL; | |
e6c172ed | 3462 | inner = set_array_declarator_inner (declarator, inner); |
1576dec7 | 3463 | return c_parser_direct_declarator_inner (parser, id_present, inner); |
3464 | } | |
3465 | else if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) | |
3466 | { | |
3467 | tree attrs; | |
3468 | struct c_arg_info *args; | |
3469 | c_parser_consume_token (parser); | |
3470 | attrs = c_parser_attributes (parser); | |
3471 | args = c_parser_parms_declarator (parser, id_present, attrs); | |
3472 | if (args == NULL) | |
3473 | return NULL; | |
3474 | else | |
3475 | { | |
3476 | inner = build_function_declarator (args, inner); | |
3477 | return c_parser_direct_declarator_inner (parser, id_present, inner); | |
3478 | } | |
3479 | } | |
3480 | return inner; | |
3481 | } | |
3482 | ||
3483 | /* Parse a parameter list or identifier list, including the closing | |
3484 | parenthesis but not the opening one. ATTRS are the attributes at | |
3485 | the start of the list. ID_LIST_OK is true if an identifier list is | |
3486 | acceptable; such a list must not have attributes at the start. */ | |
3487 | ||
3488 | static struct c_arg_info * | |
3489 | c_parser_parms_declarator (c_parser *parser, bool id_list_ok, tree attrs) | |
3490 | { | |
3491 | push_scope (); | |
3492 | declare_parm_level (); | |
3493 | /* If the list starts with an identifier, it is an identifier list. | |
3494 | Otherwise, it is either a prototype list or an empty list. */ | |
3495 | if (id_list_ok | |
3496 | && !attrs | |
3497 | && c_parser_next_token_is (parser, CPP_NAME) | |
26ee9e7a | 3498 | && c_parser_peek_token (parser)->id_kind == C_ID_ID |
3499 | ||
3500 | /* Look ahead to detect typos in type names. */ | |
3501 | && c_parser_peek_2nd_token (parser)->type != CPP_NAME | |
3502 | && c_parser_peek_2nd_token (parser)->type != CPP_MULT | |
3503 | && c_parser_peek_2nd_token (parser)->type != CPP_OPEN_PAREN | |
3504 | && c_parser_peek_2nd_token (parser)->type != CPP_OPEN_SQUARE) | |
1576dec7 | 3505 | { |
caa9f6a7 | 3506 | tree list = NULL_TREE, *nextp = &list; |
1576dec7 | 3507 | while (c_parser_next_token_is (parser, CPP_NAME) |
3508 | && c_parser_peek_token (parser)->id_kind == C_ID_ID) | |
3509 | { | |
caa9f6a7 | 3510 | *nextp = build_tree_list (NULL_TREE, |
3511 | c_parser_peek_token (parser)->value); | |
3512 | nextp = & TREE_CHAIN (*nextp); | |
1576dec7 | 3513 | c_parser_consume_token (parser); |
3514 | if (c_parser_next_token_is_not (parser, CPP_COMMA)) | |
3515 | break; | |
3516 | c_parser_consume_token (parser); | |
3517 | if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) | |
3518 | { | |
3519 | c_parser_error (parser, "expected identifier"); | |
3520 | break; | |
3521 | } | |
3522 | } | |
3523 | if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) | |
3524 | { | |
cfbfcd0b | 3525 | struct c_arg_info *ret = build_arg_info (); |
1576dec7 | 3526 | ret->types = list; |
1576dec7 | 3527 | c_parser_consume_token (parser); |
3528 | pop_scope (); | |
3529 | return ret; | |
3530 | } | |
3531 | else | |
3532 | { | |
3533 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, | |
3534 | "expected %<)%>"); | |
3535 | pop_scope (); | |
3536 | return NULL; | |
3537 | } | |
3538 | } | |
3539 | else | |
3540 | { | |
4232a958 | 3541 | struct c_arg_info *ret = c_parser_parms_list_declarator (parser, attrs, |
3542 | NULL); | |
1576dec7 | 3543 | pop_scope (); |
3544 | return ret; | |
3545 | } | |
3546 | } | |
3547 | ||
3548 | /* Parse a parameter list (possibly empty), including the closing | |
3549 | parenthesis but not the opening one. ATTRS are the attributes at | |
4232a958 | 3550 | the start of the list. EXPR is NULL or an expression that needs to |
3551 | be evaluated for the side effects of array size expressions in the | |
3552 | parameters. */ | |
1576dec7 | 3553 | |
3554 | static struct c_arg_info * | |
4232a958 | 3555 | c_parser_parms_list_declarator (c_parser *parser, tree attrs, tree expr) |
1576dec7 | 3556 | { |
0e28b26d | 3557 | bool bad_parm = false; |
4232a958 | 3558 | |
1576dec7 | 3559 | /* ??? Following the old parser, forward parameter declarations may |
3560 | use abstract declarators, and if no real parameter declarations | |
3561 | follow the forward declarations then this is not diagnosed. Also | |
3562 | note as above that attributes are ignored as the only contents of | |
3563 | the parentheses, or as the only contents after forward | |
3564 | declarations. */ | |
3565 | if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) | |
3566 | { | |
cfbfcd0b | 3567 | struct c_arg_info *ret = build_arg_info (); |
1576dec7 | 3568 | c_parser_consume_token (parser); |
3569 | return ret; | |
3570 | } | |
3571 | if (c_parser_next_token_is (parser, CPP_ELLIPSIS)) | |
3572 | { | |
cfbfcd0b | 3573 | struct c_arg_info *ret = build_arg_info (); |
c7964868 | 3574 | |
3575 | if (flag_allow_parameterless_variadic_functions) | |
3576 | { | |
3577 | /* F (...) is allowed. */ | |
3578 | ret->types = NULL_TREE; | |
3579 | } | |
3580 | else | |
3581 | { | |
3582 | /* Suppress -Wold-style-definition for this case. */ | |
3583 | ret->types = error_mark_node; | |
3584 | error_at (c_parser_peek_token (parser)->location, | |
3585 | "ISO C requires a named argument before %<...%>"); | |
3586 | } | |
1576dec7 | 3587 | c_parser_consume_token (parser); |
3588 | if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) | |
3589 | { | |
3590 | c_parser_consume_token (parser); | |
3591 | return ret; | |
3592 | } | |
3593 | else | |
3594 | { | |
3595 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, | |
3596 | "expected %<)%>"); | |
3597 | return NULL; | |
3598 | } | |
3599 | } | |
3600 | /* Nonempty list of parameters, either terminated with semicolon | |
3601 | (forward declarations; recurse) or with close parenthesis (normal | |
3602 | function) or with ", ... )" (variadic function). */ | |
3603 | while (true) | |
3604 | { | |
3605 | /* Parse a parameter. */ | |
3606 | struct c_parm *parm = c_parser_parameter_declaration (parser, attrs); | |
3607 | attrs = NULL_TREE; | |
0e28b26d | 3608 | if (parm == NULL) |
3609 | bad_parm = true; | |
3610 | else | |
4232a958 | 3611 | push_parm_decl (parm, &expr); |
1576dec7 | 3612 | if (c_parser_next_token_is (parser, CPP_SEMICOLON)) |
3613 | { | |
3614 | tree new_attrs; | |
3615 | c_parser_consume_token (parser); | |
c4a8f0ba | 3616 | mark_forward_parm_decls (); |
1576dec7 | 3617 | new_attrs = c_parser_attributes (parser); |
4232a958 | 3618 | return c_parser_parms_list_declarator (parser, new_attrs, expr); |
1576dec7 | 3619 | } |
3620 | if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) | |
3621 | { | |
3622 | c_parser_consume_token (parser); | |
0e28b26d | 3623 | if (bad_parm) |
4232a958 | 3624 | return NULL; |
0e28b26d | 3625 | else |
4232a958 | 3626 | return get_parm_info (false, expr); |
1576dec7 | 3627 | } |
3628 | if (!c_parser_require (parser, CPP_COMMA, | |
3629 | "expected %<;%>, %<,%> or %<)%>")) | |
3630 | { | |
3631 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); | |
3632 | return NULL; | |
3633 | } | |
3634 | if (c_parser_next_token_is (parser, CPP_ELLIPSIS)) | |
3635 | { | |
3636 | c_parser_consume_token (parser); | |
3637 | if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) | |
3638 | { | |
3639 | c_parser_consume_token (parser); | |
0e28b26d | 3640 | if (bad_parm) |
4232a958 | 3641 | return NULL; |
0e28b26d | 3642 | else |
4232a958 | 3643 | return get_parm_info (true, expr); |
1576dec7 | 3644 | } |
3645 | else | |
3646 | { | |
3647 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, | |
3648 | "expected %<)%>"); | |
3649 | return NULL; | |
3650 | } | |
3651 | } | |
3652 | } | |
3653 | } | |
3654 | ||
3655 | /* Parse a parameter declaration. ATTRS are the attributes at the | |
3656 | start of the declaration if it is the first parameter. */ | |
3657 | ||
3658 | static struct c_parm * | |
3659 | c_parser_parameter_declaration (c_parser *parser, tree attrs) | |
3660 | { | |
3661 | struct c_declspecs *specs; | |
3662 | struct c_declarator *declarator; | |
3663 | tree prefix_attrs; | |
3664 | tree postfix_attrs = NULL_TREE; | |
3665 | bool dummy = false; | |
dd8e8868 | 3666 | |
3667 | /* Accept #pragmas between parameter declarations. */ | |
3668 | while (c_parser_next_token_is (parser, CPP_PRAGMA)) | |
bc7bff74 | 3669 | c_parser_pragma (parser, pragma_param); |
dd8e8868 | 3670 | |
1576dec7 | 3671 | if (!c_parser_next_token_starts_declspecs (parser)) |
3672 | { | |
0e28b26d | 3673 | c_token *token = c_parser_peek_token (parser); |
3674 | if (parser->error) | |
3675 | return NULL; | |
3676 | c_parser_set_source_position_from_token (token); | |
26ee9e7a | 3677 | if (c_parser_next_tokens_start_typename (parser, cla_prefer_type)) |
0e28b26d | 3678 | { |
8f1128f8 | 3679 | error_at (token->location, "unknown type name %qE", token->value); |
0e28b26d | 3680 | parser->error = true; |
3681 | } | |
1576dec7 | 3682 | /* ??? In some Objective-C cases '...' isn't applicable so there |
3683 | should be a different message. */ | |
0e28b26d | 3684 | else |
3685 | c_parser_error (parser, | |
3686 | "expected declaration specifiers or %<...%>"); | |
1576dec7 | 3687 | c_parser_skip_to_end_of_parameter (parser); |
3688 | return NULL; | |
3689 | } | |
3690 | specs = build_null_declspecs (); | |
3691 | if (attrs) | |
3692 | { | |
a60f3e81 | 3693 | declspecs_add_attrs (input_location, specs, attrs); |
1576dec7 | 3694 | attrs = NULL_TREE; |
3695 | } | |
4fba5eb9 | 3696 | c_parser_declspecs (parser, specs, true, true, true, true, false, |
43d03c23 | 3697 | cla_nonabstract_decl); |
1576dec7 | 3698 | finish_declspecs (specs); |
3699 | pending_xref_error (); | |
3700 | prefix_attrs = specs->attrs; | |
3701 | specs->attrs = NULL_TREE; | |
ae5ead32 | 3702 | declarator = c_parser_declarator (parser, |
3703 | specs->typespec_kind != ctsk_none, | |
1576dec7 | 3704 | C_DTR_PARM, &dummy); |
3705 | if (declarator == NULL) | |
3706 | { | |
3707 | c_parser_skip_until_found (parser, CPP_COMMA, NULL); | |
3708 | return NULL; | |
3709 | } | |
3710 | if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)) | |
3711 | postfix_attrs = c_parser_attributes (parser); | |
3712 | return build_c_parm (specs, chainon (postfix_attrs, prefix_attrs), | |
3713 | declarator); | |
3714 | } | |
3715 | ||
3716 | /* Parse a string literal in an asm expression. It should not be | |
3717 | translated, and wide string literals are an error although | |
3718 | permitted by the syntax. This is a GNU extension. | |
3719 | ||
3720 | asm-string-literal: | |
3721 | string-literal | |
3722 | ||
3723 | ??? At present, following the old parser, the caller needs to have | |
8115b8be | 3724 | set lex_untranslated_string to 1. It would be better to follow the |
3725 | C++ parser rather than using this kludge. */ | |
1576dec7 | 3726 | |
3727 | static tree | |
3728 | c_parser_asm_string_literal (c_parser *parser) | |
3729 | { | |
3730 | tree str; | |
88c86c27 | 3731 | int save_flag = warn_overlength_strings; |
3732 | warn_overlength_strings = 0; | |
1576dec7 | 3733 | if (c_parser_next_token_is (parser, CPP_STRING)) |
3734 | { | |
3735 | str = c_parser_peek_token (parser)->value; | |
3736 | c_parser_consume_token (parser); | |
3737 | } | |
3738 | else if (c_parser_next_token_is (parser, CPP_WSTRING)) | |
3739 | { | |
e3b80d49 | 3740 | error_at (c_parser_peek_token (parser)->location, |
3741 | "wide string literal in %<asm%>"); | |
1576dec7 | 3742 | str = build_string (1, ""); |
3743 | c_parser_consume_token (parser); | |
3744 | } | |
3745 | else | |
3746 | { | |
3747 | c_parser_error (parser, "expected string literal"); | |
3748 | str = NULL_TREE; | |
3749 | } | |
88c86c27 | 3750 | warn_overlength_strings = save_flag; |
1576dec7 | 3751 | return str; |
3752 | } | |
3753 | ||
3754 | /* Parse a simple asm expression. This is used in restricted | |
3755 | contexts, where a full expression with inputs and outputs does not | |
3756 | make sense. This is a GNU extension. | |
3757 | ||
3758 | simple-asm-expr: | |
3759 | asm ( asm-string-literal ) | |
3760 | */ | |
3761 | ||
3762 | static tree | |
3763 | c_parser_simple_asm_expr (c_parser *parser) | |
3764 | { | |
3765 | tree str; | |
3766 | gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM)); | |
3767 | /* ??? Follow the C++ parser rather than using the | |
8115b8be | 3768 | lex_untranslated_string kludge. */ |
3769 | parser->lex_untranslated_string = true; | |
1576dec7 | 3770 | c_parser_consume_token (parser); |
3771 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
3772 | { | |
8115b8be | 3773 | parser->lex_untranslated_string = false; |
1576dec7 | 3774 | return NULL_TREE; |
3775 | } | |
3776 | str = c_parser_asm_string_literal (parser); | |
8115b8be | 3777 | parser->lex_untranslated_string = false; |
1576dec7 | 3778 | if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>")) |
3779 | { | |
3780 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); | |
3781 | return NULL_TREE; | |
3782 | } | |
3783 | return str; | |
3784 | } | |
3785 | ||
4c0315d0 | 3786 | static tree |
3787 | c_parser_attribute_any_word (c_parser *parser) | |
3788 | { | |
3789 | tree attr_name = NULL_TREE; | |
3790 | ||
3791 | if (c_parser_next_token_is (parser, CPP_KEYWORD)) | |
3792 | { | |
3793 | /* ??? See comment above about what keywords are accepted here. */ | |
3794 | bool ok; | |
3795 | switch (c_parser_peek_token (parser)->keyword) | |
3796 | { | |
3797 | case RID_STATIC: | |
3798 | case RID_UNSIGNED: | |
3799 | case RID_LONG: | |
4c0315d0 | 3800 | case RID_CONST: |
3801 | case RID_EXTERN: | |
3802 | case RID_REGISTER: | |
3803 | case RID_TYPEDEF: | |
3804 | case RID_SHORT: | |
3805 | case RID_INLINE: | |
3806 | case RID_NORETURN: | |
3807 | case RID_VOLATILE: | |
3808 | case RID_SIGNED: | |
3809 | case RID_AUTO: | |
3810 | case RID_RESTRICT: | |
3811 | case RID_COMPLEX: | |
3812 | case RID_THREAD: | |
3813 | case RID_INT: | |
3814 | case RID_CHAR: | |
3815 | case RID_FLOAT: | |
3816 | case RID_DOUBLE: | |
3817 | case RID_VOID: | |
3818 | case RID_DFLOAT32: | |
3819 | case RID_DFLOAT64: | |
3820 | case RID_DFLOAT128: | |
3821 | case RID_BOOL: | |
3822 | case RID_FRACT: | |
3823 | case RID_ACCUM: | |
3824 | case RID_SAT: | |
3825 | case RID_TRANSACTION_ATOMIC: | |
3826 | case RID_TRANSACTION_CANCEL: | |
b560fabd | 3827 | case RID_ATOMIC: |
4fba5eb9 | 3828 | case RID_AUTO_TYPE: |
9f75f026 | 3829 | case RID_INT_N_0: |
3830 | case RID_INT_N_1: | |
3831 | case RID_INT_N_2: | |
3832 | case RID_INT_N_3: | |
4c0315d0 | 3833 | ok = true; |
3834 | break; | |
3835 | default: | |
3836 | ok = false; | |
3837 | break; | |
3838 | } | |
3839 | if (!ok) | |
3840 | return NULL_TREE; | |
3841 | ||
3842 | /* Accept __attribute__((__const)) as __attribute__((const)) etc. */ | |
3843 | attr_name = ridpointers[(int) c_parser_peek_token (parser)->keyword]; | |
3844 | } | |
3845 | else if (c_parser_next_token_is (parser, CPP_NAME)) | |
3846 | attr_name = c_parser_peek_token (parser)->value; | |
3847 | ||
3848 | return attr_name; | |
3849 | } | |
3850 | ||
74acc703 | 3851 | /* Returns true of NAME is an IDENTIFIER_NODE with identiifer "vector," |
3852 | "__vector" or "__vector__." */ | |
3853 | ||
3854 | static inline bool | |
3855 | is_cilkplus_vector_p (tree name) | |
3856 | { | |
a89e6c15 | 3857 | if (flag_cilkplus && is_attribute_p ("vector", name)) |
74acc703 | 3858 | return true; |
3859 | return false; | |
3860 | } | |
3861 | ||
3862 | #define CILK_SIMD_FN_CLAUSE_MASK \ | |
3863 | ((OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_VECTORLENGTH) \ | |
3864 | | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_LINEAR) \ | |
3865 | | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_UNIFORM) \ | |
3866 | | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_MASK) \ | |
3867 | | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_NOMASK)) | |
3868 | ||
3869 | /* Parses the vector attribute of SIMD enabled functions in Cilk Plus. | |
3870 | VEC_TOKEN is the "vector" token that is replaced with "simd" and | |
3871 | pushed into the token list. | |
3872 | Syntax: | |
3873 | vector | |
3874 | vector (<vector attributes>). */ | |
3875 | ||
3876 | static void | |
3877 | c_parser_cilk_simd_fn_vector_attrs (c_parser *parser, c_token vec_token) | |
3878 | { | |
3879 | gcc_assert (is_cilkplus_vector_p (vec_token.value)); | |
3880 | ||
3881 | int paren_scope = 0; | |
3882 | vec_safe_push (parser->cilk_simd_fn_tokens, vec_token); | |
3883 | /* Consume the "vector" token. */ | |
3884 | c_parser_consume_token (parser); | |
3885 | ||
3886 | if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) | |
3887 | { | |
3888 | c_parser_consume_token (parser); | |
3889 | paren_scope++; | |
3890 | } | |
3891 | while (paren_scope > 0) | |
3892 | { | |
3893 | c_token *token = c_parser_peek_token (parser); | |
3894 | if (token->type == CPP_OPEN_PAREN) | |
3895 | paren_scope++; | |
3896 | else if (token->type == CPP_CLOSE_PAREN) | |
3897 | paren_scope--; | |
3898 | /* Do not push the last ')' since we are not pushing the '('. */ | |
3899 | if (!(token->type == CPP_CLOSE_PAREN && paren_scope == 0)) | |
3900 | vec_safe_push (parser->cilk_simd_fn_tokens, *token); | |
3901 | c_parser_consume_token (parser); | |
3902 | } | |
3903 | ||
3904 | /* Since we are converting an attribute to a pragma, we need to end the | |
3905 | attribute with PRAGMA_EOL. */ | |
3906 | c_token eol_token; | |
3907 | memset (&eol_token, 0, sizeof (eol_token)); | |
3908 | eol_token.type = CPP_PRAGMA_EOL; | |
3909 | vec_safe_push (parser->cilk_simd_fn_tokens, eol_token); | |
3910 | } | |
3911 | ||
3912 | /* Add 2 CPP_EOF at the end of PARSER->ELEM_FN_TOKENS vector. */ | |
3913 | ||
3914 | static void | |
3915 | c_finish_cilk_simd_fn_tokens (c_parser *parser) | |
3916 | { | |
3917 | c_token last_token = parser->cilk_simd_fn_tokens->last (); | |
3918 | ||
3919 | /* c_parser_attributes is called in several places, so if these EOF | |
3920 | tokens are already inserted, then don't do them again. */ | |
3921 | if (last_token.type == CPP_EOF) | |
3922 | return; | |
3923 | ||
3924 | /* Two CPP_EOF token are added as a safety net since the normal C | |
3925 | front-end has two token look-ahead. */ | |
3926 | c_token eof_token; | |
3927 | eof_token.type = CPP_EOF; | |
3928 | vec_safe_push (parser->cilk_simd_fn_tokens, eof_token); | |
3929 | vec_safe_push (parser->cilk_simd_fn_tokens, eof_token); | |
3930 | } | |
3931 | ||
1576dec7 | 3932 | /* Parse (possibly empty) attributes. This is a GNU extension. |
3933 | ||
3934 | attributes: | |
3935 | empty | |
3936 | attributes attribute | |
3937 | ||
3938 | attribute: | |
3939 | __attribute__ ( ( attribute-list ) ) | |
3940 | ||
3941 | attribute-list: | |
3942 | attrib | |
3943 | attribute_list , attrib | |
3944 | ||
3945 | attrib: | |
3946 | empty | |
3947 | any-word | |
3948 | any-word ( identifier ) | |
3949 | any-word ( identifier , nonempty-expr-list ) | |
3950 | any-word ( expr-list ) | |
3951 | ||
3952 | where the "identifier" must not be declared as a type, and | |
3953 | "any-word" may be any identifier (including one declared as a | |
3954 | type), a reserved word storage class specifier, type specifier or | |
3955 | type qualifier. ??? This still leaves out most reserved keywords | |
3956 | (following the old parser), shouldn't we include them, and why not | |
3957 | allow identifiers declared as types to start the arguments? */ | |
3958 | ||
3959 | static tree | |
3960 | c_parser_attributes (c_parser *parser) | |
3961 | { | |
3962 | tree attrs = NULL_TREE; | |
3963 | while (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)) | |
3964 | { | |
3965 | /* ??? Follow the C++ parser rather than using the | |
8115b8be | 3966 | lex_untranslated_string kludge. */ |
3967 | parser->lex_untranslated_string = true; | |
1576dec7 | 3968 | c_parser_consume_token (parser); |
3969 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
3970 | { | |
8115b8be | 3971 | parser->lex_untranslated_string = false; |
1576dec7 | 3972 | return attrs; |
3973 | } | |
3974 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
3975 | { | |
8115b8be | 3976 | parser->lex_untranslated_string = false; |
1576dec7 | 3977 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); |
3978 | return attrs; | |
3979 | } | |
3980 | /* Parse the attribute list. */ | |
3981 | while (c_parser_next_token_is (parser, CPP_COMMA) | |
3982 | || c_parser_next_token_is (parser, CPP_NAME) | |
3983 | || c_parser_next_token_is (parser, CPP_KEYWORD)) | |
3984 | { | |
3985 | tree attr, attr_name, attr_args; | |
f1f41a6c | 3986 | vec<tree, va_gc> *expr_list; |
1576dec7 | 3987 | if (c_parser_next_token_is (parser, CPP_COMMA)) |
3988 | { | |
3989 | c_parser_consume_token (parser); | |
3990 | continue; | |
3991 | } | |
4c0315d0 | 3992 | |
3993 | attr_name = c_parser_attribute_any_word (parser); | |
3994 | if (attr_name == NULL) | |
3995 | break; | |
74acc703 | 3996 | if (is_cilkplus_vector_p (attr_name)) |
3997 | { | |
3998 | c_token *v_token = c_parser_peek_token (parser); | |
3999 | c_parser_cilk_simd_fn_vector_attrs (parser, *v_token); | |
4000 | continue; | |
4001 | } | |
1576dec7 | 4002 | c_parser_consume_token (parser); |
4003 | if (c_parser_next_token_is_not (parser, CPP_OPEN_PAREN)) | |
4004 | { | |
4005 | attr = build_tree_list (attr_name, NULL_TREE); | |
4006 | attrs = chainon (attrs, attr); | |
4007 | continue; | |
4008 | } | |
4009 | c_parser_consume_token (parser); | |
4010 | /* Parse the attribute contents. If they start with an | |
4011 | identifier which is followed by a comma or close | |
4012 | parenthesis, then the arguments start with that | |
1f6616ee | 4013 | identifier; otherwise they are an expression list. |
4014 | In objective-c the identifier may be a classname. */ | |
1576dec7 | 4015 | if (c_parser_next_token_is (parser, CPP_NAME) |
1f6616ee | 4016 | && (c_parser_peek_token (parser)->id_kind == C_ID_ID |
3e5a8b00 | 4017 | || (c_dialect_objc () |
4018 | && c_parser_peek_token (parser)->id_kind | |
4019 | == C_ID_CLASSNAME)) | |
1576dec7 | 4020 | && ((c_parser_peek_2nd_token (parser)->type == CPP_COMMA) |
4021 | || (c_parser_peek_2nd_token (parser)->type | |
3e5a8b00 | 4022 | == CPP_CLOSE_PAREN)) |
4023 | && (attribute_takes_identifier_p (attr_name) | |
4024 | || (c_dialect_objc () | |
4025 | && c_parser_peek_token (parser)->id_kind | |
4026 | == C_ID_CLASSNAME))) | |
1576dec7 | 4027 | { |
4028 | tree arg1 = c_parser_peek_token (parser)->value; | |
4029 | c_parser_consume_token (parser); | |
4030 | if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) | |
4031 | attr_args = build_tree_list (NULL_TREE, arg1); | |
4032 | else | |
4033 | { | |
b9c74b4d | 4034 | tree tree_list; |
1576dec7 | 4035 | c_parser_consume_token (parser); |
f003f5dc | 4036 | expr_list = c_parser_expr_list (parser, false, true, |
ec761d5a | 4037 | NULL, NULL, NULL, NULL); |
f352a3fb | 4038 | tree_list = build_tree_list_vec (expr_list); |
b9c74b4d | 4039 | attr_args = tree_cons (NULL_TREE, arg1, tree_list); |
f352a3fb | 4040 | release_tree_vector (expr_list); |
1576dec7 | 4041 | } |
4042 | } | |
4043 | else | |
4044 | { | |
4045 | if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) | |
4046 | attr_args = NULL_TREE; | |
4047 | else | |
b9c74b4d | 4048 | { |
f003f5dc | 4049 | expr_list = c_parser_expr_list (parser, false, true, |
ec761d5a | 4050 | NULL, NULL, NULL, NULL); |
f352a3fb | 4051 | attr_args = build_tree_list_vec (expr_list); |
4052 | release_tree_vector (expr_list); | |
b9c74b4d | 4053 | } |
1576dec7 | 4054 | } |
4055 | attr = build_tree_list (attr_name, attr_args); | |
4056 | if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) | |
4057 | c_parser_consume_token (parser); | |
4058 | else | |
4059 | { | |
8115b8be | 4060 | parser->lex_untranslated_string = false; |
1576dec7 | 4061 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, |
4062 | "expected %<)%>"); | |
4063 | return attrs; | |
4064 | } | |
4065 | attrs = chainon (attrs, attr); | |
4066 | } | |
4067 | if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) | |
4068 | c_parser_consume_token (parser); | |
4069 | else | |
4070 | { | |
8115b8be | 4071 | parser->lex_untranslated_string = false; |
1576dec7 | 4072 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, |
4073 | "expected %<)%>"); | |
4074 | return attrs; | |
4075 | } | |
4076 | if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) | |
4077 | c_parser_consume_token (parser); | |
4078 | else | |
4079 | { | |
8115b8be | 4080 | parser->lex_untranslated_string = false; |
1576dec7 | 4081 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, |
4082 | "expected %<)%>"); | |
4083 | return attrs; | |
4084 | } | |
8115b8be | 4085 | parser->lex_untranslated_string = false; |
1576dec7 | 4086 | } |
74acc703 | 4087 | |
a89e6c15 | 4088 | if (flag_cilkplus && !vec_safe_is_empty (parser->cilk_simd_fn_tokens)) |
74acc703 | 4089 | c_finish_cilk_simd_fn_tokens (parser); |
1576dec7 | 4090 | return attrs; |
4091 | } | |
4092 | ||
4093 | /* Parse a type name (C90 6.5.5, C99 6.7.6). | |
4094 | ||
4095 | type-name: | |
4096 | specifier-qualifier-list abstract-declarator[opt] | |
4097 | */ | |
4098 | ||
4099 | static struct c_type_name * | |
4100 | c_parser_type_name (c_parser *parser) | |
4101 | { | |
4102 | struct c_declspecs *specs = build_null_declspecs (); | |
4103 | struct c_declarator *declarator; | |
4104 | struct c_type_name *ret; | |
4105 | bool dummy = false; | |
4fba5eb9 | 4106 | c_parser_declspecs (parser, specs, false, true, true, false, false, |
43d03c23 | 4107 | cla_prefer_type); |
1576dec7 | 4108 | if (!specs->declspecs_seen_p) |
4109 | { | |
4110 | c_parser_error (parser, "expected specifier-qualifier-list"); | |
4111 | return NULL; | |
4112 | } | |
26ee9e7a | 4113 | if (specs->type != error_mark_node) |
4114 | { | |
4115 | pending_xref_error (); | |
4116 | finish_declspecs (specs); | |
4117 | } | |
ae5ead32 | 4118 | declarator = c_parser_declarator (parser, |
4119 | specs->typespec_kind != ctsk_none, | |
1576dec7 | 4120 | C_DTR_ABSTRACT, &dummy); |
4121 | if (declarator == NULL) | |
4122 | return NULL; | |
4123 | ret = XOBNEW (&parser_obstack, struct c_type_name); | |
4124 | ret->specs = specs; | |
4125 | ret->declarator = declarator; | |
4126 | return ret; | |
4127 | } | |
4128 | ||
4129 | /* Parse an initializer (C90 6.5.7, C99 6.7.8). | |
4130 | ||
4131 | initializer: | |
4132 | assignment-expression | |
4133 | { initializer-list } | |
4134 | { initializer-list , } | |
4135 | ||
4136 | initializer-list: | |
4137 | designation[opt] initializer | |
4138 | initializer-list , designation[opt] initializer | |
4139 | ||
4140 | designation: | |
4141 | designator-list = | |
4142 | ||
4143 | designator-list: | |
4144 | designator | |
4145 | designator-list designator | |
4146 | ||
4147 | designator: | |
4148 | array-designator | |
4149 | . identifier | |
4150 | ||
4151 | array-designator: | |
4152 | [ constant-expression ] | |
4153 | ||
4154 | GNU extensions: | |
4155 | ||
4156 | initializer: | |
4157 | { } | |
4158 | ||
4159 | designation: | |
4160 | array-designator | |
4161 | identifier : | |
4162 | ||
4163 | array-designator: | |
4164 | [ constant-expression ... constant-expression ] | |
4165 | ||
4166 | Any expression without commas is accepted in the syntax for the | |
4167 | constant-expressions, with non-constant expressions rejected later. | |
4168 | ||
4169 | This function is only used for top-level initializers; for nested | |
4170 | ones, see c_parser_initval. */ | |
4171 | ||
4172 | static struct c_expr | |
4173 | c_parser_initializer (c_parser *parser) | |
4174 | { | |
4175 | if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) | |
4176 | return c_parser_braced_init (parser, NULL_TREE, false); | |
4177 | else | |
f14c8207 | 4178 | { |
4179 | struct c_expr ret; | |
e60a6f7b | 4180 | location_t loc = c_parser_peek_token (parser)->location; |
f14c8207 | 4181 | ret = c_parser_expr_no_commas (parser, NULL); |
4182 | if (TREE_CODE (ret.value) != STRING_CST | |
4183 | && TREE_CODE (ret.value) != COMPOUND_LITERAL_EXPR) | |
b560fabd | 4184 | ret = convert_lvalue_to_rvalue (loc, ret, true, true); |
f14c8207 | 4185 | return ret; |
4186 | } | |
1576dec7 | 4187 | } |
4188 | ||
4189 | /* Parse a braced initializer list. TYPE is the type specified for a | |
4190 | compound literal, and NULL_TREE for other initializers and for | |
4191 | nested braced lists. NESTED_P is true for nested braced lists, | |
4192 | false for the list of a compound literal or the list that is the | |
4193 | top-level initializer in a declaration. */ | |
4194 | ||
4195 | static struct c_expr | |
4196 | c_parser_braced_init (c_parser *parser, tree type, bool nested_p) | |
4197 | { | |
759791ee | 4198 | struct c_expr ret; |
4199 | struct obstack braced_init_obstack; | |
be9eba16 | 4200 | location_t brace_loc = c_parser_peek_token (parser)->location; |
759791ee | 4201 | gcc_obstack_init (&braced_init_obstack); |
1576dec7 | 4202 | gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE)); |
4203 | c_parser_consume_token (parser); | |
4204 | if (nested_p) | |
53de1631 | 4205 | push_init_level (brace_loc, 0, &braced_init_obstack); |
1576dec7 | 4206 | else |
4207 | really_start_incremental_init (type); | |
4208 | if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) | |
4209 | { | |
29438999 | 4210 | pedwarn (brace_loc, OPT_Wpedantic, "ISO C forbids empty initializer braces"); |
1576dec7 | 4211 | } |
4212 | else | |
4213 | { | |
4214 | /* Parse a non-empty initializer list, possibly with a trailing | |
4215 | comma. */ | |
4216 | while (true) | |
4217 | { | |
759791ee | 4218 | c_parser_initelt (parser, &braced_init_obstack); |
1576dec7 | 4219 | if (parser->error) |
4220 | break; | |
4221 | if (c_parser_next_token_is (parser, CPP_COMMA)) | |
4222 | c_parser_consume_token (parser); | |
4223 | else | |
4224 | break; | |
4225 | if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) | |
4226 | break; | |
4227 | } | |
4228 | } | |
4229 | if (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE)) | |
4230 | { | |
1576dec7 | 4231 | ret.value = error_mark_node; |
4232 | ret.original_code = ERROR_MARK; | |
841fdaa6 | 4233 | ret.original_type = NULL; |
1576dec7 | 4234 | c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, "expected %<}%>"); |
53de1631 | 4235 | pop_init_level (brace_loc, 0, &braced_init_obstack); |
759791ee | 4236 | obstack_free (&braced_init_obstack, NULL); |
1576dec7 | 4237 | return ret; |
4238 | } | |
4239 | c_parser_consume_token (parser); | |
53de1631 | 4240 | ret = pop_init_level (brace_loc, 0, &braced_init_obstack); |
759791ee | 4241 | obstack_free (&braced_init_obstack, NULL); |
4242 | return ret; | |
1576dec7 | 4243 | } |
4244 | ||
4245 | /* Parse a nested initializer, including designators. */ | |
4246 | ||
4247 | static void | |
759791ee | 4248 | c_parser_initelt (c_parser *parser, struct obstack * braced_init_obstack) |
1576dec7 | 4249 | { |
4250 | /* Parse any designator or designator list. A single array | |
4251 | designator may have the subsequent "=" omitted in GNU C, but a | |
4252 | longer list or a structure member designator may not. */ | |
4253 | if (c_parser_next_token_is (parser, CPP_NAME) | |
4254 | && c_parser_peek_2nd_token (parser)->type == CPP_COLON) | |
4255 | { | |
4256 | /* Old-style structure member designator. */ | |
53de1631 | 4257 | set_init_label (c_parser_peek_token (parser)->location, |
4258 | c_parser_peek_token (parser)->value, | |
759791ee | 4259 | braced_init_obstack); |
8864917d | 4260 | /* Use the colon as the error location. */ |
29438999 | 4261 | pedwarn (c_parser_peek_2nd_token (parser)->location, OPT_Wpedantic, |
21ca8540 | 4262 | "obsolete use of designated initializer with %<:%>"); |
1576dec7 | 4263 | c_parser_consume_token (parser); |
4264 | c_parser_consume_token (parser); | |
4265 | } | |
4266 | else | |
4267 | { | |
4268 | /* des_seen is 0 if there have been no designators, 1 if there | |
4269 | has been a single array designator and 2 otherwise. */ | |
4270 | int des_seen = 0; | |
be9eba16 | 4271 | /* Location of a designator. */ |
019abced | 4272 | location_t des_loc = UNKNOWN_LOCATION; /* Quiet warning. */ |
1576dec7 | 4273 | while (c_parser_next_token_is (parser, CPP_OPEN_SQUARE) |
4274 | || c_parser_next_token_is (parser, CPP_DOT)) | |
4275 | { | |
4276 | int des_prev = des_seen; | |
be9eba16 | 4277 | if (!des_seen) |
4278 | des_loc = c_parser_peek_token (parser)->location; | |
1576dec7 | 4279 | if (des_seen < 2) |
4280 | des_seen++; | |
4281 | if (c_parser_next_token_is (parser, CPP_DOT)) | |
4282 | { | |
4283 | des_seen = 2; | |
4284 | c_parser_consume_token (parser); | |
4285 | if (c_parser_next_token_is (parser, CPP_NAME)) | |
4286 | { | |
53de1631 | 4287 | set_init_label (des_loc, c_parser_peek_token (parser)->value, |
759791ee | 4288 | braced_init_obstack); |
1576dec7 | 4289 | c_parser_consume_token (parser); |
4290 | } | |
4291 | else | |
4292 | { | |
4293 | struct c_expr init; | |
4294 | init.value = error_mark_node; | |
4295 | init.original_code = ERROR_MARK; | |
841fdaa6 | 4296 | init.original_type = NULL; |
1576dec7 | 4297 | c_parser_error (parser, "expected identifier"); |
4298 | c_parser_skip_until_found (parser, CPP_COMMA, NULL); | |
adc93f31 | 4299 | process_init_element (input_location, init, false, |
4300 | braced_init_obstack); | |
1576dec7 | 4301 | return; |
4302 | } | |
4303 | } | |
4304 | else | |
4305 | { | |
4306 | tree first, second; | |
019abced | 4307 | location_t ellipsis_loc = UNKNOWN_LOCATION; /* Quiet warning. */ |
53de1631 | 4308 | location_t array_index_loc = UNKNOWN_LOCATION; |
1576dec7 | 4309 | /* ??? Following the old parser, [ objc-receiver |
4310 | objc-message-args ] is accepted as an initializer, | |
4311 | being distinguished from a designator by what follows | |
4312 | the first assignment expression inside the square | |
4313 | brackets, but after a first array designator a | |
4314 | subsequent square bracket is for Objective-C taken to | |
4315 | start an expression, using the obsolete form of | |
4316 | designated initializer without '=', rather than | |
4317 | possibly being a second level of designation: in LALR | |
4318 | terms, the '[' is shifted rather than reducing | |
4319 | designator to designator-list. */ | |
4320 | if (des_prev == 1 && c_dialect_objc ()) | |
4321 | { | |
4322 | des_seen = des_prev; | |
4323 | break; | |
4324 | } | |
4325 | if (des_prev == 0 && c_dialect_objc ()) | |
4326 | { | |
4327 | /* This might be an array designator or an | |
4328 | Objective-C message expression. If the former, | |
4329 | continue parsing here; if the latter, parse the | |
4330 | remainder of the initializer given the starting | |
4331 | primary-expression. ??? It might make sense to | |
4332 | distinguish when des_prev == 1 as well; see | |
4333 | previous comment. */ | |
4334 | tree rec, args; | |
4335 | struct c_expr mexpr; | |
4336 | c_parser_consume_token (parser); | |
4337 | if (c_parser_peek_token (parser)->type == CPP_NAME | |
4338 | && ((c_parser_peek_token (parser)->id_kind | |
4339 | == C_ID_TYPENAME) | |
4340 | || (c_parser_peek_token (parser)->id_kind | |
4341 | == C_ID_CLASSNAME))) | |
4342 | { | |
4343 | /* Type name receiver. */ | |
4344 | tree id = c_parser_peek_token (parser)->value; | |
4345 | c_parser_consume_token (parser); | |
4346 | rec = objc_get_class_reference (id); | |
4347 | goto parse_message_args; | |
4348 | } | |
4349 | first = c_parser_expr_no_commas (parser, NULL).value; | |
abc6c64f | 4350 | mark_exp_read (first); |
1576dec7 | 4351 | if (c_parser_next_token_is (parser, CPP_ELLIPSIS) |
4352 | || c_parser_next_token_is (parser, CPP_CLOSE_SQUARE)) | |
4353 | goto array_desig_after_first; | |
4354 | /* Expression receiver. So far only one part | |
4355 | without commas has been parsed; there might be | |
4356 | more of the expression. */ | |
4357 | rec = first; | |
4358 | while (c_parser_next_token_is (parser, CPP_COMMA)) | |
4359 | { | |
e78cf9a7 | 4360 | struct c_expr next; |
e60a6f7b | 4361 | location_t comma_loc, exp_loc; |
4362 | comma_loc = c_parser_peek_token (parser)->location; | |
1576dec7 | 4363 | c_parser_consume_token (parser); |
e60a6f7b | 4364 | exp_loc = c_parser_peek_token (parser)->location; |
e78cf9a7 | 4365 | next = c_parser_expr_no_commas (parser, NULL); |
b560fabd | 4366 | next = convert_lvalue_to_rvalue (exp_loc, next, |
4367 | true, true); | |
e60a6f7b | 4368 | rec = build_compound_expr (comma_loc, rec, next.value); |
1576dec7 | 4369 | } |
4370 | parse_message_args: | |
4371 | /* Now parse the objc-message-args. */ | |
4372 | args = c_parser_objc_message_args (parser); | |
4373 | c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, | |
4374 | "expected %<]%>"); | |
4375 | mexpr.value | |
4185cf58 | 4376 | = objc_build_message_expr (rec, args); |
1576dec7 | 4377 | mexpr.original_code = ERROR_MARK; |
841fdaa6 | 4378 | mexpr.original_type = NULL; |
1576dec7 | 4379 | /* Now parse and process the remainder of the |
4380 | initializer, starting with this message | |
4381 | expression as a primary-expression. */ | |
759791ee | 4382 | c_parser_initval (parser, &mexpr, braced_init_obstack); |
1576dec7 | 4383 | return; |
4384 | } | |
4385 | c_parser_consume_token (parser); | |
53de1631 | 4386 | array_index_loc = c_parser_peek_token (parser)->location; |
1576dec7 | 4387 | first = c_parser_expr_no_commas (parser, NULL).value; |
abc6c64f | 4388 | mark_exp_read (first); |
1576dec7 | 4389 | array_desig_after_first: |
4390 | if (c_parser_next_token_is (parser, CPP_ELLIPSIS)) | |
4391 | { | |
be9eba16 | 4392 | ellipsis_loc = c_parser_peek_token (parser)->location; |
1576dec7 | 4393 | c_parser_consume_token (parser); |
4394 | second = c_parser_expr_no_commas (parser, NULL).value; | |
abc6c64f | 4395 | mark_exp_read (second); |
1576dec7 | 4396 | } |
4397 | else | |
4398 | second = NULL_TREE; | |
4399 | if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE)) | |
4400 | { | |
4401 | c_parser_consume_token (parser); | |
53de1631 | 4402 | set_init_index (array_index_loc, first, second, |
4403 | braced_init_obstack); | |
8864917d | 4404 | if (second) |
29438999 | 4405 | pedwarn (ellipsis_loc, OPT_Wpedantic, |
21ca8540 | 4406 | "ISO C forbids specifying range of elements to initialize"); |
1576dec7 | 4407 | } |
4408 | else | |
4409 | c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, | |
4410 | "expected %<]%>"); | |
4411 | } | |
4412 | } | |
4413 | if (des_seen >= 1) | |
4414 | { | |
4415 | if (c_parser_next_token_is (parser, CPP_EQ)) | |
4416 | { | |
890c2e2f | 4417 | pedwarn_c90 (des_loc, OPT_Wpedantic, |
4418 | "ISO C90 forbids specifying subobject " | |
4419 | "to initialize"); | |
1576dec7 | 4420 | c_parser_consume_token (parser); |
4421 | } | |
4422 | else | |
4423 | { | |
4424 | if (des_seen == 1) | |
29438999 | 4425 | pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic, |
21ca8540 | 4426 | "obsolete use of designated initializer without %<=%>"); |
1576dec7 | 4427 | else |
4428 | { | |
4429 | struct c_expr init; | |
4430 | init.value = error_mark_node; | |
4431 | init.original_code = ERROR_MARK; | |
841fdaa6 | 4432 | init.original_type = NULL; |
1576dec7 | 4433 | c_parser_error (parser, "expected %<=%>"); |
4434 | c_parser_skip_until_found (parser, CPP_COMMA, NULL); | |
adc93f31 | 4435 | process_init_element (input_location, init, false, |
4436 | braced_init_obstack); | |
1576dec7 | 4437 | return; |
4438 | } | |
4439 | } | |
4440 | } | |
4441 | } | |
759791ee | 4442 | c_parser_initval (parser, NULL, braced_init_obstack); |
1576dec7 | 4443 | } |
4444 | ||
4445 | /* Parse a nested initializer; as c_parser_initializer but parses | |
4446 | initializers within braced lists, after any designators have been | |
4447 | applied. If AFTER is not NULL then it is an Objective-C message | |
4448 | expression which is the primary-expression starting the | |
4449 | initializer. */ | |
4450 | ||
4451 | static void | |
759791ee | 4452 | c_parser_initval (c_parser *parser, struct c_expr *after, |
4453 | struct obstack * braced_init_obstack) | |
1576dec7 | 4454 | { |
4455 | struct c_expr init; | |
4456 | gcc_assert (!after || c_dialect_objc ()); | |
adc93f31 | 4457 | location_t loc = c_parser_peek_token (parser)->location; |
4458 | ||
1576dec7 | 4459 | if (c_parser_next_token_is (parser, CPP_OPEN_BRACE) && !after) |
4460 | init = c_parser_braced_init (parser, NULL_TREE, true); | |
4461 | else | |
f14c8207 | 4462 | { |
4463 | init = c_parser_expr_no_commas (parser, after); | |
4464 | if (init.value != NULL_TREE | |
4465 | && TREE_CODE (init.value) != STRING_CST | |
4466 | && TREE_CODE (init.value) != COMPOUND_LITERAL_EXPR) | |
b560fabd | 4467 | init = convert_lvalue_to_rvalue (loc, init, true, true); |
f14c8207 | 4468 | } |
adc93f31 | 4469 | process_init_element (loc, init, false, braced_init_obstack); |
1576dec7 | 4470 | } |
4471 | ||
4472 | /* Parse a compound statement (possibly a function body) (C90 6.6.2, | |
4473 | C99 6.8.2). | |
4474 | ||
4475 | compound-statement: | |
4476 | { block-item-list[opt] } | |
4477 | { label-declarations block-item-list } | |
4478 | ||
4479 | block-item-list: | |
4480 | block-item | |
4481 | block-item-list block-item | |
4482 | ||
4483 | block-item: | |
4484 | nested-declaration | |
4485 | statement | |
4486 | ||
4487 | nested-declaration: | |
4488 | declaration | |
4489 | ||
4490 | GNU extensions: | |
4491 | ||
4492 | compound-statement: | |
4493 | { label-declarations block-item-list } | |
4494 | ||
4495 | nested-declaration: | |
4496 | __extension__ nested-declaration | |
4497 | nested-function-definition | |
4498 | ||
4499 | label-declarations: | |
4500 | label-declaration | |
4501 | label-declarations label-declaration | |
4502 | ||
4503 | label-declaration: | |
4504 | __label__ identifier-list ; | |
4505 | ||
4506 | Allowing the mixing of declarations and code is new in C99. The | |
4507 | GNU syntax also permits (not shown above) labels at the end of | |
4508 | compound statements, which yield an error. We don't allow labels | |
4509 | on declarations; this might seem like a natural extension, but | |
4510 | there would be a conflict between attributes on the label and | |
4511 | prefix attributes on the declaration. ??? The syntax follows the | |
4512 | old parser in requiring something after label declarations. | |
4513 | Although they are erroneous if the labels declared aren't defined, | |
1e8e9920 | 4514 | is it useful for the syntax to be this way? |
48e1416a | 4515 | |
ca4c3545 | 4516 | OpenACC: |
4517 | ||
4518 | block-item: | |
4519 | openacc-directive | |
4520 | ||
4521 | openacc-directive: | |
4522 | update-directive | |
4523 | ||
1e8e9920 | 4524 | OpenMP: |
48e1416a | 4525 | |
1e8e9920 | 4526 | block-item: |
4527 | openmp-directive | |
4528 | ||
4529 | openmp-directive: | |
4530 | barrier-directive | |
bc7bff74 | 4531 | flush-directive |
4532 | taskwait-directive | |
4533 | taskyield-directive | |
4534 | cancel-directive | |
4535 | cancellation-point-directive */ | |
1576dec7 | 4536 | |
4537 | static tree | |
4538 | c_parser_compound_statement (c_parser *parser) | |
4539 | { | |
4540 | tree stmt; | |
e60a6f7b | 4541 | location_t brace_loc; |
4542 | brace_loc = c_parser_peek_token (parser)->location; | |
1576dec7 | 4543 | if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>")) |
22d77a94 | 4544 | { |
4545 | /* Ensure a scope is entered and left anyway to avoid confusion | |
4546 | if we have just prepared to enter a function body. */ | |
4547 | stmt = c_begin_compound_stmt (true); | |
e60a6f7b | 4548 | c_end_compound_stmt (brace_loc, stmt, true); |
22d77a94 | 4549 | return error_mark_node; |
4550 | } | |
1576dec7 | 4551 | stmt = c_begin_compound_stmt (true); |
4552 | c_parser_compound_statement_nostart (parser); | |
3c6d4197 | 4553 | |
4554 | /* If the compound stmt contains array notations, then we expand them. */ | |
a89e6c15 | 4555 | if (flag_cilkplus && contains_array_notation_expr (stmt)) |
3c6d4197 | 4556 | stmt = expand_array_notation_exprs (stmt); |
e60a6f7b | 4557 | return c_end_compound_stmt (brace_loc, stmt, true); |
1576dec7 | 4558 | } |
4559 | ||
4560 | /* Parse a compound statement except for the opening brace. This is | |
4561 | used for parsing both compound statements and statement expressions | |
4562 | (which follow different paths to handling the opening). */ | |
4563 | ||
4564 | static void | |
4565 | c_parser_compound_statement_nostart (c_parser *parser) | |
4566 | { | |
4567 | bool last_stmt = false; | |
4568 | bool last_label = false; | |
3ae3a17f | 4569 | bool save_valid_for_pragma = valid_location_for_stdc_pragma_p (); |
e3b80d49 | 4570 | location_t label_loc = UNKNOWN_LOCATION; /* Quiet warning. */ |
1576dec7 | 4571 | if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) |
4572 | { | |
4573 | c_parser_consume_token (parser); | |
4574 | return; | |
4575 | } | |
3ae3a17f | 4576 | mark_valid_location_for_stdc_pragma (true); |
1576dec7 | 4577 | if (c_parser_next_token_is_keyword (parser, RID_LABEL)) |
4578 | { | |
4579 | /* Read zero or more forward-declarations for labels that nested | |
4580 | functions can jump to. */ | |
3ae3a17f | 4581 | mark_valid_location_for_stdc_pragma (false); |
1576dec7 | 4582 | while (c_parser_next_token_is_keyword (parser, RID_LABEL)) |
4583 | { | |
e60a6f7b | 4584 | label_loc = c_parser_peek_token (parser)->location; |
1576dec7 | 4585 | c_parser_consume_token (parser); |
4586 | /* Any identifiers, including those declared as type names, | |
4587 | are OK here. */ | |
4588 | while (true) | |
4589 | { | |
4590 | tree label; | |
4591 | if (c_parser_next_token_is_not (parser, CPP_NAME)) | |
4592 | { | |
4593 | c_parser_error (parser, "expected identifier"); | |
4594 | break; | |
4595 | } | |
4596 | label | |
4597 | = declare_label (c_parser_peek_token (parser)->value); | |
4598 | C_DECLARED_LABEL_FLAG (label) = 1; | |
e60a6f7b | 4599 | add_stmt (build_stmt (label_loc, DECL_EXPR, label)); |
1576dec7 | 4600 | c_parser_consume_token (parser); |
4601 | if (c_parser_next_token_is (parser, CPP_COMMA)) | |
4602 | c_parser_consume_token (parser); | |
4603 | else | |
4604 | break; | |
4605 | } | |
4606 | c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); | |
4607 | } | |
29438999 | 4608 | pedwarn (label_loc, OPT_Wpedantic, "ISO C forbids label declarations"); |
1576dec7 | 4609 | } |
4610 | /* We must now have at least one statement, label or declaration. */ | |
4611 | if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) | |
4612 | { | |
3ae3a17f | 4613 | mark_valid_location_for_stdc_pragma (save_valid_for_pragma); |
1576dec7 | 4614 | c_parser_error (parser, "expected declaration or statement"); |
4615 | c_parser_consume_token (parser); | |
4616 | return; | |
4617 | } | |
4618 | while (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE)) | |
4619 | { | |
4620 | location_t loc = c_parser_peek_token (parser)->location; | |
1576dec7 | 4621 | if (c_parser_next_token_is_keyword (parser, RID_CASE) |
4622 | || c_parser_next_token_is_keyword (parser, RID_DEFAULT) | |
4623 | || (c_parser_next_token_is (parser, CPP_NAME) | |
4624 | && c_parser_peek_2nd_token (parser)->type == CPP_COLON)) | |
4625 | { | |
be9eba16 | 4626 | if (c_parser_next_token_is_keyword (parser, RID_CASE)) |
4627 | label_loc = c_parser_peek_2nd_token (parser)->location; | |
4628 | else | |
4629 | label_loc = c_parser_peek_token (parser)->location; | |
1576dec7 | 4630 | last_label = true; |
4631 | last_stmt = false; | |
3ae3a17f | 4632 | mark_valid_location_for_stdc_pragma (false); |
1576dec7 | 4633 | c_parser_label (parser); |
4634 | } | |
4635 | else if (!last_label | |
71bb4bc6 | 4636 | && c_parser_next_tokens_start_declaration (parser)) |
1576dec7 | 4637 | { |
4638 | last_label = false; | |
3ae3a17f | 4639 | mark_valid_location_for_stdc_pragma (false); |
bc7bff74 | 4640 | c_parser_declaration_or_fndef (parser, true, true, true, true, |
4641 | true, NULL, vNULL); | |
8864917d | 4642 | if (last_stmt) |
806fe15e | 4643 | pedwarn_c90 (loc, OPT_Wdeclaration_after_statement, |
21ca8540 | 4644 | "ISO C90 forbids mixed declarations and code"); |
1576dec7 | 4645 | last_stmt = false; |
4646 | } | |
4647 | else if (!last_label | |
4648 | && c_parser_next_token_is_keyword (parser, RID_EXTENSION)) | |
4649 | { | |
4650 | /* __extension__ can start a declaration, but is also an | |
4651 | unary operator that can start an expression. Consume all | |
4652 | but the last of a possible series of __extension__ to | |
4653 | determine which. */ | |
4654 | while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD | |
4655 | && (c_parser_peek_2nd_token (parser)->keyword | |
4656 | == RID_EXTENSION)) | |
4657 | c_parser_consume_token (parser); | |
f80e7755 | 4658 | if (c_token_starts_declaration (c_parser_peek_2nd_token (parser))) |
1576dec7 | 4659 | { |
4660 | int ext; | |
4661 | ext = disable_extension_diagnostics (); | |
4662 | c_parser_consume_token (parser); | |
4663 | last_label = false; | |
3ae3a17f | 4664 | mark_valid_location_for_stdc_pragma (false); |
f80e7755 | 4665 | c_parser_declaration_or_fndef (parser, true, true, true, true, |
bc7bff74 | 4666 | true, NULL, vNULL); |
1576dec7 | 4667 | /* Following the old parser, __extension__ does not |
4668 | disable this diagnostic. */ | |
4669 | restore_extension_diagnostics (ext); | |
8864917d | 4670 | if (last_stmt) |
806fe15e | 4671 | pedwarn_c90 (loc, OPT_Wdeclaration_after_statement, |
21ca8540 | 4672 | "ISO C90 forbids mixed declarations and code"); |
1576dec7 | 4673 | last_stmt = false; |
4674 | } | |
4675 | else | |
4676 | goto statement; | |
4677 | } | |
b75b98aa | 4678 | else if (c_parser_next_token_is (parser, CPP_PRAGMA)) |
4679 | { | |
4680 | /* External pragmas, and some omp pragmas, are not associated | |
4681 | with regular c code, and so are not to be considered statements | |
4682 | syntactically. This ensures that the user doesn't put them | |
4683 | places that would turn into syntax errors if the directive | |
4684 | were ignored. */ | |
4685 | if (c_parser_pragma (parser, pragma_compound)) | |
4686 | last_label = false, last_stmt = true; | |
4687 | } | |
4688 | else if (c_parser_next_token_is (parser, CPP_EOF)) | |
4689 | { | |
3ae3a17f | 4690 | mark_valid_location_for_stdc_pragma (save_valid_for_pragma); |
b75b98aa | 4691 | c_parser_error (parser, "expected declaration or statement"); |
4692 | return; | |
4693 | } | |
10c93a35 | 4694 | else if (c_parser_next_token_is_keyword (parser, RID_ELSE)) |
4695 | { | |
48e1416a | 4696 | if (parser->in_if_block) |
10c93a35 | 4697 | { |
3ae3a17f | 4698 | mark_valid_location_for_stdc_pragma (save_valid_for_pragma); |
e3b80d49 | 4699 | error_at (loc, """expected %<}%> before %<else%>"); |
10c93a35 | 4700 | return; |
4701 | } | |
48e1416a | 4702 | else |
10c93a35 | 4703 | { |
e3b80d49 | 4704 | error_at (loc, "%<else%> without a previous %<if%>"); |
10c93a35 | 4705 | c_parser_consume_token (parser); |
4706 | continue; | |
4707 | } | |
4708 | } | |
1576dec7 | 4709 | else |
4710 | { | |
4711 | statement: | |
4712 | last_label = false; | |
4713 | last_stmt = true; | |
3ae3a17f | 4714 | mark_valid_location_for_stdc_pragma (false); |
1576dec7 | 4715 | c_parser_statement_after_labels (parser); |
4716 | } | |
d038ab63 | 4717 | |
4718 | parser->error = false; | |
1576dec7 | 4719 | } |
4720 | if (last_label) | |
e3b80d49 | 4721 | error_at (label_loc, "label at end of compound statement"); |
1576dec7 | 4722 | c_parser_consume_token (parser); |
3ae3a17f | 4723 | /* Restore the value we started with. */ |
4724 | mark_valid_location_for_stdc_pragma (save_valid_for_pragma); | |
1576dec7 | 4725 | } |
4726 | ||
4f284d4a | 4727 | /* Parse all consecutive labels. */ |
4728 | ||
4729 | static void | |
4730 | c_parser_all_labels (c_parser *parser) | |
4731 | { | |
4732 | while (c_parser_next_token_is_keyword (parser, RID_CASE) | |
4733 | || c_parser_next_token_is_keyword (parser, RID_DEFAULT) | |
4734 | || (c_parser_next_token_is (parser, CPP_NAME) | |
4735 | && c_parser_peek_2nd_token (parser)->type == CPP_COLON)) | |
4736 | c_parser_label (parser); | |
4737 | } | |
4738 | ||
1576dec7 | 4739 | /* Parse a label (C90 6.6.1, C99 6.8.1). |
4740 | ||
4741 | label: | |
4742 | identifier : attributes[opt] | |
4743 | case constant-expression : | |
4744 | default : | |
4745 | ||
4746 | GNU extensions: | |
4747 | ||
4748 | label: | |
4749 | case constant-expression ... constant-expression : | |
4750 | ||
4751 | The use of attributes on labels is a GNU extension. The syntax in | |
4752 | GNU C accepts any expressions without commas, non-constant | |
4753 | expressions being rejected later. */ | |
4754 | ||
4755 | static void | |
4756 | c_parser_label (c_parser *parser) | |
4757 | { | |
4758 | location_t loc1 = c_parser_peek_token (parser)->location; | |
4759 | tree label = NULL_TREE; | |
4760 | if (c_parser_next_token_is_keyword (parser, RID_CASE)) | |
4761 | { | |
4762 | tree exp1, exp2; | |
4763 | c_parser_consume_token (parser); | |
4764 | exp1 = c_parser_expr_no_commas (parser, NULL).value; | |
4765 | if (c_parser_next_token_is (parser, CPP_COLON)) | |
4766 | { | |
4767 | c_parser_consume_token (parser); | |
e60a6f7b | 4768 | label = do_case (loc1, exp1, NULL_TREE); |
1576dec7 | 4769 | } |
4770 | else if (c_parser_next_token_is (parser, CPP_ELLIPSIS)) | |
4771 | { | |
4772 | c_parser_consume_token (parser); | |
4773 | exp2 = c_parser_expr_no_commas (parser, NULL).value; | |
4774 | if (c_parser_require (parser, CPP_COLON, "expected %<:%>")) | |
e60a6f7b | 4775 | label = do_case (loc1, exp1, exp2); |
1576dec7 | 4776 | } |
4777 | else | |
4778 | c_parser_error (parser, "expected %<:%> or %<...%>"); | |
4779 | } | |
4780 | else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT)) | |
4781 | { | |
4782 | c_parser_consume_token (parser); | |
4783 | if (c_parser_require (parser, CPP_COLON, "expected %<:%>")) | |
e60a6f7b | 4784 | label = do_case (loc1, NULL_TREE, NULL_TREE); |
1576dec7 | 4785 | } |
4786 | else | |
4787 | { | |
4788 | tree name = c_parser_peek_token (parser)->value; | |
4789 | tree tlab; | |
1576dec7 | 4790 | tree attrs; |
be9eba16 | 4791 | location_t loc2 = c_parser_peek_token (parser)->location; |
1576dec7 | 4792 | gcc_assert (c_parser_next_token_is (parser, CPP_NAME)); |
4793 | c_parser_consume_token (parser); | |
4794 | gcc_assert (c_parser_next_token_is (parser, CPP_COLON)); | |
1576dec7 | 4795 | c_parser_consume_token (parser); |
4796 | attrs = c_parser_attributes (parser); | |
4797 | tlab = define_label (loc2, name); | |
4798 | if (tlab) | |
4799 | { | |
4800 | decl_attributes (&tlab, attrs, 0); | |
e60a6f7b | 4801 | label = add_stmt (build_stmt (loc1, LABEL_EXPR, tlab)); |
1576dec7 | 4802 | } |
4803 | } | |
4804 | if (label) | |
7561efef | 4805 | { |
71bb4bc6 | 4806 | if (c_parser_next_tokens_start_declaration (parser)) |
7561efef | 4807 | { |
e3b80d49 | 4808 | error_at (c_parser_peek_token (parser)->location, |
4809 | "a label can only be part of a statement and " | |
4810 | "a declaration is not a statement"); | |
48e1416a | 4811 | c_parser_declaration_or_fndef (parser, /*fndef_ok*/ false, |
f80e7755 | 4812 | /*static_assert_ok*/ true, |
a90d57ed | 4813 | /*empty_ok*/ true, /*nested*/ true, |
bc7bff74 | 4814 | /*start_attr_ok*/ true, NULL, |
4815 | vNULL); | |
7561efef | 4816 | } |
4817 | } | |
1576dec7 | 4818 | } |
4819 | ||
4820 | /* Parse a statement (C90 6.6, C99 6.8). | |
4821 | ||
4822 | statement: | |
4823 | labeled-statement | |
4824 | compound-statement | |
4825 | expression-statement | |
4826 | selection-statement | |
4827 | iteration-statement | |
4828 | jump-statement | |
4829 | ||
4830 | labeled-statement: | |
4831 | label statement | |
4832 | ||
4833 | expression-statement: | |
4834 | expression[opt] ; | |
4835 | ||
4836 | selection-statement: | |
4837 | if-statement | |
4838 | switch-statement | |
4839 | ||
4840 | iteration-statement: | |
4841 | while-statement | |
4842 | do-statement | |
4843 | for-statement | |
4844 | ||
4845 | jump-statement: | |
4846 | goto identifier ; | |
4847 | continue ; | |
4848 | break ; | |
4849 | return expression[opt] ; | |
4850 | ||
4851 | GNU extensions: | |
4852 | ||
4853 | statement: | |
4854 | asm-statement | |
4855 | ||
4856 | jump-statement: | |
4857 | goto * expression ; | |
4858 | ||
4859 | Objective-C: | |
4860 | ||
4861 | statement: | |
4862 | objc-throw-statement | |
4863 | objc-try-catch-statement | |
4864 | objc-synchronized-statement | |
4865 | ||
4866 | objc-throw-statement: | |
4867 | @throw expression ; | |
4868 | @throw ; | |
1e8e9920 | 4869 | |
ca4c3545 | 4870 | OpenACC: |
4871 | ||
4872 | statement: | |
4873 | openacc-construct | |
4874 | ||
4875 | openacc-construct: | |
4876 | parallel-construct | |
4877 | kernels-construct | |
4878 | data-construct | |
4879 | loop-construct | |
4880 | ||
4881 | parallel-construct: | |
4882 | parallel-directive structured-block | |
4883 | ||
4884 | kernels-construct: | |
4885 | kernels-directive structured-block | |
4886 | ||
4887 | data-construct: | |
4888 | data-directive structured-block | |
4889 | ||
4890 | loop-construct: | |
4891 | loop-directive structured-block | |
4892 | ||
1e8e9920 | 4893 | OpenMP: |
4894 | ||
4895 | statement: | |
4896 | openmp-construct | |
4897 | ||
4898 | openmp-construct: | |
4899 | parallel-construct | |
4900 | for-construct | |
bc7bff74 | 4901 | simd-construct |
4902 | for-simd-construct | |
1e8e9920 | 4903 | sections-construct |
4904 | single-construct | |
4905 | parallel-for-construct | |
bc7bff74 | 4906 | parallel-for-simd-construct |
1e8e9920 | 4907 | parallel-sections-construct |
4908 | master-construct | |
4909 | critical-construct | |
4910 | atomic-construct | |
4911 | ordered-construct | |
4912 | ||
4913 | parallel-construct: | |
4914 | parallel-directive structured-block | |
4915 | ||
4916 | for-construct: | |
4917 | for-directive iteration-statement | |
4918 | ||
bc7bff74 | 4919 | simd-construct: |
4920 | simd-directive iteration-statements | |
4921 | ||
4922 | for-simd-construct: | |
4923 | for-simd-directive iteration-statements | |
4924 | ||
1e8e9920 | 4925 | sections-construct: |
4926 | sections-directive section-scope | |
4927 | ||
4928 | single-construct: | |
4929 | single-directive structured-block | |
4930 | ||
4931 | parallel-for-construct: | |
4932 | parallel-for-directive iteration-statement | |
4933 | ||
bc7bff74 | 4934 | parallel-for-simd-construct: |
4935 | parallel-for-simd-directive iteration-statement | |
4936 | ||
1e8e9920 | 4937 | parallel-sections-construct: |
4938 | parallel-sections-directive section-scope | |
4939 | ||
4940 | master-construct: | |
4941 | master-directive structured-block | |
4942 | ||
4943 | critical-construct: | |
4944 | critical-directive structured-block | |
4945 | ||
4946 | atomic-construct: | |
4947 | atomic-directive expression-statement | |
4948 | ||
4949 | ordered-construct: | |
4c0315d0 | 4950 | ordered-directive structured-block |
4951 | ||
4952 | Transactional Memory: | |
4953 | ||
4954 | statement: | |
4955 | transaction-statement | |
4956 | transaction-cancel-statement | |
4957 | */ | |
1576dec7 | 4958 | |
4959 | static void | |
4960 | c_parser_statement (c_parser *parser) | |
4961 | { | |
4f284d4a | 4962 | c_parser_all_labels (parser); |
1576dec7 | 4963 | c_parser_statement_after_labels (parser); |
4964 | } | |
4965 | ||
ef17a71a | 4966 | /* Parse a statement, other than a labeled statement. CHAIN is a vector |
4967 | of if-else-if conditions. */ | |
1576dec7 | 4968 | |
4969 | static void | |
ef17a71a | 4970 | c_parser_statement_after_labels (c_parser *parser, vec<tree> *chain) |
1576dec7 | 4971 | { |
4972 | location_t loc = c_parser_peek_token (parser)->location; | |
4973 | tree stmt = NULL_TREE; | |
10c93a35 | 4974 | bool in_if_block = parser->in_if_block; |
4975 | parser->in_if_block = false; | |
1576dec7 | 4976 | switch (c_parser_peek_token (parser)->type) |
4977 | { | |
4978 | case CPP_OPEN_BRACE: | |
4979 | add_stmt (c_parser_compound_statement (parser)); | |
4980 | break; | |
4981 | case CPP_KEYWORD: | |
4982 | switch (c_parser_peek_token (parser)->keyword) | |
4983 | { | |
4984 | case RID_IF: | |
ef17a71a | 4985 | c_parser_if_statement (parser, chain); |
1576dec7 | 4986 | break; |
4987 | case RID_SWITCH: | |
4988 | c_parser_switch_statement (parser); | |
4989 | break; | |
4990 | case RID_WHILE: | |
4c90c04c | 4991 | c_parser_while_statement (parser, false); |
1576dec7 | 4992 | break; |
4993 | case RID_DO: | |
4c90c04c | 4994 | c_parser_do_statement (parser, false); |
1576dec7 | 4995 | break; |
4996 | case RID_FOR: | |
4644b593 | 4997 | c_parser_for_statement (parser, false); |
1576dec7 | 4998 | break; |
40750995 | 4999 | case RID_CILK_FOR: |
5000 | if (!flag_cilkplus) | |
5001 | { | |
5002 | error_at (c_parser_peek_token (parser)->location, | |
5003 | "-fcilkplus must be enabled to use %<_Cilk_for%>"); | |
5004 | c_parser_skip_to_end_of_block_or_statement (parser); | |
5005 | } | |
5006 | else | |
5007 | c_parser_cilk_for (parser, integer_zero_node); | |
5008 | break; | |
d037099f | 5009 | case RID_CILK_SYNC: |
5010 | c_parser_consume_token (parser); | |
5011 | c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); | |
a89e6c15 | 5012 | if (!flag_cilkplus) |
d037099f | 5013 | error_at (loc, "-fcilkplus must be enabled to use %<_Cilk_sync%>"); |
5014 | else | |
5015 | add_stmt (build_cilk_sync ()); | |
1576dec7 | 5016 | break; |
5017 | case RID_GOTO: | |
5018 | c_parser_consume_token (parser); | |
5019 | if (c_parser_next_token_is (parser, CPP_NAME)) | |
5020 | { | |
e60a6f7b | 5021 | stmt = c_finish_goto_label (loc, |
5022 | c_parser_peek_token (parser)->value); | |
1576dec7 | 5023 | c_parser_consume_token (parser); |
5024 | } | |
5025 | else if (c_parser_next_token_is (parser, CPP_MULT)) | |
5026 | { | |
b560fabd | 5027 | struct c_expr val; |
95f11b21 | 5028 | |
1576dec7 | 5029 | c_parser_consume_token (parser); |
b560fabd | 5030 | val = c_parser_expression (parser); |
fdd735a7 | 5031 | if (check_no_cilk (val.value, |
5032 | "Cilk array notation cannot be used as a computed goto expression", | |
5033 | "%<_Cilk_spawn%> statement cannot be used as a computed goto expression", | |
5034 | loc)) | |
5035 | val.value = error_mark_node; | |
b560fabd | 5036 | val = convert_lvalue_to_rvalue (loc, val, false, true); |
5037 | stmt = c_finish_goto_ptr (loc, val.value); | |
1576dec7 | 5038 | } |
5039 | else | |
5040 | c_parser_error (parser, "expected identifier or %<*%>"); | |
5041 | goto expect_semicolon; | |
5042 | case RID_CONTINUE: | |
5043 | c_parser_consume_token (parser); | |
e60a6f7b | 5044 | stmt = c_finish_bc_stmt (loc, &c_cont_label, false); |
1576dec7 | 5045 | goto expect_semicolon; |
5046 | case RID_BREAK: | |
5047 | c_parser_consume_token (parser); | |
e60a6f7b | 5048 | stmt = c_finish_bc_stmt (loc, &c_break_label, true); |
1576dec7 | 5049 | goto expect_semicolon; |
5050 | case RID_RETURN: | |
5051 | c_parser_consume_token (parser); | |
5052 | if (c_parser_next_token_is (parser, CPP_SEMICOLON)) | |
5053 | { | |
e60a6f7b | 5054 | stmt = c_finish_return (loc, NULL_TREE, NULL_TREE); |
1576dec7 | 5055 | c_parser_consume_token (parser); |
5056 | } | |
5057 | else | |
5058 | { | |
430b73ee | 5059 | location_t xloc = c_parser_peek_token (parser)->location; |
b9c74b4d | 5060 | struct c_expr expr = c_parser_expression_conv (parser); |
abc6c64f | 5061 | mark_exp_read (expr.value); |
430b73ee | 5062 | stmt = c_finish_return (xloc, expr.value, expr.original_type); |
1576dec7 | 5063 | goto expect_semicolon; |
5064 | } | |
5065 | break; | |
5066 | case RID_ASM: | |
5067 | stmt = c_parser_asm_statement (parser); | |
5068 | break; | |
4c0315d0 | 5069 | case RID_TRANSACTION_ATOMIC: |
5070 | case RID_TRANSACTION_RELAXED: | |
5071 | stmt = c_parser_transaction (parser, | |
5072 | c_parser_peek_token (parser)->keyword); | |
5073 | break; | |
5074 | case RID_TRANSACTION_CANCEL: | |
5075 | stmt = c_parser_transaction_cancel (parser); | |
5076 | goto expect_semicolon; | |
e5c75ac3 | 5077 | case RID_AT_THROW: |
1576dec7 | 5078 | gcc_assert (c_dialect_objc ()); |
5079 | c_parser_consume_token (parser); | |
5080 | if (c_parser_next_token_is (parser, CPP_SEMICOLON)) | |
5081 | { | |
e60a6f7b | 5082 | stmt = objc_build_throw_stmt (loc, NULL_TREE); |
1576dec7 | 5083 | c_parser_consume_token (parser); |
5084 | } | |
5085 | else | |
5086 | { | |
b560fabd | 5087 | struct c_expr expr = c_parser_expression (parser); |
5088 | expr = convert_lvalue_to_rvalue (loc, expr, false, false); | |
fdd735a7 | 5089 | if (check_no_cilk (expr.value, |
5090 | "Cilk array notation cannot be used for a throw expression", | |
5091 | "%<_Cilk_spawn%> statement cannot be used for a throw expression")) | |
5092 | expr.value = error_mark_node; | |
5093 | else | |
5094 | { | |
5095 | expr.value = c_fully_fold (expr.value, false, NULL); | |
5096 | stmt = objc_build_throw_stmt (loc, expr.value); | |
5097 | } | |
1576dec7 | 5098 | goto expect_semicolon; |
5099 | } | |
5100 | break; | |
e5c75ac3 | 5101 | case RID_AT_TRY: |
1576dec7 | 5102 | gcc_assert (c_dialect_objc ()); |
b3d2d312 | 5103 | c_parser_objc_try_catch_finally_statement (parser); |
1576dec7 | 5104 | break; |
5105 | case RID_AT_SYNCHRONIZED: | |
5106 | gcc_assert (c_dialect_objc ()); | |
5107 | c_parser_objc_synchronized_statement (parser); | |
5108 | break; | |
5109 | default: | |
5110 | goto expr_stmt; | |
5111 | } | |
5112 | break; | |
5113 | case CPP_SEMICOLON: | |
5114 | c_parser_consume_token (parser); | |
5115 | break; | |
5116 | case CPP_CLOSE_PAREN: | |
5117 | case CPP_CLOSE_SQUARE: | |
5118 | /* Avoid infinite loop in error recovery: | |
5119 | c_parser_skip_until_found stops at a closing nesting | |
5120 | delimiter without consuming it, but here we need to consume | |
5121 | it to proceed further. */ | |
5122 | c_parser_error (parser, "expected statement"); | |
5123 | c_parser_consume_token (parser); | |
5124 | break; | |
b75b98aa | 5125 | case CPP_PRAGMA: |
5126 | c_parser_pragma (parser, pragma_stmt); | |
5127 | break; | |
1576dec7 | 5128 | default: |
5129 | expr_stmt: | |
e60a6f7b | 5130 | stmt = c_finish_expr_stmt (loc, c_parser_expression_conv (parser).value); |
1576dec7 | 5131 | expect_semicolon: |
5132 | c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); | |
5133 | break; | |
5134 | } | |
5135 | /* Two cases cannot and do not have line numbers associated: If stmt | |
5136 | is degenerate, such as "2;", then stmt is an INTEGER_CST, which | |
5137 | cannot hold line numbers. But that's OK because the statement | |
5138 | will either be changed to a MODIFY_EXPR during gimplification of | |
5139 | the statement expr, or discarded. If stmt was compound, but | |
5140 | without new variables, we will have skipped the creation of a | |
5141 | BIND and will have a bare STATEMENT_LIST. But that's OK because | |
5142 | (recursively) all of the component statements should already have | |
5143 | line numbers assigned. ??? Can we discard no-op statements | |
5144 | earlier? */ | |
789fbb51 | 5145 | if (EXPR_LOCATION (stmt) == UNKNOWN_LOCATION) |
5146 | protected_set_expr_location (stmt, loc); | |
10c93a35 | 5147 | |
5148 | parser->in_if_block = in_if_block; | |
1576dec7 | 5149 | } |
5150 | ||
6513b50d | 5151 | /* Parse the condition from an if, do, while or for statements. */ |
5152 | ||
5153 | static tree | |
5154 | c_parser_condition (c_parser *parser) | |
5155 | { | |
e60a6f7b | 5156 | location_t loc = c_parser_peek_token (parser)->location; |
6513b50d | 5157 | tree cond; |
a75b1c71 | 5158 | cond = c_parser_expression_conv (parser).value; |
5159 | cond = c_objc_common_truthvalue_conversion (loc, cond); | |
5160 | cond = c_fully_fold (cond, false, NULL); | |
6513b50d | 5161 | if (warn_sequence_point) |
5162 | verify_sequence_points (cond); | |
5163 | return cond; | |
5164 | } | |
5165 | ||
1576dec7 | 5166 | /* Parse a parenthesized condition from an if, do or while statement. |
5167 | ||
5168 | condition: | |
5169 | ( expression ) | |
5170 | */ | |
5171 | static tree | |
5172 | c_parser_paren_condition (c_parser *parser) | |
5173 | { | |
1576dec7 | 5174 | tree cond; |
5175 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
5176 | return error_mark_node; | |
6513b50d | 5177 | cond = c_parser_condition (parser); |
1576dec7 | 5178 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); |
5179 | return cond; | |
5180 | } | |
5181 | ||
5182 | /* Parse a statement which is a block in C99. */ | |
5183 | ||
5184 | static tree | |
5185 | c_parser_c99_block_statement (c_parser *parser) | |
5186 | { | |
5187 | tree block = c_begin_compound_stmt (flag_isoc99); | |
e60a6f7b | 5188 | location_t loc = c_parser_peek_token (parser)->location; |
1576dec7 | 5189 | c_parser_statement (parser); |
e60a6f7b | 5190 | return c_end_compound_stmt (loc, block, flag_isoc99); |
1576dec7 | 5191 | } |
5192 | ||
10c93a35 | 5193 | /* Parse the body of an if statement. This is just parsing a |
5194 | statement but (a) it is a block in C99, (b) we track whether the | |
5195 | body is an if statement for the sake of -Wparentheses warnings, (c) | |
5196 | we handle an empty body specially for the sake of -Wempty-body | |
5197 | warnings, and (d) we call parser_compound_statement directly | |
5198 | because c_parser_statement_after_labels resets | |
5199 | parser->in_if_block. */ | |
1576dec7 | 5200 | |
5201 | static tree | |
9255be07 | 5202 | c_parser_if_body (c_parser *parser, bool *if_p, |
5203 | const token_indent_info &if_tinfo) | |
1576dec7 | 5204 | { |
5205 | tree block = c_begin_compound_stmt (flag_isoc99); | |
e60a6f7b | 5206 | location_t body_loc = c_parser_peek_token (parser)->location; |
9255be07 | 5207 | token_indent_info body_tinfo |
5208 | = get_token_indent_info (c_parser_peek_token (parser)); | |
5209 | ||
4f284d4a | 5210 | c_parser_all_labels (parser); |
1576dec7 | 5211 | *if_p = c_parser_next_token_is_keyword (parser, RID_IF); |
ffe8fd56 | 5212 | if (c_parser_next_token_is (parser, CPP_SEMICOLON)) |
10c93a35 | 5213 | { |
c2c7830b | 5214 | location_t loc = c_parser_peek_token (parser)->location; |
e60a6f7b | 5215 | add_stmt (build_empty_stmt (loc)); |
10c93a35 | 5216 | c_parser_consume_token (parser); |
c2c7830b | 5217 | if (!c_parser_next_token_is_keyword (parser, RID_ELSE)) |
5218 | warning_at (loc, OPT_Wempty_body, | |
5219 | "suggest braces around empty body in an %<if%> statement"); | |
10c93a35 | 5220 | } |
5221 | else if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) | |
5222 | add_stmt (c_parser_compound_statement (parser)); | |
5223 | else | |
9255be07 | 5224 | c_parser_statement_after_labels (parser); |
5225 | ||
5226 | token_indent_info next_tinfo | |
5227 | = get_token_indent_info (c_parser_peek_token (parser)); | |
5228 | warn_for_misleading_indentation (if_tinfo, body_tinfo, next_tinfo); | |
e5f01cba | 5229 | |
e60a6f7b | 5230 | return c_end_compound_stmt (body_loc, block, flag_isoc99); |
10c93a35 | 5231 | } |
5232 | ||
5233 | /* Parse the else body of an if statement. This is just parsing a | |
5234 | statement but (a) it is a block in C99, (b) we handle an empty body | |
ef17a71a | 5235 | specially for the sake of -Wempty-body warnings. CHAIN is a vector |
5236 | of if-else-if conditions. */ | |
10c93a35 | 5237 | |
5238 | static tree | |
ef17a71a | 5239 | c_parser_else_body (c_parser *parser, const token_indent_info &else_tinfo, |
5240 | vec<tree> *chain) | |
10c93a35 | 5241 | { |
e5f01cba | 5242 | location_t body_loc = c_parser_peek_token (parser)->location; |
10c93a35 | 5243 | tree block = c_begin_compound_stmt (flag_isoc99); |
9255be07 | 5244 | token_indent_info body_tinfo |
5245 | = get_token_indent_info (c_parser_peek_token (parser)); | |
5246 | ||
4f284d4a | 5247 | c_parser_all_labels (parser); |
10c93a35 | 5248 | if (c_parser_next_token_is (parser, CPP_SEMICOLON)) |
5249 | { | |
e60a6f7b | 5250 | location_t loc = c_parser_peek_token (parser)->location; |
5251 | warning_at (loc, | |
c2c7830b | 5252 | OPT_Wempty_body, |
5253 | "suggest braces around empty body in an %<else%> statement"); | |
e60a6f7b | 5254 | add_stmt (build_empty_stmt (loc)); |
10c93a35 | 5255 | c_parser_consume_token (parser); |
5256 | } | |
48e1416a | 5257 | else |
ef17a71a | 5258 | c_parser_statement_after_labels (parser, chain); |
9255be07 | 5259 | |
5260 | token_indent_info next_tinfo | |
5261 | = get_token_indent_info (c_parser_peek_token (parser)); | |
5262 | warn_for_misleading_indentation (else_tinfo, body_tinfo, next_tinfo); | |
5263 | ||
e5f01cba | 5264 | return c_end_compound_stmt (body_loc, block, flag_isoc99); |
1576dec7 | 5265 | } |
5266 | ||
5267 | /* Parse an if statement (C90 6.6.4, C99 6.8.4). | |
5268 | ||
5269 | if-statement: | |
5270 | if ( expression ) statement | |
5271 | if ( expression ) statement else statement | |
ef17a71a | 5272 | |
5273 | CHAIN is a vector of if-else-if conditions. */ | |
1576dec7 | 5274 | |
5275 | static void | |
ef17a71a | 5276 | c_parser_if_statement (c_parser *parser, vec<tree> *chain) |
1576dec7 | 5277 | { |
5278 | tree block; | |
5279 | location_t loc; | |
5280 | tree cond; | |
10c93a35 | 5281 | bool first_if = false; |
1576dec7 | 5282 | tree first_body, second_body; |
10c93a35 | 5283 | bool in_if_block; |
3c6d4197 | 5284 | tree if_stmt; |
10c93a35 | 5285 | |
1576dec7 | 5286 | gcc_assert (c_parser_next_token_is_keyword (parser, RID_IF)); |
9255be07 | 5287 | token_indent_info if_tinfo |
5288 | = get_token_indent_info (c_parser_peek_token (parser)); | |
1576dec7 | 5289 | c_parser_consume_token (parser); |
5290 | block = c_begin_compound_stmt (flag_isoc99); | |
5291 | loc = c_parser_peek_token (parser)->location; | |
5292 | cond = c_parser_paren_condition (parser); | |
fdd735a7 | 5293 | if (flag_cilkplus && contains_cilk_spawn_stmt (cond)) |
5294 | { | |
5295 | error_at (loc, "if statement cannot contain %<Cilk_spawn%>"); | |
5296 | cond = error_mark_node; | |
5297 | } | |
10c93a35 | 5298 | in_if_block = parser->in_if_block; |
5299 | parser->in_if_block = true; | |
9255be07 | 5300 | first_body = c_parser_if_body (parser, &first_if, if_tinfo); |
10c93a35 | 5301 | parser->in_if_block = in_if_block; |
ef17a71a | 5302 | |
5303 | if (warn_duplicated_cond) | |
5304 | warn_duplicated_cond_add_or_warn (EXPR_LOCATION (cond), cond, &chain); | |
5305 | ||
1576dec7 | 5306 | if (c_parser_next_token_is_keyword (parser, RID_ELSE)) |
5307 | { | |
9255be07 | 5308 | token_indent_info else_tinfo |
5309 | = get_token_indent_info (c_parser_peek_token (parser)); | |
1576dec7 | 5310 | c_parser_consume_token (parser); |
ef17a71a | 5311 | if (warn_duplicated_cond) |
5312 | { | |
5313 | if (c_parser_next_token_is_keyword (parser, RID_IF) | |
5314 | && chain == NULL) | |
5315 | { | |
5316 | /* We've got "if (COND) else if (COND2)". Start the | |
5317 | condition chain and add COND as the first element. */ | |
5318 | chain = new vec<tree> (); | |
5319 | if (!CONSTANT_CLASS_P (cond) && !TREE_SIDE_EFFECTS (cond)) | |
5320 | chain->safe_push (cond); | |
5321 | } | |
5322 | else if (!c_parser_next_token_is_keyword (parser, RID_IF)) | |
5323 | { | |
5324 | /* This is if-else without subsequent if. Zap the condition | |
5325 | chain; we would have already warned at this point. */ | |
5326 | delete chain; | |
5327 | chain = NULL; | |
5328 | } | |
5329 | } | |
5330 | second_body = c_parser_else_body (parser, else_tinfo, chain); | |
1576dec7 | 5331 | } |
5332 | else | |
ef17a71a | 5333 | { |
5334 | second_body = NULL_TREE; | |
5335 | if (warn_duplicated_cond) | |
5336 | { | |
5337 | /* This if statement does not have an else clause. We don't | |
5338 | need the condition chain anymore. */ | |
5339 | delete chain; | |
5340 | chain = NULL; | |
5341 | } | |
5342 | } | |
1576dec7 | 5343 | c_finish_if_stmt (loc, cond, first_body, second_body, first_if); |
3c6d4197 | 5344 | if_stmt = c_end_compound_stmt (loc, block, flag_isoc99); |
5345 | ||
5346 | /* If the if statement contains array notations, then we expand them. */ | |
a89e6c15 | 5347 | if (flag_cilkplus && contains_array_notation_expr (if_stmt)) |
3c6d4197 | 5348 | if_stmt = fix_conditional_array_notations (if_stmt); |
5349 | add_stmt (if_stmt); | |
1576dec7 | 5350 | } |
5351 | ||
5352 | /* Parse a switch statement (C90 6.6.4, C99 6.8.4). | |
5353 | ||
5354 | switch-statement: | |
5355 | switch (expression) statement | |
5356 | */ | |
5357 | ||
5358 | static void | |
5359 | c_parser_switch_statement (c_parser *parser) | |
5360 | { | |
b560fabd | 5361 | struct c_expr ce; |
1576dec7 | 5362 | tree block, expr, body, save_break; |
e60a6f7b | 5363 | location_t switch_loc = c_parser_peek_token (parser)->location; |
5364 | location_t switch_cond_loc; | |
1576dec7 | 5365 | gcc_assert (c_parser_next_token_is_keyword (parser, RID_SWITCH)); |
5366 | c_parser_consume_token (parser); | |
5367 | block = c_begin_compound_stmt (flag_isoc99); | |
c69ec07d | 5368 | bool explicit_cast_p = false; |
1576dec7 | 5369 | if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) |
5370 | { | |
e60a6f7b | 5371 | switch_cond_loc = c_parser_peek_token (parser)->location; |
c69ec07d | 5372 | if (c_parser_next_token_is (parser, CPP_OPEN_PAREN) |
5373 | && c_token_starts_typename (c_parser_peek_2nd_token (parser))) | |
5374 | explicit_cast_p = true; | |
b560fabd | 5375 | ce = c_parser_expression (parser); |
5376 | ce = convert_lvalue_to_rvalue (switch_cond_loc, ce, true, false); | |
5377 | expr = ce.value; | |
fdd735a7 | 5378 | /* ??? expr has no valid location? */ |
5379 | if (check_no_cilk (expr, | |
5380 | "Cilk array notation cannot be used as a condition for switch statement", | |
5381 | "%<_Cilk_spawn%> statement cannot be used as a condition for switch statement", | |
5382 | switch_cond_loc)) | |
5383 | expr = error_mark_node; | |
1576dec7 | 5384 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); |
5385 | } | |
5386 | else | |
e60a6f7b | 5387 | { |
5388 | switch_cond_loc = UNKNOWN_LOCATION; | |
5389 | expr = error_mark_node; | |
5390 | } | |
c69ec07d | 5391 | c_start_case (switch_loc, switch_cond_loc, expr, explicit_cast_p); |
1576dec7 | 5392 | save_break = c_break_label; |
5393 | c_break_label = NULL_TREE; | |
5394 | body = c_parser_c99_block_statement (parser); | |
5213d6c9 | 5395 | c_finish_case (body, ce.original_type); |
1576dec7 | 5396 | if (c_break_label) |
e60a6f7b | 5397 | { |
5398 | location_t here = c_parser_peek_token (parser)->location; | |
5399 | tree t = build1 (LABEL_EXPR, void_type_node, c_break_label); | |
5400 | SET_EXPR_LOCATION (t, here); | |
5401 | add_stmt (t); | |
5402 | } | |
1576dec7 | 5403 | c_break_label = save_break; |
e60a6f7b | 5404 | add_stmt (c_end_compound_stmt (switch_loc, block, flag_isoc99)); |
1576dec7 | 5405 | } |
5406 | ||
5407 | /* Parse a while statement (C90 6.6.5, C99 6.8.5). | |
5408 | ||
5409 | while-statement: | |
5410 | while (expression) statement | |
5411 | */ | |
5412 | ||
5413 | static void | |
4c90c04c | 5414 | c_parser_while_statement (c_parser *parser, bool ivdep) |
1576dec7 | 5415 | { |
5416 | tree block, cond, body, save_break, save_cont; | |
5417 | location_t loc; | |
5418 | gcc_assert (c_parser_next_token_is_keyword (parser, RID_WHILE)); | |
9255be07 | 5419 | token_indent_info while_tinfo |
5420 | = get_token_indent_info (c_parser_peek_token (parser)); | |
1576dec7 | 5421 | c_parser_consume_token (parser); |
5422 | block = c_begin_compound_stmt (flag_isoc99); | |
5423 | loc = c_parser_peek_token (parser)->location; | |
5424 | cond = c_parser_paren_condition (parser); | |
fdd735a7 | 5425 | if (check_no_cilk (cond, |
5426 | "Cilk array notation cannot be used as a condition for while statement", | |
5427 | "%<_Cilk_spawn%> statement cannot be used as a condition for while statement")) | |
5428 | cond = error_mark_node; | |
4c90c04c | 5429 | if (ivdep && cond != error_mark_node) |
5430 | cond = build2 (ANNOTATE_EXPR, TREE_TYPE (cond), cond, | |
5431 | build_int_cst (integer_type_node, | |
5432 | annot_expr_ivdep_kind)); | |
1576dec7 | 5433 | save_break = c_break_label; |
5434 | c_break_label = NULL_TREE; | |
5435 | save_cont = c_cont_label; | |
5436 | c_cont_label = NULL_TREE; | |
e5f01cba | 5437 | |
9255be07 | 5438 | token_indent_info body_tinfo |
5439 | = get_token_indent_info (c_parser_peek_token (parser)); | |
5440 | ||
1576dec7 | 5441 | body = c_parser_c99_block_statement (parser); |
9255be07 | 5442 | |
5443 | token_indent_info next_tinfo | |
5444 | = get_token_indent_info (c_parser_peek_token (parser)); | |
5445 | warn_for_misleading_indentation (while_tinfo, body_tinfo, next_tinfo); | |
e5f01cba | 5446 | |
1576dec7 | 5447 | c_finish_loop (loc, cond, NULL, body, c_break_label, c_cont_label, true); |
e60a6f7b | 5448 | add_stmt (c_end_compound_stmt (loc, block, flag_isoc99)); |
1576dec7 | 5449 | c_break_label = save_break; |
5450 | c_cont_label = save_cont; | |
5451 | } | |
5452 | ||
5453 | /* Parse a do statement (C90 6.6.5, C99 6.8.5). | |
5454 | ||
5455 | do-statement: | |
5456 | do statement while ( expression ) ; | |
5457 | */ | |
5458 | ||
5459 | static void | |
4c90c04c | 5460 | c_parser_do_statement (c_parser *parser, bool ivdep) |
1576dec7 | 5461 | { |
5462 | tree block, cond, body, save_break, save_cont, new_break, new_cont; | |
5463 | location_t loc; | |
5464 | gcc_assert (c_parser_next_token_is_keyword (parser, RID_DO)); | |
5465 | c_parser_consume_token (parser); | |
ffe8fd56 | 5466 | if (c_parser_next_token_is (parser, CPP_SEMICOLON)) |
e3b80d49 | 5467 | warning_at (c_parser_peek_token (parser)->location, |
5468 | OPT_Wempty_body, | |
5469 | "suggest braces around empty body in %<do%> statement"); | |
1576dec7 | 5470 | block = c_begin_compound_stmt (flag_isoc99); |
5471 | loc = c_parser_peek_token (parser)->location; | |
5472 | save_break = c_break_label; | |
5473 | c_break_label = NULL_TREE; | |
5474 | save_cont = c_cont_label; | |
5475 | c_cont_label = NULL_TREE; | |
5476 | body = c_parser_c99_block_statement (parser); | |
5477 | c_parser_require_keyword (parser, RID_WHILE, "expected %<while%>"); | |
5478 | new_break = c_break_label; | |
5479 | c_break_label = save_break; | |
5480 | new_cont = c_cont_label; | |
5481 | c_cont_label = save_cont; | |
5482 | cond = c_parser_paren_condition (parser); | |
fdd735a7 | 5483 | if (check_no_cilk (cond, |
5484 | "Cilk array notation cannot be used as a condition for a do-while statement", | |
5485 | "%<_Cilk_spawn%> statement cannot be used as a condition for a do-while statement")) | |
5486 | cond = error_mark_node; | |
4c90c04c | 5487 | if (ivdep && cond != error_mark_node) |
5488 | cond = build2 (ANNOTATE_EXPR, TREE_TYPE (cond), cond, | |
5489 | build_int_cst (integer_type_node, | |
5490 | annot_expr_ivdep_kind)); | |
1576dec7 | 5491 | if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>")) |
5492 | c_parser_skip_to_end_of_block_or_statement (parser); | |
5493 | c_finish_loop (loc, cond, NULL, body, new_break, new_cont, false); | |
e60a6f7b | 5494 | add_stmt (c_end_compound_stmt (loc, block, flag_isoc99)); |
1576dec7 | 5495 | } |
5496 | ||
5497 | /* Parse a for statement (C90 6.6.5, C99 6.8.5). | |
5498 | ||
5499 | for-statement: | |
5500 | for ( expression[opt] ; expression[opt] ; expression[opt] ) statement | |
5501 | for ( nested-declaration expression[opt] ; expression[opt] ) statement | |
5502 | ||
5503 | The form with a declaration is new in C99. | |
5504 | ||
5505 | ??? In accordance with the old parser, the declaration may be a | |
5506 | nested function, which is then rejected in check_for_loop_decls, | |
5507 | but does it make any sense for this to be included in the grammar? | |
5508 | Note in particular that the nested function does not include a | |
5509 | trailing ';', whereas the "declaration" production includes one. | |
5510 | Also, can we reject bad declarations earlier and cheaper than | |
0a65c3bb | 5511 | check_for_loop_decls? |
5512 | ||
5513 | In Objective-C, there are two additional variants: | |
5514 | ||
5515 | foreach-statement: | |
5516 | for ( expression in expresssion ) statement | |
5517 | for ( declaration in expression ) statement | |
5518 | ||
5519 | This is inconsistent with C, because the second variant is allowed | |
5520 | even if c99 is not enabled. | |
5521 | ||
5522 | The rest of the comment documents these Objective-C foreach-statement. | |
5523 | ||
5524 | Here is the canonical example of the first variant: | |
5525 | for (object in array) { do something with object } | |
5526 | we call the first expression ("object") the "object_expression" and | |
5527 | the second expression ("array") the "collection_expression". | |
5528 | object_expression must be an lvalue of type "id" (a generic Objective-C | |
5529 | object) because the loop works by assigning to object_expression the | |
5530 | various objects from the collection_expression. collection_expression | |
5531 | must evaluate to something of type "id" which responds to the method | |
5532 | countByEnumeratingWithState:objects:count:. | |
5533 | ||
5534 | The canonical example of the second variant is: | |
5535 | for (id object in array) { do something with object } | |
5536 | which is completely equivalent to | |
5537 | { | |
5538 | id object; | |
5539 | for (object in array) { do something with object } | |
5540 | } | |
5541 | Note that initizializing 'object' in some way (eg, "for ((object = | |
5542 | xxx) in array) { do something with object }") is possibly | |
5543 | technically valid, but completely pointless as 'object' will be | |
5544 | assigned to something else as soon as the loop starts. We should | |
5545 | most likely reject it (TODO). | |
5546 | ||
5547 | The beginning of the Objective-C foreach-statement looks exactly | |
5548 | like the beginning of the for-statement, and we can tell it is a | |
5549 | foreach-statement only because the initial declaration or | |
5550 | expression is terminated by 'in' instead of ';'. | |
5551 | */ | |
1576dec7 | 5552 | |
5553 | static void | |
4644b593 | 5554 | c_parser_for_statement (c_parser *parser, bool ivdep) |
1576dec7 | 5555 | { |
5556 | tree block, cond, incr, save_break, save_cont, body; | |
0a65c3bb | 5557 | /* The following are only used when parsing an ObjC foreach statement. */ |
65d95190 | 5558 | tree object_expression; |
5559 | /* Silence the bogus uninitialized warning. */ | |
5560 | tree collection_expression = NULL; | |
e60a6f7b | 5561 | location_t loc = c_parser_peek_token (parser)->location; |
5562 | location_t for_loc = c_parser_peek_token (parser)->location; | |
0a65c3bb | 5563 | bool is_foreach_statement = false; |
1576dec7 | 5564 | gcc_assert (c_parser_next_token_is_keyword (parser, RID_FOR)); |
9255be07 | 5565 | token_indent_info for_tinfo |
5566 | = get_token_indent_info (c_parser_peek_token (parser)); | |
1576dec7 | 5567 | c_parser_consume_token (parser); |
0a65c3bb | 5568 | /* Open a compound statement in Objective-C as well, just in case this is |
5569 | as foreach expression. */ | |
5570 | block = c_begin_compound_stmt (flag_isoc99 || c_dialect_objc ()); | |
b54b6a4d | 5571 | cond = error_mark_node; |
5572 | incr = error_mark_node; | |
1576dec7 | 5573 | if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) |
5574 | { | |
5575 | /* Parse the initialization declaration or expression. */ | |
0a65c3bb | 5576 | object_expression = error_mark_node; |
21e609c5 | 5577 | parser->objc_could_be_foreach_context = c_dialect_objc (); |
1576dec7 | 5578 | if (c_parser_next_token_is (parser, CPP_SEMICOLON)) |
5579 | { | |
21e609c5 | 5580 | parser->objc_could_be_foreach_context = false; |
1576dec7 | 5581 | c_parser_consume_token (parser); |
e60a6f7b | 5582 | c_finish_expr_stmt (loc, NULL_TREE); |
1576dec7 | 5583 | } |
71bb4bc6 | 5584 | else if (c_parser_next_tokens_start_declaration (parser)) |
1576dec7 | 5585 | { |
0a65c3bb | 5586 | c_parser_declaration_or_fndef (parser, true, true, true, true, true, |
bc7bff74 | 5587 | &object_expression, vNULL); |
0a65c3bb | 5588 | parser->objc_could_be_foreach_context = false; |
5589 | ||
5590 | if (c_parser_next_token_is_keyword (parser, RID_IN)) | |
5591 | { | |
5592 | c_parser_consume_token (parser); | |
5593 | is_foreach_statement = true; | |
5594 | if (check_for_loop_decls (for_loc, true) == NULL_TREE) | |
5595 | c_parser_error (parser, "multiple iterating variables in fast enumeration"); | |
5596 | } | |
5597 | else | |
5598 | check_for_loop_decls (for_loc, flag_isoc99); | |
1576dec7 | 5599 | } |
5600 | else if (c_parser_next_token_is_keyword (parser, RID_EXTENSION)) | |
5601 | { | |
5602 | /* __extension__ can start a declaration, but is also an | |
5603 | unary operator that can start an expression. Consume all | |
5604 | but the last of a possible series of __extension__ to | |
5605 | determine which. */ | |
5606 | while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD | |
5607 | && (c_parser_peek_2nd_token (parser)->keyword | |
5608 | == RID_EXTENSION)) | |
5609 | c_parser_consume_token (parser); | |
f80e7755 | 5610 | if (c_token_starts_declaration (c_parser_peek_2nd_token (parser))) |
1576dec7 | 5611 | { |
5612 | int ext; | |
5613 | ext = disable_extension_diagnostics (); | |
5614 | c_parser_consume_token (parser); | |
f80e7755 | 5615 | c_parser_declaration_or_fndef (parser, true, true, true, true, |
bc7bff74 | 5616 | true, &object_expression, vNULL); |
0a65c3bb | 5617 | parser->objc_could_be_foreach_context = false; |
5618 | ||
1576dec7 | 5619 | restore_extension_diagnostics (ext); |
0a65c3bb | 5620 | if (c_parser_next_token_is_keyword (parser, RID_IN)) |
5621 | { | |
5622 | c_parser_consume_token (parser); | |
5623 | is_foreach_statement = true; | |
5624 | if (check_for_loop_decls (for_loc, true) == NULL_TREE) | |
5625 | c_parser_error (parser, "multiple iterating variables in fast enumeration"); | |
5626 | } | |
5627 | else | |
5628 | check_for_loop_decls (for_loc, flag_isoc99); | |
1576dec7 | 5629 | } |
5630 | else | |
5631 | goto init_expr; | |
5632 | } | |
5633 | else | |
5634 | { | |
5635 | init_expr: | |
0a65c3bb | 5636 | { |
b560fabd | 5637 | struct c_expr ce; |
0a65c3bb | 5638 | tree init_expression; |
b560fabd | 5639 | ce = c_parser_expression (parser); |
fdd735a7 | 5640 | /* In theory we could forbid _Cilk_spawn here, as the spec says "only in top |
5641 | level statement", but it works just fine, so allow it. */ | |
b560fabd | 5642 | init_expression = ce.value; |
0a65c3bb | 5643 | parser->objc_could_be_foreach_context = false; |
5644 | if (c_parser_next_token_is_keyword (parser, RID_IN)) | |
5645 | { | |
5646 | c_parser_consume_token (parser); | |
5647 | is_foreach_statement = true; | |
5648 | if (! lvalue_p (init_expression)) | |
5649 | c_parser_error (parser, "invalid iterating variable in fast enumeration"); | |
81976f54 | 5650 | object_expression = c_fully_fold (init_expression, false, NULL); |
0a65c3bb | 5651 | } |
5652 | else | |
5653 | { | |
b560fabd | 5654 | ce = convert_lvalue_to_rvalue (loc, ce, true, false); |
5655 | init_expression = ce.value; | |
0a65c3bb | 5656 | c_finish_expr_stmt (loc, init_expression); |
5657 | c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); | |
5658 | } | |
5659 | } | |
1576dec7 | 5660 | } |
0a65c3bb | 5661 | /* Parse the loop condition. In the case of a foreach |
5662 | statement, there is no loop condition. */ | |
21e609c5 | 5663 | gcc_assert (!parser->objc_could_be_foreach_context); |
0a65c3bb | 5664 | if (!is_foreach_statement) |
1576dec7 | 5665 | { |
0a65c3bb | 5666 | if (c_parser_next_token_is (parser, CPP_SEMICOLON)) |
5667 | { | |
4644b593 | 5668 | if (ivdep) |
5669 | { | |
5670 | c_parser_error (parser, "missing loop condition in loop with " | |
5671 | "%<GCC ivdep%> pragma"); | |
5672 | cond = error_mark_node; | |
5673 | } | |
5674 | else | |
5675 | { | |
5676 | c_parser_consume_token (parser); | |
5677 | cond = NULL_TREE; | |
5678 | } | |
0a65c3bb | 5679 | } |
5680 | else | |
5681 | { | |
5682 | cond = c_parser_condition (parser); | |
fdd735a7 | 5683 | if (check_no_cilk (cond, |
5684 | "Cilk array notation cannot be used in a condition for a for-loop", | |
5685 | "%<_Cilk_spawn%> statement cannot be used in a condition for a for-loop")) | |
5686 | cond = error_mark_node; | |
3c6d4197 | 5687 | c_parser_skip_until_found (parser, CPP_SEMICOLON, |
5688 | "expected %<;%>"); | |
0a65c3bb | 5689 | } |
4644b593 | 5690 | if (ivdep && cond != error_mark_node) |
5691 | cond = build2 (ANNOTATE_EXPR, TREE_TYPE (cond), cond, | |
5692 | build_int_cst (integer_type_node, | |
5693 | annot_expr_ivdep_kind)); | |
1576dec7 | 5694 | } |
0a65c3bb | 5695 | /* Parse the increment expression (the third expression in a |
5696 | for-statement). In the case of a foreach-statement, this is | |
5697 | the expression that follows the 'in'. */ | |
5698 | if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) | |
1576dec7 | 5699 | { |
0a65c3bb | 5700 | if (is_foreach_statement) |
5701 | { | |
5702 | c_parser_error (parser, "missing collection in fast enumeration"); | |
5703 | collection_expression = error_mark_node; | |
5704 | } | |
5705 | else | |
5706 | incr = c_process_expr_stmt (loc, NULL_TREE); | |
1576dec7 | 5707 | } |
1576dec7 | 5708 | else |
0a65c3bb | 5709 | { |
5710 | if (is_foreach_statement) | |
81976f54 | 5711 | collection_expression = c_fully_fold (c_parser_expression (parser).value, |
5712 | false, NULL); | |
0a65c3bb | 5713 | else |
b560fabd | 5714 | { |
5715 | struct c_expr ce = c_parser_expression (parser); | |
5716 | ce = convert_lvalue_to_rvalue (loc, ce, true, false); | |
5717 | incr = c_process_expr_stmt (loc, ce.value); | |
5718 | } | |
0a65c3bb | 5719 | } |
1576dec7 | 5720 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); |
5721 | } | |
1576dec7 | 5722 | save_break = c_break_label; |
5723 | c_break_label = NULL_TREE; | |
5724 | save_cont = c_cont_label; | |
5725 | c_cont_label = NULL_TREE; | |
e5f01cba | 5726 | |
9255be07 | 5727 | token_indent_info body_tinfo |
5728 | = get_token_indent_info (c_parser_peek_token (parser)); | |
5729 | ||
1576dec7 | 5730 | body = c_parser_c99_block_statement (parser); |
9255be07 | 5731 | |
5732 | token_indent_info next_tinfo | |
5733 | = get_token_indent_info (c_parser_peek_token (parser)); | |
5734 | warn_for_misleading_indentation (for_tinfo, body_tinfo, next_tinfo); | |
e5f01cba | 5735 | |
0a65c3bb | 5736 | if (is_foreach_statement) |
5737 | objc_finish_foreach_loop (loc, object_expression, collection_expression, body, c_break_label, c_cont_label); | |
5738 | else | |
5739 | c_finish_loop (loc, cond, incr, body, c_break_label, c_cont_label, true); | |
5740 | add_stmt (c_end_compound_stmt (loc, block, flag_isoc99 || c_dialect_objc ())); | |
1576dec7 | 5741 | c_break_label = save_break; |
5742 | c_cont_label = save_cont; | |
5743 | } | |
5744 | ||
5745 | /* Parse an asm statement, a GNU extension. This is a full-blown asm | |
5746 | statement with inputs, outputs, clobbers, and volatile tag | |
5747 | allowed. | |
5748 | ||
5749 | asm-statement: | |
5750 | asm type-qualifier[opt] ( asm-argument ) ; | |
78f55ca8 | 5751 | asm type-qualifier[opt] goto ( asm-goto-argument ) ; |
1576dec7 | 5752 | |
5753 | asm-argument: | |
5754 | asm-string-literal | |
5755 | asm-string-literal : asm-operands[opt] | |
5756 | asm-string-literal : asm-operands[opt] : asm-operands[opt] | |
78f55ca8 | 5757 | asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers[opt] |
5758 | ||
5759 | asm-goto-argument: | |
5760 | asm-string-literal : : asm-operands[opt] : asm-clobbers[opt] \ | |
5761 | : asm-goto-operands | |
1576dec7 | 5762 | |
5763 | Qualifiers other than volatile are accepted in the syntax but | |
5764 | warned for. */ | |
5765 | ||
5766 | static tree | |
5767 | c_parser_asm_statement (c_parser *parser) | |
5768 | { | |
78f55ca8 | 5769 | tree quals, str, outputs, inputs, clobbers, labels, ret; |
5770 | bool simple, is_goto; | |
e60a6f7b | 5771 | location_t asm_loc = c_parser_peek_token (parser)->location; |
78f55ca8 | 5772 | int section, nsections; |
5773 | ||
1576dec7 | 5774 | gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM)); |
5775 | c_parser_consume_token (parser); | |
5776 | if (c_parser_next_token_is_keyword (parser, RID_VOLATILE)) | |
5777 | { | |
5778 | quals = c_parser_peek_token (parser)->value; | |
5779 | c_parser_consume_token (parser); | |
5780 | } | |
5781 | else if (c_parser_next_token_is_keyword (parser, RID_CONST) | |
5782 | || c_parser_next_token_is_keyword (parser, RID_RESTRICT)) | |
5783 | { | |
e3b80d49 | 5784 | warning_at (c_parser_peek_token (parser)->location, |
5785 | 0, | |
5786 | "%E qualifier ignored on asm", | |
5787 | c_parser_peek_token (parser)->value); | |
1576dec7 | 5788 | quals = NULL_TREE; |
5789 | c_parser_consume_token (parser); | |
5790 | } | |
5791 | else | |
5792 | quals = NULL_TREE; | |
78f55ca8 | 5793 | |
5794 | is_goto = false; | |
5795 | if (c_parser_next_token_is_keyword (parser, RID_GOTO)) | |
5796 | { | |
5797 | c_parser_consume_token (parser); | |
5798 | is_goto = true; | |
5799 | } | |
5800 | ||
1576dec7 | 5801 | /* ??? Follow the C++ parser rather than using the |
8115b8be | 5802 | lex_untranslated_string kludge. */ |
5803 | parser->lex_untranslated_string = true; | |
78f55ca8 | 5804 | ret = NULL; |
5805 | ||
1576dec7 | 5806 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) |
78f55ca8 | 5807 | goto error; |
5808 | ||
1576dec7 | 5809 | str = c_parser_asm_string_literal (parser); |
0930c694 | 5810 | if (str == NULL_TREE) |
78f55ca8 | 5811 | goto error_close_paren; |
5812 | ||
5813 | simple = true; | |
5814 | outputs = NULL_TREE; | |
5815 | inputs = NULL_TREE; | |
5816 | clobbers = NULL_TREE; | |
5817 | labels = NULL_TREE; | |
5818 | ||
5819 | if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN) && !is_goto) | |
5820 | goto done_asm; | |
5821 | ||
5822 | /* Parse each colon-delimited section of operands. */ | |
5823 | nsections = 3 + is_goto; | |
5824 | for (section = 0; section < nsections; ++section) | |
0930c694 | 5825 | { |
78f55ca8 | 5826 | if (!c_parser_require (parser, CPP_COLON, |
5827 | is_goto | |
5828 | ? "expected %<:%>" | |
5829 | : "expected %<:%> or %<)%>")) | |
5830 | goto error_close_paren; | |
5831 | ||
5832 | /* Once past any colon, we're no longer a simple asm. */ | |
5833 | simple = false; | |
5834 | ||
5835 | if ((!c_parser_next_token_is (parser, CPP_COLON) | |
5836 | && !c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) | |
5837 | || section == 3) | |
5838 | switch (section) | |
5839 | { | |
5840 | case 0: | |
5841 | /* For asm goto, we don't allow output operands, but reserve | |
5842 | the slot for a future extension that does allow them. */ | |
5843 | if (!is_goto) | |
035b65e2 | 5844 | outputs = c_parser_asm_operands (parser); |
78f55ca8 | 5845 | break; |
5846 | case 1: | |
035b65e2 | 5847 | inputs = c_parser_asm_operands (parser); |
78f55ca8 | 5848 | break; |
5849 | case 2: | |
5850 | clobbers = c_parser_asm_clobbers (parser); | |
5851 | break; | |
5852 | case 3: | |
5853 | labels = c_parser_asm_goto_operands (parser); | |
5854 | break; | |
5855 | default: | |
5856 | gcc_unreachable (); | |
5857 | } | |
5858 | ||
5859 | if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN) && !is_goto) | |
5860 | goto done_asm; | |
1576dec7 | 5861 | } |
78f55ca8 | 5862 | |
1576dec7 | 5863 | done_asm: |
1576dec7 | 5864 | if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>")) |
5865 | { | |
5866 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); | |
78f55ca8 | 5867 | goto error; |
1576dec7 | 5868 | } |
78f55ca8 | 5869 | |
1576dec7 | 5870 | if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>")) |
5871 | c_parser_skip_to_end_of_block_or_statement (parser); | |
78f55ca8 | 5872 | |
e60a6f7b | 5873 | ret = build_asm_stmt (quals, build_asm_expr (asm_loc, str, outputs, inputs, |
78f55ca8 | 5874 | clobbers, labels, simple)); |
5875 | ||
5876 | error: | |
5877 | parser->lex_untranslated_string = false; | |
1576dec7 | 5878 | return ret; |
78f55ca8 | 5879 | |
5880 | error_close_paren: | |
5881 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); | |
5882 | goto error; | |
1576dec7 | 5883 | } |
5884 | ||
035b65e2 | 5885 | /* Parse asm operands, a GNU extension. |
1576dec7 | 5886 | |
5887 | asm-operands: | |
5888 | asm-operand | |
5889 | asm-operands , asm-operand | |
5890 | ||
5891 | asm-operand: | |
5892 | asm-string-literal ( expression ) | |
5893 | [ identifier ] asm-string-literal ( expression ) | |
5894 | */ | |
5895 | ||
5896 | static tree | |
035b65e2 | 5897 | c_parser_asm_operands (c_parser *parser) |
1576dec7 | 5898 | { |
5899 | tree list = NULL_TREE; | |
5900 | while (true) | |
5901 | { | |
e78cf9a7 | 5902 | tree name, str; |
5903 | struct c_expr expr; | |
1576dec7 | 5904 | if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE)) |
5905 | { | |
5906 | c_parser_consume_token (parser); | |
5907 | if (c_parser_next_token_is (parser, CPP_NAME)) | |
5908 | { | |
5909 | tree id = c_parser_peek_token (parser)->value; | |
5910 | c_parser_consume_token (parser); | |
5911 | name = build_string (IDENTIFIER_LENGTH (id), | |
5912 | IDENTIFIER_POINTER (id)); | |
5913 | } | |
5914 | else | |
5915 | { | |
5916 | c_parser_error (parser, "expected identifier"); | |
5917 | c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL); | |
5918 | return NULL_TREE; | |
5919 | } | |
5920 | c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, | |
5921 | "expected %<]%>"); | |
5922 | } | |
5923 | else | |
5924 | name = NULL_TREE; | |
5925 | str = c_parser_asm_string_literal (parser); | |
5926 | if (str == NULL_TREE) | |
5927 | return NULL_TREE; | |
8115b8be | 5928 | parser->lex_untranslated_string = false; |
1576dec7 | 5929 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) |
5930 | { | |
8115b8be | 5931 | parser->lex_untranslated_string = true; |
1576dec7 | 5932 | return NULL_TREE; |
5933 | } | |
e78cf9a7 | 5934 | expr = c_parser_expression (parser); |
abc6c64f | 5935 | mark_exp_read (expr.value); |
8115b8be | 5936 | parser->lex_untranslated_string = true; |
1576dec7 | 5937 | if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>")) |
5938 | { | |
5939 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); | |
5940 | return NULL_TREE; | |
5941 | } | |
5942 | list = chainon (list, build_tree_list (build_tree_list (name, str), | |
e78cf9a7 | 5943 | expr.value)); |
1576dec7 | 5944 | if (c_parser_next_token_is (parser, CPP_COMMA)) |
5945 | c_parser_consume_token (parser); | |
5946 | else | |
5947 | break; | |
5948 | } | |
5949 | return list; | |
5950 | } | |
5951 | ||
5952 | /* Parse asm clobbers, a GNU extension. | |
5953 | ||
5954 | asm-clobbers: | |
5955 | asm-string-literal | |
5956 | asm-clobbers , asm-string-literal | |
5957 | */ | |
5958 | ||
5959 | static tree | |
5960 | c_parser_asm_clobbers (c_parser *parser) | |
5961 | { | |
5962 | tree list = NULL_TREE; | |
5963 | while (true) | |
5964 | { | |
5965 | tree str = c_parser_asm_string_literal (parser); | |
5966 | if (str) | |
5967 | list = tree_cons (NULL_TREE, str, list); | |
5968 | else | |
5969 | return NULL_TREE; | |
5970 | if (c_parser_next_token_is (parser, CPP_COMMA)) | |
5971 | c_parser_consume_token (parser); | |
5972 | else | |
5973 | break; | |
5974 | } | |
5975 | return list; | |
5976 | } | |
5977 | ||
78f55ca8 | 5978 | /* Parse asm goto labels, a GNU extension. |
48e1416a | 5979 | |
78f55ca8 | 5980 | asm-goto-operands: |
5981 | identifier | |
5982 | asm-goto-operands , identifier | |
5983 | */ | |
5984 | ||
5985 | static tree | |
5986 | c_parser_asm_goto_operands (c_parser *parser) | |
5987 | { | |
5988 | tree list = NULL_TREE; | |
5989 | while (true) | |
5990 | { | |
5991 | tree name, label; | |
5992 | ||
5993 | if (c_parser_next_token_is (parser, CPP_NAME)) | |
5994 | { | |
5995 | c_token *tok = c_parser_peek_token (parser); | |
5996 | name = tok->value; | |
5997 | label = lookup_label_for_goto (tok->location, name); | |
5998 | c_parser_consume_token (parser); | |
5999 | TREE_USED (label) = 1; | |
6000 | } | |
6001 | else | |
6002 | { | |
6003 | c_parser_error (parser, "expected identifier"); | |
6004 | return NULL_TREE; | |
6005 | } | |
6006 | ||
6007 | name = build_string (IDENTIFIER_LENGTH (name), | |
6008 | IDENTIFIER_POINTER (name)); | |
6009 | list = tree_cons (name, label, list); | |
6010 | if (c_parser_next_token_is (parser, CPP_COMMA)) | |
6011 | c_parser_consume_token (parser); | |
6012 | else | |
6013 | return nreverse (list); | |
6014 | } | |
6015 | } | |
6016 | ||
1576dec7 | 6017 | /* Parse an expression other than a compound expression; that is, an |
6018 | assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not | |
6019 | NULL then it is an Objective-C message expression which is the | |
6020 | primary-expression starting the expression as an initializer. | |
6021 | ||
6022 | assignment-expression: | |
6023 | conditional-expression | |
6024 | unary-expression assignment-operator assignment-expression | |
6025 | ||
6026 | assignment-operator: one of | |
6027 | = *= /= %= += -= <<= >>= &= ^= |= | |
6028 | ||
6029 | In GNU C we accept any conditional expression on the LHS and | |
6030 | diagnose the invalid lvalue rather than producing a syntax | |
6031 | error. */ | |
6032 | ||
6033 | static struct c_expr | |
bc7bff74 | 6034 | c_parser_expr_no_commas (c_parser *parser, struct c_expr *after, |
6035 | tree omp_atomic_lhs) | |
1576dec7 | 6036 | { |
6037 | struct c_expr lhs, rhs, ret; | |
6038 | enum tree_code code; | |
e60a6f7b | 6039 | location_t op_location, exp_location; |
1576dec7 | 6040 | gcc_assert (!after || c_dialect_objc ()); |
bc7bff74 | 6041 | lhs = c_parser_conditional_expression (parser, after, omp_atomic_lhs); |
b6889cb0 | 6042 | op_location = c_parser_peek_token (parser)->location; |
1576dec7 | 6043 | switch (c_parser_peek_token (parser)->type) |
6044 | { | |
6045 | case CPP_EQ: | |
6046 | code = NOP_EXPR; | |
6047 | break; | |
6048 | case CPP_MULT_EQ: | |
6049 | code = MULT_EXPR; | |
6050 | break; | |
6051 | case CPP_DIV_EQ: | |
6052 | code = TRUNC_DIV_EXPR; | |
6053 | break; | |
6054 | case CPP_MOD_EQ: | |
6055 | code = TRUNC_MOD_EXPR; | |
6056 | break; | |
6057 | case CPP_PLUS_EQ: | |
6058 | code = PLUS_EXPR; | |
6059 | break; | |
6060 | case CPP_MINUS_EQ: | |
6061 | code = MINUS_EXPR; | |
6062 | break; | |
6063 | case CPP_LSHIFT_EQ: | |
6064 | code = LSHIFT_EXPR; | |
6065 | break; | |
6066 | case CPP_RSHIFT_EQ: | |
6067 | code = RSHIFT_EXPR; | |
6068 | break; | |
6069 | case CPP_AND_EQ: | |
6070 | code = BIT_AND_EXPR; | |
6071 | break; | |
6072 | case CPP_XOR_EQ: | |
6073 | code = BIT_XOR_EXPR; | |
6074 | break; | |
6075 | case CPP_OR_EQ: | |
6076 | code = BIT_IOR_EXPR; | |
6077 | break; | |
6078 | default: | |
6079 | return lhs; | |
6080 | } | |
6081 | c_parser_consume_token (parser); | |
e60a6f7b | 6082 | exp_location = c_parser_peek_token (parser)->location; |
1576dec7 | 6083 | rhs = c_parser_expr_no_commas (parser, NULL); |
b560fabd | 6084 | rhs = convert_lvalue_to_rvalue (exp_location, rhs, true, true); |
3c6d4197 | 6085 | |
cc92dddc | 6086 | ret.value = build_modify_expr (op_location, lhs.value, lhs.original_type, |
6087 | code, exp_location, rhs.value, | |
6088 | rhs.original_type); | |
1576dec7 | 6089 | if (code == NOP_EXPR) |
6090 | ret.original_code = MODIFY_EXPR; | |
6091 | else | |
6092 | { | |
6093 | TREE_NO_WARNING (ret.value) = 1; | |
6094 | ret.original_code = ERROR_MARK; | |
6095 | } | |
841fdaa6 | 6096 | ret.original_type = NULL; |
1576dec7 | 6097 | return ret; |
6098 | } | |
6099 | ||
6100 | /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER | |
6101 | is not NULL then it is an Objective-C message expression which is | |
6102 | the primary-expression starting the expression as an initializer. | |
6103 | ||
6104 | conditional-expression: | |
6105 | logical-OR-expression | |
6106 | logical-OR-expression ? expression : conditional-expression | |
6107 | ||
6108 | GNU extensions: | |
6109 | ||
6110 | conditional-expression: | |
6111 | logical-OR-expression ? : conditional-expression | |
6112 | */ | |
6113 | ||
6114 | static struct c_expr | |
bc7bff74 | 6115 | c_parser_conditional_expression (c_parser *parser, struct c_expr *after, |
6116 | tree omp_atomic_lhs) | |
1576dec7 | 6117 | { |
6118 | struct c_expr cond, exp1, exp2, ret; | |
b9bdfa0b | 6119 | location_t cond_loc, colon_loc, middle_loc; |
8e70fb09 | 6120 | |
1576dec7 | 6121 | gcc_assert (!after || c_dialect_objc ()); |
8e70fb09 | 6122 | |
bc7bff74 | 6123 | cond = c_parser_binary_expression (parser, after, omp_atomic_lhs); |
8e70fb09 | 6124 | |
1576dec7 | 6125 | if (c_parser_next_token_is_not (parser, CPP_QUERY)) |
6126 | return cond; | |
e60a6f7b | 6127 | cond_loc = c_parser_peek_token (parser)->location; |
b560fabd | 6128 | cond = convert_lvalue_to_rvalue (cond_loc, cond, true, true); |
1576dec7 | 6129 | c_parser_consume_token (parser); |
6130 | if (c_parser_next_token_is (parser, CPP_COLON)) | |
6131 | { | |
c6418a4e | 6132 | tree eptype = NULL_TREE; |
b9bdfa0b | 6133 | |
6134 | middle_loc = c_parser_peek_token (parser)->location; | |
29438999 | 6135 | pedwarn (middle_loc, OPT_Wpedantic, |
21ca8540 | 6136 | "ISO C forbids omitting the middle term of a ?: expression"); |
b9bdfa0b | 6137 | warn_for_omitted_condop (middle_loc, cond.value); |
c6418a4e | 6138 | if (TREE_CODE (cond.value) == EXCESS_PRECISION_EXPR) |
6139 | { | |
6140 | eptype = TREE_TYPE (cond.value); | |
6141 | cond.value = TREE_OPERAND (cond.value, 0); | |
6142 | } | |
1576dec7 | 6143 | /* Make sure first operand is calculated only once. */ |
a75b1c71 | 6144 | exp1.value = c_save_expr (default_conversion (cond.value)); |
c6418a4e | 6145 | if (eptype) |
6146 | exp1.value = build1 (EXCESS_PRECISION_EXPR, eptype, exp1.value); | |
841fdaa6 | 6147 | exp1.original_type = NULL; |
8e70fb09 | 6148 | cond.value = c_objc_common_truthvalue_conversion (cond_loc, exp1.value); |
48d94ede | 6149 | c_inhibit_evaluation_warnings += cond.value == truthvalue_true_node; |
1576dec7 | 6150 | } |
6151 | else | |
6152 | { | |
6153 | cond.value | |
45a78cc0 | 6154 | = c_objc_common_truthvalue_conversion |
8e70fb09 | 6155 | (cond_loc, default_conversion (cond.value)); |
48d94ede | 6156 | c_inhibit_evaluation_warnings += cond.value == truthvalue_false_node; |
f14c8207 | 6157 | exp1 = c_parser_expression_conv (parser); |
abc6c64f | 6158 | mark_exp_read (exp1.value); |
48d94ede | 6159 | c_inhibit_evaluation_warnings += |
6160 | ((cond.value == truthvalue_true_node) | |
6161 | - (cond.value == truthvalue_false_node)); | |
1576dec7 | 6162 | } |
d5b637fa | 6163 | |
6164 | colon_loc = c_parser_peek_token (parser)->location; | |
1576dec7 | 6165 | if (!c_parser_require (parser, CPP_COLON, "expected %<:%>")) |
6166 | { | |
48d94ede | 6167 | c_inhibit_evaluation_warnings -= cond.value == truthvalue_true_node; |
1576dec7 | 6168 | ret.value = error_mark_node; |
6169 | ret.original_code = ERROR_MARK; | |
841fdaa6 | 6170 | ret.original_type = NULL; |
1576dec7 | 6171 | return ret; |
6172 | } | |
e60a6f7b | 6173 | { |
6174 | location_t exp2_loc = c_parser_peek_token (parser)->location; | |
bc7bff74 | 6175 | exp2 = c_parser_conditional_expression (parser, NULL, NULL_TREE); |
b560fabd | 6176 | exp2 = convert_lvalue_to_rvalue (exp2_loc, exp2, true, true); |
e60a6f7b | 6177 | } |
48d94ede | 6178 | c_inhibit_evaluation_warnings -= cond.value == truthvalue_true_node; |
d5b637fa | 6179 | ret.value = build_conditional_expr (colon_loc, cond.value, |
a75b1c71 | 6180 | cond.original_code == C_MAYBE_CONST_EXPR, |
6163a125 | 6181 | exp1.value, exp1.original_type, |
6182 | exp2.value, exp2.original_type); | |
1576dec7 | 6183 | ret.original_code = ERROR_MARK; |
841fdaa6 | 6184 | if (exp1.value == error_mark_node || exp2.value == error_mark_node) |
6185 | ret.original_type = NULL; | |
6186 | else | |
6187 | { | |
6188 | tree t1, t2; | |
6189 | ||
6190 | /* If both sides are enum type, the default conversion will have | |
6191 | made the type of the result be an integer type. We want to | |
6192 | remember the enum types we started with. */ | |
6193 | t1 = exp1.original_type ? exp1.original_type : TREE_TYPE (exp1.value); | |
6194 | t2 = exp2.original_type ? exp2.original_type : TREE_TYPE (exp2.value); | |
6195 | ret.original_type = ((t1 != error_mark_node | |
6196 | && t2 != error_mark_node | |
6197 | && (TYPE_MAIN_VARIANT (t1) | |
6198 | == TYPE_MAIN_VARIANT (t2))) | |
6199 | ? t1 | |
6200 | : NULL); | |
6201 | } | |
1576dec7 | 6202 | return ret; |
6203 | } | |
6204 | ||
6205 | /* Parse a binary expression; that is, a logical-OR-expression (C90 | |
6206 | 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is | |
6207 | an Objective-C message expression which is the primary-expression | |
bc7bff74 | 6208 | starting the expression as an initializer. |
6209 | ||
6210 | OMP_ATOMIC_LHS is NULL, unless parsing OpenMP #pragma omp atomic, | |
6211 | when it should be the unfolded lhs. In a valid OpenMP source, | |
6212 | one of the operands of the toplevel binary expression must be equal | |
6213 | to it. In that case, just return a build2 created binary operation | |
6214 | rather than result of parser_build_binary_op. | |
1576dec7 | 6215 | |
6216 | multiplicative-expression: | |
6217 | cast-expression | |
6218 | multiplicative-expression * cast-expression | |
6219 | multiplicative-expression / cast-expression | |
6220 | multiplicative-expression % cast-expression | |
6221 | ||
6222 | additive-expression: | |
6223 | multiplicative-expression | |
6224 | additive-expression + multiplicative-expression | |
6225 | additive-expression - multiplicative-expression | |
6226 | ||
6227 | shift-expression: | |
6228 | additive-expression | |
6229 | shift-expression << additive-expression | |
6230 | shift-expression >> additive-expression | |
6231 | ||
6232 | relational-expression: | |
6233 | shift-expression | |
6234 | relational-expression < shift-expression | |
6235 | relational-expression > shift-expression | |
6236 | relational-expression <= shift-expression | |
6237 | relational-expression >= shift-expression | |
6238 | ||
6239 | equality-expression: | |
6240 | relational-expression | |
6241 | equality-expression == relational-expression | |
6242 | equality-expression != relational-expression | |
6243 | ||
6244 | AND-expression: | |
6245 | equality-expression | |
6246 | AND-expression & equality-expression | |
6247 | ||
6248 | exclusive-OR-expression: | |
6249 | AND-expression | |
6250 | exclusive-OR-expression ^ AND-expression | |
6251 | ||
6252 | inclusive-OR-expression: | |
6253 | exclusive-OR-expression | |
6254 | inclusive-OR-expression | exclusive-OR-expression | |
6255 | ||
6256 | logical-AND-expression: | |
6257 | inclusive-OR-expression | |
6258 | logical-AND-expression && inclusive-OR-expression | |
6259 | ||
6260 | logical-OR-expression: | |
6261 | logical-AND-expression | |
6262 | logical-OR-expression || logical-AND-expression | |
6263 | */ | |
6264 | ||
6265 | static struct c_expr | |
2169f33b | 6266 | c_parser_binary_expression (c_parser *parser, struct c_expr *after, |
bc7bff74 | 6267 | tree omp_atomic_lhs) |
1576dec7 | 6268 | { |
6269 | /* A binary expression is parsed using operator-precedence parsing, | |
6270 | with the operands being cast expressions. All the binary | |
6271 | operators are left-associative. Thus a binary expression is of | |
6272 | form: | |
6273 | ||
6274 | E0 op1 E1 op2 E2 ... | |
6275 | ||
6276 | which we represent on a stack. On the stack, the precedence | |
6277 | levels are strictly increasing. When a new operator is | |
6278 | encountered of higher precedence than that at the top of the | |
6279 | stack, it is pushed; its LHS is the top expression, and its RHS | |
6280 | is everything parsed until it is popped. When a new operator is | |
6281 | encountered with precedence less than or equal to that at the top | |
6282 | of the stack, triples E[i-1] op[i] E[i] are popped and replaced | |
6283 | by the result of the operation until the operator at the top of | |
6284 | the stack has lower precedence than the new operator or there is | |
6285 | only one element on the stack; then the top expression is the LHS | |
6286 | of the new operator. In the case of logical AND and OR | |
48d94ede | 6287 | expressions, we also need to adjust c_inhibit_evaluation_warnings |
6288 | as appropriate when the operators are pushed and popped. */ | |
1576dec7 | 6289 | |
1576dec7 | 6290 | struct { |
6291 | /* The expression at this stack level. */ | |
6292 | struct c_expr expr; | |
6293 | /* The precedence of the operator on its left, PREC_NONE at the | |
6294 | bottom of the stack. */ | |
2169f33b | 6295 | enum c_parser_prec prec; |
1576dec7 | 6296 | /* The operation on its left. */ |
6297 | enum tree_code op; | |
43158006 | 6298 | /* The source location of this operation. */ |
6299 | location_t loc; | |
1576dec7 | 6300 | } stack[NUM_PRECS]; |
6301 | int sp; | |
8e70fb09 | 6302 | /* Location of the binary operator. */ |
0eaffeb7 | 6303 | location_t binary_loc = UNKNOWN_LOCATION; /* Quiet warning. */ |
1576dec7 | 6304 | #define POP \ |
6305 | do { \ | |
6306 | switch (stack[sp].op) \ | |
6307 | { \ | |
6308 | case TRUTH_ANDIF_EXPR: \ | |
48d94ede | 6309 | c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \ |
6310 | == truthvalue_false_node); \ | |
1576dec7 | 6311 | break; \ |
6312 | case TRUTH_ORIF_EXPR: \ | |
48d94ede | 6313 | c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \ |
6314 | == truthvalue_true_node); \ | |
1576dec7 | 6315 | break; \ |
6316 | default: \ | |
6317 | break; \ | |
6318 | } \ | |
e78cf9a7 | 6319 | stack[sp - 1].expr \ |
b560fabd | 6320 | = convert_lvalue_to_rvalue (stack[sp - 1].loc, \ |
6321 | stack[sp - 1].expr, true, true); \ | |
e78cf9a7 | 6322 | stack[sp].expr \ |
b560fabd | 6323 | = convert_lvalue_to_rvalue (stack[sp].loc, \ |
6324 | stack[sp].expr, true, true); \ | |
bc7bff74 | 6325 | if (__builtin_expect (omp_atomic_lhs != NULL_TREE, 0) && sp == 1 \ |
6326 | && c_parser_peek_token (parser)->type == CPP_SEMICOLON \ | |
6327 | && ((1 << stack[sp].prec) \ | |
35ff54b5 | 6328 | & ((1 << PREC_BITOR) | (1 << PREC_BITXOR) | (1 << PREC_BITAND) \ |
6329 | | (1 << PREC_SHIFT) | (1 << PREC_ADD) | (1 << PREC_MULT))) \ | |
bc7bff74 | 6330 | && stack[sp].op != TRUNC_MOD_EXPR \ |
6331 | && stack[0].expr.value != error_mark_node \ | |
6332 | && stack[1].expr.value != error_mark_node \ | |
6333 | && (c_tree_equal (stack[0].expr.value, omp_atomic_lhs) \ | |
6334 | || c_tree_equal (stack[1].expr.value, omp_atomic_lhs))) \ | |
6335 | stack[0].expr.value \ | |
6336 | = build2 (stack[1].op, TREE_TYPE (stack[0].expr.value), \ | |
6337 | stack[0].expr.value, stack[1].expr.value); \ | |
6338 | else \ | |
6339 | stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc, \ | |
6340 | stack[sp].op, \ | |
6341 | stack[sp - 1].expr, \ | |
6342 | stack[sp].expr); \ | |
1576dec7 | 6343 | sp--; \ |
6344 | } while (0) | |
6345 | gcc_assert (!after || c_dialect_objc ()); | |
43158006 | 6346 | stack[0].loc = c_parser_peek_token (parser)->location; |
1576dec7 | 6347 | stack[0].expr = c_parser_cast_expression (parser, after); |
bc7bff74 | 6348 | stack[0].prec = PREC_NONE; |
1576dec7 | 6349 | sp = 0; |
6350 | while (true) | |
6351 | { | |
2169f33b | 6352 | enum c_parser_prec oprec; |
1576dec7 | 6353 | enum tree_code ocode; |
6354 | if (parser->error) | |
6355 | goto out; | |
6356 | switch (c_parser_peek_token (parser)->type) | |
6357 | { | |
6358 | case CPP_MULT: | |
6359 | oprec = PREC_MULT; | |
6360 | ocode = MULT_EXPR; | |
6361 | break; | |
6362 | case CPP_DIV: | |
6363 | oprec = PREC_MULT; | |
6364 | ocode = TRUNC_DIV_EXPR; | |
6365 | break; | |
6366 | case CPP_MOD: | |
6367 | oprec = PREC_MULT; | |
6368 | ocode = TRUNC_MOD_EXPR; | |
6369 | break; | |
6370 | case CPP_PLUS: | |
6371 | oprec = PREC_ADD; | |
6372 | ocode = PLUS_EXPR; | |
6373 | break; | |
6374 | case CPP_MINUS: | |
6375 | oprec = PREC_ADD; | |
6376 | ocode = MINUS_EXPR; | |
6377 | break; | |
6378 | case CPP_LSHIFT: | |
6379 | oprec = PREC_SHIFT; | |
6380 | ocode = LSHIFT_EXPR; | |
6381 | break; | |
6382 | case CPP_RSHIFT: | |
6383 | oprec = PREC_SHIFT; | |
6384 | ocode = RSHIFT_EXPR; | |
6385 | break; | |
6386 | case CPP_LESS: | |
6387 | oprec = PREC_REL; | |
6388 | ocode = LT_EXPR; | |
6389 | break; | |
6390 | case CPP_GREATER: | |
6391 | oprec = PREC_REL; | |
6392 | ocode = GT_EXPR; | |
6393 | break; | |
6394 | case CPP_LESS_EQ: | |
6395 | oprec = PREC_REL; | |
6396 | ocode = LE_EXPR; | |
6397 | break; | |
6398 | case CPP_GREATER_EQ: | |
6399 | oprec = PREC_REL; | |
6400 | ocode = GE_EXPR; | |
6401 | break; | |
6402 | case CPP_EQ_EQ: | |
6403 | oprec = PREC_EQ; | |
6404 | ocode = EQ_EXPR; | |
6405 | break; | |
6406 | case CPP_NOT_EQ: | |
6407 | oprec = PREC_EQ; | |
6408 | ocode = NE_EXPR; | |
6409 | break; | |
6410 | case CPP_AND: | |
6411 | oprec = PREC_BITAND; | |
6412 | ocode = BIT_AND_EXPR; | |
6413 | break; | |
6414 | case CPP_XOR: | |
6415 | oprec = PREC_BITXOR; | |
6416 | ocode = BIT_XOR_EXPR; | |
6417 | break; | |
6418 | case CPP_OR: | |
6419 | oprec = PREC_BITOR; | |
6420 | ocode = BIT_IOR_EXPR; | |
6421 | break; | |
6422 | case CPP_AND_AND: | |
6423 | oprec = PREC_LOGAND; | |
6424 | ocode = TRUTH_ANDIF_EXPR; | |
6425 | break; | |
6426 | case CPP_OR_OR: | |
6427 | oprec = PREC_LOGOR; | |
6428 | ocode = TRUTH_ORIF_EXPR; | |
6429 | break; | |
6430 | default: | |
6431 | /* Not a binary operator, so end of the binary | |
6432 | expression. */ | |
6433 | goto out; | |
6434 | } | |
8e70fb09 | 6435 | binary_loc = c_parser_peek_token (parser)->location; |
1576dec7 | 6436 | while (oprec <= stack[sp].prec) |
bc7bff74 | 6437 | POP; |
2169f33b | 6438 | c_parser_consume_token (parser); |
1576dec7 | 6439 | switch (ocode) |
6440 | { | |
6441 | case TRUTH_ANDIF_EXPR: | |
e78cf9a7 | 6442 | stack[sp].expr |
b560fabd | 6443 | = convert_lvalue_to_rvalue (stack[sp].loc, |
6444 | stack[sp].expr, true, true); | |
45a78cc0 | 6445 | stack[sp].expr.value = c_objc_common_truthvalue_conversion |
43158006 | 6446 | (stack[sp].loc, default_conversion (stack[sp].expr.value)); |
48d94ede | 6447 | c_inhibit_evaluation_warnings += (stack[sp].expr.value |
6448 | == truthvalue_false_node); | |
1576dec7 | 6449 | break; |
6450 | case TRUTH_ORIF_EXPR: | |
e78cf9a7 | 6451 | stack[sp].expr |
b560fabd | 6452 | = convert_lvalue_to_rvalue (stack[sp].loc, |
6453 | stack[sp].expr, true, true); | |
45a78cc0 | 6454 | stack[sp].expr.value = c_objc_common_truthvalue_conversion |
43158006 | 6455 | (stack[sp].loc, default_conversion (stack[sp].expr.value)); |
48d94ede | 6456 | c_inhibit_evaluation_warnings += (stack[sp].expr.value |
6457 | == truthvalue_true_node); | |
1576dec7 | 6458 | break; |
6459 | default: | |
6460 | break; | |
6461 | } | |
6462 | sp++; | |
43158006 | 6463 | stack[sp].loc = binary_loc; |
1576dec7 | 6464 | stack[sp].expr = c_parser_cast_expression (parser, NULL); |
6465 | stack[sp].prec = oprec; | |
6466 | stack[sp].op = ocode; | |
6467 | } | |
6468 | out: | |
6469 | while (sp > 0) | |
6470 | POP; | |
6471 | return stack[0].expr; | |
6472 | #undef POP | |
6473 | } | |
6474 | ||
6475 | /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not | |
6476 | NULL then it is an Objective-C message expression which is the | |
6477 | primary-expression starting the expression as an initializer. | |
6478 | ||
6479 | cast-expression: | |
6480 | unary-expression | |
6481 | ( type-name ) unary-expression | |
6482 | */ | |
6483 | ||
6484 | static struct c_expr | |
6485 | c_parser_cast_expression (c_parser *parser, struct c_expr *after) | |
6486 | { | |
e60a6f7b | 6487 | location_t cast_loc = c_parser_peek_token (parser)->location; |
1576dec7 | 6488 | gcc_assert (!after || c_dialect_objc ()); |
6489 | if (after) | |
e60a6f7b | 6490 | return c_parser_postfix_expression_after_primary (parser, |
6491 | cast_loc, *after); | |
1576dec7 | 6492 | /* If the expression begins with a parenthesized type name, it may |
6493 | be either a cast or a compound literal; we need to see whether | |
6494 | the next character is '{' to tell the difference. If not, it is | |
26ee9e7a | 6495 | an unary expression. Full detection of unknown typenames here |
6496 | would require a 3-token lookahead. */ | |
1576dec7 | 6497 | if (c_parser_next_token_is (parser, CPP_OPEN_PAREN) |
6498 | && c_token_starts_typename (c_parser_peek_2nd_token (parser))) | |
6499 | { | |
6500 | struct c_type_name *type_name; | |
6501 | struct c_expr ret; | |
e78cf9a7 | 6502 | struct c_expr expr; |
1576dec7 | 6503 | c_parser_consume_token (parser); |
6504 | type_name = c_parser_type_name (parser); | |
6505 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
6506 | if (type_name == NULL) | |
6507 | { | |
6508 | ret.value = error_mark_node; | |
6509 | ret.original_code = ERROR_MARK; | |
841fdaa6 | 6510 | ret.original_type = NULL; |
1576dec7 | 6511 | return ret; |
6512 | } | |
f6e59711 | 6513 | |
6514 | /* Save casted types in the function's used types hash table. */ | |
35df6eb4 | 6515 | used_types_insert (type_name->specs->type); |
f6e59711 | 6516 | |
1576dec7 | 6517 | if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) |
0b09525f | 6518 | return c_parser_postfix_expression_after_paren_type (parser, type_name, |
e60a6f7b | 6519 | cast_loc); |
6520 | { | |
6521 | location_t expr_loc = c_parser_peek_token (parser)->location; | |
6522 | expr = c_parser_cast_expression (parser, NULL); | |
b560fabd | 6523 | expr = convert_lvalue_to_rvalue (expr_loc, expr, true, true); |
e60a6f7b | 6524 | } |
6525 | ret.value = c_cast_expr (cast_loc, type_name, expr.value); | |
1576dec7 | 6526 | ret.original_code = ERROR_MARK; |
841fdaa6 | 6527 | ret.original_type = NULL; |
1576dec7 | 6528 | return ret; |
6529 | } | |
6530 | else | |
6531 | return c_parser_unary_expression (parser); | |
6532 | } | |
6533 | ||
6534 | /* Parse an unary expression (C90 6.3.3, C99 6.5.3). | |
6535 | ||
6536 | unary-expression: | |
6537 | postfix-expression | |
6538 | ++ unary-expression | |
6539 | -- unary-expression | |
6540 | unary-operator cast-expression | |
6541 | sizeof unary-expression | |
6542 | sizeof ( type-name ) | |
6543 | ||
6544 | unary-operator: one of | |
6545 | & * + - ~ ! | |
6546 | ||
6547 | GNU extensions: | |
6548 | ||
6549 | unary-expression: | |
6550 | __alignof__ unary-expression | |
6551 | __alignof__ ( type-name ) | |
6552 | && identifier | |
6553 | ||
32074525 | 6554 | (C11 permits _Alignof with type names only.) |
83e25171 | 6555 | |
1576dec7 | 6556 | unary-operator: one of |
6557 | __extension__ __real__ __imag__ | |
6558 | ||
4c0315d0 | 6559 | Transactional Memory: |
6560 | ||
6561 | unary-expression: | |
6562 | transaction-expression | |
6563 | ||
1576dec7 | 6564 | In addition, the GNU syntax treats ++ and -- as unary operators, so |
6565 | they may be applied to cast expressions with errors for non-lvalues | |
6566 | given later. */ | |
6567 | ||
6568 | static struct c_expr | |
6569 | c_parser_unary_expression (c_parser *parser) | |
6570 | { | |
6571 | int ext; | |
f14c8207 | 6572 | struct c_expr ret, op; |
e60a6f7b | 6573 | location_t op_loc = c_parser_peek_token (parser)->location; |
6574 | location_t exp_loc; | |
841fdaa6 | 6575 | ret.original_code = ERROR_MARK; |
6576 | ret.original_type = NULL; | |
1576dec7 | 6577 | switch (c_parser_peek_token (parser)->type) |
6578 | { | |
6579 | case CPP_PLUS_PLUS: | |
6580 | c_parser_consume_token (parser); | |
e60a6f7b | 6581 | exp_loc = c_parser_peek_token (parser)->location; |
f14c8207 | 6582 | op = c_parser_cast_expression (parser, NULL); |
3c6d4197 | 6583 | |
6584 | /* If there is array notations in op, we expand them. */ | |
a89e6c15 | 6585 | if (flag_cilkplus && TREE_CODE (op.value) == ARRAY_NOTATION_REF) |
3c6d4197 | 6586 | return fix_array_notation_expr (exp_loc, PREINCREMENT_EXPR, op); |
6587 | else | |
6588 | { | |
6589 | op = default_function_array_read_conversion (exp_loc, op); | |
6590 | return parser_build_unary_op (op_loc, PREINCREMENT_EXPR, op); | |
6591 | } | |
1576dec7 | 6592 | case CPP_MINUS_MINUS: |
6593 | c_parser_consume_token (parser); | |
e60a6f7b | 6594 | exp_loc = c_parser_peek_token (parser)->location; |
f14c8207 | 6595 | op = c_parser_cast_expression (parser, NULL); |
3c6d4197 | 6596 | |
6597 | /* If there is array notations in op, we expand them. */ | |
a89e6c15 | 6598 | if (flag_cilkplus && TREE_CODE (op.value) == ARRAY_NOTATION_REF) |
3c6d4197 | 6599 | return fix_array_notation_expr (exp_loc, PREDECREMENT_EXPR, op); |
6600 | else | |
6601 | { | |
6602 | op = default_function_array_read_conversion (exp_loc, op); | |
6603 | return parser_build_unary_op (op_loc, PREDECREMENT_EXPR, op); | |
6604 | } | |
1576dec7 | 6605 | case CPP_AND: |
6606 | c_parser_consume_token (parser); | |
abc6c64f | 6607 | op = c_parser_cast_expression (parser, NULL); |
6608 | mark_exp_read (op.value); | |
6609 | return parser_build_unary_op (op_loc, ADDR_EXPR, op); | |
1576dec7 | 6610 | case CPP_MULT: |
6611 | c_parser_consume_token (parser); | |
e60a6f7b | 6612 | exp_loc = c_parser_peek_token (parser)->location; |
f14c8207 | 6613 | op = c_parser_cast_expression (parser, NULL); |
b560fabd | 6614 | op = convert_lvalue_to_rvalue (exp_loc, op, true, true); |
f08923b3 | 6615 | ret.value = build_indirect_ref (op_loc, op.value, RO_UNARY_STAR); |
1576dec7 | 6616 | return ret; |
6617 | case CPP_PLUS: | |
3df42822 | 6618 | if (!c_dialect_objc () && !in_system_header_at (input_location)) |
e60a6f7b | 6619 | warning_at (op_loc, |
e3b80d49 | 6620 | OPT_Wtraditional, |
6621 | "traditional C rejects the unary plus operator"); | |
be9eba16 | 6622 | c_parser_consume_token (parser); |
e60a6f7b | 6623 | exp_loc = c_parser_peek_token (parser)->location; |
f14c8207 | 6624 | op = c_parser_cast_expression (parser, NULL); |
b560fabd | 6625 | op = convert_lvalue_to_rvalue (exp_loc, op, true, true); |
e60a6f7b | 6626 | return parser_build_unary_op (op_loc, CONVERT_EXPR, op); |
1576dec7 | 6627 | case CPP_MINUS: |
6628 | c_parser_consume_token (parser); | |
e60a6f7b | 6629 | exp_loc = c_parser_peek_token (parser)->location; |
f14c8207 | 6630 | op = c_parser_cast_expression (parser, NULL); |
b560fabd | 6631 | op = convert_lvalue_to_rvalue (exp_loc, op, true, true); |
e60a6f7b | 6632 | return parser_build_unary_op (op_loc, NEGATE_EXPR, op); |
1576dec7 | 6633 | case CPP_COMPL: |
6634 | c_parser_consume_token (parser); | |
e60a6f7b | 6635 | exp_loc = c_parser_peek_token (parser)->location; |
f14c8207 | 6636 | op = c_parser_cast_expression (parser, NULL); |
b560fabd | 6637 | op = convert_lvalue_to_rvalue (exp_loc, op, true, true); |
e60a6f7b | 6638 | return parser_build_unary_op (op_loc, BIT_NOT_EXPR, op); |
1576dec7 | 6639 | case CPP_NOT: |
6640 | c_parser_consume_token (parser); | |
e60a6f7b | 6641 | exp_loc = c_parser_peek_token (parser)->location; |
f14c8207 | 6642 | op = c_parser_cast_expression (parser, NULL); |
b560fabd | 6643 | op = convert_lvalue_to_rvalue (exp_loc, op, true, true); |
e60a6f7b | 6644 | return parser_build_unary_op (op_loc, TRUTH_NOT_EXPR, op); |
1576dec7 | 6645 | case CPP_AND_AND: |
6646 | /* Refer to the address of a label as a pointer. */ | |
6647 | c_parser_consume_token (parser); | |
6648 | if (c_parser_next_token_is (parser, CPP_NAME)) | |
6649 | { | |
6650 | ret.value = finish_label_address_expr | |
e60a6f7b | 6651 | (c_parser_peek_token (parser)->value, op_loc); |
1576dec7 | 6652 | c_parser_consume_token (parser); |
1576dec7 | 6653 | } |
6654 | else | |
6655 | { | |
6656 | c_parser_error (parser, "expected identifier"); | |
6657 | ret.value = error_mark_node; | |
1576dec7 | 6658 | } |
5381eb98 | 6659 | return ret; |
1576dec7 | 6660 | case CPP_KEYWORD: |
6661 | switch (c_parser_peek_token (parser)->keyword) | |
6662 | { | |
6663 | case RID_SIZEOF: | |
6664 | return c_parser_sizeof_expression (parser); | |
6665 | case RID_ALIGNOF: | |
6666 | return c_parser_alignof_expression (parser); | |
6667 | case RID_EXTENSION: | |
6668 | c_parser_consume_token (parser); | |
6669 | ext = disable_extension_diagnostics (); | |
6670 | ret = c_parser_cast_expression (parser, NULL); | |
6671 | restore_extension_diagnostics (ext); | |
6672 | return ret; | |
6673 | case RID_REALPART: | |
6674 | c_parser_consume_token (parser); | |
e60a6f7b | 6675 | exp_loc = c_parser_peek_token (parser)->location; |
f14c8207 | 6676 | op = c_parser_cast_expression (parser, NULL); |
e60a6f7b | 6677 | op = default_function_array_conversion (exp_loc, op); |
6678 | return parser_build_unary_op (op_loc, REALPART_EXPR, op); | |
1576dec7 | 6679 | case RID_IMAGPART: |
6680 | c_parser_consume_token (parser); | |
e60a6f7b | 6681 | exp_loc = c_parser_peek_token (parser)->location; |
f14c8207 | 6682 | op = c_parser_cast_expression (parser, NULL); |
e60a6f7b | 6683 | op = default_function_array_conversion (exp_loc, op); |
6684 | return parser_build_unary_op (op_loc, IMAGPART_EXPR, op); | |
4c0315d0 | 6685 | case RID_TRANSACTION_ATOMIC: |
6686 | case RID_TRANSACTION_RELAXED: | |
6687 | return c_parser_transaction_expression (parser, | |
6688 | c_parser_peek_token (parser)->keyword); | |
1576dec7 | 6689 | default: |
6690 | return c_parser_postfix_expression (parser); | |
6691 | } | |
6692 | default: | |
6693 | return c_parser_postfix_expression (parser); | |
6694 | } | |
6695 | } | |
6696 | ||
6697 | /* Parse a sizeof expression. */ | |
6698 | ||
6699 | static struct c_expr | |
6700 | c_parser_sizeof_expression (c_parser *parser) | |
6701 | { | |
6702 | struct c_expr expr; | |
be9eba16 | 6703 | location_t expr_loc; |
1576dec7 | 6704 | gcc_assert (c_parser_next_token_is_keyword (parser, RID_SIZEOF)); |
6705 | c_parser_consume_token (parser); | |
48d94ede | 6706 | c_inhibit_evaluation_warnings++; |
1576dec7 | 6707 | in_sizeof++; |
6708 | if (c_parser_next_token_is (parser, CPP_OPEN_PAREN) | |
6709 | && c_token_starts_typename (c_parser_peek_2nd_token (parser))) | |
6710 | { | |
6711 | /* Either sizeof ( type-name ) or sizeof unary-expression | |
6712 | starting with a compound literal. */ | |
6713 | struct c_type_name *type_name; | |
6714 | c_parser_consume_token (parser); | |
be9eba16 | 6715 | expr_loc = c_parser_peek_token (parser)->location; |
1576dec7 | 6716 | type_name = c_parser_type_name (parser); |
6717 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
6718 | if (type_name == NULL) | |
6719 | { | |
6720 | struct c_expr ret; | |
48d94ede | 6721 | c_inhibit_evaluation_warnings--; |
1576dec7 | 6722 | in_sizeof--; |
6723 | ret.value = error_mark_node; | |
6724 | ret.original_code = ERROR_MARK; | |
841fdaa6 | 6725 | ret.original_type = NULL; |
1576dec7 | 6726 | return ret; |
6727 | } | |
6728 | if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) | |
6729 | { | |
d44f2f7c | 6730 | expr = c_parser_postfix_expression_after_paren_type (parser, |
6731 | type_name, | |
6732 | expr_loc); | |
6733 | goto sizeof_expr; | |
1576dec7 | 6734 | } |
d44f2f7c | 6735 | /* sizeof ( type-name ). */ |
6736 | c_inhibit_evaluation_warnings--; | |
6737 | in_sizeof--; | |
6738 | return c_expr_sizeof_type (expr_loc, type_name); | |
1576dec7 | 6739 | } |
6740 | else | |
6741 | { | |
be9eba16 | 6742 | expr_loc = c_parser_peek_token (parser)->location; |
1576dec7 | 6743 | expr = c_parser_unary_expression (parser); |
d44f2f7c | 6744 | sizeof_expr: |
6745 | c_inhibit_evaluation_warnings--; | |
6746 | in_sizeof--; | |
6747 | mark_exp_read (expr.value); | |
6748 | if (TREE_CODE (expr.value) == COMPONENT_REF | |
6749 | && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1))) | |
6750 | error_at (expr_loc, "%<sizeof%> applied to a bit-field"); | |
6751 | return c_expr_sizeof_expr (expr_loc, expr); | |
1576dec7 | 6752 | } |
6753 | } | |
6754 | ||
6755 | /* Parse an alignof expression. */ | |
6756 | ||
6757 | static struct c_expr | |
6758 | c_parser_alignof_expression (c_parser *parser) | |
6759 | { | |
6760 | struct c_expr expr; | |
e60a6f7b | 6761 | location_t loc = c_parser_peek_token (parser)->location; |
83e25171 | 6762 | tree alignof_spelling = c_parser_peek_token (parser)->value; |
1576dec7 | 6763 | gcc_assert (c_parser_next_token_is_keyword (parser, RID_ALIGNOF)); |
a179a7dc | 6764 | bool is_c11_alignof = strcmp (IDENTIFIER_POINTER (alignof_spelling), |
6765 | "_Alignof") == 0; | |
83e25171 | 6766 | /* A diagnostic is not required for the use of this identifier in |
32074525 | 6767 | the implementation namespace; only diagnose it for the C11 |
83e25171 | 6768 | spelling because of existing code using the other spellings. */ |
508ea33a | 6769 | if (is_c11_alignof) |
83e25171 | 6770 | { |
6771 | if (flag_isoc99) | |
508ea33a | 6772 | pedwarn_c99 (loc, OPT_Wpedantic, "ISO C99 does not support %qE", |
6773 | alignof_spelling); | |
83e25171 | 6774 | else |
508ea33a | 6775 | pedwarn_c99 (loc, OPT_Wpedantic, "ISO C90 does not support %qE", |
6776 | alignof_spelling); | |
83e25171 | 6777 | } |
1576dec7 | 6778 | c_parser_consume_token (parser); |
48d94ede | 6779 | c_inhibit_evaluation_warnings++; |
1576dec7 | 6780 | in_alignof++; |
6781 | if (c_parser_next_token_is (parser, CPP_OPEN_PAREN) | |
6782 | && c_token_starts_typename (c_parser_peek_2nd_token (parser))) | |
6783 | { | |
6784 | /* Either __alignof__ ( type-name ) or __alignof__ | |
6785 | unary-expression starting with a compound literal. */ | |
0b09525f | 6786 | location_t loc; |
1576dec7 | 6787 | struct c_type_name *type_name; |
6788 | struct c_expr ret; | |
6789 | c_parser_consume_token (parser); | |
0b09525f | 6790 | loc = c_parser_peek_token (parser)->location; |
1576dec7 | 6791 | type_name = c_parser_type_name (parser); |
6792 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
6793 | if (type_name == NULL) | |
6794 | { | |
6795 | struct c_expr ret; | |
48d94ede | 6796 | c_inhibit_evaluation_warnings--; |
1576dec7 | 6797 | in_alignof--; |
6798 | ret.value = error_mark_node; | |
6799 | ret.original_code = ERROR_MARK; | |
841fdaa6 | 6800 | ret.original_type = NULL; |
1576dec7 | 6801 | return ret; |
6802 | } | |
6803 | if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) | |
6804 | { | |
6805 | expr = c_parser_postfix_expression_after_paren_type (parser, | |
0b09525f | 6806 | type_name, |
6807 | loc); | |
1576dec7 | 6808 | goto alignof_expr; |
6809 | } | |
6810 | /* alignof ( type-name ). */ | |
48d94ede | 6811 | c_inhibit_evaluation_warnings--; |
1576dec7 | 6812 | in_alignof--; |
a179a7dc | 6813 | ret.value = c_sizeof_or_alignof_type (loc, groktypename (type_name, |
6814 | NULL, NULL), | |
6815 | false, is_c11_alignof, 1); | |
1576dec7 | 6816 | ret.original_code = ERROR_MARK; |
841fdaa6 | 6817 | ret.original_type = NULL; |
1576dec7 | 6818 | return ret; |
6819 | } | |
6820 | else | |
6821 | { | |
6822 | struct c_expr ret; | |
6823 | expr = c_parser_unary_expression (parser); | |
6824 | alignof_expr: | |
abc6c64f | 6825 | mark_exp_read (expr.value); |
48d94ede | 6826 | c_inhibit_evaluation_warnings--; |
1576dec7 | 6827 | in_alignof--; |
29438999 | 6828 | pedwarn (loc, OPT_Wpedantic, "ISO C does not allow %<%E (expression)%>", |
83e25171 | 6829 | alignof_spelling); |
e60a6f7b | 6830 | ret.value = c_alignof_expr (loc, expr.value); |
1576dec7 | 6831 | ret.original_code = ERROR_MARK; |
841fdaa6 | 6832 | ret.original_type = NULL; |
1576dec7 | 6833 | return ret; |
6834 | } | |
6835 | } | |
6836 | ||
6cf89e04 | 6837 | /* Helper function to read arguments of builtins which are interfaces |
f4803722 | 6838 | for the middle-end nodes like COMPLEX_EXPR, VEC_PERM_EXPR and |
6cf89e04 | 6839 | others. The name of the builtin is passed using BNAME parameter. |
6840 | Function returns true if there were no errors while parsing and | |
a11dda8e | 6841 | stores the arguments in CEXPR_LIST. */ |
6cf89e04 | 6842 | static bool |
6843 | c_parser_get_builtin_args (c_parser *parser, const char *bname, | |
0b049e15 | 6844 | vec<c_expr_t, va_gc> **ret_cexpr_list, |
6845 | bool choose_expr_p) | |
6cf89e04 | 6846 | { |
6847 | location_t loc = c_parser_peek_token (parser)->location; | |
f1f41a6c | 6848 | vec<c_expr_t, va_gc> *cexpr_list; |
a11dda8e | 6849 | c_expr_t expr; |
0b049e15 | 6850 | bool saved_force_folding_builtin_constant_p; |
6cf89e04 | 6851 | |
a11dda8e | 6852 | *ret_cexpr_list = NULL; |
6cf89e04 | 6853 | if (c_parser_next_token_is_not (parser, CPP_OPEN_PAREN)) |
6854 | { | |
6855 | error_at (loc, "cannot take address of %qs", bname); | |
6856 | return false; | |
6857 | } | |
6858 | ||
6859 | c_parser_consume_token (parser); | |
6860 | ||
6861 | if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) | |
6862 | { | |
6863 | c_parser_consume_token (parser); | |
6864 | return true; | |
6865 | } | |
a11dda8e | 6866 | |
0b049e15 | 6867 | saved_force_folding_builtin_constant_p |
6868 | = force_folding_builtin_constant_p; | |
6869 | force_folding_builtin_constant_p |= choose_expr_p; | |
a11dda8e | 6870 | expr = c_parser_expr_no_commas (parser, NULL); |
0b049e15 | 6871 | force_folding_builtin_constant_p |
6872 | = saved_force_folding_builtin_constant_p; | |
f1f41a6c | 6873 | vec_alloc (cexpr_list, 1); |
825cd6ef | 6874 | vec_safe_push (cexpr_list, expr); |
a11dda8e | 6875 | while (c_parser_next_token_is (parser, CPP_COMMA)) |
6876 | { | |
6877 | c_parser_consume_token (parser); | |
6878 | expr = c_parser_expr_no_commas (parser, NULL); | |
825cd6ef | 6879 | vec_safe_push (cexpr_list, expr); |
a11dda8e | 6880 | } |
6cf89e04 | 6881 | |
6882 | if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>")) | |
6883 | return false; | |
6884 | ||
a11dda8e | 6885 | *ret_cexpr_list = cexpr_list; |
6cf89e04 | 6886 | return true; |
6887 | } | |
6888 | ||
7aa04c8d | 6889 | /* This represents a single generic-association. */ |
6890 | ||
6891 | struct c_generic_association | |
6892 | { | |
6893 | /* The location of the starting token of the type. */ | |
6894 | location_t type_location; | |
e76163a9 | 6895 | /* The association's type, or NULL_TREE for 'default'. */ |
7aa04c8d | 6896 | tree type; |
6897 | /* The association's expression. */ | |
6898 | struct c_expr expression; | |
6899 | }; | |
6900 | ||
6901 | /* Parse a generic-selection. (C11 6.5.1.1). | |
6902 | ||
6903 | generic-selection: | |
6904 | _Generic ( assignment-expression , generic-assoc-list ) | |
6905 | ||
6906 | generic-assoc-list: | |
6907 | generic-association | |
6908 | generic-assoc-list , generic-association | |
6909 | ||
6910 | generic-association: | |
6911 | type-name : assignment-expression | |
6912 | default : assignment-expression | |
6913 | */ | |
6914 | ||
6915 | static struct c_expr | |
6916 | c_parser_generic_selection (c_parser *parser) | |
6917 | { | |
6918 | vec<c_generic_association> associations = vNULL; | |
6919 | struct c_expr selector, error_expr; | |
6920 | tree selector_type; | |
6921 | struct c_generic_association matched_assoc; | |
6922 | bool match_found = false; | |
6923 | location_t generic_loc, selector_loc; | |
6924 | ||
6925 | error_expr.original_code = ERROR_MARK; | |
6926 | error_expr.original_type = NULL; | |
6927 | error_expr.value = error_mark_node; | |
6928 | matched_assoc.type_location = UNKNOWN_LOCATION; | |
6929 | matched_assoc.type = NULL_TREE; | |
6930 | matched_assoc.expression = error_expr; | |
6931 | ||
6932 | gcc_assert (c_parser_next_token_is_keyword (parser, RID_GENERIC)); | |
6933 | generic_loc = c_parser_peek_token (parser)->location; | |
6934 | c_parser_consume_token (parser); | |
508ea33a | 6935 | if (flag_isoc99) |
6936 | pedwarn_c99 (generic_loc, OPT_Wpedantic, | |
7aa04c8d | 6937 | "ISO C99 does not support %<_Generic%>"); |
508ea33a | 6938 | else |
6939 | pedwarn_c99 (generic_loc, OPT_Wpedantic, | |
7aa04c8d | 6940 | "ISO C90 does not support %<_Generic%>"); |
7aa04c8d | 6941 | |
6942 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
6943 | return error_expr; | |
6944 | ||
6945 | c_inhibit_evaluation_warnings++; | |
6946 | selector_loc = c_parser_peek_token (parser)->location; | |
6947 | selector = c_parser_expr_no_commas (parser, NULL); | |
6948 | selector = default_function_array_conversion (selector_loc, selector); | |
6949 | c_inhibit_evaluation_warnings--; | |
6950 | ||
6951 | if (selector.value == error_mark_node) | |
6952 | { | |
6953 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); | |
6954 | return selector; | |
6955 | } | |
6956 | selector_type = TREE_TYPE (selector.value); | |
6957 | /* In ISO C terms, rvalues (including the controlling expression of | |
6958 | _Generic) do not have qualified types. */ | |
6959 | if (TREE_CODE (selector_type) != ARRAY_TYPE) | |
6960 | selector_type = TYPE_MAIN_VARIANT (selector_type); | |
6961 | /* In ISO C terms, _Noreturn is not part of the type of expressions | |
6962 | such as &abort, but in GCC it is represented internally as a type | |
6963 | qualifier. */ | |
6964 | if (FUNCTION_POINTER_TYPE_P (selector_type) | |
6965 | && TYPE_QUALS (TREE_TYPE (selector_type)) != TYPE_UNQUALIFIED) | |
6966 | selector_type | |
6967 | = build_pointer_type (TYPE_MAIN_VARIANT (TREE_TYPE (selector_type))); | |
6968 | ||
6969 | if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>")) | |
6970 | { | |
6971 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); | |
6972 | return error_expr; | |
6973 | } | |
6974 | ||
6975 | while (1) | |
6976 | { | |
6977 | struct c_generic_association assoc, *iter; | |
6978 | unsigned int ix; | |
6979 | c_token *token = c_parser_peek_token (parser); | |
6980 | ||
6981 | assoc.type_location = token->location; | |
6982 | if (token->type == CPP_KEYWORD && token->keyword == RID_DEFAULT) | |
6983 | { | |
6984 | c_parser_consume_token (parser); | |
6985 | assoc.type = NULL_TREE; | |
6986 | } | |
6987 | else | |
6988 | { | |
6989 | struct c_type_name *type_name; | |
6990 | ||
6991 | type_name = c_parser_type_name (parser); | |
6992 | if (type_name == NULL) | |
6993 | { | |
6994 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); | |
6995 | goto error_exit; | |
6996 | } | |
6997 | assoc.type = groktypename (type_name, NULL, NULL); | |
6998 | if (assoc.type == error_mark_node) | |
6999 | { | |
7000 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); | |
7001 | goto error_exit; | |
7002 | } | |
7003 | ||
7004 | if (TREE_CODE (assoc.type) == FUNCTION_TYPE) | |
7005 | error_at (assoc.type_location, | |
7006 | "%<_Generic%> association has function type"); | |
7007 | else if (!COMPLETE_TYPE_P (assoc.type)) | |
7008 | error_at (assoc.type_location, | |
7009 | "%<_Generic%> association has incomplete type"); | |
7010 | ||
7011 | if (variably_modified_type_p (assoc.type, NULL_TREE)) | |
7012 | error_at (assoc.type_location, | |
7013 | "%<_Generic%> association has " | |
7014 | "variable length type"); | |
7015 | } | |
7016 | ||
7017 | if (!c_parser_require (parser, CPP_COLON, "expected %<:%>")) | |
7018 | { | |
7019 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); | |
7020 | goto error_exit; | |
7021 | } | |
7022 | ||
7023 | assoc.expression = c_parser_expr_no_commas (parser, NULL); | |
7024 | if (assoc.expression.value == error_mark_node) | |
7025 | { | |
7026 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); | |
7027 | goto error_exit; | |
7028 | } | |
7029 | ||
7030 | for (ix = 0; associations.iterate (ix, &iter); ++ix) | |
7031 | { | |
7032 | if (assoc.type == NULL_TREE) | |
7033 | { | |
7034 | if (iter->type == NULL_TREE) | |
7035 | { | |
7036 | error_at (assoc.type_location, | |
7037 | "duplicate %<default%> case in %<_Generic%>"); | |
7038 | inform (iter->type_location, "original %<default%> is here"); | |
7039 | } | |
7040 | } | |
7041 | else if (iter->type != NULL_TREE) | |
7042 | { | |
7043 | if (comptypes (assoc.type, iter->type)) | |
7044 | { | |
7045 | error_at (assoc.type_location, | |
7046 | "%<_Generic%> specifies two compatible types"); | |
7047 | inform (iter->type_location, "compatible type is here"); | |
7048 | } | |
7049 | } | |
7050 | } | |
7051 | ||
7052 | if (assoc.type == NULL_TREE) | |
7053 | { | |
7054 | if (!match_found) | |
7055 | { | |
7056 | matched_assoc = assoc; | |
7057 | match_found = true; | |
7058 | } | |
7059 | } | |
7060 | else if (comptypes (assoc.type, selector_type)) | |
7061 | { | |
7062 | if (!match_found || matched_assoc.type == NULL_TREE) | |
7063 | { | |
7064 | matched_assoc = assoc; | |
7065 | match_found = true; | |
7066 | } | |
7067 | else | |
7068 | { | |
7069 | error_at (assoc.type_location, | |
7070 | "%<_Generic> selector matches multiple associations"); | |
7071 | inform (matched_assoc.type_location, | |
7072 | "other match is here"); | |
7073 | } | |
7074 | } | |
7075 | ||
7076 | associations.safe_push (assoc); | |
7077 | ||
7078 | if (c_parser_peek_token (parser)->type != CPP_COMMA) | |
7079 | break; | |
7080 | c_parser_consume_token (parser); | |
7081 | } | |
7082 | ||
7083 | associations.release (); | |
7084 | ||
7085 | if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>")) | |
7086 | { | |
7087 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); | |
7088 | return error_expr; | |
7089 | } | |
7090 | ||
7091 | if (!match_found) | |
7092 | { | |
7093 | error_at (selector_loc, "%<_Generic%> selector of type %qT is not " | |
7094 | "compatible with any association", | |
7095 | selector_type); | |
7096 | return error_expr; | |
7097 | } | |
7098 | ||
7099 | return matched_assoc.expression; | |
7100 | ||
7101 | error_exit: | |
7102 | associations.release (); | |
7103 | return error_expr; | |
7104 | } | |
6cf89e04 | 7105 | |
1576dec7 | 7106 | /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2). |
7107 | ||
7108 | postfix-expression: | |
7109 | primary-expression | |
7110 | postfix-expression [ expression ] | |
7111 | postfix-expression ( argument-expression-list[opt] ) | |
7112 | postfix-expression . identifier | |
7113 | postfix-expression -> identifier | |
7114 | postfix-expression ++ | |
7115 | postfix-expression -- | |
7116 | ( type-name ) { initializer-list } | |
7117 | ( type-name ) { initializer-list , } | |
7118 | ||
7119 | argument-expression-list: | |
7120 | argument-expression | |
7121 | argument-expression-list , argument-expression | |
7122 | ||
7123 | primary-expression: | |
7124 | identifier | |
7125 | constant | |
7126 | string-literal | |
7127 | ( expression ) | |
7aa04c8d | 7128 | generic-selection |
1576dec7 | 7129 | |
7130 | GNU extensions: | |
7131 | ||
7132 | primary-expression: | |
7133 | __func__ | |
7134 | (treated as a keyword in GNU C) | |
7135 | __FUNCTION__ | |
7136 | __PRETTY_FUNCTION__ | |
7137 | ( compound-statement ) | |
7138 | __builtin_va_arg ( assignment-expression , type-name ) | |
7139 | __builtin_offsetof ( type-name , offsetof-member-designator ) | |
7140 | __builtin_choose_expr ( assignment-expression , | |
7141 | assignment-expression , | |
7142 | assignment-expression ) | |
7143 | __builtin_types_compatible_p ( type-name , type-name ) | |
bff4ad11 | 7144 | __builtin_complex ( assignment-expression , assignment-expression ) |
6cf89e04 | 7145 | __builtin_shuffle ( assignment-expression , assignment-expression ) |
7146 | __builtin_shuffle ( assignment-expression , | |
7147 | assignment-expression , | |
7148 | assignment-expression, ) | |
1576dec7 | 7149 | |
7150 | offsetof-member-designator: | |
7151 | identifier | |
7152 | offsetof-member-designator . identifier | |
7153 | offsetof-member-designator [ expression ] | |
7154 | ||
7155 | Objective-C: | |
7156 | ||
7157 | primary-expression: | |
7158 | [ objc-receiver objc-message-args ] | |
7159 | @selector ( objc-selector-arg ) | |
7160 | @protocol ( identifier ) | |
7161 | @encode ( type-name ) | |
7162 | objc-string-literal | |
b0d0931f | 7163 | Classname . identifier |
1576dec7 | 7164 | */ |
7165 | ||
7166 | static struct c_expr | |
7167 | c_parser_postfix_expression (c_parser *parser) | |
7168 | { | |
6cf89e04 | 7169 | struct c_expr expr, e1; |
1576dec7 | 7170 | struct c_type_name *t1, *t2; |
e60a6f7b | 7171 | location_t loc = c_parser_peek_token (parser)->location;; |
841fdaa6 | 7172 | expr.original_code = ERROR_MARK; |
7173 | expr.original_type = NULL; | |
1576dec7 | 7174 | switch (c_parser_peek_token (parser)->type) |
7175 | { | |
7176 | case CPP_NUMBER: | |
14e882ea | 7177 | expr.value = c_parser_peek_token (parser)->value; |
14e882ea | 7178 | loc = c_parser_peek_token (parser)->location; |
7179 | c_parser_consume_token (parser); | |
7180 | if (TREE_CODE (expr.value) == FIXED_CST | |
7181 | && !targetm.fixed_point_supported_p ()) | |
7182 | { | |
7183 | error_at (loc, "fixed-point types not supported for this target"); | |
7184 | expr.value = error_mark_node; | |
7185 | } | |
7186 | break; | |
1576dec7 | 7187 | case CPP_CHAR: |
924bbf02 | 7188 | case CPP_CHAR16: |
7189 | case CPP_CHAR32: | |
1576dec7 | 7190 | case CPP_WCHAR: |
7191 | expr.value = c_parser_peek_token (parser)->value; | |
1576dec7 | 7192 | c_parser_consume_token (parser); |
7193 | break; | |
7194 | case CPP_STRING: | |
924bbf02 | 7195 | case CPP_STRING16: |
7196 | case CPP_STRING32: | |
1576dec7 | 7197 | case CPP_WSTRING: |
538ba11a | 7198 | case CPP_UTF8STRING: |
1576dec7 | 7199 | expr.value = c_parser_peek_token (parser)->value; |
7200 | expr.original_code = STRING_CST; | |
7201 | c_parser_consume_token (parser); | |
7202 | break; | |
7203 | case CPP_OBJC_STRING: | |
7204 | gcc_assert (c_dialect_objc ()); | |
7205 | expr.value | |
7206 | = objc_build_string_object (c_parser_peek_token (parser)->value); | |
1576dec7 | 7207 | c_parser_consume_token (parser); |
7208 | break; | |
7209 | case CPP_NAME: | |
b0d0931f | 7210 | switch (c_parser_peek_token (parser)->id_kind) |
1576dec7 | 7211 | { |
b0d0931f | 7212 | case C_ID_ID: |
7213 | { | |
7214 | tree id = c_parser_peek_token (parser)->value; | |
7215 | c_parser_consume_token (parser); | |
7216 | expr.value = build_external_ref (loc, id, | |
7217 | (c_parser_peek_token (parser)->type | |
7218 | == CPP_OPEN_PAREN), | |
7219 | &expr.original_type); | |
7220 | break; | |
7221 | } | |
7222 | case C_ID_CLASSNAME: | |
7223 | { | |
7224 | /* Here we parse the Objective-C 2.0 Class.name dot | |
7225 | syntax. */ | |
7226 | tree class_name = c_parser_peek_token (parser)->value; | |
7227 | tree component; | |
7228 | c_parser_consume_token (parser); | |
7229 | gcc_assert (c_dialect_objc ()); | |
7230 | if (!c_parser_require (parser, CPP_DOT, "expected %<.%>")) | |
7231 | { | |
7232 | expr.value = error_mark_node; | |
7233 | break; | |
7234 | } | |
7235 | if (c_parser_next_token_is_not (parser, CPP_NAME)) | |
7236 | { | |
7237 | c_parser_error (parser, "expected identifier"); | |
7238 | expr.value = error_mark_node; | |
7239 | break; | |
7240 | } | |
7241 | component = c_parser_peek_token (parser)->value; | |
7242 | c_parser_consume_token (parser); | |
7243 | expr.value = objc_build_class_component_ref (class_name, | |
7244 | component); | |
7245 | break; | |
7246 | } | |
7247 | default: | |
1576dec7 | 7248 | c_parser_error (parser, "expected expression"); |
7249 | expr.value = error_mark_node; | |
1576dec7 | 7250 | break; |
7251 | } | |
1576dec7 | 7252 | break; |
7253 | case CPP_OPEN_PAREN: | |
7254 | /* A parenthesized expression, statement expression or compound | |
7255 | literal. */ | |
7256 | if (c_parser_peek_2nd_token (parser)->type == CPP_OPEN_BRACE) | |
7257 | { | |
7258 | /* A statement expression. */ | |
7259 | tree stmt; | |
e60a6f7b | 7260 | location_t brace_loc; |
1576dec7 | 7261 | c_parser_consume_token (parser); |
e60a6f7b | 7262 | brace_loc = c_parser_peek_token (parser)->location; |
1576dec7 | 7263 | c_parser_consume_token (parser); |
cacfdc02 | 7264 | if (!building_stmt_list_p ()) |
1576dec7 | 7265 | { |
e60a6f7b | 7266 | error_at (loc, "braced-group within expression allowed " |
e3b80d49 | 7267 | "only inside a function"); |
1576dec7 | 7268 | parser->error = true; |
7269 | c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL); | |
7270 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); | |
7271 | expr.value = error_mark_node; | |
1576dec7 | 7272 | break; |
7273 | } | |
7274 | stmt = c_begin_stmt_expr (); | |
7275 | c_parser_compound_statement_nostart (parser); | |
7276 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, | |
7277 | "expected %<)%>"); | |
29438999 | 7278 | pedwarn (loc, OPT_Wpedantic, |
21ca8540 | 7279 | "ISO C forbids braced-groups within expressions"); |
e60a6f7b | 7280 | expr.value = c_finish_stmt_expr (brace_loc, stmt); |
062966c1 | 7281 | mark_exp_read (expr.value); |
1576dec7 | 7282 | } |
7283 | else if (c_token_starts_typename (c_parser_peek_2nd_token (parser))) | |
7284 | { | |
7285 | /* A compound literal. ??? Can we actually get here rather | |
7286 | than going directly to | |
7287 | c_parser_postfix_expression_after_paren_type from | |
7288 | elsewhere? */ | |
0b09525f | 7289 | location_t loc; |
1576dec7 | 7290 | struct c_type_name *type_name; |
7291 | c_parser_consume_token (parser); | |
0b09525f | 7292 | loc = c_parser_peek_token (parser)->location; |
1576dec7 | 7293 | type_name = c_parser_type_name (parser); |
7294 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, | |
7295 | "expected %<)%>"); | |
7296 | if (type_name == NULL) | |
7297 | { | |
7298 | expr.value = error_mark_node; | |
1576dec7 | 7299 | } |
7300 | else | |
7301 | expr = c_parser_postfix_expression_after_paren_type (parser, | |
0b09525f | 7302 | type_name, |
7303 | loc); | |
1576dec7 | 7304 | } |
7305 | else | |
7306 | { | |
7307 | /* A parenthesized expression. */ | |
7308 | c_parser_consume_token (parser); | |
7309 | expr = c_parser_expression (parser); | |
7310 | if (TREE_CODE (expr.value) == MODIFY_EXPR) | |
7311 | TREE_NO_WARNING (expr.value) = 1; | |
a75b1c71 | 7312 | if (expr.original_code != C_MAYBE_CONST_EXPR) |
7313 | expr.original_code = ERROR_MARK; | |
841fdaa6 | 7314 | /* Don't change EXPR.ORIGINAL_TYPE. */ |
1576dec7 | 7315 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, |
7316 | "expected %<)%>"); | |
7317 | } | |
7318 | break; | |
7319 | case CPP_KEYWORD: | |
7320 | switch (c_parser_peek_token (parser)->keyword) | |
7321 | { | |
7322 | case RID_FUNCTION_NAME: | |
89868e45 | 7323 | pedwarn (loc, OPT_Wpedantic, "ISO C does not support " |
7324 | "%<__FUNCTION__%> predefined identifier"); | |
7325 | expr.value = fname_decl (loc, | |
7326 | c_parser_peek_token (parser)->keyword, | |
7327 | c_parser_peek_token (parser)->value); | |
7328 | c_parser_consume_token (parser); | |
7329 | break; | |
1576dec7 | 7330 | case RID_PRETTY_FUNCTION_NAME: |
89868e45 | 7331 | pedwarn (loc, OPT_Wpedantic, "ISO C does not support " |
7332 | "%<__PRETTY_FUNCTION__%> predefined identifier"); | |
7333 | expr.value = fname_decl (loc, | |
7334 | c_parser_peek_token (parser)->keyword, | |
7335 | c_parser_peek_token (parser)->value); | |
7336 | c_parser_consume_token (parser); | |
7337 | break; | |
1576dec7 | 7338 | case RID_C99_FUNCTION_NAME: |
89868e45 | 7339 | pedwarn_c90 (loc, OPT_Wpedantic, "ISO C90 does not support " |
7340 | "%<__func__%> predefined identifier"); | |
e60a6f7b | 7341 | expr.value = fname_decl (loc, |
e3b80d49 | 7342 | c_parser_peek_token (parser)->keyword, |
1576dec7 | 7343 | c_parser_peek_token (parser)->value); |
1576dec7 | 7344 | c_parser_consume_token (parser); |
7345 | break; | |
7346 | case RID_VA_ARG: | |
7347 | c_parser_consume_token (parser); | |
7348 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
7349 | { | |
7350 | expr.value = error_mark_node; | |
1576dec7 | 7351 | break; |
7352 | } | |
7353 | e1 = c_parser_expr_no_commas (parser, NULL); | |
abc6c64f | 7354 | mark_exp_read (e1.value); |
a75b1c71 | 7355 | e1.value = c_fully_fold (e1.value, false, NULL); |
1576dec7 | 7356 | if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>")) |
7357 | { | |
7358 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); | |
7359 | expr.value = error_mark_node; | |
1576dec7 | 7360 | break; |
7361 | } | |
d62e827b | 7362 | loc = c_parser_peek_token (parser)->location; |
1576dec7 | 7363 | t1 = c_parser_type_name (parser); |
7364 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, | |
7365 | "expected %<)%>"); | |
7366 | if (t1 == NULL) | |
7367 | { | |
7368 | expr.value = error_mark_node; | |
1576dec7 | 7369 | } |
7370 | else | |
7371 | { | |
a75b1c71 | 7372 | tree type_expr = NULL_TREE; |
e60a6f7b | 7373 | expr.value = c_build_va_arg (loc, e1.value, |
7374 | groktypename (t1, &type_expr, NULL)); | |
a75b1c71 | 7375 | if (type_expr) |
7376 | { | |
7377 | expr.value = build2 (C_MAYBE_CONST_EXPR, | |
7378 | TREE_TYPE (expr.value), type_expr, | |
7379 | expr.value); | |
7380 | C_MAYBE_CONST_EXPR_NON_CONST (expr.value) = true; | |
7381 | } | |
1576dec7 | 7382 | } |
7383 | break; | |
7384 | case RID_OFFSETOF: | |
7385 | c_parser_consume_token (parser); | |
7386 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
7387 | { | |
7388 | expr.value = error_mark_node; | |
1576dec7 | 7389 | break; |
7390 | } | |
7391 | t1 = c_parser_type_name (parser); | |
7392 | if (t1 == NULL) | |
26ee9e7a | 7393 | parser->error = true; |
1576dec7 | 7394 | if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>")) |
26ee9e7a | 7395 | gcc_assert (parser->error); |
7396 | if (parser->error) | |
1576dec7 | 7397 | { |
7398 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); | |
7399 | expr.value = error_mark_node; | |
1576dec7 | 7400 | break; |
7401 | } | |
26ee9e7a | 7402 | |
1576dec7 | 7403 | { |
a75b1c71 | 7404 | tree type = groktypename (t1, NULL, NULL); |
1576dec7 | 7405 | tree offsetof_ref; |
7406 | if (type == error_mark_node) | |
7407 | offsetof_ref = error_mark_node; | |
7408 | else | |
e60a6f7b | 7409 | { |
7410 | offsetof_ref = build1 (INDIRECT_REF, type, null_pointer_node); | |
7411 | SET_EXPR_LOCATION (offsetof_ref, loc); | |
7412 | } | |
1576dec7 | 7413 | /* Parse the second argument to __builtin_offsetof. We |
7414 | must have one identifier, and beyond that we want to | |
7415 | accept sub structure and sub array references. */ | |
7416 | if (c_parser_next_token_is (parser, CPP_NAME)) | |
7417 | { | |
7418 | offsetof_ref = build_component_ref | |
e60a6f7b | 7419 | (loc, offsetof_ref, c_parser_peek_token (parser)->value); |
1576dec7 | 7420 | c_parser_consume_token (parser); |
7421 | while (c_parser_next_token_is (parser, CPP_DOT) | |
7422 | || c_parser_next_token_is (parser, | |
f0d0d842 | 7423 | CPP_OPEN_SQUARE) |
7424 | || c_parser_next_token_is (parser, | |
7425 | CPP_DEREF)) | |
1576dec7 | 7426 | { |
f0d0d842 | 7427 | if (c_parser_next_token_is (parser, CPP_DEREF)) |
7428 | { | |
7429 | loc = c_parser_peek_token (parser)->location; | |
e60a6f7b | 7430 | offsetof_ref = build_array_ref (loc, |
7431 | offsetof_ref, | |
7432 | integer_zero_node); | |
f0d0d842 | 7433 | goto do_dot; |
7434 | } | |
7435 | else if (c_parser_next_token_is (parser, CPP_DOT)) | |
1576dec7 | 7436 | { |
f0d0d842 | 7437 | do_dot: |
1576dec7 | 7438 | c_parser_consume_token (parser); |
7439 | if (c_parser_next_token_is_not (parser, | |
7440 | CPP_NAME)) | |
7441 | { | |
7442 | c_parser_error (parser, "expected identifier"); | |
7443 | break; | |
7444 | } | |
7445 | offsetof_ref = build_component_ref | |
e60a6f7b | 7446 | (loc, offsetof_ref, |
1576dec7 | 7447 | c_parser_peek_token (parser)->value); |
7448 | c_parser_consume_token (parser); | |
7449 | } | |
7450 | else | |
7451 | { | |
b560fabd | 7452 | struct c_expr ce; |
1576dec7 | 7453 | tree idx; |
dda49785 | 7454 | loc = c_parser_peek_token (parser)->location; |
1576dec7 | 7455 | c_parser_consume_token (parser); |
b560fabd | 7456 | ce = c_parser_expression (parser); |
7457 | ce = convert_lvalue_to_rvalue (loc, ce, false, false); | |
7458 | idx = ce.value; | |
a75b1c71 | 7459 | idx = c_fully_fold (idx, false, NULL); |
1576dec7 | 7460 | c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, |
7461 | "expected %<]%>"); | |
e60a6f7b | 7462 | offsetof_ref = build_array_ref (loc, offsetof_ref, idx); |
1576dec7 | 7463 | } |
7464 | } | |
7465 | } | |
7466 | else | |
7467 | c_parser_error (parser, "expected identifier"); | |
7468 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, | |
7469 | "expected %<)%>"); | |
7549df0d | 7470 | expr.value = fold_offsetof (offsetof_ref); |
1576dec7 | 7471 | } |
7472 | break; | |
7473 | case RID_CHOOSE_EXPR: | |
1576dec7 | 7474 | { |
f1f41a6c | 7475 | vec<c_expr_t, va_gc> *cexpr_list; |
a11dda8e | 7476 | c_expr_t *e1_p, *e2_p, *e3_p; |
7477 | tree c; | |
1576dec7 | 7478 | |
6cf89e04 | 7479 | c_parser_consume_token (parser); |
7480 | if (!c_parser_get_builtin_args (parser, | |
7481 | "__builtin_choose_expr", | |
0b049e15 | 7482 | &cexpr_list, true)) |
6cf89e04 | 7483 | { |
7484 | expr.value = error_mark_node; | |
7485 | break; | |
7486 | } | |
7487 | ||
f1f41a6c | 7488 | if (vec_safe_length (cexpr_list) != 3) |
6cf89e04 | 7489 | { |
7490 | error_at (loc, "wrong number of arguments to " | |
7491 | "%<__builtin_choose_expr%>"); | |
7492 | expr.value = error_mark_node; | |
7493 | break; | |
7494 | } | |
a11dda8e | 7495 | |
f1f41a6c | 7496 | e1_p = &(*cexpr_list)[0]; |
7497 | e2_p = &(*cexpr_list)[1]; | |
7498 | e3_p = &(*cexpr_list)[2]; | |
a11dda8e | 7499 | |
7500 | c = e1_p->value; | |
7501 | mark_exp_read (e2_p->value); | |
7502 | mark_exp_read (e3_p->value); | |
a75b1c71 | 7503 | if (TREE_CODE (c) != INTEGER_CST |
7504 | || !INTEGRAL_TYPE_P (TREE_TYPE (c))) | |
e3b80d49 | 7505 | error_at (loc, |
7506 | "first argument to %<__builtin_choose_expr%> not" | |
7507 | " a constant"); | |
a75b1c71 | 7508 | constant_expression_warning (c); |
a11dda8e | 7509 | expr = integer_zerop (c) ? *e3_p : *e2_p; |
6cf89e04 | 7510 | break; |
1576dec7 | 7511 | } |
1576dec7 | 7512 | case RID_TYPES_COMPATIBLE_P: |
7513 | c_parser_consume_token (parser); | |
7514 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
7515 | { | |
7516 | expr.value = error_mark_node; | |
1576dec7 | 7517 | break; |
7518 | } | |
7519 | t1 = c_parser_type_name (parser); | |
7520 | if (t1 == NULL) | |
7521 | { | |
7522 | expr.value = error_mark_node; | |
1576dec7 | 7523 | break; |
7524 | } | |
7525 | if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>")) | |
7526 | { | |
7527 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); | |
7528 | expr.value = error_mark_node; | |
1576dec7 | 7529 | break; |
7530 | } | |
7531 | t2 = c_parser_type_name (parser); | |
7532 | if (t2 == NULL) | |
7533 | { | |
7534 | expr.value = error_mark_node; | |
1576dec7 | 7535 | break; |
7536 | } | |
7537 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, | |
7538 | "expected %<)%>"); | |
7539 | { | |
7540 | tree e1, e2; | |
94b5c9e7 | 7541 | e1 = groktypename (t1, NULL, NULL); |
7542 | e2 = groktypename (t2, NULL, NULL); | |
7543 | if (e1 == error_mark_node || e2 == error_mark_node) | |
7544 | { | |
7545 | expr.value = error_mark_node; | |
7546 | break; | |
7547 | } | |
1576dec7 | 7548 | |
94b5c9e7 | 7549 | e1 = TYPE_MAIN_VARIANT (e1); |
7550 | e2 = TYPE_MAIN_VARIANT (e2); | |
1576dec7 | 7551 | |
2512209b | 7552 | expr.value |
7553 | = comptypes (e1, e2) ? integer_one_node : integer_zero_node; | |
1576dec7 | 7554 | } |
7555 | break; | |
6f58cf06 | 7556 | case RID_BUILTIN_CALL_WITH_STATIC_CHAIN: |
7557 | { | |
7558 | vec<c_expr_t, va_gc> *cexpr_list; | |
7559 | c_expr_t *e2_p; | |
7560 | tree chain_value; | |
7561 | ||
7562 | c_parser_consume_token (parser); | |
7563 | if (!c_parser_get_builtin_args (parser, | |
7564 | "__builtin_call_with_static_chain", | |
7565 | &cexpr_list, false)) | |
7566 | { | |
7567 | expr.value = error_mark_node; | |
7568 | break; | |
7569 | } | |
7570 | if (vec_safe_length (cexpr_list) != 2) | |
7571 | { | |
7572 | error_at (loc, "wrong number of arguments to " | |
7573 | "%<__builtin_call_with_static_chain%>"); | |
7574 | expr.value = error_mark_node; | |
7575 | break; | |
7576 | } | |
7577 | ||
7578 | expr = (*cexpr_list)[0]; | |
7579 | e2_p = &(*cexpr_list)[1]; | |
7580 | *e2_p = convert_lvalue_to_rvalue (loc, *e2_p, true, true); | |
7581 | chain_value = e2_p->value; | |
7582 | mark_exp_read (chain_value); | |
7583 | ||
7584 | if (TREE_CODE (expr.value) != CALL_EXPR) | |
7585 | error_at (loc, "first argument to " | |
7586 | "%<__builtin_call_with_static_chain%> " | |
7587 | "must be a call expression"); | |
7588 | else if (TREE_CODE (TREE_TYPE (chain_value)) != POINTER_TYPE) | |
7589 | error_at (loc, "second argument to " | |
7590 | "%<__builtin_call_with_static_chain%> " | |
7591 | "must be a pointer type"); | |
7592 | else | |
7593 | CALL_EXPR_STATIC_CHAIN (expr.value) = chain_value; | |
7594 | break; | |
7595 | } | |
bff4ad11 | 7596 | case RID_BUILTIN_COMPLEX: |
a11dda8e | 7597 | { |
f1f41a6c | 7598 | vec<c_expr_t, va_gc> *cexpr_list; |
a11dda8e | 7599 | c_expr_t *e1_p, *e2_p; |
7600 | ||
6cf89e04 | 7601 | c_parser_consume_token (parser); |
7602 | if (!c_parser_get_builtin_args (parser, | |
7603 | "__builtin_complex", | |
0b049e15 | 7604 | &cexpr_list, false)) |
6cf89e04 | 7605 | { |
7606 | expr.value = error_mark_node; | |
7607 | break; | |
7608 | } | |
7609 | ||
f1f41a6c | 7610 | if (vec_safe_length (cexpr_list) != 2) |
6cf89e04 | 7611 | { |
7612 | error_at (loc, "wrong number of arguments to " | |
7613 | "%<__builtin_complex%>"); | |
7614 | expr.value = error_mark_node; | |
7615 | break; | |
7616 | } | |
a11dda8e | 7617 | |
f1f41a6c | 7618 | e1_p = &(*cexpr_list)[0]; |
7619 | e2_p = &(*cexpr_list)[1]; | |
a11dda8e | 7620 | |
b560fabd | 7621 | *e1_p = convert_lvalue_to_rvalue (loc, *e1_p, true, true); |
a11dda8e | 7622 | if (TREE_CODE (e1_p->value) == EXCESS_PRECISION_EXPR) |
7623 | e1_p->value = convert (TREE_TYPE (e1_p->value), | |
7624 | TREE_OPERAND (e1_p->value, 0)); | |
b560fabd | 7625 | *e2_p = convert_lvalue_to_rvalue (loc, *e2_p, true, true); |
a11dda8e | 7626 | if (TREE_CODE (e2_p->value) == EXCESS_PRECISION_EXPR) |
7627 | e2_p->value = convert (TREE_TYPE (e2_p->value), | |
7628 | TREE_OPERAND (e2_p->value, 0)); | |
7629 | if (!SCALAR_FLOAT_TYPE_P (TREE_TYPE (e1_p->value)) | |
7630 | || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e1_p->value)) | |
7631 | || !SCALAR_FLOAT_TYPE_P (TREE_TYPE (e2_p->value)) | |
7632 | || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e2_p->value))) | |
6cf89e04 | 7633 | { |
7634 | error_at (loc, "%<__builtin_complex%> operand " | |
7635 | "not of real binary floating-point type"); | |
7636 | expr.value = error_mark_node; | |
7637 | break; | |
7638 | } | |
a11dda8e | 7639 | if (TYPE_MAIN_VARIANT (TREE_TYPE (e1_p->value)) |
7640 | != TYPE_MAIN_VARIANT (TREE_TYPE (e2_p->value))) | |
6cf89e04 | 7641 | { |
7642 | error_at (loc, | |
7643 | "%<__builtin_complex%> operands of different types"); | |
7644 | expr.value = error_mark_node; | |
7645 | break; | |
7646 | } | |
890c2e2f | 7647 | pedwarn_c90 (loc, OPT_Wpedantic, |
7648 | "ISO C90 does not support complex types"); | |
6cf89e04 | 7649 | expr.value = build2 (COMPLEX_EXPR, |
a11dda8e | 7650 | build_complex_type |
7651 | (TYPE_MAIN_VARIANT | |
7652 | (TREE_TYPE (e1_p->value))), | |
7653 | e1_p->value, e2_p->value); | |
6cf89e04 | 7654 | break; |
7655 | } | |
7656 | case RID_BUILTIN_SHUFFLE: | |
7657 | { | |
f1f41a6c | 7658 | vec<c_expr_t, va_gc> *cexpr_list; |
e739f10c | 7659 | unsigned int i; |
7660 | c_expr_t *p; | |
a11dda8e | 7661 | |
6cf89e04 | 7662 | c_parser_consume_token (parser); |
7663 | if (!c_parser_get_builtin_args (parser, | |
7664 | "__builtin_shuffle", | |
0b049e15 | 7665 | &cexpr_list, false)) |
6cf89e04 | 7666 | { |
7667 | expr.value = error_mark_node; | |
7668 | break; | |
7669 | } | |
7670 | ||
f1f41a6c | 7671 | FOR_EACH_VEC_SAFE_ELT (cexpr_list, i, p) |
b560fabd | 7672 | *p = convert_lvalue_to_rvalue (loc, *p, true, true); |
e739f10c | 7673 | |
f1f41a6c | 7674 | if (vec_safe_length (cexpr_list) == 2) |
a11dda8e | 7675 | expr.value = |
f4803722 | 7676 | c_build_vec_perm_expr |
f1f41a6c | 7677 | (loc, (*cexpr_list)[0].value, |
7678 | NULL_TREE, (*cexpr_list)[1].value); | |
a11dda8e | 7679 | |
f1f41a6c | 7680 | else if (vec_safe_length (cexpr_list) == 3) |
a11dda8e | 7681 | expr.value = |
f4803722 | 7682 | c_build_vec_perm_expr |
f1f41a6c | 7683 | (loc, (*cexpr_list)[0].value, |
7684 | (*cexpr_list)[1].value, | |
7685 | (*cexpr_list)[2].value); | |
6cf89e04 | 7686 | else |
7687 | { | |
7688 | error_at (loc, "wrong number of arguments to " | |
7689 | "%<__builtin_shuffle%>"); | |
7690 | expr.value = error_mark_node; | |
7691 | } | |
7692 | break; | |
7693 | } | |
1576dec7 | 7694 | case RID_AT_SELECTOR: |
7695 | gcc_assert (c_dialect_objc ()); | |
7696 | c_parser_consume_token (parser); | |
7697 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
7698 | { | |
7699 | expr.value = error_mark_node; | |
1576dec7 | 7700 | break; |
7701 | } | |
7702 | { | |
7703 | tree sel = c_parser_objc_selector_arg (parser); | |
7704 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, | |
7705 | "expected %<)%>"); | |
e60a6f7b | 7706 | expr.value = objc_build_selector_expr (loc, sel); |
1576dec7 | 7707 | } |
7708 | break; | |
7709 | case RID_AT_PROTOCOL: | |
7710 | gcc_assert (c_dialect_objc ()); | |
7711 | c_parser_consume_token (parser); | |
7712 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
7713 | { | |
7714 | expr.value = error_mark_node; | |
1576dec7 | 7715 | break; |
7716 | } | |
7717 | if (c_parser_next_token_is_not (parser, CPP_NAME)) | |
7718 | { | |
7719 | c_parser_error (parser, "expected identifier"); | |
7720 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); | |
7721 | expr.value = error_mark_node; | |
1576dec7 | 7722 | break; |
7723 | } | |
7724 | { | |
7725 | tree id = c_parser_peek_token (parser)->value; | |
7726 | c_parser_consume_token (parser); | |
7727 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, | |
7728 | "expected %<)%>"); | |
7729 | expr.value = objc_build_protocol_expr (id); | |
1576dec7 | 7730 | } |
7731 | break; | |
7732 | case RID_AT_ENCODE: | |
7733 | /* Extension to support C-structures in the archiver. */ | |
7734 | gcc_assert (c_dialect_objc ()); | |
7735 | c_parser_consume_token (parser); | |
7736 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
7737 | { | |
7738 | expr.value = error_mark_node; | |
1576dec7 | 7739 | break; |
7740 | } | |
7741 | t1 = c_parser_type_name (parser); | |
7742 | if (t1 == NULL) | |
7743 | { | |
7744 | expr.value = error_mark_node; | |
1576dec7 | 7745 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); |
7746 | break; | |
7747 | } | |
7748 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, | |
7749 | "expected %<)%>"); | |
7750 | { | |
a75b1c71 | 7751 | tree type = groktypename (t1, NULL, NULL); |
1576dec7 | 7752 | expr.value = objc_build_encode_expr (type); |
1576dec7 | 7753 | } |
7754 | break; | |
7aa04c8d | 7755 | case RID_GENERIC: |
7756 | expr = c_parser_generic_selection (parser); | |
7757 | break; | |
d037099f | 7758 | case RID_CILK_SPAWN: |
7759 | c_parser_consume_token (parser); | |
a89e6c15 | 7760 | if (!flag_cilkplus) |
d037099f | 7761 | { |
7762 | error_at (loc, "-fcilkplus must be enabled to use " | |
7763 | "%<_Cilk_spawn%>"); | |
7764 | expr = c_parser_postfix_expression (parser); | |
7765 | expr.value = error_mark_node; | |
7766 | } | |
0bc789fc | 7767 | else if (c_parser_peek_token (parser)->keyword == RID_CILK_SPAWN) |
d037099f | 7768 | { |
7769 | error_at (loc, "consecutive %<_Cilk_spawn%> keywords " | |
7770 | "are not permitted"); | |
7771 | /* Now flush out all the _Cilk_spawns. */ | |
7772 | while (c_parser_peek_token (parser)->keyword == RID_CILK_SPAWN) | |
7773 | c_parser_consume_token (parser); | |
7774 | expr = c_parser_postfix_expression (parser); | |
7775 | } | |
7776 | else | |
7777 | { | |
7778 | expr = c_parser_postfix_expression (parser); | |
7779 | expr.value = build_cilk_spawn (loc, expr.value); | |
7780 | } | |
7781 | break; | |
1576dec7 | 7782 | default: |
7783 | c_parser_error (parser, "expected expression"); | |
7784 | expr.value = error_mark_node; | |
1576dec7 | 7785 | break; |
7786 | } | |
7787 | break; | |
7788 | case CPP_OPEN_SQUARE: | |
7789 | if (c_dialect_objc ()) | |
7790 | { | |
7791 | tree receiver, args; | |
7792 | c_parser_consume_token (parser); | |
7793 | receiver = c_parser_objc_receiver (parser); | |
7794 | args = c_parser_objc_message_args (parser); | |
7795 | c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, | |
7796 | "expected %<]%>"); | |
4185cf58 | 7797 | expr.value = objc_build_message_expr (receiver, args); |
1576dec7 | 7798 | break; |
7799 | } | |
7800 | /* Else fall through to report error. */ | |
7801 | default: | |
7802 | c_parser_error (parser, "expected expression"); | |
7803 | expr.value = error_mark_node; | |
1576dec7 | 7804 | break; |
7805 | } | |
e60a6f7b | 7806 | return c_parser_postfix_expression_after_primary (parser, loc, expr); |
1576dec7 | 7807 | } |
7808 | ||
7809 | /* Parse a postfix expression after a parenthesized type name: the | |
7810 | brace-enclosed initializer of a compound literal, possibly followed | |
7811 | by some postfix operators. This is separate because it is not | |
7812 | possible to tell until after the type name whether a cast | |
7813 | expression has a cast or a compound literal, or whether the operand | |
7814 | of sizeof is a parenthesized type name or starts with a compound | |
0b09525f | 7815 | literal. TYPE_LOC is the location where TYPE_NAME starts--the |
7816 | location of the first token after the parentheses around the type | |
7817 | name. */ | |
1576dec7 | 7818 | |
7819 | static struct c_expr | |
7820 | c_parser_postfix_expression_after_paren_type (c_parser *parser, | |
0b09525f | 7821 | struct c_type_name *type_name, |
7822 | location_t type_loc) | |
1576dec7 | 7823 | { |
7824 | tree type; | |
7825 | struct c_expr init; | |
a75b1c71 | 7826 | bool non_const; |
1576dec7 | 7827 | struct c_expr expr; |
be9eba16 | 7828 | location_t start_loc; |
a75b1c71 | 7829 | tree type_expr = NULL_TREE; |
7830 | bool type_expr_const = true; | |
e60a6f7b | 7831 | check_compound_literal_type (type_loc, type_name); |
1576dec7 | 7832 | start_init (NULL_TREE, NULL, 0); |
a75b1c71 | 7833 | type = groktypename (type_name, &type_expr, &type_expr_const); |
be9eba16 | 7834 | start_loc = c_parser_peek_token (parser)->location; |
481f0237 | 7835 | if (type != error_mark_node && C_TYPE_VARIABLE_SIZE (type)) |
1576dec7 | 7836 | { |
0b09525f | 7837 | error_at (type_loc, "compound literal has variable size"); |
1576dec7 | 7838 | type = error_mark_node; |
7839 | } | |
7840 | init = c_parser_braced_init (parser, type, false); | |
7841 | finish_init (); | |
c9e51d25 | 7842 | maybe_warn_string_init (type_loc, type, init); |
1576dec7 | 7843 | |
6d5d708e | 7844 | if (type != error_mark_node |
7845 | && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type)) | |
7846 | && current_function_decl) | |
7847 | { | |
7848 | error ("compound literal qualified by address-space qualifier"); | |
7849 | type = error_mark_node; | |
7850 | } | |
7851 | ||
890c2e2f | 7852 | pedwarn_c90 (start_loc, OPT_Wpedantic, "ISO C90 forbids compound literals"); |
a75b1c71 | 7853 | non_const = ((init.value && TREE_CODE (init.value) == CONSTRUCTOR) |
7854 | ? CONSTRUCTOR_NON_CONST (init.value) | |
7855 | : init.original_code == C_MAYBE_CONST_EXPR); | |
7856 | non_const |= !type_expr_const; | |
e60a6f7b | 7857 | expr.value = build_compound_literal (start_loc, type, init.value, non_const); |
1576dec7 | 7858 | expr.original_code = ERROR_MARK; |
841fdaa6 | 7859 | expr.original_type = NULL; |
a75b1c71 | 7860 | if (type_expr) |
7861 | { | |
7862 | if (TREE_CODE (expr.value) == C_MAYBE_CONST_EXPR) | |
7863 | { | |
7864 | gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr.value) == NULL_TREE); | |
7865 | C_MAYBE_CONST_EXPR_PRE (expr.value) = type_expr; | |
7866 | } | |
7867 | else | |
7868 | { | |
7869 | gcc_assert (!non_const); | |
7870 | expr.value = build2 (C_MAYBE_CONST_EXPR, type, | |
7871 | type_expr, expr.value); | |
7872 | } | |
7873 | } | |
e60a6f7b | 7874 | return c_parser_postfix_expression_after_primary (parser, start_loc, expr); |
1576dec7 | 7875 | } |
7876 | ||
f003f5dc | 7877 | /* Callback function for sizeof_pointer_memaccess_warning to compare |
7878 | types. */ | |
7879 | ||
7880 | static bool | |
7881 | sizeof_ptr_memacc_comptypes (tree type1, tree type2) | |
7882 | { | |
7883 | return comptypes (type1, type2) == 1; | |
7884 | } | |
7885 | ||
1576dec7 | 7886 | /* Parse a postfix expression after the initial primary or compound |
e60a6f7b | 7887 | literal; that is, parse a series of postfix operators. |
7888 | ||
7889 | EXPR_LOC is the location of the primary expression. */ | |
1576dec7 | 7890 | |
7891 | static struct c_expr | |
7892 | c_parser_postfix_expression_after_primary (c_parser *parser, | |
e60a6f7b | 7893 | location_t expr_loc, |
1576dec7 | 7894 | struct c_expr expr) |
7895 | { | |
a75b1c71 | 7896 | struct c_expr orig_expr; |
b9c74b4d | 7897 | tree ident, idx; |
57f872a2 | 7898 | location_t sizeof_arg_loc[3]; |
7899 | tree sizeof_arg[3]; | |
305d96bc | 7900 | unsigned int literal_zero_mask; |
57f872a2 | 7901 | unsigned int i; |
f1f41a6c | 7902 | vec<tree, va_gc> *exprlist; |
b862f263 | 7903 | vec<tree, va_gc> *origtypes = NULL; |
ec761d5a | 7904 | vec<location_t> arg_loc = vNULL; |
7905 | ||
1576dec7 | 7906 | while (true) |
7907 | { | |
e60a6f7b | 7908 | location_t op_loc = c_parser_peek_token (parser)->location; |
1576dec7 | 7909 | switch (c_parser_peek_token (parser)->type) |
7910 | { | |
7911 | case CPP_OPEN_SQUARE: | |
7912 | /* Array reference. */ | |
7913 | c_parser_consume_token (parser); | |
a89e6c15 | 7914 | if (flag_cilkplus |
3c6d4197 | 7915 | && c_parser_peek_token (parser)->type == CPP_COLON) |
7916 | /* If we are here, then we have something like this: | |
7917 | Array [ : ] | |
7918 | */ | |
7919 | expr.value = c_parser_array_notation (expr_loc, parser, NULL_TREE, | |
7920 | expr.value); | |
7921 | else | |
7922 | { | |
7923 | idx = c_parser_expression (parser).value; | |
7924 | /* Here we have 3 options: | |
7925 | 1. Array [EXPR] -- Normal Array call. | |
7926 | 2. Array [EXPR : EXPR] -- Array notation without stride. | |
7927 | 3. Array [EXPR : EXPR : EXPR] -- Array notation with stride. | |
7928 | ||
7929 | For 1, we just handle it just like a normal array expression. | |
7930 | For 2 and 3 we handle it like we handle array notations. The | |
7931 | idx value we have above becomes the initial/start index. | |
7932 | */ | |
a89e6c15 | 7933 | if (flag_cilkplus |
3c6d4197 | 7934 | && c_parser_peek_token (parser)->type == CPP_COLON) |
7935 | expr.value = c_parser_array_notation (expr_loc, parser, idx, | |
7936 | expr.value); | |
7937 | else | |
7938 | { | |
7939 | c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, | |
7940 | "expected %<]%>"); | |
7941 | expr.value = build_array_ref (op_loc, expr.value, idx); | |
7942 | } | |
7943 | } | |
1576dec7 | 7944 | expr.original_code = ERROR_MARK; |
841fdaa6 | 7945 | expr.original_type = NULL; |
1576dec7 | 7946 | break; |
7947 | case CPP_OPEN_PAREN: | |
7948 | /* Function call. */ | |
7949 | c_parser_consume_token (parser); | |
57f872a2 | 7950 | for (i = 0; i < 3; i++) |
7951 | { | |
7952 | sizeof_arg[i] = NULL_TREE; | |
7953 | sizeof_arg_loc[i] = UNKNOWN_LOCATION; | |
7954 | } | |
305d96bc | 7955 | literal_zero_mask = 0; |
1576dec7 | 7956 | if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) |
b9c74b4d | 7957 | exprlist = NULL; |
1576dec7 | 7958 | else |
f003f5dc | 7959 | exprlist = c_parser_expr_list (parser, true, false, &origtypes, |
ec761d5a | 7960 | sizeof_arg_loc, sizeof_arg, |
305d96bc | 7961 | &arg_loc, &literal_zero_mask); |
1576dec7 | 7962 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, |
7963 | "expected %<)%>"); | |
a75b1c71 | 7964 | orig_expr = expr; |
abc6c64f | 7965 | mark_exp_read (expr.value); |
57f872a2 | 7966 | if (warn_sizeof_pointer_memaccess) |
7967 | sizeof_pointer_memaccess_warning (sizeof_arg_loc, | |
f003f5dc | 7968 | expr.value, exprlist, |
57f872a2 | 7969 | sizeof_arg, |
f003f5dc | 7970 | sizeof_ptr_memacc_comptypes); |
305d96bc | 7971 | if (warn_memset_transposed_args |
7972 | && TREE_CODE (expr.value) == FUNCTION_DECL | |
7973 | && DECL_BUILT_IN_CLASS (expr.value) == BUILT_IN_NORMAL | |
7974 | && DECL_FUNCTION_CODE (expr.value) == BUILT_IN_MEMSET | |
7975 | && vec_safe_length (exprlist) == 3 | |
7976 | && integer_zerop ((*exprlist)[2]) | |
7977 | && (literal_zero_mask & (1 << 2)) != 0 | |
7978 | && (!integer_zerop ((*exprlist)[1]) | |
7979 | || (literal_zero_mask & (1 << 1)) == 0)) | |
7980 | warning_at (expr_loc, OPT_Wmemset_transposed_args, | |
7981 | "%<memset%> used with constant zero length parameter; " | |
7982 | "this could be due to transposed parameters"); | |
7983 | ||
5a672e62 | 7984 | expr.value |
7985 | = c_build_function_call_vec (expr_loc, arg_loc, expr.value, | |
7986 | exprlist, origtypes); | |
1576dec7 | 7987 | expr.original_code = ERROR_MARK; |
a75b1c71 | 7988 | if (TREE_CODE (expr.value) == INTEGER_CST |
7989 | && TREE_CODE (orig_expr.value) == FUNCTION_DECL | |
7990 | && DECL_BUILT_IN_CLASS (orig_expr.value) == BUILT_IN_NORMAL | |
7991 | && DECL_FUNCTION_CODE (orig_expr.value) == BUILT_IN_CONSTANT_P) | |
7992 | expr.original_code = C_MAYBE_CONST_EXPR; | |
841fdaa6 | 7993 | expr.original_type = NULL; |
f1f41a6c | 7994 | if (exprlist) |
b9c74b4d | 7995 | { |
f352a3fb | 7996 | release_tree_vector (exprlist); |
7997 | release_tree_vector (origtypes); | |
b9c74b4d | 7998 | } |
ec761d5a | 7999 | arg_loc.release (); |
1576dec7 | 8000 | break; |
8001 | case CPP_DOT: | |
8002 | /* Structure element reference. */ | |
8003 | c_parser_consume_token (parser); | |
e60a6f7b | 8004 | expr = default_function_array_conversion (expr_loc, expr); |
1576dec7 | 8005 | if (c_parser_next_token_is (parser, CPP_NAME)) |
8006 | ident = c_parser_peek_token (parser)->value; | |
8007 | else | |
8008 | { | |
8009 | c_parser_error (parser, "expected identifier"); | |
8010 | expr.value = error_mark_node; | |
8011 | expr.original_code = ERROR_MARK; | |
841fdaa6 | 8012 | expr.original_type = NULL; |
1576dec7 | 8013 | return expr; |
8014 | } | |
8015 | c_parser_consume_token (parser); | |
e60a6f7b | 8016 | expr.value = build_component_ref (op_loc, expr.value, ident); |
1576dec7 | 8017 | expr.original_code = ERROR_MARK; |
841fdaa6 | 8018 | if (TREE_CODE (expr.value) != COMPONENT_REF) |
8019 | expr.original_type = NULL; | |
8020 | else | |
8021 | { | |
8022 | /* Remember the original type of a bitfield. */ | |
8023 | tree field = TREE_OPERAND (expr.value, 1); | |
8024 | if (TREE_CODE (field) != FIELD_DECL) | |
8025 | expr.original_type = NULL; | |
8026 | else | |
8027 | expr.original_type = DECL_BIT_FIELD_TYPE (field); | |
8028 | } | |
1576dec7 | 8029 | break; |
8030 | case CPP_DEREF: | |
8031 | /* Structure element reference. */ | |
8032 | c_parser_consume_token (parser); | |
b560fabd | 8033 | expr = convert_lvalue_to_rvalue (expr_loc, expr, true, false); |
1576dec7 | 8034 | if (c_parser_next_token_is (parser, CPP_NAME)) |
8035 | ident = c_parser_peek_token (parser)->value; | |
8036 | else | |
8037 | { | |
8038 | c_parser_error (parser, "expected identifier"); | |
8039 | expr.value = error_mark_node; | |
8040 | expr.original_code = ERROR_MARK; | |
841fdaa6 | 8041 | expr.original_type = NULL; |
1576dec7 | 8042 | return expr; |
8043 | } | |
8044 | c_parser_consume_token (parser); | |
e60a6f7b | 8045 | expr.value = build_component_ref (op_loc, |
8046 | build_indirect_ref (op_loc, | |
b6889cb0 | 8047 | expr.value, |
f08923b3 | 8048 | RO_ARROW), |
dda49785 | 8049 | ident); |
1576dec7 | 8050 | expr.original_code = ERROR_MARK; |
841fdaa6 | 8051 | if (TREE_CODE (expr.value) != COMPONENT_REF) |
8052 | expr.original_type = NULL; | |
8053 | else | |
8054 | { | |
8055 | /* Remember the original type of a bitfield. */ | |
8056 | tree field = TREE_OPERAND (expr.value, 1); | |
8057 | if (TREE_CODE (field) != FIELD_DECL) | |
8058 | expr.original_type = NULL; | |
8059 | else | |
8060 | expr.original_type = DECL_BIT_FIELD_TYPE (field); | |
8061 | } | |
1576dec7 | 8062 | break; |
8063 | case CPP_PLUS_PLUS: | |
8064 | /* Postincrement. */ | |
8065 | c_parser_consume_token (parser); | |
3c6d4197 | 8066 | /* If the expressions have array notations, we expand them. */ |
a89e6c15 | 8067 | if (flag_cilkplus |
3c6d4197 | 8068 | && TREE_CODE (expr.value) == ARRAY_NOTATION_REF) |
8069 | expr = fix_array_notation_expr (expr_loc, POSTINCREMENT_EXPR, expr); | |
8070 | else | |
8071 | { | |
8072 | expr = default_function_array_read_conversion (expr_loc, expr); | |
8073 | expr.value = build_unary_op (op_loc, | |
8074 | POSTINCREMENT_EXPR, expr.value, 0); | |
8075 | } | |
1576dec7 | 8076 | expr.original_code = ERROR_MARK; |
841fdaa6 | 8077 | expr.original_type = NULL; |
1576dec7 | 8078 | break; |
8079 | case CPP_MINUS_MINUS: | |
8080 | /* Postdecrement. */ | |
8081 | c_parser_consume_token (parser); | |
3c6d4197 | 8082 | /* If the expressions have array notations, we expand them. */ |
a89e6c15 | 8083 | if (flag_cilkplus |
3c6d4197 | 8084 | && TREE_CODE (expr.value) == ARRAY_NOTATION_REF) |
8085 | expr = fix_array_notation_expr (expr_loc, POSTDECREMENT_EXPR, expr); | |
8086 | else | |
8087 | { | |
8088 | expr = default_function_array_read_conversion (expr_loc, expr); | |
8089 | expr.value = build_unary_op (op_loc, | |
8090 | POSTDECREMENT_EXPR, expr.value, 0); | |
8091 | } | |
1576dec7 | 8092 | expr.original_code = ERROR_MARK; |
841fdaa6 | 8093 | expr.original_type = NULL; |
1576dec7 | 8094 | break; |
8095 | default: | |
8096 | return expr; | |
8097 | } | |
8098 | } | |
8099 | } | |
8100 | ||
8101 | /* Parse an expression (C90 6.3.17, C99 6.5.17). | |
8102 | ||
8103 | expression: | |
8104 | assignment-expression | |
8105 | expression , assignment-expression | |
8106 | */ | |
8107 | ||
8108 | static struct c_expr | |
8109 | c_parser_expression (c_parser *parser) | |
8110 | { | |
b560fabd | 8111 | location_t tloc = c_parser_peek_token (parser)->location; |
1576dec7 | 8112 | struct c_expr expr; |
8113 | expr = c_parser_expr_no_commas (parser, NULL); | |
b560fabd | 8114 | if (c_parser_next_token_is (parser, CPP_COMMA)) |
8115 | expr = convert_lvalue_to_rvalue (tloc, expr, true, false); | |
1576dec7 | 8116 | while (c_parser_next_token_is (parser, CPP_COMMA)) |
8117 | { | |
8118 | struct c_expr next; | |
b2af2a93 | 8119 | tree lhsval; |
e60a6f7b | 8120 | location_t loc = c_parser_peek_token (parser)->location; |
8121 | location_t expr_loc; | |
1576dec7 | 8122 | c_parser_consume_token (parser); |
e60a6f7b | 8123 | expr_loc = c_parser_peek_token (parser)->location; |
b2af2a93 | 8124 | lhsval = expr.value; |
8125 | while (TREE_CODE (lhsval) == COMPOUND_EXPR) | |
8126 | lhsval = TREE_OPERAND (lhsval, 1); | |
8127 | if (DECL_P (lhsval) || handled_component_p (lhsval)) | |
8128 | mark_exp_read (lhsval); | |
1576dec7 | 8129 | next = c_parser_expr_no_commas (parser, NULL); |
b560fabd | 8130 | next = convert_lvalue_to_rvalue (expr_loc, next, true, false); |
e60a6f7b | 8131 | expr.value = build_compound_expr (loc, expr.value, next.value); |
1576dec7 | 8132 | expr.original_code = COMPOUND_EXPR; |
bc620c5c | 8133 | expr.original_type = next.original_type; |
1576dec7 | 8134 | } |
8135 | return expr; | |
8136 | } | |
8137 | ||
b560fabd | 8138 | /* Parse an expression and convert functions or arrays to pointers and |
8139 | lvalues to rvalues. */ | |
f14c8207 | 8140 | |
8141 | static struct c_expr | |
8142 | c_parser_expression_conv (c_parser *parser) | |
8143 | { | |
8144 | struct c_expr expr; | |
e60a6f7b | 8145 | location_t loc = c_parser_peek_token (parser)->location; |
f14c8207 | 8146 | expr = c_parser_expression (parser); |
b560fabd | 8147 | expr = convert_lvalue_to_rvalue (loc, expr, true, false); |
f14c8207 | 8148 | return expr; |
8149 | } | |
8150 | ||
305d96bc | 8151 | /* Helper function of c_parser_expr_list. Check if IDXth (0 based) |
8152 | argument is a literal zero alone and if so, set it in literal_zero_mask. */ | |
8153 | ||
8154 | static inline void | |
8155 | c_parser_check_literal_zero (c_parser *parser, unsigned *literal_zero_mask, | |
8156 | unsigned int idx) | |
8157 | { | |
8158 | if (idx >= HOST_BITS_PER_INT) | |
8159 | return; | |
8160 | ||
8161 | c_token *tok = c_parser_peek_token (parser); | |
8162 | switch (tok->type) | |
8163 | { | |
8164 | case CPP_NUMBER: | |
8165 | case CPP_CHAR: | |
8166 | case CPP_WCHAR: | |
8167 | case CPP_CHAR16: | |
8168 | case CPP_CHAR32: | |
8169 | /* If a parameter is literal zero alone, remember it | |
8170 | for -Wmemset-transposed-args warning. */ | |
8171 | if (integer_zerop (tok->value) | |
8172 | && !TREE_OVERFLOW (tok->value) | |
8173 | && (c_parser_peek_2nd_token (parser)->type == CPP_COMMA | |
8174 | || c_parser_peek_2nd_token (parser)->type == CPP_CLOSE_PAREN)) | |
8175 | *literal_zero_mask |= 1U << idx; | |
8176 | default: | |
8177 | break; | |
8178 | } | |
8179 | } | |
8180 | ||
f14c8207 | 8181 | /* Parse a non-empty list of expressions. If CONVERT_P, convert |
b560fabd | 8182 | functions and arrays to pointers and lvalues to rvalues. If |
ec761d5a | 8183 | FOLD_P, fold the expressions. If LOCATIONS is non-NULL, save the |
8184 | locations of function arguments into this vector. | |
1576dec7 | 8185 | |
8186 | nonempty-expr-list: | |
8187 | assignment-expression | |
8188 | nonempty-expr-list , assignment-expression | |
8189 | */ | |
8190 | ||
f1f41a6c | 8191 | static vec<tree, va_gc> * |
b9c74b4d | 8192 | c_parser_expr_list (c_parser *parser, bool convert_p, bool fold_p, |
f1f41a6c | 8193 | vec<tree, va_gc> **p_orig_types, |
ec761d5a | 8194 | location_t *sizeof_arg_loc, tree *sizeof_arg, |
305d96bc | 8195 | vec<location_t> *locations, |
8196 | unsigned int *literal_zero_mask) | |
1576dec7 | 8197 | { |
f1f41a6c | 8198 | vec<tree, va_gc> *ret; |
8199 | vec<tree, va_gc> *orig_types; | |
1576dec7 | 8200 | struct c_expr expr; |
e60a6f7b | 8201 | location_t loc = c_parser_peek_token (parser)->location; |
57f872a2 | 8202 | location_t cur_sizeof_arg_loc = UNKNOWN_LOCATION; |
8203 | unsigned int idx = 0; | |
b9c74b4d | 8204 | |
f352a3fb | 8205 | ret = make_tree_vector (); |
b9c74b4d | 8206 | if (p_orig_types == NULL) |
8207 | orig_types = NULL; | |
8208 | else | |
f352a3fb | 8209 | orig_types = make_tree_vector (); |
b9c74b4d | 8210 | |
f003f5dc | 8211 | if (sizeof_arg != NULL |
8212 | && c_parser_next_token_is_keyword (parser, RID_SIZEOF)) | |
57f872a2 | 8213 | cur_sizeof_arg_loc = c_parser_peek_2nd_token (parser)->location; |
305d96bc | 8214 | if (literal_zero_mask) |
8215 | c_parser_check_literal_zero (parser, literal_zero_mask, 0); | |
1576dec7 | 8216 | expr = c_parser_expr_no_commas (parser, NULL); |
f14c8207 | 8217 | if (convert_p) |
b560fabd | 8218 | expr = convert_lvalue_to_rvalue (loc, expr, true, true); |
a75b1c71 | 8219 | if (fold_p) |
8220 | expr.value = c_fully_fold (expr.value, false, NULL); | |
f1f41a6c | 8221 | ret->quick_push (expr.value); |
8222 | if (orig_types) | |
8223 | orig_types->quick_push (expr.original_type); | |
ec761d5a | 8224 | if (locations) |
8225 | locations->safe_push (loc); | |
57f872a2 | 8226 | if (sizeof_arg != NULL |
8227 | && cur_sizeof_arg_loc != UNKNOWN_LOCATION | |
8228 | && expr.original_code == SIZEOF_EXPR) | |
8229 | { | |
8230 | sizeof_arg[0] = c_last_sizeof_arg; | |
8231 | sizeof_arg_loc[0] = cur_sizeof_arg_loc; | |
8232 | } | |
1576dec7 | 8233 | while (c_parser_next_token_is (parser, CPP_COMMA)) |
8234 | { | |
8235 | c_parser_consume_token (parser); | |
e60a6f7b | 8236 | loc = c_parser_peek_token (parser)->location; |
f003f5dc | 8237 | if (sizeof_arg != NULL |
8238 | && c_parser_next_token_is_keyword (parser, RID_SIZEOF)) | |
57f872a2 | 8239 | cur_sizeof_arg_loc = c_parser_peek_2nd_token (parser)->location; |
f003f5dc | 8240 | else |
57f872a2 | 8241 | cur_sizeof_arg_loc = UNKNOWN_LOCATION; |
305d96bc | 8242 | if (literal_zero_mask) |
8243 | c_parser_check_literal_zero (parser, literal_zero_mask, idx + 1); | |
1576dec7 | 8244 | expr = c_parser_expr_no_commas (parser, NULL); |
f14c8207 | 8245 | if (convert_p) |
b560fabd | 8246 | expr = convert_lvalue_to_rvalue (loc, expr, true, true); |
a75b1c71 | 8247 | if (fold_p) |
8248 | expr.value = c_fully_fold (expr.value, false, NULL); | |
f1f41a6c | 8249 | vec_safe_push (ret, expr.value); |
8250 | if (orig_types) | |
8251 | vec_safe_push (orig_types, expr.original_type); | |
ec761d5a | 8252 | if (locations) |
8253 | locations->safe_push (loc); | |
57f872a2 | 8254 | if (++idx < 3 |
8255 | && sizeof_arg != NULL | |
8256 | && cur_sizeof_arg_loc != UNKNOWN_LOCATION | |
f003f5dc | 8257 | && expr.original_code == SIZEOF_EXPR) |
8258 | { | |
57f872a2 | 8259 | sizeof_arg[idx] = c_last_sizeof_arg; |
8260 | sizeof_arg_loc[idx] = cur_sizeof_arg_loc; | |
f003f5dc | 8261 | } |
8262 | } | |
f1f41a6c | 8263 | if (orig_types) |
b9c74b4d | 8264 | *p_orig_types = orig_types; |
1576dec7 | 8265 | return ret; |
8266 | } | |
1576dec7 | 8267 | \f |
8268 | /* Parse Objective-C-specific constructs. */ | |
8269 | ||
8270 | /* Parse an objc-class-definition. | |
8271 | ||
8272 | objc-class-definition: | |
8273 | @interface identifier objc-superclass[opt] objc-protocol-refs[opt] | |
8274 | objc-class-instance-variables[opt] objc-methodprotolist @end | |
8275 | @implementation identifier objc-superclass[opt] | |
8276 | objc-class-instance-variables[opt] | |
8277 | @interface identifier ( identifier ) objc-protocol-refs[opt] | |
8278 | objc-methodprotolist @end | |
e16610d0 | 8279 | @interface identifier ( ) objc-protocol-refs[opt] |
8280 | objc-methodprotolist @end | |
1576dec7 | 8281 | @implementation identifier ( identifier ) |
8282 | ||
8283 | objc-superclass: | |
8284 | : identifier | |
8285 | ||
8286 | "@interface identifier (" must start "@interface identifier ( | |
8287 | identifier ) ...": objc-methodprotolist in the first production may | |
442e3cb9 | 8288 | not start with a parenthesized identifier as a declarator of a data |
1576dec7 | 8289 | definition with no declaration specifiers if the objc-superclass, |
8290 | objc-protocol-refs and objc-class-instance-variables are omitted. */ | |
8291 | ||
8292 | static void | |
a336eb4b | 8293 | c_parser_objc_class_definition (c_parser *parser, tree attributes) |
1576dec7 | 8294 | { |
8295 | bool iface_p; | |
8296 | tree id1; | |
8297 | tree superclass; | |
8298 | if (c_parser_next_token_is_keyword (parser, RID_AT_INTERFACE)) | |
8299 | iface_p = true; | |
8300 | else if (c_parser_next_token_is_keyword (parser, RID_AT_IMPLEMENTATION)) | |
8301 | iface_p = false; | |
8302 | else | |
8303 | gcc_unreachable (); | |
a336eb4b | 8304 | |
1576dec7 | 8305 | c_parser_consume_token (parser); |
8306 | if (c_parser_next_token_is_not (parser, CPP_NAME)) | |
8307 | { | |
8308 | c_parser_error (parser, "expected identifier"); | |
8309 | return; | |
8310 | } | |
8311 | id1 = c_parser_peek_token (parser)->value; | |
8312 | c_parser_consume_token (parser); | |
8313 | if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) | |
8314 | { | |
e16610d0 | 8315 | /* We have a category or class extension. */ |
1576dec7 | 8316 | tree id2; |
8317 | tree proto = NULL_TREE; | |
8318 | c_parser_consume_token (parser); | |
8319 | if (c_parser_next_token_is_not (parser, CPP_NAME)) | |
8320 | { | |
e16610d0 | 8321 | if (iface_p && c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) |
8322 | { | |
8323 | /* We have a class extension. */ | |
8324 | id2 = NULL_TREE; | |
8325 | } | |
8326 | else | |
8327 | { | |
8328 | c_parser_error (parser, "expected identifier or %<)%>"); | |
8329 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); | |
8330 | return; | |
8331 | } | |
8332 | } | |
8333 | else | |
8334 | { | |
8335 | id2 = c_parser_peek_token (parser)->value; | |
8336 | c_parser_consume_token (parser); | |
1576dec7 | 8337 | } |
1576dec7 | 8338 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); |
8339 | if (!iface_p) | |
8340 | { | |
8341 | objc_start_category_implementation (id1, id2); | |
8342 | return; | |
8343 | } | |
8344 | if (c_parser_next_token_is (parser, CPP_LESS)) | |
8345 | proto = c_parser_objc_protocol_refs (parser); | |
a336eb4b | 8346 | objc_start_category_interface (id1, id2, proto, attributes); |
1576dec7 | 8347 | c_parser_objc_methodprotolist (parser); |
8348 | c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>"); | |
8349 | objc_finish_interface (); | |
8350 | return; | |
8351 | } | |
8352 | if (c_parser_next_token_is (parser, CPP_COLON)) | |
8353 | { | |
8354 | c_parser_consume_token (parser); | |
8355 | if (c_parser_next_token_is_not (parser, CPP_NAME)) | |
8356 | { | |
8357 | c_parser_error (parser, "expected identifier"); | |
8358 | return; | |
8359 | } | |
8360 | superclass = c_parser_peek_token (parser)->value; | |
8361 | c_parser_consume_token (parser); | |
8362 | } | |
8363 | else | |
8364 | superclass = NULL_TREE; | |
8365 | if (iface_p) | |
8366 | { | |
8367 | tree proto = NULL_TREE; | |
8368 | if (c_parser_next_token_is (parser, CPP_LESS)) | |
8369 | proto = c_parser_objc_protocol_refs (parser); | |
a336eb4b | 8370 | objc_start_class_interface (id1, superclass, proto, attributes); |
1576dec7 | 8371 | } |
8372 | else | |
8373 | objc_start_class_implementation (id1, superclass); | |
8374 | if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) | |
8375 | c_parser_objc_class_instance_variables (parser); | |
8376 | if (iface_p) | |
8377 | { | |
8378 | objc_continue_interface (); | |
8379 | c_parser_objc_methodprotolist (parser); | |
8380 | c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>"); | |
8381 | objc_finish_interface (); | |
8382 | } | |
8383 | else | |
8384 | { | |
8385 | objc_continue_implementation (); | |
8386 | return; | |
8387 | } | |
8388 | } | |
8389 | ||
8390 | /* Parse objc-class-instance-variables. | |
8391 | ||
8392 | objc-class-instance-variables: | |
8393 | { objc-instance-variable-decl-list[opt] } | |
8394 | ||
8395 | objc-instance-variable-decl-list: | |
8396 | objc-visibility-spec | |
8397 | objc-instance-variable-decl ; | |
8398 | ; | |
8399 | objc-instance-variable-decl-list objc-visibility-spec | |
8400 | objc-instance-variable-decl-list objc-instance-variable-decl ; | |
8401 | objc-instance-variable-decl-list ; | |
8402 | ||
8403 | objc-visibility-spec: | |
8404 | @private | |
8405 | @protected | |
8406 | @public | |
8407 | ||
8408 | objc-instance-variable-decl: | |
8409 | struct-declaration | |
8410 | */ | |
8411 | ||
8412 | static void | |
8413 | c_parser_objc_class_instance_variables (c_parser *parser) | |
8414 | { | |
8415 | gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE)); | |
8416 | c_parser_consume_token (parser); | |
8417 | while (c_parser_next_token_is_not (parser, CPP_EOF)) | |
8418 | { | |
8419 | tree decls; | |
8420 | /* Parse any stray semicolon. */ | |
8421 | if (c_parser_next_token_is (parser, CPP_SEMICOLON)) | |
8422 | { | |
29438999 | 8423 | pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic, |
7ef1fa91 | 8424 | "extra semicolon"); |
1576dec7 | 8425 | c_parser_consume_token (parser); |
8426 | continue; | |
8427 | } | |
8428 | /* Stop if at the end of the instance variables. */ | |
8429 | if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) | |
8430 | { | |
8431 | c_parser_consume_token (parser); | |
8432 | break; | |
8433 | } | |
8434 | /* Parse any objc-visibility-spec. */ | |
e5c75ac3 | 8435 | if (c_parser_next_token_is_keyword (parser, RID_AT_PRIVATE)) |
1576dec7 | 8436 | { |
8437 | c_parser_consume_token (parser); | |
4a8875ed | 8438 | objc_set_visibility (OBJC_IVAR_VIS_PRIVATE); |
1576dec7 | 8439 | continue; |
8440 | } | |
e5c75ac3 | 8441 | else if (c_parser_next_token_is_keyword (parser, RID_AT_PROTECTED)) |
1576dec7 | 8442 | { |
8443 | c_parser_consume_token (parser); | |
4a8875ed | 8444 | objc_set_visibility (OBJC_IVAR_VIS_PROTECTED); |
1576dec7 | 8445 | continue; |
8446 | } | |
e5c75ac3 | 8447 | else if (c_parser_next_token_is_keyword (parser, RID_AT_PUBLIC)) |
1576dec7 | 8448 | { |
8449 | c_parser_consume_token (parser); | |
4a8875ed | 8450 | objc_set_visibility (OBJC_IVAR_VIS_PUBLIC); |
8451 | continue; | |
8452 | } | |
8453 | else if (c_parser_next_token_is_keyword (parser, RID_AT_PACKAGE)) | |
8454 | { | |
8455 | c_parser_consume_token (parser); | |
8456 | objc_set_visibility (OBJC_IVAR_VIS_PACKAGE); | |
1576dec7 | 8457 | continue; |
8458 | } | |
b75b98aa | 8459 | else if (c_parser_next_token_is (parser, CPP_PRAGMA)) |
8460 | { | |
8461 | c_parser_pragma (parser, pragma_external); | |
8462 | continue; | |
8463 | } | |
8464 | ||
1576dec7 | 8465 | /* Parse some comma-separated declarations. */ |
8466 | decls = c_parser_struct_declaration (parser); | |
7ef1fa91 | 8467 | if (decls == NULL) |
8468 | { | |
8469 | /* There is a syntax error. We want to skip the offending | |
8470 | tokens up to the next ';' (included) or '}' | |
8471 | (excluded). */ | |
8472 | ||
8473 | /* First, skip manually a ')' or ']'. This is because they | |
8474 | reduce the nesting level, so c_parser_skip_until_found() | |
8475 | wouldn't be able to skip past them. */ | |
8476 | c_token *token = c_parser_peek_token (parser); | |
8477 | if (token->type == CPP_CLOSE_PAREN || token->type == CPP_CLOSE_SQUARE) | |
8478 | c_parser_consume_token (parser); | |
8479 | ||
8480 | /* Then, do the standard skipping. */ | |
8481 | c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL); | |
8482 | ||
8483 | /* We hopefully recovered. Start normal parsing again. */ | |
8484 | parser->error = false; | |
8485 | continue; | |
8486 | } | |
8487 | else | |
8488 | { | |
8489 | /* Comma-separated instance variables are chained together | |
8490 | in reverse order; add them one by one. */ | |
8491 | tree ivar = nreverse (decls); | |
8492 | for (; ivar; ivar = DECL_CHAIN (ivar)) | |
8493 | objc_add_instance_variable (copy_node (ivar)); | |
8494 | } | |
1576dec7 | 8495 | c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); |
8496 | } | |
8497 | } | |
8498 | ||
8499 | /* Parse an objc-class-declaration. | |
8500 | ||
8501 | objc-class-declaration: | |
8502 | @class identifier-list ; | |
8503 | */ | |
8504 | ||
8505 | static void | |
8506 | c_parser_objc_class_declaration (c_parser *parser) | |
8507 | { | |
e5c75ac3 | 8508 | gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_CLASS)); |
1576dec7 | 8509 | c_parser_consume_token (parser); |
8510 | /* Any identifiers, including those declared as type names, are OK | |
8511 | here. */ | |
8512 | while (true) | |
8513 | { | |
8514 | tree id; | |
8515 | if (c_parser_next_token_is_not (parser, CPP_NAME)) | |
8516 | { | |
8517 | c_parser_error (parser, "expected identifier"); | |
e1f293c0 | 8518 | c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL); |
8519 | parser->error = false; | |
8520 | return; | |
1576dec7 | 8521 | } |
8522 | id = c_parser_peek_token (parser)->value; | |
29d7200d | 8523 | objc_declare_class (id); |
1576dec7 | 8524 | c_parser_consume_token (parser); |
8525 | if (c_parser_next_token_is (parser, CPP_COMMA)) | |
8526 | c_parser_consume_token (parser); | |
8527 | else | |
8528 | break; | |
8529 | } | |
8530 | c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); | |
1576dec7 | 8531 | } |
8532 | ||
8533 | /* Parse an objc-alias-declaration. | |
8534 | ||
8535 | objc-alias-declaration: | |
8536 | @compatibility_alias identifier identifier ; | |
8537 | */ | |
8538 | ||
8539 | static void | |
8540 | c_parser_objc_alias_declaration (c_parser *parser) | |
8541 | { | |
8542 | tree id1, id2; | |
8543 | gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_ALIAS)); | |
8544 | c_parser_consume_token (parser); | |
8545 | if (c_parser_next_token_is_not (parser, CPP_NAME)) | |
8546 | { | |
8547 | c_parser_error (parser, "expected identifier"); | |
8548 | c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL); | |
8549 | return; | |
8550 | } | |
8551 | id1 = c_parser_peek_token (parser)->value; | |
8552 | c_parser_consume_token (parser); | |
8553 | if (c_parser_next_token_is_not (parser, CPP_NAME)) | |
8554 | { | |
8555 | c_parser_error (parser, "expected identifier"); | |
8556 | c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL); | |
8557 | return; | |
8558 | } | |
8559 | id2 = c_parser_peek_token (parser)->value; | |
8560 | c_parser_consume_token (parser); | |
8561 | c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); | |
8562 | objc_declare_alias (id1, id2); | |
8563 | } | |
8564 | ||
8565 | /* Parse an objc-protocol-definition. | |
8566 | ||
8567 | objc-protocol-definition: | |
8568 | @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end | |
8569 | @protocol identifier-list ; | |
8570 | ||
8571 | "@protocol identifier ;" should be resolved as "@protocol | |
8572 | identifier-list ;": objc-methodprotolist may not start with a | |
8573 | semicolon in the first alternative if objc-protocol-refs are | |
8574 | omitted. */ | |
8575 | ||
8576 | static void | |
a336eb4b | 8577 | c_parser_objc_protocol_definition (c_parser *parser, tree attributes) |
1576dec7 | 8578 | { |
8579 | gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_PROTOCOL)); | |
a336eb4b | 8580 | |
1576dec7 | 8581 | c_parser_consume_token (parser); |
8582 | if (c_parser_next_token_is_not (parser, CPP_NAME)) | |
8583 | { | |
8584 | c_parser_error (parser, "expected identifier"); | |
8585 | return; | |
8586 | } | |
8587 | if (c_parser_peek_2nd_token (parser)->type == CPP_COMMA | |
8588 | || c_parser_peek_2nd_token (parser)->type == CPP_SEMICOLON) | |
8589 | { | |
1576dec7 | 8590 | /* Any identifiers, including those declared as type names, are |
8591 | OK here. */ | |
8592 | while (true) | |
8593 | { | |
8594 | tree id; | |
8595 | if (c_parser_next_token_is_not (parser, CPP_NAME)) | |
8596 | { | |
8597 | c_parser_error (parser, "expected identifier"); | |
8598 | break; | |
8599 | } | |
8600 | id = c_parser_peek_token (parser)->value; | |
a758bf7d | 8601 | objc_declare_protocol (id, attributes); |
1576dec7 | 8602 | c_parser_consume_token (parser); |
8603 | if (c_parser_next_token_is (parser, CPP_COMMA)) | |
8604 | c_parser_consume_token (parser); | |
8605 | else | |
8606 | break; | |
8607 | } | |
8608 | c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); | |
1576dec7 | 8609 | } |
8610 | else | |
8611 | { | |
8612 | tree id = c_parser_peek_token (parser)->value; | |
8613 | tree proto = NULL_TREE; | |
8614 | c_parser_consume_token (parser); | |
8615 | if (c_parser_next_token_is (parser, CPP_LESS)) | |
8616 | proto = c_parser_objc_protocol_refs (parser); | |
920d59b0 | 8617 | parser->objc_pq_context = true; |
a336eb4b | 8618 | objc_start_protocol (id, proto, attributes); |
1576dec7 | 8619 | c_parser_objc_methodprotolist (parser); |
8620 | c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>"); | |
920d59b0 | 8621 | parser->objc_pq_context = false; |
1576dec7 | 8622 | objc_finish_interface (); |
8623 | } | |
8624 | } | |
8625 | ||
8626 | /* Parse an objc-method-type. | |
8627 | ||
8628 | objc-method-type: | |
8629 | + | |
8630 | - | |
1576dec7 | 8631 | |
45b2b110 | 8632 | Return true if it is a class method (+) and false if it is |
8633 | an instance method (-). | |
8634 | */ | |
8635 | static inline bool | |
1576dec7 | 8636 | c_parser_objc_method_type (c_parser *parser) |
8637 | { | |
8638 | switch (c_parser_peek_token (parser)->type) | |
8639 | { | |
8640 | case CPP_PLUS: | |
8641 | c_parser_consume_token (parser); | |
45b2b110 | 8642 | return true; |
1576dec7 | 8643 | case CPP_MINUS: |
8644 | c_parser_consume_token (parser); | |
45b2b110 | 8645 | return false; |
1576dec7 | 8646 | default: |
8647 | gcc_unreachable (); | |
8648 | } | |
8649 | } | |
8650 | ||
8651 | /* Parse an objc-method-definition. | |
8652 | ||
8653 | objc-method-definition: | |
8654 | objc-method-type objc-method-decl ;[opt] compound-statement | |
8655 | */ | |
8656 | ||
8657 | static void | |
8658 | c_parser_objc_method_definition (c_parser *parser) | |
8659 | { | |
45b2b110 | 8660 | bool is_class_method = c_parser_objc_method_type (parser); |
4232a958 | 8661 | tree decl, attributes = NULL_TREE, expr = NULL_TREE; |
920d59b0 | 8662 | parser->objc_pq_context = true; |
4232a958 | 8663 | decl = c_parser_objc_method_decl (parser, is_class_method, &attributes, |
8664 | &expr); | |
03fc2271 | 8665 | if (decl == error_mark_node) |
8666 | return; /* Bail here. */ | |
8667 | ||
1576dec7 | 8668 | if (c_parser_next_token_is (parser, CPP_SEMICOLON)) |
8669 | { | |
8670 | c_parser_consume_token (parser); | |
29438999 | 8671 | pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic, |
21ca8540 | 8672 | "extra semicolon in method definition specified"); |
1576dec7 | 8673 | } |
03fc2271 | 8674 | |
169987fa | 8675 | if (!c_parser_next_token_is (parser, CPP_OPEN_BRACE)) |
8676 | { | |
8677 | c_parser_error (parser, "expected %<{%>"); | |
8678 | return; | |
8679 | } | |
03fc2271 | 8680 | |
920d59b0 | 8681 | parser->objc_pq_context = false; |
4232a958 | 8682 | if (objc_start_method_definition (is_class_method, decl, attributes, expr)) |
d4a8fb25 | 8683 | { |
8684 | add_stmt (c_parser_compound_statement (parser)); | |
8685 | objc_finish_method_definition (current_function_decl); | |
8686 | } | |
8687 | else | |
8688 | { | |
8689 | /* This code is executed when we find a method definition | |
06517bd4 | 8690 | outside of an @implementation context (or invalid for other |
8691 | reasons). Parse the method (to keep going) but do not emit | |
8692 | any code. | |
d4a8fb25 | 8693 | */ |
8694 | c_parser_compound_statement (parser); | |
8695 | } | |
1576dec7 | 8696 | } |
8697 | ||
8698 | /* Parse an objc-methodprotolist. | |
8699 | ||
8700 | objc-methodprotolist: | |
8701 | empty | |
8702 | objc-methodprotolist objc-methodproto | |
8703 | objc-methodprotolist declaration | |
8704 | objc-methodprotolist ; | |
069761fb | 8705 | @optional |
8706 | @required | |
1576dec7 | 8707 | |
8708 | The declaration is a data definition, which may be missing | |
8709 | declaration specifiers under the same rules and diagnostics as | |
8710 | other data definitions outside functions, and the stray semicolon | |
8711 | is diagnosed the same way as a stray semicolon outside a | |
8712 | function. */ | |
8713 | ||
8714 | static void | |
8715 | c_parser_objc_methodprotolist (c_parser *parser) | |
8716 | { | |
8717 | while (true) | |
8718 | { | |
8719 | /* The list is terminated by @end. */ | |
8720 | switch (c_parser_peek_token (parser)->type) | |
8721 | { | |
8722 | case CPP_SEMICOLON: | |
29438999 | 8723 | pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic, |
21ca8540 | 8724 | "ISO C does not allow extra %<;%> outside of a function"); |
1576dec7 | 8725 | c_parser_consume_token (parser); |
8726 | break; | |
8727 | case CPP_PLUS: | |
8728 | case CPP_MINUS: | |
8729 | c_parser_objc_methodproto (parser); | |
8730 | break; | |
a2952f2e | 8731 | case CPP_PRAGMA: |
8732 | c_parser_pragma (parser, pragma_external); | |
8733 | break; | |
1576dec7 | 8734 | case CPP_EOF: |
8735 | return; | |
8736 | default: | |
8737 | if (c_parser_next_token_is_keyword (parser, RID_AT_END)) | |
8738 | return; | |
86c110ac | 8739 | else if (c_parser_next_token_is_keyword (parser, RID_AT_PROPERTY)) |
1d894bcf | 8740 | c_parser_objc_at_property_declaration (parser); |
069761fb | 8741 | else if (c_parser_next_token_is_keyword (parser, RID_AT_OPTIONAL)) |
8742 | { | |
8743 | objc_set_method_opt (true); | |
8744 | c_parser_consume_token (parser); | |
8745 | } | |
8746 | else if (c_parser_next_token_is_keyword (parser, RID_AT_REQUIRED)) | |
8747 | { | |
8748 | objc_set_method_opt (false); | |
8749 | c_parser_consume_token (parser); | |
8750 | } | |
8751 | else | |
8752 | c_parser_declaration_or_fndef (parser, false, false, true, | |
bc7bff74 | 8753 | false, true, NULL, vNULL); |
1576dec7 | 8754 | break; |
8755 | } | |
8756 | } | |
8757 | } | |
8758 | ||
8759 | /* Parse an objc-methodproto. | |
8760 | ||
8761 | objc-methodproto: | |
8762 | objc-method-type objc-method-decl ; | |
8763 | */ | |
8764 | ||
8765 | static void | |
8766 | c_parser_objc_methodproto (c_parser *parser) | |
8767 | { | |
45b2b110 | 8768 | bool is_class_method = c_parser_objc_method_type (parser); |
03fc2271 | 8769 | tree decl, attributes = NULL_TREE; |
45b2b110 | 8770 | |
1576dec7 | 8771 | /* Remember protocol qualifiers in prototypes. */ |
920d59b0 | 8772 | parser->objc_pq_context = true; |
4232a958 | 8773 | decl = c_parser_objc_method_decl (parser, is_class_method, &attributes, |
8774 | NULL); | |
03fc2271 | 8775 | /* Forget protocol qualifiers now. */ |
920d59b0 | 8776 | parser->objc_pq_context = false; |
03fc2271 | 8777 | |
8778 | /* Do not allow the presence of attributes to hide an erroneous | |
8779 | method implementation in the interface section. */ | |
8780 | if (!c_parser_next_token_is (parser, CPP_SEMICOLON)) | |
8781 | { | |
8782 | c_parser_error (parser, "expected %<;%>"); | |
8783 | return; | |
8784 | } | |
8785 | ||
8786 | if (decl != error_mark_node) | |
45b2b110 | 8787 | objc_add_method_declaration (is_class_method, decl, attributes); |
03fc2271 | 8788 | |
1576dec7 | 8789 | c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); |
8790 | } | |
8791 | ||
03fc2271 | 8792 | /* If we are at a position that method attributes may be present, check that |
8793 | there are not any parsed already (a syntax error) and then collect any | |
8794 | specified at the current location. Finally, if new attributes were present, | |
8795 | check that the next token is legal ( ';' for decls and '{' for defs). */ | |
8796 | ||
8797 | static bool | |
8798 | c_parser_objc_maybe_method_attributes (c_parser* parser, tree* attributes) | |
8799 | { | |
8800 | bool bad = false; | |
8801 | if (*attributes) | |
8802 | { | |
8803 | c_parser_error (parser, | |
8804 | "method attributes must be specified at the end only"); | |
8805 | *attributes = NULL_TREE; | |
8806 | bad = true; | |
8807 | } | |
8808 | ||
8809 | if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)) | |
8810 | *attributes = c_parser_attributes (parser); | |
8811 | ||
8812 | /* If there were no attributes here, just report any earlier error. */ | |
8813 | if (*attributes == NULL_TREE || bad) | |
8814 | return bad; | |
8815 | ||
8816 | /* If the attributes are followed by a ; or {, then just report any earlier | |
8817 | error. */ | |
8818 | if (c_parser_next_token_is (parser, CPP_SEMICOLON) | |
8819 | || c_parser_next_token_is (parser, CPP_OPEN_BRACE)) | |
8820 | return bad; | |
8821 | ||
8822 | /* We've got attributes, but not at the end. */ | |
8823 | c_parser_error (parser, | |
8824 | "expected %<;%> or %<{%> after method attribute definition"); | |
8825 | return true; | |
8826 | } | |
8827 | ||
1576dec7 | 8828 | /* Parse an objc-method-decl. |
8829 | ||
8830 | objc-method-decl: | |
8831 | ( objc-type-name ) objc-selector | |
8832 | objc-selector | |
8833 | ( objc-type-name ) objc-keyword-selector objc-optparmlist | |
8834 | objc-keyword-selector objc-optparmlist | |
03fc2271 | 8835 | attributes |
1576dec7 | 8836 | |
8837 | objc-keyword-selector: | |
8838 | objc-keyword-decl | |
8839 | objc-keyword-selector objc-keyword-decl | |
8840 | ||
8841 | objc-keyword-decl: | |
8842 | objc-selector : ( objc-type-name ) identifier | |
8843 | objc-selector : identifier | |
8844 | : ( objc-type-name ) identifier | |
8845 | : identifier | |
8846 | ||
8847 | objc-optparmlist: | |
8848 | objc-optparms objc-optellipsis | |
8849 | ||
8850 | objc-optparms: | |
8851 | empty | |
8852 | objc-opt-parms , parameter-declaration | |
8853 | ||
8854 | objc-optellipsis: | |
8855 | empty | |
8856 | , ... | |
8857 | */ | |
8858 | ||
8859 | static tree | |
4232a958 | 8860 | c_parser_objc_method_decl (c_parser *parser, bool is_class_method, |
8861 | tree *attributes, tree *expr) | |
1576dec7 | 8862 | { |
8863 | tree type = NULL_TREE; | |
8864 | tree sel; | |
8865 | tree parms = NULL_TREE; | |
450302fe | 8866 | bool ellipsis = false; |
03fc2271 | 8867 | bool attr_err = false; |
450302fe | 8868 | |
03fc2271 | 8869 | *attributes = NULL_TREE; |
1576dec7 | 8870 | if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) |
8871 | { | |
8872 | c_parser_consume_token (parser); | |
8873 | type = c_parser_objc_type_name (parser); | |
8874 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
8875 | } | |
8876 | sel = c_parser_objc_selector (parser); | |
8877 | /* If there is no selector, or a colon follows, we have an | |
8878 | objc-keyword-selector. If there is a selector, and a colon does | |
8879 | not follow, that selector ends the objc-method-decl. */ | |
8880 | if (!sel || c_parser_next_token_is (parser, CPP_COLON)) | |
8881 | { | |
8882 | tree tsel = sel; | |
8883 | tree list = NULL_TREE; | |
1576dec7 | 8884 | while (true) |
8885 | { | |
8886 | tree atype = NULL_TREE, id, keyworddecl; | |
03fc2271 | 8887 | tree param_attr = NULL_TREE; |
1576dec7 | 8888 | if (!c_parser_require (parser, CPP_COLON, "expected %<:%>")) |
8889 | break; | |
8890 | if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) | |
8891 | { | |
8892 | c_parser_consume_token (parser); | |
8893 | atype = c_parser_objc_type_name (parser); | |
8894 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, | |
8895 | "expected %<)%>"); | |
8896 | } | |
03fc2271 | 8897 | /* New ObjC allows attributes on method parameters. */ |
8898 | if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)) | |
8899 | param_attr = c_parser_attributes (parser); | |
1576dec7 | 8900 | if (c_parser_next_token_is_not (parser, CPP_NAME)) |
8901 | { | |
8902 | c_parser_error (parser, "expected identifier"); | |
8903 | return error_mark_node; | |
8904 | } | |
8905 | id = c_parser_peek_token (parser)->value; | |
8906 | c_parser_consume_token (parser); | |
03fc2271 | 8907 | keyworddecl = objc_build_keyword_decl (tsel, atype, id, param_attr); |
1576dec7 | 8908 | list = chainon (list, keyworddecl); |
8909 | tsel = c_parser_objc_selector (parser); | |
8910 | if (!tsel && c_parser_next_token_is_not (parser, CPP_COLON)) | |
8911 | break; | |
8912 | } | |
03fc2271 | 8913 | |
8914 | attr_err |= c_parser_objc_maybe_method_attributes (parser, attributes) ; | |
8915 | ||
1576dec7 | 8916 | /* Parse the optional parameter list. Optional Objective-C |
8917 | method parameters follow the C syntax, and may include '...' | |
8918 | to denote a variable number of arguments. */ | |
8919 | parms = make_node (TREE_LIST); | |
1576dec7 | 8920 | while (c_parser_next_token_is (parser, CPP_COMMA)) |
8921 | { | |
8922 | struct c_parm *parm; | |
8923 | c_parser_consume_token (parser); | |
8924 | if (c_parser_next_token_is (parser, CPP_ELLIPSIS)) | |
8925 | { | |
8926 | ellipsis = true; | |
8927 | c_parser_consume_token (parser); | |
03fc2271 | 8928 | attr_err |= c_parser_objc_maybe_method_attributes |
8929 | (parser, attributes) ; | |
1576dec7 | 8930 | break; |
8931 | } | |
8932 | parm = c_parser_parameter_declaration (parser, NULL_TREE); | |
8933 | if (parm == NULL) | |
8934 | break; | |
8935 | parms = chainon (parms, | |
4232a958 | 8936 | build_tree_list (NULL_TREE, grokparm (parm, expr))); |
1576dec7 | 8937 | } |
1576dec7 | 8938 | sel = list; |
8939 | } | |
03fc2271 | 8940 | else |
8941 | attr_err |= c_parser_objc_maybe_method_attributes (parser, attributes) ; | |
8942 | ||
8943 | if (sel == NULL) | |
8944 | { | |
8945 | c_parser_error (parser, "objective-c method declaration is expected"); | |
8946 | return error_mark_node; | |
8947 | } | |
8948 | ||
8949 | if (attr_err) | |
8950 | return error_mark_node; | |
8951 | ||
45b2b110 | 8952 | return objc_build_method_signature (is_class_method, type, sel, parms, ellipsis); |
1576dec7 | 8953 | } |
8954 | ||
8955 | /* Parse an objc-type-name. | |
8956 | ||
8957 | objc-type-name: | |
8958 | objc-type-qualifiers[opt] type-name | |
8959 | objc-type-qualifiers[opt] | |
8960 | ||
8961 | objc-type-qualifiers: | |
8962 | objc-type-qualifier | |
8963 | objc-type-qualifiers objc-type-qualifier | |
8964 | ||
8965 | objc-type-qualifier: one of | |
8966 | in out inout bycopy byref oneway | |
8967 | */ | |
8968 | ||
8969 | static tree | |
8970 | c_parser_objc_type_name (c_parser *parser) | |
8971 | { | |
8972 | tree quals = NULL_TREE; | |
7d339f93 | 8973 | struct c_type_name *type_name = NULL; |
1576dec7 | 8974 | tree type = NULL_TREE; |
8975 | while (true) | |
8976 | { | |
8977 | c_token *token = c_parser_peek_token (parser); | |
8978 | if (token->type == CPP_KEYWORD | |
8979 | && (token->keyword == RID_IN | |
8980 | || token->keyword == RID_OUT | |
8981 | || token->keyword == RID_INOUT | |
8982 | || token->keyword == RID_BYCOPY | |
8983 | || token->keyword == RID_BYREF | |
8984 | || token->keyword == RID_ONEWAY)) | |
8985 | { | |
dd26ec9b | 8986 | quals = chainon (build_tree_list (NULL_TREE, token->value), quals); |
1576dec7 | 8987 | c_parser_consume_token (parser); |
8988 | } | |
8989 | else | |
8990 | break; | |
8991 | } | |
26ee9e7a | 8992 | if (c_parser_next_tokens_start_typename (parser, cla_prefer_type)) |
7d339f93 | 8993 | type_name = c_parser_type_name (parser); |
8994 | if (type_name) | |
a75b1c71 | 8995 | type = groktypename (type_name, NULL, NULL); |
14a3bc63 | 8996 | |
8997 | /* If the type is unknown, and error has already been produced and | |
8998 | we need to recover from the error. In that case, use NULL_TREE | |
8999 | for the type, as if no type had been specified; this will use the | |
9000 | default type ('id') which is good for error recovery. */ | |
9001 | if (type == error_mark_node) | |
9002 | type = NULL_TREE; | |
9003 | ||
1576dec7 | 9004 | return build_tree_list (quals, type); |
9005 | } | |
9006 | ||
9007 | /* Parse objc-protocol-refs. | |
9008 | ||
9009 | objc-protocol-refs: | |
9010 | < identifier-list > | |
9011 | */ | |
9012 | ||
9013 | static tree | |
9014 | c_parser_objc_protocol_refs (c_parser *parser) | |
9015 | { | |
9016 | tree list = NULL_TREE; | |
9017 | gcc_assert (c_parser_next_token_is (parser, CPP_LESS)); | |
9018 | c_parser_consume_token (parser); | |
9019 | /* Any identifiers, including those declared as type names, are OK | |
9020 | here. */ | |
9021 | while (true) | |
9022 | { | |
9023 | tree id; | |
9024 | if (c_parser_next_token_is_not (parser, CPP_NAME)) | |
9025 | { | |
9026 | c_parser_error (parser, "expected identifier"); | |
9027 | break; | |
9028 | } | |
9029 | id = c_parser_peek_token (parser)->value; | |
9030 | list = chainon (list, build_tree_list (NULL_TREE, id)); | |
9031 | c_parser_consume_token (parser); | |
9032 | if (c_parser_next_token_is (parser, CPP_COMMA)) | |
9033 | c_parser_consume_token (parser); | |
9034 | else | |
9035 | break; | |
9036 | } | |
9037 | c_parser_require (parser, CPP_GREATER, "expected %<>%>"); | |
9038 | return list; | |
9039 | } | |
9040 | ||
b3d2d312 | 9041 | /* Parse an objc-try-catch-finally-statement. |
1576dec7 | 9042 | |
b3d2d312 | 9043 | objc-try-catch-finally-statement: |
1576dec7 | 9044 | @try compound-statement objc-catch-list[opt] |
9045 | @try compound-statement objc-catch-list[opt] @finally compound-statement | |
9046 | ||
9047 | objc-catch-list: | |
b3d2d312 | 9048 | @catch ( objc-catch-parameter-declaration ) compound-statement |
9049 | objc-catch-list @catch ( objc-catch-parameter-declaration ) compound-statement | |
9050 | ||
9051 | objc-catch-parameter-declaration: | |
9052 | parameter-declaration | |
9053 | '...' | |
9054 | ||
9055 | where '...' is to be interpreted literally, that is, it means CPP_ELLIPSIS. | |
9056 | ||
9057 | PS: This function is identical to cp_parser_objc_try_catch_finally_statement | |
9058 | for C++. Keep them in sync. */ | |
1576dec7 | 9059 | |
9060 | static void | |
b3d2d312 | 9061 | c_parser_objc_try_catch_finally_statement (c_parser *parser) |
1576dec7 | 9062 | { |
b3d2d312 | 9063 | location_t location; |
1576dec7 | 9064 | tree stmt; |
b3d2d312 | 9065 | |
e5c75ac3 | 9066 | gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_TRY)); |
1576dec7 | 9067 | c_parser_consume_token (parser); |
b3d2d312 | 9068 | location = c_parser_peek_token (parser)->location; |
33b3681f | 9069 | objc_maybe_warn_exceptions (location); |
1576dec7 | 9070 | stmt = c_parser_compound_statement (parser); |
b3d2d312 | 9071 | objc_begin_try_stmt (location, stmt); |
9072 | ||
e5c75ac3 | 9073 | while (c_parser_next_token_is_keyword (parser, RID_AT_CATCH)) |
1576dec7 | 9074 | { |
9075 | struct c_parm *parm; | |
b3d2d312 | 9076 | tree parameter_declaration = error_mark_node; |
9077 | bool seen_open_paren = false; | |
9078 | ||
1576dec7 | 9079 | c_parser_consume_token (parser); |
9080 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
b3d2d312 | 9081 | seen_open_paren = true; |
9082 | if (c_parser_next_token_is (parser, CPP_ELLIPSIS)) | |
1576dec7 | 9083 | { |
b3d2d312 | 9084 | /* We have "@catch (...)" (where the '...' are literally |
9085 | what is in the code). Skip the '...'. | |
9086 | parameter_declaration is set to NULL_TREE, and | |
9087 | objc_being_catch_clauses() knows that that means | |
9088 | '...'. */ | |
9089 | c_parser_consume_token (parser); | |
9090 | parameter_declaration = NULL_TREE; | |
1576dec7 | 9091 | } |
b3d2d312 | 9092 | else |
9093 | { | |
9094 | /* We have "@catch (NSException *exception)" or something | |
9095 | like that. Parse the parameter declaration. */ | |
9096 | parm = c_parser_parameter_declaration (parser, NULL_TREE); | |
9097 | if (parm == NULL) | |
9098 | parameter_declaration = error_mark_node; | |
9099 | else | |
4232a958 | 9100 | parameter_declaration = grokparm (parm, NULL); |
b3d2d312 | 9101 | } |
9102 | if (seen_open_paren) | |
9103 | c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
9104 | else | |
9105 | { | |
9106 | /* If there was no open parenthesis, we are recovering from | |
9107 | an error, and we are trying to figure out what mistake | |
9108 | the user has made. */ | |
9109 | ||
9110 | /* If there is an immediate closing parenthesis, the user | |
9111 | probably forgot the opening one (ie, they typed "@catch | |
9112 | NSException *e)". Parse the closing parenthesis and keep | |
9113 | going. */ | |
9114 | if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) | |
9115 | c_parser_consume_token (parser); | |
9116 | ||
9117 | /* If these is no immediate closing parenthesis, the user | |
9118 | probably doesn't know that parenthesis are required at | |
9119 | all (ie, they typed "@catch NSException *e"). So, just | |
9120 | forget about the closing parenthesis and keep going. */ | |
9121 | } | |
9122 | objc_begin_catch_clause (parameter_declaration); | |
1576dec7 | 9123 | if (c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>")) |
9124 | c_parser_compound_statement_nostart (parser); | |
9125 | objc_finish_catch_clause (); | |
9126 | } | |
9127 | if (c_parser_next_token_is_keyword (parser, RID_AT_FINALLY)) | |
9128 | { | |
1576dec7 | 9129 | c_parser_consume_token (parser); |
b3d2d312 | 9130 | location = c_parser_peek_token (parser)->location; |
9131 | stmt = c_parser_compound_statement (parser); | |
9132 | objc_build_finally_clause (location, stmt); | |
1576dec7 | 9133 | } |
9134 | objc_finish_try_stmt (); | |
9135 | } | |
9136 | ||
9137 | /* Parse an objc-synchronized-statement. | |
9138 | ||
9139 | objc-synchronized-statement: | |
9140 | @synchronized ( expression ) compound-statement | |
9141 | */ | |
9142 | ||
9143 | static void | |
9144 | c_parser_objc_synchronized_statement (c_parser *parser) | |
9145 | { | |
9146 | location_t loc; | |
9147 | tree expr, stmt; | |
9148 | gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_SYNCHRONIZED)); | |
9149 | c_parser_consume_token (parser); | |
9150 | loc = c_parser_peek_token (parser)->location; | |
33b3681f | 9151 | objc_maybe_warn_exceptions (loc); |
1576dec7 | 9152 | if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) |
9153 | { | |
b560fabd | 9154 | struct c_expr ce = c_parser_expression (parser); |
9155 | ce = convert_lvalue_to_rvalue (loc, ce, false, false); | |
9156 | expr = ce.value; | |
a75b1c71 | 9157 | expr = c_fully_fold (expr, false, NULL); |
1576dec7 | 9158 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); |
9159 | } | |
9160 | else | |
9161 | expr = error_mark_node; | |
9162 | stmt = c_parser_compound_statement (parser); | |
9163 | objc_build_synchronized (loc, expr, stmt); | |
9164 | } | |
9165 | ||
9166 | /* Parse an objc-selector; return NULL_TREE without an error if the | |
9167 | next token is not an objc-selector. | |
9168 | ||
9169 | objc-selector: | |
9170 | identifier | |
9171 | one of | |
9172 | enum struct union if else while do for switch case default | |
9173 | break continue return goto asm sizeof typeof __alignof | |
9174 | unsigned long const short volatile signed restrict _Complex | |
9175 | in out inout bycopy byref oneway int char float double void _Bool | |
b560fabd | 9176 | _Atomic |
1576dec7 | 9177 | |
9178 | ??? Why this selection of keywords but not, for example, storage | |
9179 | class specifiers? */ | |
9180 | ||
9181 | static tree | |
9182 | c_parser_objc_selector (c_parser *parser) | |
9183 | { | |
9184 | c_token *token = c_parser_peek_token (parser); | |
9185 | tree value = token->value; | |
9186 | if (token->type == CPP_NAME) | |
9187 | { | |
9188 | c_parser_consume_token (parser); | |
9189 | return value; | |
9190 | } | |
9191 | if (token->type != CPP_KEYWORD) | |
9192 | return NULL_TREE; | |
9193 | switch (token->keyword) | |
9194 | { | |
9195 | case RID_ENUM: | |
9196 | case RID_STRUCT: | |
9197 | case RID_UNION: | |
9198 | case RID_IF: | |
9199 | case RID_ELSE: | |
9200 | case RID_WHILE: | |
9201 | case RID_DO: | |
9202 | case RID_FOR: | |
9203 | case RID_SWITCH: | |
9204 | case RID_CASE: | |
9205 | case RID_DEFAULT: | |
9206 | case RID_BREAK: | |
9207 | case RID_CONTINUE: | |
9208 | case RID_RETURN: | |
9209 | case RID_GOTO: | |
9210 | case RID_ASM: | |
9211 | case RID_SIZEOF: | |
9212 | case RID_TYPEOF: | |
9213 | case RID_ALIGNOF: | |
9214 | case RID_UNSIGNED: | |
9215 | case RID_LONG: | |
9216 | case RID_CONST: | |
9217 | case RID_SHORT: | |
9218 | case RID_VOLATILE: | |
9219 | case RID_SIGNED: | |
9220 | case RID_RESTRICT: | |
9221 | case RID_COMPLEX: | |
9222 | case RID_IN: | |
9223 | case RID_OUT: | |
9224 | case RID_INOUT: | |
9225 | case RID_BYCOPY: | |
9226 | case RID_BYREF: | |
9227 | case RID_ONEWAY: | |
9228 | case RID_INT: | |
9229 | case RID_CHAR: | |
9230 | case RID_FLOAT: | |
9231 | case RID_DOUBLE: | |
9232 | case RID_VOID: | |
9233 | case RID_BOOL: | |
b560fabd | 9234 | case RID_ATOMIC: |
4fba5eb9 | 9235 | case RID_AUTO_TYPE: |
9f75f026 | 9236 | case RID_INT_N_0: |
9237 | case RID_INT_N_1: | |
9238 | case RID_INT_N_2: | |
9239 | case RID_INT_N_3: | |
1576dec7 | 9240 | c_parser_consume_token (parser); |
9241 | return value; | |
9242 | default: | |
9243 | return NULL_TREE; | |
9244 | } | |
9245 | } | |
9246 | ||
9247 | /* Parse an objc-selector-arg. | |
9248 | ||
9249 | objc-selector-arg: | |
9250 | objc-selector | |
9251 | objc-keywordname-list | |
9252 | ||
9253 | objc-keywordname-list: | |
9254 | objc-keywordname | |
9255 | objc-keywordname-list objc-keywordname | |
9256 | ||
9257 | objc-keywordname: | |
9258 | objc-selector : | |
9259 | : | |
9260 | */ | |
9261 | ||
9262 | static tree | |
9263 | c_parser_objc_selector_arg (c_parser *parser) | |
9264 | { | |
9265 | tree sel = c_parser_objc_selector (parser); | |
9266 | tree list = NULL_TREE; | |
9267 | if (sel && c_parser_next_token_is_not (parser, CPP_COLON)) | |
9268 | return sel; | |
9269 | while (true) | |
9270 | { | |
9271 | if (!c_parser_require (parser, CPP_COLON, "expected %<:%>")) | |
9272 | return list; | |
9273 | list = chainon (list, build_tree_list (sel, NULL_TREE)); | |
9274 | sel = c_parser_objc_selector (parser); | |
9275 | if (!sel && c_parser_next_token_is_not (parser, CPP_COLON)) | |
9276 | break; | |
9277 | } | |
9278 | return list; | |
9279 | } | |
9280 | ||
9281 | /* Parse an objc-receiver. | |
9282 | ||
9283 | objc-receiver: | |
9284 | expression | |
9285 | class-name | |
9286 | type-name | |
9287 | */ | |
9288 | ||
9289 | static tree | |
9290 | c_parser_objc_receiver (c_parser *parser) | |
9291 | { | |
b560fabd | 9292 | location_t loc = c_parser_peek_token (parser)->location; |
9293 | ||
1576dec7 | 9294 | if (c_parser_peek_token (parser)->type == CPP_NAME |
9295 | && (c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME | |
9296 | || c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME)) | |
9297 | { | |
9298 | tree id = c_parser_peek_token (parser)->value; | |
9299 | c_parser_consume_token (parser); | |
9300 | return objc_get_class_reference (id); | |
9301 | } | |
b560fabd | 9302 | struct c_expr ce = c_parser_expression (parser); |
9303 | ce = convert_lvalue_to_rvalue (loc, ce, false, false); | |
9304 | return c_fully_fold (ce.value, false, NULL); | |
1576dec7 | 9305 | } |
9306 | ||
9307 | /* Parse objc-message-args. | |
9308 | ||
9309 | objc-message-args: | |
9310 | objc-selector | |
9311 | objc-keywordarg-list | |
9312 | ||
9313 | objc-keywordarg-list: | |
9314 | objc-keywordarg | |
9315 | objc-keywordarg-list objc-keywordarg | |
9316 | ||
9317 | objc-keywordarg: | |
9318 | objc-selector : objc-keywordexpr | |
9319 | : objc-keywordexpr | |
9320 | */ | |
9321 | ||
9322 | static tree | |
9323 | c_parser_objc_message_args (c_parser *parser) | |
9324 | { | |
9325 | tree sel = c_parser_objc_selector (parser); | |
9326 | tree list = NULL_TREE; | |
9327 | if (sel && c_parser_next_token_is_not (parser, CPP_COLON)) | |
9328 | return sel; | |
9329 | while (true) | |
9330 | { | |
9331 | tree keywordexpr; | |
9332 | if (!c_parser_require (parser, CPP_COLON, "expected %<:%>")) | |
61a9d3ca | 9333 | return error_mark_node; |
1576dec7 | 9334 | keywordexpr = c_parser_objc_keywordexpr (parser); |
9335 | list = chainon (list, build_tree_list (sel, keywordexpr)); | |
9336 | sel = c_parser_objc_selector (parser); | |
9337 | if (!sel && c_parser_next_token_is_not (parser, CPP_COLON)) | |
9338 | break; | |
9339 | } | |
9340 | return list; | |
9341 | } | |
9342 | ||
9343 | /* Parse an objc-keywordexpr. | |
9344 | ||
9345 | objc-keywordexpr: | |
9346 | nonempty-expr-list | |
9347 | */ | |
9348 | ||
9349 | static tree | |
9350 | c_parser_objc_keywordexpr (c_parser *parser) | |
9351 | { | |
b9c74b4d | 9352 | tree ret; |
f1f41a6c | 9353 | vec<tree, va_gc> *expr_list = c_parser_expr_list (parser, true, true, |
ec761d5a | 9354 | NULL, NULL, NULL, NULL); |
f1f41a6c | 9355 | if (vec_safe_length (expr_list) == 1) |
1576dec7 | 9356 | { |
9357 | /* Just return the expression, remove a level of | |
9358 | indirection. */ | |
f1f41a6c | 9359 | ret = (*expr_list)[0]; |
1576dec7 | 9360 | } |
9361 | else | |
9362 | { | |
9363 | /* We have a comma expression, we will collapse later. */ | |
f352a3fb | 9364 | ret = build_tree_list_vec (expr_list); |
1576dec7 | 9365 | } |
f352a3fb | 9366 | release_tree_vector (expr_list); |
b9c74b4d | 9367 | return ret; |
1576dec7 | 9368 | } |
9369 | ||
a336eb4b | 9370 | /* A check, needed in several places, that ObjC interface, implementation or |
9371 | method definitions are not prefixed by incorrect items. */ | |
9372 | static bool | |
9373 | c_parser_objc_diagnose_bad_element_prefix (c_parser *parser, | |
9374 | struct c_declspecs *specs) | |
9375 | { | |
ae5ead32 | 9376 | if (!specs->declspecs_seen_p || specs->non_sc_seen_p |
9377 | || specs->typespec_kind != ctsk_none) | |
a336eb4b | 9378 | { |
9379 | c_parser_error (parser, | |
9380 | "no type or storage class may be specified here,"); | |
9381 | c_parser_skip_to_end_of_block_or_statement (parser); | |
9382 | return true; | |
9383 | } | |
9384 | return false; | |
9385 | } | |
86c110ac | 9386 | |
1d894bcf | 9387 | /* Parse an Objective-C @property declaration. The syntax is: |
86c110ac | 9388 | |
1d894bcf | 9389 | objc-property-declaration: |
9390 | '@property' objc-property-attributes[opt] struct-declaration ; | |
86c110ac | 9391 | |
1d894bcf | 9392 | objc-property-attributes: |
9393 | '(' objc-property-attribute-list ')' | |
9394 | ||
9395 | objc-property-attribute-list: | |
9396 | objc-property-attribute | |
9397 | objc-property-attribute-list, objc-property-attribute | |
9398 | ||
9399 | objc-property-attribute | |
9400 | 'getter' = identifier | |
9401 | 'setter' = identifier | |
9402 | 'readonly' | |
9403 | 'readwrite' | |
9404 | 'assign' | |
9405 | 'retain' | |
9406 | 'copy' | |
9407 | 'nonatomic' | |
9408 | ||
9409 | For example: | |
9410 | @property NSString *name; | |
9411 | @property (readonly) id object; | |
9412 | @property (retain, nonatomic, getter=getTheName) id name; | |
9413 | @property int a, b, c; | |
9414 | ||
9415 | PS: This function is identical to cp_parser_objc_at_propery_declaration | |
7590f0e5 | 9416 | for C++. Keep them in sync. */ |
86c110ac | 9417 | static void |
1d894bcf | 9418 | c_parser_objc_at_property_declaration (c_parser *parser) |
86c110ac | 9419 | { |
7590f0e5 | 9420 | /* The following variables hold the attributes of the properties as |
9421 | parsed. They are 'false' or 'NULL_TREE' if the attribute was not | |
9422 | seen. When we see an attribute, we set them to 'true' (if they | |
9423 | are boolean properties) or to the identifier (if they have an | |
9424 | argument, ie, for getter and setter). Note that here we only | |
9425 | parse the list of attributes, check the syntax and accumulate the | |
9426 | attributes that we find. objc_add_property_declaration() will | |
9427 | then process the information. */ | |
9428 | bool property_assign = false; | |
9429 | bool property_copy = false; | |
9430 | tree property_getter_ident = NULL_TREE; | |
9431 | bool property_nonatomic = false; | |
9432 | bool property_readonly = false; | |
9433 | bool property_readwrite = false; | |
9434 | bool property_retain = false; | |
9435 | tree property_setter_ident = NULL_TREE; | |
7590f0e5 | 9436 | |
9437 | /* 'properties' is the list of properties that we read. Usually a | |
9438 | single one, but maybe more (eg, in "@property int a, b, c;" there | |
9439 | are three). */ | |
1d894bcf | 9440 | tree properties; |
9441 | location_t loc; | |
7590f0e5 | 9442 | |
1d894bcf | 9443 | loc = c_parser_peek_token (parser)->location; |
9444 | gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_PROPERTY)); | |
86c110ac | 9445 | |
1d894bcf | 9446 | c_parser_consume_token (parser); /* Eat '@property'. */ |
86c110ac | 9447 | |
1d894bcf | 9448 | /* Parse the optional attribute list... */ |
9449 | if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) | |
86c110ac | 9450 | { |
1d894bcf | 9451 | /* Eat the '(' */ |
9452 | c_parser_consume_token (parser); | |
9453 | ||
9454 | /* Property attribute keywords are valid now. */ | |
9455 | parser->objc_property_attr_context = true; | |
9456 | ||
9457 | while (true) | |
86c110ac | 9458 | { |
1d894bcf | 9459 | bool syntax_error = false; |
9460 | c_token *token = c_parser_peek_token (parser); | |
9461 | enum rid keyword; | |
9462 | ||
9463 | if (token->type != CPP_KEYWORD) | |
9464 | { | |
9465 | if (token->type == CPP_CLOSE_PAREN) | |
9466 | c_parser_error (parser, "expected identifier"); | |
9467 | else | |
9468 | { | |
9469 | c_parser_consume_token (parser); | |
9470 | c_parser_error (parser, "unknown property attribute"); | |
9471 | } | |
9472 | break; | |
9473 | } | |
9474 | keyword = token->keyword; | |
7590f0e5 | 9475 | c_parser_consume_token (parser); |
1d894bcf | 9476 | switch (keyword) |
9477 | { | |
7590f0e5 | 9478 | case RID_ASSIGN: property_assign = true; break; |
7590f0e5 | 9479 | case RID_COPY: property_copy = true; break; |
9480 | case RID_NONATOMIC: property_nonatomic = true; break; | |
9481 | case RID_READONLY: property_readonly = true; break; | |
9482 | case RID_READWRITE: property_readwrite = true; break; | |
9483 | case RID_RETAIN: property_retain = true; break; | |
9484 | ||
1d894bcf | 9485 | case RID_GETTER: |
9486 | case RID_SETTER: | |
1d894bcf | 9487 | if (c_parser_next_token_is_not (parser, CPP_EQ)) |
9488 | { | |
ffbb3d61 | 9489 | if (keyword == RID_GETTER) |
9490 | c_parser_error (parser, | |
9491 | "missing %<=%> (after %<getter%> attribute)"); | |
9492 | else | |
9493 | c_parser_error (parser, | |
9494 | "missing %<=%> (after %<setter%> attribute)"); | |
1d894bcf | 9495 | syntax_error = true; |
9496 | break; | |
9497 | } | |
9498 | c_parser_consume_token (parser); /* eat the = */ | |
9499 | if (c_parser_next_token_is_not (parser, CPP_NAME)) | |
9500 | { | |
9501 | c_parser_error (parser, "expected identifier"); | |
9502 | syntax_error = true; | |
9503 | break; | |
9504 | } | |
1d894bcf | 9505 | if (keyword == RID_SETTER) |
9506 | { | |
7590f0e5 | 9507 | if (property_setter_ident != NULL_TREE) |
9508 | c_parser_error (parser, "the %<setter%> attribute may only be specified once"); | |
9509 | else | |
9510 | property_setter_ident = c_parser_peek_token (parser)->value; | |
1d894bcf | 9511 | c_parser_consume_token (parser); |
7590f0e5 | 9512 | if (c_parser_next_token_is_not (parser, CPP_COLON)) |
9513 | c_parser_error (parser, "setter name must terminate with %<:%>"); | |
9514 | else | |
9515 | c_parser_consume_token (parser); | |
1d894bcf | 9516 | } |
9d9f5bb3 | 9517 | else |
1d894bcf | 9518 | { |
7590f0e5 | 9519 | if (property_getter_ident != NULL_TREE) |
9520 | c_parser_error (parser, "the %<getter%> attribute may only be specified once"); | |
9521 | else | |
9522 | property_getter_ident = c_parser_peek_token (parser)->value; | |
1d894bcf | 9523 | c_parser_consume_token (parser); |
1d894bcf | 9524 | } |
7590f0e5 | 9525 | break; |
9526 | default: | |
9527 | c_parser_error (parser, "unknown property attribute"); | |
1d894bcf | 9528 | syntax_error = true; |
9529 | break; | |
9530 | } | |
9531 | ||
9532 | if (syntax_error) | |
86c110ac | 9533 | break; |
1d894bcf | 9534 | |
9535 | if (c_parser_next_token_is (parser, CPP_COMMA)) | |
86c110ac | 9536 | c_parser_consume_token (parser); |
1d894bcf | 9537 | else |
86c110ac | 9538 | break; |
9539 | } | |
1d894bcf | 9540 | parser->objc_property_attr_context = false; |
9541 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
9542 | } | |
9543 | /* ... and the property declaration(s). */ | |
9544 | properties = c_parser_struct_declaration (parser); | |
86c110ac | 9545 | |
1d894bcf | 9546 | if (properties == error_mark_node) |
9547 | { | |
9548 | c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL); | |
9549 | parser->error = false; | |
9550 | return; | |
9551 | } | |
86c110ac | 9552 | |
1d894bcf | 9553 | if (properties == NULL_TREE) |
9554 | c_parser_error (parser, "expected identifier"); | |
9555 | else | |
9556 | { | |
9557 | /* Comma-separated properties are chained together in | |
9558 | reverse order; add them one by one. */ | |
9559 | properties = nreverse (properties); | |
9560 | ||
9561 | for (; properties; properties = TREE_CHAIN (properties)) | |
7590f0e5 | 9562 | objc_add_property_declaration (loc, copy_node (properties), |
9563 | property_readonly, property_readwrite, | |
9564 | property_assign, property_retain, | |
9565 | property_copy, property_nonatomic, | |
9d9f5bb3 | 9566 | property_getter_ident, property_setter_ident); |
1d894bcf | 9567 | } |
86c110ac | 9568 | |
9569 | c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); | |
1d894bcf | 9570 | parser->error = false; |
86c110ac | 9571 | } |
9572 | ||
e1f293c0 | 9573 | /* Parse an Objective-C @synthesize declaration. The syntax is: |
9574 | ||
9575 | objc-synthesize-declaration: | |
9576 | @synthesize objc-synthesize-identifier-list ; | |
9577 | ||
9578 | objc-synthesize-identifier-list: | |
9579 | objc-synthesize-identifier | |
9580 | objc-synthesize-identifier-list, objc-synthesize-identifier | |
9581 | ||
9582 | objc-synthesize-identifier | |
9583 | identifier | |
9584 | identifier = identifier | |
9585 | ||
9586 | For example: | |
9587 | @synthesize MyProperty; | |
9588 | @synthesize OneProperty, AnotherProperty=MyIvar, YetAnotherProperty; | |
9589 | ||
9590 | PS: This function is identical to cp_parser_objc_at_synthesize_declaration | |
9591 | for C++. Keep them in sync. | |
9592 | */ | |
9593 | static void | |
9594 | c_parser_objc_at_synthesize_declaration (c_parser *parser) | |
9595 | { | |
9596 | tree list = NULL_TREE; | |
9597 | location_t loc; | |
9598 | gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_SYNTHESIZE)); | |
9599 | loc = c_parser_peek_token (parser)->location; | |
9600 | ||
9601 | c_parser_consume_token (parser); | |
9602 | while (true) | |
9603 | { | |
9604 | tree property, ivar; | |
9605 | if (c_parser_next_token_is_not (parser, CPP_NAME)) | |
9606 | { | |
9607 | c_parser_error (parser, "expected identifier"); | |
9608 | c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL); | |
9609 | /* Once we find the semicolon, we can resume normal parsing. | |
9610 | We have to reset parser->error manually because | |
9611 | c_parser_skip_until_found() won't reset it for us if the | |
9612 | next token is precisely a semicolon. */ | |
9613 | parser->error = false; | |
9614 | return; | |
9615 | } | |
9616 | property = c_parser_peek_token (parser)->value; | |
9617 | c_parser_consume_token (parser); | |
9618 | if (c_parser_next_token_is (parser, CPP_EQ)) | |
9619 | { | |
9620 | c_parser_consume_token (parser); | |
9621 | if (c_parser_next_token_is_not (parser, CPP_NAME)) | |
9622 | { | |
9623 | c_parser_error (parser, "expected identifier"); | |
9624 | c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL); | |
9625 | parser->error = false; | |
9626 | return; | |
9627 | } | |
9628 | ivar = c_parser_peek_token (parser)->value; | |
9629 | c_parser_consume_token (parser); | |
9630 | } | |
9631 | else | |
9632 | ivar = NULL_TREE; | |
9633 | list = chainon (list, build_tree_list (ivar, property)); | |
9634 | if (c_parser_next_token_is (parser, CPP_COMMA)) | |
9635 | c_parser_consume_token (parser); | |
9636 | else | |
9637 | break; | |
9638 | } | |
9639 | c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); | |
9640 | objc_add_synthesize_declaration (loc, list); | |
9641 | } | |
9642 | ||
9643 | /* Parse an Objective-C @dynamic declaration. The syntax is: | |
9644 | ||
9645 | objc-dynamic-declaration: | |
9646 | @dynamic identifier-list ; | |
9647 | ||
9648 | For example: | |
9649 | @dynamic MyProperty; | |
9650 | @dynamic MyProperty, AnotherProperty; | |
9651 | ||
9652 | PS: This function is identical to cp_parser_objc_at_dynamic_declaration | |
9653 | for C++. Keep them in sync. | |
9654 | */ | |
9655 | static void | |
9656 | c_parser_objc_at_dynamic_declaration (c_parser *parser) | |
9657 | { | |
9658 | tree list = NULL_TREE; | |
9659 | location_t loc; | |
9660 | gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_DYNAMIC)); | |
9661 | loc = c_parser_peek_token (parser)->location; | |
9662 | ||
9663 | c_parser_consume_token (parser); | |
9664 | while (true) | |
9665 | { | |
9666 | tree property; | |
9667 | if (c_parser_next_token_is_not (parser, CPP_NAME)) | |
9668 | { | |
9669 | c_parser_error (parser, "expected identifier"); | |
9670 | c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL); | |
9671 | parser->error = false; | |
9672 | return; | |
9673 | } | |
9674 | property = c_parser_peek_token (parser)->value; | |
9675 | list = chainon (list, build_tree_list (NULL_TREE, property)); | |
9676 | c_parser_consume_token (parser); | |
9677 | if (c_parser_next_token_is (parser, CPP_COMMA)) | |
9678 | c_parser_consume_token (parser); | |
9679 | else | |
9680 | break; | |
9681 | } | |
9682 | c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); | |
9683 | objc_add_dynamic_declaration (loc, list); | |
9684 | } | |
9685 | ||
1576dec7 | 9686 | \f |
1e8e9920 | 9687 | /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore |
9688 | should be considered, statements. ALLOW_STMT is true if we're within | |
9689 | the context of a function and such pragmas are to be allowed. Returns | |
9690 | true if we actually parsed such a pragma. */ | |
1576dec7 | 9691 | |
b75b98aa | 9692 | static bool |
1e8e9920 | 9693 | c_parser_pragma (c_parser *parser, enum pragma_context context) |
b75b98aa | 9694 | { |
9695 | unsigned int id; | |
9696 | ||
9697 | id = c_parser_peek_token (parser)->pragma_kind; | |
9698 | gcc_assert (id != PRAGMA_NONE); | |
9699 | ||
9700 | switch (id) | |
9701 | { | |
ca4c3545 | 9702 | case PRAGMA_OACC_ENTER_DATA: |
9703 | c_parser_oacc_enter_exit_data (parser, true); | |
9704 | return false; | |
9705 | ||
9706 | case PRAGMA_OACC_EXIT_DATA: | |
9707 | c_parser_oacc_enter_exit_data (parser, false); | |
9708 | return false; | |
9709 | ||
9710 | case PRAGMA_OACC_UPDATE: | |
9711 | if (context != pragma_compound) | |
9712 | { | |
9713 | if (context == pragma_stmt) | |
9714 | c_parser_error (parser, "%<#pragma acc update%> may only be " | |
9715 | "used in compound statements"); | |
9716 | goto bad_stmt; | |
9717 | } | |
9718 | c_parser_oacc_update (parser); | |
9719 | return false; | |
9720 | ||
1e8e9920 | 9721 | case PRAGMA_OMP_BARRIER: |
9722 | if (context != pragma_compound) | |
9723 | { | |
9724 | if (context == pragma_stmt) | |
9725 | c_parser_error (parser, "%<#pragma omp barrier%> may only be " | |
9726 | "used in compound statements"); | |
9727 | goto bad_stmt; | |
9728 | } | |
9729 | c_parser_omp_barrier (parser); | |
9730 | return false; | |
9731 | ||
9732 | case PRAGMA_OMP_FLUSH: | |
9733 | if (context != pragma_compound) | |
9734 | { | |
9735 | if (context == pragma_stmt) | |
9736 | c_parser_error (parser, "%<#pragma omp flush%> may only be " | |
9737 | "used in compound statements"); | |
9738 | goto bad_stmt; | |
9739 | } | |
9740 | c_parser_omp_flush (parser); | |
9741 | return false; | |
9742 | ||
fd6481cf | 9743 | case PRAGMA_OMP_TASKWAIT: |
9744 | if (context != pragma_compound) | |
9745 | { | |
9746 | if (context == pragma_stmt) | |
9747 | c_parser_error (parser, "%<#pragma omp taskwait%> may only be " | |
9748 | "used in compound statements"); | |
9749 | goto bad_stmt; | |
9750 | } | |
9751 | c_parser_omp_taskwait (parser); | |
9752 | return false; | |
9753 | ||
2169f33b | 9754 | case PRAGMA_OMP_TASKYIELD: |
9755 | if (context != pragma_compound) | |
9756 | { | |
9757 | if (context == pragma_stmt) | |
9758 | c_parser_error (parser, "%<#pragma omp taskyield%> may only be " | |
9759 | "used in compound statements"); | |
9760 | goto bad_stmt; | |
9761 | } | |
9762 | c_parser_omp_taskyield (parser); | |
9763 | return false; | |
9764 | ||
bc7bff74 | 9765 | case PRAGMA_OMP_CANCEL: |
9766 | if (context != pragma_compound) | |
9767 | { | |
9768 | if (context == pragma_stmt) | |
9769 | c_parser_error (parser, "%<#pragma omp cancel%> may only be " | |
9770 | "used in compound statements"); | |
9771 | goto bad_stmt; | |
9772 | } | |
9773 | c_parser_omp_cancel (parser); | |
9774 | return false; | |
9775 | ||
9776 | case PRAGMA_OMP_CANCELLATION_POINT: | |
9777 | if (context != pragma_compound) | |
9778 | { | |
9779 | if (context == pragma_stmt) | |
9780 | c_parser_error (parser, "%<#pragma omp cancellation point%> may " | |
9781 | "only be used in compound statements"); | |
9782 | goto bad_stmt; | |
9783 | } | |
9784 | c_parser_omp_cancellation_point (parser); | |
9785 | return false; | |
9786 | ||
1e8e9920 | 9787 | case PRAGMA_OMP_THREADPRIVATE: |
9788 | c_parser_omp_threadprivate (parser); | |
9789 | return false; | |
9790 | ||
bc7bff74 | 9791 | case PRAGMA_OMP_TARGET: |
9792 | return c_parser_omp_target (parser, context); | |
9793 | ||
9794 | case PRAGMA_OMP_END_DECLARE_TARGET: | |
9795 | c_parser_omp_end_declare_target (parser); | |
9796 | return false; | |
9797 | ||
1e8e9920 | 9798 | case PRAGMA_OMP_SECTION: |
e3b80d49 | 9799 | error_at (c_parser_peek_token (parser)->location, |
9800 | "%<#pragma omp section%> may only be used in " | |
9801 | "%<#pragma omp sections%> construct"); | |
1e8e9920 | 9802 | c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL); |
9803 | return false; | |
9804 | ||
bc7bff74 | 9805 | case PRAGMA_OMP_DECLARE_REDUCTION: |
9806 | c_parser_omp_declare (parser, context); | |
9807 | return false; | |
43895be5 | 9808 | |
9809 | case PRAGMA_OMP_ORDERED: | |
9810 | return c_parser_omp_ordered (parser, context); | |
9811 | ||
4644b593 | 9812 | case PRAGMA_IVDEP: |
9813 | c_parser_consume_pragma (parser); | |
9814 | c_parser_skip_to_pragma_eol (parser); | |
4c90c04c | 9815 | if (!c_parser_next_token_is_keyword (parser, RID_FOR) |
9816 | && !c_parser_next_token_is_keyword (parser, RID_WHILE) | |
9817 | && !c_parser_next_token_is_keyword (parser, RID_DO)) | |
4644b593 | 9818 | { |
4c90c04c | 9819 | c_parser_error (parser, "for, while or do statement expected"); |
4644b593 | 9820 | return false; |
9821 | } | |
4c90c04c | 9822 | if (c_parser_next_token_is_keyword (parser, RID_FOR)) |
9823 | c_parser_for_statement (parser, true); | |
9824 | else if (c_parser_next_token_is_keyword (parser, RID_WHILE)) | |
9825 | c_parser_while_statement (parser, true); | |
9826 | else | |
9827 | c_parser_do_statement (parser, true); | |
4644b593 | 9828 | return false; |
bc7bff74 | 9829 | |
b75b98aa | 9830 | case PRAGMA_GCC_PCH_PREPROCESS: |
9831 | c_parser_error (parser, "%<#pragma GCC pch_preprocess%> must be first"); | |
9832 | c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL); | |
9833 | return false; | |
9834 | ||
f2697631 | 9835 | case PRAGMA_CILK_SIMD: |
9836 | if (!c_parser_cilk_verify_simd (parser, context)) | |
9837 | return false; | |
9838 | c_parser_consume_pragma (parser); | |
9839 | c_parser_cilk_simd (parser); | |
9840 | return false; | |
40750995 | 9841 | case PRAGMA_CILK_GRAINSIZE: |
9842 | if (!flag_cilkplus) | |
9843 | { | |
9844 | warning (0, "%<#pragma grainsize%> ignored because -fcilkplus is not" | |
9845 | " enabled"); | |
9846 | c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL); | |
9847 | return false; | |
9848 | } | |
9849 | if (context == pragma_external) | |
9850 | { | |
9851 | error_at (c_parser_peek_token (parser)->location, | |
9852 | "%<#pragma grainsize%> must be inside a function"); | |
9853 | c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL); | |
9854 | return false; | |
9855 | } | |
9856 | c_parser_cilk_grainsize (parser); | |
9857 | return false; | |
f2697631 | 9858 | |
b75b98aa | 9859 | default: |
1e8e9920 | 9860 | if (id < PRAGMA_FIRST_EXTERNAL) |
9861 | { | |
bc7bff74 | 9862 | if (context != pragma_stmt && context != pragma_compound) |
1e8e9920 | 9863 | { |
9864 | bad_stmt: | |
9865 | c_parser_error (parser, "expected declaration specifiers"); | |
9866 | c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL); | |
9867 | return false; | |
9868 | } | |
9869 | c_parser_omp_construct (parser); | |
9870 | return true; | |
9871 | } | |
b75b98aa | 9872 | break; |
9873 | } | |
9874 | ||
9875 | c_parser_consume_pragma (parser); | |
9876 | c_invoke_pragma_handler (id); | |
1576dec7 | 9877 | |
48e1416a | 9878 | /* Skip to EOL, but suppress any error message. Those will have been |
b75b98aa | 9879 | generated by the handler routine through calling error, as opposed |
9880 | to calling c_parser_error. */ | |
9881 | parser->error = true; | |
9882 | c_parser_skip_to_pragma_eol (parser); | |
9883 | ||
9884 | return false; | |
9885 | } | |
9886 | ||
9887 | /* The interface the pragma parsers have to the lexer. */ | |
9888 | ||
9889 | enum cpp_ttype | |
ed536208 | 9890 | pragma_lex (tree *value, location_t *loc) |
b75b98aa | 9891 | { |
9892 | c_token *tok = c_parser_peek_token (the_parser); | |
9893 | enum cpp_ttype ret = tok->type; | |
9894 | ||
9895 | *value = tok->value; | |
ed536208 | 9896 | if (loc) |
9897 | *loc = tok->location; | |
9898 | ||
b75b98aa | 9899 | if (ret == CPP_PRAGMA_EOL || ret == CPP_EOF) |
9900 | ret = CPP_EOF; | |
9901 | else | |
9902 | { | |
9903 | if (ret == CPP_KEYWORD) | |
9904 | ret = CPP_NAME; | |
9905 | c_parser_consume_token (the_parser); | |
9906 | } | |
9907 | ||
9908 | return ret; | |
9909 | } | |
9910 | ||
9911 | static void | |
9912 | c_parser_pragma_pch_preprocess (c_parser *parser) | |
9913 | { | |
9914 | tree name = NULL; | |
9915 | ||
9916 | c_parser_consume_pragma (parser); | |
9917 | if (c_parser_next_token_is (parser, CPP_STRING)) | |
9918 | { | |
9919 | name = c_parser_peek_token (parser)->value; | |
9920 | c_parser_consume_token (parser); | |
9921 | } | |
9922 | else | |
9923 | c_parser_error (parser, "expected string literal"); | |
9924 | c_parser_skip_to_pragma_eol (parser); | |
9925 | ||
9926 | if (name) | |
9927 | c_common_pch_pragma (parse_in, TREE_STRING_POINTER (name)); | |
9928 | } | |
1e8e9920 | 9929 | \f |
ca4c3545 | 9930 | /* OpenACC and OpenMP parsing routines. */ |
1e8e9920 | 9931 | |
9932 | /* Returns name of the next clause. | |
9933 | If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and | |
9934 | the token is not consumed. Otherwise appropriate pragma_omp_clause is | |
9935 | returned and the token is consumed. */ | |
9936 | ||
9937 | static pragma_omp_clause | |
9938 | c_parser_omp_clause_name (c_parser *parser) | |
9939 | { | |
9940 | pragma_omp_clause result = PRAGMA_OMP_CLAUSE_NONE; | |
9941 | ||
ca4c3545 | 9942 | if (c_parser_next_token_is_keyword (parser, RID_AUTO)) |
9943 | result = PRAGMA_OACC_CLAUSE_AUTO; | |
9944 | else if (c_parser_next_token_is_keyword (parser, RID_IF)) | |
1e8e9920 | 9945 | result = PRAGMA_OMP_CLAUSE_IF; |
9946 | else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT)) | |
9947 | result = PRAGMA_OMP_CLAUSE_DEFAULT; | |
bc7bff74 | 9948 | else if (c_parser_next_token_is_keyword (parser, RID_FOR)) |
9949 | result = PRAGMA_OMP_CLAUSE_FOR; | |
1e8e9920 | 9950 | else if (c_parser_next_token_is (parser, CPP_NAME)) |
9951 | { | |
9952 | const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); | |
9953 | ||
9954 | switch (p[0]) | |
9955 | { | |
bc7bff74 | 9956 | case 'a': |
9957 | if (!strcmp ("aligned", p)) | |
9958 | result = PRAGMA_OMP_CLAUSE_ALIGNED; | |
ca4c3545 | 9959 | else if (!strcmp ("async", p)) |
9960 | result = PRAGMA_OACC_CLAUSE_ASYNC; | |
bc7bff74 | 9961 | break; |
1e8e9920 | 9962 | case 'c': |
fd6481cf | 9963 | if (!strcmp ("collapse", p)) |
9964 | result = PRAGMA_OMP_CLAUSE_COLLAPSE; | |
ca4c3545 | 9965 | else if (!strcmp ("copy", p)) |
9966 | result = PRAGMA_OACC_CLAUSE_COPY; | |
fd6481cf | 9967 | else if (!strcmp ("copyin", p)) |
1e8e9920 | 9968 | result = PRAGMA_OMP_CLAUSE_COPYIN; |
ca4c3545 | 9969 | else if (!strcmp ("copyout", p)) |
9970 | result = PRAGMA_OACC_CLAUSE_COPYOUT; | |
1e8e9920 | 9971 | else if (!strcmp ("copyprivate", p)) |
9972 | result = PRAGMA_OMP_CLAUSE_COPYPRIVATE; | |
ca4c3545 | 9973 | else if (!strcmp ("create", p)) |
9974 | result = PRAGMA_OACC_CLAUSE_CREATE; | |
1e8e9920 | 9975 | break; |
bc7bff74 | 9976 | case 'd': |
43895be5 | 9977 | if (!strcmp ("defaultmap", p)) |
9978 | result = PRAGMA_OMP_CLAUSE_DEFAULTMAP; | |
9979 | else if (!strcmp ("delete", p)) | |
ca4c3545 | 9980 | result = PRAGMA_OACC_CLAUSE_DELETE; |
9981 | else if (!strcmp ("depend", p)) | |
bc7bff74 | 9982 | result = PRAGMA_OMP_CLAUSE_DEPEND; |
9983 | else if (!strcmp ("device", p)) | |
9984 | result = PRAGMA_OMP_CLAUSE_DEVICE; | |
ca4c3545 | 9985 | else if (!strcmp ("deviceptr", p)) |
9986 | result = PRAGMA_OACC_CLAUSE_DEVICEPTR; | |
bc7bff74 | 9987 | else if (!strcmp ("dist_schedule", p)) |
9988 | result = PRAGMA_OMP_CLAUSE_DIST_SCHEDULE; | |
9989 | break; | |
1e8e9920 | 9990 | case 'f': |
2169f33b | 9991 | if (!strcmp ("final", p)) |
9992 | result = PRAGMA_OMP_CLAUSE_FINAL; | |
9993 | else if (!strcmp ("firstprivate", p)) | |
1e8e9920 | 9994 | result = PRAGMA_OMP_CLAUSE_FIRSTPRIVATE; |
bc7bff74 | 9995 | else if (!strcmp ("from", p)) |
9996 | result = PRAGMA_OMP_CLAUSE_FROM; | |
9997 | break; | |
ca4c3545 | 9998 | case 'g': |
9999 | if (!strcmp ("gang", p)) | |
10000 | result = PRAGMA_OACC_CLAUSE_GANG; | |
43895be5 | 10001 | else if (!strcmp ("grainsize", p)) |
10002 | result = PRAGMA_OMP_CLAUSE_GRAINSIZE; | |
ca4c3545 | 10003 | break; |
10004 | case 'h': | |
43895be5 | 10005 | if (!strcmp ("hint", p)) |
10006 | result = PRAGMA_OMP_CLAUSE_HINT; | |
10007 | else if (!strcmp ("host", p)) | |
ca4c3545 | 10008 | result = PRAGMA_OACC_CLAUSE_HOST; |
10009 | break; | |
bc7bff74 | 10010 | case 'i': |
10011 | if (!strcmp ("inbranch", p)) | |
10012 | result = PRAGMA_OMP_CLAUSE_INBRANCH; | |
43895be5 | 10013 | else if (!strcmp ("is_device_ptr", p)) |
10014 | result = PRAGMA_OMP_CLAUSE_IS_DEVICE_PTR; | |
1e8e9920 | 10015 | break; |
10016 | case 'l': | |
10017 | if (!strcmp ("lastprivate", p)) | |
10018 | result = PRAGMA_OMP_CLAUSE_LASTPRIVATE; | |
bc7bff74 | 10019 | else if (!strcmp ("linear", p)) |
10020 | result = PRAGMA_OMP_CLAUSE_LINEAR; | |
43895be5 | 10021 | else if (!strcmp ("link", p)) |
10022 | result = PRAGMA_OMP_CLAUSE_LINK; | |
1e8e9920 | 10023 | break; |
2169f33b | 10024 | case 'm': |
bc7bff74 | 10025 | if (!strcmp ("map", p)) |
10026 | result = PRAGMA_OMP_CLAUSE_MAP; | |
10027 | else if (!strcmp ("mergeable", p)) | |
2169f33b | 10028 | result = PRAGMA_OMP_CLAUSE_MERGEABLE; |
a89e6c15 | 10029 | else if (flag_cilkplus && !strcmp ("mask", p)) |
74acc703 | 10030 | result = PRAGMA_CILK_CLAUSE_MASK; |
2169f33b | 10031 | break; |
1e8e9920 | 10032 | case 'n': |
43895be5 | 10033 | if (!strcmp ("nogroup", p)) |
10034 | result = PRAGMA_OMP_CLAUSE_NOGROUP; | |
10035 | else if (!strcmp ("notinbranch", p)) | |
bc7bff74 | 10036 | result = PRAGMA_OMP_CLAUSE_NOTINBRANCH; |
10037 | else if (!strcmp ("nowait", p)) | |
1e8e9920 | 10038 | result = PRAGMA_OMP_CLAUSE_NOWAIT; |
ca4c3545 | 10039 | else if (!strcmp ("num_gangs", p)) |
10040 | result = PRAGMA_OACC_CLAUSE_NUM_GANGS; | |
43895be5 | 10041 | else if (!strcmp ("num_tasks", p)) |
10042 | result = PRAGMA_OMP_CLAUSE_NUM_TASKS; | |
bc7bff74 | 10043 | else if (!strcmp ("num_teams", p)) |
10044 | result = PRAGMA_OMP_CLAUSE_NUM_TEAMS; | |
1e8e9920 | 10045 | else if (!strcmp ("num_threads", p)) |
10046 | result = PRAGMA_OMP_CLAUSE_NUM_THREADS; | |
ca4c3545 | 10047 | else if (!strcmp ("num_workers", p)) |
10048 | result = PRAGMA_OACC_CLAUSE_NUM_WORKERS; | |
a89e6c15 | 10049 | else if (flag_cilkplus && !strcmp ("nomask", p)) |
74acc703 | 10050 | result = PRAGMA_CILK_CLAUSE_NOMASK; |
1e8e9920 | 10051 | break; |
10052 | case 'o': | |
10053 | if (!strcmp ("ordered", p)) | |
10054 | result = PRAGMA_OMP_CLAUSE_ORDERED; | |
10055 | break; | |
10056 | case 'p': | |
bc7bff74 | 10057 | if (!strcmp ("parallel", p)) |
10058 | result = PRAGMA_OMP_CLAUSE_PARALLEL; | |
ca4c3545 | 10059 | else if (!strcmp ("present", p)) |
10060 | result = PRAGMA_OACC_CLAUSE_PRESENT; | |
10061 | else if (!strcmp ("present_or_copy", p) | |
10062 | || !strcmp ("pcopy", p)) | |
10063 | result = PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY; | |
10064 | else if (!strcmp ("present_or_copyin", p) | |
10065 | || !strcmp ("pcopyin", p)) | |
10066 | result = PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN; | |
10067 | else if (!strcmp ("present_or_copyout", p) | |
10068 | || !strcmp ("pcopyout", p)) | |
10069 | result = PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT; | |
10070 | else if (!strcmp ("present_or_create", p) | |
10071 | || !strcmp ("pcreate", p)) | |
10072 | result = PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE; | |
43895be5 | 10073 | else if (!strcmp ("priority", p)) |
10074 | result = PRAGMA_OMP_CLAUSE_PRIORITY; | |
bc7bff74 | 10075 | else if (!strcmp ("private", p)) |
1e8e9920 | 10076 | result = PRAGMA_OMP_CLAUSE_PRIVATE; |
bc7bff74 | 10077 | else if (!strcmp ("proc_bind", p)) |
10078 | result = PRAGMA_OMP_CLAUSE_PROC_BIND; | |
1e8e9920 | 10079 | break; |
10080 | case 'r': | |
10081 | if (!strcmp ("reduction", p)) | |
10082 | result = PRAGMA_OMP_CLAUSE_REDUCTION; | |
10083 | break; | |
10084 | case 's': | |
bc7bff74 | 10085 | if (!strcmp ("safelen", p)) |
10086 | result = PRAGMA_OMP_CLAUSE_SAFELEN; | |
10087 | else if (!strcmp ("schedule", p)) | |
1e8e9920 | 10088 | result = PRAGMA_OMP_CLAUSE_SCHEDULE; |
bc7bff74 | 10089 | else if (!strcmp ("sections", p)) |
10090 | result = PRAGMA_OMP_CLAUSE_SECTIONS; | |
ca4c3545 | 10091 | else if (!strcmp ("seq", p)) |
10092 | result = PRAGMA_OACC_CLAUSE_SEQ; | |
1e8e9920 | 10093 | else if (!strcmp ("shared", p)) |
10094 | result = PRAGMA_OMP_CLAUSE_SHARED; | |
43895be5 | 10095 | else if (!strcmp ("simd", p)) |
10096 | result = PRAGMA_OMP_CLAUSE_SIMD; | |
bc7bff74 | 10097 | else if (!strcmp ("simdlen", p)) |
10098 | result = PRAGMA_OMP_CLAUSE_SIMDLEN; | |
ca4c3545 | 10099 | else if (!strcmp ("self", p)) |
10100 | result = PRAGMA_OACC_CLAUSE_SELF; | |
bc7bff74 | 10101 | break; |
10102 | case 't': | |
10103 | if (!strcmp ("taskgroup", p)) | |
10104 | result = PRAGMA_OMP_CLAUSE_TASKGROUP; | |
10105 | else if (!strcmp ("thread_limit", p)) | |
10106 | result = PRAGMA_OMP_CLAUSE_THREAD_LIMIT; | |
43895be5 | 10107 | else if (!strcmp ("threads", p)) |
10108 | result = PRAGMA_OMP_CLAUSE_THREADS; | |
bc7bff74 | 10109 | else if (!strcmp ("to", p)) |
10110 | result = PRAGMA_OMP_CLAUSE_TO; | |
1e8e9920 | 10111 | break; |
fd6481cf | 10112 | case 'u': |
bc7bff74 | 10113 | if (!strcmp ("uniform", p)) |
10114 | result = PRAGMA_OMP_CLAUSE_UNIFORM; | |
10115 | else if (!strcmp ("untied", p)) | |
fd6481cf | 10116 | result = PRAGMA_OMP_CLAUSE_UNTIED; |
43895be5 | 10117 | else if (!strcmp ("use_device_ptr", p)) |
10118 | result = PRAGMA_OMP_CLAUSE_USE_DEVICE_PTR; | |
fd6481cf | 10119 | break; |
74acc703 | 10120 | case 'v': |
ca4c3545 | 10121 | if (!strcmp ("vector", p)) |
10122 | result = PRAGMA_OACC_CLAUSE_VECTOR; | |
10123 | else if (!strcmp ("vector_length", p)) | |
10124 | result = PRAGMA_OACC_CLAUSE_VECTOR_LENGTH; | |
10125 | else if (flag_cilkplus && !strcmp ("vectorlength", p)) | |
74acc703 | 10126 | result = PRAGMA_CILK_CLAUSE_VECTORLENGTH; |
10127 | break; | |
ca4c3545 | 10128 | case 'w': |
10129 | if (!strcmp ("wait", p)) | |
10130 | result = PRAGMA_OACC_CLAUSE_WAIT; | |
10131 | else if (!strcmp ("worker", p)) | |
10132 | result = PRAGMA_OACC_CLAUSE_WORKER; | |
10133 | break; | |
1e8e9920 | 10134 | } |
10135 | } | |
10136 | ||
10137 | if (result != PRAGMA_OMP_CLAUSE_NONE) | |
10138 | c_parser_consume_token (parser); | |
10139 | ||
10140 | return result; | |
10141 | } | |
10142 | ||
10143 | /* Validate that a clause of the given type does not already exist. */ | |
10144 | ||
10145 | static void | |
7d339f93 | 10146 | check_no_duplicate_clause (tree clauses, enum omp_clause_code code, |
10147 | const char *name) | |
1e8e9920 | 10148 | { |
10149 | tree c; | |
10150 | ||
10151 | for (c = clauses; c ; c = OMP_CLAUSE_CHAIN (c)) | |
55d6e7cd | 10152 | if (OMP_CLAUSE_CODE (c) == code) |
1e8e9920 | 10153 | { |
e60a6f7b | 10154 | location_t loc = OMP_CLAUSE_LOCATION (c); |
10155 | error_at (loc, "too many %qs clauses", name); | |
1e8e9920 | 10156 | break; |
10157 | } | |
10158 | } | |
10159 | ||
ca4c3545 | 10160 | /* OpenACC 2.0 |
10161 | Parse wait clause or wait directive parameters. */ | |
10162 | ||
10163 | static tree | |
10164 | c_parser_oacc_wait_list (c_parser *parser, location_t clause_loc, tree list) | |
10165 | { | |
10166 | vec<tree, va_gc> *args; | |
10167 | tree t, args_tree; | |
10168 | ||
10169 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
10170 | return list; | |
10171 | ||
10172 | args = c_parser_expr_list (parser, false, true, NULL, NULL, NULL, NULL); | |
10173 | ||
10174 | if (args->length () == 0) | |
10175 | { | |
10176 | c_parser_error (parser, "expected integer expression before ')'"); | |
10177 | release_tree_vector (args); | |
10178 | return list; | |
10179 | } | |
10180 | ||
10181 | args_tree = build_tree_list_vec (args); | |
10182 | ||
10183 | for (t = args_tree; t; t = TREE_CHAIN (t)) | |
10184 | { | |
10185 | tree targ = TREE_VALUE (t); | |
10186 | ||
10187 | if (targ != error_mark_node) | |
10188 | { | |
10189 | if (!INTEGRAL_TYPE_P (TREE_TYPE (targ))) | |
10190 | { | |
10191 | c_parser_error (parser, "expression must be integral"); | |
10192 | targ = error_mark_node; | |
10193 | } | |
10194 | else | |
10195 | { | |
10196 | tree c = build_omp_clause (clause_loc, OMP_CLAUSE_WAIT); | |
10197 | ||
10198 | OMP_CLAUSE_DECL (c) = targ; | |
10199 | OMP_CLAUSE_CHAIN (c) = list; | |
10200 | list = c; | |
10201 | } | |
10202 | } | |
10203 | } | |
10204 | ||
10205 | release_tree_vector (args); | |
10206 | c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
10207 | return list; | |
10208 | } | |
10209 | ||
10210 | /* OpenACC 2.0, OpenMP 2.5: | |
1e8e9920 | 10211 | variable-list: |
10212 | identifier | |
10213 | variable-list , identifier | |
10214 | ||
e60a6f7b | 10215 | If KIND is nonzero, create the appropriate node and install the |
10216 | decl in OMP_CLAUSE_DECL and add the node to the head of the list. | |
10217 | If KIND is nonzero, CLAUSE_LOC is the location of the clause. | |
1e8e9920 | 10218 | |
10219 | If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE; | |
10220 | return the list created. */ | |
10221 | ||
10222 | static tree | |
e60a6f7b | 10223 | c_parser_omp_variable_list (c_parser *parser, |
10224 | location_t clause_loc, | |
bc7bff74 | 10225 | enum omp_clause_code kind, tree list) |
1e8e9920 | 10226 | { |
10227 | if (c_parser_next_token_is_not (parser, CPP_NAME) | |
10228 | || c_parser_peek_token (parser)->id_kind != C_ID_ID) | |
10229 | c_parser_error (parser, "expected identifier"); | |
10230 | ||
10231 | while (c_parser_next_token_is (parser, CPP_NAME) | |
10232 | && c_parser_peek_token (parser)->id_kind == C_ID_ID) | |
10233 | { | |
10234 | tree t = lookup_name (c_parser_peek_token (parser)->value); | |
10235 | ||
10236 | if (t == NULL_TREE) | |
bc7bff74 | 10237 | { |
10238 | undeclared_variable (c_parser_peek_token (parser)->location, | |
10239 | c_parser_peek_token (parser)->value); | |
10240 | t = error_mark_node; | |
10241 | } | |
10242 | ||
10243 | c_parser_consume_token (parser); | |
10244 | ||
10245 | if (t == error_mark_node) | |
1e8e9920 | 10246 | ; |
10247 | else if (kind != 0) | |
10248 | { | |
bc7bff74 | 10249 | switch (kind) |
10250 | { | |
ca4c3545 | 10251 | case OMP_CLAUSE__CACHE_: |
10252 | if (c_parser_peek_token (parser)->type != CPP_OPEN_SQUARE) | |
10253 | { | |
10254 | c_parser_error (parser, "expected %<[%>"); | |
10255 | t = error_mark_node; | |
10256 | break; | |
10257 | } | |
43895be5 | 10258 | /* FALLTHROUGH */ |
bc7bff74 | 10259 | case OMP_CLAUSE_MAP: |
10260 | case OMP_CLAUSE_FROM: | |
10261 | case OMP_CLAUSE_TO: | |
43895be5 | 10262 | while (c_parser_next_token_is (parser, CPP_DOT)) |
10263 | { | |
10264 | location_t op_loc = c_parser_peek_token (parser)->location; | |
10265 | c_parser_consume_token (parser); | |
10266 | if (!c_parser_next_token_is (parser, CPP_NAME)) | |
10267 | { | |
10268 | c_parser_error (parser, "expected identifier"); | |
10269 | t = error_mark_node; | |
10270 | break; | |
10271 | } | |
10272 | tree ident = c_parser_peek_token (parser)->value; | |
10273 | c_parser_consume_token (parser); | |
10274 | t = build_component_ref (op_loc, t, ident); | |
10275 | } | |
10276 | /* FALLTHROUGH */ | |
bc7bff74 | 10277 | case OMP_CLAUSE_DEPEND: |
43895be5 | 10278 | case OMP_CLAUSE_REDUCTION: |
bc7bff74 | 10279 | while (c_parser_next_token_is (parser, CPP_OPEN_SQUARE)) |
10280 | { | |
10281 | tree low_bound = NULL_TREE, length = NULL_TREE; | |
10282 | ||
10283 | c_parser_consume_token (parser); | |
10284 | if (!c_parser_next_token_is (parser, CPP_COLON)) | |
4fc4088b | 10285 | { |
10286 | low_bound = c_parser_expression (parser).value; | |
10287 | mark_exp_read (low_bound); | |
10288 | } | |
bc7bff74 | 10289 | if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE)) |
10290 | length = integer_one_node; | |
10291 | else | |
10292 | { | |
10293 | /* Look for `:'. */ | |
10294 | if (!c_parser_require (parser, CPP_COLON, | |
10295 | "expected %<:%>")) | |
10296 | { | |
10297 | t = error_mark_node; | |
10298 | break; | |
10299 | } | |
10300 | if (!c_parser_next_token_is (parser, CPP_CLOSE_SQUARE)) | |
4fc4088b | 10301 | { |
10302 | length = c_parser_expression (parser).value; | |
10303 | mark_exp_read (length); | |
10304 | } | |
bc7bff74 | 10305 | } |
10306 | /* Look for the closing `]'. */ | |
10307 | if (!c_parser_require (parser, CPP_CLOSE_SQUARE, | |
10308 | "expected %<]%>")) | |
10309 | { | |
10310 | t = error_mark_node; | |
10311 | break; | |
10312 | } | |
ca4c3545 | 10313 | |
10314 | if (kind == OMP_CLAUSE__CACHE_) | |
10315 | { | |
10316 | if (TREE_CODE (low_bound) != INTEGER_CST | |
10317 | && !TREE_READONLY (low_bound)) | |
10318 | { | |
10319 | error_at (clause_loc, | |
43895be5 | 10320 | "%qD is not a constant", low_bound); |
ca4c3545 | 10321 | t = error_mark_node; |
10322 | } | |
10323 | ||
10324 | if (TREE_CODE (length) != INTEGER_CST | |
10325 | && !TREE_READONLY (length)) | |
10326 | { | |
10327 | error_at (clause_loc, | |
43895be5 | 10328 | "%qD is not a constant", length); |
ca4c3545 | 10329 | t = error_mark_node; |
10330 | } | |
10331 | } | |
10332 | ||
bc7bff74 | 10333 | t = tree_cons (low_bound, length, t); |
10334 | } | |
10335 | break; | |
10336 | default: | |
10337 | break; | |
10338 | } | |
10339 | ||
10340 | if (t != error_mark_node) | |
10341 | { | |
10342 | tree u = build_omp_clause (clause_loc, kind); | |
10343 | OMP_CLAUSE_DECL (u) = t; | |
10344 | OMP_CLAUSE_CHAIN (u) = list; | |
10345 | list = u; | |
10346 | } | |
1e8e9920 | 10347 | } |
10348 | else | |
10349 | list = tree_cons (t, NULL_TREE, list); | |
10350 | ||
1e8e9920 | 10351 | if (c_parser_next_token_is_not (parser, CPP_COMMA)) |
10352 | break; | |
10353 | ||
10354 | c_parser_consume_token (parser); | |
10355 | } | |
10356 | ||
10357 | return list; | |
10358 | } | |
10359 | ||
10360 | /* Similarly, but expect leading and trailing parenthesis. This is a very | |
ca4c3545 | 10361 | common case for OpenACC and OpenMP clauses. */ |
1e8e9920 | 10362 | |
10363 | static tree | |
7d339f93 | 10364 | c_parser_omp_var_list_parens (c_parser *parser, enum omp_clause_code kind, |
10365 | tree list) | |
1e8e9920 | 10366 | { |
e60a6f7b | 10367 | /* The clauses location. */ |
10368 | location_t loc = c_parser_peek_token (parser)->location; | |
10369 | ||
1e8e9920 | 10370 | if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) |
10371 | { | |
e60a6f7b | 10372 | list = c_parser_omp_variable_list (parser, loc, kind, list); |
1e8e9920 | 10373 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); |
10374 | } | |
10375 | return list; | |
10376 | } | |
10377 | ||
ca4c3545 | 10378 | /* OpenACC 2.0: |
10379 | copy ( variable-list ) | |
10380 | copyin ( variable-list ) | |
10381 | copyout ( variable-list ) | |
10382 | create ( variable-list ) | |
10383 | delete ( variable-list ) | |
10384 | present ( variable-list ) | |
10385 | present_or_copy ( variable-list ) | |
10386 | pcopy ( variable-list ) | |
10387 | present_or_copyin ( variable-list ) | |
10388 | pcopyin ( variable-list ) | |
10389 | present_or_copyout ( variable-list ) | |
10390 | pcopyout ( variable-list ) | |
10391 | present_or_create ( variable-list ) | |
10392 | pcreate ( variable-list ) */ | |
10393 | ||
10394 | static tree | |
10395 | c_parser_oacc_data_clause (c_parser *parser, pragma_omp_clause c_kind, | |
10396 | tree list) | |
10397 | { | |
10398 | enum gomp_map_kind kind; | |
10399 | switch (c_kind) | |
10400 | { | |
10401 | case PRAGMA_OACC_CLAUSE_COPY: | |
10402 | kind = GOMP_MAP_FORCE_TOFROM; | |
10403 | break; | |
10404 | case PRAGMA_OACC_CLAUSE_COPYIN: | |
10405 | kind = GOMP_MAP_FORCE_TO; | |
10406 | break; | |
10407 | case PRAGMA_OACC_CLAUSE_COPYOUT: | |
10408 | kind = GOMP_MAP_FORCE_FROM; | |
10409 | break; | |
10410 | case PRAGMA_OACC_CLAUSE_CREATE: | |
10411 | kind = GOMP_MAP_FORCE_ALLOC; | |
10412 | break; | |
10413 | case PRAGMA_OACC_CLAUSE_DELETE: | |
10414 | kind = GOMP_MAP_FORCE_DEALLOC; | |
10415 | break; | |
10416 | case PRAGMA_OACC_CLAUSE_DEVICE: | |
10417 | kind = GOMP_MAP_FORCE_TO; | |
10418 | break; | |
10419 | case PRAGMA_OACC_CLAUSE_HOST: | |
10420 | case PRAGMA_OACC_CLAUSE_SELF: | |
10421 | kind = GOMP_MAP_FORCE_FROM; | |
10422 | break; | |
10423 | case PRAGMA_OACC_CLAUSE_PRESENT: | |
10424 | kind = GOMP_MAP_FORCE_PRESENT; | |
10425 | break; | |
10426 | case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY: | |
10427 | kind = GOMP_MAP_TOFROM; | |
10428 | break; | |
10429 | case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN: | |
10430 | kind = GOMP_MAP_TO; | |
10431 | break; | |
10432 | case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT: | |
10433 | kind = GOMP_MAP_FROM; | |
10434 | break; | |
10435 | case PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE: | |
10436 | kind = GOMP_MAP_ALLOC; | |
10437 | break; | |
10438 | default: | |
10439 | gcc_unreachable (); | |
10440 | } | |
10441 | tree nl, c; | |
10442 | nl = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_MAP, list); | |
10443 | ||
10444 | for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c)) | |
10445 | OMP_CLAUSE_SET_MAP_KIND (c, kind); | |
10446 | ||
10447 | return nl; | |
10448 | } | |
10449 | ||
10450 | /* OpenACC 2.0: | |
10451 | deviceptr ( variable-list ) */ | |
10452 | ||
10453 | static tree | |
10454 | c_parser_oacc_data_clause_deviceptr (c_parser *parser, tree list) | |
10455 | { | |
10456 | location_t loc = c_parser_peek_token (parser)->location; | |
10457 | tree vars, t; | |
10458 | ||
10459 | /* Can't use OMP_CLAUSE_MAP here (that is, can't use the generic | |
10460 | c_parser_oacc_data_clause), as for PRAGMA_OACC_CLAUSE_DEVICEPTR, | |
10461 | variable-list must only allow for pointer variables. */ | |
10462 | vars = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL); | |
10463 | for (t = vars; t && t; t = TREE_CHAIN (t)) | |
10464 | { | |
10465 | tree v = TREE_PURPOSE (t); | |
10466 | ||
10467 | /* FIXME diagnostics: Ideally we should keep individual | |
10468 | locations for all the variables in the var list to make the | |
10469 | following errors more precise. Perhaps | |
10470 | c_parser_omp_var_list_parens() should construct a list of | |
10471 | locations to go along with the var list. */ | |
10472 | ||
f48c7f4a | 10473 | if (!VAR_P (v)) |
ca4c3545 | 10474 | error_at (loc, "%qD is not a variable", v); |
10475 | else if (TREE_TYPE (v) == error_mark_node) | |
10476 | ; | |
10477 | else if (!POINTER_TYPE_P (TREE_TYPE (v))) | |
10478 | error_at (loc, "%qD is not a pointer variable", v); | |
10479 | ||
10480 | tree u = build_omp_clause (loc, OMP_CLAUSE_MAP); | |
10481 | OMP_CLAUSE_SET_MAP_KIND (u, GOMP_MAP_FORCE_DEVICEPTR); | |
10482 | OMP_CLAUSE_DECL (u) = v; | |
10483 | OMP_CLAUSE_CHAIN (u) = list; | |
10484 | list = u; | |
10485 | } | |
10486 | ||
10487 | return list; | |
10488 | } | |
10489 | ||
10490 | /* OpenACC 2.0, OpenMP 3.0: | |
fd6481cf | 10491 | collapse ( constant-expression ) */ |
10492 | ||
10493 | static tree | |
10494 | c_parser_omp_clause_collapse (c_parser *parser, tree list) | |
10495 | { | |
10496 | tree c, num = error_mark_node; | |
10497 | HOST_WIDE_INT n; | |
10498 | location_t loc; | |
10499 | ||
10500 | check_no_duplicate_clause (list, OMP_CLAUSE_COLLAPSE, "collapse"); | |
10501 | ||
10502 | loc = c_parser_peek_token (parser)->location; | |
10503 | if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
10504 | { | |
10505 | num = c_parser_expr_no_commas (parser, NULL).value; | |
10506 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
10507 | } | |
10508 | if (num == error_mark_node) | |
10509 | return list; | |
bc7bff74 | 10510 | mark_exp_read (num); |
10511 | num = c_fully_fold (num, false, NULL); | |
fd6481cf | 10512 | if (!INTEGRAL_TYPE_P (TREE_TYPE (num)) |
e913b5cd | 10513 | || !tree_fits_shwi_p (num) |
10514 | || (n = tree_to_shwi (num)) <= 0 | |
fd6481cf | 10515 | || (int) n != n) |
10516 | { | |
e3b80d49 | 10517 | error_at (loc, |
10518 | "collapse argument needs positive constant integer expression"); | |
fd6481cf | 10519 | return list; |
10520 | } | |
e60a6f7b | 10521 | c = build_omp_clause (loc, OMP_CLAUSE_COLLAPSE); |
fd6481cf | 10522 | OMP_CLAUSE_COLLAPSE_EXPR (c) = num; |
10523 | OMP_CLAUSE_CHAIN (c) = list; | |
10524 | return c; | |
10525 | } | |
10526 | ||
1e8e9920 | 10527 | /* OpenMP 2.5: |
10528 | copyin ( variable-list ) */ | |
10529 | ||
10530 | static tree | |
10531 | c_parser_omp_clause_copyin (c_parser *parser, tree list) | |
10532 | { | |
10533 | return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYIN, list); | |
10534 | } | |
10535 | ||
10536 | /* OpenMP 2.5: | |
10537 | copyprivate ( variable-list ) */ | |
10538 | ||
10539 | static tree | |
10540 | c_parser_omp_clause_copyprivate (c_parser *parser, tree list) | |
10541 | { | |
10542 | return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYPRIVATE, list); | |
10543 | } | |
10544 | ||
10545 | /* OpenMP 2.5: | |
10546 | default ( shared | none ) */ | |
10547 | ||
10548 | static tree | |
10549 | c_parser_omp_clause_default (c_parser *parser, tree list) | |
10550 | { | |
10551 | enum omp_clause_default_kind kind = OMP_CLAUSE_DEFAULT_UNSPECIFIED; | |
e60a6f7b | 10552 | location_t loc = c_parser_peek_token (parser)->location; |
1e8e9920 | 10553 | tree c; |
10554 | ||
10555 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
10556 | return list; | |
10557 | if (c_parser_next_token_is (parser, CPP_NAME)) | |
10558 | { | |
10559 | const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); | |
10560 | ||
10561 | switch (p[0]) | |
10562 | { | |
10563 | case 'n': | |
10564 | if (strcmp ("none", p) != 0) | |
10565 | goto invalid_kind; | |
10566 | kind = OMP_CLAUSE_DEFAULT_NONE; | |
10567 | break; | |
10568 | ||
10569 | case 's': | |
10570 | if (strcmp ("shared", p) != 0) | |
10571 | goto invalid_kind; | |
10572 | kind = OMP_CLAUSE_DEFAULT_SHARED; | |
10573 | break; | |
10574 | ||
10575 | default: | |
10576 | goto invalid_kind; | |
10577 | } | |
10578 | ||
10579 | c_parser_consume_token (parser); | |
10580 | } | |
10581 | else | |
10582 | { | |
10583 | invalid_kind: | |
10584 | c_parser_error (parser, "expected %<none%> or %<shared%>"); | |
10585 | } | |
10586 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
10587 | ||
10588 | if (kind == OMP_CLAUSE_DEFAULT_UNSPECIFIED) | |
10589 | return list; | |
10590 | ||
10591 | check_no_duplicate_clause (list, OMP_CLAUSE_DEFAULT, "default"); | |
e60a6f7b | 10592 | c = build_omp_clause (loc, OMP_CLAUSE_DEFAULT); |
1e8e9920 | 10593 | OMP_CLAUSE_CHAIN (c) = list; |
10594 | OMP_CLAUSE_DEFAULT_KIND (c) = kind; | |
10595 | ||
10596 | return c; | |
10597 | } | |
10598 | ||
10599 | /* OpenMP 2.5: | |
10600 | firstprivate ( variable-list ) */ | |
10601 | ||
10602 | static tree | |
10603 | c_parser_omp_clause_firstprivate (c_parser *parser, tree list) | |
10604 | { | |
10605 | return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_FIRSTPRIVATE, list); | |
10606 | } | |
10607 | ||
2169f33b | 10608 | /* OpenMP 3.1: |
10609 | final ( expression ) */ | |
10610 | ||
10611 | static tree | |
10612 | c_parser_omp_clause_final (c_parser *parser, tree list) | |
10613 | { | |
10614 | location_t loc = c_parser_peek_token (parser)->location; | |
10615 | if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) | |
10616 | { | |
10617 | tree t = c_parser_paren_condition (parser); | |
10618 | tree c; | |
10619 | ||
10620 | check_no_duplicate_clause (list, OMP_CLAUSE_FINAL, "final"); | |
10621 | ||
10622 | c = build_omp_clause (loc, OMP_CLAUSE_FINAL); | |
10623 | OMP_CLAUSE_FINAL_EXPR (c) = t; | |
10624 | OMP_CLAUSE_CHAIN (c) = list; | |
10625 | list = c; | |
10626 | } | |
10627 | else | |
10628 | c_parser_error (parser, "expected %<(%>"); | |
10629 | ||
10630 | return list; | |
10631 | } | |
10632 | ||
ca4c3545 | 10633 | /* OpenACC, OpenMP 2.5: |
43895be5 | 10634 | if ( expression ) |
10635 | ||
10636 | OpenMP 4.5: | |
10637 | if ( directive-name-modifier : expression ) | |
10638 | ||
10639 | directive-name-modifier: | |
10640 | parallel | task | taskloop | target data | target | target update | |
10641 | | target enter data | target exit data */ | |
1e8e9920 | 10642 | |
10643 | static tree | |
43895be5 | 10644 | c_parser_omp_clause_if (c_parser *parser, tree list, bool is_omp) |
1e8e9920 | 10645 | { |
43895be5 | 10646 | location_t location = c_parser_peek_token (parser)->location; |
10647 | enum tree_code if_modifier = ERROR_MARK; | |
1e8e9920 | 10648 | |
43895be5 | 10649 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) |
10650 | return list; | |
1e8e9920 | 10651 | |
43895be5 | 10652 | if (is_omp && c_parser_next_token_is (parser, CPP_NAME)) |
10653 | { | |
10654 | const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); | |
10655 | int n = 2; | |
10656 | if (strcmp (p, "parallel") == 0) | |
10657 | if_modifier = OMP_PARALLEL; | |
10658 | else if (strcmp (p, "task") == 0) | |
10659 | if_modifier = OMP_TASK; | |
10660 | else if (strcmp (p, "taskloop") == 0) | |
10661 | if_modifier = OMP_TASKLOOP; | |
10662 | else if (strcmp (p, "target") == 0) | |
10663 | { | |
10664 | if_modifier = OMP_TARGET; | |
10665 | if (c_parser_peek_2nd_token (parser)->type == CPP_NAME) | |
10666 | { | |
10667 | p = IDENTIFIER_POINTER (c_parser_peek_2nd_token (parser)->value); | |
10668 | if (strcmp ("data", p) == 0) | |
10669 | if_modifier = OMP_TARGET_DATA; | |
10670 | else if (strcmp ("update", p) == 0) | |
10671 | if_modifier = OMP_TARGET_UPDATE; | |
10672 | else if (strcmp ("enter", p) == 0) | |
10673 | if_modifier = OMP_TARGET_ENTER_DATA; | |
10674 | else if (strcmp ("exit", p) == 0) | |
10675 | if_modifier = OMP_TARGET_EXIT_DATA; | |
10676 | if (if_modifier != OMP_TARGET) | |
10677 | { | |
10678 | n = 3; | |
10679 | c_parser_consume_token (parser); | |
10680 | } | |
10681 | else | |
10682 | { | |
10683 | location_t loc = c_parser_peek_2nd_token (parser)->location; | |
10684 | error_at (loc, "expected %<data%>, %<update%>, %<enter%> " | |
10685 | "or %<exit%>"); | |
10686 | if_modifier = ERROR_MARK; | |
10687 | } | |
10688 | if (if_modifier == OMP_TARGET_ENTER_DATA | |
10689 | || if_modifier == OMP_TARGET_EXIT_DATA) | |
10690 | { | |
10691 | if (c_parser_peek_2nd_token (parser)->type == CPP_NAME) | |
10692 | { | |
10693 | p = IDENTIFIER_POINTER | |
10694 | (c_parser_peek_2nd_token (parser)->value); | |
10695 | if (strcmp ("data", p) == 0) | |
10696 | n = 4; | |
10697 | } | |
10698 | if (n == 4) | |
10699 | c_parser_consume_token (parser); | |
10700 | else | |
10701 | { | |
10702 | location_t loc | |
10703 | = c_parser_peek_2nd_token (parser)->location; | |
10704 | error_at (loc, "expected %<data%>"); | |
10705 | if_modifier = ERROR_MARK; | |
10706 | } | |
10707 | } | |
10708 | } | |
10709 | } | |
10710 | if (if_modifier != ERROR_MARK) | |
10711 | { | |
10712 | if (c_parser_peek_2nd_token (parser)->type == CPP_COLON) | |
10713 | { | |
10714 | c_parser_consume_token (parser); | |
10715 | c_parser_consume_token (parser); | |
10716 | } | |
10717 | else | |
10718 | { | |
10719 | if (n > 2) | |
10720 | { | |
10721 | location_t loc = c_parser_peek_2nd_token (parser)->location; | |
10722 | error_at (loc, "expected %<:%>"); | |
10723 | } | |
10724 | if_modifier = ERROR_MARK; | |
10725 | } | |
10726 | } | |
1e8e9920 | 10727 | } |
1e8e9920 | 10728 | |
43895be5 | 10729 | tree t = c_parser_condition (parser), c; |
10730 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
10731 | ||
10732 | for (c = list; c ; c = OMP_CLAUSE_CHAIN (c)) | |
10733 | if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IF) | |
10734 | { | |
10735 | if (if_modifier != ERROR_MARK | |
10736 | && OMP_CLAUSE_IF_MODIFIER (c) == if_modifier) | |
10737 | { | |
10738 | const char *p = NULL; | |
10739 | switch (if_modifier) | |
10740 | { | |
10741 | case OMP_PARALLEL: p = "parallel"; break; | |
10742 | case OMP_TASK: p = "task"; break; | |
10743 | case OMP_TASKLOOP: p = "taskloop"; break; | |
10744 | case OMP_TARGET_DATA: p = "target data"; break; | |
10745 | case OMP_TARGET: p = "target"; break; | |
10746 | case OMP_TARGET_UPDATE: p = "target update"; break; | |
10747 | case OMP_TARGET_ENTER_DATA: p = "enter data"; break; | |
10748 | case OMP_TARGET_EXIT_DATA: p = "exit data"; break; | |
10749 | default: gcc_unreachable (); | |
10750 | } | |
10751 | error_at (location, "too many %<if%> clauses with %qs modifier", | |
10752 | p); | |
10753 | return list; | |
10754 | } | |
10755 | else if (OMP_CLAUSE_IF_MODIFIER (c) == if_modifier) | |
10756 | { | |
10757 | if (!is_omp) | |
10758 | error_at (location, "too many %<if%> clauses"); | |
10759 | else | |
10760 | error_at (location, "too many %<if%> clauses without modifier"); | |
10761 | return list; | |
10762 | } | |
10763 | else if (if_modifier == ERROR_MARK | |
10764 | || OMP_CLAUSE_IF_MODIFIER (c) == ERROR_MARK) | |
10765 | { | |
10766 | error_at (location, "if any %<if%> clause has modifier, then all " | |
10767 | "%<if%> clauses have to use modifier"); | |
10768 | return list; | |
10769 | } | |
10770 | } | |
10771 | ||
10772 | c = build_omp_clause (location, OMP_CLAUSE_IF); | |
10773 | OMP_CLAUSE_IF_MODIFIER (c) = if_modifier; | |
10774 | OMP_CLAUSE_IF_EXPR (c) = t; | |
10775 | OMP_CLAUSE_CHAIN (c) = list; | |
10776 | return c; | |
1e8e9920 | 10777 | } |
10778 | ||
10779 | /* OpenMP 2.5: | |
10780 | lastprivate ( variable-list ) */ | |
10781 | ||
10782 | static tree | |
10783 | c_parser_omp_clause_lastprivate (c_parser *parser, tree list) | |
10784 | { | |
10785 | return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_LASTPRIVATE, list); | |
10786 | } | |
10787 | ||
2169f33b | 10788 | /* OpenMP 3.1: |
10789 | mergeable */ | |
10790 | ||
10791 | static tree | |
10792 | c_parser_omp_clause_mergeable (c_parser *parser ATTRIBUTE_UNUSED, tree list) | |
10793 | { | |
10794 | tree c; | |
10795 | ||
10796 | /* FIXME: Should we allow duplicates? */ | |
10797 | check_no_duplicate_clause (list, OMP_CLAUSE_MERGEABLE, "mergeable"); | |
10798 | ||
10799 | c = build_omp_clause (c_parser_peek_token (parser)->location, | |
10800 | OMP_CLAUSE_MERGEABLE); | |
10801 | OMP_CLAUSE_CHAIN (c) = list; | |
10802 | ||
10803 | return c; | |
10804 | } | |
10805 | ||
1e8e9920 | 10806 | /* OpenMP 2.5: |
10807 | nowait */ | |
10808 | ||
10809 | static tree | |
10810 | c_parser_omp_clause_nowait (c_parser *parser ATTRIBUTE_UNUSED, tree list) | |
10811 | { | |
10812 | tree c; | |
e60a6f7b | 10813 | location_t loc = c_parser_peek_token (parser)->location; |
1e8e9920 | 10814 | |
10815 | check_no_duplicate_clause (list, OMP_CLAUSE_NOWAIT, "nowait"); | |
10816 | ||
e60a6f7b | 10817 | c = build_omp_clause (loc, OMP_CLAUSE_NOWAIT); |
1e8e9920 | 10818 | OMP_CLAUSE_CHAIN (c) = list; |
10819 | return c; | |
10820 | } | |
10821 | ||
ca4c3545 | 10822 | /* OpenACC: |
10823 | num_gangs ( expression ) */ | |
10824 | ||
10825 | static tree | |
10826 | c_parser_omp_clause_num_gangs (c_parser *parser, tree list) | |
10827 | { | |
10828 | location_t num_gangs_loc = c_parser_peek_token (parser)->location; | |
10829 | if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
10830 | { | |
10831 | location_t expr_loc = c_parser_peek_token (parser)->location; | |
10832 | tree c, t = c_parser_expression (parser).value; | |
10833 | mark_exp_read (t); | |
10834 | t = c_fully_fold (t, false, NULL); | |
10835 | ||
10836 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
10837 | ||
10838 | if (!INTEGRAL_TYPE_P (TREE_TYPE (t))) | |
10839 | { | |
10840 | c_parser_error (parser, "expected integer expression"); | |
10841 | return list; | |
10842 | } | |
10843 | ||
10844 | /* Attempt to statically determine when the number isn't positive. */ | |
10845 | c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t, | |
10846 | build_int_cst (TREE_TYPE (t), 0)); | |
789fbb51 | 10847 | protected_set_expr_location (c, expr_loc); |
ca4c3545 | 10848 | if (c == boolean_true_node) |
10849 | { | |
10850 | warning_at (expr_loc, 0, | |
10851 | "%<num_gangs%> value must be positive"); | |
10852 | t = integer_one_node; | |
10853 | } | |
10854 | ||
10855 | check_no_duplicate_clause (list, OMP_CLAUSE_NUM_GANGS, "num_gangs"); | |
10856 | ||
10857 | c = build_omp_clause (num_gangs_loc, OMP_CLAUSE_NUM_GANGS); | |
10858 | OMP_CLAUSE_NUM_GANGS_EXPR (c) = t; | |
10859 | OMP_CLAUSE_CHAIN (c) = list; | |
10860 | list = c; | |
10861 | } | |
10862 | ||
10863 | return list; | |
10864 | } | |
10865 | ||
1e8e9920 | 10866 | /* OpenMP 2.5: |
10867 | num_threads ( expression ) */ | |
10868 | ||
10869 | static tree | |
10870 | c_parser_omp_clause_num_threads (c_parser *parser, tree list) | |
10871 | { | |
e60a6f7b | 10872 | location_t num_threads_loc = c_parser_peek_token (parser)->location; |
1e8e9920 | 10873 | if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) |
10874 | { | |
be9eba16 | 10875 | location_t expr_loc = c_parser_peek_token (parser)->location; |
1e8e9920 | 10876 | tree c, t = c_parser_expression (parser).value; |
80678da6 | 10877 | mark_exp_read (t); |
a75b1c71 | 10878 | t = c_fully_fold (t, false, NULL); |
1e8e9920 | 10879 | |
10880 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
10881 | ||
10882 | if (!INTEGRAL_TYPE_P (TREE_TYPE (t))) | |
10883 | { | |
10884 | c_parser_error (parser, "expected integer expression"); | |
10885 | return list; | |
10886 | } | |
10887 | ||
10888 | /* Attempt to statically determine when the number isn't positive. */ | |
389dd41b | 10889 | c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t, |
1e8e9920 | 10890 | build_int_cst (TREE_TYPE (t), 0)); |
789fbb51 | 10891 | protected_set_expr_location (c, expr_loc); |
1e8e9920 | 10892 | if (c == boolean_true_node) |
10893 | { | |
e3b80d49 | 10894 | warning_at (expr_loc, 0, |
10895 | "%<num_threads%> value must be positive"); | |
1e8e9920 | 10896 | t = integer_one_node; |
10897 | } | |
10898 | ||
10899 | check_no_duplicate_clause (list, OMP_CLAUSE_NUM_THREADS, "num_threads"); | |
10900 | ||
e60a6f7b | 10901 | c = build_omp_clause (num_threads_loc, OMP_CLAUSE_NUM_THREADS); |
1e8e9920 | 10902 | OMP_CLAUSE_NUM_THREADS_EXPR (c) = t; |
10903 | OMP_CLAUSE_CHAIN (c) = list; | |
10904 | list = c; | |
10905 | } | |
10906 | ||
10907 | return list; | |
10908 | } | |
10909 | ||
43895be5 | 10910 | /* OpenMP 4.5: |
10911 | num_tasks ( expression ) */ | |
10912 | ||
10913 | static tree | |
10914 | c_parser_omp_clause_num_tasks (c_parser *parser, tree list) | |
10915 | { | |
10916 | location_t num_tasks_loc = c_parser_peek_token (parser)->location; | |
10917 | if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
10918 | { | |
10919 | location_t expr_loc = c_parser_peek_token (parser)->location; | |
10920 | tree c, t = c_parser_expression (parser).value; | |
10921 | mark_exp_read (t); | |
10922 | t = c_fully_fold (t, false, NULL); | |
10923 | ||
10924 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
10925 | ||
10926 | if (!INTEGRAL_TYPE_P (TREE_TYPE (t))) | |
10927 | { | |
10928 | c_parser_error (parser, "expected integer expression"); | |
10929 | return list; | |
10930 | } | |
10931 | ||
10932 | /* Attempt to statically determine when the number isn't positive. */ | |
10933 | c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t, | |
10934 | build_int_cst (TREE_TYPE (t), 0)); | |
10935 | if (CAN_HAVE_LOCATION_P (c)) | |
10936 | SET_EXPR_LOCATION (c, expr_loc); | |
10937 | if (c == boolean_true_node) | |
10938 | { | |
10939 | warning_at (expr_loc, 0, "%<num_tasks%> value must be positive"); | |
10940 | t = integer_one_node; | |
10941 | } | |
10942 | ||
10943 | check_no_duplicate_clause (list, OMP_CLAUSE_NUM_TASKS, "num_tasks"); | |
10944 | ||
10945 | c = build_omp_clause (num_tasks_loc, OMP_CLAUSE_NUM_TASKS); | |
10946 | OMP_CLAUSE_NUM_TASKS_EXPR (c) = t; | |
10947 | OMP_CLAUSE_CHAIN (c) = list; | |
10948 | list = c; | |
10949 | } | |
10950 | ||
10951 | return list; | |
10952 | } | |
10953 | ||
10954 | /* OpenMP 4.5: | |
10955 | grainsize ( expression ) */ | |
10956 | ||
10957 | static tree | |
10958 | c_parser_omp_clause_grainsize (c_parser *parser, tree list) | |
10959 | { | |
10960 | location_t grainsize_loc = c_parser_peek_token (parser)->location; | |
10961 | if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
10962 | { | |
10963 | location_t expr_loc = c_parser_peek_token (parser)->location; | |
10964 | tree c, t = c_parser_expression (parser).value; | |
10965 | mark_exp_read (t); | |
10966 | t = c_fully_fold (t, false, NULL); | |
10967 | ||
10968 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
10969 | ||
10970 | if (!INTEGRAL_TYPE_P (TREE_TYPE (t))) | |
10971 | { | |
10972 | c_parser_error (parser, "expected integer expression"); | |
10973 | return list; | |
10974 | } | |
10975 | ||
10976 | /* Attempt to statically determine when the number isn't positive. */ | |
10977 | c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t, | |
10978 | build_int_cst (TREE_TYPE (t), 0)); | |
10979 | if (CAN_HAVE_LOCATION_P (c)) | |
10980 | SET_EXPR_LOCATION (c, expr_loc); | |
10981 | if (c == boolean_true_node) | |
10982 | { | |
10983 | warning_at (expr_loc, 0, "%<grainsize%> value must be positive"); | |
10984 | t = integer_one_node; | |
10985 | } | |
10986 | ||
10987 | check_no_duplicate_clause (list, OMP_CLAUSE_GRAINSIZE, "grainsize"); | |
10988 | ||
10989 | c = build_omp_clause (grainsize_loc, OMP_CLAUSE_GRAINSIZE); | |
10990 | OMP_CLAUSE_GRAINSIZE_EXPR (c) = t; | |
10991 | OMP_CLAUSE_CHAIN (c) = list; | |
10992 | list = c; | |
10993 | } | |
10994 | ||
10995 | return list; | |
10996 | } | |
10997 | ||
10998 | /* OpenMP 4.5: | |
10999 | priority ( expression ) */ | |
11000 | ||
11001 | static tree | |
11002 | c_parser_omp_clause_priority (c_parser *parser, tree list) | |
11003 | { | |
11004 | location_t priority_loc = c_parser_peek_token (parser)->location; | |
11005 | if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
11006 | { | |
11007 | location_t expr_loc = c_parser_peek_token (parser)->location; | |
11008 | tree c, t = c_parser_expression (parser).value; | |
11009 | mark_exp_read (t); | |
11010 | t = c_fully_fold (t, false, NULL); | |
11011 | ||
11012 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
11013 | ||
11014 | if (!INTEGRAL_TYPE_P (TREE_TYPE (t))) | |
11015 | { | |
11016 | c_parser_error (parser, "expected integer expression"); | |
11017 | return list; | |
11018 | } | |
11019 | ||
11020 | /* Attempt to statically determine when the number isn't | |
11021 | non-negative. */ | |
11022 | c = fold_build2_loc (expr_loc, LT_EXPR, boolean_type_node, t, | |
11023 | build_int_cst (TREE_TYPE (t), 0)); | |
11024 | if (CAN_HAVE_LOCATION_P (c)) | |
11025 | SET_EXPR_LOCATION (c, expr_loc); | |
11026 | if (c == boolean_true_node) | |
11027 | { | |
11028 | warning_at (expr_loc, 0, "%<priority%> value must be non-negative"); | |
11029 | t = integer_one_node; | |
11030 | } | |
11031 | ||
11032 | check_no_duplicate_clause (list, OMP_CLAUSE_PRIORITY, "priority"); | |
11033 | ||
11034 | c = build_omp_clause (priority_loc, OMP_CLAUSE_PRIORITY); | |
11035 | OMP_CLAUSE_PRIORITY_EXPR (c) = t; | |
11036 | OMP_CLAUSE_CHAIN (c) = list; | |
11037 | list = c; | |
11038 | } | |
11039 | ||
11040 | return list; | |
11041 | } | |
11042 | ||
11043 | /* OpenMP 4.5: | |
11044 | hint ( expression ) */ | |
11045 | ||
11046 | static tree | |
11047 | c_parser_omp_clause_hint (c_parser *parser, tree list) | |
11048 | { | |
11049 | location_t hint_loc = c_parser_peek_token (parser)->location; | |
11050 | if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
11051 | { | |
11052 | tree c, t = c_parser_expression (parser).value; | |
11053 | mark_exp_read (t); | |
11054 | t = c_fully_fold (t, false, NULL); | |
11055 | ||
11056 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
11057 | ||
11058 | if (!INTEGRAL_TYPE_P (TREE_TYPE (t))) | |
11059 | { | |
11060 | c_parser_error (parser, "expected integer expression"); | |
11061 | return list; | |
11062 | } | |
11063 | ||
11064 | check_no_duplicate_clause (list, OMP_CLAUSE_HINT, "hint"); | |
11065 | ||
11066 | c = build_omp_clause (hint_loc, OMP_CLAUSE_HINT); | |
11067 | OMP_CLAUSE_HINT_EXPR (c) = t; | |
11068 | OMP_CLAUSE_CHAIN (c) = list; | |
11069 | list = c; | |
11070 | } | |
11071 | ||
11072 | return list; | |
11073 | } | |
11074 | ||
11075 | /* OpenMP 4.5: | |
11076 | defaultmap ( tofrom : scalar ) */ | |
11077 | ||
11078 | static tree | |
11079 | c_parser_omp_clause_defaultmap (c_parser *parser, tree list) | |
11080 | { | |
11081 | location_t loc = c_parser_peek_token (parser)->location; | |
11082 | tree c; | |
11083 | const char *p; | |
11084 | ||
11085 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
11086 | return list; | |
11087 | if (!c_parser_next_token_is (parser, CPP_NAME)) | |
11088 | { | |
11089 | c_parser_error (parser, "expected %<tofrom%>"); | |
11090 | goto out_err; | |
11091 | } | |
11092 | p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); | |
11093 | if (strcmp (p, "tofrom") != 0) | |
11094 | { | |
11095 | c_parser_error (parser, "expected %<tofrom%>"); | |
11096 | goto out_err; | |
11097 | } | |
11098 | c_parser_consume_token (parser); | |
11099 | if (!c_parser_require (parser, CPP_COLON, "expected %<:%>")) | |
11100 | goto out_err; | |
11101 | if (!c_parser_next_token_is (parser, CPP_NAME)) | |
11102 | { | |
11103 | c_parser_error (parser, "expected %<scalar%>"); | |
11104 | goto out_err; | |
11105 | } | |
11106 | p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); | |
11107 | if (strcmp (p, "scalar") != 0) | |
11108 | { | |
11109 | c_parser_error (parser, "expected %<scalar%>"); | |
11110 | goto out_err; | |
11111 | } | |
11112 | c_parser_consume_token (parser); | |
11113 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
11114 | check_no_duplicate_clause (list, OMP_CLAUSE_DEFAULTMAP, "defaultmap"); | |
11115 | c = build_omp_clause (loc, OMP_CLAUSE_DEFAULTMAP); | |
11116 | OMP_CLAUSE_CHAIN (c) = list; | |
11117 | return c; | |
11118 | ||
11119 | out_err: | |
11120 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
11121 | return list; | |
11122 | } | |
11123 | ||
11124 | /* OpenMP 4.5: | |
11125 | use_device_ptr ( variable-list ) */ | |
11126 | ||
11127 | static tree | |
11128 | c_parser_omp_clause_use_device_ptr (c_parser *parser, tree list) | |
11129 | { | |
11130 | return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_USE_DEVICE_PTR, | |
11131 | list); | |
11132 | } | |
11133 | ||
11134 | /* OpenMP 4.5: | |
11135 | is_device_ptr ( variable-list ) */ | |
11136 | ||
11137 | static tree | |
11138 | c_parser_omp_clause_is_device_ptr (c_parser *parser, tree list) | |
11139 | { | |
11140 | return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_IS_DEVICE_PTR, list); | |
11141 | } | |
11142 | ||
ca4c3545 | 11143 | /* OpenACC: |
11144 | num_workers ( expression ) */ | |
11145 | ||
11146 | static tree | |
11147 | c_parser_omp_clause_num_workers (c_parser *parser, tree list) | |
11148 | { | |
11149 | location_t num_workers_loc = c_parser_peek_token (parser)->location; | |
11150 | if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
11151 | { | |
11152 | location_t expr_loc = c_parser_peek_token (parser)->location; | |
11153 | tree c, t = c_parser_expression (parser).value; | |
11154 | mark_exp_read (t); | |
11155 | t = c_fully_fold (t, false, NULL); | |
11156 | ||
11157 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
11158 | ||
11159 | if (!INTEGRAL_TYPE_P (TREE_TYPE (t))) | |
11160 | { | |
11161 | c_parser_error (parser, "expected integer expression"); | |
11162 | return list; | |
11163 | } | |
11164 | ||
11165 | /* Attempt to statically determine when the number isn't positive. */ | |
11166 | c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t, | |
11167 | build_int_cst (TREE_TYPE (t), 0)); | |
789fbb51 | 11168 | protected_set_expr_location (c, expr_loc); |
ca4c3545 | 11169 | if (c == boolean_true_node) |
11170 | { | |
11171 | warning_at (expr_loc, 0, | |
11172 | "%<num_workers%> value must be positive"); | |
11173 | t = integer_one_node; | |
11174 | } | |
11175 | ||
11176 | check_no_duplicate_clause (list, OMP_CLAUSE_NUM_WORKERS, "num_workers"); | |
11177 | ||
11178 | c = build_omp_clause (num_workers_loc, OMP_CLAUSE_NUM_WORKERS); | |
11179 | OMP_CLAUSE_NUM_WORKERS_EXPR (c) = t; | |
11180 | OMP_CLAUSE_CHAIN (c) = list; | |
11181 | list = c; | |
11182 | } | |
11183 | ||
11184 | return list; | |
11185 | } | |
11186 | ||
11187 | /* OpenACC: | |
11188 | async [( int-expr )] */ | |
11189 | ||
11190 | static tree | |
11191 | c_parser_oacc_clause_async (c_parser *parser, tree list) | |
11192 | { | |
11193 | tree c, t; | |
11194 | location_t loc = c_parser_peek_token (parser)->location; | |
11195 | ||
11196 | t = build_int_cst (integer_type_node, GOMP_ASYNC_NOVAL); | |
11197 | ||
11198 | if (c_parser_peek_token (parser)->type == CPP_OPEN_PAREN) | |
11199 | { | |
11200 | c_parser_consume_token (parser); | |
11201 | ||
11202 | t = c_parser_expression (parser).value; | |
11203 | if (!INTEGRAL_TYPE_P (TREE_TYPE (t))) | |
11204 | c_parser_error (parser, "expected integer expression"); | |
11205 | else if (t == error_mark_node | |
11206 | || !c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>")) | |
11207 | return list; | |
11208 | } | |
11209 | else | |
11210 | t = c_fully_fold (t, false, NULL); | |
11211 | ||
11212 | check_no_duplicate_clause (list, OMP_CLAUSE_ASYNC, "async"); | |
11213 | ||
11214 | c = build_omp_clause (loc, OMP_CLAUSE_ASYNC); | |
11215 | OMP_CLAUSE_ASYNC_EXPR (c) = t; | |
11216 | OMP_CLAUSE_CHAIN (c) = list; | |
11217 | list = c; | |
11218 | ||
11219 | return list; | |
11220 | } | |
11221 | ||
11222 | /* OpenACC: | |
11223 | wait ( int-expr-list ) */ | |
11224 | ||
11225 | static tree | |
11226 | c_parser_oacc_clause_wait (c_parser *parser, tree list) | |
11227 | { | |
11228 | location_t clause_loc = c_parser_peek_token (parser)->location; | |
11229 | ||
11230 | if (c_parser_peek_token (parser)->type == CPP_OPEN_PAREN) | |
11231 | list = c_parser_oacc_wait_list (parser, clause_loc, list); | |
11232 | ||
11233 | return list; | |
11234 | } | |
11235 | ||
1e8e9920 | 11236 | /* OpenMP 2.5: |
43895be5 | 11237 | ordered |
11238 | ||
11239 | OpenMP 4.5: | |
11240 | ordered ( constant-expression ) */ | |
1e8e9920 | 11241 | |
11242 | static tree | |
e60a6f7b | 11243 | c_parser_omp_clause_ordered (c_parser *parser, tree list) |
1e8e9920 | 11244 | { |
1e8e9920 | 11245 | check_no_duplicate_clause (list, OMP_CLAUSE_ORDERED, "ordered"); |
11246 | ||
43895be5 | 11247 | tree c, num = NULL_TREE; |
11248 | HOST_WIDE_INT n; | |
11249 | location_t loc = c_parser_peek_token (parser)->location; | |
11250 | if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) | |
11251 | { | |
11252 | c_parser_consume_token (parser); | |
11253 | num = c_parser_expr_no_commas (parser, NULL).value; | |
11254 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
11255 | } | |
11256 | if (num == error_mark_node) | |
11257 | return list; | |
11258 | if (num) | |
11259 | { | |
11260 | mark_exp_read (num); | |
11261 | num = c_fully_fold (num, false, NULL); | |
11262 | if (!INTEGRAL_TYPE_P (TREE_TYPE (num)) | |
11263 | || !tree_fits_shwi_p (num) | |
11264 | || (n = tree_to_shwi (num)) <= 0 | |
11265 | || (int) n != n) | |
11266 | { | |
11267 | error_at (loc, "ordered argument needs positive " | |
11268 | "constant integer expression"); | |
11269 | return list; | |
11270 | } | |
11271 | } | |
11272 | c = build_omp_clause (loc, OMP_CLAUSE_ORDERED); | |
11273 | OMP_CLAUSE_ORDERED_EXPR (c) = num; | |
1e8e9920 | 11274 | OMP_CLAUSE_CHAIN (c) = list; |
11275 | return c; | |
11276 | } | |
11277 | ||
11278 | /* OpenMP 2.5: | |
11279 | private ( variable-list ) */ | |
11280 | ||
11281 | static tree | |
11282 | c_parser_omp_clause_private (c_parser *parser, tree list) | |
11283 | { | |
11284 | return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_PRIVATE, list); | |
11285 | } | |
11286 | ||
11287 | /* OpenMP 2.5: | |
11288 | reduction ( reduction-operator : variable-list ) | |
11289 | ||
11290 | reduction-operator: | |
2169f33b | 11291 | One of: + * - & ^ | && || |
bc7bff74 | 11292 | |
2169f33b | 11293 | OpenMP 3.1: |
11294 | ||
11295 | reduction-operator: | |
bc7bff74 | 11296 | One of: + * - & ^ | && || max min |
11297 | ||
11298 | OpenMP 4.0: | |
11299 | ||
11300 | reduction-operator: | |
11301 | One of: + * - & ^ | && || | |
11302 | identifier */ | |
1e8e9920 | 11303 | |
11304 | static tree | |
11305 | c_parser_omp_clause_reduction (c_parser *parser, tree list) | |
11306 | { | |
e60a6f7b | 11307 | location_t clause_loc = c_parser_peek_token (parser)->location; |
1e8e9920 | 11308 | if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) |
11309 | { | |
bc7bff74 | 11310 | enum tree_code code = ERROR_MARK; |
11311 | tree reduc_id = NULL_TREE; | |
1e8e9920 | 11312 | |
11313 | switch (c_parser_peek_token (parser)->type) | |
11314 | { | |
11315 | case CPP_PLUS: | |
11316 | code = PLUS_EXPR; | |
11317 | break; | |
11318 | case CPP_MULT: | |
11319 | code = MULT_EXPR; | |
11320 | break; | |
11321 | case CPP_MINUS: | |
11322 | code = MINUS_EXPR; | |
11323 | break; | |
11324 | case CPP_AND: | |
11325 | code = BIT_AND_EXPR; | |
11326 | break; | |
11327 | case CPP_XOR: | |
11328 | code = BIT_XOR_EXPR; | |
11329 | break; | |
11330 | case CPP_OR: | |
11331 | code = BIT_IOR_EXPR; | |
11332 | break; | |
11333 | case CPP_AND_AND: | |
11334 | code = TRUTH_ANDIF_EXPR; | |
11335 | break; | |
11336 | case CPP_OR_OR: | |
11337 | code = TRUTH_ORIF_EXPR; | |
11338 | break; | |
2169f33b | 11339 | case CPP_NAME: |
11340 | { | |
11341 | const char *p | |
11342 | = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); | |
11343 | if (strcmp (p, "min") == 0) | |
11344 | { | |
11345 | code = MIN_EXPR; | |
11346 | break; | |
11347 | } | |
11348 | if (strcmp (p, "max") == 0) | |
11349 | { | |
11350 | code = MAX_EXPR; | |
11351 | break; | |
11352 | } | |
bc7bff74 | 11353 | reduc_id = c_parser_peek_token (parser)->value; |
11354 | break; | |
2169f33b | 11355 | } |
1e8e9920 | 11356 | default: |
11357 | c_parser_error (parser, | |
11358 | "expected %<+%>, %<*%>, %<-%>, %<&%>, " | |
2169f33b | 11359 | "%<^%>, %<|%>, %<&&%>, %<||%>, %<min%> or %<max%>"); |
1e8e9920 | 11360 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0); |
11361 | return list; | |
11362 | } | |
11363 | c_parser_consume_token (parser); | |
bc7bff74 | 11364 | reduc_id = c_omp_reduction_id (code, reduc_id); |
1e8e9920 | 11365 | if (c_parser_require (parser, CPP_COLON, "expected %<:%>")) |
11366 | { | |
11367 | tree nl, c; | |
11368 | ||
e60a6f7b | 11369 | nl = c_parser_omp_variable_list (parser, clause_loc, |
11370 | OMP_CLAUSE_REDUCTION, list); | |
1e8e9920 | 11371 | for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c)) |
bc7bff74 | 11372 | { |
43895be5 | 11373 | tree d = OMP_CLAUSE_DECL (c), type; |
11374 | if (TREE_CODE (d) != TREE_LIST) | |
11375 | type = TREE_TYPE (d); | |
11376 | else | |
11377 | { | |
11378 | int cnt = 0; | |
11379 | tree t; | |
11380 | for (t = d; TREE_CODE (t) == TREE_LIST; t = TREE_CHAIN (t)) | |
11381 | cnt++; | |
11382 | type = TREE_TYPE (t); | |
11383 | while (cnt > 0) | |
11384 | { | |
11385 | if (TREE_CODE (type) != POINTER_TYPE | |
11386 | && TREE_CODE (type) != ARRAY_TYPE) | |
11387 | break; | |
11388 | type = TREE_TYPE (type); | |
11389 | cnt--; | |
11390 | } | |
11391 | } | |
11392 | while (TREE_CODE (type) == ARRAY_TYPE) | |
11393 | type = TREE_TYPE (type); | |
bc7bff74 | 11394 | OMP_CLAUSE_REDUCTION_CODE (c) = code; |
11395 | if (code == ERROR_MARK | |
11396 | || !(INTEGRAL_TYPE_P (type) | |
11397 | || TREE_CODE (type) == REAL_TYPE | |
11398 | || TREE_CODE (type) == COMPLEX_TYPE)) | |
11399 | OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) | |
11400 | = c_omp_reduction_lookup (reduc_id, | |
11401 | TYPE_MAIN_VARIANT (type)); | |
11402 | } | |
1e8e9920 | 11403 | |
11404 | list = nl; | |
11405 | } | |
11406 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
11407 | } | |
11408 | return list; | |
11409 | } | |
11410 | ||
11411 | /* OpenMP 2.5: | |
11412 | schedule ( schedule-kind ) | |
11413 | schedule ( schedule-kind , expression ) | |
11414 | ||
11415 | schedule-kind: | |
fd6481cf | 11416 | static | dynamic | guided | runtime | auto |
43895be5 | 11417 | |
11418 | OpenMP 4.5: | |
11419 | schedule ( schedule-modifier : schedule-kind ) | |
11420 | schedule ( schedule-modifier : schedule-kind , expression ) | |
11421 | ||
11422 | schedule-modifier: | |
11423 | simd */ | |
1e8e9920 | 11424 | |
11425 | static tree | |
11426 | c_parser_omp_clause_schedule (c_parser *parser, tree list) | |
11427 | { | |
11428 | tree c, t; | |
e60a6f7b | 11429 | location_t loc = c_parser_peek_token (parser)->location; |
1e8e9920 | 11430 | |
11431 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
11432 | return list; | |
11433 | ||
e60a6f7b | 11434 | c = build_omp_clause (loc, OMP_CLAUSE_SCHEDULE); |
1e8e9920 | 11435 | |
43895be5 | 11436 | if (c_parser_next_token_is (parser, CPP_NAME)) |
11437 | { | |
11438 | tree kind = c_parser_peek_token (parser)->value; | |
11439 | const char *p = IDENTIFIER_POINTER (kind); | |
11440 | if (strcmp ("simd", p) == 0 | |
11441 | && c_parser_peek_2nd_token (parser)->type == CPP_COLON) | |
11442 | { | |
11443 | OMP_CLAUSE_SCHEDULE_SIMD (c) = 1; | |
11444 | c_parser_consume_token (parser); | |
11445 | c_parser_consume_token (parser); | |
11446 | } | |
11447 | } | |
11448 | ||
1e8e9920 | 11449 | if (c_parser_next_token_is (parser, CPP_NAME)) |
11450 | { | |
11451 | tree kind = c_parser_peek_token (parser)->value; | |
11452 | const char *p = IDENTIFIER_POINTER (kind); | |
11453 | ||
11454 | switch (p[0]) | |
11455 | { | |
11456 | case 'd': | |
11457 | if (strcmp ("dynamic", p) != 0) | |
11458 | goto invalid_kind; | |
11459 | OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_DYNAMIC; | |
11460 | break; | |
11461 | ||
11462 | case 'g': | |
11463 | if (strcmp ("guided", p) != 0) | |
11464 | goto invalid_kind; | |
11465 | OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_GUIDED; | |
11466 | break; | |
11467 | ||
11468 | case 'r': | |
11469 | if (strcmp ("runtime", p) != 0) | |
11470 | goto invalid_kind; | |
11471 | OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_RUNTIME; | |
11472 | break; | |
11473 | ||
11474 | default: | |
11475 | goto invalid_kind; | |
11476 | } | |
11477 | } | |
11478 | else if (c_parser_next_token_is_keyword (parser, RID_STATIC)) | |
11479 | OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_STATIC; | |
fd6481cf | 11480 | else if (c_parser_next_token_is_keyword (parser, RID_AUTO)) |
11481 | OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_AUTO; | |
1e8e9920 | 11482 | else |
11483 | goto invalid_kind; | |
11484 | ||
11485 | c_parser_consume_token (parser); | |
11486 | if (c_parser_next_token_is (parser, CPP_COMMA)) | |
11487 | { | |
be9eba16 | 11488 | location_t here; |
1e8e9920 | 11489 | c_parser_consume_token (parser); |
11490 | ||
be9eba16 | 11491 | here = c_parser_peek_token (parser)->location; |
1e8e9920 | 11492 | t = c_parser_expr_no_commas (parser, NULL).value; |
80678da6 | 11493 | mark_exp_read (t); |
a75b1c71 | 11494 | t = c_fully_fold (t, false, NULL); |
1e8e9920 | 11495 | |
11496 | if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_RUNTIME) | |
e3b80d49 | 11497 | error_at (here, "schedule %<runtime%> does not take " |
11498 | "a %<chunk_size%> parameter"); | |
fd6481cf | 11499 | else if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_AUTO) |
e3b80d49 | 11500 | error_at (here, |
11501 | "schedule %<auto%> does not take " | |
11502 | "a %<chunk_size%> parameter"); | |
1e8e9920 | 11503 | else if (TREE_CODE (TREE_TYPE (t)) == INTEGER_TYPE) |
11504 | OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c) = t; | |
11505 | else | |
11506 | c_parser_error (parser, "expected integer expression"); | |
11507 | ||
11508 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
11509 | } | |
11510 | else | |
11511 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, | |
11512 | "expected %<,%> or %<)%>"); | |
11513 | ||
11514 | check_no_duplicate_clause (list, OMP_CLAUSE_SCHEDULE, "schedule"); | |
11515 | OMP_CLAUSE_CHAIN (c) = list; | |
11516 | return c; | |
11517 | ||
11518 | invalid_kind: | |
11519 | c_parser_error (parser, "invalid schedule kind"); | |
11520 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0); | |
11521 | return list; | |
11522 | } | |
11523 | ||
11524 | /* OpenMP 2.5: | |
11525 | shared ( variable-list ) */ | |
11526 | ||
11527 | static tree | |
11528 | c_parser_omp_clause_shared (c_parser *parser, tree list) | |
11529 | { | |
11530 | return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_SHARED, list); | |
11531 | } | |
11532 | ||
fd6481cf | 11533 | /* OpenMP 3.0: |
11534 | untied */ | |
11535 | ||
11536 | static tree | |
11537 | c_parser_omp_clause_untied (c_parser *parser ATTRIBUTE_UNUSED, tree list) | |
11538 | { | |
11539 | tree c; | |
11540 | ||
11541 | /* FIXME: Should we allow duplicates? */ | |
11542 | check_no_duplicate_clause (list, OMP_CLAUSE_UNTIED, "untied"); | |
11543 | ||
e60a6f7b | 11544 | c = build_omp_clause (c_parser_peek_token (parser)->location, |
11545 | OMP_CLAUSE_UNTIED); | |
fd6481cf | 11546 | OMP_CLAUSE_CHAIN (c) = list; |
e60a6f7b | 11547 | |
fd6481cf | 11548 | return c; |
11549 | } | |
11550 | ||
ca4c3545 | 11551 | /* OpenACC: |
11552 | vector_length ( expression ) */ | |
1e8e9920 | 11553 | |
11554 | static tree | |
ca4c3545 | 11555 | c_parser_omp_clause_vector_length (c_parser *parser, tree list) |
1e8e9920 | 11556 | { |
ca4c3545 | 11557 | location_t vector_length_loc = c_parser_peek_token (parser)->location; |
11558 | if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
11559 | { | |
11560 | location_t expr_loc = c_parser_peek_token (parser)->location; | |
11561 | tree c, t = c_parser_expression (parser).value; | |
11562 | mark_exp_read (t); | |
11563 | t = c_fully_fold (t, false, NULL); | |
1e8e9920 | 11564 | |
ca4c3545 | 11565 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); |
77c8bed2 | 11566 | |
ca4c3545 | 11567 | if (!INTEGRAL_TYPE_P (TREE_TYPE (t))) |
11568 | { | |
11569 | c_parser_error (parser, "expected integer expression"); | |
11570 | return list; | |
11571 | } | |
77c8bed2 | 11572 | |
ca4c3545 | 11573 | /* Attempt to statically determine when the number isn't positive. */ |
11574 | c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t, | |
11575 | build_int_cst (TREE_TYPE (t), 0)); | |
789fbb51 | 11576 | protected_set_expr_location (c, expr_loc); |
ca4c3545 | 11577 | if (c == boolean_true_node) |
11578 | { | |
11579 | warning_at (expr_loc, 0, | |
11580 | "%<vector_length%> value must be positive"); | |
11581 | t = integer_one_node; | |
11582 | } | |
11583 | ||
11584 | check_no_duplicate_clause (list, OMP_CLAUSE_VECTOR_LENGTH, "vector_length"); | |
11585 | ||
11586 | c = build_omp_clause (vector_length_loc, OMP_CLAUSE_VECTOR_LENGTH); | |
11587 | OMP_CLAUSE_VECTOR_LENGTH_EXPR (c) = t; | |
11588 | OMP_CLAUSE_CHAIN (c) = list; | |
11589 | list = c; | |
11590 | } | |
11591 | ||
11592 | return list; | |
11593 | } | |
11594 | ||
11595 | /* OpenMP 4.0: | |
11596 | inbranch | |
11597 | notinbranch */ | |
11598 | ||
11599 | static tree | |
11600 | c_parser_omp_clause_branch (c_parser *parser ATTRIBUTE_UNUSED, | |
11601 | enum omp_clause_code code, tree list) | |
11602 | { | |
11603 | check_no_duplicate_clause (list, code, omp_clause_code_name[code]); | |
11604 | ||
11605 | tree c = build_omp_clause (c_parser_peek_token (parser)->location, code); | |
11606 | OMP_CLAUSE_CHAIN (c) = list; | |
11607 | ||
11608 | return c; | |
11609 | } | |
11610 | ||
11611 | /* OpenMP 4.0: | |
11612 | parallel | |
11613 | for | |
11614 | sections | |
11615 | taskgroup */ | |
11616 | ||
11617 | static tree | |
11618 | c_parser_omp_clause_cancelkind (c_parser *parser ATTRIBUTE_UNUSED, | |
11619 | enum omp_clause_code code, tree list) | |
11620 | { | |
11621 | tree c = build_omp_clause (c_parser_peek_token (parser)->location, code); | |
11622 | OMP_CLAUSE_CHAIN (c) = list; | |
bc7bff74 | 11623 | |
11624 | return c; | |
11625 | } | |
11626 | ||
43895be5 | 11627 | /* OpenMP 4.5: |
11628 | nogroup */ | |
11629 | ||
11630 | static tree | |
11631 | c_parser_omp_clause_nogroup (c_parser *parser ATTRIBUTE_UNUSED, tree list) | |
11632 | { | |
11633 | check_no_duplicate_clause (list, OMP_CLAUSE_NOGROUP, "nogroup"); | |
11634 | tree c = build_omp_clause (c_parser_peek_token (parser)->location, | |
11635 | OMP_CLAUSE_NOGROUP); | |
11636 | OMP_CLAUSE_CHAIN (c) = list; | |
11637 | return c; | |
11638 | } | |
11639 | ||
11640 | /* OpenMP 4.5: | |
11641 | simd | |
11642 | threads */ | |
11643 | ||
11644 | static tree | |
11645 | c_parser_omp_clause_orderedkind (c_parser *parser ATTRIBUTE_UNUSED, | |
11646 | enum omp_clause_code code, tree list) | |
11647 | { | |
11648 | check_no_duplicate_clause (list, code, omp_clause_code_name[code]); | |
11649 | tree c = build_omp_clause (c_parser_peek_token (parser)->location, code); | |
11650 | OMP_CLAUSE_CHAIN (c) = list; | |
11651 | return c; | |
11652 | } | |
11653 | ||
bc7bff74 | 11654 | /* OpenMP 4.0: |
11655 | num_teams ( expression ) */ | |
11656 | ||
11657 | static tree | |
11658 | c_parser_omp_clause_num_teams (c_parser *parser, tree list) | |
11659 | { | |
11660 | location_t num_teams_loc = c_parser_peek_token (parser)->location; | |
11661 | if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
11662 | { | |
11663 | location_t expr_loc = c_parser_peek_token (parser)->location; | |
11664 | tree c, t = c_parser_expression (parser).value; | |
11665 | mark_exp_read (t); | |
11666 | t = c_fully_fold (t, false, NULL); | |
11667 | ||
11668 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
11669 | ||
11670 | if (!INTEGRAL_TYPE_P (TREE_TYPE (t))) | |
1e8e9920 | 11671 | { |
bc7bff74 | 11672 | c_parser_error (parser, "expected integer expression"); |
11673 | return list; | |
1e8e9920 | 11674 | } |
11675 | ||
bc7bff74 | 11676 | /* Attempt to statically determine when the number isn't positive. */ |
11677 | c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t, | |
11678 | build_int_cst (TREE_TYPE (t), 0)); | |
789fbb51 | 11679 | protected_set_expr_location (c, expr_loc); |
bc7bff74 | 11680 | if (c == boolean_true_node) |
1e8e9920 | 11681 | { |
bc7bff74 | 11682 | warning_at (expr_loc, 0, "%<num_teams%> value must be positive"); |
11683 | t = integer_one_node; | |
1e8e9920 | 11684 | } |
1e8e9920 | 11685 | |
bc7bff74 | 11686 | check_no_duplicate_clause (list, OMP_CLAUSE_NUM_TEAMS, "num_teams"); |
1e8e9920 | 11687 | |
bc7bff74 | 11688 | c = build_omp_clause (num_teams_loc, OMP_CLAUSE_NUM_TEAMS); |
11689 | OMP_CLAUSE_NUM_TEAMS_EXPR (c) = t; | |
11690 | OMP_CLAUSE_CHAIN (c) = list; | |
11691 | list = c; | |
11692 | } | |
1e8e9920 | 11693 | |
bc7bff74 | 11694 | return list; |
11695 | } | |
1e8e9920 | 11696 | |
bc7bff74 | 11697 | /* OpenMP 4.0: |
11698 | thread_limit ( expression ) */ | |
1e8e9920 | 11699 | |
11700 | static tree | |
bc7bff74 | 11701 | c_parser_omp_clause_thread_limit (c_parser *parser, tree list) |
1e8e9920 | 11702 | { |
22ac3f78 | 11703 | location_t num_thread_limit_loc = c_parser_peek_token (parser)->location; |
bc7bff74 | 11704 | if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) |
11705 | { | |
11706 | location_t expr_loc = c_parser_peek_token (parser)->location; | |
11707 | tree c, t = c_parser_expression (parser).value; | |
11708 | mark_exp_read (t); | |
11709 | t = c_fully_fold (t, false, NULL); | |
1e8e9920 | 11710 | |
bc7bff74 | 11711 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); |
1e8e9920 | 11712 | |
bc7bff74 | 11713 | if (!INTEGRAL_TYPE_P (TREE_TYPE (t))) |
11714 | { | |
11715 | c_parser_error (parser, "expected integer expression"); | |
11716 | return list; | |
11717 | } | |
1e8e9920 | 11718 | |
bc7bff74 | 11719 | /* Attempt to statically determine when the number isn't positive. */ |
11720 | c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t, | |
11721 | build_int_cst (TREE_TYPE (t), 0)); | |
789fbb51 | 11722 | protected_set_expr_location (c, expr_loc); |
bc7bff74 | 11723 | if (c == boolean_true_node) |
11724 | { | |
11725 | warning_at (expr_loc, 0, "%<thread_limit%> value must be positive"); | |
11726 | t = integer_one_node; | |
11727 | } | |
e60a6f7b | 11728 | |
bc7bff74 | 11729 | check_no_duplicate_clause (list, OMP_CLAUSE_THREAD_LIMIT, |
11730 | "thread_limit"); | |
2169f33b | 11731 | |
22ac3f78 | 11732 | c = build_omp_clause (num_thread_limit_loc, OMP_CLAUSE_THREAD_LIMIT); |
bc7bff74 | 11733 | OMP_CLAUSE_THREAD_LIMIT_EXPR (c) = t; |
11734 | OMP_CLAUSE_CHAIN (c) = list; | |
11735 | list = c; | |
11736 | } | |
2169f33b | 11737 | |
bc7bff74 | 11738 | return list; |
11739 | } | |
2169f33b | 11740 | |
bc7bff74 | 11741 | /* OpenMP 4.0: |
11742 | aligned ( variable-list ) | |
11743 | aligned ( variable-list : constant-expression ) */ | |
2169f33b | 11744 | |
bc7bff74 | 11745 | static tree |
11746 | c_parser_omp_clause_aligned (c_parser *parser, tree list) | |
11747 | { | |
11748 | location_t clause_loc = c_parser_peek_token (parser)->location; | |
11749 | tree nl, c; | |
2169f33b | 11750 | |
bc7bff74 | 11751 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) |
11752 | return list; | |
2169f33b | 11753 | |
bc7bff74 | 11754 | nl = c_parser_omp_variable_list (parser, clause_loc, |
11755 | OMP_CLAUSE_ALIGNED, list); | |
2169f33b | 11756 | |
bc7bff74 | 11757 | if (c_parser_next_token_is (parser, CPP_COLON)) |
11758 | { | |
11759 | c_parser_consume_token (parser); | |
11760 | tree alignment = c_parser_expr_no_commas (parser, NULL).value; | |
11761 | mark_exp_read (alignment); | |
11762 | alignment = c_fully_fold (alignment, false, NULL); | |
0fdcfb93 | 11763 | if (TREE_CODE (alignment) != INTEGER_CST |
11764 | || !INTEGRAL_TYPE_P (TREE_TYPE (alignment)) | |
11765 | || tree_int_cst_sgn (alignment) != 1) | |
bc7bff74 | 11766 | { |
11767 | error_at (clause_loc, "%<aligned%> clause alignment expression must " | |
11768 | "be positive constant integer expression"); | |
11769 | alignment = NULL_TREE; | |
11770 | } | |
2169f33b | 11771 | |
bc7bff74 | 11772 | for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c)) |
11773 | OMP_CLAUSE_ALIGNED_ALIGNMENT (c) = alignment; | |
11774 | } | |
1e8e9920 | 11775 | |
bc7bff74 | 11776 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); |
11777 | return nl; | |
11778 | } | |
11779 | ||
11780 | /* OpenMP 4.0: | |
11781 | linear ( variable-list ) | |
43895be5 | 11782 | linear ( variable-list : expression ) |
11783 | ||
11784 | OpenMP 4.5: | |
11785 | linear ( modifier ( variable-list ) ) | |
11786 | linear ( modifier ( variable-list ) : expression ) */ | |
bc7bff74 | 11787 | |
11788 | static tree | |
74acc703 | 11789 | c_parser_omp_clause_linear (c_parser *parser, tree list, bool is_cilk_simd_fn) |
1e8e9920 | 11790 | { |
bc7bff74 | 11791 | location_t clause_loc = c_parser_peek_token (parser)->location; |
11792 | tree nl, c, step; | |
43895be5 | 11793 | enum omp_clause_linear_kind kind = OMP_CLAUSE_LINEAR_DEFAULT; |
bc7bff74 | 11794 | |
11795 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
11796 | return list; | |
11797 | ||
43895be5 | 11798 | if (!is_cilk_simd_fn |
11799 | && c_parser_next_token_is (parser, CPP_NAME)) | |
11800 | { | |
11801 | c_token *tok = c_parser_peek_token (parser); | |
11802 | const char *p = IDENTIFIER_POINTER (tok->value); | |
11803 | if (strcmp ("val", p) == 0) | |
11804 | kind = OMP_CLAUSE_LINEAR_VAL; | |
11805 | if (c_parser_peek_2nd_token (parser)->type != CPP_OPEN_PAREN) | |
11806 | kind = OMP_CLAUSE_LINEAR_DEFAULT; | |
11807 | if (kind != OMP_CLAUSE_LINEAR_DEFAULT) | |
11808 | { | |
11809 | c_parser_consume_token (parser); | |
11810 | c_parser_consume_token (parser); | |
11811 | } | |
11812 | } | |
11813 | ||
bc7bff74 | 11814 | nl = c_parser_omp_variable_list (parser, clause_loc, |
11815 | OMP_CLAUSE_LINEAR, list); | |
11816 | ||
43895be5 | 11817 | if (kind != OMP_CLAUSE_LINEAR_DEFAULT) |
11818 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
11819 | ||
bc7bff74 | 11820 | if (c_parser_next_token_is (parser, CPP_COLON)) |
11821 | { | |
11822 | c_parser_consume_token (parser); | |
11823 | step = c_parser_expression (parser).value; | |
11824 | mark_exp_read (step); | |
11825 | step = c_fully_fold (step, false, NULL); | |
74acc703 | 11826 | if (is_cilk_simd_fn && TREE_CODE (step) == PARM_DECL) |
11827 | { | |
11828 | sorry ("using parameters for %<linear%> step is not supported yet"); | |
11829 | step = integer_one_node; | |
11830 | } | |
bc7bff74 | 11831 | if (!INTEGRAL_TYPE_P (TREE_TYPE (step))) |
11832 | { | |
11833 | error_at (clause_loc, "%<linear%> clause step expression must " | |
11834 | "be integral"); | |
11835 | step = integer_one_node; | |
11836 | } | |
11837 | ||
11838 | } | |
11839 | else | |
11840 | step = integer_one_node; | |
11841 | ||
11842 | for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c)) | |
11843 | { | |
11844 | OMP_CLAUSE_LINEAR_STEP (c) = step; | |
43895be5 | 11845 | OMP_CLAUSE_LINEAR_KIND (c) = kind; |
bc7bff74 | 11846 | } |
11847 | ||
11848 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
11849 | return nl; | |
11850 | } | |
11851 | ||
11852 | /* OpenMP 4.0: | |
11853 | safelen ( constant-expression ) */ | |
11854 | ||
11855 | static tree | |
11856 | c_parser_omp_clause_safelen (c_parser *parser, tree list) | |
11857 | { | |
11858 | location_t clause_loc = c_parser_peek_token (parser)->location; | |
11859 | tree c, t; | |
11860 | ||
11861 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
11862 | return list; | |
11863 | ||
11864 | t = c_parser_expr_no_commas (parser, NULL).value; | |
11865 | mark_exp_read (t); | |
11866 | t = c_fully_fold (t, false, NULL); | |
0fdcfb93 | 11867 | if (TREE_CODE (t) != INTEGER_CST |
11868 | || !INTEGRAL_TYPE_P (TREE_TYPE (t)) | |
11869 | || tree_int_cst_sgn (t) != 1) | |
bc7bff74 | 11870 | { |
11871 | error_at (clause_loc, "%<safelen%> clause expression must " | |
11872 | "be positive constant integer expression"); | |
11873 | t = NULL_TREE; | |
11874 | } | |
11875 | ||
11876 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
11877 | if (t == NULL_TREE || t == error_mark_node) | |
11878 | return list; | |
11879 | ||
11880 | check_no_duplicate_clause (list, OMP_CLAUSE_SAFELEN, "safelen"); | |
11881 | ||
11882 | c = build_omp_clause (clause_loc, OMP_CLAUSE_SAFELEN); | |
11883 | OMP_CLAUSE_SAFELEN_EXPR (c) = t; | |
11884 | OMP_CLAUSE_CHAIN (c) = list; | |
11885 | return c; | |
11886 | } | |
11887 | ||
11888 | /* OpenMP 4.0: | |
11889 | simdlen ( constant-expression ) */ | |
11890 | ||
11891 | static tree | |
11892 | c_parser_omp_clause_simdlen (c_parser *parser, tree list) | |
11893 | { | |
11894 | location_t clause_loc = c_parser_peek_token (parser)->location; | |
11895 | tree c, t; | |
11896 | ||
11897 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
11898 | return list; | |
11899 | ||
11900 | t = c_parser_expr_no_commas (parser, NULL).value; | |
11901 | mark_exp_read (t); | |
11902 | t = c_fully_fold (t, false, NULL); | |
0fdcfb93 | 11903 | if (TREE_CODE (t) != INTEGER_CST |
11904 | || !INTEGRAL_TYPE_P (TREE_TYPE (t)) | |
11905 | || tree_int_cst_sgn (t) != 1) | |
bc7bff74 | 11906 | { |
11907 | error_at (clause_loc, "%<simdlen%> clause expression must " | |
11908 | "be positive constant integer expression"); | |
11909 | t = NULL_TREE; | |
11910 | } | |
11911 | ||
11912 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
11913 | if (t == NULL_TREE || t == error_mark_node) | |
11914 | return list; | |
11915 | ||
11916 | check_no_duplicate_clause (list, OMP_CLAUSE_SIMDLEN, "simdlen"); | |
11917 | ||
11918 | c = build_omp_clause (clause_loc, OMP_CLAUSE_SIMDLEN); | |
11919 | OMP_CLAUSE_SIMDLEN_EXPR (c) = t; | |
11920 | OMP_CLAUSE_CHAIN (c) = list; | |
11921 | return c; | |
11922 | } | |
11923 | ||
43895be5 | 11924 | /* OpenMP 4.5: |
11925 | vec: | |
11926 | identifier [+/- integer] | |
11927 | vec , identifier [+/- integer] | |
11928 | */ | |
11929 | ||
11930 | static tree | |
11931 | c_parser_omp_clause_depend_sink (c_parser *parser, location_t clause_loc, | |
11932 | tree list) | |
11933 | { | |
11934 | tree vec = NULL; | |
11935 | if (c_parser_next_token_is_not (parser, CPP_NAME) | |
11936 | || c_parser_peek_token (parser)->id_kind != C_ID_ID) | |
11937 | { | |
11938 | c_parser_error (parser, "expected identifier"); | |
11939 | return list; | |
11940 | } | |
11941 | ||
11942 | while (c_parser_next_token_is (parser, CPP_NAME) | |
11943 | && c_parser_peek_token (parser)->id_kind == C_ID_ID) | |
11944 | { | |
11945 | tree t = lookup_name (c_parser_peek_token (parser)->value); | |
11946 | tree addend = NULL; | |
11947 | ||
11948 | if (t == NULL_TREE) | |
11949 | { | |
11950 | undeclared_variable (c_parser_peek_token (parser)->location, | |
11951 | c_parser_peek_token (parser)->value); | |
11952 | t = error_mark_node; | |
11953 | } | |
11954 | ||
11955 | c_parser_consume_token (parser); | |
11956 | ||
11957 | bool neg = false; | |
11958 | if (c_parser_next_token_is (parser, CPP_MINUS)) | |
11959 | neg = true; | |
11960 | else if (!c_parser_next_token_is (parser, CPP_PLUS)) | |
11961 | { | |
11962 | addend = integer_zero_node; | |
11963 | neg = false; | |
11964 | goto add_to_vector; | |
11965 | } | |
11966 | c_parser_consume_token (parser); | |
11967 | ||
11968 | if (c_parser_next_token_is_not (parser, CPP_NUMBER)) | |
11969 | { | |
11970 | c_parser_error (parser, "expected integer"); | |
11971 | return list; | |
11972 | } | |
11973 | ||
11974 | addend = c_parser_peek_token (parser)->value; | |
11975 | if (TREE_CODE (addend) != INTEGER_CST) | |
11976 | { | |
11977 | c_parser_error (parser, "expected integer"); | |
11978 | return list; | |
11979 | } | |
11980 | c_parser_consume_token (parser); | |
11981 | ||
11982 | add_to_vector: | |
11983 | if (t != error_mark_node) | |
11984 | { | |
11985 | vec = tree_cons (addend, t, vec); | |
11986 | if (neg) | |
11987 | OMP_CLAUSE_DEPEND_SINK_NEGATIVE (vec) = 1; | |
11988 | } | |
11989 | ||
11990 | if (c_parser_next_token_is_not (parser, CPP_COMMA)) | |
11991 | break; | |
11992 | ||
11993 | c_parser_consume_token (parser); | |
11994 | } | |
11995 | ||
11996 | if (vec == NULL_TREE) | |
11997 | return list; | |
11998 | ||
11999 | tree u = build_omp_clause (clause_loc, OMP_CLAUSE_DEPEND); | |
12000 | OMP_CLAUSE_DEPEND_KIND (u) = OMP_CLAUSE_DEPEND_SINK; | |
12001 | OMP_CLAUSE_DECL (u) = nreverse (vec); | |
12002 | OMP_CLAUSE_CHAIN (u) = list; | |
12003 | return u; | |
12004 | } | |
12005 | ||
bc7bff74 | 12006 | /* OpenMP 4.0: |
12007 | depend ( depend-kind: variable-list ) | |
12008 | ||
12009 | depend-kind: | |
43895be5 | 12010 | in | out | inout |
12011 | ||
12012 | OpenMP 4.5: | |
12013 | depend ( source ) | |
12014 | ||
12015 | depend ( sink : vec ) */ | |
bc7bff74 | 12016 | |
12017 | static tree | |
12018 | c_parser_omp_clause_depend (c_parser *parser, tree list) | |
12019 | { | |
12020 | location_t clause_loc = c_parser_peek_token (parser)->location; | |
12021 | enum omp_clause_depend_kind kind = OMP_CLAUSE_DEPEND_INOUT; | |
12022 | tree nl, c; | |
12023 | ||
12024 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
12025 | return list; | |
1e8e9920 | 12026 | |
2169f33b | 12027 | if (c_parser_next_token_is (parser, CPP_NAME)) |
12028 | { | |
12029 | const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); | |
bc7bff74 | 12030 | if (strcmp ("in", p) == 0) |
12031 | kind = OMP_CLAUSE_DEPEND_IN; | |
12032 | else if (strcmp ("inout", p) == 0) | |
12033 | kind = OMP_CLAUSE_DEPEND_INOUT; | |
12034 | else if (strcmp ("out", p) == 0) | |
12035 | kind = OMP_CLAUSE_DEPEND_OUT; | |
43895be5 | 12036 | else if (strcmp ("source", p) == 0) |
12037 | kind = OMP_CLAUSE_DEPEND_SOURCE; | |
12038 | else if (strcmp ("sink", p) == 0) | |
12039 | kind = OMP_CLAUSE_DEPEND_SINK; | |
2169f33b | 12040 | else |
bc7bff74 | 12041 | goto invalid_kind; |
2169f33b | 12042 | } |
bc7bff74 | 12043 | else |
12044 | goto invalid_kind; | |
1e8e9920 | 12045 | |
bc7bff74 | 12046 | c_parser_consume_token (parser); |
43895be5 | 12047 | |
12048 | if (kind == OMP_CLAUSE_DEPEND_SOURCE) | |
12049 | { | |
12050 | c = build_omp_clause (clause_loc, OMP_CLAUSE_DEPEND); | |
12051 | OMP_CLAUSE_DEPEND_KIND (c) = kind; | |
12052 | OMP_CLAUSE_DECL (c) = NULL_TREE; | |
12053 | OMP_CLAUSE_CHAIN (c) = list; | |
12054 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
12055 | return c; | |
12056 | } | |
12057 | ||
bc7bff74 | 12058 | if (!c_parser_require (parser, CPP_COLON, "expected %<:%>")) |
12059 | goto resync_fail; | |
12060 | ||
43895be5 | 12061 | if (kind == OMP_CLAUSE_DEPEND_SINK) |
12062 | nl = c_parser_omp_clause_depend_sink (parser, clause_loc, list); | |
12063 | else | |
12064 | { | |
12065 | nl = c_parser_omp_variable_list (parser, clause_loc, | |
12066 | OMP_CLAUSE_DEPEND, list); | |
bc7bff74 | 12067 | |
43895be5 | 12068 | for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c)) |
12069 | OMP_CLAUSE_DEPEND_KIND (c) = kind; | |
12070 | } | |
bc7bff74 | 12071 | |
12072 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
12073 | return nl; | |
12074 | ||
12075 | invalid_kind: | |
12076 | c_parser_error (parser, "invalid depend kind"); | |
12077 | resync_fail: | |
12078 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
12079 | return list; | |
12080 | } | |
12081 | ||
12082 | /* OpenMP 4.0: | |
12083 | map ( map-kind: variable-list ) | |
12084 | map ( variable-list ) | |
12085 | ||
12086 | map-kind: | |
43895be5 | 12087 | alloc | to | from | tofrom |
12088 | ||
12089 | OpenMP 4.5: | |
12090 | map-kind: | |
12091 | alloc | to | from | tofrom | release | delete | |
12092 | ||
12093 | map ( always [,] map-kind: variable-list ) */ | |
bc7bff74 | 12094 | |
12095 | static tree | |
12096 | c_parser_omp_clause_map (c_parser *parser, tree list) | |
12097 | { | |
12098 | location_t clause_loc = c_parser_peek_token (parser)->location; | |
ca4c3545 | 12099 | enum gomp_map_kind kind = GOMP_MAP_TOFROM; |
43895be5 | 12100 | int always = 0; |
12101 | enum c_id_kind always_id_kind = C_ID_NONE; | |
12102 | location_t always_loc = UNKNOWN_LOCATION; | |
12103 | tree always_id = NULL_TREE; | |
bc7bff74 | 12104 | tree nl, c; |
12105 | ||
12106 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
12107 | return list; | |
12108 | ||
43895be5 | 12109 | if (c_parser_next_token_is (parser, CPP_NAME)) |
12110 | { | |
12111 | c_token *tok = c_parser_peek_token (parser); | |
12112 | const char *p = IDENTIFIER_POINTER (tok->value); | |
12113 | always_id_kind = tok->id_kind; | |
12114 | always_loc = tok->location; | |
12115 | always_id = tok->value; | |
12116 | if (strcmp ("always", p) == 0) | |
12117 | { | |
12118 | c_token *sectok = c_parser_peek_2nd_token (parser); | |
12119 | if (sectok->type == CPP_COMMA) | |
12120 | { | |
12121 | c_parser_consume_token (parser); | |
12122 | c_parser_consume_token (parser); | |
12123 | always = 2; | |
12124 | } | |
12125 | else if (sectok->type == CPP_NAME) | |
12126 | { | |
12127 | p = IDENTIFIER_POINTER (sectok->value); | |
12128 | if (strcmp ("alloc", p) == 0 | |
12129 | || strcmp ("to", p) == 0 | |
12130 | || strcmp ("from", p) == 0 | |
12131 | || strcmp ("tofrom", p) == 0 | |
12132 | || strcmp ("release", p) == 0 | |
12133 | || strcmp ("delete", p) == 0) | |
12134 | { | |
12135 | c_parser_consume_token (parser); | |
12136 | always = 1; | |
12137 | } | |
12138 | } | |
12139 | } | |
12140 | } | |
12141 | ||
bc7bff74 | 12142 | if (c_parser_next_token_is (parser, CPP_NAME) |
12143 | && c_parser_peek_2nd_token (parser)->type == CPP_COLON) | |
2169f33b | 12144 | { |
bc7bff74 | 12145 | const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
12146 | if (strcmp ("alloc", p) == 0) | |
ca4c3545 | 12147 | kind = GOMP_MAP_ALLOC; |
bc7bff74 | 12148 | else if (strcmp ("to", p) == 0) |
43895be5 | 12149 | kind = always ? GOMP_MAP_ALWAYS_TO : GOMP_MAP_TO; |
bc7bff74 | 12150 | else if (strcmp ("from", p) == 0) |
43895be5 | 12151 | kind = always ? GOMP_MAP_ALWAYS_FROM : GOMP_MAP_FROM; |
bc7bff74 | 12152 | else if (strcmp ("tofrom", p) == 0) |
43895be5 | 12153 | kind = always ? GOMP_MAP_ALWAYS_TOFROM : GOMP_MAP_TOFROM; |
12154 | else if (strcmp ("release", p) == 0) | |
12155 | kind = GOMP_MAP_RELEASE; | |
12156 | else if (strcmp ("delete", p) == 0) | |
12157 | kind = GOMP_MAP_DELETE; | |
2169f33b | 12158 | else |
12159 | { | |
bc7bff74 | 12160 | c_parser_error (parser, "invalid map kind"); |
12161 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, | |
12162 | "expected %<)%>"); | |
12163 | return list; | |
2169f33b | 12164 | } |
bc7bff74 | 12165 | c_parser_consume_token (parser); |
12166 | c_parser_consume_token (parser); | |
2169f33b | 12167 | } |
43895be5 | 12168 | else if (always) |
12169 | { | |
12170 | if (always_id_kind != C_ID_ID) | |
12171 | { | |
12172 | c_parser_error (parser, "expected identifier"); | |
12173 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
12174 | return list; | |
12175 | } | |
12176 | ||
12177 | tree t = lookup_name (always_id); | |
12178 | if (t == NULL_TREE) | |
12179 | { | |
12180 | undeclared_variable (always_loc, always_id); | |
12181 | t = error_mark_node; | |
12182 | } | |
12183 | if (t != error_mark_node) | |
12184 | { | |
12185 | tree u = build_omp_clause (clause_loc, OMP_CLAUSE_MAP); | |
12186 | OMP_CLAUSE_DECL (u) = t; | |
12187 | OMP_CLAUSE_CHAIN (u) = list; | |
12188 | OMP_CLAUSE_SET_MAP_KIND (u, kind); | |
12189 | list = u; | |
12190 | } | |
12191 | if (always == 1) | |
12192 | { | |
12193 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
12194 | return list; | |
12195 | } | |
12196 | } | |
2169f33b | 12197 | |
bc7bff74 | 12198 | nl = c_parser_omp_variable_list (parser, clause_loc, OMP_CLAUSE_MAP, list); |
12199 | ||
12200 | for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c)) | |
ca4c3545 | 12201 | OMP_CLAUSE_SET_MAP_KIND (c, kind); |
bc7bff74 | 12202 | |
12203 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
12204 | return nl; | |
12205 | } | |
12206 | ||
12207 | /* OpenMP 4.0: | |
12208 | device ( expression ) */ | |
12209 | ||
12210 | static tree | |
12211 | c_parser_omp_clause_device (c_parser *parser, tree list) | |
12212 | { | |
12213 | location_t clause_loc = c_parser_peek_token (parser)->location; | |
12214 | if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
1e8e9920 | 12215 | { |
bc7bff74 | 12216 | tree c, t = c_parser_expr_no_commas (parser, NULL).value; |
12217 | mark_exp_read (t); | |
12218 | t = c_fully_fold (t, false, NULL); | |
12219 | ||
12220 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
12221 | ||
12222 | if (!INTEGRAL_TYPE_P (TREE_TYPE (t))) | |
2169f33b | 12223 | { |
bc7bff74 | 12224 | c_parser_error (parser, "expected integer expression"); |
12225 | return list; | |
2169f33b | 12226 | } |
1e8e9920 | 12227 | |
bc7bff74 | 12228 | check_no_duplicate_clause (list, OMP_CLAUSE_DEVICE, "device"); |
1e8e9920 | 12229 | |
bc7bff74 | 12230 | c = build_omp_clause (clause_loc, OMP_CLAUSE_DEVICE); |
12231 | OMP_CLAUSE_DEVICE_ID (c) = t; | |
12232 | OMP_CLAUSE_CHAIN (c) = list; | |
12233 | list = c; | |
12234 | } | |
1e8e9920 | 12235 | |
bc7bff74 | 12236 | return list; |
12237 | } | |
2169f33b | 12238 | |
bc7bff74 | 12239 | /* OpenMP 4.0: |
12240 | dist_schedule ( static ) | |
12241 | dist_schedule ( static , expression ) */ | |
1e8e9920 | 12242 | |
bc7bff74 | 12243 | static tree |
12244 | c_parser_omp_clause_dist_schedule (c_parser *parser, tree list) | |
12245 | { | |
12246 | tree c, t = NULL_TREE; | |
12247 | location_t loc = c_parser_peek_token (parser)->location; | |
12248 | ||
12249 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
12250 | return list; | |
12251 | ||
12252 | if (!c_parser_next_token_is_keyword (parser, RID_STATIC)) | |
2169f33b | 12253 | { |
bc7bff74 | 12254 | c_parser_error (parser, "invalid dist_schedule kind"); |
12255 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, | |
12256 | "expected %<)%>"); | |
12257 | return list; | |
2169f33b | 12258 | } |
1e8e9920 | 12259 | |
bc7bff74 | 12260 | c_parser_consume_token (parser); |
12261 | if (c_parser_next_token_is (parser, CPP_COMMA)) | |
12262 | { | |
12263 | c_parser_consume_token (parser); | |
1e8e9920 | 12264 | |
bc7bff74 | 12265 | t = c_parser_expr_no_commas (parser, NULL).value; |
12266 | mark_exp_read (t); | |
12267 | t = c_fully_fold (t, false, NULL); | |
12268 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
12269 | } | |
12270 | else | |
12271 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, | |
12272 | "expected %<,%> or %<)%>"); | |
1e8e9920 | 12273 | |
bc7bff74 | 12274 | check_no_duplicate_clause (list, OMP_CLAUSE_SCHEDULE, "schedule"); |
12275 | if (t == error_mark_node) | |
12276 | return list; | |
1e8e9920 | 12277 | |
bc7bff74 | 12278 | c = build_omp_clause (loc, OMP_CLAUSE_DIST_SCHEDULE); |
12279 | OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c) = t; | |
12280 | OMP_CLAUSE_CHAIN (c) = list; | |
12281 | return c; | |
1e8e9920 | 12282 | } |
12283 | ||
bc7bff74 | 12284 | /* OpenMP 4.0: |
12285 | proc_bind ( proc-bind-kind ) | |
e60a6f7b | 12286 | |
bc7bff74 | 12287 | proc-bind-kind: |
12288 | master | close | spread */ | |
1e8e9920 | 12289 | |
12290 | static tree | |
bc7bff74 | 12291 | c_parser_omp_clause_proc_bind (c_parser *parser, tree list) |
1e8e9920 | 12292 | { |
bc7bff74 | 12293 | location_t clause_loc = c_parser_peek_token (parser)->location; |
12294 | enum omp_clause_proc_bind_kind kind; | |
12295 | tree c; | |
1e8e9920 | 12296 | |
bc7bff74 | 12297 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) |
12298 | return list; | |
12299 | ||
12300 | if (c_parser_next_token_is (parser, CPP_NAME)) | |
1e8e9920 | 12301 | { |
bc7bff74 | 12302 | const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
12303 | if (strcmp ("master", p) == 0) | |
12304 | kind = OMP_CLAUSE_PROC_BIND_MASTER; | |
12305 | else if (strcmp ("close", p) == 0) | |
12306 | kind = OMP_CLAUSE_PROC_BIND_CLOSE; | |
12307 | else if (strcmp ("spread", p) == 0) | |
12308 | kind = OMP_CLAUSE_PROC_BIND_SPREAD; | |
1e8e9920 | 12309 | else |
bc7bff74 | 12310 | goto invalid_kind; |
1e8e9920 | 12311 | } |
bc7bff74 | 12312 | else |
12313 | goto invalid_kind; | |
1e8e9920 | 12314 | |
bc7bff74 | 12315 | c_parser_consume_token (parser); |
12316 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
12317 | c = build_omp_clause (clause_loc, OMP_CLAUSE_PROC_BIND); | |
12318 | OMP_CLAUSE_PROC_BIND_KIND (c) = kind; | |
12319 | OMP_CLAUSE_CHAIN (c) = list; | |
12320 | return c; | |
1e8e9920 | 12321 | |
bc7bff74 | 12322 | invalid_kind: |
12323 | c_parser_error (parser, "invalid proc_bind kind"); | |
12324 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
12325 | return list; | |
12326 | } | |
1e8e9920 | 12327 | |
bc7bff74 | 12328 | /* OpenMP 4.0: |
12329 | to ( variable-list ) */ | |
1e8e9920 | 12330 | |
bc7bff74 | 12331 | static tree |
12332 | c_parser_omp_clause_to (c_parser *parser, tree list) | |
1e8e9920 | 12333 | { |
bc7bff74 | 12334 | return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_TO, list); |
1e8e9920 | 12335 | } |
12336 | ||
bc7bff74 | 12337 | /* OpenMP 4.0: |
12338 | from ( variable-list ) */ | |
1e8e9920 | 12339 | |
12340 | static tree | |
bc7bff74 | 12341 | c_parser_omp_clause_from (c_parser *parser, tree list) |
1e8e9920 | 12342 | { |
bc7bff74 | 12343 | return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_FROM, list); |
12344 | } | |
fd6481cf | 12345 | |
bc7bff74 | 12346 | /* OpenMP 4.0: |
12347 | uniform ( variable-list ) */ | |
fd6481cf | 12348 | |
bc7bff74 | 12349 | static tree |
12350 | c_parser_omp_clause_uniform (c_parser *parser, tree list) | |
12351 | { | |
12352 | /* The clauses location. */ | |
12353 | location_t loc = c_parser_peek_token (parser)->location; | |
1e8e9920 | 12354 | |
bc7bff74 | 12355 | if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) |
1e8e9920 | 12356 | { |
bc7bff74 | 12357 | list = c_parser_omp_variable_list (parser, loc, OMP_CLAUSE_UNIFORM, |
12358 | list); | |
12359 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
1e8e9920 | 12360 | } |
bc7bff74 | 12361 | return list; |
12362 | } | |
1e8e9920 | 12363 | |
ca4c3545 | 12364 | /* Parse all OpenACC clauses. The set clauses allowed by the directive |
12365 | is a bitmask in MASK. Return the list of clauses found. */ | |
12366 | ||
12367 | static tree | |
12368 | c_parser_oacc_all_clauses (c_parser *parser, omp_clause_mask mask, | |
12369 | const char *where, bool finish_p = true) | |
12370 | { | |
12371 | tree clauses = NULL; | |
12372 | bool first = true; | |
12373 | ||
12374 | while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL)) | |
12375 | { | |
12376 | location_t here; | |
12377 | pragma_omp_clause c_kind; | |
12378 | const char *c_name; | |
12379 | tree prev = clauses; | |
12380 | ||
12381 | if (!first && c_parser_next_token_is (parser, CPP_COMMA)) | |
12382 | c_parser_consume_token (parser); | |
12383 | ||
12384 | here = c_parser_peek_token (parser)->location; | |
12385 | c_kind = c_parser_omp_clause_name (parser); | |
12386 | ||
12387 | switch (c_kind) | |
12388 | { | |
12389 | case PRAGMA_OACC_CLAUSE_ASYNC: | |
12390 | clauses = c_parser_oacc_clause_async (parser, clauses); | |
12391 | c_name = "async"; | |
12392 | break; | |
12393 | case PRAGMA_OACC_CLAUSE_COLLAPSE: | |
12394 | clauses = c_parser_omp_clause_collapse (parser, clauses); | |
12395 | c_name = "collapse"; | |
12396 | break; | |
12397 | case PRAGMA_OACC_CLAUSE_COPY: | |
12398 | clauses = c_parser_oacc_data_clause (parser, c_kind, clauses); | |
12399 | c_name = "copy"; | |
12400 | break; | |
12401 | case PRAGMA_OACC_CLAUSE_COPYIN: | |
12402 | clauses = c_parser_oacc_data_clause (parser, c_kind, clauses); | |
12403 | c_name = "copyin"; | |
12404 | break; | |
12405 | case PRAGMA_OACC_CLAUSE_COPYOUT: | |
12406 | clauses = c_parser_oacc_data_clause (parser, c_kind, clauses); | |
12407 | c_name = "copyout"; | |
12408 | break; | |
12409 | case PRAGMA_OACC_CLAUSE_CREATE: | |
12410 | clauses = c_parser_oacc_data_clause (parser, c_kind, clauses); | |
12411 | c_name = "create"; | |
12412 | break; | |
12413 | case PRAGMA_OACC_CLAUSE_DELETE: | |
12414 | clauses = c_parser_oacc_data_clause (parser, c_kind, clauses); | |
12415 | c_name = "delete"; | |
12416 | break; | |
12417 | case PRAGMA_OACC_CLAUSE_DEVICE: | |
12418 | clauses = c_parser_oacc_data_clause (parser, c_kind, clauses); | |
12419 | c_name = "device"; | |
12420 | break; | |
12421 | case PRAGMA_OACC_CLAUSE_DEVICEPTR: | |
12422 | clauses = c_parser_oacc_data_clause_deviceptr (parser, clauses); | |
12423 | c_name = "deviceptr"; | |
12424 | break; | |
12425 | case PRAGMA_OACC_CLAUSE_FIRSTPRIVATE: | |
12426 | clauses = c_parser_omp_clause_firstprivate (parser, clauses); | |
12427 | c_name = "firstprivate"; | |
12428 | break; | |
12429 | case PRAGMA_OACC_CLAUSE_HOST: | |
12430 | clauses = c_parser_oacc_data_clause (parser, c_kind, clauses); | |
12431 | c_name = "host"; | |
12432 | break; | |
12433 | case PRAGMA_OACC_CLAUSE_IF: | |
43895be5 | 12434 | clauses = c_parser_omp_clause_if (parser, clauses, false); |
ca4c3545 | 12435 | c_name = "if"; |
12436 | break; | |
12437 | case PRAGMA_OACC_CLAUSE_NUM_GANGS: | |
12438 | clauses = c_parser_omp_clause_num_gangs (parser, clauses); | |
12439 | c_name = "num_gangs"; | |
12440 | break; | |
12441 | case PRAGMA_OACC_CLAUSE_NUM_WORKERS: | |
12442 | clauses = c_parser_omp_clause_num_workers (parser, clauses); | |
12443 | c_name = "num_workers"; | |
12444 | break; | |
12445 | case PRAGMA_OACC_CLAUSE_PRESENT: | |
12446 | clauses = c_parser_oacc_data_clause (parser, c_kind, clauses); | |
12447 | c_name = "present"; | |
12448 | break; | |
12449 | case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY: | |
12450 | clauses = c_parser_oacc_data_clause (parser, c_kind, clauses); | |
12451 | c_name = "present_or_copy"; | |
12452 | break; | |
12453 | case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN: | |
12454 | clauses = c_parser_oacc_data_clause (parser, c_kind, clauses); | |
12455 | c_name = "present_or_copyin"; | |
12456 | break; | |
12457 | case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT: | |
12458 | clauses = c_parser_oacc_data_clause (parser, c_kind, clauses); | |
12459 | c_name = "present_or_copyout"; | |
12460 | break; | |
12461 | case PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE: | |
12462 | clauses = c_parser_oacc_data_clause (parser, c_kind, clauses); | |
12463 | c_name = "present_or_create"; | |
12464 | break; | |
12465 | case PRAGMA_OACC_CLAUSE_PRIVATE: | |
12466 | clauses = c_parser_omp_clause_private (parser, clauses); | |
12467 | c_name = "private"; | |
12468 | break; | |
12469 | case PRAGMA_OACC_CLAUSE_REDUCTION: | |
12470 | clauses = c_parser_omp_clause_reduction (parser, clauses); | |
12471 | c_name = "reduction"; | |
12472 | break; | |
12473 | case PRAGMA_OACC_CLAUSE_SELF: | |
12474 | clauses = c_parser_oacc_data_clause (parser, c_kind, clauses); | |
12475 | c_name = "self"; | |
12476 | break; | |
12477 | case PRAGMA_OACC_CLAUSE_VECTOR_LENGTH: | |
12478 | clauses = c_parser_omp_clause_vector_length (parser, clauses); | |
12479 | c_name = "vector_length"; | |
12480 | break; | |
12481 | case PRAGMA_OACC_CLAUSE_WAIT: | |
12482 | clauses = c_parser_oacc_clause_wait (parser, clauses); | |
12483 | c_name = "wait"; | |
12484 | break; | |
12485 | default: | |
12486 | c_parser_error (parser, "expected %<#pragma acc%> clause"); | |
12487 | goto saw_error; | |
12488 | } | |
12489 | ||
12490 | first = false; | |
12491 | ||
c43f93d7 | 12492 | if (((mask >> c_kind) & 1) == 0) |
ca4c3545 | 12493 | { |
12494 | /* Remove the invalid clause(s) from the list to avoid | |
12495 | confusing the rest of the compiler. */ | |
12496 | clauses = prev; | |
12497 | error_at (here, "%qs is not valid for %qs", c_name, where); | |
12498 | } | |
12499 | } | |
12500 | ||
12501 | saw_error: | |
12502 | c_parser_skip_to_pragma_eol (parser); | |
12503 | ||
12504 | if (finish_p) | |
43895be5 | 12505 | return c_finish_omp_clauses (clauses, false); |
ca4c3545 | 12506 | |
12507 | return clauses; | |
12508 | } | |
12509 | ||
bc7bff74 | 12510 | /* Parse all OpenMP clauses. The set clauses allowed by the directive |
ca4c3545 | 12511 | is a bitmask in MASK. Return the list of clauses found. */ |
1e8e9920 | 12512 | |
bc7bff74 | 12513 | static tree |
12514 | c_parser_omp_all_clauses (c_parser *parser, omp_clause_mask mask, | |
12515 | const char *where, bool finish_p = true) | |
12516 | { | |
12517 | tree clauses = NULL; | |
74acc703 | 12518 | bool first = true, cilk_simd_fn = false; |
1e8e9920 | 12519 | |
bc7bff74 | 12520 | while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL)) |
12521 | { | |
12522 | location_t here; | |
12523 | pragma_omp_clause c_kind; | |
12524 | const char *c_name; | |
12525 | tree prev = clauses; | |
12526 | ||
12527 | if (!first && c_parser_next_token_is (parser, CPP_COMMA)) | |
12528 | c_parser_consume_token (parser); | |
12529 | ||
12530 | here = c_parser_peek_token (parser)->location; | |
12531 | c_kind = c_parser_omp_clause_name (parser); | |
12532 | ||
12533 | switch (c_kind) | |
fd6481cf | 12534 | { |
bc7bff74 | 12535 | case PRAGMA_OMP_CLAUSE_COLLAPSE: |
12536 | clauses = c_parser_omp_clause_collapse (parser, clauses); | |
12537 | c_name = "collapse"; | |
1e8e9920 | 12538 | break; |
bc7bff74 | 12539 | case PRAGMA_OMP_CLAUSE_COPYIN: |
12540 | clauses = c_parser_omp_clause_copyin (parser, clauses); | |
12541 | c_name = "copyin"; | |
1e8e9920 | 12542 | break; |
bc7bff74 | 12543 | case PRAGMA_OMP_CLAUSE_COPYPRIVATE: |
12544 | clauses = c_parser_omp_clause_copyprivate (parser, clauses); | |
12545 | c_name = "copyprivate"; | |
1e8e9920 | 12546 | break; |
bc7bff74 | 12547 | case PRAGMA_OMP_CLAUSE_DEFAULT: |
12548 | clauses = c_parser_omp_clause_default (parser, clauses); | |
12549 | c_name = "default"; | |
1e8e9920 | 12550 | break; |
bc7bff74 | 12551 | case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE: |
12552 | clauses = c_parser_omp_clause_firstprivate (parser, clauses); | |
12553 | c_name = "firstprivate"; | |
1e8e9920 | 12554 | break; |
bc7bff74 | 12555 | case PRAGMA_OMP_CLAUSE_FINAL: |
12556 | clauses = c_parser_omp_clause_final (parser, clauses); | |
12557 | c_name = "final"; | |
1e8e9920 | 12558 | break; |
43895be5 | 12559 | case PRAGMA_OMP_CLAUSE_GRAINSIZE: |
12560 | clauses = c_parser_omp_clause_grainsize (parser, clauses); | |
12561 | c_name = "grainsize"; | |
12562 | break; | |
12563 | case PRAGMA_OMP_CLAUSE_HINT: | |
12564 | clauses = c_parser_omp_clause_hint (parser, clauses); | |
12565 | c_name = "hint"; | |
12566 | break; | |
12567 | case PRAGMA_OMP_CLAUSE_DEFAULTMAP: | |
12568 | clauses = c_parser_omp_clause_defaultmap (parser, clauses); | |
12569 | c_name = "defaultmap"; | |
12570 | break; | |
bc7bff74 | 12571 | case PRAGMA_OMP_CLAUSE_IF: |
43895be5 | 12572 | clauses = c_parser_omp_clause_if (parser, clauses, true); |
bc7bff74 | 12573 | c_name = "if"; |
1e8e9920 | 12574 | break; |
bc7bff74 | 12575 | case PRAGMA_OMP_CLAUSE_LASTPRIVATE: |
12576 | clauses = c_parser_omp_clause_lastprivate (parser, clauses); | |
12577 | c_name = "lastprivate"; | |
1e8e9920 | 12578 | break; |
bc7bff74 | 12579 | case PRAGMA_OMP_CLAUSE_MERGEABLE: |
12580 | clauses = c_parser_omp_clause_mergeable (parser, clauses); | |
12581 | c_name = "mergeable"; | |
1e8e9920 | 12582 | break; |
bc7bff74 | 12583 | case PRAGMA_OMP_CLAUSE_NOWAIT: |
12584 | clauses = c_parser_omp_clause_nowait (parser, clauses); | |
12585 | c_name = "nowait"; | |
12586 | break; | |
43895be5 | 12587 | case PRAGMA_OMP_CLAUSE_NUM_TASKS: |
12588 | clauses = c_parser_omp_clause_num_tasks (parser, clauses); | |
12589 | c_name = "num_tasks"; | |
12590 | break; | |
bc7bff74 | 12591 | case PRAGMA_OMP_CLAUSE_NUM_THREADS: |
12592 | clauses = c_parser_omp_clause_num_threads (parser, clauses); | |
12593 | c_name = "num_threads"; | |
12594 | break; | |
12595 | case PRAGMA_OMP_CLAUSE_ORDERED: | |
12596 | clauses = c_parser_omp_clause_ordered (parser, clauses); | |
12597 | c_name = "ordered"; | |
12598 | break; | |
43895be5 | 12599 | case PRAGMA_OMP_CLAUSE_PRIORITY: |
12600 | clauses = c_parser_omp_clause_priority (parser, clauses); | |
12601 | c_name = "priority"; | |
12602 | break; | |
bc7bff74 | 12603 | case PRAGMA_OMP_CLAUSE_PRIVATE: |
12604 | clauses = c_parser_omp_clause_private (parser, clauses); | |
12605 | c_name = "private"; | |
12606 | break; | |
12607 | case PRAGMA_OMP_CLAUSE_REDUCTION: | |
12608 | clauses = c_parser_omp_clause_reduction (parser, clauses); | |
12609 | c_name = "reduction"; | |
12610 | break; | |
12611 | case PRAGMA_OMP_CLAUSE_SCHEDULE: | |
12612 | clauses = c_parser_omp_clause_schedule (parser, clauses); | |
12613 | c_name = "schedule"; | |
12614 | break; | |
12615 | case PRAGMA_OMP_CLAUSE_SHARED: | |
12616 | clauses = c_parser_omp_clause_shared (parser, clauses); | |
12617 | c_name = "shared"; | |
12618 | break; | |
12619 | case PRAGMA_OMP_CLAUSE_UNTIED: | |
12620 | clauses = c_parser_omp_clause_untied (parser, clauses); | |
12621 | c_name = "untied"; | |
12622 | break; | |
12623 | case PRAGMA_OMP_CLAUSE_INBRANCH: | |
74acc703 | 12624 | case PRAGMA_CILK_CLAUSE_MASK: |
bc7bff74 | 12625 | clauses = c_parser_omp_clause_branch (parser, OMP_CLAUSE_INBRANCH, |
12626 | clauses); | |
12627 | c_name = "inbranch"; | |
12628 | break; | |
12629 | case PRAGMA_OMP_CLAUSE_NOTINBRANCH: | |
74acc703 | 12630 | case PRAGMA_CILK_CLAUSE_NOMASK: |
bc7bff74 | 12631 | clauses = c_parser_omp_clause_branch (parser, OMP_CLAUSE_NOTINBRANCH, |
12632 | clauses); | |
12633 | c_name = "notinbranch"; | |
12634 | break; | |
12635 | case PRAGMA_OMP_CLAUSE_PARALLEL: | |
12636 | clauses | |
12637 | = c_parser_omp_clause_cancelkind (parser, OMP_CLAUSE_PARALLEL, | |
12638 | clauses); | |
12639 | c_name = "parallel"; | |
12640 | if (!first) | |
2169f33b | 12641 | { |
bc7bff74 | 12642 | clause_not_first: |
12643 | error_at (here, "%qs must be the first clause of %qs", | |
12644 | c_name, where); | |
12645 | clauses = prev; | |
12646 | } | |
12647 | break; | |
12648 | case PRAGMA_OMP_CLAUSE_FOR: | |
12649 | clauses | |
12650 | = c_parser_omp_clause_cancelkind (parser, OMP_CLAUSE_FOR, | |
12651 | clauses); | |
12652 | c_name = "for"; | |
12653 | if (!first) | |
12654 | goto clause_not_first; | |
12655 | break; | |
12656 | case PRAGMA_OMP_CLAUSE_SECTIONS: | |
12657 | clauses | |
12658 | = c_parser_omp_clause_cancelkind (parser, OMP_CLAUSE_SECTIONS, | |
12659 | clauses); | |
12660 | c_name = "sections"; | |
12661 | if (!first) | |
12662 | goto clause_not_first; | |
12663 | break; | |
12664 | case PRAGMA_OMP_CLAUSE_TASKGROUP: | |
12665 | clauses | |
12666 | = c_parser_omp_clause_cancelkind (parser, OMP_CLAUSE_TASKGROUP, | |
12667 | clauses); | |
12668 | c_name = "taskgroup"; | |
12669 | if (!first) | |
12670 | goto clause_not_first; | |
12671 | break; | |
43895be5 | 12672 | case PRAGMA_OMP_CLAUSE_LINK: |
12673 | clauses | |
12674 | = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_LINK, clauses); | |
12675 | c_name = "link"; | |
12676 | break; | |
bc7bff74 | 12677 | case PRAGMA_OMP_CLAUSE_TO: |
43895be5 | 12678 | if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINK)) != 0) |
12679 | clauses | |
12680 | = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_TO_DECLARE, | |
12681 | clauses); | |
12682 | else | |
12683 | clauses = c_parser_omp_clause_to (parser, clauses); | |
bc7bff74 | 12684 | c_name = "to"; |
12685 | break; | |
12686 | case PRAGMA_OMP_CLAUSE_FROM: | |
12687 | clauses = c_parser_omp_clause_from (parser, clauses); | |
12688 | c_name = "from"; | |
12689 | break; | |
12690 | case PRAGMA_OMP_CLAUSE_UNIFORM: | |
12691 | clauses = c_parser_omp_clause_uniform (parser, clauses); | |
12692 | c_name = "uniform"; | |
12693 | break; | |
12694 | case PRAGMA_OMP_CLAUSE_NUM_TEAMS: | |
12695 | clauses = c_parser_omp_clause_num_teams (parser, clauses); | |
12696 | c_name = "num_teams"; | |
12697 | break; | |
12698 | case PRAGMA_OMP_CLAUSE_THREAD_LIMIT: | |
12699 | clauses = c_parser_omp_clause_thread_limit (parser, clauses); | |
12700 | c_name = "thread_limit"; | |
12701 | break; | |
12702 | case PRAGMA_OMP_CLAUSE_ALIGNED: | |
12703 | clauses = c_parser_omp_clause_aligned (parser, clauses); | |
12704 | c_name = "aligned"; | |
12705 | break; | |
74acc703 | 12706 | case PRAGMA_OMP_CLAUSE_LINEAR: |
12707 | if (((mask >> PRAGMA_CILK_CLAUSE_VECTORLENGTH) & 1) != 0) | |
12708 | cilk_simd_fn = true; | |
12709 | clauses = c_parser_omp_clause_linear (parser, clauses, cilk_simd_fn); | |
bc7bff74 | 12710 | c_name = "linear"; |
12711 | break; | |
12712 | case PRAGMA_OMP_CLAUSE_DEPEND: | |
12713 | clauses = c_parser_omp_clause_depend (parser, clauses); | |
12714 | c_name = "depend"; | |
12715 | break; | |
12716 | case PRAGMA_OMP_CLAUSE_MAP: | |
12717 | clauses = c_parser_omp_clause_map (parser, clauses); | |
12718 | c_name = "map"; | |
12719 | break; | |
43895be5 | 12720 | case PRAGMA_OMP_CLAUSE_USE_DEVICE_PTR: |
12721 | clauses = c_parser_omp_clause_use_device_ptr (parser, clauses); | |
12722 | c_name = "use_device_ptr"; | |
12723 | break; | |
12724 | case PRAGMA_OMP_CLAUSE_IS_DEVICE_PTR: | |
12725 | clauses = c_parser_omp_clause_is_device_ptr (parser, clauses); | |
12726 | c_name = "is_device_ptr"; | |
12727 | break; | |
bc7bff74 | 12728 | case PRAGMA_OMP_CLAUSE_DEVICE: |
12729 | clauses = c_parser_omp_clause_device (parser, clauses); | |
12730 | c_name = "device"; | |
12731 | break; | |
12732 | case PRAGMA_OMP_CLAUSE_DIST_SCHEDULE: | |
12733 | clauses = c_parser_omp_clause_dist_schedule (parser, clauses); | |
12734 | c_name = "dist_schedule"; | |
12735 | break; | |
12736 | case PRAGMA_OMP_CLAUSE_PROC_BIND: | |
12737 | clauses = c_parser_omp_clause_proc_bind (parser, clauses); | |
12738 | c_name = "proc_bind"; | |
12739 | break; | |
12740 | case PRAGMA_OMP_CLAUSE_SAFELEN: | |
12741 | clauses = c_parser_omp_clause_safelen (parser, clauses); | |
12742 | c_name = "safelen"; | |
12743 | break; | |
74acc703 | 12744 | case PRAGMA_CILK_CLAUSE_VECTORLENGTH: |
12745 | clauses = c_parser_cilk_clause_vectorlength (parser, clauses, true); | |
12746 | c_name = "simdlen"; | |
12747 | break; | |
bc7bff74 | 12748 | case PRAGMA_OMP_CLAUSE_SIMDLEN: |
12749 | clauses = c_parser_omp_clause_simdlen (parser, clauses); | |
12750 | c_name = "simdlen"; | |
12751 | break; | |
43895be5 | 12752 | case PRAGMA_OMP_CLAUSE_NOGROUP: |
12753 | clauses = c_parser_omp_clause_nogroup (parser, clauses); | |
12754 | c_name = "nogroup"; | |
12755 | break; | |
12756 | case PRAGMA_OMP_CLAUSE_THREADS: | |
12757 | clauses | |
12758 | = c_parser_omp_clause_orderedkind (parser, OMP_CLAUSE_THREADS, | |
12759 | clauses); | |
12760 | c_name = "threads"; | |
12761 | break; | |
12762 | case PRAGMA_OMP_CLAUSE_SIMD: | |
12763 | clauses | |
12764 | = c_parser_omp_clause_orderedkind (parser, OMP_CLAUSE_SIMD, | |
12765 | clauses); | |
12766 | c_name = "simd"; | |
12767 | break; | |
1e8e9920 | 12768 | default: |
bc7bff74 | 12769 | c_parser_error (parser, "expected %<#pragma omp%> clause"); |
1e8e9920 | 12770 | goto saw_error; |
fd6481cf | 12771 | } |
1e8e9920 | 12772 | |
bc7bff74 | 12773 | first = false; |
12774 | ||
c43f93d7 | 12775 | if (((mask >> c_kind) & 1) == 0) |
fd6481cf | 12776 | { |
bc7bff74 | 12777 | /* Remove the invalid clause(s) from the list to avoid |
12778 | confusing the rest of the compiler. */ | |
12779 | clauses = prev; | |
12780 | error_at (here, "%qs is not valid for %qs", c_name, where); | |
12781 | } | |
12782 | } | |
fd6481cf | 12783 | |
bc7bff74 | 12784 | saw_error: |
12785 | c_parser_skip_to_pragma_eol (parser); | |
fd6481cf | 12786 | |
bc7bff74 | 12787 | if (finish_p) |
43895be5 | 12788 | { |
12789 | if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNIFORM)) != 0) | |
12790 | return c_finish_omp_clauses (clauses, true, true); | |
12791 | return c_finish_omp_clauses (clauses, true); | |
12792 | } | |
fd6481cf | 12793 | |
bc7bff74 | 12794 | return clauses; |
12795 | } | |
1e8e9920 | 12796 | |
ca4c3545 | 12797 | /* OpenACC 2.0, OpenMP 2.5: |
bc7bff74 | 12798 | structured-block: |
12799 | statement | |
12800 | ||
12801 | In practice, we're also interested in adding the statement to an | |
12802 | outer node. So it is convenient if we work around the fact that | |
12803 | c_parser_statement calls add_stmt. */ | |
12804 | ||
12805 | static tree | |
12806 | c_parser_omp_structured_block (c_parser *parser) | |
12807 | { | |
12808 | tree stmt = push_stmt_list (); | |
12809 | c_parser_statement (parser); | |
12810 | return pop_stmt_list (stmt); | |
12811 | } | |
12812 | ||
ca4c3545 | 12813 | /* OpenACC 2.0: |
12814 | # pragma acc cache (variable-list) new-line | |
12815 | ||
12816 | LOC is the location of the #pragma token. | |
12817 | */ | |
12818 | ||
12819 | static tree | |
12820 | c_parser_oacc_cache (location_t loc, c_parser *parser) | |
12821 | { | |
12822 | tree stmt, clauses; | |
12823 | ||
12824 | clauses = c_parser_omp_var_list_parens (parser, OMP_CLAUSE__CACHE_, NULL); | |
43895be5 | 12825 | clauses = c_finish_omp_clauses (clauses, false); |
ca4c3545 | 12826 | |
12827 | c_parser_skip_to_pragma_eol (parser); | |
12828 | ||
12829 | stmt = make_node (OACC_CACHE); | |
12830 | TREE_TYPE (stmt) = void_type_node; | |
12831 | OACC_CACHE_CLAUSES (stmt) = clauses; | |
12832 | SET_EXPR_LOCATION (stmt, loc); | |
12833 | add_stmt (stmt); | |
12834 | ||
12835 | return stmt; | |
12836 | } | |
12837 | ||
12838 | /* OpenACC 2.0: | |
12839 | # pragma acc data oacc-data-clause[optseq] new-line | |
12840 | structured-block | |
12841 | ||
12842 | LOC is the location of the #pragma token. | |
12843 | */ | |
12844 | ||
12845 | #define OACC_DATA_CLAUSE_MASK \ | |
12846 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \ | |
12847 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \ | |
12848 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \ | |
12849 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \ | |
12850 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \ | |
12851 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \ | |
12852 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \ | |
12853 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY) \ | |
12854 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \ | |
12855 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT) \ | |
12856 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) ) | |
12857 | ||
12858 | static tree | |
12859 | c_parser_oacc_data (location_t loc, c_parser *parser) | |
12860 | { | |
12861 | tree stmt, clauses, block; | |
12862 | ||
12863 | clauses = c_parser_oacc_all_clauses (parser, OACC_DATA_CLAUSE_MASK, | |
12864 | "#pragma acc data"); | |
12865 | ||
12866 | block = c_begin_omp_parallel (); | |
12867 | add_stmt (c_parser_omp_structured_block (parser)); | |
12868 | ||
12869 | stmt = c_finish_oacc_data (loc, clauses, block); | |
12870 | ||
12871 | return stmt; | |
12872 | } | |
12873 | ||
12874 | /* OpenACC 2.0: | |
12875 | # pragma acc kernels oacc-kernels-clause[optseq] new-line | |
12876 | structured-block | |
12877 | ||
12878 | LOC is the location of the #pragma token. | |
12879 | */ | |
12880 | ||
12881 | #define OACC_KERNELS_CLAUSE_MASK \ | |
12882 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \ | |
12883 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \ | |
12884 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \ | |
12885 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \ | |
12886 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \ | |
12887 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \ | |
12888 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \ | |
12889 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \ | |
12890 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY) \ | |
12891 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \ | |
12892 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT) \ | |
12893 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) \ | |
12894 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) ) | |
12895 | ||
12896 | static tree | |
12897 | c_parser_oacc_kernels (location_t loc, c_parser *parser, char *p_name) | |
12898 | { | |
12899 | tree stmt, clauses = NULL_TREE, block; | |
12900 | ||
12901 | strcat (p_name, " kernels"); | |
12902 | ||
12903 | if (c_parser_next_token_is (parser, CPP_NAME)) | |
12904 | { | |
12905 | const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); | |
12906 | if (strcmp (p, "loop") == 0) | |
12907 | { | |
12908 | c_parser_consume_token (parser); | |
12909 | block = c_begin_omp_parallel (); | |
12910 | c_parser_oacc_loop (loc, parser, p_name); | |
12911 | stmt = c_finish_oacc_kernels (loc, clauses, block); | |
12912 | OACC_KERNELS_COMBINED (stmt) = 1; | |
12913 | return stmt; | |
12914 | } | |
12915 | } | |
12916 | ||
12917 | clauses = c_parser_oacc_all_clauses (parser, OACC_KERNELS_CLAUSE_MASK, | |
12918 | p_name); | |
12919 | ||
12920 | block = c_begin_omp_parallel (); | |
12921 | add_stmt (c_parser_omp_structured_block (parser)); | |
12922 | ||
12923 | stmt = c_finish_oacc_kernels (loc, clauses, block); | |
12924 | ||
12925 | return stmt; | |
12926 | } | |
12927 | ||
12928 | /* OpenACC 2.0: | |
12929 | # pragma acc enter data oacc-enter-data-clause[optseq] new-line | |
12930 | ||
12931 | or | |
12932 | ||
12933 | # pragma acc exit data oacc-exit-data-clause[optseq] new-line | |
12934 | ||
12935 | ||
12936 | LOC is the location of the #pragma token. | |
12937 | */ | |
12938 | ||
12939 | #define OACC_ENTER_DATA_CLAUSE_MASK \ | |
12940 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \ | |
12941 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \ | |
12942 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \ | |
12943 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \ | |
12944 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \ | |
12945 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) \ | |
12946 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) ) | |
12947 | ||
12948 | #define OACC_EXIT_DATA_CLAUSE_MASK \ | |
12949 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \ | |
12950 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \ | |
12951 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \ | |
12952 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DELETE) \ | |
12953 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) ) | |
12954 | ||
12955 | static void | |
12956 | c_parser_oacc_enter_exit_data (c_parser *parser, bool enter) | |
12957 | { | |
12958 | location_t loc = c_parser_peek_token (parser)->location; | |
12959 | tree clauses, stmt; | |
12960 | ||
12961 | c_parser_consume_pragma (parser); | |
12962 | ||
12963 | if (!c_parser_next_token_is (parser, CPP_NAME)) | |
12964 | { | |
12965 | c_parser_error (parser, enter | |
12966 | ? "expected %<data%> in %<#pragma acc enter data%>" | |
12967 | : "expected %<data%> in %<#pragma acc exit data%>"); | |
12968 | c_parser_skip_to_pragma_eol (parser); | |
12969 | return; | |
12970 | } | |
12971 | ||
12972 | const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); | |
12973 | if (strcmp (p, "data") != 0) | |
12974 | { | |
12975 | c_parser_error (parser, "invalid pragma"); | |
12976 | c_parser_skip_to_pragma_eol (parser); | |
12977 | return; | |
12978 | } | |
12979 | ||
12980 | c_parser_consume_token (parser); | |
12981 | ||
12982 | if (enter) | |
12983 | clauses = c_parser_oacc_all_clauses (parser, OACC_ENTER_DATA_CLAUSE_MASK, | |
12984 | "#pragma acc enter data"); | |
12985 | else | |
12986 | clauses = c_parser_oacc_all_clauses (parser, OACC_EXIT_DATA_CLAUSE_MASK, | |
12987 | "#pragma acc exit data"); | |
12988 | ||
12989 | if (find_omp_clause (clauses, OMP_CLAUSE_MAP) == NULL_TREE) | |
12990 | { | |
12991 | error_at (loc, enter | |
12992 | ? "%<#pragma acc enter data%> has no data movement clause" | |
12993 | : "%<#pragma acc exit data%> has no data movement clause"); | |
12994 | return; | |
12995 | } | |
12996 | ||
05a827ce | 12997 | stmt = enter ? make_node (OACC_ENTER_DATA) : make_node (OACC_EXIT_DATA); |
ca4c3545 | 12998 | TREE_TYPE (stmt) = void_type_node; |
95cfd391 | 12999 | OMP_STANDALONE_CLAUSES (stmt) = clauses; |
ca4c3545 | 13000 | SET_EXPR_LOCATION (stmt, loc); |
13001 | add_stmt (stmt); | |
13002 | } | |
13003 | ||
13004 | ||
13005 | /* OpenACC 2.0: | |
13006 | ||
13007 | # pragma acc loop oacc-loop-clause[optseq] new-line | |
13008 | structured-block | |
13009 | ||
13010 | LOC is the location of the #pragma token. | |
13011 | */ | |
13012 | ||
13013 | #define OACC_LOOP_CLAUSE_MASK \ | |
13014 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COLLAPSE) \ | |
13015 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_REDUCTION) ) | |
13016 | ||
13017 | static tree | |
13018 | c_parser_oacc_loop (location_t loc, c_parser *parser, char *p_name) | |
13019 | { | |
13020 | tree stmt, clauses, block; | |
13021 | ||
13022 | strcat (p_name, " loop"); | |
13023 | ||
13024 | clauses = c_parser_oacc_all_clauses (parser, OACC_LOOP_CLAUSE_MASK, p_name); | |
13025 | ||
13026 | block = c_begin_compound_stmt (true); | |
13027 | stmt = c_parser_omp_for_loop (loc, parser, OACC_LOOP, clauses, NULL); | |
13028 | block = c_end_compound_stmt (loc, block, true); | |
13029 | add_stmt (block); | |
13030 | ||
13031 | return stmt; | |
13032 | } | |
13033 | ||
13034 | /* OpenACC 2.0: | |
13035 | # pragma acc parallel oacc-parallel-clause[optseq] new-line | |
13036 | structured-block | |
13037 | ||
13038 | LOC is the location of the #pragma token. | |
13039 | */ | |
13040 | ||
13041 | #define OACC_PARALLEL_CLAUSE_MASK \ | |
13042 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \ | |
13043 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \ | |
13044 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \ | |
13045 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \ | |
13046 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \ | |
13047 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \ | |
13048 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \ | |
13049 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_GANGS) \ | |
13050 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_WORKERS) \ | |
13051 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \ | |
13052 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY) \ | |
13053 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \ | |
13054 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT) \ | |
13055 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) \ | |
13056 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_REDUCTION) \ | |
13057 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR_LENGTH) \ | |
13058 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) ) | |
13059 | ||
13060 | static tree | |
13061 | c_parser_oacc_parallel (location_t loc, c_parser *parser, char *p_name) | |
13062 | { | |
13063 | tree stmt, clauses = NULL_TREE, block; | |
13064 | ||
13065 | strcat (p_name, " parallel"); | |
13066 | ||
13067 | if (c_parser_next_token_is (parser, CPP_NAME)) | |
13068 | { | |
13069 | const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); | |
13070 | if (strcmp (p, "loop") == 0) | |
13071 | { | |
13072 | c_parser_consume_token (parser); | |
13073 | block = c_begin_omp_parallel (); | |
13074 | c_parser_oacc_loop (loc, parser, p_name); | |
13075 | stmt = c_finish_oacc_parallel (loc, clauses, block); | |
13076 | OACC_PARALLEL_COMBINED (stmt) = 1; | |
13077 | return stmt; | |
13078 | } | |
13079 | } | |
13080 | ||
13081 | clauses = c_parser_oacc_all_clauses (parser, OACC_PARALLEL_CLAUSE_MASK, | |
13082 | p_name); | |
13083 | ||
13084 | block = c_begin_omp_parallel (); | |
13085 | add_stmt (c_parser_omp_structured_block (parser)); | |
13086 | ||
13087 | stmt = c_finish_oacc_parallel (loc, clauses, block); | |
13088 | ||
13089 | return stmt; | |
13090 | } | |
13091 | ||
13092 | /* OpenACC 2.0: | |
13093 | # pragma acc update oacc-update-clause[optseq] new-line | |
13094 | */ | |
13095 | ||
13096 | #define OACC_UPDATE_CLAUSE_MASK \ | |
13097 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \ | |
13098 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICE) \ | |
13099 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_HOST) \ | |
13100 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \ | |
13101 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SELF) \ | |
13102 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) ) | |
13103 | ||
13104 | static void | |
13105 | c_parser_oacc_update (c_parser *parser) | |
13106 | { | |
13107 | location_t loc = c_parser_peek_token (parser)->location; | |
13108 | ||
13109 | c_parser_consume_pragma (parser); | |
13110 | ||
13111 | tree clauses = c_parser_oacc_all_clauses (parser, OACC_UPDATE_CLAUSE_MASK, | |
13112 | "#pragma acc update"); | |
13113 | if (find_omp_clause (clauses, OMP_CLAUSE_MAP) == NULL_TREE) | |
13114 | { | |
13115 | error_at (loc, | |
13116 | "%<#pragma acc update%> must contain at least one " | |
13117 | "%<device%> or %<host/self%> clause"); | |
13118 | return; | |
13119 | } | |
13120 | ||
13121 | if (parser->error) | |
13122 | return; | |
13123 | ||
13124 | tree stmt = make_node (OACC_UPDATE); | |
13125 | TREE_TYPE (stmt) = void_type_node; | |
13126 | OACC_UPDATE_CLAUSES (stmt) = clauses; | |
13127 | SET_EXPR_LOCATION (stmt, loc); | |
13128 | add_stmt (stmt); | |
13129 | } | |
13130 | ||
13131 | /* OpenACC 2.0: | |
13132 | # pragma acc wait [(intseq)] oacc-wait-clause[optseq] new-line | |
13133 | ||
13134 | LOC is the location of the #pragma token. | |
13135 | */ | |
13136 | ||
13137 | #define OACC_WAIT_CLAUSE_MASK \ | |
13138 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) ) | |
13139 | ||
13140 | static tree | |
13141 | c_parser_oacc_wait (location_t loc, c_parser *parser, char *p_name) | |
13142 | { | |
13143 | tree clauses, list = NULL_TREE, stmt = NULL_TREE; | |
13144 | ||
13145 | if (c_parser_peek_token (parser)->type == CPP_OPEN_PAREN) | |
13146 | list = c_parser_oacc_wait_list (parser, loc, list); | |
13147 | ||
13148 | strcpy (p_name, " wait"); | |
13149 | clauses = c_parser_oacc_all_clauses (parser, OACC_WAIT_CLAUSE_MASK, p_name); | |
13150 | stmt = c_finish_oacc_wait (loc, list, clauses); | |
13151 | ||
13152 | return stmt; | |
13153 | } | |
13154 | ||
bc7bff74 | 13155 | /* OpenMP 2.5: |
13156 | # pragma omp atomic new-line | |
13157 | expression-stmt | |
13158 | ||
13159 | expression-stmt: | |
13160 | x binop= expr | x++ | ++x | x-- | --x | |
13161 | binop: | |
13162 | +, *, -, /, &, ^, |, <<, >> | |
13163 | ||
13164 | where x is an lvalue expression with scalar type. | |
13165 | ||
13166 | OpenMP 3.1: | |
13167 | # pragma omp atomic new-line | |
13168 | update-stmt | |
13169 | ||
13170 | # pragma omp atomic read new-line | |
13171 | read-stmt | |
13172 | ||
13173 | # pragma omp atomic write new-line | |
13174 | write-stmt | |
13175 | ||
13176 | # pragma omp atomic update new-line | |
13177 | update-stmt | |
13178 | ||
13179 | # pragma omp atomic capture new-line | |
13180 | capture-stmt | |
13181 | ||
13182 | # pragma omp atomic capture new-line | |
13183 | capture-block | |
13184 | ||
13185 | read-stmt: | |
13186 | v = x | |
13187 | write-stmt: | |
13188 | x = expr | |
13189 | update-stmt: | |
13190 | expression-stmt | x = x binop expr | |
13191 | capture-stmt: | |
13192 | v = expression-stmt | |
13193 | capture-block: | |
13194 | { v = x; update-stmt; } | { update-stmt; v = x; } | |
13195 | ||
13196 | OpenMP 4.0: | |
13197 | update-stmt: | |
13198 | expression-stmt | x = x binop expr | x = expr binop x | |
13199 | capture-stmt: | |
13200 | v = update-stmt | |
13201 | capture-block: | |
13202 | { v = x; update-stmt; } | { update-stmt; v = x; } | { v = x; x = expr; } | |
13203 | ||
13204 | where x and v are lvalue expressions with scalar type. | |
13205 | ||
13206 | LOC is the location of the #pragma token. */ | |
13207 | ||
13208 | static void | |
13209 | c_parser_omp_atomic (location_t loc, c_parser *parser) | |
13210 | { | |
13211 | tree lhs = NULL_TREE, rhs = NULL_TREE, v = NULL_TREE; | |
13212 | tree lhs1 = NULL_TREE, rhs1 = NULL_TREE; | |
13213 | tree stmt, orig_lhs, unfolded_lhs = NULL_TREE, unfolded_lhs1 = NULL_TREE; | |
13214 | enum tree_code code = OMP_ATOMIC, opcode = NOP_EXPR; | |
13215 | struct c_expr expr; | |
13216 | location_t eloc; | |
13217 | bool structured_block = false; | |
13218 | bool swapped = false; | |
13219 | bool seq_cst = false; | |
deef87db | 13220 | bool non_lvalue_p; |
bc7bff74 | 13221 | |
e1029911 | 13222 | if (c_parser_next_token_is (parser, CPP_NAME)) |
13223 | { | |
13224 | const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); | |
13225 | if (!strcmp (p, "seq_cst")) | |
13226 | { | |
13227 | seq_cst = true; | |
13228 | c_parser_consume_token (parser); | |
13229 | if (c_parser_next_token_is (parser, CPP_COMMA) | |
13230 | && c_parser_peek_2nd_token (parser)->type == CPP_NAME) | |
13231 | c_parser_consume_token (parser); | |
13232 | } | |
13233 | } | |
bc7bff74 | 13234 | if (c_parser_next_token_is (parser, CPP_NAME)) |
13235 | { | |
13236 | const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); | |
13237 | ||
13238 | if (!strcmp (p, "read")) | |
13239 | code = OMP_ATOMIC_READ; | |
13240 | else if (!strcmp (p, "write")) | |
13241 | code = NOP_EXPR; | |
13242 | else if (!strcmp (p, "update")) | |
13243 | code = OMP_ATOMIC; | |
13244 | else if (!strcmp (p, "capture")) | |
13245 | code = OMP_ATOMIC_CAPTURE_NEW; | |
fd6481cf | 13246 | else |
bc7bff74 | 13247 | p = NULL; |
13248 | if (p) | |
13249 | c_parser_consume_token (parser); | |
13250 | } | |
e1029911 | 13251 | if (!seq_cst) |
bc7bff74 | 13252 | { |
e1029911 | 13253 | if (c_parser_next_token_is (parser, CPP_COMMA) |
13254 | && c_parser_peek_2nd_token (parser)->type == CPP_NAME) | |
13255 | c_parser_consume_token (parser); | |
13256 | ||
13257 | if (c_parser_next_token_is (parser, CPP_NAME)) | |
fd6481cf | 13258 | { |
e1029911 | 13259 | const char *p |
13260 | = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); | |
13261 | if (!strcmp (p, "seq_cst")) | |
13262 | { | |
13263 | seq_cst = true; | |
13264 | c_parser_consume_token (parser); | |
13265 | } | |
fd6481cf | 13266 | } |
bc7bff74 | 13267 | } |
13268 | c_parser_skip_to_pragma_eol (parser); | |
13269 | ||
13270 | switch (code) | |
13271 | { | |
13272 | case OMP_ATOMIC_READ: | |
13273 | case NOP_EXPR: /* atomic write */ | |
deef87db | 13274 | v = c_parser_cast_expression (parser, NULL).value; |
13275 | non_lvalue_p = !lvalue_p (v); | |
bc7bff74 | 13276 | v = c_fully_fold (v, false, NULL); |
13277 | if (v == error_mark_node) | |
13278 | goto saw_error; | |
deef87db | 13279 | if (non_lvalue_p) |
13280 | v = non_lvalue (v); | |
bc7bff74 | 13281 | loc = c_parser_peek_token (parser)->location; |
13282 | if (!c_parser_require (parser, CPP_EQ, "expected %<=%>")) | |
13283 | goto saw_error; | |
13284 | if (code == NOP_EXPR) | |
deef87db | 13285 | { |
13286 | lhs = c_parser_expression (parser).value; | |
13287 | lhs = c_fully_fold (lhs, false, NULL); | |
13288 | if (lhs == error_mark_node) | |
13289 | goto saw_error; | |
13290 | } | |
bc7bff74 | 13291 | else |
deef87db | 13292 | { |
13293 | lhs = c_parser_cast_expression (parser, NULL).value; | |
13294 | non_lvalue_p = !lvalue_p (lhs); | |
13295 | lhs = c_fully_fold (lhs, false, NULL); | |
13296 | if (lhs == error_mark_node) | |
13297 | goto saw_error; | |
13298 | if (non_lvalue_p) | |
13299 | lhs = non_lvalue (lhs); | |
13300 | } | |
bc7bff74 | 13301 | if (code == NOP_EXPR) |
13302 | { | |
13303 | /* atomic write is represented by OMP_ATOMIC with NOP_EXPR | |
13304 | opcode. */ | |
13305 | code = OMP_ATOMIC; | |
13306 | rhs = lhs; | |
13307 | lhs = v; | |
13308 | v = NULL_TREE; | |
13309 | } | |
13310 | goto done; | |
13311 | case OMP_ATOMIC_CAPTURE_NEW: | |
13312 | if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) | |
13313 | { | |
13314 | c_parser_consume_token (parser); | |
13315 | structured_block = true; | |
13316 | } | |
13317 | else | |
13318 | { | |
deef87db | 13319 | v = c_parser_cast_expression (parser, NULL).value; |
13320 | non_lvalue_p = !lvalue_p (v); | |
bc7bff74 | 13321 | v = c_fully_fold (v, false, NULL); |
13322 | if (v == error_mark_node) | |
13323 | goto saw_error; | |
deef87db | 13324 | if (non_lvalue_p) |
13325 | v = non_lvalue (v); | |
bc7bff74 | 13326 | if (!c_parser_require (parser, CPP_EQ, "expected %<=%>")) |
13327 | goto saw_error; | |
13328 | } | |
13329 | break; | |
13330 | default: | |
13331 | break; | |
13332 | } | |
13333 | ||
13334 | /* For structured_block case we don't know yet whether | |
13335 | old or new x should be captured. */ | |
13336 | restart: | |
13337 | eloc = c_parser_peek_token (parser)->location; | |
deef87db | 13338 | expr = c_parser_cast_expression (parser, NULL); |
bc7bff74 | 13339 | lhs = expr.value; |
13340 | expr = default_function_array_conversion (eloc, expr); | |
13341 | unfolded_lhs = expr.value; | |
13342 | lhs = c_fully_fold (lhs, false, NULL); | |
13343 | orig_lhs = lhs; | |
13344 | switch (TREE_CODE (lhs)) | |
13345 | { | |
13346 | case ERROR_MARK: | |
13347 | saw_error: | |
13348 | c_parser_skip_to_end_of_block_or_statement (parser); | |
13349 | if (structured_block) | |
13350 | { | |
13351 | if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) | |
13352 | c_parser_consume_token (parser); | |
13353 | else if (code == OMP_ATOMIC_CAPTURE_NEW) | |
13354 | { | |
13355 | c_parser_skip_to_end_of_block_or_statement (parser); | |
13356 | if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) | |
13357 | c_parser_consume_token (parser); | |
13358 | } | |
13359 | } | |
13360 | return; | |
13361 | ||
13362 | case POSTINCREMENT_EXPR: | |
13363 | if (code == OMP_ATOMIC_CAPTURE_NEW && !structured_block) | |
13364 | code = OMP_ATOMIC_CAPTURE_OLD; | |
13365 | /* FALLTHROUGH */ | |
13366 | case PREINCREMENT_EXPR: | |
13367 | lhs = TREE_OPERAND (lhs, 0); | |
13368 | unfolded_lhs = NULL_TREE; | |
13369 | opcode = PLUS_EXPR; | |
13370 | rhs = integer_one_node; | |
13371 | break; | |
13372 | ||
13373 | case POSTDECREMENT_EXPR: | |
13374 | if (code == OMP_ATOMIC_CAPTURE_NEW && !structured_block) | |
13375 | code = OMP_ATOMIC_CAPTURE_OLD; | |
13376 | /* FALLTHROUGH */ | |
13377 | case PREDECREMENT_EXPR: | |
13378 | lhs = TREE_OPERAND (lhs, 0); | |
13379 | unfolded_lhs = NULL_TREE; | |
13380 | opcode = MINUS_EXPR; | |
13381 | rhs = integer_one_node; | |
13382 | break; | |
13383 | ||
13384 | case COMPOUND_EXPR: | |
13385 | if (TREE_CODE (TREE_OPERAND (lhs, 0)) == SAVE_EXPR | |
13386 | && TREE_CODE (TREE_OPERAND (lhs, 1)) == COMPOUND_EXPR | |
13387 | && TREE_CODE (TREE_OPERAND (TREE_OPERAND (lhs, 1), 0)) == MODIFY_EXPR | |
13388 | && TREE_OPERAND (TREE_OPERAND (lhs, 1), 1) == TREE_OPERAND (lhs, 0) | |
13389 | && TREE_CODE (TREE_TYPE (TREE_OPERAND (TREE_OPERAND | |
13390 | (TREE_OPERAND (lhs, 1), 0), 0))) | |
13391 | == BOOLEAN_TYPE) | |
13392 | /* Undo effects of boolean_increment for post {in,de}crement. */ | |
13393 | lhs = TREE_OPERAND (TREE_OPERAND (lhs, 1), 0); | |
13394 | /* FALLTHRU */ | |
13395 | case MODIFY_EXPR: | |
13396 | if (TREE_CODE (lhs) == MODIFY_EXPR | |
13397 | && TREE_CODE (TREE_TYPE (TREE_OPERAND (lhs, 0))) == BOOLEAN_TYPE) | |
13398 | { | |
13399 | /* Undo effects of boolean_increment. */ | |
13400 | if (integer_onep (TREE_OPERAND (lhs, 1))) | |
13401 | { | |
13402 | /* This is pre or post increment. */ | |
13403 | rhs = TREE_OPERAND (lhs, 1); | |
13404 | lhs = TREE_OPERAND (lhs, 0); | |
13405 | unfolded_lhs = NULL_TREE; | |
13406 | opcode = NOP_EXPR; | |
13407 | if (code == OMP_ATOMIC_CAPTURE_NEW | |
13408 | && !structured_block | |
13409 | && TREE_CODE (orig_lhs) == COMPOUND_EXPR) | |
13410 | code = OMP_ATOMIC_CAPTURE_OLD; | |
13411 | break; | |
13412 | } | |
13413 | if (TREE_CODE (TREE_OPERAND (lhs, 1)) == TRUTH_NOT_EXPR | |
13414 | && TREE_OPERAND (lhs, 0) | |
13415 | == TREE_OPERAND (TREE_OPERAND (lhs, 1), 0)) | |
13416 | { | |
13417 | /* This is pre or post decrement. */ | |
13418 | rhs = TREE_OPERAND (lhs, 1); | |
13419 | lhs = TREE_OPERAND (lhs, 0); | |
13420 | unfolded_lhs = NULL_TREE; | |
13421 | opcode = NOP_EXPR; | |
13422 | if (code == OMP_ATOMIC_CAPTURE_NEW | |
13423 | && !structured_block | |
13424 | && TREE_CODE (orig_lhs) == COMPOUND_EXPR) | |
13425 | code = OMP_ATOMIC_CAPTURE_OLD; | |
13426 | break; | |
13427 | } | |
13428 | } | |
13429 | /* FALLTHRU */ | |
13430 | default: | |
deef87db | 13431 | if (!lvalue_p (unfolded_lhs)) |
13432 | lhs = non_lvalue (lhs); | |
bc7bff74 | 13433 | switch (c_parser_peek_token (parser)->type) |
13434 | { | |
13435 | case CPP_MULT_EQ: | |
13436 | opcode = MULT_EXPR; | |
13437 | break; | |
13438 | case CPP_DIV_EQ: | |
13439 | opcode = TRUNC_DIV_EXPR; | |
13440 | break; | |
13441 | case CPP_PLUS_EQ: | |
13442 | opcode = PLUS_EXPR; | |
13443 | break; | |
13444 | case CPP_MINUS_EQ: | |
13445 | opcode = MINUS_EXPR; | |
13446 | break; | |
13447 | case CPP_LSHIFT_EQ: | |
13448 | opcode = LSHIFT_EXPR; | |
13449 | break; | |
13450 | case CPP_RSHIFT_EQ: | |
13451 | opcode = RSHIFT_EXPR; | |
13452 | break; | |
13453 | case CPP_AND_EQ: | |
13454 | opcode = BIT_AND_EXPR; | |
13455 | break; | |
13456 | case CPP_OR_EQ: | |
13457 | opcode = BIT_IOR_EXPR; | |
13458 | break; | |
13459 | case CPP_XOR_EQ: | |
13460 | opcode = BIT_XOR_EXPR; | |
13461 | break; | |
13462 | case CPP_EQ: | |
13463 | c_parser_consume_token (parser); | |
13464 | eloc = c_parser_peek_token (parser)->location; | |
13465 | expr = c_parser_expr_no_commas (parser, NULL, unfolded_lhs); | |
13466 | rhs1 = expr.value; | |
13467 | switch (TREE_CODE (rhs1)) | |
13468 | { | |
13469 | case MULT_EXPR: | |
13470 | case TRUNC_DIV_EXPR: | |
bbf8fbec | 13471 | case RDIV_EXPR: |
bc7bff74 | 13472 | case PLUS_EXPR: |
13473 | case MINUS_EXPR: | |
13474 | case LSHIFT_EXPR: | |
13475 | case RSHIFT_EXPR: | |
13476 | case BIT_AND_EXPR: | |
13477 | case BIT_IOR_EXPR: | |
13478 | case BIT_XOR_EXPR: | |
13479 | if (c_tree_equal (TREE_OPERAND (rhs1, 0), unfolded_lhs)) | |
13480 | { | |
13481 | opcode = TREE_CODE (rhs1); | |
13482 | rhs = c_fully_fold (TREE_OPERAND (rhs1, 1), false, NULL); | |
13483 | rhs1 = c_fully_fold (TREE_OPERAND (rhs1, 0), false, NULL); | |
13484 | goto stmt_done; | |
13485 | } | |
13486 | if (c_tree_equal (TREE_OPERAND (rhs1, 1), unfolded_lhs)) | |
13487 | { | |
13488 | opcode = TREE_CODE (rhs1); | |
13489 | rhs = c_fully_fold (TREE_OPERAND (rhs1, 0), false, NULL); | |
13490 | rhs1 = c_fully_fold (TREE_OPERAND (rhs1, 1), false, NULL); | |
13491 | swapped = !commutative_tree_code (opcode); | |
13492 | goto stmt_done; | |
13493 | } | |
13494 | break; | |
13495 | case ERROR_MARK: | |
13496 | goto saw_error; | |
13497 | default: | |
13498 | break; | |
13499 | } | |
13500 | if (c_parser_peek_token (parser)->type == CPP_SEMICOLON) | |
13501 | { | |
13502 | if (structured_block && code == OMP_ATOMIC_CAPTURE_NEW) | |
13503 | { | |
13504 | code = OMP_ATOMIC_CAPTURE_OLD; | |
13505 | v = lhs; | |
13506 | lhs = NULL_TREE; | |
13507 | expr = default_function_array_read_conversion (eloc, expr); | |
13508 | unfolded_lhs1 = expr.value; | |
13509 | lhs1 = c_fully_fold (unfolded_lhs1, false, NULL); | |
13510 | rhs1 = NULL_TREE; | |
13511 | c_parser_consume_token (parser); | |
13512 | goto restart; | |
13513 | } | |
13514 | if (structured_block) | |
13515 | { | |
13516 | opcode = NOP_EXPR; | |
13517 | expr = default_function_array_read_conversion (eloc, expr); | |
13518 | rhs = c_fully_fold (expr.value, false, NULL); | |
13519 | rhs1 = NULL_TREE; | |
13520 | goto stmt_done; | |
13521 | } | |
13522 | } | |
13523 | c_parser_error (parser, "invalid form of %<#pragma omp atomic%>"); | |
13524 | goto saw_error; | |
13525 | default: | |
13526 | c_parser_error (parser, | |
13527 | "invalid operator for %<#pragma omp atomic%>"); | |
13528 | goto saw_error; | |
13529 | } | |
13530 | ||
13531 | /* Arrange to pass the location of the assignment operator to | |
13532 | c_finish_omp_atomic. */ | |
13533 | loc = c_parser_peek_token (parser)->location; | |
13534 | c_parser_consume_token (parser); | |
13535 | eloc = c_parser_peek_token (parser)->location; | |
13536 | expr = c_parser_expression (parser); | |
13537 | expr = default_function_array_read_conversion (eloc, expr); | |
13538 | rhs = expr.value; | |
13539 | rhs = c_fully_fold (rhs, false, NULL); | |
13540 | break; | |
13541 | } | |
13542 | stmt_done: | |
13543 | if (structured_block && code == OMP_ATOMIC_CAPTURE_NEW) | |
13544 | { | |
13545 | if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>")) | |
13546 | goto saw_error; | |
deef87db | 13547 | v = c_parser_cast_expression (parser, NULL).value; |
13548 | non_lvalue_p = !lvalue_p (v); | |
bc7bff74 | 13549 | v = c_fully_fold (v, false, NULL); |
13550 | if (v == error_mark_node) | |
13551 | goto saw_error; | |
deef87db | 13552 | if (non_lvalue_p) |
13553 | v = non_lvalue (v); | |
bc7bff74 | 13554 | if (!c_parser_require (parser, CPP_EQ, "expected %<=%>")) |
13555 | goto saw_error; | |
13556 | eloc = c_parser_peek_token (parser)->location; | |
deef87db | 13557 | expr = c_parser_cast_expression (parser, NULL); |
bc7bff74 | 13558 | lhs1 = expr.value; |
13559 | expr = default_function_array_read_conversion (eloc, expr); | |
13560 | unfolded_lhs1 = expr.value; | |
13561 | lhs1 = c_fully_fold (lhs1, false, NULL); | |
13562 | if (lhs1 == error_mark_node) | |
13563 | goto saw_error; | |
deef87db | 13564 | if (!lvalue_p (unfolded_lhs1)) |
13565 | lhs1 = non_lvalue (lhs1); | |
bc7bff74 | 13566 | } |
13567 | if (structured_block) | |
13568 | { | |
13569 | c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); | |
13570 | c_parser_require (parser, CPP_CLOSE_BRACE, "expected %<}%>"); | |
13571 | } | |
13572 | done: | |
13573 | if (unfolded_lhs && unfolded_lhs1 | |
13574 | && !c_tree_equal (unfolded_lhs, unfolded_lhs1)) | |
13575 | { | |
13576 | error ("%<#pragma omp atomic capture%> uses two different " | |
13577 | "expressions for memory"); | |
13578 | stmt = error_mark_node; | |
13579 | } | |
13580 | else | |
13581 | stmt = c_finish_omp_atomic (loc, code, opcode, lhs, rhs, v, lhs1, rhs1, | |
13582 | swapped, seq_cst); | |
13583 | if (stmt != error_mark_node) | |
13584 | add_stmt (stmt); | |
13585 | ||
13586 | if (!structured_block) | |
13587 | c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); | |
13588 | } | |
13589 | ||
13590 | ||
13591 | /* OpenMP 2.5: | |
13592 | # pragma omp barrier new-line | |
13593 | */ | |
13594 | ||
13595 | static void | |
13596 | c_parser_omp_barrier (c_parser *parser) | |
13597 | { | |
13598 | location_t loc = c_parser_peek_token (parser)->location; | |
13599 | c_parser_consume_pragma (parser); | |
13600 | c_parser_skip_to_pragma_eol (parser); | |
13601 | ||
13602 | c_finish_omp_barrier (loc); | |
13603 | } | |
13604 | ||
13605 | /* OpenMP 2.5: | |
13606 | # pragma omp critical [(name)] new-line | |
13607 | structured-block | |
13608 | ||
43895be5 | 13609 | OpenMP 4.5: |
13610 | # pragma omp critical [(name) [hint(expression)]] new-line | |
13611 | ||
bc7bff74 | 13612 | LOC is the location of the #pragma itself. */ |
13613 | ||
43895be5 | 13614 | #define OMP_CRITICAL_CLAUSE_MASK \ |
13615 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_HINT) ) | |
13616 | ||
bc7bff74 | 13617 | static tree |
13618 | c_parser_omp_critical (location_t loc, c_parser *parser) | |
13619 | { | |
43895be5 | 13620 | tree stmt, name = NULL_TREE, clauses = NULL_TREE; |
bc7bff74 | 13621 | |
13622 | if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) | |
13623 | { | |
13624 | c_parser_consume_token (parser); | |
13625 | if (c_parser_next_token_is (parser, CPP_NAME)) | |
13626 | { | |
13627 | name = c_parser_peek_token (parser)->value; | |
13628 | c_parser_consume_token (parser); | |
13629 | c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
13630 | } | |
13631 | else | |
13632 | c_parser_error (parser, "expected identifier"); | |
43895be5 | 13633 | |
13634 | clauses = c_parser_omp_all_clauses (parser, | |
13635 | OMP_CRITICAL_CLAUSE_MASK, | |
13636 | "#pragma omp critical"); | |
13637 | } | |
13638 | else | |
13639 | { | |
13640 | if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL)) | |
13641 | c_parser_error (parser, "expected %<(%> or end of line"); | |
13642 | c_parser_skip_to_pragma_eol (parser); | |
bc7bff74 | 13643 | } |
bc7bff74 | 13644 | |
13645 | stmt = c_parser_omp_structured_block (parser); | |
43895be5 | 13646 | return c_finish_omp_critical (loc, stmt, name, clauses); |
bc7bff74 | 13647 | } |
13648 | ||
13649 | /* OpenMP 2.5: | |
13650 | # pragma omp flush flush-vars[opt] new-line | |
13651 | ||
13652 | flush-vars: | |
13653 | ( variable-list ) */ | |
13654 | ||
13655 | static void | |
13656 | c_parser_omp_flush (c_parser *parser) | |
13657 | { | |
13658 | location_t loc = c_parser_peek_token (parser)->location; | |
13659 | c_parser_consume_pragma (parser); | |
13660 | if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) | |
13661 | c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL); | |
13662 | else if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL)) | |
13663 | c_parser_error (parser, "expected %<(%> or end of line"); | |
13664 | c_parser_skip_to_pragma_eol (parser); | |
13665 | ||
13666 | c_finish_omp_flush (loc); | |
13667 | } | |
13668 | ||
ca4c3545 | 13669 | /* Parse the restricted form of loop statements allowed by OpenACC and OpenMP. |
bc7bff74 | 13670 | The real trick here is to determine the loop control variable early |
13671 | so that we can push a new decl if necessary to make it private. | |
ca4c3545 | 13672 | LOC is the location of the "acc" or "omp" in "#pragma acc" or "#pragma omp", |
13673 | respectively. */ | |
bc7bff74 | 13674 | |
13675 | static tree | |
13676 | c_parser_omp_for_loop (location_t loc, c_parser *parser, enum tree_code code, | |
13677 | tree clauses, tree *cclauses) | |
13678 | { | |
13679 | tree decl, cond, incr, save_break, save_cont, body, init, stmt, cl; | |
d2b2788c | 13680 | tree declv, condv, incrv, initv, ret = NULL_TREE; |
13681 | tree pre_body = NULL_TREE, this_pre_body; | |
43895be5 | 13682 | tree ordered_cl = NULL_TREE; |
bc7bff74 | 13683 | bool fail = false, open_brace_parsed = false; |
43895be5 | 13684 | int i, collapse = 1, ordered = 0, count, nbraces = 0; |
bc7bff74 | 13685 | location_t for_loc; |
13686 | vec<tree, va_gc> *for_block = make_tree_vector (); | |
13687 | ||
13688 | for (cl = clauses; cl; cl = OMP_CLAUSE_CHAIN (cl)) | |
13689 | if (OMP_CLAUSE_CODE (cl) == OMP_CLAUSE_COLLAPSE) | |
6b409616 | 13690 | collapse = tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (cl)); |
43895be5 | 13691 | else if (OMP_CLAUSE_CODE (cl) == OMP_CLAUSE_ORDERED |
13692 | && OMP_CLAUSE_ORDERED_EXPR (cl)) | |
13693 | { | |
13694 | ordered_cl = cl; | |
13695 | ordered = tree_to_shwi (OMP_CLAUSE_ORDERED_EXPR (cl)); | |
13696 | } | |
13697 | ||
13698 | if (ordered && ordered < collapse) | |
13699 | { | |
13700 | error_at (OMP_CLAUSE_LOCATION (ordered_cl), | |
13701 | "%<ordered%> clause parameter is less than %<collapse%>"); | |
13702 | OMP_CLAUSE_ORDERED_EXPR (ordered_cl) | |
13703 | = build_int_cst (NULL_TREE, collapse); | |
13704 | ordered = collapse; | |
13705 | } | |
13706 | if (ordered) | |
13707 | { | |
13708 | for (tree *pc = &clauses; *pc; ) | |
13709 | if (OMP_CLAUSE_CODE (*pc) == OMP_CLAUSE_LINEAR) | |
13710 | { | |
13711 | error_at (OMP_CLAUSE_LOCATION (*pc), | |
13712 | "%<linear%> clause may not be specified together " | |
13713 | "with %<ordered%> clause with a parameter"); | |
13714 | *pc = OMP_CLAUSE_CHAIN (*pc); | |
13715 | } | |
13716 | else | |
13717 | pc = &OMP_CLAUSE_CHAIN (*pc); | |
13718 | } | |
bc7bff74 | 13719 | |
43895be5 | 13720 | gcc_assert (collapse >= 1 && ordered >= 0); |
13721 | count = ordered ? ordered : collapse; | |
bc7bff74 | 13722 | |
43895be5 | 13723 | declv = make_tree_vec (count); |
13724 | initv = make_tree_vec (count); | |
13725 | condv = make_tree_vec (count); | |
13726 | incrv = make_tree_vec (count); | |
bc7bff74 | 13727 | |
40750995 | 13728 | if (code != CILK_FOR |
13729 | && !c_parser_next_token_is_keyword (parser, RID_FOR)) | |
bc7bff74 | 13730 | { |
13731 | c_parser_error (parser, "for statement expected"); | |
13732 | return NULL; | |
13733 | } | |
40750995 | 13734 | if (code == CILK_FOR |
13735 | && !c_parser_next_token_is_keyword (parser, RID_CILK_FOR)) | |
13736 | { | |
13737 | c_parser_error (parser, "_Cilk_for statement expected"); | |
13738 | return NULL; | |
13739 | } | |
bc7bff74 | 13740 | for_loc = c_parser_peek_token (parser)->location; |
13741 | c_parser_consume_token (parser); | |
13742 | ||
43895be5 | 13743 | for (i = 0; i < count; i++) |
bc7bff74 | 13744 | { |
13745 | int bracecount = 0; | |
13746 | ||
13747 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
13748 | goto pop_scopes; | |
13749 | ||
13750 | /* Parse the initialization declaration or expression. */ | |
13751 | if (c_parser_next_tokens_start_declaration (parser)) | |
13752 | { | |
13753 | if (i > 0) | |
13754 | vec_safe_push (for_block, c_begin_compound_stmt (true)); | |
d2b2788c | 13755 | this_pre_body = push_stmt_list (); |
bc7bff74 | 13756 | c_parser_declaration_or_fndef (parser, true, true, true, true, true, |
13757 | NULL, vNULL); | |
d2b2788c | 13758 | if (this_pre_body) |
13759 | { | |
13760 | this_pre_body = pop_stmt_list (this_pre_body); | |
13761 | if (pre_body) | |
13762 | { | |
13763 | tree t = pre_body; | |
13764 | pre_body = push_stmt_list (); | |
13765 | add_stmt (t); | |
13766 | add_stmt (this_pre_body); | |
13767 | pre_body = pop_stmt_list (pre_body); | |
13768 | } | |
13769 | else | |
13770 | pre_body = this_pre_body; | |
13771 | } | |
bc7bff74 | 13772 | decl = check_for_loop_decls (for_loc, flag_isoc99); |
13773 | if (decl == NULL) | |
13774 | goto error_init; | |
13775 | if (DECL_INITIAL (decl) == error_mark_node) | |
13776 | decl = error_mark_node; | |
13777 | init = decl; | |
13778 | } | |
13779 | else if (c_parser_next_token_is (parser, CPP_NAME) | |
13780 | && c_parser_peek_2nd_token (parser)->type == CPP_EQ) | |
13781 | { | |
13782 | struct c_expr decl_exp; | |
13783 | struct c_expr init_exp; | |
13784 | location_t init_loc; | |
13785 | ||
13786 | decl_exp = c_parser_postfix_expression (parser); | |
13787 | decl = decl_exp.value; | |
13788 | ||
13789 | c_parser_require (parser, CPP_EQ, "expected %<=%>"); | |
13790 | ||
13791 | init_loc = c_parser_peek_token (parser)->location; | |
13792 | init_exp = c_parser_expr_no_commas (parser, NULL); | |
13793 | init_exp = default_function_array_read_conversion (init_loc, | |
13794 | init_exp); | |
13795 | init = build_modify_expr (init_loc, decl, decl_exp.original_type, | |
13796 | NOP_EXPR, init_loc, init_exp.value, | |
13797 | init_exp.original_type); | |
13798 | init = c_process_expr_stmt (init_loc, init); | |
13799 | ||
13800 | c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); | |
13801 | } | |
13802 | else | |
13803 | { | |
13804 | error_init: | |
13805 | c_parser_error (parser, | |
13806 | "expected iteration declaration or initialization"); | |
13807 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, | |
13808 | "expected %<)%>"); | |
13809 | fail = true; | |
13810 | goto parse_next; | |
13811 | } | |
13812 | ||
13813 | /* Parse the loop condition. */ | |
13814 | cond = NULL_TREE; | |
13815 | if (c_parser_next_token_is_not (parser, CPP_SEMICOLON)) | |
13816 | { | |
13817 | location_t cond_loc = c_parser_peek_token (parser)->location; | |
13818 | struct c_expr cond_expr | |
13819 | = c_parser_binary_expression (parser, NULL, NULL_TREE); | |
13820 | ||
13821 | cond = cond_expr.value; | |
13822 | cond = c_objc_common_truthvalue_conversion (cond_loc, cond); | |
13823 | cond = c_fully_fold (cond, false, NULL); | |
13824 | switch (cond_expr.original_code) | |
13825 | { | |
13826 | case GT_EXPR: | |
13827 | case GE_EXPR: | |
13828 | case LT_EXPR: | |
13829 | case LE_EXPR: | |
13830 | break; | |
f2697631 | 13831 | case NE_EXPR: |
40750995 | 13832 | if (code == CILK_SIMD || code == CILK_FOR) |
f2697631 | 13833 | break; |
13834 | /* FALLTHRU. */ | |
bc7bff74 | 13835 | default: |
13836 | /* Can't be cond = error_mark_node, because we want to preserve | |
13837 | the location until c_finish_omp_for. */ | |
13838 | cond = build1 (NOP_EXPR, boolean_type_node, error_mark_node); | |
13839 | break; | |
13840 | } | |
13841 | protected_set_expr_location (cond, cond_loc); | |
13842 | } | |
13843 | c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); | |
13844 | ||
13845 | /* Parse the increment expression. */ | |
13846 | incr = NULL_TREE; | |
13847 | if (c_parser_next_token_is_not (parser, CPP_CLOSE_PAREN)) | |
13848 | { | |
13849 | location_t incr_loc = c_parser_peek_token (parser)->location; | |
13850 | ||
13851 | incr = c_process_expr_stmt (incr_loc, | |
13852 | c_parser_expression (parser).value); | |
13853 | } | |
13854 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
13855 | ||
13856 | if (decl == NULL || decl == error_mark_node || init == error_mark_node) | |
13857 | fail = true; | |
13858 | else | |
13859 | { | |
13860 | TREE_VEC_ELT (declv, i) = decl; | |
13861 | TREE_VEC_ELT (initv, i) = init; | |
13862 | TREE_VEC_ELT (condv, i) = cond; | |
13863 | TREE_VEC_ELT (incrv, i) = incr; | |
13864 | } | |
13865 | ||
13866 | parse_next: | |
43895be5 | 13867 | if (i == count - 1) |
bc7bff74 | 13868 | break; |
13869 | ||
13870 | /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed | |
13871 | in between the collapsed for loops to be still considered perfectly | |
13872 | nested. Hopefully the final version clarifies this. | |
13873 | For now handle (multiple) {'s and empty statements. */ | |
13874 | do | |
13875 | { | |
13876 | if (c_parser_next_token_is_keyword (parser, RID_FOR)) | |
13877 | { | |
13878 | c_parser_consume_token (parser); | |
13879 | break; | |
13880 | } | |
13881 | else if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) | |
13882 | { | |
13883 | c_parser_consume_token (parser); | |
13884 | bracecount++; | |
13885 | } | |
13886 | else if (bracecount | |
13887 | && c_parser_next_token_is (parser, CPP_SEMICOLON)) | |
13888 | c_parser_consume_token (parser); | |
13889 | else | |
13890 | { | |
13891 | c_parser_error (parser, "not enough perfectly nested loops"); | |
13892 | if (bracecount) | |
13893 | { | |
13894 | open_brace_parsed = true; | |
13895 | bracecount--; | |
13896 | } | |
13897 | fail = true; | |
43895be5 | 13898 | count = 0; |
bc7bff74 | 13899 | break; |
13900 | } | |
13901 | } | |
13902 | while (1); | |
13903 | ||
13904 | nbraces += bracecount; | |
13905 | } | |
13906 | ||
13907 | save_break = c_break_label; | |
f2697631 | 13908 | if (code == CILK_SIMD) |
13909 | c_break_label = build_int_cst (size_type_node, 2); | |
13910 | else | |
13911 | c_break_label = size_one_node; | |
bc7bff74 | 13912 | save_cont = c_cont_label; |
13913 | c_cont_label = NULL_TREE; | |
13914 | body = push_stmt_list (); | |
13915 | ||
13916 | if (open_brace_parsed) | |
13917 | { | |
13918 | location_t here = c_parser_peek_token (parser)->location; | |
13919 | stmt = c_begin_compound_stmt (true); | |
13920 | c_parser_compound_statement_nostart (parser); | |
13921 | add_stmt (c_end_compound_stmt (here, stmt, true)); | |
13922 | } | |
13923 | else | |
13924 | add_stmt (c_parser_c99_block_statement (parser)); | |
13925 | if (c_cont_label) | |
13926 | { | |
13927 | tree t = build1 (LABEL_EXPR, void_type_node, c_cont_label); | |
13928 | SET_EXPR_LOCATION (t, loc); | |
13929 | add_stmt (t); | |
13930 | } | |
13931 | ||
13932 | body = pop_stmt_list (body); | |
13933 | c_break_label = save_break; | |
13934 | c_cont_label = save_cont; | |
13935 | ||
13936 | while (nbraces) | |
13937 | { | |
13938 | if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) | |
13939 | { | |
13940 | c_parser_consume_token (parser); | |
13941 | nbraces--; | |
13942 | } | |
13943 | else if (c_parser_next_token_is (parser, CPP_SEMICOLON)) | |
13944 | c_parser_consume_token (parser); | |
13945 | else | |
13946 | { | |
13947 | c_parser_error (parser, "collapsed loops not perfectly nested"); | |
13948 | while (nbraces) | |
13949 | { | |
13950 | location_t here = c_parser_peek_token (parser)->location; | |
13951 | stmt = c_begin_compound_stmt (true); | |
13952 | add_stmt (body); | |
13953 | c_parser_compound_statement_nostart (parser); | |
13954 | body = c_end_compound_stmt (here, stmt, true); | |
13955 | nbraces--; | |
13956 | } | |
13957 | goto pop_scopes; | |
13958 | } | |
13959 | } | |
13960 | ||
13961 | /* Only bother calling c_finish_omp_for if we haven't already generated | |
13962 | an error from the initialization parsing. */ | |
13963 | if (!fail) | |
13964 | { | |
43895be5 | 13965 | stmt = c_finish_omp_for (loc, code, declv, NULL, initv, condv, |
d2b2788c | 13966 | incrv, body, pre_body); |
bc7bff74 | 13967 | if (stmt) |
13968 | { | |
13969 | if (cclauses != NULL | |
13970 | && cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL] != NULL) | |
13971 | { | |
13972 | tree *c; | |
13973 | for (c = &cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL]; *c ; ) | |
13974 | if (OMP_CLAUSE_CODE (*c) != OMP_CLAUSE_FIRSTPRIVATE | |
13975 | && OMP_CLAUSE_CODE (*c) != OMP_CLAUSE_LASTPRIVATE) | |
13976 | c = &OMP_CLAUSE_CHAIN (*c); | |
13977 | else | |
13978 | { | |
43895be5 | 13979 | for (i = 0; i < count; i++) |
bc7bff74 | 13980 | if (TREE_VEC_ELT (declv, i) == OMP_CLAUSE_DECL (*c)) |
13981 | break; | |
43895be5 | 13982 | if (i == count) |
bc7bff74 | 13983 | c = &OMP_CLAUSE_CHAIN (*c); |
13984 | else if (OMP_CLAUSE_CODE (*c) == OMP_CLAUSE_FIRSTPRIVATE) | |
13985 | { | |
13986 | error_at (loc, | |
13987 | "iteration variable %qD should not be firstprivate", | |
13988 | OMP_CLAUSE_DECL (*c)); | |
13989 | *c = OMP_CLAUSE_CHAIN (*c); | |
13990 | } | |
13991 | else | |
13992 | { | |
d7729e26 | 13993 | /* Move lastprivate (decl) clause to OMP_FOR_CLAUSES. */ |
13994 | tree l = *c; | |
13995 | *c = OMP_CLAUSE_CHAIN (*c); | |
e471cc6f | 13996 | if (code == OMP_SIMD) |
13997 | { | |
13998 | OMP_CLAUSE_CHAIN (l) | |
13999 | = cclauses[C_OMP_CLAUSE_SPLIT_FOR]; | |
14000 | cclauses[C_OMP_CLAUSE_SPLIT_FOR] = l; | |
14001 | } | |
14002 | else | |
14003 | { | |
14004 | OMP_CLAUSE_CHAIN (l) = clauses; | |
14005 | clauses = l; | |
14006 | } | |
bc7bff74 | 14007 | } |
14008 | } | |
14009 | } | |
14010 | OMP_FOR_CLAUSES (stmt) = clauses; | |
14011 | } | |
14012 | ret = stmt; | |
14013 | } | |
14014 | pop_scopes: | |
14015 | while (!for_block->is_empty ()) | |
14016 | { | |
14017 | /* FIXME diagnostics: LOC below should be the actual location of | |
14018 | this particular for block. We need to build a list of | |
14019 | locations to go along with FOR_BLOCK. */ | |
14020 | stmt = c_end_compound_stmt (loc, for_block->pop (), true); | |
14021 | add_stmt (stmt); | |
14022 | } | |
14023 | release_tree_vector (for_block); | |
14024 | return ret; | |
14025 | } | |
14026 | ||
14027 | /* Helper function for OpenMP parsing, split clauses and call | |
14028 | finish_omp_clauses on each of the set of clauses afterwards. */ | |
14029 | ||
14030 | static void | |
14031 | omp_split_clauses (location_t loc, enum tree_code code, | |
14032 | omp_clause_mask mask, tree clauses, tree *cclauses) | |
14033 | { | |
14034 | int i; | |
14035 | c_omp_split_clauses (loc, code, mask, clauses, cclauses); | |
14036 | for (i = 0; i < C_OMP_CLAUSE_SPLIT_COUNT; i++) | |
14037 | if (cclauses[i]) | |
43895be5 | 14038 | cclauses[i] = c_finish_omp_clauses (cclauses[i], true); |
bc7bff74 | 14039 | } |
14040 | ||
14041 | /* OpenMP 4.0: | |
14042 | #pragma omp simd simd-clause[optseq] new-line | |
14043 | for-loop | |
14044 | ||
14045 | LOC is the location of the #pragma token. | |
14046 | */ | |
14047 | ||
14048 | #define OMP_SIMD_CLAUSE_MASK \ | |
14049 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SAFELEN) \ | |
43895be5 | 14050 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMDLEN) \ |
bc7bff74 | 14051 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \ |
14052 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \ | |
14053 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \ | |
14054 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \ | |
14055 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \ | |
14056 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE)) | |
14057 | ||
14058 | static tree | |
14059 | c_parser_omp_simd (location_t loc, c_parser *parser, | |
14060 | char *p_name, omp_clause_mask mask, tree *cclauses) | |
14061 | { | |
14062 | tree block, clauses, ret; | |
14063 | ||
14064 | strcat (p_name, " simd"); | |
14065 | mask |= OMP_SIMD_CLAUSE_MASK; | |
bc7bff74 | 14066 | |
14067 | clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL); | |
14068 | if (cclauses) | |
14069 | { | |
14070 | omp_split_clauses (loc, OMP_SIMD, mask, clauses, cclauses); | |
14071 | clauses = cclauses[C_OMP_CLAUSE_SPLIT_SIMD]; | |
43895be5 | 14072 | tree c = find_omp_clause (cclauses[C_OMP_CLAUSE_SPLIT_FOR], |
14073 | OMP_CLAUSE_ORDERED); | |
14074 | if (c && OMP_CLAUSE_ORDERED_EXPR (c)) | |
14075 | { | |
14076 | error_at (OMP_CLAUSE_LOCATION (c), | |
14077 | "%<ordered%> clause with parameter may not be specified " | |
14078 | "on %qs construct", p_name); | |
14079 | OMP_CLAUSE_ORDERED_EXPR (c) = NULL_TREE; | |
14080 | } | |
bc7bff74 | 14081 | } |
14082 | ||
14083 | block = c_begin_compound_stmt (true); | |
14084 | ret = c_parser_omp_for_loop (loc, parser, OMP_SIMD, clauses, cclauses); | |
14085 | block = c_end_compound_stmt (loc, block, true); | |
14086 | add_stmt (block); | |
14087 | ||
14088 | return ret; | |
14089 | } | |
14090 | ||
14091 | /* OpenMP 2.5: | |
14092 | #pragma omp for for-clause[optseq] new-line | |
14093 | for-loop | |
14094 | ||
14095 | OpenMP 4.0: | |
14096 | #pragma omp for simd for-simd-clause[optseq] new-line | |
14097 | for-loop | |
14098 | ||
14099 | LOC is the location of the #pragma token. | |
14100 | */ | |
14101 | ||
14102 | #define OMP_FOR_CLAUSE_MASK \ | |
14103 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \ | |
14104 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \ | |
14105 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \ | |
43895be5 | 14106 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \ |
bc7bff74 | 14107 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \ |
14108 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ORDERED) \ | |
14109 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SCHEDULE) \ | |
14110 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE) \ | |
14111 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT)) | |
14112 | ||
14113 | static tree | |
14114 | c_parser_omp_for (location_t loc, c_parser *parser, | |
14115 | char *p_name, omp_clause_mask mask, tree *cclauses) | |
14116 | { | |
14117 | tree block, clauses, ret; | |
14118 | ||
14119 | strcat (p_name, " for"); | |
14120 | mask |= OMP_FOR_CLAUSE_MASK; | |
14121 | if (cclauses) | |
14122 | mask &= ~(OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT); | |
43895be5 | 14123 | /* Composite distribute parallel for{, simd} disallows ordered clause. */ |
14124 | if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)) != 0) | |
14125 | mask &= ~(OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ORDERED); | |
bc7bff74 | 14126 | |
14127 | if (c_parser_next_token_is (parser, CPP_NAME)) | |
2169f33b | 14128 | { |
bc7bff74 | 14129 | const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
14130 | ||
14131 | if (strcmp (p, "simd") == 0) | |
14132 | { | |
14133 | tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT]; | |
14134 | if (cclauses == NULL) | |
14135 | cclauses = cclauses_buf; | |
14136 | ||
14137 | c_parser_consume_token (parser); | |
c630ef93 | 14138 | if (!flag_openmp) /* flag_openmp_simd */ |
14139 | return c_parser_omp_simd (loc, parser, p_name, mask, cclauses); | |
bc7bff74 | 14140 | block = c_begin_compound_stmt (true); |
14141 | ret = c_parser_omp_simd (loc, parser, p_name, mask, cclauses); | |
14142 | block = c_end_compound_stmt (loc, block, true); | |
14143 | if (ret == NULL_TREE) | |
14144 | return ret; | |
14145 | ret = make_node (OMP_FOR); | |
14146 | TREE_TYPE (ret) = void_type_node; | |
14147 | OMP_FOR_BODY (ret) = block; | |
14148 | OMP_FOR_CLAUSES (ret) = cclauses[C_OMP_CLAUSE_SPLIT_FOR]; | |
14149 | SET_EXPR_LOCATION (ret, loc); | |
14150 | add_stmt (ret); | |
14151 | return ret; | |
14152 | } | |
2169f33b | 14153 | } |
c630ef93 | 14154 | if (!flag_openmp) /* flag_openmp_simd */ |
14155 | { | |
c3b1dca4 | 14156 | c_parser_skip_to_pragma_eol (parser, false); |
c630ef93 | 14157 | return NULL_TREE; |
14158 | } | |
bc7bff74 | 14159 | |
43895be5 | 14160 | /* Composite distribute parallel for disallows linear clause. */ |
14161 | if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)) != 0) | |
14162 | mask &= ~(OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR); | |
14163 | ||
bc7bff74 | 14164 | clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL); |
14165 | if (cclauses) | |
2169f33b | 14166 | { |
bc7bff74 | 14167 | omp_split_clauses (loc, OMP_FOR, mask, clauses, cclauses); |
14168 | clauses = cclauses[C_OMP_CLAUSE_SPLIT_FOR]; | |
2169f33b | 14169 | } |
2169f33b | 14170 | |
bc7bff74 | 14171 | block = c_begin_compound_stmt (true); |
14172 | ret = c_parser_omp_for_loop (loc, parser, OMP_FOR, clauses, cclauses); | |
14173 | block = c_end_compound_stmt (loc, block, true); | |
14174 | add_stmt (block); | |
14175 | ||
14176 | return ret; | |
1e8e9920 | 14177 | } |
14178 | ||
bc7bff74 | 14179 | /* OpenMP 2.5: |
14180 | # pragma omp master new-line | |
14181 | structured-block | |
14182 | ||
14183 | LOC is the location of the #pragma token. | |
14184 | */ | |
14185 | ||
14186 | static tree | |
14187 | c_parser_omp_master (location_t loc, c_parser *parser) | |
14188 | { | |
14189 | c_parser_skip_to_pragma_eol (parser); | |
14190 | return c_finish_omp_master (loc, c_parser_omp_structured_block (parser)); | |
14191 | } | |
1e8e9920 | 14192 | |
14193 | /* OpenMP 2.5: | |
bc7bff74 | 14194 | # pragma omp ordered new-line |
14195 | structured-block | |
14196 | ||
43895be5 | 14197 | OpenMP 4.5: |
14198 | # pragma omp ordered ordered-clauses new-line | |
14199 | structured-block | |
14200 | ||
14201 | # pragma omp ordered depend-clauses new-line */ | |
14202 | ||
14203 | #define OMP_ORDERED_CLAUSE_MASK \ | |
14204 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_THREADS) \ | |
14205 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMD)) | |
14206 | ||
14207 | #define OMP_ORDERED_DEPEND_CLAUSE_MASK \ | |
14208 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) | |
14209 | ||
14210 | static bool | |
14211 | c_parser_omp_ordered (c_parser *parser, enum pragma_context context) | |
14212 | { | |
14213 | location_t loc = c_parser_peek_token (parser)->location; | |
14214 | c_parser_consume_pragma (parser); | |
14215 | ||
14216 | if (context != pragma_stmt && context != pragma_compound) | |
14217 | { | |
14218 | c_parser_error (parser, "expected declaration specifiers"); | |
14219 | c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL); | |
14220 | return false; | |
14221 | } | |
14222 | ||
14223 | if (c_parser_next_token_is (parser, CPP_NAME)) | |
14224 | { | |
14225 | const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); | |
14226 | ||
14227 | if (!strcmp ("depend", p)) | |
14228 | { | |
14229 | if (context == pragma_stmt) | |
14230 | { | |
14231 | error_at (loc, | |
14232 | "%<#pragma omp ordered%> with %<depend> clause may " | |
14233 | "only be used in compound statements"); | |
14234 | c_parser_skip_to_pragma_eol (parser); | |
14235 | return false; | |
14236 | } | |
14237 | ||
14238 | tree clauses | |
14239 | = c_parser_omp_all_clauses (parser, | |
14240 | OMP_ORDERED_DEPEND_CLAUSE_MASK, | |
14241 | "#pragma omp ordered"); | |
14242 | c_finish_omp_ordered (loc, clauses, NULL_TREE); | |
14243 | return false; | |
14244 | } | |
14245 | } | |
1e8e9920 | 14246 | |
43895be5 | 14247 | tree clauses = c_parser_omp_all_clauses (parser, OMP_ORDERED_CLAUSE_MASK, |
14248 | "#pragma omp ordered"); | |
14249 | c_finish_omp_ordered (loc, clauses, | |
14250 | c_parser_omp_structured_block (parser)); | |
14251 | return true; | |
bc7bff74 | 14252 | } |
1e8e9920 | 14253 | |
bc7bff74 | 14254 | /* OpenMP 2.5: |
14255 | ||
14256 | section-scope: | |
14257 | { section-sequence } | |
14258 | ||
14259 | section-sequence: | |
14260 | section-directive[opt] structured-block | |
14261 | section-sequence section-directive structured-block | |
14262 | ||
14263 | SECTIONS_LOC is the location of the #pragma omp sections. */ | |
14264 | ||
14265 | static tree | |
14266 | c_parser_omp_sections_scope (location_t sections_loc, c_parser *parser) | |
14267 | { | |
14268 | tree stmt, substmt; | |
14269 | bool error_suppress = false; | |
14270 | location_t loc; | |
14271 | ||
14272 | loc = c_parser_peek_token (parser)->location; | |
14273 | if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>")) | |
14274 | { | |
14275 | /* Avoid skipping until the end of the block. */ | |
14276 | parser->error = false; | |
14277 | return NULL_TREE; | |
14278 | } | |
14279 | ||
14280 | stmt = push_stmt_list (); | |
14281 | ||
14282 | if (c_parser_peek_token (parser)->pragma_kind != PRAGMA_OMP_SECTION) | |
14283 | { | |
14284 | substmt = c_parser_omp_structured_block (parser); | |
14285 | substmt = build1 (OMP_SECTION, void_type_node, substmt); | |
14286 | SET_EXPR_LOCATION (substmt, loc); | |
14287 | add_stmt (substmt); | |
14288 | } | |
14289 | ||
14290 | while (1) | |
14291 | { | |
14292 | if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) | |
14293 | break; | |
14294 | if (c_parser_next_token_is (parser, CPP_EOF)) | |
14295 | break; | |
14296 | ||
14297 | loc = c_parser_peek_token (parser)->location; | |
14298 | if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_OMP_SECTION) | |
14299 | { | |
14300 | c_parser_consume_pragma (parser); | |
14301 | c_parser_skip_to_pragma_eol (parser); | |
14302 | error_suppress = false; | |
14303 | } | |
14304 | else if (!error_suppress) | |
14305 | { | |
14306 | error_at (loc, "expected %<#pragma omp section%> or %<}%>"); | |
14307 | error_suppress = true; | |
14308 | } | |
14309 | ||
14310 | substmt = c_parser_omp_structured_block (parser); | |
14311 | substmt = build1 (OMP_SECTION, void_type_node, substmt); | |
14312 | SET_EXPR_LOCATION (substmt, loc); | |
14313 | add_stmt (substmt); | |
14314 | } | |
14315 | c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, | |
14316 | "expected %<#pragma omp section%> or %<}%>"); | |
14317 | ||
14318 | substmt = pop_stmt_list (stmt); | |
14319 | ||
14320 | stmt = make_node (OMP_SECTIONS); | |
14321 | SET_EXPR_LOCATION (stmt, sections_loc); | |
14322 | TREE_TYPE (stmt) = void_type_node; | |
14323 | OMP_SECTIONS_BODY (stmt) = substmt; | |
14324 | ||
14325 | return add_stmt (stmt); | |
1e8e9920 | 14326 | } |
14327 | ||
14328 | /* OpenMP 2.5: | |
bc7bff74 | 14329 | # pragma omp sections sections-clause[optseq] newline |
14330 | sections-scope | |
e60a6f7b | 14331 | |
bc7bff74 | 14332 | LOC is the location of the #pragma token. |
14333 | */ | |
fd6481cf | 14334 | |
bc7bff74 | 14335 | #define OMP_SECTIONS_CLAUSE_MASK \ |
14336 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \ | |
14337 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \ | |
14338 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \ | |
14339 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \ | |
14340 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT)) | |
e3b80d49 | 14341 | |
1e8e9920 | 14342 | static tree |
bc7bff74 | 14343 | c_parser_omp_sections (location_t loc, c_parser *parser, |
14344 | char *p_name, omp_clause_mask mask, tree *cclauses) | |
1e8e9920 | 14345 | { |
bc7bff74 | 14346 | tree block, clauses, ret; |
1e8e9920 | 14347 | |
bc7bff74 | 14348 | strcat (p_name, " sections"); |
14349 | mask |= OMP_SECTIONS_CLAUSE_MASK; | |
14350 | if (cclauses) | |
14351 | mask &= ~(OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT); | |
b6889cb0 | 14352 | |
bc7bff74 | 14353 | clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL); |
14354 | if (cclauses) | |
14355 | { | |
14356 | omp_split_clauses (loc, OMP_SECTIONS, mask, clauses, cclauses); | |
14357 | clauses = cclauses[C_OMP_CLAUSE_SPLIT_SECTIONS]; | |
14358 | } | |
1e8e9920 | 14359 | |
bc7bff74 | 14360 | block = c_begin_compound_stmt (true); |
14361 | ret = c_parser_omp_sections_scope (loc, parser); | |
14362 | if (ret) | |
14363 | OMP_SECTIONS_CLAUSES (ret) = clauses; | |
14364 | block = c_end_compound_stmt (loc, block, true); | |
14365 | add_stmt (block); | |
fd6481cf | 14366 | |
bc7bff74 | 14367 | return ret; |
14368 | } | |
fd6481cf | 14369 | |
bc7bff74 | 14370 | /* OpenMP 2.5: |
395dc01c | 14371 | # pragma omp parallel parallel-clause[optseq] new-line |
14372 | structured-block | |
14373 | # pragma omp parallel for parallel-for-clause[optseq] new-line | |
14374 | structured-block | |
14375 | # pragma omp parallel sections parallel-sections-clause[optseq] new-line | |
14376 | structured-block | |
14377 | ||
14378 | OpenMP 4.0: | |
14379 | # pragma omp parallel for simd parallel-for-simd-clause[optseq] new-line | |
14380 | structured-block | |
fd6481cf | 14381 | |
bc7bff74 | 14382 | LOC is the location of the #pragma token. |
14383 | */ | |
1e8e9920 | 14384 | |
bc7bff74 | 14385 | #define OMP_PARALLEL_CLAUSE_MASK \ |
14386 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \ | |
14387 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \ | |
14388 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \ | |
14389 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \ | |
14390 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \ | |
14391 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYIN) \ | |
14392 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \ | |
14393 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_THREADS) \ | |
14394 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PROC_BIND)) | |
1e8e9920 | 14395 | |
bc7bff74 | 14396 | static tree |
14397 | c_parser_omp_parallel (location_t loc, c_parser *parser, | |
14398 | char *p_name, omp_clause_mask mask, tree *cclauses) | |
14399 | { | |
14400 | tree stmt, clauses, block; | |
14401 | ||
14402 | strcat (p_name, " parallel"); | |
14403 | mask |= OMP_PARALLEL_CLAUSE_MASK; | |
43895be5 | 14404 | /* #pragma omp target parallel{, for, for simd} disallow copyin clause. */ |
14405 | if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP)) != 0 | |
14406 | && (mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)) == 0) | |
14407 | mask &= ~(OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYIN); | |
bc7bff74 | 14408 | |
14409 | if (c_parser_next_token_is_keyword (parser, RID_FOR)) | |
fd6481cf | 14410 | { |
bc7bff74 | 14411 | tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT]; |
14412 | if (cclauses == NULL) | |
14413 | cclauses = cclauses_buf; | |
14414 | ||
1e8e9920 | 14415 | c_parser_consume_token (parser); |
c630ef93 | 14416 | if (!flag_openmp) /* flag_openmp_simd */ |
14417 | return c_parser_omp_for (loc, parser, p_name, mask, cclauses); | |
bc7bff74 | 14418 | block = c_begin_omp_parallel (); |
9f0a7bc6 | 14419 | tree ret = c_parser_omp_for (loc, parser, p_name, mask, cclauses); |
bc7bff74 | 14420 | stmt |
14421 | = c_finish_omp_parallel (loc, cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL], | |
14422 | block); | |
9f0a7bc6 | 14423 | if (ret == NULL_TREE) |
14424 | return ret; | |
bc7bff74 | 14425 | OMP_PARALLEL_COMBINED (stmt) = 1; |
14426 | return stmt; | |
fd6481cf | 14427 | } |
43895be5 | 14428 | /* When combined with distribute, parallel has to be followed by for. |
14429 | #pragma omp target parallel is allowed though. */ | |
14430 | else if (cclauses | |
14431 | && (mask & (OMP_CLAUSE_MASK_1 | |
14432 | << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)) != 0) | |
e60a6f7b | 14433 | { |
bc7bff74 | 14434 | error_at (loc, "expected %<for%> after %qs", p_name); |
14435 | c_parser_skip_to_pragma_eol (parser); | |
14436 | return NULL_TREE; | |
e60a6f7b | 14437 | } |
c630ef93 | 14438 | else if (!flag_openmp) /* flag_openmp_simd */ |
14439 | { | |
c3b1dca4 | 14440 | c_parser_skip_to_pragma_eol (parser, false); |
c630ef93 | 14441 | return NULL_TREE; |
14442 | } | |
43895be5 | 14443 | else if (cclauses == NULL && c_parser_next_token_is (parser, CPP_NAME)) |
fd6481cf | 14444 | { |
bc7bff74 | 14445 | const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
14446 | if (strcmp (p, "sections") == 0) | |
fd6481cf | 14447 | { |
bc7bff74 | 14448 | tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT]; |
14449 | if (cclauses == NULL) | |
14450 | cclauses = cclauses_buf; | |
14451 | ||
fd6481cf | 14452 | c_parser_consume_token (parser); |
bc7bff74 | 14453 | block = c_begin_omp_parallel (); |
14454 | c_parser_omp_sections (loc, parser, p_name, mask, cclauses); | |
14455 | stmt = c_finish_omp_parallel (loc, | |
14456 | cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL], | |
14457 | block); | |
14458 | OMP_PARALLEL_COMBINED (stmt) = 1; | |
14459 | return stmt; | |
fd6481cf | 14460 | } |
14461 | } | |
14462 | ||
bc7bff74 | 14463 | clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL); |
43895be5 | 14464 | if (cclauses) |
14465 | { | |
14466 | omp_split_clauses (loc, OMP_PARALLEL, mask, clauses, cclauses); | |
14467 | clauses = cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL]; | |
14468 | } | |
bc7bff74 | 14469 | |
14470 | block = c_begin_omp_parallel (); | |
14471 | c_parser_statement (parser); | |
14472 | stmt = c_finish_omp_parallel (loc, clauses, block); | |
14473 | ||
14474 | return stmt; | |
14475 | } | |
14476 | ||
14477 | /* OpenMP 2.5: | |
14478 | # pragma omp single single-clause[optseq] new-line | |
14479 | structured-block | |
14480 | ||
14481 | LOC is the location of the #pragma. | |
14482 | */ | |
14483 | ||
14484 | #define OMP_SINGLE_CLAUSE_MASK \ | |
14485 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \ | |
14486 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \ | |
14487 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \ | |
14488 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT)) | |
14489 | ||
14490 | static tree | |
14491 | c_parser_omp_single (location_t loc, c_parser *parser) | |
14492 | { | |
14493 | tree stmt = make_node (OMP_SINGLE); | |
14494 | SET_EXPR_LOCATION (stmt, loc); | |
14495 | TREE_TYPE (stmt) = void_type_node; | |
14496 | ||
14497 | OMP_SINGLE_CLAUSES (stmt) | |
14498 | = c_parser_omp_all_clauses (parser, OMP_SINGLE_CLAUSE_MASK, | |
14499 | "#pragma omp single"); | |
14500 | OMP_SINGLE_BODY (stmt) = c_parser_omp_structured_block (parser); | |
14501 | ||
14502 | return add_stmt (stmt); | |
14503 | } | |
14504 | ||
14505 | /* OpenMP 3.0: | |
14506 | # pragma omp task task-clause[optseq] new-line | |
14507 | ||
14508 | LOC is the location of the #pragma. | |
14509 | */ | |
14510 | ||
14511 | #define OMP_TASK_CLAUSE_MASK \ | |
14512 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \ | |
14513 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNTIED) \ | |
14514 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \ | |
14515 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \ | |
14516 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \ | |
14517 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \ | |
14518 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FINAL) \ | |
14519 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MERGEABLE) \ | |
43895be5 | 14520 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \ |
14521 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIORITY)) | |
bc7bff74 | 14522 | |
14523 | static tree | |
14524 | c_parser_omp_task (location_t loc, c_parser *parser) | |
14525 | { | |
14526 | tree clauses, block; | |
14527 | ||
14528 | clauses = c_parser_omp_all_clauses (parser, OMP_TASK_CLAUSE_MASK, | |
14529 | "#pragma omp task"); | |
14530 | ||
14531 | block = c_begin_omp_task (); | |
14532 | c_parser_statement (parser); | |
14533 | return c_finish_omp_task (loc, clauses, block); | |
1e8e9920 | 14534 | } |
14535 | ||
bc7bff74 | 14536 | /* OpenMP 3.0: |
14537 | # pragma omp taskwait new-line | |
14538 | */ | |
1e8e9920 | 14539 | |
14540 | static void | |
bc7bff74 | 14541 | c_parser_omp_taskwait (c_parser *parser) |
1e8e9920 | 14542 | { |
e60a6f7b | 14543 | location_t loc = c_parser_peek_token (parser)->location; |
1e8e9920 | 14544 | c_parser_consume_pragma (parser); |
1e8e9920 | 14545 | c_parser_skip_to_pragma_eol (parser); |
14546 | ||
bc7bff74 | 14547 | c_finish_omp_taskwait (loc); |
1e8e9920 | 14548 | } |
14549 | ||
bc7bff74 | 14550 | /* OpenMP 3.1: |
14551 | # pragma omp taskyield new-line | |
14552 | */ | |
1e8e9920 | 14553 | |
bc7bff74 | 14554 | static void |
14555 | c_parser_omp_taskyield (c_parser *parser) | |
1e8e9920 | 14556 | { |
bc7bff74 | 14557 | location_t loc = c_parser_peek_token (parser)->location; |
14558 | c_parser_consume_pragma (parser); | |
14559 | c_parser_skip_to_pragma_eol (parser); | |
fd6481cf | 14560 | |
bc7bff74 | 14561 | c_finish_omp_taskyield (loc); |
14562 | } | |
e3b80d49 | 14563 | |
bc7bff74 | 14564 | /* OpenMP 4.0: |
14565 | # pragma omp taskgroup new-line | |
14566 | */ | |
1e8e9920 | 14567 | |
bc7bff74 | 14568 | static tree |
14569 | c_parser_omp_taskgroup (c_parser *parser) | |
14570 | { | |
14571 | location_t loc = c_parser_peek_token (parser)->location; | |
14572 | c_parser_skip_to_pragma_eol (parser); | |
14573 | return c_finish_omp_taskgroup (loc, c_parser_omp_structured_block (parser)); | |
14574 | } | |
b6889cb0 | 14575 | |
bc7bff74 | 14576 | /* OpenMP 4.0: |
14577 | # pragma omp cancel cancel-clause[optseq] new-line | |
1e8e9920 | 14578 | |
bc7bff74 | 14579 | LOC is the location of the #pragma. |
14580 | */ | |
fd6481cf | 14581 | |
bc7bff74 | 14582 | #define OMP_CANCEL_CLAUSE_MASK \ |
14583 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \ | |
14584 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \ | |
14585 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \ | |
14586 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP) \ | |
14587 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF)) | |
fd6481cf | 14588 | |
bc7bff74 | 14589 | static void |
14590 | c_parser_omp_cancel (c_parser *parser) | |
14591 | { | |
14592 | location_t loc = c_parser_peek_token (parser)->location; | |
fd6481cf | 14593 | |
bc7bff74 | 14594 | c_parser_consume_pragma (parser); |
14595 | tree clauses = c_parser_omp_all_clauses (parser, OMP_CANCEL_CLAUSE_MASK, | |
14596 | "#pragma omp cancel"); | |
1e8e9920 | 14597 | |
bc7bff74 | 14598 | c_finish_omp_cancel (loc, clauses); |
14599 | } | |
1e8e9920 | 14600 | |
bc7bff74 | 14601 | /* OpenMP 4.0: |
14602 | # pragma omp cancellation point cancelpt-clause[optseq] new-line | |
1e8e9920 | 14603 | |
bc7bff74 | 14604 | LOC is the location of the #pragma. |
14605 | */ | |
1e8e9920 | 14606 | |
bc7bff74 | 14607 | #define OMP_CANCELLATION_POINT_CLAUSE_MASK \ |
14608 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \ | |
14609 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \ | |
14610 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \ | |
14611 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP)) | |
fd6481cf | 14612 | |
bc7bff74 | 14613 | static void |
14614 | c_parser_omp_cancellation_point (c_parser *parser) | |
14615 | { | |
14616 | location_t loc = c_parser_peek_token (parser)->location; | |
14617 | tree clauses; | |
14618 | bool point_seen = false; | |
14619 | ||
14620 | c_parser_consume_pragma (parser); | |
14621 | if (c_parser_next_token_is (parser, CPP_NAME)) | |
fd6481cf | 14622 | { |
bc7bff74 | 14623 | const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
14624 | if (strcmp (p, "point") == 0) | |
fd6481cf | 14625 | { |
bc7bff74 | 14626 | c_parser_consume_token (parser); |
14627 | point_seen = true; | |
fd6481cf | 14628 | } |
fd6481cf | 14629 | } |
bc7bff74 | 14630 | if (!point_seen) |
fd6481cf | 14631 | { |
bc7bff74 | 14632 | c_parser_error (parser, "expected %<point%>"); |
14633 | c_parser_skip_to_pragma_eol (parser); | |
14634 | return; | |
fd6481cf | 14635 | } |
1e8e9920 | 14636 | |
bc7bff74 | 14637 | clauses |
14638 | = c_parser_omp_all_clauses (parser, OMP_CANCELLATION_POINT_CLAUSE_MASK, | |
14639 | "#pragma omp cancellation point"); | |
e60a6f7b | 14640 | |
bc7bff74 | 14641 | c_finish_omp_cancellation_point (loc, clauses); |
14642 | } | |
1e8e9920 | 14643 | |
bc7bff74 | 14644 | /* OpenMP 4.0: |
14645 | #pragma omp distribute distribute-clause[optseq] new-line | |
14646 | for-loop */ | |
14647 | ||
14648 | #define OMP_DISTRIBUTE_CLAUSE_MASK \ | |
14649 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \ | |
14650 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \ | |
14651 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)\ | |
14652 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE)) | |
1e8e9920 | 14653 | |
14654 | static tree | |
bc7bff74 | 14655 | c_parser_omp_distribute (location_t loc, c_parser *parser, |
14656 | char *p_name, omp_clause_mask mask, tree *cclauses) | |
1e8e9920 | 14657 | { |
bc7bff74 | 14658 | tree clauses, block, ret; |
14659 | ||
14660 | strcat (p_name, " distribute"); | |
14661 | mask |= OMP_DISTRIBUTE_CLAUSE_MASK; | |
14662 | ||
14663 | if (c_parser_next_token_is (parser, CPP_NAME)) | |
14664 | { | |
14665 | const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); | |
14666 | bool simd = false; | |
14667 | bool parallel = false; | |
14668 | ||
14669 | if (strcmp (p, "simd") == 0) | |
14670 | simd = true; | |
14671 | else | |
14672 | parallel = strcmp (p, "parallel") == 0; | |
14673 | if (parallel || simd) | |
14674 | { | |
14675 | tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT]; | |
14676 | if (cclauses == NULL) | |
14677 | cclauses = cclauses_buf; | |
14678 | c_parser_consume_token (parser); | |
c630ef93 | 14679 | if (!flag_openmp) /* flag_openmp_simd */ |
14680 | { | |
14681 | if (simd) | |
14682 | return c_parser_omp_simd (loc, parser, p_name, mask, cclauses); | |
14683 | else | |
14684 | return c_parser_omp_parallel (loc, parser, p_name, mask, | |
14685 | cclauses); | |
14686 | } | |
bc7bff74 | 14687 | block = c_begin_compound_stmt (true); |
14688 | if (simd) | |
14689 | ret = c_parser_omp_simd (loc, parser, p_name, mask, cclauses); | |
14690 | else | |
14691 | ret = c_parser_omp_parallel (loc, parser, p_name, mask, cclauses); | |
14692 | block = c_end_compound_stmt (loc, block, true); | |
14693 | if (ret == NULL) | |
14694 | return ret; | |
14695 | ret = make_node (OMP_DISTRIBUTE); | |
14696 | TREE_TYPE (ret) = void_type_node; | |
14697 | OMP_FOR_BODY (ret) = block; | |
14698 | OMP_FOR_CLAUSES (ret) = cclauses[C_OMP_CLAUSE_SPLIT_DISTRIBUTE]; | |
14699 | SET_EXPR_LOCATION (ret, loc); | |
14700 | add_stmt (ret); | |
14701 | return ret; | |
14702 | } | |
14703 | } | |
c630ef93 | 14704 | if (!flag_openmp) /* flag_openmp_simd */ |
14705 | { | |
c3b1dca4 | 14706 | c_parser_skip_to_pragma_eol (parser, false); |
c630ef93 | 14707 | return NULL_TREE; |
14708 | } | |
1e8e9920 | 14709 | |
bc7bff74 | 14710 | clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL); |
14711 | if (cclauses) | |
14712 | { | |
14713 | omp_split_clauses (loc, OMP_DISTRIBUTE, mask, clauses, cclauses); | |
14714 | clauses = cclauses[C_OMP_CLAUSE_SPLIT_DISTRIBUTE]; | |
14715 | } | |
1e8e9920 | 14716 | |
14717 | block = c_begin_compound_stmt (true); | |
bc7bff74 | 14718 | ret = c_parser_omp_for_loop (loc, parser, OMP_DISTRIBUTE, clauses, NULL); |
e60a6f7b | 14719 | block = c_end_compound_stmt (loc, block, true); |
1e8e9920 | 14720 | add_stmt (block); |
14721 | ||
14722 | return ret; | |
14723 | } | |
14724 | ||
bc7bff74 | 14725 | /* OpenMP 4.0: |
14726 | # pragma omp teams teams-clause[optseq] new-line | |
14727 | structured-block */ | |
e60a6f7b | 14728 | |
bc7bff74 | 14729 | #define OMP_TEAMS_CLAUSE_MASK \ |
14730 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \ | |
14731 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \ | |
14732 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \ | |
14733 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \ | |
14734 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_TEAMS) \ | |
14735 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_THREAD_LIMIT) \ | |
14736 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT)) | |
1e8e9920 | 14737 | |
14738 | static tree | |
bc7bff74 | 14739 | c_parser_omp_teams (location_t loc, c_parser *parser, |
14740 | char *p_name, omp_clause_mask mask, tree *cclauses) | |
1e8e9920 | 14741 | { |
bc7bff74 | 14742 | tree clauses, block, ret; |
14743 | ||
14744 | strcat (p_name, " teams"); | |
14745 | mask |= OMP_TEAMS_CLAUSE_MASK; | |
14746 | ||
14747 | if (c_parser_next_token_is (parser, CPP_NAME)) | |
14748 | { | |
14749 | const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); | |
14750 | if (strcmp (p, "distribute") == 0) | |
14751 | { | |
14752 | tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT]; | |
14753 | if (cclauses == NULL) | |
14754 | cclauses = cclauses_buf; | |
14755 | ||
14756 | c_parser_consume_token (parser); | |
c630ef93 | 14757 | if (!flag_openmp) /* flag_openmp_simd */ |
14758 | return c_parser_omp_distribute (loc, parser, p_name, mask, cclauses); | |
bc7bff74 | 14759 | block = c_begin_compound_stmt (true); |
14760 | ret = c_parser_omp_distribute (loc, parser, p_name, mask, cclauses); | |
14761 | block = c_end_compound_stmt (loc, block, true); | |
14762 | if (ret == NULL) | |
14763 | return ret; | |
14764 | clauses = cclauses[C_OMP_CLAUSE_SPLIT_TEAMS]; | |
14765 | ret = make_node (OMP_TEAMS); | |
14766 | TREE_TYPE (ret) = void_type_node; | |
14767 | OMP_TEAMS_CLAUSES (ret) = clauses; | |
14768 | OMP_TEAMS_BODY (ret) = block; | |
d7729e26 | 14769 | OMP_TEAMS_COMBINED (ret) = 1; |
bc7bff74 | 14770 | return add_stmt (ret); |
14771 | } | |
14772 | } | |
c630ef93 | 14773 | if (!flag_openmp) /* flag_openmp_simd */ |
14774 | { | |
c3b1dca4 | 14775 | c_parser_skip_to_pragma_eol (parser, false); |
c630ef93 | 14776 | return NULL_TREE; |
14777 | } | |
bc7bff74 | 14778 | |
14779 | clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL); | |
14780 | if (cclauses) | |
14781 | { | |
14782 | omp_split_clauses (loc, OMP_TEAMS, mask, clauses, cclauses); | |
14783 | clauses = cclauses[C_OMP_CLAUSE_SPLIT_TEAMS]; | |
14784 | } | |
14785 | ||
14786 | tree stmt = make_node (OMP_TEAMS); | |
14787 | TREE_TYPE (stmt) = void_type_node; | |
14788 | OMP_TEAMS_CLAUSES (stmt) = clauses; | |
14789 | OMP_TEAMS_BODY (stmt) = c_parser_omp_structured_block (parser); | |
14790 | ||
14791 | return add_stmt (stmt); | |
1e8e9920 | 14792 | } |
14793 | ||
bc7bff74 | 14794 | /* OpenMP 4.0: |
14795 | # pragma omp target data target-data-clause[optseq] new-line | |
14796 | structured-block */ | |
e60a6f7b | 14797 | |
bc7bff74 | 14798 | #define OMP_TARGET_DATA_CLAUSE_MASK \ |
14799 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \ | |
14800 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \ | |
43895be5 | 14801 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \ |
14802 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_USE_DEVICE_PTR)) | |
1e8e9920 | 14803 | |
14804 | static tree | |
bc7bff74 | 14805 | c_parser_omp_target_data (location_t loc, c_parser *parser) |
1e8e9920 | 14806 | { |
43895be5 | 14807 | tree clauses |
bc7bff74 | 14808 | = c_parser_omp_all_clauses (parser, OMP_TARGET_DATA_CLAUSE_MASK, |
14809 | "#pragma omp target data"); | |
43895be5 | 14810 | int map_seen = 0; |
14811 | for (tree *pc = &clauses; *pc;) | |
14812 | { | |
14813 | if (OMP_CLAUSE_CODE (*pc) == OMP_CLAUSE_MAP) | |
14814 | switch (OMP_CLAUSE_MAP_KIND (*pc)) | |
14815 | { | |
14816 | case GOMP_MAP_TO: | |
14817 | case GOMP_MAP_ALWAYS_TO: | |
14818 | case GOMP_MAP_FROM: | |
14819 | case GOMP_MAP_ALWAYS_FROM: | |
14820 | case GOMP_MAP_TOFROM: | |
14821 | case GOMP_MAP_ALWAYS_TOFROM: | |
14822 | case GOMP_MAP_ALLOC: | |
14823 | map_seen = 3; | |
14824 | break; | |
14825 | case GOMP_MAP_FIRSTPRIVATE_POINTER: | |
14826 | break; | |
14827 | default: | |
14828 | map_seen |= 1; | |
14829 | error_at (OMP_CLAUSE_LOCATION (*pc), | |
14830 | "%<#pragma omp target data%> with map-type other " | |
14831 | "than %<to%>, %<from%>, %<tofrom%> or %<alloc%> " | |
14832 | "on %<map%> clause"); | |
14833 | *pc = OMP_CLAUSE_CHAIN (*pc); | |
14834 | continue; | |
14835 | } | |
14836 | pc = &OMP_CLAUSE_CHAIN (*pc); | |
14837 | } | |
14838 | ||
14839 | if (map_seen != 3) | |
14840 | { | |
14841 | if (map_seen == 0) | |
14842 | error_at (loc, | |
14843 | "%<#pragma omp target data%> must contain at least " | |
14844 | "one %<map%> clause"); | |
14845 | return NULL_TREE; | |
14846 | } | |
14847 | ||
14848 | tree stmt = make_node (OMP_TARGET_DATA); | |
14849 | TREE_TYPE (stmt) = void_type_node; | |
14850 | OMP_TARGET_DATA_CLAUSES (stmt) = clauses; | |
bc7bff74 | 14851 | keep_next_level (); |
14852 | tree block = c_begin_compound_stmt (true); | |
14853 | add_stmt (c_parser_omp_structured_block (parser)); | |
14854 | OMP_TARGET_DATA_BODY (stmt) = c_end_compound_stmt (loc, block, true); | |
1e8e9920 | 14855 | |
bc7bff74 | 14856 | SET_EXPR_LOCATION (stmt, loc); |
14857 | return add_stmt (stmt); | |
14858 | } | |
1e8e9920 | 14859 | |
bc7bff74 | 14860 | /* OpenMP 4.0: |
14861 | # pragma omp target update target-update-clause[optseq] new-line */ | |
e60a6f7b | 14862 | |
bc7bff74 | 14863 | #define OMP_TARGET_UPDATE_CLAUSE_MASK \ |
14864 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FROM) \ | |
14865 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TO) \ | |
14866 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \ | |
43895be5 | 14867 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \ |
14868 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \ | |
14869 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT)) | |
1e8e9920 | 14870 | |
bc7bff74 | 14871 | static bool |
14872 | c_parser_omp_target_update (location_t loc, c_parser *parser, | |
14873 | enum pragma_context context) | |
1e8e9920 | 14874 | { |
bc7bff74 | 14875 | if (context == pragma_stmt) |
14876 | { | |
14877 | error_at (loc, | |
14878 | "%<#pragma omp target update%> may only be " | |
14879 | "used in compound statements"); | |
14880 | c_parser_skip_to_pragma_eol (parser); | |
14881 | return false; | |
14882 | } | |
1e8e9920 | 14883 | |
bc7bff74 | 14884 | tree clauses |
14885 | = c_parser_omp_all_clauses (parser, OMP_TARGET_UPDATE_CLAUSE_MASK, | |
14886 | "#pragma omp target update"); | |
14887 | if (find_omp_clause (clauses, OMP_CLAUSE_TO) == NULL_TREE | |
14888 | && find_omp_clause (clauses, OMP_CLAUSE_FROM) == NULL_TREE) | |
1e8e9920 | 14889 | { |
bc7bff74 | 14890 | error_at (loc, |
05a827ce | 14891 | "%<#pragma omp target update%> must contain at least one " |
bc7bff74 | 14892 | "%<from%> or %<to%> clauses"); |
14893 | return false; | |
1e8e9920 | 14894 | } |
14895 | ||
bc7bff74 | 14896 | tree stmt = make_node (OMP_TARGET_UPDATE); |
14897 | TREE_TYPE (stmt) = void_type_node; | |
14898 | OMP_TARGET_UPDATE_CLAUSES (stmt) = clauses; | |
14899 | SET_EXPR_LOCATION (stmt, loc); | |
14900 | add_stmt (stmt); | |
14901 | return false; | |
14902 | } | |
1e8e9920 | 14903 | |
43895be5 | 14904 | /* OpenMP 4.5: |
14905 | # pragma omp target enter data target-data-clause[optseq] new-line */ | |
14906 | ||
14907 | #define OMP_TARGET_ENTER_DATA_CLAUSE_MASK \ | |
14908 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \ | |
14909 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \ | |
14910 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \ | |
14911 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \ | |
14912 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT)) | |
14913 | ||
14914 | static tree | |
14915 | c_parser_omp_target_enter_data (location_t loc, c_parser *parser, | |
14916 | enum pragma_context context) | |
14917 | { | |
14918 | bool data_seen = false; | |
14919 | if (c_parser_next_token_is (parser, CPP_NAME)) | |
14920 | { | |
14921 | const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); | |
14922 | if (strcmp (p, "data") == 0) | |
14923 | { | |
14924 | c_parser_consume_token (parser); | |
14925 | data_seen = true; | |
14926 | } | |
14927 | } | |
14928 | if (!data_seen) | |
14929 | { | |
14930 | c_parser_error (parser, "expected %<data%>"); | |
14931 | c_parser_skip_to_pragma_eol (parser); | |
14932 | return NULL_TREE; | |
14933 | } | |
14934 | ||
14935 | if (context == pragma_stmt) | |
14936 | { | |
14937 | error_at (loc, | |
14938 | "%<#pragma omp target enter data%> may only be " | |
14939 | "used in compound statements"); | |
14940 | c_parser_skip_to_pragma_eol (parser); | |
14941 | return NULL_TREE; | |
14942 | } | |
14943 | ||
14944 | tree clauses | |
14945 | = c_parser_omp_all_clauses (parser, OMP_TARGET_ENTER_DATA_CLAUSE_MASK, | |
14946 | "#pragma omp target enter data"); | |
14947 | int map_seen = 0; | |
14948 | for (tree *pc = &clauses; *pc;) | |
14949 | { | |
14950 | if (OMP_CLAUSE_CODE (*pc) == OMP_CLAUSE_MAP) | |
14951 | switch (OMP_CLAUSE_MAP_KIND (*pc)) | |
14952 | { | |
14953 | case GOMP_MAP_TO: | |
14954 | case GOMP_MAP_ALWAYS_TO: | |
14955 | case GOMP_MAP_ALLOC: | |
14956 | map_seen = 3; | |
14957 | break; | |
14958 | case GOMP_MAP_FIRSTPRIVATE_POINTER: | |
14959 | break; | |
14960 | default: | |
14961 | map_seen |= 1; | |
14962 | error_at (OMP_CLAUSE_LOCATION (*pc), | |
14963 | "%<#pragma omp target enter data%> with map-type other " | |
14964 | "than %<to%> or %<alloc%> on %<map%> clause"); | |
14965 | *pc = OMP_CLAUSE_CHAIN (*pc); | |
14966 | continue; | |
14967 | } | |
14968 | pc = &OMP_CLAUSE_CHAIN (*pc); | |
14969 | } | |
14970 | ||
14971 | if (map_seen != 3) | |
14972 | { | |
14973 | if (map_seen == 0) | |
14974 | error_at (loc, | |
14975 | "%<#pragma omp target enter data%> must contain at least " | |
14976 | "one %<map%> clause"); | |
14977 | return NULL_TREE; | |
14978 | } | |
14979 | ||
14980 | tree stmt = make_node (OMP_TARGET_ENTER_DATA); | |
14981 | TREE_TYPE (stmt) = void_type_node; | |
14982 | OMP_TARGET_ENTER_DATA_CLAUSES (stmt) = clauses; | |
14983 | SET_EXPR_LOCATION (stmt, loc); | |
14984 | add_stmt (stmt); | |
14985 | return stmt; | |
14986 | } | |
14987 | ||
14988 | /* OpenMP 4.5: | |
14989 | # pragma omp target exit data target-data-clause[optseq] new-line */ | |
14990 | ||
14991 | #define OMP_TARGET_EXIT_DATA_CLAUSE_MASK \ | |
14992 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \ | |
14993 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \ | |
14994 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \ | |
14995 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \ | |
14996 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT)) | |
14997 | ||
14998 | static tree | |
14999 | c_parser_omp_target_exit_data (location_t loc, c_parser *parser, | |
15000 | enum pragma_context context) | |
15001 | { | |
15002 | bool data_seen = false; | |
15003 | if (c_parser_next_token_is (parser, CPP_NAME)) | |
15004 | { | |
15005 | const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); | |
15006 | if (strcmp (p, "data") == 0) | |
15007 | { | |
15008 | c_parser_consume_token (parser); | |
15009 | data_seen = true; | |
15010 | } | |
15011 | } | |
15012 | if (!data_seen) | |
15013 | { | |
15014 | c_parser_error (parser, "expected %<data%>"); | |
15015 | c_parser_skip_to_pragma_eol (parser); | |
15016 | return NULL_TREE; | |
15017 | } | |
15018 | ||
15019 | if (context == pragma_stmt) | |
15020 | { | |
15021 | error_at (loc, | |
15022 | "%<#pragma omp target exit data%> may only be " | |
15023 | "used in compound statements"); | |
15024 | c_parser_skip_to_pragma_eol (parser); | |
15025 | return NULL_TREE; | |
15026 | } | |
15027 | ||
15028 | tree clauses | |
15029 | = c_parser_omp_all_clauses (parser, OMP_TARGET_EXIT_DATA_CLAUSE_MASK, | |
15030 | "#pragma omp target exit data"); | |
15031 | ||
15032 | int map_seen = 0; | |
15033 | for (tree *pc = &clauses; *pc;) | |
15034 | { | |
15035 | if (OMP_CLAUSE_CODE (*pc) == OMP_CLAUSE_MAP) | |
15036 | switch (OMP_CLAUSE_MAP_KIND (*pc)) | |
15037 | { | |
15038 | case GOMP_MAP_FROM: | |
15039 | case GOMP_MAP_ALWAYS_FROM: | |
15040 | case GOMP_MAP_RELEASE: | |
15041 | case GOMP_MAP_DELETE: | |
15042 | map_seen = 3; | |
15043 | break; | |
15044 | case GOMP_MAP_FIRSTPRIVATE_POINTER: | |
15045 | break; | |
15046 | default: | |
15047 | map_seen |= 1; | |
15048 | error_at (OMP_CLAUSE_LOCATION (*pc), | |
15049 | "%<#pragma omp target exit data%> with map-type other " | |
15050 | "than %<from%>, %<release> or %<delete%> on %<map%>" | |
15051 | " clause"); | |
15052 | *pc = OMP_CLAUSE_CHAIN (*pc); | |
15053 | continue; | |
15054 | } | |
15055 | pc = &OMP_CLAUSE_CHAIN (*pc); | |
15056 | } | |
15057 | ||
15058 | if (map_seen != 3) | |
15059 | { | |
15060 | if (map_seen == 0) | |
15061 | error_at (loc, | |
15062 | "%<#pragma omp target exit data%> must contain at least one " | |
15063 | "%<map%> clause"); | |
15064 | return NULL_TREE; | |
15065 | } | |
15066 | ||
15067 | tree stmt = make_node (OMP_TARGET_EXIT_DATA); | |
15068 | TREE_TYPE (stmt) = void_type_node; | |
15069 | OMP_TARGET_EXIT_DATA_CLAUSES (stmt) = clauses; | |
15070 | SET_EXPR_LOCATION (stmt, loc); | |
15071 | add_stmt (stmt); | |
15072 | return stmt; | |
15073 | } | |
15074 | ||
bc7bff74 | 15075 | /* OpenMP 4.0: |
15076 | # pragma omp target target-clause[optseq] new-line | |
15077 | structured-block */ | |
1e8e9920 | 15078 | |
bc7bff74 | 15079 | #define OMP_TARGET_CLAUSE_MASK \ |
15080 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \ | |
15081 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \ | |
43895be5 | 15082 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \ |
15083 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \ | |
15084 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT) \ | |
15085 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \ | |
15086 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \ | |
15087 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULTMAP) \ | |
15088 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IS_DEVICE_PTR)) | |
1e8e9920 | 15089 | |
bc7bff74 | 15090 | static bool |
15091 | c_parser_omp_target (c_parser *parser, enum pragma_context context) | |
15092 | { | |
15093 | location_t loc = c_parser_peek_token (parser)->location; | |
15094 | c_parser_consume_pragma (parser); | |
43895be5 | 15095 | tree *pc = NULL, stmt, block; |
1e8e9920 | 15096 | |
bc7bff74 | 15097 | if (context != pragma_stmt && context != pragma_compound) |
15098 | { | |
15099 | c_parser_error (parser, "expected declaration specifiers"); | |
15100 | c_parser_skip_to_pragma_eol (parser); | |
15101 | return false; | |
1e8e9920 | 15102 | } |
15103 | ||
bc7bff74 | 15104 | if (c_parser_next_token_is (parser, CPP_NAME)) |
1e8e9920 | 15105 | { |
bc7bff74 | 15106 | const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
43895be5 | 15107 | enum tree_code ccode = ERROR_MARK; |
1e8e9920 | 15108 | |
c630ef93 | 15109 | if (strcmp (p, "teams") == 0) |
43895be5 | 15110 | ccode = OMP_TEAMS; |
15111 | else if (strcmp (p, "parallel") == 0) | |
15112 | ccode = OMP_PARALLEL; | |
15113 | else if (strcmp (p, "simd") == 0) | |
15114 | ccode = OMP_SIMD; | |
15115 | if (ccode != ERROR_MARK) | |
bc7bff74 | 15116 | { |
15117 | tree cclauses[C_OMP_CLAUSE_SPLIT_COUNT]; | |
15118 | char p_name[sizeof ("#pragma omp target teams distribute " | |
15119 | "parallel for simd")]; | |
1e8e9920 | 15120 | |
bc7bff74 | 15121 | c_parser_consume_token (parser); |
dc133326 | 15122 | strcpy (p_name, "#pragma omp target"); |
c630ef93 | 15123 | if (!flag_openmp) /* flag_openmp_simd */ |
184a718f | 15124 | { |
43895be5 | 15125 | tree stmt; |
15126 | switch (ccode) | |
15127 | { | |
15128 | case OMP_TEAMS: | |
15129 | stmt = c_parser_omp_teams (loc, parser, p_name, | |
15130 | OMP_TARGET_CLAUSE_MASK, | |
15131 | cclauses); | |
15132 | break; | |
15133 | case OMP_PARALLEL: | |
15134 | stmt = c_parser_omp_parallel (loc, parser, p_name, | |
15135 | OMP_TARGET_CLAUSE_MASK, | |
15136 | cclauses); | |
15137 | break; | |
15138 | case OMP_SIMD: | |
15139 | stmt = c_parser_omp_simd (loc, parser, p_name, | |
15140 | OMP_TARGET_CLAUSE_MASK, | |
15141 | cclauses); | |
15142 | break; | |
15143 | default: | |
15144 | gcc_unreachable (); | |
15145 | } | |
184a718f | 15146 | return stmt != NULL_TREE; |
15147 | } | |
bc7bff74 | 15148 | keep_next_level (); |
43895be5 | 15149 | tree block = c_begin_compound_stmt (true), ret; |
15150 | switch (ccode) | |
15151 | { | |
15152 | case OMP_TEAMS: | |
15153 | ret = c_parser_omp_teams (loc, parser, p_name, | |
15154 | OMP_TARGET_CLAUSE_MASK, cclauses); | |
15155 | break; | |
15156 | case OMP_PARALLEL: | |
15157 | ret = c_parser_omp_parallel (loc, parser, p_name, | |
15158 | OMP_TARGET_CLAUSE_MASK, cclauses); | |
15159 | break; | |
15160 | case OMP_SIMD: | |
15161 | ret = c_parser_omp_simd (loc, parser, p_name, | |
15162 | OMP_TARGET_CLAUSE_MASK, cclauses); | |
15163 | break; | |
15164 | default: | |
15165 | gcc_unreachable (); | |
15166 | } | |
bc7bff74 | 15167 | block = c_end_compound_stmt (loc, block, true); |
184a718f | 15168 | if (ret == NULL_TREE) |
15169 | return false; | |
bc7bff74 | 15170 | tree stmt = make_node (OMP_TARGET); |
15171 | TREE_TYPE (stmt) = void_type_node; | |
15172 | OMP_TARGET_CLAUSES (stmt) = cclauses[C_OMP_CLAUSE_SPLIT_TARGET]; | |
15173 | OMP_TARGET_BODY (stmt) = block; | |
43895be5 | 15174 | OMP_TARGET_COMBINED (stmt) = 1; |
bc7bff74 | 15175 | add_stmt (stmt); |
43895be5 | 15176 | pc = &OMP_TARGET_CLAUSES (stmt); |
15177 | goto check_clauses; | |
bc7bff74 | 15178 | } |
c630ef93 | 15179 | else if (!flag_openmp) /* flag_openmp_simd */ |
15180 | { | |
c3b1dca4 | 15181 | c_parser_skip_to_pragma_eol (parser, false); |
184a718f | 15182 | return false; |
c630ef93 | 15183 | } |
15184 | else if (strcmp (p, "data") == 0) | |
15185 | { | |
15186 | c_parser_consume_token (parser); | |
15187 | c_parser_omp_target_data (loc, parser); | |
15188 | return true; | |
15189 | } | |
43895be5 | 15190 | else if (strcmp (p, "enter") == 0) |
15191 | { | |
15192 | c_parser_consume_token (parser); | |
15193 | c_parser_omp_target_enter_data (loc, parser, context); | |
15194 | return false; | |
15195 | } | |
15196 | else if (strcmp (p, "exit") == 0) | |
15197 | { | |
15198 | c_parser_consume_token (parser); | |
15199 | c_parser_omp_target_exit_data (loc, parser, context); | |
15200 | return false; | |
15201 | } | |
c630ef93 | 15202 | else if (strcmp (p, "update") == 0) |
15203 | { | |
15204 | c_parser_consume_token (parser); | |
15205 | return c_parser_omp_target_update (loc, parser, context); | |
15206 | } | |
1e8e9920 | 15207 | } |
1e8e9920 | 15208 | |
43895be5 | 15209 | stmt = make_node (OMP_TARGET); |
1e8e9920 | 15210 | TREE_TYPE (stmt) = void_type_node; |
1e8e9920 | 15211 | |
bc7bff74 | 15212 | OMP_TARGET_CLAUSES (stmt) |
15213 | = c_parser_omp_all_clauses (parser, OMP_TARGET_CLAUSE_MASK, | |
15214 | "#pragma omp target"); | |
43895be5 | 15215 | pc = &OMP_TARGET_CLAUSES (stmt); |
bc7bff74 | 15216 | keep_next_level (); |
43895be5 | 15217 | block = c_begin_compound_stmt (true); |
bc7bff74 | 15218 | add_stmt (c_parser_omp_structured_block (parser)); |
15219 | OMP_TARGET_BODY (stmt) = c_end_compound_stmt (loc, block, true); | |
15220 | ||
15221 | SET_EXPR_LOCATION (stmt, loc); | |
15222 | add_stmt (stmt); | |
43895be5 | 15223 | |
15224 | check_clauses: | |
15225 | while (*pc) | |
15226 | { | |
15227 | if (OMP_CLAUSE_CODE (*pc) == OMP_CLAUSE_MAP) | |
15228 | switch (OMP_CLAUSE_MAP_KIND (*pc)) | |
15229 | { | |
15230 | case GOMP_MAP_TO: | |
15231 | case GOMP_MAP_ALWAYS_TO: | |
15232 | case GOMP_MAP_FROM: | |
15233 | case GOMP_MAP_ALWAYS_FROM: | |
15234 | case GOMP_MAP_TOFROM: | |
15235 | case GOMP_MAP_ALWAYS_TOFROM: | |
15236 | case GOMP_MAP_ALLOC: | |
15237 | case GOMP_MAP_FIRSTPRIVATE_POINTER: | |
15238 | break; | |
15239 | default: | |
15240 | error_at (OMP_CLAUSE_LOCATION (*pc), | |
15241 | "%<#pragma omp target%> with map-type other " | |
15242 | "than %<to%>, %<from%>, %<tofrom%> or %<alloc%> " | |
15243 | "on %<map%> clause"); | |
15244 | *pc = OMP_CLAUSE_CHAIN (*pc); | |
15245 | continue; | |
15246 | } | |
15247 | pc = &OMP_CLAUSE_CHAIN (*pc); | |
15248 | } | |
bc7bff74 | 15249 | return true; |
15250 | } | |
15251 | ||
15252 | /* OpenMP 4.0: | |
15253 | # pragma omp declare simd declare-simd-clauses[optseq] new-line */ | |
15254 | ||
15255 | #define OMP_DECLARE_SIMD_CLAUSE_MASK \ | |
15256 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMDLEN) \ | |
15257 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \ | |
15258 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \ | |
15259 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNIFORM) \ | |
15260 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_INBRANCH) \ | |
15261 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOTINBRANCH)) | |
15262 | ||
15263 | static void | |
15264 | c_parser_omp_declare_simd (c_parser *parser, enum pragma_context context) | |
15265 | { | |
15266 | vec<c_token> clauses = vNULL; | |
15267 | while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL)) | |
15268 | { | |
15269 | c_token *token = c_parser_peek_token (parser); | |
15270 | if (token->type == CPP_EOF) | |
15271 | { | |
15272 | c_parser_skip_to_pragma_eol (parser); | |
15273 | clauses.release (); | |
15274 | return; | |
15275 | } | |
15276 | clauses.safe_push (*token); | |
15277 | c_parser_consume_token (parser); | |
15278 | } | |
15279 | clauses.safe_push (*c_parser_peek_token (parser)); | |
15280 | c_parser_skip_to_pragma_eol (parser); | |
15281 | ||
15282 | while (c_parser_next_token_is (parser, CPP_PRAGMA)) | |
15283 | { | |
15284 | if (c_parser_peek_token (parser)->pragma_kind | |
15285 | != PRAGMA_OMP_DECLARE_REDUCTION | |
15286 | || c_parser_peek_2nd_token (parser)->type != CPP_NAME | |
15287 | || strcmp (IDENTIFIER_POINTER | |
15288 | (c_parser_peek_2nd_token (parser)->value), | |
15289 | "simd") != 0) | |
15290 | { | |
15291 | c_parser_error (parser, | |
15292 | "%<#pragma omp declare simd%> must be followed by " | |
15293 | "function declaration or definition or another " | |
15294 | "%<#pragma omp declare simd%>"); | |
15295 | clauses.release (); | |
15296 | return; | |
15297 | } | |
15298 | c_parser_consume_pragma (parser); | |
15299 | while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL)) | |
15300 | { | |
15301 | c_token *token = c_parser_peek_token (parser); | |
15302 | if (token->type == CPP_EOF) | |
15303 | { | |
15304 | c_parser_skip_to_pragma_eol (parser); | |
15305 | clauses.release (); | |
15306 | return; | |
15307 | } | |
15308 | clauses.safe_push (*token); | |
15309 | c_parser_consume_token (parser); | |
15310 | } | |
15311 | clauses.safe_push (*c_parser_peek_token (parser)); | |
15312 | c_parser_skip_to_pragma_eol (parser); | |
15313 | } | |
15314 | ||
15315 | /* Make sure nothing tries to read past the end of the tokens. */ | |
15316 | c_token eof_token; | |
15317 | memset (&eof_token, 0, sizeof (eof_token)); | |
15318 | eof_token.type = CPP_EOF; | |
15319 | clauses.safe_push (eof_token); | |
15320 | clauses.safe_push (eof_token); | |
15321 | ||
15322 | switch (context) | |
15323 | { | |
15324 | case pragma_external: | |
15325 | if (c_parser_next_token_is (parser, CPP_KEYWORD) | |
15326 | && c_parser_peek_token (parser)->keyword == RID_EXTENSION) | |
15327 | { | |
15328 | int ext = disable_extension_diagnostics (); | |
15329 | do | |
15330 | c_parser_consume_token (parser); | |
15331 | while (c_parser_next_token_is (parser, CPP_KEYWORD) | |
15332 | && c_parser_peek_token (parser)->keyword == RID_EXTENSION); | |
15333 | c_parser_declaration_or_fndef (parser, true, true, true, false, true, | |
15334 | NULL, clauses); | |
15335 | restore_extension_diagnostics (ext); | |
15336 | } | |
15337 | else | |
15338 | c_parser_declaration_or_fndef (parser, true, true, true, false, true, | |
15339 | NULL, clauses); | |
15340 | break; | |
15341 | case pragma_struct: | |
15342 | case pragma_param: | |
15343 | c_parser_error (parser, "%<#pragma omp declare simd%> must be followed by " | |
15344 | "function declaration or definition"); | |
15345 | break; | |
15346 | case pragma_compound: | |
15347 | case pragma_stmt: | |
15348 | if (c_parser_next_token_is (parser, CPP_KEYWORD) | |
15349 | && c_parser_peek_token (parser)->keyword == RID_EXTENSION) | |
15350 | { | |
15351 | int ext = disable_extension_diagnostics (); | |
15352 | do | |
15353 | c_parser_consume_token (parser); | |
15354 | while (c_parser_next_token_is (parser, CPP_KEYWORD) | |
15355 | && c_parser_peek_token (parser)->keyword == RID_EXTENSION); | |
15356 | if (c_parser_next_tokens_start_declaration (parser)) | |
15357 | { | |
15358 | c_parser_declaration_or_fndef (parser, true, true, true, true, | |
15359 | true, NULL, clauses); | |
15360 | restore_extension_diagnostics (ext); | |
15361 | break; | |
15362 | } | |
15363 | restore_extension_diagnostics (ext); | |
15364 | } | |
15365 | else if (c_parser_next_tokens_start_declaration (parser)) | |
15366 | { | |
15367 | c_parser_declaration_or_fndef (parser, true, true, true, true, true, | |
15368 | NULL, clauses); | |
15369 | break; | |
15370 | } | |
15371 | c_parser_error (parser, "%<#pragma omp declare simd%> must be followed by " | |
15372 | "function declaration or definition"); | |
15373 | break; | |
15374 | default: | |
15375 | gcc_unreachable (); | |
15376 | } | |
15377 | clauses.release (); | |
1e8e9920 | 15378 | } |
15379 | ||
bc7bff74 | 15380 | /* Finalize #pragma omp declare simd clauses after FNDECL has been parsed, |
15381 | and put that into "omp declare simd" attribute. */ | |
e60a6f7b | 15382 | |
bc7bff74 | 15383 | static void |
15384 | c_finish_omp_declare_simd (c_parser *parser, tree fndecl, tree parms, | |
15385 | vec<c_token> clauses) | |
15386 | { | |
a89e6c15 | 15387 | if (flag_cilkplus |
74acc703 | 15388 | && clauses.exists () && !vec_safe_is_empty (parser->cilk_simd_fn_tokens)) |
15389 | { | |
15390 | error ("%<#pragma omp declare simd%> cannot be used in the same " | |
15391 | "function marked as a Cilk Plus SIMD-enabled function"); | |
15392 | vec_free (parser->cilk_simd_fn_tokens); | |
15393 | return; | |
15394 | } | |
15395 | ||
bc7bff74 | 15396 | /* Normally first token is CPP_NAME "simd". CPP_EOF there indicates |
15397 | error has been reported and CPP_PRAGMA that c_finish_omp_declare_simd | |
15398 | has already processed the tokens. */ | |
74acc703 | 15399 | if (clauses.exists () && clauses[0].type == CPP_EOF) |
bc7bff74 | 15400 | return; |
15401 | if (fndecl == NULL_TREE || TREE_CODE (fndecl) != FUNCTION_DECL) | |
15402 | { | |
15403 | error ("%<#pragma omp declare simd%> not immediately followed by " | |
15404 | "a function declaration or definition"); | |
15405 | clauses[0].type = CPP_EOF; | |
15406 | return; | |
15407 | } | |
74acc703 | 15408 | if (clauses.exists () && clauses[0].type != CPP_NAME) |
bc7bff74 | 15409 | { |
15410 | error_at (DECL_SOURCE_LOCATION (fndecl), | |
15411 | "%<#pragma omp declare simd%> not immediately followed by " | |
15412 | "a single function declaration or definition"); | |
15413 | clauses[0].type = CPP_EOF; | |
15414 | return; | |
15415 | } | |
1e8e9920 | 15416 | |
bc7bff74 | 15417 | if (parms == NULL_TREE) |
15418 | parms = DECL_ARGUMENTS (fndecl); | |
1e8e9920 | 15419 | |
bc7bff74 | 15420 | unsigned int tokens_avail = parser->tokens_avail; |
15421 | gcc_assert (parser->tokens == &parser->tokens_buf[0]); | |
74acc703 | 15422 | bool is_cilkplus_cilk_simd_fn = false; |
15423 | ||
a89e6c15 | 15424 | if (flag_cilkplus && !vec_safe_is_empty (parser->cilk_simd_fn_tokens)) |
74acc703 | 15425 | { |
15426 | parser->tokens = parser->cilk_simd_fn_tokens->address (); | |
15427 | parser->tokens_avail = vec_safe_length (parser->cilk_simd_fn_tokens); | |
15428 | is_cilkplus_cilk_simd_fn = true; | |
15429 | } | |
15430 | else | |
15431 | { | |
15432 | parser->tokens = clauses.address (); | |
15433 | parser->tokens_avail = clauses.length (); | |
15434 | } | |
15435 | ||
bc7bff74 | 15436 | /* c_parser_omp_declare_simd pushed 2 extra CPP_EOF tokens at the end. */ |
15437 | while (parser->tokens_avail > 3) | |
15438 | { | |
15439 | c_token *token = c_parser_peek_token (parser); | |
74acc703 | 15440 | if (!is_cilkplus_cilk_simd_fn) |
15441 | gcc_assert (token->type == CPP_NAME | |
15442 | && strcmp (IDENTIFIER_POINTER (token->value), "simd") == 0); | |
15443 | else | |
15444 | gcc_assert (token->type == CPP_NAME | |
15445 | && is_cilkplus_vector_p (token->value)); | |
bc7bff74 | 15446 | c_parser_consume_token (parser); |
15447 | parser->in_pragma = true; | |
1e8e9920 | 15448 | |
74acc703 | 15449 | tree c = NULL_TREE; |
15450 | if (is_cilkplus_cilk_simd_fn) | |
15451 | c = c_parser_omp_all_clauses (parser, CILK_SIMD_FN_CLAUSE_MASK, | |
15452 | "SIMD-enabled functions attribute"); | |
15453 | else | |
15454 | c = c_parser_omp_all_clauses (parser, OMP_DECLARE_SIMD_CLAUSE_MASK, | |
15455 | "#pragma omp declare simd"); | |
bc7bff74 | 15456 | c = c_omp_declare_simd_clauses_to_numbers (parms, c); |
15457 | if (c != NULL_TREE) | |
15458 | c = tree_cons (NULL_TREE, c, NULL_TREE); | |
74acc703 | 15459 | if (is_cilkplus_cilk_simd_fn) |
15460 | { | |
7e005ab5 | 15461 | tree k = build_tree_list (get_identifier ("cilk simd function"), |
15462 | NULL_TREE); | |
74acc703 | 15463 | TREE_CHAIN (k) = DECL_ATTRIBUTES (fndecl); |
15464 | DECL_ATTRIBUTES (fndecl) = k; | |
15465 | } | |
bc7bff74 | 15466 | c = build_tree_list (get_identifier ("omp declare simd"), c); |
15467 | TREE_CHAIN (c) = DECL_ATTRIBUTES (fndecl); | |
15468 | DECL_ATTRIBUTES (fndecl) = c; | |
15469 | } | |
1e8e9920 | 15470 | |
bc7bff74 | 15471 | parser->tokens = &parser->tokens_buf[0]; |
15472 | parser->tokens_avail = tokens_avail; | |
74acc703 | 15473 | if (clauses.exists ()) |
15474 | clauses[0].type = CPP_PRAGMA; | |
15475 | ||
15476 | if (!vec_safe_is_empty (parser->cilk_simd_fn_tokens)) | |
15477 | vec_free (parser->cilk_simd_fn_tokens); | |
1e8e9920 | 15478 | } |
15479 | ||
1e8e9920 | 15480 | |
bc7bff74 | 15481 | /* OpenMP 4.0: |
15482 | # pragma omp declare target new-line | |
15483 | declarations and definitions | |
43895be5 | 15484 | # pragma omp end declare target new-line |
15485 | ||
15486 | OpenMP 4.5: | |
15487 | # pragma omp declare target ( extended-list ) new-line | |
15488 | ||
15489 | # pragma omp declare target declare-target-clauses[seq] new-line */ | |
15490 | ||
15491 | #define OMP_DECLARE_TARGET_CLAUSE_MASK \ | |
15492 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TO) \ | |
15493 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINK)) | |
1e8e9920 | 15494 | |
bc7bff74 | 15495 | static void |
15496 | c_parser_omp_declare_target (c_parser *parser) | |
1e8e9920 | 15497 | { |
43895be5 | 15498 | location_t loc = c_parser_peek_token (parser)->location; |
15499 | tree clauses = NULL_TREE; | |
15500 | if (c_parser_next_token_is (parser, CPP_NAME)) | |
15501 | clauses = c_parser_omp_all_clauses (parser, OMP_DECLARE_TARGET_CLAUSE_MASK, | |
15502 | "#pragma omp declare target"); | |
15503 | else if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) | |
15504 | { | |
15505 | clauses = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_TO_DECLARE, | |
15506 | clauses); | |
15507 | c_parser_skip_to_pragma_eol (parser); | |
15508 | } | |
15509 | else | |
15510 | { | |
15511 | c_parser_skip_to_pragma_eol (parser); | |
15512 | current_omp_declare_target_attribute++; | |
15513 | return; | |
15514 | } | |
15515 | if (current_omp_declare_target_attribute) | |
15516 | error_at (loc, "%<#pragma omp declare target%> with clauses in between " | |
15517 | "%<#pragma omp declare target%> without clauses and " | |
15518 | "%<#pragma omp end declare target%>"); | |
15519 | for (tree c = clauses; c; c = OMP_CLAUSE_CHAIN (c)) | |
15520 | { | |
15521 | tree t = OMP_CLAUSE_DECL (c), id; | |
15522 | tree at1 = lookup_attribute ("omp declare target", DECL_ATTRIBUTES (t)); | |
15523 | tree at2 = lookup_attribute ("omp declare target link", | |
15524 | DECL_ATTRIBUTES (t)); | |
15525 | if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LINK) | |
15526 | { | |
15527 | id = get_identifier ("omp declare target link"); | |
15528 | std::swap (at1, at2); | |
15529 | } | |
15530 | else | |
15531 | id = get_identifier ("omp declare target"); | |
15532 | if (at2) | |
15533 | { | |
15534 | error_at (OMP_CLAUSE_LOCATION (c), | |
15535 | "%qD specified both in declare target %<link%> and %<to%>" | |
15536 | " clauses", t); | |
15537 | continue; | |
15538 | } | |
15539 | if (!at1) | |
15540 | DECL_ATTRIBUTES (t) = tree_cons (id, NULL_TREE, DECL_ATTRIBUTES (t)); | |
15541 | } | |
bc7bff74 | 15542 | } |
1e8e9920 | 15543 | |
bc7bff74 | 15544 | static void |
15545 | c_parser_omp_end_declare_target (c_parser *parser) | |
15546 | { | |
15547 | location_t loc = c_parser_peek_token (parser)->location; | |
15548 | c_parser_consume_pragma (parser); | |
15549 | if (c_parser_next_token_is (parser, CPP_NAME) | |
15550 | && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser)->value), | |
15551 | "declare") == 0) | |
1e8e9920 | 15552 | { |
15553 | c_parser_consume_token (parser); | |
bc7bff74 | 15554 | if (c_parser_next_token_is (parser, CPP_NAME) |
15555 | && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser)->value), | |
15556 | "target") == 0) | |
15557 | c_parser_consume_token (parser); | |
15558 | else | |
1e8e9920 | 15559 | { |
bc7bff74 | 15560 | c_parser_error (parser, "expected %<target%>"); |
15561 | c_parser_skip_to_pragma_eol (parser); | |
15562 | return; | |
1e8e9920 | 15563 | } |
15564 | } | |
bc7bff74 | 15565 | else |
15566 | { | |
15567 | c_parser_error (parser, "expected %<declare%>"); | |
15568 | c_parser_skip_to_pragma_eol (parser); | |
15569 | return; | |
15570 | } | |
15571 | c_parser_skip_to_pragma_eol (parser); | |
15572 | if (!current_omp_declare_target_attribute) | |
15573 | error_at (loc, "%<#pragma omp end declare target%> without corresponding " | |
15574 | "%<#pragma omp declare target%>"); | |
15575 | else | |
15576 | current_omp_declare_target_attribute--; | |
15577 | } | |
1e8e9920 | 15578 | |
1e8e9920 | 15579 | |
bc7bff74 | 15580 | /* OpenMP 4.0 |
15581 | #pragma omp declare reduction (reduction-id : typename-list : expression) \ | |
15582 | initializer-clause[opt] new-line | |
15583 | ||
15584 | initializer-clause: | |
15585 | initializer (omp_priv = initializer) | |
15586 | initializer (function-name (argument-list)) */ | |
15587 | ||
15588 | static void | |
15589 | c_parser_omp_declare_reduction (c_parser *parser, enum pragma_context context) | |
15590 | { | |
15591 | unsigned int tokens_avail = 0, i; | |
15592 | vec<tree> types = vNULL; | |
15593 | vec<c_token> clauses = vNULL; | |
15594 | enum tree_code reduc_code = ERROR_MARK; | |
15595 | tree reduc_id = NULL_TREE; | |
15596 | tree type; | |
15597 | location_t rloc = c_parser_peek_token (parser)->location; | |
15598 | ||
15599 | if (context == pragma_struct || context == pragma_param) | |
1e8e9920 | 15600 | { |
bc7bff74 | 15601 | error ("%<#pragma omp declare reduction%> not at file or block scope"); |
15602 | goto fail; | |
15603 | } | |
1e8e9920 | 15604 | |
bc7bff74 | 15605 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) |
15606 | goto fail; | |
1e8e9920 | 15607 | |
bc7bff74 | 15608 | switch (c_parser_peek_token (parser)->type) |
15609 | { | |
15610 | case CPP_PLUS: | |
15611 | reduc_code = PLUS_EXPR; | |
15612 | break; | |
15613 | case CPP_MULT: | |
15614 | reduc_code = MULT_EXPR; | |
15615 | break; | |
15616 | case CPP_MINUS: | |
15617 | reduc_code = MINUS_EXPR; | |
15618 | break; | |
15619 | case CPP_AND: | |
15620 | reduc_code = BIT_AND_EXPR; | |
15621 | break; | |
15622 | case CPP_XOR: | |
15623 | reduc_code = BIT_XOR_EXPR; | |
15624 | break; | |
15625 | case CPP_OR: | |
15626 | reduc_code = BIT_IOR_EXPR; | |
15627 | break; | |
15628 | case CPP_AND_AND: | |
15629 | reduc_code = TRUTH_ANDIF_EXPR; | |
15630 | break; | |
15631 | case CPP_OR_OR: | |
15632 | reduc_code = TRUTH_ORIF_EXPR; | |
15633 | break; | |
15634 | case CPP_NAME: | |
15635 | const char *p; | |
15636 | p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); | |
15637 | if (strcmp (p, "min") == 0) | |
15638 | { | |
15639 | reduc_code = MIN_EXPR; | |
15640 | break; | |
15641 | } | |
15642 | if (strcmp (p, "max") == 0) | |
15643 | { | |
15644 | reduc_code = MAX_EXPR; | |
15645 | break; | |
15646 | } | |
15647 | reduc_id = c_parser_peek_token (parser)->value; | |
1e8e9920 | 15648 | break; |
1e8e9920 | 15649 | default: |
bc7bff74 | 15650 | c_parser_error (parser, |
15651 | "expected %<+%>, %<*%>, %<-%>, %<&%>, " | |
15652 | "%<^%>, %<|%>, %<&&%>, %<||%>, %<min%> or identifier"); | |
15653 | goto fail; | |
1e8e9920 | 15654 | } |
15655 | ||
bc7bff74 | 15656 | tree orig_reduc_id, reduc_decl; |
15657 | orig_reduc_id = reduc_id; | |
15658 | reduc_id = c_omp_reduction_id (reduc_code, reduc_id); | |
15659 | reduc_decl = c_omp_reduction_decl (reduc_id); | |
15660 | c_parser_consume_token (parser); | |
1e8e9920 | 15661 | |
bc7bff74 | 15662 | if (!c_parser_require (parser, CPP_COLON, "expected %<:%>")) |
15663 | goto fail; | |
e60a6f7b | 15664 | |
bc7bff74 | 15665 | while (true) |
15666 | { | |
15667 | location_t loc = c_parser_peek_token (parser)->location; | |
15668 | struct c_type_name *ctype = c_parser_type_name (parser); | |
15669 | if (ctype != NULL) | |
15670 | { | |
15671 | type = groktypename (ctype, NULL, NULL); | |
15672 | if (type == error_mark_node) | |
15673 | ; | |
15674 | else if ((INTEGRAL_TYPE_P (type) | |
15675 | || TREE_CODE (type) == REAL_TYPE | |
15676 | || TREE_CODE (type) == COMPLEX_TYPE) | |
15677 | && orig_reduc_id == NULL_TREE) | |
15678 | error_at (loc, "predeclared arithmetic type in " | |
15679 | "%<#pragma omp declare reduction%>"); | |
15680 | else if (TREE_CODE (type) == FUNCTION_TYPE | |
15681 | || TREE_CODE (type) == ARRAY_TYPE) | |
15682 | error_at (loc, "function or array type in " | |
15683 | "%<#pragma omp declare reduction%>"); | |
15684 | else if (TYPE_QUALS_NO_ADDR_SPACE (type)) | |
15685 | error_at (loc, "const, volatile or restrict qualified type in " | |
15686 | "%<#pragma omp declare reduction%>"); | |
15687 | else | |
15688 | { | |
15689 | tree t; | |
15690 | for (t = DECL_INITIAL (reduc_decl); t; t = TREE_CHAIN (t)) | |
15691 | if (comptypes (TREE_PURPOSE (t), type)) | |
15692 | { | |
15693 | error_at (loc, "redeclaration of %qs " | |
15694 | "%<#pragma omp declare reduction%> for " | |
15695 | "type %qT", | |
15696 | IDENTIFIER_POINTER (reduc_id) | |
15697 | + sizeof ("omp declare reduction ") - 1, | |
15698 | type); | |
15699 | location_t ploc | |
15700 | = DECL_SOURCE_LOCATION (TREE_VEC_ELT (TREE_VALUE (t), | |
15701 | 0)); | |
15702 | error_at (ploc, "previous %<#pragma omp declare " | |
15703 | "reduction%>"); | |
15704 | break; | |
15705 | } | |
15706 | if (t == NULL_TREE) | |
15707 | types.safe_push (type); | |
15708 | } | |
15709 | if (c_parser_next_token_is (parser, CPP_COMMA)) | |
15710 | c_parser_consume_token (parser); | |
15711 | else | |
15712 | break; | |
15713 | } | |
15714 | else | |
15715 | break; | |
15716 | } | |
1e8e9920 | 15717 | |
bc7bff74 | 15718 | if (!c_parser_require (parser, CPP_COLON, "expected %<:%>") |
15719 | || types.is_empty ()) | |
15720 | { | |
15721 | fail: | |
15722 | clauses.release (); | |
15723 | types.release (); | |
15724 | while (true) | |
15725 | { | |
15726 | c_token *token = c_parser_peek_token (parser); | |
15727 | if (token->type == CPP_EOF || token->type == CPP_PRAGMA_EOL) | |
15728 | break; | |
15729 | c_parser_consume_token (parser); | |
15730 | } | |
15731 | c_parser_skip_to_pragma_eol (parser); | |
15732 | return; | |
15733 | } | |
1e8e9920 | 15734 | |
bc7bff74 | 15735 | if (types.length () > 1) |
15736 | { | |
15737 | while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL)) | |
15738 | { | |
15739 | c_token *token = c_parser_peek_token (parser); | |
15740 | if (token->type == CPP_EOF) | |
15741 | goto fail; | |
15742 | clauses.safe_push (*token); | |
15743 | c_parser_consume_token (parser); | |
15744 | } | |
15745 | clauses.safe_push (*c_parser_peek_token (parser)); | |
15746 | c_parser_skip_to_pragma_eol (parser); | |
1e8e9920 | 15747 | |
bc7bff74 | 15748 | /* Make sure nothing tries to read past the end of the tokens. */ |
15749 | c_token eof_token; | |
15750 | memset (&eof_token, 0, sizeof (eof_token)); | |
15751 | eof_token.type = CPP_EOF; | |
15752 | clauses.safe_push (eof_token); | |
15753 | clauses.safe_push (eof_token); | |
15754 | } | |
1e8e9920 | 15755 | |
bc7bff74 | 15756 | int errs = errorcount; |
15757 | FOR_EACH_VEC_ELT (types, i, type) | |
15758 | { | |
15759 | tokens_avail = parser->tokens_avail; | |
15760 | gcc_assert (parser->tokens == &parser->tokens_buf[0]); | |
15761 | if (!clauses.is_empty ()) | |
15762 | { | |
15763 | parser->tokens = clauses.address (); | |
15764 | parser->tokens_avail = clauses.length (); | |
15765 | parser->in_pragma = true; | |
15766 | } | |
1e8e9920 | 15767 | |
bc7bff74 | 15768 | bool nested = current_function_decl != NULL_TREE; |
15769 | if (nested) | |
15770 | c_push_function_context (); | |
15771 | tree fndecl = build_decl (BUILTINS_LOCATION, FUNCTION_DECL, | |
15772 | reduc_id, default_function_type); | |
15773 | current_function_decl = fndecl; | |
15774 | allocate_struct_function (fndecl, true); | |
15775 | push_scope (); | |
15776 | tree stmt = push_stmt_list (); | |
15777 | /* Intentionally BUILTINS_LOCATION, so that -Wshadow doesn't | |
15778 | warn about these. */ | |
15779 | tree omp_out = build_decl (BUILTINS_LOCATION, VAR_DECL, | |
15780 | get_identifier ("omp_out"), type); | |
15781 | DECL_ARTIFICIAL (omp_out) = 1; | |
15782 | DECL_CONTEXT (omp_out) = fndecl; | |
15783 | pushdecl (omp_out); | |
15784 | tree omp_in = build_decl (BUILTINS_LOCATION, VAR_DECL, | |
15785 | get_identifier ("omp_in"), type); | |
15786 | DECL_ARTIFICIAL (omp_in) = 1; | |
15787 | DECL_CONTEXT (omp_in) = fndecl; | |
15788 | pushdecl (omp_in); | |
15789 | struct c_expr combiner = c_parser_expression (parser); | |
15790 | struct c_expr initializer; | |
15791 | tree omp_priv = NULL_TREE, omp_orig = NULL_TREE; | |
15792 | bool bad = false; | |
15793 | initializer.value = error_mark_node; | |
15794 | if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>")) | |
15795 | bad = true; | |
15796 | else if (c_parser_next_token_is (parser, CPP_NAME) | |
15797 | && strcmp (IDENTIFIER_POINTER | |
15798 | (c_parser_peek_token (parser)->value), | |
15799 | "initializer") == 0) | |
15800 | { | |
15801 | c_parser_consume_token (parser); | |
15802 | pop_scope (); | |
15803 | push_scope (); | |
15804 | omp_priv = build_decl (BUILTINS_LOCATION, VAR_DECL, | |
15805 | get_identifier ("omp_priv"), type); | |
15806 | DECL_ARTIFICIAL (omp_priv) = 1; | |
15807 | DECL_INITIAL (omp_priv) = error_mark_node; | |
15808 | DECL_CONTEXT (omp_priv) = fndecl; | |
15809 | pushdecl (omp_priv); | |
15810 | omp_orig = build_decl (BUILTINS_LOCATION, VAR_DECL, | |
15811 | get_identifier ("omp_orig"), type); | |
15812 | DECL_ARTIFICIAL (omp_orig) = 1; | |
15813 | DECL_CONTEXT (omp_orig) = fndecl; | |
15814 | pushdecl (omp_orig); | |
15815 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
15816 | bad = true; | |
15817 | else if (!c_parser_next_token_is (parser, CPP_NAME)) | |
15818 | { | |
15819 | c_parser_error (parser, "expected %<omp_priv%> or " | |
15820 | "function-name"); | |
15821 | bad = true; | |
15822 | } | |
15823 | else if (strcmp (IDENTIFIER_POINTER | |
15824 | (c_parser_peek_token (parser)->value), | |
15825 | "omp_priv") != 0) | |
15826 | { | |
15827 | if (c_parser_peek_2nd_token (parser)->type != CPP_OPEN_PAREN | |
15828 | || c_parser_peek_token (parser)->id_kind != C_ID_ID) | |
15829 | { | |
15830 | c_parser_error (parser, "expected function-name %<(%>"); | |
15831 | bad = true; | |
15832 | } | |
15833 | else | |
15834 | initializer = c_parser_postfix_expression (parser); | |
15835 | if (initializer.value | |
15836 | && TREE_CODE (initializer.value) == CALL_EXPR) | |
15837 | { | |
15838 | int j; | |
15839 | tree c = initializer.value; | |
15840 | for (j = 0; j < call_expr_nargs (c); j++) | |
43895be5 | 15841 | { |
15842 | tree a = CALL_EXPR_ARG (c, j); | |
15843 | STRIP_NOPS (a); | |
15844 | if (TREE_CODE (a) == ADDR_EXPR | |
15845 | && TREE_OPERAND (a, 0) == omp_priv) | |
15846 | break; | |
15847 | } | |
bc7bff74 | 15848 | if (j == call_expr_nargs (c)) |
15849 | error ("one of the initializer call arguments should be " | |
15850 | "%<&omp_priv%>"); | |
15851 | } | |
15852 | } | |
15853 | else | |
15854 | { | |
15855 | c_parser_consume_token (parser); | |
15856 | if (!c_parser_require (parser, CPP_EQ, "expected %<=%>")) | |
15857 | bad = true; | |
15858 | else | |
15859 | { | |
15860 | tree st = push_stmt_list (); | |
15861 | start_init (omp_priv, NULL_TREE, 0); | |
15862 | location_t loc = c_parser_peek_token (parser)->location; | |
15863 | struct c_expr init = c_parser_initializer (parser); | |
15864 | finish_init (); | |
15865 | finish_decl (omp_priv, loc, init.value, | |
15866 | init.original_type, NULL_TREE); | |
15867 | pop_stmt_list (st); | |
15868 | } | |
15869 | } | |
15870 | if (!bad | |
15871 | && !c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>")) | |
15872 | bad = true; | |
15873 | } | |
e60a6f7b | 15874 | |
bc7bff74 | 15875 | if (!bad) |
15876 | { | |
15877 | c_parser_skip_to_pragma_eol (parser); | |
fd6481cf | 15878 | |
bc7bff74 | 15879 | tree t = tree_cons (type, make_tree_vec (omp_priv ? 6 : 3), |
15880 | DECL_INITIAL (reduc_decl)); | |
15881 | DECL_INITIAL (reduc_decl) = t; | |
15882 | DECL_SOURCE_LOCATION (omp_out) = rloc; | |
15883 | TREE_VEC_ELT (TREE_VALUE (t), 0) = omp_out; | |
15884 | TREE_VEC_ELT (TREE_VALUE (t), 1) = omp_in; | |
15885 | TREE_VEC_ELT (TREE_VALUE (t), 2) = combiner.value; | |
15886 | walk_tree (&combiner.value, c_check_omp_declare_reduction_r, | |
15887 | &TREE_VEC_ELT (TREE_VALUE (t), 0), NULL); | |
15888 | if (omp_priv) | |
15889 | { | |
15890 | DECL_SOURCE_LOCATION (omp_priv) = rloc; | |
15891 | TREE_VEC_ELT (TREE_VALUE (t), 3) = omp_priv; | |
15892 | TREE_VEC_ELT (TREE_VALUE (t), 4) = omp_orig; | |
15893 | TREE_VEC_ELT (TREE_VALUE (t), 5) = initializer.value; | |
15894 | walk_tree (&initializer.value, c_check_omp_declare_reduction_r, | |
15895 | &TREE_VEC_ELT (TREE_VALUE (t), 3), NULL); | |
15896 | walk_tree (&DECL_INITIAL (omp_priv), | |
15897 | c_check_omp_declare_reduction_r, | |
15898 | &TREE_VEC_ELT (TREE_VALUE (t), 3), NULL); | |
15899 | } | |
15900 | } | |
fd6481cf | 15901 | |
bc7bff74 | 15902 | pop_stmt_list (stmt); |
15903 | pop_scope (); | |
15904 | if (cfun->language != NULL) | |
15905 | { | |
15906 | ggc_free (cfun->language); | |
15907 | cfun->language = NULL; | |
15908 | } | |
15909 | set_cfun (NULL); | |
15910 | current_function_decl = NULL_TREE; | |
15911 | if (nested) | |
15912 | c_pop_function_context (); | |
fd6481cf | 15913 | |
bc7bff74 | 15914 | if (!clauses.is_empty ()) |
15915 | { | |
15916 | parser->tokens = &parser->tokens_buf[0]; | |
15917 | parser->tokens_avail = tokens_avail; | |
15918 | } | |
15919 | if (bad) | |
15920 | goto fail; | |
15921 | if (errs != errorcount) | |
15922 | break; | |
15923 | } | |
fd6481cf | 15924 | |
bc7bff74 | 15925 | clauses.release (); |
15926 | types.release (); | |
fd6481cf | 15927 | } |
15928 | ||
1e8e9920 | 15929 | |
bc7bff74 | 15930 | /* OpenMP 4.0 |
15931 | #pragma omp declare simd declare-simd-clauses[optseq] new-line | |
15932 | #pragma omp declare reduction (reduction-id : typename-list : expression) \ | |
15933 | initializer-clause[opt] new-line | |
15934 | #pragma omp declare target new-line */ | |
2169f33b | 15935 | |
15936 | static void | |
bc7bff74 | 15937 | c_parser_omp_declare (c_parser *parser, enum pragma_context context) |
2169f33b | 15938 | { |
2169f33b | 15939 | c_parser_consume_pragma (parser); |
bc7bff74 | 15940 | if (c_parser_next_token_is (parser, CPP_NAME)) |
15941 | { | |
15942 | const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); | |
15943 | if (strcmp (p, "simd") == 0) | |
15944 | { | |
15945 | /* c_parser_consume_token (parser); done in | |
15946 | c_parser_omp_declare_simd. */ | |
15947 | c_parser_omp_declare_simd (parser, context); | |
15948 | return; | |
15949 | } | |
15950 | if (strcmp (p, "reduction") == 0) | |
15951 | { | |
15952 | c_parser_consume_token (parser); | |
15953 | c_parser_omp_declare_reduction (parser, context); | |
15954 | return; | |
15955 | } | |
c630ef93 | 15956 | if (!flag_openmp) /* flag_openmp_simd */ |
15957 | { | |
c3b1dca4 | 15958 | c_parser_skip_to_pragma_eol (parser, false); |
c630ef93 | 15959 | return; |
15960 | } | |
bc7bff74 | 15961 | if (strcmp (p, "target") == 0) |
15962 | { | |
15963 | c_parser_consume_token (parser); | |
15964 | c_parser_omp_declare_target (parser); | |
15965 | return; | |
15966 | } | |
15967 | } | |
2169f33b | 15968 | |
bc7bff74 | 15969 | c_parser_error (parser, "expected %<simd%> or %<reduction%> " |
15970 | "or %<target%>"); | |
15971 | c_parser_skip_to_pragma_eol (parser); | |
2169f33b | 15972 | } |
15973 | ||
43895be5 | 15974 | /* OpenMP 4.5: |
15975 | #pragma omp taskloop taskloop-clause[optseq] new-line | |
15976 | for-loop | |
15977 | ||
15978 | #pragma omp taskloop simd taskloop-simd-clause[optseq] new-line | |
15979 | for-loop */ | |
15980 | ||
15981 | #define OMP_TASKLOOP_CLAUSE_MASK \ | |
15982 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \ | |
15983 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \ | |
15984 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \ | |
15985 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \ | |
15986 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \ | |
15987 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_GRAINSIZE) \ | |
15988 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_TASKS) \ | |
15989 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE) \ | |
15990 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNTIED) \ | |
15991 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \ | |
15992 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FINAL) \ | |
15993 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MERGEABLE) \ | |
15994 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOGROUP) \ | |
15995 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIORITY)) | |
15996 | ||
15997 | static tree | |
15998 | c_parser_omp_taskloop (location_t loc, c_parser *parser, | |
15999 | char *p_name, omp_clause_mask mask, tree *cclauses) | |
16000 | { | |
16001 | tree clauses, block, ret; | |
16002 | ||
16003 | strcat (p_name, " taskloop"); | |
16004 | mask |= OMP_TASKLOOP_CLAUSE_MASK; | |
16005 | ||
16006 | if (c_parser_next_token_is (parser, CPP_NAME)) | |
16007 | { | |
16008 | const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); | |
16009 | ||
16010 | if (strcmp (p, "simd") == 0) | |
16011 | { | |
16012 | tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT]; | |
16013 | if (cclauses == NULL) | |
16014 | cclauses = cclauses_buf; | |
16015 | mask &= ~(OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION); | |
16016 | c_parser_consume_token (parser); | |
16017 | if (!flag_openmp) /* flag_openmp_simd */ | |
16018 | return c_parser_omp_simd (loc, parser, p_name, mask, cclauses); | |
16019 | block = c_begin_compound_stmt (true); | |
16020 | ret = c_parser_omp_simd (loc, parser, p_name, mask, cclauses); | |
16021 | block = c_end_compound_stmt (loc, block, true); | |
16022 | if (ret == NULL) | |
16023 | return ret; | |
16024 | ret = make_node (OMP_TASKLOOP); | |
16025 | TREE_TYPE (ret) = void_type_node; | |
16026 | OMP_FOR_BODY (ret) = block; | |
16027 | OMP_FOR_CLAUSES (ret) = cclauses[C_OMP_CLAUSE_SPLIT_TASKLOOP]; | |
16028 | SET_EXPR_LOCATION (ret, loc); | |
16029 | add_stmt (ret); | |
16030 | return ret; | |
16031 | } | |
16032 | } | |
16033 | if (!flag_openmp) /* flag_openmp_simd */ | |
16034 | { | |
16035 | c_parser_skip_to_pragma_eol (parser, false); | |
16036 | return NULL_TREE; | |
16037 | } | |
16038 | ||
16039 | clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL); | |
16040 | if (cclauses) | |
16041 | { | |
16042 | omp_split_clauses (loc, OMP_TASKLOOP, mask, clauses, cclauses); | |
16043 | clauses = cclauses[C_OMP_CLAUSE_SPLIT_TASKLOOP]; | |
16044 | } | |
16045 | ||
16046 | block = c_begin_compound_stmt (true); | |
16047 | ret = c_parser_omp_for_loop (loc, parser, OMP_TASKLOOP, clauses, NULL); | |
16048 | block = c_end_compound_stmt (loc, block, true); | |
16049 | add_stmt (block); | |
16050 | ||
16051 | return ret; | |
16052 | } | |
16053 | ||
1e8e9920 | 16054 | /* Main entry point to parsing most OpenMP pragmas. */ |
16055 | ||
16056 | static void | |
16057 | c_parser_omp_construct (c_parser *parser) | |
16058 | { | |
16059 | enum pragma_kind p_kind; | |
16060 | location_t loc; | |
16061 | tree stmt; | |
bc7bff74 | 16062 | char p_name[sizeof "#pragma omp teams distribute parallel for simd"]; |
16063 | omp_clause_mask mask (0); | |
1e8e9920 | 16064 | |
16065 | loc = c_parser_peek_token (parser)->location; | |
16066 | p_kind = c_parser_peek_token (parser)->pragma_kind; | |
16067 | c_parser_consume_pragma (parser); | |
16068 | ||
16069 | switch (p_kind) | |
16070 | { | |
ca4c3545 | 16071 | case PRAGMA_OACC_CACHE: |
16072 | strcpy (p_name, "#pragma acc"); | |
16073 | stmt = c_parser_oacc_cache (loc, parser); | |
16074 | break; | |
16075 | case PRAGMA_OACC_DATA: | |
16076 | stmt = c_parser_oacc_data (loc, parser); | |
16077 | break; | |
16078 | case PRAGMA_OACC_KERNELS: | |
16079 | strcpy (p_name, "#pragma acc"); | |
16080 | stmt = c_parser_oacc_kernels (loc, parser, p_name); | |
16081 | break; | |
16082 | case PRAGMA_OACC_LOOP: | |
16083 | strcpy (p_name, "#pragma acc"); | |
16084 | stmt = c_parser_oacc_loop (loc, parser, p_name); | |
16085 | break; | |
16086 | case PRAGMA_OACC_PARALLEL: | |
16087 | strcpy (p_name, "#pragma acc"); | |
16088 | stmt = c_parser_oacc_parallel (loc, parser, p_name); | |
16089 | break; | |
16090 | case PRAGMA_OACC_WAIT: | |
16091 | strcpy (p_name, "#pragma wait"); | |
16092 | stmt = c_parser_oacc_wait (loc, parser, p_name); | |
16093 | break; | |
1e8e9920 | 16094 | case PRAGMA_OMP_ATOMIC: |
e60a6f7b | 16095 | c_parser_omp_atomic (loc, parser); |
1e8e9920 | 16096 | return; |
16097 | case PRAGMA_OMP_CRITICAL: | |
e60a6f7b | 16098 | stmt = c_parser_omp_critical (loc, parser); |
1e8e9920 | 16099 | break; |
bc7bff74 | 16100 | case PRAGMA_OMP_DISTRIBUTE: |
16101 | strcpy (p_name, "#pragma omp"); | |
16102 | stmt = c_parser_omp_distribute (loc, parser, p_name, mask, NULL); | |
16103 | break; | |
1e8e9920 | 16104 | case PRAGMA_OMP_FOR: |
bc7bff74 | 16105 | strcpy (p_name, "#pragma omp"); |
16106 | stmt = c_parser_omp_for (loc, parser, p_name, mask, NULL); | |
1e8e9920 | 16107 | break; |
16108 | case PRAGMA_OMP_MASTER: | |
e60a6f7b | 16109 | stmt = c_parser_omp_master (loc, parser); |
1e8e9920 | 16110 | break; |
1e8e9920 | 16111 | case PRAGMA_OMP_PARALLEL: |
bc7bff74 | 16112 | strcpy (p_name, "#pragma omp"); |
16113 | stmt = c_parser_omp_parallel (loc, parser, p_name, mask, NULL); | |
1e8e9920 | 16114 | break; |
16115 | case PRAGMA_OMP_SECTIONS: | |
bc7bff74 | 16116 | strcpy (p_name, "#pragma omp"); |
16117 | stmt = c_parser_omp_sections (loc, parser, p_name, mask, NULL); | |
16118 | break; | |
16119 | case PRAGMA_OMP_SIMD: | |
16120 | strcpy (p_name, "#pragma omp"); | |
16121 | stmt = c_parser_omp_simd (loc, parser, p_name, mask, NULL); | |
1e8e9920 | 16122 | break; |
16123 | case PRAGMA_OMP_SINGLE: | |
e60a6f7b | 16124 | stmt = c_parser_omp_single (loc, parser); |
1e8e9920 | 16125 | break; |
fd6481cf | 16126 | case PRAGMA_OMP_TASK: |
e60a6f7b | 16127 | stmt = c_parser_omp_task (loc, parser); |
fd6481cf | 16128 | break; |
bc7bff74 | 16129 | case PRAGMA_OMP_TASKGROUP: |
16130 | stmt = c_parser_omp_taskgroup (parser); | |
16131 | break; | |
43895be5 | 16132 | case PRAGMA_OMP_TASKLOOP: |
16133 | strcpy (p_name, "#pragma omp"); | |
16134 | stmt = c_parser_omp_taskloop (loc, parser, p_name, mask, NULL); | |
16135 | break; | |
bc7bff74 | 16136 | case PRAGMA_OMP_TEAMS: |
16137 | strcpy (p_name, "#pragma omp"); | |
16138 | stmt = c_parser_omp_teams (loc, parser, p_name, mask, NULL); | |
16139 | break; | |
1e8e9920 | 16140 | default: |
16141 | gcc_unreachable (); | |
16142 | } | |
16143 | ||
16144 | if (stmt) | |
e60a6f7b | 16145 | gcc_assert (EXPR_LOCATION (stmt) != UNKNOWN_LOCATION); |
1e8e9920 | 16146 | } |
16147 | ||
16148 | ||
16149 | /* OpenMP 2.5: | |
16150 | # pragma omp threadprivate (variable-list) */ | |
16151 | ||
16152 | static void | |
16153 | c_parser_omp_threadprivate (c_parser *parser) | |
16154 | { | |
16155 | tree vars, t; | |
e60a6f7b | 16156 | location_t loc; |
1e8e9920 | 16157 | |
16158 | c_parser_consume_pragma (parser); | |
e60a6f7b | 16159 | loc = c_parser_peek_token (parser)->location; |
7d339f93 | 16160 | vars = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL); |
1e8e9920 | 16161 | |
1e8e9920 | 16162 | /* Mark every variable in VARS to be assigned thread local storage. */ |
16163 | for (t = vars; t; t = TREE_CHAIN (t)) | |
16164 | { | |
16165 | tree v = TREE_PURPOSE (t); | |
16166 | ||
e60a6f7b | 16167 | /* FIXME diagnostics: Ideally we should keep individual |
16168 | locations for all the variables in the var list to make the | |
16169 | following errors more precise. Perhaps | |
16170 | c_parser_omp_var_list_parens() should construct a list of | |
16171 | locations to go along with the var list. */ | |
16172 | ||
1e8e9920 | 16173 | /* If V had already been marked threadprivate, it doesn't matter |
16174 | whether it had been used prior to this point. */ | |
f48c7f4a | 16175 | if (!VAR_P (v)) |
e60a6f7b | 16176 | error_at (loc, "%qD is not a variable", v); |
50389d5d | 16177 | else if (TREE_USED (v) && !C_DECL_THREADPRIVATE_P (v)) |
e60a6f7b | 16178 | error_at (loc, "%qE declared %<threadprivate%> after first use", v); |
ce41e81a | 16179 | else if (! is_global_var (v)) |
e60a6f7b | 16180 | error_at (loc, "automatic variable %qE cannot be %<threadprivate%>", v); |
50389d5d | 16181 | else if (TREE_TYPE (v) == error_mark_node) |
16182 | ; | |
1e8e9920 | 16183 | else if (! COMPLETE_TYPE_P (TREE_TYPE (v))) |
e60a6f7b | 16184 | error_at (loc, "%<threadprivate%> %qE has incomplete type", v); |
1e8e9920 | 16185 | else |
16186 | { | |
16187 | if (! DECL_THREAD_LOCAL_P (v)) | |
16188 | { | |
5e68df57 | 16189 | set_decl_tls_model (v, decl_default_tls_model (v)); |
1e8e9920 | 16190 | /* If rtl has been already set for this var, call |
16191 | make_decl_rtl once again, so that encode_section_info | |
16192 | has a chance to look at the new decl flags. */ | |
16193 | if (DECL_RTL_SET_P (v)) | |
16194 | make_decl_rtl (v); | |
16195 | } | |
16196 | C_DECL_THREADPRIVATE_P (v) = 1; | |
16197 | } | |
16198 | } | |
16199 | ||
16200 | c_parser_skip_to_pragma_eol (parser); | |
16201 | } | |
f2697631 | 16202 | \f |
16203 | /* Cilk Plus <#pragma simd> parsing routines. */ | |
16204 | ||
16205 | /* Helper function for c_parser_pragma. Perform some sanity checking | |
16206 | for <#pragma simd> constructs. Returns FALSE if there was a | |
16207 | problem. */ | |
16208 | ||
16209 | static bool | |
16210 | c_parser_cilk_verify_simd (c_parser *parser, | |
16211 | enum pragma_context context) | |
16212 | { | |
a89e6c15 | 16213 | if (!flag_cilkplus) |
f2697631 | 16214 | { |
16215 | warning (0, "pragma simd ignored because -fcilkplus is not enabled"); | |
16216 | c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL); | |
16217 | return false; | |
16218 | } | |
16219 | if (context == pragma_external) | |
16220 | { | |
16221 | c_parser_error (parser,"pragma simd must be inside a function"); | |
16222 | c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL); | |
16223 | return false; | |
16224 | } | |
16225 | return true; | |
16226 | } | |
16227 | ||
16228 | /* Cilk Plus: | |
74acc703 | 16229 | This function is shared by SIMD-enabled functions and #pragma simd. |
16230 | If IS_SIMD_FN is true then it is parsing a SIMD-enabled function and | |
16231 | CLAUSES is unused. The main purpose of this function is to parse a | |
16232 | vectorlength attribute or clause and check for parse errors. | |
16233 | When IS_SIMD_FN is true then the function is merely caching the tokens | |
16234 | in PARSER->CILK_SIMD_FN_TOKENS. If errors are found then the token | |
16235 | cache is cleared since there is no reason to continue. | |
16236 | Syntax: | |
16237 | vectorlength ( constant-expression ) */ | |
f2697631 | 16238 | |
16239 | static tree | |
74acc703 | 16240 | c_parser_cilk_clause_vectorlength (c_parser *parser, tree clauses, |
16241 | bool is_simd_fn) | |
f2697631 | 16242 | { |
74acc703 | 16243 | if (is_simd_fn) |
16244 | check_no_duplicate_clause (clauses, OMP_CLAUSE_SIMDLEN, "vectorlength"); | |
16245 | else | |
f2697631 | 16246 | /* The vectorlength clause behaves exactly like OpenMP's safelen |
16247 | clause. Represent it in OpenMP terms. */ | |
74acc703 | 16248 | check_no_duplicate_clause (clauses, OMP_CLAUSE_SAFELEN, "vectorlength"); |
f2697631 | 16249 | |
16250 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
16251 | return clauses; | |
16252 | ||
16253 | location_t loc = c_parser_peek_token (parser)->location; | |
16254 | tree expr = c_parser_expr_no_commas (parser, NULL).value; | |
16255 | expr = c_fully_fold (expr, false, NULL); | |
16256 | ||
74acc703 | 16257 | /* If expr is an error_mark_node then the above function would have |
16258 | emitted an error. No reason to do it twice. */ | |
16259 | if (expr == error_mark_node) | |
16260 | ; | |
16261 | else if (!TREE_TYPE (expr) | |
16262 | || !TREE_CONSTANT (expr) | |
16263 | || !INTEGRAL_TYPE_P (TREE_TYPE (expr))) | |
16264 | ||
16265 | error_at (loc, "vectorlength must be an integer constant"); | |
cc69d08a | 16266 | else if (wi::exact_log2 (expr) == -1) |
f2697631 | 16267 | error_at (loc, "vectorlength must be a power of 2"); |
16268 | else | |
16269 | { | |
74acc703 | 16270 | if (is_simd_fn) |
16271 | { | |
16272 | tree u = build_omp_clause (loc, OMP_CLAUSE_SIMDLEN); | |
16273 | OMP_CLAUSE_SIMDLEN_EXPR (u) = expr; | |
16274 | OMP_CLAUSE_CHAIN (u) = clauses; | |
16275 | clauses = u; | |
16276 | } | |
16277 | else | |
16278 | { | |
16279 | tree u = build_omp_clause (loc, OMP_CLAUSE_SAFELEN); | |
16280 | OMP_CLAUSE_SAFELEN_EXPR (u) = expr; | |
16281 | OMP_CLAUSE_CHAIN (u) = clauses; | |
16282 | clauses = u; | |
16283 | } | |
f2697631 | 16284 | } |
16285 | ||
16286 | c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
16287 | ||
16288 | return clauses; | |
16289 | } | |
16290 | ||
16291 | /* Cilk Plus: | |
16292 | linear ( simd-linear-variable-list ) | |
16293 | ||
16294 | simd-linear-variable-list: | |
16295 | simd-linear-variable | |
16296 | simd-linear-variable-list , simd-linear-variable | |
16297 | ||
16298 | simd-linear-variable: | |
16299 | id-expression | |
16300 | id-expression : simd-linear-step | |
16301 | ||
16302 | simd-linear-step: | |
16303 | conditional-expression */ | |
16304 | ||
16305 | static tree | |
16306 | c_parser_cilk_clause_linear (c_parser *parser, tree clauses) | |
16307 | { | |
16308 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) | |
16309 | return clauses; | |
16310 | ||
16311 | location_t loc = c_parser_peek_token (parser)->location; | |
16312 | ||
16313 | if (c_parser_next_token_is_not (parser, CPP_NAME) | |
16314 | || c_parser_peek_token (parser)->id_kind != C_ID_ID) | |
16315 | c_parser_error (parser, "expected identifier"); | |
16316 | ||
16317 | while (c_parser_next_token_is (parser, CPP_NAME) | |
16318 | && c_parser_peek_token (parser)->id_kind == C_ID_ID) | |
16319 | { | |
16320 | tree var = lookup_name (c_parser_peek_token (parser)->value); | |
16321 | ||
16322 | if (var == NULL) | |
16323 | { | |
16324 | undeclared_variable (c_parser_peek_token (parser)->location, | |
16325 | c_parser_peek_token (parser)->value); | |
16326 | c_parser_consume_token (parser); | |
16327 | } | |
16328 | else if (var == error_mark_node) | |
16329 | c_parser_consume_token (parser); | |
16330 | else | |
16331 | { | |
16332 | tree step = integer_one_node; | |
16333 | ||
16334 | /* Parse the linear step if present. */ | |
16335 | if (c_parser_peek_2nd_token (parser)->type == CPP_COLON) | |
16336 | { | |
16337 | c_parser_consume_token (parser); | |
16338 | c_parser_consume_token (parser); | |
16339 | ||
16340 | tree expr = c_parser_expr_no_commas (parser, NULL).value; | |
16341 | expr = c_fully_fold (expr, false, NULL); | |
16342 | ||
16343 | if (TREE_TYPE (expr) | |
16344 | && INTEGRAL_TYPE_P (TREE_TYPE (expr)) | |
16345 | && (TREE_CONSTANT (expr) | |
16346 | || DECL_P (expr))) | |
16347 | step = expr; | |
16348 | else | |
16349 | c_parser_error (parser, | |
16350 | "step size must be an integer constant " | |
16351 | "expression or an integer variable"); | |
16352 | } | |
16353 | else | |
16354 | c_parser_consume_token (parser); | |
16355 | ||
16356 | /* Use OMP_CLAUSE_LINEAR, which has the same semantics. */ | |
16357 | tree u = build_omp_clause (loc, OMP_CLAUSE_LINEAR); | |
16358 | OMP_CLAUSE_DECL (u) = var; | |
16359 | OMP_CLAUSE_LINEAR_STEP (u) = step; | |
16360 | OMP_CLAUSE_CHAIN (u) = clauses; | |
16361 | clauses = u; | |
16362 | } | |
16363 | ||
16364 | if (c_parser_next_token_is_not (parser, CPP_COMMA)) | |
16365 | break; | |
16366 | ||
16367 | c_parser_consume_token (parser); | |
16368 | } | |
16369 | ||
16370 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); | |
16371 | ||
16372 | return clauses; | |
16373 | } | |
16374 | ||
16375 | /* Returns the name of the next clause. If the clause is not | |
16376 | recognized SIMD_OMP_CLAUSE_NONE is returned and the next token is | |
16377 | not consumed. Otherwise, the appropriate pragma_simd_clause is | |
16378 | returned and the token is consumed. */ | |
16379 | ||
74acc703 | 16380 | static pragma_omp_clause |
f2697631 | 16381 | c_parser_cilk_clause_name (c_parser *parser) |
16382 | { | |
74acc703 | 16383 | pragma_omp_clause result; |
f2697631 | 16384 | c_token *token = c_parser_peek_token (parser); |
16385 | ||
16386 | if (!token->value || token->type != CPP_NAME) | |
16387 | return PRAGMA_CILK_CLAUSE_NONE; | |
16388 | ||
16389 | const char *p = IDENTIFIER_POINTER (token->value); | |
16390 | ||
16391 | if (!strcmp (p, "vectorlength")) | |
16392 | result = PRAGMA_CILK_CLAUSE_VECTORLENGTH; | |
16393 | else if (!strcmp (p, "linear")) | |
16394 | result = PRAGMA_CILK_CLAUSE_LINEAR; | |
16395 | else if (!strcmp (p, "private")) | |
16396 | result = PRAGMA_CILK_CLAUSE_PRIVATE; | |
16397 | else if (!strcmp (p, "firstprivate")) | |
16398 | result = PRAGMA_CILK_CLAUSE_FIRSTPRIVATE; | |
16399 | else if (!strcmp (p, "lastprivate")) | |
16400 | result = PRAGMA_CILK_CLAUSE_LASTPRIVATE; | |
16401 | else if (!strcmp (p, "reduction")) | |
16402 | result = PRAGMA_CILK_CLAUSE_REDUCTION; | |
16403 | else | |
16404 | return PRAGMA_CILK_CLAUSE_NONE; | |
16405 | ||
16406 | c_parser_consume_token (parser); | |
16407 | return result; | |
16408 | } | |
16409 | ||
16410 | /* Parse all #<pragma simd> clauses. Return the list of clauses | |
16411 | found. */ | |
16412 | ||
16413 | static tree | |
16414 | c_parser_cilk_all_clauses (c_parser *parser) | |
16415 | { | |
16416 | tree clauses = NULL; | |
16417 | ||
16418 | while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL)) | |
16419 | { | |
74acc703 | 16420 | pragma_omp_clause c_kind; |
f2697631 | 16421 | |
16422 | c_kind = c_parser_cilk_clause_name (parser); | |
16423 | ||
16424 | switch (c_kind) | |
16425 | { | |
16426 | case PRAGMA_CILK_CLAUSE_VECTORLENGTH: | |
74acc703 | 16427 | clauses = c_parser_cilk_clause_vectorlength (parser, clauses, false); |
f2697631 | 16428 | break; |
16429 | case PRAGMA_CILK_CLAUSE_LINEAR: | |
16430 | clauses = c_parser_cilk_clause_linear (parser, clauses); | |
16431 | break; | |
16432 | case PRAGMA_CILK_CLAUSE_PRIVATE: | |
16433 | /* Use the OpenMP counterpart. */ | |
16434 | clauses = c_parser_omp_clause_private (parser, clauses); | |
16435 | break; | |
16436 | case PRAGMA_CILK_CLAUSE_FIRSTPRIVATE: | |
16437 | /* Use the OpenMP counterpart. */ | |
16438 | clauses = c_parser_omp_clause_firstprivate (parser, clauses); | |
16439 | break; | |
16440 | case PRAGMA_CILK_CLAUSE_LASTPRIVATE: | |
16441 | /* Use the OpenMP counterpart. */ | |
16442 | clauses = c_parser_omp_clause_lastprivate (parser, clauses); | |
16443 | break; | |
16444 | case PRAGMA_CILK_CLAUSE_REDUCTION: | |
16445 | /* Use the OpenMP counterpart. */ | |
16446 | clauses = c_parser_omp_clause_reduction (parser, clauses); | |
16447 | break; | |
16448 | default: | |
16449 | c_parser_error (parser, "expected %<#pragma simd%> clause"); | |
16450 | goto saw_error; | |
16451 | } | |
16452 | } | |
16453 | ||
16454 | saw_error: | |
16455 | c_parser_skip_to_pragma_eol (parser); | |
16456 | return c_finish_cilk_clauses (clauses); | |
16457 | } | |
16458 | ||
40750995 | 16459 | /* This function helps parse the grainsize pragma for a _Cilk_for statement. |
16460 | Here is the correct syntax of this pragma: | |
16461 | #pragma cilk grainsize = <EXP> | |
16462 | */ | |
16463 | ||
16464 | static void | |
16465 | c_parser_cilk_grainsize (c_parser *parser) | |
16466 | { | |
16467 | extern tree convert_to_integer (tree, tree); | |
16468 | ||
16469 | /* consume the 'grainsize' keyword. */ | |
16470 | c_parser_consume_pragma (parser); | |
16471 | ||
16472 | if (c_parser_require (parser, CPP_EQ, "expected %<=%>") != 0) | |
16473 | { | |
16474 | struct c_expr g_expr = c_parser_binary_expression (parser, NULL, NULL); | |
16475 | if (g_expr.value == error_mark_node) | |
16476 | { | |
16477 | c_parser_skip_to_pragma_eol (parser); | |
16478 | return; | |
16479 | } | |
16480 | tree grain = convert_to_integer (long_integer_type_node, | |
16481 | c_fully_fold (g_expr.value, false, | |
16482 | NULL)); | |
16483 | c_parser_skip_to_pragma_eol (parser); | |
16484 | c_token *token = c_parser_peek_token (parser); | |
16485 | if (token && token->type == CPP_KEYWORD | |
16486 | && token->keyword == RID_CILK_FOR) | |
16487 | { | |
16488 | if (grain == NULL_TREE || grain == error_mark_node) | |
16489 | grain = integer_zero_node; | |
16490 | c_parser_cilk_for (parser, grain); | |
16491 | } | |
16492 | else | |
16493 | warning (0, "%<#pragma cilk grainsize%> is not followed by " | |
16494 | "%<_Cilk_for%>"); | |
16495 | } | |
16496 | else | |
16497 | c_parser_skip_to_pragma_eol (parser); | |
16498 | } | |
16499 | ||
16500 | /* Main entry point for parsing Cilk Plus <#pragma simd> for loops. */ | |
1e8e9920 | 16501 | |
f2697631 | 16502 | static void |
dc133326 | 16503 | c_parser_cilk_simd (c_parser *parser) |
f2697631 | 16504 | { |
f2697631 | 16505 | tree clauses = c_parser_cilk_all_clauses (parser); |
16506 | tree block = c_begin_compound_stmt (true); | |
16507 | location_t loc = c_parser_peek_token (parser)->location; | |
16508 | c_parser_omp_for_loop (loc, parser, CILK_SIMD, clauses, NULL); | |
16509 | block = c_end_compound_stmt (loc, block, true); | |
16510 | add_stmt (block); | |
16511 | } | |
40750995 | 16512 | |
16513 | /* Create an artificial decl with TYPE and emit initialization of it with | |
16514 | INIT. */ | |
16515 | ||
16516 | static tree | |
16517 | c_get_temp_regvar (tree type, tree init) | |
16518 | { | |
16519 | location_t loc = EXPR_LOCATION (init); | |
16520 | tree decl = build_decl (loc, VAR_DECL, NULL_TREE, type); | |
16521 | DECL_ARTIFICIAL (decl) = 1; | |
16522 | DECL_IGNORED_P (decl) = 1; | |
16523 | pushdecl (decl); | |
16524 | tree t = build2 (INIT_EXPR, type, decl, init); | |
16525 | add_stmt (t); | |
16526 | return decl; | |
16527 | } | |
16528 | ||
16529 | /* Main entry point for parsing Cilk Plus _Cilk_for loops. | |
16530 | GRAIN is the grain value passed in through pragma or 0. */ | |
16531 | ||
16532 | static void | |
16533 | c_parser_cilk_for (c_parser *parser, tree grain) | |
16534 | { | |
16535 | tree clauses = build_omp_clause (EXPR_LOCATION (grain), OMP_CLAUSE_SCHEDULE); | |
16536 | OMP_CLAUSE_SCHEDULE_KIND (clauses) = OMP_CLAUSE_SCHEDULE_CILKFOR; | |
16537 | OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (clauses) = grain; | |
43895be5 | 16538 | clauses = c_finish_omp_clauses (clauses, false); |
40750995 | 16539 | |
16540 | tree block = c_begin_compound_stmt (true); | |
16541 | tree sb = push_stmt_list (); | |
16542 | location_t loc = c_parser_peek_token (parser)->location; | |
16543 | tree omp_for = c_parser_omp_for_loop (loc, parser, CILK_FOR, clauses, NULL); | |
16544 | sb = pop_stmt_list (sb); | |
16545 | ||
16546 | if (omp_for) | |
16547 | { | |
16548 | tree omp_par = make_node (OMP_PARALLEL); | |
16549 | TREE_TYPE (omp_par) = void_type_node; | |
16550 | OMP_PARALLEL_CLAUSES (omp_par) = NULL_TREE; | |
16551 | tree bind = build3 (BIND_EXPR, void_type_node, NULL, NULL, NULL); | |
16552 | TREE_SIDE_EFFECTS (bind) = 1; | |
16553 | BIND_EXPR_BODY (bind) = sb; | |
16554 | OMP_PARALLEL_BODY (omp_par) = bind; | |
16555 | if (OMP_FOR_PRE_BODY (omp_for)) | |
16556 | { | |
16557 | add_stmt (OMP_FOR_PRE_BODY (omp_for)); | |
16558 | OMP_FOR_PRE_BODY (omp_for) = NULL_TREE; | |
16559 | } | |
16560 | tree init = TREE_VEC_ELT (OMP_FOR_INIT (omp_for), 0); | |
16561 | tree decl = TREE_OPERAND (init, 0); | |
16562 | tree cond = TREE_VEC_ELT (OMP_FOR_COND (omp_for), 0); | |
16563 | tree incr = TREE_VEC_ELT (OMP_FOR_INCR (omp_for), 0); | |
16564 | tree t = TREE_OPERAND (cond, 1), c, clauses = NULL_TREE; | |
16565 | if (TREE_CODE (t) != INTEGER_CST) | |
16566 | { | |
16567 | TREE_OPERAND (cond, 1) = c_get_temp_regvar (TREE_TYPE (t), t); | |
16568 | c = build_omp_clause (input_location, OMP_CLAUSE_FIRSTPRIVATE); | |
16569 | OMP_CLAUSE_DECL (c) = TREE_OPERAND (cond, 1); | |
16570 | OMP_CLAUSE_CHAIN (c) = clauses; | |
16571 | clauses = c; | |
16572 | } | |
16573 | if (TREE_CODE (incr) == MODIFY_EXPR) | |
16574 | { | |
16575 | t = TREE_OPERAND (TREE_OPERAND (incr, 1), 1); | |
16576 | if (TREE_CODE (t) != INTEGER_CST) | |
16577 | { | |
16578 | TREE_OPERAND (TREE_OPERAND (incr, 1), 1) | |
16579 | = c_get_temp_regvar (TREE_TYPE (t), t); | |
16580 | c = build_omp_clause (input_location, OMP_CLAUSE_FIRSTPRIVATE); | |
16581 | OMP_CLAUSE_DECL (c) = TREE_OPERAND (TREE_OPERAND (incr, 1), 1); | |
16582 | OMP_CLAUSE_CHAIN (c) = clauses; | |
16583 | clauses = c; | |
16584 | } | |
16585 | } | |
16586 | t = TREE_OPERAND (init, 1); | |
16587 | if (TREE_CODE (t) != INTEGER_CST) | |
16588 | { | |
16589 | TREE_OPERAND (init, 1) = c_get_temp_regvar (TREE_TYPE (t), t); | |
16590 | c = build_omp_clause (input_location, OMP_CLAUSE_FIRSTPRIVATE); | |
16591 | OMP_CLAUSE_DECL (c) = TREE_OPERAND (init, 1); | |
16592 | OMP_CLAUSE_CHAIN (c) = clauses; | |
16593 | clauses = c; | |
16594 | } | |
16595 | c = build_omp_clause (input_location, OMP_CLAUSE_PRIVATE); | |
16596 | OMP_CLAUSE_DECL (c) = decl; | |
16597 | OMP_CLAUSE_CHAIN (c) = clauses; | |
16598 | clauses = c; | |
16599 | c = build_omp_clause (input_location, OMP_CLAUSE__CILK_FOR_COUNT_); | |
16600 | OMP_CLAUSE_OPERAND (c, 0) | |
16601 | = cilk_for_number_of_iterations (omp_for); | |
16602 | OMP_CLAUSE_CHAIN (c) = clauses; | |
43895be5 | 16603 | OMP_PARALLEL_CLAUSES (omp_par) = c_finish_omp_clauses (c, true); |
40750995 | 16604 | add_stmt (omp_par); |
16605 | } | |
16606 | ||
16607 | block = c_end_compound_stmt (loc, block, true); | |
16608 | add_stmt (block); | |
16609 | } | |
16610 | ||
f2697631 | 16611 | \f |
4c0315d0 | 16612 | /* Parse a transaction attribute (GCC Extension). |
16613 | ||
16614 | transaction-attribute: | |
16615 | attributes | |
16616 | [ [ any-word ] ] | |
16617 | ||
16618 | The transactional memory language description is written for C++, | |
16619 | and uses the C++0x attribute syntax. For compatibility, allow the | |
16620 | bracket style for transactions in C as well. */ | |
16621 | ||
16622 | static tree | |
16623 | c_parser_transaction_attributes (c_parser *parser) | |
16624 | { | |
16625 | tree attr_name, attr = NULL; | |
16626 | ||
16627 | if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)) | |
16628 | return c_parser_attributes (parser); | |
16629 | ||
16630 | if (!c_parser_next_token_is (parser, CPP_OPEN_SQUARE)) | |
16631 | return NULL_TREE; | |
16632 | c_parser_consume_token (parser); | |
16633 | if (!c_parser_require (parser, CPP_OPEN_SQUARE, "expected %<[%>")) | |
16634 | goto error1; | |
16635 | ||
16636 | attr_name = c_parser_attribute_any_word (parser); | |
16637 | if (attr_name) | |
16638 | { | |
16639 | c_parser_consume_token (parser); | |
16640 | attr = build_tree_list (attr_name, NULL_TREE); | |
16641 | } | |
16642 | else | |
16643 | c_parser_error (parser, "expected identifier"); | |
16644 | ||
16645 | c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, "expected %<]%>"); | |
16646 | error1: | |
16647 | c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, "expected %<]%>"); | |
16648 | return attr; | |
16649 | } | |
16650 | ||
16651 | /* Parse a __transaction_atomic or __transaction_relaxed statement | |
16652 | (GCC Extension). | |
16653 | ||
16654 | transaction-statement: | |
16655 | __transaction_atomic transaction-attribute[opt] compound-statement | |
16656 | __transaction_relaxed compound-statement | |
16657 | ||
16658 | Note that the only valid attribute is: "outer". | |
16659 | */ | |
16660 | ||
16661 | static tree | |
16662 | c_parser_transaction (c_parser *parser, enum rid keyword) | |
16663 | { | |
16664 | unsigned int old_in = parser->in_transaction; | |
16665 | unsigned int this_in = 1, new_in; | |
16666 | location_t loc = c_parser_peek_token (parser)->location; | |
16667 | tree stmt, attrs; | |
16668 | ||
16669 | gcc_assert ((keyword == RID_TRANSACTION_ATOMIC | |
16670 | || keyword == RID_TRANSACTION_RELAXED) | |
16671 | && c_parser_next_token_is_keyword (parser, keyword)); | |
16672 | c_parser_consume_token (parser); | |
16673 | ||
16674 | if (keyword == RID_TRANSACTION_RELAXED) | |
16675 | this_in |= TM_STMT_ATTR_RELAXED; | |
16676 | else | |
16677 | { | |
16678 | attrs = c_parser_transaction_attributes (parser); | |
16679 | if (attrs) | |
16680 | this_in |= parse_tm_stmt_attr (attrs, TM_STMT_ATTR_OUTER); | |
16681 | } | |
16682 | ||
16683 | /* Keep track if we're in the lexical scope of an outer transaction. */ | |
16684 | new_in = this_in | (old_in & TM_STMT_ATTR_OUTER); | |
16685 | ||
16686 | parser->in_transaction = new_in; | |
16687 | stmt = c_parser_compound_statement (parser); | |
16688 | parser->in_transaction = old_in; | |
16689 | ||
16690 | if (flag_tm) | |
16691 | stmt = c_finish_transaction (loc, stmt, this_in); | |
16692 | else | |
16693 | error_at (loc, (keyword == RID_TRANSACTION_ATOMIC ? | |
16694 | "%<__transaction_atomic%> without transactional memory support enabled" | |
16695 | : "%<__transaction_relaxed %> " | |
16696 | "without transactional memory support enabled")); | |
16697 | ||
16698 | return stmt; | |
16699 | } | |
16700 | ||
16701 | /* Parse a __transaction_atomic or __transaction_relaxed expression | |
16702 | (GCC Extension). | |
16703 | ||
16704 | transaction-expression: | |
16705 | __transaction_atomic ( expression ) | |
16706 | __transaction_relaxed ( expression ) | |
16707 | */ | |
16708 | ||
16709 | static struct c_expr | |
16710 | c_parser_transaction_expression (c_parser *parser, enum rid keyword) | |
16711 | { | |
16712 | struct c_expr ret; | |
16713 | unsigned int old_in = parser->in_transaction; | |
16714 | unsigned int this_in = 1; | |
16715 | location_t loc = c_parser_peek_token (parser)->location; | |
16716 | tree attrs; | |
16717 | ||
16718 | gcc_assert ((keyword == RID_TRANSACTION_ATOMIC | |
16719 | || keyword == RID_TRANSACTION_RELAXED) | |
16720 | && c_parser_next_token_is_keyword (parser, keyword)); | |
16721 | c_parser_consume_token (parser); | |
16722 | ||
16723 | if (keyword == RID_TRANSACTION_RELAXED) | |
16724 | this_in |= TM_STMT_ATTR_RELAXED; | |
16725 | else | |
16726 | { | |
16727 | attrs = c_parser_transaction_attributes (parser); | |
16728 | if (attrs) | |
16729 | this_in |= parse_tm_stmt_attr (attrs, 0); | |
16730 | } | |
16731 | ||
16732 | parser->in_transaction = this_in; | |
bdd07b44 | 16733 | if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) |
4c0315d0 | 16734 | { |
16735 | tree expr = c_parser_expression (parser).value; | |
16736 | ret.original_type = TREE_TYPE (expr); | |
16737 | ret.value = build1 (TRANSACTION_EXPR, ret.original_type, expr); | |
16738 | if (this_in & TM_STMT_ATTR_RELAXED) | |
16739 | TRANSACTION_EXPR_RELAXED (ret.value) = 1; | |
16740 | SET_EXPR_LOCATION (ret.value, loc); | |
16741 | ret.original_code = TRANSACTION_EXPR; | |
bdd07b44 | 16742 | if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>")) |
16743 | { | |
16744 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); | |
16745 | goto error; | |
16746 | } | |
4c0315d0 | 16747 | } |
16748 | else | |
16749 | { | |
bdd07b44 | 16750 | error: |
4c0315d0 | 16751 | ret.value = error_mark_node; |
16752 | ret.original_code = ERROR_MARK; | |
16753 | ret.original_type = NULL; | |
16754 | } | |
16755 | parser->in_transaction = old_in; | |
16756 | ||
16757 | if (!flag_tm) | |
16758 | error_at (loc, (keyword == RID_TRANSACTION_ATOMIC ? | |
16759 | "%<__transaction_atomic%> without transactional memory support enabled" | |
16760 | : "%<__transaction_relaxed %> " | |
16761 | "without transactional memory support enabled")); | |
16762 | ||
16763 | return ret; | |
16764 | } | |
16765 | ||
16766 | /* Parse a __transaction_cancel statement (GCC Extension). | |
16767 | ||
16768 | transaction-cancel-statement: | |
16769 | __transaction_cancel transaction-attribute[opt] ; | |
16770 | ||
16771 | Note that the only valid attribute is "outer". | |
16772 | */ | |
16773 | ||
16774 | static tree | |
bc7bff74 | 16775 | c_parser_transaction_cancel (c_parser *parser) |
4c0315d0 | 16776 | { |
16777 | location_t loc = c_parser_peek_token (parser)->location; | |
16778 | tree attrs; | |
16779 | bool is_outer = false; | |
16780 | ||
16781 | gcc_assert (c_parser_next_token_is_keyword (parser, RID_TRANSACTION_CANCEL)); | |
16782 | c_parser_consume_token (parser); | |
16783 | ||
16784 | attrs = c_parser_transaction_attributes (parser); | |
16785 | if (attrs) | |
16786 | is_outer = (parse_tm_stmt_attr (attrs, TM_STMT_ATTR_OUTER) != 0); | |
16787 | ||
16788 | if (!flag_tm) | |
16789 | { | |
16790 | error_at (loc, "%<__transaction_cancel%> without " | |
16791 | "transactional memory support enabled"); | |
16792 | goto ret_error; | |
16793 | } | |
16794 | else if (parser->in_transaction & TM_STMT_ATTR_RELAXED) | |
16795 | { | |
16796 | error_at (loc, "%<__transaction_cancel%> within a " | |
16797 | "%<__transaction_relaxed%>"); | |
16798 | goto ret_error; | |
16799 | } | |
16800 | else if (is_outer) | |
16801 | { | |
16802 | if ((parser->in_transaction & TM_STMT_ATTR_OUTER) == 0 | |
16803 | && !is_tm_may_cancel_outer (current_function_decl)) | |
16804 | { | |
16805 | error_at (loc, "outer %<__transaction_cancel%> not " | |
16806 | "within outer %<__transaction_atomic%>"); | |
16807 | error_at (loc, " or a %<transaction_may_cancel_outer%> function"); | |
16808 | goto ret_error; | |
16809 | } | |
16810 | } | |
16811 | else if (parser->in_transaction == 0) | |
16812 | { | |
16813 | error_at (loc, "%<__transaction_cancel%> not within " | |
16814 | "%<__transaction_atomic%>"); | |
16815 | goto ret_error; | |
16816 | } | |
16817 | ||
16818 | return add_stmt (build_tm_abort_call (loc, is_outer)); | |
16819 | ||
16820 | ret_error: | |
16821 | return build1 (NOP_EXPR, void_type_node, error_mark_node); | |
16822 | } | |
b75b98aa | 16823 | \f |
1576dec7 | 16824 | /* Parse a single source file. */ |
16825 | ||
16826 | void | |
16827 | c_parse_file (void) | |
16828 | { | |
b75b98aa | 16829 | /* Use local storage to begin. If the first token is a pragma, parse it. |
16830 | If it is #pragma GCC pch_preprocess, then this will load a PCH file | |
16831 | which will cause garbage collection. */ | |
16832 | c_parser tparser; | |
16833 | ||
16834 | memset (&tparser, 0, sizeof tparser); | |
bc7bff74 | 16835 | tparser.tokens = &tparser.tokens_buf[0]; |
b75b98aa | 16836 | the_parser = &tparser; |
16837 | ||
16838 | if (c_parser_peek_token (&tparser)->pragma_kind == PRAGMA_GCC_PCH_PREPROCESS) | |
16839 | c_parser_pragma_pch_preprocess (&tparser); | |
16840 | ||
25a27413 | 16841 | the_parser = ggc_alloc<c_parser> (); |
b75b98aa | 16842 | *the_parser = tparser; |
bc7bff74 | 16843 | if (tparser.tokens == &tparser.tokens_buf[0]) |
16844 | the_parser->tokens = &the_parser->tokens_buf[0]; | |
b75b98aa | 16845 | |
58d82cd0 | 16846 | /* Initialize EH, if we've been told to do so. */ |
16847 | if (flag_exceptions) | |
e38def9c | 16848 | using_eh_for_cleanups (); |
58d82cd0 | 16849 | |
1576dec7 | 16850 | c_parser_translation_unit (the_parser); |
16851 | the_parser = NULL; | |
16852 | } | |
16853 | ||
3c6d4197 | 16854 | /* This function parses Cilk Plus array notation. The starting index is |
16855 | passed in INITIAL_INDEX and the array name is passes in ARRAY_VALUE. The | |
16856 | return value of this function is a tree_node called VALUE_TREE of type | |
16857 | ARRAY_NOTATION_REF. */ | |
16858 | ||
16859 | static tree | |
16860 | c_parser_array_notation (location_t loc, c_parser *parser, tree initial_index, | |
16861 | tree array_value) | |
16862 | { | |
16863 | c_token *token = NULL; | |
16864 | tree start_index = NULL_TREE, end_index = NULL_TREE, stride = NULL_TREE; | |
16865 | tree value_tree = NULL_TREE, type = NULL_TREE, array_type = NULL_TREE; | |
16866 | tree array_type_domain = NULL_TREE; | |
16867 | ||
4879e4cf | 16868 | if (array_value == error_mark_node || initial_index == error_mark_node) |
3c6d4197 | 16869 | { |
16870 | /* No need to continue. If either of these 2 were true, then an error | |
16871 | must be emitted already. Thus, no need to emit them twice. */ | |
16872 | c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL); | |
16873 | return error_mark_node; | |
16874 | } | |
16875 | ||
16876 | array_type = TREE_TYPE (array_value); | |
16877 | gcc_assert (array_type); | |
5fdda74b | 16878 | if (TREE_CODE (array_type) != ARRAY_TYPE |
16879 | && TREE_CODE (array_type) != POINTER_TYPE) | |
16880 | { | |
16881 | error_at (loc, "base of array section must be pointer or array type"); | |
16882 | c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL); | |
16883 | return error_mark_node; | |
16884 | } | |
3c6d4197 | 16885 | type = TREE_TYPE (array_type); |
16886 | token = c_parser_peek_token (parser); | |
16887 | ||
16888 | if (token->type == CPP_EOF) | |
16889 | { | |
16890 | c_parser_error (parser, "expected %<:%> or numeral"); | |
16891 | return value_tree; | |
16892 | } | |
16893 | else if (token->type == CPP_COLON) | |
16894 | { | |
16895 | if (!initial_index) | |
16896 | { | |
16897 | /* If we are here, then we have a case like this A[:]. */ | |
16898 | c_parser_consume_token (parser); | |
16899 | if (TREE_CODE (array_type) == POINTER_TYPE) | |
16900 | { | |
16901 | error_at (loc, "start-index and length fields necessary for " | |
16902 | "using array notations in pointers"); | |
16903 | c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL); | |
16904 | return error_mark_node; | |
16905 | } | |
16906 | if (TREE_CODE (array_type) == FUNCTION_TYPE) | |
16907 | { | |
16908 | error_at (loc, "array notations cannot be used with function " | |
16909 | "type"); | |
16910 | c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL); | |
16911 | return error_mark_node; | |
16912 | } | |
3c6d4197 | 16913 | array_type_domain = TYPE_DOMAIN (array_type); |
16914 | ||
16915 | if (!array_type_domain) | |
16916 | { | |
16917 | error_at (loc, "start-index and length fields necessary for " | |
16918 | "using array notations in dimensionless arrays"); | |
16919 | c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL); | |
16920 | return error_mark_node; | |
16921 | } | |
16922 | ||
16923 | start_index = TYPE_MINVAL (array_type_domain); | |
16924 | start_index = fold_build1 (CONVERT_EXPR, ptrdiff_type_node, | |
16925 | start_index); | |
16926 | if (!TYPE_MAXVAL (array_type_domain) | |
16927 | || !TREE_CONSTANT (TYPE_MAXVAL (array_type_domain))) | |
16928 | { | |
16929 | error_at (loc, "start-index and length fields necessary for " | |
16930 | "using array notations in variable-length arrays"); | |
16931 | c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL); | |
16932 | return error_mark_node; | |
16933 | } | |
16934 | end_index = TYPE_MAXVAL (array_type_domain); | |
16935 | end_index = fold_build2 (PLUS_EXPR, TREE_TYPE (end_index), | |
16936 | end_index, integer_one_node); | |
16937 | end_index = fold_build1 (CONVERT_EXPR, ptrdiff_type_node, end_index); | |
16938 | stride = build_int_cst (integer_type_node, 1); | |
16939 | stride = fold_build1 (CONVERT_EXPR, ptrdiff_type_node, stride); | |
16940 | } | |
16941 | else if (initial_index != error_mark_node) | |
16942 | { | |
16943 | /* If we are here, then there should be 2 possibilities: | |
16944 | 1. Array [EXPR : EXPR] | |
16945 | 2. Array [EXPR : EXPR : EXPR] | |
16946 | */ | |
16947 | start_index = initial_index; | |
16948 | ||
16949 | if (TREE_CODE (array_type) == FUNCTION_TYPE) | |
16950 | { | |
16951 | error_at (loc, "array notations cannot be used with function " | |
16952 | "type"); | |
16953 | c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL); | |
16954 | return error_mark_node; | |
16955 | } | |
3c6d4197 | 16956 | c_parser_consume_token (parser); /* consume the ':' */ |
b560fabd | 16957 | struct c_expr ce = c_parser_expression (parser); |
16958 | ce = convert_lvalue_to_rvalue (loc, ce, false, false); | |
16959 | end_index = ce.value; | |
3c6d4197 | 16960 | if (!end_index || end_index == error_mark_node) |
16961 | { | |
16962 | c_parser_skip_to_end_of_block_or_statement (parser); | |
16963 | return error_mark_node; | |
16964 | } | |
16965 | if (c_parser_peek_token (parser)->type == CPP_COLON) | |
16966 | { | |
16967 | c_parser_consume_token (parser); | |
b560fabd | 16968 | ce = c_parser_expression (parser); |
16969 | ce = convert_lvalue_to_rvalue (loc, ce, false, false); | |
16970 | stride = ce.value; | |
3c6d4197 | 16971 | if (!stride || stride == error_mark_node) |
16972 | { | |
16973 | c_parser_skip_to_end_of_block_or_statement (parser); | |
16974 | return error_mark_node; | |
16975 | } | |
16976 | } | |
16977 | } | |
16978 | else | |
16979 | c_parser_error (parser, "expected array notation expression"); | |
16980 | } | |
16981 | else | |
16982 | c_parser_error (parser, "expected array notation expression"); | |
16983 | ||
16984 | c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, "expected %<]%>"); | |
16985 | ||
16986 | value_tree = build_array_notation_ref (loc, array_value, start_index, | |
16987 | end_index, stride, type); | |
16988 | if (value_tree != error_mark_node) | |
16989 | SET_EXPR_LOCATION (value_tree, loc); | |
16990 | return value_tree; | |
16991 | } | |
16992 | ||
e53d55e7 | 16993 | #include "gt-c-c-parser.h" |