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
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"
62 /* Initialization routine for this file. */
67 /* The only initialization required is of the reserved word
78 mask
|= D_ASM
| D_EXT
;
82 if (!c_dialect_objc ())
83 mask
|= D_OBJC
| D_CXX_OBJC
;
85 ridpointers
= GGC_CNEWVEC (tree
, (int) RID_MAX
);
86 for (i
= 0; i
< num_c_common_reswords
; i
++)
88 /* If a keyword is disabled, do not enter it into the table
89 and so create a canonical spelling that isn't a keyword. */
90 if (c_common_reswords
[i
].disable
& mask
)
93 && (c_common_reswords
[i
].disable
& D_CXXWARN
))
95 id
= get_identifier (c_common_reswords
[i
].word
);
96 C_SET_RID_CODE (id
, RID_CXX_COMPAT_WARN
);
97 C_IS_RESERVED_WORD (id
) = 1;
102 id
= get_identifier (c_common_reswords
[i
].word
);
103 C_SET_RID_CODE (id
, c_common_reswords
[i
].rid
);
104 C_IS_RESERVED_WORD (id
) = 1;
105 ridpointers
[(int) c_common_reswords
[i
].rid
] = id
;
109 /* The C lexer intermediates between the lexer in cpplib and c-lex.c
110 and the C parser. Unlike the C++ lexer, the parser structure
111 stores the lexer information instead of using a separate structure.
112 Identifiers are separated into ordinary identifiers, type names,
113 keywords and some other Objective-C types of identifiers, and some
114 look-ahead is maintained.
116 ??? It might be a good idea to lex the whole file up front (as for
117 C++). It would then be possible to share more of the C and C++
118 lexer code, if desired. */
120 /* The following local token type is used. */
123 #define CPP_KEYWORD ((enum cpp_ttype) (N_TTYPES + 1))
125 /* More information about the type of a CPP_NAME token. */
126 typedef enum c_id_kind
{
127 /* An ordinary identifier. */
129 /* An identifier declared as a typedef name. */
131 /* An identifier declared as an Objective-C class name. */
133 /* Not an identifier. */
137 /* A single C token after string literal concatenation and conversion
138 of preprocessing tokens to tokens. */
139 typedef struct c_token
GTY (())
141 /* The kind of token. */
142 ENUM_BITFIELD (cpp_ttype
) type
: 8;
143 /* If this token is a CPP_NAME, this value indicates whether also
144 declared as some kind of type. Otherwise, it is C_ID_NONE. */
145 ENUM_BITFIELD (c_id_kind
) id_kind
: 8;
146 /* If this token is a keyword, this value indicates which keyword.
147 Otherwise, this value is RID_MAX. */
148 ENUM_BITFIELD (rid
) keyword
: 8;
149 /* If this token is a CPP_PRAGMA, this indicates the pragma that
150 was seen. Otherwise it is PRAGMA_NONE. */
151 ENUM_BITFIELD (pragma_kind
) pragma_kind
: 7;
152 /* True if this token is from a system header. */
153 BOOL_BITFIELD in_system_header
: 1;
154 /* The value associated with this token, if any. */
156 /* The location at which this token was found. */
160 /* A parser structure recording information about the state and
161 context of parsing. Includes lexer information with up to two
162 tokens of look-ahead; more are not needed for C. */
163 typedef struct c_parser
GTY(())
165 /* The look-ahead tokens. */
167 /* How many look-ahead tokens are available (0, 1 or 2). */
169 /* True if a syntax error is being recovered from; false otherwise.
170 c_parser_error sets this flag. It should clear this flag when
171 enough tokens have been consumed to recover from the error. */
172 BOOL_BITFIELD error
: 1;
173 /* True if we're processing a pragma, and shouldn't automatically
174 consume CPP_PRAGMA_EOL. */
175 BOOL_BITFIELD in_pragma
: 1;
176 /* True if we're parsing the outermost block of an if statement. */
177 BOOL_BITFIELD in_if_block
: 1;
178 /* True if we want to lex an untranslated string. */
179 BOOL_BITFIELD lex_untranslated_string
: 1;
180 /* Objective-C specific parser/lexer information. */
181 BOOL_BITFIELD objc_pq_context
: 1;
182 /* The following flag is needed to contextualize Objective-C lexical
183 analysis. In some cases (e.g., 'int NSObject;'), it is
184 undesirable to bind an identifier to an Objective-C class, even
185 if a class with that name exists. */
186 BOOL_BITFIELD objc_need_raw_identifier
: 1;
190 /* The actual parser and external interface. ??? Does this need to be
191 garbage-collected? */
193 static GTY (()) c_parser
*the_parser
;
196 /* Read in and lex a single token, storing it in *TOKEN. */
199 c_lex_one_token (c_parser
*parser
, c_token
*token
)
201 timevar_push (TV_LEX
);
203 token
->type
= c_lex_with_flags (&token
->value
, &token
->location
, NULL
,
204 (parser
->lex_untranslated_string
205 ? C_LEX_STRING_NO_TRANSLATE
: 0));
206 token
->id_kind
= C_ID_NONE
;
207 token
->keyword
= RID_MAX
;
208 token
->pragma_kind
= PRAGMA_NONE
;
209 token
->in_system_header
= in_system_header
;
217 bool objc_force_identifier
= parser
->objc_need_raw_identifier
;
218 if (c_dialect_objc ())
219 parser
->objc_need_raw_identifier
= false;
221 if (C_IS_RESERVED_WORD (token
->value
))
223 enum rid rid_code
= C_RID_CODE (token
->value
);
225 if (rid_code
== RID_CXX_COMPAT_WARN
)
227 warning (OPT_Wc___compat
,
228 "%Hidentifier %qs conflicts with C++ keyword",
230 IDENTIFIER_POINTER (token
->value
));
232 else if (c_dialect_objc ())
234 if (!objc_is_reserved_word (token
->value
)
235 && (!OBJC_IS_PQ_KEYWORD (rid_code
)
236 || parser
->objc_pq_context
))
238 /* Return the canonical spelling for this keyword. */
239 token
->value
= ridpointers
[(int) rid_code
];
240 token
->type
= CPP_KEYWORD
;
241 token
->keyword
= rid_code
;
247 /* Return the canonical spelling for this keyword. */
248 token
->value
= ridpointers
[(int) rid_code
];
249 token
->type
= CPP_KEYWORD
;
250 token
->keyword
= rid_code
;
255 decl
= lookup_name (token
->value
);
258 if (TREE_CODE (decl
) == TYPE_DECL
)
260 token
->id_kind
= C_ID_TYPENAME
;
264 else if (c_dialect_objc ())
266 tree objc_interface_decl
= objc_is_class_name (token
->value
);
267 /* Objective-C class names are in the same namespace as
268 variables and typedefs, and hence are shadowed by local
270 if (objc_interface_decl
271 && (global_bindings_p ()
272 || (!objc_force_identifier
&& !decl
)))
274 token
->value
= objc_interface_decl
;
275 token
->id_kind
= C_ID_CLASSNAME
;
279 token
->id_kind
= C_ID_ID
;
283 /* This only happens in Objective-C; it must be a keyword. */
284 token
->type
= CPP_KEYWORD
;
285 token
->keyword
= C_RID_CODE (token
->value
);
289 case CPP_CLOSE_PAREN
:
291 /* These tokens may affect the interpretation of any identifiers
292 following, if doing Objective-C. */
293 if (c_dialect_objc ())
294 parser
->objc_need_raw_identifier
= false;
297 /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */
298 token
->pragma_kind
= (enum pragma_kind
) TREE_INT_CST_LOW (token
->value
);
304 timevar_pop (TV_LEX
);
307 /* Return a pointer to the next token from PARSER, reading it in if
310 static inline c_token
*
311 c_parser_peek_token (c_parser
*parser
)
313 if (parser
->tokens_avail
== 0)
315 c_lex_one_token (parser
, &parser
->tokens
[0]);
316 parser
->tokens_avail
= 1;
318 return &parser
->tokens
[0];
321 /* Return true if the next token from PARSER has the indicated
325 c_parser_next_token_is (c_parser
*parser
, enum cpp_ttype type
)
327 return c_parser_peek_token (parser
)->type
== type
;
330 /* Return true if the next token from PARSER does not have the
334 c_parser_next_token_is_not (c_parser
*parser
, enum cpp_ttype type
)
336 return !c_parser_next_token_is (parser
, type
);
339 /* Return true if the next token from PARSER is the indicated
343 c_parser_next_token_is_keyword (c_parser
*parser
, enum rid keyword
)
345 return c_parser_peek_token (parser
)->keyword
== keyword
;
348 /* Return true if TOKEN can start a type name,
351 c_token_starts_typename (c_token
*token
)
356 switch (token
->id_kind
)
363 gcc_assert (c_dialect_objc ());
369 switch (token
->keyword
)
401 if (c_dialect_objc ())
409 /* Return true if the next token from PARSER can start a type name,
412 c_parser_next_token_starts_typename (c_parser
*parser
)
414 c_token
*token
= c_parser_peek_token (parser
);
415 return c_token_starts_typename (token
);
418 /* Return true if TOKEN can start declaration specifiers, false
421 c_token_starts_declspecs (c_token
*token
)
426 switch (token
->id_kind
)
433 gcc_assert (c_dialect_objc ());
439 switch (token
->keyword
)
478 if (c_dialect_objc ())
486 /* Return true if the next token from PARSER can start declaration
487 specifiers, false otherwise. */
489 c_parser_next_token_starts_declspecs (c_parser
*parser
)
491 c_token
*token
= c_parser_peek_token (parser
);
492 return c_token_starts_declspecs (token
);
495 /* Return a pointer to the next-but-one token from PARSER, reading it
496 in if necessary. The next token is already read in. */
499 c_parser_peek_2nd_token (c_parser
*parser
)
501 if (parser
->tokens_avail
>= 2)
502 return &parser
->tokens
[1];
503 gcc_assert (parser
->tokens_avail
== 1);
504 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
505 gcc_assert (parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
506 c_lex_one_token (parser
, &parser
->tokens
[1]);
507 parser
->tokens_avail
= 2;
508 return &parser
->tokens
[1];
511 /* Consume the next token from PARSER. */
514 c_parser_consume_token (c_parser
*parser
)
516 gcc_assert (parser
->tokens_avail
>= 1);
517 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
518 gcc_assert (!parser
->in_pragma
|| parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
519 gcc_assert (parser
->error
|| parser
->tokens
[0].type
!= CPP_PRAGMA
);
520 if (parser
->tokens_avail
== 2)
521 parser
->tokens
[0] = parser
->tokens
[1];
522 parser
->tokens_avail
--;
525 /* Expect the current token to be a #pragma. Consume it and remember
526 that we've begun parsing a pragma. */
529 c_parser_consume_pragma (c_parser
*parser
)
531 gcc_assert (!parser
->in_pragma
);
532 gcc_assert (parser
->tokens_avail
>= 1);
533 gcc_assert (parser
->tokens
[0].type
== CPP_PRAGMA
);
534 if (parser
->tokens_avail
== 2)
535 parser
->tokens
[0] = parser
->tokens
[1];
536 parser
->tokens_avail
--;
537 parser
->in_pragma
= true;
540 /* Update the globals input_location and in_system_header from
543 c_parser_set_source_position_from_token (c_token
*token
)
545 if (token
->type
!= CPP_EOF
)
547 input_location
= token
->location
;
548 in_system_header
= token
->in_system_header
;
552 /* Issue a diagnostic of the form
553 FILE:LINE: MESSAGE before TOKEN
554 where TOKEN is the next token in the input stream of PARSER.
555 MESSAGE (specified by the caller) is usually of the form "expected
558 Do not issue a diagnostic if still recovering from an error.
560 ??? This is taken from the C++ parser, but building up messages in
561 this way is not i18n-friendly and some other approach should be
565 c_parser_error (c_parser
*parser
, const char *gmsgid
)
567 c_token
*token
= c_parser_peek_token (parser
);
570 parser
->error
= true;
573 /* This diagnostic makes more sense if it is tagged to the line of
574 the token we just peeked at. */
575 c_parser_set_source_position_from_token (token
);
576 c_parse_error (gmsgid
,
577 /* Because c_parse_error does not understand
578 CPP_KEYWORD, keywords are treated like
580 (token
->type
== CPP_KEYWORD
? CPP_NAME
: token
->type
),
584 /* If the next token is of the indicated TYPE, consume it. Otherwise,
585 issue the error MSGID. If MSGID is NULL then a message has already
586 been produced and no message will be produced this time. Returns
587 true if found, false otherwise. */
590 c_parser_require (c_parser
*parser
,
594 if (c_parser_next_token_is (parser
, type
))
596 c_parser_consume_token (parser
);
601 c_parser_error (parser
, msgid
);
606 /* If the next token is the indicated keyword, consume it. Otherwise,
607 issue the error MSGID. Returns true if found, false otherwise. */
610 c_parser_require_keyword (c_parser
*parser
,
614 if (c_parser_next_token_is_keyword (parser
, keyword
))
616 c_parser_consume_token (parser
);
621 c_parser_error (parser
, msgid
);
626 /* Like c_parser_require, except that tokens will be skipped until the
627 desired token is found. An error message is still produced if the
628 next token is not as expected. If MSGID is NULL then a message has
629 already been produced and no message will be produced this
633 c_parser_skip_until_found (c_parser
*parser
,
637 unsigned nesting_depth
= 0;
639 if (c_parser_require (parser
, type
, msgid
))
642 /* Skip tokens until the desired token is found. */
645 /* Peek at the next token. */
646 c_token
*token
= c_parser_peek_token (parser
);
647 /* If we've reached the token we want, consume it and stop. */
648 if (token
->type
== type
&& !nesting_depth
)
650 c_parser_consume_token (parser
);
654 /* If we've run out of tokens, stop. */
655 if (token
->type
== CPP_EOF
)
657 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
659 if (token
->type
== CPP_OPEN_BRACE
660 || token
->type
== CPP_OPEN_PAREN
661 || token
->type
== CPP_OPEN_SQUARE
)
663 else if (token
->type
== CPP_CLOSE_BRACE
664 || token
->type
== CPP_CLOSE_PAREN
665 || token
->type
== CPP_CLOSE_SQUARE
)
667 if (nesting_depth
-- == 0)
670 /* Consume this token. */
671 c_parser_consume_token (parser
);
673 parser
->error
= false;
676 /* Skip tokens until the end of a parameter is found, but do not
677 consume the comma, semicolon or closing delimiter. */
680 c_parser_skip_to_end_of_parameter (c_parser
*parser
)
682 unsigned nesting_depth
= 0;
686 c_token
*token
= c_parser_peek_token (parser
);
687 if ((token
->type
== CPP_COMMA
|| token
->type
== CPP_SEMICOLON
)
690 /* If we've run out of tokens, stop. */
691 if (token
->type
== CPP_EOF
)
693 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
695 if (token
->type
== CPP_OPEN_BRACE
696 || token
->type
== CPP_OPEN_PAREN
697 || token
->type
== CPP_OPEN_SQUARE
)
699 else if (token
->type
== CPP_CLOSE_BRACE
700 || token
->type
== CPP_CLOSE_PAREN
701 || token
->type
== CPP_CLOSE_SQUARE
)
703 if (nesting_depth
-- == 0)
706 /* Consume this token. */
707 c_parser_consume_token (parser
);
709 parser
->error
= false;
712 /* Expect to be at the end of the pragma directive and consume an
713 end of line marker. */
716 c_parser_skip_to_pragma_eol (c_parser
*parser
)
718 gcc_assert (parser
->in_pragma
);
719 parser
->in_pragma
= false;
721 if (!c_parser_require (parser
, CPP_PRAGMA_EOL
, "expected end of line"))
724 c_token
*token
= c_parser_peek_token (parser
);
725 if (token
->type
== CPP_EOF
)
727 if (token
->type
== CPP_PRAGMA_EOL
)
729 c_parser_consume_token (parser
);
732 c_parser_consume_token (parser
);
735 parser
->error
= false;
738 /* Skip tokens until we have consumed an entire block, or until we
739 have consumed a non-nested ';'. */
742 c_parser_skip_to_end_of_block_or_statement (c_parser
*parser
)
744 unsigned nesting_depth
= 0;
745 bool save_error
= parser
->error
;
751 /* Peek at the next token. */
752 token
= c_parser_peek_token (parser
);
760 if (parser
->in_pragma
)
765 /* If the next token is a ';', we have reached the
766 end of the statement. */
769 /* Consume the ';'. */
770 c_parser_consume_token (parser
);
775 case CPP_CLOSE_BRACE
:
776 /* If the next token is a non-nested '}', then we have
777 reached the end of the current block. */
778 if (nesting_depth
== 0 || --nesting_depth
== 0)
780 c_parser_consume_token (parser
);
786 /* If it the next token is a '{', then we are entering a new
787 block. Consume the entire block. */
792 /* If we see a pragma, consume the whole thing at once. We
793 have some safeguards against consuming pragmas willy-nilly.
794 Normally, we'd expect to be here with parser->error set,
795 which disables these safeguards. But it's possible to get
796 here for secondary error recovery, after parser->error has
798 c_parser_consume_pragma (parser
);
799 c_parser_skip_to_pragma_eol (parser
);
800 parser
->error
= save_error
;
807 c_parser_consume_token (parser
);
811 parser
->error
= false;
814 /* Save the warning flags which are controlled by __extension__. */
817 disable_extension_diagnostics (void)
820 | (warn_pointer_arith
<< 1)
821 | (warn_traditional
<< 2)
824 warn_pointer_arith
= 0;
825 warn_traditional
= 0;
830 /* Restore the warning flags which are controlled by __extension__.
831 FLAGS is the return value from disable_extension_diagnostics. */
834 restore_extension_diagnostics (int flags
)
836 pedantic
= flags
& 1;
837 warn_pointer_arith
= (flags
>> 1) & 1;
838 warn_traditional
= (flags
>> 2) & 1;
839 flag_iso
= (flags
>> 3) & 1;
842 /* Possibly kinds of declarator to parse. */
843 typedef enum c_dtr_syn
{
844 /* A normal declarator with an identifier. */
846 /* An abstract declarator (maybe empty). */
848 /* A parameter declarator: may be either, but after a type name does
849 not redeclare a typedef name as an identifier if it can
850 alternatively be interpreted as a typedef name; see DR#009,
851 applied in C90 TC1, omitted from C99 and reapplied in C99 TC2
852 following DR#249. For example, given a typedef T, "int T" and
853 "int *T" are valid parameter declarations redeclaring T, while
854 "int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are
855 abstract declarators rather than involving redundant parentheses;
856 the same applies with attributes inside the parentheses before
861 static void c_parser_external_declaration (c_parser
*);
862 static void c_parser_asm_definition (c_parser
*);
863 static void c_parser_declaration_or_fndef (c_parser
*, bool, bool, bool, bool);
864 static void c_parser_declspecs (c_parser
*, struct c_declspecs
*, bool, bool,
866 static struct c_typespec
c_parser_enum_specifier (c_parser
*);
867 static struct c_typespec
c_parser_struct_or_union_specifier (c_parser
*);
868 static tree
c_parser_struct_declaration (c_parser
*);
869 static struct c_typespec
c_parser_typeof_specifier (c_parser
*);
870 static struct c_declarator
*c_parser_declarator (c_parser
*, bool, c_dtr_syn
,
872 static struct c_declarator
*c_parser_direct_declarator (c_parser
*, bool,
874 static struct c_declarator
*c_parser_direct_declarator_inner (c_parser
*,
876 struct c_declarator
*);
877 static struct c_arg_info
*c_parser_parms_declarator (c_parser
*, bool, tree
);
878 static struct c_arg_info
*c_parser_parms_list_declarator (c_parser
*, tree
);
879 static struct c_parm
*c_parser_parameter_declaration (c_parser
*, tree
);
880 static tree
c_parser_simple_asm_expr (c_parser
*);
881 static tree
c_parser_attributes (c_parser
*);
882 static struct c_type_name
*c_parser_type_name (c_parser
*);
883 static struct c_expr
c_parser_initializer (c_parser
*);
884 static struct c_expr
c_parser_braced_init (c_parser
*, tree
, bool);
885 static void c_parser_initelt (c_parser
*);
886 static void c_parser_initval (c_parser
*, struct c_expr
*);
887 static tree
c_parser_compound_statement (c_parser
*);
888 static void c_parser_compound_statement_nostart (c_parser
*);
889 static void c_parser_label (c_parser
*);
890 static void c_parser_statement (c_parser
*);
891 static void c_parser_statement_after_labels (c_parser
*);
892 static void c_parser_if_statement (c_parser
*);
893 static void c_parser_switch_statement (c_parser
*);
894 static void c_parser_while_statement (c_parser
*);
895 static void c_parser_do_statement (c_parser
*);
896 static void c_parser_for_statement (c_parser
*);
897 static tree
c_parser_asm_statement (c_parser
*);
898 static tree
c_parser_asm_operands (c_parser
*, bool);
899 static tree
c_parser_asm_clobbers (c_parser
*);
900 static struct c_expr
c_parser_expr_no_commas (c_parser
*, struct c_expr
*);
901 static struct c_expr
c_parser_conditional_expression (c_parser
*,
903 static struct c_expr
c_parser_binary_expression (c_parser
*, struct c_expr
*);
904 static struct c_expr
c_parser_cast_expression (c_parser
*, struct c_expr
*);
905 static struct c_expr
c_parser_unary_expression (c_parser
*);
906 static struct c_expr
c_parser_sizeof_expression (c_parser
*);
907 static struct c_expr
c_parser_alignof_expression (c_parser
*);
908 static struct c_expr
c_parser_postfix_expression (c_parser
*);
909 static struct c_expr
c_parser_postfix_expression_after_paren_type (c_parser
*,
910 struct c_type_name
*);
911 static struct c_expr
c_parser_postfix_expression_after_primary (c_parser
*,
913 static struct c_expr
c_parser_expression (c_parser
*);
914 static struct c_expr
c_parser_expression_conv (c_parser
*);
915 static tree
c_parser_expr_list (c_parser
*, bool);
916 static void c_parser_omp_construct (c_parser
*);
917 static void c_parser_omp_threadprivate (c_parser
*);
918 static void c_parser_omp_barrier (c_parser
*);
919 static void c_parser_omp_flush (c_parser
*);
920 static void c_parser_omp_taskwait (c_parser
*);
922 enum pragma_context
{ pragma_external
, pragma_stmt
, pragma_compound
};
923 static bool c_parser_pragma (c_parser
*, enum pragma_context
);
925 /* These Objective-C parser functions are only ever called when
926 compiling Objective-C. */
927 static void c_parser_objc_class_definition (c_parser
*);
928 static void c_parser_objc_class_instance_variables (c_parser
*);
929 static void c_parser_objc_class_declaration (c_parser
*);
930 static void c_parser_objc_alias_declaration (c_parser
*);
931 static void c_parser_objc_protocol_definition (c_parser
*);
932 static enum tree_code
c_parser_objc_method_type (c_parser
*);
933 static void c_parser_objc_method_definition (c_parser
*);
934 static void c_parser_objc_methodprotolist (c_parser
*);
935 static void c_parser_objc_methodproto (c_parser
*);
936 static tree
c_parser_objc_method_decl (c_parser
*);
937 static tree
c_parser_objc_type_name (c_parser
*);
938 static tree
c_parser_objc_protocol_refs (c_parser
*);
939 static void c_parser_objc_try_catch_statement (c_parser
*);
940 static void c_parser_objc_synchronized_statement (c_parser
*);
941 static tree
c_parser_objc_selector (c_parser
*);
942 static tree
c_parser_objc_selector_arg (c_parser
*);
943 static tree
c_parser_objc_receiver (c_parser
*);
944 static tree
c_parser_objc_message_args (c_parser
*);
945 static tree
c_parser_objc_keywordexpr (c_parser
*);
947 /* Parse a translation unit (C90 6.7, C99 6.9).
950 external-declarations
952 external-declarations:
954 external-declarations external-declaration
963 c_parser_translation_unit (c_parser
*parser
)
965 if (c_parser_next_token_is (parser
, CPP_EOF
))
968 pedwarn ("%HISO C forbids an empty translation unit",
969 &c_parser_peek_token (parser
)->location
);
973 void *obstack_position
= obstack_alloc (&parser_obstack
, 0);
977 c_parser_external_declaration (parser
);
978 obstack_free (&parser_obstack
, obstack_position
);
980 while (c_parser_next_token_is_not (parser
, CPP_EOF
));
984 /* Parse an external declaration (C90 6.7, C99 6.9).
986 external-declaration:
992 external-declaration:
995 __extension__ external-declaration
999 external-declaration:
1000 objc-class-definition
1001 objc-class-declaration
1002 objc-alias-declaration
1003 objc-protocol-definition
1004 objc-method-definition
1009 c_parser_external_declaration (c_parser
*parser
)
1012 switch (c_parser_peek_token (parser
)->type
)
1015 switch (c_parser_peek_token (parser
)->keyword
)
1018 ext
= disable_extension_diagnostics ();
1019 c_parser_consume_token (parser
);
1020 c_parser_external_declaration (parser
);
1021 restore_extension_diagnostics (ext
);
1024 c_parser_asm_definition (parser
);
1026 case RID_AT_INTERFACE
:
1027 case RID_AT_IMPLEMENTATION
:
1028 gcc_assert (c_dialect_objc ());
1029 c_parser_objc_class_definition (parser
);
1032 gcc_assert (c_dialect_objc ());
1033 c_parser_objc_class_declaration (parser
);
1036 gcc_assert (c_dialect_objc ());
1037 c_parser_objc_alias_declaration (parser
);
1039 case RID_AT_PROTOCOL
:
1040 gcc_assert (c_dialect_objc ());
1041 c_parser_objc_protocol_definition (parser
);
1044 gcc_assert (c_dialect_objc ());
1045 c_parser_consume_token (parser
);
1046 objc_finish_implementation ();
1054 pedwarn ("%HISO C does not allow extra %<;%> outside of a function",
1055 &c_parser_peek_token (parser
)->location
);
1056 c_parser_consume_token (parser
);
1059 c_parser_pragma (parser
, pragma_external
);
1063 if (c_dialect_objc ())
1065 c_parser_objc_method_definition (parser
);
1068 /* Else fall through, and yield a syntax error trying to parse
1069 as a declaration or function definition. */
1072 /* A declaration or a function definition. We can only tell
1073 which after parsing the declaration specifiers, if any, and
1074 the first declarator. */
1075 c_parser_declaration_or_fndef (parser
, true, true, false, true);
1081 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1082 6.7, 6.9.1). If FNDEF_OK is true, a function definition is
1083 accepted; otherwise (old-style parameter declarations) only other
1084 declarations are accepted. If NESTED is true, we are inside a
1085 function or parsing old-style parameter declarations; any functions
1086 encountered are nested functions and declaration specifiers are
1087 required; otherwise we are at top level and functions are normal
1088 functions and declaration specifiers may be optional. If EMPTY_OK
1089 is true, empty declarations are OK (subject to all other
1090 constraints); otherwise (old-style parameter declarations) they are
1091 diagnosed. If START_ATTR_OK is true, the declaration specifiers
1092 may start with attributes; otherwise they may not.
1095 declaration-specifiers init-declarator-list[opt] ;
1097 function-definition:
1098 declaration-specifiers[opt] declarator declaration-list[opt]
1103 declaration-list declaration
1105 init-declarator-list:
1107 init-declarator-list , init-declarator
1110 declarator simple-asm-expr[opt] attributes[opt]
1111 declarator simple-asm-expr[opt] attributes[opt] = initializer
1115 nested-function-definition:
1116 declaration-specifiers declarator declaration-list[opt]
1119 The simple-asm-expr and attributes are GNU extensions.
1121 This function does not handle __extension__; that is handled in its
1122 callers. ??? Following the old parser, __extension__ may start
1123 external declarations, declarations in functions and declarations
1124 at the start of "for" loops, but not old-style parameter
1127 C99 requires declaration specifiers in a function definition; the
1128 absence is diagnosed through the diagnosis of implicit int. In GNU
1129 C we also allow but diagnose declarations without declaration
1130 specifiers, but only at top level (elsewhere they conflict with
1136 threadprivate-directive */
1139 c_parser_declaration_or_fndef (c_parser
*parser
, bool fndef_ok
, bool empty_ok
,
1140 bool nested
, bool start_attr_ok
)
1142 struct c_declspecs
*specs
;
1144 tree all_prefix_attrs
;
1145 bool diagnosed_no_specs
= false;
1146 location_t here
= c_parser_peek_token (parser
)->location
;
1148 specs
= build_null_declspecs ();
1149 c_parser_declspecs (parser
, specs
, true, true, start_attr_ok
);
1152 c_parser_skip_to_end_of_block_or_statement (parser
);
1155 if (nested
&& !specs
->declspecs_seen_p
)
1157 c_parser_error (parser
, "expected declaration specifiers");
1158 c_parser_skip_to_end_of_block_or_statement (parser
);
1161 finish_declspecs (specs
);
1162 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1168 shadow_tag_warned (specs
, 1);
1169 pedwarn ("%Hempty declaration", &here
);
1171 c_parser_consume_token (parser
);
1174 pending_xref_error ();
1175 prefix_attrs
= specs
->attrs
;
1176 all_prefix_attrs
= prefix_attrs
;
1177 specs
->attrs
= NULL_TREE
;
1180 struct c_declarator
*declarator
;
1183 /* Declaring either one or more declarators (in which case we
1184 should diagnose if there were no declaration specifiers) or a
1185 function definition (in which case the diagnostic for
1186 implicit int suffices). */
1187 declarator
= c_parser_declarator (parser
, specs
->type_seen_p
,
1188 C_DTR_NORMAL
, &dummy
);
1189 if (declarator
== NULL
)
1191 c_parser_skip_to_end_of_block_or_statement (parser
);
1194 if (c_parser_next_token_is (parser
, CPP_EQ
)
1195 || c_parser_next_token_is (parser
, CPP_COMMA
)
1196 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
1197 || c_parser_next_token_is_keyword (parser
, RID_ASM
)
1198 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1200 tree asm_name
= NULL_TREE
;
1201 tree postfix_attrs
= NULL_TREE
;
1202 if (!diagnosed_no_specs
&& !specs
->declspecs_seen_p
)
1204 diagnosed_no_specs
= true;
1205 pedwarn ("%Hdata definition has no type or storage class",
1208 /* Having seen a data definition, there cannot now be a
1209 function definition. */
1211 if (c_parser_next_token_is_keyword (parser
, RID_ASM
))
1212 asm_name
= c_parser_simple_asm_expr (parser
);
1213 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1214 postfix_attrs
= c_parser_attributes (parser
);
1215 if (c_parser_next_token_is (parser
, CPP_EQ
))
1219 c_parser_consume_token (parser
);
1220 /* The declaration of the variable is in effect while
1221 its initializer is parsed. */
1222 d
= start_decl (declarator
, specs
, true,
1223 chainon (postfix_attrs
, all_prefix_attrs
));
1225 d
= error_mark_node
;
1226 start_init (d
, asm_name
, global_bindings_p ());
1227 init
= c_parser_initializer (parser
);
1229 if (d
!= error_mark_node
)
1231 maybe_warn_string_init (TREE_TYPE (d
), init
);
1232 finish_decl (d
, init
.value
, asm_name
);
1237 tree d
= start_decl (declarator
, specs
, false,
1238 chainon (postfix_attrs
,
1241 finish_decl (d
, NULL_TREE
, asm_name
);
1243 if (c_parser_next_token_is (parser
, CPP_COMMA
))
1245 c_parser_consume_token (parser
);
1246 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1247 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
1250 all_prefix_attrs
= prefix_attrs
;
1253 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1255 c_parser_consume_token (parser
);
1260 c_parser_error (parser
, "expected %<,%> or %<;%>");
1261 c_parser_skip_to_end_of_block_or_statement (parser
);
1267 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, "
1268 "%<asm%> or %<__attribute__%>");
1269 c_parser_skip_to_end_of_block_or_statement (parser
);
1272 /* Function definition (nested or otherwise). */
1276 pedwarn ("%HISO C forbids nested functions", &here
);
1277 c_push_function_context ();
1279 if (!start_function (specs
, declarator
, all_prefix_attrs
))
1281 /* This can appear in many cases looking nothing like a
1282 function definition, so we don't give a more specific
1283 error suggesting there was one. */
1284 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
1285 "or %<__attribute__%>");
1287 c_pop_function_context ();
1290 /* Parse old-style parameter declarations. ??? Attributes are
1291 not allowed to start declaration specifiers here because of a
1292 syntax conflict between a function declaration with attribute
1293 suffix and a function definition with an attribute prefix on
1294 first old-style parameter declaration. Following the old
1295 parser, they are not accepted on subsequent old-style
1296 parameter declarations either. However, there is no
1297 ambiguity after the first declaration, nor indeed on the
1298 first as long as we don't allow postfix attributes after a
1299 declarator with a nonempty identifier list in a definition;
1300 and postfix attributes have never been accepted here in
1301 function definitions either. */
1302 while (c_parser_next_token_is_not (parser
, CPP_EOF
)
1303 && c_parser_next_token_is_not (parser
, CPP_OPEN_BRACE
))
1304 c_parser_declaration_or_fndef (parser
, false, false, true, false);
1305 DECL_SOURCE_LOCATION (current_function_decl
)
1306 = c_parser_peek_token (parser
)->location
;
1307 store_parm_decls ();
1308 fnbody
= c_parser_compound_statement (parser
);
1311 tree decl
= current_function_decl
;
1314 c_pop_function_context ();
1315 add_stmt (build_stmt (DECL_EXPR
, decl
));
1326 /* Parse an asm-definition (asm() outside a function body). This is a
1334 c_parser_asm_definition (c_parser
*parser
)
1336 tree asm_str
= c_parser_simple_asm_expr (parser
);
1338 cgraph_add_asm_node (asm_str
);
1339 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
1342 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
1343 6.7), adding them to SPECS (which may already include some).
1344 Storage class specifiers are accepted iff SCSPEC_OK; type
1345 specifiers are accepted iff TYPESPEC_OK; attributes are accepted at
1346 the start iff START_ATTR_OK.
1348 declaration-specifiers:
1349 storage-class-specifier declaration-specifiers[opt]
1350 type-specifier declaration-specifiers[opt]
1351 type-qualifier declaration-specifiers[opt]
1352 function-specifier declaration-specifiers[opt]
1354 Function specifiers (inline) are from C99, and are currently
1355 handled as storage class specifiers, as is __thread.
1357 C90 6.5.1, C99 6.7.1:
1358 storage-class-specifier:
1369 C90 6.5.2, C99 6.7.2:
1382 [_Imaginary removed in C99 TC2]
1383 struct-or-union-specifier
1387 (_Bool and _Complex are new in C99.)
1389 C90 6.5.3, C99 6.7.3:
1396 (restrict is new in C99.)
1400 declaration-specifiers:
1401 attributes declaration-specifiers[opt]
1403 storage-class-specifier:
1415 (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
1416 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
1421 class-name objc-protocol-refs[opt]
1422 typedef-name objc-protocol-refs
1427 c_parser_declspecs (c_parser
*parser
, struct c_declspecs
*specs
,
1428 bool scspec_ok
, bool typespec_ok
, bool start_attr_ok
)
1430 bool attrs_ok
= start_attr_ok
;
1431 bool seen_type
= specs
->type_seen_p
;
1432 while (c_parser_next_token_is (parser
, CPP_NAME
)
1433 || c_parser_next_token_is (parser
, CPP_KEYWORD
)
1434 || (c_dialect_objc () && c_parser_next_token_is (parser
, CPP_LESS
)))
1436 struct c_typespec t
;
1438 if (c_parser_next_token_is (parser
, CPP_NAME
))
1440 tree value
= c_parser_peek_token (parser
)->value
;
1441 c_id_kind kind
= c_parser_peek_token (parser
)->id_kind
;
1442 /* This finishes the specifiers unless a type name is OK, it
1443 is declared as a type name and a type name hasn't yet
1445 if (!typespec_ok
|| seen_type
1446 || (kind
!= C_ID_TYPENAME
&& kind
!= C_ID_CLASSNAME
))
1448 c_parser_consume_token (parser
);
1451 if (kind
== C_ID_TYPENAME
1452 && (!c_dialect_objc ()
1453 || c_parser_next_token_is_not (parser
, CPP_LESS
)))
1455 t
.kind
= ctsk_typedef
;
1456 /* For a typedef name, record the meaning, not the name.
1457 In case of 'foo foo, bar;'. */
1458 t
.spec
= lookup_name (value
);
1462 tree proto
= NULL_TREE
;
1463 gcc_assert (c_dialect_objc ());
1465 if (c_parser_next_token_is (parser
, CPP_LESS
))
1466 proto
= c_parser_objc_protocol_refs (parser
);
1467 t
.spec
= objc_get_protocol_qualified_type (value
, proto
);
1469 declspecs_add_type (specs
, t
);
1472 if (c_parser_next_token_is (parser
, CPP_LESS
))
1474 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
1475 nisse@lysator.liu.se. */
1477 gcc_assert (c_dialect_objc ());
1478 if (!typespec_ok
|| seen_type
)
1480 proto
= c_parser_objc_protocol_refs (parser
);
1482 t
.spec
= objc_get_protocol_qualified_type (NULL_TREE
, proto
);
1483 declspecs_add_type (specs
, t
);
1486 gcc_assert (c_parser_next_token_is (parser
, CPP_KEYWORD
));
1487 switch (c_parser_peek_token (parser
)->keyword
)
1499 /* TODO: Distinguish between function specifiers (inline)
1500 and storage class specifiers, either here or in
1501 declspecs_add_scspec. */
1502 declspecs_add_scspec (specs
, c_parser_peek_token (parser
)->value
);
1503 c_parser_consume_token (parser
);
1526 if (c_dialect_objc ())
1527 parser
->objc_need_raw_identifier
= true;
1528 t
.kind
= ctsk_resword
;
1529 t
.spec
= c_parser_peek_token (parser
)->value
;
1530 declspecs_add_type (specs
, t
);
1531 c_parser_consume_token (parser
);
1538 t
= c_parser_enum_specifier (parser
);
1539 declspecs_add_type (specs
, t
);
1547 t
= c_parser_struct_or_union_specifier (parser
);
1548 declspecs_add_type (specs
, t
);
1551 /* ??? The old parser rejected typeof after other type
1552 specifiers, but is a syntax error the best way of
1554 if (!typespec_ok
|| seen_type
)
1558 t
= c_parser_typeof_specifier (parser
);
1559 declspecs_add_type (specs
, t
);
1565 declspecs_add_qual (specs
, c_parser_peek_token (parser
)->value
);
1566 c_parser_consume_token (parser
);
1571 attrs
= c_parser_attributes (parser
);
1572 declspecs_add_attrs (specs
, attrs
);
1581 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
1584 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
1585 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
1586 enum attributes[opt] identifier
1588 The form with trailing comma is new in C99. The forms with
1589 attributes are GNU extensions. In GNU C, we accept any expression
1590 without commas in the syntax (assignment expressions, not just
1591 conditional expressions); assignment expressions will be diagnosed
1596 enumerator-list , enumerator
1599 enumeration-constant
1600 enumeration-constant = constant-expression
1603 static struct c_typespec
1604 c_parser_enum_specifier (c_parser
*parser
)
1606 struct c_typespec ret
;
1608 tree ident
= NULL_TREE
;
1609 location_t ident_loc
;
1610 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ENUM
));
1611 c_parser_consume_token (parser
);
1612 attrs
= c_parser_attributes (parser
);
1613 /* Set the location in case we create a decl now. */
1614 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
1615 if (c_parser_next_token_is (parser
, CPP_NAME
))
1617 ident
= c_parser_peek_token (parser
)->value
;
1618 ident_loc
= c_parser_peek_token (parser
)->location
;
1619 c_parser_consume_token (parser
);
1621 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
1623 /* Parse an enum definition. */
1624 struct c_enum_contents the_enum
;
1625 tree type
= start_enum (&the_enum
, ident
);
1627 /* We chain the enumerators in reverse order, then put them in
1628 forward order at the end. */
1629 tree values
= NULL_TREE
;
1630 c_parser_consume_token (parser
);
1638 location_t comma_loc
;
1639 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
1641 c_parser_error (parser
, "expected identifier");
1642 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
1643 values
= error_mark_node
;
1646 token
= c_parser_peek_token (parser
);
1647 enum_id
= token
->value
;
1648 /* Set the location in case we create a decl now. */
1649 c_parser_set_source_position_from_token (token
);
1650 c_parser_consume_token (parser
);
1651 if (c_parser_next_token_is (parser
, CPP_EQ
))
1653 c_parser_consume_token (parser
);
1654 enum_value
= c_parser_expr_no_commas (parser
, NULL
).value
;
1657 enum_value
= NULL_TREE
;
1658 enum_decl
= build_enumerator (&the_enum
, enum_id
, enum_value
);
1659 TREE_CHAIN (enum_decl
) = values
;
1662 if (c_parser_next_token_is (parser
, CPP_COMMA
))
1664 comma_loc
= c_parser_peek_token (parser
)->location
;
1666 c_parser_consume_token (parser
);
1668 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
1670 if (seen_comma
&& pedantic
&& !flag_isoc99
)
1671 pedwarn ("%Hcomma at end of enumerator list", &comma_loc
);
1672 c_parser_consume_token (parser
);
1677 c_parser_error (parser
, "expected %<,%> or %<}%>");
1678 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
1679 values
= error_mark_node
;
1683 postfix_attrs
= c_parser_attributes (parser
);
1684 ret
.spec
= finish_enum (type
, nreverse (values
),
1685 chainon (attrs
, postfix_attrs
));
1686 ret
.kind
= ctsk_tagdef
;
1691 c_parser_error (parser
, "expected %<{%>");
1692 ret
.spec
= error_mark_node
;
1693 ret
.kind
= ctsk_tagref
;
1696 ret
= parser_xref_tag (ENUMERAL_TYPE
, ident
);
1697 /* In ISO C, enumerated types can be referred to only if already
1699 if (pedantic
&& !COMPLETE_TYPE_P (ret
.spec
))
1702 pedwarn ("%HISO C forbids forward references to %<enum%> types",
1708 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
1710 struct-or-union-specifier:
1711 struct-or-union attributes[opt] identifier[opt]
1712 { struct-contents } attributes[opt]
1713 struct-or-union attributes[opt] identifier
1716 struct-declaration-list
1718 struct-declaration-list:
1719 struct-declaration ;
1720 struct-declaration-list struct-declaration ;
1727 struct-declaration-list struct-declaration
1729 struct-declaration-list:
1730 struct-declaration-list ;
1733 (Note that in the syntax here, unlike that in ISO C, the semicolons
1734 are included here rather than in struct-declaration, in order to
1735 describe the syntax with extra semicolons and missing semicolon at
1740 struct-declaration-list:
1741 @defs ( class-name )
1743 (Note this does not include a trailing semicolon, but can be
1744 followed by further declarations, and gets a pedwarn-if-pedantic
1745 when followed by a semicolon.) */
1747 static struct c_typespec
1748 c_parser_struct_or_union_specifier (c_parser
*parser
)
1750 struct c_typespec ret
;
1752 tree ident
= NULL_TREE
;
1753 enum tree_code code
;
1754 switch (c_parser_peek_token (parser
)->keyword
)
1765 c_parser_consume_token (parser
);
1766 attrs
= c_parser_attributes (parser
);
1767 /* Set the location in case we create a decl now. */
1768 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
1769 if (c_parser_next_token_is (parser
, CPP_NAME
))
1771 ident
= c_parser_peek_token (parser
)->value
;
1772 c_parser_consume_token (parser
);
1774 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
1776 /* Parse a struct or union definition. Start the scope of the
1777 tag before parsing components. */
1778 tree type
= start_struct (code
, ident
);
1780 /* We chain the components in reverse order, then put them in
1781 forward order at the end. Each struct-declaration may
1782 declare multiple components (comma-separated), so we must use
1783 chainon to join them, although when parsing each
1784 struct-declaration we can use TREE_CHAIN directly.
1786 The theory behind all this is that there will be more
1787 semicolon separated fields than comma separated fields, and
1788 so we'll be minimizing the number of node traversals required
1790 tree contents
= NULL_TREE
;
1791 c_parser_consume_token (parser
);
1792 /* Handle the Objective-C @defs construct,
1793 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
1794 if (c_parser_next_token_is_keyword (parser
, RID_AT_DEFS
))
1797 gcc_assert (c_dialect_objc ());
1798 c_parser_consume_token (parser
);
1799 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
1801 if (c_parser_next_token_is (parser
, CPP_NAME
)
1802 && c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
)
1804 name
= c_parser_peek_token (parser
)->value
;
1805 c_parser_consume_token (parser
);
1809 c_parser_error (parser
, "expected class name");
1810 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
1813 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
1815 contents
= nreverse (objc_get_class_ivars (name
));
1818 /* Parse the struct-declarations and semicolons. Problems with
1819 semicolons are diagnosed here; empty structures are diagnosed
1824 /* Parse any stray semicolon. */
1825 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1828 pedwarn ("%Hextra semicolon in struct or union specified",
1829 &c_parser_peek_token (parser
)->location
);
1830 c_parser_consume_token (parser
);
1833 /* Stop if at the end of the struct or union contents. */
1834 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
1836 c_parser_consume_token (parser
);
1839 /* Accept #pragmas at struct scope. */
1840 if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
1842 c_parser_pragma (parser
, pragma_external
);
1845 /* Parse some comma-separated declarations, but not the
1846 trailing semicolon if any. */
1847 decls
= c_parser_struct_declaration (parser
);
1848 contents
= chainon (decls
, contents
);
1849 /* If no semicolon follows, either we have a parse error or
1850 are at the end of the struct or union and should
1852 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1853 c_parser_consume_token (parser
);
1856 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
1857 pedwarn ("%Hno semicolon at end of struct or union",
1858 &c_parser_peek_token (parser
)->location
);
1861 c_parser_error (parser
, "expected %<;%>");
1862 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
1867 postfix_attrs
= c_parser_attributes (parser
);
1868 ret
.spec
= finish_struct (type
, nreverse (contents
),
1869 chainon (attrs
, postfix_attrs
));
1870 ret
.kind
= ctsk_tagdef
;
1875 c_parser_error (parser
, "expected %<{%>");
1876 ret
.spec
= error_mark_node
;
1877 ret
.kind
= ctsk_tagref
;
1880 ret
= parser_xref_tag (code
, ident
);
1884 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
1885 the trailing semicolon.
1888 specifier-qualifier-list struct-declarator-list
1890 specifier-qualifier-list:
1891 type-specifier specifier-qualifier-list[opt]
1892 type-qualifier specifier-qualifier-list[opt]
1893 attributes specifier-qualifier-list[opt]
1895 struct-declarator-list:
1897 struct-declarator-list , attributes[opt] struct-declarator
1900 declarator attributes[opt]
1901 declarator[opt] : constant-expression attributes[opt]
1906 __extension__ struct-declaration
1907 specifier-qualifier-list
1909 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
1910 of attributes where shown is a GNU extension. In GNU C, we accept
1911 any expression without commas in the syntax (assignment
1912 expressions, not just conditional expressions); assignment
1913 expressions will be diagnosed as non-constant. */
1916 c_parser_struct_declaration (c_parser
*parser
)
1918 struct c_declspecs
*specs
;
1920 tree all_prefix_attrs
;
1922 location_t decl_loc
;
1923 if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
1927 ext
= disable_extension_diagnostics ();
1928 c_parser_consume_token (parser
);
1929 decl
= c_parser_struct_declaration (parser
);
1930 restore_extension_diagnostics (ext
);
1933 specs
= build_null_declspecs ();
1934 decl_loc
= c_parser_peek_token (parser
)->location
;
1935 c_parser_declspecs (parser
, specs
, false, true, true);
1938 if (!specs
->declspecs_seen_p
)
1940 c_parser_error (parser
, "expected specifier-qualifier-list");
1943 finish_declspecs (specs
);
1944 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1947 if (!specs
->type_seen_p
)
1950 pedwarn ("%HISO C forbids member declarations with no members",
1952 shadow_tag_warned (specs
, pedantic
);
1957 /* Support for unnamed structs or unions as members of
1958 structs or unions (which is [a] useful and [b] supports
1961 ret
= grokfield (build_id_declarator (NULL_TREE
), specs
,
1964 decl_attributes (&ret
, attrs
, 0);
1968 pending_xref_error ();
1969 prefix_attrs
= specs
->attrs
;
1970 all_prefix_attrs
= prefix_attrs
;
1971 specs
->attrs
= NULL_TREE
;
1975 /* Declaring one or more declarators or un-named bit-fields. */
1976 struct c_declarator
*declarator
;
1978 if (c_parser_next_token_is (parser
, CPP_COLON
))
1979 declarator
= build_id_declarator (NULL_TREE
);
1981 declarator
= c_parser_declarator (parser
, specs
->type_seen_p
,
1982 C_DTR_NORMAL
, &dummy
);
1983 if (declarator
== NULL
)
1985 c_parser_skip_to_end_of_block_or_statement (parser
);
1988 if (c_parser_next_token_is (parser
, CPP_COLON
)
1989 || c_parser_next_token_is (parser
, CPP_COMMA
)
1990 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
1991 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
)
1992 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1994 tree postfix_attrs
= NULL_TREE
;
1995 tree width
= NULL_TREE
;
1997 if (c_parser_next_token_is (parser
, CPP_COLON
))
1999 c_parser_consume_token (parser
);
2000 width
= c_parser_expr_no_commas (parser
, NULL
).value
;
2002 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2003 postfix_attrs
= c_parser_attributes (parser
);
2004 d
= grokfield (declarator
, specs
, width
, &all_prefix_attrs
);
2005 decl_attributes (&d
, chainon (postfix_attrs
,
2006 all_prefix_attrs
), 0);
2007 TREE_CHAIN (d
) = decls
;
2009 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2010 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
2013 all_prefix_attrs
= prefix_attrs
;
2014 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2015 c_parser_consume_token (parser
);
2016 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2017 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2019 /* Semicolon consumed in caller. */
2024 c_parser_error (parser
, "expected %<,%>, %<;%> or %<}%>");
2030 c_parser_error (parser
,
2031 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
2032 "%<__attribute__%>");
2039 /* Parse a typeof specifier (a GNU extension).
2042 typeof ( expression )
2043 typeof ( type-name )
2046 static struct c_typespec
2047 c_parser_typeof_specifier (c_parser
*parser
)
2049 struct c_typespec ret
;
2050 ret
.kind
= ctsk_typeof
;
2051 ret
.spec
= error_mark_node
;
2052 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TYPEOF
));
2053 c_parser_consume_token (parser
);
2056 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2062 if (c_parser_next_token_starts_typename (parser
))
2064 struct c_type_name
*type
= c_parser_type_name (parser
);
2069 ret
.spec
= groktypename (type
);
2070 pop_maybe_used (variably_modified_type_p (ret
.spec
, NULL_TREE
));
2076 location_t here
= c_parser_peek_token (parser
)->location
;
2077 struct c_expr expr
= c_parser_expression (parser
);
2080 if (TREE_CODE (expr
.value
) == COMPONENT_REF
2081 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
2082 error ("%H%<typeof%> applied to a bit-field", &here
);
2083 ret
.spec
= TREE_TYPE (expr
.value
);
2084 was_vm
= variably_modified_type_p (ret
.spec
, NULL_TREE
);
2085 /* This should be returned with the type so that when the type
2086 is evaluated, this can be evaluated. For now, we avoid
2087 evaluation when the context might. */
2088 if (!skip_evaluation
&& was_vm
)
2090 tree e
= expr
.value
;
2092 /* If the expression is not of a type to which we cannot assign a line
2093 number, wrap the thing in a no-op NOP_EXPR. */
2094 if (DECL_P (e
) || CONSTANT_CLASS_P (e
))
2095 e
= build1 (NOP_EXPR
, void_type_node
, e
);
2097 if (CAN_HAVE_LOCATION_P (e
))
2098 SET_EXPR_LOCATION (e
, input_location
);
2102 pop_maybe_used (was_vm
);
2104 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
2108 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
2109 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
2110 be redeclared; otherwise it may not. KIND indicates which kind of
2111 declarator is wanted. Returns a valid declarator except in the
2112 case of a syntax error in which case NULL is returned. *SEEN_ID is
2113 set to true if an identifier being declared is seen; this is used
2114 to diagnose bad forms of abstract array declarators and to
2115 determine whether an identifier list is syntactically permitted.
2118 pointer[opt] direct-declarator
2122 ( attributes[opt] declarator )
2123 direct-declarator array-declarator
2124 direct-declarator ( parameter-type-list )
2125 direct-declarator ( identifier-list[opt] )
2128 * type-qualifier-list[opt]
2129 * type-qualifier-list[opt] pointer
2131 type-qualifier-list:
2134 type-qualifier-list type-qualifier
2135 type-qualifier-list attributes
2137 parameter-type-list:
2139 parameter-list , ...
2142 parameter-declaration
2143 parameter-list , parameter-declaration
2145 parameter-declaration:
2146 declaration-specifiers declarator attributes[opt]
2147 declaration-specifiers abstract-declarator[opt] attributes[opt]
2151 identifier-list , identifier
2153 abstract-declarator:
2155 pointer[opt] direct-abstract-declarator
2157 direct-abstract-declarator:
2158 ( attributes[opt] abstract-declarator )
2159 direct-abstract-declarator[opt] array-declarator
2160 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
2165 direct-declarator ( parameter-forward-declarations
2166 parameter-type-list[opt] )
2168 direct-abstract-declarator:
2169 direct-abstract-declarator[opt] ( parameter-forward-declarations
2170 parameter-type-list[opt] )
2172 parameter-forward-declarations:
2174 parameter-forward-declarations parameter-list ;
2176 The uses of attributes shown above are GNU extensions.
2178 Some forms of array declarator are not included in C99 in the
2179 syntax for abstract declarators; these are disallowed elsewhere.
2180 This may be a defect (DR#289).
2182 This function also accepts an omitted abstract declarator as being
2183 an abstract declarator, although not part of the formal syntax. */
2185 static struct c_declarator
*
2186 c_parser_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
2189 /* Parse any initial pointer part. */
2190 if (c_parser_next_token_is (parser
, CPP_MULT
))
2192 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
2193 struct c_declarator
*inner
;
2194 c_parser_consume_token (parser
);
2195 c_parser_declspecs (parser
, quals_attrs
, false, false, true);
2196 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
2200 return make_pointer_declarator (quals_attrs
, inner
);
2202 /* Now we have a direct declarator, direct abstract declarator or
2203 nothing (which counts as a direct abstract declarator here). */
2204 return c_parser_direct_declarator (parser
, type_seen_p
, kind
, seen_id
);
2207 /* Parse a direct declarator or direct abstract declarator; arguments
2208 as c_parser_declarator. */
2210 static struct c_declarator
*
2211 c_parser_direct_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
2214 /* The direct declarator must start with an identifier (possibly
2215 omitted) or a parenthesized declarator (possibly abstract). In
2216 an ordinary declarator, initial parentheses must start a
2217 parenthesized declarator. In an abstract declarator or parameter
2218 declarator, they could start a parenthesized declarator or a
2219 parameter list. To tell which, the open parenthesis and any
2220 following attributes must be read. If a declaration specifier
2221 follows, then it is a parameter list; if the specifier is a
2222 typedef name, there might be an ambiguity about redeclaring it,
2223 which is resolved in the direction of treating it as a typedef
2224 name. If a close parenthesis follows, it is also an empty
2225 parameter list, as the syntax does not permit empty abstract
2226 declarators. Otherwise, it is a parenthesized declarator (in
2227 which case the analysis may be repeated inside it, recursively).
2229 ??? There is an ambiguity in a parameter declaration "int
2230 (__attribute__((foo)) x)", where x is not a typedef name: it
2231 could be an abstract declarator for a function, or declare x with
2232 parentheses. The proper resolution of this ambiguity needs
2233 documenting. At present we follow an accident of the old
2234 parser's implementation, whereby the first parameter must have
2235 some declaration specifiers other than just attributes. Thus as
2236 a parameter declaration it is treated as a parenthesized
2237 parameter named x, and as an abstract declarator it is
2240 ??? Also following the old parser, attributes inside an empty
2241 parameter list are ignored, making it a list not yielding a
2242 prototype, rather than giving an error or making it have one
2243 parameter with implicit type int.
2245 ??? Also following the old parser, typedef names may be
2246 redeclared in declarators, but not Objective-C class names. */
2248 if (kind
!= C_DTR_ABSTRACT
2249 && c_parser_next_token_is (parser
, CPP_NAME
)
2251 && c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
)
2252 || c_parser_peek_token (parser
)->id_kind
== C_ID_ID
))
2254 struct c_declarator
*inner
2255 = build_id_declarator (c_parser_peek_token (parser
)->value
);
2257 inner
->id_loc
= c_parser_peek_token (parser
)->location
;
2258 c_parser_consume_token (parser
);
2259 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
2262 if (kind
!= C_DTR_NORMAL
2263 && c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
2265 struct c_declarator
*inner
= build_id_declarator (NULL_TREE
);
2266 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
2269 /* Either we are at the end of an abstract declarator, or we have
2272 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
2275 struct c_declarator
*inner
;
2276 c_parser_consume_token (parser
);
2277 attrs
= c_parser_attributes (parser
);
2278 if (kind
!= C_DTR_NORMAL
2279 && (c_parser_next_token_starts_declspecs (parser
)
2280 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
)))
2282 struct c_arg_info
*args
2283 = c_parser_parms_declarator (parser
, kind
== C_DTR_NORMAL
,
2290 = build_function_declarator (args
,
2291 build_id_declarator (NULL_TREE
));
2292 return c_parser_direct_declarator_inner (parser
, *seen_id
,
2296 /* A parenthesized declarator. */
2297 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
2298 if (inner
!= NULL
&& attrs
!= NULL
)
2299 inner
= build_attrs_declarator (attrs
, inner
);
2300 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2302 c_parser_consume_token (parser
);
2306 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
2310 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2317 if (kind
== C_DTR_NORMAL
)
2319 c_parser_error (parser
, "expected identifier or %<(%>");
2323 return build_id_declarator (NULL_TREE
);
2327 /* Parse part of a direct declarator or direct abstract declarator,
2328 given that some (in INNER) has already been parsed; ID_PRESENT is
2329 true if an identifier is present, false for an abstract
2332 static struct c_declarator
*
2333 c_parser_direct_declarator_inner (c_parser
*parser
, bool id_present
,
2334 struct c_declarator
*inner
)
2336 /* Parse a sequence of array declarators and parameter lists. */
2337 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
2339 struct c_declarator
*declarator
;
2340 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
2344 c_parser_consume_token (parser
);
2345 c_parser_declspecs (parser
, quals_attrs
, false, false, true);
2346 static_seen
= c_parser_next_token_is_keyword (parser
, RID_STATIC
);
2348 c_parser_consume_token (parser
);
2349 if (static_seen
&& !quals_attrs
->declspecs_seen_p
)
2350 c_parser_declspecs (parser
, quals_attrs
, false, false, true);
2351 if (!quals_attrs
->declspecs_seen_p
)
2353 /* If "static" is present, there must be an array dimension.
2354 Otherwise, there may be a dimension, "*", or no
2359 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
2363 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
2368 else if (c_parser_next_token_is (parser
, CPP_MULT
))
2370 if (c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_SQUARE
)
2374 c_parser_consume_token (parser
);
2379 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
2385 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
2388 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
2389 c_parser_consume_token (parser
);
2392 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
2396 declarator
= build_array_declarator (dimen
, quals_attrs
, static_seen
,
2398 if (declarator
== NULL
)
2400 inner
= set_array_declarator_inner (declarator
, inner
);
2401 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
2403 else if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
2406 struct c_arg_info
*args
;
2407 c_parser_consume_token (parser
);
2408 attrs
= c_parser_attributes (parser
);
2409 args
= c_parser_parms_declarator (parser
, id_present
, attrs
);
2414 inner
= build_function_declarator (args
, inner
);
2415 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
2421 /* Parse a parameter list or identifier list, including the closing
2422 parenthesis but not the opening one. ATTRS are the attributes at
2423 the start of the list. ID_LIST_OK is true if an identifier list is
2424 acceptable; such a list must not have attributes at the start. */
2426 static struct c_arg_info
*
2427 c_parser_parms_declarator (c_parser
*parser
, bool id_list_ok
, tree attrs
)
2430 declare_parm_level ();
2431 /* If the list starts with an identifier, it is an identifier list.
2432 Otherwise, it is either a prototype list or an empty list. */
2435 && c_parser_next_token_is (parser
, CPP_NAME
)
2436 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
2438 tree list
= NULL_TREE
, *nextp
= &list
;
2439 while (c_parser_next_token_is (parser
, CPP_NAME
)
2440 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
2442 *nextp
= build_tree_list (NULL_TREE
,
2443 c_parser_peek_token (parser
)->value
);
2444 nextp
= & TREE_CHAIN (*nextp
);
2445 c_parser_consume_token (parser
);
2446 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
2448 c_parser_consume_token (parser
);
2449 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2451 c_parser_error (parser
, "expected identifier");
2455 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2457 struct c_arg_info
*ret
= XOBNEW (&parser_obstack
, struct c_arg_info
);
2462 ret
->pending_sizes
= 0;
2463 ret
->had_vla_unspec
= 0;
2464 c_parser_consume_token (parser
);
2470 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2478 struct c_arg_info
*ret
= c_parser_parms_list_declarator (parser
, attrs
);
2484 /* Parse a parameter list (possibly empty), including the closing
2485 parenthesis but not the opening one. ATTRS are the attributes at
2486 the start of the list. */
2488 static struct c_arg_info
*
2489 c_parser_parms_list_declarator (c_parser
*parser
, tree attrs
)
2491 bool good_parm
= false;
2492 /* ??? Following the old parser, forward parameter declarations may
2493 use abstract declarators, and if no real parameter declarations
2494 follow the forward declarations then this is not diagnosed. Also
2495 note as above that attributes are ignored as the only contents of
2496 the parentheses, or as the only contents after forward
2498 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2500 struct c_arg_info
*ret
= XOBNEW (&parser_obstack
, struct c_arg_info
);
2505 ret
->pending_sizes
= 0;
2506 ret
->had_vla_unspec
= 0;
2507 c_parser_consume_token (parser
);
2510 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
2512 struct c_arg_info
*ret
= XOBNEW (&parser_obstack
, struct c_arg_info
);
2516 ret
->pending_sizes
= 0;
2517 ret
->had_vla_unspec
= 0;
2518 /* Suppress -Wold-style-definition for this case. */
2519 ret
->types
= error_mark_node
;
2520 error ("%HISO C requires a named argument before %<...%>",
2521 &c_parser_peek_token (parser
)->location
);
2522 c_parser_consume_token (parser
);
2523 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2525 c_parser_consume_token (parser
);
2530 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2535 /* Nonempty list of parameters, either terminated with semicolon
2536 (forward declarations; recurse) or with close parenthesis (normal
2537 function) or with ", ... )" (variadic function). */
2540 /* Parse a parameter. */
2541 struct c_parm
*parm
= c_parser_parameter_declaration (parser
, attrs
);
2546 push_parm_decl (parm
);
2548 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2551 c_parser_consume_token (parser
);
2552 mark_forward_parm_decls ();
2553 new_attrs
= c_parser_attributes (parser
);
2554 return c_parser_parms_list_declarator (parser
, new_attrs
);
2556 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2558 c_parser_consume_token (parser
);
2560 return get_parm_info (false);
2563 struct c_arg_info
*ret
2564 = XOBNEW (&parser_obstack
, struct c_arg_info
);
2569 ret
->pending_sizes
= 0;
2570 ret
->had_vla_unspec
= 0;
2574 if (!c_parser_require (parser
, CPP_COMMA
,
2575 "expected %<;%>, %<,%> or %<)%>"))
2577 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2580 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
2582 c_parser_consume_token (parser
);
2583 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2585 c_parser_consume_token (parser
);
2587 return get_parm_info (true);
2590 struct c_arg_info
*ret
2591 = XOBNEW (&parser_obstack
, struct c_arg_info
);
2596 ret
->pending_sizes
= 0;
2597 ret
->had_vla_unspec
= 0;
2603 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2611 /* Parse a parameter declaration. ATTRS are the attributes at the
2612 start of the declaration if it is the first parameter. */
2614 static struct c_parm
*
2615 c_parser_parameter_declaration (c_parser
*parser
, tree attrs
)
2617 struct c_declspecs
*specs
;
2618 struct c_declarator
*declarator
;
2620 tree postfix_attrs
= NULL_TREE
;
2622 if (!c_parser_next_token_starts_declspecs (parser
))
2624 /* ??? In some Objective-C cases '...' isn't applicable so there
2625 should be a different message. */
2626 c_parser_error (parser
,
2627 "expected declaration specifiers or %<...%>");
2628 c_parser_skip_to_end_of_parameter (parser
);
2631 specs
= build_null_declspecs ();
2634 declspecs_add_attrs (specs
, attrs
);
2637 c_parser_declspecs (parser
, specs
, true, true, true);
2638 finish_declspecs (specs
);
2639 pending_xref_error ();
2640 prefix_attrs
= specs
->attrs
;
2641 specs
->attrs
= NULL_TREE
;
2642 declarator
= c_parser_declarator (parser
, specs
->type_seen_p
,
2643 C_DTR_PARM
, &dummy
);
2644 if (declarator
== NULL
)
2646 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
2649 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2650 postfix_attrs
= c_parser_attributes (parser
);
2651 return build_c_parm (specs
, chainon (postfix_attrs
, prefix_attrs
),
2655 /* Parse a string literal in an asm expression. It should not be
2656 translated, and wide string literals are an error although
2657 permitted by the syntax. This is a GNU extension.
2662 ??? At present, following the old parser, the caller needs to have
2663 set lex_untranslated_string to 1. It would be better to follow the
2664 C++ parser rather than using this kludge. */
2667 c_parser_asm_string_literal (c_parser
*parser
)
2670 if (c_parser_next_token_is (parser
, CPP_STRING
))
2672 str
= c_parser_peek_token (parser
)->value
;
2673 c_parser_consume_token (parser
);
2675 else if (c_parser_next_token_is (parser
, CPP_WSTRING
))
2677 error ("%Hwide string literal in %<asm%>",
2678 &c_parser_peek_token (parser
)->location
);
2679 str
= build_string (1, "");
2680 c_parser_consume_token (parser
);
2684 c_parser_error (parser
, "expected string literal");
2690 /* Parse a simple asm expression. This is used in restricted
2691 contexts, where a full expression with inputs and outputs does not
2692 make sense. This is a GNU extension.
2695 asm ( asm-string-literal )
2699 c_parser_simple_asm_expr (c_parser
*parser
)
2702 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
2703 /* ??? Follow the C++ parser rather than using the
2704 lex_untranslated_string kludge. */
2705 parser
->lex_untranslated_string
= true;
2706 c_parser_consume_token (parser
);
2707 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2709 parser
->lex_untranslated_string
= false;
2712 str
= c_parser_asm_string_literal (parser
);
2713 parser
->lex_untranslated_string
= false;
2714 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
2716 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2722 /* Parse (possibly empty) attributes. This is a GNU extension.
2726 attributes attribute
2729 __attribute__ ( ( attribute-list ) )
2733 attribute_list , attrib
2738 any-word ( identifier )
2739 any-word ( identifier , nonempty-expr-list )
2740 any-word ( expr-list )
2742 where the "identifier" must not be declared as a type, and
2743 "any-word" may be any identifier (including one declared as a
2744 type), a reserved word storage class specifier, type specifier or
2745 type qualifier. ??? This still leaves out most reserved keywords
2746 (following the old parser), shouldn't we include them, and why not
2747 allow identifiers declared as types to start the arguments? */
2750 c_parser_attributes (c_parser
*parser
)
2752 tree attrs
= NULL_TREE
;
2753 while (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2755 /* ??? Follow the C++ parser rather than using the
2756 lex_untranslated_string kludge. */
2757 parser
->lex_untranslated_string
= true;
2758 c_parser_consume_token (parser
);
2759 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2761 parser
->lex_untranslated_string
= false;
2764 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2766 parser
->lex_untranslated_string
= false;
2767 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2770 /* Parse the attribute list. */
2771 while (c_parser_next_token_is (parser
, CPP_COMMA
)
2772 || c_parser_next_token_is (parser
, CPP_NAME
)
2773 || c_parser_next_token_is (parser
, CPP_KEYWORD
))
2775 tree attr
, attr_name
, attr_args
;
2776 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2778 c_parser_consume_token (parser
);
2781 if (c_parser_next_token_is (parser
, CPP_KEYWORD
))
2783 /* ??? See comment above about what keywords are
2786 switch (c_parser_peek_token (parser
)->keyword
)
2824 attr_name
= c_parser_peek_token (parser
)->value
;
2825 c_parser_consume_token (parser
);
2826 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
2828 attr
= build_tree_list (attr_name
, NULL_TREE
);
2829 attrs
= chainon (attrs
, attr
);
2832 c_parser_consume_token (parser
);
2833 /* Parse the attribute contents. If they start with an
2834 identifier which is followed by a comma or close
2835 parenthesis, then the arguments start with that
2836 identifier; otherwise they are an expression list. */
2837 if (c_parser_next_token_is (parser
, CPP_NAME
)
2838 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
2839 && ((c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
)
2840 || (c_parser_peek_2nd_token (parser
)->type
2841 == CPP_CLOSE_PAREN
)))
2843 tree arg1
= c_parser_peek_token (parser
)->value
;
2844 c_parser_consume_token (parser
);
2845 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2846 attr_args
= build_tree_list (NULL_TREE
, arg1
);
2849 c_parser_consume_token (parser
);
2850 attr_args
= tree_cons (NULL_TREE
, arg1
,
2851 c_parser_expr_list (parser
, false));
2856 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2857 attr_args
= NULL_TREE
;
2859 attr_args
= c_parser_expr_list (parser
, false);
2861 attr
= build_tree_list (attr_name
, attr_args
);
2862 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2863 c_parser_consume_token (parser
);
2866 parser
->lex_untranslated_string
= false;
2867 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2871 attrs
= chainon (attrs
, attr
);
2873 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2874 c_parser_consume_token (parser
);
2877 parser
->lex_untranslated_string
= false;
2878 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2882 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2883 c_parser_consume_token (parser
);
2886 parser
->lex_untranslated_string
= false;
2887 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2891 parser
->lex_untranslated_string
= false;
2896 /* Parse a type name (C90 6.5.5, C99 6.7.6).
2899 specifier-qualifier-list abstract-declarator[opt]
2902 static struct c_type_name
*
2903 c_parser_type_name (c_parser
*parser
)
2905 struct c_declspecs
*specs
= build_null_declspecs ();
2906 struct c_declarator
*declarator
;
2907 struct c_type_name
*ret
;
2909 c_parser_declspecs (parser
, specs
, false, true, true);
2910 if (!specs
->declspecs_seen_p
)
2912 c_parser_error (parser
, "expected specifier-qualifier-list");
2915 pending_xref_error ();
2916 finish_declspecs (specs
);
2917 declarator
= c_parser_declarator (parser
, specs
->type_seen_p
,
2918 C_DTR_ABSTRACT
, &dummy
);
2919 if (declarator
== NULL
)
2921 ret
= XOBNEW (&parser_obstack
, struct c_type_name
);
2923 ret
->declarator
= declarator
;
2927 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
2930 assignment-expression
2931 { initializer-list }
2932 { initializer-list , }
2935 designation[opt] initializer
2936 initializer-list , designation[opt] initializer
2943 designator-list designator
2950 [ constant-expression ]
2962 [ constant-expression ... constant-expression ]
2964 Any expression without commas is accepted in the syntax for the
2965 constant-expressions, with non-constant expressions rejected later.
2967 This function is only used for top-level initializers; for nested
2968 ones, see c_parser_initval. */
2970 static struct c_expr
2971 c_parser_initializer (c_parser
*parser
)
2973 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2974 return c_parser_braced_init (parser
, NULL_TREE
, false);
2978 ret
= c_parser_expr_no_commas (parser
, NULL
);
2979 if (TREE_CODE (ret
.value
) != STRING_CST
2980 && TREE_CODE (ret
.value
) != COMPOUND_LITERAL_EXPR
)
2981 ret
= default_function_array_conversion (ret
);
2986 /* Parse a braced initializer list. TYPE is the type specified for a
2987 compound literal, and NULL_TREE for other initializers and for
2988 nested braced lists. NESTED_P is true for nested braced lists,
2989 false for the list of a compound literal or the list that is the
2990 top-level initializer in a declaration. */
2992 static struct c_expr
2993 c_parser_braced_init (c_parser
*parser
, tree type
, bool nested_p
)
2995 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
2996 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
2997 c_parser_consume_token (parser
);
2999 push_init_level (0);
3001 really_start_incremental_init (type
);
3002 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3005 pedwarn ("%HISO C forbids empty initializer braces", &brace_loc
);
3009 /* Parse a non-empty initializer list, possibly with a trailing
3013 c_parser_initelt (parser
);
3016 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3017 c_parser_consume_token (parser
);
3020 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3024 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
3027 ret
.value
= error_mark_node
;
3028 ret
.original_code
= ERROR_MARK
;
3029 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
3032 c_parser_consume_token (parser
);
3033 return pop_init_level (0);
3036 /* Parse a nested initializer, including designators. */
3039 c_parser_initelt (c_parser
*parser
)
3041 /* Parse any designator or designator list. A single array
3042 designator may have the subsequent "=" omitted in GNU C, but a
3043 longer list or a structure member designator may not. */
3044 if (c_parser_next_token_is (parser
, CPP_NAME
)
3045 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
3047 /* Old-style structure member designator. */
3048 set_init_label (c_parser_peek_token (parser
)->value
);
3051 /* Use the colon as the error location. */
3052 pedwarn ("%Hobsolete use of designated initializer with %<:%>",
3053 &c_parser_peek_2nd_token (parser
)->location
);
3055 c_parser_consume_token (parser
);
3056 c_parser_consume_token (parser
);
3060 /* des_seen is 0 if there have been no designators, 1 if there
3061 has been a single array designator and 2 otherwise. */
3063 /* Location of a designator. */
3065 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
)
3066 || c_parser_next_token_is (parser
, CPP_DOT
))
3068 int des_prev
= des_seen
;
3070 des_loc
= c_parser_peek_token (parser
)->location
;
3073 if (c_parser_next_token_is (parser
, CPP_DOT
))
3076 c_parser_consume_token (parser
);
3077 if (c_parser_next_token_is (parser
, CPP_NAME
))
3079 set_init_label (c_parser_peek_token (parser
)->value
);
3080 c_parser_consume_token (parser
);
3085 init
.value
= error_mark_node
;
3086 init
.original_code
= ERROR_MARK
;
3087 c_parser_error (parser
, "expected identifier");
3088 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3089 process_init_element (init
);
3096 location_t ellipsis_loc
;
3097 /* ??? Following the old parser, [ objc-receiver
3098 objc-message-args ] is accepted as an initializer,
3099 being distinguished from a designator by what follows
3100 the first assignment expression inside the square
3101 brackets, but after a first array designator a
3102 subsequent square bracket is for Objective-C taken to
3103 start an expression, using the obsolete form of
3104 designated initializer without '=', rather than
3105 possibly being a second level of designation: in LALR
3106 terms, the '[' is shifted rather than reducing
3107 designator to designator-list. */
3108 if (des_prev
== 1 && c_dialect_objc ())
3110 des_seen
= des_prev
;
3113 if (des_prev
== 0 && c_dialect_objc ())
3115 /* This might be an array designator or an
3116 Objective-C message expression. If the former,
3117 continue parsing here; if the latter, parse the
3118 remainder of the initializer given the starting
3119 primary-expression. ??? It might make sense to
3120 distinguish when des_prev == 1 as well; see
3121 previous comment. */
3123 struct c_expr mexpr
;
3124 c_parser_consume_token (parser
);
3125 if (c_parser_peek_token (parser
)->type
== CPP_NAME
3126 && ((c_parser_peek_token (parser
)->id_kind
3128 || (c_parser_peek_token (parser
)->id_kind
3129 == C_ID_CLASSNAME
)))
3131 /* Type name receiver. */
3132 tree id
= c_parser_peek_token (parser
)->value
;
3133 c_parser_consume_token (parser
);
3134 rec
= objc_get_class_reference (id
);
3135 goto parse_message_args
;
3137 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
3138 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
)
3139 || c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3140 goto array_desig_after_first
;
3141 /* Expression receiver. So far only one part
3142 without commas has been parsed; there might be
3143 more of the expression. */
3145 while (c_parser_next_token_is (parser
, CPP_COMMA
))
3148 c_parser_consume_token (parser
);
3149 next
= c_parser_expr_no_commas (parser
, NULL
);
3150 next
= default_function_array_conversion (next
);
3151 rec
= build_compound_expr (rec
, next
.value
);
3154 /* Now parse the objc-message-args. */
3155 args
= c_parser_objc_message_args (parser
);
3156 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3159 = objc_build_message_expr (build_tree_list (rec
, args
));
3160 mexpr
.original_code
= ERROR_MARK
;
3161 /* Now parse and process the remainder of the
3162 initializer, starting with this message
3163 expression as a primary-expression. */
3164 c_parser_initval (parser
, &mexpr
);
3167 c_parser_consume_token (parser
);
3168 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
3169 array_desig_after_first
:
3170 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3172 ellipsis_loc
= c_parser_peek_token (parser
)->location
;
3173 c_parser_consume_token (parser
);
3174 second
= c_parser_expr_no_commas (parser
, NULL
).value
;
3178 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3180 c_parser_consume_token (parser
);
3181 set_init_index (first
, second
);
3182 if (pedantic
&& second
)
3183 pedwarn ("%HISO C forbids specifying range of "
3184 "elements to initialize", &ellipsis_loc
);
3187 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3193 if (c_parser_next_token_is (parser
, CPP_EQ
))
3195 if (pedantic
&& !flag_isoc99
)
3196 pedwarn ("%HISO C90 forbids specifying subobject "
3197 "to initialize", &des_loc
);
3198 c_parser_consume_token (parser
);
3205 pedwarn ("%Hobsolete use of designated initializer "
3207 &c_parser_peek_token (parser
)->location
);
3212 init
.value
= error_mark_node
;
3213 init
.original_code
= ERROR_MARK
;
3214 c_parser_error (parser
, "expected %<=%>");
3215 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3216 process_init_element (init
);
3222 c_parser_initval (parser
, NULL
);
3225 /* Parse a nested initializer; as c_parser_initializer but parses
3226 initializers within braced lists, after any designators have been
3227 applied. If AFTER is not NULL then it is an Objective-C message
3228 expression which is the primary-expression starting the
3232 c_parser_initval (c_parser
*parser
, struct c_expr
*after
)
3235 gcc_assert (!after
|| c_dialect_objc ());
3236 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
) && !after
)
3237 init
= c_parser_braced_init (parser
, NULL_TREE
, true);
3240 init
= c_parser_expr_no_commas (parser
, after
);
3241 if (init
.value
!= NULL_TREE
3242 && TREE_CODE (init
.value
) != STRING_CST
3243 && TREE_CODE (init
.value
) != COMPOUND_LITERAL_EXPR
)
3244 init
= default_function_array_conversion (init
);
3246 process_init_element (init
);
3249 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
3253 { block-item-list[opt] }
3254 { label-declarations block-item-list }
3258 block-item-list block-item
3270 { label-declarations block-item-list }
3273 __extension__ nested-declaration
3274 nested-function-definition
3278 label-declarations label-declaration
3281 __label__ identifier-list ;
3283 Allowing the mixing of declarations and code is new in C99. The
3284 GNU syntax also permits (not shown above) labels at the end of
3285 compound statements, which yield an error. We don't allow labels
3286 on declarations; this might seem like a natural extension, but
3287 there would be a conflict between attributes on the label and
3288 prefix attributes on the declaration. ??? The syntax follows the
3289 old parser in requiring something after label declarations.
3290 Although they are erroneous if the labels declared aren't defined,
3291 is it useful for the syntax to be this way?
3303 c_parser_compound_statement (c_parser
*parser
)
3306 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
3307 return error_mark_node
;
3308 stmt
= c_begin_compound_stmt (true);
3309 c_parser_compound_statement_nostart (parser
);
3310 return c_end_compound_stmt (stmt
, true);
3313 /* Parse a compound statement except for the opening brace. This is
3314 used for parsing both compound statements and statement expressions
3315 (which follow different paths to handling the opening). */
3318 c_parser_compound_statement_nostart (c_parser
*parser
)
3320 bool last_stmt
= false;
3321 bool last_label
= false;
3322 location_t label_loc
;
3323 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3325 c_parser_consume_token (parser
);
3328 if (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
3330 location_t err_loc
= c_parser_peek_token (parser
)->location
;
3331 /* Read zero or more forward-declarations for labels that nested
3332 functions can jump to. */
3333 while (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
3335 c_parser_consume_token (parser
);
3336 /* Any identifiers, including those declared as type names,
3341 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
3343 c_parser_error (parser
, "expected identifier");
3347 = declare_label (c_parser_peek_token (parser
)->value
);
3348 C_DECLARED_LABEL_FLAG (label
) = 1;
3349 add_stmt (build_stmt (DECL_EXPR
, label
));
3350 c_parser_consume_token (parser
);
3351 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3352 c_parser_consume_token (parser
);
3356 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
3359 pedwarn ("%HISO C forbids label declarations", &err_loc
);
3361 /* We must now have at least one statement, label or declaration. */
3362 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3364 c_parser_error (parser
, "expected declaration or statement");
3365 c_parser_consume_token (parser
);
3368 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
3370 location_t loc
= c_parser_peek_token (parser
)->location
;
3371 if (c_parser_next_token_is_keyword (parser
, RID_CASE
)
3372 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
3373 || (c_parser_next_token_is (parser
, CPP_NAME
)
3374 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
3376 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
3377 label_loc
= c_parser_peek_2nd_token (parser
)->location
;
3379 label_loc
= c_parser_peek_token (parser
)->location
;
3382 c_parser_label (parser
);
3384 else if (!last_label
3385 && c_parser_next_token_starts_declspecs (parser
))
3388 c_parser_declaration_or_fndef (parser
, true, true, true, true);
3390 && ((pedantic
&& !flag_isoc99
)
3391 || warn_declaration_after_statement
))
3392 pedwarn_c90 ("%HISO C90 forbids mixed declarations and code",
3396 else if (!last_label
3397 && c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
3399 /* __extension__ can start a declaration, but is also an
3400 unary operator that can start an expression. Consume all
3401 but the last of a possible series of __extension__ to
3403 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
3404 && (c_parser_peek_2nd_token (parser
)->keyword
3406 c_parser_consume_token (parser
);
3407 if (c_token_starts_declspecs (c_parser_peek_2nd_token (parser
)))
3410 ext
= disable_extension_diagnostics ();
3411 c_parser_consume_token (parser
);
3413 c_parser_declaration_or_fndef (parser
, true, true, true, true);
3414 /* Following the old parser, __extension__ does not
3415 disable this diagnostic. */
3416 restore_extension_diagnostics (ext
);
3418 && ((pedantic
&& !flag_isoc99
)
3419 || warn_declaration_after_statement
))
3420 pedwarn_c90 ("%HISO C90 forbids mixed declarations and code",
3427 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
3429 /* External pragmas, and some omp pragmas, are not associated
3430 with regular c code, and so are not to be considered statements
3431 syntactically. This ensures that the user doesn't put them
3432 places that would turn into syntax errors if the directive
3434 if (c_parser_pragma (parser
, pragma_compound
))
3435 last_label
= false, last_stmt
= true;
3437 else if (c_parser_next_token_is (parser
, CPP_EOF
))
3439 c_parser_error (parser
, "expected declaration or statement");
3442 else if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
3444 if (parser
->in_if_block
)
3446 error ("%H""expected %<}%> before %<else%>", &loc
);
3451 error ("%H%<else%> without a previous %<if%>", &loc
);
3452 c_parser_consume_token (parser
);
3461 c_parser_statement_after_labels (parser
);
3464 parser
->error
= false;
3467 error ("%Hlabel at end of compound statement", &label_loc
);
3468 c_parser_consume_token (parser
);
3471 /* Parse a label (C90 6.6.1, C99 6.8.1).
3474 identifier : attributes[opt]
3475 case constant-expression :
3481 case constant-expression ... constant-expression :
3483 The use of attributes on labels is a GNU extension. The syntax in
3484 GNU C accepts any expressions without commas, non-constant
3485 expressions being rejected later. */
3488 c_parser_label (c_parser
*parser
)
3490 location_t loc1
= c_parser_peek_token (parser
)->location
;
3491 tree label
= NULL_TREE
;
3492 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
3495 c_parser_consume_token (parser
);
3496 exp1
= c_parser_expr_no_commas (parser
, NULL
).value
;
3497 if (c_parser_next_token_is (parser
, CPP_COLON
))
3499 c_parser_consume_token (parser
);
3500 label
= do_case (exp1
, NULL_TREE
);
3502 else if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3504 c_parser_consume_token (parser
);
3505 exp2
= c_parser_expr_no_commas (parser
, NULL
).value
;
3506 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
3507 label
= do_case (exp1
, exp2
);
3510 c_parser_error (parser
, "expected %<:%> or %<...%>");
3512 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
3514 c_parser_consume_token (parser
);
3515 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
3516 label
= do_case (NULL_TREE
, NULL_TREE
);
3520 tree name
= c_parser_peek_token (parser
)->value
;
3523 location_t loc2
= c_parser_peek_token (parser
)->location
;
3524 gcc_assert (c_parser_next_token_is (parser
, CPP_NAME
));
3525 c_parser_consume_token (parser
);
3526 gcc_assert (c_parser_next_token_is (parser
, CPP_COLON
));
3527 c_parser_consume_token (parser
);
3528 attrs
= c_parser_attributes (parser
);
3529 tlab
= define_label (loc2
, name
);
3532 decl_attributes (&tlab
, attrs
, 0);
3533 label
= add_stmt (build_stmt (LABEL_EXPR
, tlab
));
3538 SET_EXPR_LOCATION (label
, loc1
);
3539 if (c_parser_next_token_starts_declspecs (parser
)
3540 && !(c_parser_next_token_is (parser
, CPP_NAME
)
3541 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
3543 error ("%Ha label can only be part of a statement and "
3544 "a declaration is not a statement",
3545 &c_parser_peek_token (parser
)->location
);
3546 c_parser_declaration_or_fndef (parser
, /*fndef_ok*/ false,
3547 /*nested*/ true, /*empty_ok*/ false,
3548 /*start_attr_ok*/ true);
3553 /* Parse a statement (C90 6.6, C99 6.8).
3558 expression-statement
3566 expression-statement:
3569 selection-statement:
3573 iteration-statement:
3582 return expression[opt] ;
3595 objc-throw-statement
3596 objc-try-catch-statement
3597 objc-synchronized-statement
3599 objc-throw-statement:
3613 parallel-for-construct
3614 parallel-sections-construct
3621 parallel-directive structured-block
3624 for-directive iteration-statement
3627 sections-directive section-scope
3630 single-directive structured-block
3632 parallel-for-construct:
3633 parallel-for-directive iteration-statement
3635 parallel-sections-construct:
3636 parallel-sections-directive section-scope
3639 master-directive structured-block
3642 critical-directive structured-block
3645 atomic-directive expression-statement
3648 ordered-directive structured-block */
3651 c_parser_statement (c_parser
*parser
)
3653 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
3654 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
3655 || (c_parser_next_token_is (parser
, CPP_NAME
)
3656 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
3657 c_parser_label (parser
);
3658 c_parser_statement_after_labels (parser
);
3661 /* Parse a statement, other than a labeled statement. */
3664 c_parser_statement_after_labels (c_parser
*parser
)
3666 location_t loc
= c_parser_peek_token (parser
)->location
;
3667 tree stmt
= NULL_TREE
;
3668 bool in_if_block
= parser
->in_if_block
;
3669 parser
->in_if_block
= false;
3670 switch (c_parser_peek_token (parser
)->type
)
3672 case CPP_OPEN_BRACE
:
3673 add_stmt (c_parser_compound_statement (parser
));
3676 switch (c_parser_peek_token (parser
)->keyword
)
3679 c_parser_if_statement (parser
);
3682 c_parser_switch_statement (parser
);
3685 c_parser_while_statement (parser
);
3688 c_parser_do_statement (parser
);
3691 c_parser_for_statement (parser
);
3694 c_parser_consume_token (parser
);
3695 if (c_parser_next_token_is (parser
, CPP_NAME
))
3697 stmt
= c_finish_goto_label (c_parser_peek_token (parser
)->value
);
3698 c_parser_consume_token (parser
);
3700 else if (c_parser_next_token_is (parser
, CPP_MULT
))
3702 c_parser_consume_token (parser
);
3703 stmt
= c_finish_goto_ptr (c_parser_expression (parser
).value
);
3706 c_parser_error (parser
, "expected identifier or %<*%>");
3707 goto expect_semicolon
;
3709 c_parser_consume_token (parser
);
3710 stmt
= c_finish_bc_stmt (&c_cont_label
, false);
3711 goto expect_semicolon
;
3713 c_parser_consume_token (parser
);
3714 stmt
= c_finish_bc_stmt (&c_break_label
, true);
3715 goto expect_semicolon
;
3717 c_parser_consume_token (parser
);
3718 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3720 stmt
= c_finish_return (NULL_TREE
);
3721 c_parser_consume_token (parser
);
3725 stmt
= c_finish_return (c_parser_expression_conv (parser
).value
);
3726 goto expect_semicolon
;
3730 stmt
= c_parser_asm_statement (parser
);
3733 gcc_assert (c_dialect_objc ());
3734 c_parser_consume_token (parser
);
3735 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3737 stmt
= objc_build_throw_stmt (NULL_TREE
);
3738 c_parser_consume_token (parser
);
3743 = objc_build_throw_stmt (c_parser_expression (parser
).value
);
3744 goto expect_semicolon
;
3748 gcc_assert (c_dialect_objc ());
3749 c_parser_objc_try_catch_statement (parser
);
3751 case RID_AT_SYNCHRONIZED
:
3752 gcc_assert (c_dialect_objc ());
3753 c_parser_objc_synchronized_statement (parser
);
3760 c_parser_consume_token (parser
);
3762 case CPP_CLOSE_PAREN
:
3763 case CPP_CLOSE_SQUARE
:
3764 /* Avoid infinite loop in error recovery:
3765 c_parser_skip_until_found stops at a closing nesting
3766 delimiter without consuming it, but here we need to consume
3767 it to proceed further. */
3768 c_parser_error (parser
, "expected statement");
3769 c_parser_consume_token (parser
);
3772 c_parser_pragma (parser
, pragma_stmt
);
3776 stmt
= c_finish_expr_stmt (c_parser_expression_conv (parser
).value
);
3778 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
3781 /* Two cases cannot and do not have line numbers associated: If stmt
3782 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
3783 cannot hold line numbers. But that's OK because the statement
3784 will either be changed to a MODIFY_EXPR during gimplification of
3785 the statement expr, or discarded. If stmt was compound, but
3786 without new variables, we will have skipped the creation of a
3787 BIND and will have a bare STATEMENT_LIST. But that's OK because
3788 (recursively) all of the component statements should already have
3789 line numbers assigned. ??? Can we discard no-op statements
3791 if (stmt
&& CAN_HAVE_LOCATION_P (stmt
))
3792 SET_EXPR_LOCATION (stmt
, loc
);
3794 parser
->in_if_block
= in_if_block
;
3797 /* Parse a parenthesized condition from an if, do or while statement.
3803 c_parser_paren_condition (c_parser
*parser
)
3807 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3808 return error_mark_node
;
3809 loc
= c_parser_peek_token (parser
)->location
;
3810 cond
= c_objc_common_truthvalue_conversion
3811 (c_parser_expression_conv (parser
).value
);
3812 if (CAN_HAVE_LOCATION_P (cond
))
3813 SET_EXPR_LOCATION (cond
, loc
);
3814 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
3818 /* Parse a statement which is a block in C99. */
3821 c_parser_c99_block_statement (c_parser
*parser
)
3823 tree block
= c_begin_compound_stmt (flag_isoc99
);
3824 c_parser_statement (parser
);
3825 return c_end_compound_stmt (block
, flag_isoc99
);
3828 /* Parse the body of an if statement. This is just parsing a
3829 statement but (a) it is a block in C99, (b) we track whether the
3830 body is an if statement for the sake of -Wparentheses warnings, (c)
3831 we handle an empty body specially for the sake of -Wempty-body
3832 warnings, and (d) we call parser_compound_statement directly
3833 because c_parser_statement_after_labels resets
3834 parser->in_if_block. */
3837 c_parser_if_body (c_parser
*parser
, bool *if_p
)
3839 tree block
= c_begin_compound_stmt (flag_isoc99
);
3840 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
3841 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
3842 || (c_parser_next_token_is (parser
, CPP_NAME
)
3843 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
3844 c_parser_label (parser
);
3845 *if_p
= c_parser_next_token_is_keyword (parser
, RID_IF
);
3846 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3848 add_stmt (build_empty_stmt ());
3849 c_parser_consume_token (parser
);
3851 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
3852 add_stmt (c_parser_compound_statement (parser
));
3854 c_parser_statement_after_labels (parser
);
3855 return c_end_compound_stmt (block
, flag_isoc99
);
3858 /* Parse the else body of an if statement. This is just parsing a
3859 statement but (a) it is a block in C99, (b) we handle an empty body
3860 specially for the sake of -Wempty-body warnings. */
3863 c_parser_else_body (c_parser
*parser
)
3865 tree block
= c_begin_compound_stmt (flag_isoc99
);
3866 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
3867 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
3868 || (c_parser_next_token_is (parser
, CPP_NAME
)
3869 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
3870 c_parser_label (parser
);
3871 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3873 add_stmt (build_empty_stmt ());
3874 c_parser_consume_token (parser
);
3877 c_parser_statement_after_labels (parser
);
3878 return c_end_compound_stmt (block
, flag_isoc99
);
3881 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
3884 if ( expression ) statement
3885 if ( expression ) statement else statement
3889 c_parser_if_statement (c_parser
*parser
)
3894 bool first_if
= false;
3895 tree first_body
, second_body
;
3898 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_IF
));
3899 c_parser_consume_token (parser
);
3900 block
= c_begin_compound_stmt (flag_isoc99
);
3901 loc
= c_parser_peek_token (parser
)->location
;
3902 cond
= c_parser_paren_condition (parser
);
3903 in_if_block
= parser
->in_if_block
;
3904 parser
->in_if_block
= true;
3905 first_body
= c_parser_if_body (parser
, &first_if
);
3906 parser
->in_if_block
= in_if_block
;
3907 if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
3909 c_parser_consume_token (parser
);
3910 second_body
= c_parser_else_body (parser
);
3913 second_body
= NULL_TREE
;
3914 c_finish_if_stmt (loc
, cond
, first_body
, second_body
, first_if
);
3915 add_stmt (c_end_compound_stmt (block
, flag_isoc99
));
3918 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
3921 switch (expression) statement
3925 c_parser_switch_statement (c_parser
*parser
)
3927 tree block
, expr
, body
, save_break
;
3928 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SWITCH
));
3929 c_parser_consume_token (parser
);
3930 block
= c_begin_compound_stmt (flag_isoc99
);
3931 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3933 expr
= c_parser_expression (parser
).value
;
3934 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
3937 expr
= error_mark_node
;
3938 c_start_case (expr
);
3939 save_break
= c_break_label
;
3940 c_break_label
= NULL_TREE
;
3941 body
= c_parser_c99_block_statement (parser
);
3942 c_finish_case (body
);
3944 add_stmt (build1 (LABEL_EXPR
, void_type_node
, c_break_label
));
3945 c_break_label
= save_break
;
3946 add_stmt (c_end_compound_stmt (block
, flag_isoc99
));
3949 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
3952 while (expression) statement
3956 c_parser_while_statement (c_parser
*parser
)
3958 tree block
, cond
, body
, save_break
, save_cont
;
3960 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_WHILE
));
3961 c_parser_consume_token (parser
);
3962 block
= c_begin_compound_stmt (flag_isoc99
);
3963 loc
= c_parser_peek_token (parser
)->location
;
3964 cond
= c_parser_paren_condition (parser
);
3965 save_break
= c_break_label
;
3966 c_break_label
= NULL_TREE
;
3967 save_cont
= c_cont_label
;
3968 c_cont_label
= NULL_TREE
;
3969 body
= c_parser_c99_block_statement (parser
);
3970 c_finish_loop (loc
, cond
, NULL
, body
, c_break_label
, c_cont_label
, true);
3971 add_stmt (c_end_compound_stmt (block
, flag_isoc99
));
3972 c_break_label
= save_break
;
3973 c_cont_label
= save_cont
;
3976 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
3979 do statement while ( expression ) ;
3983 c_parser_do_statement (c_parser
*parser
)
3985 tree block
, cond
, body
, save_break
, save_cont
, new_break
, new_cont
;
3987 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_DO
));
3988 c_parser_consume_token (parser
);
3989 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3990 warning (OPT_Wempty_body
,
3991 "%Hsuggest braces around empty body in %<do%> statement",
3992 &c_parser_peek_token (parser
)->location
);
3993 block
= c_begin_compound_stmt (flag_isoc99
);
3994 loc
= c_parser_peek_token (parser
)->location
;
3995 save_break
= c_break_label
;
3996 c_break_label
= NULL_TREE
;
3997 save_cont
= c_cont_label
;
3998 c_cont_label
= NULL_TREE
;
3999 body
= c_parser_c99_block_statement (parser
);
4000 c_parser_require_keyword (parser
, RID_WHILE
, "expected %<while%>");
4001 new_break
= c_break_label
;
4002 c_break_label
= save_break
;
4003 new_cont
= c_cont_label
;
4004 c_cont_label
= save_cont
;
4005 cond
= c_parser_paren_condition (parser
);
4006 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
4007 c_parser_skip_to_end_of_block_or_statement (parser
);
4008 c_finish_loop (loc
, cond
, NULL
, body
, new_break
, new_cont
, false);
4009 add_stmt (c_end_compound_stmt (block
, flag_isoc99
));
4012 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
4015 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
4016 for ( nested-declaration expression[opt] ; expression[opt] ) statement
4018 The form with a declaration is new in C99.
4020 ??? In accordance with the old parser, the declaration may be a
4021 nested function, which is then rejected in check_for_loop_decls,
4022 but does it make any sense for this to be included in the grammar?
4023 Note in particular that the nested function does not include a
4024 trailing ';', whereas the "declaration" production includes one.
4025 Also, can we reject bad declarations earlier and cheaper than
4026 check_for_loop_decls? */
4029 c_parser_for_statement (c_parser
*parser
)
4031 tree block
, cond
, incr
, save_break
, save_cont
, body
;
4033 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_FOR
));
4034 loc
= c_parser_peek_token (parser
)->location
;
4035 c_parser_consume_token (parser
);
4036 block
= c_begin_compound_stmt (flag_isoc99
);
4037 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4039 /* Parse the initialization declaration or expression. */
4040 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4042 c_parser_consume_token (parser
);
4043 c_finish_expr_stmt (NULL_TREE
);
4045 else if (c_parser_next_token_starts_declspecs (parser
))
4047 c_parser_declaration_or_fndef (parser
, true, true, true, true);
4048 check_for_loop_decls ();
4050 else if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
4052 /* __extension__ can start a declaration, but is also an
4053 unary operator that can start an expression. Consume all
4054 but the last of a possible series of __extension__ to
4056 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
4057 && (c_parser_peek_2nd_token (parser
)->keyword
4059 c_parser_consume_token (parser
);
4060 if (c_token_starts_declspecs (c_parser_peek_2nd_token (parser
)))
4063 ext
= disable_extension_diagnostics ();
4064 c_parser_consume_token (parser
);
4065 c_parser_declaration_or_fndef (parser
, true, true, true, true);
4066 restore_extension_diagnostics (ext
);
4067 check_for_loop_decls ();
4075 c_finish_expr_stmt (c_parser_expression (parser
).value
);
4076 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4078 /* Parse the loop condition. */
4079 loc
= c_parser_peek_token (parser
)->location
;
4080 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4082 c_parser_consume_token (parser
);
4087 tree ocond
= c_parser_expression_conv (parser
).value
;
4088 cond
= c_objc_common_truthvalue_conversion (ocond
);
4089 if (CAN_HAVE_LOCATION_P (cond
))
4090 SET_EXPR_LOCATION (cond
, loc
);
4091 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4093 /* Parse the increment expression. */
4094 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4095 incr
= c_process_expr_stmt (NULL_TREE
);
4097 incr
= c_process_expr_stmt (c_parser_expression (parser
).value
);
4098 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4102 cond
= error_mark_node
;
4103 incr
= error_mark_node
;
4105 save_break
= c_break_label
;
4106 c_break_label
= NULL_TREE
;
4107 save_cont
= c_cont_label
;
4108 c_cont_label
= NULL_TREE
;
4109 body
= c_parser_c99_block_statement (parser
);
4110 c_finish_loop (loc
, cond
, incr
, body
, c_break_label
, c_cont_label
, true);
4111 add_stmt (c_end_compound_stmt (block
, flag_isoc99
));
4112 c_break_label
= save_break
;
4113 c_cont_label
= save_cont
;
4116 /* Parse an asm statement, a GNU extension. This is a full-blown asm
4117 statement with inputs, outputs, clobbers, and volatile tag
4121 asm type-qualifier[opt] ( asm-argument ) ;
4125 asm-string-literal : asm-operands[opt]
4126 asm-string-literal : asm-operands[opt] : asm-operands[opt]
4127 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers
4129 Qualifiers other than volatile are accepted in the syntax but
4133 c_parser_asm_statement (c_parser
*parser
)
4135 tree quals
, str
, outputs
, inputs
, clobbers
, ret
;
4137 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
4138 c_parser_consume_token (parser
);
4139 if (c_parser_next_token_is_keyword (parser
, RID_VOLATILE
))
4141 quals
= c_parser_peek_token (parser
)->value
;
4142 c_parser_consume_token (parser
);
4144 else if (c_parser_next_token_is_keyword (parser
, RID_CONST
)
4145 || c_parser_next_token_is_keyword (parser
, RID_RESTRICT
))
4147 warning (0, "%H%E qualifier ignored on asm",
4148 &c_parser_peek_token (parser
)->location
,
4149 c_parser_peek_token (parser
)->value
);
4151 c_parser_consume_token (parser
);
4155 /* ??? Follow the C++ parser rather than using the
4156 lex_untranslated_string kludge. */
4157 parser
->lex_untranslated_string
= true;
4158 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4160 parser
->lex_untranslated_string
= false;
4163 str
= c_parser_asm_string_literal (parser
);
4164 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4167 outputs
= NULL_TREE
;
4169 clobbers
= NULL_TREE
;
4172 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%> or %<)%>"))
4174 parser
->lex_untranslated_string
= false;
4175 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4179 /* Parse outputs. */
4180 if (c_parser_next_token_is (parser
, CPP_COLON
)
4181 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4182 outputs
= NULL_TREE
;
4184 outputs
= c_parser_asm_operands (parser
, false);
4185 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4188 clobbers
= NULL_TREE
;
4191 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%> or %<)%>"))
4193 parser
->lex_untranslated_string
= false;
4194 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4198 if (c_parser_next_token_is (parser
, CPP_COLON
)
4199 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4202 inputs
= c_parser_asm_operands (parser
, true);
4203 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4205 clobbers
= NULL_TREE
;
4208 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%> or %<)%>"))
4210 parser
->lex_untranslated_string
= false;
4211 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4214 /* Parse clobbers. */
4215 clobbers
= c_parser_asm_clobbers (parser
);
4217 parser
->lex_untranslated_string
= false;
4218 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
4220 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4223 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
4224 c_parser_skip_to_end_of_block_or_statement (parser
);
4225 ret
= build_asm_stmt (quals
, build_asm_expr (str
, outputs
, inputs
,
4230 /* Parse asm operands, a GNU extension. If CONVERT_P (for inputs but
4231 not outputs), apply the default conversion of functions and arrays
4236 asm-operands , asm-operand
4239 asm-string-literal ( expression )
4240 [ identifier ] asm-string-literal ( expression )
4244 c_parser_asm_operands (c_parser
*parser
, bool convert_p
)
4246 tree list
= NULL_TREE
;
4251 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
4253 c_parser_consume_token (parser
);
4254 if (c_parser_next_token_is (parser
, CPP_NAME
))
4256 tree id
= c_parser_peek_token (parser
)->value
;
4257 c_parser_consume_token (parser
);
4258 name
= build_string (IDENTIFIER_LENGTH (id
),
4259 IDENTIFIER_POINTER (id
));
4263 c_parser_error (parser
, "expected identifier");
4264 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
4267 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4272 str
= c_parser_asm_string_literal (parser
);
4273 if (str
== NULL_TREE
)
4275 parser
->lex_untranslated_string
= false;
4276 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4278 parser
->lex_untranslated_string
= true;
4281 expr
= c_parser_expression (parser
);
4283 expr
= default_function_array_conversion (expr
);
4284 parser
->lex_untranslated_string
= true;
4285 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
4287 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4290 list
= chainon (list
, build_tree_list (build_tree_list (name
, str
),
4292 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4293 c_parser_consume_token (parser
);
4300 /* Parse asm clobbers, a GNU extension.
4304 asm-clobbers , asm-string-literal
4308 c_parser_asm_clobbers (c_parser
*parser
)
4310 tree list
= NULL_TREE
;
4313 tree str
= c_parser_asm_string_literal (parser
);
4315 list
= tree_cons (NULL_TREE
, str
, list
);
4318 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4319 c_parser_consume_token (parser
);
4326 /* Parse an expression other than a compound expression; that is, an
4327 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
4328 NULL then it is an Objective-C message expression which is the
4329 primary-expression starting the expression as an initializer.
4331 assignment-expression:
4332 conditional-expression
4333 unary-expression assignment-operator assignment-expression
4335 assignment-operator: one of
4336 = *= /= %= += -= <<= >>= &= ^= |=
4338 In GNU C we accept any conditional expression on the LHS and
4339 diagnose the invalid lvalue rather than producing a syntax
4342 static struct c_expr
4343 c_parser_expr_no_commas (c_parser
*parser
, struct c_expr
*after
)
4345 struct c_expr lhs
, rhs
, ret
;
4346 enum tree_code code
;
4347 gcc_assert (!after
|| c_dialect_objc ());
4348 lhs
= c_parser_conditional_expression (parser
, after
);
4349 switch (c_parser_peek_token (parser
)->type
)
4358 code
= TRUNC_DIV_EXPR
;
4361 code
= TRUNC_MOD_EXPR
;
4376 code
= BIT_AND_EXPR
;
4379 code
= BIT_XOR_EXPR
;
4382 code
= BIT_IOR_EXPR
;
4387 c_parser_consume_token (parser
);
4388 rhs
= c_parser_expr_no_commas (parser
, NULL
);
4389 rhs
= default_function_array_conversion (rhs
);
4390 ret
.value
= build_modify_expr (lhs
.value
, code
, rhs
.value
);
4391 if (code
== NOP_EXPR
)
4392 ret
.original_code
= MODIFY_EXPR
;
4395 TREE_NO_WARNING (ret
.value
) = 1;
4396 ret
.original_code
= ERROR_MARK
;
4401 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
4402 is not NULL then it is an Objective-C message expression which is
4403 the primary-expression starting the expression as an initializer.
4405 conditional-expression:
4406 logical-OR-expression
4407 logical-OR-expression ? expression : conditional-expression
4411 conditional-expression:
4412 logical-OR-expression ? : conditional-expression
4415 static struct c_expr
4416 c_parser_conditional_expression (c_parser
*parser
, struct c_expr
*after
)
4418 struct c_expr cond
, exp1
, exp2
, ret
;
4419 gcc_assert (!after
|| c_dialect_objc ());
4420 cond
= c_parser_binary_expression (parser
, after
);
4421 if (c_parser_next_token_is_not (parser
, CPP_QUERY
))
4423 cond
= default_function_array_conversion (cond
);
4424 c_parser_consume_token (parser
);
4425 if (c_parser_next_token_is (parser
, CPP_COLON
))
4428 pedwarn ("%HISO C forbids omitting the middle term of a ?: expression",
4429 &c_parser_peek_token (parser
)->location
);
4430 /* Make sure first operand is calculated only once. */
4431 exp1
.value
= save_expr (default_conversion (cond
.value
));
4432 cond
.value
= c_objc_common_truthvalue_conversion (exp1
.value
);
4433 skip_evaluation
+= cond
.value
== truthvalue_true_node
;
4438 = c_objc_common_truthvalue_conversion
4439 (default_conversion (cond
.value
));
4440 skip_evaluation
+= cond
.value
== truthvalue_false_node
;
4441 exp1
= c_parser_expression_conv (parser
);
4442 skip_evaluation
+= ((cond
.value
== truthvalue_true_node
)
4443 - (cond
.value
== truthvalue_false_node
));
4445 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4447 skip_evaluation
-= cond
.value
== truthvalue_true_node
;
4448 ret
.value
= error_mark_node
;
4449 ret
.original_code
= ERROR_MARK
;
4452 exp2
= c_parser_conditional_expression (parser
, NULL
);
4453 exp2
= default_function_array_conversion (exp2
);
4454 skip_evaluation
-= cond
.value
== truthvalue_true_node
;
4455 ret
.value
= build_conditional_expr (cond
.value
, exp1
.value
, exp2
.value
);
4456 ret
.original_code
= ERROR_MARK
;
4460 /* Parse a binary expression; that is, a logical-OR-expression (C90
4461 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
4462 an Objective-C message expression which is the primary-expression
4463 starting the expression as an initializer.
4465 multiplicative-expression:
4467 multiplicative-expression * cast-expression
4468 multiplicative-expression / cast-expression
4469 multiplicative-expression % cast-expression
4471 additive-expression:
4472 multiplicative-expression
4473 additive-expression + multiplicative-expression
4474 additive-expression - multiplicative-expression
4478 shift-expression << additive-expression
4479 shift-expression >> additive-expression
4481 relational-expression:
4483 relational-expression < shift-expression
4484 relational-expression > shift-expression
4485 relational-expression <= shift-expression
4486 relational-expression >= shift-expression
4488 equality-expression:
4489 relational-expression
4490 equality-expression == relational-expression
4491 equality-expression != relational-expression
4495 AND-expression & equality-expression
4497 exclusive-OR-expression:
4499 exclusive-OR-expression ^ AND-expression
4501 inclusive-OR-expression:
4502 exclusive-OR-expression
4503 inclusive-OR-expression | exclusive-OR-expression
4505 logical-AND-expression:
4506 inclusive-OR-expression
4507 logical-AND-expression && inclusive-OR-expression
4509 logical-OR-expression:
4510 logical-AND-expression
4511 logical-OR-expression || logical-AND-expression
4514 static struct c_expr
4515 c_parser_binary_expression (c_parser
*parser
, struct c_expr
*after
)
4517 /* A binary expression is parsed using operator-precedence parsing,
4518 with the operands being cast expressions. All the binary
4519 operators are left-associative. Thus a binary expression is of
4522 E0 op1 E1 op2 E2 ...
4524 which we represent on a stack. On the stack, the precedence
4525 levels are strictly increasing. When a new operator is
4526 encountered of higher precedence than that at the top of the
4527 stack, it is pushed; its LHS is the top expression, and its RHS
4528 is everything parsed until it is popped. When a new operator is
4529 encountered with precedence less than or equal to that at the top
4530 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
4531 by the result of the operation until the operator at the top of
4532 the stack has lower precedence than the new operator or there is
4533 only one element on the stack; then the top expression is the LHS
4534 of the new operator. In the case of logical AND and OR
4535 expressions, we also need to adjust skip_evaluation as
4536 appropriate when the operators are pushed and popped. */
4538 /* The precedence levels, where 0 is a dummy lowest level used for
4539 the bottom of the stack. */
4555 /* The expression at this stack level. */
4557 /* The precedence of the operator on its left, PREC_NONE at the
4558 bottom of the stack. */
4560 /* The operation on its left. */
4566 switch (stack[sp].op) \
4568 case TRUTH_ANDIF_EXPR: \
4569 skip_evaluation -= stack[sp - 1].expr.value == truthvalue_false_node; \
4571 case TRUTH_ORIF_EXPR: \
4572 skip_evaluation -= stack[sp - 1].expr.value == truthvalue_true_node; \
4577 stack[sp - 1].expr \
4578 = default_function_array_conversion (stack[sp - 1].expr); \
4580 = default_function_array_conversion (stack[sp].expr); \
4581 stack[sp - 1].expr = parser_build_binary_op (stack[sp].op, \
4582 stack[sp - 1].expr, \
4586 gcc_assert (!after
|| c_dialect_objc ());
4587 stack
[0].expr
= c_parser_cast_expression (parser
, after
);
4588 stack
[0].prec
= PREC_NONE
;
4593 enum tree_code ocode
;
4596 switch (c_parser_peek_token (parser
)->type
)
4604 ocode
= TRUNC_DIV_EXPR
;
4608 ocode
= TRUNC_MOD_EXPR
;
4620 ocode
= LSHIFT_EXPR
;
4624 ocode
= RSHIFT_EXPR
;
4638 case CPP_GREATER_EQ
:
4651 oprec
= PREC_BITAND
;
4652 ocode
= BIT_AND_EXPR
;
4655 oprec
= PREC_BITXOR
;
4656 ocode
= BIT_XOR_EXPR
;
4660 ocode
= BIT_IOR_EXPR
;
4663 oprec
= PREC_LOGAND
;
4664 ocode
= TRUTH_ANDIF_EXPR
;
4668 ocode
= TRUTH_ORIF_EXPR
;
4671 /* Not a binary operator, so end of the binary
4675 c_parser_consume_token (parser
);
4676 while (oprec
<= stack
[sp
].prec
)
4680 case TRUTH_ANDIF_EXPR
:
4682 = default_function_array_conversion (stack
[sp
].expr
);
4683 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
4684 (default_conversion (stack
[sp
].expr
.value
));
4685 skip_evaluation
+= stack
[sp
].expr
.value
== truthvalue_false_node
;
4687 case TRUTH_ORIF_EXPR
:
4689 = default_function_array_conversion (stack
[sp
].expr
);
4690 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
4691 (default_conversion (stack
[sp
].expr
.value
));
4692 skip_evaluation
+= stack
[sp
].expr
.value
== truthvalue_true_node
;
4698 stack
[sp
].expr
= c_parser_cast_expression (parser
, NULL
);
4699 stack
[sp
].prec
= oprec
;
4700 stack
[sp
].op
= ocode
;
4705 return stack
[0].expr
;
4709 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
4710 NULL then it is an Objective-C message expression which is the
4711 primary-expression starting the expression as an initializer.
4715 ( type-name ) unary-expression
4718 static struct c_expr
4719 c_parser_cast_expression (c_parser
*parser
, struct c_expr
*after
)
4721 gcc_assert (!after
|| c_dialect_objc ());
4723 return c_parser_postfix_expression_after_primary (parser
, *after
);
4724 /* If the expression begins with a parenthesized type name, it may
4725 be either a cast or a compound literal; we need to see whether
4726 the next character is '{' to tell the difference. If not, it is
4727 an unary expression. */
4728 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
4729 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
4731 struct c_type_name
*type_name
;
4734 c_parser_consume_token (parser
);
4735 type_name
= c_parser_type_name (parser
);
4736 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4737 if (type_name
== NULL
)
4739 ret
.value
= error_mark_node
;
4740 ret
.original_code
= ERROR_MARK
;
4744 /* Save casted types in the function's used types hash table. */
4745 used_types_insert (type_name
->specs
->type
);
4747 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4748 return c_parser_postfix_expression_after_paren_type (parser
,
4750 expr
= c_parser_cast_expression (parser
, NULL
);
4751 expr
= default_function_array_conversion (expr
);
4752 ret
.value
= c_cast_expr (type_name
, expr
.value
);
4753 ret
.original_code
= ERROR_MARK
;
4757 return c_parser_unary_expression (parser
);
4760 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
4766 unary-operator cast-expression
4767 sizeof unary-expression
4768 sizeof ( type-name )
4770 unary-operator: one of
4776 __alignof__ unary-expression
4777 __alignof__ ( type-name )
4780 unary-operator: one of
4781 __extension__ __real__ __imag__
4783 In addition, the GNU syntax treats ++ and -- as unary operators, so
4784 they may be applied to cast expressions with errors for non-lvalues
4787 static struct c_expr
4788 c_parser_unary_expression (c_parser
*parser
)
4791 struct c_expr ret
, op
;
4792 switch (c_parser_peek_token (parser
)->type
)
4795 c_parser_consume_token (parser
);
4796 op
= c_parser_cast_expression (parser
, NULL
);
4797 op
= default_function_array_conversion (op
);
4798 return parser_build_unary_op (PREINCREMENT_EXPR
, op
);
4799 case CPP_MINUS_MINUS
:
4800 c_parser_consume_token (parser
);
4801 op
= c_parser_cast_expression (parser
, NULL
);
4802 op
= default_function_array_conversion (op
);
4803 return parser_build_unary_op (PREDECREMENT_EXPR
, op
);
4805 c_parser_consume_token (parser
);
4806 return parser_build_unary_op (ADDR_EXPR
,
4807 c_parser_cast_expression (parser
, NULL
));
4809 c_parser_consume_token (parser
);
4810 op
= c_parser_cast_expression (parser
, NULL
);
4811 op
= default_function_array_conversion (op
);
4812 ret
.value
= build_indirect_ref (op
.value
, "unary *");
4813 ret
.original_code
= ERROR_MARK
;
4816 if (!c_dialect_objc () && !in_system_header
)
4817 warning (OPT_Wtraditional
,
4818 "%Htraditional C rejects the unary plus operator",
4819 &c_parser_peek_token (parser
)->location
);
4820 c_parser_consume_token (parser
);
4821 op
= c_parser_cast_expression (parser
, NULL
);
4822 op
= default_function_array_conversion (op
);
4823 return parser_build_unary_op (CONVERT_EXPR
, op
);
4825 c_parser_consume_token (parser
);
4826 op
= c_parser_cast_expression (parser
, NULL
);
4827 op
= default_function_array_conversion (op
);
4828 return parser_build_unary_op (NEGATE_EXPR
, op
);
4830 c_parser_consume_token (parser
);
4831 op
= c_parser_cast_expression (parser
, NULL
);
4832 op
= default_function_array_conversion (op
);
4833 return parser_build_unary_op (BIT_NOT_EXPR
, op
);
4835 c_parser_consume_token (parser
);
4836 op
= c_parser_cast_expression (parser
, NULL
);
4837 op
= default_function_array_conversion (op
);
4838 return parser_build_unary_op (TRUTH_NOT_EXPR
, op
);
4840 /* Refer to the address of a label as a pointer. */
4841 c_parser_consume_token (parser
);
4842 if (c_parser_next_token_is (parser
, CPP_NAME
))
4844 ret
.value
= finish_label_address_expr
4845 (c_parser_peek_token (parser
)->value
);
4846 c_parser_consume_token (parser
);
4850 c_parser_error (parser
, "expected identifier");
4851 ret
.value
= error_mark_node
;
4853 ret
.original_code
= ERROR_MARK
;
4856 switch (c_parser_peek_token (parser
)->keyword
)
4859 return c_parser_sizeof_expression (parser
);
4861 return c_parser_alignof_expression (parser
);
4863 c_parser_consume_token (parser
);
4864 ext
= disable_extension_diagnostics ();
4865 ret
= c_parser_cast_expression (parser
, NULL
);
4866 restore_extension_diagnostics (ext
);
4869 c_parser_consume_token (parser
);
4870 op
= c_parser_cast_expression (parser
, NULL
);
4871 op
= default_function_array_conversion (op
);
4872 return parser_build_unary_op (REALPART_EXPR
, op
);
4874 c_parser_consume_token (parser
);
4875 op
= c_parser_cast_expression (parser
, NULL
);
4876 op
= default_function_array_conversion (op
);
4877 return parser_build_unary_op (IMAGPART_EXPR
, op
);
4879 return c_parser_postfix_expression (parser
);
4882 return c_parser_postfix_expression (parser
);
4886 /* Parse a sizeof expression. */
4888 static struct c_expr
4889 c_parser_sizeof_expression (c_parser
*parser
)
4892 location_t expr_loc
;
4893 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SIZEOF
));
4894 c_parser_consume_token (parser
);
4897 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
4898 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
4900 /* Either sizeof ( type-name ) or sizeof unary-expression
4901 starting with a compound literal. */
4902 struct c_type_name
*type_name
;
4903 c_parser_consume_token (parser
);
4904 expr_loc
= c_parser_peek_token (parser
)->location
;
4905 type_name
= c_parser_type_name (parser
);
4906 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4907 if (type_name
== NULL
)
4912 ret
.value
= error_mark_node
;
4913 ret
.original_code
= ERROR_MARK
;
4916 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4918 expr
= c_parser_postfix_expression_after_paren_type (parser
,
4922 /* sizeof ( type-name ). */
4925 if (type_name
->declarator
->kind
== cdk_array
4926 && type_name
->declarator
->u
.array
.vla_unspec_p
)
4929 error ("%H%<[*]%> not allowed in other than a declaration",
4932 return c_expr_sizeof_type (type_name
);
4936 expr_loc
= c_parser_peek_token (parser
)->location
;
4937 expr
= c_parser_unary_expression (parser
);
4941 if (TREE_CODE (expr
.value
) == COMPONENT_REF
4942 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
4943 error ("%H%<sizeof%> applied to a bit-field", &expr_loc
);
4944 return c_expr_sizeof_expr (expr
);
4948 /* Parse an alignof expression. */
4950 static struct c_expr
4951 c_parser_alignof_expression (c_parser
*parser
)
4954 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNOF
));
4955 c_parser_consume_token (parser
);
4958 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
4959 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
4961 /* Either __alignof__ ( type-name ) or __alignof__
4962 unary-expression starting with a compound literal. */
4963 struct c_type_name
*type_name
;
4965 c_parser_consume_token (parser
);
4966 type_name
= c_parser_type_name (parser
);
4967 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4968 if (type_name
== NULL
)
4973 ret
.value
= error_mark_node
;
4974 ret
.original_code
= ERROR_MARK
;
4977 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4979 expr
= c_parser_postfix_expression_after_paren_type (parser
,
4983 /* alignof ( type-name ). */
4986 ret
.value
= c_alignof (groktypename (type_name
));
4987 ret
.original_code
= ERROR_MARK
;
4993 expr
= c_parser_unary_expression (parser
);
4997 ret
.value
= c_alignof_expr (expr
.value
);
4998 ret
.original_code
= ERROR_MARK
;
5003 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
5007 postfix-expression [ expression ]
5008 postfix-expression ( argument-expression-list[opt] )
5009 postfix-expression . identifier
5010 postfix-expression -> identifier
5011 postfix-expression ++
5012 postfix-expression --
5013 ( type-name ) { initializer-list }
5014 ( type-name ) { initializer-list , }
5016 argument-expression-list:
5018 argument-expression-list , argument-expression
5030 (treated as a keyword in GNU C)
5033 ( compound-statement )
5034 __builtin_va_arg ( assignment-expression , type-name )
5035 __builtin_offsetof ( type-name , offsetof-member-designator )
5036 __builtin_choose_expr ( assignment-expression ,
5037 assignment-expression ,
5038 assignment-expression )
5039 __builtin_types_compatible_p ( type-name , type-name )
5041 offsetof-member-designator:
5043 offsetof-member-designator . identifier
5044 offsetof-member-designator [ expression ]
5049 [ objc-receiver objc-message-args ]
5050 @selector ( objc-selector-arg )
5051 @protocol ( identifier )
5052 @encode ( type-name )
5056 static struct c_expr
5057 c_parser_postfix_expression (c_parser
*parser
)
5059 struct c_expr expr
, e1
, e2
, e3
;
5060 struct c_type_name
*t1
, *t2
;
5062 switch (c_parser_peek_token (parser
)->type
)
5069 expr
.value
= c_parser_peek_token (parser
)->value
;
5070 expr
.original_code
= ERROR_MARK
;
5071 c_parser_consume_token (parser
);
5077 expr
.value
= c_parser_peek_token (parser
)->value
;
5078 expr
.original_code
= STRING_CST
;
5079 c_parser_consume_token (parser
);
5081 case CPP_OBJC_STRING
:
5082 gcc_assert (c_dialect_objc ());
5084 = objc_build_string_object (c_parser_peek_token (parser
)->value
);
5085 expr
.original_code
= ERROR_MARK
;
5086 c_parser_consume_token (parser
);
5089 if (c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
5091 c_parser_error (parser
, "expected expression");
5092 expr
.value
= error_mark_node
;
5093 expr
.original_code
= ERROR_MARK
;
5097 tree id
= c_parser_peek_token (parser
)->value
;
5098 location_t loc
= c_parser_peek_token (parser
)->location
;
5099 c_parser_consume_token (parser
);
5100 expr
.value
= build_external_ref (id
,
5101 (c_parser_peek_token (parser
)->type
5102 == CPP_OPEN_PAREN
), loc
);
5103 expr
.original_code
= ERROR_MARK
;
5106 case CPP_OPEN_PAREN
:
5107 /* A parenthesized expression, statement expression or compound
5109 if (c_parser_peek_2nd_token (parser
)->type
== CPP_OPEN_BRACE
)
5111 /* A statement expression. */
5113 location_t here
= c_parser_peek_token (parser
)->location
;
5114 c_parser_consume_token (parser
);
5115 c_parser_consume_token (parser
);
5116 if (cur_stmt_list
== NULL
)
5118 error ("%Hbraced-group within expression allowed "
5119 "only inside a function", &here
);
5120 parser
->error
= true;
5121 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
5122 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5123 expr
.value
= error_mark_node
;
5124 expr
.original_code
= ERROR_MARK
;
5127 stmt
= c_begin_stmt_expr ();
5128 c_parser_compound_statement_nostart (parser
);
5129 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5132 pedwarn ("%HISO C forbids braced-groups within expressions",
5134 expr
.value
= c_finish_stmt_expr (stmt
);
5135 expr
.original_code
= ERROR_MARK
;
5137 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
5139 /* A compound literal. ??? Can we actually get here rather
5140 than going directly to
5141 c_parser_postfix_expression_after_paren_type from
5143 struct c_type_name
*type_name
;
5144 c_parser_consume_token (parser
);
5145 type_name
= c_parser_type_name (parser
);
5146 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5148 if (type_name
== NULL
)
5150 expr
.value
= error_mark_node
;
5151 expr
.original_code
= ERROR_MARK
;
5154 expr
= c_parser_postfix_expression_after_paren_type (parser
,
5159 /* A parenthesized expression. */
5160 c_parser_consume_token (parser
);
5161 expr
= c_parser_expression (parser
);
5162 if (TREE_CODE (expr
.value
) == MODIFY_EXPR
)
5163 TREE_NO_WARNING (expr
.value
) = 1;
5164 expr
.original_code
= ERROR_MARK
;
5165 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5170 switch (c_parser_peek_token (parser
)->keyword
)
5172 case RID_FUNCTION_NAME
:
5173 case RID_PRETTY_FUNCTION_NAME
:
5174 case RID_C99_FUNCTION_NAME
:
5175 expr
.value
= fname_decl (c_parser_peek_token (parser
)->keyword
,
5176 c_parser_peek_token (parser
)->value
);
5177 expr
.original_code
= ERROR_MARK
;
5178 c_parser_consume_token (parser
);
5181 c_parser_consume_token (parser
);
5182 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5184 expr
.value
= error_mark_node
;
5185 expr
.original_code
= ERROR_MARK
;
5188 e1
= c_parser_expr_no_commas (parser
, NULL
);
5189 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5191 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5192 expr
.value
= error_mark_node
;
5193 expr
.original_code
= ERROR_MARK
;
5196 t1
= c_parser_type_name (parser
);
5197 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5201 expr
.value
= error_mark_node
;
5202 expr
.original_code
= ERROR_MARK
;
5206 expr
.value
= build_va_arg (e1
.value
, groktypename (t1
));
5207 expr
.original_code
= ERROR_MARK
;
5211 c_parser_consume_token (parser
);
5212 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5214 expr
.value
= error_mark_node
;
5215 expr
.original_code
= ERROR_MARK
;
5218 t1
= c_parser_type_name (parser
);
5221 expr
.value
= error_mark_node
;
5222 expr
.original_code
= ERROR_MARK
;
5225 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5227 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5228 expr
.value
= error_mark_node
;
5229 expr
.original_code
= ERROR_MARK
;
5233 tree type
= groktypename (t1
);
5235 if (type
== error_mark_node
)
5236 offsetof_ref
= error_mark_node
;
5238 offsetof_ref
= build1 (INDIRECT_REF
, type
, null_pointer_node
);
5239 /* Parse the second argument to __builtin_offsetof. We
5240 must have one identifier, and beyond that we want to
5241 accept sub structure and sub array references. */
5242 if (c_parser_next_token_is (parser
, CPP_NAME
))
5244 offsetof_ref
= build_component_ref
5245 (offsetof_ref
, c_parser_peek_token (parser
)->value
);
5246 c_parser_consume_token (parser
);
5247 while (c_parser_next_token_is (parser
, CPP_DOT
)
5248 || c_parser_next_token_is (parser
,
5251 if (c_parser_next_token_is (parser
, CPP_DOT
))
5253 c_parser_consume_token (parser
);
5254 if (c_parser_next_token_is_not (parser
,
5257 c_parser_error (parser
, "expected identifier");
5260 offsetof_ref
= build_component_ref
5262 c_parser_peek_token (parser
)->value
);
5263 c_parser_consume_token (parser
);
5268 c_parser_consume_token (parser
);
5269 idx
= c_parser_expression (parser
).value
;
5270 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5272 offsetof_ref
= build_array_ref (offsetof_ref
, idx
);
5277 c_parser_error (parser
, "expected identifier");
5278 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5280 expr
.value
= fold_offsetof (offsetof_ref
, NULL_TREE
);
5281 expr
.original_code
= ERROR_MARK
;
5284 case RID_CHOOSE_EXPR
:
5285 c_parser_consume_token (parser
);
5286 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5288 expr
.value
= error_mark_node
;
5289 expr
.original_code
= ERROR_MARK
;
5292 loc
= c_parser_peek_token (parser
)->location
;
5293 e1
= c_parser_expr_no_commas (parser
, NULL
);
5294 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5296 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5297 expr
.value
= error_mark_node
;
5298 expr
.original_code
= ERROR_MARK
;
5301 e2
= c_parser_expr_no_commas (parser
, NULL
);
5302 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5304 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5305 expr
.value
= error_mark_node
;
5306 expr
.original_code
= ERROR_MARK
;
5309 e3
= c_parser_expr_no_commas (parser
, NULL
);
5310 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5315 c
= fold (e1
.value
);
5316 if (TREE_CODE (c
) != INTEGER_CST
)
5317 error ("%Hfirst argument to %<__builtin_choose_expr%> not"
5318 " a constant", &loc
);
5319 expr
= integer_zerop (c
) ? e3
: e2
;
5322 case RID_TYPES_COMPATIBLE_P
:
5323 c_parser_consume_token (parser
);
5324 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5326 expr
.value
= error_mark_node
;
5327 expr
.original_code
= ERROR_MARK
;
5330 t1
= c_parser_type_name (parser
);
5333 expr
.value
= error_mark_node
;
5334 expr
.original_code
= ERROR_MARK
;
5337 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5339 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5340 expr
.value
= error_mark_node
;
5341 expr
.original_code
= ERROR_MARK
;
5344 t2
= c_parser_type_name (parser
);
5347 expr
.value
= error_mark_node
;
5348 expr
.original_code
= ERROR_MARK
;
5351 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5356 e1
= TYPE_MAIN_VARIANT (groktypename (t1
));
5357 e2
= TYPE_MAIN_VARIANT (groktypename (t2
));
5359 expr
.value
= comptypes (e1
, e2
)
5360 ? build_int_cst (NULL_TREE
, 1)
5361 : build_int_cst (NULL_TREE
, 0);
5362 expr
.original_code
= ERROR_MARK
;
5365 case RID_AT_SELECTOR
:
5366 gcc_assert (c_dialect_objc ());
5367 c_parser_consume_token (parser
);
5368 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5370 expr
.value
= error_mark_node
;
5371 expr
.original_code
= ERROR_MARK
;
5375 tree sel
= c_parser_objc_selector_arg (parser
);
5376 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5378 expr
.value
= objc_build_selector_expr (sel
);
5379 expr
.original_code
= ERROR_MARK
;
5382 case RID_AT_PROTOCOL
:
5383 gcc_assert (c_dialect_objc ());
5384 c_parser_consume_token (parser
);
5385 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5387 expr
.value
= error_mark_node
;
5388 expr
.original_code
= ERROR_MARK
;
5391 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5393 c_parser_error (parser
, "expected identifier");
5394 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5395 expr
.value
= error_mark_node
;
5396 expr
.original_code
= ERROR_MARK
;
5400 tree id
= c_parser_peek_token (parser
)->value
;
5401 c_parser_consume_token (parser
);
5402 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5404 expr
.value
= objc_build_protocol_expr (id
);
5405 expr
.original_code
= ERROR_MARK
;
5409 /* Extension to support C-structures in the archiver. */
5410 gcc_assert (c_dialect_objc ());
5411 c_parser_consume_token (parser
);
5412 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5414 expr
.value
= error_mark_node
;
5415 expr
.original_code
= ERROR_MARK
;
5418 t1
= c_parser_type_name (parser
);
5421 expr
.value
= error_mark_node
;
5422 expr
.original_code
= ERROR_MARK
;
5423 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5426 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5429 tree type
= groktypename (t1
);
5430 expr
.value
= objc_build_encode_expr (type
);
5431 expr
.original_code
= ERROR_MARK
;
5435 c_parser_error (parser
, "expected expression");
5436 expr
.value
= error_mark_node
;
5437 expr
.original_code
= ERROR_MARK
;
5441 case CPP_OPEN_SQUARE
:
5442 if (c_dialect_objc ())
5444 tree receiver
, args
;
5445 c_parser_consume_token (parser
);
5446 receiver
= c_parser_objc_receiver (parser
);
5447 args
= c_parser_objc_message_args (parser
);
5448 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5450 expr
.value
= objc_build_message_expr (build_tree_list (receiver
,
5452 expr
.original_code
= ERROR_MARK
;
5455 /* Else fall through to report error. */
5457 c_parser_error (parser
, "expected expression");
5458 expr
.value
= error_mark_node
;
5459 expr
.original_code
= ERROR_MARK
;
5462 return c_parser_postfix_expression_after_primary (parser
, expr
);
5465 /* Parse a postfix expression after a parenthesized type name: the
5466 brace-enclosed initializer of a compound literal, possibly followed
5467 by some postfix operators. This is separate because it is not
5468 possible to tell until after the type name whether a cast
5469 expression has a cast or a compound literal, or whether the operand
5470 of sizeof is a parenthesized type name or starts with a compound
5473 static struct c_expr
5474 c_parser_postfix_expression_after_paren_type (c_parser
*parser
,
5475 struct c_type_name
*type_name
)
5480 location_t start_loc
;
5481 start_init (NULL_TREE
, NULL
, 0);
5482 type
= groktypename (type_name
);
5483 start_loc
= c_parser_peek_token (parser
)->location
;
5484 if (type
!= error_mark_node
&& C_TYPE_VARIABLE_SIZE (type
))
5486 error ("%Hcompound literal has variable size", &start_loc
);
5487 type
= error_mark_node
;
5489 init
= c_parser_braced_init (parser
, type
, false);
5491 maybe_warn_string_init (type
, init
);
5493 if (pedantic
&& !flag_isoc99
)
5494 pedwarn ("%HISO C90 forbids compound literals", &start_loc
);
5495 expr
.value
= build_compound_literal (type
, init
.value
);
5496 expr
.original_code
= ERROR_MARK
;
5497 return c_parser_postfix_expression_after_primary (parser
, expr
);
5500 /* Parse a postfix expression after the initial primary or compound
5501 literal; that is, parse a series of postfix operators. */
5503 static struct c_expr
5504 c_parser_postfix_expression_after_primary (c_parser
*parser
,
5507 tree ident
, idx
, exprlist
;
5510 switch (c_parser_peek_token (parser
)->type
)
5512 case CPP_OPEN_SQUARE
:
5513 /* Array reference. */
5514 c_parser_consume_token (parser
);
5515 idx
= c_parser_expression (parser
).value
;
5516 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5518 expr
.value
= build_array_ref (expr
.value
, idx
);
5519 expr
.original_code
= ERROR_MARK
;
5521 case CPP_OPEN_PAREN
:
5522 /* Function call. */
5523 c_parser_consume_token (parser
);
5524 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
5525 exprlist
= NULL_TREE
;
5527 exprlist
= c_parser_expr_list (parser
, true);
5528 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5530 expr
.value
= build_function_call (expr
.value
, exprlist
);
5531 expr
.original_code
= ERROR_MARK
;
5532 if (warn_disallowed_functions
)
5533 warn_if_disallowed_function_p (expr
.value
);
5536 /* Structure element reference. */
5537 c_parser_consume_token (parser
);
5538 expr
= default_function_array_conversion (expr
);
5539 if (c_parser_next_token_is (parser
, CPP_NAME
))
5540 ident
= c_parser_peek_token (parser
)->value
;
5543 c_parser_error (parser
, "expected identifier");
5544 expr
.value
= error_mark_node
;
5545 expr
.original_code
= ERROR_MARK
;
5548 c_parser_consume_token (parser
);
5549 expr
.value
= build_component_ref (expr
.value
, ident
);
5550 expr
.original_code
= ERROR_MARK
;
5553 /* Structure element reference. */
5554 c_parser_consume_token (parser
);
5555 expr
= default_function_array_conversion (expr
);
5556 if (c_parser_next_token_is (parser
, CPP_NAME
))
5557 ident
= c_parser_peek_token (parser
)->value
;
5560 c_parser_error (parser
, "expected identifier");
5561 expr
.value
= error_mark_node
;
5562 expr
.original_code
= ERROR_MARK
;
5565 c_parser_consume_token (parser
);
5566 expr
.value
= build_component_ref (build_indirect_ref (expr
.value
,
5568 expr
.original_code
= ERROR_MARK
;
5571 /* Postincrement. */
5572 c_parser_consume_token (parser
);
5573 expr
= default_function_array_conversion (expr
);
5574 expr
.value
= build_unary_op (POSTINCREMENT_EXPR
, expr
.value
, 0);
5575 expr
.original_code
= ERROR_MARK
;
5577 case CPP_MINUS_MINUS
:
5578 /* Postdecrement. */
5579 c_parser_consume_token (parser
);
5580 expr
= default_function_array_conversion (expr
);
5581 expr
.value
= build_unary_op (POSTDECREMENT_EXPR
, expr
.value
, 0);
5582 expr
.original_code
= ERROR_MARK
;
5590 /* Parse an expression (C90 6.3.17, C99 6.5.17).
5593 assignment-expression
5594 expression , assignment-expression
5597 static struct c_expr
5598 c_parser_expression (c_parser
*parser
)
5601 expr
= c_parser_expr_no_commas (parser
, NULL
);
5602 while (c_parser_next_token_is (parser
, CPP_COMMA
))
5605 c_parser_consume_token (parser
);
5606 next
= c_parser_expr_no_commas (parser
, NULL
);
5607 next
= default_function_array_conversion (next
);
5608 expr
.value
= build_compound_expr (expr
.value
, next
.value
);
5609 expr
.original_code
= COMPOUND_EXPR
;
5614 /* Parse an expression and convert functions or arrays to
5617 static struct c_expr
5618 c_parser_expression_conv (c_parser
*parser
)
5621 expr
= c_parser_expression (parser
);
5622 expr
= default_function_array_conversion (expr
);
5626 /* Parse a non-empty list of expressions. If CONVERT_P, convert
5627 functions and arrays to pointers.
5630 assignment-expression
5631 nonempty-expr-list , assignment-expression
5635 c_parser_expr_list (c_parser
*parser
, bool convert_p
)
5639 expr
= c_parser_expr_no_commas (parser
, NULL
);
5641 expr
= default_function_array_conversion (expr
);
5642 ret
= cur
= build_tree_list (NULL_TREE
, expr
.value
);
5643 while (c_parser_next_token_is (parser
, CPP_COMMA
))
5645 c_parser_consume_token (parser
);
5646 expr
= c_parser_expr_no_commas (parser
, NULL
);
5648 expr
= default_function_array_conversion (expr
);
5649 cur
= TREE_CHAIN (cur
) = build_tree_list (NULL_TREE
, expr
.value
);
5655 /* Parse Objective-C-specific constructs. */
5657 /* Parse an objc-class-definition.
5659 objc-class-definition:
5660 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
5661 objc-class-instance-variables[opt] objc-methodprotolist @end
5662 @implementation identifier objc-superclass[opt]
5663 objc-class-instance-variables[opt]
5664 @interface identifier ( identifier ) objc-protocol-refs[opt]
5665 objc-methodprotolist @end
5666 @implementation identifier ( identifier )
5671 "@interface identifier (" must start "@interface identifier (
5672 identifier ) ...": objc-methodprotolist in the first production may
5673 not start with a parenthesized identifier as a declarator of a data
5674 definition with no declaration specifiers if the objc-superclass,
5675 objc-protocol-refs and objc-class-instance-variables are omitted. */
5678 c_parser_objc_class_definition (c_parser
*parser
)
5683 if (c_parser_next_token_is_keyword (parser
, RID_AT_INTERFACE
))
5685 else if (c_parser_next_token_is_keyword (parser
, RID_AT_IMPLEMENTATION
))
5689 c_parser_consume_token (parser
);
5690 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5692 c_parser_error (parser
, "expected identifier");
5695 id1
= c_parser_peek_token (parser
)->value
;
5696 c_parser_consume_token (parser
);
5697 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
5700 tree proto
= NULL_TREE
;
5701 c_parser_consume_token (parser
);
5702 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5704 c_parser_error (parser
, "expected identifier");
5705 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5708 id2
= c_parser_peek_token (parser
)->value
;
5709 c_parser_consume_token (parser
);
5710 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5713 objc_start_category_implementation (id1
, id2
);
5716 if (c_parser_next_token_is (parser
, CPP_LESS
))
5717 proto
= c_parser_objc_protocol_refs (parser
);
5718 objc_start_category_interface (id1
, id2
, proto
);
5719 c_parser_objc_methodprotolist (parser
);
5720 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
5721 objc_finish_interface ();
5724 if (c_parser_next_token_is (parser
, CPP_COLON
))
5726 c_parser_consume_token (parser
);
5727 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5729 c_parser_error (parser
, "expected identifier");
5732 superclass
= c_parser_peek_token (parser
)->value
;
5733 c_parser_consume_token (parser
);
5736 superclass
= NULL_TREE
;
5739 tree proto
= NULL_TREE
;
5740 if (c_parser_next_token_is (parser
, CPP_LESS
))
5741 proto
= c_parser_objc_protocol_refs (parser
);
5742 objc_start_class_interface (id1
, superclass
, proto
);
5745 objc_start_class_implementation (id1
, superclass
);
5746 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5747 c_parser_objc_class_instance_variables (parser
);
5750 objc_continue_interface ();
5751 c_parser_objc_methodprotolist (parser
);
5752 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
5753 objc_finish_interface ();
5757 objc_continue_implementation ();
5762 /* Parse objc-class-instance-variables.
5764 objc-class-instance-variables:
5765 { objc-instance-variable-decl-list[opt] }
5767 objc-instance-variable-decl-list:
5768 objc-visibility-spec
5769 objc-instance-variable-decl ;
5771 objc-instance-variable-decl-list objc-visibility-spec
5772 objc-instance-variable-decl-list objc-instance-variable-decl ;
5773 objc-instance-variable-decl-list ;
5775 objc-visibility-spec:
5780 objc-instance-variable-decl:
5785 c_parser_objc_class_instance_variables (c_parser
*parser
)
5787 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
5788 c_parser_consume_token (parser
);
5789 while (c_parser_next_token_is_not (parser
, CPP_EOF
))
5792 /* Parse any stray semicolon. */
5793 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5796 pedwarn ("%Hextra semicolon in struct or union specified",
5797 &c_parser_peek_token (parser
)->location
);
5798 c_parser_consume_token (parser
);
5801 /* Stop if at the end of the instance variables. */
5802 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
5804 c_parser_consume_token (parser
);
5807 /* Parse any objc-visibility-spec. */
5808 if (c_parser_next_token_is_keyword (parser
, RID_PRIVATE
))
5810 c_parser_consume_token (parser
);
5811 objc_set_visibility (2);
5814 else if (c_parser_next_token_is_keyword (parser
, RID_PROTECTED
))
5816 c_parser_consume_token (parser
);
5817 objc_set_visibility (0);
5820 else if (c_parser_next_token_is_keyword (parser
, RID_PUBLIC
))
5822 c_parser_consume_token (parser
);
5823 objc_set_visibility (1);
5826 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
5828 c_parser_pragma (parser
, pragma_external
);
5832 /* Parse some comma-separated declarations. */
5833 decls
= c_parser_struct_declaration (parser
);
5835 /* Comma-separated instance variables are chained together in
5836 reverse order; add them one by one. */
5837 tree ivar
= nreverse (decls
);
5838 for (; ivar
; ivar
= TREE_CHAIN (ivar
))
5839 objc_add_instance_variable (copy_node (ivar
));
5841 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5845 /* Parse an objc-class-declaration.
5847 objc-class-declaration:
5848 @class identifier-list ;
5852 c_parser_objc_class_declaration (c_parser
*parser
)
5854 tree list
= NULL_TREE
;
5855 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_CLASS
));
5856 c_parser_consume_token (parser
);
5857 /* Any identifiers, including those declared as type names, are OK
5862 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5864 c_parser_error (parser
, "expected identifier");
5867 id
= c_parser_peek_token (parser
)->value
;
5868 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
5869 c_parser_consume_token (parser
);
5870 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5871 c_parser_consume_token (parser
);
5875 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5876 objc_declare_class (list
);
5879 /* Parse an objc-alias-declaration.
5881 objc-alias-declaration:
5882 @compatibility_alias identifier identifier ;
5886 c_parser_objc_alias_declaration (c_parser
*parser
)
5889 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_ALIAS
));
5890 c_parser_consume_token (parser
);
5891 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5893 c_parser_error (parser
, "expected identifier");
5894 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
5897 id1
= c_parser_peek_token (parser
)->value
;
5898 c_parser_consume_token (parser
);
5899 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5901 c_parser_error (parser
, "expected identifier");
5902 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
5905 id2
= c_parser_peek_token (parser
)->value
;
5906 c_parser_consume_token (parser
);
5907 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5908 objc_declare_alias (id1
, id2
);
5911 /* Parse an objc-protocol-definition.
5913 objc-protocol-definition:
5914 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
5915 @protocol identifier-list ;
5917 "@protocol identifier ;" should be resolved as "@protocol
5918 identifier-list ;": objc-methodprotolist may not start with a
5919 semicolon in the first alternative if objc-protocol-refs are
5923 c_parser_objc_protocol_definition (c_parser
*parser
)
5925 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROTOCOL
));
5926 c_parser_consume_token (parser
);
5927 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5929 c_parser_error (parser
, "expected identifier");
5932 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
5933 || c_parser_peek_2nd_token (parser
)->type
== CPP_SEMICOLON
)
5935 tree list
= NULL_TREE
;
5936 /* Any identifiers, including those declared as type names, are
5941 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5943 c_parser_error (parser
, "expected identifier");
5946 id
= c_parser_peek_token (parser
)->value
;
5947 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
5948 c_parser_consume_token (parser
);
5949 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5950 c_parser_consume_token (parser
);
5954 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5955 objc_declare_protocols (list
);
5959 tree id
= c_parser_peek_token (parser
)->value
;
5960 tree proto
= NULL_TREE
;
5961 c_parser_consume_token (parser
);
5962 if (c_parser_next_token_is (parser
, CPP_LESS
))
5963 proto
= c_parser_objc_protocol_refs (parser
);
5964 parser
->objc_pq_context
= true;
5965 objc_start_protocol (id
, proto
);
5966 c_parser_objc_methodprotolist (parser
);
5967 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
5968 parser
->objc_pq_context
= false;
5969 objc_finish_interface ();
5973 /* Parse an objc-method-type.
5980 static enum tree_code
5981 c_parser_objc_method_type (c_parser
*parser
)
5983 switch (c_parser_peek_token (parser
)->type
)
5986 c_parser_consume_token (parser
);
5989 c_parser_consume_token (parser
);
5996 /* Parse an objc-method-definition.
5998 objc-method-definition:
5999 objc-method-type objc-method-decl ;[opt] compound-statement
6003 c_parser_objc_method_definition (c_parser
*parser
)
6005 enum tree_code type
= c_parser_objc_method_type (parser
);
6007 objc_set_method_type (type
);
6008 parser
->objc_pq_context
= true;
6009 decl
= c_parser_objc_method_decl (parser
);
6010 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
6012 c_parser_consume_token (parser
);
6014 pedwarn ("%Hextra semicolon in method definition specified",
6015 &c_parser_peek_token (parser
)->location
);
6017 if (!c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6019 c_parser_error (parser
, "expected %<{%>");
6022 parser
->objc_pq_context
= false;
6023 objc_start_method_definition (decl
);
6024 add_stmt (c_parser_compound_statement (parser
));
6025 objc_finish_method_definition (current_function_decl
);
6028 /* Parse an objc-methodprotolist.
6030 objc-methodprotolist:
6032 objc-methodprotolist objc-methodproto
6033 objc-methodprotolist declaration
6034 objc-methodprotolist ;
6036 The declaration is a data definition, which may be missing
6037 declaration specifiers under the same rules and diagnostics as
6038 other data definitions outside functions, and the stray semicolon
6039 is diagnosed the same way as a stray semicolon outside a
6043 c_parser_objc_methodprotolist (c_parser
*parser
)
6047 /* The list is terminated by @end. */
6048 switch (c_parser_peek_token (parser
)->type
)
6052 pedwarn ("%HISO C does not allow extra %<;%> "
6053 "outside of a function",
6054 &c_parser_peek_token (parser
)->location
);
6055 c_parser_consume_token (parser
);
6059 c_parser_objc_methodproto (parser
);
6062 c_parser_pragma (parser
, pragma_external
);
6067 if (c_parser_next_token_is_keyword (parser
, RID_AT_END
))
6069 c_parser_declaration_or_fndef (parser
, false, true, false, true);
6075 /* Parse an objc-methodproto.
6078 objc-method-type objc-method-decl ;
6082 c_parser_objc_methodproto (c_parser
*parser
)
6084 enum tree_code type
= c_parser_objc_method_type (parser
);
6086 objc_set_method_type (type
);
6087 /* Remember protocol qualifiers in prototypes. */
6088 parser
->objc_pq_context
= true;
6089 decl
= c_parser_objc_method_decl (parser
);
6090 /* Forget protocol qualifiers here. */
6091 parser
->objc_pq_context
= false;
6092 objc_add_method_declaration (decl
);
6093 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
6096 /* Parse an objc-method-decl.
6099 ( objc-type-name ) objc-selector
6101 ( objc-type-name ) objc-keyword-selector objc-optparmlist
6102 objc-keyword-selector objc-optparmlist
6104 objc-keyword-selector:
6106 objc-keyword-selector objc-keyword-decl
6109 objc-selector : ( objc-type-name ) identifier
6110 objc-selector : identifier
6111 : ( objc-type-name ) identifier
6115 objc-optparms objc-optellipsis
6119 objc-opt-parms , parameter-declaration
6127 c_parser_objc_method_decl (c_parser
*parser
)
6129 tree type
= NULL_TREE
;
6131 tree parms
= NULL_TREE
;
6132 bool ellipsis
= false;
6134 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
6136 c_parser_consume_token (parser
);
6137 type
= c_parser_objc_type_name (parser
);
6138 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6140 sel
= c_parser_objc_selector (parser
);
6141 /* If there is no selector, or a colon follows, we have an
6142 objc-keyword-selector. If there is a selector, and a colon does
6143 not follow, that selector ends the objc-method-decl. */
6144 if (!sel
|| c_parser_next_token_is (parser
, CPP_COLON
))
6147 tree list
= NULL_TREE
;
6150 tree atype
= NULL_TREE
, id
, keyworddecl
;
6151 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6153 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
6155 c_parser_consume_token (parser
);
6156 atype
= c_parser_objc_type_name (parser
);
6157 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6160 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6162 c_parser_error (parser
, "expected identifier");
6163 return error_mark_node
;
6165 id
= c_parser_peek_token (parser
)->value
;
6166 c_parser_consume_token (parser
);
6167 keyworddecl
= objc_build_keyword_decl (tsel
, atype
, id
);
6168 list
= chainon (list
, keyworddecl
);
6169 tsel
= c_parser_objc_selector (parser
);
6170 if (!tsel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6173 /* Parse the optional parameter list. Optional Objective-C
6174 method parameters follow the C syntax, and may include '...'
6175 to denote a variable number of arguments. */
6176 parms
= make_node (TREE_LIST
);
6177 while (c_parser_next_token_is (parser
, CPP_COMMA
))
6179 struct c_parm
*parm
;
6180 c_parser_consume_token (parser
);
6181 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
6184 c_parser_consume_token (parser
);
6187 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
6190 parms
= chainon (parms
,
6191 build_tree_list (NULL_TREE
, grokparm (parm
)));
6195 return objc_build_method_signature (type
, sel
, parms
, ellipsis
);
6198 /* Parse an objc-type-name.
6201 objc-type-qualifiers[opt] type-name
6202 objc-type-qualifiers[opt]
6204 objc-type-qualifiers:
6206 objc-type-qualifiers objc-type-qualifier
6208 objc-type-qualifier: one of
6209 in out inout bycopy byref oneway
6213 c_parser_objc_type_name (c_parser
*parser
)
6215 tree quals
= NULL_TREE
;
6216 struct c_type_name
*type_name
= NULL
;
6217 tree type
= NULL_TREE
;
6220 c_token
*token
= c_parser_peek_token (parser
);
6221 if (token
->type
== CPP_KEYWORD
6222 && (token
->keyword
== RID_IN
6223 || token
->keyword
== RID_OUT
6224 || token
->keyword
== RID_INOUT
6225 || token
->keyword
== RID_BYCOPY
6226 || token
->keyword
== RID_BYREF
6227 || token
->keyword
== RID_ONEWAY
))
6229 quals
= chainon (quals
, build_tree_list (NULL_TREE
, token
->value
));
6230 c_parser_consume_token (parser
);
6235 if (c_parser_next_token_starts_typename (parser
))
6236 type_name
= c_parser_type_name (parser
);
6238 type
= groktypename (type_name
);
6239 return build_tree_list (quals
, type
);
6242 /* Parse objc-protocol-refs.
6249 c_parser_objc_protocol_refs (c_parser
*parser
)
6251 tree list
= NULL_TREE
;
6252 gcc_assert (c_parser_next_token_is (parser
, CPP_LESS
));
6253 c_parser_consume_token (parser
);
6254 /* Any identifiers, including those declared as type names, are OK
6259 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6261 c_parser_error (parser
, "expected identifier");
6264 id
= c_parser_peek_token (parser
)->value
;
6265 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
6266 c_parser_consume_token (parser
);
6267 if (c_parser_next_token_is (parser
, CPP_COMMA
))
6268 c_parser_consume_token (parser
);
6272 c_parser_require (parser
, CPP_GREATER
, "expected %<>%>");
6276 /* Parse an objc-try-catch-statement.
6278 objc-try-catch-statement:
6279 @try compound-statement objc-catch-list[opt]
6280 @try compound-statement objc-catch-list[opt] @finally compound-statement
6283 @catch ( parameter-declaration ) compound-statement
6284 objc-catch-list @catch ( parameter-declaration ) compound-statement
6288 c_parser_objc_try_catch_statement (c_parser
*parser
)
6292 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TRY
));
6293 c_parser_consume_token (parser
);
6294 loc
= c_parser_peek_token (parser
)->location
;
6295 stmt
= c_parser_compound_statement (parser
);
6296 objc_begin_try_stmt (loc
, stmt
);
6297 while (c_parser_next_token_is_keyword (parser
, RID_CATCH
))
6299 struct c_parm
*parm
;
6300 c_parser_consume_token (parser
);
6301 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6303 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
6306 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6309 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6310 objc_begin_catch_clause (grokparm (parm
));
6311 if (c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
6312 c_parser_compound_statement_nostart (parser
);
6313 objc_finish_catch_clause ();
6315 if (c_parser_next_token_is_keyword (parser
, RID_AT_FINALLY
))
6319 c_parser_consume_token (parser
);
6320 finloc
= c_parser_peek_token (parser
)->location
;
6321 finstmt
= c_parser_compound_statement (parser
);
6322 objc_build_finally_clause (finloc
, finstmt
);
6324 objc_finish_try_stmt ();
6327 /* Parse an objc-synchronized-statement.
6329 objc-synchronized-statement:
6330 @synchronized ( expression ) compound-statement
6334 c_parser_objc_synchronized_statement (c_parser
*parser
)
6338 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNCHRONIZED
));
6339 c_parser_consume_token (parser
);
6340 loc
= c_parser_peek_token (parser
)->location
;
6341 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6343 expr
= c_parser_expression (parser
).value
;
6344 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6347 expr
= error_mark_node
;
6348 stmt
= c_parser_compound_statement (parser
);
6349 objc_build_synchronized (loc
, expr
, stmt
);
6352 /* Parse an objc-selector; return NULL_TREE without an error if the
6353 next token is not an objc-selector.
6358 enum struct union if else while do for switch case default
6359 break continue return goto asm sizeof typeof __alignof
6360 unsigned long const short volatile signed restrict _Complex
6361 in out inout bycopy byref oneway int char float double void _Bool
6363 ??? Why this selection of keywords but not, for example, storage
6364 class specifiers? */
6367 c_parser_objc_selector (c_parser
*parser
)
6369 c_token
*token
= c_parser_peek_token (parser
);
6370 tree value
= token
->value
;
6371 if (token
->type
== CPP_NAME
)
6373 c_parser_consume_token (parser
);
6376 if (token
->type
!= CPP_KEYWORD
)
6378 switch (token
->keyword
)
6419 c_parser_consume_token (parser
);
6426 /* Parse an objc-selector-arg.
6430 objc-keywordname-list
6432 objc-keywordname-list:
6434 objc-keywordname-list objc-keywordname
6442 c_parser_objc_selector_arg (c_parser
*parser
)
6444 tree sel
= c_parser_objc_selector (parser
);
6445 tree list
= NULL_TREE
;
6446 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6450 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6452 list
= chainon (list
, build_tree_list (sel
, NULL_TREE
));
6453 sel
= c_parser_objc_selector (parser
);
6454 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6460 /* Parse an objc-receiver.
6469 c_parser_objc_receiver (c_parser
*parser
)
6471 if (c_parser_peek_token (parser
)->type
== CPP_NAME
6472 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
6473 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
6475 tree id
= c_parser_peek_token (parser
)->value
;
6476 c_parser_consume_token (parser
);
6477 return objc_get_class_reference (id
);
6479 return c_parser_expression (parser
).value
;
6482 /* Parse objc-message-args.
6486 objc-keywordarg-list
6488 objc-keywordarg-list:
6490 objc-keywordarg-list objc-keywordarg
6493 objc-selector : objc-keywordexpr
6498 c_parser_objc_message_args (c_parser
*parser
)
6500 tree sel
= c_parser_objc_selector (parser
);
6501 tree list
= NULL_TREE
;
6502 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6507 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6509 keywordexpr
= c_parser_objc_keywordexpr (parser
);
6510 list
= chainon (list
, build_tree_list (sel
, keywordexpr
));
6511 sel
= c_parser_objc_selector (parser
);
6512 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6518 /* Parse an objc-keywordexpr.
6525 c_parser_objc_keywordexpr (c_parser
*parser
)
6527 tree list
= c_parser_expr_list (parser
, true);
6528 if (TREE_CHAIN (list
) == NULL_TREE
)
6530 /* Just return the expression, remove a level of
6532 return TREE_VALUE (list
);
6536 /* We have a comma expression, we will collapse later. */
6542 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
6543 should be considered, statements. ALLOW_STMT is true if we're within
6544 the context of a function and such pragmas are to be allowed. Returns
6545 true if we actually parsed such a pragma. */
6548 c_parser_pragma (c_parser
*parser
, enum pragma_context context
)
6552 id
= c_parser_peek_token (parser
)->pragma_kind
;
6553 gcc_assert (id
!= PRAGMA_NONE
);
6557 case PRAGMA_OMP_BARRIER
:
6558 if (context
!= pragma_compound
)
6560 if (context
== pragma_stmt
)
6561 c_parser_error (parser
, "%<#pragma omp barrier%> may only be "
6562 "used in compound statements");
6565 c_parser_omp_barrier (parser
);
6568 case PRAGMA_OMP_FLUSH
:
6569 if (context
!= pragma_compound
)
6571 if (context
== pragma_stmt
)
6572 c_parser_error (parser
, "%<#pragma omp flush%> may only be "
6573 "used in compound statements");
6576 c_parser_omp_flush (parser
);
6579 case PRAGMA_OMP_TASKWAIT
:
6580 if (context
!= pragma_compound
)
6582 if (context
== pragma_stmt
)
6583 c_parser_error (parser
, "%<#pragma omp taskwait%> may only be "
6584 "used in compound statements");
6587 c_parser_omp_taskwait (parser
);
6590 case PRAGMA_OMP_THREADPRIVATE
:
6591 c_parser_omp_threadprivate (parser
);
6594 case PRAGMA_OMP_SECTION
:
6595 error ("%H%<#pragma omp section%> may only be used in "
6596 "%<#pragma omp sections%> construct",
6597 &c_parser_peek_token (parser
)->location
);
6598 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
6601 case PRAGMA_GCC_PCH_PREPROCESS
:
6602 c_parser_error (parser
, "%<#pragma GCC pch_preprocess%> must be first");
6603 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
6607 if (id
< PRAGMA_FIRST_EXTERNAL
)
6609 if (context
== pragma_external
)
6612 c_parser_error (parser
, "expected declaration specifiers");
6613 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
6616 c_parser_omp_construct (parser
);
6622 c_parser_consume_pragma (parser
);
6623 c_invoke_pragma_handler (id
);
6625 /* Skip to EOL, but suppress any error message. Those will have been
6626 generated by the handler routine through calling error, as opposed
6627 to calling c_parser_error. */
6628 parser
->error
= true;
6629 c_parser_skip_to_pragma_eol (parser
);
6634 /* The interface the pragma parsers have to the lexer. */
6637 pragma_lex (tree
*value
)
6639 c_token
*tok
= c_parser_peek_token (the_parser
);
6640 enum cpp_ttype ret
= tok
->type
;
6642 *value
= tok
->value
;
6643 if (ret
== CPP_PRAGMA_EOL
|| ret
== CPP_EOF
)
6647 if (ret
== CPP_KEYWORD
)
6649 c_parser_consume_token (the_parser
);
6656 c_parser_pragma_pch_preprocess (c_parser
*parser
)
6660 c_parser_consume_pragma (parser
);
6661 if (c_parser_next_token_is (parser
, CPP_STRING
))
6663 name
= c_parser_peek_token (parser
)->value
;
6664 c_parser_consume_token (parser
);
6667 c_parser_error (parser
, "expected string literal");
6668 c_parser_skip_to_pragma_eol (parser
);
6671 c_common_pch_pragma (parse_in
, TREE_STRING_POINTER (name
));
6674 /* OpenMP 2.5 parsing routines. */
6676 /* Returns name of the next clause.
6677 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
6678 the token is not consumed. Otherwise appropriate pragma_omp_clause is
6679 returned and the token is consumed. */
6681 static pragma_omp_clause
6682 c_parser_omp_clause_name (c_parser
*parser
)
6684 pragma_omp_clause result
= PRAGMA_OMP_CLAUSE_NONE
;
6686 if (c_parser_next_token_is_keyword (parser
, RID_IF
))
6687 result
= PRAGMA_OMP_CLAUSE_IF
;
6688 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
6689 result
= PRAGMA_OMP_CLAUSE_DEFAULT
;
6690 else if (c_parser_next_token_is (parser
, CPP_NAME
))
6692 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
6697 if (!strcmp ("collapse", p
))
6698 result
= PRAGMA_OMP_CLAUSE_COLLAPSE
;
6699 else if (!strcmp ("copyin", p
))
6700 result
= PRAGMA_OMP_CLAUSE_COPYIN
;
6701 else if (!strcmp ("copyprivate", p
))
6702 result
= PRAGMA_OMP_CLAUSE_COPYPRIVATE
;
6705 if (!strcmp ("firstprivate", p
))
6706 result
= PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
;
6709 if (!strcmp ("lastprivate", p
))
6710 result
= PRAGMA_OMP_CLAUSE_LASTPRIVATE
;
6713 if (!strcmp ("nowait", p
))
6714 result
= PRAGMA_OMP_CLAUSE_NOWAIT
;
6715 else if (!strcmp ("num_threads", p
))
6716 result
= PRAGMA_OMP_CLAUSE_NUM_THREADS
;
6719 if (!strcmp ("ordered", p
))
6720 result
= PRAGMA_OMP_CLAUSE_ORDERED
;
6723 if (!strcmp ("private", p
))
6724 result
= PRAGMA_OMP_CLAUSE_PRIVATE
;
6727 if (!strcmp ("reduction", p
))
6728 result
= PRAGMA_OMP_CLAUSE_REDUCTION
;
6731 if (!strcmp ("schedule", p
))
6732 result
= PRAGMA_OMP_CLAUSE_SCHEDULE
;
6733 else if (!strcmp ("shared", p
))
6734 result
= PRAGMA_OMP_CLAUSE_SHARED
;
6737 if (!strcmp ("untied", p
))
6738 result
= PRAGMA_OMP_CLAUSE_UNTIED
;
6743 if (result
!= PRAGMA_OMP_CLAUSE_NONE
)
6744 c_parser_consume_token (parser
);
6749 /* Validate that a clause of the given type does not already exist. */
6752 check_no_duplicate_clause (tree clauses
, enum omp_clause_code code
,
6757 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
6758 if (OMP_CLAUSE_CODE (c
) == code
)
6760 error ("too many %qs clauses", name
);
6768 variable-list , identifier
6770 If KIND is nonzero, create the appropriate node and install the decl
6771 in OMP_CLAUSE_DECL and add the node to the head of the list.
6773 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
6774 return the list created. */
6777 c_parser_omp_variable_list (c_parser
*parser
, enum omp_clause_code kind
,
6780 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
6781 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
6782 c_parser_error (parser
, "expected identifier");
6784 while (c_parser_next_token_is (parser
, CPP_NAME
)
6785 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
6787 tree t
= lookup_name (c_parser_peek_token (parser
)->value
);
6790 undeclared_variable (c_parser_peek_token (parser
)->value
,
6791 c_parser_peek_token (parser
)->location
);
6792 else if (t
== error_mark_node
)
6796 tree u
= build_omp_clause (kind
);
6797 OMP_CLAUSE_DECL (u
) = t
;
6798 OMP_CLAUSE_CHAIN (u
) = list
;
6802 list
= tree_cons (t
, NULL_TREE
, list
);
6804 c_parser_consume_token (parser
);
6806 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
6809 c_parser_consume_token (parser
);
6815 /* Similarly, but expect leading and trailing parenthesis. This is a very
6816 common case for omp clauses. */
6819 c_parser_omp_var_list_parens (c_parser
*parser
, enum omp_clause_code kind
,
6822 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6824 list
= c_parser_omp_variable_list (parser
, kind
, list
);
6825 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6831 collapse ( constant-expression ) */
6834 c_parser_omp_clause_collapse (c_parser
*parser
, tree list
)
6836 tree c
, num
= error_mark_node
;
6840 check_no_duplicate_clause (list
, OMP_CLAUSE_COLLAPSE
, "collapse");
6842 loc
= c_parser_peek_token (parser
)->location
;
6843 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6845 num
= c_parser_expr_no_commas (parser
, NULL
).value
;
6846 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6848 if (num
== error_mark_node
)
6850 if (!INTEGRAL_TYPE_P (TREE_TYPE (num
))
6851 || !host_integerp (num
, 0)
6852 || (n
= tree_low_cst (num
, 0)) <= 0
6855 error ("%Hcollapse argument needs positive constant integer expression",
6859 c
= build_omp_clause (OMP_CLAUSE_COLLAPSE
);
6860 OMP_CLAUSE_COLLAPSE_EXPR (c
) = num
;
6861 OMP_CLAUSE_CHAIN (c
) = list
;
6866 copyin ( variable-list ) */
6869 c_parser_omp_clause_copyin (c_parser
*parser
, tree list
)
6871 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYIN
, list
);
6875 copyprivate ( variable-list ) */
6878 c_parser_omp_clause_copyprivate (c_parser
*parser
, tree list
)
6880 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYPRIVATE
, list
);
6884 default ( shared | none ) */
6887 c_parser_omp_clause_default (c_parser
*parser
, tree list
)
6889 enum omp_clause_default_kind kind
= OMP_CLAUSE_DEFAULT_UNSPECIFIED
;
6892 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6894 if (c_parser_next_token_is (parser
, CPP_NAME
))
6896 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
6901 if (strcmp ("none", p
) != 0)
6903 kind
= OMP_CLAUSE_DEFAULT_NONE
;
6907 if (strcmp ("shared", p
) != 0)
6909 kind
= OMP_CLAUSE_DEFAULT_SHARED
;
6916 c_parser_consume_token (parser
);
6921 c_parser_error (parser
, "expected %<none%> or %<shared%>");
6923 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6925 if (kind
== OMP_CLAUSE_DEFAULT_UNSPECIFIED
)
6928 check_no_duplicate_clause (list
, OMP_CLAUSE_DEFAULT
, "default");
6929 c
= build_omp_clause (OMP_CLAUSE_DEFAULT
);
6930 OMP_CLAUSE_CHAIN (c
) = list
;
6931 OMP_CLAUSE_DEFAULT_KIND (c
) = kind
;
6937 firstprivate ( variable-list ) */
6940 c_parser_omp_clause_firstprivate (c_parser
*parser
, tree list
)
6942 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FIRSTPRIVATE
, list
);
6946 if ( expression ) */
6949 c_parser_omp_clause_if (c_parser
*parser
, tree list
)
6951 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
6953 tree t
= c_parser_paren_condition (parser
);
6956 check_no_duplicate_clause (list
, OMP_CLAUSE_IF
, "if");
6958 c
= build_omp_clause (OMP_CLAUSE_IF
);
6959 OMP_CLAUSE_IF_EXPR (c
) = t
;
6960 OMP_CLAUSE_CHAIN (c
) = list
;
6964 c_parser_error (parser
, "expected %<(%>");
6970 lastprivate ( variable-list ) */
6973 c_parser_omp_clause_lastprivate (c_parser
*parser
, tree list
)
6975 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_LASTPRIVATE
, list
);
6982 c_parser_omp_clause_nowait (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
6986 check_no_duplicate_clause (list
, OMP_CLAUSE_NOWAIT
, "nowait");
6988 c
= build_omp_clause (OMP_CLAUSE_NOWAIT
);
6989 OMP_CLAUSE_CHAIN (c
) = list
;
6994 num_threads ( expression ) */
6997 c_parser_omp_clause_num_threads (c_parser
*parser
, tree list
)
6999 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7001 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
7002 tree c
, t
= c_parser_expression (parser
).value
;
7004 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7006 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
7008 c_parser_error (parser
, "expected integer expression");
7012 /* Attempt to statically determine when the number isn't positive. */
7013 c
= fold_build2 (LE_EXPR
, boolean_type_node
, t
,
7014 build_int_cst (TREE_TYPE (t
), 0));
7015 if (c
== boolean_true_node
)
7017 warning (0, "%H%<num_threads%> value must be positive", &expr_loc
);
7018 t
= integer_one_node
;
7021 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_THREADS
, "num_threads");
7023 c
= build_omp_clause (OMP_CLAUSE_NUM_THREADS
);
7024 OMP_CLAUSE_NUM_THREADS_EXPR (c
) = t
;
7025 OMP_CLAUSE_CHAIN (c
) = list
;
7036 c_parser_omp_clause_ordered (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
7040 check_no_duplicate_clause (list
, OMP_CLAUSE_ORDERED
, "ordered");
7042 c
= build_omp_clause (OMP_CLAUSE_ORDERED
);
7043 OMP_CLAUSE_CHAIN (c
) = list
;
7048 private ( variable-list ) */
7051 c_parser_omp_clause_private (c_parser
*parser
, tree list
)
7053 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_PRIVATE
, list
);
7057 reduction ( reduction-operator : variable-list )
7060 One of: + * - & ^ | && || */
7063 c_parser_omp_clause_reduction (c_parser
*parser
, tree list
)
7065 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7067 enum tree_code code
;
7069 switch (c_parser_peek_token (parser
)->type
)
7081 code
= BIT_AND_EXPR
;
7084 code
= BIT_XOR_EXPR
;
7087 code
= BIT_IOR_EXPR
;
7090 code
= TRUTH_ANDIF_EXPR
;
7093 code
= TRUTH_ORIF_EXPR
;
7096 c_parser_error (parser
,
7097 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
7098 "%<^%>, %<|%>, %<&&%>, or %<||%>");
7099 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
7102 c_parser_consume_token (parser
);
7103 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
7107 nl
= c_parser_omp_variable_list (parser
, OMP_CLAUSE_REDUCTION
, list
);
7108 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
7109 OMP_CLAUSE_REDUCTION_CODE (c
) = code
;
7113 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7119 schedule ( schedule-kind )
7120 schedule ( schedule-kind , expression )
7123 static | dynamic | guided | runtime | auto
7127 c_parser_omp_clause_schedule (c_parser
*parser
, tree list
)
7131 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7134 c
= build_omp_clause (OMP_CLAUSE_SCHEDULE
);
7136 if (c_parser_next_token_is (parser
, CPP_NAME
))
7138 tree kind
= c_parser_peek_token (parser
)->value
;
7139 const char *p
= IDENTIFIER_POINTER (kind
);
7144 if (strcmp ("dynamic", p
) != 0)
7146 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_DYNAMIC
;
7150 if (strcmp ("guided", p
) != 0)
7152 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_GUIDED
;
7156 if (strcmp ("runtime", p
) != 0)
7158 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_RUNTIME
;
7165 else if (c_parser_next_token_is_keyword (parser
, RID_STATIC
))
7166 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_STATIC
;
7167 else if (c_parser_next_token_is_keyword (parser
, RID_AUTO
))
7168 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_AUTO
;
7172 c_parser_consume_token (parser
);
7173 if (c_parser_next_token_is (parser
, CPP_COMMA
))
7176 c_parser_consume_token (parser
);
7178 here
= c_parser_peek_token (parser
)->location
;
7179 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
7181 if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_RUNTIME
)
7182 error ("%Hschedule %<runtime%> does not take "
7183 "a %<chunk_size%> parameter", &here
);
7184 else if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_AUTO
)
7185 error ("%Hschedule %<auto%> does not take "
7186 "a %<chunk_size%> parameter", &here
);
7187 else if (TREE_CODE (TREE_TYPE (t
)) == INTEGER_TYPE
)
7188 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
) = t
;
7190 c_parser_error (parser
, "expected integer expression");
7192 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7195 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7196 "expected %<,%> or %<)%>");
7198 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
7199 OMP_CLAUSE_CHAIN (c
) = list
;
7203 c_parser_error (parser
, "invalid schedule kind");
7204 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
7209 shared ( variable-list ) */
7212 c_parser_omp_clause_shared (c_parser
*parser
, tree list
)
7214 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_SHARED
, list
);
7221 c_parser_omp_clause_untied (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
7225 /* FIXME: Should we allow duplicates? */
7226 check_no_duplicate_clause (list
, OMP_CLAUSE_UNTIED
, "untied");
7228 c
= build_omp_clause (OMP_CLAUSE_UNTIED
);
7229 OMP_CLAUSE_CHAIN (c
) = list
;
7233 /* Parse all OpenMP clauses. The set clauses allowed by the directive
7234 is a bitmask in MASK. Return the list of clauses found; the result
7235 of clause default goes in *pdefault. */
7238 c_parser_omp_all_clauses (c_parser
*parser
, unsigned int mask
,
7241 tree clauses
= NULL
;
7244 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
7247 pragma_omp_clause c_kind
;
7249 tree prev
= clauses
;
7251 if (!first
&& c_parser_next_token_is (parser
, CPP_COMMA
))
7252 c_parser_consume_token (parser
);
7255 here
= c_parser_peek_token (parser
)->location
;
7256 c_kind
= c_parser_omp_clause_name (parser
);
7260 case PRAGMA_OMP_CLAUSE_COLLAPSE
:
7261 clauses
= c_parser_omp_clause_collapse (parser
, clauses
);
7262 c_name
= "collapse";
7264 case PRAGMA_OMP_CLAUSE_COPYIN
:
7265 clauses
= c_parser_omp_clause_copyin (parser
, clauses
);
7268 case PRAGMA_OMP_CLAUSE_COPYPRIVATE
:
7269 clauses
= c_parser_omp_clause_copyprivate (parser
, clauses
);
7270 c_name
= "copyprivate";
7272 case PRAGMA_OMP_CLAUSE_DEFAULT
:
7273 clauses
= c_parser_omp_clause_default (parser
, clauses
);
7276 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
:
7277 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
7278 c_name
= "firstprivate";
7280 case PRAGMA_OMP_CLAUSE_IF
:
7281 clauses
= c_parser_omp_clause_if (parser
, clauses
);
7284 case PRAGMA_OMP_CLAUSE_LASTPRIVATE
:
7285 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
7286 c_name
= "lastprivate";
7288 case PRAGMA_OMP_CLAUSE_NOWAIT
:
7289 clauses
= c_parser_omp_clause_nowait (parser
, clauses
);
7292 case PRAGMA_OMP_CLAUSE_NUM_THREADS
:
7293 clauses
= c_parser_omp_clause_num_threads (parser
, clauses
);
7294 c_name
= "num_threads";
7296 case PRAGMA_OMP_CLAUSE_ORDERED
:
7297 clauses
= c_parser_omp_clause_ordered (parser
, clauses
);
7300 case PRAGMA_OMP_CLAUSE_PRIVATE
:
7301 clauses
= c_parser_omp_clause_private (parser
, clauses
);
7304 case PRAGMA_OMP_CLAUSE_REDUCTION
:
7305 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
7306 c_name
= "reduction";
7308 case PRAGMA_OMP_CLAUSE_SCHEDULE
:
7309 clauses
= c_parser_omp_clause_schedule (parser
, clauses
);
7310 c_name
= "schedule";
7312 case PRAGMA_OMP_CLAUSE_SHARED
:
7313 clauses
= c_parser_omp_clause_shared (parser
, clauses
);
7316 case PRAGMA_OMP_CLAUSE_UNTIED
:
7317 clauses
= c_parser_omp_clause_untied (parser
, clauses
);
7321 c_parser_error (parser
, "expected %<#pragma omp%> clause");
7325 if (((mask
>> c_kind
) & 1) == 0 && !parser
->error
)
7327 /* Remove the invalid clause(s) from the list to avoid
7328 confusing the rest of the compiler. */
7330 error ("%H%qs is not valid for %qs", &here
, c_name
, where
);
7335 c_parser_skip_to_pragma_eol (parser
);
7337 return c_finish_omp_clauses (clauses
);
7344 In practice, we're also interested in adding the statement to an
7345 outer node. So it is convenient if we work around the fact that
7346 c_parser_statement calls add_stmt. */
7349 c_parser_omp_structured_block (c_parser
*parser
)
7351 tree stmt
= push_stmt_list ();
7352 c_parser_statement (parser
);
7353 return pop_stmt_list (stmt
);
7357 # pragma omp atomic new-line
7361 x binop= expr | x++ | ++x | x-- | --x
7363 +, *, -, /, &, ^, |, <<, >>
7365 where x is an lvalue expression with scalar type. */
7368 c_parser_omp_atomic (c_parser
*parser
)
7372 enum tree_code code
;
7373 struct c_expr rhs_expr
;
7375 c_parser_skip_to_pragma_eol (parser
);
7377 lhs
= c_parser_unary_expression (parser
).value
;
7378 switch (TREE_CODE (lhs
))
7382 c_parser_skip_to_end_of_block_or_statement (parser
);
7385 case PREINCREMENT_EXPR
:
7386 case POSTINCREMENT_EXPR
:
7387 lhs
= TREE_OPERAND (lhs
, 0);
7389 rhs
= integer_one_node
;
7392 case PREDECREMENT_EXPR
:
7393 case POSTDECREMENT_EXPR
:
7394 lhs
= TREE_OPERAND (lhs
, 0);
7396 rhs
= integer_one_node
;
7400 switch (c_parser_peek_token (parser
)->type
)
7406 code
= TRUNC_DIV_EXPR
;
7421 code
= BIT_AND_EXPR
;
7424 code
= BIT_IOR_EXPR
;
7427 code
= BIT_XOR_EXPR
;
7430 c_parser_error (parser
,
7431 "invalid operator for %<#pragma omp atomic%>");
7435 c_parser_consume_token (parser
);
7436 rhs_expr
= c_parser_expression (parser
);
7437 rhs_expr
= default_function_array_conversion (rhs_expr
);
7438 rhs
= rhs_expr
.value
;
7441 stmt
= c_finish_omp_atomic (code
, lhs
, rhs
);
7442 if (stmt
!= error_mark_node
)
7444 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7449 # pragma omp barrier new-line
7453 c_parser_omp_barrier (c_parser
*parser
)
7455 c_parser_consume_pragma (parser
);
7456 c_parser_skip_to_pragma_eol (parser
);
7458 c_finish_omp_barrier ();
7462 # pragma omp critical [(name)] new-line
7467 c_parser_omp_critical (c_parser
*parser
)
7469 tree stmt
, name
= NULL
;
7471 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
7473 c_parser_consume_token (parser
);
7474 if (c_parser_next_token_is (parser
, CPP_NAME
))
7476 name
= c_parser_peek_token (parser
)->value
;
7477 c_parser_consume_token (parser
);
7478 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7481 c_parser_error (parser
, "expected identifier");
7483 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
7484 c_parser_error (parser
, "expected %<(%> or end of line");
7485 c_parser_skip_to_pragma_eol (parser
);
7487 stmt
= c_parser_omp_structured_block (parser
);
7488 return c_finish_omp_critical (stmt
, name
);
7492 # pragma omp flush flush-vars[opt] new-line
7495 ( variable-list ) */
7498 c_parser_omp_flush (c_parser
*parser
)
7500 c_parser_consume_pragma (parser
);
7501 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
7502 c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
7503 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
7504 c_parser_error (parser
, "expected %<(%> or end of line");
7505 c_parser_skip_to_pragma_eol (parser
);
7507 c_finish_omp_flush ();
7510 /* Parse the restricted form of the for statement allowed by OpenMP.
7511 The real trick here is to determine the loop control variable early
7512 so that we can push a new decl if necessary to make it private. */
7515 c_parser_omp_for_loop (c_parser
*parser
, tree clauses
, tree
*par_clauses
)
7517 tree decl
, cond
, incr
, save_break
, save_cont
, body
, init
, stmt
, cl
;
7518 tree declv
, condv
, incrv
, initv
, for_block
= NULL
, ret
= NULL
;
7520 bool fail
= false, open_brace_parsed
= false;
7521 int i
, collapse
= 1, nbraces
= 0;
7523 for (cl
= clauses
; cl
; cl
= OMP_CLAUSE_CHAIN (cl
))
7524 if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_COLLAPSE
)
7525 collapse
= tree_low_cst (OMP_CLAUSE_COLLAPSE_EXPR (cl
), 0);
7527 gcc_assert (collapse
>= 1);
7529 declv
= make_tree_vec (collapse
);
7530 initv
= make_tree_vec (collapse
);
7531 condv
= make_tree_vec (collapse
);
7532 incrv
= make_tree_vec (collapse
);
7534 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
))
7536 c_parser_error (parser
, "for statement expected");
7539 loc
= c_parser_peek_token (parser
)->location
;
7540 c_parser_consume_token (parser
);
7542 for (i
= 0; i
< collapse
; i
++)
7546 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7549 /* Parse the initialization declaration or expression. */
7550 if (c_parser_next_token_starts_declspecs (parser
))
7554 = tree_cons (NULL
, c_begin_compound_stmt (true), for_block
);
7555 c_parser_declaration_or_fndef (parser
, true, true, true, true);
7556 decl
= check_for_loop_decls ();
7559 if (DECL_INITIAL (decl
) == error_mark_node
)
7560 decl
= error_mark_node
;
7563 else if (c_parser_next_token_is (parser
, CPP_NAME
)
7564 && c_parser_peek_2nd_token (parser
)->type
== CPP_EQ
)
7566 struct c_expr init_exp
;
7568 decl
= c_parser_postfix_expression (parser
).value
;
7570 c_parser_require (parser
, CPP_EQ
, "expected %<=%>");
7572 init_exp
= c_parser_expr_no_commas (parser
, NULL
);
7573 init_exp
= default_function_array_conversion (init_exp
);
7574 init
= build_modify_expr (decl
, NOP_EXPR
, init_exp
.value
);
7575 init
= c_process_expr_stmt (init
);
7577 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7582 c_parser_error (parser
,
7583 "expected iteration declaration or initialization");
7584 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7590 /* Parse the loop condition. */
7592 if (c_parser_next_token_is_not (parser
, CPP_SEMICOLON
))
7594 cond
= c_parser_expression_conv (parser
).value
;
7595 cond
= c_objc_common_truthvalue_conversion (cond
);
7596 if (CAN_HAVE_LOCATION_P (cond
))
7597 SET_EXPR_LOCATION (cond
, input_location
);
7599 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7601 /* Parse the increment expression. */
7603 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_PAREN
))
7604 incr
= c_process_expr_stmt (c_parser_expression (parser
).value
);
7605 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7607 if (decl
== NULL
|| decl
== error_mark_node
|| init
== error_mark_node
)
7611 TREE_VEC_ELT (declv
, i
) = decl
;
7612 TREE_VEC_ELT (initv
, i
) = init
;
7613 TREE_VEC_ELT (condv
, i
) = cond
;
7614 TREE_VEC_ELT (incrv
, i
) = incr
;
7618 if (i
== collapse
- 1)
7621 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
7622 in between the collapsed for loops to be still considered perfectly
7623 nested. Hopefully the final version clarifies this.
7624 For now handle (multiple) {'s and empty statements. */
7627 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
7629 c_parser_consume_token (parser
);
7632 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
7634 c_parser_consume_token (parser
);
7638 && c_parser_next_token_is (parser
, CPP_SEMICOLON
))
7639 c_parser_consume_token (parser
);
7642 c_parser_error (parser
, "not enough perfectly nested loops");
7645 open_brace_parsed
= true;
7655 nbraces
+= bracecount
;
7658 save_break
= c_break_label
;
7659 c_break_label
= size_one_node
;
7660 save_cont
= c_cont_label
;
7661 c_cont_label
= NULL_TREE
;
7662 body
= push_stmt_list ();
7664 if (open_brace_parsed
)
7666 stmt
= c_begin_compound_stmt (true);
7667 c_parser_compound_statement_nostart (parser
);
7668 add_stmt (c_end_compound_stmt (stmt
, true));
7671 add_stmt (c_parser_c99_block_statement (parser
));
7673 add_stmt (build1 (LABEL_EXPR
, void_type_node
, c_cont_label
));
7675 body
= pop_stmt_list (body
);
7676 c_break_label
= save_break
;
7677 c_cont_label
= save_cont
;
7681 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
7683 c_parser_consume_token (parser
);
7686 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
7687 c_parser_consume_token (parser
);
7690 c_parser_error (parser
, "collapsed loops not perfectly nested");
7693 stmt
= c_begin_compound_stmt (true);
7695 c_parser_compound_statement_nostart (parser
);
7696 body
= c_end_compound_stmt (stmt
, true);
7703 /* Only bother calling c_finish_omp_for if we haven't already generated
7704 an error from the initialization parsing. */
7707 stmt
= c_finish_omp_for (loc
, declv
, initv
, condv
, incrv
, body
, NULL
);
7710 if (par_clauses
!= NULL
)
7713 for (c
= par_clauses
; *c
; )
7714 if (OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_FIRSTPRIVATE
7715 && OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_LASTPRIVATE
)
7716 c
= &OMP_CLAUSE_CHAIN (*c
);
7719 for (i
= 0; i
< collapse
; i
++)
7720 if (TREE_VEC_ELT (declv
, i
) == OMP_CLAUSE_DECL (*c
))
7723 c
= &OMP_CLAUSE_CHAIN (*c
);
7724 else if (OMP_CLAUSE_CODE (*c
) == OMP_CLAUSE_FIRSTPRIVATE
)
7726 error ("%Hiteration variable %qD should not be firstprivate",
7727 &loc
, OMP_CLAUSE_DECL (*c
));
7728 *c
= OMP_CLAUSE_CHAIN (*c
);
7732 /* Copy lastprivate (decl) clause to OMP_FOR_CLAUSES,
7733 change it to shared (decl) in
7734 OMP_PARALLEL_CLAUSES. */
7735 tree l
= build_omp_clause (OMP_CLAUSE_LASTPRIVATE
);
7736 OMP_CLAUSE_DECL (l
) = OMP_CLAUSE_DECL (*c
);
7737 OMP_CLAUSE_CHAIN (l
) = clauses
;
7739 OMP_CLAUSE_SET_CODE (*c
, OMP_CLAUSE_SHARED
);
7743 OMP_FOR_CLAUSES (stmt
) = clauses
;
7750 stmt
= c_end_compound_stmt (TREE_VALUE (for_block
), true);
7752 for_block
= TREE_CHAIN (for_block
);
7758 #pragma omp for for-clause[optseq] new-line
7762 #define OMP_FOR_CLAUSE_MASK \
7763 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
7764 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
7765 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
7766 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
7767 | (1u << PRAGMA_OMP_CLAUSE_ORDERED) \
7768 | (1u << PRAGMA_OMP_CLAUSE_SCHEDULE) \
7769 | (1u << PRAGMA_OMP_CLAUSE_COLLAPSE) \
7770 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
7773 c_parser_omp_for (c_parser
*parser
)
7775 tree block
, clauses
, ret
;
7777 clauses
= c_parser_omp_all_clauses (parser
, OMP_FOR_CLAUSE_MASK
,
7780 block
= c_begin_compound_stmt (true);
7781 ret
= c_parser_omp_for_loop (parser
, clauses
, NULL
);
7782 block
= c_end_compound_stmt (block
, true);
7789 # pragma omp master new-line
7794 c_parser_omp_master (c_parser
*parser
)
7796 c_parser_skip_to_pragma_eol (parser
);
7797 return c_finish_omp_master (c_parser_omp_structured_block (parser
));
7801 # pragma omp ordered new-line
7806 c_parser_omp_ordered (c_parser
*parser
)
7808 c_parser_skip_to_pragma_eol (parser
);
7809 return c_finish_omp_ordered (c_parser_omp_structured_block (parser
));
7815 { section-sequence }
7818 section-directive[opt] structured-block
7819 section-sequence section-directive structured-block */
7822 c_parser_omp_sections_scope (c_parser
*parser
)
7825 bool error_suppress
= false;
7828 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
7830 /* Avoid skipping until the end of the block. */
7831 parser
->error
= false;
7835 stmt
= push_stmt_list ();
7837 loc
= c_parser_peek_token (parser
)->location
;
7838 if (c_parser_peek_token (parser
)->pragma_kind
!= PRAGMA_OMP_SECTION
)
7840 substmt
= push_stmt_list ();
7844 c_parser_statement (parser
);
7846 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
7848 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
7850 if (c_parser_next_token_is (parser
, CPP_EOF
))
7854 substmt
= pop_stmt_list (substmt
);
7855 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
7856 SET_EXPR_LOCATION (substmt
, loc
);
7862 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
7864 if (c_parser_next_token_is (parser
, CPP_EOF
))
7867 loc
= c_parser_peek_token (parser
)->location
;
7868 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
7870 c_parser_consume_pragma (parser
);
7871 c_parser_skip_to_pragma_eol (parser
);
7872 error_suppress
= false;
7874 else if (!error_suppress
)
7876 error ("%Hexpected %<#pragma omp section%> or %<}%>",
7878 error_suppress
= true;
7881 substmt
= c_parser_omp_structured_block (parser
);
7882 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
7883 SET_EXPR_LOCATION (substmt
, loc
);
7886 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
,
7887 "expected %<#pragma omp section%> or %<}%>");
7889 substmt
= pop_stmt_list (stmt
);
7891 stmt
= make_node (OMP_SECTIONS
);
7892 TREE_TYPE (stmt
) = void_type_node
;
7893 OMP_SECTIONS_BODY (stmt
) = substmt
;
7895 return add_stmt (stmt
);
7899 # pragma omp sections sections-clause[optseq] newline
7903 #define OMP_SECTIONS_CLAUSE_MASK \
7904 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
7905 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
7906 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
7907 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
7908 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
7911 c_parser_omp_sections (c_parser
*parser
)
7913 tree block
, clauses
, ret
;
7915 clauses
= c_parser_omp_all_clauses (parser
, OMP_SECTIONS_CLAUSE_MASK
,
7916 "#pragma omp sections");
7918 block
= c_begin_compound_stmt (true);
7919 ret
= c_parser_omp_sections_scope (parser
);
7921 OMP_SECTIONS_CLAUSES (ret
) = clauses
;
7922 block
= c_end_compound_stmt (block
, true);
7929 # pragma parallel parallel-clause new-line
7930 # pragma parallel for parallel-for-clause new-line
7931 # pragma parallel sections parallel-sections-clause new-line
7934 #define OMP_PARALLEL_CLAUSE_MASK \
7935 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
7936 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
7937 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
7938 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
7939 | (1u << PRAGMA_OMP_CLAUSE_SHARED) \
7940 | (1u << PRAGMA_OMP_CLAUSE_COPYIN) \
7941 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
7942 | (1u << PRAGMA_OMP_CLAUSE_NUM_THREADS))
7945 c_parser_omp_parallel (c_parser
*parser
)
7947 enum pragma_kind p_kind
= PRAGMA_OMP_PARALLEL
;
7948 const char *p_name
= "#pragma omp parallel";
7949 tree stmt
, clauses
, par_clause
, ws_clause
, block
;
7950 unsigned int mask
= OMP_PARALLEL_CLAUSE_MASK
;
7952 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
7954 c_parser_consume_token (parser
);
7955 p_kind
= PRAGMA_OMP_PARALLEL_FOR
;
7956 p_name
= "#pragma omp parallel for";
7957 mask
|= OMP_FOR_CLAUSE_MASK
;
7958 mask
&= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT
);
7960 else if (c_parser_next_token_is (parser
, CPP_NAME
))
7962 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
7963 if (strcmp (p
, "sections") == 0)
7965 c_parser_consume_token (parser
);
7966 p_kind
= PRAGMA_OMP_PARALLEL_SECTIONS
;
7967 p_name
= "#pragma omp parallel sections";
7968 mask
|= OMP_SECTIONS_CLAUSE_MASK
;
7969 mask
&= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT
);
7973 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
);
7977 case PRAGMA_OMP_PARALLEL
:
7978 block
= c_begin_omp_parallel ();
7979 c_parser_statement (parser
);
7980 stmt
= c_finish_omp_parallel (clauses
, block
);
7983 case PRAGMA_OMP_PARALLEL_FOR
:
7984 block
= c_begin_omp_parallel ();
7985 c_split_parallel_clauses (clauses
, &par_clause
, &ws_clause
);
7986 c_parser_omp_for_loop (parser
, ws_clause
, &par_clause
);
7987 stmt
= c_finish_omp_parallel (par_clause
, block
);
7988 OMP_PARALLEL_COMBINED (stmt
) = 1;
7991 case PRAGMA_OMP_PARALLEL_SECTIONS
:
7992 block
= c_begin_omp_parallel ();
7993 c_split_parallel_clauses (clauses
, &par_clause
, &ws_clause
);
7994 stmt
= c_parser_omp_sections_scope (parser
);
7996 OMP_SECTIONS_CLAUSES (stmt
) = ws_clause
;
7997 stmt
= c_finish_omp_parallel (par_clause
, block
);
7998 OMP_PARALLEL_COMBINED (stmt
) = 1;
8009 # pragma omp single single-clause[optseq] new-line
8013 #define OMP_SINGLE_CLAUSE_MASK \
8014 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8015 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8016 | (1u << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
8017 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
8020 c_parser_omp_single (c_parser
*parser
)
8022 tree stmt
= make_node (OMP_SINGLE
);
8023 TREE_TYPE (stmt
) = void_type_node
;
8025 OMP_SINGLE_CLAUSES (stmt
)
8026 = c_parser_omp_all_clauses (parser
, OMP_SINGLE_CLAUSE_MASK
,
8027 "#pragma omp single");
8028 OMP_SINGLE_BODY (stmt
) = c_parser_omp_structured_block (parser
);
8030 return add_stmt (stmt
);
8034 # pragma omp task task-clause[optseq] new-line
8037 #define OMP_TASK_CLAUSE_MASK \
8038 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
8039 | (1u << PRAGMA_OMP_CLAUSE_UNTIED) \
8040 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
8041 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8042 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8043 | (1u << PRAGMA_OMP_CLAUSE_SHARED))
8046 c_parser_omp_task (c_parser
*parser
)
8048 tree clauses
, block
;
8050 clauses
= c_parser_omp_all_clauses (parser
, OMP_TASK_CLAUSE_MASK
,
8051 "#pragma omp task");
8053 block
= c_begin_omp_task ();
8054 c_parser_statement (parser
);
8055 return c_finish_omp_task (clauses
, block
);
8059 # pragma omp taskwait new-line
8063 c_parser_omp_taskwait (c_parser
*parser
)
8065 c_parser_consume_pragma (parser
);
8066 c_parser_skip_to_pragma_eol (parser
);
8068 c_finish_omp_taskwait ();
8071 /* Main entry point to parsing most OpenMP pragmas. */
8074 c_parser_omp_construct (c_parser
*parser
)
8076 enum pragma_kind p_kind
;
8080 loc
= c_parser_peek_token (parser
)->location
;
8081 p_kind
= c_parser_peek_token (parser
)->pragma_kind
;
8082 c_parser_consume_pragma (parser
);
8084 /* For all constructs below except #pragma omp atomic
8085 MUST_NOT_THROW catch handlers are needed when exceptions
8087 if (p_kind
!= PRAGMA_OMP_ATOMIC
)
8088 c_maybe_initialize_eh ();
8092 case PRAGMA_OMP_ATOMIC
:
8093 c_parser_omp_atomic (parser
);
8095 case PRAGMA_OMP_CRITICAL
:
8096 stmt
= c_parser_omp_critical (parser
);
8098 case PRAGMA_OMP_FOR
:
8099 stmt
= c_parser_omp_for (parser
);
8101 case PRAGMA_OMP_MASTER
:
8102 stmt
= c_parser_omp_master (parser
);
8104 case PRAGMA_OMP_ORDERED
:
8105 stmt
= c_parser_omp_ordered (parser
);
8107 case PRAGMA_OMP_PARALLEL
:
8108 stmt
= c_parser_omp_parallel (parser
);
8110 case PRAGMA_OMP_SECTIONS
:
8111 stmt
= c_parser_omp_sections (parser
);
8113 case PRAGMA_OMP_SINGLE
:
8114 stmt
= c_parser_omp_single (parser
);
8116 case PRAGMA_OMP_TASK
:
8117 stmt
= c_parser_omp_task (parser
);
8124 SET_EXPR_LOCATION (stmt
, loc
);
8129 # pragma omp threadprivate (variable-list) */
8132 c_parser_omp_threadprivate (c_parser
*parser
)
8136 c_parser_consume_pragma (parser
);
8137 vars
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
8139 /* Mark every variable in VARS to be assigned thread local storage. */
8140 for (t
= vars
; t
; t
= TREE_CHAIN (t
))
8142 tree v
= TREE_PURPOSE (t
);
8144 /* If V had already been marked threadprivate, it doesn't matter
8145 whether it had been used prior to this point. */
8146 if (TREE_CODE (v
) != VAR_DECL
)
8147 error ("%qD is not a variable", v
);
8148 else if (TREE_USED (v
) && !C_DECL_THREADPRIVATE_P (v
))
8149 error ("%qE declared %<threadprivate%> after first use", v
);
8150 else if (! TREE_STATIC (v
) && ! DECL_EXTERNAL (v
))
8151 error ("automatic variable %qE cannot be %<threadprivate%>", v
);
8152 else if (TREE_TYPE (v
) == error_mark_node
)
8154 else if (! COMPLETE_TYPE_P (TREE_TYPE (v
)))
8155 error ("%<threadprivate%> %qE has incomplete type", v
);
8158 if (! DECL_THREAD_LOCAL_P (v
))
8160 DECL_TLS_MODEL (v
) = decl_default_tls_model (v
);
8161 /* If rtl has been already set for this var, call
8162 make_decl_rtl once again, so that encode_section_info
8163 has a chance to look at the new decl flags. */
8164 if (DECL_RTL_SET_P (v
))
8167 C_DECL_THREADPRIVATE_P (v
) = 1;
8171 c_parser_skip_to_pragma_eol (parser
);
8175 /* Parse a single source file. */
8180 /* Use local storage to begin. If the first token is a pragma, parse it.
8181 If it is #pragma GCC pch_preprocess, then this will load a PCH file
8182 which will cause garbage collection. */
8185 memset (&tparser
, 0, sizeof tparser
);
8186 the_parser
= &tparser
;
8188 if (c_parser_peek_token (&tparser
)->pragma_kind
== PRAGMA_GCC_PCH_PREPROCESS
)
8189 c_parser_pragma_pch_preprocess (&tparser
);
8191 the_parser
= GGC_NEW (c_parser
);
8192 *the_parser
= tparser
;
8194 c_parser_translation_unit (the_parser
);
8198 #include "gt-c-parser.h"