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 && (!objc_force_identifier
|| global_bindings_p ()))
339 token
->value
= objc_interface_decl
;
340 token
->id_kind
= C_ID_CLASSNAME
;
344 token
->id_kind
= C_ID_ID
;
348 /* This only happens in Objective-C; it must be a keyword. */
349 token
->type
= CPP_KEYWORD
;
350 switch (C_RID_CODE (token
->value
))
352 /* Replace 'class' with '@class', 'private' with '@private',
353 etc. This prevents confusion with the C++ keyword
354 'class', and makes the tokens consistent with other
355 Objective-C 'AT' keywords. For example '@class' is
356 reported as RID_AT_CLASS which is consistent with
357 '@synchronized', which is reported as
360 case RID_CLASS
: token
->keyword
= RID_AT_CLASS
; break;
361 case RID_PRIVATE
: token
->keyword
= RID_AT_PRIVATE
; break;
362 case RID_PROTECTED
: token
->keyword
= RID_AT_PROTECTED
; break;
363 case RID_PUBLIC
: token
->keyword
= RID_AT_PUBLIC
; break;
364 case RID_THROW
: token
->keyword
= RID_AT_THROW
; break;
365 case RID_TRY
: token
->keyword
= RID_AT_TRY
; break;
366 case RID_CATCH
: token
->keyword
= RID_AT_CATCH
; break;
367 default: token
->keyword
= C_RID_CODE (token
->value
);
372 case CPP_CLOSE_PAREN
:
374 /* These tokens may affect the interpretation of any identifiers
375 following, if doing Objective-C. */
376 if (c_dialect_objc ())
377 parser
->objc_need_raw_identifier
= false;
380 /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */
381 token
->pragma_kind
= (enum pragma_kind
) TREE_INT_CST_LOW (token
->value
);
387 timevar_pop (TV_LEX
);
390 /* Return a pointer to the next token from PARSER, reading it in if
393 static inline c_token
*
394 c_parser_peek_token (c_parser
*parser
)
396 if (parser
->tokens_avail
== 0)
398 c_lex_one_token (parser
, &parser
->tokens
[0]);
399 parser
->tokens_avail
= 1;
401 return &parser
->tokens
[0];
404 /* Return true if the next token from PARSER has the indicated
408 c_parser_next_token_is (c_parser
*parser
, enum cpp_ttype type
)
410 return c_parser_peek_token (parser
)->type
== type
;
413 /* Return true if the next token from PARSER does not have the
417 c_parser_next_token_is_not (c_parser
*parser
, enum cpp_ttype type
)
419 return !c_parser_next_token_is (parser
, type
);
422 /* Return true if the next token from PARSER is the indicated
426 c_parser_next_token_is_keyword (c_parser
*parser
, enum rid keyword
)
428 return c_parser_peek_token (parser
)->keyword
== keyword
;
431 /* Return a pointer to the next-but-one token from PARSER, reading it
432 in if necessary. The next token is already read in. */
435 c_parser_peek_2nd_token (c_parser
*parser
)
437 if (parser
->tokens_avail
>= 2)
438 return &parser
->tokens
[1];
439 gcc_assert (parser
->tokens_avail
== 1);
440 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
441 gcc_assert (parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
442 c_lex_one_token (parser
, &parser
->tokens
[1]);
443 parser
->tokens_avail
= 2;
444 return &parser
->tokens
[1];
447 /* Return true if TOKEN can start a type name,
450 c_token_starts_typename (c_token
*token
)
455 switch (token
->id_kind
)
464 gcc_assert (c_dialect_objc ());
470 switch (token
->keyword
)
503 if (c_dialect_objc ())
511 enum c_lookahead_kind
{
512 /* Always treat unknown identifiers as typenames. */
515 /* Could be parsing a nonabstract declarator. Only treat an identifier
516 as a typename if followed by another identifier or a star. */
517 cla_nonabstract_decl
,
519 /* Never treat identifiers as typenames. */
523 /* Return true if the next token from PARSER can start a type name,
524 false otherwise. LA specifies how to do lookahead in order to
525 detect unknown type names. If unsure, pick CLA_PREFER_ID. */
528 c_parser_next_tokens_start_typename (c_parser
*parser
, enum c_lookahead_kind la
)
530 c_token
*token
= c_parser_peek_token (parser
);
531 if (c_token_starts_typename (token
))
534 /* Try a bit harder to detect an unknown typename. */
535 if (la
!= cla_prefer_id
536 && token
->type
== CPP_NAME
537 && token
->id_kind
== C_ID_ID
539 /* Do not try too hard when we could have "object in array". */
540 && !parser
->objc_could_be_foreach_context
542 && (la
== cla_prefer_type
543 || c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
544 || c_parser_peek_2nd_token (parser
)->type
== CPP_MULT
)
546 /* Only unknown identifiers. */
547 && !lookup_name (token
->value
))
553 /* Return true if TOKEN is a type qualifier, false otherwise. */
555 c_token_is_qualifier (c_token
*token
)
560 switch (token
->id_kind
)
568 switch (token
->keyword
)
585 /* Return true if the next token from PARSER is a type qualifier,
588 c_parser_next_token_is_qualifier (c_parser
*parser
)
590 c_token
*token
= c_parser_peek_token (parser
);
591 return c_token_is_qualifier (token
);
594 /* Return true if TOKEN can start declaration specifiers, false
597 c_token_starts_declspecs (c_token
*token
)
602 switch (token
->id_kind
)
611 gcc_assert (c_dialect_objc ());
617 switch (token
->keyword
)
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 | (warn_overlength_strings
<< 6));
1050 cpp_opts
->cpp_pedantic
= pedantic
= 0;
1051 warn_pointer_arith
= 0;
1052 cpp_opts
->cpp_warn_traditional
= warn_traditional
= 0;
1054 cpp_opts
->cpp_warn_long_long
= warn_long_long
= 0;
1055 warn_cxx_compat
= 0;
1056 warn_overlength_strings
= 0;
1060 /* Restore the warning flags which are controlled by __extension__.
1061 FLAGS is the return value from disable_extension_diagnostics. */
1064 restore_extension_diagnostics (int flags
)
1066 cpp_opts
->cpp_pedantic
= pedantic
= flags
& 1;
1067 warn_pointer_arith
= (flags
>> 1) & 1;
1068 cpp_opts
->cpp_warn_traditional
= warn_traditional
= (flags
>> 2) & 1;
1069 flag_iso
= (flags
>> 3) & 1;
1070 cpp_opts
->cpp_warn_long_long
= warn_long_long
= (flags
>> 4) & 1;
1071 warn_cxx_compat
= (flags
>> 5) & 1;
1072 warn_overlength_strings
= (flags
>> 6) & 1;
1075 /* Possibly kinds of declarator to parse. */
1076 typedef enum c_dtr_syn
{
1077 /* A normal declarator with an identifier. */
1079 /* An abstract declarator (maybe empty). */
1081 /* A parameter declarator: may be either, but after a type name does
1082 not redeclare a typedef name as an identifier if it can
1083 alternatively be interpreted as a typedef name; see DR#009,
1084 applied in C90 TC1, omitted from C99 and reapplied in C99 TC2
1085 following DR#249. For example, given a typedef T, "int T" and
1086 "int *T" are valid parameter declarations redeclaring T, while
1087 "int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are
1088 abstract declarators rather than involving redundant parentheses;
1089 the same applies with attributes inside the parentheses before
1094 /* The binary operation precedence levels, where 0 is a dummy lowest level
1095 used for the bottom of the stack. */
1096 enum c_parser_prec
{
1111 static void c_parser_external_declaration (c_parser
*);
1112 static void c_parser_asm_definition (c_parser
*);
1113 static void c_parser_declaration_or_fndef (c_parser
*, bool, bool, bool,
1114 bool, bool, tree
*);
1115 static void c_parser_static_assert_declaration_no_semi (c_parser
*);
1116 static void c_parser_static_assert_declaration (c_parser
*);
1117 static void c_parser_declspecs (c_parser
*, struct c_declspecs
*, bool, bool,
1118 bool, enum c_lookahead_kind
);
1119 static struct c_typespec
c_parser_enum_specifier (c_parser
*);
1120 static struct c_typespec
c_parser_struct_or_union_specifier (c_parser
*);
1121 static tree
c_parser_struct_declaration (c_parser
*);
1122 static struct c_typespec
c_parser_typeof_specifier (c_parser
*);
1123 static struct c_declarator
*c_parser_declarator (c_parser
*, bool, c_dtr_syn
,
1125 static struct c_declarator
*c_parser_direct_declarator (c_parser
*, bool,
1127 static struct c_declarator
*c_parser_direct_declarator_inner (c_parser
*,
1129 struct c_declarator
*);
1130 static struct c_arg_info
*c_parser_parms_declarator (c_parser
*, bool, tree
);
1131 static struct c_arg_info
*c_parser_parms_list_declarator (c_parser
*, tree
,
1133 static struct c_parm
*c_parser_parameter_declaration (c_parser
*, tree
);
1134 static tree
c_parser_simple_asm_expr (c_parser
*);
1135 static tree
c_parser_attributes (c_parser
*);
1136 static struct c_type_name
*c_parser_type_name (c_parser
*);
1137 static struct c_expr
c_parser_initializer (c_parser
*);
1138 static struct c_expr
c_parser_braced_init (c_parser
*, tree
, bool);
1139 static void c_parser_initelt (c_parser
*, struct obstack
*);
1140 static void c_parser_initval (c_parser
*, struct c_expr
*,
1142 static tree
c_parser_compound_statement (c_parser
*);
1143 static void c_parser_compound_statement_nostart (c_parser
*);
1144 static void c_parser_label (c_parser
*);
1145 static void c_parser_statement (c_parser
*);
1146 static void c_parser_statement_after_labels (c_parser
*);
1147 static void c_parser_if_statement (c_parser
*);
1148 static void c_parser_switch_statement (c_parser
*);
1149 static void c_parser_while_statement (c_parser
*);
1150 static void c_parser_do_statement (c_parser
*);
1151 static void c_parser_for_statement (c_parser
*);
1152 static tree
c_parser_asm_statement (c_parser
*);
1153 static tree
c_parser_asm_operands (c_parser
*, bool);
1154 static tree
c_parser_asm_goto_operands (c_parser
*);
1155 static tree
c_parser_asm_clobbers (c_parser
*);
1156 static struct c_expr
c_parser_expr_no_commas (c_parser
*, struct c_expr
*);
1157 static struct c_expr
c_parser_conditional_expression (c_parser
*,
1159 static struct c_expr
c_parser_binary_expression (c_parser
*, struct c_expr
*,
1160 enum c_parser_prec
);
1161 static struct c_expr
c_parser_cast_expression (c_parser
*, struct c_expr
*);
1162 static struct c_expr
c_parser_unary_expression (c_parser
*);
1163 static struct c_expr
c_parser_sizeof_expression (c_parser
*);
1164 static struct c_expr
c_parser_alignof_expression (c_parser
*);
1165 static struct c_expr
c_parser_postfix_expression (c_parser
*);
1166 static struct c_expr
c_parser_postfix_expression_after_paren_type (c_parser
*,
1167 struct c_type_name
*,
1169 static struct c_expr
c_parser_postfix_expression_after_primary (c_parser
*,
1172 static struct c_expr
c_parser_expression (c_parser
*);
1173 static struct c_expr
c_parser_expression_conv (c_parser
*);
1174 static VEC(tree
,gc
) *c_parser_expr_list (c_parser
*, bool, bool,
1176 static void c_parser_omp_construct (c_parser
*);
1177 static void c_parser_omp_threadprivate (c_parser
*);
1178 static void c_parser_omp_barrier (c_parser
*);
1179 static void c_parser_omp_flush (c_parser
*);
1180 static void c_parser_omp_taskwait (c_parser
*);
1181 static void c_parser_omp_taskyield (c_parser
*);
1183 enum pragma_context
{ pragma_external
, pragma_stmt
, pragma_compound
};
1184 static bool c_parser_pragma (c_parser
*, enum pragma_context
);
1186 /* These Objective-C parser functions are only ever called when
1187 compiling Objective-C. */
1188 static void c_parser_objc_class_definition (c_parser
*, tree
);
1189 static void c_parser_objc_class_instance_variables (c_parser
*);
1190 static void c_parser_objc_class_declaration (c_parser
*);
1191 static void c_parser_objc_alias_declaration (c_parser
*);
1192 static void c_parser_objc_protocol_definition (c_parser
*, tree
);
1193 static bool c_parser_objc_method_type (c_parser
*);
1194 static void c_parser_objc_method_definition (c_parser
*);
1195 static void c_parser_objc_methodprotolist (c_parser
*);
1196 static void c_parser_objc_methodproto (c_parser
*);
1197 static tree
c_parser_objc_method_decl (c_parser
*, bool, tree
*, tree
*);
1198 static tree
c_parser_objc_type_name (c_parser
*);
1199 static tree
c_parser_objc_protocol_refs (c_parser
*);
1200 static void c_parser_objc_try_catch_finally_statement (c_parser
*);
1201 static void c_parser_objc_synchronized_statement (c_parser
*);
1202 static tree
c_parser_objc_selector (c_parser
*);
1203 static tree
c_parser_objc_selector_arg (c_parser
*);
1204 static tree
c_parser_objc_receiver (c_parser
*);
1205 static tree
c_parser_objc_message_args (c_parser
*);
1206 static tree
c_parser_objc_keywordexpr (c_parser
*);
1207 static void c_parser_objc_at_property_declaration (c_parser
*);
1208 static void c_parser_objc_at_synthesize_declaration (c_parser
*);
1209 static void c_parser_objc_at_dynamic_declaration (c_parser
*);
1210 static bool c_parser_objc_diagnose_bad_element_prefix
1211 (c_parser
*, struct c_declspecs
*);
1213 /* Parse a translation unit (C90 6.7, C99 6.9).
1216 external-declarations
1218 external-declarations:
1219 external-declaration
1220 external-declarations external-declaration
1229 c_parser_translation_unit (c_parser
*parser
)
1231 if (c_parser_next_token_is (parser
, CPP_EOF
))
1233 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
1234 "ISO C forbids an empty translation unit");
1238 void *obstack_position
= obstack_alloc (&parser_obstack
, 0);
1239 mark_valid_location_for_stdc_pragma (false);
1243 c_parser_external_declaration (parser
);
1244 obstack_free (&parser_obstack
, obstack_position
);
1246 while (c_parser_next_token_is_not (parser
, CPP_EOF
));
1250 /* Parse an external declaration (C90 6.7, C99 6.9).
1252 external-declaration:
1258 external-declaration:
1261 __extension__ external-declaration
1265 external-declaration:
1266 objc-class-definition
1267 objc-class-declaration
1268 objc-alias-declaration
1269 objc-protocol-definition
1270 objc-method-definition
1275 c_parser_external_declaration (c_parser
*parser
)
1278 switch (c_parser_peek_token (parser
)->type
)
1281 switch (c_parser_peek_token (parser
)->keyword
)
1284 ext
= disable_extension_diagnostics ();
1285 c_parser_consume_token (parser
);
1286 c_parser_external_declaration (parser
);
1287 restore_extension_diagnostics (ext
);
1290 c_parser_asm_definition (parser
);
1292 case RID_AT_INTERFACE
:
1293 case RID_AT_IMPLEMENTATION
:
1294 gcc_assert (c_dialect_objc ());
1295 c_parser_objc_class_definition (parser
, NULL_TREE
);
1298 gcc_assert (c_dialect_objc ());
1299 c_parser_objc_class_declaration (parser
);
1302 gcc_assert (c_dialect_objc ());
1303 c_parser_objc_alias_declaration (parser
);
1305 case RID_AT_PROTOCOL
:
1306 gcc_assert (c_dialect_objc ());
1307 c_parser_objc_protocol_definition (parser
, NULL_TREE
);
1309 case RID_AT_PROPERTY
:
1310 gcc_assert (c_dialect_objc ());
1311 c_parser_objc_at_property_declaration (parser
);
1313 case RID_AT_SYNTHESIZE
:
1314 gcc_assert (c_dialect_objc ());
1315 c_parser_objc_at_synthesize_declaration (parser
);
1317 case RID_AT_DYNAMIC
:
1318 gcc_assert (c_dialect_objc ());
1319 c_parser_objc_at_dynamic_declaration (parser
);
1322 gcc_assert (c_dialect_objc ());
1323 c_parser_consume_token (parser
);
1324 objc_finish_implementation ();
1331 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
1332 "ISO C does not allow extra %<;%> outside of a function");
1333 c_parser_consume_token (parser
);
1336 mark_valid_location_for_stdc_pragma (true);
1337 c_parser_pragma (parser
, pragma_external
);
1338 mark_valid_location_for_stdc_pragma (false);
1342 if (c_dialect_objc ())
1344 c_parser_objc_method_definition (parser
);
1347 /* Else fall through, and yield a syntax error trying to parse
1348 as a declaration or function definition. */
1351 /* A declaration or a function definition (or, in Objective-C,
1352 an @interface or @protocol with prefix attributes). We can
1353 only tell which after parsing the declaration specifiers, if
1354 any, and the first declarator. */
1355 c_parser_declaration_or_fndef (parser
, true, true, true, false, true, NULL
);
1360 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1361 6.7, 6.9.1). If FNDEF_OK is true, a function definition is
1362 accepted; otherwise (old-style parameter declarations) only other
1363 declarations are accepted. If STATIC_ASSERT_OK is true, a static
1364 assertion is accepted; otherwise (old-style parameter declarations)
1365 it is not. If NESTED is true, we are inside a function or parsing
1366 old-style parameter declarations; any functions encountered are
1367 nested functions and declaration specifiers are required; otherwise
1368 we are at top level and functions are normal functions and
1369 declaration specifiers may be optional. If EMPTY_OK is true, empty
1370 declarations are OK (subject to all other constraints); otherwise
1371 (old-style parameter declarations) they are diagnosed. If
1372 START_ATTR_OK is true, the declaration specifiers may start with
1373 attributes; otherwise they may not.
1374 OBJC_FOREACH_OBJECT_DECLARATION can be used to get back the parsed
1375 declaration when parsing an Objective-C foreach statement.
1378 declaration-specifiers init-declarator-list[opt] ;
1379 static_assert-declaration
1381 function-definition:
1382 declaration-specifiers[opt] declarator declaration-list[opt]
1387 declaration-list declaration
1389 init-declarator-list:
1391 init-declarator-list , init-declarator
1394 declarator simple-asm-expr[opt] attributes[opt]
1395 declarator simple-asm-expr[opt] attributes[opt] = initializer
1399 nested-function-definition:
1400 declaration-specifiers declarator declaration-list[opt]
1404 attributes objc-class-definition
1405 attributes objc-category-definition
1406 attributes objc-protocol-definition
1408 The simple-asm-expr and attributes are GNU extensions.
1410 This function does not handle __extension__; that is handled in its
1411 callers. ??? Following the old parser, __extension__ may start
1412 external declarations, declarations in functions and declarations
1413 at the start of "for" loops, but not old-style parameter
1416 C99 requires declaration specifiers in a function definition; the
1417 absence is diagnosed through the diagnosis of implicit int. In GNU
1418 C we also allow but diagnose declarations without declaration
1419 specifiers, but only at top level (elsewhere they conflict with
1422 In Objective-C, declarations of the looping variable in a foreach
1423 statement are exceptionally terminated by 'in' (for example, 'for
1424 (NSObject *object in array) { ... }').
1429 threadprivate-directive */
1432 c_parser_declaration_or_fndef (c_parser
*parser
, bool fndef_ok
,
1433 bool static_assert_ok
, bool empty_ok
,
1434 bool nested
, bool start_attr_ok
,
1435 tree
*objc_foreach_object_declaration
)
1437 struct c_declspecs
*specs
;
1439 tree all_prefix_attrs
;
1440 bool diagnosed_no_specs
= false;
1441 location_t here
= c_parser_peek_token (parser
)->location
;
1443 if (static_assert_ok
1444 && c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
1446 c_parser_static_assert_declaration (parser
);
1449 specs
= build_null_declspecs ();
1451 /* Try to detect an unknown type name when we have "A B" or "A *B". */
1452 if (c_parser_peek_token (parser
)->type
== CPP_NAME
1453 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
1454 && (c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
1455 || c_parser_peek_2nd_token (parser
)->type
== CPP_MULT
)
1456 && (!nested
|| !lookup_name (c_parser_peek_token (parser
)->value
)))
1458 error_at (here
, "unknown type name %qE",
1459 c_parser_peek_token (parser
)->value
);
1461 /* Parse declspecs normally to get a correct pointer type, but avoid
1462 a further "fails to be a type name" error. Refuse nested functions
1463 since it is not how the user likely wants us to recover. */
1464 c_parser_peek_token (parser
)->type
= CPP_KEYWORD
;
1465 c_parser_peek_token (parser
)->keyword
= RID_VOID
;
1466 c_parser_peek_token (parser
)->value
= error_mark_node
;
1470 c_parser_declspecs (parser
, specs
, true, true, start_attr_ok
, cla_nonabstract_decl
);
1473 c_parser_skip_to_end_of_block_or_statement (parser
);
1476 if (nested
&& !specs
->declspecs_seen_p
)
1478 c_parser_error (parser
, "expected declaration specifiers");
1479 c_parser_skip_to_end_of_block_or_statement (parser
);
1482 finish_declspecs (specs
);
1483 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1489 shadow_tag_warned (specs
, 1);
1490 pedwarn (here
, 0, "empty declaration");
1492 c_parser_consume_token (parser
);
1496 /* Provide better error recovery. Note that a type name here is usually
1497 better diagnosed as a redeclaration. */
1499 && specs
->typespec_kind
== ctsk_tagdef
1500 && c_parser_next_token_starts_declspecs (parser
)
1501 && !c_parser_next_token_is (parser
, CPP_NAME
))
1503 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
1504 parser
->error
= false;
1505 shadow_tag_warned (specs
, 1);
1508 else if (c_dialect_objc ())
1510 /* Prefix attributes are an error on method decls. */
1511 switch (c_parser_peek_token (parser
)->type
)
1515 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1519 warning_at (c_parser_peek_token (parser
)->location
,
1521 "prefix attributes are ignored for methods");
1522 specs
->attrs
= NULL_TREE
;
1525 c_parser_objc_method_definition (parser
);
1527 c_parser_objc_methodproto (parser
);
1533 /* This is where we parse 'attributes @interface ...',
1534 'attributes @implementation ...', 'attributes @protocol ...'
1535 (where attributes could be, for example, __attribute__
1538 switch (c_parser_peek_token (parser
)->keyword
)
1540 case RID_AT_INTERFACE
:
1542 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1544 c_parser_objc_class_definition (parser
, specs
->attrs
);
1548 case RID_AT_IMPLEMENTATION
:
1550 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1554 warning_at (c_parser_peek_token (parser
)->location
,
1556 "prefix attributes are ignored for implementations");
1557 specs
->attrs
= NULL_TREE
;
1559 c_parser_objc_class_definition (parser
, NULL_TREE
);
1563 case RID_AT_PROTOCOL
:
1565 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1567 c_parser_objc_protocol_definition (parser
, specs
->attrs
);
1574 case RID_AT_PROPERTY
:
1577 c_parser_error (parser
, "unexpected attribute");
1578 specs
->attrs
= NULL
;
1586 pending_xref_error ();
1587 prefix_attrs
= specs
->attrs
;
1588 all_prefix_attrs
= prefix_attrs
;
1589 specs
->attrs
= NULL_TREE
;
1592 struct c_declarator
*declarator
;
1596 /* Declaring either one or more declarators (in which case we
1597 should diagnose if there were no declaration specifiers) or a
1598 function definition (in which case the diagnostic for
1599 implicit int suffices). */
1600 declarator
= c_parser_declarator (parser
,
1601 specs
->typespec_kind
!= ctsk_none
,
1602 C_DTR_NORMAL
, &dummy
);
1603 if (declarator
== NULL
)
1605 c_parser_skip_to_end_of_block_or_statement (parser
);
1608 if (c_parser_next_token_is (parser
, CPP_EQ
)
1609 || c_parser_next_token_is (parser
, CPP_COMMA
)
1610 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
1611 || c_parser_next_token_is_keyword (parser
, RID_ASM
)
1612 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
)
1613 || c_parser_next_token_is_keyword (parser
, RID_IN
))
1615 tree asm_name
= NULL_TREE
;
1616 tree postfix_attrs
= NULL_TREE
;
1617 if (!diagnosed_no_specs
&& !specs
->declspecs_seen_p
)
1619 diagnosed_no_specs
= true;
1620 pedwarn (here
, 0, "data definition has no type or storage class");
1622 /* Having seen a data definition, there cannot now be a
1623 function definition. */
1625 if (c_parser_next_token_is_keyword (parser
, RID_ASM
))
1626 asm_name
= c_parser_simple_asm_expr (parser
);
1627 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1628 postfix_attrs
= c_parser_attributes (parser
);
1629 if (c_parser_next_token_is (parser
, CPP_EQ
))
1633 location_t init_loc
;
1634 c_parser_consume_token (parser
);
1635 /* The declaration of the variable is in effect while
1636 its initializer is parsed. */
1637 d
= start_decl (declarator
, specs
, true,
1638 chainon (postfix_attrs
, all_prefix_attrs
));
1640 d
= error_mark_node
;
1641 start_init (d
, asm_name
, global_bindings_p ());
1642 init_loc
= c_parser_peek_token (parser
)->location
;
1643 init
= c_parser_initializer (parser
);
1645 if (d
!= error_mark_node
)
1647 maybe_warn_string_init (TREE_TYPE (d
), init
);
1648 finish_decl (d
, init_loc
, init
.value
,
1649 init
.original_type
, asm_name
);
1654 tree d
= start_decl (declarator
, specs
, false,
1655 chainon (postfix_attrs
,
1658 finish_decl (d
, UNKNOWN_LOCATION
, NULL_TREE
,
1659 NULL_TREE
, asm_name
);
1661 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
1664 *objc_foreach_object_declaration
= d
;
1666 *objc_foreach_object_declaration
= error_mark_node
;
1669 if (c_parser_next_token_is (parser
, CPP_COMMA
))
1671 c_parser_consume_token (parser
);
1672 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1673 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
1676 all_prefix_attrs
= prefix_attrs
;
1679 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1681 c_parser_consume_token (parser
);
1684 else if (c_parser_next_token_is_keyword (parser
, RID_IN
))
1686 /* This can only happen in Objective-C: we found the
1687 'in' that terminates the declaration inside an
1688 Objective-C foreach statement. Do not consume the
1689 token, so that the caller can use it to determine
1690 that this indeed is a foreach context. */
1695 c_parser_error (parser
, "expected %<,%> or %<;%>");
1696 c_parser_skip_to_end_of_block_or_statement (parser
);
1702 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, "
1703 "%<asm%> or %<__attribute__%>");
1704 c_parser_skip_to_end_of_block_or_statement (parser
);
1707 /* Function definition (nested or otherwise). */
1710 pedwarn (here
, OPT_pedantic
, "ISO C forbids nested functions");
1711 c_push_function_context ();
1713 if (!start_function (specs
, declarator
, all_prefix_attrs
))
1715 /* This can appear in many cases looking nothing like a
1716 function definition, so we don't give a more specific
1717 error suggesting there was one. */
1718 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
1719 "or %<__attribute__%>");
1721 c_pop_function_context ();
1725 if (DECL_DECLARED_INLINE_P (current_function_decl
))
1726 tv
= TV_PARSE_INLINE
;
1731 /* Parse old-style parameter declarations. ??? Attributes are
1732 not allowed to start declaration specifiers here because of a
1733 syntax conflict between a function declaration with attribute
1734 suffix and a function definition with an attribute prefix on
1735 first old-style parameter declaration. Following the old
1736 parser, they are not accepted on subsequent old-style
1737 parameter declarations either. However, there is no
1738 ambiguity after the first declaration, nor indeed on the
1739 first as long as we don't allow postfix attributes after a
1740 declarator with a nonempty identifier list in a definition;
1741 and postfix attributes have never been accepted here in
1742 function definitions either. */
1743 while (c_parser_next_token_is_not (parser
, CPP_EOF
)
1744 && c_parser_next_token_is_not (parser
, CPP_OPEN_BRACE
))
1745 c_parser_declaration_or_fndef (parser
, false, false, false,
1747 store_parm_decls ();
1748 DECL_STRUCT_FUNCTION (current_function_decl
)->function_start_locus
1749 = c_parser_peek_token (parser
)->location
;
1750 fnbody
= c_parser_compound_statement (parser
);
1753 tree decl
= current_function_decl
;
1754 /* Mark nested functions as needing static-chain initially.
1755 lower_nested_functions will recompute it but the
1756 DECL_STATIC_CHAIN flag is also used before that happens,
1757 by initializer_constant_valid_p. See gcc.dg/nested-fn-2.c. */
1758 DECL_STATIC_CHAIN (decl
) = 1;
1761 c_pop_function_context ();
1762 add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl
), DECL_EXPR
, decl
));
1775 /* Parse an asm-definition (asm() outside a function body). This is a
1783 c_parser_asm_definition (c_parser
*parser
)
1785 tree asm_str
= c_parser_simple_asm_expr (parser
);
1787 cgraph_add_asm_node (asm_str
);
1788 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
1791 /* Parse a static assertion (C1X N1425 6.7.10).
1793 static_assert-declaration:
1794 static_assert-declaration-no-semi ;
1798 c_parser_static_assert_declaration (c_parser
*parser
)
1800 c_parser_static_assert_declaration_no_semi (parser
);
1802 || !c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
1803 c_parser_skip_to_end_of_block_or_statement (parser
);
1806 /* Parse a static assertion (C1X N1425 6.7.10), without the trailing
1809 static_assert-declaration-no-semi:
1810 _Static_assert ( constant-expression , string-literal )
1814 c_parser_static_assert_declaration_no_semi (c_parser
*parser
)
1816 location_t assert_loc
, value_loc
;
1820 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
));
1821 assert_loc
= c_parser_peek_token (parser
)->location
;
1825 pedwarn (assert_loc
, OPT_pedantic
,
1826 "ISO C99 does not support %<_Static_assert%>");
1828 pedwarn (assert_loc
, OPT_pedantic
,
1829 "ISO C90 does not support %<_Static_assert%>");
1831 c_parser_consume_token (parser
);
1832 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
1834 value_loc
= c_parser_peek_token (parser
)->location
;
1835 value
= c_parser_expr_no_commas (parser
, NULL
).value
;
1836 parser
->lex_untranslated_string
= true;
1837 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
1839 parser
->lex_untranslated_string
= false;
1842 switch (c_parser_peek_token (parser
)->type
)
1848 case CPP_UTF8STRING
:
1849 string
= c_parser_peek_token (parser
)->value
;
1850 c_parser_consume_token (parser
);
1851 parser
->lex_untranslated_string
= false;
1854 c_parser_error (parser
, "expected string literal");
1855 parser
->lex_untranslated_string
= false;
1858 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
1860 if (!INTEGRAL_TYPE_P (TREE_TYPE (value
)))
1862 error_at (value_loc
, "expression in static assertion is not an integer");
1865 if (TREE_CODE (value
) != INTEGER_CST
)
1867 value
= c_fully_fold (value
, false, NULL
);
1868 if (TREE_CODE (value
) == INTEGER_CST
)
1869 pedwarn (value_loc
, OPT_pedantic
, "expression in static assertion "
1870 "is not an integer constant expression");
1872 if (TREE_CODE (value
) != INTEGER_CST
)
1874 error_at (value_loc
, "expression in static assertion is not constant");
1877 constant_expression_warning (value
);
1878 if (integer_zerop (value
))
1879 error_at (assert_loc
, "static assertion failed: %E", string
);
1882 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
1883 6.7), adding them to SPECS (which may already include some).
1884 Storage class specifiers are accepted iff SCSPEC_OK; type
1885 specifiers are accepted iff TYPESPEC_OK; attributes are accepted at
1886 the start iff START_ATTR_OK.
1888 declaration-specifiers:
1889 storage-class-specifier declaration-specifiers[opt]
1890 type-specifier declaration-specifiers[opt]
1891 type-qualifier declaration-specifiers[opt]
1892 function-specifier declaration-specifiers[opt]
1894 Function specifiers (inline) are from C99, and are currently
1895 handled as storage class specifiers, as is __thread.
1897 C90 6.5.1, C99 6.7.1:
1898 storage-class-specifier:
1910 (_Noreturn is new in C1X.)
1912 C90 6.5.2, C99 6.7.2:
1925 [_Imaginary removed in C99 TC2]
1926 struct-or-union-specifier
1930 (_Bool and _Complex are new in C99.)
1932 C90 6.5.3, C99 6.7.3:
1938 address-space-qualifier
1940 (restrict is new in C99.)
1944 declaration-specifiers:
1945 attributes declaration-specifiers[opt]
1951 identifier recognized by the target
1953 storage-class-specifier:
1966 (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
1967 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
1972 class-name objc-protocol-refs[opt]
1973 typedef-name objc-protocol-refs
1978 c_parser_declspecs (c_parser
*parser
, struct c_declspecs
*specs
,
1979 bool scspec_ok
, bool typespec_ok
, bool start_attr_ok
,
1980 enum c_lookahead_kind la
)
1982 bool attrs_ok
= start_attr_ok
;
1983 bool seen_type
= specs
->typespec_kind
!= ctsk_none
;
1986 gcc_assert (la
== cla_prefer_id
);
1988 while (c_parser_next_token_is (parser
, CPP_NAME
)
1989 || c_parser_next_token_is (parser
, CPP_KEYWORD
)
1990 || (c_dialect_objc () && c_parser_next_token_is (parser
, CPP_LESS
)))
1992 struct c_typespec t
;
1994 location_t loc
= c_parser_peek_token (parser
)->location
;
1996 /* If we cannot accept a type, exit if the next token must start
1997 one. Also, if we already have seen a tagged definition,
1998 a typename would be an error anyway and likely the user
1999 has simply forgotten a semicolon, so we exit. */
2000 if ((!typespec_ok
|| specs
->typespec_kind
== ctsk_tagdef
)
2001 && c_parser_next_tokens_start_typename (parser
, la
)
2002 && !c_parser_next_token_is_qualifier (parser
))
2005 if (c_parser_next_token_is (parser
, CPP_NAME
))
2007 tree value
= c_parser_peek_token (parser
)->value
;
2008 c_id_kind kind
= c_parser_peek_token (parser
)->id_kind
;
2010 if (kind
== C_ID_ADDRSPACE
)
2013 = c_parser_peek_token (parser
)->keyword
- RID_FIRST_ADDR_SPACE
;
2014 declspecs_add_addrspace (specs
, as
);
2015 c_parser_consume_token (parser
);
2020 gcc_assert (!c_parser_next_token_is_qualifier (parser
));
2022 /* If we cannot accept a type, and the next token must start one,
2023 exit. Do the same if we already have seen a tagged definition,
2024 since it would be an error anyway and likely the user has simply
2025 forgotten a semicolon. */
2026 if (seen_type
|| !c_parser_next_tokens_start_typename (parser
, la
))
2029 /* Now at an unknown typename (C_ID_ID), a C_ID_TYPENAME or
2030 a C_ID_CLASSNAME. */
2031 c_parser_consume_token (parser
);
2034 if (kind
== C_ID_ID
)
2036 error ("unknown type name %qE", value
);
2037 t
.kind
= ctsk_typedef
;
2038 t
.spec
= error_mark_node
;
2040 else if (kind
== C_ID_TYPENAME
2041 && (!c_dialect_objc ()
2042 || c_parser_next_token_is_not (parser
, CPP_LESS
)))
2044 t
.kind
= ctsk_typedef
;
2045 /* For a typedef name, record the meaning, not the name.
2046 In case of 'foo foo, bar;'. */
2047 t
.spec
= lookup_name (value
);
2051 tree proto
= NULL_TREE
;
2052 gcc_assert (c_dialect_objc ());
2054 if (c_parser_next_token_is (parser
, CPP_LESS
))
2055 proto
= c_parser_objc_protocol_refs (parser
);
2056 t
.spec
= objc_get_protocol_qualified_type (value
, proto
);
2059 t
.expr_const_operands
= true;
2060 declspecs_add_type (loc
, specs
, t
);
2063 if (c_parser_next_token_is (parser
, CPP_LESS
))
2065 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
2066 nisse@lysator.liu.se. */
2068 gcc_assert (c_dialect_objc ());
2069 if (!typespec_ok
|| seen_type
)
2071 proto
= c_parser_objc_protocol_refs (parser
);
2073 t
.spec
= objc_get_protocol_qualified_type (NULL_TREE
, proto
);
2075 t
.expr_const_operands
= true;
2076 declspecs_add_type (loc
, specs
, t
);
2079 gcc_assert (c_parser_next_token_is (parser
, CPP_KEYWORD
));
2080 switch (c_parser_peek_token (parser
)->keyword
)
2093 /* TODO: Distinguish between function specifiers (inline, noreturn)
2094 and storage class specifiers, either here or in
2095 declspecs_add_scspec. */
2096 declspecs_add_scspec (specs
, c_parser_peek_token (parser
)->value
);
2097 c_parser_consume_token (parser
);
2121 if (c_dialect_objc ())
2122 parser
->objc_need_raw_identifier
= true;
2123 t
.kind
= ctsk_resword
;
2124 t
.spec
= c_parser_peek_token (parser
)->value
;
2126 t
.expr_const_operands
= true;
2127 declspecs_add_type (loc
, specs
, t
);
2128 c_parser_consume_token (parser
);
2135 t
= c_parser_enum_specifier (parser
);
2136 declspecs_add_type (loc
, specs
, t
);
2144 t
= c_parser_struct_or_union_specifier (parser
);
2145 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE
, t
.spec
);
2146 declspecs_add_type (loc
, specs
, t
);
2149 /* ??? The old parser rejected typeof after other type
2150 specifiers, but is a syntax error the best way of
2152 if (!typespec_ok
|| seen_type
)
2156 t
= c_parser_typeof_specifier (parser
);
2157 declspecs_add_type (loc
, specs
, t
);
2163 declspecs_add_qual (specs
, c_parser_peek_token (parser
)->value
);
2164 c_parser_consume_token (parser
);
2169 attrs
= c_parser_attributes (parser
);
2170 declspecs_add_attrs (specs
, attrs
);
2179 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
2182 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
2183 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
2184 enum attributes[opt] identifier
2186 The form with trailing comma is new in C99. The forms with
2187 attributes are GNU extensions. In GNU C, we accept any expression
2188 without commas in the syntax (assignment expressions, not just
2189 conditional expressions); assignment expressions will be diagnosed
2194 enumerator-list , enumerator
2197 enumeration-constant
2198 enumeration-constant = constant-expression
2201 static struct c_typespec
2202 c_parser_enum_specifier (c_parser
*parser
)
2204 struct c_typespec ret
;
2206 tree ident
= NULL_TREE
;
2207 location_t enum_loc
;
2208 location_t ident_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2209 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ENUM
));
2210 enum_loc
= c_parser_peek_token (parser
)->location
;
2211 c_parser_consume_token (parser
);
2212 attrs
= c_parser_attributes (parser
);
2213 enum_loc
= c_parser_peek_token (parser
)->location
;
2214 /* Set the location in case we create a decl now. */
2215 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2216 if (c_parser_next_token_is (parser
, CPP_NAME
))
2218 ident
= c_parser_peek_token (parser
)->value
;
2219 ident_loc
= c_parser_peek_token (parser
)->location
;
2220 enum_loc
= ident_loc
;
2221 c_parser_consume_token (parser
);
2223 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2225 /* Parse an enum definition. */
2226 struct c_enum_contents the_enum
;
2229 /* We chain the enumerators in reverse order, then put them in
2230 forward order at the end. */
2232 timevar_push (TV_PARSE_ENUM
);
2233 type
= start_enum (enum_loc
, &the_enum
, ident
);
2235 c_parser_consume_token (parser
);
2243 location_t comma_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2244 location_t decl_loc
, value_loc
;
2245 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
2247 c_parser_error (parser
, "expected identifier");
2248 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2249 values
= error_mark_node
;
2252 token
= c_parser_peek_token (parser
);
2253 enum_id
= token
->value
;
2254 /* Set the location in case we create a decl now. */
2255 c_parser_set_source_position_from_token (token
);
2256 decl_loc
= value_loc
= token
->location
;
2257 c_parser_consume_token (parser
);
2258 if (c_parser_next_token_is (parser
, CPP_EQ
))
2260 c_parser_consume_token (parser
);
2261 value_loc
= c_parser_peek_token (parser
)->location
;
2262 enum_value
= c_parser_expr_no_commas (parser
, NULL
).value
;
2265 enum_value
= NULL_TREE
;
2266 enum_decl
= build_enumerator (decl_loc
, value_loc
,
2267 &the_enum
, enum_id
, enum_value
);
2268 TREE_CHAIN (enum_decl
) = values
;
2271 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2273 comma_loc
= c_parser_peek_token (parser
)->location
;
2275 c_parser_consume_token (parser
);
2277 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2279 if (seen_comma
&& !flag_isoc99
)
2280 pedwarn (comma_loc
, OPT_pedantic
, "comma at end of enumerator list");
2281 c_parser_consume_token (parser
);
2286 c_parser_error (parser
, "expected %<,%> or %<}%>");
2287 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2288 values
= error_mark_node
;
2292 postfix_attrs
= c_parser_attributes (parser
);
2293 ret
.spec
= finish_enum (type
, nreverse (values
),
2294 chainon (attrs
, postfix_attrs
));
2295 ret
.kind
= ctsk_tagdef
;
2296 ret
.expr
= NULL_TREE
;
2297 ret
.expr_const_operands
= true;
2298 timevar_pop (TV_PARSE_ENUM
);
2303 c_parser_error (parser
, "expected %<{%>");
2304 ret
.spec
= error_mark_node
;
2305 ret
.kind
= ctsk_tagref
;
2306 ret
.expr
= NULL_TREE
;
2307 ret
.expr_const_operands
= true;
2310 ret
= parser_xref_tag (ident_loc
, ENUMERAL_TYPE
, ident
);
2311 /* In ISO C, enumerated types can be referred to only if already
2313 if (pedantic
&& !COMPLETE_TYPE_P (ret
.spec
))
2316 pedwarn (enum_loc
, OPT_pedantic
,
2317 "ISO C forbids forward references to %<enum%> types");
2322 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
2324 struct-or-union-specifier:
2325 struct-or-union attributes[opt] identifier[opt]
2326 { struct-contents } attributes[opt]
2327 struct-or-union attributes[opt] identifier
2330 struct-declaration-list
2332 struct-declaration-list:
2333 struct-declaration ;
2334 struct-declaration-list struct-declaration ;
2341 struct-declaration-list struct-declaration
2343 struct-declaration-list:
2344 struct-declaration-list ;
2347 (Note that in the syntax here, unlike that in ISO C, the semicolons
2348 are included here rather than in struct-declaration, in order to
2349 describe the syntax with extra semicolons and missing semicolon at
2354 struct-declaration-list:
2355 @defs ( class-name )
2357 (Note this does not include a trailing semicolon, but can be
2358 followed by further declarations, and gets a pedwarn-if-pedantic
2359 when followed by a semicolon.) */
2361 static struct c_typespec
2362 c_parser_struct_or_union_specifier (c_parser
*parser
)
2364 struct c_typespec ret
;
2366 tree ident
= NULL_TREE
;
2367 location_t struct_loc
;
2368 location_t ident_loc
= UNKNOWN_LOCATION
;
2369 enum tree_code code
;
2370 switch (c_parser_peek_token (parser
)->keyword
)
2381 struct_loc
= c_parser_peek_token (parser
)->location
;
2382 c_parser_consume_token (parser
);
2383 attrs
= c_parser_attributes (parser
);
2385 /* Set the location in case we create a decl now. */
2386 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2388 if (c_parser_next_token_is (parser
, CPP_NAME
))
2390 ident
= c_parser_peek_token (parser
)->value
;
2391 ident_loc
= c_parser_peek_token (parser
)->location
;
2392 struct_loc
= ident_loc
;
2393 c_parser_consume_token (parser
);
2395 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2397 /* Parse a struct or union definition. Start the scope of the
2398 tag before parsing components. */
2399 struct c_struct_parse_info
*struct_info
;
2400 tree type
= start_struct (struct_loc
, code
, ident
, &struct_info
);
2402 /* We chain the components in reverse order, then put them in
2403 forward order at the end. Each struct-declaration may
2404 declare multiple components (comma-separated), so we must use
2405 chainon to join them, although when parsing each
2406 struct-declaration we can use TREE_CHAIN directly.
2408 The theory behind all this is that there will be more
2409 semicolon separated fields than comma separated fields, and
2410 so we'll be minimizing the number of node traversals required
2413 timevar_push (TV_PARSE_STRUCT
);
2414 contents
= NULL_TREE
;
2415 c_parser_consume_token (parser
);
2416 /* Handle the Objective-C @defs construct,
2417 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
2418 if (c_parser_next_token_is_keyword (parser
, RID_AT_DEFS
))
2421 gcc_assert (c_dialect_objc ());
2422 c_parser_consume_token (parser
);
2423 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2425 if (c_parser_next_token_is (parser
, CPP_NAME
)
2426 && c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
)
2428 name
= c_parser_peek_token (parser
)->value
;
2429 c_parser_consume_token (parser
);
2433 c_parser_error (parser
, "expected class name");
2434 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2437 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2439 contents
= nreverse (objc_get_class_ivars (name
));
2442 /* Parse the struct-declarations and semicolons. Problems with
2443 semicolons are diagnosed here; empty structures are diagnosed
2448 /* Parse any stray semicolon. */
2449 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2451 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
2452 "extra semicolon in struct or union specified");
2453 c_parser_consume_token (parser
);
2456 /* Stop if at the end of the struct or union contents. */
2457 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2459 c_parser_consume_token (parser
);
2462 /* Accept #pragmas at struct scope. */
2463 if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
2465 c_parser_pragma (parser
, pragma_external
);
2468 /* Parse some comma-separated declarations, but not the
2469 trailing semicolon if any. */
2470 decls
= c_parser_struct_declaration (parser
);
2471 contents
= chainon (decls
, contents
);
2472 /* If no semicolon follows, either we have a parse error or
2473 are at the end of the struct or union and should
2475 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2476 c_parser_consume_token (parser
);
2479 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2480 pedwarn (c_parser_peek_token (parser
)->location
, 0,
2481 "no semicolon at end of struct or union");
2482 else if (parser
->error
2483 || !c_parser_next_token_starts_declspecs (parser
))
2485 c_parser_error (parser
, "expected %<;%>");
2486 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2490 /* If we come here, we have already emitted an error
2491 for an expected `;', identifier or `(', and we also
2492 recovered already. Go on with the next field. */
2495 postfix_attrs
= c_parser_attributes (parser
);
2496 ret
.spec
= finish_struct (struct_loc
, type
, nreverse (contents
),
2497 chainon (attrs
, postfix_attrs
), struct_info
);
2498 ret
.kind
= ctsk_tagdef
;
2499 ret
.expr
= NULL_TREE
;
2500 ret
.expr_const_operands
= true;
2501 timevar_pop (TV_PARSE_STRUCT
);
2506 c_parser_error (parser
, "expected %<{%>");
2507 ret
.spec
= error_mark_node
;
2508 ret
.kind
= ctsk_tagref
;
2509 ret
.expr
= NULL_TREE
;
2510 ret
.expr_const_operands
= true;
2513 ret
= parser_xref_tag (ident_loc
, code
, ident
);
2517 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
2518 the trailing semicolon.
2521 specifier-qualifier-list struct-declarator-list
2522 static_assert-declaration-no-semi
2524 specifier-qualifier-list:
2525 type-specifier specifier-qualifier-list[opt]
2526 type-qualifier specifier-qualifier-list[opt]
2527 attributes specifier-qualifier-list[opt]
2529 struct-declarator-list:
2531 struct-declarator-list , attributes[opt] struct-declarator
2534 declarator attributes[opt]
2535 declarator[opt] : constant-expression attributes[opt]
2540 __extension__ struct-declaration
2541 specifier-qualifier-list
2543 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
2544 of attributes where shown is a GNU extension. In GNU C, we accept
2545 any expression without commas in the syntax (assignment
2546 expressions, not just conditional expressions); assignment
2547 expressions will be diagnosed as non-constant. */
2550 c_parser_struct_declaration (c_parser
*parser
)
2552 struct c_declspecs
*specs
;
2554 tree all_prefix_attrs
;
2556 location_t decl_loc
;
2557 if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
2561 ext
= disable_extension_diagnostics ();
2562 c_parser_consume_token (parser
);
2563 decl
= c_parser_struct_declaration (parser
);
2564 restore_extension_diagnostics (ext
);
2567 if (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
2569 c_parser_static_assert_declaration_no_semi (parser
);
2572 specs
= build_null_declspecs ();
2573 decl_loc
= c_parser_peek_token (parser
)->location
;
2574 c_parser_declspecs (parser
, specs
, false, true, true, cla_nonabstract_decl
);
2577 if (!specs
->declspecs_seen_p
)
2579 c_parser_error (parser
, "expected specifier-qualifier-list");
2582 finish_declspecs (specs
);
2583 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2584 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2587 if (specs
->typespec_kind
== ctsk_none
)
2589 pedwarn (decl_loc
, OPT_pedantic
,
2590 "ISO C forbids member declarations with no members");
2591 shadow_tag_warned (specs
, pedantic
);
2596 /* Support for unnamed structs or unions as members of
2597 structs or unions (which is [a] useful and [b] supports
2601 ret
= grokfield (c_parser_peek_token (parser
)->location
,
2602 build_id_declarator (NULL_TREE
), specs
,
2605 decl_attributes (&ret
, attrs
, 0);
2610 /* Provide better error recovery. Note that a type name here is valid,
2611 and will be treated as a field name. */
2612 if (specs
->typespec_kind
== ctsk_tagdef
2613 && TREE_CODE (specs
->type
) != ENUMERAL_TYPE
2614 && c_parser_next_token_starts_declspecs (parser
)
2615 && !c_parser_next_token_is (parser
, CPP_NAME
))
2617 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
2618 parser
->error
= false;
2622 pending_xref_error ();
2623 prefix_attrs
= specs
->attrs
;
2624 all_prefix_attrs
= prefix_attrs
;
2625 specs
->attrs
= NULL_TREE
;
2629 /* Declaring one or more declarators or un-named bit-fields. */
2630 struct c_declarator
*declarator
;
2632 if (c_parser_next_token_is (parser
, CPP_COLON
))
2633 declarator
= build_id_declarator (NULL_TREE
);
2635 declarator
= c_parser_declarator (parser
,
2636 specs
->typespec_kind
!= ctsk_none
,
2637 C_DTR_NORMAL
, &dummy
);
2638 if (declarator
== NULL
)
2640 c_parser_skip_to_end_of_block_or_statement (parser
);
2643 if (c_parser_next_token_is (parser
, CPP_COLON
)
2644 || c_parser_next_token_is (parser
, CPP_COMMA
)
2645 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2646 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
)
2647 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2649 tree postfix_attrs
= NULL_TREE
;
2650 tree width
= NULL_TREE
;
2652 if (c_parser_next_token_is (parser
, CPP_COLON
))
2654 c_parser_consume_token (parser
);
2655 width
= c_parser_expr_no_commas (parser
, NULL
).value
;
2657 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2658 postfix_attrs
= c_parser_attributes (parser
);
2659 d
= grokfield (c_parser_peek_token (parser
)->location
,
2660 declarator
, specs
, width
, &all_prefix_attrs
);
2661 decl_attributes (&d
, chainon (postfix_attrs
,
2662 all_prefix_attrs
), 0);
2663 DECL_CHAIN (d
) = decls
;
2665 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2666 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
2669 all_prefix_attrs
= prefix_attrs
;
2670 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2671 c_parser_consume_token (parser
);
2672 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2673 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2675 /* Semicolon consumed in caller. */
2680 c_parser_error (parser
, "expected %<,%>, %<;%> or %<}%>");
2686 c_parser_error (parser
,
2687 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
2688 "%<__attribute__%>");
2695 /* Parse a typeof specifier (a GNU extension).
2698 typeof ( expression )
2699 typeof ( type-name )
2702 static struct c_typespec
2703 c_parser_typeof_specifier (c_parser
*parser
)
2705 struct c_typespec ret
;
2706 ret
.kind
= ctsk_typeof
;
2707 ret
.spec
= error_mark_node
;
2708 ret
.expr
= NULL_TREE
;
2709 ret
.expr_const_operands
= true;
2710 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TYPEOF
));
2711 c_parser_consume_token (parser
);
2712 c_inhibit_evaluation_warnings
++;
2714 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2716 c_inhibit_evaluation_warnings
--;
2720 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
2722 struct c_type_name
*type
= c_parser_type_name (parser
);
2723 c_inhibit_evaluation_warnings
--;
2727 ret
.spec
= groktypename (type
, &ret
.expr
, &ret
.expr_const_operands
);
2728 pop_maybe_used (variably_modified_type_p (ret
.spec
, NULL_TREE
));
2734 location_t here
= c_parser_peek_token (parser
)->location
;
2735 struct c_expr expr
= c_parser_expression (parser
);
2736 c_inhibit_evaluation_warnings
--;
2738 if (TREE_CODE (expr
.value
) == COMPONENT_REF
2739 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
2740 error_at (here
, "%<typeof%> applied to a bit-field");
2741 mark_exp_read (expr
.value
);
2742 ret
.spec
= TREE_TYPE (expr
.value
);
2743 was_vm
= variably_modified_type_p (ret
.spec
, NULL_TREE
);
2744 /* This is returned with the type so that when the type is
2745 evaluated, this can be evaluated. */
2747 ret
.expr
= c_fully_fold (expr
.value
, false, &ret
.expr_const_operands
);
2748 pop_maybe_used (was_vm
);
2750 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
2754 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
2755 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
2756 be redeclared; otherwise it may not. KIND indicates which kind of
2757 declarator is wanted. Returns a valid declarator except in the
2758 case of a syntax error in which case NULL is returned. *SEEN_ID is
2759 set to true if an identifier being declared is seen; this is used
2760 to diagnose bad forms of abstract array declarators and to
2761 determine whether an identifier list is syntactically permitted.
2764 pointer[opt] direct-declarator
2768 ( attributes[opt] declarator )
2769 direct-declarator array-declarator
2770 direct-declarator ( parameter-type-list )
2771 direct-declarator ( identifier-list[opt] )
2774 * type-qualifier-list[opt]
2775 * type-qualifier-list[opt] pointer
2777 type-qualifier-list:
2780 type-qualifier-list type-qualifier
2781 type-qualifier-list attributes
2783 parameter-type-list:
2785 parameter-list , ...
2788 parameter-declaration
2789 parameter-list , parameter-declaration
2791 parameter-declaration:
2792 declaration-specifiers declarator attributes[opt]
2793 declaration-specifiers abstract-declarator[opt] attributes[opt]
2797 identifier-list , identifier
2799 abstract-declarator:
2801 pointer[opt] direct-abstract-declarator
2803 direct-abstract-declarator:
2804 ( attributes[opt] abstract-declarator )
2805 direct-abstract-declarator[opt] array-declarator
2806 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
2811 direct-declarator ( parameter-forward-declarations
2812 parameter-type-list[opt] )
2814 direct-abstract-declarator:
2815 direct-abstract-declarator[opt] ( parameter-forward-declarations
2816 parameter-type-list[opt] )
2818 parameter-forward-declarations:
2820 parameter-forward-declarations parameter-list ;
2822 The uses of attributes shown above are GNU extensions.
2824 Some forms of array declarator are not included in C99 in the
2825 syntax for abstract declarators; these are disallowed elsewhere.
2826 This may be a defect (DR#289).
2828 This function also accepts an omitted abstract declarator as being
2829 an abstract declarator, although not part of the formal syntax. */
2831 static struct c_declarator
*
2832 c_parser_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
2835 /* Parse any initial pointer part. */
2836 if (c_parser_next_token_is (parser
, CPP_MULT
))
2838 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
2839 struct c_declarator
*inner
;
2840 c_parser_consume_token (parser
);
2841 c_parser_declspecs (parser
, quals_attrs
, false, false, true, cla_prefer_id
);
2842 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
2846 return make_pointer_declarator (quals_attrs
, inner
);
2848 /* Now we have a direct declarator, direct abstract declarator or
2849 nothing (which counts as a direct abstract declarator here). */
2850 return c_parser_direct_declarator (parser
, type_seen_p
, kind
, seen_id
);
2853 /* Parse a direct declarator or direct abstract declarator; arguments
2854 as c_parser_declarator. */
2856 static struct c_declarator
*
2857 c_parser_direct_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
2860 /* The direct declarator must start with an identifier (possibly
2861 omitted) or a parenthesized declarator (possibly abstract). In
2862 an ordinary declarator, initial parentheses must start a
2863 parenthesized declarator. In an abstract declarator or parameter
2864 declarator, they could start a parenthesized declarator or a
2865 parameter list. To tell which, the open parenthesis and any
2866 following attributes must be read. If a declaration specifier
2867 follows, then it is a parameter list; if the specifier is a
2868 typedef name, there might be an ambiguity about redeclaring it,
2869 which is resolved in the direction of treating it as a typedef
2870 name. If a close parenthesis follows, it is also an empty
2871 parameter list, as the syntax does not permit empty abstract
2872 declarators. Otherwise, it is a parenthesized declarator (in
2873 which case the analysis may be repeated inside it, recursively).
2875 ??? There is an ambiguity in a parameter declaration "int
2876 (__attribute__((foo)) x)", where x is not a typedef name: it
2877 could be an abstract declarator for a function, or declare x with
2878 parentheses. The proper resolution of this ambiguity needs
2879 documenting. At present we follow an accident of the old
2880 parser's implementation, whereby the first parameter must have
2881 some declaration specifiers other than just attributes. Thus as
2882 a parameter declaration it is treated as a parenthesized
2883 parameter named x, and as an abstract declarator it is
2886 ??? Also following the old parser, attributes inside an empty
2887 parameter list are ignored, making it a list not yielding a
2888 prototype, rather than giving an error or making it have one
2889 parameter with implicit type int.
2891 ??? Also following the old parser, typedef names may be
2892 redeclared in declarators, but not Objective-C class names. */
2894 if (kind
!= C_DTR_ABSTRACT
2895 && c_parser_next_token_is (parser
, CPP_NAME
)
2897 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
2898 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
2899 || c_parser_peek_token (parser
)->id_kind
== C_ID_ID
))
2901 struct c_declarator
*inner
2902 = build_id_declarator (c_parser_peek_token (parser
)->value
);
2904 inner
->id_loc
= c_parser_peek_token (parser
)->location
;
2905 c_parser_consume_token (parser
);
2906 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
2909 if (kind
!= C_DTR_NORMAL
2910 && c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
2912 struct c_declarator
*inner
= build_id_declarator (NULL_TREE
);
2913 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
2916 /* Either we are at the end of an abstract declarator, or we have
2919 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
2922 struct c_declarator
*inner
;
2923 c_parser_consume_token (parser
);
2924 attrs
= c_parser_attributes (parser
);
2925 if (kind
!= C_DTR_NORMAL
2926 && (c_parser_next_token_starts_declspecs (parser
)
2927 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
)))
2929 struct c_arg_info
*args
2930 = c_parser_parms_declarator (parser
, kind
== C_DTR_NORMAL
,
2937 = build_function_declarator (args
,
2938 build_id_declarator (NULL_TREE
));
2939 return c_parser_direct_declarator_inner (parser
, *seen_id
,
2943 /* A parenthesized declarator. */
2944 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
2945 if (inner
!= NULL
&& attrs
!= NULL
)
2946 inner
= build_attrs_declarator (attrs
, inner
);
2947 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2949 c_parser_consume_token (parser
);
2953 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
2957 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2964 if (kind
== C_DTR_NORMAL
)
2966 c_parser_error (parser
, "expected identifier or %<(%>");
2970 return build_id_declarator (NULL_TREE
);
2974 /* Parse part of a direct declarator or direct abstract declarator,
2975 given that some (in INNER) has already been parsed; ID_PRESENT is
2976 true if an identifier is present, false for an abstract
2979 static struct c_declarator
*
2980 c_parser_direct_declarator_inner (c_parser
*parser
, bool id_present
,
2981 struct c_declarator
*inner
)
2983 /* Parse a sequence of array declarators and parameter lists. */
2984 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
2986 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
2987 struct c_declarator
*declarator
;
2988 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
2992 c_parser_consume_token (parser
);
2993 c_parser_declspecs (parser
, quals_attrs
, false, false, true, cla_prefer_id
);
2994 static_seen
= c_parser_next_token_is_keyword (parser
, RID_STATIC
);
2996 c_parser_consume_token (parser
);
2997 if (static_seen
&& !quals_attrs
->declspecs_seen_p
)
2998 c_parser_declspecs (parser
, quals_attrs
, false, false, true, cla_prefer_id
);
2999 if (!quals_attrs
->declspecs_seen_p
)
3001 /* If "static" is present, there must be an array dimension.
3002 Otherwise, there may be a dimension, "*", or no
3007 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
3011 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3016 else if (c_parser_next_token_is (parser
, CPP_MULT
))
3018 if (c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_SQUARE
)
3022 c_parser_consume_token (parser
);
3027 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
3033 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
3036 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3037 c_parser_consume_token (parser
);
3040 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3045 mark_exp_read (dimen
);
3046 declarator
= build_array_declarator (brace_loc
, dimen
, quals_attrs
,
3047 static_seen
, star_seen
);
3048 if (declarator
== NULL
)
3050 inner
= set_array_declarator_inner (declarator
, inner
);
3051 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3053 else if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3056 struct c_arg_info
*args
;
3057 c_parser_consume_token (parser
);
3058 attrs
= c_parser_attributes (parser
);
3059 args
= c_parser_parms_declarator (parser
, id_present
, attrs
);
3064 inner
= build_function_declarator (args
, inner
);
3065 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3071 /* Parse a parameter list or identifier list, including the closing
3072 parenthesis but not the opening one. ATTRS are the attributes at
3073 the start of the list. ID_LIST_OK is true if an identifier list is
3074 acceptable; such a list must not have attributes at the start. */
3076 static struct c_arg_info
*
3077 c_parser_parms_declarator (c_parser
*parser
, bool id_list_ok
, tree attrs
)
3080 declare_parm_level ();
3081 /* If the list starts with an identifier, it is an identifier list.
3082 Otherwise, it is either a prototype list or an empty list. */
3085 && c_parser_next_token_is (parser
, CPP_NAME
)
3086 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
3088 /* Look ahead to detect typos in type names. */
3089 && c_parser_peek_2nd_token (parser
)->type
!= CPP_NAME
3090 && c_parser_peek_2nd_token (parser
)->type
!= CPP_MULT
3091 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
3092 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_SQUARE
)
3094 tree list
= NULL_TREE
, *nextp
= &list
;
3095 while (c_parser_next_token_is (parser
, CPP_NAME
)
3096 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
3098 *nextp
= build_tree_list (NULL_TREE
,
3099 c_parser_peek_token (parser
)->value
);
3100 nextp
= & TREE_CHAIN (*nextp
);
3101 c_parser_consume_token (parser
);
3102 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
3104 c_parser_consume_token (parser
);
3105 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3107 c_parser_error (parser
, "expected identifier");
3111 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3113 struct c_arg_info
*ret
= build_arg_info ();
3115 c_parser_consume_token (parser
);
3121 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3129 struct c_arg_info
*ret
= c_parser_parms_list_declarator (parser
, attrs
,
3136 /* Parse a parameter list (possibly empty), including the closing
3137 parenthesis but not the opening one. ATTRS are the attributes at
3138 the start of the list. EXPR is NULL or an expression that needs to
3139 be evaluated for the side effects of array size expressions in the
3142 static struct c_arg_info
*
3143 c_parser_parms_list_declarator (c_parser
*parser
, tree attrs
, tree expr
)
3145 bool bad_parm
= false;
3147 /* ??? Following the old parser, forward parameter declarations may
3148 use abstract declarators, and if no real parameter declarations
3149 follow the forward declarations then this is not diagnosed. Also
3150 note as above that attributes are ignored as the only contents of
3151 the parentheses, or as the only contents after forward
3153 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3155 struct c_arg_info
*ret
= build_arg_info ();
3156 c_parser_consume_token (parser
);
3159 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3161 struct c_arg_info
*ret
= build_arg_info ();
3162 /* Suppress -Wold-style-definition for this case. */
3163 ret
->types
= error_mark_node
;
3164 error_at (c_parser_peek_token (parser
)->location
,
3165 "ISO C requires a named argument before %<...%>");
3166 c_parser_consume_token (parser
);
3167 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3169 c_parser_consume_token (parser
);
3174 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3179 /* Nonempty list of parameters, either terminated with semicolon
3180 (forward declarations; recurse) or with close parenthesis (normal
3181 function) or with ", ... )" (variadic function). */
3184 /* Parse a parameter. */
3185 struct c_parm
*parm
= c_parser_parameter_declaration (parser
, attrs
);
3190 push_parm_decl (parm
, &expr
);
3191 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3194 c_parser_consume_token (parser
);
3195 mark_forward_parm_decls ();
3196 new_attrs
= c_parser_attributes (parser
);
3197 return c_parser_parms_list_declarator (parser
, new_attrs
, expr
);
3199 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3201 c_parser_consume_token (parser
);
3205 return get_parm_info (false, expr
);
3207 if (!c_parser_require (parser
, CPP_COMMA
,
3208 "expected %<;%>, %<,%> or %<)%>"))
3210 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3213 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3215 c_parser_consume_token (parser
);
3216 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3218 c_parser_consume_token (parser
);
3222 return get_parm_info (true, expr
);
3226 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3234 /* Parse a parameter declaration. ATTRS are the attributes at the
3235 start of the declaration if it is the first parameter. */
3237 static struct c_parm
*
3238 c_parser_parameter_declaration (c_parser
*parser
, tree attrs
)
3240 struct c_declspecs
*specs
;
3241 struct c_declarator
*declarator
;
3243 tree postfix_attrs
= NULL_TREE
;
3245 if (!c_parser_next_token_starts_declspecs (parser
))
3247 c_token
*token
= c_parser_peek_token (parser
);
3250 c_parser_set_source_position_from_token (token
);
3251 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
3253 error ("unknown type name %qE", token
->value
);
3254 parser
->error
= true;
3256 /* ??? In some Objective-C cases '...' isn't applicable so there
3257 should be a different message. */
3259 c_parser_error (parser
,
3260 "expected declaration specifiers or %<...%>");
3261 c_parser_skip_to_end_of_parameter (parser
);
3264 specs
= build_null_declspecs ();
3267 declspecs_add_attrs (specs
, attrs
);
3270 c_parser_declspecs (parser
, specs
, true, true, true, cla_nonabstract_decl
);
3271 finish_declspecs (specs
);
3272 pending_xref_error ();
3273 prefix_attrs
= specs
->attrs
;
3274 specs
->attrs
= NULL_TREE
;
3275 declarator
= c_parser_declarator (parser
,
3276 specs
->typespec_kind
!= ctsk_none
,
3277 C_DTR_PARM
, &dummy
);
3278 if (declarator
== NULL
)
3280 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3283 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3284 postfix_attrs
= c_parser_attributes (parser
);
3285 return build_c_parm (specs
, chainon (postfix_attrs
, prefix_attrs
),
3289 /* Parse a string literal in an asm expression. It should not be
3290 translated, and wide string literals are an error although
3291 permitted by the syntax. This is a GNU extension.
3296 ??? At present, following the old parser, the caller needs to have
3297 set lex_untranslated_string to 1. It would be better to follow the
3298 C++ parser rather than using this kludge. */
3301 c_parser_asm_string_literal (c_parser
*parser
)
3304 int save_flag
= warn_overlength_strings
;
3305 warn_overlength_strings
= 0;
3306 if (c_parser_next_token_is (parser
, CPP_STRING
))
3308 str
= c_parser_peek_token (parser
)->value
;
3309 c_parser_consume_token (parser
);
3311 else if (c_parser_next_token_is (parser
, CPP_WSTRING
))
3313 error_at (c_parser_peek_token (parser
)->location
,
3314 "wide string literal in %<asm%>");
3315 str
= build_string (1, "");
3316 c_parser_consume_token (parser
);
3320 c_parser_error (parser
, "expected string literal");
3323 warn_overlength_strings
= save_flag
;
3327 /* Parse a simple asm expression. This is used in restricted
3328 contexts, where a full expression with inputs and outputs does not
3329 make sense. This is a GNU extension.
3332 asm ( asm-string-literal )
3336 c_parser_simple_asm_expr (c_parser
*parser
)
3339 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
3340 /* ??? Follow the C++ parser rather than using the
3341 lex_untranslated_string kludge. */
3342 parser
->lex_untranslated_string
= true;
3343 c_parser_consume_token (parser
);
3344 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3346 parser
->lex_untranslated_string
= false;
3349 str
= c_parser_asm_string_literal (parser
);
3350 parser
->lex_untranslated_string
= false;
3351 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
3353 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3359 /* Parse (possibly empty) attributes. This is a GNU extension.
3363 attributes attribute
3366 __attribute__ ( ( attribute-list ) )
3370 attribute_list , attrib
3375 any-word ( identifier )
3376 any-word ( identifier , nonempty-expr-list )
3377 any-word ( expr-list )
3379 where the "identifier" must not be declared as a type, and
3380 "any-word" may be any identifier (including one declared as a
3381 type), a reserved word storage class specifier, type specifier or
3382 type qualifier. ??? This still leaves out most reserved keywords
3383 (following the old parser), shouldn't we include them, and why not
3384 allow identifiers declared as types to start the arguments? */
3387 c_parser_attributes (c_parser
*parser
)
3389 tree attrs
= NULL_TREE
;
3390 while (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3392 /* ??? Follow the C++ parser rather than using the
3393 lex_untranslated_string kludge. */
3394 parser
->lex_untranslated_string
= true;
3395 c_parser_consume_token (parser
);
3396 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3398 parser
->lex_untranslated_string
= false;
3401 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3403 parser
->lex_untranslated_string
= false;
3404 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3407 /* Parse the attribute list. */
3408 while (c_parser_next_token_is (parser
, CPP_COMMA
)
3409 || c_parser_next_token_is (parser
, CPP_NAME
)
3410 || c_parser_next_token_is (parser
, CPP_KEYWORD
))
3412 tree attr
, attr_name
, attr_args
;
3413 VEC(tree
,gc
) *expr_list
;
3414 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3416 c_parser_consume_token (parser
);
3419 if (c_parser_next_token_is (parser
, CPP_KEYWORD
))
3421 /* ??? See comment above about what keywords are
3424 switch (c_parser_peek_token (parser
)->keyword
)
3463 /* Accept __attribute__((__const)) as __attribute__((const))
3466 = ridpointers
[(int) c_parser_peek_token (parser
)->keyword
];
3469 attr_name
= c_parser_peek_token (parser
)->value
;
3470 c_parser_consume_token (parser
);
3471 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
3473 attr
= build_tree_list (attr_name
, NULL_TREE
);
3474 attrs
= chainon (attrs
, attr
);
3477 c_parser_consume_token (parser
);
3478 /* Parse the attribute contents. If they start with an
3479 identifier which is followed by a comma or close
3480 parenthesis, then the arguments start with that
3481 identifier; otherwise they are an expression list.
3482 In objective-c the identifier may be a classname. */
3483 if (c_parser_next_token_is (parser
, CPP_NAME
)
3484 && (c_parser_peek_token (parser
)->id_kind
== C_ID_ID
3485 || (c_dialect_objc ()
3486 && c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
3487 && ((c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
)
3488 || (c_parser_peek_2nd_token (parser
)->type
3489 == CPP_CLOSE_PAREN
)))
3491 tree arg1
= c_parser_peek_token (parser
)->value
;
3492 c_parser_consume_token (parser
);
3493 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3494 attr_args
= build_tree_list (NULL_TREE
, arg1
);
3498 c_parser_consume_token (parser
);
3499 expr_list
= c_parser_expr_list (parser
, false, true, NULL
);
3500 tree_list
= build_tree_list_vec (expr_list
);
3501 attr_args
= tree_cons (NULL_TREE
, arg1
, tree_list
);
3502 release_tree_vector (expr_list
);
3507 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3508 attr_args
= NULL_TREE
;
3511 expr_list
= c_parser_expr_list (parser
, false, true, NULL
);
3512 attr_args
= build_tree_list_vec (expr_list
);
3513 release_tree_vector (expr_list
);
3516 attr
= build_tree_list (attr_name
, attr_args
);
3517 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3518 c_parser_consume_token (parser
);
3521 parser
->lex_untranslated_string
= false;
3522 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3526 attrs
= chainon (attrs
, attr
);
3528 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3529 c_parser_consume_token (parser
);
3532 parser
->lex_untranslated_string
= false;
3533 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3537 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3538 c_parser_consume_token (parser
);
3541 parser
->lex_untranslated_string
= false;
3542 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3546 parser
->lex_untranslated_string
= false;
3551 /* Parse a type name (C90 6.5.5, C99 6.7.6).
3554 specifier-qualifier-list abstract-declarator[opt]
3557 static struct c_type_name
*
3558 c_parser_type_name (c_parser
*parser
)
3560 struct c_declspecs
*specs
= build_null_declspecs ();
3561 struct c_declarator
*declarator
;
3562 struct c_type_name
*ret
;
3564 c_parser_declspecs (parser
, specs
, false, true, true, cla_prefer_type
);
3565 if (!specs
->declspecs_seen_p
)
3567 c_parser_error (parser
, "expected specifier-qualifier-list");
3570 if (specs
->type
!= error_mark_node
)
3572 pending_xref_error ();
3573 finish_declspecs (specs
);
3575 declarator
= c_parser_declarator (parser
,
3576 specs
->typespec_kind
!= ctsk_none
,
3577 C_DTR_ABSTRACT
, &dummy
);
3578 if (declarator
== NULL
)
3580 ret
= XOBNEW (&parser_obstack
, struct c_type_name
);
3582 ret
->declarator
= declarator
;
3586 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
3589 assignment-expression
3590 { initializer-list }
3591 { initializer-list , }
3594 designation[opt] initializer
3595 initializer-list , designation[opt] initializer
3602 designator-list designator
3609 [ constant-expression ]
3621 [ constant-expression ... constant-expression ]
3623 Any expression without commas is accepted in the syntax for the
3624 constant-expressions, with non-constant expressions rejected later.
3626 This function is only used for top-level initializers; for nested
3627 ones, see c_parser_initval. */
3629 static struct c_expr
3630 c_parser_initializer (c_parser
*parser
)
3632 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
3633 return c_parser_braced_init (parser
, NULL_TREE
, false);
3637 location_t loc
= c_parser_peek_token (parser
)->location
;
3638 ret
= c_parser_expr_no_commas (parser
, NULL
);
3639 if (TREE_CODE (ret
.value
) != STRING_CST
3640 && TREE_CODE (ret
.value
) != COMPOUND_LITERAL_EXPR
)
3641 ret
= default_function_array_read_conversion (loc
, ret
);
3646 /* Parse a braced initializer list. TYPE is the type specified for a
3647 compound literal, and NULL_TREE for other initializers and for
3648 nested braced lists. NESTED_P is true for nested braced lists,
3649 false for the list of a compound literal or the list that is the
3650 top-level initializer in a declaration. */
3652 static struct c_expr
3653 c_parser_braced_init (c_parser
*parser
, tree type
, bool nested_p
)
3656 struct obstack braced_init_obstack
;
3657 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
3658 gcc_obstack_init (&braced_init_obstack
);
3659 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
3660 c_parser_consume_token (parser
);
3662 push_init_level (0, &braced_init_obstack
);
3664 really_start_incremental_init (type
);
3665 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3667 pedwarn (brace_loc
, OPT_pedantic
, "ISO C forbids empty initializer braces");
3671 /* Parse a non-empty initializer list, possibly with a trailing
3675 c_parser_initelt (parser
, &braced_init_obstack
);
3678 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3679 c_parser_consume_token (parser
);
3682 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3686 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
3688 ret
.value
= error_mark_node
;
3689 ret
.original_code
= ERROR_MARK
;
3690 ret
.original_type
= NULL
;
3691 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
3692 pop_init_level (0, &braced_init_obstack
);
3693 obstack_free (&braced_init_obstack
, NULL
);
3696 c_parser_consume_token (parser
);
3697 ret
= pop_init_level (0, &braced_init_obstack
);
3698 obstack_free (&braced_init_obstack
, NULL
);
3702 /* Parse a nested initializer, including designators. */
3705 c_parser_initelt (c_parser
*parser
, struct obstack
* braced_init_obstack
)
3707 /* Parse any designator or designator list. A single array
3708 designator may have the subsequent "=" omitted in GNU C, but a
3709 longer list or a structure member designator may not. */
3710 if (c_parser_next_token_is (parser
, CPP_NAME
)
3711 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
3713 /* Old-style structure member designator. */
3714 set_init_label (c_parser_peek_token (parser
)->value
,
3715 braced_init_obstack
);
3716 /* Use the colon as the error location. */
3717 pedwarn (c_parser_peek_2nd_token (parser
)->location
, OPT_pedantic
,
3718 "obsolete use of designated initializer with %<:%>");
3719 c_parser_consume_token (parser
);
3720 c_parser_consume_token (parser
);
3724 /* des_seen is 0 if there have been no designators, 1 if there
3725 has been a single array designator and 2 otherwise. */
3727 /* Location of a designator. */
3728 location_t des_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
3729 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
)
3730 || c_parser_next_token_is (parser
, CPP_DOT
))
3732 int des_prev
= des_seen
;
3734 des_loc
= c_parser_peek_token (parser
)->location
;
3737 if (c_parser_next_token_is (parser
, CPP_DOT
))
3740 c_parser_consume_token (parser
);
3741 if (c_parser_next_token_is (parser
, CPP_NAME
))
3743 set_init_label (c_parser_peek_token (parser
)->value
,
3744 braced_init_obstack
);
3745 c_parser_consume_token (parser
);
3750 init
.value
= error_mark_node
;
3751 init
.original_code
= ERROR_MARK
;
3752 init
.original_type
= NULL
;
3753 c_parser_error (parser
, "expected identifier");
3754 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3755 process_init_element (init
, false, braced_init_obstack
);
3762 location_t ellipsis_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
3763 /* ??? Following the old parser, [ objc-receiver
3764 objc-message-args ] is accepted as an initializer,
3765 being distinguished from a designator by what follows
3766 the first assignment expression inside the square
3767 brackets, but after a first array designator a
3768 subsequent square bracket is for Objective-C taken to
3769 start an expression, using the obsolete form of
3770 designated initializer without '=', rather than
3771 possibly being a second level of designation: in LALR
3772 terms, the '[' is shifted rather than reducing
3773 designator to designator-list. */
3774 if (des_prev
== 1 && c_dialect_objc ())
3776 des_seen
= des_prev
;
3779 if (des_prev
== 0 && c_dialect_objc ())
3781 /* This might be an array designator or an
3782 Objective-C message expression. If the former,
3783 continue parsing here; if the latter, parse the
3784 remainder of the initializer given the starting
3785 primary-expression. ??? It might make sense to
3786 distinguish when des_prev == 1 as well; see
3787 previous comment. */
3789 struct c_expr mexpr
;
3790 c_parser_consume_token (parser
);
3791 if (c_parser_peek_token (parser
)->type
== CPP_NAME
3792 && ((c_parser_peek_token (parser
)->id_kind
3794 || (c_parser_peek_token (parser
)->id_kind
3795 == C_ID_CLASSNAME
)))
3797 /* Type name receiver. */
3798 tree id
= c_parser_peek_token (parser
)->value
;
3799 c_parser_consume_token (parser
);
3800 rec
= objc_get_class_reference (id
);
3801 goto parse_message_args
;
3803 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
3804 mark_exp_read (first
);
3805 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
)
3806 || c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3807 goto array_desig_after_first
;
3808 /* Expression receiver. So far only one part
3809 without commas has been parsed; there might be
3810 more of the expression. */
3812 while (c_parser_next_token_is (parser
, CPP_COMMA
))
3815 location_t comma_loc
, exp_loc
;
3816 comma_loc
= c_parser_peek_token (parser
)->location
;
3817 c_parser_consume_token (parser
);
3818 exp_loc
= c_parser_peek_token (parser
)->location
;
3819 next
= c_parser_expr_no_commas (parser
, NULL
);
3820 next
= default_function_array_read_conversion (exp_loc
,
3822 rec
= build_compound_expr (comma_loc
, rec
, next
.value
);
3825 /* Now parse the objc-message-args. */
3826 args
= c_parser_objc_message_args (parser
);
3827 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3830 = objc_build_message_expr (rec
, args
);
3831 mexpr
.original_code
= ERROR_MARK
;
3832 mexpr
.original_type
= NULL
;
3833 /* Now parse and process the remainder of the
3834 initializer, starting with this message
3835 expression as a primary-expression. */
3836 c_parser_initval (parser
, &mexpr
, braced_init_obstack
);
3839 c_parser_consume_token (parser
);
3840 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
3841 mark_exp_read (first
);
3842 array_desig_after_first
:
3843 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3845 ellipsis_loc
= c_parser_peek_token (parser
)->location
;
3846 c_parser_consume_token (parser
);
3847 second
= c_parser_expr_no_commas (parser
, NULL
).value
;
3848 mark_exp_read (second
);
3852 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3854 c_parser_consume_token (parser
);
3855 set_init_index (first
, second
, braced_init_obstack
);
3857 pedwarn (ellipsis_loc
, OPT_pedantic
,
3858 "ISO C forbids specifying range of elements to initialize");
3861 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3867 if (c_parser_next_token_is (parser
, CPP_EQ
))
3870 pedwarn (des_loc
, OPT_pedantic
,
3871 "ISO C90 forbids specifying subobject to initialize");
3872 c_parser_consume_token (parser
);
3877 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
3878 "obsolete use of designated initializer without %<=%>");
3882 init
.value
= error_mark_node
;
3883 init
.original_code
= ERROR_MARK
;
3884 init
.original_type
= NULL
;
3885 c_parser_error (parser
, "expected %<=%>");
3886 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3887 process_init_element (init
, false, braced_init_obstack
);
3893 c_parser_initval (parser
, NULL
, braced_init_obstack
);
3896 /* Parse a nested initializer; as c_parser_initializer but parses
3897 initializers within braced lists, after any designators have been
3898 applied. If AFTER is not NULL then it is an Objective-C message
3899 expression which is the primary-expression starting the
3903 c_parser_initval (c_parser
*parser
, struct c_expr
*after
,
3904 struct obstack
* braced_init_obstack
)
3907 gcc_assert (!after
|| c_dialect_objc ());
3908 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
) && !after
)
3909 init
= c_parser_braced_init (parser
, NULL_TREE
, true);
3912 location_t loc
= c_parser_peek_token (parser
)->location
;
3913 init
= c_parser_expr_no_commas (parser
, after
);
3914 if (init
.value
!= NULL_TREE
3915 && TREE_CODE (init
.value
) != STRING_CST
3916 && TREE_CODE (init
.value
) != COMPOUND_LITERAL_EXPR
)
3917 init
= default_function_array_read_conversion (loc
, init
);
3919 process_init_element (init
, false, braced_init_obstack
);
3922 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
3926 { block-item-list[opt] }
3927 { label-declarations block-item-list }
3931 block-item-list block-item
3943 { label-declarations block-item-list }
3946 __extension__ nested-declaration
3947 nested-function-definition
3951 label-declarations label-declaration
3954 __label__ identifier-list ;
3956 Allowing the mixing of declarations and code is new in C99. The
3957 GNU syntax also permits (not shown above) labels at the end of
3958 compound statements, which yield an error. We don't allow labels
3959 on declarations; this might seem like a natural extension, but
3960 there would be a conflict between attributes on the label and
3961 prefix attributes on the declaration. ??? The syntax follows the
3962 old parser in requiring something after label declarations.
3963 Although they are erroneous if the labels declared aren't defined,
3964 is it useful for the syntax to be this way?
3976 c_parser_compound_statement (c_parser
*parser
)
3979 location_t brace_loc
;
3980 brace_loc
= c_parser_peek_token (parser
)->location
;
3981 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
3983 /* Ensure a scope is entered and left anyway to avoid confusion
3984 if we have just prepared to enter a function body. */
3985 stmt
= c_begin_compound_stmt (true);
3986 c_end_compound_stmt (brace_loc
, stmt
, true);
3987 return error_mark_node
;
3989 stmt
= c_begin_compound_stmt (true);
3990 c_parser_compound_statement_nostart (parser
);
3991 return c_end_compound_stmt (brace_loc
, stmt
, true);
3994 /* Parse a compound statement except for the opening brace. This is
3995 used for parsing both compound statements and statement expressions
3996 (which follow different paths to handling the opening). */
3999 c_parser_compound_statement_nostart (c_parser
*parser
)
4001 bool last_stmt
= false;
4002 bool last_label
= false;
4003 bool save_valid_for_pragma
= valid_location_for_stdc_pragma_p ();
4004 location_t label_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4005 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4007 c_parser_consume_token (parser
);
4010 mark_valid_location_for_stdc_pragma (true);
4011 if (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
4013 /* Read zero or more forward-declarations for labels that nested
4014 functions can jump to. */
4015 mark_valid_location_for_stdc_pragma (false);
4016 while (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
4018 label_loc
= c_parser_peek_token (parser
)->location
;
4019 c_parser_consume_token (parser
);
4020 /* Any identifiers, including those declared as type names,
4025 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
4027 c_parser_error (parser
, "expected identifier");
4031 = declare_label (c_parser_peek_token (parser
)->value
);
4032 C_DECLARED_LABEL_FLAG (label
) = 1;
4033 add_stmt (build_stmt (label_loc
, DECL_EXPR
, label
));
4034 c_parser_consume_token (parser
);
4035 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4036 c_parser_consume_token (parser
);
4040 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4042 pedwarn (label_loc
, OPT_pedantic
, "ISO C forbids label declarations");
4044 /* We must now have at least one statement, label or declaration. */
4045 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4047 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4048 c_parser_error (parser
, "expected declaration or statement");
4049 c_parser_consume_token (parser
);
4052 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
4054 location_t loc
= c_parser_peek_token (parser
)->location
;
4055 if (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4056 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4057 || (c_parser_next_token_is (parser
, CPP_NAME
)
4058 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4060 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
4061 label_loc
= c_parser_peek_2nd_token (parser
)->location
;
4063 label_loc
= c_parser_peek_token (parser
)->location
;
4066 mark_valid_location_for_stdc_pragma (false);
4067 c_parser_label (parser
);
4069 else if (!last_label
4070 && c_parser_next_tokens_start_declaration (parser
))
4073 mark_valid_location_for_stdc_pragma (false);
4074 c_parser_declaration_or_fndef (parser
, true, true, true, true, true, NULL
);
4077 (pedantic
&& !flag_isoc99
)
4079 : OPT_Wdeclaration_after_statement
,
4080 "ISO C90 forbids mixed declarations and code");
4083 else if (!last_label
4084 && c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
4086 /* __extension__ can start a declaration, but is also an
4087 unary operator that can start an expression. Consume all
4088 but the last of a possible series of __extension__ to
4090 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
4091 && (c_parser_peek_2nd_token (parser
)->keyword
4093 c_parser_consume_token (parser
);
4094 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
4097 ext
= disable_extension_diagnostics ();
4098 c_parser_consume_token (parser
);
4100 mark_valid_location_for_stdc_pragma (false);
4101 c_parser_declaration_or_fndef (parser
, true, true, true, true,
4103 /* Following the old parser, __extension__ does not
4104 disable this diagnostic. */
4105 restore_extension_diagnostics (ext
);
4107 pedwarn_c90 (loc
, (pedantic
&& !flag_isoc99
)
4109 : OPT_Wdeclaration_after_statement
,
4110 "ISO C90 forbids mixed declarations and code");
4116 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
4118 /* External pragmas, and some omp pragmas, are not associated
4119 with regular c code, and so are not to be considered statements
4120 syntactically. This ensures that the user doesn't put them
4121 places that would turn into syntax errors if the directive
4123 if (c_parser_pragma (parser
, pragma_compound
))
4124 last_label
= false, last_stmt
= true;
4126 else if (c_parser_next_token_is (parser
, CPP_EOF
))
4128 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4129 c_parser_error (parser
, "expected declaration or statement");
4132 else if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
4134 if (parser
->in_if_block
)
4136 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4137 error_at (loc
, """expected %<}%> before %<else%>");
4142 error_at (loc
, "%<else%> without a previous %<if%>");
4143 c_parser_consume_token (parser
);
4152 mark_valid_location_for_stdc_pragma (false);
4153 c_parser_statement_after_labels (parser
);
4156 parser
->error
= false;
4159 error_at (label_loc
, "label at end of compound statement");
4160 c_parser_consume_token (parser
);
4161 /* Restore the value we started with. */
4162 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4165 /* Parse a label (C90 6.6.1, C99 6.8.1).
4168 identifier : attributes[opt]
4169 case constant-expression :
4175 case constant-expression ... constant-expression :
4177 The use of attributes on labels is a GNU extension. The syntax in
4178 GNU C accepts any expressions without commas, non-constant
4179 expressions being rejected later. */
4182 c_parser_label (c_parser
*parser
)
4184 location_t loc1
= c_parser_peek_token (parser
)->location
;
4185 tree label
= NULL_TREE
;
4186 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
4189 c_parser_consume_token (parser
);
4190 exp1
= c_parser_expr_no_commas (parser
, NULL
).value
;
4191 if (c_parser_next_token_is (parser
, CPP_COLON
))
4193 c_parser_consume_token (parser
);
4194 label
= do_case (loc1
, exp1
, NULL_TREE
);
4196 else if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
4198 c_parser_consume_token (parser
);
4199 exp2
= c_parser_expr_no_commas (parser
, NULL
).value
;
4200 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4201 label
= do_case (loc1
, exp1
, exp2
);
4204 c_parser_error (parser
, "expected %<:%> or %<...%>");
4206 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
4208 c_parser_consume_token (parser
);
4209 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4210 label
= do_case (loc1
, NULL_TREE
, NULL_TREE
);
4214 tree name
= c_parser_peek_token (parser
)->value
;
4217 location_t loc2
= c_parser_peek_token (parser
)->location
;
4218 gcc_assert (c_parser_next_token_is (parser
, CPP_NAME
));
4219 c_parser_consume_token (parser
);
4220 gcc_assert (c_parser_next_token_is (parser
, CPP_COLON
));
4221 c_parser_consume_token (parser
);
4222 attrs
= c_parser_attributes (parser
);
4223 tlab
= define_label (loc2
, name
);
4226 decl_attributes (&tlab
, attrs
, 0);
4227 label
= add_stmt (build_stmt (loc1
, LABEL_EXPR
, tlab
));
4232 if (c_parser_next_tokens_start_declaration (parser
))
4234 error_at (c_parser_peek_token (parser
)->location
,
4235 "a label can only be part of a statement and "
4236 "a declaration is not a statement");
4237 c_parser_declaration_or_fndef (parser
, /*fndef_ok*/ false,
4238 /*static_assert_ok*/ true,
4239 /*nested*/ true, /*empty_ok*/ false,
4240 /*start_attr_ok*/ true, NULL
);
4245 /* Parse a statement (C90 6.6, C99 6.8).
4250 expression-statement
4258 expression-statement:
4261 selection-statement:
4265 iteration-statement:
4274 return expression[opt] ;
4287 objc-throw-statement
4288 objc-try-catch-statement
4289 objc-synchronized-statement
4291 objc-throw-statement:
4305 parallel-for-construct
4306 parallel-sections-construct
4313 parallel-directive structured-block
4316 for-directive iteration-statement
4319 sections-directive section-scope
4322 single-directive structured-block
4324 parallel-for-construct:
4325 parallel-for-directive iteration-statement
4327 parallel-sections-construct:
4328 parallel-sections-directive section-scope
4331 master-directive structured-block
4334 critical-directive structured-block
4337 atomic-directive expression-statement
4340 ordered-directive structured-block */
4343 c_parser_statement (c_parser
*parser
)
4345 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4346 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4347 || (c_parser_next_token_is (parser
, CPP_NAME
)
4348 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4349 c_parser_label (parser
);
4350 c_parser_statement_after_labels (parser
);
4353 /* Parse a statement, other than a labeled statement. */
4356 c_parser_statement_after_labels (c_parser
*parser
)
4358 location_t loc
= c_parser_peek_token (parser
)->location
;
4359 tree stmt
= NULL_TREE
;
4360 bool in_if_block
= parser
->in_if_block
;
4361 parser
->in_if_block
= false;
4362 switch (c_parser_peek_token (parser
)->type
)
4364 case CPP_OPEN_BRACE
:
4365 add_stmt (c_parser_compound_statement (parser
));
4368 switch (c_parser_peek_token (parser
)->keyword
)
4371 c_parser_if_statement (parser
);
4374 c_parser_switch_statement (parser
);
4377 c_parser_while_statement (parser
);
4380 c_parser_do_statement (parser
);
4383 c_parser_for_statement (parser
);
4386 c_parser_consume_token (parser
);
4387 if (c_parser_next_token_is (parser
, CPP_NAME
))
4389 stmt
= c_finish_goto_label (loc
,
4390 c_parser_peek_token (parser
)->value
);
4391 c_parser_consume_token (parser
);
4393 else if (c_parser_next_token_is (parser
, CPP_MULT
))
4397 c_parser_consume_token (parser
);
4398 val
= c_parser_expression (parser
).value
;
4399 mark_exp_read (val
);
4400 stmt
= c_finish_goto_ptr (loc
, val
);
4403 c_parser_error (parser
, "expected identifier or %<*%>");
4404 goto expect_semicolon
;
4406 c_parser_consume_token (parser
);
4407 stmt
= c_finish_bc_stmt (loc
, &c_cont_label
, false);
4408 goto expect_semicolon
;
4410 c_parser_consume_token (parser
);
4411 stmt
= c_finish_bc_stmt (loc
, &c_break_label
, true);
4412 goto expect_semicolon
;
4414 c_parser_consume_token (parser
);
4415 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4417 stmt
= c_finish_return (loc
, NULL_TREE
, NULL_TREE
);
4418 c_parser_consume_token (parser
);
4422 struct c_expr expr
= c_parser_expression_conv (parser
);
4423 mark_exp_read (expr
.value
);
4424 stmt
= c_finish_return (loc
, expr
.value
, expr
.original_type
);
4425 goto expect_semicolon
;
4429 stmt
= c_parser_asm_statement (parser
);
4432 gcc_assert (c_dialect_objc ());
4433 c_parser_consume_token (parser
);
4434 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4436 stmt
= objc_build_throw_stmt (loc
, NULL_TREE
);
4437 c_parser_consume_token (parser
);
4441 tree expr
= c_parser_expression (parser
).value
;
4442 expr
= c_fully_fold (expr
, false, NULL
);
4443 stmt
= objc_build_throw_stmt (loc
, expr
);
4444 goto expect_semicolon
;
4448 gcc_assert (c_dialect_objc ());
4449 c_parser_objc_try_catch_finally_statement (parser
);
4451 case RID_AT_SYNCHRONIZED
:
4452 gcc_assert (c_dialect_objc ());
4453 c_parser_objc_synchronized_statement (parser
);
4460 c_parser_consume_token (parser
);
4462 case CPP_CLOSE_PAREN
:
4463 case CPP_CLOSE_SQUARE
:
4464 /* Avoid infinite loop in error recovery:
4465 c_parser_skip_until_found stops at a closing nesting
4466 delimiter without consuming it, but here we need to consume
4467 it to proceed further. */
4468 c_parser_error (parser
, "expected statement");
4469 c_parser_consume_token (parser
);
4472 c_parser_pragma (parser
, pragma_stmt
);
4476 stmt
= c_finish_expr_stmt (loc
, c_parser_expression_conv (parser
).value
);
4478 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4481 /* Two cases cannot and do not have line numbers associated: If stmt
4482 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
4483 cannot hold line numbers. But that's OK because the statement
4484 will either be changed to a MODIFY_EXPR during gimplification of
4485 the statement expr, or discarded. If stmt was compound, but
4486 without new variables, we will have skipped the creation of a
4487 BIND and will have a bare STATEMENT_LIST. But that's OK because
4488 (recursively) all of the component statements should already have
4489 line numbers assigned. ??? Can we discard no-op statements
4491 if (CAN_HAVE_LOCATION_P (stmt
)
4492 && EXPR_LOCATION (stmt
) == UNKNOWN_LOCATION
)
4493 SET_EXPR_LOCATION (stmt
, loc
);
4495 parser
->in_if_block
= in_if_block
;
4498 /* Parse the condition from an if, do, while or for statements. */
4501 c_parser_condition (c_parser
*parser
)
4503 location_t loc
= c_parser_peek_token (parser
)->location
;
4505 cond
= c_parser_expression_conv (parser
).value
;
4506 cond
= c_objc_common_truthvalue_conversion (loc
, cond
);
4507 cond
= c_fully_fold (cond
, false, NULL
);
4508 if (warn_sequence_point
)
4509 verify_sequence_points (cond
);
4513 /* Parse a parenthesized condition from an if, do or while statement.
4519 c_parser_paren_condition (c_parser
*parser
)
4522 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4523 return error_mark_node
;
4524 cond
= c_parser_condition (parser
);
4525 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4529 /* Parse a statement which is a block in C99. */
4532 c_parser_c99_block_statement (c_parser
*parser
)
4534 tree block
= c_begin_compound_stmt (flag_isoc99
);
4535 location_t loc
= c_parser_peek_token (parser
)->location
;
4536 c_parser_statement (parser
);
4537 return c_end_compound_stmt (loc
, block
, flag_isoc99
);
4540 /* Parse the body of an if statement. This is just parsing a
4541 statement but (a) it is a block in C99, (b) we track whether the
4542 body is an if statement for the sake of -Wparentheses warnings, (c)
4543 we handle an empty body specially for the sake of -Wempty-body
4544 warnings, and (d) we call parser_compound_statement directly
4545 because c_parser_statement_after_labels resets
4546 parser->in_if_block. */
4549 c_parser_if_body (c_parser
*parser
, bool *if_p
)
4551 tree block
= c_begin_compound_stmt (flag_isoc99
);
4552 location_t body_loc
= c_parser_peek_token (parser
)->location
;
4553 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4554 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4555 || (c_parser_next_token_is (parser
, CPP_NAME
)
4556 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4557 c_parser_label (parser
);
4558 *if_p
= c_parser_next_token_is_keyword (parser
, RID_IF
);
4559 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4561 location_t loc
= c_parser_peek_token (parser
)->location
;
4562 add_stmt (build_empty_stmt (loc
));
4563 c_parser_consume_token (parser
);
4564 if (!c_parser_next_token_is_keyword (parser
, RID_ELSE
))
4565 warning_at (loc
, OPT_Wempty_body
,
4566 "suggest braces around empty body in an %<if%> statement");
4568 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4569 add_stmt (c_parser_compound_statement (parser
));
4571 c_parser_statement_after_labels (parser
);
4572 return c_end_compound_stmt (body_loc
, block
, flag_isoc99
);
4575 /* Parse the else body of an if statement. This is just parsing a
4576 statement but (a) it is a block in C99, (b) we handle an empty body
4577 specially for the sake of -Wempty-body warnings. */
4580 c_parser_else_body (c_parser
*parser
)
4582 location_t else_loc
= c_parser_peek_token (parser
)->location
;
4583 tree block
= c_begin_compound_stmt (flag_isoc99
);
4584 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4585 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4586 || (c_parser_next_token_is (parser
, CPP_NAME
)
4587 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4588 c_parser_label (parser
);
4589 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4591 location_t loc
= c_parser_peek_token (parser
)->location
;
4594 "suggest braces around empty body in an %<else%> statement");
4595 add_stmt (build_empty_stmt (loc
));
4596 c_parser_consume_token (parser
);
4599 c_parser_statement_after_labels (parser
);
4600 return c_end_compound_stmt (else_loc
, block
, flag_isoc99
);
4603 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
4606 if ( expression ) statement
4607 if ( expression ) statement else statement
4611 c_parser_if_statement (c_parser
*parser
)
4616 bool first_if
= false;
4617 tree first_body
, second_body
;
4620 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_IF
));
4621 c_parser_consume_token (parser
);
4622 block
= c_begin_compound_stmt (flag_isoc99
);
4623 loc
= c_parser_peek_token (parser
)->location
;
4624 cond
= c_parser_paren_condition (parser
);
4625 in_if_block
= parser
->in_if_block
;
4626 parser
->in_if_block
= true;
4627 first_body
= c_parser_if_body (parser
, &first_if
);
4628 parser
->in_if_block
= in_if_block
;
4629 if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
4631 c_parser_consume_token (parser
);
4632 second_body
= c_parser_else_body (parser
);
4635 second_body
= NULL_TREE
;
4636 c_finish_if_stmt (loc
, cond
, first_body
, second_body
, first_if
);
4637 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
4640 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
4643 switch (expression) statement
4647 c_parser_switch_statement (c_parser
*parser
)
4649 tree block
, expr
, body
, save_break
;
4650 location_t switch_loc
= c_parser_peek_token (parser
)->location
;
4651 location_t switch_cond_loc
;
4652 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SWITCH
));
4653 c_parser_consume_token (parser
);
4654 block
= c_begin_compound_stmt (flag_isoc99
);
4655 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4657 switch_cond_loc
= c_parser_peek_token (parser
)->location
;
4658 expr
= c_parser_expression (parser
).value
;
4659 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4663 switch_cond_loc
= UNKNOWN_LOCATION
;
4664 expr
= error_mark_node
;
4666 c_start_case (switch_loc
, switch_cond_loc
, expr
);
4667 save_break
= c_break_label
;
4668 c_break_label
= NULL_TREE
;
4669 body
= c_parser_c99_block_statement (parser
);
4670 c_finish_case (body
);
4673 location_t here
= c_parser_peek_token (parser
)->location
;
4674 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_break_label
);
4675 SET_EXPR_LOCATION (t
, here
);
4678 c_break_label
= save_break
;
4679 add_stmt (c_end_compound_stmt (switch_loc
, block
, flag_isoc99
));
4682 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
4685 while (expression) statement
4689 c_parser_while_statement (c_parser
*parser
)
4691 tree block
, cond
, body
, save_break
, save_cont
;
4693 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_WHILE
));
4694 c_parser_consume_token (parser
);
4695 block
= c_begin_compound_stmt (flag_isoc99
);
4696 loc
= c_parser_peek_token (parser
)->location
;
4697 cond
= c_parser_paren_condition (parser
);
4698 save_break
= c_break_label
;
4699 c_break_label
= NULL_TREE
;
4700 save_cont
= c_cont_label
;
4701 c_cont_label
= NULL_TREE
;
4702 body
= c_parser_c99_block_statement (parser
);
4703 c_finish_loop (loc
, cond
, NULL
, body
, c_break_label
, c_cont_label
, true);
4704 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
4705 c_break_label
= save_break
;
4706 c_cont_label
= save_cont
;
4709 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
4712 do statement while ( expression ) ;
4716 c_parser_do_statement (c_parser
*parser
)
4718 tree block
, cond
, body
, save_break
, save_cont
, new_break
, new_cont
;
4720 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_DO
));
4721 c_parser_consume_token (parser
);
4722 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4723 warning_at (c_parser_peek_token (parser
)->location
,
4725 "suggest braces around empty body in %<do%> statement");
4726 block
= c_begin_compound_stmt (flag_isoc99
);
4727 loc
= c_parser_peek_token (parser
)->location
;
4728 save_break
= c_break_label
;
4729 c_break_label
= NULL_TREE
;
4730 save_cont
= c_cont_label
;
4731 c_cont_label
= NULL_TREE
;
4732 body
= c_parser_c99_block_statement (parser
);
4733 c_parser_require_keyword (parser
, RID_WHILE
, "expected %<while%>");
4734 new_break
= c_break_label
;
4735 c_break_label
= save_break
;
4736 new_cont
= c_cont_label
;
4737 c_cont_label
= save_cont
;
4738 cond
= c_parser_paren_condition (parser
);
4739 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
4740 c_parser_skip_to_end_of_block_or_statement (parser
);
4741 c_finish_loop (loc
, cond
, NULL
, body
, new_break
, new_cont
, false);
4742 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
4745 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
4748 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
4749 for ( nested-declaration expression[opt] ; expression[opt] ) statement
4751 The form with a declaration is new in C99.
4753 ??? In accordance with the old parser, the declaration may be a
4754 nested function, which is then rejected in check_for_loop_decls,
4755 but does it make any sense for this to be included in the grammar?
4756 Note in particular that the nested function does not include a
4757 trailing ';', whereas the "declaration" production includes one.
4758 Also, can we reject bad declarations earlier and cheaper than
4759 check_for_loop_decls?
4761 In Objective-C, there are two additional variants:
4764 for ( expression in expresssion ) statement
4765 for ( declaration in expression ) statement
4767 This is inconsistent with C, because the second variant is allowed
4768 even if c99 is not enabled.
4770 The rest of the comment documents these Objective-C foreach-statement.
4772 Here is the canonical example of the first variant:
4773 for (object in array) { do something with object }
4774 we call the first expression ("object") the "object_expression" and
4775 the second expression ("array") the "collection_expression".
4776 object_expression must be an lvalue of type "id" (a generic Objective-C
4777 object) because the loop works by assigning to object_expression the
4778 various objects from the collection_expression. collection_expression
4779 must evaluate to something of type "id" which responds to the method
4780 countByEnumeratingWithState:objects:count:.
4782 The canonical example of the second variant is:
4783 for (id object in array) { do something with object }
4784 which is completely equivalent to
4787 for (object in array) { do something with object }
4789 Note that initizializing 'object' in some way (eg, "for ((object =
4790 xxx) in array) { do something with object }") is possibly
4791 technically valid, but completely pointless as 'object' will be
4792 assigned to something else as soon as the loop starts. We should
4793 most likely reject it (TODO).
4795 The beginning of the Objective-C foreach-statement looks exactly
4796 like the beginning of the for-statement, and we can tell it is a
4797 foreach-statement only because the initial declaration or
4798 expression is terminated by 'in' instead of ';'.
4802 c_parser_for_statement (c_parser
*parser
)
4804 tree block
, cond
, incr
, save_break
, save_cont
, body
;
4805 /* The following are only used when parsing an ObjC foreach statement. */
4806 tree object_expression
;
4807 /* Silence the bogus uninitialized warning. */
4808 tree collection_expression
= NULL
;
4809 location_t loc
= c_parser_peek_token (parser
)->location
;
4810 location_t for_loc
= c_parser_peek_token (parser
)->location
;
4811 bool is_foreach_statement
= false;
4812 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_FOR
));
4813 c_parser_consume_token (parser
);
4814 /* Open a compound statement in Objective-C as well, just in case this is
4815 as foreach expression. */
4816 block
= c_begin_compound_stmt (flag_isoc99
|| c_dialect_objc ());
4817 cond
= error_mark_node
;
4818 incr
= error_mark_node
;
4819 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4821 /* Parse the initialization declaration or expression. */
4822 object_expression
= error_mark_node
;
4823 parser
->objc_could_be_foreach_context
= c_dialect_objc ();
4824 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4826 parser
->objc_could_be_foreach_context
= false;
4827 c_parser_consume_token (parser
);
4828 c_finish_expr_stmt (loc
, NULL_TREE
);
4830 else if (c_parser_next_tokens_start_declaration (parser
))
4832 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
4833 &object_expression
);
4834 parser
->objc_could_be_foreach_context
= false;
4836 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
4838 c_parser_consume_token (parser
);
4839 is_foreach_statement
= true;
4840 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
4841 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
4844 check_for_loop_decls (for_loc
, flag_isoc99
);
4846 else if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
4848 /* __extension__ can start a declaration, but is also an
4849 unary operator that can start an expression. Consume all
4850 but the last of a possible series of __extension__ to
4852 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
4853 && (c_parser_peek_2nd_token (parser
)->keyword
4855 c_parser_consume_token (parser
);
4856 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
4859 ext
= disable_extension_diagnostics ();
4860 c_parser_consume_token (parser
);
4861 c_parser_declaration_or_fndef (parser
, true, true, true, true,
4862 true, &object_expression
);
4863 parser
->objc_could_be_foreach_context
= false;
4865 restore_extension_diagnostics (ext
);
4866 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
4868 c_parser_consume_token (parser
);
4869 is_foreach_statement
= true;
4870 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
4871 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
4874 check_for_loop_decls (for_loc
, flag_isoc99
);
4883 tree init_expression
;
4884 init_expression
= c_parser_expression (parser
).value
;
4885 parser
->objc_could_be_foreach_context
= false;
4886 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
4888 c_parser_consume_token (parser
);
4889 is_foreach_statement
= true;
4890 if (! lvalue_p (init_expression
))
4891 c_parser_error (parser
, "invalid iterating variable in fast enumeration");
4892 object_expression
= c_fully_fold (init_expression
, false, NULL
);
4896 c_finish_expr_stmt (loc
, init_expression
);
4897 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4901 /* Parse the loop condition. In the case of a foreach
4902 statement, there is no loop condition. */
4903 gcc_assert (!parser
->objc_could_be_foreach_context
);
4904 if (!is_foreach_statement
)
4906 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4908 c_parser_consume_token (parser
);
4913 cond
= c_parser_condition (parser
);
4914 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4917 /* Parse the increment expression (the third expression in a
4918 for-statement). In the case of a foreach-statement, this is
4919 the expression that follows the 'in'. */
4920 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4922 if (is_foreach_statement
)
4924 c_parser_error (parser
, "missing collection in fast enumeration");
4925 collection_expression
= error_mark_node
;
4928 incr
= c_process_expr_stmt (loc
, NULL_TREE
);
4932 if (is_foreach_statement
)
4933 collection_expression
= c_fully_fold (c_parser_expression (parser
).value
,
4936 incr
= c_process_expr_stmt (loc
, c_parser_expression (parser
).value
);
4938 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4940 save_break
= c_break_label
;
4941 c_break_label
= NULL_TREE
;
4942 save_cont
= c_cont_label
;
4943 c_cont_label
= NULL_TREE
;
4944 body
= c_parser_c99_block_statement (parser
);
4945 if (is_foreach_statement
)
4946 objc_finish_foreach_loop (loc
, object_expression
, collection_expression
, body
, c_break_label
, c_cont_label
);
4948 c_finish_loop (loc
, cond
, incr
, body
, c_break_label
, c_cont_label
, true);
4949 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
|| c_dialect_objc ()));
4950 c_break_label
= save_break
;
4951 c_cont_label
= save_cont
;
4954 /* Parse an asm statement, a GNU extension. This is a full-blown asm
4955 statement with inputs, outputs, clobbers, and volatile tag
4959 asm type-qualifier[opt] ( asm-argument ) ;
4960 asm type-qualifier[opt] goto ( asm-goto-argument ) ;
4964 asm-string-literal : asm-operands[opt]
4965 asm-string-literal : asm-operands[opt] : asm-operands[opt]
4966 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers[opt]
4969 asm-string-literal : : asm-operands[opt] : asm-clobbers[opt] \
4972 Qualifiers other than volatile are accepted in the syntax but
4976 c_parser_asm_statement (c_parser
*parser
)
4978 tree quals
, str
, outputs
, inputs
, clobbers
, labels
, ret
;
4979 bool simple
, is_goto
;
4980 location_t asm_loc
= c_parser_peek_token (parser
)->location
;
4981 int section
, nsections
;
4983 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
4984 c_parser_consume_token (parser
);
4985 if (c_parser_next_token_is_keyword (parser
, RID_VOLATILE
))
4987 quals
= c_parser_peek_token (parser
)->value
;
4988 c_parser_consume_token (parser
);
4990 else if (c_parser_next_token_is_keyword (parser
, RID_CONST
)
4991 || c_parser_next_token_is_keyword (parser
, RID_RESTRICT
))
4993 warning_at (c_parser_peek_token (parser
)->location
,
4995 "%E qualifier ignored on asm",
4996 c_parser_peek_token (parser
)->value
);
4998 c_parser_consume_token (parser
);
5004 if (c_parser_next_token_is_keyword (parser
, RID_GOTO
))
5006 c_parser_consume_token (parser
);
5010 /* ??? Follow the C++ parser rather than using the
5011 lex_untranslated_string kludge. */
5012 parser
->lex_untranslated_string
= true;
5015 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5018 str
= c_parser_asm_string_literal (parser
);
5019 if (str
== NULL_TREE
)
5020 goto error_close_paren
;
5023 outputs
= NULL_TREE
;
5025 clobbers
= NULL_TREE
;
5028 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
5031 /* Parse each colon-delimited section of operands. */
5032 nsections
= 3 + is_goto
;
5033 for (section
= 0; section
< nsections
; ++section
)
5035 if (!c_parser_require (parser
, CPP_COLON
,
5038 : "expected %<:%> or %<)%>"))
5039 goto error_close_paren
;
5041 /* Once past any colon, we're no longer a simple asm. */
5044 if ((!c_parser_next_token_is (parser
, CPP_COLON
)
5045 && !c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
5050 /* For asm goto, we don't allow output operands, but reserve
5051 the slot for a future extension that does allow them. */
5053 outputs
= c_parser_asm_operands (parser
, false);
5056 inputs
= c_parser_asm_operands (parser
, true);
5059 clobbers
= c_parser_asm_clobbers (parser
);
5062 labels
= c_parser_asm_goto_operands (parser
);
5068 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
5073 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
5075 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5079 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
5080 c_parser_skip_to_end_of_block_or_statement (parser
);
5082 ret
= build_asm_stmt (quals
, build_asm_expr (asm_loc
, str
, outputs
, inputs
,
5083 clobbers
, labels
, simple
));
5086 parser
->lex_untranslated_string
= false;
5090 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5094 /* Parse asm operands, a GNU extension. If CONVERT_P (for inputs but
5095 not outputs), apply the default conversion of functions and arrays
5100 asm-operands , asm-operand
5103 asm-string-literal ( expression )
5104 [ identifier ] asm-string-literal ( expression )
5108 c_parser_asm_operands (c_parser
*parser
, bool convert_p
)
5110 tree list
= NULL_TREE
;
5116 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
5118 c_parser_consume_token (parser
);
5119 if (c_parser_next_token_is (parser
, CPP_NAME
))
5121 tree id
= c_parser_peek_token (parser
)->value
;
5122 c_parser_consume_token (parser
);
5123 name
= build_string (IDENTIFIER_LENGTH (id
),
5124 IDENTIFIER_POINTER (id
));
5128 c_parser_error (parser
, "expected identifier");
5129 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
5132 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5137 str
= c_parser_asm_string_literal (parser
);
5138 if (str
== NULL_TREE
)
5140 parser
->lex_untranslated_string
= false;
5141 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5143 parser
->lex_untranslated_string
= true;
5146 loc
= c_parser_peek_token (parser
)->location
;
5147 expr
= c_parser_expression (parser
);
5148 mark_exp_read (expr
.value
);
5150 expr
= default_function_array_conversion (loc
, expr
);
5151 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
5152 parser
->lex_untranslated_string
= true;
5153 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
5155 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5158 list
= chainon (list
, build_tree_list (build_tree_list (name
, str
),
5160 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5161 c_parser_consume_token (parser
);
5168 /* Parse asm clobbers, a GNU extension.
5172 asm-clobbers , asm-string-literal
5176 c_parser_asm_clobbers (c_parser
*parser
)
5178 tree list
= NULL_TREE
;
5181 tree str
= c_parser_asm_string_literal (parser
);
5183 list
= tree_cons (NULL_TREE
, str
, list
);
5186 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5187 c_parser_consume_token (parser
);
5194 /* Parse asm goto labels, a GNU extension.
5198 asm-goto-operands , identifier
5202 c_parser_asm_goto_operands (c_parser
*parser
)
5204 tree list
= NULL_TREE
;
5209 if (c_parser_next_token_is (parser
, CPP_NAME
))
5211 c_token
*tok
= c_parser_peek_token (parser
);
5213 label
= lookup_label_for_goto (tok
->location
, name
);
5214 c_parser_consume_token (parser
);
5215 TREE_USED (label
) = 1;
5219 c_parser_error (parser
, "expected identifier");
5223 name
= build_string (IDENTIFIER_LENGTH (name
),
5224 IDENTIFIER_POINTER (name
));
5225 list
= tree_cons (name
, label
, list
);
5226 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5227 c_parser_consume_token (parser
);
5229 return nreverse (list
);
5233 /* Parse an expression other than a compound expression; that is, an
5234 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
5235 NULL then it is an Objective-C message expression which is the
5236 primary-expression starting the expression as an initializer.
5238 assignment-expression:
5239 conditional-expression
5240 unary-expression assignment-operator assignment-expression
5242 assignment-operator: one of
5243 = *= /= %= += -= <<= >>= &= ^= |=
5245 In GNU C we accept any conditional expression on the LHS and
5246 diagnose the invalid lvalue rather than producing a syntax
5249 static struct c_expr
5250 c_parser_expr_no_commas (c_parser
*parser
, struct c_expr
*after
)
5252 struct c_expr lhs
, rhs
, ret
;
5253 enum tree_code code
;
5254 location_t op_location
, exp_location
;
5255 gcc_assert (!after
|| c_dialect_objc ());
5256 lhs
= c_parser_conditional_expression (parser
, after
);
5257 op_location
= c_parser_peek_token (parser
)->location
;
5258 switch (c_parser_peek_token (parser
)->type
)
5267 code
= TRUNC_DIV_EXPR
;
5270 code
= TRUNC_MOD_EXPR
;
5285 code
= BIT_AND_EXPR
;
5288 code
= BIT_XOR_EXPR
;
5291 code
= BIT_IOR_EXPR
;
5296 c_parser_consume_token (parser
);
5297 exp_location
= c_parser_peek_token (parser
)->location
;
5298 rhs
= c_parser_expr_no_commas (parser
, NULL
);
5299 rhs
= default_function_array_read_conversion (exp_location
, rhs
);
5300 ret
.value
= build_modify_expr (op_location
, lhs
.value
, lhs
.original_type
,
5301 code
, exp_location
, rhs
.value
,
5303 if (code
== NOP_EXPR
)
5304 ret
.original_code
= MODIFY_EXPR
;
5307 TREE_NO_WARNING (ret
.value
) = 1;
5308 ret
.original_code
= ERROR_MARK
;
5310 ret
.original_type
= NULL
;
5314 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
5315 is not NULL then it is an Objective-C message expression which is
5316 the primary-expression starting the expression as an initializer.
5318 conditional-expression:
5319 logical-OR-expression
5320 logical-OR-expression ? expression : conditional-expression
5324 conditional-expression:
5325 logical-OR-expression ? : conditional-expression
5328 static struct c_expr
5329 c_parser_conditional_expression (c_parser
*parser
, struct c_expr
*after
)
5331 struct c_expr cond
, exp1
, exp2
, ret
;
5332 location_t cond_loc
, colon_loc
, middle_loc
;
5334 gcc_assert (!after
|| c_dialect_objc ());
5336 cond
= c_parser_binary_expression (parser
, after
, PREC_NONE
);
5338 if (c_parser_next_token_is_not (parser
, CPP_QUERY
))
5340 cond_loc
= c_parser_peek_token (parser
)->location
;
5341 cond
= default_function_array_read_conversion (cond_loc
, cond
);
5342 c_parser_consume_token (parser
);
5343 if (c_parser_next_token_is (parser
, CPP_COLON
))
5345 tree eptype
= NULL_TREE
;
5347 middle_loc
= c_parser_peek_token (parser
)->location
;
5348 pedwarn (middle_loc
, OPT_pedantic
,
5349 "ISO C forbids omitting the middle term of a ?: expression");
5350 warn_for_omitted_condop (middle_loc
, cond
.value
);
5351 if (TREE_CODE (cond
.value
) == EXCESS_PRECISION_EXPR
)
5353 eptype
= TREE_TYPE (cond
.value
);
5354 cond
.value
= TREE_OPERAND (cond
.value
, 0);
5356 /* Make sure first operand is calculated only once. */
5357 exp1
.value
= c_save_expr (default_conversion (cond
.value
));
5359 exp1
.value
= build1 (EXCESS_PRECISION_EXPR
, eptype
, exp1
.value
);
5360 exp1
.original_type
= NULL
;
5361 cond
.value
= c_objc_common_truthvalue_conversion (cond_loc
, exp1
.value
);
5362 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_true_node
;
5367 = c_objc_common_truthvalue_conversion
5368 (cond_loc
, default_conversion (cond
.value
));
5369 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_false_node
;
5370 exp1
= c_parser_expression_conv (parser
);
5371 mark_exp_read (exp1
.value
);
5372 c_inhibit_evaluation_warnings
+=
5373 ((cond
.value
== truthvalue_true_node
)
5374 - (cond
.value
== truthvalue_false_node
));
5377 colon_loc
= c_parser_peek_token (parser
)->location
;
5378 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
5380 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
5381 ret
.value
= error_mark_node
;
5382 ret
.original_code
= ERROR_MARK
;
5383 ret
.original_type
= NULL
;
5387 location_t exp2_loc
= c_parser_peek_token (parser
)->location
;
5388 exp2
= c_parser_conditional_expression (parser
, NULL
);
5389 exp2
= default_function_array_read_conversion (exp2_loc
, exp2
);
5391 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
5392 ret
.value
= build_conditional_expr (colon_loc
, cond
.value
,
5393 cond
.original_code
== C_MAYBE_CONST_EXPR
,
5394 exp1
.value
, exp1
.original_type
,
5395 exp2
.value
, exp2
.original_type
);
5396 ret
.original_code
= ERROR_MARK
;
5397 if (exp1
.value
== error_mark_node
|| exp2
.value
== error_mark_node
)
5398 ret
.original_type
= NULL
;
5403 /* If both sides are enum type, the default conversion will have
5404 made the type of the result be an integer type. We want to
5405 remember the enum types we started with. */
5406 t1
= exp1
.original_type
? exp1
.original_type
: TREE_TYPE (exp1
.value
);
5407 t2
= exp2
.original_type
? exp2
.original_type
: TREE_TYPE (exp2
.value
);
5408 ret
.original_type
= ((t1
!= error_mark_node
5409 && t2
!= error_mark_node
5410 && (TYPE_MAIN_VARIANT (t1
)
5411 == TYPE_MAIN_VARIANT (t2
)))
5418 /* Parse a binary expression; that is, a logical-OR-expression (C90
5419 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
5420 an Objective-C message expression which is the primary-expression
5421 starting the expression as an initializer. PREC is the starting
5422 precedence, usually PREC_NONE.
5424 multiplicative-expression:
5426 multiplicative-expression * cast-expression
5427 multiplicative-expression / cast-expression
5428 multiplicative-expression % cast-expression
5430 additive-expression:
5431 multiplicative-expression
5432 additive-expression + multiplicative-expression
5433 additive-expression - multiplicative-expression
5437 shift-expression << additive-expression
5438 shift-expression >> additive-expression
5440 relational-expression:
5442 relational-expression < shift-expression
5443 relational-expression > shift-expression
5444 relational-expression <= shift-expression
5445 relational-expression >= shift-expression
5447 equality-expression:
5448 relational-expression
5449 equality-expression == relational-expression
5450 equality-expression != relational-expression
5454 AND-expression & equality-expression
5456 exclusive-OR-expression:
5458 exclusive-OR-expression ^ AND-expression
5460 inclusive-OR-expression:
5461 exclusive-OR-expression
5462 inclusive-OR-expression | exclusive-OR-expression
5464 logical-AND-expression:
5465 inclusive-OR-expression
5466 logical-AND-expression && inclusive-OR-expression
5468 logical-OR-expression:
5469 logical-AND-expression
5470 logical-OR-expression || logical-AND-expression
5473 static struct c_expr
5474 c_parser_binary_expression (c_parser
*parser
, struct c_expr
*after
,
5475 enum c_parser_prec prec
)
5477 /* A binary expression is parsed using operator-precedence parsing,
5478 with the operands being cast expressions. All the binary
5479 operators are left-associative. Thus a binary expression is of
5482 E0 op1 E1 op2 E2 ...
5484 which we represent on a stack. On the stack, the precedence
5485 levels are strictly increasing. When a new operator is
5486 encountered of higher precedence than that at the top of the
5487 stack, it is pushed; its LHS is the top expression, and its RHS
5488 is everything parsed until it is popped. When a new operator is
5489 encountered with precedence less than or equal to that at the top
5490 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
5491 by the result of the operation until the operator at the top of
5492 the stack has lower precedence than the new operator or there is
5493 only one element on the stack; then the top expression is the LHS
5494 of the new operator. In the case of logical AND and OR
5495 expressions, we also need to adjust c_inhibit_evaluation_warnings
5496 as appropriate when the operators are pushed and popped. */
5499 /* The expression at this stack level. */
5501 /* The precedence of the operator on its left, PREC_NONE at the
5502 bottom of the stack. */
5503 enum c_parser_prec prec
;
5504 /* The operation on its left. */
5506 /* The source location of this operation. */
5510 /* Location of the binary operator. */
5511 location_t binary_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
5514 switch (stack[sp].op) \
5516 case TRUTH_ANDIF_EXPR: \
5517 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
5518 == truthvalue_false_node); \
5520 case TRUTH_ORIF_EXPR: \
5521 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
5522 == truthvalue_true_node); \
5527 stack[sp - 1].expr \
5528 = default_function_array_read_conversion (stack[sp - 1].loc, \
5529 stack[sp - 1].expr); \
5531 = default_function_array_read_conversion (stack[sp].loc, \
5533 stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc, \
5535 stack[sp - 1].expr, \
5539 gcc_assert (!after
|| c_dialect_objc ());
5540 stack
[0].loc
= c_parser_peek_token (parser
)->location
;
5541 stack
[0].expr
= c_parser_cast_expression (parser
, after
);
5542 stack
[0].prec
= prec
;
5546 enum c_parser_prec oprec
;
5547 enum tree_code ocode
;
5550 switch (c_parser_peek_token (parser
)->type
)
5558 ocode
= TRUNC_DIV_EXPR
;
5562 ocode
= TRUNC_MOD_EXPR
;
5574 ocode
= LSHIFT_EXPR
;
5578 ocode
= RSHIFT_EXPR
;
5592 case CPP_GREATER_EQ
:
5605 oprec
= PREC_BITAND
;
5606 ocode
= BIT_AND_EXPR
;
5609 oprec
= PREC_BITXOR
;
5610 ocode
= BIT_XOR_EXPR
;
5614 ocode
= BIT_IOR_EXPR
;
5617 oprec
= PREC_LOGAND
;
5618 ocode
= TRUTH_ANDIF_EXPR
;
5622 ocode
= TRUTH_ORIF_EXPR
;
5625 /* Not a binary operator, so end of the binary
5629 binary_loc
= c_parser_peek_token (parser
)->location
;
5630 while (oprec
<= stack
[sp
].prec
)
5636 c_parser_consume_token (parser
);
5639 case TRUTH_ANDIF_EXPR
:
5641 = default_function_array_read_conversion (stack
[sp
].loc
,
5643 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
5644 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
5645 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
5646 == truthvalue_false_node
);
5648 case TRUTH_ORIF_EXPR
:
5650 = default_function_array_read_conversion (stack
[sp
].loc
,
5652 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
5653 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
5654 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
5655 == truthvalue_true_node
);
5661 stack
[sp
].loc
= binary_loc
;
5662 stack
[sp
].expr
= c_parser_cast_expression (parser
, NULL
);
5663 stack
[sp
].prec
= oprec
;
5664 stack
[sp
].op
= ocode
;
5665 stack
[sp
].loc
= binary_loc
;
5670 return stack
[0].expr
;
5674 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
5675 NULL then it is an Objective-C message expression which is the
5676 primary-expression starting the expression as an initializer.
5680 ( type-name ) unary-expression
5683 static struct c_expr
5684 c_parser_cast_expression (c_parser
*parser
, struct c_expr
*after
)
5686 location_t cast_loc
= c_parser_peek_token (parser
)->location
;
5687 gcc_assert (!after
|| c_dialect_objc ());
5689 return c_parser_postfix_expression_after_primary (parser
,
5691 /* If the expression begins with a parenthesized type name, it may
5692 be either a cast or a compound literal; we need to see whether
5693 the next character is '{' to tell the difference. If not, it is
5694 an unary expression. Full detection of unknown typenames here
5695 would require a 3-token lookahead. */
5696 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
5697 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
5699 struct c_type_name
*type_name
;
5702 c_parser_consume_token (parser
);
5703 type_name
= c_parser_type_name (parser
);
5704 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5705 if (type_name
== NULL
)
5707 ret
.value
= error_mark_node
;
5708 ret
.original_code
= ERROR_MARK
;
5709 ret
.original_type
= NULL
;
5713 /* Save casted types in the function's used types hash table. */
5714 used_types_insert (type_name
->specs
->type
);
5716 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5717 return c_parser_postfix_expression_after_paren_type (parser
, type_name
,
5720 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
5721 expr
= c_parser_cast_expression (parser
, NULL
);
5722 expr
= default_function_array_read_conversion (expr_loc
, expr
);
5724 ret
.value
= c_cast_expr (cast_loc
, type_name
, expr
.value
);
5725 ret
.original_code
= ERROR_MARK
;
5726 ret
.original_type
= NULL
;
5730 return c_parser_unary_expression (parser
);
5733 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
5739 unary-operator cast-expression
5740 sizeof unary-expression
5741 sizeof ( type-name )
5743 unary-operator: one of
5749 __alignof__ unary-expression
5750 __alignof__ ( type-name )
5753 unary-operator: one of
5754 __extension__ __real__ __imag__
5756 In addition, the GNU syntax treats ++ and -- as unary operators, so
5757 they may be applied to cast expressions with errors for non-lvalues
5760 static struct c_expr
5761 c_parser_unary_expression (c_parser
*parser
)
5764 struct c_expr ret
, op
;
5765 location_t op_loc
= c_parser_peek_token (parser
)->location
;
5767 ret
.original_code
= ERROR_MARK
;
5768 ret
.original_type
= NULL
;
5769 switch (c_parser_peek_token (parser
)->type
)
5772 c_parser_consume_token (parser
);
5773 exp_loc
= c_parser_peek_token (parser
)->location
;
5774 op
= c_parser_cast_expression (parser
, NULL
);
5775 op
= default_function_array_read_conversion (exp_loc
, op
);
5776 return parser_build_unary_op (op_loc
, PREINCREMENT_EXPR
, op
);
5777 case CPP_MINUS_MINUS
:
5778 c_parser_consume_token (parser
);
5779 exp_loc
= c_parser_peek_token (parser
)->location
;
5780 op
= c_parser_cast_expression (parser
, NULL
);
5781 op
= default_function_array_read_conversion (exp_loc
, op
);
5782 return parser_build_unary_op (op_loc
, PREDECREMENT_EXPR
, op
);
5784 c_parser_consume_token (parser
);
5785 op
= c_parser_cast_expression (parser
, NULL
);
5786 mark_exp_read (op
.value
);
5787 return parser_build_unary_op (op_loc
, ADDR_EXPR
, op
);
5789 c_parser_consume_token (parser
);
5790 exp_loc
= c_parser_peek_token (parser
)->location
;
5791 op
= c_parser_cast_expression (parser
, NULL
);
5792 op
= default_function_array_read_conversion (exp_loc
, op
);
5793 ret
.value
= build_indirect_ref (op_loc
, op
.value
, RO_UNARY_STAR
);
5796 if (!c_dialect_objc () && !in_system_header
)
5799 "traditional C rejects the unary plus operator");
5800 c_parser_consume_token (parser
);
5801 exp_loc
= c_parser_peek_token (parser
)->location
;
5802 op
= c_parser_cast_expression (parser
, NULL
);
5803 op
= default_function_array_read_conversion (exp_loc
, op
);
5804 return parser_build_unary_op (op_loc
, CONVERT_EXPR
, op
);
5806 c_parser_consume_token (parser
);
5807 exp_loc
= c_parser_peek_token (parser
)->location
;
5808 op
= c_parser_cast_expression (parser
, NULL
);
5809 op
= default_function_array_read_conversion (exp_loc
, op
);
5810 return parser_build_unary_op (op_loc
, NEGATE_EXPR
, op
);
5812 c_parser_consume_token (parser
);
5813 exp_loc
= c_parser_peek_token (parser
)->location
;
5814 op
= c_parser_cast_expression (parser
, NULL
);
5815 op
= default_function_array_read_conversion (exp_loc
, op
);
5816 return parser_build_unary_op (op_loc
, BIT_NOT_EXPR
, op
);
5818 c_parser_consume_token (parser
);
5819 exp_loc
= c_parser_peek_token (parser
)->location
;
5820 op
= c_parser_cast_expression (parser
, NULL
);
5821 op
= default_function_array_read_conversion (exp_loc
, op
);
5822 return parser_build_unary_op (op_loc
, TRUTH_NOT_EXPR
, op
);
5824 /* Refer to the address of a label as a pointer. */
5825 c_parser_consume_token (parser
);
5826 if (c_parser_next_token_is (parser
, CPP_NAME
))
5828 ret
.value
= finish_label_address_expr
5829 (c_parser_peek_token (parser
)->value
, op_loc
);
5830 c_parser_consume_token (parser
);
5834 c_parser_error (parser
, "expected identifier");
5835 ret
.value
= error_mark_node
;
5839 switch (c_parser_peek_token (parser
)->keyword
)
5842 return c_parser_sizeof_expression (parser
);
5844 return c_parser_alignof_expression (parser
);
5846 c_parser_consume_token (parser
);
5847 ext
= disable_extension_diagnostics ();
5848 ret
= c_parser_cast_expression (parser
, NULL
);
5849 restore_extension_diagnostics (ext
);
5852 c_parser_consume_token (parser
);
5853 exp_loc
= c_parser_peek_token (parser
)->location
;
5854 op
= c_parser_cast_expression (parser
, NULL
);
5855 op
= default_function_array_conversion (exp_loc
, op
);
5856 return parser_build_unary_op (op_loc
, REALPART_EXPR
, op
);
5858 c_parser_consume_token (parser
);
5859 exp_loc
= c_parser_peek_token (parser
)->location
;
5860 op
= c_parser_cast_expression (parser
, NULL
);
5861 op
= default_function_array_conversion (exp_loc
, op
);
5862 return parser_build_unary_op (op_loc
, IMAGPART_EXPR
, op
);
5864 return c_parser_postfix_expression (parser
);
5867 return c_parser_postfix_expression (parser
);
5871 /* Parse a sizeof expression. */
5873 static struct c_expr
5874 c_parser_sizeof_expression (c_parser
*parser
)
5877 location_t expr_loc
;
5878 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SIZEOF
));
5879 c_parser_consume_token (parser
);
5880 c_inhibit_evaluation_warnings
++;
5882 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
5883 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
5885 /* Either sizeof ( type-name ) or sizeof unary-expression
5886 starting with a compound literal. */
5887 struct c_type_name
*type_name
;
5888 c_parser_consume_token (parser
);
5889 expr_loc
= c_parser_peek_token (parser
)->location
;
5890 type_name
= c_parser_type_name (parser
);
5891 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5892 if (type_name
== NULL
)
5895 c_inhibit_evaluation_warnings
--;
5897 ret
.value
= error_mark_node
;
5898 ret
.original_code
= ERROR_MARK
;
5899 ret
.original_type
= NULL
;
5902 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5904 expr
= c_parser_postfix_expression_after_paren_type (parser
,
5909 /* sizeof ( type-name ). */
5910 c_inhibit_evaluation_warnings
--;
5912 return c_expr_sizeof_type (expr_loc
, type_name
);
5916 expr_loc
= c_parser_peek_token (parser
)->location
;
5917 expr
= c_parser_unary_expression (parser
);
5919 c_inhibit_evaluation_warnings
--;
5921 mark_exp_read (expr
.value
);
5922 if (TREE_CODE (expr
.value
) == COMPONENT_REF
5923 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
5924 error_at (expr_loc
, "%<sizeof%> applied to a bit-field");
5925 return c_expr_sizeof_expr (expr_loc
, expr
);
5929 /* Parse an alignof expression. */
5931 static struct c_expr
5932 c_parser_alignof_expression (c_parser
*parser
)
5935 location_t loc
= c_parser_peek_token (parser
)->location
;
5936 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNOF
));
5937 c_parser_consume_token (parser
);
5938 c_inhibit_evaluation_warnings
++;
5940 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
5941 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
5943 /* Either __alignof__ ( type-name ) or __alignof__
5944 unary-expression starting with a compound literal. */
5946 struct c_type_name
*type_name
;
5948 c_parser_consume_token (parser
);
5949 loc
= c_parser_peek_token (parser
)->location
;
5950 type_name
= c_parser_type_name (parser
);
5951 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5952 if (type_name
== NULL
)
5955 c_inhibit_evaluation_warnings
--;
5957 ret
.value
= error_mark_node
;
5958 ret
.original_code
= ERROR_MARK
;
5959 ret
.original_type
= NULL
;
5962 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5964 expr
= c_parser_postfix_expression_after_paren_type (parser
,
5969 /* alignof ( type-name ). */
5970 c_inhibit_evaluation_warnings
--;
5972 ret
.value
= c_alignof (loc
, groktypename (type_name
, NULL
, NULL
));
5973 ret
.original_code
= ERROR_MARK
;
5974 ret
.original_type
= NULL
;
5980 expr
= c_parser_unary_expression (parser
);
5982 mark_exp_read (expr
.value
);
5983 c_inhibit_evaluation_warnings
--;
5985 ret
.value
= c_alignof_expr (loc
, expr
.value
);
5986 ret
.original_code
= ERROR_MARK
;
5987 ret
.original_type
= NULL
;
5992 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
5996 postfix-expression [ expression ]
5997 postfix-expression ( argument-expression-list[opt] )
5998 postfix-expression . identifier
5999 postfix-expression -> identifier
6000 postfix-expression ++
6001 postfix-expression --
6002 ( type-name ) { initializer-list }
6003 ( type-name ) { initializer-list , }
6005 argument-expression-list:
6007 argument-expression-list , argument-expression
6019 (treated as a keyword in GNU C)
6022 ( compound-statement )
6023 __builtin_va_arg ( assignment-expression , type-name )
6024 __builtin_offsetof ( type-name , offsetof-member-designator )
6025 __builtin_choose_expr ( assignment-expression ,
6026 assignment-expression ,
6027 assignment-expression )
6028 __builtin_types_compatible_p ( type-name , type-name )
6029 __builtin_complex ( assignment-expression , assignment-expression )
6031 offsetof-member-designator:
6033 offsetof-member-designator . identifier
6034 offsetof-member-designator [ expression ]
6039 [ objc-receiver objc-message-args ]
6040 @selector ( objc-selector-arg )
6041 @protocol ( identifier )
6042 @encode ( type-name )
6044 Classname . identifier
6047 static struct c_expr
6048 c_parser_postfix_expression (c_parser
*parser
)
6050 struct c_expr expr
, e1
, e2
, e3
;
6051 struct c_type_name
*t1
, *t2
;
6052 location_t loc
= c_parser_peek_token (parser
)->location
;;
6053 expr
.original_code
= ERROR_MARK
;
6054 expr
.original_type
= NULL
;
6055 switch (c_parser_peek_token (parser
)->type
)
6058 expr
.value
= c_parser_peek_token (parser
)->value
;
6059 loc
= c_parser_peek_token (parser
)->location
;
6060 c_parser_consume_token (parser
);
6061 if (TREE_CODE (expr
.value
) == FIXED_CST
6062 && !targetm
.fixed_point_supported_p ())
6064 error_at (loc
, "fixed-point types not supported for this target");
6065 expr
.value
= error_mark_node
;
6072 expr
.value
= c_parser_peek_token (parser
)->value
;
6073 c_parser_consume_token (parser
);
6079 case CPP_UTF8STRING
:
6080 expr
.value
= c_parser_peek_token (parser
)->value
;
6081 expr
.original_code
= STRING_CST
;
6082 c_parser_consume_token (parser
);
6084 case CPP_OBJC_STRING
:
6085 gcc_assert (c_dialect_objc ());
6087 = objc_build_string_object (c_parser_peek_token (parser
)->value
);
6088 c_parser_consume_token (parser
);
6091 switch (c_parser_peek_token (parser
)->id_kind
)
6095 tree id
= c_parser_peek_token (parser
)->value
;
6096 c_parser_consume_token (parser
);
6097 expr
.value
= build_external_ref (loc
, id
,
6098 (c_parser_peek_token (parser
)->type
6100 &expr
.original_type
);
6103 case C_ID_CLASSNAME
:
6105 /* Here we parse the Objective-C 2.0 Class.name dot
6107 tree class_name
= c_parser_peek_token (parser
)->value
;
6109 c_parser_consume_token (parser
);
6110 gcc_assert (c_dialect_objc ());
6111 if (!c_parser_require (parser
, CPP_DOT
, "expected %<.%>"))
6113 expr
.value
= error_mark_node
;
6116 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6118 c_parser_error (parser
, "expected identifier");
6119 expr
.value
= error_mark_node
;
6122 component
= c_parser_peek_token (parser
)->value
;
6123 c_parser_consume_token (parser
);
6124 expr
.value
= objc_build_class_component_ref (class_name
,
6129 c_parser_error (parser
, "expected expression");
6130 expr
.value
= error_mark_node
;
6134 case CPP_OPEN_PAREN
:
6135 /* A parenthesized expression, statement expression or compound
6137 if (c_parser_peek_2nd_token (parser
)->type
== CPP_OPEN_BRACE
)
6139 /* A statement expression. */
6141 location_t brace_loc
;
6142 c_parser_consume_token (parser
);
6143 brace_loc
= c_parser_peek_token (parser
)->location
;
6144 c_parser_consume_token (parser
);
6145 if (!building_stmt_list_p ())
6147 error_at (loc
, "braced-group within expression allowed "
6148 "only inside a function");
6149 parser
->error
= true;
6150 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
6151 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6152 expr
.value
= error_mark_node
;
6155 stmt
= c_begin_stmt_expr ();
6156 c_parser_compound_statement_nostart (parser
);
6157 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6159 pedwarn (loc
, OPT_pedantic
,
6160 "ISO C forbids braced-groups within expressions");
6161 expr
.value
= c_finish_stmt_expr (brace_loc
, stmt
);
6162 mark_exp_read (expr
.value
);
6164 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6166 /* A compound literal. ??? Can we actually get here rather
6167 than going directly to
6168 c_parser_postfix_expression_after_paren_type from
6171 struct c_type_name
*type_name
;
6172 c_parser_consume_token (parser
);
6173 loc
= c_parser_peek_token (parser
)->location
;
6174 type_name
= c_parser_type_name (parser
);
6175 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6177 if (type_name
== NULL
)
6179 expr
.value
= error_mark_node
;
6182 expr
= c_parser_postfix_expression_after_paren_type (parser
,
6188 /* A parenthesized expression. */
6189 c_parser_consume_token (parser
);
6190 expr
= c_parser_expression (parser
);
6191 if (TREE_CODE (expr
.value
) == MODIFY_EXPR
)
6192 TREE_NO_WARNING (expr
.value
) = 1;
6193 if (expr
.original_code
!= C_MAYBE_CONST_EXPR
)
6194 expr
.original_code
= ERROR_MARK
;
6195 /* Don't change EXPR.ORIGINAL_TYPE. */
6196 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6201 switch (c_parser_peek_token (parser
)->keyword
)
6203 case RID_FUNCTION_NAME
:
6204 case RID_PRETTY_FUNCTION_NAME
:
6205 case RID_C99_FUNCTION_NAME
:
6206 expr
.value
= fname_decl (loc
,
6207 c_parser_peek_token (parser
)->keyword
,
6208 c_parser_peek_token (parser
)->value
);
6209 c_parser_consume_token (parser
);
6212 c_parser_consume_token (parser
);
6213 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6215 expr
.value
= error_mark_node
;
6218 e1
= c_parser_expr_no_commas (parser
, NULL
);
6219 mark_exp_read (e1
.value
);
6220 e1
.value
= c_fully_fold (e1
.value
, false, NULL
);
6221 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
6223 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6224 expr
.value
= error_mark_node
;
6227 loc
= c_parser_peek_token (parser
)->location
;
6228 t1
= c_parser_type_name (parser
);
6229 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6233 expr
.value
= error_mark_node
;
6237 tree type_expr
= NULL_TREE
;
6238 expr
.value
= c_build_va_arg (loc
, e1
.value
,
6239 groktypename (t1
, &type_expr
, NULL
));
6242 expr
.value
= build2 (C_MAYBE_CONST_EXPR
,
6243 TREE_TYPE (expr
.value
), type_expr
,
6245 C_MAYBE_CONST_EXPR_NON_CONST (expr
.value
) = true;
6250 c_parser_consume_token (parser
);
6251 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6253 expr
.value
= error_mark_node
;
6256 t1
= c_parser_type_name (parser
);
6258 parser
->error
= true;
6259 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
6260 gcc_assert (parser
->error
);
6263 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6264 expr
.value
= error_mark_node
;
6269 tree type
= groktypename (t1
, NULL
, NULL
);
6271 if (type
== error_mark_node
)
6272 offsetof_ref
= error_mark_node
;
6275 offsetof_ref
= build1 (INDIRECT_REF
, type
, null_pointer_node
);
6276 SET_EXPR_LOCATION (offsetof_ref
, loc
);
6278 /* Parse the second argument to __builtin_offsetof. We
6279 must have one identifier, and beyond that we want to
6280 accept sub structure and sub array references. */
6281 if (c_parser_next_token_is (parser
, CPP_NAME
))
6283 offsetof_ref
= build_component_ref
6284 (loc
, offsetof_ref
, c_parser_peek_token (parser
)->value
);
6285 c_parser_consume_token (parser
);
6286 while (c_parser_next_token_is (parser
, CPP_DOT
)
6287 || c_parser_next_token_is (parser
,
6289 || c_parser_next_token_is (parser
,
6292 if (c_parser_next_token_is (parser
, CPP_DEREF
))
6294 loc
= c_parser_peek_token (parser
)->location
;
6295 offsetof_ref
= build_array_ref (loc
,
6300 else if (c_parser_next_token_is (parser
, CPP_DOT
))
6303 c_parser_consume_token (parser
);
6304 if (c_parser_next_token_is_not (parser
,
6307 c_parser_error (parser
, "expected identifier");
6310 offsetof_ref
= build_component_ref
6312 c_parser_peek_token (parser
)->value
);
6313 c_parser_consume_token (parser
);
6318 loc
= c_parser_peek_token (parser
)->location
;
6319 c_parser_consume_token (parser
);
6320 idx
= c_parser_expression (parser
).value
;
6321 idx
= c_fully_fold (idx
, false, NULL
);
6322 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
6324 offsetof_ref
= build_array_ref (loc
, offsetof_ref
, idx
);
6329 c_parser_error (parser
, "expected identifier");
6330 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6332 expr
.value
= fold_offsetof (offsetof_ref
, NULL_TREE
);
6335 case RID_CHOOSE_EXPR
:
6336 c_parser_consume_token (parser
);
6337 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6339 expr
.value
= error_mark_node
;
6342 loc
= c_parser_peek_token (parser
)->location
;
6343 e1
= c_parser_expr_no_commas (parser
, NULL
);
6344 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
6346 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6347 expr
.value
= error_mark_node
;
6350 e2
= c_parser_expr_no_commas (parser
, NULL
);
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 e3
= c_parser_expr_no_commas (parser
, NULL
);
6358 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6364 mark_exp_read (e2
.value
);
6365 mark_exp_read (e3
.value
);
6366 if (TREE_CODE (c
) != INTEGER_CST
6367 || !INTEGRAL_TYPE_P (TREE_TYPE (c
)))
6369 "first argument to %<__builtin_choose_expr%> not"
6371 constant_expression_warning (c
);
6372 expr
= integer_zerop (c
) ? e3
: e2
;
6375 case RID_TYPES_COMPATIBLE_P
:
6376 c_parser_consume_token (parser
);
6377 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6379 expr
.value
= error_mark_node
;
6382 t1
= c_parser_type_name (parser
);
6385 expr
.value
= error_mark_node
;
6388 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
6390 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6391 expr
.value
= error_mark_node
;
6394 t2
= c_parser_type_name (parser
);
6397 expr
.value
= error_mark_node
;
6400 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6405 e1
= TYPE_MAIN_VARIANT (groktypename (t1
, NULL
, NULL
));
6406 e2
= TYPE_MAIN_VARIANT (groktypename (t2
, NULL
, NULL
));
6409 = comptypes (e1
, e2
) ? integer_one_node
: integer_zero_node
;
6412 case RID_BUILTIN_COMPLEX
:
6413 c_parser_consume_token (parser
);
6414 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6416 expr
.value
= error_mark_node
;
6419 loc
= c_parser_peek_token (parser
)->location
;
6420 e1
= c_parser_expr_no_commas (parser
, NULL
);
6421 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
6423 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6424 expr
.value
= error_mark_node
;
6427 e2
= c_parser_expr_no_commas (parser
, NULL
);
6428 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6430 mark_exp_read (e1
.value
);
6431 if (TREE_CODE (e1
.value
) == EXCESS_PRECISION_EXPR
)
6432 e1
.value
= convert (TREE_TYPE (e1
.value
),
6433 TREE_OPERAND (e1
.value
, 0));
6434 mark_exp_read (e2
.value
);
6435 if (TREE_CODE (e2
.value
) == EXCESS_PRECISION_EXPR
)
6436 e2
.value
= convert (TREE_TYPE (e2
.value
),
6437 TREE_OPERAND (e2
.value
, 0));
6438 if (!SCALAR_FLOAT_TYPE_P (TREE_TYPE (e1
.value
))
6439 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e1
.value
))
6440 || !SCALAR_FLOAT_TYPE_P (TREE_TYPE (e2
.value
))
6441 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e2
.value
)))
6443 error_at (loc
, "%<__builtin_complex%> operand "
6444 "not of real binary floating-point type");
6445 expr
.value
= error_mark_node
;
6448 if (TYPE_MAIN_VARIANT (TREE_TYPE (e1
.value
))
6449 != TYPE_MAIN_VARIANT (TREE_TYPE (e2
.value
)))
6452 "%<__builtin_complex%> operands of different types");
6453 expr
.value
= error_mark_node
;
6457 pedwarn (loc
, OPT_pedantic
,
6458 "ISO C90 does not support complex types");
6459 expr
.value
= build2 (COMPLEX_EXPR
,
6460 build_complex_type (TYPE_MAIN_VARIANT
6461 (TREE_TYPE (e1
.value
))),
6462 e1
.value
, e2
.value
);
6464 case RID_AT_SELECTOR
:
6465 gcc_assert (c_dialect_objc ());
6466 c_parser_consume_token (parser
);
6467 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6469 expr
.value
= error_mark_node
;
6473 tree sel
= c_parser_objc_selector_arg (parser
);
6474 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6476 expr
.value
= objc_build_selector_expr (loc
, sel
);
6479 case RID_AT_PROTOCOL
:
6480 gcc_assert (c_dialect_objc ());
6481 c_parser_consume_token (parser
);
6482 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6484 expr
.value
= error_mark_node
;
6487 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6489 c_parser_error (parser
, "expected identifier");
6490 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6491 expr
.value
= error_mark_node
;
6495 tree id
= c_parser_peek_token (parser
)->value
;
6496 c_parser_consume_token (parser
);
6497 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6499 expr
.value
= objc_build_protocol_expr (id
);
6503 /* Extension to support C-structures in the archiver. */
6504 gcc_assert (c_dialect_objc ());
6505 c_parser_consume_token (parser
);
6506 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6508 expr
.value
= error_mark_node
;
6511 t1
= c_parser_type_name (parser
);
6514 expr
.value
= error_mark_node
;
6515 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6518 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6521 tree type
= groktypename (t1
, NULL
, NULL
);
6522 expr
.value
= objc_build_encode_expr (type
);
6526 c_parser_error (parser
, "expected expression");
6527 expr
.value
= error_mark_node
;
6531 case CPP_OPEN_SQUARE
:
6532 if (c_dialect_objc ())
6534 tree receiver
, args
;
6535 c_parser_consume_token (parser
);
6536 receiver
= c_parser_objc_receiver (parser
);
6537 args
= c_parser_objc_message_args (parser
);
6538 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
6540 expr
.value
= objc_build_message_expr (receiver
, args
);
6543 /* Else fall through to report error. */
6545 c_parser_error (parser
, "expected expression");
6546 expr
.value
= error_mark_node
;
6549 return c_parser_postfix_expression_after_primary (parser
, loc
, expr
);
6552 /* Parse a postfix expression after a parenthesized type name: the
6553 brace-enclosed initializer of a compound literal, possibly followed
6554 by some postfix operators. This is separate because it is not
6555 possible to tell until after the type name whether a cast
6556 expression has a cast or a compound literal, or whether the operand
6557 of sizeof is a parenthesized type name or starts with a compound
6558 literal. TYPE_LOC is the location where TYPE_NAME starts--the
6559 location of the first token after the parentheses around the type
6562 static struct c_expr
6563 c_parser_postfix_expression_after_paren_type (c_parser
*parser
,
6564 struct c_type_name
*type_name
,
6565 location_t type_loc
)
6571 location_t start_loc
;
6572 tree type_expr
= NULL_TREE
;
6573 bool type_expr_const
= true;
6574 check_compound_literal_type (type_loc
, type_name
);
6575 start_init (NULL_TREE
, NULL
, 0);
6576 type
= groktypename (type_name
, &type_expr
, &type_expr_const
);
6577 start_loc
= c_parser_peek_token (parser
)->location
;
6578 if (type
!= error_mark_node
&& C_TYPE_VARIABLE_SIZE (type
))
6580 error_at (type_loc
, "compound literal has variable size");
6581 type
= error_mark_node
;
6583 init
= c_parser_braced_init (parser
, type
, false);
6585 maybe_warn_string_init (type
, init
);
6587 if (type
!= error_mark_node
6588 && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type
))
6589 && current_function_decl
)
6591 error ("compound literal qualified by address-space qualifier");
6592 type
= error_mark_node
;
6596 pedwarn (start_loc
, OPT_pedantic
, "ISO C90 forbids compound literals");
6597 non_const
= ((init
.value
&& TREE_CODE (init
.value
) == CONSTRUCTOR
)
6598 ? CONSTRUCTOR_NON_CONST (init
.value
)
6599 : init
.original_code
== C_MAYBE_CONST_EXPR
);
6600 non_const
|= !type_expr_const
;
6601 expr
.value
= build_compound_literal (start_loc
, type
, init
.value
, non_const
);
6602 expr
.original_code
= ERROR_MARK
;
6603 expr
.original_type
= NULL
;
6606 if (TREE_CODE (expr
.value
) == C_MAYBE_CONST_EXPR
)
6608 gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr
.value
) == NULL_TREE
);
6609 C_MAYBE_CONST_EXPR_PRE (expr
.value
) = type_expr
;
6613 gcc_assert (!non_const
);
6614 expr
.value
= build2 (C_MAYBE_CONST_EXPR
, type
,
6615 type_expr
, expr
.value
);
6618 return c_parser_postfix_expression_after_primary (parser
, start_loc
, expr
);
6621 /* Parse a postfix expression after the initial primary or compound
6622 literal; that is, parse a series of postfix operators.
6624 EXPR_LOC is the location of the primary expression. */
6626 static struct c_expr
6627 c_parser_postfix_expression_after_primary (c_parser
*parser
,
6628 location_t expr_loc
,
6631 struct c_expr orig_expr
;
6633 VEC(tree
,gc
) *exprlist
;
6634 VEC(tree
,gc
) *origtypes
;
6637 location_t op_loc
= c_parser_peek_token (parser
)->location
;
6638 switch (c_parser_peek_token (parser
)->type
)
6640 case CPP_OPEN_SQUARE
:
6641 /* Array reference. */
6642 c_parser_consume_token (parser
);
6643 idx
= c_parser_expression (parser
).value
;
6644 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
6646 expr
.value
= build_array_ref (op_loc
, expr
.value
, idx
);
6647 expr
.original_code
= ERROR_MARK
;
6648 expr
.original_type
= NULL
;
6650 case CPP_OPEN_PAREN
:
6651 /* Function call. */
6652 c_parser_consume_token (parser
);
6653 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
6656 exprlist
= c_parser_expr_list (parser
, true, false, &origtypes
);
6657 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6660 mark_exp_read (expr
.value
);
6661 /* FIXME diagnostics: Ideally we want the FUNCNAME, not the
6662 "(" after the FUNCNAME, which is what we have now. */
6663 expr
.value
= build_function_call_vec (op_loc
, expr
.value
, exprlist
,
6665 expr
.original_code
= ERROR_MARK
;
6666 if (TREE_CODE (expr
.value
) == INTEGER_CST
6667 && TREE_CODE (orig_expr
.value
) == FUNCTION_DECL
6668 && DECL_BUILT_IN_CLASS (orig_expr
.value
) == BUILT_IN_NORMAL
6669 && DECL_FUNCTION_CODE (orig_expr
.value
) == BUILT_IN_CONSTANT_P
)
6670 expr
.original_code
= C_MAYBE_CONST_EXPR
;
6671 expr
.original_type
= NULL
;
6672 if (exprlist
!= NULL
)
6674 release_tree_vector (exprlist
);
6675 release_tree_vector (origtypes
);
6679 /* Structure element reference. */
6680 c_parser_consume_token (parser
);
6681 expr
= default_function_array_conversion (expr_loc
, expr
);
6682 if (c_parser_next_token_is (parser
, CPP_NAME
))
6683 ident
= c_parser_peek_token (parser
)->value
;
6686 c_parser_error (parser
, "expected identifier");
6687 expr
.value
= error_mark_node
;
6688 expr
.original_code
= ERROR_MARK
;
6689 expr
.original_type
= NULL
;
6692 c_parser_consume_token (parser
);
6693 expr
.value
= build_component_ref (op_loc
, expr
.value
, ident
);
6694 expr
.original_code
= ERROR_MARK
;
6695 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
6696 expr
.original_type
= NULL
;
6699 /* Remember the original type of a bitfield. */
6700 tree field
= TREE_OPERAND (expr
.value
, 1);
6701 if (TREE_CODE (field
) != FIELD_DECL
)
6702 expr
.original_type
= NULL
;
6704 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
6708 /* Structure element reference. */
6709 c_parser_consume_token (parser
);
6710 expr
= default_function_array_conversion (expr_loc
, expr
);
6711 if (c_parser_next_token_is (parser
, CPP_NAME
))
6712 ident
= c_parser_peek_token (parser
)->value
;
6715 c_parser_error (parser
, "expected identifier");
6716 expr
.value
= error_mark_node
;
6717 expr
.original_code
= ERROR_MARK
;
6718 expr
.original_type
= NULL
;
6721 c_parser_consume_token (parser
);
6722 expr
.value
= build_component_ref (op_loc
,
6723 build_indirect_ref (op_loc
,
6727 expr
.original_code
= ERROR_MARK
;
6728 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
6729 expr
.original_type
= NULL
;
6732 /* Remember the original type of a bitfield. */
6733 tree field
= TREE_OPERAND (expr
.value
, 1);
6734 if (TREE_CODE (field
) != FIELD_DECL
)
6735 expr
.original_type
= NULL
;
6737 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
6741 /* Postincrement. */
6742 c_parser_consume_token (parser
);
6743 expr
= default_function_array_read_conversion (expr_loc
, expr
);
6744 expr
.value
= build_unary_op (op_loc
,
6745 POSTINCREMENT_EXPR
, expr
.value
, 0);
6746 expr
.original_code
= ERROR_MARK
;
6747 expr
.original_type
= NULL
;
6749 case CPP_MINUS_MINUS
:
6750 /* Postdecrement. */
6751 c_parser_consume_token (parser
);
6752 expr
= default_function_array_read_conversion (expr_loc
, expr
);
6753 expr
.value
= build_unary_op (op_loc
,
6754 POSTDECREMENT_EXPR
, expr
.value
, 0);
6755 expr
.original_code
= ERROR_MARK
;
6756 expr
.original_type
= NULL
;
6764 /* Parse an expression (C90 6.3.17, C99 6.5.17).
6767 assignment-expression
6768 expression , assignment-expression
6771 static struct c_expr
6772 c_parser_expression (c_parser
*parser
)
6775 expr
= c_parser_expr_no_commas (parser
, NULL
);
6776 while (c_parser_next_token_is (parser
, CPP_COMMA
))
6780 location_t loc
= c_parser_peek_token (parser
)->location
;
6781 location_t expr_loc
;
6782 c_parser_consume_token (parser
);
6783 expr_loc
= c_parser_peek_token (parser
)->location
;
6784 lhsval
= expr
.value
;
6785 while (TREE_CODE (lhsval
) == COMPOUND_EXPR
)
6786 lhsval
= TREE_OPERAND (lhsval
, 1);
6787 if (DECL_P (lhsval
) || handled_component_p (lhsval
))
6788 mark_exp_read (lhsval
);
6789 next
= c_parser_expr_no_commas (parser
, NULL
);
6790 next
= default_function_array_conversion (expr_loc
, next
);
6791 expr
.value
= build_compound_expr (loc
, expr
.value
, next
.value
);
6792 expr
.original_code
= COMPOUND_EXPR
;
6793 expr
.original_type
= next
.original_type
;
6798 /* Parse an expression and convert functions or arrays to
6801 static struct c_expr
6802 c_parser_expression_conv (c_parser
*parser
)
6805 location_t loc
= c_parser_peek_token (parser
)->location
;
6806 expr
= c_parser_expression (parser
);
6807 expr
= default_function_array_conversion (loc
, expr
);
6811 /* Parse a non-empty list of expressions. If CONVERT_P, convert
6812 functions and arrays to pointers. If FOLD_P, fold the expressions.
6815 assignment-expression
6816 nonempty-expr-list , assignment-expression
6819 static VEC(tree
,gc
) *
6820 c_parser_expr_list (c_parser
*parser
, bool convert_p
, bool fold_p
,
6821 VEC(tree
,gc
) **p_orig_types
)
6824 VEC(tree
,gc
) *orig_types
;
6826 location_t loc
= c_parser_peek_token (parser
)->location
;
6828 ret
= make_tree_vector ();
6829 if (p_orig_types
== NULL
)
6832 orig_types
= make_tree_vector ();
6834 expr
= c_parser_expr_no_commas (parser
, NULL
);
6836 expr
= default_function_array_read_conversion (loc
, expr
);
6838 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
6839 VEC_quick_push (tree
, ret
, expr
.value
);
6840 if (orig_types
!= NULL
)
6841 VEC_quick_push (tree
, orig_types
, expr
.original_type
);
6842 while (c_parser_next_token_is (parser
, CPP_COMMA
))
6844 c_parser_consume_token (parser
);
6845 loc
= c_parser_peek_token (parser
)->location
;
6846 expr
= c_parser_expr_no_commas (parser
, NULL
);
6848 expr
= default_function_array_read_conversion (loc
, expr
);
6850 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
6851 VEC_safe_push (tree
, gc
, ret
, expr
.value
);
6852 if (orig_types
!= NULL
)
6853 VEC_safe_push (tree
, gc
, orig_types
, expr
.original_type
);
6855 if (orig_types
!= NULL
)
6856 *p_orig_types
= orig_types
;
6860 /* Parse Objective-C-specific constructs. */
6862 /* Parse an objc-class-definition.
6864 objc-class-definition:
6865 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
6866 objc-class-instance-variables[opt] objc-methodprotolist @end
6867 @implementation identifier objc-superclass[opt]
6868 objc-class-instance-variables[opt]
6869 @interface identifier ( identifier ) objc-protocol-refs[opt]
6870 objc-methodprotolist @end
6871 @interface identifier ( ) objc-protocol-refs[opt]
6872 objc-methodprotolist @end
6873 @implementation identifier ( identifier )
6878 "@interface identifier (" must start "@interface identifier (
6879 identifier ) ...": objc-methodprotolist in the first production may
6880 not start with a parenthesized identifier as a declarator of a data
6881 definition with no declaration specifiers if the objc-superclass,
6882 objc-protocol-refs and objc-class-instance-variables are omitted. */
6885 c_parser_objc_class_definition (c_parser
*parser
, tree attributes
)
6890 if (c_parser_next_token_is_keyword (parser
, RID_AT_INTERFACE
))
6892 else if (c_parser_next_token_is_keyword (parser
, RID_AT_IMPLEMENTATION
))
6897 c_parser_consume_token (parser
);
6898 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6900 c_parser_error (parser
, "expected identifier");
6903 id1
= c_parser_peek_token (parser
)->value
;
6904 c_parser_consume_token (parser
);
6905 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
6907 /* We have a category or class extension. */
6909 tree proto
= NULL_TREE
;
6910 c_parser_consume_token (parser
);
6911 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6913 if (iface_p
&& c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
6915 /* We have a class extension. */
6920 c_parser_error (parser
, "expected identifier or %<)%>");
6921 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6927 id2
= c_parser_peek_token (parser
)->value
;
6928 c_parser_consume_token (parser
);
6930 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6933 objc_start_category_implementation (id1
, id2
);
6936 if (c_parser_next_token_is (parser
, CPP_LESS
))
6937 proto
= c_parser_objc_protocol_refs (parser
);
6938 objc_start_category_interface (id1
, id2
, proto
, attributes
);
6939 c_parser_objc_methodprotolist (parser
);
6940 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
6941 objc_finish_interface ();
6944 if (c_parser_next_token_is (parser
, CPP_COLON
))
6946 c_parser_consume_token (parser
);
6947 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6949 c_parser_error (parser
, "expected identifier");
6952 superclass
= c_parser_peek_token (parser
)->value
;
6953 c_parser_consume_token (parser
);
6956 superclass
= NULL_TREE
;
6959 tree proto
= NULL_TREE
;
6960 if (c_parser_next_token_is (parser
, CPP_LESS
))
6961 proto
= c_parser_objc_protocol_refs (parser
);
6962 objc_start_class_interface (id1
, superclass
, proto
, attributes
);
6965 objc_start_class_implementation (id1
, superclass
);
6966 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6967 c_parser_objc_class_instance_variables (parser
);
6970 objc_continue_interface ();
6971 c_parser_objc_methodprotolist (parser
);
6972 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
6973 objc_finish_interface ();
6977 objc_continue_implementation ();
6982 /* Parse objc-class-instance-variables.
6984 objc-class-instance-variables:
6985 { objc-instance-variable-decl-list[opt] }
6987 objc-instance-variable-decl-list:
6988 objc-visibility-spec
6989 objc-instance-variable-decl ;
6991 objc-instance-variable-decl-list objc-visibility-spec
6992 objc-instance-variable-decl-list objc-instance-variable-decl ;
6993 objc-instance-variable-decl-list ;
6995 objc-visibility-spec:
7000 objc-instance-variable-decl:
7005 c_parser_objc_class_instance_variables (c_parser
*parser
)
7007 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
7008 c_parser_consume_token (parser
);
7009 while (c_parser_next_token_is_not (parser
, CPP_EOF
))
7012 /* Parse any stray semicolon. */
7013 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
7015 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
7017 c_parser_consume_token (parser
);
7020 /* Stop if at the end of the instance variables. */
7021 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
7023 c_parser_consume_token (parser
);
7026 /* Parse any objc-visibility-spec. */
7027 if (c_parser_next_token_is_keyword (parser
, RID_AT_PRIVATE
))
7029 c_parser_consume_token (parser
);
7030 objc_set_visibility (OBJC_IVAR_VIS_PRIVATE
);
7033 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROTECTED
))
7035 c_parser_consume_token (parser
);
7036 objc_set_visibility (OBJC_IVAR_VIS_PROTECTED
);
7039 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PUBLIC
))
7041 c_parser_consume_token (parser
);
7042 objc_set_visibility (OBJC_IVAR_VIS_PUBLIC
);
7045 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PACKAGE
))
7047 c_parser_consume_token (parser
);
7048 objc_set_visibility (OBJC_IVAR_VIS_PACKAGE
);
7051 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
7053 c_parser_pragma (parser
, pragma_external
);
7057 /* Parse some comma-separated declarations. */
7058 decls
= c_parser_struct_declaration (parser
);
7061 /* There is a syntax error. We want to skip the offending
7062 tokens up to the next ';' (included) or '}'
7065 /* First, skip manually a ')' or ']'. This is because they
7066 reduce the nesting level, so c_parser_skip_until_found()
7067 wouldn't be able to skip past them. */
7068 c_token
*token
= c_parser_peek_token (parser
);
7069 if (token
->type
== CPP_CLOSE_PAREN
|| token
->type
== CPP_CLOSE_SQUARE
)
7070 c_parser_consume_token (parser
);
7072 /* Then, do the standard skipping. */
7073 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
7075 /* We hopefully recovered. Start normal parsing again. */
7076 parser
->error
= false;
7081 /* Comma-separated instance variables are chained together
7082 in reverse order; add them one by one. */
7083 tree ivar
= nreverse (decls
);
7084 for (; ivar
; ivar
= DECL_CHAIN (ivar
))
7085 objc_add_instance_variable (copy_node (ivar
));
7087 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7091 /* Parse an objc-class-declaration.
7093 objc-class-declaration:
7094 @class identifier-list ;
7098 c_parser_objc_class_declaration (c_parser
*parser
)
7100 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_CLASS
));
7101 c_parser_consume_token (parser
);
7102 /* Any identifiers, including those declared as type names, are OK
7107 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7109 c_parser_error (parser
, "expected identifier");
7110 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
7111 parser
->error
= false;
7114 id
= c_parser_peek_token (parser
)->value
;
7115 objc_declare_class (id
);
7116 c_parser_consume_token (parser
);
7117 if (c_parser_next_token_is (parser
, CPP_COMMA
))
7118 c_parser_consume_token (parser
);
7122 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7125 /* Parse an objc-alias-declaration.
7127 objc-alias-declaration:
7128 @compatibility_alias identifier identifier ;
7132 c_parser_objc_alias_declaration (c_parser
*parser
)
7135 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_ALIAS
));
7136 c_parser_consume_token (parser
);
7137 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7139 c_parser_error (parser
, "expected identifier");
7140 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
7143 id1
= c_parser_peek_token (parser
)->value
;
7144 c_parser_consume_token (parser
);
7145 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7147 c_parser_error (parser
, "expected identifier");
7148 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
7151 id2
= c_parser_peek_token (parser
)->value
;
7152 c_parser_consume_token (parser
);
7153 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7154 objc_declare_alias (id1
, id2
);
7157 /* Parse an objc-protocol-definition.
7159 objc-protocol-definition:
7160 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
7161 @protocol identifier-list ;
7163 "@protocol identifier ;" should be resolved as "@protocol
7164 identifier-list ;": objc-methodprotolist may not start with a
7165 semicolon in the first alternative if objc-protocol-refs are
7169 c_parser_objc_protocol_definition (c_parser
*parser
, tree attributes
)
7171 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROTOCOL
));
7173 c_parser_consume_token (parser
);
7174 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7176 c_parser_error (parser
, "expected identifier");
7179 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
7180 || c_parser_peek_2nd_token (parser
)->type
== CPP_SEMICOLON
)
7182 /* Any identifiers, including those declared as type names, are
7187 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7189 c_parser_error (parser
, "expected identifier");
7192 id
= c_parser_peek_token (parser
)->value
;
7193 objc_declare_protocol (id
, attributes
);
7194 c_parser_consume_token (parser
);
7195 if (c_parser_next_token_is (parser
, CPP_COMMA
))
7196 c_parser_consume_token (parser
);
7200 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7204 tree id
= c_parser_peek_token (parser
)->value
;
7205 tree proto
= NULL_TREE
;
7206 c_parser_consume_token (parser
);
7207 if (c_parser_next_token_is (parser
, CPP_LESS
))
7208 proto
= c_parser_objc_protocol_refs (parser
);
7209 parser
->objc_pq_context
= true;
7210 objc_start_protocol (id
, proto
, attributes
);
7211 c_parser_objc_methodprotolist (parser
);
7212 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
7213 parser
->objc_pq_context
= false;
7214 objc_finish_interface ();
7218 /* Parse an objc-method-type.
7224 Return true if it is a class method (+) and false if it is
7225 an instance method (-).
7228 c_parser_objc_method_type (c_parser
*parser
)
7230 switch (c_parser_peek_token (parser
)->type
)
7233 c_parser_consume_token (parser
);
7236 c_parser_consume_token (parser
);
7243 /* Parse an objc-method-definition.
7245 objc-method-definition:
7246 objc-method-type objc-method-decl ;[opt] compound-statement
7250 c_parser_objc_method_definition (c_parser
*parser
)
7252 bool is_class_method
= c_parser_objc_method_type (parser
);
7253 tree decl
, attributes
= NULL_TREE
, expr
= NULL_TREE
;
7254 parser
->objc_pq_context
= true;
7255 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
7257 if (decl
== error_mark_node
)
7258 return; /* Bail here. */
7260 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
7262 c_parser_consume_token (parser
);
7263 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
7264 "extra semicolon in method definition specified");
7267 if (!c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
7269 c_parser_error (parser
, "expected %<{%>");
7273 parser
->objc_pq_context
= false;
7274 if (objc_start_method_definition (is_class_method
, decl
, attributes
, expr
))
7276 add_stmt (c_parser_compound_statement (parser
));
7277 objc_finish_method_definition (current_function_decl
);
7281 /* This code is executed when we find a method definition
7282 outside of an @implementation context (or invalid for other
7283 reasons). Parse the method (to keep going) but do not emit
7286 c_parser_compound_statement (parser
);
7290 /* Parse an objc-methodprotolist.
7292 objc-methodprotolist:
7294 objc-methodprotolist objc-methodproto
7295 objc-methodprotolist declaration
7296 objc-methodprotolist ;
7300 The declaration is a data definition, which may be missing
7301 declaration specifiers under the same rules and diagnostics as
7302 other data definitions outside functions, and the stray semicolon
7303 is diagnosed the same way as a stray semicolon outside a
7307 c_parser_objc_methodprotolist (c_parser
*parser
)
7311 /* The list is terminated by @end. */
7312 switch (c_parser_peek_token (parser
)->type
)
7315 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
7316 "ISO C does not allow extra %<;%> outside of a function");
7317 c_parser_consume_token (parser
);
7321 c_parser_objc_methodproto (parser
);
7324 c_parser_pragma (parser
, pragma_external
);
7329 if (c_parser_next_token_is_keyword (parser
, RID_AT_END
))
7331 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
))
7332 c_parser_objc_at_property_declaration (parser
);
7333 else if (c_parser_next_token_is_keyword (parser
, RID_AT_OPTIONAL
))
7335 objc_set_method_opt (true);
7336 c_parser_consume_token (parser
);
7338 else if (c_parser_next_token_is_keyword (parser
, RID_AT_REQUIRED
))
7340 objc_set_method_opt (false);
7341 c_parser_consume_token (parser
);
7344 c_parser_declaration_or_fndef (parser
, false, false, true,
7351 /* Parse an objc-methodproto.
7354 objc-method-type objc-method-decl ;
7358 c_parser_objc_methodproto (c_parser
*parser
)
7360 bool is_class_method
= c_parser_objc_method_type (parser
);
7361 tree decl
, attributes
= NULL_TREE
;
7363 /* Remember protocol qualifiers in prototypes. */
7364 parser
->objc_pq_context
= true;
7365 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
7367 /* Forget protocol qualifiers now. */
7368 parser
->objc_pq_context
= false;
7370 /* Do not allow the presence of attributes to hide an erroneous
7371 method implementation in the interface section. */
7372 if (!c_parser_next_token_is (parser
, CPP_SEMICOLON
))
7374 c_parser_error (parser
, "expected %<;%>");
7378 if (decl
!= error_mark_node
)
7379 objc_add_method_declaration (is_class_method
, decl
, attributes
);
7381 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7384 /* If we are at a position that method attributes may be present, check that
7385 there are not any parsed already (a syntax error) and then collect any
7386 specified at the current location. Finally, if new attributes were present,
7387 check that the next token is legal ( ';' for decls and '{' for defs). */
7390 c_parser_objc_maybe_method_attributes (c_parser
* parser
, tree
* attributes
)
7395 c_parser_error (parser
,
7396 "method attributes must be specified at the end only");
7397 *attributes
= NULL_TREE
;
7401 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
7402 *attributes
= c_parser_attributes (parser
);
7404 /* If there were no attributes here, just report any earlier error. */
7405 if (*attributes
== NULL_TREE
|| bad
)
7408 /* If the attributes are followed by a ; or {, then just report any earlier
7410 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
7411 || c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
7414 /* We've got attributes, but not at the end. */
7415 c_parser_error (parser
,
7416 "expected %<;%> or %<{%> after method attribute definition");
7420 /* Parse an objc-method-decl.
7423 ( objc-type-name ) objc-selector
7425 ( objc-type-name ) objc-keyword-selector objc-optparmlist
7426 objc-keyword-selector objc-optparmlist
7429 objc-keyword-selector:
7431 objc-keyword-selector objc-keyword-decl
7434 objc-selector : ( objc-type-name ) identifier
7435 objc-selector : identifier
7436 : ( objc-type-name ) identifier
7440 objc-optparms objc-optellipsis
7444 objc-opt-parms , parameter-declaration
7452 c_parser_objc_method_decl (c_parser
*parser
, bool is_class_method
,
7453 tree
*attributes
, tree
*expr
)
7455 tree type
= NULL_TREE
;
7457 tree parms
= NULL_TREE
;
7458 bool ellipsis
= false;
7459 bool attr_err
= false;
7461 *attributes
= NULL_TREE
;
7462 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
7464 c_parser_consume_token (parser
);
7465 type
= c_parser_objc_type_name (parser
);
7466 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7468 sel
= c_parser_objc_selector (parser
);
7469 /* If there is no selector, or a colon follows, we have an
7470 objc-keyword-selector. If there is a selector, and a colon does
7471 not follow, that selector ends the objc-method-decl. */
7472 if (!sel
|| c_parser_next_token_is (parser
, CPP_COLON
))
7475 tree list
= NULL_TREE
;
7478 tree atype
= NULL_TREE
, id
, keyworddecl
;
7479 tree param_attr
= NULL_TREE
;
7480 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
7482 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
7484 c_parser_consume_token (parser
);
7485 atype
= c_parser_objc_type_name (parser
);
7486 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7489 /* New ObjC allows attributes on method parameters. */
7490 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
7491 param_attr
= c_parser_attributes (parser
);
7492 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7494 c_parser_error (parser
, "expected identifier");
7495 return error_mark_node
;
7497 id
= c_parser_peek_token (parser
)->value
;
7498 c_parser_consume_token (parser
);
7499 keyworddecl
= objc_build_keyword_decl (tsel
, atype
, id
, param_attr
);
7500 list
= chainon (list
, keyworddecl
);
7501 tsel
= c_parser_objc_selector (parser
);
7502 if (!tsel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
7506 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
7508 /* Parse the optional parameter list. Optional Objective-C
7509 method parameters follow the C syntax, and may include '...'
7510 to denote a variable number of arguments. */
7511 parms
= make_node (TREE_LIST
);
7512 while (c_parser_next_token_is (parser
, CPP_COMMA
))
7514 struct c_parm
*parm
;
7515 c_parser_consume_token (parser
);
7516 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
7519 c_parser_consume_token (parser
);
7520 attr_err
|= c_parser_objc_maybe_method_attributes
7521 (parser
, attributes
) ;
7524 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
7527 parms
= chainon (parms
,
7528 build_tree_list (NULL_TREE
, grokparm (parm
, expr
)));
7533 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
7537 c_parser_error (parser
, "objective-c method declaration is expected");
7538 return error_mark_node
;
7542 return error_mark_node
;
7544 return objc_build_method_signature (is_class_method
, type
, sel
, parms
, ellipsis
);
7547 /* Parse an objc-type-name.
7550 objc-type-qualifiers[opt] type-name
7551 objc-type-qualifiers[opt]
7553 objc-type-qualifiers:
7555 objc-type-qualifiers objc-type-qualifier
7557 objc-type-qualifier: one of
7558 in out inout bycopy byref oneway
7562 c_parser_objc_type_name (c_parser
*parser
)
7564 tree quals
= NULL_TREE
;
7565 struct c_type_name
*type_name
= NULL
;
7566 tree type
= NULL_TREE
;
7569 c_token
*token
= c_parser_peek_token (parser
);
7570 if (token
->type
== CPP_KEYWORD
7571 && (token
->keyword
== RID_IN
7572 || token
->keyword
== RID_OUT
7573 || token
->keyword
== RID_INOUT
7574 || token
->keyword
== RID_BYCOPY
7575 || token
->keyword
== RID_BYREF
7576 || token
->keyword
== RID_ONEWAY
))
7578 quals
= chainon (build_tree_list (NULL_TREE
, token
->value
), quals
);
7579 c_parser_consume_token (parser
);
7584 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
7585 type_name
= c_parser_type_name (parser
);
7587 type
= groktypename (type_name
, NULL
, NULL
);
7589 /* If the type is unknown, and error has already been produced and
7590 we need to recover from the error. In that case, use NULL_TREE
7591 for the type, as if no type had been specified; this will use the
7592 default type ('id') which is good for error recovery. */
7593 if (type
== error_mark_node
)
7596 return build_tree_list (quals
, type
);
7599 /* Parse objc-protocol-refs.
7606 c_parser_objc_protocol_refs (c_parser
*parser
)
7608 tree list
= NULL_TREE
;
7609 gcc_assert (c_parser_next_token_is (parser
, CPP_LESS
));
7610 c_parser_consume_token (parser
);
7611 /* Any identifiers, including those declared as type names, are OK
7616 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7618 c_parser_error (parser
, "expected identifier");
7621 id
= c_parser_peek_token (parser
)->value
;
7622 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
7623 c_parser_consume_token (parser
);
7624 if (c_parser_next_token_is (parser
, CPP_COMMA
))
7625 c_parser_consume_token (parser
);
7629 c_parser_require (parser
, CPP_GREATER
, "expected %<>%>");
7633 /* Parse an objc-try-catch-finally-statement.
7635 objc-try-catch-finally-statement:
7636 @try compound-statement objc-catch-list[opt]
7637 @try compound-statement objc-catch-list[opt] @finally compound-statement
7640 @catch ( objc-catch-parameter-declaration ) compound-statement
7641 objc-catch-list @catch ( objc-catch-parameter-declaration ) compound-statement
7643 objc-catch-parameter-declaration:
7644 parameter-declaration
7647 where '...' is to be interpreted literally, that is, it means CPP_ELLIPSIS.
7649 PS: This function is identical to cp_parser_objc_try_catch_finally_statement
7650 for C++. Keep them in sync. */
7653 c_parser_objc_try_catch_finally_statement (c_parser
*parser
)
7655 location_t location
;
7658 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_TRY
));
7659 c_parser_consume_token (parser
);
7660 location
= c_parser_peek_token (parser
)->location
;
7661 objc_maybe_warn_exceptions (location
);
7662 stmt
= c_parser_compound_statement (parser
);
7663 objc_begin_try_stmt (location
, stmt
);
7665 while (c_parser_next_token_is_keyword (parser
, RID_AT_CATCH
))
7667 struct c_parm
*parm
;
7668 tree parameter_declaration
= error_mark_node
;
7669 bool seen_open_paren
= false;
7671 c_parser_consume_token (parser
);
7672 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7673 seen_open_paren
= true;
7674 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
7676 /* We have "@catch (...)" (where the '...' are literally
7677 what is in the code). Skip the '...'.
7678 parameter_declaration is set to NULL_TREE, and
7679 objc_being_catch_clauses() knows that that means
7681 c_parser_consume_token (parser
);
7682 parameter_declaration
= NULL_TREE
;
7686 /* We have "@catch (NSException *exception)" or something
7687 like that. Parse the parameter declaration. */
7688 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
7690 parameter_declaration
= error_mark_node
;
7692 parameter_declaration
= grokparm (parm
, NULL
);
7694 if (seen_open_paren
)
7695 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7698 /* If there was no open parenthesis, we are recovering from
7699 an error, and we are trying to figure out what mistake
7700 the user has made. */
7702 /* If there is an immediate closing parenthesis, the user
7703 probably forgot the opening one (ie, they typed "@catch
7704 NSException *e)". Parse the closing parenthesis and keep
7706 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
7707 c_parser_consume_token (parser
);
7709 /* If these is no immediate closing parenthesis, the user
7710 probably doesn't know that parenthesis are required at
7711 all (ie, they typed "@catch NSException *e"). So, just
7712 forget about the closing parenthesis and keep going. */
7714 objc_begin_catch_clause (parameter_declaration
);
7715 if (c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
7716 c_parser_compound_statement_nostart (parser
);
7717 objc_finish_catch_clause ();
7719 if (c_parser_next_token_is_keyword (parser
, RID_AT_FINALLY
))
7721 c_parser_consume_token (parser
);
7722 location
= c_parser_peek_token (parser
)->location
;
7723 stmt
= c_parser_compound_statement (parser
);
7724 objc_build_finally_clause (location
, stmt
);
7726 objc_finish_try_stmt ();
7729 /* Parse an objc-synchronized-statement.
7731 objc-synchronized-statement:
7732 @synchronized ( expression ) compound-statement
7736 c_parser_objc_synchronized_statement (c_parser
*parser
)
7740 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNCHRONIZED
));
7741 c_parser_consume_token (parser
);
7742 loc
= c_parser_peek_token (parser
)->location
;
7743 objc_maybe_warn_exceptions (loc
);
7744 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7746 expr
= c_parser_expression (parser
).value
;
7747 expr
= c_fully_fold (expr
, false, NULL
);
7748 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7751 expr
= error_mark_node
;
7752 stmt
= c_parser_compound_statement (parser
);
7753 objc_build_synchronized (loc
, expr
, stmt
);
7756 /* Parse an objc-selector; return NULL_TREE without an error if the
7757 next token is not an objc-selector.
7762 enum struct union if else while do for switch case default
7763 break continue return goto asm sizeof typeof __alignof
7764 unsigned long const short volatile signed restrict _Complex
7765 in out inout bycopy byref oneway int char float double void _Bool
7767 ??? Why this selection of keywords but not, for example, storage
7768 class specifiers? */
7771 c_parser_objc_selector (c_parser
*parser
)
7773 c_token
*token
= c_parser_peek_token (parser
);
7774 tree value
= token
->value
;
7775 if (token
->type
== CPP_NAME
)
7777 c_parser_consume_token (parser
);
7780 if (token
->type
!= CPP_KEYWORD
)
7782 switch (token
->keyword
)
7824 c_parser_consume_token (parser
);
7831 /* Parse an objc-selector-arg.
7835 objc-keywordname-list
7837 objc-keywordname-list:
7839 objc-keywordname-list objc-keywordname
7847 c_parser_objc_selector_arg (c_parser
*parser
)
7849 tree sel
= c_parser_objc_selector (parser
);
7850 tree list
= NULL_TREE
;
7851 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
7855 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
7857 list
= chainon (list
, build_tree_list (sel
, NULL_TREE
));
7858 sel
= c_parser_objc_selector (parser
);
7859 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
7865 /* Parse an objc-receiver.
7874 c_parser_objc_receiver (c_parser
*parser
)
7876 if (c_parser_peek_token (parser
)->type
== CPP_NAME
7877 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
7878 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
7880 tree id
= c_parser_peek_token (parser
)->value
;
7881 c_parser_consume_token (parser
);
7882 return objc_get_class_reference (id
);
7884 return c_fully_fold (c_parser_expression (parser
).value
, false, NULL
);
7887 /* Parse objc-message-args.
7891 objc-keywordarg-list
7893 objc-keywordarg-list:
7895 objc-keywordarg-list objc-keywordarg
7898 objc-selector : objc-keywordexpr
7903 c_parser_objc_message_args (c_parser
*parser
)
7905 tree sel
= c_parser_objc_selector (parser
);
7906 tree list
= NULL_TREE
;
7907 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
7912 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
7913 return error_mark_node
;
7914 keywordexpr
= c_parser_objc_keywordexpr (parser
);
7915 list
= chainon (list
, build_tree_list (sel
, keywordexpr
));
7916 sel
= c_parser_objc_selector (parser
);
7917 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
7923 /* Parse an objc-keywordexpr.
7930 c_parser_objc_keywordexpr (c_parser
*parser
)
7933 VEC(tree
,gc
) *expr_list
= c_parser_expr_list (parser
, true, true, NULL
);
7934 if (VEC_length (tree
, expr_list
) == 1)
7936 /* Just return the expression, remove a level of
7938 ret
= VEC_index (tree
, expr_list
, 0);
7942 /* We have a comma expression, we will collapse later. */
7943 ret
= build_tree_list_vec (expr_list
);
7945 release_tree_vector (expr_list
);
7949 /* A check, needed in several places, that ObjC interface, implementation or
7950 method definitions are not prefixed by incorrect items. */
7952 c_parser_objc_diagnose_bad_element_prefix (c_parser
*parser
,
7953 struct c_declspecs
*specs
)
7955 if (!specs
->declspecs_seen_p
|| specs
->non_sc_seen_p
7956 || specs
->typespec_kind
!= ctsk_none
)
7958 c_parser_error (parser
,
7959 "no type or storage class may be specified here,");
7960 c_parser_skip_to_end_of_block_or_statement (parser
);
7966 /* Parse an Objective-C @property declaration. The syntax is:
7968 objc-property-declaration:
7969 '@property' objc-property-attributes[opt] struct-declaration ;
7971 objc-property-attributes:
7972 '(' objc-property-attribute-list ')'
7974 objc-property-attribute-list:
7975 objc-property-attribute
7976 objc-property-attribute-list, objc-property-attribute
7978 objc-property-attribute
7979 'getter' = identifier
7980 'setter' = identifier
7989 @property NSString *name;
7990 @property (readonly) id object;
7991 @property (retain, nonatomic, getter=getTheName) id name;
7992 @property int a, b, c;
7994 PS: This function is identical to cp_parser_objc_at_propery_declaration
7995 for C++. Keep them in sync. */
7997 c_parser_objc_at_property_declaration (c_parser
*parser
)
7999 /* The following variables hold the attributes of the properties as
8000 parsed. They are 'false' or 'NULL_TREE' if the attribute was not
8001 seen. When we see an attribute, we set them to 'true' (if they
8002 are boolean properties) or to the identifier (if they have an
8003 argument, ie, for getter and setter). Note that here we only
8004 parse the list of attributes, check the syntax and accumulate the
8005 attributes that we find. objc_add_property_declaration() will
8006 then process the information. */
8007 bool property_assign
= false;
8008 bool property_copy
= false;
8009 tree property_getter_ident
= NULL_TREE
;
8010 bool property_nonatomic
= false;
8011 bool property_readonly
= false;
8012 bool property_readwrite
= false;
8013 bool property_retain
= false;
8014 tree property_setter_ident
= NULL_TREE
;
8016 /* 'properties' is the list of properties that we read. Usually a
8017 single one, but maybe more (eg, in "@property int a, b, c;" there
8022 loc
= c_parser_peek_token (parser
)->location
;
8023 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
));
8025 c_parser_consume_token (parser
); /* Eat '@property'. */
8027 /* Parse the optional attribute list... */
8028 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8031 c_parser_consume_token (parser
);
8033 /* Property attribute keywords are valid now. */
8034 parser
->objc_property_attr_context
= true;
8038 bool syntax_error
= false;
8039 c_token
*token
= c_parser_peek_token (parser
);
8042 if (token
->type
!= CPP_KEYWORD
)
8044 if (token
->type
== CPP_CLOSE_PAREN
)
8045 c_parser_error (parser
, "expected identifier");
8048 c_parser_consume_token (parser
);
8049 c_parser_error (parser
, "unknown property attribute");
8053 keyword
= token
->keyword
;
8054 c_parser_consume_token (parser
);
8057 case RID_ASSIGN
: property_assign
= true; break;
8058 case RID_COPY
: property_copy
= true; break;
8059 case RID_NONATOMIC
: property_nonatomic
= true; break;
8060 case RID_READONLY
: property_readonly
= true; break;
8061 case RID_READWRITE
: property_readwrite
= true; break;
8062 case RID_RETAIN
: property_retain
= true; break;
8066 if (c_parser_next_token_is_not (parser
, CPP_EQ
))
8068 if (keyword
== RID_GETTER
)
8069 c_parser_error (parser
,
8070 "missing %<=%> (after %<getter%> attribute)");
8072 c_parser_error (parser
,
8073 "missing %<=%> (after %<setter%> attribute)");
8074 syntax_error
= true;
8077 c_parser_consume_token (parser
); /* eat the = */
8078 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8080 c_parser_error (parser
, "expected identifier");
8081 syntax_error
= true;
8084 if (keyword
== RID_SETTER
)
8086 if (property_setter_ident
!= NULL_TREE
)
8087 c_parser_error (parser
, "the %<setter%> attribute may only be specified once");
8089 property_setter_ident
= c_parser_peek_token (parser
)->value
;
8090 c_parser_consume_token (parser
);
8091 if (c_parser_next_token_is_not (parser
, CPP_COLON
))
8092 c_parser_error (parser
, "setter name must terminate with %<:%>");
8094 c_parser_consume_token (parser
);
8098 if (property_getter_ident
!= NULL_TREE
)
8099 c_parser_error (parser
, "the %<getter%> attribute may only be specified once");
8101 property_getter_ident
= c_parser_peek_token (parser
)->value
;
8102 c_parser_consume_token (parser
);
8106 c_parser_error (parser
, "unknown property attribute");
8107 syntax_error
= true;
8114 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8115 c_parser_consume_token (parser
);
8119 parser
->objc_property_attr_context
= false;
8120 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8122 /* ... and the property declaration(s). */
8123 properties
= c_parser_struct_declaration (parser
);
8125 if (properties
== error_mark_node
)
8127 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8128 parser
->error
= false;
8132 if (properties
== NULL_TREE
)
8133 c_parser_error (parser
, "expected identifier");
8136 /* Comma-separated properties are chained together in
8137 reverse order; add them one by one. */
8138 properties
= nreverse (properties
);
8140 for (; properties
; properties
= TREE_CHAIN (properties
))
8141 objc_add_property_declaration (loc
, copy_node (properties
),
8142 property_readonly
, property_readwrite
,
8143 property_assign
, property_retain
,
8144 property_copy
, property_nonatomic
,
8145 property_getter_ident
, property_setter_ident
);
8148 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8149 parser
->error
= false;
8152 /* Parse an Objective-C @synthesize declaration. The syntax is:
8154 objc-synthesize-declaration:
8155 @synthesize objc-synthesize-identifier-list ;
8157 objc-synthesize-identifier-list:
8158 objc-synthesize-identifier
8159 objc-synthesize-identifier-list, objc-synthesize-identifier
8161 objc-synthesize-identifier
8163 identifier = identifier
8166 @synthesize MyProperty;
8167 @synthesize OneProperty, AnotherProperty=MyIvar, YetAnotherProperty;
8169 PS: This function is identical to cp_parser_objc_at_synthesize_declaration
8170 for C++. Keep them in sync.
8173 c_parser_objc_at_synthesize_declaration (c_parser
*parser
)
8175 tree list
= NULL_TREE
;
8177 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNTHESIZE
));
8178 loc
= c_parser_peek_token (parser
)->location
;
8180 c_parser_consume_token (parser
);
8183 tree property
, ivar
;
8184 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8186 c_parser_error (parser
, "expected identifier");
8187 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8188 /* Once we find the semicolon, we can resume normal parsing.
8189 We have to reset parser->error manually because
8190 c_parser_skip_until_found() won't reset it for us if the
8191 next token is precisely a semicolon. */
8192 parser
->error
= false;
8195 property
= c_parser_peek_token (parser
)->value
;
8196 c_parser_consume_token (parser
);
8197 if (c_parser_next_token_is (parser
, CPP_EQ
))
8199 c_parser_consume_token (parser
);
8200 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8202 c_parser_error (parser
, "expected identifier");
8203 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8204 parser
->error
= false;
8207 ivar
= c_parser_peek_token (parser
)->value
;
8208 c_parser_consume_token (parser
);
8212 list
= chainon (list
, build_tree_list (ivar
, property
));
8213 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8214 c_parser_consume_token (parser
);
8218 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8219 objc_add_synthesize_declaration (loc
, list
);
8222 /* Parse an Objective-C @dynamic declaration. The syntax is:
8224 objc-dynamic-declaration:
8225 @dynamic identifier-list ;
8228 @dynamic MyProperty;
8229 @dynamic MyProperty, AnotherProperty;
8231 PS: This function is identical to cp_parser_objc_at_dynamic_declaration
8232 for C++. Keep them in sync.
8235 c_parser_objc_at_dynamic_declaration (c_parser
*parser
)
8237 tree list
= NULL_TREE
;
8239 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_DYNAMIC
));
8240 loc
= c_parser_peek_token (parser
)->location
;
8242 c_parser_consume_token (parser
);
8246 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8248 c_parser_error (parser
, "expected identifier");
8249 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8250 parser
->error
= false;
8253 property
= c_parser_peek_token (parser
)->value
;
8254 list
= chainon (list
, build_tree_list (NULL_TREE
, property
));
8255 c_parser_consume_token (parser
);
8256 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8257 c_parser_consume_token (parser
);
8261 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8262 objc_add_dynamic_declaration (loc
, list
);
8266 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
8267 should be considered, statements. ALLOW_STMT is true if we're within
8268 the context of a function and such pragmas are to be allowed. Returns
8269 true if we actually parsed such a pragma. */
8272 c_parser_pragma (c_parser
*parser
, enum pragma_context context
)
8276 id
= c_parser_peek_token (parser
)->pragma_kind
;
8277 gcc_assert (id
!= PRAGMA_NONE
);
8281 case PRAGMA_OMP_BARRIER
:
8282 if (context
!= pragma_compound
)
8284 if (context
== pragma_stmt
)
8285 c_parser_error (parser
, "%<#pragma omp barrier%> may only be "
8286 "used in compound statements");
8289 c_parser_omp_barrier (parser
);
8292 case PRAGMA_OMP_FLUSH
:
8293 if (context
!= pragma_compound
)
8295 if (context
== pragma_stmt
)
8296 c_parser_error (parser
, "%<#pragma omp flush%> may only be "
8297 "used in compound statements");
8300 c_parser_omp_flush (parser
);
8303 case PRAGMA_OMP_TASKWAIT
:
8304 if (context
!= pragma_compound
)
8306 if (context
== pragma_stmt
)
8307 c_parser_error (parser
, "%<#pragma omp taskwait%> may only be "
8308 "used in compound statements");
8311 c_parser_omp_taskwait (parser
);
8314 case PRAGMA_OMP_TASKYIELD
:
8315 if (context
!= pragma_compound
)
8317 if (context
== pragma_stmt
)
8318 c_parser_error (parser
, "%<#pragma omp taskyield%> may only be "
8319 "used in compound statements");
8322 c_parser_omp_taskyield (parser
);
8325 case PRAGMA_OMP_THREADPRIVATE
:
8326 c_parser_omp_threadprivate (parser
);
8329 case PRAGMA_OMP_SECTION
:
8330 error_at (c_parser_peek_token (parser
)->location
,
8331 "%<#pragma omp section%> may only be used in "
8332 "%<#pragma omp sections%> construct");
8333 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
8336 case PRAGMA_GCC_PCH_PREPROCESS
:
8337 c_parser_error (parser
, "%<#pragma GCC pch_preprocess%> must be first");
8338 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
8342 if (id
< PRAGMA_FIRST_EXTERNAL
)
8344 if (context
== pragma_external
)
8347 c_parser_error (parser
, "expected declaration specifiers");
8348 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
8351 c_parser_omp_construct (parser
);
8357 c_parser_consume_pragma (parser
);
8358 c_invoke_pragma_handler (id
);
8360 /* Skip to EOL, but suppress any error message. Those will have been
8361 generated by the handler routine through calling error, as opposed
8362 to calling c_parser_error. */
8363 parser
->error
= true;
8364 c_parser_skip_to_pragma_eol (parser
);
8369 /* The interface the pragma parsers have to the lexer. */
8372 pragma_lex (tree
*value
)
8374 c_token
*tok
= c_parser_peek_token (the_parser
);
8375 enum cpp_ttype ret
= tok
->type
;
8377 *value
= tok
->value
;
8378 if (ret
== CPP_PRAGMA_EOL
|| ret
== CPP_EOF
)
8382 if (ret
== CPP_KEYWORD
)
8384 c_parser_consume_token (the_parser
);
8391 c_parser_pragma_pch_preprocess (c_parser
*parser
)
8395 c_parser_consume_pragma (parser
);
8396 if (c_parser_next_token_is (parser
, CPP_STRING
))
8398 name
= c_parser_peek_token (parser
)->value
;
8399 c_parser_consume_token (parser
);
8402 c_parser_error (parser
, "expected string literal");
8403 c_parser_skip_to_pragma_eol (parser
);
8406 c_common_pch_pragma (parse_in
, TREE_STRING_POINTER (name
));
8409 /* OpenMP 2.5 parsing routines. */
8411 /* Returns name of the next clause.
8412 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
8413 the token is not consumed. Otherwise appropriate pragma_omp_clause is
8414 returned and the token is consumed. */
8416 static pragma_omp_clause
8417 c_parser_omp_clause_name (c_parser
*parser
)
8419 pragma_omp_clause result
= PRAGMA_OMP_CLAUSE_NONE
;
8421 if (c_parser_next_token_is_keyword (parser
, RID_IF
))
8422 result
= PRAGMA_OMP_CLAUSE_IF
;
8423 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
8424 result
= PRAGMA_OMP_CLAUSE_DEFAULT
;
8425 else if (c_parser_next_token_is (parser
, CPP_NAME
))
8427 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
8432 if (!strcmp ("collapse", p
))
8433 result
= PRAGMA_OMP_CLAUSE_COLLAPSE
;
8434 else if (!strcmp ("copyin", p
))
8435 result
= PRAGMA_OMP_CLAUSE_COPYIN
;
8436 else if (!strcmp ("copyprivate", p
))
8437 result
= PRAGMA_OMP_CLAUSE_COPYPRIVATE
;
8440 if (!strcmp ("final", p
))
8441 result
= PRAGMA_OMP_CLAUSE_FINAL
;
8442 else if (!strcmp ("firstprivate", p
))
8443 result
= PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
;
8446 if (!strcmp ("lastprivate", p
))
8447 result
= PRAGMA_OMP_CLAUSE_LASTPRIVATE
;
8450 if (!strcmp ("mergeable", p
))
8451 result
= PRAGMA_OMP_CLAUSE_MERGEABLE
;
8454 if (!strcmp ("nowait", p
))
8455 result
= PRAGMA_OMP_CLAUSE_NOWAIT
;
8456 else if (!strcmp ("num_threads", p
))
8457 result
= PRAGMA_OMP_CLAUSE_NUM_THREADS
;
8460 if (!strcmp ("ordered", p
))
8461 result
= PRAGMA_OMP_CLAUSE_ORDERED
;
8464 if (!strcmp ("private", p
))
8465 result
= PRAGMA_OMP_CLAUSE_PRIVATE
;
8468 if (!strcmp ("reduction", p
))
8469 result
= PRAGMA_OMP_CLAUSE_REDUCTION
;
8472 if (!strcmp ("schedule", p
))
8473 result
= PRAGMA_OMP_CLAUSE_SCHEDULE
;
8474 else if (!strcmp ("shared", p
))
8475 result
= PRAGMA_OMP_CLAUSE_SHARED
;
8478 if (!strcmp ("untied", p
))
8479 result
= PRAGMA_OMP_CLAUSE_UNTIED
;
8484 if (result
!= PRAGMA_OMP_CLAUSE_NONE
)
8485 c_parser_consume_token (parser
);
8490 /* Validate that a clause of the given type does not already exist. */
8493 check_no_duplicate_clause (tree clauses
, enum omp_clause_code code
,
8498 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
8499 if (OMP_CLAUSE_CODE (c
) == code
)
8501 location_t loc
= OMP_CLAUSE_LOCATION (c
);
8502 error_at (loc
, "too many %qs clauses", name
);
8510 variable-list , identifier
8512 If KIND is nonzero, create the appropriate node and install the
8513 decl in OMP_CLAUSE_DECL and add the node to the head of the list.
8514 If KIND is nonzero, CLAUSE_LOC is the location of the clause.
8516 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
8517 return the list created. */
8520 c_parser_omp_variable_list (c_parser
*parser
,
8521 location_t clause_loc
,
8522 enum omp_clause_code kind
,
8525 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
8526 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
8527 c_parser_error (parser
, "expected identifier");
8529 while (c_parser_next_token_is (parser
, CPP_NAME
)
8530 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
8532 tree t
= lookup_name (c_parser_peek_token (parser
)->value
);
8535 undeclared_variable (c_parser_peek_token (parser
)->location
,
8536 c_parser_peek_token (parser
)->value
);
8537 else if (t
== error_mark_node
)
8541 tree u
= build_omp_clause (clause_loc
, kind
);
8542 OMP_CLAUSE_DECL (u
) = t
;
8543 OMP_CLAUSE_CHAIN (u
) = list
;
8547 list
= tree_cons (t
, NULL_TREE
, list
);
8549 c_parser_consume_token (parser
);
8551 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
8554 c_parser_consume_token (parser
);
8560 /* Similarly, but expect leading and trailing parenthesis. This is a very
8561 common case for omp clauses. */
8564 c_parser_omp_var_list_parens (c_parser
*parser
, enum omp_clause_code kind
,
8567 /* The clauses location. */
8568 location_t loc
= c_parser_peek_token (parser
)->location
;
8570 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8572 list
= c_parser_omp_variable_list (parser
, loc
, kind
, list
);
8573 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8579 collapse ( constant-expression ) */
8582 c_parser_omp_clause_collapse (c_parser
*parser
, tree list
)
8584 tree c
, num
= error_mark_node
;
8588 check_no_duplicate_clause (list
, OMP_CLAUSE_COLLAPSE
, "collapse");
8590 loc
= c_parser_peek_token (parser
)->location
;
8591 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8593 num
= c_parser_expr_no_commas (parser
, NULL
).value
;
8594 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8596 if (num
== error_mark_node
)
8598 if (!INTEGRAL_TYPE_P (TREE_TYPE (num
))
8599 || !host_integerp (num
, 0)
8600 || (n
= tree_low_cst (num
, 0)) <= 0
8604 "collapse argument needs positive constant integer expression");
8607 c
= build_omp_clause (loc
, OMP_CLAUSE_COLLAPSE
);
8608 OMP_CLAUSE_COLLAPSE_EXPR (c
) = num
;
8609 OMP_CLAUSE_CHAIN (c
) = list
;
8614 copyin ( variable-list ) */
8617 c_parser_omp_clause_copyin (c_parser
*parser
, tree list
)
8619 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYIN
, list
);
8623 copyprivate ( variable-list ) */
8626 c_parser_omp_clause_copyprivate (c_parser
*parser
, tree list
)
8628 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYPRIVATE
, list
);
8632 default ( shared | none ) */
8635 c_parser_omp_clause_default (c_parser
*parser
, tree list
)
8637 enum omp_clause_default_kind kind
= OMP_CLAUSE_DEFAULT_UNSPECIFIED
;
8638 location_t loc
= c_parser_peek_token (parser
)->location
;
8641 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8643 if (c_parser_next_token_is (parser
, CPP_NAME
))
8645 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
8650 if (strcmp ("none", p
) != 0)
8652 kind
= OMP_CLAUSE_DEFAULT_NONE
;
8656 if (strcmp ("shared", p
) != 0)
8658 kind
= OMP_CLAUSE_DEFAULT_SHARED
;
8665 c_parser_consume_token (parser
);
8670 c_parser_error (parser
, "expected %<none%> or %<shared%>");
8672 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8674 if (kind
== OMP_CLAUSE_DEFAULT_UNSPECIFIED
)
8677 check_no_duplicate_clause (list
, OMP_CLAUSE_DEFAULT
, "default");
8678 c
= build_omp_clause (loc
, OMP_CLAUSE_DEFAULT
);
8679 OMP_CLAUSE_CHAIN (c
) = list
;
8680 OMP_CLAUSE_DEFAULT_KIND (c
) = kind
;
8686 firstprivate ( variable-list ) */
8689 c_parser_omp_clause_firstprivate (c_parser
*parser
, tree list
)
8691 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FIRSTPRIVATE
, list
);
8695 final ( expression ) */
8698 c_parser_omp_clause_final (c_parser
*parser
, tree list
)
8700 location_t loc
= c_parser_peek_token (parser
)->location
;
8701 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8703 tree t
= c_parser_paren_condition (parser
);
8706 check_no_duplicate_clause (list
, OMP_CLAUSE_FINAL
, "final");
8708 c
= build_omp_clause (loc
, OMP_CLAUSE_FINAL
);
8709 OMP_CLAUSE_FINAL_EXPR (c
) = t
;
8710 OMP_CLAUSE_CHAIN (c
) = list
;
8714 c_parser_error (parser
, "expected %<(%>");
8720 if ( expression ) */
8723 c_parser_omp_clause_if (c_parser
*parser
, tree list
)
8725 location_t loc
= c_parser_peek_token (parser
)->location
;
8726 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8728 tree t
= c_parser_paren_condition (parser
);
8731 check_no_duplicate_clause (list
, OMP_CLAUSE_IF
, "if");
8733 c
= build_omp_clause (loc
, OMP_CLAUSE_IF
);
8734 OMP_CLAUSE_IF_EXPR (c
) = t
;
8735 OMP_CLAUSE_CHAIN (c
) = list
;
8739 c_parser_error (parser
, "expected %<(%>");
8745 lastprivate ( variable-list ) */
8748 c_parser_omp_clause_lastprivate (c_parser
*parser
, tree list
)
8750 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_LASTPRIVATE
, list
);
8757 c_parser_omp_clause_mergeable (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
8761 /* FIXME: Should we allow duplicates? */
8762 check_no_duplicate_clause (list
, OMP_CLAUSE_MERGEABLE
, "mergeable");
8764 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
8765 OMP_CLAUSE_MERGEABLE
);
8766 OMP_CLAUSE_CHAIN (c
) = list
;
8775 c_parser_omp_clause_nowait (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
8778 location_t loc
= c_parser_peek_token (parser
)->location
;
8780 check_no_duplicate_clause (list
, OMP_CLAUSE_NOWAIT
, "nowait");
8782 c
= build_omp_clause (loc
, OMP_CLAUSE_NOWAIT
);
8783 OMP_CLAUSE_CHAIN (c
) = list
;
8788 num_threads ( expression ) */
8791 c_parser_omp_clause_num_threads (c_parser
*parser
, tree list
)
8793 location_t num_threads_loc
= c_parser_peek_token (parser
)->location
;
8794 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8796 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
8797 tree c
, t
= c_parser_expression (parser
).value
;
8798 t
= c_fully_fold (t
, false, NULL
);
8800 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8802 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
8804 c_parser_error (parser
, "expected integer expression");
8808 /* Attempt to statically determine when the number isn't positive. */
8809 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
8810 build_int_cst (TREE_TYPE (t
), 0));
8811 if (CAN_HAVE_LOCATION_P (c
))
8812 SET_EXPR_LOCATION (c
, expr_loc
);
8813 if (c
== boolean_true_node
)
8815 warning_at (expr_loc
, 0,
8816 "%<num_threads%> value must be positive");
8817 t
= integer_one_node
;
8820 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_THREADS
, "num_threads");
8822 c
= build_omp_clause (num_threads_loc
, OMP_CLAUSE_NUM_THREADS
);
8823 OMP_CLAUSE_NUM_THREADS_EXPR (c
) = t
;
8824 OMP_CLAUSE_CHAIN (c
) = list
;
8835 c_parser_omp_clause_ordered (c_parser
*parser
, tree list
)
8839 check_no_duplicate_clause (list
, OMP_CLAUSE_ORDERED
, "ordered");
8841 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
8842 OMP_CLAUSE_ORDERED
);
8843 OMP_CLAUSE_CHAIN (c
) = list
;
8849 private ( variable-list ) */
8852 c_parser_omp_clause_private (c_parser
*parser
, tree list
)
8854 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_PRIVATE
, list
);
8858 reduction ( reduction-operator : variable-list )
8861 One of: + * - & ^ | && ||
8866 One of: + * - & ^ | && || max min */
8869 c_parser_omp_clause_reduction (c_parser
*parser
, tree list
)
8871 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
8872 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8874 enum tree_code code
;
8876 switch (c_parser_peek_token (parser
)->type
)
8888 code
= BIT_AND_EXPR
;
8891 code
= BIT_XOR_EXPR
;
8894 code
= BIT_IOR_EXPR
;
8897 code
= TRUTH_ANDIF_EXPR
;
8900 code
= TRUTH_ORIF_EXPR
;
8905 = IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
8906 if (strcmp (p
, "min") == 0)
8911 if (strcmp (p
, "max") == 0)
8919 c_parser_error (parser
,
8920 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
8921 "%<^%>, %<|%>, %<&&%>, %<||%>, %<min%> or %<max%>");
8922 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
8925 c_parser_consume_token (parser
);
8926 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
8930 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
8931 OMP_CLAUSE_REDUCTION
, list
);
8932 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
8933 OMP_CLAUSE_REDUCTION_CODE (c
) = code
;
8937 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8943 schedule ( schedule-kind )
8944 schedule ( schedule-kind , expression )
8947 static | dynamic | guided | runtime | auto
8951 c_parser_omp_clause_schedule (c_parser
*parser
, tree list
)
8954 location_t loc
= c_parser_peek_token (parser
)->location
;
8956 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8959 c
= build_omp_clause (loc
, OMP_CLAUSE_SCHEDULE
);
8961 if (c_parser_next_token_is (parser
, CPP_NAME
))
8963 tree kind
= c_parser_peek_token (parser
)->value
;
8964 const char *p
= IDENTIFIER_POINTER (kind
);
8969 if (strcmp ("dynamic", p
) != 0)
8971 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_DYNAMIC
;
8975 if (strcmp ("guided", p
) != 0)
8977 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_GUIDED
;
8981 if (strcmp ("runtime", p
) != 0)
8983 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_RUNTIME
;
8990 else if (c_parser_next_token_is_keyword (parser
, RID_STATIC
))
8991 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_STATIC
;
8992 else if (c_parser_next_token_is_keyword (parser
, RID_AUTO
))
8993 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_AUTO
;
8997 c_parser_consume_token (parser
);
8998 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9001 c_parser_consume_token (parser
);
9003 here
= c_parser_peek_token (parser
)->location
;
9004 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
9005 t
= c_fully_fold (t
, false, NULL
);
9007 if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_RUNTIME
)
9008 error_at (here
, "schedule %<runtime%> does not take "
9009 "a %<chunk_size%> parameter");
9010 else if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_AUTO
)
9012 "schedule %<auto%> does not take "
9013 "a %<chunk_size%> parameter");
9014 else if (TREE_CODE (TREE_TYPE (t
)) == INTEGER_TYPE
)
9015 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
) = t
;
9017 c_parser_error (parser
, "expected integer expression");
9019 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9022 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
9023 "expected %<,%> or %<)%>");
9025 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
9026 OMP_CLAUSE_CHAIN (c
) = list
;
9030 c_parser_error (parser
, "invalid schedule kind");
9031 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
9036 shared ( variable-list ) */
9039 c_parser_omp_clause_shared (c_parser
*parser
, tree list
)
9041 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_SHARED
, list
);
9048 c_parser_omp_clause_untied (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
9052 /* FIXME: Should we allow duplicates? */
9053 check_no_duplicate_clause (list
, OMP_CLAUSE_UNTIED
, "untied");
9055 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
9057 OMP_CLAUSE_CHAIN (c
) = list
;
9062 /* Parse all OpenMP clauses. The set clauses allowed by the directive
9063 is a bitmask in MASK. Return the list of clauses found; the result
9064 of clause default goes in *pdefault. */
9067 c_parser_omp_all_clauses (c_parser
*parser
, unsigned int mask
,
9070 tree clauses
= NULL
;
9073 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
9076 pragma_omp_clause c_kind
;
9078 tree prev
= clauses
;
9080 if (!first
&& c_parser_next_token_is (parser
, CPP_COMMA
))
9081 c_parser_consume_token (parser
);
9084 here
= c_parser_peek_token (parser
)->location
;
9085 c_kind
= c_parser_omp_clause_name (parser
);
9089 case PRAGMA_OMP_CLAUSE_COLLAPSE
:
9090 clauses
= c_parser_omp_clause_collapse (parser
, clauses
);
9091 c_name
= "collapse";
9093 case PRAGMA_OMP_CLAUSE_COPYIN
:
9094 clauses
= c_parser_omp_clause_copyin (parser
, clauses
);
9097 case PRAGMA_OMP_CLAUSE_COPYPRIVATE
:
9098 clauses
= c_parser_omp_clause_copyprivate (parser
, clauses
);
9099 c_name
= "copyprivate";
9101 case PRAGMA_OMP_CLAUSE_DEFAULT
:
9102 clauses
= c_parser_omp_clause_default (parser
, clauses
);
9105 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
:
9106 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
9107 c_name
= "firstprivate";
9109 case PRAGMA_OMP_CLAUSE_FINAL
:
9110 clauses
= c_parser_omp_clause_final (parser
, clauses
);
9113 case PRAGMA_OMP_CLAUSE_IF
:
9114 clauses
= c_parser_omp_clause_if (parser
, clauses
);
9117 case PRAGMA_OMP_CLAUSE_LASTPRIVATE
:
9118 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
9119 c_name
= "lastprivate";
9121 case PRAGMA_OMP_CLAUSE_MERGEABLE
:
9122 clauses
= c_parser_omp_clause_mergeable (parser
, clauses
);
9123 c_name
= "mergeable";
9125 case PRAGMA_OMP_CLAUSE_NOWAIT
:
9126 clauses
= c_parser_omp_clause_nowait (parser
, clauses
);
9129 case PRAGMA_OMP_CLAUSE_NUM_THREADS
:
9130 clauses
= c_parser_omp_clause_num_threads (parser
, clauses
);
9131 c_name
= "num_threads";
9133 case PRAGMA_OMP_CLAUSE_ORDERED
:
9134 clauses
= c_parser_omp_clause_ordered (parser
, clauses
);
9137 case PRAGMA_OMP_CLAUSE_PRIVATE
:
9138 clauses
= c_parser_omp_clause_private (parser
, clauses
);
9141 case PRAGMA_OMP_CLAUSE_REDUCTION
:
9142 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
9143 c_name
= "reduction";
9145 case PRAGMA_OMP_CLAUSE_SCHEDULE
:
9146 clauses
= c_parser_omp_clause_schedule (parser
, clauses
);
9147 c_name
= "schedule";
9149 case PRAGMA_OMP_CLAUSE_SHARED
:
9150 clauses
= c_parser_omp_clause_shared (parser
, clauses
);
9153 case PRAGMA_OMP_CLAUSE_UNTIED
:
9154 clauses
= c_parser_omp_clause_untied (parser
, clauses
);
9158 c_parser_error (parser
, "expected %<#pragma omp%> clause");
9162 if (((mask
>> c_kind
) & 1) == 0 && !parser
->error
)
9164 /* Remove the invalid clause(s) from the list to avoid
9165 confusing the rest of the compiler. */
9167 error_at (here
, "%qs is not valid for %qs", c_name
, where
);
9172 c_parser_skip_to_pragma_eol (parser
);
9174 return c_finish_omp_clauses (clauses
);
9181 In practice, we're also interested in adding the statement to an
9182 outer node. So it is convenient if we work around the fact that
9183 c_parser_statement calls add_stmt. */
9186 c_parser_omp_structured_block (c_parser
*parser
)
9188 tree stmt
= push_stmt_list ();
9189 c_parser_statement (parser
);
9190 return pop_stmt_list (stmt
);
9194 # pragma omp atomic new-line
9198 x binop= expr | x++ | ++x | x-- | --x
9200 +, *, -, /, &, ^, |, <<, >>
9202 where x is an lvalue expression with scalar type.
9205 # pragma omp atomic new-line
9208 # pragma omp atomic read new-line
9211 # pragma omp atomic write new-line
9214 # pragma omp atomic update new-line
9217 # pragma omp atomic capture new-line
9220 # pragma omp atomic capture new-line
9228 expression-stmt | x = x binop expr
9230 v = x binop= expr | v = x++ | v = ++x | v = x-- | v = --x
9232 { v = x; update-stmt; } | { update-stmt; v = x; }
9234 where x and v are lvalue expressions with scalar type.
9236 LOC is the location of the #pragma token. */
9239 c_parser_omp_atomic (location_t loc
, c_parser
*parser
)
9241 tree lhs
= NULL_TREE
, rhs
= NULL_TREE
, v
= NULL_TREE
;
9242 tree lhs1
= NULL_TREE
, rhs1
= NULL_TREE
;
9243 tree stmt
, orig_lhs
;
9244 enum tree_code code
= OMP_ATOMIC
, opcode
= NOP_EXPR
;
9245 struct c_expr rhs_expr
;
9246 bool structured_block
= false;
9248 if (c_parser_next_token_is (parser
, CPP_NAME
))
9250 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
9252 if (!strcmp (p
, "read"))
9253 code
= OMP_ATOMIC_READ
;
9254 else if (!strcmp (p
, "write"))
9256 else if (!strcmp (p
, "update"))
9258 else if (!strcmp (p
, "capture"))
9259 code
= OMP_ATOMIC_CAPTURE_NEW
;
9263 c_parser_consume_token (parser
);
9265 c_parser_skip_to_pragma_eol (parser
);
9269 case OMP_ATOMIC_READ
:
9270 case NOP_EXPR
: /* atomic write */
9271 v
= c_parser_unary_expression (parser
).value
;
9272 v
= c_fully_fold (v
, false, NULL
);
9273 if (v
== error_mark_node
)
9275 loc
= c_parser_peek_token (parser
)->location
;
9276 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
9278 if (code
== NOP_EXPR
)
9279 lhs
= c_parser_expression (parser
).value
;
9281 lhs
= c_parser_unary_expression (parser
).value
;
9282 lhs
= c_fully_fold (lhs
, false, NULL
);
9283 if (lhs
== error_mark_node
)
9285 if (code
== NOP_EXPR
)
9287 /* atomic write is represented by OMP_ATOMIC with NOP_EXPR
9295 case OMP_ATOMIC_CAPTURE_NEW
:
9296 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
9298 c_parser_consume_token (parser
);
9299 structured_block
= true;
9303 v
= c_parser_unary_expression (parser
).value
;
9304 v
= c_fully_fold (v
, false, NULL
);
9305 if (v
== error_mark_node
)
9307 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
9315 /* For structured_block case we don't know yet whether
9316 old or new x should be captured. */
9318 lhs
= c_parser_unary_expression (parser
).value
;
9319 lhs
= c_fully_fold (lhs
, false, NULL
);
9321 switch (TREE_CODE (lhs
))
9325 c_parser_skip_to_end_of_block_or_statement (parser
);
9326 if (structured_block
)
9328 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
9329 c_parser_consume_token (parser
);
9330 else if (code
== OMP_ATOMIC_CAPTURE_NEW
)
9332 c_parser_skip_to_end_of_block_or_statement (parser
);
9333 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
9334 c_parser_consume_token (parser
);
9339 case POSTINCREMENT_EXPR
:
9340 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
9341 code
= OMP_ATOMIC_CAPTURE_OLD
;
9343 case PREINCREMENT_EXPR
:
9344 lhs
= TREE_OPERAND (lhs
, 0);
9346 rhs
= integer_one_node
;
9349 case POSTDECREMENT_EXPR
:
9350 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
9351 code
= OMP_ATOMIC_CAPTURE_OLD
;
9353 case PREDECREMENT_EXPR
:
9354 lhs
= TREE_OPERAND (lhs
, 0);
9355 opcode
= MINUS_EXPR
;
9356 rhs
= integer_one_node
;
9360 if (TREE_CODE (TREE_OPERAND (lhs
, 0)) == SAVE_EXPR
9361 && TREE_CODE (TREE_OPERAND (lhs
, 1)) == COMPOUND_EXPR
9362 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0)) == MODIFY_EXPR
9363 && TREE_OPERAND (TREE_OPERAND (lhs
, 1), 1) == TREE_OPERAND (lhs
, 0)
9364 && TREE_CODE (TREE_TYPE (TREE_OPERAND (TREE_OPERAND
9365 (TREE_OPERAND (lhs
, 1), 0), 0)))
9367 /* Undo effects of boolean_increment for post {in,de}crement. */
9368 lhs
= TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0);
9371 if (TREE_CODE (lhs
) == MODIFY_EXPR
9372 && TREE_CODE (TREE_TYPE (TREE_OPERAND (lhs
, 0))) == BOOLEAN_TYPE
)
9374 /* Undo effects of boolean_increment. */
9375 if (integer_onep (TREE_OPERAND (lhs
, 1)))
9377 /* This is pre or post increment. */
9378 rhs
= TREE_OPERAND (lhs
, 1);
9379 lhs
= TREE_OPERAND (lhs
, 0);
9381 if (code
== OMP_ATOMIC_CAPTURE_NEW
9382 && !structured_block
9383 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
9384 code
= OMP_ATOMIC_CAPTURE_OLD
;
9387 if (TREE_CODE (TREE_OPERAND (lhs
, 1)) == TRUTH_NOT_EXPR
9388 && TREE_OPERAND (lhs
, 0)
9389 == TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0))
9391 /* This is pre or post decrement. */
9392 rhs
= TREE_OPERAND (lhs
, 1);
9393 lhs
= TREE_OPERAND (lhs
, 0);
9395 if (code
== OMP_ATOMIC_CAPTURE_NEW
9396 && !structured_block
9397 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
9398 code
= OMP_ATOMIC_CAPTURE_OLD
;
9404 switch (c_parser_peek_token (parser
)->type
)
9410 opcode
= TRUNC_DIV_EXPR
;
9416 opcode
= MINUS_EXPR
;
9419 opcode
= LSHIFT_EXPR
;
9422 opcode
= RSHIFT_EXPR
;
9425 opcode
= BIT_AND_EXPR
;
9428 opcode
= BIT_IOR_EXPR
;
9431 opcode
= BIT_XOR_EXPR
;
9434 if (structured_block
|| code
== OMP_ATOMIC
)
9436 location_t aloc
= c_parser_peek_token (parser
)->location
;
9438 enum c_parser_prec oprec
= PREC_NONE
;
9440 c_parser_consume_token (parser
);
9441 rhs1
= c_parser_unary_expression (parser
).value
;
9442 rhs1
= c_fully_fold (rhs1
, false, NULL
);
9443 if (rhs1
== error_mark_node
)
9445 switch (c_parser_peek_token (parser
)->type
)
9448 if (code
== OMP_ATOMIC_CAPTURE_NEW
)
9450 code
= OMP_ATOMIC_CAPTURE_OLD
;
9455 c_parser_consume_token (parser
);
9458 c_parser_error (parser
,
9459 "invalid form of %<#pragma omp atomic%>");
9466 opcode
= TRUNC_DIV_EXPR
;
9474 opcode
= MINUS_EXPR
;
9478 opcode
= LSHIFT_EXPR
;
9482 opcode
= RSHIFT_EXPR
;
9486 opcode
= BIT_AND_EXPR
;
9487 oprec
= PREC_BITAND
;
9490 opcode
= BIT_IOR_EXPR
;
9494 opcode
= BIT_XOR_EXPR
;
9495 oprec
= PREC_BITXOR
;
9498 c_parser_error (parser
,
9499 "invalid operator for %<#pragma omp atomic%>");
9503 c_parser_consume_token (parser
);
9504 rhs_loc
= c_parser_peek_token (parser
)->location
;
9505 if (commutative_tree_code (opcode
))
9506 oprec
= (enum c_parser_prec
) (oprec
- 1);
9507 rhs_expr
= c_parser_binary_expression (parser
, NULL
, oprec
);
9508 rhs_expr
= default_function_array_read_conversion (rhs_loc
,
9510 rhs
= rhs_expr
.value
;
9511 rhs
= c_fully_fold (rhs
, false, NULL
);
9516 c_parser_error (parser
,
9517 "invalid operator for %<#pragma omp atomic%>");
9521 /* Arrange to pass the location of the assignment operator to
9522 c_finish_omp_atomic. */
9523 loc
= c_parser_peek_token (parser
)->location
;
9524 c_parser_consume_token (parser
);
9526 location_t rhs_loc
= c_parser_peek_token (parser
)->location
;
9527 rhs_expr
= c_parser_expression (parser
);
9528 rhs_expr
= default_function_array_read_conversion (rhs_loc
, rhs_expr
);
9530 rhs
= rhs_expr
.value
;
9531 rhs
= c_fully_fold (rhs
, false, NULL
);
9535 if (structured_block
&& code
== OMP_ATOMIC_CAPTURE_NEW
)
9537 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
9539 v
= c_parser_unary_expression (parser
).value
;
9540 v
= c_fully_fold (v
, false, NULL
);
9541 if (v
== error_mark_node
)
9543 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
9545 lhs1
= c_parser_unary_expression (parser
).value
;
9546 lhs1
= c_fully_fold (lhs1
, false, NULL
);
9547 if (lhs1
== error_mark_node
)
9550 if (structured_block
)
9552 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9553 c_parser_require (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
9556 stmt
= c_finish_omp_atomic (loc
, code
, opcode
, lhs
, rhs
, v
, lhs1
, rhs1
);
9557 if (stmt
!= error_mark_node
)
9560 if (!structured_block
)
9561 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9566 # pragma omp barrier new-line
9570 c_parser_omp_barrier (c_parser
*parser
)
9572 location_t loc
= c_parser_peek_token (parser
)->location
;
9573 c_parser_consume_pragma (parser
);
9574 c_parser_skip_to_pragma_eol (parser
);
9576 c_finish_omp_barrier (loc
);
9580 # pragma omp critical [(name)] new-line
9583 LOC is the location of the #pragma itself. */
9586 c_parser_omp_critical (location_t loc
, c_parser
*parser
)
9588 tree stmt
, name
= NULL
;
9590 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9592 c_parser_consume_token (parser
);
9593 if (c_parser_next_token_is (parser
, CPP_NAME
))
9595 name
= c_parser_peek_token (parser
)->value
;
9596 c_parser_consume_token (parser
);
9597 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9600 c_parser_error (parser
, "expected identifier");
9602 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
9603 c_parser_error (parser
, "expected %<(%> or end of line");
9604 c_parser_skip_to_pragma_eol (parser
);
9606 stmt
= c_parser_omp_structured_block (parser
);
9607 return c_finish_omp_critical (loc
, stmt
, name
);
9611 # pragma omp flush flush-vars[opt] new-line
9614 ( variable-list ) */
9617 c_parser_omp_flush (c_parser
*parser
)
9619 location_t loc
= c_parser_peek_token (parser
)->location
;
9620 c_parser_consume_pragma (parser
);
9621 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9622 c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
9623 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
9624 c_parser_error (parser
, "expected %<(%> or end of line");
9625 c_parser_skip_to_pragma_eol (parser
);
9627 c_finish_omp_flush (loc
);
9630 /* Parse the restricted form of the for statement allowed by OpenMP.
9631 The real trick here is to determine the loop control variable early
9632 so that we can push a new decl if necessary to make it private.
9633 LOC is the location of the OMP in "#pragma omp". */
9636 c_parser_omp_for_loop (location_t loc
,
9637 c_parser
*parser
, tree clauses
, tree
*par_clauses
)
9639 tree decl
, cond
, incr
, save_break
, save_cont
, body
, init
, stmt
, cl
;
9640 tree declv
, condv
, incrv
, initv
, ret
= NULL
;
9641 bool fail
= false, open_brace_parsed
= false;
9642 int i
, collapse
= 1, nbraces
= 0;
9644 VEC(tree
,gc
) *for_block
= make_tree_vector ();
9646 for (cl
= clauses
; cl
; cl
= OMP_CLAUSE_CHAIN (cl
))
9647 if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_COLLAPSE
)
9648 collapse
= tree_low_cst (OMP_CLAUSE_COLLAPSE_EXPR (cl
), 0);
9650 gcc_assert (collapse
>= 1);
9652 declv
= make_tree_vec (collapse
);
9653 initv
= make_tree_vec (collapse
);
9654 condv
= make_tree_vec (collapse
);
9655 incrv
= make_tree_vec (collapse
);
9657 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
))
9659 c_parser_error (parser
, "for statement expected");
9662 for_loc
= c_parser_peek_token (parser
)->location
;
9663 c_parser_consume_token (parser
);
9665 for (i
= 0; i
< collapse
; i
++)
9669 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9672 /* Parse the initialization declaration or expression. */
9673 if (c_parser_next_tokens_start_declaration (parser
))
9676 VEC_safe_push (tree
, gc
, for_block
, c_begin_compound_stmt (true));
9677 c_parser_declaration_or_fndef (parser
, true, true, true, true, true, NULL
);
9678 decl
= check_for_loop_decls (for_loc
, flag_isoc99
);
9681 if (DECL_INITIAL (decl
) == error_mark_node
)
9682 decl
= error_mark_node
;
9685 else if (c_parser_next_token_is (parser
, CPP_NAME
)
9686 && c_parser_peek_2nd_token (parser
)->type
== CPP_EQ
)
9688 struct c_expr decl_exp
;
9689 struct c_expr init_exp
;
9690 location_t init_loc
;
9692 decl_exp
= c_parser_postfix_expression (parser
);
9693 decl
= decl_exp
.value
;
9695 c_parser_require (parser
, CPP_EQ
, "expected %<=%>");
9697 init_loc
= c_parser_peek_token (parser
)->location
;
9698 init_exp
= c_parser_expr_no_commas (parser
, NULL
);
9699 init_exp
= default_function_array_read_conversion (init_loc
,
9701 init
= build_modify_expr (init_loc
, decl
, decl_exp
.original_type
,
9702 NOP_EXPR
, init_loc
, init_exp
.value
,
9703 init_exp
.original_type
);
9704 init
= c_process_expr_stmt (init_loc
, init
);
9706 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9711 c_parser_error (parser
,
9712 "expected iteration declaration or initialization");
9713 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
9719 /* Parse the loop condition. */
9721 if (c_parser_next_token_is_not (parser
, CPP_SEMICOLON
))
9723 location_t cond_loc
= c_parser_peek_token (parser
)->location
;
9724 struct c_expr cond_expr
= c_parser_binary_expression (parser
, NULL
,
9727 cond
= cond_expr
.value
;
9728 cond
= c_objc_common_truthvalue_conversion (cond_loc
, cond
);
9729 cond
= c_fully_fold (cond
, false, NULL
);
9730 switch (cond_expr
.original_code
)
9738 /* Can't be cond = error_mark_node, because we want to preserve
9739 the location until c_finish_omp_for. */
9740 cond
= build1 (NOP_EXPR
, boolean_type_node
, error_mark_node
);
9743 protected_set_expr_location (cond
, cond_loc
);
9745 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9747 /* Parse the increment expression. */
9749 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_PAREN
))
9751 location_t incr_loc
= c_parser_peek_token (parser
)->location
;
9753 incr
= c_process_expr_stmt (incr_loc
,
9754 c_parser_expression (parser
).value
);
9756 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9758 if (decl
== NULL
|| decl
== error_mark_node
|| init
== error_mark_node
)
9762 TREE_VEC_ELT (declv
, i
) = decl
;
9763 TREE_VEC_ELT (initv
, i
) = init
;
9764 TREE_VEC_ELT (condv
, i
) = cond
;
9765 TREE_VEC_ELT (incrv
, i
) = incr
;
9769 if (i
== collapse
- 1)
9772 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
9773 in between the collapsed for loops to be still considered perfectly
9774 nested. Hopefully the final version clarifies this.
9775 For now handle (multiple) {'s and empty statements. */
9778 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
9780 c_parser_consume_token (parser
);
9783 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
9785 c_parser_consume_token (parser
);
9789 && c_parser_next_token_is (parser
, CPP_SEMICOLON
))
9790 c_parser_consume_token (parser
);
9793 c_parser_error (parser
, "not enough perfectly nested loops");
9796 open_brace_parsed
= true;
9806 nbraces
+= bracecount
;
9809 save_break
= c_break_label
;
9810 c_break_label
= size_one_node
;
9811 save_cont
= c_cont_label
;
9812 c_cont_label
= NULL_TREE
;
9813 body
= push_stmt_list ();
9815 if (open_brace_parsed
)
9817 location_t here
= c_parser_peek_token (parser
)->location
;
9818 stmt
= c_begin_compound_stmt (true);
9819 c_parser_compound_statement_nostart (parser
);
9820 add_stmt (c_end_compound_stmt (here
, stmt
, true));
9823 add_stmt (c_parser_c99_block_statement (parser
));
9826 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_cont_label
);
9827 SET_EXPR_LOCATION (t
, loc
);
9831 body
= pop_stmt_list (body
);
9832 c_break_label
= save_break
;
9833 c_cont_label
= save_cont
;
9837 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
9839 c_parser_consume_token (parser
);
9842 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
9843 c_parser_consume_token (parser
);
9846 c_parser_error (parser
, "collapsed loops not perfectly nested");
9849 location_t here
= c_parser_peek_token (parser
)->location
;
9850 stmt
= c_begin_compound_stmt (true);
9852 c_parser_compound_statement_nostart (parser
);
9853 body
= c_end_compound_stmt (here
, stmt
, true);
9860 /* Only bother calling c_finish_omp_for if we haven't already generated
9861 an error from the initialization parsing. */
9864 stmt
= c_finish_omp_for (loc
, declv
, initv
, condv
, incrv
, body
, NULL
);
9867 if (par_clauses
!= NULL
)
9870 for (c
= par_clauses
; *c
; )
9871 if (OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_FIRSTPRIVATE
9872 && OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_LASTPRIVATE
)
9873 c
= &OMP_CLAUSE_CHAIN (*c
);
9876 for (i
= 0; i
< collapse
; i
++)
9877 if (TREE_VEC_ELT (declv
, i
) == OMP_CLAUSE_DECL (*c
))
9880 c
= &OMP_CLAUSE_CHAIN (*c
);
9881 else if (OMP_CLAUSE_CODE (*c
) == OMP_CLAUSE_FIRSTPRIVATE
)
9884 "iteration variable %qD should not be firstprivate",
9885 OMP_CLAUSE_DECL (*c
));
9886 *c
= OMP_CLAUSE_CHAIN (*c
);
9890 /* Copy lastprivate (decl) clause to OMP_FOR_CLAUSES,
9891 change it to shared (decl) in
9892 OMP_PARALLEL_CLAUSES. */
9893 tree l
= build_omp_clause (OMP_CLAUSE_LOCATION (*c
),
9894 OMP_CLAUSE_LASTPRIVATE
);
9895 OMP_CLAUSE_DECL (l
) = OMP_CLAUSE_DECL (*c
);
9896 OMP_CLAUSE_CHAIN (l
) = clauses
;
9898 OMP_CLAUSE_SET_CODE (*c
, OMP_CLAUSE_SHARED
);
9902 OMP_FOR_CLAUSES (stmt
) = clauses
;
9907 while (!VEC_empty (tree
, for_block
))
9909 /* FIXME diagnostics: LOC below should be the actual location of
9910 this particular for block. We need to build a list of
9911 locations to go along with FOR_BLOCK. */
9912 stmt
= c_end_compound_stmt (loc
, VEC_pop (tree
, for_block
), true);
9915 release_tree_vector (for_block
);
9920 #pragma omp for for-clause[optseq] new-line
9923 LOC is the location of the #pragma token.
9926 #define OMP_FOR_CLAUSE_MASK \
9927 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
9928 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
9929 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
9930 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
9931 | (1u << PRAGMA_OMP_CLAUSE_ORDERED) \
9932 | (1u << PRAGMA_OMP_CLAUSE_SCHEDULE) \
9933 | (1u << PRAGMA_OMP_CLAUSE_COLLAPSE) \
9934 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
9937 c_parser_omp_for (location_t loc
, c_parser
*parser
)
9939 tree block
, clauses
, ret
;
9941 clauses
= c_parser_omp_all_clauses (parser
, OMP_FOR_CLAUSE_MASK
,
9944 block
= c_begin_compound_stmt (true);
9945 ret
= c_parser_omp_for_loop (loc
, parser
, clauses
, NULL
);
9946 block
= c_end_compound_stmt (loc
, block
, true);
9953 # pragma omp master new-line
9956 LOC is the location of the #pragma token.
9960 c_parser_omp_master (location_t loc
, c_parser
*parser
)
9962 c_parser_skip_to_pragma_eol (parser
);
9963 return c_finish_omp_master (loc
, c_parser_omp_structured_block (parser
));
9967 # pragma omp ordered new-line
9970 LOC is the location of the #pragma itself.
9974 c_parser_omp_ordered (location_t loc
, c_parser
*parser
)
9976 c_parser_skip_to_pragma_eol (parser
);
9977 return c_finish_omp_ordered (loc
, c_parser_omp_structured_block (parser
));
9983 { section-sequence }
9986 section-directive[opt] structured-block
9987 section-sequence section-directive structured-block
9989 SECTIONS_LOC is the location of the #pragma omp sections. */
9992 c_parser_omp_sections_scope (location_t sections_loc
, c_parser
*parser
)
9995 bool error_suppress
= false;
9998 loc
= c_parser_peek_token (parser
)->location
;
9999 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
10001 /* Avoid skipping until the end of the block. */
10002 parser
->error
= false;
10006 stmt
= push_stmt_list ();
10008 if (c_parser_peek_token (parser
)->pragma_kind
!= PRAGMA_OMP_SECTION
)
10010 substmt
= push_stmt_list ();
10014 c_parser_statement (parser
);
10016 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
10018 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
10020 if (c_parser_next_token_is (parser
, CPP_EOF
))
10024 substmt
= pop_stmt_list (substmt
);
10025 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
10026 SET_EXPR_LOCATION (substmt
, loc
);
10027 add_stmt (substmt
);
10032 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
10034 if (c_parser_next_token_is (parser
, CPP_EOF
))
10037 loc
= c_parser_peek_token (parser
)->location
;
10038 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
10040 c_parser_consume_pragma (parser
);
10041 c_parser_skip_to_pragma_eol (parser
);
10042 error_suppress
= false;
10044 else if (!error_suppress
)
10046 error_at (loc
, "expected %<#pragma omp section%> or %<}%>");
10047 error_suppress
= true;
10050 substmt
= c_parser_omp_structured_block (parser
);
10051 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
10052 SET_EXPR_LOCATION (substmt
, loc
);
10053 add_stmt (substmt
);
10055 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
,
10056 "expected %<#pragma omp section%> or %<}%>");
10058 substmt
= pop_stmt_list (stmt
);
10060 stmt
= make_node (OMP_SECTIONS
);
10061 SET_EXPR_LOCATION (stmt
, sections_loc
);
10062 TREE_TYPE (stmt
) = void_type_node
;
10063 OMP_SECTIONS_BODY (stmt
) = substmt
;
10065 return add_stmt (stmt
);
10069 # pragma omp sections sections-clause[optseq] newline
10072 LOC is the location of the #pragma token.
10075 #define OMP_SECTIONS_CLAUSE_MASK \
10076 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
10077 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
10078 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
10079 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
10080 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
10083 c_parser_omp_sections (location_t loc
, c_parser
*parser
)
10085 tree block
, clauses
, ret
;
10087 clauses
= c_parser_omp_all_clauses (parser
, OMP_SECTIONS_CLAUSE_MASK
,
10088 "#pragma omp sections");
10090 block
= c_begin_compound_stmt (true);
10091 ret
= c_parser_omp_sections_scope (loc
, parser
);
10093 OMP_SECTIONS_CLAUSES (ret
) = clauses
;
10094 block
= c_end_compound_stmt (loc
, block
, true);
10101 # pragma parallel parallel-clause new-line
10102 # pragma parallel for parallel-for-clause new-line
10103 # pragma parallel sections parallel-sections-clause new-line
10105 LOC is the location of the #pragma token.
10108 #define OMP_PARALLEL_CLAUSE_MASK \
10109 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
10110 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
10111 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
10112 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
10113 | (1u << PRAGMA_OMP_CLAUSE_SHARED) \
10114 | (1u << PRAGMA_OMP_CLAUSE_COPYIN) \
10115 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
10116 | (1u << PRAGMA_OMP_CLAUSE_NUM_THREADS))
10119 c_parser_omp_parallel (location_t loc
, c_parser
*parser
)
10121 enum pragma_kind p_kind
= PRAGMA_OMP_PARALLEL
;
10122 const char *p_name
= "#pragma omp parallel";
10123 tree stmt
, clauses
, par_clause
, ws_clause
, block
;
10124 unsigned int mask
= OMP_PARALLEL_CLAUSE_MASK
;
10126 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
10128 c_parser_consume_token (parser
);
10129 p_kind
= PRAGMA_OMP_PARALLEL_FOR
;
10130 p_name
= "#pragma omp parallel for";
10131 mask
|= OMP_FOR_CLAUSE_MASK
;
10132 mask
&= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT
);
10134 else if (c_parser_next_token_is (parser
, CPP_NAME
))
10136 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10137 if (strcmp (p
, "sections") == 0)
10139 c_parser_consume_token (parser
);
10140 p_kind
= PRAGMA_OMP_PARALLEL_SECTIONS
;
10141 p_name
= "#pragma omp parallel sections";
10142 mask
|= OMP_SECTIONS_CLAUSE_MASK
;
10143 mask
&= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT
);
10147 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
);
10151 case PRAGMA_OMP_PARALLEL
:
10152 block
= c_begin_omp_parallel ();
10153 c_parser_statement (parser
);
10154 stmt
= c_finish_omp_parallel (loc
, clauses
, block
);
10157 case PRAGMA_OMP_PARALLEL_FOR
:
10158 block
= c_begin_omp_parallel ();
10159 c_split_parallel_clauses (loc
, clauses
, &par_clause
, &ws_clause
);
10160 c_parser_omp_for_loop (loc
, parser
, ws_clause
, &par_clause
);
10161 stmt
= c_finish_omp_parallel (loc
, par_clause
, block
);
10162 OMP_PARALLEL_COMBINED (stmt
) = 1;
10165 case PRAGMA_OMP_PARALLEL_SECTIONS
:
10166 block
= c_begin_omp_parallel ();
10167 c_split_parallel_clauses (loc
, clauses
, &par_clause
, &ws_clause
);
10168 stmt
= c_parser_omp_sections_scope (loc
, parser
);
10170 OMP_SECTIONS_CLAUSES (stmt
) = ws_clause
;
10171 stmt
= c_finish_omp_parallel (loc
, par_clause
, block
);
10172 OMP_PARALLEL_COMBINED (stmt
) = 1;
10176 gcc_unreachable ();
10183 # pragma omp single single-clause[optseq] new-line
10186 LOC is the location of the #pragma.
10189 #define OMP_SINGLE_CLAUSE_MASK \
10190 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
10191 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
10192 | (1u << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
10193 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
10196 c_parser_omp_single (location_t loc
, c_parser
*parser
)
10198 tree stmt
= make_node (OMP_SINGLE
);
10199 SET_EXPR_LOCATION (stmt
, loc
);
10200 TREE_TYPE (stmt
) = void_type_node
;
10202 OMP_SINGLE_CLAUSES (stmt
)
10203 = c_parser_omp_all_clauses (parser
, OMP_SINGLE_CLAUSE_MASK
,
10204 "#pragma omp single");
10205 OMP_SINGLE_BODY (stmt
) = c_parser_omp_structured_block (parser
);
10207 return add_stmt (stmt
);
10211 # pragma omp task task-clause[optseq] new-line
10213 LOC is the location of the #pragma.
10216 #define OMP_TASK_CLAUSE_MASK \
10217 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
10218 | (1u << PRAGMA_OMP_CLAUSE_UNTIED) \
10219 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
10220 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
10221 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
10222 | (1u << PRAGMA_OMP_CLAUSE_SHARED) \
10223 | (1u << PRAGMA_OMP_CLAUSE_FINAL) \
10224 | (1u << PRAGMA_OMP_CLAUSE_MERGEABLE))
10227 c_parser_omp_task (location_t loc
, c_parser
*parser
)
10229 tree clauses
, block
;
10231 clauses
= c_parser_omp_all_clauses (parser
, OMP_TASK_CLAUSE_MASK
,
10232 "#pragma omp task");
10234 block
= c_begin_omp_task ();
10235 c_parser_statement (parser
);
10236 return c_finish_omp_task (loc
, clauses
, block
);
10240 # pragma omp taskwait new-line
10244 c_parser_omp_taskwait (c_parser
*parser
)
10246 location_t loc
= c_parser_peek_token (parser
)->location
;
10247 c_parser_consume_pragma (parser
);
10248 c_parser_skip_to_pragma_eol (parser
);
10250 c_finish_omp_taskwait (loc
);
10254 # pragma omp taskyield new-line
10258 c_parser_omp_taskyield (c_parser
*parser
)
10260 location_t loc
= c_parser_peek_token (parser
)->location
;
10261 c_parser_consume_pragma (parser
);
10262 c_parser_skip_to_pragma_eol (parser
);
10264 c_finish_omp_taskyield (loc
);
10267 /* Main entry point to parsing most OpenMP pragmas. */
10270 c_parser_omp_construct (c_parser
*parser
)
10272 enum pragma_kind p_kind
;
10276 loc
= c_parser_peek_token (parser
)->location
;
10277 p_kind
= c_parser_peek_token (parser
)->pragma_kind
;
10278 c_parser_consume_pragma (parser
);
10282 case PRAGMA_OMP_ATOMIC
:
10283 c_parser_omp_atomic (loc
, parser
);
10285 case PRAGMA_OMP_CRITICAL
:
10286 stmt
= c_parser_omp_critical (loc
, parser
);
10288 case PRAGMA_OMP_FOR
:
10289 stmt
= c_parser_omp_for (loc
, parser
);
10291 case PRAGMA_OMP_MASTER
:
10292 stmt
= c_parser_omp_master (loc
, parser
);
10294 case PRAGMA_OMP_ORDERED
:
10295 stmt
= c_parser_omp_ordered (loc
, parser
);
10297 case PRAGMA_OMP_PARALLEL
:
10298 stmt
= c_parser_omp_parallel (loc
, parser
);
10300 case PRAGMA_OMP_SECTIONS
:
10301 stmt
= c_parser_omp_sections (loc
, parser
);
10303 case PRAGMA_OMP_SINGLE
:
10304 stmt
= c_parser_omp_single (loc
, parser
);
10306 case PRAGMA_OMP_TASK
:
10307 stmt
= c_parser_omp_task (loc
, parser
);
10310 gcc_unreachable ();
10314 gcc_assert (EXPR_LOCATION (stmt
) != UNKNOWN_LOCATION
);
10319 # pragma omp threadprivate (variable-list) */
10322 c_parser_omp_threadprivate (c_parser
*parser
)
10327 c_parser_consume_pragma (parser
);
10328 loc
= c_parser_peek_token (parser
)->location
;
10329 vars
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
10331 /* Mark every variable in VARS to be assigned thread local storage. */
10332 for (t
= vars
; t
; t
= TREE_CHAIN (t
))
10334 tree v
= TREE_PURPOSE (t
);
10336 /* FIXME diagnostics: Ideally we should keep individual
10337 locations for all the variables in the var list to make the
10338 following errors more precise. Perhaps
10339 c_parser_omp_var_list_parens() should construct a list of
10340 locations to go along with the var list. */
10342 /* If V had already been marked threadprivate, it doesn't matter
10343 whether it had been used prior to this point. */
10344 if (TREE_CODE (v
) != VAR_DECL
)
10345 error_at (loc
, "%qD is not a variable", v
);
10346 else if (TREE_USED (v
) && !C_DECL_THREADPRIVATE_P (v
))
10347 error_at (loc
, "%qE declared %<threadprivate%> after first use", v
);
10348 else if (! TREE_STATIC (v
) && ! DECL_EXTERNAL (v
))
10349 error_at (loc
, "automatic variable %qE cannot be %<threadprivate%>", v
);
10350 else if (TREE_TYPE (v
) == error_mark_node
)
10352 else if (! COMPLETE_TYPE_P (TREE_TYPE (v
)))
10353 error_at (loc
, "%<threadprivate%> %qE has incomplete type", v
);
10356 if (! DECL_THREAD_LOCAL_P (v
))
10358 DECL_TLS_MODEL (v
) = decl_default_tls_model (v
);
10359 /* If rtl has been already set for this var, call
10360 make_decl_rtl once again, so that encode_section_info
10361 has a chance to look at the new decl flags. */
10362 if (DECL_RTL_SET_P (v
))
10365 C_DECL_THREADPRIVATE_P (v
) = 1;
10369 c_parser_skip_to_pragma_eol (parser
);
10373 /* Parse a single source file. */
10376 c_parse_file (void)
10378 /* Use local storage to begin. If the first token is a pragma, parse it.
10379 If it is #pragma GCC pch_preprocess, then this will load a PCH file
10380 which will cause garbage collection. */
10383 memset (&tparser
, 0, sizeof tparser
);
10384 the_parser
= &tparser
;
10386 if (c_parser_peek_token (&tparser
)->pragma_kind
== PRAGMA_GCC_PCH_PREPROCESS
)
10387 c_parser_pragma_pch_preprocess (&tparser
);
10389 the_parser
= ggc_alloc_c_parser ();
10390 *the_parser
= tparser
;
10392 /* Initialize EH, if we've been told to do so. */
10393 if (flag_exceptions
)
10394 using_eh_for_cleanups ();
10396 c_parser_translation_unit (the_parser
);
10400 #include "gt-c-parser.h"