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
);
1761 tree decl
= current_function_decl
;
1762 /* Mark nested functions as needing static-chain initially.
1763 lower_nested_functions will recompute it but the
1764 DECL_STATIC_CHAIN flag is also used before that happens,
1765 by initializer_constant_valid_p. See gcc.dg/nested-fn-2.c. */
1766 DECL_STATIC_CHAIN (decl
) = 1;
1769 c_pop_function_context ();
1770 add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl
), DECL_EXPR
, decl
));
1783 /* Parse an asm-definition (asm() outside a function body). This is a
1791 c_parser_asm_definition (c_parser
*parser
)
1793 tree asm_str
= c_parser_simple_asm_expr (parser
);
1795 add_asm_node (asm_str
);
1796 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
1799 /* Parse a static assertion (C11 6.7.10).
1801 static_assert-declaration:
1802 static_assert-declaration-no-semi ;
1806 c_parser_static_assert_declaration (c_parser
*parser
)
1808 c_parser_static_assert_declaration_no_semi (parser
);
1810 || !c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
1811 c_parser_skip_to_end_of_block_or_statement (parser
);
1814 /* Parse a static assertion (C11 6.7.10), without the trailing
1817 static_assert-declaration-no-semi:
1818 _Static_assert ( constant-expression , string-literal )
1822 c_parser_static_assert_declaration_no_semi (c_parser
*parser
)
1824 location_t assert_loc
, value_loc
;
1828 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
));
1829 assert_loc
= c_parser_peek_token (parser
)->location
;
1833 pedwarn (assert_loc
, OPT_Wpedantic
,
1834 "ISO C99 does not support %<_Static_assert%>");
1836 pedwarn (assert_loc
, OPT_Wpedantic
,
1837 "ISO C90 does not support %<_Static_assert%>");
1839 c_parser_consume_token (parser
);
1840 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
1842 value_loc
= c_parser_peek_token (parser
)->location
;
1843 value
= c_parser_expr_no_commas (parser
, NULL
).value
;
1844 parser
->lex_untranslated_string
= true;
1845 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
1847 parser
->lex_untranslated_string
= false;
1850 switch (c_parser_peek_token (parser
)->type
)
1856 case CPP_UTF8STRING
:
1857 string
= c_parser_peek_token (parser
)->value
;
1858 c_parser_consume_token (parser
);
1859 parser
->lex_untranslated_string
= false;
1862 c_parser_error (parser
, "expected string literal");
1863 parser
->lex_untranslated_string
= false;
1866 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
1868 if (!INTEGRAL_TYPE_P (TREE_TYPE (value
)))
1870 error_at (value_loc
, "expression in static assertion is not an integer");
1873 if (TREE_CODE (value
) != INTEGER_CST
)
1875 value
= c_fully_fold (value
, false, NULL
);
1876 if (TREE_CODE (value
) == INTEGER_CST
)
1877 pedwarn (value_loc
, OPT_Wpedantic
, "expression in static assertion "
1878 "is not an integer constant expression");
1880 if (TREE_CODE (value
) != INTEGER_CST
)
1882 error_at (value_loc
, "expression in static assertion is not constant");
1885 constant_expression_warning (value
);
1886 if (integer_zerop (value
))
1887 error_at (assert_loc
, "static assertion failed: %E", string
);
1890 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
1891 6.7), adding them to SPECS (which may already include some).
1892 Storage class specifiers are accepted iff SCSPEC_OK; type
1893 specifiers are accepted iff TYPESPEC_OK; attributes are accepted at
1894 the start iff START_ATTR_OK.
1896 declaration-specifiers:
1897 storage-class-specifier declaration-specifiers[opt]
1898 type-specifier declaration-specifiers[opt]
1899 type-qualifier declaration-specifiers[opt]
1900 function-specifier declaration-specifiers[opt]
1901 alignment-specifier declaration-specifiers[opt]
1903 Function specifiers (inline) are from C99, and are currently
1904 handled as storage class specifiers, as is __thread. Alignment
1905 specifiers are from C11.
1907 C90 6.5.1, C99 6.7.1:
1908 storage-class-specifier:
1920 (_Noreturn is new in C11.)
1922 C90 6.5.2, C99 6.7.2:
1935 [_Imaginary removed in C99 TC2]
1936 struct-or-union-specifier
1940 (_Bool and _Complex are new in C99.)
1942 C90 6.5.3, C99 6.7.3:
1948 address-space-qualifier
1950 (restrict is new in C99.)
1954 declaration-specifiers:
1955 attributes declaration-specifiers[opt]
1961 identifier recognized by the target
1963 storage-class-specifier:
1976 (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
1977 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
1982 class-name objc-protocol-refs[opt]
1983 typedef-name objc-protocol-refs
1988 c_parser_declspecs (c_parser
*parser
, struct c_declspecs
*specs
,
1989 bool scspec_ok
, bool typespec_ok
, bool start_attr_ok
,
1990 enum c_lookahead_kind la
)
1992 bool attrs_ok
= start_attr_ok
;
1993 bool seen_type
= specs
->typespec_kind
!= ctsk_none
;
1996 gcc_assert (la
== cla_prefer_id
);
1998 while (c_parser_next_token_is (parser
, CPP_NAME
)
1999 || c_parser_next_token_is (parser
, CPP_KEYWORD
)
2000 || (c_dialect_objc () && c_parser_next_token_is (parser
, CPP_LESS
)))
2002 struct c_typespec t
;
2005 location_t loc
= c_parser_peek_token (parser
)->location
;
2007 /* If we cannot accept a type, exit if the next token must start
2008 one. Also, if we already have seen a tagged definition,
2009 a typename would be an error anyway and likely the user
2010 has simply forgotten a semicolon, so we exit. */
2011 if ((!typespec_ok
|| specs
->typespec_kind
== ctsk_tagdef
)
2012 && c_parser_next_tokens_start_typename (parser
, la
)
2013 && !c_parser_next_token_is_qualifier (parser
))
2016 if (c_parser_next_token_is (parser
, CPP_NAME
))
2018 c_token
*name_token
= c_parser_peek_token (parser
);
2019 tree value
= name_token
->value
;
2020 c_id_kind kind
= name_token
->id_kind
;
2022 if (kind
== C_ID_ADDRSPACE
)
2025 = name_token
->keyword
- RID_FIRST_ADDR_SPACE
;
2026 declspecs_add_addrspace (name_token
->location
, specs
, as
);
2027 c_parser_consume_token (parser
);
2032 gcc_assert (!c_parser_next_token_is_qualifier (parser
));
2034 /* If we cannot accept a type, and the next token must start one,
2035 exit. Do the same if we already have seen a tagged definition,
2036 since it would be an error anyway and likely the user has simply
2037 forgotten a semicolon. */
2038 if (seen_type
|| !c_parser_next_tokens_start_typename (parser
, la
))
2041 /* Now at an unknown typename (C_ID_ID), a C_ID_TYPENAME or
2042 a C_ID_CLASSNAME. */
2043 c_parser_consume_token (parser
);
2046 if (kind
== C_ID_ID
)
2048 error ("unknown type name %qE", value
);
2049 t
.kind
= ctsk_typedef
;
2050 t
.spec
= error_mark_node
;
2052 else if (kind
== C_ID_TYPENAME
2053 && (!c_dialect_objc ()
2054 || c_parser_next_token_is_not (parser
, CPP_LESS
)))
2056 t
.kind
= ctsk_typedef
;
2057 /* For a typedef name, record the meaning, not the name.
2058 In case of 'foo foo, bar;'. */
2059 t
.spec
= lookup_name (value
);
2063 tree proto
= NULL_TREE
;
2064 gcc_assert (c_dialect_objc ());
2066 if (c_parser_next_token_is (parser
, CPP_LESS
))
2067 proto
= c_parser_objc_protocol_refs (parser
);
2068 t
.spec
= objc_get_protocol_qualified_type (value
, proto
);
2071 t
.expr_const_operands
= true;
2072 declspecs_add_type (name_token
->location
, specs
, t
);
2075 if (c_parser_next_token_is (parser
, CPP_LESS
))
2077 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
2078 nisse@lysator.liu.se. */
2080 gcc_assert (c_dialect_objc ());
2081 if (!typespec_ok
|| seen_type
)
2083 proto
= c_parser_objc_protocol_refs (parser
);
2085 t
.spec
= objc_get_protocol_qualified_type (NULL_TREE
, proto
);
2087 t
.expr_const_operands
= true;
2088 declspecs_add_type (loc
, specs
, t
);
2091 gcc_assert (c_parser_next_token_is (parser
, CPP_KEYWORD
));
2092 switch (c_parser_peek_token (parser
)->keyword
)
2105 /* TODO: Distinguish between function specifiers (inline, noreturn)
2106 and storage class specifiers, either here or in
2107 declspecs_add_scspec. */
2108 declspecs_add_scspec (loc
, specs
,
2109 c_parser_peek_token (parser
)->value
);
2110 c_parser_consume_token (parser
);
2134 if (c_dialect_objc ())
2135 parser
->objc_need_raw_identifier
= true;
2136 t
.kind
= ctsk_resword
;
2137 t
.spec
= c_parser_peek_token (parser
)->value
;
2139 t
.expr_const_operands
= true;
2140 declspecs_add_type (loc
, specs
, t
);
2141 c_parser_consume_token (parser
);
2148 t
= c_parser_enum_specifier (parser
);
2149 declspecs_add_type (loc
, specs
, t
);
2157 t
= c_parser_struct_or_union_specifier (parser
);
2158 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE
, t
.spec
);
2159 declspecs_add_type (loc
, specs
, t
);
2162 /* ??? The old parser rejected typeof after other type
2163 specifiers, but is a syntax error the best way of
2165 if (!typespec_ok
|| seen_type
)
2169 t
= c_parser_typeof_specifier (parser
);
2170 declspecs_add_type (loc
, specs
, t
);
2176 declspecs_add_qual (loc
, specs
, c_parser_peek_token (parser
)->value
);
2177 c_parser_consume_token (parser
);
2182 attrs
= c_parser_attributes (parser
);
2183 declspecs_add_attrs (loc
, specs
, attrs
);
2186 align
= c_parser_alignas_specifier (parser
);
2187 declspecs_add_alignas (loc
, specs
, align
);
2196 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
2199 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
2200 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
2201 enum attributes[opt] identifier
2203 The form with trailing comma is new in C99. The forms with
2204 attributes are GNU extensions. In GNU C, we accept any expression
2205 without commas in the syntax (assignment expressions, not just
2206 conditional expressions); assignment expressions will be diagnosed
2211 enumerator-list , enumerator
2214 enumeration-constant
2215 enumeration-constant = constant-expression
2218 static struct c_typespec
2219 c_parser_enum_specifier (c_parser
*parser
)
2221 struct c_typespec ret
;
2223 tree ident
= NULL_TREE
;
2224 location_t enum_loc
;
2225 location_t ident_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2226 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ENUM
));
2227 enum_loc
= c_parser_peek_token (parser
)->location
;
2228 c_parser_consume_token (parser
);
2229 attrs
= c_parser_attributes (parser
);
2230 enum_loc
= c_parser_peek_token (parser
)->location
;
2231 /* Set the location in case we create a decl now. */
2232 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2233 if (c_parser_next_token_is (parser
, CPP_NAME
))
2235 ident
= c_parser_peek_token (parser
)->value
;
2236 ident_loc
= c_parser_peek_token (parser
)->location
;
2237 enum_loc
= ident_loc
;
2238 c_parser_consume_token (parser
);
2240 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2242 /* Parse an enum definition. */
2243 struct c_enum_contents the_enum
;
2246 /* We chain the enumerators in reverse order, then put them in
2247 forward order at the end. */
2249 timevar_push (TV_PARSE_ENUM
);
2250 type
= start_enum (enum_loc
, &the_enum
, ident
);
2252 c_parser_consume_token (parser
);
2260 location_t comma_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2261 location_t decl_loc
, value_loc
;
2262 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
2264 c_parser_error (parser
, "expected identifier");
2265 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2266 values
= error_mark_node
;
2269 token
= c_parser_peek_token (parser
);
2270 enum_id
= token
->value
;
2271 /* Set the location in case we create a decl now. */
2272 c_parser_set_source_position_from_token (token
);
2273 decl_loc
= value_loc
= token
->location
;
2274 c_parser_consume_token (parser
);
2275 if (c_parser_next_token_is (parser
, CPP_EQ
))
2277 c_parser_consume_token (parser
);
2278 value_loc
= c_parser_peek_token (parser
)->location
;
2279 enum_value
= c_parser_expr_no_commas (parser
, NULL
).value
;
2282 enum_value
= NULL_TREE
;
2283 enum_decl
= build_enumerator (decl_loc
, value_loc
,
2284 &the_enum
, enum_id
, enum_value
);
2285 TREE_CHAIN (enum_decl
) = values
;
2288 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2290 comma_loc
= c_parser_peek_token (parser
)->location
;
2292 c_parser_consume_token (parser
);
2294 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2296 if (seen_comma
&& !flag_isoc99
)
2297 pedwarn (comma_loc
, OPT_Wpedantic
, "comma at end of enumerator list");
2298 c_parser_consume_token (parser
);
2303 c_parser_error (parser
, "expected %<,%> or %<}%>");
2304 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2305 values
= error_mark_node
;
2309 postfix_attrs
= c_parser_attributes (parser
);
2310 ret
.spec
= finish_enum (type
, nreverse (values
),
2311 chainon (attrs
, postfix_attrs
));
2312 ret
.kind
= ctsk_tagdef
;
2313 ret
.expr
= NULL_TREE
;
2314 ret
.expr_const_operands
= true;
2315 timevar_pop (TV_PARSE_ENUM
);
2320 c_parser_error (parser
, "expected %<{%>");
2321 ret
.spec
= error_mark_node
;
2322 ret
.kind
= ctsk_tagref
;
2323 ret
.expr
= NULL_TREE
;
2324 ret
.expr_const_operands
= true;
2327 ret
= parser_xref_tag (ident_loc
, ENUMERAL_TYPE
, ident
);
2328 /* In ISO C, enumerated types can be referred to only if already
2330 if (pedantic
&& !COMPLETE_TYPE_P (ret
.spec
))
2333 pedwarn (enum_loc
, OPT_Wpedantic
,
2334 "ISO C forbids forward references to %<enum%> types");
2339 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
2341 struct-or-union-specifier:
2342 struct-or-union attributes[opt] identifier[opt]
2343 { struct-contents } attributes[opt]
2344 struct-or-union attributes[opt] identifier
2347 struct-declaration-list
2349 struct-declaration-list:
2350 struct-declaration ;
2351 struct-declaration-list struct-declaration ;
2358 struct-declaration-list struct-declaration
2360 struct-declaration-list:
2361 struct-declaration-list ;
2364 (Note that in the syntax here, unlike that in ISO C, the semicolons
2365 are included here rather than in struct-declaration, in order to
2366 describe the syntax with extra semicolons and missing semicolon at
2371 struct-declaration-list:
2372 @defs ( class-name )
2374 (Note this does not include a trailing semicolon, but can be
2375 followed by further declarations, and gets a pedwarn-if-pedantic
2376 when followed by a semicolon.) */
2378 static struct c_typespec
2379 c_parser_struct_or_union_specifier (c_parser
*parser
)
2381 struct c_typespec ret
;
2383 tree ident
= NULL_TREE
;
2384 location_t struct_loc
;
2385 location_t ident_loc
= UNKNOWN_LOCATION
;
2386 enum tree_code code
;
2387 switch (c_parser_peek_token (parser
)->keyword
)
2398 struct_loc
= c_parser_peek_token (parser
)->location
;
2399 c_parser_consume_token (parser
);
2400 attrs
= c_parser_attributes (parser
);
2402 /* Set the location in case we create a decl now. */
2403 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2405 if (c_parser_next_token_is (parser
, CPP_NAME
))
2407 ident
= c_parser_peek_token (parser
)->value
;
2408 ident_loc
= c_parser_peek_token (parser
)->location
;
2409 struct_loc
= ident_loc
;
2410 c_parser_consume_token (parser
);
2412 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2414 /* Parse a struct or union definition. Start the scope of the
2415 tag before parsing components. */
2416 struct c_struct_parse_info
*struct_info
;
2417 tree type
= start_struct (struct_loc
, code
, ident
, &struct_info
);
2419 /* We chain the components in reverse order, then put them in
2420 forward order at the end. Each struct-declaration may
2421 declare multiple components (comma-separated), so we must use
2422 chainon to join them, although when parsing each
2423 struct-declaration we can use TREE_CHAIN directly.
2425 The theory behind all this is that there will be more
2426 semicolon separated fields than comma separated fields, and
2427 so we'll be minimizing the number of node traversals required
2430 timevar_push (TV_PARSE_STRUCT
);
2431 contents
= NULL_TREE
;
2432 c_parser_consume_token (parser
);
2433 /* Handle the Objective-C @defs construct,
2434 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
2435 if (c_parser_next_token_is_keyword (parser
, RID_AT_DEFS
))
2438 gcc_assert (c_dialect_objc ());
2439 c_parser_consume_token (parser
);
2440 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2442 if (c_parser_next_token_is (parser
, CPP_NAME
)
2443 && c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
)
2445 name
= c_parser_peek_token (parser
)->value
;
2446 c_parser_consume_token (parser
);
2450 c_parser_error (parser
, "expected class name");
2451 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2454 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2456 contents
= nreverse (objc_get_class_ivars (name
));
2459 /* Parse the struct-declarations and semicolons. Problems with
2460 semicolons are diagnosed here; empty structures are diagnosed
2465 /* Parse any stray semicolon. */
2466 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2468 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
2469 "extra semicolon in struct or union specified");
2470 c_parser_consume_token (parser
);
2473 /* Stop if at the end of the struct or union contents. */
2474 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2476 c_parser_consume_token (parser
);
2479 /* Accept #pragmas at struct scope. */
2480 if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
2482 c_parser_pragma (parser
, pragma_external
);
2485 /* Parse some comma-separated declarations, but not the
2486 trailing semicolon if any. */
2487 decls
= c_parser_struct_declaration (parser
);
2488 contents
= chainon (decls
, contents
);
2489 /* If no semicolon follows, either we have a parse error or
2490 are at the end of the struct or union and should
2492 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2493 c_parser_consume_token (parser
);
2496 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2497 pedwarn (c_parser_peek_token (parser
)->location
, 0,
2498 "no semicolon at end of struct or union");
2499 else if (parser
->error
2500 || !c_parser_next_token_starts_declspecs (parser
))
2502 c_parser_error (parser
, "expected %<;%>");
2503 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2507 /* If we come here, we have already emitted an error
2508 for an expected `;', identifier or `(', and we also
2509 recovered already. Go on with the next field. */
2512 postfix_attrs
= c_parser_attributes (parser
);
2513 ret
.spec
= finish_struct (struct_loc
, type
, nreverse (contents
),
2514 chainon (attrs
, postfix_attrs
), struct_info
);
2515 ret
.kind
= ctsk_tagdef
;
2516 ret
.expr
= NULL_TREE
;
2517 ret
.expr_const_operands
= true;
2518 timevar_pop (TV_PARSE_STRUCT
);
2523 c_parser_error (parser
, "expected %<{%>");
2524 ret
.spec
= error_mark_node
;
2525 ret
.kind
= ctsk_tagref
;
2526 ret
.expr
= NULL_TREE
;
2527 ret
.expr_const_operands
= true;
2530 ret
= parser_xref_tag (ident_loc
, code
, ident
);
2534 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
2535 the trailing semicolon.
2538 specifier-qualifier-list struct-declarator-list
2539 static_assert-declaration-no-semi
2541 specifier-qualifier-list:
2542 type-specifier specifier-qualifier-list[opt]
2543 type-qualifier specifier-qualifier-list[opt]
2544 attributes specifier-qualifier-list[opt]
2546 struct-declarator-list:
2548 struct-declarator-list , attributes[opt] struct-declarator
2551 declarator attributes[opt]
2552 declarator[opt] : constant-expression attributes[opt]
2557 __extension__ struct-declaration
2558 specifier-qualifier-list
2560 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
2561 of attributes where shown is a GNU extension. In GNU C, we accept
2562 any expression without commas in the syntax (assignment
2563 expressions, not just conditional expressions); assignment
2564 expressions will be diagnosed as non-constant. */
2567 c_parser_struct_declaration (c_parser
*parser
)
2569 struct c_declspecs
*specs
;
2571 tree all_prefix_attrs
;
2573 location_t decl_loc
;
2574 if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
2578 ext
= disable_extension_diagnostics ();
2579 c_parser_consume_token (parser
);
2580 decl
= c_parser_struct_declaration (parser
);
2581 restore_extension_diagnostics (ext
);
2584 if (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
2586 c_parser_static_assert_declaration_no_semi (parser
);
2589 specs
= build_null_declspecs ();
2590 decl_loc
= c_parser_peek_token (parser
)->location
;
2591 c_parser_declspecs (parser
, specs
, false, true, true, cla_nonabstract_decl
);
2594 if (!specs
->declspecs_seen_p
)
2596 c_parser_error (parser
, "expected specifier-qualifier-list");
2599 finish_declspecs (specs
);
2600 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2601 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2604 if (specs
->typespec_kind
== ctsk_none
)
2606 pedwarn (decl_loc
, OPT_Wpedantic
,
2607 "ISO C forbids member declarations with no members");
2608 shadow_tag_warned (specs
, pedantic
);
2613 /* Support for unnamed structs or unions as members of
2614 structs or unions (which is [a] useful and [b] supports
2618 ret
= grokfield (c_parser_peek_token (parser
)->location
,
2619 build_id_declarator (NULL_TREE
), specs
,
2622 decl_attributes (&ret
, attrs
, 0);
2627 /* Provide better error recovery. Note that a type name here is valid,
2628 and will be treated as a field name. */
2629 if (specs
->typespec_kind
== ctsk_tagdef
2630 && TREE_CODE (specs
->type
) != ENUMERAL_TYPE
2631 && c_parser_next_token_starts_declspecs (parser
)
2632 && !c_parser_next_token_is (parser
, CPP_NAME
))
2634 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
2635 parser
->error
= false;
2639 pending_xref_error ();
2640 prefix_attrs
= specs
->attrs
;
2641 all_prefix_attrs
= prefix_attrs
;
2642 specs
->attrs
= NULL_TREE
;
2646 /* Declaring one or more declarators or un-named bit-fields. */
2647 struct c_declarator
*declarator
;
2649 if (c_parser_next_token_is (parser
, CPP_COLON
))
2650 declarator
= build_id_declarator (NULL_TREE
);
2652 declarator
= c_parser_declarator (parser
,
2653 specs
->typespec_kind
!= ctsk_none
,
2654 C_DTR_NORMAL
, &dummy
);
2655 if (declarator
== NULL
)
2657 c_parser_skip_to_end_of_block_or_statement (parser
);
2660 if (c_parser_next_token_is (parser
, CPP_COLON
)
2661 || c_parser_next_token_is (parser
, CPP_COMMA
)
2662 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2663 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
)
2664 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2666 tree postfix_attrs
= NULL_TREE
;
2667 tree width
= NULL_TREE
;
2669 if (c_parser_next_token_is (parser
, CPP_COLON
))
2671 c_parser_consume_token (parser
);
2672 width
= c_parser_expr_no_commas (parser
, NULL
).value
;
2674 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2675 postfix_attrs
= c_parser_attributes (parser
);
2676 d
= grokfield (c_parser_peek_token (parser
)->location
,
2677 declarator
, specs
, width
, &all_prefix_attrs
);
2678 decl_attributes (&d
, chainon (postfix_attrs
,
2679 all_prefix_attrs
), 0);
2680 DECL_CHAIN (d
) = decls
;
2682 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2683 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
2686 all_prefix_attrs
= prefix_attrs
;
2687 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2688 c_parser_consume_token (parser
);
2689 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2690 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2692 /* Semicolon consumed in caller. */
2697 c_parser_error (parser
, "expected %<,%>, %<;%> or %<}%>");
2703 c_parser_error (parser
,
2704 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
2705 "%<__attribute__%>");
2712 /* Parse a typeof specifier (a GNU extension).
2715 typeof ( expression )
2716 typeof ( type-name )
2719 static struct c_typespec
2720 c_parser_typeof_specifier (c_parser
*parser
)
2722 struct c_typespec ret
;
2723 ret
.kind
= ctsk_typeof
;
2724 ret
.spec
= error_mark_node
;
2725 ret
.expr
= NULL_TREE
;
2726 ret
.expr_const_operands
= true;
2727 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TYPEOF
));
2728 c_parser_consume_token (parser
);
2729 c_inhibit_evaluation_warnings
++;
2731 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2733 c_inhibit_evaluation_warnings
--;
2737 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
2739 struct c_type_name
*type
= c_parser_type_name (parser
);
2740 c_inhibit_evaluation_warnings
--;
2744 ret
.spec
= groktypename (type
, &ret
.expr
, &ret
.expr_const_operands
);
2745 pop_maybe_used (variably_modified_type_p (ret
.spec
, NULL_TREE
));
2751 location_t here
= c_parser_peek_token (parser
)->location
;
2752 struct c_expr expr
= c_parser_expression (parser
);
2753 c_inhibit_evaluation_warnings
--;
2755 if (TREE_CODE (expr
.value
) == COMPONENT_REF
2756 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
2757 error_at (here
, "%<typeof%> applied to a bit-field");
2758 mark_exp_read (expr
.value
);
2759 ret
.spec
= TREE_TYPE (expr
.value
);
2760 was_vm
= variably_modified_type_p (ret
.spec
, NULL_TREE
);
2761 /* This is returned with the type so that when the type is
2762 evaluated, this can be evaluated. */
2764 ret
.expr
= c_fully_fold (expr
.value
, false, &ret
.expr_const_operands
);
2765 pop_maybe_used (was_vm
);
2767 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
2771 /* Parse an alignment-specifier.
2775 alignment-specifier:
2776 _Alignas ( type-name )
2777 _Alignas ( constant-expression )
2781 c_parser_alignas_specifier (c_parser
* parser
)
2783 tree ret
= error_mark_node
;
2784 location_t loc
= c_parser_peek_token (parser
)->location
;
2785 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNAS
));
2786 c_parser_consume_token (parser
);
2790 pedwarn (loc
, OPT_Wpedantic
,
2791 "ISO C99 does not support %<_Alignas%>");
2793 pedwarn (loc
, OPT_Wpedantic
,
2794 "ISO C90 does not support %<_Alignas%>");
2796 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2798 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
2800 struct c_type_name
*type
= c_parser_type_name (parser
);
2802 ret
= c_alignof (loc
, groktypename (type
, NULL
, NULL
));
2805 ret
= c_parser_expr_no_commas (parser
, NULL
).value
;
2806 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
2810 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
2811 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
2812 be redeclared; otherwise it may not. KIND indicates which kind of
2813 declarator is wanted. Returns a valid declarator except in the
2814 case of a syntax error in which case NULL is returned. *SEEN_ID is
2815 set to true if an identifier being declared is seen; this is used
2816 to diagnose bad forms of abstract array declarators and to
2817 determine whether an identifier list is syntactically permitted.
2820 pointer[opt] direct-declarator
2824 ( attributes[opt] declarator )
2825 direct-declarator array-declarator
2826 direct-declarator ( parameter-type-list )
2827 direct-declarator ( identifier-list[opt] )
2830 * type-qualifier-list[opt]
2831 * type-qualifier-list[opt] pointer
2833 type-qualifier-list:
2836 type-qualifier-list type-qualifier
2837 type-qualifier-list attributes
2839 parameter-type-list:
2841 parameter-list , ...
2844 parameter-declaration
2845 parameter-list , parameter-declaration
2847 parameter-declaration:
2848 declaration-specifiers declarator attributes[opt]
2849 declaration-specifiers abstract-declarator[opt] attributes[opt]
2853 identifier-list , identifier
2855 abstract-declarator:
2857 pointer[opt] direct-abstract-declarator
2859 direct-abstract-declarator:
2860 ( attributes[opt] abstract-declarator )
2861 direct-abstract-declarator[opt] array-declarator
2862 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
2867 direct-declarator ( parameter-forward-declarations
2868 parameter-type-list[opt] )
2870 direct-abstract-declarator:
2871 direct-abstract-declarator[opt] ( parameter-forward-declarations
2872 parameter-type-list[opt] )
2874 parameter-forward-declarations:
2876 parameter-forward-declarations parameter-list ;
2878 The uses of attributes shown above are GNU extensions.
2880 Some forms of array declarator are not included in C99 in the
2881 syntax for abstract declarators; these are disallowed elsewhere.
2882 This may be a defect (DR#289).
2884 This function also accepts an omitted abstract declarator as being
2885 an abstract declarator, although not part of the formal syntax. */
2887 static struct c_declarator
*
2888 c_parser_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
2891 /* Parse any initial pointer part. */
2892 if (c_parser_next_token_is (parser
, CPP_MULT
))
2894 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
2895 struct c_declarator
*inner
;
2896 c_parser_consume_token (parser
);
2897 c_parser_declspecs (parser
, quals_attrs
, false, false, true, cla_prefer_id
);
2898 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
2902 return make_pointer_declarator (quals_attrs
, inner
);
2904 /* Now we have a direct declarator, direct abstract declarator or
2905 nothing (which counts as a direct abstract declarator here). */
2906 return c_parser_direct_declarator (parser
, type_seen_p
, kind
, seen_id
);
2909 /* Parse a direct declarator or direct abstract declarator; arguments
2910 as c_parser_declarator. */
2912 static struct c_declarator
*
2913 c_parser_direct_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
2916 /* The direct declarator must start with an identifier (possibly
2917 omitted) or a parenthesized declarator (possibly abstract). In
2918 an ordinary declarator, initial parentheses must start a
2919 parenthesized declarator. In an abstract declarator or parameter
2920 declarator, they could start a parenthesized declarator or a
2921 parameter list. To tell which, the open parenthesis and any
2922 following attributes must be read. If a declaration specifier
2923 follows, then it is a parameter list; if the specifier is a
2924 typedef name, there might be an ambiguity about redeclaring it,
2925 which is resolved in the direction of treating it as a typedef
2926 name. If a close parenthesis follows, it is also an empty
2927 parameter list, as the syntax does not permit empty abstract
2928 declarators. Otherwise, it is a parenthesized declarator (in
2929 which case the analysis may be repeated inside it, recursively).
2931 ??? There is an ambiguity in a parameter declaration "int
2932 (__attribute__((foo)) x)", where x is not a typedef name: it
2933 could be an abstract declarator for a function, or declare x with
2934 parentheses. The proper resolution of this ambiguity needs
2935 documenting. At present we follow an accident of the old
2936 parser's implementation, whereby the first parameter must have
2937 some declaration specifiers other than just attributes. Thus as
2938 a parameter declaration it is treated as a parenthesized
2939 parameter named x, and as an abstract declarator it is
2942 ??? Also following the old parser, attributes inside an empty
2943 parameter list are ignored, making it a list not yielding a
2944 prototype, rather than giving an error or making it have one
2945 parameter with implicit type int.
2947 ??? Also following the old parser, typedef names may be
2948 redeclared in declarators, but not Objective-C class names. */
2950 if (kind
!= C_DTR_ABSTRACT
2951 && c_parser_next_token_is (parser
, CPP_NAME
)
2953 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
2954 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
2955 || c_parser_peek_token (parser
)->id_kind
== C_ID_ID
))
2957 struct c_declarator
*inner
2958 = build_id_declarator (c_parser_peek_token (parser
)->value
);
2960 inner
->id_loc
= c_parser_peek_token (parser
)->location
;
2961 c_parser_consume_token (parser
);
2962 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
2965 if (kind
!= C_DTR_NORMAL
2966 && c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
2968 struct c_declarator
*inner
= build_id_declarator (NULL_TREE
);
2969 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
2972 /* Either we are at the end of an abstract declarator, or we have
2975 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
2978 struct c_declarator
*inner
;
2979 c_parser_consume_token (parser
);
2980 attrs
= c_parser_attributes (parser
);
2981 if (kind
!= C_DTR_NORMAL
2982 && (c_parser_next_token_starts_declspecs (parser
)
2983 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
)))
2985 struct c_arg_info
*args
2986 = c_parser_parms_declarator (parser
, kind
== C_DTR_NORMAL
,
2993 = build_function_declarator (args
,
2994 build_id_declarator (NULL_TREE
));
2995 return c_parser_direct_declarator_inner (parser
, *seen_id
,
2999 /* A parenthesized declarator. */
3000 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
3001 if (inner
!= NULL
&& attrs
!= NULL
)
3002 inner
= build_attrs_declarator (attrs
, inner
);
3003 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3005 c_parser_consume_token (parser
);
3009 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3013 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3020 if (kind
== C_DTR_NORMAL
)
3022 c_parser_error (parser
, "expected identifier or %<(%>");
3026 return build_id_declarator (NULL_TREE
);
3030 /* Parse part of a direct declarator or direct abstract declarator,
3031 given that some (in INNER) has already been parsed; ID_PRESENT is
3032 true if an identifier is present, false for an abstract
3035 static struct c_declarator
*
3036 c_parser_direct_declarator_inner (c_parser
*parser
, bool id_present
,
3037 struct c_declarator
*inner
)
3039 /* Parse a sequence of array declarators and parameter lists. */
3040 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
3042 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
3043 struct c_declarator
*declarator
;
3044 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
3048 c_parser_consume_token (parser
);
3049 c_parser_declspecs (parser
, quals_attrs
, false, false, true, cla_prefer_id
);
3050 static_seen
= c_parser_next_token_is_keyword (parser
, RID_STATIC
);
3052 c_parser_consume_token (parser
);
3053 if (static_seen
&& !quals_attrs
->declspecs_seen_p
)
3054 c_parser_declspecs (parser
, quals_attrs
, false, false, true, cla_prefer_id
);
3055 if (!quals_attrs
->declspecs_seen_p
)
3057 /* If "static" is present, there must be an array dimension.
3058 Otherwise, there may be a dimension, "*", or no
3063 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
3067 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3072 else if (flag_enable_cilkplus
3073 && c_parser_next_token_is (parser
, CPP_COLON
))
3075 dimen
= error_mark_node
;
3077 error_at (c_parser_peek_token (parser
)->location
,
3078 "array notations cannot be used in declaration");
3079 c_parser_consume_token (parser
);
3081 else if (c_parser_next_token_is (parser
, CPP_MULT
))
3083 if (c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_SQUARE
)
3087 c_parser_consume_token (parser
);
3092 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
3098 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
3101 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3102 c_parser_consume_token (parser
);
3103 else if (flag_enable_cilkplus
3104 && c_parser_next_token_is (parser
, CPP_COLON
))
3106 error_at (c_parser_peek_token (parser
)->location
,
3107 "array notations cannot be used in declaration");
3108 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
3113 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3118 mark_exp_read (dimen
);
3119 declarator
= build_array_declarator (brace_loc
, dimen
, quals_attrs
,
3120 static_seen
, star_seen
);
3121 if (declarator
== NULL
)
3123 inner
= set_array_declarator_inner (declarator
, inner
);
3124 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3126 else if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3129 struct c_arg_info
*args
;
3130 c_parser_consume_token (parser
);
3131 attrs
= c_parser_attributes (parser
);
3132 args
= c_parser_parms_declarator (parser
, id_present
, attrs
);
3137 inner
= build_function_declarator (args
, inner
);
3138 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3144 /* Parse a parameter list or identifier list, including the closing
3145 parenthesis but not the opening one. ATTRS are the attributes at
3146 the start of the list. ID_LIST_OK is true if an identifier list is
3147 acceptable; such a list must not have attributes at the start. */
3149 static struct c_arg_info
*
3150 c_parser_parms_declarator (c_parser
*parser
, bool id_list_ok
, tree attrs
)
3153 declare_parm_level ();
3154 /* If the list starts with an identifier, it is an identifier list.
3155 Otherwise, it is either a prototype list or an empty list. */
3158 && c_parser_next_token_is (parser
, CPP_NAME
)
3159 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
3161 /* Look ahead to detect typos in type names. */
3162 && c_parser_peek_2nd_token (parser
)->type
!= CPP_NAME
3163 && c_parser_peek_2nd_token (parser
)->type
!= CPP_MULT
3164 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
3165 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_SQUARE
)
3167 tree list
= NULL_TREE
, *nextp
= &list
;
3168 while (c_parser_next_token_is (parser
, CPP_NAME
)
3169 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
3171 *nextp
= build_tree_list (NULL_TREE
,
3172 c_parser_peek_token (parser
)->value
);
3173 nextp
= & TREE_CHAIN (*nextp
);
3174 c_parser_consume_token (parser
);
3175 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
3177 c_parser_consume_token (parser
);
3178 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3180 c_parser_error (parser
, "expected identifier");
3184 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3186 struct c_arg_info
*ret
= build_arg_info ();
3188 c_parser_consume_token (parser
);
3194 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3202 struct c_arg_info
*ret
= c_parser_parms_list_declarator (parser
, attrs
,
3209 /* Parse a parameter list (possibly empty), including the closing
3210 parenthesis but not the opening one. ATTRS are the attributes at
3211 the start of the list. EXPR is NULL or an expression that needs to
3212 be evaluated for the side effects of array size expressions in the
3215 static struct c_arg_info
*
3216 c_parser_parms_list_declarator (c_parser
*parser
, tree attrs
, tree expr
)
3218 bool bad_parm
= false;
3220 /* ??? Following the old parser, forward parameter declarations may
3221 use abstract declarators, and if no real parameter declarations
3222 follow the forward declarations then this is not diagnosed. Also
3223 note as above that attributes are ignored as the only contents of
3224 the parentheses, or as the only contents after forward
3226 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3228 struct c_arg_info
*ret
= build_arg_info ();
3229 c_parser_consume_token (parser
);
3232 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3234 struct c_arg_info
*ret
= build_arg_info ();
3236 if (flag_allow_parameterless_variadic_functions
)
3238 /* F (...) is allowed. */
3239 ret
->types
= NULL_TREE
;
3243 /* Suppress -Wold-style-definition for this case. */
3244 ret
->types
= error_mark_node
;
3245 error_at (c_parser_peek_token (parser
)->location
,
3246 "ISO C requires a named argument before %<...%>");
3248 c_parser_consume_token (parser
);
3249 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3251 c_parser_consume_token (parser
);
3256 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3261 /* Nonempty list of parameters, either terminated with semicolon
3262 (forward declarations; recurse) or with close parenthesis (normal
3263 function) or with ", ... )" (variadic function). */
3266 /* Parse a parameter. */
3267 struct c_parm
*parm
= c_parser_parameter_declaration (parser
, attrs
);
3272 push_parm_decl (parm
, &expr
);
3273 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3276 c_parser_consume_token (parser
);
3277 mark_forward_parm_decls ();
3278 new_attrs
= c_parser_attributes (parser
);
3279 return c_parser_parms_list_declarator (parser
, new_attrs
, expr
);
3281 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3283 c_parser_consume_token (parser
);
3287 return get_parm_info (false, expr
);
3289 if (!c_parser_require (parser
, CPP_COMMA
,
3290 "expected %<;%>, %<,%> or %<)%>"))
3292 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3295 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3297 c_parser_consume_token (parser
);
3298 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3300 c_parser_consume_token (parser
);
3304 return get_parm_info (true, expr
);
3308 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3316 /* Parse a parameter declaration. ATTRS are the attributes at the
3317 start of the declaration if it is the first parameter. */
3319 static struct c_parm
*
3320 c_parser_parameter_declaration (c_parser
*parser
, tree attrs
)
3322 struct c_declspecs
*specs
;
3323 struct c_declarator
*declarator
;
3325 tree postfix_attrs
= NULL_TREE
;
3328 /* Accept #pragmas between parameter declarations. */
3329 while (c_parser_next_token_is (parser
, CPP_PRAGMA
))
3330 c_parser_pragma (parser
, pragma_external
);
3332 if (!c_parser_next_token_starts_declspecs (parser
))
3334 c_token
*token
= c_parser_peek_token (parser
);
3337 c_parser_set_source_position_from_token (token
);
3338 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
3340 error ("unknown type name %qE", token
->value
);
3341 parser
->error
= true;
3343 /* ??? In some Objective-C cases '...' isn't applicable so there
3344 should be a different message. */
3346 c_parser_error (parser
,
3347 "expected declaration specifiers or %<...%>");
3348 c_parser_skip_to_end_of_parameter (parser
);
3351 specs
= build_null_declspecs ();
3354 declspecs_add_attrs (input_location
, specs
, attrs
);
3357 c_parser_declspecs (parser
, specs
, true, true, true, cla_nonabstract_decl
);
3358 finish_declspecs (specs
);
3359 pending_xref_error ();
3360 prefix_attrs
= specs
->attrs
;
3361 specs
->attrs
= NULL_TREE
;
3362 declarator
= c_parser_declarator (parser
,
3363 specs
->typespec_kind
!= ctsk_none
,
3364 C_DTR_PARM
, &dummy
);
3365 if (declarator
== NULL
)
3367 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3370 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3371 postfix_attrs
= c_parser_attributes (parser
);
3372 return build_c_parm (specs
, chainon (postfix_attrs
, prefix_attrs
),
3376 /* Parse a string literal in an asm expression. It should not be
3377 translated, and wide string literals are an error although
3378 permitted by the syntax. This is a GNU extension.
3383 ??? At present, following the old parser, the caller needs to have
3384 set lex_untranslated_string to 1. It would be better to follow the
3385 C++ parser rather than using this kludge. */
3388 c_parser_asm_string_literal (c_parser
*parser
)
3391 int save_flag
= warn_overlength_strings
;
3392 warn_overlength_strings
= 0;
3393 if (c_parser_next_token_is (parser
, CPP_STRING
))
3395 str
= c_parser_peek_token (parser
)->value
;
3396 c_parser_consume_token (parser
);
3398 else if (c_parser_next_token_is (parser
, CPP_WSTRING
))
3400 error_at (c_parser_peek_token (parser
)->location
,
3401 "wide string literal in %<asm%>");
3402 str
= build_string (1, "");
3403 c_parser_consume_token (parser
);
3407 c_parser_error (parser
, "expected string literal");
3410 warn_overlength_strings
= save_flag
;
3414 /* Parse a simple asm expression. This is used in restricted
3415 contexts, where a full expression with inputs and outputs does not
3416 make sense. This is a GNU extension.
3419 asm ( asm-string-literal )
3423 c_parser_simple_asm_expr (c_parser
*parser
)
3426 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
3427 /* ??? Follow the C++ parser rather than using the
3428 lex_untranslated_string kludge. */
3429 parser
->lex_untranslated_string
= true;
3430 c_parser_consume_token (parser
);
3431 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3433 parser
->lex_untranslated_string
= false;
3436 str
= c_parser_asm_string_literal (parser
);
3437 parser
->lex_untranslated_string
= false;
3438 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
3440 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3447 c_parser_attribute_any_word (c_parser
*parser
)
3449 tree attr_name
= NULL_TREE
;
3451 if (c_parser_next_token_is (parser
, CPP_KEYWORD
))
3453 /* ??? See comment above about what keywords are accepted here. */
3455 switch (c_parser_peek_token (parser
)->keyword
)
3486 case RID_TRANSACTION_ATOMIC
:
3487 case RID_TRANSACTION_CANCEL
:
3497 /* Accept __attribute__((__const)) as __attribute__((const)) etc. */
3498 attr_name
= ridpointers
[(int) c_parser_peek_token (parser
)->keyword
];
3500 else if (c_parser_next_token_is (parser
, CPP_NAME
))
3501 attr_name
= c_parser_peek_token (parser
)->value
;
3506 /* Parse (possibly empty) attributes. This is a GNU extension.
3510 attributes attribute
3513 __attribute__ ( ( attribute-list ) )
3517 attribute_list , attrib
3522 any-word ( identifier )
3523 any-word ( identifier , nonempty-expr-list )
3524 any-word ( expr-list )
3526 where the "identifier" must not be declared as a type, and
3527 "any-word" may be any identifier (including one declared as a
3528 type), a reserved word storage class specifier, type specifier or
3529 type qualifier. ??? This still leaves out most reserved keywords
3530 (following the old parser), shouldn't we include them, and why not
3531 allow identifiers declared as types to start the arguments? */
3534 c_parser_attributes (c_parser
*parser
)
3536 tree attrs
= NULL_TREE
;
3537 while (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3539 /* ??? Follow the C++ parser rather than using the
3540 lex_untranslated_string kludge. */
3541 parser
->lex_untranslated_string
= true;
3542 c_parser_consume_token (parser
);
3543 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3545 parser
->lex_untranslated_string
= false;
3548 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3550 parser
->lex_untranslated_string
= false;
3551 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3554 /* Parse the attribute list. */
3555 while (c_parser_next_token_is (parser
, CPP_COMMA
)
3556 || c_parser_next_token_is (parser
, CPP_NAME
)
3557 || c_parser_next_token_is (parser
, CPP_KEYWORD
))
3559 tree attr
, attr_name
, attr_args
;
3560 vec
<tree
, va_gc
> *expr_list
;
3561 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3563 c_parser_consume_token (parser
);
3567 attr_name
= c_parser_attribute_any_word (parser
);
3568 if (attr_name
== NULL
)
3570 c_parser_consume_token (parser
);
3571 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
3573 attr
= build_tree_list (attr_name
, NULL_TREE
);
3574 attrs
= chainon (attrs
, attr
);
3577 c_parser_consume_token (parser
);
3578 /* Parse the attribute contents. If they start with an
3579 identifier which is followed by a comma or close
3580 parenthesis, then the arguments start with that
3581 identifier; otherwise they are an expression list.
3582 In objective-c the identifier may be a classname. */
3583 if (c_parser_next_token_is (parser
, CPP_NAME
)
3584 && (c_parser_peek_token (parser
)->id_kind
== C_ID_ID
3585 || (c_dialect_objc ()
3586 && c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
3587 && ((c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
)
3588 || (c_parser_peek_2nd_token (parser
)->type
3589 == CPP_CLOSE_PAREN
)))
3591 tree arg1
= c_parser_peek_token (parser
)->value
;
3592 c_parser_consume_token (parser
);
3593 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3594 attr_args
= build_tree_list (NULL_TREE
, arg1
);
3598 c_parser_consume_token (parser
);
3599 expr_list
= c_parser_expr_list (parser
, false, true,
3601 tree_list
= build_tree_list_vec (expr_list
);
3602 attr_args
= tree_cons (NULL_TREE
, arg1
, tree_list
);
3603 release_tree_vector (expr_list
);
3608 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3609 attr_args
= NULL_TREE
;
3612 expr_list
= c_parser_expr_list (parser
, false, true,
3614 attr_args
= build_tree_list_vec (expr_list
);
3615 release_tree_vector (expr_list
);
3618 attr
= build_tree_list (attr_name
, attr_args
);
3619 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3620 c_parser_consume_token (parser
);
3623 parser
->lex_untranslated_string
= false;
3624 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3628 attrs
= chainon (attrs
, attr
);
3630 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3631 c_parser_consume_token (parser
);
3634 parser
->lex_untranslated_string
= false;
3635 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3639 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3640 c_parser_consume_token (parser
);
3643 parser
->lex_untranslated_string
= false;
3644 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3648 parser
->lex_untranslated_string
= false;
3653 /* Parse a type name (C90 6.5.5, C99 6.7.6).
3656 specifier-qualifier-list abstract-declarator[opt]
3659 static struct c_type_name
*
3660 c_parser_type_name (c_parser
*parser
)
3662 struct c_declspecs
*specs
= build_null_declspecs ();
3663 struct c_declarator
*declarator
;
3664 struct c_type_name
*ret
;
3666 c_parser_declspecs (parser
, specs
, false, true, true, cla_prefer_type
);
3667 if (!specs
->declspecs_seen_p
)
3669 c_parser_error (parser
, "expected specifier-qualifier-list");
3672 if (specs
->type
!= error_mark_node
)
3674 pending_xref_error ();
3675 finish_declspecs (specs
);
3677 declarator
= c_parser_declarator (parser
,
3678 specs
->typespec_kind
!= ctsk_none
,
3679 C_DTR_ABSTRACT
, &dummy
);
3680 if (declarator
== NULL
)
3682 ret
= XOBNEW (&parser_obstack
, struct c_type_name
);
3684 ret
->declarator
= declarator
;
3688 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
3691 assignment-expression
3692 { initializer-list }
3693 { initializer-list , }
3696 designation[opt] initializer
3697 initializer-list , designation[opt] initializer
3704 designator-list designator
3711 [ constant-expression ]
3723 [ constant-expression ... constant-expression ]
3725 Any expression without commas is accepted in the syntax for the
3726 constant-expressions, with non-constant expressions rejected later.
3728 This function is only used for top-level initializers; for nested
3729 ones, see c_parser_initval. */
3731 static struct c_expr
3732 c_parser_initializer (c_parser
*parser
)
3734 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
3735 return c_parser_braced_init (parser
, NULL_TREE
, false);
3739 location_t loc
= c_parser_peek_token (parser
)->location
;
3740 ret
= c_parser_expr_no_commas (parser
, NULL
);
3741 if (TREE_CODE (ret
.value
) != STRING_CST
3742 && TREE_CODE (ret
.value
) != COMPOUND_LITERAL_EXPR
)
3743 ret
= default_function_array_read_conversion (loc
, ret
);
3748 /* Parse a braced initializer list. TYPE is the type specified for a
3749 compound literal, and NULL_TREE for other initializers and for
3750 nested braced lists. NESTED_P is true for nested braced lists,
3751 false for the list of a compound literal or the list that is the
3752 top-level initializer in a declaration. */
3754 static struct c_expr
3755 c_parser_braced_init (c_parser
*parser
, tree type
, bool nested_p
)
3758 struct obstack braced_init_obstack
;
3759 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
3760 gcc_obstack_init (&braced_init_obstack
);
3761 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
3762 c_parser_consume_token (parser
);
3764 push_init_level (0, &braced_init_obstack
);
3766 really_start_incremental_init (type
);
3767 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3769 pedwarn (brace_loc
, OPT_Wpedantic
, "ISO C forbids empty initializer braces");
3773 /* Parse a non-empty initializer list, possibly with a trailing
3777 c_parser_initelt (parser
, &braced_init_obstack
);
3780 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3781 c_parser_consume_token (parser
);
3784 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3788 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
3790 ret
.value
= error_mark_node
;
3791 ret
.original_code
= ERROR_MARK
;
3792 ret
.original_type
= NULL
;
3793 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
3794 pop_init_level (0, &braced_init_obstack
);
3795 obstack_free (&braced_init_obstack
, NULL
);
3798 c_parser_consume_token (parser
);
3799 ret
= pop_init_level (0, &braced_init_obstack
);
3800 obstack_free (&braced_init_obstack
, NULL
);
3804 /* Parse a nested initializer, including designators. */
3807 c_parser_initelt (c_parser
*parser
, struct obstack
* braced_init_obstack
)
3809 /* Parse any designator or designator list. A single array
3810 designator may have the subsequent "=" omitted in GNU C, but a
3811 longer list or a structure member designator may not. */
3812 if (c_parser_next_token_is (parser
, CPP_NAME
)
3813 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
3815 /* Old-style structure member designator. */
3816 set_init_label (c_parser_peek_token (parser
)->value
,
3817 braced_init_obstack
);
3818 /* Use the colon as the error location. */
3819 pedwarn (c_parser_peek_2nd_token (parser
)->location
, OPT_Wpedantic
,
3820 "obsolete use of designated initializer with %<:%>");
3821 c_parser_consume_token (parser
);
3822 c_parser_consume_token (parser
);
3826 /* des_seen is 0 if there have been no designators, 1 if there
3827 has been a single array designator and 2 otherwise. */
3829 /* Location of a designator. */
3830 location_t des_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
3831 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
)
3832 || c_parser_next_token_is (parser
, CPP_DOT
))
3834 int des_prev
= des_seen
;
3836 des_loc
= c_parser_peek_token (parser
)->location
;
3839 if (c_parser_next_token_is (parser
, CPP_DOT
))
3842 c_parser_consume_token (parser
);
3843 if (c_parser_next_token_is (parser
, CPP_NAME
))
3845 set_init_label (c_parser_peek_token (parser
)->value
,
3846 braced_init_obstack
);
3847 c_parser_consume_token (parser
);
3852 init
.value
= error_mark_node
;
3853 init
.original_code
= ERROR_MARK
;
3854 init
.original_type
= NULL
;
3855 c_parser_error (parser
, "expected identifier");
3856 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3857 process_init_element (init
, false, braced_init_obstack
);
3864 location_t ellipsis_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
3865 /* ??? Following the old parser, [ objc-receiver
3866 objc-message-args ] is accepted as an initializer,
3867 being distinguished from a designator by what follows
3868 the first assignment expression inside the square
3869 brackets, but after a first array designator a
3870 subsequent square bracket is for Objective-C taken to
3871 start an expression, using the obsolete form of
3872 designated initializer without '=', rather than
3873 possibly being a second level of designation: in LALR
3874 terms, the '[' is shifted rather than reducing
3875 designator to designator-list. */
3876 if (des_prev
== 1 && c_dialect_objc ())
3878 des_seen
= des_prev
;
3881 if (des_prev
== 0 && c_dialect_objc ())
3883 /* This might be an array designator or an
3884 Objective-C message expression. If the former,
3885 continue parsing here; if the latter, parse the
3886 remainder of the initializer given the starting
3887 primary-expression. ??? It might make sense to
3888 distinguish when des_prev == 1 as well; see
3889 previous comment. */
3891 struct c_expr mexpr
;
3892 c_parser_consume_token (parser
);
3893 if (c_parser_peek_token (parser
)->type
== CPP_NAME
3894 && ((c_parser_peek_token (parser
)->id_kind
3896 || (c_parser_peek_token (parser
)->id_kind
3897 == C_ID_CLASSNAME
)))
3899 /* Type name receiver. */
3900 tree id
= c_parser_peek_token (parser
)->value
;
3901 c_parser_consume_token (parser
);
3902 rec
= objc_get_class_reference (id
);
3903 goto parse_message_args
;
3905 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
3906 mark_exp_read (first
);
3907 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
)
3908 || c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3909 goto array_desig_after_first
;
3910 /* Expression receiver. So far only one part
3911 without commas has been parsed; there might be
3912 more of the expression. */
3914 while (c_parser_next_token_is (parser
, CPP_COMMA
))
3917 location_t comma_loc
, exp_loc
;
3918 comma_loc
= c_parser_peek_token (parser
)->location
;
3919 c_parser_consume_token (parser
);
3920 exp_loc
= c_parser_peek_token (parser
)->location
;
3921 next
= c_parser_expr_no_commas (parser
, NULL
);
3922 next
= default_function_array_read_conversion (exp_loc
,
3924 rec
= build_compound_expr (comma_loc
, rec
, next
.value
);
3927 /* Now parse the objc-message-args. */
3928 args
= c_parser_objc_message_args (parser
);
3929 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3932 = objc_build_message_expr (rec
, args
);
3933 mexpr
.original_code
= ERROR_MARK
;
3934 mexpr
.original_type
= NULL
;
3935 /* Now parse and process the remainder of the
3936 initializer, starting with this message
3937 expression as a primary-expression. */
3938 c_parser_initval (parser
, &mexpr
, braced_init_obstack
);
3941 c_parser_consume_token (parser
);
3942 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
3943 mark_exp_read (first
);
3944 array_desig_after_first
:
3945 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3947 ellipsis_loc
= c_parser_peek_token (parser
)->location
;
3948 c_parser_consume_token (parser
);
3949 second
= c_parser_expr_no_commas (parser
, NULL
).value
;
3950 mark_exp_read (second
);
3954 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3956 c_parser_consume_token (parser
);
3957 set_init_index (first
, second
, braced_init_obstack
);
3959 pedwarn (ellipsis_loc
, OPT_Wpedantic
,
3960 "ISO C forbids specifying range of elements to initialize");
3963 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3969 if (c_parser_next_token_is (parser
, CPP_EQ
))
3972 pedwarn (des_loc
, OPT_Wpedantic
,
3973 "ISO C90 forbids specifying subobject to initialize");
3974 c_parser_consume_token (parser
);
3979 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
3980 "obsolete use of designated initializer without %<=%>");
3984 init
.value
= error_mark_node
;
3985 init
.original_code
= ERROR_MARK
;
3986 init
.original_type
= NULL
;
3987 c_parser_error (parser
, "expected %<=%>");
3988 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3989 process_init_element (init
, false, braced_init_obstack
);
3995 c_parser_initval (parser
, NULL
, braced_init_obstack
);
3998 /* Parse a nested initializer; as c_parser_initializer but parses
3999 initializers within braced lists, after any designators have been
4000 applied. If AFTER is not NULL then it is an Objective-C message
4001 expression which is the primary-expression starting the
4005 c_parser_initval (c_parser
*parser
, struct c_expr
*after
,
4006 struct obstack
* braced_init_obstack
)
4009 gcc_assert (!after
|| c_dialect_objc ());
4010 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
) && !after
)
4011 init
= c_parser_braced_init (parser
, NULL_TREE
, true);
4014 location_t loc
= c_parser_peek_token (parser
)->location
;
4015 init
= c_parser_expr_no_commas (parser
, after
);
4016 if (init
.value
!= NULL_TREE
4017 && TREE_CODE (init
.value
) != STRING_CST
4018 && TREE_CODE (init
.value
) != COMPOUND_LITERAL_EXPR
)
4019 init
= default_function_array_read_conversion (loc
, init
);
4021 process_init_element (init
, false, braced_init_obstack
);
4024 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
4028 { block-item-list[opt] }
4029 { label-declarations block-item-list }
4033 block-item-list block-item
4045 { label-declarations block-item-list }
4048 __extension__ nested-declaration
4049 nested-function-definition
4053 label-declarations label-declaration
4056 __label__ identifier-list ;
4058 Allowing the mixing of declarations and code is new in C99. The
4059 GNU syntax also permits (not shown above) labels at the end of
4060 compound statements, which yield an error. We don't allow labels
4061 on declarations; this might seem like a natural extension, but
4062 there would be a conflict between attributes on the label and
4063 prefix attributes on the declaration. ??? The syntax follows the
4064 old parser in requiring something after label declarations.
4065 Although they are erroneous if the labels declared aren't defined,
4066 is it useful for the syntax to be this way?
4078 c_parser_compound_statement (c_parser
*parser
)
4081 location_t brace_loc
;
4082 brace_loc
= c_parser_peek_token (parser
)->location
;
4083 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
4085 /* Ensure a scope is entered and left anyway to avoid confusion
4086 if we have just prepared to enter a function body. */
4087 stmt
= c_begin_compound_stmt (true);
4088 c_end_compound_stmt (brace_loc
, stmt
, true);
4089 return error_mark_node
;
4091 stmt
= c_begin_compound_stmt (true);
4092 c_parser_compound_statement_nostart (parser
);
4094 /* If the compound stmt contains array notations, then we expand them. */
4095 if (flag_enable_cilkplus
&& contains_array_notation_expr (stmt
))
4096 stmt
= expand_array_notation_exprs (stmt
);
4097 return c_end_compound_stmt (brace_loc
, stmt
, true);
4100 /* Parse a compound statement except for the opening brace. This is
4101 used for parsing both compound statements and statement expressions
4102 (which follow different paths to handling the opening). */
4105 c_parser_compound_statement_nostart (c_parser
*parser
)
4107 bool last_stmt
= false;
4108 bool last_label
= false;
4109 bool save_valid_for_pragma
= valid_location_for_stdc_pragma_p ();
4110 location_t label_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4111 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4113 c_parser_consume_token (parser
);
4116 mark_valid_location_for_stdc_pragma (true);
4117 if (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
4119 /* Read zero or more forward-declarations for labels that nested
4120 functions can jump to. */
4121 mark_valid_location_for_stdc_pragma (false);
4122 while (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
4124 label_loc
= c_parser_peek_token (parser
)->location
;
4125 c_parser_consume_token (parser
);
4126 /* Any identifiers, including those declared as type names,
4131 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
4133 c_parser_error (parser
, "expected identifier");
4137 = declare_label (c_parser_peek_token (parser
)->value
);
4138 C_DECLARED_LABEL_FLAG (label
) = 1;
4139 add_stmt (build_stmt (label_loc
, DECL_EXPR
, label
));
4140 c_parser_consume_token (parser
);
4141 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4142 c_parser_consume_token (parser
);
4146 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4148 pedwarn (label_loc
, OPT_Wpedantic
, "ISO C forbids label declarations");
4150 /* We must now have at least one statement, label or declaration. */
4151 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4153 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4154 c_parser_error (parser
, "expected declaration or statement");
4155 c_parser_consume_token (parser
);
4158 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
4160 location_t loc
= c_parser_peek_token (parser
)->location
;
4161 if (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4162 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4163 || (c_parser_next_token_is (parser
, CPP_NAME
)
4164 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4166 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
4167 label_loc
= c_parser_peek_2nd_token (parser
)->location
;
4169 label_loc
= c_parser_peek_token (parser
)->location
;
4172 mark_valid_location_for_stdc_pragma (false);
4173 c_parser_label (parser
);
4175 else if (!last_label
4176 && c_parser_next_tokens_start_declaration (parser
))
4179 mark_valid_location_for_stdc_pragma (false);
4180 c_parser_declaration_or_fndef (parser
, true, true, true, true, true, NULL
);
4183 (pedantic
&& !flag_isoc99
)
4185 : OPT_Wdeclaration_after_statement
,
4186 "ISO C90 forbids mixed declarations and code");
4189 else if (!last_label
4190 && c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
4192 /* __extension__ can start a declaration, but is also an
4193 unary operator that can start an expression. Consume all
4194 but the last of a possible series of __extension__ to
4196 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
4197 && (c_parser_peek_2nd_token (parser
)->keyword
4199 c_parser_consume_token (parser
);
4200 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
4203 ext
= disable_extension_diagnostics ();
4204 c_parser_consume_token (parser
);
4206 mark_valid_location_for_stdc_pragma (false);
4207 c_parser_declaration_or_fndef (parser
, true, true, true, true,
4209 /* Following the old parser, __extension__ does not
4210 disable this diagnostic. */
4211 restore_extension_diagnostics (ext
);
4213 pedwarn_c90 (loc
, (pedantic
&& !flag_isoc99
)
4215 : OPT_Wdeclaration_after_statement
,
4216 "ISO C90 forbids mixed declarations and code");
4222 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
4224 /* External pragmas, and some omp pragmas, are not associated
4225 with regular c code, and so are not to be considered statements
4226 syntactically. This ensures that the user doesn't put them
4227 places that would turn into syntax errors if the directive
4229 if (c_parser_pragma (parser
, pragma_compound
))
4230 last_label
= false, last_stmt
= true;
4232 else if (c_parser_next_token_is (parser
, CPP_EOF
))
4234 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4235 c_parser_error (parser
, "expected declaration or statement");
4238 else if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
4240 if (parser
->in_if_block
)
4242 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4243 error_at (loc
, """expected %<}%> before %<else%>");
4248 error_at (loc
, "%<else%> without a previous %<if%>");
4249 c_parser_consume_token (parser
);
4258 mark_valid_location_for_stdc_pragma (false);
4259 c_parser_statement_after_labels (parser
);
4262 parser
->error
= false;
4265 error_at (label_loc
, "label at end of compound statement");
4266 c_parser_consume_token (parser
);
4267 /* Restore the value we started with. */
4268 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4271 /* Parse a label (C90 6.6.1, C99 6.8.1).
4274 identifier : attributes[opt]
4275 case constant-expression :
4281 case constant-expression ... constant-expression :
4283 The use of attributes on labels is a GNU extension. The syntax in
4284 GNU C accepts any expressions without commas, non-constant
4285 expressions being rejected later. */
4288 c_parser_label (c_parser
*parser
)
4290 location_t loc1
= c_parser_peek_token (parser
)->location
;
4291 tree label
= NULL_TREE
;
4292 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
4295 c_parser_consume_token (parser
);
4296 exp1
= c_parser_expr_no_commas (parser
, NULL
).value
;
4297 if (c_parser_next_token_is (parser
, CPP_COLON
))
4299 c_parser_consume_token (parser
);
4300 label
= do_case (loc1
, exp1
, NULL_TREE
);
4302 else if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
4304 c_parser_consume_token (parser
);
4305 exp2
= c_parser_expr_no_commas (parser
, NULL
).value
;
4306 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4307 label
= do_case (loc1
, exp1
, exp2
);
4310 c_parser_error (parser
, "expected %<:%> or %<...%>");
4312 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
4314 c_parser_consume_token (parser
);
4315 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4316 label
= do_case (loc1
, NULL_TREE
, NULL_TREE
);
4320 tree name
= c_parser_peek_token (parser
)->value
;
4323 location_t loc2
= c_parser_peek_token (parser
)->location
;
4324 gcc_assert (c_parser_next_token_is (parser
, CPP_NAME
));
4325 c_parser_consume_token (parser
);
4326 gcc_assert (c_parser_next_token_is (parser
, CPP_COLON
));
4327 c_parser_consume_token (parser
);
4328 attrs
= c_parser_attributes (parser
);
4329 tlab
= define_label (loc2
, name
);
4332 decl_attributes (&tlab
, attrs
, 0);
4333 label
= add_stmt (build_stmt (loc1
, LABEL_EXPR
, tlab
));
4338 if (c_parser_next_tokens_start_declaration (parser
))
4340 error_at (c_parser_peek_token (parser
)->location
,
4341 "a label can only be part of a statement and "
4342 "a declaration is not a statement");
4343 c_parser_declaration_or_fndef (parser
, /*fndef_ok*/ false,
4344 /*static_assert_ok*/ true,
4345 /*empty_ok*/ true, /*nested*/ true,
4346 /*start_attr_ok*/ true, NULL
);
4351 /* Parse a statement (C90 6.6, C99 6.8).
4356 expression-statement
4364 expression-statement:
4367 selection-statement:
4371 iteration-statement:
4380 return expression[opt] ;
4393 objc-throw-statement
4394 objc-try-catch-statement
4395 objc-synchronized-statement
4397 objc-throw-statement:
4411 parallel-for-construct
4412 parallel-sections-construct
4419 parallel-directive structured-block
4422 for-directive iteration-statement
4425 sections-directive section-scope
4428 single-directive structured-block
4430 parallel-for-construct:
4431 parallel-for-directive iteration-statement
4433 parallel-sections-construct:
4434 parallel-sections-directive section-scope
4437 master-directive structured-block
4440 critical-directive structured-block
4443 atomic-directive expression-statement
4446 ordered-directive structured-block
4448 Transactional Memory:
4451 transaction-statement
4452 transaction-cancel-statement
4456 c_parser_statement (c_parser
*parser
)
4458 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4459 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4460 || (c_parser_next_token_is (parser
, CPP_NAME
)
4461 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4462 c_parser_label (parser
);
4463 c_parser_statement_after_labels (parser
);
4466 /* Parse a statement, other than a labeled statement. */
4469 c_parser_statement_after_labels (c_parser
*parser
)
4471 location_t loc
= c_parser_peek_token (parser
)->location
;
4472 tree stmt
= NULL_TREE
;
4473 bool in_if_block
= parser
->in_if_block
;
4474 parser
->in_if_block
= false;
4475 switch (c_parser_peek_token (parser
)->type
)
4477 case CPP_OPEN_BRACE
:
4478 add_stmt (c_parser_compound_statement (parser
));
4481 switch (c_parser_peek_token (parser
)->keyword
)
4484 c_parser_if_statement (parser
);
4487 c_parser_switch_statement (parser
);
4490 c_parser_while_statement (parser
);
4493 c_parser_do_statement (parser
);
4496 c_parser_for_statement (parser
);
4499 c_parser_consume_token (parser
);
4500 if (c_parser_next_token_is (parser
, CPP_NAME
))
4502 stmt
= c_finish_goto_label (loc
,
4503 c_parser_peek_token (parser
)->value
);
4504 c_parser_consume_token (parser
);
4506 else if (c_parser_next_token_is (parser
, CPP_MULT
))
4510 c_parser_consume_token (parser
);
4511 val
= c_parser_expression (parser
).value
;
4512 mark_exp_read (val
);
4513 stmt
= c_finish_goto_ptr (loc
, val
);
4516 c_parser_error (parser
, "expected identifier or %<*%>");
4517 goto expect_semicolon
;
4519 c_parser_consume_token (parser
);
4520 stmt
= c_finish_bc_stmt (loc
, &c_cont_label
, false);
4521 goto expect_semicolon
;
4523 c_parser_consume_token (parser
);
4524 stmt
= c_finish_bc_stmt (loc
, &c_break_label
, true);
4525 goto expect_semicolon
;
4527 c_parser_consume_token (parser
);
4528 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4530 stmt
= c_finish_return (loc
, NULL_TREE
, NULL_TREE
);
4531 c_parser_consume_token (parser
);
4535 struct c_expr expr
= c_parser_expression_conv (parser
);
4536 mark_exp_read (expr
.value
);
4537 stmt
= c_finish_return (loc
, expr
.value
, expr
.original_type
);
4538 goto expect_semicolon
;
4542 stmt
= c_parser_asm_statement (parser
);
4544 case RID_TRANSACTION_ATOMIC
:
4545 case RID_TRANSACTION_RELAXED
:
4546 stmt
= c_parser_transaction (parser
,
4547 c_parser_peek_token (parser
)->keyword
);
4549 case RID_TRANSACTION_CANCEL
:
4550 stmt
= c_parser_transaction_cancel (parser
);
4551 goto expect_semicolon
;
4553 gcc_assert (c_dialect_objc ());
4554 c_parser_consume_token (parser
);
4555 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4557 stmt
= objc_build_throw_stmt (loc
, NULL_TREE
);
4558 c_parser_consume_token (parser
);
4562 tree expr
= c_parser_expression (parser
).value
;
4563 expr
= c_fully_fold (expr
, false, NULL
);
4564 stmt
= objc_build_throw_stmt (loc
, expr
);
4565 goto expect_semicolon
;
4569 gcc_assert (c_dialect_objc ());
4570 c_parser_objc_try_catch_finally_statement (parser
);
4572 case RID_AT_SYNCHRONIZED
:
4573 gcc_assert (c_dialect_objc ());
4574 c_parser_objc_synchronized_statement (parser
);
4581 c_parser_consume_token (parser
);
4583 case CPP_CLOSE_PAREN
:
4584 case CPP_CLOSE_SQUARE
:
4585 /* Avoid infinite loop in error recovery:
4586 c_parser_skip_until_found stops at a closing nesting
4587 delimiter without consuming it, but here we need to consume
4588 it to proceed further. */
4589 c_parser_error (parser
, "expected statement");
4590 c_parser_consume_token (parser
);
4593 c_parser_pragma (parser
, pragma_stmt
);
4597 stmt
= c_finish_expr_stmt (loc
, c_parser_expression_conv (parser
).value
);
4599 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4602 /* Two cases cannot and do not have line numbers associated: If stmt
4603 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
4604 cannot hold line numbers. But that's OK because the statement
4605 will either be changed to a MODIFY_EXPR during gimplification of
4606 the statement expr, or discarded. If stmt was compound, but
4607 without new variables, we will have skipped the creation of a
4608 BIND and will have a bare STATEMENT_LIST. But that's OK because
4609 (recursively) all of the component statements should already have
4610 line numbers assigned. ??? Can we discard no-op statements
4612 if (CAN_HAVE_LOCATION_P (stmt
)
4613 && EXPR_LOCATION (stmt
) == UNKNOWN_LOCATION
)
4614 SET_EXPR_LOCATION (stmt
, loc
);
4616 parser
->in_if_block
= in_if_block
;
4619 /* Parse the condition from an if, do, while or for statements. */
4622 c_parser_condition (c_parser
*parser
)
4624 location_t loc
= c_parser_peek_token (parser
)->location
;
4626 cond
= c_parser_expression_conv (parser
).value
;
4627 cond
= c_objc_common_truthvalue_conversion (loc
, cond
);
4628 cond
= c_fully_fold (cond
, false, NULL
);
4629 if (warn_sequence_point
)
4630 verify_sequence_points (cond
);
4634 /* Parse a parenthesized condition from an if, do or while statement.
4640 c_parser_paren_condition (c_parser
*parser
)
4643 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4644 return error_mark_node
;
4645 cond
= c_parser_condition (parser
);
4646 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4650 /* Parse a statement which is a block in C99. */
4653 c_parser_c99_block_statement (c_parser
*parser
)
4655 tree block
= c_begin_compound_stmt (flag_isoc99
);
4656 location_t loc
= c_parser_peek_token (parser
)->location
;
4657 c_parser_statement (parser
);
4658 return c_end_compound_stmt (loc
, block
, flag_isoc99
);
4661 /* Parse the body of an if statement. This is just parsing a
4662 statement but (a) it is a block in C99, (b) we track whether the
4663 body is an if statement for the sake of -Wparentheses warnings, (c)
4664 we handle an empty body specially for the sake of -Wempty-body
4665 warnings, and (d) we call parser_compound_statement directly
4666 because c_parser_statement_after_labels resets
4667 parser->in_if_block. */
4670 c_parser_if_body (c_parser
*parser
, bool *if_p
)
4672 tree block
= c_begin_compound_stmt (flag_isoc99
);
4673 location_t body_loc
= c_parser_peek_token (parser
)->location
;
4674 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4675 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4676 || (c_parser_next_token_is (parser
, CPP_NAME
)
4677 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4678 c_parser_label (parser
);
4679 *if_p
= c_parser_next_token_is_keyword (parser
, RID_IF
);
4680 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4682 location_t loc
= c_parser_peek_token (parser
)->location
;
4683 add_stmt (build_empty_stmt (loc
));
4684 c_parser_consume_token (parser
);
4685 if (!c_parser_next_token_is_keyword (parser
, RID_ELSE
))
4686 warning_at (loc
, OPT_Wempty_body
,
4687 "suggest braces around empty body in an %<if%> statement");
4689 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4690 add_stmt (c_parser_compound_statement (parser
));
4692 c_parser_statement_after_labels (parser
);
4693 return c_end_compound_stmt (body_loc
, block
, flag_isoc99
);
4696 /* Parse the else body of an if statement. This is just parsing a
4697 statement but (a) it is a block in C99, (b) we handle an empty body
4698 specially for the sake of -Wempty-body warnings. */
4701 c_parser_else_body (c_parser
*parser
)
4703 location_t else_loc
= c_parser_peek_token (parser
)->location
;
4704 tree block
= c_begin_compound_stmt (flag_isoc99
);
4705 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4706 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4707 || (c_parser_next_token_is (parser
, CPP_NAME
)
4708 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4709 c_parser_label (parser
);
4710 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4712 location_t loc
= c_parser_peek_token (parser
)->location
;
4715 "suggest braces around empty body in an %<else%> statement");
4716 add_stmt (build_empty_stmt (loc
));
4717 c_parser_consume_token (parser
);
4720 c_parser_statement_after_labels (parser
);
4721 return c_end_compound_stmt (else_loc
, block
, flag_isoc99
);
4724 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
4727 if ( expression ) statement
4728 if ( expression ) statement else statement
4732 c_parser_if_statement (c_parser
*parser
)
4737 bool first_if
= false;
4738 tree first_body
, second_body
;
4742 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_IF
));
4743 c_parser_consume_token (parser
);
4744 block
= c_begin_compound_stmt (flag_isoc99
);
4745 loc
= c_parser_peek_token (parser
)->location
;
4746 cond
= c_parser_paren_condition (parser
);
4747 in_if_block
= parser
->in_if_block
;
4748 parser
->in_if_block
= true;
4749 first_body
= c_parser_if_body (parser
, &first_if
);
4750 parser
->in_if_block
= in_if_block
;
4751 if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
4753 c_parser_consume_token (parser
);
4754 second_body
= c_parser_else_body (parser
);
4757 second_body
= NULL_TREE
;
4758 c_finish_if_stmt (loc
, cond
, first_body
, second_body
, first_if
);
4759 if_stmt
= c_end_compound_stmt (loc
, block
, flag_isoc99
);
4761 /* If the if statement contains array notations, then we expand them. */
4762 if (flag_enable_cilkplus
&& contains_array_notation_expr (if_stmt
))
4763 if_stmt
= fix_conditional_array_notations (if_stmt
);
4767 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
4770 switch (expression) statement
4774 c_parser_switch_statement (c_parser
*parser
)
4776 tree block
, expr
, body
, save_break
;
4777 location_t switch_loc
= c_parser_peek_token (parser
)->location
;
4778 location_t switch_cond_loc
;
4779 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SWITCH
));
4780 c_parser_consume_token (parser
);
4781 block
= c_begin_compound_stmt (flag_isoc99
);
4782 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4784 switch_cond_loc
= c_parser_peek_token (parser
)->location
;
4785 expr
= c_parser_expression (parser
).value
;
4786 if (flag_enable_cilkplus
&& contains_array_notation_expr (expr
))
4788 error_at (switch_cond_loc
,
4789 "array notations cannot be used as a condition for switch "
4791 expr
= error_mark_node
;
4793 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4797 switch_cond_loc
= UNKNOWN_LOCATION
;
4798 expr
= error_mark_node
;
4800 c_start_case (switch_loc
, switch_cond_loc
, expr
);
4801 save_break
= c_break_label
;
4802 c_break_label
= NULL_TREE
;
4803 body
= c_parser_c99_block_statement (parser
);
4804 c_finish_case (body
);
4807 location_t here
= c_parser_peek_token (parser
)->location
;
4808 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_break_label
);
4809 SET_EXPR_LOCATION (t
, here
);
4812 c_break_label
= save_break
;
4813 add_stmt (c_end_compound_stmt (switch_loc
, block
, flag_isoc99
));
4816 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
4819 while (expression) statement
4823 c_parser_while_statement (c_parser
*parser
)
4825 tree block
, cond
, body
, save_break
, save_cont
;
4827 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_WHILE
));
4828 c_parser_consume_token (parser
);
4829 block
= c_begin_compound_stmt (flag_isoc99
);
4830 loc
= c_parser_peek_token (parser
)->location
;
4831 cond
= c_parser_paren_condition (parser
);
4832 if (flag_enable_cilkplus
&& contains_array_notation_expr (cond
))
4834 error_at (loc
, "array notations cannot be used as a condition for while "
4836 cond
= error_mark_node
;
4838 save_break
= c_break_label
;
4839 c_break_label
= NULL_TREE
;
4840 save_cont
= c_cont_label
;
4841 c_cont_label
= NULL_TREE
;
4842 body
= c_parser_c99_block_statement (parser
);
4843 c_finish_loop (loc
, cond
, NULL
, body
, c_break_label
, c_cont_label
, true);
4844 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
4845 c_break_label
= save_break
;
4846 c_cont_label
= save_cont
;
4849 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
4852 do statement while ( expression ) ;
4856 c_parser_do_statement (c_parser
*parser
)
4858 tree block
, cond
, body
, save_break
, save_cont
, new_break
, new_cont
;
4860 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_DO
));
4861 c_parser_consume_token (parser
);
4862 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4863 warning_at (c_parser_peek_token (parser
)->location
,
4865 "suggest braces around empty body in %<do%> statement");
4866 block
= c_begin_compound_stmt (flag_isoc99
);
4867 loc
= c_parser_peek_token (parser
)->location
;
4868 save_break
= c_break_label
;
4869 c_break_label
= NULL_TREE
;
4870 save_cont
= c_cont_label
;
4871 c_cont_label
= NULL_TREE
;
4872 body
= c_parser_c99_block_statement (parser
);
4873 c_parser_require_keyword (parser
, RID_WHILE
, "expected %<while%>");
4874 new_break
= c_break_label
;
4875 c_break_label
= save_break
;
4876 new_cont
= c_cont_label
;
4877 c_cont_label
= save_cont
;
4878 cond
= c_parser_paren_condition (parser
);
4879 if (flag_enable_cilkplus
&& contains_array_notation_expr (cond
))
4881 error_at (loc
, "array notations cannot be used as a condition for a "
4882 "do-while statement");
4883 cond
= error_mark_node
;
4886 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
4887 c_parser_skip_to_end_of_block_or_statement (parser
);
4888 c_finish_loop (loc
, cond
, NULL
, body
, new_break
, new_cont
, false);
4889 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
4892 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
4895 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
4896 for ( nested-declaration expression[opt] ; expression[opt] ) statement
4898 The form with a declaration is new in C99.
4900 ??? In accordance with the old parser, the declaration may be a
4901 nested function, which is then rejected in check_for_loop_decls,
4902 but does it make any sense for this to be included in the grammar?
4903 Note in particular that the nested function does not include a
4904 trailing ';', whereas the "declaration" production includes one.
4905 Also, can we reject bad declarations earlier and cheaper than
4906 check_for_loop_decls?
4908 In Objective-C, there are two additional variants:
4911 for ( expression in expresssion ) statement
4912 for ( declaration in expression ) statement
4914 This is inconsistent with C, because the second variant is allowed
4915 even if c99 is not enabled.
4917 The rest of the comment documents these Objective-C foreach-statement.
4919 Here is the canonical example of the first variant:
4920 for (object in array) { do something with object }
4921 we call the first expression ("object") the "object_expression" and
4922 the second expression ("array") the "collection_expression".
4923 object_expression must be an lvalue of type "id" (a generic Objective-C
4924 object) because the loop works by assigning to object_expression the
4925 various objects from the collection_expression. collection_expression
4926 must evaluate to something of type "id" which responds to the method
4927 countByEnumeratingWithState:objects:count:.
4929 The canonical example of the second variant is:
4930 for (id object in array) { do something with object }
4931 which is completely equivalent to
4934 for (object in array) { do something with object }
4936 Note that initizializing 'object' in some way (eg, "for ((object =
4937 xxx) in array) { do something with object }") is possibly
4938 technically valid, but completely pointless as 'object' will be
4939 assigned to something else as soon as the loop starts. We should
4940 most likely reject it (TODO).
4942 The beginning of the Objective-C foreach-statement looks exactly
4943 like the beginning of the for-statement, and we can tell it is a
4944 foreach-statement only because the initial declaration or
4945 expression is terminated by 'in' instead of ';'.
4949 c_parser_for_statement (c_parser
*parser
)
4951 tree block
, cond
, incr
, save_break
, save_cont
, body
;
4952 /* The following are only used when parsing an ObjC foreach statement. */
4953 tree object_expression
;
4954 /* Silence the bogus uninitialized warning. */
4955 tree collection_expression
= NULL
;
4956 location_t loc
= c_parser_peek_token (parser
)->location
;
4957 location_t for_loc
= c_parser_peek_token (parser
)->location
;
4958 bool is_foreach_statement
= false;
4959 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_FOR
));
4960 c_parser_consume_token (parser
);
4961 /* Open a compound statement in Objective-C as well, just in case this is
4962 as foreach expression. */
4963 block
= c_begin_compound_stmt (flag_isoc99
|| c_dialect_objc ());
4964 cond
= error_mark_node
;
4965 incr
= error_mark_node
;
4966 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4968 /* Parse the initialization declaration or expression. */
4969 object_expression
= error_mark_node
;
4970 parser
->objc_could_be_foreach_context
= c_dialect_objc ();
4971 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4973 parser
->objc_could_be_foreach_context
= false;
4974 c_parser_consume_token (parser
);
4975 c_finish_expr_stmt (loc
, NULL_TREE
);
4977 else if (c_parser_next_tokens_start_declaration (parser
))
4979 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
4980 &object_expression
);
4981 parser
->objc_could_be_foreach_context
= false;
4983 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
4985 c_parser_consume_token (parser
);
4986 is_foreach_statement
= true;
4987 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
4988 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
4991 check_for_loop_decls (for_loc
, flag_isoc99
);
4993 else if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
4995 /* __extension__ can start a declaration, but is also an
4996 unary operator that can start an expression. Consume all
4997 but the last of a possible series of __extension__ to
4999 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
5000 && (c_parser_peek_2nd_token (parser
)->keyword
5002 c_parser_consume_token (parser
);
5003 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
5006 ext
= disable_extension_diagnostics ();
5007 c_parser_consume_token (parser
);
5008 c_parser_declaration_or_fndef (parser
, true, true, true, true,
5009 true, &object_expression
);
5010 parser
->objc_could_be_foreach_context
= false;
5012 restore_extension_diagnostics (ext
);
5013 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5015 c_parser_consume_token (parser
);
5016 is_foreach_statement
= true;
5017 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
5018 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
5021 check_for_loop_decls (for_loc
, flag_isoc99
);
5030 tree init_expression
;
5031 init_expression
= c_parser_expression (parser
).value
;
5032 parser
->objc_could_be_foreach_context
= false;
5033 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5035 c_parser_consume_token (parser
);
5036 is_foreach_statement
= true;
5037 if (! lvalue_p (init_expression
))
5038 c_parser_error (parser
, "invalid iterating variable in fast enumeration");
5039 object_expression
= c_fully_fold (init_expression
, false, NULL
);
5043 c_finish_expr_stmt (loc
, init_expression
);
5044 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5048 /* Parse the loop condition. In the case of a foreach
5049 statement, there is no loop condition. */
5050 gcc_assert (!parser
->objc_could_be_foreach_context
);
5051 if (!is_foreach_statement
)
5053 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5055 c_parser_consume_token (parser
);
5060 cond
= c_parser_condition (parser
);
5061 if (flag_enable_cilkplus
&& contains_array_notation_expr (cond
))
5063 error_at (loc
, "array notations cannot be used in a "
5064 "condition for a for-loop");
5065 cond
= error_mark_node
;
5067 c_parser_skip_until_found (parser
, CPP_SEMICOLON
,
5071 /* Parse the increment expression (the third expression in a
5072 for-statement). In the case of a foreach-statement, this is
5073 the expression that follows the 'in'. */
5074 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
5076 if (is_foreach_statement
)
5078 c_parser_error (parser
, "missing collection in fast enumeration");
5079 collection_expression
= error_mark_node
;
5082 incr
= c_process_expr_stmt (loc
, NULL_TREE
);
5086 if (is_foreach_statement
)
5087 collection_expression
= c_fully_fold (c_parser_expression (parser
).value
,
5090 incr
= c_process_expr_stmt (loc
, c_parser_expression (parser
).value
);
5092 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5094 save_break
= c_break_label
;
5095 c_break_label
= NULL_TREE
;
5096 save_cont
= c_cont_label
;
5097 c_cont_label
= NULL_TREE
;
5098 body
= c_parser_c99_block_statement (parser
);
5099 if (is_foreach_statement
)
5100 objc_finish_foreach_loop (loc
, object_expression
, collection_expression
, body
, c_break_label
, c_cont_label
);
5102 c_finish_loop (loc
, cond
, incr
, body
, c_break_label
, c_cont_label
, true);
5103 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
|| c_dialect_objc ()));
5104 c_break_label
= save_break
;
5105 c_cont_label
= save_cont
;
5108 /* Parse an asm statement, a GNU extension. This is a full-blown asm
5109 statement with inputs, outputs, clobbers, and volatile tag
5113 asm type-qualifier[opt] ( asm-argument ) ;
5114 asm type-qualifier[opt] goto ( asm-goto-argument ) ;
5118 asm-string-literal : asm-operands[opt]
5119 asm-string-literal : asm-operands[opt] : asm-operands[opt]
5120 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers[opt]
5123 asm-string-literal : : asm-operands[opt] : asm-clobbers[opt] \
5126 Qualifiers other than volatile are accepted in the syntax but
5130 c_parser_asm_statement (c_parser
*parser
)
5132 tree quals
, str
, outputs
, inputs
, clobbers
, labels
, ret
;
5133 bool simple
, is_goto
;
5134 location_t asm_loc
= c_parser_peek_token (parser
)->location
;
5135 int section
, nsections
;
5137 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
5138 c_parser_consume_token (parser
);
5139 if (c_parser_next_token_is_keyword (parser
, RID_VOLATILE
))
5141 quals
= c_parser_peek_token (parser
)->value
;
5142 c_parser_consume_token (parser
);
5144 else if (c_parser_next_token_is_keyword (parser
, RID_CONST
)
5145 || c_parser_next_token_is_keyword (parser
, RID_RESTRICT
))
5147 warning_at (c_parser_peek_token (parser
)->location
,
5149 "%E qualifier ignored on asm",
5150 c_parser_peek_token (parser
)->value
);
5152 c_parser_consume_token (parser
);
5158 if (c_parser_next_token_is_keyword (parser
, RID_GOTO
))
5160 c_parser_consume_token (parser
);
5164 /* ??? Follow the C++ parser rather than using the
5165 lex_untranslated_string kludge. */
5166 parser
->lex_untranslated_string
= true;
5169 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5172 str
= c_parser_asm_string_literal (parser
);
5173 if (str
== NULL_TREE
)
5174 goto error_close_paren
;
5177 outputs
= NULL_TREE
;
5179 clobbers
= NULL_TREE
;
5182 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
5185 /* Parse each colon-delimited section of operands. */
5186 nsections
= 3 + is_goto
;
5187 for (section
= 0; section
< nsections
; ++section
)
5189 if (!c_parser_require (parser
, CPP_COLON
,
5192 : "expected %<:%> or %<)%>"))
5193 goto error_close_paren
;
5195 /* Once past any colon, we're no longer a simple asm. */
5198 if ((!c_parser_next_token_is (parser
, CPP_COLON
)
5199 && !c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
5204 /* For asm goto, we don't allow output operands, but reserve
5205 the slot for a future extension that does allow them. */
5207 outputs
= c_parser_asm_operands (parser
);
5210 inputs
= c_parser_asm_operands (parser
);
5213 clobbers
= c_parser_asm_clobbers (parser
);
5216 labels
= c_parser_asm_goto_operands (parser
);
5222 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
5227 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
5229 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5233 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
5234 c_parser_skip_to_end_of_block_or_statement (parser
);
5236 ret
= build_asm_stmt (quals
, build_asm_expr (asm_loc
, str
, outputs
, inputs
,
5237 clobbers
, labels
, simple
));
5240 parser
->lex_untranslated_string
= false;
5244 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5248 /* Parse asm operands, a GNU extension.
5252 asm-operands , asm-operand
5255 asm-string-literal ( expression )
5256 [ identifier ] asm-string-literal ( expression )
5260 c_parser_asm_operands (c_parser
*parser
)
5262 tree list
= NULL_TREE
;
5267 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
5269 c_parser_consume_token (parser
);
5270 if (c_parser_next_token_is (parser
, CPP_NAME
))
5272 tree id
= c_parser_peek_token (parser
)->value
;
5273 c_parser_consume_token (parser
);
5274 name
= build_string (IDENTIFIER_LENGTH (id
),
5275 IDENTIFIER_POINTER (id
));
5279 c_parser_error (parser
, "expected identifier");
5280 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
5283 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5288 str
= c_parser_asm_string_literal (parser
);
5289 if (str
== NULL_TREE
)
5291 parser
->lex_untranslated_string
= false;
5292 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5294 parser
->lex_untranslated_string
= true;
5297 expr
= c_parser_expression (parser
);
5298 mark_exp_read (expr
.value
);
5299 parser
->lex_untranslated_string
= true;
5300 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
5302 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5305 list
= chainon (list
, build_tree_list (build_tree_list (name
, str
),
5307 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5308 c_parser_consume_token (parser
);
5315 /* Parse asm clobbers, a GNU extension.
5319 asm-clobbers , asm-string-literal
5323 c_parser_asm_clobbers (c_parser
*parser
)
5325 tree list
= NULL_TREE
;
5328 tree str
= c_parser_asm_string_literal (parser
);
5330 list
= tree_cons (NULL_TREE
, str
, list
);
5333 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5334 c_parser_consume_token (parser
);
5341 /* Parse asm goto labels, a GNU extension.
5345 asm-goto-operands , identifier
5349 c_parser_asm_goto_operands (c_parser
*parser
)
5351 tree list
= NULL_TREE
;
5356 if (c_parser_next_token_is (parser
, CPP_NAME
))
5358 c_token
*tok
= c_parser_peek_token (parser
);
5360 label
= lookup_label_for_goto (tok
->location
, name
);
5361 c_parser_consume_token (parser
);
5362 TREE_USED (label
) = 1;
5366 c_parser_error (parser
, "expected identifier");
5370 name
= build_string (IDENTIFIER_LENGTH (name
),
5371 IDENTIFIER_POINTER (name
));
5372 list
= tree_cons (name
, label
, list
);
5373 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5374 c_parser_consume_token (parser
);
5376 return nreverse (list
);
5380 /* Parse an expression other than a compound expression; that is, an
5381 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
5382 NULL then it is an Objective-C message expression which is the
5383 primary-expression starting the expression as an initializer.
5385 assignment-expression:
5386 conditional-expression
5387 unary-expression assignment-operator assignment-expression
5389 assignment-operator: one of
5390 = *= /= %= += -= <<= >>= &= ^= |=
5392 In GNU C we accept any conditional expression on the LHS and
5393 diagnose the invalid lvalue rather than producing a syntax
5396 static struct c_expr
5397 c_parser_expr_no_commas (c_parser
*parser
, struct c_expr
*after
)
5399 struct c_expr lhs
, rhs
, ret
;
5400 enum tree_code code
;
5401 location_t op_location
, exp_location
;
5402 gcc_assert (!after
|| c_dialect_objc ());
5403 lhs
= c_parser_conditional_expression (parser
, after
);
5404 op_location
= c_parser_peek_token (parser
)->location
;
5405 switch (c_parser_peek_token (parser
)->type
)
5414 code
= TRUNC_DIV_EXPR
;
5417 code
= TRUNC_MOD_EXPR
;
5432 code
= BIT_AND_EXPR
;
5435 code
= BIT_XOR_EXPR
;
5438 code
= BIT_IOR_EXPR
;
5443 c_parser_consume_token (parser
);
5444 exp_location
= c_parser_peek_token (parser
)->location
;
5445 rhs
= c_parser_expr_no_commas (parser
, NULL
);
5446 rhs
= default_function_array_read_conversion (exp_location
, rhs
);
5448 /* The line below is where the statement has the form:
5449 A = B, where A and B contain array notation exprs. So this is where
5451 if (flag_enable_cilkplus
5452 && (contains_array_notation_expr (lhs
.value
)
5453 || contains_array_notation_expr (rhs
.value
)))
5454 ret
.value
= build_array_notation_expr (op_location
, lhs
.value
,
5455 lhs
.original_type
, code
,
5456 exp_location
, rhs
.value
,
5459 ret
.value
= build_modify_expr (op_location
, lhs
.value
, lhs
.original_type
,
5460 code
, exp_location
, rhs
.value
,
5462 if (code
== NOP_EXPR
)
5463 ret
.original_code
= MODIFY_EXPR
;
5466 TREE_NO_WARNING (ret
.value
) = 1;
5467 ret
.original_code
= ERROR_MARK
;
5469 ret
.original_type
= NULL
;
5473 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
5474 is not NULL then it is an Objective-C message expression which is
5475 the primary-expression starting the expression as an initializer.
5477 conditional-expression:
5478 logical-OR-expression
5479 logical-OR-expression ? expression : conditional-expression
5483 conditional-expression:
5484 logical-OR-expression ? : conditional-expression
5487 static struct c_expr
5488 c_parser_conditional_expression (c_parser
*parser
, struct c_expr
*after
)
5490 struct c_expr cond
, exp1
, exp2
, ret
;
5491 location_t cond_loc
, colon_loc
, middle_loc
;
5493 gcc_assert (!after
|| c_dialect_objc ());
5495 cond
= c_parser_binary_expression (parser
, after
, PREC_NONE
);
5497 if (c_parser_next_token_is_not (parser
, CPP_QUERY
))
5499 cond_loc
= c_parser_peek_token (parser
)->location
;
5500 cond
= default_function_array_read_conversion (cond_loc
, cond
);
5501 c_parser_consume_token (parser
);
5502 if (c_parser_next_token_is (parser
, CPP_COLON
))
5504 tree eptype
= NULL_TREE
;
5506 middle_loc
= c_parser_peek_token (parser
)->location
;
5507 pedwarn (middle_loc
, OPT_Wpedantic
,
5508 "ISO C forbids omitting the middle term of a ?: expression");
5509 warn_for_omitted_condop (middle_loc
, cond
.value
);
5510 if (TREE_CODE (cond
.value
) == EXCESS_PRECISION_EXPR
)
5512 eptype
= TREE_TYPE (cond
.value
);
5513 cond
.value
= TREE_OPERAND (cond
.value
, 0);
5515 /* Make sure first operand is calculated only once. */
5516 exp1
.value
= c_save_expr (default_conversion (cond
.value
));
5518 exp1
.value
= build1 (EXCESS_PRECISION_EXPR
, eptype
, exp1
.value
);
5519 exp1
.original_type
= NULL
;
5520 cond
.value
= c_objc_common_truthvalue_conversion (cond_loc
, exp1
.value
);
5521 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_true_node
;
5526 = c_objc_common_truthvalue_conversion
5527 (cond_loc
, default_conversion (cond
.value
));
5528 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_false_node
;
5529 exp1
= c_parser_expression_conv (parser
);
5530 mark_exp_read (exp1
.value
);
5531 c_inhibit_evaluation_warnings
+=
5532 ((cond
.value
== truthvalue_true_node
)
5533 - (cond
.value
== truthvalue_false_node
));
5536 colon_loc
= c_parser_peek_token (parser
)->location
;
5537 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
5539 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
5540 ret
.value
= error_mark_node
;
5541 ret
.original_code
= ERROR_MARK
;
5542 ret
.original_type
= NULL
;
5546 location_t exp2_loc
= c_parser_peek_token (parser
)->location
;
5547 exp2
= c_parser_conditional_expression (parser
, NULL
);
5548 exp2
= default_function_array_read_conversion (exp2_loc
, exp2
);
5550 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
5551 ret
.value
= build_conditional_expr (colon_loc
, cond
.value
,
5552 cond
.original_code
== C_MAYBE_CONST_EXPR
,
5553 exp1
.value
, exp1
.original_type
,
5554 exp2
.value
, exp2
.original_type
);
5555 ret
.original_code
= ERROR_MARK
;
5556 if (exp1
.value
== error_mark_node
|| exp2
.value
== error_mark_node
)
5557 ret
.original_type
= NULL
;
5562 /* If both sides are enum type, the default conversion will have
5563 made the type of the result be an integer type. We want to
5564 remember the enum types we started with. */
5565 t1
= exp1
.original_type
? exp1
.original_type
: TREE_TYPE (exp1
.value
);
5566 t2
= exp2
.original_type
? exp2
.original_type
: TREE_TYPE (exp2
.value
);
5567 ret
.original_type
= ((t1
!= error_mark_node
5568 && t2
!= error_mark_node
5569 && (TYPE_MAIN_VARIANT (t1
)
5570 == TYPE_MAIN_VARIANT (t2
)))
5577 /* Parse a binary expression; that is, a logical-OR-expression (C90
5578 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
5579 an Objective-C message expression which is the primary-expression
5580 starting the expression as an initializer. PREC is the starting
5581 precedence, usually PREC_NONE.
5583 multiplicative-expression:
5585 multiplicative-expression * cast-expression
5586 multiplicative-expression / cast-expression
5587 multiplicative-expression % cast-expression
5589 additive-expression:
5590 multiplicative-expression
5591 additive-expression + multiplicative-expression
5592 additive-expression - multiplicative-expression
5596 shift-expression << additive-expression
5597 shift-expression >> additive-expression
5599 relational-expression:
5601 relational-expression < shift-expression
5602 relational-expression > shift-expression
5603 relational-expression <= shift-expression
5604 relational-expression >= shift-expression
5606 equality-expression:
5607 relational-expression
5608 equality-expression == relational-expression
5609 equality-expression != relational-expression
5613 AND-expression & equality-expression
5615 exclusive-OR-expression:
5617 exclusive-OR-expression ^ AND-expression
5619 inclusive-OR-expression:
5620 exclusive-OR-expression
5621 inclusive-OR-expression | exclusive-OR-expression
5623 logical-AND-expression:
5624 inclusive-OR-expression
5625 logical-AND-expression && inclusive-OR-expression
5627 logical-OR-expression:
5628 logical-AND-expression
5629 logical-OR-expression || logical-AND-expression
5632 static struct c_expr
5633 c_parser_binary_expression (c_parser
*parser
, struct c_expr
*after
,
5634 enum c_parser_prec prec
)
5636 /* A binary expression is parsed using operator-precedence parsing,
5637 with the operands being cast expressions. All the binary
5638 operators are left-associative. Thus a binary expression is of
5641 E0 op1 E1 op2 E2 ...
5643 which we represent on a stack. On the stack, the precedence
5644 levels are strictly increasing. When a new operator is
5645 encountered of higher precedence than that at the top of the
5646 stack, it is pushed; its LHS is the top expression, and its RHS
5647 is everything parsed until it is popped. When a new operator is
5648 encountered with precedence less than or equal to that at the top
5649 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
5650 by the result of the operation until the operator at the top of
5651 the stack has lower precedence than the new operator or there is
5652 only one element on the stack; then the top expression is the LHS
5653 of the new operator. In the case of logical AND and OR
5654 expressions, we also need to adjust c_inhibit_evaluation_warnings
5655 as appropriate when the operators are pushed and popped. */
5658 /* The expression at this stack level. */
5660 /* The precedence of the operator on its left, PREC_NONE at the
5661 bottom of the stack. */
5662 enum c_parser_prec prec
;
5663 /* The operation on its left. */
5665 /* The source location of this operation. */
5669 /* Location of the binary operator. */
5670 location_t binary_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
5673 switch (stack[sp].op) \
5675 case TRUTH_ANDIF_EXPR: \
5676 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
5677 == truthvalue_false_node); \
5679 case TRUTH_ORIF_EXPR: \
5680 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
5681 == truthvalue_true_node); \
5686 stack[sp - 1].expr \
5687 = default_function_array_read_conversion (stack[sp - 1].loc, \
5688 stack[sp - 1].expr); \
5690 = default_function_array_read_conversion (stack[sp].loc, \
5692 stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc, \
5694 stack[sp - 1].expr, \
5698 gcc_assert (!after
|| c_dialect_objc ());
5699 stack
[0].loc
= c_parser_peek_token (parser
)->location
;
5700 stack
[0].expr
= c_parser_cast_expression (parser
, after
);
5701 stack
[0].prec
= prec
;
5705 enum c_parser_prec oprec
;
5706 enum tree_code ocode
;
5709 switch (c_parser_peek_token (parser
)->type
)
5717 ocode
= TRUNC_DIV_EXPR
;
5721 ocode
= TRUNC_MOD_EXPR
;
5733 ocode
= LSHIFT_EXPR
;
5737 ocode
= RSHIFT_EXPR
;
5751 case CPP_GREATER_EQ
:
5764 oprec
= PREC_BITAND
;
5765 ocode
= BIT_AND_EXPR
;
5768 oprec
= PREC_BITXOR
;
5769 ocode
= BIT_XOR_EXPR
;
5773 ocode
= BIT_IOR_EXPR
;
5776 oprec
= PREC_LOGAND
;
5777 ocode
= TRUTH_ANDIF_EXPR
;
5781 ocode
= TRUTH_ORIF_EXPR
;
5784 /* Not a binary operator, so end of the binary
5788 binary_loc
= c_parser_peek_token (parser
)->location
;
5789 while (oprec
<= stack
[sp
].prec
)
5795 c_parser_consume_token (parser
);
5798 case TRUTH_ANDIF_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_false_node
);
5807 case TRUTH_ORIF_EXPR
:
5809 = default_function_array_read_conversion (stack
[sp
].loc
,
5811 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
5812 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
5813 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
5814 == truthvalue_true_node
);
5820 stack
[sp
].loc
= binary_loc
;
5821 stack
[sp
].expr
= c_parser_cast_expression (parser
, NULL
);
5822 stack
[sp
].prec
= oprec
;
5823 stack
[sp
].op
= ocode
;
5824 stack
[sp
].loc
= binary_loc
;
5829 return stack
[0].expr
;
5833 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
5834 NULL then it is an Objective-C message expression which is the
5835 primary-expression starting the expression as an initializer.
5839 ( type-name ) unary-expression
5842 static struct c_expr
5843 c_parser_cast_expression (c_parser
*parser
, struct c_expr
*after
)
5845 location_t cast_loc
= c_parser_peek_token (parser
)->location
;
5846 gcc_assert (!after
|| c_dialect_objc ());
5848 return c_parser_postfix_expression_after_primary (parser
,
5850 /* If the expression begins with a parenthesized type name, it may
5851 be either a cast or a compound literal; we need to see whether
5852 the next character is '{' to tell the difference. If not, it is
5853 an unary expression. Full detection of unknown typenames here
5854 would require a 3-token lookahead. */
5855 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
5856 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
5858 struct c_type_name
*type_name
;
5861 c_parser_consume_token (parser
);
5862 type_name
= c_parser_type_name (parser
);
5863 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5864 if (type_name
== NULL
)
5866 ret
.value
= error_mark_node
;
5867 ret
.original_code
= ERROR_MARK
;
5868 ret
.original_type
= NULL
;
5872 /* Save casted types in the function's used types hash table. */
5873 used_types_insert (type_name
->specs
->type
);
5875 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5876 return c_parser_postfix_expression_after_paren_type (parser
, type_name
,
5879 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
5880 expr
= c_parser_cast_expression (parser
, NULL
);
5881 expr
= default_function_array_read_conversion (expr_loc
, expr
);
5883 ret
.value
= c_cast_expr (cast_loc
, type_name
, expr
.value
);
5884 ret
.original_code
= ERROR_MARK
;
5885 ret
.original_type
= NULL
;
5889 return c_parser_unary_expression (parser
);
5892 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
5898 unary-operator cast-expression
5899 sizeof unary-expression
5900 sizeof ( type-name )
5902 unary-operator: one of
5908 __alignof__ unary-expression
5909 __alignof__ ( type-name )
5912 (C11 permits _Alignof with type names only.)
5914 unary-operator: one of
5915 __extension__ __real__ __imag__
5917 Transactional Memory:
5920 transaction-expression
5922 In addition, the GNU syntax treats ++ and -- as unary operators, so
5923 they may be applied to cast expressions with errors for non-lvalues
5926 static struct c_expr
5927 c_parser_unary_expression (c_parser
*parser
)
5930 struct c_expr ret
, op
;
5931 location_t op_loc
= c_parser_peek_token (parser
)->location
;
5933 ret
.original_code
= ERROR_MARK
;
5934 ret
.original_type
= NULL
;
5935 switch (c_parser_peek_token (parser
)->type
)
5938 c_parser_consume_token (parser
);
5939 exp_loc
= c_parser_peek_token (parser
)->location
;
5940 op
= c_parser_cast_expression (parser
, NULL
);
5942 /* If there is array notations in op, we expand them. */
5943 if (flag_enable_cilkplus
&& TREE_CODE (op
.value
) == ARRAY_NOTATION_REF
)
5944 return fix_array_notation_expr (exp_loc
, PREINCREMENT_EXPR
, op
);
5947 op
= default_function_array_read_conversion (exp_loc
, op
);
5948 return parser_build_unary_op (op_loc
, PREINCREMENT_EXPR
, op
);
5950 case CPP_MINUS_MINUS
:
5951 c_parser_consume_token (parser
);
5952 exp_loc
= c_parser_peek_token (parser
)->location
;
5953 op
= c_parser_cast_expression (parser
, NULL
);
5955 /* If there is array notations in op, we expand them. */
5956 if (flag_enable_cilkplus
&& TREE_CODE (op
.value
) == ARRAY_NOTATION_REF
)
5957 return fix_array_notation_expr (exp_loc
, PREDECREMENT_EXPR
, op
);
5960 op
= default_function_array_read_conversion (exp_loc
, op
);
5961 return parser_build_unary_op (op_loc
, PREDECREMENT_EXPR
, op
);
5964 c_parser_consume_token (parser
);
5965 op
= c_parser_cast_expression (parser
, NULL
);
5966 mark_exp_read (op
.value
);
5967 return parser_build_unary_op (op_loc
, ADDR_EXPR
, op
);
5969 c_parser_consume_token (parser
);
5970 exp_loc
= c_parser_peek_token (parser
)->location
;
5971 op
= c_parser_cast_expression (parser
, NULL
);
5972 op
= default_function_array_read_conversion (exp_loc
, op
);
5973 ret
.value
= build_indirect_ref (op_loc
, op
.value
, RO_UNARY_STAR
);
5976 if (!c_dialect_objc () && !in_system_header
)
5979 "traditional C rejects the unary plus operator");
5980 c_parser_consume_token (parser
);
5981 exp_loc
= c_parser_peek_token (parser
)->location
;
5982 op
= c_parser_cast_expression (parser
, NULL
);
5983 op
= default_function_array_read_conversion (exp_loc
, op
);
5984 return parser_build_unary_op (op_loc
, CONVERT_EXPR
, op
);
5986 c_parser_consume_token (parser
);
5987 exp_loc
= c_parser_peek_token (parser
)->location
;
5988 op
= c_parser_cast_expression (parser
, NULL
);
5989 op
= default_function_array_read_conversion (exp_loc
, op
);
5990 return parser_build_unary_op (op_loc
, NEGATE_EXPR
, op
);
5992 c_parser_consume_token (parser
);
5993 exp_loc
= c_parser_peek_token (parser
)->location
;
5994 op
= c_parser_cast_expression (parser
, NULL
);
5995 op
= default_function_array_read_conversion (exp_loc
, op
);
5996 return parser_build_unary_op (op_loc
, BIT_NOT_EXPR
, op
);
5998 c_parser_consume_token (parser
);
5999 exp_loc
= c_parser_peek_token (parser
)->location
;
6000 op
= c_parser_cast_expression (parser
, NULL
);
6001 op
= default_function_array_read_conversion (exp_loc
, op
);
6002 return parser_build_unary_op (op_loc
, TRUTH_NOT_EXPR
, op
);
6004 /* Refer to the address of a label as a pointer. */
6005 c_parser_consume_token (parser
);
6006 if (c_parser_next_token_is (parser
, CPP_NAME
))
6008 ret
.value
= finish_label_address_expr
6009 (c_parser_peek_token (parser
)->value
, op_loc
);
6010 c_parser_consume_token (parser
);
6014 c_parser_error (parser
, "expected identifier");
6015 ret
.value
= error_mark_node
;
6019 switch (c_parser_peek_token (parser
)->keyword
)
6022 return c_parser_sizeof_expression (parser
);
6024 return c_parser_alignof_expression (parser
);
6026 c_parser_consume_token (parser
);
6027 ext
= disable_extension_diagnostics ();
6028 ret
= c_parser_cast_expression (parser
, NULL
);
6029 restore_extension_diagnostics (ext
);
6032 c_parser_consume_token (parser
);
6033 exp_loc
= c_parser_peek_token (parser
)->location
;
6034 op
= c_parser_cast_expression (parser
, NULL
);
6035 op
= default_function_array_conversion (exp_loc
, op
);
6036 return parser_build_unary_op (op_loc
, REALPART_EXPR
, op
);
6038 c_parser_consume_token (parser
);
6039 exp_loc
= c_parser_peek_token (parser
)->location
;
6040 op
= c_parser_cast_expression (parser
, NULL
);
6041 op
= default_function_array_conversion (exp_loc
, op
);
6042 return parser_build_unary_op (op_loc
, IMAGPART_EXPR
, op
);
6043 case RID_TRANSACTION_ATOMIC
:
6044 case RID_TRANSACTION_RELAXED
:
6045 return c_parser_transaction_expression (parser
,
6046 c_parser_peek_token (parser
)->keyword
);
6048 return c_parser_postfix_expression (parser
);
6051 return c_parser_postfix_expression (parser
);
6055 /* Parse a sizeof expression. */
6057 static struct c_expr
6058 c_parser_sizeof_expression (c_parser
*parser
)
6061 location_t expr_loc
;
6062 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SIZEOF
));
6063 c_parser_consume_token (parser
);
6064 c_inhibit_evaluation_warnings
++;
6066 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
6067 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6069 /* Either sizeof ( type-name ) or sizeof unary-expression
6070 starting with a compound literal. */
6071 struct c_type_name
*type_name
;
6072 c_parser_consume_token (parser
);
6073 expr_loc
= c_parser_peek_token (parser
)->location
;
6074 type_name
= c_parser_type_name (parser
);
6075 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6076 if (type_name
== NULL
)
6079 c_inhibit_evaluation_warnings
--;
6081 ret
.value
= error_mark_node
;
6082 ret
.original_code
= ERROR_MARK
;
6083 ret
.original_type
= NULL
;
6086 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6088 expr
= c_parser_postfix_expression_after_paren_type (parser
,
6093 /* sizeof ( type-name ). */
6094 c_inhibit_evaluation_warnings
--;
6096 return c_expr_sizeof_type (expr_loc
, type_name
);
6100 expr_loc
= c_parser_peek_token (parser
)->location
;
6101 expr
= c_parser_unary_expression (parser
);
6103 c_inhibit_evaluation_warnings
--;
6105 mark_exp_read (expr
.value
);
6106 if (TREE_CODE (expr
.value
) == COMPONENT_REF
6107 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
6108 error_at (expr_loc
, "%<sizeof%> applied to a bit-field");
6109 return c_expr_sizeof_expr (expr_loc
, expr
);
6113 /* Parse an alignof expression. */
6115 static struct c_expr
6116 c_parser_alignof_expression (c_parser
*parser
)
6119 location_t loc
= c_parser_peek_token (parser
)->location
;
6120 tree alignof_spelling
= c_parser_peek_token (parser
)->value
;
6121 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNOF
));
6122 /* A diagnostic is not required for the use of this identifier in
6123 the implementation namespace; only diagnose it for the C11
6124 spelling because of existing code using the other spellings. */
6126 && strcmp (IDENTIFIER_POINTER (alignof_spelling
), "_Alignof") == 0)
6129 pedwarn (loc
, OPT_Wpedantic
, "ISO C99 does not support %qE",
6132 pedwarn (loc
, OPT_Wpedantic
, "ISO C90 does not support %qE",
6135 c_parser_consume_token (parser
);
6136 c_inhibit_evaluation_warnings
++;
6138 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
6139 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6141 /* Either __alignof__ ( type-name ) or __alignof__
6142 unary-expression starting with a compound literal. */
6144 struct c_type_name
*type_name
;
6146 c_parser_consume_token (parser
);
6147 loc
= c_parser_peek_token (parser
)->location
;
6148 type_name
= c_parser_type_name (parser
);
6149 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6150 if (type_name
== NULL
)
6153 c_inhibit_evaluation_warnings
--;
6155 ret
.value
= error_mark_node
;
6156 ret
.original_code
= ERROR_MARK
;
6157 ret
.original_type
= NULL
;
6160 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6162 expr
= c_parser_postfix_expression_after_paren_type (parser
,
6167 /* alignof ( type-name ). */
6168 c_inhibit_evaluation_warnings
--;
6170 ret
.value
= c_alignof (loc
, groktypename (type_name
, NULL
, NULL
));
6171 ret
.original_code
= ERROR_MARK
;
6172 ret
.original_type
= NULL
;
6178 expr
= c_parser_unary_expression (parser
);
6180 mark_exp_read (expr
.value
);
6181 c_inhibit_evaluation_warnings
--;
6183 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not allow %<%E (expression)%>",
6185 ret
.value
= c_alignof_expr (loc
, expr
.value
);
6186 ret
.original_code
= ERROR_MARK
;
6187 ret
.original_type
= NULL
;
6192 /* Helper function to read arguments of builtins which are interfaces
6193 for the middle-end nodes like COMPLEX_EXPR, VEC_PERM_EXPR and
6194 others. The name of the builtin is passed using BNAME parameter.
6195 Function returns true if there were no errors while parsing and
6196 stores the arguments in CEXPR_LIST. */
6198 c_parser_get_builtin_args (c_parser
*parser
, const char *bname
,
6199 vec
<c_expr_t
, va_gc
> **ret_cexpr_list
,
6202 location_t loc
= c_parser_peek_token (parser
)->location
;
6203 vec
<c_expr_t
, va_gc
> *cexpr_list
;
6205 bool saved_force_folding_builtin_constant_p
;
6207 *ret_cexpr_list
= NULL
;
6208 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
6210 error_at (loc
, "cannot take address of %qs", bname
);
6214 c_parser_consume_token (parser
);
6216 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
6218 c_parser_consume_token (parser
);
6222 saved_force_folding_builtin_constant_p
6223 = force_folding_builtin_constant_p
;
6224 force_folding_builtin_constant_p
|= choose_expr_p
;
6225 expr
= c_parser_expr_no_commas (parser
, NULL
);
6226 force_folding_builtin_constant_p
6227 = saved_force_folding_builtin_constant_p
;
6228 vec_alloc (cexpr_list
, 1);
6229 C_EXPR_APPEND (cexpr_list
, expr
);
6230 while (c_parser_next_token_is (parser
, CPP_COMMA
))
6232 c_parser_consume_token (parser
);
6233 expr
= c_parser_expr_no_commas (parser
, NULL
);
6234 C_EXPR_APPEND (cexpr_list
, expr
);
6237 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
6240 *ret_cexpr_list
= cexpr_list
;
6245 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
6249 postfix-expression [ expression ]
6250 postfix-expression ( argument-expression-list[opt] )
6251 postfix-expression . identifier
6252 postfix-expression -> identifier
6253 postfix-expression ++
6254 postfix-expression --
6255 ( type-name ) { initializer-list }
6256 ( type-name ) { initializer-list , }
6258 argument-expression-list:
6260 argument-expression-list , argument-expression
6272 (treated as a keyword in GNU C)
6275 ( compound-statement )
6276 __builtin_va_arg ( assignment-expression , type-name )
6277 __builtin_offsetof ( type-name , offsetof-member-designator )
6278 __builtin_choose_expr ( assignment-expression ,
6279 assignment-expression ,
6280 assignment-expression )
6281 __builtin_types_compatible_p ( type-name , type-name )
6282 __builtin_complex ( assignment-expression , assignment-expression )
6283 __builtin_shuffle ( assignment-expression , assignment-expression )
6284 __builtin_shuffle ( assignment-expression ,
6285 assignment-expression ,
6286 assignment-expression, )
6288 offsetof-member-designator:
6290 offsetof-member-designator . identifier
6291 offsetof-member-designator [ expression ]
6296 [ objc-receiver objc-message-args ]
6297 @selector ( objc-selector-arg )
6298 @protocol ( identifier )
6299 @encode ( type-name )
6301 Classname . identifier
6304 static struct c_expr
6305 c_parser_postfix_expression (c_parser
*parser
)
6307 struct c_expr expr
, e1
;
6308 struct c_type_name
*t1
, *t2
;
6309 location_t loc
= c_parser_peek_token (parser
)->location
;;
6310 expr
.original_code
= ERROR_MARK
;
6311 expr
.original_type
= NULL
;
6312 switch (c_parser_peek_token (parser
)->type
)
6315 expr
.value
= c_parser_peek_token (parser
)->value
;
6316 loc
= c_parser_peek_token (parser
)->location
;
6317 c_parser_consume_token (parser
);
6318 if (TREE_CODE (expr
.value
) == FIXED_CST
6319 && !targetm
.fixed_point_supported_p ())
6321 error_at (loc
, "fixed-point types not supported for this target");
6322 expr
.value
= error_mark_node
;
6329 expr
.value
= c_parser_peek_token (parser
)->value
;
6330 c_parser_consume_token (parser
);
6336 case CPP_UTF8STRING
:
6337 expr
.value
= c_parser_peek_token (parser
)->value
;
6338 expr
.original_code
= STRING_CST
;
6339 c_parser_consume_token (parser
);
6341 case CPP_OBJC_STRING
:
6342 gcc_assert (c_dialect_objc ());
6344 = objc_build_string_object (c_parser_peek_token (parser
)->value
);
6345 c_parser_consume_token (parser
);
6348 switch (c_parser_peek_token (parser
)->id_kind
)
6352 tree id
= c_parser_peek_token (parser
)->value
;
6353 c_parser_consume_token (parser
);
6354 expr
.value
= build_external_ref (loc
, id
,
6355 (c_parser_peek_token (parser
)->type
6357 &expr
.original_type
);
6360 case C_ID_CLASSNAME
:
6362 /* Here we parse the Objective-C 2.0 Class.name dot
6364 tree class_name
= c_parser_peek_token (parser
)->value
;
6366 c_parser_consume_token (parser
);
6367 gcc_assert (c_dialect_objc ());
6368 if (!c_parser_require (parser
, CPP_DOT
, "expected %<.%>"))
6370 expr
.value
= error_mark_node
;
6373 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6375 c_parser_error (parser
, "expected identifier");
6376 expr
.value
= error_mark_node
;
6379 component
= c_parser_peek_token (parser
)->value
;
6380 c_parser_consume_token (parser
);
6381 expr
.value
= objc_build_class_component_ref (class_name
,
6386 c_parser_error (parser
, "expected expression");
6387 expr
.value
= error_mark_node
;
6391 case CPP_OPEN_PAREN
:
6392 /* A parenthesized expression, statement expression or compound
6394 if (c_parser_peek_2nd_token (parser
)->type
== CPP_OPEN_BRACE
)
6396 /* A statement expression. */
6398 location_t brace_loc
;
6399 c_parser_consume_token (parser
);
6400 brace_loc
= c_parser_peek_token (parser
)->location
;
6401 c_parser_consume_token (parser
);
6402 if (!building_stmt_list_p ())
6404 error_at (loc
, "braced-group within expression allowed "
6405 "only inside a function");
6406 parser
->error
= true;
6407 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
6408 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6409 expr
.value
= error_mark_node
;
6412 stmt
= c_begin_stmt_expr ();
6413 c_parser_compound_statement_nostart (parser
);
6414 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6416 pedwarn (loc
, OPT_Wpedantic
,
6417 "ISO C forbids braced-groups within expressions");
6418 expr
.value
= c_finish_stmt_expr (brace_loc
, stmt
);
6419 mark_exp_read (expr
.value
);
6421 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6423 /* A compound literal. ??? Can we actually get here rather
6424 than going directly to
6425 c_parser_postfix_expression_after_paren_type from
6428 struct c_type_name
*type_name
;
6429 c_parser_consume_token (parser
);
6430 loc
= c_parser_peek_token (parser
)->location
;
6431 type_name
= c_parser_type_name (parser
);
6432 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6434 if (type_name
== NULL
)
6436 expr
.value
= error_mark_node
;
6439 expr
= c_parser_postfix_expression_after_paren_type (parser
,
6445 /* A parenthesized expression. */
6446 c_parser_consume_token (parser
);
6447 expr
= c_parser_expression (parser
);
6448 if (TREE_CODE (expr
.value
) == MODIFY_EXPR
)
6449 TREE_NO_WARNING (expr
.value
) = 1;
6450 if (expr
.original_code
!= C_MAYBE_CONST_EXPR
)
6451 expr
.original_code
= ERROR_MARK
;
6452 /* Don't change EXPR.ORIGINAL_TYPE. */
6453 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6458 switch (c_parser_peek_token (parser
)->keyword
)
6460 case RID_FUNCTION_NAME
:
6461 case RID_PRETTY_FUNCTION_NAME
:
6462 case RID_C99_FUNCTION_NAME
:
6463 expr
.value
= fname_decl (loc
,
6464 c_parser_peek_token (parser
)->keyword
,
6465 c_parser_peek_token (parser
)->value
);
6466 c_parser_consume_token (parser
);
6469 c_parser_consume_token (parser
);
6470 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6472 expr
.value
= error_mark_node
;
6475 e1
= c_parser_expr_no_commas (parser
, NULL
);
6476 mark_exp_read (e1
.value
);
6477 e1
.value
= c_fully_fold (e1
.value
, false, NULL
);
6478 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
6480 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6481 expr
.value
= error_mark_node
;
6484 loc
= c_parser_peek_token (parser
)->location
;
6485 t1
= c_parser_type_name (parser
);
6486 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6490 expr
.value
= error_mark_node
;
6494 tree type_expr
= NULL_TREE
;
6495 expr
.value
= c_build_va_arg (loc
, e1
.value
,
6496 groktypename (t1
, &type_expr
, NULL
));
6499 expr
.value
= build2 (C_MAYBE_CONST_EXPR
,
6500 TREE_TYPE (expr
.value
), type_expr
,
6502 C_MAYBE_CONST_EXPR_NON_CONST (expr
.value
) = true;
6507 c_parser_consume_token (parser
);
6508 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6510 expr
.value
= error_mark_node
;
6513 t1
= c_parser_type_name (parser
);
6515 parser
->error
= true;
6516 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
6517 gcc_assert (parser
->error
);
6520 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6521 expr
.value
= error_mark_node
;
6526 tree type
= groktypename (t1
, NULL
, NULL
);
6528 if (type
== error_mark_node
)
6529 offsetof_ref
= error_mark_node
;
6532 offsetof_ref
= build1 (INDIRECT_REF
, type
, null_pointer_node
);
6533 SET_EXPR_LOCATION (offsetof_ref
, loc
);
6535 /* Parse the second argument to __builtin_offsetof. We
6536 must have one identifier, and beyond that we want to
6537 accept sub structure and sub array references. */
6538 if (c_parser_next_token_is (parser
, CPP_NAME
))
6540 offsetof_ref
= build_component_ref
6541 (loc
, offsetof_ref
, c_parser_peek_token (parser
)->value
);
6542 c_parser_consume_token (parser
);
6543 while (c_parser_next_token_is (parser
, CPP_DOT
)
6544 || c_parser_next_token_is (parser
,
6546 || c_parser_next_token_is (parser
,
6549 if (c_parser_next_token_is (parser
, CPP_DEREF
))
6551 loc
= c_parser_peek_token (parser
)->location
;
6552 offsetof_ref
= build_array_ref (loc
,
6557 else if (c_parser_next_token_is (parser
, CPP_DOT
))
6560 c_parser_consume_token (parser
);
6561 if (c_parser_next_token_is_not (parser
,
6564 c_parser_error (parser
, "expected identifier");
6567 offsetof_ref
= build_component_ref
6569 c_parser_peek_token (parser
)->value
);
6570 c_parser_consume_token (parser
);
6575 loc
= c_parser_peek_token (parser
)->location
;
6576 c_parser_consume_token (parser
);
6577 idx
= c_parser_expression (parser
).value
;
6578 idx
= c_fully_fold (idx
, false, NULL
);
6579 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
6581 offsetof_ref
= build_array_ref (loc
, offsetof_ref
, idx
);
6586 c_parser_error (parser
, "expected identifier");
6587 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6589 expr
.value
= fold_offsetof (offsetof_ref
);
6592 case RID_CHOOSE_EXPR
:
6594 vec
<c_expr_t
, va_gc
> *cexpr_list
;
6595 c_expr_t
*e1_p
, *e2_p
, *e3_p
;
6598 c_parser_consume_token (parser
);
6599 if (!c_parser_get_builtin_args (parser
,
6600 "__builtin_choose_expr",
6603 expr
.value
= error_mark_node
;
6607 if (vec_safe_length (cexpr_list
) != 3)
6609 error_at (loc
, "wrong number of arguments to "
6610 "%<__builtin_choose_expr%>");
6611 expr
.value
= error_mark_node
;
6615 e1_p
= &(*cexpr_list
)[0];
6616 e2_p
= &(*cexpr_list
)[1];
6617 e3_p
= &(*cexpr_list
)[2];
6620 mark_exp_read (e2_p
->value
);
6621 mark_exp_read (e3_p
->value
);
6622 if (TREE_CODE (c
) != INTEGER_CST
6623 || !INTEGRAL_TYPE_P (TREE_TYPE (c
)))
6625 "first argument to %<__builtin_choose_expr%> not"
6627 constant_expression_warning (c
);
6628 expr
= integer_zerop (c
) ? *e3_p
: *e2_p
;
6631 case RID_TYPES_COMPATIBLE_P
:
6632 c_parser_consume_token (parser
);
6633 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6635 expr
.value
= error_mark_node
;
6638 t1
= c_parser_type_name (parser
);
6641 expr
.value
= error_mark_node
;
6644 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
6646 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6647 expr
.value
= error_mark_node
;
6650 t2
= c_parser_type_name (parser
);
6653 expr
.value
= error_mark_node
;
6656 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6660 e1
= groktypename (t1
, NULL
, NULL
);
6661 e2
= groktypename (t2
, NULL
, NULL
);
6662 if (e1
== error_mark_node
|| e2
== error_mark_node
)
6664 expr
.value
= error_mark_node
;
6668 e1
= TYPE_MAIN_VARIANT (e1
);
6669 e2
= TYPE_MAIN_VARIANT (e2
);
6672 = comptypes (e1
, e2
) ? integer_one_node
: integer_zero_node
;
6675 case RID_BUILTIN_COMPLEX
:
6677 vec
<c_expr_t
, va_gc
> *cexpr_list
;
6678 c_expr_t
*e1_p
, *e2_p
;
6680 c_parser_consume_token (parser
);
6681 if (!c_parser_get_builtin_args (parser
,
6682 "__builtin_complex",
6683 &cexpr_list
, false))
6685 expr
.value
= error_mark_node
;
6689 if (vec_safe_length (cexpr_list
) != 2)
6691 error_at (loc
, "wrong number of arguments to "
6692 "%<__builtin_complex%>");
6693 expr
.value
= error_mark_node
;
6697 e1_p
= &(*cexpr_list
)[0];
6698 e2_p
= &(*cexpr_list
)[1];
6700 mark_exp_read (e1_p
->value
);
6701 if (TREE_CODE (e1_p
->value
) == EXCESS_PRECISION_EXPR
)
6702 e1_p
->value
= convert (TREE_TYPE (e1_p
->value
),
6703 TREE_OPERAND (e1_p
->value
, 0));
6704 mark_exp_read (e2_p
->value
);
6705 if (TREE_CODE (e2_p
->value
) == EXCESS_PRECISION_EXPR
)
6706 e2_p
->value
= convert (TREE_TYPE (e2_p
->value
),
6707 TREE_OPERAND (e2_p
->value
, 0));
6708 if (!SCALAR_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
6709 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
6710 || !SCALAR_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
))
6711 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
)))
6713 error_at (loc
, "%<__builtin_complex%> operand "
6714 "not of real binary floating-point type");
6715 expr
.value
= error_mark_node
;
6718 if (TYPE_MAIN_VARIANT (TREE_TYPE (e1_p
->value
))
6719 != TYPE_MAIN_VARIANT (TREE_TYPE (e2_p
->value
)))
6722 "%<__builtin_complex%> operands of different types");
6723 expr
.value
= error_mark_node
;
6727 pedwarn (loc
, OPT_Wpedantic
,
6728 "ISO C90 does not support complex types");
6729 expr
.value
= build2 (COMPLEX_EXPR
,
6732 (TREE_TYPE (e1_p
->value
))),
6733 e1_p
->value
, e2_p
->value
);
6736 case RID_BUILTIN_SHUFFLE
:
6738 vec
<c_expr_t
, va_gc
> *cexpr_list
;
6742 c_parser_consume_token (parser
);
6743 if (!c_parser_get_builtin_args (parser
,
6744 "__builtin_shuffle",
6745 &cexpr_list
, false))
6747 expr
.value
= error_mark_node
;
6751 FOR_EACH_VEC_SAFE_ELT (cexpr_list
, i
, p
)
6752 mark_exp_read (p
->value
);
6754 if (vec_safe_length (cexpr_list
) == 2)
6756 c_build_vec_perm_expr
6757 (loc
, (*cexpr_list
)[0].value
,
6758 NULL_TREE
, (*cexpr_list
)[1].value
);
6760 else if (vec_safe_length (cexpr_list
) == 3)
6762 c_build_vec_perm_expr
6763 (loc
, (*cexpr_list
)[0].value
,
6764 (*cexpr_list
)[1].value
,
6765 (*cexpr_list
)[2].value
);
6768 error_at (loc
, "wrong number of arguments to "
6769 "%<__builtin_shuffle%>");
6770 expr
.value
= error_mark_node
;
6774 case RID_AT_SELECTOR
:
6775 gcc_assert (c_dialect_objc ());
6776 c_parser_consume_token (parser
);
6777 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6779 expr
.value
= error_mark_node
;
6783 tree sel
= c_parser_objc_selector_arg (parser
);
6784 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6786 expr
.value
= objc_build_selector_expr (loc
, sel
);
6789 case RID_AT_PROTOCOL
:
6790 gcc_assert (c_dialect_objc ());
6791 c_parser_consume_token (parser
);
6792 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6794 expr
.value
= error_mark_node
;
6797 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6799 c_parser_error (parser
, "expected identifier");
6800 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6801 expr
.value
= error_mark_node
;
6805 tree id
= c_parser_peek_token (parser
)->value
;
6806 c_parser_consume_token (parser
);
6807 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6809 expr
.value
= objc_build_protocol_expr (id
);
6813 /* Extension to support C-structures in the archiver. */
6814 gcc_assert (c_dialect_objc ());
6815 c_parser_consume_token (parser
);
6816 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6818 expr
.value
= error_mark_node
;
6821 t1
= c_parser_type_name (parser
);
6824 expr
.value
= error_mark_node
;
6825 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6828 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6831 tree type
= groktypename (t1
, NULL
, NULL
);
6832 expr
.value
= objc_build_encode_expr (type
);
6836 c_parser_error (parser
, "expected expression");
6837 expr
.value
= error_mark_node
;
6841 case CPP_OPEN_SQUARE
:
6842 if (c_dialect_objc ())
6844 tree receiver
, args
;
6845 c_parser_consume_token (parser
);
6846 receiver
= c_parser_objc_receiver (parser
);
6847 args
= c_parser_objc_message_args (parser
);
6848 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
6850 expr
.value
= objc_build_message_expr (receiver
, args
);
6853 /* Else fall through to report error. */
6855 c_parser_error (parser
, "expected expression");
6856 expr
.value
= error_mark_node
;
6859 return c_parser_postfix_expression_after_primary (parser
, loc
, expr
);
6862 /* Parse a postfix expression after a parenthesized type name: the
6863 brace-enclosed initializer of a compound literal, possibly followed
6864 by some postfix operators. This is separate because it is not
6865 possible to tell until after the type name whether a cast
6866 expression has a cast or a compound literal, or whether the operand
6867 of sizeof is a parenthesized type name or starts with a compound
6868 literal. TYPE_LOC is the location where TYPE_NAME starts--the
6869 location of the first token after the parentheses around the type
6872 static struct c_expr
6873 c_parser_postfix_expression_after_paren_type (c_parser
*parser
,
6874 struct c_type_name
*type_name
,
6875 location_t type_loc
)
6881 location_t start_loc
;
6882 tree type_expr
= NULL_TREE
;
6883 bool type_expr_const
= true;
6884 check_compound_literal_type (type_loc
, type_name
);
6885 start_init (NULL_TREE
, NULL
, 0);
6886 type
= groktypename (type_name
, &type_expr
, &type_expr_const
);
6887 start_loc
= c_parser_peek_token (parser
)->location
;
6888 if (type
!= error_mark_node
&& C_TYPE_VARIABLE_SIZE (type
))
6890 error_at (type_loc
, "compound literal has variable size");
6891 type
= error_mark_node
;
6893 init
= c_parser_braced_init (parser
, type
, false);
6895 maybe_warn_string_init (type
, init
);
6897 if (type
!= error_mark_node
6898 && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type
))
6899 && current_function_decl
)
6901 error ("compound literal qualified by address-space qualifier");
6902 type
= error_mark_node
;
6906 pedwarn (start_loc
, OPT_Wpedantic
, "ISO C90 forbids compound literals");
6907 non_const
= ((init
.value
&& TREE_CODE (init
.value
) == CONSTRUCTOR
)
6908 ? CONSTRUCTOR_NON_CONST (init
.value
)
6909 : init
.original_code
== C_MAYBE_CONST_EXPR
);
6910 non_const
|= !type_expr_const
;
6911 expr
.value
= build_compound_literal (start_loc
, type
, init
.value
, non_const
);
6912 expr
.original_code
= ERROR_MARK
;
6913 expr
.original_type
= NULL
;
6916 if (TREE_CODE (expr
.value
) == C_MAYBE_CONST_EXPR
)
6918 gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr
.value
) == NULL_TREE
);
6919 C_MAYBE_CONST_EXPR_PRE (expr
.value
) = type_expr
;
6923 gcc_assert (!non_const
);
6924 expr
.value
= build2 (C_MAYBE_CONST_EXPR
, type
,
6925 type_expr
, expr
.value
);
6928 return c_parser_postfix_expression_after_primary (parser
, start_loc
, expr
);
6931 /* Callback function for sizeof_pointer_memaccess_warning to compare
6935 sizeof_ptr_memacc_comptypes (tree type1
, tree type2
)
6937 return comptypes (type1
, type2
) == 1;
6940 /* Parse a postfix expression after the initial primary or compound
6941 literal; that is, parse a series of postfix operators.
6943 EXPR_LOC is the location of the primary expression. */
6945 static struct c_expr
6946 c_parser_postfix_expression_after_primary (c_parser
*parser
,
6947 location_t expr_loc
,
6950 struct c_expr orig_expr
;
6952 location_t sizeof_arg_loc
[3];
6955 vec
<tree
, va_gc
> *exprlist
;
6956 vec
<tree
, va_gc
> *origtypes
= NULL
;
6959 location_t op_loc
= c_parser_peek_token (parser
)->location
;
6960 switch (c_parser_peek_token (parser
)->type
)
6962 case CPP_OPEN_SQUARE
:
6963 /* Array reference. */
6964 c_parser_consume_token (parser
);
6965 if (flag_enable_cilkplus
6966 && c_parser_peek_token (parser
)->type
== CPP_COLON
)
6967 /* If we are here, then we have something like this:
6970 expr
.value
= c_parser_array_notation (expr_loc
, parser
, NULL_TREE
,
6974 idx
= c_parser_expression (parser
).value
;
6975 /* Here we have 3 options:
6976 1. Array [EXPR] -- Normal Array call.
6977 2. Array [EXPR : EXPR] -- Array notation without stride.
6978 3. Array [EXPR : EXPR : EXPR] -- Array notation with stride.
6980 For 1, we just handle it just like a normal array expression.
6981 For 2 and 3 we handle it like we handle array notations. The
6982 idx value we have above becomes the initial/start index.
6984 if (flag_enable_cilkplus
6985 && c_parser_peek_token (parser
)->type
== CPP_COLON
)
6986 expr
.value
= c_parser_array_notation (expr_loc
, parser
, idx
,
6990 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
6992 expr
.value
= build_array_ref (op_loc
, expr
.value
, idx
);
6995 expr
.original_code
= ERROR_MARK
;
6996 expr
.original_type
= NULL
;
6998 case CPP_OPEN_PAREN
:
6999 /* Function call. */
7000 c_parser_consume_token (parser
);
7001 for (i
= 0; i
< 3; i
++)
7003 sizeof_arg
[i
] = NULL_TREE
;
7004 sizeof_arg_loc
[i
] = UNKNOWN_LOCATION
;
7006 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
7009 exprlist
= c_parser_expr_list (parser
, true, false, &origtypes
,
7010 sizeof_arg_loc
, sizeof_arg
);
7011 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7014 mark_exp_read (expr
.value
);
7015 if (warn_sizeof_pointer_memaccess
)
7016 sizeof_pointer_memaccess_warning (sizeof_arg_loc
,
7017 expr
.value
, exprlist
,
7019 sizeof_ptr_memacc_comptypes
);
7020 /* FIXME diagnostics: Ideally we want the FUNCNAME, not the
7021 "(" after the FUNCNAME, which is what we have now. */
7022 expr
.value
= build_function_call_vec (op_loc
, expr
.value
, exprlist
,
7024 expr
.original_code
= ERROR_MARK
;
7025 if (TREE_CODE (expr
.value
) == INTEGER_CST
7026 && TREE_CODE (orig_expr
.value
) == FUNCTION_DECL
7027 && DECL_BUILT_IN_CLASS (orig_expr
.value
) == BUILT_IN_NORMAL
7028 && DECL_FUNCTION_CODE (orig_expr
.value
) == BUILT_IN_CONSTANT_P
)
7029 expr
.original_code
= C_MAYBE_CONST_EXPR
;
7030 expr
.original_type
= NULL
;
7033 release_tree_vector (exprlist
);
7034 release_tree_vector (origtypes
);
7038 /* Structure element reference. */
7039 c_parser_consume_token (parser
);
7040 expr
= default_function_array_conversion (expr_loc
, expr
);
7041 if (c_parser_next_token_is (parser
, CPP_NAME
))
7042 ident
= c_parser_peek_token (parser
)->value
;
7045 c_parser_error (parser
, "expected identifier");
7046 expr
.value
= error_mark_node
;
7047 expr
.original_code
= ERROR_MARK
;
7048 expr
.original_type
= NULL
;
7051 c_parser_consume_token (parser
);
7052 expr
.value
= build_component_ref (op_loc
, expr
.value
, ident
);
7053 expr
.original_code
= ERROR_MARK
;
7054 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
7055 expr
.original_type
= NULL
;
7058 /* Remember the original type of a bitfield. */
7059 tree field
= TREE_OPERAND (expr
.value
, 1);
7060 if (TREE_CODE (field
) != FIELD_DECL
)
7061 expr
.original_type
= NULL
;
7063 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
7067 /* Structure element reference. */
7068 c_parser_consume_token (parser
);
7069 expr
= default_function_array_conversion (expr_loc
, expr
);
7070 if (c_parser_next_token_is (parser
, CPP_NAME
))
7071 ident
= c_parser_peek_token (parser
)->value
;
7074 c_parser_error (parser
, "expected identifier");
7075 expr
.value
= error_mark_node
;
7076 expr
.original_code
= ERROR_MARK
;
7077 expr
.original_type
= NULL
;
7080 c_parser_consume_token (parser
);
7081 expr
.value
= build_component_ref (op_loc
,
7082 build_indirect_ref (op_loc
,
7086 expr
.original_code
= ERROR_MARK
;
7087 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
7088 expr
.original_type
= NULL
;
7091 /* Remember the original type of a bitfield. */
7092 tree field
= TREE_OPERAND (expr
.value
, 1);
7093 if (TREE_CODE (field
) != FIELD_DECL
)
7094 expr
.original_type
= NULL
;
7096 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
7100 /* Postincrement. */
7101 c_parser_consume_token (parser
);
7102 /* If the expressions have array notations, we expand them. */
7103 if (flag_enable_cilkplus
7104 && TREE_CODE (expr
.value
) == ARRAY_NOTATION_REF
)
7105 expr
= fix_array_notation_expr (expr_loc
, POSTINCREMENT_EXPR
, expr
);
7108 expr
= default_function_array_read_conversion (expr_loc
, expr
);
7109 expr
.value
= build_unary_op (op_loc
,
7110 POSTINCREMENT_EXPR
, expr
.value
, 0);
7112 expr
.original_code
= ERROR_MARK
;
7113 expr
.original_type
= NULL
;
7115 case CPP_MINUS_MINUS
:
7116 /* Postdecrement. */
7117 c_parser_consume_token (parser
);
7118 /* If the expressions have array notations, we expand them. */
7119 if (flag_enable_cilkplus
7120 && TREE_CODE (expr
.value
) == ARRAY_NOTATION_REF
)
7121 expr
= fix_array_notation_expr (expr_loc
, POSTDECREMENT_EXPR
, expr
);
7124 expr
= default_function_array_read_conversion (expr_loc
, expr
);
7125 expr
.value
= build_unary_op (op_loc
,
7126 POSTDECREMENT_EXPR
, expr
.value
, 0);
7128 expr
.original_code
= ERROR_MARK
;
7129 expr
.original_type
= NULL
;
7137 /* Parse an expression (C90 6.3.17, C99 6.5.17).
7140 assignment-expression
7141 expression , assignment-expression
7144 static struct c_expr
7145 c_parser_expression (c_parser
*parser
)
7148 expr
= c_parser_expr_no_commas (parser
, NULL
);
7149 while (c_parser_next_token_is (parser
, CPP_COMMA
))
7153 location_t loc
= c_parser_peek_token (parser
)->location
;
7154 location_t expr_loc
;
7155 c_parser_consume_token (parser
);
7156 expr_loc
= c_parser_peek_token (parser
)->location
;
7157 lhsval
= expr
.value
;
7158 while (TREE_CODE (lhsval
) == COMPOUND_EXPR
)
7159 lhsval
= TREE_OPERAND (lhsval
, 1);
7160 if (DECL_P (lhsval
) || handled_component_p (lhsval
))
7161 mark_exp_read (lhsval
);
7162 next
= c_parser_expr_no_commas (parser
, NULL
);
7163 next
= default_function_array_conversion (expr_loc
, next
);
7164 expr
.value
= build_compound_expr (loc
, expr
.value
, next
.value
);
7165 expr
.original_code
= COMPOUND_EXPR
;
7166 expr
.original_type
= next
.original_type
;
7171 /* Parse an expression and convert functions or arrays to
7174 static struct c_expr
7175 c_parser_expression_conv (c_parser
*parser
)
7178 location_t loc
= c_parser_peek_token (parser
)->location
;
7179 expr
= c_parser_expression (parser
);
7180 expr
= default_function_array_conversion (loc
, expr
);
7184 /* Parse a non-empty list of expressions. If CONVERT_P, convert
7185 functions and arrays to pointers. If FOLD_P, fold the expressions.
7188 assignment-expression
7189 nonempty-expr-list , assignment-expression
7192 static vec
<tree
, va_gc
> *
7193 c_parser_expr_list (c_parser
*parser
, bool convert_p
, bool fold_p
,
7194 vec
<tree
, va_gc
> **p_orig_types
,
7195 location_t
*sizeof_arg_loc
, tree
*sizeof_arg
)
7197 vec
<tree
, va_gc
> *ret
;
7198 vec
<tree
, va_gc
> *orig_types
;
7200 location_t loc
= c_parser_peek_token (parser
)->location
;
7201 location_t cur_sizeof_arg_loc
= UNKNOWN_LOCATION
;
7202 unsigned int idx
= 0;
7204 ret
= make_tree_vector ();
7205 if (p_orig_types
== NULL
)
7208 orig_types
= make_tree_vector ();
7210 if (sizeof_arg
!= NULL
7211 && c_parser_next_token_is_keyword (parser
, RID_SIZEOF
))
7212 cur_sizeof_arg_loc
= c_parser_peek_2nd_token (parser
)->location
;
7213 expr
= c_parser_expr_no_commas (parser
, NULL
);
7215 expr
= default_function_array_read_conversion (loc
, expr
);
7217 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
7218 ret
->quick_push (expr
.value
);
7220 orig_types
->quick_push (expr
.original_type
);
7221 if (sizeof_arg
!= NULL
7222 && cur_sizeof_arg_loc
!= UNKNOWN_LOCATION
7223 && expr
.original_code
== SIZEOF_EXPR
)
7225 sizeof_arg
[0] = c_last_sizeof_arg
;
7226 sizeof_arg_loc
[0] = cur_sizeof_arg_loc
;
7228 while (c_parser_next_token_is (parser
, CPP_COMMA
))
7230 c_parser_consume_token (parser
);
7231 loc
= c_parser_peek_token (parser
)->location
;
7232 if (sizeof_arg
!= NULL
7233 && c_parser_next_token_is_keyword (parser
, RID_SIZEOF
))
7234 cur_sizeof_arg_loc
= c_parser_peek_2nd_token (parser
)->location
;
7236 cur_sizeof_arg_loc
= UNKNOWN_LOCATION
;
7237 expr
= c_parser_expr_no_commas (parser
, NULL
);
7239 expr
= default_function_array_read_conversion (loc
, expr
);
7241 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
7242 vec_safe_push (ret
, expr
.value
);
7244 vec_safe_push (orig_types
, expr
.original_type
);
7246 && sizeof_arg
!= NULL
7247 && cur_sizeof_arg_loc
!= UNKNOWN_LOCATION
7248 && expr
.original_code
== SIZEOF_EXPR
)
7250 sizeof_arg
[idx
] = c_last_sizeof_arg
;
7251 sizeof_arg_loc
[idx
] = cur_sizeof_arg_loc
;
7255 *p_orig_types
= orig_types
;
7259 /* Parse Objective-C-specific constructs. */
7261 /* Parse an objc-class-definition.
7263 objc-class-definition:
7264 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
7265 objc-class-instance-variables[opt] objc-methodprotolist @end
7266 @implementation identifier objc-superclass[opt]
7267 objc-class-instance-variables[opt]
7268 @interface identifier ( identifier ) objc-protocol-refs[opt]
7269 objc-methodprotolist @end
7270 @interface identifier ( ) objc-protocol-refs[opt]
7271 objc-methodprotolist @end
7272 @implementation identifier ( identifier )
7277 "@interface identifier (" must start "@interface identifier (
7278 identifier ) ...": objc-methodprotolist in the first production may
7279 not start with a parenthesized identifier as a declarator of a data
7280 definition with no declaration specifiers if the objc-superclass,
7281 objc-protocol-refs and objc-class-instance-variables are omitted. */
7284 c_parser_objc_class_definition (c_parser
*parser
, tree attributes
)
7289 if (c_parser_next_token_is_keyword (parser
, RID_AT_INTERFACE
))
7291 else if (c_parser_next_token_is_keyword (parser
, RID_AT_IMPLEMENTATION
))
7296 c_parser_consume_token (parser
);
7297 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7299 c_parser_error (parser
, "expected identifier");
7302 id1
= c_parser_peek_token (parser
)->value
;
7303 c_parser_consume_token (parser
);
7304 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
7306 /* We have a category or class extension. */
7308 tree proto
= NULL_TREE
;
7309 c_parser_consume_token (parser
);
7310 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7312 if (iface_p
&& c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
7314 /* We have a class extension. */
7319 c_parser_error (parser
, "expected identifier or %<)%>");
7320 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7326 id2
= c_parser_peek_token (parser
)->value
;
7327 c_parser_consume_token (parser
);
7329 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7332 objc_start_category_implementation (id1
, id2
);
7335 if (c_parser_next_token_is (parser
, CPP_LESS
))
7336 proto
= c_parser_objc_protocol_refs (parser
);
7337 objc_start_category_interface (id1
, id2
, proto
, attributes
);
7338 c_parser_objc_methodprotolist (parser
);
7339 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
7340 objc_finish_interface ();
7343 if (c_parser_next_token_is (parser
, CPP_COLON
))
7345 c_parser_consume_token (parser
);
7346 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7348 c_parser_error (parser
, "expected identifier");
7351 superclass
= c_parser_peek_token (parser
)->value
;
7352 c_parser_consume_token (parser
);
7355 superclass
= NULL_TREE
;
7358 tree proto
= NULL_TREE
;
7359 if (c_parser_next_token_is (parser
, CPP_LESS
))
7360 proto
= c_parser_objc_protocol_refs (parser
);
7361 objc_start_class_interface (id1
, superclass
, proto
, attributes
);
7364 objc_start_class_implementation (id1
, superclass
);
7365 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
7366 c_parser_objc_class_instance_variables (parser
);
7369 objc_continue_interface ();
7370 c_parser_objc_methodprotolist (parser
);
7371 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
7372 objc_finish_interface ();
7376 objc_continue_implementation ();
7381 /* Parse objc-class-instance-variables.
7383 objc-class-instance-variables:
7384 { objc-instance-variable-decl-list[opt] }
7386 objc-instance-variable-decl-list:
7387 objc-visibility-spec
7388 objc-instance-variable-decl ;
7390 objc-instance-variable-decl-list objc-visibility-spec
7391 objc-instance-variable-decl-list objc-instance-variable-decl ;
7392 objc-instance-variable-decl-list ;
7394 objc-visibility-spec:
7399 objc-instance-variable-decl:
7404 c_parser_objc_class_instance_variables (c_parser
*parser
)
7406 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
7407 c_parser_consume_token (parser
);
7408 while (c_parser_next_token_is_not (parser
, CPP_EOF
))
7411 /* Parse any stray semicolon. */
7412 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
7414 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
7416 c_parser_consume_token (parser
);
7419 /* Stop if at the end of the instance variables. */
7420 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
7422 c_parser_consume_token (parser
);
7425 /* Parse any objc-visibility-spec. */
7426 if (c_parser_next_token_is_keyword (parser
, RID_AT_PRIVATE
))
7428 c_parser_consume_token (parser
);
7429 objc_set_visibility (OBJC_IVAR_VIS_PRIVATE
);
7432 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROTECTED
))
7434 c_parser_consume_token (parser
);
7435 objc_set_visibility (OBJC_IVAR_VIS_PROTECTED
);
7438 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PUBLIC
))
7440 c_parser_consume_token (parser
);
7441 objc_set_visibility (OBJC_IVAR_VIS_PUBLIC
);
7444 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PACKAGE
))
7446 c_parser_consume_token (parser
);
7447 objc_set_visibility (OBJC_IVAR_VIS_PACKAGE
);
7450 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
7452 c_parser_pragma (parser
, pragma_external
);
7456 /* Parse some comma-separated declarations. */
7457 decls
= c_parser_struct_declaration (parser
);
7460 /* There is a syntax error. We want to skip the offending
7461 tokens up to the next ';' (included) or '}'
7464 /* First, skip manually a ')' or ']'. This is because they
7465 reduce the nesting level, so c_parser_skip_until_found()
7466 wouldn't be able to skip past them. */
7467 c_token
*token
= c_parser_peek_token (parser
);
7468 if (token
->type
== CPP_CLOSE_PAREN
|| token
->type
== CPP_CLOSE_SQUARE
)
7469 c_parser_consume_token (parser
);
7471 /* Then, do the standard skipping. */
7472 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
7474 /* We hopefully recovered. Start normal parsing again. */
7475 parser
->error
= false;
7480 /* Comma-separated instance variables are chained together
7481 in reverse order; add them one by one. */
7482 tree ivar
= nreverse (decls
);
7483 for (; ivar
; ivar
= DECL_CHAIN (ivar
))
7484 objc_add_instance_variable (copy_node (ivar
));
7486 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7490 /* Parse an objc-class-declaration.
7492 objc-class-declaration:
7493 @class identifier-list ;
7497 c_parser_objc_class_declaration (c_parser
*parser
)
7499 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_CLASS
));
7500 c_parser_consume_token (parser
);
7501 /* Any identifiers, including those declared as type names, are OK
7506 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7508 c_parser_error (parser
, "expected identifier");
7509 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
7510 parser
->error
= false;
7513 id
= c_parser_peek_token (parser
)->value
;
7514 objc_declare_class (id
);
7515 c_parser_consume_token (parser
);
7516 if (c_parser_next_token_is (parser
, CPP_COMMA
))
7517 c_parser_consume_token (parser
);
7521 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7524 /* Parse an objc-alias-declaration.
7526 objc-alias-declaration:
7527 @compatibility_alias identifier identifier ;
7531 c_parser_objc_alias_declaration (c_parser
*parser
)
7534 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_ALIAS
));
7535 c_parser_consume_token (parser
);
7536 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7538 c_parser_error (parser
, "expected identifier");
7539 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
7542 id1
= c_parser_peek_token (parser
)->value
;
7543 c_parser_consume_token (parser
);
7544 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7546 c_parser_error (parser
, "expected identifier");
7547 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
7550 id2
= c_parser_peek_token (parser
)->value
;
7551 c_parser_consume_token (parser
);
7552 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7553 objc_declare_alias (id1
, id2
);
7556 /* Parse an objc-protocol-definition.
7558 objc-protocol-definition:
7559 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
7560 @protocol identifier-list ;
7562 "@protocol identifier ;" should be resolved as "@protocol
7563 identifier-list ;": objc-methodprotolist may not start with a
7564 semicolon in the first alternative if objc-protocol-refs are
7568 c_parser_objc_protocol_definition (c_parser
*parser
, tree attributes
)
7570 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROTOCOL
));
7572 c_parser_consume_token (parser
);
7573 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7575 c_parser_error (parser
, "expected identifier");
7578 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
7579 || c_parser_peek_2nd_token (parser
)->type
== CPP_SEMICOLON
)
7581 /* Any identifiers, including those declared as type names, are
7586 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7588 c_parser_error (parser
, "expected identifier");
7591 id
= c_parser_peek_token (parser
)->value
;
7592 objc_declare_protocol (id
, attributes
);
7593 c_parser_consume_token (parser
);
7594 if (c_parser_next_token_is (parser
, CPP_COMMA
))
7595 c_parser_consume_token (parser
);
7599 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7603 tree id
= c_parser_peek_token (parser
)->value
;
7604 tree proto
= NULL_TREE
;
7605 c_parser_consume_token (parser
);
7606 if (c_parser_next_token_is (parser
, CPP_LESS
))
7607 proto
= c_parser_objc_protocol_refs (parser
);
7608 parser
->objc_pq_context
= true;
7609 objc_start_protocol (id
, proto
, attributes
);
7610 c_parser_objc_methodprotolist (parser
);
7611 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
7612 parser
->objc_pq_context
= false;
7613 objc_finish_interface ();
7617 /* Parse an objc-method-type.
7623 Return true if it is a class method (+) and false if it is
7624 an instance method (-).
7627 c_parser_objc_method_type (c_parser
*parser
)
7629 switch (c_parser_peek_token (parser
)->type
)
7632 c_parser_consume_token (parser
);
7635 c_parser_consume_token (parser
);
7642 /* Parse an objc-method-definition.
7644 objc-method-definition:
7645 objc-method-type objc-method-decl ;[opt] compound-statement
7649 c_parser_objc_method_definition (c_parser
*parser
)
7651 bool is_class_method
= c_parser_objc_method_type (parser
);
7652 tree decl
, attributes
= NULL_TREE
, expr
= NULL_TREE
;
7653 parser
->objc_pq_context
= true;
7654 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
7656 if (decl
== error_mark_node
)
7657 return; /* Bail here. */
7659 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
7661 c_parser_consume_token (parser
);
7662 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
7663 "extra semicolon in method definition specified");
7666 if (!c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
7668 c_parser_error (parser
, "expected %<{%>");
7672 parser
->objc_pq_context
= false;
7673 if (objc_start_method_definition (is_class_method
, decl
, attributes
, expr
))
7675 add_stmt (c_parser_compound_statement (parser
));
7676 objc_finish_method_definition (current_function_decl
);
7680 /* This code is executed when we find a method definition
7681 outside of an @implementation context (or invalid for other
7682 reasons). Parse the method (to keep going) but do not emit
7685 c_parser_compound_statement (parser
);
7689 /* Parse an objc-methodprotolist.
7691 objc-methodprotolist:
7693 objc-methodprotolist objc-methodproto
7694 objc-methodprotolist declaration
7695 objc-methodprotolist ;
7699 The declaration is a data definition, which may be missing
7700 declaration specifiers under the same rules and diagnostics as
7701 other data definitions outside functions, and the stray semicolon
7702 is diagnosed the same way as a stray semicolon outside a
7706 c_parser_objc_methodprotolist (c_parser
*parser
)
7710 /* The list is terminated by @end. */
7711 switch (c_parser_peek_token (parser
)->type
)
7714 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
7715 "ISO C does not allow extra %<;%> outside of a function");
7716 c_parser_consume_token (parser
);
7720 c_parser_objc_methodproto (parser
);
7723 c_parser_pragma (parser
, pragma_external
);
7728 if (c_parser_next_token_is_keyword (parser
, RID_AT_END
))
7730 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
))
7731 c_parser_objc_at_property_declaration (parser
);
7732 else if (c_parser_next_token_is_keyword (parser
, RID_AT_OPTIONAL
))
7734 objc_set_method_opt (true);
7735 c_parser_consume_token (parser
);
7737 else if (c_parser_next_token_is_keyword (parser
, RID_AT_REQUIRED
))
7739 objc_set_method_opt (false);
7740 c_parser_consume_token (parser
);
7743 c_parser_declaration_or_fndef (parser
, false, false, true,
7750 /* Parse an objc-methodproto.
7753 objc-method-type objc-method-decl ;
7757 c_parser_objc_methodproto (c_parser
*parser
)
7759 bool is_class_method
= c_parser_objc_method_type (parser
);
7760 tree decl
, attributes
= NULL_TREE
;
7762 /* Remember protocol qualifiers in prototypes. */
7763 parser
->objc_pq_context
= true;
7764 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
7766 /* Forget protocol qualifiers now. */
7767 parser
->objc_pq_context
= false;
7769 /* Do not allow the presence of attributes to hide an erroneous
7770 method implementation in the interface section. */
7771 if (!c_parser_next_token_is (parser
, CPP_SEMICOLON
))
7773 c_parser_error (parser
, "expected %<;%>");
7777 if (decl
!= error_mark_node
)
7778 objc_add_method_declaration (is_class_method
, decl
, attributes
);
7780 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7783 /* If we are at a position that method attributes may be present, check that
7784 there are not any parsed already (a syntax error) and then collect any
7785 specified at the current location. Finally, if new attributes were present,
7786 check that the next token is legal ( ';' for decls and '{' for defs). */
7789 c_parser_objc_maybe_method_attributes (c_parser
* parser
, tree
* attributes
)
7794 c_parser_error (parser
,
7795 "method attributes must be specified at the end only");
7796 *attributes
= NULL_TREE
;
7800 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
7801 *attributes
= c_parser_attributes (parser
);
7803 /* If there were no attributes here, just report any earlier error. */
7804 if (*attributes
== NULL_TREE
|| bad
)
7807 /* If the attributes are followed by a ; or {, then just report any earlier
7809 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
7810 || c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
7813 /* We've got attributes, but not at the end. */
7814 c_parser_error (parser
,
7815 "expected %<;%> or %<{%> after method attribute definition");
7819 /* Parse an objc-method-decl.
7822 ( objc-type-name ) objc-selector
7824 ( objc-type-name ) objc-keyword-selector objc-optparmlist
7825 objc-keyword-selector objc-optparmlist
7828 objc-keyword-selector:
7830 objc-keyword-selector objc-keyword-decl
7833 objc-selector : ( objc-type-name ) identifier
7834 objc-selector : identifier
7835 : ( objc-type-name ) identifier
7839 objc-optparms objc-optellipsis
7843 objc-opt-parms , parameter-declaration
7851 c_parser_objc_method_decl (c_parser
*parser
, bool is_class_method
,
7852 tree
*attributes
, tree
*expr
)
7854 tree type
= NULL_TREE
;
7856 tree parms
= NULL_TREE
;
7857 bool ellipsis
= false;
7858 bool attr_err
= false;
7860 *attributes
= NULL_TREE
;
7861 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
7863 c_parser_consume_token (parser
);
7864 type
= c_parser_objc_type_name (parser
);
7865 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7867 sel
= c_parser_objc_selector (parser
);
7868 /* If there is no selector, or a colon follows, we have an
7869 objc-keyword-selector. If there is a selector, and a colon does
7870 not follow, that selector ends the objc-method-decl. */
7871 if (!sel
|| c_parser_next_token_is (parser
, CPP_COLON
))
7874 tree list
= NULL_TREE
;
7877 tree atype
= NULL_TREE
, id
, keyworddecl
;
7878 tree param_attr
= NULL_TREE
;
7879 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
7881 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
7883 c_parser_consume_token (parser
);
7884 atype
= c_parser_objc_type_name (parser
);
7885 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7888 /* New ObjC allows attributes on method parameters. */
7889 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
7890 param_attr
= c_parser_attributes (parser
);
7891 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7893 c_parser_error (parser
, "expected identifier");
7894 return error_mark_node
;
7896 id
= c_parser_peek_token (parser
)->value
;
7897 c_parser_consume_token (parser
);
7898 keyworddecl
= objc_build_keyword_decl (tsel
, atype
, id
, param_attr
);
7899 list
= chainon (list
, keyworddecl
);
7900 tsel
= c_parser_objc_selector (parser
);
7901 if (!tsel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
7905 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
7907 /* Parse the optional parameter list. Optional Objective-C
7908 method parameters follow the C syntax, and may include '...'
7909 to denote a variable number of arguments. */
7910 parms
= make_node (TREE_LIST
);
7911 while (c_parser_next_token_is (parser
, CPP_COMMA
))
7913 struct c_parm
*parm
;
7914 c_parser_consume_token (parser
);
7915 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
7918 c_parser_consume_token (parser
);
7919 attr_err
|= c_parser_objc_maybe_method_attributes
7920 (parser
, attributes
) ;
7923 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
7926 parms
= chainon (parms
,
7927 build_tree_list (NULL_TREE
, grokparm (parm
, expr
)));
7932 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
7936 c_parser_error (parser
, "objective-c method declaration is expected");
7937 return error_mark_node
;
7941 return error_mark_node
;
7943 return objc_build_method_signature (is_class_method
, type
, sel
, parms
, ellipsis
);
7946 /* Parse an objc-type-name.
7949 objc-type-qualifiers[opt] type-name
7950 objc-type-qualifiers[opt]
7952 objc-type-qualifiers:
7954 objc-type-qualifiers objc-type-qualifier
7956 objc-type-qualifier: one of
7957 in out inout bycopy byref oneway
7961 c_parser_objc_type_name (c_parser
*parser
)
7963 tree quals
= NULL_TREE
;
7964 struct c_type_name
*type_name
= NULL
;
7965 tree type
= NULL_TREE
;
7968 c_token
*token
= c_parser_peek_token (parser
);
7969 if (token
->type
== CPP_KEYWORD
7970 && (token
->keyword
== RID_IN
7971 || token
->keyword
== RID_OUT
7972 || token
->keyword
== RID_INOUT
7973 || token
->keyword
== RID_BYCOPY
7974 || token
->keyword
== RID_BYREF
7975 || token
->keyword
== RID_ONEWAY
))
7977 quals
= chainon (build_tree_list (NULL_TREE
, token
->value
), quals
);
7978 c_parser_consume_token (parser
);
7983 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
7984 type_name
= c_parser_type_name (parser
);
7986 type
= groktypename (type_name
, NULL
, NULL
);
7988 /* If the type is unknown, and error has already been produced and
7989 we need to recover from the error. In that case, use NULL_TREE
7990 for the type, as if no type had been specified; this will use the
7991 default type ('id') which is good for error recovery. */
7992 if (type
== error_mark_node
)
7995 return build_tree_list (quals
, type
);
7998 /* Parse objc-protocol-refs.
8005 c_parser_objc_protocol_refs (c_parser
*parser
)
8007 tree list
= NULL_TREE
;
8008 gcc_assert (c_parser_next_token_is (parser
, CPP_LESS
));
8009 c_parser_consume_token (parser
);
8010 /* Any identifiers, including those declared as type names, are OK
8015 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8017 c_parser_error (parser
, "expected identifier");
8020 id
= c_parser_peek_token (parser
)->value
;
8021 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
8022 c_parser_consume_token (parser
);
8023 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8024 c_parser_consume_token (parser
);
8028 c_parser_require (parser
, CPP_GREATER
, "expected %<>%>");
8032 /* Parse an objc-try-catch-finally-statement.
8034 objc-try-catch-finally-statement:
8035 @try compound-statement objc-catch-list[opt]
8036 @try compound-statement objc-catch-list[opt] @finally compound-statement
8039 @catch ( objc-catch-parameter-declaration ) compound-statement
8040 objc-catch-list @catch ( objc-catch-parameter-declaration ) compound-statement
8042 objc-catch-parameter-declaration:
8043 parameter-declaration
8046 where '...' is to be interpreted literally, that is, it means CPP_ELLIPSIS.
8048 PS: This function is identical to cp_parser_objc_try_catch_finally_statement
8049 for C++. Keep them in sync. */
8052 c_parser_objc_try_catch_finally_statement (c_parser
*parser
)
8054 location_t location
;
8057 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_TRY
));
8058 c_parser_consume_token (parser
);
8059 location
= c_parser_peek_token (parser
)->location
;
8060 objc_maybe_warn_exceptions (location
);
8061 stmt
= c_parser_compound_statement (parser
);
8062 objc_begin_try_stmt (location
, stmt
);
8064 while (c_parser_next_token_is_keyword (parser
, RID_AT_CATCH
))
8066 struct c_parm
*parm
;
8067 tree parameter_declaration
= error_mark_node
;
8068 bool seen_open_paren
= false;
8070 c_parser_consume_token (parser
);
8071 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8072 seen_open_paren
= true;
8073 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
8075 /* We have "@catch (...)" (where the '...' are literally
8076 what is in the code). Skip the '...'.
8077 parameter_declaration is set to NULL_TREE, and
8078 objc_being_catch_clauses() knows that that means
8080 c_parser_consume_token (parser
);
8081 parameter_declaration
= NULL_TREE
;
8085 /* We have "@catch (NSException *exception)" or something
8086 like that. Parse the parameter declaration. */
8087 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
8089 parameter_declaration
= error_mark_node
;
8091 parameter_declaration
= grokparm (parm
, NULL
);
8093 if (seen_open_paren
)
8094 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8097 /* If there was no open parenthesis, we are recovering from
8098 an error, and we are trying to figure out what mistake
8099 the user has made. */
8101 /* If there is an immediate closing parenthesis, the user
8102 probably forgot the opening one (ie, they typed "@catch
8103 NSException *e)". Parse the closing parenthesis and keep
8105 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
8106 c_parser_consume_token (parser
);
8108 /* If these is no immediate closing parenthesis, the user
8109 probably doesn't know that parenthesis are required at
8110 all (ie, they typed "@catch NSException *e"). So, just
8111 forget about the closing parenthesis and keep going. */
8113 objc_begin_catch_clause (parameter_declaration
);
8114 if (c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
8115 c_parser_compound_statement_nostart (parser
);
8116 objc_finish_catch_clause ();
8118 if (c_parser_next_token_is_keyword (parser
, RID_AT_FINALLY
))
8120 c_parser_consume_token (parser
);
8121 location
= c_parser_peek_token (parser
)->location
;
8122 stmt
= c_parser_compound_statement (parser
);
8123 objc_build_finally_clause (location
, stmt
);
8125 objc_finish_try_stmt ();
8128 /* Parse an objc-synchronized-statement.
8130 objc-synchronized-statement:
8131 @synchronized ( expression ) compound-statement
8135 c_parser_objc_synchronized_statement (c_parser
*parser
)
8139 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNCHRONIZED
));
8140 c_parser_consume_token (parser
);
8141 loc
= c_parser_peek_token (parser
)->location
;
8142 objc_maybe_warn_exceptions (loc
);
8143 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8145 expr
= c_parser_expression (parser
).value
;
8146 expr
= c_fully_fold (expr
, false, NULL
);
8147 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8150 expr
= error_mark_node
;
8151 stmt
= c_parser_compound_statement (parser
);
8152 objc_build_synchronized (loc
, expr
, stmt
);
8155 /* Parse an objc-selector; return NULL_TREE without an error if the
8156 next token is not an objc-selector.
8161 enum struct union if else while do for switch case default
8162 break continue return goto asm sizeof typeof __alignof
8163 unsigned long const short volatile signed restrict _Complex
8164 in out inout bycopy byref oneway int char float double void _Bool
8166 ??? Why this selection of keywords but not, for example, storage
8167 class specifiers? */
8170 c_parser_objc_selector (c_parser
*parser
)
8172 c_token
*token
= c_parser_peek_token (parser
);
8173 tree value
= token
->value
;
8174 if (token
->type
== CPP_NAME
)
8176 c_parser_consume_token (parser
);
8179 if (token
->type
!= CPP_KEYWORD
)
8181 switch (token
->keyword
)
8223 c_parser_consume_token (parser
);
8230 /* Parse an objc-selector-arg.
8234 objc-keywordname-list
8236 objc-keywordname-list:
8238 objc-keywordname-list objc-keywordname
8246 c_parser_objc_selector_arg (c_parser
*parser
)
8248 tree sel
= c_parser_objc_selector (parser
);
8249 tree list
= NULL_TREE
;
8250 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
8254 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
8256 list
= chainon (list
, build_tree_list (sel
, NULL_TREE
));
8257 sel
= c_parser_objc_selector (parser
);
8258 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
8264 /* Parse an objc-receiver.
8273 c_parser_objc_receiver (c_parser
*parser
)
8275 if (c_parser_peek_token (parser
)->type
== CPP_NAME
8276 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
8277 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
8279 tree id
= c_parser_peek_token (parser
)->value
;
8280 c_parser_consume_token (parser
);
8281 return objc_get_class_reference (id
);
8283 return c_fully_fold (c_parser_expression (parser
).value
, false, NULL
);
8286 /* Parse objc-message-args.
8290 objc-keywordarg-list
8292 objc-keywordarg-list:
8294 objc-keywordarg-list objc-keywordarg
8297 objc-selector : objc-keywordexpr
8302 c_parser_objc_message_args (c_parser
*parser
)
8304 tree sel
= c_parser_objc_selector (parser
);
8305 tree list
= NULL_TREE
;
8306 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
8311 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
8312 return error_mark_node
;
8313 keywordexpr
= c_parser_objc_keywordexpr (parser
);
8314 list
= chainon (list
, build_tree_list (sel
, keywordexpr
));
8315 sel
= c_parser_objc_selector (parser
);
8316 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
8322 /* Parse an objc-keywordexpr.
8329 c_parser_objc_keywordexpr (c_parser
*parser
)
8332 vec
<tree
, va_gc
> *expr_list
= c_parser_expr_list (parser
, true, true,
8334 if (vec_safe_length (expr_list
) == 1)
8336 /* Just return the expression, remove a level of
8338 ret
= (*expr_list
)[0];
8342 /* We have a comma expression, we will collapse later. */
8343 ret
= build_tree_list_vec (expr_list
);
8345 release_tree_vector (expr_list
);
8349 /* A check, needed in several places, that ObjC interface, implementation or
8350 method definitions are not prefixed by incorrect items. */
8352 c_parser_objc_diagnose_bad_element_prefix (c_parser
*parser
,
8353 struct c_declspecs
*specs
)
8355 if (!specs
->declspecs_seen_p
|| specs
->non_sc_seen_p
8356 || specs
->typespec_kind
!= ctsk_none
)
8358 c_parser_error (parser
,
8359 "no type or storage class may be specified here,");
8360 c_parser_skip_to_end_of_block_or_statement (parser
);
8366 /* Parse an Objective-C @property declaration. The syntax is:
8368 objc-property-declaration:
8369 '@property' objc-property-attributes[opt] struct-declaration ;
8371 objc-property-attributes:
8372 '(' objc-property-attribute-list ')'
8374 objc-property-attribute-list:
8375 objc-property-attribute
8376 objc-property-attribute-list, objc-property-attribute
8378 objc-property-attribute
8379 'getter' = identifier
8380 'setter' = identifier
8389 @property NSString *name;
8390 @property (readonly) id object;
8391 @property (retain, nonatomic, getter=getTheName) id name;
8392 @property int a, b, c;
8394 PS: This function is identical to cp_parser_objc_at_propery_declaration
8395 for C++. Keep them in sync. */
8397 c_parser_objc_at_property_declaration (c_parser
*parser
)
8399 /* The following variables hold the attributes of the properties as
8400 parsed. They are 'false' or 'NULL_TREE' if the attribute was not
8401 seen. When we see an attribute, we set them to 'true' (if they
8402 are boolean properties) or to the identifier (if they have an
8403 argument, ie, for getter and setter). Note that here we only
8404 parse the list of attributes, check the syntax and accumulate the
8405 attributes that we find. objc_add_property_declaration() will
8406 then process the information. */
8407 bool property_assign
= false;
8408 bool property_copy
= false;
8409 tree property_getter_ident
= NULL_TREE
;
8410 bool property_nonatomic
= false;
8411 bool property_readonly
= false;
8412 bool property_readwrite
= false;
8413 bool property_retain
= false;
8414 tree property_setter_ident
= NULL_TREE
;
8416 /* 'properties' is the list of properties that we read. Usually a
8417 single one, but maybe more (eg, in "@property int a, b, c;" there
8422 loc
= c_parser_peek_token (parser
)->location
;
8423 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
));
8425 c_parser_consume_token (parser
); /* Eat '@property'. */
8427 /* Parse the optional attribute list... */
8428 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8431 c_parser_consume_token (parser
);
8433 /* Property attribute keywords are valid now. */
8434 parser
->objc_property_attr_context
= true;
8438 bool syntax_error
= false;
8439 c_token
*token
= c_parser_peek_token (parser
);
8442 if (token
->type
!= CPP_KEYWORD
)
8444 if (token
->type
== CPP_CLOSE_PAREN
)
8445 c_parser_error (parser
, "expected identifier");
8448 c_parser_consume_token (parser
);
8449 c_parser_error (parser
, "unknown property attribute");
8453 keyword
= token
->keyword
;
8454 c_parser_consume_token (parser
);
8457 case RID_ASSIGN
: property_assign
= true; break;
8458 case RID_COPY
: property_copy
= true; break;
8459 case RID_NONATOMIC
: property_nonatomic
= true; break;
8460 case RID_READONLY
: property_readonly
= true; break;
8461 case RID_READWRITE
: property_readwrite
= true; break;
8462 case RID_RETAIN
: property_retain
= true; break;
8466 if (c_parser_next_token_is_not (parser
, CPP_EQ
))
8468 if (keyword
== RID_GETTER
)
8469 c_parser_error (parser
,
8470 "missing %<=%> (after %<getter%> attribute)");
8472 c_parser_error (parser
,
8473 "missing %<=%> (after %<setter%> attribute)");
8474 syntax_error
= true;
8477 c_parser_consume_token (parser
); /* eat the = */
8478 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8480 c_parser_error (parser
, "expected identifier");
8481 syntax_error
= true;
8484 if (keyword
== RID_SETTER
)
8486 if (property_setter_ident
!= NULL_TREE
)
8487 c_parser_error (parser
, "the %<setter%> attribute may only be specified once");
8489 property_setter_ident
= c_parser_peek_token (parser
)->value
;
8490 c_parser_consume_token (parser
);
8491 if (c_parser_next_token_is_not (parser
, CPP_COLON
))
8492 c_parser_error (parser
, "setter name must terminate with %<:%>");
8494 c_parser_consume_token (parser
);
8498 if (property_getter_ident
!= NULL_TREE
)
8499 c_parser_error (parser
, "the %<getter%> attribute may only be specified once");
8501 property_getter_ident
= c_parser_peek_token (parser
)->value
;
8502 c_parser_consume_token (parser
);
8506 c_parser_error (parser
, "unknown property attribute");
8507 syntax_error
= true;
8514 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8515 c_parser_consume_token (parser
);
8519 parser
->objc_property_attr_context
= false;
8520 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8522 /* ... and the property declaration(s). */
8523 properties
= c_parser_struct_declaration (parser
);
8525 if (properties
== error_mark_node
)
8527 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8528 parser
->error
= false;
8532 if (properties
== NULL_TREE
)
8533 c_parser_error (parser
, "expected identifier");
8536 /* Comma-separated properties are chained together in
8537 reverse order; add them one by one. */
8538 properties
= nreverse (properties
);
8540 for (; properties
; properties
= TREE_CHAIN (properties
))
8541 objc_add_property_declaration (loc
, copy_node (properties
),
8542 property_readonly
, property_readwrite
,
8543 property_assign
, property_retain
,
8544 property_copy
, property_nonatomic
,
8545 property_getter_ident
, property_setter_ident
);
8548 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8549 parser
->error
= false;
8552 /* Parse an Objective-C @synthesize declaration. The syntax is:
8554 objc-synthesize-declaration:
8555 @synthesize objc-synthesize-identifier-list ;
8557 objc-synthesize-identifier-list:
8558 objc-synthesize-identifier
8559 objc-synthesize-identifier-list, objc-synthesize-identifier
8561 objc-synthesize-identifier
8563 identifier = identifier
8566 @synthesize MyProperty;
8567 @synthesize OneProperty, AnotherProperty=MyIvar, YetAnotherProperty;
8569 PS: This function is identical to cp_parser_objc_at_synthesize_declaration
8570 for C++. Keep them in sync.
8573 c_parser_objc_at_synthesize_declaration (c_parser
*parser
)
8575 tree list
= NULL_TREE
;
8577 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNTHESIZE
));
8578 loc
= c_parser_peek_token (parser
)->location
;
8580 c_parser_consume_token (parser
);
8583 tree property
, ivar
;
8584 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8586 c_parser_error (parser
, "expected identifier");
8587 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8588 /* Once we find the semicolon, we can resume normal parsing.
8589 We have to reset parser->error manually because
8590 c_parser_skip_until_found() won't reset it for us if the
8591 next token is precisely a semicolon. */
8592 parser
->error
= false;
8595 property
= c_parser_peek_token (parser
)->value
;
8596 c_parser_consume_token (parser
);
8597 if (c_parser_next_token_is (parser
, CPP_EQ
))
8599 c_parser_consume_token (parser
);
8600 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8602 c_parser_error (parser
, "expected identifier");
8603 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8604 parser
->error
= false;
8607 ivar
= c_parser_peek_token (parser
)->value
;
8608 c_parser_consume_token (parser
);
8612 list
= chainon (list
, build_tree_list (ivar
, property
));
8613 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8614 c_parser_consume_token (parser
);
8618 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8619 objc_add_synthesize_declaration (loc
, list
);
8622 /* Parse an Objective-C @dynamic declaration. The syntax is:
8624 objc-dynamic-declaration:
8625 @dynamic identifier-list ;
8628 @dynamic MyProperty;
8629 @dynamic MyProperty, AnotherProperty;
8631 PS: This function is identical to cp_parser_objc_at_dynamic_declaration
8632 for C++. Keep them in sync.
8635 c_parser_objc_at_dynamic_declaration (c_parser
*parser
)
8637 tree list
= NULL_TREE
;
8639 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_DYNAMIC
));
8640 loc
= c_parser_peek_token (parser
)->location
;
8642 c_parser_consume_token (parser
);
8646 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8648 c_parser_error (parser
, "expected identifier");
8649 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8650 parser
->error
= false;
8653 property
= c_parser_peek_token (parser
)->value
;
8654 list
= chainon (list
, build_tree_list (NULL_TREE
, property
));
8655 c_parser_consume_token (parser
);
8656 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8657 c_parser_consume_token (parser
);
8661 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8662 objc_add_dynamic_declaration (loc
, list
);
8666 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
8667 should be considered, statements. ALLOW_STMT is true if we're within
8668 the context of a function and such pragmas are to be allowed. Returns
8669 true if we actually parsed such a pragma. */
8672 c_parser_pragma (c_parser
*parser
, enum pragma_context context
)
8676 id
= c_parser_peek_token (parser
)->pragma_kind
;
8677 gcc_assert (id
!= PRAGMA_NONE
);
8681 case PRAGMA_OMP_BARRIER
:
8682 if (context
!= pragma_compound
)
8684 if (context
== pragma_stmt
)
8685 c_parser_error (parser
, "%<#pragma omp barrier%> may only be "
8686 "used in compound statements");
8689 c_parser_omp_barrier (parser
);
8692 case PRAGMA_OMP_FLUSH
:
8693 if (context
!= pragma_compound
)
8695 if (context
== pragma_stmt
)
8696 c_parser_error (parser
, "%<#pragma omp flush%> may only be "
8697 "used in compound statements");
8700 c_parser_omp_flush (parser
);
8703 case PRAGMA_OMP_TASKWAIT
:
8704 if (context
!= pragma_compound
)
8706 if (context
== pragma_stmt
)
8707 c_parser_error (parser
, "%<#pragma omp taskwait%> may only be "
8708 "used in compound statements");
8711 c_parser_omp_taskwait (parser
);
8714 case PRAGMA_OMP_TASKYIELD
:
8715 if (context
!= pragma_compound
)
8717 if (context
== pragma_stmt
)
8718 c_parser_error (parser
, "%<#pragma omp taskyield%> may only be "
8719 "used in compound statements");
8722 c_parser_omp_taskyield (parser
);
8725 case PRAGMA_OMP_THREADPRIVATE
:
8726 c_parser_omp_threadprivate (parser
);
8729 case PRAGMA_OMP_SECTION
:
8730 error_at (c_parser_peek_token (parser
)->location
,
8731 "%<#pragma omp section%> may only be used in "
8732 "%<#pragma omp sections%> construct");
8733 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
8736 case PRAGMA_GCC_PCH_PREPROCESS
:
8737 c_parser_error (parser
, "%<#pragma GCC pch_preprocess%> must be first");
8738 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
8742 if (id
< PRAGMA_FIRST_EXTERNAL
)
8744 if (context
== pragma_external
)
8747 c_parser_error (parser
, "expected declaration specifiers");
8748 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
8751 c_parser_omp_construct (parser
);
8757 c_parser_consume_pragma (parser
);
8758 c_invoke_pragma_handler (id
);
8760 /* Skip to EOL, but suppress any error message. Those will have been
8761 generated by the handler routine through calling error, as opposed
8762 to calling c_parser_error. */
8763 parser
->error
= true;
8764 c_parser_skip_to_pragma_eol (parser
);
8769 /* The interface the pragma parsers have to the lexer. */
8772 pragma_lex (tree
*value
)
8774 c_token
*tok
= c_parser_peek_token (the_parser
);
8775 enum cpp_ttype ret
= tok
->type
;
8777 *value
= tok
->value
;
8778 if (ret
== CPP_PRAGMA_EOL
|| ret
== CPP_EOF
)
8782 if (ret
== CPP_KEYWORD
)
8784 c_parser_consume_token (the_parser
);
8791 c_parser_pragma_pch_preprocess (c_parser
*parser
)
8795 c_parser_consume_pragma (parser
);
8796 if (c_parser_next_token_is (parser
, CPP_STRING
))
8798 name
= c_parser_peek_token (parser
)->value
;
8799 c_parser_consume_token (parser
);
8802 c_parser_error (parser
, "expected string literal");
8803 c_parser_skip_to_pragma_eol (parser
);
8806 c_common_pch_pragma (parse_in
, TREE_STRING_POINTER (name
));
8809 /* OpenMP 2.5 parsing routines. */
8811 /* Returns name of the next clause.
8812 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
8813 the token is not consumed. Otherwise appropriate pragma_omp_clause is
8814 returned and the token is consumed. */
8816 static pragma_omp_clause
8817 c_parser_omp_clause_name (c_parser
*parser
)
8819 pragma_omp_clause result
= PRAGMA_OMP_CLAUSE_NONE
;
8821 if (c_parser_next_token_is_keyword (parser
, RID_IF
))
8822 result
= PRAGMA_OMP_CLAUSE_IF
;
8823 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
8824 result
= PRAGMA_OMP_CLAUSE_DEFAULT
;
8825 else if (c_parser_next_token_is (parser
, CPP_NAME
))
8827 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
8832 if (!strcmp ("collapse", p
))
8833 result
= PRAGMA_OMP_CLAUSE_COLLAPSE
;
8834 else if (!strcmp ("copyin", p
))
8835 result
= PRAGMA_OMP_CLAUSE_COPYIN
;
8836 else if (!strcmp ("copyprivate", p
))
8837 result
= PRAGMA_OMP_CLAUSE_COPYPRIVATE
;
8840 if (!strcmp ("final", p
))
8841 result
= PRAGMA_OMP_CLAUSE_FINAL
;
8842 else if (!strcmp ("firstprivate", p
))
8843 result
= PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
;
8846 if (!strcmp ("lastprivate", p
))
8847 result
= PRAGMA_OMP_CLAUSE_LASTPRIVATE
;
8850 if (!strcmp ("mergeable", p
))
8851 result
= PRAGMA_OMP_CLAUSE_MERGEABLE
;
8854 if (!strcmp ("nowait", p
))
8855 result
= PRAGMA_OMP_CLAUSE_NOWAIT
;
8856 else if (!strcmp ("num_threads", p
))
8857 result
= PRAGMA_OMP_CLAUSE_NUM_THREADS
;
8860 if (!strcmp ("ordered", p
))
8861 result
= PRAGMA_OMP_CLAUSE_ORDERED
;
8864 if (!strcmp ("private", p
))
8865 result
= PRAGMA_OMP_CLAUSE_PRIVATE
;
8868 if (!strcmp ("reduction", p
))
8869 result
= PRAGMA_OMP_CLAUSE_REDUCTION
;
8872 if (!strcmp ("schedule", p
))
8873 result
= PRAGMA_OMP_CLAUSE_SCHEDULE
;
8874 else if (!strcmp ("shared", p
))
8875 result
= PRAGMA_OMP_CLAUSE_SHARED
;
8878 if (!strcmp ("untied", p
))
8879 result
= PRAGMA_OMP_CLAUSE_UNTIED
;
8884 if (result
!= PRAGMA_OMP_CLAUSE_NONE
)
8885 c_parser_consume_token (parser
);
8890 /* Validate that a clause of the given type does not already exist. */
8893 check_no_duplicate_clause (tree clauses
, enum omp_clause_code code
,
8898 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
8899 if (OMP_CLAUSE_CODE (c
) == code
)
8901 location_t loc
= OMP_CLAUSE_LOCATION (c
);
8902 error_at (loc
, "too many %qs clauses", name
);
8910 variable-list , identifier
8912 If KIND is nonzero, create the appropriate node and install the
8913 decl in OMP_CLAUSE_DECL and add the node to the head of the list.
8914 If KIND is nonzero, CLAUSE_LOC is the location of the clause.
8916 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
8917 return the list created. */
8920 c_parser_omp_variable_list (c_parser
*parser
,
8921 location_t clause_loc
,
8922 enum omp_clause_code kind
,
8925 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
8926 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
8927 c_parser_error (parser
, "expected identifier");
8929 while (c_parser_next_token_is (parser
, CPP_NAME
)
8930 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
8932 tree t
= lookup_name (c_parser_peek_token (parser
)->value
);
8935 undeclared_variable (c_parser_peek_token (parser
)->location
,
8936 c_parser_peek_token (parser
)->value
);
8937 else if (t
== error_mark_node
)
8941 tree u
= build_omp_clause (clause_loc
, kind
);
8942 OMP_CLAUSE_DECL (u
) = t
;
8943 OMP_CLAUSE_CHAIN (u
) = list
;
8947 list
= tree_cons (t
, NULL_TREE
, list
);
8949 c_parser_consume_token (parser
);
8951 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
8954 c_parser_consume_token (parser
);
8960 /* Similarly, but expect leading and trailing parenthesis. This is a very
8961 common case for omp clauses. */
8964 c_parser_omp_var_list_parens (c_parser
*parser
, enum omp_clause_code kind
,
8967 /* The clauses location. */
8968 location_t loc
= c_parser_peek_token (parser
)->location
;
8970 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8972 list
= c_parser_omp_variable_list (parser
, loc
, kind
, list
);
8973 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8979 collapse ( constant-expression ) */
8982 c_parser_omp_clause_collapse (c_parser
*parser
, tree list
)
8984 tree c
, num
= error_mark_node
;
8988 check_no_duplicate_clause (list
, OMP_CLAUSE_COLLAPSE
, "collapse");
8990 loc
= c_parser_peek_token (parser
)->location
;
8991 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8993 num
= c_parser_expr_no_commas (parser
, NULL
).value
;
8994 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8996 if (num
== error_mark_node
)
8998 if (!INTEGRAL_TYPE_P (TREE_TYPE (num
))
8999 || !host_integerp (num
, 0)
9000 || (n
= tree_low_cst (num
, 0)) <= 0
9004 "collapse argument needs positive constant integer expression");
9007 c
= build_omp_clause (loc
, OMP_CLAUSE_COLLAPSE
);
9008 OMP_CLAUSE_COLLAPSE_EXPR (c
) = num
;
9009 OMP_CLAUSE_CHAIN (c
) = list
;
9014 copyin ( variable-list ) */
9017 c_parser_omp_clause_copyin (c_parser
*parser
, tree list
)
9019 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYIN
, list
);
9023 copyprivate ( variable-list ) */
9026 c_parser_omp_clause_copyprivate (c_parser
*parser
, tree list
)
9028 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYPRIVATE
, list
);
9032 default ( shared | none ) */
9035 c_parser_omp_clause_default (c_parser
*parser
, tree list
)
9037 enum omp_clause_default_kind kind
= OMP_CLAUSE_DEFAULT_UNSPECIFIED
;
9038 location_t loc
= c_parser_peek_token (parser
)->location
;
9041 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9043 if (c_parser_next_token_is (parser
, CPP_NAME
))
9045 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
9050 if (strcmp ("none", p
) != 0)
9052 kind
= OMP_CLAUSE_DEFAULT_NONE
;
9056 if (strcmp ("shared", p
) != 0)
9058 kind
= OMP_CLAUSE_DEFAULT_SHARED
;
9065 c_parser_consume_token (parser
);
9070 c_parser_error (parser
, "expected %<none%> or %<shared%>");
9072 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9074 if (kind
== OMP_CLAUSE_DEFAULT_UNSPECIFIED
)
9077 check_no_duplicate_clause (list
, OMP_CLAUSE_DEFAULT
, "default");
9078 c
= build_omp_clause (loc
, OMP_CLAUSE_DEFAULT
);
9079 OMP_CLAUSE_CHAIN (c
) = list
;
9080 OMP_CLAUSE_DEFAULT_KIND (c
) = kind
;
9086 firstprivate ( variable-list ) */
9089 c_parser_omp_clause_firstprivate (c_parser
*parser
, tree list
)
9091 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FIRSTPRIVATE
, list
);
9095 final ( expression ) */
9098 c_parser_omp_clause_final (c_parser
*parser
, tree list
)
9100 location_t loc
= c_parser_peek_token (parser
)->location
;
9101 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9103 tree t
= c_parser_paren_condition (parser
);
9106 check_no_duplicate_clause (list
, OMP_CLAUSE_FINAL
, "final");
9108 c
= build_omp_clause (loc
, OMP_CLAUSE_FINAL
);
9109 OMP_CLAUSE_FINAL_EXPR (c
) = t
;
9110 OMP_CLAUSE_CHAIN (c
) = list
;
9114 c_parser_error (parser
, "expected %<(%>");
9120 if ( expression ) */
9123 c_parser_omp_clause_if (c_parser
*parser
, tree list
)
9125 location_t loc
= c_parser_peek_token (parser
)->location
;
9126 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9128 tree t
= c_parser_paren_condition (parser
);
9131 check_no_duplicate_clause (list
, OMP_CLAUSE_IF
, "if");
9133 c
= build_omp_clause (loc
, OMP_CLAUSE_IF
);
9134 OMP_CLAUSE_IF_EXPR (c
) = t
;
9135 OMP_CLAUSE_CHAIN (c
) = list
;
9139 c_parser_error (parser
, "expected %<(%>");
9145 lastprivate ( variable-list ) */
9148 c_parser_omp_clause_lastprivate (c_parser
*parser
, tree list
)
9150 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_LASTPRIVATE
, list
);
9157 c_parser_omp_clause_mergeable (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
9161 /* FIXME: Should we allow duplicates? */
9162 check_no_duplicate_clause (list
, OMP_CLAUSE_MERGEABLE
, "mergeable");
9164 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
9165 OMP_CLAUSE_MERGEABLE
);
9166 OMP_CLAUSE_CHAIN (c
) = list
;
9175 c_parser_omp_clause_nowait (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
9178 location_t loc
= c_parser_peek_token (parser
)->location
;
9180 check_no_duplicate_clause (list
, OMP_CLAUSE_NOWAIT
, "nowait");
9182 c
= build_omp_clause (loc
, OMP_CLAUSE_NOWAIT
);
9183 OMP_CLAUSE_CHAIN (c
) = list
;
9188 num_threads ( expression ) */
9191 c_parser_omp_clause_num_threads (c_parser
*parser
, tree list
)
9193 location_t num_threads_loc
= c_parser_peek_token (parser
)->location
;
9194 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9196 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
9197 tree c
, t
= c_parser_expression (parser
).value
;
9199 t
= c_fully_fold (t
, false, NULL
);
9201 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9203 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
9205 c_parser_error (parser
, "expected integer expression");
9209 /* Attempt to statically determine when the number isn't positive. */
9210 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
9211 build_int_cst (TREE_TYPE (t
), 0));
9212 if (CAN_HAVE_LOCATION_P (c
))
9213 SET_EXPR_LOCATION (c
, expr_loc
);
9214 if (c
== boolean_true_node
)
9216 warning_at (expr_loc
, 0,
9217 "%<num_threads%> value must be positive");
9218 t
= integer_one_node
;
9221 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_THREADS
, "num_threads");
9223 c
= build_omp_clause (num_threads_loc
, OMP_CLAUSE_NUM_THREADS
);
9224 OMP_CLAUSE_NUM_THREADS_EXPR (c
) = t
;
9225 OMP_CLAUSE_CHAIN (c
) = list
;
9236 c_parser_omp_clause_ordered (c_parser
*parser
, tree list
)
9240 check_no_duplicate_clause (list
, OMP_CLAUSE_ORDERED
, "ordered");
9242 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
9243 OMP_CLAUSE_ORDERED
);
9244 OMP_CLAUSE_CHAIN (c
) = list
;
9250 private ( variable-list ) */
9253 c_parser_omp_clause_private (c_parser
*parser
, tree list
)
9255 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_PRIVATE
, list
);
9259 reduction ( reduction-operator : variable-list )
9262 One of: + * - & ^ | && ||
9267 One of: + * - & ^ | && || max min */
9270 c_parser_omp_clause_reduction (c_parser
*parser
, tree list
)
9272 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
9273 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9275 enum tree_code code
;
9277 switch (c_parser_peek_token (parser
)->type
)
9289 code
= BIT_AND_EXPR
;
9292 code
= BIT_XOR_EXPR
;
9295 code
= BIT_IOR_EXPR
;
9298 code
= TRUTH_ANDIF_EXPR
;
9301 code
= TRUTH_ORIF_EXPR
;
9306 = IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
9307 if (strcmp (p
, "min") == 0)
9312 if (strcmp (p
, "max") == 0)
9320 c_parser_error (parser
,
9321 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
9322 "%<^%>, %<|%>, %<&&%>, %<||%>, %<min%> or %<max%>");
9323 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
9326 c_parser_consume_token (parser
);
9327 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
9331 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
9332 OMP_CLAUSE_REDUCTION
, list
);
9333 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
9334 OMP_CLAUSE_REDUCTION_CODE (c
) = code
;
9338 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9344 schedule ( schedule-kind )
9345 schedule ( schedule-kind , expression )
9348 static | dynamic | guided | runtime | auto
9352 c_parser_omp_clause_schedule (c_parser
*parser
, tree list
)
9355 location_t loc
= c_parser_peek_token (parser
)->location
;
9357 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9360 c
= build_omp_clause (loc
, OMP_CLAUSE_SCHEDULE
);
9362 if (c_parser_next_token_is (parser
, CPP_NAME
))
9364 tree kind
= c_parser_peek_token (parser
)->value
;
9365 const char *p
= IDENTIFIER_POINTER (kind
);
9370 if (strcmp ("dynamic", p
) != 0)
9372 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_DYNAMIC
;
9376 if (strcmp ("guided", p
) != 0)
9378 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_GUIDED
;
9382 if (strcmp ("runtime", p
) != 0)
9384 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_RUNTIME
;
9391 else if (c_parser_next_token_is_keyword (parser
, RID_STATIC
))
9392 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_STATIC
;
9393 else if (c_parser_next_token_is_keyword (parser
, RID_AUTO
))
9394 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_AUTO
;
9398 c_parser_consume_token (parser
);
9399 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9402 c_parser_consume_token (parser
);
9404 here
= c_parser_peek_token (parser
)->location
;
9405 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
9407 t
= c_fully_fold (t
, false, NULL
);
9409 if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_RUNTIME
)
9410 error_at (here
, "schedule %<runtime%> does not take "
9411 "a %<chunk_size%> parameter");
9412 else if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_AUTO
)
9414 "schedule %<auto%> does not take "
9415 "a %<chunk_size%> parameter");
9416 else if (TREE_CODE (TREE_TYPE (t
)) == INTEGER_TYPE
)
9417 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
) = t
;
9419 c_parser_error (parser
, "expected integer expression");
9421 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9424 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
9425 "expected %<,%> or %<)%>");
9427 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
9428 OMP_CLAUSE_CHAIN (c
) = list
;
9432 c_parser_error (parser
, "invalid schedule kind");
9433 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
9438 shared ( variable-list ) */
9441 c_parser_omp_clause_shared (c_parser
*parser
, tree list
)
9443 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_SHARED
, list
);
9450 c_parser_omp_clause_untied (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
9454 /* FIXME: Should we allow duplicates? */
9455 check_no_duplicate_clause (list
, OMP_CLAUSE_UNTIED
, "untied");
9457 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
9459 OMP_CLAUSE_CHAIN (c
) = list
;
9464 /* Parse all OpenMP clauses. The set clauses allowed by the directive
9465 is a bitmask in MASK. Return the list of clauses found; the result
9466 of clause default goes in *pdefault. */
9469 c_parser_omp_all_clauses (c_parser
*parser
, unsigned int mask
,
9472 tree clauses
= NULL
;
9475 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
9478 pragma_omp_clause c_kind
;
9480 tree prev
= clauses
;
9482 if (!first
&& c_parser_next_token_is (parser
, CPP_COMMA
))
9483 c_parser_consume_token (parser
);
9486 here
= c_parser_peek_token (parser
)->location
;
9487 c_kind
= c_parser_omp_clause_name (parser
);
9491 case PRAGMA_OMP_CLAUSE_COLLAPSE
:
9492 clauses
= c_parser_omp_clause_collapse (parser
, clauses
);
9493 c_name
= "collapse";
9495 case PRAGMA_OMP_CLAUSE_COPYIN
:
9496 clauses
= c_parser_omp_clause_copyin (parser
, clauses
);
9499 case PRAGMA_OMP_CLAUSE_COPYPRIVATE
:
9500 clauses
= c_parser_omp_clause_copyprivate (parser
, clauses
);
9501 c_name
= "copyprivate";
9503 case PRAGMA_OMP_CLAUSE_DEFAULT
:
9504 clauses
= c_parser_omp_clause_default (parser
, clauses
);
9507 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
:
9508 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
9509 c_name
= "firstprivate";
9511 case PRAGMA_OMP_CLAUSE_FINAL
:
9512 clauses
= c_parser_omp_clause_final (parser
, clauses
);
9515 case PRAGMA_OMP_CLAUSE_IF
:
9516 clauses
= c_parser_omp_clause_if (parser
, clauses
);
9519 case PRAGMA_OMP_CLAUSE_LASTPRIVATE
:
9520 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
9521 c_name
= "lastprivate";
9523 case PRAGMA_OMP_CLAUSE_MERGEABLE
:
9524 clauses
= c_parser_omp_clause_mergeable (parser
, clauses
);
9525 c_name
= "mergeable";
9527 case PRAGMA_OMP_CLAUSE_NOWAIT
:
9528 clauses
= c_parser_omp_clause_nowait (parser
, clauses
);
9531 case PRAGMA_OMP_CLAUSE_NUM_THREADS
:
9532 clauses
= c_parser_omp_clause_num_threads (parser
, clauses
);
9533 c_name
= "num_threads";
9535 case PRAGMA_OMP_CLAUSE_ORDERED
:
9536 clauses
= c_parser_omp_clause_ordered (parser
, clauses
);
9539 case PRAGMA_OMP_CLAUSE_PRIVATE
:
9540 clauses
= c_parser_omp_clause_private (parser
, clauses
);
9543 case PRAGMA_OMP_CLAUSE_REDUCTION
:
9544 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
9545 c_name
= "reduction";
9547 case PRAGMA_OMP_CLAUSE_SCHEDULE
:
9548 clauses
= c_parser_omp_clause_schedule (parser
, clauses
);
9549 c_name
= "schedule";
9551 case PRAGMA_OMP_CLAUSE_SHARED
:
9552 clauses
= c_parser_omp_clause_shared (parser
, clauses
);
9555 case PRAGMA_OMP_CLAUSE_UNTIED
:
9556 clauses
= c_parser_omp_clause_untied (parser
, clauses
);
9560 c_parser_error (parser
, "expected %<#pragma omp%> clause");
9564 if (((mask
>> c_kind
) & 1) == 0 && !parser
->error
)
9566 /* Remove the invalid clause(s) from the list to avoid
9567 confusing the rest of the compiler. */
9569 error_at (here
, "%qs is not valid for %qs", c_name
, where
);
9574 c_parser_skip_to_pragma_eol (parser
);
9576 return c_finish_omp_clauses (clauses
);
9583 In practice, we're also interested in adding the statement to an
9584 outer node. So it is convenient if we work around the fact that
9585 c_parser_statement calls add_stmt. */
9588 c_parser_omp_structured_block (c_parser
*parser
)
9590 tree stmt
= push_stmt_list ();
9591 c_parser_statement (parser
);
9592 return pop_stmt_list (stmt
);
9596 # pragma omp atomic new-line
9600 x binop= expr | x++ | ++x | x-- | --x
9602 +, *, -, /, &, ^, |, <<, >>
9604 where x is an lvalue expression with scalar type.
9607 # pragma omp atomic new-line
9610 # pragma omp atomic read new-line
9613 # pragma omp atomic write new-line
9616 # pragma omp atomic update new-line
9619 # pragma omp atomic capture new-line
9622 # pragma omp atomic capture new-line
9630 expression-stmt | x = x binop expr
9632 v = x binop= expr | v = x++ | v = ++x | v = x-- | v = --x
9634 { v = x; update-stmt; } | { update-stmt; v = x; }
9636 where x and v are lvalue expressions with scalar type.
9638 LOC is the location of the #pragma token. */
9641 c_parser_omp_atomic (location_t loc
, c_parser
*parser
)
9643 tree lhs
= NULL_TREE
, rhs
= NULL_TREE
, v
= NULL_TREE
;
9644 tree lhs1
= NULL_TREE
, rhs1
= NULL_TREE
;
9645 tree stmt
, orig_lhs
;
9646 enum tree_code code
= OMP_ATOMIC
, opcode
= NOP_EXPR
;
9647 struct c_expr rhs_expr
;
9648 bool structured_block
= false;
9650 if (c_parser_next_token_is (parser
, CPP_NAME
))
9652 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
9654 if (!strcmp (p
, "read"))
9655 code
= OMP_ATOMIC_READ
;
9656 else if (!strcmp (p
, "write"))
9658 else if (!strcmp (p
, "update"))
9660 else if (!strcmp (p
, "capture"))
9661 code
= OMP_ATOMIC_CAPTURE_NEW
;
9665 c_parser_consume_token (parser
);
9667 c_parser_skip_to_pragma_eol (parser
);
9671 case OMP_ATOMIC_READ
:
9672 case NOP_EXPR
: /* atomic write */
9673 v
= c_parser_unary_expression (parser
).value
;
9674 v
= c_fully_fold (v
, false, NULL
);
9675 if (v
== error_mark_node
)
9677 loc
= c_parser_peek_token (parser
)->location
;
9678 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
9680 if (code
== NOP_EXPR
)
9681 lhs
= c_parser_expression (parser
).value
;
9683 lhs
= c_parser_unary_expression (parser
).value
;
9684 lhs
= c_fully_fold (lhs
, false, NULL
);
9685 if (lhs
== error_mark_node
)
9687 if (code
== NOP_EXPR
)
9689 /* atomic write is represented by OMP_ATOMIC with NOP_EXPR
9697 case OMP_ATOMIC_CAPTURE_NEW
:
9698 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
9700 c_parser_consume_token (parser
);
9701 structured_block
= true;
9705 v
= c_parser_unary_expression (parser
).value
;
9706 v
= c_fully_fold (v
, false, NULL
);
9707 if (v
== error_mark_node
)
9709 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
9717 /* For structured_block case we don't know yet whether
9718 old or new x should be captured. */
9720 lhs
= c_parser_unary_expression (parser
).value
;
9721 lhs
= c_fully_fold (lhs
, false, NULL
);
9723 switch (TREE_CODE (lhs
))
9727 c_parser_skip_to_end_of_block_or_statement (parser
);
9728 if (structured_block
)
9730 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
9731 c_parser_consume_token (parser
);
9732 else if (code
== OMP_ATOMIC_CAPTURE_NEW
)
9734 c_parser_skip_to_end_of_block_or_statement (parser
);
9735 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
9736 c_parser_consume_token (parser
);
9741 case POSTINCREMENT_EXPR
:
9742 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
9743 code
= OMP_ATOMIC_CAPTURE_OLD
;
9745 case PREINCREMENT_EXPR
:
9746 lhs
= TREE_OPERAND (lhs
, 0);
9748 rhs
= integer_one_node
;
9751 case POSTDECREMENT_EXPR
:
9752 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
9753 code
= OMP_ATOMIC_CAPTURE_OLD
;
9755 case PREDECREMENT_EXPR
:
9756 lhs
= TREE_OPERAND (lhs
, 0);
9757 opcode
= MINUS_EXPR
;
9758 rhs
= integer_one_node
;
9762 if (TREE_CODE (TREE_OPERAND (lhs
, 0)) == SAVE_EXPR
9763 && TREE_CODE (TREE_OPERAND (lhs
, 1)) == COMPOUND_EXPR
9764 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0)) == MODIFY_EXPR
9765 && TREE_OPERAND (TREE_OPERAND (lhs
, 1), 1) == TREE_OPERAND (lhs
, 0)
9766 && TREE_CODE (TREE_TYPE (TREE_OPERAND (TREE_OPERAND
9767 (TREE_OPERAND (lhs
, 1), 0), 0)))
9769 /* Undo effects of boolean_increment for post {in,de}crement. */
9770 lhs
= TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0);
9773 if (TREE_CODE (lhs
) == MODIFY_EXPR
9774 && TREE_CODE (TREE_TYPE (TREE_OPERAND (lhs
, 0))) == BOOLEAN_TYPE
)
9776 /* Undo effects of boolean_increment. */
9777 if (integer_onep (TREE_OPERAND (lhs
, 1)))
9779 /* This is pre or post increment. */
9780 rhs
= TREE_OPERAND (lhs
, 1);
9781 lhs
= TREE_OPERAND (lhs
, 0);
9783 if (code
== OMP_ATOMIC_CAPTURE_NEW
9784 && !structured_block
9785 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
9786 code
= OMP_ATOMIC_CAPTURE_OLD
;
9789 if (TREE_CODE (TREE_OPERAND (lhs
, 1)) == TRUTH_NOT_EXPR
9790 && TREE_OPERAND (lhs
, 0)
9791 == TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0))
9793 /* This is pre or post decrement. */
9794 rhs
= TREE_OPERAND (lhs
, 1);
9795 lhs
= TREE_OPERAND (lhs
, 0);
9797 if (code
== OMP_ATOMIC_CAPTURE_NEW
9798 && !structured_block
9799 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
9800 code
= OMP_ATOMIC_CAPTURE_OLD
;
9806 switch (c_parser_peek_token (parser
)->type
)
9812 opcode
= TRUNC_DIV_EXPR
;
9818 opcode
= MINUS_EXPR
;
9821 opcode
= LSHIFT_EXPR
;
9824 opcode
= RSHIFT_EXPR
;
9827 opcode
= BIT_AND_EXPR
;
9830 opcode
= BIT_IOR_EXPR
;
9833 opcode
= BIT_XOR_EXPR
;
9836 if (structured_block
|| code
== OMP_ATOMIC
)
9838 location_t aloc
= c_parser_peek_token (parser
)->location
;
9840 enum c_parser_prec oprec
= PREC_NONE
;
9842 c_parser_consume_token (parser
);
9843 rhs1
= c_parser_unary_expression (parser
).value
;
9844 rhs1
= c_fully_fold (rhs1
, false, NULL
);
9845 if (rhs1
== error_mark_node
)
9847 switch (c_parser_peek_token (parser
)->type
)
9850 if (code
== OMP_ATOMIC_CAPTURE_NEW
)
9852 code
= OMP_ATOMIC_CAPTURE_OLD
;
9857 c_parser_consume_token (parser
);
9860 c_parser_error (parser
,
9861 "invalid form of %<#pragma omp atomic%>");
9868 opcode
= TRUNC_DIV_EXPR
;
9876 opcode
= MINUS_EXPR
;
9880 opcode
= LSHIFT_EXPR
;
9884 opcode
= RSHIFT_EXPR
;
9888 opcode
= BIT_AND_EXPR
;
9889 oprec
= PREC_BITAND
;
9892 opcode
= BIT_IOR_EXPR
;
9896 opcode
= BIT_XOR_EXPR
;
9897 oprec
= PREC_BITXOR
;
9900 c_parser_error (parser
,
9901 "invalid operator for %<#pragma omp atomic%>");
9905 c_parser_consume_token (parser
);
9906 rhs_loc
= c_parser_peek_token (parser
)->location
;
9907 if (commutative_tree_code (opcode
))
9908 oprec
= (enum c_parser_prec
) (oprec
- 1);
9909 rhs_expr
= c_parser_binary_expression (parser
, NULL
, oprec
);
9910 rhs_expr
= default_function_array_read_conversion (rhs_loc
,
9912 rhs
= rhs_expr
.value
;
9913 rhs
= c_fully_fold (rhs
, false, NULL
);
9918 c_parser_error (parser
,
9919 "invalid operator for %<#pragma omp atomic%>");
9923 /* Arrange to pass the location of the assignment operator to
9924 c_finish_omp_atomic. */
9925 loc
= c_parser_peek_token (parser
)->location
;
9926 c_parser_consume_token (parser
);
9928 location_t rhs_loc
= c_parser_peek_token (parser
)->location
;
9929 rhs_expr
= c_parser_expression (parser
);
9930 rhs_expr
= default_function_array_read_conversion (rhs_loc
, rhs_expr
);
9932 rhs
= rhs_expr
.value
;
9933 rhs
= c_fully_fold (rhs
, false, NULL
);
9937 if (structured_block
&& code
== OMP_ATOMIC_CAPTURE_NEW
)
9939 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
9941 v
= c_parser_unary_expression (parser
).value
;
9942 v
= c_fully_fold (v
, false, NULL
);
9943 if (v
== error_mark_node
)
9945 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
9947 lhs1
= c_parser_unary_expression (parser
).value
;
9948 lhs1
= c_fully_fold (lhs1
, false, NULL
);
9949 if (lhs1
== error_mark_node
)
9952 if (structured_block
)
9954 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9955 c_parser_require (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
9958 stmt
= c_finish_omp_atomic (loc
, code
, opcode
, lhs
, rhs
, v
, lhs1
, rhs1
);
9959 if (stmt
!= error_mark_node
)
9962 if (!structured_block
)
9963 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9968 # pragma omp barrier new-line
9972 c_parser_omp_barrier (c_parser
*parser
)
9974 location_t loc
= c_parser_peek_token (parser
)->location
;
9975 c_parser_consume_pragma (parser
);
9976 c_parser_skip_to_pragma_eol (parser
);
9978 c_finish_omp_barrier (loc
);
9982 # pragma omp critical [(name)] new-line
9985 LOC is the location of the #pragma itself. */
9988 c_parser_omp_critical (location_t loc
, c_parser
*parser
)
9990 tree stmt
, name
= NULL
;
9992 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9994 c_parser_consume_token (parser
);
9995 if (c_parser_next_token_is (parser
, CPP_NAME
))
9997 name
= c_parser_peek_token (parser
)->value
;
9998 c_parser_consume_token (parser
);
9999 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10002 c_parser_error (parser
, "expected identifier");
10004 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
10005 c_parser_error (parser
, "expected %<(%> or end of line");
10006 c_parser_skip_to_pragma_eol (parser
);
10008 stmt
= c_parser_omp_structured_block (parser
);
10009 return c_finish_omp_critical (loc
, stmt
, name
);
10013 # pragma omp flush flush-vars[opt] new-line
10016 ( variable-list ) */
10019 c_parser_omp_flush (c_parser
*parser
)
10021 location_t loc
= c_parser_peek_token (parser
)->location
;
10022 c_parser_consume_pragma (parser
);
10023 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
10024 c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
10025 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
10026 c_parser_error (parser
, "expected %<(%> or end of line");
10027 c_parser_skip_to_pragma_eol (parser
);
10029 c_finish_omp_flush (loc
);
10032 /* Parse the restricted form of the for statement allowed by OpenMP.
10033 The real trick here is to determine the loop control variable early
10034 so that we can push a new decl if necessary to make it private.
10035 LOC is the location of the OMP in "#pragma omp". */
10038 c_parser_omp_for_loop (location_t loc
,
10039 c_parser
*parser
, tree clauses
, tree
*par_clauses
)
10041 tree decl
, cond
, incr
, save_break
, save_cont
, body
, init
, stmt
, cl
;
10042 tree declv
, condv
, incrv
, initv
, ret
= NULL
;
10043 bool fail
= false, open_brace_parsed
= false;
10044 int i
, collapse
= 1, nbraces
= 0;
10045 location_t for_loc
;
10046 vec
<tree
, va_gc
> *for_block
= make_tree_vector ();
10048 for (cl
= clauses
; cl
; cl
= OMP_CLAUSE_CHAIN (cl
))
10049 if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_COLLAPSE
)
10050 collapse
= tree_low_cst (OMP_CLAUSE_COLLAPSE_EXPR (cl
), 0);
10052 gcc_assert (collapse
>= 1);
10054 declv
= make_tree_vec (collapse
);
10055 initv
= make_tree_vec (collapse
);
10056 condv
= make_tree_vec (collapse
);
10057 incrv
= make_tree_vec (collapse
);
10059 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
))
10061 c_parser_error (parser
, "for statement expected");
10064 for_loc
= c_parser_peek_token (parser
)->location
;
10065 c_parser_consume_token (parser
);
10067 for (i
= 0; i
< collapse
; i
++)
10069 int bracecount
= 0;
10071 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10074 /* Parse the initialization declaration or expression. */
10075 if (c_parser_next_tokens_start_declaration (parser
))
10078 vec_safe_push (for_block
, c_begin_compound_stmt (true));
10079 c_parser_declaration_or_fndef (parser
, true, true, true, true, true, NULL
);
10080 decl
= check_for_loop_decls (for_loc
, flag_isoc99
);
10083 if (DECL_INITIAL (decl
) == error_mark_node
)
10084 decl
= error_mark_node
;
10087 else if (c_parser_next_token_is (parser
, CPP_NAME
)
10088 && c_parser_peek_2nd_token (parser
)->type
== CPP_EQ
)
10090 struct c_expr decl_exp
;
10091 struct c_expr init_exp
;
10092 location_t init_loc
;
10094 decl_exp
= c_parser_postfix_expression (parser
);
10095 decl
= decl_exp
.value
;
10097 c_parser_require (parser
, CPP_EQ
, "expected %<=%>");
10099 init_loc
= c_parser_peek_token (parser
)->location
;
10100 init_exp
= c_parser_expr_no_commas (parser
, NULL
);
10101 init_exp
= default_function_array_read_conversion (init_loc
,
10103 init
= build_modify_expr (init_loc
, decl
, decl_exp
.original_type
,
10104 NOP_EXPR
, init_loc
, init_exp
.value
,
10105 init_exp
.original_type
);
10106 init
= c_process_expr_stmt (init_loc
, init
);
10108 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
10113 c_parser_error (parser
,
10114 "expected iteration declaration or initialization");
10115 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
10121 /* Parse the loop condition. */
10123 if (c_parser_next_token_is_not (parser
, CPP_SEMICOLON
))
10125 location_t cond_loc
= c_parser_peek_token (parser
)->location
;
10126 struct c_expr cond_expr
= c_parser_binary_expression (parser
, NULL
,
10129 cond
= cond_expr
.value
;
10130 cond
= c_objc_common_truthvalue_conversion (cond_loc
, cond
);
10131 cond
= c_fully_fold (cond
, false, NULL
);
10132 switch (cond_expr
.original_code
)
10140 /* Can't be cond = error_mark_node, because we want to preserve
10141 the location until c_finish_omp_for. */
10142 cond
= build1 (NOP_EXPR
, boolean_type_node
, error_mark_node
);
10145 protected_set_expr_location (cond
, cond_loc
);
10147 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
10149 /* Parse the increment expression. */
10151 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_PAREN
))
10153 location_t incr_loc
= c_parser_peek_token (parser
)->location
;
10155 incr
= c_process_expr_stmt (incr_loc
,
10156 c_parser_expression (parser
).value
);
10158 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10160 if (decl
== NULL
|| decl
== error_mark_node
|| init
== error_mark_node
)
10164 TREE_VEC_ELT (declv
, i
) = decl
;
10165 TREE_VEC_ELT (initv
, i
) = init
;
10166 TREE_VEC_ELT (condv
, i
) = cond
;
10167 TREE_VEC_ELT (incrv
, i
) = incr
;
10171 if (i
== collapse
- 1)
10174 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
10175 in between the collapsed for loops to be still considered perfectly
10176 nested. Hopefully the final version clarifies this.
10177 For now handle (multiple) {'s and empty statements. */
10180 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
10182 c_parser_consume_token (parser
);
10185 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
10187 c_parser_consume_token (parser
);
10190 else if (bracecount
10191 && c_parser_next_token_is (parser
, CPP_SEMICOLON
))
10192 c_parser_consume_token (parser
);
10195 c_parser_error (parser
, "not enough perfectly nested loops");
10198 open_brace_parsed
= true;
10208 nbraces
+= bracecount
;
10211 save_break
= c_break_label
;
10212 c_break_label
= size_one_node
;
10213 save_cont
= c_cont_label
;
10214 c_cont_label
= NULL_TREE
;
10215 body
= push_stmt_list ();
10217 if (open_brace_parsed
)
10219 location_t here
= c_parser_peek_token (parser
)->location
;
10220 stmt
= c_begin_compound_stmt (true);
10221 c_parser_compound_statement_nostart (parser
);
10222 add_stmt (c_end_compound_stmt (here
, stmt
, true));
10225 add_stmt (c_parser_c99_block_statement (parser
));
10228 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_cont_label
);
10229 SET_EXPR_LOCATION (t
, loc
);
10233 body
= pop_stmt_list (body
);
10234 c_break_label
= save_break
;
10235 c_cont_label
= save_cont
;
10239 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
10241 c_parser_consume_token (parser
);
10244 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
10245 c_parser_consume_token (parser
);
10248 c_parser_error (parser
, "collapsed loops not perfectly nested");
10251 location_t here
= c_parser_peek_token (parser
)->location
;
10252 stmt
= c_begin_compound_stmt (true);
10254 c_parser_compound_statement_nostart (parser
);
10255 body
= c_end_compound_stmt (here
, stmt
, true);
10262 /* Only bother calling c_finish_omp_for if we haven't already generated
10263 an error from the initialization parsing. */
10266 stmt
= c_finish_omp_for (loc
, declv
, initv
, condv
, incrv
, body
, NULL
);
10269 if (par_clauses
!= NULL
)
10272 for (c
= par_clauses
; *c
; )
10273 if (OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_FIRSTPRIVATE
10274 && OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_LASTPRIVATE
)
10275 c
= &OMP_CLAUSE_CHAIN (*c
);
10278 for (i
= 0; i
< collapse
; i
++)
10279 if (TREE_VEC_ELT (declv
, i
) == OMP_CLAUSE_DECL (*c
))
10282 c
= &OMP_CLAUSE_CHAIN (*c
);
10283 else if (OMP_CLAUSE_CODE (*c
) == OMP_CLAUSE_FIRSTPRIVATE
)
10286 "iteration variable %qD should not be firstprivate",
10287 OMP_CLAUSE_DECL (*c
));
10288 *c
= OMP_CLAUSE_CHAIN (*c
);
10292 /* Copy lastprivate (decl) clause to OMP_FOR_CLAUSES,
10293 change it to shared (decl) in
10294 OMP_PARALLEL_CLAUSES. */
10295 tree l
= build_omp_clause (OMP_CLAUSE_LOCATION (*c
),
10296 OMP_CLAUSE_LASTPRIVATE
);
10297 OMP_CLAUSE_DECL (l
) = OMP_CLAUSE_DECL (*c
);
10298 OMP_CLAUSE_CHAIN (l
) = clauses
;
10300 OMP_CLAUSE_SET_CODE (*c
, OMP_CLAUSE_SHARED
);
10304 OMP_FOR_CLAUSES (stmt
) = clauses
;
10309 while (!for_block
->is_empty ())
10311 /* FIXME diagnostics: LOC below should be the actual location of
10312 this particular for block. We need to build a list of
10313 locations to go along with FOR_BLOCK. */
10314 stmt
= c_end_compound_stmt (loc
, for_block
->pop (), true);
10317 release_tree_vector (for_block
);
10322 #pragma omp for for-clause[optseq] new-line
10325 LOC is the location of the #pragma token.
10328 #define OMP_FOR_CLAUSE_MASK \
10329 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
10330 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
10331 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
10332 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
10333 | (1u << PRAGMA_OMP_CLAUSE_ORDERED) \
10334 | (1u << PRAGMA_OMP_CLAUSE_SCHEDULE) \
10335 | (1u << PRAGMA_OMP_CLAUSE_COLLAPSE) \
10336 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
10339 c_parser_omp_for (location_t loc
, c_parser
*parser
)
10341 tree block
, clauses
, ret
;
10343 clauses
= c_parser_omp_all_clauses (parser
, OMP_FOR_CLAUSE_MASK
,
10344 "#pragma omp for");
10346 block
= c_begin_compound_stmt (true);
10347 ret
= c_parser_omp_for_loop (loc
, parser
, clauses
, NULL
);
10348 block
= c_end_compound_stmt (loc
, block
, true);
10355 # pragma omp master new-line
10358 LOC is the location of the #pragma token.
10362 c_parser_omp_master (location_t loc
, c_parser
*parser
)
10364 c_parser_skip_to_pragma_eol (parser
);
10365 return c_finish_omp_master (loc
, c_parser_omp_structured_block (parser
));
10369 # pragma omp ordered new-line
10372 LOC is the location of the #pragma itself.
10376 c_parser_omp_ordered (location_t loc
, c_parser
*parser
)
10378 c_parser_skip_to_pragma_eol (parser
);
10379 return c_finish_omp_ordered (loc
, c_parser_omp_structured_block (parser
));
10385 { section-sequence }
10388 section-directive[opt] structured-block
10389 section-sequence section-directive structured-block
10391 SECTIONS_LOC is the location of the #pragma omp sections. */
10394 c_parser_omp_sections_scope (location_t sections_loc
, c_parser
*parser
)
10396 tree stmt
, substmt
;
10397 bool error_suppress
= false;
10400 loc
= c_parser_peek_token (parser
)->location
;
10401 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
10403 /* Avoid skipping until the end of the block. */
10404 parser
->error
= false;
10408 stmt
= push_stmt_list ();
10410 if (c_parser_peek_token (parser
)->pragma_kind
!= PRAGMA_OMP_SECTION
)
10412 substmt
= push_stmt_list ();
10416 c_parser_statement (parser
);
10418 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
10420 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
10422 if (c_parser_next_token_is (parser
, CPP_EOF
))
10426 substmt
= pop_stmt_list (substmt
);
10427 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
10428 SET_EXPR_LOCATION (substmt
, loc
);
10429 add_stmt (substmt
);
10434 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
10436 if (c_parser_next_token_is (parser
, CPP_EOF
))
10439 loc
= c_parser_peek_token (parser
)->location
;
10440 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
10442 c_parser_consume_pragma (parser
);
10443 c_parser_skip_to_pragma_eol (parser
);
10444 error_suppress
= false;
10446 else if (!error_suppress
)
10448 error_at (loc
, "expected %<#pragma omp section%> or %<}%>");
10449 error_suppress
= true;
10452 substmt
= c_parser_omp_structured_block (parser
);
10453 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
10454 SET_EXPR_LOCATION (substmt
, loc
);
10455 add_stmt (substmt
);
10457 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
,
10458 "expected %<#pragma omp section%> or %<}%>");
10460 substmt
= pop_stmt_list (stmt
);
10462 stmt
= make_node (OMP_SECTIONS
);
10463 SET_EXPR_LOCATION (stmt
, sections_loc
);
10464 TREE_TYPE (stmt
) = void_type_node
;
10465 OMP_SECTIONS_BODY (stmt
) = substmt
;
10467 return add_stmt (stmt
);
10471 # pragma omp sections sections-clause[optseq] newline
10474 LOC is the location of the #pragma token.
10477 #define OMP_SECTIONS_CLAUSE_MASK \
10478 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
10479 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
10480 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
10481 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
10482 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
10485 c_parser_omp_sections (location_t loc
, c_parser
*parser
)
10487 tree block
, clauses
, ret
;
10489 clauses
= c_parser_omp_all_clauses (parser
, OMP_SECTIONS_CLAUSE_MASK
,
10490 "#pragma omp sections");
10492 block
= c_begin_compound_stmt (true);
10493 ret
= c_parser_omp_sections_scope (loc
, parser
);
10495 OMP_SECTIONS_CLAUSES (ret
) = clauses
;
10496 block
= c_end_compound_stmt (loc
, block
, true);
10503 # pragma parallel parallel-clause new-line
10504 # pragma parallel for parallel-for-clause new-line
10505 # pragma parallel sections parallel-sections-clause new-line
10507 LOC is the location of the #pragma token.
10510 #define OMP_PARALLEL_CLAUSE_MASK \
10511 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
10512 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
10513 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
10514 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
10515 | (1u << PRAGMA_OMP_CLAUSE_SHARED) \
10516 | (1u << PRAGMA_OMP_CLAUSE_COPYIN) \
10517 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
10518 | (1u << PRAGMA_OMP_CLAUSE_NUM_THREADS))
10521 c_parser_omp_parallel (location_t loc
, c_parser
*parser
)
10523 enum pragma_kind p_kind
= PRAGMA_OMP_PARALLEL
;
10524 const char *p_name
= "#pragma omp parallel";
10525 tree stmt
, clauses
, par_clause
, ws_clause
, block
;
10526 unsigned int mask
= OMP_PARALLEL_CLAUSE_MASK
;
10528 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
10530 c_parser_consume_token (parser
);
10531 p_kind
= PRAGMA_OMP_PARALLEL_FOR
;
10532 p_name
= "#pragma omp parallel for";
10533 mask
|= OMP_FOR_CLAUSE_MASK
;
10534 mask
&= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT
);
10536 else if (c_parser_next_token_is (parser
, CPP_NAME
))
10538 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10539 if (strcmp (p
, "sections") == 0)
10541 c_parser_consume_token (parser
);
10542 p_kind
= PRAGMA_OMP_PARALLEL_SECTIONS
;
10543 p_name
= "#pragma omp parallel sections";
10544 mask
|= OMP_SECTIONS_CLAUSE_MASK
;
10545 mask
&= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT
);
10549 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
);
10553 case PRAGMA_OMP_PARALLEL
:
10554 block
= c_begin_omp_parallel ();
10555 c_parser_statement (parser
);
10556 stmt
= c_finish_omp_parallel (loc
, clauses
, block
);
10559 case PRAGMA_OMP_PARALLEL_FOR
:
10560 block
= c_begin_omp_parallel ();
10561 c_split_parallel_clauses (loc
, clauses
, &par_clause
, &ws_clause
);
10562 c_parser_omp_for_loop (loc
, parser
, ws_clause
, &par_clause
);
10563 stmt
= c_finish_omp_parallel (loc
, par_clause
, block
);
10564 OMP_PARALLEL_COMBINED (stmt
) = 1;
10567 case PRAGMA_OMP_PARALLEL_SECTIONS
:
10568 block
= c_begin_omp_parallel ();
10569 c_split_parallel_clauses (loc
, clauses
, &par_clause
, &ws_clause
);
10570 stmt
= c_parser_omp_sections_scope (loc
, parser
);
10572 OMP_SECTIONS_CLAUSES (stmt
) = ws_clause
;
10573 stmt
= c_finish_omp_parallel (loc
, par_clause
, block
);
10574 OMP_PARALLEL_COMBINED (stmt
) = 1;
10578 gcc_unreachable ();
10585 # pragma omp single single-clause[optseq] new-line
10588 LOC is the location of the #pragma.
10591 #define OMP_SINGLE_CLAUSE_MASK \
10592 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
10593 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
10594 | (1u << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
10595 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
10598 c_parser_omp_single (location_t loc
, c_parser
*parser
)
10600 tree stmt
= make_node (OMP_SINGLE
);
10601 SET_EXPR_LOCATION (stmt
, loc
);
10602 TREE_TYPE (stmt
) = void_type_node
;
10604 OMP_SINGLE_CLAUSES (stmt
)
10605 = c_parser_omp_all_clauses (parser
, OMP_SINGLE_CLAUSE_MASK
,
10606 "#pragma omp single");
10607 OMP_SINGLE_BODY (stmt
) = c_parser_omp_structured_block (parser
);
10609 return add_stmt (stmt
);
10613 # pragma omp task task-clause[optseq] new-line
10615 LOC is the location of the #pragma.
10618 #define OMP_TASK_CLAUSE_MASK \
10619 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
10620 | (1u << PRAGMA_OMP_CLAUSE_UNTIED) \
10621 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
10622 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
10623 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
10624 | (1u << PRAGMA_OMP_CLAUSE_SHARED) \
10625 | (1u << PRAGMA_OMP_CLAUSE_FINAL) \
10626 | (1u << PRAGMA_OMP_CLAUSE_MERGEABLE))
10629 c_parser_omp_task (location_t loc
, c_parser
*parser
)
10631 tree clauses
, block
;
10633 clauses
= c_parser_omp_all_clauses (parser
, OMP_TASK_CLAUSE_MASK
,
10634 "#pragma omp task");
10636 block
= c_begin_omp_task ();
10637 c_parser_statement (parser
);
10638 return c_finish_omp_task (loc
, clauses
, block
);
10642 # pragma omp taskwait new-line
10646 c_parser_omp_taskwait (c_parser
*parser
)
10648 location_t loc
= c_parser_peek_token (parser
)->location
;
10649 c_parser_consume_pragma (parser
);
10650 c_parser_skip_to_pragma_eol (parser
);
10652 c_finish_omp_taskwait (loc
);
10656 # pragma omp taskyield new-line
10660 c_parser_omp_taskyield (c_parser
*parser
)
10662 location_t loc
= c_parser_peek_token (parser
)->location
;
10663 c_parser_consume_pragma (parser
);
10664 c_parser_skip_to_pragma_eol (parser
);
10666 c_finish_omp_taskyield (loc
);
10669 /* Main entry point to parsing most OpenMP pragmas. */
10672 c_parser_omp_construct (c_parser
*parser
)
10674 enum pragma_kind p_kind
;
10678 loc
= c_parser_peek_token (parser
)->location
;
10679 p_kind
= c_parser_peek_token (parser
)->pragma_kind
;
10680 c_parser_consume_pragma (parser
);
10684 case PRAGMA_OMP_ATOMIC
:
10685 c_parser_omp_atomic (loc
, parser
);
10687 case PRAGMA_OMP_CRITICAL
:
10688 stmt
= c_parser_omp_critical (loc
, parser
);
10690 case PRAGMA_OMP_FOR
:
10691 stmt
= c_parser_omp_for (loc
, parser
);
10693 case PRAGMA_OMP_MASTER
:
10694 stmt
= c_parser_omp_master (loc
, parser
);
10696 case PRAGMA_OMP_ORDERED
:
10697 stmt
= c_parser_omp_ordered (loc
, parser
);
10699 case PRAGMA_OMP_PARALLEL
:
10700 stmt
= c_parser_omp_parallel (loc
, parser
);
10702 case PRAGMA_OMP_SECTIONS
:
10703 stmt
= c_parser_omp_sections (loc
, parser
);
10705 case PRAGMA_OMP_SINGLE
:
10706 stmt
= c_parser_omp_single (loc
, parser
);
10708 case PRAGMA_OMP_TASK
:
10709 stmt
= c_parser_omp_task (loc
, parser
);
10712 gcc_unreachable ();
10716 gcc_assert (EXPR_LOCATION (stmt
) != UNKNOWN_LOCATION
);
10721 # pragma omp threadprivate (variable-list) */
10724 c_parser_omp_threadprivate (c_parser
*parser
)
10729 c_parser_consume_pragma (parser
);
10730 loc
= c_parser_peek_token (parser
)->location
;
10731 vars
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
10733 /* Mark every variable in VARS to be assigned thread local storage. */
10734 for (t
= vars
; t
; t
= TREE_CHAIN (t
))
10736 tree v
= TREE_PURPOSE (t
);
10738 /* FIXME diagnostics: Ideally we should keep individual
10739 locations for all the variables in the var list to make the
10740 following errors more precise. Perhaps
10741 c_parser_omp_var_list_parens() should construct a list of
10742 locations to go along with the var list. */
10744 /* If V had already been marked threadprivate, it doesn't matter
10745 whether it had been used prior to this point. */
10746 if (TREE_CODE (v
) != VAR_DECL
)
10747 error_at (loc
, "%qD is not a variable", v
);
10748 else if (TREE_USED (v
) && !C_DECL_THREADPRIVATE_P (v
))
10749 error_at (loc
, "%qE declared %<threadprivate%> after first use", v
);
10750 else if (! TREE_STATIC (v
) && ! DECL_EXTERNAL (v
))
10751 error_at (loc
, "automatic variable %qE cannot be %<threadprivate%>", v
);
10752 else if (TREE_TYPE (v
) == error_mark_node
)
10754 else if (! COMPLETE_TYPE_P (TREE_TYPE (v
)))
10755 error_at (loc
, "%<threadprivate%> %qE has incomplete type", v
);
10758 if (! DECL_THREAD_LOCAL_P (v
))
10760 DECL_TLS_MODEL (v
) = decl_default_tls_model (v
);
10761 /* If rtl has been already set for this var, call
10762 make_decl_rtl once again, so that encode_section_info
10763 has a chance to look at the new decl flags. */
10764 if (DECL_RTL_SET_P (v
))
10767 C_DECL_THREADPRIVATE_P (v
) = 1;
10771 c_parser_skip_to_pragma_eol (parser
);
10774 /* Parse a transaction attribute (GCC Extension).
10776 transaction-attribute:
10780 The transactional memory language description is written for C++,
10781 and uses the C++0x attribute syntax. For compatibility, allow the
10782 bracket style for transactions in C as well. */
10785 c_parser_transaction_attributes (c_parser
*parser
)
10787 tree attr_name
, attr
= NULL
;
10789 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
10790 return c_parser_attributes (parser
);
10792 if (!c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
10794 c_parser_consume_token (parser
);
10795 if (!c_parser_require (parser
, CPP_OPEN_SQUARE
, "expected %<[%>"))
10798 attr_name
= c_parser_attribute_any_word (parser
);
10801 c_parser_consume_token (parser
);
10802 attr
= build_tree_list (attr_name
, NULL_TREE
);
10805 c_parser_error (parser
, "expected identifier");
10807 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
10809 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
10813 /* Parse a __transaction_atomic or __transaction_relaxed statement
10816 transaction-statement:
10817 __transaction_atomic transaction-attribute[opt] compound-statement
10818 __transaction_relaxed compound-statement
10820 Note that the only valid attribute is: "outer".
10824 c_parser_transaction (c_parser
*parser
, enum rid keyword
)
10826 unsigned int old_in
= parser
->in_transaction
;
10827 unsigned int this_in
= 1, new_in
;
10828 location_t loc
= c_parser_peek_token (parser
)->location
;
10831 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
10832 || keyword
== RID_TRANSACTION_RELAXED
)
10833 && c_parser_next_token_is_keyword (parser
, keyword
));
10834 c_parser_consume_token (parser
);
10836 if (keyword
== RID_TRANSACTION_RELAXED
)
10837 this_in
|= TM_STMT_ATTR_RELAXED
;
10840 attrs
= c_parser_transaction_attributes (parser
);
10842 this_in
|= parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
);
10845 /* Keep track if we're in the lexical scope of an outer transaction. */
10846 new_in
= this_in
| (old_in
& TM_STMT_ATTR_OUTER
);
10848 parser
->in_transaction
= new_in
;
10849 stmt
= c_parser_compound_statement (parser
);
10850 parser
->in_transaction
= old_in
;
10853 stmt
= c_finish_transaction (loc
, stmt
, this_in
);
10855 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
10856 "%<__transaction_atomic%> without transactional memory support enabled"
10857 : "%<__transaction_relaxed %> "
10858 "without transactional memory support enabled"));
10863 /* Parse a __transaction_atomic or __transaction_relaxed expression
10866 transaction-expression:
10867 __transaction_atomic ( expression )
10868 __transaction_relaxed ( expression )
10871 static struct c_expr
10872 c_parser_transaction_expression (c_parser
*parser
, enum rid keyword
)
10875 unsigned int old_in
= parser
->in_transaction
;
10876 unsigned int this_in
= 1;
10877 location_t loc
= c_parser_peek_token (parser
)->location
;
10880 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
10881 || keyword
== RID_TRANSACTION_RELAXED
)
10882 && c_parser_next_token_is_keyword (parser
, keyword
));
10883 c_parser_consume_token (parser
);
10885 if (keyword
== RID_TRANSACTION_RELAXED
)
10886 this_in
|= TM_STMT_ATTR_RELAXED
;
10889 attrs
= c_parser_transaction_attributes (parser
);
10891 this_in
|= parse_tm_stmt_attr (attrs
, 0);
10894 parser
->in_transaction
= this_in
;
10895 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10897 tree expr
= c_parser_expression (parser
).value
;
10898 ret
.original_type
= TREE_TYPE (expr
);
10899 ret
.value
= build1 (TRANSACTION_EXPR
, ret
.original_type
, expr
);
10900 if (this_in
& TM_STMT_ATTR_RELAXED
)
10901 TRANSACTION_EXPR_RELAXED (ret
.value
) = 1;
10902 SET_EXPR_LOCATION (ret
.value
, loc
);
10903 ret
.original_code
= TRANSACTION_EXPR
;
10904 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
10906 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
10913 ret
.value
= error_mark_node
;
10914 ret
.original_code
= ERROR_MARK
;
10915 ret
.original_type
= NULL
;
10917 parser
->in_transaction
= old_in
;
10920 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
10921 "%<__transaction_atomic%> without transactional memory support enabled"
10922 : "%<__transaction_relaxed %> "
10923 "without transactional memory support enabled"));
10928 /* Parse a __transaction_cancel statement (GCC Extension).
10930 transaction-cancel-statement:
10931 __transaction_cancel transaction-attribute[opt] ;
10933 Note that the only valid attribute is "outer".
10937 c_parser_transaction_cancel(c_parser
*parser
)
10939 location_t loc
= c_parser_peek_token (parser
)->location
;
10941 bool is_outer
= false;
10943 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TRANSACTION_CANCEL
));
10944 c_parser_consume_token (parser
);
10946 attrs
= c_parser_transaction_attributes (parser
);
10948 is_outer
= (parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
) != 0);
10952 error_at (loc
, "%<__transaction_cancel%> without "
10953 "transactional memory support enabled");
10956 else if (parser
->in_transaction
& TM_STMT_ATTR_RELAXED
)
10958 error_at (loc
, "%<__transaction_cancel%> within a "
10959 "%<__transaction_relaxed%>");
10964 if ((parser
->in_transaction
& TM_STMT_ATTR_OUTER
) == 0
10965 && !is_tm_may_cancel_outer (current_function_decl
))
10967 error_at (loc
, "outer %<__transaction_cancel%> not "
10968 "within outer %<__transaction_atomic%>");
10969 error_at (loc
, " or a %<transaction_may_cancel_outer%> function");
10973 else if (parser
->in_transaction
== 0)
10975 error_at (loc
, "%<__transaction_cancel%> not within "
10976 "%<__transaction_atomic%>");
10980 return add_stmt (build_tm_abort_call (loc
, is_outer
));
10983 return build1 (NOP_EXPR
, void_type_node
, error_mark_node
);
10986 /* Parse a single source file. */
10989 c_parse_file (void)
10991 /* Use local storage to begin. If the first token is a pragma, parse it.
10992 If it is #pragma GCC pch_preprocess, then this will load a PCH file
10993 which will cause garbage collection. */
10996 memset (&tparser
, 0, sizeof tparser
);
10997 the_parser
= &tparser
;
10999 if (c_parser_peek_token (&tparser
)->pragma_kind
== PRAGMA_GCC_PCH_PREPROCESS
)
11000 c_parser_pragma_pch_preprocess (&tparser
);
11002 the_parser
= ggc_alloc_c_parser ();
11003 *the_parser
= tparser
;
11005 /* Initialize EH, if we've been told to do so. */
11006 if (flag_exceptions
)
11007 using_eh_for_cleanups ();
11009 c_parser_translation_unit (the_parser
);
11013 /* This function parses Cilk Plus array notation. The starting index is
11014 passed in INITIAL_INDEX and the array name is passes in ARRAY_VALUE. The
11015 return value of this function is a tree_node called VALUE_TREE of type
11016 ARRAY_NOTATION_REF. */
11019 c_parser_array_notation (location_t loc
, c_parser
*parser
, tree initial_index
,
11022 c_token
*token
= NULL
;
11023 tree start_index
= NULL_TREE
, end_index
= NULL_TREE
, stride
= NULL_TREE
;
11024 tree value_tree
= NULL_TREE
, type
= NULL_TREE
, array_type
= NULL_TREE
;
11025 tree array_type_domain
= NULL_TREE
;
11027 if (array_value
== error_mark_node
)
11029 /* No need to continue. If either of these 2 were true, then an error
11030 must be emitted already. Thus, no need to emit them twice. */
11031 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
11032 return error_mark_node
;
11035 array_type
= TREE_TYPE (array_value
);
11036 gcc_assert (array_type
);
11037 type
= TREE_TYPE (array_type
);
11038 token
= c_parser_peek_token (parser
);
11040 if (token
->type
== CPP_EOF
)
11042 c_parser_error (parser
, "expected %<:%> or numeral");
11045 else if (token
->type
== CPP_COLON
)
11047 if (!initial_index
)
11049 /* If we are here, then we have a case like this A[:]. */
11050 c_parser_consume_token (parser
);
11051 if (TREE_CODE (array_type
) == POINTER_TYPE
)
11053 error_at (loc
, "start-index and length fields necessary for "
11054 "using array notations in pointers");
11055 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
11056 return error_mark_node
;
11058 if (TREE_CODE (array_type
) == FUNCTION_TYPE
)
11060 error_at (loc
, "array notations cannot be used with function "
11062 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
11063 return error_mark_node
;
11065 if (TREE_CODE (array_type
) == ARRAY_TYPE
)
11067 tree subtype
= TREE_TYPE (array_type
);
11068 while (subtype
&& TREE_CODE (subtype
) == POINTER_TYPE
)
11070 /* Now this could be a function pointer. Find them and
11071 give out an error. */
11072 subtype
= TREE_TYPE (subtype
);
11073 if (subtype
&& TREE_CODE (subtype
) == FUNCTION_TYPE
)
11075 error_at (loc
, "array notations cannot be used with "
11076 "function pointer arrays");
11077 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
11079 return error_mark_node
;
11083 array_type_domain
= TYPE_DOMAIN (array_type
);
11085 if (!array_type_domain
)
11087 error_at (loc
, "start-index and length fields necessary for "
11088 "using array notations in dimensionless arrays");
11089 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
11090 return error_mark_node
;
11093 start_index
= TYPE_MINVAL (array_type_domain
);
11094 start_index
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
,
11096 if (!TYPE_MAXVAL (array_type_domain
)
11097 || !TREE_CONSTANT (TYPE_MAXVAL (array_type_domain
)))
11099 error_at (loc
, "start-index and length fields necessary for "
11100 "using array notations in variable-length arrays");
11101 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
11102 return error_mark_node
;
11104 end_index
= TYPE_MAXVAL (array_type_domain
);
11105 end_index
= fold_build2 (PLUS_EXPR
, TREE_TYPE (end_index
),
11106 end_index
, integer_one_node
);
11107 end_index
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
, end_index
);
11108 stride
= build_int_cst (integer_type_node
, 1);
11109 stride
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
, stride
);
11111 else if (initial_index
!= error_mark_node
)
11113 /* If we are here, then there should be 2 possibilities:
11114 1. Array [EXPR : EXPR]
11115 2. Array [EXPR : EXPR : EXPR]
11117 start_index
= initial_index
;
11119 if (TREE_CODE (array_type
) == FUNCTION_TYPE
)
11121 error_at (loc
, "array notations cannot be used with function "
11123 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
11124 return error_mark_node
;
11126 if (TREE_CODE (array_type
) == ARRAY_TYPE
11127 || TREE_CODE (array_type
) == POINTER_TYPE
)
11129 tree subtype
= TREE_TYPE (array_type
);
11131 && (TREE_CODE (subtype
) == POINTER_TYPE
11132 || TREE_CODE (subtype
) == ARRAY_TYPE
))
11134 /* Now this could be a function pointer. Find them and
11135 give out an error. */
11136 subtype
= TREE_TYPE (subtype
);
11137 if (subtype
&& TREE_CODE (subtype
) == FUNCTION_TYPE
)
11139 error_at (loc
, "array notations cannot be used with "
11140 "function pointer arrays");
11141 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
11143 return error_mark_node
;
11147 c_parser_consume_token (parser
); /* consume the ':' */
11148 end_index
= c_parser_expression (parser
).value
;
11149 if (!end_index
|| end_index
== error_mark_node
)
11151 c_parser_skip_to_end_of_block_or_statement (parser
);
11152 return error_mark_node
;
11154 if (c_parser_peek_token (parser
)->type
== CPP_COLON
)
11156 c_parser_consume_token (parser
);
11157 stride
= c_parser_expression (parser
).value
;
11158 if (!stride
|| stride
== error_mark_node
)
11160 c_parser_skip_to_end_of_block_or_statement (parser
);
11161 return error_mark_node
;
11166 c_parser_error (parser
, "expected array notation expression");
11169 c_parser_error (parser
, "expected array notation expression");
11171 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
11173 value_tree
= build_array_notation_ref (loc
, array_value
, start_index
,
11174 end_index
, stride
, type
);
11175 if (value_tree
!= error_mark_node
)
11176 SET_EXPR_LOCATION (value_tree
, loc
);
11180 #include "gt-c-c-parser.h"