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
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 ret
.spec
= TREE_TYPE (expr
.value
);
2175 was_vm
= variably_modified_type_p (ret
.spec
, NULL_TREE
);
2176 /* This is returned with the type so that when the type is
2177 evaluated, this can be evaluated. */
2179 ret
.expr
= c_fully_fold (expr
.value
, false, &ret
.expr_const_operands
);
2180 pop_maybe_used (was_vm
);
2182 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
2186 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
2187 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
2188 be redeclared; otherwise it may not. KIND indicates which kind of
2189 declarator is wanted. Returns a valid declarator except in the
2190 case of a syntax error in which case NULL is returned. *SEEN_ID is
2191 set to true if an identifier being declared is seen; this is used
2192 to diagnose bad forms of abstract array declarators and to
2193 determine whether an identifier list is syntactically permitted.
2196 pointer[opt] direct-declarator
2200 ( attributes[opt] declarator )
2201 direct-declarator array-declarator
2202 direct-declarator ( parameter-type-list )
2203 direct-declarator ( identifier-list[opt] )
2206 * type-qualifier-list[opt]
2207 * type-qualifier-list[opt] pointer
2209 type-qualifier-list:
2212 type-qualifier-list type-qualifier
2213 type-qualifier-list attributes
2215 parameter-type-list:
2217 parameter-list , ...
2220 parameter-declaration
2221 parameter-list , parameter-declaration
2223 parameter-declaration:
2224 declaration-specifiers declarator attributes[opt]
2225 declaration-specifiers abstract-declarator[opt] attributes[opt]
2229 identifier-list , identifier
2231 abstract-declarator:
2233 pointer[opt] direct-abstract-declarator
2235 direct-abstract-declarator:
2236 ( attributes[opt] abstract-declarator )
2237 direct-abstract-declarator[opt] array-declarator
2238 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
2243 direct-declarator ( parameter-forward-declarations
2244 parameter-type-list[opt] )
2246 direct-abstract-declarator:
2247 direct-abstract-declarator[opt] ( parameter-forward-declarations
2248 parameter-type-list[opt] )
2250 parameter-forward-declarations:
2252 parameter-forward-declarations parameter-list ;
2254 The uses of attributes shown above are GNU extensions.
2256 Some forms of array declarator are not included in C99 in the
2257 syntax for abstract declarators; these are disallowed elsewhere.
2258 This may be a defect (DR#289).
2260 This function also accepts an omitted abstract declarator as being
2261 an abstract declarator, although not part of the formal syntax. */
2263 static struct c_declarator
*
2264 c_parser_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
2267 /* Parse any initial pointer part. */
2268 if (c_parser_next_token_is (parser
, CPP_MULT
))
2270 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
2271 struct c_declarator
*inner
;
2272 c_parser_consume_token (parser
);
2273 c_parser_declspecs (parser
, quals_attrs
, false, false, true);
2274 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
2278 return make_pointer_declarator (quals_attrs
, inner
);
2280 /* Now we have a direct declarator, direct abstract declarator or
2281 nothing (which counts as a direct abstract declarator here). */
2282 return c_parser_direct_declarator (parser
, type_seen_p
, kind
, seen_id
);
2285 /* Parse a direct declarator or direct abstract declarator; arguments
2286 as c_parser_declarator. */
2288 static struct c_declarator
*
2289 c_parser_direct_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
2292 /* The direct declarator must start with an identifier (possibly
2293 omitted) or a parenthesized declarator (possibly abstract). In
2294 an ordinary declarator, initial parentheses must start a
2295 parenthesized declarator. In an abstract declarator or parameter
2296 declarator, they could start a parenthesized declarator or a
2297 parameter list. To tell which, the open parenthesis and any
2298 following attributes must be read. If a declaration specifier
2299 follows, then it is a parameter list; if the specifier is a
2300 typedef name, there might be an ambiguity about redeclaring it,
2301 which is resolved in the direction of treating it as a typedef
2302 name. If a close parenthesis follows, it is also an empty
2303 parameter list, as the syntax does not permit empty abstract
2304 declarators. Otherwise, it is a parenthesized declarator (in
2305 which case the analysis may be repeated inside it, recursively).
2307 ??? There is an ambiguity in a parameter declaration "int
2308 (__attribute__((foo)) x)", where x is not a typedef name: it
2309 could be an abstract declarator for a function, or declare x with
2310 parentheses. The proper resolution of this ambiguity needs
2311 documenting. At present we follow an accident of the old
2312 parser's implementation, whereby the first parameter must have
2313 some declaration specifiers other than just attributes. Thus as
2314 a parameter declaration it is treated as a parenthesized
2315 parameter named x, and as an abstract declarator it is
2318 ??? Also following the old parser, attributes inside an empty
2319 parameter list are ignored, making it a list not yielding a
2320 prototype, rather than giving an error or making it have one
2321 parameter with implicit type int.
2323 ??? Also following the old parser, typedef names may be
2324 redeclared in declarators, but not Objective-C class names. */
2326 if (kind
!= C_DTR_ABSTRACT
2327 && c_parser_next_token_is (parser
, CPP_NAME
)
2329 && c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
)
2330 || c_parser_peek_token (parser
)->id_kind
== C_ID_ID
))
2332 struct c_declarator
*inner
2333 = build_id_declarator (c_parser_peek_token (parser
)->value
);
2335 inner
->id_loc
= c_parser_peek_token (parser
)->location
;
2336 c_parser_consume_token (parser
);
2337 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
2340 if (kind
!= C_DTR_NORMAL
2341 && c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
2343 struct c_declarator
*inner
= build_id_declarator (NULL_TREE
);
2344 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
2347 /* Either we are at the end of an abstract declarator, or we have
2350 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
2353 struct c_declarator
*inner
;
2354 c_parser_consume_token (parser
);
2355 attrs
= c_parser_attributes (parser
);
2356 if (kind
!= C_DTR_NORMAL
2357 && (c_parser_next_token_starts_declspecs (parser
)
2358 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
)))
2360 struct c_arg_info
*args
2361 = c_parser_parms_declarator (parser
, kind
== C_DTR_NORMAL
,
2368 = build_function_declarator (args
,
2369 build_id_declarator (NULL_TREE
));
2370 return c_parser_direct_declarator_inner (parser
, *seen_id
,
2374 /* A parenthesized declarator. */
2375 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
2376 if (inner
!= NULL
&& attrs
!= NULL
)
2377 inner
= build_attrs_declarator (attrs
, inner
);
2378 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2380 c_parser_consume_token (parser
);
2384 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
2388 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2395 if (kind
== C_DTR_NORMAL
)
2397 c_parser_error (parser
, "expected identifier or %<(%>");
2401 return build_id_declarator (NULL_TREE
);
2405 /* Parse part of a direct declarator or direct abstract declarator,
2406 given that some (in INNER) has already been parsed; ID_PRESENT is
2407 true if an identifier is present, false for an abstract
2410 static struct c_declarator
*
2411 c_parser_direct_declarator_inner (c_parser
*parser
, bool id_present
,
2412 struct c_declarator
*inner
)
2414 /* Parse a sequence of array declarators and parameter lists. */
2415 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
2417 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
2418 struct c_declarator
*declarator
;
2419 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
2423 c_parser_consume_token (parser
);
2424 c_parser_declspecs (parser
, quals_attrs
, false, false, true);
2425 static_seen
= c_parser_next_token_is_keyword (parser
, RID_STATIC
);
2427 c_parser_consume_token (parser
);
2428 if (static_seen
&& !quals_attrs
->declspecs_seen_p
)
2429 c_parser_declspecs (parser
, quals_attrs
, false, false, true);
2430 if (!quals_attrs
->declspecs_seen_p
)
2432 /* If "static" is present, there must be an array dimension.
2433 Otherwise, there may be a dimension, "*", or no
2438 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
2442 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
2447 else if (c_parser_next_token_is (parser
, CPP_MULT
))
2449 if (c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_SQUARE
)
2453 c_parser_consume_token (parser
);
2458 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
2464 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
2467 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
2468 c_parser_consume_token (parser
);
2471 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
2475 declarator
= build_array_declarator (brace_loc
, dimen
, quals_attrs
,
2476 static_seen
, star_seen
);
2477 if (declarator
== NULL
)
2479 inner
= set_array_declarator_inner (declarator
, inner
);
2480 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
2482 else if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
2485 struct c_arg_info
*args
;
2486 c_parser_consume_token (parser
);
2487 attrs
= c_parser_attributes (parser
);
2488 args
= c_parser_parms_declarator (parser
, id_present
, attrs
);
2493 inner
= build_function_declarator (args
, inner
);
2494 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
2500 /* Parse a parameter list or identifier list, including the closing
2501 parenthesis but not the opening one. ATTRS are the attributes at
2502 the start of the list. ID_LIST_OK is true if an identifier list is
2503 acceptable; such a list must not have attributes at the start. */
2505 static struct c_arg_info
*
2506 c_parser_parms_declarator (c_parser
*parser
, bool id_list_ok
, tree attrs
)
2509 declare_parm_level ();
2510 /* If the list starts with an identifier, it is an identifier list.
2511 Otherwise, it is either a prototype list or an empty list. */
2514 && c_parser_next_token_is (parser
, CPP_NAME
)
2515 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
2517 tree list
= NULL_TREE
, *nextp
= &list
;
2518 while (c_parser_next_token_is (parser
, CPP_NAME
)
2519 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
2521 *nextp
= build_tree_list (NULL_TREE
,
2522 c_parser_peek_token (parser
)->value
);
2523 nextp
= & TREE_CHAIN (*nextp
);
2524 c_parser_consume_token (parser
);
2525 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
2527 c_parser_consume_token (parser
);
2528 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2530 c_parser_error (parser
, "expected identifier");
2534 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2536 struct c_arg_info
*ret
= XOBNEW (&parser_obstack
, struct c_arg_info
);
2541 ret
->pending_sizes
= 0;
2542 ret
->had_vla_unspec
= 0;
2543 c_parser_consume_token (parser
);
2549 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2557 struct c_arg_info
*ret
= c_parser_parms_list_declarator (parser
, attrs
);
2563 /* Parse a parameter list (possibly empty), including the closing
2564 parenthesis but not the opening one. ATTRS are the attributes at
2565 the start of the list. */
2567 static struct c_arg_info
*
2568 c_parser_parms_list_declarator (c_parser
*parser
, tree attrs
)
2570 bool good_parm
= false;
2571 /* ??? Following the old parser, forward parameter declarations may
2572 use abstract declarators, and if no real parameter declarations
2573 follow the forward declarations then this is not diagnosed. Also
2574 note as above that attributes are ignored as the only contents of
2575 the parentheses, or as the only contents after forward
2577 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2579 struct c_arg_info
*ret
= XOBNEW (&parser_obstack
, struct c_arg_info
);
2584 ret
->pending_sizes
= 0;
2585 ret
->had_vla_unspec
= 0;
2586 c_parser_consume_token (parser
);
2589 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
2591 struct c_arg_info
*ret
= XOBNEW (&parser_obstack
, struct c_arg_info
);
2595 ret
->pending_sizes
= 0;
2596 ret
->had_vla_unspec
= 0;
2597 /* Suppress -Wold-style-definition for this case. */
2598 ret
->types
= error_mark_node
;
2599 error_at (c_parser_peek_token (parser
)->location
,
2600 "ISO C requires a named argument before %<...%>");
2601 c_parser_consume_token (parser
);
2602 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2604 c_parser_consume_token (parser
);
2609 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2614 /* Nonempty list of parameters, either terminated with semicolon
2615 (forward declarations; recurse) or with close parenthesis (normal
2616 function) or with ", ... )" (variadic function). */
2619 /* Parse a parameter. */
2620 struct c_parm
*parm
= c_parser_parameter_declaration (parser
, attrs
);
2625 push_parm_decl (parm
);
2627 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2630 c_parser_consume_token (parser
);
2631 mark_forward_parm_decls ();
2632 new_attrs
= c_parser_attributes (parser
);
2633 return c_parser_parms_list_declarator (parser
, new_attrs
);
2635 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2637 c_parser_consume_token (parser
);
2639 return get_parm_info (false);
2642 struct c_arg_info
*ret
2643 = XOBNEW (&parser_obstack
, struct c_arg_info
);
2648 ret
->pending_sizes
= 0;
2649 ret
->had_vla_unspec
= 0;
2653 if (!c_parser_require (parser
, CPP_COMMA
,
2654 "expected %<;%>, %<,%> or %<)%>"))
2656 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2657 get_pending_sizes ();
2660 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
2662 c_parser_consume_token (parser
);
2663 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2665 c_parser_consume_token (parser
);
2667 return get_parm_info (true);
2670 struct c_arg_info
*ret
2671 = XOBNEW (&parser_obstack
, struct c_arg_info
);
2676 ret
->pending_sizes
= 0;
2677 ret
->had_vla_unspec
= 0;
2683 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2685 get_pending_sizes ();
2692 /* Parse a parameter declaration. ATTRS are the attributes at the
2693 start of the declaration if it is the first parameter. */
2695 static struct c_parm
*
2696 c_parser_parameter_declaration (c_parser
*parser
, tree attrs
)
2698 struct c_declspecs
*specs
;
2699 struct c_declarator
*declarator
;
2701 tree postfix_attrs
= NULL_TREE
;
2703 if (!c_parser_next_token_starts_declspecs (parser
))
2705 /* ??? In some Objective-C cases '...' isn't applicable so there
2706 should be a different message. */
2707 c_parser_error (parser
,
2708 "expected declaration specifiers or %<...%>");
2709 c_parser_skip_to_end_of_parameter (parser
);
2712 specs
= build_null_declspecs ();
2715 declspecs_add_attrs (specs
, attrs
);
2718 c_parser_declspecs (parser
, specs
, true, true, true);
2719 finish_declspecs (specs
);
2720 pending_xref_error ();
2721 prefix_attrs
= specs
->attrs
;
2722 specs
->attrs
= NULL_TREE
;
2723 declarator
= c_parser_declarator (parser
, specs
->type_seen_p
,
2724 C_DTR_PARM
, &dummy
);
2725 if (declarator
== NULL
)
2727 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
2730 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2731 postfix_attrs
= c_parser_attributes (parser
);
2732 return build_c_parm (specs
, chainon (postfix_attrs
, prefix_attrs
),
2736 /* Parse a string literal in an asm expression. It should not be
2737 translated, and wide string literals are an error although
2738 permitted by the syntax. This is a GNU extension.
2743 ??? At present, following the old parser, the caller needs to have
2744 set lex_untranslated_string to 1. It would be better to follow the
2745 C++ parser rather than using this kludge. */
2748 c_parser_asm_string_literal (c_parser
*parser
)
2751 if (c_parser_next_token_is (parser
, CPP_STRING
))
2753 str
= c_parser_peek_token (parser
)->value
;
2754 c_parser_consume_token (parser
);
2756 else if (c_parser_next_token_is (parser
, CPP_WSTRING
))
2758 error_at (c_parser_peek_token (parser
)->location
,
2759 "wide string literal in %<asm%>");
2760 str
= build_string (1, "");
2761 c_parser_consume_token (parser
);
2765 c_parser_error (parser
, "expected string literal");
2771 /* Parse a simple asm expression. This is used in restricted
2772 contexts, where a full expression with inputs and outputs does not
2773 make sense. This is a GNU extension.
2776 asm ( asm-string-literal )
2780 c_parser_simple_asm_expr (c_parser
*parser
)
2783 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
2784 /* ??? Follow the C++ parser rather than using the
2785 lex_untranslated_string kludge. */
2786 parser
->lex_untranslated_string
= true;
2787 c_parser_consume_token (parser
);
2788 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2790 parser
->lex_untranslated_string
= false;
2793 str
= c_parser_asm_string_literal (parser
);
2794 parser
->lex_untranslated_string
= false;
2795 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
2797 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2803 /* Parse (possibly empty) attributes. This is a GNU extension.
2807 attributes attribute
2810 __attribute__ ( ( attribute-list ) )
2814 attribute_list , attrib
2819 any-word ( identifier )
2820 any-word ( identifier , nonempty-expr-list )
2821 any-word ( expr-list )
2823 where the "identifier" must not be declared as a type, and
2824 "any-word" may be any identifier (including one declared as a
2825 type), a reserved word storage class specifier, type specifier or
2826 type qualifier. ??? This still leaves out most reserved keywords
2827 (following the old parser), shouldn't we include them, and why not
2828 allow identifiers declared as types to start the arguments? */
2831 c_parser_attributes (c_parser
*parser
)
2833 tree attrs
= NULL_TREE
;
2834 while (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2836 /* ??? Follow the C++ parser rather than using the
2837 lex_untranslated_string kludge. */
2838 parser
->lex_untranslated_string
= true;
2839 c_parser_consume_token (parser
);
2840 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2842 parser
->lex_untranslated_string
= false;
2845 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2847 parser
->lex_untranslated_string
= false;
2848 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2851 /* Parse the attribute list. */
2852 while (c_parser_next_token_is (parser
, CPP_COMMA
)
2853 || c_parser_next_token_is (parser
, CPP_NAME
)
2854 || c_parser_next_token_is (parser
, CPP_KEYWORD
))
2856 tree attr
, attr_name
, attr_args
;
2857 VEC(tree
,gc
) *expr_list
;
2858 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2860 c_parser_consume_token (parser
);
2863 if (c_parser_next_token_is (parser
, CPP_KEYWORD
))
2865 /* ??? See comment above about what keywords are
2868 switch (c_parser_peek_token (parser
)->keyword
)
2905 /* Accept __attribute__((__const)) as __attribute__((const))
2908 = ridpointers
[(int) c_parser_peek_token (parser
)->keyword
];
2911 attr_name
= c_parser_peek_token (parser
)->value
;
2912 c_parser_consume_token (parser
);
2913 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
2915 attr
= build_tree_list (attr_name
, NULL_TREE
);
2916 attrs
= chainon (attrs
, attr
);
2919 c_parser_consume_token (parser
);
2920 /* Parse the attribute contents. If they start with an
2921 identifier which is followed by a comma or close
2922 parenthesis, then the arguments start with that
2923 identifier; otherwise they are an expression list. */
2924 if (c_parser_next_token_is (parser
, CPP_NAME
)
2925 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
2926 && ((c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
)
2927 || (c_parser_peek_2nd_token (parser
)->type
2928 == CPP_CLOSE_PAREN
)))
2930 tree arg1
= c_parser_peek_token (parser
)->value
;
2931 c_parser_consume_token (parser
);
2932 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2933 attr_args
= build_tree_list (NULL_TREE
, arg1
);
2937 c_parser_consume_token (parser
);
2938 expr_list
= c_parser_expr_list (parser
, false, true, NULL
);
2939 tree_list
= build_tree_list_vec (expr_list
);
2940 attr_args
= tree_cons (NULL_TREE
, arg1
, tree_list
);
2941 release_tree_vector (expr_list
);
2946 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2947 attr_args
= NULL_TREE
;
2950 expr_list
= c_parser_expr_list (parser
, false, true, NULL
);
2951 attr_args
= build_tree_list_vec (expr_list
);
2952 release_tree_vector (expr_list
);
2955 attr
= build_tree_list (attr_name
, attr_args
);
2956 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2957 c_parser_consume_token (parser
);
2960 parser
->lex_untranslated_string
= false;
2961 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2965 attrs
= chainon (attrs
, attr
);
2967 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2968 c_parser_consume_token (parser
);
2971 parser
->lex_untranslated_string
= false;
2972 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2976 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2977 c_parser_consume_token (parser
);
2980 parser
->lex_untranslated_string
= false;
2981 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2985 parser
->lex_untranslated_string
= false;
2990 /* Parse a type name (C90 6.5.5, C99 6.7.6).
2993 specifier-qualifier-list abstract-declarator[opt]
2996 static struct c_type_name
*
2997 c_parser_type_name (c_parser
*parser
)
2999 struct c_declspecs
*specs
= build_null_declspecs ();
3000 struct c_declarator
*declarator
;
3001 struct c_type_name
*ret
;
3003 c_parser_declspecs (parser
, specs
, false, true, true);
3004 if (!specs
->declspecs_seen_p
)
3006 c_parser_error (parser
, "expected specifier-qualifier-list");
3009 pending_xref_error ();
3010 finish_declspecs (specs
);
3011 declarator
= c_parser_declarator (parser
, specs
->type_seen_p
,
3012 C_DTR_ABSTRACT
, &dummy
);
3013 if (declarator
== NULL
)
3015 ret
= XOBNEW (&parser_obstack
, struct c_type_name
);
3017 ret
->declarator
= declarator
;
3021 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
3024 assignment-expression
3025 { initializer-list }
3026 { initializer-list , }
3029 designation[opt] initializer
3030 initializer-list , designation[opt] initializer
3037 designator-list designator
3044 [ constant-expression ]
3056 [ constant-expression ... constant-expression ]
3058 Any expression without commas is accepted in the syntax for the
3059 constant-expressions, with non-constant expressions rejected later.
3061 This function is only used for top-level initializers; for nested
3062 ones, see c_parser_initval. */
3064 static struct c_expr
3065 c_parser_initializer (c_parser
*parser
)
3067 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
3068 return c_parser_braced_init (parser
, NULL_TREE
, false);
3072 location_t loc
= c_parser_peek_token (parser
)->location
;
3073 ret
= c_parser_expr_no_commas (parser
, NULL
);
3074 if (TREE_CODE (ret
.value
) != STRING_CST
3075 && TREE_CODE (ret
.value
) != COMPOUND_LITERAL_EXPR
)
3076 ret
= default_function_array_conversion (loc
, ret
);
3081 /* Parse a braced initializer list. TYPE is the type specified for a
3082 compound literal, and NULL_TREE for other initializers and for
3083 nested braced lists. NESTED_P is true for nested braced lists,
3084 false for the list of a compound literal or the list that is the
3085 top-level initializer in a declaration. */
3087 static struct c_expr
3088 c_parser_braced_init (c_parser
*parser
, tree type
, bool nested_p
)
3090 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
3091 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
3092 c_parser_consume_token (parser
);
3094 push_init_level (0);
3096 really_start_incremental_init (type
);
3097 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3099 pedwarn (brace_loc
, OPT_pedantic
, "ISO C forbids empty initializer braces");
3103 /* Parse a non-empty initializer list, possibly with a trailing
3107 c_parser_initelt (parser
);
3110 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3111 c_parser_consume_token (parser
);
3114 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3118 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
3121 ret
.value
= error_mark_node
;
3122 ret
.original_code
= ERROR_MARK
;
3123 ret
.original_type
= NULL
;
3124 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
3128 c_parser_consume_token (parser
);
3129 return pop_init_level (0);
3132 /* Parse a nested initializer, including designators. */
3135 c_parser_initelt (c_parser
*parser
)
3137 /* Parse any designator or designator list. A single array
3138 designator may have the subsequent "=" omitted in GNU C, but a
3139 longer list or a structure member designator may not. */
3140 if (c_parser_next_token_is (parser
, CPP_NAME
)
3141 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
3143 /* Old-style structure member designator. */
3144 set_init_label (c_parser_peek_token (parser
)->value
);
3145 /* Use the colon as the error location. */
3146 pedwarn (c_parser_peek_2nd_token (parser
)->location
, OPT_pedantic
,
3147 "obsolete use of designated initializer with %<:%>");
3148 c_parser_consume_token (parser
);
3149 c_parser_consume_token (parser
);
3153 /* des_seen is 0 if there have been no designators, 1 if there
3154 has been a single array designator and 2 otherwise. */
3156 /* Location of a designator. */
3157 location_t des_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
3158 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
)
3159 || c_parser_next_token_is (parser
, CPP_DOT
))
3161 int des_prev
= des_seen
;
3163 des_loc
= c_parser_peek_token (parser
)->location
;
3166 if (c_parser_next_token_is (parser
, CPP_DOT
))
3169 c_parser_consume_token (parser
);
3170 if (c_parser_next_token_is (parser
, CPP_NAME
))
3172 set_init_label (c_parser_peek_token (parser
)->value
);
3173 c_parser_consume_token (parser
);
3178 init
.value
= error_mark_node
;
3179 init
.original_code
= ERROR_MARK
;
3180 init
.original_type
= NULL
;
3181 c_parser_error (parser
, "expected identifier");
3182 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3183 process_init_element (init
, false);
3190 location_t ellipsis_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
3191 /* ??? Following the old parser, [ objc-receiver
3192 objc-message-args ] is accepted as an initializer,
3193 being distinguished from a designator by what follows
3194 the first assignment expression inside the square
3195 brackets, but after a first array designator a
3196 subsequent square bracket is for Objective-C taken to
3197 start an expression, using the obsolete form of
3198 designated initializer without '=', rather than
3199 possibly being a second level of designation: in LALR
3200 terms, the '[' is shifted rather than reducing
3201 designator to designator-list. */
3202 if (des_prev
== 1 && c_dialect_objc ())
3204 des_seen
= des_prev
;
3207 if (des_prev
== 0 && c_dialect_objc ())
3209 /* This might be an array designator or an
3210 Objective-C message expression. If the former,
3211 continue parsing here; if the latter, parse the
3212 remainder of the initializer given the starting
3213 primary-expression. ??? It might make sense to
3214 distinguish when des_prev == 1 as well; see
3215 previous comment. */
3217 struct c_expr mexpr
;
3218 c_parser_consume_token (parser
);
3219 if (c_parser_peek_token (parser
)->type
== CPP_NAME
3220 && ((c_parser_peek_token (parser
)->id_kind
3222 || (c_parser_peek_token (parser
)->id_kind
3223 == C_ID_CLASSNAME
)))
3225 /* Type name receiver. */
3226 tree id
= c_parser_peek_token (parser
)->value
;
3227 c_parser_consume_token (parser
);
3228 rec
= objc_get_class_reference (id
);
3229 goto parse_message_args
;
3231 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
3232 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
)
3233 || c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3234 goto array_desig_after_first
;
3235 /* Expression receiver. So far only one part
3236 without commas has been parsed; there might be
3237 more of the expression. */
3239 while (c_parser_next_token_is (parser
, CPP_COMMA
))
3242 location_t comma_loc
, exp_loc
;
3243 comma_loc
= c_parser_peek_token (parser
)->location
;
3244 c_parser_consume_token (parser
);
3245 exp_loc
= c_parser_peek_token (parser
)->location
;
3246 next
= c_parser_expr_no_commas (parser
, NULL
);
3247 next
= default_function_array_conversion (exp_loc
, next
);
3248 rec
= build_compound_expr (comma_loc
, rec
, next
.value
);
3251 /* Now parse the objc-message-args. */
3252 args
= c_parser_objc_message_args (parser
);
3253 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3256 = objc_build_message_expr (build_tree_list (rec
, args
));
3257 mexpr
.original_code
= ERROR_MARK
;
3258 mexpr
.original_type
= NULL
;
3259 /* Now parse and process the remainder of the
3260 initializer, starting with this message
3261 expression as a primary-expression. */
3262 c_parser_initval (parser
, &mexpr
);
3265 c_parser_consume_token (parser
);
3266 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
3267 array_desig_after_first
:
3268 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3270 ellipsis_loc
= c_parser_peek_token (parser
)->location
;
3271 c_parser_consume_token (parser
);
3272 second
= c_parser_expr_no_commas (parser
, NULL
).value
;
3276 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3278 c_parser_consume_token (parser
);
3279 set_init_index (first
, second
);
3281 pedwarn (ellipsis_loc
, OPT_pedantic
,
3282 "ISO C forbids specifying range of elements to initialize");
3285 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3291 if (c_parser_next_token_is (parser
, CPP_EQ
))
3294 pedwarn (des_loc
, OPT_pedantic
,
3295 "ISO C90 forbids specifying subobject to initialize");
3296 c_parser_consume_token (parser
);
3301 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
3302 "obsolete use of designated initializer without %<=%>");
3306 init
.value
= error_mark_node
;
3307 init
.original_code
= ERROR_MARK
;
3308 init
.original_type
= NULL
;
3309 c_parser_error (parser
, "expected %<=%>");
3310 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3311 process_init_element (init
, false);
3317 c_parser_initval (parser
, NULL
);
3320 /* Parse a nested initializer; as c_parser_initializer but parses
3321 initializers within braced lists, after any designators have been
3322 applied. If AFTER is not NULL then it is an Objective-C message
3323 expression which is the primary-expression starting the
3327 c_parser_initval (c_parser
*parser
, struct c_expr
*after
)
3330 gcc_assert (!after
|| c_dialect_objc ());
3331 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
) && !after
)
3332 init
= c_parser_braced_init (parser
, NULL_TREE
, true);
3335 location_t loc
= c_parser_peek_token (parser
)->location
;
3336 init
= c_parser_expr_no_commas (parser
, after
);
3337 if (init
.value
!= NULL_TREE
3338 && TREE_CODE (init
.value
) != STRING_CST
3339 && TREE_CODE (init
.value
) != COMPOUND_LITERAL_EXPR
)
3340 init
= default_function_array_conversion (loc
, init
);
3342 process_init_element (init
, false);
3345 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
3349 { block-item-list[opt] }
3350 { label-declarations block-item-list }
3354 block-item-list block-item
3366 { label-declarations block-item-list }
3369 __extension__ nested-declaration
3370 nested-function-definition
3374 label-declarations label-declaration
3377 __label__ identifier-list ;
3379 Allowing the mixing of declarations and code is new in C99. The
3380 GNU syntax also permits (not shown above) labels at the end of
3381 compound statements, which yield an error. We don't allow labels
3382 on declarations; this might seem like a natural extension, but
3383 there would be a conflict between attributes on the label and
3384 prefix attributes on the declaration. ??? The syntax follows the
3385 old parser in requiring something after label declarations.
3386 Although they are erroneous if the labels declared aren't defined,
3387 is it useful for the syntax to be this way?
3399 c_parser_compound_statement (c_parser
*parser
)
3402 location_t brace_loc
;
3403 brace_loc
= c_parser_peek_token (parser
)->location
;
3404 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
3406 /* Ensure a scope is entered and left anyway to avoid confusion
3407 if we have just prepared to enter a function body. */
3408 stmt
= c_begin_compound_stmt (true);
3409 c_end_compound_stmt (brace_loc
, stmt
, true);
3410 return error_mark_node
;
3412 stmt
= c_begin_compound_stmt (true);
3413 c_parser_compound_statement_nostart (parser
);
3414 return c_end_compound_stmt (brace_loc
, stmt
, true);
3417 /* Parse a compound statement except for the opening brace. This is
3418 used for parsing both compound statements and statement expressions
3419 (which follow different paths to handling the opening). */
3422 c_parser_compound_statement_nostart (c_parser
*parser
)
3424 bool last_stmt
= false;
3425 bool last_label
= false;
3426 bool save_valid_for_pragma
= valid_location_for_stdc_pragma_p ();
3427 location_t label_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
3428 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3430 c_parser_consume_token (parser
);
3433 mark_valid_location_for_stdc_pragma (true);
3434 if (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
3436 /* Read zero or more forward-declarations for labels that nested
3437 functions can jump to. */
3438 mark_valid_location_for_stdc_pragma (false);
3439 while (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
3441 label_loc
= c_parser_peek_token (parser
)->location
;
3442 c_parser_consume_token (parser
);
3443 /* Any identifiers, including those declared as type names,
3448 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
3450 c_parser_error (parser
, "expected identifier");
3454 = declare_label (c_parser_peek_token (parser
)->value
);
3455 C_DECLARED_LABEL_FLAG (label
) = 1;
3456 add_stmt (build_stmt (label_loc
, DECL_EXPR
, label
));
3457 c_parser_consume_token (parser
);
3458 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3459 c_parser_consume_token (parser
);
3463 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
3465 pedwarn (label_loc
, OPT_pedantic
, "ISO C forbids label declarations");
3467 /* We must now have at least one statement, label or declaration. */
3468 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3470 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
3471 c_parser_error (parser
, "expected declaration or statement");
3472 c_parser_consume_token (parser
);
3475 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
3477 location_t loc
= c_parser_peek_token (parser
)->location
;
3478 if (c_parser_next_token_is_keyword (parser
, RID_CASE
)
3479 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
3480 || (c_parser_next_token_is (parser
, CPP_NAME
)
3481 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
3483 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
3484 label_loc
= c_parser_peek_2nd_token (parser
)->location
;
3486 label_loc
= c_parser_peek_token (parser
)->location
;
3489 mark_valid_location_for_stdc_pragma (false);
3490 c_parser_label (parser
);
3492 else if (!last_label
3493 && c_parser_next_token_starts_declspecs (parser
))
3496 mark_valid_location_for_stdc_pragma (false);
3497 c_parser_declaration_or_fndef (parser
, true, true, true, true);
3500 (pedantic
&& !flag_isoc99
)
3502 : OPT_Wdeclaration_after_statement
,
3503 "ISO C90 forbids mixed declarations and code");
3506 else if (!last_label
3507 && c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
3509 /* __extension__ can start a declaration, but is also an
3510 unary operator that can start an expression. Consume all
3511 but the last of a possible series of __extension__ to
3513 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
3514 && (c_parser_peek_2nd_token (parser
)->keyword
3516 c_parser_consume_token (parser
);
3517 if (c_token_starts_declspecs (c_parser_peek_2nd_token (parser
)))
3520 ext
= disable_extension_diagnostics ();
3521 c_parser_consume_token (parser
);
3523 mark_valid_location_for_stdc_pragma (false);
3524 c_parser_declaration_or_fndef (parser
, true, true, true, true);
3525 /* Following the old parser, __extension__ does not
3526 disable this diagnostic. */
3527 restore_extension_diagnostics (ext
);
3529 pedwarn_c90 (loc
, (pedantic
&& !flag_isoc99
)
3531 : OPT_Wdeclaration_after_statement
,
3532 "ISO C90 forbids mixed declarations and code");
3538 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
3540 /* External pragmas, and some omp pragmas, are not associated
3541 with regular c code, and so are not to be considered statements
3542 syntactically. This ensures that the user doesn't put them
3543 places that would turn into syntax errors if the directive
3545 if (c_parser_pragma (parser
, pragma_compound
))
3546 last_label
= false, last_stmt
= true;
3548 else if (c_parser_next_token_is (parser
, CPP_EOF
))
3550 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
3551 c_parser_error (parser
, "expected declaration or statement");
3554 else if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
3556 if (parser
->in_if_block
)
3558 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
3559 error_at (loc
, """expected %<}%> before %<else%>");
3564 error_at (loc
, "%<else%> without a previous %<if%>");
3565 c_parser_consume_token (parser
);
3574 mark_valid_location_for_stdc_pragma (false);
3575 c_parser_statement_after_labels (parser
);
3578 parser
->error
= false;
3581 error_at (label_loc
, "label at end of compound statement");
3582 c_parser_consume_token (parser
);
3583 /* Restore the value we started with. */
3584 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
3587 /* Parse a label (C90 6.6.1, C99 6.8.1).
3590 identifier : attributes[opt]
3591 case constant-expression :
3597 case constant-expression ... constant-expression :
3599 The use of attributes on labels is a GNU extension. The syntax in
3600 GNU C accepts any expressions without commas, non-constant
3601 expressions being rejected later. */
3604 c_parser_label (c_parser
*parser
)
3606 location_t loc1
= c_parser_peek_token (parser
)->location
;
3607 tree label
= NULL_TREE
;
3608 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
3611 c_parser_consume_token (parser
);
3612 exp1
= c_parser_expr_no_commas (parser
, NULL
).value
;
3613 if (c_parser_next_token_is (parser
, CPP_COLON
))
3615 c_parser_consume_token (parser
);
3616 label
= do_case (loc1
, exp1
, NULL_TREE
);
3618 else if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3620 c_parser_consume_token (parser
);
3621 exp2
= c_parser_expr_no_commas (parser
, NULL
).value
;
3622 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
3623 label
= do_case (loc1
, exp1
, exp2
);
3626 c_parser_error (parser
, "expected %<:%> or %<...%>");
3628 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
3630 c_parser_consume_token (parser
);
3631 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
3632 label
= do_case (loc1
, NULL_TREE
, NULL_TREE
);
3636 tree name
= c_parser_peek_token (parser
)->value
;
3639 location_t loc2
= c_parser_peek_token (parser
)->location
;
3640 gcc_assert (c_parser_next_token_is (parser
, CPP_NAME
));
3641 c_parser_consume_token (parser
);
3642 gcc_assert (c_parser_next_token_is (parser
, CPP_COLON
));
3643 c_parser_consume_token (parser
);
3644 attrs
= c_parser_attributes (parser
);
3645 tlab
= define_label (loc2
, name
);
3648 decl_attributes (&tlab
, attrs
, 0);
3649 label
= add_stmt (build_stmt (loc1
, LABEL_EXPR
, tlab
));
3654 if (c_parser_next_token_starts_declspecs (parser
)
3655 && !(c_parser_next_token_is (parser
, CPP_NAME
)
3656 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
3658 error_at (c_parser_peek_token (parser
)->location
,
3659 "a label can only be part of a statement and "
3660 "a declaration is not a statement");
3661 c_parser_declaration_or_fndef (parser
, /*fndef_ok*/ false,
3662 /*nested*/ true, /*empty_ok*/ false,
3663 /*start_attr_ok*/ true);
3668 /* Parse a statement (C90 6.6, C99 6.8).
3673 expression-statement
3681 expression-statement:
3684 selection-statement:
3688 iteration-statement:
3697 return expression[opt] ;
3710 objc-throw-statement
3711 objc-try-catch-statement
3712 objc-synchronized-statement
3714 objc-throw-statement:
3728 parallel-for-construct
3729 parallel-sections-construct
3736 parallel-directive structured-block
3739 for-directive iteration-statement
3742 sections-directive section-scope
3745 single-directive structured-block
3747 parallel-for-construct:
3748 parallel-for-directive iteration-statement
3750 parallel-sections-construct:
3751 parallel-sections-directive section-scope
3754 master-directive structured-block
3757 critical-directive structured-block
3760 atomic-directive expression-statement
3763 ordered-directive structured-block */
3766 c_parser_statement (c_parser
*parser
)
3768 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
3769 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
3770 || (c_parser_next_token_is (parser
, CPP_NAME
)
3771 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
3772 c_parser_label (parser
);
3773 c_parser_statement_after_labels (parser
);
3776 /* Parse a statement, other than a labeled statement. */
3779 c_parser_statement_after_labels (c_parser
*parser
)
3781 location_t loc
= c_parser_peek_token (parser
)->location
;
3782 tree stmt
= NULL_TREE
;
3783 bool in_if_block
= parser
->in_if_block
;
3784 parser
->in_if_block
= false;
3785 switch (c_parser_peek_token (parser
)->type
)
3787 case CPP_OPEN_BRACE
:
3788 add_stmt (c_parser_compound_statement (parser
));
3791 switch (c_parser_peek_token (parser
)->keyword
)
3794 c_parser_if_statement (parser
);
3797 c_parser_switch_statement (parser
);
3800 c_parser_while_statement (parser
);
3803 c_parser_do_statement (parser
);
3806 c_parser_for_statement (parser
);
3809 c_parser_consume_token (parser
);
3810 if (c_parser_next_token_is (parser
, CPP_NAME
))
3812 stmt
= c_finish_goto_label (loc
,
3813 c_parser_peek_token (parser
)->value
);
3814 c_parser_consume_token (parser
);
3816 else if (c_parser_next_token_is (parser
, CPP_MULT
))
3818 c_parser_consume_token (parser
);
3819 stmt
= c_finish_goto_ptr (loc
,
3820 c_parser_expression (parser
).value
);
3823 c_parser_error (parser
, "expected identifier or %<*%>");
3824 goto expect_semicolon
;
3826 c_parser_consume_token (parser
);
3827 stmt
= c_finish_bc_stmt (loc
, &c_cont_label
, false);
3828 goto expect_semicolon
;
3830 c_parser_consume_token (parser
);
3831 stmt
= c_finish_bc_stmt (loc
, &c_break_label
, true);
3832 goto expect_semicolon
;
3834 c_parser_consume_token (parser
);
3835 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3837 stmt
= c_finish_return (loc
, NULL_TREE
, NULL_TREE
);
3838 c_parser_consume_token (parser
);
3842 struct c_expr expr
= c_parser_expression_conv (parser
);
3843 stmt
= c_finish_return (loc
, expr
.value
, expr
.original_type
);
3844 goto expect_semicolon
;
3848 stmt
= c_parser_asm_statement (parser
);
3851 gcc_assert (c_dialect_objc ());
3852 c_parser_consume_token (parser
);
3853 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3855 stmt
= objc_build_throw_stmt (loc
, NULL_TREE
);
3856 c_parser_consume_token (parser
);
3860 tree expr
= c_parser_expression (parser
).value
;
3861 expr
= c_fully_fold (expr
, false, NULL
);
3862 stmt
= objc_build_throw_stmt (loc
, expr
);
3863 goto expect_semicolon
;
3867 gcc_assert (c_dialect_objc ());
3868 c_parser_objc_try_catch_statement (parser
);
3870 case RID_AT_SYNCHRONIZED
:
3871 gcc_assert (c_dialect_objc ());
3872 c_parser_objc_synchronized_statement (parser
);
3879 c_parser_consume_token (parser
);
3881 case CPP_CLOSE_PAREN
:
3882 case CPP_CLOSE_SQUARE
:
3883 /* Avoid infinite loop in error recovery:
3884 c_parser_skip_until_found stops at a closing nesting
3885 delimiter without consuming it, but here we need to consume
3886 it to proceed further. */
3887 c_parser_error (parser
, "expected statement");
3888 c_parser_consume_token (parser
);
3891 c_parser_pragma (parser
, pragma_stmt
);
3895 stmt
= c_finish_expr_stmt (loc
, c_parser_expression_conv (parser
).value
);
3897 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
3900 /* Two cases cannot and do not have line numbers associated: If stmt
3901 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
3902 cannot hold line numbers. But that's OK because the statement
3903 will either be changed to a MODIFY_EXPR during gimplification of
3904 the statement expr, or discarded. If stmt was compound, but
3905 without new variables, we will have skipped the creation of a
3906 BIND and will have a bare STATEMENT_LIST. But that's OK because
3907 (recursively) all of the component statements should already have
3908 line numbers assigned. ??? Can we discard no-op statements
3910 if (CAN_HAVE_LOCATION_P (stmt
)
3911 && EXPR_LOCATION (stmt
) == UNKNOWN_LOCATION
)
3912 SET_EXPR_LOCATION (stmt
, loc
);
3914 parser
->in_if_block
= in_if_block
;
3917 /* Parse the condition from an if, do, while or for statements. */
3920 c_parser_condition (c_parser
*parser
)
3922 location_t loc
= c_parser_peek_token (parser
)->location
;
3924 cond
= c_parser_expression_conv (parser
).value
;
3925 cond
= c_objc_common_truthvalue_conversion (loc
, cond
);
3926 cond
= c_fully_fold (cond
, false, NULL
);
3927 if (warn_sequence_point
)
3928 verify_sequence_points (cond
);
3932 /* Parse a parenthesized condition from an if, do or while statement.
3938 c_parser_paren_condition (c_parser
*parser
)
3941 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3942 return error_mark_node
;
3943 cond
= c_parser_condition (parser
);
3944 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
3948 /* Parse a statement which is a block in C99. */
3951 c_parser_c99_block_statement (c_parser
*parser
)
3953 tree block
= c_begin_compound_stmt (flag_isoc99
);
3954 location_t loc
= c_parser_peek_token (parser
)->location
;
3955 c_parser_statement (parser
);
3956 return c_end_compound_stmt (loc
, block
, flag_isoc99
);
3959 /* Parse the body of an if statement. This is just parsing a
3960 statement but (a) it is a block in C99, (b) we track whether the
3961 body is an if statement for the sake of -Wparentheses warnings, (c)
3962 we handle an empty body specially for the sake of -Wempty-body
3963 warnings, and (d) we call parser_compound_statement directly
3964 because c_parser_statement_after_labels resets
3965 parser->in_if_block. */
3968 c_parser_if_body (c_parser
*parser
, bool *if_p
)
3970 tree block
= c_begin_compound_stmt (flag_isoc99
);
3971 location_t body_loc
= c_parser_peek_token (parser
)->location
;
3972 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
3973 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
3974 || (c_parser_next_token_is (parser
, CPP_NAME
)
3975 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
3976 c_parser_label (parser
);
3977 *if_p
= c_parser_next_token_is_keyword (parser
, RID_IF
);
3978 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3980 location_t loc
= c_parser_peek_token (parser
)->location
;
3981 add_stmt (build_empty_stmt (loc
));
3982 c_parser_consume_token (parser
);
3983 if (!c_parser_next_token_is_keyword (parser
, RID_ELSE
))
3984 warning_at (loc
, OPT_Wempty_body
,
3985 "suggest braces around empty body in an %<if%> statement");
3987 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
3988 add_stmt (c_parser_compound_statement (parser
));
3990 c_parser_statement_after_labels (parser
);
3991 return c_end_compound_stmt (body_loc
, block
, flag_isoc99
);
3994 /* Parse the else body of an if statement. This is just parsing a
3995 statement but (a) it is a block in C99, (b) we handle an empty body
3996 specially for the sake of -Wempty-body warnings. */
3999 c_parser_else_body (c_parser
*parser
)
4001 location_t else_loc
= c_parser_peek_token (parser
)->location
;
4002 tree block
= c_begin_compound_stmt (flag_isoc99
);
4003 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4004 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4005 || (c_parser_next_token_is (parser
, CPP_NAME
)
4006 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4007 c_parser_label (parser
);
4008 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4010 location_t loc
= c_parser_peek_token (parser
)->location
;
4013 "suggest braces around empty body in an %<else%> statement");
4014 add_stmt (build_empty_stmt (loc
));
4015 c_parser_consume_token (parser
);
4018 c_parser_statement_after_labels (parser
);
4019 return c_end_compound_stmt (else_loc
, block
, flag_isoc99
);
4022 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
4025 if ( expression ) statement
4026 if ( expression ) statement else statement
4030 c_parser_if_statement (c_parser
*parser
)
4035 bool first_if
= false;
4036 tree first_body
, second_body
;
4039 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_IF
));
4040 c_parser_consume_token (parser
);
4041 block
= c_begin_compound_stmt (flag_isoc99
);
4042 loc
= c_parser_peek_token (parser
)->location
;
4043 cond
= c_parser_paren_condition (parser
);
4044 in_if_block
= parser
->in_if_block
;
4045 parser
->in_if_block
= true;
4046 first_body
= c_parser_if_body (parser
, &first_if
);
4047 parser
->in_if_block
= in_if_block
;
4048 if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
4050 c_parser_consume_token (parser
);
4051 second_body
= c_parser_else_body (parser
);
4054 second_body
= NULL_TREE
;
4055 c_finish_if_stmt (loc
, cond
, first_body
, second_body
, first_if
);
4056 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
4059 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
4062 switch (expression) statement
4066 c_parser_switch_statement (c_parser
*parser
)
4068 tree block
, expr
, body
, save_break
;
4069 location_t switch_loc
= c_parser_peek_token (parser
)->location
;
4070 location_t switch_cond_loc
;
4071 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SWITCH
));
4072 c_parser_consume_token (parser
);
4073 block
= c_begin_compound_stmt (flag_isoc99
);
4074 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4076 switch_cond_loc
= c_parser_peek_token (parser
)->location
;
4077 expr
= c_parser_expression (parser
).value
;
4078 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4082 switch_cond_loc
= UNKNOWN_LOCATION
;
4083 expr
= error_mark_node
;
4085 c_start_case (switch_loc
, switch_cond_loc
, expr
);
4086 save_break
= c_break_label
;
4087 c_break_label
= NULL_TREE
;
4088 body
= c_parser_c99_block_statement (parser
);
4089 c_finish_case (body
);
4092 location_t here
= c_parser_peek_token (parser
)->location
;
4093 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_break_label
);
4094 SET_EXPR_LOCATION (t
, here
);
4097 c_break_label
= save_break
;
4098 add_stmt (c_end_compound_stmt (switch_loc
, block
, flag_isoc99
));
4101 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
4104 while (expression) statement
4108 c_parser_while_statement (c_parser
*parser
)
4110 tree block
, cond
, body
, save_break
, save_cont
;
4112 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_WHILE
));
4113 c_parser_consume_token (parser
);
4114 block
= c_begin_compound_stmt (flag_isoc99
);
4115 loc
= c_parser_peek_token (parser
)->location
;
4116 cond
= c_parser_paren_condition (parser
);
4117 save_break
= c_break_label
;
4118 c_break_label
= NULL_TREE
;
4119 save_cont
= c_cont_label
;
4120 c_cont_label
= NULL_TREE
;
4121 body
= c_parser_c99_block_statement (parser
);
4122 c_finish_loop (loc
, cond
, NULL
, body
, c_break_label
, c_cont_label
, true);
4123 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
4124 c_break_label
= save_break
;
4125 c_cont_label
= save_cont
;
4128 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
4131 do statement while ( expression ) ;
4135 c_parser_do_statement (c_parser
*parser
)
4137 tree block
, cond
, body
, save_break
, save_cont
, new_break
, new_cont
;
4139 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_DO
));
4140 c_parser_consume_token (parser
);
4141 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4142 warning_at (c_parser_peek_token (parser
)->location
,
4144 "suggest braces around empty body in %<do%> statement");
4145 block
= c_begin_compound_stmt (flag_isoc99
);
4146 loc
= c_parser_peek_token (parser
)->location
;
4147 save_break
= c_break_label
;
4148 c_break_label
= NULL_TREE
;
4149 save_cont
= c_cont_label
;
4150 c_cont_label
= NULL_TREE
;
4151 body
= c_parser_c99_block_statement (parser
);
4152 c_parser_require_keyword (parser
, RID_WHILE
, "expected %<while%>");
4153 new_break
= c_break_label
;
4154 c_break_label
= save_break
;
4155 new_cont
= c_cont_label
;
4156 c_cont_label
= save_cont
;
4157 cond
= c_parser_paren_condition (parser
);
4158 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
4159 c_parser_skip_to_end_of_block_or_statement (parser
);
4160 c_finish_loop (loc
, cond
, NULL
, body
, new_break
, new_cont
, false);
4161 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
4164 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
4167 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
4168 for ( nested-declaration expression[opt] ; expression[opt] ) statement
4170 The form with a declaration is new in C99.
4172 ??? In accordance with the old parser, the declaration may be a
4173 nested function, which is then rejected in check_for_loop_decls,
4174 but does it make any sense for this to be included in the grammar?
4175 Note in particular that the nested function does not include a
4176 trailing ';', whereas the "declaration" production includes one.
4177 Also, can we reject bad declarations earlier and cheaper than
4178 check_for_loop_decls? */
4181 c_parser_for_statement (c_parser
*parser
)
4183 tree block
, cond
, incr
, save_break
, save_cont
, body
;
4184 location_t loc
= c_parser_peek_token (parser
)->location
;
4185 location_t for_loc
= c_parser_peek_token (parser
)->location
;
4186 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_FOR
));
4187 c_parser_consume_token (parser
);
4188 block
= c_begin_compound_stmt (flag_isoc99
);
4189 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4191 /* Parse the initialization declaration or expression. */
4192 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4194 c_parser_consume_token (parser
);
4195 c_finish_expr_stmt (loc
, NULL_TREE
);
4197 else if (c_parser_next_token_starts_declspecs (parser
))
4199 c_parser_declaration_or_fndef (parser
, true, true, true, true);
4200 check_for_loop_decls (for_loc
);
4202 else if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
4204 /* __extension__ can start a declaration, but is also an
4205 unary operator that can start an expression. Consume all
4206 but the last of a possible series of __extension__ to
4208 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
4209 && (c_parser_peek_2nd_token (parser
)->keyword
4211 c_parser_consume_token (parser
);
4212 if (c_token_starts_declspecs (c_parser_peek_2nd_token (parser
)))
4215 ext
= disable_extension_diagnostics ();
4216 c_parser_consume_token (parser
);
4217 c_parser_declaration_or_fndef (parser
, true, true, true, true);
4218 restore_extension_diagnostics (ext
);
4219 check_for_loop_decls (for_loc
);
4227 c_finish_expr_stmt (loc
, c_parser_expression (parser
).value
);
4228 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4230 /* Parse the loop condition. */
4231 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4233 c_parser_consume_token (parser
);
4238 cond
= c_parser_condition (parser
);
4239 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4241 /* Parse the increment expression. */
4242 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4243 incr
= c_process_expr_stmt (loc
, NULL_TREE
);
4245 incr
= c_process_expr_stmt (loc
, c_parser_expression (parser
).value
);
4246 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4250 cond
= error_mark_node
;
4251 incr
= error_mark_node
;
4253 save_break
= c_break_label
;
4254 c_break_label
= NULL_TREE
;
4255 save_cont
= c_cont_label
;
4256 c_cont_label
= NULL_TREE
;
4257 body
= c_parser_c99_block_statement (parser
);
4258 c_finish_loop (loc
, cond
, incr
, body
, c_break_label
, c_cont_label
, true);
4259 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
4260 c_break_label
= save_break
;
4261 c_cont_label
= save_cont
;
4264 /* Parse an asm statement, a GNU extension. This is a full-blown asm
4265 statement with inputs, outputs, clobbers, and volatile tag
4269 asm type-qualifier[opt] ( asm-argument ) ;
4270 asm type-qualifier[opt] goto ( asm-goto-argument ) ;
4274 asm-string-literal : asm-operands[opt]
4275 asm-string-literal : asm-operands[opt] : asm-operands[opt]
4276 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers[opt]
4279 asm-string-literal : : asm-operands[opt] : asm-clobbers[opt] \
4282 Qualifiers other than volatile are accepted in the syntax but
4286 c_parser_asm_statement (c_parser
*parser
)
4288 tree quals
, str
, outputs
, inputs
, clobbers
, labels
, ret
;
4289 bool simple
, is_goto
;
4290 location_t asm_loc
= c_parser_peek_token (parser
)->location
;
4291 int section
, nsections
;
4293 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
4294 c_parser_consume_token (parser
);
4295 if (c_parser_next_token_is_keyword (parser
, RID_VOLATILE
))
4297 quals
= c_parser_peek_token (parser
)->value
;
4298 c_parser_consume_token (parser
);
4300 else if (c_parser_next_token_is_keyword (parser
, RID_CONST
)
4301 || c_parser_next_token_is_keyword (parser
, RID_RESTRICT
))
4303 warning_at (c_parser_peek_token (parser
)->location
,
4305 "%E qualifier ignored on asm",
4306 c_parser_peek_token (parser
)->value
);
4308 c_parser_consume_token (parser
);
4314 if (c_parser_next_token_is_keyword (parser
, RID_GOTO
))
4316 c_parser_consume_token (parser
);
4320 /* ??? Follow the C++ parser rather than using the
4321 lex_untranslated_string kludge. */
4322 parser
->lex_untranslated_string
= true;
4325 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4328 str
= c_parser_asm_string_literal (parser
);
4329 if (str
== NULL_TREE
)
4330 goto error_close_paren
;
4333 outputs
= NULL_TREE
;
4335 clobbers
= NULL_TREE
;
4338 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
4341 /* Parse each colon-delimited section of operands. */
4342 nsections
= 3 + is_goto
;
4343 for (section
= 0; section
< nsections
; ++section
)
4345 if (!c_parser_require (parser
, CPP_COLON
,
4348 : "expected %<:%> or %<)%>"))
4349 goto error_close_paren
;
4351 /* Once past any colon, we're no longer a simple asm. */
4354 if ((!c_parser_next_token_is (parser
, CPP_COLON
)
4355 && !c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4360 /* For asm goto, we don't allow output operands, but reserve
4361 the slot for a future extension that does allow them. */
4363 outputs
= c_parser_asm_operands (parser
, false);
4366 inputs
= c_parser_asm_operands (parser
, true);
4369 clobbers
= c_parser_asm_clobbers (parser
);
4372 labels
= c_parser_asm_goto_operands (parser
);
4378 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
4383 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
4385 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4389 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
4390 c_parser_skip_to_end_of_block_or_statement (parser
);
4392 ret
= build_asm_stmt (quals
, build_asm_expr (asm_loc
, str
, outputs
, inputs
,
4393 clobbers
, labels
, simple
));
4396 parser
->lex_untranslated_string
= false;
4400 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4404 /* Parse asm operands, a GNU extension. If CONVERT_P (for inputs but
4405 not outputs), apply the default conversion of functions and arrays
4410 asm-operands , asm-operand
4413 asm-string-literal ( expression )
4414 [ identifier ] asm-string-literal ( expression )
4418 c_parser_asm_operands (c_parser
*parser
, bool convert_p
)
4420 tree list
= NULL_TREE
;
4426 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
4428 c_parser_consume_token (parser
);
4429 if (c_parser_next_token_is (parser
, CPP_NAME
))
4431 tree id
= c_parser_peek_token (parser
)->value
;
4432 c_parser_consume_token (parser
);
4433 name
= build_string (IDENTIFIER_LENGTH (id
),
4434 IDENTIFIER_POINTER (id
));
4438 c_parser_error (parser
, "expected identifier");
4439 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
4442 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4447 str
= c_parser_asm_string_literal (parser
);
4448 if (str
== NULL_TREE
)
4450 parser
->lex_untranslated_string
= false;
4451 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4453 parser
->lex_untranslated_string
= true;
4456 loc
= c_parser_peek_token (parser
)->location
;
4457 expr
= c_parser_expression (parser
);
4459 expr
= default_function_array_conversion (loc
, expr
);
4460 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
4461 parser
->lex_untranslated_string
= true;
4462 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
4464 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4467 list
= chainon (list
, build_tree_list (build_tree_list (name
, str
),
4469 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4470 c_parser_consume_token (parser
);
4477 /* Parse asm clobbers, a GNU extension.
4481 asm-clobbers , asm-string-literal
4485 c_parser_asm_clobbers (c_parser
*parser
)
4487 tree list
= NULL_TREE
;
4490 tree str
= c_parser_asm_string_literal (parser
);
4492 list
= tree_cons (NULL_TREE
, str
, list
);
4495 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4496 c_parser_consume_token (parser
);
4503 /* Parse asm goto labels, a GNU extension.
4507 asm-goto-operands , identifier
4511 c_parser_asm_goto_operands (c_parser
*parser
)
4513 tree list
= NULL_TREE
;
4518 if (c_parser_next_token_is (parser
, CPP_NAME
))
4520 c_token
*tok
= c_parser_peek_token (parser
);
4522 label
= lookup_label_for_goto (tok
->location
, name
);
4523 c_parser_consume_token (parser
);
4524 TREE_USED (label
) = 1;
4528 c_parser_error (parser
, "expected identifier");
4532 name
= build_string (IDENTIFIER_LENGTH (name
),
4533 IDENTIFIER_POINTER (name
));
4534 list
= tree_cons (name
, label
, list
);
4535 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4536 c_parser_consume_token (parser
);
4538 return nreverse (list
);
4542 /* Parse an expression other than a compound expression; that is, an
4543 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
4544 NULL then it is an Objective-C message expression which is the
4545 primary-expression starting the expression as an initializer.
4547 assignment-expression:
4548 conditional-expression
4549 unary-expression assignment-operator assignment-expression
4551 assignment-operator: one of
4552 = *= /= %= += -= <<= >>= &= ^= |=
4554 In GNU C we accept any conditional expression on the LHS and
4555 diagnose the invalid lvalue rather than producing a syntax
4558 static struct c_expr
4559 c_parser_expr_no_commas (c_parser
*parser
, struct c_expr
*after
)
4561 struct c_expr lhs
, rhs
, ret
;
4562 enum tree_code code
;
4563 location_t op_location
, exp_location
;
4564 gcc_assert (!after
|| c_dialect_objc ());
4565 lhs
= c_parser_conditional_expression (parser
, after
);
4566 op_location
= c_parser_peek_token (parser
)->location
;
4567 switch (c_parser_peek_token (parser
)->type
)
4576 code
= TRUNC_DIV_EXPR
;
4579 code
= TRUNC_MOD_EXPR
;
4594 code
= BIT_AND_EXPR
;
4597 code
= BIT_XOR_EXPR
;
4600 code
= BIT_IOR_EXPR
;
4605 c_parser_consume_token (parser
);
4606 exp_location
= c_parser_peek_token (parser
)->location
;
4607 rhs
= c_parser_expr_no_commas (parser
, NULL
);
4608 rhs
= default_function_array_conversion (exp_location
, rhs
);
4609 ret
.value
= build_modify_expr (op_location
, lhs
.value
, lhs
.original_type
,
4610 code
, exp_location
, rhs
.value
,
4612 if (code
== NOP_EXPR
)
4613 ret
.original_code
= MODIFY_EXPR
;
4616 TREE_NO_WARNING (ret
.value
) = 1;
4617 ret
.original_code
= ERROR_MARK
;
4619 ret
.original_type
= NULL
;
4623 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
4624 is not NULL then it is an Objective-C message expression which is
4625 the primary-expression starting the expression as an initializer.
4627 conditional-expression:
4628 logical-OR-expression
4629 logical-OR-expression ? expression : conditional-expression
4633 conditional-expression:
4634 logical-OR-expression ? : conditional-expression
4637 static struct c_expr
4638 c_parser_conditional_expression (c_parser
*parser
, struct c_expr
*after
)
4640 struct c_expr cond
, exp1
, exp2
, ret
;
4641 location_t cond_loc
, colon_loc
;
4643 gcc_assert (!after
|| c_dialect_objc ());
4645 cond
= c_parser_binary_expression (parser
, after
);
4647 if (c_parser_next_token_is_not (parser
, CPP_QUERY
))
4649 cond_loc
= c_parser_peek_token (parser
)->location
;
4650 cond
= default_function_array_conversion (cond_loc
, cond
);
4651 c_parser_consume_token (parser
);
4652 if (c_parser_next_token_is (parser
, CPP_COLON
))
4654 tree eptype
= NULL_TREE
;
4655 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
4656 "ISO C forbids omitting the middle term of a ?: expression");
4657 if (TREE_CODE (cond
.value
) == EXCESS_PRECISION_EXPR
)
4659 eptype
= TREE_TYPE (cond
.value
);
4660 cond
.value
= TREE_OPERAND (cond
.value
, 0);
4662 /* Make sure first operand is calculated only once. */
4663 exp1
.value
= c_save_expr (default_conversion (cond
.value
));
4665 exp1
.value
= build1 (EXCESS_PRECISION_EXPR
, eptype
, exp1
.value
);
4666 exp1
.original_type
= NULL
;
4667 cond
.value
= c_objc_common_truthvalue_conversion (cond_loc
, exp1
.value
);
4668 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_true_node
;
4673 = c_objc_common_truthvalue_conversion
4674 (cond_loc
, default_conversion (cond
.value
));
4675 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_false_node
;
4676 exp1
= c_parser_expression_conv (parser
);
4677 c_inhibit_evaluation_warnings
+=
4678 ((cond
.value
== truthvalue_true_node
)
4679 - (cond
.value
== truthvalue_false_node
));
4682 colon_loc
= c_parser_peek_token (parser
)->location
;
4683 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4685 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
4686 ret
.value
= error_mark_node
;
4687 ret
.original_code
= ERROR_MARK
;
4688 ret
.original_type
= NULL
;
4692 location_t exp2_loc
= c_parser_peek_token (parser
)->location
;
4693 exp2
= c_parser_conditional_expression (parser
, NULL
);
4694 exp2
= default_function_array_conversion (exp2_loc
, exp2
);
4696 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
4697 ret
.value
= build_conditional_expr (colon_loc
, cond
.value
,
4698 cond
.original_code
== C_MAYBE_CONST_EXPR
,
4699 exp1
.value
, exp1
.original_type
,
4700 exp2
.value
, exp2
.original_type
);
4701 ret
.original_code
= ERROR_MARK
;
4702 if (exp1
.value
== error_mark_node
|| exp2
.value
== error_mark_node
)
4703 ret
.original_type
= NULL
;
4708 /* If both sides are enum type, the default conversion will have
4709 made the type of the result be an integer type. We want to
4710 remember the enum types we started with. */
4711 t1
= exp1
.original_type
? exp1
.original_type
: TREE_TYPE (exp1
.value
);
4712 t2
= exp2
.original_type
? exp2
.original_type
: TREE_TYPE (exp2
.value
);
4713 ret
.original_type
= ((t1
!= error_mark_node
4714 && t2
!= error_mark_node
4715 && (TYPE_MAIN_VARIANT (t1
)
4716 == TYPE_MAIN_VARIANT (t2
)))
4723 /* Parse a binary expression; that is, a logical-OR-expression (C90
4724 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
4725 an Objective-C message expression which is the primary-expression
4726 starting the expression as an initializer.
4728 multiplicative-expression:
4730 multiplicative-expression * cast-expression
4731 multiplicative-expression / cast-expression
4732 multiplicative-expression % cast-expression
4734 additive-expression:
4735 multiplicative-expression
4736 additive-expression + multiplicative-expression
4737 additive-expression - multiplicative-expression
4741 shift-expression << additive-expression
4742 shift-expression >> additive-expression
4744 relational-expression:
4746 relational-expression < shift-expression
4747 relational-expression > shift-expression
4748 relational-expression <= shift-expression
4749 relational-expression >= shift-expression
4751 equality-expression:
4752 relational-expression
4753 equality-expression == relational-expression
4754 equality-expression != relational-expression
4758 AND-expression & equality-expression
4760 exclusive-OR-expression:
4762 exclusive-OR-expression ^ AND-expression
4764 inclusive-OR-expression:
4765 exclusive-OR-expression
4766 inclusive-OR-expression | exclusive-OR-expression
4768 logical-AND-expression:
4769 inclusive-OR-expression
4770 logical-AND-expression && inclusive-OR-expression
4772 logical-OR-expression:
4773 logical-AND-expression
4774 logical-OR-expression || logical-AND-expression
4777 static struct c_expr
4778 c_parser_binary_expression (c_parser
*parser
, struct c_expr
*after
)
4780 /* A binary expression is parsed using operator-precedence parsing,
4781 with the operands being cast expressions. All the binary
4782 operators are left-associative. Thus a binary expression is of
4785 E0 op1 E1 op2 E2 ...
4787 which we represent on a stack. On the stack, the precedence
4788 levels are strictly increasing. When a new operator is
4789 encountered of higher precedence than that at the top of the
4790 stack, it is pushed; its LHS is the top expression, and its RHS
4791 is everything parsed until it is popped. When a new operator is
4792 encountered with precedence less than or equal to that at the top
4793 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
4794 by the result of the operation until the operator at the top of
4795 the stack has lower precedence than the new operator or there is
4796 only one element on the stack; then the top expression is the LHS
4797 of the new operator. In the case of logical AND and OR
4798 expressions, we also need to adjust c_inhibit_evaluation_warnings
4799 as appropriate when the operators are pushed and popped. */
4801 /* The precedence levels, where 0 is a dummy lowest level used for
4802 the bottom of the stack. */
4818 /* The expression at this stack level. */
4820 /* The precedence of the operator on its left, PREC_NONE at the
4821 bottom of the stack. */
4823 /* The operation on its left. */
4825 /* The source location of this operation. */
4829 /* Location of the binary operator. */
4830 location_t binary_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4833 switch (stack[sp].op) \
4835 case TRUTH_ANDIF_EXPR: \
4836 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
4837 == truthvalue_false_node); \
4839 case TRUTH_ORIF_EXPR: \
4840 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
4841 == truthvalue_true_node); \
4846 stack[sp - 1].expr \
4847 = default_function_array_conversion (stack[sp - 1].loc, \
4848 stack[sp - 1].expr); \
4850 = default_function_array_conversion (stack[sp].loc, stack[sp].expr); \
4851 stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc, \
4853 stack[sp - 1].expr, \
4857 gcc_assert (!after
|| c_dialect_objc ());
4858 stack
[0].loc
= c_parser_peek_token (parser
)->location
;
4859 stack
[0].expr
= c_parser_cast_expression (parser
, after
);
4860 stack
[0].prec
= PREC_NONE
;
4865 enum tree_code ocode
;
4868 switch (c_parser_peek_token (parser
)->type
)
4876 ocode
= TRUNC_DIV_EXPR
;
4880 ocode
= TRUNC_MOD_EXPR
;
4892 ocode
= LSHIFT_EXPR
;
4896 ocode
= RSHIFT_EXPR
;
4910 case CPP_GREATER_EQ
:
4923 oprec
= PREC_BITAND
;
4924 ocode
= BIT_AND_EXPR
;
4927 oprec
= PREC_BITXOR
;
4928 ocode
= BIT_XOR_EXPR
;
4932 ocode
= BIT_IOR_EXPR
;
4935 oprec
= PREC_LOGAND
;
4936 ocode
= TRUTH_ANDIF_EXPR
;
4940 ocode
= TRUTH_ORIF_EXPR
;
4943 /* Not a binary operator, so end of the binary
4947 binary_loc
= c_parser_peek_token (parser
)->location
;
4948 c_parser_consume_token (parser
);
4949 while (oprec
<= stack
[sp
].prec
)
4953 case TRUTH_ANDIF_EXPR
:
4955 = default_function_array_conversion (stack
[sp
].loc
,
4957 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
4958 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
4959 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
4960 == truthvalue_false_node
);
4962 case TRUTH_ORIF_EXPR
:
4964 = default_function_array_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_true_node
);
4975 stack
[sp
].loc
= binary_loc
;
4976 stack
[sp
].expr
= c_parser_cast_expression (parser
, NULL
);
4977 stack
[sp
].prec
= oprec
;
4978 stack
[sp
].op
= ocode
;
4979 stack
[sp
].loc
= binary_loc
;
4984 return stack
[0].expr
;
4988 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
4989 NULL then it is an Objective-C message expression which is the
4990 primary-expression starting the expression as an initializer.
4994 ( type-name ) unary-expression
4997 static struct c_expr
4998 c_parser_cast_expression (c_parser
*parser
, struct c_expr
*after
)
5000 location_t cast_loc
= c_parser_peek_token (parser
)->location
;
5001 gcc_assert (!after
|| c_dialect_objc ());
5003 return c_parser_postfix_expression_after_primary (parser
,
5005 /* If the expression begins with a parenthesized type name, it may
5006 be either a cast or a compound literal; we need to see whether
5007 the next character is '{' to tell the difference. If not, it is
5008 an unary expression. */
5009 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
5010 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
5012 struct c_type_name
*type_name
;
5015 c_parser_consume_token (parser
);
5016 type_name
= c_parser_type_name (parser
);
5017 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5018 if (type_name
== NULL
)
5020 ret
.value
= error_mark_node
;
5021 ret
.original_code
= ERROR_MARK
;
5022 ret
.original_type
= NULL
;
5026 /* Save casted types in the function's used types hash table. */
5027 used_types_insert (type_name
->specs
->type
);
5029 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5030 return c_parser_postfix_expression_after_paren_type (parser
, type_name
,
5033 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
5034 expr
= c_parser_cast_expression (parser
, NULL
);
5035 expr
= default_function_array_conversion (expr_loc
, expr
);
5037 ret
.value
= c_cast_expr (cast_loc
, type_name
, expr
.value
);
5038 ret
.original_code
= ERROR_MARK
;
5039 ret
.original_type
= NULL
;
5043 return c_parser_unary_expression (parser
);
5046 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
5052 unary-operator cast-expression
5053 sizeof unary-expression
5054 sizeof ( type-name )
5056 unary-operator: one of
5062 __alignof__ unary-expression
5063 __alignof__ ( type-name )
5066 unary-operator: one of
5067 __extension__ __real__ __imag__
5069 In addition, the GNU syntax treats ++ and -- as unary operators, so
5070 they may be applied to cast expressions with errors for non-lvalues
5073 static struct c_expr
5074 c_parser_unary_expression (c_parser
*parser
)
5077 struct c_expr ret
, op
;
5078 location_t op_loc
= c_parser_peek_token (parser
)->location
;
5080 ret
.original_code
= ERROR_MARK
;
5081 ret
.original_type
= NULL
;
5082 switch (c_parser_peek_token (parser
)->type
)
5085 c_parser_consume_token (parser
);
5086 exp_loc
= c_parser_peek_token (parser
)->location
;
5087 op
= c_parser_cast_expression (parser
, NULL
);
5088 op
= default_function_array_conversion (exp_loc
, op
);
5089 return parser_build_unary_op (op_loc
, PREINCREMENT_EXPR
, op
);
5090 case CPP_MINUS_MINUS
:
5091 c_parser_consume_token (parser
);
5092 exp_loc
= c_parser_peek_token (parser
)->location
;
5093 op
= c_parser_cast_expression (parser
, NULL
);
5094 op
= default_function_array_conversion (exp_loc
, op
);
5095 return parser_build_unary_op (op_loc
, PREDECREMENT_EXPR
, op
);
5097 c_parser_consume_token (parser
);
5098 return parser_build_unary_op (op_loc
, ADDR_EXPR
,
5099 c_parser_cast_expression (parser
, NULL
));
5101 c_parser_consume_token (parser
);
5102 exp_loc
= c_parser_peek_token (parser
)->location
;
5103 op
= c_parser_cast_expression (parser
, NULL
);
5104 op
= default_function_array_conversion (exp_loc
, op
);
5105 ret
.value
= build_indirect_ref (op_loc
, op
.value
, RO_UNARY_STAR
);
5108 if (!c_dialect_objc () && !in_system_header
)
5111 "traditional C rejects the unary plus operator");
5112 c_parser_consume_token (parser
);
5113 exp_loc
= c_parser_peek_token (parser
)->location
;
5114 op
= c_parser_cast_expression (parser
, NULL
);
5115 op
= default_function_array_conversion (exp_loc
, op
);
5116 return parser_build_unary_op (op_loc
, CONVERT_EXPR
, op
);
5118 c_parser_consume_token (parser
);
5119 exp_loc
= c_parser_peek_token (parser
)->location
;
5120 op
= c_parser_cast_expression (parser
, NULL
);
5121 op
= default_function_array_conversion (exp_loc
, op
);
5122 return parser_build_unary_op (op_loc
, NEGATE_EXPR
, op
);
5124 c_parser_consume_token (parser
);
5125 exp_loc
= c_parser_peek_token (parser
)->location
;
5126 op
= c_parser_cast_expression (parser
, NULL
);
5127 op
= default_function_array_conversion (exp_loc
, op
);
5128 return parser_build_unary_op (op_loc
, BIT_NOT_EXPR
, op
);
5130 c_parser_consume_token (parser
);
5131 exp_loc
= c_parser_peek_token (parser
)->location
;
5132 op
= c_parser_cast_expression (parser
, NULL
);
5133 op
= default_function_array_conversion (exp_loc
, op
);
5134 return parser_build_unary_op (op_loc
, TRUTH_NOT_EXPR
, op
);
5136 /* Refer to the address of a label as a pointer. */
5137 c_parser_consume_token (parser
);
5138 if (c_parser_next_token_is (parser
, CPP_NAME
))
5140 ret
.value
= finish_label_address_expr
5141 (c_parser_peek_token (parser
)->value
, op_loc
);
5142 c_parser_consume_token (parser
);
5146 c_parser_error (parser
, "expected identifier");
5147 ret
.value
= error_mark_node
;
5151 switch (c_parser_peek_token (parser
)->keyword
)
5154 return c_parser_sizeof_expression (parser
);
5156 return c_parser_alignof_expression (parser
);
5158 c_parser_consume_token (parser
);
5159 ext
= disable_extension_diagnostics ();
5160 ret
= c_parser_cast_expression (parser
, NULL
);
5161 restore_extension_diagnostics (ext
);
5164 c_parser_consume_token (parser
);
5165 exp_loc
= c_parser_peek_token (parser
)->location
;
5166 op
= c_parser_cast_expression (parser
, NULL
);
5167 op
= default_function_array_conversion (exp_loc
, op
);
5168 return parser_build_unary_op (op_loc
, REALPART_EXPR
, op
);
5170 c_parser_consume_token (parser
);
5171 exp_loc
= c_parser_peek_token (parser
)->location
;
5172 op
= c_parser_cast_expression (parser
, NULL
);
5173 op
= default_function_array_conversion (exp_loc
, op
);
5174 return parser_build_unary_op (op_loc
, IMAGPART_EXPR
, op
);
5176 return c_parser_postfix_expression (parser
);
5179 return c_parser_postfix_expression (parser
);
5183 /* Parse a sizeof expression. */
5185 static struct c_expr
5186 c_parser_sizeof_expression (c_parser
*parser
)
5189 location_t expr_loc
;
5190 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SIZEOF
));
5191 c_parser_consume_token (parser
);
5192 c_inhibit_evaluation_warnings
++;
5194 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
5195 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
5197 /* Either sizeof ( type-name ) or sizeof unary-expression
5198 starting with a compound literal. */
5199 struct c_type_name
*type_name
;
5200 c_parser_consume_token (parser
);
5201 expr_loc
= c_parser_peek_token (parser
)->location
;
5202 type_name
= c_parser_type_name (parser
);
5203 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5204 if (type_name
== NULL
)
5207 c_inhibit_evaluation_warnings
--;
5209 ret
.value
= error_mark_node
;
5210 ret
.original_code
= ERROR_MARK
;
5211 ret
.original_type
= NULL
;
5214 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5216 expr
= c_parser_postfix_expression_after_paren_type (parser
,
5221 /* sizeof ( type-name ). */
5222 c_inhibit_evaluation_warnings
--;
5224 return c_expr_sizeof_type (expr_loc
, type_name
);
5228 expr_loc
= c_parser_peek_token (parser
)->location
;
5229 expr
= c_parser_unary_expression (parser
);
5231 c_inhibit_evaluation_warnings
--;
5233 if (TREE_CODE (expr
.value
) == COMPONENT_REF
5234 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
5235 error_at (expr_loc
, "%<sizeof%> applied to a bit-field");
5236 return c_expr_sizeof_expr (expr_loc
, expr
);
5240 /* Parse an alignof expression. */
5242 static struct c_expr
5243 c_parser_alignof_expression (c_parser
*parser
)
5246 location_t loc
= c_parser_peek_token (parser
)->location
;
5247 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNOF
));
5248 c_parser_consume_token (parser
);
5249 c_inhibit_evaluation_warnings
++;
5251 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
5252 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
5254 /* Either __alignof__ ( type-name ) or __alignof__
5255 unary-expression starting with a compound literal. */
5257 struct c_type_name
*type_name
;
5259 c_parser_consume_token (parser
);
5260 loc
= c_parser_peek_token (parser
)->location
;
5261 type_name
= c_parser_type_name (parser
);
5262 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5263 if (type_name
== NULL
)
5266 c_inhibit_evaluation_warnings
--;
5268 ret
.value
= error_mark_node
;
5269 ret
.original_code
= ERROR_MARK
;
5270 ret
.original_type
= NULL
;
5273 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5275 expr
= c_parser_postfix_expression_after_paren_type (parser
,
5280 /* alignof ( type-name ). */
5281 c_inhibit_evaluation_warnings
--;
5283 ret
.value
= c_alignof (loc
, groktypename (type_name
, NULL
, NULL
));
5284 ret
.original_code
= ERROR_MARK
;
5285 ret
.original_type
= NULL
;
5291 expr
= c_parser_unary_expression (parser
);
5293 c_inhibit_evaluation_warnings
--;
5295 ret
.value
= c_alignof_expr (loc
, expr
.value
);
5296 ret
.original_code
= ERROR_MARK
;
5297 ret
.original_type
= NULL
;
5302 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
5306 postfix-expression [ expression ]
5307 postfix-expression ( argument-expression-list[opt] )
5308 postfix-expression . identifier
5309 postfix-expression -> identifier
5310 postfix-expression ++
5311 postfix-expression --
5312 ( type-name ) { initializer-list }
5313 ( type-name ) { initializer-list , }
5315 argument-expression-list:
5317 argument-expression-list , argument-expression
5329 (treated as a keyword in GNU C)
5332 ( compound-statement )
5333 __builtin_va_arg ( assignment-expression , type-name )
5334 __builtin_offsetof ( type-name , offsetof-member-designator )
5335 __builtin_choose_expr ( assignment-expression ,
5336 assignment-expression ,
5337 assignment-expression )
5338 __builtin_types_compatible_p ( type-name , type-name )
5340 offsetof-member-designator:
5342 offsetof-member-designator . identifier
5343 offsetof-member-designator [ expression ]
5348 [ objc-receiver objc-message-args ]
5349 @selector ( objc-selector-arg )
5350 @protocol ( identifier )
5351 @encode ( type-name )
5355 static struct c_expr
5356 c_parser_postfix_expression (c_parser
*parser
)
5358 struct c_expr expr
, e1
, e2
, e3
;
5359 struct c_type_name
*t1
, *t2
;
5360 location_t loc
= c_parser_peek_token (parser
)->location
;;
5361 expr
.original_code
= ERROR_MARK
;
5362 expr
.original_type
= NULL
;
5363 switch (c_parser_peek_token (parser
)->type
)
5366 expr
.value
= c_parser_peek_token (parser
)->value
;
5367 loc
= c_parser_peek_token (parser
)->location
;
5368 c_parser_consume_token (parser
);
5369 if (TREE_CODE (expr
.value
) == FIXED_CST
5370 && !targetm
.fixed_point_supported_p ())
5372 error_at (loc
, "fixed-point types not supported for this target");
5373 expr
.value
= error_mark_node
;
5380 expr
.value
= c_parser_peek_token (parser
)->value
;
5381 c_parser_consume_token (parser
);
5387 case CPP_UTF8STRING
:
5388 expr
.value
= c_parser_peek_token (parser
)->value
;
5389 expr
.original_code
= STRING_CST
;
5390 c_parser_consume_token (parser
);
5392 case CPP_OBJC_STRING
:
5393 gcc_assert (c_dialect_objc ());
5395 = objc_build_string_object (c_parser_peek_token (parser
)->value
);
5396 c_parser_consume_token (parser
);
5399 if (c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
5401 c_parser_error (parser
, "expected expression");
5402 expr
.value
= error_mark_node
;
5406 tree id
= c_parser_peek_token (parser
)->value
;
5407 c_parser_consume_token (parser
);
5408 expr
.value
= build_external_ref (loc
, id
,
5409 (c_parser_peek_token (parser
)->type
5411 &expr
.original_type
);
5414 case CPP_OPEN_PAREN
:
5415 /* A parenthesized expression, statement expression or compound
5417 if (c_parser_peek_2nd_token (parser
)->type
== CPP_OPEN_BRACE
)
5419 /* A statement expression. */
5421 location_t brace_loc
;
5422 c_parser_consume_token (parser
);
5423 brace_loc
= c_parser_peek_token (parser
)->location
;
5424 c_parser_consume_token (parser
);
5425 if (cur_stmt_list
== NULL
)
5427 error_at (loc
, "braced-group within expression allowed "
5428 "only inside a function");
5429 parser
->error
= true;
5430 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
5431 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5432 expr
.value
= error_mark_node
;
5435 stmt
= c_begin_stmt_expr ();
5436 c_parser_compound_statement_nostart (parser
);
5437 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5439 pedwarn (loc
, OPT_pedantic
,
5440 "ISO C forbids braced-groups within expressions");
5441 expr
.value
= c_finish_stmt_expr (brace_loc
, stmt
);
5443 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
5445 /* A compound literal. ??? Can we actually get here rather
5446 than going directly to
5447 c_parser_postfix_expression_after_paren_type from
5450 struct c_type_name
*type_name
;
5451 c_parser_consume_token (parser
);
5452 loc
= c_parser_peek_token (parser
)->location
;
5453 type_name
= c_parser_type_name (parser
);
5454 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5456 if (type_name
== NULL
)
5458 expr
.value
= error_mark_node
;
5461 expr
= c_parser_postfix_expression_after_paren_type (parser
,
5467 /* A parenthesized expression. */
5468 c_parser_consume_token (parser
);
5469 expr
= c_parser_expression (parser
);
5470 if (TREE_CODE (expr
.value
) == MODIFY_EXPR
)
5471 TREE_NO_WARNING (expr
.value
) = 1;
5472 if (expr
.original_code
!= C_MAYBE_CONST_EXPR
)
5473 expr
.original_code
= ERROR_MARK
;
5474 /* Don't change EXPR.ORIGINAL_TYPE. */
5475 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5480 switch (c_parser_peek_token (parser
)->keyword
)
5482 case RID_FUNCTION_NAME
:
5483 case RID_PRETTY_FUNCTION_NAME
:
5484 case RID_C99_FUNCTION_NAME
:
5485 expr
.value
= fname_decl (loc
,
5486 c_parser_peek_token (parser
)->keyword
,
5487 c_parser_peek_token (parser
)->value
);
5488 c_parser_consume_token (parser
);
5491 c_parser_consume_token (parser
);
5492 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5494 expr
.value
= error_mark_node
;
5497 e1
= c_parser_expr_no_commas (parser
, NULL
);
5498 e1
.value
= c_fully_fold (e1
.value
, false, NULL
);
5499 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5501 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5502 expr
.value
= error_mark_node
;
5505 loc
= c_parser_peek_token (parser
)->location
;
5506 t1
= c_parser_type_name (parser
);
5507 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5511 expr
.value
= error_mark_node
;
5515 tree type_expr
= NULL_TREE
;
5516 expr
.value
= c_build_va_arg (loc
, e1
.value
,
5517 groktypename (t1
, &type_expr
, NULL
));
5520 expr
.value
= build2 (C_MAYBE_CONST_EXPR
,
5521 TREE_TYPE (expr
.value
), type_expr
,
5523 C_MAYBE_CONST_EXPR_NON_CONST (expr
.value
) = true;
5528 c_parser_consume_token (parser
);
5529 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5531 expr
.value
= error_mark_node
;
5534 t1
= c_parser_type_name (parser
);
5537 expr
.value
= error_mark_node
;
5540 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5542 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5543 expr
.value
= error_mark_node
;
5547 tree type
= groktypename (t1
, NULL
, NULL
);
5549 if (type
== error_mark_node
)
5550 offsetof_ref
= error_mark_node
;
5553 offsetof_ref
= build1 (INDIRECT_REF
, type
, null_pointer_node
);
5554 SET_EXPR_LOCATION (offsetof_ref
, loc
);
5556 /* Parse the second argument to __builtin_offsetof. We
5557 must have one identifier, and beyond that we want to
5558 accept sub structure and sub array references. */
5559 if (c_parser_next_token_is (parser
, CPP_NAME
))
5561 offsetof_ref
= build_component_ref
5562 (loc
, offsetof_ref
, c_parser_peek_token (parser
)->value
);
5563 c_parser_consume_token (parser
);
5564 while (c_parser_next_token_is (parser
, CPP_DOT
)
5565 || c_parser_next_token_is (parser
,
5567 || c_parser_next_token_is (parser
,
5570 if (c_parser_next_token_is (parser
, CPP_DEREF
))
5572 loc
= c_parser_peek_token (parser
)->location
;
5573 offsetof_ref
= build_array_ref (loc
,
5578 else if (c_parser_next_token_is (parser
, CPP_DOT
))
5581 c_parser_consume_token (parser
);
5582 if (c_parser_next_token_is_not (parser
,
5585 c_parser_error (parser
, "expected identifier");
5588 offsetof_ref
= build_component_ref
5590 c_parser_peek_token (parser
)->value
);
5591 c_parser_consume_token (parser
);
5596 loc
= c_parser_peek_token (parser
)->location
;
5597 c_parser_consume_token (parser
);
5598 idx
= c_parser_expression (parser
).value
;
5599 idx
= c_fully_fold (idx
, false, NULL
);
5600 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5602 offsetof_ref
= build_array_ref (loc
, offsetof_ref
, idx
);
5607 c_parser_error (parser
, "expected identifier");
5608 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5610 expr
.value
= fold_offsetof (offsetof_ref
, NULL_TREE
);
5613 case RID_CHOOSE_EXPR
:
5614 c_parser_consume_token (parser
);
5615 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5617 expr
.value
= error_mark_node
;
5620 loc
= c_parser_peek_token (parser
)->location
;
5621 e1
= c_parser_expr_no_commas (parser
, NULL
);
5622 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5624 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5625 expr
.value
= error_mark_node
;
5628 e2
= c_parser_expr_no_commas (parser
, NULL
);
5629 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5631 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5632 expr
.value
= error_mark_node
;
5635 e3
= c_parser_expr_no_commas (parser
, NULL
);
5636 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5642 if (TREE_CODE (c
) != INTEGER_CST
5643 || !INTEGRAL_TYPE_P (TREE_TYPE (c
)))
5645 "first argument to %<__builtin_choose_expr%> not"
5647 constant_expression_warning (c
);
5648 expr
= integer_zerop (c
) ? e3
: e2
;
5651 case RID_TYPES_COMPATIBLE_P
:
5652 c_parser_consume_token (parser
);
5653 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5655 expr
.value
= error_mark_node
;
5658 t1
= c_parser_type_name (parser
);
5661 expr
.value
= error_mark_node
;
5664 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5666 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5667 expr
.value
= error_mark_node
;
5670 t2
= c_parser_type_name (parser
);
5673 expr
.value
= error_mark_node
;
5676 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5681 e1
= TYPE_MAIN_VARIANT (groktypename (t1
, NULL
, NULL
));
5682 e2
= TYPE_MAIN_VARIANT (groktypename (t2
, NULL
, NULL
));
5684 expr
.value
= comptypes (e1
, e2
)
5685 ? build_int_cst (NULL_TREE
, 1)
5686 : build_int_cst (NULL_TREE
, 0);
5689 case RID_AT_SELECTOR
:
5690 gcc_assert (c_dialect_objc ());
5691 c_parser_consume_token (parser
);
5692 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5694 expr
.value
= error_mark_node
;
5698 tree sel
= c_parser_objc_selector_arg (parser
);
5699 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5701 expr
.value
= objc_build_selector_expr (loc
, sel
);
5704 case RID_AT_PROTOCOL
:
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
;
5712 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5714 c_parser_error (parser
, "expected identifier");
5715 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5716 expr
.value
= error_mark_node
;
5720 tree id
= c_parser_peek_token (parser
)->value
;
5721 c_parser_consume_token (parser
);
5722 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5724 expr
.value
= objc_build_protocol_expr (id
);
5728 /* Extension to support C-structures in the archiver. */
5729 gcc_assert (c_dialect_objc ());
5730 c_parser_consume_token (parser
);
5731 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5733 expr
.value
= error_mark_node
;
5736 t1
= c_parser_type_name (parser
);
5739 expr
.value
= error_mark_node
;
5740 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5743 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5746 tree type
= groktypename (t1
, NULL
, NULL
);
5747 expr
.value
= objc_build_encode_expr (type
);
5751 c_parser_error (parser
, "expected expression");
5752 expr
.value
= error_mark_node
;
5756 case CPP_OPEN_SQUARE
:
5757 if (c_dialect_objc ())
5759 tree receiver
, args
;
5760 c_parser_consume_token (parser
);
5761 receiver
= c_parser_objc_receiver (parser
);
5762 args
= c_parser_objc_message_args (parser
);
5763 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5765 expr
.value
= objc_build_message_expr (build_tree_list (receiver
,
5769 /* Else fall through to report error. */
5771 c_parser_error (parser
, "expected expression");
5772 expr
.value
= error_mark_node
;
5775 return c_parser_postfix_expression_after_primary (parser
, loc
, expr
);
5778 /* Parse a postfix expression after a parenthesized type name: the
5779 brace-enclosed initializer of a compound literal, possibly followed
5780 by some postfix operators. This is separate because it is not
5781 possible to tell until after the type name whether a cast
5782 expression has a cast or a compound literal, or whether the operand
5783 of sizeof is a parenthesized type name or starts with a compound
5784 literal. TYPE_LOC is the location where TYPE_NAME starts--the
5785 location of the first token after the parentheses around the type
5788 static struct c_expr
5789 c_parser_postfix_expression_after_paren_type (c_parser
*parser
,
5790 struct c_type_name
*type_name
,
5791 location_t type_loc
)
5797 location_t start_loc
;
5798 tree type_expr
= NULL_TREE
;
5799 bool type_expr_const
= true;
5800 check_compound_literal_type (type_loc
, type_name
);
5801 start_init (NULL_TREE
, NULL
, 0);
5802 type
= groktypename (type_name
, &type_expr
, &type_expr_const
);
5803 start_loc
= c_parser_peek_token (parser
)->location
;
5804 if (type
!= error_mark_node
&& C_TYPE_VARIABLE_SIZE (type
))
5806 error_at (type_loc
, "compound literal has variable size");
5807 type
= error_mark_node
;
5809 init
= c_parser_braced_init (parser
, type
, false);
5811 maybe_warn_string_init (type
, init
);
5813 if (type
!= error_mark_node
5814 && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type
))
5815 && current_function_decl
)
5817 error ("compound literal qualified by address-space qualifier");
5818 type
= error_mark_node
;
5822 pedwarn (start_loc
, OPT_pedantic
, "ISO C90 forbids compound literals");
5823 non_const
= ((init
.value
&& TREE_CODE (init
.value
) == CONSTRUCTOR
)
5824 ? CONSTRUCTOR_NON_CONST (init
.value
)
5825 : init
.original_code
== C_MAYBE_CONST_EXPR
);
5826 non_const
|= !type_expr_const
;
5827 expr
.value
= build_compound_literal (start_loc
, type
, init
.value
, non_const
);
5828 expr
.original_code
= ERROR_MARK
;
5829 expr
.original_type
= NULL
;
5832 if (TREE_CODE (expr
.value
) == C_MAYBE_CONST_EXPR
)
5834 gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr
.value
) == NULL_TREE
);
5835 C_MAYBE_CONST_EXPR_PRE (expr
.value
) = type_expr
;
5839 gcc_assert (!non_const
);
5840 expr
.value
= build2 (C_MAYBE_CONST_EXPR
, type
,
5841 type_expr
, expr
.value
);
5844 return c_parser_postfix_expression_after_primary (parser
, start_loc
, expr
);
5847 /* Parse a postfix expression after the initial primary or compound
5848 literal; that is, parse a series of postfix operators.
5850 EXPR_LOC is the location of the primary expression. */
5852 static struct c_expr
5853 c_parser_postfix_expression_after_primary (c_parser
*parser
,
5854 location_t expr_loc
,
5857 struct c_expr orig_expr
;
5859 VEC(tree
,gc
) *exprlist
;
5860 VEC(tree
,gc
) *origtypes
;
5863 location_t op_loc
= c_parser_peek_token (parser
)->location
;
5864 switch (c_parser_peek_token (parser
)->type
)
5866 case CPP_OPEN_SQUARE
:
5867 /* Array reference. */
5868 c_parser_consume_token (parser
);
5869 idx
= c_parser_expression (parser
).value
;
5870 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5872 expr
.value
= build_array_ref (op_loc
, expr
.value
, idx
);
5873 expr
.original_code
= ERROR_MARK
;
5874 expr
.original_type
= NULL
;
5876 case CPP_OPEN_PAREN
:
5877 /* Function call. */
5878 c_parser_consume_token (parser
);
5879 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
5882 exprlist
= c_parser_expr_list (parser
, true, false, &origtypes
);
5883 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5886 /* FIXME diagnostics: Ideally we want the FUNCNAME, not the
5887 "(" after the FUNCNAME, which is what we have now. */
5888 expr
.value
= build_function_call_vec (op_loc
, expr
.value
, exprlist
,
5890 expr
.original_code
= ERROR_MARK
;
5891 if (TREE_CODE (expr
.value
) == INTEGER_CST
5892 && TREE_CODE (orig_expr
.value
) == FUNCTION_DECL
5893 && DECL_BUILT_IN_CLASS (orig_expr
.value
) == BUILT_IN_NORMAL
5894 && DECL_FUNCTION_CODE (orig_expr
.value
) == BUILT_IN_CONSTANT_P
)
5895 expr
.original_code
= C_MAYBE_CONST_EXPR
;
5896 expr
.original_type
= NULL
;
5897 if (exprlist
!= NULL
)
5899 release_tree_vector (exprlist
);
5900 release_tree_vector (origtypes
);
5904 /* Structure element reference. */
5905 c_parser_consume_token (parser
);
5906 expr
= default_function_array_conversion (expr_loc
, expr
);
5907 if (c_parser_next_token_is (parser
, CPP_NAME
))
5908 ident
= c_parser_peek_token (parser
)->value
;
5911 c_parser_error (parser
, "expected identifier");
5912 expr
.value
= error_mark_node
;
5913 expr
.original_code
= ERROR_MARK
;
5914 expr
.original_type
= NULL
;
5917 c_parser_consume_token (parser
);
5918 expr
.value
= build_component_ref (op_loc
, expr
.value
, ident
);
5919 expr
.original_code
= ERROR_MARK
;
5920 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
5921 expr
.original_type
= NULL
;
5924 /* Remember the original type of a bitfield. */
5925 tree field
= TREE_OPERAND (expr
.value
, 1);
5926 if (TREE_CODE (field
) != FIELD_DECL
)
5927 expr
.original_type
= NULL
;
5929 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
5933 /* Structure element reference. */
5934 c_parser_consume_token (parser
);
5935 expr
= default_function_array_conversion (expr_loc
, expr
);
5936 if (c_parser_next_token_is (parser
, CPP_NAME
))
5937 ident
= c_parser_peek_token (parser
)->value
;
5940 c_parser_error (parser
, "expected identifier");
5941 expr
.value
= error_mark_node
;
5942 expr
.original_code
= ERROR_MARK
;
5943 expr
.original_type
= NULL
;
5946 c_parser_consume_token (parser
);
5947 expr
.value
= build_component_ref (op_loc
,
5948 build_indirect_ref (op_loc
,
5952 expr
.original_code
= ERROR_MARK
;
5953 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
5954 expr
.original_type
= NULL
;
5957 /* Remember the original type of a bitfield. */
5958 tree field
= TREE_OPERAND (expr
.value
, 1);
5959 if (TREE_CODE (field
) != FIELD_DECL
)
5960 expr
.original_type
= NULL
;
5962 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
5966 /* Postincrement. */
5967 c_parser_consume_token (parser
);
5968 expr
= default_function_array_conversion (expr_loc
, expr
);
5969 expr
.value
= build_unary_op (op_loc
,
5970 POSTINCREMENT_EXPR
, expr
.value
, 0);
5971 expr
.original_code
= ERROR_MARK
;
5972 expr
.original_type
= NULL
;
5974 case CPP_MINUS_MINUS
:
5975 /* Postdecrement. */
5976 c_parser_consume_token (parser
);
5977 expr
= default_function_array_conversion (expr_loc
, expr
);
5978 expr
.value
= build_unary_op (op_loc
,
5979 POSTDECREMENT_EXPR
, expr
.value
, 0);
5980 expr
.original_code
= ERROR_MARK
;
5981 expr
.original_type
= NULL
;
5989 /* Parse an expression (C90 6.3.17, C99 6.5.17).
5992 assignment-expression
5993 expression , assignment-expression
5996 static struct c_expr
5997 c_parser_expression (c_parser
*parser
)
6000 expr
= c_parser_expr_no_commas (parser
, NULL
);
6001 while (c_parser_next_token_is (parser
, CPP_COMMA
))
6004 location_t loc
= c_parser_peek_token (parser
)->location
;
6005 location_t expr_loc
;
6006 c_parser_consume_token (parser
);
6007 expr_loc
= c_parser_peek_token (parser
)->location
;
6008 next
= c_parser_expr_no_commas (parser
, NULL
);
6009 next
= default_function_array_conversion (expr_loc
, next
);
6010 expr
.value
= build_compound_expr (loc
, expr
.value
, next
.value
);
6011 expr
.original_code
= COMPOUND_EXPR
;
6012 expr
.original_type
= next
.original_type
;
6017 /* Parse an expression and convert functions or arrays to
6020 static struct c_expr
6021 c_parser_expression_conv (c_parser
*parser
)
6024 location_t loc
= c_parser_peek_token (parser
)->location
;
6025 expr
= c_parser_expression (parser
);
6026 expr
= default_function_array_conversion (loc
, expr
);
6030 /* Parse a non-empty list of expressions. If CONVERT_P, convert
6031 functions and arrays to pointers. If FOLD_P, fold the expressions.
6034 assignment-expression
6035 nonempty-expr-list , assignment-expression
6038 static VEC(tree
,gc
) *
6039 c_parser_expr_list (c_parser
*parser
, bool convert_p
, bool fold_p
,
6040 VEC(tree
,gc
) **p_orig_types
)
6043 VEC(tree
,gc
) *orig_types
;
6045 location_t loc
= c_parser_peek_token (parser
)->location
;
6047 ret
= make_tree_vector ();
6048 if (p_orig_types
== NULL
)
6051 orig_types
= make_tree_vector ();
6053 expr
= c_parser_expr_no_commas (parser
, NULL
);
6055 expr
= default_function_array_conversion (loc
, expr
);
6057 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
6058 VEC_quick_push (tree
, ret
, expr
.value
);
6059 if (orig_types
!= NULL
)
6060 VEC_quick_push (tree
, orig_types
, expr
.original_type
);
6061 while (c_parser_next_token_is (parser
, CPP_COMMA
))
6063 c_parser_consume_token (parser
);
6064 loc
= c_parser_peek_token (parser
)->location
;
6065 expr
= c_parser_expr_no_commas (parser
, NULL
);
6067 expr
= default_function_array_conversion (loc
, expr
);
6069 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
6070 VEC_safe_push (tree
, gc
, ret
, expr
.value
);
6071 if (orig_types
!= NULL
)
6072 VEC_safe_push (tree
, gc
, orig_types
, expr
.original_type
);
6074 if (orig_types
!= NULL
)
6075 *p_orig_types
= orig_types
;
6079 /* Parse Objective-C-specific constructs. */
6081 /* Parse an objc-class-definition.
6083 objc-class-definition:
6084 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
6085 objc-class-instance-variables[opt] objc-methodprotolist @end
6086 @implementation identifier objc-superclass[opt]
6087 objc-class-instance-variables[opt]
6088 @interface identifier ( identifier ) objc-protocol-refs[opt]
6089 objc-methodprotolist @end
6090 @implementation identifier ( identifier )
6095 "@interface identifier (" must start "@interface identifier (
6096 identifier ) ...": objc-methodprotolist in the first production may
6097 not start with a parenthesized identifier as a declarator of a data
6098 definition with no declaration specifiers if the objc-superclass,
6099 objc-protocol-refs and objc-class-instance-variables are omitted. */
6102 c_parser_objc_class_definition (c_parser
*parser
)
6107 if (c_parser_next_token_is_keyword (parser
, RID_AT_INTERFACE
))
6109 else if (c_parser_next_token_is_keyword (parser
, RID_AT_IMPLEMENTATION
))
6113 c_parser_consume_token (parser
);
6114 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6116 c_parser_error (parser
, "expected identifier");
6119 id1
= c_parser_peek_token (parser
)->value
;
6120 c_parser_consume_token (parser
);
6121 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
6124 tree proto
= NULL_TREE
;
6125 c_parser_consume_token (parser
);
6126 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6128 c_parser_error (parser
, "expected identifier");
6129 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6132 id2
= c_parser_peek_token (parser
)->value
;
6133 c_parser_consume_token (parser
);
6134 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6137 objc_start_category_implementation (id1
, id2
);
6140 if (c_parser_next_token_is (parser
, CPP_LESS
))
6141 proto
= c_parser_objc_protocol_refs (parser
);
6142 objc_start_category_interface (id1
, id2
, proto
);
6143 c_parser_objc_methodprotolist (parser
);
6144 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
6145 objc_finish_interface ();
6148 if (c_parser_next_token_is (parser
, CPP_COLON
))
6150 c_parser_consume_token (parser
);
6151 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6153 c_parser_error (parser
, "expected identifier");
6156 superclass
= c_parser_peek_token (parser
)->value
;
6157 c_parser_consume_token (parser
);
6160 superclass
= NULL_TREE
;
6163 tree proto
= NULL_TREE
;
6164 if (c_parser_next_token_is (parser
, CPP_LESS
))
6165 proto
= c_parser_objc_protocol_refs (parser
);
6166 objc_start_class_interface (id1
, superclass
, proto
);
6169 objc_start_class_implementation (id1
, superclass
);
6170 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6171 c_parser_objc_class_instance_variables (parser
);
6174 objc_continue_interface ();
6175 c_parser_objc_methodprotolist (parser
);
6176 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
6177 objc_finish_interface ();
6181 objc_continue_implementation ();
6186 /* Parse objc-class-instance-variables.
6188 objc-class-instance-variables:
6189 { objc-instance-variable-decl-list[opt] }
6191 objc-instance-variable-decl-list:
6192 objc-visibility-spec
6193 objc-instance-variable-decl ;
6195 objc-instance-variable-decl-list objc-visibility-spec
6196 objc-instance-variable-decl-list objc-instance-variable-decl ;
6197 objc-instance-variable-decl-list ;
6199 objc-visibility-spec:
6204 objc-instance-variable-decl:
6209 c_parser_objc_class_instance_variables (c_parser
*parser
)
6211 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
6212 c_parser_consume_token (parser
);
6213 while (c_parser_next_token_is_not (parser
, CPP_EOF
))
6216 /* Parse any stray semicolon. */
6217 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
6219 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
6220 "extra semicolon in struct or union specified");
6221 c_parser_consume_token (parser
);
6224 /* Stop if at the end of the instance variables. */
6225 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
6227 c_parser_consume_token (parser
);
6230 /* Parse any objc-visibility-spec. */
6231 if (c_parser_next_token_is_keyword (parser
, RID_PRIVATE
))
6233 c_parser_consume_token (parser
);
6234 objc_set_visibility (2);
6237 else if (c_parser_next_token_is_keyword (parser
, RID_PROTECTED
))
6239 c_parser_consume_token (parser
);
6240 objc_set_visibility (0);
6243 else if (c_parser_next_token_is_keyword (parser
, RID_PUBLIC
))
6245 c_parser_consume_token (parser
);
6246 objc_set_visibility (1);
6249 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
6251 c_parser_pragma (parser
, pragma_external
);
6255 /* Parse some comma-separated declarations. */
6256 decls
= c_parser_struct_declaration (parser
);
6258 /* Comma-separated instance variables are chained together in
6259 reverse order; add them one by one. */
6260 tree ivar
= nreverse (decls
);
6261 for (; ivar
; ivar
= TREE_CHAIN (ivar
))
6262 objc_add_instance_variable (copy_node (ivar
));
6264 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
6268 /* Parse an objc-class-declaration.
6270 objc-class-declaration:
6271 @class identifier-list ;
6275 c_parser_objc_class_declaration (c_parser
*parser
)
6277 tree list
= NULL_TREE
;
6278 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_CLASS
));
6279 c_parser_consume_token (parser
);
6280 /* Any identifiers, including those declared as type names, are OK
6285 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6287 c_parser_error (parser
, "expected identifier");
6290 id
= c_parser_peek_token (parser
)->value
;
6291 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
6292 c_parser_consume_token (parser
);
6293 if (c_parser_next_token_is (parser
, CPP_COMMA
))
6294 c_parser_consume_token (parser
);
6298 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
6299 objc_declare_class (list
);
6302 /* Parse an objc-alias-declaration.
6304 objc-alias-declaration:
6305 @compatibility_alias identifier identifier ;
6309 c_parser_objc_alias_declaration (c_parser
*parser
)
6312 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_ALIAS
));
6313 c_parser_consume_token (parser
);
6314 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6316 c_parser_error (parser
, "expected identifier");
6317 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
6320 id1
= c_parser_peek_token (parser
)->value
;
6321 c_parser_consume_token (parser
);
6322 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6324 c_parser_error (parser
, "expected identifier");
6325 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
6328 id2
= c_parser_peek_token (parser
)->value
;
6329 c_parser_consume_token (parser
);
6330 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
6331 objc_declare_alias (id1
, id2
);
6334 /* Parse an objc-protocol-definition.
6336 objc-protocol-definition:
6337 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
6338 @protocol identifier-list ;
6340 "@protocol identifier ;" should be resolved as "@protocol
6341 identifier-list ;": objc-methodprotolist may not start with a
6342 semicolon in the first alternative if objc-protocol-refs are
6346 c_parser_objc_protocol_definition (c_parser
*parser
)
6348 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROTOCOL
));
6349 c_parser_consume_token (parser
);
6350 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6352 c_parser_error (parser
, "expected identifier");
6355 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
6356 || c_parser_peek_2nd_token (parser
)->type
== CPP_SEMICOLON
)
6358 tree list
= NULL_TREE
;
6359 /* Any identifiers, including those declared as type names, are
6364 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6366 c_parser_error (parser
, "expected identifier");
6369 id
= c_parser_peek_token (parser
)->value
;
6370 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
6371 c_parser_consume_token (parser
);
6372 if (c_parser_next_token_is (parser
, CPP_COMMA
))
6373 c_parser_consume_token (parser
);
6377 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
6378 objc_declare_protocols (list
);
6382 tree id
= c_parser_peek_token (parser
)->value
;
6383 tree proto
= NULL_TREE
;
6384 c_parser_consume_token (parser
);
6385 if (c_parser_next_token_is (parser
, CPP_LESS
))
6386 proto
= c_parser_objc_protocol_refs (parser
);
6387 parser
->objc_pq_context
= true;
6388 objc_start_protocol (id
, proto
);
6389 c_parser_objc_methodprotolist (parser
);
6390 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
6391 parser
->objc_pq_context
= false;
6392 objc_finish_interface ();
6396 /* Parse an objc-method-type.
6403 static enum tree_code
6404 c_parser_objc_method_type (c_parser
*parser
)
6406 switch (c_parser_peek_token (parser
)->type
)
6409 c_parser_consume_token (parser
);
6412 c_parser_consume_token (parser
);
6419 /* Parse an objc-method-definition.
6421 objc-method-definition:
6422 objc-method-type objc-method-decl ;[opt] compound-statement
6426 c_parser_objc_method_definition (c_parser
*parser
)
6428 enum tree_code type
= c_parser_objc_method_type (parser
);
6430 objc_set_method_type (type
);
6431 parser
->objc_pq_context
= true;
6432 decl
= c_parser_objc_method_decl (parser
);
6433 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
6435 c_parser_consume_token (parser
);
6436 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
6437 "extra semicolon in method definition specified");
6439 if (!c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6441 c_parser_error (parser
, "expected %<{%>");
6444 parser
->objc_pq_context
= false;
6445 objc_start_method_definition (decl
);
6446 add_stmt (c_parser_compound_statement (parser
));
6447 objc_finish_method_definition (current_function_decl
);
6450 /* Parse an objc-methodprotolist.
6452 objc-methodprotolist:
6454 objc-methodprotolist objc-methodproto
6455 objc-methodprotolist declaration
6456 objc-methodprotolist ;
6458 The declaration is a data definition, which may be missing
6459 declaration specifiers under the same rules and diagnostics as
6460 other data definitions outside functions, and the stray semicolon
6461 is diagnosed the same way as a stray semicolon outside a
6465 c_parser_objc_methodprotolist (c_parser
*parser
)
6469 /* The list is terminated by @end. */
6470 switch (c_parser_peek_token (parser
)->type
)
6473 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
6474 "ISO C does not allow extra %<;%> outside of a function");
6475 c_parser_consume_token (parser
);
6479 c_parser_objc_methodproto (parser
);
6482 c_parser_pragma (parser
, pragma_external
);
6487 if (c_parser_next_token_is_keyword (parser
, RID_AT_END
))
6489 c_parser_declaration_or_fndef (parser
, false, true, false, true);
6495 /* Parse an objc-methodproto.
6498 objc-method-type objc-method-decl ;
6502 c_parser_objc_methodproto (c_parser
*parser
)
6504 enum tree_code type
= c_parser_objc_method_type (parser
);
6506 objc_set_method_type (type
);
6507 /* Remember protocol qualifiers in prototypes. */
6508 parser
->objc_pq_context
= true;
6509 decl
= c_parser_objc_method_decl (parser
);
6510 /* Forget protocol qualifiers here. */
6511 parser
->objc_pq_context
= false;
6512 objc_add_method_declaration (decl
);
6513 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
6516 /* Parse an objc-method-decl.
6519 ( objc-type-name ) objc-selector
6521 ( objc-type-name ) objc-keyword-selector objc-optparmlist
6522 objc-keyword-selector objc-optparmlist
6524 objc-keyword-selector:
6526 objc-keyword-selector objc-keyword-decl
6529 objc-selector : ( objc-type-name ) identifier
6530 objc-selector : identifier
6531 : ( objc-type-name ) identifier
6535 objc-optparms objc-optellipsis
6539 objc-opt-parms , parameter-declaration
6547 c_parser_objc_method_decl (c_parser
*parser
)
6549 tree type
= NULL_TREE
;
6551 tree parms
= NULL_TREE
;
6552 bool ellipsis
= false;
6554 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
6556 c_parser_consume_token (parser
);
6557 type
= c_parser_objc_type_name (parser
);
6558 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6560 sel
= c_parser_objc_selector (parser
);
6561 /* If there is no selector, or a colon follows, we have an
6562 objc-keyword-selector. If there is a selector, and a colon does
6563 not follow, that selector ends the objc-method-decl. */
6564 if (!sel
|| c_parser_next_token_is (parser
, CPP_COLON
))
6567 tree list
= NULL_TREE
;
6570 tree atype
= NULL_TREE
, id
, keyworddecl
;
6571 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6573 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
6575 c_parser_consume_token (parser
);
6576 atype
= c_parser_objc_type_name (parser
);
6577 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6580 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6582 c_parser_error (parser
, "expected identifier");
6583 return error_mark_node
;
6585 id
= c_parser_peek_token (parser
)->value
;
6586 c_parser_consume_token (parser
);
6587 keyworddecl
= objc_build_keyword_decl (tsel
, atype
, id
);
6588 list
= chainon (list
, keyworddecl
);
6589 tsel
= c_parser_objc_selector (parser
);
6590 if (!tsel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6593 /* Parse the optional parameter list. Optional Objective-C
6594 method parameters follow the C syntax, and may include '...'
6595 to denote a variable number of arguments. */
6596 parms
= make_node (TREE_LIST
);
6597 while (c_parser_next_token_is (parser
, CPP_COMMA
))
6599 struct c_parm
*parm
;
6600 c_parser_consume_token (parser
);
6601 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
6604 c_parser_consume_token (parser
);
6607 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
6610 parms
= chainon (parms
,
6611 build_tree_list (NULL_TREE
, grokparm (parm
)));
6615 return objc_build_method_signature (type
, sel
, parms
, ellipsis
);
6618 /* Parse an objc-type-name.
6621 objc-type-qualifiers[opt] type-name
6622 objc-type-qualifiers[opt]
6624 objc-type-qualifiers:
6626 objc-type-qualifiers objc-type-qualifier
6628 objc-type-qualifier: one of
6629 in out inout bycopy byref oneway
6633 c_parser_objc_type_name (c_parser
*parser
)
6635 tree quals
= NULL_TREE
;
6636 struct c_type_name
*type_name
= NULL
;
6637 tree type
= NULL_TREE
;
6640 c_token
*token
= c_parser_peek_token (parser
);
6641 if (token
->type
== CPP_KEYWORD
6642 && (token
->keyword
== RID_IN
6643 || token
->keyword
== RID_OUT
6644 || token
->keyword
== RID_INOUT
6645 || token
->keyword
== RID_BYCOPY
6646 || token
->keyword
== RID_BYREF
6647 || token
->keyword
== RID_ONEWAY
))
6649 quals
= chainon (quals
, build_tree_list (NULL_TREE
, token
->value
));
6650 c_parser_consume_token (parser
);
6655 if (c_parser_next_token_starts_typename (parser
))
6656 type_name
= c_parser_type_name (parser
);
6658 type
= groktypename (type_name
, NULL
, NULL
);
6659 return build_tree_list (quals
, type
);
6662 /* Parse objc-protocol-refs.
6669 c_parser_objc_protocol_refs (c_parser
*parser
)
6671 tree list
= NULL_TREE
;
6672 gcc_assert (c_parser_next_token_is (parser
, CPP_LESS
));
6673 c_parser_consume_token (parser
);
6674 /* Any identifiers, including those declared as type names, are OK
6679 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6681 c_parser_error (parser
, "expected identifier");
6684 id
= c_parser_peek_token (parser
)->value
;
6685 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
6686 c_parser_consume_token (parser
);
6687 if (c_parser_next_token_is (parser
, CPP_COMMA
))
6688 c_parser_consume_token (parser
);
6692 c_parser_require (parser
, CPP_GREATER
, "expected %<>%>");
6696 /* Parse an objc-try-catch-statement.
6698 objc-try-catch-statement:
6699 @try compound-statement objc-catch-list[opt]
6700 @try compound-statement objc-catch-list[opt] @finally compound-statement
6703 @catch ( parameter-declaration ) compound-statement
6704 objc-catch-list @catch ( parameter-declaration ) compound-statement
6708 c_parser_objc_try_catch_statement (c_parser
*parser
)
6712 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TRY
));
6713 c_parser_consume_token (parser
);
6714 loc
= c_parser_peek_token (parser
)->location
;
6715 stmt
= c_parser_compound_statement (parser
);
6716 objc_begin_try_stmt (loc
, stmt
);
6717 while (c_parser_next_token_is_keyword (parser
, RID_CATCH
))
6719 struct c_parm
*parm
;
6720 c_parser_consume_token (parser
);
6721 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6723 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
6726 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6729 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6730 objc_begin_catch_clause (grokparm (parm
));
6731 if (c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
6732 c_parser_compound_statement_nostart (parser
);
6733 objc_finish_catch_clause ();
6735 if (c_parser_next_token_is_keyword (parser
, RID_AT_FINALLY
))
6739 c_parser_consume_token (parser
);
6740 finloc
= c_parser_peek_token (parser
)->location
;
6741 finstmt
= c_parser_compound_statement (parser
);
6742 objc_build_finally_clause (finloc
, finstmt
);
6744 objc_finish_try_stmt ();
6747 /* Parse an objc-synchronized-statement.
6749 objc-synchronized-statement:
6750 @synchronized ( expression ) compound-statement
6754 c_parser_objc_synchronized_statement (c_parser
*parser
)
6758 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNCHRONIZED
));
6759 c_parser_consume_token (parser
);
6760 loc
= c_parser_peek_token (parser
)->location
;
6761 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6763 expr
= c_parser_expression (parser
).value
;
6764 expr
= c_fully_fold (expr
, false, NULL
);
6765 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6768 expr
= error_mark_node
;
6769 stmt
= c_parser_compound_statement (parser
);
6770 objc_build_synchronized (loc
, expr
, stmt
);
6773 /* Parse an objc-selector; return NULL_TREE without an error if the
6774 next token is not an objc-selector.
6779 enum struct union if else while do for switch case default
6780 break continue return goto asm sizeof typeof __alignof
6781 unsigned long const short volatile signed restrict _Complex
6782 in out inout bycopy byref oneway int char float double void _Bool
6784 ??? Why this selection of keywords but not, for example, storage
6785 class specifiers? */
6788 c_parser_objc_selector (c_parser
*parser
)
6790 c_token
*token
= c_parser_peek_token (parser
);
6791 tree value
= token
->value
;
6792 if (token
->type
== CPP_NAME
)
6794 c_parser_consume_token (parser
);
6797 if (token
->type
!= CPP_KEYWORD
)
6799 switch (token
->keyword
)
6840 c_parser_consume_token (parser
);
6847 /* Parse an objc-selector-arg.
6851 objc-keywordname-list
6853 objc-keywordname-list:
6855 objc-keywordname-list objc-keywordname
6863 c_parser_objc_selector_arg (c_parser
*parser
)
6865 tree sel
= c_parser_objc_selector (parser
);
6866 tree list
= NULL_TREE
;
6867 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6871 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6873 list
= chainon (list
, build_tree_list (sel
, NULL_TREE
));
6874 sel
= c_parser_objc_selector (parser
);
6875 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6881 /* Parse an objc-receiver.
6890 c_parser_objc_receiver (c_parser
*parser
)
6892 if (c_parser_peek_token (parser
)->type
== CPP_NAME
6893 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
6894 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
6896 tree id
= c_parser_peek_token (parser
)->value
;
6897 c_parser_consume_token (parser
);
6898 return objc_get_class_reference (id
);
6900 return c_fully_fold (c_parser_expression (parser
).value
, false, NULL
);
6903 /* Parse objc-message-args.
6907 objc-keywordarg-list
6909 objc-keywordarg-list:
6911 objc-keywordarg-list objc-keywordarg
6914 objc-selector : objc-keywordexpr
6919 c_parser_objc_message_args (c_parser
*parser
)
6921 tree sel
= c_parser_objc_selector (parser
);
6922 tree list
= NULL_TREE
;
6923 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6928 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6929 return error_mark_node
;
6930 keywordexpr
= c_parser_objc_keywordexpr (parser
);
6931 list
= chainon (list
, build_tree_list (sel
, keywordexpr
));
6932 sel
= c_parser_objc_selector (parser
);
6933 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6939 /* Parse an objc-keywordexpr.
6946 c_parser_objc_keywordexpr (c_parser
*parser
)
6949 VEC(tree
,gc
) *expr_list
= c_parser_expr_list (parser
, true, true, NULL
);
6950 if (VEC_length (tree
, expr_list
) == 1)
6952 /* Just return the expression, remove a level of
6954 ret
= VEC_index (tree
, expr_list
, 0);
6958 /* We have a comma expression, we will collapse later. */
6959 ret
= build_tree_list_vec (expr_list
);
6961 release_tree_vector (expr_list
);
6966 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
6967 should be considered, statements. ALLOW_STMT is true if we're within
6968 the context of a function and such pragmas are to be allowed. Returns
6969 true if we actually parsed such a pragma. */
6972 c_parser_pragma (c_parser
*parser
, enum pragma_context context
)
6976 id
= c_parser_peek_token (parser
)->pragma_kind
;
6977 gcc_assert (id
!= PRAGMA_NONE
);
6981 case PRAGMA_OMP_BARRIER
:
6982 if (context
!= pragma_compound
)
6984 if (context
== pragma_stmt
)
6985 c_parser_error (parser
, "%<#pragma omp barrier%> may only be "
6986 "used in compound statements");
6989 c_parser_omp_barrier (parser
);
6992 case PRAGMA_OMP_FLUSH
:
6993 if (context
!= pragma_compound
)
6995 if (context
== pragma_stmt
)
6996 c_parser_error (parser
, "%<#pragma omp flush%> may only be "
6997 "used in compound statements");
7000 c_parser_omp_flush (parser
);
7003 case PRAGMA_OMP_TASKWAIT
:
7004 if (context
!= pragma_compound
)
7006 if (context
== pragma_stmt
)
7007 c_parser_error (parser
, "%<#pragma omp taskwait%> may only be "
7008 "used in compound statements");
7011 c_parser_omp_taskwait (parser
);
7014 case PRAGMA_OMP_THREADPRIVATE
:
7015 c_parser_omp_threadprivate (parser
);
7018 case PRAGMA_OMP_SECTION
:
7019 error_at (c_parser_peek_token (parser
)->location
,
7020 "%<#pragma omp section%> may only be used in "
7021 "%<#pragma omp sections%> construct");
7022 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
7025 case PRAGMA_GCC_PCH_PREPROCESS
:
7026 c_parser_error (parser
, "%<#pragma GCC pch_preprocess%> must be first");
7027 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
7031 if (id
< PRAGMA_FIRST_EXTERNAL
)
7033 if (context
== pragma_external
)
7036 c_parser_error (parser
, "expected declaration specifiers");
7037 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
7040 c_parser_omp_construct (parser
);
7046 c_parser_consume_pragma (parser
);
7047 c_invoke_pragma_handler (id
);
7049 /* Skip to EOL, but suppress any error message. Those will have been
7050 generated by the handler routine through calling error, as opposed
7051 to calling c_parser_error. */
7052 parser
->error
= true;
7053 c_parser_skip_to_pragma_eol (parser
);
7058 /* The interface the pragma parsers have to the lexer. */
7061 pragma_lex (tree
*value
)
7063 c_token
*tok
= c_parser_peek_token (the_parser
);
7064 enum cpp_ttype ret
= tok
->type
;
7066 *value
= tok
->value
;
7067 if (ret
== CPP_PRAGMA_EOL
|| ret
== CPP_EOF
)
7071 if (ret
== CPP_KEYWORD
)
7073 c_parser_consume_token (the_parser
);
7080 c_parser_pragma_pch_preprocess (c_parser
*parser
)
7084 c_parser_consume_pragma (parser
);
7085 if (c_parser_next_token_is (parser
, CPP_STRING
))
7087 name
= c_parser_peek_token (parser
)->value
;
7088 c_parser_consume_token (parser
);
7091 c_parser_error (parser
, "expected string literal");
7092 c_parser_skip_to_pragma_eol (parser
);
7095 c_common_pch_pragma (parse_in
, TREE_STRING_POINTER (name
));
7098 /* OpenMP 2.5 parsing routines. */
7100 /* Returns name of the next clause.
7101 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
7102 the token is not consumed. Otherwise appropriate pragma_omp_clause is
7103 returned and the token is consumed. */
7105 static pragma_omp_clause
7106 c_parser_omp_clause_name (c_parser
*parser
)
7108 pragma_omp_clause result
= PRAGMA_OMP_CLAUSE_NONE
;
7110 if (c_parser_next_token_is_keyword (parser
, RID_IF
))
7111 result
= PRAGMA_OMP_CLAUSE_IF
;
7112 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
7113 result
= PRAGMA_OMP_CLAUSE_DEFAULT
;
7114 else if (c_parser_next_token_is (parser
, CPP_NAME
))
7116 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
7121 if (!strcmp ("collapse", p
))
7122 result
= PRAGMA_OMP_CLAUSE_COLLAPSE
;
7123 else if (!strcmp ("copyin", p
))
7124 result
= PRAGMA_OMP_CLAUSE_COPYIN
;
7125 else if (!strcmp ("copyprivate", p
))
7126 result
= PRAGMA_OMP_CLAUSE_COPYPRIVATE
;
7129 if (!strcmp ("firstprivate", p
))
7130 result
= PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
;
7133 if (!strcmp ("lastprivate", p
))
7134 result
= PRAGMA_OMP_CLAUSE_LASTPRIVATE
;
7137 if (!strcmp ("nowait", p
))
7138 result
= PRAGMA_OMP_CLAUSE_NOWAIT
;
7139 else if (!strcmp ("num_threads", p
))
7140 result
= PRAGMA_OMP_CLAUSE_NUM_THREADS
;
7143 if (!strcmp ("ordered", p
))
7144 result
= PRAGMA_OMP_CLAUSE_ORDERED
;
7147 if (!strcmp ("private", p
))
7148 result
= PRAGMA_OMP_CLAUSE_PRIVATE
;
7151 if (!strcmp ("reduction", p
))
7152 result
= PRAGMA_OMP_CLAUSE_REDUCTION
;
7155 if (!strcmp ("schedule", p
))
7156 result
= PRAGMA_OMP_CLAUSE_SCHEDULE
;
7157 else if (!strcmp ("shared", p
))
7158 result
= PRAGMA_OMP_CLAUSE_SHARED
;
7161 if (!strcmp ("untied", p
))
7162 result
= PRAGMA_OMP_CLAUSE_UNTIED
;
7167 if (result
!= PRAGMA_OMP_CLAUSE_NONE
)
7168 c_parser_consume_token (parser
);
7173 /* Validate that a clause of the given type does not already exist. */
7176 check_no_duplicate_clause (tree clauses
, enum omp_clause_code code
,
7181 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
7182 if (OMP_CLAUSE_CODE (c
) == code
)
7184 location_t loc
= OMP_CLAUSE_LOCATION (c
);
7185 error_at (loc
, "too many %qs clauses", name
);
7193 variable-list , identifier
7195 If KIND is nonzero, create the appropriate node and install the
7196 decl in OMP_CLAUSE_DECL and add the node to the head of the list.
7197 If KIND is nonzero, CLAUSE_LOC is the location of the clause.
7199 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
7200 return the list created. */
7203 c_parser_omp_variable_list (c_parser
*parser
,
7204 location_t clause_loc
,
7205 enum omp_clause_code kind
,
7208 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
7209 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
7210 c_parser_error (parser
, "expected identifier");
7212 while (c_parser_next_token_is (parser
, CPP_NAME
)
7213 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
7215 tree t
= lookup_name (c_parser_peek_token (parser
)->value
);
7218 undeclared_variable (c_parser_peek_token (parser
)->location
,
7219 c_parser_peek_token (parser
)->value
);
7220 else if (t
== error_mark_node
)
7224 tree u
= build_omp_clause (clause_loc
, kind
);
7225 OMP_CLAUSE_DECL (u
) = t
;
7226 OMP_CLAUSE_CHAIN (u
) = list
;
7230 list
= tree_cons (t
, NULL_TREE
, list
);
7232 c_parser_consume_token (parser
);
7234 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
7237 c_parser_consume_token (parser
);
7243 /* Similarly, but expect leading and trailing parenthesis. This is a very
7244 common case for omp clauses. */
7247 c_parser_omp_var_list_parens (c_parser
*parser
, enum omp_clause_code kind
,
7250 /* The clauses location. */
7251 location_t loc
= c_parser_peek_token (parser
)->location
;
7253 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7255 list
= c_parser_omp_variable_list (parser
, loc
, kind
, list
);
7256 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7262 collapse ( constant-expression ) */
7265 c_parser_omp_clause_collapse (c_parser
*parser
, tree list
)
7267 tree c
, num
= error_mark_node
;
7271 check_no_duplicate_clause (list
, OMP_CLAUSE_COLLAPSE
, "collapse");
7273 loc
= c_parser_peek_token (parser
)->location
;
7274 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7276 num
= c_parser_expr_no_commas (parser
, NULL
).value
;
7277 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7279 if (num
== error_mark_node
)
7281 if (!INTEGRAL_TYPE_P (TREE_TYPE (num
))
7282 || !host_integerp (num
, 0)
7283 || (n
= tree_low_cst (num
, 0)) <= 0
7287 "collapse argument needs positive constant integer expression");
7290 c
= build_omp_clause (loc
, OMP_CLAUSE_COLLAPSE
);
7291 OMP_CLAUSE_COLLAPSE_EXPR (c
) = num
;
7292 OMP_CLAUSE_CHAIN (c
) = list
;
7297 copyin ( variable-list ) */
7300 c_parser_omp_clause_copyin (c_parser
*parser
, tree list
)
7302 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYIN
, list
);
7306 copyprivate ( variable-list ) */
7309 c_parser_omp_clause_copyprivate (c_parser
*parser
, tree list
)
7311 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYPRIVATE
, list
);
7315 default ( shared | none ) */
7318 c_parser_omp_clause_default (c_parser
*parser
, tree list
)
7320 enum omp_clause_default_kind kind
= OMP_CLAUSE_DEFAULT_UNSPECIFIED
;
7321 location_t loc
= c_parser_peek_token (parser
)->location
;
7324 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7326 if (c_parser_next_token_is (parser
, CPP_NAME
))
7328 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
7333 if (strcmp ("none", p
) != 0)
7335 kind
= OMP_CLAUSE_DEFAULT_NONE
;
7339 if (strcmp ("shared", p
) != 0)
7341 kind
= OMP_CLAUSE_DEFAULT_SHARED
;
7348 c_parser_consume_token (parser
);
7353 c_parser_error (parser
, "expected %<none%> or %<shared%>");
7355 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7357 if (kind
== OMP_CLAUSE_DEFAULT_UNSPECIFIED
)
7360 check_no_duplicate_clause (list
, OMP_CLAUSE_DEFAULT
, "default");
7361 c
= build_omp_clause (loc
, OMP_CLAUSE_DEFAULT
);
7362 OMP_CLAUSE_CHAIN (c
) = list
;
7363 OMP_CLAUSE_DEFAULT_KIND (c
) = kind
;
7369 firstprivate ( variable-list ) */
7372 c_parser_omp_clause_firstprivate (c_parser
*parser
, tree list
)
7374 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FIRSTPRIVATE
, list
);
7378 if ( expression ) */
7381 c_parser_omp_clause_if (c_parser
*parser
, tree list
)
7383 location_t loc
= c_parser_peek_token (parser
)->location
;
7384 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
7386 tree t
= c_parser_paren_condition (parser
);
7389 check_no_duplicate_clause (list
, OMP_CLAUSE_IF
, "if");
7391 c
= build_omp_clause (loc
, OMP_CLAUSE_IF
);
7392 OMP_CLAUSE_IF_EXPR (c
) = t
;
7393 OMP_CLAUSE_CHAIN (c
) = list
;
7397 c_parser_error (parser
, "expected %<(%>");
7403 lastprivate ( variable-list ) */
7406 c_parser_omp_clause_lastprivate (c_parser
*parser
, tree list
)
7408 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_LASTPRIVATE
, list
);
7415 c_parser_omp_clause_nowait (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
7418 location_t loc
= c_parser_peek_token (parser
)->location
;
7420 check_no_duplicate_clause (list
, OMP_CLAUSE_NOWAIT
, "nowait");
7422 c
= build_omp_clause (loc
, OMP_CLAUSE_NOWAIT
);
7423 OMP_CLAUSE_CHAIN (c
) = list
;
7428 num_threads ( expression ) */
7431 c_parser_omp_clause_num_threads (c_parser
*parser
, tree list
)
7433 location_t num_threads_loc
= c_parser_peek_token (parser
)->location
;
7434 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7436 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
7437 tree c
, t
= c_parser_expression (parser
).value
;
7438 t
= c_fully_fold (t
, false, NULL
);
7440 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7442 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
7444 c_parser_error (parser
, "expected integer expression");
7448 /* Attempt to statically determine when the number isn't positive. */
7449 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
7450 build_int_cst (TREE_TYPE (t
), 0));
7451 if (CAN_HAVE_LOCATION_P (c
))
7452 SET_EXPR_LOCATION (c
, expr_loc
);
7453 if (c
== boolean_true_node
)
7455 warning_at (expr_loc
, 0,
7456 "%<num_threads%> value must be positive");
7457 t
= integer_one_node
;
7460 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_THREADS
, "num_threads");
7462 c
= build_omp_clause (num_threads_loc
, OMP_CLAUSE_NUM_THREADS
);
7463 OMP_CLAUSE_NUM_THREADS_EXPR (c
) = t
;
7464 OMP_CLAUSE_CHAIN (c
) = list
;
7475 c_parser_omp_clause_ordered (c_parser
*parser
, tree list
)
7479 check_no_duplicate_clause (list
, OMP_CLAUSE_ORDERED
, "ordered");
7481 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
7482 OMP_CLAUSE_ORDERED
);
7483 OMP_CLAUSE_CHAIN (c
) = list
;
7489 private ( variable-list ) */
7492 c_parser_omp_clause_private (c_parser
*parser
, tree list
)
7494 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_PRIVATE
, list
);
7498 reduction ( reduction-operator : variable-list )
7501 One of: + * - & ^ | && || */
7504 c_parser_omp_clause_reduction (c_parser
*parser
, tree list
)
7506 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
7507 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7509 enum tree_code code
;
7511 switch (c_parser_peek_token (parser
)->type
)
7523 code
= BIT_AND_EXPR
;
7526 code
= BIT_XOR_EXPR
;
7529 code
= BIT_IOR_EXPR
;
7532 code
= TRUTH_ANDIF_EXPR
;
7535 code
= TRUTH_ORIF_EXPR
;
7538 c_parser_error (parser
,
7539 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
7540 "%<^%>, %<|%>, %<&&%>, or %<||%>");
7541 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
7544 c_parser_consume_token (parser
);
7545 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
7549 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
7550 OMP_CLAUSE_REDUCTION
, list
);
7551 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
7552 OMP_CLAUSE_REDUCTION_CODE (c
) = code
;
7556 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7562 schedule ( schedule-kind )
7563 schedule ( schedule-kind , expression )
7566 static | dynamic | guided | runtime | auto
7570 c_parser_omp_clause_schedule (c_parser
*parser
, tree list
)
7573 location_t loc
= c_parser_peek_token (parser
)->location
;
7575 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7578 c
= build_omp_clause (loc
, OMP_CLAUSE_SCHEDULE
);
7580 if (c_parser_next_token_is (parser
, CPP_NAME
))
7582 tree kind
= c_parser_peek_token (parser
)->value
;
7583 const char *p
= IDENTIFIER_POINTER (kind
);
7588 if (strcmp ("dynamic", p
) != 0)
7590 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_DYNAMIC
;
7594 if (strcmp ("guided", p
) != 0)
7596 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_GUIDED
;
7600 if (strcmp ("runtime", p
) != 0)
7602 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_RUNTIME
;
7609 else if (c_parser_next_token_is_keyword (parser
, RID_STATIC
))
7610 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_STATIC
;
7611 else if (c_parser_next_token_is_keyword (parser
, RID_AUTO
))
7612 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_AUTO
;
7616 c_parser_consume_token (parser
);
7617 if (c_parser_next_token_is (parser
, CPP_COMMA
))
7620 c_parser_consume_token (parser
);
7622 here
= c_parser_peek_token (parser
)->location
;
7623 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
7624 t
= c_fully_fold (t
, false, NULL
);
7626 if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_RUNTIME
)
7627 error_at (here
, "schedule %<runtime%> does not take "
7628 "a %<chunk_size%> parameter");
7629 else if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_AUTO
)
7631 "schedule %<auto%> does not take "
7632 "a %<chunk_size%> parameter");
7633 else if (TREE_CODE (TREE_TYPE (t
)) == INTEGER_TYPE
)
7634 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
) = t
;
7636 c_parser_error (parser
, "expected integer expression");
7638 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7641 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7642 "expected %<,%> or %<)%>");
7644 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
7645 OMP_CLAUSE_CHAIN (c
) = list
;
7649 c_parser_error (parser
, "invalid schedule kind");
7650 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
7655 shared ( variable-list ) */
7658 c_parser_omp_clause_shared (c_parser
*parser
, tree list
)
7660 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_SHARED
, list
);
7667 c_parser_omp_clause_untied (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
7671 /* FIXME: Should we allow duplicates? */
7672 check_no_duplicate_clause (list
, OMP_CLAUSE_UNTIED
, "untied");
7674 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
7676 OMP_CLAUSE_CHAIN (c
) = list
;
7681 /* Parse all OpenMP clauses. The set clauses allowed by the directive
7682 is a bitmask in MASK. Return the list of clauses found; the result
7683 of clause default goes in *pdefault. */
7686 c_parser_omp_all_clauses (c_parser
*parser
, unsigned int mask
,
7689 tree clauses
= NULL
;
7692 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
7695 pragma_omp_clause c_kind
;
7697 tree prev
= clauses
;
7699 if (!first
&& c_parser_next_token_is (parser
, CPP_COMMA
))
7700 c_parser_consume_token (parser
);
7703 here
= c_parser_peek_token (parser
)->location
;
7704 c_kind
= c_parser_omp_clause_name (parser
);
7708 case PRAGMA_OMP_CLAUSE_COLLAPSE
:
7709 clauses
= c_parser_omp_clause_collapse (parser
, clauses
);
7710 c_name
= "collapse";
7712 case PRAGMA_OMP_CLAUSE_COPYIN
:
7713 clauses
= c_parser_omp_clause_copyin (parser
, clauses
);
7716 case PRAGMA_OMP_CLAUSE_COPYPRIVATE
:
7717 clauses
= c_parser_omp_clause_copyprivate (parser
, clauses
);
7718 c_name
= "copyprivate";
7720 case PRAGMA_OMP_CLAUSE_DEFAULT
:
7721 clauses
= c_parser_omp_clause_default (parser
, clauses
);
7724 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
:
7725 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
7726 c_name
= "firstprivate";
7728 case PRAGMA_OMP_CLAUSE_IF
:
7729 clauses
= c_parser_omp_clause_if (parser
, clauses
);
7732 case PRAGMA_OMP_CLAUSE_LASTPRIVATE
:
7733 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
7734 c_name
= "lastprivate";
7736 case PRAGMA_OMP_CLAUSE_NOWAIT
:
7737 clauses
= c_parser_omp_clause_nowait (parser
, clauses
);
7740 case PRAGMA_OMP_CLAUSE_NUM_THREADS
:
7741 clauses
= c_parser_omp_clause_num_threads (parser
, clauses
);
7742 c_name
= "num_threads";
7744 case PRAGMA_OMP_CLAUSE_ORDERED
:
7745 clauses
= c_parser_omp_clause_ordered (parser
, clauses
);
7748 case PRAGMA_OMP_CLAUSE_PRIVATE
:
7749 clauses
= c_parser_omp_clause_private (parser
, clauses
);
7752 case PRAGMA_OMP_CLAUSE_REDUCTION
:
7753 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
7754 c_name
= "reduction";
7756 case PRAGMA_OMP_CLAUSE_SCHEDULE
:
7757 clauses
= c_parser_omp_clause_schedule (parser
, clauses
);
7758 c_name
= "schedule";
7760 case PRAGMA_OMP_CLAUSE_SHARED
:
7761 clauses
= c_parser_omp_clause_shared (parser
, clauses
);
7764 case PRAGMA_OMP_CLAUSE_UNTIED
:
7765 clauses
= c_parser_omp_clause_untied (parser
, clauses
);
7769 c_parser_error (parser
, "expected %<#pragma omp%> clause");
7773 if (((mask
>> c_kind
) & 1) == 0 && !parser
->error
)
7775 /* Remove the invalid clause(s) from the list to avoid
7776 confusing the rest of the compiler. */
7778 error_at (here
, "%qs is not valid for %qs", c_name
, where
);
7783 c_parser_skip_to_pragma_eol (parser
);
7785 return c_finish_omp_clauses (clauses
);
7792 In practice, we're also interested in adding the statement to an
7793 outer node. So it is convenient if we work around the fact that
7794 c_parser_statement calls add_stmt. */
7797 c_parser_omp_structured_block (c_parser
*parser
)
7799 tree stmt
= push_stmt_list ();
7800 c_parser_statement (parser
);
7801 return pop_stmt_list (stmt
);
7805 # pragma omp atomic new-line
7809 x binop= expr | x++ | ++x | x-- | --x
7811 +, *, -, /, &, ^, |, <<, >>
7813 where x is an lvalue expression with scalar type.
7815 LOC is the location of the #pragma token. */
7818 c_parser_omp_atomic (location_t loc
, c_parser
*parser
)
7822 enum tree_code code
;
7823 struct c_expr rhs_expr
;
7825 c_parser_skip_to_pragma_eol (parser
);
7827 lhs
= c_parser_unary_expression (parser
).value
;
7828 lhs
= c_fully_fold (lhs
, false, NULL
);
7829 switch (TREE_CODE (lhs
))
7833 c_parser_skip_to_end_of_block_or_statement (parser
);
7836 case PREINCREMENT_EXPR
:
7837 case POSTINCREMENT_EXPR
:
7838 lhs
= TREE_OPERAND (lhs
, 0);
7840 rhs
= integer_one_node
;
7843 case PREDECREMENT_EXPR
:
7844 case POSTDECREMENT_EXPR
:
7845 lhs
= TREE_OPERAND (lhs
, 0);
7847 rhs
= integer_one_node
;
7851 switch (c_parser_peek_token (parser
)->type
)
7857 code
= TRUNC_DIV_EXPR
;
7872 code
= BIT_AND_EXPR
;
7875 code
= BIT_IOR_EXPR
;
7878 code
= BIT_XOR_EXPR
;
7881 c_parser_error (parser
,
7882 "invalid operator for %<#pragma omp atomic%>");
7886 c_parser_consume_token (parser
);
7888 location_t rhs_loc
= c_parser_peek_token (parser
)->location
;
7889 rhs_expr
= c_parser_expression (parser
);
7890 rhs_expr
= default_function_array_conversion (rhs_loc
, rhs_expr
);
7892 rhs
= rhs_expr
.value
;
7893 rhs
= c_fully_fold (rhs
, false, NULL
);
7896 stmt
= c_finish_omp_atomic (loc
, code
, lhs
, rhs
);
7897 if (stmt
!= error_mark_node
)
7899 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7904 # pragma omp barrier new-line
7908 c_parser_omp_barrier (c_parser
*parser
)
7910 location_t loc
= c_parser_peek_token (parser
)->location
;
7911 c_parser_consume_pragma (parser
);
7912 c_parser_skip_to_pragma_eol (parser
);
7914 c_finish_omp_barrier (loc
);
7918 # pragma omp critical [(name)] new-line
7921 LOC is the location of the #pragma itself. */
7924 c_parser_omp_critical (location_t loc
, c_parser
*parser
)
7926 tree stmt
, name
= NULL
;
7928 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
7930 c_parser_consume_token (parser
);
7931 if (c_parser_next_token_is (parser
, CPP_NAME
))
7933 name
= c_parser_peek_token (parser
)->value
;
7934 c_parser_consume_token (parser
);
7935 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7938 c_parser_error (parser
, "expected identifier");
7940 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
7941 c_parser_error (parser
, "expected %<(%> or end of line");
7942 c_parser_skip_to_pragma_eol (parser
);
7944 stmt
= c_parser_omp_structured_block (parser
);
7945 return c_finish_omp_critical (loc
, stmt
, name
);
7949 # pragma omp flush flush-vars[opt] new-line
7952 ( variable-list ) */
7955 c_parser_omp_flush (c_parser
*parser
)
7957 location_t loc
= c_parser_peek_token (parser
)->location
;
7958 c_parser_consume_pragma (parser
);
7959 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
7960 c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
7961 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
7962 c_parser_error (parser
, "expected %<(%> or end of line");
7963 c_parser_skip_to_pragma_eol (parser
);
7965 c_finish_omp_flush (loc
);
7968 /* Parse the restricted form of the for statement allowed by OpenMP.
7969 The real trick here is to determine the loop control variable early
7970 so that we can push a new decl if necessary to make it private.
7971 LOC is the location of the OMP in "#pragma omp". */
7974 c_parser_omp_for_loop (location_t loc
,
7975 c_parser
*parser
, tree clauses
, tree
*par_clauses
)
7977 tree decl
, cond
, incr
, save_break
, save_cont
, body
, init
, stmt
, cl
;
7978 tree declv
, condv
, incrv
, initv
, for_block
= NULL
, ret
= NULL
;
7979 bool fail
= false, open_brace_parsed
= false;
7980 int i
, collapse
= 1, nbraces
= 0;
7983 for (cl
= clauses
; cl
; cl
= OMP_CLAUSE_CHAIN (cl
))
7984 if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_COLLAPSE
)
7985 collapse
= tree_low_cst (OMP_CLAUSE_COLLAPSE_EXPR (cl
), 0);
7987 gcc_assert (collapse
>= 1);
7989 declv
= make_tree_vec (collapse
);
7990 initv
= make_tree_vec (collapse
);
7991 condv
= make_tree_vec (collapse
);
7992 incrv
= make_tree_vec (collapse
);
7994 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
))
7996 c_parser_error (parser
, "for statement expected");
7999 for_loc
= c_parser_peek_token (parser
)->location
;
8000 c_parser_consume_token (parser
);
8002 for (i
= 0; i
< collapse
; i
++)
8006 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8009 /* Parse the initialization declaration or expression. */
8010 if (c_parser_next_token_starts_declspecs (parser
))
8014 = tree_cons (NULL
, c_begin_compound_stmt (true), for_block
);
8015 c_parser_declaration_or_fndef (parser
, true, true, true, true);
8016 decl
= check_for_loop_decls (for_loc
);
8019 if (DECL_INITIAL (decl
) == error_mark_node
)
8020 decl
= error_mark_node
;
8023 else if (c_parser_next_token_is (parser
, CPP_NAME
)
8024 && c_parser_peek_2nd_token (parser
)->type
== CPP_EQ
)
8026 struct c_expr decl_exp
;
8027 struct c_expr init_exp
;
8028 location_t init_loc
;
8030 decl_exp
= c_parser_postfix_expression (parser
);
8031 decl
= decl_exp
.value
;
8033 c_parser_require (parser
, CPP_EQ
, "expected %<=%>");
8035 init_loc
= c_parser_peek_token (parser
)->location
;
8036 init_exp
= c_parser_expr_no_commas (parser
, NULL
);
8037 init_exp
= default_function_array_conversion (init_loc
, init_exp
);
8038 init
= build_modify_expr (init_loc
, decl
, decl_exp
.original_type
,
8039 NOP_EXPR
, init_loc
, init_exp
.value
,
8040 init_exp
.original_type
);
8041 init
= c_process_expr_stmt (init_loc
, init
);
8043 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8048 c_parser_error (parser
,
8049 "expected iteration declaration or initialization");
8050 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
8056 /* Parse the loop condition. */
8058 if (c_parser_next_token_is_not (parser
, CPP_SEMICOLON
))
8060 location_t cond_loc
= c_parser_peek_token (parser
)->location
;
8061 struct c_expr cond_expr
= c_parser_binary_expression (parser
, NULL
);
8063 cond
= cond_expr
.value
;
8064 cond
= c_objc_common_truthvalue_conversion (cond_loc
, cond
);
8065 cond
= c_fully_fold (cond
, false, NULL
);
8066 switch (cond_expr
.original_code
)
8074 /* Can't be cond = error_mark_node, because we want to preserve
8075 the location until c_finish_omp_for. */
8076 cond
= build1 (NOP_EXPR
, boolean_type_node
, error_mark_node
);
8079 protected_set_expr_location (cond
, cond_loc
);
8081 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8083 /* Parse the increment expression. */
8085 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_PAREN
))
8087 location_t incr_loc
= c_parser_peek_token (parser
)->location
;
8089 incr
= c_process_expr_stmt (incr_loc
,
8090 c_parser_expression (parser
).value
);
8092 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8094 if (decl
== NULL
|| decl
== error_mark_node
|| init
== error_mark_node
)
8098 TREE_VEC_ELT (declv
, i
) = decl
;
8099 TREE_VEC_ELT (initv
, i
) = init
;
8100 TREE_VEC_ELT (condv
, i
) = cond
;
8101 TREE_VEC_ELT (incrv
, i
) = incr
;
8105 if (i
== collapse
- 1)
8108 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
8109 in between the collapsed for loops to be still considered perfectly
8110 nested. Hopefully the final version clarifies this.
8111 For now handle (multiple) {'s and empty statements. */
8114 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
8116 c_parser_consume_token (parser
);
8119 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
8121 c_parser_consume_token (parser
);
8125 && c_parser_next_token_is (parser
, CPP_SEMICOLON
))
8126 c_parser_consume_token (parser
);
8129 c_parser_error (parser
, "not enough perfectly nested loops");
8132 open_brace_parsed
= true;
8142 nbraces
+= bracecount
;
8145 save_break
= c_break_label
;
8146 c_break_label
= size_one_node
;
8147 save_cont
= c_cont_label
;
8148 c_cont_label
= NULL_TREE
;
8149 body
= push_stmt_list ();
8151 if (open_brace_parsed
)
8153 location_t here
= c_parser_peek_token (parser
)->location
;
8154 stmt
= c_begin_compound_stmt (true);
8155 c_parser_compound_statement_nostart (parser
);
8156 add_stmt (c_end_compound_stmt (here
, stmt
, true));
8159 add_stmt (c_parser_c99_block_statement (parser
));
8162 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_cont_label
);
8163 SET_EXPR_LOCATION (t
, loc
);
8167 body
= pop_stmt_list (body
);
8168 c_break_label
= save_break
;
8169 c_cont_label
= save_cont
;
8173 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
8175 c_parser_consume_token (parser
);
8178 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
8179 c_parser_consume_token (parser
);
8182 c_parser_error (parser
, "collapsed loops not perfectly nested");
8185 location_t here
= c_parser_peek_token (parser
)->location
;
8186 stmt
= c_begin_compound_stmt (true);
8188 c_parser_compound_statement_nostart (parser
);
8189 body
= c_end_compound_stmt (here
, stmt
, true);
8196 /* Only bother calling c_finish_omp_for if we haven't already generated
8197 an error from the initialization parsing. */
8200 stmt
= c_finish_omp_for (loc
, declv
, initv
, condv
, incrv
, body
, NULL
);
8203 if (par_clauses
!= NULL
)
8206 for (c
= par_clauses
; *c
; )
8207 if (OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_FIRSTPRIVATE
8208 && OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_LASTPRIVATE
)
8209 c
= &OMP_CLAUSE_CHAIN (*c
);
8212 for (i
= 0; i
< collapse
; i
++)
8213 if (TREE_VEC_ELT (declv
, i
) == OMP_CLAUSE_DECL (*c
))
8216 c
= &OMP_CLAUSE_CHAIN (*c
);
8217 else if (OMP_CLAUSE_CODE (*c
) == OMP_CLAUSE_FIRSTPRIVATE
)
8220 "iteration variable %qD should not be firstprivate",
8221 OMP_CLAUSE_DECL (*c
));
8222 *c
= OMP_CLAUSE_CHAIN (*c
);
8226 /* Copy lastprivate (decl) clause to OMP_FOR_CLAUSES,
8227 change it to shared (decl) in
8228 OMP_PARALLEL_CLAUSES. */
8229 tree l
= build_omp_clause (OMP_CLAUSE_LOCATION (*c
),
8230 OMP_CLAUSE_LASTPRIVATE
);
8231 OMP_CLAUSE_DECL (l
) = OMP_CLAUSE_DECL (*c
);
8232 OMP_CLAUSE_CHAIN (l
) = clauses
;
8234 OMP_CLAUSE_SET_CODE (*c
, OMP_CLAUSE_SHARED
);
8238 OMP_FOR_CLAUSES (stmt
) = clauses
;
8245 /* FIXME diagnostics: LOC below should be the actual location of
8246 this particular for block. We need to build a list of
8247 locations to go along with FOR_BLOCK. */
8248 stmt
= c_end_compound_stmt (loc
, TREE_VALUE (for_block
), true);
8250 for_block
= TREE_CHAIN (for_block
);
8256 #pragma omp for for-clause[optseq] new-line
8259 LOC is the location of the #pragma token.
8262 #define OMP_FOR_CLAUSE_MASK \
8263 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8264 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8265 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
8266 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
8267 | (1u << PRAGMA_OMP_CLAUSE_ORDERED) \
8268 | (1u << PRAGMA_OMP_CLAUSE_SCHEDULE) \
8269 | (1u << PRAGMA_OMP_CLAUSE_COLLAPSE) \
8270 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
8273 c_parser_omp_for (location_t loc
, c_parser
*parser
)
8275 tree block
, clauses
, ret
;
8277 clauses
= c_parser_omp_all_clauses (parser
, OMP_FOR_CLAUSE_MASK
,
8280 block
= c_begin_compound_stmt (true);
8281 ret
= c_parser_omp_for_loop (loc
, parser
, clauses
, NULL
);
8282 block
= c_end_compound_stmt (loc
, block
, true);
8289 # pragma omp master new-line
8292 LOC is the location of the #pragma token.
8296 c_parser_omp_master (location_t loc
, c_parser
*parser
)
8298 c_parser_skip_to_pragma_eol (parser
);
8299 return c_finish_omp_master (loc
, c_parser_omp_structured_block (parser
));
8303 # pragma omp ordered new-line
8306 LOC is the location of the #pragma itself.
8310 c_parser_omp_ordered (location_t loc
, c_parser
*parser
)
8312 c_parser_skip_to_pragma_eol (parser
);
8313 return c_finish_omp_ordered (loc
, c_parser_omp_structured_block (parser
));
8319 { section-sequence }
8322 section-directive[opt] structured-block
8323 section-sequence section-directive structured-block
8325 SECTIONS_LOC is the location of the #pragma omp sections. */
8328 c_parser_omp_sections_scope (location_t sections_loc
, c_parser
*parser
)
8331 bool error_suppress
= false;
8334 loc
= c_parser_peek_token (parser
)->location
;
8335 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
8337 /* Avoid skipping until the end of the block. */
8338 parser
->error
= false;
8342 stmt
= push_stmt_list ();
8344 if (c_parser_peek_token (parser
)->pragma_kind
!= PRAGMA_OMP_SECTION
)
8346 substmt
= push_stmt_list ();
8350 c_parser_statement (parser
);
8352 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
8354 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
8356 if (c_parser_next_token_is (parser
, CPP_EOF
))
8360 substmt
= pop_stmt_list (substmt
);
8361 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
8362 SET_EXPR_LOCATION (substmt
, loc
);
8368 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
8370 if (c_parser_next_token_is (parser
, CPP_EOF
))
8373 loc
= c_parser_peek_token (parser
)->location
;
8374 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
8376 c_parser_consume_pragma (parser
);
8377 c_parser_skip_to_pragma_eol (parser
);
8378 error_suppress
= false;
8380 else if (!error_suppress
)
8382 error_at (loc
, "expected %<#pragma omp section%> or %<}%>");
8383 error_suppress
= true;
8386 substmt
= c_parser_omp_structured_block (parser
);
8387 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
8388 SET_EXPR_LOCATION (substmt
, loc
);
8391 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
,
8392 "expected %<#pragma omp section%> or %<}%>");
8394 substmt
= pop_stmt_list (stmt
);
8396 stmt
= make_node (OMP_SECTIONS
);
8397 SET_EXPR_LOCATION (stmt
, sections_loc
);
8398 TREE_TYPE (stmt
) = void_type_node
;
8399 OMP_SECTIONS_BODY (stmt
) = substmt
;
8401 return add_stmt (stmt
);
8405 # pragma omp sections sections-clause[optseq] newline
8408 LOC is the location of the #pragma token.
8411 #define OMP_SECTIONS_CLAUSE_MASK \
8412 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8413 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8414 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
8415 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
8416 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
8419 c_parser_omp_sections (location_t loc
, c_parser
*parser
)
8421 tree block
, clauses
, ret
;
8423 clauses
= c_parser_omp_all_clauses (parser
, OMP_SECTIONS_CLAUSE_MASK
,
8424 "#pragma omp sections");
8426 block
= c_begin_compound_stmt (true);
8427 ret
= c_parser_omp_sections_scope (loc
, parser
);
8429 OMP_SECTIONS_CLAUSES (ret
) = clauses
;
8430 block
= c_end_compound_stmt (loc
, block
, true);
8437 # pragma parallel parallel-clause new-line
8438 # pragma parallel for parallel-for-clause new-line
8439 # pragma parallel sections parallel-sections-clause new-line
8441 LOC is the location of the #pragma token.
8444 #define OMP_PARALLEL_CLAUSE_MASK \
8445 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
8446 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8447 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8448 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
8449 | (1u << PRAGMA_OMP_CLAUSE_SHARED) \
8450 | (1u << PRAGMA_OMP_CLAUSE_COPYIN) \
8451 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
8452 | (1u << PRAGMA_OMP_CLAUSE_NUM_THREADS))
8455 c_parser_omp_parallel (location_t loc
, c_parser
*parser
)
8457 enum pragma_kind p_kind
= PRAGMA_OMP_PARALLEL
;
8458 const char *p_name
= "#pragma omp parallel";
8459 tree stmt
, clauses
, par_clause
, ws_clause
, block
;
8460 unsigned int mask
= OMP_PARALLEL_CLAUSE_MASK
;
8462 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
8464 c_parser_consume_token (parser
);
8465 p_kind
= PRAGMA_OMP_PARALLEL_FOR
;
8466 p_name
= "#pragma omp parallel for";
8467 mask
|= OMP_FOR_CLAUSE_MASK
;
8468 mask
&= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT
);
8470 else if (c_parser_next_token_is (parser
, CPP_NAME
))
8472 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
8473 if (strcmp (p
, "sections") == 0)
8475 c_parser_consume_token (parser
);
8476 p_kind
= PRAGMA_OMP_PARALLEL_SECTIONS
;
8477 p_name
= "#pragma omp parallel sections";
8478 mask
|= OMP_SECTIONS_CLAUSE_MASK
;
8479 mask
&= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT
);
8483 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
);
8487 case PRAGMA_OMP_PARALLEL
:
8488 block
= c_begin_omp_parallel ();
8489 c_parser_statement (parser
);
8490 stmt
= c_finish_omp_parallel (loc
, clauses
, block
);
8493 case PRAGMA_OMP_PARALLEL_FOR
:
8494 block
= c_begin_omp_parallel ();
8495 c_split_parallel_clauses (loc
, clauses
, &par_clause
, &ws_clause
);
8496 c_parser_omp_for_loop (loc
, parser
, ws_clause
, &par_clause
);
8497 stmt
= c_finish_omp_parallel (loc
, par_clause
, block
);
8498 OMP_PARALLEL_COMBINED (stmt
) = 1;
8501 case PRAGMA_OMP_PARALLEL_SECTIONS
:
8502 block
= c_begin_omp_parallel ();
8503 c_split_parallel_clauses (loc
, clauses
, &par_clause
, &ws_clause
);
8504 stmt
= c_parser_omp_sections_scope (loc
, parser
);
8506 OMP_SECTIONS_CLAUSES (stmt
) = ws_clause
;
8507 stmt
= c_finish_omp_parallel (loc
, par_clause
, block
);
8508 OMP_PARALLEL_COMBINED (stmt
) = 1;
8519 # pragma omp single single-clause[optseq] new-line
8522 LOC is the location of the #pragma.
8525 #define OMP_SINGLE_CLAUSE_MASK \
8526 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8527 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8528 | (1u << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
8529 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
8532 c_parser_omp_single (location_t loc
, c_parser
*parser
)
8534 tree stmt
= make_node (OMP_SINGLE
);
8535 SET_EXPR_LOCATION (stmt
, loc
);
8536 TREE_TYPE (stmt
) = void_type_node
;
8538 OMP_SINGLE_CLAUSES (stmt
)
8539 = c_parser_omp_all_clauses (parser
, OMP_SINGLE_CLAUSE_MASK
,
8540 "#pragma omp single");
8541 OMP_SINGLE_BODY (stmt
) = c_parser_omp_structured_block (parser
);
8543 return add_stmt (stmt
);
8547 # pragma omp task task-clause[optseq] new-line
8549 LOC is the location of the #pragma.
8552 #define OMP_TASK_CLAUSE_MASK \
8553 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
8554 | (1u << PRAGMA_OMP_CLAUSE_UNTIED) \
8555 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
8556 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8557 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8558 | (1u << PRAGMA_OMP_CLAUSE_SHARED))
8561 c_parser_omp_task (location_t loc
, c_parser
*parser
)
8563 tree clauses
, block
;
8565 clauses
= c_parser_omp_all_clauses (parser
, OMP_TASK_CLAUSE_MASK
,
8566 "#pragma omp task");
8568 block
= c_begin_omp_task ();
8569 c_parser_statement (parser
);
8570 return c_finish_omp_task (loc
, clauses
, block
);
8574 # pragma omp taskwait new-line
8578 c_parser_omp_taskwait (c_parser
*parser
)
8580 location_t loc
= c_parser_peek_token (parser
)->location
;
8581 c_parser_consume_pragma (parser
);
8582 c_parser_skip_to_pragma_eol (parser
);
8584 c_finish_omp_taskwait (loc
);
8587 /* Main entry point to parsing most OpenMP pragmas. */
8590 c_parser_omp_construct (c_parser
*parser
)
8592 enum pragma_kind p_kind
;
8596 loc
= c_parser_peek_token (parser
)->location
;
8597 p_kind
= c_parser_peek_token (parser
)->pragma_kind
;
8598 c_parser_consume_pragma (parser
);
8602 case PRAGMA_OMP_ATOMIC
:
8603 c_parser_omp_atomic (loc
, parser
);
8605 case PRAGMA_OMP_CRITICAL
:
8606 stmt
= c_parser_omp_critical (loc
, parser
);
8608 case PRAGMA_OMP_FOR
:
8609 stmt
= c_parser_omp_for (loc
, parser
);
8611 case PRAGMA_OMP_MASTER
:
8612 stmt
= c_parser_omp_master (loc
, parser
);
8614 case PRAGMA_OMP_ORDERED
:
8615 stmt
= c_parser_omp_ordered (loc
, parser
);
8617 case PRAGMA_OMP_PARALLEL
:
8618 stmt
= c_parser_omp_parallel (loc
, parser
);
8620 case PRAGMA_OMP_SECTIONS
:
8621 stmt
= c_parser_omp_sections (loc
, parser
);
8623 case PRAGMA_OMP_SINGLE
:
8624 stmt
= c_parser_omp_single (loc
, parser
);
8626 case PRAGMA_OMP_TASK
:
8627 stmt
= c_parser_omp_task (loc
, parser
);
8634 gcc_assert (EXPR_LOCATION (stmt
) != UNKNOWN_LOCATION
);
8639 # pragma omp threadprivate (variable-list) */
8642 c_parser_omp_threadprivate (c_parser
*parser
)
8647 c_parser_consume_pragma (parser
);
8648 loc
= c_parser_peek_token (parser
)->location
;
8649 vars
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
8651 /* Mark every variable in VARS to be assigned thread local storage. */
8652 for (t
= vars
; t
; t
= TREE_CHAIN (t
))
8654 tree v
= TREE_PURPOSE (t
);
8656 /* FIXME diagnostics: Ideally we should keep individual
8657 locations for all the variables in the var list to make the
8658 following errors more precise. Perhaps
8659 c_parser_omp_var_list_parens() should construct a list of
8660 locations to go along with the var list. */
8662 /* If V had already been marked threadprivate, it doesn't matter
8663 whether it had been used prior to this point. */
8664 if (TREE_CODE (v
) != VAR_DECL
)
8665 error_at (loc
, "%qD is not a variable", v
);
8666 else if (TREE_USED (v
) && !C_DECL_THREADPRIVATE_P (v
))
8667 error_at (loc
, "%qE declared %<threadprivate%> after first use", v
);
8668 else if (! TREE_STATIC (v
) && ! DECL_EXTERNAL (v
))
8669 error_at (loc
, "automatic variable %qE cannot be %<threadprivate%>", v
);
8670 else if (TREE_TYPE (v
) == error_mark_node
)
8672 else if (! COMPLETE_TYPE_P (TREE_TYPE (v
)))
8673 error_at (loc
, "%<threadprivate%> %qE has incomplete type", v
);
8676 if (! DECL_THREAD_LOCAL_P (v
))
8678 DECL_TLS_MODEL (v
) = decl_default_tls_model (v
);
8679 /* If rtl has been already set for this var, call
8680 make_decl_rtl once again, so that encode_section_info
8681 has a chance to look at the new decl flags. */
8682 if (DECL_RTL_SET_P (v
))
8685 C_DECL_THREADPRIVATE_P (v
) = 1;
8689 c_parser_skip_to_pragma_eol (parser
);
8693 /* Parse a single source file. */
8698 /* Use local storage to begin. If the first token is a pragma, parse it.
8699 If it is #pragma GCC pch_preprocess, then this will load a PCH file
8700 which will cause garbage collection. */
8703 memset (&tparser
, 0, sizeof tparser
);
8704 the_parser
= &tparser
;
8706 if (c_parser_peek_token (&tparser
)->pragma_kind
== PRAGMA_GCC_PCH_PREPROCESS
)
8707 c_parser_pragma_pch_preprocess (&tparser
);
8709 the_parser
= GGC_NEW (c_parser
);
8710 *the_parser
= tparser
;
8712 /* Initialize EH, if we've been told to do so. */
8713 if (flag_exceptions
)
8714 using_eh_for_cleanups ();
8716 c_parser_translation_unit (the_parser
);
8720 #include "gt-c-parser.h"