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
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"
55 #include "c-family/c-common.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
258 if (parser
->objc_pq_context
)
260 token
->type
= CPP_KEYWORD
;
261 token
->keyword
= rid_code
;
264 else if (parser
->objc_could_be_foreach_context
265 && rid_code
== RID_IN
)
267 /* We are in Objective-C, inside a (potential)
268 foreach context (which means after having
269 parsed 'for (', but before having parsed ';'),
270 and we found 'in'. We consider it the keyword
271 which terminates the declaration at the
272 beginning of a foreach-statement. Note that
273 this means you can't use 'in' for anything else
274 in that context; in particular, in Objective-C
275 you can't use 'in' as the name of the running
276 variable in a C for loop. We could potentially
277 try to add code here to disambiguate, but it
278 seems a reasonable limitation.
280 token
->type
= CPP_KEYWORD
;
281 token
->keyword
= rid_code
;
284 /* Else, "pq" keywords outside of the "pq" context are
285 not keywords, and we fall through to the code for
289 else if (c_dialect_objc () && OBJC_IS_PATTR_KEYWORD (rid_code
))
291 /* We found an Objective-C "property attribute" keyword
292 (readonly, copies, getter, setter, ivar). These are
293 only valid in the property context. */
294 if (parser
->objc_property_attr_context
)
296 token
->type
= CPP_KEYWORD
;
297 token
->keyword
= rid_code
;
300 /* Else they are not special keywords.
303 else if (c_dialect_objc ()
304 && (OBJC_IS_AT_KEYWORD (rid_code
)
305 || OBJC_IS_CXX_KEYWORD (rid_code
)))
307 /* We found one of the Objective-C "@" keywords (defs,
308 selector, synchronized, etc) or one of the
309 Objective-C "cxx" keywords (class, private,
310 protected, public, try, catch, throw) without a
311 preceding '@' sign. Do nothing and fall through to
312 the code for normal tokens (in C++ we would still
313 consider the CXX ones keywords, but not in C).
319 token
->type
= CPP_KEYWORD
;
320 token
->keyword
= rid_code
;
325 decl
= lookup_name (token
->value
);
328 if (TREE_CODE (decl
) == TYPE_DECL
)
330 token
->id_kind
= C_ID_TYPENAME
;
334 else if (c_dialect_objc ())
336 tree objc_interface_decl
= objc_is_class_name (token
->value
);
337 /* Objective-C class names are in the same namespace as
338 variables and typedefs, and hence are shadowed by local
340 if (objc_interface_decl
341 && (global_bindings_p ()
342 || (!objc_force_identifier
&& !decl
)))
344 token
->value
= objc_interface_decl
;
345 token
->id_kind
= C_ID_CLASSNAME
;
349 token
->id_kind
= C_ID_ID
;
353 /* This only happens in Objective-C; it must be a keyword. */
354 token
->type
= CPP_KEYWORD
;
355 switch (C_RID_CODE (token
->value
))
357 /* Replace 'class' with '@class', 'private' with '@private',
358 etc. This prevents confusion with the C++ keyword
359 'class', and makes the tokens consistent with other
360 Objective-C 'AT' keywords. For example '@class' is
361 reported as RID_AT_CLASS which is consistent with
362 '@synchronized', which is reported as
365 case RID_CLASS
: token
->keyword
= RID_AT_CLASS
; break;
366 case RID_PRIVATE
: token
->keyword
= RID_AT_PRIVATE
; break;
367 case RID_PROTECTED
: token
->keyword
= RID_AT_PROTECTED
; break;
368 case RID_PUBLIC
: token
->keyword
= RID_AT_PUBLIC
; break;
369 case RID_THROW
: token
->keyword
= RID_AT_THROW
; break;
370 case RID_TRY
: token
->keyword
= RID_AT_TRY
; break;
371 case RID_CATCH
: token
->keyword
= RID_AT_CATCH
; break;
372 default: token
->keyword
= C_RID_CODE (token
->value
);
377 case CPP_CLOSE_PAREN
:
379 /* These tokens may affect the interpretation of any identifiers
380 following, if doing Objective-C. */
381 if (c_dialect_objc ())
382 parser
->objc_need_raw_identifier
= false;
385 /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */
386 token
->pragma_kind
= (enum pragma_kind
) TREE_INT_CST_LOW (token
->value
);
392 timevar_pop (TV_LEX
);
395 /* Return a pointer to the next token from PARSER, reading it in if
398 static inline c_token
*
399 c_parser_peek_token (c_parser
*parser
)
401 if (parser
->tokens_avail
== 0)
403 c_lex_one_token (parser
, &parser
->tokens
[0]);
404 parser
->tokens_avail
= 1;
406 return &parser
->tokens
[0];
409 /* Return true if the next token from PARSER has the indicated
413 c_parser_next_token_is (c_parser
*parser
, enum cpp_ttype type
)
415 return c_parser_peek_token (parser
)->type
== type
;
418 /* Return true if the next token from PARSER does not have the
422 c_parser_next_token_is_not (c_parser
*parser
, enum cpp_ttype type
)
424 return !c_parser_next_token_is (parser
, type
);
427 /* Return true if the next token from PARSER is the indicated
431 c_parser_next_token_is_keyword (c_parser
*parser
, enum rid keyword
)
433 return c_parser_peek_token (parser
)->keyword
== keyword
;
436 /* Return true if TOKEN can start a type name,
439 c_token_starts_typename (c_token
*token
)
444 switch (token
->id_kind
)
453 gcc_assert (c_dialect_objc ());
459 switch (token
->keyword
)
492 if (c_dialect_objc ())
500 /* Return true if the next token from PARSER can start a type name,
503 c_parser_next_token_starts_typename (c_parser
*parser
)
505 c_token
*token
= c_parser_peek_token (parser
);
506 return c_token_starts_typename (token
);
509 /* Return true if TOKEN can start declaration specifiers, false
512 c_token_starts_declspecs (c_token
*token
)
517 switch (token
->id_kind
)
526 gcc_assert (c_dialect_objc ());
532 switch (token
->keyword
)
572 if (c_dialect_objc ())
581 /* Return true if TOKEN can start declaration specifiers or a static
582 assertion, false otherwise. */
584 c_token_starts_declaration (c_token
*token
)
586 if (c_token_starts_declspecs (token
)
587 || token
->keyword
== RID_STATIC_ASSERT
)
593 static c_token
*c_parser_peek_2nd_token (c_parser
*parser
);
595 /* Return true if the next token from PARSER can start declaration
596 specifiers, false otherwise. */
598 c_parser_next_token_starts_declspecs (c_parser
*parser
)
600 c_token
*token
= c_parser_peek_token (parser
);
601 return c_token_starts_declspecs (token
);
604 /* Return true if the next token from PARSER can start declaration
605 specifiers or a static assertion, false otherwise. */
607 c_parser_next_token_starts_declaration (c_parser
*parser
)
609 c_token
*token
= c_parser_peek_token (parser
);
610 return c_token_starts_declaration (token
);
613 /* Return a pointer to the next-but-one token from PARSER, reading it
614 in if necessary. The next token is already read in. */
617 c_parser_peek_2nd_token (c_parser
*parser
)
619 if (parser
->tokens_avail
>= 2)
620 return &parser
->tokens
[1];
621 gcc_assert (parser
->tokens_avail
== 1);
622 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
623 gcc_assert (parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
624 c_lex_one_token (parser
, &parser
->tokens
[1]);
625 parser
->tokens_avail
= 2;
626 return &parser
->tokens
[1];
629 /* Consume the next token from PARSER. */
632 c_parser_consume_token (c_parser
*parser
)
634 gcc_assert (parser
->tokens_avail
>= 1);
635 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
636 gcc_assert (!parser
->in_pragma
|| parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
637 gcc_assert (parser
->error
|| parser
->tokens
[0].type
!= CPP_PRAGMA
);
638 if (parser
->tokens_avail
== 2)
639 parser
->tokens
[0] = parser
->tokens
[1];
640 parser
->tokens_avail
--;
643 /* Expect the current token to be a #pragma. Consume it and remember
644 that we've begun parsing a pragma. */
647 c_parser_consume_pragma (c_parser
*parser
)
649 gcc_assert (!parser
->in_pragma
);
650 gcc_assert (parser
->tokens_avail
>= 1);
651 gcc_assert (parser
->tokens
[0].type
== CPP_PRAGMA
);
652 if (parser
->tokens_avail
== 2)
653 parser
->tokens
[0] = parser
->tokens
[1];
654 parser
->tokens_avail
--;
655 parser
->in_pragma
= true;
658 /* Update the globals input_location and in_system_header from
661 c_parser_set_source_position_from_token (c_token
*token
)
663 if (token
->type
!= CPP_EOF
)
665 input_location
= token
->location
;
669 /* Issue a diagnostic of the form
670 FILE:LINE: MESSAGE before TOKEN
671 where TOKEN is the next token in the input stream of PARSER.
672 MESSAGE (specified by the caller) is usually of the form "expected
675 Do not issue a diagnostic if still recovering from an error.
677 ??? This is taken from the C++ parser, but building up messages in
678 this way is not i18n-friendly and some other approach should be
682 c_parser_error (c_parser
*parser
, const char *gmsgid
)
684 c_token
*token
= c_parser_peek_token (parser
);
687 parser
->error
= true;
690 /* This diagnostic makes more sense if it is tagged to the line of
691 the token we just peeked at. */
692 c_parser_set_source_position_from_token (token
);
693 c_parse_error (gmsgid
,
694 /* Because c_parse_error does not understand
695 CPP_KEYWORD, keywords are treated like
697 (token
->type
== CPP_KEYWORD
? CPP_NAME
: token
->type
),
698 /* ??? The C parser does not save the cpp flags of a
699 token, we need to pass 0 here and we will not get
700 the source spelling of some tokens but rather the
701 canonical spelling. */
702 token
->value
, /*flags=*/0);
705 /* If the next token is of the indicated TYPE, consume it. Otherwise,
706 issue the error MSGID. If MSGID is NULL then a message has already
707 been produced and no message will be produced this time. Returns
708 true if found, false otherwise. */
711 c_parser_require (c_parser
*parser
,
715 if (c_parser_next_token_is (parser
, type
))
717 c_parser_consume_token (parser
);
722 c_parser_error (parser
, msgid
);
727 /* If the next token is the indicated keyword, consume it. Otherwise,
728 issue the error MSGID. Returns true if found, false otherwise. */
731 c_parser_require_keyword (c_parser
*parser
,
735 if (c_parser_next_token_is_keyword (parser
, keyword
))
737 c_parser_consume_token (parser
);
742 c_parser_error (parser
, msgid
);
747 /* Like c_parser_require, except that tokens will be skipped until the
748 desired token is found. An error message is still produced if the
749 next token is not as expected. If MSGID is NULL then a message has
750 already been produced and no message will be produced this
754 c_parser_skip_until_found (c_parser
*parser
,
758 unsigned nesting_depth
= 0;
760 if (c_parser_require (parser
, type
, msgid
))
763 /* Skip tokens until the desired token is found. */
766 /* Peek at the next token. */
767 c_token
*token
= c_parser_peek_token (parser
);
768 /* If we've reached the token we want, consume it and stop. */
769 if (token
->type
== type
&& !nesting_depth
)
771 c_parser_consume_token (parser
);
775 /* If we've run out of tokens, stop. */
776 if (token
->type
== CPP_EOF
)
778 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
780 if (token
->type
== CPP_OPEN_BRACE
781 || token
->type
== CPP_OPEN_PAREN
782 || token
->type
== CPP_OPEN_SQUARE
)
784 else if (token
->type
== CPP_CLOSE_BRACE
785 || token
->type
== CPP_CLOSE_PAREN
786 || token
->type
== CPP_CLOSE_SQUARE
)
788 if (nesting_depth
-- == 0)
791 /* Consume this token. */
792 c_parser_consume_token (parser
);
794 parser
->error
= false;
797 /* Skip tokens until the end of a parameter is found, but do not
798 consume the comma, semicolon or closing delimiter. */
801 c_parser_skip_to_end_of_parameter (c_parser
*parser
)
803 unsigned nesting_depth
= 0;
807 c_token
*token
= c_parser_peek_token (parser
);
808 if ((token
->type
== CPP_COMMA
|| token
->type
== CPP_SEMICOLON
)
811 /* If we've run out of tokens, stop. */
812 if (token
->type
== CPP_EOF
)
814 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
816 if (token
->type
== CPP_OPEN_BRACE
817 || token
->type
== CPP_OPEN_PAREN
818 || token
->type
== CPP_OPEN_SQUARE
)
820 else if (token
->type
== CPP_CLOSE_BRACE
821 || token
->type
== CPP_CLOSE_PAREN
822 || token
->type
== CPP_CLOSE_SQUARE
)
824 if (nesting_depth
-- == 0)
827 /* Consume this token. */
828 c_parser_consume_token (parser
);
830 parser
->error
= false;
833 /* Expect to be at the end of the pragma directive and consume an
834 end of line marker. */
837 c_parser_skip_to_pragma_eol (c_parser
*parser
)
839 gcc_assert (parser
->in_pragma
);
840 parser
->in_pragma
= false;
842 if (!c_parser_require (parser
, CPP_PRAGMA_EOL
, "expected end of line"))
845 c_token
*token
= c_parser_peek_token (parser
);
846 if (token
->type
== CPP_EOF
)
848 if (token
->type
== CPP_PRAGMA_EOL
)
850 c_parser_consume_token (parser
);
853 c_parser_consume_token (parser
);
856 parser
->error
= false;
859 /* Skip tokens until we have consumed an entire block, or until we
860 have consumed a non-nested ';'. */
863 c_parser_skip_to_end_of_block_or_statement (c_parser
*parser
)
865 unsigned nesting_depth
= 0;
866 bool save_error
= parser
->error
;
872 /* Peek at the next token. */
873 token
= c_parser_peek_token (parser
);
881 if (parser
->in_pragma
)
886 /* If the next token is a ';', we have reached the
887 end of the statement. */
890 /* Consume the ';'. */
891 c_parser_consume_token (parser
);
896 case CPP_CLOSE_BRACE
:
897 /* If the next token is a non-nested '}', then we have
898 reached the end of the current block. */
899 if (nesting_depth
== 0 || --nesting_depth
== 0)
901 c_parser_consume_token (parser
);
907 /* If it the next token is a '{', then we are entering a new
908 block. Consume the entire block. */
913 /* If we see a pragma, consume the whole thing at once. We
914 have some safeguards against consuming pragmas willy-nilly.
915 Normally, we'd expect to be here with parser->error set,
916 which disables these safeguards. But it's possible to get
917 here for secondary error recovery, after parser->error has
919 c_parser_consume_pragma (parser
);
920 c_parser_skip_to_pragma_eol (parser
);
921 parser
->error
= save_error
;
928 c_parser_consume_token (parser
);
932 parser
->error
= false;
935 /* CPP's options (initialized by c-opts.c). */
936 extern cpp_options
*cpp_opts
;
938 /* Save the warning flags which are controlled by __extension__. */
941 disable_extension_diagnostics (void)
944 | (warn_pointer_arith
<< 1)
945 | (warn_traditional
<< 2)
947 | (warn_long_long
<< 4)
948 | (warn_cxx_compat
<< 5));
949 cpp_opts
->cpp_pedantic
= pedantic
= 0;
950 warn_pointer_arith
= 0;
951 cpp_opts
->cpp_warn_traditional
= warn_traditional
= 0;
953 cpp_opts
->cpp_warn_long_long
= warn_long_long
= 0;
958 /* Restore the warning flags which are controlled by __extension__.
959 FLAGS is the return value from disable_extension_diagnostics. */
962 restore_extension_diagnostics (int flags
)
964 cpp_opts
->cpp_pedantic
= pedantic
= flags
& 1;
965 warn_pointer_arith
= (flags
>> 1) & 1;
966 cpp_opts
->cpp_warn_traditional
= warn_traditional
= (flags
>> 2) & 1;
967 flag_iso
= (flags
>> 3) & 1;
968 cpp_opts
->cpp_warn_long_long
= warn_long_long
= (flags
>> 4) & 1;
969 warn_cxx_compat
= (flags
>> 5) & 1;
972 /* Possibly kinds of declarator to parse. */
973 typedef enum c_dtr_syn
{
974 /* A normal declarator with an identifier. */
976 /* An abstract declarator (maybe empty). */
978 /* A parameter declarator: may be either, but after a type name does
979 not redeclare a typedef name as an identifier if it can
980 alternatively be interpreted as a typedef name; see DR#009,
981 applied in C90 TC1, omitted from C99 and reapplied in C99 TC2
982 following DR#249. For example, given a typedef T, "int T" and
983 "int *T" are valid parameter declarations redeclaring T, while
984 "int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are
985 abstract declarators rather than involving redundant parentheses;
986 the same applies with attributes inside the parentheses before
991 static void c_parser_external_declaration (c_parser
*);
992 static void c_parser_asm_definition (c_parser
*);
993 static void c_parser_declaration_or_fndef (c_parser
*, bool, bool, bool,
995 static void c_parser_static_assert_declaration_no_semi (c_parser
*);
996 static void c_parser_static_assert_declaration (c_parser
*);
997 static void c_parser_declspecs (c_parser
*, struct c_declspecs
*, bool, bool,
999 static struct c_typespec
c_parser_enum_specifier (c_parser
*);
1000 static struct c_typespec
c_parser_struct_or_union_specifier (c_parser
*);
1001 static tree
c_parser_struct_declaration (c_parser
*);
1002 static struct c_typespec
c_parser_typeof_specifier (c_parser
*);
1003 static struct c_declarator
*c_parser_declarator (c_parser
*, bool, c_dtr_syn
,
1005 static struct c_declarator
*c_parser_direct_declarator (c_parser
*, bool,
1007 static struct c_declarator
*c_parser_direct_declarator_inner (c_parser
*,
1009 struct c_declarator
*);
1010 static struct c_arg_info
*c_parser_parms_declarator (c_parser
*, bool, tree
);
1011 static struct c_arg_info
*c_parser_parms_list_declarator (c_parser
*, tree
);
1012 static struct c_parm
*c_parser_parameter_declaration (c_parser
*, tree
);
1013 static tree
c_parser_simple_asm_expr (c_parser
*);
1014 static tree
c_parser_attributes (c_parser
*);
1015 static struct c_type_name
*c_parser_type_name (c_parser
*);
1016 static struct c_expr
c_parser_initializer (c_parser
*);
1017 static struct c_expr
c_parser_braced_init (c_parser
*, tree
, bool);
1018 static void c_parser_initelt (c_parser
*, struct obstack
*);
1019 static void c_parser_initval (c_parser
*, struct c_expr
*,
1021 static tree
c_parser_compound_statement (c_parser
*);
1022 static void c_parser_compound_statement_nostart (c_parser
*);
1023 static void c_parser_label (c_parser
*);
1024 static void c_parser_statement (c_parser
*);
1025 static void c_parser_statement_after_labels (c_parser
*);
1026 static void c_parser_if_statement (c_parser
*);
1027 static void c_parser_switch_statement (c_parser
*);
1028 static void c_parser_while_statement (c_parser
*);
1029 static void c_parser_do_statement (c_parser
*);
1030 static void c_parser_for_statement (c_parser
*);
1031 static tree
c_parser_asm_statement (c_parser
*);
1032 static tree
c_parser_asm_operands (c_parser
*, bool);
1033 static tree
c_parser_asm_goto_operands (c_parser
*);
1034 static tree
c_parser_asm_clobbers (c_parser
*);
1035 static struct c_expr
c_parser_expr_no_commas (c_parser
*, struct c_expr
*);
1036 static struct c_expr
c_parser_conditional_expression (c_parser
*,
1038 static struct c_expr
c_parser_binary_expression (c_parser
*, struct c_expr
*);
1039 static struct c_expr
c_parser_cast_expression (c_parser
*, struct c_expr
*);
1040 static struct c_expr
c_parser_unary_expression (c_parser
*);
1041 static struct c_expr
c_parser_sizeof_expression (c_parser
*);
1042 static struct c_expr
c_parser_alignof_expression (c_parser
*);
1043 static struct c_expr
c_parser_postfix_expression (c_parser
*);
1044 static struct c_expr
c_parser_postfix_expression_after_paren_type (c_parser
*,
1045 struct c_type_name
*,
1047 static struct c_expr
c_parser_postfix_expression_after_primary (c_parser
*,
1050 static struct c_expr
c_parser_expression (c_parser
*);
1051 static struct c_expr
c_parser_expression_conv (c_parser
*);
1052 static VEC(tree
,gc
) *c_parser_expr_list (c_parser
*, bool, bool,
1054 static void c_parser_omp_construct (c_parser
*);
1055 static void c_parser_omp_threadprivate (c_parser
*);
1056 static void c_parser_omp_barrier (c_parser
*);
1057 static void c_parser_omp_flush (c_parser
*);
1058 static void c_parser_omp_taskwait (c_parser
*);
1060 enum pragma_context
{ pragma_external
, pragma_stmt
, pragma_compound
};
1061 static bool c_parser_pragma (c_parser
*, enum pragma_context
);
1063 /* These Objective-C parser functions are only ever called when
1064 compiling Objective-C. */
1065 static void c_parser_objc_class_definition (c_parser
*, tree
);
1066 static void c_parser_objc_class_instance_variables (c_parser
*);
1067 static void c_parser_objc_class_declaration (c_parser
*);
1068 static void c_parser_objc_alias_declaration (c_parser
*);
1069 static void c_parser_objc_protocol_definition (c_parser
*, tree
);
1070 static bool c_parser_objc_method_type (c_parser
*);
1071 static void c_parser_objc_method_definition (c_parser
*);
1072 static void c_parser_objc_methodprotolist (c_parser
*);
1073 static void c_parser_objc_methodproto (c_parser
*);
1074 static tree
c_parser_objc_method_decl (c_parser
*, bool, tree
*);
1075 static tree
c_parser_objc_type_name (c_parser
*);
1076 static tree
c_parser_objc_protocol_refs (c_parser
*);
1077 static void c_parser_objc_try_catch_statement (c_parser
*);
1078 static void c_parser_objc_synchronized_statement (c_parser
*);
1079 static tree
c_parser_objc_selector (c_parser
*);
1080 static tree
c_parser_objc_selector_arg (c_parser
*);
1081 static tree
c_parser_objc_receiver (c_parser
*);
1082 static tree
c_parser_objc_message_args (c_parser
*);
1083 static tree
c_parser_objc_keywordexpr (c_parser
*);
1084 static void c_parser_objc_at_property_declaration (c_parser
*);
1085 static void c_parser_objc_at_synthesize_declaration (c_parser
*);
1086 static void c_parser_objc_at_dynamic_declaration (c_parser
*);
1087 static bool c_parser_objc_diagnose_bad_element_prefix
1088 (c_parser
*, struct c_declspecs
*);
1090 /* Parse a translation unit (C90 6.7, C99 6.9).
1093 external-declarations
1095 external-declarations:
1096 external-declaration
1097 external-declarations external-declaration
1106 c_parser_translation_unit (c_parser
*parser
)
1108 if (c_parser_next_token_is (parser
, CPP_EOF
))
1110 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
1111 "ISO C forbids an empty translation unit");
1115 void *obstack_position
= obstack_alloc (&parser_obstack
, 0);
1116 mark_valid_location_for_stdc_pragma (false);
1120 c_parser_external_declaration (parser
);
1121 obstack_free (&parser_obstack
, obstack_position
);
1123 while (c_parser_next_token_is_not (parser
, CPP_EOF
));
1127 /* Parse an external declaration (C90 6.7, C99 6.9).
1129 external-declaration:
1135 external-declaration:
1138 __extension__ external-declaration
1142 external-declaration:
1143 objc-class-definition
1144 objc-class-declaration
1145 objc-alias-declaration
1146 objc-protocol-definition
1147 objc-method-definition
1152 c_parser_external_declaration (c_parser
*parser
)
1155 switch (c_parser_peek_token (parser
)->type
)
1158 switch (c_parser_peek_token (parser
)->keyword
)
1161 ext
= disable_extension_diagnostics ();
1162 c_parser_consume_token (parser
);
1163 c_parser_external_declaration (parser
);
1164 restore_extension_diagnostics (ext
);
1167 c_parser_asm_definition (parser
);
1169 case RID_AT_INTERFACE
:
1170 case RID_AT_IMPLEMENTATION
:
1171 gcc_assert (c_dialect_objc ());
1172 c_parser_objc_class_definition (parser
, NULL_TREE
);
1175 gcc_assert (c_dialect_objc ());
1176 c_parser_objc_class_declaration (parser
);
1179 gcc_assert (c_dialect_objc ());
1180 c_parser_objc_alias_declaration (parser
);
1182 case RID_AT_PROTOCOL
:
1183 gcc_assert (c_dialect_objc ());
1184 c_parser_objc_protocol_definition (parser
, NULL_TREE
);
1186 case RID_AT_PROPERTY
:
1187 gcc_assert (c_dialect_objc ());
1188 c_parser_objc_at_property_declaration (parser
);
1190 case RID_AT_SYNTHESIZE
:
1191 gcc_assert (c_dialect_objc ());
1192 c_parser_objc_at_synthesize_declaration (parser
);
1194 case RID_AT_DYNAMIC
:
1195 gcc_assert (c_dialect_objc ());
1196 c_parser_objc_at_dynamic_declaration (parser
);
1199 gcc_assert (c_dialect_objc ());
1200 c_parser_consume_token (parser
);
1201 objc_finish_implementation ();
1208 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
1209 "ISO C does not allow extra %<;%> outside of a function");
1210 c_parser_consume_token (parser
);
1213 mark_valid_location_for_stdc_pragma (true);
1214 c_parser_pragma (parser
, pragma_external
);
1215 mark_valid_location_for_stdc_pragma (false);
1219 if (c_dialect_objc ())
1221 c_parser_objc_method_definition (parser
);
1224 /* Else fall through, and yield a syntax error trying to parse
1225 as a declaration or function definition. */
1228 /* A declaration or a function definition (or, in Objective-C,
1229 an @interface or @protocol with prefix attributes). We can
1230 only tell which after parsing the declaration specifiers, if
1231 any, and the first declarator. */
1232 c_parser_declaration_or_fndef (parser
, true, true, true, false, true, NULL
);
1237 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1238 6.7, 6.9.1). If FNDEF_OK is true, a function definition is
1239 accepted; otherwise (old-style parameter declarations) only other
1240 declarations are accepted. If STATIC_ASSERT_OK is true, a static
1241 assertion is accepted; otherwise (old-style parameter declarations)
1242 it is not. If NESTED is true, we are inside a function or parsing
1243 old-style parameter declarations; any functions encountered are
1244 nested functions and declaration specifiers are required; otherwise
1245 we are at top level and functions are normal functions and
1246 declaration specifiers may be optional. If EMPTY_OK is true, empty
1247 declarations are OK (subject to all other constraints); otherwise
1248 (old-style parameter declarations) they are diagnosed. If
1249 START_ATTR_OK is true, the declaration specifiers may start with
1250 attributes; otherwise they may not.
1251 OBJC_FOREACH_OBJECT_DECLARATION can be used to get back the parsed
1252 declaration when parsing an Objective-C foreach statement.
1255 declaration-specifiers init-declarator-list[opt] ;
1256 static_assert-declaration
1258 function-definition:
1259 declaration-specifiers[opt] declarator declaration-list[opt]
1264 declaration-list declaration
1266 init-declarator-list:
1268 init-declarator-list , init-declarator
1271 declarator simple-asm-expr[opt] attributes[opt]
1272 declarator simple-asm-expr[opt] attributes[opt] = initializer
1276 nested-function-definition:
1277 declaration-specifiers declarator declaration-list[opt]
1281 attributes objc-class-definition
1282 attributes objc-category-definition
1283 attributes objc-protocol-definition
1285 The simple-asm-expr and attributes are GNU extensions.
1287 This function does not handle __extension__; that is handled in its
1288 callers. ??? Following the old parser, __extension__ may start
1289 external declarations, declarations in functions and declarations
1290 at the start of "for" loops, but not old-style parameter
1293 C99 requires declaration specifiers in a function definition; the
1294 absence is diagnosed through the diagnosis of implicit int. In GNU
1295 C we also allow but diagnose declarations without declaration
1296 specifiers, but only at top level (elsewhere they conflict with
1299 In Objective-C, declarations of the looping variable in a foreach
1300 statement are exceptionally terminated by 'in' (for example, 'for
1301 (NSObject *object in array) { ... }').
1306 threadprivate-directive */
1309 c_parser_declaration_or_fndef (c_parser
*parser
, bool fndef_ok
,
1310 bool static_assert_ok
, bool empty_ok
,
1311 bool nested
, bool start_attr_ok
,
1312 tree
*objc_foreach_object_declaration
)
1314 struct c_declspecs
*specs
;
1316 tree all_prefix_attrs
;
1317 bool diagnosed_no_specs
= false;
1318 location_t here
= c_parser_peek_token (parser
)->location
;
1320 if (static_assert_ok
1321 && c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
1323 c_parser_static_assert_declaration (parser
);
1326 specs
= build_null_declspecs ();
1327 c_parser_declspecs (parser
, specs
, true, true, start_attr_ok
);
1330 c_parser_skip_to_end_of_block_or_statement (parser
);
1333 if (nested
&& !specs
->declspecs_seen_p
)
1335 c_parser_error (parser
, "expected declaration specifiers");
1336 c_parser_skip_to_end_of_block_or_statement (parser
);
1339 finish_declspecs (specs
);
1340 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1346 shadow_tag_warned (specs
, 1);
1347 pedwarn (here
, 0, "empty declaration");
1349 c_parser_consume_token (parser
);
1352 else if (c_dialect_objc ())
1354 /* Prefix attributes are an error on method decls. */
1355 switch (c_parser_peek_token (parser
)->type
)
1359 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1363 warning_at (c_parser_peek_token (parser
)->location
,
1365 "prefix attributes are ignored for methods");
1366 specs
->attrs
= NULL_TREE
;
1369 c_parser_objc_method_definition (parser
);
1371 c_parser_objc_methodproto (parser
);
1377 /* This is where we parse 'attributes @interface ...',
1378 'attributes @implementation ...', 'attributes @protocol ...'
1379 (where attributes could be, for example, __attribute__
1382 switch (c_parser_peek_token (parser
)->keyword
)
1384 case RID_AT_INTERFACE
:
1386 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1388 c_parser_objc_class_definition (parser
, specs
->attrs
);
1392 case RID_AT_IMPLEMENTATION
:
1394 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1398 warning_at (c_parser_peek_token (parser
)->location
,
1400 "prefix attributes are ignored for implementations");
1401 specs
->attrs
= NULL_TREE
;
1403 c_parser_objc_class_definition (parser
, NULL_TREE
);
1407 case RID_AT_PROTOCOL
:
1409 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1411 c_parser_objc_protocol_definition (parser
, specs
->attrs
);
1418 case RID_AT_PROPERTY
:
1421 c_parser_error (parser
,
1422 "attributes may not be specified before" );
1423 specs
->attrs
= NULL
;
1431 pending_xref_error ();
1432 prefix_attrs
= specs
->attrs
;
1433 all_prefix_attrs
= prefix_attrs
;
1434 specs
->attrs
= NULL_TREE
;
1437 struct c_declarator
*declarator
;
1440 /* Declaring either one or more declarators (in which case we
1441 should diagnose if there were no declaration specifiers) or a
1442 function definition (in which case the diagnostic for
1443 implicit int suffices). */
1444 declarator
= c_parser_declarator (parser
, specs
->type_seen_p
,
1445 C_DTR_NORMAL
, &dummy
);
1446 if (declarator
== NULL
)
1448 c_parser_skip_to_end_of_block_or_statement (parser
);
1451 if (c_parser_next_token_is (parser
, CPP_EQ
)
1452 || c_parser_next_token_is (parser
, CPP_COMMA
)
1453 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
1454 || c_parser_next_token_is_keyword (parser
, RID_ASM
)
1455 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
)
1456 || c_parser_next_token_is_keyword (parser
, RID_IN
))
1458 tree asm_name
= NULL_TREE
;
1459 tree postfix_attrs
= NULL_TREE
;
1460 if (!diagnosed_no_specs
&& !specs
->declspecs_seen_p
)
1462 diagnosed_no_specs
= true;
1463 pedwarn (here
, 0, "data definition has no type or storage class");
1465 /* Having seen a data definition, there cannot now be a
1466 function definition. */
1468 if (c_parser_next_token_is_keyword (parser
, RID_ASM
))
1469 asm_name
= c_parser_simple_asm_expr (parser
);
1470 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1471 postfix_attrs
= c_parser_attributes (parser
);
1472 if (c_parser_next_token_is (parser
, CPP_EQ
))
1476 location_t init_loc
;
1477 c_parser_consume_token (parser
);
1478 /* The declaration of the variable is in effect while
1479 its initializer is parsed. */
1480 d
= start_decl (declarator
, specs
, true,
1481 chainon (postfix_attrs
, all_prefix_attrs
));
1483 d
= error_mark_node
;
1484 start_init (d
, asm_name
, global_bindings_p ());
1485 init_loc
= c_parser_peek_token (parser
)->location
;
1486 init
= c_parser_initializer (parser
);
1488 if (d
!= error_mark_node
)
1490 maybe_warn_string_init (TREE_TYPE (d
), init
);
1491 finish_decl (d
, init_loc
, init
.value
,
1492 init
.original_type
, asm_name
);
1497 tree d
= start_decl (declarator
, specs
, false,
1498 chainon (postfix_attrs
,
1501 finish_decl (d
, UNKNOWN_LOCATION
, NULL_TREE
,
1502 NULL_TREE
, asm_name
);
1504 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
1507 *objc_foreach_object_declaration
= d
;
1509 *objc_foreach_object_declaration
= error_mark_node
;
1512 if (c_parser_next_token_is (parser
, CPP_COMMA
))
1514 c_parser_consume_token (parser
);
1515 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1516 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
1519 all_prefix_attrs
= prefix_attrs
;
1522 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1524 c_parser_consume_token (parser
);
1527 else if (c_parser_next_token_is_keyword (parser
, RID_IN
))
1529 /* This can only happen in Objective-C: we found the
1530 'in' that terminates the declaration inside an
1531 Objective-C foreach statement. Do not consume the
1532 token, so that the caller can use it to determine
1533 that this indeed is a foreach context. */
1538 c_parser_error (parser
, "expected %<,%> or %<;%>");
1539 c_parser_skip_to_end_of_block_or_statement (parser
);
1545 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, "
1546 "%<asm%> or %<__attribute__%>");
1547 c_parser_skip_to_end_of_block_or_statement (parser
);
1550 /* Function definition (nested or otherwise). */
1553 pedwarn (here
, OPT_pedantic
, "ISO C forbids nested functions");
1554 c_push_function_context ();
1556 if (!start_function (specs
, declarator
, all_prefix_attrs
))
1558 /* This can appear in many cases looking nothing like a
1559 function definition, so we don't give a more specific
1560 error suggesting there was one. */
1561 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
1562 "or %<__attribute__%>");
1564 c_pop_function_context ();
1567 /* Parse old-style parameter declarations. ??? Attributes are
1568 not allowed to start declaration specifiers here because of a
1569 syntax conflict between a function declaration with attribute
1570 suffix and a function definition with an attribute prefix on
1571 first old-style parameter declaration. Following the old
1572 parser, they are not accepted on subsequent old-style
1573 parameter declarations either. However, there is no
1574 ambiguity after the first declaration, nor indeed on the
1575 first as long as we don't allow postfix attributes after a
1576 declarator with a nonempty identifier list in a definition;
1577 and postfix attributes have never been accepted here in
1578 function definitions either. */
1579 while (c_parser_next_token_is_not (parser
, CPP_EOF
)
1580 && c_parser_next_token_is_not (parser
, CPP_OPEN_BRACE
))
1581 c_parser_declaration_or_fndef (parser
, false, false, false,
1583 store_parm_decls ();
1584 DECL_STRUCT_FUNCTION (current_function_decl
)->function_start_locus
1585 = c_parser_peek_token (parser
)->location
;
1586 fnbody
= c_parser_compound_statement (parser
);
1589 tree decl
= current_function_decl
;
1590 /* Mark nested functions as needing static-chain initially.
1591 lower_nested_functions will recompute it but the
1592 DECL_STATIC_CHAIN flag is also used before that happens,
1593 by initializer_constant_valid_p. See gcc.dg/nested-fn-2.c. */
1594 DECL_STATIC_CHAIN (decl
) = 1;
1597 c_pop_function_context ();
1598 add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl
), DECL_EXPR
, decl
));
1609 /* Parse an asm-definition (asm() outside a function body). This is a
1617 c_parser_asm_definition (c_parser
*parser
)
1619 tree asm_str
= c_parser_simple_asm_expr (parser
);
1621 cgraph_add_asm_node (asm_str
);
1622 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
1625 /* Parse a static assertion (C1X N1425 6.7.10).
1627 static_assert-declaration:
1628 static_assert-declaration-no-semi ;
1632 c_parser_static_assert_declaration (c_parser
*parser
)
1634 c_parser_static_assert_declaration_no_semi (parser
);
1636 || !c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
1637 c_parser_skip_to_end_of_block_or_statement (parser
);
1640 /* Parse a static assertion (C1X N1425 6.7.10), without the trailing
1643 static_assert-declaration-no-semi:
1644 _Static_assert ( constant-expression , string-literal )
1648 c_parser_static_assert_declaration_no_semi (c_parser
*parser
)
1650 location_t assert_loc
, value_loc
;
1654 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
));
1655 assert_loc
= c_parser_peek_token (parser
)->location
;
1659 pedwarn (assert_loc
, OPT_pedantic
,
1660 "ISO C99 does not support %<_Static_assert%>");
1662 pedwarn (assert_loc
, OPT_pedantic
,
1663 "ISO C90 does not support %<_Static_assert%>");
1665 c_parser_consume_token (parser
);
1666 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
1668 value_loc
= c_parser_peek_token (parser
)->location
;
1669 value
= c_parser_expr_no_commas (parser
, NULL
).value
;
1670 parser
->lex_untranslated_string
= true;
1671 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
1673 parser
->lex_untranslated_string
= false;
1676 switch (c_parser_peek_token (parser
)->type
)
1682 case CPP_UTF8STRING
:
1683 string
= c_parser_peek_token (parser
)->value
;
1684 c_parser_consume_token (parser
);
1685 parser
->lex_untranslated_string
= false;
1688 c_parser_error (parser
, "expected string literal");
1689 parser
->lex_untranslated_string
= false;
1692 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
1694 if (!INTEGRAL_TYPE_P (TREE_TYPE (value
)))
1696 error_at (value_loc
, "expression in static assertion is not an integer");
1699 if (TREE_CODE (value
) != INTEGER_CST
)
1701 value
= c_fully_fold (value
, false, NULL
);
1702 if (TREE_CODE (value
) == INTEGER_CST
)
1703 pedwarn (value_loc
, OPT_pedantic
, "expression in static assertion "
1704 "is not an integer constant expression");
1706 if (TREE_CODE (value
) != INTEGER_CST
)
1708 error_at (value_loc
, "expression in static assertion is not constant");
1711 constant_expression_warning (value
);
1712 if (integer_zerop (value
))
1713 error_at (assert_loc
, "static assertion failed: %E", string
);
1716 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
1717 6.7), adding them to SPECS (which may already include some).
1718 Storage class specifiers are accepted iff SCSPEC_OK; type
1719 specifiers are accepted iff TYPESPEC_OK; attributes are accepted at
1720 the start iff START_ATTR_OK.
1722 declaration-specifiers:
1723 storage-class-specifier declaration-specifiers[opt]
1724 type-specifier declaration-specifiers[opt]
1725 type-qualifier declaration-specifiers[opt]
1726 function-specifier declaration-specifiers[opt]
1728 Function specifiers (inline) are from C99, and are currently
1729 handled as storage class specifiers, as is __thread.
1731 C90 6.5.1, C99 6.7.1:
1732 storage-class-specifier:
1743 C90 6.5.2, C99 6.7.2:
1756 [_Imaginary removed in C99 TC2]
1757 struct-or-union-specifier
1761 (_Bool and _Complex are new in C99.)
1763 C90 6.5.3, C99 6.7.3:
1769 address-space-qualifier
1771 (restrict is new in C99.)
1775 declaration-specifiers:
1776 attributes declaration-specifiers[opt]
1782 identifier recognized by the target
1784 storage-class-specifier:
1797 (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
1798 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
1803 class-name objc-protocol-refs[opt]
1804 typedef-name objc-protocol-refs
1809 c_parser_declspecs (c_parser
*parser
, struct c_declspecs
*specs
,
1810 bool scspec_ok
, bool typespec_ok
, bool start_attr_ok
)
1812 bool attrs_ok
= start_attr_ok
;
1813 bool seen_type
= specs
->type_seen_p
;
1814 while (c_parser_next_token_is (parser
, CPP_NAME
)
1815 || c_parser_next_token_is (parser
, CPP_KEYWORD
)
1816 || (c_dialect_objc () && c_parser_next_token_is (parser
, CPP_LESS
)))
1818 struct c_typespec t
;
1820 location_t loc
= c_parser_peek_token (parser
)->location
;
1821 if (c_parser_next_token_is (parser
, CPP_NAME
))
1823 tree value
= c_parser_peek_token (parser
)->value
;
1824 c_id_kind kind
= c_parser_peek_token (parser
)->id_kind
;
1826 if (kind
== C_ID_ADDRSPACE
)
1829 = c_parser_peek_token (parser
)->keyword
- RID_FIRST_ADDR_SPACE
;
1830 declspecs_add_addrspace (specs
, as
);
1831 c_parser_consume_token (parser
);
1836 /* This finishes the specifiers unless a type name is OK, it
1837 is declared as a type name and a type name hasn't yet
1839 if (!typespec_ok
|| seen_type
1840 || (kind
!= C_ID_TYPENAME
&& kind
!= C_ID_CLASSNAME
))
1842 c_parser_consume_token (parser
);
1845 if (kind
== C_ID_TYPENAME
1846 && (!c_dialect_objc ()
1847 || c_parser_next_token_is_not (parser
, CPP_LESS
)))
1849 t
.kind
= ctsk_typedef
;
1850 /* For a typedef name, record the meaning, not the name.
1851 In case of 'foo foo, bar;'. */
1852 t
.spec
= lookup_name (value
);
1854 t
.expr_const_operands
= true;
1858 tree proto
= NULL_TREE
;
1859 gcc_assert (c_dialect_objc ());
1861 if (c_parser_next_token_is (parser
, CPP_LESS
))
1862 proto
= c_parser_objc_protocol_refs (parser
);
1863 t
.spec
= objc_get_protocol_qualified_type (value
, proto
);
1865 t
.expr_const_operands
= true;
1867 declspecs_add_type (loc
, specs
, t
);
1870 if (c_parser_next_token_is (parser
, CPP_LESS
))
1872 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
1873 nisse@lysator.liu.se. */
1875 gcc_assert (c_dialect_objc ());
1876 if (!typespec_ok
|| seen_type
)
1878 proto
= c_parser_objc_protocol_refs (parser
);
1880 t
.spec
= objc_get_protocol_qualified_type (NULL_TREE
, proto
);
1882 t
.expr_const_operands
= true;
1883 declspecs_add_type (loc
, specs
, t
);
1886 gcc_assert (c_parser_next_token_is (parser
, CPP_KEYWORD
));
1887 switch (c_parser_peek_token (parser
)->keyword
)
1899 /* TODO: Distinguish between function specifiers (inline)
1900 and storage class specifiers, either here or in
1901 declspecs_add_scspec. */
1902 declspecs_add_scspec (specs
, c_parser_peek_token (parser
)->value
);
1903 c_parser_consume_token (parser
);
1927 if (c_dialect_objc ())
1928 parser
->objc_need_raw_identifier
= true;
1929 t
.kind
= ctsk_resword
;
1930 t
.spec
= c_parser_peek_token (parser
)->value
;
1932 t
.expr_const_operands
= true;
1933 declspecs_add_type (loc
, specs
, t
);
1934 c_parser_consume_token (parser
);
1941 t
= c_parser_enum_specifier (parser
);
1942 declspecs_add_type (loc
, specs
, t
);
1950 t
= c_parser_struct_or_union_specifier (parser
);
1951 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE
, t
.spec
);
1952 declspecs_add_type (loc
, specs
, t
);
1955 /* ??? The old parser rejected typeof after other type
1956 specifiers, but is a syntax error the best way of
1958 if (!typespec_ok
|| seen_type
)
1962 t
= c_parser_typeof_specifier (parser
);
1963 declspecs_add_type (loc
, specs
, t
);
1969 declspecs_add_qual (specs
, c_parser_peek_token (parser
)->value
);
1970 c_parser_consume_token (parser
);
1975 attrs
= c_parser_attributes (parser
);
1976 declspecs_add_attrs (specs
, attrs
);
1985 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
1988 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
1989 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
1990 enum attributes[opt] identifier
1992 The form with trailing comma is new in C99. The forms with
1993 attributes are GNU extensions. In GNU C, we accept any expression
1994 without commas in the syntax (assignment expressions, not just
1995 conditional expressions); assignment expressions will be diagnosed
2000 enumerator-list , enumerator
2003 enumeration-constant
2004 enumeration-constant = constant-expression
2007 static struct c_typespec
2008 c_parser_enum_specifier (c_parser
*parser
)
2010 struct c_typespec ret
;
2012 tree ident
= NULL_TREE
;
2013 location_t enum_loc
;
2014 location_t ident_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2015 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ENUM
));
2016 enum_loc
= c_parser_peek_token (parser
)->location
;
2017 c_parser_consume_token (parser
);
2018 attrs
= c_parser_attributes (parser
);
2019 enum_loc
= c_parser_peek_token (parser
)->location
;
2020 /* Set the location in case we create a decl now. */
2021 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2022 if (c_parser_next_token_is (parser
, CPP_NAME
))
2024 ident
= c_parser_peek_token (parser
)->value
;
2025 ident_loc
= c_parser_peek_token (parser
)->location
;
2026 enum_loc
= ident_loc
;
2027 c_parser_consume_token (parser
);
2029 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2031 /* Parse an enum definition. */
2032 struct c_enum_contents the_enum
;
2033 tree type
= start_enum (enum_loc
, &the_enum
, ident
);
2035 /* We chain the enumerators in reverse order, then put them in
2036 forward order at the end. */
2037 tree values
= NULL_TREE
;
2038 c_parser_consume_token (parser
);
2046 location_t comma_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2047 location_t decl_loc
, value_loc
;
2048 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
2050 c_parser_error (parser
, "expected identifier");
2051 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2052 values
= error_mark_node
;
2055 token
= c_parser_peek_token (parser
);
2056 enum_id
= token
->value
;
2057 /* Set the location in case we create a decl now. */
2058 c_parser_set_source_position_from_token (token
);
2059 decl_loc
= value_loc
= token
->location
;
2060 c_parser_consume_token (parser
);
2061 if (c_parser_next_token_is (parser
, CPP_EQ
))
2063 c_parser_consume_token (parser
);
2064 value_loc
= c_parser_peek_token (parser
)->location
;
2065 enum_value
= c_parser_expr_no_commas (parser
, NULL
).value
;
2068 enum_value
= NULL_TREE
;
2069 enum_decl
= build_enumerator (decl_loc
, value_loc
,
2070 &the_enum
, enum_id
, enum_value
);
2071 TREE_CHAIN (enum_decl
) = values
;
2074 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2076 comma_loc
= c_parser_peek_token (parser
)->location
;
2078 c_parser_consume_token (parser
);
2080 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2082 if (seen_comma
&& !flag_isoc99
)
2083 pedwarn (comma_loc
, OPT_pedantic
, "comma at end of enumerator list");
2084 c_parser_consume_token (parser
);
2089 c_parser_error (parser
, "expected %<,%> or %<}%>");
2090 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2091 values
= error_mark_node
;
2095 postfix_attrs
= c_parser_attributes (parser
);
2096 ret
.spec
= finish_enum (type
, nreverse (values
),
2097 chainon (attrs
, postfix_attrs
));
2098 ret
.kind
= ctsk_tagdef
;
2099 ret
.expr
= NULL_TREE
;
2100 ret
.expr_const_operands
= true;
2105 c_parser_error (parser
, "expected %<{%>");
2106 ret
.spec
= error_mark_node
;
2107 ret
.kind
= ctsk_tagref
;
2108 ret
.expr
= NULL_TREE
;
2109 ret
.expr_const_operands
= true;
2112 ret
= parser_xref_tag (ident_loc
, ENUMERAL_TYPE
, ident
);
2113 /* In ISO C, enumerated types can be referred to only if already
2115 if (pedantic
&& !COMPLETE_TYPE_P (ret
.spec
))
2118 pedwarn (enum_loc
, OPT_pedantic
,
2119 "ISO C forbids forward references to %<enum%> types");
2124 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
2126 struct-or-union-specifier:
2127 struct-or-union attributes[opt] identifier[opt]
2128 { struct-contents } attributes[opt]
2129 struct-or-union attributes[opt] identifier
2132 struct-declaration-list
2134 struct-declaration-list:
2135 struct-declaration ;
2136 struct-declaration-list struct-declaration ;
2143 struct-declaration-list struct-declaration
2145 struct-declaration-list:
2146 struct-declaration-list ;
2149 (Note that in the syntax here, unlike that in ISO C, the semicolons
2150 are included here rather than in struct-declaration, in order to
2151 describe the syntax with extra semicolons and missing semicolon at
2156 struct-declaration-list:
2157 @defs ( class-name )
2159 (Note this does not include a trailing semicolon, but can be
2160 followed by further declarations, and gets a pedwarn-if-pedantic
2161 when followed by a semicolon.) */
2163 static struct c_typespec
2164 c_parser_struct_or_union_specifier (c_parser
*parser
)
2166 struct c_typespec ret
;
2168 tree ident
= NULL_TREE
;
2169 location_t struct_loc
;
2170 location_t ident_loc
= UNKNOWN_LOCATION
;
2171 enum tree_code code
;
2172 switch (c_parser_peek_token (parser
)->keyword
)
2183 struct_loc
= c_parser_peek_token (parser
)->location
;
2184 c_parser_consume_token (parser
);
2185 attrs
= c_parser_attributes (parser
);
2187 /* Set the location in case we create a decl now. */
2188 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2190 if (c_parser_next_token_is (parser
, CPP_NAME
))
2192 ident
= c_parser_peek_token (parser
)->value
;
2193 ident_loc
= c_parser_peek_token (parser
)->location
;
2194 struct_loc
= ident_loc
;
2195 c_parser_consume_token (parser
);
2197 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2199 /* Parse a struct or union definition. Start the scope of the
2200 tag before parsing components. */
2201 struct c_struct_parse_info
*struct_info
;
2202 tree type
= start_struct (struct_loc
, code
, ident
, &struct_info
);
2204 /* We chain the components in reverse order, then put them in
2205 forward order at the end. Each struct-declaration may
2206 declare multiple components (comma-separated), so we must use
2207 chainon to join them, although when parsing each
2208 struct-declaration we can use TREE_CHAIN directly.
2210 The theory behind all this is that there will be more
2211 semicolon separated fields than comma separated fields, and
2212 so we'll be minimizing the number of node traversals required
2214 tree contents
= NULL_TREE
;
2215 c_parser_consume_token (parser
);
2216 /* Handle the Objective-C @defs construct,
2217 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
2218 if (c_parser_next_token_is_keyword (parser
, RID_AT_DEFS
))
2221 gcc_assert (c_dialect_objc ());
2222 c_parser_consume_token (parser
);
2223 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2225 if (c_parser_next_token_is (parser
, CPP_NAME
)
2226 && c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
)
2228 name
= c_parser_peek_token (parser
)->value
;
2229 c_parser_consume_token (parser
);
2233 c_parser_error (parser
, "expected class name");
2234 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2237 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2239 contents
= nreverse (objc_get_class_ivars (name
));
2242 /* Parse the struct-declarations and semicolons. Problems with
2243 semicolons are diagnosed here; empty structures are diagnosed
2248 /* Parse any stray semicolon. */
2249 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2251 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
2252 "extra semicolon in struct or union specified");
2253 c_parser_consume_token (parser
);
2256 /* Stop if at the end of the struct or union contents. */
2257 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2259 c_parser_consume_token (parser
);
2262 /* Accept #pragmas at struct scope. */
2263 if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
2265 c_parser_pragma (parser
, pragma_external
);
2268 /* Parse some comma-separated declarations, but not the
2269 trailing semicolon if any. */
2270 decls
= c_parser_struct_declaration (parser
);
2271 contents
= chainon (decls
, contents
);
2272 /* If no semicolon follows, either we have a parse error or
2273 are at the end of the struct or union and should
2275 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2276 c_parser_consume_token (parser
);
2279 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2280 pedwarn (c_parser_peek_token (parser
)->location
, 0,
2281 "no semicolon at end of struct or union");
2284 c_parser_error (parser
, "expected %<;%>");
2285 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2290 postfix_attrs
= c_parser_attributes (parser
);
2291 ret
.spec
= finish_struct (struct_loc
, type
, nreverse (contents
),
2292 chainon (attrs
, postfix_attrs
), struct_info
);
2293 ret
.kind
= ctsk_tagdef
;
2294 ret
.expr
= NULL_TREE
;
2295 ret
.expr_const_operands
= true;
2300 c_parser_error (parser
, "expected %<{%>");
2301 ret
.spec
= error_mark_node
;
2302 ret
.kind
= ctsk_tagref
;
2303 ret
.expr
= NULL_TREE
;
2304 ret
.expr_const_operands
= true;
2307 ret
= parser_xref_tag (ident_loc
, code
, ident
);
2311 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
2312 the trailing semicolon.
2315 specifier-qualifier-list struct-declarator-list
2316 static_assert-declaration-no-semi
2318 specifier-qualifier-list:
2319 type-specifier specifier-qualifier-list[opt]
2320 type-qualifier specifier-qualifier-list[opt]
2321 attributes specifier-qualifier-list[opt]
2323 struct-declarator-list:
2325 struct-declarator-list , attributes[opt] struct-declarator
2328 declarator attributes[opt]
2329 declarator[opt] : constant-expression attributes[opt]
2334 __extension__ struct-declaration
2335 specifier-qualifier-list
2337 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
2338 of attributes where shown is a GNU extension. In GNU C, we accept
2339 any expression without commas in the syntax (assignment
2340 expressions, not just conditional expressions); assignment
2341 expressions will be diagnosed as non-constant. */
2344 c_parser_struct_declaration (c_parser
*parser
)
2346 struct c_declspecs
*specs
;
2348 tree all_prefix_attrs
;
2350 location_t decl_loc
;
2351 if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
2355 ext
= disable_extension_diagnostics ();
2356 c_parser_consume_token (parser
);
2357 decl
= c_parser_struct_declaration (parser
);
2358 restore_extension_diagnostics (ext
);
2361 if (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
2363 c_parser_static_assert_declaration_no_semi (parser
);
2366 specs
= build_null_declspecs ();
2367 decl_loc
= c_parser_peek_token (parser
)->location
;
2368 c_parser_declspecs (parser
, specs
, false, true, true);
2371 if (!specs
->declspecs_seen_p
)
2373 c_parser_error (parser
, "expected specifier-qualifier-list");
2376 finish_declspecs (specs
);
2377 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2380 if (!specs
->type_seen_p
)
2382 pedwarn (decl_loc
, OPT_pedantic
,
2383 "ISO C forbids member declarations with no members");
2384 shadow_tag_warned (specs
, pedantic
);
2389 /* Support for unnamed structs or unions as members of
2390 structs or unions (which is [a] useful and [b] supports
2394 ret
= grokfield (c_parser_peek_token (parser
)->location
,
2395 build_id_declarator (NULL_TREE
), specs
,
2398 decl_attributes (&ret
, attrs
, 0);
2402 pending_xref_error ();
2403 prefix_attrs
= specs
->attrs
;
2404 all_prefix_attrs
= prefix_attrs
;
2405 specs
->attrs
= NULL_TREE
;
2409 /* Declaring one or more declarators or un-named bit-fields. */
2410 struct c_declarator
*declarator
;
2412 if (c_parser_next_token_is (parser
, CPP_COLON
))
2413 declarator
= build_id_declarator (NULL_TREE
);
2415 declarator
= c_parser_declarator (parser
, specs
->type_seen_p
,
2416 C_DTR_NORMAL
, &dummy
);
2417 if (declarator
== NULL
)
2419 c_parser_skip_to_end_of_block_or_statement (parser
);
2422 if (c_parser_next_token_is (parser
, CPP_COLON
)
2423 || c_parser_next_token_is (parser
, CPP_COMMA
)
2424 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2425 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
)
2426 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2428 tree postfix_attrs
= NULL_TREE
;
2429 tree width
= NULL_TREE
;
2431 if (c_parser_next_token_is (parser
, CPP_COLON
))
2433 c_parser_consume_token (parser
);
2434 width
= c_parser_expr_no_commas (parser
, NULL
).value
;
2436 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2437 postfix_attrs
= c_parser_attributes (parser
);
2438 d
= grokfield (c_parser_peek_token (parser
)->location
,
2439 declarator
, specs
, width
, &all_prefix_attrs
);
2440 decl_attributes (&d
, chainon (postfix_attrs
,
2441 all_prefix_attrs
), 0);
2442 DECL_CHAIN (d
) = decls
;
2444 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2445 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
2448 all_prefix_attrs
= prefix_attrs
;
2449 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2450 c_parser_consume_token (parser
);
2451 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2452 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2454 /* Semicolon consumed in caller. */
2459 c_parser_error (parser
, "expected %<,%>, %<;%> or %<}%>");
2465 c_parser_error (parser
,
2466 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
2467 "%<__attribute__%>");
2474 /* Parse a typeof specifier (a GNU extension).
2477 typeof ( expression )
2478 typeof ( type-name )
2481 static struct c_typespec
2482 c_parser_typeof_specifier (c_parser
*parser
)
2484 struct c_typespec ret
;
2485 ret
.kind
= ctsk_typeof
;
2486 ret
.spec
= error_mark_node
;
2487 ret
.expr
= NULL_TREE
;
2488 ret
.expr_const_operands
= true;
2489 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TYPEOF
));
2490 c_parser_consume_token (parser
);
2491 c_inhibit_evaluation_warnings
++;
2493 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2495 c_inhibit_evaluation_warnings
--;
2499 if (c_parser_next_token_starts_typename (parser
))
2501 struct c_type_name
*type
= c_parser_type_name (parser
);
2502 c_inhibit_evaluation_warnings
--;
2506 ret
.spec
= groktypename (type
, &ret
.expr
, &ret
.expr_const_operands
);
2507 pop_maybe_used (variably_modified_type_p (ret
.spec
, NULL_TREE
));
2513 location_t here
= c_parser_peek_token (parser
)->location
;
2514 struct c_expr expr
= c_parser_expression (parser
);
2515 c_inhibit_evaluation_warnings
--;
2517 if (TREE_CODE (expr
.value
) == COMPONENT_REF
2518 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
2519 error_at (here
, "%<typeof%> applied to a bit-field");
2520 mark_exp_read (expr
.value
);
2521 ret
.spec
= TREE_TYPE (expr
.value
);
2522 if (c_dialect_objc()
2523 && ret
.spec
!= error_mark_node
2524 && lookup_attribute ("objc_volatilized", TYPE_ATTRIBUTES (ret
.spec
)))
2525 ret
.spec
= build_qualified_type
2526 (ret
.spec
, (TYPE_QUALS (ret
.spec
) & ~TYPE_QUAL_VOLATILE
));
2527 was_vm
= variably_modified_type_p (ret
.spec
, NULL_TREE
);
2528 /* This is returned with the type so that when the type is
2529 evaluated, this can be evaluated. */
2531 ret
.expr
= c_fully_fold (expr
.value
, false, &ret
.expr_const_operands
);
2532 pop_maybe_used (was_vm
);
2534 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
2538 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
2539 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
2540 be redeclared; otherwise it may not. KIND indicates which kind of
2541 declarator is wanted. Returns a valid declarator except in the
2542 case of a syntax error in which case NULL is returned. *SEEN_ID is
2543 set to true if an identifier being declared is seen; this is used
2544 to diagnose bad forms of abstract array declarators and to
2545 determine whether an identifier list is syntactically permitted.
2548 pointer[opt] direct-declarator
2552 ( attributes[opt] declarator )
2553 direct-declarator array-declarator
2554 direct-declarator ( parameter-type-list )
2555 direct-declarator ( identifier-list[opt] )
2558 * type-qualifier-list[opt]
2559 * type-qualifier-list[opt] pointer
2561 type-qualifier-list:
2564 type-qualifier-list type-qualifier
2565 type-qualifier-list attributes
2567 parameter-type-list:
2569 parameter-list , ...
2572 parameter-declaration
2573 parameter-list , parameter-declaration
2575 parameter-declaration:
2576 declaration-specifiers declarator attributes[opt]
2577 declaration-specifiers abstract-declarator[opt] attributes[opt]
2581 identifier-list , identifier
2583 abstract-declarator:
2585 pointer[opt] direct-abstract-declarator
2587 direct-abstract-declarator:
2588 ( attributes[opt] abstract-declarator )
2589 direct-abstract-declarator[opt] array-declarator
2590 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
2595 direct-declarator ( parameter-forward-declarations
2596 parameter-type-list[opt] )
2598 direct-abstract-declarator:
2599 direct-abstract-declarator[opt] ( parameter-forward-declarations
2600 parameter-type-list[opt] )
2602 parameter-forward-declarations:
2604 parameter-forward-declarations parameter-list ;
2606 The uses of attributes shown above are GNU extensions.
2608 Some forms of array declarator are not included in C99 in the
2609 syntax for abstract declarators; these are disallowed elsewhere.
2610 This may be a defect (DR#289).
2612 This function also accepts an omitted abstract declarator as being
2613 an abstract declarator, although not part of the formal syntax. */
2615 static struct c_declarator
*
2616 c_parser_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
2619 /* Parse any initial pointer part. */
2620 if (c_parser_next_token_is (parser
, CPP_MULT
))
2622 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
2623 struct c_declarator
*inner
;
2624 c_parser_consume_token (parser
);
2625 c_parser_declspecs (parser
, quals_attrs
, false, false, true);
2626 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
2630 return make_pointer_declarator (quals_attrs
, inner
);
2632 /* Now we have a direct declarator, direct abstract declarator or
2633 nothing (which counts as a direct abstract declarator here). */
2634 return c_parser_direct_declarator (parser
, type_seen_p
, kind
, seen_id
);
2637 /* Parse a direct declarator or direct abstract declarator; arguments
2638 as c_parser_declarator. */
2640 static struct c_declarator
*
2641 c_parser_direct_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
2644 /* The direct declarator must start with an identifier (possibly
2645 omitted) or a parenthesized declarator (possibly abstract). In
2646 an ordinary declarator, initial parentheses must start a
2647 parenthesized declarator. In an abstract declarator or parameter
2648 declarator, they could start a parenthesized declarator or a
2649 parameter list. To tell which, the open parenthesis and any
2650 following attributes must be read. If a declaration specifier
2651 follows, then it is a parameter list; if the specifier is a
2652 typedef name, there might be an ambiguity about redeclaring it,
2653 which is resolved in the direction of treating it as a typedef
2654 name. If a close parenthesis follows, it is also an empty
2655 parameter list, as the syntax does not permit empty abstract
2656 declarators. Otherwise, it is a parenthesized declarator (in
2657 which case the analysis may be repeated inside it, recursively).
2659 ??? There is an ambiguity in a parameter declaration "int
2660 (__attribute__((foo)) x)", where x is not a typedef name: it
2661 could be an abstract declarator for a function, or declare x with
2662 parentheses. The proper resolution of this ambiguity needs
2663 documenting. At present we follow an accident of the old
2664 parser's implementation, whereby the first parameter must have
2665 some declaration specifiers other than just attributes. Thus as
2666 a parameter declaration it is treated as a parenthesized
2667 parameter named x, and as an abstract declarator it is
2670 ??? Also following the old parser, attributes inside an empty
2671 parameter list are ignored, making it a list not yielding a
2672 prototype, rather than giving an error or making it have one
2673 parameter with implicit type int.
2675 ??? Also following the old parser, typedef names may be
2676 redeclared in declarators, but not Objective-C class names. */
2678 if (kind
!= C_DTR_ABSTRACT
2679 && c_parser_next_token_is (parser
, CPP_NAME
)
2681 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
2682 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
2683 || c_parser_peek_token (parser
)->id_kind
== C_ID_ID
))
2685 struct c_declarator
*inner
2686 = build_id_declarator (c_parser_peek_token (parser
)->value
);
2688 inner
->id_loc
= c_parser_peek_token (parser
)->location
;
2689 c_parser_consume_token (parser
);
2690 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
2693 if (kind
!= C_DTR_NORMAL
2694 && c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
2696 struct c_declarator
*inner
= build_id_declarator (NULL_TREE
);
2697 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
2700 /* Either we are at the end of an abstract declarator, or we have
2703 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
2706 struct c_declarator
*inner
;
2707 c_parser_consume_token (parser
);
2708 attrs
= c_parser_attributes (parser
);
2709 if (kind
!= C_DTR_NORMAL
2710 && (c_parser_next_token_starts_declspecs (parser
)
2711 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
)))
2713 struct c_arg_info
*args
2714 = c_parser_parms_declarator (parser
, kind
== C_DTR_NORMAL
,
2721 = build_function_declarator (args
,
2722 build_id_declarator (NULL_TREE
));
2723 return c_parser_direct_declarator_inner (parser
, *seen_id
,
2727 /* A parenthesized declarator. */
2728 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
2729 if (inner
!= NULL
&& attrs
!= NULL
)
2730 inner
= build_attrs_declarator (attrs
, inner
);
2731 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2733 c_parser_consume_token (parser
);
2737 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
2741 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2748 if (kind
== C_DTR_NORMAL
)
2750 c_parser_error (parser
, "expected identifier or %<(%>");
2754 return build_id_declarator (NULL_TREE
);
2758 /* Parse part of a direct declarator or direct abstract declarator,
2759 given that some (in INNER) has already been parsed; ID_PRESENT is
2760 true if an identifier is present, false for an abstract
2763 static struct c_declarator
*
2764 c_parser_direct_declarator_inner (c_parser
*parser
, bool id_present
,
2765 struct c_declarator
*inner
)
2767 /* Parse a sequence of array declarators and parameter lists. */
2768 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
2770 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
2771 struct c_declarator
*declarator
;
2772 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
2776 c_parser_consume_token (parser
);
2777 c_parser_declspecs (parser
, quals_attrs
, false, false, true);
2778 static_seen
= c_parser_next_token_is_keyword (parser
, RID_STATIC
);
2780 c_parser_consume_token (parser
);
2781 if (static_seen
&& !quals_attrs
->declspecs_seen_p
)
2782 c_parser_declspecs (parser
, quals_attrs
, false, false, true);
2783 if (!quals_attrs
->declspecs_seen_p
)
2785 /* If "static" is present, there must be an array dimension.
2786 Otherwise, there may be a dimension, "*", or no
2791 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
2795 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
2800 else if (c_parser_next_token_is (parser
, CPP_MULT
))
2802 if (c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_SQUARE
)
2806 c_parser_consume_token (parser
);
2811 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
2817 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
2820 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
2821 c_parser_consume_token (parser
);
2824 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
2829 mark_exp_read (dimen
);
2830 declarator
= build_array_declarator (brace_loc
, dimen
, quals_attrs
,
2831 static_seen
, star_seen
);
2832 if (declarator
== NULL
)
2834 inner
= set_array_declarator_inner (declarator
, inner
);
2835 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
2837 else if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
2840 struct c_arg_info
*args
;
2841 c_parser_consume_token (parser
);
2842 attrs
= c_parser_attributes (parser
);
2843 args
= c_parser_parms_declarator (parser
, id_present
, attrs
);
2848 inner
= build_function_declarator (args
, inner
);
2849 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
2855 /* Parse a parameter list or identifier list, including the closing
2856 parenthesis but not the opening one. ATTRS are the attributes at
2857 the start of the list. ID_LIST_OK is true if an identifier list is
2858 acceptable; such a list must not have attributes at the start. */
2860 static struct c_arg_info
*
2861 c_parser_parms_declarator (c_parser
*parser
, bool id_list_ok
, tree attrs
)
2864 declare_parm_level ();
2865 /* If the list starts with an identifier, it is an identifier list.
2866 Otherwise, it is either a prototype list or an empty list. */
2869 && c_parser_next_token_is (parser
, CPP_NAME
)
2870 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
2872 tree list
= NULL_TREE
, *nextp
= &list
;
2873 while (c_parser_next_token_is (parser
, CPP_NAME
)
2874 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
2876 *nextp
= build_tree_list (NULL_TREE
,
2877 c_parser_peek_token (parser
)->value
);
2878 nextp
= & TREE_CHAIN (*nextp
);
2879 c_parser_consume_token (parser
);
2880 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
2882 c_parser_consume_token (parser
);
2883 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2885 c_parser_error (parser
, "expected identifier");
2889 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2891 struct c_arg_info
*ret
= build_arg_info ();
2893 c_parser_consume_token (parser
);
2899 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2907 struct c_arg_info
*ret
= c_parser_parms_list_declarator (parser
, attrs
);
2913 /* Parse a parameter list (possibly empty), including the closing
2914 parenthesis but not the opening one. ATTRS are the attributes at
2915 the start of the list. */
2917 static struct c_arg_info
*
2918 c_parser_parms_list_declarator (c_parser
*parser
, tree attrs
)
2920 bool bad_parm
= false;
2921 /* ??? Following the old parser, forward parameter declarations may
2922 use abstract declarators, and if no real parameter declarations
2923 follow the forward declarations then this is not diagnosed. Also
2924 note as above that attributes are ignored as the only contents of
2925 the parentheses, or as the only contents after forward
2927 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2929 struct c_arg_info
*ret
= build_arg_info ();
2930 c_parser_consume_token (parser
);
2933 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
2935 struct c_arg_info
*ret
= build_arg_info ();
2936 /* Suppress -Wold-style-definition for this case. */
2937 ret
->types
= error_mark_node
;
2938 error_at (c_parser_peek_token (parser
)->location
,
2939 "ISO C requires a named argument before %<...%>");
2940 c_parser_consume_token (parser
);
2941 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2943 c_parser_consume_token (parser
);
2948 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2953 /* Nonempty list of parameters, either terminated with semicolon
2954 (forward declarations; recurse) or with close parenthesis (normal
2955 function) or with ", ... )" (variadic function). */
2958 /* Parse a parameter. */
2959 struct c_parm
*parm
= c_parser_parameter_declaration (parser
, attrs
);
2964 push_parm_decl (parm
);
2965 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2968 c_parser_consume_token (parser
);
2969 mark_forward_parm_decls ();
2970 new_attrs
= c_parser_attributes (parser
);
2971 return c_parser_parms_list_declarator (parser
, new_attrs
);
2973 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2975 c_parser_consume_token (parser
);
2978 get_pending_sizes ();
2982 return get_parm_info (false);
2984 if (!c_parser_require (parser
, CPP_COMMA
,
2985 "expected %<;%>, %<,%> or %<)%>"))
2987 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2988 get_pending_sizes ();
2991 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
2993 c_parser_consume_token (parser
);
2994 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2996 c_parser_consume_token (parser
);
2999 get_pending_sizes ();
3003 return get_parm_info (true);
3007 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3009 get_pending_sizes ();
3016 /* Parse a parameter declaration. ATTRS are the attributes at the
3017 start of the declaration if it is the first parameter. */
3019 static struct c_parm
*
3020 c_parser_parameter_declaration (c_parser
*parser
, tree attrs
)
3022 struct c_declspecs
*specs
;
3023 struct c_declarator
*declarator
;
3025 tree postfix_attrs
= NULL_TREE
;
3027 if (!c_parser_next_token_starts_declspecs (parser
))
3029 c_token
*token
= c_parser_peek_token (parser
);
3032 c_parser_set_source_position_from_token (token
);
3033 if (token
->type
== CPP_NAME
3034 && c_parser_peek_2nd_token (parser
)->type
!= CPP_COMMA
3035 && c_parser_peek_2nd_token (parser
)->type
!= CPP_CLOSE_PAREN
)
3037 error ("unknown type name %qE", token
->value
);
3038 parser
->error
= true;
3040 /* ??? In some Objective-C cases '...' isn't applicable so there
3041 should be a different message. */
3043 c_parser_error (parser
,
3044 "expected declaration specifiers or %<...%>");
3045 c_parser_skip_to_end_of_parameter (parser
);
3048 specs
= build_null_declspecs ();
3051 declspecs_add_attrs (specs
, attrs
);
3054 c_parser_declspecs (parser
, specs
, true, true, true);
3055 finish_declspecs (specs
);
3056 pending_xref_error ();
3057 prefix_attrs
= specs
->attrs
;
3058 specs
->attrs
= NULL_TREE
;
3059 declarator
= c_parser_declarator (parser
, specs
->type_seen_p
,
3060 C_DTR_PARM
, &dummy
);
3061 if (declarator
== NULL
)
3063 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3066 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3067 postfix_attrs
= c_parser_attributes (parser
);
3068 return build_c_parm (specs
, chainon (postfix_attrs
, prefix_attrs
),
3072 /* Parse a string literal in an asm expression. It should not be
3073 translated, and wide string literals are an error although
3074 permitted by the syntax. This is a GNU extension.
3079 ??? At present, following the old parser, the caller needs to have
3080 set lex_untranslated_string to 1. It would be better to follow the
3081 C++ parser rather than using this kludge. */
3084 c_parser_asm_string_literal (c_parser
*parser
)
3087 if (c_parser_next_token_is (parser
, CPP_STRING
))
3089 str
= c_parser_peek_token (parser
)->value
;
3090 c_parser_consume_token (parser
);
3092 else if (c_parser_next_token_is (parser
, CPP_WSTRING
))
3094 error_at (c_parser_peek_token (parser
)->location
,
3095 "wide string literal in %<asm%>");
3096 str
= build_string (1, "");
3097 c_parser_consume_token (parser
);
3101 c_parser_error (parser
, "expected string literal");
3107 /* Parse a simple asm expression. This is used in restricted
3108 contexts, where a full expression with inputs and outputs does not
3109 make sense. This is a GNU extension.
3112 asm ( asm-string-literal )
3116 c_parser_simple_asm_expr (c_parser
*parser
)
3119 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
3120 /* ??? Follow the C++ parser rather than using the
3121 lex_untranslated_string kludge. */
3122 parser
->lex_untranslated_string
= true;
3123 c_parser_consume_token (parser
);
3124 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3126 parser
->lex_untranslated_string
= false;
3129 str
= c_parser_asm_string_literal (parser
);
3130 parser
->lex_untranslated_string
= false;
3131 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
3133 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3139 /* Parse (possibly empty) attributes. This is a GNU extension.
3143 attributes attribute
3146 __attribute__ ( ( attribute-list ) )
3150 attribute_list , attrib
3155 any-word ( identifier )
3156 any-word ( identifier , nonempty-expr-list )
3157 any-word ( expr-list )
3159 where the "identifier" must not be declared as a type, and
3160 "any-word" may be any identifier (including one declared as a
3161 type), a reserved word storage class specifier, type specifier or
3162 type qualifier. ??? This still leaves out most reserved keywords
3163 (following the old parser), shouldn't we include them, and why not
3164 allow identifiers declared as types to start the arguments? */
3167 c_parser_attributes (c_parser
*parser
)
3169 tree attrs
= NULL_TREE
;
3170 while (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3172 /* ??? Follow the C++ parser rather than using the
3173 lex_untranslated_string kludge. */
3174 parser
->lex_untranslated_string
= true;
3175 c_parser_consume_token (parser
);
3176 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3178 parser
->lex_untranslated_string
= false;
3181 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3183 parser
->lex_untranslated_string
= false;
3184 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3187 /* Parse the attribute list. */
3188 while (c_parser_next_token_is (parser
, CPP_COMMA
)
3189 || c_parser_next_token_is (parser
, CPP_NAME
)
3190 || c_parser_next_token_is (parser
, CPP_KEYWORD
))
3192 tree attr
, attr_name
, attr_args
;
3193 VEC(tree
,gc
) *expr_list
;
3194 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3196 c_parser_consume_token (parser
);
3199 if (c_parser_next_token_is (parser
, CPP_KEYWORD
))
3201 /* ??? See comment above about what keywords are
3204 switch (c_parser_peek_token (parser
)->keyword
)
3242 /* Accept __attribute__((__const)) as __attribute__((const))
3245 = ridpointers
[(int) c_parser_peek_token (parser
)->keyword
];
3248 attr_name
= c_parser_peek_token (parser
)->value
;
3249 c_parser_consume_token (parser
);
3250 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
3252 attr
= build_tree_list (attr_name
, NULL_TREE
);
3253 attrs
= chainon (attrs
, attr
);
3256 c_parser_consume_token (parser
);
3257 /* Parse the attribute contents. If they start with an
3258 identifier which is followed by a comma or close
3259 parenthesis, then the arguments start with that
3260 identifier; otherwise they are an expression list. */
3261 if (c_parser_next_token_is (parser
, CPP_NAME
)
3262 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
3263 && ((c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
)
3264 || (c_parser_peek_2nd_token (parser
)->type
3265 == CPP_CLOSE_PAREN
)))
3267 tree arg1
= c_parser_peek_token (parser
)->value
;
3268 c_parser_consume_token (parser
);
3269 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3270 attr_args
= build_tree_list (NULL_TREE
, arg1
);
3274 c_parser_consume_token (parser
);
3275 expr_list
= c_parser_expr_list (parser
, false, true, NULL
);
3276 tree_list
= build_tree_list_vec (expr_list
);
3277 attr_args
= tree_cons (NULL_TREE
, arg1
, tree_list
);
3278 release_tree_vector (expr_list
);
3283 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3284 attr_args
= NULL_TREE
;
3287 expr_list
= c_parser_expr_list (parser
, false, true, NULL
);
3288 attr_args
= build_tree_list_vec (expr_list
);
3289 release_tree_vector (expr_list
);
3292 attr
= build_tree_list (attr_name
, attr_args
);
3293 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3294 c_parser_consume_token (parser
);
3297 parser
->lex_untranslated_string
= false;
3298 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3302 attrs
= chainon (attrs
, attr
);
3304 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3305 c_parser_consume_token (parser
);
3308 parser
->lex_untranslated_string
= false;
3309 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3313 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3314 c_parser_consume_token (parser
);
3317 parser
->lex_untranslated_string
= false;
3318 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3322 parser
->lex_untranslated_string
= false;
3327 /* Parse a type name (C90 6.5.5, C99 6.7.6).
3330 specifier-qualifier-list abstract-declarator[opt]
3333 static struct c_type_name
*
3334 c_parser_type_name (c_parser
*parser
)
3336 struct c_declspecs
*specs
= build_null_declspecs ();
3337 struct c_declarator
*declarator
;
3338 struct c_type_name
*ret
;
3340 c_parser_declspecs (parser
, specs
, false, true, true);
3341 if (!specs
->declspecs_seen_p
)
3343 c_parser_error (parser
, "expected specifier-qualifier-list");
3346 pending_xref_error ();
3347 finish_declspecs (specs
);
3348 declarator
= c_parser_declarator (parser
, specs
->type_seen_p
,
3349 C_DTR_ABSTRACT
, &dummy
);
3350 if (declarator
== NULL
)
3352 ret
= XOBNEW (&parser_obstack
, struct c_type_name
);
3354 ret
->declarator
= declarator
;
3358 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
3361 assignment-expression
3362 { initializer-list }
3363 { initializer-list , }
3366 designation[opt] initializer
3367 initializer-list , designation[opt] initializer
3374 designator-list designator
3381 [ constant-expression ]
3393 [ constant-expression ... constant-expression ]
3395 Any expression without commas is accepted in the syntax for the
3396 constant-expressions, with non-constant expressions rejected later.
3398 This function is only used for top-level initializers; for nested
3399 ones, see c_parser_initval. */
3401 static struct c_expr
3402 c_parser_initializer (c_parser
*parser
)
3404 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
3405 return c_parser_braced_init (parser
, NULL_TREE
, false);
3409 location_t loc
= c_parser_peek_token (parser
)->location
;
3410 ret
= c_parser_expr_no_commas (parser
, NULL
);
3411 if (TREE_CODE (ret
.value
) != STRING_CST
3412 && TREE_CODE (ret
.value
) != COMPOUND_LITERAL_EXPR
)
3413 ret
= default_function_array_read_conversion (loc
, ret
);
3418 /* Parse a braced initializer list. TYPE is the type specified for a
3419 compound literal, and NULL_TREE for other initializers and for
3420 nested braced lists. NESTED_P is true for nested braced lists,
3421 false for the list of a compound literal or the list that is the
3422 top-level initializer in a declaration. */
3424 static struct c_expr
3425 c_parser_braced_init (c_parser
*parser
, tree type
, bool nested_p
)
3428 struct obstack braced_init_obstack
;
3429 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
3430 gcc_obstack_init (&braced_init_obstack
);
3431 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
3432 c_parser_consume_token (parser
);
3434 push_init_level (0, &braced_init_obstack
);
3436 really_start_incremental_init (type
);
3437 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3439 pedwarn (brace_loc
, OPT_pedantic
, "ISO C forbids empty initializer braces");
3443 /* Parse a non-empty initializer list, possibly with a trailing
3447 c_parser_initelt (parser
, &braced_init_obstack
);
3450 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3451 c_parser_consume_token (parser
);
3454 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3458 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
3460 ret
.value
= error_mark_node
;
3461 ret
.original_code
= ERROR_MARK
;
3462 ret
.original_type
= NULL
;
3463 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
3464 pop_init_level (0, &braced_init_obstack
);
3465 obstack_free (&braced_init_obstack
, NULL
);
3468 c_parser_consume_token (parser
);
3469 ret
= pop_init_level (0, &braced_init_obstack
);
3470 obstack_free (&braced_init_obstack
, NULL
);
3474 /* Parse a nested initializer, including designators. */
3477 c_parser_initelt (c_parser
*parser
, struct obstack
* braced_init_obstack
)
3479 /* Parse any designator or designator list. A single array
3480 designator may have the subsequent "=" omitted in GNU C, but a
3481 longer list or a structure member designator may not. */
3482 if (c_parser_next_token_is (parser
, CPP_NAME
)
3483 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
3485 /* Old-style structure member designator. */
3486 set_init_label (c_parser_peek_token (parser
)->value
,
3487 braced_init_obstack
);
3488 /* Use the colon as the error location. */
3489 pedwarn (c_parser_peek_2nd_token (parser
)->location
, OPT_pedantic
,
3490 "obsolete use of designated initializer with %<:%>");
3491 c_parser_consume_token (parser
);
3492 c_parser_consume_token (parser
);
3496 /* des_seen is 0 if there have been no designators, 1 if there
3497 has been a single array designator and 2 otherwise. */
3499 /* Location of a designator. */
3500 location_t des_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
3501 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
)
3502 || c_parser_next_token_is (parser
, CPP_DOT
))
3504 int des_prev
= des_seen
;
3506 des_loc
= c_parser_peek_token (parser
)->location
;
3509 if (c_parser_next_token_is (parser
, CPP_DOT
))
3512 c_parser_consume_token (parser
);
3513 if (c_parser_next_token_is (parser
, CPP_NAME
))
3515 set_init_label (c_parser_peek_token (parser
)->value
,
3516 braced_init_obstack
);
3517 c_parser_consume_token (parser
);
3522 init
.value
= error_mark_node
;
3523 init
.original_code
= ERROR_MARK
;
3524 init
.original_type
= NULL
;
3525 c_parser_error (parser
, "expected identifier");
3526 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3527 process_init_element (init
, false, braced_init_obstack
);
3534 location_t ellipsis_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
3535 /* ??? Following the old parser, [ objc-receiver
3536 objc-message-args ] is accepted as an initializer,
3537 being distinguished from a designator by what follows
3538 the first assignment expression inside the square
3539 brackets, but after a first array designator a
3540 subsequent square bracket is for Objective-C taken to
3541 start an expression, using the obsolete form of
3542 designated initializer without '=', rather than
3543 possibly being a second level of designation: in LALR
3544 terms, the '[' is shifted rather than reducing
3545 designator to designator-list. */
3546 if (des_prev
== 1 && c_dialect_objc ())
3548 des_seen
= des_prev
;
3551 if (des_prev
== 0 && c_dialect_objc ())
3553 /* This might be an array designator or an
3554 Objective-C message expression. If the former,
3555 continue parsing here; if the latter, parse the
3556 remainder of the initializer given the starting
3557 primary-expression. ??? It might make sense to
3558 distinguish when des_prev == 1 as well; see
3559 previous comment. */
3561 struct c_expr mexpr
;
3562 c_parser_consume_token (parser
);
3563 if (c_parser_peek_token (parser
)->type
== CPP_NAME
3564 && ((c_parser_peek_token (parser
)->id_kind
3566 || (c_parser_peek_token (parser
)->id_kind
3567 == C_ID_CLASSNAME
)))
3569 /* Type name receiver. */
3570 tree id
= c_parser_peek_token (parser
)->value
;
3571 c_parser_consume_token (parser
);
3572 rec
= objc_get_class_reference (id
);
3573 goto parse_message_args
;
3575 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
3576 mark_exp_read (first
);
3577 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
)
3578 || c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3579 goto array_desig_after_first
;
3580 /* Expression receiver. So far only one part
3581 without commas has been parsed; there might be
3582 more of the expression. */
3584 while (c_parser_next_token_is (parser
, CPP_COMMA
))
3587 location_t comma_loc
, exp_loc
;
3588 comma_loc
= c_parser_peek_token (parser
)->location
;
3589 c_parser_consume_token (parser
);
3590 exp_loc
= c_parser_peek_token (parser
)->location
;
3591 next
= c_parser_expr_no_commas (parser
, NULL
);
3592 next
= default_function_array_read_conversion (exp_loc
,
3594 rec
= build_compound_expr (comma_loc
, rec
, next
.value
);
3597 /* Now parse the objc-message-args. */
3598 args
= c_parser_objc_message_args (parser
);
3599 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3602 = objc_build_message_expr (build_tree_list (rec
, args
));
3603 mexpr
.original_code
= ERROR_MARK
;
3604 mexpr
.original_type
= NULL
;
3605 /* Now parse and process the remainder of the
3606 initializer, starting with this message
3607 expression as a primary-expression. */
3608 c_parser_initval (parser
, &mexpr
, braced_init_obstack
);
3611 c_parser_consume_token (parser
);
3612 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
3613 mark_exp_read (first
);
3614 array_desig_after_first
:
3615 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3617 ellipsis_loc
= c_parser_peek_token (parser
)->location
;
3618 c_parser_consume_token (parser
);
3619 second
= c_parser_expr_no_commas (parser
, NULL
).value
;
3620 mark_exp_read (second
);
3624 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3626 c_parser_consume_token (parser
);
3627 set_init_index (first
, second
, braced_init_obstack
);
3629 pedwarn (ellipsis_loc
, OPT_pedantic
,
3630 "ISO C forbids specifying range of elements to initialize");
3633 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3639 if (c_parser_next_token_is (parser
, CPP_EQ
))
3642 pedwarn (des_loc
, OPT_pedantic
,
3643 "ISO C90 forbids specifying subobject to initialize");
3644 c_parser_consume_token (parser
);
3649 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
3650 "obsolete use of designated initializer without %<=%>");
3654 init
.value
= error_mark_node
;
3655 init
.original_code
= ERROR_MARK
;
3656 init
.original_type
= NULL
;
3657 c_parser_error (parser
, "expected %<=%>");
3658 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3659 process_init_element (init
, false, braced_init_obstack
);
3665 c_parser_initval (parser
, NULL
, braced_init_obstack
);
3668 /* Parse a nested initializer; as c_parser_initializer but parses
3669 initializers within braced lists, after any designators have been
3670 applied. If AFTER is not NULL then it is an Objective-C message
3671 expression which is the primary-expression starting the
3675 c_parser_initval (c_parser
*parser
, struct c_expr
*after
,
3676 struct obstack
* braced_init_obstack
)
3679 gcc_assert (!after
|| c_dialect_objc ());
3680 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
) && !after
)
3681 init
= c_parser_braced_init (parser
, NULL_TREE
, true);
3684 location_t loc
= c_parser_peek_token (parser
)->location
;
3685 init
= c_parser_expr_no_commas (parser
, after
);
3686 if (init
.value
!= NULL_TREE
3687 && TREE_CODE (init
.value
) != STRING_CST
3688 && TREE_CODE (init
.value
) != COMPOUND_LITERAL_EXPR
)
3689 init
= default_function_array_read_conversion (loc
, init
);
3691 process_init_element (init
, false, braced_init_obstack
);
3694 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
3698 { block-item-list[opt] }
3699 { label-declarations block-item-list }
3703 block-item-list block-item
3715 { label-declarations block-item-list }
3718 __extension__ nested-declaration
3719 nested-function-definition
3723 label-declarations label-declaration
3726 __label__ identifier-list ;
3728 Allowing the mixing of declarations and code is new in C99. The
3729 GNU syntax also permits (not shown above) labels at the end of
3730 compound statements, which yield an error. We don't allow labels
3731 on declarations; this might seem like a natural extension, but
3732 there would be a conflict between attributes on the label and
3733 prefix attributes on the declaration. ??? The syntax follows the
3734 old parser in requiring something after label declarations.
3735 Although they are erroneous if the labels declared aren't defined,
3736 is it useful for the syntax to be this way?
3748 c_parser_compound_statement (c_parser
*parser
)
3751 location_t brace_loc
;
3752 brace_loc
= c_parser_peek_token (parser
)->location
;
3753 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
3755 /* Ensure a scope is entered and left anyway to avoid confusion
3756 if we have just prepared to enter a function body. */
3757 stmt
= c_begin_compound_stmt (true);
3758 c_end_compound_stmt (brace_loc
, stmt
, true);
3759 return error_mark_node
;
3761 stmt
= c_begin_compound_stmt (true);
3762 c_parser_compound_statement_nostart (parser
);
3763 return c_end_compound_stmt (brace_loc
, stmt
, true);
3766 /* Parse a compound statement except for the opening brace. This is
3767 used for parsing both compound statements and statement expressions
3768 (which follow different paths to handling the opening). */
3771 c_parser_compound_statement_nostart (c_parser
*parser
)
3773 bool last_stmt
= false;
3774 bool last_label
= false;
3775 bool save_valid_for_pragma
= valid_location_for_stdc_pragma_p ();
3776 location_t label_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
3777 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3779 c_parser_consume_token (parser
);
3782 mark_valid_location_for_stdc_pragma (true);
3783 if (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
3785 /* Read zero or more forward-declarations for labels that nested
3786 functions can jump to. */
3787 mark_valid_location_for_stdc_pragma (false);
3788 while (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
3790 label_loc
= c_parser_peek_token (parser
)->location
;
3791 c_parser_consume_token (parser
);
3792 /* Any identifiers, including those declared as type names,
3797 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
3799 c_parser_error (parser
, "expected identifier");
3803 = declare_label (c_parser_peek_token (parser
)->value
);
3804 C_DECLARED_LABEL_FLAG (label
) = 1;
3805 add_stmt (build_stmt (label_loc
, DECL_EXPR
, label
));
3806 c_parser_consume_token (parser
);
3807 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3808 c_parser_consume_token (parser
);
3812 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
3814 pedwarn (label_loc
, OPT_pedantic
, "ISO C forbids label declarations");
3816 /* We must now have at least one statement, label or declaration. */
3817 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3819 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
3820 c_parser_error (parser
, "expected declaration or statement");
3821 c_parser_consume_token (parser
);
3824 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
3826 location_t loc
= c_parser_peek_token (parser
)->location
;
3827 if (c_parser_next_token_is_keyword (parser
, RID_CASE
)
3828 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
3829 || (c_parser_next_token_is (parser
, CPP_NAME
)
3830 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
3832 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
3833 label_loc
= c_parser_peek_2nd_token (parser
)->location
;
3835 label_loc
= c_parser_peek_token (parser
)->location
;
3838 mark_valid_location_for_stdc_pragma (false);
3839 c_parser_label (parser
);
3841 else if (!last_label
3842 && c_parser_next_token_starts_declaration (parser
))
3845 mark_valid_location_for_stdc_pragma (false);
3846 c_parser_declaration_or_fndef (parser
, true, true, true, true, true, NULL
);
3849 (pedantic
&& !flag_isoc99
)
3851 : OPT_Wdeclaration_after_statement
,
3852 "ISO C90 forbids mixed declarations and code");
3855 else if (!last_label
3856 && c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
3858 /* __extension__ can start a declaration, but is also an
3859 unary operator that can start an expression. Consume all
3860 but the last of a possible series of __extension__ to
3862 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
3863 && (c_parser_peek_2nd_token (parser
)->keyword
3865 c_parser_consume_token (parser
);
3866 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
3869 ext
= disable_extension_diagnostics ();
3870 c_parser_consume_token (parser
);
3872 mark_valid_location_for_stdc_pragma (false);
3873 c_parser_declaration_or_fndef (parser
, true, true, true, true,
3875 /* Following the old parser, __extension__ does not
3876 disable this diagnostic. */
3877 restore_extension_diagnostics (ext
);
3879 pedwarn_c90 (loc
, (pedantic
&& !flag_isoc99
)
3881 : OPT_Wdeclaration_after_statement
,
3882 "ISO C90 forbids mixed declarations and code");
3888 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
3890 /* External pragmas, and some omp pragmas, are not associated
3891 with regular c code, and so are not to be considered statements
3892 syntactically. This ensures that the user doesn't put them
3893 places that would turn into syntax errors if the directive
3895 if (c_parser_pragma (parser
, pragma_compound
))
3896 last_label
= false, last_stmt
= true;
3898 else if (c_parser_next_token_is (parser
, CPP_EOF
))
3900 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
3901 c_parser_error (parser
, "expected declaration or statement");
3904 else if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
3906 if (parser
->in_if_block
)
3908 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
3909 error_at (loc
, """expected %<}%> before %<else%>");
3914 error_at (loc
, "%<else%> without a previous %<if%>");
3915 c_parser_consume_token (parser
);
3924 mark_valid_location_for_stdc_pragma (false);
3925 c_parser_statement_after_labels (parser
);
3928 parser
->error
= false;
3931 error_at (label_loc
, "label at end of compound statement");
3932 c_parser_consume_token (parser
);
3933 /* Restore the value we started with. */
3934 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
3937 /* Parse a label (C90 6.6.1, C99 6.8.1).
3940 identifier : attributes[opt]
3941 case constant-expression :
3947 case constant-expression ... constant-expression :
3949 The use of attributes on labels is a GNU extension. The syntax in
3950 GNU C accepts any expressions without commas, non-constant
3951 expressions being rejected later. */
3954 c_parser_label (c_parser
*parser
)
3956 location_t loc1
= c_parser_peek_token (parser
)->location
;
3957 tree label
= NULL_TREE
;
3958 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
3961 c_parser_consume_token (parser
);
3962 exp1
= c_parser_expr_no_commas (parser
, NULL
).value
;
3963 if (c_parser_next_token_is (parser
, CPP_COLON
))
3965 c_parser_consume_token (parser
);
3966 label
= do_case (loc1
, exp1
, NULL_TREE
);
3968 else if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3970 c_parser_consume_token (parser
);
3971 exp2
= c_parser_expr_no_commas (parser
, NULL
).value
;
3972 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
3973 label
= do_case (loc1
, exp1
, exp2
);
3976 c_parser_error (parser
, "expected %<:%> or %<...%>");
3978 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
3980 c_parser_consume_token (parser
);
3981 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
3982 label
= do_case (loc1
, NULL_TREE
, NULL_TREE
);
3986 tree name
= c_parser_peek_token (parser
)->value
;
3989 location_t loc2
= c_parser_peek_token (parser
)->location
;
3990 gcc_assert (c_parser_next_token_is (parser
, CPP_NAME
));
3991 c_parser_consume_token (parser
);
3992 gcc_assert (c_parser_next_token_is (parser
, CPP_COLON
));
3993 c_parser_consume_token (parser
);
3994 attrs
= c_parser_attributes (parser
);
3995 tlab
= define_label (loc2
, name
);
3998 decl_attributes (&tlab
, attrs
, 0);
3999 label
= add_stmt (build_stmt (loc1
, LABEL_EXPR
, tlab
));
4004 if (c_parser_next_token_starts_declaration (parser
)
4005 && !(c_parser_next_token_is (parser
, CPP_NAME
)
4006 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4008 error_at (c_parser_peek_token (parser
)->location
,
4009 "a label can only be part of a statement and "
4010 "a declaration is not a statement");
4011 c_parser_declaration_or_fndef (parser
, /*fndef_ok*/ false,
4012 /*static_assert_ok*/ true,
4013 /*nested*/ true, /*empty_ok*/ false,
4014 /*start_attr_ok*/ true, NULL
);
4019 /* Parse a statement (C90 6.6, C99 6.8).
4024 expression-statement
4032 expression-statement:
4035 selection-statement:
4039 iteration-statement:
4048 return expression[opt] ;
4061 objc-throw-statement
4062 objc-try-catch-statement
4063 objc-synchronized-statement
4065 objc-throw-statement:
4079 parallel-for-construct
4080 parallel-sections-construct
4087 parallel-directive structured-block
4090 for-directive iteration-statement
4093 sections-directive section-scope
4096 single-directive structured-block
4098 parallel-for-construct:
4099 parallel-for-directive iteration-statement
4101 parallel-sections-construct:
4102 parallel-sections-directive section-scope
4105 master-directive structured-block
4108 critical-directive structured-block
4111 atomic-directive expression-statement
4114 ordered-directive structured-block */
4117 c_parser_statement (c_parser
*parser
)
4119 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4120 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4121 || (c_parser_next_token_is (parser
, CPP_NAME
)
4122 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4123 c_parser_label (parser
);
4124 c_parser_statement_after_labels (parser
);
4127 /* Parse a statement, other than a labeled statement. */
4130 c_parser_statement_after_labels (c_parser
*parser
)
4132 location_t loc
= c_parser_peek_token (parser
)->location
;
4133 tree stmt
= NULL_TREE
;
4134 bool in_if_block
= parser
->in_if_block
;
4135 parser
->in_if_block
= false;
4136 switch (c_parser_peek_token (parser
)->type
)
4138 case CPP_OPEN_BRACE
:
4139 add_stmt (c_parser_compound_statement (parser
));
4142 switch (c_parser_peek_token (parser
)->keyword
)
4145 c_parser_if_statement (parser
);
4148 c_parser_switch_statement (parser
);
4151 c_parser_while_statement (parser
);
4154 c_parser_do_statement (parser
);
4157 c_parser_for_statement (parser
);
4160 c_parser_consume_token (parser
);
4161 if (c_parser_next_token_is (parser
, CPP_NAME
))
4163 stmt
= c_finish_goto_label (loc
,
4164 c_parser_peek_token (parser
)->value
);
4165 c_parser_consume_token (parser
);
4167 else if (c_parser_next_token_is (parser
, CPP_MULT
))
4171 c_parser_consume_token (parser
);
4172 val
= c_parser_expression (parser
).value
;
4173 mark_exp_read (val
);
4174 stmt
= c_finish_goto_ptr (loc
, val
);
4177 c_parser_error (parser
, "expected identifier or %<*%>");
4178 goto expect_semicolon
;
4180 c_parser_consume_token (parser
);
4181 stmt
= c_finish_bc_stmt (loc
, &c_cont_label
, false);
4182 goto expect_semicolon
;
4184 c_parser_consume_token (parser
);
4185 stmt
= c_finish_bc_stmt (loc
, &c_break_label
, true);
4186 goto expect_semicolon
;
4188 c_parser_consume_token (parser
);
4189 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4191 stmt
= c_finish_return (loc
, NULL_TREE
, NULL_TREE
);
4192 c_parser_consume_token (parser
);
4196 struct c_expr expr
= c_parser_expression_conv (parser
);
4197 mark_exp_read (expr
.value
);
4198 stmt
= c_finish_return (loc
, expr
.value
, expr
.original_type
);
4199 goto expect_semicolon
;
4203 stmt
= c_parser_asm_statement (parser
);
4206 gcc_assert (c_dialect_objc ());
4207 c_parser_consume_token (parser
);
4208 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4210 stmt
= objc_build_throw_stmt (loc
, NULL_TREE
);
4211 c_parser_consume_token (parser
);
4215 tree expr
= c_parser_expression (parser
).value
;
4216 expr
= c_fully_fold (expr
, false, NULL
);
4217 stmt
= objc_build_throw_stmt (loc
, expr
);
4218 goto expect_semicolon
;
4222 gcc_assert (c_dialect_objc ());
4223 c_parser_objc_try_catch_statement (parser
);
4225 case RID_AT_SYNCHRONIZED
:
4226 gcc_assert (c_dialect_objc ());
4227 c_parser_objc_synchronized_statement (parser
);
4234 c_parser_consume_token (parser
);
4236 case CPP_CLOSE_PAREN
:
4237 case CPP_CLOSE_SQUARE
:
4238 /* Avoid infinite loop in error recovery:
4239 c_parser_skip_until_found stops at a closing nesting
4240 delimiter without consuming it, but here we need to consume
4241 it to proceed further. */
4242 c_parser_error (parser
, "expected statement");
4243 c_parser_consume_token (parser
);
4246 c_parser_pragma (parser
, pragma_stmt
);
4250 stmt
= c_finish_expr_stmt (loc
, c_parser_expression_conv (parser
).value
);
4252 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4255 /* Two cases cannot and do not have line numbers associated: If stmt
4256 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
4257 cannot hold line numbers. But that's OK because the statement
4258 will either be changed to a MODIFY_EXPR during gimplification of
4259 the statement expr, or discarded. If stmt was compound, but
4260 without new variables, we will have skipped the creation of a
4261 BIND and will have a bare STATEMENT_LIST. But that's OK because
4262 (recursively) all of the component statements should already have
4263 line numbers assigned. ??? Can we discard no-op statements
4265 if (CAN_HAVE_LOCATION_P (stmt
)
4266 && EXPR_LOCATION (stmt
) == UNKNOWN_LOCATION
)
4267 SET_EXPR_LOCATION (stmt
, loc
);
4269 parser
->in_if_block
= in_if_block
;
4272 /* Parse the condition from an if, do, while or for statements. */
4275 c_parser_condition (c_parser
*parser
)
4277 location_t loc
= c_parser_peek_token (parser
)->location
;
4279 cond
= c_parser_expression_conv (parser
).value
;
4280 cond
= c_objc_common_truthvalue_conversion (loc
, cond
);
4281 cond
= c_fully_fold (cond
, false, NULL
);
4282 if (warn_sequence_point
)
4283 verify_sequence_points (cond
);
4287 /* Parse a parenthesized condition from an if, do or while statement.
4293 c_parser_paren_condition (c_parser
*parser
)
4296 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4297 return error_mark_node
;
4298 cond
= c_parser_condition (parser
);
4299 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4303 /* Parse a statement which is a block in C99. */
4306 c_parser_c99_block_statement (c_parser
*parser
)
4308 tree block
= c_begin_compound_stmt (flag_isoc99
);
4309 location_t loc
= c_parser_peek_token (parser
)->location
;
4310 c_parser_statement (parser
);
4311 return c_end_compound_stmt (loc
, block
, flag_isoc99
);
4314 /* Parse the body of an if statement. This is just parsing a
4315 statement but (a) it is a block in C99, (b) we track whether the
4316 body is an if statement for the sake of -Wparentheses warnings, (c)
4317 we handle an empty body specially for the sake of -Wempty-body
4318 warnings, and (d) we call parser_compound_statement directly
4319 because c_parser_statement_after_labels resets
4320 parser->in_if_block. */
4323 c_parser_if_body (c_parser
*parser
, bool *if_p
)
4325 tree block
= c_begin_compound_stmt (flag_isoc99
);
4326 location_t body_loc
= c_parser_peek_token (parser
)->location
;
4327 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4328 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4329 || (c_parser_next_token_is (parser
, CPP_NAME
)
4330 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4331 c_parser_label (parser
);
4332 *if_p
= c_parser_next_token_is_keyword (parser
, RID_IF
);
4333 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4335 location_t loc
= c_parser_peek_token (parser
)->location
;
4336 add_stmt (build_empty_stmt (loc
));
4337 c_parser_consume_token (parser
);
4338 if (!c_parser_next_token_is_keyword (parser
, RID_ELSE
))
4339 warning_at (loc
, OPT_Wempty_body
,
4340 "suggest braces around empty body in an %<if%> statement");
4342 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4343 add_stmt (c_parser_compound_statement (parser
));
4345 c_parser_statement_after_labels (parser
);
4346 return c_end_compound_stmt (body_loc
, block
, flag_isoc99
);
4349 /* Parse the else body of an if statement. This is just parsing a
4350 statement but (a) it is a block in C99, (b) we handle an empty body
4351 specially for the sake of -Wempty-body warnings. */
4354 c_parser_else_body (c_parser
*parser
)
4356 location_t else_loc
= c_parser_peek_token (parser
)->location
;
4357 tree block
= c_begin_compound_stmt (flag_isoc99
);
4358 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4359 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4360 || (c_parser_next_token_is (parser
, CPP_NAME
)
4361 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4362 c_parser_label (parser
);
4363 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4365 location_t loc
= c_parser_peek_token (parser
)->location
;
4368 "suggest braces around empty body in an %<else%> statement");
4369 add_stmt (build_empty_stmt (loc
));
4370 c_parser_consume_token (parser
);
4373 c_parser_statement_after_labels (parser
);
4374 return c_end_compound_stmt (else_loc
, block
, flag_isoc99
);
4377 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
4380 if ( expression ) statement
4381 if ( expression ) statement else statement
4385 c_parser_if_statement (c_parser
*parser
)
4390 bool first_if
= false;
4391 tree first_body
, second_body
;
4394 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_IF
));
4395 c_parser_consume_token (parser
);
4396 block
= c_begin_compound_stmt (flag_isoc99
);
4397 loc
= c_parser_peek_token (parser
)->location
;
4398 cond
= c_parser_paren_condition (parser
);
4399 in_if_block
= parser
->in_if_block
;
4400 parser
->in_if_block
= true;
4401 first_body
= c_parser_if_body (parser
, &first_if
);
4402 parser
->in_if_block
= in_if_block
;
4403 if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
4405 c_parser_consume_token (parser
);
4406 second_body
= c_parser_else_body (parser
);
4409 second_body
= NULL_TREE
;
4410 c_finish_if_stmt (loc
, cond
, first_body
, second_body
, first_if
);
4411 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
4414 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
4417 switch (expression) statement
4421 c_parser_switch_statement (c_parser
*parser
)
4423 tree block
, expr
, body
, save_break
;
4424 location_t switch_loc
= c_parser_peek_token (parser
)->location
;
4425 location_t switch_cond_loc
;
4426 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SWITCH
));
4427 c_parser_consume_token (parser
);
4428 block
= c_begin_compound_stmt (flag_isoc99
);
4429 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4431 switch_cond_loc
= c_parser_peek_token (parser
)->location
;
4432 expr
= c_parser_expression (parser
).value
;
4433 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4437 switch_cond_loc
= UNKNOWN_LOCATION
;
4438 expr
= error_mark_node
;
4440 c_start_case (switch_loc
, switch_cond_loc
, expr
);
4441 save_break
= c_break_label
;
4442 c_break_label
= NULL_TREE
;
4443 body
= c_parser_c99_block_statement (parser
);
4444 c_finish_case (body
);
4447 location_t here
= c_parser_peek_token (parser
)->location
;
4448 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_break_label
);
4449 SET_EXPR_LOCATION (t
, here
);
4452 c_break_label
= save_break
;
4453 add_stmt (c_end_compound_stmt (switch_loc
, block
, flag_isoc99
));
4456 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
4459 while (expression) statement
4463 c_parser_while_statement (c_parser
*parser
)
4465 tree block
, cond
, body
, save_break
, save_cont
;
4467 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_WHILE
));
4468 c_parser_consume_token (parser
);
4469 block
= c_begin_compound_stmt (flag_isoc99
);
4470 loc
= c_parser_peek_token (parser
)->location
;
4471 cond
= c_parser_paren_condition (parser
);
4472 save_break
= c_break_label
;
4473 c_break_label
= NULL_TREE
;
4474 save_cont
= c_cont_label
;
4475 c_cont_label
= NULL_TREE
;
4476 body
= c_parser_c99_block_statement (parser
);
4477 c_finish_loop (loc
, cond
, NULL
, body
, c_break_label
, c_cont_label
, true);
4478 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
4479 c_break_label
= save_break
;
4480 c_cont_label
= save_cont
;
4483 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
4486 do statement while ( expression ) ;
4490 c_parser_do_statement (c_parser
*parser
)
4492 tree block
, cond
, body
, save_break
, save_cont
, new_break
, new_cont
;
4494 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_DO
));
4495 c_parser_consume_token (parser
);
4496 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4497 warning_at (c_parser_peek_token (parser
)->location
,
4499 "suggest braces around empty body in %<do%> statement");
4500 block
= c_begin_compound_stmt (flag_isoc99
);
4501 loc
= c_parser_peek_token (parser
)->location
;
4502 save_break
= c_break_label
;
4503 c_break_label
= NULL_TREE
;
4504 save_cont
= c_cont_label
;
4505 c_cont_label
= NULL_TREE
;
4506 body
= c_parser_c99_block_statement (parser
);
4507 c_parser_require_keyword (parser
, RID_WHILE
, "expected %<while%>");
4508 new_break
= c_break_label
;
4509 c_break_label
= save_break
;
4510 new_cont
= c_cont_label
;
4511 c_cont_label
= save_cont
;
4512 cond
= c_parser_paren_condition (parser
);
4513 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
4514 c_parser_skip_to_end_of_block_or_statement (parser
);
4515 c_finish_loop (loc
, cond
, NULL
, body
, new_break
, new_cont
, false);
4516 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
4519 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
4522 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
4523 for ( nested-declaration expression[opt] ; expression[opt] ) statement
4525 The form with a declaration is new in C99.
4527 ??? In accordance with the old parser, the declaration may be a
4528 nested function, which is then rejected in check_for_loop_decls,
4529 but does it make any sense for this to be included in the grammar?
4530 Note in particular that the nested function does not include a
4531 trailing ';', whereas the "declaration" production includes one.
4532 Also, can we reject bad declarations earlier and cheaper than
4533 check_for_loop_decls?
4535 In Objective-C, there are two additional variants:
4538 for ( expression in expresssion ) statement
4539 for ( declaration in expression ) statement
4541 This is inconsistent with C, because the second variant is allowed
4542 even if c99 is not enabled.
4544 The rest of the comment documents these Objective-C foreach-statement.
4546 Here is the canonical example of the first variant:
4547 for (object in array) { do something with object }
4548 we call the first expression ("object") the "object_expression" and
4549 the second expression ("array") the "collection_expression".
4550 object_expression must be an lvalue of type "id" (a generic Objective-C
4551 object) because the loop works by assigning to object_expression the
4552 various objects from the collection_expression. collection_expression
4553 must evaluate to something of type "id" which responds to the method
4554 countByEnumeratingWithState:objects:count:.
4556 The canonical example of the second variant is:
4557 for (id object in array) { do something with object }
4558 which is completely equivalent to
4561 for (object in array) { do something with object }
4563 Note that initizializing 'object' in some way (eg, "for ((object =
4564 xxx) in array) { do something with object }") is possibly
4565 technically valid, but completely pointless as 'object' will be
4566 assigned to something else as soon as the loop starts. We should
4567 most likely reject it (TODO).
4569 The beginning of the Objective-C foreach-statement looks exactly
4570 like the beginning of the for-statement, and we can tell it is a
4571 foreach-statement only because the initial declaration or
4572 expression is terminated by 'in' instead of ';'.
4576 c_parser_for_statement (c_parser
*parser
)
4578 tree block
, cond
, incr
, save_break
, save_cont
, body
;
4579 /* The following are only used when parsing an ObjC foreach statement. */
4580 tree object_expression
, collection_expression
;
4581 location_t loc
= c_parser_peek_token (parser
)->location
;
4582 location_t for_loc
= c_parser_peek_token (parser
)->location
;
4583 bool is_foreach_statement
= false;
4584 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_FOR
));
4585 c_parser_consume_token (parser
);
4586 /* Open a compound statement in Objective-C as well, just in case this is
4587 as foreach expression. */
4588 block
= c_begin_compound_stmt (flag_isoc99
|| c_dialect_objc ());
4589 cond
= error_mark_node
;
4590 incr
= error_mark_node
;
4591 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4593 /* Parse the initialization declaration or expression. */
4594 object_expression
= error_mark_node
;
4595 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4597 c_parser_consume_token (parser
);
4598 c_finish_expr_stmt (loc
, NULL_TREE
);
4600 else if (c_parser_next_token_starts_declaration (parser
))
4602 parser
->objc_could_be_foreach_context
= true;
4603 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
4604 &object_expression
);
4605 parser
->objc_could_be_foreach_context
= false;
4607 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
4609 c_parser_consume_token (parser
);
4610 is_foreach_statement
= true;
4611 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
4612 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
4615 check_for_loop_decls (for_loc
, flag_isoc99
);
4617 else if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
4619 /* __extension__ can start a declaration, but is also an
4620 unary operator that can start an expression. Consume all
4621 but the last of a possible series of __extension__ to
4623 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
4624 && (c_parser_peek_2nd_token (parser
)->keyword
4626 c_parser_consume_token (parser
);
4627 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
4630 ext
= disable_extension_diagnostics ();
4631 c_parser_consume_token (parser
);
4632 parser
->objc_could_be_foreach_context
= true;
4633 c_parser_declaration_or_fndef (parser
, true, true, true, true,
4634 true, &object_expression
);
4635 parser
->objc_could_be_foreach_context
= false;
4637 restore_extension_diagnostics (ext
);
4638 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
4640 c_parser_consume_token (parser
);
4641 is_foreach_statement
= true;
4642 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
4643 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
4646 check_for_loop_decls (for_loc
, flag_isoc99
);
4655 tree init_expression
;
4656 parser
->objc_could_be_foreach_context
= true;
4657 init_expression
= c_parser_expression (parser
).value
;
4658 parser
->objc_could_be_foreach_context
= false;
4659 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
4661 c_parser_consume_token (parser
);
4662 is_foreach_statement
= true;
4663 if (! lvalue_p (init_expression
))
4664 c_parser_error (parser
, "invalid iterating variable in fast enumeration");
4665 object_expression
= c_process_expr_stmt (loc
, init_expression
);
4670 c_finish_expr_stmt (loc
, init_expression
);
4671 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4675 /* Parse the loop condition. In the case of a foreach
4676 statement, there is no loop condition. */
4677 if (!is_foreach_statement
)
4679 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4681 c_parser_consume_token (parser
);
4686 cond
= c_parser_condition (parser
);
4687 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4690 /* Parse the increment expression (the third expression in a
4691 for-statement). In the case of a foreach-statement, this is
4692 the expression that follows the 'in'. */
4693 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4695 if (is_foreach_statement
)
4697 c_parser_error (parser
, "missing collection in fast enumeration");
4698 collection_expression
= error_mark_node
;
4701 incr
= c_process_expr_stmt (loc
, NULL_TREE
);
4705 if (is_foreach_statement
)
4706 collection_expression
= c_process_expr_stmt (loc
, c_parser_expression (parser
).value
);
4708 incr
= c_process_expr_stmt (loc
, c_parser_expression (parser
).value
);
4710 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4712 save_break
= c_break_label
;
4713 c_break_label
= NULL_TREE
;
4714 save_cont
= c_cont_label
;
4715 c_cont_label
= NULL_TREE
;
4716 body
= c_parser_c99_block_statement (parser
);
4717 if (is_foreach_statement
)
4718 objc_finish_foreach_loop (loc
, object_expression
, collection_expression
, body
, c_break_label
, c_cont_label
);
4720 c_finish_loop (loc
, cond
, incr
, body
, c_break_label
, c_cont_label
, true);
4721 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
|| c_dialect_objc ()));
4722 c_break_label
= save_break
;
4723 c_cont_label
= save_cont
;
4726 /* Parse an asm statement, a GNU extension. This is a full-blown asm
4727 statement with inputs, outputs, clobbers, and volatile tag
4731 asm type-qualifier[opt] ( asm-argument ) ;
4732 asm type-qualifier[opt] goto ( asm-goto-argument ) ;
4736 asm-string-literal : asm-operands[opt]
4737 asm-string-literal : asm-operands[opt] : asm-operands[opt]
4738 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers[opt]
4741 asm-string-literal : : asm-operands[opt] : asm-clobbers[opt] \
4744 Qualifiers other than volatile are accepted in the syntax but
4748 c_parser_asm_statement (c_parser
*parser
)
4750 tree quals
, str
, outputs
, inputs
, clobbers
, labels
, ret
;
4751 bool simple
, is_goto
;
4752 location_t asm_loc
= c_parser_peek_token (parser
)->location
;
4753 int section
, nsections
;
4755 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
4756 c_parser_consume_token (parser
);
4757 if (c_parser_next_token_is_keyword (parser
, RID_VOLATILE
))
4759 quals
= c_parser_peek_token (parser
)->value
;
4760 c_parser_consume_token (parser
);
4762 else if (c_parser_next_token_is_keyword (parser
, RID_CONST
)
4763 || c_parser_next_token_is_keyword (parser
, RID_RESTRICT
))
4765 warning_at (c_parser_peek_token (parser
)->location
,
4767 "%E qualifier ignored on asm",
4768 c_parser_peek_token (parser
)->value
);
4770 c_parser_consume_token (parser
);
4776 if (c_parser_next_token_is_keyword (parser
, RID_GOTO
))
4778 c_parser_consume_token (parser
);
4782 /* ??? Follow the C++ parser rather than using the
4783 lex_untranslated_string kludge. */
4784 parser
->lex_untranslated_string
= true;
4787 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4790 str
= c_parser_asm_string_literal (parser
);
4791 if (str
== NULL_TREE
)
4792 goto error_close_paren
;
4795 outputs
= NULL_TREE
;
4797 clobbers
= NULL_TREE
;
4800 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
4803 /* Parse each colon-delimited section of operands. */
4804 nsections
= 3 + is_goto
;
4805 for (section
= 0; section
< nsections
; ++section
)
4807 if (!c_parser_require (parser
, CPP_COLON
,
4810 : "expected %<:%> or %<)%>"))
4811 goto error_close_paren
;
4813 /* Once past any colon, we're no longer a simple asm. */
4816 if ((!c_parser_next_token_is (parser
, CPP_COLON
)
4817 && !c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4822 /* For asm goto, we don't allow output operands, but reserve
4823 the slot for a future extension that does allow them. */
4825 outputs
= c_parser_asm_operands (parser
, false);
4828 inputs
= c_parser_asm_operands (parser
, true);
4831 clobbers
= c_parser_asm_clobbers (parser
);
4834 labels
= c_parser_asm_goto_operands (parser
);
4840 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
4845 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
4847 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4851 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
4852 c_parser_skip_to_end_of_block_or_statement (parser
);
4854 ret
= build_asm_stmt (quals
, build_asm_expr (asm_loc
, str
, outputs
, inputs
,
4855 clobbers
, labels
, simple
));
4858 parser
->lex_untranslated_string
= false;
4862 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4866 /* Parse asm operands, a GNU extension. If CONVERT_P (for inputs but
4867 not outputs), apply the default conversion of functions and arrays
4872 asm-operands , asm-operand
4875 asm-string-literal ( expression )
4876 [ identifier ] asm-string-literal ( expression )
4880 c_parser_asm_operands (c_parser
*parser
, bool convert_p
)
4882 tree list
= NULL_TREE
;
4888 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
4890 c_parser_consume_token (parser
);
4891 if (c_parser_next_token_is (parser
, CPP_NAME
))
4893 tree id
= c_parser_peek_token (parser
)->value
;
4894 c_parser_consume_token (parser
);
4895 name
= build_string (IDENTIFIER_LENGTH (id
),
4896 IDENTIFIER_POINTER (id
));
4900 c_parser_error (parser
, "expected identifier");
4901 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
4904 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4909 str
= c_parser_asm_string_literal (parser
);
4910 if (str
== NULL_TREE
)
4912 parser
->lex_untranslated_string
= false;
4913 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4915 parser
->lex_untranslated_string
= true;
4918 loc
= c_parser_peek_token (parser
)->location
;
4919 expr
= c_parser_expression (parser
);
4920 mark_exp_read (expr
.value
);
4922 expr
= default_function_array_conversion (loc
, expr
);
4923 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
4924 parser
->lex_untranslated_string
= true;
4925 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
4927 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4930 list
= chainon (list
, build_tree_list (build_tree_list (name
, str
),
4932 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4933 c_parser_consume_token (parser
);
4940 /* Parse asm clobbers, a GNU extension.
4944 asm-clobbers , asm-string-literal
4948 c_parser_asm_clobbers (c_parser
*parser
)
4950 tree list
= NULL_TREE
;
4953 tree str
= c_parser_asm_string_literal (parser
);
4955 list
= tree_cons (NULL_TREE
, str
, list
);
4958 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4959 c_parser_consume_token (parser
);
4966 /* Parse asm goto labels, a GNU extension.
4970 asm-goto-operands , identifier
4974 c_parser_asm_goto_operands (c_parser
*parser
)
4976 tree list
= NULL_TREE
;
4981 if (c_parser_next_token_is (parser
, CPP_NAME
))
4983 c_token
*tok
= c_parser_peek_token (parser
);
4985 label
= lookup_label_for_goto (tok
->location
, name
);
4986 c_parser_consume_token (parser
);
4987 TREE_USED (label
) = 1;
4991 c_parser_error (parser
, "expected identifier");
4995 name
= build_string (IDENTIFIER_LENGTH (name
),
4996 IDENTIFIER_POINTER (name
));
4997 list
= tree_cons (name
, label
, list
);
4998 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4999 c_parser_consume_token (parser
);
5001 return nreverse (list
);
5005 /* Parse an expression other than a compound expression; that is, an
5006 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
5007 NULL then it is an Objective-C message expression which is the
5008 primary-expression starting the expression as an initializer.
5010 assignment-expression:
5011 conditional-expression
5012 unary-expression assignment-operator assignment-expression
5014 assignment-operator: one of
5015 = *= /= %= += -= <<= >>= &= ^= |=
5017 In GNU C we accept any conditional expression on the LHS and
5018 diagnose the invalid lvalue rather than producing a syntax
5021 static struct c_expr
5022 c_parser_expr_no_commas (c_parser
*parser
, struct c_expr
*after
)
5024 struct c_expr lhs
, rhs
, ret
;
5025 enum tree_code code
;
5026 location_t op_location
, exp_location
;
5027 gcc_assert (!after
|| c_dialect_objc ());
5028 lhs
= c_parser_conditional_expression (parser
, after
);
5029 op_location
= c_parser_peek_token (parser
)->location
;
5030 switch (c_parser_peek_token (parser
)->type
)
5039 code
= TRUNC_DIV_EXPR
;
5042 code
= TRUNC_MOD_EXPR
;
5057 code
= BIT_AND_EXPR
;
5060 code
= BIT_XOR_EXPR
;
5063 code
= BIT_IOR_EXPR
;
5068 c_parser_consume_token (parser
);
5069 exp_location
= c_parser_peek_token (parser
)->location
;
5070 rhs
= c_parser_expr_no_commas (parser
, NULL
);
5071 rhs
= default_function_array_read_conversion (exp_location
, rhs
);
5072 ret
.value
= build_modify_expr (op_location
, lhs
.value
, lhs
.original_type
,
5073 code
, exp_location
, rhs
.value
,
5075 if (code
== NOP_EXPR
)
5076 ret
.original_code
= MODIFY_EXPR
;
5079 TREE_NO_WARNING (ret
.value
) = 1;
5080 ret
.original_code
= ERROR_MARK
;
5082 ret
.original_type
= NULL
;
5086 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
5087 is not NULL then it is an Objective-C message expression which is
5088 the primary-expression starting the expression as an initializer.
5090 conditional-expression:
5091 logical-OR-expression
5092 logical-OR-expression ? expression : conditional-expression
5096 conditional-expression:
5097 logical-OR-expression ? : conditional-expression
5100 static struct c_expr
5101 c_parser_conditional_expression (c_parser
*parser
, struct c_expr
*after
)
5103 struct c_expr cond
, exp1
, exp2
, ret
;
5104 location_t cond_loc
, colon_loc
, middle_loc
;
5106 gcc_assert (!after
|| c_dialect_objc ());
5108 cond
= c_parser_binary_expression (parser
, after
);
5110 if (c_parser_next_token_is_not (parser
, CPP_QUERY
))
5112 cond_loc
= c_parser_peek_token (parser
)->location
;
5113 cond
= default_function_array_read_conversion (cond_loc
, cond
);
5114 c_parser_consume_token (parser
);
5115 if (c_parser_next_token_is (parser
, CPP_COLON
))
5117 tree eptype
= NULL_TREE
;
5119 middle_loc
= c_parser_peek_token (parser
)->location
;
5120 pedwarn (middle_loc
, OPT_pedantic
,
5121 "ISO C forbids omitting the middle term of a ?: expression");
5122 warn_for_omitted_condop (middle_loc
, cond
.value
);
5123 if (TREE_CODE (cond
.value
) == EXCESS_PRECISION_EXPR
)
5125 eptype
= TREE_TYPE (cond
.value
);
5126 cond
.value
= TREE_OPERAND (cond
.value
, 0);
5128 /* Make sure first operand is calculated only once. */
5129 exp1
.value
= c_save_expr (default_conversion (cond
.value
));
5131 exp1
.value
= build1 (EXCESS_PRECISION_EXPR
, eptype
, exp1
.value
);
5132 exp1
.original_type
= NULL
;
5133 cond
.value
= c_objc_common_truthvalue_conversion (cond_loc
, exp1
.value
);
5134 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_true_node
;
5139 = c_objc_common_truthvalue_conversion
5140 (cond_loc
, default_conversion (cond
.value
));
5141 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_false_node
;
5142 exp1
= c_parser_expression_conv (parser
);
5143 mark_exp_read (exp1
.value
);
5144 c_inhibit_evaluation_warnings
+=
5145 ((cond
.value
== truthvalue_true_node
)
5146 - (cond
.value
== truthvalue_false_node
));
5149 colon_loc
= c_parser_peek_token (parser
)->location
;
5150 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
5152 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
5153 ret
.value
= error_mark_node
;
5154 ret
.original_code
= ERROR_MARK
;
5155 ret
.original_type
= NULL
;
5159 location_t exp2_loc
= c_parser_peek_token (parser
)->location
;
5160 exp2
= c_parser_conditional_expression (parser
, NULL
);
5161 exp2
= default_function_array_read_conversion (exp2_loc
, exp2
);
5163 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
5164 ret
.value
= build_conditional_expr (colon_loc
, cond
.value
,
5165 cond
.original_code
== C_MAYBE_CONST_EXPR
,
5166 exp1
.value
, exp1
.original_type
,
5167 exp2
.value
, exp2
.original_type
);
5168 ret
.original_code
= ERROR_MARK
;
5169 if (exp1
.value
== error_mark_node
|| exp2
.value
== error_mark_node
)
5170 ret
.original_type
= NULL
;
5175 /* If both sides are enum type, the default conversion will have
5176 made the type of the result be an integer type. We want to
5177 remember the enum types we started with. */
5178 t1
= exp1
.original_type
? exp1
.original_type
: TREE_TYPE (exp1
.value
);
5179 t2
= exp2
.original_type
? exp2
.original_type
: TREE_TYPE (exp2
.value
);
5180 ret
.original_type
= ((t1
!= error_mark_node
5181 && t2
!= error_mark_node
5182 && (TYPE_MAIN_VARIANT (t1
)
5183 == TYPE_MAIN_VARIANT (t2
)))
5190 /* Parse a binary expression; that is, a logical-OR-expression (C90
5191 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
5192 an Objective-C message expression which is the primary-expression
5193 starting the expression as an initializer.
5195 multiplicative-expression:
5197 multiplicative-expression * cast-expression
5198 multiplicative-expression / cast-expression
5199 multiplicative-expression % cast-expression
5201 additive-expression:
5202 multiplicative-expression
5203 additive-expression + multiplicative-expression
5204 additive-expression - multiplicative-expression
5208 shift-expression << additive-expression
5209 shift-expression >> additive-expression
5211 relational-expression:
5213 relational-expression < shift-expression
5214 relational-expression > shift-expression
5215 relational-expression <= shift-expression
5216 relational-expression >= shift-expression
5218 equality-expression:
5219 relational-expression
5220 equality-expression == relational-expression
5221 equality-expression != relational-expression
5225 AND-expression & equality-expression
5227 exclusive-OR-expression:
5229 exclusive-OR-expression ^ AND-expression
5231 inclusive-OR-expression:
5232 exclusive-OR-expression
5233 inclusive-OR-expression | exclusive-OR-expression
5235 logical-AND-expression:
5236 inclusive-OR-expression
5237 logical-AND-expression && inclusive-OR-expression
5239 logical-OR-expression:
5240 logical-AND-expression
5241 logical-OR-expression || logical-AND-expression
5244 static struct c_expr
5245 c_parser_binary_expression (c_parser
*parser
, struct c_expr
*after
)
5247 /* A binary expression is parsed using operator-precedence parsing,
5248 with the operands being cast expressions. All the binary
5249 operators are left-associative. Thus a binary expression is of
5252 E0 op1 E1 op2 E2 ...
5254 which we represent on a stack. On the stack, the precedence
5255 levels are strictly increasing. When a new operator is
5256 encountered of higher precedence than that at the top of the
5257 stack, it is pushed; its LHS is the top expression, and its RHS
5258 is everything parsed until it is popped. When a new operator is
5259 encountered with precedence less than or equal to that at the top
5260 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
5261 by the result of the operation until the operator at the top of
5262 the stack has lower precedence than the new operator or there is
5263 only one element on the stack; then the top expression is the LHS
5264 of the new operator. In the case of logical AND and OR
5265 expressions, we also need to adjust c_inhibit_evaluation_warnings
5266 as appropriate when the operators are pushed and popped. */
5268 /* The precedence levels, where 0 is a dummy lowest level used for
5269 the bottom of the stack. */
5285 /* The expression at this stack level. */
5287 /* The precedence of the operator on its left, PREC_NONE at the
5288 bottom of the stack. */
5290 /* The operation on its left. */
5292 /* The source location of this operation. */
5296 /* Location of the binary operator. */
5297 location_t binary_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
5300 switch (stack[sp].op) \
5302 case TRUTH_ANDIF_EXPR: \
5303 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
5304 == truthvalue_false_node); \
5306 case TRUTH_ORIF_EXPR: \
5307 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
5308 == truthvalue_true_node); \
5313 stack[sp - 1].expr \
5314 = default_function_array_read_conversion (stack[sp - 1].loc, \
5315 stack[sp - 1].expr); \
5317 = default_function_array_read_conversion (stack[sp].loc, \
5319 stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc, \
5321 stack[sp - 1].expr, \
5325 gcc_assert (!after
|| c_dialect_objc ());
5326 stack
[0].loc
= c_parser_peek_token (parser
)->location
;
5327 stack
[0].expr
= c_parser_cast_expression (parser
, after
);
5328 stack
[0].prec
= PREC_NONE
;
5333 enum tree_code ocode
;
5336 switch (c_parser_peek_token (parser
)->type
)
5344 ocode
= TRUNC_DIV_EXPR
;
5348 ocode
= TRUNC_MOD_EXPR
;
5360 ocode
= LSHIFT_EXPR
;
5364 ocode
= RSHIFT_EXPR
;
5378 case CPP_GREATER_EQ
:
5391 oprec
= PREC_BITAND
;
5392 ocode
= BIT_AND_EXPR
;
5395 oprec
= PREC_BITXOR
;
5396 ocode
= BIT_XOR_EXPR
;
5400 ocode
= BIT_IOR_EXPR
;
5403 oprec
= PREC_LOGAND
;
5404 ocode
= TRUTH_ANDIF_EXPR
;
5408 ocode
= TRUTH_ORIF_EXPR
;
5411 /* Not a binary operator, so end of the binary
5415 binary_loc
= c_parser_peek_token (parser
)->location
;
5416 c_parser_consume_token (parser
);
5417 while (oprec
<= stack
[sp
].prec
)
5421 case TRUTH_ANDIF_EXPR
:
5423 = default_function_array_read_conversion (stack
[sp
].loc
,
5425 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
5426 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
5427 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
5428 == truthvalue_false_node
);
5430 case TRUTH_ORIF_EXPR
:
5432 = default_function_array_read_conversion (stack
[sp
].loc
,
5434 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
5435 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
5436 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
5437 == truthvalue_true_node
);
5443 stack
[sp
].loc
= binary_loc
;
5444 stack
[sp
].expr
= c_parser_cast_expression (parser
, NULL
);
5445 stack
[sp
].prec
= oprec
;
5446 stack
[sp
].op
= ocode
;
5447 stack
[sp
].loc
= binary_loc
;
5452 return stack
[0].expr
;
5456 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
5457 NULL then it is an Objective-C message expression which is the
5458 primary-expression starting the expression as an initializer.
5462 ( type-name ) unary-expression
5465 static struct c_expr
5466 c_parser_cast_expression (c_parser
*parser
, struct c_expr
*after
)
5468 location_t cast_loc
= c_parser_peek_token (parser
)->location
;
5469 gcc_assert (!after
|| c_dialect_objc ());
5471 return c_parser_postfix_expression_after_primary (parser
,
5473 /* If the expression begins with a parenthesized type name, it may
5474 be either a cast or a compound literal; we need to see whether
5475 the next character is '{' to tell the difference. If not, it is
5476 an unary expression. */
5477 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
5478 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
5480 struct c_type_name
*type_name
;
5483 c_parser_consume_token (parser
);
5484 type_name
= c_parser_type_name (parser
);
5485 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5486 if (type_name
== NULL
)
5488 ret
.value
= error_mark_node
;
5489 ret
.original_code
= ERROR_MARK
;
5490 ret
.original_type
= NULL
;
5494 /* Save casted types in the function's used types hash table. */
5495 used_types_insert (type_name
->specs
->type
);
5497 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5498 return c_parser_postfix_expression_after_paren_type (parser
, type_name
,
5501 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
5502 expr
= c_parser_cast_expression (parser
, NULL
);
5503 expr
= default_function_array_read_conversion (expr_loc
, expr
);
5505 ret
.value
= c_cast_expr (cast_loc
, type_name
, expr
.value
);
5506 ret
.original_code
= ERROR_MARK
;
5507 ret
.original_type
= NULL
;
5511 return c_parser_unary_expression (parser
);
5514 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
5520 unary-operator cast-expression
5521 sizeof unary-expression
5522 sizeof ( type-name )
5524 unary-operator: one of
5530 __alignof__ unary-expression
5531 __alignof__ ( type-name )
5534 unary-operator: one of
5535 __extension__ __real__ __imag__
5537 In addition, the GNU syntax treats ++ and -- as unary operators, so
5538 they may be applied to cast expressions with errors for non-lvalues
5541 static struct c_expr
5542 c_parser_unary_expression (c_parser
*parser
)
5545 struct c_expr ret
, op
;
5546 location_t op_loc
= c_parser_peek_token (parser
)->location
;
5548 ret
.original_code
= ERROR_MARK
;
5549 ret
.original_type
= NULL
;
5550 switch (c_parser_peek_token (parser
)->type
)
5553 c_parser_consume_token (parser
);
5554 exp_loc
= c_parser_peek_token (parser
)->location
;
5555 op
= c_parser_cast_expression (parser
, NULL
);
5556 op
= default_function_array_read_conversion (exp_loc
, op
);
5557 return parser_build_unary_op (op_loc
, PREINCREMENT_EXPR
, op
);
5558 case CPP_MINUS_MINUS
:
5559 c_parser_consume_token (parser
);
5560 exp_loc
= c_parser_peek_token (parser
)->location
;
5561 op
= c_parser_cast_expression (parser
, NULL
);
5562 op
= default_function_array_read_conversion (exp_loc
, op
);
5563 return parser_build_unary_op (op_loc
, PREDECREMENT_EXPR
, op
);
5565 c_parser_consume_token (parser
);
5566 op
= c_parser_cast_expression (parser
, NULL
);
5567 mark_exp_read (op
.value
);
5568 return parser_build_unary_op (op_loc
, ADDR_EXPR
, op
);
5570 c_parser_consume_token (parser
);
5571 exp_loc
= c_parser_peek_token (parser
)->location
;
5572 op
= c_parser_cast_expression (parser
, NULL
);
5573 op
= default_function_array_read_conversion (exp_loc
, op
);
5574 ret
.value
= build_indirect_ref (op_loc
, op
.value
, RO_UNARY_STAR
);
5577 if (!c_dialect_objc () && !in_system_header
)
5580 "traditional C rejects the unary plus operator");
5581 c_parser_consume_token (parser
);
5582 exp_loc
= c_parser_peek_token (parser
)->location
;
5583 op
= c_parser_cast_expression (parser
, NULL
);
5584 op
= default_function_array_read_conversion (exp_loc
, op
);
5585 return parser_build_unary_op (op_loc
, CONVERT_EXPR
, op
);
5587 c_parser_consume_token (parser
);
5588 exp_loc
= c_parser_peek_token (parser
)->location
;
5589 op
= c_parser_cast_expression (parser
, NULL
);
5590 op
= default_function_array_read_conversion (exp_loc
, op
);
5591 return parser_build_unary_op (op_loc
, NEGATE_EXPR
, op
);
5593 c_parser_consume_token (parser
);
5594 exp_loc
= c_parser_peek_token (parser
)->location
;
5595 op
= c_parser_cast_expression (parser
, NULL
);
5596 op
= default_function_array_read_conversion (exp_loc
, op
);
5597 return parser_build_unary_op (op_loc
, BIT_NOT_EXPR
, op
);
5599 c_parser_consume_token (parser
);
5600 exp_loc
= c_parser_peek_token (parser
)->location
;
5601 op
= c_parser_cast_expression (parser
, NULL
);
5602 op
= default_function_array_read_conversion (exp_loc
, op
);
5603 return parser_build_unary_op (op_loc
, TRUTH_NOT_EXPR
, op
);
5605 /* Refer to the address of a label as a pointer. */
5606 c_parser_consume_token (parser
);
5607 if (c_parser_next_token_is (parser
, CPP_NAME
))
5609 ret
.value
= finish_label_address_expr
5610 (c_parser_peek_token (parser
)->value
, op_loc
);
5611 c_parser_consume_token (parser
);
5615 c_parser_error (parser
, "expected identifier");
5616 ret
.value
= error_mark_node
;
5620 switch (c_parser_peek_token (parser
)->keyword
)
5623 return c_parser_sizeof_expression (parser
);
5625 return c_parser_alignof_expression (parser
);
5627 c_parser_consume_token (parser
);
5628 ext
= disable_extension_diagnostics ();
5629 ret
= c_parser_cast_expression (parser
, NULL
);
5630 restore_extension_diagnostics (ext
);
5633 c_parser_consume_token (parser
);
5634 exp_loc
= c_parser_peek_token (parser
)->location
;
5635 op
= c_parser_cast_expression (parser
, NULL
);
5636 op
= default_function_array_conversion (exp_loc
, op
);
5637 return parser_build_unary_op (op_loc
, REALPART_EXPR
, op
);
5639 c_parser_consume_token (parser
);
5640 exp_loc
= c_parser_peek_token (parser
)->location
;
5641 op
= c_parser_cast_expression (parser
, NULL
);
5642 op
= default_function_array_conversion (exp_loc
, op
);
5643 return parser_build_unary_op (op_loc
, IMAGPART_EXPR
, op
);
5645 return c_parser_postfix_expression (parser
);
5648 return c_parser_postfix_expression (parser
);
5652 /* Parse a sizeof expression. */
5654 static struct c_expr
5655 c_parser_sizeof_expression (c_parser
*parser
)
5658 location_t expr_loc
;
5659 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SIZEOF
));
5660 c_parser_consume_token (parser
);
5661 c_inhibit_evaluation_warnings
++;
5663 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
5664 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
5666 /* Either sizeof ( type-name ) or sizeof unary-expression
5667 starting with a compound literal. */
5668 struct c_type_name
*type_name
;
5669 c_parser_consume_token (parser
);
5670 expr_loc
= c_parser_peek_token (parser
)->location
;
5671 type_name
= c_parser_type_name (parser
);
5672 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5673 if (type_name
== NULL
)
5676 c_inhibit_evaluation_warnings
--;
5678 ret
.value
= error_mark_node
;
5679 ret
.original_code
= ERROR_MARK
;
5680 ret
.original_type
= NULL
;
5683 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5685 expr
= c_parser_postfix_expression_after_paren_type (parser
,
5690 /* sizeof ( type-name ). */
5691 c_inhibit_evaluation_warnings
--;
5693 return c_expr_sizeof_type (expr_loc
, type_name
);
5697 expr_loc
= c_parser_peek_token (parser
)->location
;
5698 expr
= c_parser_unary_expression (parser
);
5700 c_inhibit_evaluation_warnings
--;
5702 mark_exp_read (expr
.value
);
5703 if (TREE_CODE (expr
.value
) == COMPONENT_REF
5704 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
5705 error_at (expr_loc
, "%<sizeof%> applied to a bit-field");
5706 return c_expr_sizeof_expr (expr_loc
, expr
);
5710 /* Parse an alignof expression. */
5712 static struct c_expr
5713 c_parser_alignof_expression (c_parser
*parser
)
5716 location_t loc
= c_parser_peek_token (parser
)->location
;
5717 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNOF
));
5718 c_parser_consume_token (parser
);
5719 c_inhibit_evaluation_warnings
++;
5721 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
5722 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
5724 /* Either __alignof__ ( type-name ) or __alignof__
5725 unary-expression starting with a compound literal. */
5727 struct c_type_name
*type_name
;
5729 c_parser_consume_token (parser
);
5730 loc
= c_parser_peek_token (parser
)->location
;
5731 type_name
= c_parser_type_name (parser
);
5732 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5733 if (type_name
== NULL
)
5736 c_inhibit_evaluation_warnings
--;
5738 ret
.value
= error_mark_node
;
5739 ret
.original_code
= ERROR_MARK
;
5740 ret
.original_type
= NULL
;
5743 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5745 expr
= c_parser_postfix_expression_after_paren_type (parser
,
5750 /* alignof ( type-name ). */
5751 c_inhibit_evaluation_warnings
--;
5753 ret
.value
= c_alignof (loc
, groktypename (type_name
, NULL
, NULL
));
5754 ret
.original_code
= ERROR_MARK
;
5755 ret
.original_type
= NULL
;
5761 expr
= c_parser_unary_expression (parser
);
5763 mark_exp_read (expr
.value
);
5764 c_inhibit_evaluation_warnings
--;
5766 ret
.value
= c_alignof_expr (loc
, expr
.value
);
5767 ret
.original_code
= ERROR_MARK
;
5768 ret
.original_type
= NULL
;
5773 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
5777 postfix-expression [ expression ]
5778 postfix-expression ( argument-expression-list[opt] )
5779 postfix-expression . identifier
5780 postfix-expression -> identifier
5781 postfix-expression ++
5782 postfix-expression --
5783 ( type-name ) { initializer-list }
5784 ( type-name ) { initializer-list , }
5786 argument-expression-list:
5788 argument-expression-list , argument-expression
5800 (treated as a keyword in GNU C)
5803 ( compound-statement )
5804 __builtin_va_arg ( assignment-expression , type-name )
5805 __builtin_offsetof ( type-name , offsetof-member-designator )
5806 __builtin_choose_expr ( assignment-expression ,
5807 assignment-expression ,
5808 assignment-expression )
5809 __builtin_types_compatible_p ( type-name , type-name )
5811 offsetof-member-designator:
5813 offsetof-member-designator . identifier
5814 offsetof-member-designator [ expression ]
5819 [ objc-receiver objc-message-args ]
5820 @selector ( objc-selector-arg )
5821 @protocol ( identifier )
5822 @encode ( type-name )
5826 static struct c_expr
5827 c_parser_postfix_expression (c_parser
*parser
)
5829 struct c_expr expr
, e1
, e2
, e3
;
5830 struct c_type_name
*t1
, *t2
;
5831 location_t loc
= c_parser_peek_token (parser
)->location
;;
5832 expr
.original_code
= ERROR_MARK
;
5833 expr
.original_type
= NULL
;
5834 switch (c_parser_peek_token (parser
)->type
)
5837 expr
.value
= c_parser_peek_token (parser
)->value
;
5838 loc
= c_parser_peek_token (parser
)->location
;
5839 c_parser_consume_token (parser
);
5840 if (TREE_CODE (expr
.value
) == FIXED_CST
5841 && !targetm
.fixed_point_supported_p ())
5843 error_at (loc
, "fixed-point types not supported for this target");
5844 expr
.value
= error_mark_node
;
5851 expr
.value
= c_parser_peek_token (parser
)->value
;
5852 c_parser_consume_token (parser
);
5858 case CPP_UTF8STRING
:
5859 expr
.value
= c_parser_peek_token (parser
)->value
;
5860 expr
.original_code
= STRING_CST
;
5861 c_parser_consume_token (parser
);
5863 case CPP_OBJC_STRING
:
5864 gcc_assert (c_dialect_objc ());
5866 = objc_build_string_object (c_parser_peek_token (parser
)->value
);
5867 c_parser_consume_token (parser
);
5870 if (c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
5872 c_parser_error (parser
, "expected expression");
5873 expr
.value
= error_mark_node
;
5877 tree id
= c_parser_peek_token (parser
)->value
;
5878 c_parser_consume_token (parser
);
5879 expr
.value
= build_external_ref (loc
, id
,
5880 (c_parser_peek_token (parser
)->type
5882 &expr
.original_type
);
5885 case CPP_OPEN_PAREN
:
5886 /* A parenthesized expression, statement expression or compound
5888 if (c_parser_peek_2nd_token (parser
)->type
== CPP_OPEN_BRACE
)
5890 /* A statement expression. */
5892 location_t brace_loc
;
5893 c_parser_consume_token (parser
);
5894 brace_loc
= c_parser_peek_token (parser
)->location
;
5895 c_parser_consume_token (parser
);
5896 if (cur_stmt_list
== NULL
)
5898 error_at (loc
, "braced-group within expression allowed "
5899 "only inside a function");
5900 parser
->error
= true;
5901 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
5902 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5903 expr
.value
= error_mark_node
;
5906 stmt
= c_begin_stmt_expr ();
5907 c_parser_compound_statement_nostart (parser
);
5908 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5910 pedwarn (loc
, OPT_pedantic
,
5911 "ISO C forbids braced-groups within expressions");
5912 expr
.value
= c_finish_stmt_expr (brace_loc
, stmt
);
5913 mark_exp_read (expr
.value
);
5915 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
5917 /* A compound literal. ??? Can we actually get here rather
5918 than going directly to
5919 c_parser_postfix_expression_after_paren_type from
5922 struct c_type_name
*type_name
;
5923 c_parser_consume_token (parser
);
5924 loc
= c_parser_peek_token (parser
)->location
;
5925 type_name
= c_parser_type_name (parser
);
5926 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5928 if (type_name
== NULL
)
5930 expr
.value
= error_mark_node
;
5933 expr
= c_parser_postfix_expression_after_paren_type (parser
,
5939 /* A parenthesized expression. */
5940 c_parser_consume_token (parser
);
5941 expr
= c_parser_expression (parser
);
5942 if (TREE_CODE (expr
.value
) == MODIFY_EXPR
)
5943 TREE_NO_WARNING (expr
.value
) = 1;
5944 if (expr
.original_code
!= C_MAYBE_CONST_EXPR
)
5945 expr
.original_code
= ERROR_MARK
;
5946 /* Don't change EXPR.ORIGINAL_TYPE. */
5947 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5952 switch (c_parser_peek_token (parser
)->keyword
)
5954 case RID_FUNCTION_NAME
:
5955 case RID_PRETTY_FUNCTION_NAME
:
5956 case RID_C99_FUNCTION_NAME
:
5957 expr
.value
= fname_decl (loc
,
5958 c_parser_peek_token (parser
)->keyword
,
5959 c_parser_peek_token (parser
)->value
);
5960 c_parser_consume_token (parser
);
5963 c_parser_consume_token (parser
);
5964 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5966 expr
.value
= error_mark_node
;
5969 e1
= c_parser_expr_no_commas (parser
, NULL
);
5970 mark_exp_read (e1
.value
);
5971 e1
.value
= c_fully_fold (e1
.value
, false, NULL
);
5972 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5974 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5975 expr
.value
= error_mark_node
;
5978 loc
= c_parser_peek_token (parser
)->location
;
5979 t1
= c_parser_type_name (parser
);
5980 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5984 expr
.value
= error_mark_node
;
5988 tree type_expr
= NULL_TREE
;
5989 expr
.value
= c_build_va_arg (loc
, e1
.value
,
5990 groktypename (t1
, &type_expr
, NULL
));
5993 expr
.value
= build2 (C_MAYBE_CONST_EXPR
,
5994 TREE_TYPE (expr
.value
), type_expr
,
5996 C_MAYBE_CONST_EXPR_NON_CONST (expr
.value
) = true;
6001 c_parser_consume_token (parser
);
6002 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6004 expr
.value
= error_mark_node
;
6007 t1
= c_parser_type_name (parser
);
6010 expr
.value
= error_mark_node
;
6013 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
6015 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6016 expr
.value
= error_mark_node
;
6020 tree type
= groktypename (t1
, NULL
, NULL
);
6022 if (type
== error_mark_node
)
6023 offsetof_ref
= error_mark_node
;
6026 offsetof_ref
= build1 (INDIRECT_REF
, type
, null_pointer_node
);
6027 SET_EXPR_LOCATION (offsetof_ref
, loc
);
6029 /* Parse the second argument to __builtin_offsetof. We
6030 must have one identifier, and beyond that we want to
6031 accept sub structure and sub array references. */
6032 if (c_parser_next_token_is (parser
, CPP_NAME
))
6034 offsetof_ref
= build_component_ref
6035 (loc
, offsetof_ref
, c_parser_peek_token (parser
)->value
);
6036 c_parser_consume_token (parser
);
6037 while (c_parser_next_token_is (parser
, CPP_DOT
)
6038 || c_parser_next_token_is (parser
,
6040 || c_parser_next_token_is (parser
,
6043 if (c_parser_next_token_is (parser
, CPP_DEREF
))
6045 loc
= c_parser_peek_token (parser
)->location
;
6046 offsetof_ref
= build_array_ref (loc
,
6051 else if (c_parser_next_token_is (parser
, CPP_DOT
))
6054 c_parser_consume_token (parser
);
6055 if (c_parser_next_token_is_not (parser
,
6058 c_parser_error (parser
, "expected identifier");
6061 offsetof_ref
= build_component_ref
6063 c_parser_peek_token (parser
)->value
);
6064 c_parser_consume_token (parser
);
6069 loc
= c_parser_peek_token (parser
)->location
;
6070 c_parser_consume_token (parser
);
6071 idx
= c_parser_expression (parser
).value
;
6072 idx
= c_fully_fold (idx
, false, NULL
);
6073 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
6075 offsetof_ref
= build_array_ref (loc
, offsetof_ref
, idx
);
6080 c_parser_error (parser
, "expected identifier");
6081 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6083 expr
.value
= fold_offsetof (offsetof_ref
, NULL_TREE
);
6086 case RID_CHOOSE_EXPR
:
6087 c_parser_consume_token (parser
);
6088 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6090 expr
.value
= error_mark_node
;
6093 loc
= c_parser_peek_token (parser
)->location
;
6094 e1
= c_parser_expr_no_commas (parser
, NULL
);
6095 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
6097 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6098 expr
.value
= error_mark_node
;
6101 e2
= c_parser_expr_no_commas (parser
, NULL
);
6102 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
6104 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6105 expr
.value
= error_mark_node
;
6108 e3
= c_parser_expr_no_commas (parser
, NULL
);
6109 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6115 mark_exp_read (e2
.value
);
6116 mark_exp_read (e3
.value
);
6117 if (TREE_CODE (c
) != INTEGER_CST
6118 || !INTEGRAL_TYPE_P (TREE_TYPE (c
)))
6120 "first argument to %<__builtin_choose_expr%> not"
6122 constant_expression_warning (c
);
6123 expr
= integer_zerop (c
) ? e3
: e2
;
6126 case RID_TYPES_COMPATIBLE_P
:
6127 c_parser_consume_token (parser
);
6128 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6130 expr
.value
= error_mark_node
;
6133 t1
= c_parser_type_name (parser
);
6136 expr
.value
= error_mark_node
;
6139 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
6141 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6142 expr
.value
= error_mark_node
;
6145 t2
= c_parser_type_name (parser
);
6148 expr
.value
= error_mark_node
;
6151 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6156 e1
= TYPE_MAIN_VARIANT (groktypename (t1
, NULL
, NULL
));
6157 e2
= TYPE_MAIN_VARIANT (groktypename (t2
, NULL
, NULL
));
6160 = comptypes (e1
, e2
) ? integer_one_node
: integer_zero_node
;
6163 case RID_AT_SELECTOR
:
6164 gcc_assert (c_dialect_objc ());
6165 c_parser_consume_token (parser
);
6166 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6168 expr
.value
= error_mark_node
;
6172 tree sel
= c_parser_objc_selector_arg (parser
);
6173 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6175 expr
.value
= objc_build_selector_expr (loc
, sel
);
6178 case RID_AT_PROTOCOL
:
6179 gcc_assert (c_dialect_objc ());
6180 c_parser_consume_token (parser
);
6181 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6183 expr
.value
= error_mark_node
;
6186 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6188 c_parser_error (parser
, "expected identifier");
6189 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6190 expr
.value
= error_mark_node
;
6194 tree id
= c_parser_peek_token (parser
)->value
;
6195 c_parser_consume_token (parser
);
6196 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6198 expr
.value
= objc_build_protocol_expr (id
);
6202 /* Extension to support C-structures in the archiver. */
6203 gcc_assert (c_dialect_objc ());
6204 c_parser_consume_token (parser
);
6205 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6207 expr
.value
= error_mark_node
;
6210 t1
= c_parser_type_name (parser
);
6213 expr
.value
= error_mark_node
;
6214 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6217 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6220 tree type
= groktypename (t1
, NULL
, NULL
);
6221 expr
.value
= objc_build_encode_expr (type
);
6225 c_parser_error (parser
, "expected expression");
6226 expr
.value
= error_mark_node
;
6230 case CPP_OPEN_SQUARE
:
6231 if (c_dialect_objc ())
6233 tree receiver
, args
;
6234 c_parser_consume_token (parser
);
6235 receiver
= c_parser_objc_receiver (parser
);
6236 args
= c_parser_objc_message_args (parser
);
6237 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
6239 expr
.value
= objc_build_message_expr (build_tree_list (receiver
,
6243 /* Else fall through to report error. */
6245 c_parser_error (parser
, "expected expression");
6246 expr
.value
= error_mark_node
;
6249 return c_parser_postfix_expression_after_primary (parser
, loc
, expr
);
6252 /* Parse a postfix expression after a parenthesized type name: the
6253 brace-enclosed initializer of a compound literal, possibly followed
6254 by some postfix operators. This is separate because it is not
6255 possible to tell until after the type name whether a cast
6256 expression has a cast or a compound literal, or whether the operand
6257 of sizeof is a parenthesized type name or starts with a compound
6258 literal. TYPE_LOC is the location where TYPE_NAME starts--the
6259 location of the first token after the parentheses around the type
6262 static struct c_expr
6263 c_parser_postfix_expression_after_paren_type (c_parser
*parser
,
6264 struct c_type_name
*type_name
,
6265 location_t type_loc
)
6271 location_t start_loc
;
6272 tree type_expr
= NULL_TREE
;
6273 bool type_expr_const
= true;
6274 check_compound_literal_type (type_loc
, type_name
);
6275 start_init (NULL_TREE
, NULL
, 0);
6276 type
= groktypename (type_name
, &type_expr
, &type_expr_const
);
6277 start_loc
= c_parser_peek_token (parser
)->location
;
6278 if (type
!= error_mark_node
&& C_TYPE_VARIABLE_SIZE (type
))
6280 error_at (type_loc
, "compound literal has variable size");
6281 type
= error_mark_node
;
6283 init
= c_parser_braced_init (parser
, type
, false);
6285 maybe_warn_string_init (type
, init
);
6287 if (type
!= error_mark_node
6288 && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type
))
6289 && current_function_decl
)
6291 error ("compound literal qualified by address-space qualifier");
6292 type
= error_mark_node
;
6296 pedwarn (start_loc
, OPT_pedantic
, "ISO C90 forbids compound literals");
6297 non_const
= ((init
.value
&& TREE_CODE (init
.value
) == CONSTRUCTOR
)
6298 ? CONSTRUCTOR_NON_CONST (init
.value
)
6299 : init
.original_code
== C_MAYBE_CONST_EXPR
);
6300 non_const
|= !type_expr_const
;
6301 expr
.value
= build_compound_literal (start_loc
, type
, init
.value
, non_const
);
6302 expr
.original_code
= ERROR_MARK
;
6303 expr
.original_type
= NULL
;
6306 if (TREE_CODE (expr
.value
) == C_MAYBE_CONST_EXPR
)
6308 gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr
.value
) == NULL_TREE
);
6309 C_MAYBE_CONST_EXPR_PRE (expr
.value
) = type_expr
;
6313 gcc_assert (!non_const
);
6314 expr
.value
= build2 (C_MAYBE_CONST_EXPR
, type
,
6315 type_expr
, expr
.value
);
6318 return c_parser_postfix_expression_after_primary (parser
, start_loc
, expr
);
6321 /* Parse a postfix expression after the initial primary or compound
6322 literal; that is, parse a series of postfix operators.
6324 EXPR_LOC is the location of the primary expression. */
6326 static struct c_expr
6327 c_parser_postfix_expression_after_primary (c_parser
*parser
,
6328 location_t expr_loc
,
6331 struct c_expr orig_expr
;
6333 VEC(tree
,gc
) *exprlist
;
6334 VEC(tree
,gc
) *origtypes
;
6337 location_t op_loc
= c_parser_peek_token (parser
)->location
;
6338 switch (c_parser_peek_token (parser
)->type
)
6340 case CPP_OPEN_SQUARE
:
6341 /* Array reference. */
6342 c_parser_consume_token (parser
);
6343 idx
= c_parser_expression (parser
).value
;
6344 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
6346 expr
.value
= build_array_ref (op_loc
, expr
.value
, idx
);
6347 expr
.original_code
= ERROR_MARK
;
6348 expr
.original_type
= NULL
;
6350 case CPP_OPEN_PAREN
:
6351 /* Function call. */
6352 c_parser_consume_token (parser
);
6353 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
6356 exprlist
= c_parser_expr_list (parser
, true, false, &origtypes
);
6357 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6360 mark_exp_read (expr
.value
);
6361 /* FIXME diagnostics: Ideally we want the FUNCNAME, not the
6362 "(" after the FUNCNAME, which is what we have now. */
6363 expr
.value
= build_function_call_vec (op_loc
, expr
.value
, exprlist
,
6365 expr
.original_code
= ERROR_MARK
;
6366 if (TREE_CODE (expr
.value
) == INTEGER_CST
6367 && TREE_CODE (orig_expr
.value
) == FUNCTION_DECL
6368 && DECL_BUILT_IN_CLASS (orig_expr
.value
) == BUILT_IN_NORMAL
6369 && DECL_FUNCTION_CODE (orig_expr
.value
) == BUILT_IN_CONSTANT_P
)
6370 expr
.original_code
= C_MAYBE_CONST_EXPR
;
6371 expr
.original_type
= NULL
;
6372 if (exprlist
!= NULL
)
6374 release_tree_vector (exprlist
);
6375 release_tree_vector (origtypes
);
6379 /* Structure element reference. */
6380 c_parser_consume_token (parser
);
6381 expr
= default_function_array_conversion (expr_loc
, expr
);
6382 if (c_parser_next_token_is (parser
, CPP_NAME
))
6383 ident
= c_parser_peek_token (parser
)->value
;
6386 c_parser_error (parser
, "expected identifier");
6387 expr
.value
= error_mark_node
;
6388 expr
.original_code
= ERROR_MARK
;
6389 expr
.original_type
= NULL
;
6392 c_parser_consume_token (parser
);
6393 expr
.value
= build_component_ref (op_loc
, expr
.value
, ident
);
6394 expr
.original_code
= ERROR_MARK
;
6395 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
6396 expr
.original_type
= NULL
;
6399 /* Remember the original type of a bitfield. */
6400 tree field
= TREE_OPERAND (expr
.value
, 1);
6401 if (TREE_CODE (field
) != FIELD_DECL
)
6402 expr
.original_type
= NULL
;
6404 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
6408 /* Structure element reference. */
6409 c_parser_consume_token (parser
);
6410 expr
= default_function_array_conversion (expr_loc
, expr
);
6411 if (c_parser_next_token_is (parser
, CPP_NAME
))
6412 ident
= c_parser_peek_token (parser
)->value
;
6415 c_parser_error (parser
, "expected identifier");
6416 expr
.value
= error_mark_node
;
6417 expr
.original_code
= ERROR_MARK
;
6418 expr
.original_type
= NULL
;
6421 c_parser_consume_token (parser
);
6422 expr
.value
= build_component_ref (op_loc
,
6423 build_indirect_ref (op_loc
,
6427 expr
.original_code
= ERROR_MARK
;
6428 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
6429 expr
.original_type
= NULL
;
6432 /* Remember the original type of a bitfield. */
6433 tree field
= TREE_OPERAND (expr
.value
, 1);
6434 if (TREE_CODE (field
) != FIELD_DECL
)
6435 expr
.original_type
= NULL
;
6437 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
6441 /* Postincrement. */
6442 c_parser_consume_token (parser
);
6443 expr
= default_function_array_read_conversion (expr_loc
, expr
);
6444 expr
.value
= build_unary_op (op_loc
,
6445 POSTINCREMENT_EXPR
, expr
.value
, 0);
6446 expr
.original_code
= ERROR_MARK
;
6447 expr
.original_type
= NULL
;
6449 case CPP_MINUS_MINUS
:
6450 /* Postdecrement. */
6451 c_parser_consume_token (parser
);
6452 expr
= default_function_array_read_conversion (expr_loc
, expr
);
6453 expr
.value
= build_unary_op (op_loc
,
6454 POSTDECREMENT_EXPR
, expr
.value
, 0);
6455 expr
.original_code
= ERROR_MARK
;
6456 expr
.original_type
= NULL
;
6464 /* Parse an expression (C90 6.3.17, C99 6.5.17).
6467 assignment-expression
6468 expression , assignment-expression
6471 static struct c_expr
6472 c_parser_expression (c_parser
*parser
)
6475 expr
= c_parser_expr_no_commas (parser
, NULL
);
6476 while (c_parser_next_token_is (parser
, CPP_COMMA
))
6480 location_t loc
= c_parser_peek_token (parser
)->location
;
6481 location_t expr_loc
;
6482 c_parser_consume_token (parser
);
6483 expr_loc
= c_parser_peek_token (parser
)->location
;
6484 lhsval
= expr
.value
;
6485 while (TREE_CODE (lhsval
) == COMPOUND_EXPR
)
6486 lhsval
= TREE_OPERAND (lhsval
, 1);
6487 if (DECL_P (lhsval
) || handled_component_p (lhsval
))
6488 mark_exp_read (lhsval
);
6489 next
= c_parser_expr_no_commas (parser
, NULL
);
6490 next
= default_function_array_conversion (expr_loc
, next
);
6491 expr
.value
= build_compound_expr (loc
, expr
.value
, next
.value
);
6492 expr
.original_code
= COMPOUND_EXPR
;
6493 expr
.original_type
= next
.original_type
;
6498 /* Parse an expression and convert functions or arrays to
6501 static struct c_expr
6502 c_parser_expression_conv (c_parser
*parser
)
6505 location_t loc
= c_parser_peek_token (parser
)->location
;
6506 expr
= c_parser_expression (parser
);
6507 expr
= default_function_array_conversion (loc
, expr
);
6511 /* Parse a non-empty list of expressions. If CONVERT_P, convert
6512 functions and arrays to pointers. If FOLD_P, fold the expressions.
6515 assignment-expression
6516 nonempty-expr-list , assignment-expression
6519 static VEC(tree
,gc
) *
6520 c_parser_expr_list (c_parser
*parser
, bool convert_p
, bool fold_p
,
6521 VEC(tree
,gc
) **p_orig_types
)
6524 VEC(tree
,gc
) *orig_types
;
6526 location_t loc
= c_parser_peek_token (parser
)->location
;
6528 ret
= make_tree_vector ();
6529 if (p_orig_types
== NULL
)
6532 orig_types
= make_tree_vector ();
6534 expr
= c_parser_expr_no_commas (parser
, NULL
);
6536 expr
= default_function_array_read_conversion (loc
, expr
);
6538 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
6539 VEC_quick_push (tree
, ret
, expr
.value
);
6540 if (orig_types
!= NULL
)
6541 VEC_quick_push (tree
, orig_types
, expr
.original_type
);
6542 while (c_parser_next_token_is (parser
, CPP_COMMA
))
6544 c_parser_consume_token (parser
);
6545 loc
= c_parser_peek_token (parser
)->location
;
6546 expr
= c_parser_expr_no_commas (parser
, NULL
);
6548 expr
= default_function_array_read_conversion (loc
, expr
);
6550 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
6551 VEC_safe_push (tree
, gc
, ret
, expr
.value
);
6552 if (orig_types
!= NULL
)
6553 VEC_safe_push (tree
, gc
, orig_types
, expr
.original_type
);
6555 if (orig_types
!= NULL
)
6556 *p_orig_types
= orig_types
;
6560 /* Parse Objective-C-specific constructs. */
6562 /* Parse an objc-class-definition.
6564 objc-class-definition:
6565 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
6566 objc-class-instance-variables[opt] objc-methodprotolist @end
6567 @implementation identifier objc-superclass[opt]
6568 objc-class-instance-variables[opt]
6569 @interface identifier ( identifier ) objc-protocol-refs[opt]
6570 objc-methodprotolist @end
6571 @implementation identifier ( identifier )
6576 "@interface identifier (" must start "@interface identifier (
6577 identifier ) ...": objc-methodprotolist in the first production may
6578 not start with a parenthesized identifier as a declarator of a data
6579 definition with no declaration specifiers if the objc-superclass,
6580 objc-protocol-refs and objc-class-instance-variables are omitted. */
6583 c_parser_objc_class_definition (c_parser
*parser
, tree attributes
)
6588 if (c_parser_next_token_is_keyword (parser
, RID_AT_INTERFACE
))
6590 else if (c_parser_next_token_is_keyword (parser
, RID_AT_IMPLEMENTATION
))
6595 c_parser_consume_token (parser
);
6596 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6598 c_parser_error (parser
, "expected identifier");
6601 id1
= c_parser_peek_token (parser
)->value
;
6602 c_parser_consume_token (parser
);
6603 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
6606 tree proto
= NULL_TREE
;
6607 c_parser_consume_token (parser
);
6608 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6610 c_parser_error (parser
, "expected identifier");
6611 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6614 id2
= c_parser_peek_token (parser
)->value
;
6615 c_parser_consume_token (parser
);
6616 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6619 objc_start_category_implementation (id1
, id2
);
6622 if (c_parser_next_token_is (parser
, CPP_LESS
))
6623 proto
= c_parser_objc_protocol_refs (parser
);
6624 objc_start_category_interface (id1
, id2
, proto
, attributes
);
6625 c_parser_objc_methodprotolist (parser
);
6626 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
6627 objc_finish_interface ();
6630 if (c_parser_next_token_is (parser
, CPP_COLON
))
6632 c_parser_consume_token (parser
);
6633 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6635 c_parser_error (parser
, "expected identifier");
6638 superclass
= c_parser_peek_token (parser
)->value
;
6639 c_parser_consume_token (parser
);
6642 superclass
= NULL_TREE
;
6645 tree proto
= NULL_TREE
;
6646 if (c_parser_next_token_is (parser
, CPP_LESS
))
6647 proto
= c_parser_objc_protocol_refs (parser
);
6648 objc_start_class_interface (id1
, superclass
, proto
, attributes
);
6651 objc_start_class_implementation (id1
, superclass
);
6652 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6653 c_parser_objc_class_instance_variables (parser
);
6656 objc_continue_interface ();
6657 c_parser_objc_methodprotolist (parser
);
6658 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
6659 objc_finish_interface ();
6663 objc_continue_implementation ();
6668 /* Parse objc-class-instance-variables.
6670 objc-class-instance-variables:
6671 { objc-instance-variable-decl-list[opt] }
6673 objc-instance-variable-decl-list:
6674 objc-visibility-spec
6675 objc-instance-variable-decl ;
6677 objc-instance-variable-decl-list objc-visibility-spec
6678 objc-instance-variable-decl-list objc-instance-variable-decl ;
6679 objc-instance-variable-decl-list ;
6681 objc-visibility-spec:
6686 objc-instance-variable-decl:
6691 c_parser_objc_class_instance_variables (c_parser
*parser
)
6693 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
6694 c_parser_consume_token (parser
);
6695 while (c_parser_next_token_is_not (parser
, CPP_EOF
))
6698 /* Parse any stray semicolon. */
6699 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
6701 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
6702 "extra semicolon in struct or union specified");
6703 c_parser_consume_token (parser
);
6706 /* Stop if at the end of the instance variables. */
6707 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
6709 c_parser_consume_token (parser
);
6712 /* Parse any objc-visibility-spec. */
6713 if (c_parser_next_token_is_keyword (parser
, RID_AT_PRIVATE
))
6715 c_parser_consume_token (parser
);
6716 objc_set_visibility (OBJC_IVAR_VIS_PRIVATE
);
6719 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROTECTED
))
6721 c_parser_consume_token (parser
);
6722 objc_set_visibility (OBJC_IVAR_VIS_PROTECTED
);
6725 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PUBLIC
))
6727 c_parser_consume_token (parser
);
6728 objc_set_visibility (OBJC_IVAR_VIS_PUBLIC
);
6731 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PACKAGE
))
6733 c_parser_consume_token (parser
);
6734 objc_set_visibility (OBJC_IVAR_VIS_PACKAGE
);
6737 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
6739 c_parser_pragma (parser
, pragma_external
);
6743 /* Parse some comma-separated declarations. */
6744 decls
= c_parser_struct_declaration (parser
);
6746 /* Comma-separated instance variables are chained together in
6747 reverse order; add them one by one. */
6748 tree ivar
= nreverse (decls
);
6749 for (; ivar
; ivar
= DECL_CHAIN (ivar
))
6750 objc_add_instance_variable (copy_node (ivar
));
6752 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
6756 /* Parse an objc-class-declaration.
6758 objc-class-declaration:
6759 @class identifier-list ;
6763 c_parser_objc_class_declaration (c_parser
*parser
)
6765 tree list
= NULL_TREE
;
6766 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_CLASS
));
6767 c_parser_consume_token (parser
);
6768 /* Any identifiers, including those declared as type names, are OK
6773 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6775 c_parser_error (parser
, "expected identifier");
6776 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
6777 parser
->error
= false;
6780 id
= c_parser_peek_token (parser
)->value
;
6781 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
6782 c_parser_consume_token (parser
);
6783 if (c_parser_next_token_is (parser
, CPP_COMMA
))
6784 c_parser_consume_token (parser
);
6788 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
6789 objc_declare_class (list
);
6792 /* Parse an objc-alias-declaration.
6794 objc-alias-declaration:
6795 @compatibility_alias identifier identifier ;
6799 c_parser_objc_alias_declaration (c_parser
*parser
)
6802 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_ALIAS
));
6803 c_parser_consume_token (parser
);
6804 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6806 c_parser_error (parser
, "expected identifier");
6807 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
6810 id1
= c_parser_peek_token (parser
)->value
;
6811 c_parser_consume_token (parser
);
6812 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6814 c_parser_error (parser
, "expected identifier");
6815 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
6818 id2
= c_parser_peek_token (parser
)->value
;
6819 c_parser_consume_token (parser
);
6820 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
6821 objc_declare_alias (id1
, id2
);
6824 /* Parse an objc-protocol-definition.
6826 objc-protocol-definition:
6827 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
6828 @protocol identifier-list ;
6830 "@protocol identifier ;" should be resolved as "@protocol
6831 identifier-list ;": objc-methodprotolist may not start with a
6832 semicolon in the first alternative if objc-protocol-refs are
6836 c_parser_objc_protocol_definition (c_parser
*parser
, tree attributes
)
6838 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROTOCOL
));
6840 c_parser_consume_token (parser
);
6841 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6843 c_parser_error (parser
, "expected identifier");
6846 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
6847 || c_parser_peek_2nd_token (parser
)->type
== CPP_SEMICOLON
)
6849 tree list
= NULL_TREE
;
6850 /* Any identifiers, including those declared as type names, are
6855 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6857 c_parser_error (parser
, "expected identifier");
6860 id
= c_parser_peek_token (parser
)->value
;
6861 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
6862 c_parser_consume_token (parser
);
6863 if (c_parser_next_token_is (parser
, CPP_COMMA
))
6864 c_parser_consume_token (parser
);
6868 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
6869 objc_declare_protocols (list
);
6873 tree id
= c_parser_peek_token (parser
)->value
;
6874 tree proto
= NULL_TREE
;
6875 c_parser_consume_token (parser
);
6876 if (c_parser_next_token_is (parser
, CPP_LESS
))
6877 proto
= c_parser_objc_protocol_refs (parser
);
6878 parser
->objc_pq_context
= true;
6879 objc_start_protocol (id
, proto
, attributes
);
6880 c_parser_objc_methodprotolist (parser
);
6881 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
6882 parser
->objc_pq_context
= false;
6883 objc_finish_interface ();
6887 /* Parse an objc-method-type.
6893 Return true if it is a class method (+) and false if it is
6894 an instance method (-).
6897 c_parser_objc_method_type (c_parser
*parser
)
6899 switch (c_parser_peek_token (parser
)->type
)
6902 c_parser_consume_token (parser
);
6905 c_parser_consume_token (parser
);
6912 /* Parse an objc-method-definition.
6914 objc-method-definition:
6915 objc-method-type objc-method-decl ;[opt] compound-statement
6919 c_parser_objc_method_definition (c_parser
*parser
)
6921 bool is_class_method
= c_parser_objc_method_type (parser
);
6922 tree decl
, attributes
= NULL_TREE
;
6923 parser
->objc_pq_context
= true;
6924 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
);
6925 if (decl
== error_mark_node
)
6926 return; /* Bail here. */
6928 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
6930 c_parser_consume_token (parser
);
6931 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
6932 "extra semicolon in method definition specified");
6935 if (!c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6937 c_parser_error (parser
, "expected %<{%>");
6941 parser
->objc_pq_context
= false;
6942 if (objc_start_method_definition (is_class_method
, decl
, attributes
))
6944 add_stmt (c_parser_compound_statement (parser
));
6945 objc_finish_method_definition (current_function_decl
);
6949 /* This code is executed when we find a method definition
6950 outside of an @implementation context (or invalid for other
6951 reasons). Parse the method (to keep going) but do not emit
6954 c_parser_compound_statement (parser
);
6958 /* Parse an objc-methodprotolist.
6960 objc-methodprotolist:
6962 objc-methodprotolist objc-methodproto
6963 objc-methodprotolist declaration
6964 objc-methodprotolist ;
6968 The declaration is a data definition, which may be missing
6969 declaration specifiers under the same rules and diagnostics as
6970 other data definitions outside functions, and the stray semicolon
6971 is diagnosed the same way as a stray semicolon outside a
6975 c_parser_objc_methodprotolist (c_parser
*parser
)
6979 /* The list is terminated by @end. */
6980 switch (c_parser_peek_token (parser
)->type
)
6983 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
6984 "ISO C does not allow extra %<;%> outside of a function");
6985 c_parser_consume_token (parser
);
6989 c_parser_objc_methodproto (parser
);
6992 c_parser_pragma (parser
, pragma_external
);
6997 if (c_parser_next_token_is_keyword (parser
, RID_AT_END
))
6999 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
))
7000 c_parser_objc_at_property_declaration (parser
);
7001 else if (c_parser_next_token_is_keyword (parser
, RID_AT_OPTIONAL
))
7003 objc_set_method_opt (true);
7004 c_parser_consume_token (parser
);
7006 else if (c_parser_next_token_is_keyword (parser
, RID_AT_REQUIRED
))
7008 objc_set_method_opt (false);
7009 c_parser_consume_token (parser
);
7012 c_parser_declaration_or_fndef (parser
, false, false, true,
7019 /* Parse an objc-methodproto.
7022 objc-method-type objc-method-decl ;
7026 c_parser_objc_methodproto (c_parser
*parser
)
7028 bool is_class_method
= c_parser_objc_method_type (parser
);
7029 tree decl
, attributes
= NULL_TREE
;
7031 /* Remember protocol qualifiers in prototypes. */
7032 parser
->objc_pq_context
= true;
7033 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
);
7034 /* Forget protocol qualifiers now. */
7035 parser
->objc_pq_context
= false;
7037 /* Do not allow the presence of attributes to hide an erroneous
7038 method implementation in the interface section. */
7039 if (!c_parser_next_token_is (parser
, CPP_SEMICOLON
))
7041 c_parser_error (parser
, "expected %<;%>");
7045 if (decl
!= error_mark_node
)
7046 objc_add_method_declaration (is_class_method
, decl
, attributes
);
7048 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7051 /* If we are at a position that method attributes may be present, check that
7052 there are not any parsed already (a syntax error) and then collect any
7053 specified at the current location. Finally, if new attributes were present,
7054 check that the next token is legal ( ';' for decls and '{' for defs). */
7057 c_parser_objc_maybe_method_attributes (c_parser
* parser
, tree
* attributes
)
7062 c_parser_error (parser
,
7063 "method attributes must be specified at the end only");
7064 *attributes
= NULL_TREE
;
7068 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
7069 *attributes
= c_parser_attributes (parser
);
7071 /* If there were no attributes here, just report any earlier error. */
7072 if (*attributes
== NULL_TREE
|| bad
)
7075 /* If the attributes are followed by a ; or {, then just report any earlier
7077 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
7078 || c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
7081 /* We've got attributes, but not at the end. */
7082 c_parser_error (parser
,
7083 "expected %<;%> or %<{%> after method attribute definition");
7087 /* Parse an objc-method-decl.
7090 ( objc-type-name ) objc-selector
7092 ( objc-type-name ) objc-keyword-selector objc-optparmlist
7093 objc-keyword-selector objc-optparmlist
7096 objc-keyword-selector:
7098 objc-keyword-selector objc-keyword-decl
7101 objc-selector : ( objc-type-name ) identifier
7102 objc-selector : identifier
7103 : ( objc-type-name ) identifier
7107 objc-optparms objc-optellipsis
7111 objc-opt-parms , parameter-declaration
7119 c_parser_objc_method_decl (c_parser
*parser
, bool is_class_method
, tree
*attributes
)
7121 tree type
= NULL_TREE
;
7123 tree parms
= NULL_TREE
;
7124 bool ellipsis
= false;
7125 bool attr_err
= false;
7127 *attributes
= NULL_TREE
;
7128 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
7130 c_parser_consume_token (parser
);
7131 type
= c_parser_objc_type_name (parser
);
7132 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7134 sel
= c_parser_objc_selector (parser
);
7135 /* If there is no selector, or a colon follows, we have an
7136 objc-keyword-selector. If there is a selector, and a colon does
7137 not follow, that selector ends the objc-method-decl. */
7138 if (!sel
|| c_parser_next_token_is (parser
, CPP_COLON
))
7141 tree list
= NULL_TREE
;
7144 tree atype
= NULL_TREE
, id
, keyworddecl
;
7145 tree param_attr
= NULL_TREE
;
7146 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
7148 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
7150 c_parser_consume_token (parser
);
7151 atype
= c_parser_objc_type_name (parser
);
7152 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7155 /* New ObjC allows attributes on method parameters. */
7156 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
7157 param_attr
= c_parser_attributes (parser
);
7158 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7160 c_parser_error (parser
, "expected identifier");
7161 return error_mark_node
;
7163 id
= c_parser_peek_token (parser
)->value
;
7164 c_parser_consume_token (parser
);
7165 keyworddecl
= objc_build_keyword_decl (tsel
, atype
, id
, param_attr
);
7166 list
= chainon (list
, keyworddecl
);
7167 tsel
= c_parser_objc_selector (parser
);
7168 if (!tsel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
7172 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
7174 /* Parse the optional parameter list. Optional Objective-C
7175 method parameters follow the C syntax, and may include '...'
7176 to denote a variable number of arguments. */
7177 parms
= make_node (TREE_LIST
);
7178 while (c_parser_next_token_is (parser
, CPP_COMMA
))
7180 struct c_parm
*parm
;
7181 c_parser_consume_token (parser
);
7182 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
7185 c_parser_consume_token (parser
);
7186 attr_err
|= c_parser_objc_maybe_method_attributes
7187 (parser
, attributes
) ;
7190 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
7193 parms
= chainon (parms
,
7194 build_tree_list (NULL_TREE
, grokparm (parm
)));
7199 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
7203 c_parser_error (parser
, "objective-c method declaration is expected");
7204 return error_mark_node
;
7208 return error_mark_node
;
7210 return objc_build_method_signature (is_class_method
, type
, sel
, parms
, ellipsis
);
7213 /* Parse an objc-type-name.
7216 objc-type-qualifiers[opt] type-name
7217 objc-type-qualifiers[opt]
7219 objc-type-qualifiers:
7221 objc-type-qualifiers objc-type-qualifier
7223 objc-type-qualifier: one of
7224 in out inout bycopy byref oneway
7228 c_parser_objc_type_name (c_parser
*parser
)
7230 tree quals
= NULL_TREE
;
7231 struct c_type_name
*type_name
= NULL
;
7232 tree type
= NULL_TREE
;
7235 c_token
*token
= c_parser_peek_token (parser
);
7236 if (token
->type
== CPP_KEYWORD
7237 && (token
->keyword
== RID_IN
7238 || token
->keyword
== RID_OUT
7239 || token
->keyword
== RID_INOUT
7240 || token
->keyword
== RID_BYCOPY
7241 || token
->keyword
== RID_BYREF
7242 || token
->keyword
== RID_ONEWAY
))
7244 quals
= chainon (build_tree_list (NULL_TREE
, token
->value
), quals
);
7245 c_parser_consume_token (parser
);
7250 if (c_parser_next_token_starts_typename (parser
))
7251 type_name
= c_parser_type_name (parser
);
7253 type
= groktypename (type_name
, NULL
, NULL
);
7254 return build_tree_list (quals
, type
);
7257 /* Parse objc-protocol-refs.
7264 c_parser_objc_protocol_refs (c_parser
*parser
)
7266 tree list
= NULL_TREE
;
7267 gcc_assert (c_parser_next_token_is (parser
, CPP_LESS
));
7268 c_parser_consume_token (parser
);
7269 /* Any identifiers, including those declared as type names, are OK
7274 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7276 c_parser_error (parser
, "expected identifier");
7279 id
= c_parser_peek_token (parser
)->value
;
7280 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
7281 c_parser_consume_token (parser
);
7282 if (c_parser_next_token_is (parser
, CPP_COMMA
))
7283 c_parser_consume_token (parser
);
7287 c_parser_require (parser
, CPP_GREATER
, "expected %<>%>");
7291 /* Parse an objc-try-catch-statement.
7293 objc-try-catch-statement:
7294 @try compound-statement objc-catch-list[opt]
7295 @try compound-statement objc-catch-list[opt] @finally compound-statement
7298 @catch ( parameter-declaration ) compound-statement
7299 objc-catch-list @catch ( parameter-declaration ) compound-statement
7303 c_parser_objc_try_catch_statement (c_parser
*parser
)
7307 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_TRY
));
7308 c_parser_consume_token (parser
);
7309 loc
= c_parser_peek_token (parser
)->location
;
7310 stmt
= c_parser_compound_statement (parser
);
7311 objc_begin_try_stmt (loc
, stmt
);
7312 while (c_parser_next_token_is_keyword (parser
, RID_AT_CATCH
))
7314 struct c_parm
*parm
;
7315 c_parser_consume_token (parser
);
7316 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7318 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
7321 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7324 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7325 objc_begin_catch_clause (grokparm (parm
));
7326 if (c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
7327 c_parser_compound_statement_nostart (parser
);
7328 objc_finish_catch_clause ();
7330 if (c_parser_next_token_is_keyword (parser
, RID_AT_FINALLY
))
7334 c_parser_consume_token (parser
);
7335 finloc
= c_parser_peek_token (parser
)->location
;
7336 finstmt
= c_parser_compound_statement (parser
);
7337 objc_build_finally_clause (finloc
, finstmt
);
7339 objc_finish_try_stmt ();
7342 /* Parse an objc-synchronized-statement.
7344 objc-synchronized-statement:
7345 @synchronized ( expression ) compound-statement
7349 c_parser_objc_synchronized_statement (c_parser
*parser
)
7353 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNCHRONIZED
));
7354 c_parser_consume_token (parser
);
7355 loc
= c_parser_peek_token (parser
)->location
;
7356 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7358 expr
= c_parser_expression (parser
).value
;
7359 expr
= c_fully_fold (expr
, false, NULL
);
7360 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7363 expr
= error_mark_node
;
7364 stmt
= c_parser_compound_statement (parser
);
7365 objc_build_synchronized (loc
, expr
, stmt
);
7368 /* Parse an objc-selector; return NULL_TREE without an error if the
7369 next token is not an objc-selector.
7374 enum struct union if else while do for switch case default
7375 break continue return goto asm sizeof typeof __alignof
7376 unsigned long const short volatile signed restrict _Complex
7377 in out inout bycopy byref oneway int char float double void _Bool
7379 ??? Why this selection of keywords but not, for example, storage
7380 class specifiers? */
7383 c_parser_objc_selector (c_parser
*parser
)
7385 c_token
*token
= c_parser_peek_token (parser
);
7386 tree value
= token
->value
;
7387 if (token
->type
== CPP_NAME
)
7389 c_parser_consume_token (parser
);
7392 if (token
->type
!= CPP_KEYWORD
)
7394 switch (token
->keyword
)
7436 c_parser_consume_token (parser
);
7443 /* Parse an objc-selector-arg.
7447 objc-keywordname-list
7449 objc-keywordname-list:
7451 objc-keywordname-list objc-keywordname
7459 c_parser_objc_selector_arg (c_parser
*parser
)
7461 tree sel
= c_parser_objc_selector (parser
);
7462 tree list
= NULL_TREE
;
7463 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
7467 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
7469 list
= chainon (list
, build_tree_list (sel
, NULL_TREE
));
7470 sel
= c_parser_objc_selector (parser
);
7471 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
7477 /* Parse an objc-receiver.
7486 c_parser_objc_receiver (c_parser
*parser
)
7488 if (c_parser_peek_token (parser
)->type
== CPP_NAME
7489 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
7490 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
7492 tree id
= c_parser_peek_token (parser
)->value
;
7493 c_parser_consume_token (parser
);
7494 return objc_get_class_reference (id
);
7496 return c_fully_fold (c_parser_expression (parser
).value
, false, NULL
);
7499 /* Parse objc-message-args.
7503 objc-keywordarg-list
7505 objc-keywordarg-list:
7507 objc-keywordarg-list objc-keywordarg
7510 objc-selector : objc-keywordexpr
7515 c_parser_objc_message_args (c_parser
*parser
)
7517 tree sel
= c_parser_objc_selector (parser
);
7518 tree list
= NULL_TREE
;
7519 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
7524 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
7525 return error_mark_node
;
7526 keywordexpr
= c_parser_objc_keywordexpr (parser
);
7527 list
= chainon (list
, build_tree_list (sel
, keywordexpr
));
7528 sel
= c_parser_objc_selector (parser
);
7529 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
7535 /* Parse an objc-keywordexpr.
7542 c_parser_objc_keywordexpr (c_parser
*parser
)
7545 VEC(tree
,gc
) *expr_list
= c_parser_expr_list (parser
, true, true, NULL
);
7546 if (VEC_length (tree
, expr_list
) == 1)
7548 /* Just return the expression, remove a level of
7550 ret
= VEC_index (tree
, expr_list
, 0);
7554 /* We have a comma expression, we will collapse later. */
7555 ret
= build_tree_list_vec (expr_list
);
7557 release_tree_vector (expr_list
);
7561 /* A check, needed in several places, that ObjC interface, implementation or
7562 method definitions are not prefixed by incorrect items. */
7564 c_parser_objc_diagnose_bad_element_prefix (c_parser
*parser
,
7565 struct c_declspecs
*specs
)
7567 if (!specs
->declspecs_seen_p
|| specs
->type_seen_p
|| specs
->non_sc_seen_p
)
7569 c_parser_error (parser
,
7570 "no type or storage class may be specified here,");
7571 c_parser_skip_to_end_of_block_or_statement (parser
);
7577 /* Parse an Objective-C @property declaration. The syntax is:
7579 objc-property-declaration:
7580 '@property' objc-property-attributes[opt] struct-declaration ;
7582 objc-property-attributes:
7583 '(' objc-property-attribute-list ')'
7585 objc-property-attribute-list:
7586 objc-property-attribute
7587 objc-property-attribute-list, objc-property-attribute
7589 objc-property-attribute
7590 'getter' = identifier
7591 'setter' = identifier
7600 @property NSString *name;
7601 @property (readonly) id object;
7602 @property (retain, nonatomic, getter=getTheName) id name;
7603 @property int a, b, c;
7605 PS: This function is identical to cp_parser_objc_at_propery_declaration
7606 for C++. Keep them in sync. */
7608 c_parser_objc_at_property_declaration (c_parser
*parser
)
7610 /* The following variables hold the attributes of the properties as
7611 parsed. They are 'false' or 'NULL_TREE' if the attribute was not
7612 seen. When we see an attribute, we set them to 'true' (if they
7613 are boolean properties) or to the identifier (if they have an
7614 argument, ie, for getter and setter). Note that here we only
7615 parse the list of attributes, check the syntax and accumulate the
7616 attributes that we find. objc_add_property_declaration() will
7617 then process the information. */
7618 bool property_assign
= false;
7619 bool property_copy
= false;
7620 tree property_getter_ident
= NULL_TREE
;
7621 bool property_nonatomic
= false;
7622 bool property_readonly
= false;
7623 bool property_readwrite
= false;
7624 bool property_retain
= false;
7625 tree property_setter_ident
= NULL_TREE
;
7626 /* The following two will be removed once @synthesize is
7628 bool property_copies
= false;
7629 tree property_ivar_ident
= NULL_TREE
;
7631 /* 'properties' is the list of properties that we read. Usually a
7632 single one, but maybe more (eg, in "@property int a, b, c;" there
7637 loc
= c_parser_peek_token (parser
)->location
;
7638 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
));
7640 c_parser_consume_token (parser
); /* Eat '@property'. */
7642 /* Parse the optional attribute list... */
7643 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
7646 c_parser_consume_token (parser
);
7648 /* Property attribute keywords are valid now. */
7649 parser
->objc_property_attr_context
= true;
7653 bool syntax_error
= false;
7654 c_token
*token
= c_parser_peek_token (parser
);
7657 if (token
->type
!= CPP_KEYWORD
)
7659 if (token
->type
== CPP_CLOSE_PAREN
)
7660 c_parser_error (parser
, "expected identifier");
7663 c_parser_consume_token (parser
);
7664 c_parser_error (parser
, "unknown property attribute");
7668 keyword
= token
->keyword
;
7669 c_parser_consume_token (parser
);
7672 case RID_ASSIGN
: property_assign
= true; break;
7673 case RID_COPIES
: property_copies
= true; break;
7674 case RID_COPY
: property_copy
= true; break;
7675 case RID_NONATOMIC
: property_nonatomic
= true; break;
7676 case RID_READONLY
: property_readonly
= true; break;
7677 case RID_READWRITE
: property_readwrite
= true; break;
7678 case RID_RETAIN
: property_retain
= true; break;
7683 if (c_parser_next_token_is_not (parser
, CPP_EQ
))
7685 c_parser_error (parser
,
7686 "getter/setter/ivar attribute must be followed by %<=%>");
7687 syntax_error
= true;
7690 c_parser_consume_token (parser
); /* eat the = */
7691 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7693 c_parser_error (parser
, "expected identifier");
7694 syntax_error
= true;
7697 if (keyword
== RID_SETTER
)
7699 if (property_setter_ident
!= NULL_TREE
)
7700 c_parser_error (parser
, "the %<setter%> attribute may only be specified once");
7702 property_setter_ident
= c_parser_peek_token (parser
)->value
;
7703 c_parser_consume_token (parser
);
7704 if (c_parser_next_token_is_not (parser
, CPP_COLON
))
7705 c_parser_error (parser
, "setter name must terminate with %<:%>");
7707 c_parser_consume_token (parser
);
7709 else if (keyword
== RID_GETTER
)
7711 if (property_getter_ident
!= NULL_TREE
)
7712 c_parser_error (parser
, "the %<getter%> attribute may only be specified once");
7714 property_getter_ident
= c_parser_peek_token (parser
)->value
;
7715 c_parser_consume_token (parser
);
7717 else /* RID_IVAR, this case will go away. */
7719 if (property_ivar_ident
!= NULL_TREE
)
7720 c_parser_error (parser
, "the %<ivar%> attribute may only be specified once");
7722 property_ivar_ident
= c_parser_peek_token (parser
)->value
;
7723 c_parser_consume_token (parser
);
7727 c_parser_error (parser
, "unknown property attribute");
7728 syntax_error
= true;
7735 if (c_parser_next_token_is (parser
, CPP_COMMA
))
7736 c_parser_consume_token (parser
);
7740 parser
->objc_property_attr_context
= false;
7741 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7743 /* ... and the property declaration(s). */
7744 properties
= c_parser_struct_declaration (parser
);
7746 if (properties
== error_mark_node
)
7748 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
7749 parser
->error
= false;
7753 if (properties
== NULL_TREE
)
7754 c_parser_error (parser
, "expected identifier");
7757 /* Comma-separated properties are chained together in
7758 reverse order; add them one by one. */
7759 properties
= nreverse (properties
);
7761 for (; properties
; properties
= TREE_CHAIN (properties
))
7762 objc_add_property_declaration (loc
, copy_node (properties
),
7763 property_readonly
, property_readwrite
,
7764 property_assign
, property_retain
,
7765 property_copy
, property_nonatomic
,
7766 property_getter_ident
, property_setter_ident
,
7767 /* The following two will be removed. */
7768 property_copies
, property_ivar_ident
);
7771 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7772 parser
->error
= false;
7775 /* Parse an Objective-C @synthesize declaration. The syntax is:
7777 objc-synthesize-declaration:
7778 @synthesize objc-synthesize-identifier-list ;
7780 objc-synthesize-identifier-list:
7781 objc-synthesize-identifier
7782 objc-synthesize-identifier-list, objc-synthesize-identifier
7784 objc-synthesize-identifier
7786 identifier = identifier
7789 @synthesize MyProperty;
7790 @synthesize OneProperty, AnotherProperty=MyIvar, YetAnotherProperty;
7792 PS: This function is identical to cp_parser_objc_at_synthesize_declaration
7793 for C++. Keep them in sync.
7796 c_parser_objc_at_synthesize_declaration (c_parser
*parser
)
7798 tree list
= NULL_TREE
;
7800 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNTHESIZE
));
7801 loc
= c_parser_peek_token (parser
)->location
;
7803 c_parser_consume_token (parser
);
7806 tree property
, ivar
;
7807 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7809 c_parser_error (parser
, "expected identifier");
7810 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
7811 /* Once we find the semicolon, we can resume normal parsing.
7812 We have to reset parser->error manually because
7813 c_parser_skip_until_found() won't reset it for us if the
7814 next token is precisely a semicolon. */
7815 parser
->error
= false;
7818 property
= c_parser_peek_token (parser
)->value
;
7819 c_parser_consume_token (parser
);
7820 if (c_parser_next_token_is (parser
, CPP_EQ
))
7822 c_parser_consume_token (parser
);
7823 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7825 c_parser_error (parser
, "expected identifier");
7826 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
7827 parser
->error
= false;
7830 ivar
= c_parser_peek_token (parser
)->value
;
7831 c_parser_consume_token (parser
);
7835 list
= chainon (list
, build_tree_list (ivar
, property
));
7836 if (c_parser_next_token_is (parser
, CPP_COMMA
))
7837 c_parser_consume_token (parser
);
7841 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7842 objc_add_synthesize_declaration (loc
, list
);
7845 /* Parse an Objective-C @dynamic declaration. The syntax is:
7847 objc-dynamic-declaration:
7848 @dynamic identifier-list ;
7851 @dynamic MyProperty;
7852 @dynamic MyProperty, AnotherProperty;
7854 PS: This function is identical to cp_parser_objc_at_dynamic_declaration
7855 for C++. Keep them in sync.
7858 c_parser_objc_at_dynamic_declaration (c_parser
*parser
)
7860 tree list
= NULL_TREE
;
7862 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_DYNAMIC
));
7863 loc
= c_parser_peek_token (parser
)->location
;
7865 c_parser_consume_token (parser
);
7869 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7871 c_parser_error (parser
, "expected identifier");
7872 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
7873 parser
->error
= false;
7876 property
= c_parser_peek_token (parser
)->value
;
7877 list
= chainon (list
, build_tree_list (NULL_TREE
, property
));
7878 c_parser_consume_token (parser
);
7879 if (c_parser_next_token_is (parser
, CPP_COMMA
))
7880 c_parser_consume_token (parser
);
7884 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7885 objc_add_dynamic_declaration (loc
, list
);
7889 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
7890 should be considered, statements. ALLOW_STMT is true if we're within
7891 the context of a function and such pragmas are to be allowed. Returns
7892 true if we actually parsed such a pragma. */
7895 c_parser_pragma (c_parser
*parser
, enum pragma_context context
)
7899 id
= c_parser_peek_token (parser
)->pragma_kind
;
7900 gcc_assert (id
!= PRAGMA_NONE
);
7904 case PRAGMA_OMP_BARRIER
:
7905 if (context
!= pragma_compound
)
7907 if (context
== pragma_stmt
)
7908 c_parser_error (parser
, "%<#pragma omp barrier%> may only be "
7909 "used in compound statements");
7912 c_parser_omp_barrier (parser
);
7915 case PRAGMA_OMP_FLUSH
:
7916 if (context
!= pragma_compound
)
7918 if (context
== pragma_stmt
)
7919 c_parser_error (parser
, "%<#pragma omp flush%> may only be "
7920 "used in compound statements");
7923 c_parser_omp_flush (parser
);
7926 case PRAGMA_OMP_TASKWAIT
:
7927 if (context
!= pragma_compound
)
7929 if (context
== pragma_stmt
)
7930 c_parser_error (parser
, "%<#pragma omp taskwait%> may only be "
7931 "used in compound statements");
7934 c_parser_omp_taskwait (parser
);
7937 case PRAGMA_OMP_THREADPRIVATE
:
7938 c_parser_omp_threadprivate (parser
);
7941 case PRAGMA_OMP_SECTION
:
7942 error_at (c_parser_peek_token (parser
)->location
,
7943 "%<#pragma omp section%> may only be used in "
7944 "%<#pragma omp sections%> construct");
7945 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
7948 case PRAGMA_GCC_PCH_PREPROCESS
:
7949 c_parser_error (parser
, "%<#pragma GCC pch_preprocess%> must be first");
7950 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
7954 if (id
< PRAGMA_FIRST_EXTERNAL
)
7956 if (context
== pragma_external
)
7959 c_parser_error (parser
, "expected declaration specifiers");
7960 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
7963 c_parser_omp_construct (parser
);
7969 c_parser_consume_pragma (parser
);
7970 c_invoke_pragma_handler (id
);
7972 /* Skip to EOL, but suppress any error message. Those will have been
7973 generated by the handler routine through calling error, as opposed
7974 to calling c_parser_error. */
7975 parser
->error
= true;
7976 c_parser_skip_to_pragma_eol (parser
);
7981 /* The interface the pragma parsers have to the lexer. */
7984 pragma_lex (tree
*value
)
7986 c_token
*tok
= c_parser_peek_token (the_parser
);
7987 enum cpp_ttype ret
= tok
->type
;
7989 *value
= tok
->value
;
7990 if (ret
== CPP_PRAGMA_EOL
|| ret
== CPP_EOF
)
7994 if (ret
== CPP_KEYWORD
)
7996 c_parser_consume_token (the_parser
);
8003 c_parser_pragma_pch_preprocess (c_parser
*parser
)
8007 c_parser_consume_pragma (parser
);
8008 if (c_parser_next_token_is (parser
, CPP_STRING
))
8010 name
= c_parser_peek_token (parser
)->value
;
8011 c_parser_consume_token (parser
);
8014 c_parser_error (parser
, "expected string literal");
8015 c_parser_skip_to_pragma_eol (parser
);
8018 c_common_pch_pragma (parse_in
, TREE_STRING_POINTER (name
));
8021 /* OpenMP 2.5 parsing routines. */
8023 /* Returns name of the next clause.
8024 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
8025 the token is not consumed. Otherwise appropriate pragma_omp_clause is
8026 returned and the token is consumed. */
8028 static pragma_omp_clause
8029 c_parser_omp_clause_name (c_parser
*parser
)
8031 pragma_omp_clause result
= PRAGMA_OMP_CLAUSE_NONE
;
8033 if (c_parser_next_token_is_keyword (parser
, RID_IF
))
8034 result
= PRAGMA_OMP_CLAUSE_IF
;
8035 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
8036 result
= PRAGMA_OMP_CLAUSE_DEFAULT
;
8037 else if (c_parser_next_token_is (parser
, CPP_NAME
))
8039 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
8044 if (!strcmp ("collapse", p
))
8045 result
= PRAGMA_OMP_CLAUSE_COLLAPSE
;
8046 else if (!strcmp ("copyin", p
))
8047 result
= PRAGMA_OMP_CLAUSE_COPYIN
;
8048 else if (!strcmp ("copyprivate", p
))
8049 result
= PRAGMA_OMP_CLAUSE_COPYPRIVATE
;
8052 if (!strcmp ("firstprivate", p
))
8053 result
= PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
;
8056 if (!strcmp ("lastprivate", p
))
8057 result
= PRAGMA_OMP_CLAUSE_LASTPRIVATE
;
8060 if (!strcmp ("nowait", p
))
8061 result
= PRAGMA_OMP_CLAUSE_NOWAIT
;
8062 else if (!strcmp ("num_threads", p
))
8063 result
= PRAGMA_OMP_CLAUSE_NUM_THREADS
;
8066 if (!strcmp ("ordered", p
))
8067 result
= PRAGMA_OMP_CLAUSE_ORDERED
;
8070 if (!strcmp ("private", p
))
8071 result
= PRAGMA_OMP_CLAUSE_PRIVATE
;
8074 if (!strcmp ("reduction", p
))
8075 result
= PRAGMA_OMP_CLAUSE_REDUCTION
;
8078 if (!strcmp ("schedule", p
))
8079 result
= PRAGMA_OMP_CLAUSE_SCHEDULE
;
8080 else if (!strcmp ("shared", p
))
8081 result
= PRAGMA_OMP_CLAUSE_SHARED
;
8084 if (!strcmp ("untied", p
))
8085 result
= PRAGMA_OMP_CLAUSE_UNTIED
;
8090 if (result
!= PRAGMA_OMP_CLAUSE_NONE
)
8091 c_parser_consume_token (parser
);
8096 /* Validate that a clause of the given type does not already exist. */
8099 check_no_duplicate_clause (tree clauses
, enum omp_clause_code code
,
8104 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
8105 if (OMP_CLAUSE_CODE (c
) == code
)
8107 location_t loc
= OMP_CLAUSE_LOCATION (c
);
8108 error_at (loc
, "too many %qs clauses", name
);
8116 variable-list , identifier
8118 If KIND is nonzero, create the appropriate node and install the
8119 decl in OMP_CLAUSE_DECL and add the node to the head of the list.
8120 If KIND is nonzero, CLAUSE_LOC is the location of the clause.
8122 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
8123 return the list created. */
8126 c_parser_omp_variable_list (c_parser
*parser
,
8127 location_t clause_loc
,
8128 enum omp_clause_code kind
,
8131 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
8132 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
8133 c_parser_error (parser
, "expected identifier");
8135 while (c_parser_next_token_is (parser
, CPP_NAME
)
8136 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
8138 tree t
= lookup_name (c_parser_peek_token (parser
)->value
);
8141 undeclared_variable (c_parser_peek_token (parser
)->location
,
8142 c_parser_peek_token (parser
)->value
);
8143 else if (t
== error_mark_node
)
8147 tree u
= build_omp_clause (clause_loc
, kind
);
8148 OMP_CLAUSE_DECL (u
) = t
;
8149 OMP_CLAUSE_CHAIN (u
) = list
;
8153 list
= tree_cons (t
, NULL_TREE
, list
);
8155 c_parser_consume_token (parser
);
8157 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
8160 c_parser_consume_token (parser
);
8166 /* Similarly, but expect leading and trailing parenthesis. This is a very
8167 common case for omp clauses. */
8170 c_parser_omp_var_list_parens (c_parser
*parser
, enum omp_clause_code kind
,
8173 /* The clauses location. */
8174 location_t loc
= c_parser_peek_token (parser
)->location
;
8176 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8178 list
= c_parser_omp_variable_list (parser
, loc
, kind
, list
);
8179 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8185 collapse ( constant-expression ) */
8188 c_parser_omp_clause_collapse (c_parser
*parser
, tree list
)
8190 tree c
, num
= error_mark_node
;
8194 check_no_duplicate_clause (list
, OMP_CLAUSE_COLLAPSE
, "collapse");
8196 loc
= c_parser_peek_token (parser
)->location
;
8197 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8199 num
= c_parser_expr_no_commas (parser
, NULL
).value
;
8200 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8202 if (num
== error_mark_node
)
8204 if (!INTEGRAL_TYPE_P (TREE_TYPE (num
))
8205 || !host_integerp (num
, 0)
8206 || (n
= tree_low_cst (num
, 0)) <= 0
8210 "collapse argument needs positive constant integer expression");
8213 c
= build_omp_clause (loc
, OMP_CLAUSE_COLLAPSE
);
8214 OMP_CLAUSE_COLLAPSE_EXPR (c
) = num
;
8215 OMP_CLAUSE_CHAIN (c
) = list
;
8220 copyin ( variable-list ) */
8223 c_parser_omp_clause_copyin (c_parser
*parser
, tree list
)
8225 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYIN
, list
);
8229 copyprivate ( variable-list ) */
8232 c_parser_omp_clause_copyprivate (c_parser
*parser
, tree list
)
8234 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYPRIVATE
, list
);
8238 default ( shared | none ) */
8241 c_parser_omp_clause_default (c_parser
*parser
, tree list
)
8243 enum omp_clause_default_kind kind
= OMP_CLAUSE_DEFAULT_UNSPECIFIED
;
8244 location_t loc
= c_parser_peek_token (parser
)->location
;
8247 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8249 if (c_parser_next_token_is (parser
, CPP_NAME
))
8251 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
8256 if (strcmp ("none", p
) != 0)
8258 kind
= OMP_CLAUSE_DEFAULT_NONE
;
8262 if (strcmp ("shared", p
) != 0)
8264 kind
= OMP_CLAUSE_DEFAULT_SHARED
;
8271 c_parser_consume_token (parser
);
8276 c_parser_error (parser
, "expected %<none%> or %<shared%>");
8278 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8280 if (kind
== OMP_CLAUSE_DEFAULT_UNSPECIFIED
)
8283 check_no_duplicate_clause (list
, OMP_CLAUSE_DEFAULT
, "default");
8284 c
= build_omp_clause (loc
, OMP_CLAUSE_DEFAULT
);
8285 OMP_CLAUSE_CHAIN (c
) = list
;
8286 OMP_CLAUSE_DEFAULT_KIND (c
) = kind
;
8292 firstprivate ( variable-list ) */
8295 c_parser_omp_clause_firstprivate (c_parser
*parser
, tree list
)
8297 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FIRSTPRIVATE
, list
);
8301 if ( expression ) */
8304 c_parser_omp_clause_if (c_parser
*parser
, tree list
)
8306 location_t loc
= c_parser_peek_token (parser
)->location
;
8307 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8309 tree t
= c_parser_paren_condition (parser
);
8312 check_no_duplicate_clause (list
, OMP_CLAUSE_IF
, "if");
8314 c
= build_omp_clause (loc
, OMP_CLAUSE_IF
);
8315 OMP_CLAUSE_IF_EXPR (c
) = t
;
8316 OMP_CLAUSE_CHAIN (c
) = list
;
8320 c_parser_error (parser
, "expected %<(%>");
8326 lastprivate ( variable-list ) */
8329 c_parser_omp_clause_lastprivate (c_parser
*parser
, tree list
)
8331 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_LASTPRIVATE
, list
);
8338 c_parser_omp_clause_nowait (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
8341 location_t loc
= c_parser_peek_token (parser
)->location
;
8343 check_no_duplicate_clause (list
, OMP_CLAUSE_NOWAIT
, "nowait");
8345 c
= build_omp_clause (loc
, OMP_CLAUSE_NOWAIT
);
8346 OMP_CLAUSE_CHAIN (c
) = list
;
8351 num_threads ( expression ) */
8354 c_parser_omp_clause_num_threads (c_parser
*parser
, tree list
)
8356 location_t num_threads_loc
= c_parser_peek_token (parser
)->location
;
8357 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8359 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
8360 tree c
, t
= c_parser_expression (parser
).value
;
8361 t
= c_fully_fold (t
, false, NULL
);
8363 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8365 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
8367 c_parser_error (parser
, "expected integer expression");
8371 /* Attempt to statically determine when the number isn't positive. */
8372 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
8373 build_int_cst (TREE_TYPE (t
), 0));
8374 if (CAN_HAVE_LOCATION_P (c
))
8375 SET_EXPR_LOCATION (c
, expr_loc
);
8376 if (c
== boolean_true_node
)
8378 warning_at (expr_loc
, 0,
8379 "%<num_threads%> value must be positive");
8380 t
= integer_one_node
;
8383 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_THREADS
, "num_threads");
8385 c
= build_omp_clause (num_threads_loc
, OMP_CLAUSE_NUM_THREADS
);
8386 OMP_CLAUSE_NUM_THREADS_EXPR (c
) = t
;
8387 OMP_CLAUSE_CHAIN (c
) = list
;
8398 c_parser_omp_clause_ordered (c_parser
*parser
, tree list
)
8402 check_no_duplicate_clause (list
, OMP_CLAUSE_ORDERED
, "ordered");
8404 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
8405 OMP_CLAUSE_ORDERED
);
8406 OMP_CLAUSE_CHAIN (c
) = list
;
8412 private ( variable-list ) */
8415 c_parser_omp_clause_private (c_parser
*parser
, tree list
)
8417 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_PRIVATE
, list
);
8421 reduction ( reduction-operator : variable-list )
8424 One of: + * - & ^ | && || */
8427 c_parser_omp_clause_reduction (c_parser
*parser
, tree list
)
8429 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
8430 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8432 enum tree_code code
;
8434 switch (c_parser_peek_token (parser
)->type
)
8446 code
= BIT_AND_EXPR
;
8449 code
= BIT_XOR_EXPR
;
8452 code
= BIT_IOR_EXPR
;
8455 code
= TRUTH_ANDIF_EXPR
;
8458 code
= TRUTH_ORIF_EXPR
;
8461 c_parser_error (parser
,
8462 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
8463 "%<^%>, %<|%>, %<&&%>, or %<||%>");
8464 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
8467 c_parser_consume_token (parser
);
8468 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
8472 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
8473 OMP_CLAUSE_REDUCTION
, list
);
8474 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
8475 OMP_CLAUSE_REDUCTION_CODE (c
) = code
;
8479 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8485 schedule ( schedule-kind )
8486 schedule ( schedule-kind , expression )
8489 static | dynamic | guided | runtime | auto
8493 c_parser_omp_clause_schedule (c_parser
*parser
, tree list
)
8496 location_t loc
= c_parser_peek_token (parser
)->location
;
8498 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8501 c
= build_omp_clause (loc
, OMP_CLAUSE_SCHEDULE
);
8503 if (c_parser_next_token_is (parser
, CPP_NAME
))
8505 tree kind
= c_parser_peek_token (parser
)->value
;
8506 const char *p
= IDENTIFIER_POINTER (kind
);
8511 if (strcmp ("dynamic", p
) != 0)
8513 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_DYNAMIC
;
8517 if (strcmp ("guided", p
) != 0)
8519 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_GUIDED
;
8523 if (strcmp ("runtime", p
) != 0)
8525 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_RUNTIME
;
8532 else if (c_parser_next_token_is_keyword (parser
, RID_STATIC
))
8533 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_STATIC
;
8534 else if (c_parser_next_token_is_keyword (parser
, RID_AUTO
))
8535 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_AUTO
;
8539 c_parser_consume_token (parser
);
8540 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8543 c_parser_consume_token (parser
);
8545 here
= c_parser_peek_token (parser
)->location
;
8546 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
8547 t
= c_fully_fold (t
, false, NULL
);
8549 if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_RUNTIME
)
8550 error_at (here
, "schedule %<runtime%> does not take "
8551 "a %<chunk_size%> parameter");
8552 else if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_AUTO
)
8554 "schedule %<auto%> does not take "
8555 "a %<chunk_size%> parameter");
8556 else if (TREE_CODE (TREE_TYPE (t
)) == INTEGER_TYPE
)
8557 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
) = t
;
8559 c_parser_error (parser
, "expected integer expression");
8561 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8564 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
8565 "expected %<,%> or %<)%>");
8567 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
8568 OMP_CLAUSE_CHAIN (c
) = list
;
8572 c_parser_error (parser
, "invalid schedule kind");
8573 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
8578 shared ( variable-list ) */
8581 c_parser_omp_clause_shared (c_parser
*parser
, tree list
)
8583 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_SHARED
, list
);
8590 c_parser_omp_clause_untied (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
8594 /* FIXME: Should we allow duplicates? */
8595 check_no_duplicate_clause (list
, OMP_CLAUSE_UNTIED
, "untied");
8597 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
8599 OMP_CLAUSE_CHAIN (c
) = list
;
8604 /* Parse all OpenMP clauses. The set clauses allowed by the directive
8605 is a bitmask in MASK. Return the list of clauses found; the result
8606 of clause default goes in *pdefault. */
8609 c_parser_omp_all_clauses (c_parser
*parser
, unsigned int mask
,
8612 tree clauses
= NULL
;
8615 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
8618 pragma_omp_clause c_kind
;
8620 tree prev
= clauses
;
8622 if (!first
&& c_parser_next_token_is (parser
, CPP_COMMA
))
8623 c_parser_consume_token (parser
);
8626 here
= c_parser_peek_token (parser
)->location
;
8627 c_kind
= c_parser_omp_clause_name (parser
);
8631 case PRAGMA_OMP_CLAUSE_COLLAPSE
:
8632 clauses
= c_parser_omp_clause_collapse (parser
, clauses
);
8633 c_name
= "collapse";
8635 case PRAGMA_OMP_CLAUSE_COPYIN
:
8636 clauses
= c_parser_omp_clause_copyin (parser
, clauses
);
8639 case PRAGMA_OMP_CLAUSE_COPYPRIVATE
:
8640 clauses
= c_parser_omp_clause_copyprivate (parser
, clauses
);
8641 c_name
= "copyprivate";
8643 case PRAGMA_OMP_CLAUSE_DEFAULT
:
8644 clauses
= c_parser_omp_clause_default (parser
, clauses
);
8647 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
:
8648 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
8649 c_name
= "firstprivate";
8651 case PRAGMA_OMP_CLAUSE_IF
:
8652 clauses
= c_parser_omp_clause_if (parser
, clauses
);
8655 case PRAGMA_OMP_CLAUSE_LASTPRIVATE
:
8656 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
8657 c_name
= "lastprivate";
8659 case PRAGMA_OMP_CLAUSE_NOWAIT
:
8660 clauses
= c_parser_omp_clause_nowait (parser
, clauses
);
8663 case PRAGMA_OMP_CLAUSE_NUM_THREADS
:
8664 clauses
= c_parser_omp_clause_num_threads (parser
, clauses
);
8665 c_name
= "num_threads";
8667 case PRAGMA_OMP_CLAUSE_ORDERED
:
8668 clauses
= c_parser_omp_clause_ordered (parser
, clauses
);
8671 case PRAGMA_OMP_CLAUSE_PRIVATE
:
8672 clauses
= c_parser_omp_clause_private (parser
, clauses
);
8675 case PRAGMA_OMP_CLAUSE_REDUCTION
:
8676 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
8677 c_name
= "reduction";
8679 case PRAGMA_OMP_CLAUSE_SCHEDULE
:
8680 clauses
= c_parser_omp_clause_schedule (parser
, clauses
);
8681 c_name
= "schedule";
8683 case PRAGMA_OMP_CLAUSE_SHARED
:
8684 clauses
= c_parser_omp_clause_shared (parser
, clauses
);
8687 case PRAGMA_OMP_CLAUSE_UNTIED
:
8688 clauses
= c_parser_omp_clause_untied (parser
, clauses
);
8692 c_parser_error (parser
, "expected %<#pragma omp%> clause");
8696 if (((mask
>> c_kind
) & 1) == 0 && !parser
->error
)
8698 /* Remove the invalid clause(s) from the list to avoid
8699 confusing the rest of the compiler. */
8701 error_at (here
, "%qs is not valid for %qs", c_name
, where
);
8706 c_parser_skip_to_pragma_eol (parser
);
8708 return c_finish_omp_clauses (clauses
);
8715 In practice, we're also interested in adding the statement to an
8716 outer node. So it is convenient if we work around the fact that
8717 c_parser_statement calls add_stmt. */
8720 c_parser_omp_structured_block (c_parser
*parser
)
8722 tree stmt
= push_stmt_list ();
8723 c_parser_statement (parser
);
8724 return pop_stmt_list (stmt
);
8728 # pragma omp atomic new-line
8732 x binop= expr | x++ | ++x | x-- | --x
8734 +, *, -, /, &, ^, |, <<, >>
8736 where x is an lvalue expression with scalar type.
8738 LOC is the location of the #pragma token. */
8741 c_parser_omp_atomic (location_t loc
, c_parser
*parser
)
8745 enum tree_code code
;
8746 struct c_expr rhs_expr
;
8748 c_parser_skip_to_pragma_eol (parser
);
8750 lhs
= c_parser_unary_expression (parser
).value
;
8751 lhs
= c_fully_fold (lhs
, false, NULL
);
8752 switch (TREE_CODE (lhs
))
8756 c_parser_skip_to_end_of_block_or_statement (parser
);
8759 case PREINCREMENT_EXPR
:
8760 case POSTINCREMENT_EXPR
:
8761 lhs
= TREE_OPERAND (lhs
, 0);
8763 rhs
= integer_one_node
;
8766 case PREDECREMENT_EXPR
:
8767 case POSTDECREMENT_EXPR
:
8768 lhs
= TREE_OPERAND (lhs
, 0);
8770 rhs
= integer_one_node
;
8774 if (TREE_CODE (TREE_OPERAND (lhs
, 0)) == SAVE_EXPR
8775 && TREE_CODE (TREE_OPERAND (lhs
, 1)) == COMPOUND_EXPR
8776 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0)) == MODIFY_EXPR
8777 && TREE_OPERAND (TREE_OPERAND (lhs
, 1), 1) == TREE_OPERAND (lhs
, 0)
8778 && TREE_CODE (TREE_TYPE (TREE_OPERAND (TREE_OPERAND
8779 (TREE_OPERAND (lhs
, 1), 0), 0)))
8781 /* Undo effects of boolean_increment for post {in,de}crement. */
8782 lhs
= TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0);
8785 if (TREE_CODE (lhs
) == MODIFY_EXPR
8786 && TREE_CODE (TREE_TYPE (TREE_OPERAND (lhs
, 0))) == BOOLEAN_TYPE
)
8788 /* Undo effects of boolean_increment. */
8789 if (integer_onep (TREE_OPERAND (lhs
, 1)))
8791 /* This is pre or post increment. */
8792 rhs
= TREE_OPERAND (lhs
, 1);
8793 lhs
= TREE_OPERAND (lhs
, 0);
8797 if (TREE_CODE (TREE_OPERAND (lhs
, 1)) == TRUTH_NOT_EXPR
8798 && TREE_OPERAND (lhs
, 0)
8799 == TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0))
8801 /* This is pre or post decrement. */
8802 rhs
= TREE_OPERAND (lhs
, 1);
8803 lhs
= TREE_OPERAND (lhs
, 0);
8810 switch (c_parser_peek_token (parser
)->type
)
8816 code
= TRUNC_DIV_EXPR
;
8831 code
= BIT_AND_EXPR
;
8834 code
= BIT_IOR_EXPR
;
8837 code
= BIT_XOR_EXPR
;
8840 c_parser_error (parser
,
8841 "invalid operator for %<#pragma omp atomic%>");
8845 c_parser_consume_token (parser
);
8847 location_t rhs_loc
= c_parser_peek_token (parser
)->location
;
8848 rhs_expr
= c_parser_expression (parser
);
8849 rhs_expr
= default_function_array_read_conversion (rhs_loc
, rhs_expr
);
8851 rhs
= rhs_expr
.value
;
8852 rhs
= c_fully_fold (rhs
, false, NULL
);
8855 stmt
= c_finish_omp_atomic (loc
, code
, lhs
, rhs
);
8856 if (stmt
!= error_mark_node
)
8858 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8863 # pragma omp barrier new-line
8867 c_parser_omp_barrier (c_parser
*parser
)
8869 location_t loc
= c_parser_peek_token (parser
)->location
;
8870 c_parser_consume_pragma (parser
);
8871 c_parser_skip_to_pragma_eol (parser
);
8873 c_finish_omp_barrier (loc
);
8877 # pragma omp critical [(name)] new-line
8880 LOC is the location of the #pragma itself. */
8883 c_parser_omp_critical (location_t loc
, c_parser
*parser
)
8885 tree stmt
, name
= NULL
;
8887 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8889 c_parser_consume_token (parser
);
8890 if (c_parser_next_token_is (parser
, CPP_NAME
))
8892 name
= c_parser_peek_token (parser
)->value
;
8893 c_parser_consume_token (parser
);
8894 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8897 c_parser_error (parser
, "expected identifier");
8899 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
8900 c_parser_error (parser
, "expected %<(%> or end of line");
8901 c_parser_skip_to_pragma_eol (parser
);
8903 stmt
= c_parser_omp_structured_block (parser
);
8904 return c_finish_omp_critical (loc
, stmt
, name
);
8908 # pragma omp flush flush-vars[opt] new-line
8911 ( variable-list ) */
8914 c_parser_omp_flush (c_parser
*parser
)
8916 location_t loc
= c_parser_peek_token (parser
)->location
;
8917 c_parser_consume_pragma (parser
);
8918 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8919 c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
8920 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
8921 c_parser_error (parser
, "expected %<(%> or end of line");
8922 c_parser_skip_to_pragma_eol (parser
);
8924 c_finish_omp_flush (loc
);
8927 /* Parse the restricted form of the for statement allowed by OpenMP.
8928 The real trick here is to determine the loop control variable early
8929 so that we can push a new decl if necessary to make it private.
8930 LOC is the location of the OMP in "#pragma omp". */
8933 c_parser_omp_for_loop (location_t loc
,
8934 c_parser
*parser
, tree clauses
, tree
*par_clauses
)
8936 tree decl
, cond
, incr
, save_break
, save_cont
, body
, init
, stmt
, cl
;
8937 tree declv
, condv
, incrv
, initv
, ret
= NULL
;
8938 bool fail
= false, open_brace_parsed
= false;
8939 int i
, collapse
= 1, nbraces
= 0;
8941 VEC(tree
,gc
) *for_block
= make_tree_vector ();
8943 for (cl
= clauses
; cl
; cl
= OMP_CLAUSE_CHAIN (cl
))
8944 if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_COLLAPSE
)
8945 collapse
= tree_low_cst (OMP_CLAUSE_COLLAPSE_EXPR (cl
), 0);
8947 gcc_assert (collapse
>= 1);
8949 declv
= make_tree_vec (collapse
);
8950 initv
= make_tree_vec (collapse
);
8951 condv
= make_tree_vec (collapse
);
8952 incrv
= make_tree_vec (collapse
);
8954 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
))
8956 c_parser_error (parser
, "for statement expected");
8959 for_loc
= c_parser_peek_token (parser
)->location
;
8960 c_parser_consume_token (parser
);
8962 for (i
= 0; i
< collapse
; i
++)
8966 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8969 /* Parse the initialization declaration or expression. */
8970 if (c_parser_next_token_starts_declaration (parser
))
8973 VEC_safe_push (tree
, gc
, for_block
, c_begin_compound_stmt (true));
8974 c_parser_declaration_or_fndef (parser
, true, true, true, true, true, NULL
);
8975 decl
= check_for_loop_decls (for_loc
, flag_isoc99
);
8978 if (DECL_INITIAL (decl
) == error_mark_node
)
8979 decl
= error_mark_node
;
8982 else if (c_parser_next_token_is (parser
, CPP_NAME
)
8983 && c_parser_peek_2nd_token (parser
)->type
== CPP_EQ
)
8985 struct c_expr decl_exp
;
8986 struct c_expr init_exp
;
8987 location_t init_loc
;
8989 decl_exp
= c_parser_postfix_expression (parser
);
8990 decl
= decl_exp
.value
;
8992 c_parser_require (parser
, CPP_EQ
, "expected %<=%>");
8994 init_loc
= c_parser_peek_token (parser
)->location
;
8995 init_exp
= c_parser_expr_no_commas (parser
, NULL
);
8996 init_exp
= default_function_array_read_conversion (init_loc
,
8998 init
= build_modify_expr (init_loc
, decl
, decl_exp
.original_type
,
8999 NOP_EXPR
, init_loc
, init_exp
.value
,
9000 init_exp
.original_type
);
9001 init
= c_process_expr_stmt (init_loc
, init
);
9003 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9008 c_parser_error (parser
,
9009 "expected iteration declaration or initialization");
9010 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
9016 /* Parse the loop condition. */
9018 if (c_parser_next_token_is_not (parser
, CPP_SEMICOLON
))
9020 location_t cond_loc
= c_parser_peek_token (parser
)->location
;
9021 struct c_expr cond_expr
= c_parser_binary_expression (parser
, NULL
);
9023 cond
= cond_expr
.value
;
9024 cond
= c_objc_common_truthvalue_conversion (cond_loc
, cond
);
9025 cond
= c_fully_fold (cond
, false, NULL
);
9026 switch (cond_expr
.original_code
)
9034 /* Can't be cond = error_mark_node, because we want to preserve
9035 the location until c_finish_omp_for. */
9036 cond
= build1 (NOP_EXPR
, boolean_type_node
, error_mark_node
);
9039 protected_set_expr_location (cond
, cond_loc
);
9041 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9043 /* Parse the increment expression. */
9045 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_PAREN
))
9047 location_t incr_loc
= c_parser_peek_token (parser
)->location
;
9049 incr
= c_process_expr_stmt (incr_loc
,
9050 c_parser_expression (parser
).value
);
9052 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9054 if (decl
== NULL
|| decl
== error_mark_node
|| init
== error_mark_node
)
9058 TREE_VEC_ELT (declv
, i
) = decl
;
9059 TREE_VEC_ELT (initv
, i
) = init
;
9060 TREE_VEC_ELT (condv
, i
) = cond
;
9061 TREE_VEC_ELT (incrv
, i
) = incr
;
9065 if (i
== collapse
- 1)
9068 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
9069 in between the collapsed for loops to be still considered perfectly
9070 nested. Hopefully the final version clarifies this.
9071 For now handle (multiple) {'s and empty statements. */
9074 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
9076 c_parser_consume_token (parser
);
9079 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
9081 c_parser_consume_token (parser
);
9085 && c_parser_next_token_is (parser
, CPP_SEMICOLON
))
9086 c_parser_consume_token (parser
);
9089 c_parser_error (parser
, "not enough perfectly nested loops");
9092 open_brace_parsed
= true;
9102 nbraces
+= bracecount
;
9105 save_break
= c_break_label
;
9106 c_break_label
= size_one_node
;
9107 save_cont
= c_cont_label
;
9108 c_cont_label
= NULL_TREE
;
9109 body
= push_stmt_list ();
9111 if (open_brace_parsed
)
9113 location_t here
= c_parser_peek_token (parser
)->location
;
9114 stmt
= c_begin_compound_stmt (true);
9115 c_parser_compound_statement_nostart (parser
);
9116 add_stmt (c_end_compound_stmt (here
, stmt
, true));
9119 add_stmt (c_parser_c99_block_statement (parser
));
9122 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_cont_label
);
9123 SET_EXPR_LOCATION (t
, loc
);
9127 body
= pop_stmt_list (body
);
9128 c_break_label
= save_break
;
9129 c_cont_label
= save_cont
;
9133 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
9135 c_parser_consume_token (parser
);
9138 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
9139 c_parser_consume_token (parser
);
9142 c_parser_error (parser
, "collapsed loops not perfectly nested");
9145 location_t here
= c_parser_peek_token (parser
)->location
;
9146 stmt
= c_begin_compound_stmt (true);
9148 c_parser_compound_statement_nostart (parser
);
9149 body
= c_end_compound_stmt (here
, stmt
, true);
9156 /* Only bother calling c_finish_omp_for if we haven't already generated
9157 an error from the initialization parsing. */
9160 stmt
= c_finish_omp_for (loc
, declv
, initv
, condv
, incrv
, body
, NULL
);
9163 if (par_clauses
!= NULL
)
9166 for (c
= par_clauses
; *c
; )
9167 if (OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_FIRSTPRIVATE
9168 && OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_LASTPRIVATE
)
9169 c
= &OMP_CLAUSE_CHAIN (*c
);
9172 for (i
= 0; i
< collapse
; i
++)
9173 if (TREE_VEC_ELT (declv
, i
) == OMP_CLAUSE_DECL (*c
))
9176 c
= &OMP_CLAUSE_CHAIN (*c
);
9177 else if (OMP_CLAUSE_CODE (*c
) == OMP_CLAUSE_FIRSTPRIVATE
)
9180 "iteration variable %qD should not be firstprivate",
9181 OMP_CLAUSE_DECL (*c
));
9182 *c
= OMP_CLAUSE_CHAIN (*c
);
9186 /* Copy lastprivate (decl) clause to OMP_FOR_CLAUSES,
9187 change it to shared (decl) in
9188 OMP_PARALLEL_CLAUSES. */
9189 tree l
= build_omp_clause (OMP_CLAUSE_LOCATION (*c
),
9190 OMP_CLAUSE_LASTPRIVATE
);
9191 OMP_CLAUSE_DECL (l
) = OMP_CLAUSE_DECL (*c
);
9192 OMP_CLAUSE_CHAIN (l
) = clauses
;
9194 OMP_CLAUSE_SET_CODE (*c
, OMP_CLAUSE_SHARED
);
9198 OMP_FOR_CLAUSES (stmt
) = clauses
;
9203 while (!VEC_empty (tree
, for_block
))
9205 /* FIXME diagnostics: LOC below should be the actual location of
9206 this particular for block. We need to build a list of
9207 locations to go along with FOR_BLOCK. */
9208 stmt
= c_end_compound_stmt (loc
, VEC_pop (tree
, for_block
), true);
9211 release_tree_vector (for_block
);
9216 #pragma omp for for-clause[optseq] new-line
9219 LOC is the location of the #pragma token.
9222 #define OMP_FOR_CLAUSE_MASK \
9223 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
9224 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
9225 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
9226 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
9227 | (1u << PRAGMA_OMP_CLAUSE_ORDERED) \
9228 | (1u << PRAGMA_OMP_CLAUSE_SCHEDULE) \
9229 | (1u << PRAGMA_OMP_CLAUSE_COLLAPSE) \
9230 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
9233 c_parser_omp_for (location_t loc
, c_parser
*parser
)
9235 tree block
, clauses
, ret
;
9237 clauses
= c_parser_omp_all_clauses (parser
, OMP_FOR_CLAUSE_MASK
,
9240 block
= c_begin_compound_stmt (true);
9241 ret
= c_parser_omp_for_loop (loc
, parser
, clauses
, NULL
);
9242 block
= c_end_compound_stmt (loc
, block
, true);
9249 # pragma omp master new-line
9252 LOC is the location of the #pragma token.
9256 c_parser_omp_master (location_t loc
, c_parser
*parser
)
9258 c_parser_skip_to_pragma_eol (parser
);
9259 return c_finish_omp_master (loc
, c_parser_omp_structured_block (parser
));
9263 # pragma omp ordered new-line
9266 LOC is the location of the #pragma itself.
9270 c_parser_omp_ordered (location_t loc
, c_parser
*parser
)
9272 c_parser_skip_to_pragma_eol (parser
);
9273 return c_finish_omp_ordered (loc
, c_parser_omp_structured_block (parser
));
9279 { section-sequence }
9282 section-directive[opt] structured-block
9283 section-sequence section-directive structured-block
9285 SECTIONS_LOC is the location of the #pragma omp sections. */
9288 c_parser_omp_sections_scope (location_t sections_loc
, c_parser
*parser
)
9291 bool error_suppress
= false;
9294 loc
= c_parser_peek_token (parser
)->location
;
9295 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
9297 /* Avoid skipping until the end of the block. */
9298 parser
->error
= false;
9302 stmt
= push_stmt_list ();
9304 if (c_parser_peek_token (parser
)->pragma_kind
!= PRAGMA_OMP_SECTION
)
9306 substmt
= push_stmt_list ();
9310 c_parser_statement (parser
);
9312 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
9314 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
9316 if (c_parser_next_token_is (parser
, CPP_EOF
))
9320 substmt
= pop_stmt_list (substmt
);
9321 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
9322 SET_EXPR_LOCATION (substmt
, loc
);
9328 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
9330 if (c_parser_next_token_is (parser
, CPP_EOF
))
9333 loc
= c_parser_peek_token (parser
)->location
;
9334 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
9336 c_parser_consume_pragma (parser
);
9337 c_parser_skip_to_pragma_eol (parser
);
9338 error_suppress
= false;
9340 else if (!error_suppress
)
9342 error_at (loc
, "expected %<#pragma omp section%> or %<}%>");
9343 error_suppress
= true;
9346 substmt
= c_parser_omp_structured_block (parser
);
9347 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
9348 SET_EXPR_LOCATION (substmt
, loc
);
9351 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
,
9352 "expected %<#pragma omp section%> or %<}%>");
9354 substmt
= pop_stmt_list (stmt
);
9356 stmt
= make_node (OMP_SECTIONS
);
9357 SET_EXPR_LOCATION (stmt
, sections_loc
);
9358 TREE_TYPE (stmt
) = void_type_node
;
9359 OMP_SECTIONS_BODY (stmt
) = substmt
;
9361 return add_stmt (stmt
);
9365 # pragma omp sections sections-clause[optseq] newline
9368 LOC is the location of the #pragma token.
9371 #define OMP_SECTIONS_CLAUSE_MASK \
9372 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
9373 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
9374 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
9375 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
9376 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
9379 c_parser_omp_sections (location_t loc
, c_parser
*parser
)
9381 tree block
, clauses
, ret
;
9383 clauses
= c_parser_omp_all_clauses (parser
, OMP_SECTIONS_CLAUSE_MASK
,
9384 "#pragma omp sections");
9386 block
= c_begin_compound_stmt (true);
9387 ret
= c_parser_omp_sections_scope (loc
, parser
);
9389 OMP_SECTIONS_CLAUSES (ret
) = clauses
;
9390 block
= c_end_compound_stmt (loc
, block
, true);
9397 # pragma parallel parallel-clause new-line
9398 # pragma parallel for parallel-for-clause new-line
9399 # pragma parallel sections parallel-sections-clause new-line
9401 LOC is the location of the #pragma token.
9404 #define OMP_PARALLEL_CLAUSE_MASK \
9405 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
9406 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
9407 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
9408 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
9409 | (1u << PRAGMA_OMP_CLAUSE_SHARED) \
9410 | (1u << PRAGMA_OMP_CLAUSE_COPYIN) \
9411 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
9412 | (1u << PRAGMA_OMP_CLAUSE_NUM_THREADS))
9415 c_parser_omp_parallel (location_t loc
, c_parser
*parser
)
9417 enum pragma_kind p_kind
= PRAGMA_OMP_PARALLEL
;
9418 const char *p_name
= "#pragma omp parallel";
9419 tree stmt
, clauses
, par_clause
, ws_clause
, block
;
9420 unsigned int mask
= OMP_PARALLEL_CLAUSE_MASK
;
9422 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
9424 c_parser_consume_token (parser
);
9425 p_kind
= PRAGMA_OMP_PARALLEL_FOR
;
9426 p_name
= "#pragma omp parallel for";
9427 mask
|= OMP_FOR_CLAUSE_MASK
;
9428 mask
&= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT
);
9430 else if (c_parser_next_token_is (parser
, CPP_NAME
))
9432 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
9433 if (strcmp (p
, "sections") == 0)
9435 c_parser_consume_token (parser
);
9436 p_kind
= PRAGMA_OMP_PARALLEL_SECTIONS
;
9437 p_name
= "#pragma omp parallel sections";
9438 mask
|= OMP_SECTIONS_CLAUSE_MASK
;
9439 mask
&= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT
);
9443 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
);
9447 case PRAGMA_OMP_PARALLEL
:
9448 block
= c_begin_omp_parallel ();
9449 c_parser_statement (parser
);
9450 stmt
= c_finish_omp_parallel (loc
, clauses
, block
);
9453 case PRAGMA_OMP_PARALLEL_FOR
:
9454 block
= c_begin_omp_parallel ();
9455 c_split_parallel_clauses (loc
, clauses
, &par_clause
, &ws_clause
);
9456 c_parser_omp_for_loop (loc
, parser
, ws_clause
, &par_clause
);
9457 stmt
= c_finish_omp_parallel (loc
, par_clause
, block
);
9458 OMP_PARALLEL_COMBINED (stmt
) = 1;
9461 case PRAGMA_OMP_PARALLEL_SECTIONS
:
9462 block
= c_begin_omp_parallel ();
9463 c_split_parallel_clauses (loc
, clauses
, &par_clause
, &ws_clause
);
9464 stmt
= c_parser_omp_sections_scope (loc
, parser
);
9466 OMP_SECTIONS_CLAUSES (stmt
) = ws_clause
;
9467 stmt
= c_finish_omp_parallel (loc
, par_clause
, block
);
9468 OMP_PARALLEL_COMBINED (stmt
) = 1;
9479 # pragma omp single single-clause[optseq] new-line
9482 LOC is the location of the #pragma.
9485 #define OMP_SINGLE_CLAUSE_MASK \
9486 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
9487 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
9488 | (1u << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
9489 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
9492 c_parser_omp_single (location_t loc
, c_parser
*parser
)
9494 tree stmt
= make_node (OMP_SINGLE
);
9495 SET_EXPR_LOCATION (stmt
, loc
);
9496 TREE_TYPE (stmt
) = void_type_node
;
9498 OMP_SINGLE_CLAUSES (stmt
)
9499 = c_parser_omp_all_clauses (parser
, OMP_SINGLE_CLAUSE_MASK
,
9500 "#pragma omp single");
9501 OMP_SINGLE_BODY (stmt
) = c_parser_omp_structured_block (parser
);
9503 return add_stmt (stmt
);
9507 # pragma omp task task-clause[optseq] new-line
9509 LOC is the location of the #pragma.
9512 #define OMP_TASK_CLAUSE_MASK \
9513 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
9514 | (1u << PRAGMA_OMP_CLAUSE_UNTIED) \
9515 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
9516 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
9517 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
9518 | (1u << PRAGMA_OMP_CLAUSE_SHARED))
9521 c_parser_omp_task (location_t loc
, c_parser
*parser
)
9523 tree clauses
, block
;
9525 clauses
= c_parser_omp_all_clauses (parser
, OMP_TASK_CLAUSE_MASK
,
9526 "#pragma omp task");
9528 block
= c_begin_omp_task ();
9529 c_parser_statement (parser
);
9530 return c_finish_omp_task (loc
, clauses
, block
);
9534 # pragma omp taskwait new-line
9538 c_parser_omp_taskwait (c_parser
*parser
)
9540 location_t loc
= c_parser_peek_token (parser
)->location
;
9541 c_parser_consume_pragma (parser
);
9542 c_parser_skip_to_pragma_eol (parser
);
9544 c_finish_omp_taskwait (loc
);
9547 /* Main entry point to parsing most OpenMP pragmas. */
9550 c_parser_omp_construct (c_parser
*parser
)
9552 enum pragma_kind p_kind
;
9556 loc
= c_parser_peek_token (parser
)->location
;
9557 p_kind
= c_parser_peek_token (parser
)->pragma_kind
;
9558 c_parser_consume_pragma (parser
);
9562 case PRAGMA_OMP_ATOMIC
:
9563 c_parser_omp_atomic (loc
, parser
);
9565 case PRAGMA_OMP_CRITICAL
:
9566 stmt
= c_parser_omp_critical (loc
, parser
);
9568 case PRAGMA_OMP_FOR
:
9569 stmt
= c_parser_omp_for (loc
, parser
);
9571 case PRAGMA_OMP_MASTER
:
9572 stmt
= c_parser_omp_master (loc
, parser
);
9574 case PRAGMA_OMP_ORDERED
:
9575 stmt
= c_parser_omp_ordered (loc
, parser
);
9577 case PRAGMA_OMP_PARALLEL
:
9578 stmt
= c_parser_omp_parallel (loc
, parser
);
9580 case PRAGMA_OMP_SECTIONS
:
9581 stmt
= c_parser_omp_sections (loc
, parser
);
9583 case PRAGMA_OMP_SINGLE
:
9584 stmt
= c_parser_omp_single (loc
, parser
);
9586 case PRAGMA_OMP_TASK
:
9587 stmt
= c_parser_omp_task (loc
, parser
);
9594 gcc_assert (EXPR_LOCATION (stmt
) != UNKNOWN_LOCATION
);
9599 # pragma omp threadprivate (variable-list) */
9602 c_parser_omp_threadprivate (c_parser
*parser
)
9607 c_parser_consume_pragma (parser
);
9608 loc
= c_parser_peek_token (parser
)->location
;
9609 vars
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
9611 /* Mark every variable in VARS to be assigned thread local storage. */
9612 for (t
= vars
; t
; t
= TREE_CHAIN (t
))
9614 tree v
= TREE_PURPOSE (t
);
9616 /* FIXME diagnostics: Ideally we should keep individual
9617 locations for all the variables in the var list to make the
9618 following errors more precise. Perhaps
9619 c_parser_omp_var_list_parens() should construct a list of
9620 locations to go along with the var list. */
9622 /* If V had already been marked threadprivate, it doesn't matter
9623 whether it had been used prior to this point. */
9624 if (TREE_CODE (v
) != VAR_DECL
)
9625 error_at (loc
, "%qD is not a variable", v
);
9626 else if (TREE_USED (v
) && !C_DECL_THREADPRIVATE_P (v
))
9627 error_at (loc
, "%qE declared %<threadprivate%> after first use", v
);
9628 else if (! TREE_STATIC (v
) && ! DECL_EXTERNAL (v
))
9629 error_at (loc
, "automatic variable %qE cannot be %<threadprivate%>", v
);
9630 else if (TREE_TYPE (v
) == error_mark_node
)
9632 else if (! COMPLETE_TYPE_P (TREE_TYPE (v
)))
9633 error_at (loc
, "%<threadprivate%> %qE has incomplete type", v
);
9636 if (! DECL_THREAD_LOCAL_P (v
))
9638 DECL_TLS_MODEL (v
) = decl_default_tls_model (v
);
9639 /* If rtl has been already set for this var, call
9640 make_decl_rtl once again, so that encode_section_info
9641 has a chance to look at the new decl flags. */
9642 if (DECL_RTL_SET_P (v
))
9645 C_DECL_THREADPRIVATE_P (v
) = 1;
9649 c_parser_skip_to_pragma_eol (parser
);
9653 /* Parse a single source file. */
9658 /* Use local storage to begin. If the first token is a pragma, parse it.
9659 If it is #pragma GCC pch_preprocess, then this will load a PCH file
9660 which will cause garbage collection. */
9663 memset (&tparser
, 0, sizeof tparser
);
9664 the_parser
= &tparser
;
9666 if (c_parser_peek_token (&tparser
)->pragma_kind
== PRAGMA_GCC_PCH_PREPROCESS
)
9667 c_parser_pragma_pch_preprocess (&tparser
);
9669 the_parser
= ggc_alloc_c_parser ();
9670 *the_parser
= tparser
;
9672 /* Initialize EH, if we've been told to do so. */
9673 if (flag_exceptions
)
9674 using_eh_for_cleanups ();
9676 c_parser_translation_unit (the_parser
);
9680 #include "gt-c-parser.h"