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"
63 /* Initialization routine for this file. */
68 /* The only initialization required is of the reserved word
79 mask |= D_ASM | D_EXT;
83 if (!c_dialect_objc ())
84 mask |= D_OBJC | D_CXX_OBJC;
86 ridpointers = GGC_CNEWVEC (tree, (int) RID_MAX);
87 for (i = 0; i < num_c_common_reswords; i++)
89 /* If a keyword is disabled, do not enter it into the table
90 and so create a canonical spelling that isn't a keyword. */
91 if (c_common_reswords[i].disable & mask)
94 && (c_common_reswords[i].disable & D_CXXWARN))
96 id = get_identifier (c_common_reswords[i].word);
97 C_SET_RID_CODE (id, RID_CXX_COMPAT_WARN);
98 C_IS_RESERVED_WORD (id) = 1;
103 id = get_identifier (c_common_reswords[i].word);
104 C_SET_RID_CODE (id, c_common_reswords[i].rid);
105 C_IS_RESERVED_WORD (id) = 1;
106 ridpointers [(int) c_common_reswords[i].rid] = id;
110 /* The C lexer intermediates between the lexer in cpplib and c-lex.c
111 and the C parser. Unlike the C++ lexer, the parser structure
112 stores the lexer information instead of using a separate structure.
113 Identifiers are separated into ordinary identifiers, type names,
114 keywords and some other Objective-C types of identifiers, and some
115 look-ahead is maintained.
117 ??? It might be a good idea to lex the whole file up front (as for
118 C++). It would then be possible to share more of the C and C++
119 lexer code, if desired. */
121 /* The following local token type is used. */
124 #define CPP_KEYWORD ((enum cpp_ttype) (N_TTYPES + 1))
126 /* More information about the type of a CPP_NAME token. */
127 typedef enum c_id_kind {
128 /* An ordinary identifier. */
130 /* An identifier declared as a typedef name. */
132 /* An identifier declared as an Objective-C class name. */
134 /* Not an identifier. */
138 /* A single C token after string literal concatenation and conversion
139 of preprocessing tokens to tokens. */
140 typedef struct c_token GTY (())
142 /* The kind of token. */
143 ENUM_BITFIELD (cpp_ttype) type : 8;
144 /* If this token is a CPP_NAME, this value indicates whether also
145 declared as some kind of type. Otherwise, it is C_ID_NONE. */
146 ENUM_BITFIELD (c_id_kind) id_kind : 8;
147 /* If this token is a keyword, this value indicates which keyword.
148 Otherwise, this value is RID_MAX. */
149 ENUM_BITFIELD (rid) keyword : 8;
150 /* If this token is a CPP_PRAGMA, this indicates the pragma that
151 was seen. Otherwise it is PRAGMA_NONE. */
152 ENUM_BITFIELD (pragma_kind) pragma_kind : 8;
153 /* The value associated with this token, if any. */
155 /* The location at which this token was found. */
159 /* A parser structure recording information about the state and
160 context of parsing. Includes lexer information with up to two
161 tokens of look-ahead; more are not needed for C. */
162 typedef struct c_parser GTY(())
164 /* The look-ahead tokens. */
166 /* How many look-ahead tokens are available (0, 1 or 2). */
168 /* True if a syntax error is being recovered from; false otherwise.
169 c_parser_error sets this flag. It should clear this flag when
170 enough tokens have been consumed to recover from the error. */
171 BOOL_BITFIELD error : 1;
172 /* True if we're processing a pragma, and shouldn't automatically
173 consume CPP_PRAGMA_EOL. */
174 BOOL_BITFIELD in_pragma : 1;
175 /* True if we're parsing the outermost block of an if statement. */
176 BOOL_BITFIELD in_if_block : 1;
177 /* True if we want to lex an untranslated string. */
178 BOOL_BITFIELD lex_untranslated_string : 1;
179 /* Objective-C specific parser/lexer information. */
180 BOOL_BITFIELD objc_pq_context : 1;
181 /* The following flag is needed to contextualize Objective-C lexical
182 analysis. In some cases (e.g., 'int NSObject;'), it is
183 undesirable to bind an identifier to an Objective-C class, even
184 if a class with that name exists. */
185 BOOL_BITFIELD objc_need_raw_identifier : 1;
189 /* The actual parser and external interface. ??? Does this need to be
190 garbage-collected? */
192 static GTY (()) c_parser *the_parser;
195 /* Read in and lex a single token, storing it in *TOKEN. */
198 c_lex_one_token (c_parser *parser, c_token *token)
200 timevar_push (TV_LEX);
202 token->type = c_lex_with_flags (&token->value, &token->location, NULL,
203 (parser->lex_untranslated_string
204 ? C_LEX_STRING_NO_TRANSLATE : 0));
205 token->id_kind = C_ID_NONE;
206 token->keyword = RID_MAX;
207 token->pragma_kind = PRAGMA_NONE;
215 bool objc_force_identifier = parser->objc_need_raw_identifier;
216 if (c_dialect_objc ())
217 parser->objc_need_raw_identifier = false;
219 if (C_IS_RESERVED_WORD (token->value))
221 enum rid rid_code = C_RID_CODE (token->value);
223 if (rid_code == RID_CXX_COMPAT_WARN)
225 warning_at (token->location,
227 "identifier %qs conflicts with C++ keyword",
228 IDENTIFIER_POINTER (token->value));
230 else if (c_dialect_objc ())
232 if (!objc_is_reserved_word (token->value)
233 && (!OBJC_IS_PQ_KEYWORD (rid_code)
234 || parser->objc_pq_context))
236 /* Return the canonical spelling for this keyword. */
237 token->value = ridpointers[(int) rid_code];
238 token->type = CPP_KEYWORD;
239 token->keyword = rid_code;
245 token->type = CPP_KEYWORD;
246 token->keyword = rid_code;
251 decl = lookup_name (token->value);
254 if (TREE_CODE (decl) == TYPE_DECL)
256 token->id_kind = C_ID_TYPENAME;
260 else if (c_dialect_objc ())
262 tree objc_interface_decl = objc_is_class_name (token->value);
263 /* Objective-C class names are in the same namespace as
264 variables and typedefs, and hence are shadowed by local
266 if (objc_interface_decl
267 && (global_bindings_p ()
268 || (!objc_force_identifier && !decl)))
270 token->value = objc_interface_decl;
271 token->id_kind = C_ID_CLASSNAME;
275 token->id_kind = C_ID_ID;
279 /* This only happens in Objective-C; it must be a keyword. */
280 token->type = CPP_KEYWORD;
281 token->keyword = C_RID_CODE (token->value);
285 case CPP_CLOSE_PAREN:
287 /* These tokens may affect the interpretation of any identifiers
288 following, if doing Objective-C. */
289 if (c_dialect_objc ())
290 parser->objc_need_raw_identifier = false;
293 /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */
294 token->pragma_kind = (enum pragma_kind) TREE_INT_CST_LOW (token->value);
300 timevar_pop (TV_LEX);
303 /* Return a pointer to the next token from PARSER, reading it in if
306 static inline c_token *
307 c_parser_peek_token (c_parser *parser)
309 if (parser->tokens_avail == 0)
311 c_lex_one_token (parser, &parser->tokens[0]);
312 parser->tokens_avail = 1;
314 return &parser->tokens[0];
317 /* Return true if the next token from PARSER has the indicated
321 c_parser_next_token_is (c_parser *parser, enum cpp_ttype type)
323 return c_parser_peek_token (parser)->type == type;
326 /* Return true if the next token from PARSER does not have the
330 c_parser_next_token_is_not (c_parser *parser, enum cpp_ttype type)
332 return !c_parser_next_token_is (parser, type);
335 /* Return true if the next token from PARSER is the indicated
339 c_parser_next_token_is_keyword (c_parser *parser, enum rid keyword)
341 return c_parser_peek_token (parser)->keyword == keyword;
344 /* Return true if TOKEN can start a type name,
347 c_token_starts_typename (c_token *token)
352 switch (token->id_kind)
359 gcc_assert (c_dialect_objc ());
365 switch (token->keyword)
397 if (c_dialect_objc ())
405 /* Return true if the next token from PARSER can start a type name,
408 c_parser_next_token_starts_typename (c_parser *parser)
410 c_token *token = c_parser_peek_token (parser);
411 return c_token_starts_typename (token);
414 /* Return true if TOKEN can start declaration specifiers, false
417 c_token_starts_declspecs (c_token *token)
422 switch (token->id_kind)
429 gcc_assert (c_dialect_objc ());
435 switch (token->keyword)
474 if (c_dialect_objc ())
482 /* Return true if the next token from PARSER can start declaration
483 specifiers, false otherwise. */
485 c_parser_next_token_starts_declspecs (c_parser *parser)
487 c_token *token = c_parser_peek_token (parser);
488 return c_token_starts_declspecs (token);
491 /* Return a pointer to the next-but-one token from PARSER, reading it
492 in if necessary. The next token is already read in. */
495 c_parser_peek_2nd_token (c_parser *parser)
497 if (parser->tokens_avail >= 2)
498 return &parser->tokens[1];
499 gcc_assert (parser->tokens_avail == 1);
500 gcc_assert (parser->tokens[0].type != CPP_EOF);
501 gcc_assert (parser->tokens[0].type != CPP_PRAGMA_EOL);
502 c_lex_one_token (parser, &parser->tokens[1]);
503 parser->tokens_avail = 2;
504 return &parser->tokens[1];
507 /* Consume the next token from PARSER. */
510 c_parser_consume_token (c_parser *parser)
512 gcc_assert (parser->tokens_avail >= 1);
513 gcc_assert (parser->tokens[0].type != CPP_EOF);
514 gcc_assert (!parser->in_pragma || parser->tokens[0].type != CPP_PRAGMA_EOL);
515 gcc_assert (parser->error || parser->tokens[0].type != CPP_PRAGMA);
516 if (parser->tokens_avail == 2)
517 parser->tokens[0] = parser->tokens[1];
518 parser->tokens_avail--;
521 /* Expect the current token to be a #pragma. Consume it and remember
522 that we've begun parsing a pragma. */
525 c_parser_consume_pragma (c_parser *parser)
527 gcc_assert (!parser->in_pragma);
528 gcc_assert (parser->tokens_avail >= 1);
529 gcc_assert (parser->tokens[0].type == CPP_PRAGMA);
530 if (parser->tokens_avail == 2)
531 parser->tokens[0] = parser->tokens[1];
532 parser->tokens_avail--;
533 parser->in_pragma = true;
536 /* Update the globals input_location and in_system_header from
539 c_parser_set_source_position_from_token (c_token *token)
541 if (token->type != CPP_EOF)
543 input_location = token->location;
547 /* Issue a diagnostic of the form
548 FILE:LINE: MESSAGE before TOKEN
549 where TOKEN is the next token in the input stream of PARSER.
550 MESSAGE (specified by the caller) is usually of the form "expected
553 Do not issue a diagnostic if still recovering from an error.
555 ??? This is taken from the C++ parser, but building up messages in
556 this way is not i18n-friendly and some other approach should be
560 c_parser_error (c_parser *parser, const char *gmsgid)
562 c_token *token = c_parser_peek_token (parser);
565 parser->error = true;
568 /* This diagnostic makes more sense if it is tagged to the line of
569 the token we just peeked at. */
570 c_parser_set_source_position_from_token (token);
571 c_parse_error (gmsgid,
572 /* Because c_parse_error does not understand
573 CPP_KEYWORD, keywords are treated like
575 (token->type == CPP_KEYWORD ? CPP_NAME : token->type),
579 /* If the next token is of the indicated TYPE, consume it. Otherwise,
580 issue the error MSGID. If MSGID is NULL then a message has already
581 been produced and no message will be produced this time. Returns
582 true if found, false otherwise. */
585 c_parser_require (c_parser *parser,
589 if (c_parser_next_token_is (parser, type))
591 c_parser_consume_token (parser);
596 c_parser_error (parser, msgid);
601 /* If the next token is the indicated keyword, consume it. Otherwise,
602 issue the error MSGID. Returns true if found, false otherwise. */
605 c_parser_require_keyword (c_parser *parser,
609 if (c_parser_next_token_is_keyword (parser, keyword))
611 c_parser_consume_token (parser);
616 c_parser_error (parser, msgid);
621 /* Like c_parser_require, except that tokens will be skipped until the
622 desired token is found. An error message is still produced if the
623 next token is not as expected. If MSGID is NULL then a message has
624 already been produced and no message will be produced this
628 c_parser_skip_until_found (c_parser *parser,
632 unsigned nesting_depth = 0;
634 if (c_parser_require (parser, type, msgid))
637 /* Skip tokens until the desired token is found. */
640 /* Peek at the next token. */
641 c_token *token = c_parser_peek_token (parser);
642 /* If we've reached the token we want, consume it and stop. */
643 if (token->type == type && !nesting_depth)
645 c_parser_consume_token (parser);
649 /* If we've run out of tokens, stop. */
650 if (token->type == CPP_EOF)
652 if (token->type == CPP_PRAGMA_EOL && parser->in_pragma)
654 if (token->type == CPP_OPEN_BRACE
655 || token->type == CPP_OPEN_PAREN
656 || token->type == CPP_OPEN_SQUARE)
658 else if (token->type == CPP_CLOSE_BRACE
659 || token->type == CPP_CLOSE_PAREN
660 || token->type == CPP_CLOSE_SQUARE)
662 if (nesting_depth-- == 0)
665 /* Consume this token. */
666 c_parser_consume_token (parser);
668 parser->error = false;
671 /* Skip tokens until the end of a parameter is found, but do not
672 consume the comma, semicolon or closing delimiter. */
675 c_parser_skip_to_end_of_parameter (c_parser *parser)
677 unsigned nesting_depth = 0;
681 c_token *token = c_parser_peek_token (parser);
682 if ((token->type == CPP_COMMA || token->type == CPP_SEMICOLON)
685 /* If we've run out of tokens, stop. */
686 if (token->type == CPP_EOF)
688 if (token->type == CPP_PRAGMA_EOL && parser->in_pragma)
690 if (token->type == CPP_OPEN_BRACE
691 || token->type == CPP_OPEN_PAREN
692 || token->type == CPP_OPEN_SQUARE)
694 else if (token->type == CPP_CLOSE_BRACE
695 || token->type == CPP_CLOSE_PAREN
696 || token->type == CPP_CLOSE_SQUARE)
698 if (nesting_depth-- == 0)
701 /* Consume this token. */
702 c_parser_consume_token (parser);
704 parser->error = false;
707 /* Expect to be at the end of the pragma directive and consume an
708 end of line marker. */
711 c_parser_skip_to_pragma_eol (c_parser *parser)
713 gcc_assert (parser->in_pragma);
714 parser->in_pragma = false;
716 if (!c_parser_require (parser, CPP_PRAGMA_EOL, "expected end of line"))
719 c_token *token = c_parser_peek_token (parser);
720 if (token->type == CPP_EOF)
722 if (token->type == CPP_PRAGMA_EOL)
724 c_parser_consume_token (parser);
727 c_parser_consume_token (parser);
730 parser->error = false;
733 /* Skip tokens until we have consumed an entire block, or until we
734 have consumed a non-nested ';'. */
737 c_parser_skip_to_end_of_block_or_statement (c_parser *parser)
739 unsigned nesting_depth = 0;
740 bool save_error = parser->error;
746 /* Peek at the next token. */
747 token = c_parser_peek_token (parser);
755 if (parser->in_pragma)
760 /* If the next token is a ';', we have reached the
761 end of the statement. */
764 /* Consume the ';'. */
765 c_parser_consume_token (parser);
770 case CPP_CLOSE_BRACE:
771 /* If the next token is a non-nested '}', then we have
772 reached the end of the current block. */
773 if (nesting_depth == 0 || --nesting_depth == 0)
775 c_parser_consume_token (parser);
781 /* If it the next token is a '{', then we are entering a new
782 block. Consume the entire block. */
787 /* If we see a pragma, consume the whole thing at once. We
788 have some safeguards against consuming pragmas willy-nilly.
789 Normally, we'd expect to be here with parser->error set,
790 which disables these safeguards. But it's possible to get
791 here for secondary error recovery, after parser->error has
793 c_parser_consume_pragma (parser);
794 c_parser_skip_to_pragma_eol (parser);
795 parser->error = save_error;
802 c_parser_consume_token (parser);
806 parser->error = false;
809 /* CPP's options (initialized by c-opts.c). */
810 extern cpp_options *cpp_opts;
812 /* Save the warning flags which are controlled by __extension__. */
815 disable_extension_diagnostics (void)
818 | (warn_pointer_arith << 1)
819 | (warn_traditional << 2)
821 | (warn_long_long << 4)
822 | (cpp_opts->warn_long_long << 5));
823 cpp_opts->pedantic = pedantic = 0;
824 warn_pointer_arith = 0;
825 cpp_opts->warn_traditional = warn_traditional = 0;
828 cpp_opts->warn_long_long = 0;
832 /* Restore the warning flags which are controlled by __extension__.
833 FLAGS is the return value from disable_extension_diagnostics. */
836 restore_extension_diagnostics (int flags)
838 cpp_opts->pedantic = pedantic = flags & 1;
839 warn_pointer_arith = (flags >> 1) & 1;
840 cpp_opts->warn_traditional = warn_traditional = (flags >> 2) & 1;
841 flag_iso = (flags >> 3) & 1;
842 warn_long_long = (flags >> 4) & 1;
843 cpp_opts->warn_long_long = (flags >> 5) & 1;
846 /* Possibly kinds of declarator to parse. */
847 typedef enum c_dtr_syn {
848 /* A normal declarator with an identifier. */
850 /* An abstract declarator (maybe empty). */
852 /* A parameter declarator: may be either, but after a type name does
853 not redeclare a typedef name as an identifier if it can
854 alternatively be interpreted as a typedef name; see DR#009,
855 applied in C90 TC1, omitted from C99 and reapplied in C99 TC2
856 following DR#249. For example, given a typedef T, "int T" and
857 "int *T" are valid parameter declarations redeclaring T, while
858 "int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are
859 abstract declarators rather than involving redundant parentheses;
860 the same applies with attributes inside the parentheses before
865 static void c_parser_external_declaration (c_parser *);
866 static void c_parser_asm_definition (c_parser *);
867 static void c_parser_declaration_or_fndef (c_parser *, bool, bool, bool, bool);
868 static void c_parser_declspecs (c_parser *, struct c_declspecs *, bool, bool,
870 static struct c_typespec c_parser_enum_specifier (c_parser *);
871 static struct c_typespec c_parser_struct_or_union_specifier (c_parser *);
872 static tree c_parser_struct_declaration (c_parser *);
873 static struct c_typespec c_parser_typeof_specifier (c_parser *);
874 static struct c_declarator *c_parser_declarator (c_parser *, bool, c_dtr_syn,
876 static struct c_declarator *c_parser_direct_declarator (c_parser *, bool,
878 static struct c_declarator *c_parser_direct_declarator_inner (c_parser *,
880 struct c_declarator *);
881 static struct c_arg_info *c_parser_parms_declarator (c_parser *, bool, tree);
882 static struct c_arg_info *c_parser_parms_list_declarator (c_parser *, tree);
883 static struct c_parm *c_parser_parameter_declaration (c_parser *, tree);
884 static tree c_parser_simple_asm_expr (c_parser *);
885 static tree c_parser_attributes (c_parser *);
886 static struct c_type_name *c_parser_type_name (c_parser *);
887 static struct c_expr c_parser_initializer (c_parser *);
888 static struct c_expr c_parser_braced_init (c_parser *, tree, bool);
889 static void c_parser_initelt (c_parser *);
890 static void c_parser_initval (c_parser *, struct c_expr *);
891 static tree c_parser_compound_statement (c_parser *);
892 static void c_parser_compound_statement_nostart (c_parser *);
893 static void c_parser_label (c_parser *);
894 static void c_parser_statement (c_parser *);
895 static void c_parser_statement_after_labels (c_parser *);
896 static void c_parser_if_statement (c_parser *);
897 static void c_parser_switch_statement (c_parser *);
898 static void c_parser_while_statement (c_parser *);
899 static void c_parser_do_statement (c_parser *);
900 static void c_parser_for_statement (c_parser *);
901 static tree c_parser_asm_statement (c_parser *);
902 static tree c_parser_asm_operands (c_parser *, bool);
903 static tree c_parser_asm_clobbers (c_parser *);
904 static struct c_expr c_parser_expr_no_commas (c_parser *, struct c_expr *);
905 static struct c_expr c_parser_conditional_expression (c_parser *,
907 static struct c_expr c_parser_binary_expression (c_parser *, struct c_expr *);
908 static struct c_expr c_parser_cast_expression (c_parser *, struct c_expr *);
909 static struct c_expr c_parser_unary_expression (c_parser *);
910 static struct c_expr c_parser_sizeof_expression (c_parser *);
911 static struct c_expr c_parser_alignof_expression (c_parser *);
912 static struct c_expr c_parser_postfix_expression (c_parser *);
913 static struct c_expr c_parser_postfix_expression_after_paren_type (c_parser *,
914 struct c_type_name *);
915 static struct c_expr c_parser_postfix_expression_after_primary (c_parser *,
917 static struct c_expr c_parser_expression (c_parser *);
918 static struct c_expr c_parser_expression_conv (c_parser *);
919 static tree c_parser_expr_list (c_parser *, bool, bool);
920 static void c_parser_omp_construct (c_parser *);
921 static void c_parser_omp_threadprivate (c_parser *);
922 static void c_parser_omp_barrier (c_parser *);
923 static void c_parser_omp_flush (c_parser *);
924 static void c_parser_omp_taskwait (c_parser *);
926 enum pragma_context { pragma_external, pragma_stmt, pragma_compound };
927 static bool c_parser_pragma (c_parser *, enum pragma_context);
929 /* These Objective-C parser functions are only ever called when
930 compiling Objective-C. */
931 static void c_parser_objc_class_definition (c_parser *);
932 static void c_parser_objc_class_instance_variables (c_parser *);
933 static void c_parser_objc_class_declaration (c_parser *);
934 static void c_parser_objc_alias_declaration (c_parser *);
935 static void c_parser_objc_protocol_definition (c_parser *);
936 static enum tree_code c_parser_objc_method_type (c_parser *);
937 static void c_parser_objc_method_definition (c_parser *);
938 static void c_parser_objc_methodprotolist (c_parser *);
939 static void c_parser_objc_methodproto (c_parser *);
940 static tree c_parser_objc_method_decl (c_parser *);
941 static tree c_parser_objc_type_name (c_parser *);
942 static tree c_parser_objc_protocol_refs (c_parser *);
943 static void c_parser_objc_try_catch_statement (c_parser *);
944 static void c_parser_objc_synchronized_statement (c_parser *);
945 static tree c_parser_objc_selector (c_parser *);
946 static tree c_parser_objc_selector_arg (c_parser *);
947 static tree c_parser_objc_receiver (c_parser *);
948 static tree c_parser_objc_message_args (c_parser *);
949 static tree c_parser_objc_keywordexpr (c_parser *);
951 /* Parse a translation unit (C90 6.7, C99 6.9).
954 external-declarations
956 external-declarations:
958 external-declarations external-declaration
967 c_parser_translation_unit (c_parser *parser)
969 if (c_parser_next_token_is (parser, CPP_EOF))
971 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
972 "ISO C forbids an empty translation unit");
976 void *obstack_position = obstack_alloc (&parser_obstack, 0);
980 c_parser_external_declaration (parser);
981 obstack_free (&parser_obstack, obstack_position);
983 while (c_parser_next_token_is_not (parser, CPP_EOF));
987 /* Parse an external declaration (C90 6.7, C99 6.9).
989 external-declaration:
995 external-declaration:
998 __extension__ external-declaration
1002 external-declaration:
1003 objc-class-definition
1004 objc-class-declaration
1005 objc-alias-declaration
1006 objc-protocol-definition
1007 objc-method-definition
1012 c_parser_external_declaration (c_parser *parser)
1015 switch (c_parser_peek_token (parser)->type)
1018 switch (c_parser_peek_token (parser)->keyword)
1021 ext = disable_extension_diagnostics ();
1022 c_parser_consume_token (parser);
1023 c_parser_external_declaration (parser);
1024 restore_extension_diagnostics (ext);
1027 c_parser_asm_definition (parser);
1029 case RID_AT_INTERFACE:
1030 case RID_AT_IMPLEMENTATION:
1031 gcc_assert (c_dialect_objc ());
1032 c_parser_objc_class_definition (parser);
1035 gcc_assert (c_dialect_objc ());
1036 c_parser_objc_class_declaration (parser);
1039 gcc_assert (c_dialect_objc ());
1040 c_parser_objc_alias_declaration (parser);
1042 case RID_AT_PROTOCOL:
1043 gcc_assert (c_dialect_objc ());
1044 c_parser_objc_protocol_definition (parser);
1047 gcc_assert (c_dialect_objc ());
1048 c_parser_consume_token (parser);
1049 objc_finish_implementation ();
1056 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
1057 "ISO C does not allow extra %<;%> outside of a function");
1058 c_parser_consume_token (parser);
1061 c_parser_pragma (parser, pragma_external);
1065 if (c_dialect_objc ())
1067 c_parser_objc_method_definition (parser);
1070 /* Else fall through, and yield a syntax error trying to parse
1071 as a declaration or function definition. */
1074 /* A declaration or a function definition. We can only tell
1075 which after parsing the declaration specifiers, if any, and
1076 the first declarator. */
1077 c_parser_declaration_or_fndef (parser, true, true, false, true);
1083 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1084 6.7, 6.9.1). If FNDEF_OK is true, a function definition is
1085 accepted; otherwise (old-style parameter declarations) only other
1086 declarations are accepted. If NESTED is true, we are inside a
1087 function or parsing old-style parameter declarations; any functions
1088 encountered are nested functions and declaration specifiers are
1089 required; otherwise we are at top level and functions are normal
1090 functions and declaration specifiers may be optional. If EMPTY_OK
1091 is true, empty declarations are OK (subject to all other
1092 constraints); otherwise (old-style parameter declarations) they are
1093 diagnosed. If START_ATTR_OK is true, the declaration specifiers
1094 may start with attributes; otherwise they may not.
1097 declaration-specifiers init-declarator-list[opt] ;
1099 function-definition:
1100 declaration-specifiers[opt] declarator declaration-list[opt]
1105 declaration-list declaration
1107 init-declarator-list:
1109 init-declarator-list , init-declarator
1112 declarator simple-asm-expr[opt] attributes[opt]
1113 declarator simple-asm-expr[opt] attributes[opt] = initializer
1117 nested-function-definition:
1118 declaration-specifiers declarator declaration-list[opt]
1121 The simple-asm-expr and attributes are GNU extensions.
1123 This function does not handle __extension__; that is handled in its
1124 callers. ??? Following the old parser, __extension__ may start
1125 external declarations, declarations in functions and declarations
1126 at the start of "for" loops, but not old-style parameter
1129 C99 requires declaration specifiers in a function definition; the
1130 absence is diagnosed through the diagnosis of implicit int. In GNU
1131 C we also allow but diagnose declarations without declaration
1132 specifiers, but only at top level (elsewhere they conflict with
1138 threadprivate-directive */
1141 c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok, bool empty_ok,
1142 bool nested, bool start_attr_ok)
1144 struct c_declspecs *specs;
1146 tree all_prefix_attrs;
1147 bool diagnosed_no_specs = false;
1148 location_t here = c_parser_peek_token (parser)->location;
1150 specs = build_null_declspecs ();
1151 c_parser_declspecs (parser, specs, true, true, start_attr_ok);
1154 c_parser_skip_to_end_of_block_or_statement (parser);
1157 if (nested && !specs->declspecs_seen_p)
1159 c_parser_error (parser, "expected declaration specifiers");
1160 c_parser_skip_to_end_of_block_or_statement (parser);
1163 finish_declspecs (specs);
1164 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1170 shadow_tag_warned (specs, 1);
1171 pedwarn (here, 0, "empty declaration");
1173 c_parser_consume_token (parser);
1176 pending_xref_error ();
1177 prefix_attrs = specs->attrs;
1178 all_prefix_attrs = prefix_attrs;
1179 specs->attrs = NULL_TREE;
1182 struct c_declarator *declarator;
1185 /* Declaring either one or more declarators (in which case we
1186 should diagnose if there were no declaration specifiers) or a
1187 function definition (in which case the diagnostic for
1188 implicit int suffices). */
1189 declarator = c_parser_declarator (parser, specs->type_seen_p,
1190 C_DTR_NORMAL, &dummy);
1191 if (declarator == NULL)
1193 c_parser_skip_to_end_of_block_or_statement (parser);
1196 if (c_parser_next_token_is (parser, CPP_EQ)
1197 || c_parser_next_token_is (parser, CPP_COMMA)
1198 || c_parser_next_token_is (parser, CPP_SEMICOLON)
1199 || c_parser_next_token_is_keyword (parser, RID_ASM)
1200 || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1202 tree asm_name = NULL_TREE;
1203 tree postfix_attrs = NULL_TREE;
1204 if (!diagnosed_no_specs && !specs->declspecs_seen_p)
1206 diagnosed_no_specs = true;
1207 pedwarn (here, 0, "data definition has no type or storage class");
1209 /* Having seen a data definition, there cannot now be a
1210 function definition. */
1212 if (c_parser_next_token_is_keyword (parser, RID_ASM))
1213 asm_name = c_parser_simple_asm_expr (parser);
1214 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1215 postfix_attrs = c_parser_attributes (parser);
1216 if (c_parser_next_token_is (parser, CPP_EQ))
1220 c_parser_consume_token (parser);
1221 /* The declaration of the variable is in effect while
1222 its initializer is parsed. */
1223 d = start_decl (declarator, specs, true,
1224 chainon (postfix_attrs, all_prefix_attrs));
1226 d = error_mark_node;
1227 start_init (d, asm_name, global_bindings_p ());
1228 init = c_parser_initializer (parser);
1230 if (d != error_mark_node)
1232 maybe_warn_string_init (TREE_TYPE (d), init);
1233 finish_decl (d, init.value, asm_name);
1238 tree d = start_decl (declarator, specs, false,
1239 chainon (postfix_attrs,
1242 finish_decl (d, NULL_TREE, asm_name);
1244 if (c_parser_next_token_is (parser, CPP_COMMA))
1246 c_parser_consume_token (parser);
1247 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1248 all_prefix_attrs = chainon (c_parser_attributes (parser),
1251 all_prefix_attrs = prefix_attrs;
1254 else if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1256 c_parser_consume_token (parser);
1261 c_parser_error (parser, "expected %<,%> or %<;%>");
1262 c_parser_skip_to_end_of_block_or_statement (parser);
1268 c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, "
1269 "%<asm%> or %<__attribute__%>");
1270 c_parser_skip_to_end_of_block_or_statement (parser);
1273 /* Function definition (nested or otherwise). */
1276 pedwarn (here, OPT_pedantic, "ISO C forbids nested functions");
1277 c_push_function_context ();
1279 if (!start_function (specs, declarator, all_prefix_attrs))
1281 /* This can appear in many cases looking nothing like a
1282 function definition, so we don't give a more specific
1283 error suggesting there was one. */
1284 c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
1285 "or %<__attribute__%>");
1287 c_pop_function_context ();
1290 /* Parse old-style parameter declarations. ??? Attributes are
1291 not allowed to start declaration specifiers here because of a
1292 syntax conflict between a function declaration with attribute
1293 suffix and a function definition with an attribute prefix on
1294 first old-style parameter declaration. Following the old
1295 parser, they are not accepted on subsequent old-style
1296 parameter declarations either. However, there is no
1297 ambiguity after the first declaration, nor indeed on the
1298 first as long as we don't allow postfix attributes after a
1299 declarator with a nonempty identifier list in a definition;
1300 and postfix attributes have never been accepted here in
1301 function definitions either. */
1302 while (c_parser_next_token_is_not (parser, CPP_EOF)
1303 && c_parser_next_token_is_not (parser, CPP_OPEN_BRACE))
1304 c_parser_declaration_or_fndef (parser, false, false, true, false);
1305 store_parm_decls ();
1306 DECL_STRUCT_FUNCTION (current_function_decl)->function_start_locus
1307 = c_parser_peek_token (parser)->location;
1308 fnbody = c_parser_compound_statement (parser);
1311 tree decl = current_function_decl;
1314 c_pop_function_context ();
1315 add_stmt (build_stmt (DECL_EXPR, decl));
1326 /* Parse an asm-definition (asm() outside a function body). This is a
1334 c_parser_asm_definition (c_parser *parser)
1336 tree asm_str = c_parser_simple_asm_expr (parser);
1338 cgraph_add_asm_node (asm_str);
1339 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
1342 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
1343 6.7), adding them to SPECS (which may already include some).
1344 Storage class specifiers are accepted iff SCSPEC_OK; type
1345 specifiers are accepted iff TYPESPEC_OK; attributes are accepted at
1346 the start iff START_ATTR_OK.
1348 declaration-specifiers:
1349 storage-class-specifier declaration-specifiers[opt]
1350 type-specifier declaration-specifiers[opt]
1351 type-qualifier declaration-specifiers[opt]
1352 function-specifier declaration-specifiers[opt]
1354 Function specifiers (inline) are from C99, and are currently
1355 handled as storage class specifiers, as is __thread.
1357 C90 6.5.1, C99 6.7.1:
1358 storage-class-specifier:
1369 C90 6.5.2, C99 6.7.2:
1382 [_Imaginary removed in C99 TC2]
1383 struct-or-union-specifier
1387 (_Bool and _Complex are new in C99.)
1389 C90 6.5.3, C99 6.7.3:
1396 (restrict is new in C99.)
1400 declaration-specifiers:
1401 attributes declaration-specifiers[opt]
1403 storage-class-specifier:
1415 (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
1416 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
1421 class-name objc-protocol-refs[opt]
1422 typedef-name objc-protocol-refs
1427 c_parser_declspecs (c_parser *parser, struct c_declspecs *specs,
1428 bool scspec_ok, bool typespec_ok, bool start_attr_ok)
1430 bool attrs_ok = start_attr_ok;
1431 bool seen_type = specs->type_seen_p;
1432 while (c_parser_next_token_is (parser, CPP_NAME)
1433 || c_parser_next_token_is (parser, CPP_KEYWORD)
1434 || (c_dialect_objc () && c_parser_next_token_is (parser, CPP_LESS)))
1436 struct c_typespec t;
1438 if (c_parser_next_token_is (parser, CPP_NAME))
1440 tree value = c_parser_peek_token (parser)->value;
1441 c_id_kind kind = c_parser_peek_token (parser)->id_kind;
1442 /* This finishes the specifiers unless a type name is OK, it
1443 is declared as a type name and a type name hasn't yet
1445 if (!typespec_ok || seen_type
1446 || (kind != C_ID_TYPENAME && kind != C_ID_CLASSNAME))
1448 c_parser_consume_token (parser);
1451 if (kind == C_ID_TYPENAME
1452 && (!c_dialect_objc ()
1453 || c_parser_next_token_is_not (parser, CPP_LESS)))
1455 t.kind = ctsk_typedef;
1456 /* For a typedef name, record the meaning, not the name.
1457 In case of 'foo foo, bar;'. */
1458 t.spec = lookup_name (value);
1460 t.expr_const_operands = true;
1464 tree proto = NULL_TREE;
1465 gcc_assert (c_dialect_objc ());
1467 if (c_parser_next_token_is (parser, CPP_LESS))
1468 proto = c_parser_objc_protocol_refs (parser);
1469 t.spec = objc_get_protocol_qualified_type (value, proto);
1471 t.expr_const_operands = true;
1473 declspecs_add_type (specs, t);
1476 if (c_parser_next_token_is (parser, CPP_LESS))
1478 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
1479 nisse@lysator.liu.se. */
1481 gcc_assert (c_dialect_objc ());
1482 if (!typespec_ok || seen_type)
1484 proto = c_parser_objc_protocol_refs (parser);
1486 t.spec = objc_get_protocol_qualified_type (NULL_TREE, proto);
1488 t.expr_const_operands = true;
1489 declspecs_add_type (specs, t);
1492 gcc_assert (c_parser_next_token_is (parser, CPP_KEYWORD));
1493 switch (c_parser_peek_token (parser)->keyword)
1505 /* TODO: Distinguish between function specifiers (inline)
1506 and storage class specifiers, either here or in
1507 declspecs_add_scspec. */
1508 declspecs_add_scspec (specs, c_parser_peek_token (parser)->value);
1509 c_parser_consume_token (parser);
1532 if (c_dialect_objc ())
1533 parser->objc_need_raw_identifier = true;
1534 t.kind = ctsk_resword;
1535 t.spec = c_parser_peek_token (parser)->value;
1537 t.expr_const_operands = true;
1538 declspecs_add_type (specs, t);
1539 c_parser_consume_token (parser);
1546 t = c_parser_enum_specifier (parser);
1547 declspecs_add_type (specs, t);
1555 t = c_parser_struct_or_union_specifier (parser);
1556 declspecs_add_type (specs, t);
1559 /* ??? The old parser rejected typeof after other type
1560 specifiers, but is a syntax error the best way of
1562 if (!typespec_ok || seen_type)
1566 t = c_parser_typeof_specifier (parser);
1567 declspecs_add_type (specs, t);
1573 declspecs_add_qual (specs, c_parser_peek_token (parser)->value);
1574 c_parser_consume_token (parser);
1579 attrs = c_parser_attributes (parser);
1580 declspecs_add_attrs (specs, attrs);
1589 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
1592 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
1593 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
1594 enum attributes[opt] identifier
1596 The form with trailing comma is new in C99. The forms with
1597 attributes are GNU extensions. In GNU C, we accept any expression
1598 without commas in the syntax (assignment expressions, not just
1599 conditional expressions); assignment expressions will be diagnosed
1604 enumerator-list , enumerator
1607 enumeration-constant
1608 enumeration-constant = constant-expression
1611 static struct c_typespec
1612 c_parser_enum_specifier (c_parser *parser)
1614 struct c_typespec ret;
1616 tree ident = NULL_TREE;
1617 location_t ident_loc = UNKNOWN_LOCATION; /* Quiet warning. */
1618 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ENUM));
1619 c_parser_consume_token (parser);
1620 attrs = c_parser_attributes (parser);
1621 /* Set the location in case we create a decl now. */
1622 c_parser_set_source_position_from_token (c_parser_peek_token (parser));
1623 if (c_parser_next_token_is (parser, CPP_NAME))
1625 ident = c_parser_peek_token (parser)->value;
1626 ident_loc = c_parser_peek_token (parser)->location;
1627 c_parser_consume_token (parser);
1629 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
1631 /* Parse an enum definition. */
1632 struct c_enum_contents the_enum;
1633 tree type = start_enum (&the_enum, ident);
1635 /* We chain the enumerators in reverse order, then put them in
1636 forward order at the end. */
1637 tree values = NULL_TREE;
1638 c_parser_consume_token (parser);
1646 location_t comma_loc = UNKNOWN_LOCATION; /* Quiet warning. */
1647 location_t value_loc;
1648 if (c_parser_next_token_is_not (parser, CPP_NAME))
1650 c_parser_error (parser, "expected identifier");
1651 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
1652 values = error_mark_node;
1655 token = c_parser_peek_token (parser);
1656 enum_id = token->value;
1657 /* Set the location in case we create a decl now. */
1658 c_parser_set_source_position_from_token (token);
1659 value_loc = token->location;
1660 c_parser_consume_token (parser);
1661 if (c_parser_next_token_is (parser, CPP_EQ))
1663 c_parser_consume_token (parser);
1664 value_loc = c_parser_peek_token (parser)->location;
1665 enum_value = c_parser_expr_no_commas (parser, NULL).value;
1668 enum_value = NULL_TREE;
1669 enum_decl = build_enumerator (&the_enum, enum_id, enum_value,
1671 TREE_CHAIN (enum_decl) = values;
1674 if (c_parser_next_token_is (parser, CPP_COMMA))
1676 comma_loc = c_parser_peek_token (parser)->location;
1678 c_parser_consume_token (parser);
1680 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
1682 if (seen_comma && !flag_isoc99)
1683 pedwarn (comma_loc, OPT_pedantic, "comma at end of enumerator list");
1684 c_parser_consume_token (parser);
1689 c_parser_error (parser, "expected %<,%> or %<}%>");
1690 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
1691 values = error_mark_node;
1695 postfix_attrs = c_parser_attributes (parser);
1696 ret.spec = finish_enum (type, nreverse (values),
1697 chainon (attrs, postfix_attrs));
1698 ret.kind = ctsk_tagdef;
1699 ret.expr = NULL_TREE;
1700 ret.expr_const_operands = true;
1705 c_parser_error (parser, "expected %<{%>");
1706 ret.spec = error_mark_node;
1707 ret.kind = ctsk_tagref;
1708 ret.expr = NULL_TREE;
1709 ret.expr_const_operands = true;
1712 ret = parser_xref_tag (ENUMERAL_TYPE, ident);
1713 /* In ISO C, enumerated types can be referred to only if already
1715 if (pedantic && !COMPLETE_TYPE_P (ret.spec))
1718 pedwarn (ident_loc, OPT_pedantic,
1719 "ISO C forbids forward references to %<enum%> types");
1724 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
1726 struct-or-union-specifier:
1727 struct-or-union attributes[opt] identifier[opt]
1728 { struct-contents } attributes[opt]
1729 struct-or-union attributes[opt] identifier
1732 struct-declaration-list
1734 struct-declaration-list:
1735 struct-declaration ;
1736 struct-declaration-list struct-declaration ;
1743 struct-declaration-list struct-declaration
1745 struct-declaration-list:
1746 struct-declaration-list ;
1749 (Note that in the syntax here, unlike that in ISO C, the semicolons
1750 are included here rather than in struct-declaration, in order to
1751 describe the syntax with extra semicolons and missing semicolon at
1756 struct-declaration-list:
1757 @defs ( class-name )
1759 (Note this does not include a trailing semicolon, but can be
1760 followed by further declarations, and gets a pedwarn-if-pedantic
1761 when followed by a semicolon.) */
1763 static struct c_typespec
1764 c_parser_struct_or_union_specifier (c_parser *parser)
1766 struct c_typespec ret;
1768 tree ident = NULL_TREE;
1769 enum tree_code code;
1770 switch (c_parser_peek_token (parser)->keyword)
1781 c_parser_consume_token (parser);
1782 attrs = c_parser_attributes (parser);
1783 /* Set the location in case we create a decl now. */
1784 c_parser_set_source_position_from_token (c_parser_peek_token (parser));
1785 if (c_parser_next_token_is (parser, CPP_NAME))
1787 ident = c_parser_peek_token (parser)->value;
1788 c_parser_consume_token (parser);
1790 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
1792 /* Parse a struct or union definition. Start the scope of the
1793 tag before parsing components. */
1794 tree type = start_struct (code, ident);
1796 /* We chain the components in reverse order, then put them in
1797 forward order at the end. Each struct-declaration may
1798 declare multiple components (comma-separated), so we must use
1799 chainon to join them, although when parsing each
1800 struct-declaration we can use TREE_CHAIN directly.
1802 The theory behind all this is that there will be more
1803 semicolon separated fields than comma separated fields, and
1804 so we'll be minimizing the number of node traversals required
1806 tree contents = NULL_TREE;
1807 c_parser_consume_token (parser);
1808 /* Handle the Objective-C @defs construct,
1809 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
1810 if (c_parser_next_token_is_keyword (parser, RID_AT_DEFS))
1813 gcc_assert (c_dialect_objc ());
1814 c_parser_consume_token (parser);
1815 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
1817 if (c_parser_next_token_is (parser, CPP_NAME)
1818 && c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME)
1820 name = c_parser_peek_token (parser)->value;
1821 c_parser_consume_token (parser);
1825 c_parser_error (parser, "expected class name");
1826 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
1829 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
1831 contents = nreverse (objc_get_class_ivars (name));
1834 /* Parse the struct-declarations and semicolons. Problems with
1835 semicolons are diagnosed here; empty structures are diagnosed
1840 /* Parse any stray semicolon. */
1841 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1843 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
1844 "extra semicolon in struct or union specified");
1845 c_parser_consume_token (parser);
1848 /* Stop if at the end of the struct or union contents. */
1849 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
1851 c_parser_consume_token (parser);
1854 /* Accept #pragmas at struct scope. */
1855 if (c_parser_next_token_is (parser, CPP_PRAGMA))
1857 c_parser_pragma (parser, pragma_external);
1860 /* Parse some comma-separated declarations, but not the
1861 trailing semicolon if any. */
1862 decls = c_parser_struct_declaration (parser);
1863 contents = chainon (decls, contents);
1864 /* If no semicolon follows, either we have a parse error or
1865 are at the end of the struct or union and should
1867 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1868 c_parser_consume_token (parser);
1871 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
1872 pedwarn (c_parser_peek_token (parser)->location, 0,
1873 "no semicolon at end of struct or union");
1876 c_parser_error (parser, "expected %<;%>");
1877 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
1882 postfix_attrs = c_parser_attributes (parser);
1883 ret.spec = finish_struct (type, nreverse (contents),
1884 chainon (attrs, postfix_attrs));
1885 ret.kind = ctsk_tagdef;
1886 ret.expr = NULL_TREE;
1887 ret.expr_const_operands = true;
1892 c_parser_error (parser, "expected %<{%>");
1893 ret.spec = error_mark_node;
1894 ret.kind = ctsk_tagref;
1895 ret.expr = NULL_TREE;
1896 ret.expr_const_operands = true;
1899 ret = parser_xref_tag (code, ident);
1903 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
1904 the trailing semicolon.
1907 specifier-qualifier-list struct-declarator-list
1909 specifier-qualifier-list:
1910 type-specifier specifier-qualifier-list[opt]
1911 type-qualifier specifier-qualifier-list[opt]
1912 attributes specifier-qualifier-list[opt]
1914 struct-declarator-list:
1916 struct-declarator-list , attributes[opt] struct-declarator
1919 declarator attributes[opt]
1920 declarator[opt] : constant-expression attributes[opt]
1925 __extension__ struct-declaration
1926 specifier-qualifier-list
1928 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
1929 of attributes where shown is a GNU extension. In GNU C, we accept
1930 any expression without commas in the syntax (assignment
1931 expressions, not just conditional expressions); assignment
1932 expressions will be diagnosed as non-constant. */
1935 c_parser_struct_declaration (c_parser *parser)
1937 struct c_declspecs *specs;
1939 tree all_prefix_attrs;
1941 location_t decl_loc;
1942 if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
1946 ext = disable_extension_diagnostics ();
1947 c_parser_consume_token (parser);
1948 decl = c_parser_struct_declaration (parser);
1949 restore_extension_diagnostics (ext);
1952 specs = build_null_declspecs ();
1953 decl_loc = c_parser_peek_token (parser)->location;
1954 c_parser_declspecs (parser, specs, false, true, true);
1957 if (!specs->declspecs_seen_p)
1959 c_parser_error (parser, "expected specifier-qualifier-list");
1962 finish_declspecs (specs);
1963 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1966 if (!specs->type_seen_p)
1968 pedwarn (decl_loc, OPT_pedantic,
1969 "ISO C forbids member declarations with no members");
1970 shadow_tag_warned (specs, pedantic);
1975 /* Support for unnamed structs or unions as members of
1976 structs or unions (which is [a] useful and [b] supports
1980 ret = grokfield (c_parser_peek_token (parser)->location,
1981 build_id_declarator (NULL_TREE), specs,
1984 decl_attributes (&ret, attrs, 0);
1988 pending_xref_error ();
1989 prefix_attrs = specs->attrs;
1990 all_prefix_attrs = prefix_attrs;
1991 specs->attrs = NULL_TREE;
1995 /* Declaring one or more declarators or un-named bit-fields. */
1996 struct c_declarator *declarator;
1998 if (c_parser_next_token_is (parser, CPP_COLON))
1999 declarator = build_id_declarator (NULL_TREE);
2001 declarator = c_parser_declarator (parser, specs->type_seen_p,
2002 C_DTR_NORMAL, &dummy);
2003 if (declarator == NULL)
2005 c_parser_skip_to_end_of_block_or_statement (parser);
2008 if (c_parser_next_token_is (parser, CPP_COLON)
2009 || c_parser_next_token_is (parser, CPP_COMMA)
2010 || c_parser_next_token_is (parser, CPP_SEMICOLON)
2011 || c_parser_next_token_is (parser, CPP_CLOSE_BRACE)
2012 || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2014 tree postfix_attrs = NULL_TREE;
2015 tree width = NULL_TREE;
2017 if (c_parser_next_token_is (parser, CPP_COLON))
2019 c_parser_consume_token (parser);
2020 width = c_parser_expr_no_commas (parser, NULL).value;
2022 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2023 postfix_attrs = c_parser_attributes (parser);
2024 d = grokfield (c_parser_peek_token (parser)->location,
2025 declarator, specs, width, &all_prefix_attrs);
2026 decl_attributes (&d, chainon (postfix_attrs,
2027 all_prefix_attrs), 0);
2028 TREE_CHAIN (d) = decls;
2030 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2031 all_prefix_attrs = chainon (c_parser_attributes (parser),
2034 all_prefix_attrs = prefix_attrs;
2035 if (c_parser_next_token_is (parser, CPP_COMMA))
2036 c_parser_consume_token (parser);
2037 else if (c_parser_next_token_is (parser, CPP_SEMICOLON)
2038 || c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2040 /* Semicolon consumed in caller. */
2045 c_parser_error (parser, "expected %<,%>, %<;%> or %<}%>");
2051 c_parser_error (parser,
2052 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
2053 "%<__attribute__%>");
2060 /* Parse a typeof specifier (a GNU extension).
2063 typeof ( expression )
2064 typeof ( type-name )
2067 static struct c_typespec
2068 c_parser_typeof_specifier (c_parser *parser)
2070 struct c_typespec ret;
2071 ret.kind = ctsk_typeof;
2072 ret.spec = error_mark_node;
2073 ret.expr = NULL_TREE;
2074 ret.expr_const_operands = true;
2075 gcc_assert (c_parser_next_token_is_keyword (parser, RID_TYPEOF));
2076 c_parser_consume_token (parser);
2079 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2085 if (c_parser_next_token_starts_typename (parser))
2087 struct c_type_name *type = c_parser_type_name (parser);
2092 ret.spec = groktypename (type, &ret.expr, &ret.expr_const_operands);
2093 pop_maybe_used (variably_modified_type_p (ret.spec, NULL_TREE));
2099 location_t here = c_parser_peek_token (parser)->location;
2100 struct c_expr expr = c_parser_expression (parser);
2103 if (TREE_CODE (expr.value) == COMPONENT_REF
2104 && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
2105 error_at (here, "%<typeof%> applied to a bit-field");
2106 ret.spec = TREE_TYPE (expr.value);
2107 was_vm = variably_modified_type_p (ret.spec, NULL_TREE);
2108 /* This is returned with the type so that when the type is
2109 evaluated, this can be evaluated. */
2111 ret.expr = c_fully_fold (expr.value, false, &ret.expr_const_operands);
2112 pop_maybe_used (was_vm);
2114 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
2118 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
2119 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
2120 be redeclared; otherwise it may not. KIND indicates which kind of
2121 declarator is wanted. Returns a valid declarator except in the
2122 case of a syntax error in which case NULL is returned. *SEEN_ID is
2123 set to true if an identifier being declared is seen; this is used
2124 to diagnose bad forms of abstract array declarators and to
2125 determine whether an identifier list is syntactically permitted.
2128 pointer[opt] direct-declarator
2132 ( attributes[opt] declarator )
2133 direct-declarator array-declarator
2134 direct-declarator ( parameter-type-list )
2135 direct-declarator ( identifier-list[opt] )
2138 * type-qualifier-list[opt]
2139 * type-qualifier-list[opt] pointer
2141 type-qualifier-list:
2144 type-qualifier-list type-qualifier
2145 type-qualifier-list attributes
2147 parameter-type-list:
2149 parameter-list , ...
2152 parameter-declaration
2153 parameter-list , parameter-declaration
2155 parameter-declaration:
2156 declaration-specifiers declarator attributes[opt]
2157 declaration-specifiers abstract-declarator[opt] attributes[opt]
2161 identifier-list , identifier
2163 abstract-declarator:
2165 pointer[opt] direct-abstract-declarator
2167 direct-abstract-declarator:
2168 ( attributes[opt] abstract-declarator )
2169 direct-abstract-declarator[opt] array-declarator
2170 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
2175 direct-declarator ( parameter-forward-declarations
2176 parameter-type-list[opt] )
2178 direct-abstract-declarator:
2179 direct-abstract-declarator[opt] ( parameter-forward-declarations
2180 parameter-type-list[opt] )
2182 parameter-forward-declarations:
2184 parameter-forward-declarations parameter-list ;
2186 The uses of attributes shown above are GNU extensions.
2188 Some forms of array declarator are not included in C99 in the
2189 syntax for abstract declarators; these are disallowed elsewhere.
2190 This may be a defect (DR#289).
2192 This function also accepts an omitted abstract declarator as being
2193 an abstract declarator, although not part of the formal syntax. */
2195 static struct c_declarator *
2196 c_parser_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
2199 /* Parse any initial pointer part. */
2200 if (c_parser_next_token_is (parser, CPP_MULT))
2202 struct c_declspecs *quals_attrs = build_null_declspecs ();
2203 struct c_declarator *inner;
2204 c_parser_consume_token (parser);
2205 c_parser_declspecs (parser, quals_attrs, false, false, true);
2206 inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
2210 return make_pointer_declarator (quals_attrs, inner);
2212 /* Now we have a direct declarator, direct abstract declarator or
2213 nothing (which counts as a direct abstract declarator here). */
2214 return c_parser_direct_declarator (parser, type_seen_p, kind, seen_id);
2217 /* Parse a direct declarator or direct abstract declarator; arguments
2218 as c_parser_declarator. */
2220 static struct c_declarator *
2221 c_parser_direct_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
2224 /* The direct declarator must start with an identifier (possibly
2225 omitted) or a parenthesized declarator (possibly abstract). In
2226 an ordinary declarator, initial parentheses must start a
2227 parenthesized declarator. In an abstract declarator or parameter
2228 declarator, they could start a parenthesized declarator or a
2229 parameter list. To tell which, the open parenthesis and any
2230 following attributes must be read. If a declaration specifier
2231 follows, then it is a parameter list; if the specifier is a
2232 typedef name, there might be an ambiguity about redeclaring it,
2233 which is resolved in the direction of treating it as a typedef
2234 name. If a close parenthesis follows, it is also an empty
2235 parameter list, as the syntax does not permit empty abstract
2236 declarators. Otherwise, it is a parenthesized declarator (in
2237 which case the analysis may be repeated inside it, recursively).
2239 ??? There is an ambiguity in a parameter declaration "int
2240 (__attribute__((foo)) x)", where x is not a typedef name: it
2241 could be an abstract declarator for a function, or declare x with
2242 parentheses. The proper resolution of this ambiguity needs
2243 documenting. At present we follow an accident of the old
2244 parser's implementation, whereby the first parameter must have
2245 some declaration specifiers other than just attributes. Thus as
2246 a parameter declaration it is treated as a parenthesized
2247 parameter named x, and as an abstract declarator it is
2250 ??? Also following the old parser, attributes inside an empty
2251 parameter list are ignored, making it a list not yielding a
2252 prototype, rather than giving an error or making it have one
2253 parameter with implicit type int.
2255 ??? Also following the old parser, typedef names may be
2256 redeclared in declarators, but not Objective-C class names. */
2258 if (kind != C_DTR_ABSTRACT
2259 && c_parser_next_token_is (parser, CPP_NAME)
2261 && c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME)
2262 || c_parser_peek_token (parser)->id_kind == C_ID_ID))
2264 struct c_declarator *inner
2265 = build_id_declarator (c_parser_peek_token (parser)->value);
2267 inner->id_loc = c_parser_peek_token (parser)->location;
2268 c_parser_consume_token (parser);
2269 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2272 if (kind != C_DTR_NORMAL
2273 && c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
2275 struct c_declarator *inner = build_id_declarator (NULL_TREE);
2276 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2279 /* Either we are at the end of an abstract declarator, or we have
2282 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
2285 struct c_declarator *inner;
2286 c_parser_consume_token (parser);
2287 attrs = c_parser_attributes (parser);
2288 if (kind != C_DTR_NORMAL
2289 && (c_parser_next_token_starts_declspecs (parser)
2290 || c_parser_next_token_is (parser, CPP_CLOSE_PAREN)))
2292 struct c_arg_info *args
2293 = c_parser_parms_declarator (parser, kind == C_DTR_NORMAL,
2300 = build_function_declarator (args,
2301 build_id_declarator (NULL_TREE));
2302 return c_parser_direct_declarator_inner (parser, *seen_id,
2306 /* A parenthesized declarator. */
2307 inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
2308 if (inner != NULL && attrs != NULL)
2309 inner = build_attrs_declarator (attrs, inner);
2310 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2312 c_parser_consume_token (parser);
2316 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2320 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2327 if (kind == C_DTR_NORMAL)
2329 c_parser_error (parser, "expected identifier or %<(%>");
2333 return build_id_declarator (NULL_TREE);
2337 /* Parse part of a direct declarator or direct abstract declarator,
2338 given that some (in INNER) has already been parsed; ID_PRESENT is
2339 true if an identifier is present, false for an abstract
2342 static struct c_declarator *
2343 c_parser_direct_declarator_inner (c_parser *parser, bool id_present,
2344 struct c_declarator *inner)
2346 /* Parse a sequence of array declarators and parameter lists. */
2347 if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
2349 struct c_declarator *declarator;
2350 struct c_declspecs *quals_attrs = build_null_declspecs ();
2354 c_parser_consume_token (parser);
2355 c_parser_declspecs (parser, quals_attrs, false, false, true);
2356 static_seen = c_parser_next_token_is_keyword (parser, RID_STATIC);
2358 c_parser_consume_token (parser);
2359 if (static_seen && !quals_attrs->declspecs_seen_p)
2360 c_parser_declspecs (parser, quals_attrs, false, false, true);
2361 if (!quals_attrs->declspecs_seen_p)
2363 /* If "static" is present, there must be an array dimension.
2364 Otherwise, there may be a dimension, "*", or no
2369 dimen = c_parser_expr_no_commas (parser, NULL).value;
2373 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
2378 else if (c_parser_next_token_is (parser, CPP_MULT))
2380 if (c_parser_peek_2nd_token (parser)->type == CPP_CLOSE_SQUARE)
2384 c_parser_consume_token (parser);
2389 dimen = c_parser_expr_no_commas (parser, NULL).value;
2395 dimen = c_parser_expr_no_commas (parser, NULL).value;
2398 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
2399 c_parser_consume_token (parser);
2402 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
2406 declarator = build_array_declarator (dimen, quals_attrs, static_seen,
2408 if (declarator == NULL)
2410 inner = set_array_declarator_inner (declarator, inner);
2411 return c_parser_direct_declarator_inner (parser, id_present, inner);
2413 else if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
2416 struct c_arg_info *args;
2417 c_parser_consume_token (parser);
2418 attrs = c_parser_attributes (parser);
2419 args = c_parser_parms_declarator (parser, id_present, attrs);
2424 inner = build_function_declarator (args, inner);
2425 return c_parser_direct_declarator_inner (parser, id_present, inner);
2431 /* Parse a parameter list or identifier list, including the closing
2432 parenthesis but not the opening one. ATTRS are the attributes at
2433 the start of the list. ID_LIST_OK is true if an identifier list is
2434 acceptable; such a list must not have attributes at the start. */
2436 static struct c_arg_info *
2437 c_parser_parms_declarator (c_parser *parser, bool id_list_ok, tree attrs)
2440 declare_parm_level ();
2441 /* If the list starts with an identifier, it is an identifier list.
2442 Otherwise, it is either a prototype list or an empty list. */
2445 && c_parser_next_token_is (parser, CPP_NAME)
2446 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
2448 tree list = NULL_TREE, *nextp = &list;
2449 while (c_parser_next_token_is (parser, CPP_NAME)
2450 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
2452 *nextp = build_tree_list (NULL_TREE,
2453 c_parser_peek_token (parser)->value);
2454 nextp = & TREE_CHAIN (*nextp);
2455 c_parser_consume_token (parser);
2456 if (c_parser_next_token_is_not (parser, CPP_COMMA))
2458 c_parser_consume_token (parser);
2459 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2461 c_parser_error (parser, "expected identifier");
2465 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2467 struct c_arg_info *ret = XOBNEW (&parser_obstack, struct c_arg_info);
2472 ret->pending_sizes = 0;
2473 ret->had_vla_unspec = 0;
2474 c_parser_consume_token (parser);
2480 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2488 struct c_arg_info *ret = c_parser_parms_list_declarator (parser, attrs);
2494 /* Parse a parameter list (possibly empty), including the closing
2495 parenthesis but not the opening one. ATTRS are the attributes at
2496 the start of the list. */
2498 static struct c_arg_info *
2499 c_parser_parms_list_declarator (c_parser *parser, tree attrs)
2501 bool good_parm = false;
2502 /* ??? Following the old parser, forward parameter declarations may
2503 use abstract declarators, and if no real parameter declarations
2504 follow the forward declarations then this is not diagnosed. Also
2505 note as above that attributes are ignored as the only contents of
2506 the parentheses, or as the only contents after forward
2508 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2510 struct c_arg_info *ret = XOBNEW (&parser_obstack, struct c_arg_info);
2515 ret->pending_sizes = 0;
2516 ret->had_vla_unspec = 0;
2517 c_parser_consume_token (parser);
2520 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
2522 struct c_arg_info *ret = XOBNEW (&parser_obstack, struct c_arg_info);
2526 ret->pending_sizes = 0;
2527 ret->had_vla_unspec = 0;
2528 /* Suppress -Wold-style-definition for this case. */
2529 ret->types = error_mark_node;
2530 error_at (c_parser_peek_token (parser)->location,
2531 "ISO C requires a named argument before %<...%>");
2532 c_parser_consume_token (parser);
2533 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2535 c_parser_consume_token (parser);
2540 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2545 /* Nonempty list of parameters, either terminated with semicolon
2546 (forward declarations; recurse) or with close parenthesis (normal
2547 function) or with ", ... )" (variadic function). */
2550 /* Parse a parameter. */
2551 struct c_parm *parm = c_parser_parameter_declaration (parser, attrs);
2556 push_parm_decl (parm);
2558 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
2561 c_parser_consume_token (parser);
2562 mark_forward_parm_decls ();
2563 new_attrs = c_parser_attributes (parser);
2564 return c_parser_parms_list_declarator (parser, new_attrs);
2566 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2568 c_parser_consume_token (parser);
2570 return get_parm_info (false);
2573 struct c_arg_info *ret
2574 = XOBNEW (&parser_obstack, struct c_arg_info);
2579 ret->pending_sizes = 0;
2580 ret->had_vla_unspec = 0;
2584 if (!c_parser_require (parser, CPP_COMMA,
2585 "expected %<;%>, %<,%> or %<)%>"))
2587 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
2588 get_pending_sizes ();
2591 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
2593 c_parser_consume_token (parser);
2594 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2596 c_parser_consume_token (parser);
2598 return get_parm_info (true);
2601 struct c_arg_info *ret
2602 = XOBNEW (&parser_obstack, struct c_arg_info);
2607 ret->pending_sizes = 0;
2608 ret->had_vla_unspec = 0;
2614 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2616 get_pending_sizes ();
2623 /* Parse a parameter declaration. ATTRS are the attributes at the
2624 start of the declaration if it is the first parameter. */
2626 static struct c_parm *
2627 c_parser_parameter_declaration (c_parser *parser, tree attrs)
2629 struct c_declspecs *specs;
2630 struct c_declarator *declarator;
2632 tree postfix_attrs = NULL_TREE;
2634 if (!c_parser_next_token_starts_declspecs (parser))
2636 /* ??? In some Objective-C cases '...' isn't applicable so there
2637 should be a different message. */
2638 c_parser_error (parser,
2639 "expected declaration specifiers or %<...%>");
2640 c_parser_skip_to_end_of_parameter (parser);
2643 specs = build_null_declspecs ();
2646 declspecs_add_attrs (specs, attrs);
2649 c_parser_declspecs (parser, specs, true, true, true);
2650 finish_declspecs (specs);
2651 pending_xref_error ();
2652 prefix_attrs = specs->attrs;
2653 specs->attrs = NULL_TREE;
2654 declarator = c_parser_declarator (parser, specs->type_seen_p,
2655 C_DTR_PARM, &dummy);
2656 if (declarator == NULL)
2658 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
2661 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2662 postfix_attrs = c_parser_attributes (parser);
2663 return build_c_parm (specs, chainon (postfix_attrs, prefix_attrs),
2667 /* Parse a string literal in an asm expression. It should not be
2668 translated, and wide string literals are an error although
2669 permitted by the syntax. This is a GNU extension.
2674 ??? At present, following the old parser, the caller needs to have
2675 set lex_untranslated_string to 1. It would be better to follow the
2676 C++ parser rather than using this kludge. */
2679 c_parser_asm_string_literal (c_parser *parser)
2682 if (c_parser_next_token_is (parser, CPP_STRING))
2684 str = c_parser_peek_token (parser)->value;
2685 c_parser_consume_token (parser);
2687 else if (c_parser_next_token_is (parser, CPP_WSTRING))
2689 error_at (c_parser_peek_token (parser)->location,
2690 "wide string literal in %<asm%>");
2691 str = build_string (1, "");
2692 c_parser_consume_token (parser);
2696 c_parser_error (parser, "expected string literal");
2702 /* Parse a simple asm expression. This is used in restricted
2703 contexts, where a full expression with inputs and outputs does not
2704 make sense. This is a GNU extension.
2707 asm ( asm-string-literal )
2711 c_parser_simple_asm_expr (c_parser *parser)
2714 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
2715 /* ??? Follow the C++ parser rather than using the
2716 lex_untranslated_string kludge. */
2717 parser->lex_untranslated_string = true;
2718 c_parser_consume_token (parser);
2719 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2721 parser->lex_untranslated_string = false;
2724 str = c_parser_asm_string_literal (parser);
2725 parser->lex_untranslated_string = false;
2726 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
2728 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
2734 /* Parse (possibly empty) attributes. This is a GNU extension.
2738 attributes attribute
2741 __attribute__ ( ( attribute-list ) )
2745 attribute_list , attrib
2750 any-word ( identifier )
2751 any-word ( identifier , nonempty-expr-list )
2752 any-word ( expr-list )
2754 where the "identifier" must not be declared as a type, and
2755 "any-word" may be any identifier (including one declared as a
2756 type), a reserved word storage class specifier, type specifier or
2757 type qualifier. ??? This still leaves out most reserved keywords
2758 (following the old parser), shouldn't we include them, and why not
2759 allow identifiers declared as types to start the arguments? */
2762 c_parser_attributes (c_parser *parser)
2764 tree attrs = NULL_TREE;
2765 while (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2767 /* ??? Follow the C++ parser rather than using the
2768 lex_untranslated_string kludge. */
2769 parser->lex_untranslated_string = true;
2770 c_parser_consume_token (parser);
2771 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2773 parser->lex_untranslated_string = false;
2776 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2778 parser->lex_untranslated_string = false;
2779 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
2782 /* Parse the attribute list. */
2783 while (c_parser_next_token_is (parser, CPP_COMMA)
2784 || c_parser_next_token_is (parser, CPP_NAME)
2785 || c_parser_next_token_is (parser, CPP_KEYWORD))
2787 tree attr, attr_name, attr_args;
2788 if (c_parser_next_token_is (parser, CPP_COMMA))
2790 c_parser_consume_token (parser);
2793 if (c_parser_next_token_is (parser, CPP_KEYWORD))
2795 /* ??? See comment above about what keywords are
2798 switch (c_parser_peek_token (parser)->keyword)
2835 /* Accept __attribute__((__const)) as __attribute__((const))
2838 = ridpointers[(int) c_parser_peek_token (parser)->keyword];
2841 attr_name = c_parser_peek_token (parser)->value;
2842 c_parser_consume_token (parser);
2843 if (c_parser_next_token_is_not (parser, CPP_OPEN_PAREN))
2845 attr = build_tree_list (attr_name, NULL_TREE);
2846 attrs = chainon (attrs, attr);
2849 c_parser_consume_token (parser);
2850 /* Parse the attribute contents. If they start with an
2851 identifier which is followed by a comma or close
2852 parenthesis, then the arguments start with that
2853 identifier; otherwise they are an expression list. */
2854 if (c_parser_next_token_is (parser, CPP_NAME)
2855 && c_parser_peek_token (parser)->id_kind == C_ID_ID
2856 && ((c_parser_peek_2nd_token (parser)->type == CPP_COMMA)
2857 || (c_parser_peek_2nd_token (parser)->type
2858 == CPP_CLOSE_PAREN)))
2860 tree arg1 = c_parser_peek_token (parser)->value;
2861 c_parser_consume_token (parser);
2862 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2863 attr_args = build_tree_list (NULL_TREE, arg1);
2866 c_parser_consume_token (parser);
2867 attr_args = tree_cons (NULL_TREE, arg1,
2868 c_parser_expr_list (parser, false,
2874 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2875 attr_args = NULL_TREE;
2877 attr_args = c_parser_expr_list (parser, false, true);
2879 attr = build_tree_list (attr_name, attr_args);
2880 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2881 c_parser_consume_token (parser);
2884 parser->lex_untranslated_string = false;
2885 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2889 attrs = chainon (attrs, attr);
2891 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2892 c_parser_consume_token (parser);
2895 parser->lex_untranslated_string = false;
2896 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2900 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2901 c_parser_consume_token (parser);
2904 parser->lex_untranslated_string = false;
2905 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2909 parser->lex_untranslated_string = false;
2914 /* Parse a type name (C90 6.5.5, C99 6.7.6).
2917 specifier-qualifier-list abstract-declarator[opt]
2920 static struct c_type_name *
2921 c_parser_type_name (c_parser *parser)
2923 struct c_declspecs *specs = build_null_declspecs ();
2924 struct c_declarator *declarator;
2925 struct c_type_name *ret;
2927 c_parser_declspecs (parser, specs, false, true, true);
2928 if (!specs->declspecs_seen_p)
2930 c_parser_error (parser, "expected specifier-qualifier-list");
2933 pending_xref_error ();
2934 finish_declspecs (specs);
2935 declarator = c_parser_declarator (parser, specs->type_seen_p,
2936 C_DTR_ABSTRACT, &dummy);
2937 if (declarator == NULL)
2939 ret = XOBNEW (&parser_obstack, struct c_type_name);
2941 ret->declarator = declarator;
2945 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
2948 assignment-expression
2949 { initializer-list }
2950 { initializer-list , }
2953 designation[opt] initializer
2954 initializer-list , designation[opt] initializer
2961 designator-list designator
2968 [ constant-expression ]
2980 [ constant-expression ... constant-expression ]
2982 Any expression without commas is accepted in the syntax for the
2983 constant-expressions, with non-constant expressions rejected later.
2985 This function is only used for top-level initializers; for nested
2986 ones, see c_parser_initval. */
2988 static struct c_expr
2989 c_parser_initializer (c_parser *parser)
2991 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
2992 return c_parser_braced_init (parser, NULL_TREE, false);
2996 ret = c_parser_expr_no_commas (parser, NULL);
2997 if (TREE_CODE (ret.value) != STRING_CST
2998 && TREE_CODE (ret.value) != COMPOUND_LITERAL_EXPR)
2999 ret = default_function_array_conversion (ret);
3004 /* Parse a braced initializer list. TYPE is the type specified for a
3005 compound literal, and NULL_TREE for other initializers and for
3006 nested braced lists. NESTED_P is true for nested braced lists,
3007 false for the list of a compound literal or the list that is the
3008 top-level initializer in a declaration. */
3010 static struct c_expr
3011 c_parser_braced_init (c_parser *parser, tree type, bool nested_p)
3013 location_t brace_loc = c_parser_peek_token (parser)->location;
3014 gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE));
3015 c_parser_consume_token (parser);
3017 push_init_level (0);
3019 really_start_incremental_init (type);
3020 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3022 pedwarn (brace_loc, OPT_pedantic, "ISO C forbids empty initializer braces");
3026 /* Parse a non-empty initializer list, possibly with a trailing
3030 c_parser_initelt (parser);
3033 if (c_parser_next_token_is (parser, CPP_COMMA))
3034 c_parser_consume_token (parser);
3037 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3041 if (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE))
3044 ret.value = error_mark_node;
3045 ret.original_code = ERROR_MARK;
3046 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, "expected %<}%>");
3050 c_parser_consume_token (parser);
3051 return pop_init_level (0);
3054 /* Parse a nested initializer, including designators. */
3057 c_parser_initelt (c_parser *parser)
3059 /* Parse any designator or designator list. A single array
3060 designator may have the subsequent "=" omitted in GNU C, but a
3061 longer list or a structure member designator may not. */
3062 if (c_parser_next_token_is (parser, CPP_NAME)
3063 && c_parser_peek_2nd_token (parser)->type == CPP_COLON)
3065 /* Old-style structure member designator. */
3066 set_init_label (c_parser_peek_token (parser)->value);
3067 /* Use the colon as the error location. */
3068 pedwarn (c_parser_peek_2nd_token (parser)->location, OPT_pedantic,
3069 "obsolete use of designated initializer with %<:%>");
3070 c_parser_consume_token (parser);
3071 c_parser_consume_token (parser);
3075 /* des_seen is 0 if there have been no designators, 1 if there
3076 has been a single array designator and 2 otherwise. */
3078 /* Location of a designator. */
3079 location_t des_loc = UNKNOWN_LOCATION; /* Quiet warning. */
3080 while (c_parser_next_token_is (parser, CPP_OPEN_SQUARE)
3081 || c_parser_next_token_is (parser, CPP_DOT))
3083 int des_prev = des_seen;
3085 des_loc = c_parser_peek_token (parser)->location;
3088 if (c_parser_next_token_is (parser, CPP_DOT))
3091 c_parser_consume_token (parser);
3092 if (c_parser_next_token_is (parser, CPP_NAME))
3094 set_init_label (c_parser_peek_token (parser)->value);
3095 c_parser_consume_token (parser);
3100 init.value = error_mark_node;
3101 init.original_code = ERROR_MARK;
3102 c_parser_error (parser, "expected identifier");
3103 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
3104 process_init_element (init, false);
3111 location_t ellipsis_loc = UNKNOWN_LOCATION; /* Quiet warning. */
3112 /* ??? Following the old parser, [ objc-receiver
3113 objc-message-args ] is accepted as an initializer,
3114 being distinguished from a designator by what follows
3115 the first assignment expression inside the square
3116 brackets, but after a first array designator a
3117 subsequent square bracket is for Objective-C taken to
3118 start an expression, using the obsolete form of
3119 designated initializer without '=', rather than
3120 possibly being a second level of designation: in LALR
3121 terms, the '[' is shifted rather than reducing
3122 designator to designator-list. */
3123 if (des_prev == 1 && c_dialect_objc ())
3125 des_seen = des_prev;
3128 if (des_prev == 0 && c_dialect_objc ())
3130 /* This might be an array designator or an
3131 Objective-C message expression. If the former,
3132 continue parsing here; if the latter, parse the
3133 remainder of the initializer given the starting
3134 primary-expression. ??? It might make sense to
3135 distinguish when des_prev == 1 as well; see
3136 previous comment. */
3138 struct c_expr mexpr;
3139 c_parser_consume_token (parser);
3140 if (c_parser_peek_token (parser)->type == CPP_NAME
3141 && ((c_parser_peek_token (parser)->id_kind
3143 || (c_parser_peek_token (parser)->id_kind
3144 == C_ID_CLASSNAME)))
3146 /* Type name receiver. */
3147 tree id = c_parser_peek_token (parser)->value;
3148 c_parser_consume_token (parser);
3149 rec = objc_get_class_reference (id);
3150 goto parse_message_args;
3152 first = c_parser_expr_no_commas (parser, NULL).value;
3153 if (c_parser_next_token_is (parser, CPP_ELLIPSIS)
3154 || c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3155 goto array_desig_after_first;
3156 /* Expression receiver. So far only one part
3157 without commas has been parsed; there might be
3158 more of the expression. */
3160 while (c_parser_next_token_is (parser, CPP_COMMA))
3163 c_parser_consume_token (parser);
3164 next = c_parser_expr_no_commas (parser, NULL);
3165 next = default_function_array_conversion (next);
3166 rec = build_compound_expr (rec, next.value);
3169 /* Now parse the objc-message-args. */
3170 args = c_parser_objc_message_args (parser);
3171 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
3174 = objc_build_message_expr (build_tree_list (rec, args));
3175 mexpr.original_code = ERROR_MARK;
3176 /* Now parse and process the remainder of the
3177 initializer, starting with this message
3178 expression as a primary-expression. */
3179 c_parser_initval (parser, &mexpr);
3182 c_parser_consume_token (parser);
3183 first = c_parser_expr_no_commas (parser, NULL).value;
3184 array_desig_after_first:
3185 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
3187 ellipsis_loc = c_parser_peek_token (parser)->location;
3188 c_parser_consume_token (parser);
3189 second = c_parser_expr_no_commas (parser, NULL).value;
3193 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3195 c_parser_consume_token (parser);
3196 set_init_index (first, second);
3198 pedwarn (ellipsis_loc, OPT_pedantic,
3199 "ISO C forbids specifying range of elements to initialize");
3202 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
3208 if (c_parser_next_token_is (parser, CPP_EQ))
3211 pedwarn (des_loc, OPT_pedantic,
3212 "ISO C90 forbids specifying subobject to initialize");
3213 c_parser_consume_token (parser);
3218 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
3219 "obsolete use of designated initializer without %<=%>");
3223 init.value = error_mark_node;
3224 init.original_code = ERROR_MARK;
3225 c_parser_error (parser, "expected %<=%>");
3226 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
3227 process_init_element (init, false);
3233 c_parser_initval (parser, NULL);
3236 /* Parse a nested initializer; as c_parser_initializer but parses
3237 initializers within braced lists, after any designators have been
3238 applied. If AFTER is not NULL then it is an Objective-C message
3239 expression which is the primary-expression starting the
3243 c_parser_initval (c_parser *parser, struct c_expr *after)
3246 gcc_assert (!after || c_dialect_objc ());
3247 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE) && !after)
3248 init = c_parser_braced_init (parser, NULL_TREE, true);
3251 init = c_parser_expr_no_commas (parser, after);
3252 if (init.value != NULL_TREE
3253 && TREE_CODE (init.value) != STRING_CST
3254 && TREE_CODE (init.value) != COMPOUND_LITERAL_EXPR)
3255 init = default_function_array_conversion (init);
3257 process_init_element (init, false);
3260 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
3264 { block-item-list[opt] }
3265 { label-declarations block-item-list }
3269 block-item-list block-item
3281 { label-declarations block-item-list }
3284 __extension__ nested-declaration
3285 nested-function-definition
3289 label-declarations label-declaration
3292 __label__ identifier-list ;
3294 Allowing the mixing of declarations and code is new in C99. The
3295 GNU syntax also permits (not shown above) labels at the end of
3296 compound statements, which yield an error. We don't allow labels
3297 on declarations; this might seem like a natural extension, but
3298 there would be a conflict between attributes on the label and
3299 prefix attributes on the declaration. ??? The syntax follows the
3300 old parser in requiring something after label declarations.
3301 Although they are erroneous if the labels declared aren't defined,
3302 is it useful for the syntax to be this way?
3314 c_parser_compound_statement (c_parser *parser)
3317 if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
3319 /* Ensure a scope is entered and left anyway to avoid confusion
3320 if we have just prepared to enter a function body. */
3321 stmt = c_begin_compound_stmt (true);
3322 c_end_compound_stmt (stmt, true);
3323 return error_mark_node;
3325 stmt = c_begin_compound_stmt (true);
3326 c_parser_compound_statement_nostart (parser);
3327 return c_end_compound_stmt (stmt, true);
3330 /* Parse a compound statement except for the opening brace. This is
3331 used for parsing both compound statements and statement expressions
3332 (which follow different paths to handling the opening). */
3335 c_parser_compound_statement_nostart (c_parser *parser)
3337 bool last_stmt = false;
3338 bool last_label = false;
3339 location_t label_loc = UNKNOWN_LOCATION; /* Quiet warning. */
3340 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3342 c_parser_consume_token (parser);
3345 if (c_parser_next_token_is_keyword (parser, RID_LABEL))
3347 location_t err_loc = c_parser_peek_token (parser)->location;
3348 /* Read zero or more forward-declarations for labels that nested
3349 functions can jump to. */
3350 while (c_parser_next_token_is_keyword (parser, RID_LABEL))
3352 c_parser_consume_token (parser);
3353 /* Any identifiers, including those declared as type names,
3358 if (c_parser_next_token_is_not (parser, CPP_NAME))
3360 c_parser_error (parser, "expected identifier");
3364 = declare_label (c_parser_peek_token (parser)->value);
3365 C_DECLARED_LABEL_FLAG (label) = 1;
3366 add_stmt (build_stmt (DECL_EXPR, label));
3367 c_parser_consume_token (parser);
3368 if (c_parser_next_token_is (parser, CPP_COMMA))
3369 c_parser_consume_token (parser);
3373 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
3375 pedwarn (err_loc, OPT_pedantic, "ISO C forbids label declarations");
3377 /* We must now have at least one statement, label or declaration. */
3378 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3380 c_parser_error (parser, "expected declaration or statement");
3381 c_parser_consume_token (parser);
3384 while (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE))
3386 location_t loc = c_parser_peek_token (parser)->location;
3387 if (c_parser_next_token_is_keyword (parser, RID_CASE)
3388 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
3389 || (c_parser_next_token_is (parser, CPP_NAME)
3390 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3392 if (c_parser_next_token_is_keyword (parser, RID_CASE))
3393 label_loc = c_parser_peek_2nd_token (parser)->location;
3395 label_loc = c_parser_peek_token (parser)->location;
3398 c_parser_label (parser);
3400 else if (!last_label
3401 && c_parser_next_token_starts_declspecs (parser))
3404 c_parser_declaration_or_fndef (parser, true, true, true, true);
3407 (pedantic && !flag_isoc99)
3409 : OPT_Wdeclaration_after_statement,
3410 "ISO C90 forbids mixed declarations and code");
3413 else if (!last_label
3414 && c_parser_next_token_is_keyword (parser, RID_EXTENSION))
3416 /* __extension__ can start a declaration, but is also an
3417 unary operator that can start an expression. Consume all
3418 but the last of a possible series of __extension__ to
3420 while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD
3421 && (c_parser_peek_2nd_token (parser)->keyword
3423 c_parser_consume_token (parser);
3424 if (c_token_starts_declspecs (c_parser_peek_2nd_token (parser)))
3427 ext = disable_extension_diagnostics ();
3428 c_parser_consume_token (parser);
3430 c_parser_declaration_or_fndef (parser, true, true, true, true);
3431 /* Following the old parser, __extension__ does not
3432 disable this diagnostic. */
3433 restore_extension_diagnostics (ext);
3435 pedwarn_c90 (loc, (pedantic && !flag_isoc99)
3437 : OPT_Wdeclaration_after_statement,
3438 "ISO C90 forbids mixed declarations and code");
3444 else if (c_parser_next_token_is (parser, CPP_PRAGMA))
3446 /* External pragmas, and some omp pragmas, are not associated
3447 with regular c code, and so are not to be considered statements
3448 syntactically. This ensures that the user doesn't put them
3449 places that would turn into syntax errors if the directive
3451 if (c_parser_pragma (parser, pragma_compound))
3452 last_label = false, last_stmt = true;
3454 else if (c_parser_next_token_is (parser, CPP_EOF))
3456 c_parser_error (parser, "expected declaration or statement");
3459 else if (c_parser_next_token_is_keyword (parser, RID_ELSE))
3461 if (parser->in_if_block)
3463 error_at (loc, """expected %<}%> before %<else%>");
3468 error_at (loc, "%<else%> without a previous %<if%>");
3469 c_parser_consume_token (parser);
3478 c_parser_statement_after_labels (parser);
3481 parser->error = false;
3484 error_at (label_loc, "label at end of compound statement");
3485 c_parser_consume_token (parser);
3488 /* Parse a label (C90 6.6.1, C99 6.8.1).
3491 identifier : attributes[opt]
3492 case constant-expression :
3498 case constant-expression ... constant-expression :
3500 The use of attributes on labels is a GNU extension. The syntax in
3501 GNU C accepts any expressions without commas, non-constant
3502 expressions being rejected later. */
3505 c_parser_label (c_parser *parser)
3507 location_t loc1 = c_parser_peek_token (parser)->location;
3508 tree label = NULL_TREE;
3509 if (c_parser_next_token_is_keyword (parser, RID_CASE))
3512 c_parser_consume_token (parser);
3513 exp1 = c_parser_expr_no_commas (parser, NULL).value;
3514 if (c_parser_next_token_is (parser, CPP_COLON))
3516 c_parser_consume_token (parser);
3517 label = do_case (exp1, NULL_TREE);
3519 else if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
3521 c_parser_consume_token (parser);
3522 exp2 = c_parser_expr_no_commas (parser, NULL).value;
3523 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
3524 label = do_case (exp1, exp2);
3527 c_parser_error (parser, "expected %<:%> or %<...%>");
3529 else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT))
3531 c_parser_consume_token (parser);
3532 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
3533 label = do_case (NULL_TREE, NULL_TREE);
3537 tree name = c_parser_peek_token (parser)->value;
3540 location_t loc2 = c_parser_peek_token (parser)->location;
3541 gcc_assert (c_parser_next_token_is (parser, CPP_NAME));
3542 c_parser_consume_token (parser);
3543 gcc_assert (c_parser_next_token_is (parser, CPP_COLON));
3544 c_parser_consume_token (parser);
3545 attrs = c_parser_attributes (parser);
3546 tlab = define_label (loc2, name);
3549 decl_attributes (&tlab, attrs, 0);
3550 label = add_stmt (build_stmt (LABEL_EXPR, tlab));
3555 SET_EXPR_LOCATION (label, loc1);
3556 if (c_parser_next_token_starts_declspecs (parser)
3557 && !(c_parser_next_token_is (parser, CPP_NAME)
3558 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3560 error_at (c_parser_peek_token (parser)->location,
3561 "a label can only be part of a statement and "
3562 "a declaration is not a statement");
3563 c_parser_declaration_or_fndef (parser, /*fndef_ok*/ false,
3564 /*nested*/ true, /*empty_ok*/ false,
3565 /*start_attr_ok*/ true);
3570 /* Parse a statement (C90 6.6, C99 6.8).
3575 expression-statement
3583 expression-statement:
3586 selection-statement:
3590 iteration-statement:
3599 return expression[opt] ;
3612 objc-throw-statement
3613 objc-try-catch-statement
3614 objc-synchronized-statement
3616 objc-throw-statement:
3630 parallel-for-construct
3631 parallel-sections-construct
3638 parallel-directive structured-block
3641 for-directive iteration-statement
3644 sections-directive section-scope
3647 single-directive structured-block
3649 parallel-for-construct:
3650 parallel-for-directive iteration-statement
3652 parallel-sections-construct:
3653 parallel-sections-directive section-scope
3656 master-directive structured-block
3659 critical-directive structured-block
3662 atomic-directive expression-statement
3665 ordered-directive structured-block */
3668 c_parser_statement (c_parser *parser)
3670 while (c_parser_next_token_is_keyword (parser, RID_CASE)
3671 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
3672 || (c_parser_next_token_is (parser, CPP_NAME)
3673 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3674 c_parser_label (parser);
3675 c_parser_statement_after_labels (parser);
3678 /* Parse a statement, other than a labeled statement. */
3681 c_parser_statement_after_labels (c_parser *parser)
3683 location_t loc = c_parser_peek_token (parser)->location;
3684 tree stmt = NULL_TREE;
3685 bool in_if_block = parser->in_if_block;
3686 parser->in_if_block = false;
3687 switch (c_parser_peek_token (parser)->type)
3689 case CPP_OPEN_BRACE:
3690 add_stmt (c_parser_compound_statement (parser));
3693 switch (c_parser_peek_token (parser)->keyword)
3696 c_parser_if_statement (parser);
3699 c_parser_switch_statement (parser);
3702 c_parser_while_statement (parser);
3705 c_parser_do_statement (parser);
3708 c_parser_for_statement (parser);
3711 c_parser_consume_token (parser);
3712 if (c_parser_next_token_is (parser, CPP_NAME))
3714 stmt = c_finish_goto_label (c_parser_peek_token (parser)->value);
3715 c_parser_consume_token (parser);
3717 else if (c_parser_next_token_is (parser, CPP_MULT))
3719 c_parser_consume_token (parser);
3720 stmt = c_finish_goto_ptr (c_parser_expression (parser).value);
3723 c_parser_error (parser, "expected identifier or %<*%>");
3724 goto expect_semicolon;
3726 c_parser_consume_token (parser);
3727 stmt = c_finish_bc_stmt (&c_cont_label, false);
3728 goto expect_semicolon;
3730 c_parser_consume_token (parser);
3731 stmt = c_finish_bc_stmt (&c_break_label, true);
3732 goto expect_semicolon;
3734 c_parser_consume_token (parser);
3735 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3737 stmt = c_finish_return (NULL_TREE);
3738 c_parser_consume_token (parser);
3742 stmt = c_finish_return (c_parser_expression_conv (parser).value);
3743 goto expect_semicolon;
3747 stmt = c_parser_asm_statement (parser);
3750 gcc_assert (c_dialect_objc ());
3751 c_parser_consume_token (parser);
3752 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3754 stmt = objc_build_throw_stmt (NULL_TREE);
3755 c_parser_consume_token (parser);
3759 tree expr = c_parser_expression (parser).value;
3760 expr = c_fully_fold (expr, false, NULL);
3761 stmt = objc_build_throw_stmt (expr);
3762 goto expect_semicolon;
3766 gcc_assert (c_dialect_objc ());
3767 c_parser_objc_try_catch_statement (parser);
3769 case RID_AT_SYNCHRONIZED:
3770 gcc_assert (c_dialect_objc ());
3771 c_parser_objc_synchronized_statement (parser);
3778 c_parser_consume_token (parser);
3780 case CPP_CLOSE_PAREN:
3781 case CPP_CLOSE_SQUARE:
3782 /* Avoid infinite loop in error recovery:
3783 c_parser_skip_until_found stops at a closing nesting
3784 delimiter without consuming it, but here we need to consume
3785 it to proceed further. */
3786 c_parser_error (parser, "expected statement");
3787 c_parser_consume_token (parser);
3790 c_parser_pragma (parser, pragma_stmt);
3794 stmt = c_finish_expr_stmt (c_parser_expression_conv (parser).value);
3796 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
3799 /* Two cases cannot and do not have line numbers associated: If stmt
3800 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
3801 cannot hold line numbers. But that's OK because the statement
3802 will either be changed to a MODIFY_EXPR during gimplification of
3803 the statement expr, or discarded. If stmt was compound, but
3804 without new variables, we will have skipped the creation of a
3805 BIND and will have a bare STATEMENT_LIST. But that's OK because
3806 (recursively) all of the component statements should already have
3807 line numbers assigned. ??? Can we discard no-op statements
3809 protected_set_expr_location (stmt, loc);
3811 parser->in_if_block = in_if_block;
3814 /* Parse the condition from an if, do, while or for statements. */
3817 c_parser_condition (c_parser *parser)
3821 loc = c_parser_peek_token (parser)->location;
3822 cond = c_parser_expression_conv (parser).value;
3823 cond = c_objc_common_truthvalue_conversion (loc, cond);
3824 cond = c_fully_fold (cond, false, NULL);
3825 protected_set_expr_location (cond, loc);
3826 if (warn_sequence_point)
3827 verify_sequence_points (cond);
3831 /* Parse a parenthesized condition from an if, do or while statement.
3837 c_parser_paren_condition (c_parser *parser)
3840 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3841 return error_mark_node;
3842 cond = c_parser_condition (parser);
3843 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
3847 /* Parse a statement which is a block in C99. */
3850 c_parser_c99_block_statement (c_parser *parser)
3852 tree block = c_begin_compound_stmt (flag_isoc99);
3853 c_parser_statement (parser);
3854 return c_end_compound_stmt (block, flag_isoc99);
3857 /* Parse the body of an if statement. This is just parsing a
3858 statement but (a) it is a block in C99, (b) we track whether the
3859 body is an if statement for the sake of -Wparentheses warnings, (c)
3860 we handle an empty body specially for the sake of -Wempty-body
3861 warnings, and (d) we call parser_compound_statement directly
3862 because c_parser_statement_after_labels resets
3863 parser->in_if_block. */
3866 c_parser_if_body (c_parser *parser, bool *if_p)
3868 tree block = c_begin_compound_stmt (flag_isoc99);
3869 while (c_parser_next_token_is_keyword (parser, RID_CASE)
3870 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
3871 || (c_parser_next_token_is (parser, CPP_NAME)
3872 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3873 c_parser_label (parser);
3874 *if_p = c_parser_next_token_is_keyword (parser, RID_IF);
3875 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3877 location_t loc = c_parser_peek_token (parser)->location;
3878 add_stmt (build_empty_stmt ());
3879 c_parser_consume_token (parser);
3880 if (!c_parser_next_token_is_keyword (parser, RID_ELSE))
3881 warning_at (loc, OPT_Wempty_body,
3882 "suggest braces around empty body in an %<if%> statement");
3884 else if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
3885 add_stmt (c_parser_compound_statement (parser));
3887 c_parser_statement_after_labels (parser);
3888 return c_end_compound_stmt (block, flag_isoc99);
3891 /* Parse the else body of an if statement. This is just parsing a
3892 statement but (a) it is a block in C99, (b) we handle an empty body
3893 specially for the sake of -Wempty-body warnings. */
3896 c_parser_else_body (c_parser *parser)
3898 tree block = c_begin_compound_stmt (flag_isoc99);
3899 while (c_parser_next_token_is_keyword (parser, RID_CASE)
3900 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
3901 || (c_parser_next_token_is (parser, CPP_NAME)
3902 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3903 c_parser_label (parser);
3904 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3906 warning_at (c_parser_peek_token (parser)->location,
3908 "suggest braces around empty body in an %<else%> statement");
3909 add_stmt (build_empty_stmt ());
3910 c_parser_consume_token (parser);
3913 c_parser_statement_after_labels (parser);
3914 return c_end_compound_stmt (block, flag_isoc99);
3917 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
3920 if ( expression ) statement
3921 if ( expression ) statement else statement
3925 c_parser_if_statement (c_parser *parser)
3930 bool first_if = false;
3931 tree first_body, second_body;
3934 gcc_assert (c_parser_next_token_is_keyword (parser, RID_IF));
3935 c_parser_consume_token (parser);
3936 block = c_begin_compound_stmt (flag_isoc99);
3937 loc = c_parser_peek_token (parser)->location;
3938 cond = c_parser_paren_condition (parser);
3939 in_if_block = parser->in_if_block;
3940 parser->in_if_block = true;
3941 first_body = c_parser_if_body (parser, &first_if);
3942 parser->in_if_block = in_if_block;
3943 if (c_parser_next_token_is_keyword (parser, RID_ELSE))
3945 c_parser_consume_token (parser);
3946 second_body = c_parser_else_body (parser);
3949 second_body = NULL_TREE;
3950 c_finish_if_stmt (loc, cond, first_body, second_body, first_if);
3951 add_stmt (c_end_compound_stmt (block, flag_isoc99));
3954 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
3957 switch (expression) statement
3961 c_parser_switch_statement (c_parser *parser)
3963 tree block, expr, body, save_break;
3964 gcc_assert (c_parser_next_token_is_keyword (parser, RID_SWITCH));
3965 c_parser_consume_token (parser);
3966 block = c_begin_compound_stmt (flag_isoc99);
3967 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3969 expr = c_parser_expression (parser).value;
3970 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
3973 expr = error_mark_node;
3974 c_start_case (expr);
3975 save_break = c_break_label;
3976 c_break_label = NULL_TREE;
3977 body = c_parser_c99_block_statement (parser);
3978 c_finish_case (body);
3980 add_stmt (build1 (LABEL_EXPR, void_type_node, c_break_label));
3981 c_break_label = save_break;
3982 add_stmt (c_end_compound_stmt (block, flag_isoc99));
3985 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
3988 while (expression) statement
3992 c_parser_while_statement (c_parser *parser)
3994 tree block, cond, body, save_break, save_cont;
3996 gcc_assert (c_parser_next_token_is_keyword (parser, RID_WHILE));
3997 c_parser_consume_token (parser);
3998 block = c_begin_compound_stmt (flag_isoc99);
3999 loc = c_parser_peek_token (parser)->location;
4000 cond = c_parser_paren_condition (parser);
4001 save_break = c_break_label;
4002 c_break_label = NULL_TREE;
4003 save_cont = c_cont_label;
4004 c_cont_label = NULL_TREE;
4005 body = c_parser_c99_block_statement (parser);
4006 c_finish_loop (loc, cond, NULL, body, c_break_label, c_cont_label, true);
4007 add_stmt (c_end_compound_stmt (block, flag_isoc99));
4008 c_break_label = save_break;
4009 c_cont_label = save_cont;
4012 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
4015 do statement while ( expression ) ;
4019 c_parser_do_statement (c_parser *parser)
4021 tree block, cond, body, save_break, save_cont, new_break, new_cont;
4023 gcc_assert (c_parser_next_token_is_keyword (parser, RID_DO));
4024 c_parser_consume_token (parser);
4025 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4026 warning_at (c_parser_peek_token (parser)->location,
4028 "suggest braces around empty body in %<do%> statement");
4029 block = c_begin_compound_stmt (flag_isoc99);
4030 loc = c_parser_peek_token (parser)->location;
4031 save_break = c_break_label;
4032 c_break_label = NULL_TREE;
4033 save_cont = c_cont_label;
4034 c_cont_label = NULL_TREE;
4035 body = c_parser_c99_block_statement (parser);
4036 c_parser_require_keyword (parser, RID_WHILE, "expected %<while%>");
4037 new_break = c_break_label;
4038 c_break_label = save_break;
4039 new_cont = c_cont_label;
4040 c_cont_label = save_cont;
4041 cond = c_parser_paren_condition (parser);
4042 if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
4043 c_parser_skip_to_end_of_block_or_statement (parser);
4044 c_finish_loop (loc, cond, NULL, body, new_break, new_cont, false);
4045 add_stmt (c_end_compound_stmt (block, flag_isoc99));
4048 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
4051 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
4052 for ( nested-declaration expression[opt] ; expression[opt] ) statement
4054 The form with a declaration is new in C99.
4056 ??? In accordance with the old parser, the declaration may be a
4057 nested function, which is then rejected in check_for_loop_decls,
4058 but does it make any sense for this to be included in the grammar?
4059 Note in particular that the nested function does not include a
4060 trailing ';', whereas the "declaration" production includes one.
4061 Also, can we reject bad declarations earlier and cheaper than
4062 check_for_loop_decls? */
4065 c_parser_for_statement (c_parser *parser)
4067 tree block, cond, incr, save_break, save_cont, body;
4069 gcc_assert (c_parser_next_token_is_keyword (parser, RID_FOR));
4070 loc = c_parser_peek_token (parser)->location;
4071 c_parser_consume_token (parser);
4072 block = c_begin_compound_stmt (flag_isoc99);
4073 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4075 /* Parse the initialization declaration or expression. */
4076 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4078 c_parser_consume_token (parser);
4079 c_finish_expr_stmt (NULL_TREE);
4081 else if (c_parser_next_token_starts_declspecs (parser))
4083 c_parser_declaration_or_fndef (parser, true, true, true, true);
4084 check_for_loop_decls ();
4086 else if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
4088 /* __extension__ can start a declaration, but is also an
4089 unary operator that can start an expression. Consume all
4090 but the last of a possible series of __extension__ to
4092 while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD
4093 && (c_parser_peek_2nd_token (parser)->keyword
4095 c_parser_consume_token (parser);
4096 if (c_token_starts_declspecs (c_parser_peek_2nd_token (parser)))
4099 ext = disable_extension_diagnostics ();
4100 c_parser_consume_token (parser);
4101 c_parser_declaration_or_fndef (parser, true, true, true, true);
4102 restore_extension_diagnostics (ext);
4103 check_for_loop_decls ();
4111 c_finish_expr_stmt (c_parser_expression (parser).value);
4112 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4114 /* Parse the loop condition. */
4115 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4117 c_parser_consume_token (parser);
4122 cond = c_parser_condition (parser);
4123 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4125 /* Parse the increment expression. */
4126 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4127 incr = c_process_expr_stmt (NULL_TREE);
4129 incr = c_process_expr_stmt (c_parser_expression (parser).value);
4130 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4134 cond = error_mark_node;
4135 incr = error_mark_node;
4137 save_break = c_break_label;
4138 c_break_label = NULL_TREE;
4139 save_cont = c_cont_label;
4140 c_cont_label = NULL_TREE;
4141 body = c_parser_c99_block_statement (parser);
4142 c_finish_loop (loc, cond, incr, body, c_break_label, c_cont_label, true);
4143 add_stmt (c_end_compound_stmt (block, flag_isoc99));
4144 c_break_label = save_break;
4145 c_cont_label = save_cont;
4148 /* Parse an asm statement, a GNU extension. This is a full-blown asm
4149 statement with inputs, outputs, clobbers, and volatile tag
4153 asm type-qualifier[opt] ( asm-argument ) ;
4157 asm-string-literal : asm-operands[opt]
4158 asm-string-literal : asm-operands[opt] : asm-operands[opt]
4159 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers
4161 Qualifiers other than volatile are accepted in the syntax but
4165 c_parser_asm_statement (c_parser *parser)
4167 tree quals, str, outputs, inputs, clobbers, ret;
4169 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
4170 c_parser_consume_token (parser);
4171 if (c_parser_next_token_is_keyword (parser, RID_VOLATILE))
4173 quals = c_parser_peek_token (parser)->value;
4174 c_parser_consume_token (parser);
4176 else if (c_parser_next_token_is_keyword (parser, RID_CONST)
4177 || c_parser_next_token_is_keyword (parser, RID_RESTRICT))
4179 warning_at (c_parser_peek_token (parser)->location,
4181 "%E qualifier ignored on asm",
4182 c_parser_peek_token (parser)->value);
4184 c_parser_consume_token (parser);
4188 /* ??? Follow the C++ parser rather than using the
4189 lex_untranslated_string kludge. */
4190 parser->lex_untranslated_string = true;
4191 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4193 parser->lex_untranslated_string = false;
4196 str = c_parser_asm_string_literal (parser);
4197 if (str == NULL_TREE)
4199 parser->lex_untranslated_string = false;
4200 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4203 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4206 outputs = NULL_TREE;
4208 clobbers = NULL_TREE;
4211 if (!c_parser_require (parser, CPP_COLON, "expected %<:%> or %<)%>"))
4213 parser->lex_untranslated_string = false;
4214 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4218 /* Parse outputs. */
4219 if (c_parser_next_token_is (parser, CPP_COLON)
4220 || c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4221 outputs = NULL_TREE;
4223 outputs = c_parser_asm_operands (parser, false);
4224 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4227 clobbers = NULL_TREE;
4230 if (!c_parser_require (parser, CPP_COLON, "expected %<:%> or %<)%>"))
4232 parser->lex_untranslated_string = false;
4233 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4237 if (c_parser_next_token_is (parser, CPP_COLON)
4238 || c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4241 inputs = c_parser_asm_operands (parser, true);
4242 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4244 clobbers = NULL_TREE;
4247 if (!c_parser_require (parser, CPP_COLON, "expected %<:%> or %<)%>"))
4249 parser->lex_untranslated_string = false;
4250 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4253 /* Parse clobbers. */
4254 clobbers = c_parser_asm_clobbers (parser);
4256 parser->lex_untranslated_string = false;
4257 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
4259 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4262 if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
4263 c_parser_skip_to_end_of_block_or_statement (parser);
4264 ret = build_asm_stmt (quals, build_asm_expr (str, outputs, inputs,
4269 /* Parse asm operands, a GNU extension. If CONVERT_P (for inputs but
4270 not outputs), apply the default conversion of functions and arrays
4275 asm-operands , asm-operand
4278 asm-string-literal ( expression )
4279 [ identifier ] asm-string-literal ( expression )
4283 c_parser_asm_operands (c_parser *parser, bool convert_p)
4285 tree list = NULL_TREE;
4290 if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
4292 c_parser_consume_token (parser);
4293 if (c_parser_next_token_is (parser, CPP_NAME))
4295 tree id = c_parser_peek_token (parser)->value;
4296 c_parser_consume_token (parser);
4297 name = build_string (IDENTIFIER_LENGTH (id),
4298 IDENTIFIER_POINTER (id));
4302 c_parser_error (parser, "expected identifier");
4303 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
4306 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
4311 str = c_parser_asm_string_literal (parser);
4312 if (str == NULL_TREE)
4314 parser->lex_untranslated_string = false;
4315 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4317 parser->lex_untranslated_string = true;
4320 expr = c_parser_expression (parser);
4322 expr = default_function_array_conversion (expr);
4323 expr.value = c_fully_fold (expr.value, false, NULL);
4324 parser->lex_untranslated_string = true;
4325 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
4327 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4330 list = chainon (list, build_tree_list (build_tree_list (name, str),
4332 if (c_parser_next_token_is (parser, CPP_COMMA))
4333 c_parser_consume_token (parser);
4340 /* Parse asm clobbers, a GNU extension.
4344 asm-clobbers , asm-string-literal
4348 c_parser_asm_clobbers (c_parser *parser)
4350 tree list = NULL_TREE;
4353 tree str = c_parser_asm_string_literal (parser);
4355 list = tree_cons (NULL_TREE, str, list);
4358 if (c_parser_next_token_is (parser, CPP_COMMA))
4359 c_parser_consume_token (parser);
4366 /* Parse an expression other than a compound expression; that is, an
4367 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
4368 NULL then it is an Objective-C message expression which is the
4369 primary-expression starting the expression as an initializer.
4371 assignment-expression:
4372 conditional-expression
4373 unary-expression assignment-operator assignment-expression
4375 assignment-operator: one of
4376 = *= /= %= += -= <<= >>= &= ^= |=
4378 In GNU C we accept any conditional expression on the LHS and
4379 diagnose the invalid lvalue rather than producing a syntax
4382 static struct c_expr
4383 c_parser_expr_no_commas (c_parser *parser, struct c_expr *after)
4385 struct c_expr lhs, rhs, ret;
4386 enum tree_code code;
4387 location_t op_location;
4388 gcc_assert (!after || c_dialect_objc ());
4389 lhs = c_parser_conditional_expression (parser, after);
4390 op_location = c_parser_peek_token (parser)->location;
4391 switch (c_parser_peek_token (parser)->type)
4400 code = TRUNC_DIV_EXPR;
4403 code = TRUNC_MOD_EXPR;
4418 code = BIT_AND_EXPR;
4421 code = BIT_XOR_EXPR;
4424 code = BIT_IOR_EXPR;
4429 c_parser_consume_token (parser);
4430 rhs = c_parser_expr_no_commas (parser, NULL);
4431 rhs = default_function_array_conversion (rhs);
4432 ret.value = build_modify_expr (op_location, lhs.value, code, rhs.value);
4433 if (code == NOP_EXPR)
4434 ret.original_code = MODIFY_EXPR;
4437 TREE_NO_WARNING (ret.value) = 1;
4438 ret.original_code = ERROR_MARK;
4443 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
4444 is not NULL then it is an Objective-C message expression which is
4445 the primary-expression starting the expression as an initializer.
4447 conditional-expression:
4448 logical-OR-expression
4449 logical-OR-expression ? expression : conditional-expression
4453 conditional-expression:
4454 logical-OR-expression ? : conditional-expression
4457 static struct c_expr
4458 c_parser_conditional_expression (c_parser *parser, struct c_expr *after)
4460 struct c_expr cond, exp1, exp2, ret;
4461 location_t cond_loc;
4463 gcc_assert (!after || c_dialect_objc ());
4465 cond_loc = c_parser_peek_token (parser)->location;
4466 cond = c_parser_binary_expression (parser, after);
4467 protected_set_expr_location (cond.value, cond_loc);
4469 if (c_parser_next_token_is_not (parser, CPP_QUERY))
4471 cond = default_function_array_conversion (cond);
4472 c_parser_consume_token (parser);
4473 if (c_parser_next_token_is (parser, CPP_COLON))
4475 tree eptype = NULL_TREE;
4476 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
4477 "ISO C forbids omitting the middle term of a ?: expression");
4478 if (TREE_CODE (cond.value) == EXCESS_PRECISION_EXPR)
4480 eptype = TREE_TYPE (cond.value);
4481 cond.value = TREE_OPERAND (cond.value, 0);
4483 /* Make sure first operand is calculated only once. */
4484 exp1.value = c_save_expr (default_conversion (cond.value));
4486 exp1.value = build1 (EXCESS_PRECISION_EXPR, eptype, exp1.value);
4487 cond.value = c_objc_common_truthvalue_conversion (cond_loc, exp1.value);
4488 skip_evaluation += cond.value == truthvalue_true_node;
4493 = c_objc_common_truthvalue_conversion
4494 (cond_loc, default_conversion (cond.value));
4495 skip_evaluation += cond.value == truthvalue_false_node;
4496 exp1 = c_parser_expression_conv (parser);
4497 skip_evaluation += ((cond.value == truthvalue_true_node)
4498 - (cond.value == truthvalue_false_node));
4500 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
4502 skip_evaluation -= cond.value == truthvalue_true_node;
4503 ret.value = error_mark_node;
4504 ret.original_code = ERROR_MARK;
4507 exp2 = c_parser_conditional_expression (parser, NULL);
4508 exp2 = default_function_array_conversion (exp2);
4509 skip_evaluation -= cond.value == truthvalue_true_node;
4510 ret.value = build_conditional_expr (cond.value,
4511 cond.original_code == C_MAYBE_CONST_EXPR,
4512 exp1.value, exp2.value);
4513 ret.original_code = ERROR_MARK;
4517 /* Parse a binary expression; that is, a logical-OR-expression (C90
4518 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
4519 an Objective-C message expression which is the primary-expression
4520 starting the expression as an initializer.
4522 multiplicative-expression:
4524 multiplicative-expression * cast-expression
4525 multiplicative-expression / cast-expression
4526 multiplicative-expression % cast-expression
4528 additive-expression:
4529 multiplicative-expression
4530 additive-expression + multiplicative-expression
4531 additive-expression - multiplicative-expression
4535 shift-expression << additive-expression
4536 shift-expression >> additive-expression
4538 relational-expression:
4540 relational-expression < shift-expression
4541 relational-expression > shift-expression
4542 relational-expression <= shift-expression
4543 relational-expression >= shift-expression
4545 equality-expression:
4546 relational-expression
4547 equality-expression == relational-expression
4548 equality-expression != relational-expression
4552 AND-expression & equality-expression
4554 exclusive-OR-expression:
4556 exclusive-OR-expression ^ AND-expression
4558 inclusive-OR-expression:
4559 exclusive-OR-expression
4560 inclusive-OR-expression | exclusive-OR-expression
4562 logical-AND-expression:
4563 inclusive-OR-expression
4564 logical-AND-expression && inclusive-OR-expression
4566 logical-OR-expression:
4567 logical-AND-expression
4568 logical-OR-expression || logical-AND-expression
4571 static struct c_expr
4572 c_parser_binary_expression (c_parser *parser, struct c_expr *after)
4574 /* A binary expression is parsed using operator-precedence parsing,
4575 with the operands being cast expressions. All the binary
4576 operators are left-associative. Thus a binary expression is of
4579 E0 op1 E1 op2 E2 ...
4581 which we represent on a stack. On the stack, the precedence
4582 levels are strictly increasing. When a new operator is
4583 encountered of higher precedence than that at the top of the
4584 stack, it is pushed; its LHS is the top expression, and its RHS
4585 is everything parsed until it is popped. When a new operator is
4586 encountered with precedence less than or equal to that at the top
4587 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
4588 by the result of the operation until the operator at the top of
4589 the stack has lower precedence than the new operator or there is
4590 only one element on the stack; then the top expression is the LHS
4591 of the new operator. In the case of logical AND and OR
4592 expressions, we also need to adjust skip_evaluation as
4593 appropriate when the operators are pushed and popped. */
4595 /* The precedence levels, where 0 is a dummy lowest level used for
4596 the bottom of the stack. */
4612 /* The expression at this stack level. */
4614 /* The precedence of the operator on its left, PREC_NONE at the
4615 bottom of the stack. */
4617 /* The operation on its left. */
4621 /* Location of the binary operator. */
4622 location_t binary_loc = UNKNOWN_LOCATION; /* Quiet warning. */
4625 switch (stack[sp].op) \
4627 case TRUTH_ANDIF_EXPR: \
4628 skip_evaluation -= stack[sp - 1].expr.value == truthvalue_false_node; \
4630 case TRUTH_ORIF_EXPR: \
4631 skip_evaluation -= stack[sp - 1].expr.value == truthvalue_true_node; \
4636 stack[sp - 1].expr \
4637 = default_function_array_conversion (stack[sp - 1].expr); \
4639 = default_function_array_conversion (stack[sp].expr); \
4640 stack[sp - 1].expr = parser_build_binary_op (binary_loc, \
4642 stack[sp - 1].expr, \
4646 gcc_assert (!after || c_dialect_objc ());
4647 stack[0].expr = c_parser_cast_expression (parser, after);
4648 stack[0].prec = PREC_NONE;
4653 enum tree_code ocode;
4656 switch (c_parser_peek_token (parser)->type)
4664 ocode = TRUNC_DIV_EXPR;
4668 ocode = TRUNC_MOD_EXPR;
4680 ocode = LSHIFT_EXPR;
4684 ocode = RSHIFT_EXPR;
4698 case CPP_GREATER_EQ:
4711 oprec = PREC_BITAND;
4712 ocode = BIT_AND_EXPR;
4715 oprec = PREC_BITXOR;
4716 ocode = BIT_XOR_EXPR;
4720 ocode = BIT_IOR_EXPR;
4723 oprec = PREC_LOGAND;
4724 ocode = TRUTH_ANDIF_EXPR;
4728 ocode = TRUTH_ORIF_EXPR;
4731 /* Not a binary operator, so end of the binary
4735 binary_loc = c_parser_peek_token (parser)->location;
4736 c_parser_consume_token (parser);
4737 while (oprec <= stack[sp].prec)
4741 case TRUTH_ANDIF_EXPR:
4743 = default_function_array_conversion (stack[sp].expr);
4744 stack[sp].expr.value = c_objc_common_truthvalue_conversion
4745 (binary_loc, default_conversion (stack[sp].expr.value));
4746 skip_evaluation += stack[sp].expr.value == truthvalue_false_node;
4748 case TRUTH_ORIF_EXPR:
4750 = default_function_array_conversion (stack[sp].expr);
4751 stack[sp].expr.value = c_objc_common_truthvalue_conversion
4752 (binary_loc, default_conversion (stack[sp].expr.value));
4753 skip_evaluation += stack[sp].expr.value == truthvalue_true_node;
4759 stack[sp].expr = c_parser_cast_expression (parser, NULL);
4760 stack[sp].prec = oprec;
4761 stack[sp].op = ocode;
4766 return stack[0].expr;
4770 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
4771 NULL then it is an Objective-C message expression which is the
4772 primary-expression starting the expression as an initializer.
4776 ( type-name ) unary-expression
4779 static struct c_expr
4780 c_parser_cast_expression (c_parser *parser, struct c_expr *after)
4782 gcc_assert (!after || c_dialect_objc ());
4784 return c_parser_postfix_expression_after_primary (parser, *after);
4785 /* If the expression begins with a parenthesized type name, it may
4786 be either a cast or a compound literal; we need to see whether
4787 the next character is '{' to tell the difference. If not, it is
4788 an unary expression. */
4789 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
4790 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
4792 struct c_type_name *type_name;
4795 c_parser_consume_token (parser);
4796 type_name = c_parser_type_name (parser);
4797 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4798 if (type_name == NULL)
4800 ret.value = error_mark_node;
4801 ret.original_code = ERROR_MARK;
4805 /* Save casted types in the function's used types hash table. */
4806 used_types_insert (type_name->specs->type);
4808 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
4809 return c_parser_postfix_expression_after_paren_type (parser,
4811 expr = c_parser_cast_expression (parser, NULL);
4812 expr = default_function_array_conversion (expr);
4813 ret.value = c_cast_expr (type_name, expr.value);
4814 ret.original_code = ERROR_MARK;
4818 return c_parser_unary_expression (parser);
4821 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
4827 unary-operator cast-expression
4828 sizeof unary-expression
4829 sizeof ( type-name )
4831 unary-operator: one of
4837 __alignof__ unary-expression
4838 __alignof__ ( type-name )
4841 unary-operator: one of
4842 __extension__ __real__ __imag__
4844 In addition, the GNU syntax treats ++ and -- as unary operators, so
4845 they may be applied to cast expressions with errors for non-lvalues
4848 static struct c_expr
4849 c_parser_unary_expression (c_parser *parser)
4852 struct c_expr ret, op;
4853 location_t loc = c_parser_peek_token (parser)->location;
4854 switch (c_parser_peek_token (parser)->type)
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 (PREINCREMENT_EXPR, op, loc);
4861 case CPP_MINUS_MINUS:
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 (PREDECREMENT_EXPR, op, loc);
4867 c_parser_consume_token (parser);
4868 return parser_build_unary_op (ADDR_EXPR,
4869 c_parser_cast_expression (parser, NULL),
4872 c_parser_consume_token (parser);
4873 op = c_parser_cast_expression (parser, NULL);
4874 op = default_function_array_conversion (op);
4875 ret.value = build_indirect_ref (loc, op.value, "unary *");
4876 ret.original_code = ERROR_MARK;
4879 if (!c_dialect_objc () && !in_system_header)
4880 warning_at (c_parser_peek_token (parser)->location,
4882 "traditional C rejects the unary plus operator");
4883 c_parser_consume_token (parser);
4884 op = c_parser_cast_expression (parser, NULL);
4885 op = default_function_array_conversion (op);
4886 return parser_build_unary_op (CONVERT_EXPR, op, loc);
4888 c_parser_consume_token (parser);
4889 op = c_parser_cast_expression (parser, NULL);
4890 op = default_function_array_conversion (op);
4891 return parser_build_unary_op (NEGATE_EXPR, op, loc);
4893 c_parser_consume_token (parser);
4894 op = c_parser_cast_expression (parser, NULL);
4895 op = default_function_array_conversion (op);
4896 return parser_build_unary_op (BIT_NOT_EXPR, op, loc);
4898 c_parser_consume_token (parser);
4899 op = c_parser_cast_expression (parser, NULL);
4900 op = default_function_array_conversion (op);
4901 return parser_build_unary_op (TRUTH_NOT_EXPR, op, loc);
4903 /* Refer to the address of a label as a pointer. */
4904 c_parser_consume_token (parser);
4905 if (c_parser_next_token_is (parser, CPP_NAME))
4907 ret.value = finish_label_address_expr
4908 (c_parser_peek_token (parser)->value, loc);
4909 c_parser_consume_token (parser);
4913 c_parser_error (parser, "expected identifier");
4914 ret.value = error_mark_node;
4916 ret.original_code = ERROR_MARK;
4919 switch (c_parser_peek_token (parser)->keyword)
4922 return c_parser_sizeof_expression (parser);
4924 return c_parser_alignof_expression (parser);
4926 c_parser_consume_token (parser);
4927 ext = disable_extension_diagnostics ();
4928 ret = c_parser_cast_expression (parser, NULL);
4929 restore_extension_diagnostics (ext);
4932 c_parser_consume_token (parser);
4933 op = c_parser_cast_expression (parser, NULL);
4934 op = default_function_array_conversion (op);
4935 return parser_build_unary_op (REALPART_EXPR, op, loc);
4937 c_parser_consume_token (parser);
4938 op = c_parser_cast_expression (parser, NULL);
4939 op = default_function_array_conversion (op);
4940 return parser_build_unary_op (IMAGPART_EXPR, op, loc);
4942 return c_parser_postfix_expression (parser);
4945 return c_parser_postfix_expression (parser);
4949 /* Parse a sizeof expression. */
4951 static struct c_expr
4952 c_parser_sizeof_expression (c_parser *parser)
4955 location_t expr_loc;
4956 gcc_assert (c_parser_next_token_is_keyword (parser, RID_SIZEOF));
4957 c_parser_consume_token (parser);
4960 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
4961 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
4963 /* Either sizeof ( type-name ) or sizeof unary-expression
4964 starting with a compound literal. */
4965 struct c_type_name *type_name;
4966 c_parser_consume_token (parser);
4967 expr_loc = c_parser_peek_token (parser)->location;
4968 type_name = c_parser_type_name (parser);
4969 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4970 if (type_name == NULL)
4975 ret.value = error_mark_node;
4976 ret.original_code = ERROR_MARK;
4979 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
4981 expr = c_parser_postfix_expression_after_paren_type (parser,
4985 /* sizeof ( type-name ). */
4988 return c_expr_sizeof_type (type_name);
4992 expr_loc = c_parser_peek_token (parser)->location;
4993 expr = c_parser_unary_expression (parser);
4997 if (TREE_CODE (expr.value) == COMPONENT_REF
4998 && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
4999 error_at (expr_loc, "%<sizeof%> applied to a bit-field");
5000 return c_expr_sizeof_expr (expr);
5004 /* Parse an alignof expression. */
5006 static struct c_expr
5007 c_parser_alignof_expression (c_parser *parser)
5010 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ALIGNOF));
5011 c_parser_consume_token (parser);
5014 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
5015 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
5017 /* Either __alignof__ ( type-name ) or __alignof__
5018 unary-expression starting with a compound literal. */
5019 struct c_type_name *type_name;
5021 c_parser_consume_token (parser);
5022 type_name = c_parser_type_name (parser);
5023 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5024 if (type_name == NULL)
5029 ret.value = error_mark_node;
5030 ret.original_code = ERROR_MARK;
5033 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
5035 expr = c_parser_postfix_expression_after_paren_type (parser,
5039 /* alignof ( type-name ). */
5042 ret.value = c_alignof (groktypename (type_name, NULL, NULL));
5043 ret.original_code = ERROR_MARK;
5049 expr = c_parser_unary_expression (parser);
5053 ret.value = c_alignof_expr (expr.value);
5054 ret.original_code = ERROR_MARK;
5059 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
5063 postfix-expression [ expression ]
5064 postfix-expression ( argument-expression-list[opt] )
5065 postfix-expression . identifier
5066 postfix-expression -> identifier
5067 postfix-expression ++
5068 postfix-expression --
5069 ( type-name ) { initializer-list }
5070 ( type-name ) { initializer-list , }
5072 argument-expression-list:
5074 argument-expression-list , argument-expression
5086 (treated as a keyword in GNU C)
5089 ( compound-statement )
5090 __builtin_va_arg ( assignment-expression , type-name )
5091 __builtin_offsetof ( type-name , offsetof-member-designator )
5092 __builtin_choose_expr ( assignment-expression ,
5093 assignment-expression ,
5094 assignment-expression )
5095 __builtin_types_compatible_p ( type-name , type-name )
5097 offsetof-member-designator:
5099 offsetof-member-designator . identifier
5100 offsetof-member-designator [ expression ]
5105 [ objc-receiver objc-message-args ]
5106 @selector ( objc-selector-arg )
5107 @protocol ( identifier )
5108 @encode ( type-name )
5112 static struct c_expr
5113 c_parser_postfix_expression (c_parser *parser)
5115 struct c_expr expr, e1, e2, e3;
5116 struct c_type_name *t1, *t2;
5118 switch (c_parser_peek_token (parser)->type)
5121 expr.value = c_parser_peek_token (parser)->value;
5122 expr.original_code = ERROR_MARK;
5123 loc = c_parser_peek_token (parser)->location;
5124 c_parser_consume_token (parser);
5125 if (TREE_CODE (expr.value) == FIXED_CST
5126 && !targetm.fixed_point_supported_p ())
5128 error_at (loc, "fixed-point types not supported for this target");
5129 expr.value = error_mark_node;
5136 expr.value = c_parser_peek_token (parser)->value;
5137 expr.original_code = ERROR_MARK;
5138 c_parser_consume_token (parser);
5144 expr.value = c_parser_peek_token (parser)->value;
5145 expr.original_code = STRING_CST;
5146 c_parser_consume_token (parser);
5148 case CPP_OBJC_STRING:
5149 gcc_assert (c_dialect_objc ());
5151 = objc_build_string_object (c_parser_peek_token (parser)->value);
5152 expr.original_code = ERROR_MARK;
5153 c_parser_consume_token (parser);
5156 if (c_parser_peek_token (parser)->id_kind != C_ID_ID)
5158 c_parser_error (parser, "expected expression");
5159 expr.value = error_mark_node;
5160 expr.original_code = ERROR_MARK;
5164 tree id = c_parser_peek_token (parser)->value;
5165 location_t loc = c_parser_peek_token (parser)->location;
5166 c_parser_consume_token (parser);
5167 expr.value = build_external_ref (id,
5168 (c_parser_peek_token (parser)->type
5169 == CPP_OPEN_PAREN), loc);
5170 expr.original_code = ERROR_MARK;
5173 case CPP_OPEN_PAREN:
5174 /* A parenthesized expression, statement expression or compound
5176 if (c_parser_peek_2nd_token (parser)->type == CPP_OPEN_BRACE)
5178 /* A statement expression. */
5180 location_t here = c_parser_peek_token (parser)->location;
5181 c_parser_consume_token (parser);
5182 c_parser_consume_token (parser);
5183 if (cur_stmt_list == NULL)
5185 error_at (here, "braced-group within expression allowed "
5186 "only inside a function");
5187 parser->error = true;
5188 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
5189 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5190 expr.value = error_mark_node;
5191 expr.original_code = ERROR_MARK;
5194 stmt = c_begin_stmt_expr ();
5195 c_parser_compound_statement_nostart (parser);
5196 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5198 pedwarn (here, OPT_pedantic,
5199 "ISO C forbids braced-groups within expressions");
5200 expr.value = c_finish_stmt_expr (stmt);
5201 expr.original_code = ERROR_MARK;
5203 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser)))
5205 /* A compound literal. ??? Can we actually get here rather
5206 than going directly to
5207 c_parser_postfix_expression_after_paren_type from
5209 struct c_type_name *type_name;
5210 c_parser_consume_token (parser);
5211 type_name = c_parser_type_name (parser);
5212 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5214 if (type_name == NULL)
5216 expr.value = error_mark_node;
5217 expr.original_code = ERROR_MARK;
5220 expr = c_parser_postfix_expression_after_paren_type (parser,
5225 /* A parenthesized expression. */
5226 c_parser_consume_token (parser);
5227 expr = c_parser_expression (parser);
5228 if (TREE_CODE (expr.value) == MODIFY_EXPR)
5229 TREE_NO_WARNING (expr.value) = 1;
5230 if (expr.original_code != C_MAYBE_CONST_EXPR)
5231 expr.original_code = ERROR_MARK;
5232 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5237 switch (c_parser_peek_token (parser)->keyword)
5239 case RID_FUNCTION_NAME:
5240 case RID_PRETTY_FUNCTION_NAME:
5241 case RID_C99_FUNCTION_NAME:
5242 expr.value = fname_decl (c_parser_peek_token (parser)->location,
5243 c_parser_peek_token (parser)->keyword,
5244 c_parser_peek_token (parser)->value);
5245 expr.original_code = ERROR_MARK;
5246 c_parser_consume_token (parser);
5249 c_parser_consume_token (parser);
5250 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5252 expr.value = error_mark_node;
5253 expr.original_code = ERROR_MARK;
5256 e1 = c_parser_expr_no_commas (parser, NULL);
5257 e1.value = c_fully_fold (e1.value, false, NULL);
5258 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5260 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5261 expr.value = error_mark_node;
5262 expr.original_code = ERROR_MARK;
5265 t1 = c_parser_type_name (parser);
5266 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5270 expr.value = error_mark_node;
5271 expr.original_code = ERROR_MARK;
5275 tree type_expr = NULL_TREE;
5276 expr.value = build_va_arg (e1.value, groktypename (t1,
5281 expr.value = build2 (C_MAYBE_CONST_EXPR,
5282 TREE_TYPE (expr.value), type_expr,
5284 C_MAYBE_CONST_EXPR_NON_CONST (expr.value) = true;
5286 expr.original_code = ERROR_MARK;
5290 c_parser_consume_token (parser);
5291 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5293 expr.value = error_mark_node;
5294 expr.original_code = ERROR_MARK;
5297 t1 = c_parser_type_name (parser);
5300 expr.value = error_mark_node;
5301 expr.original_code = ERROR_MARK;
5304 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5306 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5307 expr.value = error_mark_node;
5308 expr.original_code = ERROR_MARK;
5312 tree type = groktypename (t1, NULL, NULL);
5314 if (type == error_mark_node)
5315 offsetof_ref = error_mark_node;
5317 offsetof_ref = build1 (INDIRECT_REF, type, null_pointer_node);
5318 /* Parse the second argument to __builtin_offsetof. We
5319 must have one identifier, and beyond that we want to
5320 accept sub structure and sub array references. */
5321 if (c_parser_next_token_is (parser, CPP_NAME))
5323 offsetof_ref = build_component_ref
5324 (offsetof_ref, c_parser_peek_token (parser)->value);
5325 c_parser_consume_token (parser);
5326 while (c_parser_next_token_is (parser, CPP_DOT)
5327 || c_parser_next_token_is (parser,
5329 || c_parser_next_token_is (parser,
5332 if (c_parser_next_token_is (parser, CPP_DEREF))
5334 loc = c_parser_peek_token (parser)->location;
5335 offsetof_ref = build_array_ref (offsetof_ref,
5340 else if (c_parser_next_token_is (parser, CPP_DOT))
5343 c_parser_consume_token (parser);
5344 if (c_parser_next_token_is_not (parser,
5347 c_parser_error (parser, "expected identifier");
5350 offsetof_ref = build_component_ref
5352 c_parser_peek_token (parser)->value);
5353 c_parser_consume_token (parser);
5358 loc = c_parser_peek_token (parser)->location;
5359 c_parser_consume_token (parser);
5360 idx = c_parser_expression (parser).value;
5361 idx = c_fully_fold (idx, false, NULL);
5362 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
5364 offsetof_ref = build_array_ref (offsetof_ref, idx, loc);
5369 c_parser_error (parser, "expected identifier");
5370 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5372 expr.value = fold_offsetof (offsetof_ref, NULL_TREE);
5373 expr.original_code = ERROR_MARK;
5376 case RID_CHOOSE_EXPR:
5377 c_parser_consume_token (parser);
5378 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5380 expr.value = error_mark_node;
5381 expr.original_code = ERROR_MARK;
5384 loc = c_parser_peek_token (parser)->location;
5385 e1 = c_parser_expr_no_commas (parser, NULL);
5386 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5388 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5389 expr.value = error_mark_node;
5390 expr.original_code = ERROR_MARK;
5393 e2 = c_parser_expr_no_commas (parser, NULL);
5394 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5396 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5397 expr.value = error_mark_node;
5398 expr.original_code = ERROR_MARK;
5401 e3 = c_parser_expr_no_commas (parser, NULL);
5402 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5408 if (TREE_CODE (c) != INTEGER_CST
5409 || !INTEGRAL_TYPE_P (TREE_TYPE (c)))
5411 "first argument to %<__builtin_choose_expr%> not"
5413 constant_expression_warning (c);
5414 expr = integer_zerop (c) ? e3 : e2;
5417 case RID_TYPES_COMPATIBLE_P:
5418 c_parser_consume_token (parser);
5419 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5421 expr.value = error_mark_node;
5422 expr.original_code = ERROR_MARK;
5425 t1 = c_parser_type_name (parser);
5428 expr.value = error_mark_node;
5429 expr.original_code = ERROR_MARK;
5432 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5434 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5435 expr.value = error_mark_node;
5436 expr.original_code = ERROR_MARK;
5439 t2 = c_parser_type_name (parser);
5442 expr.value = error_mark_node;
5443 expr.original_code = ERROR_MARK;
5446 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5451 e1 = TYPE_MAIN_VARIANT (groktypename (t1, NULL, NULL));
5452 e2 = TYPE_MAIN_VARIANT (groktypename (t2, NULL, NULL));
5454 expr.value = comptypes (e1, e2)
5455 ? build_int_cst (NULL_TREE, 1)
5456 : build_int_cst (NULL_TREE, 0);
5457 expr.original_code = ERROR_MARK;
5460 case RID_AT_SELECTOR:
5461 gcc_assert (c_dialect_objc ());
5462 c_parser_consume_token (parser);
5463 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5465 expr.value = error_mark_node;
5466 expr.original_code = ERROR_MARK;
5470 tree sel = c_parser_objc_selector_arg (parser);
5471 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5473 expr.value = objc_build_selector_expr (sel);
5474 expr.original_code = ERROR_MARK;
5477 case RID_AT_PROTOCOL:
5478 gcc_assert (c_dialect_objc ());
5479 c_parser_consume_token (parser);
5480 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5482 expr.value = error_mark_node;
5483 expr.original_code = ERROR_MARK;
5486 if (c_parser_next_token_is_not (parser, CPP_NAME))
5488 c_parser_error (parser, "expected identifier");
5489 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5490 expr.value = error_mark_node;
5491 expr.original_code = ERROR_MARK;
5495 tree id = c_parser_peek_token (parser)->value;
5496 c_parser_consume_token (parser);
5497 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5499 expr.value = objc_build_protocol_expr (id);
5500 expr.original_code = ERROR_MARK;
5504 /* Extension to support C-structures in the archiver. */
5505 gcc_assert (c_dialect_objc ());
5506 c_parser_consume_token (parser);
5507 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5509 expr.value = error_mark_node;
5510 expr.original_code = ERROR_MARK;
5513 t1 = c_parser_type_name (parser);
5516 expr.value = error_mark_node;
5517 expr.original_code = ERROR_MARK;
5518 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5521 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5524 tree type = groktypename (t1, NULL, NULL);
5525 expr.value = objc_build_encode_expr (type);
5526 expr.original_code = ERROR_MARK;
5530 c_parser_error (parser, "expected expression");
5531 expr.value = error_mark_node;
5532 expr.original_code = ERROR_MARK;
5536 case CPP_OPEN_SQUARE:
5537 if (c_dialect_objc ())
5539 tree receiver, args;
5540 c_parser_consume_token (parser);
5541 receiver = c_parser_objc_receiver (parser);
5542 args = c_parser_objc_message_args (parser);
5543 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
5545 expr.value = objc_build_message_expr (build_tree_list (receiver,
5547 expr.original_code = ERROR_MARK;
5550 /* Else fall through to report error. */
5552 c_parser_error (parser, "expected expression");
5553 expr.value = error_mark_node;
5554 expr.original_code = ERROR_MARK;
5557 return c_parser_postfix_expression_after_primary (parser, expr);
5560 /* Parse a postfix expression after a parenthesized type name: the
5561 brace-enclosed initializer of a compound literal, possibly followed
5562 by some postfix operators. This is separate because it is not
5563 possible to tell until after the type name whether a cast
5564 expression has a cast or a compound literal, or whether the operand
5565 of sizeof is a parenthesized type name or starts with a compound
5568 static struct c_expr
5569 c_parser_postfix_expression_after_paren_type (c_parser *parser,
5570 struct c_type_name *type_name)
5576 location_t start_loc;
5577 tree type_expr = NULL_TREE;
5578 bool type_expr_const = true;
5579 start_init (NULL_TREE, NULL, 0);
5580 type = groktypename (type_name, &type_expr, &type_expr_const);
5581 start_loc = c_parser_peek_token (parser)->location;
5582 if (type != error_mark_node && C_TYPE_VARIABLE_SIZE (type))
5584 error_at (start_loc, "compound literal has variable size");
5585 type = error_mark_node;
5587 init = c_parser_braced_init (parser, type, false);
5589 maybe_warn_string_init (type, init);
5592 pedwarn (start_loc, OPT_pedantic, "ISO C90 forbids compound literals");
5593 non_const = ((init.value && TREE_CODE (init.value) == CONSTRUCTOR)
5594 ? CONSTRUCTOR_NON_CONST (init.value)
5595 : init.original_code == C_MAYBE_CONST_EXPR);
5596 non_const |= !type_expr_const;
5597 expr.value = build_compound_literal (type, init.value, non_const);
5598 expr.original_code = ERROR_MARK;
5601 if (TREE_CODE (expr.value) == C_MAYBE_CONST_EXPR)
5603 gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr.value) == NULL_TREE);
5604 C_MAYBE_CONST_EXPR_PRE (expr.value) = type_expr;
5608 gcc_assert (!non_const);
5609 expr.value = build2 (C_MAYBE_CONST_EXPR, type,
5610 type_expr, expr.value);
5613 return c_parser_postfix_expression_after_primary (parser, expr);
5616 /* Parse a postfix expression after the initial primary or compound
5617 literal; that is, parse a series of postfix operators. */
5619 static struct c_expr
5620 c_parser_postfix_expression_after_primary (c_parser *parser,
5623 struct c_expr orig_expr;
5624 tree ident, idx, exprlist;
5625 location_t loc = c_parser_peek_token (parser)->location;
5628 switch (c_parser_peek_token (parser)->type)
5630 case CPP_OPEN_SQUARE:
5631 /* Array reference. */
5632 loc = c_parser_peek_token (parser)->location;
5633 c_parser_consume_token (parser);
5634 idx = c_parser_expression (parser).value;
5635 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
5637 expr.value = build_array_ref (expr.value, idx, loc);
5638 expr.original_code = ERROR_MARK;
5640 case CPP_OPEN_PAREN:
5641 /* Function call. */
5642 c_parser_consume_token (parser);
5643 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
5644 exprlist = NULL_TREE;
5646 exprlist = c_parser_expr_list (parser, true, false);
5647 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5650 expr.value = build_function_call (expr.value, exprlist);
5651 expr.original_code = ERROR_MARK;
5652 if (TREE_CODE (expr.value) == INTEGER_CST
5653 && TREE_CODE (orig_expr.value) == FUNCTION_DECL
5654 && DECL_BUILT_IN_CLASS (orig_expr.value) == BUILT_IN_NORMAL
5655 && DECL_FUNCTION_CODE (orig_expr.value) == BUILT_IN_CONSTANT_P)
5656 expr.original_code = C_MAYBE_CONST_EXPR;
5659 /* Structure element reference. */
5660 c_parser_consume_token (parser);
5661 expr = default_function_array_conversion (expr);
5662 if (c_parser_next_token_is (parser, CPP_NAME))
5663 ident = c_parser_peek_token (parser)->value;
5666 c_parser_error (parser, "expected identifier");
5667 expr.value = error_mark_node;
5668 expr.original_code = ERROR_MARK;
5671 c_parser_consume_token (parser);
5672 expr.value = build_component_ref (expr.value, ident);
5673 expr.original_code = ERROR_MARK;
5676 /* Structure element reference. */
5677 c_parser_consume_token (parser);
5678 expr = default_function_array_conversion (expr);
5679 if (c_parser_next_token_is (parser, CPP_NAME))
5680 ident = c_parser_peek_token (parser)->value;
5683 c_parser_error (parser, "expected identifier");
5684 expr.value = error_mark_node;
5685 expr.original_code = ERROR_MARK;
5688 c_parser_consume_token (parser);
5689 expr.value = build_component_ref (build_indirect_ref (loc,
5693 expr.original_code = ERROR_MARK;
5696 /* Postincrement. */
5697 c_parser_consume_token (parser);
5698 expr = default_function_array_conversion (expr);
5699 expr.value = build_unary_op (loc,
5700 POSTINCREMENT_EXPR, expr.value, 0);
5701 expr.original_code = ERROR_MARK;
5703 case CPP_MINUS_MINUS:
5704 /* Postdecrement. */
5705 c_parser_consume_token (parser);
5706 expr = default_function_array_conversion (expr);
5707 expr.value = build_unary_op (loc,
5708 POSTDECREMENT_EXPR, expr.value, 0);
5709 expr.original_code = ERROR_MARK;
5717 /* Parse an expression (C90 6.3.17, C99 6.5.17).
5720 assignment-expression
5721 expression , assignment-expression
5724 static struct c_expr
5725 c_parser_expression (c_parser *parser)
5728 expr = c_parser_expr_no_commas (parser, NULL);
5729 while (c_parser_next_token_is (parser, CPP_COMMA))
5732 c_parser_consume_token (parser);
5733 next = c_parser_expr_no_commas (parser, NULL);
5734 next = default_function_array_conversion (next);
5735 expr.value = build_compound_expr (expr.value, next.value);
5736 expr.original_code = COMPOUND_EXPR;
5741 /* Parse an expression and convert functions or arrays to
5744 static struct c_expr
5745 c_parser_expression_conv (c_parser *parser)
5748 expr = c_parser_expression (parser);
5749 expr = default_function_array_conversion (expr);
5753 /* Parse a non-empty list of expressions. If CONVERT_P, convert
5754 functions and arrays to pointers. If FOLD_P, fold the expressions.
5757 assignment-expression
5758 nonempty-expr-list , assignment-expression
5762 c_parser_expr_list (c_parser *parser, bool convert_p, bool fold_p)
5766 expr = c_parser_expr_no_commas (parser, NULL);
5768 expr = default_function_array_conversion (expr);
5770 expr.value = c_fully_fold (expr.value, false, NULL);
5771 ret = cur = build_tree_list (NULL_TREE, expr.value);
5772 while (c_parser_next_token_is (parser, CPP_COMMA))
5774 c_parser_consume_token (parser);
5775 expr = c_parser_expr_no_commas (parser, NULL);
5777 expr = default_function_array_conversion (expr);
5779 expr.value = c_fully_fold (expr.value, false, NULL);
5780 cur = TREE_CHAIN (cur) = build_tree_list (NULL_TREE, expr.value);
5786 /* Parse Objective-C-specific constructs. */
5788 /* Parse an objc-class-definition.
5790 objc-class-definition:
5791 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
5792 objc-class-instance-variables[opt] objc-methodprotolist @end
5793 @implementation identifier objc-superclass[opt]
5794 objc-class-instance-variables[opt]
5795 @interface identifier ( identifier ) objc-protocol-refs[opt]
5796 objc-methodprotolist @end
5797 @implementation identifier ( identifier )
5802 "@interface identifier (" must start "@interface identifier (
5803 identifier ) ...": objc-methodprotolist in the first production may
5804 not start with a parenthesized identifier as a declarator of a data
5805 definition with no declaration specifiers if the objc-superclass,
5806 objc-protocol-refs and objc-class-instance-variables are omitted. */
5809 c_parser_objc_class_definition (c_parser *parser)
5814 if (c_parser_next_token_is_keyword (parser, RID_AT_INTERFACE))
5816 else if (c_parser_next_token_is_keyword (parser, RID_AT_IMPLEMENTATION))
5820 c_parser_consume_token (parser);
5821 if (c_parser_next_token_is_not (parser, CPP_NAME))
5823 c_parser_error (parser, "expected identifier");
5826 id1 = c_parser_peek_token (parser)->value;
5827 c_parser_consume_token (parser);
5828 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
5831 tree proto = NULL_TREE;
5832 c_parser_consume_token (parser);
5833 if (c_parser_next_token_is_not (parser, CPP_NAME))
5835 c_parser_error (parser, "expected identifier");
5836 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5839 id2 = c_parser_peek_token (parser)->value;
5840 c_parser_consume_token (parser);
5841 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5844 objc_start_category_implementation (id1, id2);
5847 if (c_parser_next_token_is (parser, CPP_LESS))
5848 proto = c_parser_objc_protocol_refs (parser);
5849 objc_start_category_interface (id1, id2, proto);
5850 c_parser_objc_methodprotolist (parser);
5851 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
5852 objc_finish_interface ();
5855 if (c_parser_next_token_is (parser, CPP_COLON))
5857 c_parser_consume_token (parser);
5858 if (c_parser_next_token_is_not (parser, CPP_NAME))
5860 c_parser_error (parser, "expected identifier");
5863 superclass = c_parser_peek_token (parser)->value;
5864 c_parser_consume_token (parser);
5867 superclass = NULL_TREE;
5870 tree proto = NULL_TREE;
5871 if (c_parser_next_token_is (parser, CPP_LESS))
5872 proto = c_parser_objc_protocol_refs (parser);
5873 objc_start_class_interface (id1, superclass, proto);
5876 objc_start_class_implementation (id1, superclass);
5877 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
5878 c_parser_objc_class_instance_variables (parser);
5881 objc_continue_interface ();
5882 c_parser_objc_methodprotolist (parser);
5883 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
5884 objc_finish_interface ();
5888 objc_continue_implementation ();
5893 /* Parse objc-class-instance-variables.
5895 objc-class-instance-variables:
5896 { objc-instance-variable-decl-list[opt] }
5898 objc-instance-variable-decl-list:
5899 objc-visibility-spec
5900 objc-instance-variable-decl ;
5902 objc-instance-variable-decl-list objc-visibility-spec
5903 objc-instance-variable-decl-list objc-instance-variable-decl ;
5904 objc-instance-variable-decl-list ;
5906 objc-visibility-spec:
5911 objc-instance-variable-decl:
5916 c_parser_objc_class_instance_variables (c_parser *parser)
5918 gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE));
5919 c_parser_consume_token (parser);
5920 while (c_parser_next_token_is_not (parser, CPP_EOF))
5923 /* Parse any stray semicolon. */
5924 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
5926 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
5927 "extra semicolon in struct or union specified");
5928 c_parser_consume_token (parser);
5931 /* Stop if at the end of the instance variables. */
5932 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
5934 c_parser_consume_token (parser);
5937 /* Parse any objc-visibility-spec. */
5938 if (c_parser_next_token_is_keyword (parser, RID_PRIVATE))
5940 c_parser_consume_token (parser);
5941 objc_set_visibility (2);
5944 else if (c_parser_next_token_is_keyword (parser, RID_PROTECTED))
5946 c_parser_consume_token (parser);
5947 objc_set_visibility (0);
5950 else if (c_parser_next_token_is_keyword (parser, RID_PUBLIC))
5952 c_parser_consume_token (parser);
5953 objc_set_visibility (1);
5956 else if (c_parser_next_token_is (parser, CPP_PRAGMA))
5958 c_parser_pragma (parser, pragma_external);
5962 /* Parse some comma-separated declarations. */
5963 decls = c_parser_struct_declaration (parser);
5965 /* Comma-separated instance variables are chained together in
5966 reverse order; add them one by one. */
5967 tree ivar = nreverse (decls);
5968 for (; ivar; ivar = TREE_CHAIN (ivar))
5969 objc_add_instance_variable (copy_node (ivar));
5971 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
5975 /* Parse an objc-class-declaration.
5977 objc-class-declaration:
5978 @class identifier-list ;
5982 c_parser_objc_class_declaration (c_parser *parser)
5984 tree list = NULL_TREE;
5985 gcc_assert (c_parser_next_token_is_keyword (parser, RID_CLASS));
5986 c_parser_consume_token (parser);
5987 /* Any identifiers, including those declared as type names, are OK
5992 if (c_parser_next_token_is_not (parser, CPP_NAME))
5994 c_parser_error (parser, "expected identifier");
5997 id = c_parser_peek_token (parser)->value;
5998 list = chainon (list, build_tree_list (NULL_TREE, id));
5999 c_parser_consume_token (parser);
6000 if (c_parser_next_token_is (parser, CPP_COMMA))
6001 c_parser_consume_token (parser);
6005 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
6006 objc_declare_class (list);
6009 /* Parse an objc-alias-declaration.
6011 objc-alias-declaration:
6012 @compatibility_alias identifier identifier ;
6016 c_parser_objc_alias_declaration (c_parser *parser)
6019 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_ALIAS));
6020 c_parser_consume_token (parser);
6021 if (c_parser_next_token_is_not (parser, CPP_NAME))
6023 c_parser_error (parser, "expected identifier");
6024 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
6027 id1 = c_parser_peek_token (parser)->value;
6028 c_parser_consume_token (parser);
6029 if (c_parser_next_token_is_not (parser, CPP_NAME))
6031 c_parser_error (parser, "expected identifier");
6032 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
6035 id2 = c_parser_peek_token (parser)->value;
6036 c_parser_consume_token (parser);
6037 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
6038 objc_declare_alias (id1, id2);
6041 /* Parse an objc-protocol-definition.
6043 objc-protocol-definition:
6044 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
6045 @protocol identifier-list ;
6047 "@protocol identifier ;" should be resolved as "@protocol
6048 identifier-list ;": objc-methodprotolist may not start with a
6049 semicolon in the first alternative if objc-protocol-refs are
6053 c_parser_objc_protocol_definition (c_parser *parser)
6055 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_PROTOCOL));
6056 c_parser_consume_token (parser);
6057 if (c_parser_next_token_is_not (parser, CPP_NAME))
6059 c_parser_error (parser, "expected identifier");
6062 if (c_parser_peek_2nd_token (parser)->type == CPP_COMMA
6063 || c_parser_peek_2nd_token (parser)->type == CPP_SEMICOLON)
6065 tree list = NULL_TREE;
6066 /* Any identifiers, including those declared as type names, are
6071 if (c_parser_next_token_is_not (parser, CPP_NAME))
6073 c_parser_error (parser, "expected identifier");
6076 id = c_parser_peek_token (parser)->value;
6077 list = chainon (list, build_tree_list (NULL_TREE, id));
6078 c_parser_consume_token (parser);
6079 if (c_parser_next_token_is (parser, CPP_COMMA))
6080 c_parser_consume_token (parser);
6084 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
6085 objc_declare_protocols (list);
6089 tree id = c_parser_peek_token (parser)->value;
6090 tree proto = NULL_TREE;
6091 c_parser_consume_token (parser);
6092 if (c_parser_next_token_is (parser, CPP_LESS))
6093 proto = c_parser_objc_protocol_refs (parser);
6094 parser->objc_pq_context = true;
6095 objc_start_protocol (id, proto);
6096 c_parser_objc_methodprotolist (parser);
6097 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
6098 parser->objc_pq_context = false;
6099 objc_finish_interface ();
6103 /* Parse an objc-method-type.
6110 static enum tree_code
6111 c_parser_objc_method_type (c_parser *parser)
6113 switch (c_parser_peek_token (parser)->type)
6116 c_parser_consume_token (parser);
6119 c_parser_consume_token (parser);
6126 /* Parse an objc-method-definition.
6128 objc-method-definition:
6129 objc-method-type objc-method-decl ;[opt] compound-statement
6133 c_parser_objc_method_definition (c_parser *parser)
6135 enum tree_code type = c_parser_objc_method_type (parser);
6137 objc_set_method_type (type);
6138 parser->objc_pq_context = true;
6139 decl = c_parser_objc_method_decl (parser);
6140 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
6142 c_parser_consume_token (parser);
6143 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
6144 "extra semicolon in method definition specified");
6146 if (!c_parser_next_token_is (parser, CPP_OPEN_BRACE))
6148 c_parser_error (parser, "expected %<{%>");
6151 parser->objc_pq_context = false;
6152 objc_start_method_definition (decl);
6153 add_stmt (c_parser_compound_statement (parser));
6154 objc_finish_method_definition (current_function_decl);
6157 /* Parse an objc-methodprotolist.
6159 objc-methodprotolist:
6161 objc-methodprotolist objc-methodproto
6162 objc-methodprotolist declaration
6163 objc-methodprotolist ;
6165 The declaration is a data definition, which may be missing
6166 declaration specifiers under the same rules and diagnostics as
6167 other data definitions outside functions, and the stray semicolon
6168 is diagnosed the same way as a stray semicolon outside a
6172 c_parser_objc_methodprotolist (c_parser *parser)
6176 /* The list is terminated by @end. */
6177 switch (c_parser_peek_token (parser)->type)
6180 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
6181 "ISO C does not allow extra %<;%> outside of a function");
6182 c_parser_consume_token (parser);
6186 c_parser_objc_methodproto (parser);
6189 c_parser_pragma (parser, pragma_external);
6194 if (c_parser_next_token_is_keyword (parser, RID_AT_END))
6196 c_parser_declaration_or_fndef (parser, false, true, false, true);
6202 /* Parse an objc-methodproto.
6205 objc-method-type objc-method-decl ;
6209 c_parser_objc_methodproto (c_parser *parser)
6211 enum tree_code type = c_parser_objc_method_type (parser);
6213 objc_set_method_type (type);
6214 /* Remember protocol qualifiers in prototypes. */
6215 parser->objc_pq_context = true;
6216 decl = c_parser_objc_method_decl (parser);
6217 /* Forget protocol qualifiers here. */
6218 parser->objc_pq_context = false;
6219 objc_add_method_declaration (decl);
6220 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
6223 /* Parse an objc-method-decl.
6226 ( objc-type-name ) objc-selector
6228 ( objc-type-name ) objc-keyword-selector objc-optparmlist
6229 objc-keyword-selector objc-optparmlist
6231 objc-keyword-selector:
6233 objc-keyword-selector objc-keyword-decl
6236 objc-selector : ( objc-type-name ) identifier
6237 objc-selector : identifier
6238 : ( objc-type-name ) identifier
6242 objc-optparms objc-optellipsis
6246 objc-opt-parms , parameter-declaration
6254 c_parser_objc_method_decl (c_parser *parser)
6256 tree type = NULL_TREE;
6258 tree parms = NULL_TREE;
6259 bool ellipsis = false;
6261 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
6263 c_parser_consume_token (parser);
6264 type = c_parser_objc_type_name (parser);
6265 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6267 sel = c_parser_objc_selector (parser);
6268 /* If there is no selector, or a colon follows, we have an
6269 objc-keyword-selector. If there is a selector, and a colon does
6270 not follow, that selector ends the objc-method-decl. */
6271 if (!sel || c_parser_next_token_is (parser, CPP_COLON))
6274 tree list = NULL_TREE;
6277 tree atype = NULL_TREE, id, keyworddecl;
6278 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
6280 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
6282 c_parser_consume_token (parser);
6283 atype = c_parser_objc_type_name (parser);
6284 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6287 if (c_parser_next_token_is_not (parser, CPP_NAME))
6289 c_parser_error (parser, "expected identifier");
6290 return error_mark_node;
6292 id = c_parser_peek_token (parser)->value;
6293 c_parser_consume_token (parser);
6294 keyworddecl = objc_build_keyword_decl (tsel, atype, id);
6295 list = chainon (list, keyworddecl);
6296 tsel = c_parser_objc_selector (parser);
6297 if (!tsel && c_parser_next_token_is_not (parser, CPP_COLON))
6300 /* Parse the optional parameter list. Optional Objective-C
6301 method parameters follow the C syntax, and may include '...'
6302 to denote a variable number of arguments. */
6303 parms = make_node (TREE_LIST);
6304 while (c_parser_next_token_is (parser, CPP_COMMA))
6306 struct c_parm *parm;
6307 c_parser_consume_token (parser);
6308 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
6311 c_parser_consume_token (parser);
6314 parm = c_parser_parameter_declaration (parser, NULL_TREE);
6317 parms = chainon (parms,
6318 build_tree_list (NULL_TREE, grokparm (parm)));
6322 return objc_build_method_signature (type, sel, parms, ellipsis);
6325 /* Parse an objc-type-name.
6328 objc-type-qualifiers[opt] type-name
6329 objc-type-qualifiers[opt]
6331 objc-type-qualifiers:
6333 objc-type-qualifiers objc-type-qualifier
6335 objc-type-qualifier: one of
6336 in out inout bycopy byref oneway
6340 c_parser_objc_type_name (c_parser *parser)
6342 tree quals = NULL_TREE;
6343 struct c_type_name *type_name = NULL;
6344 tree type = NULL_TREE;
6347 c_token *token = c_parser_peek_token (parser);
6348 if (token->type == CPP_KEYWORD
6349 && (token->keyword == RID_IN
6350 || token->keyword == RID_OUT
6351 || token->keyword == RID_INOUT
6352 || token->keyword == RID_BYCOPY
6353 || token->keyword == RID_BYREF
6354 || token->keyword == RID_ONEWAY))
6356 quals = chainon (quals, build_tree_list (NULL_TREE, token->value));
6357 c_parser_consume_token (parser);
6362 if (c_parser_next_token_starts_typename (parser))
6363 type_name = c_parser_type_name (parser);
6365 type = groktypename (type_name, NULL, NULL);
6366 return build_tree_list (quals, type);
6369 /* Parse objc-protocol-refs.
6376 c_parser_objc_protocol_refs (c_parser *parser)
6378 tree list = NULL_TREE;
6379 gcc_assert (c_parser_next_token_is (parser, CPP_LESS));
6380 c_parser_consume_token (parser);
6381 /* Any identifiers, including those declared as type names, are OK
6386 if (c_parser_next_token_is_not (parser, CPP_NAME))
6388 c_parser_error (parser, "expected identifier");
6391 id = c_parser_peek_token (parser)->value;
6392 list = chainon (list, build_tree_list (NULL_TREE, id));
6393 c_parser_consume_token (parser);
6394 if (c_parser_next_token_is (parser, CPP_COMMA))
6395 c_parser_consume_token (parser);
6399 c_parser_require (parser, CPP_GREATER, "expected %<>%>");
6403 /* Parse an objc-try-catch-statement.
6405 objc-try-catch-statement:
6406 @try compound-statement objc-catch-list[opt]
6407 @try compound-statement objc-catch-list[opt] @finally compound-statement
6410 @catch ( parameter-declaration ) compound-statement
6411 objc-catch-list @catch ( parameter-declaration ) compound-statement
6415 c_parser_objc_try_catch_statement (c_parser *parser)
6419 gcc_assert (c_parser_next_token_is_keyword (parser, RID_TRY));
6420 c_parser_consume_token (parser);
6421 loc = c_parser_peek_token (parser)->location;
6422 stmt = c_parser_compound_statement (parser);
6423 objc_begin_try_stmt (loc, stmt);
6424 while (c_parser_next_token_is_keyword (parser, RID_CATCH))
6426 struct c_parm *parm;
6427 c_parser_consume_token (parser);
6428 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6430 parm = c_parser_parameter_declaration (parser, NULL_TREE);
6433 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6436 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6437 objc_begin_catch_clause (grokparm (parm));
6438 if (c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
6439 c_parser_compound_statement_nostart (parser);
6440 objc_finish_catch_clause ();
6442 if (c_parser_next_token_is_keyword (parser, RID_AT_FINALLY))
6446 c_parser_consume_token (parser);
6447 finloc = c_parser_peek_token (parser)->location;
6448 finstmt = c_parser_compound_statement (parser);
6449 objc_build_finally_clause (finloc, finstmt);
6451 objc_finish_try_stmt ();
6454 /* Parse an objc-synchronized-statement.
6456 objc-synchronized-statement:
6457 @synchronized ( expression ) compound-statement
6461 c_parser_objc_synchronized_statement (c_parser *parser)
6465 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_SYNCHRONIZED));
6466 c_parser_consume_token (parser);
6467 loc = c_parser_peek_token (parser)->location;
6468 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6470 expr = c_parser_expression (parser).value;
6471 expr = c_fully_fold (expr, false, NULL);
6472 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6475 expr = error_mark_node;
6476 stmt = c_parser_compound_statement (parser);
6477 objc_build_synchronized (loc, expr, stmt);
6480 /* Parse an objc-selector; return NULL_TREE without an error if the
6481 next token is not an objc-selector.
6486 enum struct union if else while do for switch case default
6487 break continue return goto asm sizeof typeof __alignof
6488 unsigned long const short volatile signed restrict _Complex
6489 in out inout bycopy byref oneway int char float double void _Bool
6491 ??? Why this selection of keywords but not, for example, storage
6492 class specifiers? */
6495 c_parser_objc_selector (c_parser *parser)
6497 c_token *token = c_parser_peek_token (parser);
6498 tree value = token->value;
6499 if (token->type == CPP_NAME)
6501 c_parser_consume_token (parser);
6504 if (token->type != CPP_KEYWORD)
6506 switch (token->keyword)
6547 c_parser_consume_token (parser);
6554 /* Parse an objc-selector-arg.
6558 objc-keywordname-list
6560 objc-keywordname-list:
6562 objc-keywordname-list objc-keywordname
6570 c_parser_objc_selector_arg (c_parser *parser)
6572 tree sel = c_parser_objc_selector (parser);
6573 tree list = NULL_TREE;
6574 if (sel && c_parser_next_token_is_not (parser, CPP_COLON))
6578 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
6580 list = chainon (list, build_tree_list (sel, NULL_TREE));
6581 sel = c_parser_objc_selector (parser);
6582 if (!sel && c_parser_next_token_is_not (parser, CPP_COLON))
6588 /* Parse an objc-receiver.
6597 c_parser_objc_receiver (c_parser *parser)
6599 if (c_parser_peek_token (parser)->type == CPP_NAME
6600 && (c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME
6601 || c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME))
6603 tree id = c_parser_peek_token (parser)->value;
6604 c_parser_consume_token (parser);
6605 return objc_get_class_reference (id);
6607 return c_fully_fold (c_parser_expression (parser).value, false, NULL);
6610 /* Parse objc-message-args.
6614 objc-keywordarg-list
6616 objc-keywordarg-list:
6618 objc-keywordarg-list objc-keywordarg
6621 objc-selector : objc-keywordexpr
6626 c_parser_objc_message_args (c_parser *parser)
6628 tree sel = c_parser_objc_selector (parser);
6629 tree list = NULL_TREE;
6630 if (sel && c_parser_next_token_is_not (parser, CPP_COLON))
6635 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
6637 keywordexpr = c_parser_objc_keywordexpr (parser);
6638 list = chainon (list, build_tree_list (sel, keywordexpr));
6639 sel = c_parser_objc_selector (parser);
6640 if (!sel && c_parser_next_token_is_not (parser, CPP_COLON))
6646 /* Parse an objc-keywordexpr.
6653 c_parser_objc_keywordexpr (c_parser *parser)
6655 tree list = c_parser_expr_list (parser, true, true);
6656 if (TREE_CHAIN (list) == NULL_TREE)
6658 /* Just return the expression, remove a level of
6660 return TREE_VALUE (list);
6664 /* We have a comma expression, we will collapse later. */
6670 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
6671 should be considered, statements. ALLOW_STMT is true if we're within
6672 the context of a function and such pragmas are to be allowed. Returns
6673 true if we actually parsed such a pragma. */
6676 c_parser_pragma (c_parser *parser, enum pragma_context context)
6680 id = c_parser_peek_token (parser)->pragma_kind;
6681 gcc_assert (id != PRAGMA_NONE);
6685 case PRAGMA_OMP_BARRIER:
6686 if (context != pragma_compound)
6688 if (context == pragma_stmt)
6689 c_parser_error (parser, "%<#pragma omp barrier%> may only be "
6690 "used in compound statements");
6693 c_parser_omp_barrier (parser);
6696 case PRAGMA_OMP_FLUSH:
6697 if (context != pragma_compound)
6699 if (context == pragma_stmt)
6700 c_parser_error (parser, "%<#pragma omp flush%> may only be "
6701 "used in compound statements");
6704 c_parser_omp_flush (parser);
6707 case PRAGMA_OMP_TASKWAIT:
6708 if (context != pragma_compound)
6710 if (context == pragma_stmt)
6711 c_parser_error (parser, "%<#pragma omp taskwait%> may only be "
6712 "used in compound statements");
6715 c_parser_omp_taskwait (parser);
6718 case PRAGMA_OMP_THREADPRIVATE:
6719 c_parser_omp_threadprivate (parser);
6722 case PRAGMA_OMP_SECTION:
6723 error_at (c_parser_peek_token (parser)->location,
6724 "%<#pragma omp section%> may only be used in "
6725 "%<#pragma omp sections%> construct");
6726 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
6729 case PRAGMA_GCC_PCH_PREPROCESS:
6730 c_parser_error (parser, "%<#pragma GCC pch_preprocess%> must be first");
6731 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
6735 if (id < PRAGMA_FIRST_EXTERNAL)
6737 if (context == pragma_external)
6740 c_parser_error (parser, "expected declaration specifiers");
6741 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
6744 c_parser_omp_construct (parser);
6750 c_parser_consume_pragma (parser);
6751 c_invoke_pragma_handler (id);
6753 /* Skip to EOL, but suppress any error message. Those will have been
6754 generated by the handler routine through calling error, as opposed
6755 to calling c_parser_error. */
6756 parser->error = true;
6757 c_parser_skip_to_pragma_eol (parser);
6762 /* The interface the pragma parsers have to the lexer. */
6765 pragma_lex (tree *value)
6767 c_token *tok = c_parser_peek_token (the_parser);
6768 enum cpp_ttype ret = tok->type;
6770 *value = tok->value;
6771 if (ret == CPP_PRAGMA_EOL || ret == CPP_EOF)
6775 if (ret == CPP_KEYWORD)
6777 c_parser_consume_token (the_parser);
6784 c_parser_pragma_pch_preprocess (c_parser *parser)
6788 c_parser_consume_pragma (parser);
6789 if (c_parser_next_token_is (parser, CPP_STRING))
6791 name = c_parser_peek_token (parser)->value;
6792 c_parser_consume_token (parser);
6795 c_parser_error (parser, "expected string literal");
6796 c_parser_skip_to_pragma_eol (parser);
6799 c_common_pch_pragma (parse_in, TREE_STRING_POINTER (name));
6802 /* OpenMP 2.5 parsing routines. */
6804 /* Returns name of the next clause.
6805 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
6806 the token is not consumed. Otherwise appropriate pragma_omp_clause is
6807 returned and the token is consumed. */
6809 static pragma_omp_clause
6810 c_parser_omp_clause_name (c_parser *parser)
6812 pragma_omp_clause result = PRAGMA_OMP_CLAUSE_NONE;
6814 if (c_parser_next_token_is_keyword (parser, RID_IF))
6815 result = PRAGMA_OMP_CLAUSE_IF;
6816 else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT))
6817 result = PRAGMA_OMP_CLAUSE_DEFAULT;
6818 else if (c_parser_next_token_is (parser, CPP_NAME))
6820 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
6825 if (!strcmp ("collapse", p))
6826 result = PRAGMA_OMP_CLAUSE_COLLAPSE;
6827 else if (!strcmp ("copyin", p))
6828 result = PRAGMA_OMP_CLAUSE_COPYIN;
6829 else if (!strcmp ("copyprivate", p))
6830 result = PRAGMA_OMP_CLAUSE_COPYPRIVATE;
6833 if (!strcmp ("firstprivate", p))
6834 result = PRAGMA_OMP_CLAUSE_FIRSTPRIVATE;
6837 if (!strcmp ("lastprivate", p))
6838 result = PRAGMA_OMP_CLAUSE_LASTPRIVATE;
6841 if (!strcmp ("nowait", p))
6842 result = PRAGMA_OMP_CLAUSE_NOWAIT;
6843 else if (!strcmp ("num_threads", p))
6844 result = PRAGMA_OMP_CLAUSE_NUM_THREADS;
6847 if (!strcmp ("ordered", p))
6848 result = PRAGMA_OMP_CLAUSE_ORDERED;
6851 if (!strcmp ("private", p))
6852 result = PRAGMA_OMP_CLAUSE_PRIVATE;
6855 if (!strcmp ("reduction", p))
6856 result = PRAGMA_OMP_CLAUSE_REDUCTION;
6859 if (!strcmp ("schedule", p))
6860 result = PRAGMA_OMP_CLAUSE_SCHEDULE;
6861 else if (!strcmp ("shared", p))
6862 result = PRAGMA_OMP_CLAUSE_SHARED;
6865 if (!strcmp ("untied", p))
6866 result = PRAGMA_OMP_CLAUSE_UNTIED;
6871 if (result != PRAGMA_OMP_CLAUSE_NONE)
6872 c_parser_consume_token (parser);
6877 /* Validate that a clause of the given type does not already exist. */
6880 check_no_duplicate_clause (tree clauses, enum omp_clause_code code,
6885 for (c = clauses; c ; c = OMP_CLAUSE_CHAIN (c))
6886 if (OMP_CLAUSE_CODE (c) == code)
6888 error ("too many %qs clauses", name);
6896 variable-list , identifier
6898 If KIND is nonzero, create the appropriate node and install the decl
6899 in OMP_CLAUSE_DECL and add the node to the head of the list.
6901 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
6902 return the list created. */
6905 c_parser_omp_variable_list (c_parser *parser, enum omp_clause_code kind,
6908 if (c_parser_next_token_is_not (parser, CPP_NAME)
6909 || c_parser_peek_token (parser)->id_kind != C_ID_ID)
6910 c_parser_error (parser, "expected identifier");
6912 while (c_parser_next_token_is (parser, CPP_NAME)
6913 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
6915 tree t = lookup_name (c_parser_peek_token (parser)->value);
6918 undeclared_variable (c_parser_peek_token (parser)->value,
6919 c_parser_peek_token (parser)->location);
6920 else if (t == error_mark_node)
6924 tree u = build_omp_clause (kind);
6925 OMP_CLAUSE_DECL (u) = t;
6926 OMP_CLAUSE_CHAIN (u) = list;
6930 list = tree_cons (t, NULL_TREE, list);
6932 c_parser_consume_token (parser);
6934 if (c_parser_next_token_is_not (parser, CPP_COMMA))
6937 c_parser_consume_token (parser);
6943 /* Similarly, but expect leading and trailing parenthesis. This is a very
6944 common case for omp clauses. */
6947 c_parser_omp_var_list_parens (c_parser *parser, enum omp_clause_code kind,
6950 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6952 list = c_parser_omp_variable_list (parser, kind, list);
6953 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6959 collapse ( constant-expression ) */
6962 c_parser_omp_clause_collapse (c_parser *parser, tree list)
6964 tree c, num = error_mark_node;
6968 check_no_duplicate_clause (list, OMP_CLAUSE_COLLAPSE, "collapse");
6970 loc = c_parser_peek_token (parser)->location;
6971 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6973 num = c_parser_expr_no_commas (parser, NULL).value;
6974 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6976 if (num == error_mark_node)
6978 if (!INTEGRAL_TYPE_P (TREE_TYPE (num))
6979 || !host_integerp (num, 0)
6980 || (n = tree_low_cst (num, 0)) <= 0
6984 "collapse argument needs positive constant integer expression");
6987 c = build_omp_clause (OMP_CLAUSE_COLLAPSE);
6988 OMP_CLAUSE_COLLAPSE_EXPR (c) = num;
6989 OMP_CLAUSE_CHAIN (c) = list;
6994 copyin ( variable-list ) */
6997 c_parser_omp_clause_copyin (c_parser *parser, tree list)
6999 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYIN, list);
7003 copyprivate ( variable-list ) */
7006 c_parser_omp_clause_copyprivate (c_parser *parser, tree list)
7008 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYPRIVATE, list);
7012 default ( shared | none ) */
7015 c_parser_omp_clause_default (c_parser *parser, tree list)
7017 enum omp_clause_default_kind kind = OMP_CLAUSE_DEFAULT_UNSPECIFIED;
7020 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7022 if (c_parser_next_token_is (parser, CPP_NAME))
7024 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
7029 if (strcmp ("none", p) != 0)
7031 kind = OMP_CLAUSE_DEFAULT_NONE;
7035 if (strcmp ("shared", p) != 0)
7037 kind = OMP_CLAUSE_DEFAULT_SHARED;
7044 c_parser_consume_token (parser);
7049 c_parser_error (parser, "expected %<none%> or %<shared%>");
7051 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7053 if (kind == OMP_CLAUSE_DEFAULT_UNSPECIFIED)
7056 check_no_duplicate_clause (list, OMP_CLAUSE_DEFAULT, "default");
7057 c = build_omp_clause (OMP_CLAUSE_DEFAULT);
7058 OMP_CLAUSE_CHAIN (c) = list;
7059 OMP_CLAUSE_DEFAULT_KIND (c) = kind;
7065 firstprivate ( variable-list ) */
7068 c_parser_omp_clause_firstprivate (c_parser *parser, tree list)
7070 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_FIRSTPRIVATE, list);
7074 if ( expression ) */
7077 c_parser_omp_clause_if (c_parser *parser, tree list)
7079 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
7081 tree t = c_parser_paren_condition (parser);
7084 check_no_duplicate_clause (list, OMP_CLAUSE_IF, "if");
7086 c = build_omp_clause (OMP_CLAUSE_IF);
7087 OMP_CLAUSE_IF_EXPR (c) = t;
7088 OMP_CLAUSE_CHAIN (c) = list;
7092 c_parser_error (parser, "expected %<(%>");
7098 lastprivate ( variable-list ) */
7101 c_parser_omp_clause_lastprivate (c_parser *parser, tree list)
7103 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_LASTPRIVATE, list);
7110 c_parser_omp_clause_nowait (c_parser *parser ATTRIBUTE_UNUSED, tree list)
7114 check_no_duplicate_clause (list, OMP_CLAUSE_NOWAIT, "nowait");
7116 c = build_omp_clause (OMP_CLAUSE_NOWAIT);
7117 OMP_CLAUSE_CHAIN (c) = list;
7122 num_threads ( expression ) */
7125 c_parser_omp_clause_num_threads (c_parser *parser, tree list)
7127 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7129 location_t expr_loc = c_parser_peek_token (parser)->location;
7130 tree c, t = c_parser_expression (parser).value;
7131 t = c_fully_fold (t, false, NULL);
7133 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7135 if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
7137 c_parser_error (parser, "expected integer expression");
7141 /* Attempt to statically determine when the number isn't positive. */
7142 c = fold_build2 (LE_EXPR, boolean_type_node, t,
7143 build_int_cst (TREE_TYPE (t), 0));
7144 if (c == boolean_true_node)
7146 warning_at (expr_loc, 0,
7147 "%<num_threads%> value must be positive");
7148 t = integer_one_node;
7151 check_no_duplicate_clause (list, OMP_CLAUSE_NUM_THREADS, "num_threads");
7153 c = build_omp_clause (OMP_CLAUSE_NUM_THREADS);
7154 OMP_CLAUSE_NUM_THREADS_EXPR (c) = t;
7155 OMP_CLAUSE_CHAIN (c) = list;
7166 c_parser_omp_clause_ordered (c_parser *parser ATTRIBUTE_UNUSED, tree list)
7170 check_no_duplicate_clause (list, OMP_CLAUSE_ORDERED, "ordered");
7172 c = build_omp_clause (OMP_CLAUSE_ORDERED);
7173 OMP_CLAUSE_CHAIN (c) = list;
7178 private ( variable-list ) */
7181 c_parser_omp_clause_private (c_parser *parser, tree list)
7183 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_PRIVATE, list);
7187 reduction ( reduction-operator : variable-list )
7190 One of: + * - & ^ | && || */
7193 c_parser_omp_clause_reduction (c_parser *parser, tree list)
7195 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7197 enum tree_code code;
7199 switch (c_parser_peek_token (parser)->type)
7211 code = BIT_AND_EXPR;
7214 code = BIT_XOR_EXPR;
7217 code = BIT_IOR_EXPR;
7220 code = TRUTH_ANDIF_EXPR;
7223 code = TRUTH_ORIF_EXPR;
7226 c_parser_error (parser,
7227 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
7228 "%<^%>, %<|%>, %<&&%>, or %<||%>");
7229 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0);
7232 c_parser_consume_token (parser);
7233 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
7237 nl = c_parser_omp_variable_list (parser, OMP_CLAUSE_REDUCTION, list);
7238 for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
7239 OMP_CLAUSE_REDUCTION_CODE (c) = code;
7243 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7249 schedule ( schedule-kind )
7250 schedule ( schedule-kind , expression )
7253 static | dynamic | guided | runtime | auto
7257 c_parser_omp_clause_schedule (c_parser *parser, tree list)
7261 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7264 c = build_omp_clause (OMP_CLAUSE_SCHEDULE);
7266 if (c_parser_next_token_is (parser, CPP_NAME))
7268 tree kind = c_parser_peek_token (parser)->value;
7269 const char *p = IDENTIFIER_POINTER (kind);
7274 if (strcmp ("dynamic", p) != 0)
7276 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_DYNAMIC;
7280 if (strcmp ("guided", p) != 0)
7282 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_GUIDED;
7286 if (strcmp ("runtime", p) != 0)
7288 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_RUNTIME;
7295 else if (c_parser_next_token_is_keyword (parser, RID_STATIC))
7296 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_STATIC;
7297 else if (c_parser_next_token_is_keyword (parser, RID_AUTO))
7298 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_AUTO;
7302 c_parser_consume_token (parser);
7303 if (c_parser_next_token_is (parser, CPP_COMMA))
7306 c_parser_consume_token (parser);
7308 here = c_parser_peek_token (parser)->location;
7309 t = c_parser_expr_no_commas (parser, NULL).value;
7310 t = c_fully_fold (t, false, NULL);
7312 if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_RUNTIME)
7313 error_at (here, "schedule %<runtime%> does not take "
7314 "a %<chunk_size%> parameter");
7315 else if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_AUTO)
7317 "schedule %<auto%> does not take "
7318 "a %<chunk_size%> parameter");
7319 else if (TREE_CODE (TREE_TYPE (t)) == INTEGER_TYPE)
7320 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c) = t;
7322 c_parser_error (parser, "expected integer expression");
7324 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7327 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7328 "expected %<,%> or %<)%>");
7330 check_no_duplicate_clause (list, OMP_CLAUSE_SCHEDULE, "schedule");
7331 OMP_CLAUSE_CHAIN (c) = list;
7335 c_parser_error (parser, "invalid schedule kind");
7336 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0);
7341 shared ( variable-list ) */
7344 c_parser_omp_clause_shared (c_parser *parser, tree list)
7346 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_SHARED, list);
7353 c_parser_omp_clause_untied (c_parser *parser ATTRIBUTE_UNUSED, tree list)
7357 /* FIXME: Should we allow duplicates? */
7358 check_no_duplicate_clause (list, OMP_CLAUSE_UNTIED, "untied");
7360 c = build_omp_clause (OMP_CLAUSE_UNTIED);
7361 OMP_CLAUSE_CHAIN (c) = list;
7365 /* Parse all OpenMP clauses. The set clauses allowed by the directive
7366 is a bitmask in MASK. Return the list of clauses found; the result
7367 of clause default goes in *pdefault. */
7370 c_parser_omp_all_clauses (c_parser *parser, unsigned int mask,
7373 tree clauses = NULL;
7376 while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
7379 pragma_omp_clause c_kind;
7381 tree prev = clauses;
7383 if (!first && c_parser_next_token_is (parser, CPP_COMMA))
7384 c_parser_consume_token (parser);
7387 here = c_parser_peek_token (parser)->location;
7388 c_kind = c_parser_omp_clause_name (parser);
7392 case PRAGMA_OMP_CLAUSE_COLLAPSE:
7393 clauses = c_parser_omp_clause_collapse (parser, clauses);
7394 c_name = "collapse";
7396 case PRAGMA_OMP_CLAUSE_COPYIN:
7397 clauses = c_parser_omp_clause_copyin (parser, clauses);
7400 case PRAGMA_OMP_CLAUSE_COPYPRIVATE:
7401 clauses = c_parser_omp_clause_copyprivate (parser, clauses);
7402 c_name = "copyprivate";
7404 case PRAGMA_OMP_CLAUSE_DEFAULT:
7405 clauses = c_parser_omp_clause_default (parser, clauses);
7408 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE:
7409 clauses = c_parser_omp_clause_firstprivate (parser, clauses);
7410 c_name = "firstprivate";
7412 case PRAGMA_OMP_CLAUSE_IF:
7413 clauses = c_parser_omp_clause_if (parser, clauses);
7416 case PRAGMA_OMP_CLAUSE_LASTPRIVATE:
7417 clauses = c_parser_omp_clause_lastprivate (parser, clauses);
7418 c_name = "lastprivate";
7420 case PRAGMA_OMP_CLAUSE_NOWAIT:
7421 clauses = c_parser_omp_clause_nowait (parser, clauses);
7424 case PRAGMA_OMP_CLAUSE_NUM_THREADS:
7425 clauses = c_parser_omp_clause_num_threads (parser, clauses);
7426 c_name = "num_threads";
7428 case PRAGMA_OMP_CLAUSE_ORDERED:
7429 clauses = c_parser_omp_clause_ordered (parser, clauses);
7432 case PRAGMA_OMP_CLAUSE_PRIVATE:
7433 clauses = c_parser_omp_clause_private (parser, clauses);
7436 case PRAGMA_OMP_CLAUSE_REDUCTION:
7437 clauses = c_parser_omp_clause_reduction (parser, clauses);
7438 c_name = "reduction";
7440 case PRAGMA_OMP_CLAUSE_SCHEDULE:
7441 clauses = c_parser_omp_clause_schedule (parser, clauses);
7442 c_name = "schedule";
7444 case PRAGMA_OMP_CLAUSE_SHARED:
7445 clauses = c_parser_omp_clause_shared (parser, clauses);
7448 case PRAGMA_OMP_CLAUSE_UNTIED:
7449 clauses = c_parser_omp_clause_untied (parser, clauses);
7453 c_parser_error (parser, "expected %<#pragma omp%> clause");
7457 if (((mask >> c_kind) & 1) == 0 && !parser->error)
7459 /* Remove the invalid clause(s) from the list to avoid
7460 confusing the rest of the compiler. */
7462 error_at (here, "%qs is not valid for %qs", c_name, where);
7467 c_parser_skip_to_pragma_eol (parser);
7469 return c_finish_omp_clauses (clauses);
7476 In practice, we're also interested in adding the statement to an
7477 outer node. So it is convenient if we work around the fact that
7478 c_parser_statement calls add_stmt. */
7481 c_parser_omp_structured_block (c_parser *parser)
7483 tree stmt = push_stmt_list ();
7484 c_parser_statement (parser);
7485 return pop_stmt_list (stmt);
7489 # pragma omp atomic new-line
7493 x binop= expr | x++ | ++x | x-- | --x
7495 +, *, -, /, &, ^, |, <<, >>
7497 where x is an lvalue expression with scalar type. */
7500 c_parser_omp_atomic (c_parser *parser)
7504 enum tree_code code;
7505 struct c_expr rhs_expr;
7507 c_parser_skip_to_pragma_eol (parser);
7509 lhs = c_parser_unary_expression (parser).value;
7510 lhs = c_fully_fold (lhs, false, NULL);
7511 switch (TREE_CODE (lhs))
7515 c_parser_skip_to_end_of_block_or_statement (parser);
7518 case PREINCREMENT_EXPR:
7519 case POSTINCREMENT_EXPR:
7520 lhs = TREE_OPERAND (lhs, 0);
7522 rhs = integer_one_node;
7525 case PREDECREMENT_EXPR:
7526 case POSTDECREMENT_EXPR:
7527 lhs = TREE_OPERAND (lhs, 0);
7529 rhs = integer_one_node;
7533 switch (c_parser_peek_token (parser)->type)
7539 code = TRUNC_DIV_EXPR;
7554 code = BIT_AND_EXPR;
7557 code = BIT_IOR_EXPR;
7560 code = BIT_XOR_EXPR;
7563 c_parser_error (parser,
7564 "invalid operator for %<#pragma omp atomic%>");
7568 c_parser_consume_token (parser);
7569 rhs_expr = c_parser_expression (parser);
7570 rhs_expr = default_function_array_conversion (rhs_expr);
7571 rhs = rhs_expr.value;
7572 rhs = c_fully_fold (rhs, false, NULL);
7575 stmt = c_finish_omp_atomic (code, lhs, rhs);
7576 if (stmt != error_mark_node)
7578 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7583 # pragma omp barrier new-line
7587 c_parser_omp_barrier (c_parser *parser)
7589 c_parser_consume_pragma (parser);
7590 c_parser_skip_to_pragma_eol (parser);
7592 c_finish_omp_barrier ();
7596 # pragma omp critical [(name)] new-line
7601 c_parser_omp_critical (c_parser *parser)
7603 tree stmt, name = NULL;
7605 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
7607 c_parser_consume_token (parser);
7608 if (c_parser_next_token_is (parser, CPP_NAME))
7610 name = c_parser_peek_token (parser)->value;
7611 c_parser_consume_token (parser);
7612 c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7615 c_parser_error (parser, "expected identifier");
7617 else if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
7618 c_parser_error (parser, "expected %<(%> or end of line");
7619 c_parser_skip_to_pragma_eol (parser);
7621 stmt = c_parser_omp_structured_block (parser);
7622 return c_finish_omp_critical (stmt, name);
7626 # pragma omp flush flush-vars[opt] new-line
7629 ( variable-list ) */
7632 c_parser_omp_flush (c_parser *parser)
7634 c_parser_consume_pragma (parser);
7635 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
7636 c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL);
7637 else if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
7638 c_parser_error (parser, "expected %<(%> or end of line");
7639 c_parser_skip_to_pragma_eol (parser);
7641 c_finish_omp_flush ();
7644 /* Parse the restricted form of the for statement allowed by OpenMP.
7645 The real trick here is to determine the loop control variable early
7646 so that we can push a new decl if necessary to make it private. */
7649 c_parser_omp_for_loop (c_parser *parser, tree clauses, tree *par_clauses)
7651 tree decl, cond, incr, save_break, save_cont, body, init, stmt, cl;
7652 tree declv, condv, incrv, initv, for_block = NULL, ret = NULL;
7654 bool fail = false, open_brace_parsed = false;
7655 int i, collapse = 1, nbraces = 0;
7657 for (cl = clauses; cl; cl = OMP_CLAUSE_CHAIN (cl))
7658 if (OMP_CLAUSE_CODE (cl) == OMP_CLAUSE_COLLAPSE)
7659 collapse = tree_low_cst (OMP_CLAUSE_COLLAPSE_EXPR (cl), 0);
7661 gcc_assert (collapse >= 1);
7663 declv = make_tree_vec (collapse);
7664 initv = make_tree_vec (collapse);
7665 condv = make_tree_vec (collapse);
7666 incrv = make_tree_vec (collapse);
7668 if (!c_parser_next_token_is_keyword (parser, RID_FOR))
7670 c_parser_error (parser, "for statement expected");
7673 loc = c_parser_peek_token (parser)->location;
7674 c_parser_consume_token (parser);
7676 for (i = 0; i < collapse; i++)
7680 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7683 /* Parse the initialization declaration or expression. */
7684 if (c_parser_next_token_starts_declspecs (parser))
7688 = tree_cons (NULL, c_begin_compound_stmt (true), for_block);
7689 c_parser_declaration_or_fndef (parser, true, true, true, true);
7690 decl = check_for_loop_decls ();
7693 if (DECL_INITIAL (decl) == error_mark_node)
7694 decl = error_mark_node;
7697 else if (c_parser_next_token_is (parser, CPP_NAME)
7698 && c_parser_peek_2nd_token (parser)->type == CPP_EQ)
7700 struct c_expr init_exp;
7701 location_t init_loc;
7703 decl = c_parser_postfix_expression (parser).value;
7705 c_parser_require (parser, CPP_EQ, "expected %<=%>");
7706 init_loc = c_parser_peek_token (parser)->location;
7708 init_exp = c_parser_expr_no_commas (parser, NULL);
7709 init_exp = default_function_array_conversion (init_exp);
7710 init = build_modify_expr (init_loc,
7711 decl, NOP_EXPR, init_exp.value);
7712 init = c_process_expr_stmt (init);
7714 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7719 c_parser_error (parser,
7720 "expected iteration declaration or initialization");
7721 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7727 /* Parse the loop condition. */
7729 if (c_parser_next_token_is_not (parser, CPP_SEMICOLON))
7731 location_t cond_loc = c_parser_peek_token (parser)->location;
7732 struct c_expr cond_expr = c_parser_binary_expression (parser, NULL);
7734 cond = cond_expr.value;
7735 cond = c_objc_common_truthvalue_conversion (cond_loc, cond);
7736 cond = c_fully_fold (cond, false, NULL);
7737 switch (cond_expr.original_code)
7745 /* Can't be cond = error_mark_node, because we want to preserve
7746 the location until c_finish_omp_for. */
7747 cond = build1 (NOP_EXPR, boolean_type_node, error_mark_node);
7750 protected_set_expr_location (cond, cond_loc);
7752 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7754 /* Parse the increment expression. */
7756 if (c_parser_next_token_is_not (parser, CPP_CLOSE_PAREN))
7758 location_t incr_loc = c_parser_peek_token (parser)->location;
7760 incr = c_process_expr_stmt (c_parser_expression (parser).value);
7761 protected_set_expr_location (incr, incr_loc);
7763 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7765 if (decl == NULL || decl == error_mark_node || init == error_mark_node)
7769 TREE_VEC_ELT (declv, i) = decl;
7770 TREE_VEC_ELT (initv, i) = init;
7771 TREE_VEC_ELT (condv, i) = cond;
7772 TREE_VEC_ELT (incrv, i) = incr;
7776 if (i == collapse - 1)
7779 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
7780 in between the collapsed for loops to be still considered perfectly
7781 nested. Hopefully the final version clarifies this.
7782 For now handle (multiple) {'s and empty statements. */
7785 if (c_parser_next_token_is_keyword (parser, RID_FOR))
7787 c_parser_consume_token (parser);
7790 else if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
7792 c_parser_consume_token (parser);
7796 && c_parser_next_token_is (parser, CPP_SEMICOLON))
7797 c_parser_consume_token (parser);
7800 c_parser_error (parser, "not enough perfectly nested loops");
7803 open_brace_parsed = true;
7813 nbraces += bracecount;
7816 save_break = c_break_label;
7817 c_break_label = size_one_node;
7818 save_cont = c_cont_label;
7819 c_cont_label = NULL_TREE;
7820 body = push_stmt_list ();
7822 if (open_brace_parsed)
7824 stmt = c_begin_compound_stmt (true);
7825 c_parser_compound_statement_nostart (parser);
7826 add_stmt (c_end_compound_stmt (stmt, true));
7829 add_stmt (c_parser_c99_block_statement (parser));
7831 add_stmt (build1 (LABEL_EXPR, void_type_node, c_cont_label));
7833 body = pop_stmt_list (body);
7834 c_break_label = save_break;
7835 c_cont_label = save_cont;
7839 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
7841 c_parser_consume_token (parser);
7844 else if (c_parser_next_token_is (parser, CPP_SEMICOLON))
7845 c_parser_consume_token (parser);
7848 c_parser_error (parser, "collapsed loops not perfectly nested");
7851 stmt = c_begin_compound_stmt (true);
7853 c_parser_compound_statement_nostart (parser);
7854 body = c_end_compound_stmt (stmt, true);
7861 /* Only bother calling c_finish_omp_for if we haven't already generated
7862 an error from the initialization parsing. */
7865 stmt = c_finish_omp_for (loc, declv, initv, condv, incrv, body, NULL);
7868 if (par_clauses != NULL)
7871 for (c = par_clauses; *c ; )
7872 if (OMP_CLAUSE_CODE (*c) != OMP_CLAUSE_FIRSTPRIVATE
7873 && OMP_CLAUSE_CODE (*c) != OMP_CLAUSE_LASTPRIVATE)
7874 c = &OMP_CLAUSE_CHAIN (*c);
7877 for (i = 0; i < collapse; i++)
7878 if (TREE_VEC_ELT (declv, i) == OMP_CLAUSE_DECL (*c))
7881 c = &OMP_CLAUSE_CHAIN (*c);
7882 else if (OMP_CLAUSE_CODE (*c) == OMP_CLAUSE_FIRSTPRIVATE)
7885 "iteration variable %qD should not be firstprivate",
7886 OMP_CLAUSE_DECL (*c));
7887 *c = OMP_CLAUSE_CHAIN (*c);
7891 /* Copy lastprivate (decl) clause to OMP_FOR_CLAUSES,
7892 change it to shared (decl) in
7893 OMP_PARALLEL_CLAUSES. */
7894 tree l = build_omp_clause (OMP_CLAUSE_LASTPRIVATE);
7895 OMP_CLAUSE_DECL (l) = OMP_CLAUSE_DECL (*c);
7896 OMP_CLAUSE_CHAIN (l) = clauses;
7898 OMP_CLAUSE_SET_CODE (*c, OMP_CLAUSE_SHARED);
7902 OMP_FOR_CLAUSES (stmt) = clauses;
7909 stmt = c_end_compound_stmt (TREE_VALUE (for_block), true);
7911 for_block = TREE_CHAIN (for_block);
7917 #pragma omp for for-clause[optseq] new-line
7921 #define OMP_FOR_CLAUSE_MASK \
7922 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
7923 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
7924 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
7925 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
7926 | (1u << PRAGMA_OMP_CLAUSE_ORDERED) \
7927 | (1u << PRAGMA_OMP_CLAUSE_SCHEDULE) \
7928 | (1u << PRAGMA_OMP_CLAUSE_COLLAPSE) \
7929 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
7932 c_parser_omp_for (c_parser *parser)
7934 tree block, clauses, ret;
7936 clauses = c_parser_omp_all_clauses (parser, OMP_FOR_CLAUSE_MASK,
7939 block = c_begin_compound_stmt (true);
7940 ret = c_parser_omp_for_loop (parser, clauses, NULL);
7941 block = c_end_compound_stmt (block, true);
7948 # pragma omp master new-line
7953 c_parser_omp_master (c_parser *parser)
7955 c_parser_skip_to_pragma_eol (parser);
7956 return c_finish_omp_master (c_parser_omp_structured_block (parser));
7960 # pragma omp ordered new-line
7965 c_parser_omp_ordered (c_parser *parser)
7967 c_parser_skip_to_pragma_eol (parser);
7968 return c_finish_omp_ordered (c_parser_omp_structured_block (parser));
7974 { section-sequence }
7977 section-directive[opt] structured-block
7978 section-sequence section-directive structured-block */
7981 c_parser_omp_sections_scope (c_parser *parser)
7984 bool error_suppress = false;
7987 if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
7989 /* Avoid skipping until the end of the block. */
7990 parser->error = false;
7994 stmt = push_stmt_list ();
7996 loc = c_parser_peek_token (parser)->location;
7997 if (c_parser_peek_token (parser)->pragma_kind != PRAGMA_OMP_SECTION)
7999 substmt = push_stmt_list ();
8003 c_parser_statement (parser);
8005 if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_OMP_SECTION)
8007 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
8009 if (c_parser_next_token_is (parser, CPP_EOF))
8013 substmt = pop_stmt_list (substmt);
8014 substmt = build1 (OMP_SECTION, void_type_node, substmt);
8015 SET_EXPR_LOCATION (substmt, loc);
8021 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
8023 if (c_parser_next_token_is (parser, CPP_EOF))
8026 loc = c_parser_peek_token (parser)->location;
8027 if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_OMP_SECTION)
8029 c_parser_consume_pragma (parser);
8030 c_parser_skip_to_pragma_eol (parser);
8031 error_suppress = false;
8033 else if (!error_suppress)
8035 error_at (loc, "expected %<#pragma omp section%> or %<}%>");
8036 error_suppress = true;
8039 substmt = c_parser_omp_structured_block (parser);
8040 substmt = build1 (OMP_SECTION, void_type_node, substmt);
8041 SET_EXPR_LOCATION (substmt, loc);
8044 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE,
8045 "expected %<#pragma omp section%> or %<}%>");
8047 substmt = pop_stmt_list (stmt);
8049 stmt = make_node (OMP_SECTIONS);
8050 TREE_TYPE (stmt) = void_type_node;
8051 OMP_SECTIONS_BODY (stmt) = substmt;
8053 return add_stmt (stmt);
8057 # pragma omp sections sections-clause[optseq] newline
8061 #define OMP_SECTIONS_CLAUSE_MASK \
8062 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8063 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8064 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
8065 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
8066 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
8069 c_parser_omp_sections (c_parser *parser)
8071 tree block, clauses, ret;
8073 clauses = c_parser_omp_all_clauses (parser, OMP_SECTIONS_CLAUSE_MASK,
8074 "#pragma omp sections");
8076 block = c_begin_compound_stmt (true);
8077 ret = c_parser_omp_sections_scope (parser);
8079 OMP_SECTIONS_CLAUSES (ret) = clauses;
8080 block = c_end_compound_stmt (block, true);
8087 # pragma parallel parallel-clause new-line
8088 # pragma parallel for parallel-for-clause new-line
8089 # pragma parallel sections parallel-sections-clause new-line
8092 #define OMP_PARALLEL_CLAUSE_MASK \
8093 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
8094 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8095 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8096 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
8097 | (1u << PRAGMA_OMP_CLAUSE_SHARED) \
8098 | (1u << PRAGMA_OMP_CLAUSE_COPYIN) \
8099 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
8100 | (1u << PRAGMA_OMP_CLAUSE_NUM_THREADS))
8103 c_parser_omp_parallel (c_parser *parser)
8105 enum pragma_kind p_kind = PRAGMA_OMP_PARALLEL;
8106 const char *p_name = "#pragma omp parallel";
8107 tree stmt, clauses, par_clause, ws_clause, block;
8108 unsigned int mask = OMP_PARALLEL_CLAUSE_MASK;
8110 if (c_parser_next_token_is_keyword (parser, RID_FOR))
8112 c_parser_consume_token (parser);
8113 p_kind = PRAGMA_OMP_PARALLEL_FOR;
8114 p_name = "#pragma omp parallel for";
8115 mask |= OMP_FOR_CLAUSE_MASK;
8116 mask &= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT);
8118 else if (c_parser_next_token_is (parser, CPP_NAME))
8120 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
8121 if (strcmp (p, "sections") == 0)
8123 c_parser_consume_token (parser);
8124 p_kind = PRAGMA_OMP_PARALLEL_SECTIONS;
8125 p_name = "#pragma omp parallel sections";
8126 mask |= OMP_SECTIONS_CLAUSE_MASK;
8127 mask &= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT);
8131 clauses = c_parser_omp_all_clauses (parser, mask, p_name);
8135 case PRAGMA_OMP_PARALLEL:
8136 block = c_begin_omp_parallel ();
8137 c_parser_statement (parser);
8138 stmt = c_finish_omp_parallel (clauses, block);
8141 case PRAGMA_OMP_PARALLEL_FOR:
8142 block = c_begin_omp_parallel ();
8143 c_split_parallel_clauses (clauses, &par_clause, &ws_clause);
8144 c_parser_omp_for_loop (parser, ws_clause, &par_clause);
8145 stmt = c_finish_omp_parallel (par_clause, block);
8146 OMP_PARALLEL_COMBINED (stmt) = 1;
8149 case PRAGMA_OMP_PARALLEL_SECTIONS:
8150 block = c_begin_omp_parallel ();
8151 c_split_parallel_clauses (clauses, &par_clause, &ws_clause);
8152 stmt = c_parser_omp_sections_scope (parser);
8154 OMP_SECTIONS_CLAUSES (stmt) = ws_clause;
8155 stmt = c_finish_omp_parallel (par_clause, block);
8156 OMP_PARALLEL_COMBINED (stmt) = 1;
8167 # pragma omp single single-clause[optseq] new-line
8171 #define OMP_SINGLE_CLAUSE_MASK \
8172 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8173 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8174 | (1u << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
8175 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
8178 c_parser_omp_single (c_parser *parser)
8180 tree stmt = make_node (OMP_SINGLE);
8181 TREE_TYPE (stmt) = void_type_node;
8183 OMP_SINGLE_CLAUSES (stmt)
8184 = c_parser_omp_all_clauses (parser, OMP_SINGLE_CLAUSE_MASK,
8185 "#pragma omp single");
8186 OMP_SINGLE_BODY (stmt) = c_parser_omp_structured_block (parser);
8188 return add_stmt (stmt);
8192 # pragma omp task task-clause[optseq] new-line
8195 #define OMP_TASK_CLAUSE_MASK \
8196 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
8197 | (1u << PRAGMA_OMP_CLAUSE_UNTIED) \
8198 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
8199 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8200 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8201 | (1u << PRAGMA_OMP_CLAUSE_SHARED))
8204 c_parser_omp_task (c_parser *parser)
8206 tree clauses, block;
8208 clauses = c_parser_omp_all_clauses (parser, OMP_TASK_CLAUSE_MASK,
8209 "#pragma omp task");
8211 block = c_begin_omp_task ();
8212 c_parser_statement (parser);
8213 return c_finish_omp_task (clauses, block);
8217 # pragma omp taskwait new-line
8221 c_parser_omp_taskwait (c_parser *parser)
8223 c_parser_consume_pragma (parser);
8224 c_parser_skip_to_pragma_eol (parser);
8226 c_finish_omp_taskwait ();
8229 /* Main entry point to parsing most OpenMP pragmas. */
8232 c_parser_omp_construct (c_parser *parser)
8234 enum pragma_kind p_kind;
8238 loc = c_parser_peek_token (parser)->location;
8239 p_kind = c_parser_peek_token (parser)->pragma_kind;
8240 c_parser_consume_pragma (parser);
8242 /* For all constructs below except #pragma omp atomic
8243 MUST_NOT_THROW catch handlers are needed when exceptions
8245 if (p_kind != PRAGMA_OMP_ATOMIC)
8246 c_maybe_initialize_eh ();
8250 case PRAGMA_OMP_ATOMIC:
8251 c_parser_omp_atomic (parser);
8253 case PRAGMA_OMP_CRITICAL:
8254 stmt = c_parser_omp_critical (parser);
8256 case PRAGMA_OMP_FOR:
8257 stmt = c_parser_omp_for (parser);
8259 case PRAGMA_OMP_MASTER:
8260 stmt = c_parser_omp_master (parser);
8262 case PRAGMA_OMP_ORDERED:
8263 stmt = c_parser_omp_ordered (parser);
8265 case PRAGMA_OMP_PARALLEL:
8266 stmt = c_parser_omp_parallel (parser);
8268 case PRAGMA_OMP_SECTIONS:
8269 stmt = c_parser_omp_sections (parser);
8271 case PRAGMA_OMP_SINGLE:
8272 stmt = c_parser_omp_single (parser);
8274 case PRAGMA_OMP_TASK:
8275 stmt = c_parser_omp_task (parser);
8282 SET_EXPR_LOCATION (stmt, loc);
8287 # pragma omp threadprivate (variable-list) */
8290 c_parser_omp_threadprivate (c_parser *parser)
8294 c_parser_consume_pragma (parser);
8295 vars = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL);
8297 /* Mark every variable in VARS to be assigned thread local storage. */
8298 for (t = vars; t; t = TREE_CHAIN (t))
8300 tree v = TREE_PURPOSE (t);
8302 /* If V had already been marked threadprivate, it doesn't matter
8303 whether it had been used prior to this point. */
8304 if (TREE_CODE (v) != VAR_DECL)
8305 error ("%qD is not a variable", v);
8306 else if (TREE_USED (v) && !C_DECL_THREADPRIVATE_P (v))
8307 error ("%qE declared %<threadprivate%> after first use", v);
8308 else if (! TREE_STATIC (v) && ! DECL_EXTERNAL (v))
8309 error ("automatic variable %qE cannot be %<threadprivate%>", v);
8310 else if (TREE_TYPE (v) == error_mark_node)
8312 else if (! COMPLETE_TYPE_P (TREE_TYPE (v)))
8313 error ("%<threadprivate%> %qE has incomplete type", v);
8316 if (! DECL_THREAD_LOCAL_P (v))
8318 DECL_TLS_MODEL (v) = decl_default_tls_model (v);
8319 /* If rtl has been already set for this var, call
8320 make_decl_rtl once again, so that encode_section_info
8321 has a chance to look at the new decl flags. */
8322 if (DECL_RTL_SET_P (v))
8325 C_DECL_THREADPRIVATE_P (v) = 1;
8329 c_parser_skip_to_pragma_eol (parser);
8333 /* Parse a single source file. */
8338 /* Use local storage to begin. If the first token is a pragma, parse it.
8339 If it is #pragma GCC pch_preprocess, then this will load a PCH file
8340 which will cause garbage collection. */
8343 memset (&tparser, 0, sizeof tparser);
8344 the_parser = &tparser;
8346 if (c_parser_peek_token (&tparser)->pragma_kind == PRAGMA_GCC_PCH_PREPROCESS)
8347 c_parser_pragma_pch_preprocess (&tparser);
8349 the_parser = GGC_NEW (c_parser);
8350 *the_parser = tparser;
8352 c_parser_translation_unit (the_parser);
8356 #include "gt-c-parser.h"