1 /* Parser for C and Objective-C.
2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010, 2011,
4 2012 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"
53 #include "c-family/c-common.h"
54 #include "c-family/c-objc.h"
55 #include "c-family/c-upc.h"
61 #include "upc/upc-tree.h"
64 /* Initialization routine for this file. */
69 /* The only initialization required is of the reserved word
75 /* Make sure RID_MAX hasn't grown past the 8 bits used to hold the keyword in
76 the c_token structure. */
77 gcc_assert (RID_MAX
<= 255);
84 mask
|= D_ASM
| D_EXT
;
88 if (!c_dialect_objc ())
89 mask
|= D_OBJC
| D_CXX_OBJC
;
91 if (!c_dialect_upc ())
94 ridpointers
= ggc_alloc_cleared_vec_tree ((int) RID_MAX
);
95 for (i
= 0; i
< num_c_common_reswords
; i
++)
97 /* If a keyword is disabled, do not enter it into the table
98 and so create a canonical spelling that isn't a keyword. */
99 if (c_common_reswords
[i
].disable
& mask
)
102 && (c_common_reswords
[i
].disable
& D_CXXWARN
))
104 id
= get_identifier (c_common_reswords
[i
].word
);
105 C_SET_RID_CODE (id
, RID_CXX_COMPAT_WARN
);
106 C_IS_RESERVED_WORD (id
) = 1;
111 id
= get_identifier (c_common_reswords
[i
].word
);
112 C_SET_RID_CODE (id
, c_common_reswords
[i
].rid
);
113 C_IS_RESERVED_WORD (id
) = 1;
114 ridpointers
[(int) c_common_reswords
[i
].rid
] = id
;
118 /* The C lexer intermediates between the lexer in cpplib and c-lex.c
119 and the C parser. Unlike the C++ lexer, the parser structure
120 stores the lexer information instead of using a separate structure.
121 Identifiers are separated into ordinary identifiers, type names,
122 keywords and some other Objective-C types of identifiers, and some
123 look-ahead is maintained.
125 ??? It might be a good idea to lex the whole file up front (as for
126 C++). It would then be possible to share more of the C and C++
127 lexer code, if desired. */
129 /* The following local token type is used. */
132 #define CPP_KEYWORD ((enum cpp_ttype) (N_TTYPES + 1))
134 /* More information about the type of a CPP_NAME token. */
135 typedef enum c_id_kind
{
136 /* An ordinary identifier. */
138 /* An identifier declared as a typedef name. */
140 /* An identifier declared as an Objective-C class name. */
142 /* An address space identifier. */
144 /* Not an identifier. */
148 /* A single C token after string literal concatenation and conversion
149 of preprocessing tokens to tokens. */
150 typedef struct GTY (()) c_token
{
151 /* The kind of token. */
152 ENUM_BITFIELD (cpp_ttype
) type
: 8;
153 /* If this token is a CPP_NAME, this value indicates whether also
154 declared as some kind of type. Otherwise, it is C_ID_NONE. */
155 ENUM_BITFIELD (c_id_kind
) id_kind
: 8;
156 /* If this token is a keyword, this value indicates which keyword.
157 Otherwise, this value is RID_MAX. */
158 ENUM_BITFIELD (rid
) keyword
: 8;
159 /* If this token is a CPP_PRAGMA, this indicates the pragma that
160 was seen. Otherwise it is PRAGMA_NONE. */
161 ENUM_BITFIELD (pragma_kind
) pragma_kind
: 8;
162 /* The location at which this token was found. */
164 /* The value associated with this token, if any. */
168 /* A parser structure recording information about the state and
169 context of parsing. Includes lexer information with up to two
170 tokens of look-ahead; more are not needed for C. */
171 typedef struct GTY(()) c_parser
{
172 /* The look-ahead tokens. */
174 /* How many look-ahead tokens are available (0, 1 or 2). */
176 /* True if a syntax error is being recovered from; false otherwise.
177 c_parser_error sets this flag. It should clear this flag when
178 enough tokens have been consumed to recover from the error. */
179 BOOL_BITFIELD error
: 1;
180 /* True if we're processing a pragma, and shouldn't automatically
181 consume CPP_PRAGMA_EOL. */
182 BOOL_BITFIELD in_pragma
: 1;
183 /* True if we're parsing the outermost block of an if statement. */
184 BOOL_BITFIELD in_if_block
: 1;
185 /* True if we want to lex an untranslated string. */
186 BOOL_BITFIELD lex_untranslated_string
: 1;
188 /* Objective-C specific parser/lexer information. */
190 /* True if we are in a context where the Objective-C "PQ" keywords
191 are considered keywords. */
192 BOOL_BITFIELD objc_pq_context
: 1;
193 /* True if we are parsing a (potential) Objective-C foreach
194 statement. This is set to true after we parsed 'for (' and while
195 we wait for 'in' or ';' to decide if it's a standard C for loop or an
196 Objective-C foreach loop. */
197 BOOL_BITFIELD objc_could_be_foreach_context
: 1;
198 /* The following flag is needed to contextualize Objective-C lexical
199 analysis. In some cases (e.g., 'int NSObject;'), it is
200 undesirable to bind an identifier to an Objective-C class, even
201 if a class with that name exists. */
202 BOOL_BITFIELD objc_need_raw_identifier
: 1;
203 /* Nonzero if we're processing a __transaction statement. The value
204 is 1 | TM_STMT_ATTR_*. */
205 unsigned int in_transaction
: 4;
206 /* True if we are in a context where the Objective-C "Property attribute"
207 keywords are valid. */
208 BOOL_BITFIELD objc_property_attr_context
: 1;
212 /* The actual parser and external interface. ??? Does this need to be
213 garbage-collected? */
215 static GTY (()) c_parser
*the_parser
;
217 /* Read in and lex a single token, storing it in *TOKEN. */
220 c_lex_one_token (c_parser
*parser
, c_token
*token
)
222 timevar_push (TV_LEX
);
224 token
->type
= c_lex_with_flags (&token
->value
, &token
->location
, NULL
,
225 (parser
->lex_untranslated_string
226 ? C_LEX_STRING_NO_TRANSLATE
: 0));
227 token
->id_kind
= C_ID_NONE
;
228 token
->keyword
= RID_MAX
;
229 token
->pragma_kind
= PRAGMA_NONE
;
237 bool objc_force_identifier
= parser
->objc_need_raw_identifier
;
238 if (c_dialect_objc ())
239 parser
->objc_need_raw_identifier
= false;
241 if (C_IS_RESERVED_WORD (token
->value
))
243 enum rid rid_code
= C_RID_CODE (token
->value
);
245 if (rid_code
== RID_CXX_COMPAT_WARN
)
247 warning_at (token
->location
,
249 "identifier %qE conflicts with C++ keyword",
252 else if (rid_code
>= RID_FIRST_ADDR_SPACE
253 && rid_code
<= RID_LAST_ADDR_SPACE
)
255 token
->id_kind
= C_ID_ADDRSPACE
;
256 token
->keyword
= rid_code
;
259 else if (c_dialect_objc () && OBJC_IS_PQ_KEYWORD (rid_code
))
261 /* We found an Objective-C "pq" keyword (in, out,
262 inout, bycopy, byref, oneway). They need special
263 care because the interpretation depends on the
265 if (parser
->objc_pq_context
)
267 token
->type
= CPP_KEYWORD
;
268 token
->keyword
= rid_code
;
271 else if (parser
->objc_could_be_foreach_context
272 && rid_code
== RID_IN
)
274 /* We are in Objective-C, inside a (potential)
275 foreach context (which means after having
276 parsed 'for (', but before having parsed ';'),
277 and we found 'in'. We consider it the keyword
278 which terminates the declaration at the
279 beginning of a foreach-statement. Note that
280 this means you can't use 'in' for anything else
281 in that context; in particular, in Objective-C
282 you can't use 'in' as the name of the running
283 variable in a C for loop. We could potentially
284 try to add code here to disambiguate, but it
285 seems a reasonable limitation. */
286 token
->type
= CPP_KEYWORD
;
287 token
->keyword
= rid_code
;
290 /* Else, "pq" keywords outside of the "pq" context are
291 not keywords, and we fall through to the code for
294 else if (c_dialect_objc () && OBJC_IS_PATTR_KEYWORD (rid_code
))
296 /* We found an Objective-C "property attribute"
297 keyword (getter, setter, readonly, etc). These are
298 only valid in the property context. */
299 if (parser
->objc_property_attr_context
)
301 token
->type
= CPP_KEYWORD
;
302 token
->keyword
= rid_code
;
305 /* Else they are not special keywords.
308 else if (c_dialect_objc ()
309 && (OBJC_IS_AT_KEYWORD (rid_code
)
310 || OBJC_IS_CXX_KEYWORD (rid_code
)))
312 /* We found one of the Objective-C "@" keywords (defs,
313 selector, synchronized, etc) or one of the
314 Objective-C "cxx" keywords (class, private,
315 protected, public, try, catch, throw) without a
316 preceding '@' sign. Do nothing and fall through to
317 the code for normal tokens (in C++ we would still
318 consider the CXX ones keywords, but not in C). */
323 token
->type
= CPP_KEYWORD
;
324 token
->keyword
= rid_code
;
329 decl
= lookup_name (token
->value
);
332 if (TREE_CODE (decl
) == TYPE_DECL
)
334 token
->id_kind
= C_ID_TYPENAME
;
338 else if (c_dialect_objc ())
340 tree objc_interface_decl
= objc_is_class_name (token
->value
);
341 /* Objective-C class names are in the same namespace as
342 variables and typedefs, and hence are shadowed by local
344 if (objc_interface_decl
345 && (!objc_force_identifier
|| global_bindings_p ()))
347 token
->value
= objc_interface_decl
;
348 token
->id_kind
= C_ID_CLASSNAME
;
352 token
->id_kind
= C_ID_ID
;
356 /* This only happens in Objective-C; it must be a keyword. */
357 token
->type
= CPP_KEYWORD
;
358 switch (C_RID_CODE (token
->value
))
360 /* Replace 'class' with '@class', 'private' with '@private',
361 etc. This prevents confusion with the C++ keyword
362 'class', and makes the tokens consistent with other
363 Objective-C 'AT' keywords. For example '@class' is
364 reported as RID_AT_CLASS which is consistent with
365 '@synchronized', which is reported as
368 case RID_CLASS
: token
->keyword
= RID_AT_CLASS
; break;
369 case RID_PRIVATE
: token
->keyword
= RID_AT_PRIVATE
; break;
370 case RID_PROTECTED
: token
->keyword
= RID_AT_PROTECTED
; break;
371 case RID_PUBLIC
: token
->keyword
= RID_AT_PUBLIC
; break;
372 case RID_THROW
: token
->keyword
= RID_AT_THROW
; break;
373 case RID_TRY
: token
->keyword
= RID_AT_TRY
; break;
374 case RID_CATCH
: token
->keyword
= RID_AT_CATCH
; break;
375 default: token
->keyword
= C_RID_CODE (token
->value
);
380 case CPP_CLOSE_PAREN
:
382 /* These tokens may affect the interpretation of any identifiers
383 following, if doing Objective-C. */
384 if (c_dialect_objc ())
385 parser
->objc_need_raw_identifier
= false;
388 /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */
389 token
->pragma_kind
= (enum pragma_kind
) TREE_INT_CST_LOW (token
->value
);
395 timevar_pop (TV_LEX
);
398 /* Return a pointer to the next token from PARSER, reading it in if
401 static inline c_token
*
402 c_parser_peek_token (c_parser
*parser
)
404 if (parser
->tokens_avail
== 0)
406 c_lex_one_token (parser
, &parser
->tokens
[0]);
407 parser
->tokens_avail
= 1;
409 return &parser
->tokens
[0];
412 /* Return true if the next token from PARSER has the indicated
416 c_parser_next_token_is (c_parser
*parser
, enum cpp_ttype type
)
418 return c_parser_peek_token (parser
)->type
== type
;
421 /* Return true if the next token from PARSER does not have the
425 c_parser_next_token_is_not (c_parser
*parser
, enum cpp_ttype type
)
427 return !c_parser_next_token_is (parser
, type
);
430 /* Return true if the next token from PARSER is the indicated
434 c_parser_next_token_is_keyword (c_parser
*parser
, enum rid keyword
)
436 return c_parser_peek_token (parser
)->keyword
== keyword
;
439 /* Return a pointer to the next-but-one token from PARSER, reading it
440 in if necessary. The next token is already read in. */
443 c_parser_peek_2nd_token (c_parser
*parser
)
445 if (parser
->tokens_avail
>= 2)
446 return &parser
->tokens
[1];
447 gcc_assert (parser
->tokens_avail
== 1);
448 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
449 gcc_assert (parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
450 c_lex_one_token (parser
, &parser
->tokens
[1]);
451 parser
->tokens_avail
= 2;
452 return &parser
->tokens
[1];
455 /* Return true if TOKEN can start a type name,
458 c_token_starts_typename (c_token
*token
)
463 switch (token
->id_kind
)
472 gcc_assert (c_dialect_objc ());
478 switch (token
->keyword
)
516 if (c_dialect_objc ())
524 enum c_lookahead_kind
{
525 /* Always treat unknown identifiers as typenames. */
528 /* Could be parsing a nonabstract declarator. Only treat an identifier
529 as a typename if followed by another identifier or a star. */
530 cla_nonabstract_decl
,
532 /* Never treat identifiers as typenames. */
536 /* Return true if the next token from PARSER can start a type name,
537 false otherwise. LA specifies how to do lookahead in order to
538 detect unknown type names. If unsure, pick CLA_PREFER_ID. */
541 c_parser_next_tokens_start_typename (c_parser
*parser
, enum c_lookahead_kind la
)
543 c_token
*token
= c_parser_peek_token (parser
);
544 if (c_token_starts_typename (token
))
547 /* Try a bit harder to detect an unknown typename. */
548 if (la
!= cla_prefer_id
549 && token
->type
== CPP_NAME
550 && token
->id_kind
== C_ID_ID
552 /* Do not try too hard when we could have "object in array". */
553 && !parser
->objc_could_be_foreach_context
555 && (la
== cla_prefer_type
556 || c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
557 || c_parser_peek_2nd_token (parser
)->type
== CPP_MULT
)
559 /* Only unknown identifiers. */
560 && !lookup_name (token
->value
))
566 /* Return true if TOKEN is a type qualifier, false otherwise. */
568 c_token_is_qualifier (c_token
*token
)
573 switch (token
->id_kind
)
581 switch (token
->keyword
)
603 /* Return true if the next token from PARSER is a type qualifier,
606 c_parser_next_token_is_qualifier (c_parser
*parser
)
608 c_token
*token
= c_parser_peek_token (parser
);
609 return c_token_is_qualifier (token
);
612 /* Return true if TOKEN can start declaration specifiers, false
615 c_token_starts_declspecs (c_token
*token
)
620 switch (token
->id_kind
)
629 gcc_assert (c_dialect_objc ());
635 switch (token
->keyword
)
682 if (c_dialect_objc ())
691 /* Return true if TOKEN can start declaration specifiers or a static
692 assertion, false otherwise. */
694 c_token_starts_declaration (c_token
*token
)
696 if (c_token_starts_declspecs (token
)
697 || token
->keyword
== RID_STATIC_ASSERT
)
703 /* Return true if the next token from PARSER can start declaration
704 specifiers, false otherwise. */
706 c_parser_next_token_starts_declspecs (c_parser
*parser
)
708 c_token
*token
= c_parser_peek_token (parser
);
710 /* In Objective-C, a classname normally starts a declspecs unless it
711 is immediately followed by a dot. In that case, it is the
712 Objective-C 2.0 "dot-syntax" for class objects, ie, calls the
713 setter/getter on the class. c_token_starts_declspecs() can't
714 differentiate between the two cases because it only checks the
715 current token, so we have a special check here. */
716 if (c_dialect_objc ()
717 && token
->type
== CPP_NAME
718 && token
->id_kind
== C_ID_CLASSNAME
719 && c_parser_peek_2nd_token (parser
)->type
== CPP_DOT
)
722 return c_token_starts_declspecs (token
);
725 /* Return true if the next tokens from PARSER can start declaration
726 specifiers or a static assertion, false otherwise. */
728 c_parser_next_tokens_start_declaration (c_parser
*parser
)
730 c_token
*token
= c_parser_peek_token (parser
);
733 if (c_dialect_objc ()
734 && token
->type
== CPP_NAME
735 && token
->id_kind
== C_ID_CLASSNAME
736 && c_parser_peek_2nd_token (parser
)->type
== CPP_DOT
)
739 /* Labels do not start declarations. */
740 if (token
->type
== CPP_NAME
741 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
744 if (c_token_starts_declaration (token
))
747 if (c_parser_next_tokens_start_typename (parser
, cla_nonabstract_decl
))
753 /* Consume the next token from PARSER. */
756 c_parser_consume_token (c_parser
*parser
)
758 gcc_assert (parser
->tokens_avail
>= 1);
759 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
760 gcc_assert (!parser
->in_pragma
|| parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
761 gcc_assert (parser
->error
|| parser
->tokens
[0].type
!= CPP_PRAGMA
);
762 if (parser
->tokens_avail
== 2)
763 parser
->tokens
[0] = parser
->tokens
[1];
764 parser
->tokens_avail
--;
767 /* Expect the current token to be a #pragma. Consume it and remember
768 that we've begun parsing a pragma. */
771 c_parser_consume_pragma (c_parser
*parser
)
773 gcc_assert (!parser
->in_pragma
);
774 gcc_assert (parser
->tokens_avail
>= 1);
775 gcc_assert (parser
->tokens
[0].type
== CPP_PRAGMA
);
776 if (parser
->tokens_avail
== 2)
777 parser
->tokens
[0] = parser
->tokens
[1];
778 parser
->tokens_avail
--;
779 parser
->in_pragma
= true;
782 /* Update the globals input_location and in_system_header from
785 c_parser_set_source_position_from_token (c_token
*token
)
787 if (token
->type
!= CPP_EOF
)
789 input_location
= token
->location
;
793 /* Issue a diagnostic of the form
794 FILE:LINE: MESSAGE before TOKEN
795 where TOKEN is the next token in the input stream of PARSER.
796 MESSAGE (specified by the caller) is usually of the form "expected
799 Do not issue a diagnostic if still recovering from an error.
801 ??? This is taken from the C++ parser, but building up messages in
802 this way is not i18n-friendly and some other approach should be
806 c_parser_error (c_parser
*parser
, const char *gmsgid
)
808 c_token
*token
= c_parser_peek_token (parser
);
811 parser
->error
= true;
814 /* This diagnostic makes more sense if it is tagged to the line of
815 the token we just peeked at. */
816 c_parser_set_source_position_from_token (token
);
817 c_parse_error (gmsgid
,
818 /* Because c_parse_error does not understand
819 CPP_KEYWORD, keywords are treated like
821 (token
->type
== CPP_KEYWORD
? CPP_NAME
: token
->type
),
822 /* ??? The C parser does not save the cpp flags of a
823 token, we need to pass 0 here and we will not get
824 the source spelling of some tokens but rather the
825 canonical spelling. */
826 token
->value
, /*flags=*/0);
829 /* If the next token is of the indicated TYPE, consume it. Otherwise,
830 issue the error MSGID. If MSGID is NULL then a message has already
831 been produced and no message will be produced this time. Returns
832 true if found, false otherwise. */
835 c_parser_require (c_parser
*parser
,
839 if (c_parser_next_token_is (parser
, type
))
841 c_parser_consume_token (parser
);
846 c_parser_error (parser
, msgid
);
851 /* If the next token is the indicated keyword, consume it. Otherwise,
852 issue the error MSGID. Returns true if found, false otherwise. */
855 c_parser_require_keyword (c_parser
*parser
,
859 if (c_parser_next_token_is_keyword (parser
, keyword
))
861 c_parser_consume_token (parser
);
866 c_parser_error (parser
, msgid
);
871 /* Like c_parser_require, except that tokens will be skipped until the
872 desired token is found. An error message is still produced if the
873 next token is not as expected. If MSGID is NULL then a message has
874 already been produced and no message will be produced this
878 c_parser_skip_until_found (c_parser
*parser
,
882 unsigned nesting_depth
= 0;
884 if (c_parser_require (parser
, type
, msgid
))
887 /* Skip tokens until the desired token is found. */
890 /* Peek at the next token. */
891 c_token
*token
= c_parser_peek_token (parser
);
892 /* If we've reached the token we want, consume it and stop. */
893 if (token
->type
== type
&& !nesting_depth
)
895 c_parser_consume_token (parser
);
899 /* If we've run out of tokens, stop. */
900 if (token
->type
== CPP_EOF
)
902 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
904 if (token
->type
== CPP_OPEN_BRACE
905 || token
->type
== CPP_OPEN_PAREN
906 || token
->type
== CPP_OPEN_SQUARE
)
908 else if (token
->type
== CPP_CLOSE_BRACE
909 || token
->type
== CPP_CLOSE_PAREN
910 || token
->type
== CPP_CLOSE_SQUARE
)
912 if (nesting_depth
-- == 0)
915 /* Consume this token. */
916 c_parser_consume_token (parser
);
918 parser
->error
= false;
921 /* Skip tokens until the end of a parameter is found, but do not
922 consume the comma, semicolon or closing delimiter. */
925 c_parser_skip_to_end_of_parameter (c_parser
*parser
)
927 unsigned nesting_depth
= 0;
931 c_token
*token
= c_parser_peek_token (parser
);
932 if ((token
->type
== CPP_COMMA
|| token
->type
== CPP_SEMICOLON
)
935 /* If we've run out of tokens, stop. */
936 if (token
->type
== CPP_EOF
)
938 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
940 if (token
->type
== CPP_OPEN_BRACE
941 || token
->type
== CPP_OPEN_PAREN
942 || token
->type
== CPP_OPEN_SQUARE
)
944 else if (token
->type
== CPP_CLOSE_BRACE
945 || token
->type
== CPP_CLOSE_PAREN
946 || token
->type
== CPP_CLOSE_SQUARE
)
948 if (nesting_depth
-- == 0)
951 /* Consume this token. */
952 c_parser_consume_token (parser
);
954 parser
->error
= false;
957 /* Expect to be at the end of the pragma directive and consume an
958 end of line marker. */
961 c_parser_skip_to_pragma_eol (c_parser
*parser
)
963 gcc_assert (parser
->in_pragma
);
964 parser
->in_pragma
= false;
966 if (!c_parser_require (parser
, CPP_PRAGMA_EOL
, "expected end of line"))
969 c_token
*token
= c_parser_peek_token (parser
);
970 if (token
->type
== CPP_EOF
)
972 if (token
->type
== CPP_PRAGMA_EOL
)
974 c_parser_consume_token (parser
);
977 c_parser_consume_token (parser
);
980 parser
->error
= false;
983 /* Skip tokens until we have consumed an entire block, or until we
984 have consumed a non-nested ';'. */
987 c_parser_skip_to_end_of_block_or_statement (c_parser
*parser
)
989 unsigned nesting_depth
= 0;
990 bool save_error
= parser
->error
;
996 /* Peek at the next token. */
997 token
= c_parser_peek_token (parser
);
1004 case CPP_PRAGMA_EOL
:
1005 if (parser
->in_pragma
)
1010 /* If the next token is a ';', we have reached the
1011 end of the statement. */
1014 /* Consume the ';'. */
1015 c_parser_consume_token (parser
);
1020 case CPP_CLOSE_BRACE
:
1021 /* If the next token is a non-nested '}', then we have
1022 reached the end of the current block. */
1023 if (nesting_depth
== 0 || --nesting_depth
== 0)
1025 c_parser_consume_token (parser
);
1030 case CPP_OPEN_BRACE
:
1031 /* If it the next token is a '{', then we are entering a new
1032 block. Consume the entire block. */
1037 /* If we see a pragma, consume the whole thing at once. We
1038 have some safeguards against consuming pragmas willy-nilly.
1039 Normally, we'd expect to be here with parser->error set,
1040 which disables these safeguards. But it's possible to get
1041 here for secondary error recovery, after parser->error has
1043 c_parser_consume_pragma (parser
);
1044 c_parser_skip_to_pragma_eol (parser
);
1045 parser
->error
= save_error
;
1052 c_parser_consume_token (parser
);
1056 parser
->error
= false;
1059 /* CPP's options (initialized by c-opts.c). */
1060 extern cpp_options
*cpp_opts
;
1062 /* Save the warning flags which are controlled by __extension__. */
1065 disable_extension_diagnostics (void)
1068 | (warn_pointer_arith
<< 1)
1069 | (warn_traditional
<< 2)
1071 | (warn_long_long
<< 4)
1072 | (warn_cxx_compat
<< 5)
1073 | (warn_overlength_strings
<< 6));
1074 cpp_opts
->cpp_pedantic
= pedantic
= 0;
1075 warn_pointer_arith
= 0;
1076 cpp_opts
->cpp_warn_traditional
= warn_traditional
= 0;
1078 cpp_opts
->cpp_warn_long_long
= warn_long_long
= 0;
1079 warn_cxx_compat
= 0;
1080 warn_overlength_strings
= 0;
1084 /* Restore the warning flags which are controlled by __extension__.
1085 FLAGS is the return value from disable_extension_diagnostics. */
1088 restore_extension_diagnostics (int flags
)
1090 cpp_opts
->cpp_pedantic
= pedantic
= flags
& 1;
1091 warn_pointer_arith
= (flags
>> 1) & 1;
1092 cpp_opts
->cpp_warn_traditional
= warn_traditional
= (flags
>> 2) & 1;
1093 flag_iso
= (flags
>> 3) & 1;
1094 cpp_opts
->cpp_warn_long_long
= warn_long_long
= (flags
>> 4) & 1;
1095 warn_cxx_compat
= (flags
>> 5) & 1;
1096 warn_overlength_strings
= (flags
>> 6) & 1;
1099 /* Possibly kinds of declarator to parse. */
1100 typedef enum c_dtr_syn
{
1101 /* A normal declarator with an identifier. */
1103 /* An abstract declarator (maybe empty). */
1105 /* A parameter declarator: may be either, but after a type name does
1106 not redeclare a typedef name as an identifier if it can
1107 alternatively be interpreted as a typedef name; see DR#009,
1108 applied in C90 TC1, omitted from C99 and reapplied in C99 TC2
1109 following DR#249. For example, given a typedef T, "int T" and
1110 "int *T" are valid parameter declarations redeclaring T, while
1111 "int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are
1112 abstract declarators rather than involving redundant parentheses;
1113 the same applies with attributes inside the parentheses before
1118 /* The binary operation precedence levels, where 0 is a dummy lowest level
1119 used for the bottom of the stack. */
1120 enum c_parser_prec
{
1135 /* Expression and its location. */
1136 struct c_tree_loc_pair
{
1141 static void c_parser_external_declaration (c_parser
*);
1142 static void c_parser_asm_definition (c_parser
*);
1143 static void c_parser_declaration_or_fndef (c_parser
*, bool, bool, bool,
1144 bool, bool, tree
*);
1145 static void c_parser_static_assert_declaration_no_semi (c_parser
*);
1146 static void c_parser_static_assert_declaration (c_parser
*);
1147 static void c_parser_declspecs (c_parser
*, struct c_declspecs
*, bool, bool,
1148 bool, enum c_lookahead_kind
);
1149 static struct c_typespec
c_parser_enum_specifier (c_parser
*);
1150 static struct c_typespec
c_parser_struct_or_union_specifier (c_parser
*);
1151 static tree
c_parser_struct_declaration (c_parser
*);
1152 static struct c_typespec
c_parser_typeof_specifier (c_parser
*);
1153 static tree
c_parser_alignas_specifier (c_parser
*);
1154 static struct c_declarator
*c_parser_declarator (c_parser
*, bool, c_dtr_syn
,
1156 static struct c_declarator
*c_parser_direct_declarator (c_parser
*, bool,
1158 static struct c_declarator
*c_parser_direct_declarator_inner (c_parser
*,
1160 struct c_declarator
*);
1161 static struct c_arg_info
*c_parser_parms_declarator (c_parser
*, bool, tree
);
1162 static struct c_arg_info
*c_parser_parms_list_declarator (c_parser
*, tree
,
1164 static struct c_parm
*c_parser_parameter_declaration (c_parser
*, tree
);
1165 static tree
c_parser_simple_asm_expr (c_parser
*);
1166 static tree
c_parser_attributes (c_parser
*);
1167 static struct c_type_name
*c_parser_type_name (c_parser
*);
1168 static struct c_expr
c_parser_initializer (c_parser
*);
1169 static struct c_expr
c_parser_braced_init (c_parser
*, tree
, bool);
1170 static void c_parser_initelt (c_parser
*, struct obstack
*);
1171 static void c_parser_initval (c_parser
*, struct c_expr
*,
1173 static tree
c_parser_compound_statement (c_parser
*);
1174 static void c_parser_compound_statement_nostart (c_parser
*);
1175 static void c_parser_label (c_parser
*);
1176 static void c_parser_statement (c_parser
*);
1177 static void c_parser_statement_after_labels (c_parser
*);
1178 static void c_parser_if_statement (c_parser
*);
1179 static void c_parser_switch_statement (c_parser
*);
1180 static void c_parser_while_statement (c_parser
*);
1181 static void c_parser_do_statement (c_parser
*);
1182 static void c_parser_for_statement (c_parser
*);
1183 static tree
c_parser_asm_statement (c_parser
*);
1184 static tree
c_parser_asm_operands (c_parser
*, bool);
1185 static tree
c_parser_asm_goto_operands (c_parser
*);
1186 static tree
c_parser_asm_clobbers (c_parser
*);
1187 static struct c_expr
c_parser_expr_no_commas (c_parser
*, struct c_expr
*);
1188 static struct c_expr
c_parser_conditional_expression (c_parser
*,
1190 static struct c_expr
c_parser_binary_expression (c_parser
*, struct c_expr
*,
1191 enum c_parser_prec
);
1192 static struct c_expr
c_parser_cast_expression (c_parser
*, struct c_expr
*);
1193 static struct c_expr
c_parser_unary_expression (c_parser
*);
1194 static struct c_expr
c_parser_sizeof_expression (c_parser
*);
1195 static struct c_expr
c_parser_alignof_expression (c_parser
*);
1196 static struct c_expr
c_parser_postfix_expression (c_parser
*);
1197 static struct c_expr
c_parser_postfix_expression_after_paren_type (c_parser
*,
1198 struct c_type_name
*,
1200 static struct c_expr
c_parser_postfix_expression_after_primary (c_parser
*,
1203 static tree
c_parser_transaction (c_parser
*, enum rid
);
1204 static struct c_expr
c_parser_transaction_expression (c_parser
*, enum rid
);
1205 static tree
c_parser_transaction_cancel (c_parser
*);
1206 static struct c_expr
c_parser_expression (c_parser
*);
1207 static struct c_expr
c_parser_expression_conv (c_parser
*);
1208 static VEC(tree
,gc
) *c_parser_expr_list (c_parser
*, bool, bool,
1210 struct c_tree_loc_pair
*);
1211 static void c_parser_omp_construct (c_parser
*);
1212 static void c_parser_omp_threadprivate (c_parser
*);
1213 static void c_parser_omp_barrier (c_parser
*);
1214 static void c_parser_omp_flush (c_parser
*);
1215 static void c_parser_omp_taskwait (c_parser
*);
1216 static void c_parser_omp_taskyield (c_parser
*);
1218 enum pragma_context
{ pragma_external
, pragma_stmt
, pragma_compound
};
1219 static bool c_parser_pragma (c_parser
*, enum pragma_context
);
1221 /* These Objective-C parser functions are only ever called when
1222 compiling Objective-C. */
1223 static void c_parser_objc_class_definition (c_parser
*, tree
);
1224 static void c_parser_objc_class_instance_variables (c_parser
*);
1225 static void c_parser_objc_class_declaration (c_parser
*);
1226 static void c_parser_objc_alias_declaration (c_parser
*);
1227 static void c_parser_objc_protocol_definition (c_parser
*, tree
);
1228 static bool c_parser_objc_method_type (c_parser
*);
1229 static void c_parser_objc_method_definition (c_parser
*);
1230 static void c_parser_objc_methodprotolist (c_parser
*);
1231 static void c_parser_objc_methodproto (c_parser
*);
1232 static tree
c_parser_objc_method_decl (c_parser
*, bool, tree
*, tree
*);
1233 static tree
c_parser_objc_type_name (c_parser
*);
1234 static tree
c_parser_objc_protocol_refs (c_parser
*);
1235 static void c_parser_objc_try_catch_finally_statement (c_parser
*);
1236 static void c_parser_objc_synchronized_statement (c_parser
*);
1237 static tree
c_parser_objc_selector (c_parser
*);
1238 static tree
c_parser_objc_selector_arg (c_parser
*);
1239 static tree
c_parser_objc_receiver (c_parser
*);
1240 static tree
c_parser_objc_message_args (c_parser
*);
1241 static tree
c_parser_objc_keywordexpr (c_parser
*);
1242 static void c_parser_objc_at_property_declaration (c_parser
*);
1243 static void c_parser_objc_at_synthesize_declaration (c_parser
*);
1244 static void c_parser_objc_at_dynamic_declaration (c_parser
*);
1245 static bool c_parser_objc_diagnose_bad_element_prefix
1246 (c_parser
*, struct c_declspecs
*);
1248 /* These UPC parser functions are only ever called when
1250 static void c_parser_upc_forall_statement (c_parser
*);
1251 static void c_parser_upc_sync_statement (c_parser
*, int);
1252 static void c_parser_upc_shared_qual (source_location
,
1254 struct c_declspecs
*);
1256 /* Parse a translation unit (C90 6.7, C99 6.9).
1259 external-declarations
1261 external-declarations:
1262 external-declaration
1263 external-declarations external-declaration
1272 c_parser_translation_unit (c_parser
*parser
)
1274 if (c_parser_next_token_is (parser
, CPP_EOF
))
1276 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
1277 "ISO C forbids an empty translation unit");
1281 void *obstack_position
= obstack_alloc (&parser_obstack
, 0);
1282 mark_valid_location_for_stdc_pragma (false);
1286 c_parser_external_declaration (parser
);
1287 obstack_free (&parser_obstack
, obstack_position
);
1289 while (c_parser_next_token_is_not (parser
, CPP_EOF
));
1293 /* Parse an external declaration (C90 6.7, C99 6.9).
1295 external-declaration:
1301 external-declaration:
1304 __extension__ external-declaration
1308 external-declaration:
1309 objc-class-definition
1310 objc-class-declaration
1311 objc-alias-declaration
1312 objc-protocol-definition
1313 objc-method-definition
1318 c_parser_external_declaration (c_parser
*parser
)
1321 switch (c_parser_peek_token (parser
)->type
)
1324 switch (c_parser_peek_token (parser
)->keyword
)
1327 ext
= disable_extension_diagnostics ();
1328 c_parser_consume_token (parser
);
1329 c_parser_external_declaration (parser
);
1330 restore_extension_diagnostics (ext
);
1333 c_parser_asm_definition (parser
);
1335 case RID_AT_INTERFACE
:
1336 case RID_AT_IMPLEMENTATION
:
1337 gcc_assert (c_dialect_objc ());
1338 c_parser_objc_class_definition (parser
, NULL_TREE
);
1341 gcc_assert (c_dialect_objc ());
1342 c_parser_objc_class_declaration (parser
);
1345 gcc_assert (c_dialect_objc ());
1346 c_parser_objc_alias_declaration (parser
);
1348 case RID_AT_PROTOCOL
:
1349 gcc_assert (c_dialect_objc ());
1350 c_parser_objc_protocol_definition (parser
, NULL_TREE
);
1352 case RID_AT_PROPERTY
:
1353 gcc_assert (c_dialect_objc ());
1354 c_parser_objc_at_property_declaration (parser
);
1356 case RID_AT_SYNTHESIZE
:
1357 gcc_assert (c_dialect_objc ());
1358 c_parser_objc_at_synthesize_declaration (parser
);
1360 case RID_AT_DYNAMIC
:
1361 gcc_assert (c_dialect_objc ());
1362 c_parser_objc_at_dynamic_declaration (parser
);
1365 gcc_assert (c_dialect_objc ());
1366 c_parser_consume_token (parser
);
1367 objc_finish_implementation ();
1374 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
1375 "ISO C does not allow extra %<;%> outside of a function");
1376 c_parser_consume_token (parser
);
1379 mark_valid_location_for_stdc_pragma (true);
1380 c_parser_pragma (parser
, pragma_external
);
1381 mark_valid_location_for_stdc_pragma (false);
1385 if (c_dialect_objc ())
1387 c_parser_objc_method_definition (parser
);
1390 /* Else fall through, and yield a syntax error trying to parse
1391 as a declaration or function definition. */
1394 /* A declaration or a function definition (or, in Objective-C,
1395 an @interface or @protocol with prefix attributes). We can
1396 only tell which after parsing the declaration specifiers, if
1397 any, and the first declarator. */
1398 c_parser_declaration_or_fndef (parser
, true, true, true, false, true, NULL
);
1403 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1404 6.7, 6.9.1). If FNDEF_OK is true, a function definition is
1405 accepted; otherwise (old-style parameter declarations) only other
1406 declarations are accepted. If STATIC_ASSERT_OK is true, a static
1407 assertion is accepted; otherwise (old-style parameter declarations)
1408 it is not. If NESTED is true, we are inside a function or parsing
1409 old-style parameter declarations; any functions encountered are
1410 nested functions and declaration specifiers are required; otherwise
1411 we are at top level and functions are normal functions and
1412 declaration specifiers may be optional. If EMPTY_OK is true, empty
1413 declarations are OK (subject to all other constraints); otherwise
1414 (old-style parameter declarations) they are diagnosed. If
1415 START_ATTR_OK is true, the declaration specifiers may start with
1416 attributes; otherwise they may not.
1417 OBJC_FOREACH_OBJECT_DECLARATION can be used to get back the parsed
1418 declaration when parsing an Objective-C foreach statement.
1421 declaration-specifiers init-declarator-list[opt] ;
1422 static_assert-declaration
1424 function-definition:
1425 declaration-specifiers[opt] declarator declaration-list[opt]
1430 declaration-list declaration
1432 init-declarator-list:
1434 init-declarator-list , init-declarator
1437 declarator simple-asm-expr[opt] attributes[opt]
1438 declarator simple-asm-expr[opt] attributes[opt] = initializer
1442 nested-function-definition:
1443 declaration-specifiers declarator declaration-list[opt]
1447 attributes objc-class-definition
1448 attributes objc-category-definition
1449 attributes objc-protocol-definition
1451 The simple-asm-expr and attributes are GNU extensions.
1453 This function does not handle __extension__; that is handled in its
1454 callers. ??? Following the old parser, __extension__ may start
1455 external declarations, declarations in functions and declarations
1456 at the start of "for" loops, but not old-style parameter
1459 C99 requires declaration specifiers in a function definition; the
1460 absence is diagnosed through the diagnosis of implicit int. In GNU
1461 C we also allow but diagnose declarations without declaration
1462 specifiers, but only at top level (elsewhere they conflict with
1465 In Objective-C, declarations of the looping variable in a foreach
1466 statement are exceptionally terminated by 'in' (for example, 'for
1467 (NSObject *object in array) { ... }').
1472 threadprivate-directive */
1475 c_parser_declaration_or_fndef (c_parser
*parser
, bool fndef_ok
,
1476 bool static_assert_ok
, bool empty_ok
,
1477 bool nested
, bool start_attr_ok
,
1478 tree
*objc_foreach_object_declaration
)
1480 struct c_declspecs
*specs
;
1482 tree all_prefix_attrs
;
1483 bool diagnosed_no_specs
= false;
1484 location_t here
= c_parser_peek_token (parser
)->location
;
1486 if (static_assert_ok
1487 && c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
1489 c_parser_static_assert_declaration (parser
);
1492 specs
= build_null_declspecs ();
1494 /* Try to detect an unknown type name when we have "A B" or "A *B". */
1495 if (c_parser_peek_token (parser
)->type
== CPP_NAME
1496 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
1497 && (c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
1498 || c_parser_peek_2nd_token (parser
)->type
== CPP_MULT
)
1499 && (!nested
|| !lookup_name (c_parser_peek_token (parser
)->value
)))
1501 error_at (here
, "unknown type name %qE",
1502 c_parser_peek_token (parser
)->value
);
1504 /* Parse declspecs normally to get a correct pointer type, but avoid
1505 a further "fails to be a type name" error. Refuse nested functions
1506 since it is not how the user likely wants us to recover. */
1507 c_parser_peek_token (parser
)->type
= CPP_KEYWORD
;
1508 c_parser_peek_token (parser
)->keyword
= RID_VOID
;
1509 c_parser_peek_token (parser
)->value
= error_mark_node
;
1513 c_parser_declspecs (parser
, specs
, true, true, start_attr_ok
, cla_nonabstract_decl
);
1516 c_parser_skip_to_end_of_block_or_statement (parser
);
1519 if (nested
&& !specs
->declspecs_seen_p
)
1521 c_parser_error (parser
, "expected declaration specifiers");
1522 c_parser_skip_to_end_of_block_or_statement (parser
);
1525 finish_declspecs (specs
);
1526 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1532 shadow_tag_warned (specs
, 1);
1533 pedwarn (here
, 0, "empty declaration");
1535 c_parser_consume_token (parser
);
1539 /* Provide better error recovery. Note that a type name here is usually
1540 better diagnosed as a redeclaration. */
1542 && specs
->typespec_kind
== ctsk_tagdef
1543 && c_parser_next_token_starts_declspecs (parser
)
1544 && !c_parser_next_token_is (parser
, CPP_NAME
))
1546 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
1547 parser
->error
= false;
1548 shadow_tag_warned (specs
, 1);
1551 else if (c_dialect_objc ())
1553 /* Prefix attributes are an error on method decls. */
1554 switch (c_parser_peek_token (parser
)->type
)
1558 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1562 warning_at (c_parser_peek_token (parser
)->location
,
1564 "prefix attributes are ignored for methods");
1565 specs
->attrs
= NULL_TREE
;
1568 c_parser_objc_method_definition (parser
);
1570 c_parser_objc_methodproto (parser
);
1576 /* This is where we parse 'attributes @interface ...',
1577 'attributes @implementation ...', 'attributes @protocol ...'
1578 (where attributes could be, for example, __attribute__
1581 switch (c_parser_peek_token (parser
)->keyword
)
1583 case RID_AT_INTERFACE
:
1585 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1587 c_parser_objc_class_definition (parser
, specs
->attrs
);
1591 case RID_AT_IMPLEMENTATION
:
1593 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1597 warning_at (c_parser_peek_token (parser
)->location
,
1599 "prefix attributes are ignored for implementations");
1600 specs
->attrs
= NULL_TREE
;
1602 c_parser_objc_class_definition (parser
, NULL_TREE
);
1606 case RID_AT_PROTOCOL
:
1608 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1610 c_parser_objc_protocol_definition (parser
, specs
->attrs
);
1617 case RID_AT_PROPERTY
:
1620 c_parser_error (parser
, "unexpected attribute");
1621 specs
->attrs
= NULL
;
1629 pending_xref_error ();
1630 prefix_attrs
= specs
->attrs
;
1631 all_prefix_attrs
= prefix_attrs
;
1632 specs
->attrs
= NULL_TREE
;
1635 struct c_declarator
*declarator
;
1639 /* Declaring either one or more declarators (in which case we
1640 should diagnose if there were no declaration specifiers) or a
1641 function definition (in which case the diagnostic for
1642 implicit int suffices). */
1643 declarator
= c_parser_declarator (parser
,
1644 specs
->typespec_kind
!= ctsk_none
,
1645 C_DTR_NORMAL
, &dummy
);
1646 if (declarator
== NULL
)
1648 c_parser_skip_to_end_of_block_or_statement (parser
);
1651 if (c_parser_next_token_is (parser
, CPP_EQ
)
1652 || c_parser_next_token_is (parser
, CPP_COMMA
)
1653 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
1654 || c_parser_next_token_is_keyword (parser
, RID_ASM
)
1655 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
)
1656 || c_parser_next_token_is_keyword (parser
, RID_IN
))
1658 tree asm_name
= NULL_TREE
;
1659 tree postfix_attrs
= NULL_TREE
;
1660 if (!diagnosed_no_specs
&& !specs
->declspecs_seen_p
)
1662 diagnosed_no_specs
= true;
1663 pedwarn (here
, 0, "data definition has no type or storage class");
1665 /* Having seen a data definition, there cannot now be a
1666 function definition. */
1668 if (c_parser_next_token_is_keyword (parser
, RID_ASM
))
1669 asm_name
= c_parser_simple_asm_expr (parser
);
1670 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1671 postfix_attrs
= c_parser_attributes (parser
);
1672 if (c_parser_next_token_is (parser
, CPP_EQ
))
1676 location_t init_loc
;
1677 c_parser_consume_token (parser
);
1678 /* The declaration of the variable is in effect while
1679 its initializer is parsed. */
1680 d
= start_decl (declarator
, specs
, true,
1681 chainon (postfix_attrs
, all_prefix_attrs
));
1683 d
= error_mark_node
;
1684 start_init (d
, asm_name
, global_bindings_p ());
1685 init_loc
= c_parser_peek_token (parser
)->location
;
1686 init
= c_parser_initializer (parser
);
1688 if (d
!= error_mark_node
)
1690 maybe_warn_string_init (TREE_TYPE (d
), init
);
1691 finish_decl (d
, init_loc
, init
.value
,
1692 init
.original_type
, asm_name
);
1697 tree d
= start_decl (declarator
, specs
, false,
1698 chainon (postfix_attrs
,
1701 finish_decl (d
, UNKNOWN_LOCATION
, NULL_TREE
,
1702 NULL_TREE
, asm_name
);
1704 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
1707 *objc_foreach_object_declaration
= d
;
1709 *objc_foreach_object_declaration
= error_mark_node
;
1712 if (c_parser_next_token_is (parser
, CPP_COMMA
))
1714 c_parser_consume_token (parser
);
1715 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1716 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
1719 all_prefix_attrs
= prefix_attrs
;
1722 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1724 c_parser_consume_token (parser
);
1727 else if (c_parser_next_token_is_keyword (parser
, RID_IN
))
1729 /* This can only happen in Objective-C: we found the
1730 'in' that terminates the declaration inside an
1731 Objective-C foreach statement. Do not consume the
1732 token, so that the caller can use it to determine
1733 that this indeed is a foreach context. */
1738 c_parser_error (parser
, "expected %<,%> or %<;%>");
1739 c_parser_skip_to_end_of_block_or_statement (parser
);
1745 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, "
1746 "%<asm%> or %<__attribute__%>");
1747 c_parser_skip_to_end_of_block_or_statement (parser
);
1750 /* Function definition (nested or otherwise). */
1753 pedwarn (here
, OPT_Wpedantic
, "ISO C forbids nested functions");
1754 c_push_function_context ();
1756 if (!start_function (specs
, declarator
, all_prefix_attrs
))
1758 /* This can appear in many cases looking nothing like a
1759 function definition, so we don't give a more specific
1760 error suggesting there was one. */
1761 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
1762 "or %<__attribute__%>");
1764 c_pop_function_context ();
1768 if (DECL_DECLARED_INLINE_P (current_function_decl
))
1769 tv
= TV_PARSE_INLINE
;
1774 /* Parse old-style parameter declarations. ??? Attributes are
1775 not allowed to start declaration specifiers here because of a
1776 syntax conflict between a function declaration with attribute
1777 suffix and a function definition with an attribute prefix on
1778 first old-style parameter declaration. Following the old
1779 parser, they are not accepted on subsequent old-style
1780 parameter declarations either. However, there is no
1781 ambiguity after the first declaration, nor indeed on the
1782 first as long as we don't allow postfix attributes after a
1783 declarator with a nonempty identifier list in a definition;
1784 and postfix attributes have never been accepted here in
1785 function definitions either. */
1786 while (c_parser_next_token_is_not (parser
, CPP_EOF
)
1787 && c_parser_next_token_is_not (parser
, CPP_OPEN_BRACE
))
1788 c_parser_declaration_or_fndef (parser
, false, false, false,
1790 store_parm_decls ();
1791 DECL_STRUCT_FUNCTION (current_function_decl
)->function_start_locus
1792 = c_parser_peek_token (parser
)->location
;
1793 fnbody
= c_parser_compound_statement (parser
);
1796 tree decl
= current_function_decl
;
1797 /* Mark nested functions as needing static-chain initially.
1798 lower_nested_functions will recompute it but the
1799 DECL_STATIC_CHAIN flag is also used before that happens,
1800 by initializer_constant_valid_p. See gcc.dg/nested-fn-2.c. */
1801 DECL_STATIC_CHAIN (decl
) = 1;
1804 c_pop_function_context ();
1805 add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl
), DECL_EXPR
, decl
));
1818 /* Parse an asm-definition (asm() outside a function body). This is a
1826 c_parser_asm_definition (c_parser
*parser
)
1828 tree asm_str
= c_parser_simple_asm_expr (parser
);
1830 add_asm_node (asm_str
);
1831 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
1834 /* Parse a static assertion (C11 6.7.10).
1836 static_assert-declaration:
1837 static_assert-declaration-no-semi ;
1841 c_parser_static_assert_declaration (c_parser
*parser
)
1843 c_parser_static_assert_declaration_no_semi (parser
);
1845 || !c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
1846 c_parser_skip_to_end_of_block_or_statement (parser
);
1849 /* Parse a static assertion (C11 6.7.10), without the trailing
1852 static_assert-declaration-no-semi:
1853 _Static_assert ( constant-expression , string-literal )
1857 c_parser_static_assert_declaration_no_semi (c_parser
*parser
)
1859 location_t assert_loc
, value_loc
;
1863 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
));
1864 assert_loc
= c_parser_peek_token (parser
)->location
;
1868 pedwarn (assert_loc
, OPT_Wpedantic
,
1869 "ISO C99 does not support %<_Static_assert%>");
1871 pedwarn (assert_loc
, OPT_Wpedantic
,
1872 "ISO C90 does not support %<_Static_assert%>");
1874 c_parser_consume_token (parser
);
1875 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
1877 value_loc
= c_parser_peek_token (parser
)->location
;
1878 value
= c_parser_expr_no_commas (parser
, NULL
).value
;
1879 parser
->lex_untranslated_string
= true;
1880 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
1882 parser
->lex_untranslated_string
= false;
1885 switch (c_parser_peek_token (parser
)->type
)
1891 case CPP_UTF8STRING
:
1892 string
= c_parser_peek_token (parser
)->value
;
1893 c_parser_consume_token (parser
);
1894 parser
->lex_untranslated_string
= false;
1897 c_parser_error (parser
, "expected string literal");
1898 parser
->lex_untranslated_string
= false;
1901 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
1903 if (!INTEGRAL_TYPE_P (TREE_TYPE (value
)))
1905 error_at (value_loc
, "expression in static assertion is not an integer");
1908 if (TREE_CODE (value
) != INTEGER_CST
)
1910 value
= c_fully_fold (value
, false, NULL
);
1911 if (TREE_CODE (value
) == INTEGER_CST
)
1912 pedwarn (value_loc
, OPT_Wpedantic
, "expression in static assertion "
1913 "is not an integer constant expression");
1915 if (TREE_CODE (value
) != INTEGER_CST
)
1917 error_at (value_loc
, "expression in static assertion is not constant");
1920 constant_expression_warning (value
);
1921 if (integer_zerop (value
))
1922 error_at (assert_loc
, "static assertion failed: %E", string
);
1925 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
1926 6.7), adding them to SPECS (which may already include some).
1927 Storage class specifiers are accepted iff SCSPEC_OK; type
1928 specifiers are accepted iff TYPESPEC_OK; attributes are accepted at
1929 the start iff START_ATTR_OK.
1931 declaration-specifiers:
1932 storage-class-specifier declaration-specifiers[opt]
1933 type-specifier declaration-specifiers[opt]
1934 type-qualifier declaration-specifiers[opt]
1935 function-specifier declaration-specifiers[opt]
1936 alignment-specifier declaration-specifiers[opt]
1938 Function specifiers (inline) are from C99, and are currently
1939 handled as storage class specifiers, as is __thread. Alignment
1940 specifiers are from C11.
1942 C90 6.5.1, C99 6.7.1:
1943 storage-class-specifier:
1955 (_Noreturn is new in C11.)
1957 C90 6.5.2, C99 6.7.2:
1970 [_Imaginary removed in C99 TC2]
1971 struct-or-union-specifier
1975 (_Bool and _Complex are new in C99.)
1977 C90 6.5.3, C99 6.7.3:
1983 address-space-qualifier
1985 (restrict is new in C99.)
1989 declaration-specifiers:
1990 attributes declaration-specifiers[opt]
1996 identifier recognized by the target
1998 storage-class-specifier:
2011 (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
2012 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
2017 class-name objc-protocol-refs[opt]
2018 typedef-name objc-protocol-refs
2023 c_parser_declspecs (c_parser
*parser
, struct c_declspecs
*specs
,
2024 bool scspec_ok
, bool typespec_ok
, bool start_attr_ok
,
2025 enum c_lookahead_kind la
)
2027 bool attrs_ok
= start_attr_ok
;
2028 bool seen_type
= specs
->typespec_kind
!= ctsk_none
;
2031 gcc_assert (la
== cla_prefer_id
);
2033 while (c_parser_next_token_is (parser
, CPP_NAME
)
2034 || c_parser_next_token_is (parser
, CPP_KEYWORD
)
2035 || (c_dialect_objc () && c_parser_next_token_is (parser
, CPP_LESS
)))
2037 struct c_typespec t
;
2040 location_t loc
= c_parser_peek_token (parser
)->location
;
2042 /* If we cannot accept a type, exit if the next token must start
2043 one. Also, if we already have seen a tagged definition,
2044 a typename would be an error anyway and likely the user
2045 has simply forgotten a semicolon, so we exit. */
2046 if ((!typespec_ok
|| specs
->typespec_kind
== ctsk_tagdef
)
2047 && c_parser_next_tokens_start_typename (parser
, la
)
2048 && !c_parser_next_token_is_qualifier (parser
))
2051 if (c_parser_next_token_is (parser
, CPP_NAME
))
2053 c_token
*name_token
= c_parser_peek_token (parser
);
2054 tree value
= name_token
->value
;
2055 c_id_kind kind
= name_token
->id_kind
;
2057 if (kind
== C_ID_ADDRSPACE
)
2060 = name_token
->keyword
- RID_FIRST_ADDR_SPACE
;
2061 declspecs_add_addrspace (name_token
->location
, specs
, as
);
2062 c_parser_consume_token (parser
);
2067 gcc_assert (!c_parser_next_token_is_qualifier (parser
));
2069 /* If we cannot accept a type, and the next token must start one,
2070 exit. Do the same if we already have seen a tagged definition,
2071 since it would be an error anyway and likely the user has simply
2072 forgotten a semicolon. */
2073 if (seen_type
|| !c_parser_next_tokens_start_typename (parser
, la
))
2076 /* Now at an unknown typename (C_ID_ID), a C_ID_TYPENAME or
2077 a C_ID_CLASSNAME. */
2078 c_parser_consume_token (parser
);
2081 if (kind
== C_ID_ID
)
2083 error ("unknown type name %qE", value
);
2084 t
.kind
= ctsk_typedef
;
2085 t
.spec
= error_mark_node
;
2087 else if (kind
== C_ID_TYPENAME
2088 && (!c_dialect_objc ()
2089 || c_parser_next_token_is_not (parser
, CPP_LESS
)))
2091 t
.kind
= ctsk_typedef
;
2092 /* For a typedef name, record the meaning, not the name.
2093 In case of 'foo foo, bar;'. */
2094 t
.spec
= lookup_name (value
);
2098 tree proto
= NULL_TREE
;
2099 gcc_assert (c_dialect_objc ());
2101 if (c_parser_next_token_is (parser
, CPP_LESS
))
2102 proto
= c_parser_objc_protocol_refs (parser
);
2103 t
.spec
= objc_get_protocol_qualified_type (value
, proto
);
2106 t
.expr_const_operands
= true;
2107 declspecs_add_type (name_token
->location
, specs
, t
);
2110 if (c_parser_next_token_is (parser
, CPP_LESS
))
2112 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
2113 nisse@lysator.liu.se. */
2115 gcc_assert (c_dialect_objc ());
2116 if (!typespec_ok
|| seen_type
)
2118 proto
= c_parser_objc_protocol_refs (parser
);
2120 t
.spec
= objc_get_protocol_qualified_type (NULL_TREE
, proto
);
2122 t
.expr_const_operands
= true;
2123 declspecs_add_type (loc
, specs
, t
);
2126 gcc_assert (c_parser_next_token_is (parser
, CPP_KEYWORD
));
2127 switch (c_parser_peek_token (parser
)->keyword
)
2140 /* TODO: Distinguish between function specifiers (inline, noreturn)
2141 and storage class specifiers, either here or in
2142 declspecs_add_scspec. */
2143 declspecs_add_scspec (loc
, specs
,
2144 c_parser_peek_token (parser
)->value
);
2145 c_parser_consume_token (parser
);
2169 if (c_dialect_objc ())
2170 parser
->objc_need_raw_identifier
= true;
2171 t
.kind
= ctsk_resword
;
2172 t
.spec
= c_parser_peek_token (parser
)->value
;
2174 t
.expr_const_operands
= true;
2175 declspecs_add_type (loc
, specs
, t
);
2176 c_parser_consume_token (parser
);
2183 t
= c_parser_enum_specifier (parser
);
2184 declspecs_add_type (loc
, specs
, t
);
2192 t
= c_parser_struct_or_union_specifier (parser
);
2193 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE
, t
.spec
);
2194 declspecs_add_type (loc
, specs
, t
);
2197 /* ??? The old parser rejected typeof after other type
2198 specifiers, but is a syntax error the best way of
2200 if (!typespec_ok
|| seen_type
)
2204 t
= c_parser_typeof_specifier (parser
);
2205 declspecs_add_type (loc
, specs
, t
);
2211 declspecs_add_qual (loc
, specs
, c_parser_peek_token (parser
)->value
);
2212 c_parser_consume_token (parser
);
2214 /* UPC qualifiers */
2217 c_parser_upc_shared_qual (loc
, parser
, specs
);
2222 declspecs_add_qual (loc
, specs
, c_parser_peek_token (parser
)->value
);
2223 c_parser_consume_token (parser
);
2228 attrs
= c_parser_attributes (parser
);
2229 declspecs_add_attrs (loc
, specs
, attrs
);
2232 align
= c_parser_alignas_specifier (parser
);
2233 declspecs_add_alignas (loc
, specs
, align
);
2242 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
2245 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
2246 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
2247 enum attributes[opt] identifier
2249 The form with trailing comma is new in C99. The forms with
2250 attributes are GNU extensions. In GNU C, we accept any expression
2251 without commas in the syntax (assignment expressions, not just
2252 conditional expressions); assignment expressions will be diagnosed
2257 enumerator-list , enumerator
2260 enumeration-constant
2261 enumeration-constant = constant-expression
2264 static struct c_typespec
2265 c_parser_enum_specifier (c_parser
*parser
)
2267 struct c_typespec ret
;
2269 tree ident
= NULL_TREE
;
2270 location_t enum_loc
;
2271 location_t ident_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2272 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ENUM
));
2273 enum_loc
= c_parser_peek_token (parser
)->location
;
2274 c_parser_consume_token (parser
);
2275 attrs
= c_parser_attributes (parser
);
2276 enum_loc
= c_parser_peek_token (parser
)->location
;
2277 /* Set the location in case we create a decl now. */
2278 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2279 if (c_parser_next_token_is (parser
, CPP_NAME
))
2281 ident
= c_parser_peek_token (parser
)->value
;
2282 ident_loc
= c_parser_peek_token (parser
)->location
;
2283 enum_loc
= ident_loc
;
2284 c_parser_consume_token (parser
);
2286 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2288 /* Parse an enum definition. */
2289 struct c_enum_contents the_enum
;
2292 /* We chain the enumerators in reverse order, then put them in
2293 forward order at the end. */
2295 timevar_push (TV_PARSE_ENUM
);
2296 type
= start_enum (enum_loc
, &the_enum
, ident
);
2298 c_parser_consume_token (parser
);
2306 location_t comma_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2307 location_t decl_loc
, value_loc
;
2308 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
2310 c_parser_error (parser
, "expected identifier");
2311 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2312 values
= error_mark_node
;
2315 token
= c_parser_peek_token (parser
);
2316 enum_id
= token
->value
;
2317 /* Set the location in case we create a decl now. */
2318 c_parser_set_source_position_from_token (token
);
2319 decl_loc
= value_loc
= token
->location
;
2320 c_parser_consume_token (parser
);
2321 if (c_parser_next_token_is (parser
, CPP_EQ
))
2323 c_parser_consume_token (parser
);
2324 value_loc
= c_parser_peek_token (parser
)->location
;
2325 enum_value
= c_parser_expr_no_commas (parser
, NULL
).value
;
2328 enum_value
= NULL_TREE
;
2329 enum_decl
= build_enumerator (decl_loc
, value_loc
,
2330 &the_enum
, enum_id
, enum_value
);
2331 TREE_CHAIN (enum_decl
) = values
;
2334 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2336 comma_loc
= c_parser_peek_token (parser
)->location
;
2338 c_parser_consume_token (parser
);
2340 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2342 if (seen_comma
&& !flag_isoc99
)
2343 pedwarn (comma_loc
, OPT_Wpedantic
, "comma at end of enumerator list");
2344 c_parser_consume_token (parser
);
2349 c_parser_error (parser
, "expected %<,%> or %<}%>");
2350 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2351 values
= error_mark_node
;
2355 postfix_attrs
= c_parser_attributes (parser
);
2356 ret
.spec
= finish_enum (type
, nreverse (values
),
2357 chainon (attrs
, postfix_attrs
));
2358 ret
.kind
= ctsk_tagdef
;
2359 ret
.expr
= NULL_TREE
;
2360 ret
.expr_const_operands
= true;
2361 timevar_pop (TV_PARSE_ENUM
);
2366 c_parser_error (parser
, "expected %<{%>");
2367 ret
.spec
= error_mark_node
;
2368 ret
.kind
= ctsk_tagref
;
2369 ret
.expr
= NULL_TREE
;
2370 ret
.expr_const_operands
= true;
2373 ret
= parser_xref_tag (ident_loc
, ENUMERAL_TYPE
, ident
);
2374 /* In ISO C, enumerated types can be referred to only if already
2376 if (pedantic
&& !COMPLETE_TYPE_P (ret
.spec
))
2379 pedwarn (enum_loc
, OPT_Wpedantic
,
2380 "ISO C forbids forward references to %<enum%> types");
2385 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
2387 struct-or-union-specifier:
2388 struct-or-union attributes[opt] identifier[opt]
2389 { struct-contents } attributes[opt]
2390 struct-or-union attributes[opt] identifier
2393 struct-declaration-list
2395 struct-declaration-list:
2396 struct-declaration ;
2397 struct-declaration-list struct-declaration ;
2404 struct-declaration-list struct-declaration
2406 struct-declaration-list:
2407 struct-declaration-list ;
2410 (Note that in the syntax here, unlike that in ISO C, the semicolons
2411 are included here rather than in struct-declaration, in order to
2412 describe the syntax with extra semicolons and missing semicolon at
2417 struct-declaration-list:
2418 @defs ( class-name )
2420 (Note this does not include a trailing semicolon, but can be
2421 followed by further declarations, and gets a pedwarn-if-pedantic
2422 when followed by a semicolon.) */
2424 static struct c_typespec
2425 c_parser_struct_or_union_specifier (c_parser
*parser
)
2427 struct c_typespec ret
;
2429 tree ident
= NULL_TREE
;
2430 location_t struct_loc
;
2431 location_t ident_loc
= UNKNOWN_LOCATION
;
2432 enum tree_code code
;
2433 switch (c_parser_peek_token (parser
)->keyword
)
2444 struct_loc
= c_parser_peek_token (parser
)->location
;
2445 c_parser_consume_token (parser
);
2446 attrs
= c_parser_attributes (parser
);
2448 /* Set the location in case we create a decl now. */
2449 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2451 if (c_parser_next_token_is (parser
, CPP_NAME
))
2453 ident
= c_parser_peek_token (parser
)->value
;
2454 ident_loc
= c_parser_peek_token (parser
)->location
;
2455 struct_loc
= ident_loc
;
2456 c_parser_consume_token (parser
);
2458 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2460 /* Parse a struct or union definition. Start the scope of the
2461 tag before parsing components. */
2462 struct c_struct_parse_info
*struct_info
;
2463 tree type
= start_struct (struct_loc
, code
, ident
, &struct_info
);
2465 /* We chain the components in reverse order, then put them in
2466 forward order at the end. Each struct-declaration may
2467 declare multiple components (comma-separated), so we must use
2468 chainon to join them, although when parsing each
2469 struct-declaration we can use TREE_CHAIN directly.
2471 The theory behind all this is that there will be more
2472 semicolon separated fields than comma separated fields, and
2473 so we'll be minimizing the number of node traversals required
2476 timevar_push (TV_PARSE_STRUCT
);
2477 contents
= NULL_TREE
;
2478 c_parser_consume_token (parser
);
2479 /* Handle the Objective-C @defs construct,
2480 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
2481 if (c_parser_next_token_is_keyword (parser
, RID_AT_DEFS
))
2484 gcc_assert (c_dialect_objc ());
2485 c_parser_consume_token (parser
);
2486 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2488 if (c_parser_next_token_is (parser
, CPP_NAME
)
2489 && c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
)
2491 name
= c_parser_peek_token (parser
)->value
;
2492 c_parser_consume_token (parser
);
2496 c_parser_error (parser
, "expected class name");
2497 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2500 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2502 contents
= nreverse (objc_get_class_ivars (name
));
2505 /* Parse the struct-declarations and semicolons. Problems with
2506 semicolons are diagnosed here; empty structures are diagnosed
2511 /* Parse any stray semicolon. */
2512 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2514 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
2515 "extra semicolon in struct or union specified");
2516 c_parser_consume_token (parser
);
2519 /* Stop if at the end of the struct or union contents. */
2520 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2522 c_parser_consume_token (parser
);
2525 /* Accept #pragmas at struct scope. */
2526 if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
2528 c_parser_pragma (parser
, pragma_external
);
2531 /* Parse some comma-separated declarations, but not the
2532 trailing semicolon if any. */
2533 decls
= c_parser_struct_declaration (parser
);
2534 contents
= chainon (decls
, contents
);
2535 /* If no semicolon follows, either we have a parse error or
2536 are at the end of the struct or union and should
2538 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2539 c_parser_consume_token (parser
);
2542 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2543 pedwarn (c_parser_peek_token (parser
)->location
, 0,
2544 "no semicolon at end of struct or union");
2545 else if (parser
->error
2546 || !c_parser_next_token_starts_declspecs (parser
))
2548 c_parser_error (parser
, "expected %<;%>");
2549 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2553 /* If we come here, we have already emitted an error
2554 for an expected `;', identifier or `(', and we also
2555 recovered already. Go on with the next field. */
2558 postfix_attrs
= c_parser_attributes (parser
);
2559 ret
.spec
= finish_struct (struct_loc
, type
, nreverse (contents
),
2560 chainon (attrs
, postfix_attrs
), struct_info
);
2561 ret
.kind
= ctsk_tagdef
;
2562 ret
.expr
= NULL_TREE
;
2563 ret
.expr_const_operands
= true;
2564 timevar_pop (TV_PARSE_STRUCT
);
2569 c_parser_error (parser
, "expected %<{%>");
2570 ret
.spec
= error_mark_node
;
2571 ret
.kind
= ctsk_tagref
;
2572 ret
.expr
= NULL_TREE
;
2573 ret
.expr_const_operands
= true;
2576 ret
= parser_xref_tag (ident_loc
, code
, ident
);
2580 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
2581 the trailing semicolon.
2584 specifier-qualifier-list struct-declarator-list
2585 static_assert-declaration-no-semi
2587 specifier-qualifier-list:
2588 type-specifier specifier-qualifier-list[opt]
2589 type-qualifier specifier-qualifier-list[opt]
2590 attributes specifier-qualifier-list[opt]
2592 struct-declarator-list:
2594 struct-declarator-list , attributes[opt] struct-declarator
2597 declarator attributes[opt]
2598 declarator[opt] : constant-expression attributes[opt]
2603 __extension__ struct-declaration
2604 specifier-qualifier-list
2606 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
2607 of attributes where shown is a GNU extension. In GNU C, we accept
2608 any expression without commas in the syntax (assignment
2609 expressions, not just conditional expressions); assignment
2610 expressions will be diagnosed as non-constant. */
2613 c_parser_struct_declaration (c_parser
*parser
)
2615 struct c_declspecs
*specs
;
2617 tree all_prefix_attrs
;
2619 location_t decl_loc
;
2620 if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
2624 ext
= disable_extension_diagnostics ();
2625 c_parser_consume_token (parser
);
2626 decl
= c_parser_struct_declaration (parser
);
2627 restore_extension_diagnostics (ext
);
2630 if (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
2632 c_parser_static_assert_declaration_no_semi (parser
);
2635 specs
= build_null_declspecs ();
2636 decl_loc
= c_parser_peek_token (parser
)->location
;
2637 c_parser_declspecs (parser
, specs
, false, true, true, cla_nonabstract_decl
);
2640 if (!specs
->declspecs_seen_p
)
2642 c_parser_error (parser
, "expected specifier-qualifier-list");
2645 finish_declspecs (specs
);
2646 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2647 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2650 if (specs
->typespec_kind
== ctsk_none
)
2652 pedwarn (decl_loc
, OPT_Wpedantic
,
2653 "ISO C forbids member declarations with no members");
2654 shadow_tag_warned (specs
, pedantic
);
2659 /* Support for unnamed structs or unions as members of
2660 structs or unions (which is [a] useful and [b] supports
2664 ret
= grokfield (c_parser_peek_token (parser
)->location
,
2665 build_id_declarator (NULL_TREE
), specs
,
2668 decl_attributes (&ret
, attrs
, 0);
2673 /* Provide better error recovery. Note that a type name here is valid,
2674 and will be treated as a field name. */
2675 if (specs
->typespec_kind
== ctsk_tagdef
2676 && TREE_CODE (specs
->type
) != ENUMERAL_TYPE
2677 && c_parser_next_token_starts_declspecs (parser
)
2678 && !c_parser_next_token_is (parser
, CPP_NAME
))
2680 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
2681 parser
->error
= false;
2685 pending_xref_error ();
2686 prefix_attrs
= specs
->attrs
;
2687 all_prefix_attrs
= prefix_attrs
;
2688 specs
->attrs
= NULL_TREE
;
2692 /* Declaring one or more declarators or un-named bit-fields. */
2693 struct c_declarator
*declarator
;
2695 if (c_parser_next_token_is (parser
, CPP_COLON
))
2696 declarator
= build_id_declarator (NULL_TREE
);
2698 declarator
= c_parser_declarator (parser
,
2699 specs
->typespec_kind
!= ctsk_none
,
2700 C_DTR_NORMAL
, &dummy
);
2701 if (declarator
== NULL
)
2703 c_parser_skip_to_end_of_block_or_statement (parser
);
2706 if (c_parser_next_token_is (parser
, CPP_COLON
)
2707 || c_parser_next_token_is (parser
, CPP_COMMA
)
2708 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2709 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
)
2710 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2712 tree postfix_attrs
= NULL_TREE
;
2713 tree width
= NULL_TREE
;
2715 if (c_parser_next_token_is (parser
, CPP_COLON
))
2717 c_parser_consume_token (parser
);
2718 width
= c_parser_expr_no_commas (parser
, NULL
).value
;
2720 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2721 postfix_attrs
= c_parser_attributes (parser
);
2722 d
= grokfield (c_parser_peek_token (parser
)->location
,
2723 declarator
, specs
, width
, &all_prefix_attrs
);
2724 decl_attributes (&d
, chainon (postfix_attrs
,
2725 all_prefix_attrs
), 0);
2726 DECL_CHAIN (d
) = decls
;
2728 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2729 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
2732 all_prefix_attrs
= prefix_attrs
;
2733 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2734 c_parser_consume_token (parser
);
2735 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2736 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2738 /* Semicolon consumed in caller. */
2743 c_parser_error (parser
, "expected %<,%>, %<;%> or %<}%>");
2749 c_parser_error (parser
,
2750 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
2751 "%<__attribute__%>");
2758 /* Parse a typeof specifier (a GNU extension).
2761 typeof ( expression )
2762 typeof ( type-name )
2765 static struct c_typespec
2766 c_parser_typeof_specifier (c_parser
*parser
)
2768 struct c_typespec ret
;
2769 ret
.kind
= ctsk_typeof
;
2770 ret
.spec
= error_mark_node
;
2771 ret
.expr
= NULL_TREE
;
2772 ret
.expr_const_operands
= true;
2773 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TYPEOF
));
2774 c_parser_consume_token (parser
);
2775 c_inhibit_evaluation_warnings
++;
2777 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2779 c_inhibit_evaluation_warnings
--;
2783 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
2785 struct c_type_name
*type
= c_parser_type_name (parser
);
2786 c_inhibit_evaluation_warnings
--;
2790 ret
.spec
= groktypename (type
, &ret
.expr
, &ret
.expr_const_operands
);
2791 pop_maybe_used (variably_modified_type_p (ret
.spec
, NULL_TREE
));
2797 location_t here
= c_parser_peek_token (parser
)->location
;
2798 struct c_expr expr
= c_parser_expression (parser
);
2799 c_inhibit_evaluation_warnings
--;
2801 if (TREE_CODE (expr
.value
) == COMPONENT_REF
2802 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
2803 error_at (here
, "%<typeof%> applied to a bit-field");
2804 mark_exp_read (expr
.value
);
2805 ret
.spec
= TREE_TYPE (expr
.value
);
2806 was_vm
= variably_modified_type_p (ret
.spec
, NULL_TREE
);
2807 /* This is returned with the type so that when the type is
2808 evaluated, this can be evaluated. */
2810 ret
.expr
= c_fully_fold (expr
.value
, false, &ret
.expr_const_operands
);
2811 pop_maybe_used (was_vm
);
2813 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
2817 /* Parse an alignment-specifier.
2821 alignment-specifier:
2822 _Alignas ( type-name )
2823 _Alignas ( constant-expression )
2827 c_parser_alignas_specifier (c_parser
* parser
)
2829 tree ret
= error_mark_node
;
2830 location_t loc
= c_parser_peek_token (parser
)->location
;
2831 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNAS
));
2832 c_parser_consume_token (parser
);
2836 pedwarn (loc
, OPT_Wpedantic
,
2837 "ISO C99 does not support %<_Alignas%>");
2839 pedwarn (loc
, OPT_Wpedantic
,
2840 "ISO C90 does not support %<_Alignas%>");
2842 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2844 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
2846 struct c_type_name
*type
= c_parser_type_name (parser
);
2848 ret
= c_alignof (loc
, groktypename (type
, NULL
, NULL
));
2851 ret
= c_parser_expr_no_commas (parser
, NULL
).value
;
2852 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
2856 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
2857 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
2858 be redeclared; otherwise it may not. KIND indicates which kind of
2859 declarator is wanted. Returns a valid declarator except in the
2860 case of a syntax error in which case NULL is returned. *SEEN_ID is
2861 set to true if an identifier being declared is seen; this is used
2862 to diagnose bad forms of abstract array declarators and to
2863 determine whether an identifier list is syntactically permitted.
2866 pointer[opt] direct-declarator
2870 ( attributes[opt] declarator )
2871 direct-declarator array-declarator
2872 direct-declarator ( parameter-type-list )
2873 direct-declarator ( identifier-list[opt] )
2876 * type-qualifier-list[opt]
2877 * type-qualifier-list[opt] pointer
2879 type-qualifier-list:
2882 type-qualifier-list type-qualifier
2883 type-qualifier-list attributes
2885 parameter-type-list:
2887 parameter-list , ...
2890 parameter-declaration
2891 parameter-list , parameter-declaration
2893 parameter-declaration:
2894 declaration-specifiers declarator attributes[opt]
2895 declaration-specifiers abstract-declarator[opt] attributes[opt]
2899 identifier-list , identifier
2901 abstract-declarator:
2903 pointer[opt] direct-abstract-declarator
2905 direct-abstract-declarator:
2906 ( attributes[opt] abstract-declarator )
2907 direct-abstract-declarator[opt] array-declarator
2908 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
2913 direct-declarator ( parameter-forward-declarations
2914 parameter-type-list[opt] )
2916 direct-abstract-declarator:
2917 direct-abstract-declarator[opt] ( parameter-forward-declarations
2918 parameter-type-list[opt] )
2920 parameter-forward-declarations:
2922 parameter-forward-declarations parameter-list ;
2924 The uses of attributes shown above are GNU extensions.
2926 Some forms of array declarator are not included in C99 in the
2927 syntax for abstract declarators; these are disallowed elsewhere.
2928 This may be a defect (DR#289).
2930 This function also accepts an omitted abstract declarator as being
2931 an abstract declarator, although not part of the formal syntax. */
2933 static struct c_declarator
*
2934 c_parser_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
2937 /* Parse any initial pointer part. */
2938 if (c_parser_next_token_is (parser
, CPP_MULT
))
2940 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
2941 struct c_declarator
*inner
;
2942 c_parser_consume_token (parser
);
2943 c_parser_declspecs (parser
, quals_attrs
, false, false, true, cla_prefer_id
);
2944 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
2948 return make_pointer_declarator (quals_attrs
, inner
);
2950 /* Now we have a direct declarator, direct abstract declarator or
2951 nothing (which counts as a direct abstract declarator here). */
2952 return c_parser_direct_declarator (parser
, type_seen_p
, kind
, seen_id
);
2955 /* Parse a direct declarator or direct abstract declarator; arguments
2956 as c_parser_declarator. */
2958 static struct c_declarator
*
2959 c_parser_direct_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
2962 /* The direct declarator must start with an identifier (possibly
2963 omitted) or a parenthesized declarator (possibly abstract). In
2964 an ordinary declarator, initial parentheses must start a
2965 parenthesized declarator. In an abstract declarator or parameter
2966 declarator, they could start a parenthesized declarator or a
2967 parameter list. To tell which, the open parenthesis and any
2968 following attributes must be read. If a declaration specifier
2969 follows, then it is a parameter list; if the specifier is a
2970 typedef name, there might be an ambiguity about redeclaring it,
2971 which is resolved in the direction of treating it as a typedef
2972 name. If a close parenthesis follows, it is also an empty
2973 parameter list, as the syntax does not permit empty abstract
2974 declarators. Otherwise, it is a parenthesized declarator (in
2975 which case the analysis may be repeated inside it, recursively).
2977 ??? There is an ambiguity in a parameter declaration "int
2978 (__attribute__((foo)) x)", where x is not a typedef name: it
2979 could be an abstract declarator for a function, or declare x with
2980 parentheses. The proper resolution of this ambiguity needs
2981 documenting. At present we follow an accident of the old
2982 parser's implementation, whereby the first parameter must have
2983 some declaration specifiers other than just attributes. Thus as
2984 a parameter declaration it is treated as a parenthesized
2985 parameter named x, and as an abstract declarator it is
2988 ??? Also following the old parser, attributes inside an empty
2989 parameter list are ignored, making it a list not yielding a
2990 prototype, rather than giving an error or making it have one
2991 parameter with implicit type int.
2993 ??? Also following the old parser, typedef names may be
2994 redeclared in declarators, but not Objective-C class names. */
2996 if (kind
!= C_DTR_ABSTRACT
2997 && c_parser_next_token_is (parser
, CPP_NAME
)
2999 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
3000 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
3001 || c_parser_peek_token (parser
)->id_kind
== C_ID_ID
))
3003 struct c_declarator
*inner
3004 = build_id_declarator (c_parser_peek_token (parser
)->value
);
3006 inner
->id_loc
= c_parser_peek_token (parser
)->location
;
3007 c_parser_consume_token (parser
);
3008 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3011 if (kind
!= C_DTR_NORMAL
3012 && c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
3014 struct c_declarator
*inner
= build_id_declarator (NULL_TREE
);
3015 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3018 /* Either we are at the end of an abstract declarator, or we have
3021 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3024 struct c_declarator
*inner
;
3025 c_parser_consume_token (parser
);
3026 attrs
= c_parser_attributes (parser
);
3027 if (kind
!= C_DTR_NORMAL
3028 && (c_parser_next_token_starts_declspecs (parser
)
3029 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
)))
3031 struct c_arg_info
*args
3032 = c_parser_parms_declarator (parser
, kind
== C_DTR_NORMAL
,
3039 = build_function_declarator (args
,
3040 build_id_declarator (NULL_TREE
));
3041 return c_parser_direct_declarator_inner (parser
, *seen_id
,
3045 /* A parenthesized declarator. */
3046 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
3047 if (inner
!= NULL
&& attrs
!= NULL
)
3048 inner
= build_attrs_declarator (attrs
, inner
);
3049 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3051 c_parser_consume_token (parser
);
3055 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3059 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3066 if (kind
== C_DTR_NORMAL
)
3068 c_parser_error (parser
, "expected identifier or %<(%>");
3072 return build_id_declarator (NULL_TREE
);
3076 /* Parse part of a direct declarator or direct abstract declarator,
3077 given that some (in INNER) has already been parsed; ID_PRESENT is
3078 true if an identifier is present, false for an abstract
3081 static struct c_declarator
*
3082 c_parser_direct_declarator_inner (c_parser
*parser
, bool id_present
,
3083 struct c_declarator
*inner
)
3085 /* Parse a sequence of array declarators and parameter lists. */
3086 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
3088 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
3089 struct c_declarator
*declarator
;
3090 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
3094 c_parser_consume_token (parser
);
3095 c_parser_declspecs (parser
, quals_attrs
, false, false, true, cla_prefer_id
);
3096 static_seen
= c_parser_next_token_is_keyword (parser
, RID_STATIC
);
3098 c_parser_consume_token (parser
);
3099 if (static_seen
&& !quals_attrs
->declspecs_seen_p
)
3100 c_parser_declspecs (parser
, quals_attrs
, false, false, true, cla_prefer_id
);
3101 if (!quals_attrs
->declspecs_seen_p
)
3103 /* If "static" is present, there must be an array dimension.
3104 Otherwise, there may be a dimension, "*", or no
3109 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
3113 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3118 else if (c_parser_next_token_is (parser
, CPP_MULT
))
3120 if (c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_SQUARE
)
3124 c_parser_consume_token (parser
);
3129 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
3135 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
3138 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3139 c_parser_consume_token (parser
);
3142 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3147 mark_exp_read (dimen
);
3148 declarator
= build_array_declarator (brace_loc
, dimen
, quals_attrs
,
3149 static_seen
, star_seen
);
3150 if (declarator
== NULL
)
3152 inner
= set_array_declarator_inner (declarator
, inner
);
3153 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3155 else if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3158 struct c_arg_info
*args
;
3159 c_parser_consume_token (parser
);
3160 attrs
= c_parser_attributes (parser
);
3161 args
= c_parser_parms_declarator (parser
, id_present
, attrs
);
3166 inner
= build_function_declarator (args
, inner
);
3167 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3173 /* Parse a parameter list or identifier list, including the closing
3174 parenthesis but not the opening one. ATTRS are the attributes at
3175 the start of the list. ID_LIST_OK is true if an identifier list is
3176 acceptable; such a list must not have attributes at the start. */
3178 static struct c_arg_info
*
3179 c_parser_parms_declarator (c_parser
*parser
, bool id_list_ok
, tree attrs
)
3182 declare_parm_level ();
3183 /* If the list starts with an identifier, it is an identifier list.
3184 Otherwise, it is either a prototype list or an empty list. */
3187 && c_parser_next_token_is (parser
, CPP_NAME
)
3188 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
3190 /* Look ahead to detect typos in type names. */
3191 && c_parser_peek_2nd_token (parser
)->type
!= CPP_NAME
3192 && c_parser_peek_2nd_token (parser
)->type
!= CPP_MULT
3193 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
3194 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_SQUARE
)
3196 tree list
= NULL_TREE
, *nextp
= &list
;
3197 while (c_parser_next_token_is (parser
, CPP_NAME
)
3198 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
3200 *nextp
= build_tree_list (NULL_TREE
,
3201 c_parser_peek_token (parser
)->value
);
3202 nextp
= & TREE_CHAIN (*nextp
);
3203 c_parser_consume_token (parser
);
3204 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
3206 c_parser_consume_token (parser
);
3207 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3209 c_parser_error (parser
, "expected identifier");
3213 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3215 struct c_arg_info
*ret
= build_arg_info ();
3217 c_parser_consume_token (parser
);
3223 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3231 struct c_arg_info
*ret
= c_parser_parms_list_declarator (parser
, attrs
,
3238 /* Parse a parameter list (possibly empty), including the closing
3239 parenthesis but not the opening one. ATTRS are the attributes at
3240 the start of the list. EXPR is NULL or an expression that needs to
3241 be evaluated for the side effects of array size expressions in the
3244 static struct c_arg_info
*
3245 c_parser_parms_list_declarator (c_parser
*parser
, tree attrs
, tree expr
)
3247 bool bad_parm
= false;
3249 /* ??? Following the old parser, forward parameter declarations may
3250 use abstract declarators, and if no real parameter declarations
3251 follow the forward declarations then this is not diagnosed. Also
3252 note as above that attributes are ignored as the only contents of
3253 the parentheses, or as the only contents after forward
3255 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3257 struct c_arg_info
*ret
= build_arg_info ();
3258 c_parser_consume_token (parser
);
3261 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3263 struct c_arg_info
*ret
= build_arg_info ();
3265 if (flag_allow_parameterless_variadic_functions
)
3267 /* F (...) is allowed. */
3268 ret
->types
= NULL_TREE
;
3272 /* Suppress -Wold-style-definition for this case. */
3273 ret
->types
= error_mark_node
;
3274 error_at (c_parser_peek_token (parser
)->location
,
3275 "ISO C requires a named argument before %<...%>");
3277 c_parser_consume_token (parser
);
3278 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3280 c_parser_consume_token (parser
);
3285 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3290 /* Nonempty list of parameters, either terminated with semicolon
3291 (forward declarations; recurse) or with close parenthesis (normal
3292 function) or with ", ... )" (variadic function). */
3295 /* Parse a parameter. */
3296 struct c_parm
*parm
= c_parser_parameter_declaration (parser
, attrs
);
3301 push_parm_decl (parm
, &expr
);
3302 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3305 c_parser_consume_token (parser
);
3306 mark_forward_parm_decls ();
3307 new_attrs
= c_parser_attributes (parser
);
3308 return c_parser_parms_list_declarator (parser
, new_attrs
, expr
);
3310 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3312 c_parser_consume_token (parser
);
3316 return get_parm_info (false, expr
);
3318 if (!c_parser_require (parser
, CPP_COMMA
,
3319 "expected %<;%>, %<,%> or %<)%>"))
3321 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3324 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3326 c_parser_consume_token (parser
);
3327 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3329 c_parser_consume_token (parser
);
3333 return get_parm_info (true, expr
);
3337 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3345 /* Parse a parameter declaration. ATTRS are the attributes at the
3346 start of the declaration if it is the first parameter. */
3348 static struct c_parm
*
3349 c_parser_parameter_declaration (c_parser
*parser
, tree attrs
)
3351 struct c_declspecs
*specs
;
3352 struct c_declarator
*declarator
;
3354 tree postfix_attrs
= NULL_TREE
;
3357 /* Accept #pragmas between parameter declarations. */
3358 while (c_parser_next_token_is (parser
, CPP_PRAGMA
))
3359 c_parser_pragma (parser
, pragma_external
);
3361 if (!c_parser_next_token_starts_declspecs (parser
))
3363 c_token
*token
= c_parser_peek_token (parser
);
3366 c_parser_set_source_position_from_token (token
);
3367 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
3369 error ("unknown type name %qE", token
->value
);
3370 parser
->error
= true;
3372 /* ??? In some Objective-C cases '...' isn't applicable so there
3373 should be a different message. */
3375 c_parser_error (parser
,
3376 "expected declaration specifiers or %<...%>");
3377 c_parser_skip_to_end_of_parameter (parser
);
3380 specs
= build_null_declspecs ();
3383 declspecs_add_attrs (input_location
, specs
, attrs
);
3386 c_parser_declspecs (parser
, specs
, true, true, true, cla_nonabstract_decl
);
3387 finish_declspecs (specs
);
3388 pending_xref_error ();
3389 prefix_attrs
= specs
->attrs
;
3390 specs
->attrs
= NULL_TREE
;
3391 declarator
= c_parser_declarator (parser
,
3392 specs
->typespec_kind
!= ctsk_none
,
3393 C_DTR_PARM
, &dummy
);
3394 if (declarator
== NULL
)
3396 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3399 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3400 postfix_attrs
= c_parser_attributes (parser
);
3401 return build_c_parm (specs
, chainon (postfix_attrs
, prefix_attrs
),
3405 /* Parse a string literal in an asm expression. It should not be
3406 translated, and wide string literals are an error although
3407 permitted by the syntax. This is a GNU extension.
3412 ??? At present, following the old parser, the caller needs to have
3413 set lex_untranslated_string to 1. It would be better to follow the
3414 C++ parser rather than using this kludge. */
3417 c_parser_asm_string_literal (c_parser
*parser
)
3420 int save_flag
= warn_overlength_strings
;
3421 warn_overlength_strings
= 0;
3422 if (c_parser_next_token_is (parser
, CPP_STRING
))
3424 str
= c_parser_peek_token (parser
)->value
;
3425 c_parser_consume_token (parser
);
3427 else if (c_parser_next_token_is (parser
, CPP_WSTRING
))
3429 error_at (c_parser_peek_token (parser
)->location
,
3430 "wide string literal in %<asm%>");
3431 str
= build_string (1, "");
3432 c_parser_consume_token (parser
);
3436 c_parser_error (parser
, "expected string literal");
3439 warn_overlength_strings
= save_flag
;
3443 /* Parse a simple asm expression. This is used in restricted
3444 contexts, where a full expression with inputs and outputs does not
3445 make sense. This is a GNU extension.
3448 asm ( asm-string-literal )
3452 c_parser_simple_asm_expr (c_parser
*parser
)
3455 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
3456 /* ??? Follow the C++ parser rather than using the
3457 lex_untranslated_string kludge. */
3458 parser
->lex_untranslated_string
= true;
3459 c_parser_consume_token (parser
);
3460 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3462 parser
->lex_untranslated_string
= false;
3465 str
= c_parser_asm_string_literal (parser
);
3466 parser
->lex_untranslated_string
= false;
3467 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
3469 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3476 c_parser_attribute_any_word (c_parser
*parser
)
3478 tree attr_name
= NULL_TREE
;
3480 if (c_parser_next_token_is (parser
, CPP_KEYWORD
))
3482 /* ??? See comment above about what keywords are accepted here. */
3484 switch (c_parser_peek_token (parser
)->keyword
)
3515 case RID_TRANSACTION_ATOMIC
:
3516 case RID_TRANSACTION_CANCEL
:
3526 /* Accept __attribute__((__const)) as __attribute__((const)) etc. */
3527 attr_name
= ridpointers
[(int) c_parser_peek_token (parser
)->keyword
];
3529 else if (c_parser_next_token_is (parser
, CPP_NAME
))
3530 attr_name
= c_parser_peek_token (parser
)->value
;
3535 /* Parse (possibly empty) attributes. This is a GNU extension.
3539 attributes attribute
3542 __attribute__ ( ( attribute-list ) )
3546 attribute_list , attrib
3551 any-word ( identifier )
3552 any-word ( identifier , nonempty-expr-list )
3553 any-word ( expr-list )
3555 where the "identifier" must not be declared as a type, and
3556 "any-word" may be any identifier (including one declared as a
3557 type), a reserved word storage class specifier, type specifier or
3558 type qualifier. ??? This still leaves out most reserved keywords
3559 (following the old parser), shouldn't we include them, and why not
3560 allow identifiers declared as types to start the arguments? */
3563 c_parser_attributes (c_parser
*parser
)
3565 tree attrs
= NULL_TREE
;
3566 while (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3568 /* ??? Follow the C++ parser rather than using the
3569 lex_untranslated_string kludge. */
3570 parser
->lex_untranslated_string
= true;
3571 c_parser_consume_token (parser
);
3572 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3574 parser
->lex_untranslated_string
= false;
3577 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3579 parser
->lex_untranslated_string
= false;
3580 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3583 /* Parse the attribute list. */
3584 while (c_parser_next_token_is (parser
, CPP_COMMA
)
3585 || c_parser_next_token_is (parser
, CPP_NAME
)
3586 || c_parser_next_token_is (parser
, CPP_KEYWORD
))
3588 tree attr
, attr_name
, attr_args
;
3589 VEC(tree
,gc
) *expr_list
;
3590 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3592 c_parser_consume_token (parser
);
3596 attr_name
= c_parser_attribute_any_word (parser
);
3597 if (attr_name
== NULL
)
3599 c_parser_consume_token (parser
);
3600 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
3602 attr
= build_tree_list (attr_name
, NULL_TREE
);
3603 attrs
= chainon (attrs
, attr
);
3606 c_parser_consume_token (parser
);
3607 /* Parse the attribute contents. If they start with an
3608 identifier which is followed by a comma or close
3609 parenthesis, then the arguments start with that
3610 identifier; otherwise they are an expression list.
3611 In objective-c the identifier may be a classname. */
3612 if (c_parser_next_token_is (parser
, CPP_NAME
)
3613 && (c_parser_peek_token (parser
)->id_kind
== C_ID_ID
3614 || (c_dialect_objc ()
3615 && c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
3616 && ((c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
)
3617 || (c_parser_peek_2nd_token (parser
)->type
3618 == CPP_CLOSE_PAREN
)))
3620 tree arg1
= c_parser_peek_token (parser
)->value
;
3621 c_parser_consume_token (parser
);
3622 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3623 attr_args
= build_tree_list (NULL_TREE
, arg1
);
3627 c_parser_consume_token (parser
);
3628 expr_list
= c_parser_expr_list (parser
, false, true,
3630 tree_list
= build_tree_list_vec (expr_list
);
3631 attr_args
= tree_cons (NULL_TREE
, arg1
, tree_list
);
3632 release_tree_vector (expr_list
);
3637 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3638 attr_args
= NULL_TREE
;
3641 expr_list
= c_parser_expr_list (parser
, false, true,
3643 attr_args
= build_tree_list_vec (expr_list
);
3644 release_tree_vector (expr_list
);
3647 attr
= build_tree_list (attr_name
, attr_args
);
3648 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3649 c_parser_consume_token (parser
);
3652 parser
->lex_untranslated_string
= false;
3653 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3657 attrs
= chainon (attrs
, attr
);
3659 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3660 c_parser_consume_token (parser
);
3663 parser
->lex_untranslated_string
= false;
3664 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3668 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3669 c_parser_consume_token (parser
);
3672 parser
->lex_untranslated_string
= false;
3673 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3677 parser
->lex_untranslated_string
= false;
3682 /* Parse a type name (C90 6.5.5, C99 6.7.6).
3685 specifier-qualifier-list abstract-declarator[opt]
3688 static struct c_type_name
*
3689 c_parser_type_name (c_parser
*parser
)
3691 struct c_declspecs
*specs
= build_null_declspecs ();
3692 struct c_declarator
*declarator
;
3693 struct c_type_name
*ret
;
3695 c_parser_declspecs (parser
, specs
, false, true, true, cla_prefer_type
);
3696 if (!specs
->declspecs_seen_p
)
3698 c_parser_error (parser
, "expected specifier-qualifier-list");
3701 if (specs
->type
!= error_mark_node
)
3703 pending_xref_error ();
3704 finish_declspecs (specs
);
3706 declarator
= c_parser_declarator (parser
,
3707 specs
->typespec_kind
!= ctsk_none
,
3708 C_DTR_ABSTRACT
, &dummy
);
3709 if (declarator
== NULL
)
3711 ret
= XOBNEW (&parser_obstack
, struct c_type_name
);
3713 ret
->declarator
= declarator
;
3717 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
3720 assignment-expression
3721 { initializer-list }
3722 { initializer-list , }
3725 designation[opt] initializer
3726 initializer-list , designation[opt] initializer
3733 designator-list designator
3740 [ constant-expression ]
3752 [ constant-expression ... constant-expression ]
3754 Any expression without commas is accepted in the syntax for the
3755 constant-expressions, with non-constant expressions rejected later.
3757 This function is only used for top-level initializers; for nested
3758 ones, see c_parser_initval. */
3760 static struct c_expr
3761 c_parser_initializer (c_parser
*parser
)
3763 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
3764 return c_parser_braced_init (parser
, NULL_TREE
, false);
3768 location_t loc
= c_parser_peek_token (parser
)->location
;
3769 ret
= c_parser_expr_no_commas (parser
, NULL
);
3770 if (TREE_CODE (ret
.value
) != STRING_CST
3771 && TREE_CODE (ret
.value
) != COMPOUND_LITERAL_EXPR
)
3772 ret
= default_function_array_read_conversion (loc
, ret
);
3777 /* Parse a braced initializer list. TYPE is the type specified for a
3778 compound literal, and NULL_TREE for other initializers and for
3779 nested braced lists. NESTED_P is true for nested braced lists,
3780 false for the list of a compound literal or the list that is the
3781 top-level initializer in a declaration. */
3783 static struct c_expr
3784 c_parser_braced_init (c_parser
*parser
, tree type
, bool nested_p
)
3787 struct obstack braced_init_obstack
;
3788 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
3789 gcc_obstack_init (&braced_init_obstack
);
3790 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
3791 c_parser_consume_token (parser
);
3793 push_init_level (0, &braced_init_obstack
);
3795 really_start_incremental_init (type
);
3796 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3798 pedwarn (brace_loc
, OPT_Wpedantic
, "ISO C forbids empty initializer braces");
3802 /* Parse a non-empty initializer list, possibly with a trailing
3806 c_parser_initelt (parser
, &braced_init_obstack
);
3809 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3810 c_parser_consume_token (parser
);
3813 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3817 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
3819 ret
.value
= error_mark_node
;
3820 ret
.original_code
= ERROR_MARK
;
3821 ret
.original_type
= NULL
;
3822 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
3823 pop_init_level (0, &braced_init_obstack
);
3824 obstack_free (&braced_init_obstack
, NULL
);
3827 c_parser_consume_token (parser
);
3828 ret
= pop_init_level (0, &braced_init_obstack
);
3829 obstack_free (&braced_init_obstack
, NULL
);
3833 /* Parse a nested initializer, including designators. */
3836 c_parser_initelt (c_parser
*parser
, struct obstack
* braced_init_obstack
)
3838 /* Parse any designator or designator list. A single array
3839 designator may have the subsequent "=" omitted in GNU C, but a
3840 longer list or a structure member designator may not. */
3841 if (c_parser_next_token_is (parser
, CPP_NAME
)
3842 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
3844 /* Old-style structure member designator. */
3845 set_init_label (c_parser_peek_token (parser
)->value
,
3846 braced_init_obstack
);
3847 /* Use the colon as the error location. */
3848 pedwarn (c_parser_peek_2nd_token (parser
)->location
, OPT_Wpedantic
,
3849 "obsolete use of designated initializer with %<:%>");
3850 c_parser_consume_token (parser
);
3851 c_parser_consume_token (parser
);
3855 /* des_seen is 0 if there have been no designators, 1 if there
3856 has been a single array designator and 2 otherwise. */
3858 /* Location of a designator. */
3859 location_t des_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
3860 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
)
3861 || c_parser_next_token_is (parser
, CPP_DOT
))
3863 int des_prev
= des_seen
;
3865 des_loc
= c_parser_peek_token (parser
)->location
;
3868 if (c_parser_next_token_is (parser
, CPP_DOT
))
3871 c_parser_consume_token (parser
);
3872 if (c_parser_next_token_is (parser
, CPP_NAME
))
3874 set_init_label (c_parser_peek_token (parser
)->value
,
3875 braced_init_obstack
);
3876 c_parser_consume_token (parser
);
3881 init
.value
= error_mark_node
;
3882 init
.original_code
= ERROR_MARK
;
3883 init
.original_type
= NULL
;
3884 c_parser_error (parser
, "expected identifier");
3885 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3886 process_init_element (init
, false, braced_init_obstack
);
3893 location_t ellipsis_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
3894 /* ??? Following the old parser, [ objc-receiver
3895 objc-message-args ] is accepted as an initializer,
3896 being distinguished from a designator by what follows
3897 the first assignment expression inside the square
3898 brackets, but after a first array designator a
3899 subsequent square bracket is for Objective-C taken to
3900 start an expression, using the obsolete form of
3901 designated initializer without '=', rather than
3902 possibly being a second level of designation: in LALR
3903 terms, the '[' is shifted rather than reducing
3904 designator to designator-list. */
3905 if (des_prev
== 1 && c_dialect_objc ())
3907 des_seen
= des_prev
;
3910 if (des_prev
== 0 && c_dialect_objc ())
3912 /* This might be an array designator or an
3913 Objective-C message expression. If the former,
3914 continue parsing here; if the latter, parse the
3915 remainder of the initializer given the starting
3916 primary-expression. ??? It might make sense to
3917 distinguish when des_prev == 1 as well; see
3918 previous comment. */
3920 struct c_expr mexpr
;
3921 c_parser_consume_token (parser
);
3922 if (c_parser_peek_token (parser
)->type
== CPP_NAME
3923 && ((c_parser_peek_token (parser
)->id_kind
3925 || (c_parser_peek_token (parser
)->id_kind
3926 == C_ID_CLASSNAME
)))
3928 /* Type name receiver. */
3929 tree id
= c_parser_peek_token (parser
)->value
;
3930 c_parser_consume_token (parser
);
3931 rec
= objc_get_class_reference (id
);
3932 goto parse_message_args
;
3934 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
3935 mark_exp_read (first
);
3936 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
)
3937 || c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3938 goto array_desig_after_first
;
3939 /* Expression receiver. So far only one part
3940 without commas has been parsed; there might be
3941 more of the expression. */
3943 while (c_parser_next_token_is (parser
, CPP_COMMA
))
3946 location_t comma_loc
, exp_loc
;
3947 comma_loc
= c_parser_peek_token (parser
)->location
;
3948 c_parser_consume_token (parser
);
3949 exp_loc
= c_parser_peek_token (parser
)->location
;
3950 next
= c_parser_expr_no_commas (parser
, NULL
);
3951 next
= default_function_array_read_conversion (exp_loc
,
3953 rec
= build_compound_expr (comma_loc
, rec
, next
.value
);
3956 /* Now parse the objc-message-args. */
3957 args
= c_parser_objc_message_args (parser
);
3958 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3961 = objc_build_message_expr (rec
, args
);
3962 mexpr
.original_code
= ERROR_MARK
;
3963 mexpr
.original_type
= NULL
;
3964 /* Now parse and process the remainder of the
3965 initializer, starting with this message
3966 expression as a primary-expression. */
3967 c_parser_initval (parser
, &mexpr
, braced_init_obstack
);
3970 c_parser_consume_token (parser
);
3971 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
3972 mark_exp_read (first
);
3973 array_desig_after_first
:
3974 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3976 ellipsis_loc
= c_parser_peek_token (parser
)->location
;
3977 c_parser_consume_token (parser
);
3978 second
= c_parser_expr_no_commas (parser
, NULL
).value
;
3979 mark_exp_read (second
);
3983 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3985 c_parser_consume_token (parser
);
3986 set_init_index (first
, second
, braced_init_obstack
);
3988 pedwarn (ellipsis_loc
, OPT_Wpedantic
,
3989 "ISO C forbids specifying range of elements to initialize");
3992 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3998 if (c_parser_next_token_is (parser
, CPP_EQ
))
4001 pedwarn (des_loc
, OPT_Wpedantic
,
4002 "ISO C90 forbids specifying subobject to initialize");
4003 c_parser_consume_token (parser
);
4008 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
4009 "obsolete use of designated initializer without %<=%>");
4013 init
.value
= error_mark_node
;
4014 init
.original_code
= ERROR_MARK
;
4015 init
.original_type
= NULL
;
4016 c_parser_error (parser
, "expected %<=%>");
4017 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
4018 process_init_element (init
, false, braced_init_obstack
);
4024 c_parser_initval (parser
, NULL
, braced_init_obstack
);
4027 /* Parse a nested initializer; as c_parser_initializer but parses
4028 initializers within braced lists, after any designators have been
4029 applied. If AFTER is not NULL then it is an Objective-C message
4030 expression which is the primary-expression starting the
4034 c_parser_initval (c_parser
*parser
, struct c_expr
*after
,
4035 struct obstack
* braced_init_obstack
)
4038 gcc_assert (!after
|| c_dialect_objc ());
4039 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
) && !after
)
4040 init
= c_parser_braced_init (parser
, NULL_TREE
, true);
4043 location_t loc
= c_parser_peek_token (parser
)->location
;
4044 init
= c_parser_expr_no_commas (parser
, after
);
4045 if (init
.value
!= NULL_TREE
4046 && TREE_CODE (init
.value
) != STRING_CST
4047 && TREE_CODE (init
.value
) != COMPOUND_LITERAL_EXPR
)
4048 init
= default_function_array_read_conversion (loc
, init
);
4050 process_init_element (init
, false, braced_init_obstack
);
4053 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
4057 { block-item-list[opt] }
4058 { label-declarations block-item-list }
4062 block-item-list block-item
4074 { label-declarations block-item-list }
4077 __extension__ nested-declaration
4078 nested-function-definition
4082 label-declarations label-declaration
4085 __label__ identifier-list ;
4087 Allowing the mixing of declarations and code is new in C99. The
4088 GNU syntax also permits (not shown above) labels at the end of
4089 compound statements, which yield an error. We don't allow labels
4090 on declarations; this might seem like a natural extension, but
4091 there would be a conflict between attributes on the label and
4092 prefix attributes on the declaration. ??? The syntax follows the
4093 old parser in requiring something after label declarations.
4094 Although they are erroneous if the labels declared aren't defined,
4095 is it useful for the syntax to be this way?
4107 c_parser_compound_statement (c_parser
*parser
)
4110 location_t brace_loc
;
4111 brace_loc
= c_parser_peek_token (parser
)->location
;
4112 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
4114 /* Ensure a scope is entered and left anyway to avoid confusion
4115 if we have just prepared to enter a function body. */
4116 stmt
= c_begin_compound_stmt (true);
4117 c_end_compound_stmt (brace_loc
, stmt
, true);
4118 return error_mark_node
;
4120 stmt
= c_begin_compound_stmt (true);
4121 c_parser_compound_statement_nostart (parser
);
4122 return c_end_compound_stmt (brace_loc
, stmt
, true);
4125 /* Parse a compound statement except for the opening brace. This is
4126 used for parsing both compound statements and statement expressions
4127 (which follow different paths to handling the opening). */
4130 c_parser_compound_statement_nostart (c_parser
*parser
)
4132 bool last_stmt
= false;
4133 bool last_label
= false;
4134 bool save_valid_for_pragma
= valid_location_for_stdc_pragma_p ();
4135 location_t label_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4136 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4138 c_parser_consume_token (parser
);
4141 mark_valid_location_for_stdc_pragma (true);
4142 if (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
4144 /* Read zero or more forward-declarations for labels that nested
4145 functions can jump to. */
4146 mark_valid_location_for_stdc_pragma (false);
4147 while (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
4149 label_loc
= c_parser_peek_token (parser
)->location
;
4150 c_parser_consume_token (parser
);
4151 /* Any identifiers, including those declared as type names,
4156 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
4158 c_parser_error (parser
, "expected identifier");
4162 = declare_label (c_parser_peek_token (parser
)->value
);
4163 C_DECLARED_LABEL_FLAG (label
) = 1;
4164 add_stmt (build_stmt (label_loc
, DECL_EXPR
, label
));
4165 c_parser_consume_token (parser
);
4166 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4167 c_parser_consume_token (parser
);
4171 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4173 pedwarn (label_loc
, OPT_Wpedantic
, "ISO C forbids label declarations");
4175 /* We must now have at least one statement, label or declaration. */
4176 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4178 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4179 c_parser_error (parser
, "expected declaration or statement");
4180 c_parser_consume_token (parser
);
4183 /* Process all #pragma's just after the opening brace. This
4184 handles #pragma upc, which can only appear just after
4185 the opening brace, when it appears within a function body. */
4186 push_upc_consistency_mode ();
4187 permit_pragma_upc ();
4188 while (c_parser_next_token_is (parser
, CPP_PRAGMA
))
4190 location_t loc ATTRIBUTE_UNUSED
= c_parser_peek_token (parser
)->location
;
4191 if (c_parser_pragma (parser
, pragma_compound
))
4192 last_label
= false, last_stmt
= true;
4193 parser
->error
= false;
4196 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
4198 location_t loc
= c_parser_peek_token (parser
)->location
;
4199 if (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4200 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4201 || (c_parser_next_token_is (parser
, CPP_NAME
)
4202 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4204 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
4205 label_loc
= c_parser_peek_2nd_token (parser
)->location
;
4207 label_loc
= c_parser_peek_token (parser
)->location
;
4210 mark_valid_location_for_stdc_pragma (false);
4211 c_parser_label (parser
);
4213 else if (!last_label
4214 && c_parser_next_tokens_start_declaration (parser
))
4217 mark_valid_location_for_stdc_pragma (false);
4218 c_parser_declaration_or_fndef (parser
, true, true, true, true, true, NULL
);
4221 (pedantic
&& !flag_isoc99
)
4223 : OPT_Wdeclaration_after_statement
,
4224 "ISO C90 forbids mixed declarations and code");
4227 else if (!last_label
4228 && c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
4230 /* __extension__ can start a declaration, but is also an
4231 unary operator that can start an expression. Consume all
4232 but the last of a possible series of __extension__ to
4234 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
4235 && (c_parser_peek_2nd_token (parser
)->keyword
4237 c_parser_consume_token (parser
);
4238 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
4241 ext
= disable_extension_diagnostics ();
4242 c_parser_consume_token (parser
);
4244 mark_valid_location_for_stdc_pragma (false);
4245 c_parser_declaration_or_fndef (parser
, true, true, true, true,
4247 /* Following the old parser, __extension__ does not
4248 disable this diagnostic. */
4249 restore_extension_diagnostics (ext
);
4251 pedwarn_c90 (loc
, (pedantic
&& !flag_isoc99
)
4253 : OPT_Wdeclaration_after_statement
,
4254 "ISO C90 forbids mixed declarations and code");
4260 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
4262 /* External pragmas, and some omp pragmas, are not associated
4263 with regular c code, and so are not to be considered statements
4264 syntactically. This ensures that the user doesn't put them
4265 places that would turn into syntax errors if the directive
4267 if (c_parser_pragma (parser
, pragma_compound
))
4268 last_label
= false, last_stmt
= true;
4270 else if (c_parser_next_token_is (parser
, CPP_EOF
))
4272 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4273 c_parser_error (parser
, "expected declaration or statement");
4276 else if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
4278 if (parser
->in_if_block
)
4280 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4281 error_at (loc
, """expected %<}%> before %<else%>");
4286 error_at (loc
, "%<else%> without a previous %<if%>");
4287 c_parser_consume_token (parser
);
4296 mark_valid_location_for_stdc_pragma (false);
4297 c_parser_statement_after_labels (parser
);
4300 parser
->error
= false;
4303 error_at (label_loc
, "label at end of compound statement");
4304 c_parser_consume_token (parser
);
4305 pop_upc_consistency_mode ();
4306 /* Restore the value we started with. */
4307 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4310 /* Parse a label (C90 6.6.1, C99 6.8.1).
4313 identifier : attributes[opt]
4314 case constant-expression :
4320 case constant-expression ... constant-expression :
4322 The use of attributes on labels is a GNU extension. The syntax in
4323 GNU C accepts any expressions without commas, non-constant
4324 expressions being rejected later. */
4327 c_parser_label (c_parser
*parser
)
4329 location_t loc1
= c_parser_peek_token (parser
)->location
;
4330 tree label
= NULL_TREE
;
4331 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
4334 c_parser_consume_token (parser
);
4335 exp1
= c_parser_expr_no_commas (parser
, NULL
).value
;
4336 if (c_parser_next_token_is (parser
, CPP_COLON
))
4338 c_parser_consume_token (parser
);
4339 label
= do_case (loc1
, exp1
, NULL_TREE
);
4341 else if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
4343 c_parser_consume_token (parser
);
4344 exp2
= c_parser_expr_no_commas (parser
, NULL
).value
;
4345 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4346 label
= do_case (loc1
, exp1
, exp2
);
4349 c_parser_error (parser
, "expected %<:%> or %<...%>");
4351 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
4353 c_parser_consume_token (parser
);
4354 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4355 label
= do_case (loc1
, NULL_TREE
, NULL_TREE
);
4359 tree name
= c_parser_peek_token (parser
)->value
;
4362 location_t loc2
= c_parser_peek_token (parser
)->location
;
4363 gcc_assert (c_parser_next_token_is (parser
, CPP_NAME
));
4364 c_parser_consume_token (parser
);
4365 gcc_assert (c_parser_next_token_is (parser
, CPP_COLON
));
4366 c_parser_consume_token (parser
);
4367 attrs
= c_parser_attributes (parser
);
4368 tlab
= define_label (loc2
, name
);
4371 decl_attributes (&tlab
, attrs
, 0);
4372 label
= add_stmt (build_stmt (loc1
, LABEL_EXPR
, tlab
));
4377 if (c_parser_next_tokens_start_declaration (parser
))
4379 error_at (c_parser_peek_token (parser
)->location
,
4380 "a label can only be part of a statement and "
4381 "a declaration is not a statement");
4382 c_parser_declaration_or_fndef (parser
, /*fndef_ok*/ false,
4383 /*static_assert_ok*/ true,
4384 /*empty_ok*/ true, /*nested*/ true,
4385 /*start_attr_ok*/ true, NULL
);
4390 /* Parse a statement (C90 6.6, C99 6.8).
4395 expression-statement
4403 expression-statement:
4406 selection-statement:
4410 iteration-statement:
4419 return expression[opt] ;
4432 objc-throw-statement
4433 objc-try-catch-statement
4434 objc-synchronized-statement
4436 objc-throw-statement:
4450 parallel-for-construct
4451 parallel-sections-construct
4458 parallel-directive structured-block
4461 for-directive iteration-statement
4464 sections-directive section-scope
4467 single-directive structured-block
4469 parallel-for-construct:
4470 parallel-for-directive iteration-statement
4472 parallel-sections-construct:
4473 parallel-sections-directive section-scope
4476 master-directive structured-block
4479 critical-directive structured-block
4482 atomic-directive expression-statement
4485 ordered-directive structured-block
4487 Transactional Memory:
4490 transaction-statement
4491 transaction-cancel-statement
4495 c_parser_statement (c_parser
*parser
)
4497 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4498 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4499 || (c_parser_next_token_is (parser
, CPP_NAME
)
4500 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4501 c_parser_label (parser
);
4502 c_parser_statement_after_labels (parser
);
4505 /* Parse a statement, other than a labeled statement. */
4508 c_parser_statement_after_labels (c_parser
*parser
)
4510 location_t loc
= c_parser_peek_token (parser
)->location
;
4511 tree stmt
= NULL_TREE
;
4512 bool in_if_block
= parser
->in_if_block
;
4513 parser
->in_if_block
= false;
4514 switch (c_parser_peek_token (parser
)->type
)
4516 case CPP_OPEN_BRACE
:
4517 add_stmt (c_parser_compound_statement (parser
));
4520 switch (c_parser_peek_token (parser
)->keyword
)
4523 c_parser_if_statement (parser
);
4526 c_parser_switch_statement (parser
);
4529 c_parser_while_statement (parser
);
4532 c_parser_do_statement (parser
);
4535 c_parser_for_statement (parser
);
4538 c_parser_consume_token (parser
);
4539 if (c_parser_next_token_is (parser
, CPP_NAME
))
4541 stmt
= c_finish_goto_label (loc
,
4542 c_parser_peek_token (parser
)->value
);
4543 c_parser_consume_token (parser
);
4545 else if (c_parser_next_token_is (parser
, CPP_MULT
))
4549 c_parser_consume_token (parser
);
4550 val
= c_parser_expression (parser
).value
;
4551 mark_exp_read (val
);
4552 stmt
= c_finish_goto_ptr (loc
, val
);
4555 c_parser_error (parser
, "expected identifier or %<*%>");
4556 goto expect_semicolon
;
4558 c_parser_consume_token (parser
);
4559 stmt
= c_finish_bc_stmt (loc
, &c_cont_label
, false);
4560 goto expect_semicolon
;
4562 c_parser_consume_token (parser
);
4563 stmt
= c_finish_bc_stmt (loc
, &c_break_label
, true);
4564 goto expect_semicolon
;
4566 c_parser_consume_token (parser
);
4567 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4569 stmt
= c_finish_return (loc
, NULL_TREE
, NULL_TREE
);
4570 c_parser_consume_token (parser
);
4574 struct c_expr expr
= c_parser_expression_conv (parser
);
4575 mark_exp_read (expr
.value
);
4576 stmt
= c_finish_return (loc
, expr
.value
, expr
.original_type
);
4577 goto expect_semicolon
;
4581 stmt
= c_parser_asm_statement (parser
);
4583 case RID_TRANSACTION_ATOMIC
:
4584 case RID_TRANSACTION_RELAXED
:
4585 stmt
= c_parser_transaction (parser
,
4586 c_parser_peek_token (parser
)->keyword
);
4588 case RID_TRANSACTION_CANCEL
:
4589 stmt
= c_parser_transaction_cancel (parser
);
4590 goto expect_semicolon
;
4592 gcc_assert (c_dialect_objc ());
4593 c_parser_consume_token (parser
);
4594 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4596 stmt
= objc_build_throw_stmt (loc
, NULL_TREE
);
4597 c_parser_consume_token (parser
);
4601 tree expr
= c_parser_expression (parser
).value
;
4602 expr
= c_fully_fold (expr
, false, NULL
);
4603 stmt
= objc_build_throw_stmt (loc
, expr
);
4604 goto expect_semicolon
;
4608 gcc_assert (c_dialect_objc ());
4609 c_parser_objc_try_catch_finally_statement (parser
);
4611 case RID_AT_SYNCHRONIZED
:
4612 gcc_assert (c_dialect_objc ());
4613 c_parser_objc_synchronized_statement (parser
);
4615 case RID_UPC_FORALL
:
4616 gcc_assert (c_dialect_upc ());
4617 c_parser_upc_forall_statement (parser
);
4619 case RID_UPC_NOTIFY
:
4620 gcc_assert (c_dialect_upc ());
4621 c_parser_upc_sync_statement (parser
, UPC_SYNC_NOTIFY_OP
);
4622 goto expect_semicolon
;
4624 gcc_assert (c_dialect_upc ());
4625 c_parser_upc_sync_statement (parser
, UPC_SYNC_WAIT_OP
);
4626 goto expect_semicolon
;
4627 case RID_UPC_BARRIER
:
4628 gcc_assert (c_dialect_upc ());
4629 c_parser_upc_sync_statement (parser
, UPC_SYNC_BARRIER_OP
);
4630 goto expect_semicolon
;
4636 c_parser_consume_token (parser
);
4638 case CPP_CLOSE_PAREN
:
4639 case CPP_CLOSE_SQUARE
:
4640 /* Avoid infinite loop in error recovery:
4641 c_parser_skip_until_found stops at a closing nesting
4642 delimiter without consuming it, but here we need to consume
4643 it to proceed further. */
4644 c_parser_error (parser
, "expected statement");
4645 c_parser_consume_token (parser
);
4648 c_parser_pragma (parser
, pragma_stmt
);
4652 stmt
= c_finish_expr_stmt (loc
, c_parser_expression_conv (parser
).value
);
4654 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4657 /* Two cases cannot and do not have line numbers associated: If stmt
4658 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
4659 cannot hold line numbers. But that's OK because the statement
4660 will either be changed to a MODIFY_EXPR during gimplification of
4661 the statement expr, or discarded. If stmt was compound, but
4662 without new variables, we will have skipped the creation of a
4663 BIND and will have a bare STATEMENT_LIST. But that's OK because
4664 (recursively) all of the component statements should already have
4665 line numbers assigned. ??? Can we discard no-op statements
4667 if (CAN_HAVE_LOCATION_P (stmt
)
4668 && EXPR_LOCATION (stmt
) == UNKNOWN_LOCATION
)
4669 SET_EXPR_LOCATION (stmt
, loc
);
4671 parser
->in_if_block
= in_if_block
;
4674 /* Parse the condition from an if, do, while or for statements. */
4677 c_parser_condition (c_parser
*parser
)
4679 location_t loc ATTRIBUTE_UNUSED
= c_parser_peek_token (parser
)->location
;
4681 cond
= c_parser_expression_conv (parser
).value
;
4682 cond
= c_objc_common_truthvalue_conversion (loc
, cond
);
4683 cond
= c_fully_fold (cond
, false, NULL
);
4684 if (warn_sequence_point
)
4685 verify_sequence_points (cond
);
4689 /* Parse a parenthesized condition from an if, do or while statement.
4695 c_parser_paren_condition (c_parser
*parser
)
4698 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4699 return error_mark_node
;
4700 cond
= c_parser_condition (parser
);
4701 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4705 /* Parse a statement which is a block in C99. */
4708 c_parser_c99_block_statement (c_parser
*parser
)
4710 tree block
= c_begin_compound_stmt (flag_isoc99
);
4711 location_t loc
= c_parser_peek_token (parser
)->location
;
4712 c_parser_statement (parser
);
4713 return c_end_compound_stmt (loc
, block
, flag_isoc99
);
4716 /* Parse the body of an if statement. This is just parsing a
4717 statement but (a) it is a block in C99, (b) we track whether the
4718 body is an if statement for the sake of -Wparentheses warnings, (c)
4719 we handle an empty body specially for the sake of -Wempty-body
4720 warnings, and (d) we call parser_compound_statement directly
4721 because c_parser_statement_after_labels resets
4722 parser->in_if_block. */
4725 c_parser_if_body (c_parser
*parser
, bool *if_p
)
4727 tree block
= c_begin_compound_stmt (flag_isoc99
);
4728 location_t body_loc
= c_parser_peek_token (parser
)->location
;
4729 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4730 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4731 || (c_parser_next_token_is (parser
, CPP_NAME
)
4732 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4733 c_parser_label (parser
);
4734 *if_p
= c_parser_next_token_is_keyword (parser
, RID_IF
);
4735 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4737 location_t loc
= c_parser_peek_token (parser
)->location
;
4738 add_stmt (build_empty_stmt (loc
));
4739 c_parser_consume_token (parser
);
4740 if (!c_parser_next_token_is_keyword (parser
, RID_ELSE
))
4741 warning_at (loc
, OPT_Wempty_body
,
4742 "suggest braces around empty body in an %<if%> statement");
4744 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4745 add_stmt (c_parser_compound_statement (parser
));
4747 c_parser_statement_after_labels (parser
);
4748 return c_end_compound_stmt (body_loc
, block
, flag_isoc99
);
4751 /* Parse the else body of an if statement. This is just parsing a
4752 statement but (a) it is a block in C99, (b) we handle an empty body
4753 specially for the sake of -Wempty-body warnings. */
4756 c_parser_else_body (c_parser
*parser
)
4758 location_t else_loc
= c_parser_peek_token (parser
)->location
;
4759 tree block
= c_begin_compound_stmt (flag_isoc99
);
4760 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4761 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4762 || (c_parser_next_token_is (parser
, CPP_NAME
)
4763 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4764 c_parser_label (parser
);
4765 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4767 location_t loc
= c_parser_peek_token (parser
)->location
;
4770 "suggest braces around empty body in an %<else%> statement");
4771 add_stmt (build_empty_stmt (loc
));
4772 c_parser_consume_token (parser
);
4775 c_parser_statement_after_labels (parser
);
4776 return c_end_compound_stmt (else_loc
, block
, flag_isoc99
);
4779 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
4782 if ( expression ) statement
4783 if ( expression ) statement else statement
4787 c_parser_if_statement (c_parser
*parser
)
4792 bool first_if
= false;
4793 tree first_body
, second_body
;
4796 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_IF
));
4797 c_parser_consume_token (parser
);
4798 block
= c_begin_compound_stmt (flag_isoc99
);
4799 loc
= c_parser_peek_token (parser
)->location
;
4800 cond
= c_parser_paren_condition (parser
);
4801 in_if_block
= parser
->in_if_block
;
4802 parser
->in_if_block
= true;
4803 first_body
= c_parser_if_body (parser
, &first_if
);
4804 parser
->in_if_block
= in_if_block
;
4805 if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
4807 c_parser_consume_token (parser
);
4808 second_body
= c_parser_else_body (parser
);
4811 second_body
= NULL_TREE
;
4812 c_finish_if_stmt (loc
, cond
, first_body
, second_body
, first_if
);
4813 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
4816 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
4819 switch (expression) statement
4823 c_parser_switch_statement (c_parser
*parser
)
4825 tree block
, expr
, body
, save_break
;
4826 location_t switch_loc
= c_parser_peek_token (parser
)->location
;
4827 location_t switch_cond_loc
;
4828 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SWITCH
));
4829 c_parser_consume_token (parser
);
4830 block
= c_begin_compound_stmt (flag_isoc99
);
4831 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4833 switch_cond_loc
= c_parser_peek_token (parser
)->location
;
4834 expr
= c_parser_expression (parser
).value
;
4835 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4839 switch_cond_loc
= UNKNOWN_LOCATION
;
4840 expr
= error_mark_node
;
4842 c_start_case (switch_loc
, switch_cond_loc
, expr
);
4843 save_break
= c_break_label
;
4844 c_break_label
= NULL_TREE
;
4845 body
= c_parser_c99_block_statement (parser
);
4846 c_finish_case (body
);
4849 location_t here
= c_parser_peek_token (parser
)->location
;
4850 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_break_label
);
4851 SET_EXPR_LOCATION (t
, here
);
4854 c_break_label
= save_break
;
4855 add_stmt (c_end_compound_stmt (switch_loc
, block
, flag_isoc99
));
4858 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
4861 while (expression) statement
4865 c_parser_while_statement (c_parser
*parser
)
4867 tree block
, cond
, body
, save_break
, save_cont
;
4869 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_WHILE
));
4870 c_parser_consume_token (parser
);
4871 block
= c_begin_compound_stmt (flag_isoc99
);
4872 loc
= c_parser_peek_token (parser
)->location
;
4873 cond
= c_parser_paren_condition (parser
);
4874 save_break
= c_break_label
;
4875 c_break_label
= NULL_TREE
;
4876 save_cont
= c_cont_label
;
4877 c_cont_label
= NULL_TREE
;
4878 body
= c_parser_c99_block_statement (parser
);
4879 c_finish_loop (loc
, cond
, NULL
, body
, c_break_label
, c_cont_label
, true);
4880 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
4881 c_break_label
= save_break
;
4882 c_cont_label
= save_cont
;
4885 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
4888 do statement while ( expression ) ;
4892 c_parser_do_statement (c_parser
*parser
)
4894 tree block
, cond
, body
, save_break
, save_cont
, new_break
, new_cont
;
4896 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_DO
));
4897 c_parser_consume_token (parser
);
4898 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4899 warning_at (c_parser_peek_token (parser
)->location
,
4901 "suggest braces around empty body in %<do%> statement");
4902 block
= c_begin_compound_stmt (flag_isoc99
);
4903 loc
= c_parser_peek_token (parser
)->location
;
4904 save_break
= c_break_label
;
4905 c_break_label
= NULL_TREE
;
4906 save_cont
= c_cont_label
;
4907 c_cont_label
= NULL_TREE
;
4908 body
= c_parser_c99_block_statement (parser
);
4909 c_parser_require_keyword (parser
, RID_WHILE
, "expected %<while%>");
4910 new_break
= c_break_label
;
4911 c_break_label
= save_break
;
4912 new_cont
= c_cont_label
;
4913 c_cont_label
= save_cont
;
4914 cond
= c_parser_paren_condition (parser
);
4915 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
4916 c_parser_skip_to_end_of_block_or_statement (parser
);
4917 c_finish_loop (loc
, cond
, NULL
, body
, new_break
, new_cont
, false);
4918 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
4921 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
4924 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
4925 for ( nested-declaration expression[opt] ; expression[opt] ) statement
4927 The form with a declaration is new in C99.
4929 ??? In accordance with the old parser, the declaration may be a
4930 nested function, which is then rejected in check_for_loop_decls,
4931 but does it make any sense for this to be included in the grammar?
4932 Note in particular that the nested function does not include a
4933 trailing ';', whereas the "declaration" production includes one.
4934 Also, can we reject bad declarations earlier and cheaper than
4935 check_for_loop_decls?
4937 In Objective-C, there are two additional variants:
4940 for ( expression in expresssion ) statement
4941 for ( declaration in expression ) statement
4943 This is inconsistent with C, because the second variant is allowed
4944 even if c99 is not enabled.
4946 The rest of the comment documents these Objective-C foreach-statement.
4948 Here is the canonical example of the first variant:
4949 for (object in array) { do something with object }
4950 we call the first expression ("object") the "object_expression" and
4951 the second expression ("array") the "collection_expression".
4952 object_expression must be an lvalue of type "id" (a generic Objective-C
4953 object) because the loop works by assigning to object_expression the
4954 various objects from the collection_expression. collection_expression
4955 must evaluate to something of type "id" which responds to the method
4956 countByEnumeratingWithState:objects:count:.
4958 The canonical example of the second variant is:
4959 for (id object in array) { do something with object }
4960 which is completely equivalent to
4963 for (object in array) { do something with object }
4965 Note that initizializing 'object' in some way (eg, "for ((object =
4966 xxx) in array) { do something with object }") is possibly
4967 technically valid, but completely pointless as 'object' will be
4968 assigned to something else as soon as the loop starts. We should
4969 most likely reject it (TODO).
4971 The beginning of the Objective-C foreach-statement looks exactly
4972 like the beginning of the for-statement, and we can tell it is a
4973 foreach-statement only because the initial declaration or
4974 expression is terminated by 'in' instead of ';'.
4978 c_parser_for_statement (c_parser
*parser
)
4980 tree block
, cond
, incr
, save_break
, save_cont
, body
;
4981 /* The following are only used when parsing an ObjC foreach statement. */
4982 tree object_expression
;
4983 /* Silence the bogus uninitialized warning. */
4984 tree collection_expression
= NULL
;
4985 location_t loc
= c_parser_peek_token (parser
)->location
;
4986 location_t for_loc
= c_parser_peek_token (parser
)->location
;
4987 bool is_foreach_statement
= false;
4988 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_FOR
));
4989 c_parser_consume_token (parser
);
4990 /* Open a compound statement in Objective-C as well, just in case this is
4991 as foreach expression. */
4992 block
= c_begin_compound_stmt (flag_isoc99
|| c_dialect_objc ());
4993 cond
= error_mark_node
;
4994 incr
= error_mark_node
;
4995 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4997 /* Parse the initialization declaration or expression. */
4998 object_expression
= error_mark_node
;
4999 parser
->objc_could_be_foreach_context
= c_dialect_objc ();
5000 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5002 parser
->objc_could_be_foreach_context
= false;
5003 c_parser_consume_token (parser
);
5004 c_finish_expr_stmt (loc
, NULL_TREE
);
5006 else if (c_parser_next_tokens_start_declaration (parser
))
5008 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
5009 &object_expression
);
5010 parser
->objc_could_be_foreach_context
= false;
5012 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5014 c_parser_consume_token (parser
);
5015 is_foreach_statement
= true;
5016 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
5017 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
5020 check_for_loop_decls (for_loc
, flag_isoc99
);
5022 else if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
5024 /* __extension__ can start a declaration, but is also an
5025 unary operator that can start an expression. Consume all
5026 but the last of a possible series of __extension__ to
5028 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
5029 && (c_parser_peek_2nd_token (parser
)->keyword
5031 c_parser_consume_token (parser
);
5032 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
5035 ext
= disable_extension_diagnostics ();
5036 c_parser_consume_token (parser
);
5037 c_parser_declaration_or_fndef (parser
, true, true, true, true,
5038 true, &object_expression
);
5039 parser
->objc_could_be_foreach_context
= false;
5041 restore_extension_diagnostics (ext
);
5042 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5044 c_parser_consume_token (parser
);
5045 is_foreach_statement
= true;
5046 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
5047 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
5050 check_for_loop_decls (for_loc
, flag_isoc99
);
5059 tree init_expression
;
5060 init_expression
= c_parser_expression (parser
).value
;
5061 parser
->objc_could_be_foreach_context
= false;
5062 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5064 c_parser_consume_token (parser
);
5065 is_foreach_statement
= true;
5066 if (! lvalue_p (init_expression
))
5067 c_parser_error (parser
, "invalid iterating variable in fast enumeration");
5068 object_expression
= c_fully_fold (init_expression
, false, NULL
);
5072 c_finish_expr_stmt (loc
, init_expression
);
5073 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5077 /* Parse the loop condition. In the case of a foreach
5078 statement, there is no loop condition. */
5079 gcc_assert (!parser
->objc_could_be_foreach_context
);
5080 if (!is_foreach_statement
)
5082 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5084 c_parser_consume_token (parser
);
5089 cond
= c_parser_condition (parser
);
5090 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5093 /* Parse the increment expression (the third expression in a
5094 for-statement). In the case of a foreach-statement, this is
5095 the expression that follows the 'in'. */
5096 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
5098 if (is_foreach_statement
)
5100 c_parser_error (parser
, "missing collection in fast enumeration");
5101 collection_expression
= error_mark_node
;
5104 incr
= c_process_expr_stmt (loc
, NULL_TREE
);
5108 if (is_foreach_statement
)
5109 collection_expression
= c_fully_fold (c_parser_expression (parser
).value
,
5112 incr
= c_process_expr_stmt (loc
, c_parser_expression (parser
).value
);
5114 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5116 save_break
= c_break_label
;
5117 c_break_label
= NULL_TREE
;
5118 save_cont
= c_cont_label
;
5119 c_cont_label
= NULL_TREE
;
5120 body
= c_parser_c99_block_statement (parser
);
5121 if (is_foreach_statement
)
5122 objc_finish_foreach_loop (loc
, object_expression
, collection_expression
, body
, c_break_label
, c_cont_label
);
5124 c_finish_loop (loc
, cond
, incr
, body
, c_break_label
, c_cont_label
, true);
5125 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
|| c_dialect_objc ()));
5126 c_break_label
= save_break
;
5127 c_cont_label
= save_cont
;
5130 /* Parse an asm statement, a GNU extension. This is a full-blown asm
5131 statement with inputs, outputs, clobbers, and volatile tag
5135 asm type-qualifier[opt] ( asm-argument ) ;
5136 asm type-qualifier[opt] goto ( asm-goto-argument ) ;
5140 asm-string-literal : asm-operands[opt]
5141 asm-string-literal : asm-operands[opt] : asm-operands[opt]
5142 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers[opt]
5145 asm-string-literal : : asm-operands[opt] : asm-clobbers[opt] \
5148 Qualifiers other than volatile are accepted in the syntax but
5152 c_parser_asm_statement (c_parser
*parser
)
5154 tree quals
, str
, outputs
, inputs
, clobbers
, labels
, ret
;
5155 bool simple
, is_goto
;
5156 location_t asm_loc
= c_parser_peek_token (parser
)->location
;
5157 int section
, nsections
;
5159 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
5160 c_parser_consume_token (parser
);
5161 if (c_parser_next_token_is_keyword (parser
, RID_VOLATILE
))
5163 quals
= c_parser_peek_token (parser
)->value
;
5164 c_parser_consume_token (parser
);
5166 else if (c_parser_next_token_is_keyword (parser
, RID_CONST
)
5167 || c_parser_next_token_is_keyword (parser
, RID_RESTRICT
))
5169 warning_at (c_parser_peek_token (parser
)->location
,
5171 "%E qualifier ignored on asm",
5172 c_parser_peek_token (parser
)->value
);
5174 c_parser_consume_token (parser
);
5180 if (c_parser_next_token_is_keyword (parser
, RID_GOTO
))
5182 c_parser_consume_token (parser
);
5186 /* ??? Follow the C++ parser rather than using the
5187 lex_untranslated_string kludge. */
5188 parser
->lex_untranslated_string
= true;
5191 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5194 str
= c_parser_asm_string_literal (parser
);
5195 if (str
== NULL_TREE
)
5196 goto error_close_paren
;
5199 outputs
= NULL_TREE
;
5201 clobbers
= NULL_TREE
;
5204 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
5207 /* Parse each colon-delimited section of operands. */
5208 nsections
= 3 + is_goto
;
5209 for (section
= 0; section
< nsections
; ++section
)
5211 if (!c_parser_require (parser
, CPP_COLON
,
5214 : "expected %<:%> or %<)%>"))
5215 goto error_close_paren
;
5217 /* Once past any colon, we're no longer a simple asm. */
5220 if ((!c_parser_next_token_is (parser
, CPP_COLON
)
5221 && !c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
5226 /* For asm goto, we don't allow output operands, but reserve
5227 the slot for a future extension that does allow them. */
5229 outputs
= c_parser_asm_operands (parser
, false);
5232 inputs
= c_parser_asm_operands (parser
, true);
5235 clobbers
= c_parser_asm_clobbers (parser
);
5238 labels
= c_parser_asm_goto_operands (parser
);
5244 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
5249 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
5251 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5255 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
5256 c_parser_skip_to_end_of_block_or_statement (parser
);
5258 ret
= build_asm_stmt (quals
, build_asm_expr (asm_loc
, str
, outputs
, inputs
,
5259 clobbers
, labels
, simple
));
5262 parser
->lex_untranslated_string
= false;
5266 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5270 /* Parse asm operands, a GNU extension. If CONVERT_P (for inputs but
5271 not outputs), apply the default conversion of functions and arrays
5276 asm-operands , asm-operand
5279 asm-string-literal ( expression )
5280 [ identifier ] asm-string-literal ( expression )
5284 c_parser_asm_operands (c_parser
*parser
, bool convert_p
)
5286 tree list
= NULL_TREE
;
5292 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
5294 c_parser_consume_token (parser
);
5295 if (c_parser_next_token_is (parser
, CPP_NAME
))
5297 tree id
= c_parser_peek_token (parser
)->value
;
5298 c_parser_consume_token (parser
);
5299 name
= build_string (IDENTIFIER_LENGTH (id
),
5300 IDENTIFIER_POINTER (id
));
5304 c_parser_error (parser
, "expected identifier");
5305 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
5308 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5313 str
= c_parser_asm_string_literal (parser
);
5314 if (str
== NULL_TREE
)
5316 parser
->lex_untranslated_string
= false;
5317 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5319 parser
->lex_untranslated_string
= true;
5322 loc
= c_parser_peek_token (parser
)->location
;
5323 expr
= c_parser_expression (parser
);
5324 mark_exp_read (expr
.value
);
5326 expr
= default_function_array_conversion (loc
, expr
);
5327 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
5328 parser
->lex_untranslated_string
= true;
5329 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
5331 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5334 list
= chainon (list
, build_tree_list (build_tree_list (name
, str
),
5336 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5337 c_parser_consume_token (parser
);
5344 /* Parse asm clobbers, a GNU extension.
5348 asm-clobbers , asm-string-literal
5352 c_parser_asm_clobbers (c_parser
*parser
)
5354 tree list
= NULL_TREE
;
5357 tree str
= c_parser_asm_string_literal (parser
);
5359 list
= tree_cons (NULL_TREE
, str
, list
);
5362 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5363 c_parser_consume_token (parser
);
5370 /* Parse asm goto labels, a GNU extension.
5374 asm-goto-operands , identifier
5378 c_parser_asm_goto_operands (c_parser
*parser
)
5380 tree list
= NULL_TREE
;
5385 if (c_parser_next_token_is (parser
, CPP_NAME
))
5387 c_token
*tok
= c_parser_peek_token (parser
);
5389 label
= lookup_label_for_goto (tok
->location
, name
);
5390 c_parser_consume_token (parser
);
5391 TREE_USED (label
) = 1;
5395 c_parser_error (parser
, "expected identifier");
5399 name
= build_string (IDENTIFIER_LENGTH (name
),
5400 IDENTIFIER_POINTER (name
));
5401 list
= tree_cons (name
, label
, list
);
5402 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5403 c_parser_consume_token (parser
);
5405 return nreverse (list
);
5409 /* Parse an expression other than a compound expression; that is, an
5410 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
5411 NULL then it is an Objective-C message expression which is the
5412 primary-expression starting the expression as an initializer.
5414 assignment-expression:
5415 conditional-expression
5416 unary-expression assignment-operator assignment-expression
5418 assignment-operator: one of
5419 = *= /= %= += -= <<= >>= &= ^= |=
5421 In GNU C we accept any conditional expression on the LHS and
5422 diagnose the invalid lvalue rather than producing a syntax
5425 static struct c_expr
5426 c_parser_expr_no_commas (c_parser
*parser
, struct c_expr
*after
)
5428 struct c_expr lhs
, rhs
, ret
;
5429 enum tree_code code
;
5430 location_t op_location
, exp_location
;
5431 gcc_assert (!after
|| c_dialect_objc ());
5432 lhs
= c_parser_conditional_expression (parser
, after
);
5433 op_location
= c_parser_peek_token (parser
)->location
;
5434 switch (c_parser_peek_token (parser
)->type
)
5443 code
= TRUNC_DIV_EXPR
;
5446 code
= TRUNC_MOD_EXPR
;
5461 code
= BIT_AND_EXPR
;
5464 code
= BIT_XOR_EXPR
;
5467 code
= BIT_IOR_EXPR
;
5472 c_parser_consume_token (parser
);
5473 exp_location
= c_parser_peek_token (parser
)->location
;
5474 rhs
= c_parser_expr_no_commas (parser
, NULL
);
5475 rhs
= default_function_array_read_conversion (exp_location
, rhs
);
5476 ret
.value
= build_modify_expr (op_location
, lhs
.value
, lhs
.original_type
,
5477 code
, exp_location
, rhs
.value
,
5479 if (code
== NOP_EXPR
)
5480 ret
.original_code
= MODIFY_EXPR
;
5483 TREE_NO_WARNING (ret
.value
) = 1;
5484 ret
.original_code
= ERROR_MARK
;
5486 ret
.original_type
= NULL
;
5490 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
5491 is not NULL then it is an Objective-C message expression which is
5492 the primary-expression starting the expression as an initializer.
5494 conditional-expression:
5495 logical-OR-expression
5496 logical-OR-expression ? expression : conditional-expression
5500 conditional-expression:
5501 logical-OR-expression ? : conditional-expression
5504 static struct c_expr
5505 c_parser_conditional_expression (c_parser
*parser
, struct c_expr
*after
)
5507 struct c_expr cond
, exp1
, exp2
, ret
;
5508 location_t cond_loc
, colon_loc
, middle_loc
;
5510 gcc_assert (!after
|| c_dialect_objc ());
5512 cond
= c_parser_binary_expression (parser
, after
, PREC_NONE
);
5514 if (c_parser_next_token_is_not (parser
, CPP_QUERY
))
5516 cond_loc
= c_parser_peek_token (parser
)->location
;
5517 cond
= default_function_array_read_conversion (cond_loc
, cond
);
5518 c_parser_consume_token (parser
);
5519 if (c_parser_next_token_is (parser
, CPP_COLON
))
5521 tree eptype
= NULL_TREE
;
5523 middle_loc
= c_parser_peek_token (parser
)->location
;
5524 pedwarn (middle_loc
, OPT_Wpedantic
,
5525 "ISO C forbids omitting the middle term of a ?: expression");
5526 warn_for_omitted_condop (middle_loc
, cond
.value
);
5527 if (TREE_CODE (cond
.value
) == EXCESS_PRECISION_EXPR
)
5529 eptype
= TREE_TYPE (cond
.value
);
5530 cond
.value
= TREE_OPERAND (cond
.value
, 0);
5532 /* Make sure first operand is calculated only once. */
5533 exp1
.value
= c_save_expr (default_conversion (cond
.value
));
5535 exp1
.value
= build1 (EXCESS_PRECISION_EXPR
, eptype
, exp1
.value
);
5536 exp1
.original_type
= NULL
;
5537 cond
.value
= c_objc_common_truthvalue_conversion (cond_loc
, exp1
.value
);
5538 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_true_node
;
5543 = c_objc_common_truthvalue_conversion
5544 (cond_loc
, default_conversion (cond
.value
));
5545 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_false_node
;
5546 exp1
= c_parser_expression_conv (parser
);
5547 mark_exp_read (exp1
.value
);
5548 c_inhibit_evaluation_warnings
+=
5549 ((cond
.value
== truthvalue_true_node
)
5550 - (cond
.value
== truthvalue_false_node
));
5553 colon_loc
= c_parser_peek_token (parser
)->location
;
5554 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
5556 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
5557 ret
.value
= error_mark_node
;
5558 ret
.original_code
= ERROR_MARK
;
5559 ret
.original_type
= NULL
;
5563 location_t exp2_loc
= c_parser_peek_token (parser
)->location
;
5564 exp2
= c_parser_conditional_expression (parser
, NULL
);
5565 exp2
= default_function_array_read_conversion (exp2_loc
, exp2
);
5567 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
5568 ret
.value
= build_conditional_expr (colon_loc
, cond
.value
,
5569 cond
.original_code
== C_MAYBE_CONST_EXPR
,
5570 exp1
.value
, exp1
.original_type
,
5571 exp2
.value
, exp2
.original_type
);
5572 ret
.original_code
= ERROR_MARK
;
5573 if (exp1
.value
== error_mark_node
|| exp2
.value
== error_mark_node
)
5574 ret
.original_type
= NULL
;
5579 /* If both sides are enum type, the default conversion will have
5580 made the type of the result be an integer type. We want to
5581 remember the enum types we started with. */
5582 t1
= exp1
.original_type
? exp1
.original_type
: TREE_TYPE (exp1
.value
);
5583 t2
= exp2
.original_type
? exp2
.original_type
: TREE_TYPE (exp2
.value
);
5584 ret
.original_type
= ((t1
!= error_mark_node
5585 && t2
!= error_mark_node
5586 && (TYPE_MAIN_VARIANT (t1
)
5587 == TYPE_MAIN_VARIANT (t2
)))
5594 /* Parse a binary expression; that is, a logical-OR-expression (C90
5595 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
5596 an Objective-C message expression which is the primary-expression
5597 starting the expression as an initializer. PREC is the starting
5598 precedence, usually PREC_NONE.
5600 multiplicative-expression:
5602 multiplicative-expression * cast-expression
5603 multiplicative-expression / cast-expression
5604 multiplicative-expression % cast-expression
5606 additive-expression:
5607 multiplicative-expression
5608 additive-expression + multiplicative-expression
5609 additive-expression - multiplicative-expression
5613 shift-expression << additive-expression
5614 shift-expression >> additive-expression
5616 relational-expression:
5618 relational-expression < shift-expression
5619 relational-expression > shift-expression
5620 relational-expression <= shift-expression
5621 relational-expression >= shift-expression
5623 equality-expression:
5624 relational-expression
5625 equality-expression == relational-expression
5626 equality-expression != relational-expression
5630 AND-expression & equality-expression
5632 exclusive-OR-expression:
5634 exclusive-OR-expression ^ AND-expression
5636 inclusive-OR-expression:
5637 exclusive-OR-expression
5638 inclusive-OR-expression | exclusive-OR-expression
5640 logical-AND-expression:
5641 inclusive-OR-expression
5642 logical-AND-expression && inclusive-OR-expression
5644 logical-OR-expression:
5645 logical-AND-expression
5646 logical-OR-expression || logical-AND-expression
5649 static struct c_expr
5650 c_parser_binary_expression (c_parser
*parser
, struct c_expr
*after
,
5651 enum c_parser_prec prec
)
5653 /* A binary expression is parsed using operator-precedence parsing,
5654 with the operands being cast expressions. All the binary
5655 operators are left-associative. Thus a binary expression is of
5658 E0 op1 E1 op2 E2 ...
5660 which we represent on a stack. On the stack, the precedence
5661 levels are strictly increasing. When a new operator is
5662 encountered of higher precedence than that at the top of the
5663 stack, it is pushed; its LHS is the top expression, and its RHS
5664 is everything parsed until it is popped. When a new operator is
5665 encountered with precedence less than or equal to that at the top
5666 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
5667 by the result of the operation until the operator at the top of
5668 the stack has lower precedence than the new operator or there is
5669 only one element on the stack; then the top expression is the LHS
5670 of the new operator. In the case of logical AND and OR
5671 expressions, we also need to adjust c_inhibit_evaluation_warnings
5672 as appropriate when the operators are pushed and popped. */
5675 /* The expression at this stack level. */
5677 /* The precedence of the operator on its left, PREC_NONE at the
5678 bottom of the stack. */
5679 enum c_parser_prec prec
;
5680 /* The operation on its left. */
5682 /* The source location of this operation. */
5686 /* Location of the binary operator. */
5687 location_t binary_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
5690 switch (stack[sp].op) \
5692 case TRUTH_ANDIF_EXPR: \
5693 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
5694 == truthvalue_false_node); \
5696 case TRUTH_ORIF_EXPR: \
5697 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
5698 == truthvalue_true_node); \
5703 stack[sp - 1].expr \
5704 = default_function_array_read_conversion (stack[sp - 1].loc, \
5705 stack[sp - 1].expr); \
5707 = default_function_array_read_conversion (stack[sp].loc, \
5709 stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc, \
5711 stack[sp - 1].expr, \
5715 gcc_assert (!after
|| c_dialect_objc ());
5716 stack
[0].loc
= c_parser_peek_token (parser
)->location
;
5717 stack
[0].expr
= c_parser_cast_expression (parser
, after
);
5718 stack
[0].prec
= prec
;
5722 enum c_parser_prec oprec
;
5723 enum tree_code ocode
;
5726 switch (c_parser_peek_token (parser
)->type
)
5734 ocode
= TRUNC_DIV_EXPR
;
5738 ocode
= TRUNC_MOD_EXPR
;
5750 ocode
= LSHIFT_EXPR
;
5754 ocode
= RSHIFT_EXPR
;
5768 case CPP_GREATER_EQ
:
5781 oprec
= PREC_BITAND
;
5782 ocode
= BIT_AND_EXPR
;
5785 oprec
= PREC_BITXOR
;
5786 ocode
= BIT_XOR_EXPR
;
5790 ocode
= BIT_IOR_EXPR
;
5793 oprec
= PREC_LOGAND
;
5794 ocode
= TRUTH_ANDIF_EXPR
;
5798 ocode
= TRUTH_ORIF_EXPR
;
5801 /* Not a binary operator, so end of the binary
5805 binary_loc
= c_parser_peek_token (parser
)->location
;
5806 while (oprec
<= stack
[sp
].prec
)
5812 c_parser_consume_token (parser
);
5815 case TRUTH_ANDIF_EXPR
:
5817 = default_function_array_read_conversion (stack
[sp
].loc
,
5819 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
5820 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
5821 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
5822 == truthvalue_false_node
);
5824 case TRUTH_ORIF_EXPR
:
5826 = default_function_array_read_conversion (stack
[sp
].loc
,
5828 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
5829 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
5830 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
5831 == truthvalue_true_node
);
5837 stack
[sp
].loc
= binary_loc
;
5838 stack
[sp
].expr
= c_parser_cast_expression (parser
, NULL
);
5839 stack
[sp
].prec
= oprec
;
5840 stack
[sp
].op
= ocode
;
5841 stack
[sp
].loc
= binary_loc
;
5846 return stack
[0].expr
;
5850 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
5851 NULL then it is an Objective-C message expression which is the
5852 primary-expression starting the expression as an initializer.
5856 ( type-name ) unary-expression
5859 static struct c_expr
5860 c_parser_cast_expression (c_parser
*parser
, struct c_expr
*after
)
5862 location_t cast_loc
= c_parser_peek_token (parser
)->location
;
5863 gcc_assert (!after
|| c_dialect_objc ());
5865 return c_parser_postfix_expression_after_primary (parser
,
5867 /* If the expression begins with a parenthesized type name, it may
5868 be either a cast or a compound literal; we need to see whether
5869 the next character is '{' to tell the difference. If not, it is
5870 an unary expression. Full detection of unknown typenames here
5871 would require a 3-token lookahead. */
5872 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
5873 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
5875 struct c_type_name
*type_name
;
5878 c_parser_consume_token (parser
);
5879 type_name
= c_parser_type_name (parser
);
5880 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5881 if (type_name
== NULL
)
5883 ret
.value
= error_mark_node
;
5884 ret
.original_code
= ERROR_MARK
;
5885 ret
.original_type
= NULL
;
5889 /* Save casted types in the function's used types hash table. */
5890 used_types_insert (type_name
->specs
->type
);
5892 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5893 return c_parser_postfix_expression_after_paren_type (parser
, type_name
,
5896 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
5897 expr
= c_parser_cast_expression (parser
, NULL
);
5898 expr
= default_function_array_read_conversion (expr_loc
, expr
);
5900 ret
.value
= c_cast_expr (cast_loc
, type_name
, expr
.value
);
5901 ret
.original_code
= ERROR_MARK
;
5902 ret
.original_type
= NULL
;
5906 return c_parser_unary_expression (parser
);
5909 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
5915 unary-operator cast-expression
5916 sizeof unary-expression
5917 sizeof ( type-name )
5919 unary-operator: one of
5925 __alignof__ unary-expression
5926 __alignof__ ( type-name )
5929 (C11 permits _Alignof with type names only.)
5931 unary-operator: one of
5932 __extension__ __real__ __imag__
5934 Transactional Memory:
5937 transaction-expression
5939 In addition, the GNU syntax treats ++ and -- as unary operators, so
5940 they may be applied to cast expressions with errors for non-lvalues
5943 static struct c_expr
5944 c_parser_unary_expression (c_parser
*parser
)
5947 struct c_expr ret
, op
;
5948 location_t op_loc
= c_parser_peek_token (parser
)->location
;
5950 ret
.original_code
= ERROR_MARK
;
5951 ret
.original_type
= NULL
;
5952 switch (c_parser_peek_token (parser
)->type
)
5955 c_parser_consume_token (parser
);
5956 exp_loc
= c_parser_peek_token (parser
)->location
;
5957 op
= c_parser_cast_expression (parser
, NULL
);
5958 op
= default_function_array_read_conversion (exp_loc
, op
);
5959 return parser_build_unary_op (op_loc
, PREINCREMENT_EXPR
, op
);
5960 case CPP_MINUS_MINUS
:
5961 c_parser_consume_token (parser
);
5962 exp_loc
= c_parser_peek_token (parser
)->location
;
5963 op
= c_parser_cast_expression (parser
, NULL
);
5964 op
= default_function_array_read_conversion (exp_loc
, op
);
5965 return parser_build_unary_op (op_loc
, PREDECREMENT_EXPR
, op
);
5967 c_parser_consume_token (parser
);
5968 op
= c_parser_cast_expression (parser
, NULL
);
5969 mark_exp_read (op
.value
);
5970 return parser_build_unary_op (op_loc
, ADDR_EXPR
, op
);
5972 c_parser_consume_token (parser
);
5973 exp_loc
= c_parser_peek_token (parser
)->location
;
5974 op
= c_parser_cast_expression (parser
, NULL
);
5975 op
= default_function_array_read_conversion (exp_loc
, op
);
5976 ret
.value
= build_indirect_ref (op_loc
, op
.value
, RO_UNARY_STAR
);
5979 if (!c_dialect_objc () && !in_system_header
)
5982 "traditional C rejects the unary plus operator");
5983 c_parser_consume_token (parser
);
5984 exp_loc
= c_parser_peek_token (parser
)->location
;
5985 op
= c_parser_cast_expression (parser
, NULL
);
5986 op
= default_function_array_read_conversion (exp_loc
, op
);
5987 return parser_build_unary_op (op_loc
, CONVERT_EXPR
, op
);
5989 c_parser_consume_token (parser
);
5990 exp_loc
= c_parser_peek_token (parser
)->location
;
5991 op
= c_parser_cast_expression (parser
, NULL
);
5992 op
= default_function_array_read_conversion (exp_loc
, op
);
5993 return parser_build_unary_op (op_loc
, NEGATE_EXPR
, op
);
5995 c_parser_consume_token (parser
);
5996 exp_loc
= c_parser_peek_token (parser
)->location
;
5997 op
= c_parser_cast_expression (parser
, NULL
);
5998 op
= default_function_array_read_conversion (exp_loc
, op
);
5999 return parser_build_unary_op (op_loc
, BIT_NOT_EXPR
, op
);
6001 c_parser_consume_token (parser
);
6002 exp_loc
= c_parser_peek_token (parser
)->location
;
6003 op
= c_parser_cast_expression (parser
, NULL
);
6004 op
= default_function_array_read_conversion (exp_loc
, op
);
6005 return parser_build_unary_op (op_loc
, TRUTH_NOT_EXPR
, op
);
6007 /* Refer to the address of a label as a pointer. */
6008 c_parser_consume_token (parser
);
6009 if (c_parser_next_token_is (parser
, CPP_NAME
))
6011 ret
.value
= finish_label_address_expr
6012 (c_parser_peek_token (parser
)->value
, op_loc
);
6013 c_parser_consume_token (parser
);
6017 c_parser_error (parser
, "expected identifier");
6018 ret
.value
= error_mark_node
;
6022 switch (c_parser_peek_token (parser
)->keyword
)
6025 return c_parser_sizeof_expression (parser
);
6026 case RID_UPC_BLOCKSIZEOF
:
6027 case RID_UPC_ELEMSIZEOF
:
6028 case RID_UPC_LOCALSIZEOF
:
6029 gcc_assert (c_dialect_upc ());
6030 return c_parser_sizeof_expression (parser
);
6032 return c_parser_alignof_expression (parser
);
6034 c_parser_consume_token (parser
);
6035 ext
= disable_extension_diagnostics ();
6036 ret
= c_parser_cast_expression (parser
, NULL
);
6037 restore_extension_diagnostics (ext
);
6040 c_parser_consume_token (parser
);
6041 exp_loc
= c_parser_peek_token (parser
)->location
;
6042 op
= c_parser_cast_expression (parser
, NULL
);
6043 op
= default_function_array_conversion (exp_loc
, op
);
6044 return parser_build_unary_op (op_loc
, REALPART_EXPR
, op
);
6046 c_parser_consume_token (parser
);
6047 exp_loc
= c_parser_peek_token (parser
)->location
;
6048 op
= c_parser_cast_expression (parser
, NULL
);
6049 op
= default_function_array_conversion (exp_loc
, op
);
6050 return parser_build_unary_op (op_loc
, IMAGPART_EXPR
, op
);
6051 case RID_TRANSACTION_ATOMIC
:
6052 case RID_TRANSACTION_RELAXED
:
6053 return c_parser_transaction_expression (parser
,
6054 c_parser_peek_token (parser
)->keyword
);
6056 return c_parser_postfix_expression (parser
);
6059 return c_parser_postfix_expression (parser
);
6063 /* Return the result of upc_blocksizeof applied to EXPR. */
6067 upc_blocksizeof_expr (location_t loc
, struct c_expr expr
)
6070 ret
.original_code
= ERROR_MARK
;
6071 ret
.original_type
= NULL_TREE
;
6072 if (expr
.value
== error_mark_node
)
6074 ret
.value
= error_mark_node
;
6075 pop_maybe_used (false);
6079 ret
.value
= upc_blocksizeof (loc
, TREE_TYPE (expr
.value
));
6080 pop_maybe_used (C_TYPE_VARIABLE_SIZE (TREE_TYPE (expr
.value
)));
6085 /* Return the result of upc_blocksizeof applied to T, a structure
6086 for the type name passed to sizeof (rather than the type itself). */
6090 upc_blocksizeof_type (location_t loc
, struct c_type_name
*t
)
6094 ret
.original_code
= ERROR_MARK
;
6095 ret
.original_type
= NULL_TREE
;
6096 type
= groktypename (t
, NULL
, NULL
);
6097 if (type
== error_mark_node
)
6099 ret
.value
= error_mark_node
;
6100 pop_maybe_used (false);
6104 ret
.value
= upc_blocksizeof (loc
, type
);
6105 pop_maybe_used (C_TYPE_VARIABLE_SIZE (type
));
6110 /* Return the result of upc_elemsizeof applied to EXPR. */
6114 upc_elemsizeof_expr (location_t loc
, struct c_expr expr
)
6117 ret
.original_code
= ERROR_MARK
;
6118 ret
.original_type
= NULL_TREE
;
6119 if (expr
.value
== error_mark_node
)
6121 ret
.value
= error_mark_node
;
6122 pop_maybe_used (false);
6126 ret
.value
= upc_elemsizeof (loc
, TREE_TYPE (expr
.value
));
6127 pop_maybe_used (C_TYPE_VARIABLE_SIZE (TREE_TYPE (expr
.value
)));
6132 /* Return the result of upc_elemsizeof applied to T, a structure
6133 for the type name passed to sizeof (rather than the type itself). */
6137 upc_elemsizeof_type (location_t loc
, struct c_type_name
*t
)
6141 ret
.original_code
= ERROR_MARK
;
6142 ret
.original_type
= NULL_TREE
;
6143 type
= groktypename (t
, NULL
, NULL
);
6144 if (type
== error_mark_node
)
6146 ret
.value
= error_mark_node
;
6147 pop_maybe_used (false);
6151 ret
.value
= upc_elemsizeof (loc
, type
);
6152 pop_maybe_used (C_TYPE_VARIABLE_SIZE (type
));
6157 /* Return the result of upc_localsizeof applied to EXPR. */
6161 upc_localsizeof_expr (location_t loc
, struct c_expr expr
)
6164 ret
.original_code
= ERROR_MARK
;
6165 ret
.original_type
= NULL_TREE
;
6166 if (expr
.value
== error_mark_node
)
6168 ret
.value
= error_mark_node
;
6169 pop_maybe_used (false);
6173 ret
.value
= upc_localsizeof (loc
, TREE_TYPE (expr
.value
));
6174 pop_maybe_used (C_TYPE_VARIABLE_SIZE (TREE_TYPE (expr
.value
)));
6179 /* Return the result of upc_localsizeof applied to T, a structure
6180 for the type name passed to sizeof (rather than the type itself). */
6184 upc_localsizeof_type (location_t loc
, struct c_type_name
*t
)
6188 ret
.original_code
= ERROR_MARK
;
6189 ret
.original_type
= NULL_TREE
;
6190 type
= groktypename (t
, NULL
, NULL
);
6191 if (type
== error_mark_node
)
6193 ret
.value
= error_mark_node
;
6194 pop_maybe_used (false);
6198 ret
.value
= upc_localsizeof (loc
, type
);
6199 pop_maybe_used (C_TYPE_VARIABLE_SIZE (type
));
6204 /* Parse a sizeof expression. */
6206 static struct c_expr
6207 c_parser_sizeof_expression (c_parser
*parser
)
6210 location_t expr_loc
;
6211 enum rid keyword
= c_parser_peek_token (parser
)->keyword
;
6212 c_parser_consume_token (parser
);
6213 c_inhibit_evaluation_warnings
++;
6215 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
6216 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6218 /* Either sizeof ( type-name ) or sizeof unary-expression
6219 starting with a compound literal. */
6220 struct c_type_name
*type_name
;
6221 c_parser_consume_token (parser
);
6222 expr_loc
= c_parser_peek_token (parser
)->location
;
6223 type_name
= c_parser_type_name (parser
);
6224 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6225 if (type_name
== NULL
)
6228 c_inhibit_evaluation_warnings
--;
6230 ret
.value
= error_mark_node
;
6231 ret
.original_code
= ERROR_MARK
;
6232 ret
.original_type
= NULL
;
6235 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6237 expr
= c_parser_postfix_expression_after_paren_type (parser
,
6242 /* sizeof ( type-name ). */
6243 c_inhibit_evaluation_warnings
--;
6245 /* Handle upc_*_sizeof (type) operations. */
6248 case RID_UPC_BLOCKSIZEOF
:
6249 return upc_blocksizeof_type (expr_loc
, type_name
);
6250 case RID_UPC_ELEMSIZEOF
:
6251 return upc_elemsizeof_type (expr_loc
, type_name
);
6252 case RID_UPC_LOCALSIZEOF
:
6253 return upc_localsizeof_type (expr_loc
, type_name
);
6256 return c_expr_sizeof_type (expr_loc
, type_name
);
6260 expr_loc
= c_parser_peek_token (parser
)->location
;
6261 expr
= c_parser_unary_expression (parser
);
6263 c_inhibit_evaluation_warnings
--;
6265 mark_exp_read (expr
.value
);
6266 if (TREE_CODE (expr
.value
) == COMPONENT_REF
6267 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
6268 error_at (expr_loc
, "%<sizeof%> applied to a bit-field");
6269 /* Handle upc_*_sizeof (expr) operations. */
6272 case RID_UPC_BLOCKSIZEOF
:
6273 return upc_blocksizeof_expr (expr_loc
, expr
);
6274 case RID_UPC_ELEMSIZEOF
:
6275 return upc_elemsizeof_expr (expr_loc
, expr
);
6276 case RID_UPC_LOCALSIZEOF
:
6277 return upc_localsizeof_expr (expr_loc
, expr
);
6279 return c_expr_sizeof_expr (expr_loc
, expr
);
6282 return c_expr_sizeof_expr (expr_loc
, expr
);
6286 /* Parse an alignof expression. */
6288 static struct c_expr
6289 c_parser_alignof_expression (c_parser
*parser
)
6292 location_t loc
= c_parser_peek_token (parser
)->location
;
6293 tree alignof_spelling
= c_parser_peek_token (parser
)->value
;
6294 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNOF
));
6295 /* A diagnostic is not required for the use of this identifier in
6296 the implementation namespace; only diagnose it for the C11
6297 spelling because of existing code using the other spellings. */
6299 && strcmp (IDENTIFIER_POINTER (alignof_spelling
), "_Alignof") == 0)
6302 pedwarn (loc
, OPT_Wpedantic
, "ISO C99 does not support %qE",
6305 pedwarn (loc
, OPT_Wpedantic
, "ISO C90 does not support %qE",
6308 c_parser_consume_token (parser
);
6309 c_inhibit_evaluation_warnings
++;
6311 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
6312 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6314 /* Either __alignof__ ( type-name ) or __alignof__
6315 unary-expression starting with a compound literal. */
6317 struct c_type_name
*type_name
;
6319 c_parser_consume_token (parser
);
6320 loc
= c_parser_peek_token (parser
)->location
;
6321 type_name
= c_parser_type_name (parser
);
6322 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6323 if (type_name
== NULL
)
6326 c_inhibit_evaluation_warnings
--;
6328 ret
.value
= error_mark_node
;
6329 ret
.original_code
= ERROR_MARK
;
6330 ret
.original_type
= NULL
;
6333 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6335 expr
= c_parser_postfix_expression_after_paren_type (parser
,
6340 /* alignof ( type-name ). */
6341 c_inhibit_evaluation_warnings
--;
6343 ret
.value
= c_alignof (loc
, groktypename (type_name
, NULL
, NULL
));
6344 ret
.original_code
= ERROR_MARK
;
6345 ret
.original_type
= NULL
;
6351 expr
= c_parser_unary_expression (parser
);
6353 mark_exp_read (expr
.value
);
6354 c_inhibit_evaluation_warnings
--;
6356 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not allow %<%E (expression)%>",
6358 ret
.value
= c_alignof_expr (loc
, expr
.value
);
6359 ret
.original_code
= ERROR_MARK
;
6360 ret
.original_type
= NULL
;
6365 /* Helper function to read arguments of builtins which are interfaces
6366 for the middle-end nodes like COMPLEX_EXPR, VEC_PERM_EXPR and
6367 others. The name of the builtin is passed using BNAME parameter.
6368 Function returns true if there were no errors while parsing and
6369 stores the arguments in CEXPR_LIST. */
6371 c_parser_get_builtin_args (c_parser
*parser
, const char *bname
,
6372 VEC(c_expr_t
,gc
) **ret_cexpr_list
)
6374 location_t loc
= c_parser_peek_token (parser
)->location
;
6375 VEC (c_expr_t
,gc
) *cexpr_list
;
6378 *ret_cexpr_list
= NULL
;
6379 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
6381 error_at (loc
, "cannot take address of %qs", bname
);
6385 c_parser_consume_token (parser
);
6387 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
6389 c_parser_consume_token (parser
);
6393 expr
= c_parser_expr_no_commas (parser
, NULL
);
6394 cexpr_list
= VEC_alloc (c_expr_t
, gc
, 1);
6395 C_EXPR_APPEND (cexpr_list
, expr
);
6396 while (c_parser_next_token_is (parser
, CPP_COMMA
))
6398 c_parser_consume_token (parser
);
6399 expr
= c_parser_expr_no_commas (parser
, NULL
);
6400 C_EXPR_APPEND (cexpr_list
, expr
);
6403 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
6406 *ret_cexpr_list
= cexpr_list
;
6411 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
6415 postfix-expression [ expression ]
6416 postfix-expression ( argument-expression-list[opt] )
6417 postfix-expression . identifier
6418 postfix-expression -> identifier
6419 postfix-expression ++
6420 postfix-expression --
6421 ( type-name ) { initializer-list }
6422 ( type-name ) { initializer-list , }
6424 argument-expression-list:
6426 argument-expression-list , argument-expression
6438 (treated as a keyword in GNU C)
6441 ( compound-statement )
6442 __builtin_va_arg ( assignment-expression , type-name )
6443 __builtin_offsetof ( type-name , offsetof-member-designator )
6444 __builtin_choose_expr ( assignment-expression ,
6445 assignment-expression ,
6446 assignment-expression )
6447 __builtin_types_compatible_p ( type-name , type-name )
6448 __builtin_complex ( assignment-expression , assignment-expression )
6449 __builtin_shuffle ( assignment-expression , assignment-expression )
6450 __builtin_shuffle ( assignment-expression ,
6451 assignment-expression ,
6452 assignment-expression, )
6454 offsetof-member-designator:
6456 offsetof-member-designator . identifier
6457 offsetof-member-designator [ expression ]
6462 [ objc-receiver objc-message-args ]
6463 @selector ( objc-selector-arg )
6464 @protocol ( identifier )
6465 @encode ( type-name )
6467 Classname . identifier
6470 static struct c_expr
6471 c_parser_postfix_expression (c_parser
*parser
)
6473 struct c_expr expr
, e1
;
6474 struct c_type_name
*t1
, *t2
;
6475 location_t loc
= c_parser_peek_token (parser
)->location
;;
6476 expr
.original_code
= ERROR_MARK
;
6477 expr
.original_type
= NULL
;
6478 switch (c_parser_peek_token (parser
)->type
)
6481 expr
.value
= c_parser_peek_token (parser
)->value
;
6482 loc
= c_parser_peek_token (parser
)->location
;
6483 c_parser_consume_token (parser
);
6484 if (TREE_CODE (expr
.value
) == FIXED_CST
6485 && !targetm
.fixed_point_supported_p ())
6487 error_at (loc
, "fixed-point types not supported for this target");
6488 expr
.value
= error_mark_node
;
6495 expr
.value
= c_parser_peek_token (parser
)->value
;
6496 c_parser_consume_token (parser
);
6502 case CPP_UTF8STRING
:
6503 expr
.value
= c_parser_peek_token (parser
)->value
;
6504 expr
.original_code
= STRING_CST
;
6505 c_parser_consume_token (parser
);
6507 case CPP_OBJC_STRING
:
6508 gcc_assert (c_dialect_objc ());
6510 = objc_build_string_object (c_parser_peek_token (parser
)->value
);
6511 c_parser_consume_token (parser
);
6514 switch (c_parser_peek_token (parser
)->id_kind
)
6518 tree id
= c_parser_peek_token (parser
)->value
;
6519 c_parser_consume_token (parser
);
6520 expr
.value
= build_external_ref (loc
, id
,
6521 (c_parser_peek_token (parser
)->type
6523 &expr
.original_type
);
6526 case C_ID_CLASSNAME
:
6528 /* Here we parse the Objective-C 2.0 Class.name dot
6530 tree class_name
= c_parser_peek_token (parser
)->value
;
6532 c_parser_consume_token (parser
);
6533 gcc_assert (c_dialect_objc ());
6534 if (!c_parser_require (parser
, CPP_DOT
, "expected %<.%>"))
6536 expr
.value
= error_mark_node
;
6539 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6541 c_parser_error (parser
, "expected identifier");
6542 expr
.value
= error_mark_node
;
6545 component
= c_parser_peek_token (parser
)->value
;
6546 c_parser_consume_token (parser
);
6547 expr
.value
= objc_build_class_component_ref (class_name
,
6552 c_parser_error (parser
, "expected expression");
6553 expr
.value
= error_mark_node
;
6557 case CPP_OPEN_PAREN
:
6558 /* A parenthesized expression, statement expression or compound
6560 if (c_parser_peek_2nd_token (parser
)->type
== CPP_OPEN_BRACE
)
6562 /* A statement expression. */
6564 location_t brace_loc
;
6565 c_parser_consume_token (parser
);
6566 brace_loc
= c_parser_peek_token (parser
)->location
;
6567 c_parser_consume_token (parser
);
6568 if (!building_stmt_list_p ())
6570 error_at (loc
, "braced-group within expression allowed "
6571 "only inside a function");
6572 parser
->error
= true;
6573 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
6574 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6575 expr
.value
= error_mark_node
;
6578 stmt
= c_begin_stmt_expr ();
6579 c_parser_compound_statement_nostart (parser
);
6580 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6582 pedwarn (loc
, OPT_Wpedantic
,
6583 "ISO C forbids braced-groups within expressions");
6584 expr
.value
= c_finish_stmt_expr (brace_loc
, stmt
);
6585 mark_exp_read (expr
.value
);
6587 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6589 /* A compound literal. ??? Can we actually get here rather
6590 than going directly to
6591 c_parser_postfix_expression_after_paren_type from
6594 struct c_type_name
*type_name
;
6595 c_parser_consume_token (parser
);
6596 loc
= c_parser_peek_token (parser
)->location
;
6597 type_name
= c_parser_type_name (parser
);
6598 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6600 if (type_name
== NULL
)
6602 expr
.value
= error_mark_node
;
6605 expr
= c_parser_postfix_expression_after_paren_type (parser
,
6611 /* A parenthesized expression. */
6612 c_parser_consume_token (parser
);
6613 expr
= c_parser_expression (parser
);
6614 if (TREE_CODE (expr
.value
) == MODIFY_EXPR
)
6615 TREE_NO_WARNING (expr
.value
) = 1;
6616 if (expr
.original_code
!= C_MAYBE_CONST_EXPR
)
6617 expr
.original_code
= ERROR_MARK
;
6618 /* Don't change EXPR.ORIGINAL_TYPE. */
6619 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6624 switch (c_parser_peek_token (parser
)->keyword
)
6626 case RID_FUNCTION_NAME
:
6627 case RID_PRETTY_FUNCTION_NAME
:
6628 case RID_C99_FUNCTION_NAME
:
6629 expr
.value
= fname_decl (loc
,
6630 c_parser_peek_token (parser
)->keyword
,
6631 c_parser_peek_token (parser
)->value
);
6632 c_parser_consume_token (parser
);
6635 c_parser_consume_token (parser
);
6636 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6638 expr
.value
= error_mark_node
;
6641 e1
= c_parser_expr_no_commas (parser
, NULL
);
6642 mark_exp_read (e1
.value
);
6643 e1
.value
= c_fully_fold (e1
.value
, false, NULL
);
6644 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
6646 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6647 expr
.value
= error_mark_node
;
6650 loc
= c_parser_peek_token (parser
)->location
;
6651 t1
= c_parser_type_name (parser
);
6652 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6656 expr
.value
= error_mark_node
;
6660 tree type_expr
= NULL_TREE
;
6661 expr
.value
= c_build_va_arg (loc
, e1
.value
,
6662 groktypename (t1
, &type_expr
, NULL
));
6665 expr
.value
= build2 (C_MAYBE_CONST_EXPR
,
6666 TREE_TYPE (expr
.value
), type_expr
,
6668 C_MAYBE_CONST_EXPR_NON_CONST (expr
.value
) = true;
6673 c_parser_consume_token (parser
);
6674 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6676 expr
.value
= error_mark_node
;
6679 t1
= c_parser_type_name (parser
);
6681 parser
->error
= true;
6682 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
6683 gcc_assert (parser
->error
);
6686 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6687 expr
.value
= error_mark_node
;
6692 tree type
= groktypename (t1
, NULL
, NULL
);
6694 if (type
== error_mark_node
)
6695 offsetof_ref
= error_mark_node
;
6698 offsetof_ref
= build1 (INDIRECT_REF
, type
, null_pointer_node
);
6699 SET_EXPR_LOCATION (offsetof_ref
, loc
);
6701 /* Parse the second argument to __builtin_offsetof. We
6702 must have one identifier, and beyond that we want to
6703 accept sub structure and sub array references. */
6704 if (c_parser_next_token_is (parser
, CPP_NAME
))
6706 offsetof_ref
= build_component_ref
6707 (loc
, offsetof_ref
, c_parser_peek_token (parser
)->value
);
6708 c_parser_consume_token (parser
);
6709 while (c_parser_next_token_is (parser
, CPP_DOT
)
6710 || c_parser_next_token_is (parser
,
6712 || c_parser_next_token_is (parser
,
6715 if (c_parser_next_token_is (parser
, CPP_DEREF
))
6717 loc
= c_parser_peek_token (parser
)->location
;
6718 offsetof_ref
= build_array_ref (loc
,
6723 else if (c_parser_next_token_is (parser
, CPP_DOT
))
6726 c_parser_consume_token (parser
);
6727 if (c_parser_next_token_is_not (parser
,
6730 c_parser_error (parser
, "expected identifier");
6733 offsetof_ref
= build_component_ref
6735 c_parser_peek_token (parser
)->value
);
6736 c_parser_consume_token (parser
);
6741 loc
= c_parser_peek_token (parser
)->location
;
6742 c_parser_consume_token (parser
);
6743 idx
= c_parser_expression (parser
).value
;
6744 idx
= c_fully_fold (idx
, false, NULL
);
6745 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
6747 offsetof_ref
= build_array_ref (loc
, offsetof_ref
, idx
);
6752 c_parser_error (parser
, "expected identifier");
6753 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6755 expr
.value
= fold_offsetof (offsetof_ref
);
6758 case RID_CHOOSE_EXPR
:
6760 VEC (c_expr_t
, gc
) *cexpr_list
;
6761 c_expr_t
*e1_p
, *e2_p
, *e3_p
;
6764 c_parser_consume_token (parser
);
6765 if (!c_parser_get_builtin_args (parser
,
6766 "__builtin_choose_expr",
6769 expr
.value
= error_mark_node
;
6773 if (VEC_length (c_expr_t
, cexpr_list
) != 3)
6775 error_at (loc
, "wrong number of arguments to "
6776 "%<__builtin_choose_expr%>");
6777 expr
.value
= error_mark_node
;
6781 e1_p
= &VEC_index (c_expr_t
, cexpr_list
, 0);
6782 e2_p
= &VEC_index (c_expr_t
, cexpr_list
, 1);
6783 e3_p
= &VEC_index (c_expr_t
, cexpr_list
, 2);
6786 mark_exp_read (e2_p
->value
);
6787 mark_exp_read (e3_p
->value
);
6788 if (TREE_CODE (c
) != INTEGER_CST
6789 || !INTEGRAL_TYPE_P (TREE_TYPE (c
)))
6791 "first argument to %<__builtin_choose_expr%> not"
6793 constant_expression_warning (c
);
6794 expr
= integer_zerop (c
) ? *e3_p
: *e2_p
;
6797 case RID_TYPES_COMPATIBLE_P
:
6798 c_parser_consume_token (parser
);
6799 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6801 expr
.value
= error_mark_node
;
6804 t1
= c_parser_type_name (parser
);
6807 expr
.value
= error_mark_node
;
6810 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
6812 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6813 expr
.value
= error_mark_node
;
6816 t2
= c_parser_type_name (parser
);
6819 expr
.value
= error_mark_node
;
6822 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6826 e1
= groktypename (t1
, NULL
, NULL
);
6827 e2
= groktypename (t2
, NULL
, NULL
);
6828 if (e1
== error_mark_node
|| e2
== error_mark_node
)
6830 expr
.value
= error_mark_node
;
6834 e1
= TYPE_MAIN_VARIANT (e1
);
6835 e2
= TYPE_MAIN_VARIANT (e2
);
6838 = comptypes (e1
, e2
) ? integer_one_node
: integer_zero_node
;
6841 case RID_BUILTIN_COMPLEX
:
6843 VEC(c_expr_t
, gc
) *cexpr_list
;
6844 c_expr_t
*e1_p
, *e2_p
;
6846 c_parser_consume_token (parser
);
6847 if (!c_parser_get_builtin_args (parser
,
6848 "__builtin_complex",
6851 expr
.value
= error_mark_node
;
6855 if (VEC_length (c_expr_t
, cexpr_list
) != 2)
6857 error_at (loc
, "wrong number of arguments to "
6858 "%<__builtin_complex%>");
6859 expr
.value
= error_mark_node
;
6863 e1_p
= &VEC_index (c_expr_t
, cexpr_list
, 0);
6864 e2_p
= &VEC_index (c_expr_t
, cexpr_list
, 1);
6866 mark_exp_read (e1_p
->value
);
6867 if (TREE_CODE (e1_p
->value
) == EXCESS_PRECISION_EXPR
)
6868 e1_p
->value
= convert (TREE_TYPE (e1_p
->value
),
6869 TREE_OPERAND (e1_p
->value
, 0));
6870 mark_exp_read (e2_p
->value
);
6871 if (TREE_CODE (e2_p
->value
) == EXCESS_PRECISION_EXPR
)
6872 e2_p
->value
= convert (TREE_TYPE (e2_p
->value
),
6873 TREE_OPERAND (e2_p
->value
, 0));
6874 if (!SCALAR_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
6875 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
6876 || !SCALAR_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
))
6877 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
)))
6879 error_at (loc
, "%<__builtin_complex%> operand "
6880 "not of real binary floating-point type");
6881 expr
.value
= error_mark_node
;
6884 if (TYPE_MAIN_VARIANT (TREE_TYPE (e1_p
->value
))
6885 != TYPE_MAIN_VARIANT (TREE_TYPE (e2_p
->value
)))
6888 "%<__builtin_complex%> operands of different types");
6889 expr
.value
= error_mark_node
;
6893 pedwarn (loc
, OPT_Wpedantic
,
6894 "ISO C90 does not support complex types");
6895 expr
.value
= build2 (COMPLEX_EXPR
,
6898 (TREE_TYPE (e1_p
->value
))),
6899 e1_p
->value
, e2_p
->value
);
6902 case RID_BUILTIN_SHUFFLE
:
6904 VEC(c_expr_t
,gc
) *cexpr_list
;
6908 c_parser_consume_token (parser
);
6909 if (!c_parser_get_builtin_args (parser
,
6910 "__builtin_shuffle",
6913 expr
.value
= error_mark_node
;
6917 FOR_EACH_VEC_ELT (c_expr_t
, cexpr_list
, i
, p
)
6918 mark_exp_read (p
->value
);
6920 if (VEC_length (c_expr_t
, cexpr_list
) == 2)
6922 c_build_vec_perm_expr
6923 (loc
, VEC_index (c_expr_t
, cexpr_list
, 0).value
,
6924 NULL_TREE
, VEC_index (c_expr_t
, cexpr_list
, 1).value
);
6926 else if (VEC_length (c_expr_t
, cexpr_list
) == 3)
6928 c_build_vec_perm_expr
6929 (loc
, VEC_index (c_expr_t
, cexpr_list
, 0).value
,
6930 VEC_index (c_expr_t
, cexpr_list
, 1).value
,
6931 VEC_index (c_expr_t
, cexpr_list
, 2).value
);
6934 error_at (loc
, "wrong number of arguments to "
6935 "%<__builtin_shuffle%>");
6936 expr
.value
= error_mark_node
;
6940 case RID_AT_SELECTOR
:
6941 gcc_assert (c_dialect_objc ());
6942 c_parser_consume_token (parser
);
6943 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6945 expr
.value
= error_mark_node
;
6949 tree sel
= c_parser_objc_selector_arg (parser
);
6950 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6952 expr
.value
= objc_build_selector_expr (loc
, sel
);
6955 case RID_AT_PROTOCOL
:
6956 gcc_assert (c_dialect_objc ());
6957 c_parser_consume_token (parser
);
6958 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6960 expr
.value
= error_mark_node
;
6963 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6965 c_parser_error (parser
, "expected identifier");
6966 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6967 expr
.value
= error_mark_node
;
6971 tree id
= c_parser_peek_token (parser
)->value
;
6972 c_parser_consume_token (parser
);
6973 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6975 expr
.value
= objc_build_protocol_expr (id
);
6979 /* Extension to support C-structures in the archiver. */
6980 gcc_assert (c_dialect_objc ());
6981 c_parser_consume_token (parser
);
6982 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6984 expr
.value
= error_mark_node
;
6987 t1
= c_parser_type_name (parser
);
6990 expr
.value
= error_mark_node
;
6991 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6994 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6997 tree type
= groktypename (t1
, NULL
, NULL
);
6998 expr
.value
= objc_build_encode_expr (type
);
7002 c_parser_error (parser
, "expected expression");
7003 expr
.value
= error_mark_node
;
7007 case CPP_OPEN_SQUARE
:
7008 if (c_dialect_objc ())
7010 tree receiver
, args
;
7011 c_parser_consume_token (parser
);
7012 receiver
= c_parser_objc_receiver (parser
);
7013 args
= c_parser_objc_message_args (parser
);
7014 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
7016 expr
.value
= objc_build_message_expr (receiver
, args
);
7019 /* Else fall through to report error. */
7021 c_parser_error (parser
, "expected expression");
7022 expr
.value
= error_mark_node
;
7025 return c_parser_postfix_expression_after_primary (parser
, loc
, expr
);
7028 /* Parse a postfix expression after a parenthesized type name: the
7029 brace-enclosed initializer of a compound literal, possibly followed
7030 by some postfix operators. This is separate because it is not
7031 possible to tell until after the type name whether a cast
7032 expression has a cast or a compound literal, or whether the operand
7033 of sizeof is a parenthesized type name or starts with a compound
7034 literal. TYPE_LOC is the location where TYPE_NAME starts--the
7035 location of the first token after the parentheses around the type
7038 static struct c_expr
7039 c_parser_postfix_expression_after_paren_type (c_parser
*parser
,
7040 struct c_type_name
*type_name
,
7041 location_t type_loc
)
7047 location_t start_loc
;
7048 tree type_expr
= NULL_TREE
;
7049 bool type_expr_const
= true;
7050 check_compound_literal_type (type_loc
, type_name
);
7051 start_init (NULL_TREE
, NULL
, 0);
7052 type
= groktypename (type_name
, &type_expr
, &type_expr_const
);
7053 start_loc
= c_parser_peek_token (parser
)->location
;
7054 if (type
!= error_mark_node
&& C_TYPE_VARIABLE_SIZE (type
))
7056 error_at (type_loc
, "compound literal has variable size");
7057 type
= error_mark_node
;
7059 init
= c_parser_braced_init (parser
, type
, false);
7061 maybe_warn_string_init (type
, init
);
7063 if (type
!= error_mark_node
7064 && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type
))
7065 && current_function_decl
)
7067 error ("compound literal qualified by address-space qualifier");
7068 type
= error_mark_node
;
7072 pedwarn (start_loc
, OPT_Wpedantic
, "ISO C90 forbids compound literals");
7073 non_const
= ((init
.value
&& TREE_CODE (init
.value
) == CONSTRUCTOR
)
7074 ? CONSTRUCTOR_NON_CONST (init
.value
)
7075 : init
.original_code
== C_MAYBE_CONST_EXPR
);
7076 non_const
|= !type_expr_const
;
7077 expr
.value
= build_compound_literal (start_loc
, type
, init
.value
, non_const
);
7078 expr
.original_code
= ERROR_MARK
;
7079 expr
.original_type
= NULL
;
7082 if (TREE_CODE (expr
.value
) == C_MAYBE_CONST_EXPR
)
7084 gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr
.value
) == NULL_TREE
);
7085 C_MAYBE_CONST_EXPR_PRE (expr
.value
) = type_expr
;
7089 gcc_assert (!non_const
);
7090 expr
.value
= build2 (C_MAYBE_CONST_EXPR
, type
,
7091 type_expr
, expr
.value
);
7094 return c_parser_postfix_expression_after_primary (parser
, start_loc
, expr
);
7097 /* Callback function for sizeof_pointer_memaccess_warning to compare
7101 sizeof_ptr_memacc_comptypes (tree type1
, tree type2
)
7103 return comptypes (type1
, type2
) == 1;
7106 /* Parse a postfix expression after the initial primary or compound
7107 literal; that is, parse a series of postfix operators.
7109 EXPR_LOC is the location of the primary expression. */
7111 static struct c_expr
7112 c_parser_postfix_expression_after_primary (c_parser
*parser
,
7113 location_t expr_loc
,
7116 struct c_expr orig_expr
;
7118 struct c_tree_loc_pair sizeof_arg
;
7119 VEC(tree
,gc
) *exprlist
;
7120 VEC(tree
,gc
) *origtypes
;
7123 location_t op_loc
= c_parser_peek_token (parser
)->location
;
7124 switch (c_parser_peek_token (parser
)->type
)
7126 case CPP_OPEN_SQUARE
:
7127 /* Array reference. */
7128 c_parser_consume_token (parser
);
7129 idx
= c_parser_expression (parser
).value
;
7130 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
7132 expr
.value
= build_array_ref (op_loc
, expr
.value
, idx
);
7133 expr
.original_code
= ERROR_MARK
;
7134 expr
.original_type
= NULL
;
7136 case CPP_OPEN_PAREN
:
7137 /* Function call. */
7138 c_parser_consume_token (parser
);
7139 sizeof_arg
.expr
= NULL_TREE
;
7140 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
7143 exprlist
= c_parser_expr_list (parser
, true, false, &origtypes
,
7145 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7148 mark_exp_read (expr
.value
);
7149 if (warn_sizeof_pointer_memaccess
7150 && sizeof_arg
.expr
!= NULL_TREE
)
7151 sizeof_pointer_memaccess_warning (sizeof_arg
.loc
,
7152 expr
.value
, exprlist
,
7154 sizeof_ptr_memacc_comptypes
);
7155 /* FIXME diagnostics: Ideally we want the FUNCNAME, not the
7156 "(" after the FUNCNAME, which is what we have now. */
7157 expr
.value
= build_function_call_vec (op_loc
, expr
.value
, exprlist
,
7159 expr
.original_code
= ERROR_MARK
;
7160 if (TREE_CODE (expr
.value
) == INTEGER_CST
7161 && TREE_CODE (orig_expr
.value
) == FUNCTION_DECL
7162 && DECL_BUILT_IN_CLASS (orig_expr
.value
) == BUILT_IN_NORMAL
7163 && DECL_FUNCTION_CODE (orig_expr
.value
) == BUILT_IN_CONSTANT_P
)
7164 expr
.original_code
= C_MAYBE_CONST_EXPR
;
7165 expr
.original_type
= NULL
;
7166 if (exprlist
!= NULL
)
7168 release_tree_vector (exprlist
);
7169 release_tree_vector (origtypes
);
7173 /* Structure element reference. */
7174 c_parser_consume_token (parser
);
7175 expr
= default_function_array_conversion (expr_loc
, expr
);
7176 if (c_parser_next_token_is (parser
, CPP_NAME
))
7177 ident
= c_parser_peek_token (parser
)->value
;
7180 c_parser_error (parser
, "expected identifier");
7181 expr
.value
= error_mark_node
;
7182 expr
.original_code
= ERROR_MARK
;
7183 expr
.original_type
= NULL
;
7186 c_parser_consume_token (parser
);
7187 expr
.value
= build_component_ref (op_loc
, expr
.value
, ident
);
7188 expr
.original_code
= ERROR_MARK
;
7189 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
7190 expr
.original_type
= NULL
;
7193 /* Remember the original type of a bitfield. */
7194 tree field
= TREE_OPERAND (expr
.value
, 1);
7195 if (TREE_CODE (field
) != FIELD_DECL
)
7196 expr
.original_type
= NULL
;
7198 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
7202 /* Structure element reference. */
7203 c_parser_consume_token (parser
);
7204 expr
= default_function_array_conversion (expr_loc
, expr
);
7205 if (c_parser_next_token_is (parser
, CPP_NAME
))
7206 ident
= c_parser_peek_token (parser
)->value
;
7209 c_parser_error (parser
, "expected identifier");
7210 expr
.value
= error_mark_node
;
7211 expr
.original_code
= ERROR_MARK
;
7212 expr
.original_type
= NULL
;
7215 c_parser_consume_token (parser
);
7216 expr
.value
= build_component_ref (op_loc
,
7217 build_indirect_ref (op_loc
,
7221 expr
.original_code
= ERROR_MARK
;
7222 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
7223 expr
.original_type
= NULL
;
7226 /* Remember the original type of a bitfield. */
7227 tree field
= TREE_OPERAND (expr
.value
, 1);
7228 if (TREE_CODE (field
) != FIELD_DECL
)
7229 expr
.original_type
= NULL
;
7231 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
7235 /* Postincrement. */
7236 c_parser_consume_token (parser
);
7237 expr
= default_function_array_read_conversion (expr_loc
, expr
);
7238 expr
.value
= build_unary_op (op_loc
,
7239 POSTINCREMENT_EXPR
, expr
.value
, 0);
7240 expr
.original_code
= ERROR_MARK
;
7241 expr
.original_type
= NULL
;
7243 case CPP_MINUS_MINUS
:
7244 /* Postdecrement. */
7245 c_parser_consume_token (parser
);
7246 expr
= default_function_array_read_conversion (expr_loc
, expr
);
7247 expr
.value
= build_unary_op (op_loc
,
7248 POSTDECREMENT_EXPR
, expr
.value
, 0);
7249 expr
.original_code
= ERROR_MARK
;
7250 expr
.original_type
= NULL
;
7258 /* Parse an expression (C90 6.3.17, C99 6.5.17).
7261 assignment-expression
7262 expression , assignment-expression
7265 static struct c_expr
7266 c_parser_expression (c_parser
*parser
)
7269 expr
= c_parser_expr_no_commas (parser
, NULL
);
7270 while (c_parser_next_token_is (parser
, CPP_COMMA
))
7274 location_t loc
= c_parser_peek_token (parser
)->location
;
7275 location_t expr_loc
;
7276 c_parser_consume_token (parser
);
7277 expr_loc
= c_parser_peek_token (parser
)->location
;
7278 lhsval
= expr
.value
;
7279 while (TREE_CODE (lhsval
) == COMPOUND_EXPR
)
7280 lhsval
= TREE_OPERAND (lhsval
, 1);
7281 if (DECL_P (lhsval
) || handled_component_p (lhsval
))
7282 mark_exp_read (lhsval
);
7283 next
= c_parser_expr_no_commas (parser
, NULL
);
7284 next
= default_function_array_conversion (expr_loc
, next
);
7285 expr
.value
= build_compound_expr (loc
, expr
.value
, next
.value
);
7286 expr
.original_code
= COMPOUND_EXPR
;
7287 expr
.original_type
= next
.original_type
;
7292 /* Parse an expression and convert functions or arrays to
7295 static struct c_expr
7296 c_parser_expression_conv (c_parser
*parser
)
7299 location_t loc
= c_parser_peek_token (parser
)->location
;
7300 expr
= c_parser_expression (parser
);
7301 expr
= default_function_array_conversion (loc
, expr
);
7305 /* Parse a non-empty list of expressions. If CONVERT_P, convert
7306 functions and arrays to pointers. If FOLD_P, fold the expressions.
7309 assignment-expression
7310 nonempty-expr-list , assignment-expression
7313 static VEC(tree
,gc
) *
7314 c_parser_expr_list (c_parser
*parser
, bool convert_p
, bool fold_p
,
7315 VEC(tree
,gc
) **p_orig_types
,
7316 struct c_tree_loc_pair
*sizeof_arg
)
7319 VEC(tree
,gc
) *orig_types
;
7321 location_t loc
= c_parser_peek_token (parser
)->location
;
7322 location_t sizeof_arg_loc
= UNKNOWN_LOCATION
;
7324 ret
= make_tree_vector ();
7325 if (p_orig_types
== NULL
)
7328 orig_types
= make_tree_vector ();
7330 if (sizeof_arg
!= NULL
7331 && c_parser_next_token_is_keyword (parser
, RID_SIZEOF
))
7332 sizeof_arg_loc
= c_parser_peek_2nd_token (parser
)->location
;
7333 expr
= c_parser_expr_no_commas (parser
, NULL
);
7335 expr
= default_function_array_read_conversion (loc
, expr
);
7337 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
7338 VEC_quick_push (tree
, ret
, expr
.value
);
7339 if (orig_types
!= NULL
)
7340 VEC_quick_push (tree
, orig_types
, expr
.original_type
);
7341 while (c_parser_next_token_is (parser
, CPP_COMMA
))
7343 c_parser_consume_token (parser
);
7344 loc
= c_parser_peek_token (parser
)->location
;
7345 if (sizeof_arg
!= NULL
7346 && c_parser_next_token_is_keyword (parser
, RID_SIZEOF
))
7347 sizeof_arg_loc
= c_parser_peek_2nd_token (parser
)->location
;
7349 sizeof_arg_loc
= UNKNOWN_LOCATION
;
7350 expr
= c_parser_expr_no_commas (parser
, NULL
);
7352 expr
= default_function_array_read_conversion (loc
, expr
);
7354 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
7355 VEC_safe_push (tree
, gc
, ret
, expr
.value
);
7356 if (orig_types
!= NULL
)
7357 VEC_safe_push (tree
, gc
, orig_types
, expr
.original_type
);
7359 if (sizeof_arg
!= NULL
)
7361 if (sizeof_arg_loc
!= UNKNOWN_LOCATION
7362 && expr
.original_code
== SIZEOF_EXPR
)
7364 sizeof_arg
->expr
= c_last_sizeof_arg
;
7365 sizeof_arg
->loc
= sizeof_arg_loc
;
7369 sizeof_arg
->expr
= NULL_TREE
;
7370 sizeof_arg
->loc
= UNKNOWN_LOCATION
;
7373 if (orig_types
!= NULL
)
7374 *p_orig_types
= orig_types
;
7378 /* Parse Objective-C-specific constructs. */
7380 /* Parse an objc-class-definition.
7382 objc-class-definition:
7383 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
7384 objc-class-instance-variables[opt] objc-methodprotolist @end
7385 @implementation identifier objc-superclass[opt]
7386 objc-class-instance-variables[opt]
7387 @interface identifier ( identifier ) objc-protocol-refs[opt]
7388 objc-methodprotolist @end
7389 @interface identifier ( ) objc-protocol-refs[opt]
7390 objc-methodprotolist @end
7391 @implementation identifier ( identifier )
7396 "@interface identifier (" must start "@interface identifier (
7397 identifier ) ...": objc-methodprotolist in the first production may
7398 not start with a parenthesized identifier as a declarator of a data
7399 definition with no declaration specifiers if the objc-superclass,
7400 objc-protocol-refs and objc-class-instance-variables are omitted. */
7403 c_parser_objc_class_definition (c_parser
*parser
, tree attributes
)
7408 if (c_parser_next_token_is_keyword (parser
, RID_AT_INTERFACE
))
7410 else if (c_parser_next_token_is_keyword (parser
, RID_AT_IMPLEMENTATION
))
7415 c_parser_consume_token (parser
);
7416 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7418 c_parser_error (parser
, "expected identifier");
7421 id1
= c_parser_peek_token (parser
)->value
;
7422 c_parser_consume_token (parser
);
7423 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
7425 /* We have a category or class extension. */
7427 tree proto
= NULL_TREE
;
7428 c_parser_consume_token (parser
);
7429 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7431 if (iface_p
&& c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
7433 /* We have a class extension. */
7438 c_parser_error (parser
, "expected identifier or %<)%>");
7439 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7445 id2
= c_parser_peek_token (parser
)->value
;
7446 c_parser_consume_token (parser
);
7448 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7451 objc_start_category_implementation (id1
, id2
);
7454 if (c_parser_next_token_is (parser
, CPP_LESS
))
7455 proto
= c_parser_objc_protocol_refs (parser
);
7456 objc_start_category_interface (id1
, id2
, proto
, attributes
);
7457 c_parser_objc_methodprotolist (parser
);
7458 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
7459 objc_finish_interface ();
7462 if (c_parser_next_token_is (parser
, CPP_COLON
))
7464 c_parser_consume_token (parser
);
7465 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7467 c_parser_error (parser
, "expected identifier");
7470 superclass
= c_parser_peek_token (parser
)->value
;
7471 c_parser_consume_token (parser
);
7474 superclass
= NULL_TREE
;
7477 tree proto
= NULL_TREE
;
7478 if (c_parser_next_token_is (parser
, CPP_LESS
))
7479 proto
= c_parser_objc_protocol_refs (parser
);
7480 objc_start_class_interface (id1
, superclass
, proto
, attributes
);
7483 objc_start_class_implementation (id1
, superclass
);
7484 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
7485 c_parser_objc_class_instance_variables (parser
);
7488 objc_continue_interface ();
7489 c_parser_objc_methodprotolist (parser
);
7490 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
7491 objc_finish_interface ();
7495 objc_continue_implementation ();
7500 /* Parse objc-class-instance-variables.
7502 objc-class-instance-variables:
7503 { objc-instance-variable-decl-list[opt] }
7505 objc-instance-variable-decl-list:
7506 objc-visibility-spec
7507 objc-instance-variable-decl ;
7509 objc-instance-variable-decl-list objc-visibility-spec
7510 objc-instance-variable-decl-list objc-instance-variable-decl ;
7511 objc-instance-variable-decl-list ;
7513 objc-visibility-spec:
7518 objc-instance-variable-decl:
7523 c_parser_objc_class_instance_variables (c_parser
*parser
)
7525 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
7526 c_parser_consume_token (parser
);
7527 while (c_parser_next_token_is_not (parser
, CPP_EOF
))
7530 /* Parse any stray semicolon. */
7531 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
7533 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
7535 c_parser_consume_token (parser
);
7538 /* Stop if at the end of the instance variables. */
7539 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
7541 c_parser_consume_token (parser
);
7544 /* Parse any objc-visibility-spec. */
7545 if (c_parser_next_token_is_keyword (parser
, RID_AT_PRIVATE
))
7547 c_parser_consume_token (parser
);
7548 objc_set_visibility (OBJC_IVAR_VIS_PRIVATE
);
7551 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROTECTED
))
7553 c_parser_consume_token (parser
);
7554 objc_set_visibility (OBJC_IVAR_VIS_PROTECTED
);
7557 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PUBLIC
))
7559 c_parser_consume_token (parser
);
7560 objc_set_visibility (OBJC_IVAR_VIS_PUBLIC
);
7563 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PACKAGE
))
7565 c_parser_consume_token (parser
);
7566 objc_set_visibility (OBJC_IVAR_VIS_PACKAGE
);
7569 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
7571 c_parser_pragma (parser
, pragma_external
);
7575 /* Parse some comma-separated declarations. */
7576 decls
= c_parser_struct_declaration (parser
);
7579 /* There is a syntax error. We want to skip the offending
7580 tokens up to the next ';' (included) or '}'
7583 /* First, skip manually a ')' or ']'. This is because they
7584 reduce the nesting level, so c_parser_skip_until_found()
7585 wouldn't be able to skip past them. */
7586 c_token
*token
= c_parser_peek_token (parser
);
7587 if (token
->type
== CPP_CLOSE_PAREN
|| token
->type
== CPP_CLOSE_SQUARE
)
7588 c_parser_consume_token (parser
);
7590 /* Then, do the standard skipping. */
7591 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
7593 /* We hopefully recovered. Start normal parsing again. */
7594 parser
->error
= false;
7599 /* Comma-separated instance variables are chained together
7600 in reverse order; add them one by one. */
7601 tree ivar
= nreverse (decls
);
7602 for (; ivar
; ivar
= DECL_CHAIN (ivar
))
7603 objc_add_instance_variable (copy_node (ivar
));
7605 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7609 /* Parse an objc-class-declaration.
7611 objc-class-declaration:
7612 @class identifier-list ;
7616 c_parser_objc_class_declaration (c_parser
*parser
)
7618 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_CLASS
));
7619 c_parser_consume_token (parser
);
7620 /* Any identifiers, including those declared as type names, are OK
7625 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7627 c_parser_error (parser
, "expected identifier");
7628 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
7629 parser
->error
= false;
7632 id
= c_parser_peek_token (parser
)->value
;
7633 objc_declare_class (id
);
7634 c_parser_consume_token (parser
);
7635 if (c_parser_next_token_is (parser
, CPP_COMMA
))
7636 c_parser_consume_token (parser
);
7640 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7643 /* Parse an objc-alias-declaration.
7645 objc-alias-declaration:
7646 @compatibility_alias identifier identifier ;
7650 c_parser_objc_alias_declaration (c_parser
*parser
)
7653 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_ALIAS
));
7654 c_parser_consume_token (parser
);
7655 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7657 c_parser_error (parser
, "expected identifier");
7658 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
7661 id1
= c_parser_peek_token (parser
)->value
;
7662 c_parser_consume_token (parser
);
7663 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7665 c_parser_error (parser
, "expected identifier");
7666 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
7669 id2
= c_parser_peek_token (parser
)->value
;
7670 c_parser_consume_token (parser
);
7671 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7672 objc_declare_alias (id1
, id2
);
7675 /* Parse an objc-protocol-definition.
7677 objc-protocol-definition:
7678 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
7679 @protocol identifier-list ;
7681 "@protocol identifier ;" should be resolved as "@protocol
7682 identifier-list ;": objc-methodprotolist may not start with a
7683 semicolon in the first alternative if objc-protocol-refs are
7687 c_parser_objc_protocol_definition (c_parser
*parser
, tree attributes
)
7689 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROTOCOL
));
7691 c_parser_consume_token (parser
);
7692 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7694 c_parser_error (parser
, "expected identifier");
7697 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
7698 || c_parser_peek_2nd_token (parser
)->type
== CPP_SEMICOLON
)
7700 /* Any identifiers, including those declared as type names, are
7705 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7707 c_parser_error (parser
, "expected identifier");
7710 id
= c_parser_peek_token (parser
)->value
;
7711 objc_declare_protocol (id
, attributes
);
7712 c_parser_consume_token (parser
);
7713 if (c_parser_next_token_is (parser
, CPP_COMMA
))
7714 c_parser_consume_token (parser
);
7718 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7722 tree id
= c_parser_peek_token (parser
)->value
;
7723 tree proto
= NULL_TREE
;
7724 c_parser_consume_token (parser
);
7725 if (c_parser_next_token_is (parser
, CPP_LESS
))
7726 proto
= c_parser_objc_protocol_refs (parser
);
7727 parser
->objc_pq_context
= true;
7728 objc_start_protocol (id
, proto
, attributes
);
7729 c_parser_objc_methodprotolist (parser
);
7730 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
7731 parser
->objc_pq_context
= false;
7732 objc_finish_interface ();
7736 /* Parse an objc-method-type.
7742 Return true if it is a class method (+) and false if it is
7743 an instance method (-).
7746 c_parser_objc_method_type (c_parser
*parser
)
7748 switch (c_parser_peek_token (parser
)->type
)
7751 c_parser_consume_token (parser
);
7754 c_parser_consume_token (parser
);
7761 /* Parse an objc-method-definition.
7763 objc-method-definition:
7764 objc-method-type objc-method-decl ;[opt] compound-statement
7768 c_parser_objc_method_definition (c_parser
*parser
)
7770 bool is_class_method
= c_parser_objc_method_type (parser
);
7771 tree decl
, attributes
= NULL_TREE
, expr
= NULL_TREE
;
7772 parser
->objc_pq_context
= true;
7773 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
7775 if (decl
== error_mark_node
)
7776 return; /* Bail here. */
7778 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
7780 c_parser_consume_token (parser
);
7781 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
7782 "extra semicolon in method definition specified");
7785 if (!c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
7787 c_parser_error (parser
, "expected %<{%>");
7791 parser
->objc_pq_context
= false;
7792 if (objc_start_method_definition (is_class_method
, decl
, attributes
, expr
))
7794 add_stmt (c_parser_compound_statement (parser
));
7795 objc_finish_method_definition (current_function_decl
);
7799 /* This code is executed when we find a method definition
7800 outside of an @implementation context (or invalid for other
7801 reasons). Parse the method (to keep going) but do not emit
7804 c_parser_compound_statement (parser
);
7808 /* Parse an objc-methodprotolist.
7810 objc-methodprotolist:
7812 objc-methodprotolist objc-methodproto
7813 objc-methodprotolist declaration
7814 objc-methodprotolist ;
7818 The declaration is a data definition, which may be missing
7819 declaration specifiers under the same rules and diagnostics as
7820 other data definitions outside functions, and the stray semicolon
7821 is diagnosed the same way as a stray semicolon outside a
7825 c_parser_objc_methodprotolist (c_parser
*parser
)
7829 /* The list is terminated by @end. */
7830 switch (c_parser_peek_token (parser
)->type
)
7833 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
7834 "ISO C does not allow extra %<;%> outside of a function");
7835 c_parser_consume_token (parser
);
7839 c_parser_objc_methodproto (parser
);
7842 c_parser_pragma (parser
, pragma_external
);
7847 if (c_parser_next_token_is_keyword (parser
, RID_AT_END
))
7849 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
))
7850 c_parser_objc_at_property_declaration (parser
);
7851 else if (c_parser_next_token_is_keyword (parser
, RID_AT_OPTIONAL
))
7853 objc_set_method_opt (true);
7854 c_parser_consume_token (parser
);
7856 else if (c_parser_next_token_is_keyword (parser
, RID_AT_REQUIRED
))
7858 objc_set_method_opt (false);
7859 c_parser_consume_token (parser
);
7862 c_parser_declaration_or_fndef (parser
, false, false, true,
7869 /* Parse an objc-methodproto.
7872 objc-method-type objc-method-decl ;
7876 c_parser_objc_methodproto (c_parser
*parser
)
7878 bool is_class_method
= c_parser_objc_method_type (parser
);
7879 tree decl
, attributes
= NULL_TREE
;
7881 /* Remember protocol qualifiers in prototypes. */
7882 parser
->objc_pq_context
= true;
7883 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
7885 /* Forget protocol qualifiers now. */
7886 parser
->objc_pq_context
= false;
7888 /* Do not allow the presence of attributes to hide an erroneous
7889 method implementation in the interface section. */
7890 if (!c_parser_next_token_is (parser
, CPP_SEMICOLON
))
7892 c_parser_error (parser
, "expected %<;%>");
7896 if (decl
!= error_mark_node
)
7897 objc_add_method_declaration (is_class_method
, decl
, attributes
);
7899 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7902 /* If we are at a position that method attributes may be present, check that
7903 there are not any parsed already (a syntax error) and then collect any
7904 specified at the current location. Finally, if new attributes were present,
7905 check that the next token is legal ( ';' for decls and '{' for defs). */
7908 c_parser_objc_maybe_method_attributes (c_parser
* parser
, tree
* attributes
)
7913 c_parser_error (parser
,
7914 "method attributes must be specified at the end only");
7915 *attributes
= NULL_TREE
;
7919 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
7920 *attributes
= c_parser_attributes (parser
);
7922 /* If there were no attributes here, just report any earlier error. */
7923 if (*attributes
== NULL_TREE
|| bad
)
7926 /* If the attributes are followed by a ; or {, then just report any earlier
7928 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
7929 || c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
7932 /* We've got attributes, but not at the end. */
7933 c_parser_error (parser
,
7934 "expected %<;%> or %<{%> after method attribute definition");
7938 /* Parse an objc-method-decl.
7941 ( objc-type-name ) objc-selector
7943 ( objc-type-name ) objc-keyword-selector objc-optparmlist
7944 objc-keyword-selector objc-optparmlist
7947 objc-keyword-selector:
7949 objc-keyword-selector objc-keyword-decl
7952 objc-selector : ( objc-type-name ) identifier
7953 objc-selector : identifier
7954 : ( objc-type-name ) identifier
7958 objc-optparms objc-optellipsis
7962 objc-opt-parms , parameter-declaration
7970 c_parser_objc_method_decl (c_parser
*parser
, bool is_class_method
,
7971 tree
*attributes
, tree
*expr
)
7973 tree type
= NULL_TREE
;
7975 tree parms
= NULL_TREE
;
7976 bool ellipsis
= false;
7977 bool attr_err
= false;
7979 *attributes
= NULL_TREE
;
7980 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
7982 c_parser_consume_token (parser
);
7983 type
= c_parser_objc_type_name (parser
);
7984 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7986 sel
= c_parser_objc_selector (parser
);
7987 /* If there is no selector, or a colon follows, we have an
7988 objc-keyword-selector. If there is a selector, and a colon does
7989 not follow, that selector ends the objc-method-decl. */
7990 if (!sel
|| c_parser_next_token_is (parser
, CPP_COLON
))
7993 tree list
= NULL_TREE
;
7996 tree atype
= NULL_TREE
, id
, keyworddecl
;
7997 tree param_attr
= NULL_TREE
;
7998 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
8000 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8002 c_parser_consume_token (parser
);
8003 atype
= c_parser_objc_type_name (parser
);
8004 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
8007 /* New ObjC allows attributes on method parameters. */
8008 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
8009 param_attr
= c_parser_attributes (parser
);
8010 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8012 c_parser_error (parser
, "expected identifier");
8013 return error_mark_node
;
8015 id
= c_parser_peek_token (parser
)->value
;
8016 c_parser_consume_token (parser
);
8017 keyworddecl
= objc_build_keyword_decl (tsel
, atype
, id
, param_attr
);
8018 list
= chainon (list
, keyworddecl
);
8019 tsel
= c_parser_objc_selector (parser
);
8020 if (!tsel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
8024 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
8026 /* Parse the optional parameter list. Optional Objective-C
8027 method parameters follow the C syntax, and may include '...'
8028 to denote a variable number of arguments. */
8029 parms
= make_node (TREE_LIST
);
8030 while (c_parser_next_token_is (parser
, CPP_COMMA
))
8032 struct c_parm
*parm
;
8033 c_parser_consume_token (parser
);
8034 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
8037 c_parser_consume_token (parser
);
8038 attr_err
|= c_parser_objc_maybe_method_attributes
8039 (parser
, attributes
) ;
8042 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
8045 parms
= chainon (parms
,
8046 build_tree_list (NULL_TREE
, grokparm (parm
, expr
)));
8051 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
8055 c_parser_error (parser
, "objective-c method declaration is expected");
8056 return error_mark_node
;
8060 return error_mark_node
;
8062 return objc_build_method_signature (is_class_method
, type
, sel
, parms
, ellipsis
);
8065 /* Parse an objc-type-name.
8068 objc-type-qualifiers[opt] type-name
8069 objc-type-qualifiers[opt]
8071 objc-type-qualifiers:
8073 objc-type-qualifiers objc-type-qualifier
8075 objc-type-qualifier: one of
8076 in out inout bycopy byref oneway
8080 c_parser_objc_type_name (c_parser
*parser
)
8082 tree quals
= NULL_TREE
;
8083 struct c_type_name
*type_name
= NULL
;
8084 tree type
= NULL_TREE
;
8087 c_token
*token
= c_parser_peek_token (parser
);
8088 if (token
->type
== CPP_KEYWORD
8089 && (token
->keyword
== RID_IN
8090 || token
->keyword
== RID_OUT
8091 || token
->keyword
== RID_INOUT
8092 || token
->keyword
== RID_BYCOPY
8093 || token
->keyword
== RID_BYREF
8094 || token
->keyword
== RID_ONEWAY
))
8096 quals
= chainon (build_tree_list (NULL_TREE
, token
->value
), quals
);
8097 c_parser_consume_token (parser
);
8102 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
8103 type_name
= c_parser_type_name (parser
);
8105 type
= groktypename (type_name
, NULL
, NULL
);
8107 /* If the type is unknown, and error has already been produced and
8108 we need to recover from the error. In that case, use NULL_TREE
8109 for the type, as if no type had been specified; this will use the
8110 default type ('id') which is good for error recovery. */
8111 if (type
== error_mark_node
)
8114 return build_tree_list (quals
, type
);
8117 /* Parse objc-protocol-refs.
8124 c_parser_objc_protocol_refs (c_parser
*parser
)
8126 tree list
= NULL_TREE
;
8127 gcc_assert (c_parser_next_token_is (parser
, CPP_LESS
));
8128 c_parser_consume_token (parser
);
8129 /* Any identifiers, including those declared as type names, are OK
8134 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8136 c_parser_error (parser
, "expected identifier");
8139 id
= c_parser_peek_token (parser
)->value
;
8140 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
8141 c_parser_consume_token (parser
);
8142 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8143 c_parser_consume_token (parser
);
8147 c_parser_require (parser
, CPP_GREATER
, "expected %<>%>");
8151 /* Parse an objc-try-catch-finally-statement.
8153 objc-try-catch-finally-statement:
8154 @try compound-statement objc-catch-list[opt]
8155 @try compound-statement objc-catch-list[opt] @finally compound-statement
8158 @catch ( objc-catch-parameter-declaration ) compound-statement
8159 objc-catch-list @catch ( objc-catch-parameter-declaration ) compound-statement
8161 objc-catch-parameter-declaration:
8162 parameter-declaration
8165 where '...' is to be interpreted literally, that is, it means CPP_ELLIPSIS.
8167 PS: This function is identical to cp_parser_objc_try_catch_finally_statement
8168 for C++. Keep them in sync. */
8171 c_parser_objc_try_catch_finally_statement (c_parser
*parser
)
8173 location_t location
;
8176 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_TRY
));
8177 c_parser_consume_token (parser
);
8178 location
= c_parser_peek_token (parser
)->location
;
8179 objc_maybe_warn_exceptions (location
);
8180 stmt
= c_parser_compound_statement (parser
);
8181 objc_begin_try_stmt (location
, stmt
);
8183 while (c_parser_next_token_is_keyword (parser
, RID_AT_CATCH
))
8185 struct c_parm
*parm
;
8186 tree parameter_declaration
= error_mark_node
;
8187 bool seen_open_paren
= false;
8189 c_parser_consume_token (parser
);
8190 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8191 seen_open_paren
= true;
8192 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
8194 /* We have "@catch (...)" (where the '...' are literally
8195 what is in the code). Skip the '...'.
8196 parameter_declaration is set to NULL_TREE, and
8197 objc_being_catch_clauses() knows that that means
8199 c_parser_consume_token (parser
);
8200 parameter_declaration
= NULL_TREE
;
8204 /* We have "@catch (NSException *exception)" or something
8205 like that. Parse the parameter declaration. */
8206 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
8208 parameter_declaration
= error_mark_node
;
8210 parameter_declaration
= grokparm (parm
, NULL
);
8212 if (seen_open_paren
)
8213 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8216 /* If there was no open parenthesis, we are recovering from
8217 an error, and we are trying to figure out what mistake
8218 the user has made. */
8220 /* If there is an immediate closing parenthesis, the user
8221 probably forgot the opening one (ie, they typed "@catch
8222 NSException *e)". Parse the closing parenthesis and keep
8224 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
8225 c_parser_consume_token (parser
);
8227 /* If these is no immediate closing parenthesis, the user
8228 probably doesn't know that parenthesis are required at
8229 all (ie, they typed "@catch NSException *e"). So, just
8230 forget about the closing parenthesis and keep going. */
8232 objc_begin_catch_clause (parameter_declaration
);
8233 if (c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
8234 c_parser_compound_statement_nostart (parser
);
8235 objc_finish_catch_clause ();
8237 if (c_parser_next_token_is_keyword (parser
, RID_AT_FINALLY
))
8239 c_parser_consume_token (parser
);
8240 location
= c_parser_peek_token (parser
)->location
;
8241 stmt
= c_parser_compound_statement (parser
);
8242 objc_build_finally_clause (location
, stmt
);
8244 objc_finish_try_stmt ();
8247 /* Parse an objc-synchronized-statement.
8249 objc-synchronized-statement:
8250 @synchronized ( expression ) compound-statement
8254 c_parser_objc_synchronized_statement (c_parser
*parser
)
8258 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNCHRONIZED
));
8259 c_parser_consume_token (parser
);
8260 loc
= c_parser_peek_token (parser
)->location
;
8261 objc_maybe_warn_exceptions (loc
);
8262 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8264 expr
= c_parser_expression (parser
).value
;
8265 expr
= c_fully_fold (expr
, false, NULL
);
8266 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8269 expr
= error_mark_node
;
8270 stmt
= c_parser_compound_statement (parser
);
8271 objc_build_synchronized (loc
, expr
, stmt
);
8274 /* Parse an objc-selector; return NULL_TREE without an error if the
8275 next token is not an objc-selector.
8280 enum struct union if else while do for switch case default
8281 break continue return goto asm sizeof typeof __alignof
8282 unsigned long const short volatile signed restrict _Complex
8283 in out inout bycopy byref oneway int char float double void _Bool
8285 ??? Why this selection of keywords but not, for example, storage
8286 class specifiers? */
8289 c_parser_objc_selector (c_parser
*parser
)
8291 c_token
*token
= c_parser_peek_token (parser
);
8292 tree value
= token
->value
;
8293 if (token
->type
== CPP_NAME
)
8295 c_parser_consume_token (parser
);
8298 if (token
->type
!= CPP_KEYWORD
)
8300 switch (token
->keyword
)
8342 c_parser_consume_token (parser
);
8349 /* Parse an objc-selector-arg.
8353 objc-keywordname-list
8355 objc-keywordname-list:
8357 objc-keywordname-list objc-keywordname
8365 c_parser_objc_selector_arg (c_parser
*parser
)
8367 tree sel
= c_parser_objc_selector (parser
);
8368 tree list
= NULL_TREE
;
8369 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
8373 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
8375 list
= chainon (list
, build_tree_list (sel
, NULL_TREE
));
8376 sel
= c_parser_objc_selector (parser
);
8377 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
8383 /* Parse an objc-receiver.
8392 c_parser_objc_receiver (c_parser
*parser
)
8394 if (c_parser_peek_token (parser
)->type
== CPP_NAME
8395 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
8396 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
8398 tree id
= c_parser_peek_token (parser
)->value
;
8399 c_parser_consume_token (parser
);
8400 return objc_get_class_reference (id
);
8402 return c_fully_fold (c_parser_expression (parser
).value
, false, NULL
);
8405 /* Parse objc-message-args.
8409 objc-keywordarg-list
8411 objc-keywordarg-list:
8413 objc-keywordarg-list objc-keywordarg
8416 objc-selector : objc-keywordexpr
8421 c_parser_objc_message_args (c_parser
*parser
)
8423 tree sel
= c_parser_objc_selector (parser
);
8424 tree list
= NULL_TREE
;
8425 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
8430 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
8431 return error_mark_node
;
8432 keywordexpr
= c_parser_objc_keywordexpr (parser
);
8433 list
= chainon (list
, build_tree_list (sel
, keywordexpr
));
8434 sel
= c_parser_objc_selector (parser
);
8435 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
8441 /* Parse an objc-keywordexpr.
8448 c_parser_objc_keywordexpr (c_parser
*parser
)
8451 VEC(tree
,gc
) *expr_list
= c_parser_expr_list (parser
, true, true,
8453 if (VEC_length (tree
, expr_list
) == 1)
8455 /* Just return the expression, remove a level of
8457 ret
= VEC_index (tree
, expr_list
, 0);
8461 /* We have a comma expression, we will collapse later. */
8462 ret
= build_tree_list_vec (expr_list
);
8464 release_tree_vector (expr_list
);
8468 /* A check, needed in several places, that ObjC interface, implementation or
8469 method definitions are not prefixed by incorrect items. */
8471 c_parser_objc_diagnose_bad_element_prefix (c_parser
*parser
,
8472 struct c_declspecs
*specs
)
8474 if (!specs
->declspecs_seen_p
|| specs
->non_sc_seen_p
8475 || specs
->typespec_kind
!= ctsk_none
)
8477 c_parser_error (parser
,
8478 "no type or storage class may be specified here,");
8479 c_parser_skip_to_end_of_block_or_statement (parser
);
8485 /* Parse an Objective-C @property declaration. The syntax is:
8487 objc-property-declaration:
8488 '@property' objc-property-attributes[opt] struct-declaration ;
8490 objc-property-attributes:
8491 '(' objc-property-attribute-list ')'
8493 objc-property-attribute-list:
8494 objc-property-attribute
8495 objc-property-attribute-list, objc-property-attribute
8497 objc-property-attribute
8498 'getter' = identifier
8499 'setter' = identifier
8508 @property NSString *name;
8509 @property (readonly) id object;
8510 @property (retain, nonatomic, getter=getTheName) id name;
8511 @property int a, b, c;
8513 PS: This function is identical to cp_parser_objc_at_propery_declaration
8514 for C++. Keep them in sync. */
8516 c_parser_objc_at_property_declaration (c_parser
*parser
)
8518 /* The following variables hold the attributes of the properties as
8519 parsed. They are 'false' or 'NULL_TREE' if the attribute was not
8520 seen. When we see an attribute, we set them to 'true' (if they
8521 are boolean properties) or to the identifier (if they have an
8522 argument, ie, for getter and setter). Note that here we only
8523 parse the list of attributes, check the syntax and accumulate the
8524 attributes that we find. objc_add_property_declaration() will
8525 then process the information. */
8526 bool property_assign
= false;
8527 bool property_copy
= false;
8528 tree property_getter_ident
= NULL_TREE
;
8529 bool property_nonatomic
= false;
8530 bool property_readonly
= false;
8531 bool property_readwrite
= false;
8532 bool property_retain
= false;
8533 tree property_setter_ident
= NULL_TREE
;
8535 /* 'properties' is the list of properties that we read. Usually a
8536 single one, but maybe more (eg, in "@property int a, b, c;" there
8541 loc
= c_parser_peek_token (parser
)->location
;
8542 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
));
8544 c_parser_consume_token (parser
); /* Eat '@property'. */
8546 /* Parse the optional attribute list... */
8547 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8550 c_parser_consume_token (parser
);
8552 /* Property attribute keywords are valid now. */
8553 parser
->objc_property_attr_context
= true;
8557 bool syntax_error
= false;
8558 c_token
*token
= c_parser_peek_token (parser
);
8561 if (token
->type
!= CPP_KEYWORD
)
8563 if (token
->type
== CPP_CLOSE_PAREN
)
8564 c_parser_error (parser
, "expected identifier");
8567 c_parser_consume_token (parser
);
8568 c_parser_error (parser
, "unknown property attribute");
8572 keyword
= token
->keyword
;
8573 c_parser_consume_token (parser
);
8576 case RID_ASSIGN
: property_assign
= true; break;
8577 case RID_COPY
: property_copy
= true; break;
8578 case RID_NONATOMIC
: property_nonatomic
= true; break;
8579 case RID_READONLY
: property_readonly
= true; break;
8580 case RID_READWRITE
: property_readwrite
= true; break;
8581 case RID_RETAIN
: property_retain
= true; break;
8585 if (c_parser_next_token_is_not (parser
, CPP_EQ
))
8587 if (keyword
== RID_GETTER
)
8588 c_parser_error (parser
,
8589 "missing %<=%> (after %<getter%> attribute)");
8591 c_parser_error (parser
,
8592 "missing %<=%> (after %<setter%> attribute)");
8593 syntax_error
= true;
8596 c_parser_consume_token (parser
); /* eat the = */
8597 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8599 c_parser_error (parser
, "expected identifier");
8600 syntax_error
= true;
8603 if (keyword
== RID_SETTER
)
8605 if (property_setter_ident
!= NULL_TREE
)
8606 c_parser_error (parser
, "the %<setter%> attribute may only be specified once");
8608 property_setter_ident
= c_parser_peek_token (parser
)->value
;
8609 c_parser_consume_token (parser
);
8610 if (c_parser_next_token_is_not (parser
, CPP_COLON
))
8611 c_parser_error (parser
, "setter name must terminate with %<:%>");
8613 c_parser_consume_token (parser
);
8617 if (property_getter_ident
!= NULL_TREE
)
8618 c_parser_error (parser
, "the %<getter%> attribute may only be specified once");
8620 property_getter_ident
= c_parser_peek_token (parser
)->value
;
8621 c_parser_consume_token (parser
);
8625 c_parser_error (parser
, "unknown property attribute");
8626 syntax_error
= true;
8633 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8634 c_parser_consume_token (parser
);
8638 parser
->objc_property_attr_context
= false;
8639 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8641 /* ... and the property declaration(s). */
8642 properties
= c_parser_struct_declaration (parser
);
8644 if (properties
== error_mark_node
)
8646 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8647 parser
->error
= false;
8651 if (properties
== NULL_TREE
)
8652 c_parser_error (parser
, "expected identifier");
8655 /* Comma-separated properties are chained together in
8656 reverse order; add them one by one. */
8657 properties
= nreverse (properties
);
8659 for (; properties
; properties
= TREE_CHAIN (properties
))
8660 objc_add_property_declaration (loc
, copy_node (properties
),
8661 property_readonly
, property_readwrite
,
8662 property_assign
, property_retain
,
8663 property_copy
, property_nonatomic
,
8664 property_getter_ident
, property_setter_ident
);
8667 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8668 parser
->error
= false;
8671 /* Parse an Objective-C @synthesize declaration. The syntax is:
8673 objc-synthesize-declaration:
8674 @synthesize objc-synthesize-identifier-list ;
8676 objc-synthesize-identifier-list:
8677 objc-synthesize-identifier
8678 objc-synthesize-identifier-list, objc-synthesize-identifier
8680 objc-synthesize-identifier
8682 identifier = identifier
8685 @synthesize MyProperty;
8686 @synthesize OneProperty, AnotherProperty=MyIvar, YetAnotherProperty;
8688 PS: This function is identical to cp_parser_objc_at_synthesize_declaration
8689 for C++. Keep them in sync.
8692 c_parser_objc_at_synthesize_declaration (c_parser
*parser
)
8694 tree list
= NULL_TREE
;
8696 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNTHESIZE
));
8697 loc
= c_parser_peek_token (parser
)->location
;
8699 c_parser_consume_token (parser
);
8702 tree property
, ivar
;
8703 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8705 c_parser_error (parser
, "expected identifier");
8706 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8707 /* Once we find the semicolon, we can resume normal parsing.
8708 We have to reset parser->error manually because
8709 c_parser_skip_until_found() won't reset it for us if the
8710 next token is precisely a semicolon. */
8711 parser
->error
= false;
8714 property
= c_parser_peek_token (parser
)->value
;
8715 c_parser_consume_token (parser
);
8716 if (c_parser_next_token_is (parser
, CPP_EQ
))
8718 c_parser_consume_token (parser
);
8719 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8721 c_parser_error (parser
, "expected identifier");
8722 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8723 parser
->error
= false;
8726 ivar
= c_parser_peek_token (parser
)->value
;
8727 c_parser_consume_token (parser
);
8731 list
= chainon (list
, build_tree_list (ivar
, property
));
8732 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8733 c_parser_consume_token (parser
);
8737 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8738 objc_add_synthesize_declaration (loc
, list
);
8741 /* Parse an Objective-C @dynamic declaration. The syntax is:
8743 objc-dynamic-declaration:
8744 @dynamic identifier-list ;
8747 @dynamic MyProperty;
8748 @dynamic MyProperty, AnotherProperty;
8750 PS: This function is identical to cp_parser_objc_at_dynamic_declaration
8751 for C++. Keep them in sync.
8754 c_parser_objc_at_dynamic_declaration (c_parser
*parser
)
8756 tree list
= NULL_TREE
;
8758 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_DYNAMIC
));
8759 loc
= c_parser_peek_token (parser
)->location
;
8761 c_parser_consume_token (parser
);
8765 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8767 c_parser_error (parser
, "expected identifier");
8768 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8769 parser
->error
= false;
8772 property
= c_parser_peek_token (parser
)->value
;
8773 list
= chainon (list
, build_tree_list (NULL_TREE
, property
));
8774 c_parser_consume_token (parser
);
8775 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8776 c_parser_consume_token (parser
);
8780 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8781 objc_add_dynamic_declaration (loc
, list
);
8784 /* Parse UPC shared qualifier
8786 shared-type-qualifier: shared layout-qualifier-opt
8787 layout-qualifier: [ constant-expression-opt ] | [ * ]
8791 c_parser_upc_shared_qual (source_location loc
,
8793 struct c_declspecs
*specs
)
8795 tree array_qual
, arg1
;
8797 /* consume "shared" part */
8798 c_parser_consume_token (parser
);
8800 /* check for shared array layout specifier */
8801 if (!c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
8803 declspecs_add_qual (loc
, specs
, ridpointers
[RID_SHARED
]);
8806 c_parser_consume_token (parser
);
8807 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
8809 /* [] layout specifier */
8810 arg1
= size_zero_node
;
8812 else if (c_parser_next_token_is (parser
, CPP_MULT
))
8814 /* [*] layout specifier */
8815 arg1
= build1 (INDIRECT_REF
, NULL_TREE
, NULL_TREE
);
8816 c_parser_consume_token (parser
);
8820 /* [ expression ] layout specifier */
8821 arg1
= c_parser_expression (parser
).value
;
8823 array_qual
= build4 (ARRAY_REF
, NULL_TREE
, NULL_TREE
,
8824 arg1
, NULL_TREE
, NULL_TREE
);
8825 declspecs_add_qual (loc
, specs
, array_qual
);
8827 if (!c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
8829 c_parser_error (parser
, "expected ]");
8831 c_parser_consume_token (parser
);
8834 /* Parse a UPC upc_forall statement
8836 upc_forall-statement:
8837 upc_forall ( expression[opt] ; expression[opt] ;
8838 expression[opt] ; affinity[opt] ) statement
8839 affinity: experssion | continue */
8842 c_parser_upc_forall_statement (c_parser
*parser
)
8844 tree block
, cond
, incr
, save_break
, save_cont
, body
;
8846 location_t loc
= c_parser_peek_token (parser
)->location
;
8847 location_t affinity_loc
= UNKNOWN_LOCATION
;
8848 const int profile_upc_forall
= flag_upc_instrument
&& get_upc_pupc_mode();
8849 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_UPC_FORALL
));
8850 c_parser_consume_token (parser
);
8851 block
= c_begin_compound_stmt (flag_isoc99
);
8852 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8854 /* Parse the initialization declaration or expression. */
8855 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
8857 c_parser_consume_token (parser
);
8858 c_finish_expr_stmt (loc
, NULL_TREE
);
8860 else if (c_parser_next_token_starts_declspecs (parser
))
8862 c_parser_declaration_or_fndef (parser
, true, true, true,
8864 check_for_loop_decls (loc
, true);
8866 else if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
8868 /* __extension__ can start a declaration, but is also an
8869 unary operator that can start an expression. Consume all
8870 but the last of a possible series of __extension__ to
8872 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
8873 && (c_parser_peek_2nd_token (parser
)->keyword
8875 c_parser_consume_token (parser
);
8876 if (c_token_starts_declspecs (c_parser_peek_2nd_token (parser
)))
8879 ext
= disable_extension_diagnostics ();
8880 c_parser_consume_token (parser
);
8881 c_parser_declaration_or_fndef (parser
, true, true, true, true, true, NULL
);
8882 restore_extension_diagnostics (ext
);
8883 check_for_loop_decls (loc
, true);
8891 c_finish_expr_stmt (loc
, c_parser_expression (parser
).value
);
8892 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8894 /* Parse the loop condition. */
8895 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
8897 c_parser_consume_token (parser
);
8902 cond
= c_parser_condition (parser
);
8903 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8905 /* Parse the increment expression. */
8906 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
8907 incr
= c_process_expr_stmt (loc
, NULL_TREE
);
8909 incr
= c_process_expr_stmt (loc
, c_parser_expression (parser
).value
);
8910 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8911 /* Parse the UPC affinity expression. */
8912 affinity_loc
= c_parser_peek_token (parser
)->location
;
8913 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
8915 affinity
= NULL_TREE
;
8917 else if (c_parser_peek_token (parser
)->type
== CPP_KEYWORD
8918 && c_parser_peek_token (parser
)->keyword
== RID_CONTINUE
)
8920 affinity
= NULL_TREE
;
8921 c_parser_consume_token (parser
);
8925 affinity
= c_parser_expression_conv (parser
).value
;
8926 affinity
= c_fully_fold (affinity
, false, NULL
);
8928 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8930 affinity
= upc_affinity_test (affinity_loc
, affinity
);
8934 cond
= error_mark_node
;
8935 incr
= error_mark_node
;
8936 affinity
= error_mark_node
;
8938 save_break
= c_break_label
;
8939 c_break_label
= NULL_TREE
;
8940 save_cont
= c_cont_label
;
8941 c_cont_label
= NULL_TREE
;
8942 body
= c_parser_c99_block_statement (parser
);
8943 if (profile_upc_forall
)
8945 const tree gasp_start
= upc_instrument_forall (loc
, 1 /* start */);
8946 add_stmt (gasp_start
);
8948 loc
= c_parser_peek_token (parser
)->location
;
8949 if (affinity
!= NULL_TREE
&& affinity
!= error_mark_node
)
8951 tree upc_forall_depth
= upc_rts_forall_depth_var ();
8952 tree inc_depth
, depth_gt_one
;
8953 inc_depth
= build_unary_op (loc
, PREINCREMENT_EXPR
, upc_forall_depth
, 0);
8954 c_finish_expr_stmt (loc
, inc_depth
);
8955 depth_gt_one
= build_binary_op (affinity_loc
,
8956 GT_EXPR
, upc_forall_depth
, integer_one_node
, 0);
8957 depth_gt_one
= c_objc_common_truthvalue_conversion (affinity_loc
, depth_gt_one
);
8958 depth_gt_one
= c_fully_fold (depth_gt_one
, false, NULL
);
8959 affinity
= build_binary_op (affinity_loc
, TRUTH_OR_EXPR
,
8960 depth_gt_one
, affinity
, 0);
8961 body
= build3 (COND_EXPR
, void_type_node
, affinity
,
8963 c_finish_loop (loc
, cond
, incr
, body
, c_break_label
, c_cont_label
, true);
8964 c_finish_expr_stmt (loc
,
8965 build_unary_op (loc
, PREDECREMENT_EXPR
, upc_forall_depth
, 0));
8968 c_finish_loop (loc
, cond
, incr
, body
, c_break_label
, c_cont_label
, true);
8969 if (profile_upc_forall
)
8971 const tree gasp_end
= upc_instrument_forall (loc
, 0 /* start */);
8972 add_stmt (gasp_end
);
8974 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
8975 c_break_label
= save_break
;
8976 c_cont_label
= save_cont
;
8979 /* Parse an upc-sync-statement.
8981 upc_barrier, upc_wait, upc_notify
8985 c_parser_upc_sync_statement (c_parser
*parser
, int sync_kind
)
8988 tree expr
= NULL_TREE
;
8990 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_UPC_BARRIER
) ||
8991 c_parser_next_token_is_keyword (parser
, RID_UPC_NOTIFY
) ||
8992 c_parser_next_token_is_keyword (parser
, RID_UPC_WAIT
));
8993 loc
= c_parser_peek_token (parser
)->location
;
8994 c_parser_consume_token (parser
);
8995 if (c_parser_peek_token (parser
)->type
!= CPP_SEMICOLON
)
8997 expr
= c_parser_expression (parser
).value
;
8998 if (expr
== error_mark_node
)
9000 if (!INTEGRAL_TYPE_P (TREE_TYPE (expr
)))
9002 c_parser_error (parser
, "expected integer expression");
9006 stmt
= size_int (sync_kind
);
9007 (void) upc_build_sync_stmt (loc
, stmt
, expr
);
9011 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
9012 should be considered, statements. ALLOW_STMT is true if we're within
9013 the context of a function and such pragmas are to be allowed. Returns
9014 true if we actually parsed such a pragma. */
9017 c_parser_pragma (c_parser
*parser
, enum pragma_context context
)
9021 id
= c_parser_peek_token (parser
)->pragma_kind
;
9022 gcc_assert (id
!= PRAGMA_NONE
);
9026 case PRAGMA_OMP_BARRIER
:
9027 if (context
!= pragma_compound
)
9029 if (context
== pragma_stmt
)
9030 c_parser_error (parser
, "%<#pragma omp barrier%> may only be "
9031 "used in compound statements");
9034 c_parser_omp_barrier (parser
);
9037 case PRAGMA_OMP_FLUSH
:
9038 if (context
!= pragma_compound
)
9040 if (context
== pragma_stmt
)
9041 c_parser_error (parser
, "%<#pragma omp flush%> may only be "
9042 "used in compound statements");
9045 c_parser_omp_flush (parser
);
9048 case PRAGMA_OMP_TASKWAIT
:
9049 if (context
!= pragma_compound
)
9051 if (context
== pragma_stmt
)
9052 c_parser_error (parser
, "%<#pragma omp taskwait%> may only be "
9053 "used in compound statements");
9056 c_parser_omp_taskwait (parser
);
9059 case PRAGMA_OMP_TASKYIELD
:
9060 if (context
!= pragma_compound
)
9062 if (context
== pragma_stmt
)
9063 c_parser_error (parser
, "%<#pragma omp taskyield%> may only be "
9064 "used in compound statements");
9067 c_parser_omp_taskyield (parser
);
9070 case PRAGMA_OMP_THREADPRIVATE
:
9071 c_parser_omp_threadprivate (parser
);
9074 case PRAGMA_OMP_SECTION
:
9075 error_at (c_parser_peek_token (parser
)->location
,
9076 "%<#pragma omp section%> may only be used in "
9077 "%<#pragma omp sections%> construct");
9078 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
9081 case PRAGMA_GCC_PCH_PREPROCESS
:
9082 c_parser_error (parser
, "%<#pragma GCC pch_preprocess%> must be first");
9083 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
9087 if (id
< PRAGMA_FIRST_EXTERNAL
)
9089 if (context
== pragma_external
)
9092 c_parser_error (parser
, "expected declaration specifiers");
9093 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
9096 c_parser_omp_construct (parser
);
9102 c_parser_consume_pragma (parser
);
9103 c_invoke_pragma_handler (id
);
9105 /* Skip to EOL, but suppress any error message. Those will have been
9106 generated by the handler routine through calling error, as opposed
9107 to calling c_parser_error. */
9108 parser
->error
= true;
9109 c_parser_skip_to_pragma_eol (parser
);
9114 /* The interface the pragma parsers have to the lexer. */
9117 pragma_lex (tree
*value
)
9119 c_token
*tok
= c_parser_peek_token (the_parser
);
9120 enum cpp_ttype ret
= tok
->type
;
9122 *value
= tok
->value
;
9123 if (ret
== CPP_PRAGMA_EOL
|| ret
== CPP_EOF
)
9127 if (ret
== CPP_KEYWORD
)
9129 c_parser_consume_token (the_parser
);
9136 c_parser_pragma_pch_preprocess (c_parser
*parser
)
9140 c_parser_consume_pragma (parser
);
9141 if (c_parser_next_token_is (parser
, CPP_STRING
))
9143 name
= c_parser_peek_token (parser
)->value
;
9144 c_parser_consume_token (parser
);
9147 c_parser_error (parser
, "expected string literal");
9148 c_parser_skip_to_pragma_eol (parser
);
9151 c_common_pch_pragma (parse_in
, TREE_STRING_POINTER (name
));
9154 /* OpenMP 2.5 parsing routines. */
9156 /* Returns name of the next clause.
9157 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
9158 the token is not consumed. Otherwise appropriate pragma_omp_clause is
9159 returned and the token is consumed. */
9161 static pragma_omp_clause
9162 c_parser_omp_clause_name (c_parser
*parser
)
9164 pragma_omp_clause result
= PRAGMA_OMP_CLAUSE_NONE
;
9166 if (c_parser_next_token_is_keyword (parser
, RID_IF
))
9167 result
= PRAGMA_OMP_CLAUSE_IF
;
9168 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
9169 result
= PRAGMA_OMP_CLAUSE_DEFAULT
;
9170 else if (c_parser_next_token_is (parser
, CPP_NAME
))
9172 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
9177 if (!strcmp ("collapse", p
))
9178 result
= PRAGMA_OMP_CLAUSE_COLLAPSE
;
9179 else if (!strcmp ("copyin", p
))
9180 result
= PRAGMA_OMP_CLAUSE_COPYIN
;
9181 else if (!strcmp ("copyprivate", p
))
9182 result
= PRAGMA_OMP_CLAUSE_COPYPRIVATE
;
9185 if (!strcmp ("final", p
))
9186 result
= PRAGMA_OMP_CLAUSE_FINAL
;
9187 else if (!strcmp ("firstprivate", p
))
9188 result
= PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
;
9191 if (!strcmp ("lastprivate", p
))
9192 result
= PRAGMA_OMP_CLAUSE_LASTPRIVATE
;
9195 if (!strcmp ("mergeable", p
))
9196 result
= PRAGMA_OMP_CLAUSE_MERGEABLE
;
9199 if (!strcmp ("nowait", p
))
9200 result
= PRAGMA_OMP_CLAUSE_NOWAIT
;
9201 else if (!strcmp ("num_threads", p
))
9202 result
= PRAGMA_OMP_CLAUSE_NUM_THREADS
;
9205 if (!strcmp ("ordered", p
))
9206 result
= PRAGMA_OMP_CLAUSE_ORDERED
;
9209 if (!strcmp ("private", p
))
9210 result
= PRAGMA_OMP_CLAUSE_PRIVATE
;
9213 if (!strcmp ("reduction", p
))
9214 result
= PRAGMA_OMP_CLAUSE_REDUCTION
;
9217 if (!strcmp ("schedule", p
))
9218 result
= PRAGMA_OMP_CLAUSE_SCHEDULE
;
9219 else if (!strcmp ("shared", p
))
9220 result
= PRAGMA_OMP_CLAUSE_SHARED
;
9223 if (!strcmp ("untied", p
))
9224 result
= PRAGMA_OMP_CLAUSE_UNTIED
;
9229 if (result
!= PRAGMA_OMP_CLAUSE_NONE
)
9230 c_parser_consume_token (parser
);
9235 /* Validate that a clause of the given type does not already exist. */
9238 check_no_duplicate_clause (tree clauses
, enum omp_clause_code code
,
9243 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
9244 if (OMP_CLAUSE_CODE (c
) == code
)
9246 location_t loc
= OMP_CLAUSE_LOCATION (c
);
9247 error_at (loc
, "too many %qs clauses", name
);
9255 variable-list , identifier
9257 If KIND is nonzero, create the appropriate node and install the
9258 decl in OMP_CLAUSE_DECL and add the node to the head of the list.
9259 If KIND is nonzero, CLAUSE_LOC is the location of the clause.
9261 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
9262 return the list created. */
9265 c_parser_omp_variable_list (c_parser
*parser
,
9266 location_t clause_loc
,
9267 enum omp_clause_code kind
,
9270 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
9271 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
9272 c_parser_error (parser
, "expected identifier");
9274 while (c_parser_next_token_is (parser
, CPP_NAME
)
9275 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
9277 tree t
= lookup_name (c_parser_peek_token (parser
)->value
);
9280 undeclared_variable (c_parser_peek_token (parser
)->location
,
9281 c_parser_peek_token (parser
)->value
);
9282 else if (t
== error_mark_node
)
9286 tree u
= build_omp_clause (clause_loc
, kind
);
9287 OMP_CLAUSE_DECL (u
) = t
;
9288 OMP_CLAUSE_CHAIN (u
) = list
;
9292 list
= tree_cons (t
, NULL_TREE
, list
);
9294 c_parser_consume_token (parser
);
9296 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
9299 c_parser_consume_token (parser
);
9305 /* Similarly, but expect leading and trailing parenthesis. This is a very
9306 common case for omp clauses. */
9309 c_parser_omp_var_list_parens (c_parser
*parser
, enum omp_clause_code kind
,
9312 /* The clauses location. */
9313 location_t loc
= c_parser_peek_token (parser
)->location
;
9315 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9317 list
= c_parser_omp_variable_list (parser
, loc
, kind
, list
);
9318 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9324 collapse ( constant-expression ) */
9327 c_parser_omp_clause_collapse (c_parser
*parser
, tree list
)
9329 tree c
, num
= error_mark_node
;
9333 check_no_duplicate_clause (list
, OMP_CLAUSE_COLLAPSE
, "collapse");
9335 loc
= c_parser_peek_token (parser
)->location
;
9336 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9338 num
= c_parser_expr_no_commas (parser
, NULL
).value
;
9339 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9341 if (num
== error_mark_node
)
9343 if (!INTEGRAL_TYPE_P (TREE_TYPE (num
))
9344 || !host_integerp (num
, 0)
9345 || (n
= tree_low_cst (num
, 0)) <= 0
9349 "collapse argument needs positive constant integer expression");
9352 c
= build_omp_clause (loc
, OMP_CLAUSE_COLLAPSE
);
9353 OMP_CLAUSE_COLLAPSE_EXPR (c
) = num
;
9354 OMP_CLAUSE_CHAIN (c
) = list
;
9359 copyin ( variable-list ) */
9362 c_parser_omp_clause_copyin (c_parser
*parser
, tree list
)
9364 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYIN
, list
);
9368 copyprivate ( variable-list ) */
9371 c_parser_omp_clause_copyprivate (c_parser
*parser
, tree list
)
9373 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYPRIVATE
, list
);
9377 default ( shared | none ) */
9380 c_parser_omp_clause_default (c_parser
*parser
, tree list
)
9382 enum omp_clause_default_kind kind
= OMP_CLAUSE_DEFAULT_UNSPECIFIED
;
9383 location_t loc
= c_parser_peek_token (parser
)->location
;
9386 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9388 if (c_parser_next_token_is (parser
, CPP_NAME
))
9390 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
9395 if (strcmp ("none", p
) != 0)
9397 kind
= OMP_CLAUSE_DEFAULT_NONE
;
9401 if (strcmp ("shared", p
) != 0)
9403 kind
= OMP_CLAUSE_DEFAULT_SHARED
;
9410 c_parser_consume_token (parser
);
9415 c_parser_error (parser
, "expected %<none%> or %<shared%>");
9417 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9419 if (kind
== OMP_CLAUSE_DEFAULT_UNSPECIFIED
)
9422 check_no_duplicate_clause (list
, OMP_CLAUSE_DEFAULT
, "default");
9423 c
= build_omp_clause (loc
, OMP_CLAUSE_DEFAULT
);
9424 OMP_CLAUSE_CHAIN (c
) = list
;
9425 OMP_CLAUSE_DEFAULT_KIND (c
) = kind
;
9431 firstprivate ( variable-list ) */
9434 c_parser_omp_clause_firstprivate (c_parser
*parser
, tree list
)
9436 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FIRSTPRIVATE
, list
);
9440 final ( expression ) */
9443 c_parser_omp_clause_final (c_parser
*parser
, tree list
)
9445 location_t loc
= c_parser_peek_token (parser
)->location
;
9446 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9448 tree t
= c_parser_paren_condition (parser
);
9451 check_no_duplicate_clause (list
, OMP_CLAUSE_FINAL
, "final");
9453 c
= build_omp_clause (loc
, OMP_CLAUSE_FINAL
);
9454 OMP_CLAUSE_FINAL_EXPR (c
) = t
;
9455 OMP_CLAUSE_CHAIN (c
) = list
;
9459 c_parser_error (parser
, "expected %<(%>");
9465 if ( expression ) */
9468 c_parser_omp_clause_if (c_parser
*parser
, tree list
)
9470 location_t loc
= c_parser_peek_token (parser
)->location
;
9471 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9473 tree t
= c_parser_paren_condition (parser
);
9476 check_no_duplicate_clause (list
, OMP_CLAUSE_IF
, "if");
9478 c
= build_omp_clause (loc
, OMP_CLAUSE_IF
);
9479 OMP_CLAUSE_IF_EXPR (c
) = t
;
9480 OMP_CLAUSE_CHAIN (c
) = list
;
9484 c_parser_error (parser
, "expected %<(%>");
9490 lastprivate ( variable-list ) */
9493 c_parser_omp_clause_lastprivate (c_parser
*parser
, tree list
)
9495 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_LASTPRIVATE
, list
);
9502 c_parser_omp_clause_mergeable (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
9506 /* FIXME: Should we allow duplicates? */
9507 check_no_duplicate_clause (list
, OMP_CLAUSE_MERGEABLE
, "mergeable");
9509 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
9510 OMP_CLAUSE_MERGEABLE
);
9511 OMP_CLAUSE_CHAIN (c
) = list
;
9520 c_parser_omp_clause_nowait (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
9523 location_t loc
= c_parser_peek_token (parser
)->location
;
9525 check_no_duplicate_clause (list
, OMP_CLAUSE_NOWAIT
, "nowait");
9527 c
= build_omp_clause (loc
, OMP_CLAUSE_NOWAIT
);
9528 OMP_CLAUSE_CHAIN (c
) = list
;
9533 num_threads ( expression ) */
9536 c_parser_omp_clause_num_threads (c_parser
*parser
, tree list
)
9538 location_t num_threads_loc
= c_parser_peek_token (parser
)->location
;
9539 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9541 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
9542 tree c
, t
= c_parser_expression (parser
).value
;
9544 t
= c_fully_fold (t
, false, NULL
);
9546 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9548 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
9550 c_parser_error (parser
, "expected integer expression");
9554 /* Attempt to statically determine when the number isn't positive. */
9555 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
9556 build_int_cst (TREE_TYPE (t
), 0));
9557 if (CAN_HAVE_LOCATION_P (c
))
9558 SET_EXPR_LOCATION (c
, expr_loc
);
9559 if (c
== boolean_true_node
)
9561 warning_at (expr_loc
, 0,
9562 "%<num_threads%> value must be positive");
9563 t
= integer_one_node
;
9566 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_THREADS
, "num_threads");
9568 c
= build_omp_clause (num_threads_loc
, OMP_CLAUSE_NUM_THREADS
);
9569 OMP_CLAUSE_NUM_THREADS_EXPR (c
) = t
;
9570 OMP_CLAUSE_CHAIN (c
) = list
;
9581 c_parser_omp_clause_ordered (c_parser
*parser
, tree list
)
9585 check_no_duplicate_clause (list
, OMP_CLAUSE_ORDERED
, "ordered");
9587 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
9588 OMP_CLAUSE_ORDERED
);
9589 OMP_CLAUSE_CHAIN (c
) = list
;
9595 private ( variable-list ) */
9598 c_parser_omp_clause_private (c_parser
*parser
, tree list
)
9600 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_PRIVATE
, list
);
9604 reduction ( reduction-operator : variable-list )
9607 One of: + * - & ^ | && ||
9612 One of: + * - & ^ | && || max min */
9615 c_parser_omp_clause_reduction (c_parser
*parser
, tree list
)
9617 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
9618 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9620 enum tree_code code
;
9622 switch (c_parser_peek_token (parser
)->type
)
9634 code
= BIT_AND_EXPR
;
9637 code
= BIT_XOR_EXPR
;
9640 code
= BIT_IOR_EXPR
;
9643 code
= TRUTH_ANDIF_EXPR
;
9646 code
= TRUTH_ORIF_EXPR
;
9651 = IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
9652 if (strcmp (p
, "min") == 0)
9657 if (strcmp (p
, "max") == 0)
9665 c_parser_error (parser
,
9666 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
9667 "%<^%>, %<|%>, %<&&%>, %<||%>, %<min%> or %<max%>");
9668 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
9671 c_parser_consume_token (parser
);
9672 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
9676 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
9677 OMP_CLAUSE_REDUCTION
, list
);
9678 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
9679 OMP_CLAUSE_REDUCTION_CODE (c
) = code
;
9683 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9689 schedule ( schedule-kind )
9690 schedule ( schedule-kind , expression )
9693 static | dynamic | guided | runtime | auto
9697 c_parser_omp_clause_schedule (c_parser
*parser
, tree list
)
9700 location_t loc
= c_parser_peek_token (parser
)->location
;
9702 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9705 c
= build_omp_clause (loc
, OMP_CLAUSE_SCHEDULE
);
9707 if (c_parser_next_token_is (parser
, CPP_NAME
))
9709 tree kind
= c_parser_peek_token (parser
)->value
;
9710 const char *p
= IDENTIFIER_POINTER (kind
);
9715 if (strcmp ("dynamic", p
) != 0)
9717 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_DYNAMIC
;
9721 if (strcmp ("guided", p
) != 0)
9723 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_GUIDED
;
9727 if (strcmp ("runtime", p
) != 0)
9729 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_RUNTIME
;
9736 else if (c_parser_next_token_is_keyword (parser
, RID_STATIC
))
9737 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_STATIC
;
9738 else if (c_parser_next_token_is_keyword (parser
, RID_AUTO
))
9739 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_AUTO
;
9743 c_parser_consume_token (parser
);
9744 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9747 c_parser_consume_token (parser
);
9749 here
= c_parser_peek_token (parser
)->location
;
9750 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
9752 t
= c_fully_fold (t
, false, NULL
);
9754 if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_RUNTIME
)
9755 error_at (here
, "schedule %<runtime%> does not take "
9756 "a %<chunk_size%> parameter");
9757 else if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_AUTO
)
9759 "schedule %<auto%> does not take "
9760 "a %<chunk_size%> parameter");
9761 else if (TREE_CODE (TREE_TYPE (t
)) == INTEGER_TYPE
)
9762 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
) = t
;
9764 c_parser_error (parser
, "expected integer expression");
9766 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9769 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
9770 "expected %<,%> or %<)%>");
9772 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
9773 OMP_CLAUSE_CHAIN (c
) = list
;
9777 c_parser_error (parser
, "invalid schedule kind");
9778 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
9783 shared ( variable-list ) */
9786 c_parser_omp_clause_shared (c_parser
*parser
, tree list
)
9788 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_SHARED
, list
);
9795 c_parser_omp_clause_untied (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
9799 /* FIXME: Should we allow duplicates? */
9800 check_no_duplicate_clause (list
, OMP_CLAUSE_UNTIED
, "untied");
9802 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
9804 OMP_CLAUSE_CHAIN (c
) = list
;
9809 /* Parse all OpenMP clauses. The set clauses allowed by the directive
9810 is a bitmask in MASK. Return the list of clauses found; the result
9811 of clause default goes in *pdefault. */
9814 c_parser_omp_all_clauses (c_parser
*parser
, unsigned int mask
,
9817 tree clauses
= NULL
;
9820 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
9823 pragma_omp_clause c_kind
;
9825 tree prev
= clauses
;
9827 if (!first
&& c_parser_next_token_is (parser
, CPP_COMMA
))
9828 c_parser_consume_token (parser
);
9831 here
= c_parser_peek_token (parser
)->location
;
9832 c_kind
= c_parser_omp_clause_name (parser
);
9836 case PRAGMA_OMP_CLAUSE_COLLAPSE
:
9837 clauses
= c_parser_omp_clause_collapse (parser
, clauses
);
9838 c_name
= "collapse";
9840 case PRAGMA_OMP_CLAUSE_COPYIN
:
9841 clauses
= c_parser_omp_clause_copyin (parser
, clauses
);
9844 case PRAGMA_OMP_CLAUSE_COPYPRIVATE
:
9845 clauses
= c_parser_omp_clause_copyprivate (parser
, clauses
);
9846 c_name
= "copyprivate";
9848 case PRAGMA_OMP_CLAUSE_DEFAULT
:
9849 clauses
= c_parser_omp_clause_default (parser
, clauses
);
9852 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
:
9853 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
9854 c_name
= "firstprivate";
9856 case PRAGMA_OMP_CLAUSE_FINAL
:
9857 clauses
= c_parser_omp_clause_final (parser
, clauses
);
9860 case PRAGMA_OMP_CLAUSE_IF
:
9861 clauses
= c_parser_omp_clause_if (parser
, clauses
);
9864 case PRAGMA_OMP_CLAUSE_LASTPRIVATE
:
9865 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
9866 c_name
= "lastprivate";
9868 case PRAGMA_OMP_CLAUSE_MERGEABLE
:
9869 clauses
= c_parser_omp_clause_mergeable (parser
, clauses
);
9870 c_name
= "mergeable";
9872 case PRAGMA_OMP_CLAUSE_NOWAIT
:
9873 clauses
= c_parser_omp_clause_nowait (parser
, clauses
);
9876 case PRAGMA_OMP_CLAUSE_NUM_THREADS
:
9877 clauses
= c_parser_omp_clause_num_threads (parser
, clauses
);
9878 c_name
= "num_threads";
9880 case PRAGMA_OMP_CLAUSE_ORDERED
:
9881 clauses
= c_parser_omp_clause_ordered (parser
, clauses
);
9884 case PRAGMA_OMP_CLAUSE_PRIVATE
:
9885 clauses
= c_parser_omp_clause_private (parser
, clauses
);
9888 case PRAGMA_OMP_CLAUSE_REDUCTION
:
9889 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
9890 c_name
= "reduction";
9892 case PRAGMA_OMP_CLAUSE_SCHEDULE
:
9893 clauses
= c_parser_omp_clause_schedule (parser
, clauses
);
9894 c_name
= "schedule";
9896 case PRAGMA_OMP_CLAUSE_SHARED
:
9897 clauses
= c_parser_omp_clause_shared (parser
, clauses
);
9900 case PRAGMA_OMP_CLAUSE_UNTIED
:
9901 clauses
= c_parser_omp_clause_untied (parser
, clauses
);
9905 c_parser_error (parser
, "expected %<#pragma omp%> clause");
9909 if (((mask
>> c_kind
) & 1) == 0 && !parser
->error
)
9911 /* Remove the invalid clause(s) from the list to avoid
9912 confusing the rest of the compiler. */
9914 error_at (here
, "%qs is not valid for %qs", c_name
, where
);
9919 c_parser_skip_to_pragma_eol (parser
);
9921 return c_finish_omp_clauses (clauses
);
9928 In practice, we're also interested in adding the statement to an
9929 outer node. So it is convenient if we work around the fact that
9930 c_parser_statement calls add_stmt. */
9933 c_parser_omp_structured_block (c_parser
*parser
)
9935 tree stmt
= push_stmt_list ();
9936 c_parser_statement (parser
);
9937 return pop_stmt_list (stmt
);
9941 # pragma omp atomic new-line
9945 x binop= expr | x++ | ++x | x-- | --x
9947 +, *, -, /, &, ^, |, <<, >>
9949 where x is an lvalue expression with scalar type.
9952 # pragma omp atomic new-line
9955 # pragma omp atomic read new-line
9958 # pragma omp atomic write new-line
9961 # pragma omp atomic update new-line
9964 # pragma omp atomic capture new-line
9967 # pragma omp atomic capture new-line
9975 expression-stmt | x = x binop expr
9977 v = x binop= expr | v = x++ | v = ++x | v = x-- | v = --x
9979 { v = x; update-stmt; } | { update-stmt; v = x; }
9981 where x and v are lvalue expressions with scalar type.
9983 LOC is the location of the #pragma token. */
9986 c_parser_omp_atomic (location_t loc
, c_parser
*parser
)
9988 tree lhs
= NULL_TREE
, rhs
= NULL_TREE
, v
= NULL_TREE
;
9989 tree lhs1
= NULL_TREE
, rhs1
= NULL_TREE
;
9990 tree stmt
, orig_lhs
;
9991 enum tree_code code
= OMP_ATOMIC
, opcode
= NOP_EXPR
;
9992 struct c_expr rhs_expr
;
9993 bool structured_block
= false;
9995 if (c_parser_next_token_is (parser
, CPP_NAME
))
9997 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
9999 if (!strcmp (p
, "read"))
10000 code
= OMP_ATOMIC_READ
;
10001 else if (!strcmp (p
, "write"))
10003 else if (!strcmp (p
, "update"))
10005 else if (!strcmp (p
, "capture"))
10006 code
= OMP_ATOMIC_CAPTURE_NEW
;
10010 c_parser_consume_token (parser
);
10012 c_parser_skip_to_pragma_eol (parser
);
10016 case OMP_ATOMIC_READ
:
10017 case NOP_EXPR
: /* atomic write */
10018 v
= c_parser_unary_expression (parser
).value
;
10019 v
= c_fully_fold (v
, false, NULL
);
10020 if (v
== error_mark_node
)
10022 loc
= c_parser_peek_token (parser
)->location
;
10023 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
10025 if (code
== NOP_EXPR
)
10026 lhs
= c_parser_expression (parser
).value
;
10028 lhs
= c_parser_unary_expression (parser
).value
;
10029 lhs
= c_fully_fold (lhs
, false, NULL
);
10030 if (lhs
== error_mark_node
)
10032 if (code
== NOP_EXPR
)
10034 /* atomic write is represented by OMP_ATOMIC with NOP_EXPR
10042 case OMP_ATOMIC_CAPTURE_NEW
:
10043 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
10045 c_parser_consume_token (parser
);
10046 structured_block
= true;
10050 v
= c_parser_unary_expression (parser
).value
;
10051 v
= c_fully_fold (v
, false, NULL
);
10052 if (v
== error_mark_node
)
10054 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
10062 /* For structured_block case we don't know yet whether
10063 old or new x should be captured. */
10065 lhs
= c_parser_unary_expression (parser
).value
;
10066 lhs
= c_fully_fold (lhs
, false, NULL
);
10068 switch (TREE_CODE (lhs
))
10072 c_parser_skip_to_end_of_block_or_statement (parser
);
10073 if (structured_block
)
10075 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
10076 c_parser_consume_token (parser
);
10077 else if (code
== OMP_ATOMIC_CAPTURE_NEW
)
10079 c_parser_skip_to_end_of_block_or_statement (parser
);
10080 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
10081 c_parser_consume_token (parser
);
10086 case POSTINCREMENT_EXPR
:
10087 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
10088 code
= OMP_ATOMIC_CAPTURE_OLD
;
10090 case PREINCREMENT_EXPR
:
10091 lhs
= TREE_OPERAND (lhs
, 0);
10092 opcode
= PLUS_EXPR
;
10093 rhs
= integer_one_node
;
10096 case POSTDECREMENT_EXPR
:
10097 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
10098 code
= OMP_ATOMIC_CAPTURE_OLD
;
10100 case PREDECREMENT_EXPR
:
10101 lhs
= TREE_OPERAND (lhs
, 0);
10102 opcode
= MINUS_EXPR
;
10103 rhs
= integer_one_node
;
10106 case COMPOUND_EXPR
:
10107 if (TREE_CODE (TREE_OPERAND (lhs
, 0)) == SAVE_EXPR
10108 && TREE_CODE (TREE_OPERAND (lhs
, 1)) == COMPOUND_EXPR
10109 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0)) == MODIFY_EXPR
10110 && TREE_OPERAND (TREE_OPERAND (lhs
, 1), 1) == TREE_OPERAND (lhs
, 0)
10111 && TREE_CODE (TREE_TYPE (TREE_OPERAND (TREE_OPERAND
10112 (TREE_OPERAND (lhs
, 1), 0), 0)))
10114 /* Undo effects of boolean_increment for post {in,de}crement. */
10115 lhs
= TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0);
10118 if (TREE_CODE (lhs
) == MODIFY_EXPR
10119 && TREE_CODE (TREE_TYPE (TREE_OPERAND (lhs
, 0))) == BOOLEAN_TYPE
)
10121 /* Undo effects of boolean_increment. */
10122 if (integer_onep (TREE_OPERAND (lhs
, 1)))
10124 /* This is pre or post increment. */
10125 rhs
= TREE_OPERAND (lhs
, 1);
10126 lhs
= TREE_OPERAND (lhs
, 0);
10128 if (code
== OMP_ATOMIC_CAPTURE_NEW
10129 && !structured_block
10130 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
10131 code
= OMP_ATOMIC_CAPTURE_OLD
;
10134 if (TREE_CODE (TREE_OPERAND (lhs
, 1)) == TRUTH_NOT_EXPR
10135 && TREE_OPERAND (lhs
, 0)
10136 == TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0))
10138 /* This is pre or post decrement. */
10139 rhs
= TREE_OPERAND (lhs
, 1);
10140 lhs
= TREE_OPERAND (lhs
, 0);
10142 if (code
== OMP_ATOMIC_CAPTURE_NEW
10143 && !structured_block
10144 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
10145 code
= OMP_ATOMIC_CAPTURE_OLD
;
10151 switch (c_parser_peek_token (parser
)->type
)
10154 opcode
= MULT_EXPR
;
10157 opcode
= TRUNC_DIV_EXPR
;
10160 opcode
= PLUS_EXPR
;
10163 opcode
= MINUS_EXPR
;
10165 case CPP_LSHIFT_EQ
:
10166 opcode
= LSHIFT_EXPR
;
10168 case CPP_RSHIFT_EQ
:
10169 opcode
= RSHIFT_EXPR
;
10172 opcode
= BIT_AND_EXPR
;
10175 opcode
= BIT_IOR_EXPR
;
10178 opcode
= BIT_XOR_EXPR
;
10181 if (structured_block
|| code
== OMP_ATOMIC
)
10183 location_t aloc
= c_parser_peek_token (parser
)->location
;
10184 location_t rhs_loc
;
10185 enum c_parser_prec oprec
= PREC_NONE
;
10187 c_parser_consume_token (parser
);
10188 rhs1
= c_parser_unary_expression (parser
).value
;
10189 rhs1
= c_fully_fold (rhs1
, false, NULL
);
10190 if (rhs1
== error_mark_node
)
10192 switch (c_parser_peek_token (parser
)->type
)
10194 case CPP_SEMICOLON
:
10195 if (code
== OMP_ATOMIC_CAPTURE_NEW
)
10197 code
= OMP_ATOMIC_CAPTURE_OLD
;
10202 c_parser_consume_token (parser
);
10205 c_parser_error (parser
,
10206 "invalid form of %<#pragma omp atomic%>");
10209 opcode
= MULT_EXPR
;
10213 opcode
= TRUNC_DIV_EXPR
;
10217 opcode
= PLUS_EXPR
;
10221 opcode
= MINUS_EXPR
;
10225 opcode
= LSHIFT_EXPR
;
10226 oprec
= PREC_SHIFT
;
10229 opcode
= RSHIFT_EXPR
;
10230 oprec
= PREC_SHIFT
;
10233 opcode
= BIT_AND_EXPR
;
10234 oprec
= PREC_BITAND
;
10237 opcode
= BIT_IOR_EXPR
;
10238 oprec
= PREC_BITOR
;
10241 opcode
= BIT_XOR_EXPR
;
10242 oprec
= PREC_BITXOR
;
10245 c_parser_error (parser
,
10246 "invalid operator for %<#pragma omp atomic%>");
10250 c_parser_consume_token (parser
);
10251 rhs_loc
= c_parser_peek_token (parser
)->location
;
10252 if (commutative_tree_code (opcode
))
10253 oprec
= (enum c_parser_prec
) (oprec
- 1);
10254 rhs_expr
= c_parser_binary_expression (parser
, NULL
, oprec
);
10255 rhs_expr
= default_function_array_read_conversion (rhs_loc
,
10257 rhs
= rhs_expr
.value
;
10258 rhs
= c_fully_fold (rhs
, false, NULL
);
10263 c_parser_error (parser
,
10264 "invalid operator for %<#pragma omp atomic%>");
10268 /* Arrange to pass the location of the assignment operator to
10269 c_finish_omp_atomic. */
10270 loc
= c_parser_peek_token (parser
)->location
;
10271 c_parser_consume_token (parser
);
10273 location_t rhs_loc
= c_parser_peek_token (parser
)->location
;
10274 rhs_expr
= c_parser_expression (parser
);
10275 rhs_expr
= default_function_array_read_conversion (rhs_loc
, rhs_expr
);
10277 rhs
= rhs_expr
.value
;
10278 rhs
= c_fully_fold (rhs
, false, NULL
);
10282 if (structured_block
&& code
== OMP_ATOMIC_CAPTURE_NEW
)
10284 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
10286 v
= c_parser_unary_expression (parser
).value
;
10287 v
= c_fully_fold (v
, false, NULL
);
10288 if (v
== error_mark_node
)
10290 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
10292 lhs1
= c_parser_unary_expression (parser
).value
;
10293 lhs1
= c_fully_fold (lhs1
, false, NULL
);
10294 if (lhs1
== error_mark_node
)
10297 if (structured_block
)
10299 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
10300 c_parser_require (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
10303 stmt
= c_finish_omp_atomic (loc
, code
, opcode
, lhs
, rhs
, v
, lhs1
, rhs1
);
10304 if (stmt
!= error_mark_node
)
10307 if (!structured_block
)
10308 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
10313 # pragma omp barrier new-line
10317 c_parser_omp_barrier (c_parser
*parser
)
10319 location_t loc
= c_parser_peek_token (parser
)->location
;
10320 c_parser_consume_pragma (parser
);
10321 c_parser_skip_to_pragma_eol (parser
);
10323 c_finish_omp_barrier (loc
);
10327 # pragma omp critical [(name)] new-line
10330 LOC is the location of the #pragma itself. */
10333 c_parser_omp_critical (location_t loc
, c_parser
*parser
)
10335 tree stmt
, name
= NULL
;
10337 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
10339 c_parser_consume_token (parser
);
10340 if (c_parser_next_token_is (parser
, CPP_NAME
))
10342 name
= c_parser_peek_token (parser
)->value
;
10343 c_parser_consume_token (parser
);
10344 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10347 c_parser_error (parser
, "expected identifier");
10349 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
10350 c_parser_error (parser
, "expected %<(%> or end of line");
10351 c_parser_skip_to_pragma_eol (parser
);
10353 stmt
= c_parser_omp_structured_block (parser
);
10354 return c_finish_omp_critical (loc
, stmt
, name
);
10358 # pragma omp flush flush-vars[opt] new-line
10361 ( variable-list ) */
10364 c_parser_omp_flush (c_parser
*parser
)
10366 location_t loc
= c_parser_peek_token (parser
)->location
;
10367 c_parser_consume_pragma (parser
);
10368 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
10369 c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
10370 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
10371 c_parser_error (parser
, "expected %<(%> or end of line");
10372 c_parser_skip_to_pragma_eol (parser
);
10374 c_finish_omp_flush (loc
);
10377 /* Parse the restricted form of the for statement allowed by OpenMP.
10378 The real trick here is to determine the loop control variable early
10379 so that we can push a new decl if necessary to make it private.
10380 LOC is the location of the OMP in "#pragma omp". */
10383 c_parser_omp_for_loop (location_t loc
,
10384 c_parser
*parser
, tree clauses
, tree
*par_clauses
)
10386 tree decl
, cond
, incr
, save_break
, save_cont
, body
, init
, stmt
, cl
;
10387 tree declv
, condv
, incrv
, initv
, ret
= NULL
;
10388 bool fail
= false, open_brace_parsed
= false;
10389 int i
, collapse
= 1, nbraces
= 0;
10390 location_t for_loc
;
10391 VEC(tree
,gc
) *for_block
= make_tree_vector ();
10393 for (cl
= clauses
; cl
; cl
= OMP_CLAUSE_CHAIN (cl
))
10394 if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_COLLAPSE
)
10395 collapse
= tree_low_cst (OMP_CLAUSE_COLLAPSE_EXPR (cl
), 0);
10397 gcc_assert (collapse
>= 1);
10399 declv
= make_tree_vec (collapse
);
10400 initv
= make_tree_vec (collapse
);
10401 condv
= make_tree_vec (collapse
);
10402 incrv
= make_tree_vec (collapse
);
10404 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
))
10406 c_parser_error (parser
, "for statement expected");
10409 for_loc
= c_parser_peek_token (parser
)->location
;
10410 c_parser_consume_token (parser
);
10412 for (i
= 0; i
< collapse
; i
++)
10414 int bracecount
= 0;
10416 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10419 /* Parse the initialization declaration or expression. */
10420 if (c_parser_next_tokens_start_declaration (parser
))
10423 VEC_safe_push (tree
, gc
, for_block
, c_begin_compound_stmt (true));
10424 c_parser_declaration_or_fndef (parser
, true, true, true, true, true, NULL
);
10425 decl
= check_for_loop_decls (for_loc
, flag_isoc99
);
10428 if (DECL_INITIAL (decl
) == error_mark_node
)
10429 decl
= error_mark_node
;
10432 else if (c_parser_next_token_is (parser
, CPP_NAME
)
10433 && c_parser_peek_2nd_token (parser
)->type
== CPP_EQ
)
10435 struct c_expr decl_exp
;
10436 struct c_expr init_exp
;
10437 location_t init_loc
;
10439 decl_exp
= c_parser_postfix_expression (parser
);
10440 decl
= decl_exp
.value
;
10442 c_parser_require (parser
, CPP_EQ
, "expected %<=%>");
10444 init_loc
= c_parser_peek_token (parser
)->location
;
10445 init_exp
= c_parser_expr_no_commas (parser
, NULL
);
10446 init_exp
= default_function_array_read_conversion (init_loc
,
10448 init
= build_modify_expr (init_loc
, decl
, decl_exp
.original_type
,
10449 NOP_EXPR
, init_loc
, init_exp
.value
,
10450 init_exp
.original_type
);
10451 init
= c_process_expr_stmt (init_loc
, init
);
10453 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
10458 c_parser_error (parser
,
10459 "expected iteration declaration or initialization");
10460 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
10466 /* Parse the loop condition. */
10468 if (c_parser_next_token_is_not (parser
, CPP_SEMICOLON
))
10470 location_t cond_loc
= c_parser_peek_token (parser
)->location
;
10471 struct c_expr cond_expr
= c_parser_binary_expression (parser
, NULL
,
10474 cond
= cond_expr
.value
;
10475 cond
= c_objc_common_truthvalue_conversion (cond_loc
, cond
);
10476 cond
= c_fully_fold (cond
, false, NULL
);
10477 switch (cond_expr
.original_code
)
10485 /* Can't be cond = error_mark_node, because we want to preserve
10486 the location until c_finish_omp_for. */
10487 cond
= build1 (NOP_EXPR
, boolean_type_node
, error_mark_node
);
10490 protected_set_expr_location (cond
, cond_loc
);
10492 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
10494 /* Parse the increment expression. */
10496 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_PAREN
))
10498 location_t incr_loc
= c_parser_peek_token (parser
)->location
;
10500 incr
= c_process_expr_stmt (incr_loc
,
10501 c_parser_expression (parser
).value
);
10503 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10505 if (decl
== NULL
|| decl
== error_mark_node
|| init
== error_mark_node
)
10509 TREE_VEC_ELT (declv
, i
) = decl
;
10510 TREE_VEC_ELT (initv
, i
) = init
;
10511 TREE_VEC_ELT (condv
, i
) = cond
;
10512 TREE_VEC_ELT (incrv
, i
) = incr
;
10516 if (i
== collapse
- 1)
10519 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
10520 in between the collapsed for loops to be still considered perfectly
10521 nested. Hopefully the final version clarifies this.
10522 For now handle (multiple) {'s and empty statements. */
10525 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
10527 c_parser_consume_token (parser
);
10530 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
10532 c_parser_consume_token (parser
);
10535 else if (bracecount
10536 && c_parser_next_token_is (parser
, CPP_SEMICOLON
))
10537 c_parser_consume_token (parser
);
10540 c_parser_error (parser
, "not enough perfectly nested loops");
10543 open_brace_parsed
= true;
10553 nbraces
+= bracecount
;
10556 save_break
= c_break_label
;
10557 c_break_label
= size_one_node
;
10558 save_cont
= c_cont_label
;
10559 c_cont_label
= NULL_TREE
;
10560 body
= push_stmt_list ();
10562 if (open_brace_parsed
)
10564 location_t here
= c_parser_peek_token (parser
)->location
;
10565 stmt
= c_begin_compound_stmt (true);
10566 c_parser_compound_statement_nostart (parser
);
10567 add_stmt (c_end_compound_stmt (here
, stmt
, true));
10570 add_stmt (c_parser_c99_block_statement (parser
));
10573 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_cont_label
);
10574 SET_EXPR_LOCATION (t
, loc
);
10578 body
= pop_stmt_list (body
);
10579 c_break_label
= save_break
;
10580 c_cont_label
= save_cont
;
10584 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
10586 c_parser_consume_token (parser
);
10589 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
10590 c_parser_consume_token (parser
);
10593 c_parser_error (parser
, "collapsed loops not perfectly nested");
10596 location_t here
= c_parser_peek_token (parser
)->location
;
10597 stmt
= c_begin_compound_stmt (true);
10599 c_parser_compound_statement_nostart (parser
);
10600 body
= c_end_compound_stmt (here
, stmt
, true);
10607 /* Only bother calling c_finish_omp_for if we haven't already generated
10608 an error from the initialization parsing. */
10611 stmt
= c_finish_omp_for (loc
, declv
, initv
, condv
, incrv
, body
, NULL
);
10614 if (par_clauses
!= NULL
)
10617 for (c
= par_clauses
; *c
; )
10618 if (OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_FIRSTPRIVATE
10619 && OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_LASTPRIVATE
)
10620 c
= &OMP_CLAUSE_CHAIN (*c
);
10623 for (i
= 0; i
< collapse
; i
++)
10624 if (TREE_VEC_ELT (declv
, i
) == OMP_CLAUSE_DECL (*c
))
10627 c
= &OMP_CLAUSE_CHAIN (*c
);
10628 else if (OMP_CLAUSE_CODE (*c
) == OMP_CLAUSE_FIRSTPRIVATE
)
10631 "iteration variable %qD should not be firstprivate",
10632 OMP_CLAUSE_DECL (*c
));
10633 *c
= OMP_CLAUSE_CHAIN (*c
);
10637 /* Copy lastprivate (decl) clause to OMP_FOR_CLAUSES,
10638 change it to shared (decl) in
10639 OMP_PARALLEL_CLAUSES. */
10640 tree l
= build_omp_clause (OMP_CLAUSE_LOCATION (*c
),
10641 OMP_CLAUSE_LASTPRIVATE
);
10642 OMP_CLAUSE_DECL (l
) = OMP_CLAUSE_DECL (*c
);
10643 OMP_CLAUSE_CHAIN (l
) = clauses
;
10645 OMP_CLAUSE_SET_CODE (*c
, OMP_CLAUSE_SHARED
);
10649 OMP_FOR_CLAUSES (stmt
) = clauses
;
10654 while (!VEC_empty (tree
, for_block
))
10656 /* FIXME diagnostics: LOC below should be the actual location of
10657 this particular for block. We need to build a list of
10658 locations to go along with FOR_BLOCK. */
10659 stmt
= c_end_compound_stmt (loc
, VEC_pop (tree
, for_block
), true);
10662 release_tree_vector (for_block
);
10667 #pragma omp for for-clause[optseq] new-line
10670 LOC is the location of the #pragma token.
10673 #define OMP_FOR_CLAUSE_MASK \
10674 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
10675 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
10676 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
10677 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
10678 | (1u << PRAGMA_OMP_CLAUSE_ORDERED) \
10679 | (1u << PRAGMA_OMP_CLAUSE_SCHEDULE) \
10680 | (1u << PRAGMA_OMP_CLAUSE_COLLAPSE) \
10681 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
10684 c_parser_omp_for (location_t loc
, c_parser
*parser
)
10686 tree block
, clauses
, ret
;
10688 clauses
= c_parser_omp_all_clauses (parser
, OMP_FOR_CLAUSE_MASK
,
10689 "#pragma omp for");
10691 block
= c_begin_compound_stmt (true);
10692 ret
= c_parser_omp_for_loop (loc
, parser
, clauses
, NULL
);
10693 block
= c_end_compound_stmt (loc
, block
, true);
10700 # pragma omp master new-line
10703 LOC is the location of the #pragma token.
10707 c_parser_omp_master (location_t loc
, c_parser
*parser
)
10709 c_parser_skip_to_pragma_eol (parser
);
10710 return c_finish_omp_master (loc
, c_parser_omp_structured_block (parser
));
10714 # pragma omp ordered new-line
10717 LOC is the location of the #pragma itself.
10721 c_parser_omp_ordered (location_t loc
, c_parser
*parser
)
10723 c_parser_skip_to_pragma_eol (parser
);
10724 return c_finish_omp_ordered (loc
, c_parser_omp_structured_block (parser
));
10730 { section-sequence }
10733 section-directive[opt] structured-block
10734 section-sequence section-directive structured-block
10736 SECTIONS_LOC is the location of the #pragma omp sections. */
10739 c_parser_omp_sections_scope (location_t sections_loc
, c_parser
*parser
)
10741 tree stmt
, substmt
;
10742 bool error_suppress
= false;
10745 loc
= c_parser_peek_token (parser
)->location
;
10746 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
10748 /* Avoid skipping until the end of the block. */
10749 parser
->error
= false;
10753 stmt
= push_stmt_list ();
10755 if (c_parser_peek_token (parser
)->pragma_kind
!= PRAGMA_OMP_SECTION
)
10757 substmt
= push_stmt_list ();
10761 c_parser_statement (parser
);
10763 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
10765 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
10767 if (c_parser_next_token_is (parser
, CPP_EOF
))
10771 substmt
= pop_stmt_list (substmt
);
10772 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
10773 SET_EXPR_LOCATION (substmt
, loc
);
10774 add_stmt (substmt
);
10779 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
10781 if (c_parser_next_token_is (parser
, CPP_EOF
))
10784 loc
= c_parser_peek_token (parser
)->location
;
10785 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
10787 c_parser_consume_pragma (parser
);
10788 c_parser_skip_to_pragma_eol (parser
);
10789 error_suppress
= false;
10791 else if (!error_suppress
)
10793 error_at (loc
, "expected %<#pragma omp section%> or %<}%>");
10794 error_suppress
= true;
10797 substmt
= c_parser_omp_structured_block (parser
);
10798 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
10799 SET_EXPR_LOCATION (substmt
, loc
);
10800 add_stmt (substmt
);
10802 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
,
10803 "expected %<#pragma omp section%> or %<}%>");
10805 substmt
= pop_stmt_list (stmt
);
10807 stmt
= make_node (OMP_SECTIONS
);
10808 SET_EXPR_LOCATION (stmt
, sections_loc
);
10809 TREE_TYPE (stmt
) = void_type_node
;
10810 OMP_SECTIONS_BODY (stmt
) = substmt
;
10812 return add_stmt (stmt
);
10816 # pragma omp sections sections-clause[optseq] newline
10819 LOC is the location of the #pragma token.
10822 #define OMP_SECTIONS_CLAUSE_MASK \
10823 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
10824 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
10825 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
10826 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
10827 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
10830 c_parser_omp_sections (location_t loc
, c_parser
*parser
)
10832 tree block
, clauses
, ret
;
10834 clauses
= c_parser_omp_all_clauses (parser
, OMP_SECTIONS_CLAUSE_MASK
,
10835 "#pragma omp sections");
10837 block
= c_begin_compound_stmt (true);
10838 ret
= c_parser_omp_sections_scope (loc
, parser
);
10840 OMP_SECTIONS_CLAUSES (ret
) = clauses
;
10841 block
= c_end_compound_stmt (loc
, block
, true);
10848 # pragma parallel parallel-clause new-line
10849 # pragma parallel for parallel-for-clause new-line
10850 # pragma parallel sections parallel-sections-clause new-line
10852 LOC is the location of the #pragma token.
10855 #define OMP_PARALLEL_CLAUSE_MASK \
10856 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
10857 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
10858 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
10859 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
10860 | (1u << PRAGMA_OMP_CLAUSE_SHARED) \
10861 | (1u << PRAGMA_OMP_CLAUSE_COPYIN) \
10862 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
10863 | (1u << PRAGMA_OMP_CLAUSE_NUM_THREADS))
10866 c_parser_omp_parallel (location_t loc
, c_parser
*parser
)
10868 enum pragma_kind p_kind
= PRAGMA_OMP_PARALLEL
;
10869 const char *p_name
= "#pragma omp parallel";
10870 tree stmt
, clauses
, par_clause
, ws_clause
, block
;
10871 unsigned int mask
= OMP_PARALLEL_CLAUSE_MASK
;
10873 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
10875 c_parser_consume_token (parser
);
10876 p_kind
= PRAGMA_OMP_PARALLEL_FOR
;
10877 p_name
= "#pragma omp parallel for";
10878 mask
|= OMP_FOR_CLAUSE_MASK
;
10879 mask
&= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT
);
10881 else if (c_parser_next_token_is (parser
, CPP_NAME
))
10883 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10884 if (strcmp (p
, "sections") == 0)
10886 c_parser_consume_token (parser
);
10887 p_kind
= PRAGMA_OMP_PARALLEL_SECTIONS
;
10888 p_name
= "#pragma omp parallel sections";
10889 mask
|= OMP_SECTIONS_CLAUSE_MASK
;
10890 mask
&= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT
);
10894 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
);
10898 case PRAGMA_OMP_PARALLEL
:
10899 block
= c_begin_omp_parallel ();
10900 c_parser_statement (parser
);
10901 stmt
= c_finish_omp_parallel (loc
, clauses
, block
);
10904 case PRAGMA_OMP_PARALLEL_FOR
:
10905 block
= c_begin_omp_parallel ();
10906 c_split_parallel_clauses (loc
, clauses
, &par_clause
, &ws_clause
);
10907 c_parser_omp_for_loop (loc
, parser
, ws_clause
, &par_clause
);
10908 stmt
= c_finish_omp_parallel (loc
, par_clause
, block
);
10909 OMP_PARALLEL_COMBINED (stmt
) = 1;
10912 case PRAGMA_OMP_PARALLEL_SECTIONS
:
10913 block
= c_begin_omp_parallel ();
10914 c_split_parallel_clauses (loc
, clauses
, &par_clause
, &ws_clause
);
10915 stmt
= c_parser_omp_sections_scope (loc
, parser
);
10917 OMP_SECTIONS_CLAUSES (stmt
) = ws_clause
;
10918 stmt
= c_finish_omp_parallel (loc
, par_clause
, block
);
10919 OMP_PARALLEL_COMBINED (stmt
) = 1;
10923 gcc_unreachable ();
10930 # pragma omp single single-clause[optseq] new-line
10933 LOC is the location of the #pragma.
10936 #define OMP_SINGLE_CLAUSE_MASK \
10937 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
10938 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
10939 | (1u << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
10940 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
10943 c_parser_omp_single (location_t loc
, c_parser
*parser
)
10945 tree stmt
= make_node (OMP_SINGLE
);
10946 SET_EXPR_LOCATION (stmt
, loc
);
10947 TREE_TYPE (stmt
) = void_type_node
;
10949 OMP_SINGLE_CLAUSES (stmt
)
10950 = c_parser_omp_all_clauses (parser
, OMP_SINGLE_CLAUSE_MASK
,
10951 "#pragma omp single");
10952 OMP_SINGLE_BODY (stmt
) = c_parser_omp_structured_block (parser
);
10954 return add_stmt (stmt
);
10958 # pragma omp task task-clause[optseq] new-line
10960 LOC is the location of the #pragma.
10963 #define OMP_TASK_CLAUSE_MASK \
10964 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
10965 | (1u << PRAGMA_OMP_CLAUSE_UNTIED) \
10966 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
10967 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
10968 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
10969 | (1u << PRAGMA_OMP_CLAUSE_SHARED) \
10970 | (1u << PRAGMA_OMP_CLAUSE_FINAL) \
10971 | (1u << PRAGMA_OMP_CLAUSE_MERGEABLE))
10974 c_parser_omp_task (location_t loc
, c_parser
*parser
)
10976 tree clauses
, block
;
10978 clauses
= c_parser_omp_all_clauses (parser
, OMP_TASK_CLAUSE_MASK
,
10979 "#pragma omp task");
10981 block
= c_begin_omp_task ();
10982 c_parser_statement (parser
);
10983 return c_finish_omp_task (loc
, clauses
, block
);
10987 # pragma omp taskwait new-line
10991 c_parser_omp_taskwait (c_parser
*parser
)
10993 location_t loc
= c_parser_peek_token (parser
)->location
;
10994 c_parser_consume_pragma (parser
);
10995 c_parser_skip_to_pragma_eol (parser
);
10997 c_finish_omp_taskwait (loc
);
11001 # pragma omp taskyield new-line
11005 c_parser_omp_taskyield (c_parser
*parser
)
11007 location_t loc
= c_parser_peek_token (parser
)->location
;
11008 c_parser_consume_pragma (parser
);
11009 c_parser_skip_to_pragma_eol (parser
);
11011 c_finish_omp_taskyield (loc
);
11014 /* Main entry point to parsing most OpenMP pragmas. */
11017 c_parser_omp_construct (c_parser
*parser
)
11019 enum pragma_kind p_kind
;
11023 loc
= c_parser_peek_token (parser
)->location
;
11024 p_kind
= c_parser_peek_token (parser
)->pragma_kind
;
11025 c_parser_consume_pragma (parser
);
11029 case PRAGMA_OMP_ATOMIC
:
11030 c_parser_omp_atomic (loc
, parser
);
11032 case PRAGMA_OMP_CRITICAL
:
11033 stmt
= c_parser_omp_critical (loc
, parser
);
11035 case PRAGMA_OMP_FOR
:
11036 stmt
= c_parser_omp_for (loc
, parser
);
11038 case PRAGMA_OMP_MASTER
:
11039 stmt
= c_parser_omp_master (loc
, parser
);
11041 case PRAGMA_OMP_ORDERED
:
11042 stmt
= c_parser_omp_ordered (loc
, parser
);
11044 case PRAGMA_OMP_PARALLEL
:
11045 stmt
= c_parser_omp_parallel (loc
, parser
);
11047 case PRAGMA_OMP_SECTIONS
:
11048 stmt
= c_parser_omp_sections (loc
, parser
);
11050 case PRAGMA_OMP_SINGLE
:
11051 stmt
= c_parser_omp_single (loc
, parser
);
11053 case PRAGMA_OMP_TASK
:
11054 stmt
= c_parser_omp_task (loc
, parser
);
11057 gcc_unreachable ();
11061 gcc_assert (EXPR_LOCATION (stmt
) != UNKNOWN_LOCATION
);
11066 # pragma omp threadprivate (variable-list) */
11069 c_parser_omp_threadprivate (c_parser
*parser
)
11074 c_parser_consume_pragma (parser
);
11075 loc
= c_parser_peek_token (parser
)->location
;
11076 vars
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
11078 /* Mark every variable in VARS to be assigned thread local storage. */
11079 for (t
= vars
; t
; t
= TREE_CHAIN (t
))
11081 tree v
= TREE_PURPOSE (t
);
11083 /* FIXME diagnostics: Ideally we should keep individual
11084 locations for all the variables in the var list to make the
11085 following errors more precise. Perhaps
11086 c_parser_omp_var_list_parens() should construct a list of
11087 locations to go along with the var list. */
11089 /* If V had already been marked threadprivate, it doesn't matter
11090 whether it had been used prior to this point. */
11091 if (TREE_CODE (v
) != VAR_DECL
)
11092 error_at (loc
, "%qD is not a variable", v
);
11093 else if (TREE_USED (v
) && !C_DECL_THREADPRIVATE_P (v
))
11094 error_at (loc
, "%qE declared %<threadprivate%> after first use", v
);
11095 else if (! TREE_STATIC (v
) && ! DECL_EXTERNAL (v
))
11096 error_at (loc
, "automatic variable %qE cannot be %<threadprivate%>", v
);
11097 else if (TREE_TYPE (v
) == error_mark_node
)
11099 else if (! COMPLETE_TYPE_P (TREE_TYPE (v
)))
11100 error_at (loc
, "%<threadprivate%> %qE has incomplete type", v
);
11103 if (! DECL_THREAD_LOCAL_P (v
))
11105 DECL_TLS_MODEL (v
) = decl_default_tls_model (v
);
11106 /* If rtl has been already set for this var, call
11107 make_decl_rtl once again, so that encode_section_info
11108 has a chance to look at the new decl flags. */
11109 if (DECL_RTL_SET_P (v
))
11112 C_DECL_THREADPRIVATE_P (v
) = 1;
11116 c_parser_skip_to_pragma_eol (parser
);
11119 /* Parse a transaction attribute (GCC Extension).
11121 transaction-attribute:
11125 The transactional memory language description is written for C++,
11126 and uses the C++0x attribute syntax. For compatibility, allow the
11127 bracket style for transactions in C as well. */
11130 c_parser_transaction_attributes (c_parser
*parser
)
11132 tree attr_name
, attr
= NULL
;
11134 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
11135 return c_parser_attributes (parser
);
11137 if (!c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
11139 c_parser_consume_token (parser
);
11140 if (!c_parser_require (parser
, CPP_OPEN_SQUARE
, "expected %<[%>"))
11143 attr_name
= c_parser_attribute_any_word (parser
);
11146 c_parser_consume_token (parser
);
11147 attr
= build_tree_list (attr_name
, NULL_TREE
);
11150 c_parser_error (parser
, "expected identifier");
11152 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
11154 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
11158 /* Parse a __transaction_atomic or __transaction_relaxed statement
11161 transaction-statement:
11162 __transaction_atomic transaction-attribute[opt] compound-statement
11163 __transaction_relaxed compound-statement
11165 Note that the only valid attribute is: "outer".
11169 c_parser_transaction (c_parser
*parser
, enum rid keyword
)
11171 unsigned int old_in
= parser
->in_transaction
;
11172 unsigned int this_in
= 1, new_in
;
11173 location_t loc
= c_parser_peek_token (parser
)->location
;
11176 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
11177 || keyword
== RID_TRANSACTION_RELAXED
)
11178 && c_parser_next_token_is_keyword (parser
, keyword
));
11179 c_parser_consume_token (parser
);
11181 if (keyword
== RID_TRANSACTION_RELAXED
)
11182 this_in
|= TM_STMT_ATTR_RELAXED
;
11185 attrs
= c_parser_transaction_attributes (parser
);
11187 this_in
|= parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
);
11190 /* Keep track if we're in the lexical scope of an outer transaction. */
11191 new_in
= this_in
| (old_in
& TM_STMT_ATTR_OUTER
);
11193 parser
->in_transaction
= new_in
;
11194 stmt
= c_parser_compound_statement (parser
);
11195 parser
->in_transaction
= old_in
;
11198 stmt
= c_finish_transaction (loc
, stmt
, this_in
);
11200 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
11201 "%<__transaction_atomic%> without transactional memory support enabled"
11202 : "%<__transaction_relaxed %> "
11203 "without transactional memory support enabled"));
11208 /* Parse a __transaction_atomic or __transaction_relaxed expression
11211 transaction-expression:
11212 __transaction_atomic ( expression )
11213 __transaction_relaxed ( expression )
11216 static struct c_expr
11217 c_parser_transaction_expression (c_parser
*parser
, enum rid keyword
)
11220 unsigned int old_in
= parser
->in_transaction
;
11221 unsigned int this_in
= 1;
11222 location_t loc
= c_parser_peek_token (parser
)->location
;
11225 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
11226 || keyword
== RID_TRANSACTION_RELAXED
)
11227 && c_parser_next_token_is_keyword (parser
, keyword
));
11228 c_parser_consume_token (parser
);
11230 if (keyword
== RID_TRANSACTION_RELAXED
)
11231 this_in
|= TM_STMT_ATTR_RELAXED
;
11234 attrs
= c_parser_transaction_attributes (parser
);
11236 this_in
|= parse_tm_stmt_attr (attrs
, 0);
11239 parser
->in_transaction
= this_in
;
11240 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11242 tree expr
= c_parser_expression (parser
).value
;
11243 ret
.original_type
= TREE_TYPE (expr
);
11244 ret
.value
= build1 (TRANSACTION_EXPR
, ret
.original_type
, expr
);
11245 if (this_in
& TM_STMT_ATTR_RELAXED
)
11246 TRANSACTION_EXPR_RELAXED (ret
.value
) = 1;
11247 SET_EXPR_LOCATION (ret
.value
, loc
);
11248 ret
.original_code
= TRANSACTION_EXPR
;
11249 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
11251 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
11258 ret
.value
= error_mark_node
;
11259 ret
.original_code
= ERROR_MARK
;
11260 ret
.original_type
= NULL
;
11262 parser
->in_transaction
= old_in
;
11265 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
11266 "%<__transaction_atomic%> without transactional memory support enabled"
11267 : "%<__transaction_relaxed %> "
11268 "without transactional memory support enabled"));
11273 /* Parse a __transaction_cancel statement (GCC Extension).
11275 transaction-cancel-statement:
11276 __transaction_cancel transaction-attribute[opt] ;
11278 Note that the only valid attribute is "outer".
11282 c_parser_transaction_cancel(c_parser
*parser
)
11284 location_t loc
= c_parser_peek_token (parser
)->location
;
11286 bool is_outer
= false;
11288 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TRANSACTION_CANCEL
));
11289 c_parser_consume_token (parser
);
11291 attrs
= c_parser_transaction_attributes (parser
);
11293 is_outer
= (parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
) != 0);
11297 error_at (loc
, "%<__transaction_cancel%> without "
11298 "transactional memory support enabled");
11301 else if (parser
->in_transaction
& TM_STMT_ATTR_RELAXED
)
11303 error_at (loc
, "%<__transaction_cancel%> within a "
11304 "%<__transaction_relaxed%>");
11309 if ((parser
->in_transaction
& TM_STMT_ATTR_OUTER
) == 0
11310 && !is_tm_may_cancel_outer (current_function_decl
))
11312 error_at (loc
, "outer %<__transaction_cancel%> not "
11313 "within outer %<__transaction_atomic%>");
11314 error_at (loc
, " or a %<transaction_may_cancel_outer%> function");
11318 else if (parser
->in_transaction
== 0)
11320 error_at (loc
, "%<__transaction_cancel%> not within "
11321 "%<__transaction_atomic%>");
11325 return add_stmt (build_tm_abort_call (loc
, is_outer
));
11328 return build1 (NOP_EXPR
, void_type_node
, error_mark_node
);
11331 /* Parse a single source file. */
11334 c_parse_file (void)
11336 /* Use local storage to begin. If the first token is a pragma, parse it.
11337 If it is #pragma GCC pch_preprocess, then this will load a PCH file
11338 which will cause garbage collection. */
11341 memset (&tparser
, 0, sizeof tparser
);
11342 the_parser
= &tparser
;
11344 if (c_parser_peek_token (&tparser
)->pragma_kind
== PRAGMA_GCC_PCH_PREPROCESS
)
11345 c_parser_pragma_pch_preprocess (&tparser
);
11347 the_parser
= ggc_alloc_c_parser ();
11348 *the_parser
= tparser
;
11350 /* Initialize EH, if we've been told to do so. */
11351 if (flag_exceptions
)
11352 using_eh_for_cleanups ();
11354 c_parser_translation_unit (the_parser
);
11358 #include "gt-c-c-parser.h"