1 /* Parser for C and Objective-C.
2 Copyright (C) 1987-2013 Free Software Foundation, Inc.
4 Parser actions based on the old Bison parser; structure somewhat
5 influenced by and fragments based on the C++ parser.
7 This file is part of GCC.
9 GCC is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free
11 Software Foundation; either version 3, or (at your option) any later
14 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING3. If not see
21 <http://www.gnu.org/licenses/>. */
25 Make sure all relevant comments, and all relevant code from all
26 actions, brought over from old parser. Verify exact correspondence
29 Add testcases covering every input symbol in every state in old and
32 Include full syntax for GNU C, including erroneous cases accepted
33 with error messages, in syntax productions in comments.
35 Make more diagnostics in the front end generally take an explicit
36 location rather than implicitly using input_location. */
40 #include "coretypes.h"
41 #include "tm.h" /* For rtl.h: needs enum reg_class. */
43 #include "langhooks.h"
47 #include "c-family/c-pragma.h"
51 #include "c-family/c-common.h"
52 #include "c-family/c-objc.h"
59 /* Initialization routine for this file. */
64 /* The only initialization required is of the reserved word
70 /* Make sure RID_MAX hasn't grown past the 8 bits used to hold the keyword in
71 the c_token structure. */
72 gcc_assert (RID_MAX
<= 255);
79 mask
|= D_ASM
| D_EXT
;
83 if (!c_dialect_objc ())
84 mask
|= D_OBJC
| D_CXX_OBJC
;
86 ridpointers
= ggc_alloc_cleared_vec_tree ((int) RID_MAX
);
87 for (i
= 0; i
< num_c_common_reswords
; i
++)
89 /* If a keyword is disabled, do not enter it into the table
90 and so create a canonical spelling that isn't a keyword. */
91 if (c_common_reswords
[i
].disable
& mask
)
94 && (c_common_reswords
[i
].disable
& D_CXXWARN
))
96 id
= get_identifier (c_common_reswords
[i
].word
);
97 C_SET_RID_CODE (id
, RID_CXX_COMPAT_WARN
);
98 C_IS_RESERVED_WORD (id
) = 1;
103 id
= get_identifier (c_common_reswords
[i
].word
);
104 C_SET_RID_CODE (id
, c_common_reswords
[i
].rid
);
105 C_IS_RESERVED_WORD (id
) = 1;
106 ridpointers
[(int) c_common_reswords
[i
].rid
] = id
;
110 /* The C lexer intermediates between the lexer in cpplib and c-lex.c
111 and the C parser. Unlike the C++ lexer, the parser structure
112 stores the lexer information instead of using a separate structure.
113 Identifiers are separated into ordinary identifiers, type names,
114 keywords and some other Objective-C types of identifiers, and some
115 look-ahead is maintained.
117 ??? It might be a good idea to lex the whole file up front (as for
118 C++). It would then be possible to share more of the C and C++
119 lexer code, if desired. */
121 /* The following local token type is used. */
124 #define CPP_KEYWORD ((enum cpp_ttype) (N_TTYPES + 1))
126 /* More information about the type of a CPP_NAME token. */
127 typedef enum c_id_kind
{
128 /* An ordinary identifier. */
130 /* An identifier declared as a typedef name. */
132 /* An identifier declared as an Objective-C class name. */
134 /* An address space identifier. */
136 /* Not an identifier. */
140 /* A single C token after string literal concatenation and conversion
141 of preprocessing tokens to tokens. */
142 typedef struct GTY (()) c_token
{
143 /* The kind of token. */
144 ENUM_BITFIELD (cpp_ttype
) type
: 8;
145 /* If this token is a CPP_NAME, this value indicates whether also
146 declared as some kind of type. Otherwise, it is C_ID_NONE. */
147 ENUM_BITFIELD (c_id_kind
) id_kind
: 8;
148 /* If this token is a keyword, this value indicates which keyword.
149 Otherwise, this value is RID_MAX. */
150 ENUM_BITFIELD (rid
) keyword
: 8;
151 /* If this token is a CPP_PRAGMA, this indicates the pragma that
152 was seen. Otherwise it is PRAGMA_NONE. */
153 ENUM_BITFIELD (pragma_kind
) pragma_kind
: 8;
154 /* The location at which this token was found. */
156 /* The value associated with this token, if any. */
160 /* A parser structure recording information about the state and
161 context of parsing. Includes lexer information with up to two
162 tokens of look-ahead; more are not needed for C. */
163 typedef struct GTY(()) c_parser
{
164 /* The look-ahead tokens. */
166 /* How many look-ahead tokens are available (0, 1 or 2). */
168 /* True if a syntax error is being recovered from; false otherwise.
169 c_parser_error sets this flag. It should clear this flag when
170 enough tokens have been consumed to recover from the error. */
171 BOOL_BITFIELD error
: 1;
172 /* True if we're processing a pragma, and shouldn't automatically
173 consume CPP_PRAGMA_EOL. */
174 BOOL_BITFIELD in_pragma
: 1;
175 /* True if we're parsing the outermost block of an if statement. */
176 BOOL_BITFIELD in_if_block
: 1;
177 /* True if we want to lex an untranslated string. */
178 BOOL_BITFIELD lex_untranslated_string
: 1;
180 /* Objective-C specific parser/lexer information. */
182 /* True if we are in a context where the Objective-C "PQ" keywords
183 are considered keywords. */
184 BOOL_BITFIELD objc_pq_context
: 1;
185 /* True if we are parsing a (potential) Objective-C foreach
186 statement. This is set to true after we parsed 'for (' and while
187 we wait for 'in' or ';' to decide if it's a standard C for loop or an
188 Objective-C foreach loop. */
189 BOOL_BITFIELD objc_could_be_foreach_context
: 1;
190 /* The following flag is needed to contextualize Objective-C lexical
191 analysis. In some cases (e.g., 'int NSObject;'), it is
192 undesirable to bind an identifier to an Objective-C class, even
193 if a class with that name exists. */
194 BOOL_BITFIELD objc_need_raw_identifier
: 1;
195 /* Nonzero if we're processing a __transaction statement. The value
196 is 1 | TM_STMT_ATTR_*. */
197 unsigned int in_transaction
: 4;
198 /* True if we are in a context where the Objective-C "Property attribute"
199 keywords are valid. */
200 BOOL_BITFIELD objc_property_attr_context
: 1;
204 /* The actual parser and external interface. ??? Does this need to be
205 garbage-collected? */
207 static GTY (()) c_parser
*the_parser
;
209 /* Read in and lex a single token, storing it in *TOKEN. */
212 c_lex_one_token (c_parser
*parser
, c_token
*token
)
214 timevar_push (TV_LEX
);
216 token
->type
= c_lex_with_flags (&token
->value
, &token
->location
, NULL
,
217 (parser
->lex_untranslated_string
218 ? C_LEX_STRING_NO_TRANSLATE
: 0));
219 token
->id_kind
= C_ID_NONE
;
220 token
->keyword
= RID_MAX
;
221 token
->pragma_kind
= PRAGMA_NONE
;
229 bool objc_force_identifier
= parser
->objc_need_raw_identifier
;
230 if (c_dialect_objc ())
231 parser
->objc_need_raw_identifier
= false;
233 if (C_IS_RESERVED_WORD (token
->value
))
235 enum rid rid_code
= C_RID_CODE (token
->value
);
237 if (rid_code
== RID_CXX_COMPAT_WARN
)
239 warning_at (token
->location
,
241 "identifier %qE conflicts with C++ keyword",
244 else if (rid_code
>= RID_FIRST_ADDR_SPACE
245 && rid_code
<= RID_LAST_ADDR_SPACE
)
247 token
->id_kind
= C_ID_ADDRSPACE
;
248 token
->keyword
= rid_code
;
251 else if (c_dialect_objc () && OBJC_IS_PQ_KEYWORD (rid_code
))
253 /* We found an Objective-C "pq" keyword (in, out,
254 inout, bycopy, byref, oneway). They need special
255 care because the interpretation depends on the
257 if (parser
->objc_pq_context
)
259 token
->type
= CPP_KEYWORD
;
260 token
->keyword
= rid_code
;
263 else if (parser
->objc_could_be_foreach_context
264 && rid_code
== RID_IN
)
266 /* We are in Objective-C, inside a (potential)
267 foreach context (which means after having
268 parsed 'for (', but before having parsed ';'),
269 and we found 'in'. We consider it the keyword
270 which terminates the declaration at the
271 beginning of a foreach-statement. Note that
272 this means you can't use 'in' for anything else
273 in that context; in particular, in Objective-C
274 you can't use 'in' as the name of the running
275 variable in a C for loop. We could potentially
276 try to add code here to disambiguate, but it
277 seems a reasonable limitation. */
278 token
->type
= CPP_KEYWORD
;
279 token
->keyword
= rid_code
;
282 /* Else, "pq" keywords outside of the "pq" context are
283 not keywords, and we fall through to the code for
286 else if (c_dialect_objc () && OBJC_IS_PATTR_KEYWORD (rid_code
))
288 /* We found an Objective-C "property attribute"
289 keyword (getter, setter, readonly, etc). These are
290 only valid in the property context. */
291 if (parser
->objc_property_attr_context
)
293 token
->type
= CPP_KEYWORD
;
294 token
->keyword
= rid_code
;
297 /* Else they are not special keywords.
300 else if (c_dialect_objc ()
301 && (OBJC_IS_AT_KEYWORD (rid_code
)
302 || OBJC_IS_CXX_KEYWORD (rid_code
)))
304 /* We found one of the Objective-C "@" keywords (defs,
305 selector, synchronized, etc) or one of the
306 Objective-C "cxx" keywords (class, private,
307 protected, public, try, catch, throw) without a
308 preceding '@' sign. Do nothing and fall through to
309 the code for normal tokens (in C++ we would still
310 consider the CXX ones keywords, but not in C). */
315 token
->type
= CPP_KEYWORD
;
316 token
->keyword
= rid_code
;
321 decl
= lookup_name (token
->value
);
324 if (TREE_CODE (decl
) == TYPE_DECL
)
326 token
->id_kind
= C_ID_TYPENAME
;
330 else if (c_dialect_objc ())
332 tree objc_interface_decl
= objc_is_class_name (token
->value
);
333 /* Objective-C class names are in the same namespace as
334 variables and typedefs, and hence are shadowed by local
336 if (objc_interface_decl
337 && (!objc_force_identifier
|| global_bindings_p ()))
339 token
->value
= objc_interface_decl
;
340 token
->id_kind
= C_ID_CLASSNAME
;
344 token
->id_kind
= C_ID_ID
;
348 /* This only happens in Objective-C; it must be a keyword. */
349 token
->type
= CPP_KEYWORD
;
350 switch (C_RID_CODE (token
->value
))
352 /* Replace 'class' with '@class', 'private' with '@private',
353 etc. This prevents confusion with the C++ keyword
354 'class', and makes the tokens consistent with other
355 Objective-C 'AT' keywords. For example '@class' is
356 reported as RID_AT_CLASS which is consistent with
357 '@synchronized', which is reported as
360 case RID_CLASS
: token
->keyword
= RID_AT_CLASS
; break;
361 case RID_PRIVATE
: token
->keyword
= RID_AT_PRIVATE
; break;
362 case RID_PROTECTED
: token
->keyword
= RID_AT_PROTECTED
; break;
363 case RID_PUBLIC
: token
->keyword
= RID_AT_PUBLIC
; break;
364 case RID_THROW
: token
->keyword
= RID_AT_THROW
; break;
365 case RID_TRY
: token
->keyword
= RID_AT_TRY
; break;
366 case RID_CATCH
: token
->keyword
= RID_AT_CATCH
; break;
367 default: token
->keyword
= C_RID_CODE (token
->value
);
372 case CPP_CLOSE_PAREN
:
374 /* These tokens may affect the interpretation of any identifiers
375 following, if doing Objective-C. */
376 if (c_dialect_objc ())
377 parser
->objc_need_raw_identifier
= false;
380 /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */
381 token
->pragma_kind
= (enum pragma_kind
) TREE_INT_CST_LOW (token
->value
);
387 timevar_pop (TV_LEX
);
390 /* Return a pointer to the next token from PARSER, reading it in if
393 static inline c_token
*
394 c_parser_peek_token (c_parser
*parser
)
396 if (parser
->tokens_avail
== 0)
398 c_lex_one_token (parser
, &parser
->tokens
[0]);
399 parser
->tokens_avail
= 1;
401 return &parser
->tokens
[0];
404 /* Return true if the next token from PARSER has the indicated
408 c_parser_next_token_is (c_parser
*parser
, enum cpp_ttype type
)
410 return c_parser_peek_token (parser
)->type
== type
;
413 /* Return true if the next token from PARSER does not have the
417 c_parser_next_token_is_not (c_parser
*parser
, enum cpp_ttype type
)
419 return !c_parser_next_token_is (parser
, type
);
422 /* Return true if the next token from PARSER is the indicated
426 c_parser_next_token_is_keyword (c_parser
*parser
, enum rid keyword
)
428 return c_parser_peek_token (parser
)->keyword
== keyword
;
431 /* Return a pointer to the next-but-one token from PARSER, reading it
432 in if necessary. The next token is already read in. */
435 c_parser_peek_2nd_token (c_parser
*parser
)
437 if (parser
->tokens_avail
>= 2)
438 return &parser
->tokens
[1];
439 gcc_assert (parser
->tokens_avail
== 1);
440 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
441 gcc_assert (parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
442 c_lex_one_token (parser
, &parser
->tokens
[1]);
443 parser
->tokens_avail
= 2;
444 return &parser
->tokens
[1];
447 /* Return true if TOKEN can start a type name,
450 c_token_starts_typename (c_token
*token
)
455 switch (token
->id_kind
)
464 gcc_assert (c_dialect_objc ());
470 switch (token
->keyword
)
503 if (c_dialect_objc ())
511 enum c_lookahead_kind
{
512 /* Always treat unknown identifiers as typenames. */
515 /* Could be parsing a nonabstract declarator. Only treat an identifier
516 as a typename if followed by another identifier or a star. */
517 cla_nonabstract_decl
,
519 /* Never treat identifiers as typenames. */
523 /* Return true if the next token from PARSER can start a type name,
524 false otherwise. LA specifies how to do lookahead in order to
525 detect unknown type names. If unsure, pick CLA_PREFER_ID. */
528 c_parser_next_tokens_start_typename (c_parser
*parser
, enum c_lookahead_kind la
)
530 c_token
*token
= c_parser_peek_token (parser
);
531 if (c_token_starts_typename (token
))
534 /* Try a bit harder to detect an unknown typename. */
535 if (la
!= cla_prefer_id
536 && token
->type
== CPP_NAME
537 && token
->id_kind
== C_ID_ID
539 /* Do not try too hard when we could have "object in array". */
540 && !parser
->objc_could_be_foreach_context
542 && (la
== cla_prefer_type
543 || c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
544 || c_parser_peek_2nd_token (parser
)->type
== CPP_MULT
)
546 /* Only unknown identifiers. */
547 && !lookup_name (token
->value
))
553 /* Return true if TOKEN is a type qualifier, false otherwise. */
555 c_token_is_qualifier (c_token
*token
)
560 switch (token
->id_kind
)
568 switch (token
->keyword
)
585 /* Return true if the next token from PARSER is a type qualifier,
588 c_parser_next_token_is_qualifier (c_parser
*parser
)
590 c_token
*token
= c_parser_peek_token (parser
);
591 return c_token_is_qualifier (token
);
594 /* Return true if TOKEN can start declaration specifiers, false
597 c_token_starts_declspecs (c_token
*token
)
602 switch (token
->id_kind
)
611 gcc_assert (c_dialect_objc ());
617 switch (token
->keyword
)
659 if (c_dialect_objc ())
668 /* Return true if TOKEN can start declaration specifiers or a static
669 assertion, false otherwise. */
671 c_token_starts_declaration (c_token
*token
)
673 if (c_token_starts_declspecs (token
)
674 || token
->keyword
== RID_STATIC_ASSERT
)
680 /* Return true if the next token from PARSER can start declaration
681 specifiers, false otherwise. */
683 c_parser_next_token_starts_declspecs (c_parser
*parser
)
685 c_token
*token
= c_parser_peek_token (parser
);
687 /* In Objective-C, a classname normally starts a declspecs unless it
688 is immediately followed by a dot. In that case, it is the
689 Objective-C 2.0 "dot-syntax" for class objects, ie, calls the
690 setter/getter on the class. c_token_starts_declspecs() can't
691 differentiate between the two cases because it only checks the
692 current token, so we have a special check here. */
693 if (c_dialect_objc ()
694 && token
->type
== CPP_NAME
695 && token
->id_kind
== C_ID_CLASSNAME
696 && c_parser_peek_2nd_token (parser
)->type
== CPP_DOT
)
699 return c_token_starts_declspecs (token
);
702 /* Return true if the next tokens from PARSER can start declaration
703 specifiers or a static assertion, false otherwise. */
705 c_parser_next_tokens_start_declaration (c_parser
*parser
)
707 c_token
*token
= c_parser_peek_token (parser
);
710 if (c_dialect_objc ()
711 && token
->type
== CPP_NAME
712 && token
->id_kind
== C_ID_CLASSNAME
713 && c_parser_peek_2nd_token (parser
)->type
== CPP_DOT
)
716 /* Labels do not start declarations. */
717 if (token
->type
== CPP_NAME
718 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
721 if (c_token_starts_declaration (token
))
724 if (c_parser_next_tokens_start_typename (parser
, cla_nonabstract_decl
))
730 /* Consume the next token from PARSER. */
733 c_parser_consume_token (c_parser
*parser
)
735 gcc_assert (parser
->tokens_avail
>= 1);
736 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
737 gcc_assert (!parser
->in_pragma
|| parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
738 gcc_assert (parser
->error
|| parser
->tokens
[0].type
!= CPP_PRAGMA
);
739 if (parser
->tokens_avail
== 2)
740 parser
->tokens
[0] = parser
->tokens
[1];
741 parser
->tokens_avail
--;
744 /* Expect the current token to be a #pragma. Consume it and remember
745 that we've begun parsing a pragma. */
748 c_parser_consume_pragma (c_parser
*parser
)
750 gcc_assert (!parser
->in_pragma
);
751 gcc_assert (parser
->tokens_avail
>= 1);
752 gcc_assert (parser
->tokens
[0].type
== CPP_PRAGMA
);
753 if (parser
->tokens_avail
== 2)
754 parser
->tokens
[0] = parser
->tokens
[1];
755 parser
->tokens_avail
--;
756 parser
->in_pragma
= true;
759 /* Update the globals input_location and in_system_header from
762 c_parser_set_source_position_from_token (c_token
*token
)
764 if (token
->type
!= CPP_EOF
)
766 input_location
= token
->location
;
770 /* Issue a diagnostic of the form
771 FILE:LINE: MESSAGE before TOKEN
772 where TOKEN is the next token in the input stream of PARSER.
773 MESSAGE (specified by the caller) is usually of the form "expected
776 Do not issue a diagnostic if still recovering from an error.
778 ??? This is taken from the C++ parser, but building up messages in
779 this way is not i18n-friendly and some other approach should be
783 c_parser_error (c_parser
*parser
, const char *gmsgid
)
785 c_token
*token
= c_parser_peek_token (parser
);
788 parser
->error
= true;
791 /* This diagnostic makes more sense if it is tagged to the line of
792 the token we just peeked at. */
793 c_parser_set_source_position_from_token (token
);
794 c_parse_error (gmsgid
,
795 /* Because c_parse_error does not understand
796 CPP_KEYWORD, keywords are treated like
798 (token
->type
== CPP_KEYWORD
? CPP_NAME
: token
->type
),
799 /* ??? The C parser does not save the cpp flags of a
800 token, we need to pass 0 here and we will not get
801 the source spelling of some tokens but rather the
802 canonical spelling. */
803 token
->value
, /*flags=*/0);
806 /* If the next token is of the indicated TYPE, consume it. Otherwise,
807 issue the error MSGID. If MSGID is NULL then a message has already
808 been produced and no message will be produced this time. Returns
809 true if found, false otherwise. */
812 c_parser_require (c_parser
*parser
,
816 if (c_parser_next_token_is (parser
, type
))
818 c_parser_consume_token (parser
);
823 c_parser_error (parser
, msgid
);
828 /* If the next token is the indicated keyword, consume it. Otherwise,
829 issue the error MSGID. Returns true if found, false otherwise. */
832 c_parser_require_keyword (c_parser
*parser
,
836 if (c_parser_next_token_is_keyword (parser
, keyword
))
838 c_parser_consume_token (parser
);
843 c_parser_error (parser
, msgid
);
848 /* Like c_parser_require, except that tokens will be skipped until the
849 desired token is found. An error message is still produced if the
850 next token is not as expected. If MSGID is NULL then a message has
851 already been produced and no message will be produced this
855 c_parser_skip_until_found (c_parser
*parser
,
859 unsigned nesting_depth
= 0;
861 if (c_parser_require (parser
, type
, msgid
))
864 /* Skip tokens until the desired token is found. */
867 /* Peek at the next token. */
868 c_token
*token
= c_parser_peek_token (parser
);
869 /* If we've reached the token we want, consume it and stop. */
870 if (token
->type
== type
&& !nesting_depth
)
872 c_parser_consume_token (parser
);
876 /* If we've run out of tokens, stop. */
877 if (token
->type
== CPP_EOF
)
879 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
881 if (token
->type
== CPP_OPEN_BRACE
882 || token
->type
== CPP_OPEN_PAREN
883 || token
->type
== CPP_OPEN_SQUARE
)
885 else if (token
->type
== CPP_CLOSE_BRACE
886 || token
->type
== CPP_CLOSE_PAREN
887 || token
->type
== CPP_CLOSE_SQUARE
)
889 if (nesting_depth
-- == 0)
892 /* Consume this token. */
893 c_parser_consume_token (parser
);
895 parser
->error
= false;
898 /* Skip tokens until the end of a parameter is found, but do not
899 consume the comma, semicolon or closing delimiter. */
902 c_parser_skip_to_end_of_parameter (c_parser
*parser
)
904 unsigned nesting_depth
= 0;
908 c_token
*token
= c_parser_peek_token (parser
);
909 if ((token
->type
== CPP_COMMA
|| token
->type
== CPP_SEMICOLON
)
912 /* If we've run out of tokens, stop. */
913 if (token
->type
== CPP_EOF
)
915 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
917 if (token
->type
== CPP_OPEN_BRACE
918 || token
->type
== CPP_OPEN_PAREN
919 || token
->type
== CPP_OPEN_SQUARE
)
921 else if (token
->type
== CPP_CLOSE_BRACE
922 || token
->type
== CPP_CLOSE_PAREN
923 || token
->type
== CPP_CLOSE_SQUARE
)
925 if (nesting_depth
-- == 0)
928 /* Consume this token. */
929 c_parser_consume_token (parser
);
931 parser
->error
= false;
934 /* Expect to be at the end of the pragma directive and consume an
935 end of line marker. */
938 c_parser_skip_to_pragma_eol (c_parser
*parser
)
940 gcc_assert (parser
->in_pragma
);
941 parser
->in_pragma
= false;
943 if (!c_parser_require (parser
, CPP_PRAGMA_EOL
, "expected end of line"))
946 c_token
*token
= c_parser_peek_token (parser
);
947 if (token
->type
== CPP_EOF
)
949 if (token
->type
== CPP_PRAGMA_EOL
)
951 c_parser_consume_token (parser
);
954 c_parser_consume_token (parser
);
957 parser
->error
= false;
960 /* Skip tokens until we have consumed an entire block, or until we
961 have consumed a non-nested ';'. */
964 c_parser_skip_to_end_of_block_or_statement (c_parser
*parser
)
966 unsigned nesting_depth
= 0;
967 bool save_error
= parser
->error
;
973 /* Peek at the next token. */
974 token
= c_parser_peek_token (parser
);
982 if (parser
->in_pragma
)
987 /* If the next token is a ';', we have reached the
988 end of the statement. */
991 /* Consume the ';'. */
992 c_parser_consume_token (parser
);
997 case CPP_CLOSE_BRACE
:
998 /* If the next token is a non-nested '}', then we have
999 reached the end of the current block. */
1000 if (nesting_depth
== 0 || --nesting_depth
== 0)
1002 c_parser_consume_token (parser
);
1007 case CPP_OPEN_BRACE
:
1008 /* If it the next token is a '{', then we are entering a new
1009 block. Consume the entire block. */
1014 /* If we see a pragma, consume the whole thing at once. We
1015 have some safeguards against consuming pragmas willy-nilly.
1016 Normally, we'd expect to be here with parser->error set,
1017 which disables these safeguards. But it's possible to get
1018 here for secondary error recovery, after parser->error has
1020 c_parser_consume_pragma (parser
);
1021 c_parser_skip_to_pragma_eol (parser
);
1022 parser
->error
= save_error
;
1029 c_parser_consume_token (parser
);
1033 parser
->error
= false;
1036 /* CPP's options (initialized by c-opts.c). */
1037 extern cpp_options
*cpp_opts
;
1039 /* Save the warning flags which are controlled by __extension__. */
1042 disable_extension_diagnostics (void)
1045 | (warn_pointer_arith
<< 1)
1046 | (warn_traditional
<< 2)
1048 | (warn_long_long
<< 4)
1049 | (warn_cxx_compat
<< 5)
1050 | (warn_overlength_strings
<< 6));
1051 cpp_opts
->cpp_pedantic
= pedantic
= 0;
1052 warn_pointer_arith
= 0;
1053 cpp_opts
->cpp_warn_traditional
= warn_traditional
= 0;
1055 cpp_opts
->cpp_warn_long_long
= warn_long_long
= 0;
1056 warn_cxx_compat
= 0;
1057 warn_overlength_strings
= 0;
1061 /* Restore the warning flags which are controlled by __extension__.
1062 FLAGS is the return value from disable_extension_diagnostics. */
1065 restore_extension_diagnostics (int flags
)
1067 cpp_opts
->cpp_pedantic
= pedantic
= flags
& 1;
1068 warn_pointer_arith
= (flags
>> 1) & 1;
1069 cpp_opts
->cpp_warn_traditional
= warn_traditional
= (flags
>> 2) & 1;
1070 flag_iso
= (flags
>> 3) & 1;
1071 cpp_opts
->cpp_warn_long_long
= warn_long_long
= (flags
>> 4) & 1;
1072 warn_cxx_compat
= (flags
>> 5) & 1;
1073 warn_overlength_strings
= (flags
>> 6) & 1;
1076 /* Possibly kinds of declarator to parse. */
1077 typedef enum c_dtr_syn
{
1078 /* A normal declarator with an identifier. */
1080 /* An abstract declarator (maybe empty). */
1082 /* A parameter declarator: may be either, but after a type name does
1083 not redeclare a typedef name as an identifier if it can
1084 alternatively be interpreted as a typedef name; see DR#009,
1085 applied in C90 TC1, omitted from C99 and reapplied in C99 TC2
1086 following DR#249. For example, given a typedef T, "int T" and
1087 "int *T" are valid parameter declarations redeclaring T, while
1088 "int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are
1089 abstract declarators rather than involving redundant parentheses;
1090 the same applies with attributes inside the parentheses before
1095 /* The binary operation precedence levels, where 0 is a dummy lowest level
1096 used for the bottom of the stack. */
1097 enum c_parser_prec
{
1112 static void c_parser_external_declaration (c_parser
*);
1113 static void c_parser_asm_definition (c_parser
*);
1114 static void c_parser_declaration_or_fndef (c_parser
*, bool, bool, bool,
1115 bool, bool, tree
*);
1116 static void c_parser_static_assert_declaration_no_semi (c_parser
*);
1117 static void c_parser_static_assert_declaration (c_parser
*);
1118 static void c_parser_declspecs (c_parser
*, struct c_declspecs
*, bool, bool,
1119 bool, enum c_lookahead_kind
);
1120 static struct c_typespec
c_parser_enum_specifier (c_parser
*);
1121 static struct c_typespec
c_parser_struct_or_union_specifier (c_parser
*);
1122 static tree
c_parser_struct_declaration (c_parser
*);
1123 static struct c_typespec
c_parser_typeof_specifier (c_parser
*);
1124 static tree
c_parser_alignas_specifier (c_parser
*);
1125 static struct c_declarator
*c_parser_declarator (c_parser
*, bool, c_dtr_syn
,
1127 static struct c_declarator
*c_parser_direct_declarator (c_parser
*, bool,
1129 static struct c_declarator
*c_parser_direct_declarator_inner (c_parser
*,
1131 struct c_declarator
*);
1132 static struct c_arg_info
*c_parser_parms_declarator (c_parser
*, bool, tree
);
1133 static struct c_arg_info
*c_parser_parms_list_declarator (c_parser
*, tree
,
1135 static struct c_parm
*c_parser_parameter_declaration (c_parser
*, tree
);
1136 static tree
c_parser_simple_asm_expr (c_parser
*);
1137 static tree
c_parser_attributes (c_parser
*);
1138 static struct c_type_name
*c_parser_type_name (c_parser
*);
1139 static struct c_expr
c_parser_initializer (c_parser
*);
1140 static struct c_expr
c_parser_braced_init (c_parser
*, tree
, bool);
1141 static void c_parser_initelt (c_parser
*, struct obstack
*);
1142 static void c_parser_initval (c_parser
*, struct c_expr
*,
1144 static tree
c_parser_compound_statement (c_parser
*);
1145 static void c_parser_compound_statement_nostart (c_parser
*);
1146 static void c_parser_label (c_parser
*);
1147 static void c_parser_statement (c_parser
*);
1148 static void c_parser_statement_after_labels (c_parser
*);
1149 static void c_parser_if_statement (c_parser
*);
1150 static void c_parser_switch_statement (c_parser
*);
1151 static void c_parser_while_statement (c_parser
*);
1152 static void c_parser_do_statement (c_parser
*);
1153 static void c_parser_for_statement (c_parser
*);
1154 static tree
c_parser_asm_statement (c_parser
*);
1155 static tree
c_parser_asm_operands (c_parser
*);
1156 static tree
c_parser_asm_goto_operands (c_parser
*);
1157 static tree
c_parser_asm_clobbers (c_parser
*);
1158 static struct c_expr
c_parser_expr_no_commas (c_parser
*, struct c_expr
*);
1159 static struct c_expr
c_parser_conditional_expression (c_parser
*,
1161 static struct c_expr
c_parser_binary_expression (c_parser
*, struct c_expr
*,
1162 enum c_parser_prec
);
1163 static struct c_expr
c_parser_cast_expression (c_parser
*, struct c_expr
*);
1164 static struct c_expr
c_parser_unary_expression (c_parser
*);
1165 static struct c_expr
c_parser_sizeof_expression (c_parser
*);
1166 static struct c_expr
c_parser_alignof_expression (c_parser
*);
1167 static struct c_expr
c_parser_postfix_expression (c_parser
*);
1168 static struct c_expr
c_parser_postfix_expression_after_paren_type (c_parser
*,
1169 struct c_type_name
*,
1171 static struct c_expr
c_parser_postfix_expression_after_primary (c_parser
*,
1174 static tree
c_parser_transaction (c_parser
*, enum rid
);
1175 static struct c_expr
c_parser_transaction_expression (c_parser
*, enum rid
);
1176 static tree
c_parser_transaction_cancel (c_parser
*);
1177 static struct c_expr
c_parser_expression (c_parser
*);
1178 static struct c_expr
c_parser_expression_conv (c_parser
*);
1179 static vec
<tree
, va_gc
> *c_parser_expr_list (c_parser
*, bool, bool,
1180 vec
<tree
, va_gc
> **, location_t
*,
1182 static void c_parser_omp_construct (c_parser
*);
1183 static void c_parser_omp_threadprivate (c_parser
*);
1184 static void c_parser_omp_barrier (c_parser
*);
1185 static void c_parser_omp_flush (c_parser
*);
1186 static void c_parser_omp_taskwait (c_parser
*);
1187 static void c_parser_omp_taskyield (c_parser
*);
1189 enum pragma_context
{ pragma_external
, pragma_stmt
, pragma_compound
};
1190 static bool c_parser_pragma (c_parser
*, enum pragma_context
);
1192 /* These Objective-C parser functions are only ever called when
1193 compiling Objective-C. */
1194 static void c_parser_objc_class_definition (c_parser
*, tree
);
1195 static void c_parser_objc_class_instance_variables (c_parser
*);
1196 static void c_parser_objc_class_declaration (c_parser
*);
1197 static void c_parser_objc_alias_declaration (c_parser
*);
1198 static void c_parser_objc_protocol_definition (c_parser
*, tree
);
1199 static bool c_parser_objc_method_type (c_parser
*);
1200 static void c_parser_objc_method_definition (c_parser
*);
1201 static void c_parser_objc_methodprotolist (c_parser
*);
1202 static void c_parser_objc_methodproto (c_parser
*);
1203 static tree
c_parser_objc_method_decl (c_parser
*, bool, tree
*, tree
*);
1204 static tree
c_parser_objc_type_name (c_parser
*);
1205 static tree
c_parser_objc_protocol_refs (c_parser
*);
1206 static void c_parser_objc_try_catch_finally_statement (c_parser
*);
1207 static void c_parser_objc_synchronized_statement (c_parser
*);
1208 static tree
c_parser_objc_selector (c_parser
*);
1209 static tree
c_parser_objc_selector_arg (c_parser
*);
1210 static tree
c_parser_objc_receiver (c_parser
*);
1211 static tree
c_parser_objc_message_args (c_parser
*);
1212 static tree
c_parser_objc_keywordexpr (c_parser
*);
1213 static void c_parser_objc_at_property_declaration (c_parser
*);
1214 static void c_parser_objc_at_synthesize_declaration (c_parser
*);
1215 static void c_parser_objc_at_dynamic_declaration (c_parser
*);
1216 static bool c_parser_objc_diagnose_bad_element_prefix
1217 (c_parser
*, struct c_declspecs
*);
1219 static tree
c_parser_array_notation (location_t
, c_parser
*, tree
, tree
);
1221 /* Parse a translation unit (C90 6.7, C99 6.9).
1224 external-declarations
1226 external-declarations:
1227 external-declaration
1228 external-declarations external-declaration
1237 c_parser_translation_unit (c_parser
*parser
)
1239 if (c_parser_next_token_is (parser
, CPP_EOF
))
1241 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
1242 "ISO C forbids an empty translation unit");
1246 void *obstack_position
= obstack_alloc (&parser_obstack
, 0);
1247 mark_valid_location_for_stdc_pragma (false);
1251 c_parser_external_declaration (parser
);
1252 obstack_free (&parser_obstack
, obstack_position
);
1254 while (c_parser_next_token_is_not (parser
, CPP_EOF
));
1258 /* Parse an external declaration (C90 6.7, C99 6.9).
1260 external-declaration:
1266 external-declaration:
1269 __extension__ external-declaration
1273 external-declaration:
1274 objc-class-definition
1275 objc-class-declaration
1276 objc-alias-declaration
1277 objc-protocol-definition
1278 objc-method-definition
1283 c_parser_external_declaration (c_parser
*parser
)
1286 switch (c_parser_peek_token (parser
)->type
)
1289 switch (c_parser_peek_token (parser
)->keyword
)
1292 ext
= disable_extension_diagnostics ();
1293 c_parser_consume_token (parser
);
1294 c_parser_external_declaration (parser
);
1295 restore_extension_diagnostics (ext
);
1298 c_parser_asm_definition (parser
);
1300 case RID_AT_INTERFACE
:
1301 case RID_AT_IMPLEMENTATION
:
1302 gcc_assert (c_dialect_objc ());
1303 c_parser_objc_class_definition (parser
, NULL_TREE
);
1306 gcc_assert (c_dialect_objc ());
1307 c_parser_objc_class_declaration (parser
);
1310 gcc_assert (c_dialect_objc ());
1311 c_parser_objc_alias_declaration (parser
);
1313 case RID_AT_PROTOCOL
:
1314 gcc_assert (c_dialect_objc ());
1315 c_parser_objc_protocol_definition (parser
, NULL_TREE
);
1317 case RID_AT_PROPERTY
:
1318 gcc_assert (c_dialect_objc ());
1319 c_parser_objc_at_property_declaration (parser
);
1321 case RID_AT_SYNTHESIZE
:
1322 gcc_assert (c_dialect_objc ());
1323 c_parser_objc_at_synthesize_declaration (parser
);
1325 case RID_AT_DYNAMIC
:
1326 gcc_assert (c_dialect_objc ());
1327 c_parser_objc_at_dynamic_declaration (parser
);
1330 gcc_assert (c_dialect_objc ());
1331 c_parser_consume_token (parser
);
1332 objc_finish_implementation ();
1339 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
1340 "ISO C does not allow extra %<;%> outside of a function");
1341 c_parser_consume_token (parser
);
1344 mark_valid_location_for_stdc_pragma (true);
1345 c_parser_pragma (parser
, pragma_external
);
1346 mark_valid_location_for_stdc_pragma (false);
1350 if (c_dialect_objc ())
1352 c_parser_objc_method_definition (parser
);
1355 /* Else fall through, and yield a syntax error trying to parse
1356 as a declaration or function definition. */
1359 /* A declaration or a function definition (or, in Objective-C,
1360 an @interface or @protocol with prefix attributes). We can
1361 only tell which after parsing the declaration specifiers, if
1362 any, and the first declarator. */
1363 c_parser_declaration_or_fndef (parser
, true, true, true, false, true, NULL
);
1368 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1369 6.7, 6.9.1). If FNDEF_OK is true, a function definition is
1370 accepted; otherwise (old-style parameter declarations) only other
1371 declarations are accepted. If STATIC_ASSERT_OK is true, a static
1372 assertion is accepted; otherwise (old-style parameter declarations)
1373 it is not. If NESTED is true, we are inside a function or parsing
1374 old-style parameter declarations; any functions encountered are
1375 nested functions and declaration specifiers are required; otherwise
1376 we are at top level and functions are normal functions and
1377 declaration specifiers may be optional. If EMPTY_OK is true, empty
1378 declarations are OK (subject to all other constraints); otherwise
1379 (old-style parameter declarations) they are diagnosed. If
1380 START_ATTR_OK is true, the declaration specifiers may start with
1381 attributes; otherwise they may not.
1382 OBJC_FOREACH_OBJECT_DECLARATION can be used to get back the parsed
1383 declaration when parsing an Objective-C foreach statement.
1386 declaration-specifiers init-declarator-list[opt] ;
1387 static_assert-declaration
1389 function-definition:
1390 declaration-specifiers[opt] declarator declaration-list[opt]
1395 declaration-list declaration
1397 init-declarator-list:
1399 init-declarator-list , init-declarator
1402 declarator simple-asm-expr[opt] attributes[opt]
1403 declarator simple-asm-expr[opt] attributes[opt] = initializer
1407 nested-function-definition:
1408 declaration-specifiers declarator declaration-list[opt]
1412 attributes objc-class-definition
1413 attributes objc-category-definition
1414 attributes objc-protocol-definition
1416 The simple-asm-expr and attributes are GNU extensions.
1418 This function does not handle __extension__; that is handled in its
1419 callers. ??? Following the old parser, __extension__ may start
1420 external declarations, declarations in functions and declarations
1421 at the start of "for" loops, but not old-style parameter
1424 C99 requires declaration specifiers in a function definition; the
1425 absence is diagnosed through the diagnosis of implicit int. In GNU
1426 C we also allow but diagnose declarations without declaration
1427 specifiers, but only at top level (elsewhere they conflict with
1430 In Objective-C, declarations of the looping variable in a foreach
1431 statement are exceptionally terminated by 'in' (for example, 'for
1432 (NSObject *object in array) { ... }').
1437 threadprivate-directive */
1440 c_parser_declaration_or_fndef (c_parser
*parser
, bool fndef_ok
,
1441 bool static_assert_ok
, bool empty_ok
,
1442 bool nested
, bool start_attr_ok
,
1443 tree
*objc_foreach_object_declaration
)
1445 struct c_declspecs
*specs
;
1447 tree all_prefix_attrs
;
1448 bool diagnosed_no_specs
= false;
1449 location_t here
= c_parser_peek_token (parser
)->location
;
1451 if (static_assert_ok
1452 && c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
1454 c_parser_static_assert_declaration (parser
);
1457 specs
= build_null_declspecs ();
1459 /* Try to detect an unknown type name when we have "A B" or "A *B". */
1460 if (c_parser_peek_token (parser
)->type
== CPP_NAME
1461 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
1462 && (c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
1463 || c_parser_peek_2nd_token (parser
)->type
== CPP_MULT
)
1464 && (!nested
|| !lookup_name (c_parser_peek_token (parser
)->value
)))
1466 error_at (here
, "unknown type name %qE",
1467 c_parser_peek_token (parser
)->value
);
1469 /* Parse declspecs normally to get a correct pointer type, but avoid
1470 a further "fails to be a type name" error. Refuse nested functions
1471 since it is not how the user likely wants us to recover. */
1472 c_parser_peek_token (parser
)->type
= CPP_KEYWORD
;
1473 c_parser_peek_token (parser
)->keyword
= RID_VOID
;
1474 c_parser_peek_token (parser
)->value
= error_mark_node
;
1478 c_parser_declspecs (parser
, specs
, true, true, start_attr_ok
, cla_nonabstract_decl
);
1481 c_parser_skip_to_end_of_block_or_statement (parser
);
1484 if (nested
&& !specs
->declspecs_seen_p
)
1486 c_parser_error (parser
, "expected declaration specifiers");
1487 c_parser_skip_to_end_of_block_or_statement (parser
);
1490 finish_declspecs (specs
);
1491 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1497 shadow_tag_warned (specs
, 1);
1498 pedwarn (here
, 0, "empty declaration");
1500 c_parser_consume_token (parser
);
1504 /* Provide better error recovery. Note that a type name here is usually
1505 better diagnosed as a redeclaration. */
1507 && specs
->typespec_kind
== ctsk_tagdef
1508 && c_parser_next_token_starts_declspecs (parser
)
1509 && !c_parser_next_token_is (parser
, CPP_NAME
))
1511 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
1512 parser
->error
= false;
1513 shadow_tag_warned (specs
, 1);
1516 else if (c_dialect_objc ())
1518 /* Prefix attributes are an error on method decls. */
1519 switch (c_parser_peek_token (parser
)->type
)
1523 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1527 warning_at (c_parser_peek_token (parser
)->location
,
1529 "prefix attributes are ignored for methods");
1530 specs
->attrs
= NULL_TREE
;
1533 c_parser_objc_method_definition (parser
);
1535 c_parser_objc_methodproto (parser
);
1541 /* This is where we parse 'attributes @interface ...',
1542 'attributes @implementation ...', 'attributes @protocol ...'
1543 (where attributes could be, for example, __attribute__
1546 switch (c_parser_peek_token (parser
)->keyword
)
1548 case RID_AT_INTERFACE
:
1550 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1552 c_parser_objc_class_definition (parser
, specs
->attrs
);
1556 case RID_AT_IMPLEMENTATION
:
1558 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1562 warning_at (c_parser_peek_token (parser
)->location
,
1564 "prefix attributes are ignored for implementations");
1565 specs
->attrs
= NULL_TREE
;
1567 c_parser_objc_class_definition (parser
, NULL_TREE
);
1571 case RID_AT_PROTOCOL
:
1573 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1575 c_parser_objc_protocol_definition (parser
, specs
->attrs
);
1582 case RID_AT_PROPERTY
:
1585 c_parser_error (parser
, "unexpected attribute");
1586 specs
->attrs
= NULL
;
1594 pending_xref_error ();
1595 prefix_attrs
= specs
->attrs
;
1596 all_prefix_attrs
= prefix_attrs
;
1597 specs
->attrs
= NULL_TREE
;
1600 struct c_declarator
*declarator
;
1604 /* Declaring either one or more declarators (in which case we
1605 should diagnose if there were no declaration specifiers) or a
1606 function definition (in which case the diagnostic for
1607 implicit int suffices). */
1608 declarator
= c_parser_declarator (parser
,
1609 specs
->typespec_kind
!= ctsk_none
,
1610 C_DTR_NORMAL
, &dummy
);
1611 if (declarator
== NULL
)
1613 c_parser_skip_to_end_of_block_or_statement (parser
);
1616 if (c_parser_next_token_is (parser
, CPP_EQ
)
1617 || c_parser_next_token_is (parser
, CPP_COMMA
)
1618 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
1619 || c_parser_next_token_is_keyword (parser
, RID_ASM
)
1620 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
)
1621 || c_parser_next_token_is_keyword (parser
, RID_IN
))
1623 tree asm_name
= NULL_TREE
;
1624 tree postfix_attrs
= NULL_TREE
;
1625 if (!diagnosed_no_specs
&& !specs
->declspecs_seen_p
)
1627 diagnosed_no_specs
= true;
1628 pedwarn (here
, 0, "data definition has no type or storage class");
1630 /* Having seen a data definition, there cannot now be a
1631 function definition. */
1633 if (c_parser_next_token_is_keyword (parser
, RID_ASM
))
1634 asm_name
= c_parser_simple_asm_expr (parser
);
1635 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1636 postfix_attrs
= c_parser_attributes (parser
);
1637 if (c_parser_next_token_is (parser
, CPP_EQ
))
1641 location_t init_loc
;
1642 c_parser_consume_token (parser
);
1643 /* The declaration of the variable is in effect while
1644 its initializer is parsed. */
1645 d
= start_decl (declarator
, specs
, true,
1646 chainon (postfix_attrs
, all_prefix_attrs
));
1648 d
= error_mark_node
;
1649 start_init (d
, asm_name
, global_bindings_p ());
1650 init_loc
= c_parser_peek_token (parser
)->location
;
1651 init
= c_parser_initializer (parser
);
1653 if (d
!= error_mark_node
)
1655 maybe_warn_string_init (TREE_TYPE (d
), init
);
1656 finish_decl (d
, init_loc
, init
.value
,
1657 init
.original_type
, asm_name
);
1662 tree d
= start_decl (declarator
, specs
, false,
1663 chainon (postfix_attrs
,
1666 finish_decl (d
, UNKNOWN_LOCATION
, NULL_TREE
,
1667 NULL_TREE
, asm_name
);
1669 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
1672 *objc_foreach_object_declaration
= d
;
1674 *objc_foreach_object_declaration
= error_mark_node
;
1677 if (c_parser_next_token_is (parser
, CPP_COMMA
))
1679 c_parser_consume_token (parser
);
1680 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1681 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
1684 all_prefix_attrs
= prefix_attrs
;
1687 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1689 c_parser_consume_token (parser
);
1692 else if (c_parser_next_token_is_keyword (parser
, RID_IN
))
1694 /* This can only happen in Objective-C: we found the
1695 'in' that terminates the declaration inside an
1696 Objective-C foreach statement. Do not consume the
1697 token, so that the caller can use it to determine
1698 that this indeed is a foreach context. */
1703 c_parser_error (parser
, "expected %<,%> or %<;%>");
1704 c_parser_skip_to_end_of_block_or_statement (parser
);
1710 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, "
1711 "%<asm%> or %<__attribute__%>");
1712 c_parser_skip_to_end_of_block_or_statement (parser
);
1715 /* Function definition (nested or otherwise). */
1718 pedwarn (here
, OPT_Wpedantic
, "ISO C forbids nested functions");
1719 c_push_function_context ();
1721 if (!start_function (specs
, declarator
, all_prefix_attrs
))
1723 /* This can appear in many cases looking nothing like a
1724 function definition, so we don't give a more specific
1725 error suggesting there was one. */
1726 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
1727 "or %<__attribute__%>");
1729 c_pop_function_context ();
1733 if (DECL_DECLARED_INLINE_P (current_function_decl
))
1734 tv
= TV_PARSE_INLINE
;
1739 /* Parse old-style parameter declarations. ??? Attributes are
1740 not allowed to start declaration specifiers here because of a
1741 syntax conflict between a function declaration with attribute
1742 suffix and a function definition with an attribute prefix on
1743 first old-style parameter declaration. Following the old
1744 parser, they are not accepted on subsequent old-style
1745 parameter declarations either. However, there is no
1746 ambiguity after the first declaration, nor indeed on the
1747 first as long as we don't allow postfix attributes after a
1748 declarator with a nonempty identifier list in a definition;
1749 and postfix attributes have never been accepted here in
1750 function definitions either. */
1751 while (c_parser_next_token_is_not (parser
, CPP_EOF
)
1752 && c_parser_next_token_is_not (parser
, CPP_OPEN_BRACE
))
1753 c_parser_declaration_or_fndef (parser
, false, false, false,
1755 store_parm_decls ();
1756 DECL_STRUCT_FUNCTION (current_function_decl
)->function_start_locus
1757 = c_parser_peek_token (parser
)->location
;
1758 fnbody
= c_parser_compound_statement (parser
);
1759 if (flag_enable_cilkplus
&& contains_array_notation_expr (fnbody
))
1760 fnbody
= expand_array_notation_exprs (fnbody
);
1763 tree decl
= current_function_decl
;
1764 /* Mark nested functions as needing static-chain initially.
1765 lower_nested_functions will recompute it but the
1766 DECL_STATIC_CHAIN flag is also used before that happens,
1767 by initializer_constant_valid_p. See gcc.dg/nested-fn-2.c. */
1768 DECL_STATIC_CHAIN (decl
) = 1;
1771 c_pop_function_context ();
1772 add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl
), DECL_EXPR
, decl
));
1785 /* Parse an asm-definition (asm() outside a function body). This is a
1793 c_parser_asm_definition (c_parser
*parser
)
1795 tree asm_str
= c_parser_simple_asm_expr (parser
);
1797 add_asm_node (asm_str
);
1798 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
1801 /* Parse a static assertion (C11 6.7.10).
1803 static_assert-declaration:
1804 static_assert-declaration-no-semi ;
1808 c_parser_static_assert_declaration (c_parser
*parser
)
1810 c_parser_static_assert_declaration_no_semi (parser
);
1812 || !c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
1813 c_parser_skip_to_end_of_block_or_statement (parser
);
1816 /* Parse a static assertion (C11 6.7.10), without the trailing
1819 static_assert-declaration-no-semi:
1820 _Static_assert ( constant-expression , string-literal )
1824 c_parser_static_assert_declaration_no_semi (c_parser
*parser
)
1826 location_t assert_loc
, value_loc
;
1830 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
));
1831 assert_loc
= c_parser_peek_token (parser
)->location
;
1835 pedwarn (assert_loc
, OPT_Wpedantic
,
1836 "ISO C99 does not support %<_Static_assert%>");
1838 pedwarn (assert_loc
, OPT_Wpedantic
,
1839 "ISO C90 does not support %<_Static_assert%>");
1841 c_parser_consume_token (parser
);
1842 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
1844 value_loc
= c_parser_peek_token (parser
)->location
;
1845 value
= c_parser_expr_no_commas (parser
, NULL
).value
;
1846 parser
->lex_untranslated_string
= true;
1847 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
1849 parser
->lex_untranslated_string
= false;
1852 switch (c_parser_peek_token (parser
)->type
)
1858 case CPP_UTF8STRING
:
1859 string
= c_parser_peek_token (parser
)->value
;
1860 c_parser_consume_token (parser
);
1861 parser
->lex_untranslated_string
= false;
1864 c_parser_error (parser
, "expected string literal");
1865 parser
->lex_untranslated_string
= false;
1868 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
1870 if (!INTEGRAL_TYPE_P (TREE_TYPE (value
)))
1872 error_at (value_loc
, "expression in static assertion is not an integer");
1875 if (TREE_CODE (value
) != INTEGER_CST
)
1877 value
= c_fully_fold (value
, false, NULL
);
1878 if (TREE_CODE (value
) == INTEGER_CST
)
1879 pedwarn (value_loc
, OPT_Wpedantic
, "expression in static assertion "
1880 "is not an integer constant expression");
1882 if (TREE_CODE (value
) != INTEGER_CST
)
1884 error_at (value_loc
, "expression in static assertion is not constant");
1887 constant_expression_warning (value
);
1888 if (integer_zerop (value
))
1889 error_at (assert_loc
, "static assertion failed: %E", string
);
1892 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
1893 6.7), adding them to SPECS (which may already include some).
1894 Storage class specifiers are accepted iff SCSPEC_OK; type
1895 specifiers are accepted iff TYPESPEC_OK; attributes are accepted at
1896 the start iff START_ATTR_OK.
1898 declaration-specifiers:
1899 storage-class-specifier declaration-specifiers[opt]
1900 type-specifier declaration-specifiers[opt]
1901 type-qualifier declaration-specifiers[opt]
1902 function-specifier declaration-specifiers[opt]
1903 alignment-specifier declaration-specifiers[opt]
1905 Function specifiers (inline) are from C99, and are currently
1906 handled as storage class specifiers, as is __thread. Alignment
1907 specifiers are from C11.
1909 C90 6.5.1, C99 6.7.1:
1910 storage-class-specifier:
1922 (_Noreturn is new in C11.)
1924 C90 6.5.2, C99 6.7.2:
1937 [_Imaginary removed in C99 TC2]
1938 struct-or-union-specifier
1942 (_Bool and _Complex are new in C99.)
1944 C90 6.5.3, C99 6.7.3:
1950 address-space-qualifier
1952 (restrict is new in C99.)
1956 declaration-specifiers:
1957 attributes declaration-specifiers[opt]
1963 identifier recognized by the target
1965 storage-class-specifier:
1978 (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
1979 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
1984 class-name objc-protocol-refs[opt]
1985 typedef-name objc-protocol-refs
1990 c_parser_declspecs (c_parser
*parser
, struct c_declspecs
*specs
,
1991 bool scspec_ok
, bool typespec_ok
, bool start_attr_ok
,
1992 enum c_lookahead_kind la
)
1994 bool attrs_ok
= start_attr_ok
;
1995 bool seen_type
= specs
->typespec_kind
!= ctsk_none
;
1998 gcc_assert (la
== cla_prefer_id
);
2000 while (c_parser_next_token_is (parser
, CPP_NAME
)
2001 || c_parser_next_token_is (parser
, CPP_KEYWORD
)
2002 || (c_dialect_objc () && c_parser_next_token_is (parser
, CPP_LESS
)))
2004 struct c_typespec t
;
2007 location_t loc
= c_parser_peek_token (parser
)->location
;
2009 /* If we cannot accept a type, exit if the next token must start
2010 one. Also, if we already have seen a tagged definition,
2011 a typename would be an error anyway and likely the user
2012 has simply forgotten a semicolon, so we exit. */
2013 if ((!typespec_ok
|| specs
->typespec_kind
== ctsk_tagdef
)
2014 && c_parser_next_tokens_start_typename (parser
, la
)
2015 && !c_parser_next_token_is_qualifier (parser
))
2018 if (c_parser_next_token_is (parser
, CPP_NAME
))
2020 c_token
*name_token
= c_parser_peek_token (parser
);
2021 tree value
= name_token
->value
;
2022 c_id_kind kind
= name_token
->id_kind
;
2024 if (kind
== C_ID_ADDRSPACE
)
2027 = name_token
->keyword
- RID_FIRST_ADDR_SPACE
;
2028 declspecs_add_addrspace (name_token
->location
, specs
, as
);
2029 c_parser_consume_token (parser
);
2034 gcc_assert (!c_parser_next_token_is_qualifier (parser
));
2036 /* If we cannot accept a type, and the next token must start one,
2037 exit. Do the same if we already have seen a tagged definition,
2038 since it would be an error anyway and likely the user has simply
2039 forgotten a semicolon. */
2040 if (seen_type
|| !c_parser_next_tokens_start_typename (parser
, la
))
2043 /* Now at an unknown typename (C_ID_ID), a C_ID_TYPENAME or
2044 a C_ID_CLASSNAME. */
2045 c_parser_consume_token (parser
);
2048 if (kind
== C_ID_ID
)
2050 error ("unknown type name %qE", value
);
2051 t
.kind
= ctsk_typedef
;
2052 t
.spec
= error_mark_node
;
2054 else if (kind
== C_ID_TYPENAME
2055 && (!c_dialect_objc ()
2056 || c_parser_next_token_is_not (parser
, CPP_LESS
)))
2058 t
.kind
= ctsk_typedef
;
2059 /* For a typedef name, record the meaning, not the name.
2060 In case of 'foo foo, bar;'. */
2061 t
.spec
= lookup_name (value
);
2065 tree proto
= NULL_TREE
;
2066 gcc_assert (c_dialect_objc ());
2068 if (c_parser_next_token_is (parser
, CPP_LESS
))
2069 proto
= c_parser_objc_protocol_refs (parser
);
2070 t
.spec
= objc_get_protocol_qualified_type (value
, proto
);
2073 t
.expr_const_operands
= true;
2074 declspecs_add_type (name_token
->location
, specs
, t
);
2077 if (c_parser_next_token_is (parser
, CPP_LESS
))
2079 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
2080 nisse@lysator.liu.se. */
2082 gcc_assert (c_dialect_objc ());
2083 if (!typespec_ok
|| seen_type
)
2085 proto
= c_parser_objc_protocol_refs (parser
);
2087 t
.spec
= objc_get_protocol_qualified_type (NULL_TREE
, proto
);
2089 t
.expr_const_operands
= true;
2090 declspecs_add_type (loc
, specs
, t
);
2093 gcc_assert (c_parser_next_token_is (parser
, CPP_KEYWORD
));
2094 switch (c_parser_peek_token (parser
)->keyword
)
2107 /* TODO: Distinguish between function specifiers (inline, noreturn)
2108 and storage class specifiers, either here or in
2109 declspecs_add_scspec. */
2110 declspecs_add_scspec (loc
, specs
,
2111 c_parser_peek_token (parser
)->value
);
2112 c_parser_consume_token (parser
);
2136 if (c_dialect_objc ())
2137 parser
->objc_need_raw_identifier
= true;
2138 t
.kind
= ctsk_resword
;
2139 t
.spec
= c_parser_peek_token (parser
)->value
;
2141 t
.expr_const_operands
= true;
2142 declspecs_add_type (loc
, specs
, t
);
2143 c_parser_consume_token (parser
);
2150 t
= c_parser_enum_specifier (parser
);
2151 declspecs_add_type (loc
, specs
, t
);
2159 t
= c_parser_struct_or_union_specifier (parser
);
2160 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE
, t
.spec
);
2161 declspecs_add_type (loc
, specs
, t
);
2164 /* ??? The old parser rejected typeof after other type
2165 specifiers, but is a syntax error the best way of
2167 if (!typespec_ok
|| seen_type
)
2171 t
= c_parser_typeof_specifier (parser
);
2172 declspecs_add_type (loc
, specs
, t
);
2178 declspecs_add_qual (loc
, specs
, c_parser_peek_token (parser
)->value
);
2179 c_parser_consume_token (parser
);
2184 attrs
= c_parser_attributes (parser
);
2185 declspecs_add_attrs (loc
, specs
, attrs
);
2188 align
= c_parser_alignas_specifier (parser
);
2189 declspecs_add_alignas (loc
, specs
, align
);
2198 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
2201 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
2202 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
2203 enum attributes[opt] identifier
2205 The form with trailing comma is new in C99. The forms with
2206 attributes are GNU extensions. In GNU C, we accept any expression
2207 without commas in the syntax (assignment expressions, not just
2208 conditional expressions); assignment expressions will be diagnosed
2213 enumerator-list , enumerator
2216 enumeration-constant
2217 enumeration-constant = constant-expression
2220 static struct c_typespec
2221 c_parser_enum_specifier (c_parser
*parser
)
2223 struct c_typespec ret
;
2225 tree ident
= NULL_TREE
;
2226 location_t enum_loc
;
2227 location_t ident_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2228 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ENUM
));
2229 enum_loc
= c_parser_peek_token (parser
)->location
;
2230 c_parser_consume_token (parser
);
2231 attrs
= c_parser_attributes (parser
);
2232 enum_loc
= c_parser_peek_token (parser
)->location
;
2233 /* Set the location in case we create a decl now. */
2234 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2235 if (c_parser_next_token_is (parser
, CPP_NAME
))
2237 ident
= c_parser_peek_token (parser
)->value
;
2238 ident_loc
= c_parser_peek_token (parser
)->location
;
2239 enum_loc
= ident_loc
;
2240 c_parser_consume_token (parser
);
2242 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2244 /* Parse an enum definition. */
2245 struct c_enum_contents the_enum
;
2248 /* We chain the enumerators in reverse order, then put them in
2249 forward order at the end. */
2251 timevar_push (TV_PARSE_ENUM
);
2252 type
= start_enum (enum_loc
, &the_enum
, ident
);
2254 c_parser_consume_token (parser
);
2262 location_t comma_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2263 location_t decl_loc
, value_loc
;
2264 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
2266 c_parser_error (parser
, "expected identifier");
2267 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2268 values
= error_mark_node
;
2271 token
= c_parser_peek_token (parser
);
2272 enum_id
= token
->value
;
2273 /* Set the location in case we create a decl now. */
2274 c_parser_set_source_position_from_token (token
);
2275 decl_loc
= value_loc
= token
->location
;
2276 c_parser_consume_token (parser
);
2277 if (c_parser_next_token_is (parser
, CPP_EQ
))
2279 c_parser_consume_token (parser
);
2280 value_loc
= c_parser_peek_token (parser
)->location
;
2281 enum_value
= c_parser_expr_no_commas (parser
, NULL
).value
;
2284 enum_value
= NULL_TREE
;
2285 enum_decl
= build_enumerator (decl_loc
, value_loc
,
2286 &the_enum
, enum_id
, enum_value
);
2287 TREE_CHAIN (enum_decl
) = values
;
2290 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2292 comma_loc
= c_parser_peek_token (parser
)->location
;
2294 c_parser_consume_token (parser
);
2296 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2298 if (seen_comma
&& !flag_isoc99
)
2299 pedwarn (comma_loc
, OPT_Wpedantic
, "comma at end of enumerator list");
2300 c_parser_consume_token (parser
);
2305 c_parser_error (parser
, "expected %<,%> or %<}%>");
2306 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2307 values
= error_mark_node
;
2311 postfix_attrs
= c_parser_attributes (parser
);
2312 ret
.spec
= finish_enum (type
, nreverse (values
),
2313 chainon (attrs
, postfix_attrs
));
2314 ret
.kind
= ctsk_tagdef
;
2315 ret
.expr
= NULL_TREE
;
2316 ret
.expr_const_operands
= true;
2317 timevar_pop (TV_PARSE_ENUM
);
2322 c_parser_error (parser
, "expected %<{%>");
2323 ret
.spec
= error_mark_node
;
2324 ret
.kind
= ctsk_tagref
;
2325 ret
.expr
= NULL_TREE
;
2326 ret
.expr_const_operands
= true;
2329 ret
= parser_xref_tag (ident_loc
, ENUMERAL_TYPE
, ident
);
2330 /* In ISO C, enumerated types can be referred to only if already
2332 if (pedantic
&& !COMPLETE_TYPE_P (ret
.spec
))
2335 pedwarn (enum_loc
, OPT_Wpedantic
,
2336 "ISO C forbids forward references to %<enum%> types");
2341 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
2343 struct-or-union-specifier:
2344 struct-or-union attributes[opt] identifier[opt]
2345 { struct-contents } attributes[opt]
2346 struct-or-union attributes[opt] identifier
2349 struct-declaration-list
2351 struct-declaration-list:
2352 struct-declaration ;
2353 struct-declaration-list struct-declaration ;
2360 struct-declaration-list struct-declaration
2362 struct-declaration-list:
2363 struct-declaration-list ;
2366 (Note that in the syntax here, unlike that in ISO C, the semicolons
2367 are included here rather than in struct-declaration, in order to
2368 describe the syntax with extra semicolons and missing semicolon at
2373 struct-declaration-list:
2374 @defs ( class-name )
2376 (Note this does not include a trailing semicolon, but can be
2377 followed by further declarations, and gets a pedwarn-if-pedantic
2378 when followed by a semicolon.) */
2380 static struct c_typespec
2381 c_parser_struct_or_union_specifier (c_parser
*parser
)
2383 struct c_typespec ret
;
2385 tree ident
= NULL_TREE
;
2386 location_t struct_loc
;
2387 location_t ident_loc
= UNKNOWN_LOCATION
;
2388 enum tree_code code
;
2389 switch (c_parser_peek_token (parser
)->keyword
)
2400 struct_loc
= c_parser_peek_token (parser
)->location
;
2401 c_parser_consume_token (parser
);
2402 attrs
= c_parser_attributes (parser
);
2404 /* Set the location in case we create a decl now. */
2405 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2407 if (c_parser_next_token_is (parser
, CPP_NAME
))
2409 ident
= c_parser_peek_token (parser
)->value
;
2410 ident_loc
= c_parser_peek_token (parser
)->location
;
2411 struct_loc
= ident_loc
;
2412 c_parser_consume_token (parser
);
2414 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2416 /* Parse a struct or union definition. Start the scope of the
2417 tag before parsing components. */
2418 struct c_struct_parse_info
*struct_info
;
2419 tree type
= start_struct (struct_loc
, code
, ident
, &struct_info
);
2421 /* We chain the components in reverse order, then put them in
2422 forward order at the end. Each struct-declaration may
2423 declare multiple components (comma-separated), so we must use
2424 chainon to join them, although when parsing each
2425 struct-declaration we can use TREE_CHAIN directly.
2427 The theory behind all this is that there will be more
2428 semicolon separated fields than comma separated fields, and
2429 so we'll be minimizing the number of node traversals required
2432 timevar_push (TV_PARSE_STRUCT
);
2433 contents
= NULL_TREE
;
2434 c_parser_consume_token (parser
);
2435 /* Handle the Objective-C @defs construct,
2436 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
2437 if (c_parser_next_token_is_keyword (parser
, RID_AT_DEFS
))
2440 gcc_assert (c_dialect_objc ());
2441 c_parser_consume_token (parser
);
2442 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2444 if (c_parser_next_token_is (parser
, CPP_NAME
)
2445 && c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
)
2447 name
= c_parser_peek_token (parser
)->value
;
2448 c_parser_consume_token (parser
);
2452 c_parser_error (parser
, "expected class name");
2453 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2456 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2458 contents
= nreverse (objc_get_class_ivars (name
));
2461 /* Parse the struct-declarations and semicolons. Problems with
2462 semicolons are diagnosed here; empty structures are diagnosed
2467 /* Parse any stray semicolon. */
2468 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2470 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
2471 "extra semicolon in struct or union specified");
2472 c_parser_consume_token (parser
);
2475 /* Stop if at the end of the struct or union contents. */
2476 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2478 c_parser_consume_token (parser
);
2481 /* Accept #pragmas at struct scope. */
2482 if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
2484 c_parser_pragma (parser
, pragma_external
);
2487 /* Parse some comma-separated declarations, but not the
2488 trailing semicolon if any. */
2489 decls
= c_parser_struct_declaration (parser
);
2490 contents
= chainon (decls
, contents
);
2491 /* If no semicolon follows, either we have a parse error or
2492 are at the end of the struct or union and should
2494 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2495 c_parser_consume_token (parser
);
2498 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2499 pedwarn (c_parser_peek_token (parser
)->location
, 0,
2500 "no semicolon at end of struct or union");
2501 else if (parser
->error
2502 || !c_parser_next_token_starts_declspecs (parser
))
2504 c_parser_error (parser
, "expected %<;%>");
2505 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2509 /* If we come here, we have already emitted an error
2510 for an expected `;', identifier or `(', and we also
2511 recovered already. Go on with the next field. */
2514 postfix_attrs
= c_parser_attributes (parser
);
2515 ret
.spec
= finish_struct (struct_loc
, type
, nreverse (contents
),
2516 chainon (attrs
, postfix_attrs
), struct_info
);
2517 ret
.kind
= ctsk_tagdef
;
2518 ret
.expr
= NULL_TREE
;
2519 ret
.expr_const_operands
= true;
2520 timevar_pop (TV_PARSE_STRUCT
);
2525 c_parser_error (parser
, "expected %<{%>");
2526 ret
.spec
= error_mark_node
;
2527 ret
.kind
= ctsk_tagref
;
2528 ret
.expr
= NULL_TREE
;
2529 ret
.expr_const_operands
= true;
2532 ret
= parser_xref_tag (ident_loc
, code
, ident
);
2536 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
2537 the trailing semicolon.
2540 specifier-qualifier-list struct-declarator-list
2541 static_assert-declaration-no-semi
2543 specifier-qualifier-list:
2544 type-specifier specifier-qualifier-list[opt]
2545 type-qualifier specifier-qualifier-list[opt]
2546 attributes specifier-qualifier-list[opt]
2548 struct-declarator-list:
2550 struct-declarator-list , attributes[opt] struct-declarator
2553 declarator attributes[opt]
2554 declarator[opt] : constant-expression attributes[opt]
2559 __extension__ struct-declaration
2560 specifier-qualifier-list
2562 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
2563 of attributes where shown is a GNU extension. In GNU C, we accept
2564 any expression without commas in the syntax (assignment
2565 expressions, not just conditional expressions); assignment
2566 expressions will be diagnosed as non-constant. */
2569 c_parser_struct_declaration (c_parser
*parser
)
2571 struct c_declspecs
*specs
;
2573 tree all_prefix_attrs
;
2575 location_t decl_loc
;
2576 if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
2580 ext
= disable_extension_diagnostics ();
2581 c_parser_consume_token (parser
);
2582 decl
= c_parser_struct_declaration (parser
);
2583 restore_extension_diagnostics (ext
);
2586 if (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
2588 c_parser_static_assert_declaration_no_semi (parser
);
2591 specs
= build_null_declspecs ();
2592 decl_loc
= c_parser_peek_token (parser
)->location
;
2593 c_parser_declspecs (parser
, specs
, false, true, true, cla_nonabstract_decl
);
2596 if (!specs
->declspecs_seen_p
)
2598 c_parser_error (parser
, "expected specifier-qualifier-list");
2601 finish_declspecs (specs
);
2602 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2603 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2606 if (specs
->typespec_kind
== ctsk_none
)
2608 pedwarn (decl_loc
, OPT_Wpedantic
,
2609 "ISO C forbids member declarations with no members");
2610 shadow_tag_warned (specs
, pedantic
);
2615 /* Support for unnamed structs or unions as members of
2616 structs or unions (which is [a] useful and [b] supports
2620 ret
= grokfield (c_parser_peek_token (parser
)->location
,
2621 build_id_declarator (NULL_TREE
), specs
,
2624 decl_attributes (&ret
, attrs
, 0);
2629 /* Provide better error recovery. Note that a type name here is valid,
2630 and will be treated as a field name. */
2631 if (specs
->typespec_kind
== ctsk_tagdef
2632 && TREE_CODE (specs
->type
) != ENUMERAL_TYPE
2633 && c_parser_next_token_starts_declspecs (parser
)
2634 && !c_parser_next_token_is (parser
, CPP_NAME
))
2636 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
2637 parser
->error
= false;
2641 pending_xref_error ();
2642 prefix_attrs
= specs
->attrs
;
2643 all_prefix_attrs
= prefix_attrs
;
2644 specs
->attrs
= NULL_TREE
;
2648 /* Declaring one or more declarators or un-named bit-fields. */
2649 struct c_declarator
*declarator
;
2651 if (c_parser_next_token_is (parser
, CPP_COLON
))
2652 declarator
= build_id_declarator (NULL_TREE
);
2654 declarator
= c_parser_declarator (parser
,
2655 specs
->typespec_kind
!= ctsk_none
,
2656 C_DTR_NORMAL
, &dummy
);
2657 if (declarator
== NULL
)
2659 c_parser_skip_to_end_of_block_or_statement (parser
);
2662 if (c_parser_next_token_is (parser
, CPP_COLON
)
2663 || c_parser_next_token_is (parser
, CPP_COMMA
)
2664 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2665 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
)
2666 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2668 tree postfix_attrs
= NULL_TREE
;
2669 tree width
= NULL_TREE
;
2671 if (c_parser_next_token_is (parser
, CPP_COLON
))
2673 c_parser_consume_token (parser
);
2674 width
= c_parser_expr_no_commas (parser
, NULL
).value
;
2676 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2677 postfix_attrs
= c_parser_attributes (parser
);
2678 d
= grokfield (c_parser_peek_token (parser
)->location
,
2679 declarator
, specs
, width
, &all_prefix_attrs
);
2680 decl_attributes (&d
, chainon (postfix_attrs
,
2681 all_prefix_attrs
), 0);
2682 DECL_CHAIN (d
) = decls
;
2684 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2685 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
2688 all_prefix_attrs
= prefix_attrs
;
2689 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2690 c_parser_consume_token (parser
);
2691 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2692 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2694 /* Semicolon consumed in caller. */
2699 c_parser_error (parser
, "expected %<,%>, %<;%> or %<}%>");
2705 c_parser_error (parser
,
2706 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
2707 "%<__attribute__%>");
2714 /* Parse a typeof specifier (a GNU extension).
2717 typeof ( expression )
2718 typeof ( type-name )
2721 static struct c_typespec
2722 c_parser_typeof_specifier (c_parser
*parser
)
2724 struct c_typespec ret
;
2725 ret
.kind
= ctsk_typeof
;
2726 ret
.spec
= error_mark_node
;
2727 ret
.expr
= NULL_TREE
;
2728 ret
.expr_const_operands
= true;
2729 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TYPEOF
));
2730 c_parser_consume_token (parser
);
2731 c_inhibit_evaluation_warnings
++;
2733 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2735 c_inhibit_evaluation_warnings
--;
2739 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
2741 struct c_type_name
*type
= c_parser_type_name (parser
);
2742 c_inhibit_evaluation_warnings
--;
2746 ret
.spec
= groktypename (type
, &ret
.expr
, &ret
.expr_const_operands
);
2747 pop_maybe_used (variably_modified_type_p (ret
.spec
, NULL_TREE
));
2753 location_t here
= c_parser_peek_token (parser
)->location
;
2754 struct c_expr expr
= c_parser_expression (parser
);
2755 c_inhibit_evaluation_warnings
--;
2757 if (TREE_CODE (expr
.value
) == COMPONENT_REF
2758 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
2759 error_at (here
, "%<typeof%> applied to a bit-field");
2760 mark_exp_read (expr
.value
);
2761 ret
.spec
= TREE_TYPE (expr
.value
);
2762 was_vm
= variably_modified_type_p (ret
.spec
, NULL_TREE
);
2763 /* This is returned with the type so that when the type is
2764 evaluated, this can be evaluated. */
2766 ret
.expr
= c_fully_fold (expr
.value
, false, &ret
.expr_const_operands
);
2767 pop_maybe_used (was_vm
);
2769 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
2773 /* Parse an alignment-specifier.
2777 alignment-specifier:
2778 _Alignas ( type-name )
2779 _Alignas ( constant-expression )
2783 c_parser_alignas_specifier (c_parser
* parser
)
2785 tree ret
= error_mark_node
;
2786 location_t loc
= c_parser_peek_token (parser
)->location
;
2787 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNAS
));
2788 c_parser_consume_token (parser
);
2792 pedwarn (loc
, OPT_Wpedantic
,
2793 "ISO C99 does not support %<_Alignas%>");
2795 pedwarn (loc
, OPT_Wpedantic
,
2796 "ISO C90 does not support %<_Alignas%>");
2798 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2800 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
2802 struct c_type_name
*type
= c_parser_type_name (parser
);
2804 ret
= c_alignof (loc
, groktypename (type
, NULL
, NULL
));
2807 ret
= c_parser_expr_no_commas (parser
, NULL
).value
;
2808 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
2812 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
2813 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
2814 be redeclared; otherwise it may not. KIND indicates which kind of
2815 declarator is wanted. Returns a valid declarator except in the
2816 case of a syntax error in which case NULL is returned. *SEEN_ID is
2817 set to true if an identifier being declared is seen; this is used
2818 to diagnose bad forms of abstract array declarators and to
2819 determine whether an identifier list is syntactically permitted.
2822 pointer[opt] direct-declarator
2826 ( attributes[opt] declarator )
2827 direct-declarator array-declarator
2828 direct-declarator ( parameter-type-list )
2829 direct-declarator ( identifier-list[opt] )
2832 * type-qualifier-list[opt]
2833 * type-qualifier-list[opt] pointer
2835 type-qualifier-list:
2838 type-qualifier-list type-qualifier
2839 type-qualifier-list attributes
2841 parameter-type-list:
2843 parameter-list , ...
2846 parameter-declaration
2847 parameter-list , parameter-declaration
2849 parameter-declaration:
2850 declaration-specifiers declarator attributes[opt]
2851 declaration-specifiers abstract-declarator[opt] attributes[opt]
2855 identifier-list , identifier
2857 abstract-declarator:
2859 pointer[opt] direct-abstract-declarator
2861 direct-abstract-declarator:
2862 ( attributes[opt] abstract-declarator )
2863 direct-abstract-declarator[opt] array-declarator
2864 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
2869 direct-declarator ( parameter-forward-declarations
2870 parameter-type-list[opt] )
2872 direct-abstract-declarator:
2873 direct-abstract-declarator[opt] ( parameter-forward-declarations
2874 parameter-type-list[opt] )
2876 parameter-forward-declarations:
2878 parameter-forward-declarations parameter-list ;
2880 The uses of attributes shown above are GNU extensions.
2882 Some forms of array declarator are not included in C99 in the
2883 syntax for abstract declarators; these are disallowed elsewhere.
2884 This may be a defect (DR#289).
2886 This function also accepts an omitted abstract declarator as being
2887 an abstract declarator, although not part of the formal syntax. */
2889 static struct c_declarator
*
2890 c_parser_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
2893 /* Parse any initial pointer part. */
2894 if (c_parser_next_token_is (parser
, CPP_MULT
))
2896 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
2897 struct c_declarator
*inner
;
2898 c_parser_consume_token (parser
);
2899 c_parser_declspecs (parser
, quals_attrs
, false, false, true, cla_prefer_id
);
2900 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
2904 return make_pointer_declarator (quals_attrs
, inner
);
2906 /* Now we have a direct declarator, direct abstract declarator or
2907 nothing (which counts as a direct abstract declarator here). */
2908 return c_parser_direct_declarator (parser
, type_seen_p
, kind
, seen_id
);
2911 /* Parse a direct declarator or direct abstract declarator; arguments
2912 as c_parser_declarator. */
2914 static struct c_declarator
*
2915 c_parser_direct_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
2918 /* The direct declarator must start with an identifier (possibly
2919 omitted) or a parenthesized declarator (possibly abstract). In
2920 an ordinary declarator, initial parentheses must start a
2921 parenthesized declarator. In an abstract declarator or parameter
2922 declarator, they could start a parenthesized declarator or a
2923 parameter list. To tell which, the open parenthesis and any
2924 following attributes must be read. If a declaration specifier
2925 follows, then it is a parameter list; if the specifier is a
2926 typedef name, there might be an ambiguity about redeclaring it,
2927 which is resolved in the direction of treating it as a typedef
2928 name. If a close parenthesis follows, it is also an empty
2929 parameter list, as the syntax does not permit empty abstract
2930 declarators. Otherwise, it is a parenthesized declarator (in
2931 which case the analysis may be repeated inside it, recursively).
2933 ??? There is an ambiguity in a parameter declaration "int
2934 (__attribute__((foo)) x)", where x is not a typedef name: it
2935 could be an abstract declarator for a function, or declare x with
2936 parentheses. The proper resolution of this ambiguity needs
2937 documenting. At present we follow an accident of the old
2938 parser's implementation, whereby the first parameter must have
2939 some declaration specifiers other than just attributes. Thus as
2940 a parameter declaration it is treated as a parenthesized
2941 parameter named x, and as an abstract declarator it is
2944 ??? Also following the old parser, attributes inside an empty
2945 parameter list are ignored, making it a list not yielding a
2946 prototype, rather than giving an error or making it have one
2947 parameter with implicit type int.
2949 ??? Also following the old parser, typedef names may be
2950 redeclared in declarators, but not Objective-C class names. */
2952 if (kind
!= C_DTR_ABSTRACT
2953 && c_parser_next_token_is (parser
, CPP_NAME
)
2955 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
2956 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
2957 || c_parser_peek_token (parser
)->id_kind
== C_ID_ID
))
2959 struct c_declarator
*inner
2960 = build_id_declarator (c_parser_peek_token (parser
)->value
);
2962 inner
->id_loc
= c_parser_peek_token (parser
)->location
;
2963 c_parser_consume_token (parser
);
2964 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
2967 if (kind
!= C_DTR_NORMAL
2968 && c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
2970 struct c_declarator
*inner
= build_id_declarator (NULL_TREE
);
2971 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
2974 /* Either we are at the end of an abstract declarator, or we have
2977 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
2980 struct c_declarator
*inner
;
2981 c_parser_consume_token (parser
);
2982 attrs
= c_parser_attributes (parser
);
2983 if (kind
!= C_DTR_NORMAL
2984 && (c_parser_next_token_starts_declspecs (parser
)
2985 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
)))
2987 struct c_arg_info
*args
2988 = c_parser_parms_declarator (parser
, kind
== C_DTR_NORMAL
,
2995 = build_function_declarator (args
,
2996 build_id_declarator (NULL_TREE
));
2997 return c_parser_direct_declarator_inner (parser
, *seen_id
,
3001 /* A parenthesized declarator. */
3002 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
3003 if (inner
!= NULL
&& attrs
!= NULL
)
3004 inner
= build_attrs_declarator (attrs
, inner
);
3005 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3007 c_parser_consume_token (parser
);
3011 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3015 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3022 if (kind
== C_DTR_NORMAL
)
3024 c_parser_error (parser
, "expected identifier or %<(%>");
3028 return build_id_declarator (NULL_TREE
);
3032 /* Parse part of a direct declarator or direct abstract declarator,
3033 given that some (in INNER) has already been parsed; ID_PRESENT is
3034 true if an identifier is present, false for an abstract
3037 static struct c_declarator
*
3038 c_parser_direct_declarator_inner (c_parser
*parser
, bool id_present
,
3039 struct c_declarator
*inner
)
3041 /* Parse a sequence of array declarators and parameter lists. */
3042 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
3044 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
3045 struct c_declarator
*declarator
;
3046 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
3050 c_parser_consume_token (parser
);
3051 c_parser_declspecs (parser
, quals_attrs
, false, false, true, cla_prefer_id
);
3052 static_seen
= c_parser_next_token_is_keyword (parser
, RID_STATIC
);
3054 c_parser_consume_token (parser
);
3055 if (static_seen
&& !quals_attrs
->declspecs_seen_p
)
3056 c_parser_declspecs (parser
, quals_attrs
, false, false, true, cla_prefer_id
);
3057 if (!quals_attrs
->declspecs_seen_p
)
3059 /* If "static" is present, there must be an array dimension.
3060 Otherwise, there may be a dimension, "*", or no
3065 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
3069 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3074 else if (flag_enable_cilkplus
3075 && c_parser_next_token_is (parser
, CPP_COLON
))
3077 dimen
= error_mark_node
;
3079 error_at (c_parser_peek_token (parser
)->location
,
3080 "array notations cannot be used in declaration");
3081 c_parser_consume_token (parser
);
3083 else if (c_parser_next_token_is (parser
, CPP_MULT
))
3085 if (c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_SQUARE
)
3089 c_parser_consume_token (parser
);
3094 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
3100 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
3103 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3104 c_parser_consume_token (parser
);
3105 else if (flag_enable_cilkplus
3106 && c_parser_next_token_is (parser
, CPP_COLON
))
3108 error_at (c_parser_peek_token (parser
)->location
,
3109 "array notations cannot be used in declaration");
3110 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
3115 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3120 mark_exp_read (dimen
);
3121 declarator
= build_array_declarator (brace_loc
, dimen
, quals_attrs
,
3122 static_seen
, star_seen
);
3123 if (declarator
== NULL
)
3125 inner
= set_array_declarator_inner (declarator
, inner
);
3126 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3128 else if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3131 struct c_arg_info
*args
;
3132 c_parser_consume_token (parser
);
3133 attrs
= c_parser_attributes (parser
);
3134 args
= c_parser_parms_declarator (parser
, id_present
, attrs
);
3139 inner
= build_function_declarator (args
, inner
);
3140 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3146 /* Parse a parameter list or identifier list, including the closing
3147 parenthesis but not the opening one. ATTRS are the attributes at
3148 the start of the list. ID_LIST_OK is true if an identifier list is
3149 acceptable; such a list must not have attributes at the start. */
3151 static struct c_arg_info
*
3152 c_parser_parms_declarator (c_parser
*parser
, bool id_list_ok
, tree attrs
)
3155 declare_parm_level ();
3156 /* If the list starts with an identifier, it is an identifier list.
3157 Otherwise, it is either a prototype list or an empty list. */
3160 && c_parser_next_token_is (parser
, CPP_NAME
)
3161 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
3163 /* Look ahead to detect typos in type names. */
3164 && c_parser_peek_2nd_token (parser
)->type
!= CPP_NAME
3165 && c_parser_peek_2nd_token (parser
)->type
!= CPP_MULT
3166 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
3167 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_SQUARE
)
3169 tree list
= NULL_TREE
, *nextp
= &list
;
3170 while (c_parser_next_token_is (parser
, CPP_NAME
)
3171 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
3173 *nextp
= build_tree_list (NULL_TREE
,
3174 c_parser_peek_token (parser
)->value
);
3175 nextp
= & TREE_CHAIN (*nextp
);
3176 c_parser_consume_token (parser
);
3177 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
3179 c_parser_consume_token (parser
);
3180 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3182 c_parser_error (parser
, "expected identifier");
3186 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3188 struct c_arg_info
*ret
= build_arg_info ();
3190 c_parser_consume_token (parser
);
3196 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3204 struct c_arg_info
*ret
= c_parser_parms_list_declarator (parser
, attrs
,
3211 /* Parse a parameter list (possibly empty), including the closing
3212 parenthesis but not the opening one. ATTRS are the attributes at
3213 the start of the list. EXPR is NULL or an expression that needs to
3214 be evaluated for the side effects of array size expressions in the
3217 static struct c_arg_info
*
3218 c_parser_parms_list_declarator (c_parser
*parser
, tree attrs
, tree expr
)
3220 bool bad_parm
= false;
3222 /* ??? Following the old parser, forward parameter declarations may
3223 use abstract declarators, and if no real parameter declarations
3224 follow the forward declarations then this is not diagnosed. Also
3225 note as above that attributes are ignored as the only contents of
3226 the parentheses, or as the only contents after forward
3228 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3230 struct c_arg_info
*ret
= build_arg_info ();
3231 c_parser_consume_token (parser
);
3234 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3236 struct c_arg_info
*ret
= build_arg_info ();
3238 if (flag_allow_parameterless_variadic_functions
)
3240 /* F (...) is allowed. */
3241 ret
->types
= NULL_TREE
;
3245 /* Suppress -Wold-style-definition for this case. */
3246 ret
->types
= error_mark_node
;
3247 error_at (c_parser_peek_token (parser
)->location
,
3248 "ISO C requires a named argument before %<...%>");
3250 c_parser_consume_token (parser
);
3251 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3253 c_parser_consume_token (parser
);
3258 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3263 /* Nonempty list of parameters, either terminated with semicolon
3264 (forward declarations; recurse) or with close parenthesis (normal
3265 function) or with ", ... )" (variadic function). */
3268 /* Parse a parameter. */
3269 struct c_parm
*parm
= c_parser_parameter_declaration (parser
, attrs
);
3274 push_parm_decl (parm
, &expr
);
3275 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3278 c_parser_consume_token (parser
);
3279 mark_forward_parm_decls ();
3280 new_attrs
= c_parser_attributes (parser
);
3281 return c_parser_parms_list_declarator (parser
, new_attrs
, expr
);
3283 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3285 c_parser_consume_token (parser
);
3289 return get_parm_info (false, expr
);
3291 if (!c_parser_require (parser
, CPP_COMMA
,
3292 "expected %<;%>, %<,%> or %<)%>"))
3294 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3297 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3299 c_parser_consume_token (parser
);
3300 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3302 c_parser_consume_token (parser
);
3306 return get_parm_info (true, expr
);
3310 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3318 /* Parse a parameter declaration. ATTRS are the attributes at the
3319 start of the declaration if it is the first parameter. */
3321 static struct c_parm
*
3322 c_parser_parameter_declaration (c_parser
*parser
, tree attrs
)
3324 struct c_declspecs
*specs
;
3325 struct c_declarator
*declarator
;
3327 tree postfix_attrs
= NULL_TREE
;
3330 /* Accept #pragmas between parameter declarations. */
3331 while (c_parser_next_token_is (parser
, CPP_PRAGMA
))
3332 c_parser_pragma (parser
, pragma_external
);
3334 if (!c_parser_next_token_starts_declspecs (parser
))
3336 c_token
*token
= c_parser_peek_token (parser
);
3339 c_parser_set_source_position_from_token (token
);
3340 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
3342 error ("unknown type name %qE", token
->value
);
3343 parser
->error
= true;
3345 /* ??? In some Objective-C cases '...' isn't applicable so there
3346 should be a different message. */
3348 c_parser_error (parser
,
3349 "expected declaration specifiers or %<...%>");
3350 c_parser_skip_to_end_of_parameter (parser
);
3353 specs
= build_null_declspecs ();
3356 declspecs_add_attrs (input_location
, specs
, attrs
);
3359 c_parser_declspecs (parser
, specs
, true, true, true, cla_nonabstract_decl
);
3360 finish_declspecs (specs
);
3361 pending_xref_error ();
3362 prefix_attrs
= specs
->attrs
;
3363 specs
->attrs
= NULL_TREE
;
3364 declarator
= c_parser_declarator (parser
,
3365 specs
->typespec_kind
!= ctsk_none
,
3366 C_DTR_PARM
, &dummy
);
3367 if (declarator
== NULL
)
3369 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3372 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3373 postfix_attrs
= c_parser_attributes (parser
);
3374 return build_c_parm (specs
, chainon (postfix_attrs
, prefix_attrs
),
3378 /* Parse a string literal in an asm expression. It should not be
3379 translated, and wide string literals are an error although
3380 permitted by the syntax. This is a GNU extension.
3385 ??? At present, following the old parser, the caller needs to have
3386 set lex_untranslated_string to 1. It would be better to follow the
3387 C++ parser rather than using this kludge. */
3390 c_parser_asm_string_literal (c_parser
*parser
)
3393 int save_flag
= warn_overlength_strings
;
3394 warn_overlength_strings
= 0;
3395 if (c_parser_next_token_is (parser
, CPP_STRING
))
3397 str
= c_parser_peek_token (parser
)->value
;
3398 c_parser_consume_token (parser
);
3400 else if (c_parser_next_token_is (parser
, CPP_WSTRING
))
3402 error_at (c_parser_peek_token (parser
)->location
,
3403 "wide string literal in %<asm%>");
3404 str
= build_string (1, "");
3405 c_parser_consume_token (parser
);
3409 c_parser_error (parser
, "expected string literal");
3412 warn_overlength_strings
= save_flag
;
3416 /* Parse a simple asm expression. This is used in restricted
3417 contexts, where a full expression with inputs and outputs does not
3418 make sense. This is a GNU extension.
3421 asm ( asm-string-literal )
3425 c_parser_simple_asm_expr (c_parser
*parser
)
3428 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
3429 /* ??? Follow the C++ parser rather than using the
3430 lex_untranslated_string kludge. */
3431 parser
->lex_untranslated_string
= true;
3432 c_parser_consume_token (parser
);
3433 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3435 parser
->lex_untranslated_string
= false;
3438 str
= c_parser_asm_string_literal (parser
);
3439 parser
->lex_untranslated_string
= false;
3440 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
3442 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3449 c_parser_attribute_any_word (c_parser
*parser
)
3451 tree attr_name
= NULL_TREE
;
3453 if (c_parser_next_token_is (parser
, CPP_KEYWORD
))
3455 /* ??? See comment above about what keywords are accepted here. */
3457 switch (c_parser_peek_token (parser
)->keyword
)
3488 case RID_TRANSACTION_ATOMIC
:
3489 case RID_TRANSACTION_CANCEL
:
3499 /* Accept __attribute__((__const)) as __attribute__((const)) etc. */
3500 attr_name
= ridpointers
[(int) c_parser_peek_token (parser
)->keyword
];
3502 else if (c_parser_next_token_is (parser
, CPP_NAME
))
3503 attr_name
= c_parser_peek_token (parser
)->value
;
3508 /* Parse (possibly empty) attributes. This is a GNU extension.
3512 attributes attribute
3515 __attribute__ ( ( attribute-list ) )
3519 attribute_list , attrib
3524 any-word ( identifier )
3525 any-word ( identifier , nonempty-expr-list )
3526 any-word ( expr-list )
3528 where the "identifier" must not be declared as a type, and
3529 "any-word" may be any identifier (including one declared as a
3530 type), a reserved word storage class specifier, type specifier or
3531 type qualifier. ??? This still leaves out most reserved keywords
3532 (following the old parser), shouldn't we include them, and why not
3533 allow identifiers declared as types to start the arguments? */
3536 c_parser_attributes (c_parser
*parser
)
3538 tree attrs
= NULL_TREE
;
3539 while (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3541 /* ??? Follow the C++ parser rather than using the
3542 lex_untranslated_string kludge. */
3543 parser
->lex_untranslated_string
= true;
3544 c_parser_consume_token (parser
);
3545 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3547 parser
->lex_untranslated_string
= false;
3550 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3552 parser
->lex_untranslated_string
= false;
3553 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3556 /* Parse the attribute list. */
3557 while (c_parser_next_token_is (parser
, CPP_COMMA
)
3558 || c_parser_next_token_is (parser
, CPP_NAME
)
3559 || c_parser_next_token_is (parser
, CPP_KEYWORD
))
3561 tree attr
, attr_name
, attr_args
;
3562 vec
<tree
, va_gc
> *expr_list
;
3563 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3565 c_parser_consume_token (parser
);
3569 attr_name
= c_parser_attribute_any_word (parser
);
3570 if (attr_name
== NULL
)
3572 c_parser_consume_token (parser
);
3573 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
3575 attr
= build_tree_list (attr_name
, NULL_TREE
);
3576 attrs
= chainon (attrs
, attr
);
3579 c_parser_consume_token (parser
);
3580 /* Parse the attribute contents. If they start with an
3581 identifier which is followed by a comma or close
3582 parenthesis, then the arguments start with that
3583 identifier; otherwise they are an expression list.
3584 In objective-c the identifier may be a classname. */
3585 if (c_parser_next_token_is (parser
, CPP_NAME
)
3586 && (c_parser_peek_token (parser
)->id_kind
== C_ID_ID
3587 || (c_dialect_objc ()
3588 && c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
3589 && ((c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
)
3590 || (c_parser_peek_2nd_token (parser
)->type
3591 == CPP_CLOSE_PAREN
)))
3593 tree arg1
= c_parser_peek_token (parser
)->value
;
3594 c_parser_consume_token (parser
);
3595 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3596 attr_args
= build_tree_list (NULL_TREE
, arg1
);
3600 c_parser_consume_token (parser
);
3601 expr_list
= c_parser_expr_list (parser
, false, true,
3603 tree_list
= build_tree_list_vec (expr_list
);
3604 attr_args
= tree_cons (NULL_TREE
, arg1
, tree_list
);
3605 release_tree_vector (expr_list
);
3610 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3611 attr_args
= NULL_TREE
;
3614 expr_list
= c_parser_expr_list (parser
, false, true,
3616 attr_args
= build_tree_list_vec (expr_list
);
3617 release_tree_vector (expr_list
);
3620 attr
= build_tree_list (attr_name
, attr_args
);
3621 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3622 c_parser_consume_token (parser
);
3625 parser
->lex_untranslated_string
= false;
3626 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3630 attrs
= chainon (attrs
, attr
);
3632 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3633 c_parser_consume_token (parser
);
3636 parser
->lex_untranslated_string
= false;
3637 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3641 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3642 c_parser_consume_token (parser
);
3645 parser
->lex_untranslated_string
= false;
3646 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3650 parser
->lex_untranslated_string
= false;
3655 /* Parse a type name (C90 6.5.5, C99 6.7.6).
3658 specifier-qualifier-list abstract-declarator[opt]
3661 static struct c_type_name
*
3662 c_parser_type_name (c_parser
*parser
)
3664 struct c_declspecs
*specs
= build_null_declspecs ();
3665 struct c_declarator
*declarator
;
3666 struct c_type_name
*ret
;
3668 c_parser_declspecs (parser
, specs
, false, true, true, cla_prefer_type
);
3669 if (!specs
->declspecs_seen_p
)
3671 c_parser_error (parser
, "expected specifier-qualifier-list");
3674 if (specs
->type
!= error_mark_node
)
3676 pending_xref_error ();
3677 finish_declspecs (specs
);
3679 declarator
= c_parser_declarator (parser
,
3680 specs
->typespec_kind
!= ctsk_none
,
3681 C_DTR_ABSTRACT
, &dummy
);
3682 if (declarator
== NULL
)
3684 ret
= XOBNEW (&parser_obstack
, struct c_type_name
);
3686 ret
->declarator
= declarator
;
3690 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
3693 assignment-expression
3694 { initializer-list }
3695 { initializer-list , }
3698 designation[opt] initializer
3699 initializer-list , designation[opt] initializer
3706 designator-list designator
3713 [ constant-expression ]
3725 [ constant-expression ... constant-expression ]
3727 Any expression without commas is accepted in the syntax for the
3728 constant-expressions, with non-constant expressions rejected later.
3730 This function is only used for top-level initializers; for nested
3731 ones, see c_parser_initval. */
3733 static struct c_expr
3734 c_parser_initializer (c_parser
*parser
)
3736 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
3737 return c_parser_braced_init (parser
, NULL_TREE
, false);
3741 location_t loc
= c_parser_peek_token (parser
)->location
;
3742 ret
= c_parser_expr_no_commas (parser
, NULL
);
3743 if (TREE_CODE (ret
.value
) != STRING_CST
3744 && TREE_CODE (ret
.value
) != COMPOUND_LITERAL_EXPR
)
3745 ret
= default_function_array_read_conversion (loc
, ret
);
3750 /* Parse a braced initializer list. TYPE is the type specified for a
3751 compound literal, and NULL_TREE for other initializers and for
3752 nested braced lists. NESTED_P is true for nested braced lists,
3753 false for the list of a compound literal or the list that is the
3754 top-level initializer in a declaration. */
3756 static struct c_expr
3757 c_parser_braced_init (c_parser
*parser
, tree type
, bool nested_p
)
3760 struct obstack braced_init_obstack
;
3761 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
3762 gcc_obstack_init (&braced_init_obstack
);
3763 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
3764 c_parser_consume_token (parser
);
3766 push_init_level (0, &braced_init_obstack
);
3768 really_start_incremental_init (type
);
3769 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3771 pedwarn (brace_loc
, OPT_Wpedantic
, "ISO C forbids empty initializer braces");
3775 /* Parse a non-empty initializer list, possibly with a trailing
3779 c_parser_initelt (parser
, &braced_init_obstack
);
3782 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3783 c_parser_consume_token (parser
);
3786 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3790 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
3792 ret
.value
= error_mark_node
;
3793 ret
.original_code
= ERROR_MARK
;
3794 ret
.original_type
= NULL
;
3795 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
3796 pop_init_level (0, &braced_init_obstack
);
3797 obstack_free (&braced_init_obstack
, NULL
);
3800 c_parser_consume_token (parser
);
3801 ret
= pop_init_level (0, &braced_init_obstack
);
3802 obstack_free (&braced_init_obstack
, NULL
);
3806 /* Parse a nested initializer, including designators. */
3809 c_parser_initelt (c_parser
*parser
, struct obstack
* braced_init_obstack
)
3811 /* Parse any designator or designator list. A single array
3812 designator may have the subsequent "=" omitted in GNU C, but a
3813 longer list or a structure member designator may not. */
3814 if (c_parser_next_token_is (parser
, CPP_NAME
)
3815 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
3817 /* Old-style structure member designator. */
3818 set_init_label (c_parser_peek_token (parser
)->value
,
3819 braced_init_obstack
);
3820 /* Use the colon as the error location. */
3821 pedwarn (c_parser_peek_2nd_token (parser
)->location
, OPT_Wpedantic
,
3822 "obsolete use of designated initializer with %<:%>");
3823 c_parser_consume_token (parser
);
3824 c_parser_consume_token (parser
);
3828 /* des_seen is 0 if there have been no designators, 1 if there
3829 has been a single array designator and 2 otherwise. */
3831 /* Location of a designator. */
3832 location_t des_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
3833 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
)
3834 || c_parser_next_token_is (parser
, CPP_DOT
))
3836 int des_prev
= des_seen
;
3838 des_loc
= c_parser_peek_token (parser
)->location
;
3841 if (c_parser_next_token_is (parser
, CPP_DOT
))
3844 c_parser_consume_token (parser
);
3845 if (c_parser_next_token_is (parser
, CPP_NAME
))
3847 set_init_label (c_parser_peek_token (parser
)->value
,
3848 braced_init_obstack
);
3849 c_parser_consume_token (parser
);
3854 init
.value
= error_mark_node
;
3855 init
.original_code
= ERROR_MARK
;
3856 init
.original_type
= NULL
;
3857 c_parser_error (parser
, "expected identifier");
3858 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3859 process_init_element (init
, false, braced_init_obstack
);
3866 location_t ellipsis_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
3867 /* ??? Following the old parser, [ objc-receiver
3868 objc-message-args ] is accepted as an initializer,
3869 being distinguished from a designator by what follows
3870 the first assignment expression inside the square
3871 brackets, but after a first array designator a
3872 subsequent square bracket is for Objective-C taken to
3873 start an expression, using the obsolete form of
3874 designated initializer without '=', rather than
3875 possibly being a second level of designation: in LALR
3876 terms, the '[' is shifted rather than reducing
3877 designator to designator-list. */
3878 if (des_prev
== 1 && c_dialect_objc ())
3880 des_seen
= des_prev
;
3883 if (des_prev
== 0 && c_dialect_objc ())
3885 /* This might be an array designator or an
3886 Objective-C message expression. If the former,
3887 continue parsing here; if the latter, parse the
3888 remainder of the initializer given the starting
3889 primary-expression. ??? It might make sense to
3890 distinguish when des_prev == 1 as well; see
3891 previous comment. */
3893 struct c_expr mexpr
;
3894 c_parser_consume_token (parser
);
3895 if (c_parser_peek_token (parser
)->type
== CPP_NAME
3896 && ((c_parser_peek_token (parser
)->id_kind
3898 || (c_parser_peek_token (parser
)->id_kind
3899 == C_ID_CLASSNAME
)))
3901 /* Type name receiver. */
3902 tree id
= c_parser_peek_token (parser
)->value
;
3903 c_parser_consume_token (parser
);
3904 rec
= objc_get_class_reference (id
);
3905 goto parse_message_args
;
3907 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
3908 mark_exp_read (first
);
3909 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
)
3910 || c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3911 goto array_desig_after_first
;
3912 /* Expression receiver. So far only one part
3913 without commas has been parsed; there might be
3914 more of the expression. */
3916 while (c_parser_next_token_is (parser
, CPP_COMMA
))
3919 location_t comma_loc
, exp_loc
;
3920 comma_loc
= c_parser_peek_token (parser
)->location
;
3921 c_parser_consume_token (parser
);
3922 exp_loc
= c_parser_peek_token (parser
)->location
;
3923 next
= c_parser_expr_no_commas (parser
, NULL
);
3924 next
= default_function_array_read_conversion (exp_loc
,
3926 rec
= build_compound_expr (comma_loc
, rec
, next
.value
);
3929 /* Now parse the objc-message-args. */
3930 args
= c_parser_objc_message_args (parser
);
3931 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3934 = objc_build_message_expr (rec
, args
);
3935 mexpr
.original_code
= ERROR_MARK
;
3936 mexpr
.original_type
= NULL
;
3937 /* Now parse and process the remainder of the
3938 initializer, starting with this message
3939 expression as a primary-expression. */
3940 c_parser_initval (parser
, &mexpr
, braced_init_obstack
);
3943 c_parser_consume_token (parser
);
3944 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
3945 mark_exp_read (first
);
3946 array_desig_after_first
:
3947 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3949 ellipsis_loc
= c_parser_peek_token (parser
)->location
;
3950 c_parser_consume_token (parser
);
3951 second
= c_parser_expr_no_commas (parser
, NULL
).value
;
3952 mark_exp_read (second
);
3956 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3958 c_parser_consume_token (parser
);
3959 set_init_index (first
, second
, braced_init_obstack
);
3961 pedwarn (ellipsis_loc
, OPT_Wpedantic
,
3962 "ISO C forbids specifying range of elements to initialize");
3965 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3971 if (c_parser_next_token_is (parser
, CPP_EQ
))
3974 pedwarn (des_loc
, OPT_Wpedantic
,
3975 "ISO C90 forbids specifying subobject to initialize");
3976 c_parser_consume_token (parser
);
3981 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
3982 "obsolete use of designated initializer without %<=%>");
3986 init
.value
= error_mark_node
;
3987 init
.original_code
= ERROR_MARK
;
3988 init
.original_type
= NULL
;
3989 c_parser_error (parser
, "expected %<=%>");
3990 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3991 process_init_element (init
, false, braced_init_obstack
);
3997 c_parser_initval (parser
, NULL
, braced_init_obstack
);
4000 /* Parse a nested initializer; as c_parser_initializer but parses
4001 initializers within braced lists, after any designators have been
4002 applied. If AFTER is not NULL then it is an Objective-C message
4003 expression which is the primary-expression starting the
4007 c_parser_initval (c_parser
*parser
, struct c_expr
*after
,
4008 struct obstack
* braced_init_obstack
)
4011 gcc_assert (!after
|| c_dialect_objc ());
4012 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
) && !after
)
4013 init
= c_parser_braced_init (parser
, NULL_TREE
, true);
4016 location_t loc
= c_parser_peek_token (parser
)->location
;
4017 init
= c_parser_expr_no_commas (parser
, after
);
4018 if (init
.value
!= NULL_TREE
4019 && TREE_CODE (init
.value
) != STRING_CST
4020 && TREE_CODE (init
.value
) != COMPOUND_LITERAL_EXPR
)
4021 init
= default_function_array_read_conversion (loc
, init
);
4023 process_init_element (init
, false, braced_init_obstack
);
4026 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
4030 { block-item-list[opt] }
4031 { label-declarations block-item-list }
4035 block-item-list block-item
4047 { label-declarations block-item-list }
4050 __extension__ nested-declaration
4051 nested-function-definition
4055 label-declarations label-declaration
4058 __label__ identifier-list ;
4060 Allowing the mixing of declarations and code is new in C99. The
4061 GNU syntax also permits (not shown above) labels at the end of
4062 compound statements, which yield an error. We don't allow labels
4063 on declarations; this might seem like a natural extension, but
4064 there would be a conflict between attributes on the label and
4065 prefix attributes on the declaration. ??? The syntax follows the
4066 old parser in requiring something after label declarations.
4067 Although they are erroneous if the labels declared aren't defined,
4068 is it useful for the syntax to be this way?
4080 c_parser_compound_statement (c_parser
*parser
)
4083 location_t brace_loc
;
4084 brace_loc
= c_parser_peek_token (parser
)->location
;
4085 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
4087 /* Ensure a scope is entered and left anyway to avoid confusion
4088 if we have just prepared to enter a function body. */
4089 stmt
= c_begin_compound_stmt (true);
4090 c_end_compound_stmt (brace_loc
, stmt
, true);
4091 return error_mark_node
;
4093 stmt
= c_begin_compound_stmt (true);
4094 c_parser_compound_statement_nostart (parser
);
4096 /* If the compound stmt contains array notations, then we expand them. */
4097 if (flag_enable_cilkplus
&& contains_array_notation_expr (stmt
))
4098 stmt
= expand_array_notation_exprs (stmt
);
4099 return c_end_compound_stmt (brace_loc
, stmt
, true);
4102 /* Parse a compound statement except for the opening brace. This is
4103 used for parsing both compound statements and statement expressions
4104 (which follow different paths to handling the opening). */
4107 c_parser_compound_statement_nostart (c_parser
*parser
)
4109 bool last_stmt
= false;
4110 bool last_label
= false;
4111 bool save_valid_for_pragma
= valid_location_for_stdc_pragma_p ();
4112 location_t label_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4113 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4115 c_parser_consume_token (parser
);
4118 mark_valid_location_for_stdc_pragma (true);
4119 if (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
4121 /* Read zero or more forward-declarations for labels that nested
4122 functions can jump to. */
4123 mark_valid_location_for_stdc_pragma (false);
4124 while (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
4126 label_loc
= c_parser_peek_token (parser
)->location
;
4127 c_parser_consume_token (parser
);
4128 /* Any identifiers, including those declared as type names,
4133 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
4135 c_parser_error (parser
, "expected identifier");
4139 = declare_label (c_parser_peek_token (parser
)->value
);
4140 C_DECLARED_LABEL_FLAG (label
) = 1;
4141 add_stmt (build_stmt (label_loc
, DECL_EXPR
, label
));
4142 c_parser_consume_token (parser
);
4143 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4144 c_parser_consume_token (parser
);
4148 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4150 pedwarn (label_loc
, OPT_Wpedantic
, "ISO C forbids label declarations");
4152 /* We must now have at least one statement, label or declaration. */
4153 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4155 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4156 c_parser_error (parser
, "expected declaration or statement");
4157 c_parser_consume_token (parser
);
4160 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
4162 location_t loc
= c_parser_peek_token (parser
)->location
;
4163 if (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4164 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4165 || (c_parser_next_token_is (parser
, CPP_NAME
)
4166 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4168 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
4169 label_loc
= c_parser_peek_2nd_token (parser
)->location
;
4171 label_loc
= c_parser_peek_token (parser
)->location
;
4174 mark_valid_location_for_stdc_pragma (false);
4175 c_parser_label (parser
);
4177 else if (!last_label
4178 && c_parser_next_tokens_start_declaration (parser
))
4181 mark_valid_location_for_stdc_pragma (false);
4182 c_parser_declaration_or_fndef (parser
, true, true, true, true, true, NULL
);
4185 (pedantic
&& !flag_isoc99
)
4187 : OPT_Wdeclaration_after_statement
,
4188 "ISO C90 forbids mixed declarations and code");
4191 else if (!last_label
4192 && c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
4194 /* __extension__ can start a declaration, but is also an
4195 unary operator that can start an expression. Consume all
4196 but the last of a possible series of __extension__ to
4198 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
4199 && (c_parser_peek_2nd_token (parser
)->keyword
4201 c_parser_consume_token (parser
);
4202 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
4205 ext
= disable_extension_diagnostics ();
4206 c_parser_consume_token (parser
);
4208 mark_valid_location_for_stdc_pragma (false);
4209 c_parser_declaration_or_fndef (parser
, true, true, true, true,
4211 /* Following the old parser, __extension__ does not
4212 disable this diagnostic. */
4213 restore_extension_diagnostics (ext
);
4215 pedwarn_c90 (loc
, (pedantic
&& !flag_isoc99
)
4217 : OPT_Wdeclaration_after_statement
,
4218 "ISO C90 forbids mixed declarations and code");
4224 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
4226 /* External pragmas, and some omp pragmas, are not associated
4227 with regular c code, and so are not to be considered statements
4228 syntactically. This ensures that the user doesn't put them
4229 places that would turn into syntax errors if the directive
4231 if (c_parser_pragma (parser
, pragma_compound
))
4232 last_label
= false, last_stmt
= true;
4234 else if (c_parser_next_token_is (parser
, CPP_EOF
))
4236 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4237 c_parser_error (parser
, "expected declaration or statement");
4240 else if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
4242 if (parser
->in_if_block
)
4244 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4245 error_at (loc
, """expected %<}%> before %<else%>");
4250 error_at (loc
, "%<else%> without a previous %<if%>");
4251 c_parser_consume_token (parser
);
4260 mark_valid_location_for_stdc_pragma (false);
4261 c_parser_statement_after_labels (parser
);
4264 parser
->error
= false;
4267 error_at (label_loc
, "label at end of compound statement");
4268 c_parser_consume_token (parser
);
4269 /* Restore the value we started with. */
4270 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4273 /* Parse a label (C90 6.6.1, C99 6.8.1).
4276 identifier : attributes[opt]
4277 case constant-expression :
4283 case constant-expression ... constant-expression :
4285 The use of attributes on labels is a GNU extension. The syntax in
4286 GNU C accepts any expressions without commas, non-constant
4287 expressions being rejected later. */
4290 c_parser_label (c_parser
*parser
)
4292 location_t loc1
= c_parser_peek_token (parser
)->location
;
4293 tree label
= NULL_TREE
;
4294 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
4297 c_parser_consume_token (parser
);
4298 exp1
= c_parser_expr_no_commas (parser
, NULL
).value
;
4299 if (c_parser_next_token_is (parser
, CPP_COLON
))
4301 c_parser_consume_token (parser
);
4302 label
= do_case (loc1
, exp1
, NULL_TREE
);
4304 else if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
4306 c_parser_consume_token (parser
);
4307 exp2
= c_parser_expr_no_commas (parser
, NULL
).value
;
4308 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4309 label
= do_case (loc1
, exp1
, exp2
);
4312 c_parser_error (parser
, "expected %<:%> or %<...%>");
4314 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
4316 c_parser_consume_token (parser
);
4317 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4318 label
= do_case (loc1
, NULL_TREE
, NULL_TREE
);
4322 tree name
= c_parser_peek_token (parser
)->value
;
4325 location_t loc2
= c_parser_peek_token (parser
)->location
;
4326 gcc_assert (c_parser_next_token_is (parser
, CPP_NAME
));
4327 c_parser_consume_token (parser
);
4328 gcc_assert (c_parser_next_token_is (parser
, CPP_COLON
));
4329 c_parser_consume_token (parser
);
4330 attrs
= c_parser_attributes (parser
);
4331 tlab
= define_label (loc2
, name
);
4334 decl_attributes (&tlab
, attrs
, 0);
4335 label
= add_stmt (build_stmt (loc1
, LABEL_EXPR
, tlab
));
4340 if (c_parser_next_tokens_start_declaration (parser
))
4342 error_at (c_parser_peek_token (parser
)->location
,
4343 "a label can only be part of a statement and "
4344 "a declaration is not a statement");
4345 c_parser_declaration_or_fndef (parser
, /*fndef_ok*/ false,
4346 /*static_assert_ok*/ true,
4347 /*empty_ok*/ true, /*nested*/ true,
4348 /*start_attr_ok*/ true, NULL
);
4353 /* Parse a statement (C90 6.6, C99 6.8).
4358 expression-statement
4366 expression-statement:
4369 selection-statement:
4373 iteration-statement:
4382 return expression[opt] ;
4395 objc-throw-statement
4396 objc-try-catch-statement
4397 objc-synchronized-statement
4399 objc-throw-statement:
4413 parallel-for-construct
4414 parallel-sections-construct
4421 parallel-directive structured-block
4424 for-directive iteration-statement
4427 sections-directive section-scope
4430 single-directive structured-block
4432 parallel-for-construct:
4433 parallel-for-directive iteration-statement
4435 parallel-sections-construct:
4436 parallel-sections-directive section-scope
4439 master-directive structured-block
4442 critical-directive structured-block
4445 atomic-directive expression-statement
4448 ordered-directive structured-block
4450 Transactional Memory:
4453 transaction-statement
4454 transaction-cancel-statement
4458 c_parser_statement (c_parser
*parser
)
4460 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4461 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4462 || (c_parser_next_token_is (parser
, CPP_NAME
)
4463 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4464 c_parser_label (parser
);
4465 c_parser_statement_after_labels (parser
);
4468 /* Parse a statement, other than a labeled statement. */
4471 c_parser_statement_after_labels (c_parser
*parser
)
4473 location_t loc
= c_parser_peek_token (parser
)->location
;
4474 tree stmt
= NULL_TREE
;
4475 bool in_if_block
= parser
->in_if_block
;
4476 parser
->in_if_block
= false;
4477 switch (c_parser_peek_token (parser
)->type
)
4479 case CPP_OPEN_BRACE
:
4480 add_stmt (c_parser_compound_statement (parser
));
4483 switch (c_parser_peek_token (parser
)->keyword
)
4486 c_parser_if_statement (parser
);
4489 c_parser_switch_statement (parser
);
4492 c_parser_while_statement (parser
);
4495 c_parser_do_statement (parser
);
4498 c_parser_for_statement (parser
);
4501 c_parser_consume_token (parser
);
4502 if (c_parser_next_token_is (parser
, CPP_NAME
))
4504 stmt
= c_finish_goto_label (loc
,
4505 c_parser_peek_token (parser
)->value
);
4506 c_parser_consume_token (parser
);
4508 else if (c_parser_next_token_is (parser
, CPP_MULT
))
4512 c_parser_consume_token (parser
);
4513 val
= c_parser_expression (parser
).value
;
4514 mark_exp_read (val
);
4515 stmt
= c_finish_goto_ptr (loc
, val
);
4518 c_parser_error (parser
, "expected identifier or %<*%>");
4519 goto expect_semicolon
;
4521 c_parser_consume_token (parser
);
4522 stmt
= c_finish_bc_stmt (loc
, &c_cont_label
, false);
4523 goto expect_semicolon
;
4525 c_parser_consume_token (parser
);
4526 stmt
= c_finish_bc_stmt (loc
, &c_break_label
, true);
4527 goto expect_semicolon
;
4529 c_parser_consume_token (parser
);
4530 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4532 stmt
= c_finish_return (loc
, NULL_TREE
, NULL_TREE
);
4533 c_parser_consume_token (parser
);
4537 struct c_expr expr
= c_parser_expression_conv (parser
);
4538 mark_exp_read (expr
.value
);
4539 stmt
= c_finish_return (loc
, expr
.value
, expr
.original_type
);
4540 goto expect_semicolon
;
4544 stmt
= c_parser_asm_statement (parser
);
4546 case RID_TRANSACTION_ATOMIC
:
4547 case RID_TRANSACTION_RELAXED
:
4548 stmt
= c_parser_transaction (parser
,
4549 c_parser_peek_token (parser
)->keyword
);
4551 case RID_TRANSACTION_CANCEL
:
4552 stmt
= c_parser_transaction_cancel (parser
);
4553 goto expect_semicolon
;
4555 gcc_assert (c_dialect_objc ());
4556 c_parser_consume_token (parser
);
4557 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4559 stmt
= objc_build_throw_stmt (loc
, NULL_TREE
);
4560 c_parser_consume_token (parser
);
4564 tree expr
= c_parser_expression (parser
).value
;
4565 expr
= c_fully_fold (expr
, false, NULL
);
4566 stmt
= objc_build_throw_stmt (loc
, expr
);
4567 goto expect_semicolon
;
4571 gcc_assert (c_dialect_objc ());
4572 c_parser_objc_try_catch_finally_statement (parser
);
4574 case RID_AT_SYNCHRONIZED
:
4575 gcc_assert (c_dialect_objc ());
4576 c_parser_objc_synchronized_statement (parser
);
4583 c_parser_consume_token (parser
);
4585 case CPP_CLOSE_PAREN
:
4586 case CPP_CLOSE_SQUARE
:
4587 /* Avoid infinite loop in error recovery:
4588 c_parser_skip_until_found stops at a closing nesting
4589 delimiter without consuming it, but here we need to consume
4590 it to proceed further. */
4591 c_parser_error (parser
, "expected statement");
4592 c_parser_consume_token (parser
);
4595 c_parser_pragma (parser
, pragma_stmt
);
4599 stmt
= c_finish_expr_stmt (loc
, c_parser_expression_conv (parser
).value
);
4601 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4604 /* Two cases cannot and do not have line numbers associated: If stmt
4605 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
4606 cannot hold line numbers. But that's OK because the statement
4607 will either be changed to a MODIFY_EXPR during gimplification of
4608 the statement expr, or discarded. If stmt was compound, but
4609 without new variables, we will have skipped the creation of a
4610 BIND and will have a bare STATEMENT_LIST. But that's OK because
4611 (recursively) all of the component statements should already have
4612 line numbers assigned. ??? Can we discard no-op statements
4614 if (CAN_HAVE_LOCATION_P (stmt
)
4615 && EXPR_LOCATION (stmt
) == UNKNOWN_LOCATION
)
4616 SET_EXPR_LOCATION (stmt
, loc
);
4618 parser
->in_if_block
= in_if_block
;
4621 /* Parse the condition from an if, do, while or for statements. */
4624 c_parser_condition (c_parser
*parser
)
4626 location_t loc
= c_parser_peek_token (parser
)->location
;
4628 cond
= c_parser_expression_conv (parser
).value
;
4629 cond
= c_objc_common_truthvalue_conversion (loc
, cond
);
4630 cond
= c_fully_fold (cond
, false, NULL
);
4631 if (warn_sequence_point
)
4632 verify_sequence_points (cond
);
4636 /* Parse a parenthesized condition from an if, do or while statement.
4642 c_parser_paren_condition (c_parser
*parser
)
4645 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4646 return error_mark_node
;
4647 cond
= c_parser_condition (parser
);
4648 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4652 /* Parse a statement which is a block in C99. */
4655 c_parser_c99_block_statement (c_parser
*parser
)
4657 tree block
= c_begin_compound_stmt (flag_isoc99
);
4658 location_t loc
= c_parser_peek_token (parser
)->location
;
4659 c_parser_statement (parser
);
4660 return c_end_compound_stmt (loc
, block
, flag_isoc99
);
4663 /* Parse the body of an if statement. This is just parsing a
4664 statement but (a) it is a block in C99, (b) we track whether the
4665 body is an if statement for the sake of -Wparentheses warnings, (c)
4666 we handle an empty body specially for the sake of -Wempty-body
4667 warnings, and (d) we call parser_compound_statement directly
4668 because c_parser_statement_after_labels resets
4669 parser->in_if_block. */
4672 c_parser_if_body (c_parser
*parser
, bool *if_p
)
4674 tree block
= c_begin_compound_stmt (flag_isoc99
);
4675 location_t body_loc
= c_parser_peek_token (parser
)->location
;
4676 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4677 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4678 || (c_parser_next_token_is (parser
, CPP_NAME
)
4679 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4680 c_parser_label (parser
);
4681 *if_p
= c_parser_next_token_is_keyword (parser
, RID_IF
);
4682 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4684 location_t loc
= c_parser_peek_token (parser
)->location
;
4685 add_stmt (build_empty_stmt (loc
));
4686 c_parser_consume_token (parser
);
4687 if (!c_parser_next_token_is_keyword (parser
, RID_ELSE
))
4688 warning_at (loc
, OPT_Wempty_body
,
4689 "suggest braces around empty body in an %<if%> statement");
4691 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4692 add_stmt (c_parser_compound_statement (parser
));
4694 c_parser_statement_after_labels (parser
);
4695 return c_end_compound_stmt (body_loc
, block
, flag_isoc99
);
4698 /* Parse the else body of an if statement. This is just parsing a
4699 statement but (a) it is a block in C99, (b) we handle an empty body
4700 specially for the sake of -Wempty-body warnings. */
4703 c_parser_else_body (c_parser
*parser
)
4705 location_t else_loc
= c_parser_peek_token (parser
)->location
;
4706 tree block
= c_begin_compound_stmt (flag_isoc99
);
4707 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4708 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4709 || (c_parser_next_token_is (parser
, CPP_NAME
)
4710 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4711 c_parser_label (parser
);
4712 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4714 location_t loc
= c_parser_peek_token (parser
)->location
;
4717 "suggest braces around empty body in an %<else%> statement");
4718 add_stmt (build_empty_stmt (loc
));
4719 c_parser_consume_token (parser
);
4722 c_parser_statement_after_labels (parser
);
4723 return c_end_compound_stmt (else_loc
, block
, flag_isoc99
);
4726 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
4729 if ( expression ) statement
4730 if ( expression ) statement else statement
4734 c_parser_if_statement (c_parser
*parser
)
4739 bool first_if
= false;
4740 tree first_body
, second_body
;
4744 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_IF
));
4745 c_parser_consume_token (parser
);
4746 block
= c_begin_compound_stmt (flag_isoc99
);
4747 loc
= c_parser_peek_token (parser
)->location
;
4748 cond
= c_parser_paren_condition (parser
);
4749 in_if_block
= parser
->in_if_block
;
4750 parser
->in_if_block
= true;
4751 first_body
= c_parser_if_body (parser
, &first_if
);
4752 parser
->in_if_block
= in_if_block
;
4753 if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
4755 c_parser_consume_token (parser
);
4756 second_body
= c_parser_else_body (parser
);
4759 second_body
= NULL_TREE
;
4760 c_finish_if_stmt (loc
, cond
, first_body
, second_body
, first_if
);
4761 if_stmt
= c_end_compound_stmt (loc
, block
, flag_isoc99
);
4763 /* If the if statement contains array notations, then we expand them. */
4764 if (flag_enable_cilkplus
&& contains_array_notation_expr (if_stmt
))
4765 if_stmt
= fix_conditional_array_notations (if_stmt
);
4769 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
4772 switch (expression) statement
4776 c_parser_switch_statement (c_parser
*parser
)
4778 tree block
, expr
, body
, save_break
;
4779 location_t switch_loc
= c_parser_peek_token (parser
)->location
;
4780 location_t switch_cond_loc
;
4781 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SWITCH
));
4782 c_parser_consume_token (parser
);
4783 block
= c_begin_compound_stmt (flag_isoc99
);
4784 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4786 switch_cond_loc
= c_parser_peek_token (parser
)->location
;
4787 expr
= c_parser_expression (parser
).value
;
4788 if (flag_enable_cilkplus
&& contains_array_notation_expr (expr
))
4790 error_at (switch_cond_loc
,
4791 "array notations cannot be used as a condition for switch "
4793 expr
= error_mark_node
;
4795 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4799 switch_cond_loc
= UNKNOWN_LOCATION
;
4800 expr
= error_mark_node
;
4802 c_start_case (switch_loc
, switch_cond_loc
, expr
);
4803 save_break
= c_break_label
;
4804 c_break_label
= NULL_TREE
;
4805 body
= c_parser_c99_block_statement (parser
);
4806 c_finish_case (body
);
4809 location_t here
= c_parser_peek_token (parser
)->location
;
4810 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_break_label
);
4811 SET_EXPR_LOCATION (t
, here
);
4814 c_break_label
= save_break
;
4815 add_stmt (c_end_compound_stmt (switch_loc
, block
, flag_isoc99
));
4818 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
4821 while (expression) statement
4825 c_parser_while_statement (c_parser
*parser
)
4827 tree block
, cond
, body
, save_break
, save_cont
;
4829 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_WHILE
));
4830 c_parser_consume_token (parser
);
4831 block
= c_begin_compound_stmt (flag_isoc99
);
4832 loc
= c_parser_peek_token (parser
)->location
;
4833 cond
= c_parser_paren_condition (parser
);
4834 if (flag_enable_cilkplus
&& contains_array_notation_expr (cond
))
4836 error_at (loc
, "array notations cannot be used as a condition for while "
4838 cond
= error_mark_node
;
4840 save_break
= c_break_label
;
4841 c_break_label
= NULL_TREE
;
4842 save_cont
= c_cont_label
;
4843 c_cont_label
= NULL_TREE
;
4844 body
= c_parser_c99_block_statement (parser
);
4845 c_finish_loop (loc
, cond
, NULL
, body
, c_break_label
, c_cont_label
, true);
4846 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
4847 c_break_label
= save_break
;
4848 c_cont_label
= save_cont
;
4851 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
4854 do statement while ( expression ) ;
4858 c_parser_do_statement (c_parser
*parser
)
4860 tree block
, cond
, body
, save_break
, save_cont
, new_break
, new_cont
;
4862 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_DO
));
4863 c_parser_consume_token (parser
);
4864 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4865 warning_at (c_parser_peek_token (parser
)->location
,
4867 "suggest braces around empty body in %<do%> statement");
4868 block
= c_begin_compound_stmt (flag_isoc99
);
4869 loc
= c_parser_peek_token (parser
)->location
;
4870 save_break
= c_break_label
;
4871 c_break_label
= NULL_TREE
;
4872 save_cont
= c_cont_label
;
4873 c_cont_label
= NULL_TREE
;
4874 body
= c_parser_c99_block_statement (parser
);
4875 c_parser_require_keyword (parser
, RID_WHILE
, "expected %<while%>");
4876 new_break
= c_break_label
;
4877 c_break_label
= save_break
;
4878 new_cont
= c_cont_label
;
4879 c_cont_label
= save_cont
;
4880 cond
= c_parser_paren_condition (parser
);
4881 if (flag_enable_cilkplus
&& contains_array_notation_expr (cond
))
4883 error_at (loc
, "array notations cannot be used as a condition for a "
4884 "do-while statement");
4885 cond
= error_mark_node
;
4888 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
4889 c_parser_skip_to_end_of_block_or_statement (parser
);
4890 c_finish_loop (loc
, cond
, NULL
, body
, new_break
, new_cont
, false);
4891 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
4894 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
4897 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
4898 for ( nested-declaration expression[opt] ; expression[opt] ) statement
4900 The form with a declaration is new in C99.
4902 ??? In accordance with the old parser, the declaration may be a
4903 nested function, which is then rejected in check_for_loop_decls,
4904 but does it make any sense for this to be included in the grammar?
4905 Note in particular that the nested function does not include a
4906 trailing ';', whereas the "declaration" production includes one.
4907 Also, can we reject bad declarations earlier and cheaper than
4908 check_for_loop_decls?
4910 In Objective-C, there are two additional variants:
4913 for ( expression in expresssion ) statement
4914 for ( declaration in expression ) statement
4916 This is inconsistent with C, because the second variant is allowed
4917 even if c99 is not enabled.
4919 The rest of the comment documents these Objective-C foreach-statement.
4921 Here is the canonical example of the first variant:
4922 for (object in array) { do something with object }
4923 we call the first expression ("object") the "object_expression" and
4924 the second expression ("array") the "collection_expression".
4925 object_expression must be an lvalue of type "id" (a generic Objective-C
4926 object) because the loop works by assigning to object_expression the
4927 various objects from the collection_expression. collection_expression
4928 must evaluate to something of type "id" which responds to the method
4929 countByEnumeratingWithState:objects:count:.
4931 The canonical example of the second variant is:
4932 for (id object in array) { do something with object }
4933 which is completely equivalent to
4936 for (object in array) { do something with object }
4938 Note that initizializing 'object' in some way (eg, "for ((object =
4939 xxx) in array) { do something with object }") is possibly
4940 technically valid, but completely pointless as 'object' will be
4941 assigned to something else as soon as the loop starts. We should
4942 most likely reject it (TODO).
4944 The beginning of the Objective-C foreach-statement looks exactly
4945 like the beginning of the for-statement, and we can tell it is a
4946 foreach-statement only because the initial declaration or
4947 expression is terminated by 'in' instead of ';'.
4951 c_parser_for_statement (c_parser
*parser
)
4953 tree block
, cond
, incr
, save_break
, save_cont
, body
;
4954 /* The following are only used when parsing an ObjC foreach statement. */
4955 tree object_expression
;
4956 /* Silence the bogus uninitialized warning. */
4957 tree collection_expression
= NULL
;
4958 location_t loc
= c_parser_peek_token (parser
)->location
;
4959 location_t for_loc
= c_parser_peek_token (parser
)->location
;
4960 bool is_foreach_statement
= false;
4961 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_FOR
));
4962 c_parser_consume_token (parser
);
4963 /* Open a compound statement in Objective-C as well, just in case this is
4964 as foreach expression. */
4965 block
= c_begin_compound_stmt (flag_isoc99
|| c_dialect_objc ());
4966 cond
= error_mark_node
;
4967 incr
= error_mark_node
;
4968 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4970 /* Parse the initialization declaration or expression. */
4971 object_expression
= error_mark_node
;
4972 parser
->objc_could_be_foreach_context
= c_dialect_objc ();
4973 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4975 parser
->objc_could_be_foreach_context
= false;
4976 c_parser_consume_token (parser
);
4977 c_finish_expr_stmt (loc
, NULL_TREE
);
4979 else if (c_parser_next_tokens_start_declaration (parser
))
4981 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
4982 &object_expression
);
4983 parser
->objc_could_be_foreach_context
= false;
4985 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
4987 c_parser_consume_token (parser
);
4988 is_foreach_statement
= true;
4989 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
4990 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
4993 check_for_loop_decls (for_loc
, flag_isoc99
);
4995 else if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
4997 /* __extension__ can start a declaration, but is also an
4998 unary operator that can start an expression. Consume all
4999 but the last of a possible series of __extension__ to
5001 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
5002 && (c_parser_peek_2nd_token (parser
)->keyword
5004 c_parser_consume_token (parser
);
5005 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
5008 ext
= disable_extension_diagnostics ();
5009 c_parser_consume_token (parser
);
5010 c_parser_declaration_or_fndef (parser
, true, true, true, true,
5011 true, &object_expression
);
5012 parser
->objc_could_be_foreach_context
= false;
5014 restore_extension_diagnostics (ext
);
5015 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5017 c_parser_consume_token (parser
);
5018 is_foreach_statement
= true;
5019 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
5020 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
5023 check_for_loop_decls (for_loc
, flag_isoc99
);
5032 tree init_expression
;
5033 init_expression
= c_parser_expression (parser
).value
;
5034 parser
->objc_could_be_foreach_context
= false;
5035 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5037 c_parser_consume_token (parser
);
5038 is_foreach_statement
= true;
5039 if (! lvalue_p (init_expression
))
5040 c_parser_error (parser
, "invalid iterating variable in fast enumeration");
5041 object_expression
= c_fully_fold (init_expression
, false, NULL
);
5045 c_finish_expr_stmt (loc
, init_expression
);
5046 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5050 /* Parse the loop condition. In the case of a foreach
5051 statement, there is no loop condition. */
5052 gcc_assert (!parser
->objc_could_be_foreach_context
);
5053 if (!is_foreach_statement
)
5055 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5057 c_parser_consume_token (parser
);
5062 cond
= c_parser_condition (parser
);
5063 if (flag_enable_cilkplus
&& contains_array_notation_expr (cond
))
5065 error_at (loc
, "array notations cannot be used in a "
5066 "condition for a for-loop");
5067 cond
= error_mark_node
;
5069 c_parser_skip_until_found (parser
, CPP_SEMICOLON
,
5073 /* Parse the increment expression (the third expression in a
5074 for-statement). In the case of a foreach-statement, this is
5075 the expression that follows the 'in'. */
5076 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
5078 if (is_foreach_statement
)
5080 c_parser_error (parser
, "missing collection in fast enumeration");
5081 collection_expression
= error_mark_node
;
5084 incr
= c_process_expr_stmt (loc
, NULL_TREE
);
5088 if (is_foreach_statement
)
5089 collection_expression
= c_fully_fold (c_parser_expression (parser
).value
,
5092 incr
= c_process_expr_stmt (loc
, c_parser_expression (parser
).value
);
5094 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5096 save_break
= c_break_label
;
5097 c_break_label
= NULL_TREE
;
5098 save_cont
= c_cont_label
;
5099 c_cont_label
= NULL_TREE
;
5100 body
= c_parser_c99_block_statement (parser
);
5101 if (is_foreach_statement
)
5102 objc_finish_foreach_loop (loc
, object_expression
, collection_expression
, body
, c_break_label
, c_cont_label
);
5104 c_finish_loop (loc
, cond
, incr
, body
, c_break_label
, c_cont_label
, true);
5105 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
|| c_dialect_objc ()));
5106 c_break_label
= save_break
;
5107 c_cont_label
= save_cont
;
5110 /* Parse an asm statement, a GNU extension. This is a full-blown asm
5111 statement with inputs, outputs, clobbers, and volatile tag
5115 asm type-qualifier[opt] ( asm-argument ) ;
5116 asm type-qualifier[opt] goto ( asm-goto-argument ) ;
5120 asm-string-literal : asm-operands[opt]
5121 asm-string-literal : asm-operands[opt] : asm-operands[opt]
5122 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers[opt]
5125 asm-string-literal : : asm-operands[opt] : asm-clobbers[opt] \
5128 Qualifiers other than volatile are accepted in the syntax but
5132 c_parser_asm_statement (c_parser
*parser
)
5134 tree quals
, str
, outputs
, inputs
, clobbers
, labels
, ret
;
5135 bool simple
, is_goto
;
5136 location_t asm_loc
= c_parser_peek_token (parser
)->location
;
5137 int section
, nsections
;
5139 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
5140 c_parser_consume_token (parser
);
5141 if (c_parser_next_token_is_keyword (parser
, RID_VOLATILE
))
5143 quals
= c_parser_peek_token (parser
)->value
;
5144 c_parser_consume_token (parser
);
5146 else if (c_parser_next_token_is_keyword (parser
, RID_CONST
)
5147 || c_parser_next_token_is_keyword (parser
, RID_RESTRICT
))
5149 warning_at (c_parser_peek_token (parser
)->location
,
5151 "%E qualifier ignored on asm",
5152 c_parser_peek_token (parser
)->value
);
5154 c_parser_consume_token (parser
);
5160 if (c_parser_next_token_is_keyword (parser
, RID_GOTO
))
5162 c_parser_consume_token (parser
);
5166 /* ??? Follow the C++ parser rather than using the
5167 lex_untranslated_string kludge. */
5168 parser
->lex_untranslated_string
= true;
5171 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5174 str
= c_parser_asm_string_literal (parser
);
5175 if (str
== NULL_TREE
)
5176 goto error_close_paren
;
5179 outputs
= NULL_TREE
;
5181 clobbers
= NULL_TREE
;
5184 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
5187 /* Parse each colon-delimited section of operands. */
5188 nsections
= 3 + is_goto
;
5189 for (section
= 0; section
< nsections
; ++section
)
5191 if (!c_parser_require (parser
, CPP_COLON
,
5194 : "expected %<:%> or %<)%>"))
5195 goto error_close_paren
;
5197 /* Once past any colon, we're no longer a simple asm. */
5200 if ((!c_parser_next_token_is (parser
, CPP_COLON
)
5201 && !c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
5206 /* For asm goto, we don't allow output operands, but reserve
5207 the slot for a future extension that does allow them. */
5209 outputs
= c_parser_asm_operands (parser
);
5212 inputs
= c_parser_asm_operands (parser
);
5215 clobbers
= c_parser_asm_clobbers (parser
);
5218 labels
= c_parser_asm_goto_operands (parser
);
5224 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
5229 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
5231 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5235 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
5236 c_parser_skip_to_end_of_block_or_statement (parser
);
5238 ret
= build_asm_stmt (quals
, build_asm_expr (asm_loc
, str
, outputs
, inputs
,
5239 clobbers
, labels
, simple
));
5242 parser
->lex_untranslated_string
= false;
5246 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5250 /* Parse asm operands, a GNU extension.
5254 asm-operands , asm-operand
5257 asm-string-literal ( expression )
5258 [ identifier ] asm-string-literal ( expression )
5262 c_parser_asm_operands (c_parser
*parser
)
5264 tree list
= NULL_TREE
;
5269 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
5271 c_parser_consume_token (parser
);
5272 if (c_parser_next_token_is (parser
, CPP_NAME
))
5274 tree id
= c_parser_peek_token (parser
)->value
;
5275 c_parser_consume_token (parser
);
5276 name
= build_string (IDENTIFIER_LENGTH (id
),
5277 IDENTIFIER_POINTER (id
));
5281 c_parser_error (parser
, "expected identifier");
5282 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
5285 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5290 str
= c_parser_asm_string_literal (parser
);
5291 if (str
== NULL_TREE
)
5293 parser
->lex_untranslated_string
= false;
5294 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5296 parser
->lex_untranslated_string
= true;
5299 expr
= c_parser_expression (parser
);
5300 mark_exp_read (expr
.value
);
5301 parser
->lex_untranslated_string
= true;
5302 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
5304 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5307 list
= chainon (list
, build_tree_list (build_tree_list (name
, str
),
5309 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5310 c_parser_consume_token (parser
);
5317 /* Parse asm clobbers, a GNU extension.
5321 asm-clobbers , asm-string-literal
5325 c_parser_asm_clobbers (c_parser
*parser
)
5327 tree list
= NULL_TREE
;
5330 tree str
= c_parser_asm_string_literal (parser
);
5332 list
= tree_cons (NULL_TREE
, str
, list
);
5335 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5336 c_parser_consume_token (parser
);
5343 /* Parse asm goto labels, a GNU extension.
5347 asm-goto-operands , identifier
5351 c_parser_asm_goto_operands (c_parser
*parser
)
5353 tree list
= NULL_TREE
;
5358 if (c_parser_next_token_is (parser
, CPP_NAME
))
5360 c_token
*tok
= c_parser_peek_token (parser
);
5362 label
= lookup_label_for_goto (tok
->location
, name
);
5363 c_parser_consume_token (parser
);
5364 TREE_USED (label
) = 1;
5368 c_parser_error (parser
, "expected identifier");
5372 name
= build_string (IDENTIFIER_LENGTH (name
),
5373 IDENTIFIER_POINTER (name
));
5374 list
= tree_cons (name
, label
, list
);
5375 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5376 c_parser_consume_token (parser
);
5378 return nreverse (list
);
5382 /* Parse an expression other than a compound expression; that is, an
5383 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
5384 NULL then it is an Objective-C message expression which is the
5385 primary-expression starting the expression as an initializer.
5387 assignment-expression:
5388 conditional-expression
5389 unary-expression assignment-operator assignment-expression
5391 assignment-operator: one of
5392 = *= /= %= += -= <<= >>= &= ^= |=
5394 In GNU C we accept any conditional expression on the LHS and
5395 diagnose the invalid lvalue rather than producing a syntax
5398 static struct c_expr
5399 c_parser_expr_no_commas (c_parser
*parser
, struct c_expr
*after
)
5401 struct c_expr lhs
, rhs
, ret
;
5402 enum tree_code code
;
5403 location_t op_location
, exp_location
;
5404 gcc_assert (!after
|| c_dialect_objc ());
5405 lhs
= c_parser_conditional_expression (parser
, after
);
5406 op_location
= c_parser_peek_token (parser
)->location
;
5407 switch (c_parser_peek_token (parser
)->type
)
5416 code
= TRUNC_DIV_EXPR
;
5419 code
= TRUNC_MOD_EXPR
;
5434 code
= BIT_AND_EXPR
;
5437 code
= BIT_XOR_EXPR
;
5440 code
= BIT_IOR_EXPR
;
5445 c_parser_consume_token (parser
);
5446 exp_location
= c_parser_peek_token (parser
)->location
;
5447 rhs
= c_parser_expr_no_commas (parser
, NULL
);
5448 rhs
= default_function_array_read_conversion (exp_location
, rhs
);
5450 ret
.value
= build_modify_expr (op_location
, lhs
.value
, lhs
.original_type
,
5451 code
, exp_location
, rhs
.value
,
5453 if (code
== NOP_EXPR
)
5454 ret
.original_code
= MODIFY_EXPR
;
5457 TREE_NO_WARNING (ret
.value
) = 1;
5458 ret
.original_code
= ERROR_MARK
;
5460 ret
.original_type
= NULL
;
5464 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
5465 is not NULL then it is an Objective-C message expression which is
5466 the primary-expression starting the expression as an initializer.
5468 conditional-expression:
5469 logical-OR-expression
5470 logical-OR-expression ? expression : conditional-expression
5474 conditional-expression:
5475 logical-OR-expression ? : conditional-expression
5478 static struct c_expr
5479 c_parser_conditional_expression (c_parser
*parser
, struct c_expr
*after
)
5481 struct c_expr cond
, exp1
, exp2
, ret
;
5482 location_t cond_loc
, colon_loc
, middle_loc
;
5484 gcc_assert (!after
|| c_dialect_objc ());
5486 cond
= c_parser_binary_expression (parser
, after
, PREC_NONE
);
5488 if (c_parser_next_token_is_not (parser
, CPP_QUERY
))
5490 cond_loc
= c_parser_peek_token (parser
)->location
;
5491 cond
= default_function_array_read_conversion (cond_loc
, cond
);
5492 c_parser_consume_token (parser
);
5493 if (c_parser_next_token_is (parser
, CPP_COLON
))
5495 tree eptype
= NULL_TREE
;
5497 middle_loc
= c_parser_peek_token (parser
)->location
;
5498 pedwarn (middle_loc
, OPT_Wpedantic
,
5499 "ISO C forbids omitting the middle term of a ?: expression");
5500 warn_for_omitted_condop (middle_loc
, cond
.value
);
5501 if (TREE_CODE (cond
.value
) == EXCESS_PRECISION_EXPR
)
5503 eptype
= TREE_TYPE (cond
.value
);
5504 cond
.value
= TREE_OPERAND (cond
.value
, 0);
5506 /* Make sure first operand is calculated only once. */
5507 exp1
.value
= c_save_expr (default_conversion (cond
.value
));
5509 exp1
.value
= build1 (EXCESS_PRECISION_EXPR
, eptype
, exp1
.value
);
5510 exp1
.original_type
= NULL
;
5511 cond
.value
= c_objc_common_truthvalue_conversion (cond_loc
, exp1
.value
);
5512 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_true_node
;
5517 = c_objc_common_truthvalue_conversion
5518 (cond_loc
, default_conversion (cond
.value
));
5519 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_false_node
;
5520 exp1
= c_parser_expression_conv (parser
);
5521 mark_exp_read (exp1
.value
);
5522 c_inhibit_evaluation_warnings
+=
5523 ((cond
.value
== truthvalue_true_node
)
5524 - (cond
.value
== truthvalue_false_node
));
5527 colon_loc
= c_parser_peek_token (parser
)->location
;
5528 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
5530 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
5531 ret
.value
= error_mark_node
;
5532 ret
.original_code
= ERROR_MARK
;
5533 ret
.original_type
= NULL
;
5537 location_t exp2_loc
= c_parser_peek_token (parser
)->location
;
5538 exp2
= c_parser_conditional_expression (parser
, NULL
);
5539 exp2
= default_function_array_read_conversion (exp2_loc
, exp2
);
5541 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
5542 ret
.value
= build_conditional_expr (colon_loc
, cond
.value
,
5543 cond
.original_code
== C_MAYBE_CONST_EXPR
,
5544 exp1
.value
, exp1
.original_type
,
5545 exp2
.value
, exp2
.original_type
);
5546 ret
.original_code
= ERROR_MARK
;
5547 if (exp1
.value
== error_mark_node
|| exp2
.value
== error_mark_node
)
5548 ret
.original_type
= NULL
;
5553 /* If both sides are enum type, the default conversion will have
5554 made the type of the result be an integer type. We want to
5555 remember the enum types we started with. */
5556 t1
= exp1
.original_type
? exp1
.original_type
: TREE_TYPE (exp1
.value
);
5557 t2
= exp2
.original_type
? exp2
.original_type
: TREE_TYPE (exp2
.value
);
5558 ret
.original_type
= ((t1
!= error_mark_node
5559 && t2
!= error_mark_node
5560 && (TYPE_MAIN_VARIANT (t1
)
5561 == TYPE_MAIN_VARIANT (t2
)))
5568 /* Parse a binary expression; that is, a logical-OR-expression (C90
5569 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
5570 an Objective-C message expression which is the primary-expression
5571 starting the expression as an initializer. PREC is the starting
5572 precedence, usually PREC_NONE.
5574 multiplicative-expression:
5576 multiplicative-expression * cast-expression
5577 multiplicative-expression / cast-expression
5578 multiplicative-expression % cast-expression
5580 additive-expression:
5581 multiplicative-expression
5582 additive-expression + multiplicative-expression
5583 additive-expression - multiplicative-expression
5587 shift-expression << additive-expression
5588 shift-expression >> additive-expression
5590 relational-expression:
5592 relational-expression < shift-expression
5593 relational-expression > shift-expression
5594 relational-expression <= shift-expression
5595 relational-expression >= shift-expression
5597 equality-expression:
5598 relational-expression
5599 equality-expression == relational-expression
5600 equality-expression != relational-expression
5604 AND-expression & equality-expression
5606 exclusive-OR-expression:
5608 exclusive-OR-expression ^ AND-expression
5610 inclusive-OR-expression:
5611 exclusive-OR-expression
5612 inclusive-OR-expression | exclusive-OR-expression
5614 logical-AND-expression:
5615 inclusive-OR-expression
5616 logical-AND-expression && inclusive-OR-expression
5618 logical-OR-expression:
5619 logical-AND-expression
5620 logical-OR-expression || logical-AND-expression
5623 static struct c_expr
5624 c_parser_binary_expression (c_parser
*parser
, struct c_expr
*after
,
5625 enum c_parser_prec prec
)
5627 /* A binary expression is parsed using operator-precedence parsing,
5628 with the operands being cast expressions. All the binary
5629 operators are left-associative. Thus a binary expression is of
5632 E0 op1 E1 op2 E2 ...
5634 which we represent on a stack. On the stack, the precedence
5635 levels are strictly increasing. When a new operator is
5636 encountered of higher precedence than that at the top of the
5637 stack, it is pushed; its LHS is the top expression, and its RHS
5638 is everything parsed until it is popped. When a new operator is
5639 encountered with precedence less than or equal to that at the top
5640 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
5641 by the result of the operation until the operator at the top of
5642 the stack has lower precedence than the new operator or there is
5643 only one element on the stack; then the top expression is the LHS
5644 of the new operator. In the case of logical AND and OR
5645 expressions, we also need to adjust c_inhibit_evaluation_warnings
5646 as appropriate when the operators are pushed and popped. */
5649 /* The expression at this stack level. */
5651 /* The precedence of the operator on its left, PREC_NONE at the
5652 bottom of the stack. */
5653 enum c_parser_prec prec
;
5654 /* The operation on its left. */
5656 /* The source location of this operation. */
5660 /* Location of the binary operator. */
5661 location_t binary_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
5664 switch (stack[sp].op) \
5666 case TRUTH_ANDIF_EXPR: \
5667 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
5668 == truthvalue_false_node); \
5670 case TRUTH_ORIF_EXPR: \
5671 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
5672 == truthvalue_true_node); \
5677 stack[sp - 1].expr \
5678 = default_function_array_read_conversion (stack[sp - 1].loc, \
5679 stack[sp - 1].expr); \
5681 = default_function_array_read_conversion (stack[sp].loc, \
5683 stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc, \
5685 stack[sp - 1].expr, \
5689 gcc_assert (!after
|| c_dialect_objc ());
5690 stack
[0].loc
= c_parser_peek_token (parser
)->location
;
5691 stack
[0].expr
= c_parser_cast_expression (parser
, after
);
5692 stack
[0].prec
= prec
;
5696 enum c_parser_prec oprec
;
5697 enum tree_code ocode
;
5700 switch (c_parser_peek_token (parser
)->type
)
5708 ocode
= TRUNC_DIV_EXPR
;
5712 ocode
= TRUNC_MOD_EXPR
;
5724 ocode
= LSHIFT_EXPR
;
5728 ocode
= RSHIFT_EXPR
;
5742 case CPP_GREATER_EQ
:
5755 oprec
= PREC_BITAND
;
5756 ocode
= BIT_AND_EXPR
;
5759 oprec
= PREC_BITXOR
;
5760 ocode
= BIT_XOR_EXPR
;
5764 ocode
= BIT_IOR_EXPR
;
5767 oprec
= PREC_LOGAND
;
5768 ocode
= TRUTH_ANDIF_EXPR
;
5772 ocode
= TRUTH_ORIF_EXPR
;
5775 /* Not a binary operator, so end of the binary
5779 binary_loc
= c_parser_peek_token (parser
)->location
;
5780 while (oprec
<= stack
[sp
].prec
)
5786 c_parser_consume_token (parser
);
5789 case TRUTH_ANDIF_EXPR
:
5791 = default_function_array_read_conversion (stack
[sp
].loc
,
5793 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
5794 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
5795 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
5796 == truthvalue_false_node
);
5798 case TRUTH_ORIF_EXPR
:
5800 = default_function_array_read_conversion (stack
[sp
].loc
,
5802 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
5803 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
5804 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
5805 == truthvalue_true_node
);
5811 stack
[sp
].loc
= binary_loc
;
5812 stack
[sp
].expr
= c_parser_cast_expression (parser
, NULL
);
5813 stack
[sp
].prec
= oprec
;
5814 stack
[sp
].op
= ocode
;
5815 stack
[sp
].loc
= binary_loc
;
5820 return stack
[0].expr
;
5824 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
5825 NULL then it is an Objective-C message expression which is the
5826 primary-expression starting the expression as an initializer.
5830 ( type-name ) unary-expression
5833 static struct c_expr
5834 c_parser_cast_expression (c_parser
*parser
, struct c_expr
*after
)
5836 location_t cast_loc
= c_parser_peek_token (parser
)->location
;
5837 gcc_assert (!after
|| c_dialect_objc ());
5839 return c_parser_postfix_expression_after_primary (parser
,
5841 /* If the expression begins with a parenthesized type name, it may
5842 be either a cast or a compound literal; we need to see whether
5843 the next character is '{' to tell the difference. If not, it is
5844 an unary expression. Full detection of unknown typenames here
5845 would require a 3-token lookahead. */
5846 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
5847 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
5849 struct c_type_name
*type_name
;
5852 c_parser_consume_token (parser
);
5853 type_name
= c_parser_type_name (parser
);
5854 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5855 if (type_name
== NULL
)
5857 ret
.value
= error_mark_node
;
5858 ret
.original_code
= ERROR_MARK
;
5859 ret
.original_type
= NULL
;
5863 /* Save casted types in the function's used types hash table. */
5864 used_types_insert (type_name
->specs
->type
);
5866 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5867 return c_parser_postfix_expression_after_paren_type (parser
, type_name
,
5870 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
5871 expr
= c_parser_cast_expression (parser
, NULL
);
5872 expr
= default_function_array_read_conversion (expr_loc
, expr
);
5874 ret
.value
= c_cast_expr (cast_loc
, type_name
, expr
.value
);
5875 ret
.original_code
= ERROR_MARK
;
5876 ret
.original_type
= NULL
;
5880 return c_parser_unary_expression (parser
);
5883 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
5889 unary-operator cast-expression
5890 sizeof unary-expression
5891 sizeof ( type-name )
5893 unary-operator: one of
5899 __alignof__ unary-expression
5900 __alignof__ ( type-name )
5903 (C11 permits _Alignof with type names only.)
5905 unary-operator: one of
5906 __extension__ __real__ __imag__
5908 Transactional Memory:
5911 transaction-expression
5913 In addition, the GNU syntax treats ++ and -- as unary operators, so
5914 they may be applied to cast expressions with errors for non-lvalues
5917 static struct c_expr
5918 c_parser_unary_expression (c_parser
*parser
)
5921 struct c_expr ret
, op
;
5922 location_t op_loc
= c_parser_peek_token (parser
)->location
;
5924 ret
.original_code
= ERROR_MARK
;
5925 ret
.original_type
= NULL
;
5926 switch (c_parser_peek_token (parser
)->type
)
5929 c_parser_consume_token (parser
);
5930 exp_loc
= c_parser_peek_token (parser
)->location
;
5931 op
= c_parser_cast_expression (parser
, NULL
);
5933 /* If there is array notations in op, we expand them. */
5934 if (flag_enable_cilkplus
&& TREE_CODE (op
.value
) == ARRAY_NOTATION_REF
)
5935 return fix_array_notation_expr (exp_loc
, PREINCREMENT_EXPR
, op
);
5938 op
= default_function_array_read_conversion (exp_loc
, op
);
5939 return parser_build_unary_op (op_loc
, PREINCREMENT_EXPR
, op
);
5941 case CPP_MINUS_MINUS
:
5942 c_parser_consume_token (parser
);
5943 exp_loc
= c_parser_peek_token (parser
)->location
;
5944 op
= c_parser_cast_expression (parser
, NULL
);
5946 /* If there is array notations in op, we expand them. */
5947 if (flag_enable_cilkplus
&& TREE_CODE (op
.value
) == ARRAY_NOTATION_REF
)
5948 return fix_array_notation_expr (exp_loc
, PREDECREMENT_EXPR
, op
);
5951 op
= default_function_array_read_conversion (exp_loc
, op
);
5952 return parser_build_unary_op (op_loc
, PREDECREMENT_EXPR
, op
);
5955 c_parser_consume_token (parser
);
5956 op
= c_parser_cast_expression (parser
, NULL
);
5957 mark_exp_read (op
.value
);
5958 return parser_build_unary_op (op_loc
, ADDR_EXPR
, op
);
5960 c_parser_consume_token (parser
);
5961 exp_loc
= c_parser_peek_token (parser
)->location
;
5962 op
= c_parser_cast_expression (parser
, NULL
);
5963 op
= default_function_array_read_conversion (exp_loc
, op
);
5964 ret
.value
= build_indirect_ref (op_loc
, op
.value
, RO_UNARY_STAR
);
5967 if (!c_dialect_objc () && !in_system_header
)
5970 "traditional C rejects the unary plus operator");
5971 c_parser_consume_token (parser
);
5972 exp_loc
= c_parser_peek_token (parser
)->location
;
5973 op
= c_parser_cast_expression (parser
, NULL
);
5974 op
= default_function_array_read_conversion (exp_loc
, op
);
5975 return parser_build_unary_op (op_loc
, CONVERT_EXPR
, op
);
5977 c_parser_consume_token (parser
);
5978 exp_loc
= c_parser_peek_token (parser
)->location
;
5979 op
= c_parser_cast_expression (parser
, NULL
);
5980 op
= default_function_array_read_conversion (exp_loc
, op
);
5981 return parser_build_unary_op (op_loc
, NEGATE_EXPR
, op
);
5983 c_parser_consume_token (parser
);
5984 exp_loc
= c_parser_peek_token (parser
)->location
;
5985 op
= c_parser_cast_expression (parser
, NULL
);
5986 op
= default_function_array_read_conversion (exp_loc
, op
);
5987 return parser_build_unary_op (op_loc
, BIT_NOT_EXPR
, op
);
5989 c_parser_consume_token (parser
);
5990 exp_loc
= c_parser_peek_token (parser
)->location
;
5991 op
= c_parser_cast_expression (parser
, NULL
);
5992 op
= default_function_array_read_conversion (exp_loc
, op
);
5993 return parser_build_unary_op (op_loc
, TRUTH_NOT_EXPR
, op
);
5995 /* Refer to the address of a label as a pointer. */
5996 c_parser_consume_token (parser
);
5997 if (c_parser_next_token_is (parser
, CPP_NAME
))
5999 ret
.value
= finish_label_address_expr
6000 (c_parser_peek_token (parser
)->value
, op_loc
);
6001 c_parser_consume_token (parser
);
6005 c_parser_error (parser
, "expected identifier");
6006 ret
.value
= error_mark_node
;
6010 switch (c_parser_peek_token (parser
)->keyword
)
6013 return c_parser_sizeof_expression (parser
);
6015 return c_parser_alignof_expression (parser
);
6017 c_parser_consume_token (parser
);
6018 ext
= disable_extension_diagnostics ();
6019 ret
= c_parser_cast_expression (parser
, NULL
);
6020 restore_extension_diagnostics (ext
);
6023 c_parser_consume_token (parser
);
6024 exp_loc
= c_parser_peek_token (parser
)->location
;
6025 op
= c_parser_cast_expression (parser
, NULL
);
6026 op
= default_function_array_conversion (exp_loc
, op
);
6027 return parser_build_unary_op (op_loc
, REALPART_EXPR
, op
);
6029 c_parser_consume_token (parser
);
6030 exp_loc
= c_parser_peek_token (parser
)->location
;
6031 op
= c_parser_cast_expression (parser
, NULL
);
6032 op
= default_function_array_conversion (exp_loc
, op
);
6033 return parser_build_unary_op (op_loc
, IMAGPART_EXPR
, op
);
6034 case RID_TRANSACTION_ATOMIC
:
6035 case RID_TRANSACTION_RELAXED
:
6036 return c_parser_transaction_expression (parser
,
6037 c_parser_peek_token (parser
)->keyword
);
6039 return c_parser_postfix_expression (parser
);
6042 return c_parser_postfix_expression (parser
);
6046 /* Parse a sizeof expression. */
6048 static struct c_expr
6049 c_parser_sizeof_expression (c_parser
*parser
)
6052 location_t expr_loc
;
6053 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SIZEOF
));
6054 c_parser_consume_token (parser
);
6055 c_inhibit_evaluation_warnings
++;
6057 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
6058 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6060 /* Either sizeof ( type-name ) or sizeof unary-expression
6061 starting with a compound literal. */
6062 struct c_type_name
*type_name
;
6063 c_parser_consume_token (parser
);
6064 expr_loc
= c_parser_peek_token (parser
)->location
;
6065 type_name
= c_parser_type_name (parser
);
6066 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6067 if (type_name
== NULL
)
6070 c_inhibit_evaluation_warnings
--;
6072 ret
.value
= error_mark_node
;
6073 ret
.original_code
= ERROR_MARK
;
6074 ret
.original_type
= NULL
;
6077 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6079 expr
= c_parser_postfix_expression_after_paren_type (parser
,
6084 /* sizeof ( type-name ). */
6085 c_inhibit_evaluation_warnings
--;
6087 return c_expr_sizeof_type (expr_loc
, type_name
);
6091 expr_loc
= c_parser_peek_token (parser
)->location
;
6092 expr
= c_parser_unary_expression (parser
);
6094 c_inhibit_evaluation_warnings
--;
6096 mark_exp_read (expr
.value
);
6097 if (TREE_CODE (expr
.value
) == COMPONENT_REF
6098 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
6099 error_at (expr_loc
, "%<sizeof%> applied to a bit-field");
6100 return c_expr_sizeof_expr (expr_loc
, expr
);
6104 /* Parse an alignof expression. */
6106 static struct c_expr
6107 c_parser_alignof_expression (c_parser
*parser
)
6110 location_t loc
= c_parser_peek_token (parser
)->location
;
6111 tree alignof_spelling
= c_parser_peek_token (parser
)->value
;
6112 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNOF
));
6113 /* A diagnostic is not required for the use of this identifier in
6114 the implementation namespace; only diagnose it for the C11
6115 spelling because of existing code using the other spellings. */
6117 && strcmp (IDENTIFIER_POINTER (alignof_spelling
), "_Alignof") == 0)
6120 pedwarn (loc
, OPT_Wpedantic
, "ISO C99 does not support %qE",
6123 pedwarn (loc
, OPT_Wpedantic
, "ISO C90 does not support %qE",
6126 c_parser_consume_token (parser
);
6127 c_inhibit_evaluation_warnings
++;
6129 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
6130 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6132 /* Either __alignof__ ( type-name ) or __alignof__
6133 unary-expression starting with a compound literal. */
6135 struct c_type_name
*type_name
;
6137 c_parser_consume_token (parser
);
6138 loc
= c_parser_peek_token (parser
)->location
;
6139 type_name
= c_parser_type_name (parser
);
6140 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6141 if (type_name
== NULL
)
6144 c_inhibit_evaluation_warnings
--;
6146 ret
.value
= error_mark_node
;
6147 ret
.original_code
= ERROR_MARK
;
6148 ret
.original_type
= NULL
;
6151 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6153 expr
= c_parser_postfix_expression_after_paren_type (parser
,
6158 /* alignof ( type-name ). */
6159 c_inhibit_evaluation_warnings
--;
6161 ret
.value
= c_alignof (loc
, groktypename (type_name
, NULL
, NULL
));
6162 ret
.original_code
= ERROR_MARK
;
6163 ret
.original_type
= NULL
;
6169 expr
= c_parser_unary_expression (parser
);
6171 mark_exp_read (expr
.value
);
6172 c_inhibit_evaluation_warnings
--;
6174 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not allow %<%E (expression)%>",
6176 ret
.value
= c_alignof_expr (loc
, expr
.value
);
6177 ret
.original_code
= ERROR_MARK
;
6178 ret
.original_type
= NULL
;
6183 /* Helper function to read arguments of builtins which are interfaces
6184 for the middle-end nodes like COMPLEX_EXPR, VEC_PERM_EXPR and
6185 others. The name of the builtin is passed using BNAME parameter.
6186 Function returns true if there were no errors while parsing and
6187 stores the arguments in CEXPR_LIST. */
6189 c_parser_get_builtin_args (c_parser
*parser
, const char *bname
,
6190 vec
<c_expr_t
, va_gc
> **ret_cexpr_list
,
6193 location_t loc
= c_parser_peek_token (parser
)->location
;
6194 vec
<c_expr_t
, va_gc
> *cexpr_list
;
6196 bool saved_force_folding_builtin_constant_p
;
6198 *ret_cexpr_list
= NULL
;
6199 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
6201 error_at (loc
, "cannot take address of %qs", bname
);
6205 c_parser_consume_token (parser
);
6207 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
6209 c_parser_consume_token (parser
);
6213 saved_force_folding_builtin_constant_p
6214 = force_folding_builtin_constant_p
;
6215 force_folding_builtin_constant_p
|= choose_expr_p
;
6216 expr
= c_parser_expr_no_commas (parser
, NULL
);
6217 force_folding_builtin_constant_p
6218 = saved_force_folding_builtin_constant_p
;
6219 vec_alloc (cexpr_list
, 1);
6220 C_EXPR_APPEND (cexpr_list
, expr
);
6221 while (c_parser_next_token_is (parser
, CPP_COMMA
))
6223 c_parser_consume_token (parser
);
6224 expr
= c_parser_expr_no_commas (parser
, NULL
);
6225 C_EXPR_APPEND (cexpr_list
, expr
);
6228 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
6231 *ret_cexpr_list
= cexpr_list
;
6236 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
6240 postfix-expression [ expression ]
6241 postfix-expression ( argument-expression-list[opt] )
6242 postfix-expression . identifier
6243 postfix-expression -> identifier
6244 postfix-expression ++
6245 postfix-expression --
6246 ( type-name ) { initializer-list }
6247 ( type-name ) { initializer-list , }
6249 argument-expression-list:
6251 argument-expression-list , argument-expression
6263 (treated as a keyword in GNU C)
6266 ( compound-statement )
6267 __builtin_va_arg ( assignment-expression , type-name )
6268 __builtin_offsetof ( type-name , offsetof-member-designator )
6269 __builtin_choose_expr ( assignment-expression ,
6270 assignment-expression ,
6271 assignment-expression )
6272 __builtin_types_compatible_p ( type-name , type-name )
6273 __builtin_complex ( assignment-expression , assignment-expression )
6274 __builtin_shuffle ( assignment-expression , assignment-expression )
6275 __builtin_shuffle ( assignment-expression ,
6276 assignment-expression ,
6277 assignment-expression, )
6279 offsetof-member-designator:
6281 offsetof-member-designator . identifier
6282 offsetof-member-designator [ expression ]
6287 [ objc-receiver objc-message-args ]
6288 @selector ( objc-selector-arg )
6289 @protocol ( identifier )
6290 @encode ( type-name )
6292 Classname . identifier
6295 static struct c_expr
6296 c_parser_postfix_expression (c_parser
*parser
)
6298 struct c_expr expr
, e1
;
6299 struct c_type_name
*t1
, *t2
;
6300 location_t loc
= c_parser_peek_token (parser
)->location
;;
6301 expr
.original_code
= ERROR_MARK
;
6302 expr
.original_type
= NULL
;
6303 switch (c_parser_peek_token (parser
)->type
)
6306 expr
.value
= c_parser_peek_token (parser
)->value
;
6307 loc
= c_parser_peek_token (parser
)->location
;
6308 c_parser_consume_token (parser
);
6309 if (TREE_CODE (expr
.value
) == FIXED_CST
6310 && !targetm
.fixed_point_supported_p ())
6312 error_at (loc
, "fixed-point types not supported for this target");
6313 expr
.value
= error_mark_node
;
6320 expr
.value
= c_parser_peek_token (parser
)->value
;
6321 c_parser_consume_token (parser
);
6327 case CPP_UTF8STRING
:
6328 expr
.value
= c_parser_peek_token (parser
)->value
;
6329 expr
.original_code
= STRING_CST
;
6330 c_parser_consume_token (parser
);
6332 case CPP_OBJC_STRING
:
6333 gcc_assert (c_dialect_objc ());
6335 = objc_build_string_object (c_parser_peek_token (parser
)->value
);
6336 c_parser_consume_token (parser
);
6339 switch (c_parser_peek_token (parser
)->id_kind
)
6343 tree id
= c_parser_peek_token (parser
)->value
;
6344 c_parser_consume_token (parser
);
6345 expr
.value
= build_external_ref (loc
, id
,
6346 (c_parser_peek_token (parser
)->type
6348 &expr
.original_type
);
6351 case C_ID_CLASSNAME
:
6353 /* Here we parse the Objective-C 2.0 Class.name dot
6355 tree class_name
= c_parser_peek_token (parser
)->value
;
6357 c_parser_consume_token (parser
);
6358 gcc_assert (c_dialect_objc ());
6359 if (!c_parser_require (parser
, CPP_DOT
, "expected %<.%>"))
6361 expr
.value
= error_mark_node
;
6364 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6366 c_parser_error (parser
, "expected identifier");
6367 expr
.value
= error_mark_node
;
6370 component
= c_parser_peek_token (parser
)->value
;
6371 c_parser_consume_token (parser
);
6372 expr
.value
= objc_build_class_component_ref (class_name
,
6377 c_parser_error (parser
, "expected expression");
6378 expr
.value
= error_mark_node
;
6382 case CPP_OPEN_PAREN
:
6383 /* A parenthesized expression, statement expression or compound
6385 if (c_parser_peek_2nd_token (parser
)->type
== CPP_OPEN_BRACE
)
6387 /* A statement expression. */
6389 location_t brace_loc
;
6390 c_parser_consume_token (parser
);
6391 brace_loc
= c_parser_peek_token (parser
)->location
;
6392 c_parser_consume_token (parser
);
6393 if (!building_stmt_list_p ())
6395 error_at (loc
, "braced-group within expression allowed "
6396 "only inside a function");
6397 parser
->error
= true;
6398 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
6399 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6400 expr
.value
= error_mark_node
;
6403 stmt
= c_begin_stmt_expr ();
6404 c_parser_compound_statement_nostart (parser
);
6405 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6407 pedwarn (loc
, OPT_Wpedantic
,
6408 "ISO C forbids braced-groups within expressions");
6409 expr
.value
= c_finish_stmt_expr (brace_loc
, stmt
);
6410 mark_exp_read (expr
.value
);
6412 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6414 /* A compound literal. ??? Can we actually get here rather
6415 than going directly to
6416 c_parser_postfix_expression_after_paren_type from
6419 struct c_type_name
*type_name
;
6420 c_parser_consume_token (parser
);
6421 loc
= c_parser_peek_token (parser
)->location
;
6422 type_name
= c_parser_type_name (parser
);
6423 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6425 if (type_name
== NULL
)
6427 expr
.value
= error_mark_node
;
6430 expr
= c_parser_postfix_expression_after_paren_type (parser
,
6436 /* A parenthesized expression. */
6437 c_parser_consume_token (parser
);
6438 expr
= c_parser_expression (parser
);
6439 if (TREE_CODE (expr
.value
) == MODIFY_EXPR
)
6440 TREE_NO_WARNING (expr
.value
) = 1;
6441 if (expr
.original_code
!= C_MAYBE_CONST_EXPR
)
6442 expr
.original_code
= ERROR_MARK
;
6443 /* Don't change EXPR.ORIGINAL_TYPE. */
6444 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6449 switch (c_parser_peek_token (parser
)->keyword
)
6451 case RID_FUNCTION_NAME
:
6452 case RID_PRETTY_FUNCTION_NAME
:
6453 case RID_C99_FUNCTION_NAME
:
6454 expr
.value
= fname_decl (loc
,
6455 c_parser_peek_token (parser
)->keyword
,
6456 c_parser_peek_token (parser
)->value
);
6457 c_parser_consume_token (parser
);
6460 c_parser_consume_token (parser
);
6461 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6463 expr
.value
= error_mark_node
;
6466 e1
= c_parser_expr_no_commas (parser
, NULL
);
6467 mark_exp_read (e1
.value
);
6468 e1
.value
= c_fully_fold (e1
.value
, false, NULL
);
6469 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
6471 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6472 expr
.value
= error_mark_node
;
6475 loc
= c_parser_peek_token (parser
)->location
;
6476 t1
= c_parser_type_name (parser
);
6477 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6481 expr
.value
= error_mark_node
;
6485 tree type_expr
= NULL_TREE
;
6486 expr
.value
= c_build_va_arg (loc
, e1
.value
,
6487 groktypename (t1
, &type_expr
, NULL
));
6490 expr
.value
= build2 (C_MAYBE_CONST_EXPR
,
6491 TREE_TYPE (expr
.value
), type_expr
,
6493 C_MAYBE_CONST_EXPR_NON_CONST (expr
.value
) = true;
6498 c_parser_consume_token (parser
);
6499 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6501 expr
.value
= error_mark_node
;
6504 t1
= c_parser_type_name (parser
);
6506 parser
->error
= true;
6507 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
6508 gcc_assert (parser
->error
);
6511 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6512 expr
.value
= error_mark_node
;
6517 tree type
= groktypename (t1
, NULL
, NULL
);
6519 if (type
== error_mark_node
)
6520 offsetof_ref
= error_mark_node
;
6523 offsetof_ref
= build1 (INDIRECT_REF
, type
, null_pointer_node
);
6524 SET_EXPR_LOCATION (offsetof_ref
, loc
);
6526 /* Parse the second argument to __builtin_offsetof. We
6527 must have one identifier, and beyond that we want to
6528 accept sub structure and sub array references. */
6529 if (c_parser_next_token_is (parser
, CPP_NAME
))
6531 offsetof_ref
= build_component_ref
6532 (loc
, offsetof_ref
, c_parser_peek_token (parser
)->value
);
6533 c_parser_consume_token (parser
);
6534 while (c_parser_next_token_is (parser
, CPP_DOT
)
6535 || c_parser_next_token_is (parser
,
6537 || c_parser_next_token_is (parser
,
6540 if (c_parser_next_token_is (parser
, CPP_DEREF
))
6542 loc
= c_parser_peek_token (parser
)->location
;
6543 offsetof_ref
= build_array_ref (loc
,
6548 else if (c_parser_next_token_is (parser
, CPP_DOT
))
6551 c_parser_consume_token (parser
);
6552 if (c_parser_next_token_is_not (parser
,
6555 c_parser_error (parser
, "expected identifier");
6558 offsetof_ref
= build_component_ref
6560 c_parser_peek_token (parser
)->value
);
6561 c_parser_consume_token (parser
);
6566 loc
= c_parser_peek_token (parser
)->location
;
6567 c_parser_consume_token (parser
);
6568 idx
= c_parser_expression (parser
).value
;
6569 idx
= c_fully_fold (idx
, false, NULL
);
6570 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
6572 offsetof_ref
= build_array_ref (loc
, offsetof_ref
, idx
);
6577 c_parser_error (parser
, "expected identifier");
6578 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6580 expr
.value
= fold_offsetof (offsetof_ref
);
6583 case RID_CHOOSE_EXPR
:
6585 vec
<c_expr_t
, va_gc
> *cexpr_list
;
6586 c_expr_t
*e1_p
, *e2_p
, *e3_p
;
6589 c_parser_consume_token (parser
);
6590 if (!c_parser_get_builtin_args (parser
,
6591 "__builtin_choose_expr",
6594 expr
.value
= error_mark_node
;
6598 if (vec_safe_length (cexpr_list
) != 3)
6600 error_at (loc
, "wrong number of arguments to "
6601 "%<__builtin_choose_expr%>");
6602 expr
.value
= error_mark_node
;
6606 e1_p
= &(*cexpr_list
)[0];
6607 e2_p
= &(*cexpr_list
)[1];
6608 e3_p
= &(*cexpr_list
)[2];
6611 mark_exp_read (e2_p
->value
);
6612 mark_exp_read (e3_p
->value
);
6613 if (TREE_CODE (c
) != INTEGER_CST
6614 || !INTEGRAL_TYPE_P (TREE_TYPE (c
)))
6616 "first argument to %<__builtin_choose_expr%> not"
6618 constant_expression_warning (c
);
6619 expr
= integer_zerop (c
) ? *e3_p
: *e2_p
;
6622 case RID_TYPES_COMPATIBLE_P
:
6623 c_parser_consume_token (parser
);
6624 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6626 expr
.value
= error_mark_node
;
6629 t1
= c_parser_type_name (parser
);
6632 expr
.value
= error_mark_node
;
6635 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
6637 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6638 expr
.value
= error_mark_node
;
6641 t2
= c_parser_type_name (parser
);
6644 expr
.value
= error_mark_node
;
6647 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6651 e1
= groktypename (t1
, NULL
, NULL
);
6652 e2
= groktypename (t2
, NULL
, NULL
);
6653 if (e1
== error_mark_node
|| e2
== error_mark_node
)
6655 expr
.value
= error_mark_node
;
6659 e1
= TYPE_MAIN_VARIANT (e1
);
6660 e2
= TYPE_MAIN_VARIANT (e2
);
6663 = comptypes (e1
, e2
) ? integer_one_node
: integer_zero_node
;
6666 case RID_BUILTIN_COMPLEX
:
6668 vec
<c_expr_t
, va_gc
> *cexpr_list
;
6669 c_expr_t
*e1_p
, *e2_p
;
6671 c_parser_consume_token (parser
);
6672 if (!c_parser_get_builtin_args (parser
,
6673 "__builtin_complex",
6674 &cexpr_list
, false))
6676 expr
.value
= error_mark_node
;
6680 if (vec_safe_length (cexpr_list
) != 2)
6682 error_at (loc
, "wrong number of arguments to "
6683 "%<__builtin_complex%>");
6684 expr
.value
= error_mark_node
;
6688 e1_p
= &(*cexpr_list
)[0];
6689 e2_p
= &(*cexpr_list
)[1];
6691 mark_exp_read (e1_p
->value
);
6692 if (TREE_CODE (e1_p
->value
) == EXCESS_PRECISION_EXPR
)
6693 e1_p
->value
= convert (TREE_TYPE (e1_p
->value
),
6694 TREE_OPERAND (e1_p
->value
, 0));
6695 mark_exp_read (e2_p
->value
);
6696 if (TREE_CODE (e2_p
->value
) == EXCESS_PRECISION_EXPR
)
6697 e2_p
->value
= convert (TREE_TYPE (e2_p
->value
),
6698 TREE_OPERAND (e2_p
->value
, 0));
6699 if (!SCALAR_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
6700 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
6701 || !SCALAR_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
))
6702 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
)))
6704 error_at (loc
, "%<__builtin_complex%> operand "
6705 "not of real binary floating-point type");
6706 expr
.value
= error_mark_node
;
6709 if (TYPE_MAIN_VARIANT (TREE_TYPE (e1_p
->value
))
6710 != TYPE_MAIN_VARIANT (TREE_TYPE (e2_p
->value
)))
6713 "%<__builtin_complex%> operands of different types");
6714 expr
.value
= error_mark_node
;
6718 pedwarn (loc
, OPT_Wpedantic
,
6719 "ISO C90 does not support complex types");
6720 expr
.value
= build2 (COMPLEX_EXPR
,
6723 (TREE_TYPE (e1_p
->value
))),
6724 e1_p
->value
, e2_p
->value
);
6727 case RID_BUILTIN_SHUFFLE
:
6729 vec
<c_expr_t
, va_gc
> *cexpr_list
;
6733 c_parser_consume_token (parser
);
6734 if (!c_parser_get_builtin_args (parser
,
6735 "__builtin_shuffle",
6736 &cexpr_list
, false))
6738 expr
.value
= error_mark_node
;
6742 FOR_EACH_VEC_SAFE_ELT (cexpr_list
, i
, p
)
6743 mark_exp_read (p
->value
);
6745 if (vec_safe_length (cexpr_list
) == 2)
6747 c_build_vec_perm_expr
6748 (loc
, (*cexpr_list
)[0].value
,
6749 NULL_TREE
, (*cexpr_list
)[1].value
);
6751 else if (vec_safe_length (cexpr_list
) == 3)
6753 c_build_vec_perm_expr
6754 (loc
, (*cexpr_list
)[0].value
,
6755 (*cexpr_list
)[1].value
,
6756 (*cexpr_list
)[2].value
);
6759 error_at (loc
, "wrong number of arguments to "
6760 "%<__builtin_shuffle%>");
6761 expr
.value
= error_mark_node
;
6765 case RID_AT_SELECTOR
:
6766 gcc_assert (c_dialect_objc ());
6767 c_parser_consume_token (parser
);
6768 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6770 expr
.value
= error_mark_node
;
6774 tree sel
= c_parser_objc_selector_arg (parser
);
6775 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6777 expr
.value
= objc_build_selector_expr (loc
, sel
);
6780 case RID_AT_PROTOCOL
:
6781 gcc_assert (c_dialect_objc ());
6782 c_parser_consume_token (parser
);
6783 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6785 expr
.value
= error_mark_node
;
6788 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6790 c_parser_error (parser
, "expected identifier");
6791 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6792 expr
.value
= error_mark_node
;
6796 tree id
= c_parser_peek_token (parser
)->value
;
6797 c_parser_consume_token (parser
);
6798 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6800 expr
.value
= objc_build_protocol_expr (id
);
6804 /* Extension to support C-structures in the archiver. */
6805 gcc_assert (c_dialect_objc ());
6806 c_parser_consume_token (parser
);
6807 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6809 expr
.value
= error_mark_node
;
6812 t1
= c_parser_type_name (parser
);
6815 expr
.value
= error_mark_node
;
6816 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6819 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6822 tree type
= groktypename (t1
, NULL
, NULL
);
6823 expr
.value
= objc_build_encode_expr (type
);
6827 c_parser_error (parser
, "expected expression");
6828 expr
.value
= error_mark_node
;
6832 case CPP_OPEN_SQUARE
:
6833 if (c_dialect_objc ())
6835 tree receiver
, args
;
6836 c_parser_consume_token (parser
);
6837 receiver
= c_parser_objc_receiver (parser
);
6838 args
= c_parser_objc_message_args (parser
);
6839 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
6841 expr
.value
= objc_build_message_expr (receiver
, args
);
6844 /* Else fall through to report error. */
6846 c_parser_error (parser
, "expected expression");
6847 expr
.value
= error_mark_node
;
6850 return c_parser_postfix_expression_after_primary (parser
, loc
, expr
);
6853 /* Parse a postfix expression after a parenthesized type name: the
6854 brace-enclosed initializer of a compound literal, possibly followed
6855 by some postfix operators. This is separate because it is not
6856 possible to tell until after the type name whether a cast
6857 expression has a cast or a compound literal, or whether the operand
6858 of sizeof is a parenthesized type name or starts with a compound
6859 literal. TYPE_LOC is the location where TYPE_NAME starts--the
6860 location of the first token after the parentheses around the type
6863 static struct c_expr
6864 c_parser_postfix_expression_after_paren_type (c_parser
*parser
,
6865 struct c_type_name
*type_name
,
6866 location_t type_loc
)
6872 location_t start_loc
;
6873 tree type_expr
= NULL_TREE
;
6874 bool type_expr_const
= true;
6875 check_compound_literal_type (type_loc
, type_name
);
6876 start_init (NULL_TREE
, NULL
, 0);
6877 type
= groktypename (type_name
, &type_expr
, &type_expr_const
);
6878 start_loc
= c_parser_peek_token (parser
)->location
;
6879 if (type
!= error_mark_node
&& C_TYPE_VARIABLE_SIZE (type
))
6881 error_at (type_loc
, "compound literal has variable size");
6882 type
= error_mark_node
;
6884 init
= c_parser_braced_init (parser
, type
, false);
6886 maybe_warn_string_init (type
, init
);
6888 if (type
!= error_mark_node
6889 && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type
))
6890 && current_function_decl
)
6892 error ("compound literal qualified by address-space qualifier");
6893 type
= error_mark_node
;
6897 pedwarn (start_loc
, OPT_Wpedantic
, "ISO C90 forbids compound literals");
6898 non_const
= ((init
.value
&& TREE_CODE (init
.value
) == CONSTRUCTOR
)
6899 ? CONSTRUCTOR_NON_CONST (init
.value
)
6900 : init
.original_code
== C_MAYBE_CONST_EXPR
);
6901 non_const
|= !type_expr_const
;
6902 expr
.value
= build_compound_literal (start_loc
, type
, init
.value
, non_const
);
6903 expr
.original_code
= ERROR_MARK
;
6904 expr
.original_type
= NULL
;
6907 if (TREE_CODE (expr
.value
) == C_MAYBE_CONST_EXPR
)
6909 gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr
.value
) == NULL_TREE
);
6910 C_MAYBE_CONST_EXPR_PRE (expr
.value
) = type_expr
;
6914 gcc_assert (!non_const
);
6915 expr
.value
= build2 (C_MAYBE_CONST_EXPR
, type
,
6916 type_expr
, expr
.value
);
6919 return c_parser_postfix_expression_after_primary (parser
, start_loc
, expr
);
6922 /* Callback function for sizeof_pointer_memaccess_warning to compare
6926 sizeof_ptr_memacc_comptypes (tree type1
, tree type2
)
6928 return comptypes (type1
, type2
) == 1;
6931 /* Parse a postfix expression after the initial primary or compound
6932 literal; that is, parse a series of postfix operators.
6934 EXPR_LOC is the location of the primary expression. */
6936 static struct c_expr
6937 c_parser_postfix_expression_after_primary (c_parser
*parser
,
6938 location_t expr_loc
,
6941 struct c_expr orig_expr
;
6943 location_t sizeof_arg_loc
[3];
6946 vec
<tree
, va_gc
> *exprlist
;
6947 vec
<tree
, va_gc
> *origtypes
= NULL
;
6950 location_t op_loc
= c_parser_peek_token (parser
)->location
;
6951 switch (c_parser_peek_token (parser
)->type
)
6953 case CPP_OPEN_SQUARE
:
6954 /* Array reference. */
6955 c_parser_consume_token (parser
);
6956 if (flag_enable_cilkplus
6957 && c_parser_peek_token (parser
)->type
== CPP_COLON
)
6958 /* If we are here, then we have something like this:
6961 expr
.value
= c_parser_array_notation (expr_loc
, parser
, NULL_TREE
,
6965 idx
= c_parser_expression (parser
).value
;
6966 /* Here we have 3 options:
6967 1. Array [EXPR] -- Normal Array call.
6968 2. Array [EXPR : EXPR] -- Array notation without stride.
6969 3. Array [EXPR : EXPR : EXPR] -- Array notation with stride.
6971 For 1, we just handle it just like a normal array expression.
6972 For 2 and 3 we handle it like we handle array notations. The
6973 idx value we have above becomes the initial/start index.
6975 if (flag_enable_cilkplus
6976 && c_parser_peek_token (parser
)->type
== CPP_COLON
)
6977 expr
.value
= c_parser_array_notation (expr_loc
, parser
, idx
,
6981 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
6983 expr
.value
= build_array_ref (op_loc
, expr
.value
, idx
);
6986 expr
.original_code
= ERROR_MARK
;
6987 expr
.original_type
= NULL
;
6989 case CPP_OPEN_PAREN
:
6990 /* Function call. */
6991 c_parser_consume_token (parser
);
6992 for (i
= 0; i
< 3; i
++)
6994 sizeof_arg
[i
] = NULL_TREE
;
6995 sizeof_arg_loc
[i
] = UNKNOWN_LOCATION
;
6997 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
7000 exprlist
= c_parser_expr_list (parser
, true, false, &origtypes
,
7001 sizeof_arg_loc
, sizeof_arg
);
7002 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7005 mark_exp_read (expr
.value
);
7006 if (warn_sizeof_pointer_memaccess
)
7007 sizeof_pointer_memaccess_warning (sizeof_arg_loc
,
7008 expr
.value
, exprlist
,
7010 sizeof_ptr_memacc_comptypes
);
7011 /* FIXME diagnostics: Ideally we want the FUNCNAME, not the
7012 "(" after the FUNCNAME, which is what we have now. */
7013 expr
.value
= build_function_call_vec (op_loc
, expr
.value
, exprlist
,
7015 expr
.original_code
= ERROR_MARK
;
7016 if (TREE_CODE (expr
.value
) == INTEGER_CST
7017 && TREE_CODE (orig_expr
.value
) == FUNCTION_DECL
7018 && DECL_BUILT_IN_CLASS (orig_expr
.value
) == BUILT_IN_NORMAL
7019 && DECL_FUNCTION_CODE (orig_expr
.value
) == BUILT_IN_CONSTANT_P
)
7020 expr
.original_code
= C_MAYBE_CONST_EXPR
;
7021 expr
.original_type
= NULL
;
7024 release_tree_vector (exprlist
);
7025 release_tree_vector (origtypes
);
7029 /* Structure element reference. */
7030 c_parser_consume_token (parser
);
7031 expr
= default_function_array_conversion (expr_loc
, expr
);
7032 if (c_parser_next_token_is (parser
, CPP_NAME
))
7033 ident
= c_parser_peek_token (parser
)->value
;
7036 c_parser_error (parser
, "expected identifier");
7037 expr
.value
= error_mark_node
;
7038 expr
.original_code
= ERROR_MARK
;
7039 expr
.original_type
= NULL
;
7042 c_parser_consume_token (parser
);
7043 expr
.value
= build_component_ref (op_loc
, expr
.value
, ident
);
7044 expr
.original_code
= ERROR_MARK
;
7045 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
7046 expr
.original_type
= NULL
;
7049 /* Remember the original type of a bitfield. */
7050 tree field
= TREE_OPERAND (expr
.value
, 1);
7051 if (TREE_CODE (field
) != FIELD_DECL
)
7052 expr
.original_type
= NULL
;
7054 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
7058 /* Structure element reference. */
7059 c_parser_consume_token (parser
);
7060 expr
= default_function_array_conversion (expr_loc
, expr
);
7061 if (c_parser_next_token_is (parser
, CPP_NAME
))
7062 ident
= c_parser_peek_token (parser
)->value
;
7065 c_parser_error (parser
, "expected identifier");
7066 expr
.value
= error_mark_node
;
7067 expr
.original_code
= ERROR_MARK
;
7068 expr
.original_type
= NULL
;
7071 c_parser_consume_token (parser
);
7072 expr
.value
= build_component_ref (op_loc
,
7073 build_indirect_ref (op_loc
,
7077 expr
.original_code
= ERROR_MARK
;
7078 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
7079 expr
.original_type
= NULL
;
7082 /* Remember the original type of a bitfield. */
7083 tree field
= TREE_OPERAND (expr
.value
, 1);
7084 if (TREE_CODE (field
) != FIELD_DECL
)
7085 expr
.original_type
= NULL
;
7087 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
7091 /* Postincrement. */
7092 c_parser_consume_token (parser
);
7093 /* If the expressions have array notations, we expand them. */
7094 if (flag_enable_cilkplus
7095 && TREE_CODE (expr
.value
) == ARRAY_NOTATION_REF
)
7096 expr
= fix_array_notation_expr (expr_loc
, POSTINCREMENT_EXPR
, expr
);
7099 expr
= default_function_array_read_conversion (expr_loc
, expr
);
7100 expr
.value
= build_unary_op (op_loc
,
7101 POSTINCREMENT_EXPR
, expr
.value
, 0);
7103 expr
.original_code
= ERROR_MARK
;
7104 expr
.original_type
= NULL
;
7106 case CPP_MINUS_MINUS
:
7107 /* Postdecrement. */
7108 c_parser_consume_token (parser
);
7109 /* If the expressions have array notations, we expand them. */
7110 if (flag_enable_cilkplus
7111 && TREE_CODE (expr
.value
) == ARRAY_NOTATION_REF
)
7112 expr
= fix_array_notation_expr (expr_loc
, POSTDECREMENT_EXPR
, expr
);
7115 expr
= default_function_array_read_conversion (expr_loc
, expr
);
7116 expr
.value
= build_unary_op (op_loc
,
7117 POSTDECREMENT_EXPR
, expr
.value
, 0);
7119 expr
.original_code
= ERROR_MARK
;
7120 expr
.original_type
= NULL
;
7128 /* Parse an expression (C90 6.3.17, C99 6.5.17).
7131 assignment-expression
7132 expression , assignment-expression
7135 static struct c_expr
7136 c_parser_expression (c_parser
*parser
)
7139 expr
= c_parser_expr_no_commas (parser
, NULL
);
7140 while (c_parser_next_token_is (parser
, CPP_COMMA
))
7144 location_t loc
= c_parser_peek_token (parser
)->location
;
7145 location_t expr_loc
;
7146 c_parser_consume_token (parser
);
7147 expr_loc
= c_parser_peek_token (parser
)->location
;
7148 lhsval
= expr
.value
;
7149 while (TREE_CODE (lhsval
) == COMPOUND_EXPR
)
7150 lhsval
= TREE_OPERAND (lhsval
, 1);
7151 if (DECL_P (lhsval
) || handled_component_p (lhsval
))
7152 mark_exp_read (lhsval
);
7153 next
= c_parser_expr_no_commas (parser
, NULL
);
7154 next
= default_function_array_conversion (expr_loc
, next
);
7155 expr
.value
= build_compound_expr (loc
, expr
.value
, next
.value
);
7156 expr
.original_code
= COMPOUND_EXPR
;
7157 expr
.original_type
= next
.original_type
;
7162 /* Parse an expression and convert functions or arrays to
7165 static struct c_expr
7166 c_parser_expression_conv (c_parser
*parser
)
7169 location_t loc
= c_parser_peek_token (parser
)->location
;
7170 expr
= c_parser_expression (parser
);
7171 expr
= default_function_array_conversion (loc
, expr
);
7175 /* Parse a non-empty list of expressions. If CONVERT_P, convert
7176 functions and arrays to pointers. If FOLD_P, fold the expressions.
7179 assignment-expression
7180 nonempty-expr-list , assignment-expression
7183 static vec
<tree
, va_gc
> *
7184 c_parser_expr_list (c_parser
*parser
, bool convert_p
, bool fold_p
,
7185 vec
<tree
, va_gc
> **p_orig_types
,
7186 location_t
*sizeof_arg_loc
, tree
*sizeof_arg
)
7188 vec
<tree
, va_gc
> *ret
;
7189 vec
<tree
, va_gc
> *orig_types
;
7191 location_t loc
= c_parser_peek_token (parser
)->location
;
7192 location_t cur_sizeof_arg_loc
= UNKNOWN_LOCATION
;
7193 unsigned int idx
= 0;
7195 ret
= make_tree_vector ();
7196 if (p_orig_types
== NULL
)
7199 orig_types
= make_tree_vector ();
7201 if (sizeof_arg
!= NULL
7202 && c_parser_next_token_is_keyword (parser
, RID_SIZEOF
))
7203 cur_sizeof_arg_loc
= c_parser_peek_2nd_token (parser
)->location
;
7204 expr
= c_parser_expr_no_commas (parser
, NULL
);
7206 expr
= default_function_array_read_conversion (loc
, expr
);
7208 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
7209 ret
->quick_push (expr
.value
);
7211 orig_types
->quick_push (expr
.original_type
);
7212 if (sizeof_arg
!= NULL
7213 && cur_sizeof_arg_loc
!= UNKNOWN_LOCATION
7214 && expr
.original_code
== SIZEOF_EXPR
)
7216 sizeof_arg
[0] = c_last_sizeof_arg
;
7217 sizeof_arg_loc
[0] = cur_sizeof_arg_loc
;
7219 while (c_parser_next_token_is (parser
, CPP_COMMA
))
7221 c_parser_consume_token (parser
);
7222 loc
= c_parser_peek_token (parser
)->location
;
7223 if (sizeof_arg
!= NULL
7224 && c_parser_next_token_is_keyword (parser
, RID_SIZEOF
))
7225 cur_sizeof_arg_loc
= c_parser_peek_2nd_token (parser
)->location
;
7227 cur_sizeof_arg_loc
= UNKNOWN_LOCATION
;
7228 expr
= c_parser_expr_no_commas (parser
, NULL
);
7230 expr
= default_function_array_read_conversion (loc
, expr
);
7232 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
7233 vec_safe_push (ret
, expr
.value
);
7235 vec_safe_push (orig_types
, expr
.original_type
);
7237 && sizeof_arg
!= NULL
7238 && cur_sizeof_arg_loc
!= UNKNOWN_LOCATION
7239 && expr
.original_code
== SIZEOF_EXPR
)
7241 sizeof_arg
[idx
] = c_last_sizeof_arg
;
7242 sizeof_arg_loc
[idx
] = cur_sizeof_arg_loc
;
7246 *p_orig_types
= orig_types
;
7250 /* Parse Objective-C-specific constructs. */
7252 /* Parse an objc-class-definition.
7254 objc-class-definition:
7255 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
7256 objc-class-instance-variables[opt] objc-methodprotolist @end
7257 @implementation identifier objc-superclass[opt]
7258 objc-class-instance-variables[opt]
7259 @interface identifier ( identifier ) objc-protocol-refs[opt]
7260 objc-methodprotolist @end
7261 @interface identifier ( ) objc-protocol-refs[opt]
7262 objc-methodprotolist @end
7263 @implementation identifier ( identifier )
7268 "@interface identifier (" must start "@interface identifier (
7269 identifier ) ...": objc-methodprotolist in the first production may
7270 not start with a parenthesized identifier as a declarator of a data
7271 definition with no declaration specifiers if the objc-superclass,
7272 objc-protocol-refs and objc-class-instance-variables are omitted. */
7275 c_parser_objc_class_definition (c_parser
*parser
, tree attributes
)
7280 if (c_parser_next_token_is_keyword (parser
, RID_AT_INTERFACE
))
7282 else if (c_parser_next_token_is_keyword (parser
, RID_AT_IMPLEMENTATION
))
7287 c_parser_consume_token (parser
);
7288 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7290 c_parser_error (parser
, "expected identifier");
7293 id1
= c_parser_peek_token (parser
)->value
;
7294 c_parser_consume_token (parser
);
7295 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
7297 /* We have a category or class extension. */
7299 tree proto
= NULL_TREE
;
7300 c_parser_consume_token (parser
);
7301 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7303 if (iface_p
&& c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
7305 /* We have a class extension. */
7310 c_parser_error (parser
, "expected identifier or %<)%>");
7311 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7317 id2
= c_parser_peek_token (parser
)->value
;
7318 c_parser_consume_token (parser
);
7320 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7323 objc_start_category_implementation (id1
, id2
);
7326 if (c_parser_next_token_is (parser
, CPP_LESS
))
7327 proto
= c_parser_objc_protocol_refs (parser
);
7328 objc_start_category_interface (id1
, id2
, proto
, attributes
);
7329 c_parser_objc_methodprotolist (parser
);
7330 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
7331 objc_finish_interface ();
7334 if (c_parser_next_token_is (parser
, CPP_COLON
))
7336 c_parser_consume_token (parser
);
7337 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7339 c_parser_error (parser
, "expected identifier");
7342 superclass
= c_parser_peek_token (parser
)->value
;
7343 c_parser_consume_token (parser
);
7346 superclass
= NULL_TREE
;
7349 tree proto
= NULL_TREE
;
7350 if (c_parser_next_token_is (parser
, CPP_LESS
))
7351 proto
= c_parser_objc_protocol_refs (parser
);
7352 objc_start_class_interface (id1
, superclass
, proto
, attributes
);
7355 objc_start_class_implementation (id1
, superclass
);
7356 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
7357 c_parser_objc_class_instance_variables (parser
);
7360 objc_continue_interface ();
7361 c_parser_objc_methodprotolist (parser
);
7362 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
7363 objc_finish_interface ();
7367 objc_continue_implementation ();
7372 /* Parse objc-class-instance-variables.
7374 objc-class-instance-variables:
7375 { objc-instance-variable-decl-list[opt] }
7377 objc-instance-variable-decl-list:
7378 objc-visibility-spec
7379 objc-instance-variable-decl ;
7381 objc-instance-variable-decl-list objc-visibility-spec
7382 objc-instance-variable-decl-list objc-instance-variable-decl ;
7383 objc-instance-variable-decl-list ;
7385 objc-visibility-spec:
7390 objc-instance-variable-decl:
7395 c_parser_objc_class_instance_variables (c_parser
*parser
)
7397 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
7398 c_parser_consume_token (parser
);
7399 while (c_parser_next_token_is_not (parser
, CPP_EOF
))
7402 /* Parse any stray semicolon. */
7403 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
7405 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
7407 c_parser_consume_token (parser
);
7410 /* Stop if at the end of the instance variables. */
7411 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
7413 c_parser_consume_token (parser
);
7416 /* Parse any objc-visibility-spec. */
7417 if (c_parser_next_token_is_keyword (parser
, RID_AT_PRIVATE
))
7419 c_parser_consume_token (parser
);
7420 objc_set_visibility (OBJC_IVAR_VIS_PRIVATE
);
7423 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROTECTED
))
7425 c_parser_consume_token (parser
);
7426 objc_set_visibility (OBJC_IVAR_VIS_PROTECTED
);
7429 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PUBLIC
))
7431 c_parser_consume_token (parser
);
7432 objc_set_visibility (OBJC_IVAR_VIS_PUBLIC
);
7435 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PACKAGE
))
7437 c_parser_consume_token (parser
);
7438 objc_set_visibility (OBJC_IVAR_VIS_PACKAGE
);
7441 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
7443 c_parser_pragma (parser
, pragma_external
);
7447 /* Parse some comma-separated declarations. */
7448 decls
= c_parser_struct_declaration (parser
);
7451 /* There is a syntax error. We want to skip the offending
7452 tokens up to the next ';' (included) or '}'
7455 /* First, skip manually a ')' or ']'. This is because they
7456 reduce the nesting level, so c_parser_skip_until_found()
7457 wouldn't be able to skip past them. */
7458 c_token
*token
= c_parser_peek_token (parser
);
7459 if (token
->type
== CPP_CLOSE_PAREN
|| token
->type
== CPP_CLOSE_SQUARE
)
7460 c_parser_consume_token (parser
);
7462 /* Then, do the standard skipping. */
7463 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
7465 /* We hopefully recovered. Start normal parsing again. */
7466 parser
->error
= false;
7471 /* Comma-separated instance variables are chained together
7472 in reverse order; add them one by one. */
7473 tree ivar
= nreverse (decls
);
7474 for (; ivar
; ivar
= DECL_CHAIN (ivar
))
7475 objc_add_instance_variable (copy_node (ivar
));
7477 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7481 /* Parse an objc-class-declaration.
7483 objc-class-declaration:
7484 @class identifier-list ;
7488 c_parser_objc_class_declaration (c_parser
*parser
)
7490 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_CLASS
));
7491 c_parser_consume_token (parser
);
7492 /* Any identifiers, including those declared as type names, are OK
7497 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7499 c_parser_error (parser
, "expected identifier");
7500 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
7501 parser
->error
= false;
7504 id
= c_parser_peek_token (parser
)->value
;
7505 objc_declare_class (id
);
7506 c_parser_consume_token (parser
);
7507 if (c_parser_next_token_is (parser
, CPP_COMMA
))
7508 c_parser_consume_token (parser
);
7512 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7515 /* Parse an objc-alias-declaration.
7517 objc-alias-declaration:
7518 @compatibility_alias identifier identifier ;
7522 c_parser_objc_alias_declaration (c_parser
*parser
)
7525 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_ALIAS
));
7526 c_parser_consume_token (parser
);
7527 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7529 c_parser_error (parser
, "expected identifier");
7530 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
7533 id1
= c_parser_peek_token (parser
)->value
;
7534 c_parser_consume_token (parser
);
7535 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7537 c_parser_error (parser
, "expected identifier");
7538 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
7541 id2
= c_parser_peek_token (parser
)->value
;
7542 c_parser_consume_token (parser
);
7543 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7544 objc_declare_alias (id1
, id2
);
7547 /* Parse an objc-protocol-definition.
7549 objc-protocol-definition:
7550 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
7551 @protocol identifier-list ;
7553 "@protocol identifier ;" should be resolved as "@protocol
7554 identifier-list ;": objc-methodprotolist may not start with a
7555 semicolon in the first alternative if objc-protocol-refs are
7559 c_parser_objc_protocol_definition (c_parser
*parser
, tree attributes
)
7561 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROTOCOL
));
7563 c_parser_consume_token (parser
);
7564 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7566 c_parser_error (parser
, "expected identifier");
7569 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
7570 || c_parser_peek_2nd_token (parser
)->type
== CPP_SEMICOLON
)
7572 /* Any identifiers, including those declared as type names, are
7577 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7579 c_parser_error (parser
, "expected identifier");
7582 id
= c_parser_peek_token (parser
)->value
;
7583 objc_declare_protocol (id
, attributes
);
7584 c_parser_consume_token (parser
);
7585 if (c_parser_next_token_is (parser
, CPP_COMMA
))
7586 c_parser_consume_token (parser
);
7590 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7594 tree id
= c_parser_peek_token (parser
)->value
;
7595 tree proto
= NULL_TREE
;
7596 c_parser_consume_token (parser
);
7597 if (c_parser_next_token_is (parser
, CPP_LESS
))
7598 proto
= c_parser_objc_protocol_refs (parser
);
7599 parser
->objc_pq_context
= true;
7600 objc_start_protocol (id
, proto
, attributes
);
7601 c_parser_objc_methodprotolist (parser
);
7602 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
7603 parser
->objc_pq_context
= false;
7604 objc_finish_interface ();
7608 /* Parse an objc-method-type.
7614 Return true if it is a class method (+) and false if it is
7615 an instance method (-).
7618 c_parser_objc_method_type (c_parser
*parser
)
7620 switch (c_parser_peek_token (parser
)->type
)
7623 c_parser_consume_token (parser
);
7626 c_parser_consume_token (parser
);
7633 /* Parse an objc-method-definition.
7635 objc-method-definition:
7636 objc-method-type objc-method-decl ;[opt] compound-statement
7640 c_parser_objc_method_definition (c_parser
*parser
)
7642 bool is_class_method
= c_parser_objc_method_type (parser
);
7643 tree decl
, attributes
= NULL_TREE
, expr
= NULL_TREE
;
7644 parser
->objc_pq_context
= true;
7645 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
7647 if (decl
== error_mark_node
)
7648 return; /* Bail here. */
7650 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
7652 c_parser_consume_token (parser
);
7653 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
7654 "extra semicolon in method definition specified");
7657 if (!c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
7659 c_parser_error (parser
, "expected %<{%>");
7663 parser
->objc_pq_context
= false;
7664 if (objc_start_method_definition (is_class_method
, decl
, attributes
, expr
))
7666 add_stmt (c_parser_compound_statement (parser
));
7667 objc_finish_method_definition (current_function_decl
);
7671 /* This code is executed when we find a method definition
7672 outside of an @implementation context (or invalid for other
7673 reasons). Parse the method (to keep going) but do not emit
7676 c_parser_compound_statement (parser
);
7680 /* Parse an objc-methodprotolist.
7682 objc-methodprotolist:
7684 objc-methodprotolist objc-methodproto
7685 objc-methodprotolist declaration
7686 objc-methodprotolist ;
7690 The declaration is a data definition, which may be missing
7691 declaration specifiers under the same rules and diagnostics as
7692 other data definitions outside functions, and the stray semicolon
7693 is diagnosed the same way as a stray semicolon outside a
7697 c_parser_objc_methodprotolist (c_parser
*parser
)
7701 /* The list is terminated by @end. */
7702 switch (c_parser_peek_token (parser
)->type
)
7705 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
7706 "ISO C does not allow extra %<;%> outside of a function");
7707 c_parser_consume_token (parser
);
7711 c_parser_objc_methodproto (parser
);
7714 c_parser_pragma (parser
, pragma_external
);
7719 if (c_parser_next_token_is_keyword (parser
, RID_AT_END
))
7721 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
))
7722 c_parser_objc_at_property_declaration (parser
);
7723 else if (c_parser_next_token_is_keyword (parser
, RID_AT_OPTIONAL
))
7725 objc_set_method_opt (true);
7726 c_parser_consume_token (parser
);
7728 else if (c_parser_next_token_is_keyword (parser
, RID_AT_REQUIRED
))
7730 objc_set_method_opt (false);
7731 c_parser_consume_token (parser
);
7734 c_parser_declaration_or_fndef (parser
, false, false, true,
7741 /* Parse an objc-methodproto.
7744 objc-method-type objc-method-decl ;
7748 c_parser_objc_methodproto (c_parser
*parser
)
7750 bool is_class_method
= c_parser_objc_method_type (parser
);
7751 tree decl
, attributes
= NULL_TREE
;
7753 /* Remember protocol qualifiers in prototypes. */
7754 parser
->objc_pq_context
= true;
7755 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
7757 /* Forget protocol qualifiers now. */
7758 parser
->objc_pq_context
= false;
7760 /* Do not allow the presence of attributes to hide an erroneous
7761 method implementation in the interface section. */
7762 if (!c_parser_next_token_is (parser
, CPP_SEMICOLON
))
7764 c_parser_error (parser
, "expected %<;%>");
7768 if (decl
!= error_mark_node
)
7769 objc_add_method_declaration (is_class_method
, decl
, attributes
);
7771 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7774 /* If we are at a position that method attributes may be present, check that
7775 there are not any parsed already (a syntax error) and then collect any
7776 specified at the current location. Finally, if new attributes were present,
7777 check that the next token is legal ( ';' for decls and '{' for defs). */
7780 c_parser_objc_maybe_method_attributes (c_parser
* parser
, tree
* attributes
)
7785 c_parser_error (parser
,
7786 "method attributes must be specified at the end only");
7787 *attributes
= NULL_TREE
;
7791 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
7792 *attributes
= c_parser_attributes (parser
);
7794 /* If there were no attributes here, just report any earlier error. */
7795 if (*attributes
== NULL_TREE
|| bad
)
7798 /* If the attributes are followed by a ; or {, then just report any earlier
7800 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
7801 || c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
7804 /* We've got attributes, but not at the end. */
7805 c_parser_error (parser
,
7806 "expected %<;%> or %<{%> after method attribute definition");
7810 /* Parse an objc-method-decl.
7813 ( objc-type-name ) objc-selector
7815 ( objc-type-name ) objc-keyword-selector objc-optparmlist
7816 objc-keyword-selector objc-optparmlist
7819 objc-keyword-selector:
7821 objc-keyword-selector objc-keyword-decl
7824 objc-selector : ( objc-type-name ) identifier
7825 objc-selector : identifier
7826 : ( objc-type-name ) identifier
7830 objc-optparms objc-optellipsis
7834 objc-opt-parms , parameter-declaration
7842 c_parser_objc_method_decl (c_parser
*parser
, bool is_class_method
,
7843 tree
*attributes
, tree
*expr
)
7845 tree type
= NULL_TREE
;
7847 tree parms
= NULL_TREE
;
7848 bool ellipsis
= false;
7849 bool attr_err
= false;
7851 *attributes
= NULL_TREE
;
7852 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
7854 c_parser_consume_token (parser
);
7855 type
= c_parser_objc_type_name (parser
);
7856 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7858 sel
= c_parser_objc_selector (parser
);
7859 /* If there is no selector, or a colon follows, we have an
7860 objc-keyword-selector. If there is a selector, and a colon does
7861 not follow, that selector ends the objc-method-decl. */
7862 if (!sel
|| c_parser_next_token_is (parser
, CPP_COLON
))
7865 tree list
= NULL_TREE
;
7868 tree atype
= NULL_TREE
, id
, keyworddecl
;
7869 tree param_attr
= NULL_TREE
;
7870 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
7872 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
7874 c_parser_consume_token (parser
);
7875 atype
= c_parser_objc_type_name (parser
);
7876 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7879 /* New ObjC allows attributes on method parameters. */
7880 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
7881 param_attr
= c_parser_attributes (parser
);
7882 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7884 c_parser_error (parser
, "expected identifier");
7885 return error_mark_node
;
7887 id
= c_parser_peek_token (parser
)->value
;
7888 c_parser_consume_token (parser
);
7889 keyworddecl
= objc_build_keyword_decl (tsel
, atype
, id
, param_attr
);
7890 list
= chainon (list
, keyworddecl
);
7891 tsel
= c_parser_objc_selector (parser
);
7892 if (!tsel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
7896 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
7898 /* Parse the optional parameter list. Optional Objective-C
7899 method parameters follow the C syntax, and may include '...'
7900 to denote a variable number of arguments. */
7901 parms
= make_node (TREE_LIST
);
7902 while (c_parser_next_token_is (parser
, CPP_COMMA
))
7904 struct c_parm
*parm
;
7905 c_parser_consume_token (parser
);
7906 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
7909 c_parser_consume_token (parser
);
7910 attr_err
|= c_parser_objc_maybe_method_attributes
7911 (parser
, attributes
) ;
7914 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
7917 parms
= chainon (parms
,
7918 build_tree_list (NULL_TREE
, grokparm (parm
, expr
)));
7923 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
7927 c_parser_error (parser
, "objective-c method declaration is expected");
7928 return error_mark_node
;
7932 return error_mark_node
;
7934 return objc_build_method_signature (is_class_method
, type
, sel
, parms
, ellipsis
);
7937 /* Parse an objc-type-name.
7940 objc-type-qualifiers[opt] type-name
7941 objc-type-qualifiers[opt]
7943 objc-type-qualifiers:
7945 objc-type-qualifiers objc-type-qualifier
7947 objc-type-qualifier: one of
7948 in out inout bycopy byref oneway
7952 c_parser_objc_type_name (c_parser
*parser
)
7954 tree quals
= NULL_TREE
;
7955 struct c_type_name
*type_name
= NULL
;
7956 tree type
= NULL_TREE
;
7959 c_token
*token
= c_parser_peek_token (parser
);
7960 if (token
->type
== CPP_KEYWORD
7961 && (token
->keyword
== RID_IN
7962 || token
->keyword
== RID_OUT
7963 || token
->keyword
== RID_INOUT
7964 || token
->keyword
== RID_BYCOPY
7965 || token
->keyword
== RID_BYREF
7966 || token
->keyword
== RID_ONEWAY
))
7968 quals
= chainon (build_tree_list (NULL_TREE
, token
->value
), quals
);
7969 c_parser_consume_token (parser
);
7974 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
7975 type_name
= c_parser_type_name (parser
);
7977 type
= groktypename (type_name
, NULL
, NULL
);
7979 /* If the type is unknown, and error has already been produced and
7980 we need to recover from the error. In that case, use NULL_TREE
7981 for the type, as if no type had been specified; this will use the
7982 default type ('id') which is good for error recovery. */
7983 if (type
== error_mark_node
)
7986 return build_tree_list (quals
, type
);
7989 /* Parse objc-protocol-refs.
7996 c_parser_objc_protocol_refs (c_parser
*parser
)
7998 tree list
= NULL_TREE
;
7999 gcc_assert (c_parser_next_token_is (parser
, CPP_LESS
));
8000 c_parser_consume_token (parser
);
8001 /* Any identifiers, including those declared as type names, are OK
8006 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8008 c_parser_error (parser
, "expected identifier");
8011 id
= c_parser_peek_token (parser
)->value
;
8012 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
8013 c_parser_consume_token (parser
);
8014 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8015 c_parser_consume_token (parser
);
8019 c_parser_require (parser
, CPP_GREATER
, "expected %<>%>");
8023 /* Parse an objc-try-catch-finally-statement.
8025 objc-try-catch-finally-statement:
8026 @try compound-statement objc-catch-list[opt]
8027 @try compound-statement objc-catch-list[opt] @finally compound-statement
8030 @catch ( objc-catch-parameter-declaration ) compound-statement
8031 objc-catch-list @catch ( objc-catch-parameter-declaration ) compound-statement
8033 objc-catch-parameter-declaration:
8034 parameter-declaration
8037 where '...' is to be interpreted literally, that is, it means CPP_ELLIPSIS.
8039 PS: This function is identical to cp_parser_objc_try_catch_finally_statement
8040 for C++. Keep them in sync. */
8043 c_parser_objc_try_catch_finally_statement (c_parser
*parser
)
8045 location_t location
;
8048 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_TRY
));
8049 c_parser_consume_token (parser
);
8050 location
= c_parser_peek_token (parser
)->location
;
8051 objc_maybe_warn_exceptions (location
);
8052 stmt
= c_parser_compound_statement (parser
);
8053 objc_begin_try_stmt (location
, stmt
);
8055 while (c_parser_next_token_is_keyword (parser
, RID_AT_CATCH
))
8057 struct c_parm
*parm
;
8058 tree parameter_declaration
= error_mark_node
;
8059 bool seen_open_paren
= false;
8061 c_parser_consume_token (parser
);
8062 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8063 seen_open_paren
= true;
8064 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
8066 /* We have "@catch (...)" (where the '...' are literally
8067 what is in the code). Skip the '...'.
8068 parameter_declaration is set to NULL_TREE, and
8069 objc_being_catch_clauses() knows that that means
8071 c_parser_consume_token (parser
);
8072 parameter_declaration
= NULL_TREE
;
8076 /* We have "@catch (NSException *exception)" or something
8077 like that. Parse the parameter declaration. */
8078 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
8080 parameter_declaration
= error_mark_node
;
8082 parameter_declaration
= grokparm (parm
, NULL
);
8084 if (seen_open_paren
)
8085 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8088 /* If there was no open parenthesis, we are recovering from
8089 an error, and we are trying to figure out what mistake
8090 the user has made. */
8092 /* If there is an immediate closing parenthesis, the user
8093 probably forgot the opening one (ie, they typed "@catch
8094 NSException *e)". Parse the closing parenthesis and keep
8096 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
8097 c_parser_consume_token (parser
);
8099 /* If these is no immediate closing parenthesis, the user
8100 probably doesn't know that parenthesis are required at
8101 all (ie, they typed "@catch NSException *e"). So, just
8102 forget about the closing parenthesis and keep going. */
8104 objc_begin_catch_clause (parameter_declaration
);
8105 if (c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
8106 c_parser_compound_statement_nostart (parser
);
8107 objc_finish_catch_clause ();
8109 if (c_parser_next_token_is_keyword (parser
, RID_AT_FINALLY
))
8111 c_parser_consume_token (parser
);
8112 location
= c_parser_peek_token (parser
)->location
;
8113 stmt
= c_parser_compound_statement (parser
);
8114 objc_build_finally_clause (location
, stmt
);
8116 objc_finish_try_stmt ();
8119 /* Parse an objc-synchronized-statement.
8121 objc-synchronized-statement:
8122 @synchronized ( expression ) compound-statement
8126 c_parser_objc_synchronized_statement (c_parser
*parser
)
8130 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNCHRONIZED
));
8131 c_parser_consume_token (parser
);
8132 loc
= c_parser_peek_token (parser
)->location
;
8133 objc_maybe_warn_exceptions (loc
);
8134 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8136 expr
= c_parser_expression (parser
).value
;
8137 expr
= c_fully_fold (expr
, false, NULL
);
8138 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8141 expr
= error_mark_node
;
8142 stmt
= c_parser_compound_statement (parser
);
8143 objc_build_synchronized (loc
, expr
, stmt
);
8146 /* Parse an objc-selector; return NULL_TREE without an error if the
8147 next token is not an objc-selector.
8152 enum struct union if else while do for switch case default
8153 break continue return goto asm sizeof typeof __alignof
8154 unsigned long const short volatile signed restrict _Complex
8155 in out inout bycopy byref oneway int char float double void _Bool
8157 ??? Why this selection of keywords but not, for example, storage
8158 class specifiers? */
8161 c_parser_objc_selector (c_parser
*parser
)
8163 c_token
*token
= c_parser_peek_token (parser
);
8164 tree value
= token
->value
;
8165 if (token
->type
== CPP_NAME
)
8167 c_parser_consume_token (parser
);
8170 if (token
->type
!= CPP_KEYWORD
)
8172 switch (token
->keyword
)
8214 c_parser_consume_token (parser
);
8221 /* Parse an objc-selector-arg.
8225 objc-keywordname-list
8227 objc-keywordname-list:
8229 objc-keywordname-list objc-keywordname
8237 c_parser_objc_selector_arg (c_parser
*parser
)
8239 tree sel
= c_parser_objc_selector (parser
);
8240 tree list
= NULL_TREE
;
8241 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
8245 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
8247 list
= chainon (list
, build_tree_list (sel
, NULL_TREE
));
8248 sel
= c_parser_objc_selector (parser
);
8249 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
8255 /* Parse an objc-receiver.
8264 c_parser_objc_receiver (c_parser
*parser
)
8266 if (c_parser_peek_token (parser
)->type
== CPP_NAME
8267 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
8268 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
8270 tree id
= c_parser_peek_token (parser
)->value
;
8271 c_parser_consume_token (parser
);
8272 return objc_get_class_reference (id
);
8274 return c_fully_fold (c_parser_expression (parser
).value
, false, NULL
);
8277 /* Parse objc-message-args.
8281 objc-keywordarg-list
8283 objc-keywordarg-list:
8285 objc-keywordarg-list objc-keywordarg
8288 objc-selector : objc-keywordexpr
8293 c_parser_objc_message_args (c_parser
*parser
)
8295 tree sel
= c_parser_objc_selector (parser
);
8296 tree list
= NULL_TREE
;
8297 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
8302 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
8303 return error_mark_node
;
8304 keywordexpr
= c_parser_objc_keywordexpr (parser
);
8305 list
= chainon (list
, build_tree_list (sel
, keywordexpr
));
8306 sel
= c_parser_objc_selector (parser
);
8307 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
8313 /* Parse an objc-keywordexpr.
8320 c_parser_objc_keywordexpr (c_parser
*parser
)
8323 vec
<tree
, va_gc
> *expr_list
= c_parser_expr_list (parser
, true, true,
8325 if (vec_safe_length (expr_list
) == 1)
8327 /* Just return the expression, remove a level of
8329 ret
= (*expr_list
)[0];
8333 /* We have a comma expression, we will collapse later. */
8334 ret
= build_tree_list_vec (expr_list
);
8336 release_tree_vector (expr_list
);
8340 /* A check, needed in several places, that ObjC interface, implementation or
8341 method definitions are not prefixed by incorrect items. */
8343 c_parser_objc_diagnose_bad_element_prefix (c_parser
*parser
,
8344 struct c_declspecs
*specs
)
8346 if (!specs
->declspecs_seen_p
|| specs
->non_sc_seen_p
8347 || specs
->typespec_kind
!= ctsk_none
)
8349 c_parser_error (parser
,
8350 "no type or storage class may be specified here,");
8351 c_parser_skip_to_end_of_block_or_statement (parser
);
8357 /* Parse an Objective-C @property declaration. The syntax is:
8359 objc-property-declaration:
8360 '@property' objc-property-attributes[opt] struct-declaration ;
8362 objc-property-attributes:
8363 '(' objc-property-attribute-list ')'
8365 objc-property-attribute-list:
8366 objc-property-attribute
8367 objc-property-attribute-list, objc-property-attribute
8369 objc-property-attribute
8370 'getter' = identifier
8371 'setter' = identifier
8380 @property NSString *name;
8381 @property (readonly) id object;
8382 @property (retain, nonatomic, getter=getTheName) id name;
8383 @property int a, b, c;
8385 PS: This function is identical to cp_parser_objc_at_propery_declaration
8386 for C++. Keep them in sync. */
8388 c_parser_objc_at_property_declaration (c_parser
*parser
)
8390 /* The following variables hold the attributes of the properties as
8391 parsed. They are 'false' or 'NULL_TREE' if the attribute was not
8392 seen. When we see an attribute, we set them to 'true' (if they
8393 are boolean properties) or to the identifier (if they have an
8394 argument, ie, for getter and setter). Note that here we only
8395 parse the list of attributes, check the syntax and accumulate the
8396 attributes that we find. objc_add_property_declaration() will
8397 then process the information. */
8398 bool property_assign
= false;
8399 bool property_copy
= false;
8400 tree property_getter_ident
= NULL_TREE
;
8401 bool property_nonatomic
= false;
8402 bool property_readonly
= false;
8403 bool property_readwrite
= false;
8404 bool property_retain
= false;
8405 tree property_setter_ident
= NULL_TREE
;
8407 /* 'properties' is the list of properties that we read. Usually a
8408 single one, but maybe more (eg, in "@property int a, b, c;" there
8413 loc
= c_parser_peek_token (parser
)->location
;
8414 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
));
8416 c_parser_consume_token (parser
); /* Eat '@property'. */
8418 /* Parse the optional attribute list... */
8419 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8422 c_parser_consume_token (parser
);
8424 /* Property attribute keywords are valid now. */
8425 parser
->objc_property_attr_context
= true;
8429 bool syntax_error
= false;
8430 c_token
*token
= c_parser_peek_token (parser
);
8433 if (token
->type
!= CPP_KEYWORD
)
8435 if (token
->type
== CPP_CLOSE_PAREN
)
8436 c_parser_error (parser
, "expected identifier");
8439 c_parser_consume_token (parser
);
8440 c_parser_error (parser
, "unknown property attribute");
8444 keyword
= token
->keyword
;
8445 c_parser_consume_token (parser
);
8448 case RID_ASSIGN
: property_assign
= true; break;
8449 case RID_COPY
: property_copy
= true; break;
8450 case RID_NONATOMIC
: property_nonatomic
= true; break;
8451 case RID_READONLY
: property_readonly
= true; break;
8452 case RID_READWRITE
: property_readwrite
= true; break;
8453 case RID_RETAIN
: property_retain
= true; break;
8457 if (c_parser_next_token_is_not (parser
, CPP_EQ
))
8459 if (keyword
== RID_GETTER
)
8460 c_parser_error (parser
,
8461 "missing %<=%> (after %<getter%> attribute)");
8463 c_parser_error (parser
,
8464 "missing %<=%> (after %<setter%> attribute)");
8465 syntax_error
= true;
8468 c_parser_consume_token (parser
); /* eat the = */
8469 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8471 c_parser_error (parser
, "expected identifier");
8472 syntax_error
= true;
8475 if (keyword
== RID_SETTER
)
8477 if (property_setter_ident
!= NULL_TREE
)
8478 c_parser_error (parser
, "the %<setter%> attribute may only be specified once");
8480 property_setter_ident
= c_parser_peek_token (parser
)->value
;
8481 c_parser_consume_token (parser
);
8482 if (c_parser_next_token_is_not (parser
, CPP_COLON
))
8483 c_parser_error (parser
, "setter name must terminate with %<:%>");
8485 c_parser_consume_token (parser
);
8489 if (property_getter_ident
!= NULL_TREE
)
8490 c_parser_error (parser
, "the %<getter%> attribute may only be specified once");
8492 property_getter_ident
= c_parser_peek_token (parser
)->value
;
8493 c_parser_consume_token (parser
);
8497 c_parser_error (parser
, "unknown property attribute");
8498 syntax_error
= true;
8505 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8506 c_parser_consume_token (parser
);
8510 parser
->objc_property_attr_context
= false;
8511 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8513 /* ... and the property declaration(s). */
8514 properties
= c_parser_struct_declaration (parser
);
8516 if (properties
== error_mark_node
)
8518 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8519 parser
->error
= false;
8523 if (properties
== NULL_TREE
)
8524 c_parser_error (parser
, "expected identifier");
8527 /* Comma-separated properties are chained together in
8528 reverse order; add them one by one. */
8529 properties
= nreverse (properties
);
8531 for (; properties
; properties
= TREE_CHAIN (properties
))
8532 objc_add_property_declaration (loc
, copy_node (properties
),
8533 property_readonly
, property_readwrite
,
8534 property_assign
, property_retain
,
8535 property_copy
, property_nonatomic
,
8536 property_getter_ident
, property_setter_ident
);
8539 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8540 parser
->error
= false;
8543 /* Parse an Objective-C @synthesize declaration. The syntax is:
8545 objc-synthesize-declaration:
8546 @synthesize objc-synthesize-identifier-list ;
8548 objc-synthesize-identifier-list:
8549 objc-synthesize-identifier
8550 objc-synthesize-identifier-list, objc-synthesize-identifier
8552 objc-synthesize-identifier
8554 identifier = identifier
8557 @synthesize MyProperty;
8558 @synthesize OneProperty, AnotherProperty=MyIvar, YetAnotherProperty;
8560 PS: This function is identical to cp_parser_objc_at_synthesize_declaration
8561 for C++. Keep them in sync.
8564 c_parser_objc_at_synthesize_declaration (c_parser
*parser
)
8566 tree list
= NULL_TREE
;
8568 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNTHESIZE
));
8569 loc
= c_parser_peek_token (parser
)->location
;
8571 c_parser_consume_token (parser
);
8574 tree property
, ivar
;
8575 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8577 c_parser_error (parser
, "expected identifier");
8578 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8579 /* Once we find the semicolon, we can resume normal parsing.
8580 We have to reset parser->error manually because
8581 c_parser_skip_until_found() won't reset it for us if the
8582 next token is precisely a semicolon. */
8583 parser
->error
= false;
8586 property
= c_parser_peek_token (parser
)->value
;
8587 c_parser_consume_token (parser
);
8588 if (c_parser_next_token_is (parser
, CPP_EQ
))
8590 c_parser_consume_token (parser
);
8591 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8593 c_parser_error (parser
, "expected identifier");
8594 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8595 parser
->error
= false;
8598 ivar
= c_parser_peek_token (parser
)->value
;
8599 c_parser_consume_token (parser
);
8603 list
= chainon (list
, build_tree_list (ivar
, property
));
8604 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8605 c_parser_consume_token (parser
);
8609 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8610 objc_add_synthesize_declaration (loc
, list
);
8613 /* Parse an Objective-C @dynamic declaration. The syntax is:
8615 objc-dynamic-declaration:
8616 @dynamic identifier-list ;
8619 @dynamic MyProperty;
8620 @dynamic MyProperty, AnotherProperty;
8622 PS: This function is identical to cp_parser_objc_at_dynamic_declaration
8623 for C++. Keep them in sync.
8626 c_parser_objc_at_dynamic_declaration (c_parser
*parser
)
8628 tree list
= NULL_TREE
;
8630 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_DYNAMIC
));
8631 loc
= c_parser_peek_token (parser
)->location
;
8633 c_parser_consume_token (parser
);
8637 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8639 c_parser_error (parser
, "expected identifier");
8640 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8641 parser
->error
= false;
8644 property
= c_parser_peek_token (parser
)->value
;
8645 list
= chainon (list
, build_tree_list (NULL_TREE
, property
));
8646 c_parser_consume_token (parser
);
8647 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8648 c_parser_consume_token (parser
);
8652 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8653 objc_add_dynamic_declaration (loc
, list
);
8657 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
8658 should be considered, statements. ALLOW_STMT is true if we're within
8659 the context of a function and such pragmas are to be allowed. Returns
8660 true if we actually parsed such a pragma. */
8663 c_parser_pragma (c_parser
*parser
, enum pragma_context context
)
8667 id
= c_parser_peek_token (parser
)->pragma_kind
;
8668 gcc_assert (id
!= PRAGMA_NONE
);
8672 case PRAGMA_OMP_BARRIER
:
8673 if (context
!= pragma_compound
)
8675 if (context
== pragma_stmt
)
8676 c_parser_error (parser
, "%<#pragma omp barrier%> may only be "
8677 "used in compound statements");
8680 c_parser_omp_barrier (parser
);
8683 case PRAGMA_OMP_FLUSH
:
8684 if (context
!= pragma_compound
)
8686 if (context
== pragma_stmt
)
8687 c_parser_error (parser
, "%<#pragma omp flush%> may only be "
8688 "used in compound statements");
8691 c_parser_omp_flush (parser
);
8694 case PRAGMA_OMP_TASKWAIT
:
8695 if (context
!= pragma_compound
)
8697 if (context
== pragma_stmt
)
8698 c_parser_error (parser
, "%<#pragma omp taskwait%> may only be "
8699 "used in compound statements");
8702 c_parser_omp_taskwait (parser
);
8705 case PRAGMA_OMP_TASKYIELD
:
8706 if (context
!= pragma_compound
)
8708 if (context
== pragma_stmt
)
8709 c_parser_error (parser
, "%<#pragma omp taskyield%> may only be "
8710 "used in compound statements");
8713 c_parser_omp_taskyield (parser
);
8716 case PRAGMA_OMP_THREADPRIVATE
:
8717 c_parser_omp_threadprivate (parser
);
8720 case PRAGMA_OMP_SECTION
:
8721 error_at (c_parser_peek_token (parser
)->location
,
8722 "%<#pragma omp section%> may only be used in "
8723 "%<#pragma omp sections%> construct");
8724 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
8727 case PRAGMA_GCC_PCH_PREPROCESS
:
8728 c_parser_error (parser
, "%<#pragma GCC pch_preprocess%> must be first");
8729 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
8733 if (id
< PRAGMA_FIRST_EXTERNAL
)
8735 if (context
== pragma_external
)
8738 c_parser_error (parser
, "expected declaration specifiers");
8739 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
8742 c_parser_omp_construct (parser
);
8748 c_parser_consume_pragma (parser
);
8749 c_invoke_pragma_handler (id
);
8751 /* Skip to EOL, but suppress any error message. Those will have been
8752 generated by the handler routine through calling error, as opposed
8753 to calling c_parser_error. */
8754 parser
->error
= true;
8755 c_parser_skip_to_pragma_eol (parser
);
8760 /* The interface the pragma parsers have to the lexer. */
8763 pragma_lex (tree
*value
)
8765 c_token
*tok
= c_parser_peek_token (the_parser
);
8766 enum cpp_ttype ret
= tok
->type
;
8768 *value
= tok
->value
;
8769 if (ret
== CPP_PRAGMA_EOL
|| ret
== CPP_EOF
)
8773 if (ret
== CPP_KEYWORD
)
8775 c_parser_consume_token (the_parser
);
8782 c_parser_pragma_pch_preprocess (c_parser
*parser
)
8786 c_parser_consume_pragma (parser
);
8787 if (c_parser_next_token_is (parser
, CPP_STRING
))
8789 name
= c_parser_peek_token (parser
)->value
;
8790 c_parser_consume_token (parser
);
8793 c_parser_error (parser
, "expected string literal");
8794 c_parser_skip_to_pragma_eol (parser
);
8797 c_common_pch_pragma (parse_in
, TREE_STRING_POINTER (name
));
8800 /* OpenMP 2.5 parsing routines. */
8802 /* Returns name of the next clause.
8803 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
8804 the token is not consumed. Otherwise appropriate pragma_omp_clause is
8805 returned and the token is consumed. */
8807 static pragma_omp_clause
8808 c_parser_omp_clause_name (c_parser
*parser
)
8810 pragma_omp_clause result
= PRAGMA_OMP_CLAUSE_NONE
;
8812 if (c_parser_next_token_is_keyword (parser
, RID_IF
))
8813 result
= PRAGMA_OMP_CLAUSE_IF
;
8814 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
8815 result
= PRAGMA_OMP_CLAUSE_DEFAULT
;
8816 else if (c_parser_next_token_is (parser
, CPP_NAME
))
8818 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
8823 if (!strcmp ("collapse", p
))
8824 result
= PRAGMA_OMP_CLAUSE_COLLAPSE
;
8825 else if (!strcmp ("copyin", p
))
8826 result
= PRAGMA_OMP_CLAUSE_COPYIN
;
8827 else if (!strcmp ("copyprivate", p
))
8828 result
= PRAGMA_OMP_CLAUSE_COPYPRIVATE
;
8831 if (!strcmp ("final", p
))
8832 result
= PRAGMA_OMP_CLAUSE_FINAL
;
8833 else if (!strcmp ("firstprivate", p
))
8834 result
= PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
;
8837 if (!strcmp ("lastprivate", p
))
8838 result
= PRAGMA_OMP_CLAUSE_LASTPRIVATE
;
8841 if (!strcmp ("mergeable", p
))
8842 result
= PRAGMA_OMP_CLAUSE_MERGEABLE
;
8845 if (!strcmp ("nowait", p
))
8846 result
= PRAGMA_OMP_CLAUSE_NOWAIT
;
8847 else if (!strcmp ("num_threads", p
))
8848 result
= PRAGMA_OMP_CLAUSE_NUM_THREADS
;
8851 if (!strcmp ("ordered", p
))
8852 result
= PRAGMA_OMP_CLAUSE_ORDERED
;
8855 if (!strcmp ("private", p
))
8856 result
= PRAGMA_OMP_CLAUSE_PRIVATE
;
8859 if (!strcmp ("reduction", p
))
8860 result
= PRAGMA_OMP_CLAUSE_REDUCTION
;
8863 if (!strcmp ("schedule", p
))
8864 result
= PRAGMA_OMP_CLAUSE_SCHEDULE
;
8865 else if (!strcmp ("shared", p
))
8866 result
= PRAGMA_OMP_CLAUSE_SHARED
;
8869 if (!strcmp ("untied", p
))
8870 result
= PRAGMA_OMP_CLAUSE_UNTIED
;
8875 if (result
!= PRAGMA_OMP_CLAUSE_NONE
)
8876 c_parser_consume_token (parser
);
8881 /* Validate that a clause of the given type does not already exist. */
8884 check_no_duplicate_clause (tree clauses
, enum omp_clause_code code
,
8889 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
8890 if (OMP_CLAUSE_CODE (c
) == code
)
8892 location_t loc
= OMP_CLAUSE_LOCATION (c
);
8893 error_at (loc
, "too many %qs clauses", name
);
8901 variable-list , identifier
8903 If KIND is nonzero, create the appropriate node and install the
8904 decl in OMP_CLAUSE_DECL and add the node to the head of the list.
8905 If KIND is nonzero, CLAUSE_LOC is the location of the clause.
8907 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
8908 return the list created. */
8911 c_parser_omp_variable_list (c_parser
*parser
,
8912 location_t clause_loc
,
8913 enum omp_clause_code kind
,
8916 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
8917 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
8918 c_parser_error (parser
, "expected identifier");
8920 while (c_parser_next_token_is (parser
, CPP_NAME
)
8921 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
8923 tree t
= lookup_name (c_parser_peek_token (parser
)->value
);
8926 undeclared_variable (c_parser_peek_token (parser
)->location
,
8927 c_parser_peek_token (parser
)->value
);
8928 else if (t
== error_mark_node
)
8932 tree u
= build_omp_clause (clause_loc
, kind
);
8933 OMP_CLAUSE_DECL (u
) = t
;
8934 OMP_CLAUSE_CHAIN (u
) = list
;
8938 list
= tree_cons (t
, NULL_TREE
, list
);
8940 c_parser_consume_token (parser
);
8942 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
8945 c_parser_consume_token (parser
);
8951 /* Similarly, but expect leading and trailing parenthesis. This is a very
8952 common case for omp clauses. */
8955 c_parser_omp_var_list_parens (c_parser
*parser
, enum omp_clause_code kind
,
8958 /* The clauses location. */
8959 location_t loc
= c_parser_peek_token (parser
)->location
;
8961 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8963 list
= c_parser_omp_variable_list (parser
, loc
, kind
, list
);
8964 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8970 collapse ( constant-expression ) */
8973 c_parser_omp_clause_collapse (c_parser
*parser
, tree list
)
8975 tree c
, num
= error_mark_node
;
8979 check_no_duplicate_clause (list
, OMP_CLAUSE_COLLAPSE
, "collapse");
8981 loc
= c_parser_peek_token (parser
)->location
;
8982 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8984 num
= c_parser_expr_no_commas (parser
, NULL
).value
;
8985 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8987 if (num
== error_mark_node
)
8989 if (!INTEGRAL_TYPE_P (TREE_TYPE (num
))
8990 || !host_integerp (num
, 0)
8991 || (n
= tree_low_cst (num
, 0)) <= 0
8995 "collapse argument needs positive constant integer expression");
8998 c
= build_omp_clause (loc
, OMP_CLAUSE_COLLAPSE
);
8999 OMP_CLAUSE_COLLAPSE_EXPR (c
) = num
;
9000 OMP_CLAUSE_CHAIN (c
) = list
;
9005 copyin ( variable-list ) */
9008 c_parser_omp_clause_copyin (c_parser
*parser
, tree list
)
9010 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYIN
, list
);
9014 copyprivate ( variable-list ) */
9017 c_parser_omp_clause_copyprivate (c_parser
*parser
, tree list
)
9019 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYPRIVATE
, list
);
9023 default ( shared | none ) */
9026 c_parser_omp_clause_default (c_parser
*parser
, tree list
)
9028 enum omp_clause_default_kind kind
= OMP_CLAUSE_DEFAULT_UNSPECIFIED
;
9029 location_t loc
= c_parser_peek_token (parser
)->location
;
9032 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9034 if (c_parser_next_token_is (parser
, CPP_NAME
))
9036 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
9041 if (strcmp ("none", p
) != 0)
9043 kind
= OMP_CLAUSE_DEFAULT_NONE
;
9047 if (strcmp ("shared", p
) != 0)
9049 kind
= OMP_CLAUSE_DEFAULT_SHARED
;
9056 c_parser_consume_token (parser
);
9061 c_parser_error (parser
, "expected %<none%> or %<shared%>");
9063 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9065 if (kind
== OMP_CLAUSE_DEFAULT_UNSPECIFIED
)
9068 check_no_duplicate_clause (list
, OMP_CLAUSE_DEFAULT
, "default");
9069 c
= build_omp_clause (loc
, OMP_CLAUSE_DEFAULT
);
9070 OMP_CLAUSE_CHAIN (c
) = list
;
9071 OMP_CLAUSE_DEFAULT_KIND (c
) = kind
;
9077 firstprivate ( variable-list ) */
9080 c_parser_omp_clause_firstprivate (c_parser
*parser
, tree list
)
9082 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FIRSTPRIVATE
, list
);
9086 final ( expression ) */
9089 c_parser_omp_clause_final (c_parser
*parser
, tree list
)
9091 location_t loc
= c_parser_peek_token (parser
)->location
;
9092 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9094 tree t
= c_parser_paren_condition (parser
);
9097 check_no_duplicate_clause (list
, OMP_CLAUSE_FINAL
, "final");
9099 c
= build_omp_clause (loc
, OMP_CLAUSE_FINAL
);
9100 OMP_CLAUSE_FINAL_EXPR (c
) = t
;
9101 OMP_CLAUSE_CHAIN (c
) = list
;
9105 c_parser_error (parser
, "expected %<(%>");
9111 if ( expression ) */
9114 c_parser_omp_clause_if (c_parser
*parser
, tree list
)
9116 location_t loc
= c_parser_peek_token (parser
)->location
;
9117 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9119 tree t
= c_parser_paren_condition (parser
);
9122 check_no_duplicate_clause (list
, OMP_CLAUSE_IF
, "if");
9124 c
= build_omp_clause (loc
, OMP_CLAUSE_IF
);
9125 OMP_CLAUSE_IF_EXPR (c
) = t
;
9126 OMP_CLAUSE_CHAIN (c
) = list
;
9130 c_parser_error (parser
, "expected %<(%>");
9136 lastprivate ( variable-list ) */
9139 c_parser_omp_clause_lastprivate (c_parser
*parser
, tree list
)
9141 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_LASTPRIVATE
, list
);
9148 c_parser_omp_clause_mergeable (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
9152 /* FIXME: Should we allow duplicates? */
9153 check_no_duplicate_clause (list
, OMP_CLAUSE_MERGEABLE
, "mergeable");
9155 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
9156 OMP_CLAUSE_MERGEABLE
);
9157 OMP_CLAUSE_CHAIN (c
) = list
;
9166 c_parser_omp_clause_nowait (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
9169 location_t loc
= c_parser_peek_token (parser
)->location
;
9171 check_no_duplicate_clause (list
, OMP_CLAUSE_NOWAIT
, "nowait");
9173 c
= build_omp_clause (loc
, OMP_CLAUSE_NOWAIT
);
9174 OMP_CLAUSE_CHAIN (c
) = list
;
9179 num_threads ( expression ) */
9182 c_parser_omp_clause_num_threads (c_parser
*parser
, tree list
)
9184 location_t num_threads_loc
= c_parser_peek_token (parser
)->location
;
9185 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9187 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
9188 tree c
, t
= c_parser_expression (parser
).value
;
9190 t
= c_fully_fold (t
, false, NULL
);
9192 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9194 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
9196 c_parser_error (parser
, "expected integer expression");
9200 /* Attempt to statically determine when the number isn't positive. */
9201 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
9202 build_int_cst (TREE_TYPE (t
), 0));
9203 if (CAN_HAVE_LOCATION_P (c
))
9204 SET_EXPR_LOCATION (c
, expr_loc
);
9205 if (c
== boolean_true_node
)
9207 warning_at (expr_loc
, 0,
9208 "%<num_threads%> value must be positive");
9209 t
= integer_one_node
;
9212 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_THREADS
, "num_threads");
9214 c
= build_omp_clause (num_threads_loc
, OMP_CLAUSE_NUM_THREADS
);
9215 OMP_CLAUSE_NUM_THREADS_EXPR (c
) = t
;
9216 OMP_CLAUSE_CHAIN (c
) = list
;
9227 c_parser_omp_clause_ordered (c_parser
*parser
, tree list
)
9231 check_no_duplicate_clause (list
, OMP_CLAUSE_ORDERED
, "ordered");
9233 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
9234 OMP_CLAUSE_ORDERED
);
9235 OMP_CLAUSE_CHAIN (c
) = list
;
9241 private ( variable-list ) */
9244 c_parser_omp_clause_private (c_parser
*parser
, tree list
)
9246 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_PRIVATE
, list
);
9250 reduction ( reduction-operator : variable-list )
9253 One of: + * - & ^ | && ||
9258 One of: + * - & ^ | && || max min */
9261 c_parser_omp_clause_reduction (c_parser
*parser
, tree list
)
9263 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
9264 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9266 enum tree_code code
;
9268 switch (c_parser_peek_token (parser
)->type
)
9280 code
= BIT_AND_EXPR
;
9283 code
= BIT_XOR_EXPR
;
9286 code
= BIT_IOR_EXPR
;
9289 code
= TRUTH_ANDIF_EXPR
;
9292 code
= TRUTH_ORIF_EXPR
;
9297 = IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
9298 if (strcmp (p
, "min") == 0)
9303 if (strcmp (p
, "max") == 0)
9311 c_parser_error (parser
,
9312 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
9313 "%<^%>, %<|%>, %<&&%>, %<||%>, %<min%> or %<max%>");
9314 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
9317 c_parser_consume_token (parser
);
9318 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
9322 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
9323 OMP_CLAUSE_REDUCTION
, list
);
9324 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
9325 OMP_CLAUSE_REDUCTION_CODE (c
) = code
;
9329 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9335 schedule ( schedule-kind )
9336 schedule ( schedule-kind , expression )
9339 static | dynamic | guided | runtime | auto
9343 c_parser_omp_clause_schedule (c_parser
*parser
, tree list
)
9346 location_t loc
= c_parser_peek_token (parser
)->location
;
9348 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9351 c
= build_omp_clause (loc
, OMP_CLAUSE_SCHEDULE
);
9353 if (c_parser_next_token_is (parser
, CPP_NAME
))
9355 tree kind
= c_parser_peek_token (parser
)->value
;
9356 const char *p
= IDENTIFIER_POINTER (kind
);
9361 if (strcmp ("dynamic", p
) != 0)
9363 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_DYNAMIC
;
9367 if (strcmp ("guided", p
) != 0)
9369 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_GUIDED
;
9373 if (strcmp ("runtime", p
) != 0)
9375 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_RUNTIME
;
9382 else if (c_parser_next_token_is_keyword (parser
, RID_STATIC
))
9383 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_STATIC
;
9384 else if (c_parser_next_token_is_keyword (parser
, RID_AUTO
))
9385 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_AUTO
;
9389 c_parser_consume_token (parser
);
9390 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9393 c_parser_consume_token (parser
);
9395 here
= c_parser_peek_token (parser
)->location
;
9396 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
9398 t
= c_fully_fold (t
, false, NULL
);
9400 if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_RUNTIME
)
9401 error_at (here
, "schedule %<runtime%> does not take "
9402 "a %<chunk_size%> parameter");
9403 else if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_AUTO
)
9405 "schedule %<auto%> does not take "
9406 "a %<chunk_size%> parameter");
9407 else if (TREE_CODE (TREE_TYPE (t
)) == INTEGER_TYPE
)
9408 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
) = t
;
9410 c_parser_error (parser
, "expected integer expression");
9412 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9415 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
9416 "expected %<,%> or %<)%>");
9418 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
9419 OMP_CLAUSE_CHAIN (c
) = list
;
9423 c_parser_error (parser
, "invalid schedule kind");
9424 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
9429 shared ( variable-list ) */
9432 c_parser_omp_clause_shared (c_parser
*parser
, tree list
)
9434 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_SHARED
, list
);
9441 c_parser_omp_clause_untied (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
9445 /* FIXME: Should we allow duplicates? */
9446 check_no_duplicate_clause (list
, OMP_CLAUSE_UNTIED
, "untied");
9448 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
9450 OMP_CLAUSE_CHAIN (c
) = list
;
9455 /* Parse all OpenMP clauses. The set clauses allowed by the directive
9456 is a bitmask in MASK. Return the list of clauses found; the result
9457 of clause default goes in *pdefault. */
9460 c_parser_omp_all_clauses (c_parser
*parser
, unsigned int mask
,
9463 tree clauses
= NULL
;
9466 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
9469 pragma_omp_clause c_kind
;
9471 tree prev
= clauses
;
9473 if (!first
&& c_parser_next_token_is (parser
, CPP_COMMA
))
9474 c_parser_consume_token (parser
);
9477 here
= c_parser_peek_token (parser
)->location
;
9478 c_kind
= c_parser_omp_clause_name (parser
);
9482 case PRAGMA_OMP_CLAUSE_COLLAPSE
:
9483 clauses
= c_parser_omp_clause_collapse (parser
, clauses
);
9484 c_name
= "collapse";
9486 case PRAGMA_OMP_CLAUSE_COPYIN
:
9487 clauses
= c_parser_omp_clause_copyin (parser
, clauses
);
9490 case PRAGMA_OMP_CLAUSE_COPYPRIVATE
:
9491 clauses
= c_parser_omp_clause_copyprivate (parser
, clauses
);
9492 c_name
= "copyprivate";
9494 case PRAGMA_OMP_CLAUSE_DEFAULT
:
9495 clauses
= c_parser_omp_clause_default (parser
, clauses
);
9498 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
:
9499 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
9500 c_name
= "firstprivate";
9502 case PRAGMA_OMP_CLAUSE_FINAL
:
9503 clauses
= c_parser_omp_clause_final (parser
, clauses
);
9506 case PRAGMA_OMP_CLAUSE_IF
:
9507 clauses
= c_parser_omp_clause_if (parser
, clauses
);
9510 case PRAGMA_OMP_CLAUSE_LASTPRIVATE
:
9511 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
9512 c_name
= "lastprivate";
9514 case PRAGMA_OMP_CLAUSE_MERGEABLE
:
9515 clauses
= c_parser_omp_clause_mergeable (parser
, clauses
);
9516 c_name
= "mergeable";
9518 case PRAGMA_OMP_CLAUSE_NOWAIT
:
9519 clauses
= c_parser_omp_clause_nowait (parser
, clauses
);
9522 case PRAGMA_OMP_CLAUSE_NUM_THREADS
:
9523 clauses
= c_parser_omp_clause_num_threads (parser
, clauses
);
9524 c_name
= "num_threads";
9526 case PRAGMA_OMP_CLAUSE_ORDERED
:
9527 clauses
= c_parser_omp_clause_ordered (parser
, clauses
);
9530 case PRAGMA_OMP_CLAUSE_PRIVATE
:
9531 clauses
= c_parser_omp_clause_private (parser
, clauses
);
9534 case PRAGMA_OMP_CLAUSE_REDUCTION
:
9535 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
9536 c_name
= "reduction";
9538 case PRAGMA_OMP_CLAUSE_SCHEDULE
:
9539 clauses
= c_parser_omp_clause_schedule (parser
, clauses
);
9540 c_name
= "schedule";
9542 case PRAGMA_OMP_CLAUSE_SHARED
:
9543 clauses
= c_parser_omp_clause_shared (parser
, clauses
);
9546 case PRAGMA_OMP_CLAUSE_UNTIED
:
9547 clauses
= c_parser_omp_clause_untied (parser
, clauses
);
9551 c_parser_error (parser
, "expected %<#pragma omp%> clause");
9555 if (((mask
>> c_kind
) & 1) == 0 && !parser
->error
)
9557 /* Remove the invalid clause(s) from the list to avoid
9558 confusing the rest of the compiler. */
9560 error_at (here
, "%qs is not valid for %qs", c_name
, where
);
9565 c_parser_skip_to_pragma_eol (parser
);
9567 return c_finish_omp_clauses (clauses
);
9574 In practice, we're also interested in adding the statement to an
9575 outer node. So it is convenient if we work around the fact that
9576 c_parser_statement calls add_stmt. */
9579 c_parser_omp_structured_block (c_parser
*parser
)
9581 tree stmt
= push_stmt_list ();
9582 c_parser_statement (parser
);
9583 return pop_stmt_list (stmt
);
9587 # pragma omp atomic new-line
9591 x binop= expr | x++ | ++x | x-- | --x
9593 +, *, -, /, &, ^, |, <<, >>
9595 where x is an lvalue expression with scalar type.
9598 # pragma omp atomic new-line
9601 # pragma omp atomic read new-line
9604 # pragma omp atomic write new-line
9607 # pragma omp atomic update new-line
9610 # pragma omp atomic capture new-line
9613 # pragma omp atomic capture new-line
9621 expression-stmt | x = x binop expr
9623 v = x binop= expr | v = x++ | v = ++x | v = x-- | v = --x
9625 { v = x; update-stmt; } | { update-stmt; v = x; }
9627 where x and v are lvalue expressions with scalar type.
9629 LOC is the location of the #pragma token. */
9632 c_parser_omp_atomic (location_t loc
, c_parser
*parser
)
9634 tree lhs
= NULL_TREE
, rhs
= NULL_TREE
, v
= NULL_TREE
;
9635 tree lhs1
= NULL_TREE
, rhs1
= NULL_TREE
;
9636 tree stmt
, orig_lhs
;
9637 enum tree_code code
= OMP_ATOMIC
, opcode
= NOP_EXPR
;
9638 struct c_expr rhs_expr
;
9639 bool structured_block
= false;
9641 if (c_parser_next_token_is (parser
, CPP_NAME
))
9643 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
9645 if (!strcmp (p
, "read"))
9646 code
= OMP_ATOMIC_READ
;
9647 else if (!strcmp (p
, "write"))
9649 else if (!strcmp (p
, "update"))
9651 else if (!strcmp (p
, "capture"))
9652 code
= OMP_ATOMIC_CAPTURE_NEW
;
9656 c_parser_consume_token (parser
);
9658 c_parser_skip_to_pragma_eol (parser
);
9662 case OMP_ATOMIC_READ
:
9663 case NOP_EXPR
: /* atomic write */
9664 v
= c_parser_unary_expression (parser
).value
;
9665 v
= c_fully_fold (v
, false, NULL
);
9666 if (v
== error_mark_node
)
9668 loc
= c_parser_peek_token (parser
)->location
;
9669 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
9671 if (code
== NOP_EXPR
)
9672 lhs
= c_parser_expression (parser
).value
;
9674 lhs
= c_parser_unary_expression (parser
).value
;
9675 lhs
= c_fully_fold (lhs
, false, NULL
);
9676 if (lhs
== error_mark_node
)
9678 if (code
== NOP_EXPR
)
9680 /* atomic write is represented by OMP_ATOMIC with NOP_EXPR
9688 case OMP_ATOMIC_CAPTURE_NEW
:
9689 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
9691 c_parser_consume_token (parser
);
9692 structured_block
= true;
9696 v
= c_parser_unary_expression (parser
).value
;
9697 v
= c_fully_fold (v
, false, NULL
);
9698 if (v
== error_mark_node
)
9700 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
9708 /* For structured_block case we don't know yet whether
9709 old or new x should be captured. */
9711 lhs
= c_parser_unary_expression (parser
).value
;
9712 lhs
= c_fully_fold (lhs
, false, NULL
);
9714 switch (TREE_CODE (lhs
))
9718 c_parser_skip_to_end_of_block_or_statement (parser
);
9719 if (structured_block
)
9721 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
9722 c_parser_consume_token (parser
);
9723 else if (code
== OMP_ATOMIC_CAPTURE_NEW
)
9725 c_parser_skip_to_end_of_block_or_statement (parser
);
9726 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
9727 c_parser_consume_token (parser
);
9732 case POSTINCREMENT_EXPR
:
9733 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
9734 code
= OMP_ATOMIC_CAPTURE_OLD
;
9736 case PREINCREMENT_EXPR
:
9737 lhs
= TREE_OPERAND (lhs
, 0);
9739 rhs
= integer_one_node
;
9742 case POSTDECREMENT_EXPR
:
9743 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
9744 code
= OMP_ATOMIC_CAPTURE_OLD
;
9746 case PREDECREMENT_EXPR
:
9747 lhs
= TREE_OPERAND (lhs
, 0);
9748 opcode
= MINUS_EXPR
;
9749 rhs
= integer_one_node
;
9753 if (TREE_CODE (TREE_OPERAND (lhs
, 0)) == SAVE_EXPR
9754 && TREE_CODE (TREE_OPERAND (lhs
, 1)) == COMPOUND_EXPR
9755 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0)) == MODIFY_EXPR
9756 && TREE_OPERAND (TREE_OPERAND (lhs
, 1), 1) == TREE_OPERAND (lhs
, 0)
9757 && TREE_CODE (TREE_TYPE (TREE_OPERAND (TREE_OPERAND
9758 (TREE_OPERAND (lhs
, 1), 0), 0)))
9760 /* Undo effects of boolean_increment for post {in,de}crement. */
9761 lhs
= TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0);
9764 if (TREE_CODE (lhs
) == MODIFY_EXPR
9765 && TREE_CODE (TREE_TYPE (TREE_OPERAND (lhs
, 0))) == BOOLEAN_TYPE
)
9767 /* Undo effects of boolean_increment. */
9768 if (integer_onep (TREE_OPERAND (lhs
, 1)))
9770 /* This is pre or post increment. */
9771 rhs
= TREE_OPERAND (lhs
, 1);
9772 lhs
= TREE_OPERAND (lhs
, 0);
9774 if (code
== OMP_ATOMIC_CAPTURE_NEW
9775 && !structured_block
9776 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
9777 code
= OMP_ATOMIC_CAPTURE_OLD
;
9780 if (TREE_CODE (TREE_OPERAND (lhs
, 1)) == TRUTH_NOT_EXPR
9781 && TREE_OPERAND (lhs
, 0)
9782 == TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0))
9784 /* This is pre or post decrement. */
9785 rhs
= TREE_OPERAND (lhs
, 1);
9786 lhs
= TREE_OPERAND (lhs
, 0);
9788 if (code
== OMP_ATOMIC_CAPTURE_NEW
9789 && !structured_block
9790 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
9791 code
= OMP_ATOMIC_CAPTURE_OLD
;
9797 switch (c_parser_peek_token (parser
)->type
)
9803 opcode
= TRUNC_DIV_EXPR
;
9809 opcode
= MINUS_EXPR
;
9812 opcode
= LSHIFT_EXPR
;
9815 opcode
= RSHIFT_EXPR
;
9818 opcode
= BIT_AND_EXPR
;
9821 opcode
= BIT_IOR_EXPR
;
9824 opcode
= BIT_XOR_EXPR
;
9827 if (structured_block
|| code
== OMP_ATOMIC
)
9829 location_t aloc
= c_parser_peek_token (parser
)->location
;
9831 enum c_parser_prec oprec
= PREC_NONE
;
9833 c_parser_consume_token (parser
);
9834 rhs1
= c_parser_unary_expression (parser
).value
;
9835 rhs1
= c_fully_fold (rhs1
, false, NULL
);
9836 if (rhs1
== error_mark_node
)
9838 switch (c_parser_peek_token (parser
)->type
)
9841 if (code
== OMP_ATOMIC_CAPTURE_NEW
)
9843 code
= OMP_ATOMIC_CAPTURE_OLD
;
9848 c_parser_consume_token (parser
);
9851 c_parser_error (parser
,
9852 "invalid form of %<#pragma omp atomic%>");
9859 opcode
= TRUNC_DIV_EXPR
;
9867 opcode
= MINUS_EXPR
;
9871 opcode
= LSHIFT_EXPR
;
9875 opcode
= RSHIFT_EXPR
;
9879 opcode
= BIT_AND_EXPR
;
9880 oprec
= PREC_BITAND
;
9883 opcode
= BIT_IOR_EXPR
;
9887 opcode
= BIT_XOR_EXPR
;
9888 oprec
= PREC_BITXOR
;
9891 c_parser_error (parser
,
9892 "invalid operator for %<#pragma omp atomic%>");
9896 c_parser_consume_token (parser
);
9897 rhs_loc
= c_parser_peek_token (parser
)->location
;
9898 if (commutative_tree_code (opcode
))
9899 oprec
= (enum c_parser_prec
) (oprec
- 1);
9900 rhs_expr
= c_parser_binary_expression (parser
, NULL
, oprec
);
9901 rhs_expr
= default_function_array_read_conversion (rhs_loc
,
9903 rhs
= rhs_expr
.value
;
9904 rhs
= c_fully_fold (rhs
, false, NULL
);
9909 c_parser_error (parser
,
9910 "invalid operator for %<#pragma omp atomic%>");
9914 /* Arrange to pass the location of the assignment operator to
9915 c_finish_omp_atomic. */
9916 loc
= c_parser_peek_token (parser
)->location
;
9917 c_parser_consume_token (parser
);
9919 location_t rhs_loc
= c_parser_peek_token (parser
)->location
;
9920 rhs_expr
= c_parser_expression (parser
);
9921 rhs_expr
= default_function_array_read_conversion (rhs_loc
, rhs_expr
);
9923 rhs
= rhs_expr
.value
;
9924 rhs
= c_fully_fold (rhs
, false, NULL
);
9928 if (structured_block
&& code
== OMP_ATOMIC_CAPTURE_NEW
)
9930 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
9932 v
= c_parser_unary_expression (parser
).value
;
9933 v
= c_fully_fold (v
, false, NULL
);
9934 if (v
== error_mark_node
)
9936 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
9938 lhs1
= c_parser_unary_expression (parser
).value
;
9939 lhs1
= c_fully_fold (lhs1
, false, NULL
);
9940 if (lhs1
== error_mark_node
)
9943 if (structured_block
)
9945 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9946 c_parser_require (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
9949 stmt
= c_finish_omp_atomic (loc
, code
, opcode
, lhs
, rhs
, v
, lhs1
, rhs1
);
9950 if (stmt
!= error_mark_node
)
9953 if (!structured_block
)
9954 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9959 # pragma omp barrier new-line
9963 c_parser_omp_barrier (c_parser
*parser
)
9965 location_t loc
= c_parser_peek_token (parser
)->location
;
9966 c_parser_consume_pragma (parser
);
9967 c_parser_skip_to_pragma_eol (parser
);
9969 c_finish_omp_barrier (loc
);
9973 # pragma omp critical [(name)] new-line
9976 LOC is the location of the #pragma itself. */
9979 c_parser_omp_critical (location_t loc
, c_parser
*parser
)
9981 tree stmt
, name
= NULL
;
9983 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9985 c_parser_consume_token (parser
);
9986 if (c_parser_next_token_is (parser
, CPP_NAME
))
9988 name
= c_parser_peek_token (parser
)->value
;
9989 c_parser_consume_token (parser
);
9990 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9993 c_parser_error (parser
, "expected identifier");
9995 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
9996 c_parser_error (parser
, "expected %<(%> or end of line");
9997 c_parser_skip_to_pragma_eol (parser
);
9999 stmt
= c_parser_omp_structured_block (parser
);
10000 return c_finish_omp_critical (loc
, stmt
, name
);
10004 # pragma omp flush flush-vars[opt] new-line
10007 ( variable-list ) */
10010 c_parser_omp_flush (c_parser
*parser
)
10012 location_t loc
= c_parser_peek_token (parser
)->location
;
10013 c_parser_consume_pragma (parser
);
10014 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
10015 c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
10016 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
10017 c_parser_error (parser
, "expected %<(%> or end of line");
10018 c_parser_skip_to_pragma_eol (parser
);
10020 c_finish_omp_flush (loc
);
10023 /* Parse the restricted form of the for statement allowed by OpenMP.
10024 The real trick here is to determine the loop control variable early
10025 so that we can push a new decl if necessary to make it private.
10026 LOC is the location of the OMP in "#pragma omp". */
10029 c_parser_omp_for_loop (location_t loc
,
10030 c_parser
*parser
, tree clauses
, tree
*par_clauses
)
10032 tree decl
, cond
, incr
, save_break
, save_cont
, body
, init
, stmt
, cl
;
10033 tree declv
, condv
, incrv
, initv
, ret
= NULL
;
10034 bool fail
= false, open_brace_parsed
= false;
10035 int i
, collapse
= 1, nbraces
= 0;
10036 location_t for_loc
;
10037 vec
<tree
, va_gc
> *for_block
= make_tree_vector ();
10039 for (cl
= clauses
; cl
; cl
= OMP_CLAUSE_CHAIN (cl
))
10040 if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_COLLAPSE
)
10041 collapse
= tree_low_cst (OMP_CLAUSE_COLLAPSE_EXPR (cl
), 0);
10043 gcc_assert (collapse
>= 1);
10045 declv
= make_tree_vec (collapse
);
10046 initv
= make_tree_vec (collapse
);
10047 condv
= make_tree_vec (collapse
);
10048 incrv
= make_tree_vec (collapse
);
10050 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
))
10052 c_parser_error (parser
, "for statement expected");
10055 for_loc
= c_parser_peek_token (parser
)->location
;
10056 c_parser_consume_token (parser
);
10058 for (i
= 0; i
< collapse
; i
++)
10060 int bracecount
= 0;
10062 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10065 /* Parse the initialization declaration or expression. */
10066 if (c_parser_next_tokens_start_declaration (parser
))
10069 vec_safe_push (for_block
, c_begin_compound_stmt (true));
10070 c_parser_declaration_or_fndef (parser
, true, true, true, true, true, NULL
);
10071 decl
= check_for_loop_decls (for_loc
, flag_isoc99
);
10074 if (DECL_INITIAL (decl
) == error_mark_node
)
10075 decl
= error_mark_node
;
10078 else if (c_parser_next_token_is (parser
, CPP_NAME
)
10079 && c_parser_peek_2nd_token (parser
)->type
== CPP_EQ
)
10081 struct c_expr decl_exp
;
10082 struct c_expr init_exp
;
10083 location_t init_loc
;
10085 decl_exp
= c_parser_postfix_expression (parser
);
10086 decl
= decl_exp
.value
;
10088 c_parser_require (parser
, CPP_EQ
, "expected %<=%>");
10090 init_loc
= c_parser_peek_token (parser
)->location
;
10091 init_exp
= c_parser_expr_no_commas (parser
, NULL
);
10092 init_exp
= default_function_array_read_conversion (init_loc
,
10094 init
= build_modify_expr (init_loc
, decl
, decl_exp
.original_type
,
10095 NOP_EXPR
, init_loc
, init_exp
.value
,
10096 init_exp
.original_type
);
10097 init
= c_process_expr_stmt (init_loc
, init
);
10099 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
10104 c_parser_error (parser
,
10105 "expected iteration declaration or initialization");
10106 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
10112 /* Parse the loop condition. */
10114 if (c_parser_next_token_is_not (parser
, CPP_SEMICOLON
))
10116 location_t cond_loc
= c_parser_peek_token (parser
)->location
;
10117 struct c_expr cond_expr
= c_parser_binary_expression (parser
, NULL
,
10120 cond
= cond_expr
.value
;
10121 cond
= c_objc_common_truthvalue_conversion (cond_loc
, cond
);
10122 cond
= c_fully_fold (cond
, false, NULL
);
10123 switch (cond_expr
.original_code
)
10131 /* Can't be cond = error_mark_node, because we want to preserve
10132 the location until c_finish_omp_for. */
10133 cond
= build1 (NOP_EXPR
, boolean_type_node
, error_mark_node
);
10136 protected_set_expr_location (cond
, cond_loc
);
10138 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
10140 /* Parse the increment expression. */
10142 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_PAREN
))
10144 location_t incr_loc
= c_parser_peek_token (parser
)->location
;
10146 incr
= c_process_expr_stmt (incr_loc
,
10147 c_parser_expression (parser
).value
);
10149 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10151 if (decl
== NULL
|| decl
== error_mark_node
|| init
== error_mark_node
)
10155 TREE_VEC_ELT (declv
, i
) = decl
;
10156 TREE_VEC_ELT (initv
, i
) = init
;
10157 TREE_VEC_ELT (condv
, i
) = cond
;
10158 TREE_VEC_ELT (incrv
, i
) = incr
;
10162 if (i
== collapse
- 1)
10165 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
10166 in between the collapsed for loops to be still considered perfectly
10167 nested. Hopefully the final version clarifies this.
10168 For now handle (multiple) {'s and empty statements. */
10171 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
10173 c_parser_consume_token (parser
);
10176 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
10178 c_parser_consume_token (parser
);
10181 else if (bracecount
10182 && c_parser_next_token_is (parser
, CPP_SEMICOLON
))
10183 c_parser_consume_token (parser
);
10186 c_parser_error (parser
, "not enough perfectly nested loops");
10189 open_brace_parsed
= true;
10199 nbraces
+= bracecount
;
10202 save_break
= c_break_label
;
10203 c_break_label
= size_one_node
;
10204 save_cont
= c_cont_label
;
10205 c_cont_label
= NULL_TREE
;
10206 body
= push_stmt_list ();
10208 if (open_brace_parsed
)
10210 location_t here
= c_parser_peek_token (parser
)->location
;
10211 stmt
= c_begin_compound_stmt (true);
10212 c_parser_compound_statement_nostart (parser
);
10213 add_stmt (c_end_compound_stmt (here
, stmt
, true));
10216 add_stmt (c_parser_c99_block_statement (parser
));
10219 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_cont_label
);
10220 SET_EXPR_LOCATION (t
, loc
);
10224 body
= pop_stmt_list (body
);
10225 c_break_label
= save_break
;
10226 c_cont_label
= save_cont
;
10230 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
10232 c_parser_consume_token (parser
);
10235 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
10236 c_parser_consume_token (parser
);
10239 c_parser_error (parser
, "collapsed loops not perfectly nested");
10242 location_t here
= c_parser_peek_token (parser
)->location
;
10243 stmt
= c_begin_compound_stmt (true);
10245 c_parser_compound_statement_nostart (parser
);
10246 body
= c_end_compound_stmt (here
, stmt
, true);
10253 /* Only bother calling c_finish_omp_for if we haven't already generated
10254 an error from the initialization parsing. */
10257 stmt
= c_finish_omp_for (loc
, declv
, initv
, condv
, incrv
, body
, NULL
);
10260 if (par_clauses
!= NULL
)
10263 for (c
= par_clauses
; *c
; )
10264 if (OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_FIRSTPRIVATE
10265 && OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_LASTPRIVATE
)
10266 c
= &OMP_CLAUSE_CHAIN (*c
);
10269 for (i
= 0; i
< collapse
; i
++)
10270 if (TREE_VEC_ELT (declv
, i
) == OMP_CLAUSE_DECL (*c
))
10273 c
= &OMP_CLAUSE_CHAIN (*c
);
10274 else if (OMP_CLAUSE_CODE (*c
) == OMP_CLAUSE_FIRSTPRIVATE
)
10277 "iteration variable %qD should not be firstprivate",
10278 OMP_CLAUSE_DECL (*c
));
10279 *c
= OMP_CLAUSE_CHAIN (*c
);
10283 /* Copy lastprivate (decl) clause to OMP_FOR_CLAUSES,
10284 change it to shared (decl) in
10285 OMP_PARALLEL_CLAUSES. */
10286 tree l
= build_omp_clause (OMP_CLAUSE_LOCATION (*c
),
10287 OMP_CLAUSE_LASTPRIVATE
);
10288 OMP_CLAUSE_DECL (l
) = OMP_CLAUSE_DECL (*c
);
10289 OMP_CLAUSE_CHAIN (l
) = clauses
;
10291 OMP_CLAUSE_SET_CODE (*c
, OMP_CLAUSE_SHARED
);
10295 OMP_FOR_CLAUSES (stmt
) = clauses
;
10300 while (!for_block
->is_empty ())
10302 /* FIXME diagnostics: LOC below should be the actual location of
10303 this particular for block. We need to build a list of
10304 locations to go along with FOR_BLOCK. */
10305 stmt
= c_end_compound_stmt (loc
, for_block
->pop (), true);
10308 release_tree_vector (for_block
);
10313 #pragma omp for for-clause[optseq] new-line
10316 LOC is the location of the #pragma token.
10319 #define OMP_FOR_CLAUSE_MASK \
10320 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
10321 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
10322 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
10323 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
10324 | (1u << PRAGMA_OMP_CLAUSE_ORDERED) \
10325 | (1u << PRAGMA_OMP_CLAUSE_SCHEDULE) \
10326 | (1u << PRAGMA_OMP_CLAUSE_COLLAPSE) \
10327 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
10330 c_parser_omp_for (location_t loc
, c_parser
*parser
)
10332 tree block
, clauses
, ret
;
10334 clauses
= c_parser_omp_all_clauses (parser
, OMP_FOR_CLAUSE_MASK
,
10335 "#pragma omp for");
10337 block
= c_begin_compound_stmt (true);
10338 ret
= c_parser_omp_for_loop (loc
, parser
, clauses
, NULL
);
10339 block
= c_end_compound_stmt (loc
, block
, true);
10346 # pragma omp master new-line
10349 LOC is the location of the #pragma token.
10353 c_parser_omp_master (location_t loc
, c_parser
*parser
)
10355 c_parser_skip_to_pragma_eol (parser
);
10356 return c_finish_omp_master (loc
, c_parser_omp_structured_block (parser
));
10360 # pragma omp ordered new-line
10363 LOC is the location of the #pragma itself.
10367 c_parser_omp_ordered (location_t loc
, c_parser
*parser
)
10369 c_parser_skip_to_pragma_eol (parser
);
10370 return c_finish_omp_ordered (loc
, c_parser_omp_structured_block (parser
));
10376 { section-sequence }
10379 section-directive[opt] structured-block
10380 section-sequence section-directive structured-block
10382 SECTIONS_LOC is the location of the #pragma omp sections. */
10385 c_parser_omp_sections_scope (location_t sections_loc
, c_parser
*parser
)
10387 tree stmt
, substmt
;
10388 bool error_suppress
= false;
10391 loc
= c_parser_peek_token (parser
)->location
;
10392 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
10394 /* Avoid skipping until the end of the block. */
10395 parser
->error
= false;
10399 stmt
= push_stmt_list ();
10401 if (c_parser_peek_token (parser
)->pragma_kind
!= PRAGMA_OMP_SECTION
)
10403 substmt
= push_stmt_list ();
10407 c_parser_statement (parser
);
10409 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
10411 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
10413 if (c_parser_next_token_is (parser
, CPP_EOF
))
10417 substmt
= pop_stmt_list (substmt
);
10418 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
10419 SET_EXPR_LOCATION (substmt
, loc
);
10420 add_stmt (substmt
);
10425 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
10427 if (c_parser_next_token_is (parser
, CPP_EOF
))
10430 loc
= c_parser_peek_token (parser
)->location
;
10431 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
10433 c_parser_consume_pragma (parser
);
10434 c_parser_skip_to_pragma_eol (parser
);
10435 error_suppress
= false;
10437 else if (!error_suppress
)
10439 error_at (loc
, "expected %<#pragma omp section%> or %<}%>");
10440 error_suppress
= true;
10443 substmt
= c_parser_omp_structured_block (parser
);
10444 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
10445 SET_EXPR_LOCATION (substmt
, loc
);
10446 add_stmt (substmt
);
10448 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
,
10449 "expected %<#pragma omp section%> or %<}%>");
10451 substmt
= pop_stmt_list (stmt
);
10453 stmt
= make_node (OMP_SECTIONS
);
10454 SET_EXPR_LOCATION (stmt
, sections_loc
);
10455 TREE_TYPE (stmt
) = void_type_node
;
10456 OMP_SECTIONS_BODY (stmt
) = substmt
;
10458 return add_stmt (stmt
);
10462 # pragma omp sections sections-clause[optseq] newline
10465 LOC is the location of the #pragma token.
10468 #define OMP_SECTIONS_CLAUSE_MASK \
10469 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
10470 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
10471 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
10472 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
10473 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
10476 c_parser_omp_sections (location_t loc
, c_parser
*parser
)
10478 tree block
, clauses
, ret
;
10480 clauses
= c_parser_omp_all_clauses (parser
, OMP_SECTIONS_CLAUSE_MASK
,
10481 "#pragma omp sections");
10483 block
= c_begin_compound_stmt (true);
10484 ret
= c_parser_omp_sections_scope (loc
, parser
);
10486 OMP_SECTIONS_CLAUSES (ret
) = clauses
;
10487 block
= c_end_compound_stmt (loc
, block
, true);
10494 # pragma parallel parallel-clause new-line
10495 # pragma parallel for parallel-for-clause new-line
10496 # pragma parallel sections parallel-sections-clause new-line
10498 LOC is the location of the #pragma token.
10501 #define OMP_PARALLEL_CLAUSE_MASK \
10502 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
10503 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
10504 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
10505 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
10506 | (1u << PRAGMA_OMP_CLAUSE_SHARED) \
10507 | (1u << PRAGMA_OMP_CLAUSE_COPYIN) \
10508 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
10509 | (1u << PRAGMA_OMP_CLAUSE_NUM_THREADS))
10512 c_parser_omp_parallel (location_t loc
, c_parser
*parser
)
10514 enum pragma_kind p_kind
= PRAGMA_OMP_PARALLEL
;
10515 const char *p_name
= "#pragma omp parallel";
10516 tree stmt
, clauses
, par_clause
, ws_clause
, block
;
10517 unsigned int mask
= OMP_PARALLEL_CLAUSE_MASK
;
10519 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
10521 c_parser_consume_token (parser
);
10522 p_kind
= PRAGMA_OMP_PARALLEL_FOR
;
10523 p_name
= "#pragma omp parallel for";
10524 mask
|= OMP_FOR_CLAUSE_MASK
;
10525 mask
&= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT
);
10527 else if (c_parser_next_token_is (parser
, CPP_NAME
))
10529 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10530 if (strcmp (p
, "sections") == 0)
10532 c_parser_consume_token (parser
);
10533 p_kind
= PRAGMA_OMP_PARALLEL_SECTIONS
;
10534 p_name
= "#pragma omp parallel sections";
10535 mask
|= OMP_SECTIONS_CLAUSE_MASK
;
10536 mask
&= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT
);
10540 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
);
10544 case PRAGMA_OMP_PARALLEL
:
10545 block
= c_begin_omp_parallel ();
10546 c_parser_statement (parser
);
10547 stmt
= c_finish_omp_parallel (loc
, clauses
, block
);
10550 case PRAGMA_OMP_PARALLEL_FOR
:
10551 block
= c_begin_omp_parallel ();
10552 c_split_parallel_clauses (loc
, clauses
, &par_clause
, &ws_clause
);
10553 c_parser_omp_for_loop (loc
, parser
, ws_clause
, &par_clause
);
10554 stmt
= c_finish_omp_parallel (loc
, par_clause
, block
);
10555 OMP_PARALLEL_COMBINED (stmt
) = 1;
10558 case PRAGMA_OMP_PARALLEL_SECTIONS
:
10559 block
= c_begin_omp_parallel ();
10560 c_split_parallel_clauses (loc
, clauses
, &par_clause
, &ws_clause
);
10561 stmt
= c_parser_omp_sections_scope (loc
, parser
);
10563 OMP_SECTIONS_CLAUSES (stmt
) = ws_clause
;
10564 stmt
= c_finish_omp_parallel (loc
, par_clause
, block
);
10565 OMP_PARALLEL_COMBINED (stmt
) = 1;
10569 gcc_unreachable ();
10576 # pragma omp single single-clause[optseq] new-line
10579 LOC is the location of the #pragma.
10582 #define OMP_SINGLE_CLAUSE_MASK \
10583 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
10584 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
10585 | (1u << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
10586 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
10589 c_parser_omp_single (location_t loc
, c_parser
*parser
)
10591 tree stmt
= make_node (OMP_SINGLE
);
10592 SET_EXPR_LOCATION (stmt
, loc
);
10593 TREE_TYPE (stmt
) = void_type_node
;
10595 OMP_SINGLE_CLAUSES (stmt
)
10596 = c_parser_omp_all_clauses (parser
, OMP_SINGLE_CLAUSE_MASK
,
10597 "#pragma omp single");
10598 OMP_SINGLE_BODY (stmt
) = c_parser_omp_structured_block (parser
);
10600 return add_stmt (stmt
);
10604 # pragma omp task task-clause[optseq] new-line
10606 LOC is the location of the #pragma.
10609 #define OMP_TASK_CLAUSE_MASK \
10610 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
10611 | (1u << PRAGMA_OMP_CLAUSE_UNTIED) \
10612 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
10613 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
10614 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
10615 | (1u << PRAGMA_OMP_CLAUSE_SHARED) \
10616 | (1u << PRAGMA_OMP_CLAUSE_FINAL) \
10617 | (1u << PRAGMA_OMP_CLAUSE_MERGEABLE))
10620 c_parser_omp_task (location_t loc
, c_parser
*parser
)
10622 tree clauses
, block
;
10624 clauses
= c_parser_omp_all_clauses (parser
, OMP_TASK_CLAUSE_MASK
,
10625 "#pragma omp task");
10627 block
= c_begin_omp_task ();
10628 c_parser_statement (parser
);
10629 return c_finish_omp_task (loc
, clauses
, block
);
10633 # pragma omp taskwait new-line
10637 c_parser_omp_taskwait (c_parser
*parser
)
10639 location_t loc
= c_parser_peek_token (parser
)->location
;
10640 c_parser_consume_pragma (parser
);
10641 c_parser_skip_to_pragma_eol (parser
);
10643 c_finish_omp_taskwait (loc
);
10647 # pragma omp taskyield new-line
10651 c_parser_omp_taskyield (c_parser
*parser
)
10653 location_t loc
= c_parser_peek_token (parser
)->location
;
10654 c_parser_consume_pragma (parser
);
10655 c_parser_skip_to_pragma_eol (parser
);
10657 c_finish_omp_taskyield (loc
);
10660 /* Main entry point to parsing most OpenMP pragmas. */
10663 c_parser_omp_construct (c_parser
*parser
)
10665 enum pragma_kind p_kind
;
10669 loc
= c_parser_peek_token (parser
)->location
;
10670 p_kind
= c_parser_peek_token (parser
)->pragma_kind
;
10671 c_parser_consume_pragma (parser
);
10675 case PRAGMA_OMP_ATOMIC
:
10676 c_parser_omp_atomic (loc
, parser
);
10678 case PRAGMA_OMP_CRITICAL
:
10679 stmt
= c_parser_omp_critical (loc
, parser
);
10681 case PRAGMA_OMP_FOR
:
10682 stmt
= c_parser_omp_for (loc
, parser
);
10684 case PRAGMA_OMP_MASTER
:
10685 stmt
= c_parser_omp_master (loc
, parser
);
10687 case PRAGMA_OMP_ORDERED
:
10688 stmt
= c_parser_omp_ordered (loc
, parser
);
10690 case PRAGMA_OMP_PARALLEL
:
10691 stmt
= c_parser_omp_parallel (loc
, parser
);
10693 case PRAGMA_OMP_SECTIONS
:
10694 stmt
= c_parser_omp_sections (loc
, parser
);
10696 case PRAGMA_OMP_SINGLE
:
10697 stmt
= c_parser_omp_single (loc
, parser
);
10699 case PRAGMA_OMP_TASK
:
10700 stmt
= c_parser_omp_task (loc
, parser
);
10703 gcc_unreachable ();
10707 gcc_assert (EXPR_LOCATION (stmt
) != UNKNOWN_LOCATION
);
10712 # pragma omp threadprivate (variable-list) */
10715 c_parser_omp_threadprivate (c_parser
*parser
)
10720 c_parser_consume_pragma (parser
);
10721 loc
= c_parser_peek_token (parser
)->location
;
10722 vars
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
10724 /* Mark every variable in VARS to be assigned thread local storage. */
10725 for (t
= vars
; t
; t
= TREE_CHAIN (t
))
10727 tree v
= TREE_PURPOSE (t
);
10729 /* FIXME diagnostics: Ideally we should keep individual
10730 locations for all the variables in the var list to make the
10731 following errors more precise. Perhaps
10732 c_parser_omp_var_list_parens() should construct a list of
10733 locations to go along with the var list. */
10735 /* If V had already been marked threadprivate, it doesn't matter
10736 whether it had been used prior to this point. */
10737 if (TREE_CODE (v
) != VAR_DECL
)
10738 error_at (loc
, "%qD is not a variable", v
);
10739 else if (TREE_USED (v
) && !C_DECL_THREADPRIVATE_P (v
))
10740 error_at (loc
, "%qE declared %<threadprivate%> after first use", v
);
10741 else if (! TREE_STATIC (v
) && ! DECL_EXTERNAL (v
))
10742 error_at (loc
, "automatic variable %qE cannot be %<threadprivate%>", v
);
10743 else if (TREE_TYPE (v
) == error_mark_node
)
10745 else if (! COMPLETE_TYPE_P (TREE_TYPE (v
)))
10746 error_at (loc
, "%<threadprivate%> %qE has incomplete type", v
);
10749 if (! DECL_THREAD_LOCAL_P (v
))
10751 DECL_TLS_MODEL (v
) = decl_default_tls_model (v
);
10752 /* If rtl has been already set for this var, call
10753 make_decl_rtl once again, so that encode_section_info
10754 has a chance to look at the new decl flags. */
10755 if (DECL_RTL_SET_P (v
))
10758 C_DECL_THREADPRIVATE_P (v
) = 1;
10762 c_parser_skip_to_pragma_eol (parser
);
10765 /* Parse a transaction attribute (GCC Extension).
10767 transaction-attribute:
10771 The transactional memory language description is written for C++,
10772 and uses the C++0x attribute syntax. For compatibility, allow the
10773 bracket style for transactions in C as well. */
10776 c_parser_transaction_attributes (c_parser
*parser
)
10778 tree attr_name
, attr
= NULL
;
10780 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
10781 return c_parser_attributes (parser
);
10783 if (!c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
10785 c_parser_consume_token (parser
);
10786 if (!c_parser_require (parser
, CPP_OPEN_SQUARE
, "expected %<[%>"))
10789 attr_name
= c_parser_attribute_any_word (parser
);
10792 c_parser_consume_token (parser
);
10793 attr
= build_tree_list (attr_name
, NULL_TREE
);
10796 c_parser_error (parser
, "expected identifier");
10798 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
10800 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
10804 /* Parse a __transaction_atomic or __transaction_relaxed statement
10807 transaction-statement:
10808 __transaction_atomic transaction-attribute[opt] compound-statement
10809 __transaction_relaxed compound-statement
10811 Note that the only valid attribute is: "outer".
10815 c_parser_transaction (c_parser
*parser
, enum rid keyword
)
10817 unsigned int old_in
= parser
->in_transaction
;
10818 unsigned int this_in
= 1, new_in
;
10819 location_t loc
= c_parser_peek_token (parser
)->location
;
10822 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
10823 || keyword
== RID_TRANSACTION_RELAXED
)
10824 && c_parser_next_token_is_keyword (parser
, keyword
));
10825 c_parser_consume_token (parser
);
10827 if (keyword
== RID_TRANSACTION_RELAXED
)
10828 this_in
|= TM_STMT_ATTR_RELAXED
;
10831 attrs
= c_parser_transaction_attributes (parser
);
10833 this_in
|= parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
);
10836 /* Keep track if we're in the lexical scope of an outer transaction. */
10837 new_in
= this_in
| (old_in
& TM_STMT_ATTR_OUTER
);
10839 parser
->in_transaction
= new_in
;
10840 stmt
= c_parser_compound_statement (parser
);
10841 parser
->in_transaction
= old_in
;
10844 stmt
= c_finish_transaction (loc
, stmt
, this_in
);
10846 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
10847 "%<__transaction_atomic%> without transactional memory support enabled"
10848 : "%<__transaction_relaxed %> "
10849 "without transactional memory support enabled"));
10854 /* Parse a __transaction_atomic or __transaction_relaxed expression
10857 transaction-expression:
10858 __transaction_atomic ( expression )
10859 __transaction_relaxed ( expression )
10862 static struct c_expr
10863 c_parser_transaction_expression (c_parser
*parser
, enum rid keyword
)
10866 unsigned int old_in
= parser
->in_transaction
;
10867 unsigned int this_in
= 1;
10868 location_t loc
= c_parser_peek_token (parser
)->location
;
10871 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
10872 || keyword
== RID_TRANSACTION_RELAXED
)
10873 && c_parser_next_token_is_keyword (parser
, keyword
));
10874 c_parser_consume_token (parser
);
10876 if (keyword
== RID_TRANSACTION_RELAXED
)
10877 this_in
|= TM_STMT_ATTR_RELAXED
;
10880 attrs
= c_parser_transaction_attributes (parser
);
10882 this_in
|= parse_tm_stmt_attr (attrs
, 0);
10885 parser
->in_transaction
= this_in
;
10886 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10888 tree expr
= c_parser_expression (parser
).value
;
10889 ret
.original_type
= TREE_TYPE (expr
);
10890 ret
.value
= build1 (TRANSACTION_EXPR
, ret
.original_type
, expr
);
10891 if (this_in
& TM_STMT_ATTR_RELAXED
)
10892 TRANSACTION_EXPR_RELAXED (ret
.value
) = 1;
10893 SET_EXPR_LOCATION (ret
.value
, loc
);
10894 ret
.original_code
= TRANSACTION_EXPR
;
10895 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
10897 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
10904 ret
.value
= error_mark_node
;
10905 ret
.original_code
= ERROR_MARK
;
10906 ret
.original_type
= NULL
;
10908 parser
->in_transaction
= old_in
;
10911 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
10912 "%<__transaction_atomic%> without transactional memory support enabled"
10913 : "%<__transaction_relaxed %> "
10914 "without transactional memory support enabled"));
10919 /* Parse a __transaction_cancel statement (GCC Extension).
10921 transaction-cancel-statement:
10922 __transaction_cancel transaction-attribute[opt] ;
10924 Note that the only valid attribute is "outer".
10928 c_parser_transaction_cancel(c_parser
*parser
)
10930 location_t loc
= c_parser_peek_token (parser
)->location
;
10932 bool is_outer
= false;
10934 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TRANSACTION_CANCEL
));
10935 c_parser_consume_token (parser
);
10937 attrs
= c_parser_transaction_attributes (parser
);
10939 is_outer
= (parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
) != 0);
10943 error_at (loc
, "%<__transaction_cancel%> without "
10944 "transactional memory support enabled");
10947 else if (parser
->in_transaction
& TM_STMT_ATTR_RELAXED
)
10949 error_at (loc
, "%<__transaction_cancel%> within a "
10950 "%<__transaction_relaxed%>");
10955 if ((parser
->in_transaction
& TM_STMT_ATTR_OUTER
) == 0
10956 && !is_tm_may_cancel_outer (current_function_decl
))
10958 error_at (loc
, "outer %<__transaction_cancel%> not "
10959 "within outer %<__transaction_atomic%>");
10960 error_at (loc
, " or a %<transaction_may_cancel_outer%> function");
10964 else if (parser
->in_transaction
== 0)
10966 error_at (loc
, "%<__transaction_cancel%> not within "
10967 "%<__transaction_atomic%>");
10971 return add_stmt (build_tm_abort_call (loc
, is_outer
));
10974 return build1 (NOP_EXPR
, void_type_node
, error_mark_node
);
10977 /* Parse a single source file. */
10980 c_parse_file (void)
10982 /* Use local storage to begin. If the first token is a pragma, parse it.
10983 If it is #pragma GCC pch_preprocess, then this will load a PCH file
10984 which will cause garbage collection. */
10987 memset (&tparser
, 0, sizeof tparser
);
10988 the_parser
= &tparser
;
10990 if (c_parser_peek_token (&tparser
)->pragma_kind
== PRAGMA_GCC_PCH_PREPROCESS
)
10991 c_parser_pragma_pch_preprocess (&tparser
);
10993 the_parser
= ggc_alloc_c_parser ();
10994 *the_parser
= tparser
;
10996 /* Initialize EH, if we've been told to do so. */
10997 if (flag_exceptions
)
10998 using_eh_for_cleanups ();
11000 c_parser_translation_unit (the_parser
);
11004 /* This function parses Cilk Plus array notation. The starting index is
11005 passed in INITIAL_INDEX and the array name is passes in ARRAY_VALUE. The
11006 return value of this function is a tree_node called VALUE_TREE of type
11007 ARRAY_NOTATION_REF. */
11010 c_parser_array_notation (location_t loc
, c_parser
*parser
, tree initial_index
,
11013 c_token
*token
= NULL
;
11014 tree start_index
= NULL_TREE
, end_index
= NULL_TREE
, stride
= NULL_TREE
;
11015 tree value_tree
= NULL_TREE
, type
= NULL_TREE
, array_type
= NULL_TREE
;
11016 tree array_type_domain
= NULL_TREE
;
11018 if (array_value
== error_mark_node
)
11020 /* No need to continue. If either of these 2 were true, then an error
11021 must be emitted already. Thus, no need to emit them twice. */
11022 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
11023 return error_mark_node
;
11026 array_type
= TREE_TYPE (array_value
);
11027 gcc_assert (array_type
);
11028 type
= TREE_TYPE (array_type
);
11029 token
= c_parser_peek_token (parser
);
11031 if (token
->type
== CPP_EOF
)
11033 c_parser_error (parser
, "expected %<:%> or numeral");
11036 else if (token
->type
== CPP_COLON
)
11038 if (!initial_index
)
11040 /* If we are here, then we have a case like this A[:]. */
11041 c_parser_consume_token (parser
);
11042 if (TREE_CODE (array_type
) == POINTER_TYPE
)
11044 error_at (loc
, "start-index and length fields necessary for "
11045 "using array notations in pointers");
11046 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
11047 return error_mark_node
;
11049 if (TREE_CODE (array_type
) == FUNCTION_TYPE
)
11051 error_at (loc
, "array notations cannot be used with function "
11053 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
11054 return error_mark_node
;
11056 if (TREE_CODE (array_type
) == ARRAY_TYPE
)
11058 tree subtype
= TREE_TYPE (array_type
);
11059 while (subtype
&& TREE_CODE (subtype
) == POINTER_TYPE
)
11061 /* Now this could be a function pointer. Find them and
11062 give out an error. */
11063 subtype
= TREE_TYPE (subtype
);
11064 if (subtype
&& TREE_CODE (subtype
) == FUNCTION_TYPE
)
11066 error_at (loc
, "array notations cannot be used with "
11067 "function pointer arrays");
11068 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
11070 return error_mark_node
;
11074 array_type_domain
= TYPE_DOMAIN (array_type
);
11076 if (!array_type_domain
)
11078 error_at (loc
, "start-index and length fields necessary for "
11079 "using array notations in dimensionless arrays");
11080 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
11081 return error_mark_node
;
11084 start_index
= TYPE_MINVAL (array_type_domain
);
11085 start_index
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
,
11087 if (!TYPE_MAXVAL (array_type_domain
)
11088 || !TREE_CONSTANT (TYPE_MAXVAL (array_type_domain
)))
11090 error_at (loc
, "start-index and length fields necessary for "
11091 "using array notations in variable-length arrays");
11092 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
11093 return error_mark_node
;
11095 end_index
= TYPE_MAXVAL (array_type_domain
);
11096 end_index
= fold_build2 (PLUS_EXPR
, TREE_TYPE (end_index
),
11097 end_index
, integer_one_node
);
11098 end_index
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
, end_index
);
11099 stride
= build_int_cst (integer_type_node
, 1);
11100 stride
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
, stride
);
11102 else if (initial_index
!= error_mark_node
)
11104 /* If we are here, then there should be 2 possibilities:
11105 1. Array [EXPR : EXPR]
11106 2. Array [EXPR : EXPR : EXPR]
11108 start_index
= initial_index
;
11110 if (TREE_CODE (array_type
) == FUNCTION_TYPE
)
11112 error_at (loc
, "array notations cannot be used with function "
11114 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
11115 return error_mark_node
;
11117 if (TREE_CODE (array_type
) == ARRAY_TYPE
11118 || TREE_CODE (array_type
) == POINTER_TYPE
)
11120 tree subtype
= TREE_TYPE (array_type
);
11122 && (TREE_CODE (subtype
) == POINTER_TYPE
11123 || TREE_CODE (subtype
) == ARRAY_TYPE
))
11125 /* Now this could be a function pointer. Find them and
11126 give out an error. */
11127 subtype
= TREE_TYPE (subtype
);
11128 if (subtype
&& TREE_CODE (subtype
) == FUNCTION_TYPE
)
11130 error_at (loc
, "array notations cannot be used with "
11131 "function pointer arrays");
11132 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
11134 return error_mark_node
;
11138 c_parser_consume_token (parser
); /* consume the ':' */
11139 end_index
= c_parser_expression (parser
).value
;
11140 if (!end_index
|| end_index
== error_mark_node
)
11142 c_parser_skip_to_end_of_block_or_statement (parser
);
11143 return error_mark_node
;
11145 if (c_parser_peek_token (parser
)->type
== CPP_COLON
)
11147 c_parser_consume_token (parser
);
11148 stride
= c_parser_expression (parser
).value
;
11149 if (!stride
|| stride
== error_mark_node
)
11151 c_parser_skip_to_end_of_block_or_statement (parser
);
11152 return error_mark_node
;
11157 c_parser_error (parser
, "expected array notation expression");
11160 c_parser_error (parser
, "expected array notation expression");
11162 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
11164 value_tree
= build_array_notation_ref (loc
, array_value
, start_index
,
11165 end_index
, stride
, type
);
11166 if (value_tree
!= error_mark_node
)
11167 SET_EXPR_LOCATION (value_tree
, loc
);
11171 #include "gt-c-c-parser.h"