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
, collection_expression
;
4763 location_t loc
= c_parser_peek_token (parser
)->location
;
4764 location_t for_loc
= c_parser_peek_token (parser
)->location
;
4765 bool is_foreach_statement
= false;
4766 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_FOR
));
4767 c_parser_consume_token (parser
);
4768 /* Open a compound statement in Objective-C as well, just in case this is
4769 as foreach expression. */
4770 block
= c_begin_compound_stmt (flag_isoc99
|| c_dialect_objc ());
4771 cond
= error_mark_node
;
4772 incr
= error_mark_node
;
4773 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4775 /* Parse the initialization declaration or expression. */
4776 object_expression
= error_mark_node
;
4777 parser
->objc_could_be_foreach_context
= c_dialect_objc ();
4778 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4780 parser
->objc_could_be_foreach_context
= false;
4781 c_parser_consume_token (parser
);
4782 c_finish_expr_stmt (loc
, NULL_TREE
);
4784 else if (c_parser_next_tokens_start_declaration (parser
))
4786 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
4787 &object_expression
);
4788 parser
->objc_could_be_foreach_context
= false;
4790 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
4792 c_parser_consume_token (parser
);
4793 is_foreach_statement
= true;
4794 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
4795 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
4798 check_for_loop_decls (for_loc
, flag_isoc99
);
4800 else if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
4802 /* __extension__ can start a declaration, but is also an
4803 unary operator that can start an expression. Consume all
4804 but the last of a possible series of __extension__ to
4806 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
4807 && (c_parser_peek_2nd_token (parser
)->keyword
4809 c_parser_consume_token (parser
);
4810 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
4813 ext
= disable_extension_diagnostics ();
4814 c_parser_consume_token (parser
);
4815 c_parser_declaration_or_fndef (parser
, true, true, true, true,
4816 true, &object_expression
);
4817 parser
->objc_could_be_foreach_context
= false;
4819 restore_extension_diagnostics (ext
);
4820 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
4822 c_parser_consume_token (parser
);
4823 is_foreach_statement
= true;
4824 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
4825 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
4828 check_for_loop_decls (for_loc
, flag_isoc99
);
4837 tree init_expression
;
4838 init_expression
= c_parser_expression (parser
).value
;
4839 parser
->objc_could_be_foreach_context
= false;
4840 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
4842 c_parser_consume_token (parser
);
4843 is_foreach_statement
= true;
4844 if (! lvalue_p (init_expression
))
4845 c_parser_error (parser
, "invalid iterating variable in fast enumeration");
4846 object_expression
= c_fully_fold (init_expression
, false, NULL
);
4850 c_finish_expr_stmt (loc
, init_expression
);
4851 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4855 /* Parse the loop condition. In the case of a foreach
4856 statement, there is no loop condition. */
4857 gcc_assert (!parser
->objc_could_be_foreach_context
);
4858 if (!is_foreach_statement
)
4860 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4862 c_parser_consume_token (parser
);
4867 cond
= c_parser_condition (parser
);
4868 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4871 /* Parse the increment expression (the third expression in a
4872 for-statement). In the case of a foreach-statement, this is
4873 the expression that follows the 'in'. */
4874 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4876 if (is_foreach_statement
)
4878 c_parser_error (parser
, "missing collection in fast enumeration");
4879 collection_expression
= error_mark_node
;
4882 incr
= c_process_expr_stmt (loc
, NULL_TREE
);
4886 if (is_foreach_statement
)
4887 collection_expression
= c_fully_fold (c_parser_expression (parser
).value
,
4890 incr
= c_process_expr_stmt (loc
, c_parser_expression (parser
).value
);
4892 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4894 save_break
= c_break_label
;
4895 c_break_label
= NULL_TREE
;
4896 save_cont
= c_cont_label
;
4897 c_cont_label
= NULL_TREE
;
4898 body
= c_parser_c99_block_statement (parser
);
4899 if (is_foreach_statement
)
4900 objc_finish_foreach_loop (loc
, object_expression
, collection_expression
, body
, c_break_label
, c_cont_label
);
4902 c_finish_loop (loc
, cond
, incr
, body
, c_break_label
, c_cont_label
, true);
4903 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
|| c_dialect_objc ()));
4904 c_break_label
= save_break
;
4905 c_cont_label
= save_cont
;
4908 /* Parse an asm statement, a GNU extension. This is a full-blown asm
4909 statement with inputs, outputs, clobbers, and volatile tag
4913 asm type-qualifier[opt] ( asm-argument ) ;
4914 asm type-qualifier[opt] goto ( asm-goto-argument ) ;
4918 asm-string-literal : asm-operands[opt]
4919 asm-string-literal : asm-operands[opt] : asm-operands[opt]
4920 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers[opt]
4923 asm-string-literal : : asm-operands[opt] : asm-clobbers[opt] \
4926 Qualifiers other than volatile are accepted in the syntax but
4930 c_parser_asm_statement (c_parser
*parser
)
4932 tree quals
, str
, outputs
, inputs
, clobbers
, labels
, ret
;
4933 bool simple
, is_goto
;
4934 location_t asm_loc
= c_parser_peek_token (parser
)->location
;
4935 int section
, nsections
;
4937 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
4938 c_parser_consume_token (parser
);
4939 if (c_parser_next_token_is_keyword (parser
, RID_VOLATILE
))
4941 quals
= c_parser_peek_token (parser
)->value
;
4942 c_parser_consume_token (parser
);
4944 else if (c_parser_next_token_is_keyword (parser
, RID_CONST
)
4945 || c_parser_next_token_is_keyword (parser
, RID_RESTRICT
))
4947 warning_at (c_parser_peek_token (parser
)->location
,
4949 "%E qualifier ignored on asm",
4950 c_parser_peek_token (parser
)->value
);
4952 c_parser_consume_token (parser
);
4958 if (c_parser_next_token_is_keyword (parser
, RID_GOTO
))
4960 c_parser_consume_token (parser
);
4964 /* ??? Follow the C++ parser rather than using the
4965 lex_untranslated_string kludge. */
4966 parser
->lex_untranslated_string
= true;
4969 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4972 str
= c_parser_asm_string_literal (parser
);
4973 if (str
== NULL_TREE
)
4974 goto error_close_paren
;
4977 outputs
= NULL_TREE
;
4979 clobbers
= NULL_TREE
;
4982 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
4985 /* Parse each colon-delimited section of operands. */
4986 nsections
= 3 + is_goto
;
4987 for (section
= 0; section
< nsections
; ++section
)
4989 if (!c_parser_require (parser
, CPP_COLON
,
4992 : "expected %<:%> or %<)%>"))
4993 goto error_close_paren
;
4995 /* Once past any colon, we're no longer a simple asm. */
4998 if ((!c_parser_next_token_is (parser
, CPP_COLON
)
4999 && !c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
5004 /* For asm goto, we don't allow output operands, but reserve
5005 the slot for a future extension that does allow them. */
5007 outputs
= c_parser_asm_operands (parser
, false);
5010 inputs
= c_parser_asm_operands (parser
, true);
5013 clobbers
= c_parser_asm_clobbers (parser
);
5016 labels
= c_parser_asm_goto_operands (parser
);
5022 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
5027 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
5029 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5033 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
5034 c_parser_skip_to_end_of_block_or_statement (parser
);
5036 ret
= build_asm_stmt (quals
, build_asm_expr (asm_loc
, str
, outputs
, inputs
,
5037 clobbers
, labels
, simple
));
5040 parser
->lex_untranslated_string
= false;
5044 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5048 /* Parse asm operands, a GNU extension. If CONVERT_P (for inputs but
5049 not outputs), apply the default conversion of functions and arrays
5054 asm-operands , asm-operand
5057 asm-string-literal ( expression )
5058 [ identifier ] asm-string-literal ( expression )
5062 c_parser_asm_operands (c_parser
*parser
, bool convert_p
)
5064 tree list
= NULL_TREE
;
5070 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
5072 c_parser_consume_token (parser
);
5073 if (c_parser_next_token_is (parser
, CPP_NAME
))
5075 tree id
= c_parser_peek_token (parser
)->value
;
5076 c_parser_consume_token (parser
);
5077 name
= build_string (IDENTIFIER_LENGTH (id
),
5078 IDENTIFIER_POINTER (id
));
5082 c_parser_error (parser
, "expected identifier");
5083 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
5086 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5091 str
= c_parser_asm_string_literal (parser
);
5092 if (str
== NULL_TREE
)
5094 parser
->lex_untranslated_string
= false;
5095 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5097 parser
->lex_untranslated_string
= true;
5100 loc
= c_parser_peek_token (parser
)->location
;
5101 expr
= c_parser_expression (parser
);
5102 mark_exp_read (expr
.value
);
5104 expr
= default_function_array_conversion (loc
, expr
);
5105 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
5106 parser
->lex_untranslated_string
= true;
5107 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
5109 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5112 list
= chainon (list
, build_tree_list (build_tree_list (name
, str
),
5114 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5115 c_parser_consume_token (parser
);
5122 /* Parse asm clobbers, a GNU extension.
5126 asm-clobbers , asm-string-literal
5130 c_parser_asm_clobbers (c_parser
*parser
)
5132 tree list
= NULL_TREE
;
5135 tree str
= c_parser_asm_string_literal (parser
);
5137 list
= tree_cons (NULL_TREE
, str
, list
);
5140 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5141 c_parser_consume_token (parser
);
5148 /* Parse asm goto labels, a GNU extension.
5152 asm-goto-operands , identifier
5156 c_parser_asm_goto_operands (c_parser
*parser
)
5158 tree list
= NULL_TREE
;
5163 if (c_parser_next_token_is (parser
, CPP_NAME
))
5165 c_token
*tok
= c_parser_peek_token (parser
);
5167 label
= lookup_label_for_goto (tok
->location
, name
);
5168 c_parser_consume_token (parser
);
5169 TREE_USED (label
) = 1;
5173 c_parser_error (parser
, "expected identifier");
5177 name
= build_string (IDENTIFIER_LENGTH (name
),
5178 IDENTIFIER_POINTER (name
));
5179 list
= tree_cons (name
, label
, list
);
5180 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5181 c_parser_consume_token (parser
);
5183 return nreverse (list
);
5187 /* Parse an expression other than a compound expression; that is, an
5188 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
5189 NULL then it is an Objective-C message expression which is the
5190 primary-expression starting the expression as an initializer.
5192 assignment-expression:
5193 conditional-expression
5194 unary-expression assignment-operator assignment-expression
5196 assignment-operator: one of
5197 = *= /= %= += -= <<= >>= &= ^= |=
5199 In GNU C we accept any conditional expression on the LHS and
5200 diagnose the invalid lvalue rather than producing a syntax
5203 static struct c_expr
5204 c_parser_expr_no_commas (c_parser
*parser
, struct c_expr
*after
)
5206 struct c_expr lhs
, rhs
, ret
;
5207 enum tree_code code
;
5208 location_t op_location
, exp_location
;
5209 gcc_assert (!after
|| c_dialect_objc ());
5210 lhs
= c_parser_conditional_expression (parser
, after
);
5211 op_location
= c_parser_peek_token (parser
)->location
;
5212 switch (c_parser_peek_token (parser
)->type
)
5221 code
= TRUNC_DIV_EXPR
;
5224 code
= TRUNC_MOD_EXPR
;
5239 code
= BIT_AND_EXPR
;
5242 code
= BIT_XOR_EXPR
;
5245 code
= BIT_IOR_EXPR
;
5250 c_parser_consume_token (parser
);
5251 exp_location
= c_parser_peek_token (parser
)->location
;
5252 rhs
= c_parser_expr_no_commas (parser
, NULL
);
5253 rhs
= default_function_array_read_conversion (exp_location
, rhs
);
5254 ret
.value
= build_modify_expr (op_location
, lhs
.value
, lhs
.original_type
,
5255 code
, exp_location
, rhs
.value
,
5257 if (code
== NOP_EXPR
)
5258 ret
.original_code
= MODIFY_EXPR
;
5261 TREE_NO_WARNING (ret
.value
) = 1;
5262 ret
.original_code
= ERROR_MARK
;
5264 ret
.original_type
= NULL
;
5268 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
5269 is not NULL then it is an Objective-C message expression which is
5270 the primary-expression starting the expression as an initializer.
5272 conditional-expression:
5273 logical-OR-expression
5274 logical-OR-expression ? expression : conditional-expression
5278 conditional-expression:
5279 logical-OR-expression ? : conditional-expression
5282 static struct c_expr
5283 c_parser_conditional_expression (c_parser
*parser
, struct c_expr
*after
)
5285 struct c_expr cond
, exp1
, exp2
, ret
;
5286 location_t cond_loc
, colon_loc
, middle_loc
;
5288 gcc_assert (!after
|| c_dialect_objc ());
5290 cond
= c_parser_binary_expression (parser
, after
);
5292 if (c_parser_next_token_is_not (parser
, CPP_QUERY
))
5294 cond_loc
= c_parser_peek_token (parser
)->location
;
5295 cond
= default_function_array_read_conversion (cond_loc
, cond
);
5296 c_parser_consume_token (parser
);
5297 if (c_parser_next_token_is (parser
, CPP_COLON
))
5299 tree eptype
= NULL_TREE
;
5301 middle_loc
= c_parser_peek_token (parser
)->location
;
5302 pedwarn (middle_loc
, OPT_pedantic
,
5303 "ISO C forbids omitting the middle term of a ?: expression");
5304 warn_for_omitted_condop (middle_loc
, cond
.value
);
5305 if (TREE_CODE (cond
.value
) == EXCESS_PRECISION_EXPR
)
5307 eptype
= TREE_TYPE (cond
.value
);
5308 cond
.value
= TREE_OPERAND (cond
.value
, 0);
5310 /* Make sure first operand is calculated only once. */
5311 exp1
.value
= c_save_expr (default_conversion (cond
.value
));
5313 exp1
.value
= build1 (EXCESS_PRECISION_EXPR
, eptype
, exp1
.value
);
5314 exp1
.original_type
= NULL
;
5315 cond
.value
= c_objc_common_truthvalue_conversion (cond_loc
, exp1
.value
);
5316 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_true_node
;
5321 = c_objc_common_truthvalue_conversion
5322 (cond_loc
, default_conversion (cond
.value
));
5323 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_false_node
;
5324 exp1
= c_parser_expression_conv (parser
);
5325 mark_exp_read (exp1
.value
);
5326 c_inhibit_evaluation_warnings
+=
5327 ((cond
.value
== truthvalue_true_node
)
5328 - (cond
.value
== truthvalue_false_node
));
5331 colon_loc
= c_parser_peek_token (parser
)->location
;
5332 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
5334 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
5335 ret
.value
= error_mark_node
;
5336 ret
.original_code
= ERROR_MARK
;
5337 ret
.original_type
= NULL
;
5341 location_t exp2_loc
= c_parser_peek_token (parser
)->location
;
5342 exp2
= c_parser_conditional_expression (parser
, NULL
);
5343 exp2
= default_function_array_read_conversion (exp2_loc
, exp2
);
5345 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
5346 ret
.value
= build_conditional_expr (colon_loc
, cond
.value
,
5347 cond
.original_code
== C_MAYBE_CONST_EXPR
,
5348 exp1
.value
, exp1
.original_type
,
5349 exp2
.value
, exp2
.original_type
);
5350 ret
.original_code
= ERROR_MARK
;
5351 if (exp1
.value
== error_mark_node
|| exp2
.value
== error_mark_node
)
5352 ret
.original_type
= NULL
;
5357 /* If both sides are enum type, the default conversion will have
5358 made the type of the result be an integer type. We want to
5359 remember the enum types we started with. */
5360 t1
= exp1
.original_type
? exp1
.original_type
: TREE_TYPE (exp1
.value
);
5361 t2
= exp2
.original_type
? exp2
.original_type
: TREE_TYPE (exp2
.value
);
5362 ret
.original_type
= ((t1
!= error_mark_node
5363 && t2
!= error_mark_node
5364 && (TYPE_MAIN_VARIANT (t1
)
5365 == TYPE_MAIN_VARIANT (t2
)))
5372 /* Parse a binary expression; that is, a logical-OR-expression (C90
5373 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
5374 an Objective-C message expression which is the primary-expression
5375 starting the expression as an initializer.
5377 multiplicative-expression:
5379 multiplicative-expression * cast-expression
5380 multiplicative-expression / cast-expression
5381 multiplicative-expression % cast-expression
5383 additive-expression:
5384 multiplicative-expression
5385 additive-expression + multiplicative-expression
5386 additive-expression - multiplicative-expression
5390 shift-expression << additive-expression
5391 shift-expression >> additive-expression
5393 relational-expression:
5395 relational-expression < shift-expression
5396 relational-expression > shift-expression
5397 relational-expression <= shift-expression
5398 relational-expression >= shift-expression
5400 equality-expression:
5401 relational-expression
5402 equality-expression == relational-expression
5403 equality-expression != relational-expression
5407 AND-expression & equality-expression
5409 exclusive-OR-expression:
5411 exclusive-OR-expression ^ AND-expression
5413 inclusive-OR-expression:
5414 exclusive-OR-expression
5415 inclusive-OR-expression | exclusive-OR-expression
5417 logical-AND-expression:
5418 inclusive-OR-expression
5419 logical-AND-expression && inclusive-OR-expression
5421 logical-OR-expression:
5422 logical-AND-expression
5423 logical-OR-expression || logical-AND-expression
5426 static struct c_expr
5427 c_parser_binary_expression (c_parser
*parser
, struct c_expr
*after
)
5429 /* A binary expression is parsed using operator-precedence parsing,
5430 with the operands being cast expressions. All the binary
5431 operators are left-associative. Thus a binary expression is of
5434 E0 op1 E1 op2 E2 ...
5436 which we represent on a stack. On the stack, the precedence
5437 levels are strictly increasing. When a new operator is
5438 encountered of higher precedence than that at the top of the
5439 stack, it is pushed; its LHS is the top expression, and its RHS
5440 is everything parsed until it is popped. When a new operator is
5441 encountered with precedence less than or equal to that at the top
5442 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
5443 by the result of the operation until the operator at the top of
5444 the stack has lower precedence than the new operator or there is
5445 only one element on the stack; then the top expression is the LHS
5446 of the new operator. In the case of logical AND and OR
5447 expressions, we also need to adjust c_inhibit_evaluation_warnings
5448 as appropriate when the operators are pushed and popped. */
5450 /* The precedence levels, where 0 is a dummy lowest level used for
5451 the bottom of the stack. */
5467 /* The expression at this stack level. */
5469 /* The precedence of the operator on its left, PREC_NONE at the
5470 bottom of the stack. */
5472 /* The operation on its left. */
5474 /* The source location of this operation. */
5478 /* Location of the binary operator. */
5479 location_t binary_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
5482 switch (stack[sp].op) \
5484 case TRUTH_ANDIF_EXPR: \
5485 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
5486 == truthvalue_false_node); \
5488 case TRUTH_ORIF_EXPR: \
5489 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
5490 == truthvalue_true_node); \
5495 stack[sp - 1].expr \
5496 = default_function_array_read_conversion (stack[sp - 1].loc, \
5497 stack[sp - 1].expr); \
5499 = default_function_array_read_conversion (stack[sp].loc, \
5501 stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc, \
5503 stack[sp - 1].expr, \
5507 gcc_assert (!after
|| c_dialect_objc ());
5508 stack
[0].loc
= c_parser_peek_token (parser
)->location
;
5509 stack
[0].expr
= c_parser_cast_expression (parser
, after
);
5510 stack
[0].prec
= PREC_NONE
;
5515 enum tree_code ocode
;
5518 switch (c_parser_peek_token (parser
)->type
)
5526 ocode
= TRUNC_DIV_EXPR
;
5530 ocode
= TRUNC_MOD_EXPR
;
5542 ocode
= LSHIFT_EXPR
;
5546 ocode
= RSHIFT_EXPR
;
5560 case CPP_GREATER_EQ
:
5573 oprec
= PREC_BITAND
;
5574 ocode
= BIT_AND_EXPR
;
5577 oprec
= PREC_BITXOR
;
5578 ocode
= BIT_XOR_EXPR
;
5582 ocode
= BIT_IOR_EXPR
;
5585 oprec
= PREC_LOGAND
;
5586 ocode
= TRUTH_ANDIF_EXPR
;
5590 ocode
= TRUTH_ORIF_EXPR
;
5593 /* Not a binary operator, so end of the binary
5597 binary_loc
= c_parser_peek_token (parser
)->location
;
5598 c_parser_consume_token (parser
);
5599 while (oprec
<= stack
[sp
].prec
)
5603 case TRUTH_ANDIF_EXPR
:
5605 = default_function_array_read_conversion (stack
[sp
].loc
,
5607 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
5608 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
5609 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
5610 == truthvalue_false_node
);
5612 case TRUTH_ORIF_EXPR
:
5614 = default_function_array_read_conversion (stack
[sp
].loc
,
5616 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
5617 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
5618 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
5619 == truthvalue_true_node
);
5625 stack
[sp
].loc
= binary_loc
;
5626 stack
[sp
].expr
= c_parser_cast_expression (parser
, NULL
);
5627 stack
[sp
].prec
= oprec
;
5628 stack
[sp
].op
= ocode
;
5629 stack
[sp
].loc
= binary_loc
;
5634 return stack
[0].expr
;
5638 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
5639 NULL then it is an Objective-C message expression which is the
5640 primary-expression starting the expression as an initializer.
5644 ( type-name ) unary-expression
5647 static struct c_expr
5648 c_parser_cast_expression (c_parser
*parser
, struct c_expr
*after
)
5650 location_t cast_loc
= c_parser_peek_token (parser
)->location
;
5651 gcc_assert (!after
|| c_dialect_objc ());
5653 return c_parser_postfix_expression_after_primary (parser
,
5655 /* If the expression begins with a parenthesized type name, it may
5656 be either a cast or a compound literal; we need to see whether
5657 the next character is '{' to tell the difference. If not, it is
5658 an unary expression. Full detection of unknown typenames here
5659 would require a 3-token lookahead. */
5660 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
5661 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
5663 struct c_type_name
*type_name
;
5666 c_parser_consume_token (parser
);
5667 type_name
= c_parser_type_name (parser
);
5668 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5669 if (type_name
== NULL
)
5671 ret
.value
= error_mark_node
;
5672 ret
.original_code
= ERROR_MARK
;
5673 ret
.original_type
= NULL
;
5677 /* Save casted types in the function's used types hash table. */
5678 used_types_insert (type_name
->specs
->type
);
5680 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5681 return c_parser_postfix_expression_after_paren_type (parser
, type_name
,
5684 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
5685 expr
= c_parser_cast_expression (parser
, NULL
);
5686 expr
= default_function_array_read_conversion (expr_loc
, expr
);
5688 ret
.value
= c_cast_expr (cast_loc
, type_name
, expr
.value
);
5689 ret
.original_code
= ERROR_MARK
;
5690 ret
.original_type
= NULL
;
5694 return c_parser_unary_expression (parser
);
5697 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
5703 unary-operator cast-expression
5704 sizeof unary-expression
5705 sizeof ( type-name )
5707 unary-operator: one of
5713 __alignof__ unary-expression
5714 __alignof__ ( type-name )
5717 unary-operator: one of
5718 __extension__ __real__ __imag__
5720 In addition, the GNU syntax treats ++ and -- as unary operators, so
5721 they may be applied to cast expressions with errors for non-lvalues
5724 static struct c_expr
5725 c_parser_unary_expression (c_parser
*parser
)
5728 struct c_expr ret
, op
;
5729 location_t op_loc
= c_parser_peek_token (parser
)->location
;
5731 ret
.original_code
= ERROR_MARK
;
5732 ret
.original_type
= NULL
;
5733 switch (c_parser_peek_token (parser
)->type
)
5736 c_parser_consume_token (parser
);
5737 exp_loc
= c_parser_peek_token (parser
)->location
;
5738 op
= c_parser_cast_expression (parser
, NULL
);
5739 op
= default_function_array_read_conversion (exp_loc
, op
);
5740 return parser_build_unary_op (op_loc
, PREINCREMENT_EXPR
, op
);
5741 case CPP_MINUS_MINUS
:
5742 c_parser_consume_token (parser
);
5743 exp_loc
= c_parser_peek_token (parser
)->location
;
5744 op
= c_parser_cast_expression (parser
, NULL
);
5745 op
= default_function_array_read_conversion (exp_loc
, op
);
5746 return parser_build_unary_op (op_loc
, PREDECREMENT_EXPR
, op
);
5748 c_parser_consume_token (parser
);
5749 op
= c_parser_cast_expression (parser
, NULL
);
5750 mark_exp_read (op
.value
);
5751 return parser_build_unary_op (op_loc
, ADDR_EXPR
, op
);
5753 c_parser_consume_token (parser
);
5754 exp_loc
= c_parser_peek_token (parser
)->location
;
5755 op
= c_parser_cast_expression (parser
, NULL
);
5756 op
= default_function_array_read_conversion (exp_loc
, op
);
5757 ret
.value
= build_indirect_ref (op_loc
, op
.value
, RO_UNARY_STAR
);
5760 if (!c_dialect_objc () && !in_system_header
)
5763 "traditional C rejects the unary plus operator");
5764 c_parser_consume_token (parser
);
5765 exp_loc
= c_parser_peek_token (parser
)->location
;
5766 op
= c_parser_cast_expression (parser
, NULL
);
5767 op
= default_function_array_read_conversion (exp_loc
, op
);
5768 return parser_build_unary_op (op_loc
, CONVERT_EXPR
, op
);
5770 c_parser_consume_token (parser
);
5771 exp_loc
= c_parser_peek_token (parser
)->location
;
5772 op
= c_parser_cast_expression (parser
, NULL
);
5773 op
= default_function_array_read_conversion (exp_loc
, op
);
5774 return parser_build_unary_op (op_loc
, NEGATE_EXPR
, op
);
5776 c_parser_consume_token (parser
);
5777 exp_loc
= c_parser_peek_token (parser
)->location
;
5778 op
= c_parser_cast_expression (parser
, NULL
);
5779 op
= default_function_array_read_conversion (exp_loc
, op
);
5780 return parser_build_unary_op (op_loc
, BIT_NOT_EXPR
, op
);
5782 c_parser_consume_token (parser
);
5783 exp_loc
= c_parser_peek_token (parser
)->location
;
5784 op
= c_parser_cast_expression (parser
, NULL
);
5785 op
= default_function_array_read_conversion (exp_loc
, op
);
5786 return parser_build_unary_op (op_loc
, TRUTH_NOT_EXPR
, op
);
5788 /* Refer to the address of a label as a pointer. */
5789 c_parser_consume_token (parser
);
5790 if (c_parser_next_token_is (parser
, CPP_NAME
))
5792 ret
.value
= finish_label_address_expr
5793 (c_parser_peek_token (parser
)->value
, op_loc
);
5794 c_parser_consume_token (parser
);
5798 c_parser_error (parser
, "expected identifier");
5799 ret
.value
= error_mark_node
;
5803 switch (c_parser_peek_token (parser
)->keyword
)
5806 return c_parser_sizeof_expression (parser
);
5808 return c_parser_alignof_expression (parser
);
5810 c_parser_consume_token (parser
);
5811 ext
= disable_extension_diagnostics ();
5812 ret
= c_parser_cast_expression (parser
, NULL
);
5813 restore_extension_diagnostics (ext
);
5816 c_parser_consume_token (parser
);
5817 exp_loc
= c_parser_peek_token (parser
)->location
;
5818 op
= c_parser_cast_expression (parser
, NULL
);
5819 op
= default_function_array_conversion (exp_loc
, op
);
5820 return parser_build_unary_op (op_loc
, REALPART_EXPR
, op
);
5822 c_parser_consume_token (parser
);
5823 exp_loc
= c_parser_peek_token (parser
)->location
;
5824 op
= c_parser_cast_expression (parser
, NULL
);
5825 op
= default_function_array_conversion (exp_loc
, op
);
5826 return parser_build_unary_op (op_loc
, IMAGPART_EXPR
, op
);
5828 return c_parser_postfix_expression (parser
);
5831 return c_parser_postfix_expression (parser
);
5835 /* Parse a sizeof expression. */
5837 static struct c_expr
5838 c_parser_sizeof_expression (c_parser
*parser
)
5841 location_t expr_loc
;
5842 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SIZEOF
));
5843 c_parser_consume_token (parser
);
5844 c_inhibit_evaluation_warnings
++;
5846 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
5847 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
5849 /* Either sizeof ( type-name ) or sizeof unary-expression
5850 starting with a compound literal. */
5851 struct c_type_name
*type_name
;
5852 c_parser_consume_token (parser
);
5853 expr_loc
= c_parser_peek_token (parser
)->location
;
5854 type_name
= c_parser_type_name (parser
);
5855 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5856 if (type_name
== NULL
)
5859 c_inhibit_evaluation_warnings
--;
5861 ret
.value
= error_mark_node
;
5862 ret
.original_code
= ERROR_MARK
;
5863 ret
.original_type
= NULL
;
5866 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5868 expr
= c_parser_postfix_expression_after_paren_type (parser
,
5873 /* sizeof ( type-name ). */
5874 c_inhibit_evaluation_warnings
--;
5876 return c_expr_sizeof_type (expr_loc
, type_name
);
5880 expr_loc
= c_parser_peek_token (parser
)->location
;
5881 expr
= c_parser_unary_expression (parser
);
5883 c_inhibit_evaluation_warnings
--;
5885 mark_exp_read (expr
.value
);
5886 if (TREE_CODE (expr
.value
) == COMPONENT_REF
5887 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
5888 error_at (expr_loc
, "%<sizeof%> applied to a bit-field");
5889 return c_expr_sizeof_expr (expr_loc
, expr
);
5893 /* Parse an alignof expression. */
5895 static struct c_expr
5896 c_parser_alignof_expression (c_parser
*parser
)
5899 location_t loc
= c_parser_peek_token (parser
)->location
;
5900 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNOF
));
5901 c_parser_consume_token (parser
);
5902 c_inhibit_evaluation_warnings
++;
5904 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
5905 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
5907 /* Either __alignof__ ( type-name ) or __alignof__
5908 unary-expression starting with a compound literal. */
5910 struct c_type_name
*type_name
;
5912 c_parser_consume_token (parser
);
5913 loc
= c_parser_peek_token (parser
)->location
;
5914 type_name
= c_parser_type_name (parser
);
5915 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5916 if (type_name
== NULL
)
5919 c_inhibit_evaluation_warnings
--;
5921 ret
.value
= error_mark_node
;
5922 ret
.original_code
= ERROR_MARK
;
5923 ret
.original_type
= NULL
;
5926 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5928 expr
= c_parser_postfix_expression_after_paren_type (parser
,
5933 /* alignof ( type-name ). */
5934 c_inhibit_evaluation_warnings
--;
5936 ret
.value
= c_alignof (loc
, groktypename (type_name
, NULL
, NULL
));
5937 ret
.original_code
= ERROR_MARK
;
5938 ret
.original_type
= NULL
;
5944 expr
= c_parser_unary_expression (parser
);
5946 mark_exp_read (expr
.value
);
5947 c_inhibit_evaluation_warnings
--;
5949 ret
.value
= c_alignof_expr (loc
, expr
.value
);
5950 ret
.original_code
= ERROR_MARK
;
5951 ret
.original_type
= NULL
;
5956 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
5960 postfix-expression [ expression ]
5961 postfix-expression ( argument-expression-list[opt] )
5962 postfix-expression . identifier
5963 postfix-expression -> identifier
5964 postfix-expression ++
5965 postfix-expression --
5966 ( type-name ) { initializer-list }
5967 ( type-name ) { initializer-list , }
5969 argument-expression-list:
5971 argument-expression-list , argument-expression
5983 (treated as a keyword in GNU C)
5986 ( compound-statement )
5987 __builtin_va_arg ( assignment-expression , type-name )
5988 __builtin_offsetof ( type-name , offsetof-member-designator )
5989 __builtin_choose_expr ( assignment-expression ,
5990 assignment-expression ,
5991 assignment-expression )
5992 __builtin_types_compatible_p ( type-name , type-name )
5994 offsetof-member-designator:
5996 offsetof-member-designator . identifier
5997 offsetof-member-designator [ expression ]
6002 [ objc-receiver objc-message-args ]
6003 @selector ( objc-selector-arg )
6004 @protocol ( identifier )
6005 @encode ( type-name )
6007 Classname . identifier
6010 static struct c_expr
6011 c_parser_postfix_expression (c_parser
*parser
)
6013 struct c_expr expr
, e1
, e2
, e3
;
6014 struct c_type_name
*t1
, *t2
;
6015 location_t loc
= c_parser_peek_token (parser
)->location
;;
6016 expr
.original_code
= ERROR_MARK
;
6017 expr
.original_type
= NULL
;
6018 switch (c_parser_peek_token (parser
)->type
)
6021 expr
.value
= c_parser_peek_token (parser
)->value
;
6022 loc
= c_parser_peek_token (parser
)->location
;
6023 c_parser_consume_token (parser
);
6024 if (TREE_CODE (expr
.value
) == FIXED_CST
6025 && !targetm
.fixed_point_supported_p ())
6027 error_at (loc
, "fixed-point types not supported for this target");
6028 expr
.value
= error_mark_node
;
6035 expr
.value
= c_parser_peek_token (parser
)->value
;
6036 c_parser_consume_token (parser
);
6042 case CPP_UTF8STRING
:
6043 expr
.value
= c_parser_peek_token (parser
)->value
;
6044 expr
.original_code
= STRING_CST
;
6045 c_parser_consume_token (parser
);
6047 case CPP_OBJC_STRING
:
6048 gcc_assert (c_dialect_objc ());
6050 = objc_build_string_object (c_parser_peek_token (parser
)->value
);
6051 c_parser_consume_token (parser
);
6054 switch (c_parser_peek_token (parser
)->id_kind
)
6058 tree id
= c_parser_peek_token (parser
)->value
;
6059 c_parser_consume_token (parser
);
6060 expr
.value
= build_external_ref (loc
, id
,
6061 (c_parser_peek_token (parser
)->type
6063 &expr
.original_type
);
6066 case C_ID_CLASSNAME
:
6068 /* Here we parse the Objective-C 2.0 Class.name dot
6070 tree class_name
= c_parser_peek_token (parser
)->value
;
6072 c_parser_consume_token (parser
);
6073 gcc_assert (c_dialect_objc ());
6074 if (!c_parser_require (parser
, CPP_DOT
, "expected %<.%>"))
6076 expr
.value
= error_mark_node
;
6079 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6081 c_parser_error (parser
, "expected identifier");
6082 expr
.value
= error_mark_node
;
6085 component
= c_parser_peek_token (parser
)->value
;
6086 c_parser_consume_token (parser
);
6087 expr
.value
= objc_build_class_component_ref (class_name
,
6092 c_parser_error (parser
, "expected expression");
6093 expr
.value
= error_mark_node
;
6097 case CPP_OPEN_PAREN
:
6098 /* A parenthesized expression, statement expression or compound
6100 if (c_parser_peek_2nd_token (parser
)->type
== CPP_OPEN_BRACE
)
6102 /* A statement expression. */
6104 location_t brace_loc
;
6105 c_parser_consume_token (parser
);
6106 brace_loc
= c_parser_peek_token (parser
)->location
;
6107 c_parser_consume_token (parser
);
6108 if (cur_stmt_list
== NULL
)
6110 error_at (loc
, "braced-group within expression allowed "
6111 "only inside a function");
6112 parser
->error
= true;
6113 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
6114 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6115 expr
.value
= error_mark_node
;
6118 stmt
= c_begin_stmt_expr ();
6119 c_parser_compound_statement_nostart (parser
);
6120 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6122 pedwarn (loc
, OPT_pedantic
,
6123 "ISO C forbids braced-groups within expressions");
6124 expr
.value
= c_finish_stmt_expr (brace_loc
, stmt
);
6125 mark_exp_read (expr
.value
);
6127 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6129 /* A compound literal. ??? Can we actually get here rather
6130 than going directly to
6131 c_parser_postfix_expression_after_paren_type from
6134 struct c_type_name
*type_name
;
6135 c_parser_consume_token (parser
);
6136 loc
= c_parser_peek_token (parser
)->location
;
6137 type_name
= c_parser_type_name (parser
);
6138 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6140 if (type_name
== NULL
)
6142 expr
.value
= error_mark_node
;
6145 expr
= c_parser_postfix_expression_after_paren_type (parser
,
6151 /* A parenthesized expression. */
6152 c_parser_consume_token (parser
);
6153 expr
= c_parser_expression (parser
);
6154 if (TREE_CODE (expr
.value
) == MODIFY_EXPR
)
6155 TREE_NO_WARNING (expr
.value
) = 1;
6156 if (expr
.original_code
!= C_MAYBE_CONST_EXPR
)
6157 expr
.original_code
= ERROR_MARK
;
6158 /* Don't change EXPR.ORIGINAL_TYPE. */
6159 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6164 switch (c_parser_peek_token (parser
)->keyword
)
6166 case RID_FUNCTION_NAME
:
6167 case RID_PRETTY_FUNCTION_NAME
:
6168 case RID_C99_FUNCTION_NAME
:
6169 expr
.value
= fname_decl (loc
,
6170 c_parser_peek_token (parser
)->keyword
,
6171 c_parser_peek_token (parser
)->value
);
6172 c_parser_consume_token (parser
);
6175 c_parser_consume_token (parser
);
6176 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6178 expr
.value
= error_mark_node
;
6181 e1
= c_parser_expr_no_commas (parser
, NULL
);
6182 mark_exp_read (e1
.value
);
6183 e1
.value
= c_fully_fold (e1
.value
, false, NULL
);
6184 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
6186 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6187 expr
.value
= error_mark_node
;
6190 loc
= c_parser_peek_token (parser
)->location
;
6191 t1
= c_parser_type_name (parser
);
6192 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6196 expr
.value
= error_mark_node
;
6200 tree type_expr
= NULL_TREE
;
6201 expr
.value
= c_build_va_arg (loc
, e1
.value
,
6202 groktypename (t1
, &type_expr
, NULL
));
6205 expr
.value
= build2 (C_MAYBE_CONST_EXPR
,
6206 TREE_TYPE (expr
.value
), type_expr
,
6208 C_MAYBE_CONST_EXPR_NON_CONST (expr
.value
) = true;
6213 c_parser_consume_token (parser
);
6214 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6216 expr
.value
= error_mark_node
;
6219 t1
= c_parser_type_name (parser
);
6221 parser
->error
= true;
6222 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
6223 gcc_assert (parser
->error
);
6226 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6227 expr
.value
= error_mark_node
;
6232 tree type
= groktypename (t1
, NULL
, NULL
);
6234 if (type
== error_mark_node
)
6235 offsetof_ref
= error_mark_node
;
6238 offsetof_ref
= build1 (INDIRECT_REF
, type
, null_pointer_node
);
6239 SET_EXPR_LOCATION (offsetof_ref
, loc
);
6241 /* Parse the second argument to __builtin_offsetof. We
6242 must have one identifier, and beyond that we want to
6243 accept sub structure and sub array references. */
6244 if (c_parser_next_token_is (parser
, CPP_NAME
))
6246 offsetof_ref
= build_component_ref
6247 (loc
, offsetof_ref
, c_parser_peek_token (parser
)->value
);
6248 c_parser_consume_token (parser
);
6249 while (c_parser_next_token_is (parser
, CPP_DOT
)
6250 || c_parser_next_token_is (parser
,
6252 || c_parser_next_token_is (parser
,
6255 if (c_parser_next_token_is (parser
, CPP_DEREF
))
6257 loc
= c_parser_peek_token (parser
)->location
;
6258 offsetof_ref
= build_array_ref (loc
,
6263 else if (c_parser_next_token_is (parser
, CPP_DOT
))
6266 c_parser_consume_token (parser
);
6267 if (c_parser_next_token_is_not (parser
,
6270 c_parser_error (parser
, "expected identifier");
6273 offsetof_ref
= build_component_ref
6275 c_parser_peek_token (parser
)->value
);
6276 c_parser_consume_token (parser
);
6281 loc
= c_parser_peek_token (parser
)->location
;
6282 c_parser_consume_token (parser
);
6283 idx
= c_parser_expression (parser
).value
;
6284 idx
= c_fully_fold (idx
, false, NULL
);
6285 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
6287 offsetof_ref
= build_array_ref (loc
, offsetof_ref
, idx
);
6292 c_parser_error (parser
, "expected identifier");
6293 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6295 expr
.value
= fold_offsetof (offsetof_ref
, NULL_TREE
);
6298 case RID_CHOOSE_EXPR
:
6299 c_parser_consume_token (parser
);
6300 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6302 expr
.value
= error_mark_node
;
6305 loc
= c_parser_peek_token (parser
)->location
;
6306 e1
= c_parser_expr_no_commas (parser
, NULL
);
6307 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
6309 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6310 expr
.value
= error_mark_node
;
6313 e2
= c_parser_expr_no_commas (parser
, NULL
);
6314 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
6316 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6317 expr
.value
= error_mark_node
;
6320 e3
= c_parser_expr_no_commas (parser
, NULL
);
6321 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6327 mark_exp_read (e2
.value
);
6328 mark_exp_read (e3
.value
);
6329 if (TREE_CODE (c
) != INTEGER_CST
6330 || !INTEGRAL_TYPE_P (TREE_TYPE (c
)))
6332 "first argument to %<__builtin_choose_expr%> not"
6334 constant_expression_warning (c
);
6335 expr
= integer_zerop (c
) ? e3
: e2
;
6338 case RID_TYPES_COMPATIBLE_P
:
6339 c_parser_consume_token (parser
);
6340 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6342 expr
.value
= error_mark_node
;
6345 t1
= c_parser_type_name (parser
);
6348 expr
.value
= error_mark_node
;
6351 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
6353 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6354 expr
.value
= error_mark_node
;
6357 t2
= c_parser_type_name (parser
);
6360 expr
.value
= error_mark_node
;
6363 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6368 e1
= TYPE_MAIN_VARIANT (groktypename (t1
, NULL
, NULL
));
6369 e2
= TYPE_MAIN_VARIANT (groktypename (t2
, NULL
, NULL
));
6372 = comptypes (e1
, e2
) ? integer_one_node
: integer_zero_node
;
6375 case RID_AT_SELECTOR
:
6376 gcc_assert (c_dialect_objc ());
6377 c_parser_consume_token (parser
);
6378 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6380 expr
.value
= error_mark_node
;
6384 tree sel
= c_parser_objc_selector_arg (parser
);
6385 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6387 expr
.value
= objc_build_selector_expr (loc
, sel
);
6390 case RID_AT_PROTOCOL
:
6391 gcc_assert (c_dialect_objc ());
6392 c_parser_consume_token (parser
);
6393 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6395 expr
.value
= error_mark_node
;
6398 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6400 c_parser_error (parser
, "expected identifier");
6401 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6402 expr
.value
= error_mark_node
;
6406 tree id
= c_parser_peek_token (parser
)->value
;
6407 c_parser_consume_token (parser
);
6408 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6410 expr
.value
= objc_build_protocol_expr (id
);
6414 /* Extension to support C-structures in the archiver. */
6415 gcc_assert (c_dialect_objc ());
6416 c_parser_consume_token (parser
);
6417 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6419 expr
.value
= error_mark_node
;
6422 t1
= c_parser_type_name (parser
);
6425 expr
.value
= error_mark_node
;
6426 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6429 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6432 tree type
= groktypename (t1
, NULL
, NULL
);
6433 expr
.value
= objc_build_encode_expr (type
);
6437 c_parser_error (parser
, "expected expression");
6438 expr
.value
= error_mark_node
;
6442 case CPP_OPEN_SQUARE
:
6443 if (c_dialect_objc ())
6445 tree receiver
, args
;
6446 c_parser_consume_token (parser
);
6447 receiver
= c_parser_objc_receiver (parser
);
6448 args
= c_parser_objc_message_args (parser
);
6449 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
6451 expr
.value
= objc_build_message_expr (build_tree_list (receiver
,
6455 /* Else fall through to report error. */
6457 c_parser_error (parser
, "expected expression");
6458 expr
.value
= error_mark_node
;
6461 return c_parser_postfix_expression_after_primary (parser
, loc
, expr
);
6464 /* Parse a postfix expression after a parenthesized type name: the
6465 brace-enclosed initializer of a compound literal, possibly followed
6466 by some postfix operators. This is separate because it is not
6467 possible to tell until after the type name whether a cast
6468 expression has a cast or a compound literal, or whether the operand
6469 of sizeof is a parenthesized type name or starts with a compound
6470 literal. TYPE_LOC is the location where TYPE_NAME starts--the
6471 location of the first token after the parentheses around the type
6474 static struct c_expr
6475 c_parser_postfix_expression_after_paren_type (c_parser
*parser
,
6476 struct c_type_name
*type_name
,
6477 location_t type_loc
)
6483 location_t start_loc
;
6484 tree type_expr
= NULL_TREE
;
6485 bool type_expr_const
= true;
6486 check_compound_literal_type (type_loc
, type_name
);
6487 start_init (NULL_TREE
, NULL
, 0);
6488 type
= groktypename (type_name
, &type_expr
, &type_expr_const
);
6489 start_loc
= c_parser_peek_token (parser
)->location
;
6490 if (type
!= error_mark_node
&& C_TYPE_VARIABLE_SIZE (type
))
6492 error_at (type_loc
, "compound literal has variable size");
6493 type
= error_mark_node
;
6495 init
= c_parser_braced_init (parser
, type
, false);
6497 maybe_warn_string_init (type
, init
);
6499 if (type
!= error_mark_node
6500 && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type
))
6501 && current_function_decl
)
6503 error ("compound literal qualified by address-space qualifier");
6504 type
= error_mark_node
;
6508 pedwarn (start_loc
, OPT_pedantic
, "ISO C90 forbids compound literals");
6509 non_const
= ((init
.value
&& TREE_CODE (init
.value
) == CONSTRUCTOR
)
6510 ? CONSTRUCTOR_NON_CONST (init
.value
)
6511 : init
.original_code
== C_MAYBE_CONST_EXPR
);
6512 non_const
|= !type_expr_const
;
6513 expr
.value
= build_compound_literal (start_loc
, type
, init
.value
, non_const
);
6514 expr
.original_code
= ERROR_MARK
;
6515 expr
.original_type
= NULL
;
6518 if (TREE_CODE (expr
.value
) == C_MAYBE_CONST_EXPR
)
6520 gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr
.value
) == NULL_TREE
);
6521 C_MAYBE_CONST_EXPR_PRE (expr
.value
) = type_expr
;
6525 gcc_assert (!non_const
);
6526 expr
.value
= build2 (C_MAYBE_CONST_EXPR
, type
,
6527 type_expr
, expr
.value
);
6530 return c_parser_postfix_expression_after_primary (parser
, start_loc
, expr
);
6533 /* Parse a postfix expression after the initial primary or compound
6534 literal; that is, parse a series of postfix operators.
6536 EXPR_LOC is the location of the primary expression. */
6538 static struct c_expr
6539 c_parser_postfix_expression_after_primary (c_parser
*parser
,
6540 location_t expr_loc
,
6543 struct c_expr orig_expr
;
6545 VEC(tree
,gc
) *exprlist
;
6546 VEC(tree
,gc
) *origtypes
;
6549 location_t op_loc
= c_parser_peek_token (parser
)->location
;
6550 switch (c_parser_peek_token (parser
)->type
)
6552 case CPP_OPEN_SQUARE
:
6553 /* Array reference. */
6554 c_parser_consume_token (parser
);
6555 idx
= c_parser_expression (parser
).value
;
6556 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
6558 expr
.value
= build_array_ref (op_loc
, expr
.value
, idx
);
6559 expr
.original_code
= ERROR_MARK
;
6560 expr
.original_type
= NULL
;
6562 case CPP_OPEN_PAREN
:
6563 /* Function call. */
6564 c_parser_consume_token (parser
);
6565 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
6568 exprlist
= c_parser_expr_list (parser
, true, false, &origtypes
);
6569 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6572 mark_exp_read (expr
.value
);
6573 /* FIXME diagnostics: Ideally we want the FUNCNAME, not the
6574 "(" after the FUNCNAME, which is what we have now. */
6575 expr
.value
= build_function_call_vec (op_loc
, expr
.value
, exprlist
,
6577 expr
.original_code
= ERROR_MARK
;
6578 if (TREE_CODE (expr
.value
) == INTEGER_CST
6579 && TREE_CODE (orig_expr
.value
) == FUNCTION_DECL
6580 && DECL_BUILT_IN_CLASS (orig_expr
.value
) == BUILT_IN_NORMAL
6581 && DECL_FUNCTION_CODE (orig_expr
.value
) == BUILT_IN_CONSTANT_P
)
6582 expr
.original_code
= C_MAYBE_CONST_EXPR
;
6583 expr
.original_type
= NULL
;
6584 if (exprlist
!= NULL
)
6586 release_tree_vector (exprlist
);
6587 release_tree_vector (origtypes
);
6591 /* Structure element reference. */
6592 c_parser_consume_token (parser
);
6593 expr
= default_function_array_conversion (expr_loc
, expr
);
6594 if (c_parser_next_token_is (parser
, CPP_NAME
))
6595 ident
= c_parser_peek_token (parser
)->value
;
6598 c_parser_error (parser
, "expected identifier");
6599 expr
.value
= error_mark_node
;
6600 expr
.original_code
= ERROR_MARK
;
6601 expr
.original_type
= NULL
;
6604 c_parser_consume_token (parser
);
6605 expr
.value
= build_component_ref (op_loc
, expr
.value
, ident
);
6606 expr
.original_code
= ERROR_MARK
;
6607 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
6608 expr
.original_type
= NULL
;
6611 /* Remember the original type of a bitfield. */
6612 tree field
= TREE_OPERAND (expr
.value
, 1);
6613 if (TREE_CODE (field
) != FIELD_DECL
)
6614 expr
.original_type
= NULL
;
6616 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
6620 /* Structure element reference. */
6621 c_parser_consume_token (parser
);
6622 expr
= default_function_array_conversion (expr_loc
, expr
);
6623 if (c_parser_next_token_is (parser
, CPP_NAME
))
6624 ident
= c_parser_peek_token (parser
)->value
;
6627 c_parser_error (parser
, "expected identifier");
6628 expr
.value
= error_mark_node
;
6629 expr
.original_code
= ERROR_MARK
;
6630 expr
.original_type
= NULL
;
6633 c_parser_consume_token (parser
);
6634 expr
.value
= build_component_ref (op_loc
,
6635 build_indirect_ref (op_loc
,
6639 expr
.original_code
= ERROR_MARK
;
6640 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
6641 expr
.original_type
= NULL
;
6644 /* Remember the original type of a bitfield. */
6645 tree field
= TREE_OPERAND (expr
.value
, 1);
6646 if (TREE_CODE (field
) != FIELD_DECL
)
6647 expr
.original_type
= NULL
;
6649 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
6653 /* Postincrement. */
6654 c_parser_consume_token (parser
);
6655 expr
= default_function_array_read_conversion (expr_loc
, expr
);
6656 expr
.value
= build_unary_op (op_loc
,
6657 POSTINCREMENT_EXPR
, expr
.value
, 0);
6658 expr
.original_code
= ERROR_MARK
;
6659 expr
.original_type
= NULL
;
6661 case CPP_MINUS_MINUS
:
6662 /* Postdecrement. */
6663 c_parser_consume_token (parser
);
6664 expr
= default_function_array_read_conversion (expr_loc
, expr
);
6665 expr
.value
= build_unary_op (op_loc
,
6666 POSTDECREMENT_EXPR
, expr
.value
, 0);
6667 expr
.original_code
= ERROR_MARK
;
6668 expr
.original_type
= NULL
;
6676 /* Parse an expression (C90 6.3.17, C99 6.5.17).
6679 assignment-expression
6680 expression , assignment-expression
6683 static struct c_expr
6684 c_parser_expression (c_parser
*parser
)
6687 expr
= c_parser_expr_no_commas (parser
, NULL
);
6688 while (c_parser_next_token_is (parser
, CPP_COMMA
))
6692 location_t loc
= c_parser_peek_token (parser
)->location
;
6693 location_t expr_loc
;
6694 c_parser_consume_token (parser
);
6695 expr_loc
= c_parser_peek_token (parser
)->location
;
6696 lhsval
= expr
.value
;
6697 while (TREE_CODE (lhsval
) == COMPOUND_EXPR
)
6698 lhsval
= TREE_OPERAND (lhsval
, 1);
6699 if (DECL_P (lhsval
) || handled_component_p (lhsval
))
6700 mark_exp_read (lhsval
);
6701 next
= c_parser_expr_no_commas (parser
, NULL
);
6702 next
= default_function_array_conversion (expr_loc
, next
);
6703 expr
.value
= build_compound_expr (loc
, expr
.value
, next
.value
);
6704 expr
.original_code
= COMPOUND_EXPR
;
6705 expr
.original_type
= next
.original_type
;
6710 /* Parse an expression and convert functions or arrays to
6713 static struct c_expr
6714 c_parser_expression_conv (c_parser
*parser
)
6717 location_t loc
= c_parser_peek_token (parser
)->location
;
6718 expr
= c_parser_expression (parser
);
6719 expr
= default_function_array_conversion (loc
, expr
);
6723 /* Parse a non-empty list of expressions. If CONVERT_P, convert
6724 functions and arrays to pointers. If FOLD_P, fold the expressions.
6727 assignment-expression
6728 nonempty-expr-list , assignment-expression
6731 static VEC(tree
,gc
) *
6732 c_parser_expr_list (c_parser
*parser
, bool convert_p
, bool fold_p
,
6733 VEC(tree
,gc
) **p_orig_types
)
6736 VEC(tree
,gc
) *orig_types
;
6738 location_t loc
= c_parser_peek_token (parser
)->location
;
6740 ret
= make_tree_vector ();
6741 if (p_orig_types
== NULL
)
6744 orig_types
= make_tree_vector ();
6746 expr
= c_parser_expr_no_commas (parser
, NULL
);
6748 expr
= default_function_array_read_conversion (loc
, expr
);
6750 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
6751 VEC_quick_push (tree
, ret
, expr
.value
);
6752 if (orig_types
!= NULL
)
6753 VEC_quick_push (tree
, orig_types
, expr
.original_type
);
6754 while (c_parser_next_token_is (parser
, CPP_COMMA
))
6756 c_parser_consume_token (parser
);
6757 loc
= c_parser_peek_token (parser
)->location
;
6758 expr
= c_parser_expr_no_commas (parser
, NULL
);
6760 expr
= default_function_array_read_conversion (loc
, expr
);
6762 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
6763 VEC_safe_push (tree
, gc
, ret
, expr
.value
);
6764 if (orig_types
!= NULL
)
6765 VEC_safe_push (tree
, gc
, orig_types
, expr
.original_type
);
6767 if (orig_types
!= NULL
)
6768 *p_orig_types
= orig_types
;
6772 /* Parse Objective-C-specific constructs. */
6774 /* Parse an objc-class-definition.
6776 objc-class-definition:
6777 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
6778 objc-class-instance-variables[opt] objc-methodprotolist @end
6779 @implementation identifier objc-superclass[opt]
6780 objc-class-instance-variables[opt]
6781 @interface identifier ( identifier ) objc-protocol-refs[opt]
6782 objc-methodprotolist @end
6783 @interface identifier ( ) objc-protocol-refs[opt]
6784 objc-methodprotolist @end
6785 @implementation identifier ( identifier )
6790 "@interface identifier (" must start "@interface identifier (
6791 identifier ) ...": objc-methodprotolist in the first production may
6792 not start with a parenthesized identifier as a declarator of a data
6793 definition with no declaration specifiers if the objc-superclass,
6794 objc-protocol-refs and objc-class-instance-variables are omitted. */
6797 c_parser_objc_class_definition (c_parser
*parser
, tree attributes
)
6802 if (c_parser_next_token_is_keyword (parser
, RID_AT_INTERFACE
))
6804 else if (c_parser_next_token_is_keyword (parser
, RID_AT_IMPLEMENTATION
))
6809 c_parser_consume_token (parser
);
6810 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6812 c_parser_error (parser
, "expected identifier");
6815 id1
= c_parser_peek_token (parser
)->value
;
6816 c_parser_consume_token (parser
);
6817 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
6819 /* We have a category or class extension. */
6821 tree proto
= NULL_TREE
;
6822 c_parser_consume_token (parser
);
6823 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6825 if (iface_p
&& c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
6827 /* We have a class extension. */
6832 c_parser_error (parser
, "expected identifier or %<)%>");
6833 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6839 id2
= c_parser_peek_token (parser
)->value
;
6840 c_parser_consume_token (parser
);
6842 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6845 objc_start_category_implementation (id1
, id2
);
6848 if (c_parser_next_token_is (parser
, CPP_LESS
))
6849 proto
= c_parser_objc_protocol_refs (parser
);
6850 objc_start_category_interface (id1
, id2
, proto
, attributes
);
6851 c_parser_objc_methodprotolist (parser
);
6852 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
6853 objc_finish_interface ();
6856 if (c_parser_next_token_is (parser
, CPP_COLON
))
6858 c_parser_consume_token (parser
);
6859 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6861 c_parser_error (parser
, "expected identifier");
6864 superclass
= c_parser_peek_token (parser
)->value
;
6865 c_parser_consume_token (parser
);
6868 superclass
= NULL_TREE
;
6871 tree proto
= NULL_TREE
;
6872 if (c_parser_next_token_is (parser
, CPP_LESS
))
6873 proto
= c_parser_objc_protocol_refs (parser
);
6874 objc_start_class_interface (id1
, superclass
, proto
, attributes
);
6877 objc_start_class_implementation (id1
, superclass
);
6878 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6879 c_parser_objc_class_instance_variables (parser
);
6882 objc_continue_interface ();
6883 c_parser_objc_methodprotolist (parser
);
6884 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
6885 objc_finish_interface ();
6889 objc_continue_implementation ();
6894 /* Parse objc-class-instance-variables.
6896 objc-class-instance-variables:
6897 { objc-instance-variable-decl-list[opt] }
6899 objc-instance-variable-decl-list:
6900 objc-visibility-spec
6901 objc-instance-variable-decl ;
6903 objc-instance-variable-decl-list objc-visibility-spec
6904 objc-instance-variable-decl-list objc-instance-variable-decl ;
6905 objc-instance-variable-decl-list ;
6907 objc-visibility-spec:
6912 objc-instance-variable-decl:
6917 c_parser_objc_class_instance_variables (c_parser
*parser
)
6919 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
6920 c_parser_consume_token (parser
);
6921 while (c_parser_next_token_is_not (parser
, CPP_EOF
))
6924 /* Parse any stray semicolon. */
6925 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
6927 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
6928 "extra semicolon in struct or union specified");
6929 c_parser_consume_token (parser
);
6932 /* Stop if at the end of the instance variables. */
6933 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
6935 c_parser_consume_token (parser
);
6938 /* Parse any objc-visibility-spec. */
6939 if (c_parser_next_token_is_keyword (parser
, RID_AT_PRIVATE
))
6941 c_parser_consume_token (parser
);
6942 objc_set_visibility (OBJC_IVAR_VIS_PRIVATE
);
6945 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROTECTED
))
6947 c_parser_consume_token (parser
);
6948 objc_set_visibility (OBJC_IVAR_VIS_PROTECTED
);
6951 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PUBLIC
))
6953 c_parser_consume_token (parser
);
6954 objc_set_visibility (OBJC_IVAR_VIS_PUBLIC
);
6957 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PACKAGE
))
6959 c_parser_consume_token (parser
);
6960 objc_set_visibility (OBJC_IVAR_VIS_PACKAGE
);
6963 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
6965 c_parser_pragma (parser
, pragma_external
);
6969 /* Parse some comma-separated declarations. */
6970 decls
= c_parser_struct_declaration (parser
);
6972 /* Comma-separated instance variables are chained together in
6973 reverse order; add them one by one. */
6974 tree ivar
= nreverse (decls
);
6975 for (; ivar
; ivar
= DECL_CHAIN (ivar
))
6976 objc_add_instance_variable (copy_node (ivar
));
6978 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
6982 /* Parse an objc-class-declaration.
6984 objc-class-declaration:
6985 @class identifier-list ;
6989 c_parser_objc_class_declaration (c_parser
*parser
)
6991 tree list
= NULL_TREE
;
6992 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_CLASS
));
6993 c_parser_consume_token (parser
);
6994 /* Any identifiers, including those declared as type names, are OK
6999 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7001 c_parser_error (parser
, "expected identifier");
7002 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
7003 parser
->error
= false;
7006 id
= c_parser_peek_token (parser
)->value
;
7007 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
7008 c_parser_consume_token (parser
);
7009 if (c_parser_next_token_is (parser
, CPP_COMMA
))
7010 c_parser_consume_token (parser
);
7014 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7015 objc_declare_class (list
);
7018 /* Parse an objc-alias-declaration.
7020 objc-alias-declaration:
7021 @compatibility_alias identifier identifier ;
7025 c_parser_objc_alias_declaration (c_parser
*parser
)
7028 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_ALIAS
));
7029 c_parser_consume_token (parser
);
7030 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7032 c_parser_error (parser
, "expected identifier");
7033 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
7036 id1
= c_parser_peek_token (parser
)->value
;
7037 c_parser_consume_token (parser
);
7038 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7040 c_parser_error (parser
, "expected identifier");
7041 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
7044 id2
= c_parser_peek_token (parser
)->value
;
7045 c_parser_consume_token (parser
);
7046 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7047 objc_declare_alias (id1
, id2
);
7050 /* Parse an objc-protocol-definition.
7052 objc-protocol-definition:
7053 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
7054 @protocol identifier-list ;
7056 "@protocol identifier ;" should be resolved as "@protocol
7057 identifier-list ;": objc-methodprotolist may not start with a
7058 semicolon in the first alternative if objc-protocol-refs are
7062 c_parser_objc_protocol_definition (c_parser
*parser
, tree attributes
)
7064 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROTOCOL
));
7066 c_parser_consume_token (parser
);
7067 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7069 c_parser_error (parser
, "expected identifier");
7072 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
7073 || c_parser_peek_2nd_token (parser
)->type
== CPP_SEMICOLON
)
7075 tree list
= NULL_TREE
;
7076 /* Any identifiers, including those declared as type names, are
7081 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7083 c_parser_error (parser
, "expected identifier");
7086 id
= c_parser_peek_token (parser
)->value
;
7087 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
7088 c_parser_consume_token (parser
);
7089 if (c_parser_next_token_is (parser
, CPP_COMMA
))
7090 c_parser_consume_token (parser
);
7094 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7095 objc_declare_protocols (list
, attributes
);
7099 tree id
= c_parser_peek_token (parser
)->value
;
7100 tree proto
= NULL_TREE
;
7101 c_parser_consume_token (parser
);
7102 if (c_parser_next_token_is (parser
, CPP_LESS
))
7103 proto
= c_parser_objc_protocol_refs (parser
);
7104 parser
->objc_pq_context
= true;
7105 objc_start_protocol (id
, proto
, attributes
);
7106 c_parser_objc_methodprotolist (parser
);
7107 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
7108 parser
->objc_pq_context
= false;
7109 objc_finish_interface ();
7113 /* Parse an objc-method-type.
7119 Return true if it is a class method (+) and false if it is
7120 an instance method (-).
7123 c_parser_objc_method_type (c_parser
*parser
)
7125 switch (c_parser_peek_token (parser
)->type
)
7128 c_parser_consume_token (parser
);
7131 c_parser_consume_token (parser
);
7138 /* Parse an objc-method-definition.
7140 objc-method-definition:
7141 objc-method-type objc-method-decl ;[opt] compound-statement
7145 c_parser_objc_method_definition (c_parser
*parser
)
7147 bool is_class_method
= c_parser_objc_method_type (parser
);
7148 tree decl
, attributes
= NULL_TREE
;
7149 parser
->objc_pq_context
= true;
7150 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
);
7151 if (decl
== error_mark_node
)
7152 return; /* Bail here. */
7154 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
7156 c_parser_consume_token (parser
);
7157 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
7158 "extra semicolon in method definition specified");
7161 if (!c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
7163 c_parser_error (parser
, "expected %<{%>");
7167 parser
->objc_pq_context
= false;
7168 if (objc_start_method_definition (is_class_method
, decl
, attributes
))
7170 add_stmt (c_parser_compound_statement (parser
));
7171 objc_finish_method_definition (current_function_decl
);
7175 /* This code is executed when we find a method definition
7176 outside of an @implementation context (or invalid for other
7177 reasons). Parse the method (to keep going) but do not emit
7180 c_parser_compound_statement (parser
);
7184 /* Parse an objc-methodprotolist.
7186 objc-methodprotolist:
7188 objc-methodprotolist objc-methodproto
7189 objc-methodprotolist declaration
7190 objc-methodprotolist ;
7194 The declaration is a data definition, which may be missing
7195 declaration specifiers under the same rules and diagnostics as
7196 other data definitions outside functions, and the stray semicolon
7197 is diagnosed the same way as a stray semicolon outside a
7201 c_parser_objc_methodprotolist (c_parser
*parser
)
7205 /* The list is terminated by @end. */
7206 switch (c_parser_peek_token (parser
)->type
)
7209 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
7210 "ISO C does not allow extra %<;%> outside of a function");
7211 c_parser_consume_token (parser
);
7215 c_parser_objc_methodproto (parser
);
7218 c_parser_pragma (parser
, pragma_external
);
7223 if (c_parser_next_token_is_keyword (parser
, RID_AT_END
))
7225 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
))
7226 c_parser_objc_at_property_declaration (parser
);
7227 else if (c_parser_next_token_is_keyword (parser
, RID_AT_OPTIONAL
))
7229 objc_set_method_opt (true);
7230 c_parser_consume_token (parser
);
7232 else if (c_parser_next_token_is_keyword (parser
, RID_AT_REQUIRED
))
7234 objc_set_method_opt (false);
7235 c_parser_consume_token (parser
);
7238 c_parser_declaration_or_fndef (parser
, false, false, true,
7245 /* Parse an objc-methodproto.
7248 objc-method-type objc-method-decl ;
7252 c_parser_objc_methodproto (c_parser
*parser
)
7254 bool is_class_method
= c_parser_objc_method_type (parser
);
7255 tree decl
, attributes
= NULL_TREE
;
7257 /* Remember protocol qualifiers in prototypes. */
7258 parser
->objc_pq_context
= true;
7259 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
);
7260 /* Forget protocol qualifiers now. */
7261 parser
->objc_pq_context
= false;
7263 /* Do not allow the presence of attributes to hide an erroneous
7264 method implementation in the interface section. */
7265 if (!c_parser_next_token_is (parser
, CPP_SEMICOLON
))
7267 c_parser_error (parser
, "expected %<;%>");
7271 if (decl
!= error_mark_node
)
7272 objc_add_method_declaration (is_class_method
, decl
, attributes
);
7274 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7277 /* If we are at a position that method attributes may be present, check that
7278 there are not any parsed already (a syntax error) and then collect any
7279 specified at the current location. Finally, if new attributes were present,
7280 check that the next token is legal ( ';' for decls and '{' for defs). */
7283 c_parser_objc_maybe_method_attributes (c_parser
* parser
, tree
* attributes
)
7288 c_parser_error (parser
,
7289 "method attributes must be specified at the end only");
7290 *attributes
= NULL_TREE
;
7294 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
7295 *attributes
= c_parser_attributes (parser
);
7297 /* If there were no attributes here, just report any earlier error. */
7298 if (*attributes
== NULL_TREE
|| bad
)
7301 /* If the attributes are followed by a ; or {, then just report any earlier
7303 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
7304 || c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
7307 /* We've got attributes, but not at the end. */
7308 c_parser_error (parser
,
7309 "expected %<;%> or %<{%> after method attribute definition");
7313 /* Parse an objc-method-decl.
7316 ( objc-type-name ) objc-selector
7318 ( objc-type-name ) objc-keyword-selector objc-optparmlist
7319 objc-keyword-selector objc-optparmlist
7322 objc-keyword-selector:
7324 objc-keyword-selector objc-keyword-decl
7327 objc-selector : ( objc-type-name ) identifier
7328 objc-selector : identifier
7329 : ( objc-type-name ) identifier
7333 objc-optparms objc-optellipsis
7337 objc-opt-parms , parameter-declaration
7345 c_parser_objc_method_decl (c_parser
*parser
, bool is_class_method
, tree
*attributes
)
7347 tree type
= NULL_TREE
;
7349 tree parms
= NULL_TREE
;
7350 bool ellipsis
= false;
7351 bool attr_err
= false;
7353 *attributes
= NULL_TREE
;
7354 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
7356 c_parser_consume_token (parser
);
7357 type
= c_parser_objc_type_name (parser
);
7358 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7360 sel
= c_parser_objc_selector (parser
);
7361 /* If there is no selector, or a colon follows, we have an
7362 objc-keyword-selector. If there is a selector, and a colon does
7363 not follow, that selector ends the objc-method-decl. */
7364 if (!sel
|| c_parser_next_token_is (parser
, CPP_COLON
))
7367 tree list
= NULL_TREE
;
7370 tree atype
= NULL_TREE
, id
, keyworddecl
;
7371 tree param_attr
= NULL_TREE
;
7372 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
7374 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
7376 c_parser_consume_token (parser
);
7377 atype
= c_parser_objc_type_name (parser
);
7378 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7381 /* New ObjC allows attributes on method parameters. */
7382 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
7383 param_attr
= c_parser_attributes (parser
);
7384 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7386 c_parser_error (parser
, "expected identifier");
7387 return error_mark_node
;
7389 id
= c_parser_peek_token (parser
)->value
;
7390 c_parser_consume_token (parser
);
7391 keyworddecl
= objc_build_keyword_decl (tsel
, atype
, id
, param_attr
);
7392 list
= chainon (list
, keyworddecl
);
7393 tsel
= c_parser_objc_selector (parser
);
7394 if (!tsel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
7398 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
7400 /* Parse the optional parameter list. Optional Objective-C
7401 method parameters follow the C syntax, and may include '...'
7402 to denote a variable number of arguments. */
7403 parms
= make_node (TREE_LIST
);
7404 while (c_parser_next_token_is (parser
, CPP_COMMA
))
7406 struct c_parm
*parm
;
7407 c_parser_consume_token (parser
);
7408 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
7411 c_parser_consume_token (parser
);
7412 attr_err
|= c_parser_objc_maybe_method_attributes
7413 (parser
, attributes
) ;
7416 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
7419 parms
= chainon (parms
,
7420 build_tree_list (NULL_TREE
, grokparm (parm
)));
7425 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
7429 c_parser_error (parser
, "objective-c method declaration is expected");
7430 return error_mark_node
;
7434 return error_mark_node
;
7436 return objc_build_method_signature (is_class_method
, type
, sel
, parms
, ellipsis
);
7439 /* Parse an objc-type-name.
7442 objc-type-qualifiers[opt] type-name
7443 objc-type-qualifiers[opt]
7445 objc-type-qualifiers:
7447 objc-type-qualifiers objc-type-qualifier
7449 objc-type-qualifier: one of
7450 in out inout bycopy byref oneway
7454 c_parser_objc_type_name (c_parser
*parser
)
7456 tree quals
= NULL_TREE
;
7457 struct c_type_name
*type_name
= NULL
;
7458 tree type
= NULL_TREE
;
7461 c_token
*token
= c_parser_peek_token (parser
);
7462 if (token
->type
== CPP_KEYWORD
7463 && (token
->keyword
== RID_IN
7464 || token
->keyword
== RID_OUT
7465 || token
->keyword
== RID_INOUT
7466 || token
->keyword
== RID_BYCOPY
7467 || token
->keyword
== RID_BYREF
7468 || token
->keyword
== RID_ONEWAY
))
7470 quals
= chainon (build_tree_list (NULL_TREE
, token
->value
), quals
);
7471 c_parser_consume_token (parser
);
7476 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
7477 type_name
= c_parser_type_name (parser
);
7479 type
= groktypename (type_name
, NULL
, NULL
);
7481 /* If the type is unknown, and error has already been produced and
7482 we need to recover from the error. In that case, use NULL_TREE
7483 for the type, as if no type had been specified; this will use the
7484 default type ('id') which is good for error recovery. */
7485 if (type
== error_mark_node
)
7488 return build_tree_list (quals
, type
);
7491 /* Parse objc-protocol-refs.
7498 c_parser_objc_protocol_refs (c_parser
*parser
)
7500 tree list
= NULL_TREE
;
7501 gcc_assert (c_parser_next_token_is (parser
, CPP_LESS
));
7502 c_parser_consume_token (parser
);
7503 /* Any identifiers, including those declared as type names, are OK
7508 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7510 c_parser_error (parser
, "expected identifier");
7513 id
= c_parser_peek_token (parser
)->value
;
7514 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
7515 c_parser_consume_token (parser
);
7516 if (c_parser_next_token_is (parser
, CPP_COMMA
))
7517 c_parser_consume_token (parser
);
7521 c_parser_require (parser
, CPP_GREATER
, "expected %<>%>");
7525 /* Parse an objc-try-catch-finally-statement.
7527 objc-try-catch-finally-statement:
7528 @try compound-statement objc-catch-list[opt]
7529 @try compound-statement objc-catch-list[opt] @finally compound-statement
7532 @catch ( objc-catch-parameter-declaration ) compound-statement
7533 objc-catch-list @catch ( objc-catch-parameter-declaration ) compound-statement
7535 objc-catch-parameter-declaration:
7536 parameter-declaration
7539 where '...' is to be interpreted literally, that is, it means CPP_ELLIPSIS.
7541 PS: This function is identical to cp_parser_objc_try_catch_finally_statement
7542 for C++. Keep them in sync. */
7545 c_parser_objc_try_catch_finally_statement (c_parser
*parser
)
7547 location_t location
;
7550 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_TRY
));
7551 c_parser_consume_token (parser
);
7552 location
= c_parser_peek_token (parser
)->location
;
7553 objc_maybe_warn_exceptions (location
);
7554 stmt
= c_parser_compound_statement (parser
);
7555 objc_begin_try_stmt (location
, stmt
);
7557 while (c_parser_next_token_is_keyword (parser
, RID_AT_CATCH
))
7559 struct c_parm
*parm
;
7560 tree parameter_declaration
= error_mark_node
;
7561 bool seen_open_paren
= false;
7563 c_parser_consume_token (parser
);
7564 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7565 seen_open_paren
= true;
7566 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
7568 /* We have "@catch (...)" (where the '...' are literally
7569 what is in the code). Skip the '...'.
7570 parameter_declaration is set to NULL_TREE, and
7571 objc_being_catch_clauses() knows that that means
7573 c_parser_consume_token (parser
);
7574 parameter_declaration
= NULL_TREE
;
7578 /* We have "@catch (NSException *exception)" or something
7579 like that. Parse the parameter declaration. */
7580 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
7582 parameter_declaration
= error_mark_node
;
7584 parameter_declaration
= grokparm (parm
);
7586 if (seen_open_paren
)
7587 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7590 /* If there was no open parenthesis, we are recovering from
7591 an error, and we are trying to figure out what mistake
7592 the user has made. */
7594 /* If there is an immediate closing parenthesis, the user
7595 probably forgot the opening one (ie, they typed "@catch
7596 NSException *e)". Parse the closing parenthesis and keep
7598 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
7599 c_parser_consume_token (parser
);
7601 /* If these is no immediate closing parenthesis, the user
7602 probably doesn't know that parenthesis are required at
7603 all (ie, they typed "@catch NSException *e"). So, just
7604 forget about the closing parenthesis and keep going. */
7606 objc_begin_catch_clause (parameter_declaration
);
7607 if (c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
7608 c_parser_compound_statement_nostart (parser
);
7609 objc_finish_catch_clause ();
7611 if (c_parser_next_token_is_keyword (parser
, RID_AT_FINALLY
))
7613 c_parser_consume_token (parser
);
7614 location
= c_parser_peek_token (parser
)->location
;
7615 stmt
= c_parser_compound_statement (parser
);
7616 objc_build_finally_clause (location
, stmt
);
7618 objc_finish_try_stmt ();
7621 /* Parse an objc-synchronized-statement.
7623 objc-synchronized-statement:
7624 @synchronized ( expression ) compound-statement
7628 c_parser_objc_synchronized_statement (c_parser
*parser
)
7632 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNCHRONIZED
));
7633 c_parser_consume_token (parser
);
7634 loc
= c_parser_peek_token (parser
)->location
;
7635 objc_maybe_warn_exceptions (loc
);
7636 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7638 expr
= c_parser_expression (parser
).value
;
7639 expr
= c_fully_fold (expr
, false, NULL
);
7640 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7643 expr
= error_mark_node
;
7644 stmt
= c_parser_compound_statement (parser
);
7645 objc_build_synchronized (loc
, expr
, stmt
);
7648 /* Parse an objc-selector; return NULL_TREE without an error if the
7649 next token is not an objc-selector.
7654 enum struct union if else while do for switch case default
7655 break continue return goto asm sizeof typeof __alignof
7656 unsigned long const short volatile signed restrict _Complex
7657 in out inout bycopy byref oneway int char float double void _Bool
7659 ??? Why this selection of keywords but not, for example, storage
7660 class specifiers? */
7663 c_parser_objc_selector (c_parser
*parser
)
7665 c_token
*token
= c_parser_peek_token (parser
);
7666 tree value
= token
->value
;
7667 if (token
->type
== CPP_NAME
)
7669 c_parser_consume_token (parser
);
7672 if (token
->type
!= CPP_KEYWORD
)
7674 switch (token
->keyword
)
7716 c_parser_consume_token (parser
);
7723 /* Parse an objc-selector-arg.
7727 objc-keywordname-list
7729 objc-keywordname-list:
7731 objc-keywordname-list objc-keywordname
7739 c_parser_objc_selector_arg (c_parser
*parser
)
7741 tree sel
= c_parser_objc_selector (parser
);
7742 tree list
= NULL_TREE
;
7743 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
7747 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
7749 list
= chainon (list
, build_tree_list (sel
, NULL_TREE
));
7750 sel
= c_parser_objc_selector (parser
);
7751 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
7757 /* Parse an objc-receiver.
7766 c_parser_objc_receiver (c_parser
*parser
)
7768 if (c_parser_peek_token (parser
)->type
== CPP_NAME
7769 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
7770 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
7772 tree id
= c_parser_peek_token (parser
)->value
;
7773 c_parser_consume_token (parser
);
7774 return objc_get_class_reference (id
);
7776 return c_fully_fold (c_parser_expression (parser
).value
, false, NULL
);
7779 /* Parse objc-message-args.
7783 objc-keywordarg-list
7785 objc-keywordarg-list:
7787 objc-keywordarg-list objc-keywordarg
7790 objc-selector : objc-keywordexpr
7795 c_parser_objc_message_args (c_parser
*parser
)
7797 tree sel
= c_parser_objc_selector (parser
);
7798 tree list
= NULL_TREE
;
7799 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
7804 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
7805 return error_mark_node
;
7806 keywordexpr
= c_parser_objc_keywordexpr (parser
);
7807 list
= chainon (list
, build_tree_list (sel
, keywordexpr
));
7808 sel
= c_parser_objc_selector (parser
);
7809 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
7815 /* Parse an objc-keywordexpr.
7822 c_parser_objc_keywordexpr (c_parser
*parser
)
7825 VEC(tree
,gc
) *expr_list
= c_parser_expr_list (parser
, true, true, NULL
);
7826 if (VEC_length (tree
, expr_list
) == 1)
7828 /* Just return the expression, remove a level of
7830 ret
= VEC_index (tree
, expr_list
, 0);
7834 /* We have a comma expression, we will collapse later. */
7835 ret
= build_tree_list_vec (expr_list
);
7837 release_tree_vector (expr_list
);
7841 /* A check, needed in several places, that ObjC interface, implementation or
7842 method definitions are not prefixed by incorrect items. */
7844 c_parser_objc_diagnose_bad_element_prefix (c_parser
*parser
,
7845 struct c_declspecs
*specs
)
7847 if (!specs
->declspecs_seen_p
|| specs
->non_sc_seen_p
7848 || specs
->typespec_kind
!= ctsk_none
)
7850 c_parser_error (parser
,
7851 "no type or storage class may be specified here,");
7852 c_parser_skip_to_end_of_block_or_statement (parser
);
7858 /* Parse an Objective-C @property declaration. The syntax is:
7860 objc-property-declaration:
7861 '@property' objc-property-attributes[opt] struct-declaration ;
7863 objc-property-attributes:
7864 '(' objc-property-attribute-list ')'
7866 objc-property-attribute-list:
7867 objc-property-attribute
7868 objc-property-attribute-list, objc-property-attribute
7870 objc-property-attribute
7871 'getter' = identifier
7872 'setter' = identifier
7881 @property NSString *name;
7882 @property (readonly) id object;
7883 @property (retain, nonatomic, getter=getTheName) id name;
7884 @property int a, b, c;
7886 PS: This function is identical to cp_parser_objc_at_propery_declaration
7887 for C++. Keep them in sync. */
7889 c_parser_objc_at_property_declaration (c_parser
*parser
)
7891 /* The following variables hold the attributes of the properties as
7892 parsed. They are 'false' or 'NULL_TREE' if the attribute was not
7893 seen. When we see an attribute, we set them to 'true' (if they
7894 are boolean properties) or to the identifier (if they have an
7895 argument, ie, for getter and setter). Note that here we only
7896 parse the list of attributes, check the syntax and accumulate the
7897 attributes that we find. objc_add_property_declaration() will
7898 then process the information. */
7899 bool property_assign
= false;
7900 bool property_copy
= false;
7901 tree property_getter_ident
= NULL_TREE
;
7902 bool property_nonatomic
= false;
7903 bool property_readonly
= false;
7904 bool property_readwrite
= false;
7905 bool property_retain
= false;
7906 tree property_setter_ident
= NULL_TREE
;
7908 /* 'properties' is the list of properties that we read. Usually a
7909 single one, but maybe more (eg, in "@property int a, b, c;" there
7914 loc
= c_parser_peek_token (parser
)->location
;
7915 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
));
7917 c_parser_consume_token (parser
); /* Eat '@property'. */
7919 /* Parse the optional attribute list... */
7920 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
7923 c_parser_consume_token (parser
);
7925 /* Property attribute keywords are valid now. */
7926 parser
->objc_property_attr_context
= true;
7930 bool syntax_error
= false;
7931 c_token
*token
= c_parser_peek_token (parser
);
7934 if (token
->type
!= CPP_KEYWORD
)
7936 if (token
->type
== CPP_CLOSE_PAREN
)
7937 c_parser_error (parser
, "expected identifier");
7940 c_parser_consume_token (parser
);
7941 c_parser_error (parser
, "unknown property attribute");
7945 keyword
= token
->keyword
;
7946 c_parser_consume_token (parser
);
7949 case RID_ASSIGN
: property_assign
= true; break;
7950 case RID_COPY
: property_copy
= true; break;
7951 case RID_NONATOMIC
: property_nonatomic
= true; break;
7952 case RID_READONLY
: property_readonly
= true; break;
7953 case RID_READWRITE
: property_readwrite
= true; break;
7954 case RID_RETAIN
: property_retain
= true; break;
7958 if (c_parser_next_token_is_not (parser
, CPP_EQ
))
7960 if (keyword
== RID_GETTER
)
7961 c_parser_error (parser
,
7962 "missing %<=%> (after %<getter%> attribute)");
7964 c_parser_error (parser
,
7965 "missing %<=%> (after %<setter%> attribute)");
7966 syntax_error
= true;
7969 c_parser_consume_token (parser
); /* eat the = */
7970 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7972 c_parser_error (parser
, "expected identifier");
7973 syntax_error
= true;
7976 if (keyword
== RID_SETTER
)
7978 if (property_setter_ident
!= NULL_TREE
)
7979 c_parser_error (parser
, "the %<setter%> attribute may only be specified once");
7981 property_setter_ident
= c_parser_peek_token (parser
)->value
;
7982 c_parser_consume_token (parser
);
7983 if (c_parser_next_token_is_not (parser
, CPP_COLON
))
7984 c_parser_error (parser
, "setter name must terminate with %<:%>");
7986 c_parser_consume_token (parser
);
7990 if (property_getter_ident
!= NULL_TREE
)
7991 c_parser_error (parser
, "the %<getter%> attribute may only be specified once");
7993 property_getter_ident
= c_parser_peek_token (parser
)->value
;
7994 c_parser_consume_token (parser
);
7998 c_parser_error (parser
, "unknown property attribute");
7999 syntax_error
= true;
8006 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8007 c_parser_consume_token (parser
);
8011 parser
->objc_property_attr_context
= false;
8012 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8014 /* ... and the property declaration(s). */
8015 properties
= c_parser_struct_declaration (parser
);
8017 if (properties
== error_mark_node
)
8019 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8020 parser
->error
= false;
8024 if (properties
== NULL_TREE
)
8025 c_parser_error (parser
, "expected identifier");
8028 /* Comma-separated properties are chained together in
8029 reverse order; add them one by one. */
8030 properties
= nreverse (properties
);
8032 for (; properties
; properties
= TREE_CHAIN (properties
))
8033 objc_add_property_declaration (loc
, copy_node (properties
),
8034 property_readonly
, property_readwrite
,
8035 property_assign
, property_retain
,
8036 property_copy
, property_nonatomic
,
8037 property_getter_ident
, property_setter_ident
);
8040 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8041 parser
->error
= false;
8044 /* Parse an Objective-C @synthesize declaration. The syntax is:
8046 objc-synthesize-declaration:
8047 @synthesize objc-synthesize-identifier-list ;
8049 objc-synthesize-identifier-list:
8050 objc-synthesize-identifier
8051 objc-synthesize-identifier-list, objc-synthesize-identifier
8053 objc-synthesize-identifier
8055 identifier = identifier
8058 @synthesize MyProperty;
8059 @synthesize OneProperty, AnotherProperty=MyIvar, YetAnotherProperty;
8061 PS: This function is identical to cp_parser_objc_at_synthesize_declaration
8062 for C++. Keep them in sync.
8065 c_parser_objc_at_synthesize_declaration (c_parser
*parser
)
8067 tree list
= NULL_TREE
;
8069 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNTHESIZE
));
8070 loc
= c_parser_peek_token (parser
)->location
;
8072 c_parser_consume_token (parser
);
8075 tree property
, ivar
;
8076 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8078 c_parser_error (parser
, "expected identifier");
8079 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8080 /* Once we find the semicolon, we can resume normal parsing.
8081 We have to reset parser->error manually because
8082 c_parser_skip_until_found() won't reset it for us if the
8083 next token is precisely a semicolon. */
8084 parser
->error
= false;
8087 property
= c_parser_peek_token (parser
)->value
;
8088 c_parser_consume_token (parser
);
8089 if (c_parser_next_token_is (parser
, CPP_EQ
))
8091 c_parser_consume_token (parser
);
8092 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8094 c_parser_error (parser
, "expected identifier");
8095 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8096 parser
->error
= false;
8099 ivar
= c_parser_peek_token (parser
)->value
;
8100 c_parser_consume_token (parser
);
8104 list
= chainon (list
, build_tree_list (ivar
, property
));
8105 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8106 c_parser_consume_token (parser
);
8110 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8111 objc_add_synthesize_declaration (loc
, list
);
8114 /* Parse an Objective-C @dynamic declaration. The syntax is:
8116 objc-dynamic-declaration:
8117 @dynamic identifier-list ;
8120 @dynamic MyProperty;
8121 @dynamic MyProperty, AnotherProperty;
8123 PS: This function is identical to cp_parser_objc_at_dynamic_declaration
8124 for C++. Keep them in sync.
8127 c_parser_objc_at_dynamic_declaration (c_parser
*parser
)
8129 tree list
= NULL_TREE
;
8131 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_DYNAMIC
));
8132 loc
= c_parser_peek_token (parser
)->location
;
8134 c_parser_consume_token (parser
);
8138 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8140 c_parser_error (parser
, "expected identifier");
8141 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8142 parser
->error
= false;
8145 property
= c_parser_peek_token (parser
)->value
;
8146 list
= chainon (list
, build_tree_list (NULL_TREE
, property
));
8147 c_parser_consume_token (parser
);
8148 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8149 c_parser_consume_token (parser
);
8153 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8154 objc_add_dynamic_declaration (loc
, list
);
8158 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
8159 should be considered, statements. ALLOW_STMT is true if we're within
8160 the context of a function and such pragmas are to be allowed. Returns
8161 true if we actually parsed such a pragma. */
8164 c_parser_pragma (c_parser
*parser
, enum pragma_context context
)
8168 id
= c_parser_peek_token (parser
)->pragma_kind
;
8169 gcc_assert (id
!= PRAGMA_NONE
);
8173 case PRAGMA_OMP_BARRIER
:
8174 if (context
!= pragma_compound
)
8176 if (context
== pragma_stmt
)
8177 c_parser_error (parser
, "%<#pragma omp barrier%> may only be "
8178 "used in compound statements");
8181 c_parser_omp_barrier (parser
);
8184 case PRAGMA_OMP_FLUSH
:
8185 if (context
!= pragma_compound
)
8187 if (context
== pragma_stmt
)
8188 c_parser_error (parser
, "%<#pragma omp flush%> may only be "
8189 "used in compound statements");
8192 c_parser_omp_flush (parser
);
8195 case PRAGMA_OMP_TASKWAIT
:
8196 if (context
!= pragma_compound
)
8198 if (context
== pragma_stmt
)
8199 c_parser_error (parser
, "%<#pragma omp taskwait%> may only be "
8200 "used in compound statements");
8203 c_parser_omp_taskwait (parser
);
8206 case PRAGMA_OMP_THREADPRIVATE
:
8207 c_parser_omp_threadprivate (parser
);
8210 case PRAGMA_OMP_SECTION
:
8211 error_at (c_parser_peek_token (parser
)->location
,
8212 "%<#pragma omp section%> may only be used in "
8213 "%<#pragma omp sections%> construct");
8214 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
8217 case PRAGMA_GCC_PCH_PREPROCESS
:
8218 c_parser_error (parser
, "%<#pragma GCC pch_preprocess%> must be first");
8219 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
8223 if (id
< PRAGMA_FIRST_EXTERNAL
)
8225 if (context
== pragma_external
)
8228 c_parser_error (parser
, "expected declaration specifiers");
8229 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
8232 c_parser_omp_construct (parser
);
8238 c_parser_consume_pragma (parser
);
8239 c_invoke_pragma_handler (id
);
8241 /* Skip to EOL, but suppress any error message. Those will have been
8242 generated by the handler routine through calling error, as opposed
8243 to calling c_parser_error. */
8244 parser
->error
= true;
8245 c_parser_skip_to_pragma_eol (parser
);
8250 /* The interface the pragma parsers have to the lexer. */
8253 pragma_lex (tree
*value
)
8255 c_token
*tok
= c_parser_peek_token (the_parser
);
8256 enum cpp_ttype ret
= tok
->type
;
8258 *value
= tok
->value
;
8259 if (ret
== CPP_PRAGMA_EOL
|| ret
== CPP_EOF
)
8263 if (ret
== CPP_KEYWORD
)
8265 c_parser_consume_token (the_parser
);
8272 c_parser_pragma_pch_preprocess (c_parser
*parser
)
8276 c_parser_consume_pragma (parser
);
8277 if (c_parser_next_token_is (parser
, CPP_STRING
))
8279 name
= c_parser_peek_token (parser
)->value
;
8280 c_parser_consume_token (parser
);
8283 c_parser_error (parser
, "expected string literal");
8284 c_parser_skip_to_pragma_eol (parser
);
8287 c_common_pch_pragma (parse_in
, TREE_STRING_POINTER (name
));
8290 /* OpenMP 2.5 parsing routines. */
8292 /* Returns name of the next clause.
8293 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
8294 the token is not consumed. Otherwise appropriate pragma_omp_clause is
8295 returned and the token is consumed. */
8297 static pragma_omp_clause
8298 c_parser_omp_clause_name (c_parser
*parser
)
8300 pragma_omp_clause result
= PRAGMA_OMP_CLAUSE_NONE
;
8302 if (c_parser_next_token_is_keyword (parser
, RID_IF
))
8303 result
= PRAGMA_OMP_CLAUSE_IF
;
8304 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
8305 result
= PRAGMA_OMP_CLAUSE_DEFAULT
;
8306 else if (c_parser_next_token_is (parser
, CPP_NAME
))
8308 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
8313 if (!strcmp ("collapse", p
))
8314 result
= PRAGMA_OMP_CLAUSE_COLLAPSE
;
8315 else if (!strcmp ("copyin", p
))
8316 result
= PRAGMA_OMP_CLAUSE_COPYIN
;
8317 else if (!strcmp ("copyprivate", p
))
8318 result
= PRAGMA_OMP_CLAUSE_COPYPRIVATE
;
8321 if (!strcmp ("firstprivate", p
))
8322 result
= PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
;
8325 if (!strcmp ("lastprivate", p
))
8326 result
= PRAGMA_OMP_CLAUSE_LASTPRIVATE
;
8329 if (!strcmp ("nowait", p
))
8330 result
= PRAGMA_OMP_CLAUSE_NOWAIT
;
8331 else if (!strcmp ("num_threads", p
))
8332 result
= PRAGMA_OMP_CLAUSE_NUM_THREADS
;
8335 if (!strcmp ("ordered", p
))
8336 result
= PRAGMA_OMP_CLAUSE_ORDERED
;
8339 if (!strcmp ("private", p
))
8340 result
= PRAGMA_OMP_CLAUSE_PRIVATE
;
8343 if (!strcmp ("reduction", p
))
8344 result
= PRAGMA_OMP_CLAUSE_REDUCTION
;
8347 if (!strcmp ("schedule", p
))
8348 result
= PRAGMA_OMP_CLAUSE_SCHEDULE
;
8349 else if (!strcmp ("shared", p
))
8350 result
= PRAGMA_OMP_CLAUSE_SHARED
;
8353 if (!strcmp ("untied", p
))
8354 result
= PRAGMA_OMP_CLAUSE_UNTIED
;
8359 if (result
!= PRAGMA_OMP_CLAUSE_NONE
)
8360 c_parser_consume_token (parser
);
8365 /* Validate that a clause of the given type does not already exist. */
8368 check_no_duplicate_clause (tree clauses
, enum omp_clause_code code
,
8373 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
8374 if (OMP_CLAUSE_CODE (c
) == code
)
8376 location_t loc
= OMP_CLAUSE_LOCATION (c
);
8377 error_at (loc
, "too many %qs clauses", name
);
8385 variable-list , identifier
8387 If KIND is nonzero, create the appropriate node and install the
8388 decl in OMP_CLAUSE_DECL and add the node to the head of the list.
8389 If KIND is nonzero, CLAUSE_LOC is the location of the clause.
8391 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
8392 return the list created. */
8395 c_parser_omp_variable_list (c_parser
*parser
,
8396 location_t clause_loc
,
8397 enum omp_clause_code kind
,
8400 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
8401 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
8402 c_parser_error (parser
, "expected identifier");
8404 while (c_parser_next_token_is (parser
, CPP_NAME
)
8405 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
8407 tree t
= lookup_name (c_parser_peek_token (parser
)->value
);
8410 undeclared_variable (c_parser_peek_token (parser
)->location
,
8411 c_parser_peek_token (parser
)->value
);
8412 else if (t
== error_mark_node
)
8416 tree u
= build_omp_clause (clause_loc
, kind
);
8417 OMP_CLAUSE_DECL (u
) = t
;
8418 OMP_CLAUSE_CHAIN (u
) = list
;
8422 list
= tree_cons (t
, NULL_TREE
, list
);
8424 c_parser_consume_token (parser
);
8426 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
8429 c_parser_consume_token (parser
);
8435 /* Similarly, but expect leading and trailing parenthesis. This is a very
8436 common case for omp clauses. */
8439 c_parser_omp_var_list_parens (c_parser
*parser
, enum omp_clause_code kind
,
8442 /* The clauses location. */
8443 location_t loc
= c_parser_peek_token (parser
)->location
;
8445 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8447 list
= c_parser_omp_variable_list (parser
, loc
, kind
, list
);
8448 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8454 collapse ( constant-expression ) */
8457 c_parser_omp_clause_collapse (c_parser
*parser
, tree list
)
8459 tree c
, num
= error_mark_node
;
8463 check_no_duplicate_clause (list
, OMP_CLAUSE_COLLAPSE
, "collapse");
8465 loc
= c_parser_peek_token (parser
)->location
;
8466 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8468 num
= c_parser_expr_no_commas (parser
, NULL
).value
;
8469 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8471 if (num
== error_mark_node
)
8473 if (!INTEGRAL_TYPE_P (TREE_TYPE (num
))
8474 || !host_integerp (num
, 0)
8475 || (n
= tree_low_cst (num
, 0)) <= 0
8479 "collapse argument needs positive constant integer expression");
8482 c
= build_omp_clause (loc
, OMP_CLAUSE_COLLAPSE
);
8483 OMP_CLAUSE_COLLAPSE_EXPR (c
) = num
;
8484 OMP_CLAUSE_CHAIN (c
) = list
;
8489 copyin ( variable-list ) */
8492 c_parser_omp_clause_copyin (c_parser
*parser
, tree list
)
8494 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYIN
, list
);
8498 copyprivate ( variable-list ) */
8501 c_parser_omp_clause_copyprivate (c_parser
*parser
, tree list
)
8503 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYPRIVATE
, list
);
8507 default ( shared | none ) */
8510 c_parser_omp_clause_default (c_parser
*parser
, tree list
)
8512 enum omp_clause_default_kind kind
= OMP_CLAUSE_DEFAULT_UNSPECIFIED
;
8513 location_t loc
= c_parser_peek_token (parser
)->location
;
8516 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8518 if (c_parser_next_token_is (parser
, CPP_NAME
))
8520 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
8525 if (strcmp ("none", p
) != 0)
8527 kind
= OMP_CLAUSE_DEFAULT_NONE
;
8531 if (strcmp ("shared", p
) != 0)
8533 kind
= OMP_CLAUSE_DEFAULT_SHARED
;
8540 c_parser_consume_token (parser
);
8545 c_parser_error (parser
, "expected %<none%> or %<shared%>");
8547 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8549 if (kind
== OMP_CLAUSE_DEFAULT_UNSPECIFIED
)
8552 check_no_duplicate_clause (list
, OMP_CLAUSE_DEFAULT
, "default");
8553 c
= build_omp_clause (loc
, OMP_CLAUSE_DEFAULT
);
8554 OMP_CLAUSE_CHAIN (c
) = list
;
8555 OMP_CLAUSE_DEFAULT_KIND (c
) = kind
;
8561 firstprivate ( variable-list ) */
8564 c_parser_omp_clause_firstprivate (c_parser
*parser
, tree list
)
8566 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FIRSTPRIVATE
, list
);
8570 if ( expression ) */
8573 c_parser_omp_clause_if (c_parser
*parser
, tree list
)
8575 location_t loc
= c_parser_peek_token (parser
)->location
;
8576 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8578 tree t
= c_parser_paren_condition (parser
);
8581 check_no_duplicate_clause (list
, OMP_CLAUSE_IF
, "if");
8583 c
= build_omp_clause (loc
, OMP_CLAUSE_IF
);
8584 OMP_CLAUSE_IF_EXPR (c
) = t
;
8585 OMP_CLAUSE_CHAIN (c
) = list
;
8589 c_parser_error (parser
, "expected %<(%>");
8595 lastprivate ( variable-list ) */
8598 c_parser_omp_clause_lastprivate (c_parser
*parser
, tree list
)
8600 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_LASTPRIVATE
, list
);
8607 c_parser_omp_clause_nowait (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
8610 location_t loc
= c_parser_peek_token (parser
)->location
;
8612 check_no_duplicate_clause (list
, OMP_CLAUSE_NOWAIT
, "nowait");
8614 c
= build_omp_clause (loc
, OMP_CLAUSE_NOWAIT
);
8615 OMP_CLAUSE_CHAIN (c
) = list
;
8620 num_threads ( expression ) */
8623 c_parser_omp_clause_num_threads (c_parser
*parser
, tree list
)
8625 location_t num_threads_loc
= c_parser_peek_token (parser
)->location
;
8626 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8628 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
8629 tree c
, t
= c_parser_expression (parser
).value
;
8630 t
= c_fully_fold (t
, false, NULL
);
8632 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8634 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
8636 c_parser_error (parser
, "expected integer expression");
8640 /* Attempt to statically determine when the number isn't positive. */
8641 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
8642 build_int_cst (TREE_TYPE (t
), 0));
8643 if (CAN_HAVE_LOCATION_P (c
))
8644 SET_EXPR_LOCATION (c
, expr_loc
);
8645 if (c
== boolean_true_node
)
8647 warning_at (expr_loc
, 0,
8648 "%<num_threads%> value must be positive");
8649 t
= integer_one_node
;
8652 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_THREADS
, "num_threads");
8654 c
= build_omp_clause (num_threads_loc
, OMP_CLAUSE_NUM_THREADS
);
8655 OMP_CLAUSE_NUM_THREADS_EXPR (c
) = t
;
8656 OMP_CLAUSE_CHAIN (c
) = list
;
8667 c_parser_omp_clause_ordered (c_parser
*parser
, tree list
)
8671 check_no_duplicate_clause (list
, OMP_CLAUSE_ORDERED
, "ordered");
8673 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
8674 OMP_CLAUSE_ORDERED
);
8675 OMP_CLAUSE_CHAIN (c
) = list
;
8681 private ( variable-list ) */
8684 c_parser_omp_clause_private (c_parser
*parser
, tree list
)
8686 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_PRIVATE
, list
);
8690 reduction ( reduction-operator : variable-list )
8693 One of: + * - & ^ | && || */
8696 c_parser_omp_clause_reduction (c_parser
*parser
, tree list
)
8698 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
8699 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8701 enum tree_code code
;
8703 switch (c_parser_peek_token (parser
)->type
)
8715 code
= BIT_AND_EXPR
;
8718 code
= BIT_XOR_EXPR
;
8721 code
= BIT_IOR_EXPR
;
8724 code
= TRUTH_ANDIF_EXPR
;
8727 code
= TRUTH_ORIF_EXPR
;
8730 c_parser_error (parser
,
8731 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
8732 "%<^%>, %<|%>, %<&&%>, or %<||%>");
8733 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
8736 c_parser_consume_token (parser
);
8737 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
8741 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
8742 OMP_CLAUSE_REDUCTION
, list
);
8743 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
8744 OMP_CLAUSE_REDUCTION_CODE (c
) = code
;
8748 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8754 schedule ( schedule-kind )
8755 schedule ( schedule-kind , expression )
8758 static | dynamic | guided | runtime | auto
8762 c_parser_omp_clause_schedule (c_parser
*parser
, tree list
)
8765 location_t loc
= c_parser_peek_token (parser
)->location
;
8767 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8770 c
= build_omp_clause (loc
, OMP_CLAUSE_SCHEDULE
);
8772 if (c_parser_next_token_is (parser
, CPP_NAME
))
8774 tree kind
= c_parser_peek_token (parser
)->value
;
8775 const char *p
= IDENTIFIER_POINTER (kind
);
8780 if (strcmp ("dynamic", p
) != 0)
8782 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_DYNAMIC
;
8786 if (strcmp ("guided", p
) != 0)
8788 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_GUIDED
;
8792 if (strcmp ("runtime", p
) != 0)
8794 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_RUNTIME
;
8801 else if (c_parser_next_token_is_keyword (parser
, RID_STATIC
))
8802 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_STATIC
;
8803 else if (c_parser_next_token_is_keyword (parser
, RID_AUTO
))
8804 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_AUTO
;
8808 c_parser_consume_token (parser
);
8809 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8812 c_parser_consume_token (parser
);
8814 here
= c_parser_peek_token (parser
)->location
;
8815 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
8816 t
= c_fully_fold (t
, false, NULL
);
8818 if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_RUNTIME
)
8819 error_at (here
, "schedule %<runtime%> does not take "
8820 "a %<chunk_size%> parameter");
8821 else if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_AUTO
)
8823 "schedule %<auto%> does not take "
8824 "a %<chunk_size%> parameter");
8825 else if (TREE_CODE (TREE_TYPE (t
)) == INTEGER_TYPE
)
8826 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
) = t
;
8828 c_parser_error (parser
, "expected integer expression");
8830 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8833 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
8834 "expected %<,%> or %<)%>");
8836 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
8837 OMP_CLAUSE_CHAIN (c
) = list
;
8841 c_parser_error (parser
, "invalid schedule kind");
8842 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
8847 shared ( variable-list ) */
8850 c_parser_omp_clause_shared (c_parser
*parser
, tree list
)
8852 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_SHARED
, list
);
8859 c_parser_omp_clause_untied (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
8863 /* FIXME: Should we allow duplicates? */
8864 check_no_duplicate_clause (list
, OMP_CLAUSE_UNTIED
, "untied");
8866 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
8868 OMP_CLAUSE_CHAIN (c
) = list
;
8873 /* Parse all OpenMP clauses. The set clauses allowed by the directive
8874 is a bitmask in MASK. Return the list of clauses found; the result
8875 of clause default goes in *pdefault. */
8878 c_parser_omp_all_clauses (c_parser
*parser
, unsigned int mask
,
8881 tree clauses
= NULL
;
8884 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
8887 pragma_omp_clause c_kind
;
8889 tree prev
= clauses
;
8891 if (!first
&& c_parser_next_token_is (parser
, CPP_COMMA
))
8892 c_parser_consume_token (parser
);
8895 here
= c_parser_peek_token (parser
)->location
;
8896 c_kind
= c_parser_omp_clause_name (parser
);
8900 case PRAGMA_OMP_CLAUSE_COLLAPSE
:
8901 clauses
= c_parser_omp_clause_collapse (parser
, clauses
);
8902 c_name
= "collapse";
8904 case PRAGMA_OMP_CLAUSE_COPYIN
:
8905 clauses
= c_parser_omp_clause_copyin (parser
, clauses
);
8908 case PRAGMA_OMP_CLAUSE_COPYPRIVATE
:
8909 clauses
= c_parser_omp_clause_copyprivate (parser
, clauses
);
8910 c_name
= "copyprivate";
8912 case PRAGMA_OMP_CLAUSE_DEFAULT
:
8913 clauses
= c_parser_omp_clause_default (parser
, clauses
);
8916 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
:
8917 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
8918 c_name
= "firstprivate";
8920 case PRAGMA_OMP_CLAUSE_IF
:
8921 clauses
= c_parser_omp_clause_if (parser
, clauses
);
8924 case PRAGMA_OMP_CLAUSE_LASTPRIVATE
:
8925 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
8926 c_name
= "lastprivate";
8928 case PRAGMA_OMP_CLAUSE_NOWAIT
:
8929 clauses
= c_parser_omp_clause_nowait (parser
, clauses
);
8932 case PRAGMA_OMP_CLAUSE_NUM_THREADS
:
8933 clauses
= c_parser_omp_clause_num_threads (parser
, clauses
);
8934 c_name
= "num_threads";
8936 case PRAGMA_OMP_CLAUSE_ORDERED
:
8937 clauses
= c_parser_omp_clause_ordered (parser
, clauses
);
8940 case PRAGMA_OMP_CLAUSE_PRIVATE
:
8941 clauses
= c_parser_omp_clause_private (parser
, clauses
);
8944 case PRAGMA_OMP_CLAUSE_REDUCTION
:
8945 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
8946 c_name
= "reduction";
8948 case PRAGMA_OMP_CLAUSE_SCHEDULE
:
8949 clauses
= c_parser_omp_clause_schedule (parser
, clauses
);
8950 c_name
= "schedule";
8952 case PRAGMA_OMP_CLAUSE_SHARED
:
8953 clauses
= c_parser_omp_clause_shared (parser
, clauses
);
8956 case PRAGMA_OMP_CLAUSE_UNTIED
:
8957 clauses
= c_parser_omp_clause_untied (parser
, clauses
);
8961 c_parser_error (parser
, "expected %<#pragma omp%> clause");
8965 if (((mask
>> c_kind
) & 1) == 0 && !parser
->error
)
8967 /* Remove the invalid clause(s) from the list to avoid
8968 confusing the rest of the compiler. */
8970 error_at (here
, "%qs is not valid for %qs", c_name
, where
);
8975 c_parser_skip_to_pragma_eol (parser
);
8977 return c_finish_omp_clauses (clauses
);
8984 In practice, we're also interested in adding the statement to an
8985 outer node. So it is convenient if we work around the fact that
8986 c_parser_statement calls add_stmt. */
8989 c_parser_omp_structured_block (c_parser
*parser
)
8991 tree stmt
= push_stmt_list ();
8992 c_parser_statement (parser
);
8993 return pop_stmt_list (stmt
);
8997 # pragma omp atomic new-line
9001 x binop= expr | x++ | ++x | x-- | --x
9003 +, *, -, /, &, ^, |, <<, >>
9005 where x is an lvalue expression with scalar type.
9007 LOC is the location of the #pragma token. */
9010 c_parser_omp_atomic (location_t loc
, c_parser
*parser
)
9014 enum tree_code code
;
9015 struct c_expr rhs_expr
;
9017 c_parser_skip_to_pragma_eol (parser
);
9019 lhs
= c_parser_unary_expression (parser
).value
;
9020 lhs
= c_fully_fold (lhs
, false, NULL
);
9021 switch (TREE_CODE (lhs
))
9025 c_parser_skip_to_end_of_block_or_statement (parser
);
9028 case PREINCREMENT_EXPR
:
9029 case POSTINCREMENT_EXPR
:
9030 lhs
= TREE_OPERAND (lhs
, 0);
9032 rhs
= integer_one_node
;
9035 case PREDECREMENT_EXPR
:
9036 case POSTDECREMENT_EXPR
:
9037 lhs
= TREE_OPERAND (lhs
, 0);
9039 rhs
= integer_one_node
;
9043 if (TREE_CODE (TREE_OPERAND (lhs
, 0)) == SAVE_EXPR
9044 && TREE_CODE (TREE_OPERAND (lhs
, 1)) == COMPOUND_EXPR
9045 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0)) == MODIFY_EXPR
9046 && TREE_OPERAND (TREE_OPERAND (lhs
, 1), 1) == TREE_OPERAND (lhs
, 0)
9047 && TREE_CODE (TREE_TYPE (TREE_OPERAND (TREE_OPERAND
9048 (TREE_OPERAND (lhs
, 1), 0), 0)))
9050 /* Undo effects of boolean_increment for post {in,de}crement. */
9051 lhs
= TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0);
9054 if (TREE_CODE (lhs
) == MODIFY_EXPR
9055 && TREE_CODE (TREE_TYPE (TREE_OPERAND (lhs
, 0))) == BOOLEAN_TYPE
)
9057 /* Undo effects of boolean_increment. */
9058 if (integer_onep (TREE_OPERAND (lhs
, 1)))
9060 /* This is pre or post increment. */
9061 rhs
= TREE_OPERAND (lhs
, 1);
9062 lhs
= TREE_OPERAND (lhs
, 0);
9066 if (TREE_CODE (TREE_OPERAND (lhs
, 1)) == TRUTH_NOT_EXPR
9067 && TREE_OPERAND (lhs
, 0)
9068 == TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0))
9070 /* This is pre or post decrement. */
9071 rhs
= TREE_OPERAND (lhs
, 1);
9072 lhs
= TREE_OPERAND (lhs
, 0);
9079 switch (c_parser_peek_token (parser
)->type
)
9085 code
= TRUNC_DIV_EXPR
;
9100 code
= BIT_AND_EXPR
;
9103 code
= BIT_IOR_EXPR
;
9106 code
= BIT_XOR_EXPR
;
9109 c_parser_error (parser
,
9110 "invalid operator for %<#pragma omp atomic%>");
9114 /* Arrange to pass the location of the assignment operator to
9115 c_finish_omp_atomic. */
9116 loc
= c_parser_peek_token (parser
)->location
;
9117 c_parser_consume_token (parser
);
9119 location_t rhs_loc
= c_parser_peek_token (parser
)->location
;
9120 rhs_expr
= c_parser_expression (parser
);
9121 rhs_expr
= default_function_array_read_conversion (rhs_loc
, rhs_expr
);
9123 rhs
= rhs_expr
.value
;
9124 rhs
= c_fully_fold (rhs
, false, NULL
);
9127 stmt
= c_finish_omp_atomic (loc
, code
, lhs
, rhs
);
9128 if (stmt
!= error_mark_node
)
9130 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9135 # pragma omp barrier new-line
9139 c_parser_omp_barrier (c_parser
*parser
)
9141 location_t loc
= c_parser_peek_token (parser
)->location
;
9142 c_parser_consume_pragma (parser
);
9143 c_parser_skip_to_pragma_eol (parser
);
9145 c_finish_omp_barrier (loc
);
9149 # pragma omp critical [(name)] new-line
9152 LOC is the location of the #pragma itself. */
9155 c_parser_omp_critical (location_t loc
, c_parser
*parser
)
9157 tree stmt
, name
= NULL
;
9159 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9161 c_parser_consume_token (parser
);
9162 if (c_parser_next_token_is (parser
, CPP_NAME
))
9164 name
= c_parser_peek_token (parser
)->value
;
9165 c_parser_consume_token (parser
);
9166 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9169 c_parser_error (parser
, "expected identifier");
9171 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
9172 c_parser_error (parser
, "expected %<(%> or end of line");
9173 c_parser_skip_to_pragma_eol (parser
);
9175 stmt
= c_parser_omp_structured_block (parser
);
9176 return c_finish_omp_critical (loc
, stmt
, name
);
9180 # pragma omp flush flush-vars[opt] new-line
9183 ( variable-list ) */
9186 c_parser_omp_flush (c_parser
*parser
)
9188 location_t loc
= c_parser_peek_token (parser
)->location
;
9189 c_parser_consume_pragma (parser
);
9190 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9191 c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
9192 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
9193 c_parser_error (parser
, "expected %<(%> or end of line");
9194 c_parser_skip_to_pragma_eol (parser
);
9196 c_finish_omp_flush (loc
);
9199 /* Parse the restricted form of the for statement allowed by OpenMP.
9200 The real trick here is to determine the loop control variable early
9201 so that we can push a new decl if necessary to make it private.
9202 LOC is the location of the OMP in "#pragma omp". */
9205 c_parser_omp_for_loop (location_t loc
,
9206 c_parser
*parser
, tree clauses
, tree
*par_clauses
)
9208 tree decl
, cond
, incr
, save_break
, save_cont
, body
, init
, stmt
, cl
;
9209 tree declv
, condv
, incrv
, initv
, ret
= NULL
;
9210 bool fail
= false, open_brace_parsed
= false;
9211 int i
, collapse
= 1, nbraces
= 0;
9213 VEC(tree
,gc
) *for_block
= make_tree_vector ();
9215 for (cl
= clauses
; cl
; cl
= OMP_CLAUSE_CHAIN (cl
))
9216 if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_COLLAPSE
)
9217 collapse
= tree_low_cst (OMP_CLAUSE_COLLAPSE_EXPR (cl
), 0);
9219 gcc_assert (collapse
>= 1);
9221 declv
= make_tree_vec (collapse
);
9222 initv
= make_tree_vec (collapse
);
9223 condv
= make_tree_vec (collapse
);
9224 incrv
= make_tree_vec (collapse
);
9226 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
))
9228 c_parser_error (parser
, "for statement expected");
9231 for_loc
= c_parser_peek_token (parser
)->location
;
9232 c_parser_consume_token (parser
);
9234 for (i
= 0; i
< collapse
; i
++)
9238 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9241 /* Parse the initialization declaration or expression. */
9242 if (c_parser_next_tokens_start_declaration (parser
))
9245 VEC_safe_push (tree
, gc
, for_block
, c_begin_compound_stmt (true));
9246 c_parser_declaration_or_fndef (parser
, true, true, true, true, true, NULL
);
9247 decl
= check_for_loop_decls (for_loc
, flag_isoc99
);
9250 if (DECL_INITIAL (decl
) == error_mark_node
)
9251 decl
= error_mark_node
;
9254 else if (c_parser_next_token_is (parser
, CPP_NAME
)
9255 && c_parser_peek_2nd_token (parser
)->type
== CPP_EQ
)
9257 struct c_expr decl_exp
;
9258 struct c_expr init_exp
;
9259 location_t init_loc
;
9261 decl_exp
= c_parser_postfix_expression (parser
);
9262 decl
= decl_exp
.value
;
9264 c_parser_require (parser
, CPP_EQ
, "expected %<=%>");
9266 init_loc
= c_parser_peek_token (parser
)->location
;
9267 init_exp
= c_parser_expr_no_commas (parser
, NULL
);
9268 init_exp
= default_function_array_read_conversion (init_loc
,
9270 init
= build_modify_expr (init_loc
, decl
, decl_exp
.original_type
,
9271 NOP_EXPR
, init_loc
, init_exp
.value
,
9272 init_exp
.original_type
);
9273 init
= c_process_expr_stmt (init_loc
, init
);
9275 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9280 c_parser_error (parser
,
9281 "expected iteration declaration or initialization");
9282 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
9288 /* Parse the loop condition. */
9290 if (c_parser_next_token_is_not (parser
, CPP_SEMICOLON
))
9292 location_t cond_loc
= c_parser_peek_token (parser
)->location
;
9293 struct c_expr cond_expr
= c_parser_binary_expression (parser
, NULL
);
9295 cond
= cond_expr
.value
;
9296 cond
= c_objc_common_truthvalue_conversion (cond_loc
, cond
);
9297 cond
= c_fully_fold (cond
, false, NULL
);
9298 switch (cond_expr
.original_code
)
9306 /* Can't be cond = error_mark_node, because we want to preserve
9307 the location until c_finish_omp_for. */
9308 cond
= build1 (NOP_EXPR
, boolean_type_node
, error_mark_node
);
9311 protected_set_expr_location (cond
, cond_loc
);
9313 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9315 /* Parse the increment expression. */
9317 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_PAREN
))
9319 location_t incr_loc
= c_parser_peek_token (parser
)->location
;
9321 incr
= c_process_expr_stmt (incr_loc
,
9322 c_parser_expression (parser
).value
);
9324 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9326 if (decl
== NULL
|| decl
== error_mark_node
|| init
== error_mark_node
)
9330 TREE_VEC_ELT (declv
, i
) = decl
;
9331 TREE_VEC_ELT (initv
, i
) = init
;
9332 TREE_VEC_ELT (condv
, i
) = cond
;
9333 TREE_VEC_ELT (incrv
, i
) = incr
;
9337 if (i
== collapse
- 1)
9340 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
9341 in between the collapsed for loops to be still considered perfectly
9342 nested. Hopefully the final version clarifies this.
9343 For now handle (multiple) {'s and empty statements. */
9346 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
9348 c_parser_consume_token (parser
);
9351 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
9353 c_parser_consume_token (parser
);
9357 && c_parser_next_token_is (parser
, CPP_SEMICOLON
))
9358 c_parser_consume_token (parser
);
9361 c_parser_error (parser
, "not enough perfectly nested loops");
9364 open_brace_parsed
= true;
9374 nbraces
+= bracecount
;
9377 save_break
= c_break_label
;
9378 c_break_label
= size_one_node
;
9379 save_cont
= c_cont_label
;
9380 c_cont_label
= NULL_TREE
;
9381 body
= push_stmt_list ();
9383 if (open_brace_parsed
)
9385 location_t here
= c_parser_peek_token (parser
)->location
;
9386 stmt
= c_begin_compound_stmt (true);
9387 c_parser_compound_statement_nostart (parser
);
9388 add_stmt (c_end_compound_stmt (here
, stmt
, true));
9391 add_stmt (c_parser_c99_block_statement (parser
));
9394 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_cont_label
);
9395 SET_EXPR_LOCATION (t
, loc
);
9399 body
= pop_stmt_list (body
);
9400 c_break_label
= save_break
;
9401 c_cont_label
= save_cont
;
9405 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
9407 c_parser_consume_token (parser
);
9410 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
9411 c_parser_consume_token (parser
);
9414 c_parser_error (parser
, "collapsed loops not perfectly nested");
9417 location_t here
= c_parser_peek_token (parser
)->location
;
9418 stmt
= c_begin_compound_stmt (true);
9420 c_parser_compound_statement_nostart (parser
);
9421 body
= c_end_compound_stmt (here
, stmt
, true);
9428 /* Only bother calling c_finish_omp_for if we haven't already generated
9429 an error from the initialization parsing. */
9432 stmt
= c_finish_omp_for (loc
, declv
, initv
, condv
, incrv
, body
, NULL
);
9435 if (par_clauses
!= NULL
)
9438 for (c
= par_clauses
; *c
; )
9439 if (OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_FIRSTPRIVATE
9440 && OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_LASTPRIVATE
)
9441 c
= &OMP_CLAUSE_CHAIN (*c
);
9444 for (i
= 0; i
< collapse
; i
++)
9445 if (TREE_VEC_ELT (declv
, i
) == OMP_CLAUSE_DECL (*c
))
9448 c
= &OMP_CLAUSE_CHAIN (*c
);
9449 else if (OMP_CLAUSE_CODE (*c
) == OMP_CLAUSE_FIRSTPRIVATE
)
9452 "iteration variable %qD should not be firstprivate",
9453 OMP_CLAUSE_DECL (*c
));
9454 *c
= OMP_CLAUSE_CHAIN (*c
);
9458 /* Copy lastprivate (decl) clause to OMP_FOR_CLAUSES,
9459 change it to shared (decl) in
9460 OMP_PARALLEL_CLAUSES. */
9461 tree l
= build_omp_clause (OMP_CLAUSE_LOCATION (*c
),
9462 OMP_CLAUSE_LASTPRIVATE
);
9463 OMP_CLAUSE_DECL (l
) = OMP_CLAUSE_DECL (*c
);
9464 OMP_CLAUSE_CHAIN (l
) = clauses
;
9466 OMP_CLAUSE_SET_CODE (*c
, OMP_CLAUSE_SHARED
);
9470 OMP_FOR_CLAUSES (stmt
) = clauses
;
9475 while (!VEC_empty (tree
, for_block
))
9477 /* FIXME diagnostics: LOC below should be the actual location of
9478 this particular for block. We need to build a list of
9479 locations to go along with FOR_BLOCK. */
9480 stmt
= c_end_compound_stmt (loc
, VEC_pop (tree
, for_block
), true);
9483 release_tree_vector (for_block
);
9488 #pragma omp for for-clause[optseq] new-line
9491 LOC is the location of the #pragma token.
9494 #define OMP_FOR_CLAUSE_MASK \
9495 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
9496 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
9497 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
9498 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
9499 | (1u << PRAGMA_OMP_CLAUSE_ORDERED) \
9500 | (1u << PRAGMA_OMP_CLAUSE_SCHEDULE) \
9501 | (1u << PRAGMA_OMP_CLAUSE_COLLAPSE) \
9502 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
9505 c_parser_omp_for (location_t loc
, c_parser
*parser
)
9507 tree block
, clauses
, ret
;
9509 clauses
= c_parser_omp_all_clauses (parser
, OMP_FOR_CLAUSE_MASK
,
9512 block
= c_begin_compound_stmt (true);
9513 ret
= c_parser_omp_for_loop (loc
, parser
, clauses
, NULL
);
9514 block
= c_end_compound_stmt (loc
, block
, true);
9521 # pragma omp master new-line
9524 LOC is the location of the #pragma token.
9528 c_parser_omp_master (location_t loc
, c_parser
*parser
)
9530 c_parser_skip_to_pragma_eol (parser
);
9531 return c_finish_omp_master (loc
, c_parser_omp_structured_block (parser
));
9535 # pragma omp ordered new-line
9538 LOC is the location of the #pragma itself.
9542 c_parser_omp_ordered (location_t loc
, c_parser
*parser
)
9544 c_parser_skip_to_pragma_eol (parser
);
9545 return c_finish_omp_ordered (loc
, c_parser_omp_structured_block (parser
));
9551 { section-sequence }
9554 section-directive[opt] structured-block
9555 section-sequence section-directive structured-block
9557 SECTIONS_LOC is the location of the #pragma omp sections. */
9560 c_parser_omp_sections_scope (location_t sections_loc
, c_parser
*parser
)
9563 bool error_suppress
= false;
9566 loc
= c_parser_peek_token (parser
)->location
;
9567 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
9569 /* Avoid skipping until the end of the block. */
9570 parser
->error
= false;
9574 stmt
= push_stmt_list ();
9576 if (c_parser_peek_token (parser
)->pragma_kind
!= PRAGMA_OMP_SECTION
)
9578 substmt
= push_stmt_list ();
9582 c_parser_statement (parser
);
9584 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
9586 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
9588 if (c_parser_next_token_is (parser
, CPP_EOF
))
9592 substmt
= pop_stmt_list (substmt
);
9593 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
9594 SET_EXPR_LOCATION (substmt
, loc
);
9600 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
9602 if (c_parser_next_token_is (parser
, CPP_EOF
))
9605 loc
= c_parser_peek_token (parser
)->location
;
9606 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
9608 c_parser_consume_pragma (parser
);
9609 c_parser_skip_to_pragma_eol (parser
);
9610 error_suppress
= false;
9612 else if (!error_suppress
)
9614 error_at (loc
, "expected %<#pragma omp section%> or %<}%>");
9615 error_suppress
= true;
9618 substmt
= c_parser_omp_structured_block (parser
);
9619 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
9620 SET_EXPR_LOCATION (substmt
, loc
);
9623 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
,
9624 "expected %<#pragma omp section%> or %<}%>");
9626 substmt
= pop_stmt_list (stmt
);
9628 stmt
= make_node (OMP_SECTIONS
);
9629 SET_EXPR_LOCATION (stmt
, sections_loc
);
9630 TREE_TYPE (stmt
) = void_type_node
;
9631 OMP_SECTIONS_BODY (stmt
) = substmt
;
9633 return add_stmt (stmt
);
9637 # pragma omp sections sections-clause[optseq] newline
9640 LOC is the location of the #pragma token.
9643 #define OMP_SECTIONS_CLAUSE_MASK \
9644 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
9645 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
9646 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
9647 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
9648 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
9651 c_parser_omp_sections (location_t loc
, c_parser
*parser
)
9653 tree block
, clauses
, ret
;
9655 clauses
= c_parser_omp_all_clauses (parser
, OMP_SECTIONS_CLAUSE_MASK
,
9656 "#pragma omp sections");
9658 block
= c_begin_compound_stmt (true);
9659 ret
= c_parser_omp_sections_scope (loc
, parser
);
9661 OMP_SECTIONS_CLAUSES (ret
) = clauses
;
9662 block
= c_end_compound_stmt (loc
, block
, true);
9669 # pragma parallel parallel-clause new-line
9670 # pragma parallel for parallel-for-clause new-line
9671 # pragma parallel sections parallel-sections-clause new-line
9673 LOC is the location of the #pragma token.
9676 #define OMP_PARALLEL_CLAUSE_MASK \
9677 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
9678 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
9679 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
9680 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
9681 | (1u << PRAGMA_OMP_CLAUSE_SHARED) \
9682 | (1u << PRAGMA_OMP_CLAUSE_COPYIN) \
9683 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
9684 | (1u << PRAGMA_OMP_CLAUSE_NUM_THREADS))
9687 c_parser_omp_parallel (location_t loc
, c_parser
*parser
)
9689 enum pragma_kind p_kind
= PRAGMA_OMP_PARALLEL
;
9690 const char *p_name
= "#pragma omp parallel";
9691 tree stmt
, clauses
, par_clause
, ws_clause
, block
;
9692 unsigned int mask
= OMP_PARALLEL_CLAUSE_MASK
;
9694 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
9696 c_parser_consume_token (parser
);
9697 p_kind
= PRAGMA_OMP_PARALLEL_FOR
;
9698 p_name
= "#pragma omp parallel for";
9699 mask
|= OMP_FOR_CLAUSE_MASK
;
9700 mask
&= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT
);
9702 else if (c_parser_next_token_is (parser
, CPP_NAME
))
9704 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
9705 if (strcmp (p
, "sections") == 0)
9707 c_parser_consume_token (parser
);
9708 p_kind
= PRAGMA_OMP_PARALLEL_SECTIONS
;
9709 p_name
= "#pragma omp parallel sections";
9710 mask
|= OMP_SECTIONS_CLAUSE_MASK
;
9711 mask
&= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT
);
9715 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
);
9719 case PRAGMA_OMP_PARALLEL
:
9720 block
= c_begin_omp_parallel ();
9721 c_parser_statement (parser
);
9722 stmt
= c_finish_omp_parallel (loc
, clauses
, block
);
9725 case PRAGMA_OMP_PARALLEL_FOR
:
9726 block
= c_begin_omp_parallel ();
9727 c_split_parallel_clauses (loc
, clauses
, &par_clause
, &ws_clause
);
9728 c_parser_omp_for_loop (loc
, parser
, ws_clause
, &par_clause
);
9729 stmt
= c_finish_omp_parallel (loc
, par_clause
, block
);
9730 OMP_PARALLEL_COMBINED (stmt
) = 1;
9733 case PRAGMA_OMP_PARALLEL_SECTIONS
:
9734 block
= c_begin_omp_parallel ();
9735 c_split_parallel_clauses (loc
, clauses
, &par_clause
, &ws_clause
);
9736 stmt
= c_parser_omp_sections_scope (loc
, parser
);
9738 OMP_SECTIONS_CLAUSES (stmt
) = ws_clause
;
9739 stmt
= c_finish_omp_parallel (loc
, par_clause
, block
);
9740 OMP_PARALLEL_COMBINED (stmt
) = 1;
9751 # pragma omp single single-clause[optseq] new-line
9754 LOC is the location of the #pragma.
9757 #define OMP_SINGLE_CLAUSE_MASK \
9758 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
9759 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
9760 | (1u << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
9761 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
9764 c_parser_omp_single (location_t loc
, c_parser
*parser
)
9766 tree stmt
= make_node (OMP_SINGLE
);
9767 SET_EXPR_LOCATION (stmt
, loc
);
9768 TREE_TYPE (stmt
) = void_type_node
;
9770 OMP_SINGLE_CLAUSES (stmt
)
9771 = c_parser_omp_all_clauses (parser
, OMP_SINGLE_CLAUSE_MASK
,
9772 "#pragma omp single");
9773 OMP_SINGLE_BODY (stmt
) = c_parser_omp_structured_block (parser
);
9775 return add_stmt (stmt
);
9779 # pragma omp task task-clause[optseq] new-line
9781 LOC is the location of the #pragma.
9784 #define OMP_TASK_CLAUSE_MASK \
9785 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
9786 | (1u << PRAGMA_OMP_CLAUSE_UNTIED) \
9787 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
9788 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
9789 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
9790 | (1u << PRAGMA_OMP_CLAUSE_SHARED))
9793 c_parser_omp_task (location_t loc
, c_parser
*parser
)
9795 tree clauses
, block
;
9797 clauses
= c_parser_omp_all_clauses (parser
, OMP_TASK_CLAUSE_MASK
,
9798 "#pragma omp task");
9800 block
= c_begin_omp_task ();
9801 c_parser_statement (parser
);
9802 return c_finish_omp_task (loc
, clauses
, block
);
9806 # pragma omp taskwait new-line
9810 c_parser_omp_taskwait (c_parser
*parser
)
9812 location_t loc
= c_parser_peek_token (parser
)->location
;
9813 c_parser_consume_pragma (parser
);
9814 c_parser_skip_to_pragma_eol (parser
);
9816 c_finish_omp_taskwait (loc
);
9819 /* Main entry point to parsing most OpenMP pragmas. */
9822 c_parser_omp_construct (c_parser
*parser
)
9824 enum pragma_kind p_kind
;
9828 loc
= c_parser_peek_token (parser
)->location
;
9829 p_kind
= c_parser_peek_token (parser
)->pragma_kind
;
9830 c_parser_consume_pragma (parser
);
9834 case PRAGMA_OMP_ATOMIC
:
9835 c_parser_omp_atomic (loc
, parser
);
9837 case PRAGMA_OMP_CRITICAL
:
9838 stmt
= c_parser_omp_critical (loc
, parser
);
9840 case PRAGMA_OMP_FOR
:
9841 stmt
= c_parser_omp_for (loc
, parser
);
9843 case PRAGMA_OMP_MASTER
:
9844 stmt
= c_parser_omp_master (loc
, parser
);
9846 case PRAGMA_OMP_ORDERED
:
9847 stmt
= c_parser_omp_ordered (loc
, parser
);
9849 case PRAGMA_OMP_PARALLEL
:
9850 stmt
= c_parser_omp_parallel (loc
, parser
);
9852 case PRAGMA_OMP_SECTIONS
:
9853 stmt
= c_parser_omp_sections (loc
, parser
);
9855 case PRAGMA_OMP_SINGLE
:
9856 stmt
= c_parser_omp_single (loc
, parser
);
9858 case PRAGMA_OMP_TASK
:
9859 stmt
= c_parser_omp_task (loc
, parser
);
9866 gcc_assert (EXPR_LOCATION (stmt
) != UNKNOWN_LOCATION
);
9871 # pragma omp threadprivate (variable-list) */
9874 c_parser_omp_threadprivate (c_parser
*parser
)
9879 c_parser_consume_pragma (parser
);
9880 loc
= c_parser_peek_token (parser
)->location
;
9881 vars
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
9883 /* Mark every variable in VARS to be assigned thread local storage. */
9884 for (t
= vars
; t
; t
= TREE_CHAIN (t
))
9886 tree v
= TREE_PURPOSE (t
);
9888 /* FIXME diagnostics: Ideally we should keep individual
9889 locations for all the variables in the var list to make the
9890 following errors more precise. Perhaps
9891 c_parser_omp_var_list_parens() should construct a list of
9892 locations to go along with the var list. */
9894 /* If V had already been marked threadprivate, it doesn't matter
9895 whether it had been used prior to this point. */
9896 if (TREE_CODE (v
) != VAR_DECL
)
9897 error_at (loc
, "%qD is not a variable", v
);
9898 else if (TREE_USED (v
) && !C_DECL_THREADPRIVATE_P (v
))
9899 error_at (loc
, "%qE declared %<threadprivate%> after first use", v
);
9900 else if (! TREE_STATIC (v
) && ! DECL_EXTERNAL (v
))
9901 error_at (loc
, "automatic variable %qE cannot be %<threadprivate%>", v
);
9902 else if (TREE_TYPE (v
) == error_mark_node
)
9904 else if (! COMPLETE_TYPE_P (TREE_TYPE (v
)))
9905 error_at (loc
, "%<threadprivate%> %qE has incomplete type", v
);
9908 if (! DECL_THREAD_LOCAL_P (v
))
9910 DECL_TLS_MODEL (v
) = decl_default_tls_model (v
);
9911 /* If rtl has been already set for this var, call
9912 make_decl_rtl once again, so that encode_section_info
9913 has a chance to look at the new decl flags. */
9914 if (DECL_RTL_SET_P (v
))
9917 C_DECL_THREADPRIVATE_P (v
) = 1;
9921 c_parser_skip_to_pragma_eol (parser
);
9925 /* Parse a single source file. */
9930 /* Use local storage to begin. If the first token is a pragma, parse it.
9931 If it is #pragma GCC pch_preprocess, then this will load a PCH file
9932 which will cause garbage collection. */
9935 memset (&tparser
, 0, sizeof tparser
);
9936 the_parser
= &tparser
;
9938 if (c_parser_peek_token (&tparser
)->pragma_kind
== PRAGMA_GCC_PCH_PREPROCESS
)
9939 c_parser_pragma_pch_preprocess (&tparser
);
9941 the_parser
= ggc_alloc_c_parser ();
9942 *the_parser
= tparser
;
9944 /* Initialize EH, if we've been told to do so. */
9945 if (flag_exceptions
)
9946 using_eh_for_cleanups ();
9948 c_parser_translation_unit (the_parser
);
9952 #include "gt-c-parser.h"