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