1 /* Parser for C and Objective-C.
2 Copyright (C) 1987-2013 Free Software Foundation, Inc.
4 Parser actions based on the old Bison parser; structure somewhat
5 influenced by and fragments based on the C++ parser.
7 This file is part of GCC.
9 GCC is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free
11 Software Foundation; either version 3, or (at your option) any later
14 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING3. If not see
21 <http://www.gnu.org/licenses/>. */
25 Make sure all relevant comments, and all relevant code from all
26 actions, brought over from old parser. Verify exact correspondence
29 Add testcases covering every input symbol in every state in old and
32 Include full syntax for GNU C, including erroneous cases accepted
33 with error messages, in syntax productions in comments.
35 Make more diagnostics in the front end generally take an explicit
36 location rather than implicitly using input_location. */
40 #include "coretypes.h"
41 #include "tm.h" /* For rtl.h: needs enum reg_class. */
43 #include "langhooks.h"
47 #include "c-family/c-pragma.h"
51 #include "c-family/c-common.h"
52 #include "c-family/c-objc.h"
59 /* Initialization routine for this file. */
64 /* The only initialization required is of the reserved word
70 /* Make sure RID_MAX hasn't grown past the 8 bits used to hold the keyword in
71 the c_token structure. */
72 gcc_assert (RID_MAX
<= 255);
79 mask
|= D_ASM
| D_EXT
;
83 if (!c_dialect_objc ())
84 mask
|= D_OBJC
| D_CXX_OBJC
;
86 ridpointers
= ggc_alloc_cleared_vec_tree ((int) RID_MAX
);
87 for (i
= 0; i
< num_c_common_reswords
; i
++)
89 /* If a keyword is disabled, do not enter it into the table
90 and so create a canonical spelling that isn't a keyword. */
91 if (c_common_reswords
[i
].disable
& mask
)
94 && (c_common_reswords
[i
].disable
& D_CXXWARN
))
96 id
= get_identifier (c_common_reswords
[i
].word
);
97 C_SET_RID_CODE (id
, RID_CXX_COMPAT_WARN
);
98 C_IS_RESERVED_WORD (id
) = 1;
103 id
= get_identifier (c_common_reswords
[i
].word
);
104 C_SET_RID_CODE (id
, c_common_reswords
[i
].rid
);
105 C_IS_RESERVED_WORD (id
) = 1;
106 ridpointers
[(int) c_common_reswords
[i
].rid
] = id
;
110 /* The C lexer intermediates between the lexer in cpplib and c-lex.c
111 and the C parser. Unlike the C++ lexer, the parser structure
112 stores the lexer information instead of using a separate structure.
113 Identifiers are separated into ordinary identifiers, type names,
114 keywords and some other Objective-C types of identifiers, and some
115 look-ahead is maintained.
117 ??? It might be a good idea to lex the whole file up front (as for
118 C++). It would then be possible to share more of the C and C++
119 lexer code, if desired. */
121 /* The following local token type is used. */
124 #define CPP_KEYWORD ((enum cpp_ttype) (N_TTYPES + 1))
126 /* More information about the type of a CPP_NAME token. */
127 typedef enum c_id_kind
{
128 /* An ordinary identifier. */
130 /* An identifier declared as a typedef name. */
132 /* An identifier declared as an Objective-C class name. */
134 /* An address space identifier. */
136 /* Not an identifier. */
140 /* A single C token after string literal concatenation and conversion
141 of preprocessing tokens to tokens. */
142 typedef struct GTY (()) c_token
{
143 /* The kind of token. */
144 ENUM_BITFIELD (cpp_ttype
) type
: 8;
145 /* If this token is a CPP_NAME, this value indicates whether also
146 declared as some kind of type. Otherwise, it is C_ID_NONE. */
147 ENUM_BITFIELD (c_id_kind
) id_kind
: 8;
148 /* If this token is a keyword, this value indicates which keyword.
149 Otherwise, this value is RID_MAX. */
150 ENUM_BITFIELD (rid
) keyword
: 8;
151 /* If this token is a CPP_PRAGMA, this indicates the pragma that
152 was seen. Otherwise it is PRAGMA_NONE. */
153 ENUM_BITFIELD (pragma_kind
) pragma_kind
: 8;
154 /* The location at which this token was found. */
156 /* The value associated with this token, if any. */
160 /* A parser structure recording information about the state and
161 context of parsing. Includes lexer information with up to two
162 tokens of look-ahead; more are not needed for C. */
163 typedef struct GTY(()) c_parser
{
164 /* The look-ahead tokens. */
166 /* How many look-ahead tokens are available (0, 1 or 2). */
168 /* True if a syntax error is being recovered from; false otherwise.
169 c_parser_error sets this flag. It should clear this flag when
170 enough tokens have been consumed to recover from the error. */
171 BOOL_BITFIELD error
: 1;
172 /* True if we're processing a pragma, and shouldn't automatically
173 consume CPP_PRAGMA_EOL. */
174 BOOL_BITFIELD in_pragma
: 1;
175 /* True if we're parsing the outermost block of an if statement. */
176 BOOL_BITFIELD in_if_block
: 1;
177 /* True if we want to lex an untranslated string. */
178 BOOL_BITFIELD lex_untranslated_string
: 1;
180 /* Objective-C specific parser/lexer information. */
182 /* True if we are in a context where the Objective-C "PQ" keywords
183 are considered keywords. */
184 BOOL_BITFIELD objc_pq_context
: 1;
185 /* True if we are parsing a (potential) Objective-C foreach
186 statement. This is set to true after we parsed 'for (' and while
187 we wait for 'in' or ';' to decide if it's a standard C for loop or an
188 Objective-C foreach loop. */
189 BOOL_BITFIELD objc_could_be_foreach_context
: 1;
190 /* The following flag is needed to contextualize Objective-C lexical
191 analysis. In some cases (e.g., 'int NSObject;'), it is
192 undesirable to bind an identifier to an Objective-C class, even
193 if a class with that name exists. */
194 BOOL_BITFIELD objc_need_raw_identifier
: 1;
195 /* Nonzero if we're processing a __transaction statement. The value
196 is 1 | TM_STMT_ATTR_*. */
197 unsigned int in_transaction
: 4;
198 /* True if we are in a context where the Objective-C "Property attribute"
199 keywords are valid. */
200 BOOL_BITFIELD objc_property_attr_context
: 1;
204 /* The actual parser and external interface. ??? Does this need to be
205 garbage-collected? */
207 static GTY (()) c_parser
*the_parser
;
209 /* Read in and lex a single token, storing it in *TOKEN. */
212 c_lex_one_token (c_parser
*parser
, c_token
*token
)
214 timevar_push (TV_LEX
);
216 token
->type
= c_lex_with_flags (&token
->value
, &token
->location
, NULL
,
217 (parser
->lex_untranslated_string
218 ? C_LEX_STRING_NO_TRANSLATE
: 0));
219 token
->id_kind
= C_ID_NONE
;
220 token
->keyword
= RID_MAX
;
221 token
->pragma_kind
= PRAGMA_NONE
;
229 bool objc_force_identifier
= parser
->objc_need_raw_identifier
;
230 if (c_dialect_objc ())
231 parser
->objc_need_raw_identifier
= false;
233 if (C_IS_RESERVED_WORD (token
->value
))
235 enum rid rid_code
= C_RID_CODE (token
->value
);
237 if (rid_code
== RID_CXX_COMPAT_WARN
)
239 warning_at (token
->location
,
241 "identifier %qE conflicts with C++ keyword",
244 else if (rid_code
>= RID_FIRST_ADDR_SPACE
245 && rid_code
<= RID_LAST_ADDR_SPACE
)
247 token
->id_kind
= C_ID_ADDRSPACE
;
248 token
->keyword
= rid_code
;
251 else if (c_dialect_objc () && OBJC_IS_PQ_KEYWORD (rid_code
))
253 /* We found an Objective-C "pq" keyword (in, out,
254 inout, bycopy, byref, oneway). They need special
255 care because the interpretation depends on the
257 if (parser
->objc_pq_context
)
259 token
->type
= CPP_KEYWORD
;
260 token
->keyword
= rid_code
;
263 else if (parser
->objc_could_be_foreach_context
264 && rid_code
== RID_IN
)
266 /* We are in Objective-C, inside a (potential)
267 foreach context (which means after having
268 parsed 'for (', but before having parsed ';'),
269 and we found 'in'. We consider it the keyword
270 which terminates the declaration at the
271 beginning of a foreach-statement. Note that
272 this means you can't use 'in' for anything else
273 in that context; in particular, in Objective-C
274 you can't use 'in' as the name of the running
275 variable in a C for loop. We could potentially
276 try to add code here to disambiguate, but it
277 seems a reasonable limitation. */
278 token
->type
= CPP_KEYWORD
;
279 token
->keyword
= rid_code
;
282 /* Else, "pq" keywords outside of the "pq" context are
283 not keywords, and we fall through to the code for
286 else if (c_dialect_objc () && OBJC_IS_PATTR_KEYWORD (rid_code
))
288 /* We found an Objective-C "property attribute"
289 keyword (getter, setter, readonly, etc). These are
290 only valid in the property context. */
291 if (parser
->objc_property_attr_context
)
293 token
->type
= CPP_KEYWORD
;
294 token
->keyword
= rid_code
;
297 /* Else they are not special keywords.
300 else if (c_dialect_objc ()
301 && (OBJC_IS_AT_KEYWORD (rid_code
)
302 || OBJC_IS_CXX_KEYWORD (rid_code
)))
304 /* We found one of the Objective-C "@" keywords (defs,
305 selector, synchronized, etc) or one of the
306 Objective-C "cxx" keywords (class, private,
307 protected, public, try, catch, throw) without a
308 preceding '@' sign. Do nothing and fall through to
309 the code for normal tokens (in C++ we would still
310 consider the CXX ones keywords, but not in C). */
315 token
->type
= CPP_KEYWORD
;
316 token
->keyword
= rid_code
;
321 decl
= lookup_name (token
->value
);
324 if (TREE_CODE (decl
) == TYPE_DECL
)
326 token
->id_kind
= C_ID_TYPENAME
;
330 else if (c_dialect_objc ())
332 tree objc_interface_decl
= objc_is_class_name (token
->value
);
333 /* Objective-C class names are in the same namespace as
334 variables and typedefs, and hence are shadowed by local
336 if (objc_interface_decl
337 && (!objc_force_identifier
|| global_bindings_p ()))
339 token
->value
= objc_interface_decl
;
340 token
->id_kind
= C_ID_CLASSNAME
;
344 token
->id_kind
= C_ID_ID
;
348 /* This only happens in Objective-C; it must be a keyword. */
349 token
->type
= CPP_KEYWORD
;
350 switch (C_RID_CODE (token
->value
))
352 /* Replace 'class' with '@class', 'private' with '@private',
353 etc. This prevents confusion with the C++ keyword
354 'class', and makes the tokens consistent with other
355 Objective-C 'AT' keywords. For example '@class' is
356 reported as RID_AT_CLASS which is consistent with
357 '@synchronized', which is reported as
360 case RID_CLASS
: token
->keyword
= RID_AT_CLASS
; break;
361 case RID_PRIVATE
: token
->keyword
= RID_AT_PRIVATE
; break;
362 case RID_PROTECTED
: token
->keyword
= RID_AT_PROTECTED
; break;
363 case RID_PUBLIC
: token
->keyword
= RID_AT_PUBLIC
; break;
364 case RID_THROW
: token
->keyword
= RID_AT_THROW
; break;
365 case RID_TRY
: token
->keyword
= RID_AT_TRY
; break;
366 case RID_CATCH
: token
->keyword
= RID_AT_CATCH
; break;
367 default: token
->keyword
= C_RID_CODE (token
->value
);
372 case CPP_CLOSE_PAREN
:
374 /* These tokens may affect the interpretation of any identifiers
375 following, if doing Objective-C. */
376 if (c_dialect_objc ())
377 parser
->objc_need_raw_identifier
= false;
380 /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */
381 token
->pragma_kind
= (enum pragma_kind
) TREE_INT_CST_LOW (token
->value
);
387 timevar_pop (TV_LEX
);
390 /* Return a pointer to the next token from PARSER, reading it in if
393 static inline c_token
*
394 c_parser_peek_token (c_parser
*parser
)
396 if (parser
->tokens_avail
== 0)
398 c_lex_one_token (parser
, &parser
->tokens
[0]);
399 parser
->tokens_avail
= 1;
401 return &parser
->tokens
[0];
404 /* Return true if the next token from PARSER has the indicated
408 c_parser_next_token_is (c_parser
*parser
, enum cpp_ttype type
)
410 return c_parser_peek_token (parser
)->type
== type
;
413 /* Return true if the next token from PARSER does not have the
417 c_parser_next_token_is_not (c_parser
*parser
, enum cpp_ttype type
)
419 return !c_parser_next_token_is (parser
, type
);
422 /* Return true if the next token from PARSER is the indicated
426 c_parser_next_token_is_keyword (c_parser
*parser
, enum rid keyword
)
428 return c_parser_peek_token (parser
)->keyword
== keyword
;
431 /* Return a pointer to the next-but-one token from PARSER, reading it
432 in if necessary. The next token is already read in. */
435 c_parser_peek_2nd_token (c_parser
*parser
)
437 if (parser
->tokens_avail
>= 2)
438 return &parser
->tokens
[1];
439 gcc_assert (parser
->tokens_avail
== 1);
440 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
441 gcc_assert (parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
442 c_lex_one_token (parser
, &parser
->tokens
[1]);
443 parser
->tokens_avail
= 2;
444 return &parser
->tokens
[1];
447 /* Return true if TOKEN can start a type name,
450 c_token_starts_typename (c_token
*token
)
455 switch (token
->id_kind
)
464 gcc_assert (c_dialect_objc ());
470 switch (token
->keyword
)
503 if (c_dialect_objc ())
511 enum c_lookahead_kind
{
512 /* Always treat unknown identifiers as typenames. */
515 /* Could be parsing a nonabstract declarator. Only treat an identifier
516 as a typename if followed by another identifier or a star. */
517 cla_nonabstract_decl
,
519 /* Never treat identifiers as typenames. */
523 /* Return true if the next token from PARSER can start a type name,
524 false otherwise. LA specifies how to do lookahead in order to
525 detect unknown type names. If unsure, pick CLA_PREFER_ID. */
528 c_parser_next_tokens_start_typename (c_parser
*parser
, enum c_lookahead_kind la
)
530 c_token
*token
= c_parser_peek_token (parser
);
531 if (c_token_starts_typename (token
))
534 /* Try a bit harder to detect an unknown typename. */
535 if (la
!= cla_prefer_id
536 && token
->type
== CPP_NAME
537 && token
->id_kind
== C_ID_ID
539 /* Do not try too hard when we could have "object in array". */
540 && !parser
->objc_could_be_foreach_context
542 && (la
== cla_prefer_type
543 || c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
544 || c_parser_peek_2nd_token (parser
)->type
== CPP_MULT
)
546 /* Only unknown identifiers. */
547 && !lookup_name (token
->value
))
553 /* Return true if TOKEN is a type qualifier, false otherwise. */
555 c_token_is_qualifier (c_token
*token
)
560 switch (token
->id_kind
)
568 switch (token
->keyword
)
585 /* Return true if the next token from PARSER is a type qualifier,
588 c_parser_next_token_is_qualifier (c_parser
*parser
)
590 c_token
*token
= c_parser_peek_token (parser
);
591 return c_token_is_qualifier (token
);
594 /* Return true if TOKEN can start declaration specifiers, false
597 c_token_starts_declspecs (c_token
*token
)
602 switch (token
->id_kind
)
611 gcc_assert (c_dialect_objc ());
617 switch (token
->keyword
)
659 if (c_dialect_objc ())
668 /* Return true if TOKEN can start declaration specifiers or a static
669 assertion, false otherwise. */
671 c_token_starts_declaration (c_token
*token
)
673 if (c_token_starts_declspecs (token
)
674 || token
->keyword
== RID_STATIC_ASSERT
)
680 /* Return true if the next token from PARSER can start declaration
681 specifiers, false otherwise. */
683 c_parser_next_token_starts_declspecs (c_parser
*parser
)
685 c_token
*token
= c_parser_peek_token (parser
);
687 /* In Objective-C, a classname normally starts a declspecs unless it
688 is immediately followed by a dot. In that case, it is the
689 Objective-C 2.0 "dot-syntax" for class objects, ie, calls the
690 setter/getter on the class. c_token_starts_declspecs() can't
691 differentiate between the two cases because it only checks the
692 current token, so we have a special check here. */
693 if (c_dialect_objc ()
694 && token
->type
== CPP_NAME
695 && token
->id_kind
== C_ID_CLASSNAME
696 && c_parser_peek_2nd_token (parser
)->type
== CPP_DOT
)
699 return c_token_starts_declspecs (token
);
702 /* Return true if the next tokens from PARSER can start declaration
703 specifiers or a static assertion, false otherwise. */
705 c_parser_next_tokens_start_declaration (c_parser
*parser
)
707 c_token
*token
= c_parser_peek_token (parser
);
710 if (c_dialect_objc ()
711 && token
->type
== CPP_NAME
712 && token
->id_kind
== C_ID_CLASSNAME
713 && c_parser_peek_2nd_token (parser
)->type
== CPP_DOT
)
716 /* Labels do not start declarations. */
717 if (token
->type
== CPP_NAME
718 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
721 if (c_token_starts_declaration (token
))
724 if (c_parser_next_tokens_start_typename (parser
, cla_nonabstract_decl
))
730 /* Consume the next token from PARSER. */
733 c_parser_consume_token (c_parser
*parser
)
735 gcc_assert (parser
->tokens_avail
>= 1);
736 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
737 gcc_assert (!parser
->in_pragma
|| parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
738 gcc_assert (parser
->error
|| parser
->tokens
[0].type
!= CPP_PRAGMA
);
739 if (parser
->tokens_avail
== 2)
740 parser
->tokens
[0] = parser
->tokens
[1];
741 parser
->tokens_avail
--;
744 /* Expect the current token to be a #pragma. Consume it and remember
745 that we've begun parsing a pragma. */
748 c_parser_consume_pragma (c_parser
*parser
)
750 gcc_assert (!parser
->in_pragma
);
751 gcc_assert (parser
->tokens_avail
>= 1);
752 gcc_assert (parser
->tokens
[0].type
== CPP_PRAGMA
);
753 if (parser
->tokens_avail
== 2)
754 parser
->tokens
[0] = parser
->tokens
[1];
755 parser
->tokens_avail
--;
756 parser
->in_pragma
= true;
759 /* Update the globals input_location and in_system_header from
762 c_parser_set_source_position_from_token (c_token
*token
)
764 if (token
->type
!= CPP_EOF
)
766 input_location
= token
->location
;
770 /* Issue a diagnostic of the form
771 FILE:LINE: MESSAGE before TOKEN
772 where TOKEN is the next token in the input stream of PARSER.
773 MESSAGE (specified by the caller) is usually of the form "expected
776 Do not issue a diagnostic if still recovering from an error.
778 ??? This is taken from the C++ parser, but building up messages in
779 this way is not i18n-friendly and some other approach should be
783 c_parser_error (c_parser
*parser
, const char *gmsgid
)
785 c_token
*token
= c_parser_peek_token (parser
);
788 parser
->error
= true;
791 /* This diagnostic makes more sense if it is tagged to the line of
792 the token we just peeked at. */
793 c_parser_set_source_position_from_token (token
);
794 c_parse_error (gmsgid
,
795 /* Because c_parse_error does not understand
796 CPP_KEYWORD, keywords are treated like
798 (token
->type
== CPP_KEYWORD
? CPP_NAME
: token
->type
),
799 /* ??? The C parser does not save the cpp flags of a
800 token, we need to pass 0 here and we will not get
801 the source spelling of some tokens but rather the
802 canonical spelling. */
803 token
->value
, /*flags=*/0);
806 /* If the next token is of the indicated TYPE, consume it. Otherwise,
807 issue the error MSGID. If MSGID is NULL then a message has already
808 been produced and no message will be produced this time. Returns
809 true if found, false otherwise. */
812 c_parser_require (c_parser
*parser
,
816 if (c_parser_next_token_is (parser
, type
))
818 c_parser_consume_token (parser
);
823 c_parser_error (parser
, msgid
);
828 /* If the next token is the indicated keyword, consume it. Otherwise,
829 issue the error MSGID. Returns true if found, false otherwise. */
832 c_parser_require_keyword (c_parser
*parser
,
836 if (c_parser_next_token_is_keyword (parser
, keyword
))
838 c_parser_consume_token (parser
);
843 c_parser_error (parser
, msgid
);
848 /* Like c_parser_require, except that tokens will be skipped until the
849 desired token is found. An error message is still produced if the
850 next token is not as expected. If MSGID is NULL then a message has
851 already been produced and no message will be produced this
855 c_parser_skip_until_found (c_parser
*parser
,
859 unsigned nesting_depth
= 0;
861 if (c_parser_require (parser
, type
, msgid
))
864 /* Skip tokens until the desired token is found. */
867 /* Peek at the next token. */
868 c_token
*token
= c_parser_peek_token (parser
);
869 /* If we've reached the token we want, consume it and stop. */
870 if (token
->type
== type
&& !nesting_depth
)
872 c_parser_consume_token (parser
);
876 /* If we've run out of tokens, stop. */
877 if (token
->type
== CPP_EOF
)
879 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
881 if (token
->type
== CPP_OPEN_BRACE
882 || token
->type
== CPP_OPEN_PAREN
883 || token
->type
== CPP_OPEN_SQUARE
)
885 else if (token
->type
== CPP_CLOSE_BRACE
886 || token
->type
== CPP_CLOSE_PAREN
887 || token
->type
== CPP_CLOSE_SQUARE
)
889 if (nesting_depth
-- == 0)
892 /* Consume this token. */
893 c_parser_consume_token (parser
);
895 parser
->error
= false;
898 /* Skip tokens until the end of a parameter is found, but do not
899 consume the comma, semicolon or closing delimiter. */
902 c_parser_skip_to_end_of_parameter (c_parser
*parser
)
904 unsigned nesting_depth
= 0;
908 c_token
*token
= c_parser_peek_token (parser
);
909 if ((token
->type
== CPP_COMMA
|| token
->type
== CPP_SEMICOLON
)
912 /* If we've run out of tokens, stop. */
913 if (token
->type
== CPP_EOF
)
915 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
917 if (token
->type
== CPP_OPEN_BRACE
918 || token
->type
== CPP_OPEN_PAREN
919 || token
->type
== CPP_OPEN_SQUARE
)
921 else if (token
->type
== CPP_CLOSE_BRACE
922 || token
->type
== CPP_CLOSE_PAREN
923 || token
->type
== CPP_CLOSE_SQUARE
)
925 if (nesting_depth
-- == 0)
928 /* Consume this token. */
929 c_parser_consume_token (parser
);
931 parser
->error
= false;
934 /* Expect to be at the end of the pragma directive and consume an
935 end of line marker. */
938 c_parser_skip_to_pragma_eol (c_parser
*parser
)
940 gcc_assert (parser
->in_pragma
);
941 parser
->in_pragma
= false;
943 if (!c_parser_require (parser
, CPP_PRAGMA_EOL
, "expected end of line"))
946 c_token
*token
= c_parser_peek_token (parser
);
947 if (token
->type
== CPP_EOF
)
949 if (token
->type
== CPP_PRAGMA_EOL
)
951 c_parser_consume_token (parser
);
954 c_parser_consume_token (parser
);
957 parser
->error
= false;
960 /* Skip tokens until we have consumed an entire block, or until we
961 have consumed a non-nested ';'. */
964 c_parser_skip_to_end_of_block_or_statement (c_parser
*parser
)
966 unsigned nesting_depth
= 0;
967 bool save_error
= parser
->error
;
973 /* Peek at the next token. */
974 token
= c_parser_peek_token (parser
);
982 if (parser
->in_pragma
)
987 /* If the next token is a ';', we have reached the
988 end of the statement. */
991 /* Consume the ';'. */
992 c_parser_consume_token (parser
);
997 case CPP_CLOSE_BRACE
:
998 /* If the next token is a non-nested '}', then we have
999 reached the end of the current block. */
1000 if (nesting_depth
== 0 || --nesting_depth
== 0)
1002 c_parser_consume_token (parser
);
1007 case CPP_OPEN_BRACE
:
1008 /* If it the next token is a '{', then we are entering a new
1009 block. Consume the entire block. */
1014 /* If we see a pragma, consume the whole thing at once. We
1015 have some safeguards against consuming pragmas willy-nilly.
1016 Normally, we'd expect to be here with parser->error set,
1017 which disables these safeguards. But it's possible to get
1018 here for secondary error recovery, after parser->error has
1020 c_parser_consume_pragma (parser
);
1021 c_parser_skip_to_pragma_eol (parser
);
1022 parser
->error
= save_error
;
1029 c_parser_consume_token (parser
);
1033 parser
->error
= false;
1036 /* CPP's options (initialized by c-opts.c). */
1037 extern cpp_options
*cpp_opts
;
1039 /* Save the warning flags which are controlled by __extension__. */
1042 disable_extension_diagnostics (void)
1045 | (warn_pointer_arith
<< 1)
1046 | (warn_traditional
<< 2)
1048 | (warn_long_long
<< 4)
1049 | (warn_cxx_compat
<< 5)
1050 | (warn_overlength_strings
<< 6));
1051 cpp_opts
->cpp_pedantic
= pedantic
= 0;
1052 warn_pointer_arith
= 0;
1053 cpp_opts
->cpp_warn_traditional
= warn_traditional
= 0;
1055 cpp_opts
->cpp_warn_long_long
= warn_long_long
= 0;
1056 warn_cxx_compat
= 0;
1057 warn_overlength_strings
= 0;
1061 /* Restore the warning flags which are controlled by __extension__.
1062 FLAGS is the return value from disable_extension_diagnostics. */
1065 restore_extension_diagnostics (int flags
)
1067 cpp_opts
->cpp_pedantic
= pedantic
= flags
& 1;
1068 warn_pointer_arith
= (flags
>> 1) & 1;
1069 cpp_opts
->cpp_warn_traditional
= warn_traditional
= (flags
>> 2) & 1;
1070 flag_iso
= (flags
>> 3) & 1;
1071 cpp_opts
->cpp_warn_long_long
= warn_long_long
= (flags
>> 4) & 1;
1072 warn_cxx_compat
= (flags
>> 5) & 1;
1073 warn_overlength_strings
= (flags
>> 6) & 1;
1076 /* Possibly kinds of declarator to parse. */
1077 typedef enum c_dtr_syn
{
1078 /* A normal declarator with an identifier. */
1080 /* An abstract declarator (maybe empty). */
1082 /* A parameter declarator: may be either, but after a type name does
1083 not redeclare a typedef name as an identifier if it can
1084 alternatively be interpreted as a typedef name; see DR#009,
1085 applied in C90 TC1, omitted from C99 and reapplied in C99 TC2
1086 following DR#249. For example, given a typedef T, "int T" and
1087 "int *T" are valid parameter declarations redeclaring T, while
1088 "int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are
1089 abstract declarators rather than involving redundant parentheses;
1090 the same applies with attributes inside the parentheses before
1095 /* The binary operation precedence levels, where 0 is a dummy lowest level
1096 used for the bottom of the stack. */
1097 enum c_parser_prec
{
1112 static void c_parser_external_declaration (c_parser
*);
1113 static void c_parser_asm_definition (c_parser
*);
1114 static void c_parser_declaration_or_fndef (c_parser
*, bool, bool, bool,
1115 bool, bool, tree
*);
1116 static void c_parser_static_assert_declaration_no_semi (c_parser
*);
1117 static void c_parser_static_assert_declaration (c_parser
*);
1118 static void c_parser_declspecs (c_parser
*, struct c_declspecs
*, bool, bool,
1119 bool, enum c_lookahead_kind
);
1120 static struct c_typespec
c_parser_enum_specifier (c_parser
*);
1121 static struct c_typespec
c_parser_struct_or_union_specifier (c_parser
*);
1122 static tree
c_parser_struct_declaration (c_parser
*);
1123 static struct c_typespec
c_parser_typeof_specifier (c_parser
*);
1124 static tree
c_parser_alignas_specifier (c_parser
*);
1125 static struct c_declarator
*c_parser_declarator (c_parser
*, bool, c_dtr_syn
,
1127 static struct c_declarator
*c_parser_direct_declarator (c_parser
*, bool,
1129 static struct c_declarator
*c_parser_direct_declarator_inner (c_parser
*,
1131 struct c_declarator
*);
1132 static struct c_arg_info
*c_parser_parms_declarator (c_parser
*, bool, tree
);
1133 static struct c_arg_info
*c_parser_parms_list_declarator (c_parser
*, tree
,
1135 static struct c_parm
*c_parser_parameter_declaration (c_parser
*, tree
);
1136 static tree
c_parser_simple_asm_expr (c_parser
*);
1137 static tree
c_parser_attributes (c_parser
*);
1138 static struct c_type_name
*c_parser_type_name (c_parser
*);
1139 static struct c_expr
c_parser_initializer (c_parser
*);
1140 static struct c_expr
c_parser_braced_init (c_parser
*, tree
, bool);
1141 static void c_parser_initelt (c_parser
*, struct obstack
*);
1142 static void c_parser_initval (c_parser
*, struct c_expr
*,
1144 static tree
c_parser_compound_statement (c_parser
*);
1145 static void c_parser_compound_statement_nostart (c_parser
*);
1146 static void c_parser_label (c_parser
*);
1147 static void c_parser_statement (c_parser
*);
1148 static void c_parser_statement_after_labels (c_parser
*);
1149 static void c_parser_if_statement (c_parser
*);
1150 static void c_parser_switch_statement (c_parser
*);
1151 static void c_parser_while_statement (c_parser
*);
1152 static void c_parser_do_statement (c_parser
*);
1153 static void c_parser_for_statement (c_parser
*);
1154 static tree
c_parser_asm_statement (c_parser
*);
1155 static tree
c_parser_asm_operands (c_parser
*);
1156 static tree
c_parser_asm_goto_operands (c_parser
*);
1157 static tree
c_parser_asm_clobbers (c_parser
*);
1158 static struct c_expr
c_parser_expr_no_commas (c_parser
*, struct c_expr
*);
1159 static struct c_expr
c_parser_conditional_expression (c_parser
*,
1161 static struct c_expr
c_parser_binary_expression (c_parser
*, struct c_expr
*,
1162 enum c_parser_prec
);
1163 static struct c_expr
c_parser_cast_expression (c_parser
*, struct c_expr
*);
1164 static struct c_expr
c_parser_unary_expression (c_parser
*);
1165 static struct c_expr
c_parser_sizeof_expression (c_parser
*);
1166 static struct c_expr
c_parser_alignof_expression (c_parser
*);
1167 static struct c_expr
c_parser_postfix_expression (c_parser
*);
1168 static struct c_expr
c_parser_postfix_expression_after_paren_type (c_parser
*,
1169 struct c_type_name
*,
1171 static struct c_expr
c_parser_postfix_expression_after_primary (c_parser
*,
1174 static tree
c_parser_transaction (c_parser
*, enum rid
);
1175 static struct c_expr
c_parser_transaction_expression (c_parser
*, enum rid
);
1176 static tree
c_parser_transaction_cancel (c_parser
*);
1177 static struct c_expr
c_parser_expression (c_parser
*);
1178 static struct c_expr
c_parser_expression_conv (c_parser
*);
1179 static vec
<tree
, va_gc
> *c_parser_expr_list (c_parser
*, bool, bool,
1180 vec
<tree
, va_gc
> **, location_t
*,
1182 static void c_parser_omp_construct (c_parser
*);
1183 static void c_parser_omp_threadprivate (c_parser
*);
1184 static void c_parser_omp_barrier (c_parser
*);
1185 static void c_parser_omp_flush (c_parser
*);
1186 static void c_parser_omp_taskwait (c_parser
*);
1187 static void c_parser_omp_taskyield (c_parser
*);
1189 enum pragma_context
{ pragma_external
, pragma_stmt
, pragma_compound
};
1190 static bool c_parser_pragma (c_parser
*, enum pragma_context
);
1192 /* These Objective-C parser functions are only ever called when
1193 compiling Objective-C. */
1194 static void c_parser_objc_class_definition (c_parser
*, tree
);
1195 static void c_parser_objc_class_instance_variables (c_parser
*);
1196 static void c_parser_objc_class_declaration (c_parser
*);
1197 static void c_parser_objc_alias_declaration (c_parser
*);
1198 static void c_parser_objc_protocol_definition (c_parser
*, tree
);
1199 static bool c_parser_objc_method_type (c_parser
*);
1200 static void c_parser_objc_method_definition (c_parser
*);
1201 static void c_parser_objc_methodprotolist (c_parser
*);
1202 static void c_parser_objc_methodproto (c_parser
*);
1203 static tree
c_parser_objc_method_decl (c_parser
*, bool, tree
*, tree
*);
1204 static tree
c_parser_objc_type_name (c_parser
*);
1205 static tree
c_parser_objc_protocol_refs (c_parser
*);
1206 static void c_parser_objc_try_catch_finally_statement (c_parser
*);
1207 static void c_parser_objc_synchronized_statement (c_parser
*);
1208 static tree
c_parser_objc_selector (c_parser
*);
1209 static tree
c_parser_objc_selector_arg (c_parser
*);
1210 static tree
c_parser_objc_receiver (c_parser
*);
1211 static tree
c_parser_objc_message_args (c_parser
*);
1212 static tree
c_parser_objc_keywordexpr (c_parser
*);
1213 static void c_parser_objc_at_property_declaration (c_parser
*);
1214 static void c_parser_objc_at_synthesize_declaration (c_parser
*);
1215 static void c_parser_objc_at_dynamic_declaration (c_parser
*);
1216 static bool c_parser_objc_diagnose_bad_element_prefix
1217 (c_parser
*, struct c_declspecs
*);
1219 static tree
c_parser_array_notation (location_t
, c_parser
*, tree
, tree
);
1221 /* Parse a translation unit (C90 6.7, C99 6.9).
1224 external-declarations
1226 external-declarations:
1227 external-declaration
1228 external-declarations external-declaration
1237 c_parser_translation_unit (c_parser
*parser
)
1239 if (c_parser_next_token_is (parser
, CPP_EOF
))
1241 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
1242 "ISO C forbids an empty translation unit");
1246 void *obstack_position
= obstack_alloc (&parser_obstack
, 0);
1247 mark_valid_location_for_stdc_pragma (false);
1251 c_parser_external_declaration (parser
);
1252 obstack_free (&parser_obstack
, obstack_position
);
1254 while (c_parser_next_token_is_not (parser
, CPP_EOF
));
1258 /* Parse an external declaration (C90 6.7, C99 6.9).
1260 external-declaration:
1266 external-declaration:
1269 __extension__ external-declaration
1273 external-declaration:
1274 objc-class-definition
1275 objc-class-declaration
1276 objc-alias-declaration
1277 objc-protocol-definition
1278 objc-method-definition
1283 c_parser_external_declaration (c_parser
*parser
)
1286 switch (c_parser_peek_token (parser
)->type
)
1289 switch (c_parser_peek_token (parser
)->keyword
)
1292 ext
= disable_extension_diagnostics ();
1293 c_parser_consume_token (parser
);
1294 c_parser_external_declaration (parser
);
1295 restore_extension_diagnostics (ext
);
1298 c_parser_asm_definition (parser
);
1300 case RID_AT_INTERFACE
:
1301 case RID_AT_IMPLEMENTATION
:
1302 gcc_assert (c_dialect_objc ());
1303 c_parser_objc_class_definition (parser
, NULL_TREE
);
1306 gcc_assert (c_dialect_objc ());
1307 c_parser_objc_class_declaration (parser
);
1310 gcc_assert (c_dialect_objc ());
1311 c_parser_objc_alias_declaration (parser
);
1313 case RID_AT_PROTOCOL
:
1314 gcc_assert (c_dialect_objc ());
1315 c_parser_objc_protocol_definition (parser
, NULL_TREE
);
1317 case RID_AT_PROPERTY
:
1318 gcc_assert (c_dialect_objc ());
1319 c_parser_objc_at_property_declaration (parser
);
1321 case RID_AT_SYNTHESIZE
:
1322 gcc_assert (c_dialect_objc ());
1323 c_parser_objc_at_synthesize_declaration (parser
);
1325 case RID_AT_DYNAMIC
:
1326 gcc_assert (c_dialect_objc ());
1327 c_parser_objc_at_dynamic_declaration (parser
);
1330 gcc_assert (c_dialect_objc ());
1331 c_parser_consume_token (parser
);
1332 objc_finish_implementation ();
1339 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
1340 "ISO C does not allow extra %<;%> outside of a function");
1341 c_parser_consume_token (parser
);
1344 mark_valid_location_for_stdc_pragma (true);
1345 c_parser_pragma (parser
, pragma_external
);
1346 mark_valid_location_for_stdc_pragma (false);
1350 if (c_dialect_objc ())
1352 c_parser_objc_method_definition (parser
);
1355 /* Else fall through, and yield a syntax error trying to parse
1356 as a declaration or function definition. */
1359 /* A declaration or a function definition (or, in Objective-C,
1360 an @interface or @protocol with prefix attributes). We can
1361 only tell which after parsing the declaration specifiers, if
1362 any, and the first declarator. */
1363 c_parser_declaration_or_fndef (parser
, true, true, true, false, true, NULL
);
1368 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1369 6.7, 6.9.1). If FNDEF_OK is true, a function definition is
1370 accepted; otherwise (old-style parameter declarations) only other
1371 declarations are accepted. If STATIC_ASSERT_OK is true, a static
1372 assertion is accepted; otherwise (old-style parameter declarations)
1373 it is not. If NESTED is true, we are inside a function or parsing
1374 old-style parameter declarations; any functions encountered are
1375 nested functions and declaration specifiers are required; otherwise
1376 we are at top level and functions are normal functions and
1377 declaration specifiers may be optional. If EMPTY_OK is true, empty
1378 declarations are OK (subject to all other constraints); otherwise
1379 (old-style parameter declarations) they are diagnosed. If
1380 START_ATTR_OK is true, the declaration specifiers may start with
1381 attributes; otherwise they may not.
1382 OBJC_FOREACH_OBJECT_DECLARATION can be used to get back the parsed
1383 declaration when parsing an Objective-C foreach statement.
1386 declaration-specifiers init-declarator-list[opt] ;
1387 static_assert-declaration
1389 function-definition:
1390 declaration-specifiers[opt] declarator declaration-list[opt]
1395 declaration-list declaration
1397 init-declarator-list:
1399 init-declarator-list , init-declarator
1402 declarator simple-asm-expr[opt] attributes[opt]
1403 declarator simple-asm-expr[opt] attributes[opt] = initializer
1407 nested-function-definition:
1408 declaration-specifiers declarator declaration-list[opt]
1412 attributes objc-class-definition
1413 attributes objc-category-definition
1414 attributes objc-protocol-definition
1416 The simple-asm-expr and attributes are GNU extensions.
1418 This function does not handle __extension__; that is handled in its
1419 callers. ??? Following the old parser, __extension__ may start
1420 external declarations, declarations in functions and declarations
1421 at the start of "for" loops, but not old-style parameter
1424 C99 requires declaration specifiers in a function definition; the
1425 absence is diagnosed through the diagnosis of implicit int. In GNU
1426 C we also allow but diagnose declarations without declaration
1427 specifiers, but only at top level (elsewhere they conflict with
1430 In Objective-C, declarations of the looping variable in a foreach
1431 statement are exceptionally terminated by 'in' (for example, 'for
1432 (NSObject *object in array) { ... }').
1437 threadprivate-directive */
1440 c_parser_declaration_or_fndef (c_parser
*parser
, bool fndef_ok
,
1441 bool static_assert_ok
, bool empty_ok
,
1442 bool nested
, bool start_attr_ok
,
1443 tree
*objc_foreach_object_declaration
)
1445 struct c_declspecs
*specs
;
1447 tree all_prefix_attrs
;
1448 bool diagnosed_no_specs
= false;
1449 location_t here
= c_parser_peek_token (parser
)->location
;
1451 if (static_assert_ok
1452 && c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
1454 c_parser_static_assert_declaration (parser
);
1457 specs
= build_null_declspecs ();
1459 /* Try to detect an unknown type name when we have "A B" or "A *B". */
1460 if (c_parser_peek_token (parser
)->type
== CPP_NAME
1461 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
1462 && (c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
1463 || c_parser_peek_2nd_token (parser
)->type
== CPP_MULT
)
1464 && (!nested
|| !lookup_name (c_parser_peek_token (parser
)->value
)))
1466 error_at (here
, "unknown type name %qE",
1467 c_parser_peek_token (parser
)->value
);
1469 /* Parse declspecs normally to get a correct pointer type, but avoid
1470 a further "fails to be a type name" error. Refuse nested functions
1471 since it is not how the user likely wants us to recover. */
1472 c_parser_peek_token (parser
)->type
= CPP_KEYWORD
;
1473 c_parser_peek_token (parser
)->keyword
= RID_VOID
;
1474 c_parser_peek_token (parser
)->value
= error_mark_node
;
1478 c_parser_declspecs (parser
, specs
, true, true, start_attr_ok
, cla_nonabstract_decl
);
1481 c_parser_skip_to_end_of_block_or_statement (parser
);
1484 if (nested
&& !specs
->declspecs_seen_p
)
1486 c_parser_error (parser
, "expected declaration specifiers");
1487 c_parser_skip_to_end_of_block_or_statement (parser
);
1490 finish_declspecs (specs
);
1491 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1497 shadow_tag_warned (specs
, 1);
1498 pedwarn (here
, 0, "empty declaration");
1500 c_parser_consume_token (parser
);
1504 /* Provide better error recovery. Note that a type name here is usually
1505 better diagnosed as a redeclaration. */
1507 && specs
->typespec_kind
== ctsk_tagdef
1508 && c_parser_next_token_starts_declspecs (parser
)
1509 && !c_parser_next_token_is (parser
, CPP_NAME
))
1511 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
1512 parser
->error
= false;
1513 shadow_tag_warned (specs
, 1);
1516 else if (c_dialect_objc ())
1518 /* Prefix attributes are an error on method decls. */
1519 switch (c_parser_peek_token (parser
)->type
)
1523 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1527 warning_at (c_parser_peek_token (parser
)->location
,
1529 "prefix attributes are ignored for methods");
1530 specs
->attrs
= NULL_TREE
;
1533 c_parser_objc_method_definition (parser
);
1535 c_parser_objc_methodproto (parser
);
1541 /* This is where we parse 'attributes @interface ...',
1542 'attributes @implementation ...', 'attributes @protocol ...'
1543 (where attributes could be, for example, __attribute__
1546 switch (c_parser_peek_token (parser
)->keyword
)
1548 case RID_AT_INTERFACE
:
1550 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1552 c_parser_objc_class_definition (parser
, specs
->attrs
);
1556 case RID_AT_IMPLEMENTATION
:
1558 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1562 warning_at (c_parser_peek_token (parser
)->location
,
1564 "prefix attributes are ignored for implementations");
1565 specs
->attrs
= NULL_TREE
;
1567 c_parser_objc_class_definition (parser
, NULL_TREE
);
1571 case RID_AT_PROTOCOL
:
1573 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1575 c_parser_objc_protocol_definition (parser
, specs
->attrs
);
1582 case RID_AT_PROPERTY
:
1585 c_parser_error (parser
, "unexpected attribute");
1586 specs
->attrs
= NULL
;
1594 pending_xref_error ();
1595 prefix_attrs
= specs
->attrs
;
1596 all_prefix_attrs
= prefix_attrs
;
1597 specs
->attrs
= NULL_TREE
;
1600 struct c_declarator
*declarator
;
1604 /* Declaring either one or more declarators (in which case we
1605 should diagnose if there were no declaration specifiers) or a
1606 function definition (in which case the diagnostic for
1607 implicit int suffices). */
1608 declarator
= c_parser_declarator (parser
,
1609 specs
->typespec_kind
!= ctsk_none
,
1610 C_DTR_NORMAL
, &dummy
);
1611 if (declarator
== NULL
)
1613 c_parser_skip_to_end_of_block_or_statement (parser
);
1616 if (c_parser_next_token_is (parser
, CPP_EQ
)
1617 || c_parser_next_token_is (parser
, CPP_COMMA
)
1618 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
1619 || c_parser_next_token_is_keyword (parser
, RID_ASM
)
1620 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
)
1621 || c_parser_next_token_is_keyword (parser
, RID_IN
))
1623 tree asm_name
= NULL_TREE
;
1624 tree postfix_attrs
= NULL_TREE
;
1625 if (!diagnosed_no_specs
&& !specs
->declspecs_seen_p
)
1627 diagnosed_no_specs
= true;
1628 pedwarn (here
, 0, "data definition has no type or storage class");
1630 /* Having seen a data definition, there cannot now be a
1631 function definition. */
1633 if (c_parser_next_token_is_keyword (parser
, RID_ASM
))
1634 asm_name
= c_parser_simple_asm_expr (parser
);
1635 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1636 postfix_attrs
= c_parser_attributes (parser
);
1637 if (c_parser_next_token_is (parser
, CPP_EQ
))
1641 location_t init_loc
;
1642 c_parser_consume_token (parser
);
1643 /* The declaration of the variable is in effect while
1644 its initializer is parsed. */
1645 d
= start_decl (declarator
, specs
, true,
1646 chainon (postfix_attrs
, all_prefix_attrs
));
1648 d
= error_mark_node
;
1649 start_init (d
, asm_name
, global_bindings_p ());
1650 init_loc
= c_parser_peek_token (parser
)->location
;
1651 init
= c_parser_initializer (parser
);
1653 if (d
!= error_mark_node
)
1655 maybe_warn_string_init (TREE_TYPE (d
), init
);
1656 finish_decl (d
, init_loc
, init
.value
,
1657 init
.original_type
, asm_name
);
1662 tree d
= start_decl (declarator
, specs
, false,
1663 chainon (postfix_attrs
,
1666 finish_decl (d
, UNKNOWN_LOCATION
, NULL_TREE
,
1667 NULL_TREE
, asm_name
);
1669 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
1672 *objc_foreach_object_declaration
= d
;
1674 *objc_foreach_object_declaration
= error_mark_node
;
1677 if (c_parser_next_token_is (parser
, CPP_COMMA
))
1679 c_parser_consume_token (parser
);
1680 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1681 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
1684 all_prefix_attrs
= prefix_attrs
;
1687 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1689 c_parser_consume_token (parser
);
1692 else if (c_parser_next_token_is_keyword (parser
, RID_IN
))
1694 /* This can only happen in Objective-C: we found the
1695 'in' that terminates the declaration inside an
1696 Objective-C foreach statement. Do not consume the
1697 token, so that the caller can use it to determine
1698 that this indeed is a foreach context. */
1703 c_parser_error (parser
, "expected %<,%> or %<;%>");
1704 c_parser_skip_to_end_of_block_or_statement (parser
);
1710 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, "
1711 "%<asm%> or %<__attribute__%>");
1712 c_parser_skip_to_end_of_block_or_statement (parser
);
1715 /* Function definition (nested or otherwise). */
1718 pedwarn (here
, OPT_Wpedantic
, "ISO C forbids nested functions");
1719 c_push_function_context ();
1721 if (!start_function (specs
, declarator
, all_prefix_attrs
))
1723 /* This can appear in many cases looking nothing like a
1724 function definition, so we don't give a more specific
1725 error suggesting there was one. */
1726 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
1727 "or %<__attribute__%>");
1729 c_pop_function_context ();
1733 if (DECL_DECLARED_INLINE_P (current_function_decl
))
1734 tv
= TV_PARSE_INLINE
;
1739 /* Parse old-style parameter declarations. ??? Attributes are
1740 not allowed to start declaration specifiers here because of a
1741 syntax conflict between a function declaration with attribute
1742 suffix and a function definition with an attribute prefix on
1743 first old-style parameter declaration. Following the old
1744 parser, they are not accepted on subsequent old-style
1745 parameter declarations either. However, there is no
1746 ambiguity after the first declaration, nor indeed on the
1747 first as long as we don't allow postfix attributes after a
1748 declarator with a nonempty identifier list in a definition;
1749 and postfix attributes have never been accepted here in
1750 function definitions either. */
1751 while (c_parser_next_token_is_not (parser
, CPP_EOF
)
1752 && c_parser_next_token_is_not (parser
, CPP_OPEN_BRACE
))
1753 c_parser_declaration_or_fndef (parser
, false, false, false,
1755 store_parm_decls ();
1756 DECL_STRUCT_FUNCTION (current_function_decl
)->function_start_locus
1757 = c_parser_peek_token (parser
)->location
;
1758 fnbody
= c_parser_compound_statement (parser
);
1759 if (flag_enable_cilkplus
&& contains_array_notation_expr (fnbody
))
1760 fnbody
= expand_array_notation_exprs (fnbody
);
1763 tree decl
= current_function_decl
;
1764 /* Mark nested functions as needing static-chain initially.
1765 lower_nested_functions will recompute it but the
1766 DECL_STATIC_CHAIN flag is also used before that happens,
1767 by initializer_constant_valid_p. See gcc.dg/nested-fn-2.c. */
1768 DECL_STATIC_CHAIN (decl
) = 1;
1771 c_pop_function_context ();
1772 add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl
), DECL_EXPR
, decl
));
1785 /* Parse an asm-definition (asm() outside a function body). This is a
1793 c_parser_asm_definition (c_parser
*parser
)
1795 tree asm_str
= c_parser_simple_asm_expr (parser
);
1797 add_asm_node (asm_str
);
1798 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
1801 /* Parse a static assertion (C11 6.7.10).
1803 static_assert-declaration:
1804 static_assert-declaration-no-semi ;
1808 c_parser_static_assert_declaration (c_parser
*parser
)
1810 c_parser_static_assert_declaration_no_semi (parser
);
1812 || !c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
1813 c_parser_skip_to_end_of_block_or_statement (parser
);
1816 /* Parse a static assertion (C11 6.7.10), without the trailing
1819 static_assert-declaration-no-semi:
1820 _Static_assert ( constant-expression , string-literal )
1824 c_parser_static_assert_declaration_no_semi (c_parser
*parser
)
1826 location_t assert_loc
, value_loc
;
1830 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
));
1831 assert_loc
= c_parser_peek_token (parser
)->location
;
1835 pedwarn (assert_loc
, OPT_Wpedantic
,
1836 "ISO C99 does not support %<_Static_assert%>");
1838 pedwarn (assert_loc
, OPT_Wpedantic
,
1839 "ISO C90 does not support %<_Static_assert%>");
1841 c_parser_consume_token (parser
);
1842 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
1844 value_loc
= c_parser_peek_token (parser
)->location
;
1845 value
= c_parser_expr_no_commas (parser
, NULL
).value
;
1846 parser
->lex_untranslated_string
= true;
1847 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
1849 parser
->lex_untranslated_string
= false;
1852 switch (c_parser_peek_token (parser
)->type
)
1858 case CPP_UTF8STRING
:
1859 string
= c_parser_peek_token (parser
)->value
;
1860 c_parser_consume_token (parser
);
1861 parser
->lex_untranslated_string
= false;
1864 c_parser_error (parser
, "expected string literal");
1865 parser
->lex_untranslated_string
= false;
1868 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
1870 if (!INTEGRAL_TYPE_P (TREE_TYPE (value
)))
1872 error_at (value_loc
, "expression in static assertion is not an integer");
1875 if (TREE_CODE (value
) != INTEGER_CST
)
1877 value
= c_fully_fold (value
, false, NULL
);
1878 if (TREE_CODE (value
) == INTEGER_CST
)
1879 pedwarn (value_loc
, OPT_Wpedantic
, "expression in static assertion "
1880 "is not an integer constant expression");
1882 if (TREE_CODE (value
) != INTEGER_CST
)
1884 error_at (value_loc
, "expression in static assertion is not constant");
1887 constant_expression_warning (value
);
1888 if (integer_zerop (value
))
1889 error_at (assert_loc
, "static assertion failed: %E", string
);
1892 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
1893 6.7), adding them to SPECS (which may already include some).
1894 Storage class specifiers are accepted iff SCSPEC_OK; type
1895 specifiers are accepted iff TYPESPEC_OK; attributes are accepted at
1896 the start iff START_ATTR_OK.
1898 declaration-specifiers:
1899 storage-class-specifier declaration-specifiers[opt]
1900 type-specifier declaration-specifiers[opt]
1901 type-qualifier declaration-specifiers[opt]
1902 function-specifier declaration-specifiers[opt]
1903 alignment-specifier declaration-specifiers[opt]
1905 Function specifiers (inline) are from C99, and are currently
1906 handled as storage class specifiers, as is __thread. Alignment
1907 specifiers are from C11.
1909 C90 6.5.1, C99 6.7.1:
1910 storage-class-specifier:
1922 (_Noreturn is new in C11.)
1924 C90 6.5.2, C99 6.7.2:
1937 [_Imaginary removed in C99 TC2]
1938 struct-or-union-specifier
1942 (_Bool and _Complex are new in C99.)
1944 C90 6.5.3, C99 6.7.3:
1950 address-space-qualifier
1952 (restrict is new in C99.)
1956 declaration-specifiers:
1957 attributes declaration-specifiers[opt]
1963 identifier recognized by the target
1965 storage-class-specifier:
1978 (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
1979 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
1984 class-name objc-protocol-refs[opt]
1985 typedef-name objc-protocol-refs
1990 c_parser_declspecs (c_parser
*parser
, struct c_declspecs
*specs
,
1991 bool scspec_ok
, bool typespec_ok
, bool start_attr_ok
,
1992 enum c_lookahead_kind la
)
1994 bool attrs_ok
= start_attr_ok
;
1995 bool seen_type
= specs
->typespec_kind
!= ctsk_none
;
1998 gcc_assert (la
== cla_prefer_id
);
2000 while (c_parser_next_token_is (parser
, CPP_NAME
)
2001 || c_parser_next_token_is (parser
, CPP_KEYWORD
)
2002 || (c_dialect_objc () && c_parser_next_token_is (parser
, CPP_LESS
)))
2004 struct c_typespec t
;
2007 location_t loc
= c_parser_peek_token (parser
)->location
;
2009 /* If we cannot accept a type, exit if the next token must start
2010 one. Also, if we already have seen a tagged definition,
2011 a typename would be an error anyway and likely the user
2012 has simply forgotten a semicolon, so we exit. */
2013 if ((!typespec_ok
|| specs
->typespec_kind
== ctsk_tagdef
)
2014 && c_parser_next_tokens_start_typename (parser
, la
)
2015 && !c_parser_next_token_is_qualifier (parser
))
2018 if (c_parser_next_token_is (parser
, CPP_NAME
))
2020 c_token
*name_token
= c_parser_peek_token (parser
);
2021 tree value
= name_token
->value
;
2022 c_id_kind kind
= name_token
->id_kind
;
2024 if (kind
== C_ID_ADDRSPACE
)
2027 = name_token
->keyword
- RID_FIRST_ADDR_SPACE
;
2028 declspecs_add_addrspace (name_token
->location
, specs
, as
);
2029 c_parser_consume_token (parser
);
2034 gcc_assert (!c_parser_next_token_is_qualifier (parser
));
2036 /* If we cannot accept a type, and the next token must start one,
2037 exit. Do the same if we already have seen a tagged definition,
2038 since it would be an error anyway and likely the user has simply
2039 forgotten a semicolon. */
2040 if (seen_type
|| !c_parser_next_tokens_start_typename (parser
, la
))
2043 /* Now at an unknown typename (C_ID_ID), a C_ID_TYPENAME or
2044 a C_ID_CLASSNAME. */
2045 c_parser_consume_token (parser
);
2048 if (kind
== C_ID_ID
)
2050 error ("unknown type name %qE", value
);
2051 t
.kind
= ctsk_typedef
;
2052 t
.spec
= error_mark_node
;
2054 else if (kind
== C_ID_TYPENAME
2055 && (!c_dialect_objc ()
2056 || c_parser_next_token_is_not (parser
, CPP_LESS
)))
2058 t
.kind
= ctsk_typedef
;
2059 /* For a typedef name, record the meaning, not the name.
2060 In case of 'foo foo, bar;'. */
2061 t
.spec
= lookup_name (value
);
2065 tree proto
= NULL_TREE
;
2066 gcc_assert (c_dialect_objc ());
2068 if (c_parser_next_token_is (parser
, CPP_LESS
))
2069 proto
= c_parser_objc_protocol_refs (parser
);
2070 t
.spec
= objc_get_protocol_qualified_type (value
, proto
);
2073 t
.expr_const_operands
= true;
2074 declspecs_add_type (name_token
->location
, specs
, t
);
2077 if (c_parser_next_token_is (parser
, CPP_LESS
))
2079 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
2080 nisse@lysator.liu.se. */
2082 gcc_assert (c_dialect_objc ());
2083 if (!typespec_ok
|| seen_type
)
2085 proto
= c_parser_objc_protocol_refs (parser
);
2087 t
.spec
= objc_get_protocol_qualified_type (NULL_TREE
, proto
);
2089 t
.expr_const_operands
= true;
2090 declspecs_add_type (loc
, specs
, t
);
2093 gcc_assert (c_parser_next_token_is (parser
, CPP_KEYWORD
));
2094 switch (c_parser_peek_token (parser
)->keyword
)
2107 /* TODO: Distinguish between function specifiers (inline, noreturn)
2108 and storage class specifiers, either here or in
2109 declspecs_add_scspec. */
2110 declspecs_add_scspec (loc
, specs
,
2111 c_parser_peek_token (parser
)->value
);
2112 c_parser_consume_token (parser
);
2136 if (c_dialect_objc ())
2137 parser
->objc_need_raw_identifier
= true;
2138 t
.kind
= ctsk_resword
;
2139 t
.spec
= c_parser_peek_token (parser
)->value
;
2141 t
.expr_const_operands
= true;
2142 declspecs_add_type (loc
, specs
, t
);
2143 c_parser_consume_token (parser
);
2150 t
= c_parser_enum_specifier (parser
);
2151 declspecs_add_type (loc
, specs
, t
);
2159 t
= c_parser_struct_or_union_specifier (parser
);
2160 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE
, t
.spec
);
2161 declspecs_add_type (loc
, specs
, t
);
2164 /* ??? The old parser rejected typeof after other type
2165 specifiers, but is a syntax error the best way of
2167 if (!typespec_ok
|| seen_type
)
2171 t
= c_parser_typeof_specifier (parser
);
2172 declspecs_add_type (loc
, specs
, t
);
2178 declspecs_add_qual (loc
, specs
, c_parser_peek_token (parser
)->value
);
2179 c_parser_consume_token (parser
);
2184 attrs
= c_parser_attributes (parser
);
2185 declspecs_add_attrs (loc
, specs
, attrs
);
2188 align
= c_parser_alignas_specifier (parser
);
2189 declspecs_add_alignas (loc
, specs
, align
);
2198 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
2201 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
2202 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
2203 enum attributes[opt] identifier
2205 The form with trailing comma is new in C99. The forms with
2206 attributes are GNU extensions. In GNU C, we accept any expression
2207 without commas in the syntax (assignment expressions, not just
2208 conditional expressions); assignment expressions will be diagnosed
2213 enumerator-list , enumerator
2216 enumeration-constant
2217 enumeration-constant = constant-expression
2220 static struct c_typespec
2221 c_parser_enum_specifier (c_parser
*parser
)
2223 struct c_typespec ret
;
2225 tree ident
= NULL_TREE
;
2226 location_t enum_loc
;
2227 location_t ident_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2228 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ENUM
));
2229 enum_loc
= c_parser_peek_token (parser
)->location
;
2230 c_parser_consume_token (parser
);
2231 attrs
= c_parser_attributes (parser
);
2232 enum_loc
= c_parser_peek_token (parser
)->location
;
2233 /* Set the location in case we create a decl now. */
2234 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2235 if (c_parser_next_token_is (parser
, CPP_NAME
))
2237 ident
= c_parser_peek_token (parser
)->value
;
2238 ident_loc
= c_parser_peek_token (parser
)->location
;
2239 enum_loc
= ident_loc
;
2240 c_parser_consume_token (parser
);
2242 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2244 /* Parse an enum definition. */
2245 struct c_enum_contents the_enum
;
2248 /* We chain the enumerators in reverse order, then put them in
2249 forward order at the end. */
2251 timevar_push (TV_PARSE_ENUM
);
2252 type
= start_enum (enum_loc
, &the_enum
, ident
);
2254 c_parser_consume_token (parser
);
2262 location_t comma_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2263 location_t decl_loc
, value_loc
;
2264 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
2266 c_parser_error (parser
, "expected identifier");
2267 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2268 values
= error_mark_node
;
2271 token
= c_parser_peek_token (parser
);
2272 enum_id
= token
->value
;
2273 /* Set the location in case we create a decl now. */
2274 c_parser_set_source_position_from_token (token
);
2275 decl_loc
= value_loc
= token
->location
;
2276 c_parser_consume_token (parser
);
2277 if (c_parser_next_token_is (parser
, CPP_EQ
))
2279 c_parser_consume_token (parser
);
2280 value_loc
= c_parser_peek_token (parser
)->location
;
2281 enum_value
= c_parser_expr_no_commas (parser
, NULL
).value
;
2284 enum_value
= NULL_TREE
;
2285 enum_decl
= build_enumerator (decl_loc
, value_loc
,
2286 &the_enum
, enum_id
, enum_value
);
2287 TREE_CHAIN (enum_decl
) = values
;
2290 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2292 comma_loc
= c_parser_peek_token (parser
)->location
;
2294 c_parser_consume_token (parser
);
2296 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2298 if (seen_comma
&& !flag_isoc99
)
2299 pedwarn (comma_loc
, OPT_Wpedantic
, "comma at end of enumerator list");
2300 c_parser_consume_token (parser
);
2305 c_parser_error (parser
, "expected %<,%> or %<}%>");
2306 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2307 values
= error_mark_node
;
2311 postfix_attrs
= c_parser_attributes (parser
);
2312 ret
.spec
= finish_enum (type
, nreverse (values
),
2313 chainon (attrs
, postfix_attrs
));
2314 ret
.kind
= ctsk_tagdef
;
2315 ret
.expr
= NULL_TREE
;
2316 ret
.expr_const_operands
= true;
2317 timevar_pop (TV_PARSE_ENUM
);
2322 c_parser_error (parser
, "expected %<{%>");
2323 ret
.spec
= error_mark_node
;
2324 ret
.kind
= ctsk_tagref
;
2325 ret
.expr
= NULL_TREE
;
2326 ret
.expr_const_operands
= true;
2329 ret
= parser_xref_tag (ident_loc
, ENUMERAL_TYPE
, ident
);
2330 /* In ISO C, enumerated types can be referred to only if already
2332 if (pedantic
&& !COMPLETE_TYPE_P (ret
.spec
))
2335 pedwarn (enum_loc
, OPT_Wpedantic
,
2336 "ISO C forbids forward references to %<enum%> types");
2341 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
2343 struct-or-union-specifier:
2344 struct-or-union attributes[opt] identifier[opt]
2345 { struct-contents } attributes[opt]
2346 struct-or-union attributes[opt] identifier
2349 struct-declaration-list
2351 struct-declaration-list:
2352 struct-declaration ;
2353 struct-declaration-list struct-declaration ;
2360 struct-declaration-list struct-declaration
2362 struct-declaration-list:
2363 struct-declaration-list ;
2366 (Note that in the syntax here, unlike that in ISO C, the semicolons
2367 are included here rather than in struct-declaration, in order to
2368 describe the syntax with extra semicolons and missing semicolon at
2373 struct-declaration-list:
2374 @defs ( class-name )
2376 (Note this does not include a trailing semicolon, but can be
2377 followed by further declarations, and gets a pedwarn-if-pedantic
2378 when followed by a semicolon.) */
2380 static struct c_typespec
2381 c_parser_struct_or_union_specifier (c_parser
*parser
)
2383 struct c_typespec ret
;
2385 tree ident
= NULL_TREE
;
2386 location_t struct_loc
;
2387 location_t ident_loc
= UNKNOWN_LOCATION
;
2388 enum tree_code code
;
2389 switch (c_parser_peek_token (parser
)->keyword
)
2400 struct_loc
= c_parser_peek_token (parser
)->location
;
2401 c_parser_consume_token (parser
);
2402 attrs
= c_parser_attributes (parser
);
2404 /* Set the location in case we create a decl now. */
2405 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2407 if (c_parser_next_token_is (parser
, CPP_NAME
))
2409 ident
= c_parser_peek_token (parser
)->value
;
2410 ident_loc
= c_parser_peek_token (parser
)->location
;
2411 struct_loc
= ident_loc
;
2412 c_parser_consume_token (parser
);
2414 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2416 /* Parse a struct or union definition. Start the scope of the
2417 tag before parsing components. */
2418 struct c_struct_parse_info
*struct_info
;
2419 tree type
= start_struct (struct_loc
, code
, ident
, &struct_info
);
2421 /* We chain the components in reverse order, then put them in
2422 forward order at the end. Each struct-declaration may
2423 declare multiple components (comma-separated), so we must use
2424 chainon to join them, although when parsing each
2425 struct-declaration we can use TREE_CHAIN directly.
2427 The theory behind all this is that there will be more
2428 semicolon separated fields than comma separated fields, and
2429 so we'll be minimizing the number of node traversals required
2432 timevar_push (TV_PARSE_STRUCT
);
2433 contents
= NULL_TREE
;
2434 c_parser_consume_token (parser
);
2435 /* Handle the Objective-C @defs construct,
2436 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
2437 if (c_parser_next_token_is_keyword (parser
, RID_AT_DEFS
))
2440 gcc_assert (c_dialect_objc ());
2441 c_parser_consume_token (parser
);
2442 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2444 if (c_parser_next_token_is (parser
, CPP_NAME
)
2445 && c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
)
2447 name
= c_parser_peek_token (parser
)->value
;
2448 c_parser_consume_token (parser
);
2452 c_parser_error (parser
, "expected class name");
2453 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2456 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2458 contents
= nreverse (objc_get_class_ivars (name
));
2461 /* Parse the struct-declarations and semicolons. Problems with
2462 semicolons are diagnosed here; empty structures are diagnosed
2467 /* Parse any stray semicolon. */
2468 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2470 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
2471 "extra semicolon in struct or union specified");
2472 c_parser_consume_token (parser
);
2475 /* Stop if at the end of the struct or union contents. */
2476 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2478 c_parser_consume_token (parser
);
2481 /* Accept #pragmas at struct scope. */
2482 if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
2484 c_parser_pragma (parser
, pragma_external
);
2487 /* Parse some comma-separated declarations, but not the
2488 trailing semicolon if any. */
2489 decls
= c_parser_struct_declaration (parser
);
2490 contents
= chainon (decls
, contents
);
2491 /* If no semicolon follows, either we have a parse error or
2492 are at the end of the struct or union and should
2494 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2495 c_parser_consume_token (parser
);
2498 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2499 pedwarn (c_parser_peek_token (parser
)->location
, 0,
2500 "no semicolon at end of struct or union");
2501 else if (parser
->error
2502 || !c_parser_next_token_starts_declspecs (parser
))
2504 c_parser_error (parser
, "expected %<;%>");
2505 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2509 /* If we come here, we have already emitted an error
2510 for an expected `;', identifier or `(', and we also
2511 recovered already. Go on with the next field. */
2514 postfix_attrs
= c_parser_attributes (parser
);
2515 ret
.spec
= finish_struct (struct_loc
, type
, nreverse (contents
),
2516 chainon (attrs
, postfix_attrs
), struct_info
);
2517 ret
.kind
= ctsk_tagdef
;
2518 ret
.expr
= NULL_TREE
;
2519 ret
.expr_const_operands
= true;
2520 timevar_pop (TV_PARSE_STRUCT
);
2525 c_parser_error (parser
, "expected %<{%>");
2526 ret
.spec
= error_mark_node
;
2527 ret
.kind
= ctsk_tagref
;
2528 ret
.expr
= NULL_TREE
;
2529 ret
.expr_const_operands
= true;
2532 ret
= parser_xref_tag (ident_loc
, code
, ident
);
2536 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
2537 the trailing semicolon.
2540 specifier-qualifier-list struct-declarator-list
2541 static_assert-declaration-no-semi
2543 specifier-qualifier-list:
2544 type-specifier specifier-qualifier-list[opt]
2545 type-qualifier specifier-qualifier-list[opt]
2546 attributes specifier-qualifier-list[opt]
2548 struct-declarator-list:
2550 struct-declarator-list , attributes[opt] struct-declarator
2553 declarator attributes[opt]
2554 declarator[opt] : constant-expression attributes[opt]
2559 __extension__ struct-declaration
2560 specifier-qualifier-list
2562 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
2563 of attributes where shown is a GNU extension. In GNU C, we accept
2564 any expression without commas in the syntax (assignment
2565 expressions, not just conditional expressions); assignment
2566 expressions will be diagnosed as non-constant. */
2569 c_parser_struct_declaration (c_parser
*parser
)
2571 struct c_declspecs
*specs
;
2573 tree all_prefix_attrs
;
2575 location_t decl_loc
;
2576 if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
2580 ext
= disable_extension_diagnostics ();
2581 c_parser_consume_token (parser
);
2582 decl
= c_parser_struct_declaration (parser
);
2583 restore_extension_diagnostics (ext
);
2586 if (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
2588 c_parser_static_assert_declaration_no_semi (parser
);
2591 specs
= build_null_declspecs ();
2592 decl_loc
= c_parser_peek_token (parser
)->location
;
2593 c_parser_declspecs (parser
, specs
, false, true, true, cla_nonabstract_decl
);
2596 if (!specs
->declspecs_seen_p
)
2598 c_parser_error (parser
, "expected specifier-qualifier-list");
2601 finish_declspecs (specs
);
2602 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2603 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2606 if (specs
->typespec_kind
== ctsk_none
)
2608 pedwarn (decl_loc
, OPT_Wpedantic
,
2609 "ISO C forbids member declarations with no members");
2610 shadow_tag_warned (specs
, pedantic
);
2615 /* Support for unnamed structs or unions as members of
2616 structs or unions (which is [a] useful and [b] supports
2620 ret
= grokfield (c_parser_peek_token (parser
)->location
,
2621 build_id_declarator (NULL_TREE
), specs
,
2624 decl_attributes (&ret
, attrs
, 0);
2629 /* Provide better error recovery. Note that a type name here is valid,
2630 and will be treated as a field name. */
2631 if (specs
->typespec_kind
== ctsk_tagdef
2632 && TREE_CODE (specs
->type
) != ENUMERAL_TYPE
2633 && c_parser_next_token_starts_declspecs (parser
)
2634 && !c_parser_next_token_is (parser
, CPP_NAME
))
2636 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
2637 parser
->error
= false;
2641 pending_xref_error ();
2642 prefix_attrs
= specs
->attrs
;
2643 all_prefix_attrs
= prefix_attrs
;
2644 specs
->attrs
= NULL_TREE
;
2648 /* Declaring one or more declarators or un-named bit-fields. */
2649 struct c_declarator
*declarator
;
2651 if (c_parser_next_token_is (parser
, CPP_COLON
))
2652 declarator
= build_id_declarator (NULL_TREE
);
2654 declarator
= c_parser_declarator (parser
,
2655 specs
->typespec_kind
!= ctsk_none
,
2656 C_DTR_NORMAL
, &dummy
);
2657 if (declarator
== NULL
)
2659 c_parser_skip_to_end_of_block_or_statement (parser
);
2662 if (c_parser_next_token_is (parser
, CPP_COLON
)
2663 || c_parser_next_token_is (parser
, CPP_COMMA
)
2664 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2665 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
)
2666 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2668 tree postfix_attrs
= NULL_TREE
;
2669 tree width
= NULL_TREE
;
2671 if (c_parser_next_token_is (parser
, CPP_COLON
))
2673 c_parser_consume_token (parser
);
2674 width
= c_parser_expr_no_commas (parser
, NULL
).value
;
2676 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2677 postfix_attrs
= c_parser_attributes (parser
);
2678 d
= grokfield (c_parser_peek_token (parser
)->location
,
2679 declarator
, specs
, width
, &all_prefix_attrs
);
2680 decl_attributes (&d
, chainon (postfix_attrs
,
2681 all_prefix_attrs
), 0);
2682 DECL_CHAIN (d
) = decls
;
2684 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2685 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
2688 all_prefix_attrs
= prefix_attrs
;
2689 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2690 c_parser_consume_token (parser
);
2691 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2692 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2694 /* Semicolon consumed in caller. */
2699 c_parser_error (parser
, "expected %<,%>, %<;%> or %<}%>");
2705 c_parser_error (parser
,
2706 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
2707 "%<__attribute__%>");
2714 /* Parse a typeof specifier (a GNU extension).
2717 typeof ( expression )
2718 typeof ( type-name )
2721 static struct c_typespec
2722 c_parser_typeof_specifier (c_parser
*parser
)
2724 struct c_typespec ret
;
2725 ret
.kind
= ctsk_typeof
;
2726 ret
.spec
= error_mark_node
;
2727 ret
.expr
= NULL_TREE
;
2728 ret
.expr_const_operands
= true;
2729 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TYPEOF
));
2730 c_parser_consume_token (parser
);
2731 c_inhibit_evaluation_warnings
++;
2733 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2735 c_inhibit_evaluation_warnings
--;
2739 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
2741 struct c_type_name
*type
= c_parser_type_name (parser
);
2742 c_inhibit_evaluation_warnings
--;
2746 ret
.spec
= groktypename (type
, &ret
.expr
, &ret
.expr_const_operands
);
2747 pop_maybe_used (variably_modified_type_p (ret
.spec
, NULL_TREE
));
2753 location_t here
= c_parser_peek_token (parser
)->location
;
2754 struct c_expr expr
= c_parser_expression (parser
);
2755 c_inhibit_evaluation_warnings
--;
2757 if (TREE_CODE (expr
.value
) == COMPONENT_REF
2758 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
2759 error_at (here
, "%<typeof%> applied to a bit-field");
2760 mark_exp_read (expr
.value
);
2761 ret
.spec
= TREE_TYPE (expr
.value
);
2762 was_vm
= variably_modified_type_p (ret
.spec
, NULL_TREE
);
2763 /* This is returned with the type so that when the type is
2764 evaluated, this can be evaluated. */
2766 ret
.expr
= c_fully_fold (expr
.value
, false, &ret
.expr_const_operands
);
2767 pop_maybe_used (was_vm
);
2769 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
2773 /* Parse an alignment-specifier.
2777 alignment-specifier:
2778 _Alignas ( type-name )
2779 _Alignas ( constant-expression )
2783 c_parser_alignas_specifier (c_parser
* parser
)
2785 tree ret
= error_mark_node
;
2786 location_t loc
= c_parser_peek_token (parser
)->location
;
2787 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNAS
));
2788 c_parser_consume_token (parser
);
2792 pedwarn (loc
, OPT_Wpedantic
,
2793 "ISO C99 does not support %<_Alignas%>");
2795 pedwarn (loc
, OPT_Wpedantic
,
2796 "ISO C90 does not support %<_Alignas%>");
2798 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2800 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
2802 struct c_type_name
*type
= c_parser_type_name (parser
);
2804 ret
= c_alignof (loc
, groktypename (type
, NULL
, NULL
));
2807 ret
= c_parser_expr_no_commas (parser
, NULL
).value
;
2808 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
2812 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
2813 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
2814 be redeclared; otherwise it may not. KIND indicates which kind of
2815 declarator is wanted. Returns a valid declarator except in the
2816 case of a syntax error in which case NULL is returned. *SEEN_ID is
2817 set to true if an identifier being declared is seen; this is used
2818 to diagnose bad forms of abstract array declarators and to
2819 determine whether an identifier list is syntactically permitted.
2822 pointer[opt] direct-declarator
2826 ( attributes[opt] declarator )
2827 direct-declarator array-declarator
2828 direct-declarator ( parameter-type-list )
2829 direct-declarator ( identifier-list[opt] )
2832 * type-qualifier-list[opt]
2833 * type-qualifier-list[opt] pointer
2835 type-qualifier-list:
2838 type-qualifier-list type-qualifier
2839 type-qualifier-list attributes
2841 parameter-type-list:
2843 parameter-list , ...
2846 parameter-declaration
2847 parameter-list , parameter-declaration
2849 parameter-declaration:
2850 declaration-specifiers declarator attributes[opt]
2851 declaration-specifiers abstract-declarator[opt] attributes[opt]
2855 identifier-list , identifier
2857 abstract-declarator:
2859 pointer[opt] direct-abstract-declarator
2861 direct-abstract-declarator:
2862 ( attributes[opt] abstract-declarator )
2863 direct-abstract-declarator[opt] array-declarator
2864 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
2869 direct-declarator ( parameter-forward-declarations
2870 parameter-type-list[opt] )
2872 direct-abstract-declarator:
2873 direct-abstract-declarator[opt] ( parameter-forward-declarations
2874 parameter-type-list[opt] )
2876 parameter-forward-declarations:
2878 parameter-forward-declarations parameter-list ;
2880 The uses of attributes shown above are GNU extensions.
2882 Some forms of array declarator are not included in C99 in the
2883 syntax for abstract declarators; these are disallowed elsewhere.
2884 This may be a defect (DR#289).
2886 This function also accepts an omitted abstract declarator as being
2887 an abstract declarator, although not part of the formal syntax. */
2889 static struct c_declarator
*
2890 c_parser_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
2893 /* Parse any initial pointer part. */
2894 if (c_parser_next_token_is (parser
, CPP_MULT
))
2896 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
2897 struct c_declarator
*inner
;
2898 c_parser_consume_token (parser
);
2899 c_parser_declspecs (parser
, quals_attrs
, false, false, true, cla_prefer_id
);
2900 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
2904 return make_pointer_declarator (quals_attrs
, inner
);
2906 /* Now we have a direct declarator, direct abstract declarator or
2907 nothing (which counts as a direct abstract declarator here). */
2908 return c_parser_direct_declarator (parser
, type_seen_p
, kind
, seen_id
);
2911 /* Parse a direct declarator or direct abstract declarator; arguments
2912 as c_parser_declarator. */
2914 static struct c_declarator
*
2915 c_parser_direct_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
2918 /* The direct declarator must start with an identifier (possibly
2919 omitted) or a parenthesized declarator (possibly abstract). In
2920 an ordinary declarator, initial parentheses must start a
2921 parenthesized declarator. In an abstract declarator or parameter
2922 declarator, they could start a parenthesized declarator or a
2923 parameter list. To tell which, the open parenthesis and any
2924 following attributes must be read. If a declaration specifier
2925 follows, then it is a parameter list; if the specifier is a
2926 typedef name, there might be an ambiguity about redeclaring it,
2927 which is resolved in the direction of treating it as a typedef
2928 name. If a close parenthesis follows, it is also an empty
2929 parameter list, as the syntax does not permit empty abstract
2930 declarators. Otherwise, it is a parenthesized declarator (in
2931 which case the analysis may be repeated inside it, recursively).
2933 ??? There is an ambiguity in a parameter declaration "int
2934 (__attribute__((foo)) x)", where x is not a typedef name: it
2935 could be an abstract declarator for a function, or declare x with
2936 parentheses. The proper resolution of this ambiguity needs
2937 documenting. At present we follow an accident of the old
2938 parser's implementation, whereby the first parameter must have
2939 some declaration specifiers other than just attributes. Thus as
2940 a parameter declaration it is treated as a parenthesized
2941 parameter named x, and as an abstract declarator it is
2944 ??? Also following the old parser, attributes inside an empty
2945 parameter list are ignored, making it a list not yielding a
2946 prototype, rather than giving an error or making it have one
2947 parameter with implicit type int.
2949 ??? Also following the old parser, typedef names may be
2950 redeclared in declarators, but not Objective-C class names. */
2952 if (kind
!= C_DTR_ABSTRACT
2953 && c_parser_next_token_is (parser
, CPP_NAME
)
2955 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
2956 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
2957 || c_parser_peek_token (parser
)->id_kind
== C_ID_ID
))
2959 struct c_declarator
*inner
2960 = build_id_declarator (c_parser_peek_token (parser
)->value
);
2962 inner
->id_loc
= c_parser_peek_token (parser
)->location
;
2963 c_parser_consume_token (parser
);
2964 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
2967 if (kind
!= C_DTR_NORMAL
2968 && c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
2970 struct c_declarator
*inner
= build_id_declarator (NULL_TREE
);
2971 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
2974 /* Either we are at the end of an abstract declarator, or we have
2977 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
2980 struct c_declarator
*inner
;
2981 c_parser_consume_token (parser
);
2982 attrs
= c_parser_attributes (parser
);
2983 if (kind
!= C_DTR_NORMAL
2984 && (c_parser_next_token_starts_declspecs (parser
)
2985 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
)))
2987 struct c_arg_info
*args
2988 = c_parser_parms_declarator (parser
, kind
== C_DTR_NORMAL
,
2995 = build_function_declarator (args
,
2996 build_id_declarator (NULL_TREE
));
2997 return c_parser_direct_declarator_inner (parser
, *seen_id
,
3001 /* A parenthesized declarator. */
3002 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
3003 if (inner
!= NULL
&& attrs
!= NULL
)
3004 inner
= build_attrs_declarator (attrs
, inner
);
3005 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3007 c_parser_consume_token (parser
);
3011 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3015 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3022 if (kind
== C_DTR_NORMAL
)
3024 c_parser_error (parser
, "expected identifier or %<(%>");
3028 return build_id_declarator (NULL_TREE
);
3032 /* Parse part of a direct declarator or direct abstract declarator,
3033 given that some (in INNER) has already been parsed; ID_PRESENT is
3034 true if an identifier is present, false for an abstract
3037 static struct c_declarator
*
3038 c_parser_direct_declarator_inner (c_parser
*parser
, bool id_present
,
3039 struct c_declarator
*inner
)
3041 /* Parse a sequence of array declarators and parameter lists. */
3042 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
3044 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
3045 struct c_declarator
*declarator
;
3046 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
3050 c_parser_consume_token (parser
);
3051 c_parser_declspecs (parser
, quals_attrs
, false, false, true, cla_prefer_id
);
3052 static_seen
= c_parser_next_token_is_keyword (parser
, RID_STATIC
);
3054 c_parser_consume_token (parser
);
3055 if (static_seen
&& !quals_attrs
->declspecs_seen_p
)
3056 c_parser_declspecs (parser
, quals_attrs
, false, false, true, cla_prefer_id
);
3057 if (!quals_attrs
->declspecs_seen_p
)
3059 /* If "static" is present, there must be an array dimension.
3060 Otherwise, there may be a dimension, "*", or no
3065 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
3069 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3074 else if (flag_enable_cilkplus
3075 && c_parser_next_token_is (parser
, CPP_COLON
))
3077 dimen
= error_mark_node
;
3079 error_at (c_parser_peek_token (parser
)->location
,
3080 "array notations cannot be used in declaration");
3081 c_parser_consume_token (parser
);
3083 else if (c_parser_next_token_is (parser
, CPP_MULT
))
3085 if (c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_SQUARE
)
3089 c_parser_consume_token (parser
);
3094 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
3100 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
3103 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3104 c_parser_consume_token (parser
);
3105 else if (flag_enable_cilkplus
3106 && c_parser_next_token_is (parser
, CPP_COLON
))
3108 error_at (c_parser_peek_token (parser
)->location
,
3109 "array notations cannot be used in declaration");
3110 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
3115 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3120 mark_exp_read (dimen
);
3121 declarator
= build_array_declarator (brace_loc
, dimen
, quals_attrs
,
3122 static_seen
, star_seen
);
3123 if (declarator
== NULL
)
3125 inner
= set_array_declarator_inner (declarator
, inner
);
3126 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3128 else if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3131 struct c_arg_info
*args
;
3132 c_parser_consume_token (parser
);
3133 attrs
= c_parser_attributes (parser
);
3134 args
= c_parser_parms_declarator (parser
, id_present
, attrs
);
3139 inner
= build_function_declarator (args
, inner
);
3140 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3146 /* Parse a parameter list or identifier list, including the closing
3147 parenthesis but not the opening one. ATTRS are the attributes at
3148 the start of the list. ID_LIST_OK is true if an identifier list is
3149 acceptable; such a list must not have attributes at the start. */
3151 static struct c_arg_info
*
3152 c_parser_parms_declarator (c_parser
*parser
, bool id_list_ok
, tree attrs
)
3155 declare_parm_level ();
3156 /* If the list starts with an identifier, it is an identifier list.
3157 Otherwise, it is either a prototype list or an empty list. */
3160 && c_parser_next_token_is (parser
, CPP_NAME
)
3161 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
3163 /* Look ahead to detect typos in type names. */
3164 && c_parser_peek_2nd_token (parser
)->type
!= CPP_NAME
3165 && c_parser_peek_2nd_token (parser
)->type
!= CPP_MULT
3166 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
3167 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_SQUARE
)
3169 tree list
= NULL_TREE
, *nextp
= &list
;
3170 while (c_parser_next_token_is (parser
, CPP_NAME
)
3171 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
3173 *nextp
= build_tree_list (NULL_TREE
,
3174 c_parser_peek_token (parser
)->value
);
3175 nextp
= & TREE_CHAIN (*nextp
);
3176 c_parser_consume_token (parser
);
3177 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
3179 c_parser_consume_token (parser
);
3180 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3182 c_parser_error (parser
, "expected identifier");
3186 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3188 struct c_arg_info
*ret
= build_arg_info ();
3190 c_parser_consume_token (parser
);
3196 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3204 struct c_arg_info
*ret
= c_parser_parms_list_declarator (parser
, attrs
,
3211 /* Parse a parameter list (possibly empty), including the closing
3212 parenthesis but not the opening one. ATTRS are the attributes at
3213 the start of the list. EXPR is NULL or an expression that needs to
3214 be evaluated for the side effects of array size expressions in the
3217 static struct c_arg_info
*
3218 c_parser_parms_list_declarator (c_parser
*parser
, tree attrs
, tree expr
)
3220 bool bad_parm
= false;
3222 /* ??? Following the old parser, forward parameter declarations may
3223 use abstract declarators, and if no real parameter declarations
3224 follow the forward declarations then this is not diagnosed. Also
3225 note as above that attributes are ignored as the only contents of
3226 the parentheses, or as the only contents after forward
3228 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3230 struct c_arg_info
*ret
= build_arg_info ();
3231 c_parser_consume_token (parser
);
3234 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3236 struct c_arg_info
*ret
= build_arg_info ();
3238 if (flag_allow_parameterless_variadic_functions
)
3240 /* F (...) is allowed. */
3241 ret
->types
= NULL_TREE
;
3245 /* Suppress -Wold-style-definition for this case. */
3246 ret
->types
= error_mark_node
;
3247 error_at (c_parser_peek_token (parser
)->location
,
3248 "ISO C requires a named argument before %<...%>");
3250 c_parser_consume_token (parser
);
3251 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3253 c_parser_consume_token (parser
);
3258 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3263 /* Nonempty list of parameters, either terminated with semicolon
3264 (forward declarations; recurse) or with close parenthesis (normal
3265 function) or with ", ... )" (variadic function). */
3268 /* Parse a parameter. */
3269 struct c_parm
*parm
= c_parser_parameter_declaration (parser
, attrs
);
3274 push_parm_decl (parm
, &expr
);
3275 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3278 c_parser_consume_token (parser
);
3279 mark_forward_parm_decls ();
3280 new_attrs
= c_parser_attributes (parser
);
3281 return c_parser_parms_list_declarator (parser
, new_attrs
, expr
);
3283 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3285 c_parser_consume_token (parser
);
3289 return get_parm_info (false, expr
);
3291 if (!c_parser_require (parser
, CPP_COMMA
,
3292 "expected %<;%>, %<,%> or %<)%>"))
3294 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3297 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3299 c_parser_consume_token (parser
);
3300 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3302 c_parser_consume_token (parser
);
3306 return get_parm_info (true, expr
);
3310 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3318 /* Parse a parameter declaration. ATTRS are the attributes at the
3319 start of the declaration if it is the first parameter. */
3321 static struct c_parm
*
3322 c_parser_parameter_declaration (c_parser
*parser
, tree attrs
)
3324 struct c_declspecs
*specs
;
3325 struct c_declarator
*declarator
;
3327 tree postfix_attrs
= NULL_TREE
;
3330 /* Accept #pragmas between parameter declarations. */
3331 while (c_parser_next_token_is (parser
, CPP_PRAGMA
))
3332 c_parser_pragma (parser
, pragma_external
);
3334 if (!c_parser_next_token_starts_declspecs (parser
))
3336 c_token
*token
= c_parser_peek_token (parser
);
3339 c_parser_set_source_position_from_token (token
);
3340 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
3342 error ("unknown type name %qE", token
->value
);
3343 parser
->error
= true;
3345 /* ??? In some Objective-C cases '...' isn't applicable so there
3346 should be a different message. */
3348 c_parser_error (parser
,
3349 "expected declaration specifiers or %<...%>");
3350 c_parser_skip_to_end_of_parameter (parser
);
3353 specs
= build_null_declspecs ();
3356 declspecs_add_attrs (input_location
, specs
, attrs
);
3359 c_parser_declspecs (parser
, specs
, true, true, true, cla_nonabstract_decl
);
3360 finish_declspecs (specs
);
3361 pending_xref_error ();
3362 prefix_attrs
= specs
->attrs
;
3363 specs
->attrs
= NULL_TREE
;
3364 declarator
= c_parser_declarator (parser
,
3365 specs
->typespec_kind
!= ctsk_none
,
3366 C_DTR_PARM
, &dummy
);
3367 if (declarator
== NULL
)
3369 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3372 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3373 postfix_attrs
= c_parser_attributes (parser
);
3374 return build_c_parm (specs
, chainon (postfix_attrs
, prefix_attrs
),
3378 /* Parse a string literal in an asm expression. It should not be
3379 translated, and wide string literals are an error although
3380 permitted by the syntax. This is a GNU extension.
3385 ??? At present, following the old parser, the caller needs to have
3386 set lex_untranslated_string to 1. It would be better to follow the
3387 C++ parser rather than using this kludge. */
3390 c_parser_asm_string_literal (c_parser
*parser
)
3393 int save_flag
= warn_overlength_strings
;
3394 warn_overlength_strings
= 0;
3395 if (c_parser_next_token_is (parser
, CPP_STRING
))
3397 str
= c_parser_peek_token (parser
)->value
;
3398 c_parser_consume_token (parser
);
3400 else if (c_parser_next_token_is (parser
, CPP_WSTRING
))
3402 error_at (c_parser_peek_token (parser
)->location
,
3403 "wide string literal in %<asm%>");
3404 str
= build_string (1, "");
3405 c_parser_consume_token (parser
);
3409 c_parser_error (parser
, "expected string literal");
3412 warn_overlength_strings
= save_flag
;
3416 /* Parse a simple asm expression. This is used in restricted
3417 contexts, where a full expression with inputs and outputs does not
3418 make sense. This is a GNU extension.
3421 asm ( asm-string-literal )
3425 c_parser_simple_asm_expr (c_parser
*parser
)
3428 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
3429 /* ??? Follow the C++ parser rather than using the
3430 lex_untranslated_string kludge. */
3431 parser
->lex_untranslated_string
= true;
3432 c_parser_consume_token (parser
);
3433 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3435 parser
->lex_untranslated_string
= false;
3438 str
= c_parser_asm_string_literal (parser
);
3439 parser
->lex_untranslated_string
= false;
3440 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
3442 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3449 c_parser_attribute_any_word (c_parser
*parser
)
3451 tree attr_name
= NULL_TREE
;
3453 if (c_parser_next_token_is (parser
, CPP_KEYWORD
))
3455 /* ??? See comment above about what keywords are accepted here. */
3457 switch (c_parser_peek_token (parser
)->keyword
)
3488 case RID_TRANSACTION_ATOMIC
:
3489 case RID_TRANSACTION_CANCEL
:
3499 /* Accept __attribute__((__const)) as __attribute__((const)) etc. */
3500 attr_name
= ridpointers
[(int) c_parser_peek_token (parser
)->keyword
];
3502 else if (c_parser_next_token_is (parser
, CPP_NAME
))
3503 attr_name
= c_parser_peek_token (parser
)->value
;
3508 /* Parse (possibly empty) attributes. This is a GNU extension.
3512 attributes attribute
3515 __attribute__ ( ( attribute-list ) )
3519 attribute_list , attrib
3524 any-word ( identifier )
3525 any-word ( identifier , nonempty-expr-list )
3526 any-word ( expr-list )
3528 where the "identifier" must not be declared as a type, and
3529 "any-word" may be any identifier (including one declared as a
3530 type), a reserved word storage class specifier, type specifier or
3531 type qualifier. ??? This still leaves out most reserved keywords
3532 (following the old parser), shouldn't we include them, and why not
3533 allow identifiers declared as types to start the arguments? */
3536 c_parser_attributes (c_parser
*parser
)
3538 tree attrs
= NULL_TREE
;
3539 while (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3541 /* ??? Follow the C++ parser rather than using the
3542 lex_untranslated_string kludge. */
3543 parser
->lex_untranslated_string
= true;
3544 c_parser_consume_token (parser
);
3545 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3547 parser
->lex_untranslated_string
= false;
3550 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3552 parser
->lex_untranslated_string
= false;
3553 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3556 /* Parse the attribute list. */
3557 while (c_parser_next_token_is (parser
, CPP_COMMA
)
3558 || c_parser_next_token_is (parser
, CPP_NAME
)
3559 || c_parser_next_token_is (parser
, CPP_KEYWORD
))
3561 tree attr
, attr_name
, attr_args
;
3562 vec
<tree
, va_gc
> *expr_list
;
3563 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3565 c_parser_consume_token (parser
);
3569 attr_name
= c_parser_attribute_any_word (parser
);
3570 if (attr_name
== NULL
)
3572 c_parser_consume_token (parser
);
3573 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
3575 attr
= build_tree_list (attr_name
, NULL_TREE
);
3576 attrs
= chainon (attrs
, attr
);
3579 c_parser_consume_token (parser
);
3580 /* Parse the attribute contents. If they start with an
3581 identifier which is followed by a comma or close
3582 parenthesis, then the arguments start with that
3583 identifier; otherwise they are an expression list.
3584 In objective-c the identifier may be a classname. */
3585 if (c_parser_next_token_is (parser
, CPP_NAME
)
3586 && (c_parser_peek_token (parser
)->id_kind
== C_ID_ID
3587 || (c_dialect_objc ()
3588 && c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
3589 && ((c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
)
3590 || (c_parser_peek_2nd_token (parser
)->type
3591 == CPP_CLOSE_PAREN
)))
3593 tree arg1
= c_parser_peek_token (parser
)->value
;
3594 c_parser_consume_token (parser
);
3595 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3596 attr_args
= build_tree_list (NULL_TREE
, arg1
);
3600 c_parser_consume_token (parser
);
3601 expr_list
= c_parser_expr_list (parser
, false, true,
3603 tree_list
= build_tree_list_vec (expr_list
);
3604 attr_args
= tree_cons (NULL_TREE
, arg1
, tree_list
);
3605 release_tree_vector (expr_list
);
3610 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3611 attr_args
= NULL_TREE
;
3614 expr_list
= c_parser_expr_list (parser
, false, true,
3616 attr_args
= build_tree_list_vec (expr_list
);
3617 release_tree_vector (expr_list
);
3620 attr
= build_tree_list (attr_name
, attr_args
);
3621 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3622 c_parser_consume_token (parser
);
3625 parser
->lex_untranslated_string
= false;
3626 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3630 attrs
= chainon (attrs
, attr
);
3632 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3633 c_parser_consume_token (parser
);
3636 parser
->lex_untranslated_string
= false;
3637 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3641 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3642 c_parser_consume_token (parser
);
3645 parser
->lex_untranslated_string
= false;
3646 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3650 parser
->lex_untranslated_string
= false;
3655 /* Parse a type name (C90 6.5.5, C99 6.7.6).
3658 specifier-qualifier-list abstract-declarator[opt]
3661 static struct c_type_name
*
3662 c_parser_type_name (c_parser
*parser
)
3664 struct c_declspecs
*specs
= build_null_declspecs ();
3665 struct c_declarator
*declarator
;
3666 struct c_type_name
*ret
;
3668 c_parser_declspecs (parser
, specs
, false, true, true, cla_prefer_type
);
3669 if (!specs
->declspecs_seen_p
)
3671 c_parser_error (parser
, "expected specifier-qualifier-list");
3674 if (specs
->type
!= error_mark_node
)
3676 pending_xref_error ();
3677 finish_declspecs (specs
);
3679 declarator
= c_parser_declarator (parser
,
3680 specs
->typespec_kind
!= ctsk_none
,
3681 C_DTR_ABSTRACT
, &dummy
);
3682 if (declarator
== NULL
)
3684 ret
= XOBNEW (&parser_obstack
, struct c_type_name
);
3686 ret
->declarator
= declarator
;
3690 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
3693 assignment-expression
3694 { initializer-list }
3695 { initializer-list , }
3698 designation[opt] initializer
3699 initializer-list , designation[opt] initializer
3706 designator-list designator
3713 [ constant-expression ]
3725 [ constant-expression ... constant-expression ]
3727 Any expression without commas is accepted in the syntax for the
3728 constant-expressions, with non-constant expressions rejected later.
3730 This function is only used for top-level initializers; for nested
3731 ones, see c_parser_initval. */
3733 static struct c_expr
3734 c_parser_initializer (c_parser
*parser
)
3736 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
3737 return c_parser_braced_init (parser
, NULL_TREE
, false);
3741 location_t loc
= c_parser_peek_token (parser
)->location
;
3742 ret
= c_parser_expr_no_commas (parser
, NULL
);
3743 if (TREE_CODE (ret
.value
) != STRING_CST
3744 && TREE_CODE (ret
.value
) != COMPOUND_LITERAL_EXPR
)
3745 ret
= default_function_array_read_conversion (loc
, ret
);
3750 /* Parse a braced initializer list. TYPE is the type specified for a
3751 compound literal, and NULL_TREE for other initializers and for
3752 nested braced lists. NESTED_P is true for nested braced lists,
3753 false for the list of a compound literal or the list that is the
3754 top-level initializer in a declaration. */
3756 static struct c_expr
3757 c_parser_braced_init (c_parser
*parser
, tree type
, bool nested_p
)
3760 struct obstack braced_init_obstack
;
3761 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
3762 gcc_obstack_init (&braced_init_obstack
);
3763 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
3764 c_parser_consume_token (parser
);
3766 push_init_level (0, &braced_init_obstack
);
3768 really_start_incremental_init (type
);
3769 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3771 pedwarn (brace_loc
, OPT_Wpedantic
, "ISO C forbids empty initializer braces");
3775 /* Parse a non-empty initializer list, possibly with a trailing
3779 c_parser_initelt (parser
, &braced_init_obstack
);
3782 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3783 c_parser_consume_token (parser
);
3786 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3790 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
3792 ret
.value
= error_mark_node
;
3793 ret
.original_code
= ERROR_MARK
;
3794 ret
.original_type
= NULL
;
3795 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
3796 pop_init_level (0, &braced_init_obstack
);
3797 obstack_free (&braced_init_obstack
, NULL
);
3800 c_parser_consume_token (parser
);
3801 ret
= pop_init_level (0, &braced_init_obstack
);
3802 obstack_free (&braced_init_obstack
, NULL
);
3806 /* Parse a nested initializer, including designators. */
3809 c_parser_initelt (c_parser
*parser
, struct obstack
* braced_init_obstack
)
3811 /* Parse any designator or designator list. A single array
3812 designator may have the subsequent "=" omitted in GNU C, but a
3813 longer list or a structure member designator may not. */
3814 if (c_parser_next_token_is (parser
, CPP_NAME
)
3815 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
3817 /* Old-style structure member designator. */
3818 set_init_label (c_parser_peek_token (parser
)->value
,
3819 braced_init_obstack
);
3820 /* Use the colon as the error location. */
3821 pedwarn (c_parser_peek_2nd_token (parser
)->location
, OPT_Wpedantic
,
3822 "obsolete use of designated initializer with %<:%>");
3823 c_parser_consume_token (parser
);
3824 c_parser_consume_token (parser
);
3828 /* des_seen is 0 if there have been no designators, 1 if there
3829 has been a single array designator and 2 otherwise. */
3831 /* Location of a designator. */
3832 location_t des_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
3833 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
)
3834 || c_parser_next_token_is (parser
, CPP_DOT
))
3836 int des_prev
= des_seen
;
3838 des_loc
= c_parser_peek_token (parser
)->location
;
3841 if (c_parser_next_token_is (parser
, CPP_DOT
))
3844 c_parser_consume_token (parser
);
3845 if (c_parser_next_token_is (parser
, CPP_NAME
))
3847 set_init_label (c_parser_peek_token (parser
)->value
,
3848 braced_init_obstack
);
3849 c_parser_consume_token (parser
);
3854 init
.value
= error_mark_node
;
3855 init
.original_code
= ERROR_MARK
;
3856 init
.original_type
= NULL
;
3857 c_parser_error (parser
, "expected identifier");
3858 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3859 process_init_element (init
, false, braced_init_obstack
);
3866 location_t ellipsis_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
3867 /* ??? Following the old parser, [ objc-receiver
3868 objc-message-args ] is accepted as an initializer,
3869 being distinguished from a designator by what follows
3870 the first assignment expression inside the square
3871 brackets, but after a first array designator a
3872 subsequent square bracket is for Objective-C taken to
3873 start an expression, using the obsolete form of
3874 designated initializer without '=', rather than
3875 possibly being a second level of designation: in LALR
3876 terms, the '[' is shifted rather than reducing
3877 designator to designator-list. */
3878 if (des_prev
== 1 && c_dialect_objc ())
3880 des_seen
= des_prev
;
3883 if (des_prev
== 0 && c_dialect_objc ())
3885 /* This might be an array designator or an
3886 Objective-C message expression. If the former,
3887 continue parsing here; if the latter, parse the
3888 remainder of the initializer given the starting
3889 primary-expression. ??? It might make sense to
3890 distinguish when des_prev == 1 as well; see
3891 previous comment. */
3893 struct c_expr mexpr
;
3894 c_parser_consume_token (parser
);
3895 if (c_parser_peek_token (parser
)->type
== CPP_NAME
3896 && ((c_parser_peek_token (parser
)->id_kind
3898 || (c_parser_peek_token (parser
)->id_kind
3899 == C_ID_CLASSNAME
)))
3901 /* Type name receiver. */
3902 tree id
= c_parser_peek_token (parser
)->value
;
3903 c_parser_consume_token (parser
);
3904 rec
= objc_get_class_reference (id
);
3905 goto parse_message_args
;
3907 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
3908 mark_exp_read (first
);
3909 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
)
3910 || c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3911 goto array_desig_after_first
;
3912 /* Expression receiver. So far only one part
3913 without commas has been parsed; there might be
3914 more of the expression. */
3916 while (c_parser_next_token_is (parser
, CPP_COMMA
))
3919 location_t comma_loc
, exp_loc
;
3920 comma_loc
= c_parser_peek_token (parser
)->location
;
3921 c_parser_consume_token (parser
);
3922 exp_loc
= c_parser_peek_token (parser
)->location
;
3923 next
= c_parser_expr_no_commas (parser
, NULL
);
3924 next
= default_function_array_read_conversion (exp_loc
,
3926 rec
= build_compound_expr (comma_loc
, rec
, next
.value
);
3929 /* Now parse the objc-message-args. */
3930 args
= c_parser_objc_message_args (parser
);
3931 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3934 = objc_build_message_expr (rec
, args
);
3935 mexpr
.original_code
= ERROR_MARK
;
3936 mexpr
.original_type
= NULL
;
3937 /* Now parse and process the remainder of the
3938 initializer, starting with this message
3939 expression as a primary-expression. */
3940 c_parser_initval (parser
, &mexpr
, braced_init_obstack
);
3943 c_parser_consume_token (parser
);
3944 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
3945 mark_exp_read (first
);
3946 array_desig_after_first
:
3947 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3949 ellipsis_loc
= c_parser_peek_token (parser
)->location
;
3950 c_parser_consume_token (parser
);
3951 second
= c_parser_expr_no_commas (parser
, NULL
).value
;
3952 mark_exp_read (second
);
3956 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3958 c_parser_consume_token (parser
);
3959 set_init_index (first
, second
, braced_init_obstack
);
3961 pedwarn (ellipsis_loc
, OPT_Wpedantic
,
3962 "ISO C forbids specifying range of elements to initialize");
3965 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3971 if (c_parser_next_token_is (parser
, CPP_EQ
))
3974 pedwarn (des_loc
, OPT_Wpedantic
,
3975 "ISO C90 forbids specifying subobject to initialize");
3976 c_parser_consume_token (parser
);
3981 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
3982 "obsolete use of designated initializer without %<=%>");
3986 init
.value
= error_mark_node
;
3987 init
.original_code
= ERROR_MARK
;
3988 init
.original_type
= NULL
;
3989 c_parser_error (parser
, "expected %<=%>");
3990 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3991 process_init_element (init
, false, braced_init_obstack
);
3997 c_parser_initval (parser
, NULL
, braced_init_obstack
);
4000 /* Parse a nested initializer; as c_parser_initializer but parses
4001 initializers within braced lists, after any designators have been
4002 applied. If AFTER is not NULL then it is an Objective-C message
4003 expression which is the primary-expression starting the
4007 c_parser_initval (c_parser
*parser
, struct c_expr
*after
,
4008 struct obstack
* braced_init_obstack
)
4011 gcc_assert (!after
|| c_dialect_objc ());
4012 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
) && !after
)
4013 init
= c_parser_braced_init (parser
, NULL_TREE
, true);
4016 location_t loc
= c_parser_peek_token (parser
)->location
;
4017 init
= c_parser_expr_no_commas (parser
, after
);
4018 if (init
.value
!= NULL_TREE
4019 && TREE_CODE (init
.value
) != STRING_CST
4020 && TREE_CODE (init
.value
) != COMPOUND_LITERAL_EXPR
)
4021 init
= default_function_array_read_conversion (loc
, init
);
4023 process_init_element (init
, false, braced_init_obstack
);
4026 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
4030 { block-item-list[opt] }
4031 { label-declarations block-item-list }
4035 block-item-list block-item
4047 { label-declarations block-item-list }
4050 __extension__ nested-declaration
4051 nested-function-definition
4055 label-declarations label-declaration
4058 __label__ identifier-list ;
4060 Allowing the mixing of declarations and code is new in C99. The
4061 GNU syntax also permits (not shown above) labels at the end of
4062 compound statements, which yield an error. We don't allow labels
4063 on declarations; this might seem like a natural extension, but
4064 there would be a conflict between attributes on the label and
4065 prefix attributes on the declaration. ??? The syntax follows the
4066 old parser in requiring something after label declarations.
4067 Although they are erroneous if the labels declared aren't defined,
4068 is it useful for the syntax to be this way?
4080 c_parser_compound_statement (c_parser
*parser
)
4083 location_t brace_loc
;
4084 brace_loc
= c_parser_peek_token (parser
)->location
;
4085 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
4087 /* Ensure a scope is entered and left anyway to avoid confusion
4088 if we have just prepared to enter a function body. */
4089 stmt
= c_begin_compound_stmt (true);
4090 c_end_compound_stmt (brace_loc
, stmt
, true);
4091 return error_mark_node
;
4093 stmt
= c_begin_compound_stmt (true);
4094 c_parser_compound_statement_nostart (parser
);
4096 /* If the compound stmt contains array notations, then we expand them. */
4097 if (flag_enable_cilkplus
&& contains_array_notation_expr (stmt
))
4098 stmt
= expand_array_notation_exprs (stmt
);
4099 return c_end_compound_stmt (brace_loc
, stmt
, true);
4102 /* Parse a compound statement except for the opening brace. This is
4103 used for parsing both compound statements and statement expressions
4104 (which follow different paths to handling the opening). */
4107 c_parser_compound_statement_nostart (c_parser
*parser
)
4109 bool last_stmt
= false;
4110 bool last_label
= false;
4111 bool save_valid_for_pragma
= valid_location_for_stdc_pragma_p ();
4112 location_t label_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4113 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4115 c_parser_consume_token (parser
);
4118 mark_valid_location_for_stdc_pragma (true);
4119 if (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
4121 /* Read zero or more forward-declarations for labels that nested
4122 functions can jump to. */
4123 mark_valid_location_for_stdc_pragma (false);
4124 while (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
4126 label_loc
= c_parser_peek_token (parser
)->location
;
4127 c_parser_consume_token (parser
);
4128 /* Any identifiers, including those declared as type names,
4133 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
4135 c_parser_error (parser
, "expected identifier");
4139 = declare_label (c_parser_peek_token (parser
)->value
);
4140 C_DECLARED_LABEL_FLAG (label
) = 1;
4141 add_stmt (build_stmt (label_loc
, DECL_EXPR
, label
));
4142 c_parser_consume_token (parser
);
4143 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4144 c_parser_consume_token (parser
);
4148 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4150 pedwarn (label_loc
, OPT_Wpedantic
, "ISO C forbids label declarations");
4152 /* We must now have at least one statement, label or declaration. */
4153 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4155 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4156 c_parser_error (parser
, "expected declaration or statement");
4157 c_parser_consume_token (parser
);
4160 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
4162 location_t loc
= c_parser_peek_token (parser
)->location
;
4163 if (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4164 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4165 || (c_parser_next_token_is (parser
, CPP_NAME
)
4166 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4168 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
4169 label_loc
= c_parser_peek_2nd_token (parser
)->location
;
4171 label_loc
= c_parser_peek_token (parser
)->location
;
4174 mark_valid_location_for_stdc_pragma (false);
4175 c_parser_label (parser
);
4177 else if (!last_label
4178 && c_parser_next_tokens_start_declaration (parser
))
4181 mark_valid_location_for_stdc_pragma (false);
4182 c_parser_declaration_or_fndef (parser
, true, true, true, true, true, NULL
);
4185 (pedantic
&& !flag_isoc99
)
4187 : OPT_Wdeclaration_after_statement
,
4188 "ISO C90 forbids mixed declarations and code");
4191 else if (!last_label
4192 && c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
4194 /* __extension__ can start a declaration, but is also an
4195 unary operator that can start an expression. Consume all
4196 but the last of a possible series of __extension__ to
4198 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
4199 && (c_parser_peek_2nd_token (parser
)->keyword
4201 c_parser_consume_token (parser
);
4202 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
4205 ext
= disable_extension_diagnostics ();
4206 c_parser_consume_token (parser
);
4208 mark_valid_location_for_stdc_pragma (false);
4209 c_parser_declaration_or_fndef (parser
, true, true, true, true,
4211 /* Following the old parser, __extension__ does not
4212 disable this diagnostic. */
4213 restore_extension_diagnostics (ext
);
4215 pedwarn_c90 (loc
, (pedantic
&& !flag_isoc99
)
4217 : OPT_Wdeclaration_after_statement
,
4218 "ISO C90 forbids mixed declarations and code");
4224 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
4226 /* External pragmas, and some omp pragmas, are not associated
4227 with regular c code, and so are not to be considered statements
4228 syntactically. This ensures that the user doesn't put them
4229 places that would turn into syntax errors if the directive
4231 if (c_parser_pragma (parser
, pragma_compound
))
4232 last_label
= false, last_stmt
= true;
4234 else if (c_parser_next_token_is (parser
, CPP_EOF
))
4236 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4237 c_parser_error (parser
, "expected declaration or statement");
4240 else if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
4242 if (parser
->in_if_block
)
4244 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4245 error_at (loc
, """expected %<}%> before %<else%>");
4250 error_at (loc
, "%<else%> without a previous %<if%>");
4251 c_parser_consume_token (parser
);
4260 mark_valid_location_for_stdc_pragma (false);
4261 c_parser_statement_after_labels (parser
);
4264 parser
->error
= false;
4267 error_at (label_loc
, "label at end of compound statement");
4268 c_parser_consume_token (parser
);
4269 /* Restore the value we started with. */
4270 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4273 /* Parse a label (C90 6.6.1, C99 6.8.1).
4276 identifier : attributes[opt]
4277 case constant-expression :
4283 case constant-expression ... constant-expression :
4285 The use of attributes on labels is a GNU extension. The syntax in
4286 GNU C accepts any expressions without commas, non-constant
4287 expressions being rejected later. */
4290 c_parser_label (c_parser
*parser
)
4292 location_t loc1
= c_parser_peek_token (parser
)->location
;
4293 tree label
= NULL_TREE
;
4294 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
4297 c_parser_consume_token (parser
);
4298 exp1
= c_parser_expr_no_commas (parser
, NULL
).value
;
4299 if (c_parser_next_token_is (parser
, CPP_COLON
))
4301 c_parser_consume_token (parser
);
4302 label
= do_case (loc1
, exp1
, NULL_TREE
);
4304 else if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
4306 c_parser_consume_token (parser
);
4307 exp2
= c_parser_expr_no_commas (parser
, NULL
).value
;
4308 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4309 label
= do_case (loc1
, exp1
, exp2
);
4312 c_parser_error (parser
, "expected %<:%> or %<...%>");
4314 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
4316 c_parser_consume_token (parser
);
4317 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4318 label
= do_case (loc1
, NULL_TREE
, NULL_TREE
);
4322 tree name
= c_parser_peek_token (parser
)->value
;
4325 location_t loc2
= c_parser_peek_token (parser
)->location
;
4326 gcc_assert (c_parser_next_token_is (parser
, CPP_NAME
));
4327 c_parser_consume_token (parser
);
4328 gcc_assert (c_parser_next_token_is (parser
, CPP_COLON
));
4329 c_parser_consume_token (parser
);
4330 attrs
= c_parser_attributes (parser
);
4331 tlab
= define_label (loc2
, name
);
4334 decl_attributes (&tlab
, attrs
, 0);
4335 label
= add_stmt (build_stmt (loc1
, LABEL_EXPR
, tlab
));
4340 if (c_parser_next_tokens_start_declaration (parser
))
4342 error_at (c_parser_peek_token (parser
)->location
,
4343 "a label can only be part of a statement and "
4344 "a declaration is not a statement");
4345 c_parser_declaration_or_fndef (parser
, /*fndef_ok*/ false,
4346 /*static_assert_ok*/ true,
4347 /*empty_ok*/ true, /*nested*/ true,
4348 /*start_attr_ok*/ true, NULL
);
4353 /* Parse a statement (C90 6.6, C99 6.8).
4358 expression-statement
4366 expression-statement:
4369 selection-statement:
4373 iteration-statement:
4382 return expression[opt] ;
4395 objc-throw-statement
4396 objc-try-catch-statement
4397 objc-synchronized-statement
4399 objc-throw-statement:
4413 parallel-for-construct
4414 parallel-sections-construct
4421 parallel-directive structured-block
4424 for-directive iteration-statement
4427 sections-directive section-scope
4430 single-directive structured-block
4432 parallel-for-construct:
4433 parallel-for-directive iteration-statement
4435 parallel-sections-construct:
4436 parallel-sections-directive section-scope
4439 master-directive structured-block
4442 critical-directive structured-block
4445 atomic-directive expression-statement
4448 ordered-directive structured-block
4450 Transactional Memory:
4453 transaction-statement
4454 transaction-cancel-statement
4458 c_parser_statement (c_parser
*parser
)
4460 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4461 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4462 || (c_parser_next_token_is (parser
, CPP_NAME
)
4463 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4464 c_parser_label (parser
);
4465 c_parser_statement_after_labels (parser
);
4468 /* Parse a statement, other than a labeled statement. */
4471 c_parser_statement_after_labels (c_parser
*parser
)
4473 location_t loc
= c_parser_peek_token (parser
)->location
;
4474 tree stmt
= NULL_TREE
;
4475 bool in_if_block
= parser
->in_if_block
;
4476 parser
->in_if_block
= false;
4477 switch (c_parser_peek_token (parser
)->type
)
4479 case CPP_OPEN_BRACE
:
4480 add_stmt (c_parser_compound_statement (parser
));
4483 switch (c_parser_peek_token (parser
)->keyword
)
4486 c_parser_if_statement (parser
);
4489 c_parser_switch_statement (parser
);
4492 c_parser_while_statement (parser
);
4495 c_parser_do_statement (parser
);
4498 c_parser_for_statement (parser
);
4501 c_parser_consume_token (parser
);
4502 if (c_parser_next_token_is (parser
, CPP_NAME
))
4504 stmt
= c_finish_goto_label (loc
,
4505 c_parser_peek_token (parser
)->value
);
4506 c_parser_consume_token (parser
);
4508 else if (c_parser_next_token_is (parser
, CPP_MULT
))
4512 c_parser_consume_token (parser
);
4513 val
= c_parser_expression (parser
).value
;
4514 mark_exp_read (val
);
4515 stmt
= c_finish_goto_ptr (loc
, val
);
4518 c_parser_error (parser
, "expected identifier or %<*%>");
4519 goto expect_semicolon
;
4521 c_parser_consume_token (parser
);
4522 stmt
= c_finish_bc_stmt (loc
, &c_cont_label
, false);
4523 goto expect_semicolon
;
4525 c_parser_consume_token (parser
);
4526 stmt
= c_finish_bc_stmt (loc
, &c_break_label
, true);
4527 goto expect_semicolon
;
4529 c_parser_consume_token (parser
);
4530 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4532 stmt
= c_finish_return (loc
, NULL_TREE
, NULL_TREE
);
4533 c_parser_consume_token (parser
);
4537 struct c_expr expr
= c_parser_expression_conv (parser
);
4538 mark_exp_read (expr
.value
);
4539 stmt
= c_finish_return (loc
, expr
.value
, expr
.original_type
);
4540 goto expect_semicolon
;
4544 stmt
= c_parser_asm_statement (parser
);
4546 case RID_TRANSACTION_ATOMIC
:
4547 case RID_TRANSACTION_RELAXED
:
4548 stmt
= c_parser_transaction (parser
,
4549 c_parser_peek_token (parser
)->keyword
);
4551 case RID_TRANSACTION_CANCEL
:
4552 stmt
= c_parser_transaction_cancel (parser
);
4553 goto expect_semicolon
;
4555 gcc_assert (c_dialect_objc ());
4556 c_parser_consume_token (parser
);
4557 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4559 stmt
= objc_build_throw_stmt (loc
, NULL_TREE
);
4560 c_parser_consume_token (parser
);
4564 tree expr
= c_parser_expression (parser
).value
;
4565 expr
= c_fully_fold (expr
, false, NULL
);
4566 stmt
= objc_build_throw_stmt (loc
, expr
);
4567 goto expect_semicolon
;
4571 gcc_assert (c_dialect_objc ());
4572 c_parser_objc_try_catch_finally_statement (parser
);
4574 case RID_AT_SYNCHRONIZED
:
4575 gcc_assert (c_dialect_objc ());
4576 c_parser_objc_synchronized_statement (parser
);
4583 c_parser_consume_token (parser
);
4585 case CPP_CLOSE_PAREN
:
4586 case CPP_CLOSE_SQUARE
:
4587 /* Avoid infinite loop in error recovery:
4588 c_parser_skip_until_found stops at a closing nesting
4589 delimiter without consuming it, but here we need to consume
4590 it to proceed further. */
4591 c_parser_error (parser
, "expected statement");
4592 c_parser_consume_token (parser
);
4595 c_parser_pragma (parser
, pragma_stmt
);
4599 stmt
= c_finish_expr_stmt (loc
, c_parser_expression_conv (parser
).value
);
4601 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4604 /* Two cases cannot and do not have line numbers associated: If stmt
4605 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
4606 cannot hold line numbers. But that's OK because the statement
4607 will either be changed to a MODIFY_EXPR during gimplification of
4608 the statement expr, or discarded. If stmt was compound, but
4609 without new variables, we will have skipped the creation of a
4610 BIND and will have a bare STATEMENT_LIST. But that's OK because
4611 (recursively) all of the component statements should already have
4612 line numbers assigned. ??? Can we discard no-op statements
4614 if (CAN_HAVE_LOCATION_P (stmt
)
4615 && EXPR_LOCATION (stmt
) == UNKNOWN_LOCATION
)
4616 SET_EXPR_LOCATION (stmt
, loc
);
4618 parser
->in_if_block
= in_if_block
;
4621 /* Parse the condition from an if, do, while or for statements. */
4624 c_parser_condition (c_parser
*parser
)
4626 location_t loc
= c_parser_peek_token (parser
)->location
;
4628 cond
= c_parser_expression_conv (parser
).value
;
4629 cond
= c_objc_common_truthvalue_conversion (loc
, cond
);
4630 cond
= c_fully_fold (cond
, false, NULL
);
4631 if (warn_sequence_point
)
4632 verify_sequence_points (cond
);
4636 /* Parse a parenthesized condition from an if, do or while statement.
4642 c_parser_paren_condition (c_parser
*parser
)
4645 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4646 return error_mark_node
;
4647 cond
= c_parser_condition (parser
);
4648 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4652 /* Parse a statement which is a block in C99. */
4655 c_parser_c99_block_statement (c_parser
*parser
)
4657 tree block
= c_begin_compound_stmt (flag_isoc99
);
4658 location_t loc
= c_parser_peek_token (parser
)->location
;
4659 c_parser_statement (parser
);
4660 return c_end_compound_stmt (loc
, block
, flag_isoc99
);
4663 /* Parse the body of an if statement. This is just parsing a
4664 statement but (a) it is a block in C99, (b) we track whether the
4665 body is an if statement for the sake of -Wparentheses warnings, (c)
4666 we handle an empty body specially for the sake of -Wempty-body
4667 warnings, and (d) we call parser_compound_statement directly
4668 because c_parser_statement_after_labels resets
4669 parser->in_if_block. */
4672 c_parser_if_body (c_parser
*parser
, bool *if_p
)
4674 tree block
= c_begin_compound_stmt (flag_isoc99
);
4675 location_t body_loc
= c_parser_peek_token (parser
)->location
;
4676 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4677 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4678 || (c_parser_next_token_is (parser
, CPP_NAME
)
4679 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4680 c_parser_label (parser
);
4681 *if_p
= c_parser_next_token_is_keyword (parser
, RID_IF
);
4682 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4684 location_t loc
= c_parser_peek_token (parser
)->location
;
4685 add_stmt (build_empty_stmt (loc
));
4686 c_parser_consume_token (parser
);
4687 if (!c_parser_next_token_is_keyword (parser
, RID_ELSE
))
4688 warning_at (loc
, OPT_Wempty_body
,
4689 "suggest braces around empty body in an %<if%> statement");
4691 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4692 add_stmt (c_parser_compound_statement (parser
));
4694 c_parser_statement_after_labels (parser
);
4695 return c_end_compound_stmt (body_loc
, block
, flag_isoc99
);
4698 /* Parse the else body of an if statement. This is just parsing a
4699 statement but (a) it is a block in C99, (b) we handle an empty body
4700 specially for the sake of -Wempty-body warnings. */
4703 c_parser_else_body (c_parser
*parser
)
4705 location_t else_loc
= c_parser_peek_token (parser
)->location
;
4706 tree block
= c_begin_compound_stmt (flag_isoc99
);
4707 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4708 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4709 || (c_parser_next_token_is (parser
, CPP_NAME
)
4710 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4711 c_parser_label (parser
);
4712 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4714 location_t loc
= c_parser_peek_token (parser
)->location
;
4717 "suggest braces around empty body in an %<else%> statement");
4718 add_stmt (build_empty_stmt (loc
));
4719 c_parser_consume_token (parser
);
4722 c_parser_statement_after_labels (parser
);
4723 return c_end_compound_stmt (else_loc
, block
, flag_isoc99
);
4726 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
4729 if ( expression ) statement
4730 if ( expression ) statement else statement
4734 c_parser_if_statement (c_parser
*parser
)
4739 bool first_if
= false;
4740 tree first_body
, second_body
;
4744 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_IF
));
4745 c_parser_consume_token (parser
);
4746 block
= c_begin_compound_stmt (flag_isoc99
);
4747 loc
= c_parser_peek_token (parser
)->location
;
4748 cond
= c_parser_paren_condition (parser
);
4749 in_if_block
= parser
->in_if_block
;
4750 parser
->in_if_block
= true;
4751 first_body
= c_parser_if_body (parser
, &first_if
);
4752 parser
->in_if_block
= in_if_block
;
4753 if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
4755 c_parser_consume_token (parser
);
4756 second_body
= c_parser_else_body (parser
);
4759 second_body
= NULL_TREE
;
4760 c_finish_if_stmt (loc
, cond
, first_body
, second_body
, first_if
);
4761 if_stmt
= c_end_compound_stmt (loc
, block
, flag_isoc99
);
4763 /* If the if statement contains array notations, then we expand them. */
4764 if (flag_enable_cilkplus
&& contains_array_notation_expr (if_stmt
))
4765 if_stmt
= fix_conditional_array_notations (if_stmt
);
4769 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
4772 switch (expression) statement
4776 c_parser_switch_statement (c_parser
*parser
)
4778 tree block
, expr
, body
, save_break
;
4779 location_t switch_loc
= c_parser_peek_token (parser
)->location
;
4780 location_t switch_cond_loc
;
4781 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SWITCH
));
4782 c_parser_consume_token (parser
);
4783 block
= c_begin_compound_stmt (flag_isoc99
);
4784 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4786 switch_cond_loc
= c_parser_peek_token (parser
)->location
;
4787 expr
= c_parser_expression (parser
).value
;
4788 if (flag_enable_cilkplus
&& contains_array_notation_expr (expr
))
4790 error_at (switch_cond_loc
,
4791 "array notations cannot be used as a condition for switch "
4793 expr
= error_mark_node
;
4795 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4799 switch_cond_loc
= UNKNOWN_LOCATION
;
4800 expr
= error_mark_node
;
4802 c_start_case (switch_loc
, switch_cond_loc
, expr
);
4803 save_break
= c_break_label
;
4804 c_break_label
= NULL_TREE
;
4805 body
= c_parser_c99_block_statement (parser
);
4806 c_finish_case (body
);
4809 location_t here
= c_parser_peek_token (parser
)->location
;
4810 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_break_label
);
4811 SET_EXPR_LOCATION (t
, here
);
4814 c_break_label
= save_break
;
4815 add_stmt (c_end_compound_stmt (switch_loc
, block
, flag_isoc99
));
4818 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
4821 while (expression) statement
4825 c_parser_while_statement (c_parser
*parser
)
4827 tree block
, cond
, body
, save_break
, save_cont
;
4829 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_WHILE
));
4830 c_parser_consume_token (parser
);
4831 block
= c_begin_compound_stmt (flag_isoc99
);
4832 loc
= c_parser_peek_token (parser
)->location
;
4833 cond
= c_parser_paren_condition (parser
);
4834 if (flag_enable_cilkplus
&& contains_array_notation_expr (cond
))
4836 error_at (loc
, "array notations cannot be used as a condition for while "
4838 cond
= error_mark_node
;
4840 save_break
= c_break_label
;
4841 c_break_label
= NULL_TREE
;
4842 save_cont
= c_cont_label
;
4843 c_cont_label
= NULL_TREE
;
4844 body
= c_parser_c99_block_statement (parser
);
4845 c_finish_loop (loc
, cond
, NULL
, body
, c_break_label
, c_cont_label
, true);
4846 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
4847 c_break_label
= save_break
;
4848 c_cont_label
= save_cont
;
4851 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
4854 do statement while ( expression ) ;
4858 c_parser_do_statement (c_parser
*parser
)
4860 tree block
, cond
, body
, save_break
, save_cont
, new_break
, new_cont
;
4862 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_DO
));
4863 c_parser_consume_token (parser
);
4864 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4865 warning_at (c_parser_peek_token (parser
)->location
,
4867 "suggest braces around empty body in %<do%> statement");
4868 block
= c_begin_compound_stmt (flag_isoc99
);
4869 loc
= c_parser_peek_token (parser
)->location
;
4870 save_break
= c_break_label
;
4871 c_break_label
= NULL_TREE
;
4872 save_cont
= c_cont_label
;
4873 c_cont_label
= NULL_TREE
;
4874 body
= c_parser_c99_block_statement (parser
);
4875 c_parser_require_keyword (parser
, RID_WHILE
, "expected %<while%>");
4876 new_break
= c_break_label
;
4877 c_break_label
= save_break
;
4878 new_cont
= c_cont_label
;
4879 c_cont_label
= save_cont
;
4880 cond
= c_parser_paren_condition (parser
);
4881 if (flag_enable_cilkplus
&& contains_array_notation_expr (cond
))
4883 error_at (loc
, "array notations cannot be used as a condition for a "
4884 "do-while statement");
4885 cond
= error_mark_node
;
4888 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
4889 c_parser_skip_to_end_of_block_or_statement (parser
);
4890 c_finish_loop (loc
, cond
, NULL
, body
, new_break
, new_cont
, false);
4891 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
4894 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
4897 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
4898 for ( nested-declaration expression[opt] ; expression[opt] ) statement
4900 The form with a declaration is new in C99.
4902 ??? In accordance with the old parser, the declaration may be a
4903 nested function, which is then rejected in check_for_loop_decls,
4904 but does it make any sense for this to be included in the grammar?
4905 Note in particular that the nested function does not include a
4906 trailing ';', whereas the "declaration" production includes one.
4907 Also, can we reject bad declarations earlier and cheaper than
4908 check_for_loop_decls?
4910 In Objective-C, there are two additional variants:
4913 for ( expression in expresssion ) statement
4914 for ( declaration in expression ) statement
4916 This is inconsistent with C, because the second variant is allowed
4917 even if c99 is not enabled.
4919 The rest of the comment documents these Objective-C foreach-statement.
4921 Here is the canonical example of the first variant:
4922 for (object in array) { do something with object }
4923 we call the first expression ("object") the "object_expression" and
4924 the second expression ("array") the "collection_expression".
4925 object_expression must be an lvalue of type "id" (a generic Objective-C
4926 object) because the loop works by assigning to object_expression the
4927 various objects from the collection_expression. collection_expression
4928 must evaluate to something of type "id" which responds to the method
4929 countByEnumeratingWithState:objects:count:.
4931 The canonical example of the second variant is:
4932 for (id object in array) { do something with object }
4933 which is completely equivalent to
4936 for (object in array) { do something with object }
4938 Note that initizializing 'object' in some way (eg, "for ((object =
4939 xxx) in array) { do something with object }") is possibly
4940 technically valid, but completely pointless as 'object' will be
4941 assigned to something else as soon as the loop starts. We should
4942 most likely reject it (TODO).
4944 The beginning of the Objective-C foreach-statement looks exactly
4945 like the beginning of the for-statement, and we can tell it is a
4946 foreach-statement only because the initial declaration or
4947 expression is terminated by 'in' instead of ';'.
4951 c_parser_for_statement (c_parser
*parser
)
4953 tree block
, cond
, incr
, save_break
, save_cont
, body
;
4954 /* The following are only used when parsing an ObjC foreach statement. */
4955 tree object_expression
;
4956 /* Silence the bogus uninitialized warning. */
4957 tree collection_expression
= NULL
;
4958 location_t loc
= c_parser_peek_token (parser
)->location
;
4959 location_t for_loc
= c_parser_peek_token (parser
)->location
;
4960 bool is_foreach_statement
= false;
4961 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_FOR
));
4962 c_parser_consume_token (parser
);
4963 /* Open a compound statement in Objective-C as well, just in case this is
4964 as foreach expression. */
4965 block
= c_begin_compound_stmt (flag_isoc99
|| c_dialect_objc ());
4966 cond
= error_mark_node
;
4967 incr
= error_mark_node
;
4968 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4970 /* Parse the initialization declaration or expression. */
4971 object_expression
= error_mark_node
;
4972 parser
->objc_could_be_foreach_context
= c_dialect_objc ();
4973 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4975 parser
->objc_could_be_foreach_context
= false;
4976 c_parser_consume_token (parser
);
4977 c_finish_expr_stmt (loc
, NULL_TREE
);
4979 else if (c_parser_next_tokens_start_declaration (parser
))
4981 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
4982 &object_expression
);
4983 parser
->objc_could_be_foreach_context
= false;
4985 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
4987 c_parser_consume_token (parser
);
4988 is_foreach_statement
= true;
4989 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
4990 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
4993 check_for_loop_decls (for_loc
, flag_isoc99
);
4995 else if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
4997 /* __extension__ can start a declaration, but is also an
4998 unary operator that can start an expression. Consume all
4999 but the last of a possible series of __extension__ to
5001 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
5002 && (c_parser_peek_2nd_token (parser
)->keyword
5004 c_parser_consume_token (parser
);
5005 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
5008 ext
= disable_extension_diagnostics ();
5009 c_parser_consume_token (parser
);
5010 c_parser_declaration_or_fndef (parser
, true, true, true, true,
5011 true, &object_expression
);
5012 parser
->objc_could_be_foreach_context
= false;
5014 restore_extension_diagnostics (ext
);
5015 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5017 c_parser_consume_token (parser
);
5018 is_foreach_statement
= true;
5019 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
5020 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
5023 check_for_loop_decls (for_loc
, flag_isoc99
);
5032 tree init_expression
;
5033 init_expression
= c_parser_expression (parser
).value
;
5034 parser
->objc_could_be_foreach_context
= false;
5035 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5037 c_parser_consume_token (parser
);
5038 is_foreach_statement
= true;
5039 if (! lvalue_p (init_expression
))
5040 c_parser_error (parser
, "invalid iterating variable in fast enumeration");
5041 object_expression
= c_fully_fold (init_expression
, false, NULL
);
5045 c_finish_expr_stmt (loc
, init_expression
);
5046 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5050 /* Parse the loop condition. In the case of a foreach
5051 statement, there is no loop condition. */
5052 gcc_assert (!parser
->objc_could_be_foreach_context
);
5053 if (!is_foreach_statement
)
5055 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5057 c_parser_consume_token (parser
);
5062 cond
= c_parser_condition (parser
);
5063 if (flag_enable_cilkplus
&& contains_array_notation_expr (cond
))
5065 error_at (loc
, "array notations cannot be used in a "
5066 "condition for a for-loop");
5067 cond
= error_mark_node
;
5069 c_parser_skip_until_found (parser
, CPP_SEMICOLON
,
5073 /* Parse the increment expression (the third expression in a
5074 for-statement). In the case of a foreach-statement, this is
5075 the expression that follows the 'in'. */
5076 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
5078 if (is_foreach_statement
)
5080 c_parser_error (parser
, "missing collection in fast enumeration");
5081 collection_expression
= error_mark_node
;
5084 incr
= c_process_expr_stmt (loc
, NULL_TREE
);
5088 if (is_foreach_statement
)
5089 collection_expression
= c_fully_fold (c_parser_expression (parser
).value
,
5092 incr
= c_process_expr_stmt (loc
, c_parser_expression (parser
).value
);
5094 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5096 save_break
= c_break_label
;
5097 c_break_label
= NULL_TREE
;
5098 save_cont
= c_cont_label
;
5099 c_cont_label
= NULL_TREE
;
5100 body
= c_parser_c99_block_statement (parser
);
5101 if (is_foreach_statement
)
5102 objc_finish_foreach_loop (loc
, object_expression
, collection_expression
, body
, c_break_label
, c_cont_label
);
5104 c_finish_loop (loc
, cond
, incr
, body
, c_break_label
, c_cont_label
, true);
5105 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
|| c_dialect_objc ()));
5106 c_break_label
= save_break
;
5107 c_cont_label
= save_cont
;
5110 /* Parse an asm statement, a GNU extension. This is a full-blown asm
5111 statement with inputs, outputs, clobbers, and volatile tag
5115 asm type-qualifier[opt] ( asm-argument ) ;
5116 asm type-qualifier[opt] goto ( asm-goto-argument ) ;
5120 asm-string-literal : asm-operands[opt]
5121 asm-string-literal : asm-operands[opt] : asm-operands[opt]
5122 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers[opt]
5125 asm-string-literal : : asm-operands[opt] : asm-clobbers[opt] \
5128 Qualifiers other than volatile are accepted in the syntax but
5132 c_parser_asm_statement (c_parser
*parser
)
5134 tree quals
, str
, outputs
, inputs
, clobbers
, labels
, ret
;
5135 bool simple
, is_goto
;
5136 location_t asm_loc
= c_parser_peek_token (parser
)->location
;
5137 int section
, nsections
;
5139 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
5140 c_parser_consume_token (parser
);
5141 if (c_parser_next_token_is_keyword (parser
, RID_VOLATILE
))
5143 quals
= c_parser_peek_token (parser
)->value
;
5144 c_parser_consume_token (parser
);
5146 else if (c_parser_next_token_is_keyword (parser
, RID_CONST
)
5147 || c_parser_next_token_is_keyword (parser
, RID_RESTRICT
))
5149 warning_at (c_parser_peek_token (parser
)->location
,
5151 "%E qualifier ignored on asm",
5152 c_parser_peek_token (parser
)->value
);
5154 c_parser_consume_token (parser
);
5160 if (c_parser_next_token_is_keyword (parser
, RID_GOTO
))
5162 c_parser_consume_token (parser
);
5166 /* ??? Follow the C++ parser rather than using the
5167 lex_untranslated_string kludge. */
5168 parser
->lex_untranslated_string
= true;
5171 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5174 str
= c_parser_asm_string_literal (parser
);
5175 if (str
== NULL_TREE
)
5176 goto error_close_paren
;
5179 outputs
= NULL_TREE
;
5181 clobbers
= NULL_TREE
;
5184 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
5187 /* Parse each colon-delimited section of operands. */
5188 nsections
= 3 + is_goto
;
5189 for (section
= 0; section
< nsections
; ++section
)
5191 if (!c_parser_require (parser
, CPP_COLON
,
5194 : "expected %<:%> or %<)%>"))
5195 goto error_close_paren
;
5197 /* Once past any colon, we're no longer a simple asm. */
5200 if ((!c_parser_next_token_is (parser
, CPP_COLON
)
5201 && !c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
5206 /* For asm goto, we don't allow output operands, but reserve
5207 the slot for a future extension that does allow them. */
5209 outputs
= c_parser_asm_operands (parser
);
5212 inputs
= c_parser_asm_operands (parser
);
5215 clobbers
= c_parser_asm_clobbers (parser
);
5218 labels
= c_parser_asm_goto_operands (parser
);
5224 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
5229 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
5231 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5235 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
5236 c_parser_skip_to_end_of_block_or_statement (parser
);
5238 ret
= build_asm_stmt (quals
, build_asm_expr (asm_loc
, str
, outputs
, inputs
,
5239 clobbers
, labels
, simple
));
5242 parser
->lex_untranslated_string
= false;
5246 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5250 /* Parse asm operands, a GNU extension.
5254 asm-operands , asm-operand
5257 asm-string-literal ( expression )
5258 [ identifier ] asm-string-literal ( expression )
5262 c_parser_asm_operands (c_parser
*parser
)
5264 tree list
= NULL_TREE
;
5269 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
5271 c_parser_consume_token (parser
);
5272 if (c_parser_next_token_is (parser
, CPP_NAME
))
5274 tree id
= c_parser_peek_token (parser
)->value
;
5275 c_parser_consume_token (parser
);
5276 name
= build_string (IDENTIFIER_LENGTH (id
),
5277 IDENTIFIER_POINTER (id
));
5281 c_parser_error (parser
, "expected identifier");
5282 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
5285 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5290 str
= c_parser_asm_string_literal (parser
);
5291 if (str
== NULL_TREE
)
5293 parser
->lex_untranslated_string
= false;
5294 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5296 parser
->lex_untranslated_string
= true;
5299 expr
= c_parser_expression (parser
);
5300 mark_exp_read (expr
.value
);
5301 parser
->lex_untranslated_string
= true;
5302 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
5304 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5307 list
= chainon (list
, build_tree_list (build_tree_list (name
, str
),
5309 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5310 c_parser_consume_token (parser
);
5317 /* Parse asm clobbers, a GNU extension.
5321 asm-clobbers , asm-string-literal
5325 c_parser_asm_clobbers (c_parser
*parser
)
5327 tree list
= NULL_TREE
;
5330 tree str
= c_parser_asm_string_literal (parser
);
5332 list
= tree_cons (NULL_TREE
, str
, list
);
5335 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5336 c_parser_consume_token (parser
);
5343 /* Parse asm goto labels, a GNU extension.
5347 asm-goto-operands , identifier
5351 c_parser_asm_goto_operands (c_parser
*parser
)
5353 tree list
= NULL_TREE
;
5358 if (c_parser_next_token_is (parser
, CPP_NAME
))
5360 c_token
*tok
= c_parser_peek_token (parser
);
5362 label
= lookup_label_for_goto (tok
->location
, name
);
5363 c_parser_consume_token (parser
);
5364 TREE_USED (label
) = 1;
5368 c_parser_error (parser
, "expected identifier");
5372 name
= build_string (IDENTIFIER_LENGTH (name
),
5373 IDENTIFIER_POINTER (name
));
5374 list
= tree_cons (name
, label
, list
);
5375 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5376 c_parser_consume_token (parser
);
5378 return nreverse (list
);
5382 /* Parse an expression other than a compound expression; that is, an
5383 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
5384 NULL then it is an Objective-C message expression which is the
5385 primary-expression starting the expression as an initializer.
5387 assignment-expression:
5388 conditional-expression
5389 unary-expression assignment-operator assignment-expression
5391 assignment-operator: one of
5392 = *= /= %= += -= <<= >>= &= ^= |=
5394 In GNU C we accept any conditional expression on the LHS and
5395 diagnose the invalid lvalue rather than producing a syntax
5398 static struct c_expr
5399 c_parser_expr_no_commas (c_parser
*parser
, struct c_expr
*after
)
5401 struct c_expr lhs
, rhs
, ret
;
5402 enum tree_code code
;
5403 location_t op_location
, exp_location
;
5404 gcc_assert (!after
|| c_dialect_objc ());
5405 lhs
= c_parser_conditional_expression (parser
, after
);
5406 op_location
= c_parser_peek_token (parser
)->location
;
5407 switch (c_parser_peek_token (parser
)->type
)
5416 code
= TRUNC_DIV_EXPR
;
5419 code
= TRUNC_MOD_EXPR
;
5434 code
= BIT_AND_EXPR
;
5437 code
= BIT_XOR_EXPR
;
5440 code
= BIT_IOR_EXPR
;
5445 c_parser_consume_token (parser
);
5446 exp_location
= c_parser_peek_token (parser
)->location
;
5447 rhs
= c_parser_expr_no_commas (parser
, NULL
);
5448 rhs
= default_function_array_read_conversion (exp_location
, rhs
);
5450 ret
.value
= build_modify_expr (op_location
, lhs
.value
, lhs
.original_type
,
5451 code
, exp_location
, rhs
.value
,
5453 if (code
== NOP_EXPR
)
5454 ret
.original_code
= MODIFY_EXPR
;
5457 TREE_NO_WARNING (ret
.value
) = 1;
5458 ret
.original_code
= ERROR_MARK
;
5460 ret
.original_type
= NULL
;
5464 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
5465 is not NULL then it is an Objective-C message expression which is
5466 the primary-expression starting the expression as an initializer.
5468 conditional-expression:
5469 logical-OR-expression
5470 logical-OR-expression ? expression : conditional-expression
5474 conditional-expression:
5475 logical-OR-expression ? : conditional-expression
5478 static struct c_expr
5479 c_parser_conditional_expression (c_parser
*parser
, struct c_expr
*after
)
5481 struct c_expr cond
, exp1
, exp2
, ret
;
5482 location_t cond_loc
, colon_loc
, middle_loc
;
5484 gcc_assert (!after
|| c_dialect_objc ());
5486 cond
= c_parser_binary_expression (parser
, after
, PREC_NONE
);
5488 if (c_parser_next_token_is_not (parser
, CPP_QUERY
))
5490 cond_loc
= c_parser_peek_token (parser
)->location
;
5491 cond
= default_function_array_read_conversion (cond_loc
, cond
);
5492 c_parser_consume_token (parser
);
5493 if (c_parser_next_token_is (parser
, CPP_COLON
))
5495 tree eptype
= NULL_TREE
;
5497 middle_loc
= c_parser_peek_token (parser
)->location
;
5498 pedwarn (middle_loc
, OPT_Wpedantic
,
5499 "ISO C forbids omitting the middle term of a ?: expression");
5500 warn_for_omitted_condop (middle_loc
, cond
.value
);
5501 if (TREE_CODE (cond
.value
) == EXCESS_PRECISION_EXPR
)
5503 eptype
= TREE_TYPE (cond
.value
);
5504 cond
.value
= TREE_OPERAND (cond
.value
, 0);
5506 /* Make sure first operand is calculated only once. */
5507 exp1
.value
= c_save_expr (default_conversion (cond
.value
));
5509 exp1
.value
= build1 (EXCESS_PRECISION_EXPR
, eptype
, exp1
.value
);
5510 exp1
.original_type
= NULL
;
5511 cond
.value
= c_objc_common_truthvalue_conversion (cond_loc
, exp1
.value
);
5512 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_true_node
;
5517 = c_objc_common_truthvalue_conversion
5518 (cond_loc
, default_conversion (cond
.value
));
5519 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_false_node
;
5520 exp1
= c_parser_expression_conv (parser
);
5521 mark_exp_read (exp1
.value
);
5522 c_inhibit_evaluation_warnings
+=
5523 ((cond
.value
== truthvalue_true_node
)
5524 - (cond
.value
== truthvalue_false_node
));
5527 colon_loc
= c_parser_peek_token (parser
)->location
;
5528 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
5530 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
5531 ret
.value
= error_mark_node
;
5532 ret
.original_code
= ERROR_MARK
;
5533 ret
.original_type
= NULL
;
5537 location_t exp2_loc
= c_parser_peek_token (parser
)->location
;
5538 exp2
= c_parser_conditional_expression (parser
, NULL
);
5539 exp2
= default_function_array_read_conversion (exp2_loc
, exp2
);
5541 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
5542 ret
.value
= build_conditional_expr (colon_loc
, cond
.value
,
5543 cond
.original_code
== C_MAYBE_CONST_EXPR
,
5544 exp1
.value
, exp1
.original_type
,
5545 exp2
.value
, exp2
.original_type
);
5546 ret
.original_code
= ERROR_MARK
;
5547 if (exp1
.value
== error_mark_node
|| exp2
.value
== error_mark_node
)
5548 ret
.original_type
= NULL
;
5553 /* If both sides are enum type, the default conversion will have
5554 made the type of the result be an integer type. We want to
5555 remember the enum types we started with. */
5556 t1
= exp1
.original_type
? exp1
.original_type
: TREE_TYPE (exp1
.value
);
5557 t2
= exp2
.original_type
? exp2
.original_type
: TREE_TYPE (exp2
.value
);
5558 ret
.original_type
= ((t1
!= error_mark_node
5559 && t2
!= error_mark_node
5560 && (TYPE_MAIN_VARIANT (t1
)
5561 == TYPE_MAIN_VARIANT (t2
)))
5568 /* Parse a binary expression; that is, a logical-OR-expression (C90
5569 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
5570 an Objective-C message expression which is the primary-expression
5571 starting the expression as an initializer. PREC is the starting
5572 precedence, usually PREC_NONE.
5574 multiplicative-expression:
5576 multiplicative-expression * cast-expression
5577 multiplicative-expression / cast-expression
5578 multiplicative-expression % cast-expression
5580 additive-expression:
5581 multiplicative-expression
5582 additive-expression + multiplicative-expression
5583 additive-expression - multiplicative-expression
5587 shift-expression << additive-expression
5588 shift-expression >> additive-expression
5590 relational-expression:
5592 relational-expression < shift-expression
5593 relational-expression > shift-expression
5594 relational-expression <= shift-expression
5595 relational-expression >= shift-expression
5597 equality-expression:
5598 relational-expression
5599 equality-expression == relational-expression
5600 equality-expression != relational-expression
5604 AND-expression & equality-expression
5606 exclusive-OR-expression:
5608 exclusive-OR-expression ^ AND-expression
5610 inclusive-OR-expression:
5611 exclusive-OR-expression
5612 inclusive-OR-expression | exclusive-OR-expression
5614 logical-AND-expression:
5615 inclusive-OR-expression
5616 logical-AND-expression && inclusive-OR-expression
5618 logical-OR-expression:
5619 logical-AND-expression
5620 logical-OR-expression || logical-AND-expression
5623 static struct c_expr
5624 c_parser_binary_expression (c_parser
*parser
, struct c_expr
*after
,
5625 enum c_parser_prec prec
)
5627 /* A binary expression is parsed using operator-precedence parsing,
5628 with the operands being cast expressions. All the binary
5629 operators are left-associative. Thus a binary expression is of
5632 E0 op1 E1 op2 E2 ...
5634 which we represent on a stack. On the stack, the precedence
5635 levels are strictly increasing. When a new operator is
5636 encountered of higher precedence than that at the top of the
5637 stack, it is pushed; its LHS is the top expression, and its RHS
5638 is everything parsed until it is popped. When a new operator is
5639 encountered with precedence less than or equal to that at the top
5640 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
5641 by the result of the operation until the operator at the top of
5642 the stack has lower precedence than the new operator or there is
5643 only one element on the stack; then the top expression is the LHS
5644 of the new operator. In the case of logical AND and OR
5645 expressions, we also need to adjust c_inhibit_evaluation_warnings
5646 as appropriate when the operators are pushed and popped. */
5649 /* The expression at this stack level. */
5651 /* The precedence of the operator on its left, PREC_NONE at the
5652 bottom of the stack. */
5653 enum c_parser_prec prec
;
5654 /* The operation on its left. */
5656 /* The source location of this operation. */
5660 /* Location of the binary operator. */
5661 location_t binary_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
5664 switch (stack[sp].op) \
5666 case TRUTH_ANDIF_EXPR: \
5667 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
5668 == truthvalue_false_node); \
5670 case TRUTH_ORIF_EXPR: \
5671 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
5672 == truthvalue_true_node); \
5677 stack[sp - 1].expr \
5678 = default_function_array_read_conversion (stack[sp - 1].loc, \
5679 stack[sp - 1].expr); \
5681 = default_function_array_read_conversion (stack[sp].loc, \
5683 stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc, \
5685 stack[sp - 1].expr, \
5689 gcc_assert (!after
|| c_dialect_objc ());
5690 stack
[0].loc
= c_parser_peek_token (parser
)->location
;
5691 stack
[0].expr
= c_parser_cast_expression (parser
, after
);
5692 stack
[0].prec
= prec
;
5696 enum c_parser_prec oprec
;
5697 enum tree_code ocode
;
5700 switch (c_parser_peek_token (parser
)->type
)
5708 ocode
= TRUNC_DIV_EXPR
;
5712 ocode
= TRUNC_MOD_EXPR
;
5724 ocode
= LSHIFT_EXPR
;
5728 ocode
= RSHIFT_EXPR
;
5742 case CPP_GREATER_EQ
:
5755 oprec
= PREC_BITAND
;
5756 ocode
= BIT_AND_EXPR
;
5759 oprec
= PREC_BITXOR
;
5760 ocode
= BIT_XOR_EXPR
;
5764 ocode
= BIT_IOR_EXPR
;
5767 oprec
= PREC_LOGAND
;
5768 ocode
= TRUTH_ANDIF_EXPR
;
5772 ocode
= TRUTH_ORIF_EXPR
;
5775 /* Not a binary operator, so end of the binary
5779 binary_loc
= c_parser_peek_token (parser
)->location
;
5780 while (oprec
<= stack
[sp
].prec
)
5786 c_parser_consume_token (parser
);
5789 case TRUTH_ANDIF_EXPR
:
5791 = default_function_array_read_conversion (stack
[sp
].loc
,
5793 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
5794 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
5795 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
5796 == truthvalue_false_node
);
5798 case TRUTH_ORIF_EXPR
:
5800 = default_function_array_read_conversion (stack
[sp
].loc
,
5802 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
5803 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
5804 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
5805 == truthvalue_true_node
);
5811 stack
[sp
].loc
= binary_loc
;
5812 stack
[sp
].expr
= c_parser_cast_expression (parser
, NULL
);
5813 stack
[sp
].prec
= oprec
;
5814 stack
[sp
].op
= ocode
;
5815 stack
[sp
].loc
= binary_loc
;
5820 return stack
[0].expr
;
5824 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
5825 NULL then it is an Objective-C message expression which is the
5826 primary-expression starting the expression as an initializer.
5830 ( type-name ) unary-expression
5833 static struct c_expr
5834 c_parser_cast_expression (c_parser
*parser
, struct c_expr
*after
)
5836 location_t cast_loc
= c_parser_peek_token (parser
)->location
;
5837 gcc_assert (!after
|| c_dialect_objc ());
5839 return c_parser_postfix_expression_after_primary (parser
,
5841 /* If the expression begins with a parenthesized type name, it may
5842 be either a cast or a compound literal; we need to see whether
5843 the next character is '{' to tell the difference. If not, it is
5844 an unary expression. Full detection of unknown typenames here
5845 would require a 3-token lookahead. */
5846 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
5847 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
5849 struct c_type_name
*type_name
;
5852 c_parser_consume_token (parser
);
5853 type_name
= c_parser_type_name (parser
);
5854 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5855 if (type_name
== NULL
)
5857 ret
.value
= error_mark_node
;
5858 ret
.original_code
= ERROR_MARK
;
5859 ret
.original_type
= NULL
;
5863 /* Save casted types in the function's used types hash table. */
5864 used_types_insert (type_name
->specs
->type
);
5866 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5867 return c_parser_postfix_expression_after_paren_type (parser
, type_name
,
5870 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
5871 expr
= c_parser_cast_expression (parser
, NULL
);
5872 expr
= default_function_array_read_conversion (expr_loc
, expr
);
5874 ret
.value
= c_cast_expr (cast_loc
, type_name
, expr
.value
);
5875 ret
.original_code
= ERROR_MARK
;
5876 ret
.original_type
= NULL
;
5880 return c_parser_unary_expression (parser
);
5883 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
5889 unary-operator cast-expression
5890 sizeof unary-expression
5891 sizeof ( type-name )
5893 unary-operator: one of
5899 __alignof__ unary-expression
5900 __alignof__ ( type-name )
5903 (C11 permits _Alignof with type names only.)
5905 unary-operator: one of
5906 __extension__ __real__ __imag__
5908 Transactional Memory:
5911 transaction-expression
5913 In addition, the GNU syntax treats ++ and -- as unary operators, so
5914 they may be applied to cast expressions with errors for non-lvalues
5917 static struct c_expr
5918 c_parser_unary_expression (c_parser
*parser
)
5921 struct c_expr ret
, op
;
5922 location_t op_loc
= c_parser_peek_token (parser
)->location
;
5924 ret
.original_code
= ERROR_MARK
;
5925 ret
.original_type
= NULL
;
5926 switch (c_parser_peek_token (parser
)->type
)
5929 c_parser_consume_token (parser
);
5930 exp_loc
= c_parser_peek_token (parser
)->location
;
5931 op
= c_parser_cast_expression (parser
, NULL
);
5933 /* If there is array notations in op, we expand them. */
5934 if (flag_enable_cilkplus
&& TREE_CODE (op
.value
) == ARRAY_NOTATION_REF
)
5935 return fix_array_notation_expr (exp_loc
, PREINCREMENT_EXPR
, op
);
5938 op
= default_function_array_read_conversion (exp_loc
, op
);
5939 return parser_build_unary_op (op_loc
, PREINCREMENT_EXPR
, op
);
5941 case CPP_MINUS_MINUS
:
5942 c_parser_consume_token (parser
);
5943 exp_loc
= c_parser_peek_token (parser
)->location
;
5944 op
= c_parser_cast_expression (parser
, NULL
);
5946 /* If there is array notations in op, we expand them. */
5947 if (flag_enable_cilkplus
&& TREE_CODE (op
.value
) == ARRAY_NOTATION_REF
)
5948 return fix_array_notation_expr (exp_loc
, PREDECREMENT_EXPR
, op
);
5951 op
= default_function_array_read_conversion (exp_loc
, op
);
5952 return parser_build_unary_op (op_loc
, PREDECREMENT_EXPR
, op
);
5955 c_parser_consume_token (parser
);
5956 op
= c_parser_cast_expression (parser
, NULL
);
5957 mark_exp_read (op
.value
);
5958 return parser_build_unary_op (op_loc
, ADDR_EXPR
, op
);
5960 c_parser_consume_token (parser
);
5961 exp_loc
= c_parser_peek_token (parser
)->location
;
5962 op
= c_parser_cast_expression (parser
, NULL
);
5963 op
= default_function_array_read_conversion (exp_loc
, op
);
5964 ret
.value
= build_indirect_ref (op_loc
, op
.value
, RO_UNARY_STAR
);
5967 if (!c_dialect_objc () && !in_system_header
)
5970 "traditional C rejects the unary plus operator");
5971 c_parser_consume_token (parser
);
5972 exp_loc
= c_parser_peek_token (parser
)->location
;
5973 op
= c_parser_cast_expression (parser
, NULL
);
5974 op
= default_function_array_read_conversion (exp_loc
, op
);
5975 return parser_build_unary_op (op_loc
, CONVERT_EXPR
, op
);
5977 c_parser_consume_token (parser
);
5978 exp_loc
= c_parser_peek_token (parser
)->location
;
5979 op
= c_parser_cast_expression (parser
, NULL
);
5980 op
= default_function_array_read_conversion (exp_loc
, op
);
5981 return parser_build_unary_op (op_loc
, NEGATE_EXPR
, op
);
5983 c_parser_consume_token (parser
);
5984 exp_loc
= c_parser_peek_token (parser
)->location
;
5985 op
= c_parser_cast_expression (parser
, NULL
);
5986 op
= default_function_array_read_conversion (exp_loc
, op
);
5987 return parser_build_unary_op (op_loc
, BIT_NOT_EXPR
, op
);
5989 c_parser_consume_token (parser
);
5990 exp_loc
= c_parser_peek_token (parser
)->location
;
5991 op
= c_parser_cast_expression (parser
, NULL
);
5992 op
= default_function_array_read_conversion (exp_loc
, op
);
5993 return parser_build_unary_op (op_loc
, TRUTH_NOT_EXPR
, op
);
5995 /* Refer to the address of a label as a pointer. */
5996 c_parser_consume_token (parser
);
5997 if (c_parser_next_token_is (parser
, CPP_NAME
))
5999 ret
.value
= finish_label_address_expr
6000 (c_parser_peek_token (parser
)->value
, op_loc
);
6001 c_parser_consume_token (parser
);
6005 c_parser_error (parser
, "expected identifier");
6006 ret
.value
= error_mark_node
;
6010 switch (c_parser_peek_token (parser
)->keyword
)
6013 return c_parser_sizeof_expression (parser
);
6015 return c_parser_alignof_expression (parser
);
6017 c_parser_consume_token (parser
);
6018 ext
= disable_extension_diagnostics ();
6019 ret
= c_parser_cast_expression (parser
, NULL
);
6020 restore_extension_diagnostics (ext
);
6023 c_parser_consume_token (parser
);
6024 exp_loc
= c_parser_peek_token (parser
)->location
;
6025 op
= c_parser_cast_expression (parser
, NULL
);
6026 op
= default_function_array_conversion (exp_loc
, op
);
6027 return parser_build_unary_op (op_loc
, REALPART_EXPR
, op
);
6029 c_parser_consume_token (parser
);
6030 exp_loc
= c_parser_peek_token (parser
)->location
;
6031 op
= c_parser_cast_expression (parser
, NULL
);
6032 op
= default_function_array_conversion (exp_loc
, op
);
6033 return parser_build_unary_op (op_loc
, IMAGPART_EXPR
, op
);
6034 case RID_TRANSACTION_ATOMIC
:
6035 case RID_TRANSACTION_RELAXED
:
6036 return c_parser_transaction_expression (parser
,
6037 c_parser_peek_token (parser
)->keyword
);
6039 return c_parser_postfix_expression (parser
);
6042 return c_parser_postfix_expression (parser
);
6046 /* Parse a sizeof expression. */
6048 static struct c_expr
6049 c_parser_sizeof_expression (c_parser
*parser
)
6052 location_t expr_loc
;
6053 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SIZEOF
));
6054 c_parser_consume_token (parser
);
6055 c_inhibit_evaluation_warnings
++;
6057 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
6058 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6060 /* Either sizeof ( type-name ) or sizeof unary-expression
6061 starting with a compound literal. */
6062 struct c_type_name
*type_name
;
6063 c_parser_consume_token (parser
);
6064 expr_loc
= c_parser_peek_token (parser
)->location
;
6065 type_name
= c_parser_type_name (parser
);
6066 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6067 if (type_name
== NULL
)
6070 c_inhibit_evaluation_warnings
--;
6072 ret
.value
= error_mark_node
;
6073 ret
.original_code
= ERROR_MARK
;
6074 ret
.original_type
= NULL
;
6077 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6079 expr
= c_parser_postfix_expression_after_paren_type (parser
,
6084 /* sizeof ( type-name ). */
6085 c_inhibit_evaluation_warnings
--;
6087 return c_expr_sizeof_type (expr_loc
, type_name
);
6091 expr_loc
= c_parser_peek_token (parser
)->location
;
6092 expr
= c_parser_unary_expression (parser
);
6094 c_inhibit_evaluation_warnings
--;
6096 mark_exp_read (expr
.value
);
6097 if (TREE_CODE (expr
.value
) == COMPONENT_REF
6098 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
6099 error_at (expr_loc
, "%<sizeof%> applied to a bit-field");
6100 return c_expr_sizeof_expr (expr_loc
, expr
);
6104 /* Parse an alignof expression. */
6106 static struct c_expr
6107 c_parser_alignof_expression (c_parser
*parser
)
6110 location_t loc
= c_parser_peek_token (parser
)->location
;
6111 tree alignof_spelling
= c_parser_peek_token (parser
)->value
;
6112 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNOF
));
6113 /* A diagnostic is not required for the use of this identifier in
6114 the implementation namespace; only diagnose it for the C11
6115 spelling because of existing code using the other spellings. */
6117 && strcmp (IDENTIFIER_POINTER (alignof_spelling
), "_Alignof") == 0)
6120 pedwarn (loc
, OPT_Wpedantic
, "ISO C99 does not support %qE",
6123 pedwarn (loc
, OPT_Wpedantic
, "ISO C90 does not support %qE",
6126 c_parser_consume_token (parser
);
6127 c_inhibit_evaluation_warnings
++;
6129 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
6130 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6132 /* Either __alignof__ ( type-name ) or __alignof__
6133 unary-expression starting with a compound literal. */
6135 struct c_type_name
*type_name
;
6137 c_parser_consume_token (parser
);
6138 loc
= c_parser_peek_token (parser
)->location
;
6139 type_name
= c_parser_type_name (parser
);
6140 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6141 if (type_name
== NULL
)
6144 c_inhibit_evaluation_warnings
--;
6146 ret
.value
= error_mark_node
;
6147 ret
.original_code
= ERROR_MARK
;
6148 ret
.original_type
= NULL
;
6151 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6153 expr
= c_parser_postfix_expression_after_paren_type (parser
,
6158 /* alignof ( type-name ). */
6159 c_inhibit_evaluation_warnings
--;
6161 ret
.value
= c_alignof (loc
, groktypename (type_name
, NULL
, NULL
));
6162 ret
.original_code
= ERROR_MARK
;
6163 ret
.original_type
= NULL
;
6169 expr
= c_parser_unary_expression (parser
);
6171 mark_exp_read (expr
.value
);
6172 c_inhibit_evaluation_warnings
--;
6174 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not allow %<%E (expression)%>",
6176 ret
.value
= c_alignof_expr (loc
, expr
.value
);
6177 ret
.original_code
= ERROR_MARK
;
6178 ret
.original_type
= NULL
;
6183 /* Helper function to read arguments of builtins which are interfaces
6184 for the middle-end nodes like COMPLEX_EXPR, VEC_PERM_EXPR and
6185 others. The name of the builtin is passed using BNAME parameter.
6186 Function returns true if there were no errors while parsing and
6187 stores the arguments in CEXPR_LIST. */
6189 c_parser_get_builtin_args (c_parser
*parser
, const char *bname
,
6190 vec
<c_expr_t
, va_gc
> **ret_cexpr_list
,
6193 location_t loc
= c_parser_peek_token (parser
)->location
;
6194 vec
<c_expr_t
, va_gc
> *cexpr_list
;
6196 bool saved_force_folding_builtin_constant_p
;
6198 *ret_cexpr_list
= NULL
;
6199 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
6201 error_at (loc
, "cannot take address of %qs", bname
);
6205 c_parser_consume_token (parser
);
6207 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
6209 c_parser_consume_token (parser
);
6213 saved_force_folding_builtin_constant_p
6214 = force_folding_builtin_constant_p
;
6215 force_folding_builtin_constant_p
|= choose_expr_p
;
6216 expr
= c_parser_expr_no_commas (parser
, NULL
);
6217 force_folding_builtin_constant_p
6218 = saved_force_folding_builtin_constant_p
;
6219 vec_alloc (cexpr_list
, 1);
6220 C_EXPR_APPEND (cexpr_list
, expr
);
6221 while (c_parser_next_token_is (parser
, CPP_COMMA
))
6223 c_parser_consume_token (parser
);
6224 expr
= c_parser_expr_no_commas (parser
, NULL
);
6225 C_EXPR_APPEND (cexpr_list
, expr
);
6228 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
6231 *ret_cexpr_list
= cexpr_list
;
6235 /* This represents a single generic-association. */
6237 struct c_generic_association
6239 /* The location of the starting token of the type. */
6240 location_t type_location
;
6241 /* The association's type, or NULL_TREE for 'default'. */
6243 /* The association's expression. */
6244 struct c_expr expression
;
6247 /* Parse a generic-selection. (C11 6.5.1.1).
6250 _Generic ( assignment-expression , generic-assoc-list )
6254 generic-assoc-list , generic-association
6256 generic-association:
6257 type-name : assignment-expression
6258 default : assignment-expression
6261 static struct c_expr
6262 c_parser_generic_selection (c_parser
*parser
)
6264 vec
<c_generic_association
> associations
= vNULL
;
6265 struct c_expr selector
, error_expr
;
6267 struct c_generic_association matched_assoc
;
6268 bool match_found
= false;
6269 location_t generic_loc
, selector_loc
;
6271 error_expr
.original_code
= ERROR_MARK
;
6272 error_expr
.original_type
= NULL
;
6273 error_expr
.value
= error_mark_node
;
6274 matched_assoc
.type_location
= UNKNOWN_LOCATION
;
6275 matched_assoc
.type
= NULL_TREE
;
6276 matched_assoc
.expression
= error_expr
;
6278 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_GENERIC
));
6279 generic_loc
= c_parser_peek_token (parser
)->location
;
6280 c_parser_consume_token (parser
);
6284 pedwarn (generic_loc
, OPT_Wpedantic
,
6285 "ISO C99 does not support %<_Generic%>");
6287 pedwarn (generic_loc
, OPT_Wpedantic
,
6288 "ISO C90 does not support %<_Generic%>");
6291 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6294 c_inhibit_evaluation_warnings
++;
6295 selector_loc
= c_parser_peek_token (parser
)->location
;
6296 selector
= c_parser_expr_no_commas (parser
, NULL
);
6297 selector
= default_function_array_conversion (selector_loc
, selector
);
6298 c_inhibit_evaluation_warnings
--;
6300 if (selector
.value
== error_mark_node
)
6302 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6305 selector_type
= TREE_TYPE (selector
.value
);
6306 /* In ISO C terms, rvalues (including the controlling expression of
6307 _Generic) do not have qualified types. */
6308 if (TREE_CODE (selector_type
) != ARRAY_TYPE
)
6309 selector_type
= TYPE_MAIN_VARIANT (selector_type
);
6310 /* In ISO C terms, _Noreturn is not part of the type of expressions
6311 such as &abort, but in GCC it is represented internally as a type
6313 if (FUNCTION_POINTER_TYPE_P (selector_type
)
6314 && TYPE_QUALS (TREE_TYPE (selector_type
)) != TYPE_UNQUALIFIED
)
6316 = build_pointer_type (TYPE_MAIN_VARIANT (TREE_TYPE (selector_type
)));
6318 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
6320 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6326 struct c_generic_association assoc
, *iter
;
6328 c_token
*token
= c_parser_peek_token (parser
);
6330 assoc
.type_location
= token
->location
;
6331 if (token
->type
== CPP_KEYWORD
&& token
->keyword
== RID_DEFAULT
)
6333 c_parser_consume_token (parser
);
6334 assoc
.type
= NULL_TREE
;
6338 struct c_type_name
*type_name
;
6340 type_name
= c_parser_type_name (parser
);
6341 if (type_name
== NULL
)
6343 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6346 assoc
.type
= groktypename (type_name
, NULL
, NULL
);
6347 if (assoc
.type
== error_mark_node
)
6349 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6353 if (TREE_CODE (assoc
.type
) == FUNCTION_TYPE
)
6354 error_at (assoc
.type_location
,
6355 "%<_Generic%> association has function type");
6356 else if (!COMPLETE_TYPE_P (assoc
.type
))
6357 error_at (assoc
.type_location
,
6358 "%<_Generic%> association has incomplete type");
6360 if (variably_modified_type_p (assoc
.type
, NULL_TREE
))
6361 error_at (assoc
.type_location
,
6362 "%<_Generic%> association has "
6363 "variable length type");
6366 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6368 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6372 assoc
.expression
= c_parser_expr_no_commas (parser
, NULL
);
6373 if (assoc
.expression
.value
== error_mark_node
)
6375 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6379 for (ix
= 0; associations
.iterate (ix
, &iter
); ++ix
)
6381 if (assoc
.type
== NULL_TREE
)
6383 if (iter
->type
== NULL_TREE
)
6385 error_at (assoc
.type_location
,
6386 "duplicate %<default%> case in %<_Generic%>");
6387 inform (iter
->type_location
, "original %<default%> is here");
6390 else if (iter
->type
!= NULL_TREE
)
6392 if (comptypes (assoc
.type
, iter
->type
))
6394 error_at (assoc
.type_location
,
6395 "%<_Generic%> specifies two compatible types");
6396 inform (iter
->type_location
, "compatible type is here");
6401 if (assoc
.type
== NULL_TREE
)
6405 matched_assoc
= assoc
;
6409 else if (comptypes (assoc
.type
, selector_type
))
6411 if (!match_found
|| matched_assoc
.type
== NULL_TREE
)
6413 matched_assoc
= assoc
;
6418 error_at (assoc
.type_location
,
6419 "%<_Generic> selector matches multiple associations");
6420 inform (matched_assoc
.type_location
,
6421 "other match is here");
6425 associations
.safe_push (assoc
);
6427 if (c_parser_peek_token (parser
)->type
!= CPP_COMMA
)
6429 c_parser_consume_token (parser
);
6432 associations
.release ();
6434 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
6436 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6442 error_at (selector_loc
, "%<_Generic%> selector of type %qT is not "
6443 "compatible with any association",
6448 return matched_assoc
.expression
;
6451 associations
.release ();
6455 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
6459 postfix-expression [ expression ]
6460 postfix-expression ( argument-expression-list[opt] )
6461 postfix-expression . identifier
6462 postfix-expression -> identifier
6463 postfix-expression ++
6464 postfix-expression --
6465 ( type-name ) { initializer-list }
6466 ( type-name ) { initializer-list , }
6468 argument-expression-list:
6470 argument-expression-list , argument-expression
6483 (treated as a keyword in GNU C)
6486 ( compound-statement )
6487 __builtin_va_arg ( assignment-expression , type-name )
6488 __builtin_offsetof ( type-name , offsetof-member-designator )
6489 __builtin_choose_expr ( assignment-expression ,
6490 assignment-expression ,
6491 assignment-expression )
6492 __builtin_types_compatible_p ( type-name , type-name )
6493 __builtin_complex ( assignment-expression , assignment-expression )
6494 __builtin_shuffle ( assignment-expression , assignment-expression )
6495 __builtin_shuffle ( assignment-expression ,
6496 assignment-expression ,
6497 assignment-expression, )
6499 offsetof-member-designator:
6501 offsetof-member-designator . identifier
6502 offsetof-member-designator [ expression ]
6507 [ objc-receiver objc-message-args ]
6508 @selector ( objc-selector-arg )
6509 @protocol ( identifier )
6510 @encode ( type-name )
6512 Classname . identifier
6515 static struct c_expr
6516 c_parser_postfix_expression (c_parser
*parser
)
6518 struct c_expr expr
, e1
;
6519 struct c_type_name
*t1
, *t2
;
6520 location_t loc
= c_parser_peek_token (parser
)->location
;;
6521 expr
.original_code
= ERROR_MARK
;
6522 expr
.original_type
= NULL
;
6523 switch (c_parser_peek_token (parser
)->type
)
6526 expr
.value
= c_parser_peek_token (parser
)->value
;
6527 loc
= c_parser_peek_token (parser
)->location
;
6528 c_parser_consume_token (parser
);
6529 if (TREE_CODE (expr
.value
) == FIXED_CST
6530 && !targetm
.fixed_point_supported_p ())
6532 error_at (loc
, "fixed-point types not supported for this target");
6533 expr
.value
= error_mark_node
;
6540 expr
.value
= c_parser_peek_token (parser
)->value
;
6541 c_parser_consume_token (parser
);
6547 case CPP_UTF8STRING
:
6548 expr
.value
= c_parser_peek_token (parser
)->value
;
6549 expr
.original_code
= STRING_CST
;
6550 c_parser_consume_token (parser
);
6552 case CPP_OBJC_STRING
:
6553 gcc_assert (c_dialect_objc ());
6555 = objc_build_string_object (c_parser_peek_token (parser
)->value
);
6556 c_parser_consume_token (parser
);
6559 switch (c_parser_peek_token (parser
)->id_kind
)
6563 tree id
= c_parser_peek_token (parser
)->value
;
6564 c_parser_consume_token (parser
);
6565 expr
.value
= build_external_ref (loc
, id
,
6566 (c_parser_peek_token (parser
)->type
6568 &expr
.original_type
);
6571 case C_ID_CLASSNAME
:
6573 /* Here we parse the Objective-C 2.0 Class.name dot
6575 tree class_name
= c_parser_peek_token (parser
)->value
;
6577 c_parser_consume_token (parser
);
6578 gcc_assert (c_dialect_objc ());
6579 if (!c_parser_require (parser
, CPP_DOT
, "expected %<.%>"))
6581 expr
.value
= error_mark_node
;
6584 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6586 c_parser_error (parser
, "expected identifier");
6587 expr
.value
= error_mark_node
;
6590 component
= c_parser_peek_token (parser
)->value
;
6591 c_parser_consume_token (parser
);
6592 expr
.value
= objc_build_class_component_ref (class_name
,
6597 c_parser_error (parser
, "expected expression");
6598 expr
.value
= error_mark_node
;
6602 case CPP_OPEN_PAREN
:
6603 /* A parenthesized expression, statement expression or compound
6605 if (c_parser_peek_2nd_token (parser
)->type
== CPP_OPEN_BRACE
)
6607 /* A statement expression. */
6609 location_t brace_loc
;
6610 c_parser_consume_token (parser
);
6611 brace_loc
= c_parser_peek_token (parser
)->location
;
6612 c_parser_consume_token (parser
);
6613 if (!building_stmt_list_p ())
6615 error_at (loc
, "braced-group within expression allowed "
6616 "only inside a function");
6617 parser
->error
= true;
6618 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
6619 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6620 expr
.value
= error_mark_node
;
6623 stmt
= c_begin_stmt_expr ();
6624 c_parser_compound_statement_nostart (parser
);
6625 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6627 pedwarn (loc
, OPT_Wpedantic
,
6628 "ISO C forbids braced-groups within expressions");
6629 expr
.value
= c_finish_stmt_expr (brace_loc
, stmt
);
6630 mark_exp_read (expr
.value
);
6632 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6634 /* A compound literal. ??? Can we actually get here rather
6635 than going directly to
6636 c_parser_postfix_expression_after_paren_type from
6639 struct c_type_name
*type_name
;
6640 c_parser_consume_token (parser
);
6641 loc
= c_parser_peek_token (parser
)->location
;
6642 type_name
= c_parser_type_name (parser
);
6643 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6645 if (type_name
== NULL
)
6647 expr
.value
= error_mark_node
;
6650 expr
= c_parser_postfix_expression_after_paren_type (parser
,
6656 /* A parenthesized expression. */
6657 c_parser_consume_token (parser
);
6658 expr
= c_parser_expression (parser
);
6659 if (TREE_CODE (expr
.value
) == MODIFY_EXPR
)
6660 TREE_NO_WARNING (expr
.value
) = 1;
6661 if (expr
.original_code
!= C_MAYBE_CONST_EXPR
)
6662 expr
.original_code
= ERROR_MARK
;
6663 /* Don't change EXPR.ORIGINAL_TYPE. */
6664 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6669 switch (c_parser_peek_token (parser
)->keyword
)
6671 case RID_FUNCTION_NAME
:
6672 case RID_PRETTY_FUNCTION_NAME
:
6673 case RID_C99_FUNCTION_NAME
:
6674 expr
.value
= fname_decl (loc
,
6675 c_parser_peek_token (parser
)->keyword
,
6676 c_parser_peek_token (parser
)->value
);
6677 c_parser_consume_token (parser
);
6680 c_parser_consume_token (parser
);
6681 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6683 expr
.value
= error_mark_node
;
6686 e1
= c_parser_expr_no_commas (parser
, NULL
);
6687 mark_exp_read (e1
.value
);
6688 e1
.value
= c_fully_fold (e1
.value
, false, NULL
);
6689 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
6691 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6692 expr
.value
= error_mark_node
;
6695 loc
= c_parser_peek_token (parser
)->location
;
6696 t1
= c_parser_type_name (parser
);
6697 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6701 expr
.value
= error_mark_node
;
6705 tree type_expr
= NULL_TREE
;
6706 expr
.value
= c_build_va_arg (loc
, e1
.value
,
6707 groktypename (t1
, &type_expr
, NULL
));
6710 expr
.value
= build2 (C_MAYBE_CONST_EXPR
,
6711 TREE_TYPE (expr
.value
), type_expr
,
6713 C_MAYBE_CONST_EXPR_NON_CONST (expr
.value
) = true;
6718 c_parser_consume_token (parser
);
6719 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6721 expr
.value
= error_mark_node
;
6724 t1
= c_parser_type_name (parser
);
6726 parser
->error
= true;
6727 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
6728 gcc_assert (parser
->error
);
6731 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6732 expr
.value
= error_mark_node
;
6737 tree type
= groktypename (t1
, NULL
, NULL
);
6739 if (type
== error_mark_node
)
6740 offsetof_ref
= error_mark_node
;
6743 offsetof_ref
= build1 (INDIRECT_REF
, type
, null_pointer_node
);
6744 SET_EXPR_LOCATION (offsetof_ref
, loc
);
6746 /* Parse the second argument to __builtin_offsetof. We
6747 must have one identifier, and beyond that we want to
6748 accept sub structure and sub array references. */
6749 if (c_parser_next_token_is (parser
, CPP_NAME
))
6751 offsetof_ref
= build_component_ref
6752 (loc
, offsetof_ref
, c_parser_peek_token (parser
)->value
);
6753 c_parser_consume_token (parser
);
6754 while (c_parser_next_token_is (parser
, CPP_DOT
)
6755 || c_parser_next_token_is (parser
,
6757 || c_parser_next_token_is (parser
,
6760 if (c_parser_next_token_is (parser
, CPP_DEREF
))
6762 loc
= c_parser_peek_token (parser
)->location
;
6763 offsetof_ref
= build_array_ref (loc
,
6768 else if (c_parser_next_token_is (parser
, CPP_DOT
))
6771 c_parser_consume_token (parser
);
6772 if (c_parser_next_token_is_not (parser
,
6775 c_parser_error (parser
, "expected identifier");
6778 offsetof_ref
= build_component_ref
6780 c_parser_peek_token (parser
)->value
);
6781 c_parser_consume_token (parser
);
6786 loc
= c_parser_peek_token (parser
)->location
;
6787 c_parser_consume_token (parser
);
6788 idx
= c_parser_expression (parser
).value
;
6789 idx
= c_fully_fold (idx
, false, NULL
);
6790 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
6792 offsetof_ref
= build_array_ref (loc
, offsetof_ref
, idx
);
6797 c_parser_error (parser
, "expected identifier");
6798 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6800 expr
.value
= fold_offsetof (offsetof_ref
);
6803 case RID_CHOOSE_EXPR
:
6805 vec
<c_expr_t
, va_gc
> *cexpr_list
;
6806 c_expr_t
*e1_p
, *e2_p
, *e3_p
;
6809 c_parser_consume_token (parser
);
6810 if (!c_parser_get_builtin_args (parser
,
6811 "__builtin_choose_expr",
6814 expr
.value
= error_mark_node
;
6818 if (vec_safe_length (cexpr_list
) != 3)
6820 error_at (loc
, "wrong number of arguments to "
6821 "%<__builtin_choose_expr%>");
6822 expr
.value
= error_mark_node
;
6826 e1_p
= &(*cexpr_list
)[0];
6827 e2_p
= &(*cexpr_list
)[1];
6828 e3_p
= &(*cexpr_list
)[2];
6831 mark_exp_read (e2_p
->value
);
6832 mark_exp_read (e3_p
->value
);
6833 if (TREE_CODE (c
) != INTEGER_CST
6834 || !INTEGRAL_TYPE_P (TREE_TYPE (c
)))
6836 "first argument to %<__builtin_choose_expr%> not"
6838 constant_expression_warning (c
);
6839 expr
= integer_zerop (c
) ? *e3_p
: *e2_p
;
6842 case RID_TYPES_COMPATIBLE_P
:
6843 c_parser_consume_token (parser
);
6844 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6846 expr
.value
= error_mark_node
;
6849 t1
= c_parser_type_name (parser
);
6852 expr
.value
= error_mark_node
;
6855 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
6857 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6858 expr
.value
= error_mark_node
;
6861 t2
= c_parser_type_name (parser
);
6864 expr
.value
= error_mark_node
;
6867 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6871 e1
= groktypename (t1
, NULL
, NULL
);
6872 e2
= groktypename (t2
, NULL
, NULL
);
6873 if (e1
== error_mark_node
|| e2
== error_mark_node
)
6875 expr
.value
= error_mark_node
;
6879 e1
= TYPE_MAIN_VARIANT (e1
);
6880 e2
= TYPE_MAIN_VARIANT (e2
);
6883 = comptypes (e1
, e2
) ? integer_one_node
: integer_zero_node
;
6886 case RID_BUILTIN_COMPLEX
:
6888 vec
<c_expr_t
, va_gc
> *cexpr_list
;
6889 c_expr_t
*e1_p
, *e2_p
;
6891 c_parser_consume_token (parser
);
6892 if (!c_parser_get_builtin_args (parser
,
6893 "__builtin_complex",
6894 &cexpr_list
, false))
6896 expr
.value
= error_mark_node
;
6900 if (vec_safe_length (cexpr_list
) != 2)
6902 error_at (loc
, "wrong number of arguments to "
6903 "%<__builtin_complex%>");
6904 expr
.value
= error_mark_node
;
6908 e1_p
= &(*cexpr_list
)[0];
6909 e2_p
= &(*cexpr_list
)[1];
6911 mark_exp_read (e1_p
->value
);
6912 if (TREE_CODE (e1_p
->value
) == EXCESS_PRECISION_EXPR
)
6913 e1_p
->value
= convert (TREE_TYPE (e1_p
->value
),
6914 TREE_OPERAND (e1_p
->value
, 0));
6915 mark_exp_read (e2_p
->value
);
6916 if (TREE_CODE (e2_p
->value
) == EXCESS_PRECISION_EXPR
)
6917 e2_p
->value
= convert (TREE_TYPE (e2_p
->value
),
6918 TREE_OPERAND (e2_p
->value
, 0));
6919 if (!SCALAR_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
6920 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
6921 || !SCALAR_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
))
6922 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
)))
6924 error_at (loc
, "%<__builtin_complex%> operand "
6925 "not of real binary floating-point type");
6926 expr
.value
= error_mark_node
;
6929 if (TYPE_MAIN_VARIANT (TREE_TYPE (e1_p
->value
))
6930 != TYPE_MAIN_VARIANT (TREE_TYPE (e2_p
->value
)))
6933 "%<__builtin_complex%> operands of different types");
6934 expr
.value
= error_mark_node
;
6938 pedwarn (loc
, OPT_Wpedantic
,
6939 "ISO C90 does not support complex types");
6940 expr
.value
= build2 (COMPLEX_EXPR
,
6943 (TREE_TYPE (e1_p
->value
))),
6944 e1_p
->value
, e2_p
->value
);
6947 case RID_BUILTIN_SHUFFLE
:
6949 vec
<c_expr_t
, va_gc
> *cexpr_list
;
6953 c_parser_consume_token (parser
);
6954 if (!c_parser_get_builtin_args (parser
,
6955 "__builtin_shuffle",
6956 &cexpr_list
, false))
6958 expr
.value
= error_mark_node
;
6962 FOR_EACH_VEC_SAFE_ELT (cexpr_list
, i
, p
)
6963 mark_exp_read (p
->value
);
6965 if (vec_safe_length (cexpr_list
) == 2)
6967 c_build_vec_perm_expr
6968 (loc
, (*cexpr_list
)[0].value
,
6969 NULL_TREE
, (*cexpr_list
)[1].value
);
6971 else if (vec_safe_length (cexpr_list
) == 3)
6973 c_build_vec_perm_expr
6974 (loc
, (*cexpr_list
)[0].value
,
6975 (*cexpr_list
)[1].value
,
6976 (*cexpr_list
)[2].value
);
6979 error_at (loc
, "wrong number of arguments to "
6980 "%<__builtin_shuffle%>");
6981 expr
.value
= error_mark_node
;
6985 case RID_AT_SELECTOR
:
6986 gcc_assert (c_dialect_objc ());
6987 c_parser_consume_token (parser
);
6988 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6990 expr
.value
= error_mark_node
;
6994 tree sel
= c_parser_objc_selector_arg (parser
);
6995 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6997 expr
.value
= objc_build_selector_expr (loc
, sel
);
7000 case RID_AT_PROTOCOL
:
7001 gcc_assert (c_dialect_objc ());
7002 c_parser_consume_token (parser
);
7003 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7005 expr
.value
= error_mark_node
;
7008 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7010 c_parser_error (parser
, "expected identifier");
7011 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7012 expr
.value
= error_mark_node
;
7016 tree id
= c_parser_peek_token (parser
)->value
;
7017 c_parser_consume_token (parser
);
7018 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7020 expr
.value
= objc_build_protocol_expr (id
);
7024 /* Extension to support C-structures in the archiver. */
7025 gcc_assert (c_dialect_objc ());
7026 c_parser_consume_token (parser
);
7027 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7029 expr
.value
= error_mark_node
;
7032 t1
= c_parser_type_name (parser
);
7035 expr
.value
= error_mark_node
;
7036 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7039 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7042 tree type
= groktypename (t1
, NULL
, NULL
);
7043 expr
.value
= objc_build_encode_expr (type
);
7047 expr
= c_parser_generic_selection (parser
);
7050 c_parser_error (parser
, "expected expression");
7051 expr
.value
= error_mark_node
;
7055 case CPP_OPEN_SQUARE
:
7056 if (c_dialect_objc ())
7058 tree receiver
, args
;
7059 c_parser_consume_token (parser
);
7060 receiver
= c_parser_objc_receiver (parser
);
7061 args
= c_parser_objc_message_args (parser
);
7062 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
7064 expr
.value
= objc_build_message_expr (receiver
, args
);
7067 /* Else fall through to report error. */
7069 c_parser_error (parser
, "expected expression");
7070 expr
.value
= error_mark_node
;
7073 return c_parser_postfix_expression_after_primary (parser
, loc
, expr
);
7076 /* Parse a postfix expression after a parenthesized type name: the
7077 brace-enclosed initializer of a compound literal, possibly followed
7078 by some postfix operators. This is separate because it is not
7079 possible to tell until after the type name whether a cast
7080 expression has a cast or a compound literal, or whether the operand
7081 of sizeof is a parenthesized type name or starts with a compound
7082 literal. TYPE_LOC is the location where TYPE_NAME starts--the
7083 location of the first token after the parentheses around the type
7086 static struct c_expr
7087 c_parser_postfix_expression_after_paren_type (c_parser
*parser
,
7088 struct c_type_name
*type_name
,
7089 location_t type_loc
)
7095 location_t start_loc
;
7096 tree type_expr
= NULL_TREE
;
7097 bool type_expr_const
= true;
7098 check_compound_literal_type (type_loc
, type_name
);
7099 start_init (NULL_TREE
, NULL
, 0);
7100 type
= groktypename (type_name
, &type_expr
, &type_expr_const
);
7101 start_loc
= c_parser_peek_token (parser
)->location
;
7102 if (type
!= error_mark_node
&& C_TYPE_VARIABLE_SIZE (type
))
7104 error_at (type_loc
, "compound literal has variable size");
7105 type
= error_mark_node
;
7107 init
= c_parser_braced_init (parser
, type
, false);
7109 maybe_warn_string_init (type
, init
);
7111 if (type
!= error_mark_node
7112 && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type
))
7113 && current_function_decl
)
7115 error ("compound literal qualified by address-space qualifier");
7116 type
= error_mark_node
;
7120 pedwarn (start_loc
, OPT_Wpedantic
, "ISO C90 forbids compound literals");
7121 non_const
= ((init
.value
&& TREE_CODE (init
.value
) == CONSTRUCTOR
)
7122 ? CONSTRUCTOR_NON_CONST (init
.value
)
7123 : init
.original_code
== C_MAYBE_CONST_EXPR
);
7124 non_const
|= !type_expr_const
;
7125 expr
.value
= build_compound_literal (start_loc
, type
, init
.value
, non_const
);
7126 expr
.original_code
= ERROR_MARK
;
7127 expr
.original_type
= NULL
;
7130 if (TREE_CODE (expr
.value
) == C_MAYBE_CONST_EXPR
)
7132 gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr
.value
) == NULL_TREE
);
7133 C_MAYBE_CONST_EXPR_PRE (expr
.value
) = type_expr
;
7137 gcc_assert (!non_const
);
7138 expr
.value
= build2 (C_MAYBE_CONST_EXPR
, type
,
7139 type_expr
, expr
.value
);
7142 return c_parser_postfix_expression_after_primary (parser
, start_loc
, expr
);
7145 /* Callback function for sizeof_pointer_memaccess_warning to compare
7149 sizeof_ptr_memacc_comptypes (tree type1
, tree type2
)
7151 return comptypes (type1
, type2
) == 1;
7154 /* Parse a postfix expression after the initial primary or compound
7155 literal; that is, parse a series of postfix operators.
7157 EXPR_LOC is the location of the primary expression. */
7159 static struct c_expr
7160 c_parser_postfix_expression_after_primary (c_parser
*parser
,
7161 location_t expr_loc
,
7164 struct c_expr orig_expr
;
7166 location_t sizeof_arg_loc
[3];
7169 vec
<tree
, va_gc
> *exprlist
;
7170 vec
<tree
, va_gc
> *origtypes
= NULL
;
7173 location_t op_loc
= c_parser_peek_token (parser
)->location
;
7174 switch (c_parser_peek_token (parser
)->type
)
7176 case CPP_OPEN_SQUARE
:
7177 /* Array reference. */
7178 c_parser_consume_token (parser
);
7179 if (flag_enable_cilkplus
7180 && c_parser_peek_token (parser
)->type
== CPP_COLON
)
7181 /* If we are here, then we have something like this:
7184 expr
.value
= c_parser_array_notation (expr_loc
, parser
, NULL_TREE
,
7188 idx
= c_parser_expression (parser
).value
;
7189 /* Here we have 3 options:
7190 1. Array [EXPR] -- Normal Array call.
7191 2. Array [EXPR : EXPR] -- Array notation without stride.
7192 3. Array [EXPR : EXPR : EXPR] -- Array notation with stride.
7194 For 1, we just handle it just like a normal array expression.
7195 For 2 and 3 we handle it like we handle array notations. The
7196 idx value we have above becomes the initial/start index.
7198 if (flag_enable_cilkplus
7199 && c_parser_peek_token (parser
)->type
== CPP_COLON
)
7200 expr
.value
= c_parser_array_notation (expr_loc
, parser
, idx
,
7204 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
7206 expr
.value
= build_array_ref (op_loc
, expr
.value
, idx
);
7209 expr
.original_code
= ERROR_MARK
;
7210 expr
.original_type
= NULL
;
7212 case CPP_OPEN_PAREN
:
7213 /* Function call. */
7214 c_parser_consume_token (parser
);
7215 for (i
= 0; i
< 3; i
++)
7217 sizeof_arg
[i
] = NULL_TREE
;
7218 sizeof_arg_loc
[i
] = UNKNOWN_LOCATION
;
7220 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
7223 exprlist
= c_parser_expr_list (parser
, true, false, &origtypes
,
7224 sizeof_arg_loc
, sizeof_arg
);
7225 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7228 mark_exp_read (expr
.value
);
7229 if (warn_sizeof_pointer_memaccess
)
7230 sizeof_pointer_memaccess_warning (sizeof_arg_loc
,
7231 expr
.value
, exprlist
,
7233 sizeof_ptr_memacc_comptypes
);
7234 /* FIXME diagnostics: Ideally we want the FUNCNAME, not the
7235 "(" after the FUNCNAME, which is what we have now. */
7236 expr
.value
= build_function_call_vec (op_loc
, expr
.value
, exprlist
,
7238 expr
.original_code
= ERROR_MARK
;
7239 if (TREE_CODE (expr
.value
) == INTEGER_CST
7240 && TREE_CODE (orig_expr
.value
) == FUNCTION_DECL
7241 && DECL_BUILT_IN_CLASS (orig_expr
.value
) == BUILT_IN_NORMAL
7242 && DECL_FUNCTION_CODE (orig_expr
.value
) == BUILT_IN_CONSTANT_P
)
7243 expr
.original_code
= C_MAYBE_CONST_EXPR
;
7244 expr
.original_type
= NULL
;
7247 release_tree_vector (exprlist
);
7248 release_tree_vector (origtypes
);
7252 /* Structure element reference. */
7253 c_parser_consume_token (parser
);
7254 expr
= default_function_array_conversion (expr_loc
, expr
);
7255 if (c_parser_next_token_is (parser
, CPP_NAME
))
7256 ident
= c_parser_peek_token (parser
)->value
;
7259 c_parser_error (parser
, "expected identifier");
7260 expr
.value
= error_mark_node
;
7261 expr
.original_code
= ERROR_MARK
;
7262 expr
.original_type
= NULL
;
7265 c_parser_consume_token (parser
);
7266 expr
.value
= build_component_ref (op_loc
, expr
.value
, ident
);
7267 expr
.original_code
= ERROR_MARK
;
7268 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
7269 expr
.original_type
= NULL
;
7272 /* Remember the original type of a bitfield. */
7273 tree field
= TREE_OPERAND (expr
.value
, 1);
7274 if (TREE_CODE (field
) != FIELD_DECL
)
7275 expr
.original_type
= NULL
;
7277 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
7281 /* Structure element reference. */
7282 c_parser_consume_token (parser
);
7283 expr
= default_function_array_conversion (expr_loc
, expr
);
7284 if (c_parser_next_token_is (parser
, CPP_NAME
))
7285 ident
= c_parser_peek_token (parser
)->value
;
7288 c_parser_error (parser
, "expected identifier");
7289 expr
.value
= error_mark_node
;
7290 expr
.original_code
= ERROR_MARK
;
7291 expr
.original_type
= NULL
;
7294 c_parser_consume_token (parser
);
7295 expr
.value
= build_component_ref (op_loc
,
7296 build_indirect_ref (op_loc
,
7300 expr
.original_code
= ERROR_MARK
;
7301 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
7302 expr
.original_type
= NULL
;
7305 /* Remember the original type of a bitfield. */
7306 tree field
= TREE_OPERAND (expr
.value
, 1);
7307 if (TREE_CODE (field
) != FIELD_DECL
)
7308 expr
.original_type
= NULL
;
7310 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
7314 /* Postincrement. */
7315 c_parser_consume_token (parser
);
7316 /* If the expressions have array notations, we expand them. */
7317 if (flag_enable_cilkplus
7318 && TREE_CODE (expr
.value
) == ARRAY_NOTATION_REF
)
7319 expr
= fix_array_notation_expr (expr_loc
, POSTINCREMENT_EXPR
, expr
);
7322 expr
= default_function_array_read_conversion (expr_loc
, expr
);
7323 expr
.value
= build_unary_op (op_loc
,
7324 POSTINCREMENT_EXPR
, expr
.value
, 0);
7326 expr
.original_code
= ERROR_MARK
;
7327 expr
.original_type
= NULL
;
7329 case CPP_MINUS_MINUS
:
7330 /* Postdecrement. */
7331 c_parser_consume_token (parser
);
7332 /* If the expressions have array notations, we expand them. */
7333 if (flag_enable_cilkplus
7334 && TREE_CODE (expr
.value
) == ARRAY_NOTATION_REF
)
7335 expr
= fix_array_notation_expr (expr_loc
, POSTDECREMENT_EXPR
, expr
);
7338 expr
= default_function_array_read_conversion (expr_loc
, expr
);
7339 expr
.value
= build_unary_op (op_loc
,
7340 POSTDECREMENT_EXPR
, expr
.value
, 0);
7342 expr
.original_code
= ERROR_MARK
;
7343 expr
.original_type
= NULL
;
7351 /* Parse an expression (C90 6.3.17, C99 6.5.17).
7354 assignment-expression
7355 expression , assignment-expression
7358 static struct c_expr
7359 c_parser_expression (c_parser
*parser
)
7362 expr
= c_parser_expr_no_commas (parser
, NULL
);
7363 while (c_parser_next_token_is (parser
, CPP_COMMA
))
7367 location_t loc
= c_parser_peek_token (parser
)->location
;
7368 location_t expr_loc
;
7369 c_parser_consume_token (parser
);
7370 expr_loc
= c_parser_peek_token (parser
)->location
;
7371 lhsval
= expr
.value
;
7372 while (TREE_CODE (lhsval
) == COMPOUND_EXPR
)
7373 lhsval
= TREE_OPERAND (lhsval
, 1);
7374 if (DECL_P (lhsval
) || handled_component_p (lhsval
))
7375 mark_exp_read (lhsval
);
7376 next
= c_parser_expr_no_commas (parser
, NULL
);
7377 next
= default_function_array_conversion (expr_loc
, next
);
7378 expr
.value
= build_compound_expr (loc
, expr
.value
, next
.value
);
7379 expr
.original_code
= COMPOUND_EXPR
;
7380 expr
.original_type
= next
.original_type
;
7385 /* Parse an expression and convert functions or arrays to
7388 static struct c_expr
7389 c_parser_expression_conv (c_parser
*parser
)
7392 location_t loc
= c_parser_peek_token (parser
)->location
;
7393 expr
= c_parser_expression (parser
);
7394 expr
= default_function_array_conversion (loc
, expr
);
7398 /* Parse a non-empty list of expressions. If CONVERT_P, convert
7399 functions and arrays to pointers. If FOLD_P, fold the expressions.
7402 assignment-expression
7403 nonempty-expr-list , assignment-expression
7406 static vec
<tree
, va_gc
> *
7407 c_parser_expr_list (c_parser
*parser
, bool convert_p
, bool fold_p
,
7408 vec
<tree
, va_gc
> **p_orig_types
,
7409 location_t
*sizeof_arg_loc
, tree
*sizeof_arg
)
7411 vec
<tree
, va_gc
> *ret
;
7412 vec
<tree
, va_gc
> *orig_types
;
7414 location_t loc
= c_parser_peek_token (parser
)->location
;
7415 location_t cur_sizeof_arg_loc
= UNKNOWN_LOCATION
;
7416 unsigned int idx
= 0;
7418 ret
= make_tree_vector ();
7419 if (p_orig_types
== NULL
)
7422 orig_types
= make_tree_vector ();
7424 if (sizeof_arg
!= NULL
7425 && c_parser_next_token_is_keyword (parser
, RID_SIZEOF
))
7426 cur_sizeof_arg_loc
= c_parser_peek_2nd_token (parser
)->location
;
7427 expr
= c_parser_expr_no_commas (parser
, NULL
);
7429 expr
= default_function_array_read_conversion (loc
, expr
);
7431 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
7432 ret
->quick_push (expr
.value
);
7434 orig_types
->quick_push (expr
.original_type
);
7435 if (sizeof_arg
!= NULL
7436 && cur_sizeof_arg_loc
!= UNKNOWN_LOCATION
7437 && expr
.original_code
== SIZEOF_EXPR
)
7439 sizeof_arg
[0] = c_last_sizeof_arg
;
7440 sizeof_arg_loc
[0] = cur_sizeof_arg_loc
;
7442 while (c_parser_next_token_is (parser
, CPP_COMMA
))
7444 c_parser_consume_token (parser
);
7445 loc
= c_parser_peek_token (parser
)->location
;
7446 if (sizeof_arg
!= NULL
7447 && c_parser_next_token_is_keyword (parser
, RID_SIZEOF
))
7448 cur_sizeof_arg_loc
= c_parser_peek_2nd_token (parser
)->location
;
7450 cur_sizeof_arg_loc
= UNKNOWN_LOCATION
;
7451 expr
= c_parser_expr_no_commas (parser
, NULL
);
7453 expr
= default_function_array_read_conversion (loc
, expr
);
7455 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
7456 vec_safe_push (ret
, expr
.value
);
7458 vec_safe_push (orig_types
, expr
.original_type
);
7460 && sizeof_arg
!= NULL
7461 && cur_sizeof_arg_loc
!= UNKNOWN_LOCATION
7462 && expr
.original_code
== SIZEOF_EXPR
)
7464 sizeof_arg
[idx
] = c_last_sizeof_arg
;
7465 sizeof_arg_loc
[idx
] = cur_sizeof_arg_loc
;
7469 *p_orig_types
= orig_types
;
7473 /* Parse Objective-C-specific constructs. */
7475 /* Parse an objc-class-definition.
7477 objc-class-definition:
7478 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
7479 objc-class-instance-variables[opt] objc-methodprotolist @end
7480 @implementation identifier objc-superclass[opt]
7481 objc-class-instance-variables[opt]
7482 @interface identifier ( identifier ) objc-protocol-refs[opt]
7483 objc-methodprotolist @end
7484 @interface identifier ( ) objc-protocol-refs[opt]
7485 objc-methodprotolist @end
7486 @implementation identifier ( identifier )
7491 "@interface identifier (" must start "@interface identifier (
7492 identifier ) ...": objc-methodprotolist in the first production may
7493 not start with a parenthesized identifier as a declarator of a data
7494 definition with no declaration specifiers if the objc-superclass,
7495 objc-protocol-refs and objc-class-instance-variables are omitted. */
7498 c_parser_objc_class_definition (c_parser
*parser
, tree attributes
)
7503 if (c_parser_next_token_is_keyword (parser
, RID_AT_INTERFACE
))
7505 else if (c_parser_next_token_is_keyword (parser
, RID_AT_IMPLEMENTATION
))
7510 c_parser_consume_token (parser
);
7511 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7513 c_parser_error (parser
, "expected identifier");
7516 id1
= c_parser_peek_token (parser
)->value
;
7517 c_parser_consume_token (parser
);
7518 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
7520 /* We have a category or class extension. */
7522 tree proto
= NULL_TREE
;
7523 c_parser_consume_token (parser
);
7524 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7526 if (iface_p
&& c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
7528 /* We have a class extension. */
7533 c_parser_error (parser
, "expected identifier or %<)%>");
7534 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7540 id2
= c_parser_peek_token (parser
)->value
;
7541 c_parser_consume_token (parser
);
7543 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7546 objc_start_category_implementation (id1
, id2
);
7549 if (c_parser_next_token_is (parser
, CPP_LESS
))
7550 proto
= c_parser_objc_protocol_refs (parser
);
7551 objc_start_category_interface (id1
, id2
, proto
, attributes
);
7552 c_parser_objc_methodprotolist (parser
);
7553 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
7554 objc_finish_interface ();
7557 if (c_parser_next_token_is (parser
, CPP_COLON
))
7559 c_parser_consume_token (parser
);
7560 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7562 c_parser_error (parser
, "expected identifier");
7565 superclass
= c_parser_peek_token (parser
)->value
;
7566 c_parser_consume_token (parser
);
7569 superclass
= NULL_TREE
;
7572 tree proto
= NULL_TREE
;
7573 if (c_parser_next_token_is (parser
, CPP_LESS
))
7574 proto
= c_parser_objc_protocol_refs (parser
);
7575 objc_start_class_interface (id1
, superclass
, proto
, attributes
);
7578 objc_start_class_implementation (id1
, superclass
);
7579 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
7580 c_parser_objc_class_instance_variables (parser
);
7583 objc_continue_interface ();
7584 c_parser_objc_methodprotolist (parser
);
7585 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
7586 objc_finish_interface ();
7590 objc_continue_implementation ();
7595 /* Parse objc-class-instance-variables.
7597 objc-class-instance-variables:
7598 { objc-instance-variable-decl-list[opt] }
7600 objc-instance-variable-decl-list:
7601 objc-visibility-spec
7602 objc-instance-variable-decl ;
7604 objc-instance-variable-decl-list objc-visibility-spec
7605 objc-instance-variable-decl-list objc-instance-variable-decl ;
7606 objc-instance-variable-decl-list ;
7608 objc-visibility-spec:
7613 objc-instance-variable-decl:
7618 c_parser_objc_class_instance_variables (c_parser
*parser
)
7620 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
7621 c_parser_consume_token (parser
);
7622 while (c_parser_next_token_is_not (parser
, CPP_EOF
))
7625 /* Parse any stray semicolon. */
7626 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
7628 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
7630 c_parser_consume_token (parser
);
7633 /* Stop if at the end of the instance variables. */
7634 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
7636 c_parser_consume_token (parser
);
7639 /* Parse any objc-visibility-spec. */
7640 if (c_parser_next_token_is_keyword (parser
, RID_AT_PRIVATE
))
7642 c_parser_consume_token (parser
);
7643 objc_set_visibility (OBJC_IVAR_VIS_PRIVATE
);
7646 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROTECTED
))
7648 c_parser_consume_token (parser
);
7649 objc_set_visibility (OBJC_IVAR_VIS_PROTECTED
);
7652 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PUBLIC
))
7654 c_parser_consume_token (parser
);
7655 objc_set_visibility (OBJC_IVAR_VIS_PUBLIC
);
7658 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PACKAGE
))
7660 c_parser_consume_token (parser
);
7661 objc_set_visibility (OBJC_IVAR_VIS_PACKAGE
);
7664 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
7666 c_parser_pragma (parser
, pragma_external
);
7670 /* Parse some comma-separated declarations. */
7671 decls
= c_parser_struct_declaration (parser
);
7674 /* There is a syntax error. We want to skip the offending
7675 tokens up to the next ';' (included) or '}'
7678 /* First, skip manually a ')' or ']'. This is because they
7679 reduce the nesting level, so c_parser_skip_until_found()
7680 wouldn't be able to skip past them. */
7681 c_token
*token
= c_parser_peek_token (parser
);
7682 if (token
->type
== CPP_CLOSE_PAREN
|| token
->type
== CPP_CLOSE_SQUARE
)
7683 c_parser_consume_token (parser
);
7685 /* Then, do the standard skipping. */
7686 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
7688 /* We hopefully recovered. Start normal parsing again. */
7689 parser
->error
= false;
7694 /* Comma-separated instance variables are chained together
7695 in reverse order; add them one by one. */
7696 tree ivar
= nreverse (decls
);
7697 for (; ivar
; ivar
= DECL_CHAIN (ivar
))
7698 objc_add_instance_variable (copy_node (ivar
));
7700 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7704 /* Parse an objc-class-declaration.
7706 objc-class-declaration:
7707 @class identifier-list ;
7711 c_parser_objc_class_declaration (c_parser
*parser
)
7713 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_CLASS
));
7714 c_parser_consume_token (parser
);
7715 /* Any identifiers, including those declared as type names, are OK
7720 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7722 c_parser_error (parser
, "expected identifier");
7723 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
7724 parser
->error
= false;
7727 id
= c_parser_peek_token (parser
)->value
;
7728 objc_declare_class (id
);
7729 c_parser_consume_token (parser
);
7730 if (c_parser_next_token_is (parser
, CPP_COMMA
))
7731 c_parser_consume_token (parser
);
7735 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7738 /* Parse an objc-alias-declaration.
7740 objc-alias-declaration:
7741 @compatibility_alias identifier identifier ;
7745 c_parser_objc_alias_declaration (c_parser
*parser
)
7748 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_ALIAS
));
7749 c_parser_consume_token (parser
);
7750 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7752 c_parser_error (parser
, "expected identifier");
7753 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
7756 id1
= c_parser_peek_token (parser
)->value
;
7757 c_parser_consume_token (parser
);
7758 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7760 c_parser_error (parser
, "expected identifier");
7761 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
7764 id2
= c_parser_peek_token (parser
)->value
;
7765 c_parser_consume_token (parser
);
7766 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7767 objc_declare_alias (id1
, id2
);
7770 /* Parse an objc-protocol-definition.
7772 objc-protocol-definition:
7773 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
7774 @protocol identifier-list ;
7776 "@protocol identifier ;" should be resolved as "@protocol
7777 identifier-list ;": objc-methodprotolist may not start with a
7778 semicolon in the first alternative if objc-protocol-refs are
7782 c_parser_objc_protocol_definition (c_parser
*parser
, tree attributes
)
7784 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROTOCOL
));
7786 c_parser_consume_token (parser
);
7787 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7789 c_parser_error (parser
, "expected identifier");
7792 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
7793 || c_parser_peek_2nd_token (parser
)->type
== CPP_SEMICOLON
)
7795 /* Any identifiers, including those declared as type names, are
7800 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7802 c_parser_error (parser
, "expected identifier");
7805 id
= c_parser_peek_token (parser
)->value
;
7806 objc_declare_protocol (id
, attributes
);
7807 c_parser_consume_token (parser
);
7808 if (c_parser_next_token_is (parser
, CPP_COMMA
))
7809 c_parser_consume_token (parser
);
7813 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7817 tree id
= c_parser_peek_token (parser
)->value
;
7818 tree proto
= NULL_TREE
;
7819 c_parser_consume_token (parser
);
7820 if (c_parser_next_token_is (parser
, CPP_LESS
))
7821 proto
= c_parser_objc_protocol_refs (parser
);
7822 parser
->objc_pq_context
= true;
7823 objc_start_protocol (id
, proto
, attributes
);
7824 c_parser_objc_methodprotolist (parser
);
7825 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
7826 parser
->objc_pq_context
= false;
7827 objc_finish_interface ();
7831 /* Parse an objc-method-type.
7837 Return true if it is a class method (+) and false if it is
7838 an instance method (-).
7841 c_parser_objc_method_type (c_parser
*parser
)
7843 switch (c_parser_peek_token (parser
)->type
)
7846 c_parser_consume_token (parser
);
7849 c_parser_consume_token (parser
);
7856 /* Parse an objc-method-definition.
7858 objc-method-definition:
7859 objc-method-type objc-method-decl ;[opt] compound-statement
7863 c_parser_objc_method_definition (c_parser
*parser
)
7865 bool is_class_method
= c_parser_objc_method_type (parser
);
7866 tree decl
, attributes
= NULL_TREE
, expr
= NULL_TREE
;
7867 parser
->objc_pq_context
= true;
7868 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
7870 if (decl
== error_mark_node
)
7871 return; /* Bail here. */
7873 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
7875 c_parser_consume_token (parser
);
7876 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
7877 "extra semicolon in method definition specified");
7880 if (!c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
7882 c_parser_error (parser
, "expected %<{%>");
7886 parser
->objc_pq_context
= false;
7887 if (objc_start_method_definition (is_class_method
, decl
, attributes
, expr
))
7889 add_stmt (c_parser_compound_statement (parser
));
7890 objc_finish_method_definition (current_function_decl
);
7894 /* This code is executed when we find a method definition
7895 outside of an @implementation context (or invalid for other
7896 reasons). Parse the method (to keep going) but do not emit
7899 c_parser_compound_statement (parser
);
7903 /* Parse an objc-methodprotolist.
7905 objc-methodprotolist:
7907 objc-methodprotolist objc-methodproto
7908 objc-methodprotolist declaration
7909 objc-methodprotolist ;
7913 The declaration is a data definition, which may be missing
7914 declaration specifiers under the same rules and diagnostics as
7915 other data definitions outside functions, and the stray semicolon
7916 is diagnosed the same way as a stray semicolon outside a
7920 c_parser_objc_methodprotolist (c_parser
*parser
)
7924 /* The list is terminated by @end. */
7925 switch (c_parser_peek_token (parser
)->type
)
7928 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
7929 "ISO C does not allow extra %<;%> outside of a function");
7930 c_parser_consume_token (parser
);
7934 c_parser_objc_methodproto (parser
);
7937 c_parser_pragma (parser
, pragma_external
);
7942 if (c_parser_next_token_is_keyword (parser
, RID_AT_END
))
7944 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
))
7945 c_parser_objc_at_property_declaration (parser
);
7946 else if (c_parser_next_token_is_keyword (parser
, RID_AT_OPTIONAL
))
7948 objc_set_method_opt (true);
7949 c_parser_consume_token (parser
);
7951 else if (c_parser_next_token_is_keyword (parser
, RID_AT_REQUIRED
))
7953 objc_set_method_opt (false);
7954 c_parser_consume_token (parser
);
7957 c_parser_declaration_or_fndef (parser
, false, false, true,
7964 /* Parse an objc-methodproto.
7967 objc-method-type objc-method-decl ;
7971 c_parser_objc_methodproto (c_parser
*parser
)
7973 bool is_class_method
= c_parser_objc_method_type (parser
);
7974 tree decl
, attributes
= NULL_TREE
;
7976 /* Remember protocol qualifiers in prototypes. */
7977 parser
->objc_pq_context
= true;
7978 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
7980 /* Forget protocol qualifiers now. */
7981 parser
->objc_pq_context
= false;
7983 /* Do not allow the presence of attributes to hide an erroneous
7984 method implementation in the interface section. */
7985 if (!c_parser_next_token_is (parser
, CPP_SEMICOLON
))
7987 c_parser_error (parser
, "expected %<;%>");
7991 if (decl
!= error_mark_node
)
7992 objc_add_method_declaration (is_class_method
, decl
, attributes
);
7994 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7997 /* If we are at a position that method attributes may be present, check that
7998 there are not any parsed already (a syntax error) and then collect any
7999 specified at the current location. Finally, if new attributes were present,
8000 check that the next token is legal ( ';' for decls and '{' for defs). */
8003 c_parser_objc_maybe_method_attributes (c_parser
* parser
, tree
* attributes
)
8008 c_parser_error (parser
,
8009 "method attributes must be specified at the end only");
8010 *attributes
= NULL_TREE
;
8014 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
8015 *attributes
= c_parser_attributes (parser
);
8017 /* If there were no attributes here, just report any earlier error. */
8018 if (*attributes
== NULL_TREE
|| bad
)
8021 /* If the attributes are followed by a ; or {, then just report any earlier
8023 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
8024 || c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
8027 /* We've got attributes, but not at the end. */
8028 c_parser_error (parser
,
8029 "expected %<;%> or %<{%> after method attribute definition");
8033 /* Parse an objc-method-decl.
8036 ( objc-type-name ) objc-selector
8038 ( objc-type-name ) objc-keyword-selector objc-optparmlist
8039 objc-keyword-selector objc-optparmlist
8042 objc-keyword-selector:
8044 objc-keyword-selector objc-keyword-decl
8047 objc-selector : ( objc-type-name ) identifier
8048 objc-selector : identifier
8049 : ( objc-type-name ) identifier
8053 objc-optparms objc-optellipsis
8057 objc-opt-parms , parameter-declaration
8065 c_parser_objc_method_decl (c_parser
*parser
, bool is_class_method
,
8066 tree
*attributes
, tree
*expr
)
8068 tree type
= NULL_TREE
;
8070 tree parms
= NULL_TREE
;
8071 bool ellipsis
= false;
8072 bool attr_err
= false;
8074 *attributes
= NULL_TREE
;
8075 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8077 c_parser_consume_token (parser
);
8078 type
= c_parser_objc_type_name (parser
);
8079 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8081 sel
= c_parser_objc_selector (parser
);
8082 /* If there is no selector, or a colon follows, we have an
8083 objc-keyword-selector. If there is a selector, and a colon does
8084 not follow, that selector ends the objc-method-decl. */
8085 if (!sel
|| c_parser_next_token_is (parser
, CPP_COLON
))
8088 tree list
= NULL_TREE
;
8091 tree atype
= NULL_TREE
, id
, keyworddecl
;
8092 tree param_attr
= NULL_TREE
;
8093 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
8095 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8097 c_parser_consume_token (parser
);
8098 atype
= c_parser_objc_type_name (parser
);
8099 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
8102 /* New ObjC allows attributes on method parameters. */
8103 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
8104 param_attr
= c_parser_attributes (parser
);
8105 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8107 c_parser_error (parser
, "expected identifier");
8108 return error_mark_node
;
8110 id
= c_parser_peek_token (parser
)->value
;
8111 c_parser_consume_token (parser
);
8112 keyworddecl
= objc_build_keyword_decl (tsel
, atype
, id
, param_attr
);
8113 list
= chainon (list
, keyworddecl
);
8114 tsel
= c_parser_objc_selector (parser
);
8115 if (!tsel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
8119 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
8121 /* Parse the optional parameter list. Optional Objective-C
8122 method parameters follow the C syntax, and may include '...'
8123 to denote a variable number of arguments. */
8124 parms
= make_node (TREE_LIST
);
8125 while (c_parser_next_token_is (parser
, CPP_COMMA
))
8127 struct c_parm
*parm
;
8128 c_parser_consume_token (parser
);
8129 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
8132 c_parser_consume_token (parser
);
8133 attr_err
|= c_parser_objc_maybe_method_attributes
8134 (parser
, attributes
) ;
8137 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
8140 parms
= chainon (parms
,
8141 build_tree_list (NULL_TREE
, grokparm (parm
, expr
)));
8146 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
8150 c_parser_error (parser
, "objective-c method declaration is expected");
8151 return error_mark_node
;
8155 return error_mark_node
;
8157 return objc_build_method_signature (is_class_method
, type
, sel
, parms
, ellipsis
);
8160 /* Parse an objc-type-name.
8163 objc-type-qualifiers[opt] type-name
8164 objc-type-qualifiers[opt]
8166 objc-type-qualifiers:
8168 objc-type-qualifiers objc-type-qualifier
8170 objc-type-qualifier: one of
8171 in out inout bycopy byref oneway
8175 c_parser_objc_type_name (c_parser
*parser
)
8177 tree quals
= NULL_TREE
;
8178 struct c_type_name
*type_name
= NULL
;
8179 tree type
= NULL_TREE
;
8182 c_token
*token
= c_parser_peek_token (parser
);
8183 if (token
->type
== CPP_KEYWORD
8184 && (token
->keyword
== RID_IN
8185 || token
->keyword
== RID_OUT
8186 || token
->keyword
== RID_INOUT
8187 || token
->keyword
== RID_BYCOPY
8188 || token
->keyword
== RID_BYREF
8189 || token
->keyword
== RID_ONEWAY
))
8191 quals
= chainon (build_tree_list (NULL_TREE
, token
->value
), quals
);
8192 c_parser_consume_token (parser
);
8197 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
8198 type_name
= c_parser_type_name (parser
);
8200 type
= groktypename (type_name
, NULL
, NULL
);
8202 /* If the type is unknown, and error has already been produced and
8203 we need to recover from the error. In that case, use NULL_TREE
8204 for the type, as if no type had been specified; this will use the
8205 default type ('id') which is good for error recovery. */
8206 if (type
== error_mark_node
)
8209 return build_tree_list (quals
, type
);
8212 /* Parse objc-protocol-refs.
8219 c_parser_objc_protocol_refs (c_parser
*parser
)
8221 tree list
= NULL_TREE
;
8222 gcc_assert (c_parser_next_token_is (parser
, CPP_LESS
));
8223 c_parser_consume_token (parser
);
8224 /* Any identifiers, including those declared as type names, are OK
8229 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8231 c_parser_error (parser
, "expected identifier");
8234 id
= c_parser_peek_token (parser
)->value
;
8235 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
8236 c_parser_consume_token (parser
);
8237 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8238 c_parser_consume_token (parser
);
8242 c_parser_require (parser
, CPP_GREATER
, "expected %<>%>");
8246 /* Parse an objc-try-catch-finally-statement.
8248 objc-try-catch-finally-statement:
8249 @try compound-statement objc-catch-list[opt]
8250 @try compound-statement objc-catch-list[opt] @finally compound-statement
8253 @catch ( objc-catch-parameter-declaration ) compound-statement
8254 objc-catch-list @catch ( objc-catch-parameter-declaration ) compound-statement
8256 objc-catch-parameter-declaration:
8257 parameter-declaration
8260 where '...' is to be interpreted literally, that is, it means CPP_ELLIPSIS.
8262 PS: This function is identical to cp_parser_objc_try_catch_finally_statement
8263 for C++. Keep them in sync. */
8266 c_parser_objc_try_catch_finally_statement (c_parser
*parser
)
8268 location_t location
;
8271 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_TRY
));
8272 c_parser_consume_token (parser
);
8273 location
= c_parser_peek_token (parser
)->location
;
8274 objc_maybe_warn_exceptions (location
);
8275 stmt
= c_parser_compound_statement (parser
);
8276 objc_begin_try_stmt (location
, stmt
);
8278 while (c_parser_next_token_is_keyword (parser
, RID_AT_CATCH
))
8280 struct c_parm
*parm
;
8281 tree parameter_declaration
= error_mark_node
;
8282 bool seen_open_paren
= false;
8284 c_parser_consume_token (parser
);
8285 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8286 seen_open_paren
= true;
8287 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
8289 /* We have "@catch (...)" (where the '...' are literally
8290 what is in the code). Skip the '...'.
8291 parameter_declaration is set to NULL_TREE, and
8292 objc_being_catch_clauses() knows that that means
8294 c_parser_consume_token (parser
);
8295 parameter_declaration
= NULL_TREE
;
8299 /* We have "@catch (NSException *exception)" or something
8300 like that. Parse the parameter declaration. */
8301 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
8303 parameter_declaration
= error_mark_node
;
8305 parameter_declaration
= grokparm (parm
, NULL
);
8307 if (seen_open_paren
)
8308 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8311 /* If there was no open parenthesis, we are recovering from
8312 an error, and we are trying to figure out what mistake
8313 the user has made. */
8315 /* If there is an immediate closing parenthesis, the user
8316 probably forgot the opening one (ie, they typed "@catch
8317 NSException *e)". Parse the closing parenthesis and keep
8319 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
8320 c_parser_consume_token (parser
);
8322 /* If these is no immediate closing parenthesis, the user
8323 probably doesn't know that parenthesis are required at
8324 all (ie, they typed "@catch NSException *e"). So, just
8325 forget about the closing parenthesis and keep going. */
8327 objc_begin_catch_clause (parameter_declaration
);
8328 if (c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
8329 c_parser_compound_statement_nostart (parser
);
8330 objc_finish_catch_clause ();
8332 if (c_parser_next_token_is_keyword (parser
, RID_AT_FINALLY
))
8334 c_parser_consume_token (parser
);
8335 location
= c_parser_peek_token (parser
)->location
;
8336 stmt
= c_parser_compound_statement (parser
);
8337 objc_build_finally_clause (location
, stmt
);
8339 objc_finish_try_stmt ();
8342 /* Parse an objc-synchronized-statement.
8344 objc-synchronized-statement:
8345 @synchronized ( expression ) compound-statement
8349 c_parser_objc_synchronized_statement (c_parser
*parser
)
8353 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNCHRONIZED
));
8354 c_parser_consume_token (parser
);
8355 loc
= c_parser_peek_token (parser
)->location
;
8356 objc_maybe_warn_exceptions (loc
);
8357 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8359 expr
= c_parser_expression (parser
).value
;
8360 expr
= c_fully_fold (expr
, false, NULL
);
8361 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8364 expr
= error_mark_node
;
8365 stmt
= c_parser_compound_statement (parser
);
8366 objc_build_synchronized (loc
, expr
, stmt
);
8369 /* Parse an objc-selector; return NULL_TREE without an error if the
8370 next token is not an objc-selector.
8375 enum struct union if else while do for switch case default
8376 break continue return goto asm sizeof typeof __alignof
8377 unsigned long const short volatile signed restrict _Complex
8378 in out inout bycopy byref oneway int char float double void _Bool
8380 ??? Why this selection of keywords but not, for example, storage
8381 class specifiers? */
8384 c_parser_objc_selector (c_parser
*parser
)
8386 c_token
*token
= c_parser_peek_token (parser
);
8387 tree value
= token
->value
;
8388 if (token
->type
== CPP_NAME
)
8390 c_parser_consume_token (parser
);
8393 if (token
->type
!= CPP_KEYWORD
)
8395 switch (token
->keyword
)
8437 c_parser_consume_token (parser
);
8444 /* Parse an objc-selector-arg.
8448 objc-keywordname-list
8450 objc-keywordname-list:
8452 objc-keywordname-list objc-keywordname
8460 c_parser_objc_selector_arg (c_parser
*parser
)
8462 tree sel
= c_parser_objc_selector (parser
);
8463 tree list
= NULL_TREE
;
8464 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
8468 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
8470 list
= chainon (list
, build_tree_list (sel
, NULL_TREE
));
8471 sel
= c_parser_objc_selector (parser
);
8472 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
8478 /* Parse an objc-receiver.
8487 c_parser_objc_receiver (c_parser
*parser
)
8489 if (c_parser_peek_token (parser
)->type
== CPP_NAME
8490 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
8491 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
8493 tree id
= c_parser_peek_token (parser
)->value
;
8494 c_parser_consume_token (parser
);
8495 return objc_get_class_reference (id
);
8497 return c_fully_fold (c_parser_expression (parser
).value
, false, NULL
);
8500 /* Parse objc-message-args.
8504 objc-keywordarg-list
8506 objc-keywordarg-list:
8508 objc-keywordarg-list objc-keywordarg
8511 objc-selector : objc-keywordexpr
8516 c_parser_objc_message_args (c_parser
*parser
)
8518 tree sel
= c_parser_objc_selector (parser
);
8519 tree list
= NULL_TREE
;
8520 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
8525 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
8526 return error_mark_node
;
8527 keywordexpr
= c_parser_objc_keywordexpr (parser
);
8528 list
= chainon (list
, build_tree_list (sel
, keywordexpr
));
8529 sel
= c_parser_objc_selector (parser
);
8530 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
8536 /* Parse an objc-keywordexpr.
8543 c_parser_objc_keywordexpr (c_parser
*parser
)
8546 vec
<tree
, va_gc
> *expr_list
= c_parser_expr_list (parser
, true, true,
8548 if (vec_safe_length (expr_list
) == 1)
8550 /* Just return the expression, remove a level of
8552 ret
= (*expr_list
)[0];
8556 /* We have a comma expression, we will collapse later. */
8557 ret
= build_tree_list_vec (expr_list
);
8559 release_tree_vector (expr_list
);
8563 /* A check, needed in several places, that ObjC interface, implementation or
8564 method definitions are not prefixed by incorrect items. */
8566 c_parser_objc_diagnose_bad_element_prefix (c_parser
*parser
,
8567 struct c_declspecs
*specs
)
8569 if (!specs
->declspecs_seen_p
|| specs
->non_sc_seen_p
8570 || specs
->typespec_kind
!= ctsk_none
)
8572 c_parser_error (parser
,
8573 "no type or storage class may be specified here,");
8574 c_parser_skip_to_end_of_block_or_statement (parser
);
8580 /* Parse an Objective-C @property declaration. The syntax is:
8582 objc-property-declaration:
8583 '@property' objc-property-attributes[opt] struct-declaration ;
8585 objc-property-attributes:
8586 '(' objc-property-attribute-list ')'
8588 objc-property-attribute-list:
8589 objc-property-attribute
8590 objc-property-attribute-list, objc-property-attribute
8592 objc-property-attribute
8593 'getter' = identifier
8594 'setter' = identifier
8603 @property NSString *name;
8604 @property (readonly) id object;
8605 @property (retain, nonatomic, getter=getTheName) id name;
8606 @property int a, b, c;
8608 PS: This function is identical to cp_parser_objc_at_propery_declaration
8609 for C++. Keep them in sync. */
8611 c_parser_objc_at_property_declaration (c_parser
*parser
)
8613 /* The following variables hold the attributes of the properties as
8614 parsed. They are 'false' or 'NULL_TREE' if the attribute was not
8615 seen. When we see an attribute, we set them to 'true' (if they
8616 are boolean properties) or to the identifier (if they have an
8617 argument, ie, for getter and setter). Note that here we only
8618 parse the list of attributes, check the syntax and accumulate the
8619 attributes that we find. objc_add_property_declaration() will
8620 then process the information. */
8621 bool property_assign
= false;
8622 bool property_copy
= false;
8623 tree property_getter_ident
= NULL_TREE
;
8624 bool property_nonatomic
= false;
8625 bool property_readonly
= false;
8626 bool property_readwrite
= false;
8627 bool property_retain
= false;
8628 tree property_setter_ident
= NULL_TREE
;
8630 /* 'properties' is the list of properties that we read. Usually a
8631 single one, but maybe more (eg, in "@property int a, b, c;" there
8636 loc
= c_parser_peek_token (parser
)->location
;
8637 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
));
8639 c_parser_consume_token (parser
); /* Eat '@property'. */
8641 /* Parse the optional attribute list... */
8642 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8645 c_parser_consume_token (parser
);
8647 /* Property attribute keywords are valid now. */
8648 parser
->objc_property_attr_context
= true;
8652 bool syntax_error
= false;
8653 c_token
*token
= c_parser_peek_token (parser
);
8656 if (token
->type
!= CPP_KEYWORD
)
8658 if (token
->type
== CPP_CLOSE_PAREN
)
8659 c_parser_error (parser
, "expected identifier");
8662 c_parser_consume_token (parser
);
8663 c_parser_error (parser
, "unknown property attribute");
8667 keyword
= token
->keyword
;
8668 c_parser_consume_token (parser
);
8671 case RID_ASSIGN
: property_assign
= true; break;
8672 case RID_COPY
: property_copy
= true; break;
8673 case RID_NONATOMIC
: property_nonatomic
= true; break;
8674 case RID_READONLY
: property_readonly
= true; break;
8675 case RID_READWRITE
: property_readwrite
= true; break;
8676 case RID_RETAIN
: property_retain
= true; break;
8680 if (c_parser_next_token_is_not (parser
, CPP_EQ
))
8682 if (keyword
== RID_GETTER
)
8683 c_parser_error (parser
,
8684 "missing %<=%> (after %<getter%> attribute)");
8686 c_parser_error (parser
,
8687 "missing %<=%> (after %<setter%> attribute)");
8688 syntax_error
= true;
8691 c_parser_consume_token (parser
); /* eat the = */
8692 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8694 c_parser_error (parser
, "expected identifier");
8695 syntax_error
= true;
8698 if (keyword
== RID_SETTER
)
8700 if (property_setter_ident
!= NULL_TREE
)
8701 c_parser_error (parser
, "the %<setter%> attribute may only be specified once");
8703 property_setter_ident
= c_parser_peek_token (parser
)->value
;
8704 c_parser_consume_token (parser
);
8705 if (c_parser_next_token_is_not (parser
, CPP_COLON
))
8706 c_parser_error (parser
, "setter name must terminate with %<:%>");
8708 c_parser_consume_token (parser
);
8712 if (property_getter_ident
!= NULL_TREE
)
8713 c_parser_error (parser
, "the %<getter%> attribute may only be specified once");
8715 property_getter_ident
= c_parser_peek_token (parser
)->value
;
8716 c_parser_consume_token (parser
);
8720 c_parser_error (parser
, "unknown property attribute");
8721 syntax_error
= true;
8728 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8729 c_parser_consume_token (parser
);
8733 parser
->objc_property_attr_context
= false;
8734 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8736 /* ... and the property declaration(s). */
8737 properties
= c_parser_struct_declaration (parser
);
8739 if (properties
== error_mark_node
)
8741 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8742 parser
->error
= false;
8746 if (properties
== NULL_TREE
)
8747 c_parser_error (parser
, "expected identifier");
8750 /* Comma-separated properties are chained together in
8751 reverse order; add them one by one. */
8752 properties
= nreverse (properties
);
8754 for (; properties
; properties
= TREE_CHAIN (properties
))
8755 objc_add_property_declaration (loc
, copy_node (properties
),
8756 property_readonly
, property_readwrite
,
8757 property_assign
, property_retain
,
8758 property_copy
, property_nonatomic
,
8759 property_getter_ident
, property_setter_ident
);
8762 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8763 parser
->error
= false;
8766 /* Parse an Objective-C @synthesize declaration. The syntax is:
8768 objc-synthesize-declaration:
8769 @synthesize objc-synthesize-identifier-list ;
8771 objc-synthesize-identifier-list:
8772 objc-synthesize-identifier
8773 objc-synthesize-identifier-list, objc-synthesize-identifier
8775 objc-synthesize-identifier
8777 identifier = identifier
8780 @synthesize MyProperty;
8781 @synthesize OneProperty, AnotherProperty=MyIvar, YetAnotherProperty;
8783 PS: This function is identical to cp_parser_objc_at_synthesize_declaration
8784 for C++. Keep them in sync.
8787 c_parser_objc_at_synthesize_declaration (c_parser
*parser
)
8789 tree list
= NULL_TREE
;
8791 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNTHESIZE
));
8792 loc
= c_parser_peek_token (parser
)->location
;
8794 c_parser_consume_token (parser
);
8797 tree property
, ivar
;
8798 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8800 c_parser_error (parser
, "expected identifier");
8801 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8802 /* Once we find the semicolon, we can resume normal parsing.
8803 We have to reset parser->error manually because
8804 c_parser_skip_until_found() won't reset it for us if the
8805 next token is precisely a semicolon. */
8806 parser
->error
= false;
8809 property
= c_parser_peek_token (parser
)->value
;
8810 c_parser_consume_token (parser
);
8811 if (c_parser_next_token_is (parser
, CPP_EQ
))
8813 c_parser_consume_token (parser
);
8814 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8816 c_parser_error (parser
, "expected identifier");
8817 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8818 parser
->error
= false;
8821 ivar
= c_parser_peek_token (parser
)->value
;
8822 c_parser_consume_token (parser
);
8826 list
= chainon (list
, build_tree_list (ivar
, property
));
8827 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8828 c_parser_consume_token (parser
);
8832 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8833 objc_add_synthesize_declaration (loc
, list
);
8836 /* Parse an Objective-C @dynamic declaration. The syntax is:
8838 objc-dynamic-declaration:
8839 @dynamic identifier-list ;
8842 @dynamic MyProperty;
8843 @dynamic MyProperty, AnotherProperty;
8845 PS: This function is identical to cp_parser_objc_at_dynamic_declaration
8846 for C++. Keep them in sync.
8849 c_parser_objc_at_dynamic_declaration (c_parser
*parser
)
8851 tree list
= NULL_TREE
;
8853 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_DYNAMIC
));
8854 loc
= c_parser_peek_token (parser
)->location
;
8856 c_parser_consume_token (parser
);
8860 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8862 c_parser_error (parser
, "expected identifier");
8863 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8864 parser
->error
= false;
8867 property
= c_parser_peek_token (parser
)->value
;
8868 list
= chainon (list
, build_tree_list (NULL_TREE
, property
));
8869 c_parser_consume_token (parser
);
8870 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8871 c_parser_consume_token (parser
);
8875 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8876 objc_add_dynamic_declaration (loc
, list
);
8880 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
8881 should be considered, statements. ALLOW_STMT is true if we're within
8882 the context of a function and such pragmas are to be allowed. Returns
8883 true if we actually parsed such a pragma. */
8886 c_parser_pragma (c_parser
*parser
, enum pragma_context context
)
8890 id
= c_parser_peek_token (parser
)->pragma_kind
;
8891 gcc_assert (id
!= PRAGMA_NONE
);
8895 case PRAGMA_OMP_BARRIER
:
8896 if (context
!= pragma_compound
)
8898 if (context
== pragma_stmt
)
8899 c_parser_error (parser
, "%<#pragma omp barrier%> may only be "
8900 "used in compound statements");
8903 c_parser_omp_barrier (parser
);
8906 case PRAGMA_OMP_FLUSH
:
8907 if (context
!= pragma_compound
)
8909 if (context
== pragma_stmt
)
8910 c_parser_error (parser
, "%<#pragma omp flush%> may only be "
8911 "used in compound statements");
8914 c_parser_omp_flush (parser
);
8917 case PRAGMA_OMP_TASKWAIT
:
8918 if (context
!= pragma_compound
)
8920 if (context
== pragma_stmt
)
8921 c_parser_error (parser
, "%<#pragma omp taskwait%> may only be "
8922 "used in compound statements");
8925 c_parser_omp_taskwait (parser
);
8928 case PRAGMA_OMP_TASKYIELD
:
8929 if (context
!= pragma_compound
)
8931 if (context
== pragma_stmt
)
8932 c_parser_error (parser
, "%<#pragma omp taskyield%> may only be "
8933 "used in compound statements");
8936 c_parser_omp_taskyield (parser
);
8939 case PRAGMA_OMP_THREADPRIVATE
:
8940 c_parser_omp_threadprivate (parser
);
8943 case PRAGMA_OMP_SECTION
:
8944 error_at (c_parser_peek_token (parser
)->location
,
8945 "%<#pragma omp section%> may only be used in "
8946 "%<#pragma omp sections%> construct");
8947 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
8950 case PRAGMA_GCC_PCH_PREPROCESS
:
8951 c_parser_error (parser
, "%<#pragma GCC pch_preprocess%> must be first");
8952 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
8956 if (id
< PRAGMA_FIRST_EXTERNAL
)
8958 if (context
== pragma_external
)
8961 c_parser_error (parser
, "expected declaration specifiers");
8962 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
8965 c_parser_omp_construct (parser
);
8971 c_parser_consume_pragma (parser
);
8972 c_invoke_pragma_handler (id
);
8974 /* Skip to EOL, but suppress any error message. Those will have been
8975 generated by the handler routine through calling error, as opposed
8976 to calling c_parser_error. */
8977 parser
->error
= true;
8978 c_parser_skip_to_pragma_eol (parser
);
8983 /* The interface the pragma parsers have to the lexer. */
8986 pragma_lex (tree
*value
)
8988 c_token
*tok
= c_parser_peek_token (the_parser
);
8989 enum cpp_ttype ret
= tok
->type
;
8991 *value
= tok
->value
;
8992 if (ret
== CPP_PRAGMA_EOL
|| ret
== CPP_EOF
)
8996 if (ret
== CPP_KEYWORD
)
8998 c_parser_consume_token (the_parser
);
9005 c_parser_pragma_pch_preprocess (c_parser
*parser
)
9009 c_parser_consume_pragma (parser
);
9010 if (c_parser_next_token_is (parser
, CPP_STRING
))
9012 name
= c_parser_peek_token (parser
)->value
;
9013 c_parser_consume_token (parser
);
9016 c_parser_error (parser
, "expected string literal");
9017 c_parser_skip_to_pragma_eol (parser
);
9020 c_common_pch_pragma (parse_in
, TREE_STRING_POINTER (name
));
9023 /* OpenMP 2.5 parsing routines. */
9025 /* Returns name of the next clause.
9026 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
9027 the token is not consumed. Otherwise appropriate pragma_omp_clause is
9028 returned and the token is consumed. */
9030 static pragma_omp_clause
9031 c_parser_omp_clause_name (c_parser
*parser
)
9033 pragma_omp_clause result
= PRAGMA_OMP_CLAUSE_NONE
;
9035 if (c_parser_next_token_is_keyword (parser
, RID_IF
))
9036 result
= PRAGMA_OMP_CLAUSE_IF
;
9037 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
9038 result
= PRAGMA_OMP_CLAUSE_DEFAULT
;
9039 else if (c_parser_next_token_is (parser
, CPP_NAME
))
9041 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
9046 if (!strcmp ("collapse", p
))
9047 result
= PRAGMA_OMP_CLAUSE_COLLAPSE
;
9048 else if (!strcmp ("copyin", p
))
9049 result
= PRAGMA_OMP_CLAUSE_COPYIN
;
9050 else if (!strcmp ("copyprivate", p
))
9051 result
= PRAGMA_OMP_CLAUSE_COPYPRIVATE
;
9054 if (!strcmp ("final", p
))
9055 result
= PRAGMA_OMP_CLAUSE_FINAL
;
9056 else if (!strcmp ("firstprivate", p
))
9057 result
= PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
;
9060 if (!strcmp ("lastprivate", p
))
9061 result
= PRAGMA_OMP_CLAUSE_LASTPRIVATE
;
9064 if (!strcmp ("mergeable", p
))
9065 result
= PRAGMA_OMP_CLAUSE_MERGEABLE
;
9068 if (!strcmp ("nowait", p
))
9069 result
= PRAGMA_OMP_CLAUSE_NOWAIT
;
9070 else if (!strcmp ("num_threads", p
))
9071 result
= PRAGMA_OMP_CLAUSE_NUM_THREADS
;
9074 if (!strcmp ("ordered", p
))
9075 result
= PRAGMA_OMP_CLAUSE_ORDERED
;
9078 if (!strcmp ("private", p
))
9079 result
= PRAGMA_OMP_CLAUSE_PRIVATE
;
9082 if (!strcmp ("reduction", p
))
9083 result
= PRAGMA_OMP_CLAUSE_REDUCTION
;
9086 if (!strcmp ("schedule", p
))
9087 result
= PRAGMA_OMP_CLAUSE_SCHEDULE
;
9088 else if (!strcmp ("shared", p
))
9089 result
= PRAGMA_OMP_CLAUSE_SHARED
;
9092 if (!strcmp ("untied", p
))
9093 result
= PRAGMA_OMP_CLAUSE_UNTIED
;
9098 if (result
!= PRAGMA_OMP_CLAUSE_NONE
)
9099 c_parser_consume_token (parser
);
9104 /* Validate that a clause of the given type does not already exist. */
9107 check_no_duplicate_clause (tree clauses
, enum omp_clause_code code
,
9112 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
9113 if (OMP_CLAUSE_CODE (c
) == code
)
9115 location_t loc
= OMP_CLAUSE_LOCATION (c
);
9116 error_at (loc
, "too many %qs clauses", name
);
9124 variable-list , identifier
9126 If KIND is nonzero, create the appropriate node and install the
9127 decl in OMP_CLAUSE_DECL and add the node to the head of the list.
9128 If KIND is nonzero, CLAUSE_LOC is the location of the clause.
9130 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
9131 return the list created. */
9134 c_parser_omp_variable_list (c_parser
*parser
,
9135 location_t clause_loc
,
9136 enum omp_clause_code kind
,
9139 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
9140 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
9141 c_parser_error (parser
, "expected identifier");
9143 while (c_parser_next_token_is (parser
, CPP_NAME
)
9144 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
9146 tree t
= lookup_name (c_parser_peek_token (parser
)->value
);
9149 undeclared_variable (c_parser_peek_token (parser
)->location
,
9150 c_parser_peek_token (parser
)->value
);
9151 else if (t
== error_mark_node
)
9155 tree u
= build_omp_clause (clause_loc
, kind
);
9156 OMP_CLAUSE_DECL (u
) = t
;
9157 OMP_CLAUSE_CHAIN (u
) = list
;
9161 list
= tree_cons (t
, NULL_TREE
, list
);
9163 c_parser_consume_token (parser
);
9165 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
9168 c_parser_consume_token (parser
);
9174 /* Similarly, but expect leading and trailing parenthesis. This is a very
9175 common case for omp clauses. */
9178 c_parser_omp_var_list_parens (c_parser
*parser
, enum omp_clause_code kind
,
9181 /* The clauses location. */
9182 location_t loc
= c_parser_peek_token (parser
)->location
;
9184 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9186 list
= c_parser_omp_variable_list (parser
, loc
, kind
, list
);
9187 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9193 collapse ( constant-expression ) */
9196 c_parser_omp_clause_collapse (c_parser
*parser
, tree list
)
9198 tree c
, num
= error_mark_node
;
9202 check_no_duplicate_clause (list
, OMP_CLAUSE_COLLAPSE
, "collapse");
9204 loc
= c_parser_peek_token (parser
)->location
;
9205 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9207 num
= c_parser_expr_no_commas (parser
, NULL
).value
;
9208 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9210 if (num
== error_mark_node
)
9212 if (!INTEGRAL_TYPE_P (TREE_TYPE (num
))
9213 || !host_integerp (num
, 0)
9214 || (n
= tree_low_cst (num
, 0)) <= 0
9218 "collapse argument needs positive constant integer expression");
9221 c
= build_omp_clause (loc
, OMP_CLAUSE_COLLAPSE
);
9222 OMP_CLAUSE_COLLAPSE_EXPR (c
) = num
;
9223 OMP_CLAUSE_CHAIN (c
) = list
;
9228 copyin ( variable-list ) */
9231 c_parser_omp_clause_copyin (c_parser
*parser
, tree list
)
9233 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYIN
, list
);
9237 copyprivate ( variable-list ) */
9240 c_parser_omp_clause_copyprivate (c_parser
*parser
, tree list
)
9242 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYPRIVATE
, list
);
9246 default ( shared | none ) */
9249 c_parser_omp_clause_default (c_parser
*parser
, tree list
)
9251 enum omp_clause_default_kind kind
= OMP_CLAUSE_DEFAULT_UNSPECIFIED
;
9252 location_t loc
= c_parser_peek_token (parser
)->location
;
9255 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9257 if (c_parser_next_token_is (parser
, CPP_NAME
))
9259 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
9264 if (strcmp ("none", p
) != 0)
9266 kind
= OMP_CLAUSE_DEFAULT_NONE
;
9270 if (strcmp ("shared", p
) != 0)
9272 kind
= OMP_CLAUSE_DEFAULT_SHARED
;
9279 c_parser_consume_token (parser
);
9284 c_parser_error (parser
, "expected %<none%> or %<shared%>");
9286 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9288 if (kind
== OMP_CLAUSE_DEFAULT_UNSPECIFIED
)
9291 check_no_duplicate_clause (list
, OMP_CLAUSE_DEFAULT
, "default");
9292 c
= build_omp_clause (loc
, OMP_CLAUSE_DEFAULT
);
9293 OMP_CLAUSE_CHAIN (c
) = list
;
9294 OMP_CLAUSE_DEFAULT_KIND (c
) = kind
;
9300 firstprivate ( variable-list ) */
9303 c_parser_omp_clause_firstprivate (c_parser
*parser
, tree list
)
9305 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FIRSTPRIVATE
, list
);
9309 final ( expression ) */
9312 c_parser_omp_clause_final (c_parser
*parser
, tree list
)
9314 location_t loc
= c_parser_peek_token (parser
)->location
;
9315 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9317 tree t
= c_parser_paren_condition (parser
);
9320 check_no_duplicate_clause (list
, OMP_CLAUSE_FINAL
, "final");
9322 c
= build_omp_clause (loc
, OMP_CLAUSE_FINAL
);
9323 OMP_CLAUSE_FINAL_EXPR (c
) = t
;
9324 OMP_CLAUSE_CHAIN (c
) = list
;
9328 c_parser_error (parser
, "expected %<(%>");
9334 if ( expression ) */
9337 c_parser_omp_clause_if (c_parser
*parser
, tree list
)
9339 location_t loc
= c_parser_peek_token (parser
)->location
;
9340 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9342 tree t
= c_parser_paren_condition (parser
);
9345 check_no_duplicate_clause (list
, OMP_CLAUSE_IF
, "if");
9347 c
= build_omp_clause (loc
, OMP_CLAUSE_IF
);
9348 OMP_CLAUSE_IF_EXPR (c
) = t
;
9349 OMP_CLAUSE_CHAIN (c
) = list
;
9353 c_parser_error (parser
, "expected %<(%>");
9359 lastprivate ( variable-list ) */
9362 c_parser_omp_clause_lastprivate (c_parser
*parser
, tree list
)
9364 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_LASTPRIVATE
, list
);
9371 c_parser_omp_clause_mergeable (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
9375 /* FIXME: Should we allow duplicates? */
9376 check_no_duplicate_clause (list
, OMP_CLAUSE_MERGEABLE
, "mergeable");
9378 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
9379 OMP_CLAUSE_MERGEABLE
);
9380 OMP_CLAUSE_CHAIN (c
) = list
;
9389 c_parser_omp_clause_nowait (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
9392 location_t loc
= c_parser_peek_token (parser
)->location
;
9394 check_no_duplicate_clause (list
, OMP_CLAUSE_NOWAIT
, "nowait");
9396 c
= build_omp_clause (loc
, OMP_CLAUSE_NOWAIT
);
9397 OMP_CLAUSE_CHAIN (c
) = list
;
9402 num_threads ( expression ) */
9405 c_parser_omp_clause_num_threads (c_parser
*parser
, tree list
)
9407 location_t num_threads_loc
= c_parser_peek_token (parser
)->location
;
9408 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9410 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
9411 tree c
, t
= c_parser_expression (parser
).value
;
9413 t
= c_fully_fold (t
, false, NULL
);
9415 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9417 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
9419 c_parser_error (parser
, "expected integer expression");
9423 /* Attempt to statically determine when the number isn't positive. */
9424 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
9425 build_int_cst (TREE_TYPE (t
), 0));
9426 if (CAN_HAVE_LOCATION_P (c
))
9427 SET_EXPR_LOCATION (c
, expr_loc
);
9428 if (c
== boolean_true_node
)
9430 warning_at (expr_loc
, 0,
9431 "%<num_threads%> value must be positive");
9432 t
= integer_one_node
;
9435 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_THREADS
, "num_threads");
9437 c
= build_omp_clause (num_threads_loc
, OMP_CLAUSE_NUM_THREADS
);
9438 OMP_CLAUSE_NUM_THREADS_EXPR (c
) = t
;
9439 OMP_CLAUSE_CHAIN (c
) = list
;
9450 c_parser_omp_clause_ordered (c_parser
*parser
, tree list
)
9454 check_no_duplicate_clause (list
, OMP_CLAUSE_ORDERED
, "ordered");
9456 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
9457 OMP_CLAUSE_ORDERED
);
9458 OMP_CLAUSE_CHAIN (c
) = list
;
9464 private ( variable-list ) */
9467 c_parser_omp_clause_private (c_parser
*parser
, tree list
)
9469 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_PRIVATE
, list
);
9473 reduction ( reduction-operator : variable-list )
9476 One of: + * - & ^ | && ||
9481 One of: + * - & ^ | && || max min */
9484 c_parser_omp_clause_reduction (c_parser
*parser
, tree list
)
9486 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
9487 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9489 enum tree_code code
;
9491 switch (c_parser_peek_token (parser
)->type
)
9503 code
= BIT_AND_EXPR
;
9506 code
= BIT_XOR_EXPR
;
9509 code
= BIT_IOR_EXPR
;
9512 code
= TRUTH_ANDIF_EXPR
;
9515 code
= TRUTH_ORIF_EXPR
;
9520 = IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
9521 if (strcmp (p
, "min") == 0)
9526 if (strcmp (p
, "max") == 0)
9534 c_parser_error (parser
,
9535 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
9536 "%<^%>, %<|%>, %<&&%>, %<||%>, %<min%> or %<max%>");
9537 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
9540 c_parser_consume_token (parser
);
9541 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
9545 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
9546 OMP_CLAUSE_REDUCTION
, list
);
9547 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
9548 OMP_CLAUSE_REDUCTION_CODE (c
) = code
;
9552 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9558 schedule ( schedule-kind )
9559 schedule ( schedule-kind , expression )
9562 static | dynamic | guided | runtime | auto
9566 c_parser_omp_clause_schedule (c_parser
*parser
, tree list
)
9569 location_t loc
= c_parser_peek_token (parser
)->location
;
9571 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9574 c
= build_omp_clause (loc
, OMP_CLAUSE_SCHEDULE
);
9576 if (c_parser_next_token_is (parser
, CPP_NAME
))
9578 tree kind
= c_parser_peek_token (parser
)->value
;
9579 const char *p
= IDENTIFIER_POINTER (kind
);
9584 if (strcmp ("dynamic", p
) != 0)
9586 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_DYNAMIC
;
9590 if (strcmp ("guided", p
) != 0)
9592 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_GUIDED
;
9596 if (strcmp ("runtime", p
) != 0)
9598 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_RUNTIME
;
9605 else if (c_parser_next_token_is_keyword (parser
, RID_STATIC
))
9606 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_STATIC
;
9607 else if (c_parser_next_token_is_keyword (parser
, RID_AUTO
))
9608 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_AUTO
;
9612 c_parser_consume_token (parser
);
9613 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9616 c_parser_consume_token (parser
);
9618 here
= c_parser_peek_token (parser
)->location
;
9619 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
9621 t
= c_fully_fold (t
, false, NULL
);
9623 if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_RUNTIME
)
9624 error_at (here
, "schedule %<runtime%> does not take "
9625 "a %<chunk_size%> parameter");
9626 else if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_AUTO
)
9628 "schedule %<auto%> does not take "
9629 "a %<chunk_size%> parameter");
9630 else if (TREE_CODE (TREE_TYPE (t
)) == INTEGER_TYPE
)
9631 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
) = t
;
9633 c_parser_error (parser
, "expected integer expression");
9635 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9638 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
9639 "expected %<,%> or %<)%>");
9641 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
9642 OMP_CLAUSE_CHAIN (c
) = list
;
9646 c_parser_error (parser
, "invalid schedule kind");
9647 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
9652 shared ( variable-list ) */
9655 c_parser_omp_clause_shared (c_parser
*parser
, tree list
)
9657 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_SHARED
, list
);
9664 c_parser_omp_clause_untied (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
9668 /* FIXME: Should we allow duplicates? */
9669 check_no_duplicate_clause (list
, OMP_CLAUSE_UNTIED
, "untied");
9671 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
9673 OMP_CLAUSE_CHAIN (c
) = list
;
9678 /* Parse all OpenMP clauses. The set clauses allowed by the directive
9679 is a bitmask in MASK. Return the list of clauses found; the result
9680 of clause default goes in *pdefault. */
9683 c_parser_omp_all_clauses (c_parser
*parser
, unsigned int mask
,
9686 tree clauses
= NULL
;
9689 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
9692 pragma_omp_clause c_kind
;
9694 tree prev
= clauses
;
9696 if (!first
&& c_parser_next_token_is (parser
, CPP_COMMA
))
9697 c_parser_consume_token (parser
);
9700 here
= c_parser_peek_token (parser
)->location
;
9701 c_kind
= c_parser_omp_clause_name (parser
);
9705 case PRAGMA_OMP_CLAUSE_COLLAPSE
:
9706 clauses
= c_parser_omp_clause_collapse (parser
, clauses
);
9707 c_name
= "collapse";
9709 case PRAGMA_OMP_CLAUSE_COPYIN
:
9710 clauses
= c_parser_omp_clause_copyin (parser
, clauses
);
9713 case PRAGMA_OMP_CLAUSE_COPYPRIVATE
:
9714 clauses
= c_parser_omp_clause_copyprivate (parser
, clauses
);
9715 c_name
= "copyprivate";
9717 case PRAGMA_OMP_CLAUSE_DEFAULT
:
9718 clauses
= c_parser_omp_clause_default (parser
, clauses
);
9721 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
:
9722 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
9723 c_name
= "firstprivate";
9725 case PRAGMA_OMP_CLAUSE_FINAL
:
9726 clauses
= c_parser_omp_clause_final (parser
, clauses
);
9729 case PRAGMA_OMP_CLAUSE_IF
:
9730 clauses
= c_parser_omp_clause_if (parser
, clauses
);
9733 case PRAGMA_OMP_CLAUSE_LASTPRIVATE
:
9734 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
9735 c_name
= "lastprivate";
9737 case PRAGMA_OMP_CLAUSE_MERGEABLE
:
9738 clauses
= c_parser_omp_clause_mergeable (parser
, clauses
);
9739 c_name
= "mergeable";
9741 case PRAGMA_OMP_CLAUSE_NOWAIT
:
9742 clauses
= c_parser_omp_clause_nowait (parser
, clauses
);
9745 case PRAGMA_OMP_CLAUSE_NUM_THREADS
:
9746 clauses
= c_parser_omp_clause_num_threads (parser
, clauses
);
9747 c_name
= "num_threads";
9749 case PRAGMA_OMP_CLAUSE_ORDERED
:
9750 clauses
= c_parser_omp_clause_ordered (parser
, clauses
);
9753 case PRAGMA_OMP_CLAUSE_PRIVATE
:
9754 clauses
= c_parser_omp_clause_private (parser
, clauses
);
9757 case PRAGMA_OMP_CLAUSE_REDUCTION
:
9758 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
9759 c_name
= "reduction";
9761 case PRAGMA_OMP_CLAUSE_SCHEDULE
:
9762 clauses
= c_parser_omp_clause_schedule (parser
, clauses
);
9763 c_name
= "schedule";
9765 case PRAGMA_OMP_CLAUSE_SHARED
:
9766 clauses
= c_parser_omp_clause_shared (parser
, clauses
);
9769 case PRAGMA_OMP_CLAUSE_UNTIED
:
9770 clauses
= c_parser_omp_clause_untied (parser
, clauses
);
9774 c_parser_error (parser
, "expected %<#pragma omp%> clause");
9778 if (((mask
>> c_kind
) & 1) == 0 && !parser
->error
)
9780 /* Remove the invalid clause(s) from the list to avoid
9781 confusing the rest of the compiler. */
9783 error_at (here
, "%qs is not valid for %qs", c_name
, where
);
9788 c_parser_skip_to_pragma_eol (parser
);
9790 return c_finish_omp_clauses (clauses
);
9797 In practice, we're also interested in adding the statement to an
9798 outer node. So it is convenient if we work around the fact that
9799 c_parser_statement calls add_stmt. */
9802 c_parser_omp_structured_block (c_parser
*parser
)
9804 tree stmt
= push_stmt_list ();
9805 c_parser_statement (parser
);
9806 return pop_stmt_list (stmt
);
9810 # pragma omp atomic new-line
9814 x binop= expr | x++ | ++x | x-- | --x
9816 +, *, -, /, &, ^, |, <<, >>
9818 where x is an lvalue expression with scalar type.
9821 # pragma omp atomic new-line
9824 # pragma omp atomic read new-line
9827 # pragma omp atomic write new-line
9830 # pragma omp atomic update new-line
9833 # pragma omp atomic capture new-line
9836 # pragma omp atomic capture new-line
9844 expression-stmt | x = x binop expr
9846 v = x binop= expr | v = x++ | v = ++x | v = x-- | v = --x
9848 { v = x; update-stmt; } | { update-stmt; v = x; }
9850 where x and v are lvalue expressions with scalar type.
9852 LOC is the location of the #pragma token. */
9855 c_parser_omp_atomic (location_t loc
, c_parser
*parser
)
9857 tree lhs
= NULL_TREE
, rhs
= NULL_TREE
, v
= NULL_TREE
;
9858 tree lhs1
= NULL_TREE
, rhs1
= NULL_TREE
;
9859 tree stmt
, orig_lhs
;
9860 enum tree_code code
= OMP_ATOMIC
, opcode
= NOP_EXPR
;
9861 struct c_expr rhs_expr
;
9862 bool structured_block
= false;
9864 if (c_parser_next_token_is (parser
, CPP_NAME
))
9866 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
9868 if (!strcmp (p
, "read"))
9869 code
= OMP_ATOMIC_READ
;
9870 else if (!strcmp (p
, "write"))
9872 else if (!strcmp (p
, "update"))
9874 else if (!strcmp (p
, "capture"))
9875 code
= OMP_ATOMIC_CAPTURE_NEW
;
9879 c_parser_consume_token (parser
);
9881 c_parser_skip_to_pragma_eol (parser
);
9885 case OMP_ATOMIC_READ
:
9886 case NOP_EXPR
: /* atomic write */
9887 v
= c_parser_unary_expression (parser
).value
;
9888 v
= c_fully_fold (v
, false, NULL
);
9889 if (v
== error_mark_node
)
9891 loc
= c_parser_peek_token (parser
)->location
;
9892 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
9894 if (code
== NOP_EXPR
)
9895 lhs
= c_parser_expression (parser
).value
;
9897 lhs
= c_parser_unary_expression (parser
).value
;
9898 lhs
= c_fully_fold (lhs
, false, NULL
);
9899 if (lhs
== error_mark_node
)
9901 if (code
== NOP_EXPR
)
9903 /* atomic write is represented by OMP_ATOMIC with NOP_EXPR
9911 case OMP_ATOMIC_CAPTURE_NEW
:
9912 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
9914 c_parser_consume_token (parser
);
9915 structured_block
= true;
9919 v
= c_parser_unary_expression (parser
).value
;
9920 v
= c_fully_fold (v
, false, NULL
);
9921 if (v
== error_mark_node
)
9923 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
9931 /* For structured_block case we don't know yet whether
9932 old or new x should be captured. */
9934 lhs
= c_parser_unary_expression (parser
).value
;
9935 lhs
= c_fully_fold (lhs
, false, NULL
);
9937 switch (TREE_CODE (lhs
))
9941 c_parser_skip_to_end_of_block_or_statement (parser
);
9942 if (structured_block
)
9944 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
9945 c_parser_consume_token (parser
);
9946 else if (code
== OMP_ATOMIC_CAPTURE_NEW
)
9948 c_parser_skip_to_end_of_block_or_statement (parser
);
9949 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
9950 c_parser_consume_token (parser
);
9955 case POSTINCREMENT_EXPR
:
9956 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
9957 code
= OMP_ATOMIC_CAPTURE_OLD
;
9959 case PREINCREMENT_EXPR
:
9960 lhs
= TREE_OPERAND (lhs
, 0);
9962 rhs
= integer_one_node
;
9965 case POSTDECREMENT_EXPR
:
9966 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
9967 code
= OMP_ATOMIC_CAPTURE_OLD
;
9969 case PREDECREMENT_EXPR
:
9970 lhs
= TREE_OPERAND (lhs
, 0);
9971 opcode
= MINUS_EXPR
;
9972 rhs
= integer_one_node
;
9976 if (TREE_CODE (TREE_OPERAND (lhs
, 0)) == SAVE_EXPR
9977 && TREE_CODE (TREE_OPERAND (lhs
, 1)) == COMPOUND_EXPR
9978 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0)) == MODIFY_EXPR
9979 && TREE_OPERAND (TREE_OPERAND (lhs
, 1), 1) == TREE_OPERAND (lhs
, 0)
9980 && TREE_CODE (TREE_TYPE (TREE_OPERAND (TREE_OPERAND
9981 (TREE_OPERAND (lhs
, 1), 0), 0)))
9983 /* Undo effects of boolean_increment for post {in,de}crement. */
9984 lhs
= TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0);
9987 if (TREE_CODE (lhs
) == MODIFY_EXPR
9988 && TREE_CODE (TREE_TYPE (TREE_OPERAND (lhs
, 0))) == BOOLEAN_TYPE
)
9990 /* Undo effects of boolean_increment. */
9991 if (integer_onep (TREE_OPERAND (lhs
, 1)))
9993 /* This is pre or post increment. */
9994 rhs
= TREE_OPERAND (lhs
, 1);
9995 lhs
= TREE_OPERAND (lhs
, 0);
9997 if (code
== OMP_ATOMIC_CAPTURE_NEW
9998 && !structured_block
9999 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
10000 code
= OMP_ATOMIC_CAPTURE_OLD
;
10003 if (TREE_CODE (TREE_OPERAND (lhs
, 1)) == TRUTH_NOT_EXPR
10004 && TREE_OPERAND (lhs
, 0)
10005 == TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0))
10007 /* This is pre or post decrement. */
10008 rhs
= TREE_OPERAND (lhs
, 1);
10009 lhs
= TREE_OPERAND (lhs
, 0);
10011 if (code
== OMP_ATOMIC_CAPTURE_NEW
10012 && !structured_block
10013 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
10014 code
= OMP_ATOMIC_CAPTURE_OLD
;
10020 switch (c_parser_peek_token (parser
)->type
)
10023 opcode
= MULT_EXPR
;
10026 opcode
= TRUNC_DIV_EXPR
;
10029 opcode
= PLUS_EXPR
;
10032 opcode
= MINUS_EXPR
;
10034 case CPP_LSHIFT_EQ
:
10035 opcode
= LSHIFT_EXPR
;
10037 case CPP_RSHIFT_EQ
:
10038 opcode
= RSHIFT_EXPR
;
10041 opcode
= BIT_AND_EXPR
;
10044 opcode
= BIT_IOR_EXPR
;
10047 opcode
= BIT_XOR_EXPR
;
10050 if (structured_block
|| code
== OMP_ATOMIC
)
10052 location_t aloc
= c_parser_peek_token (parser
)->location
;
10053 location_t rhs_loc
;
10054 enum c_parser_prec oprec
= PREC_NONE
;
10056 c_parser_consume_token (parser
);
10057 rhs1
= c_parser_unary_expression (parser
).value
;
10058 rhs1
= c_fully_fold (rhs1
, false, NULL
);
10059 if (rhs1
== error_mark_node
)
10061 switch (c_parser_peek_token (parser
)->type
)
10063 case CPP_SEMICOLON
:
10064 if (code
== OMP_ATOMIC_CAPTURE_NEW
)
10066 code
= OMP_ATOMIC_CAPTURE_OLD
;
10071 c_parser_consume_token (parser
);
10074 c_parser_error (parser
,
10075 "invalid form of %<#pragma omp atomic%>");
10078 opcode
= MULT_EXPR
;
10082 opcode
= TRUNC_DIV_EXPR
;
10086 opcode
= PLUS_EXPR
;
10090 opcode
= MINUS_EXPR
;
10094 opcode
= LSHIFT_EXPR
;
10095 oprec
= PREC_SHIFT
;
10098 opcode
= RSHIFT_EXPR
;
10099 oprec
= PREC_SHIFT
;
10102 opcode
= BIT_AND_EXPR
;
10103 oprec
= PREC_BITAND
;
10106 opcode
= BIT_IOR_EXPR
;
10107 oprec
= PREC_BITOR
;
10110 opcode
= BIT_XOR_EXPR
;
10111 oprec
= PREC_BITXOR
;
10114 c_parser_error (parser
,
10115 "invalid operator for %<#pragma omp atomic%>");
10119 c_parser_consume_token (parser
);
10120 rhs_loc
= c_parser_peek_token (parser
)->location
;
10121 if (commutative_tree_code (opcode
))
10122 oprec
= (enum c_parser_prec
) (oprec
- 1);
10123 rhs_expr
= c_parser_binary_expression (parser
, NULL
, oprec
);
10124 rhs_expr
= default_function_array_read_conversion (rhs_loc
,
10126 rhs
= rhs_expr
.value
;
10127 rhs
= c_fully_fold (rhs
, false, NULL
);
10132 c_parser_error (parser
,
10133 "invalid operator for %<#pragma omp atomic%>");
10137 /* Arrange to pass the location of the assignment operator to
10138 c_finish_omp_atomic. */
10139 loc
= c_parser_peek_token (parser
)->location
;
10140 c_parser_consume_token (parser
);
10142 location_t rhs_loc
= c_parser_peek_token (parser
)->location
;
10143 rhs_expr
= c_parser_expression (parser
);
10144 rhs_expr
= default_function_array_read_conversion (rhs_loc
, rhs_expr
);
10146 rhs
= rhs_expr
.value
;
10147 rhs
= c_fully_fold (rhs
, false, NULL
);
10151 if (structured_block
&& code
== OMP_ATOMIC_CAPTURE_NEW
)
10153 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
10155 v
= c_parser_unary_expression (parser
).value
;
10156 v
= c_fully_fold (v
, false, NULL
);
10157 if (v
== error_mark_node
)
10159 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
10161 lhs1
= c_parser_unary_expression (parser
).value
;
10162 lhs1
= c_fully_fold (lhs1
, false, NULL
);
10163 if (lhs1
== error_mark_node
)
10166 if (structured_block
)
10168 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
10169 c_parser_require (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
10172 stmt
= c_finish_omp_atomic (loc
, code
, opcode
, lhs
, rhs
, v
, lhs1
, rhs1
);
10173 if (stmt
!= error_mark_node
)
10176 if (!structured_block
)
10177 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
10182 # pragma omp barrier new-line
10186 c_parser_omp_barrier (c_parser
*parser
)
10188 location_t loc
= c_parser_peek_token (parser
)->location
;
10189 c_parser_consume_pragma (parser
);
10190 c_parser_skip_to_pragma_eol (parser
);
10192 c_finish_omp_barrier (loc
);
10196 # pragma omp critical [(name)] new-line
10199 LOC is the location of the #pragma itself. */
10202 c_parser_omp_critical (location_t loc
, c_parser
*parser
)
10204 tree stmt
, name
= NULL
;
10206 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
10208 c_parser_consume_token (parser
);
10209 if (c_parser_next_token_is (parser
, CPP_NAME
))
10211 name
= c_parser_peek_token (parser
)->value
;
10212 c_parser_consume_token (parser
);
10213 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10216 c_parser_error (parser
, "expected identifier");
10218 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
10219 c_parser_error (parser
, "expected %<(%> or end of line");
10220 c_parser_skip_to_pragma_eol (parser
);
10222 stmt
= c_parser_omp_structured_block (parser
);
10223 return c_finish_omp_critical (loc
, stmt
, name
);
10227 # pragma omp flush flush-vars[opt] new-line
10230 ( variable-list ) */
10233 c_parser_omp_flush (c_parser
*parser
)
10235 location_t loc
= c_parser_peek_token (parser
)->location
;
10236 c_parser_consume_pragma (parser
);
10237 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
10238 c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
10239 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
10240 c_parser_error (parser
, "expected %<(%> or end of line");
10241 c_parser_skip_to_pragma_eol (parser
);
10243 c_finish_omp_flush (loc
);
10246 /* Parse the restricted form of the for statement allowed by OpenMP.
10247 The real trick here is to determine the loop control variable early
10248 so that we can push a new decl if necessary to make it private.
10249 LOC is the location of the OMP in "#pragma omp". */
10252 c_parser_omp_for_loop (location_t loc
,
10253 c_parser
*parser
, tree clauses
, tree
*par_clauses
)
10255 tree decl
, cond
, incr
, save_break
, save_cont
, body
, init
, stmt
, cl
;
10256 tree declv
, condv
, incrv
, initv
, ret
= NULL
;
10257 bool fail
= false, open_brace_parsed
= false;
10258 int i
, collapse
= 1, nbraces
= 0;
10259 location_t for_loc
;
10260 vec
<tree
, va_gc
> *for_block
= make_tree_vector ();
10262 for (cl
= clauses
; cl
; cl
= OMP_CLAUSE_CHAIN (cl
))
10263 if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_COLLAPSE
)
10264 collapse
= tree_low_cst (OMP_CLAUSE_COLLAPSE_EXPR (cl
), 0);
10266 gcc_assert (collapse
>= 1);
10268 declv
= make_tree_vec (collapse
);
10269 initv
= make_tree_vec (collapse
);
10270 condv
= make_tree_vec (collapse
);
10271 incrv
= make_tree_vec (collapse
);
10273 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
))
10275 c_parser_error (parser
, "for statement expected");
10278 for_loc
= c_parser_peek_token (parser
)->location
;
10279 c_parser_consume_token (parser
);
10281 for (i
= 0; i
< collapse
; i
++)
10283 int bracecount
= 0;
10285 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10288 /* Parse the initialization declaration or expression. */
10289 if (c_parser_next_tokens_start_declaration (parser
))
10292 vec_safe_push (for_block
, c_begin_compound_stmt (true));
10293 c_parser_declaration_or_fndef (parser
, true, true, true, true, true, NULL
);
10294 decl
= check_for_loop_decls (for_loc
, flag_isoc99
);
10297 if (DECL_INITIAL (decl
) == error_mark_node
)
10298 decl
= error_mark_node
;
10301 else if (c_parser_next_token_is (parser
, CPP_NAME
)
10302 && c_parser_peek_2nd_token (parser
)->type
== CPP_EQ
)
10304 struct c_expr decl_exp
;
10305 struct c_expr init_exp
;
10306 location_t init_loc
;
10308 decl_exp
= c_parser_postfix_expression (parser
);
10309 decl
= decl_exp
.value
;
10311 c_parser_require (parser
, CPP_EQ
, "expected %<=%>");
10313 init_loc
= c_parser_peek_token (parser
)->location
;
10314 init_exp
= c_parser_expr_no_commas (parser
, NULL
);
10315 init_exp
= default_function_array_read_conversion (init_loc
,
10317 init
= build_modify_expr (init_loc
, decl
, decl_exp
.original_type
,
10318 NOP_EXPR
, init_loc
, init_exp
.value
,
10319 init_exp
.original_type
);
10320 init
= c_process_expr_stmt (init_loc
, init
);
10322 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
10327 c_parser_error (parser
,
10328 "expected iteration declaration or initialization");
10329 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
10335 /* Parse the loop condition. */
10337 if (c_parser_next_token_is_not (parser
, CPP_SEMICOLON
))
10339 location_t cond_loc
= c_parser_peek_token (parser
)->location
;
10340 struct c_expr cond_expr
= c_parser_binary_expression (parser
, NULL
,
10343 cond
= cond_expr
.value
;
10344 cond
= c_objc_common_truthvalue_conversion (cond_loc
, cond
);
10345 cond
= c_fully_fold (cond
, false, NULL
);
10346 switch (cond_expr
.original_code
)
10354 /* Can't be cond = error_mark_node, because we want to preserve
10355 the location until c_finish_omp_for. */
10356 cond
= build1 (NOP_EXPR
, boolean_type_node
, error_mark_node
);
10359 protected_set_expr_location (cond
, cond_loc
);
10361 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
10363 /* Parse the increment expression. */
10365 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_PAREN
))
10367 location_t incr_loc
= c_parser_peek_token (parser
)->location
;
10369 incr
= c_process_expr_stmt (incr_loc
,
10370 c_parser_expression (parser
).value
);
10372 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10374 if (decl
== NULL
|| decl
== error_mark_node
|| init
== error_mark_node
)
10378 TREE_VEC_ELT (declv
, i
) = decl
;
10379 TREE_VEC_ELT (initv
, i
) = init
;
10380 TREE_VEC_ELT (condv
, i
) = cond
;
10381 TREE_VEC_ELT (incrv
, i
) = incr
;
10385 if (i
== collapse
- 1)
10388 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
10389 in between the collapsed for loops to be still considered perfectly
10390 nested. Hopefully the final version clarifies this.
10391 For now handle (multiple) {'s and empty statements. */
10394 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
10396 c_parser_consume_token (parser
);
10399 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
10401 c_parser_consume_token (parser
);
10404 else if (bracecount
10405 && c_parser_next_token_is (parser
, CPP_SEMICOLON
))
10406 c_parser_consume_token (parser
);
10409 c_parser_error (parser
, "not enough perfectly nested loops");
10412 open_brace_parsed
= true;
10422 nbraces
+= bracecount
;
10425 save_break
= c_break_label
;
10426 c_break_label
= size_one_node
;
10427 save_cont
= c_cont_label
;
10428 c_cont_label
= NULL_TREE
;
10429 body
= push_stmt_list ();
10431 if (open_brace_parsed
)
10433 location_t here
= c_parser_peek_token (parser
)->location
;
10434 stmt
= c_begin_compound_stmt (true);
10435 c_parser_compound_statement_nostart (parser
);
10436 add_stmt (c_end_compound_stmt (here
, stmt
, true));
10439 add_stmt (c_parser_c99_block_statement (parser
));
10442 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_cont_label
);
10443 SET_EXPR_LOCATION (t
, loc
);
10447 body
= pop_stmt_list (body
);
10448 c_break_label
= save_break
;
10449 c_cont_label
= save_cont
;
10453 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
10455 c_parser_consume_token (parser
);
10458 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
10459 c_parser_consume_token (parser
);
10462 c_parser_error (parser
, "collapsed loops not perfectly nested");
10465 location_t here
= c_parser_peek_token (parser
)->location
;
10466 stmt
= c_begin_compound_stmt (true);
10468 c_parser_compound_statement_nostart (parser
);
10469 body
= c_end_compound_stmt (here
, stmt
, true);
10476 /* Only bother calling c_finish_omp_for if we haven't already generated
10477 an error from the initialization parsing. */
10480 stmt
= c_finish_omp_for (loc
, declv
, initv
, condv
, incrv
, body
, NULL
);
10483 if (par_clauses
!= NULL
)
10486 for (c
= par_clauses
; *c
; )
10487 if (OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_FIRSTPRIVATE
10488 && OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_LASTPRIVATE
)
10489 c
= &OMP_CLAUSE_CHAIN (*c
);
10492 for (i
= 0; i
< collapse
; i
++)
10493 if (TREE_VEC_ELT (declv
, i
) == OMP_CLAUSE_DECL (*c
))
10496 c
= &OMP_CLAUSE_CHAIN (*c
);
10497 else if (OMP_CLAUSE_CODE (*c
) == OMP_CLAUSE_FIRSTPRIVATE
)
10500 "iteration variable %qD should not be firstprivate",
10501 OMP_CLAUSE_DECL (*c
));
10502 *c
= OMP_CLAUSE_CHAIN (*c
);
10506 /* Copy lastprivate (decl) clause to OMP_FOR_CLAUSES,
10507 change it to shared (decl) in
10508 OMP_PARALLEL_CLAUSES. */
10509 tree l
= build_omp_clause (OMP_CLAUSE_LOCATION (*c
),
10510 OMP_CLAUSE_LASTPRIVATE
);
10511 OMP_CLAUSE_DECL (l
) = OMP_CLAUSE_DECL (*c
);
10512 OMP_CLAUSE_CHAIN (l
) = clauses
;
10514 OMP_CLAUSE_SET_CODE (*c
, OMP_CLAUSE_SHARED
);
10518 OMP_FOR_CLAUSES (stmt
) = clauses
;
10523 while (!for_block
->is_empty ())
10525 /* FIXME diagnostics: LOC below should be the actual location of
10526 this particular for block. We need to build a list of
10527 locations to go along with FOR_BLOCK. */
10528 stmt
= c_end_compound_stmt (loc
, for_block
->pop (), true);
10531 release_tree_vector (for_block
);
10536 #pragma omp for for-clause[optseq] new-line
10539 LOC is the location of the #pragma token.
10542 #define OMP_FOR_CLAUSE_MASK \
10543 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
10544 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
10545 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
10546 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
10547 | (1u << PRAGMA_OMP_CLAUSE_ORDERED) \
10548 | (1u << PRAGMA_OMP_CLAUSE_SCHEDULE) \
10549 | (1u << PRAGMA_OMP_CLAUSE_COLLAPSE) \
10550 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
10553 c_parser_omp_for (location_t loc
, c_parser
*parser
)
10555 tree block
, clauses
, ret
;
10557 clauses
= c_parser_omp_all_clauses (parser
, OMP_FOR_CLAUSE_MASK
,
10558 "#pragma omp for");
10560 block
= c_begin_compound_stmt (true);
10561 ret
= c_parser_omp_for_loop (loc
, parser
, clauses
, NULL
);
10562 block
= c_end_compound_stmt (loc
, block
, true);
10569 # pragma omp master new-line
10572 LOC is the location of the #pragma token.
10576 c_parser_omp_master (location_t loc
, c_parser
*parser
)
10578 c_parser_skip_to_pragma_eol (parser
);
10579 return c_finish_omp_master (loc
, c_parser_omp_structured_block (parser
));
10583 # pragma omp ordered new-line
10586 LOC is the location of the #pragma itself.
10590 c_parser_omp_ordered (location_t loc
, c_parser
*parser
)
10592 c_parser_skip_to_pragma_eol (parser
);
10593 return c_finish_omp_ordered (loc
, c_parser_omp_structured_block (parser
));
10599 { section-sequence }
10602 section-directive[opt] structured-block
10603 section-sequence section-directive structured-block
10605 SECTIONS_LOC is the location of the #pragma omp sections. */
10608 c_parser_omp_sections_scope (location_t sections_loc
, c_parser
*parser
)
10610 tree stmt
, substmt
;
10611 bool error_suppress
= false;
10614 loc
= c_parser_peek_token (parser
)->location
;
10615 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
10617 /* Avoid skipping until the end of the block. */
10618 parser
->error
= false;
10622 stmt
= push_stmt_list ();
10624 if (c_parser_peek_token (parser
)->pragma_kind
!= PRAGMA_OMP_SECTION
)
10626 substmt
= push_stmt_list ();
10630 c_parser_statement (parser
);
10632 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
10634 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
10636 if (c_parser_next_token_is (parser
, CPP_EOF
))
10640 substmt
= pop_stmt_list (substmt
);
10641 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
10642 SET_EXPR_LOCATION (substmt
, loc
);
10643 add_stmt (substmt
);
10648 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
10650 if (c_parser_next_token_is (parser
, CPP_EOF
))
10653 loc
= c_parser_peek_token (parser
)->location
;
10654 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
10656 c_parser_consume_pragma (parser
);
10657 c_parser_skip_to_pragma_eol (parser
);
10658 error_suppress
= false;
10660 else if (!error_suppress
)
10662 error_at (loc
, "expected %<#pragma omp section%> or %<}%>");
10663 error_suppress
= true;
10666 substmt
= c_parser_omp_structured_block (parser
);
10667 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
10668 SET_EXPR_LOCATION (substmt
, loc
);
10669 add_stmt (substmt
);
10671 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
,
10672 "expected %<#pragma omp section%> or %<}%>");
10674 substmt
= pop_stmt_list (stmt
);
10676 stmt
= make_node (OMP_SECTIONS
);
10677 SET_EXPR_LOCATION (stmt
, sections_loc
);
10678 TREE_TYPE (stmt
) = void_type_node
;
10679 OMP_SECTIONS_BODY (stmt
) = substmt
;
10681 return add_stmt (stmt
);
10685 # pragma omp sections sections-clause[optseq] newline
10688 LOC is the location of the #pragma token.
10691 #define OMP_SECTIONS_CLAUSE_MASK \
10692 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
10693 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
10694 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
10695 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
10696 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
10699 c_parser_omp_sections (location_t loc
, c_parser
*parser
)
10701 tree block
, clauses
, ret
;
10703 clauses
= c_parser_omp_all_clauses (parser
, OMP_SECTIONS_CLAUSE_MASK
,
10704 "#pragma omp sections");
10706 block
= c_begin_compound_stmt (true);
10707 ret
= c_parser_omp_sections_scope (loc
, parser
);
10709 OMP_SECTIONS_CLAUSES (ret
) = clauses
;
10710 block
= c_end_compound_stmt (loc
, block
, true);
10717 # pragma parallel parallel-clause new-line
10718 # pragma parallel for parallel-for-clause new-line
10719 # pragma parallel sections parallel-sections-clause new-line
10721 LOC is the location of the #pragma token.
10724 #define OMP_PARALLEL_CLAUSE_MASK \
10725 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
10726 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
10727 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
10728 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
10729 | (1u << PRAGMA_OMP_CLAUSE_SHARED) \
10730 | (1u << PRAGMA_OMP_CLAUSE_COPYIN) \
10731 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
10732 | (1u << PRAGMA_OMP_CLAUSE_NUM_THREADS))
10735 c_parser_omp_parallel (location_t loc
, c_parser
*parser
)
10737 enum pragma_kind p_kind
= PRAGMA_OMP_PARALLEL
;
10738 const char *p_name
= "#pragma omp parallel";
10739 tree stmt
, clauses
, par_clause
, ws_clause
, block
;
10740 unsigned int mask
= OMP_PARALLEL_CLAUSE_MASK
;
10742 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
10744 c_parser_consume_token (parser
);
10745 p_kind
= PRAGMA_OMP_PARALLEL_FOR
;
10746 p_name
= "#pragma omp parallel for";
10747 mask
|= OMP_FOR_CLAUSE_MASK
;
10748 mask
&= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT
);
10750 else if (c_parser_next_token_is (parser
, CPP_NAME
))
10752 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10753 if (strcmp (p
, "sections") == 0)
10755 c_parser_consume_token (parser
);
10756 p_kind
= PRAGMA_OMP_PARALLEL_SECTIONS
;
10757 p_name
= "#pragma omp parallel sections";
10758 mask
|= OMP_SECTIONS_CLAUSE_MASK
;
10759 mask
&= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT
);
10763 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
);
10767 case PRAGMA_OMP_PARALLEL
:
10768 block
= c_begin_omp_parallel ();
10769 c_parser_statement (parser
);
10770 stmt
= c_finish_omp_parallel (loc
, clauses
, block
);
10773 case PRAGMA_OMP_PARALLEL_FOR
:
10774 block
= c_begin_omp_parallel ();
10775 c_split_parallel_clauses (loc
, clauses
, &par_clause
, &ws_clause
);
10776 c_parser_omp_for_loop (loc
, parser
, ws_clause
, &par_clause
);
10777 stmt
= c_finish_omp_parallel (loc
, par_clause
, block
);
10778 OMP_PARALLEL_COMBINED (stmt
) = 1;
10781 case PRAGMA_OMP_PARALLEL_SECTIONS
:
10782 block
= c_begin_omp_parallel ();
10783 c_split_parallel_clauses (loc
, clauses
, &par_clause
, &ws_clause
);
10784 stmt
= c_parser_omp_sections_scope (loc
, parser
);
10786 OMP_SECTIONS_CLAUSES (stmt
) = ws_clause
;
10787 stmt
= c_finish_omp_parallel (loc
, par_clause
, block
);
10788 OMP_PARALLEL_COMBINED (stmt
) = 1;
10792 gcc_unreachable ();
10799 # pragma omp single single-clause[optseq] new-line
10802 LOC is the location of the #pragma.
10805 #define OMP_SINGLE_CLAUSE_MASK \
10806 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
10807 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
10808 | (1u << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
10809 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
10812 c_parser_omp_single (location_t loc
, c_parser
*parser
)
10814 tree stmt
= make_node (OMP_SINGLE
);
10815 SET_EXPR_LOCATION (stmt
, loc
);
10816 TREE_TYPE (stmt
) = void_type_node
;
10818 OMP_SINGLE_CLAUSES (stmt
)
10819 = c_parser_omp_all_clauses (parser
, OMP_SINGLE_CLAUSE_MASK
,
10820 "#pragma omp single");
10821 OMP_SINGLE_BODY (stmt
) = c_parser_omp_structured_block (parser
);
10823 return add_stmt (stmt
);
10827 # pragma omp task task-clause[optseq] new-line
10829 LOC is the location of the #pragma.
10832 #define OMP_TASK_CLAUSE_MASK \
10833 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
10834 | (1u << PRAGMA_OMP_CLAUSE_UNTIED) \
10835 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
10836 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
10837 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
10838 | (1u << PRAGMA_OMP_CLAUSE_SHARED) \
10839 | (1u << PRAGMA_OMP_CLAUSE_FINAL) \
10840 | (1u << PRAGMA_OMP_CLAUSE_MERGEABLE))
10843 c_parser_omp_task (location_t loc
, c_parser
*parser
)
10845 tree clauses
, block
;
10847 clauses
= c_parser_omp_all_clauses (parser
, OMP_TASK_CLAUSE_MASK
,
10848 "#pragma omp task");
10850 block
= c_begin_omp_task ();
10851 c_parser_statement (parser
);
10852 return c_finish_omp_task (loc
, clauses
, block
);
10856 # pragma omp taskwait new-line
10860 c_parser_omp_taskwait (c_parser
*parser
)
10862 location_t loc
= c_parser_peek_token (parser
)->location
;
10863 c_parser_consume_pragma (parser
);
10864 c_parser_skip_to_pragma_eol (parser
);
10866 c_finish_omp_taskwait (loc
);
10870 # pragma omp taskyield new-line
10874 c_parser_omp_taskyield (c_parser
*parser
)
10876 location_t loc
= c_parser_peek_token (parser
)->location
;
10877 c_parser_consume_pragma (parser
);
10878 c_parser_skip_to_pragma_eol (parser
);
10880 c_finish_omp_taskyield (loc
);
10883 /* Main entry point to parsing most OpenMP pragmas. */
10886 c_parser_omp_construct (c_parser
*parser
)
10888 enum pragma_kind p_kind
;
10892 loc
= c_parser_peek_token (parser
)->location
;
10893 p_kind
= c_parser_peek_token (parser
)->pragma_kind
;
10894 c_parser_consume_pragma (parser
);
10898 case PRAGMA_OMP_ATOMIC
:
10899 c_parser_omp_atomic (loc
, parser
);
10901 case PRAGMA_OMP_CRITICAL
:
10902 stmt
= c_parser_omp_critical (loc
, parser
);
10904 case PRAGMA_OMP_FOR
:
10905 stmt
= c_parser_omp_for (loc
, parser
);
10907 case PRAGMA_OMP_MASTER
:
10908 stmt
= c_parser_omp_master (loc
, parser
);
10910 case PRAGMA_OMP_ORDERED
:
10911 stmt
= c_parser_omp_ordered (loc
, parser
);
10913 case PRAGMA_OMP_PARALLEL
:
10914 stmt
= c_parser_omp_parallel (loc
, parser
);
10916 case PRAGMA_OMP_SECTIONS
:
10917 stmt
= c_parser_omp_sections (loc
, parser
);
10919 case PRAGMA_OMP_SINGLE
:
10920 stmt
= c_parser_omp_single (loc
, parser
);
10922 case PRAGMA_OMP_TASK
:
10923 stmt
= c_parser_omp_task (loc
, parser
);
10926 gcc_unreachable ();
10930 gcc_assert (EXPR_LOCATION (stmt
) != UNKNOWN_LOCATION
);
10935 # pragma omp threadprivate (variable-list) */
10938 c_parser_omp_threadprivate (c_parser
*parser
)
10943 c_parser_consume_pragma (parser
);
10944 loc
= c_parser_peek_token (parser
)->location
;
10945 vars
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
10947 /* Mark every variable in VARS to be assigned thread local storage. */
10948 for (t
= vars
; t
; t
= TREE_CHAIN (t
))
10950 tree v
= TREE_PURPOSE (t
);
10952 /* FIXME diagnostics: Ideally we should keep individual
10953 locations for all the variables in the var list to make the
10954 following errors more precise. Perhaps
10955 c_parser_omp_var_list_parens() should construct a list of
10956 locations to go along with the var list. */
10958 /* If V had already been marked threadprivate, it doesn't matter
10959 whether it had been used prior to this point. */
10960 if (TREE_CODE (v
) != VAR_DECL
)
10961 error_at (loc
, "%qD is not a variable", v
);
10962 else if (TREE_USED (v
) && !C_DECL_THREADPRIVATE_P (v
))
10963 error_at (loc
, "%qE declared %<threadprivate%> after first use", v
);
10964 else if (! TREE_STATIC (v
) && ! DECL_EXTERNAL (v
))
10965 error_at (loc
, "automatic variable %qE cannot be %<threadprivate%>", v
);
10966 else if (TREE_TYPE (v
) == error_mark_node
)
10968 else if (! COMPLETE_TYPE_P (TREE_TYPE (v
)))
10969 error_at (loc
, "%<threadprivate%> %qE has incomplete type", v
);
10972 if (! DECL_THREAD_LOCAL_P (v
))
10974 DECL_TLS_MODEL (v
) = decl_default_tls_model (v
);
10975 /* If rtl has been already set for this var, call
10976 make_decl_rtl once again, so that encode_section_info
10977 has a chance to look at the new decl flags. */
10978 if (DECL_RTL_SET_P (v
))
10981 C_DECL_THREADPRIVATE_P (v
) = 1;
10985 c_parser_skip_to_pragma_eol (parser
);
10988 /* Parse a transaction attribute (GCC Extension).
10990 transaction-attribute:
10994 The transactional memory language description is written for C++,
10995 and uses the C++0x attribute syntax. For compatibility, allow the
10996 bracket style for transactions in C as well. */
10999 c_parser_transaction_attributes (c_parser
*parser
)
11001 tree attr_name
, attr
= NULL
;
11003 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
11004 return c_parser_attributes (parser
);
11006 if (!c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
11008 c_parser_consume_token (parser
);
11009 if (!c_parser_require (parser
, CPP_OPEN_SQUARE
, "expected %<[%>"))
11012 attr_name
= c_parser_attribute_any_word (parser
);
11015 c_parser_consume_token (parser
);
11016 attr
= build_tree_list (attr_name
, NULL_TREE
);
11019 c_parser_error (parser
, "expected identifier");
11021 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
11023 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
11027 /* Parse a __transaction_atomic or __transaction_relaxed statement
11030 transaction-statement:
11031 __transaction_atomic transaction-attribute[opt] compound-statement
11032 __transaction_relaxed compound-statement
11034 Note that the only valid attribute is: "outer".
11038 c_parser_transaction (c_parser
*parser
, enum rid keyword
)
11040 unsigned int old_in
= parser
->in_transaction
;
11041 unsigned int this_in
= 1, new_in
;
11042 location_t loc
= c_parser_peek_token (parser
)->location
;
11045 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
11046 || keyword
== RID_TRANSACTION_RELAXED
)
11047 && c_parser_next_token_is_keyword (parser
, keyword
));
11048 c_parser_consume_token (parser
);
11050 if (keyword
== RID_TRANSACTION_RELAXED
)
11051 this_in
|= TM_STMT_ATTR_RELAXED
;
11054 attrs
= c_parser_transaction_attributes (parser
);
11056 this_in
|= parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
);
11059 /* Keep track if we're in the lexical scope of an outer transaction. */
11060 new_in
= this_in
| (old_in
& TM_STMT_ATTR_OUTER
);
11062 parser
->in_transaction
= new_in
;
11063 stmt
= c_parser_compound_statement (parser
);
11064 parser
->in_transaction
= old_in
;
11067 stmt
= c_finish_transaction (loc
, stmt
, this_in
);
11069 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
11070 "%<__transaction_atomic%> without transactional memory support enabled"
11071 : "%<__transaction_relaxed %> "
11072 "without transactional memory support enabled"));
11077 /* Parse a __transaction_atomic or __transaction_relaxed expression
11080 transaction-expression:
11081 __transaction_atomic ( expression )
11082 __transaction_relaxed ( expression )
11085 static struct c_expr
11086 c_parser_transaction_expression (c_parser
*parser
, enum rid keyword
)
11089 unsigned int old_in
= parser
->in_transaction
;
11090 unsigned int this_in
= 1;
11091 location_t loc
= c_parser_peek_token (parser
)->location
;
11094 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
11095 || keyword
== RID_TRANSACTION_RELAXED
)
11096 && c_parser_next_token_is_keyword (parser
, keyword
));
11097 c_parser_consume_token (parser
);
11099 if (keyword
== RID_TRANSACTION_RELAXED
)
11100 this_in
|= TM_STMT_ATTR_RELAXED
;
11103 attrs
= c_parser_transaction_attributes (parser
);
11105 this_in
|= parse_tm_stmt_attr (attrs
, 0);
11108 parser
->in_transaction
= this_in
;
11109 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11111 tree expr
= c_parser_expression (parser
).value
;
11112 ret
.original_type
= TREE_TYPE (expr
);
11113 ret
.value
= build1 (TRANSACTION_EXPR
, ret
.original_type
, expr
);
11114 if (this_in
& TM_STMT_ATTR_RELAXED
)
11115 TRANSACTION_EXPR_RELAXED (ret
.value
) = 1;
11116 SET_EXPR_LOCATION (ret
.value
, loc
);
11117 ret
.original_code
= TRANSACTION_EXPR
;
11118 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
11120 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
11127 ret
.value
= error_mark_node
;
11128 ret
.original_code
= ERROR_MARK
;
11129 ret
.original_type
= NULL
;
11131 parser
->in_transaction
= old_in
;
11134 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
11135 "%<__transaction_atomic%> without transactional memory support enabled"
11136 : "%<__transaction_relaxed %> "
11137 "without transactional memory support enabled"));
11142 /* Parse a __transaction_cancel statement (GCC Extension).
11144 transaction-cancel-statement:
11145 __transaction_cancel transaction-attribute[opt] ;
11147 Note that the only valid attribute is "outer".
11151 c_parser_transaction_cancel(c_parser
*parser
)
11153 location_t loc
= c_parser_peek_token (parser
)->location
;
11155 bool is_outer
= false;
11157 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TRANSACTION_CANCEL
));
11158 c_parser_consume_token (parser
);
11160 attrs
= c_parser_transaction_attributes (parser
);
11162 is_outer
= (parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
) != 0);
11166 error_at (loc
, "%<__transaction_cancel%> without "
11167 "transactional memory support enabled");
11170 else if (parser
->in_transaction
& TM_STMT_ATTR_RELAXED
)
11172 error_at (loc
, "%<__transaction_cancel%> within a "
11173 "%<__transaction_relaxed%>");
11178 if ((parser
->in_transaction
& TM_STMT_ATTR_OUTER
) == 0
11179 && !is_tm_may_cancel_outer (current_function_decl
))
11181 error_at (loc
, "outer %<__transaction_cancel%> not "
11182 "within outer %<__transaction_atomic%>");
11183 error_at (loc
, " or a %<transaction_may_cancel_outer%> function");
11187 else if (parser
->in_transaction
== 0)
11189 error_at (loc
, "%<__transaction_cancel%> not within "
11190 "%<__transaction_atomic%>");
11194 return add_stmt (build_tm_abort_call (loc
, is_outer
));
11197 return build1 (NOP_EXPR
, void_type_node
, error_mark_node
);
11200 /* Parse a single source file. */
11203 c_parse_file (void)
11205 /* Use local storage to begin. If the first token is a pragma, parse it.
11206 If it is #pragma GCC pch_preprocess, then this will load a PCH file
11207 which will cause garbage collection. */
11210 memset (&tparser
, 0, sizeof tparser
);
11211 the_parser
= &tparser
;
11213 if (c_parser_peek_token (&tparser
)->pragma_kind
== PRAGMA_GCC_PCH_PREPROCESS
)
11214 c_parser_pragma_pch_preprocess (&tparser
);
11216 the_parser
= ggc_alloc_c_parser ();
11217 *the_parser
= tparser
;
11219 /* Initialize EH, if we've been told to do so. */
11220 if (flag_exceptions
)
11221 using_eh_for_cleanups ();
11223 c_parser_translation_unit (the_parser
);
11227 /* This function parses Cilk Plus array notation. The starting index is
11228 passed in INITIAL_INDEX and the array name is passes in ARRAY_VALUE. The
11229 return value of this function is a tree_node called VALUE_TREE of type
11230 ARRAY_NOTATION_REF. */
11233 c_parser_array_notation (location_t loc
, c_parser
*parser
, tree initial_index
,
11236 c_token
*token
= NULL
;
11237 tree start_index
= NULL_TREE
, end_index
= NULL_TREE
, stride
= NULL_TREE
;
11238 tree value_tree
= NULL_TREE
, type
= NULL_TREE
, array_type
= NULL_TREE
;
11239 tree array_type_domain
= NULL_TREE
;
11241 if (array_value
== error_mark_node
)
11243 /* No need to continue. If either of these 2 were true, then an error
11244 must be emitted already. Thus, no need to emit them twice. */
11245 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
11246 return error_mark_node
;
11249 array_type
= TREE_TYPE (array_value
);
11250 gcc_assert (array_type
);
11251 type
= TREE_TYPE (array_type
);
11252 token
= c_parser_peek_token (parser
);
11254 if (token
->type
== CPP_EOF
)
11256 c_parser_error (parser
, "expected %<:%> or numeral");
11259 else if (token
->type
== CPP_COLON
)
11261 if (!initial_index
)
11263 /* If we are here, then we have a case like this A[:]. */
11264 c_parser_consume_token (parser
);
11265 if (TREE_CODE (array_type
) == POINTER_TYPE
)
11267 error_at (loc
, "start-index and length fields necessary for "
11268 "using array notations in pointers");
11269 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
11270 return error_mark_node
;
11272 if (TREE_CODE (array_type
) == FUNCTION_TYPE
)
11274 error_at (loc
, "array notations cannot be used with function "
11276 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
11277 return error_mark_node
;
11279 array_type_domain
= TYPE_DOMAIN (array_type
);
11281 if (!array_type_domain
)
11283 error_at (loc
, "start-index and length fields necessary for "
11284 "using array notations in dimensionless arrays");
11285 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
11286 return error_mark_node
;
11289 start_index
= TYPE_MINVAL (array_type_domain
);
11290 start_index
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
,
11292 if (!TYPE_MAXVAL (array_type_domain
)
11293 || !TREE_CONSTANT (TYPE_MAXVAL (array_type_domain
)))
11295 error_at (loc
, "start-index and length fields necessary for "
11296 "using array notations in variable-length arrays");
11297 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
11298 return error_mark_node
;
11300 end_index
= TYPE_MAXVAL (array_type_domain
);
11301 end_index
= fold_build2 (PLUS_EXPR
, TREE_TYPE (end_index
),
11302 end_index
, integer_one_node
);
11303 end_index
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
, end_index
);
11304 stride
= build_int_cst (integer_type_node
, 1);
11305 stride
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
, stride
);
11307 else if (initial_index
!= error_mark_node
)
11309 /* If we are here, then there should be 2 possibilities:
11310 1. Array [EXPR : EXPR]
11311 2. Array [EXPR : EXPR : EXPR]
11313 start_index
= initial_index
;
11315 if (TREE_CODE (array_type
) == FUNCTION_TYPE
)
11317 error_at (loc
, "array notations cannot be used with function "
11319 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
11320 return error_mark_node
;
11322 c_parser_consume_token (parser
); /* consume the ':' */
11323 end_index
= c_parser_expression (parser
).value
;
11324 if (!end_index
|| end_index
== error_mark_node
)
11326 c_parser_skip_to_end_of_block_or_statement (parser
);
11327 return error_mark_node
;
11329 if (c_parser_peek_token (parser
)->type
== CPP_COLON
)
11331 c_parser_consume_token (parser
);
11332 stride
= c_parser_expression (parser
).value
;
11333 if (!stride
|| stride
== error_mark_node
)
11335 c_parser_skip_to_end_of_block_or_statement (parser
);
11336 return error_mark_node
;
11341 c_parser_error (parser
, "expected array notation expression");
11344 c_parser_error (parser
, "expected array notation expression");
11346 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
11348 value_tree
= build_array_notation_ref (loc
, array_value
, start_index
,
11349 end_index
, stride
, type
);
11350 if (value_tree
!= error_mark_node
)
11351 SET_EXPR_LOCATION (value_tree
, loc
);
11355 #include "gt-c-c-parser.h"