1 /* Parser for C and Objective-C.
2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010
4 Free Software Foundation, Inc.
6 Parser actions based on the old Bison parser; structure somewhat
7 influenced by and fragments based on the C++ parser.
9 This file is part of GCC.
11 GCC is free software; you can redistribute it and/or modify it under
12 the terms of the GNU General Public License as published by the Free
13 Software Foundation; either version 3, or (at your option) any later
16 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
17 WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with GCC; see the file COPYING3. If not see
23 <http://www.gnu.org/licenses/>. */
27 Make sure all relevant comments, and all relevant code from all
28 actions, brought over from old parser. Verify exact correspondence
31 Add testcases covering every input symbol in every state in old and
34 Include full syntax for GNU C, including erroneous cases accepted
35 with error messages, in syntax productions in comments.
37 Make more diagnostics in the front end generally take an explicit
38 location rather than implicitly using input_location. */
42 #include "coretypes.h"
46 #include "langhooks.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 ridpointers
= GGC_CNEWVEC (tree
, (int) RID_MAX
);
92 for (i
= 0; i
< num_c_common_reswords
; i
++)
94 /* If a keyword is disabled, do not enter it into the table
95 and so create a canonical spelling that isn't a keyword. */
96 if (c_common_reswords
[i
].disable
& mask
)
99 && (c_common_reswords
[i
].disable
& D_CXXWARN
))
101 id
= get_identifier (c_common_reswords
[i
].word
);
102 C_SET_RID_CODE (id
, RID_CXX_COMPAT_WARN
);
103 C_IS_RESERVED_WORD (id
) = 1;
108 id
= get_identifier (c_common_reswords
[i
].word
);
109 C_SET_RID_CODE (id
, c_common_reswords
[i
].rid
);
110 C_IS_RESERVED_WORD (id
) = 1;
111 ridpointers
[(int) c_common_reswords
[i
].rid
] = id
;
115 /* The C lexer intermediates between the lexer in cpplib and c-lex.c
116 and the C parser. Unlike the C++ lexer, the parser structure
117 stores the lexer information instead of using a separate structure.
118 Identifiers are separated into ordinary identifiers, type names,
119 keywords and some other Objective-C types of identifiers, and some
120 look-ahead is maintained.
122 ??? It might be a good idea to lex the whole file up front (as for
123 C++). It would then be possible to share more of the C and C++
124 lexer code, if desired. */
126 /* The following local token type is used. */
129 #define CPP_KEYWORD ((enum cpp_ttype) (N_TTYPES + 1))
131 /* More information about the type of a CPP_NAME token. */
132 typedef enum c_id_kind
{
133 /* An ordinary identifier. */
135 /* An identifier declared as a typedef name. */
137 /* An identifier declared as an Objective-C class name. */
139 /* An address space identifier. */
141 /* Not an identifier. */
145 /* A single C token after string literal concatenation and conversion
146 of preprocessing tokens to tokens. */
147 typedef struct GTY (()) c_token
{
148 /* The kind of token. */
149 ENUM_BITFIELD (cpp_ttype
) type
: 8;
150 /* If this token is a CPP_NAME, this value indicates whether also
151 declared as some kind of type. Otherwise, it is C_ID_NONE. */
152 ENUM_BITFIELD (c_id_kind
) id_kind
: 8;
153 /* If this token is a keyword, this value indicates which keyword.
154 Otherwise, this value is RID_MAX. */
155 ENUM_BITFIELD (rid
) keyword
: 8;
156 /* If this token is a CPP_PRAGMA, this indicates the pragma that
157 was seen. Otherwise it is PRAGMA_NONE. */
158 ENUM_BITFIELD (pragma_kind
) pragma_kind
: 8;
159 /* The value associated with this token, if any. */
161 /* The location at which this token was found. */
165 /* A parser structure recording information about the state and
166 context of parsing. Includes lexer information with up to two
167 tokens of look-ahead; more are not needed for C. */
168 typedef struct GTY(()) c_parser
{
169 /* The look-ahead tokens. */
171 /* How many look-ahead tokens are available (0, 1 or 2). */
173 /* True if a syntax error is being recovered from; false otherwise.
174 c_parser_error sets this flag. It should clear this flag when
175 enough tokens have been consumed to recover from the error. */
176 BOOL_BITFIELD error
: 1;
177 /* True if we're processing a pragma, and shouldn't automatically
178 consume CPP_PRAGMA_EOL. */
179 BOOL_BITFIELD in_pragma
: 1;
180 /* True if we're parsing the outermost block of an if statement. */
181 BOOL_BITFIELD in_if_block
: 1;
182 /* True if we want to lex an untranslated string. */
183 BOOL_BITFIELD lex_untranslated_string
: 1;
184 /* Objective-C specific parser/lexer information. */
185 BOOL_BITFIELD objc_pq_context
: 1;
186 /* The following flag is needed to contextualize Objective-C lexical
187 analysis. In some cases (e.g., 'int NSObject;'), it is
188 undesirable to bind an identifier to an Objective-C class, even
189 if a class with that name exists. */
190 BOOL_BITFIELD objc_need_raw_identifier
: 1;
194 /* The actual parser and external interface. ??? Does this need to be
195 garbage-collected? */
197 static GTY (()) c_parser
*the_parser
;
200 /* Read in and lex a single token, storing it in *TOKEN. */
203 c_lex_one_token (c_parser
*parser
, c_token
*token
)
205 timevar_push (TV_LEX
);
207 token
->type
= c_lex_with_flags (&token
->value
, &token
->location
, NULL
,
208 (parser
->lex_untranslated_string
209 ? C_LEX_STRING_NO_TRANSLATE
: 0));
210 token
->id_kind
= C_ID_NONE
;
211 token
->keyword
= RID_MAX
;
212 token
->pragma_kind
= PRAGMA_NONE
;
220 bool objc_force_identifier
= parser
->objc_need_raw_identifier
;
221 if (c_dialect_objc ())
222 parser
->objc_need_raw_identifier
= false;
224 if (C_IS_RESERVED_WORD (token
->value
))
226 enum rid rid_code
= C_RID_CODE (token
->value
);
228 if (rid_code
== RID_CXX_COMPAT_WARN
)
230 warning_at (token
->location
,
232 "identifier %qE conflicts with C++ keyword",
235 else if (rid_code
>= RID_FIRST_ADDR_SPACE
236 && rid_code
<= RID_LAST_ADDR_SPACE
)
238 token
->id_kind
= C_ID_ADDRSPACE
;
239 token
->keyword
= rid_code
;
242 else if (c_dialect_objc ())
244 if (!objc_is_reserved_word (token
->value
)
245 && (!OBJC_IS_PQ_KEYWORD (rid_code
)
246 || parser
->objc_pq_context
))
248 /* Return the canonical spelling for this keyword. */
249 token
->value
= ridpointers
[(int) rid_code
];
250 token
->type
= CPP_KEYWORD
;
251 token
->keyword
= rid_code
;
257 token
->type
= CPP_KEYWORD
;
258 token
->keyword
= rid_code
;
263 decl
= lookup_name (token
->value
);
266 if (TREE_CODE (decl
) == TYPE_DECL
)
268 token
->id_kind
= C_ID_TYPENAME
;
272 else if (c_dialect_objc ())
274 tree objc_interface_decl
= objc_is_class_name (token
->value
);
275 /* Objective-C class names are in the same namespace as
276 variables and typedefs, and hence are shadowed by local
278 if (objc_interface_decl
279 && (global_bindings_p ()
280 || (!objc_force_identifier
&& !decl
)))
282 token
->value
= objc_interface_decl
;
283 token
->id_kind
= C_ID_CLASSNAME
;
287 token
->id_kind
= C_ID_ID
;
291 /* This only happens in Objective-C; it must be a keyword. */
292 token
->type
= CPP_KEYWORD
;
293 token
->keyword
= C_RID_CODE (token
->value
);
297 case CPP_CLOSE_PAREN
:
299 /* These tokens may affect the interpretation of any identifiers
300 following, if doing Objective-C. */
301 if (c_dialect_objc ())
302 parser
->objc_need_raw_identifier
= false;
305 /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */
306 token
->pragma_kind
= (enum pragma_kind
) TREE_INT_CST_LOW (token
->value
);
312 timevar_pop (TV_LEX
);
315 /* Return a pointer to the next token from PARSER, reading it in if
318 static inline c_token
*
319 c_parser_peek_token (c_parser
*parser
)
321 if (parser
->tokens_avail
== 0)
323 c_lex_one_token (parser
, &parser
->tokens
[0]);
324 parser
->tokens_avail
= 1;
326 return &parser
->tokens
[0];
329 /* Return true if the next token from PARSER has the indicated
333 c_parser_next_token_is (c_parser
*parser
, enum cpp_ttype type
)
335 return c_parser_peek_token (parser
)->type
== type
;
338 /* Return true if the next token from PARSER does not have the
342 c_parser_next_token_is_not (c_parser
*parser
, enum cpp_ttype type
)
344 return !c_parser_next_token_is (parser
, type
);
347 /* Return true if the next token from PARSER is the indicated
351 c_parser_next_token_is_keyword (c_parser
*parser
, enum rid keyword
)
353 return c_parser_peek_token (parser
)->keyword
== keyword
;
356 /* Return true if TOKEN can start a type name,
359 c_token_starts_typename (c_token
*token
)
364 switch (token
->id_kind
)
373 gcc_assert (c_dialect_objc ());
379 switch (token
->keyword
)
411 if (c_dialect_objc ())
419 /* Return true if the next token from PARSER can start a type name,
422 c_parser_next_token_starts_typename (c_parser
*parser
)
424 c_token
*token
= c_parser_peek_token (parser
);
425 return c_token_starts_typename (token
);
428 /* Return true if TOKEN can start declaration specifiers, false
431 c_token_starts_declspecs (c_token
*token
)
436 switch (token
->id_kind
)
445 gcc_assert (c_dialect_objc ());
451 switch (token
->keyword
)
490 if (c_dialect_objc ())
498 /* Return true if the next token from PARSER can start declaration
499 specifiers, false otherwise. */
501 c_parser_next_token_starts_declspecs (c_parser
*parser
)
503 c_token
*token
= c_parser_peek_token (parser
);
504 return c_token_starts_declspecs (token
);
507 /* Return a pointer to the next-but-one token from PARSER, reading it
508 in if necessary. The next token is already read in. */
511 c_parser_peek_2nd_token (c_parser
*parser
)
513 if (parser
->tokens_avail
>= 2)
514 return &parser
->tokens
[1];
515 gcc_assert (parser
->tokens_avail
== 1);
516 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
517 gcc_assert (parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
518 c_lex_one_token (parser
, &parser
->tokens
[1]);
519 parser
->tokens_avail
= 2;
520 return &parser
->tokens
[1];
523 /* Consume the next token from PARSER. */
526 c_parser_consume_token (c_parser
*parser
)
528 gcc_assert (parser
->tokens_avail
>= 1);
529 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
530 gcc_assert (!parser
->in_pragma
|| parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
531 gcc_assert (parser
->error
|| parser
->tokens
[0].type
!= CPP_PRAGMA
);
532 if (parser
->tokens_avail
== 2)
533 parser
->tokens
[0] = parser
->tokens
[1];
534 parser
->tokens_avail
--;
537 /* Expect the current token to be a #pragma. Consume it and remember
538 that we've begun parsing a pragma. */
541 c_parser_consume_pragma (c_parser
*parser
)
543 gcc_assert (!parser
->in_pragma
);
544 gcc_assert (parser
->tokens_avail
>= 1);
545 gcc_assert (parser
->tokens
[0].type
== CPP_PRAGMA
);
546 if (parser
->tokens_avail
== 2)
547 parser
->tokens
[0] = parser
->tokens
[1];
548 parser
->tokens_avail
--;
549 parser
->in_pragma
= true;
552 /* Update the globals input_location and in_system_header from
555 c_parser_set_source_position_from_token (c_token
*token
)
557 if (token
->type
!= CPP_EOF
)
559 input_location
= token
->location
;
563 /* Issue a diagnostic of the form
564 FILE:LINE: MESSAGE before TOKEN
565 where TOKEN is the next token in the input stream of PARSER.
566 MESSAGE (specified by the caller) is usually of the form "expected
569 Do not issue a diagnostic if still recovering from an error.
571 ??? This is taken from the C++ parser, but building up messages in
572 this way is not i18n-friendly and some other approach should be
576 c_parser_error (c_parser
*parser
, const char *gmsgid
)
578 c_token
*token
= c_parser_peek_token (parser
);
581 parser
->error
= true;
584 /* This diagnostic makes more sense if it is tagged to the line of
585 the token we just peeked at. */
586 c_parser_set_source_position_from_token (token
);
587 c_parse_error (gmsgid
,
588 /* Because c_parse_error does not understand
589 CPP_KEYWORD, keywords are treated like
591 (token
->type
== CPP_KEYWORD
? CPP_NAME
: token
->type
),
592 /* ??? The C parser does not save the cpp flags of a
593 token, we need to pass 0 here and we will not get
594 the source spelling of some tokens but rather the
595 canonical spelling. */
596 token
->value
, /*flags=*/0);
599 /* If the next token is of the indicated TYPE, consume it. Otherwise,
600 issue the error MSGID. If MSGID is NULL then a message has already
601 been produced and no message will be produced this time. Returns
602 true if found, false otherwise. */
605 c_parser_require (c_parser
*parser
,
609 if (c_parser_next_token_is (parser
, type
))
611 c_parser_consume_token (parser
);
616 c_parser_error (parser
, msgid
);
621 /* If the next token is the indicated keyword, consume it. Otherwise,
622 issue the error MSGID. Returns true if found, false otherwise. */
625 c_parser_require_keyword (c_parser
*parser
,
629 if (c_parser_next_token_is_keyword (parser
, keyword
))
631 c_parser_consume_token (parser
);
636 c_parser_error (parser
, msgid
);
641 /* Like c_parser_require, except that tokens will be skipped until the
642 desired token is found. An error message is still produced if the
643 next token is not as expected. If MSGID is NULL then a message has
644 already been produced and no message will be produced this
648 c_parser_skip_until_found (c_parser
*parser
,
652 unsigned nesting_depth
= 0;
654 if (c_parser_require (parser
, type
, msgid
))
657 /* Skip tokens until the desired token is found. */
660 /* Peek at the next token. */
661 c_token
*token
= c_parser_peek_token (parser
);
662 /* If we've reached the token we want, consume it and stop. */
663 if (token
->type
== type
&& !nesting_depth
)
665 c_parser_consume_token (parser
);
669 /* If we've run out of tokens, stop. */
670 if (token
->type
== CPP_EOF
)
672 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
674 if (token
->type
== CPP_OPEN_BRACE
675 || token
->type
== CPP_OPEN_PAREN
676 || token
->type
== CPP_OPEN_SQUARE
)
678 else if (token
->type
== CPP_CLOSE_BRACE
679 || token
->type
== CPP_CLOSE_PAREN
680 || token
->type
== CPP_CLOSE_SQUARE
)
682 if (nesting_depth
-- == 0)
685 /* Consume this token. */
686 c_parser_consume_token (parser
);
688 parser
->error
= false;
691 /* Skip tokens until the end of a parameter is found, but do not
692 consume the comma, semicolon or closing delimiter. */
695 c_parser_skip_to_end_of_parameter (c_parser
*parser
)
697 unsigned nesting_depth
= 0;
701 c_token
*token
= c_parser_peek_token (parser
);
702 if ((token
->type
== CPP_COMMA
|| token
->type
== CPP_SEMICOLON
)
705 /* If we've run out of tokens, stop. */
706 if (token
->type
== CPP_EOF
)
708 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
710 if (token
->type
== CPP_OPEN_BRACE
711 || token
->type
== CPP_OPEN_PAREN
712 || token
->type
== CPP_OPEN_SQUARE
)
714 else if (token
->type
== CPP_CLOSE_BRACE
715 || token
->type
== CPP_CLOSE_PAREN
716 || token
->type
== CPP_CLOSE_SQUARE
)
718 if (nesting_depth
-- == 0)
721 /* Consume this token. */
722 c_parser_consume_token (parser
);
724 parser
->error
= false;
727 /* Expect to be at the end of the pragma directive and consume an
728 end of line marker. */
731 c_parser_skip_to_pragma_eol (c_parser
*parser
)
733 gcc_assert (parser
->in_pragma
);
734 parser
->in_pragma
= false;
736 if (!c_parser_require (parser
, CPP_PRAGMA_EOL
, "expected end of line"))
739 c_token
*token
= c_parser_peek_token (parser
);
740 if (token
->type
== CPP_EOF
)
742 if (token
->type
== CPP_PRAGMA_EOL
)
744 c_parser_consume_token (parser
);
747 c_parser_consume_token (parser
);
750 parser
->error
= false;
753 /* Skip tokens until we have consumed an entire block, or until we
754 have consumed a non-nested ';'. */
757 c_parser_skip_to_end_of_block_or_statement (c_parser
*parser
)
759 unsigned nesting_depth
= 0;
760 bool save_error
= parser
->error
;
766 /* Peek at the next token. */
767 token
= c_parser_peek_token (parser
);
775 if (parser
->in_pragma
)
780 /* If the next token is a ';', we have reached the
781 end of the statement. */
784 /* Consume the ';'. */
785 c_parser_consume_token (parser
);
790 case CPP_CLOSE_BRACE
:
791 /* If the next token is a non-nested '}', then we have
792 reached the end of the current block. */
793 if (nesting_depth
== 0 || --nesting_depth
== 0)
795 c_parser_consume_token (parser
);
801 /* If it the next token is a '{', then we are entering a new
802 block. Consume the entire block. */
807 /* If we see a pragma, consume the whole thing at once. We
808 have some safeguards against consuming pragmas willy-nilly.
809 Normally, we'd expect to be here with parser->error set,
810 which disables these safeguards. But it's possible to get
811 here for secondary error recovery, after parser->error has
813 c_parser_consume_pragma (parser
);
814 c_parser_skip_to_pragma_eol (parser
);
815 parser
->error
= save_error
;
822 c_parser_consume_token (parser
);
826 parser
->error
= false;
829 /* CPP's options (initialized by c-opts.c). */
830 extern cpp_options
*cpp_opts
;
832 /* Save the warning flags which are controlled by __extension__. */
835 disable_extension_diagnostics (void)
838 | (warn_pointer_arith
<< 1)
839 | (warn_traditional
<< 2)
841 | (warn_long_long
<< 4)
842 | (warn_cxx_compat
<< 5));
843 cpp_opts
->pedantic
= pedantic
= 0;
844 warn_pointer_arith
= 0;
845 cpp_opts
->warn_traditional
= warn_traditional
= 0;
847 cpp_opts
->warn_long_long
= warn_long_long
= 0;
852 /* Restore the warning flags which are controlled by __extension__.
853 FLAGS is the return value from disable_extension_diagnostics. */
856 restore_extension_diagnostics (int flags
)
858 cpp_opts
->pedantic
= pedantic
= flags
& 1;
859 warn_pointer_arith
= (flags
>> 1) & 1;
860 cpp_opts
->warn_traditional
= warn_traditional
= (flags
>> 2) & 1;
861 flag_iso
= (flags
>> 3) & 1;
862 cpp_opts
->warn_long_long
= warn_long_long
= (flags
>> 4) & 1;
863 warn_cxx_compat
= (flags
>> 5) & 1;
866 /* Possibly kinds of declarator to parse. */
867 typedef enum c_dtr_syn
{
868 /* A normal declarator with an identifier. */
870 /* An abstract declarator (maybe empty). */
872 /* A parameter declarator: may be either, but after a type name does
873 not redeclare a typedef name as an identifier if it can
874 alternatively be interpreted as a typedef name; see DR#009,
875 applied in C90 TC1, omitted from C99 and reapplied in C99 TC2
876 following DR#249. For example, given a typedef T, "int T" and
877 "int *T" are valid parameter declarations redeclaring T, while
878 "int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are
879 abstract declarators rather than involving redundant parentheses;
880 the same applies with attributes inside the parentheses before
885 static void c_parser_external_declaration (c_parser
*);
886 static void c_parser_asm_definition (c_parser
*);
887 static void c_parser_declaration_or_fndef (c_parser
*, bool, bool, bool, bool);
888 static void c_parser_declspecs (c_parser
*, struct c_declspecs
*, bool, bool,
890 static struct c_typespec
c_parser_enum_specifier (c_parser
*);
891 static struct c_typespec
c_parser_struct_or_union_specifier (c_parser
*);
892 static tree
c_parser_struct_declaration (c_parser
*);
893 static struct c_typespec
c_parser_typeof_specifier (c_parser
*);
894 static struct c_declarator
*c_parser_declarator (c_parser
*, bool, c_dtr_syn
,
896 static struct c_declarator
*c_parser_direct_declarator (c_parser
*, bool,
898 static struct c_declarator
*c_parser_direct_declarator_inner (c_parser
*,
900 struct c_declarator
*);
901 static struct c_arg_info
*c_parser_parms_declarator (c_parser
*, bool, tree
);
902 static struct c_arg_info
*c_parser_parms_list_declarator (c_parser
*, tree
);
903 static struct c_parm
*c_parser_parameter_declaration (c_parser
*, tree
);
904 static tree
c_parser_simple_asm_expr (c_parser
*);
905 static tree
c_parser_attributes (c_parser
*);
906 static struct c_type_name
*c_parser_type_name (c_parser
*);
907 static struct c_expr
c_parser_initializer (c_parser
*);
908 static struct c_expr
c_parser_braced_init (c_parser
*, tree
, bool);
909 static void c_parser_initelt (c_parser
*);
910 static void c_parser_initval (c_parser
*, struct c_expr
*);
911 static tree
c_parser_compound_statement (c_parser
*);
912 static void c_parser_compound_statement_nostart (c_parser
*);
913 static void c_parser_label (c_parser
*);
914 static void c_parser_statement (c_parser
*);
915 static void c_parser_statement_after_labels (c_parser
*);
916 static void c_parser_if_statement (c_parser
*);
917 static void c_parser_switch_statement (c_parser
*);
918 static void c_parser_while_statement (c_parser
*);
919 static void c_parser_do_statement (c_parser
*);
920 static void c_parser_for_statement (c_parser
*);
921 static tree
c_parser_asm_statement (c_parser
*);
922 static tree
c_parser_asm_operands (c_parser
*, bool);
923 static tree
c_parser_asm_goto_operands (c_parser
*);
924 static tree
c_parser_asm_clobbers (c_parser
*);
925 static struct c_expr
c_parser_expr_no_commas (c_parser
*, struct c_expr
*);
926 static struct c_expr
c_parser_conditional_expression (c_parser
*,
928 static struct c_expr
c_parser_binary_expression (c_parser
*, struct c_expr
*);
929 static struct c_expr
c_parser_cast_expression (c_parser
*, struct c_expr
*);
930 static struct c_expr
c_parser_unary_expression (c_parser
*);
931 static struct c_expr
c_parser_sizeof_expression (c_parser
*);
932 static struct c_expr
c_parser_alignof_expression (c_parser
*);
933 static struct c_expr
c_parser_postfix_expression (c_parser
*);
934 static struct c_expr
c_parser_postfix_expression_after_paren_type (c_parser
*,
935 struct c_type_name
*,
937 static struct c_expr
c_parser_postfix_expression_after_primary (c_parser
*,
940 static struct c_expr
c_parser_expression (c_parser
*);
941 static struct c_expr
c_parser_expression_conv (c_parser
*);
942 static VEC(tree
,gc
) *c_parser_expr_list (c_parser
*, bool, bool,
944 static void c_parser_omp_construct (c_parser
*);
945 static void c_parser_omp_threadprivate (c_parser
*);
946 static void c_parser_omp_barrier (c_parser
*);
947 static void c_parser_omp_flush (c_parser
*);
948 static void c_parser_omp_taskwait (c_parser
*);
950 enum pragma_context
{ pragma_external
, pragma_stmt
, pragma_compound
};
951 static bool c_parser_pragma (c_parser
*, enum pragma_context
);
953 /* These Objective-C parser functions are only ever called when
954 compiling Objective-C. */
955 static void c_parser_objc_class_definition (c_parser
*);
956 static void c_parser_objc_class_instance_variables (c_parser
*);
957 static void c_parser_objc_class_declaration (c_parser
*);
958 static void c_parser_objc_alias_declaration (c_parser
*);
959 static void c_parser_objc_protocol_definition (c_parser
*);
960 static enum tree_code
c_parser_objc_method_type (c_parser
*);
961 static void c_parser_objc_method_definition (c_parser
*);
962 static void c_parser_objc_methodprotolist (c_parser
*);
963 static void c_parser_objc_methodproto (c_parser
*);
964 static tree
c_parser_objc_method_decl (c_parser
*);
965 static tree
c_parser_objc_type_name (c_parser
*);
966 static tree
c_parser_objc_protocol_refs (c_parser
*);
967 static void c_parser_objc_try_catch_statement (c_parser
*);
968 static void c_parser_objc_synchronized_statement (c_parser
*);
969 static tree
c_parser_objc_selector (c_parser
*);
970 static tree
c_parser_objc_selector_arg (c_parser
*);
971 static tree
c_parser_objc_receiver (c_parser
*);
972 static tree
c_parser_objc_message_args (c_parser
*);
973 static tree
c_parser_objc_keywordexpr (c_parser
*);
975 /* Parse a translation unit (C90 6.7, C99 6.9).
978 external-declarations
980 external-declarations:
982 external-declarations external-declaration
991 c_parser_translation_unit (c_parser
*parser
)
993 if (c_parser_next_token_is (parser
, CPP_EOF
))
995 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
996 "ISO C forbids an empty translation unit");
1000 void *obstack_position
= obstack_alloc (&parser_obstack
, 0);
1001 mark_valid_location_for_stdc_pragma (false);
1005 c_parser_external_declaration (parser
);
1006 obstack_free (&parser_obstack
, obstack_position
);
1008 while (c_parser_next_token_is_not (parser
, CPP_EOF
));
1012 /* Parse an external declaration (C90 6.7, C99 6.9).
1014 external-declaration:
1020 external-declaration:
1023 __extension__ external-declaration
1027 external-declaration:
1028 objc-class-definition
1029 objc-class-declaration
1030 objc-alias-declaration
1031 objc-protocol-definition
1032 objc-method-definition
1037 c_parser_external_declaration (c_parser
*parser
)
1040 switch (c_parser_peek_token (parser
)->type
)
1043 switch (c_parser_peek_token (parser
)->keyword
)
1046 ext
= disable_extension_diagnostics ();
1047 c_parser_consume_token (parser
);
1048 c_parser_external_declaration (parser
);
1049 restore_extension_diagnostics (ext
);
1052 c_parser_asm_definition (parser
);
1054 case RID_AT_INTERFACE
:
1055 case RID_AT_IMPLEMENTATION
:
1056 gcc_assert (c_dialect_objc ());
1057 c_parser_objc_class_definition (parser
);
1060 gcc_assert (c_dialect_objc ());
1061 c_parser_objc_class_declaration (parser
);
1064 gcc_assert (c_dialect_objc ());
1065 c_parser_objc_alias_declaration (parser
);
1067 case RID_AT_PROTOCOL
:
1068 gcc_assert (c_dialect_objc ());
1069 c_parser_objc_protocol_definition (parser
);
1072 gcc_assert (c_dialect_objc ());
1073 c_parser_consume_token (parser
);
1074 objc_finish_implementation ();
1081 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
1082 "ISO C does not allow extra %<;%> outside of a function");
1083 c_parser_consume_token (parser
);
1086 mark_valid_location_for_stdc_pragma (true);
1087 c_parser_pragma (parser
, pragma_external
);
1088 mark_valid_location_for_stdc_pragma (false);
1092 if (c_dialect_objc ())
1094 c_parser_objc_method_definition (parser
);
1097 /* Else fall through, and yield a syntax error trying to parse
1098 as a declaration or function definition. */
1101 /* A declaration or a function definition. We can only tell
1102 which after parsing the declaration specifiers, if any, and
1103 the first declarator. */
1104 c_parser_declaration_or_fndef (parser
, true, true, false, true);
1110 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1111 6.7, 6.9.1). If FNDEF_OK is true, a function definition is
1112 accepted; otherwise (old-style parameter declarations) only other
1113 declarations are accepted. If NESTED is true, we are inside a
1114 function or parsing old-style parameter declarations; any functions
1115 encountered are nested functions and declaration specifiers are
1116 required; otherwise we are at top level and functions are normal
1117 functions and declaration specifiers may be optional. If EMPTY_OK
1118 is true, empty declarations are OK (subject to all other
1119 constraints); otherwise (old-style parameter declarations) they are
1120 diagnosed. If START_ATTR_OK is true, the declaration specifiers
1121 may start with attributes; otherwise they may not.
1124 declaration-specifiers init-declarator-list[opt] ;
1126 function-definition:
1127 declaration-specifiers[opt] declarator declaration-list[opt]
1132 declaration-list declaration
1134 init-declarator-list:
1136 init-declarator-list , init-declarator
1139 declarator simple-asm-expr[opt] attributes[opt]
1140 declarator simple-asm-expr[opt] attributes[opt] = initializer
1144 nested-function-definition:
1145 declaration-specifiers declarator declaration-list[opt]
1148 The simple-asm-expr and attributes are GNU extensions.
1150 This function does not handle __extension__; that is handled in its
1151 callers. ??? Following the old parser, __extension__ may start
1152 external declarations, declarations in functions and declarations
1153 at the start of "for" loops, but not old-style parameter
1156 C99 requires declaration specifiers in a function definition; the
1157 absence is diagnosed through the diagnosis of implicit int. In GNU
1158 C we also allow but diagnose declarations without declaration
1159 specifiers, but only at top level (elsewhere they conflict with
1165 threadprivate-directive */
1168 c_parser_declaration_or_fndef (c_parser
*parser
, bool fndef_ok
, bool empty_ok
,
1169 bool nested
, bool start_attr_ok
)
1171 struct c_declspecs
*specs
;
1173 tree all_prefix_attrs
;
1174 bool diagnosed_no_specs
= false;
1175 location_t here
= c_parser_peek_token (parser
)->location
;
1177 specs
= build_null_declspecs ();
1178 c_parser_declspecs (parser
, specs
, true, true, start_attr_ok
);
1181 c_parser_skip_to_end_of_block_or_statement (parser
);
1184 if (nested
&& !specs
->declspecs_seen_p
)
1186 c_parser_error (parser
, "expected declaration specifiers");
1187 c_parser_skip_to_end_of_block_or_statement (parser
);
1190 finish_declspecs (specs
);
1191 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1197 shadow_tag_warned (specs
, 1);
1198 pedwarn (here
, 0, "empty declaration");
1200 c_parser_consume_token (parser
);
1203 pending_xref_error ();
1204 prefix_attrs
= specs
->attrs
;
1205 all_prefix_attrs
= prefix_attrs
;
1206 specs
->attrs
= NULL_TREE
;
1209 struct c_declarator
*declarator
;
1212 /* Declaring either one or more declarators (in which case we
1213 should diagnose if there were no declaration specifiers) or a
1214 function definition (in which case the diagnostic for
1215 implicit int suffices). */
1216 declarator
= c_parser_declarator (parser
, specs
->type_seen_p
,
1217 C_DTR_NORMAL
, &dummy
);
1218 if (declarator
== NULL
)
1220 c_parser_skip_to_end_of_block_or_statement (parser
);
1223 if (c_parser_next_token_is (parser
, CPP_EQ
)
1224 || c_parser_next_token_is (parser
, CPP_COMMA
)
1225 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
1226 || c_parser_next_token_is_keyword (parser
, RID_ASM
)
1227 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1229 tree asm_name
= NULL_TREE
;
1230 tree postfix_attrs
= NULL_TREE
;
1231 if (!diagnosed_no_specs
&& !specs
->declspecs_seen_p
)
1233 diagnosed_no_specs
= true;
1234 pedwarn (here
, 0, "data definition has no type or storage class");
1236 /* Having seen a data definition, there cannot now be a
1237 function definition. */
1239 if (c_parser_next_token_is_keyword (parser
, RID_ASM
))
1240 asm_name
= c_parser_simple_asm_expr (parser
);
1241 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1242 postfix_attrs
= c_parser_attributes (parser
);
1243 if (c_parser_next_token_is (parser
, CPP_EQ
))
1247 location_t init_loc
;
1248 c_parser_consume_token (parser
);
1249 /* The declaration of the variable is in effect while
1250 its initializer is parsed. */
1251 d
= start_decl (declarator
, specs
, true,
1252 chainon (postfix_attrs
, all_prefix_attrs
));
1254 d
= error_mark_node
;
1255 start_init (d
, asm_name
, global_bindings_p ());
1256 init_loc
= c_parser_peek_token (parser
)->location
;
1257 init
= c_parser_initializer (parser
);
1259 if (d
!= error_mark_node
)
1261 maybe_warn_string_init (TREE_TYPE (d
), init
);
1262 finish_decl (d
, init_loc
, init
.value
,
1263 init
.original_type
, asm_name
);
1268 tree d
= start_decl (declarator
, specs
, false,
1269 chainon (postfix_attrs
,
1272 finish_decl (d
, UNKNOWN_LOCATION
, NULL_TREE
,
1273 NULL_TREE
, asm_name
);
1275 if (c_parser_next_token_is (parser
, CPP_COMMA
))
1277 c_parser_consume_token (parser
);
1278 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1279 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
1282 all_prefix_attrs
= prefix_attrs
;
1285 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1287 c_parser_consume_token (parser
);
1292 c_parser_error (parser
, "expected %<,%> or %<;%>");
1293 c_parser_skip_to_end_of_block_or_statement (parser
);
1299 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, "
1300 "%<asm%> or %<__attribute__%>");
1301 c_parser_skip_to_end_of_block_or_statement (parser
);
1304 /* Function definition (nested or otherwise). */
1307 pedwarn (here
, OPT_pedantic
, "ISO C forbids nested functions");
1308 c_push_function_context ();
1310 if (!start_function (specs
, declarator
, all_prefix_attrs
))
1312 /* This can appear in many cases looking nothing like a
1313 function definition, so we don't give a more specific
1314 error suggesting there was one. */
1315 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
1316 "or %<__attribute__%>");
1318 c_pop_function_context ();
1321 /* Parse old-style parameter declarations. ??? Attributes are
1322 not allowed to start declaration specifiers here because of a
1323 syntax conflict between a function declaration with attribute
1324 suffix and a function definition with an attribute prefix on
1325 first old-style parameter declaration. Following the old
1326 parser, they are not accepted on subsequent old-style
1327 parameter declarations either. However, there is no
1328 ambiguity after the first declaration, nor indeed on the
1329 first as long as we don't allow postfix attributes after a
1330 declarator with a nonempty identifier list in a definition;
1331 and postfix attributes have never been accepted here in
1332 function definitions either. */
1333 while (c_parser_next_token_is_not (parser
, CPP_EOF
)
1334 && c_parser_next_token_is_not (parser
, CPP_OPEN_BRACE
))
1335 c_parser_declaration_or_fndef (parser
, false, false, true, false);
1336 store_parm_decls ();
1337 DECL_STRUCT_FUNCTION (current_function_decl
)->function_start_locus
1338 = c_parser_peek_token (parser
)->location
;
1339 fnbody
= c_parser_compound_statement (parser
);
1342 tree decl
= current_function_decl
;
1343 /* Mark nested functions as needing static-chain initially.
1344 lower_nested_functions will recompute it but the
1345 DECL_STATIC_CHAIN flag is also used before that happens,
1346 by initializer_constant_valid_p. See gcc.dg/nested-fn-2.c. */
1347 DECL_STATIC_CHAIN (decl
) = 1;
1350 c_pop_function_context ();
1351 add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl
), DECL_EXPR
, decl
));
1362 /* Parse an asm-definition (asm() outside a function body). This is a
1370 c_parser_asm_definition (c_parser
*parser
)
1372 tree asm_str
= c_parser_simple_asm_expr (parser
);
1374 cgraph_add_asm_node (asm_str
);
1375 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
1378 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
1379 6.7), adding them to SPECS (which may already include some).
1380 Storage class specifiers are accepted iff SCSPEC_OK; type
1381 specifiers are accepted iff TYPESPEC_OK; attributes are accepted at
1382 the start iff START_ATTR_OK.
1384 declaration-specifiers:
1385 storage-class-specifier declaration-specifiers[opt]
1386 type-specifier declaration-specifiers[opt]
1387 type-qualifier declaration-specifiers[opt]
1388 function-specifier declaration-specifiers[opt]
1390 Function specifiers (inline) are from C99, and are currently
1391 handled as storage class specifiers, as is __thread.
1393 C90 6.5.1, C99 6.7.1:
1394 storage-class-specifier:
1405 C90 6.5.2, C99 6.7.2:
1418 [_Imaginary removed in C99 TC2]
1419 struct-or-union-specifier
1423 (_Bool and _Complex are new in C99.)
1425 C90 6.5.3, C99 6.7.3:
1431 address-space-qualifier
1433 (restrict is new in C99.)
1437 declaration-specifiers:
1438 attributes declaration-specifiers[opt]
1444 identifier recognized by the target
1446 storage-class-specifier:
1458 (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
1459 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
1464 class-name objc-protocol-refs[opt]
1465 typedef-name objc-protocol-refs
1470 c_parser_declspecs (c_parser
*parser
, struct c_declspecs
*specs
,
1471 bool scspec_ok
, bool typespec_ok
, bool start_attr_ok
)
1473 bool attrs_ok
= start_attr_ok
;
1474 bool seen_type
= specs
->type_seen_p
;
1475 while (c_parser_next_token_is (parser
, CPP_NAME
)
1476 || c_parser_next_token_is (parser
, CPP_KEYWORD
)
1477 || (c_dialect_objc () && c_parser_next_token_is (parser
, CPP_LESS
)))
1479 struct c_typespec t
;
1481 location_t loc
= c_parser_peek_token (parser
)->location
;
1482 if (c_parser_next_token_is (parser
, CPP_NAME
))
1484 tree value
= c_parser_peek_token (parser
)->value
;
1485 c_id_kind kind
= c_parser_peek_token (parser
)->id_kind
;
1487 if (kind
== C_ID_ADDRSPACE
)
1490 = c_parser_peek_token (parser
)->keyword
- RID_FIRST_ADDR_SPACE
;
1491 declspecs_add_addrspace (specs
, as
);
1492 c_parser_consume_token (parser
);
1497 /* This finishes the specifiers unless a type name is OK, it
1498 is declared as a type name and a type name hasn't yet
1500 if (!typespec_ok
|| seen_type
1501 || (kind
!= C_ID_TYPENAME
&& kind
!= C_ID_CLASSNAME
))
1503 c_parser_consume_token (parser
);
1506 if (kind
== C_ID_TYPENAME
1507 && (!c_dialect_objc ()
1508 || c_parser_next_token_is_not (parser
, CPP_LESS
)))
1510 t
.kind
= ctsk_typedef
;
1511 /* For a typedef name, record the meaning, not the name.
1512 In case of 'foo foo, bar;'. */
1513 t
.spec
= lookup_name (value
);
1515 t
.expr_const_operands
= true;
1519 tree proto
= NULL_TREE
;
1520 gcc_assert (c_dialect_objc ());
1522 if (c_parser_next_token_is (parser
, CPP_LESS
))
1523 proto
= c_parser_objc_protocol_refs (parser
);
1524 t
.spec
= objc_get_protocol_qualified_type (value
, proto
);
1526 t
.expr_const_operands
= true;
1528 declspecs_add_type (loc
, specs
, t
);
1531 if (c_parser_next_token_is (parser
, CPP_LESS
))
1533 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
1534 nisse@lysator.liu.se. */
1536 gcc_assert (c_dialect_objc ());
1537 if (!typespec_ok
|| seen_type
)
1539 proto
= c_parser_objc_protocol_refs (parser
);
1541 t
.spec
= objc_get_protocol_qualified_type (NULL_TREE
, proto
);
1543 t
.expr_const_operands
= true;
1544 declspecs_add_type (loc
, specs
, t
);
1547 gcc_assert (c_parser_next_token_is (parser
, CPP_KEYWORD
));
1548 switch (c_parser_peek_token (parser
)->keyword
)
1560 /* TODO: Distinguish between function specifiers (inline)
1561 and storage class specifiers, either here or in
1562 declspecs_add_scspec. */
1563 declspecs_add_scspec (specs
, c_parser_peek_token (parser
)->value
);
1564 c_parser_consume_token (parser
);
1587 if (c_dialect_objc ())
1588 parser
->objc_need_raw_identifier
= true;
1589 t
.kind
= ctsk_resword
;
1590 t
.spec
= c_parser_peek_token (parser
)->value
;
1592 t
.expr_const_operands
= true;
1593 declspecs_add_type (loc
, specs
, t
);
1594 c_parser_consume_token (parser
);
1601 t
= c_parser_enum_specifier (parser
);
1602 declspecs_add_type (loc
, specs
, t
);
1610 t
= c_parser_struct_or_union_specifier (parser
);
1611 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE
, t
.spec
);
1612 declspecs_add_type (loc
, specs
, t
);
1615 /* ??? The old parser rejected typeof after other type
1616 specifiers, but is a syntax error the best way of
1618 if (!typespec_ok
|| seen_type
)
1622 t
= c_parser_typeof_specifier (parser
);
1623 declspecs_add_type (loc
, specs
, t
);
1629 declspecs_add_qual (specs
, c_parser_peek_token (parser
)->value
);
1630 c_parser_consume_token (parser
);
1635 attrs
= c_parser_attributes (parser
);
1636 declspecs_add_attrs (specs
, attrs
);
1645 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
1648 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
1649 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
1650 enum attributes[opt] identifier
1652 The form with trailing comma is new in C99. The forms with
1653 attributes are GNU extensions. In GNU C, we accept any expression
1654 without commas in the syntax (assignment expressions, not just
1655 conditional expressions); assignment expressions will be diagnosed
1660 enumerator-list , enumerator
1663 enumeration-constant
1664 enumeration-constant = constant-expression
1667 static struct c_typespec
1668 c_parser_enum_specifier (c_parser
*parser
)
1670 struct c_typespec ret
;
1672 tree ident
= NULL_TREE
;
1673 location_t enum_loc
;
1674 location_t ident_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
1675 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ENUM
));
1676 enum_loc
= c_parser_peek_token (parser
)->location
;
1677 c_parser_consume_token (parser
);
1678 attrs
= c_parser_attributes (parser
);
1679 enum_loc
= c_parser_peek_token (parser
)->location
;
1680 /* Set the location in case we create a decl now. */
1681 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
1682 if (c_parser_next_token_is (parser
, CPP_NAME
))
1684 ident
= c_parser_peek_token (parser
)->value
;
1685 ident_loc
= c_parser_peek_token (parser
)->location
;
1686 enum_loc
= ident_loc
;
1687 c_parser_consume_token (parser
);
1689 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
1691 /* Parse an enum definition. */
1692 struct c_enum_contents the_enum
;
1693 tree type
= start_enum (enum_loc
, &the_enum
, ident
);
1695 /* We chain the enumerators in reverse order, then put them in
1696 forward order at the end. */
1697 tree values
= NULL_TREE
;
1698 c_parser_consume_token (parser
);
1706 location_t comma_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
1707 location_t value_loc
;
1708 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
1710 c_parser_error (parser
, "expected identifier");
1711 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
1712 values
= error_mark_node
;
1715 token
= c_parser_peek_token (parser
);
1716 enum_id
= token
->value
;
1717 /* Set the location in case we create a decl now. */
1718 c_parser_set_source_position_from_token (token
);
1719 value_loc
= token
->location
;
1720 c_parser_consume_token (parser
);
1721 if (c_parser_next_token_is (parser
, CPP_EQ
))
1723 c_parser_consume_token (parser
);
1724 value_loc
= c_parser_peek_token (parser
)->location
;
1725 enum_value
= c_parser_expr_no_commas (parser
, NULL
).value
;
1728 enum_value
= NULL_TREE
;
1729 enum_decl
= build_enumerator (value_loc
,
1730 &the_enum
, enum_id
, enum_value
);
1731 TREE_CHAIN (enum_decl
) = values
;
1734 if (c_parser_next_token_is (parser
, CPP_COMMA
))
1736 comma_loc
= c_parser_peek_token (parser
)->location
;
1738 c_parser_consume_token (parser
);
1740 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
1742 if (seen_comma
&& !flag_isoc99
)
1743 pedwarn (comma_loc
, OPT_pedantic
, "comma at end of enumerator list");
1744 c_parser_consume_token (parser
);
1749 c_parser_error (parser
, "expected %<,%> or %<}%>");
1750 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
1751 values
= error_mark_node
;
1755 postfix_attrs
= c_parser_attributes (parser
);
1756 ret
.spec
= finish_enum (type
, nreverse (values
),
1757 chainon (attrs
, postfix_attrs
));
1758 ret
.kind
= ctsk_tagdef
;
1759 ret
.expr
= NULL_TREE
;
1760 ret
.expr_const_operands
= true;
1765 c_parser_error (parser
, "expected %<{%>");
1766 ret
.spec
= error_mark_node
;
1767 ret
.kind
= ctsk_tagref
;
1768 ret
.expr
= NULL_TREE
;
1769 ret
.expr_const_operands
= true;
1772 ret
= parser_xref_tag (ident_loc
, ENUMERAL_TYPE
, ident
);
1773 /* In ISO C, enumerated types can be referred to only if already
1775 if (pedantic
&& !COMPLETE_TYPE_P (ret
.spec
))
1778 pedwarn (enum_loc
, OPT_pedantic
,
1779 "ISO C forbids forward references to %<enum%> types");
1784 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
1786 struct-or-union-specifier:
1787 struct-or-union attributes[opt] identifier[opt]
1788 { struct-contents } attributes[opt]
1789 struct-or-union attributes[opt] identifier
1792 struct-declaration-list
1794 struct-declaration-list:
1795 struct-declaration ;
1796 struct-declaration-list struct-declaration ;
1803 struct-declaration-list struct-declaration
1805 struct-declaration-list:
1806 struct-declaration-list ;
1809 (Note that in the syntax here, unlike that in ISO C, the semicolons
1810 are included here rather than in struct-declaration, in order to
1811 describe the syntax with extra semicolons and missing semicolon at
1816 struct-declaration-list:
1817 @defs ( class-name )
1819 (Note this does not include a trailing semicolon, but can be
1820 followed by further declarations, and gets a pedwarn-if-pedantic
1821 when followed by a semicolon.) */
1823 static struct c_typespec
1824 c_parser_struct_or_union_specifier (c_parser
*parser
)
1826 struct c_typespec ret
;
1828 tree ident
= NULL_TREE
;
1829 location_t struct_loc
;
1830 location_t ident_loc
= UNKNOWN_LOCATION
;
1831 enum tree_code code
;
1832 switch (c_parser_peek_token (parser
)->keyword
)
1843 struct_loc
= c_parser_peek_token (parser
)->location
;
1844 c_parser_consume_token (parser
);
1845 attrs
= c_parser_attributes (parser
);
1847 /* Set the location in case we create a decl now. */
1848 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
1850 if (c_parser_next_token_is (parser
, CPP_NAME
))
1852 ident
= c_parser_peek_token (parser
)->value
;
1853 ident_loc
= c_parser_peek_token (parser
)->location
;
1854 struct_loc
= ident_loc
;
1855 c_parser_consume_token (parser
);
1857 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
1859 /* Parse a struct or union definition. Start the scope of the
1860 tag before parsing components. */
1861 struct c_struct_parse_info
*struct_info
;
1862 tree type
= start_struct (struct_loc
, code
, ident
, &struct_info
);
1864 /* We chain the components in reverse order, then put them in
1865 forward order at the end. Each struct-declaration may
1866 declare multiple components (comma-separated), so we must use
1867 chainon to join them, although when parsing each
1868 struct-declaration we can use TREE_CHAIN directly.
1870 The theory behind all this is that there will be more
1871 semicolon separated fields than comma separated fields, and
1872 so we'll be minimizing the number of node traversals required
1874 tree contents
= NULL_TREE
;
1875 c_parser_consume_token (parser
);
1876 /* Handle the Objective-C @defs construct,
1877 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
1878 if (c_parser_next_token_is_keyword (parser
, RID_AT_DEFS
))
1881 gcc_assert (c_dialect_objc ());
1882 c_parser_consume_token (parser
);
1883 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
1885 if (c_parser_next_token_is (parser
, CPP_NAME
)
1886 && c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
)
1888 name
= c_parser_peek_token (parser
)->value
;
1889 c_parser_consume_token (parser
);
1893 c_parser_error (parser
, "expected class name");
1894 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
1897 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
1899 contents
= nreverse (objc_get_class_ivars (name
));
1902 /* Parse the struct-declarations and semicolons. Problems with
1903 semicolons are diagnosed here; empty structures are diagnosed
1908 /* Parse any stray semicolon. */
1909 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1911 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
1912 "extra semicolon in struct or union specified");
1913 c_parser_consume_token (parser
);
1916 /* Stop if at the end of the struct or union contents. */
1917 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
1919 c_parser_consume_token (parser
);
1922 /* Accept #pragmas at struct scope. */
1923 if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
1925 c_parser_pragma (parser
, pragma_external
);
1928 /* Parse some comma-separated declarations, but not the
1929 trailing semicolon if any. */
1930 decls
= c_parser_struct_declaration (parser
);
1931 contents
= chainon (decls
, contents
);
1932 /* If no semicolon follows, either we have a parse error or
1933 are at the end of the struct or union and should
1935 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1936 c_parser_consume_token (parser
);
1939 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
1940 pedwarn (c_parser_peek_token (parser
)->location
, 0,
1941 "no semicolon at end of struct or union");
1944 c_parser_error (parser
, "expected %<;%>");
1945 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
1950 postfix_attrs
= c_parser_attributes (parser
);
1951 ret
.spec
= finish_struct (struct_loc
, type
, nreverse (contents
),
1952 chainon (attrs
, postfix_attrs
), struct_info
);
1953 ret
.kind
= ctsk_tagdef
;
1954 ret
.expr
= NULL_TREE
;
1955 ret
.expr_const_operands
= true;
1960 c_parser_error (parser
, "expected %<{%>");
1961 ret
.spec
= error_mark_node
;
1962 ret
.kind
= ctsk_tagref
;
1963 ret
.expr
= NULL_TREE
;
1964 ret
.expr_const_operands
= true;
1967 ret
= parser_xref_tag (ident_loc
, code
, ident
);
1971 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
1972 the trailing semicolon.
1975 specifier-qualifier-list struct-declarator-list
1977 specifier-qualifier-list:
1978 type-specifier specifier-qualifier-list[opt]
1979 type-qualifier specifier-qualifier-list[opt]
1980 attributes specifier-qualifier-list[opt]
1982 struct-declarator-list:
1984 struct-declarator-list , attributes[opt] struct-declarator
1987 declarator attributes[opt]
1988 declarator[opt] : constant-expression attributes[opt]
1993 __extension__ struct-declaration
1994 specifier-qualifier-list
1996 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
1997 of attributes where shown is a GNU extension. In GNU C, we accept
1998 any expression without commas in the syntax (assignment
1999 expressions, not just conditional expressions); assignment
2000 expressions will be diagnosed as non-constant. */
2003 c_parser_struct_declaration (c_parser
*parser
)
2005 struct c_declspecs
*specs
;
2007 tree all_prefix_attrs
;
2009 location_t decl_loc
;
2010 if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
2014 ext
= disable_extension_diagnostics ();
2015 c_parser_consume_token (parser
);
2016 decl
= c_parser_struct_declaration (parser
);
2017 restore_extension_diagnostics (ext
);
2020 specs
= build_null_declspecs ();
2021 decl_loc
= c_parser_peek_token (parser
)->location
;
2022 c_parser_declspecs (parser
, specs
, false, true, true);
2025 if (!specs
->declspecs_seen_p
)
2027 c_parser_error (parser
, "expected specifier-qualifier-list");
2030 finish_declspecs (specs
);
2031 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2034 if (!specs
->type_seen_p
)
2036 pedwarn (decl_loc
, OPT_pedantic
,
2037 "ISO C forbids member declarations with no members");
2038 shadow_tag_warned (specs
, pedantic
);
2043 /* Support for unnamed structs or unions as members of
2044 structs or unions (which is [a] useful and [b] supports
2048 ret
= grokfield (c_parser_peek_token (parser
)->location
,
2049 build_id_declarator (NULL_TREE
), specs
,
2052 decl_attributes (&ret
, attrs
, 0);
2056 pending_xref_error ();
2057 prefix_attrs
= specs
->attrs
;
2058 all_prefix_attrs
= prefix_attrs
;
2059 specs
->attrs
= NULL_TREE
;
2063 /* Declaring one or more declarators or un-named bit-fields. */
2064 struct c_declarator
*declarator
;
2066 if (c_parser_next_token_is (parser
, CPP_COLON
))
2067 declarator
= build_id_declarator (NULL_TREE
);
2069 declarator
= c_parser_declarator (parser
, specs
->type_seen_p
,
2070 C_DTR_NORMAL
, &dummy
);
2071 if (declarator
== NULL
)
2073 c_parser_skip_to_end_of_block_or_statement (parser
);
2076 if (c_parser_next_token_is (parser
, CPP_COLON
)
2077 || c_parser_next_token_is (parser
, CPP_COMMA
)
2078 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2079 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
)
2080 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2082 tree postfix_attrs
= NULL_TREE
;
2083 tree width
= NULL_TREE
;
2085 if (c_parser_next_token_is (parser
, CPP_COLON
))
2087 c_parser_consume_token (parser
);
2088 width
= c_parser_expr_no_commas (parser
, NULL
).value
;
2090 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2091 postfix_attrs
= c_parser_attributes (parser
);
2092 d
= grokfield (c_parser_peek_token (parser
)->location
,
2093 declarator
, specs
, width
, &all_prefix_attrs
);
2094 decl_attributes (&d
, chainon (postfix_attrs
,
2095 all_prefix_attrs
), 0);
2096 TREE_CHAIN (d
) = decls
;
2098 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2099 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
2102 all_prefix_attrs
= prefix_attrs
;
2103 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2104 c_parser_consume_token (parser
);
2105 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2106 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2108 /* Semicolon consumed in caller. */
2113 c_parser_error (parser
, "expected %<,%>, %<;%> or %<}%>");
2119 c_parser_error (parser
,
2120 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
2121 "%<__attribute__%>");
2128 /* Parse a typeof specifier (a GNU extension).
2131 typeof ( expression )
2132 typeof ( type-name )
2135 static struct c_typespec
2136 c_parser_typeof_specifier (c_parser
*parser
)
2138 struct c_typespec ret
;
2139 ret
.kind
= ctsk_typeof
;
2140 ret
.spec
= error_mark_node
;
2141 ret
.expr
= NULL_TREE
;
2142 ret
.expr_const_operands
= true;
2143 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TYPEOF
));
2144 c_parser_consume_token (parser
);
2145 c_inhibit_evaluation_warnings
++;
2147 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2149 c_inhibit_evaluation_warnings
--;
2153 if (c_parser_next_token_starts_typename (parser
))
2155 struct c_type_name
*type
= c_parser_type_name (parser
);
2156 c_inhibit_evaluation_warnings
--;
2160 ret
.spec
= groktypename (type
, &ret
.expr
, &ret
.expr_const_operands
);
2161 pop_maybe_used (variably_modified_type_p (ret
.spec
, NULL_TREE
));
2167 location_t here
= c_parser_peek_token (parser
)->location
;
2168 struct c_expr expr
= c_parser_expression (parser
);
2169 c_inhibit_evaluation_warnings
--;
2171 if (TREE_CODE (expr
.value
) == COMPONENT_REF
2172 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
2173 error_at (here
, "%<typeof%> applied to a bit-field");
2174 mark_exp_read (expr
.value
);
2175 ret
.spec
= TREE_TYPE (expr
.value
);
2176 was_vm
= variably_modified_type_p (ret
.spec
, NULL_TREE
);
2177 /* This is returned with the type so that when the type is
2178 evaluated, this can be evaluated. */
2180 ret
.expr
= c_fully_fold (expr
.value
, false, &ret
.expr_const_operands
);
2181 pop_maybe_used (was_vm
);
2183 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
2187 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
2188 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
2189 be redeclared; otherwise it may not. KIND indicates which kind of
2190 declarator is wanted. Returns a valid declarator except in the
2191 case of a syntax error in which case NULL is returned. *SEEN_ID is
2192 set to true if an identifier being declared is seen; this is used
2193 to diagnose bad forms of abstract array declarators and to
2194 determine whether an identifier list is syntactically permitted.
2197 pointer[opt] direct-declarator
2201 ( attributes[opt] declarator )
2202 direct-declarator array-declarator
2203 direct-declarator ( parameter-type-list )
2204 direct-declarator ( identifier-list[opt] )
2207 * type-qualifier-list[opt]
2208 * type-qualifier-list[opt] pointer
2210 type-qualifier-list:
2213 type-qualifier-list type-qualifier
2214 type-qualifier-list attributes
2216 parameter-type-list:
2218 parameter-list , ...
2221 parameter-declaration
2222 parameter-list , parameter-declaration
2224 parameter-declaration:
2225 declaration-specifiers declarator attributes[opt]
2226 declaration-specifiers abstract-declarator[opt] attributes[opt]
2230 identifier-list , identifier
2232 abstract-declarator:
2234 pointer[opt] direct-abstract-declarator
2236 direct-abstract-declarator:
2237 ( attributes[opt] abstract-declarator )
2238 direct-abstract-declarator[opt] array-declarator
2239 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
2244 direct-declarator ( parameter-forward-declarations
2245 parameter-type-list[opt] )
2247 direct-abstract-declarator:
2248 direct-abstract-declarator[opt] ( parameter-forward-declarations
2249 parameter-type-list[opt] )
2251 parameter-forward-declarations:
2253 parameter-forward-declarations parameter-list ;
2255 The uses of attributes shown above are GNU extensions.
2257 Some forms of array declarator are not included in C99 in the
2258 syntax for abstract declarators; these are disallowed elsewhere.
2259 This may be a defect (DR#289).
2261 This function also accepts an omitted abstract declarator as being
2262 an abstract declarator, although not part of the formal syntax. */
2264 static struct c_declarator
*
2265 c_parser_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
2268 /* Parse any initial pointer part. */
2269 if (c_parser_next_token_is (parser
, CPP_MULT
))
2271 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
2272 struct c_declarator
*inner
;
2273 c_parser_consume_token (parser
);
2274 c_parser_declspecs (parser
, quals_attrs
, false, false, true);
2275 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
2279 return make_pointer_declarator (quals_attrs
, inner
);
2281 /* Now we have a direct declarator, direct abstract declarator or
2282 nothing (which counts as a direct abstract declarator here). */
2283 return c_parser_direct_declarator (parser
, type_seen_p
, kind
, seen_id
);
2286 /* Parse a direct declarator or direct abstract declarator; arguments
2287 as c_parser_declarator. */
2289 static struct c_declarator
*
2290 c_parser_direct_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
2293 /* The direct declarator must start with an identifier (possibly
2294 omitted) or a parenthesized declarator (possibly abstract). In
2295 an ordinary declarator, initial parentheses must start a
2296 parenthesized declarator. In an abstract declarator or parameter
2297 declarator, they could start a parenthesized declarator or a
2298 parameter list. To tell which, the open parenthesis and any
2299 following attributes must be read. If a declaration specifier
2300 follows, then it is a parameter list; if the specifier is a
2301 typedef name, there might be an ambiguity about redeclaring it,
2302 which is resolved in the direction of treating it as a typedef
2303 name. If a close parenthesis follows, it is also an empty
2304 parameter list, as the syntax does not permit empty abstract
2305 declarators. Otherwise, it is a parenthesized declarator (in
2306 which case the analysis may be repeated inside it, recursively).
2308 ??? There is an ambiguity in a parameter declaration "int
2309 (__attribute__((foo)) x)", where x is not a typedef name: it
2310 could be an abstract declarator for a function, or declare x with
2311 parentheses. The proper resolution of this ambiguity needs
2312 documenting. At present we follow an accident of the old
2313 parser's implementation, whereby the first parameter must have
2314 some declaration specifiers other than just attributes. Thus as
2315 a parameter declaration it is treated as a parenthesized
2316 parameter named x, and as an abstract declarator it is
2319 ??? Also following the old parser, attributes inside an empty
2320 parameter list are ignored, making it a list not yielding a
2321 prototype, rather than giving an error or making it have one
2322 parameter with implicit type int.
2324 ??? Also following the old parser, typedef names may be
2325 redeclared in declarators, but not Objective-C class names. */
2327 if (kind
!= C_DTR_ABSTRACT
2328 && c_parser_next_token_is (parser
, CPP_NAME
)
2330 && c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
)
2331 || c_parser_peek_token (parser
)->id_kind
== C_ID_ID
))
2333 struct c_declarator
*inner
2334 = build_id_declarator (c_parser_peek_token (parser
)->value
);
2336 inner
->id_loc
= c_parser_peek_token (parser
)->location
;
2337 c_parser_consume_token (parser
);
2338 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
2341 if (kind
!= C_DTR_NORMAL
2342 && c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
2344 struct c_declarator
*inner
= build_id_declarator (NULL_TREE
);
2345 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
2348 /* Either we are at the end of an abstract declarator, or we have
2351 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
2354 struct c_declarator
*inner
;
2355 c_parser_consume_token (parser
);
2356 attrs
= c_parser_attributes (parser
);
2357 if (kind
!= C_DTR_NORMAL
2358 && (c_parser_next_token_starts_declspecs (parser
)
2359 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
)))
2361 struct c_arg_info
*args
2362 = c_parser_parms_declarator (parser
, kind
== C_DTR_NORMAL
,
2369 = build_function_declarator (args
,
2370 build_id_declarator (NULL_TREE
));
2371 return c_parser_direct_declarator_inner (parser
, *seen_id
,
2375 /* A parenthesized declarator. */
2376 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
2377 if (inner
!= NULL
&& attrs
!= NULL
)
2378 inner
= build_attrs_declarator (attrs
, inner
);
2379 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2381 c_parser_consume_token (parser
);
2385 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
2389 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2396 if (kind
== C_DTR_NORMAL
)
2398 c_parser_error (parser
, "expected identifier or %<(%>");
2402 return build_id_declarator (NULL_TREE
);
2406 /* Parse part of a direct declarator or direct abstract declarator,
2407 given that some (in INNER) has already been parsed; ID_PRESENT is
2408 true if an identifier is present, false for an abstract
2411 static struct c_declarator
*
2412 c_parser_direct_declarator_inner (c_parser
*parser
, bool id_present
,
2413 struct c_declarator
*inner
)
2415 /* Parse a sequence of array declarators and parameter lists. */
2416 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
2418 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
2419 struct c_declarator
*declarator
;
2420 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
2424 c_parser_consume_token (parser
);
2425 c_parser_declspecs (parser
, quals_attrs
, false, false, true);
2426 static_seen
= c_parser_next_token_is_keyword (parser
, RID_STATIC
);
2428 c_parser_consume_token (parser
);
2429 if (static_seen
&& !quals_attrs
->declspecs_seen_p
)
2430 c_parser_declspecs (parser
, quals_attrs
, false, false, true);
2431 if (!quals_attrs
->declspecs_seen_p
)
2433 /* If "static" is present, there must be an array dimension.
2434 Otherwise, there may be a dimension, "*", or no
2439 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
2443 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
2448 else if (c_parser_next_token_is (parser
, CPP_MULT
))
2450 if (c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_SQUARE
)
2454 c_parser_consume_token (parser
);
2459 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
2465 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
2468 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
2469 c_parser_consume_token (parser
);
2472 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
2476 declarator
= build_array_declarator (brace_loc
, dimen
, quals_attrs
,
2477 static_seen
, star_seen
);
2478 if (declarator
== NULL
)
2480 inner
= set_array_declarator_inner (declarator
, inner
);
2481 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
2483 else if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
2486 struct c_arg_info
*args
;
2487 c_parser_consume_token (parser
);
2488 attrs
= c_parser_attributes (parser
);
2489 args
= c_parser_parms_declarator (parser
, id_present
, attrs
);
2494 inner
= build_function_declarator (args
, inner
);
2495 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
2501 /* Parse a parameter list or identifier list, including the closing
2502 parenthesis but not the opening one. ATTRS are the attributes at
2503 the start of the list. ID_LIST_OK is true if an identifier list is
2504 acceptable; such a list must not have attributes at the start. */
2506 static struct c_arg_info
*
2507 c_parser_parms_declarator (c_parser
*parser
, bool id_list_ok
, tree attrs
)
2510 declare_parm_level ();
2511 /* If the list starts with an identifier, it is an identifier list.
2512 Otherwise, it is either a prototype list or an empty list. */
2515 && c_parser_next_token_is (parser
, CPP_NAME
)
2516 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
2518 tree list
= NULL_TREE
, *nextp
= &list
;
2519 while (c_parser_next_token_is (parser
, CPP_NAME
)
2520 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
2522 *nextp
= build_tree_list (NULL_TREE
,
2523 c_parser_peek_token (parser
)->value
);
2524 nextp
= & TREE_CHAIN (*nextp
);
2525 c_parser_consume_token (parser
);
2526 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
2528 c_parser_consume_token (parser
);
2529 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2531 c_parser_error (parser
, "expected identifier");
2535 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2537 struct c_arg_info
*ret
= XOBNEW (&parser_obstack
, struct c_arg_info
);
2542 ret
->pending_sizes
= 0;
2543 ret
->had_vla_unspec
= 0;
2544 c_parser_consume_token (parser
);
2550 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2558 struct c_arg_info
*ret
= c_parser_parms_list_declarator (parser
, attrs
);
2564 /* Parse a parameter list (possibly empty), including the closing
2565 parenthesis but not the opening one. ATTRS are the attributes at
2566 the start of the list. */
2568 static struct c_arg_info
*
2569 c_parser_parms_list_declarator (c_parser
*parser
, tree attrs
)
2571 bool good_parm
= false;
2572 /* ??? Following the old parser, forward parameter declarations may
2573 use abstract declarators, and if no real parameter declarations
2574 follow the forward declarations then this is not diagnosed. Also
2575 note as above that attributes are ignored as the only contents of
2576 the parentheses, or as the only contents after forward
2578 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2580 struct c_arg_info
*ret
= XOBNEW (&parser_obstack
, struct c_arg_info
);
2585 ret
->pending_sizes
= 0;
2586 ret
->had_vla_unspec
= 0;
2587 c_parser_consume_token (parser
);
2590 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
2592 struct c_arg_info
*ret
= XOBNEW (&parser_obstack
, struct c_arg_info
);
2596 ret
->pending_sizes
= 0;
2597 ret
->had_vla_unspec
= 0;
2598 /* Suppress -Wold-style-definition for this case. */
2599 ret
->types
= error_mark_node
;
2600 error_at (c_parser_peek_token (parser
)->location
,
2601 "ISO C requires a named argument before %<...%>");
2602 c_parser_consume_token (parser
);
2603 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2605 c_parser_consume_token (parser
);
2610 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2615 /* Nonempty list of parameters, either terminated with semicolon
2616 (forward declarations; recurse) or with close parenthesis (normal
2617 function) or with ", ... )" (variadic function). */
2620 /* Parse a parameter. */
2621 struct c_parm
*parm
= c_parser_parameter_declaration (parser
, attrs
);
2626 push_parm_decl (parm
);
2628 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2631 c_parser_consume_token (parser
);
2632 mark_forward_parm_decls ();
2633 new_attrs
= c_parser_attributes (parser
);
2634 return c_parser_parms_list_declarator (parser
, new_attrs
);
2636 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2638 c_parser_consume_token (parser
);
2640 return get_parm_info (false);
2643 struct c_arg_info
*ret
2644 = XOBNEW (&parser_obstack
, struct c_arg_info
);
2649 ret
->pending_sizes
= 0;
2650 ret
->had_vla_unspec
= 0;
2654 if (!c_parser_require (parser
, CPP_COMMA
,
2655 "expected %<;%>, %<,%> or %<)%>"))
2657 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2658 get_pending_sizes ();
2661 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
2663 c_parser_consume_token (parser
);
2664 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2666 c_parser_consume_token (parser
);
2668 return get_parm_info (true);
2671 struct c_arg_info
*ret
2672 = XOBNEW (&parser_obstack
, struct c_arg_info
);
2677 ret
->pending_sizes
= 0;
2678 ret
->had_vla_unspec
= 0;
2684 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2686 get_pending_sizes ();
2693 /* Parse a parameter declaration. ATTRS are the attributes at the
2694 start of the declaration if it is the first parameter. */
2696 static struct c_parm
*
2697 c_parser_parameter_declaration (c_parser
*parser
, tree attrs
)
2699 struct c_declspecs
*specs
;
2700 struct c_declarator
*declarator
;
2702 tree postfix_attrs
= NULL_TREE
;
2704 if (!c_parser_next_token_starts_declspecs (parser
))
2706 /* ??? In some Objective-C cases '...' isn't applicable so there
2707 should be a different message. */
2708 c_parser_error (parser
,
2709 "expected declaration specifiers or %<...%>");
2710 c_parser_skip_to_end_of_parameter (parser
);
2713 specs
= build_null_declspecs ();
2716 declspecs_add_attrs (specs
, attrs
);
2719 c_parser_declspecs (parser
, specs
, true, true, true);
2720 finish_declspecs (specs
);
2721 pending_xref_error ();
2722 prefix_attrs
= specs
->attrs
;
2723 specs
->attrs
= NULL_TREE
;
2724 declarator
= c_parser_declarator (parser
, specs
->type_seen_p
,
2725 C_DTR_PARM
, &dummy
);
2726 if (declarator
== NULL
)
2728 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
2731 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2732 postfix_attrs
= c_parser_attributes (parser
);
2733 return build_c_parm (specs
, chainon (postfix_attrs
, prefix_attrs
),
2737 /* Parse a string literal in an asm expression. It should not be
2738 translated, and wide string literals are an error although
2739 permitted by the syntax. This is a GNU extension.
2744 ??? At present, following the old parser, the caller needs to have
2745 set lex_untranslated_string to 1. It would be better to follow the
2746 C++ parser rather than using this kludge. */
2749 c_parser_asm_string_literal (c_parser
*parser
)
2752 if (c_parser_next_token_is (parser
, CPP_STRING
))
2754 str
= c_parser_peek_token (parser
)->value
;
2755 c_parser_consume_token (parser
);
2757 else if (c_parser_next_token_is (parser
, CPP_WSTRING
))
2759 error_at (c_parser_peek_token (parser
)->location
,
2760 "wide string literal in %<asm%>");
2761 str
= build_string (1, "");
2762 c_parser_consume_token (parser
);
2766 c_parser_error (parser
, "expected string literal");
2772 /* Parse a simple asm expression. This is used in restricted
2773 contexts, where a full expression with inputs and outputs does not
2774 make sense. This is a GNU extension.
2777 asm ( asm-string-literal )
2781 c_parser_simple_asm_expr (c_parser
*parser
)
2784 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
2785 /* ??? Follow the C++ parser rather than using the
2786 lex_untranslated_string kludge. */
2787 parser
->lex_untranslated_string
= true;
2788 c_parser_consume_token (parser
);
2789 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2791 parser
->lex_untranslated_string
= false;
2794 str
= c_parser_asm_string_literal (parser
);
2795 parser
->lex_untranslated_string
= false;
2796 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
2798 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2804 /* Parse (possibly empty) attributes. This is a GNU extension.
2808 attributes attribute
2811 __attribute__ ( ( attribute-list ) )
2815 attribute_list , attrib
2820 any-word ( identifier )
2821 any-word ( identifier , nonempty-expr-list )
2822 any-word ( expr-list )
2824 where the "identifier" must not be declared as a type, and
2825 "any-word" may be any identifier (including one declared as a
2826 type), a reserved word storage class specifier, type specifier or
2827 type qualifier. ??? This still leaves out most reserved keywords
2828 (following the old parser), shouldn't we include them, and why not
2829 allow identifiers declared as types to start the arguments? */
2832 c_parser_attributes (c_parser
*parser
)
2834 tree attrs
= NULL_TREE
;
2835 while (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2837 /* ??? Follow the C++ parser rather than using the
2838 lex_untranslated_string kludge. */
2839 parser
->lex_untranslated_string
= true;
2840 c_parser_consume_token (parser
);
2841 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2843 parser
->lex_untranslated_string
= false;
2846 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2848 parser
->lex_untranslated_string
= false;
2849 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2852 /* Parse the attribute list. */
2853 while (c_parser_next_token_is (parser
, CPP_COMMA
)
2854 || c_parser_next_token_is (parser
, CPP_NAME
)
2855 || c_parser_next_token_is (parser
, CPP_KEYWORD
))
2857 tree attr
, attr_name
, attr_args
;
2858 VEC(tree
,gc
) *expr_list
;
2859 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2861 c_parser_consume_token (parser
);
2864 if (c_parser_next_token_is (parser
, CPP_KEYWORD
))
2866 /* ??? See comment above about what keywords are
2869 switch (c_parser_peek_token (parser
)->keyword
)
2906 /* Accept __attribute__((__const)) as __attribute__((const))
2909 = ridpointers
[(int) c_parser_peek_token (parser
)->keyword
];
2912 attr_name
= c_parser_peek_token (parser
)->value
;
2913 c_parser_consume_token (parser
);
2914 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
2916 attr
= build_tree_list (attr_name
, NULL_TREE
);
2917 attrs
= chainon (attrs
, attr
);
2920 c_parser_consume_token (parser
);
2921 /* Parse the attribute contents. If they start with an
2922 identifier which is followed by a comma or close
2923 parenthesis, then the arguments start with that
2924 identifier; otherwise they are an expression list. */
2925 if (c_parser_next_token_is (parser
, CPP_NAME
)
2926 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
2927 && ((c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
)
2928 || (c_parser_peek_2nd_token (parser
)->type
2929 == CPP_CLOSE_PAREN
)))
2931 tree arg1
= c_parser_peek_token (parser
)->value
;
2932 c_parser_consume_token (parser
);
2933 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2934 attr_args
= build_tree_list (NULL_TREE
, arg1
);
2938 c_parser_consume_token (parser
);
2939 expr_list
= c_parser_expr_list (parser
, false, true, NULL
);
2940 tree_list
= build_tree_list_vec (expr_list
);
2941 attr_args
= tree_cons (NULL_TREE
, arg1
, tree_list
);
2942 release_tree_vector (expr_list
);
2947 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2948 attr_args
= NULL_TREE
;
2951 expr_list
= c_parser_expr_list (parser
, false, true, NULL
);
2952 attr_args
= build_tree_list_vec (expr_list
);
2953 release_tree_vector (expr_list
);
2956 attr
= build_tree_list (attr_name
, attr_args
);
2957 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2958 c_parser_consume_token (parser
);
2961 parser
->lex_untranslated_string
= false;
2962 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2966 attrs
= chainon (attrs
, attr
);
2968 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2969 c_parser_consume_token (parser
);
2972 parser
->lex_untranslated_string
= false;
2973 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2977 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2978 c_parser_consume_token (parser
);
2981 parser
->lex_untranslated_string
= false;
2982 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2986 parser
->lex_untranslated_string
= false;
2991 /* Parse a type name (C90 6.5.5, C99 6.7.6).
2994 specifier-qualifier-list abstract-declarator[opt]
2997 static struct c_type_name
*
2998 c_parser_type_name (c_parser
*parser
)
3000 struct c_declspecs
*specs
= build_null_declspecs ();
3001 struct c_declarator
*declarator
;
3002 struct c_type_name
*ret
;
3004 c_parser_declspecs (parser
, specs
, false, true, true);
3005 if (!specs
->declspecs_seen_p
)
3007 c_parser_error (parser
, "expected specifier-qualifier-list");
3010 pending_xref_error ();
3011 finish_declspecs (specs
);
3012 declarator
= c_parser_declarator (parser
, specs
->type_seen_p
,
3013 C_DTR_ABSTRACT
, &dummy
);
3014 if (declarator
== NULL
)
3016 ret
= XOBNEW (&parser_obstack
, struct c_type_name
);
3018 ret
->declarator
= declarator
;
3022 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
3025 assignment-expression
3026 { initializer-list }
3027 { initializer-list , }
3030 designation[opt] initializer
3031 initializer-list , designation[opt] initializer
3038 designator-list designator
3045 [ constant-expression ]
3057 [ constant-expression ... constant-expression ]
3059 Any expression without commas is accepted in the syntax for the
3060 constant-expressions, with non-constant expressions rejected later.
3062 This function is only used for top-level initializers; for nested
3063 ones, see c_parser_initval. */
3065 static struct c_expr
3066 c_parser_initializer (c_parser
*parser
)
3068 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
3069 return c_parser_braced_init (parser
, NULL_TREE
, false);
3073 location_t loc
= c_parser_peek_token (parser
)->location
;
3074 ret
= c_parser_expr_no_commas (parser
, NULL
);
3075 if (TREE_CODE (ret
.value
) != STRING_CST
3076 && TREE_CODE (ret
.value
) != COMPOUND_LITERAL_EXPR
)
3077 ret
= default_function_array_read_conversion (loc
, ret
);
3082 /* Parse a braced initializer list. TYPE is the type specified for a
3083 compound literal, and NULL_TREE for other initializers and for
3084 nested braced lists. NESTED_P is true for nested braced lists,
3085 false for the list of a compound literal or the list that is the
3086 top-level initializer in a declaration. */
3088 static struct c_expr
3089 c_parser_braced_init (c_parser
*parser
, tree type
, bool nested_p
)
3091 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
3092 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
3093 c_parser_consume_token (parser
);
3095 push_init_level (0);
3097 really_start_incremental_init (type
);
3098 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3100 pedwarn (brace_loc
, OPT_pedantic
, "ISO C forbids empty initializer braces");
3104 /* Parse a non-empty initializer list, possibly with a trailing
3108 c_parser_initelt (parser
);
3111 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3112 c_parser_consume_token (parser
);
3115 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3119 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
3122 ret
.value
= error_mark_node
;
3123 ret
.original_code
= ERROR_MARK
;
3124 ret
.original_type
= NULL
;
3125 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
3129 c_parser_consume_token (parser
);
3130 return pop_init_level (0);
3133 /* Parse a nested initializer, including designators. */
3136 c_parser_initelt (c_parser
*parser
)
3138 /* Parse any designator or designator list. A single array
3139 designator may have the subsequent "=" omitted in GNU C, but a
3140 longer list or a structure member designator may not. */
3141 if (c_parser_next_token_is (parser
, CPP_NAME
)
3142 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
3144 /* Old-style structure member designator. */
3145 set_init_label (c_parser_peek_token (parser
)->value
);
3146 /* Use the colon as the error location. */
3147 pedwarn (c_parser_peek_2nd_token (parser
)->location
, OPT_pedantic
,
3148 "obsolete use of designated initializer with %<:%>");
3149 c_parser_consume_token (parser
);
3150 c_parser_consume_token (parser
);
3154 /* des_seen is 0 if there have been no designators, 1 if there
3155 has been a single array designator and 2 otherwise. */
3157 /* Location of a designator. */
3158 location_t des_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
3159 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
)
3160 || c_parser_next_token_is (parser
, CPP_DOT
))
3162 int des_prev
= des_seen
;
3164 des_loc
= c_parser_peek_token (parser
)->location
;
3167 if (c_parser_next_token_is (parser
, CPP_DOT
))
3170 c_parser_consume_token (parser
);
3171 if (c_parser_next_token_is (parser
, CPP_NAME
))
3173 set_init_label (c_parser_peek_token (parser
)->value
);
3174 c_parser_consume_token (parser
);
3179 init
.value
= error_mark_node
;
3180 init
.original_code
= ERROR_MARK
;
3181 init
.original_type
= NULL
;
3182 c_parser_error (parser
, "expected identifier");
3183 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3184 process_init_element (init
, false);
3191 location_t ellipsis_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
3192 /* ??? Following the old parser, [ objc-receiver
3193 objc-message-args ] is accepted as an initializer,
3194 being distinguished from a designator by what follows
3195 the first assignment expression inside the square
3196 brackets, but after a first array designator a
3197 subsequent square bracket is for Objective-C taken to
3198 start an expression, using the obsolete form of
3199 designated initializer without '=', rather than
3200 possibly being a second level of designation: in LALR
3201 terms, the '[' is shifted rather than reducing
3202 designator to designator-list. */
3203 if (des_prev
== 1 && c_dialect_objc ())
3205 des_seen
= des_prev
;
3208 if (des_prev
== 0 && c_dialect_objc ())
3210 /* This might be an array designator or an
3211 Objective-C message expression. If the former,
3212 continue parsing here; if the latter, parse the
3213 remainder of the initializer given the starting
3214 primary-expression. ??? It might make sense to
3215 distinguish when des_prev == 1 as well; see
3216 previous comment. */
3218 struct c_expr mexpr
;
3219 c_parser_consume_token (parser
);
3220 if (c_parser_peek_token (parser
)->type
== CPP_NAME
3221 && ((c_parser_peek_token (parser
)->id_kind
3223 || (c_parser_peek_token (parser
)->id_kind
3224 == C_ID_CLASSNAME
)))
3226 /* Type name receiver. */
3227 tree id
= c_parser_peek_token (parser
)->value
;
3228 c_parser_consume_token (parser
);
3229 rec
= objc_get_class_reference (id
);
3230 goto parse_message_args
;
3232 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
3233 mark_exp_read (first
);
3234 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
)
3235 || c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3236 goto array_desig_after_first
;
3237 /* Expression receiver. So far only one part
3238 without commas has been parsed; there might be
3239 more of the expression. */
3241 while (c_parser_next_token_is (parser
, CPP_COMMA
))
3244 location_t comma_loc
, exp_loc
;
3245 comma_loc
= c_parser_peek_token (parser
)->location
;
3246 c_parser_consume_token (parser
);
3247 exp_loc
= c_parser_peek_token (parser
)->location
;
3248 next
= c_parser_expr_no_commas (parser
, NULL
);
3249 next
= default_function_array_read_conversion (exp_loc
,
3251 rec
= build_compound_expr (comma_loc
, rec
, next
.value
);
3254 /* Now parse the objc-message-args. */
3255 args
= c_parser_objc_message_args (parser
);
3256 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3259 = objc_build_message_expr (build_tree_list (rec
, args
));
3260 mexpr
.original_code
= ERROR_MARK
;
3261 mexpr
.original_type
= NULL
;
3262 /* Now parse and process the remainder of the
3263 initializer, starting with this message
3264 expression as a primary-expression. */
3265 c_parser_initval (parser
, &mexpr
);
3268 c_parser_consume_token (parser
);
3269 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
3270 mark_exp_read (first
);
3271 array_desig_after_first
:
3272 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3274 ellipsis_loc
= c_parser_peek_token (parser
)->location
;
3275 c_parser_consume_token (parser
);
3276 second
= c_parser_expr_no_commas (parser
, NULL
).value
;
3277 mark_exp_read (second
);
3281 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3283 c_parser_consume_token (parser
);
3284 set_init_index (first
, second
);
3286 pedwarn (ellipsis_loc
, OPT_pedantic
,
3287 "ISO C forbids specifying range of elements to initialize");
3290 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3296 if (c_parser_next_token_is (parser
, CPP_EQ
))
3299 pedwarn (des_loc
, OPT_pedantic
,
3300 "ISO C90 forbids specifying subobject to initialize");
3301 c_parser_consume_token (parser
);
3306 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
3307 "obsolete use of designated initializer without %<=%>");
3311 init
.value
= error_mark_node
;
3312 init
.original_code
= ERROR_MARK
;
3313 init
.original_type
= NULL
;
3314 c_parser_error (parser
, "expected %<=%>");
3315 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3316 process_init_element (init
, false);
3322 c_parser_initval (parser
, NULL
);
3325 /* Parse a nested initializer; as c_parser_initializer but parses
3326 initializers within braced lists, after any designators have been
3327 applied. If AFTER is not NULL then it is an Objective-C message
3328 expression which is the primary-expression starting the
3332 c_parser_initval (c_parser
*parser
, struct c_expr
*after
)
3335 gcc_assert (!after
|| c_dialect_objc ());
3336 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
) && !after
)
3337 init
= c_parser_braced_init (parser
, NULL_TREE
, true);
3340 location_t loc
= c_parser_peek_token (parser
)->location
;
3341 init
= c_parser_expr_no_commas (parser
, after
);
3342 if (init
.value
!= NULL_TREE
3343 && TREE_CODE (init
.value
) != STRING_CST
3344 && TREE_CODE (init
.value
) != COMPOUND_LITERAL_EXPR
)
3345 init
= default_function_array_read_conversion (loc
, init
);
3347 process_init_element (init
, false);
3350 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
3354 { block-item-list[opt] }
3355 { label-declarations block-item-list }
3359 block-item-list block-item
3371 { label-declarations block-item-list }
3374 __extension__ nested-declaration
3375 nested-function-definition
3379 label-declarations label-declaration
3382 __label__ identifier-list ;
3384 Allowing the mixing of declarations and code is new in C99. The
3385 GNU syntax also permits (not shown above) labels at the end of
3386 compound statements, which yield an error. We don't allow labels
3387 on declarations; this might seem like a natural extension, but
3388 there would be a conflict between attributes on the label and
3389 prefix attributes on the declaration. ??? The syntax follows the
3390 old parser in requiring something after label declarations.
3391 Although they are erroneous if the labels declared aren't defined,
3392 is it useful for the syntax to be this way?
3404 c_parser_compound_statement (c_parser
*parser
)
3407 location_t brace_loc
;
3408 brace_loc
= c_parser_peek_token (parser
)->location
;
3409 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
3411 /* Ensure a scope is entered and left anyway to avoid confusion
3412 if we have just prepared to enter a function body. */
3413 stmt
= c_begin_compound_stmt (true);
3414 c_end_compound_stmt (brace_loc
, stmt
, true);
3415 return error_mark_node
;
3417 stmt
= c_begin_compound_stmt (true);
3418 c_parser_compound_statement_nostart (parser
);
3419 return c_end_compound_stmt (brace_loc
, stmt
, true);
3422 /* Parse a compound statement except for the opening brace. This is
3423 used for parsing both compound statements and statement expressions
3424 (which follow different paths to handling the opening). */
3427 c_parser_compound_statement_nostart (c_parser
*parser
)
3429 bool last_stmt
= false;
3430 bool last_label
= false;
3431 bool save_valid_for_pragma
= valid_location_for_stdc_pragma_p ();
3432 location_t label_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
3433 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3435 c_parser_consume_token (parser
);
3438 mark_valid_location_for_stdc_pragma (true);
3439 if (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
3441 /* Read zero or more forward-declarations for labels that nested
3442 functions can jump to. */
3443 mark_valid_location_for_stdc_pragma (false);
3444 while (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
3446 label_loc
= c_parser_peek_token (parser
)->location
;
3447 c_parser_consume_token (parser
);
3448 /* Any identifiers, including those declared as type names,
3453 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
3455 c_parser_error (parser
, "expected identifier");
3459 = declare_label (c_parser_peek_token (parser
)->value
);
3460 C_DECLARED_LABEL_FLAG (label
) = 1;
3461 add_stmt (build_stmt (label_loc
, DECL_EXPR
, label
));
3462 c_parser_consume_token (parser
);
3463 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3464 c_parser_consume_token (parser
);
3468 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
3470 pedwarn (label_loc
, OPT_pedantic
, "ISO C forbids label declarations");
3472 /* We must now have at least one statement, label or declaration. */
3473 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3475 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
3476 c_parser_error (parser
, "expected declaration or statement");
3477 c_parser_consume_token (parser
);
3480 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
3482 location_t loc
= c_parser_peek_token (parser
)->location
;
3483 if (c_parser_next_token_is_keyword (parser
, RID_CASE
)
3484 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
3485 || (c_parser_next_token_is (parser
, CPP_NAME
)
3486 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
3488 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
3489 label_loc
= c_parser_peek_2nd_token (parser
)->location
;
3491 label_loc
= c_parser_peek_token (parser
)->location
;
3494 mark_valid_location_for_stdc_pragma (false);
3495 c_parser_label (parser
);
3497 else if (!last_label
3498 && c_parser_next_token_starts_declspecs (parser
))
3501 mark_valid_location_for_stdc_pragma (false);
3502 c_parser_declaration_or_fndef (parser
, true, true, true, true);
3505 (pedantic
&& !flag_isoc99
)
3507 : OPT_Wdeclaration_after_statement
,
3508 "ISO C90 forbids mixed declarations and code");
3511 else if (!last_label
3512 && c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
3514 /* __extension__ can start a declaration, but is also an
3515 unary operator that can start an expression. Consume all
3516 but the last of a possible series of __extension__ to
3518 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
3519 && (c_parser_peek_2nd_token (parser
)->keyword
3521 c_parser_consume_token (parser
);
3522 if (c_token_starts_declspecs (c_parser_peek_2nd_token (parser
)))
3525 ext
= disable_extension_diagnostics ();
3526 c_parser_consume_token (parser
);
3528 mark_valid_location_for_stdc_pragma (false);
3529 c_parser_declaration_or_fndef (parser
, true, true, true, true);
3530 /* Following the old parser, __extension__ does not
3531 disable this diagnostic. */
3532 restore_extension_diagnostics (ext
);
3534 pedwarn_c90 (loc
, (pedantic
&& !flag_isoc99
)
3536 : OPT_Wdeclaration_after_statement
,
3537 "ISO C90 forbids mixed declarations and code");
3543 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
3545 /* External pragmas, and some omp pragmas, are not associated
3546 with regular c code, and so are not to be considered statements
3547 syntactically. This ensures that the user doesn't put them
3548 places that would turn into syntax errors if the directive
3550 if (c_parser_pragma (parser
, pragma_compound
))
3551 last_label
= false, last_stmt
= true;
3553 else if (c_parser_next_token_is (parser
, CPP_EOF
))
3555 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
3556 c_parser_error (parser
, "expected declaration or statement");
3559 else if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
3561 if (parser
->in_if_block
)
3563 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
3564 error_at (loc
, """expected %<}%> before %<else%>");
3569 error_at (loc
, "%<else%> without a previous %<if%>");
3570 c_parser_consume_token (parser
);
3579 mark_valid_location_for_stdc_pragma (false);
3580 c_parser_statement_after_labels (parser
);
3583 parser
->error
= false;
3586 error_at (label_loc
, "label at end of compound statement");
3587 c_parser_consume_token (parser
);
3588 /* Restore the value we started with. */
3589 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
3592 /* Parse a label (C90 6.6.1, C99 6.8.1).
3595 identifier : attributes[opt]
3596 case constant-expression :
3602 case constant-expression ... constant-expression :
3604 The use of attributes on labels is a GNU extension. The syntax in
3605 GNU C accepts any expressions without commas, non-constant
3606 expressions being rejected later. */
3609 c_parser_label (c_parser
*parser
)
3611 location_t loc1
= c_parser_peek_token (parser
)->location
;
3612 tree label
= NULL_TREE
;
3613 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
3616 c_parser_consume_token (parser
);
3617 exp1
= c_parser_expr_no_commas (parser
, NULL
).value
;
3618 if (c_parser_next_token_is (parser
, CPP_COLON
))
3620 c_parser_consume_token (parser
);
3621 label
= do_case (loc1
, exp1
, NULL_TREE
);
3623 else if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3625 c_parser_consume_token (parser
);
3626 exp2
= c_parser_expr_no_commas (parser
, NULL
).value
;
3627 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
3628 label
= do_case (loc1
, exp1
, exp2
);
3631 c_parser_error (parser
, "expected %<:%> or %<...%>");
3633 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
3635 c_parser_consume_token (parser
);
3636 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
3637 label
= do_case (loc1
, NULL_TREE
, NULL_TREE
);
3641 tree name
= c_parser_peek_token (parser
)->value
;
3644 location_t loc2
= c_parser_peek_token (parser
)->location
;
3645 gcc_assert (c_parser_next_token_is (parser
, CPP_NAME
));
3646 c_parser_consume_token (parser
);
3647 gcc_assert (c_parser_next_token_is (parser
, CPP_COLON
));
3648 c_parser_consume_token (parser
);
3649 attrs
= c_parser_attributes (parser
);
3650 tlab
= define_label (loc2
, name
);
3653 decl_attributes (&tlab
, attrs
, 0);
3654 label
= add_stmt (build_stmt (loc1
, LABEL_EXPR
, tlab
));
3659 if (c_parser_next_token_starts_declspecs (parser
)
3660 && !(c_parser_next_token_is (parser
, CPP_NAME
)
3661 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
3663 error_at (c_parser_peek_token (parser
)->location
,
3664 "a label can only be part of a statement and "
3665 "a declaration is not a statement");
3666 c_parser_declaration_or_fndef (parser
, /*fndef_ok*/ false,
3667 /*nested*/ true, /*empty_ok*/ false,
3668 /*start_attr_ok*/ true);
3673 /* Parse a statement (C90 6.6, C99 6.8).
3678 expression-statement
3686 expression-statement:
3689 selection-statement:
3693 iteration-statement:
3702 return expression[opt] ;
3715 objc-throw-statement
3716 objc-try-catch-statement
3717 objc-synchronized-statement
3719 objc-throw-statement:
3733 parallel-for-construct
3734 parallel-sections-construct
3741 parallel-directive structured-block
3744 for-directive iteration-statement
3747 sections-directive section-scope
3750 single-directive structured-block
3752 parallel-for-construct:
3753 parallel-for-directive iteration-statement
3755 parallel-sections-construct:
3756 parallel-sections-directive section-scope
3759 master-directive structured-block
3762 critical-directive structured-block
3765 atomic-directive expression-statement
3768 ordered-directive structured-block */
3771 c_parser_statement (c_parser
*parser
)
3773 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
3774 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
3775 || (c_parser_next_token_is (parser
, CPP_NAME
)
3776 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
3777 c_parser_label (parser
);
3778 c_parser_statement_after_labels (parser
);
3781 /* Parse a statement, other than a labeled statement. */
3784 c_parser_statement_after_labels (c_parser
*parser
)
3786 location_t loc
= c_parser_peek_token (parser
)->location
;
3787 tree stmt
= NULL_TREE
;
3788 bool in_if_block
= parser
->in_if_block
;
3789 parser
->in_if_block
= false;
3790 switch (c_parser_peek_token (parser
)->type
)
3792 case CPP_OPEN_BRACE
:
3793 add_stmt (c_parser_compound_statement (parser
));
3796 switch (c_parser_peek_token (parser
)->keyword
)
3799 c_parser_if_statement (parser
);
3802 c_parser_switch_statement (parser
);
3805 c_parser_while_statement (parser
);
3808 c_parser_do_statement (parser
);
3811 c_parser_for_statement (parser
);
3814 c_parser_consume_token (parser
);
3815 if (c_parser_next_token_is (parser
, CPP_NAME
))
3817 stmt
= c_finish_goto_label (loc
,
3818 c_parser_peek_token (parser
)->value
);
3819 c_parser_consume_token (parser
);
3821 else if (c_parser_next_token_is (parser
, CPP_MULT
))
3823 c_parser_consume_token (parser
);
3824 stmt
= c_finish_goto_ptr (loc
,
3825 c_parser_expression (parser
).value
);
3828 c_parser_error (parser
, "expected identifier or %<*%>");
3829 goto expect_semicolon
;
3831 c_parser_consume_token (parser
);
3832 stmt
= c_finish_bc_stmt (loc
, &c_cont_label
, false);
3833 goto expect_semicolon
;
3835 c_parser_consume_token (parser
);
3836 stmt
= c_finish_bc_stmt (loc
, &c_break_label
, true);
3837 goto expect_semicolon
;
3839 c_parser_consume_token (parser
);
3840 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3842 stmt
= c_finish_return (loc
, NULL_TREE
, NULL_TREE
);
3843 c_parser_consume_token (parser
);
3847 struct c_expr expr
= c_parser_expression_conv (parser
);
3848 mark_exp_read (expr
.value
);
3849 stmt
= c_finish_return (loc
, expr
.value
, expr
.original_type
);
3850 goto expect_semicolon
;
3854 stmt
= c_parser_asm_statement (parser
);
3857 gcc_assert (c_dialect_objc ());
3858 c_parser_consume_token (parser
);
3859 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3861 stmt
= objc_build_throw_stmt (loc
, NULL_TREE
);
3862 c_parser_consume_token (parser
);
3866 tree expr
= c_parser_expression (parser
).value
;
3867 expr
= c_fully_fold (expr
, false, NULL
);
3868 stmt
= objc_build_throw_stmt (loc
, expr
);
3869 goto expect_semicolon
;
3873 gcc_assert (c_dialect_objc ());
3874 c_parser_objc_try_catch_statement (parser
);
3876 case RID_AT_SYNCHRONIZED
:
3877 gcc_assert (c_dialect_objc ());
3878 c_parser_objc_synchronized_statement (parser
);
3885 c_parser_consume_token (parser
);
3887 case CPP_CLOSE_PAREN
:
3888 case CPP_CLOSE_SQUARE
:
3889 /* Avoid infinite loop in error recovery:
3890 c_parser_skip_until_found stops at a closing nesting
3891 delimiter without consuming it, but here we need to consume
3892 it to proceed further. */
3893 c_parser_error (parser
, "expected statement");
3894 c_parser_consume_token (parser
);
3897 c_parser_pragma (parser
, pragma_stmt
);
3901 stmt
= c_finish_expr_stmt (loc
, c_parser_expression_conv (parser
).value
);
3903 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
3906 /* Two cases cannot and do not have line numbers associated: If stmt
3907 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
3908 cannot hold line numbers. But that's OK because the statement
3909 will either be changed to a MODIFY_EXPR during gimplification of
3910 the statement expr, or discarded. If stmt was compound, but
3911 without new variables, we will have skipped the creation of a
3912 BIND and will have a bare STATEMENT_LIST. But that's OK because
3913 (recursively) all of the component statements should already have
3914 line numbers assigned. ??? Can we discard no-op statements
3916 if (CAN_HAVE_LOCATION_P (stmt
)
3917 && EXPR_LOCATION (stmt
) == UNKNOWN_LOCATION
)
3918 SET_EXPR_LOCATION (stmt
, loc
);
3920 parser
->in_if_block
= in_if_block
;
3923 /* Parse the condition from an if, do, while or for statements. */
3926 c_parser_condition (c_parser
*parser
)
3928 location_t loc
= c_parser_peek_token (parser
)->location
;
3930 cond
= c_parser_expression_conv (parser
).value
;
3931 cond
= c_objc_common_truthvalue_conversion (loc
, cond
);
3932 cond
= c_fully_fold (cond
, false, NULL
);
3933 if (warn_sequence_point
)
3934 verify_sequence_points (cond
);
3938 /* Parse a parenthesized condition from an if, do or while statement.
3944 c_parser_paren_condition (c_parser
*parser
)
3947 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3948 return error_mark_node
;
3949 cond
= c_parser_condition (parser
);
3950 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
3954 /* Parse a statement which is a block in C99. */
3957 c_parser_c99_block_statement (c_parser
*parser
)
3959 tree block
= c_begin_compound_stmt (flag_isoc99
);
3960 location_t loc
= c_parser_peek_token (parser
)->location
;
3961 c_parser_statement (parser
);
3962 return c_end_compound_stmt (loc
, block
, flag_isoc99
);
3965 /* Parse the body of an if statement. This is just parsing a
3966 statement but (a) it is a block in C99, (b) we track whether the
3967 body is an if statement for the sake of -Wparentheses warnings, (c)
3968 we handle an empty body specially for the sake of -Wempty-body
3969 warnings, and (d) we call parser_compound_statement directly
3970 because c_parser_statement_after_labels resets
3971 parser->in_if_block. */
3974 c_parser_if_body (c_parser
*parser
, bool *if_p
)
3976 tree block
= c_begin_compound_stmt (flag_isoc99
);
3977 location_t body_loc
= c_parser_peek_token (parser
)->location
;
3978 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
3979 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
3980 || (c_parser_next_token_is (parser
, CPP_NAME
)
3981 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
3982 c_parser_label (parser
);
3983 *if_p
= c_parser_next_token_is_keyword (parser
, RID_IF
);
3984 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3986 location_t loc
= c_parser_peek_token (parser
)->location
;
3987 add_stmt (build_empty_stmt (loc
));
3988 c_parser_consume_token (parser
);
3989 if (!c_parser_next_token_is_keyword (parser
, RID_ELSE
))
3990 warning_at (loc
, OPT_Wempty_body
,
3991 "suggest braces around empty body in an %<if%> statement");
3993 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
3994 add_stmt (c_parser_compound_statement (parser
));
3996 c_parser_statement_after_labels (parser
);
3997 return c_end_compound_stmt (body_loc
, block
, flag_isoc99
);
4000 /* Parse the else body of an if statement. This is just parsing a
4001 statement but (a) it is a block in C99, (b) we handle an empty body
4002 specially for the sake of -Wempty-body warnings. */
4005 c_parser_else_body (c_parser
*parser
)
4007 location_t else_loc
= c_parser_peek_token (parser
)->location
;
4008 tree block
= c_begin_compound_stmt (flag_isoc99
);
4009 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4010 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4011 || (c_parser_next_token_is (parser
, CPP_NAME
)
4012 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4013 c_parser_label (parser
);
4014 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4016 location_t loc
= c_parser_peek_token (parser
)->location
;
4019 "suggest braces around empty body in an %<else%> statement");
4020 add_stmt (build_empty_stmt (loc
));
4021 c_parser_consume_token (parser
);
4024 c_parser_statement_after_labels (parser
);
4025 return c_end_compound_stmt (else_loc
, block
, flag_isoc99
);
4028 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
4031 if ( expression ) statement
4032 if ( expression ) statement else statement
4036 c_parser_if_statement (c_parser
*parser
)
4041 bool first_if
= false;
4042 tree first_body
, second_body
;
4045 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_IF
));
4046 c_parser_consume_token (parser
);
4047 block
= c_begin_compound_stmt (flag_isoc99
);
4048 loc
= c_parser_peek_token (parser
)->location
;
4049 cond
= c_parser_paren_condition (parser
);
4050 in_if_block
= parser
->in_if_block
;
4051 parser
->in_if_block
= true;
4052 first_body
= c_parser_if_body (parser
, &first_if
);
4053 parser
->in_if_block
= in_if_block
;
4054 if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
4056 c_parser_consume_token (parser
);
4057 second_body
= c_parser_else_body (parser
);
4060 second_body
= NULL_TREE
;
4061 c_finish_if_stmt (loc
, cond
, first_body
, second_body
, first_if
);
4062 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
4065 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
4068 switch (expression) statement
4072 c_parser_switch_statement (c_parser
*parser
)
4074 tree block
, expr
, body
, save_break
;
4075 location_t switch_loc
= c_parser_peek_token (parser
)->location
;
4076 location_t switch_cond_loc
;
4077 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SWITCH
));
4078 c_parser_consume_token (parser
);
4079 block
= c_begin_compound_stmt (flag_isoc99
);
4080 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4082 switch_cond_loc
= c_parser_peek_token (parser
)->location
;
4083 expr
= c_parser_expression (parser
).value
;
4084 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4088 switch_cond_loc
= UNKNOWN_LOCATION
;
4089 expr
= error_mark_node
;
4091 c_start_case (switch_loc
, switch_cond_loc
, expr
);
4092 save_break
= c_break_label
;
4093 c_break_label
= NULL_TREE
;
4094 body
= c_parser_c99_block_statement (parser
);
4095 c_finish_case (body
);
4098 location_t here
= c_parser_peek_token (parser
)->location
;
4099 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_break_label
);
4100 SET_EXPR_LOCATION (t
, here
);
4103 c_break_label
= save_break
;
4104 add_stmt (c_end_compound_stmt (switch_loc
, block
, flag_isoc99
));
4107 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
4110 while (expression) statement
4114 c_parser_while_statement (c_parser
*parser
)
4116 tree block
, cond
, body
, save_break
, save_cont
;
4118 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_WHILE
));
4119 c_parser_consume_token (parser
);
4120 block
= c_begin_compound_stmt (flag_isoc99
);
4121 loc
= c_parser_peek_token (parser
)->location
;
4122 cond
= c_parser_paren_condition (parser
);
4123 save_break
= c_break_label
;
4124 c_break_label
= NULL_TREE
;
4125 save_cont
= c_cont_label
;
4126 c_cont_label
= NULL_TREE
;
4127 body
= c_parser_c99_block_statement (parser
);
4128 c_finish_loop (loc
, cond
, NULL
, body
, c_break_label
, c_cont_label
, true);
4129 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
4130 c_break_label
= save_break
;
4131 c_cont_label
= save_cont
;
4134 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
4137 do statement while ( expression ) ;
4141 c_parser_do_statement (c_parser
*parser
)
4143 tree block
, cond
, body
, save_break
, save_cont
, new_break
, new_cont
;
4145 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_DO
));
4146 c_parser_consume_token (parser
);
4147 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4148 warning_at (c_parser_peek_token (parser
)->location
,
4150 "suggest braces around empty body in %<do%> statement");
4151 block
= c_begin_compound_stmt (flag_isoc99
);
4152 loc
= c_parser_peek_token (parser
)->location
;
4153 save_break
= c_break_label
;
4154 c_break_label
= NULL_TREE
;
4155 save_cont
= c_cont_label
;
4156 c_cont_label
= NULL_TREE
;
4157 body
= c_parser_c99_block_statement (parser
);
4158 c_parser_require_keyword (parser
, RID_WHILE
, "expected %<while%>");
4159 new_break
= c_break_label
;
4160 c_break_label
= save_break
;
4161 new_cont
= c_cont_label
;
4162 c_cont_label
= save_cont
;
4163 cond
= c_parser_paren_condition (parser
);
4164 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
4165 c_parser_skip_to_end_of_block_or_statement (parser
);
4166 c_finish_loop (loc
, cond
, NULL
, body
, new_break
, new_cont
, false);
4167 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
4170 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
4173 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
4174 for ( nested-declaration expression[opt] ; expression[opt] ) statement
4176 The form with a declaration is new in C99.
4178 ??? In accordance with the old parser, the declaration may be a
4179 nested function, which is then rejected in check_for_loop_decls,
4180 but does it make any sense for this to be included in the grammar?
4181 Note in particular that the nested function does not include a
4182 trailing ';', whereas the "declaration" production includes one.
4183 Also, can we reject bad declarations earlier and cheaper than
4184 check_for_loop_decls? */
4187 c_parser_for_statement (c_parser
*parser
)
4189 tree block
, cond
, incr
, save_break
, save_cont
, body
;
4190 location_t loc
= c_parser_peek_token (parser
)->location
;
4191 location_t for_loc
= c_parser_peek_token (parser
)->location
;
4192 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_FOR
));
4193 c_parser_consume_token (parser
);
4194 block
= c_begin_compound_stmt (flag_isoc99
);
4195 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4197 /* Parse the initialization declaration or expression. */
4198 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4200 c_parser_consume_token (parser
);
4201 c_finish_expr_stmt (loc
, NULL_TREE
);
4203 else if (c_parser_next_token_starts_declspecs (parser
))
4205 c_parser_declaration_or_fndef (parser
, true, true, true, true);
4206 check_for_loop_decls (for_loc
);
4208 else if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
4210 /* __extension__ can start a declaration, but is also an
4211 unary operator that can start an expression. Consume all
4212 but the last of a possible series of __extension__ to
4214 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
4215 && (c_parser_peek_2nd_token (parser
)->keyword
4217 c_parser_consume_token (parser
);
4218 if (c_token_starts_declspecs (c_parser_peek_2nd_token (parser
)))
4221 ext
= disable_extension_diagnostics ();
4222 c_parser_consume_token (parser
);
4223 c_parser_declaration_or_fndef (parser
, true, true, true, true);
4224 restore_extension_diagnostics (ext
);
4225 check_for_loop_decls (for_loc
);
4233 c_finish_expr_stmt (loc
, c_parser_expression (parser
).value
);
4234 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4236 /* Parse the loop condition. */
4237 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4239 c_parser_consume_token (parser
);
4244 cond
= c_parser_condition (parser
);
4245 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4247 /* Parse the increment expression. */
4248 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4249 incr
= c_process_expr_stmt (loc
, NULL_TREE
);
4251 incr
= c_process_expr_stmt (loc
, c_parser_expression (parser
).value
);
4252 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4256 cond
= error_mark_node
;
4257 incr
= error_mark_node
;
4259 save_break
= c_break_label
;
4260 c_break_label
= NULL_TREE
;
4261 save_cont
= c_cont_label
;
4262 c_cont_label
= NULL_TREE
;
4263 body
= c_parser_c99_block_statement (parser
);
4264 c_finish_loop (loc
, cond
, incr
, body
, c_break_label
, c_cont_label
, true);
4265 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
4266 c_break_label
= save_break
;
4267 c_cont_label
= save_cont
;
4270 /* Parse an asm statement, a GNU extension. This is a full-blown asm
4271 statement with inputs, outputs, clobbers, and volatile tag
4275 asm type-qualifier[opt] ( asm-argument ) ;
4276 asm type-qualifier[opt] goto ( asm-goto-argument ) ;
4280 asm-string-literal : asm-operands[opt]
4281 asm-string-literal : asm-operands[opt] : asm-operands[opt]
4282 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers[opt]
4285 asm-string-literal : : asm-operands[opt] : asm-clobbers[opt] \
4288 Qualifiers other than volatile are accepted in the syntax but
4292 c_parser_asm_statement (c_parser
*parser
)
4294 tree quals
, str
, outputs
, inputs
, clobbers
, labels
, ret
;
4295 bool simple
, is_goto
;
4296 location_t asm_loc
= c_parser_peek_token (parser
)->location
;
4297 int section
, nsections
;
4299 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
4300 c_parser_consume_token (parser
);
4301 if (c_parser_next_token_is_keyword (parser
, RID_VOLATILE
))
4303 quals
= c_parser_peek_token (parser
)->value
;
4304 c_parser_consume_token (parser
);
4306 else if (c_parser_next_token_is_keyword (parser
, RID_CONST
)
4307 || c_parser_next_token_is_keyword (parser
, RID_RESTRICT
))
4309 warning_at (c_parser_peek_token (parser
)->location
,
4311 "%E qualifier ignored on asm",
4312 c_parser_peek_token (parser
)->value
);
4314 c_parser_consume_token (parser
);
4320 if (c_parser_next_token_is_keyword (parser
, RID_GOTO
))
4322 c_parser_consume_token (parser
);
4326 /* ??? Follow the C++ parser rather than using the
4327 lex_untranslated_string kludge. */
4328 parser
->lex_untranslated_string
= true;
4331 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4334 str
= c_parser_asm_string_literal (parser
);
4335 if (str
== NULL_TREE
)
4336 goto error_close_paren
;
4339 outputs
= NULL_TREE
;
4341 clobbers
= NULL_TREE
;
4344 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
4347 /* Parse each colon-delimited section of operands. */
4348 nsections
= 3 + is_goto
;
4349 for (section
= 0; section
< nsections
; ++section
)
4351 if (!c_parser_require (parser
, CPP_COLON
,
4354 : "expected %<:%> or %<)%>"))
4355 goto error_close_paren
;
4357 /* Once past any colon, we're no longer a simple asm. */
4360 if ((!c_parser_next_token_is (parser
, CPP_COLON
)
4361 && !c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4366 /* For asm goto, we don't allow output operands, but reserve
4367 the slot for a future extension that does allow them. */
4369 outputs
= c_parser_asm_operands (parser
, false);
4372 inputs
= c_parser_asm_operands (parser
, true);
4375 clobbers
= c_parser_asm_clobbers (parser
);
4378 labels
= c_parser_asm_goto_operands (parser
);
4384 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
4389 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
4391 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4395 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
4396 c_parser_skip_to_end_of_block_or_statement (parser
);
4398 ret
= build_asm_stmt (quals
, build_asm_expr (asm_loc
, str
, outputs
, inputs
,
4399 clobbers
, labels
, simple
));
4402 parser
->lex_untranslated_string
= false;
4406 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4410 /* Parse asm operands, a GNU extension. If CONVERT_P (for inputs but
4411 not outputs), apply the default conversion of functions and arrays
4416 asm-operands , asm-operand
4419 asm-string-literal ( expression )
4420 [ identifier ] asm-string-literal ( expression )
4424 c_parser_asm_operands (c_parser
*parser
, bool convert_p
)
4426 tree list
= NULL_TREE
;
4432 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
4434 c_parser_consume_token (parser
);
4435 if (c_parser_next_token_is (parser
, CPP_NAME
))
4437 tree id
= c_parser_peek_token (parser
)->value
;
4438 c_parser_consume_token (parser
);
4439 name
= build_string (IDENTIFIER_LENGTH (id
),
4440 IDENTIFIER_POINTER (id
));
4444 c_parser_error (parser
, "expected identifier");
4445 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
4448 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4453 str
= c_parser_asm_string_literal (parser
);
4454 if (str
== NULL_TREE
)
4456 parser
->lex_untranslated_string
= false;
4457 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4459 parser
->lex_untranslated_string
= true;
4462 loc
= c_parser_peek_token (parser
)->location
;
4463 expr
= c_parser_expression (parser
);
4464 mark_exp_read (expr
.value
);
4466 expr
= default_function_array_conversion (loc
, expr
);
4467 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
4468 parser
->lex_untranslated_string
= true;
4469 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
4471 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4474 list
= chainon (list
, build_tree_list (build_tree_list (name
, str
),
4476 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4477 c_parser_consume_token (parser
);
4484 /* Parse asm clobbers, a GNU extension.
4488 asm-clobbers , asm-string-literal
4492 c_parser_asm_clobbers (c_parser
*parser
)
4494 tree list
= NULL_TREE
;
4497 tree str
= c_parser_asm_string_literal (parser
);
4499 list
= tree_cons (NULL_TREE
, str
, list
);
4502 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4503 c_parser_consume_token (parser
);
4510 /* Parse asm goto labels, a GNU extension.
4514 asm-goto-operands , identifier
4518 c_parser_asm_goto_operands (c_parser
*parser
)
4520 tree list
= NULL_TREE
;
4525 if (c_parser_next_token_is (parser
, CPP_NAME
))
4527 c_token
*tok
= c_parser_peek_token (parser
);
4529 label
= lookup_label_for_goto (tok
->location
, name
);
4530 c_parser_consume_token (parser
);
4531 TREE_USED (label
) = 1;
4535 c_parser_error (parser
, "expected identifier");
4539 name
= build_string (IDENTIFIER_LENGTH (name
),
4540 IDENTIFIER_POINTER (name
));
4541 list
= tree_cons (name
, label
, list
);
4542 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4543 c_parser_consume_token (parser
);
4545 return nreverse (list
);
4549 /* Parse an expression other than a compound expression; that is, an
4550 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
4551 NULL then it is an Objective-C message expression which is the
4552 primary-expression starting the expression as an initializer.
4554 assignment-expression:
4555 conditional-expression
4556 unary-expression assignment-operator assignment-expression
4558 assignment-operator: one of
4559 = *= /= %= += -= <<= >>= &= ^= |=
4561 In GNU C we accept any conditional expression on the LHS and
4562 diagnose the invalid lvalue rather than producing a syntax
4565 static struct c_expr
4566 c_parser_expr_no_commas (c_parser
*parser
, struct c_expr
*after
)
4568 struct c_expr lhs
, rhs
, ret
;
4569 enum tree_code code
;
4570 location_t op_location
, exp_location
;
4571 gcc_assert (!after
|| c_dialect_objc ());
4572 lhs
= c_parser_conditional_expression (parser
, after
);
4573 op_location
= c_parser_peek_token (parser
)->location
;
4574 switch (c_parser_peek_token (parser
)->type
)
4583 code
= TRUNC_DIV_EXPR
;
4586 code
= TRUNC_MOD_EXPR
;
4601 code
= BIT_AND_EXPR
;
4604 code
= BIT_XOR_EXPR
;
4607 code
= BIT_IOR_EXPR
;
4612 c_parser_consume_token (parser
);
4613 exp_location
= c_parser_peek_token (parser
)->location
;
4614 rhs
= c_parser_expr_no_commas (parser
, NULL
);
4615 rhs
= default_function_array_read_conversion (exp_location
, rhs
);
4616 ret
.value
= build_modify_expr (op_location
, lhs
.value
, lhs
.original_type
,
4617 code
, exp_location
, rhs
.value
,
4619 if (code
== NOP_EXPR
)
4620 ret
.original_code
= MODIFY_EXPR
;
4623 TREE_NO_WARNING (ret
.value
) = 1;
4624 ret
.original_code
= ERROR_MARK
;
4626 ret
.original_type
= NULL
;
4630 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
4631 is not NULL then it is an Objective-C message expression which is
4632 the primary-expression starting the expression as an initializer.
4634 conditional-expression:
4635 logical-OR-expression
4636 logical-OR-expression ? expression : conditional-expression
4640 conditional-expression:
4641 logical-OR-expression ? : conditional-expression
4644 static struct c_expr
4645 c_parser_conditional_expression (c_parser
*parser
, struct c_expr
*after
)
4647 struct c_expr cond
, exp1
, exp2
, ret
;
4648 location_t cond_loc
, colon_loc
;
4650 gcc_assert (!after
|| c_dialect_objc ());
4652 cond
= c_parser_binary_expression (parser
, after
);
4654 if (c_parser_next_token_is_not (parser
, CPP_QUERY
))
4656 cond_loc
= c_parser_peek_token (parser
)->location
;
4657 cond
= default_function_array_read_conversion (cond_loc
, cond
);
4658 c_parser_consume_token (parser
);
4659 if (c_parser_next_token_is (parser
, CPP_COLON
))
4661 tree eptype
= NULL_TREE
;
4662 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
4663 "ISO C forbids omitting the middle term of a ?: expression");
4664 if (TREE_CODE (cond
.value
) == EXCESS_PRECISION_EXPR
)
4666 eptype
= TREE_TYPE (cond
.value
);
4667 cond
.value
= TREE_OPERAND (cond
.value
, 0);
4669 /* Make sure first operand is calculated only once. */
4670 exp1
.value
= c_save_expr (default_conversion (cond
.value
));
4672 exp1
.value
= build1 (EXCESS_PRECISION_EXPR
, eptype
, exp1
.value
);
4673 exp1
.original_type
= NULL
;
4674 cond
.value
= c_objc_common_truthvalue_conversion (cond_loc
, exp1
.value
);
4675 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_true_node
;
4680 = c_objc_common_truthvalue_conversion
4681 (cond_loc
, default_conversion (cond
.value
));
4682 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_false_node
;
4683 exp1
= c_parser_expression_conv (parser
);
4684 mark_exp_read (exp1
.value
);
4685 c_inhibit_evaluation_warnings
+=
4686 ((cond
.value
== truthvalue_true_node
)
4687 - (cond
.value
== truthvalue_false_node
));
4690 colon_loc
= c_parser_peek_token (parser
)->location
;
4691 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4693 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
4694 ret
.value
= error_mark_node
;
4695 ret
.original_code
= ERROR_MARK
;
4696 ret
.original_type
= NULL
;
4700 location_t exp2_loc
= c_parser_peek_token (parser
)->location
;
4701 exp2
= c_parser_conditional_expression (parser
, NULL
);
4702 exp2
= default_function_array_read_conversion (exp2_loc
, exp2
);
4704 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
4705 ret
.value
= build_conditional_expr (colon_loc
, cond
.value
,
4706 cond
.original_code
== C_MAYBE_CONST_EXPR
,
4707 exp1
.value
, exp1
.original_type
,
4708 exp2
.value
, exp2
.original_type
);
4709 ret
.original_code
= ERROR_MARK
;
4710 if (exp1
.value
== error_mark_node
|| exp2
.value
== error_mark_node
)
4711 ret
.original_type
= NULL
;
4716 /* If both sides are enum type, the default conversion will have
4717 made the type of the result be an integer type. We want to
4718 remember the enum types we started with. */
4719 t1
= exp1
.original_type
? exp1
.original_type
: TREE_TYPE (exp1
.value
);
4720 t2
= exp2
.original_type
? exp2
.original_type
: TREE_TYPE (exp2
.value
);
4721 ret
.original_type
= ((t1
!= error_mark_node
4722 && t2
!= error_mark_node
4723 && (TYPE_MAIN_VARIANT (t1
)
4724 == TYPE_MAIN_VARIANT (t2
)))
4731 /* Parse a binary expression; that is, a logical-OR-expression (C90
4732 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
4733 an Objective-C message expression which is the primary-expression
4734 starting the expression as an initializer.
4736 multiplicative-expression:
4738 multiplicative-expression * cast-expression
4739 multiplicative-expression / cast-expression
4740 multiplicative-expression % cast-expression
4742 additive-expression:
4743 multiplicative-expression
4744 additive-expression + multiplicative-expression
4745 additive-expression - multiplicative-expression
4749 shift-expression << additive-expression
4750 shift-expression >> additive-expression
4752 relational-expression:
4754 relational-expression < shift-expression
4755 relational-expression > shift-expression
4756 relational-expression <= shift-expression
4757 relational-expression >= shift-expression
4759 equality-expression:
4760 relational-expression
4761 equality-expression == relational-expression
4762 equality-expression != relational-expression
4766 AND-expression & equality-expression
4768 exclusive-OR-expression:
4770 exclusive-OR-expression ^ AND-expression
4772 inclusive-OR-expression:
4773 exclusive-OR-expression
4774 inclusive-OR-expression | exclusive-OR-expression
4776 logical-AND-expression:
4777 inclusive-OR-expression
4778 logical-AND-expression && inclusive-OR-expression
4780 logical-OR-expression:
4781 logical-AND-expression
4782 logical-OR-expression || logical-AND-expression
4785 static struct c_expr
4786 c_parser_binary_expression (c_parser
*parser
, struct c_expr
*after
)
4788 /* A binary expression is parsed using operator-precedence parsing,
4789 with the operands being cast expressions. All the binary
4790 operators are left-associative. Thus a binary expression is of
4793 E0 op1 E1 op2 E2 ...
4795 which we represent on a stack. On the stack, the precedence
4796 levels are strictly increasing. When a new operator is
4797 encountered of higher precedence than that at the top of the
4798 stack, it is pushed; its LHS is the top expression, and its RHS
4799 is everything parsed until it is popped. When a new operator is
4800 encountered with precedence less than or equal to that at the top
4801 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
4802 by the result of the operation until the operator at the top of
4803 the stack has lower precedence than the new operator or there is
4804 only one element on the stack; then the top expression is the LHS
4805 of the new operator. In the case of logical AND and OR
4806 expressions, we also need to adjust c_inhibit_evaluation_warnings
4807 as appropriate when the operators are pushed and popped. */
4809 /* The precedence levels, where 0 is a dummy lowest level used for
4810 the bottom of the stack. */
4826 /* The expression at this stack level. */
4828 /* The precedence of the operator on its left, PREC_NONE at the
4829 bottom of the stack. */
4831 /* The operation on its left. */
4833 /* The source location of this operation. */
4837 /* Location of the binary operator. */
4838 location_t binary_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4841 switch (stack[sp].op) \
4843 case TRUTH_ANDIF_EXPR: \
4844 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
4845 == truthvalue_false_node); \
4847 case TRUTH_ORIF_EXPR: \
4848 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
4849 == truthvalue_true_node); \
4854 stack[sp - 1].expr \
4855 = default_function_array_read_conversion (stack[sp - 1].loc, \
4856 stack[sp - 1].expr); \
4858 = default_function_array_read_conversion (stack[sp].loc, \
4860 stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc, \
4862 stack[sp - 1].expr, \
4866 gcc_assert (!after
|| c_dialect_objc ());
4867 stack
[0].loc
= c_parser_peek_token (parser
)->location
;
4868 stack
[0].expr
= c_parser_cast_expression (parser
, after
);
4869 stack
[0].prec
= PREC_NONE
;
4874 enum tree_code ocode
;
4877 switch (c_parser_peek_token (parser
)->type
)
4885 ocode
= TRUNC_DIV_EXPR
;
4889 ocode
= TRUNC_MOD_EXPR
;
4901 ocode
= LSHIFT_EXPR
;
4905 ocode
= RSHIFT_EXPR
;
4919 case CPP_GREATER_EQ
:
4932 oprec
= PREC_BITAND
;
4933 ocode
= BIT_AND_EXPR
;
4936 oprec
= PREC_BITXOR
;
4937 ocode
= BIT_XOR_EXPR
;
4941 ocode
= BIT_IOR_EXPR
;
4944 oprec
= PREC_LOGAND
;
4945 ocode
= TRUTH_ANDIF_EXPR
;
4949 ocode
= TRUTH_ORIF_EXPR
;
4952 /* Not a binary operator, so end of the binary
4956 binary_loc
= c_parser_peek_token (parser
)->location
;
4957 c_parser_consume_token (parser
);
4958 while (oprec
<= stack
[sp
].prec
)
4962 case TRUTH_ANDIF_EXPR
:
4964 = default_function_array_read_conversion (stack
[sp
].loc
,
4966 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
4967 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
4968 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
4969 == truthvalue_false_node
);
4971 case TRUTH_ORIF_EXPR
:
4973 = default_function_array_read_conversion (stack
[sp
].loc
,
4975 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
4976 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
4977 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
4978 == truthvalue_true_node
);
4984 stack
[sp
].loc
= binary_loc
;
4985 stack
[sp
].expr
= c_parser_cast_expression (parser
, NULL
);
4986 stack
[sp
].prec
= oprec
;
4987 stack
[sp
].op
= ocode
;
4988 stack
[sp
].loc
= binary_loc
;
4993 return stack
[0].expr
;
4997 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
4998 NULL then it is an Objective-C message expression which is the
4999 primary-expression starting the expression as an initializer.
5003 ( type-name ) unary-expression
5006 static struct c_expr
5007 c_parser_cast_expression (c_parser
*parser
, struct c_expr
*after
)
5009 location_t cast_loc
= c_parser_peek_token (parser
)->location
;
5010 gcc_assert (!after
|| c_dialect_objc ());
5012 return c_parser_postfix_expression_after_primary (parser
,
5014 /* If the expression begins with a parenthesized type name, it may
5015 be either a cast or a compound literal; we need to see whether
5016 the next character is '{' to tell the difference. If not, it is
5017 an unary expression. */
5018 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
5019 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
5021 struct c_type_name
*type_name
;
5024 c_parser_consume_token (parser
);
5025 type_name
= c_parser_type_name (parser
);
5026 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5027 if (type_name
== NULL
)
5029 ret
.value
= error_mark_node
;
5030 ret
.original_code
= ERROR_MARK
;
5031 ret
.original_type
= NULL
;
5035 /* Save casted types in the function's used types hash table. */
5036 used_types_insert (type_name
->specs
->type
);
5038 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5039 return c_parser_postfix_expression_after_paren_type (parser
, type_name
,
5042 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
5043 expr
= c_parser_cast_expression (parser
, NULL
);
5044 expr
= default_function_array_read_conversion (expr_loc
, expr
);
5046 ret
.value
= c_cast_expr (cast_loc
, type_name
, expr
.value
);
5047 ret
.original_code
= ERROR_MARK
;
5048 ret
.original_type
= NULL
;
5052 return c_parser_unary_expression (parser
);
5055 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
5061 unary-operator cast-expression
5062 sizeof unary-expression
5063 sizeof ( type-name )
5065 unary-operator: one of
5071 __alignof__ unary-expression
5072 __alignof__ ( type-name )
5075 unary-operator: one of
5076 __extension__ __real__ __imag__
5078 In addition, the GNU syntax treats ++ and -- as unary operators, so
5079 they may be applied to cast expressions with errors for non-lvalues
5082 static struct c_expr
5083 c_parser_unary_expression (c_parser
*parser
)
5086 struct c_expr ret
, op
;
5087 location_t op_loc
= c_parser_peek_token (parser
)->location
;
5089 ret
.original_code
= ERROR_MARK
;
5090 ret
.original_type
= NULL
;
5091 switch (c_parser_peek_token (parser
)->type
)
5094 c_parser_consume_token (parser
);
5095 exp_loc
= c_parser_peek_token (parser
)->location
;
5096 op
= c_parser_cast_expression (parser
, NULL
);
5097 op
= default_function_array_read_conversion (exp_loc
, op
);
5098 return parser_build_unary_op (op_loc
, PREINCREMENT_EXPR
, op
);
5099 case CPP_MINUS_MINUS
:
5100 c_parser_consume_token (parser
);
5101 exp_loc
= c_parser_peek_token (parser
)->location
;
5102 op
= c_parser_cast_expression (parser
, NULL
);
5103 op
= default_function_array_read_conversion (exp_loc
, op
);
5104 return parser_build_unary_op (op_loc
, PREDECREMENT_EXPR
, op
);
5106 c_parser_consume_token (parser
);
5107 op
= c_parser_cast_expression (parser
, NULL
);
5108 mark_exp_read (op
.value
);
5109 return parser_build_unary_op (op_loc
, ADDR_EXPR
, op
);
5111 c_parser_consume_token (parser
);
5112 exp_loc
= c_parser_peek_token (parser
)->location
;
5113 op
= c_parser_cast_expression (parser
, NULL
);
5114 op
= default_function_array_read_conversion (exp_loc
, op
);
5115 ret
.value
= build_indirect_ref (op_loc
, op
.value
, RO_UNARY_STAR
);
5118 if (!c_dialect_objc () && !in_system_header
)
5121 "traditional C rejects the unary plus operator");
5122 c_parser_consume_token (parser
);
5123 exp_loc
= c_parser_peek_token (parser
)->location
;
5124 op
= c_parser_cast_expression (parser
, NULL
);
5125 op
= default_function_array_read_conversion (exp_loc
, op
);
5126 return parser_build_unary_op (op_loc
, CONVERT_EXPR
, op
);
5128 c_parser_consume_token (parser
);
5129 exp_loc
= c_parser_peek_token (parser
)->location
;
5130 op
= c_parser_cast_expression (parser
, NULL
);
5131 op
= default_function_array_read_conversion (exp_loc
, op
);
5132 return parser_build_unary_op (op_loc
, NEGATE_EXPR
, op
);
5134 c_parser_consume_token (parser
);
5135 exp_loc
= c_parser_peek_token (parser
)->location
;
5136 op
= c_parser_cast_expression (parser
, NULL
);
5137 op
= default_function_array_read_conversion (exp_loc
, op
);
5138 return parser_build_unary_op (op_loc
, BIT_NOT_EXPR
, op
);
5140 c_parser_consume_token (parser
);
5141 exp_loc
= c_parser_peek_token (parser
)->location
;
5142 op
= c_parser_cast_expression (parser
, NULL
);
5143 op
= default_function_array_read_conversion (exp_loc
, op
);
5144 return parser_build_unary_op (op_loc
, TRUTH_NOT_EXPR
, op
);
5146 /* Refer to the address of a label as a pointer. */
5147 c_parser_consume_token (parser
);
5148 if (c_parser_next_token_is (parser
, CPP_NAME
))
5150 ret
.value
= finish_label_address_expr
5151 (c_parser_peek_token (parser
)->value
, op_loc
);
5152 c_parser_consume_token (parser
);
5156 c_parser_error (parser
, "expected identifier");
5157 ret
.value
= error_mark_node
;
5161 switch (c_parser_peek_token (parser
)->keyword
)
5164 return c_parser_sizeof_expression (parser
);
5166 return c_parser_alignof_expression (parser
);
5168 c_parser_consume_token (parser
);
5169 ext
= disable_extension_diagnostics ();
5170 ret
= c_parser_cast_expression (parser
, NULL
);
5171 restore_extension_diagnostics (ext
);
5174 c_parser_consume_token (parser
);
5175 exp_loc
= c_parser_peek_token (parser
)->location
;
5176 op
= c_parser_cast_expression (parser
, NULL
);
5177 op
= default_function_array_conversion (exp_loc
, op
);
5178 return parser_build_unary_op (op_loc
, REALPART_EXPR
, op
);
5180 c_parser_consume_token (parser
);
5181 exp_loc
= c_parser_peek_token (parser
)->location
;
5182 op
= c_parser_cast_expression (parser
, NULL
);
5183 op
= default_function_array_conversion (exp_loc
, op
);
5184 return parser_build_unary_op (op_loc
, IMAGPART_EXPR
, op
);
5186 return c_parser_postfix_expression (parser
);
5189 return c_parser_postfix_expression (parser
);
5193 /* Parse a sizeof expression. */
5195 static struct c_expr
5196 c_parser_sizeof_expression (c_parser
*parser
)
5199 location_t expr_loc
;
5200 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SIZEOF
));
5201 c_parser_consume_token (parser
);
5202 c_inhibit_evaluation_warnings
++;
5204 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
5205 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
5207 /* Either sizeof ( type-name ) or sizeof unary-expression
5208 starting with a compound literal. */
5209 struct c_type_name
*type_name
;
5210 c_parser_consume_token (parser
);
5211 expr_loc
= c_parser_peek_token (parser
)->location
;
5212 type_name
= c_parser_type_name (parser
);
5213 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5214 if (type_name
== NULL
)
5217 c_inhibit_evaluation_warnings
--;
5219 ret
.value
= error_mark_node
;
5220 ret
.original_code
= ERROR_MARK
;
5221 ret
.original_type
= NULL
;
5224 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5226 expr
= c_parser_postfix_expression_after_paren_type (parser
,
5231 /* sizeof ( type-name ). */
5232 c_inhibit_evaluation_warnings
--;
5234 return c_expr_sizeof_type (expr_loc
, type_name
);
5238 expr_loc
= c_parser_peek_token (parser
)->location
;
5239 expr
= c_parser_unary_expression (parser
);
5241 c_inhibit_evaluation_warnings
--;
5243 mark_exp_read (expr
.value
);
5244 if (TREE_CODE (expr
.value
) == COMPONENT_REF
5245 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
5246 error_at (expr_loc
, "%<sizeof%> applied to a bit-field");
5247 return c_expr_sizeof_expr (expr_loc
, expr
);
5251 /* Parse an alignof expression. */
5253 static struct c_expr
5254 c_parser_alignof_expression (c_parser
*parser
)
5257 location_t loc
= c_parser_peek_token (parser
)->location
;
5258 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNOF
));
5259 c_parser_consume_token (parser
);
5260 c_inhibit_evaluation_warnings
++;
5262 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
5263 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
5265 /* Either __alignof__ ( type-name ) or __alignof__
5266 unary-expression starting with a compound literal. */
5268 struct c_type_name
*type_name
;
5270 c_parser_consume_token (parser
);
5271 loc
= c_parser_peek_token (parser
)->location
;
5272 type_name
= c_parser_type_name (parser
);
5273 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5274 if (type_name
== NULL
)
5277 c_inhibit_evaluation_warnings
--;
5279 ret
.value
= error_mark_node
;
5280 ret
.original_code
= ERROR_MARK
;
5281 ret
.original_type
= NULL
;
5284 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5286 expr
= c_parser_postfix_expression_after_paren_type (parser
,
5291 /* alignof ( type-name ). */
5292 c_inhibit_evaluation_warnings
--;
5294 ret
.value
= c_alignof (loc
, groktypename (type_name
, NULL
, NULL
));
5295 ret
.original_code
= ERROR_MARK
;
5296 ret
.original_type
= NULL
;
5302 expr
= c_parser_unary_expression (parser
);
5304 mark_exp_read (expr
.value
);
5305 c_inhibit_evaluation_warnings
--;
5307 ret
.value
= c_alignof_expr (loc
, expr
.value
);
5308 ret
.original_code
= ERROR_MARK
;
5309 ret
.original_type
= NULL
;
5314 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
5318 postfix-expression [ expression ]
5319 postfix-expression ( argument-expression-list[opt] )
5320 postfix-expression . identifier
5321 postfix-expression -> identifier
5322 postfix-expression ++
5323 postfix-expression --
5324 ( type-name ) { initializer-list }
5325 ( type-name ) { initializer-list , }
5327 argument-expression-list:
5329 argument-expression-list , argument-expression
5341 (treated as a keyword in GNU C)
5344 ( compound-statement )
5345 __builtin_va_arg ( assignment-expression , type-name )
5346 __builtin_offsetof ( type-name , offsetof-member-designator )
5347 __builtin_choose_expr ( assignment-expression ,
5348 assignment-expression ,
5349 assignment-expression )
5350 __builtin_types_compatible_p ( type-name , type-name )
5352 offsetof-member-designator:
5354 offsetof-member-designator . identifier
5355 offsetof-member-designator [ expression ]
5360 [ objc-receiver objc-message-args ]
5361 @selector ( objc-selector-arg )
5362 @protocol ( identifier )
5363 @encode ( type-name )
5367 static struct c_expr
5368 c_parser_postfix_expression (c_parser
*parser
)
5370 struct c_expr expr
, e1
, e2
, e3
;
5371 struct c_type_name
*t1
, *t2
;
5372 location_t loc
= c_parser_peek_token (parser
)->location
;;
5373 expr
.original_code
= ERROR_MARK
;
5374 expr
.original_type
= NULL
;
5375 switch (c_parser_peek_token (parser
)->type
)
5378 expr
.value
= c_parser_peek_token (parser
)->value
;
5379 loc
= c_parser_peek_token (parser
)->location
;
5380 c_parser_consume_token (parser
);
5381 if (TREE_CODE (expr
.value
) == FIXED_CST
5382 && !targetm
.fixed_point_supported_p ())
5384 error_at (loc
, "fixed-point types not supported for this target");
5385 expr
.value
= error_mark_node
;
5392 expr
.value
= c_parser_peek_token (parser
)->value
;
5393 c_parser_consume_token (parser
);
5399 case CPP_UTF8STRING
:
5400 expr
.value
= c_parser_peek_token (parser
)->value
;
5401 expr
.original_code
= STRING_CST
;
5402 c_parser_consume_token (parser
);
5404 case CPP_OBJC_STRING
:
5405 gcc_assert (c_dialect_objc ());
5407 = objc_build_string_object (c_parser_peek_token (parser
)->value
);
5408 c_parser_consume_token (parser
);
5411 if (c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
5413 c_parser_error (parser
, "expected expression");
5414 expr
.value
= error_mark_node
;
5418 tree id
= c_parser_peek_token (parser
)->value
;
5419 c_parser_consume_token (parser
);
5420 expr
.value
= build_external_ref (loc
, id
,
5421 (c_parser_peek_token (parser
)->type
5423 &expr
.original_type
);
5426 case CPP_OPEN_PAREN
:
5427 /* A parenthesized expression, statement expression or compound
5429 if (c_parser_peek_2nd_token (parser
)->type
== CPP_OPEN_BRACE
)
5431 /* A statement expression. */
5433 location_t brace_loc
;
5434 c_parser_consume_token (parser
);
5435 brace_loc
= c_parser_peek_token (parser
)->location
;
5436 c_parser_consume_token (parser
);
5437 if (cur_stmt_list
== NULL
)
5439 error_at (loc
, "braced-group within expression allowed "
5440 "only inside a function");
5441 parser
->error
= true;
5442 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
5443 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5444 expr
.value
= error_mark_node
;
5447 stmt
= c_begin_stmt_expr ();
5448 c_parser_compound_statement_nostart (parser
);
5449 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5451 pedwarn (loc
, OPT_pedantic
,
5452 "ISO C forbids braced-groups within expressions");
5453 expr
.value
= c_finish_stmt_expr (brace_loc
, stmt
);
5455 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
5457 /* A compound literal. ??? Can we actually get here rather
5458 than going directly to
5459 c_parser_postfix_expression_after_paren_type from
5462 struct c_type_name
*type_name
;
5463 c_parser_consume_token (parser
);
5464 loc
= c_parser_peek_token (parser
)->location
;
5465 type_name
= c_parser_type_name (parser
);
5466 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5468 if (type_name
== NULL
)
5470 expr
.value
= error_mark_node
;
5473 expr
= c_parser_postfix_expression_after_paren_type (parser
,
5479 /* A parenthesized expression. */
5480 c_parser_consume_token (parser
);
5481 expr
= c_parser_expression (parser
);
5482 if (TREE_CODE (expr
.value
) == MODIFY_EXPR
)
5483 TREE_NO_WARNING (expr
.value
) = 1;
5484 if (expr
.original_code
!= C_MAYBE_CONST_EXPR
)
5485 expr
.original_code
= ERROR_MARK
;
5486 /* Don't change EXPR.ORIGINAL_TYPE. */
5487 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5492 switch (c_parser_peek_token (parser
)->keyword
)
5494 case RID_FUNCTION_NAME
:
5495 case RID_PRETTY_FUNCTION_NAME
:
5496 case RID_C99_FUNCTION_NAME
:
5497 expr
.value
= fname_decl (loc
,
5498 c_parser_peek_token (parser
)->keyword
,
5499 c_parser_peek_token (parser
)->value
);
5500 c_parser_consume_token (parser
);
5503 c_parser_consume_token (parser
);
5504 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5506 expr
.value
= error_mark_node
;
5509 e1
= c_parser_expr_no_commas (parser
, NULL
);
5510 mark_exp_read (e1
.value
);
5511 e1
.value
= c_fully_fold (e1
.value
, false, NULL
);
5512 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5514 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5515 expr
.value
= error_mark_node
;
5518 loc
= c_parser_peek_token (parser
)->location
;
5519 t1
= c_parser_type_name (parser
);
5520 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5524 expr
.value
= error_mark_node
;
5528 tree type_expr
= NULL_TREE
;
5529 expr
.value
= c_build_va_arg (loc
, e1
.value
,
5530 groktypename (t1
, &type_expr
, NULL
));
5533 expr
.value
= build2 (C_MAYBE_CONST_EXPR
,
5534 TREE_TYPE (expr
.value
), type_expr
,
5536 C_MAYBE_CONST_EXPR_NON_CONST (expr
.value
) = true;
5541 c_parser_consume_token (parser
);
5542 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5544 expr
.value
= error_mark_node
;
5547 t1
= c_parser_type_name (parser
);
5550 expr
.value
= error_mark_node
;
5553 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5555 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5556 expr
.value
= error_mark_node
;
5560 tree type
= groktypename (t1
, NULL
, NULL
);
5562 if (type
== error_mark_node
)
5563 offsetof_ref
= error_mark_node
;
5566 offsetof_ref
= build1 (INDIRECT_REF
, type
, null_pointer_node
);
5567 SET_EXPR_LOCATION (offsetof_ref
, loc
);
5569 /* Parse the second argument to __builtin_offsetof. We
5570 must have one identifier, and beyond that we want to
5571 accept sub structure and sub array references. */
5572 if (c_parser_next_token_is (parser
, CPP_NAME
))
5574 offsetof_ref
= build_component_ref
5575 (loc
, offsetof_ref
, c_parser_peek_token (parser
)->value
);
5576 c_parser_consume_token (parser
);
5577 while (c_parser_next_token_is (parser
, CPP_DOT
)
5578 || c_parser_next_token_is (parser
,
5580 || c_parser_next_token_is (parser
,
5583 if (c_parser_next_token_is (parser
, CPP_DEREF
))
5585 loc
= c_parser_peek_token (parser
)->location
;
5586 offsetof_ref
= build_array_ref (loc
,
5591 else if (c_parser_next_token_is (parser
, CPP_DOT
))
5594 c_parser_consume_token (parser
);
5595 if (c_parser_next_token_is_not (parser
,
5598 c_parser_error (parser
, "expected identifier");
5601 offsetof_ref
= build_component_ref
5603 c_parser_peek_token (parser
)->value
);
5604 c_parser_consume_token (parser
);
5609 loc
= c_parser_peek_token (parser
)->location
;
5610 c_parser_consume_token (parser
);
5611 idx
= c_parser_expression (parser
).value
;
5612 idx
= c_fully_fold (idx
, false, NULL
);
5613 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5615 offsetof_ref
= build_array_ref (loc
, offsetof_ref
, idx
);
5620 c_parser_error (parser
, "expected identifier");
5621 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5623 expr
.value
= fold_offsetof (offsetof_ref
, NULL_TREE
);
5626 case RID_CHOOSE_EXPR
:
5627 c_parser_consume_token (parser
);
5628 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5630 expr
.value
= error_mark_node
;
5633 loc
= c_parser_peek_token (parser
)->location
;
5634 e1
= c_parser_expr_no_commas (parser
, NULL
);
5635 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5637 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5638 expr
.value
= error_mark_node
;
5641 e2
= c_parser_expr_no_commas (parser
, NULL
);
5642 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5644 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5645 expr
.value
= error_mark_node
;
5648 e3
= c_parser_expr_no_commas (parser
, NULL
);
5649 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5655 mark_exp_read (e2
.value
);
5656 mark_exp_read (e3
.value
);
5657 if (TREE_CODE (c
) != INTEGER_CST
5658 || !INTEGRAL_TYPE_P (TREE_TYPE (c
)))
5660 "first argument to %<__builtin_choose_expr%> not"
5662 constant_expression_warning (c
);
5663 expr
= integer_zerop (c
) ? e3
: e2
;
5666 case RID_TYPES_COMPATIBLE_P
:
5667 c_parser_consume_token (parser
);
5668 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5670 expr
.value
= error_mark_node
;
5673 t1
= c_parser_type_name (parser
);
5676 expr
.value
= error_mark_node
;
5679 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5681 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5682 expr
.value
= error_mark_node
;
5685 t2
= c_parser_type_name (parser
);
5688 expr
.value
= error_mark_node
;
5691 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5696 e1
= TYPE_MAIN_VARIANT (groktypename (t1
, NULL
, NULL
));
5697 e2
= TYPE_MAIN_VARIANT (groktypename (t2
, NULL
, NULL
));
5699 expr
.value
= comptypes (e1
, e2
)
5700 ? build_int_cst (NULL_TREE
, 1)
5701 : build_int_cst (NULL_TREE
, 0);
5704 case RID_AT_SELECTOR
:
5705 gcc_assert (c_dialect_objc ());
5706 c_parser_consume_token (parser
);
5707 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5709 expr
.value
= error_mark_node
;
5713 tree sel
= c_parser_objc_selector_arg (parser
);
5714 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5716 expr
.value
= objc_build_selector_expr (loc
, sel
);
5719 case RID_AT_PROTOCOL
:
5720 gcc_assert (c_dialect_objc ());
5721 c_parser_consume_token (parser
);
5722 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5724 expr
.value
= error_mark_node
;
5727 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5729 c_parser_error (parser
, "expected identifier");
5730 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5731 expr
.value
= error_mark_node
;
5735 tree id
= c_parser_peek_token (parser
)->value
;
5736 c_parser_consume_token (parser
);
5737 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5739 expr
.value
= objc_build_protocol_expr (id
);
5743 /* Extension to support C-structures in the archiver. */
5744 gcc_assert (c_dialect_objc ());
5745 c_parser_consume_token (parser
);
5746 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5748 expr
.value
= error_mark_node
;
5751 t1
= c_parser_type_name (parser
);
5754 expr
.value
= error_mark_node
;
5755 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5758 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5761 tree type
= groktypename (t1
, NULL
, NULL
);
5762 expr
.value
= objc_build_encode_expr (type
);
5766 c_parser_error (parser
, "expected expression");
5767 expr
.value
= error_mark_node
;
5771 case CPP_OPEN_SQUARE
:
5772 if (c_dialect_objc ())
5774 tree receiver
, args
;
5775 c_parser_consume_token (parser
);
5776 receiver
= c_parser_objc_receiver (parser
);
5777 args
= c_parser_objc_message_args (parser
);
5778 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5780 expr
.value
= objc_build_message_expr (build_tree_list (receiver
,
5784 /* Else fall through to report error. */
5786 c_parser_error (parser
, "expected expression");
5787 expr
.value
= error_mark_node
;
5790 return c_parser_postfix_expression_after_primary (parser
, loc
, expr
);
5793 /* Parse a postfix expression after a parenthesized type name: the
5794 brace-enclosed initializer of a compound literal, possibly followed
5795 by some postfix operators. This is separate because it is not
5796 possible to tell until after the type name whether a cast
5797 expression has a cast or a compound literal, or whether the operand
5798 of sizeof is a parenthesized type name or starts with a compound
5799 literal. TYPE_LOC is the location where TYPE_NAME starts--the
5800 location of the first token after the parentheses around the type
5803 static struct c_expr
5804 c_parser_postfix_expression_after_paren_type (c_parser
*parser
,
5805 struct c_type_name
*type_name
,
5806 location_t type_loc
)
5812 location_t start_loc
;
5813 tree type_expr
= NULL_TREE
;
5814 bool type_expr_const
= true;
5815 check_compound_literal_type (type_loc
, type_name
);
5816 start_init (NULL_TREE
, NULL
, 0);
5817 type
= groktypename (type_name
, &type_expr
, &type_expr_const
);
5818 start_loc
= c_parser_peek_token (parser
)->location
;
5819 if (type
!= error_mark_node
&& C_TYPE_VARIABLE_SIZE (type
))
5821 error_at (type_loc
, "compound literal has variable size");
5822 type
= error_mark_node
;
5824 init
= c_parser_braced_init (parser
, type
, false);
5826 maybe_warn_string_init (type
, init
);
5828 if (type
!= error_mark_node
5829 && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type
))
5830 && current_function_decl
)
5832 error ("compound literal qualified by address-space qualifier");
5833 type
= error_mark_node
;
5837 pedwarn (start_loc
, OPT_pedantic
, "ISO C90 forbids compound literals");
5838 non_const
= ((init
.value
&& TREE_CODE (init
.value
) == CONSTRUCTOR
)
5839 ? CONSTRUCTOR_NON_CONST (init
.value
)
5840 : init
.original_code
== C_MAYBE_CONST_EXPR
);
5841 non_const
|= !type_expr_const
;
5842 expr
.value
= build_compound_literal (start_loc
, type
, init
.value
, non_const
);
5843 expr
.original_code
= ERROR_MARK
;
5844 expr
.original_type
= NULL
;
5847 if (TREE_CODE (expr
.value
) == C_MAYBE_CONST_EXPR
)
5849 gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr
.value
) == NULL_TREE
);
5850 C_MAYBE_CONST_EXPR_PRE (expr
.value
) = type_expr
;
5854 gcc_assert (!non_const
);
5855 expr
.value
= build2 (C_MAYBE_CONST_EXPR
, type
,
5856 type_expr
, expr
.value
);
5859 return c_parser_postfix_expression_after_primary (parser
, start_loc
, expr
);
5862 /* Parse a postfix expression after the initial primary or compound
5863 literal; that is, parse a series of postfix operators.
5865 EXPR_LOC is the location of the primary expression. */
5867 static struct c_expr
5868 c_parser_postfix_expression_after_primary (c_parser
*parser
,
5869 location_t expr_loc
,
5872 struct c_expr orig_expr
;
5874 VEC(tree
,gc
) *exprlist
;
5875 VEC(tree
,gc
) *origtypes
;
5878 location_t op_loc
= c_parser_peek_token (parser
)->location
;
5879 switch (c_parser_peek_token (parser
)->type
)
5881 case CPP_OPEN_SQUARE
:
5882 /* Array reference. */
5883 c_parser_consume_token (parser
);
5884 idx
= c_parser_expression (parser
).value
;
5885 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5887 expr
.value
= build_array_ref (op_loc
, expr
.value
, idx
);
5888 expr
.original_code
= ERROR_MARK
;
5889 expr
.original_type
= NULL
;
5891 case CPP_OPEN_PAREN
:
5892 /* Function call. */
5893 c_parser_consume_token (parser
);
5894 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
5897 exprlist
= c_parser_expr_list (parser
, true, false, &origtypes
);
5898 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5901 mark_exp_read (expr
.value
);
5902 /* FIXME diagnostics: Ideally we want the FUNCNAME, not the
5903 "(" after the FUNCNAME, which is what we have now. */
5904 expr
.value
= build_function_call_vec (op_loc
, expr
.value
, exprlist
,
5906 expr
.original_code
= ERROR_MARK
;
5907 if (TREE_CODE (expr
.value
) == INTEGER_CST
5908 && TREE_CODE (orig_expr
.value
) == FUNCTION_DECL
5909 && DECL_BUILT_IN_CLASS (orig_expr
.value
) == BUILT_IN_NORMAL
5910 && DECL_FUNCTION_CODE (orig_expr
.value
) == BUILT_IN_CONSTANT_P
)
5911 expr
.original_code
= C_MAYBE_CONST_EXPR
;
5912 expr
.original_type
= NULL
;
5913 if (exprlist
!= NULL
)
5915 release_tree_vector (exprlist
);
5916 release_tree_vector (origtypes
);
5920 /* Structure element reference. */
5921 c_parser_consume_token (parser
);
5922 expr
= default_function_array_conversion (expr_loc
, expr
);
5923 if (c_parser_next_token_is (parser
, CPP_NAME
))
5924 ident
= c_parser_peek_token (parser
)->value
;
5927 c_parser_error (parser
, "expected identifier");
5928 expr
.value
= error_mark_node
;
5929 expr
.original_code
= ERROR_MARK
;
5930 expr
.original_type
= NULL
;
5933 c_parser_consume_token (parser
);
5934 expr
.value
= build_component_ref (op_loc
, expr
.value
, ident
);
5935 expr
.original_code
= ERROR_MARK
;
5936 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
5937 expr
.original_type
= NULL
;
5940 /* Remember the original type of a bitfield. */
5941 tree field
= TREE_OPERAND (expr
.value
, 1);
5942 if (TREE_CODE (field
) != FIELD_DECL
)
5943 expr
.original_type
= NULL
;
5945 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
5949 /* Structure element reference. */
5950 c_parser_consume_token (parser
);
5951 expr
= default_function_array_conversion (expr_loc
, expr
);
5952 if (c_parser_next_token_is (parser
, CPP_NAME
))
5953 ident
= c_parser_peek_token (parser
)->value
;
5956 c_parser_error (parser
, "expected identifier");
5957 expr
.value
= error_mark_node
;
5958 expr
.original_code
= ERROR_MARK
;
5959 expr
.original_type
= NULL
;
5962 c_parser_consume_token (parser
);
5963 expr
.value
= build_component_ref (op_loc
,
5964 build_indirect_ref (op_loc
,
5968 expr
.original_code
= ERROR_MARK
;
5969 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
5970 expr
.original_type
= NULL
;
5973 /* Remember the original type of a bitfield. */
5974 tree field
= TREE_OPERAND (expr
.value
, 1);
5975 if (TREE_CODE (field
) != FIELD_DECL
)
5976 expr
.original_type
= NULL
;
5978 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
5982 /* Postincrement. */
5983 c_parser_consume_token (parser
);
5984 expr
= default_function_array_read_conversion (expr_loc
, expr
);
5985 expr
.value
= build_unary_op (op_loc
,
5986 POSTINCREMENT_EXPR
, expr
.value
, 0);
5987 expr
.original_code
= ERROR_MARK
;
5988 expr
.original_type
= NULL
;
5990 case CPP_MINUS_MINUS
:
5991 /* Postdecrement. */
5992 c_parser_consume_token (parser
);
5993 expr
= default_function_array_read_conversion (expr_loc
, expr
);
5994 expr
.value
= build_unary_op (op_loc
,
5995 POSTDECREMENT_EXPR
, expr
.value
, 0);
5996 expr
.original_code
= ERROR_MARK
;
5997 expr
.original_type
= NULL
;
6005 /* Parse an expression (C90 6.3.17, C99 6.5.17).
6008 assignment-expression
6009 expression , assignment-expression
6012 static struct c_expr
6013 c_parser_expression (c_parser
*parser
)
6016 expr
= c_parser_expr_no_commas (parser
, NULL
);
6017 while (c_parser_next_token_is (parser
, CPP_COMMA
))
6020 location_t loc
= c_parser_peek_token (parser
)->location
;
6021 location_t expr_loc
;
6022 c_parser_consume_token (parser
);
6023 expr_loc
= c_parser_peek_token (parser
)->location
;
6024 next
= c_parser_expr_no_commas (parser
, NULL
);
6025 next
= default_function_array_conversion (expr_loc
, next
);
6026 expr
.value
= build_compound_expr (loc
, expr
.value
, next
.value
);
6027 expr
.original_code
= COMPOUND_EXPR
;
6028 expr
.original_type
= next
.original_type
;
6033 /* Parse an expression and convert functions or arrays to
6036 static struct c_expr
6037 c_parser_expression_conv (c_parser
*parser
)
6040 location_t loc
= c_parser_peek_token (parser
)->location
;
6041 expr
= c_parser_expression (parser
);
6042 expr
= default_function_array_conversion (loc
, expr
);
6046 /* Parse a non-empty list of expressions. If CONVERT_P, convert
6047 functions and arrays to pointers. If FOLD_P, fold the expressions.
6050 assignment-expression
6051 nonempty-expr-list , assignment-expression
6054 static VEC(tree
,gc
) *
6055 c_parser_expr_list (c_parser
*parser
, bool convert_p
, bool fold_p
,
6056 VEC(tree
,gc
) **p_orig_types
)
6059 VEC(tree
,gc
) *orig_types
;
6061 location_t loc
= c_parser_peek_token (parser
)->location
;
6063 ret
= make_tree_vector ();
6064 if (p_orig_types
== NULL
)
6067 orig_types
= make_tree_vector ();
6069 expr
= c_parser_expr_no_commas (parser
, NULL
);
6071 expr
= default_function_array_read_conversion (loc
, expr
);
6073 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
6074 VEC_quick_push (tree
, ret
, expr
.value
);
6075 if (orig_types
!= NULL
)
6076 VEC_quick_push (tree
, orig_types
, expr
.original_type
);
6077 while (c_parser_next_token_is (parser
, CPP_COMMA
))
6079 c_parser_consume_token (parser
);
6080 loc
= c_parser_peek_token (parser
)->location
;
6081 expr
= c_parser_expr_no_commas (parser
, NULL
);
6083 expr
= default_function_array_read_conversion (loc
, expr
);
6085 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
6086 VEC_safe_push (tree
, gc
, ret
, expr
.value
);
6087 if (orig_types
!= NULL
)
6088 VEC_safe_push (tree
, gc
, orig_types
, expr
.original_type
);
6090 if (orig_types
!= NULL
)
6091 *p_orig_types
= orig_types
;
6095 /* Parse Objective-C-specific constructs. */
6097 /* Parse an objc-class-definition.
6099 objc-class-definition:
6100 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
6101 objc-class-instance-variables[opt] objc-methodprotolist @end
6102 @implementation identifier objc-superclass[opt]
6103 objc-class-instance-variables[opt]
6104 @interface identifier ( identifier ) objc-protocol-refs[opt]
6105 objc-methodprotolist @end
6106 @implementation identifier ( identifier )
6111 "@interface identifier (" must start "@interface identifier (
6112 identifier ) ...": objc-methodprotolist in the first production may
6113 not start with a parenthesized identifier as a declarator of a data
6114 definition with no declaration specifiers if the objc-superclass,
6115 objc-protocol-refs and objc-class-instance-variables are omitted. */
6118 c_parser_objc_class_definition (c_parser
*parser
)
6123 if (c_parser_next_token_is_keyword (parser
, RID_AT_INTERFACE
))
6125 else if (c_parser_next_token_is_keyword (parser
, RID_AT_IMPLEMENTATION
))
6129 c_parser_consume_token (parser
);
6130 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6132 c_parser_error (parser
, "expected identifier");
6135 id1
= c_parser_peek_token (parser
)->value
;
6136 c_parser_consume_token (parser
);
6137 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
6140 tree proto
= NULL_TREE
;
6141 c_parser_consume_token (parser
);
6142 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6144 c_parser_error (parser
, "expected identifier");
6145 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6148 id2
= c_parser_peek_token (parser
)->value
;
6149 c_parser_consume_token (parser
);
6150 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6153 objc_start_category_implementation (id1
, id2
);
6156 if (c_parser_next_token_is (parser
, CPP_LESS
))
6157 proto
= c_parser_objc_protocol_refs (parser
);
6158 objc_start_category_interface (id1
, id2
, proto
);
6159 c_parser_objc_methodprotolist (parser
);
6160 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
6161 objc_finish_interface ();
6164 if (c_parser_next_token_is (parser
, CPP_COLON
))
6166 c_parser_consume_token (parser
);
6167 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6169 c_parser_error (parser
, "expected identifier");
6172 superclass
= c_parser_peek_token (parser
)->value
;
6173 c_parser_consume_token (parser
);
6176 superclass
= NULL_TREE
;
6179 tree proto
= NULL_TREE
;
6180 if (c_parser_next_token_is (parser
, CPP_LESS
))
6181 proto
= c_parser_objc_protocol_refs (parser
);
6182 objc_start_class_interface (id1
, superclass
, proto
);
6185 objc_start_class_implementation (id1
, superclass
);
6186 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6187 c_parser_objc_class_instance_variables (parser
);
6190 objc_continue_interface ();
6191 c_parser_objc_methodprotolist (parser
);
6192 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
6193 objc_finish_interface ();
6197 objc_continue_implementation ();
6202 /* Parse objc-class-instance-variables.
6204 objc-class-instance-variables:
6205 { objc-instance-variable-decl-list[opt] }
6207 objc-instance-variable-decl-list:
6208 objc-visibility-spec
6209 objc-instance-variable-decl ;
6211 objc-instance-variable-decl-list objc-visibility-spec
6212 objc-instance-variable-decl-list objc-instance-variable-decl ;
6213 objc-instance-variable-decl-list ;
6215 objc-visibility-spec:
6220 objc-instance-variable-decl:
6225 c_parser_objc_class_instance_variables (c_parser
*parser
)
6227 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
6228 c_parser_consume_token (parser
);
6229 while (c_parser_next_token_is_not (parser
, CPP_EOF
))
6232 /* Parse any stray semicolon. */
6233 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
6235 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
6236 "extra semicolon in struct or union specified");
6237 c_parser_consume_token (parser
);
6240 /* Stop if at the end of the instance variables. */
6241 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
6243 c_parser_consume_token (parser
);
6246 /* Parse any objc-visibility-spec. */
6247 if (c_parser_next_token_is_keyword (parser
, RID_PRIVATE
))
6249 c_parser_consume_token (parser
);
6250 objc_set_visibility (2);
6253 else if (c_parser_next_token_is_keyword (parser
, RID_PROTECTED
))
6255 c_parser_consume_token (parser
);
6256 objc_set_visibility (0);
6259 else if (c_parser_next_token_is_keyword (parser
, RID_PUBLIC
))
6261 c_parser_consume_token (parser
);
6262 objc_set_visibility (1);
6265 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
6267 c_parser_pragma (parser
, pragma_external
);
6271 /* Parse some comma-separated declarations. */
6272 decls
= c_parser_struct_declaration (parser
);
6274 /* Comma-separated instance variables are chained together in
6275 reverse order; add them one by one. */
6276 tree ivar
= nreverse (decls
);
6277 for (; ivar
; ivar
= TREE_CHAIN (ivar
))
6278 objc_add_instance_variable (copy_node (ivar
));
6280 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
6284 /* Parse an objc-class-declaration.
6286 objc-class-declaration:
6287 @class identifier-list ;
6291 c_parser_objc_class_declaration (c_parser
*parser
)
6293 tree list
= NULL_TREE
;
6294 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_CLASS
));
6295 c_parser_consume_token (parser
);
6296 /* Any identifiers, including those declared as type names, are OK
6301 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6303 c_parser_error (parser
, "expected identifier");
6306 id
= c_parser_peek_token (parser
)->value
;
6307 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
6308 c_parser_consume_token (parser
);
6309 if (c_parser_next_token_is (parser
, CPP_COMMA
))
6310 c_parser_consume_token (parser
);
6314 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
6315 objc_declare_class (list
);
6318 /* Parse an objc-alias-declaration.
6320 objc-alias-declaration:
6321 @compatibility_alias identifier identifier ;
6325 c_parser_objc_alias_declaration (c_parser
*parser
)
6328 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_ALIAS
));
6329 c_parser_consume_token (parser
);
6330 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6332 c_parser_error (parser
, "expected identifier");
6333 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
6336 id1
= c_parser_peek_token (parser
)->value
;
6337 c_parser_consume_token (parser
);
6338 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6340 c_parser_error (parser
, "expected identifier");
6341 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
6344 id2
= c_parser_peek_token (parser
)->value
;
6345 c_parser_consume_token (parser
);
6346 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
6347 objc_declare_alias (id1
, id2
);
6350 /* Parse an objc-protocol-definition.
6352 objc-protocol-definition:
6353 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
6354 @protocol identifier-list ;
6356 "@protocol identifier ;" should be resolved as "@protocol
6357 identifier-list ;": objc-methodprotolist may not start with a
6358 semicolon in the first alternative if objc-protocol-refs are
6362 c_parser_objc_protocol_definition (c_parser
*parser
)
6364 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROTOCOL
));
6365 c_parser_consume_token (parser
);
6366 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6368 c_parser_error (parser
, "expected identifier");
6371 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
6372 || c_parser_peek_2nd_token (parser
)->type
== CPP_SEMICOLON
)
6374 tree list
= NULL_TREE
;
6375 /* Any identifiers, including those declared as type names, are
6380 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6382 c_parser_error (parser
, "expected identifier");
6385 id
= c_parser_peek_token (parser
)->value
;
6386 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
6387 c_parser_consume_token (parser
);
6388 if (c_parser_next_token_is (parser
, CPP_COMMA
))
6389 c_parser_consume_token (parser
);
6393 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
6394 objc_declare_protocols (list
);
6398 tree id
= c_parser_peek_token (parser
)->value
;
6399 tree proto
= NULL_TREE
;
6400 c_parser_consume_token (parser
);
6401 if (c_parser_next_token_is (parser
, CPP_LESS
))
6402 proto
= c_parser_objc_protocol_refs (parser
);
6403 parser
->objc_pq_context
= true;
6404 objc_start_protocol (id
, proto
);
6405 c_parser_objc_methodprotolist (parser
);
6406 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
6407 parser
->objc_pq_context
= false;
6408 objc_finish_interface ();
6412 /* Parse an objc-method-type.
6419 static enum tree_code
6420 c_parser_objc_method_type (c_parser
*parser
)
6422 switch (c_parser_peek_token (parser
)->type
)
6425 c_parser_consume_token (parser
);
6428 c_parser_consume_token (parser
);
6435 /* Parse an objc-method-definition.
6437 objc-method-definition:
6438 objc-method-type objc-method-decl ;[opt] compound-statement
6442 c_parser_objc_method_definition (c_parser
*parser
)
6444 enum tree_code type
= c_parser_objc_method_type (parser
);
6446 objc_set_method_type (type
);
6447 parser
->objc_pq_context
= true;
6448 decl
= c_parser_objc_method_decl (parser
);
6449 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
6451 c_parser_consume_token (parser
);
6452 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
6453 "extra semicolon in method definition specified");
6455 if (!c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6457 c_parser_error (parser
, "expected %<{%>");
6460 parser
->objc_pq_context
= false;
6461 objc_start_method_definition (decl
);
6462 add_stmt (c_parser_compound_statement (parser
));
6463 objc_finish_method_definition (current_function_decl
);
6466 /* Parse an objc-methodprotolist.
6468 objc-methodprotolist:
6470 objc-methodprotolist objc-methodproto
6471 objc-methodprotolist declaration
6472 objc-methodprotolist ;
6474 The declaration is a data definition, which may be missing
6475 declaration specifiers under the same rules and diagnostics as
6476 other data definitions outside functions, and the stray semicolon
6477 is diagnosed the same way as a stray semicolon outside a
6481 c_parser_objc_methodprotolist (c_parser
*parser
)
6485 /* The list is terminated by @end. */
6486 switch (c_parser_peek_token (parser
)->type
)
6489 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
6490 "ISO C does not allow extra %<;%> outside of a function");
6491 c_parser_consume_token (parser
);
6495 c_parser_objc_methodproto (parser
);
6498 c_parser_pragma (parser
, pragma_external
);
6503 if (c_parser_next_token_is_keyword (parser
, RID_AT_END
))
6505 c_parser_declaration_or_fndef (parser
, false, true, false, true);
6511 /* Parse an objc-methodproto.
6514 objc-method-type objc-method-decl ;
6518 c_parser_objc_methodproto (c_parser
*parser
)
6520 enum tree_code type
= c_parser_objc_method_type (parser
);
6522 objc_set_method_type (type
);
6523 /* Remember protocol qualifiers in prototypes. */
6524 parser
->objc_pq_context
= true;
6525 decl
= c_parser_objc_method_decl (parser
);
6526 /* Forget protocol qualifiers here. */
6527 parser
->objc_pq_context
= false;
6528 objc_add_method_declaration (decl
);
6529 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
6532 /* Parse an objc-method-decl.
6535 ( objc-type-name ) objc-selector
6537 ( objc-type-name ) objc-keyword-selector objc-optparmlist
6538 objc-keyword-selector objc-optparmlist
6540 objc-keyword-selector:
6542 objc-keyword-selector objc-keyword-decl
6545 objc-selector : ( objc-type-name ) identifier
6546 objc-selector : identifier
6547 : ( objc-type-name ) identifier
6551 objc-optparms objc-optellipsis
6555 objc-opt-parms , parameter-declaration
6563 c_parser_objc_method_decl (c_parser
*parser
)
6565 tree type
= NULL_TREE
;
6567 tree parms
= NULL_TREE
;
6568 bool ellipsis
= false;
6570 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
6572 c_parser_consume_token (parser
);
6573 type
= c_parser_objc_type_name (parser
);
6574 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6576 sel
= c_parser_objc_selector (parser
);
6577 /* If there is no selector, or a colon follows, we have an
6578 objc-keyword-selector. If there is a selector, and a colon does
6579 not follow, that selector ends the objc-method-decl. */
6580 if (!sel
|| c_parser_next_token_is (parser
, CPP_COLON
))
6583 tree list
= NULL_TREE
;
6586 tree atype
= NULL_TREE
, id
, keyworddecl
;
6587 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6589 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
6591 c_parser_consume_token (parser
);
6592 atype
= c_parser_objc_type_name (parser
);
6593 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6596 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6598 c_parser_error (parser
, "expected identifier");
6599 return error_mark_node
;
6601 id
= c_parser_peek_token (parser
)->value
;
6602 c_parser_consume_token (parser
);
6603 keyworddecl
= objc_build_keyword_decl (tsel
, atype
, id
);
6604 list
= chainon (list
, keyworddecl
);
6605 tsel
= c_parser_objc_selector (parser
);
6606 if (!tsel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6609 /* Parse the optional parameter list. Optional Objective-C
6610 method parameters follow the C syntax, and may include '...'
6611 to denote a variable number of arguments. */
6612 parms
= make_node (TREE_LIST
);
6613 while (c_parser_next_token_is (parser
, CPP_COMMA
))
6615 struct c_parm
*parm
;
6616 c_parser_consume_token (parser
);
6617 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
6620 c_parser_consume_token (parser
);
6623 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
6626 parms
= chainon (parms
,
6627 build_tree_list (NULL_TREE
, grokparm (parm
)));
6631 return objc_build_method_signature (type
, sel
, parms
, ellipsis
);
6634 /* Parse an objc-type-name.
6637 objc-type-qualifiers[opt] type-name
6638 objc-type-qualifiers[opt]
6640 objc-type-qualifiers:
6642 objc-type-qualifiers objc-type-qualifier
6644 objc-type-qualifier: one of
6645 in out inout bycopy byref oneway
6649 c_parser_objc_type_name (c_parser
*parser
)
6651 tree quals
= NULL_TREE
;
6652 struct c_type_name
*type_name
= NULL
;
6653 tree type
= NULL_TREE
;
6656 c_token
*token
= c_parser_peek_token (parser
);
6657 if (token
->type
== CPP_KEYWORD
6658 && (token
->keyword
== RID_IN
6659 || token
->keyword
== RID_OUT
6660 || token
->keyword
== RID_INOUT
6661 || token
->keyword
== RID_BYCOPY
6662 || token
->keyword
== RID_BYREF
6663 || token
->keyword
== RID_ONEWAY
))
6665 quals
= chainon (quals
, build_tree_list (NULL_TREE
, token
->value
));
6666 c_parser_consume_token (parser
);
6671 if (c_parser_next_token_starts_typename (parser
))
6672 type_name
= c_parser_type_name (parser
);
6674 type
= groktypename (type_name
, NULL
, NULL
);
6675 return build_tree_list (quals
, type
);
6678 /* Parse objc-protocol-refs.
6685 c_parser_objc_protocol_refs (c_parser
*parser
)
6687 tree list
= NULL_TREE
;
6688 gcc_assert (c_parser_next_token_is (parser
, CPP_LESS
));
6689 c_parser_consume_token (parser
);
6690 /* Any identifiers, including those declared as type names, are OK
6695 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6697 c_parser_error (parser
, "expected identifier");
6700 id
= c_parser_peek_token (parser
)->value
;
6701 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
6702 c_parser_consume_token (parser
);
6703 if (c_parser_next_token_is (parser
, CPP_COMMA
))
6704 c_parser_consume_token (parser
);
6708 c_parser_require (parser
, CPP_GREATER
, "expected %<>%>");
6712 /* Parse an objc-try-catch-statement.
6714 objc-try-catch-statement:
6715 @try compound-statement objc-catch-list[opt]
6716 @try compound-statement objc-catch-list[opt] @finally compound-statement
6719 @catch ( parameter-declaration ) compound-statement
6720 objc-catch-list @catch ( parameter-declaration ) compound-statement
6724 c_parser_objc_try_catch_statement (c_parser
*parser
)
6728 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TRY
));
6729 c_parser_consume_token (parser
);
6730 loc
= c_parser_peek_token (parser
)->location
;
6731 stmt
= c_parser_compound_statement (parser
);
6732 objc_begin_try_stmt (loc
, stmt
);
6733 while (c_parser_next_token_is_keyword (parser
, RID_CATCH
))
6735 struct c_parm
*parm
;
6736 c_parser_consume_token (parser
);
6737 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6739 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
6742 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6745 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6746 objc_begin_catch_clause (grokparm (parm
));
6747 if (c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
6748 c_parser_compound_statement_nostart (parser
);
6749 objc_finish_catch_clause ();
6751 if (c_parser_next_token_is_keyword (parser
, RID_AT_FINALLY
))
6755 c_parser_consume_token (parser
);
6756 finloc
= c_parser_peek_token (parser
)->location
;
6757 finstmt
= c_parser_compound_statement (parser
);
6758 objc_build_finally_clause (finloc
, finstmt
);
6760 objc_finish_try_stmt ();
6763 /* Parse an objc-synchronized-statement.
6765 objc-synchronized-statement:
6766 @synchronized ( expression ) compound-statement
6770 c_parser_objc_synchronized_statement (c_parser
*parser
)
6774 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNCHRONIZED
));
6775 c_parser_consume_token (parser
);
6776 loc
= c_parser_peek_token (parser
)->location
;
6777 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6779 expr
= c_parser_expression (parser
).value
;
6780 expr
= c_fully_fold (expr
, false, NULL
);
6781 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6784 expr
= error_mark_node
;
6785 stmt
= c_parser_compound_statement (parser
);
6786 objc_build_synchronized (loc
, expr
, stmt
);
6789 /* Parse an objc-selector; return NULL_TREE without an error if the
6790 next token is not an objc-selector.
6795 enum struct union if else while do for switch case default
6796 break continue return goto asm sizeof typeof __alignof
6797 unsigned long const short volatile signed restrict _Complex
6798 in out inout bycopy byref oneway int char float double void _Bool
6800 ??? Why this selection of keywords but not, for example, storage
6801 class specifiers? */
6804 c_parser_objc_selector (c_parser
*parser
)
6806 c_token
*token
= c_parser_peek_token (parser
);
6807 tree value
= token
->value
;
6808 if (token
->type
== CPP_NAME
)
6810 c_parser_consume_token (parser
);
6813 if (token
->type
!= CPP_KEYWORD
)
6815 switch (token
->keyword
)
6856 c_parser_consume_token (parser
);
6863 /* Parse an objc-selector-arg.
6867 objc-keywordname-list
6869 objc-keywordname-list:
6871 objc-keywordname-list objc-keywordname
6879 c_parser_objc_selector_arg (c_parser
*parser
)
6881 tree sel
= c_parser_objc_selector (parser
);
6882 tree list
= NULL_TREE
;
6883 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6887 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6889 list
= chainon (list
, build_tree_list (sel
, NULL_TREE
));
6890 sel
= c_parser_objc_selector (parser
);
6891 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6897 /* Parse an objc-receiver.
6906 c_parser_objc_receiver (c_parser
*parser
)
6908 if (c_parser_peek_token (parser
)->type
== CPP_NAME
6909 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
6910 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
6912 tree id
= c_parser_peek_token (parser
)->value
;
6913 c_parser_consume_token (parser
);
6914 return objc_get_class_reference (id
);
6916 return c_fully_fold (c_parser_expression (parser
).value
, false, NULL
);
6919 /* Parse objc-message-args.
6923 objc-keywordarg-list
6925 objc-keywordarg-list:
6927 objc-keywordarg-list objc-keywordarg
6930 objc-selector : objc-keywordexpr
6935 c_parser_objc_message_args (c_parser
*parser
)
6937 tree sel
= c_parser_objc_selector (parser
);
6938 tree list
= NULL_TREE
;
6939 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6944 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6945 return error_mark_node
;
6946 keywordexpr
= c_parser_objc_keywordexpr (parser
);
6947 list
= chainon (list
, build_tree_list (sel
, keywordexpr
));
6948 sel
= c_parser_objc_selector (parser
);
6949 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6955 /* Parse an objc-keywordexpr.
6962 c_parser_objc_keywordexpr (c_parser
*parser
)
6965 VEC(tree
,gc
) *expr_list
= c_parser_expr_list (parser
, true, true, NULL
);
6966 if (VEC_length (tree
, expr_list
) == 1)
6968 /* Just return the expression, remove a level of
6970 ret
= VEC_index (tree
, expr_list
, 0);
6974 /* We have a comma expression, we will collapse later. */
6975 ret
= build_tree_list_vec (expr_list
);
6977 release_tree_vector (expr_list
);
6982 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
6983 should be considered, statements. ALLOW_STMT is true if we're within
6984 the context of a function and such pragmas are to be allowed. Returns
6985 true if we actually parsed such a pragma. */
6988 c_parser_pragma (c_parser
*parser
, enum pragma_context context
)
6992 id
= c_parser_peek_token (parser
)->pragma_kind
;
6993 gcc_assert (id
!= PRAGMA_NONE
);
6997 case PRAGMA_OMP_BARRIER
:
6998 if (context
!= pragma_compound
)
7000 if (context
== pragma_stmt
)
7001 c_parser_error (parser
, "%<#pragma omp barrier%> may only be "
7002 "used in compound statements");
7005 c_parser_omp_barrier (parser
);
7008 case PRAGMA_OMP_FLUSH
:
7009 if (context
!= pragma_compound
)
7011 if (context
== pragma_stmt
)
7012 c_parser_error (parser
, "%<#pragma omp flush%> may only be "
7013 "used in compound statements");
7016 c_parser_omp_flush (parser
);
7019 case PRAGMA_OMP_TASKWAIT
:
7020 if (context
!= pragma_compound
)
7022 if (context
== pragma_stmt
)
7023 c_parser_error (parser
, "%<#pragma omp taskwait%> may only be "
7024 "used in compound statements");
7027 c_parser_omp_taskwait (parser
);
7030 case PRAGMA_OMP_THREADPRIVATE
:
7031 c_parser_omp_threadprivate (parser
);
7034 case PRAGMA_OMP_SECTION
:
7035 error_at (c_parser_peek_token (parser
)->location
,
7036 "%<#pragma omp section%> may only be used in "
7037 "%<#pragma omp sections%> construct");
7038 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
7041 case PRAGMA_GCC_PCH_PREPROCESS
:
7042 c_parser_error (parser
, "%<#pragma GCC pch_preprocess%> must be first");
7043 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
7047 if (id
< PRAGMA_FIRST_EXTERNAL
)
7049 if (context
== pragma_external
)
7052 c_parser_error (parser
, "expected declaration specifiers");
7053 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
7056 c_parser_omp_construct (parser
);
7062 c_parser_consume_pragma (parser
);
7063 c_invoke_pragma_handler (id
);
7065 /* Skip to EOL, but suppress any error message. Those will have been
7066 generated by the handler routine through calling error, as opposed
7067 to calling c_parser_error. */
7068 parser
->error
= true;
7069 c_parser_skip_to_pragma_eol (parser
);
7074 /* The interface the pragma parsers have to the lexer. */
7077 pragma_lex (tree
*value
)
7079 c_token
*tok
= c_parser_peek_token (the_parser
);
7080 enum cpp_ttype ret
= tok
->type
;
7082 *value
= tok
->value
;
7083 if (ret
== CPP_PRAGMA_EOL
|| ret
== CPP_EOF
)
7087 if (ret
== CPP_KEYWORD
)
7089 c_parser_consume_token (the_parser
);
7096 c_parser_pragma_pch_preprocess (c_parser
*parser
)
7100 c_parser_consume_pragma (parser
);
7101 if (c_parser_next_token_is (parser
, CPP_STRING
))
7103 name
= c_parser_peek_token (parser
)->value
;
7104 c_parser_consume_token (parser
);
7107 c_parser_error (parser
, "expected string literal");
7108 c_parser_skip_to_pragma_eol (parser
);
7111 c_common_pch_pragma (parse_in
, TREE_STRING_POINTER (name
));
7114 /* OpenMP 2.5 parsing routines. */
7116 /* Returns name of the next clause.
7117 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
7118 the token is not consumed. Otherwise appropriate pragma_omp_clause is
7119 returned and the token is consumed. */
7121 static pragma_omp_clause
7122 c_parser_omp_clause_name (c_parser
*parser
)
7124 pragma_omp_clause result
= PRAGMA_OMP_CLAUSE_NONE
;
7126 if (c_parser_next_token_is_keyword (parser
, RID_IF
))
7127 result
= PRAGMA_OMP_CLAUSE_IF
;
7128 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
7129 result
= PRAGMA_OMP_CLAUSE_DEFAULT
;
7130 else if (c_parser_next_token_is (parser
, CPP_NAME
))
7132 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
7137 if (!strcmp ("collapse", p
))
7138 result
= PRAGMA_OMP_CLAUSE_COLLAPSE
;
7139 else if (!strcmp ("copyin", p
))
7140 result
= PRAGMA_OMP_CLAUSE_COPYIN
;
7141 else if (!strcmp ("copyprivate", p
))
7142 result
= PRAGMA_OMP_CLAUSE_COPYPRIVATE
;
7145 if (!strcmp ("firstprivate", p
))
7146 result
= PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
;
7149 if (!strcmp ("lastprivate", p
))
7150 result
= PRAGMA_OMP_CLAUSE_LASTPRIVATE
;
7153 if (!strcmp ("nowait", p
))
7154 result
= PRAGMA_OMP_CLAUSE_NOWAIT
;
7155 else if (!strcmp ("num_threads", p
))
7156 result
= PRAGMA_OMP_CLAUSE_NUM_THREADS
;
7159 if (!strcmp ("ordered", p
))
7160 result
= PRAGMA_OMP_CLAUSE_ORDERED
;
7163 if (!strcmp ("private", p
))
7164 result
= PRAGMA_OMP_CLAUSE_PRIVATE
;
7167 if (!strcmp ("reduction", p
))
7168 result
= PRAGMA_OMP_CLAUSE_REDUCTION
;
7171 if (!strcmp ("schedule", p
))
7172 result
= PRAGMA_OMP_CLAUSE_SCHEDULE
;
7173 else if (!strcmp ("shared", p
))
7174 result
= PRAGMA_OMP_CLAUSE_SHARED
;
7177 if (!strcmp ("untied", p
))
7178 result
= PRAGMA_OMP_CLAUSE_UNTIED
;
7183 if (result
!= PRAGMA_OMP_CLAUSE_NONE
)
7184 c_parser_consume_token (parser
);
7189 /* Validate that a clause of the given type does not already exist. */
7192 check_no_duplicate_clause (tree clauses
, enum omp_clause_code code
,
7197 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
7198 if (OMP_CLAUSE_CODE (c
) == code
)
7200 location_t loc
= OMP_CLAUSE_LOCATION (c
);
7201 error_at (loc
, "too many %qs clauses", name
);
7209 variable-list , identifier
7211 If KIND is nonzero, create the appropriate node and install the
7212 decl in OMP_CLAUSE_DECL and add the node to the head of the list.
7213 If KIND is nonzero, CLAUSE_LOC is the location of the clause.
7215 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
7216 return the list created. */
7219 c_parser_omp_variable_list (c_parser
*parser
,
7220 location_t clause_loc
,
7221 enum omp_clause_code kind
,
7224 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
7225 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
7226 c_parser_error (parser
, "expected identifier");
7228 while (c_parser_next_token_is (parser
, CPP_NAME
)
7229 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
7231 tree t
= lookup_name (c_parser_peek_token (parser
)->value
);
7234 undeclared_variable (c_parser_peek_token (parser
)->location
,
7235 c_parser_peek_token (parser
)->value
);
7236 else if (t
== error_mark_node
)
7240 tree u
= build_omp_clause (clause_loc
, kind
);
7241 OMP_CLAUSE_DECL (u
) = t
;
7242 OMP_CLAUSE_CHAIN (u
) = list
;
7246 list
= tree_cons (t
, NULL_TREE
, list
);
7248 c_parser_consume_token (parser
);
7250 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
7253 c_parser_consume_token (parser
);
7259 /* Similarly, but expect leading and trailing parenthesis. This is a very
7260 common case for omp clauses. */
7263 c_parser_omp_var_list_parens (c_parser
*parser
, enum omp_clause_code kind
,
7266 /* The clauses location. */
7267 location_t loc
= c_parser_peek_token (parser
)->location
;
7269 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7271 list
= c_parser_omp_variable_list (parser
, loc
, kind
, list
);
7272 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7278 collapse ( constant-expression ) */
7281 c_parser_omp_clause_collapse (c_parser
*parser
, tree list
)
7283 tree c
, num
= error_mark_node
;
7287 check_no_duplicate_clause (list
, OMP_CLAUSE_COLLAPSE
, "collapse");
7289 loc
= c_parser_peek_token (parser
)->location
;
7290 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7292 num
= c_parser_expr_no_commas (parser
, NULL
).value
;
7293 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7295 if (num
== error_mark_node
)
7297 if (!INTEGRAL_TYPE_P (TREE_TYPE (num
))
7298 || !host_integerp (num
, 0)
7299 || (n
= tree_low_cst (num
, 0)) <= 0
7303 "collapse argument needs positive constant integer expression");
7306 c
= build_omp_clause (loc
, OMP_CLAUSE_COLLAPSE
);
7307 OMP_CLAUSE_COLLAPSE_EXPR (c
) = num
;
7308 OMP_CLAUSE_CHAIN (c
) = list
;
7313 copyin ( variable-list ) */
7316 c_parser_omp_clause_copyin (c_parser
*parser
, tree list
)
7318 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYIN
, list
);
7322 copyprivate ( variable-list ) */
7325 c_parser_omp_clause_copyprivate (c_parser
*parser
, tree list
)
7327 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYPRIVATE
, list
);
7331 default ( shared | none ) */
7334 c_parser_omp_clause_default (c_parser
*parser
, tree list
)
7336 enum omp_clause_default_kind kind
= OMP_CLAUSE_DEFAULT_UNSPECIFIED
;
7337 location_t loc
= c_parser_peek_token (parser
)->location
;
7340 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7342 if (c_parser_next_token_is (parser
, CPP_NAME
))
7344 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
7349 if (strcmp ("none", p
) != 0)
7351 kind
= OMP_CLAUSE_DEFAULT_NONE
;
7355 if (strcmp ("shared", p
) != 0)
7357 kind
= OMP_CLAUSE_DEFAULT_SHARED
;
7364 c_parser_consume_token (parser
);
7369 c_parser_error (parser
, "expected %<none%> or %<shared%>");
7371 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7373 if (kind
== OMP_CLAUSE_DEFAULT_UNSPECIFIED
)
7376 check_no_duplicate_clause (list
, OMP_CLAUSE_DEFAULT
, "default");
7377 c
= build_omp_clause (loc
, OMP_CLAUSE_DEFAULT
);
7378 OMP_CLAUSE_CHAIN (c
) = list
;
7379 OMP_CLAUSE_DEFAULT_KIND (c
) = kind
;
7385 firstprivate ( variable-list ) */
7388 c_parser_omp_clause_firstprivate (c_parser
*parser
, tree list
)
7390 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FIRSTPRIVATE
, list
);
7394 if ( expression ) */
7397 c_parser_omp_clause_if (c_parser
*parser
, tree list
)
7399 location_t loc
= c_parser_peek_token (parser
)->location
;
7400 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
7402 tree t
= c_parser_paren_condition (parser
);
7405 check_no_duplicate_clause (list
, OMP_CLAUSE_IF
, "if");
7407 c
= build_omp_clause (loc
, OMP_CLAUSE_IF
);
7408 OMP_CLAUSE_IF_EXPR (c
) = t
;
7409 OMP_CLAUSE_CHAIN (c
) = list
;
7413 c_parser_error (parser
, "expected %<(%>");
7419 lastprivate ( variable-list ) */
7422 c_parser_omp_clause_lastprivate (c_parser
*parser
, tree list
)
7424 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_LASTPRIVATE
, list
);
7431 c_parser_omp_clause_nowait (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
7434 location_t loc
= c_parser_peek_token (parser
)->location
;
7436 check_no_duplicate_clause (list
, OMP_CLAUSE_NOWAIT
, "nowait");
7438 c
= build_omp_clause (loc
, OMP_CLAUSE_NOWAIT
);
7439 OMP_CLAUSE_CHAIN (c
) = list
;
7444 num_threads ( expression ) */
7447 c_parser_omp_clause_num_threads (c_parser
*parser
, tree list
)
7449 location_t num_threads_loc
= c_parser_peek_token (parser
)->location
;
7450 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7452 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
7453 tree c
, t
= c_parser_expression (parser
).value
;
7454 t
= c_fully_fold (t
, false, NULL
);
7456 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7458 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
7460 c_parser_error (parser
, "expected integer expression");
7464 /* Attempt to statically determine when the number isn't positive. */
7465 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
7466 build_int_cst (TREE_TYPE (t
), 0));
7467 if (CAN_HAVE_LOCATION_P (c
))
7468 SET_EXPR_LOCATION (c
, expr_loc
);
7469 if (c
== boolean_true_node
)
7471 warning_at (expr_loc
, 0,
7472 "%<num_threads%> value must be positive");
7473 t
= integer_one_node
;
7476 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_THREADS
, "num_threads");
7478 c
= build_omp_clause (num_threads_loc
, OMP_CLAUSE_NUM_THREADS
);
7479 OMP_CLAUSE_NUM_THREADS_EXPR (c
) = t
;
7480 OMP_CLAUSE_CHAIN (c
) = list
;
7491 c_parser_omp_clause_ordered (c_parser
*parser
, tree list
)
7495 check_no_duplicate_clause (list
, OMP_CLAUSE_ORDERED
, "ordered");
7497 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
7498 OMP_CLAUSE_ORDERED
);
7499 OMP_CLAUSE_CHAIN (c
) = list
;
7505 private ( variable-list ) */
7508 c_parser_omp_clause_private (c_parser
*parser
, tree list
)
7510 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_PRIVATE
, list
);
7514 reduction ( reduction-operator : variable-list )
7517 One of: + * - & ^ | && || */
7520 c_parser_omp_clause_reduction (c_parser
*parser
, tree list
)
7522 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
7523 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7525 enum tree_code code
;
7527 switch (c_parser_peek_token (parser
)->type
)
7539 code
= BIT_AND_EXPR
;
7542 code
= BIT_XOR_EXPR
;
7545 code
= BIT_IOR_EXPR
;
7548 code
= TRUTH_ANDIF_EXPR
;
7551 code
= TRUTH_ORIF_EXPR
;
7554 c_parser_error (parser
,
7555 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
7556 "%<^%>, %<|%>, %<&&%>, or %<||%>");
7557 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
7560 c_parser_consume_token (parser
);
7561 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
7565 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
7566 OMP_CLAUSE_REDUCTION
, list
);
7567 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
7568 OMP_CLAUSE_REDUCTION_CODE (c
) = code
;
7572 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7578 schedule ( schedule-kind )
7579 schedule ( schedule-kind , expression )
7582 static | dynamic | guided | runtime | auto
7586 c_parser_omp_clause_schedule (c_parser
*parser
, tree list
)
7589 location_t loc
= c_parser_peek_token (parser
)->location
;
7591 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7594 c
= build_omp_clause (loc
, OMP_CLAUSE_SCHEDULE
);
7596 if (c_parser_next_token_is (parser
, CPP_NAME
))
7598 tree kind
= c_parser_peek_token (parser
)->value
;
7599 const char *p
= IDENTIFIER_POINTER (kind
);
7604 if (strcmp ("dynamic", p
) != 0)
7606 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_DYNAMIC
;
7610 if (strcmp ("guided", p
) != 0)
7612 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_GUIDED
;
7616 if (strcmp ("runtime", p
) != 0)
7618 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_RUNTIME
;
7625 else if (c_parser_next_token_is_keyword (parser
, RID_STATIC
))
7626 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_STATIC
;
7627 else if (c_parser_next_token_is_keyword (parser
, RID_AUTO
))
7628 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_AUTO
;
7632 c_parser_consume_token (parser
);
7633 if (c_parser_next_token_is (parser
, CPP_COMMA
))
7636 c_parser_consume_token (parser
);
7638 here
= c_parser_peek_token (parser
)->location
;
7639 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
7640 t
= c_fully_fold (t
, false, NULL
);
7642 if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_RUNTIME
)
7643 error_at (here
, "schedule %<runtime%> does not take "
7644 "a %<chunk_size%> parameter");
7645 else if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_AUTO
)
7647 "schedule %<auto%> does not take "
7648 "a %<chunk_size%> parameter");
7649 else if (TREE_CODE (TREE_TYPE (t
)) == INTEGER_TYPE
)
7650 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
) = t
;
7652 c_parser_error (parser
, "expected integer expression");
7654 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7657 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7658 "expected %<,%> or %<)%>");
7660 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
7661 OMP_CLAUSE_CHAIN (c
) = list
;
7665 c_parser_error (parser
, "invalid schedule kind");
7666 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
7671 shared ( variable-list ) */
7674 c_parser_omp_clause_shared (c_parser
*parser
, tree list
)
7676 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_SHARED
, list
);
7683 c_parser_omp_clause_untied (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
7687 /* FIXME: Should we allow duplicates? */
7688 check_no_duplicate_clause (list
, OMP_CLAUSE_UNTIED
, "untied");
7690 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
7692 OMP_CLAUSE_CHAIN (c
) = list
;
7697 /* Parse all OpenMP clauses. The set clauses allowed by the directive
7698 is a bitmask in MASK. Return the list of clauses found; the result
7699 of clause default goes in *pdefault. */
7702 c_parser_omp_all_clauses (c_parser
*parser
, unsigned int mask
,
7705 tree clauses
= NULL
;
7708 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
7711 pragma_omp_clause c_kind
;
7713 tree prev
= clauses
;
7715 if (!first
&& c_parser_next_token_is (parser
, CPP_COMMA
))
7716 c_parser_consume_token (parser
);
7719 here
= c_parser_peek_token (parser
)->location
;
7720 c_kind
= c_parser_omp_clause_name (parser
);
7724 case PRAGMA_OMP_CLAUSE_COLLAPSE
:
7725 clauses
= c_parser_omp_clause_collapse (parser
, clauses
);
7726 c_name
= "collapse";
7728 case PRAGMA_OMP_CLAUSE_COPYIN
:
7729 clauses
= c_parser_omp_clause_copyin (parser
, clauses
);
7732 case PRAGMA_OMP_CLAUSE_COPYPRIVATE
:
7733 clauses
= c_parser_omp_clause_copyprivate (parser
, clauses
);
7734 c_name
= "copyprivate";
7736 case PRAGMA_OMP_CLAUSE_DEFAULT
:
7737 clauses
= c_parser_omp_clause_default (parser
, clauses
);
7740 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
:
7741 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
7742 c_name
= "firstprivate";
7744 case PRAGMA_OMP_CLAUSE_IF
:
7745 clauses
= c_parser_omp_clause_if (parser
, clauses
);
7748 case PRAGMA_OMP_CLAUSE_LASTPRIVATE
:
7749 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
7750 c_name
= "lastprivate";
7752 case PRAGMA_OMP_CLAUSE_NOWAIT
:
7753 clauses
= c_parser_omp_clause_nowait (parser
, clauses
);
7756 case PRAGMA_OMP_CLAUSE_NUM_THREADS
:
7757 clauses
= c_parser_omp_clause_num_threads (parser
, clauses
);
7758 c_name
= "num_threads";
7760 case PRAGMA_OMP_CLAUSE_ORDERED
:
7761 clauses
= c_parser_omp_clause_ordered (parser
, clauses
);
7764 case PRAGMA_OMP_CLAUSE_PRIVATE
:
7765 clauses
= c_parser_omp_clause_private (parser
, clauses
);
7768 case PRAGMA_OMP_CLAUSE_REDUCTION
:
7769 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
7770 c_name
= "reduction";
7772 case PRAGMA_OMP_CLAUSE_SCHEDULE
:
7773 clauses
= c_parser_omp_clause_schedule (parser
, clauses
);
7774 c_name
= "schedule";
7776 case PRAGMA_OMP_CLAUSE_SHARED
:
7777 clauses
= c_parser_omp_clause_shared (parser
, clauses
);
7780 case PRAGMA_OMP_CLAUSE_UNTIED
:
7781 clauses
= c_parser_omp_clause_untied (parser
, clauses
);
7785 c_parser_error (parser
, "expected %<#pragma omp%> clause");
7789 if (((mask
>> c_kind
) & 1) == 0 && !parser
->error
)
7791 /* Remove the invalid clause(s) from the list to avoid
7792 confusing the rest of the compiler. */
7794 error_at (here
, "%qs is not valid for %qs", c_name
, where
);
7799 c_parser_skip_to_pragma_eol (parser
);
7801 return c_finish_omp_clauses (clauses
);
7808 In practice, we're also interested in adding the statement to an
7809 outer node. So it is convenient if we work around the fact that
7810 c_parser_statement calls add_stmt. */
7813 c_parser_omp_structured_block (c_parser
*parser
)
7815 tree stmt
= push_stmt_list ();
7816 c_parser_statement (parser
);
7817 return pop_stmt_list (stmt
);
7821 # pragma omp atomic new-line
7825 x binop= expr | x++ | ++x | x-- | --x
7827 +, *, -, /, &, ^, |, <<, >>
7829 where x is an lvalue expression with scalar type.
7831 LOC is the location of the #pragma token. */
7834 c_parser_omp_atomic (location_t loc
, c_parser
*parser
)
7838 enum tree_code code
;
7839 struct c_expr rhs_expr
;
7841 c_parser_skip_to_pragma_eol (parser
);
7843 lhs
= c_parser_unary_expression (parser
).value
;
7844 lhs
= c_fully_fold (lhs
, false, NULL
);
7845 switch (TREE_CODE (lhs
))
7849 c_parser_skip_to_end_of_block_or_statement (parser
);
7852 case PREINCREMENT_EXPR
:
7853 case POSTINCREMENT_EXPR
:
7854 lhs
= TREE_OPERAND (lhs
, 0);
7856 rhs
= integer_one_node
;
7859 case PREDECREMENT_EXPR
:
7860 case POSTDECREMENT_EXPR
:
7861 lhs
= TREE_OPERAND (lhs
, 0);
7863 rhs
= integer_one_node
;
7867 switch (c_parser_peek_token (parser
)->type
)
7873 code
= TRUNC_DIV_EXPR
;
7888 code
= BIT_AND_EXPR
;
7891 code
= BIT_IOR_EXPR
;
7894 code
= BIT_XOR_EXPR
;
7897 c_parser_error (parser
,
7898 "invalid operator for %<#pragma omp atomic%>");
7902 c_parser_consume_token (parser
);
7904 location_t rhs_loc
= c_parser_peek_token (parser
)->location
;
7905 rhs_expr
= c_parser_expression (parser
);
7906 rhs_expr
= default_function_array_read_conversion (rhs_loc
, rhs_expr
);
7908 rhs
= rhs_expr
.value
;
7909 rhs
= c_fully_fold (rhs
, false, NULL
);
7912 stmt
= c_finish_omp_atomic (loc
, code
, lhs
, rhs
);
7913 if (stmt
!= error_mark_node
)
7915 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7920 # pragma omp barrier new-line
7924 c_parser_omp_barrier (c_parser
*parser
)
7926 location_t loc
= c_parser_peek_token (parser
)->location
;
7927 c_parser_consume_pragma (parser
);
7928 c_parser_skip_to_pragma_eol (parser
);
7930 c_finish_omp_barrier (loc
);
7934 # pragma omp critical [(name)] new-line
7937 LOC is the location of the #pragma itself. */
7940 c_parser_omp_critical (location_t loc
, c_parser
*parser
)
7942 tree stmt
, name
= NULL
;
7944 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
7946 c_parser_consume_token (parser
);
7947 if (c_parser_next_token_is (parser
, CPP_NAME
))
7949 name
= c_parser_peek_token (parser
)->value
;
7950 c_parser_consume_token (parser
);
7951 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7954 c_parser_error (parser
, "expected identifier");
7956 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
7957 c_parser_error (parser
, "expected %<(%> or end of line");
7958 c_parser_skip_to_pragma_eol (parser
);
7960 stmt
= c_parser_omp_structured_block (parser
);
7961 return c_finish_omp_critical (loc
, stmt
, name
);
7965 # pragma omp flush flush-vars[opt] new-line
7968 ( variable-list ) */
7971 c_parser_omp_flush (c_parser
*parser
)
7973 location_t loc
= c_parser_peek_token (parser
)->location
;
7974 c_parser_consume_pragma (parser
);
7975 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
7976 c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
7977 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
7978 c_parser_error (parser
, "expected %<(%> or end of line");
7979 c_parser_skip_to_pragma_eol (parser
);
7981 c_finish_omp_flush (loc
);
7984 /* Parse the restricted form of the for statement allowed by OpenMP.
7985 The real trick here is to determine the loop control variable early
7986 so that we can push a new decl if necessary to make it private.
7987 LOC is the location of the OMP in "#pragma omp". */
7990 c_parser_omp_for_loop (location_t loc
,
7991 c_parser
*parser
, tree clauses
, tree
*par_clauses
)
7993 tree decl
, cond
, incr
, save_break
, save_cont
, body
, init
, stmt
, cl
;
7994 tree declv
, condv
, incrv
, initv
, for_block
= NULL
, ret
= NULL
;
7995 bool fail
= false, open_brace_parsed
= false;
7996 int i
, collapse
= 1, nbraces
= 0;
7999 for (cl
= clauses
; cl
; cl
= OMP_CLAUSE_CHAIN (cl
))
8000 if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_COLLAPSE
)
8001 collapse
= tree_low_cst (OMP_CLAUSE_COLLAPSE_EXPR (cl
), 0);
8003 gcc_assert (collapse
>= 1);
8005 declv
= make_tree_vec (collapse
);
8006 initv
= make_tree_vec (collapse
);
8007 condv
= make_tree_vec (collapse
);
8008 incrv
= make_tree_vec (collapse
);
8010 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
))
8012 c_parser_error (parser
, "for statement expected");
8015 for_loc
= c_parser_peek_token (parser
)->location
;
8016 c_parser_consume_token (parser
);
8018 for (i
= 0; i
< collapse
; i
++)
8022 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8025 /* Parse the initialization declaration or expression. */
8026 if (c_parser_next_token_starts_declspecs (parser
))
8030 = tree_cons (NULL
, c_begin_compound_stmt (true), for_block
);
8031 c_parser_declaration_or_fndef (parser
, true, true, true, true);
8032 decl
= check_for_loop_decls (for_loc
);
8035 if (DECL_INITIAL (decl
) == error_mark_node
)
8036 decl
= error_mark_node
;
8039 else if (c_parser_next_token_is (parser
, CPP_NAME
)
8040 && c_parser_peek_2nd_token (parser
)->type
== CPP_EQ
)
8042 struct c_expr decl_exp
;
8043 struct c_expr init_exp
;
8044 location_t init_loc
;
8046 decl_exp
= c_parser_postfix_expression (parser
);
8047 decl
= decl_exp
.value
;
8049 c_parser_require (parser
, CPP_EQ
, "expected %<=%>");
8051 init_loc
= c_parser_peek_token (parser
)->location
;
8052 init_exp
= c_parser_expr_no_commas (parser
, NULL
);
8053 init_exp
= default_function_array_read_conversion (init_loc
,
8055 init
= build_modify_expr (init_loc
, decl
, decl_exp
.original_type
,
8056 NOP_EXPR
, init_loc
, init_exp
.value
,
8057 init_exp
.original_type
);
8058 init
= c_process_expr_stmt (init_loc
, init
);
8060 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8065 c_parser_error (parser
,
8066 "expected iteration declaration or initialization");
8067 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
8073 /* Parse the loop condition. */
8075 if (c_parser_next_token_is_not (parser
, CPP_SEMICOLON
))
8077 location_t cond_loc
= c_parser_peek_token (parser
)->location
;
8078 struct c_expr cond_expr
= c_parser_binary_expression (parser
, NULL
);
8080 cond
= cond_expr
.value
;
8081 cond
= c_objc_common_truthvalue_conversion (cond_loc
, cond
);
8082 cond
= c_fully_fold (cond
, false, NULL
);
8083 switch (cond_expr
.original_code
)
8091 /* Can't be cond = error_mark_node, because we want to preserve
8092 the location until c_finish_omp_for. */
8093 cond
= build1 (NOP_EXPR
, boolean_type_node
, error_mark_node
);
8096 protected_set_expr_location (cond
, cond_loc
);
8098 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8100 /* Parse the increment expression. */
8102 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_PAREN
))
8104 location_t incr_loc
= c_parser_peek_token (parser
)->location
;
8106 incr
= c_process_expr_stmt (incr_loc
,
8107 c_parser_expression (parser
).value
);
8109 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8111 if (decl
== NULL
|| decl
== error_mark_node
|| init
== error_mark_node
)
8115 TREE_VEC_ELT (declv
, i
) = decl
;
8116 TREE_VEC_ELT (initv
, i
) = init
;
8117 TREE_VEC_ELT (condv
, i
) = cond
;
8118 TREE_VEC_ELT (incrv
, i
) = incr
;
8122 if (i
== collapse
- 1)
8125 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
8126 in between the collapsed for loops to be still considered perfectly
8127 nested. Hopefully the final version clarifies this.
8128 For now handle (multiple) {'s and empty statements. */
8131 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
8133 c_parser_consume_token (parser
);
8136 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
8138 c_parser_consume_token (parser
);
8142 && c_parser_next_token_is (parser
, CPP_SEMICOLON
))
8143 c_parser_consume_token (parser
);
8146 c_parser_error (parser
, "not enough perfectly nested loops");
8149 open_brace_parsed
= true;
8159 nbraces
+= bracecount
;
8162 save_break
= c_break_label
;
8163 c_break_label
= size_one_node
;
8164 save_cont
= c_cont_label
;
8165 c_cont_label
= NULL_TREE
;
8166 body
= push_stmt_list ();
8168 if (open_brace_parsed
)
8170 location_t here
= c_parser_peek_token (parser
)->location
;
8171 stmt
= c_begin_compound_stmt (true);
8172 c_parser_compound_statement_nostart (parser
);
8173 add_stmt (c_end_compound_stmt (here
, stmt
, true));
8176 add_stmt (c_parser_c99_block_statement (parser
));
8179 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_cont_label
);
8180 SET_EXPR_LOCATION (t
, loc
);
8184 body
= pop_stmt_list (body
);
8185 c_break_label
= save_break
;
8186 c_cont_label
= save_cont
;
8190 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
8192 c_parser_consume_token (parser
);
8195 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
8196 c_parser_consume_token (parser
);
8199 c_parser_error (parser
, "collapsed loops not perfectly nested");
8202 location_t here
= c_parser_peek_token (parser
)->location
;
8203 stmt
= c_begin_compound_stmt (true);
8205 c_parser_compound_statement_nostart (parser
);
8206 body
= c_end_compound_stmt (here
, stmt
, true);
8213 /* Only bother calling c_finish_omp_for if we haven't already generated
8214 an error from the initialization parsing. */
8217 stmt
= c_finish_omp_for (loc
, declv
, initv
, condv
, incrv
, body
, NULL
);
8220 if (par_clauses
!= NULL
)
8223 for (c
= par_clauses
; *c
; )
8224 if (OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_FIRSTPRIVATE
8225 && OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_LASTPRIVATE
)
8226 c
= &OMP_CLAUSE_CHAIN (*c
);
8229 for (i
= 0; i
< collapse
; i
++)
8230 if (TREE_VEC_ELT (declv
, i
) == OMP_CLAUSE_DECL (*c
))
8233 c
= &OMP_CLAUSE_CHAIN (*c
);
8234 else if (OMP_CLAUSE_CODE (*c
) == OMP_CLAUSE_FIRSTPRIVATE
)
8237 "iteration variable %qD should not be firstprivate",
8238 OMP_CLAUSE_DECL (*c
));
8239 *c
= OMP_CLAUSE_CHAIN (*c
);
8243 /* Copy lastprivate (decl) clause to OMP_FOR_CLAUSES,
8244 change it to shared (decl) in
8245 OMP_PARALLEL_CLAUSES. */
8246 tree l
= build_omp_clause (OMP_CLAUSE_LOCATION (*c
),
8247 OMP_CLAUSE_LASTPRIVATE
);
8248 OMP_CLAUSE_DECL (l
) = OMP_CLAUSE_DECL (*c
);
8249 OMP_CLAUSE_CHAIN (l
) = clauses
;
8251 OMP_CLAUSE_SET_CODE (*c
, OMP_CLAUSE_SHARED
);
8255 OMP_FOR_CLAUSES (stmt
) = clauses
;
8262 /* FIXME diagnostics: LOC below should be the actual location of
8263 this particular for block. We need to build a list of
8264 locations to go along with FOR_BLOCK. */
8265 stmt
= c_end_compound_stmt (loc
, TREE_VALUE (for_block
), true);
8267 for_block
= TREE_CHAIN (for_block
);
8273 #pragma omp for for-clause[optseq] new-line
8276 LOC is the location of the #pragma token.
8279 #define OMP_FOR_CLAUSE_MASK \
8280 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8281 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8282 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
8283 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
8284 | (1u << PRAGMA_OMP_CLAUSE_ORDERED) \
8285 | (1u << PRAGMA_OMP_CLAUSE_SCHEDULE) \
8286 | (1u << PRAGMA_OMP_CLAUSE_COLLAPSE) \
8287 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
8290 c_parser_omp_for (location_t loc
, c_parser
*parser
)
8292 tree block
, clauses
, ret
;
8294 clauses
= c_parser_omp_all_clauses (parser
, OMP_FOR_CLAUSE_MASK
,
8297 block
= c_begin_compound_stmt (true);
8298 ret
= c_parser_omp_for_loop (loc
, parser
, clauses
, NULL
);
8299 block
= c_end_compound_stmt (loc
, block
, true);
8306 # pragma omp master new-line
8309 LOC is the location of the #pragma token.
8313 c_parser_omp_master (location_t loc
, c_parser
*parser
)
8315 c_parser_skip_to_pragma_eol (parser
);
8316 return c_finish_omp_master (loc
, c_parser_omp_structured_block (parser
));
8320 # pragma omp ordered new-line
8323 LOC is the location of the #pragma itself.
8327 c_parser_omp_ordered (location_t loc
, c_parser
*parser
)
8329 c_parser_skip_to_pragma_eol (parser
);
8330 return c_finish_omp_ordered (loc
, c_parser_omp_structured_block (parser
));
8336 { section-sequence }
8339 section-directive[opt] structured-block
8340 section-sequence section-directive structured-block
8342 SECTIONS_LOC is the location of the #pragma omp sections. */
8345 c_parser_omp_sections_scope (location_t sections_loc
, c_parser
*parser
)
8348 bool error_suppress
= false;
8351 loc
= c_parser_peek_token (parser
)->location
;
8352 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
8354 /* Avoid skipping until the end of the block. */
8355 parser
->error
= false;
8359 stmt
= push_stmt_list ();
8361 if (c_parser_peek_token (parser
)->pragma_kind
!= PRAGMA_OMP_SECTION
)
8363 substmt
= push_stmt_list ();
8367 c_parser_statement (parser
);
8369 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
8371 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
8373 if (c_parser_next_token_is (parser
, CPP_EOF
))
8377 substmt
= pop_stmt_list (substmt
);
8378 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
8379 SET_EXPR_LOCATION (substmt
, loc
);
8385 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
8387 if (c_parser_next_token_is (parser
, CPP_EOF
))
8390 loc
= c_parser_peek_token (parser
)->location
;
8391 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
8393 c_parser_consume_pragma (parser
);
8394 c_parser_skip_to_pragma_eol (parser
);
8395 error_suppress
= false;
8397 else if (!error_suppress
)
8399 error_at (loc
, "expected %<#pragma omp section%> or %<}%>");
8400 error_suppress
= true;
8403 substmt
= c_parser_omp_structured_block (parser
);
8404 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
8405 SET_EXPR_LOCATION (substmt
, loc
);
8408 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
,
8409 "expected %<#pragma omp section%> or %<}%>");
8411 substmt
= pop_stmt_list (stmt
);
8413 stmt
= make_node (OMP_SECTIONS
);
8414 SET_EXPR_LOCATION (stmt
, sections_loc
);
8415 TREE_TYPE (stmt
) = void_type_node
;
8416 OMP_SECTIONS_BODY (stmt
) = substmt
;
8418 return add_stmt (stmt
);
8422 # pragma omp sections sections-clause[optseq] newline
8425 LOC is the location of the #pragma token.
8428 #define OMP_SECTIONS_CLAUSE_MASK \
8429 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8430 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8431 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
8432 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
8433 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
8436 c_parser_omp_sections (location_t loc
, c_parser
*parser
)
8438 tree block
, clauses
, ret
;
8440 clauses
= c_parser_omp_all_clauses (parser
, OMP_SECTIONS_CLAUSE_MASK
,
8441 "#pragma omp sections");
8443 block
= c_begin_compound_stmt (true);
8444 ret
= c_parser_omp_sections_scope (loc
, parser
);
8446 OMP_SECTIONS_CLAUSES (ret
) = clauses
;
8447 block
= c_end_compound_stmt (loc
, block
, true);
8454 # pragma parallel parallel-clause new-line
8455 # pragma parallel for parallel-for-clause new-line
8456 # pragma parallel sections parallel-sections-clause new-line
8458 LOC is the location of the #pragma token.
8461 #define OMP_PARALLEL_CLAUSE_MASK \
8462 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
8463 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8464 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8465 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
8466 | (1u << PRAGMA_OMP_CLAUSE_SHARED) \
8467 | (1u << PRAGMA_OMP_CLAUSE_COPYIN) \
8468 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
8469 | (1u << PRAGMA_OMP_CLAUSE_NUM_THREADS))
8472 c_parser_omp_parallel (location_t loc
, c_parser
*parser
)
8474 enum pragma_kind p_kind
= PRAGMA_OMP_PARALLEL
;
8475 const char *p_name
= "#pragma omp parallel";
8476 tree stmt
, clauses
, par_clause
, ws_clause
, block
;
8477 unsigned int mask
= OMP_PARALLEL_CLAUSE_MASK
;
8479 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
8481 c_parser_consume_token (parser
);
8482 p_kind
= PRAGMA_OMP_PARALLEL_FOR
;
8483 p_name
= "#pragma omp parallel for";
8484 mask
|= OMP_FOR_CLAUSE_MASK
;
8485 mask
&= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT
);
8487 else if (c_parser_next_token_is (parser
, CPP_NAME
))
8489 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
8490 if (strcmp (p
, "sections") == 0)
8492 c_parser_consume_token (parser
);
8493 p_kind
= PRAGMA_OMP_PARALLEL_SECTIONS
;
8494 p_name
= "#pragma omp parallel sections";
8495 mask
|= OMP_SECTIONS_CLAUSE_MASK
;
8496 mask
&= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT
);
8500 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
);
8504 case PRAGMA_OMP_PARALLEL
:
8505 block
= c_begin_omp_parallel ();
8506 c_parser_statement (parser
);
8507 stmt
= c_finish_omp_parallel (loc
, clauses
, block
);
8510 case PRAGMA_OMP_PARALLEL_FOR
:
8511 block
= c_begin_omp_parallel ();
8512 c_split_parallel_clauses (loc
, clauses
, &par_clause
, &ws_clause
);
8513 c_parser_omp_for_loop (loc
, parser
, ws_clause
, &par_clause
);
8514 stmt
= c_finish_omp_parallel (loc
, par_clause
, block
);
8515 OMP_PARALLEL_COMBINED (stmt
) = 1;
8518 case PRAGMA_OMP_PARALLEL_SECTIONS
:
8519 block
= c_begin_omp_parallel ();
8520 c_split_parallel_clauses (loc
, clauses
, &par_clause
, &ws_clause
);
8521 stmt
= c_parser_omp_sections_scope (loc
, parser
);
8523 OMP_SECTIONS_CLAUSES (stmt
) = ws_clause
;
8524 stmt
= c_finish_omp_parallel (loc
, par_clause
, block
);
8525 OMP_PARALLEL_COMBINED (stmt
) = 1;
8536 # pragma omp single single-clause[optseq] new-line
8539 LOC is the location of the #pragma.
8542 #define OMP_SINGLE_CLAUSE_MASK \
8543 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8544 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8545 | (1u << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
8546 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
8549 c_parser_omp_single (location_t loc
, c_parser
*parser
)
8551 tree stmt
= make_node (OMP_SINGLE
);
8552 SET_EXPR_LOCATION (stmt
, loc
);
8553 TREE_TYPE (stmt
) = void_type_node
;
8555 OMP_SINGLE_CLAUSES (stmt
)
8556 = c_parser_omp_all_clauses (parser
, OMP_SINGLE_CLAUSE_MASK
,
8557 "#pragma omp single");
8558 OMP_SINGLE_BODY (stmt
) = c_parser_omp_structured_block (parser
);
8560 return add_stmt (stmt
);
8564 # pragma omp task task-clause[optseq] new-line
8566 LOC is the location of the #pragma.
8569 #define OMP_TASK_CLAUSE_MASK \
8570 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
8571 | (1u << PRAGMA_OMP_CLAUSE_UNTIED) \
8572 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
8573 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8574 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8575 | (1u << PRAGMA_OMP_CLAUSE_SHARED))
8578 c_parser_omp_task (location_t loc
, c_parser
*parser
)
8580 tree clauses
, block
;
8582 clauses
= c_parser_omp_all_clauses (parser
, OMP_TASK_CLAUSE_MASK
,
8583 "#pragma omp task");
8585 block
= c_begin_omp_task ();
8586 c_parser_statement (parser
);
8587 return c_finish_omp_task (loc
, clauses
, block
);
8591 # pragma omp taskwait new-line
8595 c_parser_omp_taskwait (c_parser
*parser
)
8597 location_t loc
= c_parser_peek_token (parser
)->location
;
8598 c_parser_consume_pragma (parser
);
8599 c_parser_skip_to_pragma_eol (parser
);
8601 c_finish_omp_taskwait (loc
);
8604 /* Main entry point to parsing most OpenMP pragmas. */
8607 c_parser_omp_construct (c_parser
*parser
)
8609 enum pragma_kind p_kind
;
8613 loc
= c_parser_peek_token (parser
)->location
;
8614 p_kind
= c_parser_peek_token (parser
)->pragma_kind
;
8615 c_parser_consume_pragma (parser
);
8619 case PRAGMA_OMP_ATOMIC
:
8620 c_parser_omp_atomic (loc
, parser
);
8622 case PRAGMA_OMP_CRITICAL
:
8623 stmt
= c_parser_omp_critical (loc
, parser
);
8625 case PRAGMA_OMP_FOR
:
8626 stmt
= c_parser_omp_for (loc
, parser
);
8628 case PRAGMA_OMP_MASTER
:
8629 stmt
= c_parser_omp_master (loc
, parser
);
8631 case PRAGMA_OMP_ORDERED
:
8632 stmt
= c_parser_omp_ordered (loc
, parser
);
8634 case PRAGMA_OMP_PARALLEL
:
8635 stmt
= c_parser_omp_parallel (loc
, parser
);
8637 case PRAGMA_OMP_SECTIONS
:
8638 stmt
= c_parser_omp_sections (loc
, parser
);
8640 case PRAGMA_OMP_SINGLE
:
8641 stmt
= c_parser_omp_single (loc
, parser
);
8643 case PRAGMA_OMP_TASK
:
8644 stmt
= c_parser_omp_task (loc
, parser
);
8651 gcc_assert (EXPR_LOCATION (stmt
) != UNKNOWN_LOCATION
);
8656 # pragma omp threadprivate (variable-list) */
8659 c_parser_omp_threadprivate (c_parser
*parser
)
8664 c_parser_consume_pragma (parser
);
8665 loc
= c_parser_peek_token (parser
)->location
;
8666 vars
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
8668 /* Mark every variable in VARS to be assigned thread local storage. */
8669 for (t
= vars
; t
; t
= TREE_CHAIN (t
))
8671 tree v
= TREE_PURPOSE (t
);
8673 /* FIXME diagnostics: Ideally we should keep individual
8674 locations for all the variables in the var list to make the
8675 following errors more precise. Perhaps
8676 c_parser_omp_var_list_parens() should construct a list of
8677 locations to go along with the var list. */
8679 /* If V had already been marked threadprivate, it doesn't matter
8680 whether it had been used prior to this point. */
8681 if (TREE_CODE (v
) != VAR_DECL
)
8682 error_at (loc
, "%qD is not a variable", v
);
8683 else if (TREE_USED (v
) && !C_DECL_THREADPRIVATE_P (v
))
8684 error_at (loc
, "%qE declared %<threadprivate%> after first use", v
);
8685 else if (! TREE_STATIC (v
) && ! DECL_EXTERNAL (v
))
8686 error_at (loc
, "automatic variable %qE cannot be %<threadprivate%>", v
);
8687 else if (TREE_TYPE (v
) == error_mark_node
)
8689 else if (! COMPLETE_TYPE_P (TREE_TYPE (v
)))
8690 error_at (loc
, "%<threadprivate%> %qE has incomplete type", v
);
8693 if (! DECL_THREAD_LOCAL_P (v
))
8695 DECL_TLS_MODEL (v
) = decl_default_tls_model (v
);
8696 /* If rtl has been already set for this var, call
8697 make_decl_rtl once again, so that encode_section_info
8698 has a chance to look at the new decl flags. */
8699 if (DECL_RTL_SET_P (v
))
8702 C_DECL_THREADPRIVATE_P (v
) = 1;
8706 c_parser_skip_to_pragma_eol (parser
);
8710 /* Parse a single source file. */
8715 /* Use local storage to begin. If the first token is a pragma, parse it.
8716 If it is #pragma GCC pch_preprocess, then this will load a PCH file
8717 which will cause garbage collection. */
8720 memset (&tparser
, 0, sizeof tparser
);
8721 the_parser
= &tparser
;
8723 if (c_parser_peek_token (&tparser
)->pragma_kind
== PRAGMA_GCC_PCH_PREPROCESS
)
8724 c_parser_pragma_pch_preprocess (&tparser
);
8726 the_parser
= GGC_NEW (c_parser
);
8727 *the_parser
= tparser
;
8729 /* Initialize EH, if we've been told to do so. */
8730 if (flag_exceptions
)
8731 using_eh_for_cleanups ();
8733 c_parser_translation_unit (the_parser
);
8737 #include "gt-c-parser.h"