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 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE, t.spec);
1557 declspecs_add_type (specs, t);
1560 /* ??? The old parser rejected typeof after other type
1561 specifiers, but is a syntax error the best way of
1563 if (!typespec_ok || seen_type)
1567 t = c_parser_typeof_specifier (parser);
1568 declspecs_add_type (specs, t);
1574 declspecs_add_qual (specs, c_parser_peek_token (parser)->value);
1575 c_parser_consume_token (parser);
1580 attrs = c_parser_attributes (parser);
1581 declspecs_add_attrs (specs, attrs);
1590 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
1593 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
1594 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
1595 enum attributes[opt] identifier
1597 The form with trailing comma is new in C99. The forms with
1598 attributes are GNU extensions. In GNU C, we accept any expression
1599 without commas in the syntax (assignment expressions, not just
1600 conditional expressions); assignment expressions will be diagnosed
1605 enumerator-list , enumerator
1608 enumeration-constant
1609 enumeration-constant = constant-expression
1612 static struct c_typespec
1613 c_parser_enum_specifier (c_parser *parser)
1615 struct c_typespec ret;
1617 tree ident = NULL_TREE;
1618 location_t ident_loc = UNKNOWN_LOCATION; /* Quiet warning. */
1619 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ENUM));
1620 c_parser_consume_token (parser);
1621 attrs = c_parser_attributes (parser);
1622 /* Set the location in case we create a decl now. */
1623 c_parser_set_source_position_from_token (c_parser_peek_token (parser));
1624 if (c_parser_next_token_is (parser, CPP_NAME))
1626 ident = c_parser_peek_token (parser)->value;
1627 ident_loc = c_parser_peek_token (parser)->location;
1628 c_parser_consume_token (parser);
1630 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
1632 /* Parse an enum definition. */
1633 struct c_enum_contents the_enum;
1634 tree type = start_enum (&the_enum, ident);
1636 /* We chain the enumerators in reverse order, then put them in
1637 forward order at the end. */
1638 tree values = NULL_TREE;
1639 c_parser_consume_token (parser);
1647 location_t comma_loc = UNKNOWN_LOCATION; /* Quiet warning. */
1648 location_t value_loc;
1649 if (c_parser_next_token_is_not (parser, CPP_NAME))
1651 c_parser_error (parser, "expected identifier");
1652 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
1653 values = error_mark_node;
1656 token = c_parser_peek_token (parser);
1657 enum_id = token->value;
1658 /* Set the location in case we create a decl now. */
1659 c_parser_set_source_position_from_token (token);
1660 value_loc = token->location;
1661 c_parser_consume_token (parser);
1662 if (c_parser_next_token_is (parser, CPP_EQ))
1664 c_parser_consume_token (parser);
1665 value_loc = c_parser_peek_token (parser)->location;
1666 enum_value = c_parser_expr_no_commas (parser, NULL).value;
1669 enum_value = NULL_TREE;
1670 enum_decl = build_enumerator (&the_enum, enum_id, enum_value,
1672 TREE_CHAIN (enum_decl) = values;
1675 if (c_parser_next_token_is (parser, CPP_COMMA))
1677 comma_loc = c_parser_peek_token (parser)->location;
1679 c_parser_consume_token (parser);
1681 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
1683 if (seen_comma && !flag_isoc99)
1684 pedwarn (comma_loc, OPT_pedantic, "comma at end of enumerator list");
1685 c_parser_consume_token (parser);
1690 c_parser_error (parser, "expected %<,%> or %<}%>");
1691 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
1692 values = error_mark_node;
1696 postfix_attrs = c_parser_attributes (parser);
1697 ret.spec = finish_enum (type, nreverse (values),
1698 chainon (attrs, postfix_attrs));
1699 ret.kind = ctsk_tagdef;
1700 ret.expr = NULL_TREE;
1701 ret.expr_const_operands = true;
1706 c_parser_error (parser, "expected %<{%>");
1707 ret.spec = error_mark_node;
1708 ret.kind = ctsk_tagref;
1709 ret.expr = NULL_TREE;
1710 ret.expr_const_operands = true;
1713 ret = parser_xref_tag (ENUMERAL_TYPE, ident);
1714 /* In ISO C, enumerated types can be referred to only if already
1716 if (pedantic && !COMPLETE_TYPE_P (ret.spec))
1719 pedwarn (ident_loc, OPT_pedantic,
1720 "ISO C forbids forward references to %<enum%> types");
1725 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
1727 struct-or-union-specifier:
1728 struct-or-union attributes[opt] identifier[opt]
1729 { struct-contents } attributes[opt]
1730 struct-or-union attributes[opt] identifier
1733 struct-declaration-list
1735 struct-declaration-list:
1736 struct-declaration ;
1737 struct-declaration-list struct-declaration ;
1744 struct-declaration-list struct-declaration
1746 struct-declaration-list:
1747 struct-declaration-list ;
1750 (Note that in the syntax here, unlike that in ISO C, the semicolons
1751 are included here rather than in struct-declaration, in order to
1752 describe the syntax with extra semicolons and missing semicolon at
1757 struct-declaration-list:
1758 @defs ( class-name )
1760 (Note this does not include a trailing semicolon, but can be
1761 followed by further declarations, and gets a pedwarn-if-pedantic
1762 when followed by a semicolon.) */
1764 static struct c_typespec
1765 c_parser_struct_or_union_specifier (c_parser *parser)
1767 struct c_typespec ret;
1769 tree ident = NULL_TREE;
1770 enum tree_code code;
1771 switch (c_parser_peek_token (parser)->keyword)
1782 c_parser_consume_token (parser);
1783 attrs = c_parser_attributes (parser);
1784 /* Set the location in case we create a decl now. */
1785 c_parser_set_source_position_from_token (c_parser_peek_token (parser));
1786 if (c_parser_next_token_is (parser, CPP_NAME))
1788 ident = c_parser_peek_token (parser)->value;
1789 c_parser_consume_token (parser);
1791 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
1793 /* Parse a struct or union definition. Start the scope of the
1794 tag before parsing components. */
1795 tree type = start_struct (code, ident);
1797 /* We chain the components in reverse order, then put them in
1798 forward order at the end. Each struct-declaration may
1799 declare multiple components (comma-separated), so we must use
1800 chainon to join them, although when parsing each
1801 struct-declaration we can use TREE_CHAIN directly.
1803 The theory behind all this is that there will be more
1804 semicolon separated fields than comma separated fields, and
1805 so we'll be minimizing the number of node traversals required
1807 tree contents = NULL_TREE;
1808 c_parser_consume_token (parser);
1809 /* Handle the Objective-C @defs construct,
1810 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
1811 if (c_parser_next_token_is_keyword (parser, RID_AT_DEFS))
1814 gcc_assert (c_dialect_objc ());
1815 c_parser_consume_token (parser);
1816 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
1818 if (c_parser_next_token_is (parser, CPP_NAME)
1819 && c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME)
1821 name = c_parser_peek_token (parser)->value;
1822 c_parser_consume_token (parser);
1826 c_parser_error (parser, "expected class name");
1827 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
1830 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
1832 contents = nreverse (objc_get_class_ivars (name));
1835 /* Parse the struct-declarations and semicolons. Problems with
1836 semicolons are diagnosed here; empty structures are diagnosed
1841 /* Parse any stray semicolon. */
1842 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1844 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
1845 "extra semicolon in struct or union specified");
1846 c_parser_consume_token (parser);
1849 /* Stop if at the end of the struct or union contents. */
1850 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
1852 c_parser_consume_token (parser);
1855 /* Accept #pragmas at struct scope. */
1856 if (c_parser_next_token_is (parser, CPP_PRAGMA))
1858 c_parser_pragma (parser, pragma_external);
1861 /* Parse some comma-separated declarations, but not the
1862 trailing semicolon if any. */
1863 decls = c_parser_struct_declaration (parser);
1864 contents = chainon (decls, contents);
1865 /* If no semicolon follows, either we have a parse error or
1866 are at the end of the struct or union and should
1868 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1869 c_parser_consume_token (parser);
1872 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
1873 pedwarn (c_parser_peek_token (parser)->location, 0,
1874 "no semicolon at end of struct or union");
1877 c_parser_error (parser, "expected %<;%>");
1878 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
1883 postfix_attrs = c_parser_attributes (parser);
1884 ret.spec = finish_struct (type, nreverse (contents),
1885 chainon (attrs, postfix_attrs));
1886 ret.kind = ctsk_tagdef;
1887 ret.expr = NULL_TREE;
1888 ret.expr_const_operands = true;
1893 c_parser_error (parser, "expected %<{%>");
1894 ret.spec = error_mark_node;
1895 ret.kind = ctsk_tagref;
1896 ret.expr = NULL_TREE;
1897 ret.expr_const_operands = true;
1900 ret = parser_xref_tag (code, ident);
1904 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
1905 the trailing semicolon.
1908 specifier-qualifier-list struct-declarator-list
1910 specifier-qualifier-list:
1911 type-specifier specifier-qualifier-list[opt]
1912 type-qualifier specifier-qualifier-list[opt]
1913 attributes specifier-qualifier-list[opt]
1915 struct-declarator-list:
1917 struct-declarator-list , attributes[opt] struct-declarator
1920 declarator attributes[opt]
1921 declarator[opt] : constant-expression attributes[opt]
1926 __extension__ struct-declaration
1927 specifier-qualifier-list
1929 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
1930 of attributes where shown is a GNU extension. In GNU C, we accept
1931 any expression without commas in the syntax (assignment
1932 expressions, not just conditional expressions); assignment
1933 expressions will be diagnosed as non-constant. */
1936 c_parser_struct_declaration (c_parser *parser)
1938 struct c_declspecs *specs;
1940 tree all_prefix_attrs;
1942 location_t decl_loc;
1943 if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
1947 ext = disable_extension_diagnostics ();
1948 c_parser_consume_token (parser);
1949 decl = c_parser_struct_declaration (parser);
1950 restore_extension_diagnostics (ext);
1953 specs = build_null_declspecs ();
1954 decl_loc = c_parser_peek_token (parser)->location;
1955 c_parser_declspecs (parser, specs, false, true, true);
1958 if (!specs->declspecs_seen_p)
1960 c_parser_error (parser, "expected specifier-qualifier-list");
1963 finish_declspecs (specs);
1964 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1967 if (!specs->type_seen_p)
1969 pedwarn (decl_loc, OPT_pedantic,
1970 "ISO C forbids member declarations with no members");
1971 shadow_tag_warned (specs, pedantic);
1976 /* Support for unnamed structs or unions as members of
1977 structs or unions (which is [a] useful and [b] supports
1981 ret = grokfield (c_parser_peek_token (parser)->location,
1982 build_id_declarator (NULL_TREE), specs,
1985 decl_attributes (&ret, attrs, 0);
1989 pending_xref_error ();
1990 prefix_attrs = specs->attrs;
1991 all_prefix_attrs = prefix_attrs;
1992 specs->attrs = NULL_TREE;
1996 /* Declaring one or more declarators or un-named bit-fields. */
1997 struct c_declarator *declarator;
1999 if (c_parser_next_token_is (parser, CPP_COLON))
2000 declarator = build_id_declarator (NULL_TREE);
2002 declarator = c_parser_declarator (parser, specs->type_seen_p,
2003 C_DTR_NORMAL, &dummy);
2004 if (declarator == NULL)
2006 c_parser_skip_to_end_of_block_or_statement (parser);
2009 if (c_parser_next_token_is (parser, CPP_COLON)
2010 || c_parser_next_token_is (parser, CPP_COMMA)
2011 || c_parser_next_token_is (parser, CPP_SEMICOLON)
2012 || c_parser_next_token_is (parser, CPP_CLOSE_BRACE)
2013 || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2015 tree postfix_attrs = NULL_TREE;
2016 tree width = NULL_TREE;
2018 if (c_parser_next_token_is (parser, CPP_COLON))
2020 c_parser_consume_token (parser);
2021 width = c_parser_expr_no_commas (parser, NULL).value;
2023 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2024 postfix_attrs = c_parser_attributes (parser);
2025 d = grokfield (c_parser_peek_token (parser)->location,
2026 declarator, specs, width, &all_prefix_attrs);
2027 decl_attributes (&d, chainon (postfix_attrs,
2028 all_prefix_attrs), 0);
2029 TREE_CHAIN (d) = decls;
2031 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2032 all_prefix_attrs = chainon (c_parser_attributes (parser),
2035 all_prefix_attrs = prefix_attrs;
2036 if (c_parser_next_token_is (parser, CPP_COMMA))
2037 c_parser_consume_token (parser);
2038 else if (c_parser_next_token_is (parser, CPP_SEMICOLON)
2039 || c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2041 /* Semicolon consumed in caller. */
2046 c_parser_error (parser, "expected %<,%>, %<;%> or %<}%>");
2052 c_parser_error (parser,
2053 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
2054 "%<__attribute__%>");
2061 /* Parse a typeof specifier (a GNU extension).
2064 typeof ( expression )
2065 typeof ( type-name )
2068 static struct c_typespec
2069 c_parser_typeof_specifier (c_parser *parser)
2071 struct c_typespec ret;
2072 ret.kind = ctsk_typeof;
2073 ret.spec = error_mark_node;
2074 ret.expr = NULL_TREE;
2075 ret.expr_const_operands = true;
2076 gcc_assert (c_parser_next_token_is_keyword (parser, RID_TYPEOF));
2077 c_parser_consume_token (parser);
2080 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2086 if (c_parser_next_token_starts_typename (parser))
2088 struct c_type_name *type = c_parser_type_name (parser);
2093 ret.spec = groktypename (type, &ret.expr, &ret.expr_const_operands);
2094 pop_maybe_used (variably_modified_type_p (ret.spec, NULL_TREE));
2100 location_t here = c_parser_peek_token (parser)->location;
2101 struct c_expr expr = c_parser_expression (parser);
2104 if (TREE_CODE (expr.value) == COMPONENT_REF
2105 && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
2106 error_at (here, "%<typeof%> applied to a bit-field");
2107 ret.spec = TREE_TYPE (expr.value);
2108 was_vm = variably_modified_type_p (ret.spec, NULL_TREE);
2109 /* This is returned with the type so that when the type is
2110 evaluated, this can be evaluated. */
2112 ret.expr = c_fully_fold (expr.value, false, &ret.expr_const_operands);
2113 pop_maybe_used (was_vm);
2115 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
2119 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
2120 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
2121 be redeclared; otherwise it may not. KIND indicates which kind of
2122 declarator is wanted. Returns a valid declarator except in the
2123 case of a syntax error in which case NULL is returned. *SEEN_ID is
2124 set to true if an identifier being declared is seen; this is used
2125 to diagnose bad forms of abstract array declarators and to
2126 determine whether an identifier list is syntactically permitted.
2129 pointer[opt] direct-declarator
2133 ( attributes[opt] declarator )
2134 direct-declarator array-declarator
2135 direct-declarator ( parameter-type-list )
2136 direct-declarator ( identifier-list[opt] )
2139 * type-qualifier-list[opt]
2140 * type-qualifier-list[opt] pointer
2142 type-qualifier-list:
2145 type-qualifier-list type-qualifier
2146 type-qualifier-list attributes
2148 parameter-type-list:
2150 parameter-list , ...
2153 parameter-declaration
2154 parameter-list , parameter-declaration
2156 parameter-declaration:
2157 declaration-specifiers declarator attributes[opt]
2158 declaration-specifiers abstract-declarator[opt] attributes[opt]
2162 identifier-list , identifier
2164 abstract-declarator:
2166 pointer[opt] direct-abstract-declarator
2168 direct-abstract-declarator:
2169 ( attributes[opt] abstract-declarator )
2170 direct-abstract-declarator[opt] array-declarator
2171 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
2176 direct-declarator ( parameter-forward-declarations
2177 parameter-type-list[opt] )
2179 direct-abstract-declarator:
2180 direct-abstract-declarator[opt] ( parameter-forward-declarations
2181 parameter-type-list[opt] )
2183 parameter-forward-declarations:
2185 parameter-forward-declarations parameter-list ;
2187 The uses of attributes shown above are GNU extensions.
2189 Some forms of array declarator are not included in C99 in the
2190 syntax for abstract declarators; these are disallowed elsewhere.
2191 This may be a defect (DR#289).
2193 This function also accepts an omitted abstract declarator as being
2194 an abstract declarator, although not part of the formal syntax. */
2196 static struct c_declarator *
2197 c_parser_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
2200 /* Parse any initial pointer part. */
2201 if (c_parser_next_token_is (parser, CPP_MULT))
2203 struct c_declspecs *quals_attrs = build_null_declspecs ();
2204 struct c_declarator *inner;
2205 c_parser_consume_token (parser);
2206 c_parser_declspecs (parser, quals_attrs, false, false, true);
2207 inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
2211 return make_pointer_declarator (quals_attrs, inner);
2213 /* Now we have a direct declarator, direct abstract declarator or
2214 nothing (which counts as a direct abstract declarator here). */
2215 return c_parser_direct_declarator (parser, type_seen_p, kind, seen_id);
2218 /* Parse a direct declarator or direct abstract declarator; arguments
2219 as c_parser_declarator. */
2221 static struct c_declarator *
2222 c_parser_direct_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
2225 /* The direct declarator must start with an identifier (possibly
2226 omitted) or a parenthesized declarator (possibly abstract). In
2227 an ordinary declarator, initial parentheses must start a
2228 parenthesized declarator. In an abstract declarator or parameter
2229 declarator, they could start a parenthesized declarator or a
2230 parameter list. To tell which, the open parenthesis and any
2231 following attributes must be read. If a declaration specifier
2232 follows, then it is a parameter list; if the specifier is a
2233 typedef name, there might be an ambiguity about redeclaring it,
2234 which is resolved in the direction of treating it as a typedef
2235 name. If a close parenthesis follows, it is also an empty
2236 parameter list, as the syntax does not permit empty abstract
2237 declarators. Otherwise, it is a parenthesized declarator (in
2238 which case the analysis may be repeated inside it, recursively).
2240 ??? There is an ambiguity in a parameter declaration "int
2241 (__attribute__((foo)) x)", where x is not a typedef name: it
2242 could be an abstract declarator for a function, or declare x with
2243 parentheses. The proper resolution of this ambiguity needs
2244 documenting. At present we follow an accident of the old
2245 parser's implementation, whereby the first parameter must have
2246 some declaration specifiers other than just attributes. Thus as
2247 a parameter declaration it is treated as a parenthesized
2248 parameter named x, and as an abstract declarator it is
2251 ??? Also following the old parser, attributes inside an empty
2252 parameter list are ignored, making it a list not yielding a
2253 prototype, rather than giving an error or making it have one
2254 parameter with implicit type int.
2256 ??? Also following the old parser, typedef names may be
2257 redeclared in declarators, but not Objective-C class names. */
2259 if (kind != C_DTR_ABSTRACT
2260 && c_parser_next_token_is (parser, CPP_NAME)
2262 && c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME)
2263 || c_parser_peek_token (parser)->id_kind == C_ID_ID))
2265 struct c_declarator *inner
2266 = build_id_declarator (c_parser_peek_token (parser)->value);
2268 inner->id_loc = c_parser_peek_token (parser)->location;
2269 c_parser_consume_token (parser);
2270 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2273 if (kind != C_DTR_NORMAL
2274 && c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
2276 struct c_declarator *inner = build_id_declarator (NULL_TREE);
2277 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2280 /* Either we are at the end of an abstract declarator, or we have
2283 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
2286 struct c_declarator *inner;
2287 c_parser_consume_token (parser);
2288 attrs = c_parser_attributes (parser);
2289 if (kind != C_DTR_NORMAL
2290 && (c_parser_next_token_starts_declspecs (parser)
2291 || c_parser_next_token_is (parser, CPP_CLOSE_PAREN)))
2293 struct c_arg_info *args
2294 = c_parser_parms_declarator (parser, kind == C_DTR_NORMAL,
2301 = build_function_declarator (args,
2302 build_id_declarator (NULL_TREE));
2303 return c_parser_direct_declarator_inner (parser, *seen_id,
2307 /* A parenthesized declarator. */
2308 inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
2309 if (inner != NULL && attrs != NULL)
2310 inner = build_attrs_declarator (attrs, inner);
2311 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2313 c_parser_consume_token (parser);
2317 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2321 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2328 if (kind == C_DTR_NORMAL)
2330 c_parser_error (parser, "expected identifier or %<(%>");
2334 return build_id_declarator (NULL_TREE);
2338 /* Parse part of a direct declarator or direct abstract declarator,
2339 given that some (in INNER) has already been parsed; ID_PRESENT is
2340 true if an identifier is present, false for an abstract
2343 static struct c_declarator *
2344 c_parser_direct_declarator_inner (c_parser *parser, bool id_present,
2345 struct c_declarator *inner)
2347 /* Parse a sequence of array declarators and parameter lists. */
2348 if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
2350 struct c_declarator *declarator;
2351 struct c_declspecs *quals_attrs = build_null_declspecs ();
2355 c_parser_consume_token (parser);
2356 c_parser_declspecs (parser, quals_attrs, false, false, true);
2357 static_seen = c_parser_next_token_is_keyword (parser, RID_STATIC);
2359 c_parser_consume_token (parser);
2360 if (static_seen && !quals_attrs->declspecs_seen_p)
2361 c_parser_declspecs (parser, quals_attrs, false, false, true);
2362 if (!quals_attrs->declspecs_seen_p)
2364 /* If "static" is present, there must be an array dimension.
2365 Otherwise, there may be a dimension, "*", or no
2370 dimen = c_parser_expr_no_commas (parser, NULL).value;
2374 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
2379 else if (c_parser_next_token_is (parser, CPP_MULT))
2381 if (c_parser_peek_2nd_token (parser)->type == CPP_CLOSE_SQUARE)
2385 c_parser_consume_token (parser);
2390 dimen = c_parser_expr_no_commas (parser, NULL).value;
2396 dimen = c_parser_expr_no_commas (parser, NULL).value;
2399 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
2400 c_parser_consume_token (parser);
2403 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
2407 declarator = build_array_declarator (dimen, quals_attrs, static_seen,
2409 if (declarator == NULL)
2411 inner = set_array_declarator_inner (declarator, inner);
2412 return c_parser_direct_declarator_inner (parser, id_present, inner);
2414 else if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
2417 struct c_arg_info *args;
2418 c_parser_consume_token (parser);
2419 attrs = c_parser_attributes (parser);
2420 args = c_parser_parms_declarator (parser, id_present, attrs);
2425 inner = build_function_declarator (args, inner);
2426 return c_parser_direct_declarator_inner (parser, id_present, inner);
2432 /* Parse a parameter list or identifier list, including the closing
2433 parenthesis but not the opening one. ATTRS are the attributes at
2434 the start of the list. ID_LIST_OK is true if an identifier list is
2435 acceptable; such a list must not have attributes at the start. */
2437 static struct c_arg_info *
2438 c_parser_parms_declarator (c_parser *parser, bool id_list_ok, tree attrs)
2441 declare_parm_level ();
2442 /* If the list starts with an identifier, it is an identifier list.
2443 Otherwise, it is either a prototype list or an empty list. */
2446 && c_parser_next_token_is (parser, CPP_NAME)
2447 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
2449 tree list = NULL_TREE, *nextp = &list;
2450 while (c_parser_next_token_is (parser, CPP_NAME)
2451 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
2453 *nextp = build_tree_list (NULL_TREE,
2454 c_parser_peek_token (parser)->value);
2455 nextp = & TREE_CHAIN (*nextp);
2456 c_parser_consume_token (parser);
2457 if (c_parser_next_token_is_not (parser, CPP_COMMA))
2459 c_parser_consume_token (parser);
2460 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2462 c_parser_error (parser, "expected identifier");
2466 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2468 struct c_arg_info *ret = XOBNEW (&parser_obstack, struct c_arg_info);
2473 ret->pending_sizes = 0;
2474 ret->had_vla_unspec = 0;
2475 c_parser_consume_token (parser);
2481 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2489 struct c_arg_info *ret = c_parser_parms_list_declarator (parser, attrs);
2495 /* Parse a parameter list (possibly empty), including the closing
2496 parenthesis but not the opening one. ATTRS are the attributes at
2497 the start of the list. */
2499 static struct c_arg_info *
2500 c_parser_parms_list_declarator (c_parser *parser, tree attrs)
2502 bool good_parm = false;
2503 /* ??? Following the old parser, forward parameter declarations may
2504 use abstract declarators, and if no real parameter declarations
2505 follow the forward declarations then this is not diagnosed. Also
2506 note as above that attributes are ignored as the only contents of
2507 the parentheses, or as the only contents after forward
2509 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2511 struct c_arg_info *ret = XOBNEW (&parser_obstack, struct c_arg_info);
2516 ret->pending_sizes = 0;
2517 ret->had_vla_unspec = 0;
2518 c_parser_consume_token (parser);
2521 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
2523 struct c_arg_info *ret = XOBNEW (&parser_obstack, struct c_arg_info);
2527 ret->pending_sizes = 0;
2528 ret->had_vla_unspec = 0;
2529 /* Suppress -Wold-style-definition for this case. */
2530 ret->types = error_mark_node;
2531 error_at (c_parser_peek_token (parser)->location,
2532 "ISO C requires a named argument before %<...%>");
2533 c_parser_consume_token (parser);
2534 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2536 c_parser_consume_token (parser);
2541 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2546 /* Nonempty list of parameters, either terminated with semicolon
2547 (forward declarations; recurse) or with close parenthesis (normal
2548 function) or with ", ... )" (variadic function). */
2551 /* Parse a parameter. */
2552 struct c_parm *parm = c_parser_parameter_declaration (parser, attrs);
2557 push_parm_decl (parm);
2559 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
2562 c_parser_consume_token (parser);
2563 mark_forward_parm_decls ();
2564 new_attrs = c_parser_attributes (parser);
2565 return c_parser_parms_list_declarator (parser, new_attrs);
2567 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2569 c_parser_consume_token (parser);
2571 return get_parm_info (false);
2574 struct c_arg_info *ret
2575 = XOBNEW (&parser_obstack, struct c_arg_info);
2580 ret->pending_sizes = 0;
2581 ret->had_vla_unspec = 0;
2585 if (!c_parser_require (parser, CPP_COMMA,
2586 "expected %<;%>, %<,%> or %<)%>"))
2588 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
2589 get_pending_sizes ();
2592 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
2594 c_parser_consume_token (parser);
2595 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2597 c_parser_consume_token (parser);
2599 return get_parm_info (true);
2602 struct c_arg_info *ret
2603 = XOBNEW (&parser_obstack, struct c_arg_info);
2608 ret->pending_sizes = 0;
2609 ret->had_vla_unspec = 0;
2615 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2617 get_pending_sizes ();
2624 /* Parse a parameter declaration. ATTRS are the attributes at the
2625 start of the declaration if it is the first parameter. */
2627 static struct c_parm *
2628 c_parser_parameter_declaration (c_parser *parser, tree attrs)
2630 struct c_declspecs *specs;
2631 struct c_declarator *declarator;
2633 tree postfix_attrs = NULL_TREE;
2635 if (!c_parser_next_token_starts_declspecs (parser))
2637 /* ??? In some Objective-C cases '...' isn't applicable so there
2638 should be a different message. */
2639 c_parser_error (parser,
2640 "expected declaration specifiers or %<...%>");
2641 c_parser_skip_to_end_of_parameter (parser);
2644 specs = build_null_declspecs ();
2647 declspecs_add_attrs (specs, attrs);
2650 c_parser_declspecs (parser, specs, true, true, true);
2651 finish_declspecs (specs);
2652 pending_xref_error ();
2653 prefix_attrs = specs->attrs;
2654 specs->attrs = NULL_TREE;
2655 declarator = c_parser_declarator (parser, specs->type_seen_p,
2656 C_DTR_PARM, &dummy);
2657 if (declarator == NULL)
2659 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
2662 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2663 postfix_attrs = c_parser_attributes (parser);
2664 return build_c_parm (specs, chainon (postfix_attrs, prefix_attrs),
2668 /* Parse a string literal in an asm expression. It should not be
2669 translated, and wide string literals are an error although
2670 permitted by the syntax. This is a GNU extension.
2675 ??? At present, following the old parser, the caller needs to have
2676 set lex_untranslated_string to 1. It would be better to follow the
2677 C++ parser rather than using this kludge. */
2680 c_parser_asm_string_literal (c_parser *parser)
2683 if (c_parser_next_token_is (parser, CPP_STRING))
2685 str = c_parser_peek_token (parser)->value;
2686 c_parser_consume_token (parser);
2688 else if (c_parser_next_token_is (parser, CPP_WSTRING))
2690 error_at (c_parser_peek_token (parser)->location,
2691 "wide string literal in %<asm%>");
2692 str = build_string (1, "");
2693 c_parser_consume_token (parser);
2697 c_parser_error (parser, "expected string literal");
2703 /* Parse a simple asm expression. This is used in restricted
2704 contexts, where a full expression with inputs and outputs does not
2705 make sense. This is a GNU extension.
2708 asm ( asm-string-literal )
2712 c_parser_simple_asm_expr (c_parser *parser)
2715 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
2716 /* ??? Follow the C++ parser rather than using the
2717 lex_untranslated_string kludge. */
2718 parser->lex_untranslated_string = true;
2719 c_parser_consume_token (parser);
2720 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2722 parser->lex_untranslated_string = false;
2725 str = c_parser_asm_string_literal (parser);
2726 parser->lex_untranslated_string = false;
2727 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
2729 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
2735 /* Parse (possibly empty) attributes. This is a GNU extension.
2739 attributes attribute
2742 __attribute__ ( ( attribute-list ) )
2746 attribute_list , attrib
2751 any-word ( identifier )
2752 any-word ( identifier , nonempty-expr-list )
2753 any-word ( expr-list )
2755 where the "identifier" must not be declared as a type, and
2756 "any-word" may be any identifier (including one declared as a
2757 type), a reserved word storage class specifier, type specifier or
2758 type qualifier. ??? This still leaves out most reserved keywords
2759 (following the old parser), shouldn't we include them, and why not
2760 allow identifiers declared as types to start the arguments? */
2763 c_parser_attributes (c_parser *parser)
2765 tree attrs = NULL_TREE;
2766 while (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2768 /* ??? Follow the C++ parser rather than using the
2769 lex_untranslated_string kludge. */
2770 parser->lex_untranslated_string = true;
2771 c_parser_consume_token (parser);
2772 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2774 parser->lex_untranslated_string = false;
2777 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2779 parser->lex_untranslated_string = false;
2780 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
2783 /* Parse the attribute list. */
2784 while (c_parser_next_token_is (parser, CPP_COMMA)
2785 || c_parser_next_token_is (parser, CPP_NAME)
2786 || c_parser_next_token_is (parser, CPP_KEYWORD))
2788 tree attr, attr_name, attr_args;
2789 if (c_parser_next_token_is (parser, CPP_COMMA))
2791 c_parser_consume_token (parser);
2794 if (c_parser_next_token_is (parser, CPP_KEYWORD))
2796 /* ??? See comment above about what keywords are
2799 switch (c_parser_peek_token (parser)->keyword)
2836 /* Accept __attribute__((__const)) as __attribute__((const))
2839 = ridpointers[(int) c_parser_peek_token (parser)->keyword];
2842 attr_name = c_parser_peek_token (parser)->value;
2843 c_parser_consume_token (parser);
2844 if (c_parser_next_token_is_not (parser, CPP_OPEN_PAREN))
2846 attr = build_tree_list (attr_name, NULL_TREE);
2847 attrs = chainon (attrs, attr);
2850 c_parser_consume_token (parser);
2851 /* Parse the attribute contents. If they start with an
2852 identifier which is followed by a comma or close
2853 parenthesis, then the arguments start with that
2854 identifier; otherwise they are an expression list. */
2855 if (c_parser_next_token_is (parser, CPP_NAME)
2856 && c_parser_peek_token (parser)->id_kind == C_ID_ID
2857 && ((c_parser_peek_2nd_token (parser)->type == CPP_COMMA)
2858 || (c_parser_peek_2nd_token (parser)->type
2859 == CPP_CLOSE_PAREN)))
2861 tree arg1 = c_parser_peek_token (parser)->value;
2862 c_parser_consume_token (parser);
2863 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2864 attr_args = build_tree_list (NULL_TREE, arg1);
2867 c_parser_consume_token (parser);
2868 attr_args = tree_cons (NULL_TREE, arg1,
2869 c_parser_expr_list (parser, false,
2875 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2876 attr_args = NULL_TREE;
2878 attr_args = c_parser_expr_list (parser, false, true);
2880 attr = build_tree_list (attr_name, attr_args);
2881 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2882 c_parser_consume_token (parser);
2885 parser->lex_untranslated_string = false;
2886 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2890 attrs = chainon (attrs, attr);
2892 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2893 c_parser_consume_token (parser);
2896 parser->lex_untranslated_string = false;
2897 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2901 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2902 c_parser_consume_token (parser);
2905 parser->lex_untranslated_string = false;
2906 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2910 parser->lex_untranslated_string = false;
2915 /* Parse a type name (C90 6.5.5, C99 6.7.6).
2918 specifier-qualifier-list abstract-declarator[opt]
2921 static struct c_type_name *
2922 c_parser_type_name (c_parser *parser)
2924 struct c_declspecs *specs = build_null_declspecs ();
2925 struct c_declarator *declarator;
2926 struct c_type_name *ret;
2928 c_parser_declspecs (parser, specs, false, true, true);
2929 if (!specs->declspecs_seen_p)
2931 c_parser_error (parser, "expected specifier-qualifier-list");
2934 pending_xref_error ();
2935 finish_declspecs (specs);
2936 declarator = c_parser_declarator (parser, specs->type_seen_p,
2937 C_DTR_ABSTRACT, &dummy);
2938 if (declarator == NULL)
2940 ret = XOBNEW (&parser_obstack, struct c_type_name);
2942 ret->declarator = declarator;
2946 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
2949 assignment-expression
2950 { initializer-list }
2951 { initializer-list , }
2954 designation[opt] initializer
2955 initializer-list , designation[opt] initializer
2962 designator-list designator
2969 [ constant-expression ]
2981 [ constant-expression ... constant-expression ]
2983 Any expression without commas is accepted in the syntax for the
2984 constant-expressions, with non-constant expressions rejected later.
2986 This function is only used for top-level initializers; for nested
2987 ones, see c_parser_initval. */
2989 static struct c_expr
2990 c_parser_initializer (c_parser *parser)
2992 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
2993 return c_parser_braced_init (parser, NULL_TREE, false);
2997 ret = c_parser_expr_no_commas (parser, NULL);
2998 if (TREE_CODE (ret.value) != STRING_CST
2999 && TREE_CODE (ret.value) != COMPOUND_LITERAL_EXPR)
3000 ret = default_function_array_conversion (ret);
3005 /* Parse a braced initializer list. TYPE is the type specified for a
3006 compound literal, and NULL_TREE for other initializers and for
3007 nested braced lists. NESTED_P is true for nested braced lists,
3008 false for the list of a compound literal or the list that is the
3009 top-level initializer in a declaration. */
3011 static struct c_expr
3012 c_parser_braced_init (c_parser *parser, tree type, bool nested_p)
3014 location_t brace_loc = c_parser_peek_token (parser)->location;
3015 gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE));
3016 c_parser_consume_token (parser);
3018 push_init_level (0);
3020 really_start_incremental_init (type);
3021 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3023 pedwarn (brace_loc, OPT_pedantic, "ISO C forbids empty initializer braces");
3027 /* Parse a non-empty initializer list, possibly with a trailing
3031 c_parser_initelt (parser);
3034 if (c_parser_next_token_is (parser, CPP_COMMA))
3035 c_parser_consume_token (parser);
3038 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3042 if (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE))
3045 ret.value = error_mark_node;
3046 ret.original_code = ERROR_MARK;
3047 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, "expected %<}%>");
3051 c_parser_consume_token (parser);
3052 return pop_init_level (0);
3055 /* Parse a nested initializer, including designators. */
3058 c_parser_initelt (c_parser *parser)
3060 /* Parse any designator or designator list. A single array
3061 designator may have the subsequent "=" omitted in GNU C, but a
3062 longer list or a structure member designator may not. */
3063 if (c_parser_next_token_is (parser, CPP_NAME)
3064 && c_parser_peek_2nd_token (parser)->type == CPP_COLON)
3066 /* Old-style structure member designator. */
3067 set_init_label (c_parser_peek_token (parser)->value);
3068 /* Use the colon as the error location. */
3069 pedwarn (c_parser_peek_2nd_token (parser)->location, OPT_pedantic,
3070 "obsolete use of designated initializer with %<:%>");
3071 c_parser_consume_token (parser);
3072 c_parser_consume_token (parser);
3076 /* des_seen is 0 if there have been no designators, 1 if there
3077 has been a single array designator and 2 otherwise. */
3079 /* Location of a designator. */
3080 location_t des_loc = UNKNOWN_LOCATION; /* Quiet warning. */
3081 while (c_parser_next_token_is (parser, CPP_OPEN_SQUARE)
3082 || c_parser_next_token_is (parser, CPP_DOT))
3084 int des_prev = des_seen;
3086 des_loc = c_parser_peek_token (parser)->location;
3089 if (c_parser_next_token_is (parser, CPP_DOT))
3092 c_parser_consume_token (parser);
3093 if (c_parser_next_token_is (parser, CPP_NAME))
3095 set_init_label (c_parser_peek_token (parser)->value);
3096 c_parser_consume_token (parser);
3101 init.value = error_mark_node;
3102 init.original_code = ERROR_MARK;
3103 c_parser_error (parser, "expected identifier");
3104 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
3105 process_init_element (init, false);
3112 location_t ellipsis_loc = UNKNOWN_LOCATION; /* Quiet warning. */
3113 /* ??? Following the old parser, [ objc-receiver
3114 objc-message-args ] is accepted as an initializer,
3115 being distinguished from a designator by what follows
3116 the first assignment expression inside the square
3117 brackets, but after a first array designator a
3118 subsequent square bracket is for Objective-C taken to
3119 start an expression, using the obsolete form of
3120 designated initializer without '=', rather than
3121 possibly being a second level of designation: in LALR
3122 terms, the '[' is shifted rather than reducing
3123 designator to designator-list. */
3124 if (des_prev == 1 && c_dialect_objc ())
3126 des_seen = des_prev;
3129 if (des_prev == 0 && c_dialect_objc ())
3131 /* This might be an array designator or an
3132 Objective-C message expression. If the former,
3133 continue parsing here; if the latter, parse the
3134 remainder of the initializer given the starting
3135 primary-expression. ??? It might make sense to
3136 distinguish when des_prev == 1 as well; see
3137 previous comment. */
3139 struct c_expr mexpr;
3140 c_parser_consume_token (parser);
3141 if (c_parser_peek_token (parser)->type == CPP_NAME
3142 && ((c_parser_peek_token (parser)->id_kind
3144 || (c_parser_peek_token (parser)->id_kind
3145 == C_ID_CLASSNAME)))
3147 /* Type name receiver. */
3148 tree id = c_parser_peek_token (parser)->value;
3149 c_parser_consume_token (parser);
3150 rec = objc_get_class_reference (id);
3151 goto parse_message_args;
3153 first = c_parser_expr_no_commas (parser, NULL).value;
3154 if (c_parser_next_token_is (parser, CPP_ELLIPSIS)
3155 || c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3156 goto array_desig_after_first;
3157 /* Expression receiver. So far only one part
3158 without commas has been parsed; there might be
3159 more of the expression. */
3161 while (c_parser_next_token_is (parser, CPP_COMMA))
3164 c_parser_consume_token (parser);
3165 next = c_parser_expr_no_commas (parser, NULL);
3166 next = default_function_array_conversion (next);
3167 rec = build_compound_expr (rec, next.value);
3170 /* Now parse the objc-message-args. */
3171 args = c_parser_objc_message_args (parser);
3172 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
3175 = objc_build_message_expr (build_tree_list (rec, args));
3176 mexpr.original_code = ERROR_MARK;
3177 /* Now parse and process the remainder of the
3178 initializer, starting with this message
3179 expression as a primary-expression. */
3180 c_parser_initval (parser, &mexpr);
3183 c_parser_consume_token (parser);
3184 first = c_parser_expr_no_commas (parser, NULL).value;
3185 array_desig_after_first:
3186 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
3188 ellipsis_loc = c_parser_peek_token (parser)->location;
3189 c_parser_consume_token (parser);
3190 second = c_parser_expr_no_commas (parser, NULL).value;
3194 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3196 c_parser_consume_token (parser);
3197 set_init_index (first, second);
3199 pedwarn (ellipsis_loc, OPT_pedantic,
3200 "ISO C forbids specifying range of elements to initialize");
3203 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
3209 if (c_parser_next_token_is (parser, CPP_EQ))
3212 pedwarn (des_loc, OPT_pedantic,
3213 "ISO C90 forbids specifying subobject to initialize");
3214 c_parser_consume_token (parser);
3219 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
3220 "obsolete use of designated initializer without %<=%>");
3224 init.value = error_mark_node;
3225 init.original_code = ERROR_MARK;
3226 c_parser_error (parser, "expected %<=%>");
3227 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
3228 process_init_element (init, false);
3234 c_parser_initval (parser, NULL);
3237 /* Parse a nested initializer; as c_parser_initializer but parses
3238 initializers within braced lists, after any designators have been
3239 applied. If AFTER is not NULL then it is an Objective-C message
3240 expression which is the primary-expression starting the
3244 c_parser_initval (c_parser *parser, struct c_expr *after)
3247 gcc_assert (!after || c_dialect_objc ());
3248 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE) && !after)
3249 init = c_parser_braced_init (parser, NULL_TREE, true);
3252 init = c_parser_expr_no_commas (parser, after);
3253 if (init.value != NULL_TREE
3254 && TREE_CODE (init.value) != STRING_CST
3255 && TREE_CODE (init.value) != COMPOUND_LITERAL_EXPR)
3256 init = default_function_array_conversion (init);
3258 process_init_element (init, false);
3261 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
3265 { block-item-list[opt] }
3266 { label-declarations block-item-list }
3270 block-item-list block-item
3282 { label-declarations block-item-list }
3285 __extension__ nested-declaration
3286 nested-function-definition
3290 label-declarations label-declaration
3293 __label__ identifier-list ;
3295 Allowing the mixing of declarations and code is new in C99. The
3296 GNU syntax also permits (not shown above) labels at the end of
3297 compound statements, which yield an error. We don't allow labels
3298 on declarations; this might seem like a natural extension, but
3299 there would be a conflict between attributes on the label and
3300 prefix attributes on the declaration. ??? The syntax follows the
3301 old parser in requiring something after label declarations.
3302 Although they are erroneous if the labels declared aren't defined,
3303 is it useful for the syntax to be this way?
3315 c_parser_compound_statement (c_parser *parser)
3318 if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
3320 /* Ensure a scope is entered and left anyway to avoid confusion
3321 if we have just prepared to enter a function body. */
3322 stmt = c_begin_compound_stmt (true);
3323 c_end_compound_stmt (stmt, true);
3324 return error_mark_node;
3326 stmt = c_begin_compound_stmt (true);
3327 c_parser_compound_statement_nostart (parser);
3328 return c_end_compound_stmt (stmt, true);
3331 /* Parse a compound statement except for the opening brace. This is
3332 used for parsing both compound statements and statement expressions
3333 (which follow different paths to handling the opening). */
3336 c_parser_compound_statement_nostart (c_parser *parser)
3338 bool last_stmt = false;
3339 bool last_label = false;
3340 location_t label_loc = UNKNOWN_LOCATION; /* Quiet warning. */
3341 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3343 c_parser_consume_token (parser);
3346 if (c_parser_next_token_is_keyword (parser, RID_LABEL))
3348 location_t err_loc = c_parser_peek_token (parser)->location;
3349 /* Read zero or more forward-declarations for labels that nested
3350 functions can jump to. */
3351 while (c_parser_next_token_is_keyword (parser, RID_LABEL))
3353 c_parser_consume_token (parser);
3354 /* Any identifiers, including those declared as type names,
3359 if (c_parser_next_token_is_not (parser, CPP_NAME))
3361 c_parser_error (parser, "expected identifier");
3365 = declare_label (c_parser_peek_token (parser)->value);
3366 C_DECLARED_LABEL_FLAG (label) = 1;
3367 add_stmt (build_stmt (DECL_EXPR, label));
3368 c_parser_consume_token (parser);
3369 if (c_parser_next_token_is (parser, CPP_COMMA))
3370 c_parser_consume_token (parser);
3374 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
3376 pedwarn (err_loc, OPT_pedantic, "ISO C forbids label declarations");
3378 /* We must now have at least one statement, label or declaration. */
3379 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3381 c_parser_error (parser, "expected declaration or statement");
3382 c_parser_consume_token (parser);
3385 while (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE))
3387 location_t loc = c_parser_peek_token (parser)->location;
3388 if (c_parser_next_token_is_keyword (parser, RID_CASE)
3389 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
3390 || (c_parser_next_token_is (parser, CPP_NAME)
3391 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3393 if (c_parser_next_token_is_keyword (parser, RID_CASE))
3394 label_loc = c_parser_peek_2nd_token (parser)->location;
3396 label_loc = c_parser_peek_token (parser)->location;
3399 c_parser_label (parser);
3401 else if (!last_label
3402 && c_parser_next_token_starts_declspecs (parser))
3405 c_parser_declaration_or_fndef (parser, true, true, true, true);
3408 (pedantic && !flag_isoc99)
3410 : OPT_Wdeclaration_after_statement,
3411 "ISO C90 forbids mixed declarations and code");
3414 else if (!last_label
3415 && c_parser_next_token_is_keyword (parser, RID_EXTENSION))
3417 /* __extension__ can start a declaration, but is also an
3418 unary operator that can start an expression. Consume all
3419 but the last of a possible series of __extension__ to
3421 while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD
3422 && (c_parser_peek_2nd_token (parser)->keyword
3424 c_parser_consume_token (parser);
3425 if (c_token_starts_declspecs (c_parser_peek_2nd_token (parser)))
3428 ext = disable_extension_diagnostics ();
3429 c_parser_consume_token (parser);
3431 c_parser_declaration_or_fndef (parser, true, true, true, true);
3432 /* Following the old parser, __extension__ does not
3433 disable this diagnostic. */
3434 restore_extension_diagnostics (ext);
3436 pedwarn_c90 (loc, (pedantic && !flag_isoc99)
3438 : OPT_Wdeclaration_after_statement,
3439 "ISO C90 forbids mixed declarations and code");
3445 else if (c_parser_next_token_is (parser, CPP_PRAGMA))
3447 /* External pragmas, and some omp pragmas, are not associated
3448 with regular c code, and so are not to be considered statements
3449 syntactically. This ensures that the user doesn't put them
3450 places that would turn into syntax errors if the directive
3452 if (c_parser_pragma (parser, pragma_compound))
3453 last_label = false, last_stmt = true;
3455 else if (c_parser_next_token_is (parser, CPP_EOF))
3457 c_parser_error (parser, "expected declaration or statement");
3460 else if (c_parser_next_token_is_keyword (parser, RID_ELSE))
3462 if (parser->in_if_block)
3464 error_at (loc, """expected %<}%> before %<else%>");
3469 error_at (loc, "%<else%> without a previous %<if%>");
3470 c_parser_consume_token (parser);
3479 c_parser_statement_after_labels (parser);
3482 parser->error = false;
3485 error_at (label_loc, "label at end of compound statement");
3486 c_parser_consume_token (parser);
3489 /* Parse a label (C90 6.6.1, C99 6.8.1).
3492 identifier : attributes[opt]
3493 case constant-expression :
3499 case constant-expression ... constant-expression :
3501 The use of attributes on labels is a GNU extension. The syntax in
3502 GNU C accepts any expressions without commas, non-constant
3503 expressions being rejected later. */
3506 c_parser_label (c_parser *parser)
3508 location_t loc1 = c_parser_peek_token (parser)->location;
3509 tree label = NULL_TREE;
3510 if (c_parser_next_token_is_keyword (parser, RID_CASE))
3513 c_parser_consume_token (parser);
3514 exp1 = c_parser_expr_no_commas (parser, NULL).value;
3515 if (c_parser_next_token_is (parser, CPP_COLON))
3517 c_parser_consume_token (parser);
3518 label = do_case (exp1, NULL_TREE);
3520 else if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
3522 c_parser_consume_token (parser);
3523 exp2 = c_parser_expr_no_commas (parser, NULL).value;
3524 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
3525 label = do_case (exp1, exp2);
3528 c_parser_error (parser, "expected %<:%> or %<...%>");
3530 else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT))
3532 c_parser_consume_token (parser);
3533 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
3534 label = do_case (NULL_TREE, NULL_TREE);
3538 tree name = c_parser_peek_token (parser)->value;
3541 location_t loc2 = c_parser_peek_token (parser)->location;
3542 gcc_assert (c_parser_next_token_is (parser, CPP_NAME));
3543 c_parser_consume_token (parser);
3544 gcc_assert (c_parser_next_token_is (parser, CPP_COLON));
3545 c_parser_consume_token (parser);
3546 attrs = c_parser_attributes (parser);
3547 tlab = define_label (loc2, name);
3550 decl_attributes (&tlab, attrs, 0);
3551 label = add_stmt (build_stmt (LABEL_EXPR, tlab));
3556 SET_EXPR_LOCATION (label, loc1);
3557 if (c_parser_next_token_starts_declspecs (parser)
3558 && !(c_parser_next_token_is (parser, CPP_NAME)
3559 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3561 error_at (c_parser_peek_token (parser)->location,
3562 "a label can only be part of a statement and "
3563 "a declaration is not a statement");
3564 c_parser_declaration_or_fndef (parser, /*fndef_ok*/ false,
3565 /*nested*/ true, /*empty_ok*/ false,
3566 /*start_attr_ok*/ true);
3571 /* Parse a statement (C90 6.6, C99 6.8).
3576 expression-statement
3584 expression-statement:
3587 selection-statement:
3591 iteration-statement:
3600 return expression[opt] ;
3613 objc-throw-statement
3614 objc-try-catch-statement
3615 objc-synchronized-statement
3617 objc-throw-statement:
3631 parallel-for-construct
3632 parallel-sections-construct
3639 parallel-directive structured-block
3642 for-directive iteration-statement
3645 sections-directive section-scope
3648 single-directive structured-block
3650 parallel-for-construct:
3651 parallel-for-directive iteration-statement
3653 parallel-sections-construct:
3654 parallel-sections-directive section-scope
3657 master-directive structured-block
3660 critical-directive structured-block
3663 atomic-directive expression-statement
3666 ordered-directive structured-block */
3669 c_parser_statement (c_parser *parser)
3671 while (c_parser_next_token_is_keyword (parser, RID_CASE)
3672 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
3673 || (c_parser_next_token_is (parser, CPP_NAME)
3674 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3675 c_parser_label (parser);
3676 c_parser_statement_after_labels (parser);
3679 /* Parse a statement, other than a labeled statement. */
3682 c_parser_statement_after_labels (c_parser *parser)
3684 location_t loc = c_parser_peek_token (parser)->location;
3685 tree stmt = NULL_TREE;
3686 bool in_if_block = parser->in_if_block;
3687 parser->in_if_block = false;
3688 switch (c_parser_peek_token (parser)->type)
3690 case CPP_OPEN_BRACE:
3691 add_stmt (c_parser_compound_statement (parser));
3694 switch (c_parser_peek_token (parser)->keyword)
3697 c_parser_if_statement (parser);
3700 c_parser_switch_statement (parser);
3703 c_parser_while_statement (parser);
3706 c_parser_do_statement (parser);
3709 c_parser_for_statement (parser);
3712 c_parser_consume_token (parser);
3713 if (c_parser_next_token_is (parser, CPP_NAME))
3715 stmt = c_finish_goto_label (c_parser_peek_token (parser)->value);
3716 c_parser_consume_token (parser);
3718 else if (c_parser_next_token_is (parser, CPP_MULT))
3720 c_parser_consume_token (parser);
3721 stmt = c_finish_goto_ptr (c_parser_expression (parser).value);
3724 c_parser_error (parser, "expected identifier or %<*%>");
3725 goto expect_semicolon;
3727 c_parser_consume_token (parser);
3728 stmt = c_finish_bc_stmt (&c_cont_label, false);
3729 goto expect_semicolon;
3731 c_parser_consume_token (parser);
3732 stmt = c_finish_bc_stmt (&c_break_label, true);
3733 goto expect_semicolon;
3735 c_parser_consume_token (parser);
3736 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3738 stmt = c_finish_return (NULL_TREE);
3739 c_parser_consume_token (parser);
3743 stmt = c_finish_return (c_parser_expression_conv (parser).value);
3744 goto expect_semicolon;
3748 stmt = c_parser_asm_statement (parser);
3751 gcc_assert (c_dialect_objc ());
3752 c_parser_consume_token (parser);
3753 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3755 stmt = objc_build_throw_stmt (NULL_TREE);
3756 c_parser_consume_token (parser);
3760 tree expr = c_parser_expression (parser).value;
3761 expr = c_fully_fold (expr, false, NULL);
3762 stmt = objc_build_throw_stmt (expr);
3763 goto expect_semicolon;
3767 gcc_assert (c_dialect_objc ());
3768 c_parser_objc_try_catch_statement (parser);
3770 case RID_AT_SYNCHRONIZED:
3771 gcc_assert (c_dialect_objc ());
3772 c_parser_objc_synchronized_statement (parser);
3779 c_parser_consume_token (parser);
3781 case CPP_CLOSE_PAREN:
3782 case CPP_CLOSE_SQUARE:
3783 /* Avoid infinite loop in error recovery:
3784 c_parser_skip_until_found stops at a closing nesting
3785 delimiter without consuming it, but here we need to consume
3786 it to proceed further. */
3787 c_parser_error (parser, "expected statement");
3788 c_parser_consume_token (parser);
3791 c_parser_pragma (parser, pragma_stmt);
3795 stmt = c_finish_expr_stmt (c_parser_expression_conv (parser).value);
3797 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
3800 /* Two cases cannot and do not have line numbers associated: If stmt
3801 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
3802 cannot hold line numbers. But that's OK because the statement
3803 will either be changed to a MODIFY_EXPR during gimplification of
3804 the statement expr, or discarded. If stmt was compound, but
3805 without new variables, we will have skipped the creation of a
3806 BIND and will have a bare STATEMENT_LIST. But that's OK because
3807 (recursively) all of the component statements should already have
3808 line numbers assigned. ??? Can we discard no-op statements
3810 protected_set_expr_location (stmt, loc);
3812 parser->in_if_block = in_if_block;
3815 /* Parse the condition from an if, do, while or for statements. */
3818 c_parser_condition (c_parser *parser)
3822 loc = c_parser_peek_token (parser)->location;
3823 cond = c_parser_expression_conv (parser).value;
3824 cond = c_objc_common_truthvalue_conversion (loc, cond);
3825 cond = c_fully_fold (cond, false, NULL);
3826 protected_set_expr_location (cond, loc);
3827 if (warn_sequence_point)
3828 verify_sequence_points (cond);
3832 /* Parse a parenthesized condition from an if, do or while statement.
3838 c_parser_paren_condition (c_parser *parser)
3841 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3842 return error_mark_node;
3843 cond = c_parser_condition (parser);
3844 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
3848 /* Parse a statement which is a block in C99. */
3851 c_parser_c99_block_statement (c_parser *parser)
3853 tree block = c_begin_compound_stmt (flag_isoc99);
3854 c_parser_statement (parser);
3855 return c_end_compound_stmt (block, flag_isoc99);
3858 /* Parse the body of an if statement. This is just parsing a
3859 statement but (a) it is a block in C99, (b) we track whether the
3860 body is an if statement for the sake of -Wparentheses warnings, (c)
3861 we handle an empty body specially for the sake of -Wempty-body
3862 warnings, and (d) we call parser_compound_statement directly
3863 because c_parser_statement_after_labels resets
3864 parser->in_if_block. */
3867 c_parser_if_body (c_parser *parser, bool *if_p)
3869 tree block = c_begin_compound_stmt (flag_isoc99);
3870 while (c_parser_next_token_is_keyword (parser, RID_CASE)
3871 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
3872 || (c_parser_next_token_is (parser, CPP_NAME)
3873 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3874 c_parser_label (parser);
3875 *if_p = c_parser_next_token_is_keyword (parser, RID_IF);
3876 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3878 location_t loc = c_parser_peek_token (parser)->location;
3879 add_stmt (build_empty_stmt ());
3880 c_parser_consume_token (parser);
3881 if (!c_parser_next_token_is_keyword (parser, RID_ELSE))
3882 warning_at (loc, OPT_Wempty_body,
3883 "suggest braces around empty body in an %<if%> statement");
3885 else if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
3886 add_stmt (c_parser_compound_statement (parser));
3888 c_parser_statement_after_labels (parser);
3889 return c_end_compound_stmt (block, flag_isoc99);
3892 /* Parse the else body of an if statement. This is just parsing a
3893 statement but (a) it is a block in C99, (b) we handle an empty body
3894 specially for the sake of -Wempty-body warnings. */
3897 c_parser_else_body (c_parser *parser)
3899 tree block = c_begin_compound_stmt (flag_isoc99);
3900 while (c_parser_next_token_is_keyword (parser, RID_CASE)
3901 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
3902 || (c_parser_next_token_is (parser, CPP_NAME)
3903 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3904 c_parser_label (parser);
3905 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3907 warning_at (c_parser_peek_token (parser)->location,
3909 "suggest braces around empty body in an %<else%> statement");
3910 add_stmt (build_empty_stmt ());
3911 c_parser_consume_token (parser);
3914 c_parser_statement_after_labels (parser);
3915 return c_end_compound_stmt (block, flag_isoc99);
3918 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
3921 if ( expression ) statement
3922 if ( expression ) statement else statement
3926 c_parser_if_statement (c_parser *parser)
3931 bool first_if = false;
3932 tree first_body, second_body;
3935 gcc_assert (c_parser_next_token_is_keyword (parser, RID_IF));
3936 c_parser_consume_token (parser);
3937 block = c_begin_compound_stmt (flag_isoc99);
3938 loc = c_parser_peek_token (parser)->location;
3939 cond = c_parser_paren_condition (parser);
3940 in_if_block = parser->in_if_block;
3941 parser->in_if_block = true;
3942 first_body = c_parser_if_body (parser, &first_if);
3943 parser->in_if_block = in_if_block;
3944 if (c_parser_next_token_is_keyword (parser, RID_ELSE))
3946 c_parser_consume_token (parser);
3947 second_body = c_parser_else_body (parser);
3950 second_body = NULL_TREE;
3951 c_finish_if_stmt (loc, cond, first_body, second_body, first_if);
3952 add_stmt (c_end_compound_stmt (block, flag_isoc99));
3955 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
3958 switch (expression) statement
3962 c_parser_switch_statement (c_parser *parser)
3964 tree block, expr, body, save_break;
3965 gcc_assert (c_parser_next_token_is_keyword (parser, RID_SWITCH));
3966 c_parser_consume_token (parser);
3967 block = c_begin_compound_stmt (flag_isoc99);
3968 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3970 expr = c_parser_expression (parser).value;
3971 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
3974 expr = error_mark_node;
3975 c_start_case (expr);
3976 save_break = c_break_label;
3977 c_break_label = NULL_TREE;
3978 body = c_parser_c99_block_statement (parser);
3979 c_finish_case (body);
3981 add_stmt (build1 (LABEL_EXPR, void_type_node, c_break_label));
3982 c_break_label = save_break;
3983 add_stmt (c_end_compound_stmt (block, flag_isoc99));
3986 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
3989 while (expression) statement
3993 c_parser_while_statement (c_parser *parser)
3995 tree block, cond, body, save_break, save_cont;
3997 gcc_assert (c_parser_next_token_is_keyword (parser, RID_WHILE));
3998 c_parser_consume_token (parser);
3999 block = c_begin_compound_stmt (flag_isoc99);
4000 loc = c_parser_peek_token (parser)->location;
4001 cond = c_parser_paren_condition (parser);
4002 save_break = c_break_label;
4003 c_break_label = NULL_TREE;
4004 save_cont = c_cont_label;
4005 c_cont_label = NULL_TREE;
4006 body = c_parser_c99_block_statement (parser);
4007 c_finish_loop (loc, cond, NULL, body, c_break_label, c_cont_label, true);
4008 add_stmt (c_end_compound_stmt (block, flag_isoc99));
4009 c_break_label = save_break;
4010 c_cont_label = save_cont;
4013 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
4016 do statement while ( expression ) ;
4020 c_parser_do_statement (c_parser *parser)
4022 tree block, cond, body, save_break, save_cont, new_break, new_cont;
4024 gcc_assert (c_parser_next_token_is_keyword (parser, RID_DO));
4025 c_parser_consume_token (parser);
4026 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4027 warning_at (c_parser_peek_token (parser)->location,
4029 "suggest braces around empty body in %<do%> statement");
4030 block = c_begin_compound_stmt (flag_isoc99);
4031 loc = c_parser_peek_token (parser)->location;
4032 save_break = c_break_label;
4033 c_break_label = NULL_TREE;
4034 save_cont = c_cont_label;
4035 c_cont_label = NULL_TREE;
4036 body = c_parser_c99_block_statement (parser);
4037 c_parser_require_keyword (parser, RID_WHILE, "expected %<while%>");
4038 new_break = c_break_label;
4039 c_break_label = save_break;
4040 new_cont = c_cont_label;
4041 c_cont_label = save_cont;
4042 cond = c_parser_paren_condition (parser);
4043 if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
4044 c_parser_skip_to_end_of_block_or_statement (parser);
4045 c_finish_loop (loc, cond, NULL, body, new_break, new_cont, false);
4046 add_stmt (c_end_compound_stmt (block, flag_isoc99));
4049 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
4052 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
4053 for ( nested-declaration expression[opt] ; expression[opt] ) statement
4055 The form with a declaration is new in C99.
4057 ??? In accordance with the old parser, the declaration may be a
4058 nested function, which is then rejected in check_for_loop_decls,
4059 but does it make any sense for this to be included in the grammar?
4060 Note in particular that the nested function does not include a
4061 trailing ';', whereas the "declaration" production includes one.
4062 Also, can we reject bad declarations earlier and cheaper than
4063 check_for_loop_decls? */
4066 c_parser_for_statement (c_parser *parser)
4068 tree block, cond, incr, save_break, save_cont, body;
4070 gcc_assert (c_parser_next_token_is_keyword (parser, RID_FOR));
4071 loc = c_parser_peek_token (parser)->location;
4072 c_parser_consume_token (parser);
4073 block = c_begin_compound_stmt (flag_isoc99);
4074 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4076 /* Parse the initialization declaration or expression. */
4077 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4079 c_parser_consume_token (parser);
4080 c_finish_expr_stmt (NULL_TREE);
4082 else if (c_parser_next_token_starts_declspecs (parser))
4084 c_parser_declaration_or_fndef (parser, true, true, true, true);
4085 check_for_loop_decls ();
4087 else if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
4089 /* __extension__ can start a declaration, but is also an
4090 unary operator that can start an expression. Consume all
4091 but the last of a possible series of __extension__ to
4093 while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD
4094 && (c_parser_peek_2nd_token (parser)->keyword
4096 c_parser_consume_token (parser);
4097 if (c_token_starts_declspecs (c_parser_peek_2nd_token (parser)))
4100 ext = disable_extension_diagnostics ();
4101 c_parser_consume_token (parser);
4102 c_parser_declaration_or_fndef (parser, true, true, true, true);
4103 restore_extension_diagnostics (ext);
4104 check_for_loop_decls ();
4112 c_finish_expr_stmt (c_parser_expression (parser).value);
4113 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4115 /* Parse the loop condition. */
4116 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4118 c_parser_consume_token (parser);
4123 cond = c_parser_condition (parser);
4124 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4126 /* Parse the increment expression. */
4127 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4128 incr = c_process_expr_stmt (NULL_TREE);
4130 incr = c_process_expr_stmt (c_parser_expression (parser).value);
4131 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4135 cond = error_mark_node;
4136 incr = error_mark_node;
4138 save_break = c_break_label;
4139 c_break_label = NULL_TREE;
4140 save_cont = c_cont_label;
4141 c_cont_label = NULL_TREE;
4142 body = c_parser_c99_block_statement (parser);
4143 c_finish_loop (loc, cond, incr, body, c_break_label, c_cont_label, true);
4144 add_stmt (c_end_compound_stmt (block, flag_isoc99));
4145 c_break_label = save_break;
4146 c_cont_label = save_cont;
4149 /* Parse an asm statement, a GNU extension. This is a full-blown asm
4150 statement with inputs, outputs, clobbers, and volatile tag
4154 asm type-qualifier[opt] ( asm-argument ) ;
4158 asm-string-literal : asm-operands[opt]
4159 asm-string-literal : asm-operands[opt] : asm-operands[opt]
4160 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers
4162 Qualifiers other than volatile are accepted in the syntax but
4166 c_parser_asm_statement (c_parser *parser)
4168 tree quals, str, outputs, inputs, clobbers, ret;
4170 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
4171 c_parser_consume_token (parser);
4172 if (c_parser_next_token_is_keyword (parser, RID_VOLATILE))
4174 quals = c_parser_peek_token (parser)->value;
4175 c_parser_consume_token (parser);
4177 else if (c_parser_next_token_is_keyword (parser, RID_CONST)
4178 || c_parser_next_token_is_keyword (parser, RID_RESTRICT))
4180 warning_at (c_parser_peek_token (parser)->location,
4182 "%E qualifier ignored on asm",
4183 c_parser_peek_token (parser)->value);
4185 c_parser_consume_token (parser);
4189 /* ??? Follow the C++ parser rather than using the
4190 lex_untranslated_string kludge. */
4191 parser->lex_untranslated_string = true;
4192 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4194 parser->lex_untranslated_string = false;
4197 str = c_parser_asm_string_literal (parser);
4198 if (str == NULL_TREE)
4200 parser->lex_untranslated_string = false;
4201 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4204 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4207 outputs = NULL_TREE;
4209 clobbers = NULL_TREE;
4212 if (!c_parser_require (parser, CPP_COLON, "expected %<:%> or %<)%>"))
4214 parser->lex_untranslated_string = false;
4215 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4219 /* Parse outputs. */
4220 if (c_parser_next_token_is (parser, CPP_COLON)
4221 || c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4222 outputs = NULL_TREE;
4224 outputs = c_parser_asm_operands (parser, false);
4225 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4228 clobbers = NULL_TREE;
4231 if (!c_parser_require (parser, CPP_COLON, "expected %<:%> or %<)%>"))
4233 parser->lex_untranslated_string = false;
4234 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4238 if (c_parser_next_token_is (parser, CPP_COLON)
4239 || c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4242 inputs = c_parser_asm_operands (parser, true);
4243 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4245 clobbers = NULL_TREE;
4248 if (!c_parser_require (parser, CPP_COLON, "expected %<:%> or %<)%>"))
4250 parser->lex_untranslated_string = false;
4251 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4254 /* Parse clobbers. */
4255 clobbers = c_parser_asm_clobbers (parser);
4257 parser->lex_untranslated_string = false;
4258 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
4260 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4263 if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
4264 c_parser_skip_to_end_of_block_or_statement (parser);
4265 ret = build_asm_stmt (quals, build_asm_expr (str, outputs, inputs,
4270 /* Parse asm operands, a GNU extension. If CONVERT_P (for inputs but
4271 not outputs), apply the default conversion of functions and arrays
4276 asm-operands , asm-operand
4279 asm-string-literal ( expression )
4280 [ identifier ] asm-string-literal ( expression )
4284 c_parser_asm_operands (c_parser *parser, bool convert_p)
4286 tree list = NULL_TREE;
4291 if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
4293 c_parser_consume_token (parser);
4294 if (c_parser_next_token_is (parser, CPP_NAME))
4296 tree id = c_parser_peek_token (parser)->value;
4297 c_parser_consume_token (parser);
4298 name = build_string (IDENTIFIER_LENGTH (id),
4299 IDENTIFIER_POINTER (id));
4303 c_parser_error (parser, "expected identifier");
4304 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
4307 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
4312 str = c_parser_asm_string_literal (parser);
4313 if (str == NULL_TREE)
4315 parser->lex_untranslated_string = false;
4316 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4318 parser->lex_untranslated_string = true;
4321 expr = c_parser_expression (parser);
4323 expr = default_function_array_conversion (expr);
4324 expr.value = c_fully_fold (expr.value, false, NULL);
4325 parser->lex_untranslated_string = true;
4326 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
4328 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4331 list = chainon (list, build_tree_list (build_tree_list (name, str),
4333 if (c_parser_next_token_is (parser, CPP_COMMA))
4334 c_parser_consume_token (parser);
4341 /* Parse asm clobbers, a GNU extension.
4345 asm-clobbers , asm-string-literal
4349 c_parser_asm_clobbers (c_parser *parser)
4351 tree list = NULL_TREE;
4354 tree str = c_parser_asm_string_literal (parser);
4356 list = tree_cons (NULL_TREE, str, list);
4359 if (c_parser_next_token_is (parser, CPP_COMMA))
4360 c_parser_consume_token (parser);
4367 /* Parse an expression other than a compound expression; that is, an
4368 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
4369 NULL then it is an Objective-C message expression which is the
4370 primary-expression starting the expression as an initializer.
4372 assignment-expression:
4373 conditional-expression
4374 unary-expression assignment-operator assignment-expression
4376 assignment-operator: one of
4377 = *= /= %= += -= <<= >>= &= ^= |=
4379 In GNU C we accept any conditional expression on the LHS and
4380 diagnose the invalid lvalue rather than producing a syntax
4383 static struct c_expr
4384 c_parser_expr_no_commas (c_parser *parser, struct c_expr *after)
4386 struct c_expr lhs, rhs, ret;
4387 enum tree_code code;
4388 location_t op_location;
4389 gcc_assert (!after || c_dialect_objc ());
4390 lhs = c_parser_conditional_expression (parser, after);
4391 op_location = c_parser_peek_token (parser)->location;
4392 switch (c_parser_peek_token (parser)->type)
4401 code = TRUNC_DIV_EXPR;
4404 code = TRUNC_MOD_EXPR;
4419 code = BIT_AND_EXPR;
4422 code = BIT_XOR_EXPR;
4425 code = BIT_IOR_EXPR;
4430 c_parser_consume_token (parser);
4431 rhs = c_parser_expr_no_commas (parser, NULL);
4432 rhs = default_function_array_conversion (rhs);
4433 ret.value = build_modify_expr (op_location, lhs.value, code, rhs.value);
4434 if (code == NOP_EXPR)
4435 ret.original_code = MODIFY_EXPR;
4438 TREE_NO_WARNING (ret.value) = 1;
4439 ret.original_code = ERROR_MARK;
4444 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
4445 is not NULL then it is an Objective-C message expression which is
4446 the primary-expression starting the expression as an initializer.
4448 conditional-expression:
4449 logical-OR-expression
4450 logical-OR-expression ? expression : conditional-expression
4454 conditional-expression:
4455 logical-OR-expression ? : conditional-expression
4458 static struct c_expr
4459 c_parser_conditional_expression (c_parser *parser, struct c_expr *after)
4461 struct c_expr cond, exp1, exp2, ret;
4462 location_t cond_loc;
4464 gcc_assert (!after || c_dialect_objc ());
4466 cond_loc = c_parser_peek_token (parser)->location;
4467 cond = c_parser_binary_expression (parser, after);
4468 protected_set_expr_location (cond.value, cond_loc);
4470 if (c_parser_next_token_is_not (parser, CPP_QUERY))
4472 cond = default_function_array_conversion (cond);
4473 c_parser_consume_token (parser);
4474 if (c_parser_next_token_is (parser, CPP_COLON))
4476 tree eptype = NULL_TREE;
4477 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
4478 "ISO C forbids omitting the middle term of a ?: expression");
4479 if (TREE_CODE (cond.value) == EXCESS_PRECISION_EXPR)
4481 eptype = TREE_TYPE (cond.value);
4482 cond.value = TREE_OPERAND (cond.value, 0);
4484 /* Make sure first operand is calculated only once. */
4485 exp1.value = c_save_expr (default_conversion (cond.value));
4487 exp1.value = build1 (EXCESS_PRECISION_EXPR, eptype, exp1.value);
4488 cond.value = c_objc_common_truthvalue_conversion (cond_loc, exp1.value);
4489 skip_evaluation += cond.value == truthvalue_true_node;
4494 = c_objc_common_truthvalue_conversion
4495 (cond_loc, default_conversion (cond.value));
4496 skip_evaluation += cond.value == truthvalue_false_node;
4497 exp1 = c_parser_expression_conv (parser);
4498 skip_evaluation += ((cond.value == truthvalue_true_node)
4499 - (cond.value == truthvalue_false_node));
4501 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
4503 skip_evaluation -= cond.value == truthvalue_true_node;
4504 ret.value = error_mark_node;
4505 ret.original_code = ERROR_MARK;
4508 exp2 = c_parser_conditional_expression (parser, NULL);
4509 exp2 = default_function_array_conversion (exp2);
4510 skip_evaluation -= cond.value == truthvalue_true_node;
4511 ret.value = build_conditional_expr (cond.value,
4512 cond.original_code == C_MAYBE_CONST_EXPR,
4513 exp1.value, exp2.value);
4514 ret.original_code = ERROR_MARK;
4518 /* Parse a binary expression; that is, a logical-OR-expression (C90
4519 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
4520 an Objective-C message expression which is the primary-expression
4521 starting the expression as an initializer.
4523 multiplicative-expression:
4525 multiplicative-expression * cast-expression
4526 multiplicative-expression / cast-expression
4527 multiplicative-expression % cast-expression
4529 additive-expression:
4530 multiplicative-expression
4531 additive-expression + multiplicative-expression
4532 additive-expression - multiplicative-expression
4536 shift-expression << additive-expression
4537 shift-expression >> additive-expression
4539 relational-expression:
4541 relational-expression < shift-expression
4542 relational-expression > shift-expression
4543 relational-expression <= shift-expression
4544 relational-expression >= shift-expression
4546 equality-expression:
4547 relational-expression
4548 equality-expression == relational-expression
4549 equality-expression != relational-expression
4553 AND-expression & equality-expression
4555 exclusive-OR-expression:
4557 exclusive-OR-expression ^ AND-expression
4559 inclusive-OR-expression:
4560 exclusive-OR-expression
4561 inclusive-OR-expression | exclusive-OR-expression
4563 logical-AND-expression:
4564 inclusive-OR-expression
4565 logical-AND-expression && inclusive-OR-expression
4567 logical-OR-expression:
4568 logical-AND-expression
4569 logical-OR-expression || logical-AND-expression
4572 static struct c_expr
4573 c_parser_binary_expression (c_parser *parser, struct c_expr *after)
4575 /* A binary expression is parsed using operator-precedence parsing,
4576 with the operands being cast expressions. All the binary
4577 operators are left-associative. Thus a binary expression is of
4580 E0 op1 E1 op2 E2 ...
4582 which we represent on a stack. On the stack, the precedence
4583 levels are strictly increasing. When a new operator is
4584 encountered of higher precedence than that at the top of the
4585 stack, it is pushed; its LHS is the top expression, and its RHS
4586 is everything parsed until it is popped. When a new operator is
4587 encountered with precedence less than or equal to that at the top
4588 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
4589 by the result of the operation until the operator at the top of
4590 the stack has lower precedence than the new operator or there is
4591 only one element on the stack; then the top expression is the LHS
4592 of the new operator. In the case of logical AND and OR
4593 expressions, we also need to adjust skip_evaluation as
4594 appropriate when the operators are pushed and popped. */
4596 /* The precedence levels, where 0 is a dummy lowest level used for
4597 the bottom of the stack. */
4613 /* The expression at this stack level. */
4615 /* The precedence of the operator on its left, PREC_NONE at the
4616 bottom of the stack. */
4618 /* The operation on its left. */
4622 /* Location of the binary operator. */
4623 location_t binary_loc = UNKNOWN_LOCATION; /* Quiet warning. */
4626 switch (stack[sp].op) \
4628 case TRUTH_ANDIF_EXPR: \
4629 skip_evaluation -= stack[sp - 1].expr.value == truthvalue_false_node; \
4631 case TRUTH_ORIF_EXPR: \
4632 skip_evaluation -= stack[sp - 1].expr.value == truthvalue_true_node; \
4637 stack[sp - 1].expr \
4638 = default_function_array_conversion (stack[sp - 1].expr); \
4640 = default_function_array_conversion (stack[sp].expr); \
4641 stack[sp - 1].expr = parser_build_binary_op (binary_loc, \
4643 stack[sp - 1].expr, \
4647 gcc_assert (!after || c_dialect_objc ());
4648 stack[0].expr = c_parser_cast_expression (parser, after);
4649 stack[0].prec = PREC_NONE;
4654 enum tree_code ocode;
4657 switch (c_parser_peek_token (parser)->type)
4665 ocode = TRUNC_DIV_EXPR;
4669 ocode = TRUNC_MOD_EXPR;
4681 ocode = LSHIFT_EXPR;
4685 ocode = RSHIFT_EXPR;
4699 case CPP_GREATER_EQ:
4712 oprec = PREC_BITAND;
4713 ocode = BIT_AND_EXPR;
4716 oprec = PREC_BITXOR;
4717 ocode = BIT_XOR_EXPR;
4721 ocode = BIT_IOR_EXPR;
4724 oprec = PREC_LOGAND;
4725 ocode = TRUTH_ANDIF_EXPR;
4729 ocode = TRUTH_ORIF_EXPR;
4732 /* Not a binary operator, so end of the binary
4736 binary_loc = c_parser_peek_token (parser)->location;
4737 c_parser_consume_token (parser);
4738 while (oprec <= stack[sp].prec)
4742 case TRUTH_ANDIF_EXPR:
4744 = default_function_array_conversion (stack[sp].expr);
4745 stack[sp].expr.value = c_objc_common_truthvalue_conversion
4746 (binary_loc, default_conversion (stack[sp].expr.value));
4747 skip_evaluation += stack[sp].expr.value == truthvalue_false_node;
4749 case TRUTH_ORIF_EXPR:
4751 = default_function_array_conversion (stack[sp].expr);
4752 stack[sp].expr.value = c_objc_common_truthvalue_conversion
4753 (binary_loc, default_conversion (stack[sp].expr.value));
4754 skip_evaluation += stack[sp].expr.value == truthvalue_true_node;
4760 stack[sp].expr = c_parser_cast_expression (parser, NULL);
4761 stack[sp].prec = oprec;
4762 stack[sp].op = ocode;
4767 return stack[0].expr;
4771 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
4772 NULL then it is an Objective-C message expression which is the
4773 primary-expression starting the expression as an initializer.
4777 ( type-name ) unary-expression
4780 static struct c_expr
4781 c_parser_cast_expression (c_parser *parser, struct c_expr *after)
4783 gcc_assert (!after || c_dialect_objc ());
4785 return c_parser_postfix_expression_after_primary (parser, *after);
4786 /* If the expression begins with a parenthesized type name, it may
4787 be either a cast or a compound literal; we need to see whether
4788 the next character is '{' to tell the difference. If not, it is
4789 an unary expression. */
4790 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
4791 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
4793 struct c_type_name *type_name;
4796 c_parser_consume_token (parser);
4797 type_name = c_parser_type_name (parser);
4798 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4799 if (type_name == NULL)
4801 ret.value = error_mark_node;
4802 ret.original_code = ERROR_MARK;
4806 /* Save casted types in the function's used types hash table. */
4807 used_types_insert (type_name->specs->type);
4809 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
4810 return c_parser_postfix_expression_after_paren_type (parser,
4812 expr = c_parser_cast_expression (parser, NULL);
4813 expr = default_function_array_conversion (expr);
4814 ret.value = c_cast_expr (type_name, expr.value);
4815 ret.original_code = ERROR_MARK;
4819 return c_parser_unary_expression (parser);
4822 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
4828 unary-operator cast-expression
4829 sizeof unary-expression
4830 sizeof ( type-name )
4832 unary-operator: one of
4838 __alignof__ unary-expression
4839 __alignof__ ( type-name )
4842 unary-operator: one of
4843 __extension__ __real__ __imag__
4845 In addition, the GNU syntax treats ++ and -- as unary operators, so
4846 they may be applied to cast expressions with errors for non-lvalues
4849 static struct c_expr
4850 c_parser_unary_expression (c_parser *parser)
4853 struct c_expr ret, op;
4854 location_t loc = c_parser_peek_token (parser)->location;
4855 switch (c_parser_peek_token (parser)->type)
4858 c_parser_consume_token (parser);
4859 op = c_parser_cast_expression (parser, NULL);
4860 op = default_function_array_conversion (op);
4861 return parser_build_unary_op (PREINCREMENT_EXPR, op, loc);
4862 case CPP_MINUS_MINUS:
4863 c_parser_consume_token (parser);
4864 op = c_parser_cast_expression (parser, NULL);
4865 op = default_function_array_conversion (op);
4866 return parser_build_unary_op (PREDECREMENT_EXPR, op, loc);
4868 c_parser_consume_token (parser);
4869 return parser_build_unary_op (ADDR_EXPR,
4870 c_parser_cast_expression (parser, NULL),
4873 c_parser_consume_token (parser);
4874 op = c_parser_cast_expression (parser, NULL);
4875 op = default_function_array_conversion (op);
4876 ret.value = build_indirect_ref (loc, op.value, "unary *");
4877 ret.original_code = ERROR_MARK;
4880 if (!c_dialect_objc () && !in_system_header)
4881 warning_at (c_parser_peek_token (parser)->location,
4883 "traditional C rejects the unary plus operator");
4884 c_parser_consume_token (parser);
4885 op = c_parser_cast_expression (parser, NULL);
4886 op = default_function_array_conversion (op);
4887 return parser_build_unary_op (CONVERT_EXPR, op, loc);
4889 c_parser_consume_token (parser);
4890 op = c_parser_cast_expression (parser, NULL);
4891 op = default_function_array_conversion (op);
4892 return parser_build_unary_op (NEGATE_EXPR, op, loc);
4894 c_parser_consume_token (parser);
4895 op = c_parser_cast_expression (parser, NULL);
4896 op = default_function_array_conversion (op);
4897 return parser_build_unary_op (BIT_NOT_EXPR, op, loc);
4899 c_parser_consume_token (parser);
4900 op = c_parser_cast_expression (parser, NULL);
4901 op = default_function_array_conversion (op);
4902 return parser_build_unary_op (TRUTH_NOT_EXPR, op, loc);
4904 /* Refer to the address of a label as a pointer. */
4905 c_parser_consume_token (parser);
4906 if (c_parser_next_token_is (parser, CPP_NAME))
4908 ret.value = finish_label_address_expr
4909 (c_parser_peek_token (parser)->value, loc);
4910 c_parser_consume_token (parser);
4914 c_parser_error (parser, "expected identifier");
4915 ret.value = error_mark_node;
4917 ret.original_code = ERROR_MARK;
4920 switch (c_parser_peek_token (parser)->keyword)
4923 return c_parser_sizeof_expression (parser);
4925 return c_parser_alignof_expression (parser);
4927 c_parser_consume_token (parser);
4928 ext = disable_extension_diagnostics ();
4929 ret = c_parser_cast_expression (parser, NULL);
4930 restore_extension_diagnostics (ext);
4933 c_parser_consume_token (parser);
4934 op = c_parser_cast_expression (parser, NULL);
4935 op = default_function_array_conversion (op);
4936 return parser_build_unary_op (REALPART_EXPR, op, loc);
4938 c_parser_consume_token (parser);
4939 op = c_parser_cast_expression (parser, NULL);
4940 op = default_function_array_conversion (op);
4941 return parser_build_unary_op (IMAGPART_EXPR, op, loc);
4943 return c_parser_postfix_expression (parser);
4946 return c_parser_postfix_expression (parser);
4950 /* Parse a sizeof expression. */
4952 static struct c_expr
4953 c_parser_sizeof_expression (c_parser *parser)
4956 location_t expr_loc;
4957 gcc_assert (c_parser_next_token_is_keyword (parser, RID_SIZEOF));
4958 c_parser_consume_token (parser);
4961 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
4962 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
4964 /* Either sizeof ( type-name ) or sizeof unary-expression
4965 starting with a compound literal. */
4966 struct c_type_name *type_name;
4967 c_parser_consume_token (parser);
4968 expr_loc = c_parser_peek_token (parser)->location;
4969 type_name = c_parser_type_name (parser);
4970 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4971 if (type_name == NULL)
4976 ret.value = error_mark_node;
4977 ret.original_code = ERROR_MARK;
4980 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
4982 expr = c_parser_postfix_expression_after_paren_type (parser,
4986 /* sizeof ( type-name ). */
4989 return c_expr_sizeof_type (type_name);
4993 expr_loc = c_parser_peek_token (parser)->location;
4994 expr = c_parser_unary_expression (parser);
4998 if (TREE_CODE (expr.value) == COMPONENT_REF
4999 && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
5000 error_at (expr_loc, "%<sizeof%> applied to a bit-field");
5001 return c_expr_sizeof_expr (expr);
5005 /* Parse an alignof expression. */
5007 static struct c_expr
5008 c_parser_alignof_expression (c_parser *parser)
5011 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ALIGNOF));
5012 c_parser_consume_token (parser);
5015 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
5016 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
5018 /* Either __alignof__ ( type-name ) or __alignof__
5019 unary-expression starting with a compound literal. */
5020 struct c_type_name *type_name;
5022 c_parser_consume_token (parser);
5023 type_name = c_parser_type_name (parser);
5024 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5025 if (type_name == NULL)
5030 ret.value = error_mark_node;
5031 ret.original_code = ERROR_MARK;
5034 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
5036 expr = c_parser_postfix_expression_after_paren_type (parser,
5040 /* alignof ( type-name ). */
5043 ret.value = c_alignof (groktypename (type_name, NULL, NULL));
5044 ret.original_code = ERROR_MARK;
5050 expr = c_parser_unary_expression (parser);
5054 ret.value = c_alignof_expr (expr.value);
5055 ret.original_code = ERROR_MARK;
5060 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
5064 postfix-expression [ expression ]
5065 postfix-expression ( argument-expression-list[opt] )
5066 postfix-expression . identifier
5067 postfix-expression -> identifier
5068 postfix-expression ++
5069 postfix-expression --
5070 ( type-name ) { initializer-list }
5071 ( type-name ) { initializer-list , }
5073 argument-expression-list:
5075 argument-expression-list , argument-expression
5087 (treated as a keyword in GNU C)
5090 ( compound-statement )
5091 __builtin_va_arg ( assignment-expression , type-name )
5092 __builtin_offsetof ( type-name , offsetof-member-designator )
5093 __builtin_choose_expr ( assignment-expression ,
5094 assignment-expression ,
5095 assignment-expression )
5096 __builtin_types_compatible_p ( type-name , type-name )
5098 offsetof-member-designator:
5100 offsetof-member-designator . identifier
5101 offsetof-member-designator [ expression ]
5106 [ objc-receiver objc-message-args ]
5107 @selector ( objc-selector-arg )
5108 @protocol ( identifier )
5109 @encode ( type-name )
5113 static struct c_expr
5114 c_parser_postfix_expression (c_parser *parser)
5116 struct c_expr expr, e1, e2, e3;
5117 struct c_type_name *t1, *t2;
5119 switch (c_parser_peek_token (parser)->type)
5122 expr.value = c_parser_peek_token (parser)->value;
5123 expr.original_code = ERROR_MARK;
5124 loc = c_parser_peek_token (parser)->location;
5125 c_parser_consume_token (parser);
5126 if (TREE_CODE (expr.value) == FIXED_CST
5127 && !targetm.fixed_point_supported_p ())
5129 error_at (loc, "fixed-point types not supported for this target");
5130 expr.value = error_mark_node;
5137 expr.value = c_parser_peek_token (parser)->value;
5138 expr.original_code = ERROR_MARK;
5139 c_parser_consume_token (parser);
5145 expr.value = c_parser_peek_token (parser)->value;
5146 expr.original_code = STRING_CST;
5147 c_parser_consume_token (parser);
5149 case CPP_OBJC_STRING:
5150 gcc_assert (c_dialect_objc ());
5152 = objc_build_string_object (c_parser_peek_token (parser)->value);
5153 expr.original_code = ERROR_MARK;
5154 c_parser_consume_token (parser);
5157 if (c_parser_peek_token (parser)->id_kind != C_ID_ID)
5159 c_parser_error (parser, "expected expression");
5160 expr.value = error_mark_node;
5161 expr.original_code = ERROR_MARK;
5165 tree id = c_parser_peek_token (parser)->value;
5166 location_t loc = c_parser_peek_token (parser)->location;
5167 c_parser_consume_token (parser);
5168 expr.value = build_external_ref (id,
5169 (c_parser_peek_token (parser)->type
5170 == CPP_OPEN_PAREN), loc);
5171 expr.original_code = ERROR_MARK;
5174 case CPP_OPEN_PAREN:
5175 /* A parenthesized expression, statement expression or compound
5177 if (c_parser_peek_2nd_token (parser)->type == CPP_OPEN_BRACE)
5179 /* A statement expression. */
5181 location_t here = c_parser_peek_token (parser)->location;
5182 c_parser_consume_token (parser);
5183 c_parser_consume_token (parser);
5184 if (cur_stmt_list == NULL)
5186 error_at (here, "braced-group within expression allowed "
5187 "only inside a function");
5188 parser->error = true;
5189 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
5190 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5191 expr.value = error_mark_node;
5192 expr.original_code = ERROR_MARK;
5195 stmt = c_begin_stmt_expr ();
5196 c_parser_compound_statement_nostart (parser);
5197 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5199 pedwarn (here, OPT_pedantic,
5200 "ISO C forbids braced-groups within expressions");
5201 expr.value = c_finish_stmt_expr (stmt);
5202 expr.original_code = ERROR_MARK;
5204 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser)))
5206 /* A compound literal. ??? Can we actually get here rather
5207 than going directly to
5208 c_parser_postfix_expression_after_paren_type from
5210 struct c_type_name *type_name;
5211 c_parser_consume_token (parser);
5212 type_name = c_parser_type_name (parser);
5213 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5215 if (type_name == NULL)
5217 expr.value = error_mark_node;
5218 expr.original_code = ERROR_MARK;
5221 expr = c_parser_postfix_expression_after_paren_type (parser,
5226 /* A parenthesized expression. */
5227 c_parser_consume_token (parser);
5228 expr = c_parser_expression (parser);
5229 if (TREE_CODE (expr.value) == MODIFY_EXPR)
5230 TREE_NO_WARNING (expr.value) = 1;
5231 if (expr.original_code != C_MAYBE_CONST_EXPR)
5232 expr.original_code = ERROR_MARK;
5233 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5238 switch (c_parser_peek_token (parser)->keyword)
5240 case RID_FUNCTION_NAME:
5241 case RID_PRETTY_FUNCTION_NAME:
5242 case RID_C99_FUNCTION_NAME:
5243 expr.value = fname_decl (c_parser_peek_token (parser)->location,
5244 c_parser_peek_token (parser)->keyword,
5245 c_parser_peek_token (parser)->value);
5246 expr.original_code = ERROR_MARK;
5247 c_parser_consume_token (parser);
5250 c_parser_consume_token (parser);
5251 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5253 expr.value = error_mark_node;
5254 expr.original_code = ERROR_MARK;
5257 e1 = c_parser_expr_no_commas (parser, NULL);
5258 e1.value = c_fully_fold (e1.value, false, NULL);
5259 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5261 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5262 expr.value = error_mark_node;
5263 expr.original_code = ERROR_MARK;
5266 t1 = c_parser_type_name (parser);
5267 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5271 expr.value = error_mark_node;
5272 expr.original_code = ERROR_MARK;
5276 tree type_expr = NULL_TREE;
5277 expr.value = build_va_arg (e1.value, groktypename (t1,
5282 expr.value = build2 (C_MAYBE_CONST_EXPR,
5283 TREE_TYPE (expr.value), type_expr,
5285 C_MAYBE_CONST_EXPR_NON_CONST (expr.value) = true;
5287 expr.original_code = ERROR_MARK;
5291 c_parser_consume_token (parser);
5292 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5294 expr.value = error_mark_node;
5295 expr.original_code = ERROR_MARK;
5298 t1 = c_parser_type_name (parser);
5301 expr.value = error_mark_node;
5302 expr.original_code = ERROR_MARK;
5305 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5307 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5308 expr.value = error_mark_node;
5309 expr.original_code = ERROR_MARK;
5313 tree type = groktypename (t1, NULL, NULL);
5315 if (type == error_mark_node)
5316 offsetof_ref = error_mark_node;
5318 offsetof_ref = build1 (INDIRECT_REF, type, null_pointer_node);
5319 /* Parse the second argument to __builtin_offsetof. We
5320 must have one identifier, and beyond that we want to
5321 accept sub structure and sub array references. */
5322 if (c_parser_next_token_is (parser, CPP_NAME))
5324 offsetof_ref = build_component_ref
5325 (offsetof_ref, c_parser_peek_token (parser)->value);
5326 c_parser_consume_token (parser);
5327 while (c_parser_next_token_is (parser, CPP_DOT)
5328 || c_parser_next_token_is (parser,
5330 || c_parser_next_token_is (parser,
5333 if (c_parser_next_token_is (parser, CPP_DEREF))
5335 loc = c_parser_peek_token (parser)->location;
5336 offsetof_ref = build_array_ref (offsetof_ref,
5341 else if (c_parser_next_token_is (parser, CPP_DOT))
5344 c_parser_consume_token (parser);
5345 if (c_parser_next_token_is_not (parser,
5348 c_parser_error (parser, "expected identifier");
5351 offsetof_ref = build_component_ref
5353 c_parser_peek_token (parser)->value);
5354 c_parser_consume_token (parser);
5359 loc = c_parser_peek_token (parser)->location;
5360 c_parser_consume_token (parser);
5361 idx = c_parser_expression (parser).value;
5362 idx = c_fully_fold (idx, false, NULL);
5363 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
5365 offsetof_ref = build_array_ref (offsetof_ref, idx, loc);
5370 c_parser_error (parser, "expected identifier");
5371 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5373 expr.value = fold_offsetof (offsetof_ref, NULL_TREE);
5374 expr.original_code = ERROR_MARK;
5377 case RID_CHOOSE_EXPR:
5378 c_parser_consume_token (parser);
5379 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5381 expr.value = error_mark_node;
5382 expr.original_code = ERROR_MARK;
5385 loc = c_parser_peek_token (parser)->location;
5386 e1 = c_parser_expr_no_commas (parser, NULL);
5387 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5389 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5390 expr.value = error_mark_node;
5391 expr.original_code = ERROR_MARK;
5394 e2 = c_parser_expr_no_commas (parser, NULL);
5395 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5397 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5398 expr.value = error_mark_node;
5399 expr.original_code = ERROR_MARK;
5402 e3 = c_parser_expr_no_commas (parser, NULL);
5403 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5409 if (TREE_CODE (c) != INTEGER_CST
5410 || !INTEGRAL_TYPE_P (TREE_TYPE (c)))
5412 "first argument to %<__builtin_choose_expr%> not"
5414 constant_expression_warning (c);
5415 expr = integer_zerop (c) ? e3 : e2;
5418 case RID_TYPES_COMPATIBLE_P:
5419 c_parser_consume_token (parser);
5420 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5422 expr.value = error_mark_node;
5423 expr.original_code = ERROR_MARK;
5426 t1 = c_parser_type_name (parser);
5429 expr.value = error_mark_node;
5430 expr.original_code = ERROR_MARK;
5433 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5435 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5436 expr.value = error_mark_node;
5437 expr.original_code = ERROR_MARK;
5440 t2 = c_parser_type_name (parser);
5443 expr.value = error_mark_node;
5444 expr.original_code = ERROR_MARK;
5447 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5452 e1 = TYPE_MAIN_VARIANT (groktypename (t1, NULL, NULL));
5453 e2 = TYPE_MAIN_VARIANT (groktypename (t2, NULL, NULL));
5455 expr.value = comptypes (e1, e2)
5456 ? build_int_cst (NULL_TREE, 1)
5457 : build_int_cst (NULL_TREE, 0);
5458 expr.original_code = ERROR_MARK;
5461 case RID_AT_SELECTOR:
5462 gcc_assert (c_dialect_objc ());
5463 c_parser_consume_token (parser);
5464 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5466 expr.value = error_mark_node;
5467 expr.original_code = ERROR_MARK;
5471 tree sel = c_parser_objc_selector_arg (parser);
5472 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5474 expr.value = objc_build_selector_expr (sel);
5475 expr.original_code = ERROR_MARK;
5478 case RID_AT_PROTOCOL:
5479 gcc_assert (c_dialect_objc ());
5480 c_parser_consume_token (parser);
5481 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5483 expr.value = error_mark_node;
5484 expr.original_code = ERROR_MARK;
5487 if (c_parser_next_token_is_not (parser, CPP_NAME))
5489 c_parser_error (parser, "expected identifier");
5490 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5491 expr.value = error_mark_node;
5492 expr.original_code = ERROR_MARK;
5496 tree id = c_parser_peek_token (parser)->value;
5497 c_parser_consume_token (parser);
5498 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5500 expr.value = objc_build_protocol_expr (id);
5501 expr.original_code = ERROR_MARK;
5505 /* Extension to support C-structures in the archiver. */
5506 gcc_assert (c_dialect_objc ());
5507 c_parser_consume_token (parser);
5508 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5510 expr.value = error_mark_node;
5511 expr.original_code = ERROR_MARK;
5514 t1 = c_parser_type_name (parser);
5517 expr.value = error_mark_node;
5518 expr.original_code = ERROR_MARK;
5519 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5522 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5525 tree type = groktypename (t1, NULL, NULL);
5526 expr.value = objc_build_encode_expr (type);
5527 expr.original_code = ERROR_MARK;
5531 c_parser_error (parser, "expected expression");
5532 expr.value = error_mark_node;
5533 expr.original_code = ERROR_MARK;
5537 case CPP_OPEN_SQUARE:
5538 if (c_dialect_objc ())
5540 tree receiver, args;
5541 c_parser_consume_token (parser);
5542 receiver = c_parser_objc_receiver (parser);
5543 args = c_parser_objc_message_args (parser);
5544 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
5546 expr.value = objc_build_message_expr (build_tree_list (receiver,
5548 expr.original_code = ERROR_MARK;
5551 /* Else fall through to report error. */
5553 c_parser_error (parser, "expected expression");
5554 expr.value = error_mark_node;
5555 expr.original_code = ERROR_MARK;
5558 return c_parser_postfix_expression_after_primary (parser, expr);
5561 /* Parse a postfix expression after a parenthesized type name: the
5562 brace-enclosed initializer of a compound literal, possibly followed
5563 by some postfix operators. This is separate because it is not
5564 possible to tell until after the type name whether a cast
5565 expression has a cast or a compound literal, or whether the operand
5566 of sizeof is a parenthesized type name or starts with a compound
5569 static struct c_expr
5570 c_parser_postfix_expression_after_paren_type (c_parser *parser,
5571 struct c_type_name *type_name)
5577 location_t start_loc;
5578 tree type_expr = NULL_TREE;
5579 bool type_expr_const = true;
5580 start_init (NULL_TREE, NULL, 0);
5581 type = groktypename (type_name, &type_expr, &type_expr_const);
5582 start_loc = c_parser_peek_token (parser)->location;
5583 if (type != error_mark_node && C_TYPE_VARIABLE_SIZE (type))
5585 error_at (start_loc, "compound literal has variable size");
5586 type = error_mark_node;
5588 init = c_parser_braced_init (parser, type, false);
5590 maybe_warn_string_init (type, init);
5593 pedwarn (start_loc, OPT_pedantic, "ISO C90 forbids compound literals");
5594 non_const = ((init.value && TREE_CODE (init.value) == CONSTRUCTOR)
5595 ? CONSTRUCTOR_NON_CONST (init.value)
5596 : init.original_code == C_MAYBE_CONST_EXPR);
5597 non_const |= !type_expr_const;
5598 expr.value = build_compound_literal (type, init.value, non_const);
5599 expr.original_code = ERROR_MARK;
5602 if (TREE_CODE (expr.value) == C_MAYBE_CONST_EXPR)
5604 gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr.value) == NULL_TREE);
5605 C_MAYBE_CONST_EXPR_PRE (expr.value) = type_expr;
5609 gcc_assert (!non_const);
5610 expr.value = build2 (C_MAYBE_CONST_EXPR, type,
5611 type_expr, expr.value);
5614 return c_parser_postfix_expression_after_primary (parser, expr);
5617 /* Parse a postfix expression after the initial primary or compound
5618 literal; that is, parse a series of postfix operators. */
5620 static struct c_expr
5621 c_parser_postfix_expression_after_primary (c_parser *parser,
5624 struct c_expr orig_expr;
5625 tree ident, idx, exprlist;
5626 location_t loc = c_parser_peek_token (parser)->location;
5629 switch (c_parser_peek_token (parser)->type)
5631 case CPP_OPEN_SQUARE:
5632 /* Array reference. */
5633 loc = c_parser_peek_token (parser)->location;
5634 c_parser_consume_token (parser);
5635 idx = c_parser_expression (parser).value;
5636 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
5638 expr.value = build_array_ref (expr.value, idx, loc);
5639 expr.original_code = ERROR_MARK;
5641 case CPP_OPEN_PAREN:
5642 /* Function call. */
5643 c_parser_consume_token (parser);
5644 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
5645 exprlist = NULL_TREE;
5647 exprlist = c_parser_expr_list (parser, true, false);
5648 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5651 expr.value = build_function_call (expr.value, exprlist);
5652 expr.original_code = ERROR_MARK;
5653 if (TREE_CODE (expr.value) == INTEGER_CST
5654 && TREE_CODE (orig_expr.value) == FUNCTION_DECL
5655 && DECL_BUILT_IN_CLASS (orig_expr.value) == BUILT_IN_NORMAL
5656 && DECL_FUNCTION_CODE (orig_expr.value) == BUILT_IN_CONSTANT_P)
5657 expr.original_code = C_MAYBE_CONST_EXPR;
5660 /* Structure element reference. */
5661 c_parser_consume_token (parser);
5662 expr = default_function_array_conversion (expr);
5663 if (c_parser_next_token_is (parser, CPP_NAME))
5664 ident = c_parser_peek_token (parser)->value;
5667 c_parser_error (parser, "expected identifier");
5668 expr.value = error_mark_node;
5669 expr.original_code = ERROR_MARK;
5672 c_parser_consume_token (parser);
5673 expr.value = build_component_ref (expr.value, ident);
5674 expr.original_code = ERROR_MARK;
5677 /* Structure element reference. */
5678 c_parser_consume_token (parser);
5679 expr = default_function_array_conversion (expr);
5680 if (c_parser_next_token_is (parser, CPP_NAME))
5681 ident = c_parser_peek_token (parser)->value;
5684 c_parser_error (parser, "expected identifier");
5685 expr.value = error_mark_node;
5686 expr.original_code = ERROR_MARK;
5689 c_parser_consume_token (parser);
5690 expr.value = build_component_ref (build_indirect_ref (loc,
5694 expr.original_code = ERROR_MARK;
5697 /* Postincrement. */
5698 c_parser_consume_token (parser);
5699 expr = default_function_array_conversion (expr);
5700 expr.value = build_unary_op (loc,
5701 POSTINCREMENT_EXPR, expr.value, 0);
5702 expr.original_code = ERROR_MARK;
5704 case CPP_MINUS_MINUS:
5705 /* Postdecrement. */
5706 c_parser_consume_token (parser);
5707 expr = default_function_array_conversion (expr);
5708 expr.value = build_unary_op (loc,
5709 POSTDECREMENT_EXPR, expr.value, 0);
5710 expr.original_code = ERROR_MARK;
5718 /* Parse an expression (C90 6.3.17, C99 6.5.17).
5721 assignment-expression
5722 expression , assignment-expression
5725 static struct c_expr
5726 c_parser_expression (c_parser *parser)
5729 expr = c_parser_expr_no_commas (parser, NULL);
5730 while (c_parser_next_token_is (parser, CPP_COMMA))
5733 c_parser_consume_token (parser);
5734 next = c_parser_expr_no_commas (parser, NULL);
5735 next = default_function_array_conversion (next);
5736 expr.value = build_compound_expr (expr.value, next.value);
5737 expr.original_code = COMPOUND_EXPR;
5742 /* Parse an expression and convert functions or arrays to
5745 static struct c_expr
5746 c_parser_expression_conv (c_parser *parser)
5749 expr = c_parser_expression (parser);
5750 expr = default_function_array_conversion (expr);
5754 /* Parse a non-empty list of expressions. If CONVERT_P, convert
5755 functions and arrays to pointers. If FOLD_P, fold the expressions.
5758 assignment-expression
5759 nonempty-expr-list , assignment-expression
5763 c_parser_expr_list (c_parser *parser, bool convert_p, bool fold_p)
5767 expr = c_parser_expr_no_commas (parser, NULL);
5769 expr = default_function_array_conversion (expr);
5771 expr.value = c_fully_fold (expr.value, false, NULL);
5772 ret = cur = build_tree_list (NULL_TREE, expr.value);
5773 while (c_parser_next_token_is (parser, CPP_COMMA))
5775 c_parser_consume_token (parser);
5776 expr = c_parser_expr_no_commas (parser, NULL);
5778 expr = default_function_array_conversion (expr);
5780 expr.value = c_fully_fold (expr.value, false, NULL);
5781 cur = TREE_CHAIN (cur) = build_tree_list (NULL_TREE, expr.value);
5787 /* Parse Objective-C-specific constructs. */
5789 /* Parse an objc-class-definition.
5791 objc-class-definition:
5792 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
5793 objc-class-instance-variables[opt] objc-methodprotolist @end
5794 @implementation identifier objc-superclass[opt]
5795 objc-class-instance-variables[opt]
5796 @interface identifier ( identifier ) objc-protocol-refs[opt]
5797 objc-methodprotolist @end
5798 @implementation identifier ( identifier )
5803 "@interface identifier (" must start "@interface identifier (
5804 identifier ) ...": objc-methodprotolist in the first production may
5805 not start with a parenthesized identifier as a declarator of a data
5806 definition with no declaration specifiers if the objc-superclass,
5807 objc-protocol-refs and objc-class-instance-variables are omitted. */
5810 c_parser_objc_class_definition (c_parser *parser)
5815 if (c_parser_next_token_is_keyword (parser, RID_AT_INTERFACE))
5817 else if (c_parser_next_token_is_keyword (parser, RID_AT_IMPLEMENTATION))
5821 c_parser_consume_token (parser);
5822 if (c_parser_next_token_is_not (parser, CPP_NAME))
5824 c_parser_error (parser, "expected identifier");
5827 id1 = c_parser_peek_token (parser)->value;
5828 c_parser_consume_token (parser);
5829 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
5832 tree proto = NULL_TREE;
5833 c_parser_consume_token (parser);
5834 if (c_parser_next_token_is_not (parser, CPP_NAME))
5836 c_parser_error (parser, "expected identifier");
5837 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5840 id2 = c_parser_peek_token (parser)->value;
5841 c_parser_consume_token (parser);
5842 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5845 objc_start_category_implementation (id1, id2);
5848 if (c_parser_next_token_is (parser, CPP_LESS))
5849 proto = c_parser_objc_protocol_refs (parser);
5850 objc_start_category_interface (id1, id2, proto);
5851 c_parser_objc_methodprotolist (parser);
5852 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
5853 objc_finish_interface ();
5856 if (c_parser_next_token_is (parser, CPP_COLON))
5858 c_parser_consume_token (parser);
5859 if (c_parser_next_token_is_not (parser, CPP_NAME))
5861 c_parser_error (parser, "expected identifier");
5864 superclass = c_parser_peek_token (parser)->value;
5865 c_parser_consume_token (parser);
5868 superclass = NULL_TREE;
5871 tree proto = NULL_TREE;
5872 if (c_parser_next_token_is (parser, CPP_LESS))
5873 proto = c_parser_objc_protocol_refs (parser);
5874 objc_start_class_interface (id1, superclass, proto);
5877 objc_start_class_implementation (id1, superclass);
5878 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
5879 c_parser_objc_class_instance_variables (parser);
5882 objc_continue_interface ();
5883 c_parser_objc_methodprotolist (parser);
5884 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
5885 objc_finish_interface ();
5889 objc_continue_implementation ();
5894 /* Parse objc-class-instance-variables.
5896 objc-class-instance-variables:
5897 { objc-instance-variable-decl-list[opt] }
5899 objc-instance-variable-decl-list:
5900 objc-visibility-spec
5901 objc-instance-variable-decl ;
5903 objc-instance-variable-decl-list objc-visibility-spec
5904 objc-instance-variable-decl-list objc-instance-variable-decl ;
5905 objc-instance-variable-decl-list ;
5907 objc-visibility-spec:
5912 objc-instance-variable-decl:
5917 c_parser_objc_class_instance_variables (c_parser *parser)
5919 gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE));
5920 c_parser_consume_token (parser);
5921 while (c_parser_next_token_is_not (parser, CPP_EOF))
5924 /* Parse any stray semicolon. */
5925 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
5927 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
5928 "extra semicolon in struct or union specified");
5929 c_parser_consume_token (parser);
5932 /* Stop if at the end of the instance variables. */
5933 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
5935 c_parser_consume_token (parser);
5938 /* Parse any objc-visibility-spec. */
5939 if (c_parser_next_token_is_keyword (parser, RID_PRIVATE))
5941 c_parser_consume_token (parser);
5942 objc_set_visibility (2);
5945 else if (c_parser_next_token_is_keyword (parser, RID_PROTECTED))
5947 c_parser_consume_token (parser);
5948 objc_set_visibility (0);
5951 else if (c_parser_next_token_is_keyword (parser, RID_PUBLIC))
5953 c_parser_consume_token (parser);
5954 objc_set_visibility (1);
5957 else if (c_parser_next_token_is (parser, CPP_PRAGMA))
5959 c_parser_pragma (parser, pragma_external);
5963 /* Parse some comma-separated declarations. */
5964 decls = c_parser_struct_declaration (parser);
5966 /* Comma-separated instance variables are chained together in
5967 reverse order; add them one by one. */
5968 tree ivar = nreverse (decls);
5969 for (; ivar; ivar = TREE_CHAIN (ivar))
5970 objc_add_instance_variable (copy_node (ivar));
5972 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
5976 /* Parse an objc-class-declaration.
5978 objc-class-declaration:
5979 @class identifier-list ;
5983 c_parser_objc_class_declaration (c_parser *parser)
5985 tree list = NULL_TREE;
5986 gcc_assert (c_parser_next_token_is_keyword (parser, RID_CLASS));
5987 c_parser_consume_token (parser);
5988 /* Any identifiers, including those declared as type names, are OK
5993 if (c_parser_next_token_is_not (parser, CPP_NAME))
5995 c_parser_error (parser, "expected identifier");
5998 id = c_parser_peek_token (parser)->value;
5999 list = chainon (list, build_tree_list (NULL_TREE, id));
6000 c_parser_consume_token (parser);
6001 if (c_parser_next_token_is (parser, CPP_COMMA))
6002 c_parser_consume_token (parser);
6006 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
6007 objc_declare_class (list);
6010 /* Parse an objc-alias-declaration.
6012 objc-alias-declaration:
6013 @compatibility_alias identifier identifier ;
6017 c_parser_objc_alias_declaration (c_parser *parser)
6020 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_ALIAS));
6021 c_parser_consume_token (parser);
6022 if (c_parser_next_token_is_not (parser, CPP_NAME))
6024 c_parser_error (parser, "expected identifier");
6025 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
6028 id1 = c_parser_peek_token (parser)->value;
6029 c_parser_consume_token (parser);
6030 if (c_parser_next_token_is_not (parser, CPP_NAME))
6032 c_parser_error (parser, "expected identifier");
6033 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
6036 id2 = c_parser_peek_token (parser)->value;
6037 c_parser_consume_token (parser);
6038 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
6039 objc_declare_alias (id1, id2);
6042 /* Parse an objc-protocol-definition.
6044 objc-protocol-definition:
6045 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
6046 @protocol identifier-list ;
6048 "@protocol identifier ;" should be resolved as "@protocol
6049 identifier-list ;": objc-methodprotolist may not start with a
6050 semicolon in the first alternative if objc-protocol-refs are
6054 c_parser_objc_protocol_definition (c_parser *parser)
6056 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_PROTOCOL));
6057 c_parser_consume_token (parser);
6058 if (c_parser_next_token_is_not (parser, CPP_NAME))
6060 c_parser_error (parser, "expected identifier");
6063 if (c_parser_peek_2nd_token (parser)->type == CPP_COMMA
6064 || c_parser_peek_2nd_token (parser)->type == CPP_SEMICOLON)
6066 tree list = NULL_TREE;
6067 /* Any identifiers, including those declared as type names, are
6072 if (c_parser_next_token_is_not (parser, CPP_NAME))
6074 c_parser_error (parser, "expected identifier");
6077 id = c_parser_peek_token (parser)->value;
6078 list = chainon (list, build_tree_list (NULL_TREE, id));
6079 c_parser_consume_token (parser);
6080 if (c_parser_next_token_is (parser, CPP_COMMA))
6081 c_parser_consume_token (parser);
6085 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
6086 objc_declare_protocols (list);
6090 tree id = c_parser_peek_token (parser)->value;
6091 tree proto = NULL_TREE;
6092 c_parser_consume_token (parser);
6093 if (c_parser_next_token_is (parser, CPP_LESS))
6094 proto = c_parser_objc_protocol_refs (parser);
6095 parser->objc_pq_context = true;
6096 objc_start_protocol (id, proto);
6097 c_parser_objc_methodprotolist (parser);
6098 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
6099 parser->objc_pq_context = false;
6100 objc_finish_interface ();
6104 /* Parse an objc-method-type.
6111 static enum tree_code
6112 c_parser_objc_method_type (c_parser *parser)
6114 switch (c_parser_peek_token (parser)->type)
6117 c_parser_consume_token (parser);
6120 c_parser_consume_token (parser);
6127 /* Parse an objc-method-definition.
6129 objc-method-definition:
6130 objc-method-type objc-method-decl ;[opt] compound-statement
6134 c_parser_objc_method_definition (c_parser *parser)
6136 enum tree_code type = c_parser_objc_method_type (parser);
6138 objc_set_method_type (type);
6139 parser->objc_pq_context = true;
6140 decl = c_parser_objc_method_decl (parser);
6141 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
6143 c_parser_consume_token (parser);
6144 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
6145 "extra semicolon in method definition specified");
6147 if (!c_parser_next_token_is (parser, CPP_OPEN_BRACE))
6149 c_parser_error (parser, "expected %<{%>");
6152 parser->objc_pq_context = false;
6153 objc_start_method_definition (decl);
6154 add_stmt (c_parser_compound_statement (parser));
6155 objc_finish_method_definition (current_function_decl);
6158 /* Parse an objc-methodprotolist.
6160 objc-methodprotolist:
6162 objc-methodprotolist objc-methodproto
6163 objc-methodprotolist declaration
6164 objc-methodprotolist ;
6166 The declaration is a data definition, which may be missing
6167 declaration specifiers under the same rules and diagnostics as
6168 other data definitions outside functions, and the stray semicolon
6169 is diagnosed the same way as a stray semicolon outside a
6173 c_parser_objc_methodprotolist (c_parser *parser)
6177 /* The list is terminated by @end. */
6178 switch (c_parser_peek_token (parser)->type)
6181 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
6182 "ISO C does not allow extra %<;%> outside of a function");
6183 c_parser_consume_token (parser);
6187 c_parser_objc_methodproto (parser);
6190 c_parser_pragma (parser, pragma_external);
6195 if (c_parser_next_token_is_keyword (parser, RID_AT_END))
6197 c_parser_declaration_or_fndef (parser, false, true, false, true);
6203 /* Parse an objc-methodproto.
6206 objc-method-type objc-method-decl ;
6210 c_parser_objc_methodproto (c_parser *parser)
6212 enum tree_code type = c_parser_objc_method_type (parser);
6214 objc_set_method_type (type);
6215 /* Remember protocol qualifiers in prototypes. */
6216 parser->objc_pq_context = true;
6217 decl = c_parser_objc_method_decl (parser);
6218 /* Forget protocol qualifiers here. */
6219 parser->objc_pq_context = false;
6220 objc_add_method_declaration (decl);
6221 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
6224 /* Parse an objc-method-decl.
6227 ( objc-type-name ) objc-selector
6229 ( objc-type-name ) objc-keyword-selector objc-optparmlist
6230 objc-keyword-selector objc-optparmlist
6232 objc-keyword-selector:
6234 objc-keyword-selector objc-keyword-decl
6237 objc-selector : ( objc-type-name ) identifier
6238 objc-selector : identifier
6239 : ( objc-type-name ) identifier
6243 objc-optparms objc-optellipsis
6247 objc-opt-parms , parameter-declaration
6255 c_parser_objc_method_decl (c_parser *parser)
6257 tree type = NULL_TREE;
6259 tree parms = NULL_TREE;
6260 bool ellipsis = false;
6262 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
6264 c_parser_consume_token (parser);
6265 type = c_parser_objc_type_name (parser);
6266 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6268 sel = c_parser_objc_selector (parser);
6269 /* If there is no selector, or a colon follows, we have an
6270 objc-keyword-selector. If there is a selector, and a colon does
6271 not follow, that selector ends the objc-method-decl. */
6272 if (!sel || c_parser_next_token_is (parser, CPP_COLON))
6275 tree list = NULL_TREE;
6278 tree atype = NULL_TREE, id, keyworddecl;
6279 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
6281 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
6283 c_parser_consume_token (parser);
6284 atype = c_parser_objc_type_name (parser);
6285 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6288 if (c_parser_next_token_is_not (parser, CPP_NAME))
6290 c_parser_error (parser, "expected identifier");
6291 return error_mark_node;
6293 id = c_parser_peek_token (parser)->value;
6294 c_parser_consume_token (parser);
6295 keyworddecl = objc_build_keyword_decl (tsel, atype, id);
6296 list = chainon (list, keyworddecl);
6297 tsel = c_parser_objc_selector (parser);
6298 if (!tsel && c_parser_next_token_is_not (parser, CPP_COLON))
6301 /* Parse the optional parameter list. Optional Objective-C
6302 method parameters follow the C syntax, and may include '...'
6303 to denote a variable number of arguments. */
6304 parms = make_node (TREE_LIST);
6305 while (c_parser_next_token_is (parser, CPP_COMMA))
6307 struct c_parm *parm;
6308 c_parser_consume_token (parser);
6309 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
6312 c_parser_consume_token (parser);
6315 parm = c_parser_parameter_declaration (parser, NULL_TREE);
6318 parms = chainon (parms,
6319 build_tree_list (NULL_TREE, grokparm (parm)));
6323 return objc_build_method_signature (type, sel, parms, ellipsis);
6326 /* Parse an objc-type-name.
6329 objc-type-qualifiers[opt] type-name
6330 objc-type-qualifiers[opt]
6332 objc-type-qualifiers:
6334 objc-type-qualifiers objc-type-qualifier
6336 objc-type-qualifier: one of
6337 in out inout bycopy byref oneway
6341 c_parser_objc_type_name (c_parser *parser)
6343 tree quals = NULL_TREE;
6344 struct c_type_name *type_name = NULL;
6345 tree type = NULL_TREE;
6348 c_token *token = c_parser_peek_token (parser);
6349 if (token->type == CPP_KEYWORD
6350 && (token->keyword == RID_IN
6351 || token->keyword == RID_OUT
6352 || token->keyword == RID_INOUT
6353 || token->keyword == RID_BYCOPY
6354 || token->keyword == RID_BYREF
6355 || token->keyword == RID_ONEWAY))
6357 quals = chainon (quals, build_tree_list (NULL_TREE, token->value));
6358 c_parser_consume_token (parser);
6363 if (c_parser_next_token_starts_typename (parser))
6364 type_name = c_parser_type_name (parser);
6366 type = groktypename (type_name, NULL, NULL);
6367 return build_tree_list (quals, type);
6370 /* Parse objc-protocol-refs.
6377 c_parser_objc_protocol_refs (c_parser *parser)
6379 tree list = NULL_TREE;
6380 gcc_assert (c_parser_next_token_is (parser, CPP_LESS));
6381 c_parser_consume_token (parser);
6382 /* Any identifiers, including those declared as type names, are OK
6387 if (c_parser_next_token_is_not (parser, CPP_NAME))
6389 c_parser_error (parser, "expected identifier");
6392 id = c_parser_peek_token (parser)->value;
6393 list = chainon (list, build_tree_list (NULL_TREE, id));
6394 c_parser_consume_token (parser);
6395 if (c_parser_next_token_is (parser, CPP_COMMA))
6396 c_parser_consume_token (parser);
6400 c_parser_require (parser, CPP_GREATER, "expected %<>%>");
6404 /* Parse an objc-try-catch-statement.
6406 objc-try-catch-statement:
6407 @try compound-statement objc-catch-list[opt]
6408 @try compound-statement objc-catch-list[opt] @finally compound-statement
6411 @catch ( parameter-declaration ) compound-statement
6412 objc-catch-list @catch ( parameter-declaration ) compound-statement
6416 c_parser_objc_try_catch_statement (c_parser *parser)
6420 gcc_assert (c_parser_next_token_is_keyword (parser, RID_TRY));
6421 c_parser_consume_token (parser);
6422 loc = c_parser_peek_token (parser)->location;
6423 stmt = c_parser_compound_statement (parser);
6424 objc_begin_try_stmt (loc, stmt);
6425 while (c_parser_next_token_is_keyword (parser, RID_CATCH))
6427 struct c_parm *parm;
6428 c_parser_consume_token (parser);
6429 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6431 parm = c_parser_parameter_declaration (parser, NULL_TREE);
6434 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6437 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6438 objc_begin_catch_clause (grokparm (parm));
6439 if (c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
6440 c_parser_compound_statement_nostart (parser);
6441 objc_finish_catch_clause ();
6443 if (c_parser_next_token_is_keyword (parser, RID_AT_FINALLY))
6447 c_parser_consume_token (parser);
6448 finloc = c_parser_peek_token (parser)->location;
6449 finstmt = c_parser_compound_statement (parser);
6450 objc_build_finally_clause (finloc, finstmt);
6452 objc_finish_try_stmt ();
6455 /* Parse an objc-synchronized-statement.
6457 objc-synchronized-statement:
6458 @synchronized ( expression ) compound-statement
6462 c_parser_objc_synchronized_statement (c_parser *parser)
6466 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_SYNCHRONIZED));
6467 c_parser_consume_token (parser);
6468 loc = c_parser_peek_token (parser)->location;
6469 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6471 expr = c_parser_expression (parser).value;
6472 expr = c_fully_fold (expr, false, NULL);
6473 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6476 expr = error_mark_node;
6477 stmt = c_parser_compound_statement (parser);
6478 objc_build_synchronized (loc, expr, stmt);
6481 /* Parse an objc-selector; return NULL_TREE without an error if the
6482 next token is not an objc-selector.
6487 enum struct union if else while do for switch case default
6488 break continue return goto asm sizeof typeof __alignof
6489 unsigned long const short volatile signed restrict _Complex
6490 in out inout bycopy byref oneway int char float double void _Bool
6492 ??? Why this selection of keywords but not, for example, storage
6493 class specifiers? */
6496 c_parser_objc_selector (c_parser *parser)
6498 c_token *token = c_parser_peek_token (parser);
6499 tree value = token->value;
6500 if (token->type == CPP_NAME)
6502 c_parser_consume_token (parser);
6505 if (token->type != CPP_KEYWORD)
6507 switch (token->keyword)
6548 c_parser_consume_token (parser);
6555 /* Parse an objc-selector-arg.
6559 objc-keywordname-list
6561 objc-keywordname-list:
6563 objc-keywordname-list objc-keywordname
6571 c_parser_objc_selector_arg (c_parser *parser)
6573 tree sel = c_parser_objc_selector (parser);
6574 tree list = NULL_TREE;
6575 if (sel && c_parser_next_token_is_not (parser, CPP_COLON))
6579 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
6581 list = chainon (list, build_tree_list (sel, NULL_TREE));
6582 sel = c_parser_objc_selector (parser);
6583 if (!sel && c_parser_next_token_is_not (parser, CPP_COLON))
6589 /* Parse an objc-receiver.
6598 c_parser_objc_receiver (c_parser *parser)
6600 if (c_parser_peek_token (parser)->type == CPP_NAME
6601 && (c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME
6602 || c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME))
6604 tree id = c_parser_peek_token (parser)->value;
6605 c_parser_consume_token (parser);
6606 return objc_get_class_reference (id);
6608 return c_fully_fold (c_parser_expression (parser).value, false, NULL);
6611 /* Parse objc-message-args.
6615 objc-keywordarg-list
6617 objc-keywordarg-list:
6619 objc-keywordarg-list objc-keywordarg
6622 objc-selector : objc-keywordexpr
6627 c_parser_objc_message_args (c_parser *parser)
6629 tree sel = c_parser_objc_selector (parser);
6630 tree list = NULL_TREE;
6631 if (sel && c_parser_next_token_is_not (parser, CPP_COLON))
6636 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
6638 keywordexpr = c_parser_objc_keywordexpr (parser);
6639 list = chainon (list, build_tree_list (sel, keywordexpr));
6640 sel = c_parser_objc_selector (parser);
6641 if (!sel && c_parser_next_token_is_not (parser, CPP_COLON))
6647 /* Parse an objc-keywordexpr.
6654 c_parser_objc_keywordexpr (c_parser *parser)
6656 tree list = c_parser_expr_list (parser, true, true);
6657 if (TREE_CHAIN (list) == NULL_TREE)
6659 /* Just return the expression, remove a level of
6661 return TREE_VALUE (list);
6665 /* We have a comma expression, we will collapse later. */
6671 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
6672 should be considered, statements. ALLOW_STMT is true if we're within
6673 the context of a function and such pragmas are to be allowed. Returns
6674 true if we actually parsed such a pragma. */
6677 c_parser_pragma (c_parser *parser, enum pragma_context context)
6681 id = c_parser_peek_token (parser)->pragma_kind;
6682 gcc_assert (id != PRAGMA_NONE);
6686 case PRAGMA_OMP_BARRIER:
6687 if (context != pragma_compound)
6689 if (context == pragma_stmt)
6690 c_parser_error (parser, "%<#pragma omp barrier%> may only be "
6691 "used in compound statements");
6694 c_parser_omp_barrier (parser);
6697 case PRAGMA_OMP_FLUSH:
6698 if (context != pragma_compound)
6700 if (context == pragma_stmt)
6701 c_parser_error (parser, "%<#pragma omp flush%> may only be "
6702 "used in compound statements");
6705 c_parser_omp_flush (parser);
6708 case PRAGMA_OMP_TASKWAIT:
6709 if (context != pragma_compound)
6711 if (context == pragma_stmt)
6712 c_parser_error (parser, "%<#pragma omp taskwait%> may only be "
6713 "used in compound statements");
6716 c_parser_omp_taskwait (parser);
6719 case PRAGMA_OMP_THREADPRIVATE:
6720 c_parser_omp_threadprivate (parser);
6723 case PRAGMA_OMP_SECTION:
6724 error_at (c_parser_peek_token (parser)->location,
6725 "%<#pragma omp section%> may only be used in "
6726 "%<#pragma omp sections%> construct");
6727 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
6730 case PRAGMA_GCC_PCH_PREPROCESS:
6731 c_parser_error (parser, "%<#pragma GCC pch_preprocess%> must be first");
6732 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
6736 if (id < PRAGMA_FIRST_EXTERNAL)
6738 if (context == pragma_external)
6741 c_parser_error (parser, "expected declaration specifiers");
6742 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
6745 c_parser_omp_construct (parser);
6751 c_parser_consume_pragma (parser);
6752 c_invoke_pragma_handler (id);
6754 /* Skip to EOL, but suppress any error message. Those will have been
6755 generated by the handler routine through calling error, as opposed
6756 to calling c_parser_error. */
6757 parser->error = true;
6758 c_parser_skip_to_pragma_eol (parser);
6763 /* The interface the pragma parsers have to the lexer. */
6766 pragma_lex (tree *value)
6768 c_token *tok = c_parser_peek_token (the_parser);
6769 enum cpp_ttype ret = tok->type;
6771 *value = tok->value;
6772 if (ret == CPP_PRAGMA_EOL || ret == CPP_EOF)
6776 if (ret == CPP_KEYWORD)
6778 c_parser_consume_token (the_parser);
6785 c_parser_pragma_pch_preprocess (c_parser *parser)
6789 c_parser_consume_pragma (parser);
6790 if (c_parser_next_token_is (parser, CPP_STRING))
6792 name = c_parser_peek_token (parser)->value;
6793 c_parser_consume_token (parser);
6796 c_parser_error (parser, "expected string literal");
6797 c_parser_skip_to_pragma_eol (parser);
6800 c_common_pch_pragma (parse_in, TREE_STRING_POINTER (name));
6803 /* OpenMP 2.5 parsing routines. */
6805 /* Returns name of the next clause.
6806 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
6807 the token is not consumed. Otherwise appropriate pragma_omp_clause is
6808 returned and the token is consumed. */
6810 static pragma_omp_clause
6811 c_parser_omp_clause_name (c_parser *parser)
6813 pragma_omp_clause result = PRAGMA_OMP_CLAUSE_NONE;
6815 if (c_parser_next_token_is_keyword (parser, RID_IF))
6816 result = PRAGMA_OMP_CLAUSE_IF;
6817 else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT))
6818 result = PRAGMA_OMP_CLAUSE_DEFAULT;
6819 else if (c_parser_next_token_is (parser, CPP_NAME))
6821 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
6826 if (!strcmp ("collapse", p))
6827 result = PRAGMA_OMP_CLAUSE_COLLAPSE;
6828 else if (!strcmp ("copyin", p))
6829 result = PRAGMA_OMP_CLAUSE_COPYIN;
6830 else if (!strcmp ("copyprivate", p))
6831 result = PRAGMA_OMP_CLAUSE_COPYPRIVATE;
6834 if (!strcmp ("firstprivate", p))
6835 result = PRAGMA_OMP_CLAUSE_FIRSTPRIVATE;
6838 if (!strcmp ("lastprivate", p))
6839 result = PRAGMA_OMP_CLAUSE_LASTPRIVATE;
6842 if (!strcmp ("nowait", p))
6843 result = PRAGMA_OMP_CLAUSE_NOWAIT;
6844 else if (!strcmp ("num_threads", p))
6845 result = PRAGMA_OMP_CLAUSE_NUM_THREADS;
6848 if (!strcmp ("ordered", p))
6849 result = PRAGMA_OMP_CLAUSE_ORDERED;
6852 if (!strcmp ("private", p))
6853 result = PRAGMA_OMP_CLAUSE_PRIVATE;
6856 if (!strcmp ("reduction", p))
6857 result = PRAGMA_OMP_CLAUSE_REDUCTION;
6860 if (!strcmp ("schedule", p))
6861 result = PRAGMA_OMP_CLAUSE_SCHEDULE;
6862 else if (!strcmp ("shared", p))
6863 result = PRAGMA_OMP_CLAUSE_SHARED;
6866 if (!strcmp ("untied", p))
6867 result = PRAGMA_OMP_CLAUSE_UNTIED;
6872 if (result != PRAGMA_OMP_CLAUSE_NONE)
6873 c_parser_consume_token (parser);
6878 /* Validate that a clause of the given type does not already exist. */
6881 check_no_duplicate_clause (tree clauses, enum omp_clause_code code,
6886 for (c = clauses; c ; c = OMP_CLAUSE_CHAIN (c))
6887 if (OMP_CLAUSE_CODE (c) == code)
6889 error ("too many %qs clauses", name);
6897 variable-list , identifier
6899 If KIND is nonzero, create the appropriate node and install the decl
6900 in OMP_CLAUSE_DECL and add the node to the head of the list.
6902 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
6903 return the list created. */
6906 c_parser_omp_variable_list (c_parser *parser, enum omp_clause_code kind,
6909 if (c_parser_next_token_is_not (parser, CPP_NAME)
6910 || c_parser_peek_token (parser)->id_kind != C_ID_ID)
6911 c_parser_error (parser, "expected identifier");
6913 while (c_parser_next_token_is (parser, CPP_NAME)
6914 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
6916 tree t = lookup_name (c_parser_peek_token (parser)->value);
6919 undeclared_variable (c_parser_peek_token (parser)->value,
6920 c_parser_peek_token (parser)->location);
6921 else if (t == error_mark_node)
6925 tree u = build_omp_clause (kind);
6926 OMP_CLAUSE_DECL (u) = t;
6927 OMP_CLAUSE_CHAIN (u) = list;
6931 list = tree_cons (t, NULL_TREE, list);
6933 c_parser_consume_token (parser);
6935 if (c_parser_next_token_is_not (parser, CPP_COMMA))
6938 c_parser_consume_token (parser);
6944 /* Similarly, but expect leading and trailing parenthesis. This is a very
6945 common case for omp clauses. */
6948 c_parser_omp_var_list_parens (c_parser *parser, enum omp_clause_code kind,
6951 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6953 list = c_parser_omp_variable_list (parser, kind, list);
6954 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6960 collapse ( constant-expression ) */
6963 c_parser_omp_clause_collapse (c_parser *parser, tree list)
6965 tree c, num = error_mark_node;
6969 check_no_duplicate_clause (list, OMP_CLAUSE_COLLAPSE, "collapse");
6971 loc = c_parser_peek_token (parser)->location;
6972 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6974 num = c_parser_expr_no_commas (parser, NULL).value;
6975 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6977 if (num == error_mark_node)
6979 if (!INTEGRAL_TYPE_P (TREE_TYPE (num))
6980 || !host_integerp (num, 0)
6981 || (n = tree_low_cst (num, 0)) <= 0
6985 "collapse argument needs positive constant integer expression");
6988 c = build_omp_clause (OMP_CLAUSE_COLLAPSE);
6989 OMP_CLAUSE_COLLAPSE_EXPR (c) = num;
6990 OMP_CLAUSE_CHAIN (c) = list;
6995 copyin ( variable-list ) */
6998 c_parser_omp_clause_copyin (c_parser *parser, tree list)
7000 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYIN, list);
7004 copyprivate ( variable-list ) */
7007 c_parser_omp_clause_copyprivate (c_parser *parser, tree list)
7009 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYPRIVATE, list);
7013 default ( shared | none ) */
7016 c_parser_omp_clause_default (c_parser *parser, tree list)
7018 enum omp_clause_default_kind kind = OMP_CLAUSE_DEFAULT_UNSPECIFIED;
7021 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7023 if (c_parser_next_token_is (parser, CPP_NAME))
7025 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
7030 if (strcmp ("none", p) != 0)
7032 kind = OMP_CLAUSE_DEFAULT_NONE;
7036 if (strcmp ("shared", p) != 0)
7038 kind = OMP_CLAUSE_DEFAULT_SHARED;
7045 c_parser_consume_token (parser);
7050 c_parser_error (parser, "expected %<none%> or %<shared%>");
7052 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7054 if (kind == OMP_CLAUSE_DEFAULT_UNSPECIFIED)
7057 check_no_duplicate_clause (list, OMP_CLAUSE_DEFAULT, "default");
7058 c = build_omp_clause (OMP_CLAUSE_DEFAULT);
7059 OMP_CLAUSE_CHAIN (c) = list;
7060 OMP_CLAUSE_DEFAULT_KIND (c) = kind;
7066 firstprivate ( variable-list ) */
7069 c_parser_omp_clause_firstprivate (c_parser *parser, tree list)
7071 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_FIRSTPRIVATE, list);
7075 if ( expression ) */
7078 c_parser_omp_clause_if (c_parser *parser, tree list)
7080 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
7082 tree t = c_parser_paren_condition (parser);
7085 check_no_duplicate_clause (list, OMP_CLAUSE_IF, "if");
7087 c = build_omp_clause (OMP_CLAUSE_IF);
7088 OMP_CLAUSE_IF_EXPR (c) = t;
7089 OMP_CLAUSE_CHAIN (c) = list;
7093 c_parser_error (parser, "expected %<(%>");
7099 lastprivate ( variable-list ) */
7102 c_parser_omp_clause_lastprivate (c_parser *parser, tree list)
7104 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_LASTPRIVATE, list);
7111 c_parser_omp_clause_nowait (c_parser *parser ATTRIBUTE_UNUSED, tree list)
7115 check_no_duplicate_clause (list, OMP_CLAUSE_NOWAIT, "nowait");
7117 c = build_omp_clause (OMP_CLAUSE_NOWAIT);
7118 OMP_CLAUSE_CHAIN (c) = list;
7123 num_threads ( expression ) */
7126 c_parser_omp_clause_num_threads (c_parser *parser, tree list)
7128 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7130 location_t expr_loc = c_parser_peek_token (parser)->location;
7131 tree c, t = c_parser_expression (parser).value;
7132 t = c_fully_fold (t, false, NULL);
7134 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7136 if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
7138 c_parser_error (parser, "expected integer expression");
7142 /* Attempt to statically determine when the number isn't positive. */
7143 c = fold_build2 (LE_EXPR, boolean_type_node, t,
7144 build_int_cst (TREE_TYPE (t), 0));
7145 if (c == boolean_true_node)
7147 warning_at (expr_loc, 0,
7148 "%<num_threads%> value must be positive");
7149 t = integer_one_node;
7152 check_no_duplicate_clause (list, OMP_CLAUSE_NUM_THREADS, "num_threads");
7154 c = build_omp_clause (OMP_CLAUSE_NUM_THREADS);
7155 OMP_CLAUSE_NUM_THREADS_EXPR (c) = t;
7156 OMP_CLAUSE_CHAIN (c) = list;
7167 c_parser_omp_clause_ordered (c_parser *parser ATTRIBUTE_UNUSED, tree list)
7171 check_no_duplicate_clause (list, OMP_CLAUSE_ORDERED, "ordered");
7173 c = build_omp_clause (OMP_CLAUSE_ORDERED);
7174 OMP_CLAUSE_CHAIN (c) = list;
7179 private ( variable-list ) */
7182 c_parser_omp_clause_private (c_parser *parser, tree list)
7184 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_PRIVATE, list);
7188 reduction ( reduction-operator : variable-list )
7191 One of: + * - & ^ | && || */
7194 c_parser_omp_clause_reduction (c_parser *parser, tree list)
7196 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7198 enum tree_code code;
7200 switch (c_parser_peek_token (parser)->type)
7212 code = BIT_AND_EXPR;
7215 code = BIT_XOR_EXPR;
7218 code = BIT_IOR_EXPR;
7221 code = TRUTH_ANDIF_EXPR;
7224 code = TRUTH_ORIF_EXPR;
7227 c_parser_error (parser,
7228 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
7229 "%<^%>, %<|%>, %<&&%>, or %<||%>");
7230 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0);
7233 c_parser_consume_token (parser);
7234 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
7238 nl = c_parser_omp_variable_list (parser, OMP_CLAUSE_REDUCTION, list);
7239 for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
7240 OMP_CLAUSE_REDUCTION_CODE (c) = code;
7244 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7250 schedule ( schedule-kind )
7251 schedule ( schedule-kind , expression )
7254 static | dynamic | guided | runtime | auto
7258 c_parser_omp_clause_schedule (c_parser *parser, tree list)
7262 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7265 c = build_omp_clause (OMP_CLAUSE_SCHEDULE);
7267 if (c_parser_next_token_is (parser, CPP_NAME))
7269 tree kind = c_parser_peek_token (parser)->value;
7270 const char *p = IDENTIFIER_POINTER (kind);
7275 if (strcmp ("dynamic", p) != 0)
7277 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_DYNAMIC;
7281 if (strcmp ("guided", p) != 0)
7283 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_GUIDED;
7287 if (strcmp ("runtime", p) != 0)
7289 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_RUNTIME;
7296 else if (c_parser_next_token_is_keyword (parser, RID_STATIC))
7297 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_STATIC;
7298 else if (c_parser_next_token_is_keyword (parser, RID_AUTO))
7299 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_AUTO;
7303 c_parser_consume_token (parser);
7304 if (c_parser_next_token_is (parser, CPP_COMMA))
7307 c_parser_consume_token (parser);
7309 here = c_parser_peek_token (parser)->location;
7310 t = c_parser_expr_no_commas (parser, NULL).value;
7311 t = c_fully_fold (t, false, NULL);
7313 if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_RUNTIME)
7314 error_at (here, "schedule %<runtime%> does not take "
7315 "a %<chunk_size%> parameter");
7316 else if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_AUTO)
7318 "schedule %<auto%> does not take "
7319 "a %<chunk_size%> parameter");
7320 else if (TREE_CODE (TREE_TYPE (t)) == INTEGER_TYPE)
7321 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c) = t;
7323 c_parser_error (parser, "expected integer expression");
7325 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7328 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7329 "expected %<,%> or %<)%>");
7331 check_no_duplicate_clause (list, OMP_CLAUSE_SCHEDULE, "schedule");
7332 OMP_CLAUSE_CHAIN (c) = list;
7336 c_parser_error (parser, "invalid schedule kind");
7337 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0);
7342 shared ( variable-list ) */
7345 c_parser_omp_clause_shared (c_parser *parser, tree list)
7347 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_SHARED, list);
7354 c_parser_omp_clause_untied (c_parser *parser ATTRIBUTE_UNUSED, tree list)
7358 /* FIXME: Should we allow duplicates? */
7359 check_no_duplicate_clause (list, OMP_CLAUSE_UNTIED, "untied");
7361 c = build_omp_clause (OMP_CLAUSE_UNTIED);
7362 OMP_CLAUSE_CHAIN (c) = list;
7366 /* Parse all OpenMP clauses. The set clauses allowed by the directive
7367 is a bitmask in MASK. Return the list of clauses found; the result
7368 of clause default goes in *pdefault. */
7371 c_parser_omp_all_clauses (c_parser *parser, unsigned int mask,
7374 tree clauses = NULL;
7377 while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
7380 pragma_omp_clause c_kind;
7382 tree prev = clauses;
7384 if (!first && c_parser_next_token_is (parser, CPP_COMMA))
7385 c_parser_consume_token (parser);
7388 here = c_parser_peek_token (parser)->location;
7389 c_kind = c_parser_omp_clause_name (parser);
7393 case PRAGMA_OMP_CLAUSE_COLLAPSE:
7394 clauses = c_parser_omp_clause_collapse (parser, clauses);
7395 c_name = "collapse";
7397 case PRAGMA_OMP_CLAUSE_COPYIN:
7398 clauses = c_parser_omp_clause_copyin (parser, clauses);
7401 case PRAGMA_OMP_CLAUSE_COPYPRIVATE:
7402 clauses = c_parser_omp_clause_copyprivate (parser, clauses);
7403 c_name = "copyprivate";
7405 case PRAGMA_OMP_CLAUSE_DEFAULT:
7406 clauses = c_parser_omp_clause_default (parser, clauses);
7409 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE:
7410 clauses = c_parser_omp_clause_firstprivate (parser, clauses);
7411 c_name = "firstprivate";
7413 case PRAGMA_OMP_CLAUSE_IF:
7414 clauses = c_parser_omp_clause_if (parser, clauses);
7417 case PRAGMA_OMP_CLAUSE_LASTPRIVATE:
7418 clauses = c_parser_omp_clause_lastprivate (parser, clauses);
7419 c_name = "lastprivate";
7421 case PRAGMA_OMP_CLAUSE_NOWAIT:
7422 clauses = c_parser_omp_clause_nowait (parser, clauses);
7425 case PRAGMA_OMP_CLAUSE_NUM_THREADS:
7426 clauses = c_parser_omp_clause_num_threads (parser, clauses);
7427 c_name = "num_threads";
7429 case PRAGMA_OMP_CLAUSE_ORDERED:
7430 clauses = c_parser_omp_clause_ordered (parser, clauses);
7433 case PRAGMA_OMP_CLAUSE_PRIVATE:
7434 clauses = c_parser_omp_clause_private (parser, clauses);
7437 case PRAGMA_OMP_CLAUSE_REDUCTION:
7438 clauses = c_parser_omp_clause_reduction (parser, clauses);
7439 c_name = "reduction";
7441 case PRAGMA_OMP_CLAUSE_SCHEDULE:
7442 clauses = c_parser_omp_clause_schedule (parser, clauses);
7443 c_name = "schedule";
7445 case PRAGMA_OMP_CLAUSE_SHARED:
7446 clauses = c_parser_omp_clause_shared (parser, clauses);
7449 case PRAGMA_OMP_CLAUSE_UNTIED:
7450 clauses = c_parser_omp_clause_untied (parser, clauses);
7454 c_parser_error (parser, "expected %<#pragma omp%> clause");
7458 if (((mask >> c_kind) & 1) == 0 && !parser->error)
7460 /* Remove the invalid clause(s) from the list to avoid
7461 confusing the rest of the compiler. */
7463 error_at (here, "%qs is not valid for %qs", c_name, where);
7468 c_parser_skip_to_pragma_eol (parser);
7470 return c_finish_omp_clauses (clauses);
7477 In practice, we're also interested in adding the statement to an
7478 outer node. So it is convenient if we work around the fact that
7479 c_parser_statement calls add_stmt. */
7482 c_parser_omp_structured_block (c_parser *parser)
7484 tree stmt = push_stmt_list ();
7485 c_parser_statement (parser);
7486 return pop_stmt_list (stmt);
7490 # pragma omp atomic new-line
7494 x binop= expr | x++ | ++x | x-- | --x
7496 +, *, -, /, &, ^, |, <<, >>
7498 where x is an lvalue expression with scalar type. */
7501 c_parser_omp_atomic (c_parser *parser)
7505 enum tree_code code;
7506 struct c_expr rhs_expr;
7508 c_parser_skip_to_pragma_eol (parser);
7510 lhs = c_parser_unary_expression (parser).value;
7511 lhs = c_fully_fold (lhs, false, NULL);
7512 switch (TREE_CODE (lhs))
7516 c_parser_skip_to_end_of_block_or_statement (parser);
7519 case PREINCREMENT_EXPR:
7520 case POSTINCREMENT_EXPR:
7521 lhs = TREE_OPERAND (lhs, 0);
7523 rhs = integer_one_node;
7526 case PREDECREMENT_EXPR:
7527 case POSTDECREMENT_EXPR:
7528 lhs = TREE_OPERAND (lhs, 0);
7530 rhs = integer_one_node;
7534 switch (c_parser_peek_token (parser)->type)
7540 code = TRUNC_DIV_EXPR;
7555 code = BIT_AND_EXPR;
7558 code = BIT_IOR_EXPR;
7561 code = BIT_XOR_EXPR;
7564 c_parser_error (parser,
7565 "invalid operator for %<#pragma omp atomic%>");
7569 c_parser_consume_token (parser);
7570 rhs_expr = c_parser_expression (parser);
7571 rhs_expr = default_function_array_conversion (rhs_expr);
7572 rhs = rhs_expr.value;
7573 rhs = c_fully_fold (rhs, false, NULL);
7576 stmt = c_finish_omp_atomic (code, lhs, rhs);
7577 if (stmt != error_mark_node)
7579 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7584 # pragma omp barrier new-line
7588 c_parser_omp_barrier (c_parser *parser)
7590 c_parser_consume_pragma (parser);
7591 c_parser_skip_to_pragma_eol (parser);
7593 c_finish_omp_barrier ();
7597 # pragma omp critical [(name)] new-line
7602 c_parser_omp_critical (c_parser *parser)
7604 tree stmt, name = NULL;
7606 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
7608 c_parser_consume_token (parser);
7609 if (c_parser_next_token_is (parser, CPP_NAME))
7611 name = c_parser_peek_token (parser)->value;
7612 c_parser_consume_token (parser);
7613 c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7616 c_parser_error (parser, "expected identifier");
7618 else if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
7619 c_parser_error (parser, "expected %<(%> or end of line");
7620 c_parser_skip_to_pragma_eol (parser);
7622 stmt = c_parser_omp_structured_block (parser);
7623 return c_finish_omp_critical (stmt, name);
7627 # pragma omp flush flush-vars[opt] new-line
7630 ( variable-list ) */
7633 c_parser_omp_flush (c_parser *parser)
7635 c_parser_consume_pragma (parser);
7636 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
7637 c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL);
7638 else if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
7639 c_parser_error (parser, "expected %<(%> or end of line");
7640 c_parser_skip_to_pragma_eol (parser);
7642 c_finish_omp_flush ();
7645 /* Parse the restricted form of the for statement allowed by OpenMP.
7646 The real trick here is to determine the loop control variable early
7647 so that we can push a new decl if necessary to make it private. */
7650 c_parser_omp_for_loop (c_parser *parser, tree clauses, tree *par_clauses)
7652 tree decl, cond, incr, save_break, save_cont, body, init, stmt, cl;
7653 tree declv, condv, incrv, initv, for_block = NULL, ret = NULL;
7655 bool fail = false, open_brace_parsed = false;
7656 int i, collapse = 1, nbraces = 0;
7658 for (cl = clauses; cl; cl = OMP_CLAUSE_CHAIN (cl))
7659 if (OMP_CLAUSE_CODE (cl) == OMP_CLAUSE_COLLAPSE)
7660 collapse = tree_low_cst (OMP_CLAUSE_COLLAPSE_EXPR (cl), 0);
7662 gcc_assert (collapse >= 1);
7664 declv = make_tree_vec (collapse);
7665 initv = make_tree_vec (collapse);
7666 condv = make_tree_vec (collapse);
7667 incrv = make_tree_vec (collapse);
7669 if (!c_parser_next_token_is_keyword (parser, RID_FOR))
7671 c_parser_error (parser, "for statement expected");
7674 loc = c_parser_peek_token (parser)->location;
7675 c_parser_consume_token (parser);
7677 for (i = 0; i < collapse; i++)
7681 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7684 /* Parse the initialization declaration or expression. */
7685 if (c_parser_next_token_starts_declspecs (parser))
7689 = tree_cons (NULL, c_begin_compound_stmt (true), for_block);
7690 c_parser_declaration_or_fndef (parser, true, true, true, true);
7691 decl = check_for_loop_decls ();
7694 if (DECL_INITIAL (decl) == error_mark_node)
7695 decl = error_mark_node;
7698 else if (c_parser_next_token_is (parser, CPP_NAME)
7699 && c_parser_peek_2nd_token (parser)->type == CPP_EQ)
7701 struct c_expr init_exp;
7702 location_t init_loc;
7704 decl = c_parser_postfix_expression (parser).value;
7706 c_parser_require (parser, CPP_EQ, "expected %<=%>");
7707 init_loc = c_parser_peek_token (parser)->location;
7709 init_exp = c_parser_expr_no_commas (parser, NULL);
7710 init_exp = default_function_array_conversion (init_exp);
7711 init = build_modify_expr (init_loc,
7712 decl, NOP_EXPR, init_exp.value);
7713 init = c_process_expr_stmt (init);
7715 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7720 c_parser_error (parser,
7721 "expected iteration declaration or initialization");
7722 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7728 /* Parse the loop condition. */
7730 if (c_parser_next_token_is_not (parser, CPP_SEMICOLON))
7732 location_t cond_loc = c_parser_peek_token (parser)->location;
7733 struct c_expr cond_expr = c_parser_binary_expression (parser, NULL);
7735 cond = cond_expr.value;
7736 cond = c_objc_common_truthvalue_conversion (cond_loc, cond);
7737 cond = c_fully_fold (cond, false, NULL);
7738 switch (cond_expr.original_code)
7746 /* Can't be cond = error_mark_node, because we want to preserve
7747 the location until c_finish_omp_for. */
7748 cond = build1 (NOP_EXPR, boolean_type_node, error_mark_node);
7751 protected_set_expr_location (cond, cond_loc);
7753 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7755 /* Parse the increment expression. */
7757 if (c_parser_next_token_is_not (parser, CPP_CLOSE_PAREN))
7759 location_t incr_loc = c_parser_peek_token (parser)->location;
7761 incr = c_process_expr_stmt (c_parser_expression (parser).value);
7762 protected_set_expr_location (incr, incr_loc);
7764 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7766 if (decl == NULL || decl == error_mark_node || init == error_mark_node)
7770 TREE_VEC_ELT (declv, i) = decl;
7771 TREE_VEC_ELT (initv, i) = init;
7772 TREE_VEC_ELT (condv, i) = cond;
7773 TREE_VEC_ELT (incrv, i) = incr;
7777 if (i == collapse - 1)
7780 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
7781 in between the collapsed for loops to be still considered perfectly
7782 nested. Hopefully the final version clarifies this.
7783 For now handle (multiple) {'s and empty statements. */
7786 if (c_parser_next_token_is_keyword (parser, RID_FOR))
7788 c_parser_consume_token (parser);
7791 else if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
7793 c_parser_consume_token (parser);
7797 && c_parser_next_token_is (parser, CPP_SEMICOLON))
7798 c_parser_consume_token (parser);
7801 c_parser_error (parser, "not enough perfectly nested loops");
7804 open_brace_parsed = true;
7814 nbraces += bracecount;
7817 save_break = c_break_label;
7818 c_break_label = size_one_node;
7819 save_cont = c_cont_label;
7820 c_cont_label = NULL_TREE;
7821 body = push_stmt_list ();
7823 if (open_brace_parsed)
7825 stmt = c_begin_compound_stmt (true);
7826 c_parser_compound_statement_nostart (parser);
7827 add_stmt (c_end_compound_stmt (stmt, true));
7830 add_stmt (c_parser_c99_block_statement (parser));
7832 add_stmt (build1 (LABEL_EXPR, void_type_node, c_cont_label));
7834 body = pop_stmt_list (body);
7835 c_break_label = save_break;
7836 c_cont_label = save_cont;
7840 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
7842 c_parser_consume_token (parser);
7845 else if (c_parser_next_token_is (parser, CPP_SEMICOLON))
7846 c_parser_consume_token (parser);
7849 c_parser_error (parser, "collapsed loops not perfectly nested");
7852 stmt = c_begin_compound_stmt (true);
7854 c_parser_compound_statement_nostart (parser);
7855 body = c_end_compound_stmt (stmt, true);
7862 /* Only bother calling c_finish_omp_for if we haven't already generated
7863 an error from the initialization parsing. */
7866 stmt = c_finish_omp_for (loc, declv, initv, condv, incrv, body, NULL);
7869 if (par_clauses != NULL)
7872 for (c = par_clauses; *c ; )
7873 if (OMP_CLAUSE_CODE (*c) != OMP_CLAUSE_FIRSTPRIVATE
7874 && OMP_CLAUSE_CODE (*c) != OMP_CLAUSE_LASTPRIVATE)
7875 c = &OMP_CLAUSE_CHAIN (*c);
7878 for (i = 0; i < collapse; i++)
7879 if (TREE_VEC_ELT (declv, i) == OMP_CLAUSE_DECL (*c))
7882 c = &OMP_CLAUSE_CHAIN (*c);
7883 else if (OMP_CLAUSE_CODE (*c) == OMP_CLAUSE_FIRSTPRIVATE)
7886 "iteration variable %qD should not be firstprivate",
7887 OMP_CLAUSE_DECL (*c));
7888 *c = OMP_CLAUSE_CHAIN (*c);
7892 /* Copy lastprivate (decl) clause to OMP_FOR_CLAUSES,
7893 change it to shared (decl) in
7894 OMP_PARALLEL_CLAUSES. */
7895 tree l = build_omp_clause (OMP_CLAUSE_LASTPRIVATE);
7896 OMP_CLAUSE_DECL (l) = OMP_CLAUSE_DECL (*c);
7897 OMP_CLAUSE_CHAIN (l) = clauses;
7899 OMP_CLAUSE_SET_CODE (*c, OMP_CLAUSE_SHARED);
7903 OMP_FOR_CLAUSES (stmt) = clauses;
7910 stmt = c_end_compound_stmt (TREE_VALUE (for_block), true);
7912 for_block = TREE_CHAIN (for_block);
7918 #pragma omp for for-clause[optseq] new-line
7922 #define OMP_FOR_CLAUSE_MASK \
7923 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
7924 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
7925 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
7926 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
7927 | (1u << PRAGMA_OMP_CLAUSE_ORDERED) \
7928 | (1u << PRAGMA_OMP_CLAUSE_SCHEDULE) \
7929 | (1u << PRAGMA_OMP_CLAUSE_COLLAPSE) \
7930 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
7933 c_parser_omp_for (c_parser *parser)
7935 tree block, clauses, ret;
7937 clauses = c_parser_omp_all_clauses (parser, OMP_FOR_CLAUSE_MASK,
7940 block = c_begin_compound_stmt (true);
7941 ret = c_parser_omp_for_loop (parser, clauses, NULL);
7942 block = c_end_compound_stmt (block, true);
7949 # pragma omp master new-line
7954 c_parser_omp_master (c_parser *parser)
7956 c_parser_skip_to_pragma_eol (parser);
7957 return c_finish_omp_master (c_parser_omp_structured_block (parser));
7961 # pragma omp ordered new-line
7966 c_parser_omp_ordered (c_parser *parser)
7968 c_parser_skip_to_pragma_eol (parser);
7969 return c_finish_omp_ordered (c_parser_omp_structured_block (parser));
7975 { section-sequence }
7978 section-directive[opt] structured-block
7979 section-sequence section-directive structured-block */
7982 c_parser_omp_sections_scope (c_parser *parser)
7985 bool error_suppress = false;
7988 if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
7990 /* Avoid skipping until the end of the block. */
7991 parser->error = false;
7995 stmt = push_stmt_list ();
7997 loc = c_parser_peek_token (parser)->location;
7998 if (c_parser_peek_token (parser)->pragma_kind != PRAGMA_OMP_SECTION)
8000 substmt = push_stmt_list ();
8004 c_parser_statement (parser);
8006 if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_OMP_SECTION)
8008 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
8010 if (c_parser_next_token_is (parser, CPP_EOF))
8014 substmt = pop_stmt_list (substmt);
8015 substmt = build1 (OMP_SECTION, void_type_node, substmt);
8016 SET_EXPR_LOCATION (substmt, loc);
8022 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
8024 if (c_parser_next_token_is (parser, CPP_EOF))
8027 loc = c_parser_peek_token (parser)->location;
8028 if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_OMP_SECTION)
8030 c_parser_consume_pragma (parser);
8031 c_parser_skip_to_pragma_eol (parser);
8032 error_suppress = false;
8034 else if (!error_suppress)
8036 error_at (loc, "expected %<#pragma omp section%> or %<}%>");
8037 error_suppress = true;
8040 substmt = c_parser_omp_structured_block (parser);
8041 substmt = build1 (OMP_SECTION, void_type_node, substmt);
8042 SET_EXPR_LOCATION (substmt, loc);
8045 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE,
8046 "expected %<#pragma omp section%> or %<}%>");
8048 substmt = pop_stmt_list (stmt);
8050 stmt = make_node (OMP_SECTIONS);
8051 TREE_TYPE (stmt) = void_type_node;
8052 OMP_SECTIONS_BODY (stmt) = substmt;
8054 return add_stmt (stmt);
8058 # pragma omp sections sections-clause[optseq] newline
8062 #define OMP_SECTIONS_CLAUSE_MASK \
8063 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8064 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8065 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
8066 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
8067 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
8070 c_parser_omp_sections (c_parser *parser)
8072 tree block, clauses, ret;
8074 clauses = c_parser_omp_all_clauses (parser, OMP_SECTIONS_CLAUSE_MASK,
8075 "#pragma omp sections");
8077 block = c_begin_compound_stmt (true);
8078 ret = c_parser_omp_sections_scope (parser);
8080 OMP_SECTIONS_CLAUSES (ret) = clauses;
8081 block = c_end_compound_stmt (block, true);
8088 # pragma parallel parallel-clause new-line
8089 # pragma parallel for parallel-for-clause new-line
8090 # pragma parallel sections parallel-sections-clause new-line
8093 #define OMP_PARALLEL_CLAUSE_MASK \
8094 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
8095 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8096 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8097 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
8098 | (1u << PRAGMA_OMP_CLAUSE_SHARED) \
8099 | (1u << PRAGMA_OMP_CLAUSE_COPYIN) \
8100 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
8101 | (1u << PRAGMA_OMP_CLAUSE_NUM_THREADS))
8104 c_parser_omp_parallel (c_parser *parser)
8106 enum pragma_kind p_kind = PRAGMA_OMP_PARALLEL;
8107 const char *p_name = "#pragma omp parallel";
8108 tree stmt, clauses, par_clause, ws_clause, block;
8109 unsigned int mask = OMP_PARALLEL_CLAUSE_MASK;
8111 if (c_parser_next_token_is_keyword (parser, RID_FOR))
8113 c_parser_consume_token (parser);
8114 p_kind = PRAGMA_OMP_PARALLEL_FOR;
8115 p_name = "#pragma omp parallel for";
8116 mask |= OMP_FOR_CLAUSE_MASK;
8117 mask &= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT);
8119 else if (c_parser_next_token_is (parser, CPP_NAME))
8121 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
8122 if (strcmp (p, "sections") == 0)
8124 c_parser_consume_token (parser);
8125 p_kind = PRAGMA_OMP_PARALLEL_SECTIONS;
8126 p_name = "#pragma omp parallel sections";
8127 mask |= OMP_SECTIONS_CLAUSE_MASK;
8128 mask &= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT);
8132 clauses = c_parser_omp_all_clauses (parser, mask, p_name);
8136 case PRAGMA_OMP_PARALLEL:
8137 block = c_begin_omp_parallel ();
8138 c_parser_statement (parser);
8139 stmt = c_finish_omp_parallel (clauses, block);
8142 case PRAGMA_OMP_PARALLEL_FOR:
8143 block = c_begin_omp_parallel ();
8144 c_split_parallel_clauses (clauses, &par_clause, &ws_clause);
8145 c_parser_omp_for_loop (parser, ws_clause, &par_clause);
8146 stmt = c_finish_omp_parallel (par_clause, block);
8147 OMP_PARALLEL_COMBINED (stmt) = 1;
8150 case PRAGMA_OMP_PARALLEL_SECTIONS:
8151 block = c_begin_omp_parallel ();
8152 c_split_parallel_clauses (clauses, &par_clause, &ws_clause);
8153 stmt = c_parser_omp_sections_scope (parser);
8155 OMP_SECTIONS_CLAUSES (stmt) = ws_clause;
8156 stmt = c_finish_omp_parallel (par_clause, block);
8157 OMP_PARALLEL_COMBINED (stmt) = 1;
8168 # pragma omp single single-clause[optseq] new-line
8172 #define OMP_SINGLE_CLAUSE_MASK \
8173 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8174 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8175 | (1u << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
8176 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
8179 c_parser_omp_single (c_parser *parser)
8181 tree stmt = make_node (OMP_SINGLE);
8182 TREE_TYPE (stmt) = void_type_node;
8184 OMP_SINGLE_CLAUSES (stmt)
8185 = c_parser_omp_all_clauses (parser, OMP_SINGLE_CLAUSE_MASK,
8186 "#pragma omp single");
8187 OMP_SINGLE_BODY (stmt) = c_parser_omp_structured_block (parser);
8189 return add_stmt (stmt);
8193 # pragma omp task task-clause[optseq] new-line
8196 #define OMP_TASK_CLAUSE_MASK \
8197 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
8198 | (1u << PRAGMA_OMP_CLAUSE_UNTIED) \
8199 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
8200 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8201 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8202 | (1u << PRAGMA_OMP_CLAUSE_SHARED))
8205 c_parser_omp_task (c_parser *parser)
8207 tree clauses, block;
8209 clauses = c_parser_omp_all_clauses (parser, OMP_TASK_CLAUSE_MASK,
8210 "#pragma omp task");
8212 block = c_begin_omp_task ();
8213 c_parser_statement (parser);
8214 return c_finish_omp_task (clauses, block);
8218 # pragma omp taskwait new-line
8222 c_parser_omp_taskwait (c_parser *parser)
8224 c_parser_consume_pragma (parser);
8225 c_parser_skip_to_pragma_eol (parser);
8227 c_finish_omp_taskwait ();
8230 /* Main entry point to parsing most OpenMP pragmas. */
8233 c_parser_omp_construct (c_parser *parser)
8235 enum pragma_kind p_kind;
8239 loc = c_parser_peek_token (parser)->location;
8240 p_kind = c_parser_peek_token (parser)->pragma_kind;
8241 c_parser_consume_pragma (parser);
8243 /* For all constructs below except #pragma omp atomic
8244 MUST_NOT_THROW catch handlers are needed when exceptions
8246 if (p_kind != PRAGMA_OMP_ATOMIC)
8247 c_maybe_initialize_eh ();
8251 case PRAGMA_OMP_ATOMIC:
8252 c_parser_omp_atomic (parser);
8254 case PRAGMA_OMP_CRITICAL:
8255 stmt = c_parser_omp_critical (parser);
8257 case PRAGMA_OMP_FOR:
8258 stmt = c_parser_omp_for (parser);
8260 case PRAGMA_OMP_MASTER:
8261 stmt = c_parser_omp_master (parser);
8263 case PRAGMA_OMP_ORDERED:
8264 stmt = c_parser_omp_ordered (parser);
8266 case PRAGMA_OMP_PARALLEL:
8267 stmt = c_parser_omp_parallel (parser);
8269 case PRAGMA_OMP_SECTIONS:
8270 stmt = c_parser_omp_sections (parser);
8272 case PRAGMA_OMP_SINGLE:
8273 stmt = c_parser_omp_single (parser);
8275 case PRAGMA_OMP_TASK:
8276 stmt = c_parser_omp_task (parser);
8283 SET_EXPR_LOCATION (stmt, loc);
8288 # pragma omp threadprivate (variable-list) */
8291 c_parser_omp_threadprivate (c_parser *parser)
8295 c_parser_consume_pragma (parser);
8296 vars = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL);
8298 /* Mark every variable in VARS to be assigned thread local storage. */
8299 for (t = vars; t; t = TREE_CHAIN (t))
8301 tree v = TREE_PURPOSE (t);
8303 /* If V had already been marked threadprivate, it doesn't matter
8304 whether it had been used prior to this point. */
8305 if (TREE_CODE (v) != VAR_DECL)
8306 error ("%qD is not a variable", v);
8307 else if (TREE_USED (v) && !C_DECL_THREADPRIVATE_P (v))
8308 error ("%qE declared %<threadprivate%> after first use", v);
8309 else if (! TREE_STATIC (v) && ! DECL_EXTERNAL (v))
8310 error ("automatic variable %qE cannot be %<threadprivate%>", v);
8311 else if (TREE_TYPE (v) == error_mark_node)
8313 else if (! COMPLETE_TYPE_P (TREE_TYPE (v)))
8314 error ("%<threadprivate%> %qE has incomplete type", v);
8317 if (! DECL_THREAD_LOCAL_P (v))
8319 DECL_TLS_MODEL (v) = decl_default_tls_model (v);
8320 /* If rtl has been already set for this var, call
8321 make_decl_rtl once again, so that encode_section_info
8322 has a chance to look at the new decl flags. */
8323 if (DECL_RTL_SET_P (v))
8326 C_DECL_THREADPRIVATE_P (v) = 1;
8330 c_parser_skip_to_pragma_eol (parser);
8334 /* Parse a single source file. */
8339 /* Use local storage to begin. If the first token is a pragma, parse it.
8340 If it is #pragma GCC pch_preprocess, then this will load a PCH file
8341 which will cause garbage collection. */
8344 memset (&tparser, 0, sizeof tparser);
8345 the_parser = &tparser;
8347 if (c_parser_peek_token (&tparser)->pragma_kind == PRAGMA_GCC_PCH_PREPROCESS)
8348 c_parser_pragma_pch_preprocess (&tparser);
8350 the_parser = GGC_NEW (c_parser);
8351 *the_parser = tparser;
8353 c_parser_translation_unit (the_parser);
8357 #include "gt-c-parser.h"