1 /* Parser for C and Objective-C.
2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008
4 Free Software Foundation, Inc.
6 Parser actions based on the old Bison parser; structure somewhat
7 influenced by and fragments based on the C++ parser.
9 This file is part of GCC.
11 GCC is free software; you can redistribute it and/or modify it under
12 the terms of the GNU General Public License as published by the Free
13 Software Foundation; either version 3, or (at your option) any later
16 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
17 WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with GCC; see the file COPYING3. If not see
23 <http://www.gnu.org/licenses/>. */
27 Make sure all relevant comments, and all relevant code from all
28 actions, brought over from old parser. Verify exact correspondence
31 Add testcases covering every input symbol in every state in old and
34 Include full syntax for GNU C, including erroneous cases accepted
35 with error messages, in syntax productions in comments.
37 Make more diagnostics in the front end generally take an explicit
38 location rather than implicitly using input_location. */
42 #include "coretypes.h"
46 #include "langhooks.h"
62 /* Initialization routine for this file. */
67 /* The only initialization required is of the reserved word
78 mask |= D_ASM | D_EXT;
82 if (!c_dialect_objc ())
83 mask |= D_OBJC | D_CXX_OBJC;
85 ridpointers = GGC_CNEWVEC (tree, (int) RID_MAX);
86 for (i = 0; i < num_c_common_reswords; i++)
88 /* If a keyword is disabled, do not enter it into the table
89 and so create a canonical spelling that isn't a keyword. */
90 if (c_common_reswords[i].disable & mask)
93 && (c_common_reswords[i].disable & D_CXXWARN))
95 id = get_identifier (c_common_reswords[i].word);
96 C_SET_RID_CODE (id, RID_CXX_COMPAT_WARN);
97 C_IS_RESERVED_WORD (id) = 1;
102 id = get_identifier (c_common_reswords[i].word);
103 C_SET_RID_CODE (id, c_common_reswords[i].rid);
104 C_IS_RESERVED_WORD (id) = 1;
105 ridpointers [(int) c_common_reswords[i].rid] = id;
109 /* The C lexer intermediates between the lexer in cpplib and c-lex.c
110 and the C parser. Unlike the C++ lexer, the parser structure
111 stores the lexer information instead of using a separate structure.
112 Identifiers are separated into ordinary identifiers, type names,
113 keywords and some other Objective-C types of identifiers, and some
114 look-ahead is maintained.
116 ??? It might be a good idea to lex the whole file up front (as for
117 C++). It would then be possible to share more of the C and C++
118 lexer code, if desired. */
120 /* The following local token type is used. */
123 #define CPP_KEYWORD ((enum cpp_ttype) (N_TTYPES + 1))
125 /* More information about the type of a CPP_NAME token. */
126 typedef enum c_id_kind {
127 /* An ordinary identifier. */
129 /* An identifier declared as a typedef name. */
131 /* An identifier declared as an Objective-C class name. */
133 /* Not an identifier. */
137 /* A single C token after string literal concatenation and conversion
138 of preprocessing tokens to tokens. */
139 typedef struct c_token GTY (())
141 /* The kind of token. */
142 ENUM_BITFIELD (cpp_ttype) type : 8;
143 /* If this token is a CPP_NAME, this value indicates whether also
144 declared as some kind of type. Otherwise, it is C_ID_NONE. */
145 ENUM_BITFIELD (c_id_kind) id_kind : 8;
146 /* If this token is a keyword, this value indicates which keyword.
147 Otherwise, this value is RID_MAX. */
148 ENUM_BITFIELD (rid) keyword : 8;
149 /* If this token is a CPP_PRAGMA, this indicates the pragma that
150 was seen. Otherwise it is PRAGMA_NONE. */
151 ENUM_BITFIELD (pragma_kind) pragma_kind : 7;
152 /* 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 (OPT_Wc___compat,
225 "%Hidentifier %qs conflicts with C++ keyword",
227 IDENTIFIER_POINTER (token->value));
229 else if (c_dialect_objc ())
231 if (!objc_is_reserved_word (token->value)
232 && (!OBJC_IS_PQ_KEYWORD (rid_code)
233 || parser->objc_pq_context))
235 /* Return the canonical spelling for this keyword. */
236 token->value = ridpointers[(int) rid_code];
237 token->type = CPP_KEYWORD;
238 token->keyword = rid_code;
244 token->type = CPP_KEYWORD;
245 token->keyword = rid_code;
250 decl = lookup_name (token->value);
253 if (TREE_CODE (decl) == TYPE_DECL)
255 token->id_kind = C_ID_TYPENAME;
259 else if (c_dialect_objc ())
261 tree objc_interface_decl = objc_is_class_name (token->value);
262 /* Objective-C class names are in the same namespace as
263 variables and typedefs, and hence are shadowed by local
265 if (objc_interface_decl
266 && (global_bindings_p ()
267 || (!objc_force_identifier && !decl)))
269 token->value = objc_interface_decl;
270 token->id_kind = C_ID_CLASSNAME;
274 token->id_kind = C_ID_ID;
278 /* This only happens in Objective-C; it must be a keyword. */
279 token->type = CPP_KEYWORD;
280 token->keyword = C_RID_CODE (token->value);
284 case CPP_CLOSE_PAREN:
286 /* These tokens may affect the interpretation of any identifiers
287 following, if doing Objective-C. */
288 if (c_dialect_objc ())
289 parser->objc_need_raw_identifier = false;
292 /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */
293 token->pragma_kind = (enum pragma_kind) TREE_INT_CST_LOW (token->value);
299 timevar_pop (TV_LEX);
302 /* Return a pointer to the next token from PARSER, reading it in if
305 static inline c_token *
306 c_parser_peek_token (c_parser *parser)
308 if (parser->tokens_avail == 0)
310 c_lex_one_token (parser, &parser->tokens[0]);
311 parser->tokens_avail = 1;
313 return &parser->tokens[0];
316 /* Return true if the next token from PARSER has the indicated
320 c_parser_next_token_is (c_parser *parser, enum cpp_ttype type)
322 return c_parser_peek_token (parser)->type == type;
325 /* Return true if the next token from PARSER does not have the
329 c_parser_next_token_is_not (c_parser *parser, enum cpp_ttype type)
331 return !c_parser_next_token_is (parser, type);
334 /* Return true if the next token from PARSER is the indicated
338 c_parser_next_token_is_keyword (c_parser *parser, enum rid keyword)
340 return c_parser_peek_token (parser)->keyword == keyword;
343 /* Return true if TOKEN can start a type name,
346 c_token_starts_typename (c_token *token)
351 switch (token->id_kind)
358 gcc_assert (c_dialect_objc ());
364 switch (token->keyword)
396 if (c_dialect_objc ())
404 /* Return true if the next token from PARSER can start a type name,
407 c_parser_next_token_starts_typename (c_parser *parser)
409 c_token *token = c_parser_peek_token (parser);
410 return c_token_starts_typename (token);
413 /* Return true if TOKEN can start declaration specifiers, false
416 c_token_starts_declspecs (c_token *token)
421 switch (token->id_kind)
428 gcc_assert (c_dialect_objc ());
434 switch (token->keyword)
473 if (c_dialect_objc ())
481 /* Return true if the next token from PARSER can start declaration
482 specifiers, false otherwise. */
484 c_parser_next_token_starts_declspecs (c_parser *parser)
486 c_token *token = c_parser_peek_token (parser);
487 return c_token_starts_declspecs (token);
490 /* Return a pointer to the next-but-one token from PARSER, reading it
491 in if necessary. The next token is already read in. */
494 c_parser_peek_2nd_token (c_parser *parser)
496 if (parser->tokens_avail >= 2)
497 return &parser->tokens[1];
498 gcc_assert (parser->tokens_avail == 1);
499 gcc_assert (parser->tokens[0].type != CPP_EOF);
500 gcc_assert (parser->tokens[0].type != CPP_PRAGMA_EOL);
501 c_lex_one_token (parser, &parser->tokens[1]);
502 parser->tokens_avail = 2;
503 return &parser->tokens[1];
506 /* Consume the next token from PARSER. */
509 c_parser_consume_token (c_parser *parser)
511 gcc_assert (parser->tokens_avail >= 1);
512 gcc_assert (parser->tokens[0].type != CPP_EOF);
513 gcc_assert (!parser->in_pragma || parser->tokens[0].type != CPP_PRAGMA_EOL);
514 gcc_assert (parser->error || parser->tokens[0].type != CPP_PRAGMA);
515 if (parser->tokens_avail == 2)
516 parser->tokens[0] = parser->tokens[1];
517 parser->tokens_avail--;
520 /* Expect the current token to be a #pragma. Consume it and remember
521 that we've begun parsing a pragma. */
524 c_parser_consume_pragma (c_parser *parser)
526 gcc_assert (!parser->in_pragma);
527 gcc_assert (parser->tokens_avail >= 1);
528 gcc_assert (parser->tokens[0].type == CPP_PRAGMA);
529 if (parser->tokens_avail == 2)
530 parser->tokens[0] = parser->tokens[1];
531 parser->tokens_avail--;
532 parser->in_pragma = true;
535 /* Update the globals input_location and in_system_header from
538 c_parser_set_source_position_from_token (c_token *token)
540 if (token->type != CPP_EOF)
542 input_location = token->location;
546 /* Issue a diagnostic of the form
547 FILE:LINE: MESSAGE before TOKEN
548 where TOKEN is the next token in the input stream of PARSER.
549 MESSAGE (specified by the caller) is usually of the form "expected
552 Do not issue a diagnostic if still recovering from an error.
554 ??? This is taken from the C++ parser, but building up messages in
555 this way is not i18n-friendly and some other approach should be
559 c_parser_error (c_parser *parser, const char *gmsgid)
561 c_token *token = c_parser_peek_token (parser);
564 parser->error = true;
567 /* This diagnostic makes more sense if it is tagged to the line of
568 the token we just peeked at. */
569 c_parser_set_source_position_from_token (token);
570 c_parse_error (gmsgid,
571 /* Because c_parse_error does not understand
572 CPP_KEYWORD, keywords are treated like
574 (token->type == CPP_KEYWORD ? CPP_NAME : token->type),
578 /* If the next token is of the indicated TYPE, consume it. Otherwise,
579 issue the error MSGID. If MSGID is NULL then a message has already
580 been produced and no message will be produced this time. Returns
581 true if found, false otherwise. */
584 c_parser_require (c_parser *parser,
588 if (c_parser_next_token_is (parser, type))
590 c_parser_consume_token (parser);
595 c_parser_error (parser, msgid);
600 /* If the next token is the indicated keyword, consume it. Otherwise,
601 issue the error MSGID. Returns true if found, false otherwise. */
604 c_parser_require_keyword (c_parser *parser,
608 if (c_parser_next_token_is_keyword (parser, keyword))
610 c_parser_consume_token (parser);
615 c_parser_error (parser, msgid);
620 /* Like c_parser_require, except that tokens will be skipped until the
621 desired token is found. An error message is still produced if the
622 next token is not as expected. If MSGID is NULL then a message has
623 already been produced and no message will be produced this
627 c_parser_skip_until_found (c_parser *parser,
631 unsigned nesting_depth = 0;
633 if (c_parser_require (parser, type, msgid))
636 /* Skip tokens until the desired token is found. */
639 /* Peek at the next token. */
640 c_token *token = c_parser_peek_token (parser);
641 /* If we've reached the token we want, consume it and stop. */
642 if (token->type == type && !nesting_depth)
644 c_parser_consume_token (parser);
648 /* If we've run out of tokens, stop. */
649 if (token->type == CPP_EOF)
651 if (token->type == CPP_PRAGMA_EOL && parser->in_pragma)
653 if (token->type == CPP_OPEN_BRACE
654 || token->type == CPP_OPEN_PAREN
655 || token->type == CPP_OPEN_SQUARE)
657 else if (token->type == CPP_CLOSE_BRACE
658 || token->type == CPP_CLOSE_PAREN
659 || token->type == CPP_CLOSE_SQUARE)
661 if (nesting_depth-- == 0)
664 /* Consume this token. */
665 c_parser_consume_token (parser);
667 parser->error = false;
670 /* Skip tokens until the end of a parameter is found, but do not
671 consume the comma, semicolon or closing delimiter. */
674 c_parser_skip_to_end_of_parameter (c_parser *parser)
676 unsigned nesting_depth = 0;
680 c_token *token = c_parser_peek_token (parser);
681 if ((token->type == CPP_COMMA || token->type == CPP_SEMICOLON)
684 /* If we've run out of tokens, stop. */
685 if (token->type == CPP_EOF)
687 if (token->type == CPP_PRAGMA_EOL && parser->in_pragma)
689 if (token->type == CPP_OPEN_BRACE
690 || token->type == CPP_OPEN_PAREN
691 || token->type == CPP_OPEN_SQUARE)
693 else if (token->type == CPP_CLOSE_BRACE
694 || token->type == CPP_CLOSE_PAREN
695 || token->type == CPP_CLOSE_SQUARE)
697 if (nesting_depth-- == 0)
700 /* Consume this token. */
701 c_parser_consume_token (parser);
703 parser->error = false;
706 /* Expect to be at the end of the pragma directive and consume an
707 end of line marker. */
710 c_parser_skip_to_pragma_eol (c_parser *parser)
712 gcc_assert (parser->in_pragma);
713 parser->in_pragma = false;
715 if (!c_parser_require (parser, CPP_PRAGMA_EOL, "expected end of line"))
718 c_token *token = c_parser_peek_token (parser);
719 if (token->type == CPP_EOF)
721 if (token->type == CPP_PRAGMA_EOL)
723 c_parser_consume_token (parser);
726 c_parser_consume_token (parser);
729 parser->error = false;
732 /* Skip tokens until we have consumed an entire block, or until we
733 have consumed a non-nested ';'. */
736 c_parser_skip_to_end_of_block_or_statement (c_parser *parser)
738 unsigned nesting_depth = 0;
739 bool save_error = parser->error;
745 /* Peek at the next token. */
746 token = c_parser_peek_token (parser);
754 if (parser->in_pragma)
759 /* If the next token is a ';', we have reached the
760 end of the statement. */
763 /* Consume the ';'. */
764 c_parser_consume_token (parser);
769 case CPP_CLOSE_BRACE:
770 /* If the next token is a non-nested '}', then we have
771 reached the end of the current block. */
772 if (nesting_depth == 0 || --nesting_depth == 0)
774 c_parser_consume_token (parser);
780 /* If it the next token is a '{', then we are entering a new
781 block. Consume the entire block. */
786 /* If we see a pragma, consume the whole thing at once. We
787 have some safeguards against consuming pragmas willy-nilly.
788 Normally, we'd expect to be here with parser->error set,
789 which disables these safeguards. But it's possible to get
790 here for secondary error recovery, after parser->error has
792 c_parser_consume_pragma (parser);
793 c_parser_skip_to_pragma_eol (parser);
794 parser->error = save_error;
801 c_parser_consume_token (parser);
805 parser->error = false;
808 /* CPP's options (initialized by c-opts.c). */
809 extern cpp_options *cpp_opts;
811 /* Save the warning flags which are controlled by __extension__. */
814 disable_extension_diagnostics (void)
817 | (warn_pointer_arith << 1)
818 | (warn_traditional << 2)
820 | (warn_long_long << 4)
821 | (cpp_opts->warn_long_long << 5));
822 cpp_opts->pedantic = pedantic = 0;
823 warn_pointer_arith = 0;
824 cpp_opts->warn_traditional = warn_traditional = 0;
827 cpp_opts->warn_long_long = 0;
831 /* Restore the warning flags which are controlled by __extension__.
832 FLAGS is the return value from disable_extension_diagnostics. */
835 restore_extension_diagnostics (int flags)
837 cpp_opts->pedantic = pedantic = flags & 1;
838 warn_pointer_arith = (flags >> 1) & 1;
839 cpp_opts->warn_traditional = warn_traditional = (flags >> 2) & 1;
840 flag_iso = (flags >> 3) & 1;
841 warn_long_long = (flags >> 4) & 1;
842 cpp_opts->warn_long_long = (flags >> 5) & 1;
845 /* Possibly kinds of declarator to parse. */
846 typedef enum c_dtr_syn {
847 /* A normal declarator with an identifier. */
849 /* An abstract declarator (maybe empty). */
851 /* A parameter declarator: may be either, but after a type name does
852 not redeclare a typedef name as an identifier if it can
853 alternatively be interpreted as a typedef name; see DR#009,
854 applied in C90 TC1, omitted from C99 and reapplied in C99 TC2
855 following DR#249. For example, given a typedef T, "int T" and
856 "int *T" are valid parameter declarations redeclaring T, while
857 "int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are
858 abstract declarators rather than involving redundant parentheses;
859 the same applies with attributes inside the parentheses before
864 static void c_parser_external_declaration (c_parser *);
865 static void c_parser_asm_definition (c_parser *);
866 static void c_parser_declaration_or_fndef (c_parser *, bool, bool, bool, bool);
867 static void c_parser_declspecs (c_parser *, struct c_declspecs *, bool, bool,
869 static struct c_typespec c_parser_enum_specifier (c_parser *);
870 static struct c_typespec c_parser_struct_or_union_specifier (c_parser *);
871 static tree c_parser_struct_declaration (c_parser *);
872 static struct c_typespec c_parser_typeof_specifier (c_parser *);
873 static struct c_declarator *c_parser_declarator (c_parser *, bool, c_dtr_syn,
875 static struct c_declarator *c_parser_direct_declarator (c_parser *, bool,
877 static struct c_declarator *c_parser_direct_declarator_inner (c_parser *,
879 struct c_declarator *);
880 static struct c_arg_info *c_parser_parms_declarator (c_parser *, bool, tree);
881 static struct c_arg_info *c_parser_parms_list_declarator (c_parser *, tree);
882 static struct c_parm *c_parser_parameter_declaration (c_parser *, tree);
883 static tree c_parser_simple_asm_expr (c_parser *);
884 static tree c_parser_attributes (c_parser *);
885 static struct c_type_name *c_parser_type_name (c_parser *);
886 static struct c_expr c_parser_initializer (c_parser *);
887 static struct c_expr c_parser_braced_init (c_parser *, tree, bool);
888 static void c_parser_initelt (c_parser *);
889 static void c_parser_initval (c_parser *, struct c_expr *);
890 static tree c_parser_compound_statement (c_parser *);
891 static void c_parser_compound_statement_nostart (c_parser *);
892 static void c_parser_label (c_parser *);
893 static void c_parser_statement (c_parser *);
894 static void c_parser_statement_after_labels (c_parser *);
895 static void c_parser_if_statement (c_parser *);
896 static void c_parser_switch_statement (c_parser *);
897 static void c_parser_while_statement (c_parser *);
898 static void c_parser_do_statement (c_parser *);
899 static void c_parser_for_statement (c_parser *);
900 static tree c_parser_asm_statement (c_parser *);
901 static tree c_parser_asm_operands (c_parser *, bool);
902 static tree c_parser_asm_clobbers (c_parser *);
903 static struct c_expr c_parser_expr_no_commas (c_parser *, struct c_expr *);
904 static struct c_expr c_parser_conditional_expression (c_parser *,
906 static struct c_expr c_parser_binary_expression (c_parser *, struct c_expr *);
907 static struct c_expr c_parser_cast_expression (c_parser *, struct c_expr *);
908 static struct c_expr c_parser_unary_expression (c_parser *);
909 static struct c_expr c_parser_sizeof_expression (c_parser *);
910 static struct c_expr c_parser_alignof_expression (c_parser *);
911 static struct c_expr c_parser_postfix_expression (c_parser *);
912 static struct c_expr c_parser_postfix_expression_after_paren_type (c_parser *,
913 struct c_type_name *);
914 static struct c_expr c_parser_postfix_expression_after_primary (c_parser *,
916 static struct c_expr c_parser_expression (c_parser *);
917 static struct c_expr c_parser_expression_conv (c_parser *);
918 static tree c_parser_expr_list (c_parser *, bool);
919 static void c_parser_omp_construct (c_parser *);
920 static void c_parser_omp_threadprivate (c_parser *);
921 static void c_parser_omp_barrier (c_parser *);
922 static void c_parser_omp_flush (c_parser *);
923 static void c_parser_omp_taskwait (c_parser *);
925 enum pragma_context { pragma_external, pragma_stmt, pragma_compound };
926 static bool c_parser_pragma (c_parser *, enum pragma_context);
928 /* These Objective-C parser functions are only ever called when
929 compiling Objective-C. */
930 static void c_parser_objc_class_definition (c_parser *);
931 static void c_parser_objc_class_instance_variables (c_parser *);
932 static void c_parser_objc_class_declaration (c_parser *);
933 static void c_parser_objc_alias_declaration (c_parser *);
934 static void c_parser_objc_protocol_definition (c_parser *);
935 static enum tree_code c_parser_objc_method_type (c_parser *);
936 static void c_parser_objc_method_definition (c_parser *);
937 static void c_parser_objc_methodprotolist (c_parser *);
938 static void c_parser_objc_methodproto (c_parser *);
939 static tree c_parser_objc_method_decl (c_parser *);
940 static tree c_parser_objc_type_name (c_parser *);
941 static tree c_parser_objc_protocol_refs (c_parser *);
942 static void c_parser_objc_try_catch_statement (c_parser *);
943 static void c_parser_objc_synchronized_statement (c_parser *);
944 static tree c_parser_objc_selector (c_parser *);
945 static tree c_parser_objc_selector_arg (c_parser *);
946 static tree c_parser_objc_receiver (c_parser *);
947 static tree c_parser_objc_message_args (c_parser *);
948 static tree c_parser_objc_keywordexpr (c_parser *);
950 /* Parse a translation unit (C90 6.7, C99 6.9).
953 external-declarations
955 external-declarations:
957 external-declarations external-declaration
966 c_parser_translation_unit (c_parser *parser)
968 if (c_parser_next_token_is (parser, CPP_EOF))
970 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
971 "ISO C forbids an empty translation unit");
975 void *obstack_position = obstack_alloc (&parser_obstack, 0);
979 c_parser_external_declaration (parser);
980 obstack_free (&parser_obstack, obstack_position);
982 while (c_parser_next_token_is_not (parser, CPP_EOF));
986 /* Parse an external declaration (C90 6.7, C99 6.9).
988 external-declaration:
994 external-declaration:
997 __extension__ external-declaration
1001 external-declaration:
1002 objc-class-definition
1003 objc-class-declaration
1004 objc-alias-declaration
1005 objc-protocol-definition
1006 objc-method-definition
1011 c_parser_external_declaration (c_parser *parser)
1014 switch (c_parser_peek_token (parser)->type)
1017 switch (c_parser_peek_token (parser)->keyword)
1020 ext = disable_extension_diagnostics ();
1021 c_parser_consume_token (parser);
1022 c_parser_external_declaration (parser);
1023 restore_extension_diagnostics (ext);
1026 c_parser_asm_definition (parser);
1028 case RID_AT_INTERFACE:
1029 case RID_AT_IMPLEMENTATION:
1030 gcc_assert (c_dialect_objc ());
1031 c_parser_objc_class_definition (parser);
1034 gcc_assert (c_dialect_objc ());
1035 c_parser_objc_class_declaration (parser);
1038 gcc_assert (c_dialect_objc ());
1039 c_parser_objc_alias_declaration (parser);
1041 case RID_AT_PROTOCOL:
1042 gcc_assert (c_dialect_objc ());
1043 c_parser_objc_protocol_definition (parser);
1046 gcc_assert (c_dialect_objc ());
1047 c_parser_consume_token (parser);
1048 objc_finish_implementation ();
1055 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
1056 "ISO C does not allow extra %<;%> outside of a function");
1057 c_parser_consume_token (parser);
1060 c_parser_pragma (parser, pragma_external);
1064 if (c_dialect_objc ())
1066 c_parser_objc_method_definition (parser);
1069 /* Else fall through, and yield a syntax error trying to parse
1070 as a declaration or function definition. */
1073 /* A declaration or a function definition. We can only tell
1074 which after parsing the declaration specifiers, if any, and
1075 the first declarator. */
1076 c_parser_declaration_or_fndef (parser, true, true, false, true);
1082 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1083 6.7, 6.9.1). If FNDEF_OK is true, a function definition is
1084 accepted; otherwise (old-style parameter declarations) only other
1085 declarations are accepted. If NESTED is true, we are inside a
1086 function or parsing old-style parameter declarations; any functions
1087 encountered are nested functions and declaration specifiers are
1088 required; otherwise we are at top level and functions are normal
1089 functions and declaration specifiers may be optional. If EMPTY_OK
1090 is true, empty declarations are OK (subject to all other
1091 constraints); otherwise (old-style parameter declarations) they are
1092 diagnosed. If START_ATTR_OK is true, the declaration specifiers
1093 may start with attributes; otherwise they may not.
1096 declaration-specifiers init-declarator-list[opt] ;
1098 function-definition:
1099 declaration-specifiers[opt] declarator declaration-list[opt]
1104 declaration-list declaration
1106 init-declarator-list:
1108 init-declarator-list , init-declarator
1111 declarator simple-asm-expr[opt] attributes[opt]
1112 declarator simple-asm-expr[opt] attributes[opt] = initializer
1116 nested-function-definition:
1117 declaration-specifiers declarator declaration-list[opt]
1120 The simple-asm-expr and attributes are GNU extensions.
1122 This function does not handle __extension__; that is handled in its
1123 callers. ??? Following the old parser, __extension__ may start
1124 external declarations, declarations in functions and declarations
1125 at the start of "for" loops, but not old-style parameter
1128 C99 requires declaration specifiers in a function definition; the
1129 absence is diagnosed through the diagnosis of implicit int. In GNU
1130 C we also allow but diagnose declarations without declaration
1131 specifiers, but only at top level (elsewhere they conflict with
1137 threadprivate-directive */
1140 c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok, bool empty_ok,
1141 bool nested, bool start_attr_ok)
1143 struct c_declspecs *specs;
1145 tree all_prefix_attrs;
1146 bool diagnosed_no_specs = false;
1147 location_t here = c_parser_peek_token (parser)->location;
1149 specs = build_null_declspecs ();
1150 c_parser_declspecs (parser, specs, true, true, start_attr_ok);
1153 c_parser_skip_to_end_of_block_or_statement (parser);
1156 if (nested && !specs->declspecs_seen_p)
1158 c_parser_error (parser, "expected declaration specifiers");
1159 c_parser_skip_to_end_of_block_or_statement (parser);
1162 finish_declspecs (specs);
1163 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1169 shadow_tag_warned (specs, 1);
1170 pedwarn (here, 0, "empty declaration");
1172 c_parser_consume_token (parser);
1175 pending_xref_error ();
1176 prefix_attrs = specs->attrs;
1177 all_prefix_attrs = prefix_attrs;
1178 specs->attrs = NULL_TREE;
1181 struct c_declarator *declarator;
1184 /* Declaring either one or more declarators (in which case we
1185 should diagnose if there were no declaration specifiers) or a
1186 function definition (in which case the diagnostic for
1187 implicit int suffices). */
1188 declarator = c_parser_declarator (parser, specs->type_seen_p,
1189 C_DTR_NORMAL, &dummy);
1190 if (declarator == NULL)
1192 c_parser_skip_to_end_of_block_or_statement (parser);
1195 if (c_parser_next_token_is (parser, CPP_EQ)
1196 || c_parser_next_token_is (parser, CPP_COMMA)
1197 || c_parser_next_token_is (parser, CPP_SEMICOLON)
1198 || c_parser_next_token_is_keyword (parser, RID_ASM)
1199 || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1201 tree asm_name = NULL_TREE;
1202 tree postfix_attrs = NULL_TREE;
1203 if (!diagnosed_no_specs && !specs->declspecs_seen_p)
1205 diagnosed_no_specs = true;
1206 pedwarn (here, 0, "data definition has no type or storage class");
1208 /* Having seen a data definition, there cannot now be a
1209 function definition. */
1211 if (c_parser_next_token_is_keyword (parser, RID_ASM))
1212 asm_name = c_parser_simple_asm_expr (parser);
1213 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1214 postfix_attrs = c_parser_attributes (parser);
1215 if (c_parser_next_token_is (parser, CPP_EQ))
1219 c_parser_consume_token (parser);
1220 /* The declaration of the variable is in effect while
1221 its initializer is parsed. */
1222 d = start_decl (declarator, specs, true,
1223 chainon (postfix_attrs, all_prefix_attrs));
1225 d = error_mark_node;
1226 start_init (d, asm_name, global_bindings_p ());
1227 init = c_parser_initializer (parser);
1229 if (d != error_mark_node)
1231 maybe_warn_string_init (TREE_TYPE (d), init);
1232 finish_decl (d, init.value, asm_name);
1237 tree d = start_decl (declarator, specs, false,
1238 chainon (postfix_attrs,
1241 finish_decl (d, NULL_TREE, asm_name);
1243 if (c_parser_next_token_is (parser, CPP_COMMA))
1245 c_parser_consume_token (parser);
1246 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1247 all_prefix_attrs = chainon (c_parser_attributes (parser),
1250 all_prefix_attrs = prefix_attrs;
1253 else if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1255 c_parser_consume_token (parser);
1260 c_parser_error (parser, "expected %<,%> or %<;%>");
1261 c_parser_skip_to_end_of_block_or_statement (parser);
1267 c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, "
1268 "%<asm%> or %<__attribute__%>");
1269 c_parser_skip_to_end_of_block_or_statement (parser);
1272 /* Function definition (nested or otherwise). */
1275 pedwarn (here, OPT_pedantic, "ISO C forbids nested functions");
1276 c_push_function_context ();
1278 if (!start_function (specs, declarator, all_prefix_attrs))
1280 /* This can appear in many cases looking nothing like a
1281 function definition, so we don't give a more specific
1282 error suggesting there was one. */
1283 c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
1284 "or %<__attribute__%>");
1286 c_pop_function_context ();
1289 /* Parse old-style parameter declarations. ??? Attributes are
1290 not allowed to start declaration specifiers here because of a
1291 syntax conflict between a function declaration with attribute
1292 suffix and a function definition with an attribute prefix on
1293 first old-style parameter declaration. Following the old
1294 parser, they are not accepted on subsequent old-style
1295 parameter declarations either. However, there is no
1296 ambiguity after the first declaration, nor indeed on the
1297 first as long as we don't allow postfix attributes after a
1298 declarator with a nonempty identifier list in a definition;
1299 and postfix attributes have never been accepted here in
1300 function definitions either. */
1301 while (c_parser_next_token_is_not (parser, CPP_EOF)
1302 && c_parser_next_token_is_not (parser, CPP_OPEN_BRACE))
1303 c_parser_declaration_or_fndef (parser, false, false, true, false);
1304 DECL_SOURCE_LOCATION (current_function_decl)
1305 = c_parser_peek_token (parser)->location;
1306 store_parm_decls ();
1307 fnbody = c_parser_compound_statement (parser);
1310 tree decl = current_function_decl;
1313 c_pop_function_context ();
1314 add_stmt (build_stmt (DECL_EXPR, decl));
1325 /* Parse an asm-definition (asm() outside a function body). This is a
1333 c_parser_asm_definition (c_parser *parser)
1335 tree asm_str = c_parser_simple_asm_expr (parser);
1337 cgraph_add_asm_node (asm_str);
1338 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
1341 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
1342 6.7), adding them to SPECS (which may already include some).
1343 Storage class specifiers are accepted iff SCSPEC_OK; type
1344 specifiers are accepted iff TYPESPEC_OK; attributes are accepted at
1345 the start iff START_ATTR_OK.
1347 declaration-specifiers:
1348 storage-class-specifier declaration-specifiers[opt]
1349 type-specifier declaration-specifiers[opt]
1350 type-qualifier declaration-specifiers[opt]
1351 function-specifier declaration-specifiers[opt]
1353 Function specifiers (inline) are from C99, and are currently
1354 handled as storage class specifiers, as is __thread.
1356 C90 6.5.1, C99 6.7.1:
1357 storage-class-specifier:
1368 C90 6.5.2, C99 6.7.2:
1381 [_Imaginary removed in C99 TC2]
1382 struct-or-union-specifier
1386 (_Bool and _Complex are new in C99.)
1388 C90 6.5.3, C99 6.7.3:
1395 (restrict is new in C99.)
1399 declaration-specifiers:
1400 attributes declaration-specifiers[opt]
1402 storage-class-specifier:
1414 (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
1415 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
1420 class-name objc-protocol-refs[opt]
1421 typedef-name objc-protocol-refs
1426 c_parser_declspecs (c_parser *parser, struct c_declspecs *specs,
1427 bool scspec_ok, bool typespec_ok, bool start_attr_ok)
1429 bool attrs_ok = start_attr_ok;
1430 bool seen_type = specs->type_seen_p;
1431 while (c_parser_next_token_is (parser, CPP_NAME)
1432 || c_parser_next_token_is (parser, CPP_KEYWORD)
1433 || (c_dialect_objc () && c_parser_next_token_is (parser, CPP_LESS)))
1435 struct c_typespec t;
1437 if (c_parser_next_token_is (parser, CPP_NAME))
1439 tree value = c_parser_peek_token (parser)->value;
1440 c_id_kind kind = c_parser_peek_token (parser)->id_kind;
1441 /* This finishes the specifiers unless a type name is OK, it
1442 is declared as a type name and a type name hasn't yet
1444 if (!typespec_ok || seen_type
1445 || (kind != C_ID_TYPENAME && kind != C_ID_CLASSNAME))
1447 c_parser_consume_token (parser);
1450 if (kind == C_ID_TYPENAME
1451 && (!c_dialect_objc ()
1452 || c_parser_next_token_is_not (parser, CPP_LESS)))
1454 t.kind = ctsk_typedef;
1455 /* For a typedef name, record the meaning, not the name.
1456 In case of 'foo foo, bar;'. */
1457 t.spec = lookup_name (value);
1461 tree proto = NULL_TREE;
1462 gcc_assert (c_dialect_objc ());
1464 if (c_parser_next_token_is (parser, CPP_LESS))
1465 proto = c_parser_objc_protocol_refs (parser);
1466 t.spec = objc_get_protocol_qualified_type (value, proto);
1468 declspecs_add_type (specs, t);
1471 if (c_parser_next_token_is (parser, CPP_LESS))
1473 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
1474 nisse@lysator.liu.se. */
1476 gcc_assert (c_dialect_objc ());
1477 if (!typespec_ok || seen_type)
1479 proto = c_parser_objc_protocol_refs (parser);
1481 t.spec = objc_get_protocol_qualified_type (NULL_TREE, proto);
1482 declspecs_add_type (specs, t);
1485 gcc_assert (c_parser_next_token_is (parser, CPP_KEYWORD));
1486 switch (c_parser_peek_token (parser)->keyword)
1498 /* TODO: Distinguish between function specifiers (inline)
1499 and storage class specifiers, either here or in
1500 declspecs_add_scspec. */
1501 declspecs_add_scspec (specs, c_parser_peek_token (parser)->value);
1502 c_parser_consume_token (parser);
1525 if (c_dialect_objc ())
1526 parser->objc_need_raw_identifier = true;
1527 t.kind = ctsk_resword;
1528 t.spec = c_parser_peek_token (parser)->value;
1529 declspecs_add_type (specs, t);
1530 c_parser_consume_token (parser);
1537 t = c_parser_enum_specifier (parser);
1538 declspecs_add_type (specs, t);
1546 t = c_parser_struct_or_union_specifier (parser);
1547 declspecs_add_type (specs, t);
1550 /* ??? The old parser rejected typeof after other type
1551 specifiers, but is a syntax error the best way of
1553 if (!typespec_ok || seen_type)
1557 t = c_parser_typeof_specifier (parser);
1558 declspecs_add_type (specs, t);
1564 declspecs_add_qual (specs, c_parser_peek_token (parser)->value);
1565 c_parser_consume_token (parser);
1570 attrs = c_parser_attributes (parser);
1571 declspecs_add_attrs (specs, attrs);
1580 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
1583 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
1584 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
1585 enum attributes[opt] identifier
1587 The form with trailing comma is new in C99. The forms with
1588 attributes are GNU extensions. In GNU C, we accept any expression
1589 without commas in the syntax (assignment expressions, not just
1590 conditional expressions); assignment expressions will be diagnosed
1595 enumerator-list , enumerator
1598 enumeration-constant
1599 enumeration-constant = constant-expression
1602 static struct c_typespec
1603 c_parser_enum_specifier (c_parser *parser)
1605 struct c_typespec ret;
1607 tree ident = NULL_TREE;
1608 location_t ident_loc;
1609 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ENUM));
1610 c_parser_consume_token (parser);
1611 attrs = c_parser_attributes (parser);
1612 /* Set the location in case we create a decl now. */
1613 c_parser_set_source_position_from_token (c_parser_peek_token (parser));
1614 if (c_parser_next_token_is (parser, CPP_NAME))
1616 ident = c_parser_peek_token (parser)->value;
1617 ident_loc = c_parser_peek_token (parser)->location;
1618 c_parser_consume_token (parser);
1620 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
1622 /* Parse an enum definition. */
1623 struct c_enum_contents the_enum;
1624 tree type = start_enum (&the_enum, ident);
1626 /* We chain the enumerators in reverse order, then put them in
1627 forward order at the end. */
1628 tree values = NULL_TREE;
1629 c_parser_consume_token (parser);
1637 location_t comma_loc;
1638 location_t value_loc;
1639 if (c_parser_next_token_is_not (parser, CPP_NAME))
1641 c_parser_error (parser, "expected identifier");
1642 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
1643 values = error_mark_node;
1646 token = c_parser_peek_token (parser);
1647 enum_id = token->value;
1648 /* Set the location in case we create a decl now. */
1649 c_parser_set_source_position_from_token (token);
1650 value_loc = token->location;
1651 c_parser_consume_token (parser);
1652 if (c_parser_next_token_is (parser, CPP_EQ))
1654 c_parser_consume_token (parser);
1655 value_loc = c_parser_peek_token (parser)->location;
1656 /* This may call cb_line_change and alter the input_location. */
1657 enum_value = c_parser_expr_no_commas (parser, NULL).value;
1660 enum_value = NULL_TREE;
1661 enum_decl = build_enumerator (&the_enum, enum_id, enum_value,
1663 TREE_CHAIN (enum_decl) = values;
1666 if (c_parser_next_token_is (parser, CPP_COMMA))
1668 comma_loc = c_parser_peek_token (parser)->location;
1670 c_parser_consume_token (parser);
1672 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
1674 if (seen_comma && !flag_isoc99)
1675 pedwarn (comma_loc, OPT_pedantic, "comma at end of enumerator list");
1676 c_parser_consume_token (parser);
1681 c_parser_error (parser, "expected %<,%> or %<}%>");
1682 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
1683 values = error_mark_node;
1687 postfix_attrs = c_parser_attributes (parser);
1688 ret.spec = finish_enum (type, nreverse (values),
1689 chainon (attrs, postfix_attrs));
1690 ret.kind = ctsk_tagdef;
1695 c_parser_error (parser, "expected %<{%>");
1696 ret.spec = error_mark_node;
1697 ret.kind = ctsk_tagref;
1700 ret = parser_xref_tag (ENUMERAL_TYPE, ident);
1701 /* In ISO C, enumerated types can be referred to only if already
1703 if (pedantic && !COMPLETE_TYPE_P (ret.spec))
1706 pedwarn (ident_loc, OPT_pedantic,
1707 "ISO C forbids forward references to %<enum%> types");
1712 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
1714 struct-or-union-specifier:
1715 struct-or-union attributes[opt] identifier[opt]
1716 { struct-contents } attributes[opt]
1717 struct-or-union attributes[opt] identifier
1720 struct-declaration-list
1722 struct-declaration-list:
1723 struct-declaration ;
1724 struct-declaration-list struct-declaration ;
1731 struct-declaration-list struct-declaration
1733 struct-declaration-list:
1734 struct-declaration-list ;
1737 (Note that in the syntax here, unlike that in ISO C, the semicolons
1738 are included here rather than in struct-declaration, in order to
1739 describe the syntax with extra semicolons and missing semicolon at
1744 struct-declaration-list:
1745 @defs ( class-name )
1747 (Note this does not include a trailing semicolon, but can be
1748 followed by further declarations, and gets a pedwarn-if-pedantic
1749 when followed by a semicolon.) */
1751 static struct c_typespec
1752 c_parser_struct_or_union_specifier (c_parser *parser)
1754 struct c_typespec ret;
1756 tree ident = NULL_TREE;
1757 enum tree_code code;
1758 switch (c_parser_peek_token (parser)->keyword)
1769 c_parser_consume_token (parser);
1770 attrs = c_parser_attributes (parser);
1771 /* Set the location in case we create a decl now. */
1772 c_parser_set_source_position_from_token (c_parser_peek_token (parser));
1773 if (c_parser_next_token_is (parser, CPP_NAME))
1775 ident = c_parser_peek_token (parser)->value;
1776 c_parser_consume_token (parser);
1778 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
1780 /* Parse a struct or union definition. Start the scope of the
1781 tag before parsing components. */
1782 tree type = start_struct (code, ident);
1784 /* We chain the components in reverse order, then put them in
1785 forward order at the end. Each struct-declaration may
1786 declare multiple components (comma-separated), so we must use
1787 chainon to join them, although when parsing each
1788 struct-declaration we can use TREE_CHAIN directly.
1790 The theory behind all this is that there will be more
1791 semicolon separated fields than comma separated fields, and
1792 so we'll be minimizing the number of node traversals required
1794 tree contents = NULL_TREE;
1795 c_parser_consume_token (parser);
1796 /* Handle the Objective-C @defs construct,
1797 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
1798 if (c_parser_next_token_is_keyword (parser, RID_AT_DEFS))
1801 gcc_assert (c_dialect_objc ());
1802 c_parser_consume_token (parser);
1803 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
1805 if (c_parser_next_token_is (parser, CPP_NAME)
1806 && c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME)
1808 name = c_parser_peek_token (parser)->value;
1809 c_parser_consume_token (parser);
1813 c_parser_error (parser, "expected class name");
1814 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
1817 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
1819 contents = nreverse (objc_get_class_ivars (name));
1822 /* Parse the struct-declarations and semicolons. Problems with
1823 semicolons are diagnosed here; empty structures are diagnosed
1828 /* Parse any stray semicolon. */
1829 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1831 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
1832 "extra semicolon in struct or union specified");
1833 c_parser_consume_token (parser);
1836 /* Stop if at the end of the struct or union contents. */
1837 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
1839 c_parser_consume_token (parser);
1842 /* Accept #pragmas at struct scope. */
1843 if (c_parser_next_token_is (parser, CPP_PRAGMA))
1845 c_parser_pragma (parser, pragma_external);
1848 /* Parse some comma-separated declarations, but not the
1849 trailing semicolon if any. */
1850 decls = c_parser_struct_declaration (parser);
1851 contents = chainon (decls, contents);
1852 /* If no semicolon follows, either we have a parse error or
1853 are at the end of the struct or union and should
1855 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1856 c_parser_consume_token (parser);
1859 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
1860 pedwarn (c_parser_peek_token (parser)->location, 0,
1861 "no semicolon at end of struct or union");
1864 c_parser_error (parser, "expected %<;%>");
1865 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
1870 postfix_attrs = c_parser_attributes (parser);
1871 ret.spec = finish_struct (type, nreverse (contents),
1872 chainon (attrs, postfix_attrs));
1873 ret.kind = ctsk_tagdef;
1878 c_parser_error (parser, "expected %<{%>");
1879 ret.spec = error_mark_node;
1880 ret.kind = ctsk_tagref;
1883 ret = parser_xref_tag (code, ident);
1887 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
1888 the trailing semicolon.
1891 specifier-qualifier-list struct-declarator-list
1893 specifier-qualifier-list:
1894 type-specifier specifier-qualifier-list[opt]
1895 type-qualifier specifier-qualifier-list[opt]
1896 attributes specifier-qualifier-list[opt]
1898 struct-declarator-list:
1900 struct-declarator-list , attributes[opt] struct-declarator
1903 declarator attributes[opt]
1904 declarator[opt] : constant-expression attributes[opt]
1909 __extension__ struct-declaration
1910 specifier-qualifier-list
1912 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
1913 of attributes where shown is a GNU extension. In GNU C, we accept
1914 any expression without commas in the syntax (assignment
1915 expressions, not just conditional expressions); assignment
1916 expressions will be diagnosed as non-constant. */
1919 c_parser_struct_declaration (c_parser *parser)
1921 struct c_declspecs *specs;
1923 tree all_prefix_attrs;
1925 location_t decl_loc;
1926 if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
1930 ext = disable_extension_diagnostics ();
1931 c_parser_consume_token (parser);
1932 decl = c_parser_struct_declaration (parser);
1933 restore_extension_diagnostics (ext);
1936 specs = build_null_declspecs ();
1937 decl_loc = c_parser_peek_token (parser)->location;
1938 c_parser_declspecs (parser, specs, false, true, true);
1941 if (!specs->declspecs_seen_p)
1943 c_parser_error (parser, "expected specifier-qualifier-list");
1946 finish_declspecs (specs);
1947 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1950 if (!specs->type_seen_p)
1952 pedwarn (decl_loc, OPT_pedantic,
1953 "ISO C forbids member declarations with no members");
1954 shadow_tag_warned (specs, pedantic);
1959 /* Support for unnamed structs or unions as members of
1960 structs or unions (which is [a] useful and [b] supports
1963 ret = grokfield (build_id_declarator (NULL_TREE), specs,
1966 decl_attributes (&ret, attrs, 0);
1970 pending_xref_error ();
1971 prefix_attrs = specs->attrs;
1972 all_prefix_attrs = prefix_attrs;
1973 specs->attrs = NULL_TREE;
1977 /* Declaring one or more declarators or un-named bit-fields. */
1978 struct c_declarator *declarator;
1980 if (c_parser_next_token_is (parser, CPP_COLON))
1981 declarator = build_id_declarator (NULL_TREE);
1983 declarator = c_parser_declarator (parser, specs->type_seen_p,
1984 C_DTR_NORMAL, &dummy);
1985 if (declarator == NULL)
1987 c_parser_skip_to_end_of_block_or_statement (parser);
1990 if (c_parser_next_token_is (parser, CPP_COLON)
1991 || c_parser_next_token_is (parser, CPP_COMMA)
1992 || c_parser_next_token_is (parser, CPP_SEMICOLON)
1993 || c_parser_next_token_is (parser, CPP_CLOSE_BRACE)
1994 || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1996 tree postfix_attrs = NULL_TREE;
1997 tree width = NULL_TREE;
1999 if (c_parser_next_token_is (parser, CPP_COLON))
2001 c_parser_consume_token (parser);
2002 width = c_parser_expr_no_commas (parser, NULL).value;
2004 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2005 postfix_attrs = c_parser_attributes (parser);
2006 d = grokfield (declarator, specs, width, &all_prefix_attrs);
2007 decl_attributes (&d, chainon (postfix_attrs,
2008 all_prefix_attrs), 0);
2009 TREE_CHAIN (d) = decls;
2011 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2012 all_prefix_attrs = chainon (c_parser_attributes (parser),
2015 all_prefix_attrs = prefix_attrs;
2016 if (c_parser_next_token_is (parser, CPP_COMMA))
2017 c_parser_consume_token (parser);
2018 else if (c_parser_next_token_is (parser, CPP_SEMICOLON)
2019 || c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2021 /* Semicolon consumed in caller. */
2026 c_parser_error (parser, "expected %<,%>, %<;%> or %<}%>");
2032 c_parser_error (parser,
2033 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
2034 "%<__attribute__%>");
2041 /* Parse a typeof specifier (a GNU extension).
2044 typeof ( expression )
2045 typeof ( type-name )
2048 static struct c_typespec
2049 c_parser_typeof_specifier (c_parser *parser)
2051 struct c_typespec ret;
2052 ret.kind = ctsk_typeof;
2053 ret.spec = error_mark_node;
2054 gcc_assert (c_parser_next_token_is_keyword (parser, RID_TYPEOF));
2055 c_parser_consume_token (parser);
2058 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2064 if (c_parser_next_token_starts_typename (parser))
2066 struct c_type_name *type = c_parser_type_name (parser);
2071 ret.spec = groktypename (type);
2072 pop_maybe_used (variably_modified_type_p (ret.spec, NULL_TREE));
2078 location_t here = c_parser_peek_token (parser)->location;
2079 struct c_expr expr = c_parser_expression (parser);
2082 if (TREE_CODE (expr.value) == COMPONENT_REF
2083 && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
2084 error ("%H%<typeof%> applied to a bit-field", &here);
2085 ret.spec = TREE_TYPE (expr.value);
2086 was_vm = variably_modified_type_p (ret.spec, NULL_TREE);
2087 /* This should be returned with the type so that when the type
2088 is evaluated, this can be evaluated. For now, we avoid
2089 evaluation when the context might. */
2090 if (!skip_evaluation && was_vm)
2092 tree e = expr.value;
2094 /* If the expression is not of a type to which we cannot assign a line
2095 number, wrap the thing in a no-op NOP_EXPR. */
2096 if (DECL_P (e) || CONSTANT_CLASS_P (e))
2097 e = build1 (NOP_EXPR, void_type_node, e);
2099 if (CAN_HAVE_LOCATION_P (e))
2100 SET_EXPR_LOCATION (e, input_location);
2104 pop_maybe_used (was_vm);
2106 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
2110 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
2111 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
2112 be redeclared; otherwise it may not. KIND indicates which kind of
2113 declarator is wanted. Returns a valid declarator except in the
2114 case of a syntax error in which case NULL is returned. *SEEN_ID is
2115 set to true if an identifier being declared is seen; this is used
2116 to diagnose bad forms of abstract array declarators and to
2117 determine whether an identifier list is syntactically permitted.
2120 pointer[opt] direct-declarator
2124 ( attributes[opt] declarator )
2125 direct-declarator array-declarator
2126 direct-declarator ( parameter-type-list )
2127 direct-declarator ( identifier-list[opt] )
2130 * type-qualifier-list[opt]
2131 * type-qualifier-list[opt] pointer
2133 type-qualifier-list:
2136 type-qualifier-list type-qualifier
2137 type-qualifier-list attributes
2139 parameter-type-list:
2141 parameter-list , ...
2144 parameter-declaration
2145 parameter-list , parameter-declaration
2147 parameter-declaration:
2148 declaration-specifiers declarator attributes[opt]
2149 declaration-specifiers abstract-declarator[opt] attributes[opt]
2153 identifier-list , identifier
2155 abstract-declarator:
2157 pointer[opt] direct-abstract-declarator
2159 direct-abstract-declarator:
2160 ( attributes[opt] abstract-declarator )
2161 direct-abstract-declarator[opt] array-declarator
2162 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
2167 direct-declarator ( parameter-forward-declarations
2168 parameter-type-list[opt] )
2170 direct-abstract-declarator:
2171 direct-abstract-declarator[opt] ( parameter-forward-declarations
2172 parameter-type-list[opt] )
2174 parameter-forward-declarations:
2176 parameter-forward-declarations parameter-list ;
2178 The uses of attributes shown above are GNU extensions.
2180 Some forms of array declarator are not included in C99 in the
2181 syntax for abstract declarators; these are disallowed elsewhere.
2182 This may be a defect (DR#289).
2184 This function also accepts an omitted abstract declarator as being
2185 an abstract declarator, although not part of the formal syntax. */
2187 static struct c_declarator *
2188 c_parser_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
2191 /* Parse any initial pointer part. */
2192 if (c_parser_next_token_is (parser, CPP_MULT))
2194 struct c_declspecs *quals_attrs = build_null_declspecs ();
2195 struct c_declarator *inner;
2196 c_parser_consume_token (parser);
2197 c_parser_declspecs (parser, quals_attrs, false, false, true);
2198 inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
2202 return make_pointer_declarator (quals_attrs, inner);
2204 /* Now we have a direct declarator, direct abstract declarator or
2205 nothing (which counts as a direct abstract declarator here). */
2206 return c_parser_direct_declarator (parser, type_seen_p, kind, seen_id);
2209 /* Parse a direct declarator or direct abstract declarator; arguments
2210 as c_parser_declarator. */
2212 static struct c_declarator *
2213 c_parser_direct_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
2216 /* The direct declarator must start with an identifier (possibly
2217 omitted) or a parenthesized declarator (possibly abstract). In
2218 an ordinary declarator, initial parentheses must start a
2219 parenthesized declarator. In an abstract declarator or parameter
2220 declarator, they could start a parenthesized declarator or a
2221 parameter list. To tell which, the open parenthesis and any
2222 following attributes must be read. If a declaration specifier
2223 follows, then it is a parameter list; if the specifier is a
2224 typedef name, there might be an ambiguity about redeclaring it,
2225 which is resolved in the direction of treating it as a typedef
2226 name. If a close parenthesis follows, it is also an empty
2227 parameter list, as the syntax does not permit empty abstract
2228 declarators. Otherwise, it is a parenthesized declarator (in
2229 which case the analysis may be repeated inside it, recursively).
2231 ??? There is an ambiguity in a parameter declaration "int
2232 (__attribute__((foo)) x)", where x is not a typedef name: it
2233 could be an abstract declarator for a function, or declare x with
2234 parentheses. The proper resolution of this ambiguity needs
2235 documenting. At present we follow an accident of the old
2236 parser's implementation, whereby the first parameter must have
2237 some declaration specifiers other than just attributes. Thus as
2238 a parameter declaration it is treated as a parenthesized
2239 parameter named x, and as an abstract declarator it is
2242 ??? Also following the old parser, attributes inside an empty
2243 parameter list are ignored, making it a list not yielding a
2244 prototype, rather than giving an error or making it have one
2245 parameter with implicit type int.
2247 ??? Also following the old parser, typedef names may be
2248 redeclared in declarators, but not Objective-C class names. */
2250 if (kind != C_DTR_ABSTRACT
2251 && c_parser_next_token_is (parser, CPP_NAME)
2253 && c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME)
2254 || c_parser_peek_token (parser)->id_kind == C_ID_ID))
2256 struct c_declarator *inner
2257 = build_id_declarator (c_parser_peek_token (parser)->value);
2259 inner->id_loc = c_parser_peek_token (parser)->location;
2260 c_parser_consume_token (parser);
2261 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2264 if (kind != C_DTR_NORMAL
2265 && c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
2267 struct c_declarator *inner = build_id_declarator (NULL_TREE);
2268 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2271 /* Either we are at the end of an abstract declarator, or we have
2274 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
2277 struct c_declarator *inner;
2278 c_parser_consume_token (parser);
2279 attrs = c_parser_attributes (parser);
2280 if (kind != C_DTR_NORMAL
2281 && (c_parser_next_token_starts_declspecs (parser)
2282 || c_parser_next_token_is (parser, CPP_CLOSE_PAREN)))
2284 struct c_arg_info *args
2285 = c_parser_parms_declarator (parser, kind == C_DTR_NORMAL,
2292 = build_function_declarator (args,
2293 build_id_declarator (NULL_TREE));
2294 return c_parser_direct_declarator_inner (parser, *seen_id,
2298 /* A parenthesized declarator. */
2299 inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
2300 if (inner != NULL && attrs != NULL)
2301 inner = build_attrs_declarator (attrs, inner);
2302 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2304 c_parser_consume_token (parser);
2308 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2312 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2319 if (kind == C_DTR_NORMAL)
2321 c_parser_error (parser, "expected identifier or %<(%>");
2325 return build_id_declarator (NULL_TREE);
2329 /* Parse part of a direct declarator or direct abstract declarator,
2330 given that some (in INNER) has already been parsed; ID_PRESENT is
2331 true if an identifier is present, false for an abstract
2334 static struct c_declarator *
2335 c_parser_direct_declarator_inner (c_parser *parser, bool id_present,
2336 struct c_declarator *inner)
2338 /* Parse a sequence of array declarators and parameter lists. */
2339 if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
2341 struct c_declarator *declarator;
2342 struct c_declspecs *quals_attrs = build_null_declspecs ();
2346 c_parser_consume_token (parser);
2347 c_parser_declspecs (parser, quals_attrs, false, false, true);
2348 static_seen = c_parser_next_token_is_keyword (parser, RID_STATIC);
2350 c_parser_consume_token (parser);
2351 if (static_seen && !quals_attrs->declspecs_seen_p)
2352 c_parser_declspecs (parser, quals_attrs, false, false, true);
2353 if (!quals_attrs->declspecs_seen_p)
2355 /* If "static" is present, there must be an array dimension.
2356 Otherwise, there may be a dimension, "*", or no
2361 dimen = c_parser_expr_no_commas (parser, NULL).value;
2365 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
2370 else if (c_parser_next_token_is (parser, CPP_MULT))
2372 if (c_parser_peek_2nd_token (parser)->type == CPP_CLOSE_SQUARE)
2376 c_parser_consume_token (parser);
2381 dimen = c_parser_expr_no_commas (parser, NULL).value;
2387 dimen = c_parser_expr_no_commas (parser, NULL).value;
2390 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
2391 c_parser_consume_token (parser);
2394 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
2398 declarator = build_array_declarator (dimen, quals_attrs, static_seen,
2400 if (declarator == NULL)
2402 inner = set_array_declarator_inner (declarator, inner);
2403 return c_parser_direct_declarator_inner (parser, id_present, inner);
2405 else if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
2408 struct c_arg_info *args;
2409 c_parser_consume_token (parser);
2410 attrs = c_parser_attributes (parser);
2411 args = c_parser_parms_declarator (parser, id_present, attrs);
2416 inner = build_function_declarator (args, inner);
2417 return c_parser_direct_declarator_inner (parser, id_present, inner);
2423 /* Parse a parameter list or identifier list, including the closing
2424 parenthesis but not the opening one. ATTRS are the attributes at
2425 the start of the list. ID_LIST_OK is true if an identifier list is
2426 acceptable; such a list must not have attributes at the start. */
2428 static struct c_arg_info *
2429 c_parser_parms_declarator (c_parser *parser, bool id_list_ok, tree attrs)
2432 declare_parm_level ();
2433 /* If the list starts with an identifier, it is an identifier list.
2434 Otherwise, it is either a prototype list or an empty list. */
2437 && c_parser_next_token_is (parser, CPP_NAME)
2438 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
2440 tree list = NULL_TREE, *nextp = &list;
2441 while (c_parser_next_token_is (parser, CPP_NAME)
2442 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
2444 *nextp = build_tree_list (NULL_TREE,
2445 c_parser_peek_token (parser)->value);
2446 nextp = & TREE_CHAIN (*nextp);
2447 c_parser_consume_token (parser);
2448 if (c_parser_next_token_is_not (parser, CPP_COMMA))
2450 c_parser_consume_token (parser);
2451 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2453 c_parser_error (parser, "expected identifier");
2457 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2459 struct c_arg_info *ret = XOBNEW (&parser_obstack, struct c_arg_info);
2464 ret->pending_sizes = 0;
2465 ret->had_vla_unspec = 0;
2466 c_parser_consume_token (parser);
2472 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2480 struct c_arg_info *ret = c_parser_parms_list_declarator (parser, attrs);
2486 /* Parse a parameter list (possibly empty), including the closing
2487 parenthesis but not the opening one. ATTRS are the attributes at
2488 the start of the list. */
2490 static struct c_arg_info *
2491 c_parser_parms_list_declarator (c_parser *parser, tree attrs)
2493 bool good_parm = false;
2494 /* ??? Following the old parser, forward parameter declarations may
2495 use abstract declarators, and if no real parameter declarations
2496 follow the forward declarations then this is not diagnosed. Also
2497 note as above that attributes are ignored as the only contents of
2498 the parentheses, or as the only contents after forward
2500 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2502 struct c_arg_info *ret = XOBNEW (&parser_obstack, struct c_arg_info);
2507 ret->pending_sizes = 0;
2508 ret->had_vla_unspec = 0;
2509 c_parser_consume_token (parser);
2512 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
2514 struct c_arg_info *ret = XOBNEW (&parser_obstack, struct c_arg_info);
2518 ret->pending_sizes = 0;
2519 ret->had_vla_unspec = 0;
2520 /* Suppress -Wold-style-definition for this case. */
2521 ret->types = error_mark_node;
2522 error ("%HISO C requires a named argument before %<...%>",
2523 &c_parser_peek_token (parser)->location);
2524 c_parser_consume_token (parser);
2525 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2527 c_parser_consume_token (parser);
2532 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2537 /* Nonempty list of parameters, either terminated with semicolon
2538 (forward declarations; recurse) or with close parenthesis (normal
2539 function) or with ", ... )" (variadic function). */
2542 /* Parse a parameter. */
2543 struct c_parm *parm = c_parser_parameter_declaration (parser, attrs);
2548 push_parm_decl (parm);
2550 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
2553 c_parser_consume_token (parser);
2554 mark_forward_parm_decls ();
2555 new_attrs = c_parser_attributes (parser);
2556 return c_parser_parms_list_declarator (parser, new_attrs);
2558 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2560 c_parser_consume_token (parser);
2562 return get_parm_info (false);
2565 struct c_arg_info *ret
2566 = XOBNEW (&parser_obstack, struct c_arg_info);
2571 ret->pending_sizes = 0;
2572 ret->had_vla_unspec = 0;
2576 if (!c_parser_require (parser, CPP_COMMA,
2577 "expected %<;%>, %<,%> or %<)%>"))
2579 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
2582 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
2584 c_parser_consume_token (parser);
2585 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2587 c_parser_consume_token (parser);
2589 return get_parm_info (true);
2592 struct c_arg_info *ret
2593 = XOBNEW (&parser_obstack, struct c_arg_info);
2598 ret->pending_sizes = 0;
2599 ret->had_vla_unspec = 0;
2605 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2613 /* Parse a parameter declaration. ATTRS are the attributes at the
2614 start of the declaration if it is the first parameter. */
2616 static struct c_parm *
2617 c_parser_parameter_declaration (c_parser *parser, tree attrs)
2619 struct c_declspecs *specs;
2620 struct c_declarator *declarator;
2622 tree postfix_attrs = NULL_TREE;
2624 if (!c_parser_next_token_starts_declspecs (parser))
2626 /* ??? In some Objective-C cases '...' isn't applicable so there
2627 should be a different message. */
2628 c_parser_error (parser,
2629 "expected declaration specifiers or %<...%>");
2630 c_parser_skip_to_end_of_parameter (parser);
2633 specs = build_null_declspecs ();
2636 declspecs_add_attrs (specs, attrs);
2639 c_parser_declspecs (parser, specs, true, true, true);
2640 finish_declspecs (specs);
2641 pending_xref_error ();
2642 prefix_attrs = specs->attrs;
2643 specs->attrs = NULL_TREE;
2644 declarator = c_parser_declarator (parser, specs->type_seen_p,
2645 C_DTR_PARM, &dummy);
2646 if (declarator == NULL)
2648 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
2651 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2652 postfix_attrs = c_parser_attributes (parser);
2653 return build_c_parm (specs, chainon (postfix_attrs, prefix_attrs),
2657 /* Parse a string literal in an asm expression. It should not be
2658 translated, and wide string literals are an error although
2659 permitted by the syntax. This is a GNU extension.
2664 ??? At present, following the old parser, the caller needs to have
2665 set lex_untranslated_string to 1. It would be better to follow the
2666 C++ parser rather than using this kludge. */
2669 c_parser_asm_string_literal (c_parser *parser)
2672 if (c_parser_next_token_is (parser, CPP_STRING))
2674 str = c_parser_peek_token (parser)->value;
2675 c_parser_consume_token (parser);
2677 else if (c_parser_next_token_is (parser, CPP_WSTRING))
2679 error ("%Hwide string literal in %<asm%>",
2680 &c_parser_peek_token (parser)->location);
2681 str = build_string (1, "");
2682 c_parser_consume_token (parser);
2686 c_parser_error (parser, "expected string literal");
2692 /* Parse a simple asm expression. This is used in restricted
2693 contexts, where a full expression with inputs and outputs does not
2694 make sense. This is a GNU extension.
2697 asm ( asm-string-literal )
2701 c_parser_simple_asm_expr (c_parser *parser)
2704 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
2705 /* ??? Follow the C++ parser rather than using the
2706 lex_untranslated_string kludge. */
2707 parser->lex_untranslated_string = true;
2708 c_parser_consume_token (parser);
2709 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2711 parser->lex_untranslated_string = false;
2714 str = c_parser_asm_string_literal (parser);
2715 parser->lex_untranslated_string = false;
2716 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
2718 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
2724 /* Parse (possibly empty) attributes. This is a GNU extension.
2728 attributes attribute
2731 __attribute__ ( ( attribute-list ) )
2735 attribute_list , attrib
2740 any-word ( identifier )
2741 any-word ( identifier , nonempty-expr-list )
2742 any-word ( expr-list )
2744 where the "identifier" must not be declared as a type, and
2745 "any-word" may be any identifier (including one declared as a
2746 type), a reserved word storage class specifier, type specifier or
2747 type qualifier. ??? This still leaves out most reserved keywords
2748 (following the old parser), shouldn't we include them, and why not
2749 allow identifiers declared as types to start the arguments? */
2752 c_parser_attributes (c_parser *parser)
2754 tree attrs = NULL_TREE;
2755 while (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2757 /* ??? Follow the C++ parser rather than using the
2758 lex_untranslated_string kludge. */
2759 parser->lex_untranslated_string = true;
2760 c_parser_consume_token (parser);
2761 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2763 parser->lex_untranslated_string = false;
2766 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2768 parser->lex_untranslated_string = false;
2769 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
2772 /* Parse the attribute list. */
2773 while (c_parser_next_token_is (parser, CPP_COMMA)
2774 || c_parser_next_token_is (parser, CPP_NAME)
2775 || c_parser_next_token_is (parser, CPP_KEYWORD))
2777 tree attr, attr_name, attr_args;
2778 if (c_parser_next_token_is (parser, CPP_COMMA))
2780 c_parser_consume_token (parser);
2783 if (c_parser_next_token_is (parser, CPP_KEYWORD))
2785 /* ??? See comment above about what keywords are
2788 switch (c_parser_peek_token (parser)->keyword)
2825 /* Accept __attribute__((__const)) as __attribute__((const))
2828 = ridpointers[(int) c_parser_peek_token (parser)->keyword];
2831 attr_name = c_parser_peek_token (parser)->value;
2832 c_parser_consume_token (parser);
2833 if (c_parser_next_token_is_not (parser, CPP_OPEN_PAREN))
2835 attr = build_tree_list (attr_name, NULL_TREE);
2836 attrs = chainon (attrs, attr);
2839 c_parser_consume_token (parser);
2840 /* Parse the attribute contents. If they start with an
2841 identifier which is followed by a comma or close
2842 parenthesis, then the arguments start with that
2843 identifier; otherwise they are an expression list. */
2844 if (c_parser_next_token_is (parser, CPP_NAME)
2845 && c_parser_peek_token (parser)->id_kind == C_ID_ID
2846 && ((c_parser_peek_2nd_token (parser)->type == CPP_COMMA)
2847 || (c_parser_peek_2nd_token (parser)->type
2848 == CPP_CLOSE_PAREN)))
2850 tree arg1 = c_parser_peek_token (parser)->value;
2851 c_parser_consume_token (parser);
2852 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2853 attr_args = build_tree_list (NULL_TREE, arg1);
2856 c_parser_consume_token (parser);
2857 attr_args = tree_cons (NULL_TREE, arg1,
2858 c_parser_expr_list (parser, false));
2863 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2864 attr_args = NULL_TREE;
2866 attr_args = c_parser_expr_list (parser, false);
2868 attr = build_tree_list (attr_name, attr_args);
2869 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2870 c_parser_consume_token (parser);
2873 parser->lex_untranslated_string = false;
2874 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2878 attrs = chainon (attrs, attr);
2880 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2881 c_parser_consume_token (parser);
2884 parser->lex_untranslated_string = false;
2885 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2889 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2890 c_parser_consume_token (parser);
2893 parser->lex_untranslated_string = false;
2894 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2898 parser->lex_untranslated_string = false;
2903 /* Parse a type name (C90 6.5.5, C99 6.7.6).
2906 specifier-qualifier-list abstract-declarator[opt]
2909 static struct c_type_name *
2910 c_parser_type_name (c_parser *parser)
2912 struct c_declspecs *specs = build_null_declspecs ();
2913 struct c_declarator *declarator;
2914 struct c_type_name *ret;
2916 c_parser_declspecs (parser, specs, false, true, true);
2917 if (!specs->declspecs_seen_p)
2919 c_parser_error (parser, "expected specifier-qualifier-list");
2922 pending_xref_error ();
2923 finish_declspecs (specs);
2924 declarator = c_parser_declarator (parser, specs->type_seen_p,
2925 C_DTR_ABSTRACT, &dummy);
2926 if (declarator == NULL)
2928 ret = XOBNEW (&parser_obstack, struct c_type_name);
2930 ret->declarator = declarator;
2934 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
2937 assignment-expression
2938 { initializer-list }
2939 { initializer-list , }
2942 designation[opt] initializer
2943 initializer-list , designation[opt] initializer
2950 designator-list designator
2957 [ constant-expression ]
2969 [ constant-expression ... constant-expression ]
2971 Any expression without commas is accepted in the syntax for the
2972 constant-expressions, with non-constant expressions rejected later.
2974 This function is only used for top-level initializers; for nested
2975 ones, see c_parser_initval. */
2977 static struct c_expr
2978 c_parser_initializer (c_parser *parser)
2980 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
2981 return c_parser_braced_init (parser, NULL_TREE, false);
2985 ret = c_parser_expr_no_commas (parser, NULL);
2986 if (TREE_CODE (ret.value) != STRING_CST
2987 && TREE_CODE (ret.value) != COMPOUND_LITERAL_EXPR)
2988 ret = default_function_array_conversion (ret);
2993 /* Parse a braced initializer list. TYPE is the type specified for a
2994 compound literal, and NULL_TREE for other initializers and for
2995 nested braced lists. NESTED_P is true for nested braced lists,
2996 false for the list of a compound literal or the list that is the
2997 top-level initializer in a declaration. */
2999 static struct c_expr
3000 c_parser_braced_init (c_parser *parser, tree type, bool nested_p)
3002 location_t brace_loc = c_parser_peek_token (parser)->location;
3003 gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE));
3004 c_parser_consume_token (parser);
3006 push_init_level (0);
3008 really_start_incremental_init (type);
3009 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3011 pedwarn (brace_loc, OPT_pedantic, "ISO C forbids empty initializer braces");
3015 /* Parse a non-empty initializer list, possibly with a trailing
3019 c_parser_initelt (parser);
3022 if (c_parser_next_token_is (parser, CPP_COMMA))
3023 c_parser_consume_token (parser);
3026 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3030 if (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE))
3033 ret.value = error_mark_node;
3034 ret.original_code = ERROR_MARK;
3035 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, "expected %<}%>");
3038 c_parser_consume_token (parser);
3039 return pop_init_level (0);
3042 /* Parse a nested initializer, including designators. */
3045 c_parser_initelt (c_parser *parser)
3047 /* Parse any designator or designator list. A single array
3048 designator may have the subsequent "=" omitted in GNU C, but a
3049 longer list or a structure member designator may not. */
3050 if (c_parser_next_token_is (parser, CPP_NAME)
3051 && c_parser_peek_2nd_token (parser)->type == CPP_COLON)
3053 /* Old-style structure member designator. */
3054 set_init_label (c_parser_peek_token (parser)->value);
3055 /* Use the colon as the error location. */
3056 pedwarn (c_parser_peek_2nd_token (parser)->location, OPT_pedantic,
3057 "obsolete use of designated initializer with %<:%>");
3058 c_parser_consume_token (parser);
3059 c_parser_consume_token (parser);
3063 /* des_seen is 0 if there have been no designators, 1 if there
3064 has been a single array designator and 2 otherwise. */
3066 /* Location of a designator. */
3068 while (c_parser_next_token_is (parser, CPP_OPEN_SQUARE)
3069 || c_parser_next_token_is (parser, CPP_DOT))
3071 int des_prev = des_seen;
3073 des_loc = c_parser_peek_token (parser)->location;
3076 if (c_parser_next_token_is (parser, CPP_DOT))
3079 c_parser_consume_token (parser);
3080 if (c_parser_next_token_is (parser, CPP_NAME))
3082 set_init_label (c_parser_peek_token (parser)->value);
3083 c_parser_consume_token (parser);
3088 init.value = error_mark_node;
3089 init.original_code = ERROR_MARK;
3090 c_parser_error (parser, "expected identifier");
3091 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
3092 process_init_element (init);
3099 location_t ellipsis_loc;
3100 /* ??? Following the old parser, [ objc-receiver
3101 objc-message-args ] is accepted as an initializer,
3102 being distinguished from a designator by what follows
3103 the first assignment expression inside the square
3104 brackets, but after a first array designator a
3105 subsequent square bracket is for Objective-C taken to
3106 start an expression, using the obsolete form of
3107 designated initializer without '=', rather than
3108 possibly being a second level of designation: in LALR
3109 terms, the '[' is shifted rather than reducing
3110 designator to designator-list. */
3111 if (des_prev == 1 && c_dialect_objc ())
3113 des_seen = des_prev;
3116 if (des_prev == 0 && c_dialect_objc ())
3118 /* This might be an array designator or an
3119 Objective-C message expression. If the former,
3120 continue parsing here; if the latter, parse the
3121 remainder of the initializer given the starting
3122 primary-expression. ??? It might make sense to
3123 distinguish when des_prev == 1 as well; see
3124 previous comment. */
3126 struct c_expr mexpr;
3127 c_parser_consume_token (parser);
3128 if (c_parser_peek_token (parser)->type == CPP_NAME
3129 && ((c_parser_peek_token (parser)->id_kind
3131 || (c_parser_peek_token (parser)->id_kind
3132 == C_ID_CLASSNAME)))
3134 /* Type name receiver. */
3135 tree id = c_parser_peek_token (parser)->value;
3136 c_parser_consume_token (parser);
3137 rec = objc_get_class_reference (id);
3138 goto parse_message_args;
3140 first = c_parser_expr_no_commas (parser, NULL).value;
3141 if (c_parser_next_token_is (parser, CPP_ELLIPSIS)
3142 || c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3143 goto array_desig_after_first;
3144 /* Expression receiver. So far only one part
3145 without commas has been parsed; there might be
3146 more of the expression. */
3148 while (c_parser_next_token_is (parser, CPP_COMMA))
3151 c_parser_consume_token (parser);
3152 next = c_parser_expr_no_commas (parser, NULL);
3153 next = default_function_array_conversion (next);
3154 rec = build_compound_expr (rec, next.value);
3157 /* Now parse the objc-message-args. */
3158 args = c_parser_objc_message_args (parser);
3159 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
3162 = objc_build_message_expr (build_tree_list (rec, args));
3163 mexpr.original_code = ERROR_MARK;
3164 /* Now parse and process the remainder of the
3165 initializer, starting with this message
3166 expression as a primary-expression. */
3167 c_parser_initval (parser, &mexpr);
3170 c_parser_consume_token (parser);
3171 first = c_parser_expr_no_commas (parser, NULL).value;
3172 array_desig_after_first:
3173 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
3175 ellipsis_loc = c_parser_peek_token (parser)->location;
3176 c_parser_consume_token (parser);
3177 second = c_parser_expr_no_commas (parser, NULL).value;
3181 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3183 c_parser_consume_token (parser);
3184 set_init_index (first, second);
3186 pedwarn (ellipsis_loc, OPT_pedantic,
3187 "ISO C forbids specifying range of elements to initialize");
3190 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
3196 if (c_parser_next_token_is (parser, CPP_EQ))
3199 pedwarn (des_loc, OPT_pedantic,
3200 "ISO C90 forbids specifying subobject to initialize");
3201 c_parser_consume_token (parser);
3206 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
3207 "obsolete use of designated initializer without %<=%>");
3211 init.value = error_mark_node;
3212 init.original_code = ERROR_MARK;
3213 c_parser_error (parser, "expected %<=%>");
3214 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
3215 process_init_element (init);
3221 c_parser_initval (parser, NULL);
3224 /* Parse a nested initializer; as c_parser_initializer but parses
3225 initializers within braced lists, after any designators have been
3226 applied. If AFTER is not NULL then it is an Objective-C message
3227 expression which is the primary-expression starting the
3231 c_parser_initval (c_parser *parser, struct c_expr *after)
3234 gcc_assert (!after || c_dialect_objc ());
3235 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE) && !after)
3236 init = c_parser_braced_init (parser, NULL_TREE, true);
3239 init = c_parser_expr_no_commas (parser, after);
3240 if (init.value != NULL_TREE
3241 && TREE_CODE (init.value) != STRING_CST
3242 && TREE_CODE (init.value) != COMPOUND_LITERAL_EXPR)
3243 init = default_function_array_conversion (init);
3245 process_init_element (init);
3248 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
3252 { block-item-list[opt] }
3253 { label-declarations block-item-list }
3257 block-item-list block-item
3269 { label-declarations block-item-list }
3272 __extension__ nested-declaration
3273 nested-function-definition
3277 label-declarations label-declaration
3280 __label__ identifier-list ;
3282 Allowing the mixing of declarations and code is new in C99. The
3283 GNU syntax also permits (not shown above) labels at the end of
3284 compound statements, which yield an error. We don't allow labels
3285 on declarations; this might seem like a natural extension, but
3286 there would be a conflict between attributes on the label and
3287 prefix attributes on the declaration. ??? The syntax follows the
3288 old parser in requiring something after label declarations.
3289 Although they are erroneous if the labels declared aren't defined,
3290 is it useful for the syntax to be this way?
3302 c_parser_compound_statement (c_parser *parser)
3305 if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
3306 return error_mark_node;
3307 stmt = c_begin_compound_stmt (true);
3308 c_parser_compound_statement_nostart (parser);
3309 return c_end_compound_stmt (stmt, true);
3312 /* Parse a compound statement except for the opening brace. This is
3313 used for parsing both compound statements and statement expressions
3314 (which follow different paths to handling the opening). */
3317 c_parser_compound_statement_nostart (c_parser *parser)
3319 bool last_stmt = false;
3320 bool last_label = false;
3321 location_t label_loc;
3322 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3324 c_parser_consume_token (parser);
3327 if (c_parser_next_token_is_keyword (parser, RID_LABEL))
3329 location_t err_loc = c_parser_peek_token (parser)->location;
3330 /* Read zero or more forward-declarations for labels that nested
3331 functions can jump to. */
3332 while (c_parser_next_token_is_keyword (parser, RID_LABEL))
3334 c_parser_consume_token (parser);
3335 /* Any identifiers, including those declared as type names,
3340 if (c_parser_next_token_is_not (parser, CPP_NAME))
3342 c_parser_error (parser, "expected identifier");
3346 = declare_label (c_parser_peek_token (parser)->value);
3347 C_DECLARED_LABEL_FLAG (label) = 1;
3348 add_stmt (build_stmt (DECL_EXPR, label));
3349 c_parser_consume_token (parser);
3350 if (c_parser_next_token_is (parser, CPP_COMMA))
3351 c_parser_consume_token (parser);
3355 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
3357 pedwarn (err_loc, OPT_pedantic, "ISO C forbids label declarations");
3359 /* We must now have at least one statement, label or declaration. */
3360 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3362 c_parser_error (parser, "expected declaration or statement");
3363 c_parser_consume_token (parser);
3366 while (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE))
3368 location_t loc = c_parser_peek_token (parser)->location;
3369 if (c_parser_next_token_is_keyword (parser, RID_CASE)
3370 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
3371 || (c_parser_next_token_is (parser, CPP_NAME)
3372 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3374 if (c_parser_next_token_is_keyword (parser, RID_CASE))
3375 label_loc = c_parser_peek_2nd_token (parser)->location;
3377 label_loc = c_parser_peek_token (parser)->location;
3380 c_parser_label (parser);
3382 else if (!last_label
3383 && c_parser_next_token_starts_declspecs (parser))
3386 c_parser_declaration_or_fndef (parser, true, true, true, true);
3389 (pedantic && !flag_isoc99)
3391 : OPT_Wdeclaration_after_statement,
3392 "ISO C90 forbids mixed declarations and code");
3395 else if (!last_label
3396 && c_parser_next_token_is_keyword (parser, RID_EXTENSION))
3398 /* __extension__ can start a declaration, but is also an
3399 unary operator that can start an expression. Consume all
3400 but the last of a possible series of __extension__ to
3402 while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD
3403 && (c_parser_peek_2nd_token (parser)->keyword
3405 c_parser_consume_token (parser);
3406 if (c_token_starts_declspecs (c_parser_peek_2nd_token (parser)))
3409 ext = disable_extension_diagnostics ();
3410 c_parser_consume_token (parser);
3412 c_parser_declaration_or_fndef (parser, true, true, true, true);
3413 /* Following the old parser, __extension__ does not
3414 disable this diagnostic. */
3415 restore_extension_diagnostics (ext);
3417 pedwarn_c90 (loc, (pedantic && !flag_isoc99)
3419 : OPT_Wdeclaration_after_statement,
3420 "ISO C90 forbids mixed declarations and code");
3426 else if (c_parser_next_token_is (parser, CPP_PRAGMA))
3428 /* External pragmas, and some omp pragmas, are not associated
3429 with regular c code, and so are not to be considered statements
3430 syntactically. This ensures that the user doesn't put them
3431 places that would turn into syntax errors if the directive
3433 if (c_parser_pragma (parser, pragma_compound))
3434 last_label = false, last_stmt = true;
3436 else if (c_parser_next_token_is (parser, CPP_EOF))
3438 c_parser_error (parser, "expected declaration or statement");
3441 else if (c_parser_next_token_is_keyword (parser, RID_ELSE))
3443 if (parser->in_if_block)
3445 error ("%H""expected %<}%> before %<else%>", &loc);
3450 error ("%H%<else%> without a previous %<if%>", &loc);
3451 c_parser_consume_token (parser);
3460 c_parser_statement_after_labels (parser);
3463 parser->error = false;
3466 error ("%Hlabel at end of compound statement", &label_loc);
3467 c_parser_consume_token (parser);
3470 /* Parse a label (C90 6.6.1, C99 6.8.1).
3473 identifier : attributes[opt]
3474 case constant-expression :
3480 case constant-expression ... constant-expression :
3482 The use of attributes on labels is a GNU extension. The syntax in
3483 GNU C accepts any expressions without commas, non-constant
3484 expressions being rejected later. */
3487 c_parser_label (c_parser *parser)
3489 location_t loc1 = c_parser_peek_token (parser)->location;
3490 tree label = NULL_TREE;
3491 if (c_parser_next_token_is_keyword (parser, RID_CASE))
3494 c_parser_consume_token (parser);
3495 exp1 = c_parser_expr_no_commas (parser, NULL).value;
3496 if (c_parser_next_token_is (parser, CPP_COLON))
3498 c_parser_consume_token (parser);
3499 label = do_case (exp1, NULL_TREE);
3501 else if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
3503 c_parser_consume_token (parser);
3504 exp2 = c_parser_expr_no_commas (parser, NULL).value;
3505 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
3506 label = do_case (exp1, exp2);
3509 c_parser_error (parser, "expected %<:%> or %<...%>");
3511 else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT))
3513 c_parser_consume_token (parser);
3514 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
3515 label = do_case (NULL_TREE, NULL_TREE);
3519 tree name = c_parser_peek_token (parser)->value;
3522 location_t loc2 = c_parser_peek_token (parser)->location;
3523 gcc_assert (c_parser_next_token_is (parser, CPP_NAME));
3524 c_parser_consume_token (parser);
3525 gcc_assert (c_parser_next_token_is (parser, CPP_COLON));
3526 c_parser_consume_token (parser);
3527 attrs = c_parser_attributes (parser);
3528 tlab = define_label (loc2, name);
3531 decl_attributes (&tlab, attrs, 0);
3532 label = add_stmt (build_stmt (LABEL_EXPR, tlab));
3537 SET_EXPR_LOCATION (label, loc1);
3538 if (c_parser_next_token_starts_declspecs (parser)
3539 && !(c_parser_next_token_is (parser, CPP_NAME)
3540 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3542 error ("%Ha label can only be part of a statement and "
3543 "a declaration is not a statement",
3544 &c_parser_peek_token (parser)->location);
3545 c_parser_declaration_or_fndef (parser, /*fndef_ok*/ false,
3546 /*nested*/ true, /*empty_ok*/ false,
3547 /*start_attr_ok*/ true);
3552 /* Parse a statement (C90 6.6, C99 6.8).
3557 expression-statement
3565 expression-statement:
3568 selection-statement:
3572 iteration-statement:
3581 return expression[opt] ;
3594 objc-throw-statement
3595 objc-try-catch-statement
3596 objc-synchronized-statement
3598 objc-throw-statement:
3612 parallel-for-construct
3613 parallel-sections-construct
3620 parallel-directive structured-block
3623 for-directive iteration-statement
3626 sections-directive section-scope
3629 single-directive structured-block
3631 parallel-for-construct:
3632 parallel-for-directive iteration-statement
3634 parallel-sections-construct:
3635 parallel-sections-directive section-scope
3638 master-directive structured-block
3641 critical-directive structured-block
3644 atomic-directive expression-statement
3647 ordered-directive structured-block */
3650 c_parser_statement (c_parser *parser)
3652 while (c_parser_next_token_is_keyword (parser, RID_CASE)
3653 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
3654 || (c_parser_next_token_is (parser, CPP_NAME)
3655 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3656 c_parser_label (parser);
3657 c_parser_statement_after_labels (parser);
3660 /* Parse a statement, other than a labeled statement. */
3663 c_parser_statement_after_labels (c_parser *parser)
3665 location_t loc = c_parser_peek_token (parser)->location;
3666 tree stmt = NULL_TREE;
3667 bool in_if_block = parser->in_if_block;
3668 parser->in_if_block = false;
3669 switch (c_parser_peek_token (parser)->type)
3671 case CPP_OPEN_BRACE:
3672 add_stmt (c_parser_compound_statement (parser));
3675 switch (c_parser_peek_token (parser)->keyword)
3678 c_parser_if_statement (parser);
3681 c_parser_switch_statement (parser);
3684 c_parser_while_statement (parser);
3687 c_parser_do_statement (parser);
3690 c_parser_for_statement (parser);
3693 c_parser_consume_token (parser);
3694 if (c_parser_next_token_is (parser, CPP_NAME))
3696 stmt = c_finish_goto_label (c_parser_peek_token (parser)->value);
3697 c_parser_consume_token (parser);
3699 else if (c_parser_next_token_is (parser, CPP_MULT))
3701 c_parser_consume_token (parser);
3702 stmt = c_finish_goto_ptr (c_parser_expression (parser).value);
3705 c_parser_error (parser, "expected identifier or %<*%>");
3706 goto expect_semicolon;
3708 c_parser_consume_token (parser);
3709 stmt = c_finish_bc_stmt (&c_cont_label, false);
3710 goto expect_semicolon;
3712 c_parser_consume_token (parser);
3713 stmt = c_finish_bc_stmt (&c_break_label, true);
3714 goto expect_semicolon;
3716 c_parser_consume_token (parser);
3717 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3719 stmt = c_finish_return (NULL_TREE);
3720 c_parser_consume_token (parser);
3724 stmt = c_finish_return (c_parser_expression_conv (parser).value);
3725 goto expect_semicolon;
3729 stmt = c_parser_asm_statement (parser);
3732 gcc_assert (c_dialect_objc ());
3733 c_parser_consume_token (parser);
3734 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3736 stmt = objc_build_throw_stmt (NULL_TREE);
3737 c_parser_consume_token (parser);
3742 = objc_build_throw_stmt (c_parser_expression (parser).value);
3743 goto expect_semicolon;
3747 gcc_assert (c_dialect_objc ());
3748 c_parser_objc_try_catch_statement (parser);
3750 case RID_AT_SYNCHRONIZED:
3751 gcc_assert (c_dialect_objc ());
3752 c_parser_objc_synchronized_statement (parser);
3759 c_parser_consume_token (parser);
3761 case CPP_CLOSE_PAREN:
3762 case CPP_CLOSE_SQUARE:
3763 /* Avoid infinite loop in error recovery:
3764 c_parser_skip_until_found stops at a closing nesting
3765 delimiter without consuming it, but here we need to consume
3766 it to proceed further. */
3767 c_parser_error (parser, "expected statement");
3768 c_parser_consume_token (parser);
3771 c_parser_pragma (parser, pragma_stmt);
3775 stmt = c_finish_expr_stmt (c_parser_expression_conv (parser).value);
3777 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
3780 /* Two cases cannot and do not have line numbers associated: If stmt
3781 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
3782 cannot hold line numbers. But that's OK because the statement
3783 will either be changed to a MODIFY_EXPR during gimplification of
3784 the statement expr, or discarded. If stmt was compound, but
3785 without new variables, we will have skipped the creation of a
3786 BIND and will have a bare STATEMENT_LIST. But that's OK because
3787 (recursively) all of the component statements should already have
3788 line numbers assigned. ??? Can we discard no-op statements
3790 if (stmt && CAN_HAVE_LOCATION_P (stmt))
3791 SET_EXPR_LOCATION (stmt, loc);
3793 parser->in_if_block = in_if_block;
3796 /* Parse the condition from an if, do, while or for statements. */
3799 c_parser_condition (c_parser *parser)
3803 loc = c_parser_peek_token (parser)->location;
3804 cond = c_objc_common_truthvalue_conversion
3805 (c_parser_expression_conv (parser).value);
3806 if (CAN_HAVE_LOCATION_P (cond))
3807 SET_EXPR_LOCATION (cond, loc);
3808 if (warn_sequence_point)
3809 verify_sequence_points (cond);
3813 /* Parse a parenthesized condition from an if, do or while statement.
3819 c_parser_paren_condition (c_parser *parser)
3822 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3823 return error_mark_node;
3824 cond = c_parser_condition (parser);
3825 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
3829 /* Parse a statement which is a block in C99. */
3832 c_parser_c99_block_statement (c_parser *parser)
3834 tree block = c_begin_compound_stmt (flag_isoc99);
3835 c_parser_statement (parser);
3836 return c_end_compound_stmt (block, flag_isoc99);
3839 /* Parse the body of an if statement. This is just parsing a
3840 statement but (a) it is a block in C99, (b) we track whether the
3841 body is an if statement for the sake of -Wparentheses warnings, (c)
3842 we handle an empty body specially for the sake of -Wempty-body
3843 warnings, and (d) we call parser_compound_statement directly
3844 because c_parser_statement_after_labels resets
3845 parser->in_if_block. */
3848 c_parser_if_body (c_parser *parser, bool *if_p)
3850 tree block = c_begin_compound_stmt (flag_isoc99);
3851 while (c_parser_next_token_is_keyword (parser, RID_CASE)
3852 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
3853 || (c_parser_next_token_is (parser, CPP_NAME)
3854 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3855 c_parser_label (parser);
3856 *if_p = c_parser_next_token_is_keyword (parser, RID_IF);
3857 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3859 add_stmt (build_empty_stmt ());
3860 c_parser_consume_token (parser);
3862 else if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
3863 add_stmt (c_parser_compound_statement (parser));
3865 c_parser_statement_after_labels (parser);
3866 return c_end_compound_stmt (block, flag_isoc99);
3869 /* Parse the else body of an if statement. This is just parsing a
3870 statement but (a) it is a block in C99, (b) we handle an empty body
3871 specially for the sake of -Wempty-body warnings. */
3874 c_parser_else_body (c_parser *parser)
3876 tree block = c_begin_compound_stmt (flag_isoc99);
3877 while (c_parser_next_token_is_keyword (parser, RID_CASE)
3878 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
3879 || (c_parser_next_token_is (parser, CPP_NAME)
3880 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3881 c_parser_label (parser);
3882 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3884 add_stmt (build_empty_stmt ());
3885 c_parser_consume_token (parser);
3888 c_parser_statement_after_labels (parser);
3889 return c_end_compound_stmt (block, flag_isoc99);
3892 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
3895 if ( expression ) statement
3896 if ( expression ) statement else statement
3900 c_parser_if_statement (c_parser *parser)
3905 bool first_if = false;
3906 tree first_body, second_body;
3909 gcc_assert (c_parser_next_token_is_keyword (parser, RID_IF));
3910 c_parser_consume_token (parser);
3911 block = c_begin_compound_stmt (flag_isoc99);
3912 loc = c_parser_peek_token (parser)->location;
3913 cond = c_parser_paren_condition (parser);
3914 in_if_block = parser->in_if_block;
3915 parser->in_if_block = true;
3916 first_body = c_parser_if_body (parser, &first_if);
3917 parser->in_if_block = in_if_block;
3918 if (c_parser_next_token_is_keyword (parser, RID_ELSE))
3920 c_parser_consume_token (parser);
3921 second_body = c_parser_else_body (parser);
3924 second_body = NULL_TREE;
3925 c_finish_if_stmt (loc, cond, first_body, second_body, first_if);
3926 add_stmt (c_end_compound_stmt (block, flag_isoc99));
3929 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
3932 switch (expression) statement
3936 c_parser_switch_statement (c_parser *parser)
3938 tree block, expr, body, save_break;
3939 gcc_assert (c_parser_next_token_is_keyword (parser, RID_SWITCH));
3940 c_parser_consume_token (parser);
3941 block = c_begin_compound_stmt (flag_isoc99);
3942 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3944 expr = c_parser_expression (parser).value;
3945 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
3948 expr = error_mark_node;
3949 c_start_case (expr);
3950 save_break = c_break_label;
3951 c_break_label = NULL_TREE;
3952 body = c_parser_c99_block_statement (parser);
3953 c_finish_case (body);
3955 add_stmt (build1 (LABEL_EXPR, void_type_node, c_break_label));
3956 c_break_label = save_break;
3957 add_stmt (c_end_compound_stmt (block, flag_isoc99));
3960 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
3963 while (expression) statement
3967 c_parser_while_statement (c_parser *parser)
3969 tree block, cond, body, save_break, save_cont;
3971 gcc_assert (c_parser_next_token_is_keyword (parser, RID_WHILE));
3972 c_parser_consume_token (parser);
3973 block = c_begin_compound_stmt (flag_isoc99);
3974 loc = c_parser_peek_token (parser)->location;
3975 cond = c_parser_paren_condition (parser);
3976 save_break = c_break_label;
3977 c_break_label = NULL_TREE;
3978 save_cont = c_cont_label;
3979 c_cont_label = NULL_TREE;
3980 body = c_parser_c99_block_statement (parser);
3981 c_finish_loop (loc, cond, NULL, body, c_break_label, c_cont_label, true);
3982 add_stmt (c_end_compound_stmt (block, flag_isoc99));
3983 c_break_label = save_break;
3984 c_cont_label = save_cont;
3987 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
3990 do statement while ( expression ) ;
3994 c_parser_do_statement (c_parser *parser)
3996 tree block, cond, body, save_break, save_cont, new_break, new_cont;
3998 gcc_assert (c_parser_next_token_is_keyword (parser, RID_DO));
3999 c_parser_consume_token (parser);
4000 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4001 warning (OPT_Wempty_body,
4002 "%Hsuggest braces around empty body in %<do%> statement",
4003 &c_parser_peek_token (parser)->location);
4004 block = c_begin_compound_stmt (flag_isoc99);
4005 loc = c_parser_peek_token (parser)->location;
4006 save_break = c_break_label;
4007 c_break_label = NULL_TREE;
4008 save_cont = c_cont_label;
4009 c_cont_label = NULL_TREE;
4010 body = c_parser_c99_block_statement (parser);
4011 c_parser_require_keyword (parser, RID_WHILE, "expected %<while%>");
4012 new_break = c_break_label;
4013 c_break_label = save_break;
4014 new_cont = c_cont_label;
4015 c_cont_label = save_cont;
4016 cond = c_parser_paren_condition (parser);
4017 if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
4018 c_parser_skip_to_end_of_block_or_statement (parser);
4019 c_finish_loop (loc, cond, NULL, body, new_break, new_cont, false);
4020 add_stmt (c_end_compound_stmt (block, flag_isoc99));
4023 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
4026 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
4027 for ( nested-declaration expression[opt] ; expression[opt] ) statement
4029 The form with a declaration is new in C99.
4031 ??? In accordance with the old parser, the declaration may be a
4032 nested function, which is then rejected in check_for_loop_decls,
4033 but does it make any sense for this to be included in the grammar?
4034 Note in particular that the nested function does not include a
4035 trailing ';', whereas the "declaration" production includes one.
4036 Also, can we reject bad declarations earlier and cheaper than
4037 check_for_loop_decls? */
4040 c_parser_for_statement (c_parser *parser)
4042 tree block, cond, incr, save_break, save_cont, body;
4044 gcc_assert (c_parser_next_token_is_keyword (parser, RID_FOR));
4045 loc = c_parser_peek_token (parser)->location;
4046 c_parser_consume_token (parser);
4047 block = c_begin_compound_stmt (flag_isoc99);
4048 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4050 /* Parse the initialization declaration or expression. */
4051 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4053 c_parser_consume_token (parser);
4054 c_finish_expr_stmt (NULL_TREE);
4056 else if (c_parser_next_token_starts_declspecs (parser))
4058 c_parser_declaration_or_fndef (parser, true, true, true, true);
4059 check_for_loop_decls ();
4061 else if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
4063 /* __extension__ can start a declaration, but is also an
4064 unary operator that can start an expression. Consume all
4065 but the last of a possible series of __extension__ to
4067 while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD
4068 && (c_parser_peek_2nd_token (parser)->keyword
4070 c_parser_consume_token (parser);
4071 if (c_token_starts_declspecs (c_parser_peek_2nd_token (parser)))
4074 ext = disable_extension_diagnostics ();
4075 c_parser_consume_token (parser);
4076 c_parser_declaration_or_fndef (parser, true, true, true, true);
4077 restore_extension_diagnostics (ext);
4078 check_for_loop_decls ();
4086 c_finish_expr_stmt (c_parser_expression (parser).value);
4087 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4089 /* Parse the loop condition. */
4090 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4092 c_parser_consume_token (parser);
4097 cond = c_parser_condition (parser);
4098 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4100 /* Parse the increment expression. */
4101 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4102 incr = c_process_expr_stmt (NULL_TREE);
4104 incr = c_process_expr_stmt (c_parser_expression (parser).value);
4105 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4109 cond = error_mark_node;
4110 incr = error_mark_node;
4112 save_break = c_break_label;
4113 c_break_label = NULL_TREE;
4114 save_cont = c_cont_label;
4115 c_cont_label = NULL_TREE;
4116 body = c_parser_c99_block_statement (parser);
4117 c_finish_loop (loc, cond, incr, body, c_break_label, c_cont_label, true);
4118 add_stmt (c_end_compound_stmt (block, flag_isoc99));
4119 c_break_label = save_break;
4120 c_cont_label = save_cont;
4123 /* Parse an asm statement, a GNU extension. This is a full-blown asm
4124 statement with inputs, outputs, clobbers, and volatile tag
4128 asm type-qualifier[opt] ( asm-argument ) ;
4132 asm-string-literal : asm-operands[opt]
4133 asm-string-literal : asm-operands[opt] : asm-operands[opt]
4134 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers
4136 Qualifiers other than volatile are accepted in the syntax but
4140 c_parser_asm_statement (c_parser *parser)
4142 tree quals, str, outputs, inputs, clobbers, ret;
4144 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
4145 c_parser_consume_token (parser);
4146 if (c_parser_next_token_is_keyword (parser, RID_VOLATILE))
4148 quals = c_parser_peek_token (parser)->value;
4149 c_parser_consume_token (parser);
4151 else if (c_parser_next_token_is_keyword (parser, RID_CONST)
4152 || c_parser_next_token_is_keyword (parser, RID_RESTRICT))
4154 warning (0, "%H%E qualifier ignored on asm",
4155 &c_parser_peek_token (parser)->location,
4156 c_parser_peek_token (parser)->value);
4158 c_parser_consume_token (parser);
4162 /* ??? Follow the C++ parser rather than using the
4163 lex_untranslated_string kludge. */
4164 parser->lex_untranslated_string = true;
4165 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4167 parser->lex_untranslated_string = false;
4170 str = c_parser_asm_string_literal (parser);
4171 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4174 outputs = NULL_TREE;
4176 clobbers = NULL_TREE;
4179 if (!c_parser_require (parser, CPP_COLON, "expected %<:%> or %<)%>"))
4181 parser->lex_untranslated_string = false;
4182 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4186 /* Parse outputs. */
4187 if (c_parser_next_token_is (parser, CPP_COLON)
4188 || c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4189 outputs = NULL_TREE;
4191 outputs = c_parser_asm_operands (parser, false);
4192 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4195 clobbers = NULL_TREE;
4198 if (!c_parser_require (parser, CPP_COLON, "expected %<:%> or %<)%>"))
4200 parser->lex_untranslated_string = false;
4201 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4205 if (c_parser_next_token_is (parser, CPP_COLON)
4206 || c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4209 inputs = c_parser_asm_operands (parser, true);
4210 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4212 clobbers = NULL_TREE;
4215 if (!c_parser_require (parser, CPP_COLON, "expected %<:%> or %<)%>"))
4217 parser->lex_untranslated_string = false;
4218 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4221 /* Parse clobbers. */
4222 clobbers = c_parser_asm_clobbers (parser);
4224 parser->lex_untranslated_string = false;
4225 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
4227 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4230 if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
4231 c_parser_skip_to_end_of_block_or_statement (parser);
4232 ret = build_asm_stmt (quals, build_asm_expr (str, outputs, inputs,
4237 /* Parse asm operands, a GNU extension. If CONVERT_P (for inputs but
4238 not outputs), apply the default conversion of functions and arrays
4243 asm-operands , asm-operand
4246 asm-string-literal ( expression )
4247 [ identifier ] asm-string-literal ( expression )
4251 c_parser_asm_operands (c_parser *parser, bool convert_p)
4253 tree list = NULL_TREE;
4258 if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
4260 c_parser_consume_token (parser);
4261 if (c_parser_next_token_is (parser, CPP_NAME))
4263 tree id = c_parser_peek_token (parser)->value;
4264 c_parser_consume_token (parser);
4265 name = build_string (IDENTIFIER_LENGTH (id),
4266 IDENTIFIER_POINTER (id));
4270 c_parser_error (parser, "expected identifier");
4271 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
4274 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
4279 str = c_parser_asm_string_literal (parser);
4280 if (str == NULL_TREE)
4282 parser->lex_untranslated_string = false;
4283 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4285 parser->lex_untranslated_string = true;
4288 expr = c_parser_expression (parser);
4290 expr = default_function_array_conversion (expr);
4291 parser->lex_untranslated_string = true;
4292 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
4294 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4297 list = chainon (list, build_tree_list (build_tree_list (name, str),
4299 if (c_parser_next_token_is (parser, CPP_COMMA))
4300 c_parser_consume_token (parser);
4307 /* Parse asm clobbers, a GNU extension.
4311 asm-clobbers , asm-string-literal
4315 c_parser_asm_clobbers (c_parser *parser)
4317 tree list = NULL_TREE;
4320 tree str = c_parser_asm_string_literal (parser);
4322 list = tree_cons (NULL_TREE, str, list);
4325 if (c_parser_next_token_is (parser, CPP_COMMA))
4326 c_parser_consume_token (parser);
4333 /* Parse an expression other than a compound expression; that is, an
4334 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
4335 NULL then it is an Objective-C message expression which is the
4336 primary-expression starting the expression as an initializer.
4338 assignment-expression:
4339 conditional-expression
4340 unary-expression assignment-operator assignment-expression
4342 assignment-operator: one of
4343 = *= /= %= += -= <<= >>= &= ^= |=
4345 In GNU C we accept any conditional expression on the LHS and
4346 diagnose the invalid lvalue rather than producing a syntax
4349 static struct c_expr
4350 c_parser_expr_no_commas (c_parser *parser, struct c_expr *after)
4352 struct c_expr lhs, rhs, ret;
4353 enum tree_code code;
4354 gcc_assert (!after || c_dialect_objc ());
4355 lhs = c_parser_conditional_expression (parser, after);
4356 switch (c_parser_peek_token (parser)->type)
4365 code = TRUNC_DIV_EXPR;
4368 code = TRUNC_MOD_EXPR;
4383 code = BIT_AND_EXPR;
4386 code = BIT_XOR_EXPR;
4389 code = BIT_IOR_EXPR;
4394 c_parser_consume_token (parser);
4395 rhs = c_parser_expr_no_commas (parser, NULL);
4396 rhs = default_function_array_conversion (rhs);
4397 ret.value = build_modify_expr (lhs.value, code, rhs.value);
4398 if (code == NOP_EXPR)
4399 ret.original_code = MODIFY_EXPR;
4402 TREE_NO_WARNING (ret.value) = 1;
4403 ret.original_code = ERROR_MARK;
4408 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
4409 is not NULL then it is an Objective-C message expression which is
4410 the primary-expression starting the expression as an initializer.
4412 conditional-expression:
4413 logical-OR-expression
4414 logical-OR-expression ? expression : conditional-expression
4418 conditional-expression:
4419 logical-OR-expression ? : conditional-expression
4422 static struct c_expr
4423 c_parser_conditional_expression (c_parser *parser, struct c_expr *after)
4425 struct c_expr cond, exp1, exp2, ret;
4426 gcc_assert (!after || c_dialect_objc ());
4427 cond = c_parser_binary_expression (parser, after);
4428 if (c_parser_next_token_is_not (parser, CPP_QUERY))
4430 cond = default_function_array_conversion (cond);
4431 c_parser_consume_token (parser);
4432 if (c_parser_next_token_is (parser, CPP_COLON))
4434 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
4435 "ISO C forbids omitting the middle term of a ?: expression");
4436 /* Make sure first operand is calculated only once. */
4437 exp1.value = save_expr (default_conversion (cond.value));
4438 cond.value = c_objc_common_truthvalue_conversion (exp1.value);
4439 skip_evaluation += cond.value == truthvalue_true_node;
4444 = c_objc_common_truthvalue_conversion
4445 (default_conversion (cond.value));
4446 skip_evaluation += cond.value == truthvalue_false_node;
4447 exp1 = c_parser_expression_conv (parser);
4448 skip_evaluation += ((cond.value == truthvalue_true_node)
4449 - (cond.value == truthvalue_false_node));
4451 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
4453 skip_evaluation -= cond.value == truthvalue_true_node;
4454 ret.value = error_mark_node;
4455 ret.original_code = ERROR_MARK;
4458 exp2 = c_parser_conditional_expression (parser, NULL);
4459 exp2 = default_function_array_conversion (exp2);
4460 skip_evaluation -= cond.value == truthvalue_true_node;
4461 ret.value = build_conditional_expr (cond.value, exp1.value, exp2.value);
4462 ret.original_code = ERROR_MARK;
4466 /* Parse a binary expression; that is, a logical-OR-expression (C90
4467 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
4468 an Objective-C message expression which is the primary-expression
4469 starting the expression as an initializer.
4471 multiplicative-expression:
4473 multiplicative-expression * cast-expression
4474 multiplicative-expression / cast-expression
4475 multiplicative-expression % cast-expression
4477 additive-expression:
4478 multiplicative-expression
4479 additive-expression + multiplicative-expression
4480 additive-expression - multiplicative-expression
4484 shift-expression << additive-expression
4485 shift-expression >> additive-expression
4487 relational-expression:
4489 relational-expression < shift-expression
4490 relational-expression > shift-expression
4491 relational-expression <= shift-expression
4492 relational-expression >= shift-expression
4494 equality-expression:
4495 relational-expression
4496 equality-expression == relational-expression
4497 equality-expression != relational-expression
4501 AND-expression & equality-expression
4503 exclusive-OR-expression:
4505 exclusive-OR-expression ^ AND-expression
4507 inclusive-OR-expression:
4508 exclusive-OR-expression
4509 inclusive-OR-expression | exclusive-OR-expression
4511 logical-AND-expression:
4512 inclusive-OR-expression
4513 logical-AND-expression && inclusive-OR-expression
4515 logical-OR-expression:
4516 logical-AND-expression
4517 logical-OR-expression || logical-AND-expression
4520 static struct c_expr
4521 c_parser_binary_expression (c_parser *parser, struct c_expr *after)
4523 /* A binary expression is parsed using operator-precedence parsing,
4524 with the operands being cast expressions. All the binary
4525 operators are left-associative. Thus a binary expression is of
4528 E0 op1 E1 op2 E2 ...
4530 which we represent on a stack. On the stack, the precedence
4531 levels are strictly increasing. When a new operator is
4532 encountered of higher precedence than that at the top of the
4533 stack, it is pushed; its LHS is the top expression, and its RHS
4534 is everything parsed until it is popped. When a new operator is
4535 encountered with precedence less than or equal to that at the top
4536 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
4537 by the result of the operation until the operator at the top of
4538 the stack has lower precedence than the new operator or there is
4539 only one element on the stack; then the top expression is the LHS
4540 of the new operator. In the case of logical AND and OR
4541 expressions, we also need to adjust skip_evaluation as
4542 appropriate when the operators are pushed and popped. */
4544 /* The precedence levels, where 0 is a dummy lowest level used for
4545 the bottom of the stack. */
4561 /* The expression at this stack level. */
4563 /* The precedence of the operator on its left, PREC_NONE at the
4564 bottom of the stack. */
4566 /* The operation on its left. */
4572 switch (stack[sp].op) \
4574 case TRUTH_ANDIF_EXPR: \
4575 skip_evaluation -= stack[sp - 1].expr.value == truthvalue_false_node; \
4577 case TRUTH_ORIF_EXPR: \
4578 skip_evaluation -= stack[sp - 1].expr.value == truthvalue_true_node; \
4583 stack[sp - 1].expr \
4584 = default_function_array_conversion (stack[sp - 1].expr); \
4586 = default_function_array_conversion (stack[sp].expr); \
4587 stack[sp - 1].expr = parser_build_binary_op (stack[sp].op, \
4588 stack[sp - 1].expr, \
4592 gcc_assert (!after || c_dialect_objc ());
4593 stack[0].expr = c_parser_cast_expression (parser, after);
4594 stack[0].prec = PREC_NONE;
4599 enum tree_code ocode;
4602 switch (c_parser_peek_token (parser)->type)
4610 ocode = TRUNC_DIV_EXPR;
4614 ocode = TRUNC_MOD_EXPR;
4626 ocode = LSHIFT_EXPR;
4630 ocode = RSHIFT_EXPR;
4644 case CPP_GREATER_EQ:
4657 oprec = PREC_BITAND;
4658 ocode = BIT_AND_EXPR;
4661 oprec = PREC_BITXOR;
4662 ocode = BIT_XOR_EXPR;
4666 ocode = BIT_IOR_EXPR;
4669 oprec = PREC_LOGAND;
4670 ocode = TRUTH_ANDIF_EXPR;
4674 ocode = TRUTH_ORIF_EXPR;
4677 /* Not a binary operator, so end of the binary
4681 c_parser_consume_token (parser);
4682 while (oprec <= stack[sp].prec)
4686 case TRUTH_ANDIF_EXPR:
4688 = default_function_array_conversion (stack[sp].expr);
4689 stack[sp].expr.value = c_objc_common_truthvalue_conversion
4690 (default_conversion (stack[sp].expr.value));
4691 skip_evaluation += stack[sp].expr.value == truthvalue_false_node;
4693 case TRUTH_ORIF_EXPR:
4695 = default_function_array_conversion (stack[sp].expr);
4696 stack[sp].expr.value = c_objc_common_truthvalue_conversion
4697 (default_conversion (stack[sp].expr.value));
4698 skip_evaluation += stack[sp].expr.value == truthvalue_true_node;
4704 stack[sp].expr = c_parser_cast_expression (parser, NULL);
4705 stack[sp].prec = oprec;
4706 stack[sp].op = ocode;
4711 return stack[0].expr;
4715 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
4716 NULL then it is an Objective-C message expression which is the
4717 primary-expression starting the expression as an initializer.
4721 ( type-name ) unary-expression
4724 static struct c_expr
4725 c_parser_cast_expression (c_parser *parser, struct c_expr *after)
4727 gcc_assert (!after || c_dialect_objc ());
4729 return c_parser_postfix_expression_after_primary (parser, *after);
4730 /* If the expression begins with a parenthesized type name, it may
4731 be either a cast or a compound literal; we need to see whether
4732 the next character is '{' to tell the difference. If not, it is
4733 an unary expression. */
4734 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
4735 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
4737 struct c_type_name *type_name;
4740 c_parser_consume_token (parser);
4741 type_name = c_parser_type_name (parser);
4742 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4743 if (type_name == NULL)
4745 ret.value = error_mark_node;
4746 ret.original_code = ERROR_MARK;
4750 /* Save casted types in the function's used types hash table. */
4751 used_types_insert (type_name->specs->type);
4753 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
4754 return c_parser_postfix_expression_after_paren_type (parser,
4756 expr = c_parser_cast_expression (parser, NULL);
4757 expr = default_function_array_conversion (expr);
4758 ret.value = c_cast_expr (type_name, expr.value);
4759 ret.original_code = ERROR_MARK;
4763 return c_parser_unary_expression (parser);
4766 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
4772 unary-operator cast-expression
4773 sizeof unary-expression
4774 sizeof ( type-name )
4776 unary-operator: one of
4782 __alignof__ unary-expression
4783 __alignof__ ( type-name )
4786 unary-operator: one of
4787 __extension__ __real__ __imag__
4789 In addition, the GNU syntax treats ++ and -- as unary operators, so
4790 they may be applied to cast expressions with errors for non-lvalues
4793 static struct c_expr
4794 c_parser_unary_expression (c_parser *parser)
4797 struct c_expr ret, op;
4798 switch (c_parser_peek_token (parser)->type)
4801 c_parser_consume_token (parser);
4802 op = c_parser_cast_expression (parser, NULL);
4803 op = default_function_array_conversion (op);
4804 return parser_build_unary_op (PREINCREMENT_EXPR, op);
4805 case CPP_MINUS_MINUS:
4806 c_parser_consume_token (parser);
4807 op = c_parser_cast_expression (parser, NULL);
4808 op = default_function_array_conversion (op);
4809 return parser_build_unary_op (PREDECREMENT_EXPR, op);
4811 c_parser_consume_token (parser);
4812 return parser_build_unary_op (ADDR_EXPR,
4813 c_parser_cast_expression (parser, NULL));
4815 c_parser_consume_token (parser);
4816 op = c_parser_cast_expression (parser, NULL);
4817 op = default_function_array_conversion (op);
4818 ret.value = build_indirect_ref (op.value, "unary *");
4819 ret.original_code = ERROR_MARK;
4822 if (!c_dialect_objc () && !in_system_header)
4823 warning (OPT_Wtraditional,
4824 "%Htraditional C rejects the unary plus operator",
4825 &c_parser_peek_token (parser)->location);
4826 c_parser_consume_token (parser);
4827 op = c_parser_cast_expression (parser, NULL);
4828 op = default_function_array_conversion (op);
4829 return parser_build_unary_op (CONVERT_EXPR, op);
4831 c_parser_consume_token (parser);
4832 op = c_parser_cast_expression (parser, NULL);
4833 op = default_function_array_conversion (op);
4834 return parser_build_unary_op (NEGATE_EXPR, op);
4836 c_parser_consume_token (parser);
4837 op = c_parser_cast_expression (parser, NULL);
4838 op = default_function_array_conversion (op);
4839 return parser_build_unary_op (BIT_NOT_EXPR, op);
4841 c_parser_consume_token (parser);
4842 op = c_parser_cast_expression (parser, NULL);
4843 op = default_function_array_conversion (op);
4844 return parser_build_unary_op (TRUTH_NOT_EXPR, op);
4846 /* Refer to the address of a label as a pointer. */
4847 c_parser_consume_token (parser);
4848 if (c_parser_next_token_is (parser, CPP_NAME))
4850 ret.value = finish_label_address_expr
4851 (c_parser_peek_token (parser)->value);
4852 c_parser_consume_token (parser);
4856 c_parser_error (parser, "expected identifier");
4857 ret.value = error_mark_node;
4859 ret.original_code = ERROR_MARK;
4862 switch (c_parser_peek_token (parser)->keyword)
4865 return c_parser_sizeof_expression (parser);
4867 return c_parser_alignof_expression (parser);
4869 c_parser_consume_token (parser);
4870 ext = disable_extension_diagnostics ();
4871 ret = c_parser_cast_expression (parser, NULL);
4872 restore_extension_diagnostics (ext);
4875 c_parser_consume_token (parser);
4876 op = c_parser_cast_expression (parser, NULL);
4877 op = default_function_array_conversion (op);
4878 return parser_build_unary_op (REALPART_EXPR, op);
4880 c_parser_consume_token (parser);
4881 op = c_parser_cast_expression (parser, NULL);
4882 op = default_function_array_conversion (op);
4883 return parser_build_unary_op (IMAGPART_EXPR, op);
4885 return c_parser_postfix_expression (parser);
4888 return c_parser_postfix_expression (parser);
4892 /* Parse a sizeof expression. */
4894 static struct c_expr
4895 c_parser_sizeof_expression (c_parser *parser)
4898 location_t expr_loc;
4899 gcc_assert (c_parser_next_token_is_keyword (parser, RID_SIZEOF));
4900 c_parser_consume_token (parser);
4903 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
4904 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
4906 /* Either sizeof ( type-name ) or sizeof unary-expression
4907 starting with a compound literal. */
4908 struct c_type_name *type_name;
4909 c_parser_consume_token (parser);
4910 expr_loc = c_parser_peek_token (parser)->location;
4911 type_name = c_parser_type_name (parser);
4912 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4913 if (type_name == NULL)
4918 ret.value = error_mark_node;
4919 ret.original_code = ERROR_MARK;
4922 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
4924 expr = c_parser_postfix_expression_after_paren_type (parser,
4928 /* sizeof ( type-name ). */
4931 if (type_name->declarator->kind == cdk_array
4932 && type_name->declarator->u.array.vla_unspec_p)
4935 error ("%H%<[*]%> not allowed in other than a declaration",
4938 return c_expr_sizeof_type (type_name);
4942 expr_loc = c_parser_peek_token (parser)->location;
4943 expr = c_parser_unary_expression (parser);
4947 if (TREE_CODE (expr.value) == COMPONENT_REF
4948 && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
4949 error ("%H%<sizeof%> applied to a bit-field", &expr_loc);
4950 return c_expr_sizeof_expr (expr);
4954 /* Parse an alignof expression. */
4956 static struct c_expr
4957 c_parser_alignof_expression (c_parser *parser)
4960 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ALIGNOF));
4961 c_parser_consume_token (parser);
4964 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
4965 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
4967 /* Either __alignof__ ( type-name ) or __alignof__
4968 unary-expression starting with a compound literal. */
4969 struct c_type_name *type_name;
4971 c_parser_consume_token (parser);
4972 type_name = c_parser_type_name (parser);
4973 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4974 if (type_name == NULL)
4979 ret.value = error_mark_node;
4980 ret.original_code = ERROR_MARK;
4983 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
4985 expr = c_parser_postfix_expression_after_paren_type (parser,
4989 /* alignof ( type-name ). */
4992 ret.value = c_alignof (groktypename (type_name));
4993 ret.original_code = ERROR_MARK;
4999 expr = c_parser_unary_expression (parser);
5003 ret.value = c_alignof_expr (expr.value);
5004 ret.original_code = ERROR_MARK;
5009 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
5013 postfix-expression [ expression ]
5014 postfix-expression ( argument-expression-list[opt] )
5015 postfix-expression . identifier
5016 postfix-expression -> identifier
5017 postfix-expression ++
5018 postfix-expression --
5019 ( type-name ) { initializer-list }
5020 ( type-name ) { initializer-list , }
5022 argument-expression-list:
5024 argument-expression-list , argument-expression
5036 (treated as a keyword in GNU C)
5039 ( compound-statement )
5040 __builtin_va_arg ( assignment-expression , type-name )
5041 __builtin_offsetof ( type-name , offsetof-member-designator )
5042 __builtin_choose_expr ( assignment-expression ,
5043 assignment-expression ,
5044 assignment-expression )
5045 __builtin_types_compatible_p ( type-name , type-name )
5047 offsetof-member-designator:
5049 offsetof-member-designator . identifier
5050 offsetof-member-designator [ expression ]
5055 [ objc-receiver objc-message-args ]
5056 @selector ( objc-selector-arg )
5057 @protocol ( identifier )
5058 @encode ( type-name )
5062 static struct c_expr
5063 c_parser_postfix_expression (c_parser *parser)
5065 struct c_expr expr, e1, e2, e3;
5066 struct c_type_name *t1, *t2;
5068 switch (c_parser_peek_token (parser)->type)
5075 expr.value = c_parser_peek_token (parser)->value;
5076 expr.original_code = ERROR_MARK;
5077 c_parser_consume_token (parser);
5083 expr.value = c_parser_peek_token (parser)->value;
5084 expr.original_code = STRING_CST;
5085 c_parser_consume_token (parser);
5087 case CPP_OBJC_STRING:
5088 gcc_assert (c_dialect_objc ());
5090 = objc_build_string_object (c_parser_peek_token (parser)->value);
5091 expr.original_code = ERROR_MARK;
5092 c_parser_consume_token (parser);
5095 if (c_parser_peek_token (parser)->id_kind != C_ID_ID)
5097 c_parser_error (parser, "expected expression");
5098 expr.value = error_mark_node;
5099 expr.original_code = ERROR_MARK;
5103 tree id = c_parser_peek_token (parser)->value;
5104 location_t loc = c_parser_peek_token (parser)->location;
5105 c_parser_consume_token (parser);
5106 expr.value = build_external_ref (id,
5107 (c_parser_peek_token (parser)->type
5108 == CPP_OPEN_PAREN), loc);
5109 expr.original_code = ERROR_MARK;
5112 case CPP_OPEN_PAREN:
5113 /* A parenthesized expression, statement expression or compound
5115 if (c_parser_peek_2nd_token (parser)->type == CPP_OPEN_BRACE)
5117 /* A statement expression. */
5119 location_t here = c_parser_peek_token (parser)->location;
5120 c_parser_consume_token (parser);
5121 c_parser_consume_token (parser);
5122 if (cur_stmt_list == NULL)
5124 error ("%Hbraced-group within expression allowed "
5125 "only inside a function", &here);
5126 parser->error = true;
5127 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
5128 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5129 expr.value = error_mark_node;
5130 expr.original_code = ERROR_MARK;
5133 stmt = c_begin_stmt_expr ();
5134 c_parser_compound_statement_nostart (parser);
5135 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5137 pedwarn (here, OPT_pedantic,
5138 "ISO C forbids braced-groups within expressions");
5139 expr.value = c_finish_stmt_expr (stmt);
5140 expr.original_code = ERROR_MARK;
5142 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser)))
5144 /* A compound literal. ??? Can we actually get here rather
5145 than going directly to
5146 c_parser_postfix_expression_after_paren_type from
5148 struct c_type_name *type_name;
5149 c_parser_consume_token (parser);
5150 type_name = c_parser_type_name (parser);
5151 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5153 if (type_name == NULL)
5155 expr.value = error_mark_node;
5156 expr.original_code = ERROR_MARK;
5159 expr = c_parser_postfix_expression_after_paren_type (parser,
5164 /* A parenthesized expression. */
5165 c_parser_consume_token (parser);
5166 expr = c_parser_expression (parser);
5167 if (TREE_CODE (expr.value) == MODIFY_EXPR)
5168 TREE_NO_WARNING (expr.value) = 1;
5169 expr.original_code = ERROR_MARK;
5170 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5175 switch (c_parser_peek_token (parser)->keyword)
5177 case RID_FUNCTION_NAME:
5178 case RID_PRETTY_FUNCTION_NAME:
5179 case RID_C99_FUNCTION_NAME:
5180 expr.value = fname_decl (c_parser_peek_token (parser)->keyword,
5181 c_parser_peek_token (parser)->value);
5182 expr.original_code = ERROR_MARK;
5183 c_parser_consume_token (parser);
5186 c_parser_consume_token (parser);
5187 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5189 expr.value = error_mark_node;
5190 expr.original_code = ERROR_MARK;
5193 e1 = c_parser_expr_no_commas (parser, NULL);
5194 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5196 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5197 expr.value = error_mark_node;
5198 expr.original_code = ERROR_MARK;
5201 t1 = c_parser_type_name (parser);
5202 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5206 expr.value = error_mark_node;
5207 expr.original_code = ERROR_MARK;
5211 expr.value = build_va_arg (e1.value, groktypename (t1));
5212 expr.original_code = ERROR_MARK;
5216 c_parser_consume_token (parser);
5217 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5219 expr.value = error_mark_node;
5220 expr.original_code = ERROR_MARK;
5223 t1 = c_parser_type_name (parser);
5226 expr.value = error_mark_node;
5227 expr.original_code = ERROR_MARK;
5230 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5232 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5233 expr.value = error_mark_node;
5234 expr.original_code = ERROR_MARK;
5238 tree type = groktypename (t1);
5240 if (type == error_mark_node)
5241 offsetof_ref = error_mark_node;
5243 offsetof_ref = build1 (INDIRECT_REF, type, null_pointer_node);
5244 /* Parse the second argument to __builtin_offsetof. We
5245 must have one identifier, and beyond that we want to
5246 accept sub structure and sub array references. */
5247 if (c_parser_next_token_is (parser, CPP_NAME))
5249 offsetof_ref = build_component_ref
5250 (offsetof_ref, c_parser_peek_token (parser)->value);
5251 c_parser_consume_token (parser);
5252 while (c_parser_next_token_is (parser, CPP_DOT)
5253 || c_parser_next_token_is (parser,
5256 if (c_parser_next_token_is (parser, CPP_DOT))
5258 c_parser_consume_token (parser);
5259 if (c_parser_next_token_is_not (parser,
5262 c_parser_error (parser, "expected identifier");
5265 offsetof_ref = build_component_ref
5267 c_parser_peek_token (parser)->value);
5268 c_parser_consume_token (parser);
5273 c_parser_consume_token (parser);
5274 idx = c_parser_expression (parser).value;
5275 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
5277 offsetof_ref = build_array_ref (offsetof_ref, idx);
5282 c_parser_error (parser, "expected identifier");
5283 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5285 expr.value = fold_offsetof (offsetof_ref, NULL_TREE);
5286 expr.original_code = ERROR_MARK;
5289 case RID_CHOOSE_EXPR:
5290 c_parser_consume_token (parser);
5291 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5293 expr.value = error_mark_node;
5294 expr.original_code = ERROR_MARK;
5297 loc = c_parser_peek_token (parser)->location;
5298 e1 = c_parser_expr_no_commas (parser, NULL);
5299 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5301 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5302 expr.value = error_mark_node;
5303 expr.original_code = ERROR_MARK;
5306 e2 = c_parser_expr_no_commas (parser, NULL);
5307 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5309 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5310 expr.value = error_mark_node;
5311 expr.original_code = ERROR_MARK;
5314 e3 = c_parser_expr_no_commas (parser, NULL);
5315 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5320 c = fold (e1.value);
5321 if (TREE_CODE (c) != INTEGER_CST)
5322 error ("%Hfirst argument to %<__builtin_choose_expr%> not"
5323 " a constant", &loc);
5324 expr = integer_zerop (c) ? e3 : e2;
5327 case RID_TYPES_COMPATIBLE_P:
5328 c_parser_consume_token (parser);
5329 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5331 expr.value = error_mark_node;
5332 expr.original_code = ERROR_MARK;
5335 t1 = c_parser_type_name (parser);
5338 expr.value = error_mark_node;
5339 expr.original_code = ERROR_MARK;
5342 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5344 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5345 expr.value = error_mark_node;
5346 expr.original_code = ERROR_MARK;
5349 t2 = c_parser_type_name (parser);
5352 expr.value = error_mark_node;
5353 expr.original_code = ERROR_MARK;
5356 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5361 e1 = TYPE_MAIN_VARIANT (groktypename (t1));
5362 e2 = TYPE_MAIN_VARIANT (groktypename (t2));
5364 expr.value = comptypes (e1, e2)
5365 ? build_int_cst (NULL_TREE, 1)
5366 : build_int_cst (NULL_TREE, 0);
5367 expr.original_code = ERROR_MARK;
5370 case RID_AT_SELECTOR:
5371 gcc_assert (c_dialect_objc ());
5372 c_parser_consume_token (parser);
5373 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5375 expr.value = error_mark_node;
5376 expr.original_code = ERROR_MARK;
5380 tree sel = c_parser_objc_selector_arg (parser);
5381 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5383 expr.value = objc_build_selector_expr (sel);
5384 expr.original_code = ERROR_MARK;
5387 case RID_AT_PROTOCOL:
5388 gcc_assert (c_dialect_objc ());
5389 c_parser_consume_token (parser);
5390 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5392 expr.value = error_mark_node;
5393 expr.original_code = ERROR_MARK;
5396 if (c_parser_next_token_is_not (parser, CPP_NAME))
5398 c_parser_error (parser, "expected identifier");
5399 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5400 expr.value = error_mark_node;
5401 expr.original_code = ERROR_MARK;
5405 tree id = c_parser_peek_token (parser)->value;
5406 c_parser_consume_token (parser);
5407 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5409 expr.value = objc_build_protocol_expr (id);
5410 expr.original_code = ERROR_MARK;
5414 /* Extension to support C-structures in the archiver. */
5415 gcc_assert (c_dialect_objc ());
5416 c_parser_consume_token (parser);
5417 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5419 expr.value = error_mark_node;
5420 expr.original_code = ERROR_MARK;
5423 t1 = c_parser_type_name (parser);
5426 expr.value = error_mark_node;
5427 expr.original_code = ERROR_MARK;
5428 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5431 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5434 tree type = groktypename (t1);
5435 expr.value = objc_build_encode_expr (type);
5436 expr.original_code = ERROR_MARK;
5440 c_parser_error (parser, "expected expression");
5441 expr.value = error_mark_node;
5442 expr.original_code = ERROR_MARK;
5446 case CPP_OPEN_SQUARE:
5447 if (c_dialect_objc ())
5449 tree receiver, args;
5450 c_parser_consume_token (parser);
5451 receiver = c_parser_objc_receiver (parser);
5452 args = c_parser_objc_message_args (parser);
5453 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
5455 expr.value = objc_build_message_expr (build_tree_list (receiver,
5457 expr.original_code = ERROR_MARK;
5460 /* Else fall through to report error. */
5462 c_parser_error (parser, "expected expression");
5463 expr.value = error_mark_node;
5464 expr.original_code = ERROR_MARK;
5467 return c_parser_postfix_expression_after_primary (parser, expr);
5470 /* Parse a postfix expression after a parenthesized type name: the
5471 brace-enclosed initializer of a compound literal, possibly followed
5472 by some postfix operators. This is separate because it is not
5473 possible to tell until after the type name whether a cast
5474 expression has a cast or a compound literal, or whether the operand
5475 of sizeof is a parenthesized type name or starts with a compound
5478 static struct c_expr
5479 c_parser_postfix_expression_after_paren_type (c_parser *parser,
5480 struct c_type_name *type_name)
5485 location_t start_loc;
5486 start_init (NULL_TREE, NULL, 0);
5487 type = groktypename (type_name);
5488 start_loc = c_parser_peek_token (parser)->location;
5489 if (type != error_mark_node && C_TYPE_VARIABLE_SIZE (type))
5491 error ("%Hcompound literal has variable size", &start_loc);
5492 type = error_mark_node;
5494 init = c_parser_braced_init (parser, type, false);
5496 maybe_warn_string_init (type, init);
5499 pedwarn (start_loc, OPT_pedantic, "ISO C90 forbids compound literals");
5500 expr.value = build_compound_literal (type, init.value);
5501 expr.original_code = ERROR_MARK;
5502 return c_parser_postfix_expression_after_primary (parser, expr);
5505 /* Parse a postfix expression after the initial primary or compound
5506 literal; that is, parse a series of postfix operators. */
5508 static struct c_expr
5509 c_parser_postfix_expression_after_primary (c_parser *parser,
5512 tree ident, idx, exprlist;
5515 switch (c_parser_peek_token (parser)->type)
5517 case CPP_OPEN_SQUARE:
5518 /* Array reference. */
5519 c_parser_consume_token (parser);
5520 idx = c_parser_expression (parser).value;
5521 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
5523 expr.value = build_array_ref (expr.value, idx);
5524 expr.original_code = ERROR_MARK;
5526 case CPP_OPEN_PAREN:
5527 /* Function call. */
5528 c_parser_consume_token (parser);
5529 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
5530 exprlist = NULL_TREE;
5532 exprlist = c_parser_expr_list (parser, true);
5533 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5535 expr.value = build_function_call (expr.value, exprlist);
5536 expr.original_code = ERROR_MARK;
5537 if (warn_disallowed_functions)
5538 warn_if_disallowed_function_p (expr.value);
5541 /* Structure element reference. */
5542 c_parser_consume_token (parser);
5543 expr = default_function_array_conversion (expr);
5544 if (c_parser_next_token_is (parser, CPP_NAME))
5545 ident = c_parser_peek_token (parser)->value;
5548 c_parser_error (parser, "expected identifier");
5549 expr.value = error_mark_node;
5550 expr.original_code = ERROR_MARK;
5553 c_parser_consume_token (parser);
5554 expr.value = build_component_ref (expr.value, ident);
5555 expr.original_code = ERROR_MARK;
5558 /* Structure element reference. */
5559 c_parser_consume_token (parser);
5560 expr = default_function_array_conversion (expr);
5561 if (c_parser_next_token_is (parser, CPP_NAME))
5562 ident = c_parser_peek_token (parser)->value;
5565 c_parser_error (parser, "expected identifier");
5566 expr.value = error_mark_node;
5567 expr.original_code = ERROR_MARK;
5570 c_parser_consume_token (parser);
5571 expr.value = build_component_ref (build_indirect_ref (expr.value,
5573 expr.original_code = ERROR_MARK;
5576 /* Postincrement. */
5577 c_parser_consume_token (parser);
5578 expr = default_function_array_conversion (expr);
5579 expr.value = build_unary_op (POSTINCREMENT_EXPR, expr.value, 0);
5580 expr.original_code = ERROR_MARK;
5582 case CPP_MINUS_MINUS:
5583 /* Postdecrement. */
5584 c_parser_consume_token (parser);
5585 expr = default_function_array_conversion (expr);
5586 expr.value = build_unary_op (POSTDECREMENT_EXPR, expr.value, 0);
5587 expr.original_code = ERROR_MARK;
5595 /* Parse an expression (C90 6.3.17, C99 6.5.17).
5598 assignment-expression
5599 expression , assignment-expression
5602 static struct c_expr
5603 c_parser_expression (c_parser *parser)
5606 expr = c_parser_expr_no_commas (parser, NULL);
5607 while (c_parser_next_token_is (parser, CPP_COMMA))
5610 c_parser_consume_token (parser);
5611 next = c_parser_expr_no_commas (parser, NULL);
5612 next = default_function_array_conversion (next);
5613 expr.value = build_compound_expr (expr.value, next.value);
5614 expr.original_code = COMPOUND_EXPR;
5619 /* Parse an expression and convert functions or arrays to
5622 static struct c_expr
5623 c_parser_expression_conv (c_parser *parser)
5626 expr = c_parser_expression (parser);
5627 expr = default_function_array_conversion (expr);
5631 /* Parse a non-empty list of expressions. If CONVERT_P, convert
5632 functions and arrays to pointers.
5635 assignment-expression
5636 nonempty-expr-list , assignment-expression
5640 c_parser_expr_list (c_parser *parser, bool convert_p)
5644 expr = c_parser_expr_no_commas (parser, NULL);
5646 expr = default_function_array_conversion (expr);
5647 ret = cur = build_tree_list (NULL_TREE, expr.value);
5648 while (c_parser_next_token_is (parser, CPP_COMMA))
5650 c_parser_consume_token (parser);
5651 expr = c_parser_expr_no_commas (parser, NULL);
5653 expr = default_function_array_conversion (expr);
5654 cur = TREE_CHAIN (cur) = build_tree_list (NULL_TREE, expr.value);
5660 /* Parse Objective-C-specific constructs. */
5662 /* Parse an objc-class-definition.
5664 objc-class-definition:
5665 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
5666 objc-class-instance-variables[opt] objc-methodprotolist @end
5667 @implementation identifier objc-superclass[opt]
5668 objc-class-instance-variables[opt]
5669 @interface identifier ( identifier ) objc-protocol-refs[opt]
5670 objc-methodprotolist @end
5671 @implementation identifier ( identifier )
5676 "@interface identifier (" must start "@interface identifier (
5677 identifier ) ...": objc-methodprotolist in the first production may
5678 not start with a parenthesized identifier as a declarator of a data
5679 definition with no declaration specifiers if the objc-superclass,
5680 objc-protocol-refs and objc-class-instance-variables are omitted. */
5683 c_parser_objc_class_definition (c_parser *parser)
5688 if (c_parser_next_token_is_keyword (parser, RID_AT_INTERFACE))
5690 else if (c_parser_next_token_is_keyword (parser, RID_AT_IMPLEMENTATION))
5694 c_parser_consume_token (parser);
5695 if (c_parser_next_token_is_not (parser, CPP_NAME))
5697 c_parser_error (parser, "expected identifier");
5700 id1 = c_parser_peek_token (parser)->value;
5701 c_parser_consume_token (parser);
5702 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
5705 tree proto = NULL_TREE;
5706 c_parser_consume_token (parser);
5707 if (c_parser_next_token_is_not (parser, CPP_NAME))
5709 c_parser_error (parser, "expected identifier");
5710 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5713 id2 = c_parser_peek_token (parser)->value;
5714 c_parser_consume_token (parser);
5715 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5718 objc_start_category_implementation (id1, id2);
5721 if (c_parser_next_token_is (parser, CPP_LESS))
5722 proto = c_parser_objc_protocol_refs (parser);
5723 objc_start_category_interface (id1, id2, proto);
5724 c_parser_objc_methodprotolist (parser);
5725 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
5726 objc_finish_interface ();
5729 if (c_parser_next_token_is (parser, CPP_COLON))
5731 c_parser_consume_token (parser);
5732 if (c_parser_next_token_is_not (parser, CPP_NAME))
5734 c_parser_error (parser, "expected identifier");
5737 superclass = c_parser_peek_token (parser)->value;
5738 c_parser_consume_token (parser);
5741 superclass = NULL_TREE;
5744 tree proto = NULL_TREE;
5745 if (c_parser_next_token_is (parser, CPP_LESS))
5746 proto = c_parser_objc_protocol_refs (parser);
5747 objc_start_class_interface (id1, superclass, proto);
5750 objc_start_class_implementation (id1, superclass);
5751 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
5752 c_parser_objc_class_instance_variables (parser);
5755 objc_continue_interface ();
5756 c_parser_objc_methodprotolist (parser);
5757 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
5758 objc_finish_interface ();
5762 objc_continue_implementation ();
5767 /* Parse objc-class-instance-variables.
5769 objc-class-instance-variables:
5770 { objc-instance-variable-decl-list[opt] }
5772 objc-instance-variable-decl-list:
5773 objc-visibility-spec
5774 objc-instance-variable-decl ;
5776 objc-instance-variable-decl-list objc-visibility-spec
5777 objc-instance-variable-decl-list objc-instance-variable-decl ;
5778 objc-instance-variable-decl-list ;
5780 objc-visibility-spec:
5785 objc-instance-variable-decl:
5790 c_parser_objc_class_instance_variables (c_parser *parser)
5792 gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE));
5793 c_parser_consume_token (parser);
5794 while (c_parser_next_token_is_not (parser, CPP_EOF))
5797 /* Parse any stray semicolon. */
5798 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
5800 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
5801 "extra semicolon in struct or union specified");
5802 c_parser_consume_token (parser);
5805 /* Stop if at the end of the instance variables. */
5806 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
5808 c_parser_consume_token (parser);
5811 /* Parse any objc-visibility-spec. */
5812 if (c_parser_next_token_is_keyword (parser, RID_PRIVATE))
5814 c_parser_consume_token (parser);
5815 objc_set_visibility (2);
5818 else if (c_parser_next_token_is_keyword (parser, RID_PROTECTED))
5820 c_parser_consume_token (parser);
5821 objc_set_visibility (0);
5824 else if (c_parser_next_token_is_keyword (parser, RID_PUBLIC))
5826 c_parser_consume_token (parser);
5827 objc_set_visibility (1);
5830 else if (c_parser_next_token_is (parser, CPP_PRAGMA))
5832 c_parser_pragma (parser, pragma_external);
5836 /* Parse some comma-separated declarations. */
5837 decls = c_parser_struct_declaration (parser);
5839 /* Comma-separated instance variables are chained together in
5840 reverse order; add them one by one. */
5841 tree ivar = nreverse (decls);
5842 for (; ivar; ivar = TREE_CHAIN (ivar))
5843 objc_add_instance_variable (copy_node (ivar));
5845 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
5849 /* Parse an objc-class-declaration.
5851 objc-class-declaration:
5852 @class identifier-list ;
5856 c_parser_objc_class_declaration (c_parser *parser)
5858 tree list = NULL_TREE;
5859 gcc_assert (c_parser_next_token_is_keyword (parser, RID_CLASS));
5860 c_parser_consume_token (parser);
5861 /* Any identifiers, including those declared as type names, are OK
5866 if (c_parser_next_token_is_not (parser, CPP_NAME))
5868 c_parser_error (parser, "expected identifier");
5871 id = c_parser_peek_token (parser)->value;
5872 list = chainon (list, build_tree_list (NULL_TREE, id));
5873 c_parser_consume_token (parser);
5874 if (c_parser_next_token_is (parser, CPP_COMMA))
5875 c_parser_consume_token (parser);
5879 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
5880 objc_declare_class (list);
5883 /* Parse an objc-alias-declaration.
5885 objc-alias-declaration:
5886 @compatibility_alias identifier identifier ;
5890 c_parser_objc_alias_declaration (c_parser *parser)
5893 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_ALIAS));
5894 c_parser_consume_token (parser);
5895 if (c_parser_next_token_is_not (parser, CPP_NAME))
5897 c_parser_error (parser, "expected identifier");
5898 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
5901 id1 = c_parser_peek_token (parser)->value;
5902 c_parser_consume_token (parser);
5903 if (c_parser_next_token_is_not (parser, CPP_NAME))
5905 c_parser_error (parser, "expected identifier");
5906 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
5909 id2 = c_parser_peek_token (parser)->value;
5910 c_parser_consume_token (parser);
5911 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
5912 objc_declare_alias (id1, id2);
5915 /* Parse an objc-protocol-definition.
5917 objc-protocol-definition:
5918 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
5919 @protocol identifier-list ;
5921 "@protocol identifier ;" should be resolved as "@protocol
5922 identifier-list ;": objc-methodprotolist may not start with a
5923 semicolon in the first alternative if objc-protocol-refs are
5927 c_parser_objc_protocol_definition (c_parser *parser)
5929 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_PROTOCOL));
5930 c_parser_consume_token (parser);
5931 if (c_parser_next_token_is_not (parser, CPP_NAME))
5933 c_parser_error (parser, "expected identifier");
5936 if (c_parser_peek_2nd_token (parser)->type == CPP_COMMA
5937 || c_parser_peek_2nd_token (parser)->type == CPP_SEMICOLON)
5939 tree list = NULL_TREE;
5940 /* Any identifiers, including those declared as type names, are
5945 if (c_parser_next_token_is_not (parser, CPP_NAME))
5947 c_parser_error (parser, "expected identifier");
5950 id = c_parser_peek_token (parser)->value;
5951 list = chainon (list, build_tree_list (NULL_TREE, id));
5952 c_parser_consume_token (parser);
5953 if (c_parser_next_token_is (parser, CPP_COMMA))
5954 c_parser_consume_token (parser);
5958 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
5959 objc_declare_protocols (list);
5963 tree id = c_parser_peek_token (parser)->value;
5964 tree proto = NULL_TREE;
5965 c_parser_consume_token (parser);
5966 if (c_parser_next_token_is (parser, CPP_LESS))
5967 proto = c_parser_objc_protocol_refs (parser);
5968 parser->objc_pq_context = true;
5969 objc_start_protocol (id, proto);
5970 c_parser_objc_methodprotolist (parser);
5971 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
5972 parser->objc_pq_context = false;
5973 objc_finish_interface ();
5977 /* Parse an objc-method-type.
5984 static enum tree_code
5985 c_parser_objc_method_type (c_parser *parser)
5987 switch (c_parser_peek_token (parser)->type)
5990 c_parser_consume_token (parser);
5993 c_parser_consume_token (parser);
6000 /* Parse an objc-method-definition.
6002 objc-method-definition:
6003 objc-method-type objc-method-decl ;[opt] compound-statement
6007 c_parser_objc_method_definition (c_parser *parser)
6009 enum tree_code type = c_parser_objc_method_type (parser);
6011 objc_set_method_type (type);
6012 parser->objc_pq_context = true;
6013 decl = c_parser_objc_method_decl (parser);
6014 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
6016 c_parser_consume_token (parser);
6017 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
6018 "extra semicolon in method definition specified");
6020 if (!c_parser_next_token_is (parser, CPP_OPEN_BRACE))
6022 c_parser_error (parser, "expected %<{%>");
6025 parser->objc_pq_context = false;
6026 objc_start_method_definition (decl);
6027 add_stmt (c_parser_compound_statement (parser));
6028 objc_finish_method_definition (current_function_decl);
6031 /* Parse an objc-methodprotolist.
6033 objc-methodprotolist:
6035 objc-methodprotolist objc-methodproto
6036 objc-methodprotolist declaration
6037 objc-methodprotolist ;
6039 The declaration is a data definition, which may be missing
6040 declaration specifiers under the same rules and diagnostics as
6041 other data definitions outside functions, and the stray semicolon
6042 is diagnosed the same way as a stray semicolon outside a
6046 c_parser_objc_methodprotolist (c_parser *parser)
6050 /* The list is terminated by @end. */
6051 switch (c_parser_peek_token (parser)->type)
6054 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
6055 "ISO C does not allow extra %<;%> outside of a function");
6056 c_parser_consume_token (parser);
6060 c_parser_objc_methodproto (parser);
6063 c_parser_pragma (parser, pragma_external);
6068 if (c_parser_next_token_is_keyword (parser, RID_AT_END))
6070 c_parser_declaration_or_fndef (parser, false, true, false, true);
6076 /* Parse an objc-methodproto.
6079 objc-method-type objc-method-decl ;
6083 c_parser_objc_methodproto (c_parser *parser)
6085 enum tree_code type = c_parser_objc_method_type (parser);
6087 objc_set_method_type (type);
6088 /* Remember protocol qualifiers in prototypes. */
6089 parser->objc_pq_context = true;
6090 decl = c_parser_objc_method_decl (parser);
6091 /* Forget protocol qualifiers here. */
6092 parser->objc_pq_context = false;
6093 objc_add_method_declaration (decl);
6094 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
6097 /* Parse an objc-method-decl.
6100 ( objc-type-name ) objc-selector
6102 ( objc-type-name ) objc-keyword-selector objc-optparmlist
6103 objc-keyword-selector objc-optparmlist
6105 objc-keyword-selector:
6107 objc-keyword-selector objc-keyword-decl
6110 objc-selector : ( objc-type-name ) identifier
6111 objc-selector : identifier
6112 : ( objc-type-name ) identifier
6116 objc-optparms objc-optellipsis
6120 objc-opt-parms , parameter-declaration
6128 c_parser_objc_method_decl (c_parser *parser)
6130 tree type = NULL_TREE;
6132 tree parms = NULL_TREE;
6133 bool ellipsis = false;
6135 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
6137 c_parser_consume_token (parser);
6138 type = c_parser_objc_type_name (parser);
6139 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6141 sel = c_parser_objc_selector (parser);
6142 /* If there is no selector, or a colon follows, we have an
6143 objc-keyword-selector. If there is a selector, and a colon does
6144 not follow, that selector ends the objc-method-decl. */
6145 if (!sel || c_parser_next_token_is (parser, CPP_COLON))
6148 tree list = NULL_TREE;
6151 tree atype = NULL_TREE, id, keyworddecl;
6152 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
6154 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
6156 c_parser_consume_token (parser);
6157 atype = c_parser_objc_type_name (parser);
6158 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6161 if (c_parser_next_token_is_not (parser, CPP_NAME))
6163 c_parser_error (parser, "expected identifier");
6164 return error_mark_node;
6166 id = c_parser_peek_token (parser)->value;
6167 c_parser_consume_token (parser);
6168 keyworddecl = objc_build_keyword_decl (tsel, atype, id);
6169 list = chainon (list, keyworddecl);
6170 tsel = c_parser_objc_selector (parser);
6171 if (!tsel && c_parser_next_token_is_not (parser, CPP_COLON))
6174 /* Parse the optional parameter list. Optional Objective-C
6175 method parameters follow the C syntax, and may include '...'
6176 to denote a variable number of arguments. */
6177 parms = make_node (TREE_LIST);
6178 while (c_parser_next_token_is (parser, CPP_COMMA))
6180 struct c_parm *parm;
6181 c_parser_consume_token (parser);
6182 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
6185 c_parser_consume_token (parser);
6188 parm = c_parser_parameter_declaration (parser, NULL_TREE);
6191 parms = chainon (parms,
6192 build_tree_list (NULL_TREE, grokparm (parm)));
6196 return objc_build_method_signature (type, sel, parms, ellipsis);
6199 /* Parse an objc-type-name.
6202 objc-type-qualifiers[opt] type-name
6203 objc-type-qualifiers[opt]
6205 objc-type-qualifiers:
6207 objc-type-qualifiers objc-type-qualifier
6209 objc-type-qualifier: one of
6210 in out inout bycopy byref oneway
6214 c_parser_objc_type_name (c_parser *parser)
6216 tree quals = NULL_TREE;
6217 struct c_type_name *type_name = NULL;
6218 tree type = NULL_TREE;
6221 c_token *token = c_parser_peek_token (parser);
6222 if (token->type == CPP_KEYWORD
6223 && (token->keyword == RID_IN
6224 || token->keyword == RID_OUT
6225 || token->keyword == RID_INOUT
6226 || token->keyword == RID_BYCOPY
6227 || token->keyword == RID_BYREF
6228 || token->keyword == RID_ONEWAY))
6230 quals = chainon (quals, build_tree_list (NULL_TREE, token->value));
6231 c_parser_consume_token (parser);
6236 if (c_parser_next_token_starts_typename (parser))
6237 type_name = c_parser_type_name (parser);
6239 type = groktypename (type_name);
6240 return build_tree_list (quals, type);
6243 /* Parse objc-protocol-refs.
6250 c_parser_objc_protocol_refs (c_parser *parser)
6252 tree list = NULL_TREE;
6253 gcc_assert (c_parser_next_token_is (parser, CPP_LESS));
6254 c_parser_consume_token (parser);
6255 /* Any identifiers, including those declared as type names, are OK
6260 if (c_parser_next_token_is_not (parser, CPP_NAME))
6262 c_parser_error (parser, "expected identifier");
6265 id = c_parser_peek_token (parser)->value;
6266 list = chainon (list, build_tree_list (NULL_TREE, id));
6267 c_parser_consume_token (parser);
6268 if (c_parser_next_token_is (parser, CPP_COMMA))
6269 c_parser_consume_token (parser);
6273 c_parser_require (parser, CPP_GREATER, "expected %<>%>");
6277 /* Parse an objc-try-catch-statement.
6279 objc-try-catch-statement:
6280 @try compound-statement objc-catch-list[opt]
6281 @try compound-statement objc-catch-list[opt] @finally compound-statement
6284 @catch ( parameter-declaration ) compound-statement
6285 objc-catch-list @catch ( parameter-declaration ) compound-statement
6289 c_parser_objc_try_catch_statement (c_parser *parser)
6293 gcc_assert (c_parser_next_token_is_keyword (parser, RID_TRY));
6294 c_parser_consume_token (parser);
6295 loc = c_parser_peek_token (parser)->location;
6296 stmt = c_parser_compound_statement (parser);
6297 objc_begin_try_stmt (loc, stmt);
6298 while (c_parser_next_token_is_keyword (parser, RID_CATCH))
6300 struct c_parm *parm;
6301 c_parser_consume_token (parser);
6302 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6304 parm = c_parser_parameter_declaration (parser, NULL_TREE);
6307 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6310 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6311 objc_begin_catch_clause (grokparm (parm));
6312 if (c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
6313 c_parser_compound_statement_nostart (parser);
6314 objc_finish_catch_clause ();
6316 if (c_parser_next_token_is_keyword (parser, RID_AT_FINALLY))
6320 c_parser_consume_token (parser);
6321 finloc = c_parser_peek_token (parser)->location;
6322 finstmt = c_parser_compound_statement (parser);
6323 objc_build_finally_clause (finloc, finstmt);
6325 objc_finish_try_stmt ();
6328 /* Parse an objc-synchronized-statement.
6330 objc-synchronized-statement:
6331 @synchronized ( expression ) compound-statement
6335 c_parser_objc_synchronized_statement (c_parser *parser)
6339 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_SYNCHRONIZED));
6340 c_parser_consume_token (parser);
6341 loc = c_parser_peek_token (parser)->location;
6342 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6344 expr = c_parser_expression (parser).value;
6345 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6348 expr = error_mark_node;
6349 stmt = c_parser_compound_statement (parser);
6350 objc_build_synchronized (loc, expr, stmt);
6353 /* Parse an objc-selector; return NULL_TREE without an error if the
6354 next token is not an objc-selector.
6359 enum struct union if else while do for switch case default
6360 break continue return goto asm sizeof typeof __alignof
6361 unsigned long const short volatile signed restrict _Complex
6362 in out inout bycopy byref oneway int char float double void _Bool
6364 ??? Why this selection of keywords but not, for example, storage
6365 class specifiers? */
6368 c_parser_objc_selector (c_parser *parser)
6370 c_token *token = c_parser_peek_token (parser);
6371 tree value = token->value;
6372 if (token->type == CPP_NAME)
6374 c_parser_consume_token (parser);
6377 if (token->type != CPP_KEYWORD)
6379 switch (token->keyword)
6420 c_parser_consume_token (parser);
6427 /* Parse an objc-selector-arg.
6431 objc-keywordname-list
6433 objc-keywordname-list:
6435 objc-keywordname-list objc-keywordname
6443 c_parser_objc_selector_arg (c_parser *parser)
6445 tree sel = c_parser_objc_selector (parser);
6446 tree list = NULL_TREE;
6447 if (sel && c_parser_next_token_is_not (parser, CPP_COLON))
6451 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
6453 list = chainon (list, build_tree_list (sel, NULL_TREE));
6454 sel = c_parser_objc_selector (parser);
6455 if (!sel && c_parser_next_token_is_not (parser, CPP_COLON))
6461 /* Parse an objc-receiver.
6470 c_parser_objc_receiver (c_parser *parser)
6472 if (c_parser_peek_token (parser)->type == CPP_NAME
6473 && (c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME
6474 || c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME))
6476 tree id = c_parser_peek_token (parser)->value;
6477 c_parser_consume_token (parser);
6478 return objc_get_class_reference (id);
6480 return c_parser_expression (parser).value;
6483 /* Parse objc-message-args.
6487 objc-keywordarg-list
6489 objc-keywordarg-list:
6491 objc-keywordarg-list objc-keywordarg
6494 objc-selector : objc-keywordexpr
6499 c_parser_objc_message_args (c_parser *parser)
6501 tree sel = c_parser_objc_selector (parser);
6502 tree list = NULL_TREE;
6503 if (sel && c_parser_next_token_is_not (parser, CPP_COLON))
6508 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
6510 keywordexpr = c_parser_objc_keywordexpr (parser);
6511 list = chainon (list, build_tree_list (sel, keywordexpr));
6512 sel = c_parser_objc_selector (parser);
6513 if (!sel && c_parser_next_token_is_not (parser, CPP_COLON))
6519 /* Parse an objc-keywordexpr.
6526 c_parser_objc_keywordexpr (c_parser *parser)
6528 tree list = c_parser_expr_list (parser, true);
6529 if (TREE_CHAIN (list) == NULL_TREE)
6531 /* Just return the expression, remove a level of
6533 return TREE_VALUE (list);
6537 /* We have a comma expression, we will collapse later. */
6543 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
6544 should be considered, statements. ALLOW_STMT is true if we're within
6545 the context of a function and such pragmas are to be allowed. Returns
6546 true if we actually parsed such a pragma. */
6549 c_parser_pragma (c_parser *parser, enum pragma_context context)
6553 id = c_parser_peek_token (parser)->pragma_kind;
6554 gcc_assert (id != PRAGMA_NONE);
6558 case PRAGMA_OMP_BARRIER:
6559 if (context != pragma_compound)
6561 if (context == pragma_stmt)
6562 c_parser_error (parser, "%<#pragma omp barrier%> may only be "
6563 "used in compound statements");
6566 c_parser_omp_barrier (parser);
6569 case PRAGMA_OMP_FLUSH:
6570 if (context != pragma_compound)
6572 if (context == pragma_stmt)
6573 c_parser_error (parser, "%<#pragma omp flush%> may only be "
6574 "used in compound statements");
6577 c_parser_omp_flush (parser);
6580 case PRAGMA_OMP_TASKWAIT:
6581 if (context != pragma_compound)
6583 if (context == pragma_stmt)
6584 c_parser_error (parser, "%<#pragma omp taskwait%> may only be "
6585 "used in compound statements");
6588 c_parser_omp_taskwait (parser);
6591 case PRAGMA_OMP_THREADPRIVATE:
6592 c_parser_omp_threadprivate (parser);
6595 case PRAGMA_OMP_SECTION:
6596 error ("%H%<#pragma omp section%> may only be used in "
6597 "%<#pragma omp sections%> construct",
6598 &c_parser_peek_token (parser)->location);
6599 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
6602 case PRAGMA_GCC_PCH_PREPROCESS:
6603 c_parser_error (parser, "%<#pragma GCC pch_preprocess%> must be first");
6604 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
6608 if (id < PRAGMA_FIRST_EXTERNAL)
6610 if (context == pragma_external)
6613 c_parser_error (parser, "expected declaration specifiers");
6614 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
6617 c_parser_omp_construct (parser);
6623 c_parser_consume_pragma (parser);
6624 c_invoke_pragma_handler (id);
6626 /* Skip to EOL, but suppress any error message. Those will have been
6627 generated by the handler routine through calling error, as opposed
6628 to calling c_parser_error. */
6629 parser->error = true;
6630 c_parser_skip_to_pragma_eol (parser);
6635 /* The interface the pragma parsers have to the lexer. */
6638 pragma_lex (tree *value)
6640 c_token *tok = c_parser_peek_token (the_parser);
6641 enum cpp_ttype ret = tok->type;
6643 *value = tok->value;
6644 if (ret == CPP_PRAGMA_EOL || ret == CPP_EOF)
6648 if (ret == CPP_KEYWORD)
6650 c_parser_consume_token (the_parser);
6657 c_parser_pragma_pch_preprocess (c_parser *parser)
6661 c_parser_consume_pragma (parser);
6662 if (c_parser_next_token_is (parser, CPP_STRING))
6664 name = c_parser_peek_token (parser)->value;
6665 c_parser_consume_token (parser);
6668 c_parser_error (parser, "expected string literal");
6669 c_parser_skip_to_pragma_eol (parser);
6672 c_common_pch_pragma (parse_in, TREE_STRING_POINTER (name));
6675 /* OpenMP 2.5 parsing routines. */
6677 /* Returns name of the next clause.
6678 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
6679 the token is not consumed. Otherwise appropriate pragma_omp_clause is
6680 returned and the token is consumed. */
6682 static pragma_omp_clause
6683 c_parser_omp_clause_name (c_parser *parser)
6685 pragma_omp_clause result = PRAGMA_OMP_CLAUSE_NONE;
6687 if (c_parser_next_token_is_keyword (parser, RID_IF))
6688 result = PRAGMA_OMP_CLAUSE_IF;
6689 else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT))
6690 result = PRAGMA_OMP_CLAUSE_DEFAULT;
6691 else if (c_parser_next_token_is (parser, CPP_NAME))
6693 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
6698 if (!strcmp ("collapse", p))
6699 result = PRAGMA_OMP_CLAUSE_COLLAPSE;
6700 else if (!strcmp ("copyin", p))
6701 result = PRAGMA_OMP_CLAUSE_COPYIN;
6702 else if (!strcmp ("copyprivate", p))
6703 result = PRAGMA_OMP_CLAUSE_COPYPRIVATE;
6706 if (!strcmp ("firstprivate", p))
6707 result = PRAGMA_OMP_CLAUSE_FIRSTPRIVATE;
6710 if (!strcmp ("lastprivate", p))
6711 result = PRAGMA_OMP_CLAUSE_LASTPRIVATE;
6714 if (!strcmp ("nowait", p))
6715 result = PRAGMA_OMP_CLAUSE_NOWAIT;
6716 else if (!strcmp ("num_threads", p))
6717 result = PRAGMA_OMP_CLAUSE_NUM_THREADS;
6720 if (!strcmp ("ordered", p))
6721 result = PRAGMA_OMP_CLAUSE_ORDERED;
6724 if (!strcmp ("private", p))
6725 result = PRAGMA_OMP_CLAUSE_PRIVATE;
6728 if (!strcmp ("reduction", p))
6729 result = PRAGMA_OMP_CLAUSE_REDUCTION;
6732 if (!strcmp ("schedule", p))
6733 result = PRAGMA_OMP_CLAUSE_SCHEDULE;
6734 else if (!strcmp ("shared", p))
6735 result = PRAGMA_OMP_CLAUSE_SHARED;
6738 if (!strcmp ("untied", p))
6739 result = PRAGMA_OMP_CLAUSE_UNTIED;
6744 if (result != PRAGMA_OMP_CLAUSE_NONE)
6745 c_parser_consume_token (parser);
6750 /* Validate that a clause of the given type does not already exist. */
6753 check_no_duplicate_clause (tree clauses, enum omp_clause_code code,
6758 for (c = clauses; c ; c = OMP_CLAUSE_CHAIN (c))
6759 if (OMP_CLAUSE_CODE (c) == code)
6761 error ("too many %qs clauses", name);
6769 variable-list , identifier
6771 If KIND is nonzero, create the appropriate node and install the decl
6772 in OMP_CLAUSE_DECL and add the node to the head of the list.
6774 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
6775 return the list created. */
6778 c_parser_omp_variable_list (c_parser *parser, enum omp_clause_code kind,
6781 if (c_parser_next_token_is_not (parser, CPP_NAME)
6782 || c_parser_peek_token (parser)->id_kind != C_ID_ID)
6783 c_parser_error (parser, "expected identifier");
6785 while (c_parser_next_token_is (parser, CPP_NAME)
6786 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
6788 tree t = lookup_name (c_parser_peek_token (parser)->value);
6791 undeclared_variable (c_parser_peek_token (parser)->value,
6792 c_parser_peek_token (parser)->location);
6793 else if (t == error_mark_node)
6797 tree u = build_omp_clause (kind);
6798 OMP_CLAUSE_DECL (u) = t;
6799 OMP_CLAUSE_CHAIN (u) = list;
6803 list = tree_cons (t, NULL_TREE, list);
6805 c_parser_consume_token (parser);
6807 if (c_parser_next_token_is_not (parser, CPP_COMMA))
6810 c_parser_consume_token (parser);
6816 /* Similarly, but expect leading and trailing parenthesis. This is a very
6817 common case for omp clauses. */
6820 c_parser_omp_var_list_parens (c_parser *parser, enum omp_clause_code kind,
6823 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6825 list = c_parser_omp_variable_list (parser, kind, list);
6826 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6832 collapse ( constant-expression ) */
6835 c_parser_omp_clause_collapse (c_parser *parser, tree list)
6837 tree c, num = error_mark_node;
6841 check_no_duplicate_clause (list, OMP_CLAUSE_COLLAPSE, "collapse");
6843 loc = c_parser_peek_token (parser)->location;
6844 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6846 num = c_parser_expr_no_commas (parser, NULL).value;
6847 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6849 if (num == error_mark_node)
6851 if (!INTEGRAL_TYPE_P (TREE_TYPE (num))
6852 || !host_integerp (num, 0)
6853 || (n = tree_low_cst (num, 0)) <= 0
6856 error ("%Hcollapse argument needs positive constant integer expression",
6860 c = build_omp_clause (OMP_CLAUSE_COLLAPSE);
6861 OMP_CLAUSE_COLLAPSE_EXPR (c) = num;
6862 OMP_CLAUSE_CHAIN (c) = list;
6867 copyin ( variable-list ) */
6870 c_parser_omp_clause_copyin (c_parser *parser, tree list)
6872 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYIN, list);
6876 copyprivate ( variable-list ) */
6879 c_parser_omp_clause_copyprivate (c_parser *parser, tree list)
6881 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYPRIVATE, list);
6885 default ( shared | none ) */
6888 c_parser_omp_clause_default (c_parser *parser, tree list)
6890 enum omp_clause_default_kind kind = OMP_CLAUSE_DEFAULT_UNSPECIFIED;
6893 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6895 if (c_parser_next_token_is (parser, CPP_NAME))
6897 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
6902 if (strcmp ("none", p) != 0)
6904 kind = OMP_CLAUSE_DEFAULT_NONE;
6908 if (strcmp ("shared", p) != 0)
6910 kind = OMP_CLAUSE_DEFAULT_SHARED;
6917 c_parser_consume_token (parser);
6922 c_parser_error (parser, "expected %<none%> or %<shared%>");
6924 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6926 if (kind == OMP_CLAUSE_DEFAULT_UNSPECIFIED)
6929 check_no_duplicate_clause (list, OMP_CLAUSE_DEFAULT, "default");
6930 c = build_omp_clause (OMP_CLAUSE_DEFAULT);
6931 OMP_CLAUSE_CHAIN (c) = list;
6932 OMP_CLAUSE_DEFAULT_KIND (c) = kind;
6938 firstprivate ( variable-list ) */
6941 c_parser_omp_clause_firstprivate (c_parser *parser, tree list)
6943 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_FIRSTPRIVATE, list);
6947 if ( expression ) */
6950 c_parser_omp_clause_if (c_parser *parser, tree list)
6952 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
6954 tree t = c_parser_paren_condition (parser);
6957 check_no_duplicate_clause (list, OMP_CLAUSE_IF, "if");
6959 c = build_omp_clause (OMP_CLAUSE_IF);
6960 OMP_CLAUSE_IF_EXPR (c) = t;
6961 OMP_CLAUSE_CHAIN (c) = list;
6965 c_parser_error (parser, "expected %<(%>");
6971 lastprivate ( variable-list ) */
6974 c_parser_omp_clause_lastprivate (c_parser *parser, tree list)
6976 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_LASTPRIVATE, list);
6983 c_parser_omp_clause_nowait (c_parser *parser ATTRIBUTE_UNUSED, tree list)
6987 check_no_duplicate_clause (list, OMP_CLAUSE_NOWAIT, "nowait");
6989 c = build_omp_clause (OMP_CLAUSE_NOWAIT);
6990 OMP_CLAUSE_CHAIN (c) = list;
6995 num_threads ( expression ) */
6998 c_parser_omp_clause_num_threads (c_parser *parser, tree list)
7000 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7002 location_t expr_loc = c_parser_peek_token (parser)->location;
7003 tree c, t = c_parser_expression (parser).value;
7005 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7007 if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
7009 c_parser_error (parser, "expected integer expression");
7013 /* Attempt to statically determine when the number isn't positive. */
7014 c = fold_build2 (LE_EXPR, boolean_type_node, t,
7015 build_int_cst (TREE_TYPE (t), 0));
7016 if (c == boolean_true_node)
7018 warning (0, "%H%<num_threads%> value must be positive", &expr_loc);
7019 t = integer_one_node;
7022 check_no_duplicate_clause (list, OMP_CLAUSE_NUM_THREADS, "num_threads");
7024 c = build_omp_clause (OMP_CLAUSE_NUM_THREADS);
7025 OMP_CLAUSE_NUM_THREADS_EXPR (c) = t;
7026 OMP_CLAUSE_CHAIN (c) = list;
7037 c_parser_omp_clause_ordered (c_parser *parser ATTRIBUTE_UNUSED, tree list)
7041 check_no_duplicate_clause (list, OMP_CLAUSE_ORDERED, "ordered");
7043 c = build_omp_clause (OMP_CLAUSE_ORDERED);
7044 OMP_CLAUSE_CHAIN (c) = list;
7049 private ( variable-list ) */
7052 c_parser_omp_clause_private (c_parser *parser, tree list)
7054 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_PRIVATE, list);
7058 reduction ( reduction-operator : variable-list )
7061 One of: + * - & ^ | && || */
7064 c_parser_omp_clause_reduction (c_parser *parser, tree list)
7066 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7068 enum tree_code code;
7070 switch (c_parser_peek_token (parser)->type)
7082 code = BIT_AND_EXPR;
7085 code = BIT_XOR_EXPR;
7088 code = BIT_IOR_EXPR;
7091 code = TRUTH_ANDIF_EXPR;
7094 code = TRUTH_ORIF_EXPR;
7097 c_parser_error (parser,
7098 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
7099 "%<^%>, %<|%>, %<&&%>, or %<||%>");
7100 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0);
7103 c_parser_consume_token (parser);
7104 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
7108 nl = c_parser_omp_variable_list (parser, OMP_CLAUSE_REDUCTION, list);
7109 for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
7110 OMP_CLAUSE_REDUCTION_CODE (c) = code;
7114 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7120 schedule ( schedule-kind )
7121 schedule ( schedule-kind , expression )
7124 static | dynamic | guided | runtime | auto
7128 c_parser_omp_clause_schedule (c_parser *parser, tree list)
7132 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7135 c = build_omp_clause (OMP_CLAUSE_SCHEDULE);
7137 if (c_parser_next_token_is (parser, CPP_NAME))
7139 tree kind = c_parser_peek_token (parser)->value;
7140 const char *p = IDENTIFIER_POINTER (kind);
7145 if (strcmp ("dynamic", p) != 0)
7147 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_DYNAMIC;
7151 if (strcmp ("guided", p) != 0)
7153 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_GUIDED;
7157 if (strcmp ("runtime", p) != 0)
7159 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_RUNTIME;
7166 else if (c_parser_next_token_is_keyword (parser, RID_STATIC))
7167 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_STATIC;
7168 else if (c_parser_next_token_is_keyword (parser, RID_AUTO))
7169 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_AUTO;
7173 c_parser_consume_token (parser);
7174 if (c_parser_next_token_is (parser, CPP_COMMA))
7177 c_parser_consume_token (parser);
7179 here = c_parser_peek_token (parser)->location;
7180 t = c_parser_expr_no_commas (parser, NULL).value;
7182 if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_RUNTIME)
7183 error ("%Hschedule %<runtime%> does not take "
7184 "a %<chunk_size%> parameter", &here);
7185 else if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_AUTO)
7186 error ("%Hschedule %<auto%> does not take "
7187 "a %<chunk_size%> parameter", &here);
7188 else if (TREE_CODE (TREE_TYPE (t)) == INTEGER_TYPE)
7189 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c) = t;
7191 c_parser_error (parser, "expected integer expression");
7193 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7196 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7197 "expected %<,%> or %<)%>");
7199 check_no_duplicate_clause (list, OMP_CLAUSE_SCHEDULE, "schedule");
7200 OMP_CLAUSE_CHAIN (c) = list;
7204 c_parser_error (parser, "invalid schedule kind");
7205 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0);
7210 shared ( variable-list ) */
7213 c_parser_omp_clause_shared (c_parser *parser, tree list)
7215 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_SHARED, list);
7222 c_parser_omp_clause_untied (c_parser *parser ATTRIBUTE_UNUSED, tree list)
7226 /* FIXME: Should we allow duplicates? */
7227 check_no_duplicate_clause (list, OMP_CLAUSE_UNTIED, "untied");
7229 c = build_omp_clause (OMP_CLAUSE_UNTIED);
7230 OMP_CLAUSE_CHAIN (c) = list;
7234 /* Parse all OpenMP clauses. The set clauses allowed by the directive
7235 is a bitmask in MASK. Return the list of clauses found; the result
7236 of clause default goes in *pdefault. */
7239 c_parser_omp_all_clauses (c_parser *parser, unsigned int mask,
7242 tree clauses = NULL;
7245 while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
7248 pragma_omp_clause c_kind;
7250 tree prev = clauses;
7252 if (!first && c_parser_next_token_is (parser, CPP_COMMA))
7253 c_parser_consume_token (parser);
7256 here = c_parser_peek_token (parser)->location;
7257 c_kind = c_parser_omp_clause_name (parser);
7261 case PRAGMA_OMP_CLAUSE_COLLAPSE:
7262 clauses = c_parser_omp_clause_collapse (parser, clauses);
7263 c_name = "collapse";
7265 case PRAGMA_OMP_CLAUSE_COPYIN:
7266 clauses = c_parser_omp_clause_copyin (parser, clauses);
7269 case PRAGMA_OMP_CLAUSE_COPYPRIVATE:
7270 clauses = c_parser_omp_clause_copyprivate (parser, clauses);
7271 c_name = "copyprivate";
7273 case PRAGMA_OMP_CLAUSE_DEFAULT:
7274 clauses = c_parser_omp_clause_default (parser, clauses);
7277 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE:
7278 clauses = c_parser_omp_clause_firstprivate (parser, clauses);
7279 c_name = "firstprivate";
7281 case PRAGMA_OMP_CLAUSE_IF:
7282 clauses = c_parser_omp_clause_if (parser, clauses);
7285 case PRAGMA_OMP_CLAUSE_LASTPRIVATE:
7286 clauses = c_parser_omp_clause_lastprivate (parser, clauses);
7287 c_name = "lastprivate";
7289 case PRAGMA_OMP_CLAUSE_NOWAIT:
7290 clauses = c_parser_omp_clause_nowait (parser, clauses);
7293 case PRAGMA_OMP_CLAUSE_NUM_THREADS:
7294 clauses = c_parser_omp_clause_num_threads (parser, clauses);
7295 c_name = "num_threads";
7297 case PRAGMA_OMP_CLAUSE_ORDERED:
7298 clauses = c_parser_omp_clause_ordered (parser, clauses);
7301 case PRAGMA_OMP_CLAUSE_PRIVATE:
7302 clauses = c_parser_omp_clause_private (parser, clauses);
7305 case PRAGMA_OMP_CLAUSE_REDUCTION:
7306 clauses = c_parser_omp_clause_reduction (parser, clauses);
7307 c_name = "reduction";
7309 case PRAGMA_OMP_CLAUSE_SCHEDULE:
7310 clauses = c_parser_omp_clause_schedule (parser, clauses);
7311 c_name = "schedule";
7313 case PRAGMA_OMP_CLAUSE_SHARED:
7314 clauses = c_parser_omp_clause_shared (parser, clauses);
7317 case PRAGMA_OMP_CLAUSE_UNTIED:
7318 clauses = c_parser_omp_clause_untied (parser, clauses);
7322 c_parser_error (parser, "expected %<#pragma omp%> clause");
7326 if (((mask >> c_kind) & 1) == 0 && !parser->error)
7328 /* Remove the invalid clause(s) from the list to avoid
7329 confusing the rest of the compiler. */
7331 error ("%H%qs is not valid for %qs", &here, c_name, where);
7336 c_parser_skip_to_pragma_eol (parser);
7338 return c_finish_omp_clauses (clauses);
7345 In practice, we're also interested in adding the statement to an
7346 outer node. So it is convenient if we work around the fact that
7347 c_parser_statement calls add_stmt. */
7350 c_parser_omp_structured_block (c_parser *parser)
7352 tree stmt = push_stmt_list ();
7353 c_parser_statement (parser);
7354 return pop_stmt_list (stmt);
7358 # pragma omp atomic new-line
7362 x binop= expr | x++ | ++x | x-- | --x
7364 +, *, -, /, &, ^, |, <<, >>
7366 where x is an lvalue expression with scalar type. */
7369 c_parser_omp_atomic (c_parser *parser)
7373 enum tree_code code;
7374 struct c_expr rhs_expr;
7376 c_parser_skip_to_pragma_eol (parser);
7378 lhs = c_parser_unary_expression (parser).value;
7379 switch (TREE_CODE (lhs))
7383 c_parser_skip_to_end_of_block_or_statement (parser);
7386 case PREINCREMENT_EXPR:
7387 case POSTINCREMENT_EXPR:
7388 lhs = TREE_OPERAND (lhs, 0);
7390 rhs = integer_one_node;
7393 case PREDECREMENT_EXPR:
7394 case POSTDECREMENT_EXPR:
7395 lhs = TREE_OPERAND (lhs, 0);
7397 rhs = integer_one_node;
7401 switch (c_parser_peek_token (parser)->type)
7407 code = TRUNC_DIV_EXPR;
7422 code = BIT_AND_EXPR;
7425 code = BIT_IOR_EXPR;
7428 code = BIT_XOR_EXPR;
7431 c_parser_error (parser,
7432 "invalid operator for %<#pragma omp atomic%>");
7436 c_parser_consume_token (parser);
7437 rhs_expr = c_parser_expression (parser);
7438 rhs_expr = default_function_array_conversion (rhs_expr);
7439 rhs = rhs_expr.value;
7442 stmt = c_finish_omp_atomic (code, lhs, rhs);
7443 if (stmt != error_mark_node)
7445 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7450 # pragma omp barrier new-line
7454 c_parser_omp_barrier (c_parser *parser)
7456 c_parser_consume_pragma (parser);
7457 c_parser_skip_to_pragma_eol (parser);
7459 c_finish_omp_barrier ();
7463 # pragma omp critical [(name)] new-line
7468 c_parser_omp_critical (c_parser *parser)
7470 tree stmt, name = NULL;
7472 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
7474 c_parser_consume_token (parser);
7475 if (c_parser_next_token_is (parser, CPP_NAME))
7477 name = c_parser_peek_token (parser)->value;
7478 c_parser_consume_token (parser);
7479 c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7482 c_parser_error (parser, "expected identifier");
7484 else if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
7485 c_parser_error (parser, "expected %<(%> or end of line");
7486 c_parser_skip_to_pragma_eol (parser);
7488 stmt = c_parser_omp_structured_block (parser);
7489 return c_finish_omp_critical (stmt, name);
7493 # pragma omp flush flush-vars[opt] new-line
7496 ( variable-list ) */
7499 c_parser_omp_flush (c_parser *parser)
7501 c_parser_consume_pragma (parser);
7502 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
7503 c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL);
7504 else if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
7505 c_parser_error (parser, "expected %<(%> or end of line");
7506 c_parser_skip_to_pragma_eol (parser);
7508 c_finish_omp_flush ();
7511 /* Parse the restricted form of the for statement allowed by OpenMP.
7512 The real trick here is to determine the loop control variable early
7513 so that we can push a new decl if necessary to make it private. */
7516 c_parser_omp_for_loop (c_parser *parser, tree clauses, tree *par_clauses)
7518 tree decl, cond, incr, save_break, save_cont, body, init, stmt, cl;
7519 tree declv, condv, incrv, initv, for_block = NULL, ret = NULL;
7521 bool fail = false, open_brace_parsed = false;
7522 int i, collapse = 1, nbraces = 0;
7524 for (cl = clauses; cl; cl = OMP_CLAUSE_CHAIN (cl))
7525 if (OMP_CLAUSE_CODE (cl) == OMP_CLAUSE_COLLAPSE)
7526 collapse = tree_low_cst (OMP_CLAUSE_COLLAPSE_EXPR (cl), 0);
7528 gcc_assert (collapse >= 1);
7530 declv = make_tree_vec (collapse);
7531 initv = make_tree_vec (collapse);
7532 condv = make_tree_vec (collapse);
7533 incrv = make_tree_vec (collapse);
7535 if (!c_parser_next_token_is_keyword (parser, RID_FOR))
7537 c_parser_error (parser, "for statement expected");
7540 loc = c_parser_peek_token (parser)->location;
7541 c_parser_consume_token (parser);
7543 for (i = 0; i < collapse; i++)
7547 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7550 /* Parse the initialization declaration or expression. */
7551 if (c_parser_next_token_starts_declspecs (parser))
7555 = tree_cons (NULL, c_begin_compound_stmt (true), for_block);
7556 c_parser_declaration_or_fndef (parser, true, true, true, true);
7557 decl = check_for_loop_decls ();
7560 if (DECL_INITIAL (decl) == error_mark_node)
7561 decl = error_mark_node;
7564 else if (c_parser_next_token_is (parser, CPP_NAME)
7565 && c_parser_peek_2nd_token (parser)->type == CPP_EQ)
7567 struct c_expr init_exp;
7569 decl = c_parser_postfix_expression (parser).value;
7571 c_parser_require (parser, CPP_EQ, "expected %<=%>");
7573 init_exp = c_parser_expr_no_commas (parser, NULL);
7574 init_exp = default_function_array_conversion (init_exp);
7575 init = build_modify_expr (decl, NOP_EXPR, init_exp.value);
7576 init = c_process_expr_stmt (init);
7578 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7583 c_parser_error (parser,
7584 "expected iteration declaration or initialization");
7585 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7591 /* Parse the loop condition. */
7593 if (c_parser_next_token_is_not (parser, CPP_SEMICOLON))
7595 cond = c_parser_expression_conv (parser).value;
7596 cond = c_objc_common_truthvalue_conversion (cond);
7597 if (CAN_HAVE_LOCATION_P (cond))
7598 SET_EXPR_LOCATION (cond, input_location);
7600 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7602 /* Parse the increment expression. */
7604 if (c_parser_next_token_is_not (parser, CPP_CLOSE_PAREN))
7605 incr = c_process_expr_stmt (c_parser_expression (parser).value);
7606 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7608 if (decl == NULL || decl == error_mark_node || init == error_mark_node)
7612 TREE_VEC_ELT (declv, i) = decl;
7613 TREE_VEC_ELT (initv, i) = init;
7614 TREE_VEC_ELT (condv, i) = cond;
7615 TREE_VEC_ELT (incrv, i) = incr;
7619 if (i == collapse - 1)
7622 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
7623 in between the collapsed for loops to be still considered perfectly
7624 nested. Hopefully the final version clarifies this.
7625 For now handle (multiple) {'s and empty statements. */
7628 if (c_parser_next_token_is_keyword (parser, RID_FOR))
7630 c_parser_consume_token (parser);
7633 else if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
7635 c_parser_consume_token (parser);
7639 && c_parser_next_token_is (parser, CPP_SEMICOLON))
7640 c_parser_consume_token (parser);
7643 c_parser_error (parser, "not enough perfectly nested loops");
7646 open_brace_parsed = true;
7656 nbraces += bracecount;
7659 save_break = c_break_label;
7660 c_break_label = size_one_node;
7661 save_cont = c_cont_label;
7662 c_cont_label = NULL_TREE;
7663 body = push_stmt_list ();
7665 if (open_brace_parsed)
7667 stmt = c_begin_compound_stmt (true);
7668 c_parser_compound_statement_nostart (parser);
7669 add_stmt (c_end_compound_stmt (stmt, true));
7672 add_stmt (c_parser_c99_block_statement (parser));
7674 add_stmt (build1 (LABEL_EXPR, void_type_node, c_cont_label));
7676 body = pop_stmt_list (body);
7677 c_break_label = save_break;
7678 c_cont_label = save_cont;
7682 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
7684 c_parser_consume_token (parser);
7687 else if (c_parser_next_token_is (parser, CPP_SEMICOLON))
7688 c_parser_consume_token (parser);
7691 c_parser_error (parser, "collapsed loops not perfectly nested");
7694 stmt = c_begin_compound_stmt (true);
7696 c_parser_compound_statement_nostart (parser);
7697 body = c_end_compound_stmt (stmt, true);
7704 /* Only bother calling c_finish_omp_for if we haven't already generated
7705 an error from the initialization parsing. */
7708 stmt = c_finish_omp_for (loc, declv, initv, condv, incrv, body, NULL);
7711 if (par_clauses != NULL)
7714 for (c = par_clauses; *c ; )
7715 if (OMP_CLAUSE_CODE (*c) != OMP_CLAUSE_FIRSTPRIVATE
7716 && OMP_CLAUSE_CODE (*c) != OMP_CLAUSE_LASTPRIVATE)
7717 c = &OMP_CLAUSE_CHAIN (*c);
7720 for (i = 0; i < collapse; i++)
7721 if (TREE_VEC_ELT (declv, i) == OMP_CLAUSE_DECL (*c))
7724 c = &OMP_CLAUSE_CHAIN (*c);
7725 else if (OMP_CLAUSE_CODE (*c) == OMP_CLAUSE_FIRSTPRIVATE)
7727 error ("%Hiteration variable %qD should not be firstprivate",
7728 &loc, OMP_CLAUSE_DECL (*c));
7729 *c = OMP_CLAUSE_CHAIN (*c);
7733 /* Copy lastprivate (decl) clause to OMP_FOR_CLAUSES,
7734 change it to shared (decl) in
7735 OMP_PARALLEL_CLAUSES. */
7736 tree l = build_omp_clause (OMP_CLAUSE_LASTPRIVATE);
7737 OMP_CLAUSE_DECL (l) = OMP_CLAUSE_DECL (*c);
7738 OMP_CLAUSE_CHAIN (l) = clauses;
7740 OMP_CLAUSE_SET_CODE (*c, OMP_CLAUSE_SHARED);
7744 OMP_FOR_CLAUSES (stmt) = clauses;
7751 stmt = c_end_compound_stmt (TREE_VALUE (for_block), true);
7753 for_block = TREE_CHAIN (for_block);
7759 #pragma omp for for-clause[optseq] new-line
7763 #define OMP_FOR_CLAUSE_MASK \
7764 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
7765 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
7766 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
7767 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
7768 | (1u << PRAGMA_OMP_CLAUSE_ORDERED) \
7769 | (1u << PRAGMA_OMP_CLAUSE_SCHEDULE) \
7770 | (1u << PRAGMA_OMP_CLAUSE_COLLAPSE) \
7771 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
7774 c_parser_omp_for (c_parser *parser)
7776 tree block, clauses, ret;
7778 clauses = c_parser_omp_all_clauses (parser, OMP_FOR_CLAUSE_MASK,
7781 block = c_begin_compound_stmt (true);
7782 ret = c_parser_omp_for_loop (parser, clauses, NULL);
7783 block = c_end_compound_stmt (block, true);
7790 # pragma omp master new-line
7795 c_parser_omp_master (c_parser *parser)
7797 c_parser_skip_to_pragma_eol (parser);
7798 return c_finish_omp_master (c_parser_omp_structured_block (parser));
7802 # pragma omp ordered new-line
7807 c_parser_omp_ordered (c_parser *parser)
7809 c_parser_skip_to_pragma_eol (parser);
7810 return c_finish_omp_ordered (c_parser_omp_structured_block (parser));
7816 { section-sequence }
7819 section-directive[opt] structured-block
7820 section-sequence section-directive structured-block */
7823 c_parser_omp_sections_scope (c_parser *parser)
7826 bool error_suppress = false;
7829 if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
7831 /* Avoid skipping until the end of the block. */
7832 parser->error = false;
7836 stmt = push_stmt_list ();
7838 loc = c_parser_peek_token (parser)->location;
7839 if (c_parser_peek_token (parser)->pragma_kind != PRAGMA_OMP_SECTION)
7841 substmt = push_stmt_list ();
7845 c_parser_statement (parser);
7847 if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_OMP_SECTION)
7849 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
7851 if (c_parser_next_token_is (parser, CPP_EOF))
7855 substmt = pop_stmt_list (substmt);
7856 substmt = build1 (OMP_SECTION, void_type_node, substmt);
7857 SET_EXPR_LOCATION (substmt, loc);
7863 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
7865 if (c_parser_next_token_is (parser, CPP_EOF))
7868 loc = c_parser_peek_token (parser)->location;
7869 if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_OMP_SECTION)
7871 c_parser_consume_pragma (parser);
7872 c_parser_skip_to_pragma_eol (parser);
7873 error_suppress = false;
7875 else if (!error_suppress)
7877 error ("%Hexpected %<#pragma omp section%> or %<}%>",
7879 error_suppress = true;
7882 substmt = c_parser_omp_structured_block (parser);
7883 substmt = build1 (OMP_SECTION, void_type_node, substmt);
7884 SET_EXPR_LOCATION (substmt, loc);
7887 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE,
7888 "expected %<#pragma omp section%> or %<}%>");
7890 substmt = pop_stmt_list (stmt);
7892 stmt = make_node (OMP_SECTIONS);
7893 TREE_TYPE (stmt) = void_type_node;
7894 OMP_SECTIONS_BODY (stmt) = substmt;
7896 return add_stmt (stmt);
7900 # pragma omp sections sections-clause[optseq] newline
7904 #define OMP_SECTIONS_CLAUSE_MASK \
7905 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
7906 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
7907 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
7908 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
7909 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
7912 c_parser_omp_sections (c_parser *parser)
7914 tree block, clauses, ret;
7916 clauses = c_parser_omp_all_clauses (parser, OMP_SECTIONS_CLAUSE_MASK,
7917 "#pragma omp sections");
7919 block = c_begin_compound_stmt (true);
7920 ret = c_parser_omp_sections_scope (parser);
7922 OMP_SECTIONS_CLAUSES (ret) = clauses;
7923 block = c_end_compound_stmt (block, true);
7930 # pragma parallel parallel-clause new-line
7931 # pragma parallel for parallel-for-clause new-line
7932 # pragma parallel sections parallel-sections-clause new-line
7935 #define OMP_PARALLEL_CLAUSE_MASK \
7936 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
7937 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
7938 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
7939 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
7940 | (1u << PRAGMA_OMP_CLAUSE_SHARED) \
7941 | (1u << PRAGMA_OMP_CLAUSE_COPYIN) \
7942 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
7943 | (1u << PRAGMA_OMP_CLAUSE_NUM_THREADS))
7946 c_parser_omp_parallel (c_parser *parser)
7948 enum pragma_kind p_kind = PRAGMA_OMP_PARALLEL;
7949 const char *p_name = "#pragma omp parallel";
7950 tree stmt, clauses, par_clause, ws_clause, block;
7951 unsigned int mask = OMP_PARALLEL_CLAUSE_MASK;
7953 if (c_parser_next_token_is_keyword (parser, RID_FOR))
7955 c_parser_consume_token (parser);
7956 p_kind = PRAGMA_OMP_PARALLEL_FOR;
7957 p_name = "#pragma omp parallel for";
7958 mask |= OMP_FOR_CLAUSE_MASK;
7959 mask &= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT);
7961 else if (c_parser_next_token_is (parser, CPP_NAME))
7963 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
7964 if (strcmp (p, "sections") == 0)
7966 c_parser_consume_token (parser);
7967 p_kind = PRAGMA_OMP_PARALLEL_SECTIONS;
7968 p_name = "#pragma omp parallel sections";
7969 mask |= OMP_SECTIONS_CLAUSE_MASK;
7970 mask &= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT);
7974 clauses = c_parser_omp_all_clauses (parser, mask, p_name);
7978 case PRAGMA_OMP_PARALLEL:
7979 block = c_begin_omp_parallel ();
7980 c_parser_statement (parser);
7981 stmt = c_finish_omp_parallel (clauses, block);
7984 case PRAGMA_OMP_PARALLEL_FOR:
7985 block = c_begin_omp_parallel ();
7986 c_split_parallel_clauses (clauses, &par_clause, &ws_clause);
7987 c_parser_omp_for_loop (parser, ws_clause, &par_clause);
7988 stmt = c_finish_omp_parallel (par_clause, block);
7989 OMP_PARALLEL_COMBINED (stmt) = 1;
7992 case PRAGMA_OMP_PARALLEL_SECTIONS:
7993 block = c_begin_omp_parallel ();
7994 c_split_parallel_clauses (clauses, &par_clause, &ws_clause);
7995 stmt = c_parser_omp_sections_scope (parser);
7997 OMP_SECTIONS_CLAUSES (stmt) = ws_clause;
7998 stmt = c_finish_omp_parallel (par_clause, block);
7999 OMP_PARALLEL_COMBINED (stmt) = 1;
8010 # pragma omp single single-clause[optseq] new-line
8014 #define OMP_SINGLE_CLAUSE_MASK \
8015 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8016 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8017 | (1u << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
8018 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
8021 c_parser_omp_single (c_parser *parser)
8023 tree stmt = make_node (OMP_SINGLE);
8024 TREE_TYPE (stmt) = void_type_node;
8026 OMP_SINGLE_CLAUSES (stmt)
8027 = c_parser_omp_all_clauses (parser, OMP_SINGLE_CLAUSE_MASK,
8028 "#pragma omp single");
8029 OMP_SINGLE_BODY (stmt) = c_parser_omp_structured_block (parser);
8031 return add_stmt (stmt);
8035 # pragma omp task task-clause[optseq] new-line
8038 #define OMP_TASK_CLAUSE_MASK \
8039 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
8040 | (1u << PRAGMA_OMP_CLAUSE_UNTIED) \
8041 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
8042 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8043 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8044 | (1u << PRAGMA_OMP_CLAUSE_SHARED))
8047 c_parser_omp_task (c_parser *parser)
8049 tree clauses, block;
8051 clauses = c_parser_omp_all_clauses (parser, OMP_TASK_CLAUSE_MASK,
8052 "#pragma omp task");
8054 block = c_begin_omp_task ();
8055 c_parser_statement (parser);
8056 return c_finish_omp_task (clauses, block);
8060 # pragma omp taskwait new-line
8064 c_parser_omp_taskwait (c_parser *parser)
8066 c_parser_consume_pragma (parser);
8067 c_parser_skip_to_pragma_eol (parser);
8069 c_finish_omp_taskwait ();
8072 /* Main entry point to parsing most OpenMP pragmas. */
8075 c_parser_omp_construct (c_parser *parser)
8077 enum pragma_kind p_kind;
8081 loc = c_parser_peek_token (parser)->location;
8082 p_kind = c_parser_peek_token (parser)->pragma_kind;
8083 c_parser_consume_pragma (parser);
8085 /* For all constructs below except #pragma omp atomic
8086 MUST_NOT_THROW catch handlers are needed when exceptions
8088 if (p_kind != PRAGMA_OMP_ATOMIC)
8089 c_maybe_initialize_eh ();
8093 case PRAGMA_OMP_ATOMIC:
8094 c_parser_omp_atomic (parser);
8096 case PRAGMA_OMP_CRITICAL:
8097 stmt = c_parser_omp_critical (parser);
8099 case PRAGMA_OMP_FOR:
8100 stmt = c_parser_omp_for (parser);
8102 case PRAGMA_OMP_MASTER:
8103 stmt = c_parser_omp_master (parser);
8105 case PRAGMA_OMP_ORDERED:
8106 stmt = c_parser_omp_ordered (parser);
8108 case PRAGMA_OMP_PARALLEL:
8109 stmt = c_parser_omp_parallel (parser);
8111 case PRAGMA_OMP_SECTIONS:
8112 stmt = c_parser_omp_sections (parser);
8114 case PRAGMA_OMP_SINGLE:
8115 stmt = c_parser_omp_single (parser);
8117 case PRAGMA_OMP_TASK:
8118 stmt = c_parser_omp_task (parser);
8125 SET_EXPR_LOCATION (stmt, loc);
8130 # pragma omp threadprivate (variable-list) */
8133 c_parser_omp_threadprivate (c_parser *parser)
8137 c_parser_consume_pragma (parser);
8138 vars = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL);
8140 /* Mark every variable in VARS to be assigned thread local storage. */
8141 for (t = vars; t; t = TREE_CHAIN (t))
8143 tree v = TREE_PURPOSE (t);
8145 /* If V had already been marked threadprivate, it doesn't matter
8146 whether it had been used prior to this point. */
8147 if (TREE_CODE (v) != VAR_DECL)
8148 error ("%qD is not a variable", v);
8149 else if (TREE_USED (v) && !C_DECL_THREADPRIVATE_P (v))
8150 error ("%qE declared %<threadprivate%> after first use", v);
8151 else if (! TREE_STATIC (v) && ! DECL_EXTERNAL (v))
8152 error ("automatic variable %qE cannot be %<threadprivate%>", v);
8153 else if (TREE_TYPE (v) == error_mark_node)
8155 else if (! COMPLETE_TYPE_P (TREE_TYPE (v)))
8156 error ("%<threadprivate%> %qE has incomplete type", v);
8159 if (! DECL_THREAD_LOCAL_P (v))
8161 DECL_TLS_MODEL (v) = decl_default_tls_model (v);
8162 /* If rtl has been already set for this var, call
8163 make_decl_rtl once again, so that encode_section_info
8164 has a chance to look at the new decl flags. */
8165 if (DECL_RTL_SET_P (v))
8168 C_DECL_THREADPRIVATE_P (v) = 1;
8172 c_parser_skip_to_pragma_eol (parser);
8176 /* Parse a single source file. */
8181 /* Use local storage to begin. If the first token is a pragma, parse it.
8182 If it is #pragma GCC pch_preprocess, then this will load a PCH file
8183 which will cause garbage collection. */
8186 memset (&tparser, 0, sizeof tparser);
8187 the_parser = &tparser;
8189 if (c_parser_peek_token (&tparser)->pragma_kind == PRAGMA_GCC_PCH_PREPROCESS)
8190 c_parser_pragma_pch_preprocess (&tparser);
8192 the_parser = GGC_NEW (c_parser);
8193 *the_parser = tparser;
8195 c_parser_translation_unit (the_parser);
8199 #include "gt-c-parser.h"