1 /* Parser for C and Objective-C.
2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009
4 Free Software Foundation, Inc.
6 Parser actions based on the old Bison parser; structure somewhat
7 influenced by and fragments based on the C++ parser.
9 This file is part of GCC.
11 GCC is free software; you can redistribute it and/or modify it under
12 the terms of the GNU General Public License as published by the Free
13 Software Foundation; either version 3, or (at your option) any later
16 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
17 WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with GCC; see the file COPYING3. If not see
23 <http://www.gnu.org/licenses/>. */
27 Make sure all relevant comments, and all relevant code from all
28 actions, brought over from old parser. Verify exact correspondence
31 Add testcases covering every input symbol in every state in old and
34 Include full syntax for GNU C, including erroneous cases accepted
35 with error messages, in syntax productions in comments.
37 Make more diagnostics in the front end generally take an explicit
38 location rather than implicitly using input_location. */
42 #include "coretypes.h"
46 #include "langhooks.h"
62 /* Initialization routine for this file. */
67 /* The only initialization required is of the reserved word
78 mask |= D_ASM | D_EXT;
82 if (!c_dialect_objc ())
83 mask |= D_OBJC | D_CXX_OBJC;
85 ridpointers = GGC_CNEWVEC (tree, (int) RID_MAX);
86 for (i = 0; i < num_c_common_reswords; i++)
88 /* If a keyword is disabled, do not enter it into the table
89 and so create a canonical spelling that isn't a keyword. */
90 if (c_common_reswords[i].disable & mask)
93 && (c_common_reswords[i].disable & D_CXXWARN))
95 id = get_identifier (c_common_reswords[i].word);
96 C_SET_RID_CODE (id, RID_CXX_COMPAT_WARN);
97 C_IS_RESERVED_WORD (id) = 1;
102 id = get_identifier (c_common_reswords[i].word);
103 C_SET_RID_CODE (id, c_common_reswords[i].rid);
104 C_IS_RESERVED_WORD (id) = 1;
105 ridpointers [(int) c_common_reswords[i].rid] = id;
109 /* The C lexer intermediates between the lexer in cpplib and c-lex.c
110 and the C parser. Unlike the C++ lexer, the parser structure
111 stores the lexer information instead of using a separate structure.
112 Identifiers are separated into ordinary identifiers, type names,
113 keywords and some other Objective-C types of identifiers, and some
114 look-ahead is maintained.
116 ??? It might be a good idea to lex the whole file up front (as for
117 C++). It would then be possible to share more of the C and C++
118 lexer code, if desired. */
120 /* The following local token type is used. */
123 #define CPP_KEYWORD ((enum cpp_ttype) (N_TTYPES + 1))
125 /* More information about the type of a CPP_NAME token. */
126 typedef enum c_id_kind {
127 /* An ordinary identifier. */
129 /* An identifier declared as a typedef name. */
131 /* An identifier declared as an Objective-C class name. */
133 /* Not an identifier. */
137 /* A single C token after string literal concatenation and conversion
138 of preprocessing tokens to tokens. */
139 typedef struct c_token GTY (())
141 /* The kind of token. */
142 ENUM_BITFIELD (cpp_ttype) type : 8;
143 /* If this token is a CPP_NAME, this value indicates whether also
144 declared as some kind of type. Otherwise, it is C_ID_NONE. */
145 ENUM_BITFIELD (c_id_kind) id_kind : 8;
146 /* If this token is a keyword, this value indicates which keyword.
147 Otherwise, this value is RID_MAX. */
148 ENUM_BITFIELD (rid) keyword : 8;
149 /* If this token is a CPP_PRAGMA, this indicates the pragma that
150 was seen. Otherwise it is PRAGMA_NONE. */
151 ENUM_BITFIELD (pragma_kind) pragma_kind : 8;
152 /* The value associated with this token, if any. */
154 /* The location at which this token was found. */
158 /* A parser structure recording information about the state and
159 context of parsing. Includes lexer information with up to two
160 tokens of look-ahead; more are not needed for C. */
161 typedef struct c_parser GTY(())
163 /* The look-ahead tokens. */
165 /* How many look-ahead tokens are available (0, 1 or 2). */
167 /* True if a syntax error is being recovered from; false otherwise.
168 c_parser_error sets this flag. It should clear this flag when
169 enough tokens have been consumed to recover from the error. */
170 BOOL_BITFIELD error : 1;
171 /* True if we're processing a pragma, and shouldn't automatically
172 consume CPP_PRAGMA_EOL. */
173 BOOL_BITFIELD in_pragma : 1;
174 /* True if we're parsing the outermost block of an if statement. */
175 BOOL_BITFIELD in_if_block : 1;
176 /* True if we want to lex an untranslated string. */
177 BOOL_BITFIELD lex_untranslated_string : 1;
178 /* Objective-C specific parser/lexer information. */
179 BOOL_BITFIELD objc_pq_context : 1;
180 /* The following flag is needed to contextualize Objective-C lexical
181 analysis. In some cases (e.g., 'int NSObject;'), it is
182 undesirable to bind an identifier to an Objective-C class, even
183 if a class with that name exists. */
184 BOOL_BITFIELD objc_need_raw_identifier : 1;
188 /* The actual parser and external interface. ??? Does this need to be
189 garbage-collected? */
191 static GTY (()) c_parser *the_parser;
194 /* Read in and lex a single token, storing it in *TOKEN. */
197 c_lex_one_token (c_parser *parser, c_token *token)
199 timevar_push (TV_LEX);
201 token->type = c_lex_with_flags (&token->value, &token->location, NULL,
202 (parser->lex_untranslated_string
203 ? C_LEX_STRING_NO_TRANSLATE : 0));
204 token->id_kind = C_ID_NONE;
205 token->keyword = RID_MAX;
206 token->pragma_kind = PRAGMA_NONE;
214 bool objc_force_identifier = parser->objc_need_raw_identifier;
215 if (c_dialect_objc ())
216 parser->objc_need_raw_identifier = false;
218 if (C_IS_RESERVED_WORD (token->value))
220 enum rid rid_code = C_RID_CODE (token->value);
222 if (rid_code == RID_CXX_COMPAT_WARN)
224 warning_at (token->location,
226 "identifier %qs conflicts with C++ keyword",
227 IDENTIFIER_POINTER (token->value));
229 else if (c_dialect_objc ())
231 if (!objc_is_reserved_word (token->value)
232 && (!OBJC_IS_PQ_KEYWORD (rid_code)
233 || parser->objc_pq_context))
235 /* Return the canonical spelling for this keyword. */
236 token->value = ridpointers[(int) rid_code];
237 token->type = CPP_KEYWORD;
238 token->keyword = rid_code;
244 token->type = CPP_KEYWORD;
245 token->keyword = rid_code;
250 decl = lookup_name (token->value);
253 if (TREE_CODE (decl) == TYPE_DECL)
255 token->id_kind = C_ID_TYPENAME;
259 else if (c_dialect_objc ())
261 tree objc_interface_decl = objc_is_class_name (token->value);
262 /* Objective-C class names are in the same namespace as
263 variables and typedefs, and hence are shadowed by local
265 if (objc_interface_decl
266 && (global_bindings_p ()
267 || (!objc_force_identifier && !decl)))
269 token->value = objc_interface_decl;
270 token->id_kind = C_ID_CLASSNAME;
274 token->id_kind = C_ID_ID;
278 /* This only happens in Objective-C; it must be a keyword. */
279 token->type = CPP_KEYWORD;
280 token->keyword = C_RID_CODE (token->value);
284 case CPP_CLOSE_PAREN:
286 /* These tokens may affect the interpretation of any identifiers
287 following, if doing Objective-C. */
288 if (c_dialect_objc ())
289 parser->objc_need_raw_identifier = false;
292 /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */
293 token->pragma_kind = (enum pragma_kind) TREE_INT_CST_LOW (token->value);
299 timevar_pop (TV_LEX);
302 /* Return a pointer to the next token from PARSER, reading it in if
305 static inline c_token *
306 c_parser_peek_token (c_parser *parser)
308 if (parser->tokens_avail == 0)
310 c_lex_one_token (parser, &parser->tokens[0]);
311 parser->tokens_avail = 1;
313 return &parser->tokens[0];
316 /* Return true if the next token from PARSER has the indicated
320 c_parser_next_token_is (c_parser *parser, enum cpp_ttype type)
322 return c_parser_peek_token (parser)->type == type;
325 /* Return true if the next token from PARSER does not have the
329 c_parser_next_token_is_not (c_parser *parser, enum cpp_ttype type)
331 return !c_parser_next_token_is (parser, type);
334 /* Return true if the next token from PARSER is the indicated
338 c_parser_next_token_is_keyword (c_parser *parser, enum rid keyword)
340 return c_parser_peek_token (parser)->keyword == keyword;
343 /* Return true if TOKEN can start a type name,
346 c_token_starts_typename (c_token *token)
351 switch (token->id_kind)
358 gcc_assert (c_dialect_objc ());
364 switch (token->keyword)
396 if (c_dialect_objc ())
404 /* Return true if the next token from PARSER can start a type name,
407 c_parser_next_token_starts_typename (c_parser *parser)
409 c_token *token = c_parser_peek_token (parser);
410 return c_token_starts_typename (token);
413 /* Return true if TOKEN can start declaration specifiers, false
416 c_token_starts_declspecs (c_token *token)
421 switch (token->id_kind)
428 gcc_assert (c_dialect_objc ());
434 switch (token->keyword)
473 if (c_dialect_objc ())
481 /* Return true if the next token from PARSER can start declaration
482 specifiers, false otherwise. */
484 c_parser_next_token_starts_declspecs (c_parser *parser)
486 c_token *token = c_parser_peek_token (parser);
487 return c_token_starts_declspecs (token);
490 /* Return a pointer to the next-but-one token from PARSER, reading it
491 in if necessary. The next token is already read in. */
494 c_parser_peek_2nd_token (c_parser *parser)
496 if (parser->tokens_avail >= 2)
497 return &parser->tokens[1];
498 gcc_assert (parser->tokens_avail == 1);
499 gcc_assert (parser->tokens[0].type != CPP_EOF);
500 gcc_assert (parser->tokens[0].type != CPP_PRAGMA_EOL);
501 c_lex_one_token (parser, &parser->tokens[1]);
502 parser->tokens_avail = 2;
503 return &parser->tokens[1];
506 /* Consume the next token from PARSER. */
509 c_parser_consume_token (c_parser *parser)
511 gcc_assert (parser->tokens_avail >= 1);
512 gcc_assert (parser->tokens[0].type != CPP_EOF);
513 gcc_assert (!parser->in_pragma || parser->tokens[0].type != CPP_PRAGMA_EOL);
514 gcc_assert (parser->error || parser->tokens[0].type != CPP_PRAGMA);
515 if (parser->tokens_avail == 2)
516 parser->tokens[0] = parser->tokens[1];
517 parser->tokens_avail--;
520 /* Expect the current token to be a #pragma. Consume it and remember
521 that we've begun parsing a pragma. */
524 c_parser_consume_pragma (c_parser *parser)
526 gcc_assert (!parser->in_pragma);
527 gcc_assert (parser->tokens_avail >= 1);
528 gcc_assert (parser->tokens[0].type == CPP_PRAGMA);
529 if (parser->tokens_avail == 2)
530 parser->tokens[0] = parser->tokens[1];
531 parser->tokens_avail--;
532 parser->in_pragma = true;
535 /* Update the globals input_location and in_system_header from
538 c_parser_set_source_position_from_token (c_token *token)
540 if (token->type != CPP_EOF)
542 input_location = token->location;
546 /* Issue a diagnostic of the form
547 FILE:LINE: MESSAGE before TOKEN
548 where TOKEN is the next token in the input stream of PARSER.
549 MESSAGE (specified by the caller) is usually of the form "expected
552 Do not issue a diagnostic if still recovering from an error.
554 ??? This is taken from the C++ parser, but building up messages in
555 this way is not i18n-friendly and some other approach should be
559 c_parser_error (c_parser *parser, const char *gmsgid)
561 c_token *token = c_parser_peek_token (parser);
564 parser->error = true;
567 /* This diagnostic makes more sense if it is tagged to the line of
568 the token we just peeked at. */
569 c_parser_set_source_position_from_token (token);
570 c_parse_error (gmsgid,
571 /* Because c_parse_error does not understand
572 CPP_KEYWORD, keywords are treated like
574 (token->type == CPP_KEYWORD ? CPP_NAME : token->type),
578 /* If the next token is of the indicated TYPE, consume it. Otherwise,
579 issue the error MSGID. If MSGID is NULL then a message has already
580 been produced and no message will be produced this time. Returns
581 true if found, false otherwise. */
584 c_parser_require (c_parser *parser,
588 if (c_parser_next_token_is (parser, type))
590 c_parser_consume_token (parser);
595 c_parser_error (parser, msgid);
600 /* If the next token is the indicated keyword, consume it. Otherwise,
601 issue the error MSGID. Returns true if found, false otherwise. */
604 c_parser_require_keyword (c_parser *parser,
608 if (c_parser_next_token_is_keyword (parser, keyword))
610 c_parser_consume_token (parser);
615 c_parser_error (parser, msgid);
620 /* Like c_parser_require, except that tokens will be skipped until the
621 desired token is found. An error message is still produced if the
622 next token is not as expected. If MSGID is NULL then a message has
623 already been produced and no message will be produced this
627 c_parser_skip_until_found (c_parser *parser,
631 unsigned nesting_depth = 0;
633 if (c_parser_require (parser, type, msgid))
636 /* Skip tokens until the desired token is found. */
639 /* Peek at the next token. */
640 c_token *token = c_parser_peek_token (parser);
641 /* If we've reached the token we want, consume it and stop. */
642 if (token->type == type && !nesting_depth)
644 c_parser_consume_token (parser);
648 /* If we've run out of tokens, stop. */
649 if (token->type == CPP_EOF)
651 if (token->type == CPP_PRAGMA_EOL && parser->in_pragma)
653 if (token->type == CPP_OPEN_BRACE
654 || token->type == CPP_OPEN_PAREN
655 || token->type == CPP_OPEN_SQUARE)
657 else if (token->type == CPP_CLOSE_BRACE
658 || token->type == CPP_CLOSE_PAREN
659 || token->type == CPP_CLOSE_SQUARE)
661 if (nesting_depth-- == 0)
664 /* Consume this token. */
665 c_parser_consume_token (parser);
667 parser->error = false;
670 /* Skip tokens until the end of a parameter is found, but do not
671 consume the comma, semicolon or closing delimiter. */
674 c_parser_skip_to_end_of_parameter (c_parser *parser)
676 unsigned nesting_depth = 0;
680 c_token *token = c_parser_peek_token (parser);
681 if ((token->type == CPP_COMMA || token->type == CPP_SEMICOLON)
684 /* If we've run out of tokens, stop. */
685 if (token->type == CPP_EOF)
687 if (token->type == CPP_PRAGMA_EOL && parser->in_pragma)
689 if (token->type == CPP_OPEN_BRACE
690 || token->type == CPP_OPEN_PAREN
691 || token->type == CPP_OPEN_SQUARE)
693 else if (token->type == CPP_CLOSE_BRACE
694 || token->type == CPP_CLOSE_PAREN
695 || token->type == CPP_CLOSE_SQUARE)
697 if (nesting_depth-- == 0)
700 /* Consume this token. */
701 c_parser_consume_token (parser);
703 parser->error = false;
706 /* Expect to be at the end of the pragma directive and consume an
707 end of line marker. */
710 c_parser_skip_to_pragma_eol (c_parser *parser)
712 gcc_assert (parser->in_pragma);
713 parser->in_pragma = false;
715 if (!c_parser_require (parser, CPP_PRAGMA_EOL, "expected end of line"))
718 c_token *token = c_parser_peek_token (parser);
719 if (token->type == CPP_EOF)
721 if (token->type == CPP_PRAGMA_EOL)
723 c_parser_consume_token (parser);
726 c_parser_consume_token (parser);
729 parser->error = false;
732 /* Skip tokens until we have consumed an entire block, or until we
733 have consumed a non-nested ';'. */
736 c_parser_skip_to_end_of_block_or_statement (c_parser *parser)
738 unsigned nesting_depth = 0;
739 bool save_error = parser->error;
745 /* Peek at the next token. */
746 token = c_parser_peek_token (parser);
754 if (parser->in_pragma)
759 /* If the next token is a ';', we have reached the
760 end of the statement. */
763 /* Consume the ';'. */
764 c_parser_consume_token (parser);
769 case CPP_CLOSE_BRACE:
770 /* If the next token is a non-nested '}', then we have
771 reached the end of the current block. */
772 if (nesting_depth == 0 || --nesting_depth == 0)
774 c_parser_consume_token (parser);
780 /* If it the next token is a '{', then we are entering a new
781 block. Consume the entire block. */
786 /* If we see a pragma, consume the whole thing at once. We
787 have some safeguards against consuming pragmas willy-nilly.
788 Normally, we'd expect to be here with parser->error set,
789 which disables these safeguards. But it's possible to get
790 here for secondary error recovery, after parser->error has
792 c_parser_consume_pragma (parser);
793 c_parser_skip_to_pragma_eol (parser);
794 parser->error = save_error;
801 c_parser_consume_token (parser);
805 parser->error = false;
808 /* CPP's options (initialized by c-opts.c). */
809 extern cpp_options *cpp_opts;
811 /* Save the warning flags which are controlled by __extension__. */
814 disable_extension_diagnostics (void)
817 | (warn_pointer_arith << 1)
818 | (warn_traditional << 2)
820 | (warn_long_long << 4)
821 | (cpp_opts->warn_long_long << 5));
822 cpp_opts->pedantic = pedantic = 0;
823 warn_pointer_arith = 0;
824 cpp_opts->warn_traditional = warn_traditional = 0;
827 cpp_opts->warn_long_long = 0;
831 /* Restore the warning flags which are controlled by __extension__.
832 FLAGS is the return value from disable_extension_diagnostics. */
835 restore_extension_diagnostics (int flags)
837 cpp_opts->pedantic = pedantic = flags & 1;
838 warn_pointer_arith = (flags >> 1) & 1;
839 cpp_opts->warn_traditional = warn_traditional = (flags >> 2) & 1;
840 flag_iso = (flags >> 3) & 1;
841 warn_long_long = (flags >> 4) & 1;
842 cpp_opts->warn_long_long = (flags >> 5) & 1;
845 /* Possibly kinds of declarator to parse. */
846 typedef enum c_dtr_syn {
847 /* A normal declarator with an identifier. */
849 /* An abstract declarator (maybe empty). */
851 /* A parameter declarator: may be either, but after a type name does
852 not redeclare a typedef name as an identifier if it can
853 alternatively be interpreted as a typedef name; see DR#009,
854 applied in C90 TC1, omitted from C99 and reapplied in C99 TC2
855 following DR#249. For example, given a typedef T, "int T" and
856 "int *T" are valid parameter declarations redeclaring T, while
857 "int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are
858 abstract declarators rather than involving redundant parentheses;
859 the same applies with attributes inside the parentheses before
864 static void c_parser_external_declaration (c_parser *);
865 static void c_parser_asm_definition (c_parser *);
866 static void c_parser_declaration_or_fndef (c_parser *, bool, bool, bool, bool);
867 static void c_parser_declspecs (c_parser *, struct c_declspecs *, bool, bool,
869 static struct c_typespec c_parser_enum_specifier (c_parser *);
870 static struct c_typespec c_parser_struct_or_union_specifier (c_parser *);
871 static tree c_parser_struct_declaration (c_parser *);
872 static struct c_typespec c_parser_typeof_specifier (c_parser *);
873 static struct c_declarator *c_parser_declarator (c_parser *, bool, c_dtr_syn,
875 static struct c_declarator *c_parser_direct_declarator (c_parser *, bool,
877 static struct c_declarator *c_parser_direct_declarator_inner (c_parser *,
879 struct c_declarator *);
880 static struct c_arg_info *c_parser_parms_declarator (c_parser *, bool, tree);
881 static struct c_arg_info *c_parser_parms_list_declarator (c_parser *, tree);
882 static struct c_parm *c_parser_parameter_declaration (c_parser *, tree);
883 static tree c_parser_simple_asm_expr (c_parser *);
884 static tree c_parser_attributes (c_parser *);
885 static struct c_type_name *c_parser_type_name (c_parser *);
886 static struct c_expr c_parser_initializer (c_parser *);
887 static struct c_expr c_parser_braced_init (c_parser *, tree, bool);
888 static void c_parser_initelt (c_parser *);
889 static void c_parser_initval (c_parser *, struct c_expr *);
890 static tree c_parser_compound_statement (c_parser *);
891 static void c_parser_compound_statement_nostart (c_parser *);
892 static void c_parser_label (c_parser *);
893 static void c_parser_statement (c_parser *);
894 static void c_parser_statement_after_labels (c_parser *);
895 static void c_parser_if_statement (c_parser *);
896 static void c_parser_switch_statement (c_parser *);
897 static void c_parser_while_statement (c_parser *);
898 static void c_parser_do_statement (c_parser *);
899 static void c_parser_for_statement (c_parser *);
900 static tree c_parser_asm_statement (c_parser *);
901 static tree c_parser_asm_operands (c_parser *, bool);
902 static tree c_parser_asm_clobbers (c_parser *);
903 static struct c_expr c_parser_expr_no_commas (c_parser *, struct c_expr *);
904 static struct c_expr c_parser_conditional_expression (c_parser *,
906 static struct c_expr c_parser_binary_expression (c_parser *, struct c_expr *);
907 static struct c_expr c_parser_cast_expression (c_parser *, struct c_expr *);
908 static struct c_expr c_parser_unary_expression (c_parser *);
909 static struct c_expr c_parser_sizeof_expression (c_parser *);
910 static struct c_expr c_parser_alignof_expression (c_parser *);
911 static struct c_expr c_parser_postfix_expression (c_parser *);
912 static struct c_expr c_parser_postfix_expression_after_paren_type (c_parser *,
913 struct c_type_name *);
914 static struct c_expr c_parser_postfix_expression_after_primary (c_parser *,
916 static struct c_expr c_parser_expression (c_parser *);
917 static struct c_expr c_parser_expression_conv (c_parser *);
918 static tree c_parser_expr_list (c_parser *, bool, bool);
919 static void c_parser_omp_construct (c_parser *);
920 static void c_parser_omp_threadprivate (c_parser *);
921 static void c_parser_omp_barrier (c_parser *);
922 static void c_parser_omp_flush (c_parser *);
923 static void c_parser_omp_taskwait (c_parser *);
925 enum pragma_context { pragma_external, pragma_stmt, pragma_compound };
926 static bool c_parser_pragma (c_parser *, enum pragma_context);
928 /* These Objective-C parser functions are only ever called when
929 compiling Objective-C. */
930 static void c_parser_objc_class_definition (c_parser *);
931 static void c_parser_objc_class_instance_variables (c_parser *);
932 static void c_parser_objc_class_declaration (c_parser *);
933 static void c_parser_objc_alias_declaration (c_parser *);
934 static void c_parser_objc_protocol_definition (c_parser *);
935 static enum tree_code c_parser_objc_method_type (c_parser *);
936 static void c_parser_objc_method_definition (c_parser *);
937 static void c_parser_objc_methodprotolist (c_parser *);
938 static void c_parser_objc_methodproto (c_parser *);
939 static tree c_parser_objc_method_decl (c_parser *);
940 static tree c_parser_objc_type_name (c_parser *);
941 static tree c_parser_objc_protocol_refs (c_parser *);
942 static void c_parser_objc_try_catch_statement (c_parser *);
943 static void c_parser_objc_synchronized_statement (c_parser *);
944 static tree c_parser_objc_selector (c_parser *);
945 static tree c_parser_objc_selector_arg (c_parser *);
946 static tree c_parser_objc_receiver (c_parser *);
947 static tree c_parser_objc_message_args (c_parser *);
948 static tree c_parser_objc_keywordexpr (c_parser *);
950 /* Parse a translation unit (C90 6.7, C99 6.9).
953 external-declarations
955 external-declarations:
957 external-declarations external-declaration
966 c_parser_translation_unit (c_parser *parser)
968 if (c_parser_next_token_is (parser, CPP_EOF))
970 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
971 "ISO C forbids an empty translation unit");
975 void *obstack_position = obstack_alloc (&parser_obstack, 0);
979 c_parser_external_declaration (parser);
980 obstack_free (&parser_obstack, obstack_position);
982 while (c_parser_next_token_is_not (parser, CPP_EOF));
986 /* Parse an external declaration (C90 6.7, C99 6.9).
988 external-declaration:
994 external-declaration:
997 __extension__ external-declaration
1001 external-declaration:
1002 objc-class-definition
1003 objc-class-declaration
1004 objc-alias-declaration
1005 objc-protocol-definition
1006 objc-method-definition
1011 c_parser_external_declaration (c_parser *parser)
1014 switch (c_parser_peek_token (parser)->type)
1017 switch (c_parser_peek_token (parser)->keyword)
1020 ext = disable_extension_diagnostics ();
1021 c_parser_consume_token (parser);
1022 c_parser_external_declaration (parser);
1023 restore_extension_diagnostics (ext);
1026 c_parser_asm_definition (parser);
1028 case RID_AT_INTERFACE:
1029 case RID_AT_IMPLEMENTATION:
1030 gcc_assert (c_dialect_objc ());
1031 c_parser_objc_class_definition (parser);
1034 gcc_assert (c_dialect_objc ());
1035 c_parser_objc_class_declaration (parser);
1038 gcc_assert (c_dialect_objc ());
1039 c_parser_objc_alias_declaration (parser);
1041 case RID_AT_PROTOCOL:
1042 gcc_assert (c_dialect_objc ());
1043 c_parser_objc_protocol_definition (parser);
1046 gcc_assert (c_dialect_objc ());
1047 c_parser_consume_token (parser);
1048 objc_finish_implementation ();
1055 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
1056 "ISO C does not allow extra %<;%> outside of a function");
1057 c_parser_consume_token (parser);
1060 c_parser_pragma (parser, pragma_external);
1064 if (c_dialect_objc ())
1066 c_parser_objc_method_definition (parser);
1069 /* Else fall through, and yield a syntax error trying to parse
1070 as a declaration or function definition. */
1073 /* A declaration or a function definition. We can only tell
1074 which after parsing the declaration specifiers, if any, and
1075 the first declarator. */
1076 c_parser_declaration_or_fndef (parser, true, true, false, true);
1082 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1083 6.7, 6.9.1). If FNDEF_OK is true, a function definition is
1084 accepted; otherwise (old-style parameter declarations) only other
1085 declarations are accepted. If NESTED is true, we are inside a
1086 function or parsing old-style parameter declarations; any functions
1087 encountered are nested functions and declaration specifiers are
1088 required; otherwise we are at top level and functions are normal
1089 functions and declaration specifiers may be optional. If EMPTY_OK
1090 is true, empty declarations are OK (subject to all other
1091 constraints); otherwise (old-style parameter declarations) they are
1092 diagnosed. If START_ATTR_OK is true, the declaration specifiers
1093 may start with attributes; otherwise they may not.
1096 declaration-specifiers init-declarator-list[opt] ;
1098 function-definition:
1099 declaration-specifiers[opt] declarator declaration-list[opt]
1104 declaration-list declaration
1106 init-declarator-list:
1108 init-declarator-list , init-declarator
1111 declarator simple-asm-expr[opt] attributes[opt]
1112 declarator simple-asm-expr[opt] attributes[opt] = initializer
1116 nested-function-definition:
1117 declaration-specifiers declarator declaration-list[opt]
1120 The simple-asm-expr and attributes are GNU extensions.
1122 This function does not handle __extension__; that is handled in its
1123 callers. ??? Following the old parser, __extension__ may start
1124 external declarations, declarations in functions and declarations
1125 at the start of "for" loops, but not old-style parameter
1128 C99 requires declaration specifiers in a function definition; the
1129 absence is diagnosed through the diagnosis of implicit int. In GNU
1130 C we also allow but diagnose declarations without declaration
1131 specifiers, but only at top level (elsewhere they conflict with
1137 threadprivate-directive */
1140 c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok, bool empty_ok,
1141 bool nested, bool start_attr_ok)
1143 struct c_declspecs *specs;
1145 tree all_prefix_attrs;
1146 bool diagnosed_no_specs = false;
1147 location_t here = c_parser_peek_token (parser)->location;
1149 specs = build_null_declspecs ();
1150 c_parser_declspecs (parser, specs, true, true, start_attr_ok);
1153 c_parser_skip_to_end_of_block_or_statement (parser);
1156 if (nested && !specs->declspecs_seen_p)
1158 c_parser_error (parser, "expected declaration specifiers");
1159 c_parser_skip_to_end_of_block_or_statement (parser);
1162 finish_declspecs (specs);
1163 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1169 shadow_tag_warned (specs, 1);
1170 pedwarn (here, 0, "empty declaration");
1172 c_parser_consume_token (parser);
1175 pending_xref_error ();
1176 prefix_attrs = specs->attrs;
1177 all_prefix_attrs = prefix_attrs;
1178 specs->attrs = NULL_TREE;
1181 struct c_declarator *declarator;
1184 /* Declaring either one or more declarators (in which case we
1185 should diagnose if there were no declaration specifiers) or a
1186 function definition (in which case the diagnostic for
1187 implicit int suffices). */
1188 declarator = c_parser_declarator (parser, specs->type_seen_p,
1189 C_DTR_NORMAL, &dummy);
1190 if (declarator == NULL)
1192 c_parser_skip_to_end_of_block_or_statement (parser);
1195 if (c_parser_next_token_is (parser, CPP_EQ)
1196 || c_parser_next_token_is (parser, CPP_COMMA)
1197 || c_parser_next_token_is (parser, CPP_SEMICOLON)
1198 || c_parser_next_token_is_keyword (parser, RID_ASM)
1199 || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1201 tree asm_name = NULL_TREE;
1202 tree postfix_attrs = NULL_TREE;
1203 if (!diagnosed_no_specs && !specs->declspecs_seen_p)
1205 diagnosed_no_specs = true;
1206 pedwarn (here, 0, "data definition has no type or storage class");
1208 /* Having seen a data definition, there cannot now be a
1209 function definition. */
1211 if (c_parser_next_token_is_keyword (parser, RID_ASM))
1212 asm_name = c_parser_simple_asm_expr (parser);
1213 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1214 postfix_attrs = c_parser_attributes (parser);
1215 if (c_parser_next_token_is (parser, CPP_EQ))
1219 c_parser_consume_token (parser);
1220 /* The declaration of the variable is in effect while
1221 its initializer is parsed. */
1222 d = start_decl (declarator, specs, true,
1223 chainon (postfix_attrs, all_prefix_attrs));
1225 d = error_mark_node;
1226 start_init (d, asm_name, global_bindings_p ());
1227 init = c_parser_initializer (parser);
1229 if (d != error_mark_node)
1231 maybe_warn_string_init (TREE_TYPE (d), init);
1232 finish_decl (d, init.value, asm_name);
1237 tree d = start_decl (declarator, specs, false,
1238 chainon (postfix_attrs,
1241 finish_decl (d, NULL_TREE, asm_name);
1243 if (c_parser_next_token_is (parser, CPP_COMMA))
1245 c_parser_consume_token (parser);
1246 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1247 all_prefix_attrs = chainon (c_parser_attributes (parser),
1250 all_prefix_attrs = prefix_attrs;
1253 else if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1255 c_parser_consume_token (parser);
1260 c_parser_error (parser, "expected %<,%> or %<;%>");
1261 c_parser_skip_to_end_of_block_or_statement (parser);
1267 c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, "
1268 "%<asm%> or %<__attribute__%>");
1269 c_parser_skip_to_end_of_block_or_statement (parser);
1272 /* Function definition (nested or otherwise). */
1275 pedwarn (here, OPT_pedantic, "ISO C forbids nested functions");
1276 c_push_function_context ();
1278 if (!start_function (specs, declarator, all_prefix_attrs))
1280 /* This can appear in many cases looking nothing like a
1281 function definition, so we don't give a more specific
1282 error suggesting there was one. */
1283 c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
1284 "or %<__attribute__%>");
1286 c_pop_function_context ();
1289 /* Parse old-style parameter declarations. ??? Attributes are
1290 not allowed to start declaration specifiers here because of a
1291 syntax conflict between a function declaration with attribute
1292 suffix and a function definition with an attribute prefix on
1293 first old-style parameter declaration. Following the old
1294 parser, they are not accepted on subsequent old-style
1295 parameter declarations either. However, there is no
1296 ambiguity after the first declaration, nor indeed on the
1297 first as long as we don't allow postfix attributes after a
1298 declarator with a nonempty identifier list in a definition;
1299 and postfix attributes have never been accepted here in
1300 function definitions either. */
1301 while (c_parser_next_token_is_not (parser, CPP_EOF)
1302 && c_parser_next_token_is_not (parser, CPP_OPEN_BRACE))
1303 c_parser_declaration_or_fndef (parser, false, false, true, false);
1304 store_parm_decls ();
1305 DECL_STRUCT_FUNCTION (current_function_decl)->function_start_locus
1306 = c_parser_peek_token (parser)->location;
1307 fnbody = c_parser_compound_statement (parser);
1310 tree decl = current_function_decl;
1313 c_pop_function_context ();
1314 add_stmt (build_stmt (DECL_EXPR, decl));
1325 /* Parse an asm-definition (asm() outside a function body). This is a
1333 c_parser_asm_definition (c_parser *parser)
1335 tree asm_str = c_parser_simple_asm_expr (parser);
1337 cgraph_add_asm_node (asm_str);
1338 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
1341 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
1342 6.7), adding them to SPECS (which may already include some).
1343 Storage class specifiers are accepted iff SCSPEC_OK; type
1344 specifiers are accepted iff TYPESPEC_OK; attributes are accepted at
1345 the start iff START_ATTR_OK.
1347 declaration-specifiers:
1348 storage-class-specifier declaration-specifiers[opt]
1349 type-specifier declaration-specifiers[opt]
1350 type-qualifier declaration-specifiers[opt]
1351 function-specifier declaration-specifiers[opt]
1353 Function specifiers (inline) are from C99, and are currently
1354 handled as storage class specifiers, as is __thread.
1356 C90 6.5.1, C99 6.7.1:
1357 storage-class-specifier:
1368 C90 6.5.2, C99 6.7.2:
1381 [_Imaginary removed in C99 TC2]
1382 struct-or-union-specifier
1386 (_Bool and _Complex are new in C99.)
1388 C90 6.5.3, C99 6.7.3:
1395 (restrict is new in C99.)
1399 declaration-specifiers:
1400 attributes declaration-specifiers[opt]
1402 storage-class-specifier:
1414 (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
1415 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
1420 class-name objc-protocol-refs[opt]
1421 typedef-name objc-protocol-refs
1426 c_parser_declspecs (c_parser *parser, struct c_declspecs *specs,
1427 bool scspec_ok, bool typespec_ok, bool start_attr_ok)
1429 bool attrs_ok = start_attr_ok;
1430 bool seen_type = specs->type_seen_p;
1431 while (c_parser_next_token_is (parser, CPP_NAME)
1432 || c_parser_next_token_is (parser, CPP_KEYWORD)
1433 || (c_dialect_objc () && c_parser_next_token_is (parser, CPP_LESS)))
1435 struct c_typespec t;
1437 if (c_parser_next_token_is (parser, CPP_NAME))
1439 tree value = c_parser_peek_token (parser)->value;
1440 c_id_kind kind = c_parser_peek_token (parser)->id_kind;
1441 /* This finishes the specifiers unless a type name is OK, it
1442 is declared as a type name and a type name hasn't yet
1444 if (!typespec_ok || seen_type
1445 || (kind != C_ID_TYPENAME && kind != C_ID_CLASSNAME))
1447 c_parser_consume_token (parser);
1450 if (kind == C_ID_TYPENAME
1451 && (!c_dialect_objc ()
1452 || c_parser_next_token_is_not (parser, CPP_LESS)))
1454 t.kind = ctsk_typedef;
1455 /* For a typedef name, record the meaning, not the name.
1456 In case of 'foo foo, bar;'. */
1457 t.spec = lookup_name (value);
1459 t.expr_const_operands = true;
1463 tree proto = NULL_TREE;
1464 gcc_assert (c_dialect_objc ());
1466 if (c_parser_next_token_is (parser, CPP_LESS))
1467 proto = c_parser_objc_protocol_refs (parser);
1468 t.spec = objc_get_protocol_qualified_type (value, proto);
1470 t.expr_const_operands = true;
1472 declspecs_add_type (specs, t);
1475 if (c_parser_next_token_is (parser, CPP_LESS))
1477 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
1478 nisse@lysator.liu.se. */
1480 gcc_assert (c_dialect_objc ());
1481 if (!typespec_ok || seen_type)
1483 proto = c_parser_objc_protocol_refs (parser);
1485 t.spec = objc_get_protocol_qualified_type (NULL_TREE, proto);
1487 t.expr_const_operands = true;
1488 declspecs_add_type (specs, t);
1491 gcc_assert (c_parser_next_token_is (parser, CPP_KEYWORD));
1492 switch (c_parser_peek_token (parser)->keyword)
1504 /* TODO: Distinguish between function specifiers (inline)
1505 and storage class specifiers, either here or in
1506 declspecs_add_scspec. */
1507 declspecs_add_scspec (specs, c_parser_peek_token (parser)->value);
1508 c_parser_consume_token (parser);
1531 if (c_dialect_objc ())
1532 parser->objc_need_raw_identifier = true;
1533 t.kind = ctsk_resword;
1534 t.spec = c_parser_peek_token (parser)->value;
1536 t.expr_const_operands = true;
1537 declspecs_add_type (specs, t);
1538 c_parser_consume_token (parser);
1545 t = c_parser_enum_specifier (parser);
1546 declspecs_add_type (specs, t);
1554 t = c_parser_struct_or_union_specifier (parser);
1555 declspecs_add_type (specs, t);
1558 /* ??? The old parser rejected typeof after other type
1559 specifiers, but is a syntax error the best way of
1561 if (!typespec_ok || seen_type)
1565 t = c_parser_typeof_specifier (parser);
1566 declspecs_add_type (specs, t);
1572 declspecs_add_qual (specs, c_parser_peek_token (parser)->value);
1573 c_parser_consume_token (parser);
1578 attrs = c_parser_attributes (parser);
1579 declspecs_add_attrs (specs, attrs);
1588 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
1591 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
1592 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
1593 enum attributes[opt] identifier
1595 The form with trailing comma is new in C99. The forms with
1596 attributes are GNU extensions. In GNU C, we accept any expression
1597 without commas in the syntax (assignment expressions, not just
1598 conditional expressions); assignment expressions will be diagnosed
1603 enumerator-list , enumerator
1606 enumeration-constant
1607 enumeration-constant = constant-expression
1610 static struct c_typespec
1611 c_parser_enum_specifier (c_parser *parser)
1613 struct c_typespec ret;
1615 tree ident = NULL_TREE;
1616 location_t ident_loc = UNKNOWN_LOCATION; /* Quiet warning. */
1617 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ENUM));
1618 c_parser_consume_token (parser);
1619 attrs = c_parser_attributes (parser);
1620 /* Set the location in case we create a decl now. */
1621 c_parser_set_source_position_from_token (c_parser_peek_token (parser));
1622 if (c_parser_next_token_is (parser, CPP_NAME))
1624 ident = c_parser_peek_token (parser)->value;
1625 ident_loc = c_parser_peek_token (parser)->location;
1626 c_parser_consume_token (parser);
1628 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
1630 /* Parse an enum definition. */
1631 struct c_enum_contents the_enum;
1632 tree type = start_enum (&the_enum, ident);
1634 /* We chain the enumerators in reverse order, then put them in
1635 forward order at the end. */
1636 tree values = NULL_TREE;
1637 c_parser_consume_token (parser);
1645 location_t comma_loc = UNKNOWN_LOCATION; /* Quiet warning. */
1646 location_t value_loc;
1647 if (c_parser_next_token_is_not (parser, CPP_NAME))
1649 c_parser_error (parser, "expected identifier");
1650 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
1651 values = error_mark_node;
1654 token = c_parser_peek_token (parser);
1655 enum_id = token->value;
1656 /* Set the location in case we create a decl now. */
1657 c_parser_set_source_position_from_token (token);
1658 value_loc = token->location;
1659 c_parser_consume_token (parser);
1660 if (c_parser_next_token_is (parser, CPP_EQ))
1662 c_parser_consume_token (parser);
1663 value_loc = c_parser_peek_token (parser)->location;
1664 enum_value = c_parser_expr_no_commas (parser, NULL).value;
1667 enum_value = NULL_TREE;
1668 enum_decl = build_enumerator (&the_enum, enum_id, enum_value,
1670 TREE_CHAIN (enum_decl) = values;
1673 if (c_parser_next_token_is (parser, CPP_COMMA))
1675 comma_loc = c_parser_peek_token (parser)->location;
1677 c_parser_consume_token (parser);
1679 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
1681 if (seen_comma && !flag_isoc99)
1682 pedwarn (comma_loc, OPT_pedantic, "comma at end of enumerator list");
1683 c_parser_consume_token (parser);
1688 c_parser_error (parser, "expected %<,%> or %<}%>");
1689 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
1690 values = error_mark_node;
1694 postfix_attrs = c_parser_attributes (parser);
1695 ret.spec = finish_enum (type, nreverse (values),
1696 chainon (attrs, postfix_attrs));
1697 ret.kind = ctsk_tagdef;
1698 ret.expr = NULL_TREE;
1699 ret.expr_const_operands = true;
1704 c_parser_error (parser, "expected %<{%>");
1705 ret.spec = error_mark_node;
1706 ret.kind = ctsk_tagref;
1707 ret.expr = NULL_TREE;
1708 ret.expr_const_operands = true;
1711 ret = parser_xref_tag (ENUMERAL_TYPE, ident);
1712 /* In ISO C, enumerated types can be referred to only if already
1714 if (pedantic && !COMPLETE_TYPE_P (ret.spec))
1717 pedwarn (ident_loc, OPT_pedantic,
1718 "ISO C forbids forward references to %<enum%> types");
1723 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
1725 struct-or-union-specifier:
1726 struct-or-union attributes[opt] identifier[opt]
1727 { struct-contents } attributes[opt]
1728 struct-or-union attributes[opt] identifier
1731 struct-declaration-list
1733 struct-declaration-list:
1734 struct-declaration ;
1735 struct-declaration-list struct-declaration ;
1742 struct-declaration-list struct-declaration
1744 struct-declaration-list:
1745 struct-declaration-list ;
1748 (Note that in the syntax here, unlike that in ISO C, the semicolons
1749 are included here rather than in struct-declaration, in order to
1750 describe the syntax with extra semicolons and missing semicolon at
1755 struct-declaration-list:
1756 @defs ( class-name )
1758 (Note this does not include a trailing semicolon, but can be
1759 followed by further declarations, and gets a pedwarn-if-pedantic
1760 when followed by a semicolon.) */
1762 static struct c_typespec
1763 c_parser_struct_or_union_specifier (c_parser *parser)
1765 struct c_typespec ret;
1767 tree ident = NULL_TREE;
1768 enum tree_code code;
1769 switch (c_parser_peek_token (parser)->keyword)
1780 c_parser_consume_token (parser);
1781 attrs = c_parser_attributes (parser);
1782 /* Set the location in case we create a decl now. */
1783 c_parser_set_source_position_from_token (c_parser_peek_token (parser));
1784 if (c_parser_next_token_is (parser, CPP_NAME))
1786 ident = c_parser_peek_token (parser)->value;
1787 c_parser_consume_token (parser);
1789 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
1791 /* Parse a struct or union definition. Start the scope of the
1792 tag before parsing components. */
1793 tree type = start_struct (code, ident);
1795 /* We chain the components in reverse order, then put them in
1796 forward order at the end. Each struct-declaration may
1797 declare multiple components (comma-separated), so we must use
1798 chainon to join them, although when parsing each
1799 struct-declaration we can use TREE_CHAIN directly.
1801 The theory behind all this is that there will be more
1802 semicolon separated fields than comma separated fields, and
1803 so we'll be minimizing the number of node traversals required
1805 tree contents = NULL_TREE;
1806 c_parser_consume_token (parser);
1807 /* Handle the Objective-C @defs construct,
1808 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
1809 if (c_parser_next_token_is_keyword (parser, RID_AT_DEFS))
1812 gcc_assert (c_dialect_objc ());
1813 c_parser_consume_token (parser);
1814 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
1816 if (c_parser_next_token_is (parser, CPP_NAME)
1817 && c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME)
1819 name = c_parser_peek_token (parser)->value;
1820 c_parser_consume_token (parser);
1824 c_parser_error (parser, "expected class name");
1825 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
1828 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
1830 contents = nreverse (objc_get_class_ivars (name));
1833 /* Parse the struct-declarations and semicolons. Problems with
1834 semicolons are diagnosed here; empty structures are diagnosed
1839 /* Parse any stray semicolon. */
1840 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1842 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
1843 "extra semicolon in struct or union specified");
1844 c_parser_consume_token (parser);
1847 /* Stop if at the end of the struct or union contents. */
1848 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
1850 c_parser_consume_token (parser);
1853 /* Accept #pragmas at struct scope. */
1854 if (c_parser_next_token_is (parser, CPP_PRAGMA))
1856 c_parser_pragma (parser, pragma_external);
1859 /* Parse some comma-separated declarations, but not the
1860 trailing semicolon if any. */
1861 decls = c_parser_struct_declaration (parser);
1862 contents = chainon (decls, contents);
1863 /* If no semicolon follows, either we have a parse error or
1864 are at the end of the struct or union and should
1866 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1867 c_parser_consume_token (parser);
1870 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
1871 pedwarn (c_parser_peek_token (parser)->location, 0,
1872 "no semicolon at end of struct or union");
1875 c_parser_error (parser, "expected %<;%>");
1876 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
1881 postfix_attrs = c_parser_attributes (parser);
1882 ret.spec = finish_struct (type, nreverse (contents),
1883 chainon (attrs, postfix_attrs));
1884 ret.kind = ctsk_tagdef;
1885 ret.expr = NULL_TREE;
1886 ret.expr_const_operands = true;
1891 c_parser_error (parser, "expected %<{%>");
1892 ret.spec = error_mark_node;
1893 ret.kind = ctsk_tagref;
1894 ret.expr = NULL_TREE;
1895 ret.expr_const_operands = true;
1898 ret = parser_xref_tag (code, ident);
1902 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
1903 the trailing semicolon.
1906 specifier-qualifier-list struct-declarator-list
1908 specifier-qualifier-list:
1909 type-specifier specifier-qualifier-list[opt]
1910 type-qualifier specifier-qualifier-list[opt]
1911 attributes specifier-qualifier-list[opt]
1913 struct-declarator-list:
1915 struct-declarator-list , attributes[opt] struct-declarator
1918 declarator attributes[opt]
1919 declarator[opt] : constant-expression attributes[opt]
1924 __extension__ struct-declaration
1925 specifier-qualifier-list
1927 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
1928 of attributes where shown is a GNU extension. In GNU C, we accept
1929 any expression without commas in the syntax (assignment
1930 expressions, not just conditional expressions); assignment
1931 expressions will be diagnosed as non-constant. */
1934 c_parser_struct_declaration (c_parser *parser)
1936 struct c_declspecs *specs;
1938 tree all_prefix_attrs;
1940 location_t decl_loc;
1941 if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
1945 ext = disable_extension_diagnostics ();
1946 c_parser_consume_token (parser);
1947 decl = c_parser_struct_declaration (parser);
1948 restore_extension_diagnostics (ext);
1951 specs = build_null_declspecs ();
1952 decl_loc = c_parser_peek_token (parser)->location;
1953 c_parser_declspecs (parser, specs, false, true, true);
1956 if (!specs->declspecs_seen_p)
1958 c_parser_error (parser, "expected specifier-qualifier-list");
1961 finish_declspecs (specs);
1962 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1965 if (!specs->type_seen_p)
1967 pedwarn (decl_loc, OPT_pedantic,
1968 "ISO C forbids member declarations with no members");
1969 shadow_tag_warned (specs, pedantic);
1974 /* Support for unnamed structs or unions as members of
1975 structs or unions (which is [a] useful and [b] supports
1979 ret = grokfield (c_parser_peek_token (parser)->location,
1980 build_id_declarator (NULL_TREE), specs,
1983 decl_attributes (&ret, attrs, 0);
1987 pending_xref_error ();
1988 prefix_attrs = specs->attrs;
1989 all_prefix_attrs = prefix_attrs;
1990 specs->attrs = NULL_TREE;
1994 /* Declaring one or more declarators or un-named bit-fields. */
1995 struct c_declarator *declarator;
1997 if (c_parser_next_token_is (parser, CPP_COLON))
1998 declarator = build_id_declarator (NULL_TREE);
2000 declarator = c_parser_declarator (parser, specs->type_seen_p,
2001 C_DTR_NORMAL, &dummy);
2002 if (declarator == NULL)
2004 c_parser_skip_to_end_of_block_or_statement (parser);
2007 if (c_parser_next_token_is (parser, CPP_COLON)
2008 || c_parser_next_token_is (parser, CPP_COMMA)
2009 || c_parser_next_token_is (parser, CPP_SEMICOLON)
2010 || c_parser_next_token_is (parser, CPP_CLOSE_BRACE)
2011 || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2013 tree postfix_attrs = NULL_TREE;
2014 tree width = NULL_TREE;
2016 if (c_parser_next_token_is (parser, CPP_COLON))
2018 c_parser_consume_token (parser);
2019 width = c_parser_expr_no_commas (parser, NULL).value;
2021 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2022 postfix_attrs = c_parser_attributes (parser);
2023 d = grokfield (c_parser_peek_token (parser)->location,
2024 declarator, specs, width, &all_prefix_attrs);
2025 decl_attributes (&d, chainon (postfix_attrs,
2026 all_prefix_attrs), 0);
2027 TREE_CHAIN (d) = decls;
2029 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2030 all_prefix_attrs = chainon (c_parser_attributes (parser),
2033 all_prefix_attrs = prefix_attrs;
2034 if (c_parser_next_token_is (parser, CPP_COMMA))
2035 c_parser_consume_token (parser);
2036 else if (c_parser_next_token_is (parser, CPP_SEMICOLON)
2037 || c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2039 /* Semicolon consumed in caller. */
2044 c_parser_error (parser, "expected %<,%>, %<;%> or %<}%>");
2050 c_parser_error (parser,
2051 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
2052 "%<__attribute__%>");
2059 /* Parse a typeof specifier (a GNU extension).
2062 typeof ( expression )
2063 typeof ( type-name )
2066 static struct c_typespec
2067 c_parser_typeof_specifier (c_parser *parser)
2069 struct c_typespec ret;
2070 ret.kind = ctsk_typeof;
2071 ret.spec = error_mark_node;
2072 ret.expr = NULL_TREE;
2073 ret.expr_const_operands = true;
2074 gcc_assert (c_parser_next_token_is_keyword (parser, RID_TYPEOF));
2075 c_parser_consume_token (parser);
2078 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2084 if (c_parser_next_token_starts_typename (parser))
2086 struct c_type_name *type = c_parser_type_name (parser);
2091 ret.spec = groktypename (type, &ret.expr, &ret.expr_const_operands);
2092 pop_maybe_used (variably_modified_type_p (ret.spec, NULL_TREE));
2098 location_t here = c_parser_peek_token (parser)->location;
2099 struct c_expr expr = c_parser_expression (parser);
2102 if (TREE_CODE (expr.value) == COMPONENT_REF
2103 && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
2104 error_at (here, "%<typeof%> applied to a bit-field");
2105 ret.spec = TREE_TYPE (expr.value);
2106 was_vm = variably_modified_type_p (ret.spec, NULL_TREE);
2107 /* This is returned with the type so that when the type is
2108 evaluated, this can be evaluated. */
2110 ret.expr = c_fully_fold (expr.value, false, &ret.expr_const_operands);
2111 pop_maybe_used (was_vm);
2113 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
2117 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
2118 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
2119 be redeclared; otherwise it may not. KIND indicates which kind of
2120 declarator is wanted. Returns a valid declarator except in the
2121 case of a syntax error in which case NULL is returned. *SEEN_ID is
2122 set to true if an identifier being declared is seen; this is used
2123 to diagnose bad forms of abstract array declarators and to
2124 determine whether an identifier list is syntactically permitted.
2127 pointer[opt] direct-declarator
2131 ( attributes[opt] declarator )
2132 direct-declarator array-declarator
2133 direct-declarator ( parameter-type-list )
2134 direct-declarator ( identifier-list[opt] )
2137 * type-qualifier-list[opt]
2138 * type-qualifier-list[opt] pointer
2140 type-qualifier-list:
2143 type-qualifier-list type-qualifier
2144 type-qualifier-list attributes
2146 parameter-type-list:
2148 parameter-list , ...
2151 parameter-declaration
2152 parameter-list , parameter-declaration
2154 parameter-declaration:
2155 declaration-specifiers declarator attributes[opt]
2156 declaration-specifiers abstract-declarator[opt] attributes[opt]
2160 identifier-list , identifier
2162 abstract-declarator:
2164 pointer[opt] direct-abstract-declarator
2166 direct-abstract-declarator:
2167 ( attributes[opt] abstract-declarator )
2168 direct-abstract-declarator[opt] array-declarator
2169 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
2174 direct-declarator ( parameter-forward-declarations
2175 parameter-type-list[opt] )
2177 direct-abstract-declarator:
2178 direct-abstract-declarator[opt] ( parameter-forward-declarations
2179 parameter-type-list[opt] )
2181 parameter-forward-declarations:
2183 parameter-forward-declarations parameter-list ;
2185 The uses of attributes shown above are GNU extensions.
2187 Some forms of array declarator are not included in C99 in the
2188 syntax for abstract declarators; these are disallowed elsewhere.
2189 This may be a defect (DR#289).
2191 This function also accepts an omitted abstract declarator as being
2192 an abstract declarator, although not part of the formal syntax. */
2194 static struct c_declarator *
2195 c_parser_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
2198 /* Parse any initial pointer part. */
2199 if (c_parser_next_token_is (parser, CPP_MULT))
2201 struct c_declspecs *quals_attrs = build_null_declspecs ();
2202 struct c_declarator *inner;
2203 c_parser_consume_token (parser);
2204 c_parser_declspecs (parser, quals_attrs, false, false, true);
2205 inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
2209 return make_pointer_declarator (quals_attrs, inner);
2211 /* Now we have a direct declarator, direct abstract declarator or
2212 nothing (which counts as a direct abstract declarator here). */
2213 return c_parser_direct_declarator (parser, type_seen_p, kind, seen_id);
2216 /* Parse a direct declarator or direct abstract declarator; arguments
2217 as c_parser_declarator. */
2219 static struct c_declarator *
2220 c_parser_direct_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
2223 /* The direct declarator must start with an identifier (possibly
2224 omitted) or a parenthesized declarator (possibly abstract). In
2225 an ordinary declarator, initial parentheses must start a
2226 parenthesized declarator. In an abstract declarator or parameter
2227 declarator, they could start a parenthesized declarator or a
2228 parameter list. To tell which, the open parenthesis and any
2229 following attributes must be read. If a declaration specifier
2230 follows, then it is a parameter list; if the specifier is a
2231 typedef name, there might be an ambiguity about redeclaring it,
2232 which is resolved in the direction of treating it as a typedef
2233 name. If a close parenthesis follows, it is also an empty
2234 parameter list, as the syntax does not permit empty abstract
2235 declarators. Otherwise, it is a parenthesized declarator (in
2236 which case the analysis may be repeated inside it, recursively).
2238 ??? There is an ambiguity in a parameter declaration "int
2239 (__attribute__((foo)) x)", where x is not a typedef name: it
2240 could be an abstract declarator for a function, or declare x with
2241 parentheses. The proper resolution of this ambiguity needs
2242 documenting. At present we follow an accident of the old
2243 parser's implementation, whereby the first parameter must have
2244 some declaration specifiers other than just attributes. Thus as
2245 a parameter declaration it is treated as a parenthesized
2246 parameter named x, and as an abstract declarator it is
2249 ??? Also following the old parser, attributes inside an empty
2250 parameter list are ignored, making it a list not yielding a
2251 prototype, rather than giving an error or making it have one
2252 parameter with implicit type int.
2254 ??? Also following the old parser, typedef names may be
2255 redeclared in declarators, but not Objective-C class names. */
2257 if (kind != C_DTR_ABSTRACT
2258 && c_parser_next_token_is (parser, CPP_NAME)
2260 && c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME)
2261 || c_parser_peek_token (parser)->id_kind == C_ID_ID))
2263 struct c_declarator *inner
2264 = build_id_declarator (c_parser_peek_token (parser)->value);
2266 inner->id_loc = c_parser_peek_token (parser)->location;
2267 c_parser_consume_token (parser);
2268 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2271 if (kind != C_DTR_NORMAL
2272 && c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
2274 struct c_declarator *inner = build_id_declarator (NULL_TREE);
2275 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2278 /* Either we are at the end of an abstract declarator, or we have
2281 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
2284 struct c_declarator *inner;
2285 c_parser_consume_token (parser);
2286 attrs = c_parser_attributes (parser);
2287 if (kind != C_DTR_NORMAL
2288 && (c_parser_next_token_starts_declspecs (parser)
2289 || c_parser_next_token_is (parser, CPP_CLOSE_PAREN)))
2291 struct c_arg_info *args
2292 = c_parser_parms_declarator (parser, kind == C_DTR_NORMAL,
2299 = build_function_declarator (args,
2300 build_id_declarator (NULL_TREE));
2301 return c_parser_direct_declarator_inner (parser, *seen_id,
2305 /* A parenthesized declarator. */
2306 inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
2307 if (inner != NULL && attrs != NULL)
2308 inner = build_attrs_declarator (attrs, inner);
2309 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2311 c_parser_consume_token (parser);
2315 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2319 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2326 if (kind == C_DTR_NORMAL)
2328 c_parser_error (parser, "expected identifier or %<(%>");
2332 return build_id_declarator (NULL_TREE);
2336 /* Parse part of a direct declarator or direct abstract declarator,
2337 given that some (in INNER) has already been parsed; ID_PRESENT is
2338 true if an identifier is present, false for an abstract
2341 static struct c_declarator *
2342 c_parser_direct_declarator_inner (c_parser *parser, bool id_present,
2343 struct c_declarator *inner)
2345 /* Parse a sequence of array declarators and parameter lists. */
2346 if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
2348 struct c_declarator *declarator;
2349 struct c_declspecs *quals_attrs = build_null_declspecs ();
2353 c_parser_consume_token (parser);
2354 c_parser_declspecs (parser, quals_attrs, false, false, true);
2355 static_seen = c_parser_next_token_is_keyword (parser, RID_STATIC);
2357 c_parser_consume_token (parser);
2358 if (static_seen && !quals_attrs->declspecs_seen_p)
2359 c_parser_declspecs (parser, quals_attrs, false, false, true);
2360 if (!quals_attrs->declspecs_seen_p)
2362 /* If "static" is present, there must be an array dimension.
2363 Otherwise, there may be a dimension, "*", or no
2368 dimen = c_parser_expr_no_commas (parser, NULL).value;
2372 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
2377 else if (c_parser_next_token_is (parser, CPP_MULT))
2379 if (c_parser_peek_2nd_token (parser)->type == CPP_CLOSE_SQUARE)
2383 c_parser_consume_token (parser);
2388 dimen = c_parser_expr_no_commas (parser, NULL).value;
2394 dimen = c_parser_expr_no_commas (parser, NULL).value;
2397 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
2398 c_parser_consume_token (parser);
2401 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
2405 declarator = build_array_declarator (dimen, quals_attrs, static_seen,
2407 if (declarator == NULL)
2409 inner = set_array_declarator_inner (declarator, inner);
2410 return c_parser_direct_declarator_inner (parser, id_present, inner);
2412 else if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
2415 struct c_arg_info *args;
2416 c_parser_consume_token (parser);
2417 attrs = c_parser_attributes (parser);
2418 args = c_parser_parms_declarator (parser, id_present, attrs);
2423 inner = build_function_declarator (args, inner);
2424 return c_parser_direct_declarator_inner (parser, id_present, inner);
2430 /* Parse a parameter list or identifier list, including the closing
2431 parenthesis but not the opening one. ATTRS are the attributes at
2432 the start of the list. ID_LIST_OK is true if an identifier list is
2433 acceptable; such a list must not have attributes at the start. */
2435 static struct c_arg_info *
2436 c_parser_parms_declarator (c_parser *parser, bool id_list_ok, tree attrs)
2439 declare_parm_level ();
2440 /* If the list starts with an identifier, it is an identifier list.
2441 Otherwise, it is either a prototype list or an empty list. */
2444 && c_parser_next_token_is (parser, CPP_NAME)
2445 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
2447 tree list = NULL_TREE, *nextp = &list;
2448 while (c_parser_next_token_is (parser, CPP_NAME)
2449 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
2451 *nextp = build_tree_list (NULL_TREE,
2452 c_parser_peek_token (parser)->value);
2453 nextp = & TREE_CHAIN (*nextp);
2454 c_parser_consume_token (parser);
2455 if (c_parser_next_token_is_not (parser, CPP_COMMA))
2457 c_parser_consume_token (parser);
2458 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2460 c_parser_error (parser, "expected identifier");
2464 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2466 struct c_arg_info *ret = XOBNEW (&parser_obstack, struct c_arg_info);
2471 ret->pending_sizes = 0;
2472 ret->had_vla_unspec = 0;
2473 c_parser_consume_token (parser);
2479 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2487 struct c_arg_info *ret = c_parser_parms_list_declarator (parser, attrs);
2493 /* Parse a parameter list (possibly empty), including the closing
2494 parenthesis but not the opening one. ATTRS are the attributes at
2495 the start of the list. */
2497 static struct c_arg_info *
2498 c_parser_parms_list_declarator (c_parser *parser, tree attrs)
2500 bool good_parm = false;
2501 /* ??? Following the old parser, forward parameter declarations may
2502 use abstract declarators, and if no real parameter declarations
2503 follow the forward declarations then this is not diagnosed. Also
2504 note as above that attributes are ignored as the only contents of
2505 the parentheses, or as the only contents after forward
2507 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2509 struct c_arg_info *ret = XOBNEW (&parser_obstack, struct c_arg_info);
2514 ret->pending_sizes = 0;
2515 ret->had_vla_unspec = 0;
2516 c_parser_consume_token (parser);
2519 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
2521 struct c_arg_info *ret = XOBNEW (&parser_obstack, struct c_arg_info);
2525 ret->pending_sizes = 0;
2526 ret->had_vla_unspec = 0;
2527 /* Suppress -Wold-style-definition for this case. */
2528 ret->types = error_mark_node;
2529 error_at (c_parser_peek_token (parser)->location,
2530 "ISO C requires a named argument before %<...%>");
2531 c_parser_consume_token (parser);
2532 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2534 c_parser_consume_token (parser);
2539 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2544 /* Nonempty list of parameters, either terminated with semicolon
2545 (forward declarations; recurse) or with close parenthesis (normal
2546 function) or with ", ... )" (variadic function). */
2549 /* Parse a parameter. */
2550 struct c_parm *parm = c_parser_parameter_declaration (parser, attrs);
2555 push_parm_decl (parm);
2557 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
2560 c_parser_consume_token (parser);
2561 mark_forward_parm_decls ();
2562 new_attrs = c_parser_attributes (parser);
2563 return c_parser_parms_list_declarator (parser, new_attrs);
2565 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2567 c_parser_consume_token (parser);
2569 return get_parm_info (false);
2572 struct c_arg_info *ret
2573 = XOBNEW (&parser_obstack, struct c_arg_info);
2578 ret->pending_sizes = 0;
2579 ret->had_vla_unspec = 0;
2583 if (!c_parser_require (parser, CPP_COMMA,
2584 "expected %<;%>, %<,%> or %<)%>"))
2586 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
2587 get_pending_sizes ();
2590 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
2592 c_parser_consume_token (parser);
2593 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2595 c_parser_consume_token (parser);
2597 return get_parm_info (true);
2600 struct c_arg_info *ret
2601 = XOBNEW (&parser_obstack, struct c_arg_info);
2606 ret->pending_sizes = 0;
2607 ret->had_vla_unspec = 0;
2613 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2615 get_pending_sizes ();
2622 /* Parse a parameter declaration. ATTRS are the attributes at the
2623 start of the declaration if it is the first parameter. */
2625 static struct c_parm *
2626 c_parser_parameter_declaration (c_parser *parser, tree attrs)
2628 struct c_declspecs *specs;
2629 struct c_declarator *declarator;
2631 tree postfix_attrs = NULL_TREE;
2633 if (!c_parser_next_token_starts_declspecs (parser))
2635 /* ??? In some Objective-C cases '...' isn't applicable so there
2636 should be a different message. */
2637 c_parser_error (parser,
2638 "expected declaration specifiers or %<...%>");
2639 c_parser_skip_to_end_of_parameter (parser);
2642 specs = build_null_declspecs ();
2645 declspecs_add_attrs (specs, attrs);
2648 c_parser_declspecs (parser, specs, true, true, true);
2649 finish_declspecs (specs);
2650 pending_xref_error ();
2651 prefix_attrs = specs->attrs;
2652 specs->attrs = NULL_TREE;
2653 declarator = c_parser_declarator (parser, specs->type_seen_p,
2654 C_DTR_PARM, &dummy);
2655 if (declarator == NULL)
2657 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
2660 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2661 postfix_attrs = c_parser_attributes (parser);
2662 return build_c_parm (specs, chainon (postfix_attrs, prefix_attrs),
2666 /* Parse a string literal in an asm expression. It should not be
2667 translated, and wide string literals are an error although
2668 permitted by the syntax. This is a GNU extension.
2673 ??? At present, following the old parser, the caller needs to have
2674 set lex_untranslated_string to 1. It would be better to follow the
2675 C++ parser rather than using this kludge. */
2678 c_parser_asm_string_literal (c_parser *parser)
2681 if (c_parser_next_token_is (parser, CPP_STRING))
2683 str = c_parser_peek_token (parser)->value;
2684 c_parser_consume_token (parser);
2686 else if (c_parser_next_token_is (parser, CPP_WSTRING))
2688 error_at (c_parser_peek_token (parser)->location,
2689 "wide string literal in %<asm%>");
2690 str = build_string (1, "");
2691 c_parser_consume_token (parser);
2695 c_parser_error (parser, "expected string literal");
2701 /* Parse a simple asm expression. This is used in restricted
2702 contexts, where a full expression with inputs and outputs does not
2703 make sense. This is a GNU extension.
2706 asm ( asm-string-literal )
2710 c_parser_simple_asm_expr (c_parser *parser)
2713 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
2714 /* ??? Follow the C++ parser rather than using the
2715 lex_untranslated_string kludge. */
2716 parser->lex_untranslated_string = true;
2717 c_parser_consume_token (parser);
2718 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2720 parser->lex_untranslated_string = false;
2723 str = c_parser_asm_string_literal (parser);
2724 parser->lex_untranslated_string = false;
2725 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
2727 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
2733 /* Parse (possibly empty) attributes. This is a GNU extension.
2737 attributes attribute
2740 __attribute__ ( ( attribute-list ) )
2744 attribute_list , attrib
2749 any-word ( identifier )
2750 any-word ( identifier , nonempty-expr-list )
2751 any-word ( expr-list )
2753 where the "identifier" must not be declared as a type, and
2754 "any-word" may be any identifier (including one declared as a
2755 type), a reserved word storage class specifier, type specifier or
2756 type qualifier. ??? This still leaves out most reserved keywords
2757 (following the old parser), shouldn't we include them, and why not
2758 allow identifiers declared as types to start the arguments? */
2761 c_parser_attributes (c_parser *parser)
2763 tree attrs = NULL_TREE;
2764 while (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2766 /* ??? Follow the C++ parser rather than using the
2767 lex_untranslated_string kludge. */
2768 parser->lex_untranslated_string = true;
2769 c_parser_consume_token (parser);
2770 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2772 parser->lex_untranslated_string = false;
2775 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2777 parser->lex_untranslated_string = false;
2778 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
2781 /* Parse the attribute list. */
2782 while (c_parser_next_token_is (parser, CPP_COMMA)
2783 || c_parser_next_token_is (parser, CPP_NAME)
2784 || c_parser_next_token_is (parser, CPP_KEYWORD))
2786 tree attr, attr_name, attr_args;
2787 if (c_parser_next_token_is (parser, CPP_COMMA))
2789 c_parser_consume_token (parser);
2792 if (c_parser_next_token_is (parser, CPP_KEYWORD))
2794 /* ??? See comment above about what keywords are
2797 switch (c_parser_peek_token (parser)->keyword)
2834 /* Accept __attribute__((__const)) as __attribute__((const))
2837 = ridpointers[(int) c_parser_peek_token (parser)->keyword];
2840 attr_name = c_parser_peek_token (parser)->value;
2841 c_parser_consume_token (parser);
2842 if (c_parser_next_token_is_not (parser, CPP_OPEN_PAREN))
2844 attr = build_tree_list (attr_name, NULL_TREE);
2845 attrs = chainon (attrs, attr);
2848 c_parser_consume_token (parser);
2849 /* Parse the attribute contents. If they start with an
2850 identifier which is followed by a comma or close
2851 parenthesis, then the arguments start with that
2852 identifier; otherwise they are an expression list. */
2853 if (c_parser_next_token_is (parser, CPP_NAME)
2854 && c_parser_peek_token (parser)->id_kind == C_ID_ID
2855 && ((c_parser_peek_2nd_token (parser)->type == CPP_COMMA)
2856 || (c_parser_peek_2nd_token (parser)->type
2857 == CPP_CLOSE_PAREN)))
2859 tree arg1 = c_parser_peek_token (parser)->value;
2860 c_parser_consume_token (parser);
2861 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2862 attr_args = build_tree_list (NULL_TREE, arg1);
2865 c_parser_consume_token (parser);
2866 attr_args = tree_cons (NULL_TREE, arg1,
2867 c_parser_expr_list (parser, false,
2873 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2874 attr_args = NULL_TREE;
2876 attr_args = c_parser_expr_list (parser, false, true);
2878 attr = build_tree_list (attr_name, attr_args);
2879 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2880 c_parser_consume_token (parser);
2883 parser->lex_untranslated_string = false;
2884 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2888 attrs = chainon (attrs, attr);
2890 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2891 c_parser_consume_token (parser);
2894 parser->lex_untranslated_string = false;
2895 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2899 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2900 c_parser_consume_token (parser);
2903 parser->lex_untranslated_string = false;
2904 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2908 parser->lex_untranslated_string = false;
2913 /* Parse a type name (C90 6.5.5, C99 6.7.6).
2916 specifier-qualifier-list abstract-declarator[opt]
2919 static struct c_type_name *
2920 c_parser_type_name (c_parser *parser)
2922 struct c_declspecs *specs = build_null_declspecs ();
2923 struct c_declarator *declarator;
2924 struct c_type_name *ret;
2926 c_parser_declspecs (parser, specs, false, true, true);
2927 if (!specs->declspecs_seen_p)
2929 c_parser_error (parser, "expected specifier-qualifier-list");
2932 pending_xref_error ();
2933 finish_declspecs (specs);
2934 declarator = c_parser_declarator (parser, specs->type_seen_p,
2935 C_DTR_ABSTRACT, &dummy);
2936 if (declarator == NULL)
2938 ret = XOBNEW (&parser_obstack, struct c_type_name);
2940 ret->declarator = declarator;
2944 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
2947 assignment-expression
2948 { initializer-list }
2949 { initializer-list , }
2952 designation[opt] initializer
2953 initializer-list , designation[opt] initializer
2960 designator-list designator
2967 [ constant-expression ]
2979 [ constant-expression ... constant-expression ]
2981 Any expression without commas is accepted in the syntax for the
2982 constant-expressions, with non-constant expressions rejected later.
2984 This function is only used for top-level initializers; for nested
2985 ones, see c_parser_initval. */
2987 static struct c_expr
2988 c_parser_initializer (c_parser *parser)
2990 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
2991 return c_parser_braced_init (parser, NULL_TREE, false);
2995 ret = c_parser_expr_no_commas (parser, NULL);
2996 if (TREE_CODE (ret.value) != STRING_CST
2997 && TREE_CODE (ret.value) != COMPOUND_LITERAL_EXPR)
2998 ret = default_function_array_conversion (ret);
3003 /* Parse a braced initializer list. TYPE is the type specified for a
3004 compound literal, and NULL_TREE for other initializers and for
3005 nested braced lists. NESTED_P is true for nested braced lists,
3006 false for the list of a compound literal or the list that is the
3007 top-level initializer in a declaration. */
3009 static struct c_expr
3010 c_parser_braced_init (c_parser *parser, tree type, bool nested_p)
3012 location_t brace_loc = c_parser_peek_token (parser)->location;
3013 gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE));
3014 c_parser_consume_token (parser);
3016 push_init_level (0);
3018 really_start_incremental_init (type);
3019 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3021 pedwarn (brace_loc, OPT_pedantic, "ISO C forbids empty initializer braces");
3025 /* Parse a non-empty initializer list, possibly with a trailing
3029 c_parser_initelt (parser);
3032 if (c_parser_next_token_is (parser, CPP_COMMA))
3033 c_parser_consume_token (parser);
3036 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3040 if (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE))
3043 ret.value = error_mark_node;
3044 ret.original_code = ERROR_MARK;
3045 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, "expected %<}%>");
3049 c_parser_consume_token (parser);
3050 return pop_init_level (0);
3053 /* Parse a nested initializer, including designators. */
3056 c_parser_initelt (c_parser *parser)
3058 /* Parse any designator or designator list. A single array
3059 designator may have the subsequent "=" omitted in GNU C, but a
3060 longer list or a structure member designator may not. */
3061 if (c_parser_next_token_is (parser, CPP_NAME)
3062 && c_parser_peek_2nd_token (parser)->type == CPP_COLON)
3064 /* Old-style structure member designator. */
3065 set_init_label (c_parser_peek_token (parser)->value);
3066 /* Use the colon as the error location. */
3067 pedwarn (c_parser_peek_2nd_token (parser)->location, OPT_pedantic,
3068 "obsolete use of designated initializer with %<:%>");
3069 c_parser_consume_token (parser);
3070 c_parser_consume_token (parser);
3074 /* des_seen is 0 if there have been no designators, 1 if there
3075 has been a single array designator and 2 otherwise. */
3077 /* Location of a designator. */
3078 location_t des_loc = UNKNOWN_LOCATION; /* Quiet warning. */
3079 while (c_parser_next_token_is (parser, CPP_OPEN_SQUARE)
3080 || c_parser_next_token_is (parser, CPP_DOT))
3082 int des_prev = des_seen;
3084 des_loc = c_parser_peek_token (parser)->location;
3087 if (c_parser_next_token_is (parser, CPP_DOT))
3090 c_parser_consume_token (parser);
3091 if (c_parser_next_token_is (parser, CPP_NAME))
3093 set_init_label (c_parser_peek_token (parser)->value);
3094 c_parser_consume_token (parser);
3099 init.value = error_mark_node;
3100 init.original_code = ERROR_MARK;
3101 c_parser_error (parser, "expected identifier");
3102 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
3103 process_init_element (init, false);
3110 location_t ellipsis_loc = UNKNOWN_LOCATION; /* Quiet warning. */
3111 /* ??? Following the old parser, [ objc-receiver
3112 objc-message-args ] is accepted as an initializer,
3113 being distinguished from a designator by what follows
3114 the first assignment expression inside the square
3115 brackets, but after a first array designator a
3116 subsequent square bracket is for Objective-C taken to
3117 start an expression, using the obsolete form of
3118 designated initializer without '=', rather than
3119 possibly being a second level of designation: in LALR
3120 terms, the '[' is shifted rather than reducing
3121 designator to designator-list. */
3122 if (des_prev == 1 && c_dialect_objc ())
3124 des_seen = des_prev;
3127 if (des_prev == 0 && c_dialect_objc ())
3129 /* This might be an array designator or an
3130 Objective-C message expression. If the former,
3131 continue parsing here; if the latter, parse the
3132 remainder of the initializer given the starting
3133 primary-expression. ??? It might make sense to
3134 distinguish when des_prev == 1 as well; see
3135 previous comment. */
3137 struct c_expr mexpr;
3138 c_parser_consume_token (parser);
3139 if (c_parser_peek_token (parser)->type == CPP_NAME
3140 && ((c_parser_peek_token (parser)->id_kind
3142 || (c_parser_peek_token (parser)->id_kind
3143 == C_ID_CLASSNAME)))
3145 /* Type name receiver. */
3146 tree id = c_parser_peek_token (parser)->value;
3147 c_parser_consume_token (parser);
3148 rec = objc_get_class_reference (id);
3149 goto parse_message_args;
3151 first = c_parser_expr_no_commas (parser, NULL).value;
3152 if (c_parser_next_token_is (parser, CPP_ELLIPSIS)
3153 || c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3154 goto array_desig_after_first;
3155 /* Expression receiver. So far only one part
3156 without commas has been parsed; there might be
3157 more of the expression. */
3159 while (c_parser_next_token_is (parser, CPP_COMMA))
3162 c_parser_consume_token (parser);
3163 next = c_parser_expr_no_commas (parser, NULL);
3164 next = default_function_array_conversion (next);
3165 rec = build_compound_expr (rec, next.value);
3168 /* Now parse the objc-message-args. */
3169 args = c_parser_objc_message_args (parser);
3170 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
3173 = objc_build_message_expr (build_tree_list (rec, args));
3174 mexpr.original_code = ERROR_MARK;
3175 /* Now parse and process the remainder of the
3176 initializer, starting with this message
3177 expression as a primary-expression. */
3178 c_parser_initval (parser, &mexpr);
3181 c_parser_consume_token (parser);
3182 first = c_parser_expr_no_commas (parser, NULL).value;
3183 array_desig_after_first:
3184 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
3186 ellipsis_loc = c_parser_peek_token (parser)->location;
3187 c_parser_consume_token (parser);
3188 second = c_parser_expr_no_commas (parser, NULL).value;
3192 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3194 c_parser_consume_token (parser);
3195 set_init_index (first, second);
3197 pedwarn (ellipsis_loc, OPT_pedantic,
3198 "ISO C forbids specifying range of elements to initialize");
3201 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
3207 if (c_parser_next_token_is (parser, CPP_EQ))
3210 pedwarn (des_loc, OPT_pedantic,
3211 "ISO C90 forbids specifying subobject to initialize");
3212 c_parser_consume_token (parser);
3217 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
3218 "obsolete use of designated initializer without %<=%>");
3222 init.value = error_mark_node;
3223 init.original_code = ERROR_MARK;
3224 c_parser_error (parser, "expected %<=%>");
3225 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
3226 process_init_element (init, false);
3232 c_parser_initval (parser, NULL);
3235 /* Parse a nested initializer; as c_parser_initializer but parses
3236 initializers within braced lists, after any designators have been
3237 applied. If AFTER is not NULL then it is an Objective-C message
3238 expression which is the primary-expression starting the
3242 c_parser_initval (c_parser *parser, struct c_expr *after)
3245 gcc_assert (!after || c_dialect_objc ());
3246 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE) && !after)
3247 init = c_parser_braced_init (parser, NULL_TREE, true);
3250 init = c_parser_expr_no_commas (parser, after);
3251 if (init.value != NULL_TREE
3252 && TREE_CODE (init.value) != STRING_CST
3253 && TREE_CODE (init.value) != COMPOUND_LITERAL_EXPR)
3254 init = default_function_array_conversion (init);
3256 process_init_element (init, false);
3259 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
3263 { block-item-list[opt] }
3264 { label-declarations block-item-list }
3268 block-item-list block-item
3280 { label-declarations block-item-list }
3283 __extension__ nested-declaration
3284 nested-function-definition
3288 label-declarations label-declaration
3291 __label__ identifier-list ;
3293 Allowing the mixing of declarations and code is new in C99. The
3294 GNU syntax also permits (not shown above) labels at the end of
3295 compound statements, which yield an error. We don't allow labels
3296 on declarations; this might seem like a natural extension, but
3297 there would be a conflict between attributes on the label and
3298 prefix attributes on the declaration. ??? The syntax follows the
3299 old parser in requiring something after label declarations.
3300 Although they are erroneous if the labels declared aren't defined,
3301 is it useful for the syntax to be this way?
3313 c_parser_compound_statement (c_parser *parser)
3316 if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
3318 /* Ensure a scope is entered and left anyway to avoid confusion
3319 if we have just prepared to enter a function body. */
3320 stmt = c_begin_compound_stmt (true);
3321 c_end_compound_stmt (stmt, true);
3322 return error_mark_node;
3324 stmt = c_begin_compound_stmt (true);
3325 c_parser_compound_statement_nostart (parser);
3326 return c_end_compound_stmt (stmt, true);
3329 /* Parse a compound statement except for the opening brace. This is
3330 used for parsing both compound statements and statement expressions
3331 (which follow different paths to handling the opening). */
3334 c_parser_compound_statement_nostart (c_parser *parser)
3336 bool last_stmt = false;
3337 bool last_label = false;
3338 location_t label_loc = UNKNOWN_LOCATION; /* Quiet warning. */
3339 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3341 c_parser_consume_token (parser);
3344 if (c_parser_next_token_is_keyword (parser, RID_LABEL))
3346 location_t err_loc = c_parser_peek_token (parser)->location;
3347 /* Read zero or more forward-declarations for labels that nested
3348 functions can jump to. */
3349 while (c_parser_next_token_is_keyword (parser, RID_LABEL))
3351 c_parser_consume_token (parser);
3352 /* Any identifiers, including those declared as type names,
3357 if (c_parser_next_token_is_not (parser, CPP_NAME))
3359 c_parser_error (parser, "expected identifier");
3363 = declare_label (c_parser_peek_token (parser)->value);
3364 C_DECLARED_LABEL_FLAG (label) = 1;
3365 add_stmt (build_stmt (DECL_EXPR, label));
3366 c_parser_consume_token (parser);
3367 if (c_parser_next_token_is (parser, CPP_COMMA))
3368 c_parser_consume_token (parser);
3372 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
3374 pedwarn (err_loc, OPT_pedantic, "ISO C forbids label declarations");
3376 /* We must now have at least one statement, label or declaration. */
3377 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3379 c_parser_error (parser, "expected declaration or statement");
3380 c_parser_consume_token (parser);
3383 while (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE))
3385 location_t loc = c_parser_peek_token (parser)->location;
3386 if (c_parser_next_token_is_keyword (parser, RID_CASE)
3387 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
3388 || (c_parser_next_token_is (parser, CPP_NAME)
3389 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3391 if (c_parser_next_token_is_keyword (parser, RID_CASE))
3392 label_loc = c_parser_peek_2nd_token (parser)->location;
3394 label_loc = c_parser_peek_token (parser)->location;
3397 c_parser_label (parser);
3399 else if (!last_label
3400 && c_parser_next_token_starts_declspecs (parser))
3403 c_parser_declaration_or_fndef (parser, true, true, true, true);
3406 (pedantic && !flag_isoc99)
3408 : OPT_Wdeclaration_after_statement,
3409 "ISO C90 forbids mixed declarations and code");
3412 else if (!last_label
3413 && c_parser_next_token_is_keyword (parser, RID_EXTENSION))
3415 /* __extension__ can start a declaration, but is also an
3416 unary operator that can start an expression. Consume all
3417 but the last of a possible series of __extension__ to
3419 while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD
3420 && (c_parser_peek_2nd_token (parser)->keyword
3422 c_parser_consume_token (parser);
3423 if (c_token_starts_declspecs (c_parser_peek_2nd_token (parser)))
3426 ext = disable_extension_diagnostics ();
3427 c_parser_consume_token (parser);
3429 c_parser_declaration_or_fndef (parser, true, true, true, true);
3430 /* Following the old parser, __extension__ does not
3431 disable this diagnostic. */
3432 restore_extension_diagnostics (ext);
3434 pedwarn_c90 (loc, (pedantic && !flag_isoc99)
3436 : OPT_Wdeclaration_after_statement,
3437 "ISO C90 forbids mixed declarations and code");
3443 else if (c_parser_next_token_is (parser, CPP_PRAGMA))
3445 /* External pragmas, and some omp pragmas, are not associated
3446 with regular c code, and so are not to be considered statements
3447 syntactically. This ensures that the user doesn't put them
3448 places that would turn into syntax errors if the directive
3450 if (c_parser_pragma (parser, pragma_compound))
3451 last_label = false, last_stmt = true;
3453 else if (c_parser_next_token_is (parser, CPP_EOF))
3455 c_parser_error (parser, "expected declaration or statement");
3458 else if (c_parser_next_token_is_keyword (parser, RID_ELSE))
3460 if (parser->in_if_block)
3462 error_at (loc, """expected %<}%> before %<else%>");
3467 error_at (loc, "%<else%> without a previous %<if%>");
3468 c_parser_consume_token (parser);
3477 c_parser_statement_after_labels (parser);
3480 parser->error = false;
3483 error_at (label_loc, "label at end of compound statement");
3484 c_parser_consume_token (parser);
3487 /* Parse a label (C90 6.6.1, C99 6.8.1).
3490 identifier : attributes[opt]
3491 case constant-expression :
3497 case constant-expression ... constant-expression :
3499 The use of attributes on labels is a GNU extension. The syntax in
3500 GNU C accepts any expressions without commas, non-constant
3501 expressions being rejected later. */
3504 c_parser_label (c_parser *parser)
3506 location_t loc1 = c_parser_peek_token (parser)->location;
3507 tree label = NULL_TREE;
3508 if (c_parser_next_token_is_keyword (parser, RID_CASE))
3511 c_parser_consume_token (parser);
3512 exp1 = c_parser_expr_no_commas (parser, NULL).value;
3513 if (c_parser_next_token_is (parser, CPP_COLON))
3515 c_parser_consume_token (parser);
3516 label = do_case (exp1, NULL_TREE);
3518 else if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
3520 c_parser_consume_token (parser);
3521 exp2 = c_parser_expr_no_commas (parser, NULL).value;
3522 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
3523 label = do_case (exp1, exp2);
3526 c_parser_error (parser, "expected %<:%> or %<...%>");
3528 else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT))
3530 c_parser_consume_token (parser);
3531 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
3532 label = do_case (NULL_TREE, NULL_TREE);
3536 tree name = c_parser_peek_token (parser)->value;
3539 location_t loc2 = c_parser_peek_token (parser)->location;
3540 gcc_assert (c_parser_next_token_is (parser, CPP_NAME));
3541 c_parser_consume_token (parser);
3542 gcc_assert (c_parser_next_token_is (parser, CPP_COLON));
3543 c_parser_consume_token (parser);
3544 attrs = c_parser_attributes (parser);
3545 tlab = define_label (loc2, name);
3548 decl_attributes (&tlab, attrs, 0);
3549 label = add_stmt (build_stmt (LABEL_EXPR, tlab));
3554 SET_EXPR_LOCATION (label, loc1);
3555 if (c_parser_next_token_starts_declspecs (parser)
3556 && !(c_parser_next_token_is (parser, CPP_NAME)
3557 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3559 error_at (c_parser_peek_token (parser)->location,
3560 "a label can only be part of a statement and "
3561 "a declaration is not a statement");
3562 c_parser_declaration_or_fndef (parser, /*fndef_ok*/ false,
3563 /*nested*/ true, /*empty_ok*/ false,
3564 /*start_attr_ok*/ true);
3569 /* Parse a statement (C90 6.6, C99 6.8).
3574 expression-statement
3582 expression-statement:
3585 selection-statement:
3589 iteration-statement:
3598 return expression[opt] ;
3611 objc-throw-statement
3612 objc-try-catch-statement
3613 objc-synchronized-statement
3615 objc-throw-statement:
3629 parallel-for-construct
3630 parallel-sections-construct
3637 parallel-directive structured-block
3640 for-directive iteration-statement
3643 sections-directive section-scope
3646 single-directive structured-block
3648 parallel-for-construct:
3649 parallel-for-directive iteration-statement
3651 parallel-sections-construct:
3652 parallel-sections-directive section-scope
3655 master-directive structured-block
3658 critical-directive structured-block
3661 atomic-directive expression-statement
3664 ordered-directive structured-block */
3667 c_parser_statement (c_parser *parser)
3669 while (c_parser_next_token_is_keyword (parser, RID_CASE)
3670 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
3671 || (c_parser_next_token_is (parser, CPP_NAME)
3672 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3673 c_parser_label (parser);
3674 c_parser_statement_after_labels (parser);
3677 /* Parse a statement, other than a labeled statement. */
3680 c_parser_statement_after_labels (c_parser *parser)
3682 location_t loc = c_parser_peek_token (parser)->location;
3683 tree stmt = NULL_TREE;
3684 bool in_if_block = parser->in_if_block;
3685 parser->in_if_block = false;
3686 switch (c_parser_peek_token (parser)->type)
3688 case CPP_OPEN_BRACE:
3689 add_stmt (c_parser_compound_statement (parser));
3692 switch (c_parser_peek_token (parser)->keyword)
3695 c_parser_if_statement (parser);
3698 c_parser_switch_statement (parser);
3701 c_parser_while_statement (parser);
3704 c_parser_do_statement (parser);
3707 c_parser_for_statement (parser);
3710 c_parser_consume_token (parser);
3711 if (c_parser_next_token_is (parser, CPP_NAME))
3713 stmt = c_finish_goto_label (c_parser_peek_token (parser)->value);
3714 c_parser_consume_token (parser);
3716 else if (c_parser_next_token_is (parser, CPP_MULT))
3718 c_parser_consume_token (parser);
3719 stmt = c_finish_goto_ptr (c_parser_expression (parser).value);
3722 c_parser_error (parser, "expected identifier or %<*%>");
3723 goto expect_semicolon;
3725 c_parser_consume_token (parser);
3726 stmt = c_finish_bc_stmt (&c_cont_label, false);
3727 goto expect_semicolon;
3729 c_parser_consume_token (parser);
3730 stmt = c_finish_bc_stmt (&c_break_label, true);
3731 goto expect_semicolon;
3733 c_parser_consume_token (parser);
3734 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3736 stmt = c_finish_return (NULL_TREE);
3737 c_parser_consume_token (parser);
3741 stmt = c_finish_return (c_parser_expression_conv (parser).value);
3742 goto expect_semicolon;
3746 stmt = c_parser_asm_statement (parser);
3749 gcc_assert (c_dialect_objc ());
3750 c_parser_consume_token (parser);
3751 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3753 stmt = objc_build_throw_stmt (NULL_TREE);
3754 c_parser_consume_token (parser);
3758 tree expr = c_parser_expression (parser).value;
3759 expr = c_fully_fold (expr, false, NULL);
3760 stmt = objc_build_throw_stmt (expr);
3761 goto expect_semicolon;
3765 gcc_assert (c_dialect_objc ());
3766 c_parser_objc_try_catch_statement (parser);
3768 case RID_AT_SYNCHRONIZED:
3769 gcc_assert (c_dialect_objc ());
3770 c_parser_objc_synchronized_statement (parser);
3777 c_parser_consume_token (parser);
3779 case CPP_CLOSE_PAREN:
3780 case CPP_CLOSE_SQUARE:
3781 /* Avoid infinite loop in error recovery:
3782 c_parser_skip_until_found stops at a closing nesting
3783 delimiter without consuming it, but here we need to consume
3784 it to proceed further. */
3785 c_parser_error (parser, "expected statement");
3786 c_parser_consume_token (parser);
3789 c_parser_pragma (parser, pragma_stmt);
3793 stmt = c_finish_expr_stmt (c_parser_expression_conv (parser).value);
3795 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
3798 /* Two cases cannot and do not have line numbers associated: If stmt
3799 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
3800 cannot hold line numbers. But that's OK because the statement
3801 will either be changed to a MODIFY_EXPR during gimplification of
3802 the statement expr, or discarded. If stmt was compound, but
3803 without new variables, we will have skipped the creation of a
3804 BIND and will have a bare STATEMENT_LIST. But that's OK because
3805 (recursively) all of the component statements should already have
3806 line numbers assigned. ??? Can we discard no-op statements
3808 protected_set_expr_location (stmt, loc);
3810 parser->in_if_block = in_if_block;
3813 /* Parse the condition from an if, do, while or for statements. */
3816 c_parser_condition (c_parser *parser)
3820 loc = c_parser_peek_token (parser)->location;
3821 cond = c_parser_expression_conv (parser).value;
3822 cond = c_objc_common_truthvalue_conversion (loc, cond);
3823 cond = c_fully_fold (cond, false, NULL);
3824 protected_set_expr_location (cond, loc);
3825 if (warn_sequence_point)
3826 verify_sequence_points (cond);
3830 /* Parse a parenthesized condition from an if, do or while statement.
3836 c_parser_paren_condition (c_parser *parser)
3839 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3840 return error_mark_node;
3841 cond = c_parser_condition (parser);
3842 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
3846 /* Parse a statement which is a block in C99. */
3849 c_parser_c99_block_statement (c_parser *parser)
3851 tree block = c_begin_compound_stmt (flag_isoc99);
3852 c_parser_statement (parser);
3853 return c_end_compound_stmt (block, flag_isoc99);
3856 /* Parse the body of an if statement. This is just parsing a
3857 statement but (a) it is a block in C99, (b) we track whether the
3858 body is an if statement for the sake of -Wparentheses warnings, (c)
3859 we handle an empty body specially for the sake of -Wempty-body
3860 warnings, and (d) we call parser_compound_statement directly
3861 because c_parser_statement_after_labels resets
3862 parser->in_if_block. */
3865 c_parser_if_body (c_parser *parser, bool *if_p)
3867 tree block = c_begin_compound_stmt (flag_isoc99);
3868 while (c_parser_next_token_is_keyword (parser, RID_CASE)
3869 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
3870 || (c_parser_next_token_is (parser, CPP_NAME)
3871 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3872 c_parser_label (parser);
3873 *if_p = c_parser_next_token_is_keyword (parser, RID_IF);
3874 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3876 location_t loc = c_parser_peek_token (parser)->location;
3877 add_stmt (build_empty_stmt ());
3878 c_parser_consume_token (parser);
3879 if (!c_parser_next_token_is_keyword (parser, RID_ELSE))
3880 warning_at (loc, OPT_Wempty_body,
3881 "suggest braces around empty body in an %<if%> statement");
3883 else if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
3884 add_stmt (c_parser_compound_statement (parser));
3886 c_parser_statement_after_labels (parser);
3887 return c_end_compound_stmt (block, flag_isoc99);
3890 /* Parse the else body of an if statement. This is just parsing a
3891 statement but (a) it is a block in C99, (b) we handle an empty body
3892 specially for the sake of -Wempty-body warnings. */
3895 c_parser_else_body (c_parser *parser)
3897 tree block = c_begin_compound_stmt (flag_isoc99);
3898 while (c_parser_next_token_is_keyword (parser, RID_CASE)
3899 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
3900 || (c_parser_next_token_is (parser, CPP_NAME)
3901 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3902 c_parser_label (parser);
3903 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3905 warning_at (c_parser_peek_token (parser)->location,
3907 "suggest braces around empty body in an %<else%> statement");
3908 add_stmt (build_empty_stmt ());
3909 c_parser_consume_token (parser);
3912 c_parser_statement_after_labels (parser);
3913 return c_end_compound_stmt (block, flag_isoc99);
3916 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
3919 if ( expression ) statement
3920 if ( expression ) statement else statement
3924 c_parser_if_statement (c_parser *parser)
3929 bool first_if = false;
3930 tree first_body, second_body;
3933 gcc_assert (c_parser_next_token_is_keyword (parser, RID_IF));
3934 c_parser_consume_token (parser);
3935 block = c_begin_compound_stmt (flag_isoc99);
3936 loc = c_parser_peek_token (parser)->location;
3937 cond = c_parser_paren_condition (parser);
3938 in_if_block = parser->in_if_block;
3939 parser->in_if_block = true;
3940 first_body = c_parser_if_body (parser, &first_if);
3941 parser->in_if_block = in_if_block;
3942 if (c_parser_next_token_is_keyword (parser, RID_ELSE))
3944 c_parser_consume_token (parser);
3945 second_body = c_parser_else_body (parser);
3948 second_body = NULL_TREE;
3949 c_finish_if_stmt (loc, cond, first_body, second_body, first_if);
3950 add_stmt (c_end_compound_stmt (block, flag_isoc99));
3953 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
3956 switch (expression) statement
3960 c_parser_switch_statement (c_parser *parser)
3962 tree block, expr, body, save_break;
3963 gcc_assert (c_parser_next_token_is_keyword (parser, RID_SWITCH));
3964 c_parser_consume_token (parser);
3965 block = c_begin_compound_stmt (flag_isoc99);
3966 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3968 expr = c_parser_expression (parser).value;
3969 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
3972 expr = error_mark_node;
3973 c_start_case (expr);
3974 save_break = c_break_label;
3975 c_break_label = NULL_TREE;
3976 body = c_parser_c99_block_statement (parser);
3977 c_finish_case (body);
3979 add_stmt (build1 (LABEL_EXPR, void_type_node, c_break_label));
3980 c_break_label = save_break;
3981 add_stmt (c_end_compound_stmt (block, flag_isoc99));
3984 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
3987 while (expression) statement
3991 c_parser_while_statement (c_parser *parser)
3993 tree block, cond, body, save_break, save_cont;
3995 gcc_assert (c_parser_next_token_is_keyword (parser, RID_WHILE));
3996 c_parser_consume_token (parser);
3997 block = c_begin_compound_stmt (flag_isoc99);
3998 loc = c_parser_peek_token (parser)->location;
3999 cond = c_parser_paren_condition (parser);
4000 save_break = c_break_label;
4001 c_break_label = NULL_TREE;
4002 save_cont = c_cont_label;
4003 c_cont_label = NULL_TREE;
4004 body = c_parser_c99_block_statement (parser);
4005 c_finish_loop (loc, cond, NULL, body, c_break_label, c_cont_label, true);
4006 add_stmt (c_end_compound_stmt (block, flag_isoc99));
4007 c_break_label = save_break;
4008 c_cont_label = save_cont;
4011 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
4014 do statement while ( expression ) ;
4018 c_parser_do_statement (c_parser *parser)
4020 tree block, cond, body, save_break, save_cont, new_break, new_cont;
4022 gcc_assert (c_parser_next_token_is_keyword (parser, RID_DO));
4023 c_parser_consume_token (parser);
4024 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4025 warning_at (c_parser_peek_token (parser)->location,
4027 "suggest braces around empty body in %<do%> statement");
4028 block = c_begin_compound_stmt (flag_isoc99);
4029 loc = c_parser_peek_token (parser)->location;
4030 save_break = c_break_label;
4031 c_break_label = NULL_TREE;
4032 save_cont = c_cont_label;
4033 c_cont_label = NULL_TREE;
4034 body = c_parser_c99_block_statement (parser);
4035 c_parser_require_keyword (parser, RID_WHILE, "expected %<while%>");
4036 new_break = c_break_label;
4037 c_break_label = save_break;
4038 new_cont = c_cont_label;
4039 c_cont_label = save_cont;
4040 cond = c_parser_paren_condition (parser);
4041 if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
4042 c_parser_skip_to_end_of_block_or_statement (parser);
4043 c_finish_loop (loc, cond, NULL, body, new_break, new_cont, false);
4044 add_stmt (c_end_compound_stmt (block, flag_isoc99));
4047 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
4050 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
4051 for ( nested-declaration expression[opt] ; expression[opt] ) statement
4053 The form with a declaration is new in C99.
4055 ??? In accordance with the old parser, the declaration may be a
4056 nested function, which is then rejected in check_for_loop_decls,
4057 but does it make any sense for this to be included in the grammar?
4058 Note in particular that the nested function does not include a
4059 trailing ';', whereas the "declaration" production includes one.
4060 Also, can we reject bad declarations earlier and cheaper than
4061 check_for_loop_decls? */
4064 c_parser_for_statement (c_parser *parser)
4066 tree block, cond, incr, save_break, save_cont, body;
4068 gcc_assert (c_parser_next_token_is_keyword (parser, RID_FOR));
4069 loc = c_parser_peek_token (parser)->location;
4070 c_parser_consume_token (parser);
4071 block = c_begin_compound_stmt (flag_isoc99);
4072 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4074 /* Parse the initialization declaration or expression. */
4075 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4077 c_parser_consume_token (parser);
4078 c_finish_expr_stmt (NULL_TREE);
4080 else if (c_parser_next_token_starts_declspecs (parser))
4082 c_parser_declaration_or_fndef (parser, true, true, true, true);
4083 check_for_loop_decls ();
4085 else if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
4087 /* __extension__ can start a declaration, but is also an
4088 unary operator that can start an expression. Consume all
4089 but the last of a possible series of __extension__ to
4091 while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD
4092 && (c_parser_peek_2nd_token (parser)->keyword
4094 c_parser_consume_token (parser);
4095 if (c_token_starts_declspecs (c_parser_peek_2nd_token (parser)))
4098 ext = disable_extension_diagnostics ();
4099 c_parser_consume_token (parser);
4100 c_parser_declaration_or_fndef (parser, true, true, true, true);
4101 restore_extension_diagnostics (ext);
4102 check_for_loop_decls ();
4110 c_finish_expr_stmt (c_parser_expression (parser).value);
4111 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4113 /* Parse the loop condition. */
4114 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4116 c_parser_consume_token (parser);
4121 cond = c_parser_condition (parser);
4122 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4124 /* Parse the increment expression. */
4125 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4126 incr = c_process_expr_stmt (NULL_TREE);
4128 incr = c_process_expr_stmt (c_parser_expression (parser).value);
4129 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4133 cond = error_mark_node;
4134 incr = error_mark_node;
4136 save_break = c_break_label;
4137 c_break_label = NULL_TREE;
4138 save_cont = c_cont_label;
4139 c_cont_label = NULL_TREE;
4140 body = c_parser_c99_block_statement (parser);
4141 c_finish_loop (loc, cond, incr, body, c_break_label, c_cont_label, true);
4142 add_stmt (c_end_compound_stmt (block, flag_isoc99));
4143 c_break_label = save_break;
4144 c_cont_label = save_cont;
4147 /* Parse an asm statement, a GNU extension. This is a full-blown asm
4148 statement with inputs, outputs, clobbers, and volatile tag
4152 asm type-qualifier[opt] ( asm-argument ) ;
4156 asm-string-literal : asm-operands[opt]
4157 asm-string-literal : asm-operands[opt] : asm-operands[opt]
4158 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers
4160 Qualifiers other than volatile are accepted in the syntax but
4164 c_parser_asm_statement (c_parser *parser)
4166 tree quals, str, outputs, inputs, clobbers, ret;
4168 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
4169 c_parser_consume_token (parser);
4170 if (c_parser_next_token_is_keyword (parser, RID_VOLATILE))
4172 quals = c_parser_peek_token (parser)->value;
4173 c_parser_consume_token (parser);
4175 else if (c_parser_next_token_is_keyword (parser, RID_CONST)
4176 || c_parser_next_token_is_keyword (parser, RID_RESTRICT))
4178 warning_at (c_parser_peek_token (parser)->location,
4180 "%E qualifier ignored on asm",
4181 c_parser_peek_token (parser)->value);
4183 c_parser_consume_token (parser);
4187 /* ??? Follow the C++ parser rather than using the
4188 lex_untranslated_string kludge. */
4189 parser->lex_untranslated_string = true;
4190 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4192 parser->lex_untranslated_string = false;
4195 str = c_parser_asm_string_literal (parser);
4196 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4199 outputs = NULL_TREE;
4201 clobbers = NULL_TREE;
4204 if (!c_parser_require (parser, CPP_COLON, "expected %<:%> or %<)%>"))
4206 parser->lex_untranslated_string = false;
4207 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4211 /* Parse outputs. */
4212 if (c_parser_next_token_is (parser, CPP_COLON)
4213 || c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4214 outputs = NULL_TREE;
4216 outputs = c_parser_asm_operands (parser, false);
4217 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4220 clobbers = NULL_TREE;
4223 if (!c_parser_require (parser, CPP_COLON, "expected %<:%> or %<)%>"))
4225 parser->lex_untranslated_string = false;
4226 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4230 if (c_parser_next_token_is (parser, CPP_COLON)
4231 || c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4234 inputs = c_parser_asm_operands (parser, true);
4235 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4237 clobbers = NULL_TREE;
4240 if (!c_parser_require (parser, CPP_COLON, "expected %<:%> or %<)%>"))
4242 parser->lex_untranslated_string = false;
4243 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4246 /* Parse clobbers. */
4247 clobbers = c_parser_asm_clobbers (parser);
4249 parser->lex_untranslated_string = false;
4250 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
4252 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4255 if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
4256 c_parser_skip_to_end_of_block_or_statement (parser);
4257 ret = build_asm_stmt (quals, build_asm_expr (str, outputs, inputs,
4262 /* Parse asm operands, a GNU extension. If CONVERT_P (for inputs but
4263 not outputs), apply the default conversion of functions and arrays
4268 asm-operands , asm-operand
4271 asm-string-literal ( expression )
4272 [ identifier ] asm-string-literal ( expression )
4276 c_parser_asm_operands (c_parser *parser, bool convert_p)
4278 tree list = NULL_TREE;
4283 if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
4285 c_parser_consume_token (parser);
4286 if (c_parser_next_token_is (parser, CPP_NAME))
4288 tree id = c_parser_peek_token (parser)->value;
4289 c_parser_consume_token (parser);
4290 name = build_string (IDENTIFIER_LENGTH (id),
4291 IDENTIFIER_POINTER (id));
4295 c_parser_error (parser, "expected identifier");
4296 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
4299 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
4304 str = c_parser_asm_string_literal (parser);
4305 if (str == NULL_TREE)
4307 parser->lex_untranslated_string = false;
4308 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4310 parser->lex_untranslated_string = true;
4313 expr = c_parser_expression (parser);
4315 expr = default_function_array_conversion (expr);
4316 expr.value = c_fully_fold (expr.value, false, NULL);
4317 parser->lex_untranslated_string = true;
4318 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
4320 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4323 list = chainon (list, build_tree_list (build_tree_list (name, str),
4325 if (c_parser_next_token_is (parser, CPP_COMMA))
4326 c_parser_consume_token (parser);
4333 /* Parse asm clobbers, a GNU extension.
4337 asm-clobbers , asm-string-literal
4341 c_parser_asm_clobbers (c_parser *parser)
4343 tree list = NULL_TREE;
4346 tree str = c_parser_asm_string_literal (parser);
4348 list = tree_cons (NULL_TREE, str, list);
4351 if (c_parser_next_token_is (parser, CPP_COMMA))
4352 c_parser_consume_token (parser);
4359 /* Parse an expression other than a compound expression; that is, an
4360 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
4361 NULL then it is an Objective-C message expression which is the
4362 primary-expression starting the expression as an initializer.
4364 assignment-expression:
4365 conditional-expression
4366 unary-expression assignment-operator assignment-expression
4368 assignment-operator: one of
4369 = *= /= %= += -= <<= >>= &= ^= |=
4371 In GNU C we accept any conditional expression on the LHS and
4372 diagnose the invalid lvalue rather than producing a syntax
4375 static struct c_expr
4376 c_parser_expr_no_commas (c_parser *parser, struct c_expr *after)
4378 struct c_expr lhs, rhs, ret;
4379 enum tree_code code;
4380 location_t op_location;
4381 gcc_assert (!after || c_dialect_objc ());
4382 lhs = c_parser_conditional_expression (parser, after);
4383 op_location = c_parser_peek_token (parser)->location;
4384 switch (c_parser_peek_token (parser)->type)
4393 code = TRUNC_DIV_EXPR;
4396 code = TRUNC_MOD_EXPR;
4411 code = BIT_AND_EXPR;
4414 code = BIT_XOR_EXPR;
4417 code = BIT_IOR_EXPR;
4422 c_parser_consume_token (parser);
4423 rhs = c_parser_expr_no_commas (parser, NULL);
4424 rhs = default_function_array_conversion (rhs);
4425 ret.value = build_modify_expr (op_location, lhs.value, code, rhs.value);
4426 if (code == NOP_EXPR)
4427 ret.original_code = MODIFY_EXPR;
4430 TREE_NO_WARNING (ret.value) = 1;
4431 ret.original_code = ERROR_MARK;
4436 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
4437 is not NULL then it is an Objective-C message expression which is
4438 the primary-expression starting the expression as an initializer.
4440 conditional-expression:
4441 logical-OR-expression
4442 logical-OR-expression ? expression : conditional-expression
4446 conditional-expression:
4447 logical-OR-expression ? : conditional-expression
4450 static struct c_expr
4451 c_parser_conditional_expression (c_parser *parser, struct c_expr *after)
4453 struct c_expr cond, exp1, exp2, ret;
4454 location_t cond_loc;
4456 gcc_assert (!after || c_dialect_objc ());
4458 cond_loc = c_parser_peek_token (parser)->location;
4459 cond = c_parser_binary_expression (parser, after);
4460 protected_set_expr_location (cond.value, cond_loc);
4462 if (c_parser_next_token_is_not (parser, CPP_QUERY))
4464 cond = default_function_array_conversion (cond);
4465 c_parser_consume_token (parser);
4466 if (c_parser_next_token_is (parser, CPP_COLON))
4468 tree eptype = NULL_TREE;
4469 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
4470 "ISO C forbids omitting the middle term of a ?: expression");
4471 if (TREE_CODE (cond.value) == EXCESS_PRECISION_EXPR)
4473 eptype = TREE_TYPE (cond.value);
4474 cond.value = TREE_OPERAND (cond.value, 0);
4476 /* Make sure first operand is calculated only once. */
4477 exp1.value = c_save_expr (default_conversion (cond.value));
4479 exp1.value = build1 (EXCESS_PRECISION_EXPR, eptype, exp1.value);
4480 cond.value = c_objc_common_truthvalue_conversion (cond_loc, exp1.value);
4481 skip_evaluation += cond.value == truthvalue_true_node;
4486 = c_objc_common_truthvalue_conversion
4487 (cond_loc, default_conversion (cond.value));
4488 skip_evaluation += cond.value == truthvalue_false_node;
4489 exp1 = c_parser_expression_conv (parser);
4490 skip_evaluation += ((cond.value == truthvalue_true_node)
4491 - (cond.value == truthvalue_false_node));
4493 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
4495 skip_evaluation -= cond.value == truthvalue_true_node;
4496 ret.value = error_mark_node;
4497 ret.original_code = ERROR_MARK;
4500 exp2 = c_parser_conditional_expression (parser, NULL);
4501 exp2 = default_function_array_conversion (exp2);
4502 skip_evaluation -= cond.value == truthvalue_true_node;
4503 ret.value = build_conditional_expr (cond.value,
4504 cond.original_code == C_MAYBE_CONST_EXPR,
4505 exp1.value, exp2.value);
4506 ret.original_code = ERROR_MARK;
4510 /* Parse a binary expression; that is, a logical-OR-expression (C90
4511 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
4512 an Objective-C message expression which is the primary-expression
4513 starting the expression as an initializer.
4515 multiplicative-expression:
4517 multiplicative-expression * cast-expression
4518 multiplicative-expression / cast-expression
4519 multiplicative-expression % cast-expression
4521 additive-expression:
4522 multiplicative-expression
4523 additive-expression + multiplicative-expression
4524 additive-expression - multiplicative-expression
4528 shift-expression << additive-expression
4529 shift-expression >> additive-expression
4531 relational-expression:
4533 relational-expression < shift-expression
4534 relational-expression > shift-expression
4535 relational-expression <= shift-expression
4536 relational-expression >= shift-expression
4538 equality-expression:
4539 relational-expression
4540 equality-expression == relational-expression
4541 equality-expression != relational-expression
4545 AND-expression & equality-expression
4547 exclusive-OR-expression:
4549 exclusive-OR-expression ^ AND-expression
4551 inclusive-OR-expression:
4552 exclusive-OR-expression
4553 inclusive-OR-expression | exclusive-OR-expression
4555 logical-AND-expression:
4556 inclusive-OR-expression
4557 logical-AND-expression && inclusive-OR-expression
4559 logical-OR-expression:
4560 logical-AND-expression
4561 logical-OR-expression || logical-AND-expression
4564 static struct c_expr
4565 c_parser_binary_expression (c_parser *parser, struct c_expr *after)
4567 /* A binary expression is parsed using operator-precedence parsing,
4568 with the operands being cast expressions. All the binary
4569 operators are left-associative. Thus a binary expression is of
4572 E0 op1 E1 op2 E2 ...
4574 which we represent on a stack. On the stack, the precedence
4575 levels are strictly increasing. When a new operator is
4576 encountered of higher precedence than that at the top of the
4577 stack, it is pushed; its LHS is the top expression, and its RHS
4578 is everything parsed until it is popped. When a new operator is
4579 encountered with precedence less than or equal to that at the top
4580 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
4581 by the result of the operation until the operator at the top of
4582 the stack has lower precedence than the new operator or there is
4583 only one element on the stack; then the top expression is the LHS
4584 of the new operator. In the case of logical AND and OR
4585 expressions, we also need to adjust skip_evaluation as
4586 appropriate when the operators are pushed and popped. */
4588 /* The precedence levels, where 0 is a dummy lowest level used for
4589 the bottom of the stack. */
4605 /* The expression at this stack level. */
4607 /* The precedence of the operator on its left, PREC_NONE at the
4608 bottom of the stack. */
4610 /* The operation on its left. */
4614 /* Location of the binary operator. */
4615 location_t binary_loc = UNKNOWN_LOCATION; /* Quiet warning. */
4618 switch (stack[sp].op) \
4620 case TRUTH_ANDIF_EXPR: \
4621 skip_evaluation -= stack[sp - 1].expr.value == truthvalue_false_node; \
4623 case TRUTH_ORIF_EXPR: \
4624 skip_evaluation -= stack[sp - 1].expr.value == truthvalue_true_node; \
4629 stack[sp - 1].expr \
4630 = default_function_array_conversion (stack[sp - 1].expr); \
4632 = default_function_array_conversion (stack[sp].expr); \
4633 stack[sp - 1].expr = parser_build_binary_op (binary_loc, \
4635 stack[sp - 1].expr, \
4639 gcc_assert (!after || c_dialect_objc ());
4640 stack[0].expr = c_parser_cast_expression (parser, after);
4641 stack[0].prec = PREC_NONE;
4646 enum tree_code ocode;
4649 switch (c_parser_peek_token (parser)->type)
4657 ocode = TRUNC_DIV_EXPR;
4661 ocode = TRUNC_MOD_EXPR;
4673 ocode = LSHIFT_EXPR;
4677 ocode = RSHIFT_EXPR;
4691 case CPP_GREATER_EQ:
4704 oprec = PREC_BITAND;
4705 ocode = BIT_AND_EXPR;
4708 oprec = PREC_BITXOR;
4709 ocode = BIT_XOR_EXPR;
4713 ocode = BIT_IOR_EXPR;
4716 oprec = PREC_LOGAND;
4717 ocode = TRUTH_ANDIF_EXPR;
4721 ocode = TRUTH_ORIF_EXPR;
4724 /* Not a binary operator, so end of the binary
4728 binary_loc = c_parser_peek_token (parser)->location;
4729 c_parser_consume_token (parser);
4730 while (oprec <= stack[sp].prec)
4734 case TRUTH_ANDIF_EXPR:
4736 = default_function_array_conversion (stack[sp].expr);
4737 stack[sp].expr.value = c_objc_common_truthvalue_conversion
4738 (binary_loc, default_conversion (stack[sp].expr.value));
4739 skip_evaluation += stack[sp].expr.value == truthvalue_false_node;
4741 case TRUTH_ORIF_EXPR:
4743 = default_function_array_conversion (stack[sp].expr);
4744 stack[sp].expr.value = c_objc_common_truthvalue_conversion
4745 (binary_loc, default_conversion (stack[sp].expr.value));
4746 skip_evaluation += stack[sp].expr.value == truthvalue_true_node;
4752 stack[sp].expr = c_parser_cast_expression (parser, NULL);
4753 stack[sp].prec = oprec;
4754 stack[sp].op = ocode;
4759 return stack[0].expr;
4763 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
4764 NULL then it is an Objective-C message expression which is the
4765 primary-expression starting the expression as an initializer.
4769 ( type-name ) unary-expression
4772 static struct c_expr
4773 c_parser_cast_expression (c_parser *parser, struct c_expr *after)
4775 gcc_assert (!after || c_dialect_objc ());
4777 return c_parser_postfix_expression_after_primary (parser, *after);
4778 /* If the expression begins with a parenthesized type name, it may
4779 be either a cast or a compound literal; we need to see whether
4780 the next character is '{' to tell the difference. If not, it is
4781 an unary expression. */
4782 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
4783 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
4785 struct c_type_name *type_name;
4788 c_parser_consume_token (parser);
4789 type_name = c_parser_type_name (parser);
4790 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4791 if (type_name == NULL)
4793 ret.value = error_mark_node;
4794 ret.original_code = ERROR_MARK;
4798 /* Save casted types in the function's used types hash table. */
4799 used_types_insert (type_name->specs->type);
4801 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
4802 return c_parser_postfix_expression_after_paren_type (parser,
4804 expr = c_parser_cast_expression (parser, NULL);
4805 expr = default_function_array_conversion (expr);
4806 ret.value = c_cast_expr (type_name, expr.value);
4807 ret.original_code = ERROR_MARK;
4811 return c_parser_unary_expression (parser);
4814 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
4820 unary-operator cast-expression
4821 sizeof unary-expression
4822 sizeof ( type-name )
4824 unary-operator: one of
4830 __alignof__ unary-expression
4831 __alignof__ ( type-name )
4834 unary-operator: one of
4835 __extension__ __real__ __imag__
4837 In addition, the GNU syntax treats ++ and -- as unary operators, so
4838 they may be applied to cast expressions with errors for non-lvalues
4841 static struct c_expr
4842 c_parser_unary_expression (c_parser *parser)
4845 struct c_expr ret, op;
4846 location_t loc = c_parser_peek_token (parser)->location;
4847 switch (c_parser_peek_token (parser)->type)
4850 c_parser_consume_token (parser);
4851 op = c_parser_cast_expression (parser, NULL);
4852 op = default_function_array_conversion (op);
4853 return parser_build_unary_op (PREINCREMENT_EXPR, op, loc);
4854 case CPP_MINUS_MINUS:
4855 c_parser_consume_token (parser);
4856 op = c_parser_cast_expression (parser, NULL);
4857 op = default_function_array_conversion (op);
4858 return parser_build_unary_op (PREDECREMENT_EXPR, op, loc);
4860 c_parser_consume_token (parser);
4861 return parser_build_unary_op (ADDR_EXPR,
4862 c_parser_cast_expression (parser, NULL),
4865 c_parser_consume_token (parser);
4866 op = c_parser_cast_expression (parser, NULL);
4867 op = default_function_array_conversion (op);
4868 ret.value = build_indirect_ref (loc, op.value, "unary *");
4869 ret.original_code = ERROR_MARK;
4872 if (!c_dialect_objc () && !in_system_header)
4873 warning_at (c_parser_peek_token (parser)->location,
4875 "traditional C rejects the unary plus operator");
4876 c_parser_consume_token (parser);
4877 op = c_parser_cast_expression (parser, NULL);
4878 op = default_function_array_conversion (op);
4879 return parser_build_unary_op (CONVERT_EXPR, op, loc);
4881 c_parser_consume_token (parser);
4882 op = c_parser_cast_expression (parser, NULL);
4883 op = default_function_array_conversion (op);
4884 return parser_build_unary_op (NEGATE_EXPR, op, loc);
4886 c_parser_consume_token (parser);
4887 op = c_parser_cast_expression (parser, NULL);
4888 op = default_function_array_conversion (op);
4889 return parser_build_unary_op (BIT_NOT_EXPR, op, loc);
4891 c_parser_consume_token (parser);
4892 op = c_parser_cast_expression (parser, NULL);
4893 op = default_function_array_conversion (op);
4894 return parser_build_unary_op (TRUTH_NOT_EXPR, op, loc);
4896 /* Refer to the address of a label as a pointer. */
4897 c_parser_consume_token (parser);
4898 if (c_parser_next_token_is (parser, CPP_NAME))
4900 ret.value = finish_label_address_expr
4901 (c_parser_peek_token (parser)->value, loc);
4902 c_parser_consume_token (parser);
4906 c_parser_error (parser, "expected identifier");
4907 ret.value = error_mark_node;
4909 ret.original_code = ERROR_MARK;
4912 switch (c_parser_peek_token (parser)->keyword)
4915 return c_parser_sizeof_expression (parser);
4917 return c_parser_alignof_expression (parser);
4919 c_parser_consume_token (parser);
4920 ext = disable_extension_diagnostics ();
4921 ret = c_parser_cast_expression (parser, NULL);
4922 restore_extension_diagnostics (ext);
4925 c_parser_consume_token (parser);
4926 op = c_parser_cast_expression (parser, NULL);
4927 op = default_function_array_conversion (op);
4928 return parser_build_unary_op (REALPART_EXPR, op, loc);
4930 c_parser_consume_token (parser);
4931 op = c_parser_cast_expression (parser, NULL);
4932 op = default_function_array_conversion (op);
4933 return parser_build_unary_op (IMAGPART_EXPR, op, loc);
4935 return c_parser_postfix_expression (parser);
4938 return c_parser_postfix_expression (parser);
4942 /* Parse a sizeof expression. */
4944 static struct c_expr
4945 c_parser_sizeof_expression (c_parser *parser)
4948 location_t expr_loc;
4949 gcc_assert (c_parser_next_token_is_keyword (parser, RID_SIZEOF));
4950 c_parser_consume_token (parser);
4953 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
4954 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
4956 /* Either sizeof ( type-name ) or sizeof unary-expression
4957 starting with a compound literal. */
4958 struct c_type_name *type_name;
4959 c_parser_consume_token (parser);
4960 expr_loc = c_parser_peek_token (parser)->location;
4961 type_name = c_parser_type_name (parser);
4962 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4963 if (type_name == NULL)
4968 ret.value = error_mark_node;
4969 ret.original_code = ERROR_MARK;
4972 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
4974 expr = c_parser_postfix_expression_after_paren_type (parser,
4978 /* sizeof ( type-name ). */
4981 return c_expr_sizeof_type (type_name);
4985 expr_loc = c_parser_peek_token (parser)->location;
4986 expr = c_parser_unary_expression (parser);
4990 if (TREE_CODE (expr.value) == COMPONENT_REF
4991 && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
4992 error_at (expr_loc, "%<sizeof%> applied to a bit-field");
4993 return c_expr_sizeof_expr (expr);
4997 /* Parse an alignof expression. */
4999 static struct c_expr
5000 c_parser_alignof_expression (c_parser *parser)
5003 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ALIGNOF));
5004 c_parser_consume_token (parser);
5007 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
5008 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
5010 /* Either __alignof__ ( type-name ) or __alignof__
5011 unary-expression starting with a compound literal. */
5012 struct c_type_name *type_name;
5014 c_parser_consume_token (parser);
5015 type_name = c_parser_type_name (parser);
5016 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5017 if (type_name == NULL)
5022 ret.value = error_mark_node;
5023 ret.original_code = ERROR_MARK;
5026 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
5028 expr = c_parser_postfix_expression_after_paren_type (parser,
5032 /* alignof ( type-name ). */
5035 ret.value = c_alignof (groktypename (type_name, NULL, NULL));
5036 ret.original_code = ERROR_MARK;
5042 expr = c_parser_unary_expression (parser);
5046 ret.value = c_alignof_expr (expr.value);
5047 ret.original_code = ERROR_MARK;
5052 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
5056 postfix-expression [ expression ]
5057 postfix-expression ( argument-expression-list[opt] )
5058 postfix-expression . identifier
5059 postfix-expression -> identifier
5060 postfix-expression ++
5061 postfix-expression --
5062 ( type-name ) { initializer-list }
5063 ( type-name ) { initializer-list , }
5065 argument-expression-list:
5067 argument-expression-list , argument-expression
5079 (treated as a keyword in GNU C)
5082 ( compound-statement )
5083 __builtin_va_arg ( assignment-expression , type-name )
5084 __builtin_offsetof ( type-name , offsetof-member-designator )
5085 __builtin_choose_expr ( assignment-expression ,
5086 assignment-expression ,
5087 assignment-expression )
5088 __builtin_types_compatible_p ( type-name , type-name )
5090 offsetof-member-designator:
5092 offsetof-member-designator . identifier
5093 offsetof-member-designator [ expression ]
5098 [ objc-receiver objc-message-args ]
5099 @selector ( objc-selector-arg )
5100 @protocol ( identifier )
5101 @encode ( type-name )
5105 static struct c_expr
5106 c_parser_postfix_expression (c_parser *parser)
5108 struct c_expr expr, e1, e2, e3;
5109 struct c_type_name *t1, *t2;
5111 switch (c_parser_peek_token (parser)->type)
5114 expr.value = c_parser_peek_token (parser)->value;
5115 expr.original_code = ERROR_MARK;
5116 loc = c_parser_peek_token (parser)->location;
5117 c_parser_consume_token (parser);
5118 if (TREE_CODE (expr.value) == FIXED_CST
5119 && !targetm.fixed_point_supported_p ())
5121 error_at (loc, "fixed-point types not supported for this target");
5122 expr.value = error_mark_node;
5129 expr.value = c_parser_peek_token (parser)->value;
5130 expr.original_code = ERROR_MARK;
5131 c_parser_consume_token (parser);
5137 expr.value = c_parser_peek_token (parser)->value;
5138 expr.original_code = STRING_CST;
5139 c_parser_consume_token (parser);
5141 case CPP_OBJC_STRING:
5142 gcc_assert (c_dialect_objc ());
5144 = objc_build_string_object (c_parser_peek_token (parser)->value);
5145 expr.original_code = ERROR_MARK;
5146 c_parser_consume_token (parser);
5149 if (c_parser_peek_token (parser)->id_kind != C_ID_ID)
5151 c_parser_error (parser, "expected expression");
5152 expr.value = error_mark_node;
5153 expr.original_code = ERROR_MARK;
5157 tree id = c_parser_peek_token (parser)->value;
5158 location_t loc = c_parser_peek_token (parser)->location;
5159 c_parser_consume_token (parser);
5160 expr.value = build_external_ref (id,
5161 (c_parser_peek_token (parser)->type
5162 == CPP_OPEN_PAREN), loc);
5163 expr.original_code = ERROR_MARK;
5166 case CPP_OPEN_PAREN:
5167 /* A parenthesized expression, statement expression or compound
5169 if (c_parser_peek_2nd_token (parser)->type == CPP_OPEN_BRACE)
5171 /* A statement expression. */
5173 location_t here = c_parser_peek_token (parser)->location;
5174 c_parser_consume_token (parser);
5175 c_parser_consume_token (parser);
5176 if (cur_stmt_list == NULL)
5178 error_at (here, "braced-group within expression allowed "
5179 "only inside a function");
5180 parser->error = true;
5181 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
5182 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5183 expr.value = error_mark_node;
5184 expr.original_code = ERROR_MARK;
5187 stmt = c_begin_stmt_expr ();
5188 c_parser_compound_statement_nostart (parser);
5189 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5191 pedwarn (here, OPT_pedantic,
5192 "ISO C forbids braced-groups within expressions");
5193 expr.value = c_finish_stmt_expr (stmt);
5194 expr.original_code = ERROR_MARK;
5196 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser)))
5198 /* A compound literal. ??? Can we actually get here rather
5199 than going directly to
5200 c_parser_postfix_expression_after_paren_type from
5202 struct c_type_name *type_name;
5203 c_parser_consume_token (parser);
5204 type_name = c_parser_type_name (parser);
5205 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5207 if (type_name == NULL)
5209 expr.value = error_mark_node;
5210 expr.original_code = ERROR_MARK;
5213 expr = c_parser_postfix_expression_after_paren_type (parser,
5218 /* A parenthesized expression. */
5219 c_parser_consume_token (parser);
5220 expr = c_parser_expression (parser);
5221 if (TREE_CODE (expr.value) == MODIFY_EXPR)
5222 TREE_NO_WARNING (expr.value) = 1;
5223 if (expr.original_code != C_MAYBE_CONST_EXPR)
5224 expr.original_code = ERROR_MARK;
5225 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5230 switch (c_parser_peek_token (parser)->keyword)
5232 case RID_FUNCTION_NAME:
5233 case RID_PRETTY_FUNCTION_NAME:
5234 case RID_C99_FUNCTION_NAME:
5235 expr.value = fname_decl (c_parser_peek_token (parser)->location,
5236 c_parser_peek_token (parser)->keyword,
5237 c_parser_peek_token (parser)->value);
5238 expr.original_code = ERROR_MARK;
5239 c_parser_consume_token (parser);
5242 c_parser_consume_token (parser);
5243 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5245 expr.value = error_mark_node;
5246 expr.original_code = ERROR_MARK;
5249 e1 = c_parser_expr_no_commas (parser, NULL);
5250 e1.value = c_fully_fold (e1.value, false, NULL);
5251 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5253 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5254 expr.value = error_mark_node;
5255 expr.original_code = ERROR_MARK;
5258 t1 = c_parser_type_name (parser);
5259 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5263 expr.value = error_mark_node;
5264 expr.original_code = ERROR_MARK;
5268 tree type_expr = NULL_TREE;
5269 expr.value = build_va_arg (e1.value, groktypename (t1,
5274 expr.value = build2 (C_MAYBE_CONST_EXPR,
5275 TREE_TYPE (expr.value), type_expr,
5277 C_MAYBE_CONST_EXPR_NON_CONST (expr.value) = true;
5279 expr.original_code = ERROR_MARK;
5283 c_parser_consume_token (parser);
5284 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5286 expr.value = error_mark_node;
5287 expr.original_code = ERROR_MARK;
5290 t1 = c_parser_type_name (parser);
5293 expr.value = error_mark_node;
5294 expr.original_code = ERROR_MARK;
5297 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5299 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5300 expr.value = error_mark_node;
5301 expr.original_code = ERROR_MARK;
5305 tree type = groktypename (t1, NULL, NULL);
5307 if (type == error_mark_node)
5308 offsetof_ref = error_mark_node;
5310 offsetof_ref = build1 (INDIRECT_REF, type, null_pointer_node);
5311 /* Parse the second argument to __builtin_offsetof. We
5312 must have one identifier, and beyond that we want to
5313 accept sub structure and sub array references. */
5314 if (c_parser_next_token_is (parser, CPP_NAME))
5316 offsetof_ref = build_component_ref
5317 (offsetof_ref, c_parser_peek_token (parser)->value);
5318 c_parser_consume_token (parser);
5319 while (c_parser_next_token_is (parser, CPP_DOT)
5320 || c_parser_next_token_is (parser,
5322 || c_parser_next_token_is (parser,
5325 if (c_parser_next_token_is (parser, CPP_DEREF))
5327 loc = c_parser_peek_token (parser)->location;
5328 offsetof_ref = build_array_ref (offsetof_ref,
5333 else if (c_parser_next_token_is (parser, CPP_DOT))
5336 c_parser_consume_token (parser);
5337 if (c_parser_next_token_is_not (parser,
5340 c_parser_error (parser, "expected identifier");
5343 offsetof_ref = build_component_ref
5345 c_parser_peek_token (parser)->value);
5346 c_parser_consume_token (parser);
5351 loc = c_parser_peek_token (parser)->location;
5352 c_parser_consume_token (parser);
5353 idx = c_parser_expression (parser).value;
5354 idx = c_fully_fold (idx, false, NULL);
5355 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
5357 offsetof_ref = build_array_ref (offsetof_ref, idx, loc);
5362 c_parser_error (parser, "expected identifier");
5363 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5365 expr.value = fold_offsetof (offsetof_ref, NULL_TREE);
5366 expr.original_code = ERROR_MARK;
5369 case RID_CHOOSE_EXPR:
5370 c_parser_consume_token (parser);
5371 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5373 expr.value = error_mark_node;
5374 expr.original_code = ERROR_MARK;
5377 loc = c_parser_peek_token (parser)->location;
5378 e1 = c_parser_expr_no_commas (parser, NULL);
5379 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5381 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5382 expr.value = error_mark_node;
5383 expr.original_code = ERROR_MARK;
5386 e2 = 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 e3 = c_parser_expr_no_commas (parser, NULL);
5395 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5400 c = fold (e1.value);
5401 if (TREE_CODE (c) != INTEGER_CST
5402 || !INTEGRAL_TYPE_P (TREE_TYPE (c)))
5404 "first argument to %<__builtin_choose_expr%> not"
5406 constant_expression_warning (c);
5407 expr = integer_zerop (c) ? e3 : e2;
5410 case RID_TYPES_COMPATIBLE_P:
5411 c_parser_consume_token (parser);
5412 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5414 expr.value = error_mark_node;
5415 expr.original_code = ERROR_MARK;
5418 t1 = c_parser_type_name (parser);
5421 expr.value = error_mark_node;
5422 expr.original_code = ERROR_MARK;
5425 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5427 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5428 expr.value = error_mark_node;
5429 expr.original_code = ERROR_MARK;
5432 t2 = c_parser_type_name (parser);
5435 expr.value = error_mark_node;
5436 expr.original_code = ERROR_MARK;
5439 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5444 e1 = TYPE_MAIN_VARIANT (groktypename (t1, NULL, NULL));
5445 e2 = TYPE_MAIN_VARIANT (groktypename (t2, NULL, NULL));
5447 expr.value = comptypes (e1, e2)
5448 ? build_int_cst (NULL_TREE, 1)
5449 : build_int_cst (NULL_TREE, 0);
5450 expr.original_code = ERROR_MARK;
5453 case RID_AT_SELECTOR:
5454 gcc_assert (c_dialect_objc ());
5455 c_parser_consume_token (parser);
5456 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5458 expr.value = error_mark_node;
5459 expr.original_code = ERROR_MARK;
5463 tree sel = c_parser_objc_selector_arg (parser);
5464 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5466 expr.value = objc_build_selector_expr (sel);
5467 expr.original_code = ERROR_MARK;
5470 case RID_AT_PROTOCOL:
5471 gcc_assert (c_dialect_objc ());
5472 c_parser_consume_token (parser);
5473 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5475 expr.value = error_mark_node;
5476 expr.original_code = ERROR_MARK;
5479 if (c_parser_next_token_is_not (parser, CPP_NAME))
5481 c_parser_error (parser, "expected identifier");
5482 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5483 expr.value = error_mark_node;
5484 expr.original_code = ERROR_MARK;
5488 tree id = c_parser_peek_token (parser)->value;
5489 c_parser_consume_token (parser);
5490 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5492 expr.value = objc_build_protocol_expr (id);
5493 expr.original_code = ERROR_MARK;
5497 /* Extension to support C-structures in the archiver. */
5498 gcc_assert (c_dialect_objc ());
5499 c_parser_consume_token (parser);
5500 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5502 expr.value = error_mark_node;
5503 expr.original_code = ERROR_MARK;
5506 t1 = c_parser_type_name (parser);
5509 expr.value = error_mark_node;
5510 expr.original_code = ERROR_MARK;
5511 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5514 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5517 tree type = groktypename (t1, NULL, NULL);
5518 expr.value = objc_build_encode_expr (type);
5519 expr.original_code = ERROR_MARK;
5523 c_parser_error (parser, "expected expression");
5524 expr.value = error_mark_node;
5525 expr.original_code = ERROR_MARK;
5529 case CPP_OPEN_SQUARE:
5530 if (c_dialect_objc ())
5532 tree receiver, args;
5533 c_parser_consume_token (parser);
5534 receiver = c_parser_objc_receiver (parser);
5535 args = c_parser_objc_message_args (parser);
5536 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
5538 expr.value = objc_build_message_expr (build_tree_list (receiver,
5540 expr.original_code = ERROR_MARK;
5543 /* Else fall through to report error. */
5545 c_parser_error (parser, "expected expression");
5546 expr.value = error_mark_node;
5547 expr.original_code = ERROR_MARK;
5550 return c_parser_postfix_expression_after_primary (parser, expr);
5553 /* Parse a postfix expression after a parenthesized type name: the
5554 brace-enclosed initializer of a compound literal, possibly followed
5555 by some postfix operators. This is separate because it is not
5556 possible to tell until after the type name whether a cast
5557 expression has a cast or a compound literal, or whether the operand
5558 of sizeof is a parenthesized type name or starts with a compound
5561 static struct c_expr
5562 c_parser_postfix_expression_after_paren_type (c_parser *parser,
5563 struct c_type_name *type_name)
5569 location_t start_loc;
5570 tree type_expr = NULL_TREE;
5571 bool type_expr_const = true;
5572 start_init (NULL_TREE, NULL, 0);
5573 type = groktypename (type_name, &type_expr, &type_expr_const);
5574 start_loc = c_parser_peek_token (parser)->location;
5575 if (type != error_mark_node && C_TYPE_VARIABLE_SIZE (type))
5577 error_at (start_loc, "compound literal has variable size");
5578 type = error_mark_node;
5580 init = c_parser_braced_init (parser, type, false);
5582 maybe_warn_string_init (type, init);
5585 pedwarn (start_loc, OPT_pedantic, "ISO C90 forbids compound literals");
5586 non_const = ((init.value && TREE_CODE (init.value) == CONSTRUCTOR)
5587 ? CONSTRUCTOR_NON_CONST (init.value)
5588 : init.original_code == C_MAYBE_CONST_EXPR);
5589 non_const |= !type_expr_const;
5590 expr.value = build_compound_literal (type, init.value, non_const);
5591 expr.original_code = ERROR_MARK;
5594 if (TREE_CODE (expr.value) == C_MAYBE_CONST_EXPR)
5596 gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr.value) == NULL_TREE);
5597 C_MAYBE_CONST_EXPR_PRE (expr.value) = type_expr;
5601 gcc_assert (!non_const);
5602 expr.value = build2 (C_MAYBE_CONST_EXPR, type,
5603 type_expr, expr.value);
5606 return c_parser_postfix_expression_after_primary (parser, expr);
5609 /* Parse a postfix expression after the initial primary or compound
5610 literal; that is, parse a series of postfix operators. */
5612 static struct c_expr
5613 c_parser_postfix_expression_after_primary (c_parser *parser,
5616 struct c_expr orig_expr;
5617 tree ident, idx, exprlist;
5618 location_t loc = c_parser_peek_token (parser)->location;
5621 switch (c_parser_peek_token (parser)->type)
5623 case CPP_OPEN_SQUARE:
5624 /* Array reference. */
5625 loc = c_parser_peek_token (parser)->location;
5626 c_parser_consume_token (parser);
5627 idx = c_parser_expression (parser).value;
5628 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
5630 expr.value = build_array_ref (expr.value, idx, loc);
5631 expr.original_code = ERROR_MARK;
5633 case CPP_OPEN_PAREN:
5634 /* Function call. */
5635 c_parser_consume_token (parser);
5636 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
5637 exprlist = NULL_TREE;
5639 exprlist = c_parser_expr_list (parser, true, false);
5640 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5643 expr.value = build_function_call (expr.value, exprlist);
5644 expr.original_code = ERROR_MARK;
5645 if (TREE_CODE (expr.value) == INTEGER_CST
5646 && TREE_CODE (orig_expr.value) == FUNCTION_DECL
5647 && DECL_BUILT_IN_CLASS (orig_expr.value) == BUILT_IN_NORMAL
5648 && DECL_FUNCTION_CODE (orig_expr.value) == BUILT_IN_CONSTANT_P)
5649 expr.original_code = C_MAYBE_CONST_EXPR;
5652 /* Structure element reference. */
5653 c_parser_consume_token (parser);
5654 expr = default_function_array_conversion (expr);
5655 if (c_parser_next_token_is (parser, CPP_NAME))
5656 ident = c_parser_peek_token (parser)->value;
5659 c_parser_error (parser, "expected identifier");
5660 expr.value = error_mark_node;
5661 expr.original_code = ERROR_MARK;
5664 c_parser_consume_token (parser);
5665 expr.value = build_component_ref (expr.value, ident);
5666 expr.original_code = ERROR_MARK;
5669 /* Structure element reference. */
5670 c_parser_consume_token (parser);
5671 expr = default_function_array_conversion (expr);
5672 if (c_parser_next_token_is (parser, CPP_NAME))
5673 ident = c_parser_peek_token (parser)->value;
5676 c_parser_error (parser, "expected identifier");
5677 expr.value = error_mark_node;
5678 expr.original_code = ERROR_MARK;
5681 c_parser_consume_token (parser);
5682 expr.value = build_component_ref (build_indirect_ref (loc,
5686 expr.original_code = ERROR_MARK;
5689 /* Postincrement. */
5690 c_parser_consume_token (parser);
5691 expr = default_function_array_conversion (expr);
5692 expr.value = build_unary_op (loc,
5693 POSTINCREMENT_EXPR, expr.value, 0);
5694 expr.original_code = ERROR_MARK;
5696 case CPP_MINUS_MINUS:
5697 /* Postdecrement. */
5698 c_parser_consume_token (parser);
5699 expr = default_function_array_conversion (expr);
5700 expr.value = build_unary_op (loc,
5701 POSTDECREMENT_EXPR, expr.value, 0);
5702 expr.original_code = ERROR_MARK;
5710 /* Parse an expression (C90 6.3.17, C99 6.5.17).
5713 assignment-expression
5714 expression , assignment-expression
5717 static struct c_expr
5718 c_parser_expression (c_parser *parser)
5721 expr = c_parser_expr_no_commas (parser, NULL);
5722 while (c_parser_next_token_is (parser, CPP_COMMA))
5725 c_parser_consume_token (parser);
5726 next = c_parser_expr_no_commas (parser, NULL);
5727 next = default_function_array_conversion (next);
5728 expr.value = build_compound_expr (expr.value, next.value);
5729 expr.original_code = COMPOUND_EXPR;
5734 /* Parse an expression and convert functions or arrays to
5737 static struct c_expr
5738 c_parser_expression_conv (c_parser *parser)
5741 expr = c_parser_expression (parser);
5742 expr = default_function_array_conversion (expr);
5746 /* Parse a non-empty list of expressions. If CONVERT_P, convert
5747 functions and arrays to pointers. If FOLD_P, fold the expressions.
5750 assignment-expression
5751 nonempty-expr-list , assignment-expression
5755 c_parser_expr_list (c_parser *parser, bool convert_p, bool fold_p)
5759 expr = c_parser_expr_no_commas (parser, NULL);
5761 expr = default_function_array_conversion (expr);
5763 expr.value = c_fully_fold (expr.value, false, NULL);
5764 ret = cur = build_tree_list (NULL_TREE, expr.value);
5765 while (c_parser_next_token_is (parser, CPP_COMMA))
5767 c_parser_consume_token (parser);
5768 expr = c_parser_expr_no_commas (parser, NULL);
5770 expr = default_function_array_conversion (expr);
5772 expr.value = c_fully_fold (expr.value, false, NULL);
5773 cur = TREE_CHAIN (cur) = build_tree_list (NULL_TREE, expr.value);
5779 /* Parse Objective-C-specific constructs. */
5781 /* Parse an objc-class-definition.
5783 objc-class-definition:
5784 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
5785 objc-class-instance-variables[opt] objc-methodprotolist @end
5786 @implementation identifier objc-superclass[opt]
5787 objc-class-instance-variables[opt]
5788 @interface identifier ( identifier ) objc-protocol-refs[opt]
5789 objc-methodprotolist @end
5790 @implementation identifier ( identifier )
5795 "@interface identifier (" must start "@interface identifier (
5796 identifier ) ...": objc-methodprotolist in the first production may
5797 not start with a parenthesized identifier as a declarator of a data
5798 definition with no declaration specifiers if the objc-superclass,
5799 objc-protocol-refs and objc-class-instance-variables are omitted. */
5802 c_parser_objc_class_definition (c_parser *parser)
5807 if (c_parser_next_token_is_keyword (parser, RID_AT_INTERFACE))
5809 else if (c_parser_next_token_is_keyword (parser, RID_AT_IMPLEMENTATION))
5813 c_parser_consume_token (parser);
5814 if (c_parser_next_token_is_not (parser, CPP_NAME))
5816 c_parser_error (parser, "expected identifier");
5819 id1 = c_parser_peek_token (parser)->value;
5820 c_parser_consume_token (parser);
5821 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
5824 tree proto = NULL_TREE;
5825 c_parser_consume_token (parser);
5826 if (c_parser_next_token_is_not (parser, CPP_NAME))
5828 c_parser_error (parser, "expected identifier");
5829 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5832 id2 = c_parser_peek_token (parser)->value;
5833 c_parser_consume_token (parser);
5834 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5837 objc_start_category_implementation (id1, id2);
5840 if (c_parser_next_token_is (parser, CPP_LESS))
5841 proto = c_parser_objc_protocol_refs (parser);
5842 objc_start_category_interface (id1, id2, proto);
5843 c_parser_objc_methodprotolist (parser);
5844 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
5845 objc_finish_interface ();
5848 if (c_parser_next_token_is (parser, CPP_COLON))
5850 c_parser_consume_token (parser);
5851 if (c_parser_next_token_is_not (parser, CPP_NAME))
5853 c_parser_error (parser, "expected identifier");
5856 superclass = c_parser_peek_token (parser)->value;
5857 c_parser_consume_token (parser);
5860 superclass = NULL_TREE;
5863 tree proto = NULL_TREE;
5864 if (c_parser_next_token_is (parser, CPP_LESS))
5865 proto = c_parser_objc_protocol_refs (parser);
5866 objc_start_class_interface (id1, superclass, proto);
5869 objc_start_class_implementation (id1, superclass);
5870 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
5871 c_parser_objc_class_instance_variables (parser);
5874 objc_continue_interface ();
5875 c_parser_objc_methodprotolist (parser);
5876 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
5877 objc_finish_interface ();
5881 objc_continue_implementation ();
5886 /* Parse objc-class-instance-variables.
5888 objc-class-instance-variables:
5889 { objc-instance-variable-decl-list[opt] }
5891 objc-instance-variable-decl-list:
5892 objc-visibility-spec
5893 objc-instance-variable-decl ;
5895 objc-instance-variable-decl-list objc-visibility-spec
5896 objc-instance-variable-decl-list objc-instance-variable-decl ;
5897 objc-instance-variable-decl-list ;
5899 objc-visibility-spec:
5904 objc-instance-variable-decl:
5909 c_parser_objc_class_instance_variables (c_parser *parser)
5911 gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE));
5912 c_parser_consume_token (parser);
5913 while (c_parser_next_token_is_not (parser, CPP_EOF))
5916 /* Parse any stray semicolon. */
5917 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
5919 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
5920 "extra semicolon in struct or union specified");
5921 c_parser_consume_token (parser);
5924 /* Stop if at the end of the instance variables. */
5925 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
5927 c_parser_consume_token (parser);
5930 /* Parse any objc-visibility-spec. */
5931 if (c_parser_next_token_is_keyword (parser, RID_PRIVATE))
5933 c_parser_consume_token (parser);
5934 objc_set_visibility (2);
5937 else if (c_parser_next_token_is_keyword (parser, RID_PROTECTED))
5939 c_parser_consume_token (parser);
5940 objc_set_visibility (0);
5943 else if (c_parser_next_token_is_keyword (parser, RID_PUBLIC))
5945 c_parser_consume_token (parser);
5946 objc_set_visibility (1);
5949 else if (c_parser_next_token_is (parser, CPP_PRAGMA))
5951 c_parser_pragma (parser, pragma_external);
5955 /* Parse some comma-separated declarations. */
5956 decls = c_parser_struct_declaration (parser);
5958 /* Comma-separated instance variables are chained together in
5959 reverse order; add them one by one. */
5960 tree ivar = nreverse (decls);
5961 for (; ivar; ivar = TREE_CHAIN (ivar))
5962 objc_add_instance_variable (copy_node (ivar));
5964 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
5968 /* Parse an objc-class-declaration.
5970 objc-class-declaration:
5971 @class identifier-list ;
5975 c_parser_objc_class_declaration (c_parser *parser)
5977 tree list = NULL_TREE;
5978 gcc_assert (c_parser_next_token_is_keyword (parser, RID_CLASS));
5979 c_parser_consume_token (parser);
5980 /* Any identifiers, including those declared as type names, are OK
5985 if (c_parser_next_token_is_not (parser, CPP_NAME))
5987 c_parser_error (parser, "expected identifier");
5990 id = c_parser_peek_token (parser)->value;
5991 list = chainon (list, build_tree_list (NULL_TREE, id));
5992 c_parser_consume_token (parser);
5993 if (c_parser_next_token_is (parser, CPP_COMMA))
5994 c_parser_consume_token (parser);
5998 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
5999 objc_declare_class (list);
6002 /* Parse an objc-alias-declaration.
6004 objc-alias-declaration:
6005 @compatibility_alias identifier identifier ;
6009 c_parser_objc_alias_declaration (c_parser *parser)
6012 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_ALIAS));
6013 c_parser_consume_token (parser);
6014 if (c_parser_next_token_is_not (parser, CPP_NAME))
6016 c_parser_error (parser, "expected identifier");
6017 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
6020 id1 = c_parser_peek_token (parser)->value;
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 id2 = c_parser_peek_token (parser)->value;
6029 c_parser_consume_token (parser);
6030 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
6031 objc_declare_alias (id1, id2);
6034 /* Parse an objc-protocol-definition.
6036 objc-protocol-definition:
6037 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
6038 @protocol identifier-list ;
6040 "@protocol identifier ;" should be resolved as "@protocol
6041 identifier-list ;": objc-methodprotolist may not start with a
6042 semicolon in the first alternative if objc-protocol-refs are
6046 c_parser_objc_protocol_definition (c_parser *parser)
6048 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_PROTOCOL));
6049 c_parser_consume_token (parser);
6050 if (c_parser_next_token_is_not (parser, CPP_NAME))
6052 c_parser_error (parser, "expected identifier");
6055 if (c_parser_peek_2nd_token (parser)->type == CPP_COMMA
6056 || c_parser_peek_2nd_token (parser)->type == CPP_SEMICOLON)
6058 tree list = NULL_TREE;
6059 /* Any identifiers, including those declared as type names, are
6064 if (c_parser_next_token_is_not (parser, CPP_NAME))
6066 c_parser_error (parser, "expected identifier");
6069 id = c_parser_peek_token (parser)->value;
6070 list = chainon (list, build_tree_list (NULL_TREE, id));
6071 c_parser_consume_token (parser);
6072 if (c_parser_next_token_is (parser, CPP_COMMA))
6073 c_parser_consume_token (parser);
6077 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
6078 objc_declare_protocols (list);
6082 tree id = c_parser_peek_token (parser)->value;
6083 tree proto = NULL_TREE;
6084 c_parser_consume_token (parser);
6085 if (c_parser_next_token_is (parser, CPP_LESS))
6086 proto = c_parser_objc_protocol_refs (parser);
6087 parser->objc_pq_context = true;
6088 objc_start_protocol (id, proto);
6089 c_parser_objc_methodprotolist (parser);
6090 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
6091 parser->objc_pq_context = false;
6092 objc_finish_interface ();
6096 /* Parse an objc-method-type.
6103 static enum tree_code
6104 c_parser_objc_method_type (c_parser *parser)
6106 switch (c_parser_peek_token (parser)->type)
6109 c_parser_consume_token (parser);
6112 c_parser_consume_token (parser);
6119 /* Parse an objc-method-definition.
6121 objc-method-definition:
6122 objc-method-type objc-method-decl ;[opt] compound-statement
6126 c_parser_objc_method_definition (c_parser *parser)
6128 enum tree_code type = c_parser_objc_method_type (parser);
6130 objc_set_method_type (type);
6131 parser->objc_pq_context = true;
6132 decl = c_parser_objc_method_decl (parser);
6133 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
6135 c_parser_consume_token (parser);
6136 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
6137 "extra semicolon in method definition specified");
6139 if (!c_parser_next_token_is (parser, CPP_OPEN_BRACE))
6141 c_parser_error (parser, "expected %<{%>");
6144 parser->objc_pq_context = false;
6145 objc_start_method_definition (decl);
6146 add_stmt (c_parser_compound_statement (parser));
6147 objc_finish_method_definition (current_function_decl);
6150 /* Parse an objc-methodprotolist.
6152 objc-methodprotolist:
6154 objc-methodprotolist objc-methodproto
6155 objc-methodprotolist declaration
6156 objc-methodprotolist ;
6158 The declaration is a data definition, which may be missing
6159 declaration specifiers under the same rules and diagnostics as
6160 other data definitions outside functions, and the stray semicolon
6161 is diagnosed the same way as a stray semicolon outside a
6165 c_parser_objc_methodprotolist (c_parser *parser)
6169 /* The list is terminated by @end. */
6170 switch (c_parser_peek_token (parser)->type)
6173 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
6174 "ISO C does not allow extra %<;%> outside of a function");
6175 c_parser_consume_token (parser);
6179 c_parser_objc_methodproto (parser);
6182 c_parser_pragma (parser, pragma_external);
6187 if (c_parser_next_token_is_keyword (parser, RID_AT_END))
6189 c_parser_declaration_or_fndef (parser, false, true, false, true);
6195 /* Parse an objc-methodproto.
6198 objc-method-type objc-method-decl ;
6202 c_parser_objc_methodproto (c_parser *parser)
6204 enum tree_code type = c_parser_objc_method_type (parser);
6206 objc_set_method_type (type);
6207 /* Remember protocol qualifiers in prototypes. */
6208 parser->objc_pq_context = true;
6209 decl = c_parser_objc_method_decl (parser);
6210 /* Forget protocol qualifiers here. */
6211 parser->objc_pq_context = false;
6212 objc_add_method_declaration (decl);
6213 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
6216 /* Parse an objc-method-decl.
6219 ( objc-type-name ) objc-selector
6221 ( objc-type-name ) objc-keyword-selector objc-optparmlist
6222 objc-keyword-selector objc-optparmlist
6224 objc-keyword-selector:
6226 objc-keyword-selector objc-keyword-decl
6229 objc-selector : ( objc-type-name ) identifier
6230 objc-selector : identifier
6231 : ( objc-type-name ) identifier
6235 objc-optparms objc-optellipsis
6239 objc-opt-parms , parameter-declaration
6247 c_parser_objc_method_decl (c_parser *parser)
6249 tree type = NULL_TREE;
6251 tree parms = NULL_TREE;
6252 bool ellipsis = false;
6254 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
6256 c_parser_consume_token (parser);
6257 type = c_parser_objc_type_name (parser);
6258 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6260 sel = c_parser_objc_selector (parser);
6261 /* If there is no selector, or a colon follows, we have an
6262 objc-keyword-selector. If there is a selector, and a colon does
6263 not follow, that selector ends the objc-method-decl. */
6264 if (!sel || c_parser_next_token_is (parser, CPP_COLON))
6267 tree list = NULL_TREE;
6270 tree atype = NULL_TREE, id, keyworddecl;
6271 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
6273 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
6275 c_parser_consume_token (parser);
6276 atype = c_parser_objc_type_name (parser);
6277 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6280 if (c_parser_next_token_is_not (parser, CPP_NAME))
6282 c_parser_error (parser, "expected identifier");
6283 return error_mark_node;
6285 id = c_parser_peek_token (parser)->value;
6286 c_parser_consume_token (parser);
6287 keyworddecl = objc_build_keyword_decl (tsel, atype, id);
6288 list = chainon (list, keyworddecl);
6289 tsel = c_parser_objc_selector (parser);
6290 if (!tsel && c_parser_next_token_is_not (parser, CPP_COLON))
6293 /* Parse the optional parameter list. Optional Objective-C
6294 method parameters follow the C syntax, and may include '...'
6295 to denote a variable number of arguments. */
6296 parms = make_node (TREE_LIST);
6297 while (c_parser_next_token_is (parser, CPP_COMMA))
6299 struct c_parm *parm;
6300 c_parser_consume_token (parser);
6301 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
6304 c_parser_consume_token (parser);
6307 parm = c_parser_parameter_declaration (parser, NULL_TREE);
6310 parms = chainon (parms,
6311 build_tree_list (NULL_TREE, grokparm (parm)));
6315 return objc_build_method_signature (type, sel, parms, ellipsis);
6318 /* Parse an objc-type-name.
6321 objc-type-qualifiers[opt] type-name
6322 objc-type-qualifiers[opt]
6324 objc-type-qualifiers:
6326 objc-type-qualifiers objc-type-qualifier
6328 objc-type-qualifier: one of
6329 in out inout bycopy byref oneway
6333 c_parser_objc_type_name (c_parser *parser)
6335 tree quals = NULL_TREE;
6336 struct c_type_name *type_name = NULL;
6337 tree type = NULL_TREE;
6340 c_token *token = c_parser_peek_token (parser);
6341 if (token->type == CPP_KEYWORD
6342 && (token->keyword == RID_IN
6343 || token->keyword == RID_OUT
6344 || token->keyword == RID_INOUT
6345 || token->keyword == RID_BYCOPY
6346 || token->keyword == RID_BYREF
6347 || token->keyword == RID_ONEWAY))
6349 quals = chainon (quals, build_tree_list (NULL_TREE, token->value));
6350 c_parser_consume_token (parser);
6355 if (c_parser_next_token_starts_typename (parser))
6356 type_name = c_parser_type_name (parser);
6358 type = groktypename (type_name, NULL, NULL);
6359 return build_tree_list (quals, type);
6362 /* Parse objc-protocol-refs.
6369 c_parser_objc_protocol_refs (c_parser *parser)
6371 tree list = NULL_TREE;
6372 gcc_assert (c_parser_next_token_is (parser, CPP_LESS));
6373 c_parser_consume_token (parser);
6374 /* Any identifiers, including those declared as type names, are OK
6379 if (c_parser_next_token_is_not (parser, CPP_NAME))
6381 c_parser_error (parser, "expected identifier");
6384 id = c_parser_peek_token (parser)->value;
6385 list = chainon (list, build_tree_list (NULL_TREE, id));
6386 c_parser_consume_token (parser);
6387 if (c_parser_next_token_is (parser, CPP_COMMA))
6388 c_parser_consume_token (parser);
6392 c_parser_require (parser, CPP_GREATER, "expected %<>%>");
6396 /* Parse an objc-try-catch-statement.
6398 objc-try-catch-statement:
6399 @try compound-statement objc-catch-list[opt]
6400 @try compound-statement objc-catch-list[opt] @finally compound-statement
6403 @catch ( parameter-declaration ) compound-statement
6404 objc-catch-list @catch ( parameter-declaration ) compound-statement
6408 c_parser_objc_try_catch_statement (c_parser *parser)
6412 gcc_assert (c_parser_next_token_is_keyword (parser, RID_TRY));
6413 c_parser_consume_token (parser);
6414 loc = c_parser_peek_token (parser)->location;
6415 stmt = c_parser_compound_statement (parser);
6416 objc_begin_try_stmt (loc, stmt);
6417 while (c_parser_next_token_is_keyword (parser, RID_CATCH))
6419 struct c_parm *parm;
6420 c_parser_consume_token (parser);
6421 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6423 parm = c_parser_parameter_declaration (parser, NULL_TREE);
6426 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6429 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6430 objc_begin_catch_clause (grokparm (parm));
6431 if (c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
6432 c_parser_compound_statement_nostart (parser);
6433 objc_finish_catch_clause ();
6435 if (c_parser_next_token_is_keyword (parser, RID_AT_FINALLY))
6439 c_parser_consume_token (parser);
6440 finloc = c_parser_peek_token (parser)->location;
6441 finstmt = c_parser_compound_statement (parser);
6442 objc_build_finally_clause (finloc, finstmt);
6444 objc_finish_try_stmt ();
6447 /* Parse an objc-synchronized-statement.
6449 objc-synchronized-statement:
6450 @synchronized ( expression ) compound-statement
6454 c_parser_objc_synchronized_statement (c_parser *parser)
6458 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_SYNCHRONIZED));
6459 c_parser_consume_token (parser);
6460 loc = c_parser_peek_token (parser)->location;
6461 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6463 expr = c_parser_expression (parser).value;
6464 expr = c_fully_fold (expr, false, NULL);
6465 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6468 expr = error_mark_node;
6469 stmt = c_parser_compound_statement (parser);
6470 objc_build_synchronized (loc, expr, stmt);
6473 /* Parse an objc-selector; return NULL_TREE without an error if the
6474 next token is not an objc-selector.
6479 enum struct union if else while do for switch case default
6480 break continue return goto asm sizeof typeof __alignof
6481 unsigned long const short volatile signed restrict _Complex
6482 in out inout bycopy byref oneway int char float double void _Bool
6484 ??? Why this selection of keywords but not, for example, storage
6485 class specifiers? */
6488 c_parser_objc_selector (c_parser *parser)
6490 c_token *token = c_parser_peek_token (parser);
6491 tree value = token->value;
6492 if (token->type == CPP_NAME)
6494 c_parser_consume_token (parser);
6497 if (token->type != CPP_KEYWORD)
6499 switch (token->keyword)
6540 c_parser_consume_token (parser);
6547 /* Parse an objc-selector-arg.
6551 objc-keywordname-list
6553 objc-keywordname-list:
6555 objc-keywordname-list objc-keywordname
6563 c_parser_objc_selector_arg (c_parser *parser)
6565 tree sel = c_parser_objc_selector (parser);
6566 tree list = NULL_TREE;
6567 if (sel && c_parser_next_token_is_not (parser, CPP_COLON))
6571 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
6573 list = chainon (list, build_tree_list (sel, NULL_TREE));
6574 sel = c_parser_objc_selector (parser);
6575 if (!sel && c_parser_next_token_is_not (parser, CPP_COLON))
6581 /* Parse an objc-receiver.
6590 c_parser_objc_receiver (c_parser *parser)
6592 if (c_parser_peek_token (parser)->type == CPP_NAME
6593 && (c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME
6594 || c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME))
6596 tree id = c_parser_peek_token (parser)->value;
6597 c_parser_consume_token (parser);
6598 return objc_get_class_reference (id);
6600 return c_fully_fold (c_parser_expression (parser).value, false, NULL);
6603 /* Parse objc-message-args.
6607 objc-keywordarg-list
6609 objc-keywordarg-list:
6611 objc-keywordarg-list objc-keywordarg
6614 objc-selector : objc-keywordexpr
6619 c_parser_objc_message_args (c_parser *parser)
6621 tree sel = c_parser_objc_selector (parser);
6622 tree list = NULL_TREE;
6623 if (sel && c_parser_next_token_is_not (parser, CPP_COLON))
6628 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
6630 keywordexpr = c_parser_objc_keywordexpr (parser);
6631 list = chainon (list, build_tree_list (sel, keywordexpr));
6632 sel = c_parser_objc_selector (parser);
6633 if (!sel && c_parser_next_token_is_not (parser, CPP_COLON))
6639 /* Parse an objc-keywordexpr.
6646 c_parser_objc_keywordexpr (c_parser *parser)
6648 tree list = c_parser_expr_list (parser, true, true);
6649 if (TREE_CHAIN (list) == NULL_TREE)
6651 /* Just return the expression, remove a level of
6653 return TREE_VALUE (list);
6657 /* We have a comma expression, we will collapse later. */
6663 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
6664 should be considered, statements. ALLOW_STMT is true if we're within
6665 the context of a function and such pragmas are to be allowed. Returns
6666 true if we actually parsed such a pragma. */
6669 c_parser_pragma (c_parser *parser, enum pragma_context context)
6673 id = c_parser_peek_token (parser)->pragma_kind;
6674 gcc_assert (id != PRAGMA_NONE);
6678 case PRAGMA_OMP_BARRIER:
6679 if (context != pragma_compound)
6681 if (context == pragma_stmt)
6682 c_parser_error (parser, "%<#pragma omp barrier%> may only be "
6683 "used in compound statements");
6686 c_parser_omp_barrier (parser);
6689 case PRAGMA_OMP_FLUSH:
6690 if (context != pragma_compound)
6692 if (context == pragma_stmt)
6693 c_parser_error (parser, "%<#pragma omp flush%> may only be "
6694 "used in compound statements");
6697 c_parser_omp_flush (parser);
6700 case PRAGMA_OMP_TASKWAIT:
6701 if (context != pragma_compound)
6703 if (context == pragma_stmt)
6704 c_parser_error (parser, "%<#pragma omp taskwait%> may only be "
6705 "used in compound statements");
6708 c_parser_omp_taskwait (parser);
6711 case PRAGMA_OMP_THREADPRIVATE:
6712 c_parser_omp_threadprivate (parser);
6715 case PRAGMA_OMP_SECTION:
6716 error_at (c_parser_peek_token (parser)->location,
6717 "%<#pragma omp section%> may only be used in "
6718 "%<#pragma omp sections%> construct");
6719 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
6722 case PRAGMA_GCC_PCH_PREPROCESS:
6723 c_parser_error (parser, "%<#pragma GCC pch_preprocess%> must be first");
6724 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
6728 if (id < PRAGMA_FIRST_EXTERNAL)
6730 if (context == pragma_external)
6733 c_parser_error (parser, "expected declaration specifiers");
6734 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
6737 c_parser_omp_construct (parser);
6743 c_parser_consume_pragma (parser);
6744 c_invoke_pragma_handler (id);
6746 /* Skip to EOL, but suppress any error message. Those will have been
6747 generated by the handler routine through calling error, as opposed
6748 to calling c_parser_error. */
6749 parser->error = true;
6750 c_parser_skip_to_pragma_eol (parser);
6755 /* The interface the pragma parsers have to the lexer. */
6758 pragma_lex (tree *value)
6760 c_token *tok = c_parser_peek_token (the_parser);
6761 enum cpp_ttype ret = tok->type;
6763 *value = tok->value;
6764 if (ret == CPP_PRAGMA_EOL || ret == CPP_EOF)
6768 if (ret == CPP_KEYWORD)
6770 c_parser_consume_token (the_parser);
6777 c_parser_pragma_pch_preprocess (c_parser *parser)
6781 c_parser_consume_pragma (parser);
6782 if (c_parser_next_token_is (parser, CPP_STRING))
6784 name = c_parser_peek_token (parser)->value;
6785 c_parser_consume_token (parser);
6788 c_parser_error (parser, "expected string literal");
6789 c_parser_skip_to_pragma_eol (parser);
6792 c_common_pch_pragma (parse_in, TREE_STRING_POINTER (name));
6795 /* OpenMP 2.5 parsing routines. */
6797 /* Returns name of the next clause.
6798 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
6799 the token is not consumed. Otherwise appropriate pragma_omp_clause is
6800 returned and the token is consumed. */
6802 static pragma_omp_clause
6803 c_parser_omp_clause_name (c_parser *parser)
6805 pragma_omp_clause result = PRAGMA_OMP_CLAUSE_NONE;
6807 if (c_parser_next_token_is_keyword (parser, RID_IF))
6808 result = PRAGMA_OMP_CLAUSE_IF;
6809 else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT))
6810 result = PRAGMA_OMP_CLAUSE_DEFAULT;
6811 else if (c_parser_next_token_is (parser, CPP_NAME))
6813 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
6818 if (!strcmp ("collapse", p))
6819 result = PRAGMA_OMP_CLAUSE_COLLAPSE;
6820 else if (!strcmp ("copyin", p))
6821 result = PRAGMA_OMP_CLAUSE_COPYIN;
6822 else if (!strcmp ("copyprivate", p))
6823 result = PRAGMA_OMP_CLAUSE_COPYPRIVATE;
6826 if (!strcmp ("firstprivate", p))
6827 result = PRAGMA_OMP_CLAUSE_FIRSTPRIVATE;
6830 if (!strcmp ("lastprivate", p))
6831 result = PRAGMA_OMP_CLAUSE_LASTPRIVATE;
6834 if (!strcmp ("nowait", p))
6835 result = PRAGMA_OMP_CLAUSE_NOWAIT;
6836 else if (!strcmp ("num_threads", p))
6837 result = PRAGMA_OMP_CLAUSE_NUM_THREADS;
6840 if (!strcmp ("ordered", p))
6841 result = PRAGMA_OMP_CLAUSE_ORDERED;
6844 if (!strcmp ("private", p))
6845 result = PRAGMA_OMP_CLAUSE_PRIVATE;
6848 if (!strcmp ("reduction", p))
6849 result = PRAGMA_OMP_CLAUSE_REDUCTION;
6852 if (!strcmp ("schedule", p))
6853 result = PRAGMA_OMP_CLAUSE_SCHEDULE;
6854 else if (!strcmp ("shared", p))
6855 result = PRAGMA_OMP_CLAUSE_SHARED;
6858 if (!strcmp ("untied", p))
6859 result = PRAGMA_OMP_CLAUSE_UNTIED;
6864 if (result != PRAGMA_OMP_CLAUSE_NONE)
6865 c_parser_consume_token (parser);
6870 /* Validate that a clause of the given type does not already exist. */
6873 check_no_duplicate_clause (tree clauses, enum omp_clause_code code,
6878 for (c = clauses; c ; c = OMP_CLAUSE_CHAIN (c))
6879 if (OMP_CLAUSE_CODE (c) == code)
6881 error ("too many %qs clauses", name);
6889 variable-list , identifier
6891 If KIND is nonzero, create the appropriate node and install the decl
6892 in OMP_CLAUSE_DECL and add the node to the head of the list.
6894 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
6895 return the list created. */
6898 c_parser_omp_variable_list (c_parser *parser, enum omp_clause_code kind,
6901 if (c_parser_next_token_is_not (parser, CPP_NAME)
6902 || c_parser_peek_token (parser)->id_kind != C_ID_ID)
6903 c_parser_error (parser, "expected identifier");
6905 while (c_parser_next_token_is (parser, CPP_NAME)
6906 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
6908 tree t = lookup_name (c_parser_peek_token (parser)->value);
6911 undeclared_variable (c_parser_peek_token (parser)->value,
6912 c_parser_peek_token (parser)->location);
6913 else if (t == error_mark_node)
6917 tree u = build_omp_clause (kind);
6918 OMP_CLAUSE_DECL (u) = t;
6919 OMP_CLAUSE_CHAIN (u) = list;
6923 list = tree_cons (t, NULL_TREE, list);
6925 c_parser_consume_token (parser);
6927 if (c_parser_next_token_is_not (parser, CPP_COMMA))
6930 c_parser_consume_token (parser);
6936 /* Similarly, but expect leading and trailing parenthesis. This is a very
6937 common case for omp clauses. */
6940 c_parser_omp_var_list_parens (c_parser *parser, enum omp_clause_code kind,
6943 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6945 list = c_parser_omp_variable_list (parser, kind, list);
6946 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6952 collapse ( constant-expression ) */
6955 c_parser_omp_clause_collapse (c_parser *parser, tree list)
6957 tree c, num = error_mark_node;
6961 check_no_duplicate_clause (list, OMP_CLAUSE_COLLAPSE, "collapse");
6963 loc = c_parser_peek_token (parser)->location;
6964 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6966 num = c_parser_expr_no_commas (parser, NULL).value;
6967 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6969 if (num == error_mark_node)
6971 if (!INTEGRAL_TYPE_P (TREE_TYPE (num))
6972 || !host_integerp (num, 0)
6973 || (n = tree_low_cst (num, 0)) <= 0
6977 "collapse argument needs positive constant integer expression");
6980 c = build_omp_clause (OMP_CLAUSE_COLLAPSE);
6981 OMP_CLAUSE_COLLAPSE_EXPR (c) = num;
6982 OMP_CLAUSE_CHAIN (c) = list;
6987 copyin ( variable-list ) */
6990 c_parser_omp_clause_copyin (c_parser *parser, tree list)
6992 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYIN, list);
6996 copyprivate ( variable-list ) */
6999 c_parser_omp_clause_copyprivate (c_parser *parser, tree list)
7001 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYPRIVATE, list);
7005 default ( shared | none ) */
7008 c_parser_omp_clause_default (c_parser *parser, tree list)
7010 enum omp_clause_default_kind kind = OMP_CLAUSE_DEFAULT_UNSPECIFIED;
7013 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7015 if (c_parser_next_token_is (parser, CPP_NAME))
7017 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
7022 if (strcmp ("none", p) != 0)
7024 kind = OMP_CLAUSE_DEFAULT_NONE;
7028 if (strcmp ("shared", p) != 0)
7030 kind = OMP_CLAUSE_DEFAULT_SHARED;
7037 c_parser_consume_token (parser);
7042 c_parser_error (parser, "expected %<none%> or %<shared%>");
7044 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7046 if (kind == OMP_CLAUSE_DEFAULT_UNSPECIFIED)
7049 check_no_duplicate_clause (list, OMP_CLAUSE_DEFAULT, "default");
7050 c = build_omp_clause (OMP_CLAUSE_DEFAULT);
7051 OMP_CLAUSE_CHAIN (c) = list;
7052 OMP_CLAUSE_DEFAULT_KIND (c) = kind;
7058 firstprivate ( variable-list ) */
7061 c_parser_omp_clause_firstprivate (c_parser *parser, tree list)
7063 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_FIRSTPRIVATE, list);
7067 if ( expression ) */
7070 c_parser_omp_clause_if (c_parser *parser, tree list)
7072 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
7074 tree t = c_parser_paren_condition (parser);
7077 check_no_duplicate_clause (list, OMP_CLAUSE_IF, "if");
7079 c = build_omp_clause (OMP_CLAUSE_IF);
7080 OMP_CLAUSE_IF_EXPR (c) = t;
7081 OMP_CLAUSE_CHAIN (c) = list;
7085 c_parser_error (parser, "expected %<(%>");
7091 lastprivate ( variable-list ) */
7094 c_parser_omp_clause_lastprivate (c_parser *parser, tree list)
7096 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_LASTPRIVATE, list);
7103 c_parser_omp_clause_nowait (c_parser *parser ATTRIBUTE_UNUSED, tree list)
7107 check_no_duplicate_clause (list, OMP_CLAUSE_NOWAIT, "nowait");
7109 c = build_omp_clause (OMP_CLAUSE_NOWAIT);
7110 OMP_CLAUSE_CHAIN (c) = list;
7115 num_threads ( expression ) */
7118 c_parser_omp_clause_num_threads (c_parser *parser, tree list)
7120 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7122 location_t expr_loc = c_parser_peek_token (parser)->location;
7123 tree c, t = c_parser_expression (parser).value;
7124 t = c_fully_fold (t, false, NULL);
7126 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7128 if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
7130 c_parser_error (parser, "expected integer expression");
7134 /* Attempt to statically determine when the number isn't positive. */
7135 c = fold_build2 (LE_EXPR, boolean_type_node, t,
7136 build_int_cst (TREE_TYPE (t), 0));
7137 if (c == boolean_true_node)
7139 warning_at (expr_loc, 0,
7140 "%<num_threads%> value must be positive");
7141 t = integer_one_node;
7144 check_no_duplicate_clause (list, OMP_CLAUSE_NUM_THREADS, "num_threads");
7146 c = build_omp_clause (OMP_CLAUSE_NUM_THREADS);
7147 OMP_CLAUSE_NUM_THREADS_EXPR (c) = t;
7148 OMP_CLAUSE_CHAIN (c) = list;
7159 c_parser_omp_clause_ordered (c_parser *parser ATTRIBUTE_UNUSED, tree list)
7163 check_no_duplicate_clause (list, OMP_CLAUSE_ORDERED, "ordered");
7165 c = build_omp_clause (OMP_CLAUSE_ORDERED);
7166 OMP_CLAUSE_CHAIN (c) = list;
7171 private ( variable-list ) */
7174 c_parser_omp_clause_private (c_parser *parser, tree list)
7176 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_PRIVATE, list);
7180 reduction ( reduction-operator : variable-list )
7183 One of: + * - & ^ | && || */
7186 c_parser_omp_clause_reduction (c_parser *parser, tree list)
7188 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7190 enum tree_code code;
7192 switch (c_parser_peek_token (parser)->type)
7204 code = BIT_AND_EXPR;
7207 code = BIT_XOR_EXPR;
7210 code = BIT_IOR_EXPR;
7213 code = TRUTH_ANDIF_EXPR;
7216 code = TRUTH_ORIF_EXPR;
7219 c_parser_error (parser,
7220 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
7221 "%<^%>, %<|%>, %<&&%>, or %<||%>");
7222 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0);
7225 c_parser_consume_token (parser);
7226 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
7230 nl = c_parser_omp_variable_list (parser, OMP_CLAUSE_REDUCTION, list);
7231 for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
7232 OMP_CLAUSE_REDUCTION_CODE (c) = code;
7236 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7242 schedule ( schedule-kind )
7243 schedule ( schedule-kind , expression )
7246 static | dynamic | guided | runtime | auto
7250 c_parser_omp_clause_schedule (c_parser *parser, tree list)
7254 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7257 c = build_omp_clause (OMP_CLAUSE_SCHEDULE);
7259 if (c_parser_next_token_is (parser, CPP_NAME))
7261 tree kind = c_parser_peek_token (parser)->value;
7262 const char *p = IDENTIFIER_POINTER (kind);
7267 if (strcmp ("dynamic", p) != 0)
7269 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_DYNAMIC;
7273 if (strcmp ("guided", p) != 0)
7275 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_GUIDED;
7279 if (strcmp ("runtime", p) != 0)
7281 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_RUNTIME;
7288 else if (c_parser_next_token_is_keyword (parser, RID_STATIC))
7289 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_STATIC;
7290 else if (c_parser_next_token_is_keyword (parser, RID_AUTO))
7291 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_AUTO;
7295 c_parser_consume_token (parser);
7296 if (c_parser_next_token_is (parser, CPP_COMMA))
7299 c_parser_consume_token (parser);
7301 here = c_parser_peek_token (parser)->location;
7302 t = c_parser_expr_no_commas (parser, NULL).value;
7303 t = c_fully_fold (t, false, NULL);
7305 if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_RUNTIME)
7306 error_at (here, "schedule %<runtime%> does not take "
7307 "a %<chunk_size%> parameter");
7308 else if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_AUTO)
7310 "schedule %<auto%> does not take "
7311 "a %<chunk_size%> parameter");
7312 else if (TREE_CODE (TREE_TYPE (t)) == INTEGER_TYPE)
7313 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c) = t;
7315 c_parser_error (parser, "expected integer expression");
7317 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7320 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7321 "expected %<,%> or %<)%>");
7323 check_no_duplicate_clause (list, OMP_CLAUSE_SCHEDULE, "schedule");
7324 OMP_CLAUSE_CHAIN (c) = list;
7328 c_parser_error (parser, "invalid schedule kind");
7329 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0);
7334 shared ( variable-list ) */
7337 c_parser_omp_clause_shared (c_parser *parser, tree list)
7339 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_SHARED, list);
7346 c_parser_omp_clause_untied (c_parser *parser ATTRIBUTE_UNUSED, tree list)
7350 /* FIXME: Should we allow duplicates? */
7351 check_no_duplicate_clause (list, OMP_CLAUSE_UNTIED, "untied");
7353 c = build_omp_clause (OMP_CLAUSE_UNTIED);
7354 OMP_CLAUSE_CHAIN (c) = list;
7358 /* Parse all OpenMP clauses. The set clauses allowed by the directive
7359 is a bitmask in MASK. Return the list of clauses found; the result
7360 of clause default goes in *pdefault. */
7363 c_parser_omp_all_clauses (c_parser *parser, unsigned int mask,
7366 tree clauses = NULL;
7369 while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
7372 pragma_omp_clause c_kind;
7374 tree prev = clauses;
7376 if (!first && c_parser_next_token_is (parser, CPP_COMMA))
7377 c_parser_consume_token (parser);
7380 here = c_parser_peek_token (parser)->location;
7381 c_kind = c_parser_omp_clause_name (parser);
7385 case PRAGMA_OMP_CLAUSE_COLLAPSE:
7386 clauses = c_parser_omp_clause_collapse (parser, clauses);
7387 c_name = "collapse";
7389 case PRAGMA_OMP_CLAUSE_COPYIN:
7390 clauses = c_parser_omp_clause_copyin (parser, clauses);
7393 case PRAGMA_OMP_CLAUSE_COPYPRIVATE:
7394 clauses = c_parser_omp_clause_copyprivate (parser, clauses);
7395 c_name = "copyprivate";
7397 case PRAGMA_OMP_CLAUSE_DEFAULT:
7398 clauses = c_parser_omp_clause_default (parser, clauses);
7401 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE:
7402 clauses = c_parser_omp_clause_firstprivate (parser, clauses);
7403 c_name = "firstprivate";
7405 case PRAGMA_OMP_CLAUSE_IF:
7406 clauses = c_parser_omp_clause_if (parser, clauses);
7409 case PRAGMA_OMP_CLAUSE_LASTPRIVATE:
7410 clauses = c_parser_omp_clause_lastprivate (parser, clauses);
7411 c_name = "lastprivate";
7413 case PRAGMA_OMP_CLAUSE_NOWAIT:
7414 clauses = c_parser_omp_clause_nowait (parser, clauses);
7417 case PRAGMA_OMP_CLAUSE_NUM_THREADS:
7418 clauses = c_parser_omp_clause_num_threads (parser, clauses);
7419 c_name = "num_threads";
7421 case PRAGMA_OMP_CLAUSE_ORDERED:
7422 clauses = c_parser_omp_clause_ordered (parser, clauses);
7425 case PRAGMA_OMP_CLAUSE_PRIVATE:
7426 clauses = c_parser_omp_clause_private (parser, clauses);
7429 case PRAGMA_OMP_CLAUSE_REDUCTION:
7430 clauses = c_parser_omp_clause_reduction (parser, clauses);
7431 c_name = "reduction";
7433 case PRAGMA_OMP_CLAUSE_SCHEDULE:
7434 clauses = c_parser_omp_clause_schedule (parser, clauses);
7435 c_name = "schedule";
7437 case PRAGMA_OMP_CLAUSE_SHARED:
7438 clauses = c_parser_omp_clause_shared (parser, clauses);
7441 case PRAGMA_OMP_CLAUSE_UNTIED:
7442 clauses = c_parser_omp_clause_untied (parser, clauses);
7446 c_parser_error (parser, "expected %<#pragma omp%> clause");
7450 if (((mask >> c_kind) & 1) == 0 && !parser->error)
7452 /* Remove the invalid clause(s) from the list to avoid
7453 confusing the rest of the compiler. */
7455 error_at (here, "%qs is not valid for %qs", c_name, where);
7460 c_parser_skip_to_pragma_eol (parser);
7462 return c_finish_omp_clauses (clauses);
7469 In practice, we're also interested in adding the statement to an
7470 outer node. So it is convenient if we work around the fact that
7471 c_parser_statement calls add_stmt. */
7474 c_parser_omp_structured_block (c_parser *parser)
7476 tree stmt = push_stmt_list ();
7477 c_parser_statement (parser);
7478 return pop_stmt_list (stmt);
7482 # pragma omp atomic new-line
7486 x binop= expr | x++ | ++x | x-- | --x
7488 +, *, -, /, &, ^, |, <<, >>
7490 where x is an lvalue expression with scalar type. */
7493 c_parser_omp_atomic (c_parser *parser)
7497 enum tree_code code;
7498 struct c_expr rhs_expr;
7500 c_parser_skip_to_pragma_eol (parser);
7502 lhs = c_parser_unary_expression (parser).value;
7503 lhs = c_fully_fold (lhs, false, NULL);
7504 switch (TREE_CODE (lhs))
7508 c_parser_skip_to_end_of_block_or_statement (parser);
7511 case PREINCREMENT_EXPR:
7512 case POSTINCREMENT_EXPR:
7513 lhs = TREE_OPERAND (lhs, 0);
7515 rhs = integer_one_node;
7518 case PREDECREMENT_EXPR:
7519 case POSTDECREMENT_EXPR:
7520 lhs = TREE_OPERAND (lhs, 0);
7522 rhs = integer_one_node;
7526 switch (c_parser_peek_token (parser)->type)
7532 code = TRUNC_DIV_EXPR;
7547 code = BIT_AND_EXPR;
7550 code = BIT_IOR_EXPR;
7553 code = BIT_XOR_EXPR;
7556 c_parser_error (parser,
7557 "invalid operator for %<#pragma omp atomic%>");
7561 c_parser_consume_token (parser);
7562 rhs_expr = c_parser_expression (parser);
7563 rhs_expr = default_function_array_conversion (rhs_expr);
7564 rhs = rhs_expr.value;
7565 rhs = c_fully_fold (rhs, false, NULL);
7568 stmt = c_finish_omp_atomic (code, lhs, rhs);
7569 if (stmt != error_mark_node)
7571 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7576 # pragma omp barrier new-line
7580 c_parser_omp_barrier (c_parser *parser)
7582 c_parser_consume_pragma (parser);
7583 c_parser_skip_to_pragma_eol (parser);
7585 c_finish_omp_barrier ();
7589 # pragma omp critical [(name)] new-line
7594 c_parser_omp_critical (c_parser *parser)
7596 tree stmt, name = NULL;
7598 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
7600 c_parser_consume_token (parser);
7601 if (c_parser_next_token_is (parser, CPP_NAME))
7603 name = c_parser_peek_token (parser)->value;
7604 c_parser_consume_token (parser);
7605 c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7608 c_parser_error (parser, "expected identifier");
7610 else if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
7611 c_parser_error (parser, "expected %<(%> or end of line");
7612 c_parser_skip_to_pragma_eol (parser);
7614 stmt = c_parser_omp_structured_block (parser);
7615 return c_finish_omp_critical (stmt, name);
7619 # pragma omp flush flush-vars[opt] new-line
7622 ( variable-list ) */
7625 c_parser_omp_flush (c_parser *parser)
7627 c_parser_consume_pragma (parser);
7628 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
7629 c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL);
7630 else if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
7631 c_parser_error (parser, "expected %<(%> or end of line");
7632 c_parser_skip_to_pragma_eol (parser);
7634 c_finish_omp_flush ();
7637 /* Parse the restricted form of the for statement allowed by OpenMP.
7638 The real trick here is to determine the loop control variable early
7639 so that we can push a new decl if necessary to make it private. */
7642 c_parser_omp_for_loop (c_parser *parser, tree clauses, tree *par_clauses)
7644 tree decl, cond, incr, save_break, save_cont, body, init, stmt, cl;
7645 tree declv, condv, incrv, initv, for_block = NULL, ret = NULL;
7647 bool fail = false, open_brace_parsed = false;
7648 int i, collapse = 1, nbraces = 0;
7650 for (cl = clauses; cl; cl = OMP_CLAUSE_CHAIN (cl))
7651 if (OMP_CLAUSE_CODE (cl) == OMP_CLAUSE_COLLAPSE)
7652 collapse = tree_low_cst (OMP_CLAUSE_COLLAPSE_EXPR (cl), 0);
7654 gcc_assert (collapse >= 1);
7656 declv = make_tree_vec (collapse);
7657 initv = make_tree_vec (collapse);
7658 condv = make_tree_vec (collapse);
7659 incrv = make_tree_vec (collapse);
7661 if (!c_parser_next_token_is_keyword (parser, RID_FOR))
7663 c_parser_error (parser, "for statement expected");
7666 loc = c_parser_peek_token (parser)->location;
7667 c_parser_consume_token (parser);
7669 for (i = 0; i < collapse; i++)
7673 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7676 /* Parse the initialization declaration or expression. */
7677 if (c_parser_next_token_starts_declspecs (parser))
7681 = tree_cons (NULL, c_begin_compound_stmt (true), for_block);
7682 c_parser_declaration_or_fndef (parser, true, true, true, true);
7683 decl = check_for_loop_decls ();
7686 if (DECL_INITIAL (decl) == error_mark_node)
7687 decl = error_mark_node;
7690 else if (c_parser_next_token_is (parser, CPP_NAME)
7691 && c_parser_peek_2nd_token (parser)->type == CPP_EQ)
7693 struct c_expr init_exp;
7694 location_t init_loc;
7696 decl = c_parser_postfix_expression (parser).value;
7698 c_parser_require (parser, CPP_EQ, "expected %<=%>");
7699 init_loc = c_parser_peek_token (parser)->location;
7701 init_exp = c_parser_expr_no_commas (parser, NULL);
7702 init_exp = default_function_array_conversion (init_exp);
7703 init = build_modify_expr (init_loc,
7704 decl, NOP_EXPR, init_exp.value);
7705 init = c_process_expr_stmt (init);
7707 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7712 c_parser_error (parser,
7713 "expected iteration declaration or initialization");
7714 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7720 /* Parse the loop condition. */
7722 if (c_parser_next_token_is_not (parser, CPP_SEMICOLON))
7724 location_t cond_loc = c_parser_peek_token (parser)->location;
7725 struct c_expr cond_expr = c_parser_binary_expression (parser, NULL);
7727 cond = cond_expr.value;
7728 cond = c_objc_common_truthvalue_conversion (cond_loc, cond);
7729 cond = c_fully_fold (cond, false, NULL);
7730 switch (cond_expr.original_code)
7738 /* Can't be cond = error_mark_node, because we want to preserve
7739 the location until c_finish_omp_for. */
7740 cond = build1 (NOP_EXPR, boolean_type_node, error_mark_node);
7743 protected_set_expr_location (cond, cond_loc);
7745 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7747 /* Parse the increment expression. */
7749 if (c_parser_next_token_is_not (parser, CPP_CLOSE_PAREN))
7751 location_t incr_loc = c_parser_peek_token (parser)->location;
7753 incr = c_process_expr_stmt (c_parser_expression (parser).value);
7754 protected_set_expr_location (incr, incr_loc);
7756 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7758 if (decl == NULL || decl == error_mark_node || init == error_mark_node)
7762 TREE_VEC_ELT (declv, i) = decl;
7763 TREE_VEC_ELT (initv, i) = init;
7764 TREE_VEC_ELT (condv, i) = cond;
7765 TREE_VEC_ELT (incrv, i) = incr;
7769 if (i == collapse - 1)
7772 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
7773 in between the collapsed for loops to be still considered perfectly
7774 nested. Hopefully the final version clarifies this.
7775 For now handle (multiple) {'s and empty statements. */
7778 if (c_parser_next_token_is_keyword (parser, RID_FOR))
7780 c_parser_consume_token (parser);
7783 else if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
7785 c_parser_consume_token (parser);
7789 && c_parser_next_token_is (parser, CPP_SEMICOLON))
7790 c_parser_consume_token (parser);
7793 c_parser_error (parser, "not enough perfectly nested loops");
7796 open_brace_parsed = true;
7806 nbraces += bracecount;
7809 save_break = c_break_label;
7810 c_break_label = size_one_node;
7811 save_cont = c_cont_label;
7812 c_cont_label = NULL_TREE;
7813 body = push_stmt_list ();
7815 if (open_brace_parsed)
7817 stmt = c_begin_compound_stmt (true);
7818 c_parser_compound_statement_nostart (parser);
7819 add_stmt (c_end_compound_stmt (stmt, true));
7822 add_stmt (c_parser_c99_block_statement (parser));
7824 add_stmt (build1 (LABEL_EXPR, void_type_node, c_cont_label));
7826 body = pop_stmt_list (body);
7827 c_break_label = save_break;
7828 c_cont_label = save_cont;
7832 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
7834 c_parser_consume_token (parser);
7837 else if (c_parser_next_token_is (parser, CPP_SEMICOLON))
7838 c_parser_consume_token (parser);
7841 c_parser_error (parser, "collapsed loops not perfectly nested");
7844 stmt = c_begin_compound_stmt (true);
7846 c_parser_compound_statement_nostart (parser);
7847 body = c_end_compound_stmt (stmt, true);
7854 /* Only bother calling c_finish_omp_for if we haven't already generated
7855 an error from the initialization parsing. */
7858 stmt = c_finish_omp_for (loc, declv, initv, condv, incrv, body, NULL);
7861 if (par_clauses != NULL)
7864 for (c = par_clauses; *c ; )
7865 if (OMP_CLAUSE_CODE (*c) != OMP_CLAUSE_FIRSTPRIVATE
7866 && OMP_CLAUSE_CODE (*c) != OMP_CLAUSE_LASTPRIVATE)
7867 c = &OMP_CLAUSE_CHAIN (*c);
7870 for (i = 0; i < collapse; i++)
7871 if (TREE_VEC_ELT (declv, i) == OMP_CLAUSE_DECL (*c))
7874 c = &OMP_CLAUSE_CHAIN (*c);
7875 else if (OMP_CLAUSE_CODE (*c) == OMP_CLAUSE_FIRSTPRIVATE)
7878 "iteration variable %qD should not be firstprivate",
7879 OMP_CLAUSE_DECL (*c));
7880 *c = OMP_CLAUSE_CHAIN (*c);
7884 /* Copy lastprivate (decl) clause to OMP_FOR_CLAUSES,
7885 change it to shared (decl) in
7886 OMP_PARALLEL_CLAUSES. */
7887 tree l = build_omp_clause (OMP_CLAUSE_LASTPRIVATE);
7888 OMP_CLAUSE_DECL (l) = OMP_CLAUSE_DECL (*c);
7889 OMP_CLAUSE_CHAIN (l) = clauses;
7891 OMP_CLAUSE_SET_CODE (*c, OMP_CLAUSE_SHARED);
7895 OMP_FOR_CLAUSES (stmt) = clauses;
7902 stmt = c_end_compound_stmt (TREE_VALUE (for_block), true);
7904 for_block = TREE_CHAIN (for_block);
7910 #pragma omp for for-clause[optseq] new-line
7914 #define OMP_FOR_CLAUSE_MASK \
7915 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
7916 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
7917 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
7918 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
7919 | (1u << PRAGMA_OMP_CLAUSE_ORDERED) \
7920 | (1u << PRAGMA_OMP_CLAUSE_SCHEDULE) \
7921 | (1u << PRAGMA_OMP_CLAUSE_COLLAPSE) \
7922 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
7925 c_parser_omp_for (c_parser *parser)
7927 tree block, clauses, ret;
7929 clauses = c_parser_omp_all_clauses (parser, OMP_FOR_CLAUSE_MASK,
7932 block = c_begin_compound_stmt (true);
7933 ret = c_parser_omp_for_loop (parser, clauses, NULL);
7934 block = c_end_compound_stmt (block, true);
7941 # pragma omp master new-line
7946 c_parser_omp_master (c_parser *parser)
7948 c_parser_skip_to_pragma_eol (parser);
7949 return c_finish_omp_master (c_parser_omp_structured_block (parser));
7953 # pragma omp ordered new-line
7958 c_parser_omp_ordered (c_parser *parser)
7960 c_parser_skip_to_pragma_eol (parser);
7961 return c_finish_omp_ordered (c_parser_omp_structured_block (parser));
7967 { section-sequence }
7970 section-directive[opt] structured-block
7971 section-sequence section-directive structured-block */
7974 c_parser_omp_sections_scope (c_parser *parser)
7977 bool error_suppress = false;
7980 if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
7982 /* Avoid skipping until the end of the block. */
7983 parser->error = false;
7987 stmt = push_stmt_list ();
7989 loc = c_parser_peek_token (parser)->location;
7990 if (c_parser_peek_token (parser)->pragma_kind != PRAGMA_OMP_SECTION)
7992 substmt = push_stmt_list ();
7996 c_parser_statement (parser);
7998 if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_OMP_SECTION)
8000 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
8002 if (c_parser_next_token_is (parser, CPP_EOF))
8006 substmt = pop_stmt_list (substmt);
8007 substmt = build1 (OMP_SECTION, void_type_node, substmt);
8008 SET_EXPR_LOCATION (substmt, loc);
8014 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
8016 if (c_parser_next_token_is (parser, CPP_EOF))
8019 loc = c_parser_peek_token (parser)->location;
8020 if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_OMP_SECTION)
8022 c_parser_consume_pragma (parser);
8023 c_parser_skip_to_pragma_eol (parser);
8024 error_suppress = false;
8026 else if (!error_suppress)
8028 error_at (loc, "expected %<#pragma omp section%> or %<}%>");
8029 error_suppress = true;
8032 substmt = c_parser_omp_structured_block (parser);
8033 substmt = build1 (OMP_SECTION, void_type_node, substmt);
8034 SET_EXPR_LOCATION (substmt, loc);
8037 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE,
8038 "expected %<#pragma omp section%> or %<}%>");
8040 substmt = pop_stmt_list (stmt);
8042 stmt = make_node (OMP_SECTIONS);
8043 TREE_TYPE (stmt) = void_type_node;
8044 OMP_SECTIONS_BODY (stmt) = substmt;
8046 return add_stmt (stmt);
8050 # pragma omp sections sections-clause[optseq] newline
8054 #define OMP_SECTIONS_CLAUSE_MASK \
8055 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8056 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8057 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
8058 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
8059 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
8062 c_parser_omp_sections (c_parser *parser)
8064 tree block, clauses, ret;
8066 clauses = c_parser_omp_all_clauses (parser, OMP_SECTIONS_CLAUSE_MASK,
8067 "#pragma omp sections");
8069 block = c_begin_compound_stmt (true);
8070 ret = c_parser_omp_sections_scope (parser);
8072 OMP_SECTIONS_CLAUSES (ret) = clauses;
8073 block = c_end_compound_stmt (block, true);
8080 # pragma parallel parallel-clause new-line
8081 # pragma parallel for parallel-for-clause new-line
8082 # pragma parallel sections parallel-sections-clause new-line
8085 #define OMP_PARALLEL_CLAUSE_MASK \
8086 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
8087 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8088 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8089 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
8090 | (1u << PRAGMA_OMP_CLAUSE_SHARED) \
8091 | (1u << PRAGMA_OMP_CLAUSE_COPYIN) \
8092 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
8093 | (1u << PRAGMA_OMP_CLAUSE_NUM_THREADS))
8096 c_parser_omp_parallel (c_parser *parser)
8098 enum pragma_kind p_kind = PRAGMA_OMP_PARALLEL;
8099 const char *p_name = "#pragma omp parallel";
8100 tree stmt, clauses, par_clause, ws_clause, block;
8101 unsigned int mask = OMP_PARALLEL_CLAUSE_MASK;
8103 if (c_parser_next_token_is_keyword (parser, RID_FOR))
8105 c_parser_consume_token (parser);
8106 p_kind = PRAGMA_OMP_PARALLEL_FOR;
8107 p_name = "#pragma omp parallel for";
8108 mask |= OMP_FOR_CLAUSE_MASK;
8109 mask &= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT);
8111 else if (c_parser_next_token_is (parser, CPP_NAME))
8113 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
8114 if (strcmp (p, "sections") == 0)
8116 c_parser_consume_token (parser);
8117 p_kind = PRAGMA_OMP_PARALLEL_SECTIONS;
8118 p_name = "#pragma omp parallel sections";
8119 mask |= OMP_SECTIONS_CLAUSE_MASK;
8120 mask &= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT);
8124 clauses = c_parser_omp_all_clauses (parser, mask, p_name);
8128 case PRAGMA_OMP_PARALLEL:
8129 block = c_begin_omp_parallel ();
8130 c_parser_statement (parser);
8131 stmt = c_finish_omp_parallel (clauses, block);
8134 case PRAGMA_OMP_PARALLEL_FOR:
8135 block = c_begin_omp_parallel ();
8136 c_split_parallel_clauses (clauses, &par_clause, &ws_clause);
8137 c_parser_omp_for_loop (parser, ws_clause, &par_clause);
8138 stmt = c_finish_omp_parallel (par_clause, block);
8139 OMP_PARALLEL_COMBINED (stmt) = 1;
8142 case PRAGMA_OMP_PARALLEL_SECTIONS:
8143 block = c_begin_omp_parallel ();
8144 c_split_parallel_clauses (clauses, &par_clause, &ws_clause);
8145 stmt = c_parser_omp_sections_scope (parser);
8147 OMP_SECTIONS_CLAUSES (stmt) = ws_clause;
8148 stmt = c_finish_omp_parallel (par_clause, block);
8149 OMP_PARALLEL_COMBINED (stmt) = 1;
8160 # pragma omp single single-clause[optseq] new-line
8164 #define OMP_SINGLE_CLAUSE_MASK \
8165 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8166 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8167 | (1u << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
8168 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
8171 c_parser_omp_single (c_parser *parser)
8173 tree stmt = make_node (OMP_SINGLE);
8174 TREE_TYPE (stmt) = void_type_node;
8176 OMP_SINGLE_CLAUSES (stmt)
8177 = c_parser_omp_all_clauses (parser, OMP_SINGLE_CLAUSE_MASK,
8178 "#pragma omp single");
8179 OMP_SINGLE_BODY (stmt) = c_parser_omp_structured_block (parser);
8181 return add_stmt (stmt);
8185 # pragma omp task task-clause[optseq] new-line
8188 #define OMP_TASK_CLAUSE_MASK \
8189 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
8190 | (1u << PRAGMA_OMP_CLAUSE_UNTIED) \
8191 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
8192 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8193 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8194 | (1u << PRAGMA_OMP_CLAUSE_SHARED))
8197 c_parser_omp_task (c_parser *parser)
8199 tree clauses, block;
8201 clauses = c_parser_omp_all_clauses (parser, OMP_TASK_CLAUSE_MASK,
8202 "#pragma omp task");
8204 block = c_begin_omp_task ();
8205 c_parser_statement (parser);
8206 return c_finish_omp_task (clauses, block);
8210 # pragma omp taskwait new-line
8214 c_parser_omp_taskwait (c_parser *parser)
8216 c_parser_consume_pragma (parser);
8217 c_parser_skip_to_pragma_eol (parser);
8219 c_finish_omp_taskwait ();
8222 /* Main entry point to parsing most OpenMP pragmas. */
8225 c_parser_omp_construct (c_parser *parser)
8227 enum pragma_kind p_kind;
8231 loc = c_parser_peek_token (parser)->location;
8232 p_kind = c_parser_peek_token (parser)->pragma_kind;
8233 c_parser_consume_pragma (parser);
8235 /* For all constructs below except #pragma omp atomic
8236 MUST_NOT_THROW catch handlers are needed when exceptions
8238 if (p_kind != PRAGMA_OMP_ATOMIC)
8239 c_maybe_initialize_eh ();
8243 case PRAGMA_OMP_ATOMIC:
8244 c_parser_omp_atomic (parser);
8246 case PRAGMA_OMP_CRITICAL:
8247 stmt = c_parser_omp_critical (parser);
8249 case PRAGMA_OMP_FOR:
8250 stmt = c_parser_omp_for (parser);
8252 case PRAGMA_OMP_MASTER:
8253 stmt = c_parser_omp_master (parser);
8255 case PRAGMA_OMP_ORDERED:
8256 stmt = c_parser_omp_ordered (parser);
8258 case PRAGMA_OMP_PARALLEL:
8259 stmt = c_parser_omp_parallel (parser);
8261 case PRAGMA_OMP_SECTIONS:
8262 stmt = c_parser_omp_sections (parser);
8264 case PRAGMA_OMP_SINGLE:
8265 stmt = c_parser_omp_single (parser);
8267 case PRAGMA_OMP_TASK:
8268 stmt = c_parser_omp_task (parser);
8275 SET_EXPR_LOCATION (stmt, loc);
8280 # pragma omp threadprivate (variable-list) */
8283 c_parser_omp_threadprivate (c_parser *parser)
8287 c_parser_consume_pragma (parser);
8288 vars = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL);
8290 /* Mark every variable in VARS to be assigned thread local storage. */
8291 for (t = vars; t; t = TREE_CHAIN (t))
8293 tree v = TREE_PURPOSE (t);
8295 /* If V had already been marked threadprivate, it doesn't matter
8296 whether it had been used prior to this point. */
8297 if (TREE_CODE (v) != VAR_DECL)
8298 error ("%qD is not a variable", v);
8299 else if (TREE_USED (v) && !C_DECL_THREADPRIVATE_P (v))
8300 error ("%qE declared %<threadprivate%> after first use", v);
8301 else if (! TREE_STATIC (v) && ! DECL_EXTERNAL (v))
8302 error ("automatic variable %qE cannot be %<threadprivate%>", v);
8303 else if (TREE_TYPE (v) == error_mark_node)
8305 else if (! COMPLETE_TYPE_P (TREE_TYPE (v)))
8306 error ("%<threadprivate%> %qE has incomplete type", v);
8309 if (! DECL_THREAD_LOCAL_P (v))
8311 DECL_TLS_MODEL (v) = decl_default_tls_model (v);
8312 /* If rtl has been already set for this var, call
8313 make_decl_rtl once again, so that encode_section_info
8314 has a chance to look at the new decl flags. */
8315 if (DECL_RTL_SET_P (v))
8318 C_DECL_THREADPRIVATE_P (v) = 1;
8322 c_parser_skip_to_pragma_eol (parser);
8326 /* Parse a single source file. */
8331 /* Use local storage to begin. If the first token is a pragma, parse it.
8332 If it is #pragma GCC pch_preprocess, then this will load a PCH file
8333 which will cause garbage collection. */
8336 memset (&tparser, 0, sizeof tparser);
8337 the_parser = &tparser;
8339 if (c_parser_peek_token (&tparser)->pragma_kind == PRAGMA_GCC_PCH_PREPROCESS)
8340 c_parser_pragma_pch_preprocess (&tparser);
8342 the_parser = GGC_NEW (c_parser);
8343 *the_parser = tparser;
8345 c_parser_translation_unit (the_parser);
8349 #include "gt-c-parser.h"