1 /* Parser for C and Objective-C.
2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010, 2011
4 Free Software Foundation, Inc.
6 Parser actions based on the old Bison parser; structure somewhat
7 influenced by and fragments based on the C++ parser.
9 This file is part of GCC.
11 GCC is free software; you can redistribute it and/or modify it under
12 the terms of the GNU General Public License as published by the Free
13 Software Foundation; either version 3, or (at your option) any later
16 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
17 WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with GCC; see the file COPYING3. If not see
23 <http://www.gnu.org/licenses/>. */
27 Make sure all relevant comments, and all relevant code from all
28 actions, brought over from old parser. Verify exact correspondence
31 Add testcases covering every input symbol in every state in old and
34 Include full syntax for GNU C, including erroneous cases accepted
35 with error messages, in syntax productions in comments.
37 Make more diagnostics in the front end generally take an explicit
38 location rather than implicitly using input_location. */
42 #include "coretypes.h"
43 #include "tm.h" /* For rtl.h: needs enum reg_class. */
45 #include "langhooks.h"
49 #include "c-family/c-pragma.h"
54 #include "c-family/c-common.h"
55 #include "c-family/c-objc.h"
62 /* Initialization routine for this file. */
67 /* The only initialization required is of the reserved word
73 /* Make sure RID_MAX hasn't grown past the 8 bits used to hold the keyword in
74 the c_token structure. */
75 gcc_assert (RID_MAX
<= 255);
82 mask
|= D_ASM
| D_EXT
;
86 if (!c_dialect_objc ())
87 mask
|= D_OBJC
| D_CXX_OBJC
;
89 ridpointers
= ggc_alloc_cleared_vec_tree ((int) RID_MAX
);
90 for (i
= 0; i
< num_c_common_reswords
; i
++)
92 /* If a keyword is disabled, do not enter it into the table
93 and so create a canonical spelling that isn't a keyword. */
94 if (c_common_reswords
[i
].disable
& mask
)
97 && (c_common_reswords
[i
].disable
& D_CXXWARN
))
99 id
= get_identifier (c_common_reswords
[i
].word
);
100 C_SET_RID_CODE (id
, RID_CXX_COMPAT_WARN
);
101 C_IS_RESERVED_WORD (id
) = 1;
106 id
= get_identifier (c_common_reswords
[i
].word
);
107 C_SET_RID_CODE (id
, c_common_reswords
[i
].rid
);
108 C_IS_RESERVED_WORD (id
) = 1;
109 ridpointers
[(int) c_common_reswords
[i
].rid
] = id
;
113 /* The C lexer intermediates between the lexer in cpplib and c-lex.c
114 and the C parser. Unlike the C++ lexer, the parser structure
115 stores the lexer information instead of using a separate structure.
116 Identifiers are separated into ordinary identifiers, type names,
117 keywords and some other Objective-C types of identifiers, and some
118 look-ahead is maintained.
120 ??? It might be a good idea to lex the whole file up front (as for
121 C++). It would then be possible to share more of the C and C++
122 lexer code, if desired. */
124 /* The following local token type is used. */
127 #define CPP_KEYWORD ((enum cpp_ttype) (N_TTYPES + 1))
129 /* More information about the type of a CPP_NAME token. */
130 typedef enum c_id_kind
{
131 /* An ordinary identifier. */
133 /* An identifier declared as a typedef name. */
135 /* An identifier declared as an Objective-C class name. */
137 /* An address space identifier. */
139 /* Not an identifier. */
143 /* A single C token after string literal concatenation and conversion
144 of preprocessing tokens to tokens. */
145 typedef struct GTY (()) c_token
{
146 /* The kind of token. */
147 ENUM_BITFIELD (cpp_ttype
) type
: 8;
148 /* If this token is a CPP_NAME, this value indicates whether also
149 declared as some kind of type. Otherwise, it is C_ID_NONE. */
150 ENUM_BITFIELD (c_id_kind
) id_kind
: 8;
151 /* If this token is a keyword, this value indicates which keyword.
152 Otherwise, this value is RID_MAX. */
153 ENUM_BITFIELD (rid
) keyword
: 8;
154 /* If this token is a CPP_PRAGMA, this indicates the pragma that
155 was seen. Otherwise it is PRAGMA_NONE. */
156 ENUM_BITFIELD (pragma_kind
) pragma_kind
: 8;
157 /* The location at which this token was found. */
159 /* The value associated with this token, if any. */
163 /* A parser structure recording information about the state and
164 context of parsing. Includes lexer information with up to two
165 tokens of look-ahead; more are not needed for C. */
166 typedef struct GTY(()) c_parser
{
167 /* The look-ahead tokens. */
169 /* How many look-ahead tokens are available (0, 1 or 2). */
171 /* True if a syntax error is being recovered from; false otherwise.
172 c_parser_error sets this flag. It should clear this flag when
173 enough tokens have been consumed to recover from the error. */
174 BOOL_BITFIELD error
: 1;
175 /* True if we're processing a pragma, and shouldn't automatically
176 consume CPP_PRAGMA_EOL. */
177 BOOL_BITFIELD in_pragma
: 1;
178 /* True if we're parsing the outermost block of an if statement. */
179 BOOL_BITFIELD in_if_block
: 1;
180 /* True if we want to lex an untranslated string. */
181 BOOL_BITFIELD lex_untranslated_string
: 1;
183 /* Objective-C specific parser/lexer information. */
185 /* True if we are in a context where the Objective-C "PQ" keywords
186 are considered keywords. */
187 BOOL_BITFIELD objc_pq_context
: 1;
188 /* True if we are parsing a (potential) Objective-C foreach
189 statement. This is set to true after we parsed 'for (' and while
190 we wait for 'in' or ';' to decide if it's a standard C for loop or an
191 Objective-C foreach loop. */
192 BOOL_BITFIELD objc_could_be_foreach_context
: 1;
193 /* The following flag is needed to contextualize Objective-C lexical
194 analysis. In some cases (e.g., 'int NSObject;'), it is
195 undesirable to bind an identifier to an Objective-C class, even
196 if a class with that name exists. */
197 BOOL_BITFIELD objc_need_raw_identifier
: 1;
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 && (global_bindings_p ()
338 || (!objc_force_identifier
&& !decl
)))
340 token
->value
= objc_interface_decl
;
341 token
->id_kind
= C_ID_CLASSNAME
;
345 token
->id_kind
= C_ID_ID
;
349 /* This only happens in Objective-C; it must be a keyword. */
350 token
->type
= CPP_KEYWORD
;
351 switch (C_RID_CODE (token
->value
))
353 /* Replace 'class' with '@class', 'private' with '@private',
354 etc. This prevents confusion with the C++ keyword
355 'class', and makes the tokens consistent with other
356 Objective-C 'AT' keywords. For example '@class' is
357 reported as RID_AT_CLASS which is consistent with
358 '@synchronized', which is reported as
361 case RID_CLASS
: token
->keyword
= RID_AT_CLASS
; break;
362 case RID_PRIVATE
: token
->keyword
= RID_AT_PRIVATE
; break;
363 case RID_PROTECTED
: token
->keyword
= RID_AT_PROTECTED
; break;
364 case RID_PUBLIC
: token
->keyword
= RID_AT_PUBLIC
; break;
365 case RID_THROW
: token
->keyword
= RID_AT_THROW
; break;
366 case RID_TRY
: token
->keyword
= RID_AT_TRY
; break;
367 case RID_CATCH
: token
->keyword
= RID_AT_CATCH
; break;
368 default: token
->keyword
= C_RID_CODE (token
->value
);
373 case CPP_CLOSE_PAREN
:
375 /* These tokens may affect the interpretation of any identifiers
376 following, if doing Objective-C. */
377 if (c_dialect_objc ())
378 parser
->objc_need_raw_identifier
= false;
381 /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */
382 token
->pragma_kind
= (enum pragma_kind
) TREE_INT_CST_LOW (token
->value
);
388 timevar_pop (TV_LEX
);
391 /* Return a pointer to the next token from PARSER, reading it in if
394 static inline c_token
*
395 c_parser_peek_token (c_parser
*parser
)
397 if (parser
->tokens_avail
== 0)
399 c_lex_one_token (parser
, &parser
->tokens
[0]);
400 parser
->tokens_avail
= 1;
402 return &parser
->tokens
[0];
405 /* Return true if the next token from PARSER has the indicated
409 c_parser_next_token_is (c_parser
*parser
, enum cpp_ttype type
)
411 return c_parser_peek_token (parser
)->type
== type
;
414 /* Return true if the next token from PARSER does not have the
418 c_parser_next_token_is_not (c_parser
*parser
, enum cpp_ttype type
)
420 return !c_parser_next_token_is (parser
, type
);
423 /* Return true if the next token from PARSER is the indicated
427 c_parser_next_token_is_keyword (c_parser
*parser
, enum rid keyword
)
429 return c_parser_peek_token (parser
)->keyword
== keyword
;
432 /* Return a pointer to the next-but-one token from PARSER, reading it
433 in if necessary. The next token is already read in. */
436 c_parser_peek_2nd_token (c_parser
*parser
)
438 if (parser
->tokens_avail
>= 2)
439 return &parser
->tokens
[1];
440 gcc_assert (parser
->tokens_avail
== 1);
441 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
442 gcc_assert (parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
443 c_lex_one_token (parser
, &parser
->tokens
[1]);
444 parser
->tokens_avail
= 2;
445 return &parser
->tokens
[1];
448 /* Return true if TOKEN can start a type name,
451 c_token_starts_typename (c_token
*token
)
456 switch (token
->id_kind
)
465 gcc_assert (c_dialect_objc ());
471 switch (token
->keyword
)
504 if (c_dialect_objc ())
512 enum c_lookahead_kind
{
513 /* Always treat unknown identifiers as typenames. */
516 /* Could be parsing a nonabstract declarator. Only treat an identifier
517 as a typename if followed by another identifier or a star. */
518 cla_nonabstract_decl
,
520 /* Never treat identifiers as typenames. */
524 /* Return true if the next token from PARSER can start a type name,
525 false otherwise. LA specifies how to do lookahead in order to
526 detect unknown type names. If unsure, pick CLA_PREFER_ID. */
529 c_parser_next_tokens_start_typename (c_parser
*parser
, enum c_lookahead_kind la
)
531 c_token
*token
= c_parser_peek_token (parser
);
532 if (c_token_starts_typename (token
))
535 /* Try a bit harder to detect an unknown typename. */
536 if (la
!= cla_prefer_id
537 && token
->type
== CPP_NAME
538 && token
->id_kind
== C_ID_ID
540 /* Do not try too hard when we could have "object in array". */
541 && !parser
->objc_could_be_foreach_context
543 && (la
== cla_prefer_type
544 || c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
545 || c_parser_peek_2nd_token (parser
)->type
== CPP_MULT
)
547 /* Only unknown identifiers. */
548 && !lookup_name (token
->value
))
554 /* Return true if TOKEN is a type qualifier, false otherwise. */
556 c_token_is_qualifier (c_token
*token
)
561 switch (token
->id_kind
)
569 switch (token
->keyword
)
586 /* Return true if the next token from PARSER is a type qualifier,
589 c_parser_next_token_is_qualifier (c_parser
*parser
)
591 c_token
*token
= c_parser_peek_token (parser
);
592 return c_token_is_qualifier (token
);
595 /* Return true if TOKEN can start declaration specifiers, false
598 c_token_starts_declspecs (c_token
*token
)
603 switch (token
->id_kind
)
612 gcc_assert (c_dialect_objc ());
618 switch (token
->keyword
)
658 if (c_dialect_objc ())
667 /* Return true if TOKEN can start declaration specifiers or a static
668 assertion, false otherwise. */
670 c_token_starts_declaration (c_token
*token
)
672 if (c_token_starts_declspecs (token
)
673 || token
->keyword
== RID_STATIC_ASSERT
)
679 /* Return true if the next token from PARSER can start declaration
680 specifiers, false otherwise. */
682 c_parser_next_token_starts_declspecs (c_parser
*parser
)
684 c_token
*token
= c_parser_peek_token (parser
);
686 /* In Objective-C, a classname normally starts a declspecs unless it
687 is immediately followed by a dot. In that case, it is the
688 Objective-C 2.0 "dot-syntax" for class objects, ie, calls the
689 setter/getter on the class. c_token_starts_declspecs() can't
690 differentiate between the two cases because it only checks the
691 current token, so we have a special check here. */
692 if (c_dialect_objc ()
693 && token
->type
== CPP_NAME
694 && token
->id_kind
== C_ID_CLASSNAME
695 && c_parser_peek_2nd_token (parser
)->type
== CPP_DOT
)
698 return c_token_starts_declspecs (token
);
701 /* Return true if the next tokens from PARSER can start declaration
702 specifiers or a static assertion, false otherwise. */
704 c_parser_next_tokens_start_declaration (c_parser
*parser
)
706 c_token
*token
= c_parser_peek_token (parser
);
709 if (c_dialect_objc ()
710 && token
->type
== CPP_NAME
711 && token
->id_kind
== C_ID_CLASSNAME
712 && c_parser_peek_2nd_token (parser
)->type
== CPP_DOT
)
715 /* Labels do not start declarations. */
716 if (token
->type
== CPP_NAME
717 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
720 if (c_token_starts_declaration (token
))
723 if (c_parser_next_tokens_start_typename (parser
, cla_nonabstract_decl
))
729 /* Consume the next token from PARSER. */
732 c_parser_consume_token (c_parser
*parser
)
734 gcc_assert (parser
->tokens_avail
>= 1);
735 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
736 gcc_assert (!parser
->in_pragma
|| parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
737 gcc_assert (parser
->error
|| parser
->tokens
[0].type
!= CPP_PRAGMA
);
738 if (parser
->tokens_avail
== 2)
739 parser
->tokens
[0] = parser
->tokens
[1];
740 parser
->tokens_avail
--;
743 /* Expect the current token to be a #pragma. Consume it and remember
744 that we've begun parsing a pragma. */
747 c_parser_consume_pragma (c_parser
*parser
)
749 gcc_assert (!parser
->in_pragma
);
750 gcc_assert (parser
->tokens_avail
>= 1);
751 gcc_assert (parser
->tokens
[0].type
== CPP_PRAGMA
);
752 if (parser
->tokens_avail
== 2)
753 parser
->tokens
[0] = parser
->tokens
[1];
754 parser
->tokens_avail
--;
755 parser
->in_pragma
= true;
758 /* Update the globals input_location and in_system_header from
761 c_parser_set_source_position_from_token (c_token
*token
)
763 if (token
->type
!= CPP_EOF
)
765 input_location
= token
->location
;
769 /* Issue a diagnostic of the form
770 FILE:LINE: MESSAGE before TOKEN
771 where TOKEN is the next token in the input stream of PARSER.
772 MESSAGE (specified by the caller) is usually of the form "expected
775 Do not issue a diagnostic if still recovering from an error.
777 ??? This is taken from the C++ parser, but building up messages in
778 this way is not i18n-friendly and some other approach should be
782 c_parser_error (c_parser
*parser
, const char *gmsgid
)
784 c_token
*token
= c_parser_peek_token (parser
);
787 parser
->error
= true;
790 /* This diagnostic makes more sense if it is tagged to the line of
791 the token we just peeked at. */
792 c_parser_set_source_position_from_token (token
);
793 c_parse_error (gmsgid
,
794 /* Because c_parse_error does not understand
795 CPP_KEYWORD, keywords are treated like
797 (token
->type
== CPP_KEYWORD
? CPP_NAME
: token
->type
),
798 /* ??? The C parser does not save the cpp flags of a
799 token, we need to pass 0 here and we will not get
800 the source spelling of some tokens but rather the
801 canonical spelling. */
802 token
->value
, /*flags=*/0);
805 /* If the next token is of the indicated TYPE, consume it. Otherwise,
806 issue the error MSGID. If MSGID is NULL then a message has already
807 been produced and no message will be produced this time. Returns
808 true if found, false otherwise. */
811 c_parser_require (c_parser
*parser
,
815 if (c_parser_next_token_is (parser
, type
))
817 c_parser_consume_token (parser
);
822 c_parser_error (parser
, msgid
);
827 /* If the next token is the indicated keyword, consume it. Otherwise,
828 issue the error MSGID. Returns true if found, false otherwise. */
831 c_parser_require_keyword (c_parser
*parser
,
835 if (c_parser_next_token_is_keyword (parser
, keyword
))
837 c_parser_consume_token (parser
);
842 c_parser_error (parser
, msgid
);
847 /* Like c_parser_require, except that tokens will be skipped until the
848 desired token is found. An error message is still produced if the
849 next token is not as expected. If MSGID is NULL then a message has
850 already been produced and no message will be produced this
854 c_parser_skip_until_found (c_parser
*parser
,
858 unsigned nesting_depth
= 0;
860 if (c_parser_require (parser
, type
, msgid
))
863 /* Skip tokens until the desired token is found. */
866 /* Peek at the next token. */
867 c_token
*token
= c_parser_peek_token (parser
);
868 /* If we've reached the token we want, consume it and stop. */
869 if (token
->type
== type
&& !nesting_depth
)
871 c_parser_consume_token (parser
);
875 /* If we've run out of tokens, stop. */
876 if (token
->type
== CPP_EOF
)
878 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
880 if (token
->type
== CPP_OPEN_BRACE
881 || token
->type
== CPP_OPEN_PAREN
882 || token
->type
== CPP_OPEN_SQUARE
)
884 else if (token
->type
== CPP_CLOSE_BRACE
885 || token
->type
== CPP_CLOSE_PAREN
886 || token
->type
== CPP_CLOSE_SQUARE
)
888 if (nesting_depth
-- == 0)
891 /* Consume this token. */
892 c_parser_consume_token (parser
);
894 parser
->error
= false;
897 /* Skip tokens until the end of a parameter is found, but do not
898 consume the comma, semicolon or closing delimiter. */
901 c_parser_skip_to_end_of_parameter (c_parser
*parser
)
903 unsigned nesting_depth
= 0;
907 c_token
*token
= c_parser_peek_token (parser
);
908 if ((token
->type
== CPP_COMMA
|| token
->type
== CPP_SEMICOLON
)
911 /* If we've run out of tokens, stop. */
912 if (token
->type
== CPP_EOF
)
914 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
916 if (token
->type
== CPP_OPEN_BRACE
917 || token
->type
== CPP_OPEN_PAREN
918 || token
->type
== CPP_OPEN_SQUARE
)
920 else if (token
->type
== CPP_CLOSE_BRACE
921 || token
->type
== CPP_CLOSE_PAREN
922 || token
->type
== CPP_CLOSE_SQUARE
)
924 if (nesting_depth
-- == 0)
927 /* Consume this token. */
928 c_parser_consume_token (parser
);
930 parser
->error
= false;
933 /* Expect to be at the end of the pragma directive and consume an
934 end of line marker. */
937 c_parser_skip_to_pragma_eol (c_parser
*parser
)
939 gcc_assert (parser
->in_pragma
);
940 parser
->in_pragma
= false;
942 if (!c_parser_require (parser
, CPP_PRAGMA_EOL
, "expected end of line"))
945 c_token
*token
= c_parser_peek_token (parser
);
946 if (token
->type
== CPP_EOF
)
948 if (token
->type
== CPP_PRAGMA_EOL
)
950 c_parser_consume_token (parser
);
953 c_parser_consume_token (parser
);
956 parser
->error
= false;
959 /* Skip tokens until we have consumed an entire block, or until we
960 have consumed a non-nested ';'. */
963 c_parser_skip_to_end_of_block_or_statement (c_parser
*parser
)
965 unsigned nesting_depth
= 0;
966 bool save_error
= parser
->error
;
972 /* Peek at the next token. */
973 token
= c_parser_peek_token (parser
);
981 if (parser
->in_pragma
)
986 /* If the next token is a ';', we have reached the
987 end of the statement. */
990 /* Consume the ';'. */
991 c_parser_consume_token (parser
);
996 case CPP_CLOSE_BRACE
:
997 /* If the next token is a non-nested '}', then we have
998 reached the end of the current block. */
999 if (nesting_depth
== 0 || --nesting_depth
== 0)
1001 c_parser_consume_token (parser
);
1006 case CPP_OPEN_BRACE
:
1007 /* If it the next token is a '{', then we are entering a new
1008 block. Consume the entire block. */
1013 /* If we see a pragma, consume the whole thing at once. We
1014 have some safeguards against consuming pragmas willy-nilly.
1015 Normally, we'd expect to be here with parser->error set,
1016 which disables these safeguards. But it's possible to get
1017 here for secondary error recovery, after parser->error has
1019 c_parser_consume_pragma (parser
);
1020 c_parser_skip_to_pragma_eol (parser
);
1021 parser
->error
= save_error
;
1028 c_parser_consume_token (parser
);
1032 parser
->error
= false;
1035 /* CPP's options (initialized by c-opts.c). */
1036 extern cpp_options
*cpp_opts
;
1038 /* Save the warning flags which are controlled by __extension__. */
1041 disable_extension_diagnostics (void)
1044 | (warn_pointer_arith
<< 1)
1045 | (warn_traditional
<< 2)
1047 | (warn_long_long
<< 4)
1048 | (warn_cxx_compat
<< 5));
1049 cpp_opts
->cpp_pedantic
= pedantic
= 0;
1050 warn_pointer_arith
= 0;
1051 cpp_opts
->cpp_warn_traditional
= warn_traditional
= 0;
1053 cpp_opts
->cpp_warn_long_long
= warn_long_long
= 0;
1054 warn_cxx_compat
= 0;
1058 /* Restore the warning flags which are controlled by __extension__.
1059 FLAGS is the return value from disable_extension_diagnostics. */
1062 restore_extension_diagnostics (int flags
)
1064 cpp_opts
->cpp_pedantic
= pedantic
= flags
& 1;
1065 warn_pointer_arith
= (flags
>> 1) & 1;
1066 cpp_opts
->cpp_warn_traditional
= warn_traditional
= (flags
>> 2) & 1;
1067 flag_iso
= (flags
>> 3) & 1;
1068 cpp_opts
->cpp_warn_long_long
= warn_long_long
= (flags
>> 4) & 1;
1069 warn_cxx_compat
= (flags
>> 5) & 1;
1072 /* Possibly kinds of declarator to parse. */
1073 typedef enum c_dtr_syn
{
1074 /* A normal declarator with an identifier. */
1076 /* An abstract declarator (maybe empty). */
1078 /* A parameter declarator: may be either, but after a type name does
1079 not redeclare a typedef name as an identifier if it can
1080 alternatively be interpreted as a typedef name; see DR#009,
1081 applied in C90 TC1, omitted from C99 and reapplied in C99 TC2
1082 following DR#249. For example, given a typedef T, "int T" and
1083 "int *T" are valid parameter declarations redeclaring T, while
1084 "int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are
1085 abstract declarators rather than involving redundant parentheses;
1086 the same applies with attributes inside the parentheses before
1091 static void c_parser_external_declaration (c_parser
*);
1092 static void c_parser_asm_definition (c_parser
*);
1093 static void c_parser_declaration_or_fndef (c_parser
*, bool, bool, bool,
1094 bool, bool, tree
*);
1095 static void c_parser_static_assert_declaration_no_semi (c_parser
*);
1096 static void c_parser_static_assert_declaration (c_parser
*);
1097 static void c_parser_declspecs (c_parser
*, struct c_declspecs
*, bool, bool,
1098 bool, enum c_lookahead_kind
);
1099 static struct c_typespec
c_parser_enum_specifier (c_parser
*);
1100 static struct c_typespec
c_parser_struct_or_union_specifier (c_parser
*);
1101 static tree
c_parser_struct_declaration (c_parser
*);
1102 static struct c_typespec
c_parser_typeof_specifier (c_parser
*);
1103 static struct c_declarator
*c_parser_declarator (c_parser
*, bool, c_dtr_syn
,
1105 static struct c_declarator
*c_parser_direct_declarator (c_parser
*, bool,
1107 static struct c_declarator
*c_parser_direct_declarator_inner (c_parser
*,
1109 struct c_declarator
*);
1110 static struct c_arg_info
*c_parser_parms_declarator (c_parser
*, bool, tree
);
1111 static struct c_arg_info
*c_parser_parms_list_declarator (c_parser
*, tree
);
1112 static struct c_parm
*c_parser_parameter_declaration (c_parser
*, tree
);
1113 static tree
c_parser_simple_asm_expr (c_parser
*);
1114 static tree
c_parser_attributes (c_parser
*);
1115 static struct c_type_name
*c_parser_type_name (c_parser
*);
1116 static struct c_expr
c_parser_initializer (c_parser
*);
1117 static struct c_expr
c_parser_braced_init (c_parser
*, tree
, bool);
1118 static void c_parser_initelt (c_parser
*, struct obstack
*);
1119 static void c_parser_initval (c_parser
*, struct c_expr
*,
1121 static tree
c_parser_compound_statement (c_parser
*);
1122 static void c_parser_compound_statement_nostart (c_parser
*);
1123 static void c_parser_label (c_parser
*);
1124 static void c_parser_statement (c_parser
*);
1125 static void c_parser_statement_after_labels (c_parser
*);
1126 static void c_parser_if_statement (c_parser
*);
1127 static void c_parser_switch_statement (c_parser
*);
1128 static void c_parser_while_statement (c_parser
*);
1129 static void c_parser_do_statement (c_parser
*);
1130 static void c_parser_for_statement (c_parser
*);
1131 static tree
c_parser_asm_statement (c_parser
*);
1132 static tree
c_parser_asm_operands (c_parser
*, bool);
1133 static tree
c_parser_asm_goto_operands (c_parser
*);
1134 static tree
c_parser_asm_clobbers (c_parser
*);
1135 static struct c_expr
c_parser_expr_no_commas (c_parser
*, struct c_expr
*);
1136 static struct c_expr
c_parser_conditional_expression (c_parser
*,
1138 static struct c_expr
c_parser_binary_expression (c_parser
*, struct c_expr
*);
1139 static struct c_expr
c_parser_cast_expression (c_parser
*, struct c_expr
*);
1140 static struct c_expr
c_parser_unary_expression (c_parser
*);
1141 static struct c_expr
c_parser_sizeof_expression (c_parser
*);
1142 static struct c_expr
c_parser_alignof_expression (c_parser
*);
1143 static struct c_expr
c_parser_postfix_expression (c_parser
*);
1144 static struct c_expr
c_parser_postfix_expression_after_paren_type (c_parser
*,
1145 struct c_type_name
*,
1147 static struct c_expr
c_parser_postfix_expression_after_primary (c_parser
*,
1150 static struct c_expr
c_parser_expression (c_parser
*);
1151 static struct c_expr
c_parser_expression_conv (c_parser
*);
1152 static VEC(tree
,gc
) *c_parser_expr_list (c_parser
*, bool, bool,
1154 static void c_parser_omp_construct (c_parser
*);
1155 static void c_parser_omp_threadprivate (c_parser
*);
1156 static void c_parser_omp_barrier (c_parser
*);
1157 static void c_parser_omp_flush (c_parser
*);
1158 static void c_parser_omp_taskwait (c_parser
*);
1160 enum pragma_context
{ pragma_external
, pragma_stmt
, pragma_compound
};
1161 static bool c_parser_pragma (c_parser
*, enum pragma_context
);
1163 /* These Objective-C parser functions are only ever called when
1164 compiling Objective-C. */
1165 static void c_parser_objc_class_definition (c_parser
*, tree
);
1166 static void c_parser_objc_class_instance_variables (c_parser
*);
1167 static void c_parser_objc_class_declaration (c_parser
*);
1168 static void c_parser_objc_alias_declaration (c_parser
*);
1169 static void c_parser_objc_protocol_definition (c_parser
*, tree
);
1170 static bool c_parser_objc_method_type (c_parser
*);
1171 static void c_parser_objc_method_definition (c_parser
*);
1172 static void c_parser_objc_methodprotolist (c_parser
*);
1173 static void c_parser_objc_methodproto (c_parser
*);
1174 static tree
c_parser_objc_method_decl (c_parser
*, bool, tree
*);
1175 static tree
c_parser_objc_type_name (c_parser
*);
1176 static tree
c_parser_objc_protocol_refs (c_parser
*);
1177 static void c_parser_objc_try_catch_finally_statement (c_parser
*);
1178 static void c_parser_objc_synchronized_statement (c_parser
*);
1179 static tree
c_parser_objc_selector (c_parser
*);
1180 static tree
c_parser_objc_selector_arg (c_parser
*);
1181 static tree
c_parser_objc_receiver (c_parser
*);
1182 static tree
c_parser_objc_message_args (c_parser
*);
1183 static tree
c_parser_objc_keywordexpr (c_parser
*);
1184 static void c_parser_objc_at_property_declaration (c_parser
*);
1185 static void c_parser_objc_at_synthesize_declaration (c_parser
*);
1186 static void c_parser_objc_at_dynamic_declaration (c_parser
*);
1187 static bool c_parser_objc_diagnose_bad_element_prefix
1188 (c_parser
*, struct c_declspecs
*);
1190 /* Parse a translation unit (C90 6.7, C99 6.9).
1193 external-declarations
1195 external-declarations:
1196 external-declaration
1197 external-declarations external-declaration
1206 c_parser_translation_unit (c_parser
*parser
)
1208 if (c_parser_next_token_is (parser
, CPP_EOF
))
1210 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
1211 "ISO C forbids an empty translation unit");
1215 void *obstack_position
= obstack_alloc (&parser_obstack
, 0);
1216 mark_valid_location_for_stdc_pragma (false);
1220 c_parser_external_declaration (parser
);
1221 obstack_free (&parser_obstack
, obstack_position
);
1223 while (c_parser_next_token_is_not (parser
, CPP_EOF
));
1227 /* Parse an external declaration (C90 6.7, C99 6.9).
1229 external-declaration:
1235 external-declaration:
1238 __extension__ external-declaration
1242 external-declaration:
1243 objc-class-definition
1244 objc-class-declaration
1245 objc-alias-declaration
1246 objc-protocol-definition
1247 objc-method-definition
1252 c_parser_external_declaration (c_parser
*parser
)
1255 switch (c_parser_peek_token (parser
)->type
)
1258 switch (c_parser_peek_token (parser
)->keyword
)
1261 ext
= disable_extension_diagnostics ();
1262 c_parser_consume_token (parser
);
1263 c_parser_external_declaration (parser
);
1264 restore_extension_diagnostics (ext
);
1267 c_parser_asm_definition (parser
);
1269 case RID_AT_INTERFACE
:
1270 case RID_AT_IMPLEMENTATION
:
1271 gcc_assert (c_dialect_objc ());
1272 c_parser_objc_class_definition (parser
, NULL_TREE
);
1275 gcc_assert (c_dialect_objc ());
1276 c_parser_objc_class_declaration (parser
);
1279 gcc_assert (c_dialect_objc ());
1280 c_parser_objc_alias_declaration (parser
);
1282 case RID_AT_PROTOCOL
:
1283 gcc_assert (c_dialect_objc ());
1284 c_parser_objc_protocol_definition (parser
, NULL_TREE
);
1286 case RID_AT_PROPERTY
:
1287 gcc_assert (c_dialect_objc ());
1288 c_parser_objc_at_property_declaration (parser
);
1290 case RID_AT_SYNTHESIZE
:
1291 gcc_assert (c_dialect_objc ());
1292 c_parser_objc_at_synthesize_declaration (parser
);
1294 case RID_AT_DYNAMIC
:
1295 gcc_assert (c_dialect_objc ());
1296 c_parser_objc_at_dynamic_declaration (parser
);
1299 gcc_assert (c_dialect_objc ());
1300 c_parser_consume_token (parser
);
1301 objc_finish_implementation ();
1308 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
1309 "ISO C does not allow extra %<;%> outside of a function");
1310 c_parser_consume_token (parser
);
1313 mark_valid_location_for_stdc_pragma (true);
1314 c_parser_pragma (parser
, pragma_external
);
1315 mark_valid_location_for_stdc_pragma (false);
1319 if (c_dialect_objc ())
1321 c_parser_objc_method_definition (parser
);
1324 /* Else fall through, and yield a syntax error trying to parse
1325 as a declaration or function definition. */
1328 /* A declaration or a function definition (or, in Objective-C,
1329 an @interface or @protocol with prefix attributes). We can
1330 only tell which after parsing the declaration specifiers, if
1331 any, and the first declarator. */
1332 c_parser_declaration_or_fndef (parser
, true, true, true, false, true, NULL
);
1337 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1338 6.7, 6.9.1). If FNDEF_OK is true, a function definition is
1339 accepted; otherwise (old-style parameter declarations) only other
1340 declarations are accepted. If STATIC_ASSERT_OK is true, a static
1341 assertion is accepted; otherwise (old-style parameter declarations)
1342 it is not. If NESTED is true, we are inside a function or parsing
1343 old-style parameter declarations; any functions encountered are
1344 nested functions and declaration specifiers are required; otherwise
1345 we are at top level and functions are normal functions and
1346 declaration specifiers may be optional. If EMPTY_OK is true, empty
1347 declarations are OK (subject to all other constraints); otherwise
1348 (old-style parameter declarations) they are diagnosed. If
1349 START_ATTR_OK is true, the declaration specifiers may start with
1350 attributes; otherwise they may not.
1351 OBJC_FOREACH_OBJECT_DECLARATION can be used to get back the parsed
1352 declaration when parsing an Objective-C foreach statement.
1355 declaration-specifiers init-declarator-list[opt] ;
1356 static_assert-declaration
1358 function-definition:
1359 declaration-specifiers[opt] declarator declaration-list[opt]
1364 declaration-list declaration
1366 init-declarator-list:
1368 init-declarator-list , init-declarator
1371 declarator simple-asm-expr[opt] attributes[opt]
1372 declarator simple-asm-expr[opt] attributes[opt] = initializer
1376 nested-function-definition:
1377 declaration-specifiers declarator declaration-list[opt]
1381 attributes objc-class-definition
1382 attributes objc-category-definition
1383 attributes objc-protocol-definition
1385 The simple-asm-expr and attributes are GNU extensions.
1387 This function does not handle __extension__; that is handled in its
1388 callers. ??? Following the old parser, __extension__ may start
1389 external declarations, declarations in functions and declarations
1390 at the start of "for" loops, but not old-style parameter
1393 C99 requires declaration specifiers in a function definition; the
1394 absence is diagnosed through the diagnosis of implicit int. In GNU
1395 C we also allow but diagnose declarations without declaration
1396 specifiers, but only at top level (elsewhere they conflict with
1399 In Objective-C, declarations of the looping variable in a foreach
1400 statement are exceptionally terminated by 'in' (for example, 'for
1401 (NSObject *object in array) { ... }').
1406 threadprivate-directive */
1409 c_parser_declaration_or_fndef (c_parser
*parser
, bool fndef_ok
,
1410 bool static_assert_ok
, bool empty_ok
,
1411 bool nested
, bool start_attr_ok
,
1412 tree
*objc_foreach_object_declaration
)
1414 struct c_declspecs
*specs
;
1416 tree all_prefix_attrs
;
1417 bool diagnosed_no_specs
= false;
1418 location_t here
= c_parser_peek_token (parser
)->location
;
1420 if (static_assert_ok
1421 && c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
1423 c_parser_static_assert_declaration (parser
);
1426 specs
= build_null_declspecs ();
1428 /* Try to detect an unknown type name when we have "A B" or "A *B". */
1429 if (c_parser_peek_token (parser
)->type
== CPP_NAME
1430 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
1431 && (c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
1432 || c_parser_peek_2nd_token (parser
)->type
== CPP_MULT
)
1433 && (!nested
|| !lookup_name (c_parser_peek_token (parser
)->value
)))
1435 error_at (here
, "unknown type name %qE",
1436 c_parser_peek_token (parser
)->value
);
1438 /* Parse declspecs normally to get a correct pointer type, but avoid
1439 a further "fails to be a type name" error. Refuse nested functions
1440 since it is not how the user likely wants us to recover. */
1441 c_parser_peek_token (parser
)->type
= CPP_KEYWORD
;
1442 c_parser_peek_token (parser
)->keyword
= RID_VOID
;
1443 c_parser_peek_token (parser
)->value
= error_mark_node
;
1447 c_parser_declspecs (parser
, specs
, true, true, start_attr_ok
, cla_nonabstract_decl
);
1450 c_parser_skip_to_end_of_block_or_statement (parser
);
1453 if (nested
&& !specs
->declspecs_seen_p
)
1455 c_parser_error (parser
, "expected declaration specifiers");
1456 c_parser_skip_to_end_of_block_or_statement (parser
);
1459 finish_declspecs (specs
);
1460 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1466 shadow_tag_warned (specs
, 1);
1467 pedwarn (here
, 0, "empty declaration");
1469 c_parser_consume_token (parser
);
1473 /* Provide better error recovery. Note that a type name here is usually
1474 better diagnosed as a redeclaration. */
1476 && specs
->typespec_kind
== ctsk_tagdef
1477 && c_parser_next_token_starts_declspecs (parser
)
1478 && !c_parser_next_token_is (parser
, CPP_NAME
))
1480 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
1481 parser
->error
= false;
1482 shadow_tag_warned (specs
, 1);
1485 else if (c_dialect_objc ())
1487 /* Prefix attributes are an error on method decls. */
1488 switch (c_parser_peek_token (parser
)->type
)
1492 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1496 warning_at (c_parser_peek_token (parser
)->location
,
1498 "prefix attributes are ignored for methods");
1499 specs
->attrs
= NULL_TREE
;
1502 c_parser_objc_method_definition (parser
);
1504 c_parser_objc_methodproto (parser
);
1510 /* This is where we parse 'attributes @interface ...',
1511 'attributes @implementation ...', 'attributes @protocol ...'
1512 (where attributes could be, for example, __attribute__
1515 switch (c_parser_peek_token (parser
)->keyword
)
1517 case RID_AT_INTERFACE
:
1519 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1521 c_parser_objc_class_definition (parser
, specs
->attrs
);
1525 case RID_AT_IMPLEMENTATION
:
1527 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1531 warning_at (c_parser_peek_token (parser
)->location
,
1533 "prefix attributes are ignored for implementations");
1534 specs
->attrs
= NULL_TREE
;
1536 c_parser_objc_class_definition (parser
, NULL_TREE
);
1540 case RID_AT_PROTOCOL
:
1542 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1544 c_parser_objc_protocol_definition (parser
, specs
->attrs
);
1551 case RID_AT_PROPERTY
:
1554 c_parser_error (parser
, "unexpected attribute");
1555 specs
->attrs
= NULL
;
1563 pending_xref_error ();
1564 prefix_attrs
= specs
->attrs
;
1565 all_prefix_attrs
= prefix_attrs
;
1566 specs
->attrs
= NULL_TREE
;
1569 struct c_declarator
*declarator
;
1572 /* Declaring either one or more declarators (in which case we
1573 should diagnose if there were no declaration specifiers) or a
1574 function definition (in which case the diagnostic for
1575 implicit int suffices). */
1576 declarator
= c_parser_declarator (parser
,
1577 specs
->typespec_kind
!= ctsk_none
,
1578 C_DTR_NORMAL
, &dummy
);
1579 if (declarator
== NULL
)
1581 c_parser_skip_to_end_of_block_or_statement (parser
);
1584 if (c_parser_next_token_is (parser
, CPP_EQ
)
1585 || c_parser_next_token_is (parser
, CPP_COMMA
)
1586 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
1587 || c_parser_next_token_is_keyword (parser
, RID_ASM
)
1588 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
)
1589 || c_parser_next_token_is_keyword (parser
, RID_IN
))
1591 tree asm_name
= NULL_TREE
;
1592 tree postfix_attrs
= NULL_TREE
;
1593 if (!diagnosed_no_specs
&& !specs
->declspecs_seen_p
)
1595 diagnosed_no_specs
= true;
1596 pedwarn (here
, 0, "data definition has no type or storage class");
1598 /* Having seen a data definition, there cannot now be a
1599 function definition. */
1601 if (c_parser_next_token_is_keyword (parser
, RID_ASM
))
1602 asm_name
= c_parser_simple_asm_expr (parser
);
1603 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1604 postfix_attrs
= c_parser_attributes (parser
);
1605 if (c_parser_next_token_is (parser
, CPP_EQ
))
1609 location_t init_loc
;
1610 c_parser_consume_token (parser
);
1611 /* The declaration of the variable is in effect while
1612 its initializer is parsed. */
1613 d
= start_decl (declarator
, specs
, true,
1614 chainon (postfix_attrs
, all_prefix_attrs
));
1616 d
= error_mark_node
;
1617 start_init (d
, asm_name
, global_bindings_p ());
1618 init_loc
= c_parser_peek_token (parser
)->location
;
1619 init
= c_parser_initializer (parser
);
1621 if (d
!= error_mark_node
)
1623 maybe_warn_string_init (TREE_TYPE (d
), init
);
1624 finish_decl (d
, init_loc
, init
.value
,
1625 init
.original_type
, asm_name
);
1630 tree d
= start_decl (declarator
, specs
, false,
1631 chainon (postfix_attrs
,
1634 finish_decl (d
, UNKNOWN_LOCATION
, NULL_TREE
,
1635 NULL_TREE
, asm_name
);
1637 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
1640 *objc_foreach_object_declaration
= d
;
1642 *objc_foreach_object_declaration
= error_mark_node
;
1645 if (c_parser_next_token_is (parser
, CPP_COMMA
))
1647 c_parser_consume_token (parser
);
1648 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1649 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
1652 all_prefix_attrs
= prefix_attrs
;
1655 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1657 c_parser_consume_token (parser
);
1660 else if (c_parser_next_token_is_keyword (parser
, RID_IN
))
1662 /* This can only happen in Objective-C: we found the
1663 'in' that terminates the declaration inside an
1664 Objective-C foreach statement. Do not consume the
1665 token, so that the caller can use it to determine
1666 that this indeed is a foreach context. */
1671 c_parser_error (parser
, "expected %<,%> or %<;%>");
1672 c_parser_skip_to_end_of_block_or_statement (parser
);
1678 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, "
1679 "%<asm%> or %<__attribute__%>");
1680 c_parser_skip_to_end_of_block_or_statement (parser
);
1683 /* Function definition (nested or otherwise). */
1686 pedwarn (here
, OPT_pedantic
, "ISO C forbids nested functions");
1687 c_push_function_context ();
1689 if (!start_function (specs
, declarator
, all_prefix_attrs
))
1691 /* This can appear in many cases looking nothing like a
1692 function definition, so we don't give a more specific
1693 error suggesting there was one. */
1694 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
1695 "or %<__attribute__%>");
1697 c_pop_function_context ();
1700 /* Parse old-style parameter declarations. ??? Attributes are
1701 not allowed to start declaration specifiers here because of a
1702 syntax conflict between a function declaration with attribute
1703 suffix and a function definition with an attribute prefix on
1704 first old-style parameter declaration. Following the old
1705 parser, they are not accepted on subsequent old-style
1706 parameter declarations either. However, there is no
1707 ambiguity after the first declaration, nor indeed on the
1708 first as long as we don't allow postfix attributes after a
1709 declarator with a nonempty identifier list in a definition;
1710 and postfix attributes have never been accepted here in
1711 function definitions either. */
1712 while (c_parser_next_token_is_not (parser
, CPP_EOF
)
1713 && c_parser_next_token_is_not (parser
, CPP_OPEN_BRACE
))
1714 c_parser_declaration_or_fndef (parser
, false, false, false,
1716 store_parm_decls ();
1717 DECL_STRUCT_FUNCTION (current_function_decl
)->function_start_locus
1718 = c_parser_peek_token (parser
)->location
;
1719 fnbody
= c_parser_compound_statement (parser
);
1722 tree decl
= current_function_decl
;
1723 /* Mark nested functions as needing static-chain initially.
1724 lower_nested_functions will recompute it but the
1725 DECL_STATIC_CHAIN flag is also used before that happens,
1726 by initializer_constant_valid_p. See gcc.dg/nested-fn-2.c. */
1727 DECL_STATIC_CHAIN (decl
) = 1;
1730 c_pop_function_context ();
1731 add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl
), DECL_EXPR
, decl
));
1742 /* Parse an asm-definition (asm() outside a function body). This is a
1750 c_parser_asm_definition (c_parser
*parser
)
1752 tree asm_str
= c_parser_simple_asm_expr (parser
);
1754 cgraph_add_asm_node (asm_str
);
1755 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
1758 /* Parse a static assertion (C1X N1425 6.7.10).
1760 static_assert-declaration:
1761 static_assert-declaration-no-semi ;
1765 c_parser_static_assert_declaration (c_parser
*parser
)
1767 c_parser_static_assert_declaration_no_semi (parser
);
1769 || !c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
1770 c_parser_skip_to_end_of_block_or_statement (parser
);
1773 /* Parse a static assertion (C1X N1425 6.7.10), without the trailing
1776 static_assert-declaration-no-semi:
1777 _Static_assert ( constant-expression , string-literal )
1781 c_parser_static_assert_declaration_no_semi (c_parser
*parser
)
1783 location_t assert_loc
, value_loc
;
1787 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
));
1788 assert_loc
= c_parser_peek_token (parser
)->location
;
1792 pedwarn (assert_loc
, OPT_pedantic
,
1793 "ISO C99 does not support %<_Static_assert%>");
1795 pedwarn (assert_loc
, OPT_pedantic
,
1796 "ISO C90 does not support %<_Static_assert%>");
1798 c_parser_consume_token (parser
);
1799 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
1801 value_loc
= c_parser_peek_token (parser
)->location
;
1802 value
= c_parser_expr_no_commas (parser
, NULL
).value
;
1803 parser
->lex_untranslated_string
= true;
1804 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
1806 parser
->lex_untranslated_string
= false;
1809 switch (c_parser_peek_token (parser
)->type
)
1815 case CPP_UTF8STRING
:
1816 string
= c_parser_peek_token (parser
)->value
;
1817 c_parser_consume_token (parser
);
1818 parser
->lex_untranslated_string
= false;
1821 c_parser_error (parser
, "expected string literal");
1822 parser
->lex_untranslated_string
= false;
1825 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
1827 if (!INTEGRAL_TYPE_P (TREE_TYPE (value
)))
1829 error_at (value_loc
, "expression in static assertion is not an integer");
1832 if (TREE_CODE (value
) != INTEGER_CST
)
1834 value
= c_fully_fold (value
, false, NULL
);
1835 if (TREE_CODE (value
) == INTEGER_CST
)
1836 pedwarn (value_loc
, OPT_pedantic
, "expression in static assertion "
1837 "is not an integer constant expression");
1839 if (TREE_CODE (value
) != INTEGER_CST
)
1841 error_at (value_loc
, "expression in static assertion is not constant");
1844 constant_expression_warning (value
);
1845 if (integer_zerop (value
))
1846 error_at (assert_loc
, "static assertion failed: %E", string
);
1849 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
1850 6.7), adding them to SPECS (which may already include some).
1851 Storage class specifiers are accepted iff SCSPEC_OK; type
1852 specifiers are accepted iff TYPESPEC_OK; attributes are accepted at
1853 the start iff START_ATTR_OK.
1855 declaration-specifiers:
1856 storage-class-specifier declaration-specifiers[opt]
1857 type-specifier declaration-specifiers[opt]
1858 type-qualifier declaration-specifiers[opt]
1859 function-specifier declaration-specifiers[opt]
1861 Function specifiers (inline) are from C99, and are currently
1862 handled as storage class specifiers, as is __thread.
1864 C90 6.5.1, C99 6.7.1:
1865 storage-class-specifier:
1876 C90 6.5.2, C99 6.7.2:
1889 [_Imaginary removed in C99 TC2]
1890 struct-or-union-specifier
1894 (_Bool and _Complex are new in C99.)
1896 C90 6.5.3, C99 6.7.3:
1902 address-space-qualifier
1904 (restrict is new in C99.)
1908 declaration-specifiers:
1909 attributes declaration-specifiers[opt]
1915 identifier recognized by the target
1917 storage-class-specifier:
1930 (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
1931 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
1936 class-name objc-protocol-refs[opt]
1937 typedef-name objc-protocol-refs
1942 c_parser_declspecs (c_parser
*parser
, struct c_declspecs
*specs
,
1943 bool scspec_ok
, bool typespec_ok
, bool start_attr_ok
,
1944 enum c_lookahead_kind la
)
1946 bool attrs_ok
= start_attr_ok
;
1947 bool seen_type
= specs
->typespec_kind
!= ctsk_none
;
1950 gcc_assert (la
== cla_prefer_id
);
1952 while (c_parser_next_token_is (parser
, CPP_NAME
)
1953 || c_parser_next_token_is (parser
, CPP_KEYWORD
)
1954 || (c_dialect_objc () && c_parser_next_token_is (parser
, CPP_LESS
)))
1956 struct c_typespec t
;
1958 location_t loc
= c_parser_peek_token (parser
)->location
;
1960 /* If we cannot accept a type, exit if the next token must start
1961 one. Also, if we already have seen a tagged definition,
1962 a typename would be an error anyway and likely the user
1963 has simply forgotten a semicolon, so we exit. */
1964 if ((!typespec_ok
|| specs
->typespec_kind
== ctsk_tagdef
)
1965 && c_parser_next_tokens_start_typename (parser
, la
)
1966 && !c_parser_next_token_is_qualifier (parser
))
1969 if (c_parser_next_token_is (parser
, CPP_NAME
))
1971 tree value
= c_parser_peek_token (parser
)->value
;
1972 c_id_kind kind
= c_parser_peek_token (parser
)->id_kind
;
1974 if (kind
== C_ID_ADDRSPACE
)
1977 = c_parser_peek_token (parser
)->keyword
- RID_FIRST_ADDR_SPACE
;
1978 declspecs_add_addrspace (specs
, as
);
1979 c_parser_consume_token (parser
);
1984 gcc_assert (!c_parser_next_token_is_qualifier (parser
));
1986 /* If we cannot accept a type, and the next token must start one,
1987 exit. Do the same if we already have seen a tagged definition,
1988 since it would be an error anyway and likely the user has simply
1989 forgotten a semicolon. */
1990 if (seen_type
|| !c_parser_next_tokens_start_typename (parser
, la
))
1993 /* Now at an unknown typename (C_ID_ID), a C_ID_TYPENAME or
1994 a C_ID_CLASSNAME. */
1995 c_parser_consume_token (parser
);
1998 if (kind
== C_ID_ID
)
2000 error ("unknown type name %qE", value
);
2001 t
.kind
= ctsk_typedef
;
2002 t
.spec
= error_mark_node
;
2004 else if (kind
== C_ID_TYPENAME
2005 && (!c_dialect_objc ()
2006 || c_parser_next_token_is_not (parser
, CPP_LESS
)))
2008 t
.kind
= ctsk_typedef
;
2009 /* For a typedef name, record the meaning, not the name.
2010 In case of 'foo foo, bar;'. */
2011 t
.spec
= lookup_name (value
);
2015 tree proto
= NULL_TREE
;
2016 gcc_assert (c_dialect_objc ());
2018 if (c_parser_next_token_is (parser
, CPP_LESS
))
2019 proto
= c_parser_objc_protocol_refs (parser
);
2020 t
.spec
= objc_get_protocol_qualified_type (value
, proto
);
2023 t
.expr_const_operands
= true;
2024 declspecs_add_type (loc
, specs
, t
);
2027 if (c_parser_next_token_is (parser
, CPP_LESS
))
2029 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
2030 nisse@lysator.liu.se. */
2032 gcc_assert (c_dialect_objc ());
2033 if (!typespec_ok
|| seen_type
)
2035 proto
= c_parser_objc_protocol_refs (parser
);
2037 t
.spec
= objc_get_protocol_qualified_type (NULL_TREE
, proto
);
2039 t
.expr_const_operands
= true;
2040 declspecs_add_type (loc
, specs
, t
);
2043 gcc_assert (c_parser_next_token_is (parser
, CPP_KEYWORD
));
2044 switch (c_parser_peek_token (parser
)->keyword
)
2056 /* TODO: Distinguish between function specifiers (inline)
2057 and storage class specifiers, either here or in
2058 declspecs_add_scspec. */
2059 declspecs_add_scspec (specs
, c_parser_peek_token (parser
)->value
);
2060 c_parser_consume_token (parser
);
2084 if (c_dialect_objc ())
2085 parser
->objc_need_raw_identifier
= true;
2086 t
.kind
= ctsk_resword
;
2087 t
.spec
= c_parser_peek_token (parser
)->value
;
2089 t
.expr_const_operands
= true;
2090 declspecs_add_type (loc
, specs
, t
);
2091 c_parser_consume_token (parser
);
2098 t
= c_parser_enum_specifier (parser
);
2099 declspecs_add_type (loc
, specs
, t
);
2107 t
= c_parser_struct_or_union_specifier (parser
);
2108 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE
, t
.spec
);
2109 declspecs_add_type (loc
, specs
, t
);
2112 /* ??? The old parser rejected typeof after other type
2113 specifiers, but is a syntax error the best way of
2115 if (!typespec_ok
|| seen_type
)
2119 t
= c_parser_typeof_specifier (parser
);
2120 declspecs_add_type (loc
, specs
, t
);
2126 declspecs_add_qual (specs
, c_parser_peek_token (parser
)->value
);
2127 c_parser_consume_token (parser
);
2132 attrs
= c_parser_attributes (parser
);
2133 declspecs_add_attrs (specs
, attrs
);
2142 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
2145 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
2146 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
2147 enum attributes[opt] identifier
2149 The form with trailing comma is new in C99. The forms with
2150 attributes are GNU extensions. In GNU C, we accept any expression
2151 without commas in the syntax (assignment expressions, not just
2152 conditional expressions); assignment expressions will be diagnosed
2157 enumerator-list , enumerator
2160 enumeration-constant
2161 enumeration-constant = constant-expression
2164 static struct c_typespec
2165 c_parser_enum_specifier (c_parser
*parser
)
2167 struct c_typespec ret
;
2169 tree ident
= NULL_TREE
;
2170 location_t enum_loc
;
2171 location_t ident_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2172 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ENUM
));
2173 enum_loc
= c_parser_peek_token (parser
)->location
;
2174 c_parser_consume_token (parser
);
2175 attrs
= c_parser_attributes (parser
);
2176 enum_loc
= c_parser_peek_token (parser
)->location
;
2177 /* Set the location in case we create a decl now. */
2178 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2179 if (c_parser_next_token_is (parser
, CPP_NAME
))
2181 ident
= c_parser_peek_token (parser
)->value
;
2182 ident_loc
= c_parser_peek_token (parser
)->location
;
2183 enum_loc
= ident_loc
;
2184 c_parser_consume_token (parser
);
2186 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2188 /* Parse an enum definition. */
2189 struct c_enum_contents the_enum
;
2190 tree type
= start_enum (enum_loc
, &the_enum
, ident
);
2192 /* We chain the enumerators in reverse order, then put them in
2193 forward order at the end. */
2194 tree values
= NULL_TREE
;
2195 c_parser_consume_token (parser
);
2203 location_t comma_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2204 location_t decl_loc
, value_loc
;
2205 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
2207 c_parser_error (parser
, "expected identifier");
2208 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2209 values
= error_mark_node
;
2212 token
= c_parser_peek_token (parser
);
2213 enum_id
= token
->value
;
2214 /* Set the location in case we create a decl now. */
2215 c_parser_set_source_position_from_token (token
);
2216 decl_loc
= value_loc
= token
->location
;
2217 c_parser_consume_token (parser
);
2218 if (c_parser_next_token_is (parser
, CPP_EQ
))
2220 c_parser_consume_token (parser
);
2221 value_loc
= c_parser_peek_token (parser
)->location
;
2222 enum_value
= c_parser_expr_no_commas (parser
, NULL
).value
;
2225 enum_value
= NULL_TREE
;
2226 enum_decl
= build_enumerator (decl_loc
, value_loc
,
2227 &the_enum
, enum_id
, enum_value
);
2228 TREE_CHAIN (enum_decl
) = values
;
2231 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2233 comma_loc
= c_parser_peek_token (parser
)->location
;
2235 c_parser_consume_token (parser
);
2237 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2239 if (seen_comma
&& !flag_isoc99
)
2240 pedwarn (comma_loc
, OPT_pedantic
, "comma at end of enumerator list");
2241 c_parser_consume_token (parser
);
2246 c_parser_error (parser
, "expected %<,%> or %<}%>");
2247 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2248 values
= error_mark_node
;
2252 postfix_attrs
= c_parser_attributes (parser
);
2253 ret
.spec
= finish_enum (type
, nreverse (values
),
2254 chainon (attrs
, postfix_attrs
));
2255 ret
.kind
= ctsk_tagdef
;
2256 ret
.expr
= NULL_TREE
;
2257 ret
.expr_const_operands
= true;
2262 c_parser_error (parser
, "expected %<{%>");
2263 ret
.spec
= error_mark_node
;
2264 ret
.kind
= ctsk_tagref
;
2265 ret
.expr
= NULL_TREE
;
2266 ret
.expr_const_operands
= true;
2269 ret
= parser_xref_tag (ident_loc
, ENUMERAL_TYPE
, ident
);
2270 /* In ISO C, enumerated types can be referred to only if already
2272 if (pedantic
&& !COMPLETE_TYPE_P (ret
.spec
))
2275 pedwarn (enum_loc
, OPT_pedantic
,
2276 "ISO C forbids forward references to %<enum%> types");
2281 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
2283 struct-or-union-specifier:
2284 struct-or-union attributes[opt] identifier[opt]
2285 { struct-contents } attributes[opt]
2286 struct-or-union attributes[opt] identifier
2289 struct-declaration-list
2291 struct-declaration-list:
2292 struct-declaration ;
2293 struct-declaration-list struct-declaration ;
2300 struct-declaration-list struct-declaration
2302 struct-declaration-list:
2303 struct-declaration-list ;
2306 (Note that in the syntax here, unlike that in ISO C, the semicolons
2307 are included here rather than in struct-declaration, in order to
2308 describe the syntax with extra semicolons and missing semicolon at
2313 struct-declaration-list:
2314 @defs ( class-name )
2316 (Note this does not include a trailing semicolon, but can be
2317 followed by further declarations, and gets a pedwarn-if-pedantic
2318 when followed by a semicolon.) */
2320 static struct c_typespec
2321 c_parser_struct_or_union_specifier (c_parser
*parser
)
2323 struct c_typespec ret
;
2325 tree ident
= NULL_TREE
;
2326 location_t struct_loc
;
2327 location_t ident_loc
= UNKNOWN_LOCATION
;
2328 enum tree_code code
;
2329 switch (c_parser_peek_token (parser
)->keyword
)
2340 struct_loc
= c_parser_peek_token (parser
)->location
;
2341 c_parser_consume_token (parser
);
2342 attrs
= c_parser_attributes (parser
);
2344 /* Set the location in case we create a decl now. */
2345 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2347 if (c_parser_next_token_is (parser
, CPP_NAME
))
2349 ident
= c_parser_peek_token (parser
)->value
;
2350 ident_loc
= c_parser_peek_token (parser
)->location
;
2351 struct_loc
= ident_loc
;
2352 c_parser_consume_token (parser
);
2354 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2356 /* Parse a struct or union definition. Start the scope of the
2357 tag before parsing components. */
2358 struct c_struct_parse_info
*struct_info
;
2359 tree type
= start_struct (struct_loc
, code
, ident
, &struct_info
);
2361 /* We chain the components in reverse order, then put them in
2362 forward order at the end. Each struct-declaration may
2363 declare multiple components (comma-separated), so we must use
2364 chainon to join them, although when parsing each
2365 struct-declaration we can use TREE_CHAIN directly.
2367 The theory behind all this is that there will be more
2368 semicolon separated fields than comma separated fields, and
2369 so we'll be minimizing the number of node traversals required
2371 tree contents
= NULL_TREE
;
2372 c_parser_consume_token (parser
);
2373 /* Handle the Objective-C @defs construct,
2374 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
2375 if (c_parser_next_token_is_keyword (parser
, RID_AT_DEFS
))
2378 gcc_assert (c_dialect_objc ());
2379 c_parser_consume_token (parser
);
2380 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2382 if (c_parser_next_token_is (parser
, CPP_NAME
)
2383 && c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
)
2385 name
= c_parser_peek_token (parser
)->value
;
2386 c_parser_consume_token (parser
);
2390 c_parser_error (parser
, "expected class name");
2391 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2394 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2396 contents
= nreverse (objc_get_class_ivars (name
));
2399 /* Parse the struct-declarations and semicolons. Problems with
2400 semicolons are diagnosed here; empty structures are diagnosed
2405 /* Parse any stray semicolon. */
2406 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2408 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
2409 "extra semicolon in struct or union specified");
2410 c_parser_consume_token (parser
);
2413 /* Stop if at the end of the struct or union contents. */
2414 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2416 c_parser_consume_token (parser
);
2419 /* Accept #pragmas at struct scope. */
2420 if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
2422 c_parser_pragma (parser
, pragma_external
);
2425 /* Parse some comma-separated declarations, but not the
2426 trailing semicolon if any. */
2427 decls
= c_parser_struct_declaration (parser
);
2428 contents
= chainon (decls
, contents
);
2429 /* If no semicolon follows, either we have a parse error or
2430 are at the end of the struct or union and should
2432 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2433 c_parser_consume_token (parser
);
2436 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2437 pedwarn (c_parser_peek_token (parser
)->location
, 0,
2438 "no semicolon at end of struct or union");
2439 else if (parser
->error
2440 || !c_parser_next_token_starts_declspecs (parser
))
2442 c_parser_error (parser
, "expected %<;%>");
2443 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2447 /* If we come here, we have already emitted an error
2448 for an expected `;', identifier or `(', and we also
2449 recovered already. Go on with the next field. */
2452 postfix_attrs
= c_parser_attributes (parser
);
2453 ret
.spec
= finish_struct (struct_loc
, type
, nreverse (contents
),
2454 chainon (attrs
, postfix_attrs
), struct_info
);
2455 ret
.kind
= ctsk_tagdef
;
2456 ret
.expr
= NULL_TREE
;
2457 ret
.expr_const_operands
= true;
2462 c_parser_error (parser
, "expected %<{%>");
2463 ret
.spec
= error_mark_node
;
2464 ret
.kind
= ctsk_tagref
;
2465 ret
.expr
= NULL_TREE
;
2466 ret
.expr_const_operands
= true;
2469 ret
= parser_xref_tag (ident_loc
, code
, ident
);
2473 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
2474 the trailing semicolon.
2477 specifier-qualifier-list struct-declarator-list
2478 static_assert-declaration-no-semi
2480 specifier-qualifier-list:
2481 type-specifier specifier-qualifier-list[opt]
2482 type-qualifier specifier-qualifier-list[opt]
2483 attributes specifier-qualifier-list[opt]
2485 struct-declarator-list:
2487 struct-declarator-list , attributes[opt] struct-declarator
2490 declarator attributes[opt]
2491 declarator[opt] : constant-expression attributes[opt]
2496 __extension__ struct-declaration
2497 specifier-qualifier-list
2499 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
2500 of attributes where shown is a GNU extension. In GNU C, we accept
2501 any expression without commas in the syntax (assignment
2502 expressions, not just conditional expressions); assignment
2503 expressions will be diagnosed as non-constant. */
2506 c_parser_struct_declaration (c_parser
*parser
)
2508 struct c_declspecs
*specs
;
2510 tree all_prefix_attrs
;
2512 location_t decl_loc
;
2513 if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
2517 ext
= disable_extension_diagnostics ();
2518 c_parser_consume_token (parser
);
2519 decl
= c_parser_struct_declaration (parser
);
2520 restore_extension_diagnostics (ext
);
2523 if (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
2525 c_parser_static_assert_declaration_no_semi (parser
);
2528 specs
= build_null_declspecs ();
2529 decl_loc
= c_parser_peek_token (parser
)->location
;
2530 c_parser_declspecs (parser
, specs
, false, true, true, cla_nonabstract_decl
);
2533 if (!specs
->declspecs_seen_p
)
2535 c_parser_error (parser
, "expected specifier-qualifier-list");
2538 finish_declspecs (specs
);
2539 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2540 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2543 if (specs
->typespec_kind
== ctsk_none
)
2545 pedwarn (decl_loc
, OPT_pedantic
,
2546 "ISO C forbids member declarations with no members");
2547 shadow_tag_warned (specs
, pedantic
);
2552 /* Support for unnamed structs or unions as members of
2553 structs or unions (which is [a] useful and [b] supports
2557 ret
= grokfield (c_parser_peek_token (parser
)->location
,
2558 build_id_declarator (NULL_TREE
), specs
,
2561 decl_attributes (&ret
, attrs
, 0);
2566 /* Provide better error recovery. Note that a type name here is valid,
2567 and will be treated as a field name. */
2568 if (specs
->typespec_kind
== ctsk_tagdef
2569 && TREE_CODE (specs
->type
) != ENUMERAL_TYPE
2570 && c_parser_next_token_starts_declspecs (parser
)
2571 && !c_parser_next_token_is (parser
, CPP_NAME
))
2573 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
2574 parser
->error
= false;
2578 pending_xref_error ();
2579 prefix_attrs
= specs
->attrs
;
2580 all_prefix_attrs
= prefix_attrs
;
2581 specs
->attrs
= NULL_TREE
;
2585 /* Declaring one or more declarators or un-named bit-fields. */
2586 struct c_declarator
*declarator
;
2588 if (c_parser_next_token_is (parser
, CPP_COLON
))
2589 declarator
= build_id_declarator (NULL_TREE
);
2591 declarator
= c_parser_declarator (parser
,
2592 specs
->typespec_kind
!= ctsk_none
,
2593 C_DTR_NORMAL
, &dummy
);
2594 if (declarator
== NULL
)
2596 c_parser_skip_to_end_of_block_or_statement (parser
);
2599 if (c_parser_next_token_is (parser
, CPP_COLON
)
2600 || c_parser_next_token_is (parser
, CPP_COMMA
)
2601 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2602 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
)
2603 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2605 tree postfix_attrs
= NULL_TREE
;
2606 tree width
= NULL_TREE
;
2608 if (c_parser_next_token_is (parser
, CPP_COLON
))
2610 c_parser_consume_token (parser
);
2611 width
= c_parser_expr_no_commas (parser
, NULL
).value
;
2613 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2614 postfix_attrs
= c_parser_attributes (parser
);
2615 d
= grokfield (c_parser_peek_token (parser
)->location
,
2616 declarator
, specs
, width
, &all_prefix_attrs
);
2617 decl_attributes (&d
, chainon (postfix_attrs
,
2618 all_prefix_attrs
), 0);
2619 DECL_CHAIN (d
) = decls
;
2621 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2622 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
2625 all_prefix_attrs
= prefix_attrs
;
2626 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2627 c_parser_consume_token (parser
);
2628 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2629 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2631 /* Semicolon consumed in caller. */
2636 c_parser_error (parser
, "expected %<,%>, %<;%> or %<}%>");
2642 c_parser_error (parser
,
2643 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
2644 "%<__attribute__%>");
2651 /* Parse a typeof specifier (a GNU extension).
2654 typeof ( expression )
2655 typeof ( type-name )
2658 static struct c_typespec
2659 c_parser_typeof_specifier (c_parser
*parser
)
2661 struct c_typespec ret
;
2662 ret
.kind
= ctsk_typeof
;
2663 ret
.spec
= error_mark_node
;
2664 ret
.expr
= NULL_TREE
;
2665 ret
.expr_const_operands
= true;
2666 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TYPEOF
));
2667 c_parser_consume_token (parser
);
2668 c_inhibit_evaluation_warnings
++;
2670 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2672 c_inhibit_evaluation_warnings
--;
2676 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
2678 struct c_type_name
*type
= c_parser_type_name (parser
);
2679 c_inhibit_evaluation_warnings
--;
2683 ret
.spec
= groktypename (type
, &ret
.expr
, &ret
.expr_const_operands
);
2684 pop_maybe_used (variably_modified_type_p (ret
.spec
, NULL_TREE
));
2690 location_t here
= c_parser_peek_token (parser
)->location
;
2691 struct c_expr expr
= c_parser_expression (parser
);
2692 c_inhibit_evaluation_warnings
--;
2694 if (TREE_CODE (expr
.value
) == COMPONENT_REF
2695 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
2696 error_at (here
, "%<typeof%> applied to a bit-field");
2697 mark_exp_read (expr
.value
);
2698 ret
.spec
= TREE_TYPE (expr
.value
);
2699 was_vm
= variably_modified_type_p (ret
.spec
, NULL_TREE
);
2700 /* This is returned with the type so that when the type is
2701 evaluated, this can be evaluated. */
2703 ret
.expr
= c_fully_fold (expr
.value
, false, &ret
.expr_const_operands
);
2704 pop_maybe_used (was_vm
);
2706 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
2710 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
2711 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
2712 be redeclared; otherwise it may not. KIND indicates which kind of
2713 declarator is wanted. Returns a valid declarator except in the
2714 case of a syntax error in which case NULL is returned. *SEEN_ID is
2715 set to true if an identifier being declared is seen; this is used
2716 to diagnose bad forms of abstract array declarators and to
2717 determine whether an identifier list is syntactically permitted.
2720 pointer[opt] direct-declarator
2724 ( attributes[opt] declarator )
2725 direct-declarator array-declarator
2726 direct-declarator ( parameter-type-list )
2727 direct-declarator ( identifier-list[opt] )
2730 * type-qualifier-list[opt]
2731 * type-qualifier-list[opt] pointer
2733 type-qualifier-list:
2736 type-qualifier-list type-qualifier
2737 type-qualifier-list attributes
2739 parameter-type-list:
2741 parameter-list , ...
2744 parameter-declaration
2745 parameter-list , parameter-declaration
2747 parameter-declaration:
2748 declaration-specifiers declarator attributes[opt]
2749 declaration-specifiers abstract-declarator[opt] attributes[opt]
2753 identifier-list , identifier
2755 abstract-declarator:
2757 pointer[opt] direct-abstract-declarator
2759 direct-abstract-declarator:
2760 ( attributes[opt] abstract-declarator )
2761 direct-abstract-declarator[opt] array-declarator
2762 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
2767 direct-declarator ( parameter-forward-declarations
2768 parameter-type-list[opt] )
2770 direct-abstract-declarator:
2771 direct-abstract-declarator[opt] ( parameter-forward-declarations
2772 parameter-type-list[opt] )
2774 parameter-forward-declarations:
2776 parameter-forward-declarations parameter-list ;
2778 The uses of attributes shown above are GNU extensions.
2780 Some forms of array declarator are not included in C99 in the
2781 syntax for abstract declarators; these are disallowed elsewhere.
2782 This may be a defect (DR#289).
2784 This function also accepts an omitted abstract declarator as being
2785 an abstract declarator, although not part of the formal syntax. */
2787 static struct c_declarator
*
2788 c_parser_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
2791 /* Parse any initial pointer part. */
2792 if (c_parser_next_token_is (parser
, CPP_MULT
))
2794 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
2795 struct c_declarator
*inner
;
2796 c_parser_consume_token (parser
);
2797 c_parser_declspecs (parser
, quals_attrs
, false, false, true, cla_prefer_id
);
2798 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
2802 return make_pointer_declarator (quals_attrs
, inner
);
2804 /* Now we have a direct declarator, direct abstract declarator or
2805 nothing (which counts as a direct abstract declarator here). */
2806 return c_parser_direct_declarator (parser
, type_seen_p
, kind
, seen_id
);
2809 /* Parse a direct declarator or direct abstract declarator; arguments
2810 as c_parser_declarator. */
2812 static struct c_declarator
*
2813 c_parser_direct_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
2816 /* The direct declarator must start with an identifier (possibly
2817 omitted) or a parenthesized declarator (possibly abstract). In
2818 an ordinary declarator, initial parentheses must start a
2819 parenthesized declarator. In an abstract declarator or parameter
2820 declarator, they could start a parenthesized declarator or a
2821 parameter list. To tell which, the open parenthesis and any
2822 following attributes must be read. If a declaration specifier
2823 follows, then it is a parameter list; if the specifier is a
2824 typedef name, there might be an ambiguity about redeclaring it,
2825 which is resolved in the direction of treating it as a typedef
2826 name. If a close parenthesis follows, it is also an empty
2827 parameter list, as the syntax does not permit empty abstract
2828 declarators. Otherwise, it is a parenthesized declarator (in
2829 which case the analysis may be repeated inside it, recursively).
2831 ??? There is an ambiguity in a parameter declaration "int
2832 (__attribute__((foo)) x)", where x is not a typedef name: it
2833 could be an abstract declarator for a function, or declare x with
2834 parentheses. The proper resolution of this ambiguity needs
2835 documenting. At present we follow an accident of the old
2836 parser's implementation, whereby the first parameter must have
2837 some declaration specifiers other than just attributes. Thus as
2838 a parameter declaration it is treated as a parenthesized
2839 parameter named x, and as an abstract declarator it is
2842 ??? Also following the old parser, attributes inside an empty
2843 parameter list are ignored, making it a list not yielding a
2844 prototype, rather than giving an error or making it have one
2845 parameter with implicit type int.
2847 ??? Also following the old parser, typedef names may be
2848 redeclared in declarators, but not Objective-C class names. */
2850 if (kind
!= C_DTR_ABSTRACT
2851 && c_parser_next_token_is (parser
, CPP_NAME
)
2853 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
2854 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
2855 || c_parser_peek_token (parser
)->id_kind
== C_ID_ID
))
2857 struct c_declarator
*inner
2858 = build_id_declarator (c_parser_peek_token (parser
)->value
);
2860 inner
->id_loc
= c_parser_peek_token (parser
)->location
;
2861 c_parser_consume_token (parser
);
2862 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
2865 if (kind
!= C_DTR_NORMAL
2866 && c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
2868 struct c_declarator
*inner
= build_id_declarator (NULL_TREE
);
2869 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
2872 /* Either we are at the end of an abstract declarator, or we have
2875 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
2878 struct c_declarator
*inner
;
2879 c_parser_consume_token (parser
);
2880 attrs
= c_parser_attributes (parser
);
2881 if (kind
!= C_DTR_NORMAL
2882 && (c_parser_next_token_starts_declspecs (parser
)
2883 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
)))
2885 struct c_arg_info
*args
2886 = c_parser_parms_declarator (parser
, kind
== C_DTR_NORMAL
,
2893 = build_function_declarator (args
,
2894 build_id_declarator (NULL_TREE
));
2895 return c_parser_direct_declarator_inner (parser
, *seen_id
,
2899 /* A parenthesized declarator. */
2900 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
2901 if (inner
!= NULL
&& attrs
!= NULL
)
2902 inner
= build_attrs_declarator (attrs
, inner
);
2903 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2905 c_parser_consume_token (parser
);
2909 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
2913 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2920 if (kind
== C_DTR_NORMAL
)
2922 c_parser_error (parser
, "expected identifier or %<(%>");
2926 return build_id_declarator (NULL_TREE
);
2930 /* Parse part of a direct declarator or direct abstract declarator,
2931 given that some (in INNER) has already been parsed; ID_PRESENT is
2932 true if an identifier is present, false for an abstract
2935 static struct c_declarator
*
2936 c_parser_direct_declarator_inner (c_parser
*parser
, bool id_present
,
2937 struct c_declarator
*inner
)
2939 /* Parse a sequence of array declarators and parameter lists. */
2940 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
2942 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
2943 struct c_declarator
*declarator
;
2944 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
2948 c_parser_consume_token (parser
);
2949 c_parser_declspecs (parser
, quals_attrs
, false, false, true, cla_prefer_id
);
2950 static_seen
= c_parser_next_token_is_keyword (parser
, RID_STATIC
);
2952 c_parser_consume_token (parser
);
2953 if (static_seen
&& !quals_attrs
->declspecs_seen_p
)
2954 c_parser_declspecs (parser
, quals_attrs
, false, false, true, cla_prefer_id
);
2955 if (!quals_attrs
->declspecs_seen_p
)
2957 /* If "static" is present, there must be an array dimension.
2958 Otherwise, there may be a dimension, "*", or no
2963 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
2967 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
2972 else if (c_parser_next_token_is (parser
, CPP_MULT
))
2974 if (c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_SQUARE
)
2978 c_parser_consume_token (parser
);
2983 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
2989 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
2992 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
2993 c_parser_consume_token (parser
);
2996 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3001 mark_exp_read (dimen
);
3002 declarator
= build_array_declarator (brace_loc
, dimen
, quals_attrs
,
3003 static_seen
, star_seen
);
3004 if (declarator
== NULL
)
3006 inner
= set_array_declarator_inner (declarator
, inner
);
3007 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3009 else if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3012 struct c_arg_info
*args
;
3013 c_parser_consume_token (parser
);
3014 attrs
= c_parser_attributes (parser
);
3015 args
= c_parser_parms_declarator (parser
, id_present
, attrs
);
3020 inner
= build_function_declarator (args
, inner
);
3021 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3027 /* Parse a parameter list or identifier list, including the closing
3028 parenthesis but not the opening one. ATTRS are the attributes at
3029 the start of the list. ID_LIST_OK is true if an identifier list is
3030 acceptable; such a list must not have attributes at the start. */
3032 static struct c_arg_info
*
3033 c_parser_parms_declarator (c_parser
*parser
, bool id_list_ok
, tree attrs
)
3036 declare_parm_level ();
3037 /* If the list starts with an identifier, it is an identifier list.
3038 Otherwise, it is either a prototype list or an empty list. */
3041 && c_parser_next_token_is (parser
, CPP_NAME
)
3042 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
3044 /* Look ahead to detect typos in type names. */
3045 && c_parser_peek_2nd_token (parser
)->type
!= CPP_NAME
3046 && c_parser_peek_2nd_token (parser
)->type
!= CPP_MULT
3047 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
3048 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_SQUARE
)
3050 tree list
= NULL_TREE
, *nextp
= &list
;
3051 while (c_parser_next_token_is (parser
, CPP_NAME
)
3052 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
3054 *nextp
= build_tree_list (NULL_TREE
,
3055 c_parser_peek_token (parser
)->value
);
3056 nextp
= & TREE_CHAIN (*nextp
);
3057 c_parser_consume_token (parser
);
3058 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
3060 c_parser_consume_token (parser
);
3061 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3063 c_parser_error (parser
, "expected identifier");
3067 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3069 struct c_arg_info
*ret
= build_arg_info ();
3071 c_parser_consume_token (parser
);
3077 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3085 struct c_arg_info
*ret
= c_parser_parms_list_declarator (parser
, attrs
);
3091 /* Parse a parameter list (possibly empty), including the closing
3092 parenthesis but not the opening one. ATTRS are the attributes at
3093 the start of the list. */
3095 static struct c_arg_info
*
3096 c_parser_parms_list_declarator (c_parser
*parser
, tree attrs
)
3098 bool bad_parm
= false;
3099 /* ??? Following the old parser, forward parameter declarations may
3100 use abstract declarators, and if no real parameter declarations
3101 follow the forward declarations then this is not diagnosed. Also
3102 note as above that attributes are ignored as the only contents of
3103 the parentheses, or as the only contents after forward
3105 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3107 struct c_arg_info
*ret
= build_arg_info ();
3108 c_parser_consume_token (parser
);
3111 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3113 struct c_arg_info
*ret
= build_arg_info ();
3114 /* Suppress -Wold-style-definition for this case. */
3115 ret
->types
= error_mark_node
;
3116 error_at (c_parser_peek_token (parser
)->location
,
3117 "ISO C requires a named argument before %<...%>");
3118 c_parser_consume_token (parser
);
3119 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3121 c_parser_consume_token (parser
);
3126 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3131 /* Nonempty list of parameters, either terminated with semicolon
3132 (forward declarations; recurse) or with close parenthesis (normal
3133 function) or with ", ... )" (variadic function). */
3136 /* Parse a parameter. */
3137 struct c_parm
*parm
= c_parser_parameter_declaration (parser
, attrs
);
3142 push_parm_decl (parm
);
3143 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3146 c_parser_consume_token (parser
);
3147 mark_forward_parm_decls ();
3148 new_attrs
= c_parser_attributes (parser
);
3149 return c_parser_parms_list_declarator (parser
, new_attrs
);
3151 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3153 c_parser_consume_token (parser
);
3156 get_pending_sizes ();
3160 return get_parm_info (false);
3162 if (!c_parser_require (parser
, CPP_COMMA
,
3163 "expected %<;%>, %<,%> or %<)%>"))
3165 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3166 get_pending_sizes ();
3169 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3171 c_parser_consume_token (parser
);
3172 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3174 c_parser_consume_token (parser
);
3177 get_pending_sizes ();
3181 return get_parm_info (true);
3185 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3187 get_pending_sizes ();
3194 /* Parse a parameter declaration. ATTRS are the attributes at the
3195 start of the declaration if it is the first parameter. */
3197 static struct c_parm
*
3198 c_parser_parameter_declaration (c_parser
*parser
, tree attrs
)
3200 struct c_declspecs
*specs
;
3201 struct c_declarator
*declarator
;
3203 tree postfix_attrs
= NULL_TREE
;
3205 if (!c_parser_next_token_starts_declspecs (parser
))
3207 c_token
*token
= c_parser_peek_token (parser
);
3210 c_parser_set_source_position_from_token (token
);
3211 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
3213 error ("unknown type name %qE", token
->value
);
3214 parser
->error
= true;
3216 /* ??? In some Objective-C cases '...' isn't applicable so there
3217 should be a different message. */
3219 c_parser_error (parser
,
3220 "expected declaration specifiers or %<...%>");
3221 c_parser_skip_to_end_of_parameter (parser
);
3224 specs
= build_null_declspecs ();
3227 declspecs_add_attrs (specs
, attrs
);
3230 c_parser_declspecs (parser
, specs
, true, true, true, cla_nonabstract_decl
);
3231 finish_declspecs (specs
);
3232 pending_xref_error ();
3233 prefix_attrs
= specs
->attrs
;
3234 specs
->attrs
= NULL_TREE
;
3235 declarator
= c_parser_declarator (parser
,
3236 specs
->typespec_kind
!= ctsk_none
,
3237 C_DTR_PARM
, &dummy
);
3238 if (declarator
== NULL
)
3240 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3243 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3244 postfix_attrs
= c_parser_attributes (parser
);
3245 return build_c_parm (specs
, chainon (postfix_attrs
, prefix_attrs
),
3249 /* Parse a string literal in an asm expression. It should not be
3250 translated, and wide string literals are an error although
3251 permitted by the syntax. This is a GNU extension.
3256 ??? At present, following the old parser, the caller needs to have
3257 set lex_untranslated_string to 1. It would be better to follow the
3258 C++ parser rather than using this kludge. */
3261 c_parser_asm_string_literal (c_parser
*parser
)
3264 if (c_parser_next_token_is (parser
, CPP_STRING
))
3266 str
= c_parser_peek_token (parser
)->value
;
3267 c_parser_consume_token (parser
);
3269 else if (c_parser_next_token_is (parser
, CPP_WSTRING
))
3271 error_at (c_parser_peek_token (parser
)->location
,
3272 "wide string literal in %<asm%>");
3273 str
= build_string (1, "");
3274 c_parser_consume_token (parser
);
3278 c_parser_error (parser
, "expected string literal");
3284 /* Parse a simple asm expression. This is used in restricted
3285 contexts, where a full expression with inputs and outputs does not
3286 make sense. This is a GNU extension.
3289 asm ( asm-string-literal )
3293 c_parser_simple_asm_expr (c_parser
*parser
)
3296 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
3297 /* ??? Follow the C++ parser rather than using the
3298 lex_untranslated_string kludge. */
3299 parser
->lex_untranslated_string
= true;
3300 c_parser_consume_token (parser
);
3301 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3303 parser
->lex_untranslated_string
= false;
3306 str
= c_parser_asm_string_literal (parser
);
3307 parser
->lex_untranslated_string
= false;
3308 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
3310 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3316 /* Parse (possibly empty) attributes. This is a GNU extension.
3320 attributes attribute
3323 __attribute__ ( ( attribute-list ) )
3327 attribute_list , attrib
3332 any-word ( identifier )
3333 any-word ( identifier , nonempty-expr-list )
3334 any-word ( expr-list )
3336 where the "identifier" must not be declared as a type, and
3337 "any-word" may be any identifier (including one declared as a
3338 type), a reserved word storage class specifier, type specifier or
3339 type qualifier. ??? This still leaves out most reserved keywords
3340 (following the old parser), shouldn't we include them, and why not
3341 allow identifiers declared as types to start the arguments? */
3344 c_parser_attributes (c_parser
*parser
)
3346 tree attrs
= NULL_TREE
;
3347 while (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3349 /* ??? Follow the C++ parser rather than using the
3350 lex_untranslated_string kludge. */
3351 parser
->lex_untranslated_string
= true;
3352 c_parser_consume_token (parser
);
3353 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3355 parser
->lex_untranslated_string
= false;
3358 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3360 parser
->lex_untranslated_string
= false;
3361 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3364 /* Parse the attribute list. */
3365 while (c_parser_next_token_is (parser
, CPP_COMMA
)
3366 || c_parser_next_token_is (parser
, CPP_NAME
)
3367 || c_parser_next_token_is (parser
, CPP_KEYWORD
))
3369 tree attr
, attr_name
, attr_args
;
3370 VEC(tree
,gc
) *expr_list
;
3371 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3373 c_parser_consume_token (parser
);
3376 if (c_parser_next_token_is (parser
, CPP_KEYWORD
))
3378 /* ??? See comment above about what keywords are
3381 switch (c_parser_peek_token (parser
)->keyword
)
3419 /* Accept __attribute__((__const)) as __attribute__((const))
3422 = ridpointers
[(int) c_parser_peek_token (parser
)->keyword
];
3425 attr_name
= c_parser_peek_token (parser
)->value
;
3426 c_parser_consume_token (parser
);
3427 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
3429 attr
= build_tree_list (attr_name
, NULL_TREE
);
3430 attrs
= chainon (attrs
, attr
);
3433 c_parser_consume_token (parser
);
3434 /* Parse the attribute contents. If they start with an
3435 identifier which is followed by a comma or close
3436 parenthesis, then the arguments start with that
3437 identifier; otherwise they are an expression list.
3438 In objective-c the identifier may be a classname. */
3439 if (c_parser_next_token_is (parser
, CPP_NAME
)
3440 && (c_parser_peek_token (parser
)->id_kind
== C_ID_ID
3441 || (c_dialect_objc ()
3442 && c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
3443 && ((c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
)
3444 || (c_parser_peek_2nd_token (parser
)->type
3445 == CPP_CLOSE_PAREN
)))
3447 tree arg1
= c_parser_peek_token (parser
)->value
;
3448 c_parser_consume_token (parser
);
3449 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3450 attr_args
= build_tree_list (NULL_TREE
, arg1
);
3454 c_parser_consume_token (parser
);
3455 expr_list
= c_parser_expr_list (parser
, false, true, NULL
);
3456 tree_list
= build_tree_list_vec (expr_list
);
3457 attr_args
= tree_cons (NULL_TREE
, arg1
, tree_list
);
3458 release_tree_vector (expr_list
);
3463 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3464 attr_args
= NULL_TREE
;
3467 expr_list
= c_parser_expr_list (parser
, false, true, NULL
);
3468 attr_args
= build_tree_list_vec (expr_list
);
3469 release_tree_vector (expr_list
);
3472 attr
= build_tree_list (attr_name
, attr_args
);
3473 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3474 c_parser_consume_token (parser
);
3477 parser
->lex_untranslated_string
= false;
3478 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3482 attrs
= chainon (attrs
, attr
);
3484 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3485 c_parser_consume_token (parser
);
3488 parser
->lex_untranslated_string
= false;
3489 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3493 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3494 c_parser_consume_token (parser
);
3497 parser
->lex_untranslated_string
= false;
3498 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3502 parser
->lex_untranslated_string
= false;
3507 /* Parse a type name (C90 6.5.5, C99 6.7.6).
3510 specifier-qualifier-list abstract-declarator[opt]
3513 static struct c_type_name
*
3514 c_parser_type_name (c_parser
*parser
)
3516 struct c_declspecs
*specs
= build_null_declspecs ();
3517 struct c_declarator
*declarator
;
3518 struct c_type_name
*ret
;
3520 c_parser_declspecs (parser
, specs
, false, true, true, cla_prefer_type
);
3521 if (!specs
->declspecs_seen_p
)
3523 c_parser_error (parser
, "expected specifier-qualifier-list");
3526 if (specs
->type
!= error_mark_node
)
3528 pending_xref_error ();
3529 finish_declspecs (specs
);
3531 declarator
= c_parser_declarator (parser
,
3532 specs
->typespec_kind
!= ctsk_none
,
3533 C_DTR_ABSTRACT
, &dummy
);
3534 if (declarator
== NULL
)
3536 ret
= XOBNEW (&parser_obstack
, struct c_type_name
);
3538 ret
->declarator
= declarator
;
3542 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
3545 assignment-expression
3546 { initializer-list }
3547 { initializer-list , }
3550 designation[opt] initializer
3551 initializer-list , designation[opt] initializer
3558 designator-list designator
3565 [ constant-expression ]
3577 [ constant-expression ... constant-expression ]
3579 Any expression without commas is accepted in the syntax for the
3580 constant-expressions, with non-constant expressions rejected later.
3582 This function is only used for top-level initializers; for nested
3583 ones, see c_parser_initval. */
3585 static struct c_expr
3586 c_parser_initializer (c_parser
*parser
)
3588 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
3589 return c_parser_braced_init (parser
, NULL_TREE
, false);
3593 location_t loc
= c_parser_peek_token (parser
)->location
;
3594 ret
= c_parser_expr_no_commas (parser
, NULL
);
3595 if (TREE_CODE (ret
.value
) != STRING_CST
3596 && TREE_CODE (ret
.value
) != COMPOUND_LITERAL_EXPR
)
3597 ret
= default_function_array_read_conversion (loc
, ret
);
3602 /* Parse a braced initializer list. TYPE is the type specified for a
3603 compound literal, and NULL_TREE for other initializers and for
3604 nested braced lists. NESTED_P is true for nested braced lists,
3605 false for the list of a compound literal or the list that is the
3606 top-level initializer in a declaration. */
3608 static struct c_expr
3609 c_parser_braced_init (c_parser
*parser
, tree type
, bool nested_p
)
3612 struct obstack braced_init_obstack
;
3613 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
3614 gcc_obstack_init (&braced_init_obstack
);
3615 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
3616 c_parser_consume_token (parser
);
3618 push_init_level (0, &braced_init_obstack
);
3620 really_start_incremental_init (type
);
3621 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3623 pedwarn (brace_loc
, OPT_pedantic
, "ISO C forbids empty initializer braces");
3627 /* Parse a non-empty initializer list, possibly with a trailing
3631 c_parser_initelt (parser
, &braced_init_obstack
);
3634 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3635 c_parser_consume_token (parser
);
3638 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3642 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
3644 ret
.value
= error_mark_node
;
3645 ret
.original_code
= ERROR_MARK
;
3646 ret
.original_type
= NULL
;
3647 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
3648 pop_init_level (0, &braced_init_obstack
);
3649 obstack_free (&braced_init_obstack
, NULL
);
3652 c_parser_consume_token (parser
);
3653 ret
= pop_init_level (0, &braced_init_obstack
);
3654 obstack_free (&braced_init_obstack
, NULL
);
3658 /* Parse a nested initializer, including designators. */
3661 c_parser_initelt (c_parser
*parser
, struct obstack
* braced_init_obstack
)
3663 /* Parse any designator or designator list. A single array
3664 designator may have the subsequent "=" omitted in GNU C, but a
3665 longer list or a structure member designator may not. */
3666 if (c_parser_next_token_is (parser
, CPP_NAME
)
3667 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
3669 /* Old-style structure member designator. */
3670 set_init_label (c_parser_peek_token (parser
)->value
,
3671 braced_init_obstack
);
3672 /* Use the colon as the error location. */
3673 pedwarn (c_parser_peek_2nd_token (parser
)->location
, OPT_pedantic
,
3674 "obsolete use of designated initializer with %<:%>");
3675 c_parser_consume_token (parser
);
3676 c_parser_consume_token (parser
);
3680 /* des_seen is 0 if there have been no designators, 1 if there
3681 has been a single array designator and 2 otherwise. */
3683 /* Location of a designator. */
3684 location_t des_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
3685 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
)
3686 || c_parser_next_token_is (parser
, CPP_DOT
))
3688 int des_prev
= des_seen
;
3690 des_loc
= c_parser_peek_token (parser
)->location
;
3693 if (c_parser_next_token_is (parser
, CPP_DOT
))
3696 c_parser_consume_token (parser
);
3697 if (c_parser_next_token_is (parser
, CPP_NAME
))
3699 set_init_label (c_parser_peek_token (parser
)->value
,
3700 braced_init_obstack
);
3701 c_parser_consume_token (parser
);
3706 init
.value
= error_mark_node
;
3707 init
.original_code
= ERROR_MARK
;
3708 init
.original_type
= NULL
;
3709 c_parser_error (parser
, "expected identifier");
3710 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3711 process_init_element (init
, false, braced_init_obstack
);
3718 location_t ellipsis_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
3719 /* ??? Following the old parser, [ objc-receiver
3720 objc-message-args ] is accepted as an initializer,
3721 being distinguished from a designator by what follows
3722 the first assignment expression inside the square
3723 brackets, but after a first array designator a
3724 subsequent square bracket is for Objective-C taken to
3725 start an expression, using the obsolete form of
3726 designated initializer without '=', rather than
3727 possibly being a second level of designation: in LALR
3728 terms, the '[' is shifted rather than reducing
3729 designator to designator-list. */
3730 if (des_prev
== 1 && c_dialect_objc ())
3732 des_seen
= des_prev
;
3735 if (des_prev
== 0 && c_dialect_objc ())
3737 /* This might be an array designator or an
3738 Objective-C message expression. If the former,
3739 continue parsing here; if the latter, parse the
3740 remainder of the initializer given the starting
3741 primary-expression. ??? It might make sense to
3742 distinguish when des_prev == 1 as well; see
3743 previous comment. */
3745 struct c_expr mexpr
;
3746 c_parser_consume_token (parser
);
3747 if (c_parser_peek_token (parser
)->type
== CPP_NAME
3748 && ((c_parser_peek_token (parser
)->id_kind
3750 || (c_parser_peek_token (parser
)->id_kind
3751 == C_ID_CLASSNAME
)))
3753 /* Type name receiver. */
3754 tree id
= c_parser_peek_token (parser
)->value
;
3755 c_parser_consume_token (parser
);
3756 rec
= objc_get_class_reference (id
);
3757 goto parse_message_args
;
3759 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
3760 mark_exp_read (first
);
3761 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
)
3762 || c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3763 goto array_desig_after_first
;
3764 /* Expression receiver. So far only one part
3765 without commas has been parsed; there might be
3766 more of the expression. */
3768 while (c_parser_next_token_is (parser
, CPP_COMMA
))
3771 location_t comma_loc
, exp_loc
;
3772 comma_loc
= c_parser_peek_token (parser
)->location
;
3773 c_parser_consume_token (parser
);
3774 exp_loc
= c_parser_peek_token (parser
)->location
;
3775 next
= c_parser_expr_no_commas (parser
, NULL
);
3776 next
= default_function_array_read_conversion (exp_loc
,
3778 rec
= build_compound_expr (comma_loc
, rec
, next
.value
);
3781 /* Now parse the objc-message-args. */
3782 args
= c_parser_objc_message_args (parser
);
3783 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3786 = objc_build_message_expr (build_tree_list (rec
, args
));
3787 mexpr
.original_code
= ERROR_MARK
;
3788 mexpr
.original_type
= NULL
;
3789 /* Now parse and process the remainder of the
3790 initializer, starting with this message
3791 expression as a primary-expression. */
3792 c_parser_initval (parser
, &mexpr
, braced_init_obstack
);
3795 c_parser_consume_token (parser
);
3796 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
3797 mark_exp_read (first
);
3798 array_desig_after_first
:
3799 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3801 ellipsis_loc
= c_parser_peek_token (parser
)->location
;
3802 c_parser_consume_token (parser
);
3803 second
= c_parser_expr_no_commas (parser
, NULL
).value
;
3804 mark_exp_read (second
);
3808 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3810 c_parser_consume_token (parser
);
3811 set_init_index (first
, second
, braced_init_obstack
);
3813 pedwarn (ellipsis_loc
, OPT_pedantic
,
3814 "ISO C forbids specifying range of elements to initialize");
3817 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3823 if (c_parser_next_token_is (parser
, CPP_EQ
))
3826 pedwarn (des_loc
, OPT_pedantic
,
3827 "ISO C90 forbids specifying subobject to initialize");
3828 c_parser_consume_token (parser
);
3833 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
3834 "obsolete use of designated initializer without %<=%>");
3838 init
.value
= error_mark_node
;
3839 init
.original_code
= ERROR_MARK
;
3840 init
.original_type
= NULL
;
3841 c_parser_error (parser
, "expected %<=%>");
3842 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3843 process_init_element (init
, false, braced_init_obstack
);
3849 c_parser_initval (parser
, NULL
, braced_init_obstack
);
3852 /* Parse a nested initializer; as c_parser_initializer but parses
3853 initializers within braced lists, after any designators have been
3854 applied. If AFTER is not NULL then it is an Objective-C message
3855 expression which is the primary-expression starting the
3859 c_parser_initval (c_parser
*parser
, struct c_expr
*after
,
3860 struct obstack
* braced_init_obstack
)
3863 gcc_assert (!after
|| c_dialect_objc ());
3864 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
) && !after
)
3865 init
= c_parser_braced_init (parser
, NULL_TREE
, true);
3868 location_t loc
= c_parser_peek_token (parser
)->location
;
3869 init
= c_parser_expr_no_commas (parser
, after
);
3870 if (init
.value
!= NULL_TREE
3871 && TREE_CODE (init
.value
) != STRING_CST
3872 && TREE_CODE (init
.value
) != COMPOUND_LITERAL_EXPR
)
3873 init
= default_function_array_read_conversion (loc
, init
);
3875 process_init_element (init
, false, braced_init_obstack
);
3878 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
3882 { block-item-list[opt] }
3883 { label-declarations block-item-list }
3887 block-item-list block-item
3899 { label-declarations block-item-list }
3902 __extension__ nested-declaration
3903 nested-function-definition
3907 label-declarations label-declaration
3910 __label__ identifier-list ;
3912 Allowing the mixing of declarations and code is new in C99. The
3913 GNU syntax also permits (not shown above) labels at the end of
3914 compound statements, which yield an error. We don't allow labels
3915 on declarations; this might seem like a natural extension, but
3916 there would be a conflict between attributes on the label and
3917 prefix attributes on the declaration. ??? The syntax follows the
3918 old parser in requiring something after label declarations.
3919 Although they are erroneous if the labels declared aren't defined,
3920 is it useful for the syntax to be this way?
3932 c_parser_compound_statement (c_parser
*parser
)
3935 location_t brace_loc
;
3936 brace_loc
= c_parser_peek_token (parser
)->location
;
3937 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
3939 /* Ensure a scope is entered and left anyway to avoid confusion
3940 if we have just prepared to enter a function body. */
3941 stmt
= c_begin_compound_stmt (true);
3942 c_end_compound_stmt (brace_loc
, stmt
, true);
3943 return error_mark_node
;
3945 stmt
= c_begin_compound_stmt (true);
3946 c_parser_compound_statement_nostart (parser
);
3947 return c_end_compound_stmt (brace_loc
, stmt
, true);
3950 /* Parse a compound statement except for the opening brace. This is
3951 used for parsing both compound statements and statement expressions
3952 (which follow different paths to handling the opening). */
3955 c_parser_compound_statement_nostart (c_parser
*parser
)
3957 bool last_stmt
= false;
3958 bool last_label
= false;
3959 bool save_valid_for_pragma
= valid_location_for_stdc_pragma_p ();
3960 location_t label_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
3961 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3963 c_parser_consume_token (parser
);
3966 mark_valid_location_for_stdc_pragma (true);
3967 if (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
3969 /* Read zero or more forward-declarations for labels that nested
3970 functions can jump to. */
3971 mark_valid_location_for_stdc_pragma (false);
3972 while (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
3974 label_loc
= c_parser_peek_token (parser
)->location
;
3975 c_parser_consume_token (parser
);
3976 /* Any identifiers, including those declared as type names,
3981 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
3983 c_parser_error (parser
, "expected identifier");
3987 = declare_label (c_parser_peek_token (parser
)->value
);
3988 C_DECLARED_LABEL_FLAG (label
) = 1;
3989 add_stmt (build_stmt (label_loc
, DECL_EXPR
, label
));
3990 c_parser_consume_token (parser
);
3991 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3992 c_parser_consume_token (parser
);
3996 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
3998 pedwarn (label_loc
, OPT_pedantic
, "ISO C forbids label declarations");
4000 /* We must now have at least one statement, label or declaration. */
4001 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4003 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4004 c_parser_error (parser
, "expected declaration or statement");
4005 c_parser_consume_token (parser
);
4008 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
4010 location_t loc
= c_parser_peek_token (parser
)->location
;
4011 if (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4012 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4013 || (c_parser_next_token_is (parser
, CPP_NAME
)
4014 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4016 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
4017 label_loc
= c_parser_peek_2nd_token (parser
)->location
;
4019 label_loc
= c_parser_peek_token (parser
)->location
;
4022 mark_valid_location_for_stdc_pragma (false);
4023 c_parser_label (parser
);
4025 else if (!last_label
4026 && c_parser_next_tokens_start_declaration (parser
))
4029 mark_valid_location_for_stdc_pragma (false);
4030 c_parser_declaration_or_fndef (parser
, true, true, true, true, true, NULL
);
4033 (pedantic
&& !flag_isoc99
)
4035 : OPT_Wdeclaration_after_statement
,
4036 "ISO C90 forbids mixed declarations and code");
4039 else if (!last_label
4040 && c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
4042 /* __extension__ can start a declaration, but is also an
4043 unary operator that can start an expression. Consume all
4044 but the last of a possible series of __extension__ to
4046 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
4047 && (c_parser_peek_2nd_token (parser
)->keyword
4049 c_parser_consume_token (parser
);
4050 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
4053 ext
= disable_extension_diagnostics ();
4054 c_parser_consume_token (parser
);
4056 mark_valid_location_for_stdc_pragma (false);
4057 c_parser_declaration_or_fndef (parser
, true, true, true, true,
4059 /* Following the old parser, __extension__ does not
4060 disable this diagnostic. */
4061 restore_extension_diagnostics (ext
);
4063 pedwarn_c90 (loc
, (pedantic
&& !flag_isoc99
)
4065 : OPT_Wdeclaration_after_statement
,
4066 "ISO C90 forbids mixed declarations and code");
4072 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
4074 /* External pragmas, and some omp pragmas, are not associated
4075 with regular c code, and so are not to be considered statements
4076 syntactically. This ensures that the user doesn't put them
4077 places that would turn into syntax errors if the directive
4079 if (c_parser_pragma (parser
, pragma_compound
))
4080 last_label
= false, last_stmt
= true;
4082 else if (c_parser_next_token_is (parser
, CPP_EOF
))
4084 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4085 c_parser_error (parser
, "expected declaration or statement");
4088 else if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
4090 if (parser
->in_if_block
)
4092 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4093 error_at (loc
, """expected %<}%> before %<else%>");
4098 error_at (loc
, "%<else%> without a previous %<if%>");
4099 c_parser_consume_token (parser
);
4108 mark_valid_location_for_stdc_pragma (false);
4109 c_parser_statement_after_labels (parser
);
4112 parser
->error
= false;
4115 error_at (label_loc
, "label at end of compound statement");
4116 c_parser_consume_token (parser
);
4117 /* Restore the value we started with. */
4118 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4121 /* Parse a label (C90 6.6.1, C99 6.8.1).
4124 identifier : attributes[opt]
4125 case constant-expression :
4131 case constant-expression ... constant-expression :
4133 The use of attributes on labels is a GNU extension. The syntax in
4134 GNU C accepts any expressions without commas, non-constant
4135 expressions being rejected later. */
4138 c_parser_label (c_parser
*parser
)
4140 location_t loc1
= c_parser_peek_token (parser
)->location
;
4141 tree label
= NULL_TREE
;
4142 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
4145 c_parser_consume_token (parser
);
4146 exp1
= c_parser_expr_no_commas (parser
, NULL
).value
;
4147 if (c_parser_next_token_is (parser
, CPP_COLON
))
4149 c_parser_consume_token (parser
);
4150 label
= do_case (loc1
, exp1
, NULL_TREE
);
4152 else if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
4154 c_parser_consume_token (parser
);
4155 exp2
= c_parser_expr_no_commas (parser
, NULL
).value
;
4156 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4157 label
= do_case (loc1
, exp1
, exp2
);
4160 c_parser_error (parser
, "expected %<:%> or %<...%>");
4162 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
4164 c_parser_consume_token (parser
);
4165 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4166 label
= do_case (loc1
, NULL_TREE
, NULL_TREE
);
4170 tree name
= c_parser_peek_token (parser
)->value
;
4173 location_t loc2
= c_parser_peek_token (parser
)->location
;
4174 gcc_assert (c_parser_next_token_is (parser
, CPP_NAME
));
4175 c_parser_consume_token (parser
);
4176 gcc_assert (c_parser_next_token_is (parser
, CPP_COLON
));
4177 c_parser_consume_token (parser
);
4178 attrs
= c_parser_attributes (parser
);
4179 tlab
= define_label (loc2
, name
);
4182 decl_attributes (&tlab
, attrs
, 0);
4183 label
= add_stmt (build_stmt (loc1
, LABEL_EXPR
, tlab
));
4188 if (c_parser_next_tokens_start_declaration (parser
))
4190 error_at (c_parser_peek_token (parser
)->location
,
4191 "a label can only be part of a statement and "
4192 "a declaration is not a statement");
4193 c_parser_declaration_or_fndef (parser
, /*fndef_ok*/ false,
4194 /*static_assert_ok*/ true,
4195 /*nested*/ true, /*empty_ok*/ false,
4196 /*start_attr_ok*/ true, NULL
);
4201 /* Parse a statement (C90 6.6, C99 6.8).
4206 expression-statement
4214 expression-statement:
4217 selection-statement:
4221 iteration-statement:
4230 return expression[opt] ;
4243 objc-throw-statement
4244 objc-try-catch-statement
4245 objc-synchronized-statement
4247 objc-throw-statement:
4261 parallel-for-construct
4262 parallel-sections-construct
4269 parallel-directive structured-block
4272 for-directive iteration-statement
4275 sections-directive section-scope
4278 single-directive structured-block
4280 parallel-for-construct:
4281 parallel-for-directive iteration-statement
4283 parallel-sections-construct:
4284 parallel-sections-directive section-scope
4287 master-directive structured-block
4290 critical-directive structured-block
4293 atomic-directive expression-statement
4296 ordered-directive structured-block */
4299 c_parser_statement (c_parser
*parser
)
4301 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4302 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4303 || (c_parser_next_token_is (parser
, CPP_NAME
)
4304 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4305 c_parser_label (parser
);
4306 c_parser_statement_after_labels (parser
);
4309 /* Parse a statement, other than a labeled statement. */
4312 c_parser_statement_after_labels (c_parser
*parser
)
4314 location_t loc
= c_parser_peek_token (parser
)->location
;
4315 tree stmt
= NULL_TREE
;
4316 bool in_if_block
= parser
->in_if_block
;
4317 parser
->in_if_block
= false;
4318 switch (c_parser_peek_token (parser
)->type
)
4320 case CPP_OPEN_BRACE
:
4321 add_stmt (c_parser_compound_statement (parser
));
4324 switch (c_parser_peek_token (parser
)->keyword
)
4327 c_parser_if_statement (parser
);
4330 c_parser_switch_statement (parser
);
4333 c_parser_while_statement (parser
);
4336 c_parser_do_statement (parser
);
4339 c_parser_for_statement (parser
);
4342 c_parser_consume_token (parser
);
4343 if (c_parser_next_token_is (parser
, CPP_NAME
))
4345 stmt
= c_finish_goto_label (loc
,
4346 c_parser_peek_token (parser
)->value
);
4347 c_parser_consume_token (parser
);
4349 else if (c_parser_next_token_is (parser
, CPP_MULT
))
4353 c_parser_consume_token (parser
);
4354 val
= c_parser_expression (parser
).value
;
4355 mark_exp_read (val
);
4356 stmt
= c_finish_goto_ptr (loc
, val
);
4359 c_parser_error (parser
, "expected identifier or %<*%>");
4360 goto expect_semicolon
;
4362 c_parser_consume_token (parser
);
4363 stmt
= c_finish_bc_stmt (loc
, &c_cont_label
, false);
4364 goto expect_semicolon
;
4366 c_parser_consume_token (parser
);
4367 stmt
= c_finish_bc_stmt (loc
, &c_break_label
, true);
4368 goto expect_semicolon
;
4370 c_parser_consume_token (parser
);
4371 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4373 stmt
= c_finish_return (loc
, NULL_TREE
, NULL_TREE
);
4374 c_parser_consume_token (parser
);
4378 struct c_expr expr
= c_parser_expression_conv (parser
);
4379 mark_exp_read (expr
.value
);
4380 stmt
= c_finish_return (loc
, expr
.value
, expr
.original_type
);
4381 goto expect_semicolon
;
4385 stmt
= c_parser_asm_statement (parser
);
4388 gcc_assert (c_dialect_objc ());
4389 c_parser_consume_token (parser
);
4390 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4392 stmt
= objc_build_throw_stmt (loc
, NULL_TREE
);
4393 c_parser_consume_token (parser
);
4397 tree expr
= c_parser_expression (parser
).value
;
4398 expr
= c_fully_fold (expr
, false, NULL
);
4399 stmt
= objc_build_throw_stmt (loc
, expr
);
4400 goto expect_semicolon
;
4404 gcc_assert (c_dialect_objc ());
4405 c_parser_objc_try_catch_finally_statement (parser
);
4407 case RID_AT_SYNCHRONIZED
:
4408 gcc_assert (c_dialect_objc ());
4409 c_parser_objc_synchronized_statement (parser
);
4416 c_parser_consume_token (parser
);
4418 case CPP_CLOSE_PAREN
:
4419 case CPP_CLOSE_SQUARE
:
4420 /* Avoid infinite loop in error recovery:
4421 c_parser_skip_until_found stops at a closing nesting
4422 delimiter without consuming it, but here we need to consume
4423 it to proceed further. */
4424 c_parser_error (parser
, "expected statement");
4425 c_parser_consume_token (parser
);
4428 c_parser_pragma (parser
, pragma_stmt
);
4432 stmt
= c_finish_expr_stmt (loc
, c_parser_expression_conv (parser
).value
);
4434 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4437 /* Two cases cannot and do not have line numbers associated: If stmt
4438 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
4439 cannot hold line numbers. But that's OK because the statement
4440 will either be changed to a MODIFY_EXPR during gimplification of
4441 the statement expr, or discarded. If stmt was compound, but
4442 without new variables, we will have skipped the creation of a
4443 BIND and will have a bare STATEMENT_LIST. But that's OK because
4444 (recursively) all of the component statements should already have
4445 line numbers assigned. ??? Can we discard no-op statements
4447 if (CAN_HAVE_LOCATION_P (stmt
)
4448 && EXPR_LOCATION (stmt
) == UNKNOWN_LOCATION
)
4449 SET_EXPR_LOCATION (stmt
, loc
);
4451 parser
->in_if_block
= in_if_block
;
4454 /* Parse the condition from an if, do, while or for statements. */
4457 c_parser_condition (c_parser
*parser
)
4459 location_t loc
= c_parser_peek_token (parser
)->location
;
4461 cond
= c_parser_expression_conv (parser
).value
;
4462 cond
= c_objc_common_truthvalue_conversion (loc
, cond
);
4463 cond
= c_fully_fold (cond
, false, NULL
);
4464 if (warn_sequence_point
)
4465 verify_sequence_points (cond
);
4469 /* Parse a parenthesized condition from an if, do or while statement.
4475 c_parser_paren_condition (c_parser
*parser
)
4478 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4479 return error_mark_node
;
4480 cond
= c_parser_condition (parser
);
4481 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4485 /* Parse a statement which is a block in C99. */
4488 c_parser_c99_block_statement (c_parser
*parser
)
4490 tree block
= c_begin_compound_stmt (flag_isoc99
);
4491 location_t loc
= c_parser_peek_token (parser
)->location
;
4492 c_parser_statement (parser
);
4493 return c_end_compound_stmt (loc
, block
, flag_isoc99
);
4496 /* Parse the body of an if statement. This is just parsing a
4497 statement but (a) it is a block in C99, (b) we track whether the
4498 body is an if statement for the sake of -Wparentheses warnings, (c)
4499 we handle an empty body specially for the sake of -Wempty-body
4500 warnings, and (d) we call parser_compound_statement directly
4501 because c_parser_statement_after_labels resets
4502 parser->in_if_block. */
4505 c_parser_if_body (c_parser
*parser
, bool *if_p
)
4507 tree block
= c_begin_compound_stmt (flag_isoc99
);
4508 location_t body_loc
= c_parser_peek_token (parser
)->location
;
4509 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4510 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4511 || (c_parser_next_token_is (parser
, CPP_NAME
)
4512 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4513 c_parser_label (parser
);
4514 *if_p
= c_parser_next_token_is_keyword (parser
, RID_IF
);
4515 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4517 location_t loc
= c_parser_peek_token (parser
)->location
;
4518 add_stmt (build_empty_stmt (loc
));
4519 c_parser_consume_token (parser
);
4520 if (!c_parser_next_token_is_keyword (parser
, RID_ELSE
))
4521 warning_at (loc
, OPT_Wempty_body
,
4522 "suggest braces around empty body in an %<if%> statement");
4524 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4525 add_stmt (c_parser_compound_statement (parser
));
4527 c_parser_statement_after_labels (parser
);
4528 return c_end_compound_stmt (body_loc
, block
, flag_isoc99
);
4531 /* Parse the else body of an if statement. This is just parsing a
4532 statement but (a) it is a block in C99, (b) we handle an empty body
4533 specially for the sake of -Wempty-body warnings. */
4536 c_parser_else_body (c_parser
*parser
)
4538 location_t else_loc
= c_parser_peek_token (parser
)->location
;
4539 tree block
= c_begin_compound_stmt (flag_isoc99
);
4540 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4541 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4542 || (c_parser_next_token_is (parser
, CPP_NAME
)
4543 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4544 c_parser_label (parser
);
4545 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4547 location_t loc
= c_parser_peek_token (parser
)->location
;
4550 "suggest braces around empty body in an %<else%> statement");
4551 add_stmt (build_empty_stmt (loc
));
4552 c_parser_consume_token (parser
);
4555 c_parser_statement_after_labels (parser
);
4556 return c_end_compound_stmt (else_loc
, block
, flag_isoc99
);
4559 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
4562 if ( expression ) statement
4563 if ( expression ) statement else statement
4567 c_parser_if_statement (c_parser
*parser
)
4572 bool first_if
= false;
4573 tree first_body
, second_body
;
4576 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_IF
));
4577 c_parser_consume_token (parser
);
4578 block
= c_begin_compound_stmt (flag_isoc99
);
4579 loc
= c_parser_peek_token (parser
)->location
;
4580 cond
= c_parser_paren_condition (parser
);
4581 in_if_block
= parser
->in_if_block
;
4582 parser
->in_if_block
= true;
4583 first_body
= c_parser_if_body (parser
, &first_if
);
4584 parser
->in_if_block
= in_if_block
;
4585 if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
4587 c_parser_consume_token (parser
);
4588 second_body
= c_parser_else_body (parser
);
4591 second_body
= NULL_TREE
;
4592 c_finish_if_stmt (loc
, cond
, first_body
, second_body
, first_if
);
4593 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
4596 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
4599 switch (expression) statement
4603 c_parser_switch_statement (c_parser
*parser
)
4605 tree block
, expr
, body
, save_break
;
4606 location_t switch_loc
= c_parser_peek_token (parser
)->location
;
4607 location_t switch_cond_loc
;
4608 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SWITCH
));
4609 c_parser_consume_token (parser
);
4610 block
= c_begin_compound_stmt (flag_isoc99
);
4611 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4613 switch_cond_loc
= c_parser_peek_token (parser
)->location
;
4614 expr
= c_parser_expression (parser
).value
;
4615 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4619 switch_cond_loc
= UNKNOWN_LOCATION
;
4620 expr
= error_mark_node
;
4622 c_start_case (switch_loc
, switch_cond_loc
, expr
);
4623 save_break
= c_break_label
;
4624 c_break_label
= NULL_TREE
;
4625 body
= c_parser_c99_block_statement (parser
);
4626 c_finish_case (body
);
4629 location_t here
= c_parser_peek_token (parser
)->location
;
4630 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_break_label
);
4631 SET_EXPR_LOCATION (t
, here
);
4634 c_break_label
= save_break
;
4635 add_stmt (c_end_compound_stmt (switch_loc
, block
, flag_isoc99
));
4638 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
4641 while (expression) statement
4645 c_parser_while_statement (c_parser
*parser
)
4647 tree block
, cond
, body
, save_break
, save_cont
;
4649 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_WHILE
));
4650 c_parser_consume_token (parser
);
4651 block
= c_begin_compound_stmt (flag_isoc99
);
4652 loc
= c_parser_peek_token (parser
)->location
;
4653 cond
= c_parser_paren_condition (parser
);
4654 save_break
= c_break_label
;
4655 c_break_label
= NULL_TREE
;
4656 save_cont
= c_cont_label
;
4657 c_cont_label
= NULL_TREE
;
4658 body
= c_parser_c99_block_statement (parser
);
4659 c_finish_loop (loc
, cond
, NULL
, body
, c_break_label
, c_cont_label
, true);
4660 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
4661 c_break_label
= save_break
;
4662 c_cont_label
= save_cont
;
4665 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
4668 do statement while ( expression ) ;
4672 c_parser_do_statement (c_parser
*parser
)
4674 tree block
, cond
, body
, save_break
, save_cont
, new_break
, new_cont
;
4676 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_DO
));
4677 c_parser_consume_token (parser
);
4678 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4679 warning_at (c_parser_peek_token (parser
)->location
,
4681 "suggest braces around empty body in %<do%> statement");
4682 block
= c_begin_compound_stmt (flag_isoc99
);
4683 loc
= c_parser_peek_token (parser
)->location
;
4684 save_break
= c_break_label
;
4685 c_break_label
= NULL_TREE
;
4686 save_cont
= c_cont_label
;
4687 c_cont_label
= NULL_TREE
;
4688 body
= c_parser_c99_block_statement (parser
);
4689 c_parser_require_keyword (parser
, RID_WHILE
, "expected %<while%>");
4690 new_break
= c_break_label
;
4691 c_break_label
= save_break
;
4692 new_cont
= c_cont_label
;
4693 c_cont_label
= save_cont
;
4694 cond
= c_parser_paren_condition (parser
);
4695 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
4696 c_parser_skip_to_end_of_block_or_statement (parser
);
4697 c_finish_loop (loc
, cond
, NULL
, body
, new_break
, new_cont
, false);
4698 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
4701 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
4704 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
4705 for ( nested-declaration expression[opt] ; expression[opt] ) statement
4707 The form with a declaration is new in C99.
4709 ??? In accordance with the old parser, the declaration may be a
4710 nested function, which is then rejected in check_for_loop_decls,
4711 but does it make any sense for this to be included in the grammar?
4712 Note in particular that the nested function does not include a
4713 trailing ';', whereas the "declaration" production includes one.
4714 Also, can we reject bad declarations earlier and cheaper than
4715 check_for_loop_decls?
4717 In Objective-C, there are two additional variants:
4720 for ( expression in expresssion ) statement
4721 for ( declaration in expression ) statement
4723 This is inconsistent with C, because the second variant is allowed
4724 even if c99 is not enabled.
4726 The rest of the comment documents these Objective-C foreach-statement.
4728 Here is the canonical example of the first variant:
4729 for (object in array) { do something with object }
4730 we call the first expression ("object") the "object_expression" and
4731 the second expression ("array") the "collection_expression".
4732 object_expression must be an lvalue of type "id" (a generic Objective-C
4733 object) because the loop works by assigning to object_expression the
4734 various objects from the collection_expression. collection_expression
4735 must evaluate to something of type "id" which responds to the method
4736 countByEnumeratingWithState:objects:count:.
4738 The canonical example of the second variant is:
4739 for (id object in array) { do something with object }
4740 which is completely equivalent to
4743 for (object in array) { do something with object }
4745 Note that initizializing 'object' in some way (eg, "for ((object =
4746 xxx) in array) { do something with object }") is possibly
4747 technically valid, but completely pointless as 'object' will be
4748 assigned to something else as soon as the loop starts. We should
4749 most likely reject it (TODO).
4751 The beginning of the Objective-C foreach-statement looks exactly
4752 like the beginning of the for-statement, and we can tell it is a
4753 foreach-statement only because the initial declaration or
4754 expression is terminated by 'in' instead of ';'.
4758 c_parser_for_statement (c_parser
*parser
)
4760 tree block
, cond
, incr
, save_break
, save_cont
, body
;
4761 /* The following are only used when parsing an ObjC foreach statement. */
4762 tree object_expression
;
4763 /* Silence the bogus uninitialized warning. */
4764 tree collection_expression
= NULL
;
4765 location_t loc
= c_parser_peek_token (parser
)->location
;
4766 location_t for_loc
= c_parser_peek_token (parser
)->location
;
4767 bool is_foreach_statement
= false;
4768 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_FOR
));
4769 c_parser_consume_token (parser
);
4770 /* Open a compound statement in Objective-C as well, just in case this is
4771 as foreach expression. */
4772 block
= c_begin_compound_stmt (flag_isoc99
|| c_dialect_objc ());
4773 cond
= error_mark_node
;
4774 incr
= error_mark_node
;
4775 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4777 /* Parse the initialization declaration or expression. */
4778 object_expression
= error_mark_node
;
4779 parser
->objc_could_be_foreach_context
= c_dialect_objc ();
4780 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4782 parser
->objc_could_be_foreach_context
= false;
4783 c_parser_consume_token (parser
);
4784 c_finish_expr_stmt (loc
, NULL_TREE
);
4786 else if (c_parser_next_tokens_start_declaration (parser
))
4788 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
4789 &object_expression
);
4790 parser
->objc_could_be_foreach_context
= false;
4792 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
4794 c_parser_consume_token (parser
);
4795 is_foreach_statement
= true;
4796 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
4797 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
4800 check_for_loop_decls (for_loc
, flag_isoc99
);
4802 else if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
4804 /* __extension__ can start a declaration, but is also an
4805 unary operator that can start an expression. Consume all
4806 but the last of a possible series of __extension__ to
4808 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
4809 && (c_parser_peek_2nd_token (parser
)->keyword
4811 c_parser_consume_token (parser
);
4812 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
4815 ext
= disable_extension_diagnostics ();
4816 c_parser_consume_token (parser
);
4817 c_parser_declaration_or_fndef (parser
, true, true, true, true,
4818 true, &object_expression
);
4819 parser
->objc_could_be_foreach_context
= false;
4821 restore_extension_diagnostics (ext
);
4822 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
4824 c_parser_consume_token (parser
);
4825 is_foreach_statement
= true;
4826 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
4827 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
4830 check_for_loop_decls (for_loc
, flag_isoc99
);
4839 tree init_expression
;
4840 init_expression
= c_parser_expression (parser
).value
;
4841 parser
->objc_could_be_foreach_context
= false;
4842 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
4844 c_parser_consume_token (parser
);
4845 is_foreach_statement
= true;
4846 if (! lvalue_p (init_expression
))
4847 c_parser_error (parser
, "invalid iterating variable in fast enumeration");
4848 object_expression
= c_fully_fold (init_expression
, false, NULL
);
4852 c_finish_expr_stmt (loc
, init_expression
);
4853 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4857 /* Parse the loop condition. In the case of a foreach
4858 statement, there is no loop condition. */
4859 gcc_assert (!parser
->objc_could_be_foreach_context
);
4860 if (!is_foreach_statement
)
4862 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4864 c_parser_consume_token (parser
);
4869 cond
= c_parser_condition (parser
);
4870 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4873 /* Parse the increment expression (the third expression in a
4874 for-statement). In the case of a foreach-statement, this is
4875 the expression that follows the 'in'. */
4876 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4878 if (is_foreach_statement
)
4880 c_parser_error (parser
, "missing collection in fast enumeration");
4881 collection_expression
= error_mark_node
;
4884 incr
= c_process_expr_stmt (loc
, NULL_TREE
);
4888 if (is_foreach_statement
)
4889 collection_expression
= c_fully_fold (c_parser_expression (parser
).value
,
4892 incr
= c_process_expr_stmt (loc
, c_parser_expression (parser
).value
);
4894 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4896 save_break
= c_break_label
;
4897 c_break_label
= NULL_TREE
;
4898 save_cont
= c_cont_label
;
4899 c_cont_label
= NULL_TREE
;
4900 body
= c_parser_c99_block_statement (parser
);
4901 if (is_foreach_statement
)
4902 objc_finish_foreach_loop (loc
, object_expression
, collection_expression
, body
, c_break_label
, c_cont_label
);
4904 c_finish_loop (loc
, cond
, incr
, body
, c_break_label
, c_cont_label
, true);
4905 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
|| c_dialect_objc ()));
4906 c_break_label
= save_break
;
4907 c_cont_label
= save_cont
;
4910 /* Parse an asm statement, a GNU extension. This is a full-blown asm
4911 statement with inputs, outputs, clobbers, and volatile tag
4915 asm type-qualifier[opt] ( asm-argument ) ;
4916 asm type-qualifier[opt] goto ( asm-goto-argument ) ;
4920 asm-string-literal : asm-operands[opt]
4921 asm-string-literal : asm-operands[opt] : asm-operands[opt]
4922 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers[opt]
4925 asm-string-literal : : asm-operands[opt] : asm-clobbers[opt] \
4928 Qualifiers other than volatile are accepted in the syntax but
4932 c_parser_asm_statement (c_parser
*parser
)
4934 tree quals
, str
, outputs
, inputs
, clobbers
, labels
, ret
;
4935 bool simple
, is_goto
;
4936 location_t asm_loc
= c_parser_peek_token (parser
)->location
;
4937 int section
, nsections
;
4939 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
4940 c_parser_consume_token (parser
);
4941 if (c_parser_next_token_is_keyword (parser
, RID_VOLATILE
))
4943 quals
= c_parser_peek_token (parser
)->value
;
4944 c_parser_consume_token (parser
);
4946 else if (c_parser_next_token_is_keyword (parser
, RID_CONST
)
4947 || c_parser_next_token_is_keyword (parser
, RID_RESTRICT
))
4949 warning_at (c_parser_peek_token (parser
)->location
,
4951 "%E qualifier ignored on asm",
4952 c_parser_peek_token (parser
)->value
);
4954 c_parser_consume_token (parser
);
4960 if (c_parser_next_token_is_keyword (parser
, RID_GOTO
))
4962 c_parser_consume_token (parser
);
4966 /* ??? Follow the C++ parser rather than using the
4967 lex_untranslated_string kludge. */
4968 parser
->lex_untranslated_string
= true;
4971 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4974 str
= c_parser_asm_string_literal (parser
);
4975 if (str
== NULL_TREE
)
4976 goto error_close_paren
;
4979 outputs
= NULL_TREE
;
4981 clobbers
= NULL_TREE
;
4984 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
4987 /* Parse each colon-delimited section of operands. */
4988 nsections
= 3 + is_goto
;
4989 for (section
= 0; section
< nsections
; ++section
)
4991 if (!c_parser_require (parser
, CPP_COLON
,
4994 : "expected %<:%> or %<)%>"))
4995 goto error_close_paren
;
4997 /* Once past any colon, we're no longer a simple asm. */
5000 if ((!c_parser_next_token_is (parser
, CPP_COLON
)
5001 && !c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
5006 /* For asm goto, we don't allow output operands, but reserve
5007 the slot for a future extension that does allow them. */
5009 outputs
= c_parser_asm_operands (parser
, false);
5012 inputs
= c_parser_asm_operands (parser
, true);
5015 clobbers
= c_parser_asm_clobbers (parser
);
5018 labels
= c_parser_asm_goto_operands (parser
);
5024 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
5029 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
5031 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5035 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
5036 c_parser_skip_to_end_of_block_or_statement (parser
);
5038 ret
= build_asm_stmt (quals
, build_asm_expr (asm_loc
, str
, outputs
, inputs
,
5039 clobbers
, labels
, simple
));
5042 parser
->lex_untranslated_string
= false;
5046 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5050 /* Parse asm operands, a GNU extension. If CONVERT_P (for inputs but
5051 not outputs), apply the default conversion of functions and arrays
5056 asm-operands , asm-operand
5059 asm-string-literal ( expression )
5060 [ identifier ] asm-string-literal ( expression )
5064 c_parser_asm_operands (c_parser
*parser
, bool convert_p
)
5066 tree list
= NULL_TREE
;
5072 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
5074 c_parser_consume_token (parser
);
5075 if (c_parser_next_token_is (parser
, CPP_NAME
))
5077 tree id
= c_parser_peek_token (parser
)->value
;
5078 c_parser_consume_token (parser
);
5079 name
= build_string (IDENTIFIER_LENGTH (id
),
5080 IDENTIFIER_POINTER (id
));
5084 c_parser_error (parser
, "expected identifier");
5085 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
5088 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5093 str
= c_parser_asm_string_literal (parser
);
5094 if (str
== NULL_TREE
)
5096 parser
->lex_untranslated_string
= false;
5097 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5099 parser
->lex_untranslated_string
= true;
5102 loc
= c_parser_peek_token (parser
)->location
;
5103 expr
= c_parser_expression (parser
);
5104 mark_exp_read (expr
.value
);
5106 expr
= default_function_array_conversion (loc
, expr
);
5107 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
5108 parser
->lex_untranslated_string
= true;
5109 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
5111 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5114 list
= chainon (list
, build_tree_list (build_tree_list (name
, str
),
5116 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5117 c_parser_consume_token (parser
);
5124 /* Parse asm clobbers, a GNU extension.
5128 asm-clobbers , asm-string-literal
5132 c_parser_asm_clobbers (c_parser
*parser
)
5134 tree list
= NULL_TREE
;
5137 tree str
= c_parser_asm_string_literal (parser
);
5139 list
= tree_cons (NULL_TREE
, str
, list
);
5142 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5143 c_parser_consume_token (parser
);
5150 /* Parse asm goto labels, a GNU extension.
5154 asm-goto-operands , identifier
5158 c_parser_asm_goto_operands (c_parser
*parser
)
5160 tree list
= NULL_TREE
;
5165 if (c_parser_next_token_is (parser
, CPP_NAME
))
5167 c_token
*tok
= c_parser_peek_token (parser
);
5169 label
= lookup_label_for_goto (tok
->location
, name
);
5170 c_parser_consume_token (parser
);
5171 TREE_USED (label
) = 1;
5175 c_parser_error (parser
, "expected identifier");
5179 name
= build_string (IDENTIFIER_LENGTH (name
),
5180 IDENTIFIER_POINTER (name
));
5181 list
= tree_cons (name
, label
, list
);
5182 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5183 c_parser_consume_token (parser
);
5185 return nreverse (list
);
5189 /* Parse an expression other than a compound expression; that is, an
5190 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
5191 NULL then it is an Objective-C message expression which is the
5192 primary-expression starting the expression as an initializer.
5194 assignment-expression:
5195 conditional-expression
5196 unary-expression assignment-operator assignment-expression
5198 assignment-operator: one of
5199 = *= /= %= += -= <<= >>= &= ^= |=
5201 In GNU C we accept any conditional expression on the LHS and
5202 diagnose the invalid lvalue rather than producing a syntax
5205 static struct c_expr
5206 c_parser_expr_no_commas (c_parser
*parser
, struct c_expr
*after
)
5208 struct c_expr lhs
, rhs
, ret
;
5209 enum tree_code code
;
5210 location_t op_location
, exp_location
;
5211 gcc_assert (!after
|| c_dialect_objc ());
5212 lhs
= c_parser_conditional_expression (parser
, after
);
5213 op_location
= c_parser_peek_token (parser
)->location
;
5214 switch (c_parser_peek_token (parser
)->type
)
5223 code
= TRUNC_DIV_EXPR
;
5226 code
= TRUNC_MOD_EXPR
;
5241 code
= BIT_AND_EXPR
;
5244 code
= BIT_XOR_EXPR
;
5247 code
= BIT_IOR_EXPR
;
5252 c_parser_consume_token (parser
);
5253 exp_location
= c_parser_peek_token (parser
)->location
;
5254 rhs
= c_parser_expr_no_commas (parser
, NULL
);
5255 rhs
= default_function_array_read_conversion (exp_location
, rhs
);
5256 ret
.value
= build_modify_expr (op_location
, lhs
.value
, lhs
.original_type
,
5257 code
, exp_location
, rhs
.value
,
5259 if (code
== NOP_EXPR
)
5260 ret
.original_code
= MODIFY_EXPR
;
5263 TREE_NO_WARNING (ret
.value
) = 1;
5264 ret
.original_code
= ERROR_MARK
;
5266 ret
.original_type
= NULL
;
5270 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
5271 is not NULL then it is an Objective-C message expression which is
5272 the primary-expression starting the expression as an initializer.
5274 conditional-expression:
5275 logical-OR-expression
5276 logical-OR-expression ? expression : conditional-expression
5280 conditional-expression:
5281 logical-OR-expression ? : conditional-expression
5284 static struct c_expr
5285 c_parser_conditional_expression (c_parser
*parser
, struct c_expr
*after
)
5287 struct c_expr cond
, exp1
, exp2
, ret
;
5288 location_t cond_loc
, colon_loc
, middle_loc
;
5290 gcc_assert (!after
|| c_dialect_objc ());
5292 cond
= c_parser_binary_expression (parser
, after
);
5294 if (c_parser_next_token_is_not (parser
, CPP_QUERY
))
5296 cond_loc
= c_parser_peek_token (parser
)->location
;
5297 cond
= default_function_array_read_conversion (cond_loc
, cond
);
5298 c_parser_consume_token (parser
);
5299 if (c_parser_next_token_is (parser
, CPP_COLON
))
5301 tree eptype
= NULL_TREE
;
5303 middle_loc
= c_parser_peek_token (parser
)->location
;
5304 pedwarn (middle_loc
, OPT_pedantic
,
5305 "ISO C forbids omitting the middle term of a ?: expression");
5306 warn_for_omitted_condop (middle_loc
, cond
.value
);
5307 if (TREE_CODE (cond
.value
) == EXCESS_PRECISION_EXPR
)
5309 eptype
= TREE_TYPE (cond
.value
);
5310 cond
.value
= TREE_OPERAND (cond
.value
, 0);
5312 /* Make sure first operand is calculated only once. */
5313 exp1
.value
= c_save_expr (default_conversion (cond
.value
));
5315 exp1
.value
= build1 (EXCESS_PRECISION_EXPR
, eptype
, exp1
.value
);
5316 exp1
.original_type
= NULL
;
5317 cond
.value
= c_objc_common_truthvalue_conversion (cond_loc
, exp1
.value
);
5318 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_true_node
;
5323 = c_objc_common_truthvalue_conversion
5324 (cond_loc
, default_conversion (cond
.value
));
5325 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_false_node
;
5326 exp1
= c_parser_expression_conv (parser
);
5327 mark_exp_read (exp1
.value
);
5328 c_inhibit_evaluation_warnings
+=
5329 ((cond
.value
== truthvalue_true_node
)
5330 - (cond
.value
== truthvalue_false_node
));
5333 colon_loc
= c_parser_peek_token (parser
)->location
;
5334 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
5336 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
5337 ret
.value
= error_mark_node
;
5338 ret
.original_code
= ERROR_MARK
;
5339 ret
.original_type
= NULL
;
5343 location_t exp2_loc
= c_parser_peek_token (parser
)->location
;
5344 exp2
= c_parser_conditional_expression (parser
, NULL
);
5345 exp2
= default_function_array_read_conversion (exp2_loc
, exp2
);
5347 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
5348 ret
.value
= build_conditional_expr (colon_loc
, cond
.value
,
5349 cond
.original_code
== C_MAYBE_CONST_EXPR
,
5350 exp1
.value
, exp1
.original_type
,
5351 exp2
.value
, exp2
.original_type
);
5352 ret
.original_code
= ERROR_MARK
;
5353 if (exp1
.value
== error_mark_node
|| exp2
.value
== error_mark_node
)
5354 ret
.original_type
= NULL
;
5359 /* If both sides are enum type, the default conversion will have
5360 made the type of the result be an integer type. We want to
5361 remember the enum types we started with. */
5362 t1
= exp1
.original_type
? exp1
.original_type
: TREE_TYPE (exp1
.value
);
5363 t2
= exp2
.original_type
? exp2
.original_type
: TREE_TYPE (exp2
.value
);
5364 ret
.original_type
= ((t1
!= error_mark_node
5365 && t2
!= error_mark_node
5366 && (TYPE_MAIN_VARIANT (t1
)
5367 == TYPE_MAIN_VARIANT (t2
)))
5374 /* Parse a binary expression; that is, a logical-OR-expression (C90
5375 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
5376 an Objective-C message expression which is the primary-expression
5377 starting the expression as an initializer.
5379 multiplicative-expression:
5381 multiplicative-expression * cast-expression
5382 multiplicative-expression / cast-expression
5383 multiplicative-expression % cast-expression
5385 additive-expression:
5386 multiplicative-expression
5387 additive-expression + multiplicative-expression
5388 additive-expression - multiplicative-expression
5392 shift-expression << additive-expression
5393 shift-expression >> additive-expression
5395 relational-expression:
5397 relational-expression < shift-expression
5398 relational-expression > shift-expression
5399 relational-expression <= shift-expression
5400 relational-expression >= shift-expression
5402 equality-expression:
5403 relational-expression
5404 equality-expression == relational-expression
5405 equality-expression != relational-expression
5409 AND-expression & equality-expression
5411 exclusive-OR-expression:
5413 exclusive-OR-expression ^ AND-expression
5415 inclusive-OR-expression:
5416 exclusive-OR-expression
5417 inclusive-OR-expression | exclusive-OR-expression
5419 logical-AND-expression:
5420 inclusive-OR-expression
5421 logical-AND-expression && inclusive-OR-expression
5423 logical-OR-expression:
5424 logical-AND-expression
5425 logical-OR-expression || logical-AND-expression
5428 static struct c_expr
5429 c_parser_binary_expression (c_parser
*parser
, struct c_expr
*after
)
5431 /* A binary expression is parsed using operator-precedence parsing,
5432 with the operands being cast expressions. All the binary
5433 operators are left-associative. Thus a binary expression is of
5436 E0 op1 E1 op2 E2 ...
5438 which we represent on a stack. On the stack, the precedence
5439 levels are strictly increasing. When a new operator is
5440 encountered of higher precedence than that at the top of the
5441 stack, it is pushed; its LHS is the top expression, and its RHS
5442 is everything parsed until it is popped. When a new operator is
5443 encountered with precedence less than or equal to that at the top
5444 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
5445 by the result of the operation until the operator at the top of
5446 the stack has lower precedence than the new operator or there is
5447 only one element on the stack; then the top expression is the LHS
5448 of the new operator. In the case of logical AND and OR
5449 expressions, we also need to adjust c_inhibit_evaluation_warnings
5450 as appropriate when the operators are pushed and popped. */
5452 /* The precedence levels, where 0 is a dummy lowest level used for
5453 the bottom of the stack. */
5469 /* The expression at this stack level. */
5471 /* The precedence of the operator on its left, PREC_NONE at the
5472 bottom of the stack. */
5474 /* The operation on its left. */
5476 /* The source location of this operation. */
5480 /* Location of the binary operator. */
5481 location_t binary_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
5484 switch (stack[sp].op) \
5486 case TRUTH_ANDIF_EXPR: \
5487 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
5488 == truthvalue_false_node); \
5490 case TRUTH_ORIF_EXPR: \
5491 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
5492 == truthvalue_true_node); \
5497 stack[sp - 1].expr \
5498 = default_function_array_read_conversion (stack[sp - 1].loc, \
5499 stack[sp - 1].expr); \
5501 = default_function_array_read_conversion (stack[sp].loc, \
5503 stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc, \
5505 stack[sp - 1].expr, \
5509 gcc_assert (!after
|| c_dialect_objc ());
5510 stack
[0].loc
= c_parser_peek_token (parser
)->location
;
5511 stack
[0].expr
= c_parser_cast_expression (parser
, after
);
5512 stack
[0].prec
= PREC_NONE
;
5517 enum tree_code ocode
;
5520 switch (c_parser_peek_token (parser
)->type
)
5528 ocode
= TRUNC_DIV_EXPR
;
5532 ocode
= TRUNC_MOD_EXPR
;
5544 ocode
= LSHIFT_EXPR
;
5548 ocode
= RSHIFT_EXPR
;
5562 case CPP_GREATER_EQ
:
5575 oprec
= PREC_BITAND
;
5576 ocode
= BIT_AND_EXPR
;
5579 oprec
= PREC_BITXOR
;
5580 ocode
= BIT_XOR_EXPR
;
5584 ocode
= BIT_IOR_EXPR
;
5587 oprec
= PREC_LOGAND
;
5588 ocode
= TRUTH_ANDIF_EXPR
;
5592 ocode
= TRUTH_ORIF_EXPR
;
5595 /* Not a binary operator, so end of the binary
5599 binary_loc
= c_parser_peek_token (parser
)->location
;
5600 c_parser_consume_token (parser
);
5601 while (oprec
<= stack
[sp
].prec
)
5605 case TRUTH_ANDIF_EXPR
:
5607 = default_function_array_read_conversion (stack
[sp
].loc
,
5609 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
5610 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
5611 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
5612 == truthvalue_false_node
);
5614 case TRUTH_ORIF_EXPR
:
5616 = default_function_array_read_conversion (stack
[sp
].loc
,
5618 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
5619 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
5620 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
5621 == truthvalue_true_node
);
5627 stack
[sp
].loc
= binary_loc
;
5628 stack
[sp
].expr
= c_parser_cast_expression (parser
, NULL
);
5629 stack
[sp
].prec
= oprec
;
5630 stack
[sp
].op
= ocode
;
5631 stack
[sp
].loc
= binary_loc
;
5636 return stack
[0].expr
;
5640 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
5641 NULL then it is an Objective-C message expression which is the
5642 primary-expression starting the expression as an initializer.
5646 ( type-name ) unary-expression
5649 static struct c_expr
5650 c_parser_cast_expression (c_parser
*parser
, struct c_expr
*after
)
5652 location_t cast_loc
= c_parser_peek_token (parser
)->location
;
5653 gcc_assert (!after
|| c_dialect_objc ());
5655 return c_parser_postfix_expression_after_primary (parser
,
5657 /* If the expression begins with a parenthesized type name, it may
5658 be either a cast or a compound literal; we need to see whether
5659 the next character is '{' to tell the difference. If not, it is
5660 an unary expression. Full detection of unknown typenames here
5661 would require a 3-token lookahead. */
5662 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
5663 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
5665 struct c_type_name
*type_name
;
5668 c_parser_consume_token (parser
);
5669 type_name
= c_parser_type_name (parser
);
5670 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5671 if (type_name
== NULL
)
5673 ret
.value
= error_mark_node
;
5674 ret
.original_code
= ERROR_MARK
;
5675 ret
.original_type
= NULL
;
5679 /* Save casted types in the function's used types hash table. */
5680 used_types_insert (type_name
->specs
->type
);
5682 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5683 return c_parser_postfix_expression_after_paren_type (parser
, type_name
,
5686 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
5687 expr
= c_parser_cast_expression (parser
, NULL
);
5688 expr
= default_function_array_read_conversion (expr_loc
, expr
);
5690 ret
.value
= c_cast_expr (cast_loc
, type_name
, expr
.value
);
5691 ret
.original_code
= ERROR_MARK
;
5692 ret
.original_type
= NULL
;
5696 return c_parser_unary_expression (parser
);
5699 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
5705 unary-operator cast-expression
5706 sizeof unary-expression
5707 sizeof ( type-name )
5709 unary-operator: one of
5715 __alignof__ unary-expression
5716 __alignof__ ( type-name )
5719 unary-operator: one of
5720 __extension__ __real__ __imag__
5722 In addition, the GNU syntax treats ++ and -- as unary operators, so
5723 they may be applied to cast expressions with errors for non-lvalues
5726 static struct c_expr
5727 c_parser_unary_expression (c_parser
*parser
)
5730 struct c_expr ret
, op
;
5731 location_t op_loc
= c_parser_peek_token (parser
)->location
;
5733 ret
.original_code
= ERROR_MARK
;
5734 ret
.original_type
= NULL
;
5735 switch (c_parser_peek_token (parser
)->type
)
5738 c_parser_consume_token (parser
);
5739 exp_loc
= c_parser_peek_token (parser
)->location
;
5740 op
= c_parser_cast_expression (parser
, NULL
);
5741 op
= default_function_array_read_conversion (exp_loc
, op
);
5742 return parser_build_unary_op (op_loc
, PREINCREMENT_EXPR
, op
);
5743 case CPP_MINUS_MINUS
:
5744 c_parser_consume_token (parser
);
5745 exp_loc
= c_parser_peek_token (parser
)->location
;
5746 op
= c_parser_cast_expression (parser
, NULL
);
5747 op
= default_function_array_read_conversion (exp_loc
, op
);
5748 return parser_build_unary_op (op_loc
, PREDECREMENT_EXPR
, op
);
5750 c_parser_consume_token (parser
);
5751 op
= c_parser_cast_expression (parser
, NULL
);
5752 mark_exp_read (op
.value
);
5753 return parser_build_unary_op (op_loc
, ADDR_EXPR
, op
);
5755 c_parser_consume_token (parser
);
5756 exp_loc
= c_parser_peek_token (parser
)->location
;
5757 op
= c_parser_cast_expression (parser
, NULL
);
5758 op
= default_function_array_read_conversion (exp_loc
, op
);
5759 ret
.value
= build_indirect_ref (op_loc
, op
.value
, RO_UNARY_STAR
);
5762 if (!c_dialect_objc () && !in_system_header
)
5765 "traditional C rejects the unary plus operator");
5766 c_parser_consume_token (parser
);
5767 exp_loc
= c_parser_peek_token (parser
)->location
;
5768 op
= c_parser_cast_expression (parser
, NULL
);
5769 op
= default_function_array_read_conversion (exp_loc
, op
);
5770 return parser_build_unary_op (op_loc
, CONVERT_EXPR
, op
);
5772 c_parser_consume_token (parser
);
5773 exp_loc
= c_parser_peek_token (parser
)->location
;
5774 op
= c_parser_cast_expression (parser
, NULL
);
5775 op
= default_function_array_read_conversion (exp_loc
, op
);
5776 return parser_build_unary_op (op_loc
, NEGATE_EXPR
, op
);
5778 c_parser_consume_token (parser
);
5779 exp_loc
= c_parser_peek_token (parser
)->location
;
5780 op
= c_parser_cast_expression (parser
, NULL
);
5781 op
= default_function_array_read_conversion (exp_loc
, op
);
5782 return parser_build_unary_op (op_loc
, BIT_NOT_EXPR
, op
);
5784 c_parser_consume_token (parser
);
5785 exp_loc
= c_parser_peek_token (parser
)->location
;
5786 op
= c_parser_cast_expression (parser
, NULL
);
5787 op
= default_function_array_read_conversion (exp_loc
, op
);
5788 return parser_build_unary_op (op_loc
, TRUTH_NOT_EXPR
, op
);
5790 /* Refer to the address of a label as a pointer. */
5791 c_parser_consume_token (parser
);
5792 if (c_parser_next_token_is (parser
, CPP_NAME
))
5794 ret
.value
= finish_label_address_expr
5795 (c_parser_peek_token (parser
)->value
, op_loc
);
5796 c_parser_consume_token (parser
);
5800 c_parser_error (parser
, "expected identifier");
5801 ret
.value
= error_mark_node
;
5805 switch (c_parser_peek_token (parser
)->keyword
)
5808 return c_parser_sizeof_expression (parser
);
5810 return c_parser_alignof_expression (parser
);
5812 c_parser_consume_token (parser
);
5813 ext
= disable_extension_diagnostics ();
5814 ret
= c_parser_cast_expression (parser
, NULL
);
5815 restore_extension_diagnostics (ext
);
5818 c_parser_consume_token (parser
);
5819 exp_loc
= c_parser_peek_token (parser
)->location
;
5820 op
= c_parser_cast_expression (parser
, NULL
);
5821 op
= default_function_array_conversion (exp_loc
, op
);
5822 return parser_build_unary_op (op_loc
, REALPART_EXPR
, op
);
5824 c_parser_consume_token (parser
);
5825 exp_loc
= c_parser_peek_token (parser
)->location
;
5826 op
= c_parser_cast_expression (parser
, NULL
);
5827 op
= default_function_array_conversion (exp_loc
, op
);
5828 return parser_build_unary_op (op_loc
, IMAGPART_EXPR
, op
);
5830 return c_parser_postfix_expression (parser
);
5833 return c_parser_postfix_expression (parser
);
5837 /* Parse a sizeof expression. */
5839 static struct c_expr
5840 c_parser_sizeof_expression (c_parser
*parser
)
5843 location_t expr_loc
;
5844 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SIZEOF
));
5845 c_parser_consume_token (parser
);
5846 c_inhibit_evaluation_warnings
++;
5848 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
5849 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
5851 /* Either sizeof ( type-name ) or sizeof unary-expression
5852 starting with a compound literal. */
5853 struct c_type_name
*type_name
;
5854 c_parser_consume_token (parser
);
5855 expr_loc
= c_parser_peek_token (parser
)->location
;
5856 type_name
= c_parser_type_name (parser
);
5857 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5858 if (type_name
== NULL
)
5861 c_inhibit_evaluation_warnings
--;
5863 ret
.value
= error_mark_node
;
5864 ret
.original_code
= ERROR_MARK
;
5865 ret
.original_type
= NULL
;
5868 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5870 expr
= c_parser_postfix_expression_after_paren_type (parser
,
5875 /* sizeof ( type-name ). */
5876 c_inhibit_evaluation_warnings
--;
5878 return c_expr_sizeof_type (expr_loc
, type_name
);
5882 expr_loc
= c_parser_peek_token (parser
)->location
;
5883 expr
= c_parser_unary_expression (parser
);
5885 c_inhibit_evaluation_warnings
--;
5887 mark_exp_read (expr
.value
);
5888 if (TREE_CODE (expr
.value
) == COMPONENT_REF
5889 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
5890 error_at (expr_loc
, "%<sizeof%> applied to a bit-field");
5891 return c_expr_sizeof_expr (expr_loc
, expr
);
5895 /* Parse an alignof expression. */
5897 static struct c_expr
5898 c_parser_alignof_expression (c_parser
*parser
)
5901 location_t loc
= c_parser_peek_token (parser
)->location
;
5902 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNOF
));
5903 c_parser_consume_token (parser
);
5904 c_inhibit_evaluation_warnings
++;
5906 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
5907 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
5909 /* Either __alignof__ ( type-name ) or __alignof__
5910 unary-expression starting with a compound literal. */
5912 struct c_type_name
*type_name
;
5914 c_parser_consume_token (parser
);
5915 loc
= c_parser_peek_token (parser
)->location
;
5916 type_name
= c_parser_type_name (parser
);
5917 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5918 if (type_name
== NULL
)
5921 c_inhibit_evaluation_warnings
--;
5923 ret
.value
= error_mark_node
;
5924 ret
.original_code
= ERROR_MARK
;
5925 ret
.original_type
= NULL
;
5928 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5930 expr
= c_parser_postfix_expression_after_paren_type (parser
,
5935 /* alignof ( type-name ). */
5936 c_inhibit_evaluation_warnings
--;
5938 ret
.value
= c_alignof (loc
, groktypename (type_name
, NULL
, NULL
));
5939 ret
.original_code
= ERROR_MARK
;
5940 ret
.original_type
= NULL
;
5946 expr
= c_parser_unary_expression (parser
);
5948 mark_exp_read (expr
.value
);
5949 c_inhibit_evaluation_warnings
--;
5951 ret
.value
= c_alignof_expr (loc
, expr
.value
);
5952 ret
.original_code
= ERROR_MARK
;
5953 ret
.original_type
= NULL
;
5958 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
5962 postfix-expression [ expression ]
5963 postfix-expression ( argument-expression-list[opt] )
5964 postfix-expression . identifier
5965 postfix-expression -> identifier
5966 postfix-expression ++
5967 postfix-expression --
5968 ( type-name ) { initializer-list }
5969 ( type-name ) { initializer-list , }
5971 argument-expression-list:
5973 argument-expression-list , argument-expression
5985 (treated as a keyword in GNU C)
5988 ( compound-statement )
5989 __builtin_va_arg ( assignment-expression , type-name )
5990 __builtin_offsetof ( type-name , offsetof-member-designator )
5991 __builtin_choose_expr ( assignment-expression ,
5992 assignment-expression ,
5993 assignment-expression )
5994 __builtin_types_compatible_p ( type-name , type-name )
5996 offsetof-member-designator:
5998 offsetof-member-designator . identifier
5999 offsetof-member-designator [ expression ]
6004 [ objc-receiver objc-message-args ]
6005 @selector ( objc-selector-arg )
6006 @protocol ( identifier )
6007 @encode ( type-name )
6009 Classname . identifier
6012 static struct c_expr
6013 c_parser_postfix_expression (c_parser
*parser
)
6015 struct c_expr expr
, e1
, e2
, e3
;
6016 struct c_type_name
*t1
, *t2
;
6017 location_t loc
= c_parser_peek_token (parser
)->location
;;
6018 expr
.original_code
= ERROR_MARK
;
6019 expr
.original_type
= NULL
;
6020 switch (c_parser_peek_token (parser
)->type
)
6023 expr
.value
= c_parser_peek_token (parser
)->value
;
6024 loc
= c_parser_peek_token (parser
)->location
;
6025 c_parser_consume_token (parser
);
6026 if (TREE_CODE (expr
.value
) == FIXED_CST
6027 && !targetm
.fixed_point_supported_p ())
6029 error_at (loc
, "fixed-point types not supported for this target");
6030 expr
.value
= error_mark_node
;
6037 expr
.value
= c_parser_peek_token (parser
)->value
;
6038 c_parser_consume_token (parser
);
6044 case CPP_UTF8STRING
:
6045 expr
.value
= c_parser_peek_token (parser
)->value
;
6046 expr
.original_code
= STRING_CST
;
6047 c_parser_consume_token (parser
);
6049 case CPP_OBJC_STRING
:
6050 gcc_assert (c_dialect_objc ());
6052 = objc_build_string_object (c_parser_peek_token (parser
)->value
);
6053 c_parser_consume_token (parser
);
6056 switch (c_parser_peek_token (parser
)->id_kind
)
6060 tree id
= c_parser_peek_token (parser
)->value
;
6061 c_parser_consume_token (parser
);
6062 expr
.value
= build_external_ref (loc
, id
,
6063 (c_parser_peek_token (parser
)->type
6065 &expr
.original_type
);
6068 case C_ID_CLASSNAME
:
6070 /* Here we parse the Objective-C 2.0 Class.name dot
6072 tree class_name
= c_parser_peek_token (parser
)->value
;
6074 c_parser_consume_token (parser
);
6075 gcc_assert (c_dialect_objc ());
6076 if (!c_parser_require (parser
, CPP_DOT
, "expected %<.%>"))
6078 expr
.value
= error_mark_node
;
6081 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6083 c_parser_error (parser
, "expected identifier");
6084 expr
.value
= error_mark_node
;
6087 component
= c_parser_peek_token (parser
)->value
;
6088 c_parser_consume_token (parser
);
6089 expr
.value
= objc_build_class_component_ref (class_name
,
6094 c_parser_error (parser
, "expected expression");
6095 expr
.value
= error_mark_node
;
6099 case CPP_OPEN_PAREN
:
6100 /* A parenthesized expression, statement expression or compound
6102 if (c_parser_peek_2nd_token (parser
)->type
== CPP_OPEN_BRACE
)
6104 /* A statement expression. */
6106 location_t brace_loc
;
6107 c_parser_consume_token (parser
);
6108 brace_loc
= c_parser_peek_token (parser
)->location
;
6109 c_parser_consume_token (parser
);
6110 if (cur_stmt_list
== NULL
)
6112 error_at (loc
, "braced-group within expression allowed "
6113 "only inside a function");
6114 parser
->error
= true;
6115 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
6116 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6117 expr
.value
= error_mark_node
;
6120 stmt
= c_begin_stmt_expr ();
6121 c_parser_compound_statement_nostart (parser
);
6122 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6124 pedwarn (loc
, OPT_pedantic
,
6125 "ISO C forbids braced-groups within expressions");
6126 expr
.value
= c_finish_stmt_expr (brace_loc
, stmt
);
6127 mark_exp_read (expr
.value
);
6129 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6131 /* A compound literal. ??? Can we actually get here rather
6132 than going directly to
6133 c_parser_postfix_expression_after_paren_type from
6136 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
,
6142 if (type_name
== NULL
)
6144 expr
.value
= error_mark_node
;
6147 expr
= c_parser_postfix_expression_after_paren_type (parser
,
6153 /* A parenthesized expression. */
6154 c_parser_consume_token (parser
);
6155 expr
= c_parser_expression (parser
);
6156 if (TREE_CODE (expr
.value
) == MODIFY_EXPR
)
6157 TREE_NO_WARNING (expr
.value
) = 1;
6158 if (expr
.original_code
!= C_MAYBE_CONST_EXPR
)
6159 expr
.original_code
= ERROR_MARK
;
6160 /* Don't change EXPR.ORIGINAL_TYPE. */
6161 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6166 switch (c_parser_peek_token (parser
)->keyword
)
6168 case RID_FUNCTION_NAME
:
6169 case RID_PRETTY_FUNCTION_NAME
:
6170 case RID_C99_FUNCTION_NAME
:
6171 expr
.value
= fname_decl (loc
,
6172 c_parser_peek_token (parser
)->keyword
,
6173 c_parser_peek_token (parser
)->value
);
6174 c_parser_consume_token (parser
);
6177 c_parser_consume_token (parser
);
6178 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6180 expr
.value
= error_mark_node
;
6183 e1
= c_parser_expr_no_commas (parser
, NULL
);
6184 mark_exp_read (e1
.value
);
6185 e1
.value
= c_fully_fold (e1
.value
, false, NULL
);
6186 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
6188 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6189 expr
.value
= error_mark_node
;
6192 loc
= c_parser_peek_token (parser
)->location
;
6193 t1
= c_parser_type_name (parser
);
6194 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6198 expr
.value
= error_mark_node
;
6202 tree type_expr
= NULL_TREE
;
6203 expr
.value
= c_build_va_arg (loc
, e1
.value
,
6204 groktypename (t1
, &type_expr
, NULL
));
6207 expr
.value
= build2 (C_MAYBE_CONST_EXPR
,
6208 TREE_TYPE (expr
.value
), type_expr
,
6210 C_MAYBE_CONST_EXPR_NON_CONST (expr
.value
) = true;
6215 c_parser_consume_token (parser
);
6216 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6218 expr
.value
= error_mark_node
;
6221 t1
= c_parser_type_name (parser
);
6223 parser
->error
= true;
6224 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
6225 gcc_assert (parser
->error
);
6228 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6229 expr
.value
= error_mark_node
;
6234 tree type
= groktypename (t1
, NULL
, NULL
);
6236 if (type
== error_mark_node
)
6237 offsetof_ref
= error_mark_node
;
6240 offsetof_ref
= build1 (INDIRECT_REF
, type
, null_pointer_node
);
6241 SET_EXPR_LOCATION (offsetof_ref
, loc
);
6243 /* Parse the second argument to __builtin_offsetof. We
6244 must have one identifier, and beyond that we want to
6245 accept sub structure and sub array references. */
6246 if (c_parser_next_token_is (parser
, CPP_NAME
))
6248 offsetof_ref
= build_component_ref
6249 (loc
, offsetof_ref
, c_parser_peek_token (parser
)->value
);
6250 c_parser_consume_token (parser
);
6251 while (c_parser_next_token_is (parser
, CPP_DOT
)
6252 || c_parser_next_token_is (parser
,
6254 || c_parser_next_token_is (parser
,
6257 if (c_parser_next_token_is (parser
, CPP_DEREF
))
6259 loc
= c_parser_peek_token (parser
)->location
;
6260 offsetof_ref
= build_array_ref (loc
,
6265 else if (c_parser_next_token_is (parser
, CPP_DOT
))
6268 c_parser_consume_token (parser
);
6269 if (c_parser_next_token_is_not (parser
,
6272 c_parser_error (parser
, "expected identifier");
6275 offsetof_ref
= build_component_ref
6277 c_parser_peek_token (parser
)->value
);
6278 c_parser_consume_token (parser
);
6283 loc
= c_parser_peek_token (parser
)->location
;
6284 c_parser_consume_token (parser
);
6285 idx
= c_parser_expression (parser
).value
;
6286 idx
= c_fully_fold (idx
, false, NULL
);
6287 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
6289 offsetof_ref
= build_array_ref (loc
, offsetof_ref
, idx
);
6294 c_parser_error (parser
, "expected identifier");
6295 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6297 expr
.value
= fold_offsetof (offsetof_ref
, NULL_TREE
);
6300 case RID_CHOOSE_EXPR
:
6301 c_parser_consume_token (parser
);
6302 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6304 expr
.value
= error_mark_node
;
6307 loc
= c_parser_peek_token (parser
)->location
;
6308 e1
= c_parser_expr_no_commas (parser
, NULL
);
6309 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
6311 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6312 expr
.value
= error_mark_node
;
6315 e2
= c_parser_expr_no_commas (parser
, NULL
);
6316 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
6318 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6319 expr
.value
= error_mark_node
;
6322 e3
= c_parser_expr_no_commas (parser
, NULL
);
6323 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6329 mark_exp_read (e2
.value
);
6330 mark_exp_read (e3
.value
);
6331 if (TREE_CODE (c
) != INTEGER_CST
6332 || !INTEGRAL_TYPE_P (TREE_TYPE (c
)))
6334 "first argument to %<__builtin_choose_expr%> not"
6336 constant_expression_warning (c
);
6337 expr
= integer_zerop (c
) ? e3
: e2
;
6340 case RID_TYPES_COMPATIBLE_P
:
6341 c_parser_consume_token (parser
);
6342 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6344 expr
.value
= error_mark_node
;
6347 t1
= c_parser_type_name (parser
);
6350 expr
.value
= error_mark_node
;
6353 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
6355 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6356 expr
.value
= error_mark_node
;
6359 t2
= c_parser_type_name (parser
);
6362 expr
.value
= error_mark_node
;
6365 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6370 e1
= TYPE_MAIN_VARIANT (groktypename (t1
, NULL
, NULL
));
6371 e2
= TYPE_MAIN_VARIANT (groktypename (t2
, NULL
, NULL
));
6374 = comptypes (e1
, e2
) ? integer_one_node
: integer_zero_node
;
6377 case RID_AT_SELECTOR
:
6378 gcc_assert (c_dialect_objc ());
6379 c_parser_consume_token (parser
);
6380 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6382 expr
.value
= error_mark_node
;
6386 tree sel
= c_parser_objc_selector_arg (parser
);
6387 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6389 expr
.value
= objc_build_selector_expr (loc
, sel
);
6392 case RID_AT_PROTOCOL
:
6393 gcc_assert (c_dialect_objc ());
6394 c_parser_consume_token (parser
);
6395 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6397 expr
.value
= error_mark_node
;
6400 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6402 c_parser_error (parser
, "expected identifier");
6403 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6404 expr
.value
= error_mark_node
;
6408 tree id
= c_parser_peek_token (parser
)->value
;
6409 c_parser_consume_token (parser
);
6410 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6412 expr
.value
= objc_build_protocol_expr (id
);
6416 /* Extension to support C-structures in the archiver. */
6417 gcc_assert (c_dialect_objc ());
6418 c_parser_consume_token (parser
);
6419 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6421 expr
.value
= error_mark_node
;
6424 t1
= c_parser_type_name (parser
);
6427 expr
.value
= error_mark_node
;
6428 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6431 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6434 tree type
= groktypename (t1
, NULL
, NULL
);
6435 expr
.value
= objc_build_encode_expr (type
);
6439 c_parser_error (parser
, "expected expression");
6440 expr
.value
= error_mark_node
;
6444 case CPP_OPEN_SQUARE
:
6445 if (c_dialect_objc ())
6447 tree receiver
, args
;
6448 c_parser_consume_token (parser
);
6449 receiver
= c_parser_objc_receiver (parser
);
6450 args
= c_parser_objc_message_args (parser
);
6451 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
6453 expr
.value
= objc_build_message_expr (build_tree_list (receiver
,
6457 /* Else fall through to report error. */
6459 c_parser_error (parser
, "expected expression");
6460 expr
.value
= error_mark_node
;
6463 return c_parser_postfix_expression_after_primary (parser
, loc
, expr
);
6466 /* Parse a postfix expression after a parenthesized type name: the
6467 brace-enclosed initializer of a compound literal, possibly followed
6468 by some postfix operators. This is separate because it is not
6469 possible to tell until after the type name whether a cast
6470 expression has a cast or a compound literal, or whether the operand
6471 of sizeof is a parenthesized type name or starts with a compound
6472 literal. TYPE_LOC is the location where TYPE_NAME starts--the
6473 location of the first token after the parentheses around the type
6476 static struct c_expr
6477 c_parser_postfix_expression_after_paren_type (c_parser
*parser
,
6478 struct c_type_name
*type_name
,
6479 location_t type_loc
)
6485 location_t start_loc
;
6486 tree type_expr
= NULL_TREE
;
6487 bool type_expr_const
= true;
6488 check_compound_literal_type (type_loc
, type_name
);
6489 start_init (NULL_TREE
, NULL
, 0);
6490 type
= groktypename (type_name
, &type_expr
, &type_expr_const
);
6491 start_loc
= c_parser_peek_token (parser
)->location
;
6492 if (type
!= error_mark_node
&& C_TYPE_VARIABLE_SIZE (type
))
6494 error_at (type_loc
, "compound literal has variable size");
6495 type
= error_mark_node
;
6497 init
= c_parser_braced_init (parser
, type
, false);
6499 maybe_warn_string_init (type
, init
);
6501 if (type
!= error_mark_node
6502 && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type
))
6503 && current_function_decl
)
6505 error ("compound literal qualified by address-space qualifier");
6506 type
= error_mark_node
;
6510 pedwarn (start_loc
, OPT_pedantic
, "ISO C90 forbids compound literals");
6511 non_const
= ((init
.value
&& TREE_CODE (init
.value
) == CONSTRUCTOR
)
6512 ? CONSTRUCTOR_NON_CONST (init
.value
)
6513 : init
.original_code
== C_MAYBE_CONST_EXPR
);
6514 non_const
|= !type_expr_const
;
6515 expr
.value
= build_compound_literal (start_loc
, type
, init
.value
, non_const
);
6516 expr
.original_code
= ERROR_MARK
;
6517 expr
.original_type
= NULL
;
6520 if (TREE_CODE (expr
.value
) == C_MAYBE_CONST_EXPR
)
6522 gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr
.value
) == NULL_TREE
);
6523 C_MAYBE_CONST_EXPR_PRE (expr
.value
) = type_expr
;
6527 gcc_assert (!non_const
);
6528 expr
.value
= build2 (C_MAYBE_CONST_EXPR
, type
,
6529 type_expr
, expr
.value
);
6532 return c_parser_postfix_expression_after_primary (parser
, start_loc
, expr
);
6535 /* Parse a postfix expression after the initial primary or compound
6536 literal; that is, parse a series of postfix operators.
6538 EXPR_LOC is the location of the primary expression. */
6540 static struct c_expr
6541 c_parser_postfix_expression_after_primary (c_parser
*parser
,
6542 location_t expr_loc
,
6545 struct c_expr orig_expr
;
6547 VEC(tree
,gc
) *exprlist
;
6548 VEC(tree
,gc
) *origtypes
;
6551 location_t op_loc
= c_parser_peek_token (parser
)->location
;
6552 switch (c_parser_peek_token (parser
)->type
)
6554 case CPP_OPEN_SQUARE
:
6555 /* Array reference. */
6556 c_parser_consume_token (parser
);
6557 idx
= c_parser_expression (parser
).value
;
6558 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
6560 expr
.value
= build_array_ref (op_loc
, expr
.value
, idx
);
6561 expr
.original_code
= ERROR_MARK
;
6562 expr
.original_type
= NULL
;
6564 case CPP_OPEN_PAREN
:
6565 /* Function call. */
6566 c_parser_consume_token (parser
);
6567 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
6570 exprlist
= c_parser_expr_list (parser
, true, false, &origtypes
);
6571 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6574 mark_exp_read (expr
.value
);
6575 /* FIXME diagnostics: Ideally we want the FUNCNAME, not the
6576 "(" after the FUNCNAME, which is what we have now. */
6577 expr
.value
= build_function_call_vec (op_loc
, expr
.value
, exprlist
,
6579 expr
.original_code
= ERROR_MARK
;
6580 if (TREE_CODE (expr
.value
) == INTEGER_CST
6581 && TREE_CODE (orig_expr
.value
) == FUNCTION_DECL
6582 && DECL_BUILT_IN_CLASS (orig_expr
.value
) == BUILT_IN_NORMAL
6583 && DECL_FUNCTION_CODE (orig_expr
.value
) == BUILT_IN_CONSTANT_P
)
6584 expr
.original_code
= C_MAYBE_CONST_EXPR
;
6585 expr
.original_type
= NULL
;
6586 if (exprlist
!= NULL
)
6588 release_tree_vector (exprlist
);
6589 release_tree_vector (origtypes
);
6593 /* Structure element reference. */
6594 c_parser_consume_token (parser
);
6595 expr
= default_function_array_conversion (expr_loc
, expr
);
6596 if (c_parser_next_token_is (parser
, CPP_NAME
))
6597 ident
= c_parser_peek_token (parser
)->value
;
6600 c_parser_error (parser
, "expected identifier");
6601 expr
.value
= error_mark_node
;
6602 expr
.original_code
= ERROR_MARK
;
6603 expr
.original_type
= NULL
;
6606 c_parser_consume_token (parser
);
6607 expr
.value
= build_component_ref (op_loc
, expr
.value
, ident
);
6608 expr
.original_code
= ERROR_MARK
;
6609 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
6610 expr
.original_type
= NULL
;
6613 /* Remember the original type of a bitfield. */
6614 tree field
= TREE_OPERAND (expr
.value
, 1);
6615 if (TREE_CODE (field
) != FIELD_DECL
)
6616 expr
.original_type
= NULL
;
6618 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
6622 /* Structure element reference. */
6623 c_parser_consume_token (parser
);
6624 expr
= default_function_array_conversion (expr_loc
, expr
);
6625 if (c_parser_next_token_is (parser
, CPP_NAME
))
6626 ident
= c_parser_peek_token (parser
)->value
;
6629 c_parser_error (parser
, "expected identifier");
6630 expr
.value
= error_mark_node
;
6631 expr
.original_code
= ERROR_MARK
;
6632 expr
.original_type
= NULL
;
6635 c_parser_consume_token (parser
);
6636 expr
.value
= build_component_ref (op_loc
,
6637 build_indirect_ref (op_loc
,
6641 expr
.original_code
= ERROR_MARK
;
6642 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
6643 expr
.original_type
= NULL
;
6646 /* Remember the original type of a bitfield. */
6647 tree field
= TREE_OPERAND (expr
.value
, 1);
6648 if (TREE_CODE (field
) != FIELD_DECL
)
6649 expr
.original_type
= NULL
;
6651 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
6655 /* Postincrement. */
6656 c_parser_consume_token (parser
);
6657 expr
= default_function_array_read_conversion (expr_loc
, expr
);
6658 expr
.value
= build_unary_op (op_loc
,
6659 POSTINCREMENT_EXPR
, expr
.value
, 0);
6660 expr
.original_code
= ERROR_MARK
;
6661 expr
.original_type
= NULL
;
6663 case CPP_MINUS_MINUS
:
6664 /* Postdecrement. */
6665 c_parser_consume_token (parser
);
6666 expr
= default_function_array_read_conversion (expr_loc
, expr
);
6667 expr
.value
= build_unary_op (op_loc
,
6668 POSTDECREMENT_EXPR
, expr
.value
, 0);
6669 expr
.original_code
= ERROR_MARK
;
6670 expr
.original_type
= NULL
;
6678 /* Parse an expression (C90 6.3.17, C99 6.5.17).
6681 assignment-expression
6682 expression , assignment-expression
6685 static struct c_expr
6686 c_parser_expression (c_parser
*parser
)
6689 expr
= c_parser_expr_no_commas (parser
, NULL
);
6690 while (c_parser_next_token_is (parser
, CPP_COMMA
))
6694 location_t loc
= c_parser_peek_token (parser
)->location
;
6695 location_t expr_loc
;
6696 c_parser_consume_token (parser
);
6697 expr_loc
= c_parser_peek_token (parser
)->location
;
6698 lhsval
= expr
.value
;
6699 while (TREE_CODE (lhsval
) == COMPOUND_EXPR
)
6700 lhsval
= TREE_OPERAND (lhsval
, 1);
6701 if (DECL_P (lhsval
) || handled_component_p (lhsval
))
6702 mark_exp_read (lhsval
);
6703 next
= c_parser_expr_no_commas (parser
, NULL
);
6704 next
= default_function_array_conversion (expr_loc
, next
);
6705 expr
.value
= build_compound_expr (loc
, expr
.value
, next
.value
);
6706 expr
.original_code
= COMPOUND_EXPR
;
6707 expr
.original_type
= next
.original_type
;
6712 /* Parse an expression and convert functions or arrays to
6715 static struct c_expr
6716 c_parser_expression_conv (c_parser
*parser
)
6719 location_t loc
= c_parser_peek_token (parser
)->location
;
6720 expr
= c_parser_expression (parser
);
6721 expr
= default_function_array_conversion (loc
, expr
);
6725 /* Parse a non-empty list of expressions. If CONVERT_P, convert
6726 functions and arrays to pointers. If FOLD_P, fold the expressions.
6729 assignment-expression
6730 nonempty-expr-list , assignment-expression
6733 static VEC(tree
,gc
) *
6734 c_parser_expr_list (c_parser
*parser
, bool convert_p
, bool fold_p
,
6735 VEC(tree
,gc
) **p_orig_types
)
6738 VEC(tree
,gc
) *orig_types
;
6740 location_t loc
= c_parser_peek_token (parser
)->location
;
6742 ret
= make_tree_vector ();
6743 if (p_orig_types
== NULL
)
6746 orig_types
= make_tree_vector ();
6748 expr
= c_parser_expr_no_commas (parser
, NULL
);
6750 expr
= default_function_array_read_conversion (loc
, expr
);
6752 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
6753 VEC_quick_push (tree
, ret
, expr
.value
);
6754 if (orig_types
!= NULL
)
6755 VEC_quick_push (tree
, orig_types
, expr
.original_type
);
6756 while (c_parser_next_token_is (parser
, CPP_COMMA
))
6758 c_parser_consume_token (parser
);
6759 loc
= c_parser_peek_token (parser
)->location
;
6760 expr
= c_parser_expr_no_commas (parser
, NULL
);
6762 expr
= default_function_array_read_conversion (loc
, expr
);
6764 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
6765 VEC_safe_push (tree
, gc
, ret
, expr
.value
);
6766 if (orig_types
!= NULL
)
6767 VEC_safe_push (tree
, gc
, orig_types
, expr
.original_type
);
6769 if (orig_types
!= NULL
)
6770 *p_orig_types
= orig_types
;
6774 /* Parse Objective-C-specific constructs. */
6776 /* Parse an objc-class-definition.
6778 objc-class-definition:
6779 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
6780 objc-class-instance-variables[opt] objc-methodprotolist @end
6781 @implementation identifier objc-superclass[opt]
6782 objc-class-instance-variables[opt]
6783 @interface identifier ( identifier ) objc-protocol-refs[opt]
6784 objc-methodprotolist @end
6785 @interface identifier ( ) objc-protocol-refs[opt]
6786 objc-methodprotolist @end
6787 @implementation identifier ( identifier )
6792 "@interface identifier (" must start "@interface identifier (
6793 identifier ) ...": objc-methodprotolist in the first production may
6794 not start with a parenthesized identifier as a declarator of a data
6795 definition with no declaration specifiers if the objc-superclass,
6796 objc-protocol-refs and objc-class-instance-variables are omitted. */
6799 c_parser_objc_class_definition (c_parser
*parser
, tree attributes
)
6804 if (c_parser_next_token_is_keyword (parser
, RID_AT_INTERFACE
))
6806 else if (c_parser_next_token_is_keyword (parser
, RID_AT_IMPLEMENTATION
))
6811 c_parser_consume_token (parser
);
6812 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6814 c_parser_error (parser
, "expected identifier");
6817 id1
= c_parser_peek_token (parser
)->value
;
6818 c_parser_consume_token (parser
);
6819 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
6821 /* We have a category or class extension. */
6823 tree proto
= NULL_TREE
;
6824 c_parser_consume_token (parser
);
6825 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6827 if (iface_p
&& c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
6829 /* We have a class extension. */
6834 c_parser_error (parser
, "expected identifier or %<)%>");
6835 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6841 id2
= c_parser_peek_token (parser
)->value
;
6842 c_parser_consume_token (parser
);
6844 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6847 objc_start_category_implementation (id1
, id2
);
6850 if (c_parser_next_token_is (parser
, CPP_LESS
))
6851 proto
= c_parser_objc_protocol_refs (parser
);
6852 objc_start_category_interface (id1
, id2
, proto
, attributes
);
6853 c_parser_objc_methodprotolist (parser
);
6854 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
6855 objc_finish_interface ();
6858 if (c_parser_next_token_is (parser
, CPP_COLON
))
6860 c_parser_consume_token (parser
);
6861 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6863 c_parser_error (parser
, "expected identifier");
6866 superclass
= c_parser_peek_token (parser
)->value
;
6867 c_parser_consume_token (parser
);
6870 superclass
= NULL_TREE
;
6873 tree proto
= NULL_TREE
;
6874 if (c_parser_next_token_is (parser
, CPP_LESS
))
6875 proto
= c_parser_objc_protocol_refs (parser
);
6876 objc_start_class_interface (id1
, superclass
, proto
, attributes
);
6879 objc_start_class_implementation (id1
, superclass
);
6880 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6881 c_parser_objc_class_instance_variables (parser
);
6884 objc_continue_interface ();
6885 c_parser_objc_methodprotolist (parser
);
6886 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
6887 objc_finish_interface ();
6891 objc_continue_implementation ();
6896 /* Parse objc-class-instance-variables.
6898 objc-class-instance-variables:
6899 { objc-instance-variable-decl-list[opt] }
6901 objc-instance-variable-decl-list:
6902 objc-visibility-spec
6903 objc-instance-variable-decl ;
6905 objc-instance-variable-decl-list objc-visibility-spec
6906 objc-instance-variable-decl-list objc-instance-variable-decl ;
6907 objc-instance-variable-decl-list ;
6909 objc-visibility-spec:
6914 objc-instance-variable-decl:
6919 c_parser_objc_class_instance_variables (c_parser
*parser
)
6921 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
6922 c_parser_consume_token (parser
);
6923 while (c_parser_next_token_is_not (parser
, CPP_EOF
))
6926 /* Parse any stray semicolon. */
6927 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
6929 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
6930 "extra semicolon in struct or union specified");
6931 c_parser_consume_token (parser
);
6934 /* Stop if at the end of the instance variables. */
6935 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
6937 c_parser_consume_token (parser
);
6940 /* Parse any objc-visibility-spec. */
6941 if (c_parser_next_token_is_keyword (parser
, RID_AT_PRIVATE
))
6943 c_parser_consume_token (parser
);
6944 objc_set_visibility (OBJC_IVAR_VIS_PRIVATE
);
6947 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROTECTED
))
6949 c_parser_consume_token (parser
);
6950 objc_set_visibility (OBJC_IVAR_VIS_PROTECTED
);
6953 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PUBLIC
))
6955 c_parser_consume_token (parser
);
6956 objc_set_visibility (OBJC_IVAR_VIS_PUBLIC
);
6959 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PACKAGE
))
6961 c_parser_consume_token (parser
);
6962 objc_set_visibility (OBJC_IVAR_VIS_PACKAGE
);
6965 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
6967 c_parser_pragma (parser
, pragma_external
);
6971 /* Parse some comma-separated declarations. */
6972 decls
= c_parser_struct_declaration (parser
);
6974 /* Comma-separated instance variables are chained together in
6975 reverse order; add them one by one. */
6976 tree ivar
= nreverse (decls
);
6977 for (; ivar
; ivar
= DECL_CHAIN (ivar
))
6978 objc_add_instance_variable (copy_node (ivar
));
6980 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
6984 /* Parse an objc-class-declaration.
6986 objc-class-declaration:
6987 @class identifier-list ;
6991 c_parser_objc_class_declaration (c_parser
*parser
)
6993 tree list
= NULL_TREE
;
6994 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_CLASS
));
6995 c_parser_consume_token (parser
);
6996 /* Any identifiers, including those declared as type names, are OK
7001 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7003 c_parser_error (parser
, "expected identifier");
7004 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
7005 parser
->error
= false;
7008 id
= c_parser_peek_token (parser
)->value
;
7009 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
7010 c_parser_consume_token (parser
);
7011 if (c_parser_next_token_is (parser
, CPP_COMMA
))
7012 c_parser_consume_token (parser
);
7016 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7017 objc_declare_class (list
);
7020 /* Parse an objc-alias-declaration.
7022 objc-alias-declaration:
7023 @compatibility_alias identifier identifier ;
7027 c_parser_objc_alias_declaration (c_parser
*parser
)
7030 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_ALIAS
));
7031 c_parser_consume_token (parser
);
7032 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7034 c_parser_error (parser
, "expected identifier");
7035 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
7038 id1
= c_parser_peek_token (parser
)->value
;
7039 c_parser_consume_token (parser
);
7040 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7042 c_parser_error (parser
, "expected identifier");
7043 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
7046 id2
= c_parser_peek_token (parser
)->value
;
7047 c_parser_consume_token (parser
);
7048 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7049 objc_declare_alias (id1
, id2
);
7052 /* Parse an objc-protocol-definition.
7054 objc-protocol-definition:
7055 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
7056 @protocol identifier-list ;
7058 "@protocol identifier ;" should be resolved as "@protocol
7059 identifier-list ;": objc-methodprotolist may not start with a
7060 semicolon in the first alternative if objc-protocol-refs are
7064 c_parser_objc_protocol_definition (c_parser
*parser
, tree attributes
)
7066 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROTOCOL
));
7068 c_parser_consume_token (parser
);
7069 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7071 c_parser_error (parser
, "expected identifier");
7074 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
7075 || c_parser_peek_2nd_token (parser
)->type
== CPP_SEMICOLON
)
7077 tree list
= NULL_TREE
;
7078 /* Any identifiers, including those declared as type names, are
7083 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7085 c_parser_error (parser
, "expected identifier");
7088 id
= c_parser_peek_token (parser
)->value
;
7089 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
7090 c_parser_consume_token (parser
);
7091 if (c_parser_next_token_is (parser
, CPP_COMMA
))
7092 c_parser_consume_token (parser
);
7096 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7097 objc_declare_protocols (list
, attributes
);
7101 tree id
= c_parser_peek_token (parser
)->value
;
7102 tree proto
= NULL_TREE
;
7103 c_parser_consume_token (parser
);
7104 if (c_parser_next_token_is (parser
, CPP_LESS
))
7105 proto
= c_parser_objc_protocol_refs (parser
);
7106 parser
->objc_pq_context
= true;
7107 objc_start_protocol (id
, proto
, attributes
);
7108 c_parser_objc_methodprotolist (parser
);
7109 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
7110 parser
->objc_pq_context
= false;
7111 objc_finish_interface ();
7115 /* Parse an objc-method-type.
7121 Return true if it is a class method (+) and false if it is
7122 an instance method (-).
7125 c_parser_objc_method_type (c_parser
*parser
)
7127 switch (c_parser_peek_token (parser
)->type
)
7130 c_parser_consume_token (parser
);
7133 c_parser_consume_token (parser
);
7140 /* Parse an objc-method-definition.
7142 objc-method-definition:
7143 objc-method-type objc-method-decl ;[opt] compound-statement
7147 c_parser_objc_method_definition (c_parser
*parser
)
7149 bool is_class_method
= c_parser_objc_method_type (parser
);
7150 tree decl
, attributes
= NULL_TREE
;
7151 parser
->objc_pq_context
= true;
7152 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
);
7153 if (decl
== error_mark_node
)
7154 return; /* Bail here. */
7156 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
7158 c_parser_consume_token (parser
);
7159 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
7160 "extra semicolon in method definition specified");
7163 if (!c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
7165 c_parser_error (parser
, "expected %<{%>");
7169 parser
->objc_pq_context
= false;
7170 if (objc_start_method_definition (is_class_method
, decl
, attributes
))
7172 add_stmt (c_parser_compound_statement (parser
));
7173 objc_finish_method_definition (current_function_decl
);
7177 /* This code is executed when we find a method definition
7178 outside of an @implementation context (or invalid for other
7179 reasons). Parse the method (to keep going) but do not emit
7182 c_parser_compound_statement (parser
);
7186 /* Parse an objc-methodprotolist.
7188 objc-methodprotolist:
7190 objc-methodprotolist objc-methodproto
7191 objc-methodprotolist declaration
7192 objc-methodprotolist ;
7196 The declaration is a data definition, which may be missing
7197 declaration specifiers under the same rules and diagnostics as
7198 other data definitions outside functions, and the stray semicolon
7199 is diagnosed the same way as a stray semicolon outside a
7203 c_parser_objc_methodprotolist (c_parser
*parser
)
7207 /* The list is terminated by @end. */
7208 switch (c_parser_peek_token (parser
)->type
)
7211 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
7212 "ISO C does not allow extra %<;%> outside of a function");
7213 c_parser_consume_token (parser
);
7217 c_parser_objc_methodproto (parser
);
7220 c_parser_pragma (parser
, pragma_external
);
7225 if (c_parser_next_token_is_keyword (parser
, RID_AT_END
))
7227 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
))
7228 c_parser_objc_at_property_declaration (parser
);
7229 else if (c_parser_next_token_is_keyword (parser
, RID_AT_OPTIONAL
))
7231 objc_set_method_opt (true);
7232 c_parser_consume_token (parser
);
7234 else if (c_parser_next_token_is_keyword (parser
, RID_AT_REQUIRED
))
7236 objc_set_method_opt (false);
7237 c_parser_consume_token (parser
);
7240 c_parser_declaration_or_fndef (parser
, false, false, true,
7247 /* Parse an objc-methodproto.
7250 objc-method-type objc-method-decl ;
7254 c_parser_objc_methodproto (c_parser
*parser
)
7256 bool is_class_method
= c_parser_objc_method_type (parser
);
7257 tree decl
, attributes
= NULL_TREE
;
7259 /* Remember protocol qualifiers in prototypes. */
7260 parser
->objc_pq_context
= true;
7261 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
);
7262 /* Forget protocol qualifiers now. */
7263 parser
->objc_pq_context
= false;
7265 /* Do not allow the presence of attributes to hide an erroneous
7266 method implementation in the interface section. */
7267 if (!c_parser_next_token_is (parser
, CPP_SEMICOLON
))
7269 c_parser_error (parser
, "expected %<;%>");
7273 if (decl
!= error_mark_node
)
7274 objc_add_method_declaration (is_class_method
, decl
, attributes
);
7276 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7279 /* If we are at a position that method attributes may be present, check that
7280 there are not any parsed already (a syntax error) and then collect any
7281 specified at the current location. Finally, if new attributes were present,
7282 check that the next token is legal ( ';' for decls and '{' for defs). */
7285 c_parser_objc_maybe_method_attributes (c_parser
* parser
, tree
* attributes
)
7290 c_parser_error (parser
,
7291 "method attributes must be specified at the end only");
7292 *attributes
= NULL_TREE
;
7296 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
7297 *attributes
= c_parser_attributes (parser
);
7299 /* If there were no attributes here, just report any earlier error. */
7300 if (*attributes
== NULL_TREE
|| bad
)
7303 /* If the attributes are followed by a ; or {, then just report any earlier
7305 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
7306 || c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
7309 /* We've got attributes, but not at the end. */
7310 c_parser_error (parser
,
7311 "expected %<;%> or %<{%> after method attribute definition");
7315 /* Parse an objc-method-decl.
7318 ( objc-type-name ) objc-selector
7320 ( objc-type-name ) objc-keyword-selector objc-optparmlist
7321 objc-keyword-selector objc-optparmlist
7324 objc-keyword-selector:
7326 objc-keyword-selector objc-keyword-decl
7329 objc-selector : ( objc-type-name ) identifier
7330 objc-selector : identifier
7331 : ( objc-type-name ) identifier
7335 objc-optparms objc-optellipsis
7339 objc-opt-parms , parameter-declaration
7347 c_parser_objc_method_decl (c_parser
*parser
, bool is_class_method
, tree
*attributes
)
7349 tree type
= NULL_TREE
;
7351 tree parms
= NULL_TREE
;
7352 bool ellipsis
= false;
7353 bool attr_err
= false;
7355 *attributes
= NULL_TREE
;
7356 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
7358 c_parser_consume_token (parser
);
7359 type
= c_parser_objc_type_name (parser
);
7360 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7362 sel
= c_parser_objc_selector (parser
);
7363 /* If there is no selector, or a colon follows, we have an
7364 objc-keyword-selector. If there is a selector, and a colon does
7365 not follow, that selector ends the objc-method-decl. */
7366 if (!sel
|| c_parser_next_token_is (parser
, CPP_COLON
))
7369 tree list
= NULL_TREE
;
7372 tree atype
= NULL_TREE
, id
, keyworddecl
;
7373 tree param_attr
= NULL_TREE
;
7374 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
7376 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
7378 c_parser_consume_token (parser
);
7379 atype
= c_parser_objc_type_name (parser
);
7380 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7383 /* New ObjC allows attributes on method parameters. */
7384 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
7385 param_attr
= c_parser_attributes (parser
);
7386 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7388 c_parser_error (parser
, "expected identifier");
7389 return error_mark_node
;
7391 id
= c_parser_peek_token (parser
)->value
;
7392 c_parser_consume_token (parser
);
7393 keyworddecl
= objc_build_keyword_decl (tsel
, atype
, id
, param_attr
);
7394 list
= chainon (list
, keyworddecl
);
7395 tsel
= c_parser_objc_selector (parser
);
7396 if (!tsel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
7400 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
7402 /* Parse the optional parameter list. Optional Objective-C
7403 method parameters follow the C syntax, and may include '...'
7404 to denote a variable number of arguments. */
7405 parms
= make_node (TREE_LIST
);
7406 while (c_parser_next_token_is (parser
, CPP_COMMA
))
7408 struct c_parm
*parm
;
7409 c_parser_consume_token (parser
);
7410 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
7413 c_parser_consume_token (parser
);
7414 attr_err
|= c_parser_objc_maybe_method_attributes
7415 (parser
, attributes
) ;
7418 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
7421 parms
= chainon (parms
,
7422 build_tree_list (NULL_TREE
, grokparm (parm
)));
7427 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
7431 c_parser_error (parser
, "objective-c method declaration is expected");
7432 return error_mark_node
;
7436 return error_mark_node
;
7438 return objc_build_method_signature (is_class_method
, type
, sel
, parms
, ellipsis
);
7441 /* Parse an objc-type-name.
7444 objc-type-qualifiers[opt] type-name
7445 objc-type-qualifiers[opt]
7447 objc-type-qualifiers:
7449 objc-type-qualifiers objc-type-qualifier
7451 objc-type-qualifier: one of
7452 in out inout bycopy byref oneway
7456 c_parser_objc_type_name (c_parser
*parser
)
7458 tree quals
= NULL_TREE
;
7459 struct c_type_name
*type_name
= NULL
;
7460 tree type
= NULL_TREE
;
7463 c_token
*token
= c_parser_peek_token (parser
);
7464 if (token
->type
== CPP_KEYWORD
7465 && (token
->keyword
== RID_IN
7466 || token
->keyword
== RID_OUT
7467 || token
->keyword
== RID_INOUT
7468 || token
->keyword
== RID_BYCOPY
7469 || token
->keyword
== RID_BYREF
7470 || token
->keyword
== RID_ONEWAY
))
7472 quals
= chainon (build_tree_list (NULL_TREE
, token
->value
), quals
);
7473 c_parser_consume_token (parser
);
7478 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
7479 type_name
= c_parser_type_name (parser
);
7481 type
= groktypename (type_name
, NULL
, NULL
);
7483 /* If the type is unknown, and error has already been produced and
7484 we need to recover from the error. In that case, use NULL_TREE
7485 for the type, as if no type had been specified; this will use the
7486 default type ('id') which is good for error recovery. */
7487 if (type
== error_mark_node
)
7490 return build_tree_list (quals
, type
);
7493 /* Parse objc-protocol-refs.
7500 c_parser_objc_protocol_refs (c_parser
*parser
)
7502 tree list
= NULL_TREE
;
7503 gcc_assert (c_parser_next_token_is (parser
, CPP_LESS
));
7504 c_parser_consume_token (parser
);
7505 /* Any identifiers, including those declared as type names, are OK
7510 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7512 c_parser_error (parser
, "expected identifier");
7515 id
= c_parser_peek_token (parser
)->value
;
7516 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
7517 c_parser_consume_token (parser
);
7518 if (c_parser_next_token_is (parser
, CPP_COMMA
))
7519 c_parser_consume_token (parser
);
7523 c_parser_require (parser
, CPP_GREATER
, "expected %<>%>");
7527 /* Parse an objc-try-catch-finally-statement.
7529 objc-try-catch-finally-statement:
7530 @try compound-statement objc-catch-list[opt]
7531 @try compound-statement objc-catch-list[opt] @finally compound-statement
7534 @catch ( objc-catch-parameter-declaration ) compound-statement
7535 objc-catch-list @catch ( objc-catch-parameter-declaration ) compound-statement
7537 objc-catch-parameter-declaration:
7538 parameter-declaration
7541 where '...' is to be interpreted literally, that is, it means CPP_ELLIPSIS.
7543 PS: This function is identical to cp_parser_objc_try_catch_finally_statement
7544 for C++. Keep them in sync. */
7547 c_parser_objc_try_catch_finally_statement (c_parser
*parser
)
7549 location_t location
;
7552 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_TRY
));
7553 c_parser_consume_token (parser
);
7554 location
= c_parser_peek_token (parser
)->location
;
7555 objc_maybe_warn_exceptions (location
);
7556 stmt
= c_parser_compound_statement (parser
);
7557 objc_begin_try_stmt (location
, stmt
);
7559 while (c_parser_next_token_is_keyword (parser
, RID_AT_CATCH
))
7561 struct c_parm
*parm
;
7562 tree parameter_declaration
= error_mark_node
;
7563 bool seen_open_paren
= false;
7565 c_parser_consume_token (parser
);
7566 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7567 seen_open_paren
= true;
7568 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
7570 /* We have "@catch (...)" (where the '...' are literally
7571 what is in the code). Skip the '...'.
7572 parameter_declaration is set to NULL_TREE, and
7573 objc_being_catch_clauses() knows that that means
7575 c_parser_consume_token (parser
);
7576 parameter_declaration
= NULL_TREE
;
7580 /* We have "@catch (NSException *exception)" or something
7581 like that. Parse the parameter declaration. */
7582 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
7584 parameter_declaration
= error_mark_node
;
7586 parameter_declaration
= grokparm (parm
);
7588 if (seen_open_paren
)
7589 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7592 /* If there was no open parenthesis, we are recovering from
7593 an error, and we are trying to figure out what mistake
7594 the user has made. */
7596 /* If there is an immediate closing parenthesis, the user
7597 probably forgot the opening one (ie, they typed "@catch
7598 NSException *e)". Parse the closing parenthesis and keep
7600 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
7601 c_parser_consume_token (parser
);
7603 /* If these is no immediate closing parenthesis, the user
7604 probably doesn't know that parenthesis are required at
7605 all (ie, they typed "@catch NSException *e"). So, just
7606 forget about the closing parenthesis and keep going. */
7608 objc_begin_catch_clause (parameter_declaration
);
7609 if (c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
7610 c_parser_compound_statement_nostart (parser
);
7611 objc_finish_catch_clause ();
7613 if (c_parser_next_token_is_keyword (parser
, RID_AT_FINALLY
))
7615 c_parser_consume_token (parser
);
7616 location
= c_parser_peek_token (parser
)->location
;
7617 stmt
= c_parser_compound_statement (parser
);
7618 objc_build_finally_clause (location
, stmt
);
7620 objc_finish_try_stmt ();
7623 /* Parse an objc-synchronized-statement.
7625 objc-synchronized-statement:
7626 @synchronized ( expression ) compound-statement
7630 c_parser_objc_synchronized_statement (c_parser
*parser
)
7634 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNCHRONIZED
));
7635 c_parser_consume_token (parser
);
7636 loc
= c_parser_peek_token (parser
)->location
;
7637 objc_maybe_warn_exceptions (loc
);
7638 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7640 expr
= c_parser_expression (parser
).value
;
7641 expr
= c_fully_fold (expr
, false, NULL
);
7642 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7645 expr
= error_mark_node
;
7646 stmt
= c_parser_compound_statement (parser
);
7647 objc_build_synchronized (loc
, expr
, stmt
);
7650 /* Parse an objc-selector; return NULL_TREE without an error if the
7651 next token is not an objc-selector.
7656 enum struct union if else while do for switch case default
7657 break continue return goto asm sizeof typeof __alignof
7658 unsigned long const short volatile signed restrict _Complex
7659 in out inout bycopy byref oneway int char float double void _Bool
7661 ??? Why this selection of keywords but not, for example, storage
7662 class specifiers? */
7665 c_parser_objc_selector (c_parser
*parser
)
7667 c_token
*token
= c_parser_peek_token (parser
);
7668 tree value
= token
->value
;
7669 if (token
->type
== CPP_NAME
)
7671 c_parser_consume_token (parser
);
7674 if (token
->type
!= CPP_KEYWORD
)
7676 switch (token
->keyword
)
7718 c_parser_consume_token (parser
);
7725 /* Parse an objc-selector-arg.
7729 objc-keywordname-list
7731 objc-keywordname-list:
7733 objc-keywordname-list objc-keywordname
7741 c_parser_objc_selector_arg (c_parser
*parser
)
7743 tree sel
= c_parser_objc_selector (parser
);
7744 tree list
= NULL_TREE
;
7745 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
7749 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
7751 list
= chainon (list
, build_tree_list (sel
, NULL_TREE
));
7752 sel
= c_parser_objc_selector (parser
);
7753 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
7759 /* Parse an objc-receiver.
7768 c_parser_objc_receiver (c_parser
*parser
)
7770 if (c_parser_peek_token (parser
)->type
== CPP_NAME
7771 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
7772 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
7774 tree id
= c_parser_peek_token (parser
)->value
;
7775 c_parser_consume_token (parser
);
7776 return objc_get_class_reference (id
);
7778 return c_fully_fold (c_parser_expression (parser
).value
, false, NULL
);
7781 /* Parse objc-message-args.
7785 objc-keywordarg-list
7787 objc-keywordarg-list:
7789 objc-keywordarg-list objc-keywordarg
7792 objc-selector : objc-keywordexpr
7797 c_parser_objc_message_args (c_parser
*parser
)
7799 tree sel
= c_parser_objc_selector (parser
);
7800 tree list
= NULL_TREE
;
7801 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
7806 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
7807 return error_mark_node
;
7808 keywordexpr
= c_parser_objc_keywordexpr (parser
);
7809 list
= chainon (list
, build_tree_list (sel
, keywordexpr
));
7810 sel
= c_parser_objc_selector (parser
);
7811 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
7817 /* Parse an objc-keywordexpr.
7824 c_parser_objc_keywordexpr (c_parser
*parser
)
7827 VEC(tree
,gc
) *expr_list
= c_parser_expr_list (parser
, true, true, NULL
);
7828 if (VEC_length (tree
, expr_list
) == 1)
7830 /* Just return the expression, remove a level of
7832 ret
= VEC_index (tree
, expr_list
, 0);
7836 /* We have a comma expression, we will collapse later. */
7837 ret
= build_tree_list_vec (expr_list
);
7839 release_tree_vector (expr_list
);
7843 /* A check, needed in several places, that ObjC interface, implementation or
7844 method definitions are not prefixed by incorrect items. */
7846 c_parser_objc_diagnose_bad_element_prefix (c_parser
*parser
,
7847 struct c_declspecs
*specs
)
7849 if (!specs
->declspecs_seen_p
|| specs
->non_sc_seen_p
7850 || specs
->typespec_kind
!= ctsk_none
)
7852 c_parser_error (parser
,
7853 "no type or storage class may be specified here,");
7854 c_parser_skip_to_end_of_block_or_statement (parser
);
7860 /* Parse an Objective-C @property declaration. The syntax is:
7862 objc-property-declaration:
7863 '@property' objc-property-attributes[opt] struct-declaration ;
7865 objc-property-attributes:
7866 '(' objc-property-attribute-list ')'
7868 objc-property-attribute-list:
7869 objc-property-attribute
7870 objc-property-attribute-list, objc-property-attribute
7872 objc-property-attribute
7873 'getter' = identifier
7874 'setter' = identifier
7883 @property NSString *name;
7884 @property (readonly) id object;
7885 @property (retain, nonatomic, getter=getTheName) id name;
7886 @property int a, b, c;
7888 PS: This function is identical to cp_parser_objc_at_propery_declaration
7889 for C++. Keep them in sync. */
7891 c_parser_objc_at_property_declaration (c_parser
*parser
)
7893 /* The following variables hold the attributes of the properties as
7894 parsed. They are 'false' or 'NULL_TREE' if the attribute was not
7895 seen. When we see an attribute, we set them to 'true' (if they
7896 are boolean properties) or to the identifier (if they have an
7897 argument, ie, for getter and setter). Note that here we only
7898 parse the list of attributes, check the syntax and accumulate the
7899 attributes that we find. objc_add_property_declaration() will
7900 then process the information. */
7901 bool property_assign
= false;
7902 bool property_copy
= false;
7903 tree property_getter_ident
= NULL_TREE
;
7904 bool property_nonatomic
= false;
7905 bool property_readonly
= false;
7906 bool property_readwrite
= false;
7907 bool property_retain
= false;
7908 tree property_setter_ident
= NULL_TREE
;
7910 /* 'properties' is the list of properties that we read. Usually a
7911 single one, but maybe more (eg, in "@property int a, b, c;" there
7916 loc
= c_parser_peek_token (parser
)->location
;
7917 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
));
7919 c_parser_consume_token (parser
); /* Eat '@property'. */
7921 /* Parse the optional attribute list... */
7922 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
7925 c_parser_consume_token (parser
);
7927 /* Property attribute keywords are valid now. */
7928 parser
->objc_property_attr_context
= true;
7932 bool syntax_error
= false;
7933 c_token
*token
= c_parser_peek_token (parser
);
7936 if (token
->type
!= CPP_KEYWORD
)
7938 if (token
->type
== CPP_CLOSE_PAREN
)
7939 c_parser_error (parser
, "expected identifier");
7942 c_parser_consume_token (parser
);
7943 c_parser_error (parser
, "unknown property attribute");
7947 keyword
= token
->keyword
;
7948 c_parser_consume_token (parser
);
7951 case RID_ASSIGN
: property_assign
= true; break;
7952 case RID_COPY
: property_copy
= true; break;
7953 case RID_NONATOMIC
: property_nonatomic
= true; break;
7954 case RID_READONLY
: property_readonly
= true; break;
7955 case RID_READWRITE
: property_readwrite
= true; break;
7956 case RID_RETAIN
: property_retain
= true; break;
7960 if (c_parser_next_token_is_not (parser
, CPP_EQ
))
7962 if (keyword
== RID_GETTER
)
7963 c_parser_error (parser
,
7964 "missing %<=%> (after %<getter%> attribute)");
7966 c_parser_error (parser
,
7967 "missing %<=%> (after %<setter%> attribute)");
7968 syntax_error
= true;
7971 c_parser_consume_token (parser
); /* eat the = */
7972 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7974 c_parser_error (parser
, "expected identifier");
7975 syntax_error
= true;
7978 if (keyword
== RID_SETTER
)
7980 if (property_setter_ident
!= NULL_TREE
)
7981 c_parser_error (parser
, "the %<setter%> attribute may only be specified once");
7983 property_setter_ident
= c_parser_peek_token (parser
)->value
;
7984 c_parser_consume_token (parser
);
7985 if (c_parser_next_token_is_not (parser
, CPP_COLON
))
7986 c_parser_error (parser
, "setter name must terminate with %<:%>");
7988 c_parser_consume_token (parser
);
7992 if (property_getter_ident
!= NULL_TREE
)
7993 c_parser_error (parser
, "the %<getter%> attribute may only be specified once");
7995 property_getter_ident
= c_parser_peek_token (parser
)->value
;
7996 c_parser_consume_token (parser
);
8000 c_parser_error (parser
, "unknown property attribute");
8001 syntax_error
= true;
8008 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8009 c_parser_consume_token (parser
);
8013 parser
->objc_property_attr_context
= false;
8014 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8016 /* ... and the property declaration(s). */
8017 properties
= c_parser_struct_declaration (parser
);
8019 if (properties
== error_mark_node
)
8021 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8022 parser
->error
= false;
8026 if (properties
== NULL_TREE
)
8027 c_parser_error (parser
, "expected identifier");
8030 /* Comma-separated properties are chained together in
8031 reverse order; add them one by one. */
8032 properties
= nreverse (properties
);
8034 for (; properties
; properties
= TREE_CHAIN (properties
))
8035 objc_add_property_declaration (loc
, copy_node (properties
),
8036 property_readonly
, property_readwrite
,
8037 property_assign
, property_retain
,
8038 property_copy
, property_nonatomic
,
8039 property_getter_ident
, property_setter_ident
);
8042 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8043 parser
->error
= false;
8046 /* Parse an Objective-C @synthesize declaration. The syntax is:
8048 objc-synthesize-declaration:
8049 @synthesize objc-synthesize-identifier-list ;
8051 objc-synthesize-identifier-list:
8052 objc-synthesize-identifier
8053 objc-synthesize-identifier-list, objc-synthesize-identifier
8055 objc-synthesize-identifier
8057 identifier = identifier
8060 @synthesize MyProperty;
8061 @synthesize OneProperty, AnotherProperty=MyIvar, YetAnotherProperty;
8063 PS: This function is identical to cp_parser_objc_at_synthesize_declaration
8064 for C++. Keep them in sync.
8067 c_parser_objc_at_synthesize_declaration (c_parser
*parser
)
8069 tree list
= NULL_TREE
;
8071 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNTHESIZE
));
8072 loc
= c_parser_peek_token (parser
)->location
;
8074 c_parser_consume_token (parser
);
8077 tree property
, ivar
;
8078 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8080 c_parser_error (parser
, "expected identifier");
8081 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8082 /* Once we find the semicolon, we can resume normal parsing.
8083 We have to reset parser->error manually because
8084 c_parser_skip_until_found() won't reset it for us if the
8085 next token is precisely a semicolon. */
8086 parser
->error
= false;
8089 property
= c_parser_peek_token (parser
)->value
;
8090 c_parser_consume_token (parser
);
8091 if (c_parser_next_token_is (parser
, CPP_EQ
))
8093 c_parser_consume_token (parser
);
8094 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8096 c_parser_error (parser
, "expected identifier");
8097 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8098 parser
->error
= false;
8101 ivar
= c_parser_peek_token (parser
)->value
;
8102 c_parser_consume_token (parser
);
8106 list
= chainon (list
, build_tree_list (ivar
, property
));
8107 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8108 c_parser_consume_token (parser
);
8112 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8113 objc_add_synthesize_declaration (loc
, list
);
8116 /* Parse an Objective-C @dynamic declaration. The syntax is:
8118 objc-dynamic-declaration:
8119 @dynamic identifier-list ;
8122 @dynamic MyProperty;
8123 @dynamic MyProperty, AnotherProperty;
8125 PS: This function is identical to cp_parser_objc_at_dynamic_declaration
8126 for C++. Keep them in sync.
8129 c_parser_objc_at_dynamic_declaration (c_parser
*parser
)
8131 tree list
= NULL_TREE
;
8133 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_DYNAMIC
));
8134 loc
= c_parser_peek_token (parser
)->location
;
8136 c_parser_consume_token (parser
);
8140 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8142 c_parser_error (parser
, "expected identifier");
8143 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8144 parser
->error
= false;
8147 property
= c_parser_peek_token (parser
)->value
;
8148 list
= chainon (list
, build_tree_list (NULL_TREE
, property
));
8149 c_parser_consume_token (parser
);
8150 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8151 c_parser_consume_token (parser
);
8155 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8156 objc_add_dynamic_declaration (loc
, list
);
8160 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
8161 should be considered, statements. ALLOW_STMT is true if we're within
8162 the context of a function and such pragmas are to be allowed. Returns
8163 true if we actually parsed such a pragma. */
8166 c_parser_pragma (c_parser
*parser
, enum pragma_context context
)
8170 id
= c_parser_peek_token (parser
)->pragma_kind
;
8171 gcc_assert (id
!= PRAGMA_NONE
);
8175 case PRAGMA_OMP_BARRIER
:
8176 if (context
!= pragma_compound
)
8178 if (context
== pragma_stmt
)
8179 c_parser_error (parser
, "%<#pragma omp barrier%> may only be "
8180 "used in compound statements");
8183 c_parser_omp_barrier (parser
);
8186 case PRAGMA_OMP_FLUSH
:
8187 if (context
!= pragma_compound
)
8189 if (context
== pragma_stmt
)
8190 c_parser_error (parser
, "%<#pragma omp flush%> may only be "
8191 "used in compound statements");
8194 c_parser_omp_flush (parser
);
8197 case PRAGMA_OMP_TASKWAIT
:
8198 if (context
!= pragma_compound
)
8200 if (context
== pragma_stmt
)
8201 c_parser_error (parser
, "%<#pragma omp taskwait%> may only be "
8202 "used in compound statements");
8205 c_parser_omp_taskwait (parser
);
8208 case PRAGMA_OMP_THREADPRIVATE
:
8209 c_parser_omp_threadprivate (parser
);
8212 case PRAGMA_OMP_SECTION
:
8213 error_at (c_parser_peek_token (parser
)->location
,
8214 "%<#pragma omp section%> may only be used in "
8215 "%<#pragma omp sections%> construct");
8216 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
8219 case PRAGMA_GCC_PCH_PREPROCESS
:
8220 c_parser_error (parser
, "%<#pragma GCC pch_preprocess%> must be first");
8221 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
8225 if (id
< PRAGMA_FIRST_EXTERNAL
)
8227 if (context
== pragma_external
)
8230 c_parser_error (parser
, "expected declaration specifiers");
8231 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
8234 c_parser_omp_construct (parser
);
8240 c_parser_consume_pragma (parser
);
8241 c_invoke_pragma_handler (id
);
8243 /* Skip to EOL, but suppress any error message. Those will have been
8244 generated by the handler routine through calling error, as opposed
8245 to calling c_parser_error. */
8246 parser
->error
= true;
8247 c_parser_skip_to_pragma_eol (parser
);
8252 /* The interface the pragma parsers have to the lexer. */
8255 pragma_lex (tree
*value
)
8257 c_token
*tok
= c_parser_peek_token (the_parser
);
8258 enum cpp_ttype ret
= tok
->type
;
8260 *value
= tok
->value
;
8261 if (ret
== CPP_PRAGMA_EOL
|| ret
== CPP_EOF
)
8265 if (ret
== CPP_KEYWORD
)
8267 c_parser_consume_token (the_parser
);
8274 c_parser_pragma_pch_preprocess (c_parser
*parser
)
8278 c_parser_consume_pragma (parser
);
8279 if (c_parser_next_token_is (parser
, CPP_STRING
))
8281 name
= c_parser_peek_token (parser
)->value
;
8282 c_parser_consume_token (parser
);
8285 c_parser_error (parser
, "expected string literal");
8286 c_parser_skip_to_pragma_eol (parser
);
8289 c_common_pch_pragma (parse_in
, TREE_STRING_POINTER (name
));
8292 /* OpenMP 2.5 parsing routines. */
8294 /* Returns name of the next clause.
8295 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
8296 the token is not consumed. Otherwise appropriate pragma_omp_clause is
8297 returned and the token is consumed. */
8299 static pragma_omp_clause
8300 c_parser_omp_clause_name (c_parser
*parser
)
8302 pragma_omp_clause result
= PRAGMA_OMP_CLAUSE_NONE
;
8304 if (c_parser_next_token_is_keyword (parser
, RID_IF
))
8305 result
= PRAGMA_OMP_CLAUSE_IF
;
8306 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
8307 result
= PRAGMA_OMP_CLAUSE_DEFAULT
;
8308 else if (c_parser_next_token_is (parser
, CPP_NAME
))
8310 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
8315 if (!strcmp ("collapse", p
))
8316 result
= PRAGMA_OMP_CLAUSE_COLLAPSE
;
8317 else if (!strcmp ("copyin", p
))
8318 result
= PRAGMA_OMP_CLAUSE_COPYIN
;
8319 else if (!strcmp ("copyprivate", p
))
8320 result
= PRAGMA_OMP_CLAUSE_COPYPRIVATE
;
8323 if (!strcmp ("firstprivate", p
))
8324 result
= PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
;
8327 if (!strcmp ("lastprivate", p
))
8328 result
= PRAGMA_OMP_CLAUSE_LASTPRIVATE
;
8331 if (!strcmp ("nowait", p
))
8332 result
= PRAGMA_OMP_CLAUSE_NOWAIT
;
8333 else if (!strcmp ("num_threads", p
))
8334 result
= PRAGMA_OMP_CLAUSE_NUM_THREADS
;
8337 if (!strcmp ("ordered", p
))
8338 result
= PRAGMA_OMP_CLAUSE_ORDERED
;
8341 if (!strcmp ("private", p
))
8342 result
= PRAGMA_OMP_CLAUSE_PRIVATE
;
8345 if (!strcmp ("reduction", p
))
8346 result
= PRAGMA_OMP_CLAUSE_REDUCTION
;
8349 if (!strcmp ("schedule", p
))
8350 result
= PRAGMA_OMP_CLAUSE_SCHEDULE
;
8351 else if (!strcmp ("shared", p
))
8352 result
= PRAGMA_OMP_CLAUSE_SHARED
;
8355 if (!strcmp ("untied", p
))
8356 result
= PRAGMA_OMP_CLAUSE_UNTIED
;
8361 if (result
!= PRAGMA_OMP_CLAUSE_NONE
)
8362 c_parser_consume_token (parser
);
8367 /* Validate that a clause of the given type does not already exist. */
8370 check_no_duplicate_clause (tree clauses
, enum omp_clause_code code
,
8375 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
8376 if (OMP_CLAUSE_CODE (c
) == code
)
8378 location_t loc
= OMP_CLAUSE_LOCATION (c
);
8379 error_at (loc
, "too many %qs clauses", name
);
8387 variable-list , identifier
8389 If KIND is nonzero, create the appropriate node and install the
8390 decl in OMP_CLAUSE_DECL and add the node to the head of the list.
8391 If KIND is nonzero, CLAUSE_LOC is the location of the clause.
8393 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
8394 return the list created. */
8397 c_parser_omp_variable_list (c_parser
*parser
,
8398 location_t clause_loc
,
8399 enum omp_clause_code kind
,
8402 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
8403 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
8404 c_parser_error (parser
, "expected identifier");
8406 while (c_parser_next_token_is (parser
, CPP_NAME
)
8407 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
8409 tree t
= lookup_name (c_parser_peek_token (parser
)->value
);
8412 undeclared_variable (c_parser_peek_token (parser
)->location
,
8413 c_parser_peek_token (parser
)->value
);
8414 else if (t
== error_mark_node
)
8418 tree u
= build_omp_clause (clause_loc
, kind
);
8419 OMP_CLAUSE_DECL (u
) = t
;
8420 OMP_CLAUSE_CHAIN (u
) = list
;
8424 list
= tree_cons (t
, NULL_TREE
, list
);
8426 c_parser_consume_token (parser
);
8428 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
8431 c_parser_consume_token (parser
);
8437 /* Similarly, but expect leading and trailing parenthesis. This is a very
8438 common case for omp clauses. */
8441 c_parser_omp_var_list_parens (c_parser
*parser
, enum omp_clause_code kind
,
8444 /* The clauses location. */
8445 location_t loc
= c_parser_peek_token (parser
)->location
;
8447 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8449 list
= c_parser_omp_variable_list (parser
, loc
, kind
, list
);
8450 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8456 collapse ( constant-expression ) */
8459 c_parser_omp_clause_collapse (c_parser
*parser
, tree list
)
8461 tree c
, num
= error_mark_node
;
8465 check_no_duplicate_clause (list
, OMP_CLAUSE_COLLAPSE
, "collapse");
8467 loc
= c_parser_peek_token (parser
)->location
;
8468 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8470 num
= c_parser_expr_no_commas (parser
, NULL
).value
;
8471 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8473 if (num
== error_mark_node
)
8475 if (!INTEGRAL_TYPE_P (TREE_TYPE (num
))
8476 || !host_integerp (num
, 0)
8477 || (n
= tree_low_cst (num
, 0)) <= 0
8481 "collapse argument needs positive constant integer expression");
8484 c
= build_omp_clause (loc
, OMP_CLAUSE_COLLAPSE
);
8485 OMP_CLAUSE_COLLAPSE_EXPR (c
) = num
;
8486 OMP_CLAUSE_CHAIN (c
) = list
;
8491 copyin ( variable-list ) */
8494 c_parser_omp_clause_copyin (c_parser
*parser
, tree list
)
8496 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYIN
, list
);
8500 copyprivate ( variable-list ) */
8503 c_parser_omp_clause_copyprivate (c_parser
*parser
, tree list
)
8505 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYPRIVATE
, list
);
8509 default ( shared | none ) */
8512 c_parser_omp_clause_default (c_parser
*parser
, tree list
)
8514 enum omp_clause_default_kind kind
= OMP_CLAUSE_DEFAULT_UNSPECIFIED
;
8515 location_t loc
= c_parser_peek_token (parser
)->location
;
8518 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8520 if (c_parser_next_token_is (parser
, CPP_NAME
))
8522 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
8527 if (strcmp ("none", p
) != 0)
8529 kind
= OMP_CLAUSE_DEFAULT_NONE
;
8533 if (strcmp ("shared", p
) != 0)
8535 kind
= OMP_CLAUSE_DEFAULT_SHARED
;
8542 c_parser_consume_token (parser
);
8547 c_parser_error (parser
, "expected %<none%> or %<shared%>");
8549 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8551 if (kind
== OMP_CLAUSE_DEFAULT_UNSPECIFIED
)
8554 check_no_duplicate_clause (list
, OMP_CLAUSE_DEFAULT
, "default");
8555 c
= build_omp_clause (loc
, OMP_CLAUSE_DEFAULT
);
8556 OMP_CLAUSE_CHAIN (c
) = list
;
8557 OMP_CLAUSE_DEFAULT_KIND (c
) = kind
;
8563 firstprivate ( variable-list ) */
8566 c_parser_omp_clause_firstprivate (c_parser
*parser
, tree list
)
8568 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FIRSTPRIVATE
, list
);
8572 if ( expression ) */
8575 c_parser_omp_clause_if (c_parser
*parser
, tree list
)
8577 location_t loc
= c_parser_peek_token (parser
)->location
;
8578 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8580 tree t
= c_parser_paren_condition (parser
);
8583 check_no_duplicate_clause (list
, OMP_CLAUSE_IF
, "if");
8585 c
= build_omp_clause (loc
, OMP_CLAUSE_IF
);
8586 OMP_CLAUSE_IF_EXPR (c
) = t
;
8587 OMP_CLAUSE_CHAIN (c
) = list
;
8591 c_parser_error (parser
, "expected %<(%>");
8597 lastprivate ( variable-list ) */
8600 c_parser_omp_clause_lastprivate (c_parser
*parser
, tree list
)
8602 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_LASTPRIVATE
, list
);
8609 c_parser_omp_clause_nowait (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
8612 location_t loc
= c_parser_peek_token (parser
)->location
;
8614 check_no_duplicate_clause (list
, OMP_CLAUSE_NOWAIT
, "nowait");
8616 c
= build_omp_clause (loc
, OMP_CLAUSE_NOWAIT
);
8617 OMP_CLAUSE_CHAIN (c
) = list
;
8622 num_threads ( expression ) */
8625 c_parser_omp_clause_num_threads (c_parser
*parser
, tree list
)
8627 location_t num_threads_loc
= c_parser_peek_token (parser
)->location
;
8628 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8630 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
8631 tree c
, t
= c_parser_expression (parser
).value
;
8632 t
= c_fully_fold (t
, false, NULL
);
8634 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8636 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
8638 c_parser_error (parser
, "expected integer expression");
8642 /* Attempt to statically determine when the number isn't positive. */
8643 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
8644 build_int_cst (TREE_TYPE (t
), 0));
8645 if (CAN_HAVE_LOCATION_P (c
))
8646 SET_EXPR_LOCATION (c
, expr_loc
);
8647 if (c
== boolean_true_node
)
8649 warning_at (expr_loc
, 0,
8650 "%<num_threads%> value must be positive");
8651 t
= integer_one_node
;
8654 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_THREADS
, "num_threads");
8656 c
= build_omp_clause (num_threads_loc
, OMP_CLAUSE_NUM_THREADS
);
8657 OMP_CLAUSE_NUM_THREADS_EXPR (c
) = t
;
8658 OMP_CLAUSE_CHAIN (c
) = list
;
8669 c_parser_omp_clause_ordered (c_parser
*parser
, tree list
)
8673 check_no_duplicate_clause (list
, OMP_CLAUSE_ORDERED
, "ordered");
8675 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
8676 OMP_CLAUSE_ORDERED
);
8677 OMP_CLAUSE_CHAIN (c
) = list
;
8683 private ( variable-list ) */
8686 c_parser_omp_clause_private (c_parser
*parser
, tree list
)
8688 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_PRIVATE
, list
);
8692 reduction ( reduction-operator : variable-list )
8695 One of: + * - & ^ | && || */
8698 c_parser_omp_clause_reduction (c_parser
*parser
, tree list
)
8700 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
8701 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8703 enum tree_code code
;
8705 switch (c_parser_peek_token (parser
)->type
)
8717 code
= BIT_AND_EXPR
;
8720 code
= BIT_XOR_EXPR
;
8723 code
= BIT_IOR_EXPR
;
8726 code
= TRUTH_ANDIF_EXPR
;
8729 code
= TRUTH_ORIF_EXPR
;
8732 c_parser_error (parser
,
8733 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
8734 "%<^%>, %<|%>, %<&&%>, or %<||%>");
8735 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
8738 c_parser_consume_token (parser
);
8739 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
8743 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
8744 OMP_CLAUSE_REDUCTION
, list
);
8745 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
8746 OMP_CLAUSE_REDUCTION_CODE (c
) = code
;
8750 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8756 schedule ( schedule-kind )
8757 schedule ( schedule-kind , expression )
8760 static | dynamic | guided | runtime | auto
8764 c_parser_omp_clause_schedule (c_parser
*parser
, tree list
)
8767 location_t loc
= c_parser_peek_token (parser
)->location
;
8769 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8772 c
= build_omp_clause (loc
, OMP_CLAUSE_SCHEDULE
);
8774 if (c_parser_next_token_is (parser
, CPP_NAME
))
8776 tree kind
= c_parser_peek_token (parser
)->value
;
8777 const char *p
= IDENTIFIER_POINTER (kind
);
8782 if (strcmp ("dynamic", p
) != 0)
8784 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_DYNAMIC
;
8788 if (strcmp ("guided", p
) != 0)
8790 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_GUIDED
;
8794 if (strcmp ("runtime", p
) != 0)
8796 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_RUNTIME
;
8803 else if (c_parser_next_token_is_keyword (parser
, RID_STATIC
))
8804 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_STATIC
;
8805 else if (c_parser_next_token_is_keyword (parser
, RID_AUTO
))
8806 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_AUTO
;
8810 c_parser_consume_token (parser
);
8811 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8814 c_parser_consume_token (parser
);
8816 here
= c_parser_peek_token (parser
)->location
;
8817 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
8818 t
= c_fully_fold (t
, false, NULL
);
8820 if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_RUNTIME
)
8821 error_at (here
, "schedule %<runtime%> does not take "
8822 "a %<chunk_size%> parameter");
8823 else if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_AUTO
)
8825 "schedule %<auto%> does not take "
8826 "a %<chunk_size%> parameter");
8827 else if (TREE_CODE (TREE_TYPE (t
)) == INTEGER_TYPE
)
8828 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
) = t
;
8830 c_parser_error (parser
, "expected integer expression");
8832 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8835 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
8836 "expected %<,%> or %<)%>");
8838 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
8839 OMP_CLAUSE_CHAIN (c
) = list
;
8843 c_parser_error (parser
, "invalid schedule kind");
8844 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
8849 shared ( variable-list ) */
8852 c_parser_omp_clause_shared (c_parser
*parser
, tree list
)
8854 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_SHARED
, list
);
8861 c_parser_omp_clause_untied (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
8865 /* FIXME: Should we allow duplicates? */
8866 check_no_duplicate_clause (list
, OMP_CLAUSE_UNTIED
, "untied");
8868 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
8870 OMP_CLAUSE_CHAIN (c
) = list
;
8875 /* Parse all OpenMP clauses. The set clauses allowed by the directive
8876 is a bitmask in MASK. Return the list of clauses found; the result
8877 of clause default goes in *pdefault. */
8880 c_parser_omp_all_clauses (c_parser
*parser
, unsigned int mask
,
8883 tree clauses
= NULL
;
8886 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
8889 pragma_omp_clause c_kind
;
8891 tree prev
= clauses
;
8893 if (!first
&& c_parser_next_token_is (parser
, CPP_COMMA
))
8894 c_parser_consume_token (parser
);
8897 here
= c_parser_peek_token (parser
)->location
;
8898 c_kind
= c_parser_omp_clause_name (parser
);
8902 case PRAGMA_OMP_CLAUSE_COLLAPSE
:
8903 clauses
= c_parser_omp_clause_collapse (parser
, clauses
);
8904 c_name
= "collapse";
8906 case PRAGMA_OMP_CLAUSE_COPYIN
:
8907 clauses
= c_parser_omp_clause_copyin (parser
, clauses
);
8910 case PRAGMA_OMP_CLAUSE_COPYPRIVATE
:
8911 clauses
= c_parser_omp_clause_copyprivate (parser
, clauses
);
8912 c_name
= "copyprivate";
8914 case PRAGMA_OMP_CLAUSE_DEFAULT
:
8915 clauses
= c_parser_omp_clause_default (parser
, clauses
);
8918 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
:
8919 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
8920 c_name
= "firstprivate";
8922 case PRAGMA_OMP_CLAUSE_IF
:
8923 clauses
= c_parser_omp_clause_if (parser
, clauses
);
8926 case PRAGMA_OMP_CLAUSE_LASTPRIVATE
:
8927 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
8928 c_name
= "lastprivate";
8930 case PRAGMA_OMP_CLAUSE_NOWAIT
:
8931 clauses
= c_parser_omp_clause_nowait (parser
, clauses
);
8934 case PRAGMA_OMP_CLAUSE_NUM_THREADS
:
8935 clauses
= c_parser_omp_clause_num_threads (parser
, clauses
);
8936 c_name
= "num_threads";
8938 case PRAGMA_OMP_CLAUSE_ORDERED
:
8939 clauses
= c_parser_omp_clause_ordered (parser
, clauses
);
8942 case PRAGMA_OMP_CLAUSE_PRIVATE
:
8943 clauses
= c_parser_omp_clause_private (parser
, clauses
);
8946 case PRAGMA_OMP_CLAUSE_REDUCTION
:
8947 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
8948 c_name
= "reduction";
8950 case PRAGMA_OMP_CLAUSE_SCHEDULE
:
8951 clauses
= c_parser_omp_clause_schedule (parser
, clauses
);
8952 c_name
= "schedule";
8954 case PRAGMA_OMP_CLAUSE_SHARED
:
8955 clauses
= c_parser_omp_clause_shared (parser
, clauses
);
8958 case PRAGMA_OMP_CLAUSE_UNTIED
:
8959 clauses
= c_parser_omp_clause_untied (parser
, clauses
);
8963 c_parser_error (parser
, "expected %<#pragma omp%> clause");
8967 if (((mask
>> c_kind
) & 1) == 0 && !parser
->error
)
8969 /* Remove the invalid clause(s) from the list to avoid
8970 confusing the rest of the compiler. */
8972 error_at (here
, "%qs is not valid for %qs", c_name
, where
);
8977 c_parser_skip_to_pragma_eol (parser
);
8979 return c_finish_omp_clauses (clauses
);
8986 In practice, we're also interested in adding the statement to an
8987 outer node. So it is convenient if we work around the fact that
8988 c_parser_statement calls add_stmt. */
8991 c_parser_omp_structured_block (c_parser
*parser
)
8993 tree stmt
= push_stmt_list ();
8994 c_parser_statement (parser
);
8995 return pop_stmt_list (stmt
);
8999 # pragma omp atomic new-line
9003 x binop= expr | x++ | ++x | x-- | --x
9005 +, *, -, /, &, ^, |, <<, >>
9007 where x is an lvalue expression with scalar type.
9009 LOC is the location of the #pragma token. */
9012 c_parser_omp_atomic (location_t loc
, c_parser
*parser
)
9016 enum tree_code code
;
9017 struct c_expr rhs_expr
;
9019 c_parser_skip_to_pragma_eol (parser
);
9021 lhs
= c_parser_unary_expression (parser
).value
;
9022 lhs
= c_fully_fold (lhs
, false, NULL
);
9023 switch (TREE_CODE (lhs
))
9027 c_parser_skip_to_end_of_block_or_statement (parser
);
9030 case PREINCREMENT_EXPR
:
9031 case POSTINCREMENT_EXPR
:
9032 lhs
= TREE_OPERAND (lhs
, 0);
9034 rhs
= integer_one_node
;
9037 case PREDECREMENT_EXPR
:
9038 case POSTDECREMENT_EXPR
:
9039 lhs
= TREE_OPERAND (lhs
, 0);
9041 rhs
= integer_one_node
;
9045 if (TREE_CODE (TREE_OPERAND (lhs
, 0)) == SAVE_EXPR
9046 && TREE_CODE (TREE_OPERAND (lhs
, 1)) == COMPOUND_EXPR
9047 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0)) == MODIFY_EXPR
9048 && TREE_OPERAND (TREE_OPERAND (lhs
, 1), 1) == TREE_OPERAND (lhs
, 0)
9049 && TREE_CODE (TREE_TYPE (TREE_OPERAND (TREE_OPERAND
9050 (TREE_OPERAND (lhs
, 1), 0), 0)))
9052 /* Undo effects of boolean_increment for post {in,de}crement. */
9053 lhs
= TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0);
9056 if (TREE_CODE (lhs
) == MODIFY_EXPR
9057 && TREE_CODE (TREE_TYPE (TREE_OPERAND (lhs
, 0))) == BOOLEAN_TYPE
)
9059 /* Undo effects of boolean_increment. */
9060 if (integer_onep (TREE_OPERAND (lhs
, 1)))
9062 /* This is pre or post increment. */
9063 rhs
= TREE_OPERAND (lhs
, 1);
9064 lhs
= TREE_OPERAND (lhs
, 0);
9068 if (TREE_CODE (TREE_OPERAND (lhs
, 1)) == TRUTH_NOT_EXPR
9069 && TREE_OPERAND (lhs
, 0)
9070 == TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0))
9072 /* This is pre or post decrement. */
9073 rhs
= TREE_OPERAND (lhs
, 1);
9074 lhs
= TREE_OPERAND (lhs
, 0);
9081 switch (c_parser_peek_token (parser
)->type
)
9087 code
= TRUNC_DIV_EXPR
;
9102 code
= BIT_AND_EXPR
;
9105 code
= BIT_IOR_EXPR
;
9108 code
= BIT_XOR_EXPR
;
9111 c_parser_error (parser
,
9112 "invalid operator for %<#pragma omp atomic%>");
9116 /* Arrange to pass the location of the assignment operator to
9117 c_finish_omp_atomic. */
9118 loc
= c_parser_peek_token (parser
)->location
;
9119 c_parser_consume_token (parser
);
9121 location_t rhs_loc
= c_parser_peek_token (parser
)->location
;
9122 rhs_expr
= c_parser_expression (parser
);
9123 rhs_expr
= default_function_array_read_conversion (rhs_loc
, rhs_expr
);
9125 rhs
= rhs_expr
.value
;
9126 rhs
= c_fully_fold (rhs
, false, NULL
);
9129 stmt
= c_finish_omp_atomic (loc
, code
, lhs
, rhs
);
9130 if (stmt
!= error_mark_node
)
9132 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9137 # pragma omp barrier new-line
9141 c_parser_omp_barrier (c_parser
*parser
)
9143 location_t loc
= c_parser_peek_token (parser
)->location
;
9144 c_parser_consume_pragma (parser
);
9145 c_parser_skip_to_pragma_eol (parser
);
9147 c_finish_omp_barrier (loc
);
9151 # pragma omp critical [(name)] new-line
9154 LOC is the location of the #pragma itself. */
9157 c_parser_omp_critical (location_t loc
, c_parser
*parser
)
9159 tree stmt
, name
= NULL
;
9161 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9163 c_parser_consume_token (parser
);
9164 if (c_parser_next_token_is (parser
, CPP_NAME
))
9166 name
= c_parser_peek_token (parser
)->value
;
9167 c_parser_consume_token (parser
);
9168 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9171 c_parser_error (parser
, "expected identifier");
9173 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
9174 c_parser_error (parser
, "expected %<(%> or end of line");
9175 c_parser_skip_to_pragma_eol (parser
);
9177 stmt
= c_parser_omp_structured_block (parser
);
9178 return c_finish_omp_critical (loc
, stmt
, name
);
9182 # pragma omp flush flush-vars[opt] new-line
9185 ( variable-list ) */
9188 c_parser_omp_flush (c_parser
*parser
)
9190 location_t loc
= c_parser_peek_token (parser
)->location
;
9191 c_parser_consume_pragma (parser
);
9192 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9193 c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
9194 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
9195 c_parser_error (parser
, "expected %<(%> or end of line");
9196 c_parser_skip_to_pragma_eol (parser
);
9198 c_finish_omp_flush (loc
);
9201 /* Parse the restricted form of the for statement allowed by OpenMP.
9202 The real trick here is to determine the loop control variable early
9203 so that we can push a new decl if necessary to make it private.
9204 LOC is the location of the OMP in "#pragma omp". */
9207 c_parser_omp_for_loop (location_t loc
,
9208 c_parser
*parser
, tree clauses
, tree
*par_clauses
)
9210 tree decl
, cond
, incr
, save_break
, save_cont
, body
, init
, stmt
, cl
;
9211 tree declv
, condv
, incrv
, initv
, ret
= NULL
;
9212 bool fail
= false, open_brace_parsed
= false;
9213 int i
, collapse
= 1, nbraces
= 0;
9215 VEC(tree
,gc
) *for_block
= make_tree_vector ();
9217 for (cl
= clauses
; cl
; cl
= OMP_CLAUSE_CHAIN (cl
))
9218 if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_COLLAPSE
)
9219 collapse
= tree_low_cst (OMP_CLAUSE_COLLAPSE_EXPR (cl
), 0);
9221 gcc_assert (collapse
>= 1);
9223 declv
= make_tree_vec (collapse
);
9224 initv
= make_tree_vec (collapse
);
9225 condv
= make_tree_vec (collapse
);
9226 incrv
= make_tree_vec (collapse
);
9228 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
))
9230 c_parser_error (parser
, "for statement expected");
9233 for_loc
= c_parser_peek_token (parser
)->location
;
9234 c_parser_consume_token (parser
);
9236 for (i
= 0; i
< collapse
; i
++)
9240 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9243 /* Parse the initialization declaration or expression. */
9244 if (c_parser_next_tokens_start_declaration (parser
))
9247 VEC_safe_push (tree
, gc
, for_block
, c_begin_compound_stmt (true));
9248 c_parser_declaration_or_fndef (parser
, true, true, true, true, true, NULL
);
9249 decl
= check_for_loop_decls (for_loc
, flag_isoc99
);
9252 if (DECL_INITIAL (decl
) == error_mark_node
)
9253 decl
= error_mark_node
;
9256 else if (c_parser_next_token_is (parser
, CPP_NAME
)
9257 && c_parser_peek_2nd_token (parser
)->type
== CPP_EQ
)
9259 struct c_expr decl_exp
;
9260 struct c_expr init_exp
;
9261 location_t init_loc
;
9263 decl_exp
= c_parser_postfix_expression (parser
);
9264 decl
= decl_exp
.value
;
9266 c_parser_require (parser
, CPP_EQ
, "expected %<=%>");
9268 init_loc
= c_parser_peek_token (parser
)->location
;
9269 init_exp
= c_parser_expr_no_commas (parser
, NULL
);
9270 init_exp
= default_function_array_read_conversion (init_loc
,
9272 init
= build_modify_expr (init_loc
, decl
, decl_exp
.original_type
,
9273 NOP_EXPR
, init_loc
, init_exp
.value
,
9274 init_exp
.original_type
);
9275 init
= c_process_expr_stmt (init_loc
, init
);
9277 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9282 c_parser_error (parser
,
9283 "expected iteration declaration or initialization");
9284 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
9290 /* Parse the loop condition. */
9292 if (c_parser_next_token_is_not (parser
, CPP_SEMICOLON
))
9294 location_t cond_loc
= c_parser_peek_token (parser
)->location
;
9295 struct c_expr cond_expr
= c_parser_binary_expression (parser
, NULL
);
9297 cond
= cond_expr
.value
;
9298 cond
= c_objc_common_truthvalue_conversion (cond_loc
, cond
);
9299 cond
= c_fully_fold (cond
, false, NULL
);
9300 switch (cond_expr
.original_code
)
9308 /* Can't be cond = error_mark_node, because we want to preserve
9309 the location until c_finish_omp_for. */
9310 cond
= build1 (NOP_EXPR
, boolean_type_node
, error_mark_node
);
9313 protected_set_expr_location (cond
, cond_loc
);
9315 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9317 /* Parse the increment expression. */
9319 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_PAREN
))
9321 location_t incr_loc
= c_parser_peek_token (parser
)->location
;
9323 incr
= c_process_expr_stmt (incr_loc
,
9324 c_parser_expression (parser
).value
);
9326 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9328 if (decl
== NULL
|| decl
== error_mark_node
|| init
== error_mark_node
)
9332 TREE_VEC_ELT (declv
, i
) = decl
;
9333 TREE_VEC_ELT (initv
, i
) = init
;
9334 TREE_VEC_ELT (condv
, i
) = cond
;
9335 TREE_VEC_ELT (incrv
, i
) = incr
;
9339 if (i
== collapse
- 1)
9342 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
9343 in between the collapsed for loops to be still considered perfectly
9344 nested. Hopefully the final version clarifies this.
9345 For now handle (multiple) {'s and empty statements. */
9348 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
9350 c_parser_consume_token (parser
);
9353 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
9355 c_parser_consume_token (parser
);
9359 && c_parser_next_token_is (parser
, CPP_SEMICOLON
))
9360 c_parser_consume_token (parser
);
9363 c_parser_error (parser
, "not enough perfectly nested loops");
9366 open_brace_parsed
= true;
9376 nbraces
+= bracecount
;
9379 save_break
= c_break_label
;
9380 c_break_label
= size_one_node
;
9381 save_cont
= c_cont_label
;
9382 c_cont_label
= NULL_TREE
;
9383 body
= push_stmt_list ();
9385 if (open_brace_parsed
)
9387 location_t here
= c_parser_peek_token (parser
)->location
;
9388 stmt
= c_begin_compound_stmt (true);
9389 c_parser_compound_statement_nostart (parser
);
9390 add_stmt (c_end_compound_stmt (here
, stmt
, true));
9393 add_stmt (c_parser_c99_block_statement (parser
));
9396 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_cont_label
);
9397 SET_EXPR_LOCATION (t
, loc
);
9401 body
= pop_stmt_list (body
);
9402 c_break_label
= save_break
;
9403 c_cont_label
= save_cont
;
9407 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
9409 c_parser_consume_token (parser
);
9412 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
9413 c_parser_consume_token (parser
);
9416 c_parser_error (parser
, "collapsed loops not perfectly nested");
9419 location_t here
= c_parser_peek_token (parser
)->location
;
9420 stmt
= c_begin_compound_stmt (true);
9422 c_parser_compound_statement_nostart (parser
);
9423 body
= c_end_compound_stmt (here
, stmt
, true);
9430 /* Only bother calling c_finish_omp_for if we haven't already generated
9431 an error from the initialization parsing. */
9434 stmt
= c_finish_omp_for (loc
, declv
, initv
, condv
, incrv
, body
, NULL
);
9437 if (par_clauses
!= NULL
)
9440 for (c
= par_clauses
; *c
; )
9441 if (OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_FIRSTPRIVATE
9442 && OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_LASTPRIVATE
)
9443 c
= &OMP_CLAUSE_CHAIN (*c
);
9446 for (i
= 0; i
< collapse
; i
++)
9447 if (TREE_VEC_ELT (declv
, i
) == OMP_CLAUSE_DECL (*c
))
9450 c
= &OMP_CLAUSE_CHAIN (*c
);
9451 else if (OMP_CLAUSE_CODE (*c
) == OMP_CLAUSE_FIRSTPRIVATE
)
9454 "iteration variable %qD should not be firstprivate",
9455 OMP_CLAUSE_DECL (*c
));
9456 *c
= OMP_CLAUSE_CHAIN (*c
);
9460 /* Copy lastprivate (decl) clause to OMP_FOR_CLAUSES,
9461 change it to shared (decl) in
9462 OMP_PARALLEL_CLAUSES. */
9463 tree l
= build_omp_clause (OMP_CLAUSE_LOCATION (*c
),
9464 OMP_CLAUSE_LASTPRIVATE
);
9465 OMP_CLAUSE_DECL (l
) = OMP_CLAUSE_DECL (*c
);
9466 OMP_CLAUSE_CHAIN (l
) = clauses
;
9468 OMP_CLAUSE_SET_CODE (*c
, OMP_CLAUSE_SHARED
);
9472 OMP_FOR_CLAUSES (stmt
) = clauses
;
9477 while (!VEC_empty (tree
, for_block
))
9479 /* FIXME diagnostics: LOC below should be the actual location of
9480 this particular for block. We need to build a list of
9481 locations to go along with FOR_BLOCK. */
9482 stmt
= c_end_compound_stmt (loc
, VEC_pop (tree
, for_block
), true);
9485 release_tree_vector (for_block
);
9490 #pragma omp for for-clause[optseq] new-line
9493 LOC is the location of the #pragma token.
9496 #define OMP_FOR_CLAUSE_MASK \
9497 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
9498 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
9499 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
9500 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
9501 | (1u << PRAGMA_OMP_CLAUSE_ORDERED) \
9502 | (1u << PRAGMA_OMP_CLAUSE_SCHEDULE) \
9503 | (1u << PRAGMA_OMP_CLAUSE_COLLAPSE) \
9504 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
9507 c_parser_omp_for (location_t loc
, c_parser
*parser
)
9509 tree block
, clauses
, ret
;
9511 clauses
= c_parser_omp_all_clauses (parser
, OMP_FOR_CLAUSE_MASK
,
9514 block
= c_begin_compound_stmt (true);
9515 ret
= c_parser_omp_for_loop (loc
, parser
, clauses
, NULL
);
9516 block
= c_end_compound_stmt (loc
, block
, true);
9523 # pragma omp master new-line
9526 LOC is the location of the #pragma token.
9530 c_parser_omp_master (location_t loc
, c_parser
*parser
)
9532 c_parser_skip_to_pragma_eol (parser
);
9533 return c_finish_omp_master (loc
, c_parser_omp_structured_block (parser
));
9537 # pragma omp ordered new-line
9540 LOC is the location of the #pragma itself.
9544 c_parser_omp_ordered (location_t loc
, c_parser
*parser
)
9546 c_parser_skip_to_pragma_eol (parser
);
9547 return c_finish_omp_ordered (loc
, c_parser_omp_structured_block (parser
));
9553 { section-sequence }
9556 section-directive[opt] structured-block
9557 section-sequence section-directive structured-block
9559 SECTIONS_LOC is the location of the #pragma omp sections. */
9562 c_parser_omp_sections_scope (location_t sections_loc
, c_parser
*parser
)
9565 bool error_suppress
= false;
9568 loc
= c_parser_peek_token (parser
)->location
;
9569 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
9571 /* Avoid skipping until the end of the block. */
9572 parser
->error
= false;
9576 stmt
= push_stmt_list ();
9578 if (c_parser_peek_token (parser
)->pragma_kind
!= PRAGMA_OMP_SECTION
)
9580 substmt
= push_stmt_list ();
9584 c_parser_statement (parser
);
9586 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
9588 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
9590 if (c_parser_next_token_is (parser
, CPP_EOF
))
9594 substmt
= pop_stmt_list (substmt
);
9595 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
9596 SET_EXPR_LOCATION (substmt
, loc
);
9602 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
9604 if (c_parser_next_token_is (parser
, CPP_EOF
))
9607 loc
= c_parser_peek_token (parser
)->location
;
9608 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
9610 c_parser_consume_pragma (parser
);
9611 c_parser_skip_to_pragma_eol (parser
);
9612 error_suppress
= false;
9614 else if (!error_suppress
)
9616 error_at (loc
, "expected %<#pragma omp section%> or %<}%>");
9617 error_suppress
= true;
9620 substmt
= c_parser_omp_structured_block (parser
);
9621 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
9622 SET_EXPR_LOCATION (substmt
, loc
);
9625 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
,
9626 "expected %<#pragma omp section%> or %<}%>");
9628 substmt
= pop_stmt_list (stmt
);
9630 stmt
= make_node (OMP_SECTIONS
);
9631 SET_EXPR_LOCATION (stmt
, sections_loc
);
9632 TREE_TYPE (stmt
) = void_type_node
;
9633 OMP_SECTIONS_BODY (stmt
) = substmt
;
9635 return add_stmt (stmt
);
9639 # pragma omp sections sections-clause[optseq] newline
9642 LOC is the location of the #pragma token.
9645 #define OMP_SECTIONS_CLAUSE_MASK \
9646 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
9647 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
9648 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
9649 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
9650 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
9653 c_parser_omp_sections (location_t loc
, c_parser
*parser
)
9655 tree block
, clauses
, ret
;
9657 clauses
= c_parser_omp_all_clauses (parser
, OMP_SECTIONS_CLAUSE_MASK
,
9658 "#pragma omp sections");
9660 block
= c_begin_compound_stmt (true);
9661 ret
= c_parser_omp_sections_scope (loc
, parser
);
9663 OMP_SECTIONS_CLAUSES (ret
) = clauses
;
9664 block
= c_end_compound_stmt (loc
, block
, true);
9671 # pragma parallel parallel-clause new-line
9672 # pragma parallel for parallel-for-clause new-line
9673 # pragma parallel sections parallel-sections-clause new-line
9675 LOC is the location of the #pragma token.
9678 #define OMP_PARALLEL_CLAUSE_MASK \
9679 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
9680 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
9681 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
9682 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
9683 | (1u << PRAGMA_OMP_CLAUSE_SHARED) \
9684 | (1u << PRAGMA_OMP_CLAUSE_COPYIN) \
9685 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
9686 | (1u << PRAGMA_OMP_CLAUSE_NUM_THREADS))
9689 c_parser_omp_parallel (location_t loc
, c_parser
*parser
)
9691 enum pragma_kind p_kind
= PRAGMA_OMP_PARALLEL
;
9692 const char *p_name
= "#pragma omp parallel";
9693 tree stmt
, clauses
, par_clause
, ws_clause
, block
;
9694 unsigned int mask
= OMP_PARALLEL_CLAUSE_MASK
;
9696 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
9698 c_parser_consume_token (parser
);
9699 p_kind
= PRAGMA_OMP_PARALLEL_FOR
;
9700 p_name
= "#pragma omp parallel for";
9701 mask
|= OMP_FOR_CLAUSE_MASK
;
9702 mask
&= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT
);
9704 else if (c_parser_next_token_is (parser
, CPP_NAME
))
9706 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
9707 if (strcmp (p
, "sections") == 0)
9709 c_parser_consume_token (parser
);
9710 p_kind
= PRAGMA_OMP_PARALLEL_SECTIONS
;
9711 p_name
= "#pragma omp parallel sections";
9712 mask
|= OMP_SECTIONS_CLAUSE_MASK
;
9713 mask
&= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT
);
9717 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
);
9721 case PRAGMA_OMP_PARALLEL
:
9722 block
= c_begin_omp_parallel ();
9723 c_parser_statement (parser
);
9724 stmt
= c_finish_omp_parallel (loc
, clauses
, block
);
9727 case PRAGMA_OMP_PARALLEL_FOR
:
9728 block
= c_begin_omp_parallel ();
9729 c_split_parallel_clauses (loc
, clauses
, &par_clause
, &ws_clause
);
9730 c_parser_omp_for_loop (loc
, parser
, ws_clause
, &par_clause
);
9731 stmt
= c_finish_omp_parallel (loc
, par_clause
, block
);
9732 OMP_PARALLEL_COMBINED (stmt
) = 1;
9735 case PRAGMA_OMP_PARALLEL_SECTIONS
:
9736 block
= c_begin_omp_parallel ();
9737 c_split_parallel_clauses (loc
, clauses
, &par_clause
, &ws_clause
);
9738 stmt
= c_parser_omp_sections_scope (loc
, parser
);
9740 OMP_SECTIONS_CLAUSES (stmt
) = ws_clause
;
9741 stmt
= c_finish_omp_parallel (loc
, par_clause
, block
);
9742 OMP_PARALLEL_COMBINED (stmt
) = 1;
9753 # pragma omp single single-clause[optseq] new-line
9756 LOC is the location of the #pragma.
9759 #define OMP_SINGLE_CLAUSE_MASK \
9760 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
9761 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
9762 | (1u << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
9763 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
9766 c_parser_omp_single (location_t loc
, c_parser
*parser
)
9768 tree stmt
= make_node (OMP_SINGLE
);
9769 SET_EXPR_LOCATION (stmt
, loc
);
9770 TREE_TYPE (stmt
) = void_type_node
;
9772 OMP_SINGLE_CLAUSES (stmt
)
9773 = c_parser_omp_all_clauses (parser
, OMP_SINGLE_CLAUSE_MASK
,
9774 "#pragma omp single");
9775 OMP_SINGLE_BODY (stmt
) = c_parser_omp_structured_block (parser
);
9777 return add_stmt (stmt
);
9781 # pragma omp task task-clause[optseq] new-line
9783 LOC is the location of the #pragma.
9786 #define OMP_TASK_CLAUSE_MASK \
9787 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
9788 | (1u << PRAGMA_OMP_CLAUSE_UNTIED) \
9789 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
9790 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
9791 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
9792 | (1u << PRAGMA_OMP_CLAUSE_SHARED))
9795 c_parser_omp_task (location_t loc
, c_parser
*parser
)
9797 tree clauses
, block
;
9799 clauses
= c_parser_omp_all_clauses (parser
, OMP_TASK_CLAUSE_MASK
,
9800 "#pragma omp task");
9802 block
= c_begin_omp_task ();
9803 c_parser_statement (parser
);
9804 return c_finish_omp_task (loc
, clauses
, block
);
9808 # pragma omp taskwait new-line
9812 c_parser_omp_taskwait (c_parser
*parser
)
9814 location_t loc
= c_parser_peek_token (parser
)->location
;
9815 c_parser_consume_pragma (parser
);
9816 c_parser_skip_to_pragma_eol (parser
);
9818 c_finish_omp_taskwait (loc
);
9821 /* Main entry point to parsing most OpenMP pragmas. */
9824 c_parser_omp_construct (c_parser
*parser
)
9826 enum pragma_kind p_kind
;
9830 loc
= c_parser_peek_token (parser
)->location
;
9831 p_kind
= c_parser_peek_token (parser
)->pragma_kind
;
9832 c_parser_consume_pragma (parser
);
9836 case PRAGMA_OMP_ATOMIC
:
9837 c_parser_omp_atomic (loc
, parser
);
9839 case PRAGMA_OMP_CRITICAL
:
9840 stmt
= c_parser_omp_critical (loc
, parser
);
9842 case PRAGMA_OMP_FOR
:
9843 stmt
= c_parser_omp_for (loc
, parser
);
9845 case PRAGMA_OMP_MASTER
:
9846 stmt
= c_parser_omp_master (loc
, parser
);
9848 case PRAGMA_OMP_ORDERED
:
9849 stmt
= c_parser_omp_ordered (loc
, parser
);
9851 case PRAGMA_OMP_PARALLEL
:
9852 stmt
= c_parser_omp_parallel (loc
, parser
);
9854 case PRAGMA_OMP_SECTIONS
:
9855 stmt
= c_parser_omp_sections (loc
, parser
);
9857 case PRAGMA_OMP_SINGLE
:
9858 stmt
= c_parser_omp_single (loc
, parser
);
9860 case PRAGMA_OMP_TASK
:
9861 stmt
= c_parser_omp_task (loc
, parser
);
9868 gcc_assert (EXPR_LOCATION (stmt
) != UNKNOWN_LOCATION
);
9873 # pragma omp threadprivate (variable-list) */
9876 c_parser_omp_threadprivate (c_parser
*parser
)
9881 c_parser_consume_pragma (parser
);
9882 loc
= c_parser_peek_token (parser
)->location
;
9883 vars
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
9885 /* Mark every variable in VARS to be assigned thread local storage. */
9886 for (t
= vars
; t
; t
= TREE_CHAIN (t
))
9888 tree v
= TREE_PURPOSE (t
);
9890 /* FIXME diagnostics: Ideally we should keep individual
9891 locations for all the variables in the var list to make the
9892 following errors more precise. Perhaps
9893 c_parser_omp_var_list_parens() should construct a list of
9894 locations to go along with the var list. */
9896 /* If V had already been marked threadprivate, it doesn't matter
9897 whether it had been used prior to this point. */
9898 if (TREE_CODE (v
) != VAR_DECL
)
9899 error_at (loc
, "%qD is not a variable", v
);
9900 else if (TREE_USED (v
) && !C_DECL_THREADPRIVATE_P (v
))
9901 error_at (loc
, "%qE declared %<threadprivate%> after first use", v
);
9902 else if (! TREE_STATIC (v
) && ! DECL_EXTERNAL (v
))
9903 error_at (loc
, "automatic variable %qE cannot be %<threadprivate%>", v
);
9904 else if (TREE_TYPE (v
) == error_mark_node
)
9906 else if (! COMPLETE_TYPE_P (TREE_TYPE (v
)))
9907 error_at (loc
, "%<threadprivate%> %qE has incomplete type", v
);
9910 if (! DECL_THREAD_LOCAL_P (v
))
9912 DECL_TLS_MODEL (v
) = decl_default_tls_model (v
);
9913 /* If rtl has been already set for this var, call
9914 make_decl_rtl once again, so that encode_section_info
9915 has a chance to look at the new decl flags. */
9916 if (DECL_RTL_SET_P (v
))
9919 C_DECL_THREADPRIVATE_P (v
) = 1;
9923 c_parser_skip_to_pragma_eol (parser
);
9927 /* Parse a single source file. */
9932 /* Use local storage to begin. If the first token is a pragma, parse it.
9933 If it is #pragma GCC pch_preprocess, then this will load a PCH file
9934 which will cause garbage collection. */
9937 memset (&tparser
, 0, sizeof tparser
);
9938 the_parser
= &tparser
;
9940 if (c_parser_peek_token (&tparser
)->pragma_kind
== PRAGMA_GCC_PCH_PREPROCESS
)
9941 c_parser_pragma_pch_preprocess (&tparser
);
9943 the_parser
= ggc_alloc_c_parser ();
9944 *the_parser
= tparser
;
9946 /* Initialize EH, if we've been told to do so. */
9947 if (flag_exceptions
)
9948 using_eh_for_cleanups ();
9950 c_parser_translation_unit (the_parser
);
9954 #include "gt-c-parser.h"