1 /* Parser for C and Objective-C.
2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009
4 Free Software Foundation, Inc.
6 Parser actions based on the old Bison parser; structure somewhat
7 influenced by and fragments based on the C++ parser.
9 This file is part of GCC.
11 GCC is free software; you can redistribute it and/or modify it under
12 the terms of the GNU General Public License as published by the Free
13 Software Foundation; either version 3, or (at your option) any later
16 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
17 WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with GCC; see the file COPYING3. If not see
23 <http://www.gnu.org/licenses/>. */
27 Make sure all relevant comments, and all relevant code from all
28 actions, brought over from old parser. Verify exact correspondence
31 Add testcases covering every input symbol in every state in old and
34 Include full syntax for GNU C, including erroneous cases accepted
35 with error messages, in syntax productions in comments.
37 Make more diagnostics in the front end generally take an explicit
38 location rather than implicitly using input_location. */
42 #include "coretypes.h"
46 #include "langhooks.h"
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
: 8;
152 /* The value associated with this token, if any. */
154 /* The location at which this token was found. */
158 /* A parser structure recording information about the state and
159 context of parsing. Includes lexer information with up to two
160 tokens of look-ahead; more are not needed for C. */
161 typedef struct c_parser
GTY(())
163 /* The look-ahead tokens. */
165 /* How many look-ahead tokens are available (0, 1 or 2). */
167 /* True if a syntax error is being recovered from; false otherwise.
168 c_parser_error sets this flag. It should clear this flag when
169 enough tokens have been consumed to recover from the error. */
170 BOOL_BITFIELD error
: 1;
171 /* True if we're processing a pragma, and shouldn't automatically
172 consume CPP_PRAGMA_EOL. */
173 BOOL_BITFIELD in_pragma
: 1;
174 /* True if we're parsing the outermost block of an if statement. */
175 BOOL_BITFIELD in_if_block
: 1;
176 /* True if we want to lex an untranslated string. */
177 BOOL_BITFIELD lex_untranslated_string
: 1;
178 /* Objective-C specific parser/lexer information. */
179 BOOL_BITFIELD objc_pq_context
: 1;
180 /* The following flag is needed to contextualize Objective-C lexical
181 analysis. In some cases (e.g., 'int NSObject;'), it is
182 undesirable to bind an identifier to an Objective-C class, even
183 if a class with that name exists. */
184 BOOL_BITFIELD objc_need_raw_identifier
: 1;
188 /* The actual parser and external interface. ??? Does this need to be
189 garbage-collected? */
191 static GTY (()) c_parser
*the_parser
;
194 /* Read in and lex a single token, storing it in *TOKEN. */
197 c_lex_one_token (c_parser
*parser
, c_token
*token
)
199 timevar_push (TV_LEX
);
201 token
->type
= c_lex_with_flags (&token
->value
, &token
->location
, NULL
,
202 (parser
->lex_untranslated_string
203 ? C_LEX_STRING_NO_TRANSLATE
: 0));
204 token
->id_kind
= C_ID_NONE
;
205 token
->keyword
= RID_MAX
;
206 token
->pragma_kind
= PRAGMA_NONE
;
214 bool objc_force_identifier
= parser
->objc_need_raw_identifier
;
215 if (c_dialect_objc ())
216 parser
->objc_need_raw_identifier
= false;
218 if (C_IS_RESERVED_WORD (token
->value
))
220 enum rid rid_code
= C_RID_CODE (token
->value
);
222 if (rid_code
== RID_CXX_COMPAT_WARN
)
224 warning_at (token
->location
,
226 "identifier %qs conflicts with C++ keyword",
227 IDENTIFIER_POINTER (token
->value
));
229 else if (c_dialect_objc ())
231 if (!objc_is_reserved_word (token
->value
)
232 && (!OBJC_IS_PQ_KEYWORD (rid_code
)
233 || parser
->objc_pq_context
))
235 /* Return the canonical spelling for this keyword. */
236 token
->value
= ridpointers
[(int) rid_code
];
237 token
->type
= CPP_KEYWORD
;
238 token
->keyword
= rid_code
;
244 token
->type
= CPP_KEYWORD
;
245 token
->keyword
= rid_code
;
250 decl
= lookup_name (token
->value
);
253 if (TREE_CODE (decl
) == TYPE_DECL
)
255 token
->id_kind
= C_ID_TYPENAME
;
259 else if (c_dialect_objc ())
261 tree objc_interface_decl
= objc_is_class_name (token
->value
);
262 /* Objective-C class names are in the same namespace as
263 variables and typedefs, and hence are shadowed by local
265 if (objc_interface_decl
266 && (global_bindings_p ()
267 || (!objc_force_identifier
&& !decl
)))
269 token
->value
= objc_interface_decl
;
270 token
->id_kind
= C_ID_CLASSNAME
;
274 token
->id_kind
= C_ID_ID
;
278 /* This only happens in Objective-C; it must be a keyword. */
279 token
->type
= CPP_KEYWORD
;
280 token
->keyword
= C_RID_CODE (token
->value
);
284 case CPP_CLOSE_PAREN
:
286 /* These tokens may affect the interpretation of any identifiers
287 following, if doing Objective-C. */
288 if (c_dialect_objc ())
289 parser
->objc_need_raw_identifier
= false;
292 /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */
293 token
->pragma_kind
= (enum pragma_kind
) TREE_INT_CST_LOW (token
->value
);
299 timevar_pop (TV_LEX
);
302 /* Return a pointer to the next token from PARSER, reading it in if
305 static inline c_token
*
306 c_parser_peek_token (c_parser
*parser
)
308 if (parser
->tokens_avail
== 0)
310 c_lex_one_token (parser
, &parser
->tokens
[0]);
311 parser
->tokens_avail
= 1;
313 return &parser
->tokens
[0];
316 /* Return true if the next token from PARSER has the indicated
320 c_parser_next_token_is (c_parser
*parser
, enum cpp_ttype type
)
322 return c_parser_peek_token (parser
)->type
== type
;
325 /* Return true if the next token from PARSER does not have the
329 c_parser_next_token_is_not (c_parser
*parser
, enum cpp_ttype type
)
331 return !c_parser_next_token_is (parser
, type
);
334 /* Return true if the next token from PARSER is the indicated
338 c_parser_next_token_is_keyword (c_parser
*parser
, enum rid keyword
)
340 return c_parser_peek_token (parser
)->keyword
== keyword
;
343 /* Return true if TOKEN can start a type name,
346 c_token_starts_typename (c_token
*token
)
351 switch (token
->id_kind
)
358 gcc_assert (c_dialect_objc ());
364 switch (token
->keyword
)
396 if (c_dialect_objc ())
404 /* Return true if the next token from PARSER can start a type name,
407 c_parser_next_token_starts_typename (c_parser
*parser
)
409 c_token
*token
= c_parser_peek_token (parser
);
410 return c_token_starts_typename (token
);
413 /* Return true if TOKEN can start declaration specifiers, false
416 c_token_starts_declspecs (c_token
*token
)
421 switch (token
->id_kind
)
428 gcc_assert (c_dialect_objc ());
434 switch (token
->keyword
)
473 if (c_dialect_objc ())
481 /* Return true if the next token from PARSER can start declaration
482 specifiers, false otherwise. */
484 c_parser_next_token_starts_declspecs (c_parser
*parser
)
486 c_token
*token
= c_parser_peek_token (parser
);
487 return c_token_starts_declspecs (token
);
490 /* Return a pointer to the next-but-one token from PARSER, reading it
491 in if necessary. The next token is already read in. */
494 c_parser_peek_2nd_token (c_parser
*parser
)
496 if (parser
->tokens_avail
>= 2)
497 return &parser
->tokens
[1];
498 gcc_assert (parser
->tokens_avail
== 1);
499 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
500 gcc_assert (parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
501 c_lex_one_token (parser
, &parser
->tokens
[1]);
502 parser
->tokens_avail
= 2;
503 return &parser
->tokens
[1];
506 /* Consume the next token from PARSER. */
509 c_parser_consume_token (c_parser
*parser
)
511 gcc_assert (parser
->tokens_avail
>= 1);
512 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
513 gcc_assert (!parser
->in_pragma
|| parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
514 gcc_assert (parser
->error
|| parser
->tokens
[0].type
!= CPP_PRAGMA
);
515 if (parser
->tokens_avail
== 2)
516 parser
->tokens
[0] = parser
->tokens
[1];
517 parser
->tokens_avail
--;
520 /* Expect the current token to be a #pragma. Consume it and remember
521 that we've begun parsing a pragma. */
524 c_parser_consume_pragma (c_parser
*parser
)
526 gcc_assert (!parser
->in_pragma
);
527 gcc_assert (parser
->tokens_avail
>= 1);
528 gcc_assert (parser
->tokens
[0].type
== CPP_PRAGMA
);
529 if (parser
->tokens_avail
== 2)
530 parser
->tokens
[0] = parser
->tokens
[1];
531 parser
->tokens_avail
--;
532 parser
->in_pragma
= true;
535 /* Update the globals input_location and in_system_header from
538 c_parser_set_source_position_from_token (c_token
*token
)
540 if (token
->type
!= CPP_EOF
)
542 input_location
= token
->location
;
546 /* Issue a diagnostic of the form
547 FILE:LINE: MESSAGE before TOKEN
548 where TOKEN is the next token in the input stream of PARSER.
549 MESSAGE (specified by the caller) is usually of the form "expected
552 Do not issue a diagnostic if still recovering from an error.
554 ??? This is taken from the C++ parser, but building up messages in
555 this way is not i18n-friendly and some other approach should be
559 c_parser_error (c_parser
*parser
, const char *gmsgid
)
561 c_token
*token
= c_parser_peek_token (parser
);
564 parser
->error
= true;
567 /* This diagnostic makes more sense if it is tagged to the line of
568 the token we just peeked at. */
569 c_parser_set_source_position_from_token (token
);
570 c_parse_error (gmsgid
,
571 /* Because c_parse_error does not understand
572 CPP_KEYWORD, keywords are treated like
574 (token
->type
== CPP_KEYWORD
? CPP_NAME
: token
->type
),
578 /* If the next token is of the indicated TYPE, consume it. Otherwise,
579 issue the error MSGID. If MSGID is NULL then a message has already
580 been produced and no message will be produced this time. Returns
581 true if found, false otherwise. */
584 c_parser_require (c_parser
*parser
,
588 if (c_parser_next_token_is (parser
, type
))
590 c_parser_consume_token (parser
);
595 c_parser_error (parser
, msgid
);
600 /* If the next token is the indicated keyword, consume it. Otherwise,
601 issue the error MSGID. Returns true if found, false otherwise. */
604 c_parser_require_keyword (c_parser
*parser
,
608 if (c_parser_next_token_is_keyword (parser
, keyword
))
610 c_parser_consume_token (parser
);
615 c_parser_error (parser
, msgid
);
620 /* Like c_parser_require, except that tokens will be skipped until the
621 desired token is found. An error message is still produced if the
622 next token is not as expected. If MSGID is NULL then a message has
623 already been produced and no message will be produced this
627 c_parser_skip_until_found (c_parser
*parser
,
631 unsigned nesting_depth
= 0;
633 if (c_parser_require (parser
, type
, msgid
))
636 /* Skip tokens until the desired token is found. */
639 /* Peek at the next token. */
640 c_token
*token
= c_parser_peek_token (parser
);
641 /* If we've reached the token we want, consume it and stop. */
642 if (token
->type
== type
&& !nesting_depth
)
644 c_parser_consume_token (parser
);
648 /* If we've run out of tokens, stop. */
649 if (token
->type
== CPP_EOF
)
651 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
653 if (token
->type
== CPP_OPEN_BRACE
654 || token
->type
== CPP_OPEN_PAREN
655 || token
->type
== CPP_OPEN_SQUARE
)
657 else if (token
->type
== CPP_CLOSE_BRACE
658 || token
->type
== CPP_CLOSE_PAREN
659 || token
->type
== CPP_CLOSE_SQUARE
)
661 if (nesting_depth
-- == 0)
664 /* Consume this token. */
665 c_parser_consume_token (parser
);
667 parser
->error
= false;
670 /* Skip tokens until the end of a parameter is found, but do not
671 consume the comma, semicolon or closing delimiter. */
674 c_parser_skip_to_end_of_parameter (c_parser
*parser
)
676 unsigned nesting_depth
= 0;
680 c_token
*token
= c_parser_peek_token (parser
);
681 if ((token
->type
== CPP_COMMA
|| token
->type
== CPP_SEMICOLON
)
684 /* If we've run out of tokens, stop. */
685 if (token
->type
== CPP_EOF
)
687 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
689 if (token
->type
== CPP_OPEN_BRACE
690 || token
->type
== CPP_OPEN_PAREN
691 || token
->type
== CPP_OPEN_SQUARE
)
693 else if (token
->type
== CPP_CLOSE_BRACE
694 || token
->type
== CPP_CLOSE_PAREN
695 || token
->type
== CPP_CLOSE_SQUARE
)
697 if (nesting_depth
-- == 0)
700 /* Consume this token. */
701 c_parser_consume_token (parser
);
703 parser
->error
= false;
706 /* Expect to be at the end of the pragma directive and consume an
707 end of line marker. */
710 c_parser_skip_to_pragma_eol (c_parser
*parser
)
712 gcc_assert (parser
->in_pragma
);
713 parser
->in_pragma
= false;
715 if (!c_parser_require (parser
, CPP_PRAGMA_EOL
, "expected end of line"))
718 c_token
*token
= c_parser_peek_token (parser
);
719 if (token
->type
== CPP_EOF
)
721 if (token
->type
== CPP_PRAGMA_EOL
)
723 c_parser_consume_token (parser
);
726 c_parser_consume_token (parser
);
729 parser
->error
= false;
732 /* Skip tokens until we have consumed an entire block, or until we
733 have consumed a non-nested ';'. */
736 c_parser_skip_to_end_of_block_or_statement (c_parser
*parser
)
738 unsigned nesting_depth
= 0;
739 bool save_error
= parser
->error
;
745 /* Peek at the next token. */
746 token
= c_parser_peek_token (parser
);
754 if (parser
->in_pragma
)
759 /* If the next token is a ';', we have reached the
760 end of the statement. */
763 /* Consume the ';'. */
764 c_parser_consume_token (parser
);
769 case CPP_CLOSE_BRACE
:
770 /* If the next token is a non-nested '}', then we have
771 reached the end of the current block. */
772 if (nesting_depth
== 0 || --nesting_depth
== 0)
774 c_parser_consume_token (parser
);
780 /* If it the next token is a '{', then we are entering a new
781 block. Consume the entire block. */
786 /* If we see a pragma, consume the whole thing at once. We
787 have some safeguards against consuming pragmas willy-nilly.
788 Normally, we'd expect to be here with parser->error set,
789 which disables these safeguards. But it's possible to get
790 here for secondary error recovery, after parser->error has
792 c_parser_consume_pragma (parser
);
793 c_parser_skip_to_pragma_eol (parser
);
794 parser
->error
= save_error
;
801 c_parser_consume_token (parser
);
805 parser
->error
= false;
808 /* CPP's options (initialized by c-opts.c). */
809 extern cpp_options
*cpp_opts
;
811 /* Save the warning flags which are controlled by __extension__. */
814 disable_extension_diagnostics (void)
817 | (warn_pointer_arith
<< 1)
818 | (warn_traditional
<< 2)
820 | (warn_long_long
<< 4)
821 | (cpp_opts
->warn_long_long
<< 5));
822 cpp_opts
->pedantic
= pedantic
= 0;
823 warn_pointer_arith
= 0;
824 cpp_opts
->warn_traditional
= warn_traditional
= 0;
827 cpp_opts
->warn_long_long
= 0;
831 /* Restore the warning flags which are controlled by __extension__.
832 FLAGS is the return value from disable_extension_diagnostics. */
835 restore_extension_diagnostics (int flags
)
837 cpp_opts
->pedantic
= pedantic
= flags
& 1;
838 warn_pointer_arith
= (flags
>> 1) & 1;
839 cpp_opts
->warn_traditional
= warn_traditional
= (flags
>> 2) & 1;
840 flag_iso
= (flags
>> 3) & 1;
841 warn_long_long
= (flags
>> 4) & 1;
842 cpp_opts
->warn_long_long
= (flags
>> 5) & 1;
845 /* Possibly kinds of declarator to parse. */
846 typedef enum c_dtr_syn
{
847 /* A normal declarator with an identifier. */
849 /* An abstract declarator (maybe empty). */
851 /* A parameter declarator: may be either, but after a type name does
852 not redeclare a typedef name as an identifier if it can
853 alternatively be interpreted as a typedef name; see DR#009,
854 applied in C90 TC1, omitted from C99 and reapplied in C99 TC2
855 following DR#249. For example, given a typedef T, "int T" and
856 "int *T" are valid parameter declarations redeclaring T, while
857 "int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are
858 abstract declarators rather than involving redundant parentheses;
859 the same applies with attributes inside the parentheses before
864 static void c_parser_external_declaration (c_parser
*);
865 static void c_parser_asm_definition (c_parser
*);
866 static void c_parser_declaration_or_fndef (c_parser
*, bool, bool, bool, bool);
867 static void c_parser_declspecs (c_parser
*, struct c_declspecs
*, bool, bool,
869 static struct c_typespec
c_parser_enum_specifier (c_parser
*);
870 static struct c_typespec
c_parser_struct_or_union_specifier (c_parser
*);
871 static tree
c_parser_struct_declaration (c_parser
*);
872 static struct c_typespec
c_parser_typeof_specifier (c_parser
*);
873 static struct c_declarator
*c_parser_declarator (c_parser
*, bool, c_dtr_syn
,
875 static struct c_declarator
*c_parser_direct_declarator (c_parser
*, bool,
877 static struct c_declarator
*c_parser_direct_declarator_inner (c_parser
*,
879 struct c_declarator
*);
880 static struct c_arg_info
*c_parser_parms_declarator (c_parser
*, bool, tree
);
881 static struct c_arg_info
*c_parser_parms_list_declarator (c_parser
*, tree
);
882 static struct c_parm
*c_parser_parameter_declaration (c_parser
*, tree
);
883 static tree
c_parser_simple_asm_expr (c_parser
*);
884 static tree
c_parser_attributes (c_parser
*);
885 static struct c_type_name
*c_parser_type_name (c_parser
*);
886 static struct c_expr
c_parser_initializer (c_parser
*);
887 static struct c_expr
c_parser_braced_init (c_parser
*, tree
, bool);
888 static void c_parser_initelt (c_parser
*);
889 static void c_parser_initval (c_parser
*, struct c_expr
*);
890 static tree
c_parser_compound_statement (c_parser
*);
891 static void c_parser_compound_statement_nostart (c_parser
*);
892 static void c_parser_label (c_parser
*);
893 static void c_parser_statement (c_parser
*);
894 static void c_parser_statement_after_labels (c_parser
*);
895 static void c_parser_if_statement (c_parser
*);
896 static void c_parser_switch_statement (c_parser
*);
897 static void c_parser_while_statement (c_parser
*);
898 static void c_parser_do_statement (c_parser
*);
899 static void c_parser_for_statement (c_parser
*);
900 static tree
c_parser_asm_statement (c_parser
*);
901 static tree
c_parser_asm_operands (c_parser
*, bool);
902 static tree
c_parser_asm_clobbers (c_parser
*);
903 static struct c_expr
c_parser_expr_no_commas (c_parser
*, struct c_expr
*);
904 static struct c_expr
c_parser_conditional_expression (c_parser
*,
906 static struct c_expr
c_parser_binary_expression (c_parser
*, struct c_expr
*);
907 static struct c_expr
c_parser_cast_expression (c_parser
*, struct c_expr
*);
908 static struct c_expr
c_parser_unary_expression (c_parser
*);
909 static struct c_expr
c_parser_sizeof_expression (c_parser
*);
910 static struct c_expr
c_parser_alignof_expression (c_parser
*);
911 static struct c_expr
c_parser_postfix_expression (c_parser
*);
912 static struct c_expr
c_parser_postfix_expression_after_paren_type (c_parser
*,
913 struct c_type_name
*);
914 static struct c_expr
c_parser_postfix_expression_after_primary (c_parser
*,
916 static struct c_expr
c_parser_expression (c_parser
*);
917 static struct c_expr
c_parser_expression_conv (c_parser
*);
918 static tree
c_parser_expr_list (c_parser
*, bool);
919 static void c_parser_omp_construct (c_parser
*);
920 static void c_parser_omp_threadprivate (c_parser
*);
921 static void c_parser_omp_barrier (c_parser
*);
922 static void c_parser_omp_flush (c_parser
*);
923 static void c_parser_omp_taskwait (c_parser
*);
925 enum pragma_context
{ pragma_external
, pragma_stmt
, pragma_compound
};
926 static bool c_parser_pragma (c_parser
*, enum pragma_context
);
928 /* These Objective-C parser functions are only ever called when
929 compiling Objective-C. */
930 static void c_parser_objc_class_definition (c_parser
*);
931 static void c_parser_objc_class_instance_variables (c_parser
*);
932 static void c_parser_objc_class_declaration (c_parser
*);
933 static void c_parser_objc_alias_declaration (c_parser
*);
934 static void c_parser_objc_protocol_definition (c_parser
*);
935 static enum tree_code
c_parser_objc_method_type (c_parser
*);
936 static void c_parser_objc_method_definition (c_parser
*);
937 static void c_parser_objc_methodprotolist (c_parser
*);
938 static void c_parser_objc_methodproto (c_parser
*);
939 static tree
c_parser_objc_method_decl (c_parser
*);
940 static tree
c_parser_objc_type_name (c_parser
*);
941 static tree
c_parser_objc_protocol_refs (c_parser
*);
942 static void c_parser_objc_try_catch_statement (c_parser
*);
943 static void c_parser_objc_synchronized_statement (c_parser
*);
944 static tree
c_parser_objc_selector (c_parser
*);
945 static tree
c_parser_objc_selector_arg (c_parser
*);
946 static tree
c_parser_objc_receiver (c_parser
*);
947 static tree
c_parser_objc_message_args (c_parser
*);
948 static tree
c_parser_objc_keywordexpr (c_parser
*);
950 /* Parse a translation unit (C90 6.7, C99 6.9).
953 external-declarations
955 external-declarations:
957 external-declarations external-declaration
966 c_parser_translation_unit (c_parser
*parser
)
968 if (c_parser_next_token_is (parser
, CPP_EOF
))
970 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
971 "ISO C forbids an empty translation unit");
975 void *obstack_position
= obstack_alloc (&parser_obstack
, 0);
979 c_parser_external_declaration (parser
);
980 obstack_free (&parser_obstack
, obstack_position
);
982 while (c_parser_next_token_is_not (parser
, CPP_EOF
));
986 /* Parse an external declaration (C90 6.7, C99 6.9).
988 external-declaration:
994 external-declaration:
997 __extension__ external-declaration
1001 external-declaration:
1002 objc-class-definition
1003 objc-class-declaration
1004 objc-alias-declaration
1005 objc-protocol-definition
1006 objc-method-definition
1011 c_parser_external_declaration (c_parser
*parser
)
1014 switch (c_parser_peek_token (parser
)->type
)
1017 switch (c_parser_peek_token (parser
)->keyword
)
1020 ext
= disable_extension_diagnostics ();
1021 c_parser_consume_token (parser
);
1022 c_parser_external_declaration (parser
);
1023 restore_extension_diagnostics (ext
);
1026 c_parser_asm_definition (parser
);
1028 case RID_AT_INTERFACE
:
1029 case RID_AT_IMPLEMENTATION
:
1030 gcc_assert (c_dialect_objc ());
1031 c_parser_objc_class_definition (parser
);
1034 gcc_assert (c_dialect_objc ());
1035 c_parser_objc_class_declaration (parser
);
1038 gcc_assert (c_dialect_objc ());
1039 c_parser_objc_alias_declaration (parser
);
1041 case RID_AT_PROTOCOL
:
1042 gcc_assert (c_dialect_objc ());
1043 c_parser_objc_protocol_definition (parser
);
1046 gcc_assert (c_dialect_objc ());
1047 c_parser_consume_token (parser
);
1048 objc_finish_implementation ();
1055 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
1056 "ISO C does not allow extra %<;%> outside of a function");
1057 c_parser_consume_token (parser
);
1060 c_parser_pragma (parser
, pragma_external
);
1064 if (c_dialect_objc ())
1066 c_parser_objc_method_definition (parser
);
1069 /* Else fall through, and yield a syntax error trying to parse
1070 as a declaration or function definition. */
1073 /* A declaration or a function definition. We can only tell
1074 which after parsing the declaration specifiers, if any, and
1075 the first declarator. */
1076 c_parser_declaration_or_fndef (parser
, true, true, false, true);
1082 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1083 6.7, 6.9.1). If FNDEF_OK is true, a function definition is
1084 accepted; otherwise (old-style parameter declarations) only other
1085 declarations are accepted. If NESTED is true, we are inside a
1086 function or parsing old-style parameter declarations; any functions
1087 encountered are nested functions and declaration specifiers are
1088 required; otherwise we are at top level and functions are normal
1089 functions and declaration specifiers may be optional. If EMPTY_OK
1090 is true, empty declarations are OK (subject to all other
1091 constraints); otherwise (old-style parameter declarations) they are
1092 diagnosed. If START_ATTR_OK is true, the declaration specifiers
1093 may start with attributes; otherwise they may not.
1096 declaration-specifiers init-declarator-list[opt] ;
1098 function-definition:
1099 declaration-specifiers[opt] declarator declaration-list[opt]
1104 declaration-list declaration
1106 init-declarator-list:
1108 init-declarator-list , init-declarator
1111 declarator simple-asm-expr[opt] attributes[opt]
1112 declarator simple-asm-expr[opt] attributes[opt] = initializer
1116 nested-function-definition:
1117 declaration-specifiers declarator declaration-list[opt]
1120 The simple-asm-expr and attributes are GNU extensions.
1122 This function does not handle __extension__; that is handled in its
1123 callers. ??? Following the old parser, __extension__ may start
1124 external declarations, declarations in functions and declarations
1125 at the start of "for" loops, but not old-style parameter
1128 C99 requires declaration specifiers in a function definition; the
1129 absence is diagnosed through the diagnosis of implicit int. In GNU
1130 C we also allow but diagnose declarations without declaration
1131 specifiers, but only at top level (elsewhere they conflict with
1137 threadprivate-directive */
1140 c_parser_declaration_or_fndef (c_parser
*parser
, bool fndef_ok
, bool empty_ok
,
1141 bool nested
, bool start_attr_ok
)
1143 struct c_declspecs
*specs
;
1145 tree all_prefix_attrs
;
1146 bool diagnosed_no_specs
= false;
1147 location_t here
= c_parser_peek_token (parser
)->location
;
1149 specs
= build_null_declspecs ();
1150 c_parser_declspecs (parser
, specs
, true, true, start_attr_ok
);
1153 c_parser_skip_to_end_of_block_or_statement (parser
);
1156 if (nested
&& !specs
->declspecs_seen_p
)
1158 c_parser_error (parser
, "expected declaration specifiers");
1159 c_parser_skip_to_end_of_block_or_statement (parser
);
1162 finish_declspecs (specs
);
1163 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1169 shadow_tag_warned (specs
, 1);
1170 pedwarn (here
, 0, "empty declaration");
1172 c_parser_consume_token (parser
);
1175 pending_xref_error ();
1176 prefix_attrs
= specs
->attrs
;
1177 all_prefix_attrs
= prefix_attrs
;
1178 specs
->attrs
= NULL_TREE
;
1181 struct c_declarator
*declarator
;
1184 /* Declaring either one or more declarators (in which case we
1185 should diagnose if there were no declaration specifiers) or a
1186 function definition (in which case the diagnostic for
1187 implicit int suffices). */
1188 declarator
= c_parser_declarator (parser
, specs
->type_seen_p
,
1189 C_DTR_NORMAL
, &dummy
);
1190 if (declarator
== NULL
)
1192 c_parser_skip_to_end_of_block_or_statement (parser
);
1195 if (c_parser_next_token_is (parser
, CPP_EQ
)
1196 || c_parser_next_token_is (parser
, CPP_COMMA
)
1197 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
1198 || c_parser_next_token_is_keyword (parser
, RID_ASM
)
1199 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1201 tree asm_name
= NULL_TREE
;
1202 tree postfix_attrs
= NULL_TREE
;
1203 if (!diagnosed_no_specs
&& !specs
->declspecs_seen_p
)
1205 diagnosed_no_specs
= true;
1206 pedwarn (here
, 0, "data 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). */
1275 pedwarn (here
, OPT_pedantic
, "ISO C forbids nested functions");
1276 c_push_function_context ();
1278 if (!start_function (specs
, declarator
, all_prefix_attrs
))
1280 /* This can appear in many cases looking nothing like a
1281 function definition, so we don't give a more specific
1282 error suggesting there was one. */
1283 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
1284 "or %<__attribute__%>");
1286 c_pop_function_context ();
1289 /* Parse old-style parameter declarations. ??? Attributes are
1290 not allowed to start declaration specifiers here because of a
1291 syntax conflict between a function declaration with attribute
1292 suffix and a function definition with an attribute prefix on
1293 first old-style parameter declaration. Following the old
1294 parser, they are not accepted on subsequent old-style
1295 parameter declarations either. However, there is no
1296 ambiguity after the first declaration, nor indeed on the
1297 first as long as we don't allow postfix attributes after a
1298 declarator with a nonempty identifier list in a definition;
1299 and postfix attributes have never been accepted here in
1300 function definitions either. */
1301 while (c_parser_next_token_is_not (parser
, CPP_EOF
)
1302 && c_parser_next_token_is_not (parser
, CPP_OPEN_BRACE
))
1303 c_parser_declaration_or_fndef (parser
, false, false, true, false);
1304 store_parm_decls ();
1305 DECL_STRUCT_FUNCTION (current_function_decl
)->function_start_locus
1306 = c_parser_peek_token (parser
)->location
;
1307 fnbody
= c_parser_compound_statement (parser
);
1310 tree decl
= current_function_decl
;
1313 c_pop_function_context ();
1314 add_stmt (build_stmt (DECL_EXPR
, decl
));
1325 /* Parse an asm-definition (asm() outside a function body). This is a
1333 c_parser_asm_definition (c_parser
*parser
)
1335 tree asm_str
= c_parser_simple_asm_expr (parser
);
1337 cgraph_add_asm_node (asm_str
);
1338 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
1341 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
1342 6.7), adding them to SPECS (which may already include some).
1343 Storage class specifiers are accepted iff SCSPEC_OK; type
1344 specifiers are accepted iff TYPESPEC_OK; attributes are accepted at
1345 the start iff START_ATTR_OK.
1347 declaration-specifiers:
1348 storage-class-specifier declaration-specifiers[opt]
1349 type-specifier declaration-specifiers[opt]
1350 type-qualifier declaration-specifiers[opt]
1351 function-specifier declaration-specifiers[opt]
1353 Function specifiers (inline) are from C99, and are currently
1354 handled as storage class specifiers, as is __thread.
1356 C90 6.5.1, C99 6.7.1:
1357 storage-class-specifier:
1368 C90 6.5.2, C99 6.7.2:
1381 [_Imaginary removed in C99 TC2]
1382 struct-or-union-specifier
1386 (_Bool and _Complex are new in C99.)
1388 C90 6.5.3, C99 6.7.3:
1395 (restrict is new in C99.)
1399 declaration-specifiers:
1400 attributes declaration-specifiers[opt]
1402 storage-class-specifier:
1414 (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
1415 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
1420 class-name objc-protocol-refs[opt]
1421 typedef-name objc-protocol-refs
1426 c_parser_declspecs (c_parser
*parser
, struct c_declspecs
*specs
,
1427 bool scspec_ok
, bool typespec_ok
, bool start_attr_ok
)
1429 bool attrs_ok
= start_attr_ok
;
1430 bool seen_type
= specs
->type_seen_p
;
1431 while (c_parser_next_token_is (parser
, CPP_NAME
)
1432 || c_parser_next_token_is (parser
, CPP_KEYWORD
)
1433 || (c_dialect_objc () && c_parser_next_token_is (parser
, CPP_LESS
)))
1435 struct c_typespec t
;
1437 if (c_parser_next_token_is (parser
, CPP_NAME
))
1439 tree value
= c_parser_peek_token (parser
)->value
;
1440 c_id_kind kind
= c_parser_peek_token (parser
)->id_kind
;
1441 /* This finishes the specifiers unless a type name is OK, it
1442 is declared as a type name and a type name hasn't yet
1444 if (!typespec_ok
|| seen_type
1445 || (kind
!= C_ID_TYPENAME
&& kind
!= C_ID_CLASSNAME
))
1447 c_parser_consume_token (parser
);
1450 if (kind
== C_ID_TYPENAME
1451 && (!c_dialect_objc ()
1452 || c_parser_next_token_is_not (parser
, CPP_LESS
)))
1454 t
.kind
= ctsk_typedef
;
1455 /* For a typedef name, record the meaning, not the name.
1456 In case of 'foo foo, bar;'. */
1457 t
.spec
= lookup_name (value
);
1461 tree proto
= NULL_TREE
;
1462 gcc_assert (c_dialect_objc ());
1464 if (c_parser_next_token_is (parser
, CPP_LESS
))
1465 proto
= c_parser_objc_protocol_refs (parser
);
1466 t
.spec
= objc_get_protocol_qualified_type (value
, proto
);
1468 declspecs_add_type (specs
, t
);
1471 if (c_parser_next_token_is (parser
, CPP_LESS
))
1473 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
1474 nisse@lysator.liu.se. */
1476 gcc_assert (c_dialect_objc ());
1477 if (!typespec_ok
|| seen_type
)
1479 proto
= c_parser_objc_protocol_refs (parser
);
1481 t
.spec
= objc_get_protocol_qualified_type (NULL_TREE
, proto
);
1482 declspecs_add_type (specs
, t
);
1485 gcc_assert (c_parser_next_token_is (parser
, CPP_KEYWORD
));
1486 switch (c_parser_peek_token (parser
)->keyword
)
1498 /* TODO: Distinguish between function specifiers (inline)
1499 and storage class specifiers, either here or in
1500 declspecs_add_scspec. */
1501 declspecs_add_scspec (specs
, c_parser_peek_token (parser
)->value
);
1502 c_parser_consume_token (parser
);
1525 if (c_dialect_objc ())
1526 parser
->objc_need_raw_identifier
= true;
1527 t
.kind
= ctsk_resword
;
1528 t
.spec
= c_parser_peek_token (parser
)->value
;
1529 declspecs_add_type (specs
, t
);
1530 c_parser_consume_token (parser
);
1537 t
= c_parser_enum_specifier (parser
);
1538 declspecs_add_type (specs
, t
);
1546 t
= c_parser_struct_or_union_specifier (parser
);
1547 declspecs_add_type (specs
, t
);
1550 /* ??? The old parser rejected typeof after other type
1551 specifiers, but is a syntax error the best way of
1553 if (!typespec_ok
|| seen_type
)
1557 t
= c_parser_typeof_specifier (parser
);
1558 declspecs_add_type (specs
, t
);
1564 declspecs_add_qual (specs
, c_parser_peek_token (parser
)->value
);
1565 c_parser_consume_token (parser
);
1570 attrs
= c_parser_attributes (parser
);
1571 declspecs_add_attrs (specs
, attrs
);
1580 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
1583 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
1584 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
1585 enum attributes[opt] identifier
1587 The form with trailing comma is new in C99. The forms with
1588 attributes are GNU extensions. In GNU C, we accept any expression
1589 without commas in the syntax (assignment expressions, not just
1590 conditional expressions); assignment expressions will be diagnosed
1595 enumerator-list , enumerator
1598 enumeration-constant
1599 enumeration-constant = constant-expression
1602 static struct c_typespec
1603 c_parser_enum_specifier (c_parser
*parser
)
1605 struct c_typespec ret
;
1607 tree ident
= NULL_TREE
;
1608 location_t ident_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
1609 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ENUM
));
1610 c_parser_consume_token (parser
);
1611 attrs
= c_parser_attributes (parser
);
1612 /* Set the location in case we create a decl now. */
1613 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
1614 if (c_parser_next_token_is (parser
, CPP_NAME
))
1616 ident
= c_parser_peek_token (parser
)->value
;
1617 ident_loc
= c_parser_peek_token (parser
)->location
;
1618 c_parser_consume_token (parser
);
1620 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
1622 /* Parse an enum definition. */
1623 struct c_enum_contents the_enum
;
1624 tree type
= start_enum (&the_enum
, ident
);
1626 /* We chain the enumerators in reverse order, then put them in
1627 forward order at the end. */
1628 tree values
= NULL_TREE
;
1629 c_parser_consume_token (parser
);
1637 location_t comma_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
1638 location_t value_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 value_loc
= token
->location
;
1651 c_parser_consume_token (parser
);
1652 if (c_parser_next_token_is (parser
, CPP_EQ
))
1654 c_parser_consume_token (parser
);
1655 value_loc
= c_parser_peek_token (parser
)->location
;
1656 enum_value
= c_parser_expr_no_commas (parser
, NULL
).value
;
1659 enum_value
= NULL_TREE
;
1660 enum_decl
= build_enumerator (&the_enum
, enum_id
, enum_value
,
1662 TREE_CHAIN (enum_decl
) = values
;
1665 if (c_parser_next_token_is (parser
, CPP_COMMA
))
1667 comma_loc
= c_parser_peek_token (parser
)->location
;
1669 c_parser_consume_token (parser
);
1671 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
1673 if (seen_comma
&& !flag_isoc99
)
1674 pedwarn (comma_loc
, OPT_pedantic
, "comma at end of enumerator list");
1675 c_parser_consume_token (parser
);
1680 c_parser_error (parser
, "expected %<,%> or %<}%>");
1681 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
1682 values
= error_mark_node
;
1686 postfix_attrs
= c_parser_attributes (parser
);
1687 ret
.spec
= finish_enum (type
, nreverse (values
),
1688 chainon (attrs
, postfix_attrs
));
1689 ret
.kind
= ctsk_tagdef
;
1694 c_parser_error (parser
, "expected %<{%>");
1695 ret
.spec
= error_mark_node
;
1696 ret
.kind
= ctsk_tagref
;
1699 ret
= parser_xref_tag (ENUMERAL_TYPE
, ident
);
1700 /* In ISO C, enumerated types can be referred to only if already
1702 if (pedantic
&& !COMPLETE_TYPE_P (ret
.spec
))
1705 pedwarn (ident_loc
, OPT_pedantic
,
1706 "ISO C forbids forward references to %<enum%> types");
1711 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
1713 struct-or-union-specifier:
1714 struct-or-union attributes[opt] identifier[opt]
1715 { struct-contents } attributes[opt]
1716 struct-or-union attributes[opt] identifier
1719 struct-declaration-list
1721 struct-declaration-list:
1722 struct-declaration ;
1723 struct-declaration-list struct-declaration ;
1730 struct-declaration-list struct-declaration
1732 struct-declaration-list:
1733 struct-declaration-list ;
1736 (Note that in the syntax here, unlike that in ISO C, the semicolons
1737 are included here rather than in struct-declaration, in order to
1738 describe the syntax with extra semicolons and missing semicolon at
1743 struct-declaration-list:
1744 @defs ( class-name )
1746 (Note this does not include a trailing semicolon, but can be
1747 followed by further declarations, and gets a pedwarn-if-pedantic
1748 when followed by a semicolon.) */
1750 static struct c_typespec
1751 c_parser_struct_or_union_specifier (c_parser
*parser
)
1753 struct c_typespec ret
;
1755 tree ident
= NULL_TREE
;
1756 enum tree_code code
;
1757 switch (c_parser_peek_token (parser
)->keyword
)
1768 c_parser_consume_token (parser
);
1769 attrs
= c_parser_attributes (parser
);
1770 /* Set the location in case we create a decl now. */
1771 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
1772 if (c_parser_next_token_is (parser
, CPP_NAME
))
1774 ident
= c_parser_peek_token (parser
)->value
;
1775 c_parser_consume_token (parser
);
1777 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
1779 /* Parse a struct or union definition. Start the scope of the
1780 tag before parsing components. */
1781 tree type
= start_struct (code
, ident
);
1783 /* We chain the components in reverse order, then put them in
1784 forward order at the end. Each struct-declaration may
1785 declare multiple components (comma-separated), so we must use
1786 chainon to join them, although when parsing each
1787 struct-declaration we can use TREE_CHAIN directly.
1789 The theory behind all this is that there will be more
1790 semicolon separated fields than comma separated fields, and
1791 so we'll be minimizing the number of node traversals required
1793 tree contents
= NULL_TREE
;
1794 c_parser_consume_token (parser
);
1795 /* Handle the Objective-C @defs construct,
1796 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
1797 if (c_parser_next_token_is_keyword (parser
, RID_AT_DEFS
))
1800 gcc_assert (c_dialect_objc ());
1801 c_parser_consume_token (parser
);
1802 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
1804 if (c_parser_next_token_is (parser
, CPP_NAME
)
1805 && c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
)
1807 name
= c_parser_peek_token (parser
)->value
;
1808 c_parser_consume_token (parser
);
1812 c_parser_error (parser
, "expected class name");
1813 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
1816 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
1818 contents
= nreverse (objc_get_class_ivars (name
));
1821 /* Parse the struct-declarations and semicolons. Problems with
1822 semicolons are diagnosed here; empty structures are diagnosed
1827 /* Parse any stray semicolon. */
1828 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1830 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
1831 "extra semicolon in struct or union specified");
1832 c_parser_consume_token (parser
);
1835 /* Stop if at the end of the struct or union contents. */
1836 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
1838 c_parser_consume_token (parser
);
1841 /* Accept #pragmas at struct scope. */
1842 if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
1844 c_parser_pragma (parser
, pragma_external
);
1847 /* Parse some comma-separated declarations, but not the
1848 trailing semicolon if any. */
1849 decls
= c_parser_struct_declaration (parser
);
1850 contents
= chainon (decls
, contents
);
1851 /* If no semicolon follows, either we have a parse error or
1852 are at the end of the struct or union and should
1854 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1855 c_parser_consume_token (parser
);
1858 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
1859 pedwarn (c_parser_peek_token (parser
)->location
, 0,
1860 "no semicolon at end of struct or union");
1863 c_parser_error (parser
, "expected %<;%>");
1864 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
1869 postfix_attrs
= c_parser_attributes (parser
);
1870 ret
.spec
= finish_struct (type
, nreverse (contents
),
1871 chainon (attrs
, postfix_attrs
));
1872 ret
.kind
= ctsk_tagdef
;
1877 c_parser_error (parser
, "expected %<{%>");
1878 ret
.spec
= error_mark_node
;
1879 ret
.kind
= ctsk_tagref
;
1882 ret
= parser_xref_tag (code
, ident
);
1886 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
1887 the trailing semicolon.
1890 specifier-qualifier-list struct-declarator-list
1892 specifier-qualifier-list:
1893 type-specifier specifier-qualifier-list[opt]
1894 type-qualifier specifier-qualifier-list[opt]
1895 attributes specifier-qualifier-list[opt]
1897 struct-declarator-list:
1899 struct-declarator-list , attributes[opt] struct-declarator
1902 declarator attributes[opt]
1903 declarator[opt] : constant-expression attributes[opt]
1908 __extension__ struct-declaration
1909 specifier-qualifier-list
1911 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
1912 of attributes where shown is a GNU extension. In GNU C, we accept
1913 any expression without commas in the syntax (assignment
1914 expressions, not just conditional expressions); assignment
1915 expressions will be diagnosed as non-constant. */
1918 c_parser_struct_declaration (c_parser
*parser
)
1920 struct c_declspecs
*specs
;
1922 tree all_prefix_attrs
;
1924 location_t decl_loc
;
1925 if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
1929 ext
= disable_extension_diagnostics ();
1930 c_parser_consume_token (parser
);
1931 decl
= c_parser_struct_declaration (parser
);
1932 restore_extension_diagnostics (ext
);
1935 specs
= build_null_declspecs ();
1936 decl_loc
= c_parser_peek_token (parser
)->location
;
1937 c_parser_declspecs (parser
, specs
, false, true, true);
1940 if (!specs
->declspecs_seen_p
)
1942 c_parser_error (parser
, "expected specifier-qualifier-list");
1945 finish_declspecs (specs
);
1946 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1949 if (!specs
->type_seen_p
)
1951 pedwarn (decl_loc
, OPT_pedantic
,
1952 "ISO C forbids member declarations with no members");
1953 shadow_tag_warned (specs
, pedantic
);
1958 /* Support for unnamed structs or unions as members of
1959 structs or unions (which is [a] useful and [b] supports
1963 ret
= grokfield (c_parser_peek_token (parser
)->location
,
1964 build_id_declarator (NULL_TREE
), specs
,
1967 decl_attributes (&ret
, attrs
, 0);
1971 pending_xref_error ();
1972 prefix_attrs
= specs
->attrs
;
1973 all_prefix_attrs
= prefix_attrs
;
1974 specs
->attrs
= NULL_TREE
;
1978 /* Declaring one or more declarators or un-named bit-fields. */
1979 struct c_declarator
*declarator
;
1981 if (c_parser_next_token_is (parser
, CPP_COLON
))
1982 declarator
= build_id_declarator (NULL_TREE
);
1984 declarator
= c_parser_declarator (parser
, specs
->type_seen_p
,
1985 C_DTR_NORMAL
, &dummy
);
1986 if (declarator
== NULL
)
1988 c_parser_skip_to_end_of_block_or_statement (parser
);
1991 if (c_parser_next_token_is (parser
, CPP_COLON
)
1992 || c_parser_next_token_is (parser
, CPP_COMMA
)
1993 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
1994 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
)
1995 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1997 tree postfix_attrs
= NULL_TREE
;
1998 tree width
= NULL_TREE
;
2000 if (c_parser_next_token_is (parser
, CPP_COLON
))
2002 c_parser_consume_token (parser
);
2003 width
= c_parser_expr_no_commas (parser
, NULL
).value
;
2005 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2006 postfix_attrs
= c_parser_attributes (parser
);
2007 d
= grokfield (c_parser_peek_token (parser
)->location
,
2008 declarator
, specs
, width
, &all_prefix_attrs
);
2009 decl_attributes (&d
, chainon (postfix_attrs
,
2010 all_prefix_attrs
), 0);
2011 TREE_CHAIN (d
) = decls
;
2013 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2014 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
2017 all_prefix_attrs
= prefix_attrs
;
2018 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2019 c_parser_consume_token (parser
);
2020 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2021 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2023 /* Semicolon consumed in caller. */
2028 c_parser_error (parser
, "expected %<,%>, %<;%> or %<}%>");
2034 c_parser_error (parser
,
2035 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
2036 "%<__attribute__%>");
2043 /* Parse a typeof specifier (a GNU extension).
2046 typeof ( expression )
2047 typeof ( type-name )
2050 static struct c_typespec
2051 c_parser_typeof_specifier (c_parser
*parser
)
2053 struct c_typespec ret
;
2054 ret
.kind
= ctsk_typeof
;
2055 ret
.spec
= error_mark_node
;
2056 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TYPEOF
));
2057 c_parser_consume_token (parser
);
2060 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2066 if (c_parser_next_token_starts_typename (parser
))
2068 struct c_type_name
*type
= c_parser_type_name (parser
);
2073 ret
.spec
= groktypename (type
);
2074 pop_maybe_used (variably_modified_type_p (ret
.spec
, NULL_TREE
));
2080 location_t here
= c_parser_peek_token (parser
)->location
;
2081 struct c_expr expr
= c_parser_expression (parser
);
2084 if (TREE_CODE (expr
.value
) == COMPONENT_REF
2085 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
2086 error_at (here
, "%<typeof%> applied to a bit-field");
2087 ret
.spec
= TREE_TYPE (expr
.value
);
2088 was_vm
= variably_modified_type_p (ret
.spec
, NULL_TREE
);
2089 /* This should be returned with the type so that when the type
2090 is evaluated, this can be evaluated. For now, we avoid
2091 evaluation when the context might. */
2092 if (!skip_evaluation
&& was_vm
)
2094 tree e
= expr
.value
;
2096 /* If the expression is not of a type to which we cannot assign a line
2097 number, wrap the thing in a no-op NOP_EXPR. */
2098 if (DECL_P (e
) || CONSTANT_CLASS_P (e
))
2099 e
= build1 (NOP_EXPR
, void_type_node
, e
);
2101 protected_set_expr_location (e
, here
);
2105 pop_maybe_used (was_vm
);
2107 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
2111 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
2112 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
2113 be redeclared; otherwise it may not. KIND indicates which kind of
2114 declarator is wanted. Returns a valid declarator except in the
2115 case of a syntax error in which case NULL is returned. *SEEN_ID is
2116 set to true if an identifier being declared is seen; this is used
2117 to diagnose bad forms of abstract array declarators and to
2118 determine whether an identifier list is syntactically permitted.
2121 pointer[opt] direct-declarator
2125 ( attributes[opt] declarator )
2126 direct-declarator array-declarator
2127 direct-declarator ( parameter-type-list )
2128 direct-declarator ( identifier-list[opt] )
2131 * type-qualifier-list[opt]
2132 * type-qualifier-list[opt] pointer
2134 type-qualifier-list:
2137 type-qualifier-list type-qualifier
2138 type-qualifier-list attributes
2140 parameter-type-list:
2142 parameter-list , ...
2145 parameter-declaration
2146 parameter-list , parameter-declaration
2148 parameter-declaration:
2149 declaration-specifiers declarator attributes[opt]
2150 declaration-specifiers abstract-declarator[opt] attributes[opt]
2154 identifier-list , identifier
2156 abstract-declarator:
2158 pointer[opt] direct-abstract-declarator
2160 direct-abstract-declarator:
2161 ( attributes[opt] abstract-declarator )
2162 direct-abstract-declarator[opt] array-declarator
2163 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
2168 direct-declarator ( parameter-forward-declarations
2169 parameter-type-list[opt] )
2171 direct-abstract-declarator:
2172 direct-abstract-declarator[opt] ( parameter-forward-declarations
2173 parameter-type-list[opt] )
2175 parameter-forward-declarations:
2177 parameter-forward-declarations parameter-list ;
2179 The uses of attributes shown above are GNU extensions.
2181 Some forms of array declarator are not included in C99 in the
2182 syntax for abstract declarators; these are disallowed elsewhere.
2183 This may be a defect (DR#289).
2185 This function also accepts an omitted abstract declarator as being
2186 an abstract declarator, although not part of the formal syntax. */
2188 static struct c_declarator
*
2189 c_parser_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
2192 /* Parse any initial pointer part. */
2193 if (c_parser_next_token_is (parser
, CPP_MULT
))
2195 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
2196 struct c_declarator
*inner
;
2197 c_parser_consume_token (parser
);
2198 c_parser_declspecs (parser
, quals_attrs
, false, false, true);
2199 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
2203 return make_pointer_declarator (quals_attrs
, inner
);
2205 /* Now we have a direct declarator, direct abstract declarator or
2206 nothing (which counts as a direct abstract declarator here). */
2207 return c_parser_direct_declarator (parser
, type_seen_p
, kind
, seen_id
);
2210 /* Parse a direct declarator or direct abstract declarator; arguments
2211 as c_parser_declarator. */
2213 static struct c_declarator
*
2214 c_parser_direct_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
2217 /* The direct declarator must start with an identifier (possibly
2218 omitted) or a parenthesized declarator (possibly abstract). In
2219 an ordinary declarator, initial parentheses must start a
2220 parenthesized declarator. In an abstract declarator or parameter
2221 declarator, they could start a parenthesized declarator or a
2222 parameter list. To tell which, the open parenthesis and any
2223 following attributes must be read. If a declaration specifier
2224 follows, then it is a parameter list; if the specifier is a
2225 typedef name, there might be an ambiguity about redeclaring it,
2226 which is resolved in the direction of treating it as a typedef
2227 name. If a close parenthesis follows, it is also an empty
2228 parameter list, as the syntax does not permit empty abstract
2229 declarators. Otherwise, it is a parenthesized declarator (in
2230 which case the analysis may be repeated inside it, recursively).
2232 ??? There is an ambiguity in a parameter declaration "int
2233 (__attribute__((foo)) x)", where x is not a typedef name: it
2234 could be an abstract declarator for a function, or declare x with
2235 parentheses. The proper resolution of this ambiguity needs
2236 documenting. At present we follow an accident of the old
2237 parser's implementation, whereby the first parameter must have
2238 some declaration specifiers other than just attributes. Thus as
2239 a parameter declaration it is treated as a parenthesized
2240 parameter named x, and as an abstract declarator it is
2243 ??? Also following the old parser, attributes inside an empty
2244 parameter list are ignored, making it a list not yielding a
2245 prototype, rather than giving an error or making it have one
2246 parameter with implicit type int.
2248 ??? Also following the old parser, typedef names may be
2249 redeclared in declarators, but not Objective-C class names. */
2251 if (kind
!= C_DTR_ABSTRACT
2252 && c_parser_next_token_is (parser
, CPP_NAME
)
2254 && c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
)
2255 || c_parser_peek_token (parser
)->id_kind
== C_ID_ID
))
2257 struct c_declarator
*inner
2258 = build_id_declarator (c_parser_peek_token (parser
)->value
);
2260 inner
->id_loc
= c_parser_peek_token (parser
)->location
;
2261 c_parser_consume_token (parser
);
2262 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
2265 if (kind
!= C_DTR_NORMAL
2266 && c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
2268 struct c_declarator
*inner
= build_id_declarator (NULL_TREE
);
2269 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
2272 /* Either we are at the end of an abstract declarator, or we have
2275 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
2278 struct c_declarator
*inner
;
2279 c_parser_consume_token (parser
);
2280 attrs
= c_parser_attributes (parser
);
2281 if (kind
!= C_DTR_NORMAL
2282 && (c_parser_next_token_starts_declspecs (parser
)
2283 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
)))
2285 struct c_arg_info
*args
2286 = c_parser_parms_declarator (parser
, kind
== C_DTR_NORMAL
,
2293 = build_function_declarator (args
,
2294 build_id_declarator (NULL_TREE
));
2295 return c_parser_direct_declarator_inner (parser
, *seen_id
,
2299 /* A parenthesized declarator. */
2300 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
2301 if (inner
!= NULL
&& attrs
!= NULL
)
2302 inner
= build_attrs_declarator (attrs
, inner
);
2303 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2305 c_parser_consume_token (parser
);
2309 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
2313 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2320 if (kind
== C_DTR_NORMAL
)
2322 c_parser_error (parser
, "expected identifier or %<(%>");
2326 return build_id_declarator (NULL_TREE
);
2330 /* Parse part of a direct declarator or direct abstract declarator,
2331 given that some (in INNER) has already been parsed; ID_PRESENT is
2332 true if an identifier is present, false for an abstract
2335 static struct c_declarator
*
2336 c_parser_direct_declarator_inner (c_parser
*parser
, bool id_present
,
2337 struct c_declarator
*inner
)
2339 /* Parse a sequence of array declarators and parameter lists. */
2340 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
2342 struct c_declarator
*declarator
;
2343 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
2347 c_parser_consume_token (parser
);
2348 c_parser_declspecs (parser
, quals_attrs
, false, false, true);
2349 static_seen
= c_parser_next_token_is_keyword (parser
, RID_STATIC
);
2351 c_parser_consume_token (parser
);
2352 if (static_seen
&& !quals_attrs
->declspecs_seen_p
)
2353 c_parser_declspecs (parser
, quals_attrs
, false, false, true);
2354 if (!quals_attrs
->declspecs_seen_p
)
2356 /* If "static" is present, there must be an array dimension.
2357 Otherwise, there may be a dimension, "*", or no
2362 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
2366 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
2371 else if (c_parser_next_token_is (parser
, CPP_MULT
))
2373 if (c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_SQUARE
)
2377 c_parser_consume_token (parser
);
2382 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
2388 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
2391 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
2392 c_parser_consume_token (parser
);
2395 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
2399 declarator
= build_array_declarator (dimen
, quals_attrs
, static_seen
,
2401 if (declarator
== NULL
)
2403 inner
= set_array_declarator_inner (declarator
, inner
);
2404 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
2406 else if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
2409 struct c_arg_info
*args
;
2410 c_parser_consume_token (parser
);
2411 attrs
= c_parser_attributes (parser
);
2412 args
= c_parser_parms_declarator (parser
, id_present
, attrs
);
2417 inner
= build_function_declarator (args
, inner
);
2418 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
2424 /* Parse a parameter list or identifier list, including the closing
2425 parenthesis but not the opening one. ATTRS are the attributes at
2426 the start of the list. ID_LIST_OK is true if an identifier list is
2427 acceptable; such a list must not have attributes at the start. */
2429 static struct c_arg_info
*
2430 c_parser_parms_declarator (c_parser
*parser
, bool id_list_ok
, tree attrs
)
2433 declare_parm_level ();
2434 /* If the list starts with an identifier, it is an identifier list.
2435 Otherwise, it is either a prototype list or an empty list. */
2438 && c_parser_next_token_is (parser
, CPP_NAME
)
2439 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
2441 tree list
= NULL_TREE
, *nextp
= &list
;
2442 while (c_parser_next_token_is (parser
, CPP_NAME
)
2443 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
2445 *nextp
= build_tree_list (NULL_TREE
,
2446 c_parser_peek_token (parser
)->value
);
2447 nextp
= & TREE_CHAIN (*nextp
);
2448 c_parser_consume_token (parser
);
2449 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
2451 c_parser_consume_token (parser
);
2452 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2454 c_parser_error (parser
, "expected identifier");
2458 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2460 struct c_arg_info
*ret
= XOBNEW (&parser_obstack
, struct c_arg_info
);
2465 ret
->pending_sizes
= 0;
2466 ret
->had_vla_unspec
= 0;
2467 c_parser_consume_token (parser
);
2473 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2481 struct c_arg_info
*ret
= c_parser_parms_list_declarator (parser
, attrs
);
2487 /* Parse a parameter list (possibly empty), including the closing
2488 parenthesis but not the opening one. ATTRS are the attributes at
2489 the start of the list. */
2491 static struct c_arg_info
*
2492 c_parser_parms_list_declarator (c_parser
*parser
, tree attrs
)
2494 bool good_parm
= false;
2495 /* ??? Following the old parser, forward parameter declarations may
2496 use abstract declarators, and if no real parameter declarations
2497 follow the forward declarations then this is not diagnosed. Also
2498 note as above that attributes are ignored as the only contents of
2499 the parentheses, or as the only contents after forward
2501 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2503 struct c_arg_info
*ret
= XOBNEW (&parser_obstack
, struct c_arg_info
);
2508 ret
->pending_sizes
= 0;
2509 ret
->had_vla_unspec
= 0;
2510 c_parser_consume_token (parser
);
2513 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
2515 struct c_arg_info
*ret
= XOBNEW (&parser_obstack
, struct c_arg_info
);
2519 ret
->pending_sizes
= 0;
2520 ret
->had_vla_unspec
= 0;
2521 /* Suppress -Wold-style-definition for this case. */
2522 ret
->types
= error_mark_node
;
2523 error_at (c_parser_peek_token (parser
)->location
,
2524 "ISO C requires a named argument before %<...%>");
2525 c_parser_consume_token (parser
);
2526 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2528 c_parser_consume_token (parser
);
2533 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2538 /* Nonempty list of parameters, either terminated with semicolon
2539 (forward declarations; recurse) or with close parenthesis (normal
2540 function) or with ", ... )" (variadic function). */
2543 /* Parse a parameter. */
2544 struct c_parm
*parm
= c_parser_parameter_declaration (parser
, attrs
);
2549 push_parm_decl (parm
);
2551 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2554 c_parser_consume_token (parser
);
2555 mark_forward_parm_decls ();
2556 new_attrs
= c_parser_attributes (parser
);
2557 return c_parser_parms_list_declarator (parser
, new_attrs
);
2559 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2561 c_parser_consume_token (parser
);
2563 return get_parm_info (false);
2566 struct c_arg_info
*ret
2567 = XOBNEW (&parser_obstack
, struct c_arg_info
);
2572 ret
->pending_sizes
= 0;
2573 ret
->had_vla_unspec
= 0;
2577 if (!c_parser_require (parser
, CPP_COMMA
,
2578 "expected %<;%>, %<,%> or %<)%>"))
2580 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2583 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
2585 c_parser_consume_token (parser
);
2586 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2588 c_parser_consume_token (parser
);
2590 return get_parm_info (true);
2593 struct c_arg_info
*ret
2594 = XOBNEW (&parser_obstack
, struct c_arg_info
);
2599 ret
->pending_sizes
= 0;
2600 ret
->had_vla_unspec
= 0;
2606 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2614 /* Parse a parameter declaration. ATTRS are the attributes at the
2615 start of the declaration if it is the first parameter. */
2617 static struct c_parm
*
2618 c_parser_parameter_declaration (c_parser
*parser
, tree attrs
)
2620 struct c_declspecs
*specs
;
2621 struct c_declarator
*declarator
;
2623 tree postfix_attrs
= NULL_TREE
;
2625 if (!c_parser_next_token_starts_declspecs (parser
))
2627 /* ??? In some Objective-C cases '...' isn't applicable so there
2628 should be a different message. */
2629 c_parser_error (parser
,
2630 "expected declaration specifiers or %<...%>");
2631 c_parser_skip_to_end_of_parameter (parser
);
2634 specs
= build_null_declspecs ();
2637 declspecs_add_attrs (specs
, attrs
);
2640 c_parser_declspecs (parser
, specs
, true, true, true);
2641 finish_declspecs (specs
);
2642 pending_xref_error ();
2643 prefix_attrs
= specs
->attrs
;
2644 specs
->attrs
= NULL_TREE
;
2645 declarator
= c_parser_declarator (parser
, specs
->type_seen_p
,
2646 C_DTR_PARM
, &dummy
);
2647 if (declarator
== NULL
)
2649 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
2652 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2653 postfix_attrs
= c_parser_attributes (parser
);
2654 return build_c_parm (specs
, chainon (postfix_attrs
, prefix_attrs
),
2658 /* Parse a string literal in an asm expression. It should not be
2659 translated, and wide string literals are an error although
2660 permitted by the syntax. This is a GNU extension.
2665 ??? At present, following the old parser, the caller needs to have
2666 set lex_untranslated_string to 1. It would be better to follow the
2667 C++ parser rather than using this kludge. */
2670 c_parser_asm_string_literal (c_parser
*parser
)
2673 if (c_parser_next_token_is (parser
, CPP_STRING
))
2675 str
= c_parser_peek_token (parser
)->value
;
2676 c_parser_consume_token (parser
);
2678 else if (c_parser_next_token_is (parser
, CPP_WSTRING
))
2680 error_at (c_parser_peek_token (parser
)->location
,
2681 "wide string literal in %<asm%>");
2682 str
= build_string (1, "");
2683 c_parser_consume_token (parser
);
2687 c_parser_error (parser
, "expected string literal");
2693 /* Parse a simple asm expression. This is used in restricted
2694 contexts, where a full expression with inputs and outputs does not
2695 make sense. This is a GNU extension.
2698 asm ( asm-string-literal )
2702 c_parser_simple_asm_expr (c_parser
*parser
)
2705 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
2706 /* ??? Follow the C++ parser rather than using the
2707 lex_untranslated_string kludge. */
2708 parser
->lex_untranslated_string
= true;
2709 c_parser_consume_token (parser
);
2710 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2712 parser
->lex_untranslated_string
= false;
2715 str
= c_parser_asm_string_literal (parser
);
2716 parser
->lex_untranslated_string
= false;
2717 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
2719 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2725 /* Parse (possibly empty) attributes. This is a GNU extension.
2729 attributes attribute
2732 __attribute__ ( ( attribute-list ) )
2736 attribute_list , attrib
2741 any-word ( identifier )
2742 any-word ( identifier , nonempty-expr-list )
2743 any-word ( expr-list )
2745 where the "identifier" must not be declared as a type, and
2746 "any-word" may be any identifier (including one declared as a
2747 type), a reserved word storage class specifier, type specifier or
2748 type qualifier. ??? This still leaves out most reserved keywords
2749 (following the old parser), shouldn't we include them, and why not
2750 allow identifiers declared as types to start the arguments? */
2753 c_parser_attributes (c_parser
*parser
)
2755 tree attrs
= NULL_TREE
;
2756 while (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2758 /* ??? Follow the C++ parser rather than using the
2759 lex_untranslated_string kludge. */
2760 parser
->lex_untranslated_string
= true;
2761 c_parser_consume_token (parser
);
2762 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2764 parser
->lex_untranslated_string
= false;
2767 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2769 parser
->lex_untranslated_string
= false;
2770 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2773 /* Parse the attribute list. */
2774 while (c_parser_next_token_is (parser
, CPP_COMMA
)
2775 || c_parser_next_token_is (parser
, CPP_NAME
)
2776 || c_parser_next_token_is (parser
, CPP_KEYWORD
))
2778 tree attr
, attr_name
, attr_args
;
2779 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2781 c_parser_consume_token (parser
);
2784 if (c_parser_next_token_is (parser
, CPP_KEYWORD
))
2786 /* ??? See comment above about what keywords are
2789 switch (c_parser_peek_token (parser
)->keyword
)
2826 /* Accept __attribute__((__const)) as __attribute__((const))
2829 = ridpointers
[(int) c_parser_peek_token (parser
)->keyword
];
2832 attr_name
= c_parser_peek_token (parser
)->value
;
2833 c_parser_consume_token (parser
);
2834 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
2836 attr
= build_tree_list (attr_name
, NULL_TREE
);
2837 attrs
= chainon (attrs
, attr
);
2840 c_parser_consume_token (parser
);
2841 /* Parse the attribute contents. If they start with an
2842 identifier which is followed by a comma or close
2843 parenthesis, then the arguments start with that
2844 identifier; otherwise they are an expression list. */
2845 if (c_parser_next_token_is (parser
, CPP_NAME
)
2846 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
2847 && ((c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
)
2848 || (c_parser_peek_2nd_token (parser
)->type
2849 == CPP_CLOSE_PAREN
)))
2851 tree arg1
= c_parser_peek_token (parser
)->value
;
2852 c_parser_consume_token (parser
);
2853 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2854 attr_args
= build_tree_list (NULL_TREE
, arg1
);
2857 c_parser_consume_token (parser
);
2858 attr_args
= tree_cons (NULL_TREE
, arg1
,
2859 c_parser_expr_list (parser
, false));
2864 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2865 attr_args
= NULL_TREE
;
2867 attr_args
= c_parser_expr_list (parser
, false);
2869 attr
= build_tree_list (attr_name
, attr_args
);
2870 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2871 c_parser_consume_token (parser
);
2874 parser
->lex_untranslated_string
= false;
2875 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2879 attrs
= chainon (attrs
, attr
);
2881 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2882 c_parser_consume_token (parser
);
2885 parser
->lex_untranslated_string
= false;
2886 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2890 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2891 c_parser_consume_token (parser
);
2894 parser
->lex_untranslated_string
= false;
2895 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2899 parser
->lex_untranslated_string
= false;
2904 /* Parse a type name (C90 6.5.5, C99 6.7.6).
2907 specifier-qualifier-list abstract-declarator[opt]
2910 static struct c_type_name
*
2911 c_parser_type_name (c_parser
*parser
)
2913 struct c_declspecs
*specs
= build_null_declspecs ();
2914 struct c_declarator
*declarator
;
2915 struct c_type_name
*ret
;
2917 c_parser_declspecs (parser
, specs
, false, true, true);
2918 if (!specs
->declspecs_seen_p
)
2920 c_parser_error (parser
, "expected specifier-qualifier-list");
2923 pending_xref_error ();
2924 finish_declspecs (specs
);
2925 declarator
= c_parser_declarator (parser
, specs
->type_seen_p
,
2926 C_DTR_ABSTRACT
, &dummy
);
2927 if (declarator
== NULL
)
2929 ret
= XOBNEW (&parser_obstack
, struct c_type_name
);
2931 ret
->declarator
= declarator
;
2935 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
2938 assignment-expression
2939 { initializer-list }
2940 { initializer-list , }
2943 designation[opt] initializer
2944 initializer-list , designation[opt] initializer
2951 designator-list designator
2958 [ constant-expression ]
2970 [ constant-expression ... constant-expression ]
2972 Any expression without commas is accepted in the syntax for the
2973 constant-expressions, with non-constant expressions rejected later.
2975 This function is only used for top-level initializers; for nested
2976 ones, see c_parser_initval. */
2978 static struct c_expr
2979 c_parser_initializer (c_parser
*parser
)
2981 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2982 return c_parser_braced_init (parser
, NULL_TREE
, false);
2986 ret
= c_parser_expr_no_commas (parser
, NULL
);
2987 if (TREE_CODE (ret
.value
) != STRING_CST
2988 && TREE_CODE (ret
.value
) != COMPOUND_LITERAL_EXPR
)
2989 ret
= default_function_array_conversion (ret
);
2994 /* Parse a braced initializer list. TYPE is the type specified for a
2995 compound literal, and NULL_TREE for other initializers and for
2996 nested braced lists. NESTED_P is true for nested braced lists,
2997 false for the list of a compound literal or the list that is the
2998 top-level initializer in a declaration. */
3000 static struct c_expr
3001 c_parser_braced_init (c_parser
*parser
, tree type
, bool nested_p
)
3003 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
3004 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
3005 c_parser_consume_token (parser
);
3007 push_init_level (0);
3009 really_start_incremental_init (type
);
3010 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3012 pedwarn (brace_loc
, OPT_pedantic
, "ISO C forbids empty initializer braces");
3016 /* Parse a non-empty initializer list, possibly with a trailing
3020 c_parser_initelt (parser
);
3023 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3024 c_parser_consume_token (parser
);
3027 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3031 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
3034 ret
.value
= error_mark_node
;
3035 ret
.original_code
= ERROR_MARK
;
3036 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
3039 c_parser_consume_token (parser
);
3040 return pop_init_level (0);
3043 /* Parse a nested initializer, including designators. */
3046 c_parser_initelt (c_parser
*parser
)
3048 /* Parse any designator or designator list. A single array
3049 designator may have the subsequent "=" omitted in GNU C, but a
3050 longer list or a structure member designator may not. */
3051 if (c_parser_next_token_is (parser
, CPP_NAME
)
3052 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
3054 /* Old-style structure member designator. */
3055 set_init_label (c_parser_peek_token (parser
)->value
);
3056 /* Use the colon as the error location. */
3057 pedwarn (c_parser_peek_2nd_token (parser
)->location
, OPT_pedantic
,
3058 "obsolete use of designated initializer with %<:%>");
3059 c_parser_consume_token (parser
);
3060 c_parser_consume_token (parser
);
3064 /* des_seen is 0 if there have been no designators, 1 if there
3065 has been a single array designator and 2 otherwise. */
3067 /* Location of a designator. */
3068 location_t des_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
3069 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
)
3070 || c_parser_next_token_is (parser
, CPP_DOT
))
3072 int des_prev
= des_seen
;
3074 des_loc
= c_parser_peek_token (parser
)->location
;
3077 if (c_parser_next_token_is (parser
, CPP_DOT
))
3080 c_parser_consume_token (parser
);
3081 if (c_parser_next_token_is (parser
, CPP_NAME
))
3083 set_init_label (c_parser_peek_token (parser
)->value
);
3084 c_parser_consume_token (parser
);
3089 init
.value
= error_mark_node
;
3090 init
.original_code
= ERROR_MARK
;
3091 c_parser_error (parser
, "expected identifier");
3092 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3093 process_init_element (init
, false);
3100 location_t ellipsis_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
3101 /* ??? Following the old parser, [ objc-receiver
3102 objc-message-args ] is accepted as an initializer,
3103 being distinguished from a designator by what follows
3104 the first assignment expression inside the square
3105 brackets, but after a first array designator a
3106 subsequent square bracket is for Objective-C taken to
3107 start an expression, using the obsolete form of
3108 designated initializer without '=', rather than
3109 possibly being a second level of designation: in LALR
3110 terms, the '[' is shifted rather than reducing
3111 designator to designator-list. */
3112 if (des_prev
== 1 && c_dialect_objc ())
3114 des_seen
= des_prev
;
3117 if (des_prev
== 0 && c_dialect_objc ())
3119 /* This might be an array designator or an
3120 Objective-C message expression. If the former,
3121 continue parsing here; if the latter, parse the
3122 remainder of the initializer given the starting
3123 primary-expression. ??? It might make sense to
3124 distinguish when des_prev == 1 as well; see
3125 previous comment. */
3127 struct c_expr mexpr
;
3128 c_parser_consume_token (parser
);
3129 if (c_parser_peek_token (parser
)->type
== CPP_NAME
3130 && ((c_parser_peek_token (parser
)->id_kind
3132 || (c_parser_peek_token (parser
)->id_kind
3133 == C_ID_CLASSNAME
)))
3135 /* Type name receiver. */
3136 tree id
= c_parser_peek_token (parser
)->value
;
3137 c_parser_consume_token (parser
);
3138 rec
= objc_get_class_reference (id
);
3139 goto parse_message_args
;
3141 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
3142 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
)
3143 || c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3144 goto array_desig_after_first
;
3145 /* Expression receiver. So far only one part
3146 without commas has been parsed; there might be
3147 more of the expression. */
3149 while (c_parser_next_token_is (parser
, CPP_COMMA
))
3152 c_parser_consume_token (parser
);
3153 next
= c_parser_expr_no_commas (parser
, NULL
);
3154 next
= default_function_array_conversion (next
);
3155 rec
= build_compound_expr (rec
, next
.value
);
3158 /* Now parse the objc-message-args. */
3159 args
= c_parser_objc_message_args (parser
);
3160 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3163 = objc_build_message_expr (build_tree_list (rec
, args
));
3164 mexpr
.original_code
= ERROR_MARK
;
3165 /* Now parse and process the remainder of the
3166 initializer, starting with this message
3167 expression as a primary-expression. */
3168 c_parser_initval (parser
, &mexpr
);
3171 c_parser_consume_token (parser
);
3172 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
3173 array_desig_after_first
:
3174 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3176 ellipsis_loc
= c_parser_peek_token (parser
)->location
;
3177 c_parser_consume_token (parser
);
3178 second
= c_parser_expr_no_commas (parser
, NULL
).value
;
3182 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3184 c_parser_consume_token (parser
);
3185 set_init_index (first
, second
);
3187 pedwarn (ellipsis_loc
, OPT_pedantic
,
3188 "ISO C forbids specifying range of elements to initialize");
3191 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3197 if (c_parser_next_token_is (parser
, CPP_EQ
))
3200 pedwarn (des_loc
, OPT_pedantic
,
3201 "ISO C90 forbids specifying subobject to initialize");
3202 c_parser_consume_token (parser
);
3207 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
3208 "obsolete use of designated initializer without %<=%>");
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
, false);
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
, false);
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
= UNKNOWN_LOCATION
; /* Quiet warning. */
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 %<;%>");
3358 pedwarn (err_loc
, OPT_pedantic
, "ISO C forbids label declarations");
3360 /* We must now have at least one statement, label or declaration. */
3361 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3363 c_parser_error (parser
, "expected declaration or statement");
3364 c_parser_consume_token (parser
);
3367 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
3369 location_t loc
= c_parser_peek_token (parser
)->location
;
3370 if (c_parser_next_token_is_keyword (parser
, RID_CASE
)
3371 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
3372 || (c_parser_next_token_is (parser
, CPP_NAME
)
3373 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
3375 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
3376 label_loc
= c_parser_peek_2nd_token (parser
)->location
;
3378 label_loc
= c_parser_peek_token (parser
)->location
;
3381 c_parser_label (parser
);
3383 else if (!last_label
3384 && c_parser_next_token_starts_declspecs (parser
))
3387 c_parser_declaration_or_fndef (parser
, true, true, true, true);
3390 (pedantic
&& !flag_isoc99
)
3392 : OPT_Wdeclaration_after_statement
,
3393 "ISO 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 pedwarn_c90 (loc
, (pedantic
&& !flag_isoc99
)
3420 : OPT_Wdeclaration_after_statement
,
3421 "ISO 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_at (loc
, """expected %<}%> before %<else%>");
3451 error_at (loc
, "%<else%> without a previous %<if%>");
3452 c_parser_consume_token (parser
);
3461 c_parser_statement_after_labels (parser
);
3464 parser
->error
= false;
3467 error_at (label_loc
, "label at end of compound statement");
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_at (c_parser_peek_token (parser
)->location
,
3544 "a label can only be part of a statement and "
3545 "a declaration is not a statement");
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 protected_set_expr_location (stmt
, loc
);
3793 parser
->in_if_block
= in_if_block
;
3796 /* Parse the condition from an if, do, while or for statements. */
3799 c_parser_condition (c_parser
*parser
)
3803 loc
= c_parser_peek_token (parser
)->location
;
3804 cond
= c_objc_common_truthvalue_conversion
3805 (loc
, c_parser_expression_conv (parser
).value
);
3806 protected_set_expr_location (cond
, loc
);
3807 if (warn_sequence_point
)
3808 verify_sequence_points (cond
);
3812 /* Parse a parenthesized condition from an if, do or while statement.
3818 c_parser_paren_condition (c_parser
*parser
)
3821 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3822 return error_mark_node
;
3823 cond
= c_parser_condition (parser
);
3824 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
3828 /* Parse a statement which is a block in C99. */
3831 c_parser_c99_block_statement (c_parser
*parser
)
3833 tree block
= c_begin_compound_stmt (flag_isoc99
);
3834 c_parser_statement (parser
);
3835 return c_end_compound_stmt (block
, flag_isoc99
);
3838 /* Parse the body of an if statement. This is just parsing a
3839 statement but (a) it is a block in C99, (b) we track whether the
3840 body is an if statement for the sake of -Wparentheses warnings, (c)
3841 we handle an empty body specially for the sake of -Wempty-body
3842 warnings, and (d) we call parser_compound_statement directly
3843 because c_parser_statement_after_labels resets
3844 parser->in_if_block. */
3847 c_parser_if_body (c_parser
*parser
, bool *if_p
)
3849 tree block
= c_begin_compound_stmt (flag_isoc99
);
3850 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
3851 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
3852 || (c_parser_next_token_is (parser
, CPP_NAME
)
3853 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
3854 c_parser_label (parser
);
3855 *if_p
= c_parser_next_token_is_keyword (parser
, RID_IF
);
3856 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3858 location_t loc
= c_parser_peek_token (parser
)->location
;
3859 add_stmt (build_empty_stmt ());
3860 c_parser_consume_token (parser
);
3861 if (!c_parser_next_token_is_keyword (parser
, RID_ELSE
))
3862 warning_at (loc
, OPT_Wempty_body
,
3863 "suggest braces around empty body in an %<if%> statement");
3865 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
3866 add_stmt (c_parser_compound_statement (parser
));
3868 c_parser_statement_after_labels (parser
);
3869 return c_end_compound_stmt (block
, flag_isoc99
);
3872 /* Parse the else body of an if statement. This is just parsing a
3873 statement but (a) it is a block in C99, (b) we handle an empty body
3874 specially for the sake of -Wempty-body warnings. */
3877 c_parser_else_body (c_parser
*parser
)
3879 tree block
= c_begin_compound_stmt (flag_isoc99
);
3880 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
3881 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
3882 || (c_parser_next_token_is (parser
, CPP_NAME
)
3883 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
3884 c_parser_label (parser
);
3885 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3887 warning_at (c_parser_peek_token (parser
)->location
,
3889 "suggest braces around empty body in an %<else%> statement");
3890 add_stmt (build_empty_stmt ());
3891 c_parser_consume_token (parser
);
3894 c_parser_statement_after_labels (parser
);
3895 return c_end_compound_stmt (block
, flag_isoc99
);
3898 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
3901 if ( expression ) statement
3902 if ( expression ) statement else statement
3906 c_parser_if_statement (c_parser
*parser
)
3911 bool first_if
= false;
3912 tree first_body
, second_body
;
3915 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_IF
));
3916 c_parser_consume_token (parser
);
3917 block
= c_begin_compound_stmt (flag_isoc99
);
3918 loc
= c_parser_peek_token (parser
)->location
;
3919 cond
= c_parser_paren_condition (parser
);
3920 in_if_block
= parser
->in_if_block
;
3921 parser
->in_if_block
= true;
3922 first_body
= c_parser_if_body (parser
, &first_if
);
3923 parser
->in_if_block
= in_if_block
;
3924 if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
3926 c_parser_consume_token (parser
);
3927 second_body
= c_parser_else_body (parser
);
3930 second_body
= NULL_TREE
;
3931 c_finish_if_stmt (loc
, cond
, first_body
, second_body
, first_if
);
3932 add_stmt (c_end_compound_stmt (block
, flag_isoc99
));
3935 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
3938 switch (expression) statement
3942 c_parser_switch_statement (c_parser
*parser
)
3944 tree block
, expr
, body
, save_break
;
3945 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SWITCH
));
3946 c_parser_consume_token (parser
);
3947 block
= c_begin_compound_stmt (flag_isoc99
);
3948 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3950 expr
= c_parser_expression (parser
).value
;
3951 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
3954 expr
= error_mark_node
;
3955 c_start_case (expr
);
3956 save_break
= c_break_label
;
3957 c_break_label
= NULL_TREE
;
3958 body
= c_parser_c99_block_statement (parser
);
3959 c_finish_case (body
);
3961 add_stmt (build1 (LABEL_EXPR
, void_type_node
, c_break_label
));
3962 c_break_label
= save_break
;
3963 add_stmt (c_end_compound_stmt (block
, flag_isoc99
));
3966 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
3969 while (expression) statement
3973 c_parser_while_statement (c_parser
*parser
)
3975 tree block
, cond
, body
, save_break
, save_cont
;
3977 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_WHILE
));
3978 c_parser_consume_token (parser
);
3979 block
= c_begin_compound_stmt (flag_isoc99
);
3980 loc
= c_parser_peek_token (parser
)->location
;
3981 cond
= c_parser_paren_condition (parser
);
3982 save_break
= c_break_label
;
3983 c_break_label
= NULL_TREE
;
3984 save_cont
= c_cont_label
;
3985 c_cont_label
= NULL_TREE
;
3986 body
= c_parser_c99_block_statement (parser
);
3987 c_finish_loop (loc
, cond
, NULL
, body
, c_break_label
, c_cont_label
, true);
3988 add_stmt (c_end_compound_stmt (block
, flag_isoc99
));
3989 c_break_label
= save_break
;
3990 c_cont_label
= save_cont
;
3993 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
3996 do statement while ( expression ) ;
4000 c_parser_do_statement (c_parser
*parser
)
4002 tree block
, cond
, body
, save_break
, save_cont
, new_break
, new_cont
;
4004 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_DO
));
4005 c_parser_consume_token (parser
);
4006 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4007 warning_at (c_parser_peek_token (parser
)->location
,
4009 "suggest braces around empty body in %<do%> statement");
4010 block
= c_begin_compound_stmt (flag_isoc99
);
4011 loc
= c_parser_peek_token (parser
)->location
;
4012 save_break
= c_break_label
;
4013 c_break_label
= NULL_TREE
;
4014 save_cont
= c_cont_label
;
4015 c_cont_label
= NULL_TREE
;
4016 body
= c_parser_c99_block_statement (parser
);
4017 c_parser_require_keyword (parser
, RID_WHILE
, "expected %<while%>");
4018 new_break
= c_break_label
;
4019 c_break_label
= save_break
;
4020 new_cont
= c_cont_label
;
4021 c_cont_label
= save_cont
;
4022 cond
= c_parser_paren_condition (parser
);
4023 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
4024 c_parser_skip_to_end_of_block_or_statement (parser
);
4025 c_finish_loop (loc
, cond
, NULL
, body
, new_break
, new_cont
, false);
4026 add_stmt (c_end_compound_stmt (block
, flag_isoc99
));
4029 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
4032 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
4033 for ( nested-declaration expression[opt] ; expression[opt] ) statement
4035 The form with a declaration is new in C99.
4037 ??? In accordance with the old parser, the declaration may be a
4038 nested function, which is then rejected in check_for_loop_decls,
4039 but does it make any sense for this to be included in the grammar?
4040 Note in particular that the nested function does not include a
4041 trailing ';', whereas the "declaration" production includes one.
4042 Also, can we reject bad declarations earlier and cheaper than
4043 check_for_loop_decls? */
4046 c_parser_for_statement (c_parser
*parser
)
4048 tree block
, cond
, incr
, save_break
, save_cont
, body
;
4050 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_FOR
));
4051 loc
= c_parser_peek_token (parser
)->location
;
4052 c_parser_consume_token (parser
);
4053 block
= c_begin_compound_stmt (flag_isoc99
);
4054 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4056 /* Parse the initialization declaration or expression. */
4057 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4059 c_parser_consume_token (parser
);
4060 c_finish_expr_stmt (NULL_TREE
);
4062 else if (c_parser_next_token_starts_declspecs (parser
))
4064 c_parser_declaration_or_fndef (parser
, true, true, true, true);
4065 check_for_loop_decls ();
4067 else if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
4069 /* __extension__ can start a declaration, but is also an
4070 unary operator that can start an expression. Consume all
4071 but the last of a possible series of __extension__ to
4073 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
4074 && (c_parser_peek_2nd_token (parser
)->keyword
4076 c_parser_consume_token (parser
);
4077 if (c_token_starts_declspecs (c_parser_peek_2nd_token (parser
)))
4080 ext
= disable_extension_diagnostics ();
4081 c_parser_consume_token (parser
);
4082 c_parser_declaration_or_fndef (parser
, true, true, true, true);
4083 restore_extension_diagnostics (ext
);
4084 check_for_loop_decls ();
4092 c_finish_expr_stmt (c_parser_expression (parser
).value
);
4093 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4095 /* Parse the loop condition. */
4096 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4098 c_parser_consume_token (parser
);
4103 cond
= c_parser_condition (parser
);
4104 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4106 /* Parse the increment expression. */
4107 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4108 incr
= c_process_expr_stmt (NULL_TREE
);
4110 incr
= c_process_expr_stmt (c_parser_expression (parser
).value
);
4111 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4115 cond
= error_mark_node
;
4116 incr
= error_mark_node
;
4118 save_break
= c_break_label
;
4119 c_break_label
= NULL_TREE
;
4120 save_cont
= c_cont_label
;
4121 c_cont_label
= NULL_TREE
;
4122 body
= c_parser_c99_block_statement (parser
);
4123 c_finish_loop (loc
, cond
, incr
, body
, c_break_label
, c_cont_label
, true);
4124 add_stmt (c_end_compound_stmt (block
, flag_isoc99
));
4125 c_break_label
= save_break
;
4126 c_cont_label
= save_cont
;
4129 /* Parse an asm statement, a GNU extension. This is a full-blown asm
4130 statement with inputs, outputs, clobbers, and volatile tag
4134 asm type-qualifier[opt] ( asm-argument ) ;
4138 asm-string-literal : asm-operands[opt]
4139 asm-string-literal : asm-operands[opt] : asm-operands[opt]
4140 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers
4142 Qualifiers other than volatile are accepted in the syntax but
4146 c_parser_asm_statement (c_parser
*parser
)
4148 tree quals
, str
, outputs
, inputs
, clobbers
, ret
;
4150 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
4151 c_parser_consume_token (parser
);
4152 if (c_parser_next_token_is_keyword (parser
, RID_VOLATILE
))
4154 quals
= c_parser_peek_token (parser
)->value
;
4155 c_parser_consume_token (parser
);
4157 else if (c_parser_next_token_is_keyword (parser
, RID_CONST
)
4158 || c_parser_next_token_is_keyword (parser
, RID_RESTRICT
))
4160 warning_at (c_parser_peek_token (parser
)->location
,
4162 "%E qualifier ignored on asm",
4163 c_parser_peek_token (parser
)->value
);
4165 c_parser_consume_token (parser
);
4169 /* ??? Follow the C++ parser rather than using the
4170 lex_untranslated_string kludge. */
4171 parser
->lex_untranslated_string
= true;
4172 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4174 parser
->lex_untranslated_string
= false;
4177 str
= c_parser_asm_string_literal (parser
);
4178 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4181 outputs
= NULL_TREE
;
4183 clobbers
= NULL_TREE
;
4186 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%> or %<)%>"))
4188 parser
->lex_untranslated_string
= false;
4189 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4193 /* Parse outputs. */
4194 if (c_parser_next_token_is (parser
, CPP_COLON
)
4195 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4196 outputs
= NULL_TREE
;
4198 outputs
= c_parser_asm_operands (parser
, false);
4199 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4202 clobbers
= NULL_TREE
;
4205 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%> or %<)%>"))
4207 parser
->lex_untranslated_string
= false;
4208 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4212 if (c_parser_next_token_is (parser
, CPP_COLON
)
4213 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4216 inputs
= c_parser_asm_operands (parser
, true);
4217 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4219 clobbers
= NULL_TREE
;
4222 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%> or %<)%>"))
4224 parser
->lex_untranslated_string
= false;
4225 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4228 /* Parse clobbers. */
4229 clobbers
= c_parser_asm_clobbers (parser
);
4231 parser
->lex_untranslated_string
= false;
4232 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
4234 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4237 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
4238 c_parser_skip_to_end_of_block_or_statement (parser
);
4239 ret
= build_asm_stmt (quals
, build_asm_expr (str
, outputs
, inputs
,
4244 /* Parse asm operands, a GNU extension. If CONVERT_P (for inputs but
4245 not outputs), apply the default conversion of functions and arrays
4250 asm-operands , asm-operand
4253 asm-string-literal ( expression )
4254 [ identifier ] asm-string-literal ( expression )
4258 c_parser_asm_operands (c_parser
*parser
, bool convert_p
)
4260 tree list
= NULL_TREE
;
4265 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
4267 c_parser_consume_token (parser
);
4268 if (c_parser_next_token_is (parser
, CPP_NAME
))
4270 tree id
= c_parser_peek_token (parser
)->value
;
4271 c_parser_consume_token (parser
);
4272 name
= build_string (IDENTIFIER_LENGTH (id
),
4273 IDENTIFIER_POINTER (id
));
4277 c_parser_error (parser
, "expected identifier");
4278 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
4281 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4286 str
= c_parser_asm_string_literal (parser
);
4287 if (str
== NULL_TREE
)
4289 parser
->lex_untranslated_string
= false;
4290 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4292 parser
->lex_untranslated_string
= true;
4295 expr
= c_parser_expression (parser
);
4297 expr
= default_function_array_conversion (expr
);
4298 parser
->lex_untranslated_string
= true;
4299 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
4301 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4304 list
= chainon (list
, build_tree_list (build_tree_list (name
, str
),
4306 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4307 c_parser_consume_token (parser
);
4314 /* Parse asm clobbers, a GNU extension.
4318 asm-clobbers , asm-string-literal
4322 c_parser_asm_clobbers (c_parser
*parser
)
4324 tree list
= NULL_TREE
;
4327 tree str
= c_parser_asm_string_literal (parser
);
4329 list
= tree_cons (NULL_TREE
, str
, list
);
4332 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4333 c_parser_consume_token (parser
);
4340 /* Parse an expression other than a compound expression; that is, an
4341 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
4342 NULL then it is an Objective-C message expression which is the
4343 primary-expression starting the expression as an initializer.
4345 assignment-expression:
4346 conditional-expression
4347 unary-expression assignment-operator assignment-expression
4349 assignment-operator: one of
4350 = *= /= %= += -= <<= >>= &= ^= |=
4352 In GNU C we accept any conditional expression on the LHS and
4353 diagnose the invalid lvalue rather than producing a syntax
4356 static struct c_expr
4357 c_parser_expr_no_commas (c_parser
*parser
, struct c_expr
*after
)
4359 struct c_expr lhs
, rhs
, ret
;
4360 enum tree_code code
;
4361 location_t op_location
;
4362 gcc_assert (!after
|| c_dialect_objc ());
4363 lhs
= c_parser_conditional_expression (parser
, after
);
4364 op_location
= c_parser_peek_token (parser
)->location
;
4365 switch (c_parser_peek_token (parser
)->type
)
4374 code
= TRUNC_DIV_EXPR
;
4377 code
= TRUNC_MOD_EXPR
;
4392 code
= BIT_AND_EXPR
;
4395 code
= BIT_XOR_EXPR
;
4398 code
= BIT_IOR_EXPR
;
4403 c_parser_consume_token (parser
);
4404 rhs
= c_parser_expr_no_commas (parser
, NULL
);
4405 rhs
= default_function_array_conversion (rhs
);
4406 ret
.value
= build_modify_expr (op_location
, lhs
.value
, code
, rhs
.value
);
4407 if (code
== NOP_EXPR
)
4408 ret
.original_code
= MODIFY_EXPR
;
4411 TREE_NO_WARNING (ret
.value
) = 1;
4412 ret
.original_code
= ERROR_MARK
;
4417 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
4418 is not NULL then it is an Objective-C message expression which is
4419 the primary-expression starting the expression as an initializer.
4421 conditional-expression:
4422 logical-OR-expression
4423 logical-OR-expression ? expression : conditional-expression
4427 conditional-expression:
4428 logical-OR-expression ? : conditional-expression
4431 static struct c_expr
4432 c_parser_conditional_expression (c_parser
*parser
, struct c_expr
*after
)
4434 struct c_expr cond
, exp1
, exp2
, ret
;
4435 location_t cond_loc
;
4437 gcc_assert (!after
|| c_dialect_objc ());
4439 cond_loc
= c_parser_peek_token (parser
)->location
;
4440 cond
= c_parser_binary_expression (parser
, after
);
4441 protected_set_expr_location (cond
.value
, cond_loc
);
4443 if (c_parser_next_token_is_not (parser
, CPP_QUERY
))
4445 cond
= default_function_array_conversion (cond
);
4446 c_parser_consume_token (parser
);
4447 if (c_parser_next_token_is (parser
, CPP_COLON
))
4449 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
4450 "ISO C forbids omitting the middle term of a ?: expression");
4451 /* Make sure first operand is calculated only once. */
4452 exp1
.value
= save_expr (default_conversion (cond
.value
));
4453 cond
.value
= c_objc_common_truthvalue_conversion (cond_loc
, exp1
.value
);
4454 skip_evaluation
+= cond
.value
== truthvalue_true_node
;
4459 = c_objc_common_truthvalue_conversion
4460 (cond_loc
, default_conversion (cond
.value
));
4461 skip_evaluation
+= cond
.value
== truthvalue_false_node
;
4462 exp1
= c_parser_expression_conv (parser
);
4463 skip_evaluation
+= ((cond
.value
== truthvalue_true_node
)
4464 - (cond
.value
== truthvalue_false_node
));
4466 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4468 skip_evaluation
-= cond
.value
== truthvalue_true_node
;
4469 ret
.value
= error_mark_node
;
4470 ret
.original_code
= ERROR_MARK
;
4473 exp2
= c_parser_conditional_expression (parser
, NULL
);
4474 exp2
= default_function_array_conversion (exp2
);
4475 skip_evaluation
-= cond
.value
== truthvalue_true_node
;
4476 ret
.value
= build_conditional_expr (cond
.value
, exp1
.value
, exp2
.value
);
4477 ret
.original_code
= ERROR_MARK
;
4481 /* Parse a binary expression; that is, a logical-OR-expression (C90
4482 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
4483 an Objective-C message expression which is the primary-expression
4484 starting the expression as an initializer.
4486 multiplicative-expression:
4488 multiplicative-expression * cast-expression
4489 multiplicative-expression / cast-expression
4490 multiplicative-expression % cast-expression
4492 additive-expression:
4493 multiplicative-expression
4494 additive-expression + multiplicative-expression
4495 additive-expression - multiplicative-expression
4499 shift-expression << additive-expression
4500 shift-expression >> additive-expression
4502 relational-expression:
4504 relational-expression < shift-expression
4505 relational-expression > shift-expression
4506 relational-expression <= shift-expression
4507 relational-expression >= shift-expression
4509 equality-expression:
4510 relational-expression
4511 equality-expression == relational-expression
4512 equality-expression != relational-expression
4516 AND-expression & equality-expression
4518 exclusive-OR-expression:
4520 exclusive-OR-expression ^ AND-expression
4522 inclusive-OR-expression:
4523 exclusive-OR-expression
4524 inclusive-OR-expression | exclusive-OR-expression
4526 logical-AND-expression:
4527 inclusive-OR-expression
4528 logical-AND-expression && inclusive-OR-expression
4530 logical-OR-expression:
4531 logical-AND-expression
4532 logical-OR-expression || logical-AND-expression
4535 static struct c_expr
4536 c_parser_binary_expression (c_parser
*parser
, struct c_expr
*after
)
4538 /* A binary expression is parsed using operator-precedence parsing,
4539 with the operands being cast expressions. All the binary
4540 operators are left-associative. Thus a binary expression is of
4543 E0 op1 E1 op2 E2 ...
4545 which we represent on a stack. On the stack, the precedence
4546 levels are strictly increasing. When a new operator is
4547 encountered of higher precedence than that at the top of the
4548 stack, it is pushed; its LHS is the top expression, and its RHS
4549 is everything parsed until it is popped. When a new operator is
4550 encountered with precedence less than or equal to that at the top
4551 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
4552 by the result of the operation until the operator at the top of
4553 the stack has lower precedence than the new operator or there is
4554 only one element on the stack; then the top expression is the LHS
4555 of the new operator. In the case of logical AND and OR
4556 expressions, we also need to adjust skip_evaluation as
4557 appropriate when the operators are pushed and popped. */
4559 /* The precedence levels, where 0 is a dummy lowest level used for
4560 the bottom of the stack. */
4576 /* The expression at this stack level. */
4578 /* The precedence of the operator on its left, PREC_NONE at the
4579 bottom of the stack. */
4581 /* The operation on its left. */
4585 /* Location of the binary operator. */
4586 location_t binary_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4589 switch (stack[sp].op) \
4591 case TRUTH_ANDIF_EXPR: \
4592 skip_evaluation -= stack[sp - 1].expr.value == truthvalue_false_node; \
4594 case TRUTH_ORIF_EXPR: \
4595 skip_evaluation -= stack[sp - 1].expr.value == truthvalue_true_node; \
4600 stack[sp - 1].expr \
4601 = default_function_array_conversion (stack[sp - 1].expr); \
4603 = default_function_array_conversion (stack[sp].expr); \
4604 stack[sp - 1].expr = parser_build_binary_op (binary_loc, \
4606 stack[sp - 1].expr, \
4610 gcc_assert (!after
|| c_dialect_objc ());
4611 stack
[0].expr
= c_parser_cast_expression (parser
, after
);
4612 stack
[0].prec
= PREC_NONE
;
4617 enum tree_code ocode
;
4620 switch (c_parser_peek_token (parser
)->type
)
4628 ocode
= TRUNC_DIV_EXPR
;
4632 ocode
= TRUNC_MOD_EXPR
;
4644 ocode
= LSHIFT_EXPR
;
4648 ocode
= RSHIFT_EXPR
;
4662 case CPP_GREATER_EQ
:
4675 oprec
= PREC_BITAND
;
4676 ocode
= BIT_AND_EXPR
;
4679 oprec
= PREC_BITXOR
;
4680 ocode
= BIT_XOR_EXPR
;
4684 ocode
= BIT_IOR_EXPR
;
4687 oprec
= PREC_LOGAND
;
4688 ocode
= TRUTH_ANDIF_EXPR
;
4692 ocode
= TRUTH_ORIF_EXPR
;
4695 /* Not a binary operator, so end of the binary
4699 binary_loc
= c_parser_peek_token (parser
)->location
;
4700 c_parser_consume_token (parser
);
4701 while (oprec
<= stack
[sp
].prec
)
4705 case TRUTH_ANDIF_EXPR
:
4707 = default_function_array_conversion (stack
[sp
].expr
);
4708 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
4709 (binary_loc
, default_conversion (stack
[sp
].expr
.value
));
4710 skip_evaluation
+= stack
[sp
].expr
.value
== truthvalue_false_node
;
4712 case TRUTH_ORIF_EXPR
:
4714 = default_function_array_conversion (stack
[sp
].expr
);
4715 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
4716 (binary_loc
, default_conversion (stack
[sp
].expr
.value
));
4717 skip_evaluation
+= stack
[sp
].expr
.value
== truthvalue_true_node
;
4723 stack
[sp
].expr
= c_parser_cast_expression (parser
, NULL
);
4724 stack
[sp
].prec
= oprec
;
4725 stack
[sp
].op
= ocode
;
4730 return stack
[0].expr
;
4734 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
4735 NULL then it is an Objective-C message expression which is the
4736 primary-expression starting the expression as an initializer.
4740 ( type-name ) unary-expression
4743 static struct c_expr
4744 c_parser_cast_expression (c_parser
*parser
, struct c_expr
*after
)
4746 gcc_assert (!after
|| c_dialect_objc ());
4748 return c_parser_postfix_expression_after_primary (parser
, *after
);
4749 /* If the expression begins with a parenthesized type name, it may
4750 be either a cast or a compound literal; we need to see whether
4751 the next character is '{' to tell the difference. If not, it is
4752 an unary expression. */
4753 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
4754 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
4756 struct c_type_name
*type_name
;
4759 c_parser_consume_token (parser
);
4760 type_name
= c_parser_type_name (parser
);
4761 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4762 if (type_name
== NULL
)
4764 ret
.value
= error_mark_node
;
4765 ret
.original_code
= ERROR_MARK
;
4769 /* Save casted types in the function's used types hash table. */
4770 used_types_insert (type_name
->specs
->type
);
4772 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4773 return c_parser_postfix_expression_after_paren_type (parser
,
4775 expr
= c_parser_cast_expression (parser
, NULL
);
4776 expr
= default_function_array_conversion (expr
);
4777 ret
.value
= c_cast_expr (type_name
, expr
.value
);
4778 ret
.original_code
= ERROR_MARK
;
4782 return c_parser_unary_expression (parser
);
4785 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
4791 unary-operator cast-expression
4792 sizeof unary-expression
4793 sizeof ( type-name )
4795 unary-operator: one of
4801 __alignof__ unary-expression
4802 __alignof__ ( type-name )
4805 unary-operator: one of
4806 __extension__ __real__ __imag__
4808 In addition, the GNU syntax treats ++ and -- as unary operators, so
4809 they may be applied to cast expressions with errors for non-lvalues
4812 static struct c_expr
4813 c_parser_unary_expression (c_parser
*parser
)
4816 struct c_expr ret
, op
;
4817 location_t loc
= c_parser_peek_token (parser
)->location
;
4818 switch (c_parser_peek_token (parser
)->type
)
4821 c_parser_consume_token (parser
);
4822 op
= c_parser_cast_expression (parser
, NULL
);
4823 op
= default_function_array_conversion (op
);
4824 return parser_build_unary_op (PREINCREMENT_EXPR
, op
, loc
);
4825 case CPP_MINUS_MINUS
:
4826 c_parser_consume_token (parser
);
4827 op
= c_parser_cast_expression (parser
, NULL
);
4828 op
= default_function_array_conversion (op
);
4829 return parser_build_unary_op (PREDECREMENT_EXPR
, op
, loc
);
4831 c_parser_consume_token (parser
);
4832 return parser_build_unary_op (ADDR_EXPR
,
4833 c_parser_cast_expression (parser
, NULL
),
4836 c_parser_consume_token (parser
);
4837 op
= c_parser_cast_expression (parser
, NULL
);
4838 op
= default_function_array_conversion (op
);
4839 ret
.value
= build_indirect_ref (loc
, op
.value
, "unary *");
4840 ret
.original_code
= ERROR_MARK
;
4843 if (!c_dialect_objc () && !in_system_header
)
4844 warning_at (c_parser_peek_token (parser
)->location
,
4846 "traditional C rejects the unary plus operator");
4847 c_parser_consume_token (parser
);
4848 op
= c_parser_cast_expression (parser
, NULL
);
4849 op
= default_function_array_conversion (op
);
4850 return parser_build_unary_op (CONVERT_EXPR
, op
, loc
);
4852 c_parser_consume_token (parser
);
4853 op
= c_parser_cast_expression (parser
, NULL
);
4854 op
= default_function_array_conversion (op
);
4855 return parser_build_unary_op (NEGATE_EXPR
, op
, loc
);
4857 c_parser_consume_token (parser
);
4858 op
= c_parser_cast_expression (parser
, NULL
);
4859 op
= default_function_array_conversion (op
);
4860 return parser_build_unary_op (BIT_NOT_EXPR
, op
, loc
);
4862 c_parser_consume_token (parser
);
4863 op
= c_parser_cast_expression (parser
, NULL
);
4864 op
= default_function_array_conversion (op
);
4865 return parser_build_unary_op (TRUTH_NOT_EXPR
, op
, loc
);
4867 /* Refer to the address of a label as a pointer. */
4868 c_parser_consume_token (parser
);
4869 if (c_parser_next_token_is (parser
, CPP_NAME
))
4871 ret
.value
= finish_label_address_expr
4872 (c_parser_peek_token (parser
)->value
, loc
);
4873 c_parser_consume_token (parser
);
4877 c_parser_error (parser
, "expected identifier");
4878 ret
.value
= error_mark_node
;
4880 ret
.original_code
= ERROR_MARK
;
4883 switch (c_parser_peek_token (parser
)->keyword
)
4886 return c_parser_sizeof_expression (parser
);
4888 return c_parser_alignof_expression (parser
);
4890 c_parser_consume_token (parser
);
4891 ext
= disable_extension_diagnostics ();
4892 ret
= c_parser_cast_expression (parser
, NULL
);
4893 restore_extension_diagnostics (ext
);
4896 c_parser_consume_token (parser
);
4897 op
= c_parser_cast_expression (parser
, NULL
);
4898 op
= default_function_array_conversion (op
);
4899 return parser_build_unary_op (REALPART_EXPR
, op
, loc
);
4901 c_parser_consume_token (parser
);
4902 op
= c_parser_cast_expression (parser
, NULL
);
4903 op
= default_function_array_conversion (op
);
4904 return parser_build_unary_op (IMAGPART_EXPR
, op
, loc
);
4906 return c_parser_postfix_expression (parser
);
4909 return c_parser_postfix_expression (parser
);
4913 /* Parse a sizeof expression. */
4915 static struct c_expr
4916 c_parser_sizeof_expression (c_parser
*parser
)
4919 location_t expr_loc
;
4920 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SIZEOF
));
4921 c_parser_consume_token (parser
);
4924 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
4925 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
4927 /* Either sizeof ( type-name ) or sizeof unary-expression
4928 starting with a compound literal. */
4929 struct c_type_name
*type_name
;
4930 c_parser_consume_token (parser
);
4931 expr_loc
= c_parser_peek_token (parser
)->location
;
4932 type_name
= c_parser_type_name (parser
);
4933 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4934 if (type_name
== NULL
)
4939 ret
.value
= error_mark_node
;
4940 ret
.original_code
= ERROR_MARK
;
4943 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4945 expr
= c_parser_postfix_expression_after_paren_type (parser
,
4949 /* sizeof ( type-name ). */
4952 return c_expr_sizeof_type (type_name
);
4956 expr_loc
= c_parser_peek_token (parser
)->location
;
4957 expr
= c_parser_unary_expression (parser
);
4961 if (TREE_CODE (expr
.value
) == COMPONENT_REF
4962 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
4963 error_at (expr_loc
, "%<sizeof%> applied to a bit-field");
4964 return c_expr_sizeof_expr (expr
);
4968 /* Parse an alignof expression. */
4970 static struct c_expr
4971 c_parser_alignof_expression (c_parser
*parser
)
4974 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNOF
));
4975 c_parser_consume_token (parser
);
4978 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
4979 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
4981 /* Either __alignof__ ( type-name ) or __alignof__
4982 unary-expression starting with a compound literal. */
4983 struct c_type_name
*type_name
;
4985 c_parser_consume_token (parser
);
4986 type_name
= c_parser_type_name (parser
);
4987 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4988 if (type_name
== NULL
)
4993 ret
.value
= error_mark_node
;
4994 ret
.original_code
= ERROR_MARK
;
4997 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4999 expr
= c_parser_postfix_expression_after_paren_type (parser
,
5003 /* alignof ( type-name ). */
5006 ret
.value
= c_alignof (groktypename (type_name
));
5007 ret
.original_code
= ERROR_MARK
;
5013 expr
= c_parser_unary_expression (parser
);
5017 ret
.value
= c_alignof_expr (expr
.value
);
5018 ret
.original_code
= ERROR_MARK
;
5023 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
5027 postfix-expression [ expression ]
5028 postfix-expression ( argument-expression-list[opt] )
5029 postfix-expression . identifier
5030 postfix-expression -> identifier
5031 postfix-expression ++
5032 postfix-expression --
5033 ( type-name ) { initializer-list }
5034 ( type-name ) { initializer-list , }
5036 argument-expression-list:
5038 argument-expression-list , argument-expression
5050 (treated as a keyword in GNU C)
5053 ( compound-statement )
5054 __builtin_va_arg ( assignment-expression , type-name )
5055 __builtin_offsetof ( type-name , offsetof-member-designator )
5056 __builtin_choose_expr ( assignment-expression ,
5057 assignment-expression ,
5058 assignment-expression )
5059 __builtin_types_compatible_p ( type-name , type-name )
5061 offsetof-member-designator:
5063 offsetof-member-designator . identifier
5064 offsetof-member-designator [ expression ]
5069 [ objc-receiver objc-message-args ]
5070 @selector ( objc-selector-arg )
5071 @protocol ( identifier )
5072 @encode ( type-name )
5076 static struct c_expr
5077 c_parser_postfix_expression (c_parser
*parser
)
5079 struct c_expr expr
, e1
, e2
, e3
;
5080 struct c_type_name
*t1
, *t2
;
5082 switch (c_parser_peek_token (parser
)->type
)
5085 expr
.value
= c_parser_peek_token (parser
)->value
;
5086 expr
.original_code
= ERROR_MARK
;
5087 loc
= c_parser_peek_token (parser
)->location
;
5088 c_parser_consume_token (parser
);
5089 if (TREE_CODE (expr
.value
) == FIXED_CST
5090 && !targetm
.fixed_point_supported_p ())
5092 error_at (loc
, "fixed-point types not supported for this target");
5093 expr
.value
= error_mark_node
;
5100 expr
.value
= c_parser_peek_token (parser
)->value
;
5101 expr
.original_code
= ERROR_MARK
;
5102 c_parser_consume_token (parser
);
5108 expr
.value
= c_parser_peek_token (parser
)->value
;
5109 expr
.original_code
= STRING_CST
;
5110 c_parser_consume_token (parser
);
5112 case CPP_OBJC_STRING
:
5113 gcc_assert (c_dialect_objc ());
5115 = objc_build_string_object (c_parser_peek_token (parser
)->value
);
5116 expr
.original_code
= ERROR_MARK
;
5117 c_parser_consume_token (parser
);
5120 if (c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
5122 c_parser_error (parser
, "expected expression");
5123 expr
.value
= error_mark_node
;
5124 expr
.original_code
= ERROR_MARK
;
5128 tree id
= c_parser_peek_token (parser
)->value
;
5129 location_t loc
= c_parser_peek_token (parser
)->location
;
5130 c_parser_consume_token (parser
);
5131 expr
.value
= build_external_ref (id
,
5132 (c_parser_peek_token (parser
)->type
5133 == CPP_OPEN_PAREN
), loc
);
5134 expr
.original_code
= ERROR_MARK
;
5137 case CPP_OPEN_PAREN
:
5138 /* A parenthesized expression, statement expression or compound
5140 if (c_parser_peek_2nd_token (parser
)->type
== CPP_OPEN_BRACE
)
5142 /* A statement expression. */
5144 location_t here
= c_parser_peek_token (parser
)->location
;
5145 c_parser_consume_token (parser
);
5146 c_parser_consume_token (parser
);
5147 if (cur_stmt_list
== NULL
)
5149 error_at (here
, "braced-group within expression allowed "
5150 "only inside a function");
5151 parser
->error
= true;
5152 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
5153 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5154 expr
.value
= error_mark_node
;
5155 expr
.original_code
= ERROR_MARK
;
5158 stmt
= c_begin_stmt_expr ();
5159 c_parser_compound_statement_nostart (parser
);
5160 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5162 pedwarn (here
, OPT_pedantic
,
5163 "ISO C forbids braced-groups within expressions");
5164 expr
.value
= c_finish_stmt_expr (stmt
);
5165 expr
.original_code
= ERROR_MARK
;
5167 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
5169 /* A compound literal. ??? Can we actually get here rather
5170 than going directly to
5171 c_parser_postfix_expression_after_paren_type from
5173 struct c_type_name
*type_name
;
5174 c_parser_consume_token (parser
);
5175 type_name
= c_parser_type_name (parser
);
5176 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5178 if (type_name
== NULL
)
5180 expr
.value
= error_mark_node
;
5181 expr
.original_code
= ERROR_MARK
;
5184 expr
= c_parser_postfix_expression_after_paren_type (parser
,
5189 /* A parenthesized expression. */
5190 c_parser_consume_token (parser
);
5191 expr
= c_parser_expression (parser
);
5192 if (TREE_CODE (expr
.value
) == MODIFY_EXPR
)
5193 TREE_NO_WARNING (expr
.value
) = 1;
5194 expr
.original_code
= ERROR_MARK
;
5195 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5200 switch (c_parser_peek_token (parser
)->keyword
)
5202 case RID_FUNCTION_NAME
:
5203 case RID_PRETTY_FUNCTION_NAME
:
5204 case RID_C99_FUNCTION_NAME
:
5205 expr
.value
= fname_decl (c_parser_peek_token (parser
)->location
,
5206 c_parser_peek_token (parser
)->keyword
,
5207 c_parser_peek_token (parser
)->value
);
5208 expr
.original_code
= ERROR_MARK
;
5209 c_parser_consume_token (parser
);
5212 c_parser_consume_token (parser
);
5213 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5215 expr
.value
= error_mark_node
;
5216 expr
.original_code
= ERROR_MARK
;
5219 e1
= c_parser_expr_no_commas (parser
, NULL
);
5220 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5222 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5223 expr
.value
= error_mark_node
;
5224 expr
.original_code
= ERROR_MARK
;
5227 t1
= c_parser_type_name (parser
);
5228 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5232 expr
.value
= error_mark_node
;
5233 expr
.original_code
= ERROR_MARK
;
5237 expr
.value
= build_va_arg (e1
.value
, groktypename (t1
));
5238 expr
.original_code
= ERROR_MARK
;
5242 c_parser_consume_token (parser
);
5243 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5245 expr
.value
= error_mark_node
;
5246 expr
.original_code
= ERROR_MARK
;
5249 t1
= c_parser_type_name (parser
);
5252 expr
.value
= error_mark_node
;
5253 expr
.original_code
= ERROR_MARK
;
5256 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5258 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5259 expr
.value
= error_mark_node
;
5260 expr
.original_code
= ERROR_MARK
;
5264 tree type
= groktypename (t1
);
5266 if (type
== error_mark_node
)
5267 offsetof_ref
= error_mark_node
;
5269 offsetof_ref
= build1 (INDIRECT_REF
, type
, null_pointer_node
);
5270 /* Parse the second argument to __builtin_offsetof. We
5271 must have one identifier, and beyond that we want to
5272 accept sub structure and sub array references. */
5273 if (c_parser_next_token_is (parser
, CPP_NAME
))
5275 offsetof_ref
= build_component_ref
5276 (offsetof_ref
, c_parser_peek_token (parser
)->value
);
5277 c_parser_consume_token (parser
);
5278 while (c_parser_next_token_is (parser
, CPP_DOT
)
5279 || c_parser_next_token_is (parser
,
5281 || c_parser_next_token_is (parser
,
5284 if (c_parser_next_token_is (parser
, CPP_DEREF
))
5286 loc
= c_parser_peek_token (parser
)->location
;
5287 offsetof_ref
= build_array_ref (offsetof_ref
,
5292 else if (c_parser_next_token_is (parser
, CPP_DOT
))
5295 c_parser_consume_token (parser
);
5296 if (c_parser_next_token_is_not (parser
,
5299 c_parser_error (parser
, "expected identifier");
5302 offsetof_ref
= build_component_ref
5304 c_parser_peek_token (parser
)->value
);
5305 c_parser_consume_token (parser
);
5310 loc
= c_parser_peek_token (parser
)->location
;
5311 c_parser_consume_token (parser
);
5312 idx
= c_parser_expression (parser
).value
;
5313 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5315 offsetof_ref
= build_array_ref (offsetof_ref
, idx
, loc
);
5320 c_parser_error (parser
, "expected identifier");
5321 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5323 expr
.value
= fold_offsetof (offsetof_ref
, NULL_TREE
);
5324 expr
.original_code
= ERROR_MARK
;
5327 case RID_CHOOSE_EXPR
:
5328 c_parser_consume_token (parser
);
5329 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5331 expr
.value
= error_mark_node
;
5332 expr
.original_code
= ERROR_MARK
;
5335 loc
= c_parser_peek_token (parser
)->location
;
5336 e1
= c_parser_expr_no_commas (parser
, NULL
);
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 e2
= c_parser_expr_no_commas (parser
, NULL
);
5345 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5347 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5348 expr
.value
= error_mark_node
;
5349 expr
.original_code
= ERROR_MARK
;
5352 e3
= c_parser_expr_no_commas (parser
, NULL
);
5353 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5358 c
= fold (e1
.value
);
5359 if (TREE_CODE (c
) != INTEGER_CST
)
5361 "first argument to %<__builtin_choose_expr%> not"
5363 expr
= integer_zerop (c
) ? e3
: e2
;
5366 case RID_TYPES_COMPATIBLE_P
:
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
;
5374 t1
= c_parser_type_name (parser
);
5377 expr
.value
= error_mark_node
;
5378 expr
.original_code
= ERROR_MARK
;
5381 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5383 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5384 expr
.value
= error_mark_node
;
5385 expr
.original_code
= ERROR_MARK
;
5388 t2
= c_parser_type_name (parser
);
5391 expr
.value
= error_mark_node
;
5392 expr
.original_code
= ERROR_MARK
;
5395 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5400 e1
= TYPE_MAIN_VARIANT (groktypename (t1
));
5401 e2
= TYPE_MAIN_VARIANT (groktypename (t2
));
5403 expr
.value
= comptypes (e1
, e2
)
5404 ? build_int_cst (NULL_TREE
, 1)
5405 : build_int_cst (NULL_TREE
, 0);
5406 expr
.original_code
= ERROR_MARK
;
5409 case RID_AT_SELECTOR
:
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
;
5419 tree sel
= c_parser_objc_selector_arg (parser
);
5420 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5422 expr
.value
= objc_build_selector_expr (sel
);
5423 expr
.original_code
= ERROR_MARK
;
5426 case RID_AT_PROTOCOL
:
5427 gcc_assert (c_dialect_objc ());
5428 c_parser_consume_token (parser
);
5429 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5431 expr
.value
= error_mark_node
;
5432 expr
.original_code
= ERROR_MARK
;
5435 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5437 c_parser_error (parser
, "expected identifier");
5438 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5439 expr
.value
= error_mark_node
;
5440 expr
.original_code
= ERROR_MARK
;
5444 tree id
= c_parser_peek_token (parser
)->value
;
5445 c_parser_consume_token (parser
);
5446 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5448 expr
.value
= objc_build_protocol_expr (id
);
5449 expr
.original_code
= ERROR_MARK
;
5453 /* Extension to support C-structures in the archiver. */
5454 gcc_assert (c_dialect_objc ());
5455 c_parser_consume_token (parser
);
5456 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5458 expr
.value
= error_mark_node
;
5459 expr
.original_code
= ERROR_MARK
;
5462 t1
= c_parser_type_name (parser
);
5465 expr
.value
= error_mark_node
;
5466 expr
.original_code
= ERROR_MARK
;
5467 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5470 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5473 tree type
= groktypename (t1
);
5474 expr
.value
= objc_build_encode_expr (type
);
5475 expr
.original_code
= ERROR_MARK
;
5479 c_parser_error (parser
, "expected expression");
5480 expr
.value
= error_mark_node
;
5481 expr
.original_code
= ERROR_MARK
;
5485 case CPP_OPEN_SQUARE
:
5486 if (c_dialect_objc ())
5488 tree receiver
, args
;
5489 c_parser_consume_token (parser
);
5490 receiver
= c_parser_objc_receiver (parser
);
5491 args
= c_parser_objc_message_args (parser
);
5492 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5494 expr
.value
= objc_build_message_expr (build_tree_list (receiver
,
5496 expr
.original_code
= ERROR_MARK
;
5499 /* Else fall through to report error. */
5501 c_parser_error (parser
, "expected expression");
5502 expr
.value
= error_mark_node
;
5503 expr
.original_code
= ERROR_MARK
;
5506 return c_parser_postfix_expression_after_primary (parser
, expr
);
5509 /* Parse a postfix expression after a parenthesized type name: the
5510 brace-enclosed initializer of a compound literal, possibly followed
5511 by some postfix operators. This is separate because it is not
5512 possible to tell until after the type name whether a cast
5513 expression has a cast or a compound literal, or whether the operand
5514 of sizeof is a parenthesized type name or starts with a compound
5517 static struct c_expr
5518 c_parser_postfix_expression_after_paren_type (c_parser
*parser
,
5519 struct c_type_name
*type_name
)
5524 location_t start_loc
;
5525 start_init (NULL_TREE
, NULL
, 0);
5526 type
= groktypename (type_name
);
5527 start_loc
= c_parser_peek_token (parser
)->location
;
5528 if (type
!= error_mark_node
&& C_TYPE_VARIABLE_SIZE (type
))
5530 error_at (start_loc
, "compound literal has variable size");
5531 type
= error_mark_node
;
5533 init
= c_parser_braced_init (parser
, type
, false);
5535 maybe_warn_string_init (type
, init
);
5538 pedwarn (start_loc
, OPT_pedantic
, "ISO C90 forbids compound literals");
5539 expr
.value
= build_compound_literal (type
, init
.value
);
5540 expr
.original_code
= ERROR_MARK
;
5541 return c_parser_postfix_expression_after_primary (parser
, expr
);
5544 /* Parse a postfix expression after the initial primary or compound
5545 literal; that is, parse a series of postfix operators. */
5547 static struct c_expr
5548 c_parser_postfix_expression_after_primary (c_parser
*parser
,
5551 tree ident
, idx
, exprlist
;
5552 location_t loc
= c_parser_peek_token (parser
)->location
;
5555 switch (c_parser_peek_token (parser
)->type
)
5557 case CPP_OPEN_SQUARE
:
5558 /* Array reference. */
5559 loc
= c_parser_peek_token (parser
)->location
;
5560 c_parser_consume_token (parser
);
5561 idx
= c_parser_expression (parser
).value
;
5562 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5564 expr
.value
= build_array_ref (expr
.value
, idx
, loc
);
5565 expr
.original_code
= ERROR_MARK
;
5567 case CPP_OPEN_PAREN
:
5568 /* Function call. */
5569 c_parser_consume_token (parser
);
5570 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
5571 exprlist
= NULL_TREE
;
5573 exprlist
= c_parser_expr_list (parser
, true);
5574 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5576 expr
.value
= build_function_call (expr
.value
, exprlist
);
5577 expr
.original_code
= ERROR_MARK
;
5578 if (warn_disallowed_functions
)
5579 warn_if_disallowed_function_p (expr
.value
);
5582 /* Structure element reference. */
5583 c_parser_consume_token (parser
);
5584 expr
= default_function_array_conversion (expr
);
5585 if (c_parser_next_token_is (parser
, CPP_NAME
))
5586 ident
= c_parser_peek_token (parser
)->value
;
5589 c_parser_error (parser
, "expected identifier");
5590 expr
.value
= error_mark_node
;
5591 expr
.original_code
= ERROR_MARK
;
5594 c_parser_consume_token (parser
);
5595 expr
.value
= build_component_ref (expr
.value
, ident
);
5596 expr
.original_code
= ERROR_MARK
;
5599 /* Structure element reference. */
5600 c_parser_consume_token (parser
);
5601 expr
= default_function_array_conversion (expr
);
5602 if (c_parser_next_token_is (parser
, CPP_NAME
))
5603 ident
= c_parser_peek_token (parser
)->value
;
5606 c_parser_error (parser
, "expected identifier");
5607 expr
.value
= error_mark_node
;
5608 expr
.original_code
= ERROR_MARK
;
5611 c_parser_consume_token (parser
);
5612 expr
.value
= build_component_ref (build_indirect_ref (loc
,
5616 expr
.original_code
= ERROR_MARK
;
5619 /* Postincrement. */
5620 c_parser_consume_token (parser
);
5621 expr
= default_function_array_conversion (expr
);
5622 expr
.value
= build_unary_op (loc
,
5623 POSTINCREMENT_EXPR
, expr
.value
, 0);
5624 expr
.original_code
= ERROR_MARK
;
5626 case CPP_MINUS_MINUS
:
5627 /* Postdecrement. */
5628 c_parser_consume_token (parser
);
5629 expr
= default_function_array_conversion (expr
);
5630 expr
.value
= build_unary_op (loc
,
5631 POSTDECREMENT_EXPR
, expr
.value
, 0);
5632 expr
.original_code
= ERROR_MARK
;
5640 /* Parse an expression (C90 6.3.17, C99 6.5.17).
5643 assignment-expression
5644 expression , assignment-expression
5647 static struct c_expr
5648 c_parser_expression (c_parser
*parser
)
5651 expr
= c_parser_expr_no_commas (parser
, NULL
);
5652 while (c_parser_next_token_is (parser
, CPP_COMMA
))
5655 c_parser_consume_token (parser
);
5656 next
= c_parser_expr_no_commas (parser
, NULL
);
5657 next
= default_function_array_conversion (next
);
5658 expr
.value
= build_compound_expr (expr
.value
, next
.value
);
5659 expr
.original_code
= COMPOUND_EXPR
;
5664 /* Parse an expression and convert functions or arrays to
5667 static struct c_expr
5668 c_parser_expression_conv (c_parser
*parser
)
5671 expr
= c_parser_expression (parser
);
5672 expr
= default_function_array_conversion (expr
);
5676 /* Parse a non-empty list of expressions. If CONVERT_P, convert
5677 functions and arrays to pointers.
5680 assignment-expression
5681 nonempty-expr-list , assignment-expression
5685 c_parser_expr_list (c_parser
*parser
, bool convert_p
)
5689 expr
= c_parser_expr_no_commas (parser
, NULL
);
5691 expr
= default_function_array_conversion (expr
);
5692 ret
= cur
= build_tree_list (NULL_TREE
, expr
.value
);
5693 while (c_parser_next_token_is (parser
, CPP_COMMA
))
5695 c_parser_consume_token (parser
);
5696 expr
= c_parser_expr_no_commas (parser
, NULL
);
5698 expr
= default_function_array_conversion (expr
);
5699 cur
= TREE_CHAIN (cur
) = build_tree_list (NULL_TREE
, expr
.value
);
5705 /* Parse Objective-C-specific constructs. */
5707 /* Parse an objc-class-definition.
5709 objc-class-definition:
5710 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
5711 objc-class-instance-variables[opt] objc-methodprotolist @end
5712 @implementation identifier objc-superclass[opt]
5713 objc-class-instance-variables[opt]
5714 @interface identifier ( identifier ) objc-protocol-refs[opt]
5715 objc-methodprotolist @end
5716 @implementation identifier ( identifier )
5721 "@interface identifier (" must start "@interface identifier (
5722 identifier ) ...": objc-methodprotolist in the first production may
5723 not start with a parenthesized identifier as a declarator of a data
5724 definition with no declaration specifiers if the objc-superclass,
5725 objc-protocol-refs and objc-class-instance-variables are omitted. */
5728 c_parser_objc_class_definition (c_parser
*parser
)
5733 if (c_parser_next_token_is_keyword (parser
, RID_AT_INTERFACE
))
5735 else if (c_parser_next_token_is_keyword (parser
, RID_AT_IMPLEMENTATION
))
5739 c_parser_consume_token (parser
);
5740 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5742 c_parser_error (parser
, "expected identifier");
5745 id1
= c_parser_peek_token (parser
)->value
;
5746 c_parser_consume_token (parser
);
5747 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
5750 tree proto
= NULL_TREE
;
5751 c_parser_consume_token (parser
);
5752 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5754 c_parser_error (parser
, "expected identifier");
5755 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5758 id2
= c_parser_peek_token (parser
)->value
;
5759 c_parser_consume_token (parser
);
5760 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5763 objc_start_category_implementation (id1
, id2
);
5766 if (c_parser_next_token_is (parser
, CPP_LESS
))
5767 proto
= c_parser_objc_protocol_refs (parser
);
5768 objc_start_category_interface (id1
, id2
, proto
);
5769 c_parser_objc_methodprotolist (parser
);
5770 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
5771 objc_finish_interface ();
5774 if (c_parser_next_token_is (parser
, CPP_COLON
))
5776 c_parser_consume_token (parser
);
5777 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5779 c_parser_error (parser
, "expected identifier");
5782 superclass
= c_parser_peek_token (parser
)->value
;
5783 c_parser_consume_token (parser
);
5786 superclass
= NULL_TREE
;
5789 tree proto
= NULL_TREE
;
5790 if (c_parser_next_token_is (parser
, CPP_LESS
))
5791 proto
= c_parser_objc_protocol_refs (parser
);
5792 objc_start_class_interface (id1
, superclass
, proto
);
5795 objc_start_class_implementation (id1
, superclass
);
5796 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5797 c_parser_objc_class_instance_variables (parser
);
5800 objc_continue_interface ();
5801 c_parser_objc_methodprotolist (parser
);
5802 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
5803 objc_finish_interface ();
5807 objc_continue_implementation ();
5812 /* Parse objc-class-instance-variables.
5814 objc-class-instance-variables:
5815 { objc-instance-variable-decl-list[opt] }
5817 objc-instance-variable-decl-list:
5818 objc-visibility-spec
5819 objc-instance-variable-decl ;
5821 objc-instance-variable-decl-list objc-visibility-spec
5822 objc-instance-variable-decl-list objc-instance-variable-decl ;
5823 objc-instance-variable-decl-list ;
5825 objc-visibility-spec:
5830 objc-instance-variable-decl:
5835 c_parser_objc_class_instance_variables (c_parser
*parser
)
5837 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
5838 c_parser_consume_token (parser
);
5839 while (c_parser_next_token_is_not (parser
, CPP_EOF
))
5842 /* Parse any stray semicolon. */
5843 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5845 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
5846 "extra semicolon in struct or union specified");
5847 c_parser_consume_token (parser
);
5850 /* Stop if at the end of the instance variables. */
5851 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
5853 c_parser_consume_token (parser
);
5856 /* Parse any objc-visibility-spec. */
5857 if (c_parser_next_token_is_keyword (parser
, RID_PRIVATE
))
5859 c_parser_consume_token (parser
);
5860 objc_set_visibility (2);
5863 else if (c_parser_next_token_is_keyword (parser
, RID_PROTECTED
))
5865 c_parser_consume_token (parser
);
5866 objc_set_visibility (0);
5869 else if (c_parser_next_token_is_keyword (parser
, RID_PUBLIC
))
5871 c_parser_consume_token (parser
);
5872 objc_set_visibility (1);
5875 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
5877 c_parser_pragma (parser
, pragma_external
);
5881 /* Parse some comma-separated declarations. */
5882 decls
= c_parser_struct_declaration (parser
);
5884 /* Comma-separated instance variables are chained together in
5885 reverse order; add them one by one. */
5886 tree ivar
= nreverse (decls
);
5887 for (; ivar
; ivar
= TREE_CHAIN (ivar
))
5888 objc_add_instance_variable (copy_node (ivar
));
5890 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5894 /* Parse an objc-class-declaration.
5896 objc-class-declaration:
5897 @class identifier-list ;
5901 c_parser_objc_class_declaration (c_parser
*parser
)
5903 tree list
= NULL_TREE
;
5904 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_CLASS
));
5905 c_parser_consume_token (parser
);
5906 /* Any identifiers, including those declared as type names, are OK
5911 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5913 c_parser_error (parser
, "expected identifier");
5916 id
= c_parser_peek_token (parser
)->value
;
5917 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
5918 c_parser_consume_token (parser
);
5919 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5920 c_parser_consume_token (parser
);
5924 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5925 objc_declare_class (list
);
5928 /* Parse an objc-alias-declaration.
5930 objc-alias-declaration:
5931 @compatibility_alias identifier identifier ;
5935 c_parser_objc_alias_declaration (c_parser
*parser
)
5938 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_ALIAS
));
5939 c_parser_consume_token (parser
);
5940 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5942 c_parser_error (parser
, "expected identifier");
5943 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
5946 id1
= c_parser_peek_token (parser
)->value
;
5947 c_parser_consume_token (parser
);
5948 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5950 c_parser_error (parser
, "expected identifier");
5951 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
5954 id2
= c_parser_peek_token (parser
)->value
;
5955 c_parser_consume_token (parser
);
5956 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5957 objc_declare_alias (id1
, id2
);
5960 /* Parse an objc-protocol-definition.
5962 objc-protocol-definition:
5963 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
5964 @protocol identifier-list ;
5966 "@protocol identifier ;" should be resolved as "@protocol
5967 identifier-list ;": objc-methodprotolist may not start with a
5968 semicolon in the first alternative if objc-protocol-refs are
5972 c_parser_objc_protocol_definition (c_parser
*parser
)
5974 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROTOCOL
));
5975 c_parser_consume_token (parser
);
5976 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5978 c_parser_error (parser
, "expected identifier");
5981 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
5982 || c_parser_peek_2nd_token (parser
)->type
== CPP_SEMICOLON
)
5984 tree list
= NULL_TREE
;
5985 /* Any identifiers, including those declared as type names, are
5990 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5992 c_parser_error (parser
, "expected identifier");
5995 id
= c_parser_peek_token (parser
)->value
;
5996 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
5997 c_parser_consume_token (parser
);
5998 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5999 c_parser_consume_token (parser
);
6003 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
6004 objc_declare_protocols (list
);
6008 tree id
= c_parser_peek_token (parser
)->value
;
6009 tree proto
= NULL_TREE
;
6010 c_parser_consume_token (parser
);
6011 if (c_parser_next_token_is (parser
, CPP_LESS
))
6012 proto
= c_parser_objc_protocol_refs (parser
);
6013 parser
->objc_pq_context
= true;
6014 objc_start_protocol (id
, proto
);
6015 c_parser_objc_methodprotolist (parser
);
6016 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
6017 parser
->objc_pq_context
= false;
6018 objc_finish_interface ();
6022 /* Parse an objc-method-type.
6029 static enum tree_code
6030 c_parser_objc_method_type (c_parser
*parser
)
6032 switch (c_parser_peek_token (parser
)->type
)
6035 c_parser_consume_token (parser
);
6038 c_parser_consume_token (parser
);
6045 /* Parse an objc-method-definition.
6047 objc-method-definition:
6048 objc-method-type objc-method-decl ;[opt] compound-statement
6052 c_parser_objc_method_definition (c_parser
*parser
)
6054 enum tree_code type
= c_parser_objc_method_type (parser
);
6056 objc_set_method_type (type
);
6057 parser
->objc_pq_context
= true;
6058 decl
= c_parser_objc_method_decl (parser
);
6059 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
6061 c_parser_consume_token (parser
);
6062 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
6063 "extra semicolon in method definition specified");
6065 if (!c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6067 c_parser_error (parser
, "expected %<{%>");
6070 parser
->objc_pq_context
= false;
6071 objc_start_method_definition (decl
);
6072 add_stmt (c_parser_compound_statement (parser
));
6073 objc_finish_method_definition (current_function_decl
);
6076 /* Parse an objc-methodprotolist.
6078 objc-methodprotolist:
6080 objc-methodprotolist objc-methodproto
6081 objc-methodprotolist declaration
6082 objc-methodprotolist ;
6084 The declaration is a data definition, which may be missing
6085 declaration specifiers under the same rules and diagnostics as
6086 other data definitions outside functions, and the stray semicolon
6087 is diagnosed the same way as a stray semicolon outside a
6091 c_parser_objc_methodprotolist (c_parser
*parser
)
6095 /* The list is terminated by @end. */
6096 switch (c_parser_peek_token (parser
)->type
)
6099 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
6100 "ISO C does not allow extra %<;%> outside of a function");
6101 c_parser_consume_token (parser
);
6105 c_parser_objc_methodproto (parser
);
6108 c_parser_pragma (parser
, pragma_external
);
6113 if (c_parser_next_token_is_keyword (parser
, RID_AT_END
))
6115 c_parser_declaration_or_fndef (parser
, false, true, false, true);
6121 /* Parse an objc-methodproto.
6124 objc-method-type objc-method-decl ;
6128 c_parser_objc_methodproto (c_parser
*parser
)
6130 enum tree_code type
= c_parser_objc_method_type (parser
);
6132 objc_set_method_type (type
);
6133 /* Remember protocol qualifiers in prototypes. */
6134 parser
->objc_pq_context
= true;
6135 decl
= c_parser_objc_method_decl (parser
);
6136 /* Forget protocol qualifiers here. */
6137 parser
->objc_pq_context
= false;
6138 objc_add_method_declaration (decl
);
6139 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
6142 /* Parse an objc-method-decl.
6145 ( objc-type-name ) objc-selector
6147 ( objc-type-name ) objc-keyword-selector objc-optparmlist
6148 objc-keyword-selector objc-optparmlist
6150 objc-keyword-selector:
6152 objc-keyword-selector objc-keyword-decl
6155 objc-selector : ( objc-type-name ) identifier
6156 objc-selector : identifier
6157 : ( objc-type-name ) identifier
6161 objc-optparms objc-optellipsis
6165 objc-opt-parms , parameter-declaration
6173 c_parser_objc_method_decl (c_parser
*parser
)
6175 tree type
= NULL_TREE
;
6177 tree parms
= NULL_TREE
;
6178 bool ellipsis
= false;
6180 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
6182 c_parser_consume_token (parser
);
6183 type
= c_parser_objc_type_name (parser
);
6184 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6186 sel
= c_parser_objc_selector (parser
);
6187 /* If there is no selector, or a colon follows, we have an
6188 objc-keyword-selector. If there is a selector, and a colon does
6189 not follow, that selector ends the objc-method-decl. */
6190 if (!sel
|| c_parser_next_token_is (parser
, CPP_COLON
))
6193 tree list
= NULL_TREE
;
6196 tree atype
= NULL_TREE
, id
, keyworddecl
;
6197 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6199 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
6201 c_parser_consume_token (parser
);
6202 atype
= c_parser_objc_type_name (parser
);
6203 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6206 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6208 c_parser_error (parser
, "expected identifier");
6209 return error_mark_node
;
6211 id
= c_parser_peek_token (parser
)->value
;
6212 c_parser_consume_token (parser
);
6213 keyworddecl
= objc_build_keyword_decl (tsel
, atype
, id
);
6214 list
= chainon (list
, keyworddecl
);
6215 tsel
= c_parser_objc_selector (parser
);
6216 if (!tsel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6219 /* Parse the optional parameter list. Optional Objective-C
6220 method parameters follow the C syntax, and may include '...'
6221 to denote a variable number of arguments. */
6222 parms
= make_node (TREE_LIST
);
6223 while (c_parser_next_token_is (parser
, CPP_COMMA
))
6225 struct c_parm
*parm
;
6226 c_parser_consume_token (parser
);
6227 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
6230 c_parser_consume_token (parser
);
6233 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
6236 parms
= chainon (parms
,
6237 build_tree_list (NULL_TREE
, grokparm (parm
)));
6241 return objc_build_method_signature (type
, sel
, parms
, ellipsis
);
6244 /* Parse an objc-type-name.
6247 objc-type-qualifiers[opt] type-name
6248 objc-type-qualifiers[opt]
6250 objc-type-qualifiers:
6252 objc-type-qualifiers objc-type-qualifier
6254 objc-type-qualifier: one of
6255 in out inout bycopy byref oneway
6259 c_parser_objc_type_name (c_parser
*parser
)
6261 tree quals
= NULL_TREE
;
6262 struct c_type_name
*type_name
= NULL
;
6263 tree type
= NULL_TREE
;
6266 c_token
*token
= c_parser_peek_token (parser
);
6267 if (token
->type
== CPP_KEYWORD
6268 && (token
->keyword
== RID_IN
6269 || token
->keyword
== RID_OUT
6270 || token
->keyword
== RID_INOUT
6271 || token
->keyword
== RID_BYCOPY
6272 || token
->keyword
== RID_BYREF
6273 || token
->keyword
== RID_ONEWAY
))
6275 quals
= chainon (quals
, build_tree_list (NULL_TREE
, token
->value
));
6276 c_parser_consume_token (parser
);
6281 if (c_parser_next_token_starts_typename (parser
))
6282 type_name
= c_parser_type_name (parser
);
6284 type
= groktypename (type_name
);
6285 return build_tree_list (quals
, type
);
6288 /* Parse objc-protocol-refs.
6295 c_parser_objc_protocol_refs (c_parser
*parser
)
6297 tree list
= NULL_TREE
;
6298 gcc_assert (c_parser_next_token_is (parser
, CPP_LESS
));
6299 c_parser_consume_token (parser
);
6300 /* Any identifiers, including those declared as type names, are OK
6305 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6307 c_parser_error (parser
, "expected identifier");
6310 id
= c_parser_peek_token (parser
)->value
;
6311 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
6312 c_parser_consume_token (parser
);
6313 if (c_parser_next_token_is (parser
, CPP_COMMA
))
6314 c_parser_consume_token (parser
);
6318 c_parser_require (parser
, CPP_GREATER
, "expected %<>%>");
6322 /* Parse an objc-try-catch-statement.
6324 objc-try-catch-statement:
6325 @try compound-statement objc-catch-list[opt]
6326 @try compound-statement objc-catch-list[opt] @finally compound-statement
6329 @catch ( parameter-declaration ) compound-statement
6330 objc-catch-list @catch ( parameter-declaration ) compound-statement
6334 c_parser_objc_try_catch_statement (c_parser
*parser
)
6338 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TRY
));
6339 c_parser_consume_token (parser
);
6340 loc
= c_parser_peek_token (parser
)->location
;
6341 stmt
= c_parser_compound_statement (parser
);
6342 objc_begin_try_stmt (loc
, stmt
);
6343 while (c_parser_next_token_is_keyword (parser
, RID_CATCH
))
6345 struct c_parm
*parm
;
6346 c_parser_consume_token (parser
);
6347 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6349 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
6352 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6355 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6356 objc_begin_catch_clause (grokparm (parm
));
6357 if (c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
6358 c_parser_compound_statement_nostart (parser
);
6359 objc_finish_catch_clause ();
6361 if (c_parser_next_token_is_keyword (parser
, RID_AT_FINALLY
))
6365 c_parser_consume_token (parser
);
6366 finloc
= c_parser_peek_token (parser
)->location
;
6367 finstmt
= c_parser_compound_statement (parser
);
6368 objc_build_finally_clause (finloc
, finstmt
);
6370 objc_finish_try_stmt ();
6373 /* Parse an objc-synchronized-statement.
6375 objc-synchronized-statement:
6376 @synchronized ( expression ) compound-statement
6380 c_parser_objc_synchronized_statement (c_parser
*parser
)
6384 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNCHRONIZED
));
6385 c_parser_consume_token (parser
);
6386 loc
= c_parser_peek_token (parser
)->location
;
6387 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6389 expr
= c_parser_expression (parser
).value
;
6390 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6393 expr
= error_mark_node
;
6394 stmt
= c_parser_compound_statement (parser
);
6395 objc_build_synchronized (loc
, expr
, stmt
);
6398 /* Parse an objc-selector; return NULL_TREE without an error if the
6399 next token is not an objc-selector.
6404 enum struct union if else while do for switch case default
6405 break continue return goto asm sizeof typeof __alignof
6406 unsigned long const short volatile signed restrict _Complex
6407 in out inout bycopy byref oneway int char float double void _Bool
6409 ??? Why this selection of keywords but not, for example, storage
6410 class specifiers? */
6413 c_parser_objc_selector (c_parser
*parser
)
6415 c_token
*token
= c_parser_peek_token (parser
);
6416 tree value
= token
->value
;
6417 if (token
->type
== CPP_NAME
)
6419 c_parser_consume_token (parser
);
6422 if (token
->type
!= CPP_KEYWORD
)
6424 switch (token
->keyword
)
6465 c_parser_consume_token (parser
);
6472 /* Parse an objc-selector-arg.
6476 objc-keywordname-list
6478 objc-keywordname-list:
6480 objc-keywordname-list objc-keywordname
6488 c_parser_objc_selector_arg (c_parser
*parser
)
6490 tree sel
= c_parser_objc_selector (parser
);
6491 tree list
= NULL_TREE
;
6492 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6496 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6498 list
= chainon (list
, build_tree_list (sel
, NULL_TREE
));
6499 sel
= c_parser_objc_selector (parser
);
6500 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6506 /* Parse an objc-receiver.
6515 c_parser_objc_receiver (c_parser
*parser
)
6517 if (c_parser_peek_token (parser
)->type
== CPP_NAME
6518 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
6519 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
6521 tree id
= c_parser_peek_token (parser
)->value
;
6522 c_parser_consume_token (parser
);
6523 return objc_get_class_reference (id
);
6525 return c_parser_expression (parser
).value
;
6528 /* Parse objc-message-args.
6532 objc-keywordarg-list
6534 objc-keywordarg-list:
6536 objc-keywordarg-list objc-keywordarg
6539 objc-selector : objc-keywordexpr
6544 c_parser_objc_message_args (c_parser
*parser
)
6546 tree sel
= c_parser_objc_selector (parser
);
6547 tree list
= NULL_TREE
;
6548 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6553 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6555 keywordexpr
= c_parser_objc_keywordexpr (parser
);
6556 list
= chainon (list
, build_tree_list (sel
, keywordexpr
));
6557 sel
= c_parser_objc_selector (parser
);
6558 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6564 /* Parse an objc-keywordexpr.
6571 c_parser_objc_keywordexpr (c_parser
*parser
)
6573 tree list
= c_parser_expr_list (parser
, true);
6574 if (TREE_CHAIN (list
) == NULL_TREE
)
6576 /* Just return the expression, remove a level of
6578 return TREE_VALUE (list
);
6582 /* We have a comma expression, we will collapse later. */
6588 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
6589 should be considered, statements. ALLOW_STMT is true if we're within
6590 the context of a function and such pragmas are to be allowed. Returns
6591 true if we actually parsed such a pragma. */
6594 c_parser_pragma (c_parser
*parser
, enum pragma_context context
)
6598 id
= c_parser_peek_token (parser
)->pragma_kind
;
6599 gcc_assert (id
!= PRAGMA_NONE
);
6603 case PRAGMA_OMP_BARRIER
:
6604 if (context
!= pragma_compound
)
6606 if (context
== pragma_stmt
)
6607 c_parser_error (parser
, "%<#pragma omp barrier%> may only be "
6608 "used in compound statements");
6611 c_parser_omp_barrier (parser
);
6614 case PRAGMA_OMP_FLUSH
:
6615 if (context
!= pragma_compound
)
6617 if (context
== pragma_stmt
)
6618 c_parser_error (parser
, "%<#pragma omp flush%> may only be "
6619 "used in compound statements");
6622 c_parser_omp_flush (parser
);
6625 case PRAGMA_OMP_TASKWAIT
:
6626 if (context
!= pragma_compound
)
6628 if (context
== pragma_stmt
)
6629 c_parser_error (parser
, "%<#pragma omp taskwait%> may only be "
6630 "used in compound statements");
6633 c_parser_omp_taskwait (parser
);
6636 case PRAGMA_OMP_THREADPRIVATE
:
6637 c_parser_omp_threadprivate (parser
);
6640 case PRAGMA_OMP_SECTION
:
6641 error_at (c_parser_peek_token (parser
)->location
,
6642 "%<#pragma omp section%> may only be used in "
6643 "%<#pragma omp sections%> construct");
6644 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
6647 case PRAGMA_GCC_PCH_PREPROCESS
:
6648 c_parser_error (parser
, "%<#pragma GCC pch_preprocess%> must be first");
6649 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
6653 if (id
< PRAGMA_FIRST_EXTERNAL
)
6655 if (context
== pragma_external
)
6658 c_parser_error (parser
, "expected declaration specifiers");
6659 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
6662 c_parser_omp_construct (parser
);
6668 c_parser_consume_pragma (parser
);
6669 c_invoke_pragma_handler (id
);
6671 /* Skip to EOL, but suppress any error message. Those will have been
6672 generated by the handler routine through calling error, as opposed
6673 to calling c_parser_error. */
6674 parser
->error
= true;
6675 c_parser_skip_to_pragma_eol (parser
);
6680 /* The interface the pragma parsers have to the lexer. */
6683 pragma_lex (tree
*value
)
6685 c_token
*tok
= c_parser_peek_token (the_parser
);
6686 enum cpp_ttype ret
= tok
->type
;
6688 *value
= tok
->value
;
6689 if (ret
== CPP_PRAGMA_EOL
|| ret
== CPP_EOF
)
6693 if (ret
== CPP_KEYWORD
)
6695 c_parser_consume_token (the_parser
);
6702 c_parser_pragma_pch_preprocess (c_parser
*parser
)
6706 c_parser_consume_pragma (parser
);
6707 if (c_parser_next_token_is (parser
, CPP_STRING
))
6709 name
= c_parser_peek_token (parser
)->value
;
6710 c_parser_consume_token (parser
);
6713 c_parser_error (parser
, "expected string literal");
6714 c_parser_skip_to_pragma_eol (parser
);
6717 c_common_pch_pragma (parse_in
, TREE_STRING_POINTER (name
));
6720 /* OpenMP 2.5 parsing routines. */
6722 /* Returns name of the next clause.
6723 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
6724 the token is not consumed. Otherwise appropriate pragma_omp_clause is
6725 returned and the token is consumed. */
6727 static pragma_omp_clause
6728 c_parser_omp_clause_name (c_parser
*parser
)
6730 pragma_omp_clause result
= PRAGMA_OMP_CLAUSE_NONE
;
6732 if (c_parser_next_token_is_keyword (parser
, RID_IF
))
6733 result
= PRAGMA_OMP_CLAUSE_IF
;
6734 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
6735 result
= PRAGMA_OMP_CLAUSE_DEFAULT
;
6736 else if (c_parser_next_token_is (parser
, CPP_NAME
))
6738 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
6743 if (!strcmp ("collapse", p
))
6744 result
= PRAGMA_OMP_CLAUSE_COLLAPSE
;
6745 else if (!strcmp ("copyin", p
))
6746 result
= PRAGMA_OMP_CLAUSE_COPYIN
;
6747 else if (!strcmp ("copyprivate", p
))
6748 result
= PRAGMA_OMP_CLAUSE_COPYPRIVATE
;
6751 if (!strcmp ("firstprivate", p
))
6752 result
= PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
;
6755 if (!strcmp ("lastprivate", p
))
6756 result
= PRAGMA_OMP_CLAUSE_LASTPRIVATE
;
6759 if (!strcmp ("nowait", p
))
6760 result
= PRAGMA_OMP_CLAUSE_NOWAIT
;
6761 else if (!strcmp ("num_threads", p
))
6762 result
= PRAGMA_OMP_CLAUSE_NUM_THREADS
;
6765 if (!strcmp ("ordered", p
))
6766 result
= PRAGMA_OMP_CLAUSE_ORDERED
;
6769 if (!strcmp ("private", p
))
6770 result
= PRAGMA_OMP_CLAUSE_PRIVATE
;
6773 if (!strcmp ("reduction", p
))
6774 result
= PRAGMA_OMP_CLAUSE_REDUCTION
;
6777 if (!strcmp ("schedule", p
))
6778 result
= PRAGMA_OMP_CLAUSE_SCHEDULE
;
6779 else if (!strcmp ("shared", p
))
6780 result
= PRAGMA_OMP_CLAUSE_SHARED
;
6783 if (!strcmp ("untied", p
))
6784 result
= PRAGMA_OMP_CLAUSE_UNTIED
;
6789 if (result
!= PRAGMA_OMP_CLAUSE_NONE
)
6790 c_parser_consume_token (parser
);
6795 /* Validate that a clause of the given type does not already exist. */
6798 check_no_duplicate_clause (tree clauses
, enum omp_clause_code code
,
6803 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
6804 if (OMP_CLAUSE_CODE (c
) == code
)
6806 error ("too many %qs clauses", name
);
6814 variable-list , identifier
6816 If KIND is nonzero, create the appropriate node and install the decl
6817 in OMP_CLAUSE_DECL and add the node to the head of the list.
6819 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
6820 return the list created. */
6823 c_parser_omp_variable_list (c_parser
*parser
, enum omp_clause_code kind
,
6826 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
6827 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
6828 c_parser_error (parser
, "expected identifier");
6830 while (c_parser_next_token_is (parser
, CPP_NAME
)
6831 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
6833 tree t
= lookup_name (c_parser_peek_token (parser
)->value
);
6836 undeclared_variable (c_parser_peek_token (parser
)->value
,
6837 c_parser_peek_token (parser
)->location
);
6838 else if (t
== error_mark_node
)
6842 tree u
= build_omp_clause (kind
);
6843 OMP_CLAUSE_DECL (u
) = t
;
6844 OMP_CLAUSE_CHAIN (u
) = list
;
6848 list
= tree_cons (t
, NULL_TREE
, list
);
6850 c_parser_consume_token (parser
);
6852 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
6855 c_parser_consume_token (parser
);
6861 /* Similarly, but expect leading and trailing parenthesis. This is a very
6862 common case for omp clauses. */
6865 c_parser_omp_var_list_parens (c_parser
*parser
, enum omp_clause_code kind
,
6868 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6870 list
= c_parser_omp_variable_list (parser
, kind
, list
);
6871 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6877 collapse ( constant-expression ) */
6880 c_parser_omp_clause_collapse (c_parser
*parser
, tree list
)
6882 tree c
, num
= error_mark_node
;
6886 check_no_duplicate_clause (list
, OMP_CLAUSE_COLLAPSE
, "collapse");
6888 loc
= c_parser_peek_token (parser
)->location
;
6889 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6891 num
= c_parser_expr_no_commas (parser
, NULL
).value
;
6892 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6894 if (num
== error_mark_node
)
6896 if (!INTEGRAL_TYPE_P (TREE_TYPE (num
))
6897 || !host_integerp (num
, 0)
6898 || (n
= tree_low_cst (num
, 0)) <= 0
6902 "collapse argument needs positive constant integer expression");
6905 c
= build_omp_clause (OMP_CLAUSE_COLLAPSE
);
6906 OMP_CLAUSE_COLLAPSE_EXPR (c
) = num
;
6907 OMP_CLAUSE_CHAIN (c
) = list
;
6912 copyin ( variable-list ) */
6915 c_parser_omp_clause_copyin (c_parser
*parser
, tree list
)
6917 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYIN
, list
);
6921 copyprivate ( variable-list ) */
6924 c_parser_omp_clause_copyprivate (c_parser
*parser
, tree list
)
6926 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYPRIVATE
, list
);
6930 default ( shared | none ) */
6933 c_parser_omp_clause_default (c_parser
*parser
, tree list
)
6935 enum omp_clause_default_kind kind
= OMP_CLAUSE_DEFAULT_UNSPECIFIED
;
6938 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6940 if (c_parser_next_token_is (parser
, CPP_NAME
))
6942 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
6947 if (strcmp ("none", p
) != 0)
6949 kind
= OMP_CLAUSE_DEFAULT_NONE
;
6953 if (strcmp ("shared", p
) != 0)
6955 kind
= OMP_CLAUSE_DEFAULT_SHARED
;
6962 c_parser_consume_token (parser
);
6967 c_parser_error (parser
, "expected %<none%> or %<shared%>");
6969 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6971 if (kind
== OMP_CLAUSE_DEFAULT_UNSPECIFIED
)
6974 check_no_duplicate_clause (list
, OMP_CLAUSE_DEFAULT
, "default");
6975 c
= build_omp_clause (OMP_CLAUSE_DEFAULT
);
6976 OMP_CLAUSE_CHAIN (c
) = list
;
6977 OMP_CLAUSE_DEFAULT_KIND (c
) = kind
;
6983 firstprivate ( variable-list ) */
6986 c_parser_omp_clause_firstprivate (c_parser
*parser
, tree list
)
6988 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FIRSTPRIVATE
, list
);
6992 if ( expression ) */
6995 c_parser_omp_clause_if (c_parser
*parser
, tree list
)
6997 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
6999 tree t
= c_parser_paren_condition (parser
);
7002 check_no_duplicate_clause (list
, OMP_CLAUSE_IF
, "if");
7004 c
= build_omp_clause (OMP_CLAUSE_IF
);
7005 OMP_CLAUSE_IF_EXPR (c
) = t
;
7006 OMP_CLAUSE_CHAIN (c
) = list
;
7010 c_parser_error (parser
, "expected %<(%>");
7016 lastprivate ( variable-list ) */
7019 c_parser_omp_clause_lastprivate (c_parser
*parser
, tree list
)
7021 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_LASTPRIVATE
, list
);
7028 c_parser_omp_clause_nowait (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
7032 check_no_duplicate_clause (list
, OMP_CLAUSE_NOWAIT
, "nowait");
7034 c
= build_omp_clause (OMP_CLAUSE_NOWAIT
);
7035 OMP_CLAUSE_CHAIN (c
) = list
;
7040 num_threads ( expression ) */
7043 c_parser_omp_clause_num_threads (c_parser
*parser
, tree list
)
7045 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7047 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
7048 tree c
, t
= c_parser_expression (parser
).value
;
7050 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7052 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
7054 c_parser_error (parser
, "expected integer expression");
7058 /* Attempt to statically determine when the number isn't positive. */
7059 c
= fold_build2 (LE_EXPR
, boolean_type_node
, t
,
7060 build_int_cst (TREE_TYPE (t
), 0));
7061 if (c
== boolean_true_node
)
7063 warning_at (expr_loc
, 0,
7064 "%<num_threads%> value must be positive");
7065 t
= integer_one_node
;
7068 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_THREADS
, "num_threads");
7070 c
= build_omp_clause (OMP_CLAUSE_NUM_THREADS
);
7071 OMP_CLAUSE_NUM_THREADS_EXPR (c
) = t
;
7072 OMP_CLAUSE_CHAIN (c
) = list
;
7083 c_parser_omp_clause_ordered (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
7087 check_no_duplicate_clause (list
, OMP_CLAUSE_ORDERED
, "ordered");
7089 c
= build_omp_clause (OMP_CLAUSE_ORDERED
);
7090 OMP_CLAUSE_CHAIN (c
) = list
;
7095 private ( variable-list ) */
7098 c_parser_omp_clause_private (c_parser
*parser
, tree list
)
7100 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_PRIVATE
, list
);
7104 reduction ( reduction-operator : variable-list )
7107 One of: + * - & ^ | && || */
7110 c_parser_omp_clause_reduction (c_parser
*parser
, tree list
)
7112 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7114 enum tree_code code
;
7116 switch (c_parser_peek_token (parser
)->type
)
7128 code
= BIT_AND_EXPR
;
7131 code
= BIT_XOR_EXPR
;
7134 code
= BIT_IOR_EXPR
;
7137 code
= TRUTH_ANDIF_EXPR
;
7140 code
= TRUTH_ORIF_EXPR
;
7143 c_parser_error (parser
,
7144 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
7145 "%<^%>, %<|%>, %<&&%>, or %<||%>");
7146 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
7149 c_parser_consume_token (parser
);
7150 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
7154 nl
= c_parser_omp_variable_list (parser
, OMP_CLAUSE_REDUCTION
, list
);
7155 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
7156 OMP_CLAUSE_REDUCTION_CODE (c
) = code
;
7160 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7166 schedule ( schedule-kind )
7167 schedule ( schedule-kind , expression )
7170 static | dynamic | guided | runtime | auto
7174 c_parser_omp_clause_schedule (c_parser
*parser
, tree list
)
7178 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7181 c
= build_omp_clause (OMP_CLAUSE_SCHEDULE
);
7183 if (c_parser_next_token_is (parser
, CPP_NAME
))
7185 tree kind
= c_parser_peek_token (parser
)->value
;
7186 const char *p
= IDENTIFIER_POINTER (kind
);
7191 if (strcmp ("dynamic", p
) != 0)
7193 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_DYNAMIC
;
7197 if (strcmp ("guided", p
) != 0)
7199 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_GUIDED
;
7203 if (strcmp ("runtime", p
) != 0)
7205 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_RUNTIME
;
7212 else if (c_parser_next_token_is_keyword (parser
, RID_STATIC
))
7213 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_STATIC
;
7214 else if (c_parser_next_token_is_keyword (parser
, RID_AUTO
))
7215 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_AUTO
;
7219 c_parser_consume_token (parser
);
7220 if (c_parser_next_token_is (parser
, CPP_COMMA
))
7223 c_parser_consume_token (parser
);
7225 here
= c_parser_peek_token (parser
)->location
;
7226 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
7228 if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_RUNTIME
)
7229 error_at (here
, "schedule %<runtime%> does not take "
7230 "a %<chunk_size%> parameter");
7231 else if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_AUTO
)
7233 "schedule %<auto%> does not take "
7234 "a %<chunk_size%> parameter");
7235 else if (TREE_CODE (TREE_TYPE (t
)) == INTEGER_TYPE
)
7236 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
) = t
;
7238 c_parser_error (parser
, "expected integer expression");
7240 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7243 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7244 "expected %<,%> or %<)%>");
7246 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
7247 OMP_CLAUSE_CHAIN (c
) = list
;
7251 c_parser_error (parser
, "invalid schedule kind");
7252 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
7257 shared ( variable-list ) */
7260 c_parser_omp_clause_shared (c_parser
*parser
, tree list
)
7262 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_SHARED
, list
);
7269 c_parser_omp_clause_untied (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
7273 /* FIXME: Should we allow duplicates? */
7274 check_no_duplicate_clause (list
, OMP_CLAUSE_UNTIED
, "untied");
7276 c
= build_omp_clause (OMP_CLAUSE_UNTIED
);
7277 OMP_CLAUSE_CHAIN (c
) = list
;
7281 /* Parse all OpenMP clauses. The set clauses allowed by the directive
7282 is a bitmask in MASK. Return the list of clauses found; the result
7283 of clause default goes in *pdefault. */
7286 c_parser_omp_all_clauses (c_parser
*parser
, unsigned int mask
,
7289 tree clauses
= NULL
;
7292 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
7295 pragma_omp_clause c_kind
;
7297 tree prev
= clauses
;
7299 if (!first
&& c_parser_next_token_is (parser
, CPP_COMMA
))
7300 c_parser_consume_token (parser
);
7303 here
= c_parser_peek_token (parser
)->location
;
7304 c_kind
= c_parser_omp_clause_name (parser
);
7308 case PRAGMA_OMP_CLAUSE_COLLAPSE
:
7309 clauses
= c_parser_omp_clause_collapse (parser
, clauses
);
7310 c_name
= "collapse";
7312 case PRAGMA_OMP_CLAUSE_COPYIN
:
7313 clauses
= c_parser_omp_clause_copyin (parser
, clauses
);
7316 case PRAGMA_OMP_CLAUSE_COPYPRIVATE
:
7317 clauses
= c_parser_omp_clause_copyprivate (parser
, clauses
);
7318 c_name
= "copyprivate";
7320 case PRAGMA_OMP_CLAUSE_DEFAULT
:
7321 clauses
= c_parser_omp_clause_default (parser
, clauses
);
7324 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
:
7325 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
7326 c_name
= "firstprivate";
7328 case PRAGMA_OMP_CLAUSE_IF
:
7329 clauses
= c_parser_omp_clause_if (parser
, clauses
);
7332 case PRAGMA_OMP_CLAUSE_LASTPRIVATE
:
7333 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
7334 c_name
= "lastprivate";
7336 case PRAGMA_OMP_CLAUSE_NOWAIT
:
7337 clauses
= c_parser_omp_clause_nowait (parser
, clauses
);
7340 case PRAGMA_OMP_CLAUSE_NUM_THREADS
:
7341 clauses
= c_parser_omp_clause_num_threads (parser
, clauses
);
7342 c_name
= "num_threads";
7344 case PRAGMA_OMP_CLAUSE_ORDERED
:
7345 clauses
= c_parser_omp_clause_ordered (parser
, clauses
);
7348 case PRAGMA_OMP_CLAUSE_PRIVATE
:
7349 clauses
= c_parser_omp_clause_private (parser
, clauses
);
7352 case PRAGMA_OMP_CLAUSE_REDUCTION
:
7353 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
7354 c_name
= "reduction";
7356 case PRAGMA_OMP_CLAUSE_SCHEDULE
:
7357 clauses
= c_parser_omp_clause_schedule (parser
, clauses
);
7358 c_name
= "schedule";
7360 case PRAGMA_OMP_CLAUSE_SHARED
:
7361 clauses
= c_parser_omp_clause_shared (parser
, clauses
);
7364 case PRAGMA_OMP_CLAUSE_UNTIED
:
7365 clauses
= c_parser_omp_clause_untied (parser
, clauses
);
7369 c_parser_error (parser
, "expected %<#pragma omp%> clause");
7373 if (((mask
>> c_kind
) & 1) == 0 && !parser
->error
)
7375 /* Remove the invalid clause(s) from the list to avoid
7376 confusing the rest of the compiler. */
7378 error_at (here
, "%qs is not valid for %qs", c_name
, where
);
7383 c_parser_skip_to_pragma_eol (parser
);
7385 return c_finish_omp_clauses (clauses
);
7392 In practice, we're also interested in adding the statement to an
7393 outer node. So it is convenient if we work around the fact that
7394 c_parser_statement calls add_stmt. */
7397 c_parser_omp_structured_block (c_parser
*parser
)
7399 tree stmt
= push_stmt_list ();
7400 c_parser_statement (parser
);
7401 return pop_stmt_list (stmt
);
7405 # pragma omp atomic new-line
7409 x binop= expr | x++ | ++x | x-- | --x
7411 +, *, -, /, &, ^, |, <<, >>
7413 where x is an lvalue expression with scalar type. */
7416 c_parser_omp_atomic (c_parser
*parser
)
7420 enum tree_code code
;
7421 struct c_expr rhs_expr
;
7423 c_parser_skip_to_pragma_eol (parser
);
7425 lhs
= c_parser_unary_expression (parser
).value
;
7426 switch (TREE_CODE (lhs
))
7430 c_parser_skip_to_end_of_block_or_statement (parser
);
7433 case PREINCREMENT_EXPR
:
7434 case POSTINCREMENT_EXPR
:
7435 lhs
= TREE_OPERAND (lhs
, 0);
7437 rhs
= integer_one_node
;
7440 case PREDECREMENT_EXPR
:
7441 case POSTDECREMENT_EXPR
:
7442 lhs
= TREE_OPERAND (lhs
, 0);
7444 rhs
= integer_one_node
;
7448 switch (c_parser_peek_token (parser
)->type
)
7454 code
= TRUNC_DIV_EXPR
;
7469 code
= BIT_AND_EXPR
;
7472 code
= BIT_IOR_EXPR
;
7475 code
= BIT_XOR_EXPR
;
7478 c_parser_error (parser
,
7479 "invalid operator for %<#pragma omp atomic%>");
7483 c_parser_consume_token (parser
);
7484 rhs_expr
= c_parser_expression (parser
);
7485 rhs_expr
= default_function_array_conversion (rhs_expr
);
7486 rhs
= rhs_expr
.value
;
7489 stmt
= c_finish_omp_atomic (code
, lhs
, rhs
);
7490 if (stmt
!= error_mark_node
)
7492 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7497 # pragma omp barrier new-line
7501 c_parser_omp_barrier (c_parser
*parser
)
7503 c_parser_consume_pragma (parser
);
7504 c_parser_skip_to_pragma_eol (parser
);
7506 c_finish_omp_barrier ();
7510 # pragma omp critical [(name)] new-line
7515 c_parser_omp_critical (c_parser
*parser
)
7517 tree stmt
, name
= NULL
;
7519 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
7521 c_parser_consume_token (parser
);
7522 if (c_parser_next_token_is (parser
, CPP_NAME
))
7524 name
= c_parser_peek_token (parser
)->value
;
7525 c_parser_consume_token (parser
);
7526 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7529 c_parser_error (parser
, "expected identifier");
7531 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
7532 c_parser_error (parser
, "expected %<(%> or end of line");
7533 c_parser_skip_to_pragma_eol (parser
);
7535 stmt
= c_parser_omp_structured_block (parser
);
7536 return c_finish_omp_critical (stmt
, name
);
7540 # pragma omp flush flush-vars[opt] new-line
7543 ( variable-list ) */
7546 c_parser_omp_flush (c_parser
*parser
)
7548 c_parser_consume_pragma (parser
);
7549 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
7550 c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
7551 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
7552 c_parser_error (parser
, "expected %<(%> or end of line");
7553 c_parser_skip_to_pragma_eol (parser
);
7555 c_finish_omp_flush ();
7558 /* Parse the restricted form of the for statement allowed by OpenMP.
7559 The real trick here is to determine the loop control variable early
7560 so that we can push a new decl if necessary to make it private. */
7563 c_parser_omp_for_loop (c_parser
*parser
, tree clauses
, tree
*par_clauses
)
7565 tree decl
, cond
, incr
, save_break
, save_cont
, body
, init
, stmt
, cl
;
7566 tree declv
, condv
, incrv
, initv
, for_block
= NULL
, ret
= NULL
;
7568 bool fail
= false, open_brace_parsed
= false;
7569 int i
, collapse
= 1, nbraces
= 0;
7571 for (cl
= clauses
; cl
; cl
= OMP_CLAUSE_CHAIN (cl
))
7572 if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_COLLAPSE
)
7573 collapse
= tree_low_cst (OMP_CLAUSE_COLLAPSE_EXPR (cl
), 0);
7575 gcc_assert (collapse
>= 1);
7577 declv
= make_tree_vec (collapse
);
7578 initv
= make_tree_vec (collapse
);
7579 condv
= make_tree_vec (collapse
);
7580 incrv
= make_tree_vec (collapse
);
7582 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
))
7584 c_parser_error (parser
, "for statement expected");
7587 loc
= c_parser_peek_token (parser
)->location
;
7588 c_parser_consume_token (parser
);
7590 for (i
= 0; i
< collapse
; i
++)
7594 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7597 /* Parse the initialization declaration or expression. */
7598 if (c_parser_next_token_starts_declspecs (parser
))
7602 = tree_cons (NULL
, c_begin_compound_stmt (true), for_block
);
7603 c_parser_declaration_or_fndef (parser
, true, true, true, true);
7604 decl
= check_for_loop_decls ();
7607 if (DECL_INITIAL (decl
) == error_mark_node
)
7608 decl
= error_mark_node
;
7611 else if (c_parser_next_token_is (parser
, CPP_NAME
)
7612 && c_parser_peek_2nd_token (parser
)->type
== CPP_EQ
)
7614 struct c_expr init_exp
;
7615 location_t init_loc
;
7617 decl
= c_parser_postfix_expression (parser
).value
;
7619 c_parser_require (parser
, CPP_EQ
, "expected %<=%>");
7620 init_loc
= c_parser_peek_token (parser
)->location
;
7622 init_exp
= c_parser_expr_no_commas (parser
, NULL
);
7623 init_exp
= default_function_array_conversion (init_exp
);
7624 init
= build_modify_expr (init_loc
,
7625 decl
, NOP_EXPR
, init_exp
.value
);
7626 init
= c_process_expr_stmt (init
);
7628 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7633 c_parser_error (parser
,
7634 "expected iteration declaration or initialization");
7635 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7641 /* Parse the loop condition. */
7643 if (c_parser_next_token_is_not (parser
, CPP_SEMICOLON
))
7645 location_t cond_loc
= c_parser_peek_token (parser
)->location
;
7647 cond
= c_parser_expression_conv (parser
).value
;
7648 cond
= c_objc_common_truthvalue_conversion (cond_loc
, cond
);
7649 protected_set_expr_location (cond
, cond_loc
);
7651 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7653 /* Parse the increment expression. */
7655 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_PAREN
))
7657 location_t incr_loc
= c_parser_peek_token (parser
)->location
;
7659 incr
= c_process_expr_stmt (c_parser_expression (parser
).value
);
7660 protected_set_expr_location (incr
, incr_loc
);
7662 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7664 if (decl
== NULL
|| decl
== error_mark_node
|| init
== error_mark_node
)
7668 TREE_VEC_ELT (declv
, i
) = decl
;
7669 TREE_VEC_ELT (initv
, i
) = init
;
7670 TREE_VEC_ELT (condv
, i
) = cond
;
7671 TREE_VEC_ELT (incrv
, i
) = incr
;
7675 if (i
== collapse
- 1)
7678 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
7679 in between the collapsed for loops to be still considered perfectly
7680 nested. Hopefully the final version clarifies this.
7681 For now handle (multiple) {'s and empty statements. */
7684 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
7686 c_parser_consume_token (parser
);
7689 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
7691 c_parser_consume_token (parser
);
7695 && c_parser_next_token_is (parser
, CPP_SEMICOLON
))
7696 c_parser_consume_token (parser
);
7699 c_parser_error (parser
, "not enough perfectly nested loops");
7702 open_brace_parsed
= true;
7712 nbraces
+= bracecount
;
7715 save_break
= c_break_label
;
7716 c_break_label
= size_one_node
;
7717 save_cont
= c_cont_label
;
7718 c_cont_label
= NULL_TREE
;
7719 body
= push_stmt_list ();
7721 if (open_brace_parsed
)
7723 stmt
= c_begin_compound_stmt (true);
7724 c_parser_compound_statement_nostart (parser
);
7725 add_stmt (c_end_compound_stmt (stmt
, true));
7728 add_stmt (c_parser_c99_block_statement (parser
));
7730 add_stmt (build1 (LABEL_EXPR
, void_type_node
, c_cont_label
));
7732 body
= pop_stmt_list (body
);
7733 c_break_label
= save_break
;
7734 c_cont_label
= save_cont
;
7738 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
7740 c_parser_consume_token (parser
);
7743 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
7744 c_parser_consume_token (parser
);
7747 c_parser_error (parser
, "collapsed loops not perfectly nested");
7750 stmt
= c_begin_compound_stmt (true);
7752 c_parser_compound_statement_nostart (parser
);
7753 body
= c_end_compound_stmt (stmt
, true);
7760 /* Only bother calling c_finish_omp_for if we haven't already generated
7761 an error from the initialization parsing. */
7764 stmt
= c_finish_omp_for (loc
, declv
, initv
, condv
, incrv
, body
, NULL
);
7767 if (par_clauses
!= NULL
)
7770 for (c
= par_clauses
; *c
; )
7771 if (OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_FIRSTPRIVATE
7772 && OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_LASTPRIVATE
)
7773 c
= &OMP_CLAUSE_CHAIN (*c
);
7776 for (i
= 0; i
< collapse
; i
++)
7777 if (TREE_VEC_ELT (declv
, i
) == OMP_CLAUSE_DECL (*c
))
7780 c
= &OMP_CLAUSE_CHAIN (*c
);
7781 else if (OMP_CLAUSE_CODE (*c
) == OMP_CLAUSE_FIRSTPRIVATE
)
7784 "iteration variable %qD should not be firstprivate",
7785 OMP_CLAUSE_DECL (*c
));
7786 *c
= OMP_CLAUSE_CHAIN (*c
);
7790 /* Copy lastprivate (decl) clause to OMP_FOR_CLAUSES,
7791 change it to shared (decl) in
7792 OMP_PARALLEL_CLAUSES. */
7793 tree l
= build_omp_clause (OMP_CLAUSE_LASTPRIVATE
);
7794 OMP_CLAUSE_DECL (l
) = OMP_CLAUSE_DECL (*c
);
7795 OMP_CLAUSE_CHAIN (l
) = clauses
;
7797 OMP_CLAUSE_SET_CODE (*c
, OMP_CLAUSE_SHARED
);
7801 OMP_FOR_CLAUSES (stmt
) = clauses
;
7808 stmt
= c_end_compound_stmt (TREE_VALUE (for_block
), true);
7810 for_block
= TREE_CHAIN (for_block
);
7816 #pragma omp for for-clause[optseq] new-line
7820 #define OMP_FOR_CLAUSE_MASK \
7821 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
7822 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
7823 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
7824 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
7825 | (1u << PRAGMA_OMP_CLAUSE_ORDERED) \
7826 | (1u << PRAGMA_OMP_CLAUSE_SCHEDULE) \
7827 | (1u << PRAGMA_OMP_CLAUSE_COLLAPSE) \
7828 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
7831 c_parser_omp_for (c_parser
*parser
)
7833 tree block
, clauses
, ret
;
7835 clauses
= c_parser_omp_all_clauses (parser
, OMP_FOR_CLAUSE_MASK
,
7838 block
= c_begin_compound_stmt (true);
7839 ret
= c_parser_omp_for_loop (parser
, clauses
, NULL
);
7840 block
= c_end_compound_stmt (block
, true);
7847 # pragma omp master new-line
7852 c_parser_omp_master (c_parser
*parser
)
7854 c_parser_skip_to_pragma_eol (parser
);
7855 return c_finish_omp_master (c_parser_omp_structured_block (parser
));
7859 # pragma omp ordered new-line
7864 c_parser_omp_ordered (c_parser
*parser
)
7866 c_parser_skip_to_pragma_eol (parser
);
7867 return c_finish_omp_ordered (c_parser_omp_structured_block (parser
));
7873 { section-sequence }
7876 section-directive[opt] structured-block
7877 section-sequence section-directive structured-block */
7880 c_parser_omp_sections_scope (c_parser
*parser
)
7883 bool error_suppress
= false;
7886 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
7888 /* Avoid skipping until the end of the block. */
7889 parser
->error
= false;
7893 stmt
= push_stmt_list ();
7895 loc
= c_parser_peek_token (parser
)->location
;
7896 if (c_parser_peek_token (parser
)->pragma_kind
!= PRAGMA_OMP_SECTION
)
7898 substmt
= push_stmt_list ();
7902 c_parser_statement (parser
);
7904 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
7906 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
7908 if (c_parser_next_token_is (parser
, CPP_EOF
))
7912 substmt
= pop_stmt_list (substmt
);
7913 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
7914 SET_EXPR_LOCATION (substmt
, loc
);
7920 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
7922 if (c_parser_next_token_is (parser
, CPP_EOF
))
7925 loc
= c_parser_peek_token (parser
)->location
;
7926 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
7928 c_parser_consume_pragma (parser
);
7929 c_parser_skip_to_pragma_eol (parser
);
7930 error_suppress
= false;
7932 else if (!error_suppress
)
7934 error_at (loc
, "expected %<#pragma omp section%> or %<}%>");
7935 error_suppress
= true;
7938 substmt
= c_parser_omp_structured_block (parser
);
7939 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
7940 SET_EXPR_LOCATION (substmt
, loc
);
7943 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
,
7944 "expected %<#pragma omp section%> or %<}%>");
7946 substmt
= pop_stmt_list (stmt
);
7948 stmt
= make_node (OMP_SECTIONS
);
7949 TREE_TYPE (stmt
) = void_type_node
;
7950 OMP_SECTIONS_BODY (stmt
) = substmt
;
7952 return add_stmt (stmt
);
7956 # pragma omp sections sections-clause[optseq] newline
7960 #define OMP_SECTIONS_CLAUSE_MASK \
7961 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
7962 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
7963 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
7964 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
7965 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
7968 c_parser_omp_sections (c_parser
*parser
)
7970 tree block
, clauses
, ret
;
7972 clauses
= c_parser_omp_all_clauses (parser
, OMP_SECTIONS_CLAUSE_MASK
,
7973 "#pragma omp sections");
7975 block
= c_begin_compound_stmt (true);
7976 ret
= c_parser_omp_sections_scope (parser
);
7978 OMP_SECTIONS_CLAUSES (ret
) = clauses
;
7979 block
= c_end_compound_stmt (block
, true);
7986 # pragma parallel parallel-clause new-line
7987 # pragma parallel for parallel-for-clause new-line
7988 # pragma parallel sections parallel-sections-clause new-line
7991 #define OMP_PARALLEL_CLAUSE_MASK \
7992 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
7993 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
7994 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
7995 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
7996 | (1u << PRAGMA_OMP_CLAUSE_SHARED) \
7997 | (1u << PRAGMA_OMP_CLAUSE_COPYIN) \
7998 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
7999 | (1u << PRAGMA_OMP_CLAUSE_NUM_THREADS))
8002 c_parser_omp_parallel (c_parser
*parser
)
8004 enum pragma_kind p_kind
= PRAGMA_OMP_PARALLEL
;
8005 const char *p_name
= "#pragma omp parallel";
8006 tree stmt
, clauses
, par_clause
, ws_clause
, block
;
8007 unsigned int mask
= OMP_PARALLEL_CLAUSE_MASK
;
8009 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
8011 c_parser_consume_token (parser
);
8012 p_kind
= PRAGMA_OMP_PARALLEL_FOR
;
8013 p_name
= "#pragma omp parallel for";
8014 mask
|= OMP_FOR_CLAUSE_MASK
;
8015 mask
&= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT
);
8017 else if (c_parser_next_token_is (parser
, CPP_NAME
))
8019 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
8020 if (strcmp (p
, "sections") == 0)
8022 c_parser_consume_token (parser
);
8023 p_kind
= PRAGMA_OMP_PARALLEL_SECTIONS
;
8024 p_name
= "#pragma omp parallel sections";
8025 mask
|= OMP_SECTIONS_CLAUSE_MASK
;
8026 mask
&= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT
);
8030 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
);
8034 case PRAGMA_OMP_PARALLEL
:
8035 block
= c_begin_omp_parallel ();
8036 c_parser_statement (parser
);
8037 stmt
= c_finish_omp_parallel (clauses
, block
);
8040 case PRAGMA_OMP_PARALLEL_FOR
:
8041 block
= c_begin_omp_parallel ();
8042 c_split_parallel_clauses (clauses
, &par_clause
, &ws_clause
);
8043 c_parser_omp_for_loop (parser
, ws_clause
, &par_clause
);
8044 stmt
= c_finish_omp_parallel (par_clause
, block
);
8045 OMP_PARALLEL_COMBINED (stmt
) = 1;
8048 case PRAGMA_OMP_PARALLEL_SECTIONS
:
8049 block
= c_begin_omp_parallel ();
8050 c_split_parallel_clauses (clauses
, &par_clause
, &ws_clause
);
8051 stmt
= c_parser_omp_sections_scope (parser
);
8053 OMP_SECTIONS_CLAUSES (stmt
) = ws_clause
;
8054 stmt
= c_finish_omp_parallel (par_clause
, block
);
8055 OMP_PARALLEL_COMBINED (stmt
) = 1;
8066 # pragma omp single single-clause[optseq] new-line
8070 #define OMP_SINGLE_CLAUSE_MASK \
8071 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8072 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8073 | (1u << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
8074 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
8077 c_parser_omp_single (c_parser
*parser
)
8079 tree stmt
= make_node (OMP_SINGLE
);
8080 TREE_TYPE (stmt
) = void_type_node
;
8082 OMP_SINGLE_CLAUSES (stmt
)
8083 = c_parser_omp_all_clauses (parser
, OMP_SINGLE_CLAUSE_MASK
,
8084 "#pragma omp single");
8085 OMP_SINGLE_BODY (stmt
) = c_parser_omp_structured_block (parser
);
8087 return add_stmt (stmt
);
8091 # pragma omp task task-clause[optseq] new-line
8094 #define OMP_TASK_CLAUSE_MASK \
8095 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
8096 | (1u << PRAGMA_OMP_CLAUSE_UNTIED) \
8097 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
8098 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8099 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8100 | (1u << PRAGMA_OMP_CLAUSE_SHARED))
8103 c_parser_omp_task (c_parser
*parser
)
8105 tree clauses
, block
;
8107 clauses
= c_parser_omp_all_clauses (parser
, OMP_TASK_CLAUSE_MASK
,
8108 "#pragma omp task");
8110 block
= c_begin_omp_task ();
8111 c_parser_statement (parser
);
8112 return c_finish_omp_task (clauses
, block
);
8116 # pragma omp taskwait new-line
8120 c_parser_omp_taskwait (c_parser
*parser
)
8122 c_parser_consume_pragma (parser
);
8123 c_parser_skip_to_pragma_eol (parser
);
8125 c_finish_omp_taskwait ();
8128 /* Main entry point to parsing most OpenMP pragmas. */
8131 c_parser_omp_construct (c_parser
*parser
)
8133 enum pragma_kind p_kind
;
8137 loc
= c_parser_peek_token (parser
)->location
;
8138 p_kind
= c_parser_peek_token (parser
)->pragma_kind
;
8139 c_parser_consume_pragma (parser
);
8141 /* For all constructs below except #pragma omp atomic
8142 MUST_NOT_THROW catch handlers are needed when exceptions
8144 if (p_kind
!= PRAGMA_OMP_ATOMIC
)
8145 c_maybe_initialize_eh ();
8149 case PRAGMA_OMP_ATOMIC
:
8150 c_parser_omp_atomic (parser
);
8152 case PRAGMA_OMP_CRITICAL
:
8153 stmt
= c_parser_omp_critical (parser
);
8155 case PRAGMA_OMP_FOR
:
8156 stmt
= c_parser_omp_for (parser
);
8158 case PRAGMA_OMP_MASTER
:
8159 stmt
= c_parser_omp_master (parser
);
8161 case PRAGMA_OMP_ORDERED
:
8162 stmt
= c_parser_omp_ordered (parser
);
8164 case PRAGMA_OMP_PARALLEL
:
8165 stmt
= c_parser_omp_parallel (parser
);
8167 case PRAGMA_OMP_SECTIONS
:
8168 stmt
= c_parser_omp_sections (parser
);
8170 case PRAGMA_OMP_SINGLE
:
8171 stmt
= c_parser_omp_single (parser
);
8173 case PRAGMA_OMP_TASK
:
8174 stmt
= c_parser_omp_task (parser
);
8181 SET_EXPR_LOCATION (stmt
, loc
);
8186 # pragma omp threadprivate (variable-list) */
8189 c_parser_omp_threadprivate (c_parser
*parser
)
8193 c_parser_consume_pragma (parser
);
8194 vars
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
8196 /* Mark every variable in VARS to be assigned thread local storage. */
8197 for (t
= vars
; t
; t
= TREE_CHAIN (t
))
8199 tree v
= TREE_PURPOSE (t
);
8201 /* If V had already been marked threadprivate, it doesn't matter
8202 whether it had been used prior to this point. */
8203 if (TREE_CODE (v
) != VAR_DECL
)
8204 error ("%qD is not a variable", v
);
8205 else if (TREE_USED (v
) && !C_DECL_THREADPRIVATE_P (v
))
8206 error ("%qE declared %<threadprivate%> after first use", v
);
8207 else if (! TREE_STATIC (v
) && ! DECL_EXTERNAL (v
))
8208 error ("automatic variable %qE cannot be %<threadprivate%>", v
);
8209 else if (TREE_TYPE (v
) == error_mark_node
)
8211 else if (! COMPLETE_TYPE_P (TREE_TYPE (v
)))
8212 error ("%<threadprivate%> %qE has incomplete type", v
);
8215 if (! DECL_THREAD_LOCAL_P (v
))
8217 DECL_TLS_MODEL (v
) = decl_default_tls_model (v
);
8218 /* If rtl has been already set for this var, call
8219 make_decl_rtl once again, so that encode_section_info
8220 has a chance to look at the new decl flags. */
8221 if (DECL_RTL_SET_P (v
))
8224 C_DECL_THREADPRIVATE_P (v
) = 1;
8228 c_parser_skip_to_pragma_eol (parser
);
8232 /* Parse a single source file. */
8237 /* Use local storage to begin. If the first token is a pragma, parse it.
8238 If it is #pragma GCC pch_preprocess, then this will load a PCH file
8239 which will cause garbage collection. */
8242 memset (&tparser
, 0, sizeof tparser
);
8243 the_parser
= &tparser
;
8245 if (c_parser_peek_token (&tparser
)->pragma_kind
== PRAGMA_GCC_PCH_PREPROCESS
)
8246 c_parser_pragma_pch_preprocess (&tparser
);
8248 the_parser
= GGC_NEW (c_parser
);
8249 *the_parser
= tparser
;
8251 c_parser_translation_unit (the_parser
);
8255 #include "gt-c-parser.h"