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 (OPT_pedantic, "%HISO C forbids an empty translation unit",
971 &c_parser_peek_token (parser)->location);
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 (OPT_pedantic,
1056 "%HISO C does not allow extra %<;%> outside of a function",
1057 &c_parser_peek_token (parser)->location);
1058 c_parser_consume_token (parser);
1061 c_parser_pragma (parser, pragma_external);
1065 if (c_dialect_objc ())
1067 c_parser_objc_method_definition (parser);
1070 /* Else fall through, and yield a syntax error trying to parse
1071 as a declaration or function definition. */
1074 /* A declaration or a function definition. We can only tell
1075 which after parsing the declaration specifiers, if any, and
1076 the first declarator. */
1077 c_parser_declaration_or_fndef (parser, true, true, false, true);
1083 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1084 6.7, 6.9.1). If FNDEF_OK is true, a function definition is
1085 accepted; otherwise (old-style parameter declarations) only other
1086 declarations are accepted. If NESTED is true, we are inside a
1087 function or parsing old-style parameter declarations; any functions
1088 encountered are nested functions and declaration specifiers are
1089 required; otherwise we are at top level and functions are normal
1090 functions and declaration specifiers may be optional. If EMPTY_OK
1091 is true, empty declarations are OK (subject to all other
1092 constraints); otherwise (old-style parameter declarations) they are
1093 diagnosed. If START_ATTR_OK is true, the declaration specifiers
1094 may start with attributes; otherwise they may not.
1097 declaration-specifiers init-declarator-list[opt] ;
1099 function-definition:
1100 declaration-specifiers[opt] declarator declaration-list[opt]
1105 declaration-list declaration
1107 init-declarator-list:
1109 init-declarator-list , init-declarator
1112 declarator simple-asm-expr[opt] attributes[opt]
1113 declarator simple-asm-expr[opt] attributes[opt] = initializer
1117 nested-function-definition:
1118 declaration-specifiers declarator declaration-list[opt]
1121 The simple-asm-expr and attributes are GNU extensions.
1123 This function does not handle __extension__; that is handled in its
1124 callers. ??? Following the old parser, __extension__ may start
1125 external declarations, declarations in functions and declarations
1126 at the start of "for" loops, but not old-style parameter
1129 C99 requires declaration specifiers in a function definition; the
1130 absence is diagnosed through the diagnosis of implicit int. In GNU
1131 C we also allow but diagnose declarations without declaration
1132 specifiers, but only at top level (elsewhere they conflict with
1138 threadprivate-directive */
1141 c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok, bool empty_ok,
1142 bool nested, bool start_attr_ok)
1144 struct c_declspecs *specs;
1146 tree all_prefix_attrs;
1147 bool diagnosed_no_specs = false;
1148 location_t here = c_parser_peek_token (parser)->location;
1150 specs = build_null_declspecs ();
1151 c_parser_declspecs (parser, specs, true, true, start_attr_ok);
1154 c_parser_skip_to_end_of_block_or_statement (parser);
1157 if (nested && !specs->declspecs_seen_p)
1159 c_parser_error (parser, "expected declaration specifiers");
1160 c_parser_skip_to_end_of_block_or_statement (parser);
1163 finish_declspecs (specs);
1164 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1170 shadow_tag_warned (specs, 1);
1171 pedwarn (0, "%Hempty declaration", &here);
1173 c_parser_consume_token (parser);
1176 pending_xref_error ();
1177 prefix_attrs = specs->attrs;
1178 all_prefix_attrs = prefix_attrs;
1179 specs->attrs = NULL_TREE;
1182 struct c_declarator *declarator;
1185 /* Declaring either one or more declarators (in which case we
1186 should diagnose if there were no declaration specifiers) or a
1187 function definition (in which case the diagnostic for
1188 implicit int suffices). */
1189 declarator = c_parser_declarator (parser, specs->type_seen_p,
1190 C_DTR_NORMAL, &dummy);
1191 if (declarator == NULL)
1193 c_parser_skip_to_end_of_block_or_statement (parser);
1196 if (c_parser_next_token_is (parser, CPP_EQ)
1197 || c_parser_next_token_is (parser, CPP_COMMA)
1198 || c_parser_next_token_is (parser, CPP_SEMICOLON)
1199 || c_parser_next_token_is_keyword (parser, RID_ASM)
1200 || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1202 tree asm_name = NULL_TREE;
1203 tree postfix_attrs = NULL_TREE;
1204 if (!diagnosed_no_specs && !specs->declspecs_seen_p)
1206 diagnosed_no_specs = true;
1207 pedwarn (0, "%Hdata definition has no type or storage class",
1210 /* Having seen a data definition, there cannot now be a
1211 function definition. */
1213 if (c_parser_next_token_is_keyword (parser, RID_ASM))
1214 asm_name = c_parser_simple_asm_expr (parser);
1215 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1216 postfix_attrs = c_parser_attributes (parser);
1217 if (c_parser_next_token_is (parser, CPP_EQ))
1221 c_parser_consume_token (parser);
1222 /* The declaration of the variable is in effect while
1223 its initializer is parsed. */
1224 d = start_decl (declarator, specs, true,
1225 chainon (postfix_attrs, all_prefix_attrs));
1227 d = error_mark_node;
1228 start_init (d, asm_name, global_bindings_p ());
1229 init = c_parser_initializer (parser);
1231 if (d != error_mark_node)
1233 maybe_warn_string_init (TREE_TYPE (d), init);
1234 finish_decl (d, init.value, asm_name);
1239 tree d = start_decl (declarator, specs, false,
1240 chainon (postfix_attrs,
1243 finish_decl (d, NULL_TREE, asm_name);
1245 if (c_parser_next_token_is (parser, CPP_COMMA))
1247 c_parser_consume_token (parser);
1248 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1249 all_prefix_attrs = chainon (c_parser_attributes (parser),
1252 all_prefix_attrs = prefix_attrs;
1255 else if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1257 c_parser_consume_token (parser);
1262 c_parser_error (parser, "expected %<,%> or %<;%>");
1263 c_parser_skip_to_end_of_block_or_statement (parser);
1269 c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, "
1270 "%<asm%> or %<__attribute__%>");
1271 c_parser_skip_to_end_of_block_or_statement (parser);
1274 /* Function definition (nested or otherwise). */
1277 pedwarn (OPT_pedantic, "%HISO C forbids nested functions", &here);
1278 c_push_function_context ();
1280 if (!start_function (specs, declarator, all_prefix_attrs))
1282 /* This can appear in many cases looking nothing like a
1283 function definition, so we don't give a more specific
1284 error suggesting there was one. */
1285 c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
1286 "or %<__attribute__%>");
1288 c_pop_function_context ();
1291 /* Parse old-style parameter declarations. ??? Attributes are
1292 not allowed to start declaration specifiers here because of a
1293 syntax conflict between a function declaration with attribute
1294 suffix and a function definition with an attribute prefix on
1295 first old-style parameter declaration. Following the old
1296 parser, they are not accepted on subsequent old-style
1297 parameter declarations either. However, there is no
1298 ambiguity after the first declaration, nor indeed on the
1299 first as long as we don't allow postfix attributes after a
1300 declarator with a nonempty identifier list in a definition;
1301 and postfix attributes have never been accepted here in
1302 function definitions either. */
1303 while (c_parser_next_token_is_not (parser, CPP_EOF)
1304 && c_parser_next_token_is_not (parser, CPP_OPEN_BRACE))
1305 c_parser_declaration_or_fndef (parser, false, false, true, false);
1306 DECL_SOURCE_LOCATION (current_function_decl)
1307 = c_parser_peek_token (parser)->location;
1308 store_parm_decls ();
1309 fnbody = c_parser_compound_statement (parser);
1312 tree decl = current_function_decl;
1315 c_pop_function_context ();
1316 add_stmt (build_stmt (DECL_EXPR, decl));
1327 /* Parse an asm-definition (asm() outside a function body). This is a
1335 c_parser_asm_definition (c_parser *parser)
1337 tree asm_str = c_parser_simple_asm_expr (parser);
1339 cgraph_add_asm_node (asm_str);
1340 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
1343 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
1344 6.7), adding them to SPECS (which may already include some).
1345 Storage class specifiers are accepted iff SCSPEC_OK; type
1346 specifiers are accepted iff TYPESPEC_OK; attributes are accepted at
1347 the start iff START_ATTR_OK.
1349 declaration-specifiers:
1350 storage-class-specifier declaration-specifiers[opt]
1351 type-specifier declaration-specifiers[opt]
1352 type-qualifier declaration-specifiers[opt]
1353 function-specifier declaration-specifiers[opt]
1355 Function specifiers (inline) are from C99, and are currently
1356 handled as storage class specifiers, as is __thread.
1358 C90 6.5.1, C99 6.7.1:
1359 storage-class-specifier:
1370 C90 6.5.2, C99 6.7.2:
1383 [_Imaginary removed in C99 TC2]
1384 struct-or-union-specifier
1388 (_Bool and _Complex are new in C99.)
1390 C90 6.5.3, C99 6.7.3:
1397 (restrict is new in C99.)
1401 declaration-specifiers:
1402 attributes declaration-specifiers[opt]
1404 storage-class-specifier:
1416 (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
1417 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
1422 class-name objc-protocol-refs[opt]
1423 typedef-name objc-protocol-refs
1428 c_parser_declspecs (c_parser *parser, struct c_declspecs *specs,
1429 bool scspec_ok, bool typespec_ok, bool start_attr_ok)
1431 bool attrs_ok = start_attr_ok;
1432 bool seen_type = specs->type_seen_p;
1433 while (c_parser_next_token_is (parser, CPP_NAME)
1434 || c_parser_next_token_is (parser, CPP_KEYWORD)
1435 || (c_dialect_objc () && c_parser_next_token_is (parser, CPP_LESS)))
1437 struct c_typespec t;
1439 if (c_parser_next_token_is (parser, CPP_NAME))
1441 tree value = c_parser_peek_token (parser)->value;
1442 c_id_kind kind = c_parser_peek_token (parser)->id_kind;
1443 /* This finishes the specifiers unless a type name is OK, it
1444 is declared as a type name and a type name hasn't yet
1446 if (!typespec_ok || seen_type
1447 || (kind != C_ID_TYPENAME && kind != C_ID_CLASSNAME))
1449 c_parser_consume_token (parser);
1452 if (kind == C_ID_TYPENAME
1453 && (!c_dialect_objc ()
1454 || c_parser_next_token_is_not (parser, CPP_LESS)))
1456 t.kind = ctsk_typedef;
1457 /* For a typedef name, record the meaning, not the name.
1458 In case of 'foo foo, bar;'. */
1459 t.spec = lookup_name (value);
1463 tree proto = NULL_TREE;
1464 gcc_assert (c_dialect_objc ());
1466 if (c_parser_next_token_is (parser, CPP_LESS))
1467 proto = c_parser_objc_protocol_refs (parser);
1468 t.spec = objc_get_protocol_qualified_type (value, proto);
1470 declspecs_add_type (specs, t);
1473 if (c_parser_next_token_is (parser, CPP_LESS))
1475 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
1476 nisse@lysator.liu.se. */
1478 gcc_assert (c_dialect_objc ());
1479 if (!typespec_ok || seen_type)
1481 proto = c_parser_objc_protocol_refs (parser);
1483 t.spec = objc_get_protocol_qualified_type (NULL_TREE, proto);
1484 declspecs_add_type (specs, t);
1487 gcc_assert (c_parser_next_token_is (parser, CPP_KEYWORD));
1488 switch (c_parser_peek_token (parser)->keyword)
1500 /* TODO: Distinguish between function specifiers (inline)
1501 and storage class specifiers, either here or in
1502 declspecs_add_scspec. */
1503 declspecs_add_scspec (specs, c_parser_peek_token (parser)->value);
1504 c_parser_consume_token (parser);
1527 if (c_dialect_objc ())
1528 parser->objc_need_raw_identifier = true;
1529 t.kind = ctsk_resword;
1530 t.spec = c_parser_peek_token (parser)->value;
1531 declspecs_add_type (specs, t);
1532 c_parser_consume_token (parser);
1539 t = c_parser_enum_specifier (parser);
1540 declspecs_add_type (specs, t);
1548 t = c_parser_struct_or_union_specifier (parser);
1549 declspecs_add_type (specs, t);
1552 /* ??? The old parser rejected typeof after other type
1553 specifiers, but is a syntax error the best way of
1555 if (!typespec_ok || seen_type)
1559 t = c_parser_typeof_specifier (parser);
1560 declspecs_add_type (specs, t);
1566 declspecs_add_qual (specs, c_parser_peek_token (parser)->value);
1567 c_parser_consume_token (parser);
1572 attrs = c_parser_attributes (parser);
1573 declspecs_add_attrs (specs, attrs);
1582 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
1585 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
1586 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
1587 enum attributes[opt] identifier
1589 The form with trailing comma is new in C99. The forms with
1590 attributes are GNU extensions. In GNU C, we accept any expression
1591 without commas in the syntax (assignment expressions, not just
1592 conditional expressions); assignment expressions will be diagnosed
1597 enumerator-list , enumerator
1600 enumeration-constant
1601 enumeration-constant = constant-expression
1604 static struct c_typespec
1605 c_parser_enum_specifier (c_parser *parser)
1607 struct c_typespec ret;
1609 tree ident = NULL_TREE;
1610 location_t ident_loc;
1611 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ENUM));
1612 c_parser_consume_token (parser);
1613 attrs = c_parser_attributes (parser);
1614 /* Set the location in case we create a decl now. */
1615 c_parser_set_source_position_from_token (c_parser_peek_token (parser));
1616 if (c_parser_next_token_is (parser, CPP_NAME))
1618 ident = c_parser_peek_token (parser)->value;
1619 ident_loc = c_parser_peek_token (parser)->location;
1620 c_parser_consume_token (parser);
1622 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
1624 /* Parse an enum definition. */
1625 struct c_enum_contents the_enum;
1626 tree type = start_enum (&the_enum, ident);
1628 /* We chain the enumerators in reverse order, then put them in
1629 forward order at the end. */
1630 tree values = NULL_TREE;
1631 c_parser_consume_token (parser);
1639 location_t comma_loc;
1640 location_t value_loc;
1641 if (c_parser_next_token_is_not (parser, CPP_NAME))
1643 c_parser_error (parser, "expected identifier");
1644 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
1645 values = error_mark_node;
1648 token = c_parser_peek_token (parser);
1649 enum_id = token->value;
1650 /* Set the location in case we create a decl now. */
1651 c_parser_set_source_position_from_token (token);
1652 value_loc = token->location;
1653 c_parser_consume_token (parser);
1654 if (c_parser_next_token_is (parser, CPP_EQ))
1656 c_parser_consume_token (parser);
1657 value_loc = c_parser_peek_token (parser)->location;
1658 /* This may call cb_line_change and alter the input_location. */
1659 enum_value = c_parser_expr_no_commas (parser, NULL).value;
1662 enum_value = NULL_TREE;
1663 enum_decl = build_enumerator (&the_enum, enum_id, enum_value,
1665 TREE_CHAIN (enum_decl) = values;
1668 if (c_parser_next_token_is (parser, CPP_COMMA))
1670 comma_loc = c_parser_peek_token (parser)->location;
1672 c_parser_consume_token (parser);
1674 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
1676 if (seen_comma && !flag_isoc99)
1677 pedwarn (OPT_pedantic, "%Hcomma at end of enumerator list",
1679 c_parser_consume_token (parser);
1684 c_parser_error (parser, "expected %<,%> or %<}%>");
1685 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
1686 values = error_mark_node;
1690 postfix_attrs = c_parser_attributes (parser);
1691 ret.spec = finish_enum (type, nreverse (values),
1692 chainon (attrs, postfix_attrs));
1693 ret.kind = ctsk_tagdef;
1698 c_parser_error (parser, "expected %<{%>");
1699 ret.spec = error_mark_node;
1700 ret.kind = ctsk_tagref;
1703 ret = parser_xref_tag (ENUMERAL_TYPE, ident);
1704 /* In ISO C, enumerated types can be referred to only if already
1706 if (pedantic && !COMPLETE_TYPE_P (ret.spec))
1709 pedwarn (OPT_pedantic,
1710 "%HISO C forbids forward references to %<enum%> types",
1716 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
1718 struct-or-union-specifier:
1719 struct-or-union attributes[opt] identifier[opt]
1720 { struct-contents } attributes[opt]
1721 struct-or-union attributes[opt] identifier
1724 struct-declaration-list
1726 struct-declaration-list:
1727 struct-declaration ;
1728 struct-declaration-list struct-declaration ;
1735 struct-declaration-list struct-declaration
1737 struct-declaration-list:
1738 struct-declaration-list ;
1741 (Note that in the syntax here, unlike that in ISO C, the semicolons
1742 are included here rather than in struct-declaration, in order to
1743 describe the syntax with extra semicolons and missing semicolon at
1748 struct-declaration-list:
1749 @defs ( class-name )
1751 (Note this does not include a trailing semicolon, but can be
1752 followed by further declarations, and gets a pedwarn-if-pedantic
1753 when followed by a semicolon.) */
1755 static struct c_typespec
1756 c_parser_struct_or_union_specifier (c_parser *parser)
1758 struct c_typespec ret;
1760 tree ident = NULL_TREE;
1761 enum tree_code code;
1762 switch (c_parser_peek_token (parser)->keyword)
1773 c_parser_consume_token (parser);
1774 attrs = c_parser_attributes (parser);
1775 /* Set the location in case we create a decl now. */
1776 c_parser_set_source_position_from_token (c_parser_peek_token (parser));
1777 if (c_parser_next_token_is (parser, CPP_NAME))
1779 ident = c_parser_peek_token (parser)->value;
1780 c_parser_consume_token (parser);
1782 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
1784 /* Parse a struct or union definition. Start the scope of the
1785 tag before parsing components. */
1786 tree type = start_struct (code, ident);
1788 /* We chain the components in reverse order, then put them in
1789 forward order at the end. Each struct-declaration may
1790 declare multiple components (comma-separated), so we must use
1791 chainon to join them, although when parsing each
1792 struct-declaration we can use TREE_CHAIN directly.
1794 The theory behind all this is that there will be more
1795 semicolon separated fields than comma separated fields, and
1796 so we'll be minimizing the number of node traversals required
1798 tree contents = NULL_TREE;
1799 c_parser_consume_token (parser);
1800 /* Handle the Objective-C @defs construct,
1801 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
1802 if (c_parser_next_token_is_keyword (parser, RID_AT_DEFS))
1805 gcc_assert (c_dialect_objc ());
1806 c_parser_consume_token (parser);
1807 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
1809 if (c_parser_next_token_is (parser, CPP_NAME)
1810 && c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME)
1812 name = c_parser_peek_token (parser)->value;
1813 c_parser_consume_token (parser);
1817 c_parser_error (parser, "expected class name");
1818 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
1821 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
1823 contents = nreverse (objc_get_class_ivars (name));
1826 /* Parse the struct-declarations and semicolons. Problems with
1827 semicolons are diagnosed here; empty structures are diagnosed
1832 /* Parse any stray semicolon. */
1833 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1835 pedwarn (OPT_pedantic,
1836 "%Hextra semicolon in struct or union specified",
1837 &c_parser_peek_token (parser)->location);
1838 c_parser_consume_token (parser);
1841 /* Stop if at the end of the struct or union contents. */
1842 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
1844 c_parser_consume_token (parser);
1847 /* Accept #pragmas at struct scope. */
1848 if (c_parser_next_token_is (parser, CPP_PRAGMA))
1850 c_parser_pragma (parser, pragma_external);
1853 /* Parse some comma-separated declarations, but not the
1854 trailing semicolon if any. */
1855 decls = c_parser_struct_declaration (parser);
1856 contents = chainon (decls, contents);
1857 /* If no semicolon follows, either we have a parse error or
1858 are at the end of the struct or union and should
1860 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1861 c_parser_consume_token (parser);
1864 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
1865 pedwarn (0, "%Hno semicolon at end of struct or union",
1866 &c_parser_peek_token (parser)->location);
1869 c_parser_error (parser, "expected %<;%>");
1870 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
1875 postfix_attrs = c_parser_attributes (parser);
1876 ret.spec = finish_struct (type, nreverse (contents),
1877 chainon (attrs, postfix_attrs));
1878 ret.kind = ctsk_tagdef;
1883 c_parser_error (parser, "expected %<{%>");
1884 ret.spec = error_mark_node;
1885 ret.kind = ctsk_tagref;
1888 ret = parser_xref_tag (code, ident);
1892 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
1893 the trailing semicolon.
1896 specifier-qualifier-list struct-declarator-list
1898 specifier-qualifier-list:
1899 type-specifier specifier-qualifier-list[opt]
1900 type-qualifier specifier-qualifier-list[opt]
1901 attributes specifier-qualifier-list[opt]
1903 struct-declarator-list:
1905 struct-declarator-list , attributes[opt] struct-declarator
1908 declarator attributes[opt]
1909 declarator[opt] : constant-expression attributes[opt]
1914 __extension__ struct-declaration
1915 specifier-qualifier-list
1917 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
1918 of attributes where shown is a GNU extension. In GNU C, we accept
1919 any expression without commas in the syntax (assignment
1920 expressions, not just conditional expressions); assignment
1921 expressions will be diagnosed as non-constant. */
1924 c_parser_struct_declaration (c_parser *parser)
1926 struct c_declspecs *specs;
1928 tree all_prefix_attrs;
1930 location_t decl_loc;
1931 if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
1935 ext = disable_extension_diagnostics ();
1936 c_parser_consume_token (parser);
1937 decl = c_parser_struct_declaration (parser);
1938 restore_extension_diagnostics (ext);
1941 specs = build_null_declspecs ();
1942 decl_loc = c_parser_peek_token (parser)->location;
1943 c_parser_declspecs (parser, specs, false, true, true);
1946 if (!specs->declspecs_seen_p)
1948 c_parser_error (parser, "expected specifier-qualifier-list");
1951 finish_declspecs (specs);
1952 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1955 if (!specs->type_seen_p)
1957 pedwarn (OPT_pedantic,
1958 "%HISO C forbids member declarations with no members",
1960 shadow_tag_warned (specs, pedantic);
1965 /* Support for unnamed structs or unions as members of
1966 structs or unions (which is [a] useful and [b] supports
1969 ret = grokfield (build_id_declarator (NULL_TREE), specs,
1972 decl_attributes (&ret, attrs, 0);
1976 pending_xref_error ();
1977 prefix_attrs = specs->attrs;
1978 all_prefix_attrs = prefix_attrs;
1979 specs->attrs = NULL_TREE;
1983 /* Declaring one or more declarators or un-named bit-fields. */
1984 struct c_declarator *declarator;
1986 if (c_parser_next_token_is (parser, CPP_COLON))
1987 declarator = build_id_declarator (NULL_TREE);
1989 declarator = c_parser_declarator (parser, specs->type_seen_p,
1990 C_DTR_NORMAL, &dummy);
1991 if (declarator == NULL)
1993 c_parser_skip_to_end_of_block_or_statement (parser);
1996 if (c_parser_next_token_is (parser, CPP_COLON)
1997 || c_parser_next_token_is (parser, CPP_COMMA)
1998 || c_parser_next_token_is (parser, CPP_SEMICOLON)
1999 || c_parser_next_token_is (parser, CPP_CLOSE_BRACE)
2000 || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2002 tree postfix_attrs = NULL_TREE;
2003 tree width = NULL_TREE;
2005 if (c_parser_next_token_is (parser, CPP_COLON))
2007 c_parser_consume_token (parser);
2008 width = c_parser_expr_no_commas (parser, NULL).value;
2010 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2011 postfix_attrs = c_parser_attributes (parser);
2012 d = grokfield (declarator, specs, width, &all_prefix_attrs);
2013 decl_attributes (&d, chainon (postfix_attrs,
2014 all_prefix_attrs), 0);
2015 TREE_CHAIN (d) = decls;
2017 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2018 all_prefix_attrs = chainon (c_parser_attributes (parser),
2021 all_prefix_attrs = prefix_attrs;
2022 if (c_parser_next_token_is (parser, CPP_COMMA))
2023 c_parser_consume_token (parser);
2024 else if (c_parser_next_token_is (parser, CPP_SEMICOLON)
2025 || c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2027 /* Semicolon consumed in caller. */
2032 c_parser_error (parser, "expected %<,%>, %<;%> or %<}%>");
2038 c_parser_error (parser,
2039 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
2040 "%<__attribute__%>");
2047 /* Parse a typeof specifier (a GNU extension).
2050 typeof ( expression )
2051 typeof ( type-name )
2054 static struct c_typespec
2055 c_parser_typeof_specifier (c_parser *parser)
2057 struct c_typespec ret;
2058 ret.kind = ctsk_typeof;
2059 ret.spec = error_mark_node;
2060 gcc_assert (c_parser_next_token_is_keyword (parser, RID_TYPEOF));
2061 c_parser_consume_token (parser);
2064 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2070 if (c_parser_next_token_starts_typename (parser))
2072 struct c_type_name *type = c_parser_type_name (parser);
2077 ret.spec = groktypename (type);
2078 pop_maybe_used (variably_modified_type_p (ret.spec, NULL_TREE));
2084 location_t here = c_parser_peek_token (parser)->location;
2085 struct c_expr expr = c_parser_expression (parser);
2088 if (TREE_CODE (expr.value) == COMPONENT_REF
2089 && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
2090 error ("%H%<typeof%> applied to a bit-field", &here);
2091 ret.spec = TREE_TYPE (expr.value);
2092 was_vm = variably_modified_type_p (ret.spec, NULL_TREE);
2093 /* This should be returned with the type so that when the type
2094 is evaluated, this can be evaluated. For now, we avoid
2095 evaluation when the context might. */
2096 if (!skip_evaluation && was_vm)
2098 tree e = expr.value;
2100 /* If the expression is not of a type to which we cannot assign a line
2101 number, wrap the thing in a no-op NOP_EXPR. */
2102 if (DECL_P (e) || CONSTANT_CLASS_P (e))
2103 e = build1 (NOP_EXPR, void_type_node, e);
2105 if (CAN_HAVE_LOCATION_P (e))
2106 SET_EXPR_LOCATION (e, input_location);
2110 pop_maybe_used (was_vm);
2112 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
2116 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
2117 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
2118 be redeclared; otherwise it may not. KIND indicates which kind of
2119 declarator is wanted. Returns a valid declarator except in the
2120 case of a syntax error in which case NULL is returned. *SEEN_ID is
2121 set to true if an identifier being declared is seen; this is used
2122 to diagnose bad forms of abstract array declarators and to
2123 determine whether an identifier list is syntactically permitted.
2126 pointer[opt] direct-declarator
2130 ( attributes[opt] declarator )
2131 direct-declarator array-declarator
2132 direct-declarator ( parameter-type-list )
2133 direct-declarator ( identifier-list[opt] )
2136 * type-qualifier-list[opt]
2137 * type-qualifier-list[opt] pointer
2139 type-qualifier-list:
2142 type-qualifier-list type-qualifier
2143 type-qualifier-list attributes
2145 parameter-type-list:
2147 parameter-list , ...
2150 parameter-declaration
2151 parameter-list , parameter-declaration
2153 parameter-declaration:
2154 declaration-specifiers declarator attributes[opt]
2155 declaration-specifiers abstract-declarator[opt] attributes[opt]
2159 identifier-list , identifier
2161 abstract-declarator:
2163 pointer[opt] direct-abstract-declarator
2165 direct-abstract-declarator:
2166 ( attributes[opt] abstract-declarator )
2167 direct-abstract-declarator[opt] array-declarator
2168 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
2173 direct-declarator ( parameter-forward-declarations
2174 parameter-type-list[opt] )
2176 direct-abstract-declarator:
2177 direct-abstract-declarator[opt] ( parameter-forward-declarations
2178 parameter-type-list[opt] )
2180 parameter-forward-declarations:
2182 parameter-forward-declarations parameter-list ;
2184 The uses of attributes shown above are GNU extensions.
2186 Some forms of array declarator are not included in C99 in the
2187 syntax for abstract declarators; these are disallowed elsewhere.
2188 This may be a defect (DR#289).
2190 This function also accepts an omitted abstract declarator as being
2191 an abstract declarator, although not part of the formal syntax. */
2193 static struct c_declarator *
2194 c_parser_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
2197 /* Parse any initial pointer part. */
2198 if (c_parser_next_token_is (parser, CPP_MULT))
2200 struct c_declspecs *quals_attrs = build_null_declspecs ();
2201 struct c_declarator *inner;
2202 c_parser_consume_token (parser);
2203 c_parser_declspecs (parser, quals_attrs, false, false, true);
2204 inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
2208 return make_pointer_declarator (quals_attrs, inner);
2210 /* Now we have a direct declarator, direct abstract declarator or
2211 nothing (which counts as a direct abstract declarator here). */
2212 return c_parser_direct_declarator (parser, type_seen_p, kind, seen_id);
2215 /* Parse a direct declarator or direct abstract declarator; arguments
2216 as c_parser_declarator. */
2218 static struct c_declarator *
2219 c_parser_direct_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
2222 /* The direct declarator must start with an identifier (possibly
2223 omitted) or a parenthesized declarator (possibly abstract). In
2224 an ordinary declarator, initial parentheses must start a
2225 parenthesized declarator. In an abstract declarator or parameter
2226 declarator, they could start a parenthesized declarator or a
2227 parameter list. To tell which, the open parenthesis and any
2228 following attributes must be read. If a declaration specifier
2229 follows, then it is a parameter list; if the specifier is a
2230 typedef name, there might be an ambiguity about redeclaring it,
2231 which is resolved in the direction of treating it as a typedef
2232 name. If a close parenthesis follows, it is also an empty
2233 parameter list, as the syntax does not permit empty abstract
2234 declarators. Otherwise, it is a parenthesized declarator (in
2235 which case the analysis may be repeated inside it, recursively).
2237 ??? There is an ambiguity in a parameter declaration "int
2238 (__attribute__((foo)) x)", where x is not a typedef name: it
2239 could be an abstract declarator for a function, or declare x with
2240 parentheses. The proper resolution of this ambiguity needs
2241 documenting. At present we follow an accident of the old
2242 parser's implementation, whereby the first parameter must have
2243 some declaration specifiers other than just attributes. Thus as
2244 a parameter declaration it is treated as a parenthesized
2245 parameter named x, and as an abstract declarator it is
2248 ??? Also following the old parser, attributes inside an empty
2249 parameter list are ignored, making it a list not yielding a
2250 prototype, rather than giving an error or making it have one
2251 parameter with implicit type int.
2253 ??? Also following the old parser, typedef names may be
2254 redeclared in declarators, but not Objective-C class names. */
2256 if (kind != C_DTR_ABSTRACT
2257 && c_parser_next_token_is (parser, CPP_NAME)
2259 && c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME)
2260 || c_parser_peek_token (parser)->id_kind == C_ID_ID))
2262 struct c_declarator *inner
2263 = build_id_declarator (c_parser_peek_token (parser)->value);
2265 inner->id_loc = c_parser_peek_token (parser)->location;
2266 c_parser_consume_token (parser);
2267 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2270 if (kind != C_DTR_NORMAL
2271 && c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
2273 struct c_declarator *inner = build_id_declarator (NULL_TREE);
2274 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2277 /* Either we are at the end of an abstract declarator, or we have
2280 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
2283 struct c_declarator *inner;
2284 c_parser_consume_token (parser);
2285 attrs = c_parser_attributes (parser);
2286 if (kind != C_DTR_NORMAL
2287 && (c_parser_next_token_starts_declspecs (parser)
2288 || c_parser_next_token_is (parser, CPP_CLOSE_PAREN)))
2290 struct c_arg_info *args
2291 = c_parser_parms_declarator (parser, kind == C_DTR_NORMAL,
2298 = build_function_declarator (args,
2299 build_id_declarator (NULL_TREE));
2300 return c_parser_direct_declarator_inner (parser, *seen_id,
2304 /* A parenthesized declarator. */
2305 inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
2306 if (inner != NULL && attrs != NULL)
2307 inner = build_attrs_declarator (attrs, inner);
2308 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2310 c_parser_consume_token (parser);
2314 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2318 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2325 if (kind == C_DTR_NORMAL)
2327 c_parser_error (parser, "expected identifier or %<(%>");
2331 return build_id_declarator (NULL_TREE);
2335 /* Parse part of a direct declarator or direct abstract declarator,
2336 given that some (in INNER) has already been parsed; ID_PRESENT is
2337 true if an identifier is present, false for an abstract
2340 static struct c_declarator *
2341 c_parser_direct_declarator_inner (c_parser *parser, bool id_present,
2342 struct c_declarator *inner)
2344 /* Parse a sequence of array declarators and parameter lists. */
2345 if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
2347 struct c_declarator *declarator;
2348 struct c_declspecs *quals_attrs = build_null_declspecs ();
2352 c_parser_consume_token (parser);
2353 c_parser_declspecs (parser, quals_attrs, false, false, true);
2354 static_seen = c_parser_next_token_is_keyword (parser, RID_STATIC);
2356 c_parser_consume_token (parser);
2357 if (static_seen && !quals_attrs->declspecs_seen_p)
2358 c_parser_declspecs (parser, quals_attrs, false, false, true);
2359 if (!quals_attrs->declspecs_seen_p)
2361 /* If "static" is present, there must be an array dimension.
2362 Otherwise, there may be a dimension, "*", or no
2367 dimen = c_parser_expr_no_commas (parser, NULL).value;
2371 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
2376 else if (c_parser_next_token_is (parser, CPP_MULT))
2378 if (c_parser_peek_2nd_token (parser)->type == CPP_CLOSE_SQUARE)
2382 c_parser_consume_token (parser);
2387 dimen = c_parser_expr_no_commas (parser, NULL).value;
2393 dimen = c_parser_expr_no_commas (parser, NULL).value;
2396 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
2397 c_parser_consume_token (parser);
2400 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
2404 declarator = build_array_declarator (dimen, quals_attrs, static_seen,
2406 if (declarator == NULL)
2408 inner = set_array_declarator_inner (declarator, inner);
2409 return c_parser_direct_declarator_inner (parser, id_present, inner);
2411 else if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
2414 struct c_arg_info *args;
2415 c_parser_consume_token (parser);
2416 attrs = c_parser_attributes (parser);
2417 args = c_parser_parms_declarator (parser, id_present, attrs);
2422 inner = build_function_declarator (args, inner);
2423 return c_parser_direct_declarator_inner (parser, id_present, inner);
2429 /* Parse a parameter list or identifier list, including the closing
2430 parenthesis but not the opening one. ATTRS are the attributes at
2431 the start of the list. ID_LIST_OK is true if an identifier list is
2432 acceptable; such a list must not have attributes at the start. */
2434 static struct c_arg_info *
2435 c_parser_parms_declarator (c_parser *parser, bool id_list_ok, tree attrs)
2438 declare_parm_level ();
2439 /* If the list starts with an identifier, it is an identifier list.
2440 Otherwise, it is either a prototype list or an empty list. */
2443 && c_parser_next_token_is (parser, CPP_NAME)
2444 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
2446 tree list = NULL_TREE, *nextp = &list;
2447 while (c_parser_next_token_is (parser, CPP_NAME)
2448 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
2450 *nextp = build_tree_list (NULL_TREE,
2451 c_parser_peek_token (parser)->value);
2452 nextp = & TREE_CHAIN (*nextp);
2453 c_parser_consume_token (parser);
2454 if (c_parser_next_token_is_not (parser, CPP_COMMA))
2456 c_parser_consume_token (parser);
2457 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2459 c_parser_error (parser, "expected identifier");
2463 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2465 struct c_arg_info *ret = XOBNEW (&parser_obstack, struct c_arg_info);
2470 ret->pending_sizes = 0;
2471 ret->had_vla_unspec = 0;
2472 c_parser_consume_token (parser);
2478 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2486 struct c_arg_info *ret = c_parser_parms_list_declarator (parser, attrs);
2492 /* Parse a parameter list (possibly empty), including the closing
2493 parenthesis but not the opening one. ATTRS are the attributes at
2494 the start of the list. */
2496 static struct c_arg_info *
2497 c_parser_parms_list_declarator (c_parser *parser, tree attrs)
2499 bool good_parm = false;
2500 /* ??? Following the old parser, forward parameter declarations may
2501 use abstract declarators, and if no real parameter declarations
2502 follow the forward declarations then this is not diagnosed. Also
2503 note as above that attributes are ignored as the only contents of
2504 the parentheses, or as the only contents after forward
2506 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2508 struct c_arg_info *ret = XOBNEW (&parser_obstack, struct c_arg_info);
2513 ret->pending_sizes = 0;
2514 ret->had_vla_unspec = 0;
2515 c_parser_consume_token (parser);
2518 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
2520 struct c_arg_info *ret = XOBNEW (&parser_obstack, struct c_arg_info);
2524 ret->pending_sizes = 0;
2525 ret->had_vla_unspec = 0;
2526 /* Suppress -Wold-style-definition for this case. */
2527 ret->types = error_mark_node;
2528 error ("%HISO C requires a named argument before %<...%>",
2529 &c_parser_peek_token (parser)->location);
2530 c_parser_consume_token (parser);
2531 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2533 c_parser_consume_token (parser);
2538 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2543 /* Nonempty list of parameters, either terminated with semicolon
2544 (forward declarations; recurse) or with close parenthesis (normal
2545 function) or with ", ... )" (variadic function). */
2548 /* Parse a parameter. */
2549 struct c_parm *parm = c_parser_parameter_declaration (parser, attrs);
2554 push_parm_decl (parm);
2556 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
2559 c_parser_consume_token (parser);
2560 mark_forward_parm_decls ();
2561 new_attrs = c_parser_attributes (parser);
2562 return c_parser_parms_list_declarator (parser, new_attrs);
2564 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2566 c_parser_consume_token (parser);
2568 return get_parm_info (false);
2571 struct c_arg_info *ret
2572 = XOBNEW (&parser_obstack, struct c_arg_info);
2577 ret->pending_sizes = 0;
2578 ret->had_vla_unspec = 0;
2582 if (!c_parser_require (parser, CPP_COMMA,
2583 "expected %<;%>, %<,%> or %<)%>"))
2585 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
2588 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
2590 c_parser_consume_token (parser);
2591 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2593 c_parser_consume_token (parser);
2595 return get_parm_info (true);
2598 struct c_arg_info *ret
2599 = XOBNEW (&parser_obstack, struct c_arg_info);
2604 ret->pending_sizes = 0;
2605 ret->had_vla_unspec = 0;
2611 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2619 /* Parse a parameter declaration. ATTRS are the attributes at the
2620 start of the declaration if it is the first parameter. */
2622 static struct c_parm *
2623 c_parser_parameter_declaration (c_parser *parser, tree attrs)
2625 struct c_declspecs *specs;
2626 struct c_declarator *declarator;
2628 tree postfix_attrs = NULL_TREE;
2630 if (!c_parser_next_token_starts_declspecs (parser))
2632 /* ??? In some Objective-C cases '...' isn't applicable so there
2633 should be a different message. */
2634 c_parser_error (parser,
2635 "expected declaration specifiers or %<...%>");
2636 c_parser_skip_to_end_of_parameter (parser);
2639 specs = build_null_declspecs ();
2642 declspecs_add_attrs (specs, attrs);
2645 c_parser_declspecs (parser, specs, true, true, true);
2646 finish_declspecs (specs);
2647 pending_xref_error ();
2648 prefix_attrs = specs->attrs;
2649 specs->attrs = NULL_TREE;
2650 declarator = c_parser_declarator (parser, specs->type_seen_p,
2651 C_DTR_PARM, &dummy);
2652 if (declarator == NULL)
2654 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
2657 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2658 postfix_attrs = c_parser_attributes (parser);
2659 return build_c_parm (specs, chainon (postfix_attrs, prefix_attrs),
2663 /* Parse a string literal in an asm expression. It should not be
2664 translated, and wide string literals are an error although
2665 permitted by the syntax. This is a GNU extension.
2670 ??? At present, following the old parser, the caller needs to have
2671 set lex_untranslated_string to 1. It would be better to follow the
2672 C++ parser rather than using this kludge. */
2675 c_parser_asm_string_literal (c_parser *parser)
2678 if (c_parser_next_token_is (parser, CPP_STRING))
2680 str = c_parser_peek_token (parser)->value;
2681 c_parser_consume_token (parser);
2683 else if (c_parser_next_token_is (parser, CPP_WSTRING))
2685 error ("%Hwide string literal in %<asm%>",
2686 &c_parser_peek_token (parser)->location);
2687 str = build_string (1, "");
2688 c_parser_consume_token (parser);
2692 c_parser_error (parser, "expected string literal");
2698 /* Parse a simple asm expression. This is used in restricted
2699 contexts, where a full expression with inputs and outputs does not
2700 make sense. This is a GNU extension.
2703 asm ( asm-string-literal )
2707 c_parser_simple_asm_expr (c_parser *parser)
2710 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
2711 /* ??? Follow the C++ parser rather than using the
2712 lex_untranslated_string kludge. */
2713 parser->lex_untranslated_string = true;
2714 c_parser_consume_token (parser);
2715 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2717 parser->lex_untranslated_string = false;
2720 str = c_parser_asm_string_literal (parser);
2721 parser->lex_untranslated_string = false;
2722 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
2724 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
2730 /* Parse (possibly empty) attributes. This is a GNU extension.
2734 attributes attribute
2737 __attribute__ ( ( attribute-list ) )
2741 attribute_list , attrib
2746 any-word ( identifier )
2747 any-word ( identifier , nonempty-expr-list )
2748 any-word ( expr-list )
2750 where the "identifier" must not be declared as a type, and
2751 "any-word" may be any identifier (including one declared as a
2752 type), a reserved word storage class specifier, type specifier or
2753 type qualifier. ??? This still leaves out most reserved keywords
2754 (following the old parser), shouldn't we include them, and why not
2755 allow identifiers declared as types to start the arguments? */
2758 c_parser_attributes (c_parser *parser)
2760 tree attrs = NULL_TREE;
2761 while (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2763 /* ??? Follow the C++ parser rather than using the
2764 lex_untranslated_string kludge. */
2765 parser->lex_untranslated_string = true;
2766 c_parser_consume_token (parser);
2767 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2769 parser->lex_untranslated_string = false;
2772 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2774 parser->lex_untranslated_string = false;
2775 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
2778 /* Parse the attribute list. */
2779 while (c_parser_next_token_is (parser, CPP_COMMA)
2780 || c_parser_next_token_is (parser, CPP_NAME)
2781 || c_parser_next_token_is (parser, CPP_KEYWORD))
2783 tree attr, attr_name, attr_args;
2784 if (c_parser_next_token_is (parser, CPP_COMMA))
2786 c_parser_consume_token (parser);
2789 if (c_parser_next_token_is (parser, CPP_KEYWORD))
2791 /* ??? See comment above about what keywords are
2794 switch (c_parser_peek_token (parser)->keyword)
2832 attr_name = c_parser_peek_token (parser)->value;
2833 c_parser_consume_token (parser);
2834 if (c_parser_next_token_is_not (parser, CPP_OPEN_PAREN))
2836 attr = build_tree_list (attr_name, NULL_TREE);
2837 attrs = chainon (attrs, attr);
2840 c_parser_consume_token (parser);
2841 /* Parse the attribute contents. If they start with an
2842 identifier which is followed by a comma or close
2843 parenthesis, then the arguments start with that
2844 identifier; otherwise they are an expression list. */
2845 if (c_parser_next_token_is (parser, CPP_NAME)
2846 && c_parser_peek_token (parser)->id_kind == C_ID_ID
2847 && ((c_parser_peek_2nd_token (parser)->type == CPP_COMMA)
2848 || (c_parser_peek_2nd_token (parser)->type
2849 == CPP_CLOSE_PAREN)))
2851 tree arg1 = c_parser_peek_token (parser)->value;
2852 c_parser_consume_token (parser);
2853 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2854 attr_args = build_tree_list (NULL_TREE, arg1);
2857 c_parser_consume_token (parser);
2858 attr_args = tree_cons (NULL_TREE, arg1,
2859 c_parser_expr_list (parser, false));
2864 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2865 attr_args = NULL_TREE;
2867 attr_args = c_parser_expr_list (parser, false);
2869 attr = build_tree_list (attr_name, attr_args);
2870 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2871 c_parser_consume_token (parser);
2874 parser->lex_untranslated_string = false;
2875 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2879 attrs = chainon (attrs, attr);
2881 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2882 c_parser_consume_token (parser);
2885 parser->lex_untranslated_string = false;
2886 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2890 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2891 c_parser_consume_token (parser);
2894 parser->lex_untranslated_string = false;
2895 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2899 parser->lex_untranslated_string = false;
2904 /* Parse a type name (C90 6.5.5, C99 6.7.6).
2907 specifier-qualifier-list abstract-declarator[opt]
2910 static struct c_type_name *
2911 c_parser_type_name (c_parser *parser)
2913 struct c_declspecs *specs = build_null_declspecs ();
2914 struct c_declarator *declarator;
2915 struct c_type_name *ret;
2917 c_parser_declspecs (parser, specs, false, true, true);
2918 if (!specs->declspecs_seen_p)
2920 c_parser_error (parser, "expected specifier-qualifier-list");
2923 pending_xref_error ();
2924 finish_declspecs (specs);
2925 declarator = c_parser_declarator (parser, specs->type_seen_p,
2926 C_DTR_ABSTRACT, &dummy);
2927 if (declarator == NULL)
2929 ret = XOBNEW (&parser_obstack, struct c_type_name);
2931 ret->declarator = declarator;
2935 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
2938 assignment-expression
2939 { initializer-list }
2940 { initializer-list , }
2943 designation[opt] initializer
2944 initializer-list , designation[opt] initializer
2951 designator-list designator
2958 [ constant-expression ]
2970 [ constant-expression ... constant-expression ]
2972 Any expression without commas is accepted in the syntax for the
2973 constant-expressions, with non-constant expressions rejected later.
2975 This function is only used for top-level initializers; for nested
2976 ones, see c_parser_initval. */
2978 static struct c_expr
2979 c_parser_initializer (c_parser *parser)
2981 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
2982 return c_parser_braced_init (parser, NULL_TREE, false);
2986 ret = c_parser_expr_no_commas (parser, NULL);
2987 if (TREE_CODE (ret.value) != STRING_CST
2988 && TREE_CODE (ret.value) != COMPOUND_LITERAL_EXPR)
2989 ret = default_function_array_conversion (ret);
2994 /* Parse a braced initializer list. TYPE is the type specified for a
2995 compound literal, and NULL_TREE for other initializers and for
2996 nested braced lists. NESTED_P is true for nested braced lists,
2997 false for the list of a compound literal or the list that is the
2998 top-level initializer in a declaration. */
3000 static struct c_expr
3001 c_parser_braced_init (c_parser *parser, tree type, bool nested_p)
3003 location_t brace_loc = c_parser_peek_token (parser)->location;
3004 gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE));
3005 c_parser_consume_token (parser);
3007 push_init_level (0);
3009 really_start_incremental_init (type);
3010 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3012 pedwarn (OPT_pedantic, "%HISO C forbids empty initializer braces",
3017 /* Parse a non-empty initializer list, possibly with a trailing
3021 c_parser_initelt (parser);
3024 if (c_parser_next_token_is (parser, CPP_COMMA))
3025 c_parser_consume_token (parser);
3028 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3032 if (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE))
3035 ret.value = error_mark_node;
3036 ret.original_code = ERROR_MARK;
3037 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, "expected %<}%>");
3040 c_parser_consume_token (parser);
3041 return pop_init_level (0);
3044 /* Parse a nested initializer, including designators. */
3047 c_parser_initelt (c_parser *parser)
3049 /* Parse any designator or designator list. A single array
3050 designator may have the subsequent "=" omitted in GNU C, but a
3051 longer list or a structure member designator may not. */
3052 if (c_parser_next_token_is (parser, CPP_NAME)
3053 && c_parser_peek_2nd_token (parser)->type == CPP_COLON)
3055 /* Old-style structure member designator. */
3056 set_init_label (c_parser_peek_token (parser)->value);
3057 /* Use the colon as the error location. */
3058 pedwarn (OPT_pedantic,
3059 "%Hobsolete use of designated initializer with %<:%>",
3060 &c_parser_peek_2nd_token (parser)->location);
3061 c_parser_consume_token (parser);
3062 c_parser_consume_token (parser);
3066 /* des_seen is 0 if there have been no designators, 1 if there
3067 has been a single array designator and 2 otherwise. */
3069 /* Location of a designator. */
3071 while (c_parser_next_token_is (parser, CPP_OPEN_SQUARE)
3072 || c_parser_next_token_is (parser, CPP_DOT))
3074 int des_prev = des_seen;
3076 des_loc = c_parser_peek_token (parser)->location;
3079 if (c_parser_next_token_is (parser, CPP_DOT))
3082 c_parser_consume_token (parser);
3083 if (c_parser_next_token_is (parser, CPP_NAME))
3085 set_init_label (c_parser_peek_token (parser)->value);
3086 c_parser_consume_token (parser);
3091 init.value = error_mark_node;
3092 init.original_code = ERROR_MARK;
3093 c_parser_error (parser, "expected identifier");
3094 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
3095 process_init_element (init);
3102 location_t ellipsis_loc;
3103 /* ??? Following the old parser, [ objc-receiver
3104 objc-message-args ] is accepted as an initializer,
3105 being distinguished from a designator by what follows
3106 the first assignment expression inside the square
3107 brackets, but after a first array designator a
3108 subsequent square bracket is for Objective-C taken to
3109 start an expression, using the obsolete form of
3110 designated initializer without '=', rather than
3111 possibly being a second level of designation: in LALR
3112 terms, the '[' is shifted rather than reducing
3113 designator to designator-list. */
3114 if (des_prev == 1 && c_dialect_objc ())
3116 des_seen = des_prev;
3119 if (des_prev == 0 && c_dialect_objc ())
3121 /* This might be an array designator or an
3122 Objective-C message expression. If the former,
3123 continue parsing here; if the latter, parse the
3124 remainder of the initializer given the starting
3125 primary-expression. ??? It might make sense to
3126 distinguish when des_prev == 1 as well; see
3127 previous comment. */
3129 struct c_expr mexpr;
3130 c_parser_consume_token (parser);
3131 if (c_parser_peek_token (parser)->type == CPP_NAME
3132 && ((c_parser_peek_token (parser)->id_kind
3134 || (c_parser_peek_token (parser)->id_kind
3135 == C_ID_CLASSNAME)))
3137 /* Type name receiver. */
3138 tree id = c_parser_peek_token (parser)->value;
3139 c_parser_consume_token (parser);
3140 rec = objc_get_class_reference (id);
3141 goto parse_message_args;
3143 first = c_parser_expr_no_commas (parser, NULL).value;
3144 if (c_parser_next_token_is (parser, CPP_ELLIPSIS)
3145 || c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3146 goto array_desig_after_first;
3147 /* Expression receiver. So far only one part
3148 without commas has been parsed; there might be
3149 more of the expression. */
3151 while (c_parser_next_token_is (parser, CPP_COMMA))
3154 c_parser_consume_token (parser);
3155 next = c_parser_expr_no_commas (parser, NULL);
3156 next = default_function_array_conversion (next);
3157 rec = build_compound_expr (rec, next.value);
3160 /* Now parse the objc-message-args. */
3161 args = c_parser_objc_message_args (parser);
3162 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
3165 = objc_build_message_expr (build_tree_list (rec, args));
3166 mexpr.original_code = ERROR_MARK;
3167 /* Now parse and process the remainder of the
3168 initializer, starting with this message
3169 expression as a primary-expression. */
3170 c_parser_initval (parser, &mexpr);
3173 c_parser_consume_token (parser);
3174 first = c_parser_expr_no_commas (parser, NULL).value;
3175 array_desig_after_first:
3176 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
3178 ellipsis_loc = c_parser_peek_token (parser)->location;
3179 c_parser_consume_token (parser);
3180 second = c_parser_expr_no_commas (parser, NULL).value;
3184 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3186 c_parser_consume_token (parser);
3187 set_init_index (first, second);
3189 pedwarn (OPT_pedantic,
3190 "%HISO C forbids specifying range of "
3191 "elements to initialize", &ellipsis_loc);
3194 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
3200 if (c_parser_next_token_is (parser, CPP_EQ))
3203 pedwarn (OPT_pedantic,
3204 "%HISO C90 forbids specifying subobject "
3205 "to initialize", &des_loc);
3206 c_parser_consume_token (parser);
3212 pedwarn (OPT_pedantic,
3213 "%Hobsolete use of designated initializer "
3215 &c_parser_peek_token (parser)->location);
3220 init.value = error_mark_node;
3221 init.original_code = ERROR_MARK;
3222 c_parser_error (parser, "expected %<=%>");
3223 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
3224 process_init_element (init);
3230 c_parser_initval (parser, NULL);
3233 /* Parse a nested initializer; as c_parser_initializer but parses
3234 initializers within braced lists, after any designators have been
3235 applied. If AFTER is not NULL then it is an Objective-C message
3236 expression which is the primary-expression starting the
3240 c_parser_initval (c_parser *parser, struct c_expr *after)
3243 gcc_assert (!after || c_dialect_objc ());
3244 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE) && !after)
3245 init = c_parser_braced_init (parser, NULL_TREE, true);
3248 init = c_parser_expr_no_commas (parser, after);
3249 if (init.value != NULL_TREE
3250 && TREE_CODE (init.value) != STRING_CST
3251 && TREE_CODE (init.value) != COMPOUND_LITERAL_EXPR)
3252 init = default_function_array_conversion (init);
3254 process_init_element (init);
3257 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
3261 { block-item-list[opt] }
3262 { label-declarations block-item-list }
3266 block-item-list block-item
3278 { label-declarations block-item-list }
3281 __extension__ nested-declaration
3282 nested-function-definition
3286 label-declarations label-declaration
3289 __label__ identifier-list ;
3291 Allowing the mixing of declarations and code is new in C99. The
3292 GNU syntax also permits (not shown above) labels at the end of
3293 compound statements, which yield an error. We don't allow labels
3294 on declarations; this might seem like a natural extension, but
3295 there would be a conflict between attributes on the label and
3296 prefix attributes on the declaration. ??? The syntax follows the
3297 old parser in requiring something after label declarations.
3298 Although they are erroneous if the labels declared aren't defined,
3299 is it useful for the syntax to be this way?
3311 c_parser_compound_statement (c_parser *parser)
3314 if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
3315 return error_mark_node;
3316 stmt = c_begin_compound_stmt (true);
3317 c_parser_compound_statement_nostart (parser);
3318 return c_end_compound_stmt (stmt, true);
3321 /* Parse a compound statement except for the opening brace. This is
3322 used for parsing both compound statements and statement expressions
3323 (which follow different paths to handling the opening). */
3326 c_parser_compound_statement_nostart (c_parser *parser)
3328 bool last_stmt = false;
3329 bool last_label = false;
3330 location_t label_loc;
3331 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3333 c_parser_consume_token (parser);
3336 if (c_parser_next_token_is_keyword (parser, RID_LABEL))
3338 location_t err_loc = c_parser_peek_token (parser)->location;
3339 /* Read zero or more forward-declarations for labels that nested
3340 functions can jump to. */
3341 while (c_parser_next_token_is_keyword (parser, RID_LABEL))
3343 c_parser_consume_token (parser);
3344 /* Any identifiers, including those declared as type names,
3349 if (c_parser_next_token_is_not (parser, CPP_NAME))
3351 c_parser_error (parser, "expected identifier");
3355 = declare_label (c_parser_peek_token (parser)->value);
3356 C_DECLARED_LABEL_FLAG (label) = 1;
3357 add_stmt (build_stmt (DECL_EXPR, label));
3358 c_parser_consume_token (parser);
3359 if (c_parser_next_token_is (parser, CPP_COMMA))
3360 c_parser_consume_token (parser);
3364 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
3366 pedwarn (OPT_pedantic, "%HISO C forbids label declarations", &err_loc);
3368 /* We must now have at least one statement, label or declaration. */
3369 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3371 c_parser_error (parser, "expected declaration or statement");
3372 c_parser_consume_token (parser);
3375 while (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE))
3377 location_t loc = c_parser_peek_token (parser)->location;
3378 if (c_parser_next_token_is_keyword (parser, RID_CASE)
3379 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
3380 || (c_parser_next_token_is (parser, CPP_NAME)
3381 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3383 if (c_parser_next_token_is_keyword (parser, RID_CASE))
3384 label_loc = c_parser_peek_2nd_token (parser)->location;
3386 label_loc = c_parser_peek_token (parser)->location;
3389 c_parser_label (parser);
3391 else if (!last_label
3392 && c_parser_next_token_starts_declspecs (parser))
3395 c_parser_declaration_or_fndef (parser, true, true, true, true);
3397 pedwarn_c90 ((pedantic && !flag_isoc99)
3399 : OPT_Wdeclaration_after_statement,
3400 "%HISO C90 forbids mixed declarations and code",
3404 else if (!last_label
3405 && c_parser_next_token_is_keyword (parser, RID_EXTENSION))
3407 /* __extension__ can start a declaration, but is also an
3408 unary operator that can start an expression. Consume all
3409 but the last of a possible series of __extension__ to
3411 while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD
3412 && (c_parser_peek_2nd_token (parser)->keyword
3414 c_parser_consume_token (parser);
3415 if (c_token_starts_declspecs (c_parser_peek_2nd_token (parser)))
3418 ext = disable_extension_diagnostics ();
3419 c_parser_consume_token (parser);
3421 c_parser_declaration_or_fndef (parser, true, true, true, true);
3422 /* Following the old parser, __extension__ does not
3423 disable this diagnostic. */
3424 restore_extension_diagnostics (ext);
3426 pedwarn_c90 ((pedantic && !flag_isoc99)
3428 : OPT_Wdeclaration_after_statement,
3429 "%HISO C90 forbids mixed declarations and code",
3436 else if (c_parser_next_token_is (parser, CPP_PRAGMA))
3438 /* External pragmas, and some omp pragmas, are not associated
3439 with regular c code, and so are not to be considered statements
3440 syntactically. This ensures that the user doesn't put them
3441 places that would turn into syntax errors if the directive
3443 if (c_parser_pragma (parser, pragma_compound))
3444 last_label = false, last_stmt = true;
3446 else if (c_parser_next_token_is (parser, CPP_EOF))
3448 c_parser_error (parser, "expected declaration or statement");
3451 else if (c_parser_next_token_is_keyword (parser, RID_ELSE))
3453 if (parser->in_if_block)
3455 error ("%H""expected %<}%> before %<else%>", &loc);
3460 error ("%H%<else%> without a previous %<if%>", &loc);
3461 c_parser_consume_token (parser);
3470 c_parser_statement_after_labels (parser);
3473 parser->error = false;
3476 error ("%Hlabel at end of compound statement", &label_loc);
3477 c_parser_consume_token (parser);
3480 /* Parse a label (C90 6.6.1, C99 6.8.1).
3483 identifier : attributes[opt]
3484 case constant-expression :
3490 case constant-expression ... constant-expression :
3492 The use of attributes on labels is a GNU extension. The syntax in
3493 GNU C accepts any expressions without commas, non-constant
3494 expressions being rejected later. */
3497 c_parser_label (c_parser *parser)
3499 location_t loc1 = c_parser_peek_token (parser)->location;
3500 tree label = NULL_TREE;
3501 if (c_parser_next_token_is_keyword (parser, RID_CASE))
3504 c_parser_consume_token (parser);
3505 exp1 = c_parser_expr_no_commas (parser, NULL).value;
3506 if (c_parser_next_token_is (parser, CPP_COLON))
3508 c_parser_consume_token (parser);
3509 label = do_case (exp1, NULL_TREE);
3511 else if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
3513 c_parser_consume_token (parser);
3514 exp2 = c_parser_expr_no_commas (parser, NULL).value;
3515 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
3516 label = do_case (exp1, exp2);
3519 c_parser_error (parser, "expected %<:%> or %<...%>");
3521 else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT))
3523 c_parser_consume_token (parser);
3524 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
3525 label = do_case (NULL_TREE, NULL_TREE);
3529 tree name = c_parser_peek_token (parser)->value;
3532 location_t loc2 = c_parser_peek_token (parser)->location;
3533 gcc_assert (c_parser_next_token_is (parser, CPP_NAME));
3534 c_parser_consume_token (parser);
3535 gcc_assert (c_parser_next_token_is (parser, CPP_COLON));
3536 c_parser_consume_token (parser);
3537 attrs = c_parser_attributes (parser);
3538 tlab = define_label (loc2, name);
3541 decl_attributes (&tlab, attrs, 0);
3542 label = add_stmt (build_stmt (LABEL_EXPR, tlab));
3547 SET_EXPR_LOCATION (label, loc1);
3548 if (c_parser_next_token_starts_declspecs (parser)
3549 && !(c_parser_next_token_is (parser, CPP_NAME)
3550 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3552 error ("%Ha label can only be part of a statement and "
3553 "a declaration is not a statement",
3554 &c_parser_peek_token (parser)->location);
3555 c_parser_declaration_or_fndef (parser, /*fndef_ok*/ false,
3556 /*nested*/ true, /*empty_ok*/ false,
3557 /*start_attr_ok*/ true);
3562 /* Parse a statement (C90 6.6, C99 6.8).
3567 expression-statement
3575 expression-statement:
3578 selection-statement:
3582 iteration-statement:
3591 return expression[opt] ;
3604 objc-throw-statement
3605 objc-try-catch-statement
3606 objc-synchronized-statement
3608 objc-throw-statement:
3622 parallel-for-construct
3623 parallel-sections-construct
3630 parallel-directive structured-block
3633 for-directive iteration-statement
3636 sections-directive section-scope
3639 single-directive structured-block
3641 parallel-for-construct:
3642 parallel-for-directive iteration-statement
3644 parallel-sections-construct:
3645 parallel-sections-directive section-scope
3648 master-directive structured-block
3651 critical-directive structured-block
3654 atomic-directive expression-statement
3657 ordered-directive structured-block */
3660 c_parser_statement (c_parser *parser)
3662 while (c_parser_next_token_is_keyword (parser, RID_CASE)
3663 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
3664 || (c_parser_next_token_is (parser, CPP_NAME)
3665 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3666 c_parser_label (parser);
3667 c_parser_statement_after_labels (parser);
3670 /* Parse a statement, other than a labeled statement. */
3673 c_parser_statement_after_labels (c_parser *parser)
3675 location_t loc = c_parser_peek_token (parser)->location;
3676 tree stmt = NULL_TREE;
3677 bool in_if_block = parser->in_if_block;
3678 parser->in_if_block = false;
3679 switch (c_parser_peek_token (parser)->type)
3681 case CPP_OPEN_BRACE:
3682 add_stmt (c_parser_compound_statement (parser));
3685 switch (c_parser_peek_token (parser)->keyword)
3688 c_parser_if_statement (parser);
3691 c_parser_switch_statement (parser);
3694 c_parser_while_statement (parser);
3697 c_parser_do_statement (parser);
3700 c_parser_for_statement (parser);
3703 c_parser_consume_token (parser);
3704 if (c_parser_next_token_is (parser, CPP_NAME))
3706 stmt = c_finish_goto_label (c_parser_peek_token (parser)->value);
3707 c_parser_consume_token (parser);
3709 else if (c_parser_next_token_is (parser, CPP_MULT))
3711 c_parser_consume_token (parser);
3712 stmt = c_finish_goto_ptr (c_parser_expression (parser).value);
3715 c_parser_error (parser, "expected identifier or %<*%>");
3716 goto expect_semicolon;
3718 c_parser_consume_token (parser);
3719 stmt = c_finish_bc_stmt (&c_cont_label, false);
3720 goto expect_semicolon;
3722 c_parser_consume_token (parser);
3723 stmt = c_finish_bc_stmt (&c_break_label, true);
3724 goto expect_semicolon;
3726 c_parser_consume_token (parser);
3727 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3729 stmt = c_finish_return (NULL_TREE);
3730 c_parser_consume_token (parser);
3734 stmt = c_finish_return (c_parser_expression_conv (parser).value);
3735 goto expect_semicolon;
3739 stmt = c_parser_asm_statement (parser);
3742 gcc_assert (c_dialect_objc ());
3743 c_parser_consume_token (parser);
3744 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3746 stmt = objc_build_throw_stmt (NULL_TREE);
3747 c_parser_consume_token (parser);
3752 = objc_build_throw_stmt (c_parser_expression (parser).value);
3753 goto expect_semicolon;
3757 gcc_assert (c_dialect_objc ());
3758 c_parser_objc_try_catch_statement (parser);
3760 case RID_AT_SYNCHRONIZED:
3761 gcc_assert (c_dialect_objc ());
3762 c_parser_objc_synchronized_statement (parser);
3769 c_parser_consume_token (parser);
3771 case CPP_CLOSE_PAREN:
3772 case CPP_CLOSE_SQUARE:
3773 /* Avoid infinite loop in error recovery:
3774 c_parser_skip_until_found stops at a closing nesting
3775 delimiter without consuming it, but here we need to consume
3776 it to proceed further. */
3777 c_parser_error (parser, "expected statement");
3778 c_parser_consume_token (parser);
3781 c_parser_pragma (parser, pragma_stmt);
3785 stmt = c_finish_expr_stmt (c_parser_expression_conv (parser).value);
3787 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
3790 /* Two cases cannot and do not have line numbers associated: If stmt
3791 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
3792 cannot hold line numbers. But that's OK because the statement
3793 will either be changed to a MODIFY_EXPR during gimplification of
3794 the statement expr, or discarded. If stmt was compound, but
3795 without new variables, we will have skipped the creation of a
3796 BIND and will have a bare STATEMENT_LIST. But that's OK because
3797 (recursively) all of the component statements should already have
3798 line numbers assigned. ??? Can we discard no-op statements
3800 if (stmt && CAN_HAVE_LOCATION_P (stmt))
3801 SET_EXPR_LOCATION (stmt, loc);
3803 parser->in_if_block = in_if_block;
3806 /* Parse the condition from an if, do, while or for statements. */
3809 c_parser_condition (c_parser *parser)
3813 loc = c_parser_peek_token (parser)->location;
3814 cond = c_objc_common_truthvalue_conversion
3815 (c_parser_expression_conv (parser).value);
3816 if (CAN_HAVE_LOCATION_P (cond))
3817 SET_EXPR_LOCATION (cond, loc);
3818 if (warn_sequence_point)
3819 verify_sequence_points (cond);
3823 /* Parse a parenthesized condition from an if, do or while statement.
3829 c_parser_paren_condition (c_parser *parser)
3832 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3833 return error_mark_node;
3834 cond = c_parser_condition (parser);
3835 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
3839 /* Parse a statement which is a block in C99. */
3842 c_parser_c99_block_statement (c_parser *parser)
3844 tree block = c_begin_compound_stmt (flag_isoc99);
3845 c_parser_statement (parser);
3846 return c_end_compound_stmt (block, flag_isoc99);
3849 /* Parse the body of an if statement. This is just parsing a
3850 statement but (a) it is a block in C99, (b) we track whether the
3851 body is an if statement for the sake of -Wparentheses warnings, (c)
3852 we handle an empty body specially for the sake of -Wempty-body
3853 warnings, and (d) we call parser_compound_statement directly
3854 because c_parser_statement_after_labels resets
3855 parser->in_if_block. */
3858 c_parser_if_body (c_parser *parser, bool *if_p)
3860 tree block = c_begin_compound_stmt (flag_isoc99);
3861 while (c_parser_next_token_is_keyword (parser, RID_CASE)
3862 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
3863 || (c_parser_next_token_is (parser, CPP_NAME)
3864 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3865 c_parser_label (parser);
3866 *if_p = c_parser_next_token_is_keyword (parser, RID_IF);
3867 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3869 add_stmt (build_empty_stmt ());
3870 c_parser_consume_token (parser);
3872 else if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
3873 add_stmt (c_parser_compound_statement (parser));
3875 c_parser_statement_after_labels (parser);
3876 return c_end_compound_stmt (block, flag_isoc99);
3879 /* Parse the else body of an if statement. This is just parsing a
3880 statement but (a) it is a block in C99, (b) we handle an empty body
3881 specially for the sake of -Wempty-body warnings. */
3884 c_parser_else_body (c_parser *parser)
3886 tree block = c_begin_compound_stmt (flag_isoc99);
3887 while (c_parser_next_token_is_keyword (parser, RID_CASE)
3888 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
3889 || (c_parser_next_token_is (parser, CPP_NAME)
3890 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3891 c_parser_label (parser);
3892 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3894 add_stmt (build_empty_stmt ());
3895 c_parser_consume_token (parser);
3898 c_parser_statement_after_labels (parser);
3899 return c_end_compound_stmt (block, flag_isoc99);
3902 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
3905 if ( expression ) statement
3906 if ( expression ) statement else statement
3910 c_parser_if_statement (c_parser *parser)
3915 bool first_if = false;
3916 tree first_body, second_body;
3919 gcc_assert (c_parser_next_token_is_keyword (parser, RID_IF));
3920 c_parser_consume_token (parser);
3921 block = c_begin_compound_stmt (flag_isoc99);
3922 loc = c_parser_peek_token (parser)->location;
3923 cond = c_parser_paren_condition (parser);
3924 in_if_block = parser->in_if_block;
3925 parser->in_if_block = true;
3926 first_body = c_parser_if_body (parser, &first_if);
3927 parser->in_if_block = in_if_block;
3928 if (c_parser_next_token_is_keyword (parser, RID_ELSE))
3930 c_parser_consume_token (parser);
3931 second_body = c_parser_else_body (parser);
3934 second_body = NULL_TREE;
3935 c_finish_if_stmt (loc, cond, first_body, second_body, first_if);
3936 add_stmt (c_end_compound_stmt (block, flag_isoc99));
3939 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
3942 switch (expression) statement
3946 c_parser_switch_statement (c_parser *parser)
3948 tree block, expr, body, save_break;
3949 gcc_assert (c_parser_next_token_is_keyword (parser, RID_SWITCH));
3950 c_parser_consume_token (parser);
3951 block = c_begin_compound_stmt (flag_isoc99);
3952 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3954 expr = c_parser_expression (parser).value;
3955 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
3958 expr = error_mark_node;
3959 c_start_case (expr);
3960 save_break = c_break_label;
3961 c_break_label = NULL_TREE;
3962 body = c_parser_c99_block_statement (parser);
3963 c_finish_case (body);
3965 add_stmt (build1 (LABEL_EXPR, void_type_node, c_break_label));
3966 c_break_label = save_break;
3967 add_stmt (c_end_compound_stmt (block, flag_isoc99));
3970 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
3973 while (expression) statement
3977 c_parser_while_statement (c_parser *parser)
3979 tree block, cond, body, save_break, save_cont;
3981 gcc_assert (c_parser_next_token_is_keyword (parser, RID_WHILE));
3982 c_parser_consume_token (parser);
3983 block = c_begin_compound_stmt (flag_isoc99);
3984 loc = c_parser_peek_token (parser)->location;
3985 cond = c_parser_paren_condition (parser);
3986 save_break = c_break_label;
3987 c_break_label = NULL_TREE;
3988 save_cont = c_cont_label;
3989 c_cont_label = NULL_TREE;
3990 body = c_parser_c99_block_statement (parser);
3991 c_finish_loop (loc, cond, NULL, body, c_break_label, c_cont_label, true);
3992 add_stmt (c_end_compound_stmt (block, flag_isoc99));
3993 c_break_label = save_break;
3994 c_cont_label = save_cont;
3997 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
4000 do statement while ( expression ) ;
4004 c_parser_do_statement (c_parser *parser)
4006 tree block, cond, body, save_break, save_cont, new_break, new_cont;
4008 gcc_assert (c_parser_next_token_is_keyword (parser, RID_DO));
4009 c_parser_consume_token (parser);
4010 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4011 warning (OPT_Wempty_body,
4012 "%Hsuggest braces around empty body in %<do%> statement",
4013 &c_parser_peek_token (parser)->location);
4014 block = c_begin_compound_stmt (flag_isoc99);
4015 loc = c_parser_peek_token (parser)->location;
4016 save_break = c_break_label;
4017 c_break_label = NULL_TREE;
4018 save_cont = c_cont_label;
4019 c_cont_label = NULL_TREE;
4020 body = c_parser_c99_block_statement (parser);
4021 c_parser_require_keyword (parser, RID_WHILE, "expected %<while%>");
4022 new_break = c_break_label;
4023 c_break_label = save_break;
4024 new_cont = c_cont_label;
4025 c_cont_label = save_cont;
4026 cond = c_parser_paren_condition (parser);
4027 if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
4028 c_parser_skip_to_end_of_block_or_statement (parser);
4029 c_finish_loop (loc, cond, NULL, body, new_break, new_cont, false);
4030 add_stmt (c_end_compound_stmt (block, flag_isoc99));
4033 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
4036 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
4037 for ( nested-declaration expression[opt] ; expression[opt] ) statement
4039 The form with a declaration is new in C99.
4041 ??? In accordance with the old parser, the declaration may be a
4042 nested function, which is then rejected in check_for_loop_decls,
4043 but does it make any sense for this to be included in the grammar?
4044 Note in particular that the nested function does not include a
4045 trailing ';', whereas the "declaration" production includes one.
4046 Also, can we reject bad declarations earlier and cheaper than
4047 check_for_loop_decls? */
4050 c_parser_for_statement (c_parser *parser)
4052 tree block, cond, incr, save_break, save_cont, body;
4054 gcc_assert (c_parser_next_token_is_keyword (parser, RID_FOR));
4055 loc = c_parser_peek_token (parser)->location;
4056 c_parser_consume_token (parser);
4057 block = c_begin_compound_stmt (flag_isoc99);
4058 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4060 /* Parse the initialization declaration or expression. */
4061 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4063 c_parser_consume_token (parser);
4064 c_finish_expr_stmt (NULL_TREE);
4066 else if (c_parser_next_token_starts_declspecs (parser))
4068 c_parser_declaration_or_fndef (parser, true, true, true, true);
4069 check_for_loop_decls ();
4071 else if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
4073 /* __extension__ can start a declaration, but is also an
4074 unary operator that can start an expression. Consume all
4075 but the last of a possible series of __extension__ to
4077 while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD
4078 && (c_parser_peek_2nd_token (parser)->keyword
4080 c_parser_consume_token (parser);
4081 if (c_token_starts_declspecs (c_parser_peek_2nd_token (parser)))
4084 ext = disable_extension_diagnostics ();
4085 c_parser_consume_token (parser);
4086 c_parser_declaration_or_fndef (parser, true, true, true, true);
4087 restore_extension_diagnostics (ext);
4088 check_for_loop_decls ();
4096 c_finish_expr_stmt (c_parser_expression (parser).value);
4097 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4099 /* Parse the loop condition. */
4100 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4102 c_parser_consume_token (parser);
4107 cond = c_parser_condition (parser);
4108 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4110 /* Parse the increment expression. */
4111 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4112 incr = c_process_expr_stmt (NULL_TREE);
4114 incr = c_process_expr_stmt (c_parser_expression (parser).value);
4115 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4119 cond = error_mark_node;
4120 incr = error_mark_node;
4122 save_break = c_break_label;
4123 c_break_label = NULL_TREE;
4124 save_cont = c_cont_label;
4125 c_cont_label = NULL_TREE;
4126 body = c_parser_c99_block_statement (parser);
4127 c_finish_loop (loc, cond, incr, body, c_break_label, c_cont_label, true);
4128 add_stmt (c_end_compound_stmt (block, flag_isoc99));
4129 c_break_label = save_break;
4130 c_cont_label = save_cont;
4133 /* Parse an asm statement, a GNU extension. This is a full-blown asm
4134 statement with inputs, outputs, clobbers, and volatile tag
4138 asm type-qualifier[opt] ( asm-argument ) ;
4142 asm-string-literal : asm-operands[opt]
4143 asm-string-literal : asm-operands[opt] : asm-operands[opt]
4144 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers
4146 Qualifiers other than volatile are accepted in the syntax but
4150 c_parser_asm_statement (c_parser *parser)
4152 tree quals, str, outputs, inputs, clobbers, ret;
4154 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
4155 c_parser_consume_token (parser);
4156 if (c_parser_next_token_is_keyword (parser, RID_VOLATILE))
4158 quals = c_parser_peek_token (parser)->value;
4159 c_parser_consume_token (parser);
4161 else if (c_parser_next_token_is_keyword (parser, RID_CONST)
4162 || c_parser_next_token_is_keyword (parser, RID_RESTRICT))
4164 warning (0, "%H%E qualifier ignored on asm",
4165 &c_parser_peek_token (parser)->location,
4166 c_parser_peek_token (parser)->value);
4168 c_parser_consume_token (parser);
4172 /* ??? Follow the C++ parser rather than using the
4173 lex_untranslated_string kludge. */
4174 parser->lex_untranslated_string = true;
4175 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4177 parser->lex_untranslated_string = false;
4180 str = c_parser_asm_string_literal (parser);
4181 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4184 outputs = NULL_TREE;
4186 clobbers = NULL_TREE;
4189 if (!c_parser_require (parser, CPP_COLON, "expected %<:%> or %<)%>"))
4191 parser->lex_untranslated_string = false;
4192 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4196 /* Parse outputs. */
4197 if (c_parser_next_token_is (parser, CPP_COLON)
4198 || c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4199 outputs = NULL_TREE;
4201 outputs = c_parser_asm_operands (parser, false);
4202 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4205 clobbers = NULL_TREE;
4208 if (!c_parser_require (parser, CPP_COLON, "expected %<:%> or %<)%>"))
4210 parser->lex_untranslated_string = false;
4211 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4215 if (c_parser_next_token_is (parser, CPP_COLON)
4216 || c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4219 inputs = c_parser_asm_operands (parser, true);
4220 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4222 clobbers = NULL_TREE;
4225 if (!c_parser_require (parser, CPP_COLON, "expected %<:%> or %<)%>"))
4227 parser->lex_untranslated_string = false;
4228 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4231 /* Parse clobbers. */
4232 clobbers = c_parser_asm_clobbers (parser);
4234 parser->lex_untranslated_string = false;
4235 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
4237 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4240 if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
4241 c_parser_skip_to_end_of_block_or_statement (parser);
4242 ret = build_asm_stmt (quals, build_asm_expr (str, outputs, inputs,
4247 /* Parse asm operands, a GNU extension. If CONVERT_P (for inputs but
4248 not outputs), apply the default conversion of functions and arrays
4253 asm-operands , asm-operand
4256 asm-string-literal ( expression )
4257 [ identifier ] asm-string-literal ( expression )
4261 c_parser_asm_operands (c_parser *parser, bool convert_p)
4263 tree list = NULL_TREE;
4268 if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
4270 c_parser_consume_token (parser);
4271 if (c_parser_next_token_is (parser, CPP_NAME))
4273 tree id = c_parser_peek_token (parser)->value;
4274 c_parser_consume_token (parser);
4275 name = build_string (IDENTIFIER_LENGTH (id),
4276 IDENTIFIER_POINTER (id));
4280 c_parser_error (parser, "expected identifier");
4281 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
4284 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
4289 str = c_parser_asm_string_literal (parser);
4290 if (str == NULL_TREE)
4292 parser->lex_untranslated_string = false;
4293 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4295 parser->lex_untranslated_string = true;
4298 expr = c_parser_expression (parser);
4300 expr = default_function_array_conversion (expr);
4301 parser->lex_untranslated_string = true;
4302 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
4304 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4307 list = chainon (list, build_tree_list (build_tree_list (name, str),
4309 if (c_parser_next_token_is (parser, CPP_COMMA))
4310 c_parser_consume_token (parser);
4317 /* Parse asm clobbers, a GNU extension.
4321 asm-clobbers , asm-string-literal
4325 c_parser_asm_clobbers (c_parser *parser)
4327 tree list = NULL_TREE;
4330 tree str = c_parser_asm_string_literal (parser);
4332 list = tree_cons (NULL_TREE, str, list);
4335 if (c_parser_next_token_is (parser, CPP_COMMA))
4336 c_parser_consume_token (parser);
4343 /* Parse an expression other than a compound expression; that is, an
4344 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
4345 NULL then it is an Objective-C message expression which is the
4346 primary-expression starting the expression as an initializer.
4348 assignment-expression:
4349 conditional-expression
4350 unary-expression assignment-operator assignment-expression
4352 assignment-operator: one of
4353 = *= /= %= += -= <<= >>= &= ^= |=
4355 In GNU C we accept any conditional expression on the LHS and
4356 diagnose the invalid lvalue rather than producing a syntax
4359 static struct c_expr
4360 c_parser_expr_no_commas (c_parser *parser, struct c_expr *after)
4362 struct c_expr lhs, rhs, ret;
4363 enum tree_code code;
4364 gcc_assert (!after || c_dialect_objc ());
4365 lhs = c_parser_conditional_expression (parser, after);
4366 switch (c_parser_peek_token (parser)->type)
4375 code = TRUNC_DIV_EXPR;
4378 code = TRUNC_MOD_EXPR;
4393 code = BIT_AND_EXPR;
4396 code = BIT_XOR_EXPR;
4399 code = BIT_IOR_EXPR;
4404 c_parser_consume_token (parser);
4405 rhs = c_parser_expr_no_commas (parser, NULL);
4406 rhs = default_function_array_conversion (rhs);
4407 ret.value = build_modify_expr (lhs.value, code, rhs.value);
4408 if (code == NOP_EXPR)
4409 ret.original_code = MODIFY_EXPR;
4412 TREE_NO_WARNING (ret.value) = 1;
4413 ret.original_code = ERROR_MARK;
4418 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
4419 is not NULL then it is an Objective-C message expression which is
4420 the primary-expression starting the expression as an initializer.
4422 conditional-expression:
4423 logical-OR-expression
4424 logical-OR-expression ? expression : conditional-expression
4428 conditional-expression:
4429 logical-OR-expression ? : conditional-expression
4432 static struct c_expr
4433 c_parser_conditional_expression (c_parser *parser, struct c_expr *after)
4435 struct c_expr cond, exp1, exp2, ret;
4436 gcc_assert (!after || c_dialect_objc ());
4437 cond = c_parser_binary_expression (parser, after);
4438 if (c_parser_next_token_is_not (parser, CPP_QUERY))
4440 cond = default_function_array_conversion (cond);
4441 c_parser_consume_token (parser);
4442 if (c_parser_next_token_is (parser, CPP_COLON))
4444 pedwarn (OPT_pedantic,
4445 "%HISO C forbids omitting the middle term of a ?: expression",
4446 &c_parser_peek_token (parser)->location);
4447 /* Make sure first operand is calculated only once. */
4448 exp1.value = save_expr (default_conversion (cond.value));
4449 cond.value = c_objc_common_truthvalue_conversion (exp1.value);
4450 skip_evaluation += cond.value == truthvalue_true_node;
4455 = c_objc_common_truthvalue_conversion
4456 (default_conversion (cond.value));
4457 skip_evaluation += cond.value == truthvalue_false_node;
4458 exp1 = c_parser_expression_conv (parser);
4459 skip_evaluation += ((cond.value == truthvalue_true_node)
4460 - (cond.value == truthvalue_false_node));
4462 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
4464 skip_evaluation -= cond.value == truthvalue_true_node;
4465 ret.value = error_mark_node;
4466 ret.original_code = ERROR_MARK;
4469 exp2 = c_parser_conditional_expression (parser, NULL);
4470 exp2 = default_function_array_conversion (exp2);
4471 skip_evaluation -= cond.value == truthvalue_true_node;
4472 ret.value = build_conditional_expr (cond.value, exp1.value, exp2.value);
4473 ret.original_code = ERROR_MARK;
4477 /* Parse a binary expression; that is, a logical-OR-expression (C90
4478 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
4479 an Objective-C message expression which is the primary-expression
4480 starting the expression as an initializer.
4482 multiplicative-expression:
4484 multiplicative-expression * cast-expression
4485 multiplicative-expression / cast-expression
4486 multiplicative-expression % cast-expression
4488 additive-expression:
4489 multiplicative-expression
4490 additive-expression + multiplicative-expression
4491 additive-expression - multiplicative-expression
4495 shift-expression << additive-expression
4496 shift-expression >> additive-expression
4498 relational-expression:
4500 relational-expression < shift-expression
4501 relational-expression > shift-expression
4502 relational-expression <= shift-expression
4503 relational-expression >= shift-expression
4505 equality-expression:
4506 relational-expression
4507 equality-expression == relational-expression
4508 equality-expression != relational-expression
4512 AND-expression & equality-expression
4514 exclusive-OR-expression:
4516 exclusive-OR-expression ^ AND-expression
4518 inclusive-OR-expression:
4519 exclusive-OR-expression
4520 inclusive-OR-expression | exclusive-OR-expression
4522 logical-AND-expression:
4523 inclusive-OR-expression
4524 logical-AND-expression && inclusive-OR-expression
4526 logical-OR-expression:
4527 logical-AND-expression
4528 logical-OR-expression || logical-AND-expression
4531 static struct c_expr
4532 c_parser_binary_expression (c_parser *parser, struct c_expr *after)
4534 /* A binary expression is parsed using operator-precedence parsing,
4535 with the operands being cast expressions. All the binary
4536 operators are left-associative. Thus a binary expression is of
4539 E0 op1 E1 op2 E2 ...
4541 which we represent on a stack. On the stack, the precedence
4542 levels are strictly increasing. When a new operator is
4543 encountered of higher precedence than that at the top of the
4544 stack, it is pushed; its LHS is the top expression, and its RHS
4545 is everything parsed until it is popped. When a new operator is
4546 encountered with precedence less than or equal to that at the top
4547 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
4548 by the result of the operation until the operator at the top of
4549 the stack has lower precedence than the new operator or there is
4550 only one element on the stack; then the top expression is the LHS
4551 of the new operator. In the case of logical AND and OR
4552 expressions, we also need to adjust skip_evaluation as
4553 appropriate when the operators are pushed and popped. */
4555 /* The precedence levels, where 0 is a dummy lowest level used for
4556 the bottom of the stack. */
4572 /* The expression at this stack level. */
4574 /* The precedence of the operator on its left, PREC_NONE at the
4575 bottom of the stack. */
4577 /* The operation on its left. */
4583 switch (stack[sp].op) \
4585 case TRUTH_ANDIF_EXPR: \
4586 skip_evaluation -= stack[sp - 1].expr.value == truthvalue_false_node; \
4588 case TRUTH_ORIF_EXPR: \
4589 skip_evaluation -= stack[sp - 1].expr.value == truthvalue_true_node; \
4594 stack[sp - 1].expr \
4595 = default_function_array_conversion (stack[sp - 1].expr); \
4597 = default_function_array_conversion (stack[sp].expr); \
4598 stack[sp - 1].expr = parser_build_binary_op (stack[sp].op, \
4599 stack[sp - 1].expr, \
4603 gcc_assert (!after || c_dialect_objc ());
4604 stack[0].expr = c_parser_cast_expression (parser, after);
4605 stack[0].prec = PREC_NONE;
4610 enum tree_code ocode;
4613 switch (c_parser_peek_token (parser)->type)
4621 ocode = TRUNC_DIV_EXPR;
4625 ocode = TRUNC_MOD_EXPR;
4637 ocode = LSHIFT_EXPR;
4641 ocode = RSHIFT_EXPR;
4655 case CPP_GREATER_EQ:
4668 oprec = PREC_BITAND;
4669 ocode = BIT_AND_EXPR;
4672 oprec = PREC_BITXOR;
4673 ocode = BIT_XOR_EXPR;
4677 ocode = BIT_IOR_EXPR;
4680 oprec = PREC_LOGAND;
4681 ocode = TRUTH_ANDIF_EXPR;
4685 ocode = TRUTH_ORIF_EXPR;
4688 /* Not a binary operator, so end of the binary
4692 c_parser_consume_token (parser);
4693 while (oprec <= stack[sp].prec)
4697 case TRUTH_ANDIF_EXPR:
4699 = default_function_array_conversion (stack[sp].expr);
4700 stack[sp].expr.value = c_objc_common_truthvalue_conversion
4701 (default_conversion (stack[sp].expr.value));
4702 skip_evaluation += stack[sp].expr.value == truthvalue_false_node;
4704 case TRUTH_ORIF_EXPR:
4706 = default_function_array_conversion (stack[sp].expr);
4707 stack[sp].expr.value = c_objc_common_truthvalue_conversion
4708 (default_conversion (stack[sp].expr.value));
4709 skip_evaluation += stack[sp].expr.value == truthvalue_true_node;
4715 stack[sp].expr = c_parser_cast_expression (parser, NULL);
4716 stack[sp].prec = oprec;
4717 stack[sp].op = ocode;
4722 return stack[0].expr;
4726 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
4727 NULL then it is an Objective-C message expression which is the
4728 primary-expression starting the expression as an initializer.
4732 ( type-name ) unary-expression
4735 static struct c_expr
4736 c_parser_cast_expression (c_parser *parser, struct c_expr *after)
4738 gcc_assert (!after || c_dialect_objc ());
4740 return c_parser_postfix_expression_after_primary (parser, *after);
4741 /* If the expression begins with a parenthesized type name, it may
4742 be either a cast or a compound literal; we need to see whether
4743 the next character is '{' to tell the difference. If not, it is
4744 an unary expression. */
4745 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
4746 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
4748 struct c_type_name *type_name;
4751 c_parser_consume_token (parser);
4752 type_name = c_parser_type_name (parser);
4753 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4754 if (type_name == NULL)
4756 ret.value = error_mark_node;
4757 ret.original_code = ERROR_MARK;
4761 /* Save casted types in the function's used types hash table. */
4762 used_types_insert (type_name->specs->type);
4764 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
4765 return c_parser_postfix_expression_after_paren_type (parser,
4767 expr = c_parser_cast_expression (parser, NULL);
4768 expr = default_function_array_conversion (expr);
4769 ret.value = c_cast_expr (type_name, expr.value);
4770 ret.original_code = ERROR_MARK;
4774 return c_parser_unary_expression (parser);
4777 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
4783 unary-operator cast-expression
4784 sizeof unary-expression
4785 sizeof ( type-name )
4787 unary-operator: one of
4793 __alignof__ unary-expression
4794 __alignof__ ( type-name )
4797 unary-operator: one of
4798 __extension__ __real__ __imag__
4800 In addition, the GNU syntax treats ++ and -- as unary operators, so
4801 they may be applied to cast expressions with errors for non-lvalues
4804 static struct c_expr
4805 c_parser_unary_expression (c_parser *parser)
4808 struct c_expr ret, op;
4809 switch (c_parser_peek_token (parser)->type)
4812 c_parser_consume_token (parser);
4813 op = c_parser_cast_expression (parser, NULL);
4814 op = default_function_array_conversion (op);
4815 return parser_build_unary_op (PREINCREMENT_EXPR, op);
4816 case CPP_MINUS_MINUS:
4817 c_parser_consume_token (parser);
4818 op = c_parser_cast_expression (parser, NULL);
4819 op = default_function_array_conversion (op);
4820 return parser_build_unary_op (PREDECREMENT_EXPR, op);
4822 c_parser_consume_token (parser);
4823 return parser_build_unary_op (ADDR_EXPR,
4824 c_parser_cast_expression (parser, NULL));
4826 c_parser_consume_token (parser);
4827 op = c_parser_cast_expression (parser, NULL);
4828 op = default_function_array_conversion (op);
4829 ret.value = build_indirect_ref (op.value, "unary *");
4830 ret.original_code = ERROR_MARK;
4833 if (!c_dialect_objc () && !in_system_header)
4834 warning (OPT_Wtraditional,
4835 "%Htraditional C rejects the unary plus operator",
4836 &c_parser_peek_token (parser)->location);
4837 c_parser_consume_token (parser);
4838 op = c_parser_cast_expression (parser, NULL);
4839 op = default_function_array_conversion (op);
4840 return parser_build_unary_op (CONVERT_EXPR, op);
4842 c_parser_consume_token (parser);
4843 op = c_parser_cast_expression (parser, NULL);
4844 op = default_function_array_conversion (op);
4845 return parser_build_unary_op (NEGATE_EXPR, op);
4847 c_parser_consume_token (parser);
4848 op = c_parser_cast_expression (parser, NULL);
4849 op = default_function_array_conversion (op);
4850 return parser_build_unary_op (BIT_NOT_EXPR, op);
4852 c_parser_consume_token (parser);
4853 op = c_parser_cast_expression (parser, NULL);
4854 op = default_function_array_conversion (op);
4855 return parser_build_unary_op (TRUTH_NOT_EXPR, op);
4857 /* Refer to the address of a label as a pointer. */
4858 c_parser_consume_token (parser);
4859 if (c_parser_next_token_is (parser, CPP_NAME))
4861 ret.value = finish_label_address_expr
4862 (c_parser_peek_token (parser)->value);
4863 c_parser_consume_token (parser);
4867 c_parser_error (parser, "expected identifier");
4868 ret.value = error_mark_node;
4870 ret.original_code = ERROR_MARK;
4873 switch (c_parser_peek_token (parser)->keyword)
4876 return c_parser_sizeof_expression (parser);
4878 return c_parser_alignof_expression (parser);
4880 c_parser_consume_token (parser);
4881 ext = disable_extension_diagnostics ();
4882 ret = c_parser_cast_expression (parser, NULL);
4883 restore_extension_diagnostics (ext);
4886 c_parser_consume_token (parser);
4887 op = c_parser_cast_expression (parser, NULL);
4888 op = default_function_array_conversion (op);
4889 return parser_build_unary_op (REALPART_EXPR, op);
4891 c_parser_consume_token (parser);
4892 op = c_parser_cast_expression (parser, NULL);
4893 op = default_function_array_conversion (op);
4894 return parser_build_unary_op (IMAGPART_EXPR, op);
4896 return c_parser_postfix_expression (parser);
4899 return c_parser_postfix_expression (parser);
4903 /* Parse a sizeof expression. */
4905 static struct c_expr
4906 c_parser_sizeof_expression (c_parser *parser)
4909 location_t expr_loc;
4910 gcc_assert (c_parser_next_token_is_keyword (parser, RID_SIZEOF));
4911 c_parser_consume_token (parser);
4914 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
4915 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
4917 /* Either sizeof ( type-name ) or sizeof unary-expression
4918 starting with a compound literal. */
4919 struct c_type_name *type_name;
4920 c_parser_consume_token (parser);
4921 expr_loc = c_parser_peek_token (parser)->location;
4922 type_name = c_parser_type_name (parser);
4923 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4924 if (type_name == NULL)
4929 ret.value = error_mark_node;
4930 ret.original_code = ERROR_MARK;
4933 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
4935 expr = c_parser_postfix_expression_after_paren_type (parser,
4939 /* sizeof ( type-name ). */
4942 if (type_name->declarator->kind == cdk_array
4943 && type_name->declarator->u.array.vla_unspec_p)
4946 error ("%H%<[*]%> not allowed in other than a declaration",
4949 return c_expr_sizeof_type (type_name);
4953 expr_loc = c_parser_peek_token (parser)->location;
4954 expr = c_parser_unary_expression (parser);
4958 if (TREE_CODE (expr.value) == COMPONENT_REF
4959 && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
4960 error ("%H%<sizeof%> applied to a bit-field", &expr_loc);
4961 return c_expr_sizeof_expr (expr);
4965 /* Parse an alignof expression. */
4967 static struct c_expr
4968 c_parser_alignof_expression (c_parser *parser)
4971 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ALIGNOF));
4972 c_parser_consume_token (parser);
4975 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
4976 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
4978 /* Either __alignof__ ( type-name ) or __alignof__
4979 unary-expression starting with a compound literal. */
4980 struct c_type_name *type_name;
4982 c_parser_consume_token (parser);
4983 type_name = c_parser_type_name (parser);
4984 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4985 if (type_name == NULL)
4990 ret.value = error_mark_node;
4991 ret.original_code = ERROR_MARK;
4994 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
4996 expr = c_parser_postfix_expression_after_paren_type (parser,
5000 /* alignof ( type-name ). */
5003 ret.value = c_alignof (groktypename (type_name));
5004 ret.original_code = ERROR_MARK;
5010 expr = c_parser_unary_expression (parser);
5014 ret.value = c_alignof_expr (expr.value);
5015 ret.original_code = ERROR_MARK;
5020 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
5024 postfix-expression [ expression ]
5025 postfix-expression ( argument-expression-list[opt] )
5026 postfix-expression . identifier
5027 postfix-expression -> identifier
5028 postfix-expression ++
5029 postfix-expression --
5030 ( type-name ) { initializer-list }
5031 ( type-name ) { initializer-list , }
5033 argument-expression-list:
5035 argument-expression-list , argument-expression
5047 (treated as a keyword in GNU C)
5050 ( compound-statement )
5051 __builtin_va_arg ( assignment-expression , type-name )
5052 __builtin_offsetof ( type-name , offsetof-member-designator )
5053 __builtin_choose_expr ( assignment-expression ,
5054 assignment-expression ,
5055 assignment-expression )
5056 __builtin_types_compatible_p ( type-name , type-name )
5058 offsetof-member-designator:
5060 offsetof-member-designator . identifier
5061 offsetof-member-designator [ expression ]
5066 [ objc-receiver objc-message-args ]
5067 @selector ( objc-selector-arg )
5068 @protocol ( identifier )
5069 @encode ( type-name )
5073 static struct c_expr
5074 c_parser_postfix_expression (c_parser *parser)
5076 struct c_expr expr, e1, e2, e3;
5077 struct c_type_name *t1, *t2;
5079 switch (c_parser_peek_token (parser)->type)
5086 expr.value = c_parser_peek_token (parser)->value;
5087 expr.original_code = ERROR_MARK;
5088 c_parser_consume_token (parser);
5094 expr.value = c_parser_peek_token (parser)->value;
5095 expr.original_code = STRING_CST;
5096 c_parser_consume_token (parser);
5098 case CPP_OBJC_STRING:
5099 gcc_assert (c_dialect_objc ());
5101 = objc_build_string_object (c_parser_peek_token (parser)->value);
5102 expr.original_code = ERROR_MARK;
5103 c_parser_consume_token (parser);
5106 if (c_parser_peek_token (parser)->id_kind != C_ID_ID)
5108 c_parser_error (parser, "expected expression");
5109 expr.value = error_mark_node;
5110 expr.original_code = ERROR_MARK;
5114 tree id = c_parser_peek_token (parser)->value;
5115 location_t loc = c_parser_peek_token (parser)->location;
5116 c_parser_consume_token (parser);
5117 expr.value = build_external_ref (id,
5118 (c_parser_peek_token (parser)->type
5119 == CPP_OPEN_PAREN), loc);
5120 expr.original_code = ERROR_MARK;
5123 case CPP_OPEN_PAREN:
5124 /* A parenthesized expression, statement expression or compound
5126 if (c_parser_peek_2nd_token (parser)->type == CPP_OPEN_BRACE)
5128 /* A statement expression. */
5130 location_t here = c_parser_peek_token (parser)->location;
5131 c_parser_consume_token (parser);
5132 c_parser_consume_token (parser);
5133 if (cur_stmt_list == NULL)
5135 error ("%Hbraced-group within expression allowed "
5136 "only inside a function", &here);
5137 parser->error = true;
5138 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
5139 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5140 expr.value = error_mark_node;
5141 expr.original_code = ERROR_MARK;
5144 stmt = c_begin_stmt_expr ();
5145 c_parser_compound_statement_nostart (parser);
5146 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5148 pedwarn (OPT_pedantic,
5149 "%HISO C forbids braced-groups within expressions", &here);
5150 expr.value = c_finish_stmt_expr (stmt);
5151 expr.original_code = ERROR_MARK;
5153 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser)))
5155 /* A compound literal. ??? Can we actually get here rather
5156 than going directly to
5157 c_parser_postfix_expression_after_paren_type from
5159 struct c_type_name *type_name;
5160 c_parser_consume_token (parser);
5161 type_name = c_parser_type_name (parser);
5162 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5164 if (type_name == NULL)
5166 expr.value = error_mark_node;
5167 expr.original_code = ERROR_MARK;
5170 expr = c_parser_postfix_expression_after_paren_type (parser,
5175 /* A parenthesized expression. */
5176 c_parser_consume_token (parser);
5177 expr = c_parser_expression (parser);
5178 if (TREE_CODE (expr.value) == MODIFY_EXPR)
5179 TREE_NO_WARNING (expr.value) = 1;
5180 expr.original_code = ERROR_MARK;
5181 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5186 switch (c_parser_peek_token (parser)->keyword)
5188 case RID_FUNCTION_NAME:
5189 case RID_PRETTY_FUNCTION_NAME:
5190 case RID_C99_FUNCTION_NAME:
5191 expr.value = fname_decl (c_parser_peek_token (parser)->keyword,
5192 c_parser_peek_token (parser)->value);
5193 expr.original_code = ERROR_MARK;
5194 c_parser_consume_token (parser);
5197 c_parser_consume_token (parser);
5198 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5200 expr.value = error_mark_node;
5201 expr.original_code = ERROR_MARK;
5204 e1 = c_parser_expr_no_commas (parser, NULL);
5205 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5207 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5208 expr.value = error_mark_node;
5209 expr.original_code = ERROR_MARK;
5212 t1 = c_parser_type_name (parser);
5213 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5217 expr.value = error_mark_node;
5218 expr.original_code = ERROR_MARK;
5222 expr.value = build_va_arg (e1.value, groktypename (t1));
5223 expr.original_code = ERROR_MARK;
5227 c_parser_consume_token (parser);
5228 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5230 expr.value = error_mark_node;
5231 expr.original_code = ERROR_MARK;
5234 t1 = c_parser_type_name (parser);
5237 expr.value = error_mark_node;
5238 expr.original_code = ERROR_MARK;
5241 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5243 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5244 expr.value = error_mark_node;
5245 expr.original_code = ERROR_MARK;
5249 tree type = groktypename (t1);
5251 if (type == error_mark_node)
5252 offsetof_ref = error_mark_node;
5254 offsetof_ref = build1 (INDIRECT_REF, type, null_pointer_node);
5255 /* Parse the second argument to __builtin_offsetof. We
5256 must have one identifier, and beyond that we want to
5257 accept sub structure and sub array references. */
5258 if (c_parser_next_token_is (parser, CPP_NAME))
5260 offsetof_ref = build_component_ref
5261 (offsetof_ref, c_parser_peek_token (parser)->value);
5262 c_parser_consume_token (parser);
5263 while (c_parser_next_token_is (parser, CPP_DOT)
5264 || c_parser_next_token_is (parser,
5267 if (c_parser_next_token_is (parser, CPP_DOT))
5269 c_parser_consume_token (parser);
5270 if (c_parser_next_token_is_not (parser,
5273 c_parser_error (parser, "expected identifier");
5276 offsetof_ref = build_component_ref
5278 c_parser_peek_token (parser)->value);
5279 c_parser_consume_token (parser);
5284 c_parser_consume_token (parser);
5285 idx = c_parser_expression (parser).value;
5286 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
5288 offsetof_ref = build_array_ref (offsetof_ref, idx);
5293 c_parser_error (parser, "expected identifier");
5294 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5296 expr.value = fold_offsetof (offsetof_ref, NULL_TREE);
5297 expr.original_code = ERROR_MARK;
5300 case RID_CHOOSE_EXPR:
5301 c_parser_consume_token (parser);
5302 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5304 expr.value = error_mark_node;
5305 expr.original_code = ERROR_MARK;
5308 loc = c_parser_peek_token (parser)->location;
5309 e1 = c_parser_expr_no_commas (parser, NULL);
5310 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5312 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5313 expr.value = error_mark_node;
5314 expr.original_code = ERROR_MARK;
5317 e2 = c_parser_expr_no_commas (parser, NULL);
5318 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5320 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5321 expr.value = error_mark_node;
5322 expr.original_code = ERROR_MARK;
5325 e3 = c_parser_expr_no_commas (parser, NULL);
5326 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5331 c = fold (e1.value);
5332 if (TREE_CODE (c) != INTEGER_CST)
5333 error ("%Hfirst argument to %<__builtin_choose_expr%> not"
5334 " a constant", &loc);
5335 expr = integer_zerop (c) ? e3 : e2;
5338 case RID_TYPES_COMPATIBLE_P:
5339 c_parser_consume_token (parser);
5340 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5342 expr.value = error_mark_node;
5343 expr.original_code = ERROR_MARK;
5346 t1 = c_parser_type_name (parser);
5349 expr.value = error_mark_node;
5350 expr.original_code = ERROR_MARK;
5353 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5355 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5356 expr.value = error_mark_node;
5357 expr.original_code = ERROR_MARK;
5360 t2 = c_parser_type_name (parser);
5363 expr.value = error_mark_node;
5364 expr.original_code = ERROR_MARK;
5367 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5372 e1 = TYPE_MAIN_VARIANT (groktypename (t1));
5373 e2 = TYPE_MAIN_VARIANT (groktypename (t2));
5375 expr.value = comptypes (e1, e2)
5376 ? build_int_cst (NULL_TREE, 1)
5377 : build_int_cst (NULL_TREE, 0);
5378 expr.original_code = ERROR_MARK;
5381 case RID_AT_SELECTOR:
5382 gcc_assert (c_dialect_objc ());
5383 c_parser_consume_token (parser);
5384 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5386 expr.value = error_mark_node;
5387 expr.original_code = ERROR_MARK;
5391 tree sel = c_parser_objc_selector_arg (parser);
5392 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5394 expr.value = objc_build_selector_expr (sel);
5395 expr.original_code = ERROR_MARK;
5398 case RID_AT_PROTOCOL:
5399 gcc_assert (c_dialect_objc ());
5400 c_parser_consume_token (parser);
5401 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5403 expr.value = error_mark_node;
5404 expr.original_code = ERROR_MARK;
5407 if (c_parser_next_token_is_not (parser, CPP_NAME))
5409 c_parser_error (parser, "expected identifier");
5410 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5411 expr.value = error_mark_node;
5412 expr.original_code = ERROR_MARK;
5416 tree id = c_parser_peek_token (parser)->value;
5417 c_parser_consume_token (parser);
5418 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5420 expr.value = objc_build_protocol_expr (id);
5421 expr.original_code = ERROR_MARK;
5425 /* Extension to support C-structures in the archiver. */
5426 gcc_assert (c_dialect_objc ());
5427 c_parser_consume_token (parser);
5428 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5430 expr.value = error_mark_node;
5431 expr.original_code = ERROR_MARK;
5434 t1 = c_parser_type_name (parser);
5437 expr.value = error_mark_node;
5438 expr.original_code = ERROR_MARK;
5439 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5442 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5445 tree type = groktypename (t1);
5446 expr.value = objc_build_encode_expr (type);
5447 expr.original_code = ERROR_MARK;
5451 c_parser_error (parser, "expected expression");
5452 expr.value = error_mark_node;
5453 expr.original_code = ERROR_MARK;
5457 case CPP_OPEN_SQUARE:
5458 if (c_dialect_objc ())
5460 tree receiver, args;
5461 c_parser_consume_token (parser);
5462 receiver = c_parser_objc_receiver (parser);
5463 args = c_parser_objc_message_args (parser);
5464 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
5466 expr.value = objc_build_message_expr (build_tree_list (receiver,
5468 expr.original_code = ERROR_MARK;
5471 /* Else fall through to report error. */
5473 c_parser_error (parser, "expected expression");
5474 expr.value = error_mark_node;
5475 expr.original_code = ERROR_MARK;
5478 return c_parser_postfix_expression_after_primary (parser, expr);
5481 /* Parse a postfix expression after a parenthesized type name: the
5482 brace-enclosed initializer of a compound literal, possibly followed
5483 by some postfix operators. This is separate because it is not
5484 possible to tell until after the type name whether a cast
5485 expression has a cast or a compound literal, or whether the operand
5486 of sizeof is a parenthesized type name or starts with a compound
5489 static struct c_expr
5490 c_parser_postfix_expression_after_paren_type (c_parser *parser,
5491 struct c_type_name *type_name)
5496 location_t start_loc;
5497 start_init (NULL_TREE, NULL, 0);
5498 type = groktypename (type_name);
5499 start_loc = c_parser_peek_token (parser)->location;
5500 if (type != error_mark_node && C_TYPE_VARIABLE_SIZE (type))
5502 error ("%Hcompound literal has variable size", &start_loc);
5503 type = error_mark_node;
5505 init = c_parser_braced_init (parser, type, false);
5507 maybe_warn_string_init (type, init);
5510 pedwarn (OPT_pedantic, "%HISO C90 forbids compound literals",
5512 expr.value = build_compound_literal (type, init.value);
5513 expr.original_code = ERROR_MARK;
5514 return c_parser_postfix_expression_after_primary (parser, expr);
5517 /* Parse a postfix expression after the initial primary or compound
5518 literal; that is, parse a series of postfix operators. */
5520 static struct c_expr
5521 c_parser_postfix_expression_after_primary (c_parser *parser,
5524 tree ident, idx, exprlist;
5527 switch (c_parser_peek_token (parser)->type)
5529 case CPP_OPEN_SQUARE:
5530 /* Array reference. */
5531 c_parser_consume_token (parser);
5532 idx = c_parser_expression (parser).value;
5533 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
5535 expr.value = build_array_ref (expr.value, idx);
5536 expr.original_code = ERROR_MARK;
5538 case CPP_OPEN_PAREN:
5539 /* Function call. */
5540 c_parser_consume_token (parser);
5541 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
5542 exprlist = NULL_TREE;
5544 exprlist = c_parser_expr_list (parser, true);
5545 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5547 expr.value = build_function_call (expr.value, exprlist);
5548 expr.original_code = ERROR_MARK;
5549 if (warn_disallowed_functions)
5550 warn_if_disallowed_function_p (expr.value);
5553 /* Structure element reference. */
5554 c_parser_consume_token (parser);
5555 expr = default_function_array_conversion (expr);
5556 if (c_parser_next_token_is (parser, CPP_NAME))
5557 ident = c_parser_peek_token (parser)->value;
5560 c_parser_error (parser, "expected identifier");
5561 expr.value = error_mark_node;
5562 expr.original_code = ERROR_MARK;
5565 c_parser_consume_token (parser);
5566 expr.value = build_component_ref (expr.value, ident);
5567 expr.original_code = ERROR_MARK;
5570 /* Structure element reference. */
5571 c_parser_consume_token (parser);
5572 expr = default_function_array_conversion (expr);
5573 if (c_parser_next_token_is (parser, CPP_NAME))
5574 ident = c_parser_peek_token (parser)->value;
5577 c_parser_error (parser, "expected identifier");
5578 expr.value = error_mark_node;
5579 expr.original_code = ERROR_MARK;
5582 c_parser_consume_token (parser);
5583 expr.value = build_component_ref (build_indirect_ref (expr.value,
5585 expr.original_code = ERROR_MARK;
5588 /* Postincrement. */
5589 c_parser_consume_token (parser);
5590 expr = default_function_array_conversion (expr);
5591 expr.value = build_unary_op (POSTINCREMENT_EXPR, expr.value, 0);
5592 expr.original_code = ERROR_MARK;
5594 case CPP_MINUS_MINUS:
5595 /* Postdecrement. */
5596 c_parser_consume_token (parser);
5597 expr = default_function_array_conversion (expr);
5598 expr.value = build_unary_op (POSTDECREMENT_EXPR, expr.value, 0);
5599 expr.original_code = ERROR_MARK;
5607 /* Parse an expression (C90 6.3.17, C99 6.5.17).
5610 assignment-expression
5611 expression , assignment-expression
5614 static struct c_expr
5615 c_parser_expression (c_parser *parser)
5618 expr = c_parser_expr_no_commas (parser, NULL);
5619 while (c_parser_next_token_is (parser, CPP_COMMA))
5622 c_parser_consume_token (parser);
5623 next = c_parser_expr_no_commas (parser, NULL);
5624 next = default_function_array_conversion (next);
5625 expr.value = build_compound_expr (expr.value, next.value);
5626 expr.original_code = COMPOUND_EXPR;
5631 /* Parse an expression and convert functions or arrays to
5634 static struct c_expr
5635 c_parser_expression_conv (c_parser *parser)
5638 expr = c_parser_expression (parser);
5639 expr = default_function_array_conversion (expr);
5643 /* Parse a non-empty list of expressions. If CONVERT_P, convert
5644 functions and arrays to pointers.
5647 assignment-expression
5648 nonempty-expr-list , assignment-expression
5652 c_parser_expr_list (c_parser *parser, bool convert_p)
5656 expr = c_parser_expr_no_commas (parser, NULL);
5658 expr = default_function_array_conversion (expr);
5659 ret = cur = build_tree_list (NULL_TREE, expr.value);
5660 while (c_parser_next_token_is (parser, CPP_COMMA))
5662 c_parser_consume_token (parser);
5663 expr = c_parser_expr_no_commas (parser, NULL);
5665 expr = default_function_array_conversion (expr);
5666 cur = TREE_CHAIN (cur) = build_tree_list (NULL_TREE, expr.value);
5672 /* Parse Objective-C-specific constructs. */
5674 /* Parse an objc-class-definition.
5676 objc-class-definition:
5677 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
5678 objc-class-instance-variables[opt] objc-methodprotolist @end
5679 @implementation identifier objc-superclass[opt]
5680 objc-class-instance-variables[opt]
5681 @interface identifier ( identifier ) objc-protocol-refs[opt]
5682 objc-methodprotolist @end
5683 @implementation identifier ( identifier )
5688 "@interface identifier (" must start "@interface identifier (
5689 identifier ) ...": objc-methodprotolist in the first production may
5690 not start with a parenthesized identifier as a declarator of a data
5691 definition with no declaration specifiers if the objc-superclass,
5692 objc-protocol-refs and objc-class-instance-variables are omitted. */
5695 c_parser_objc_class_definition (c_parser *parser)
5700 if (c_parser_next_token_is_keyword (parser, RID_AT_INTERFACE))
5702 else if (c_parser_next_token_is_keyword (parser, RID_AT_IMPLEMENTATION))
5706 c_parser_consume_token (parser);
5707 if (c_parser_next_token_is_not (parser, CPP_NAME))
5709 c_parser_error (parser, "expected identifier");
5712 id1 = c_parser_peek_token (parser)->value;
5713 c_parser_consume_token (parser);
5714 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
5717 tree proto = NULL_TREE;
5718 c_parser_consume_token (parser);
5719 if (c_parser_next_token_is_not (parser, CPP_NAME))
5721 c_parser_error (parser, "expected identifier");
5722 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5725 id2 = c_parser_peek_token (parser)->value;
5726 c_parser_consume_token (parser);
5727 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5730 objc_start_category_implementation (id1, id2);
5733 if (c_parser_next_token_is (parser, CPP_LESS))
5734 proto = c_parser_objc_protocol_refs (parser);
5735 objc_start_category_interface (id1, id2, proto);
5736 c_parser_objc_methodprotolist (parser);
5737 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
5738 objc_finish_interface ();
5741 if (c_parser_next_token_is (parser, CPP_COLON))
5743 c_parser_consume_token (parser);
5744 if (c_parser_next_token_is_not (parser, CPP_NAME))
5746 c_parser_error (parser, "expected identifier");
5749 superclass = c_parser_peek_token (parser)->value;
5750 c_parser_consume_token (parser);
5753 superclass = NULL_TREE;
5756 tree proto = NULL_TREE;
5757 if (c_parser_next_token_is (parser, CPP_LESS))
5758 proto = c_parser_objc_protocol_refs (parser);
5759 objc_start_class_interface (id1, superclass, proto);
5762 objc_start_class_implementation (id1, superclass);
5763 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
5764 c_parser_objc_class_instance_variables (parser);
5767 objc_continue_interface ();
5768 c_parser_objc_methodprotolist (parser);
5769 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
5770 objc_finish_interface ();
5774 objc_continue_implementation ();
5779 /* Parse objc-class-instance-variables.
5781 objc-class-instance-variables:
5782 { objc-instance-variable-decl-list[opt] }
5784 objc-instance-variable-decl-list:
5785 objc-visibility-spec
5786 objc-instance-variable-decl ;
5788 objc-instance-variable-decl-list objc-visibility-spec
5789 objc-instance-variable-decl-list objc-instance-variable-decl ;
5790 objc-instance-variable-decl-list ;
5792 objc-visibility-spec:
5797 objc-instance-variable-decl:
5802 c_parser_objc_class_instance_variables (c_parser *parser)
5804 gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE));
5805 c_parser_consume_token (parser);
5806 while (c_parser_next_token_is_not (parser, CPP_EOF))
5809 /* Parse any stray semicolon. */
5810 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
5812 pedwarn (OPT_pedantic,
5813 "%Hextra semicolon in struct or union specified",
5814 &c_parser_peek_token (parser)->location);
5815 c_parser_consume_token (parser);
5818 /* Stop if at the end of the instance variables. */
5819 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
5821 c_parser_consume_token (parser);
5824 /* Parse any objc-visibility-spec. */
5825 if (c_parser_next_token_is_keyword (parser, RID_PRIVATE))
5827 c_parser_consume_token (parser);
5828 objc_set_visibility (2);
5831 else if (c_parser_next_token_is_keyword (parser, RID_PROTECTED))
5833 c_parser_consume_token (parser);
5834 objc_set_visibility (0);
5837 else if (c_parser_next_token_is_keyword (parser, RID_PUBLIC))
5839 c_parser_consume_token (parser);
5840 objc_set_visibility (1);
5843 else if (c_parser_next_token_is (parser, CPP_PRAGMA))
5845 c_parser_pragma (parser, pragma_external);
5849 /* Parse some comma-separated declarations. */
5850 decls = c_parser_struct_declaration (parser);
5852 /* Comma-separated instance variables are chained together in
5853 reverse order; add them one by one. */
5854 tree ivar = nreverse (decls);
5855 for (; ivar; ivar = TREE_CHAIN (ivar))
5856 objc_add_instance_variable (copy_node (ivar));
5858 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
5862 /* Parse an objc-class-declaration.
5864 objc-class-declaration:
5865 @class identifier-list ;
5869 c_parser_objc_class_declaration (c_parser *parser)
5871 tree list = NULL_TREE;
5872 gcc_assert (c_parser_next_token_is_keyword (parser, RID_CLASS));
5873 c_parser_consume_token (parser);
5874 /* Any identifiers, including those declared as type names, are OK
5879 if (c_parser_next_token_is_not (parser, CPP_NAME))
5881 c_parser_error (parser, "expected identifier");
5884 id = c_parser_peek_token (parser)->value;
5885 list = chainon (list, build_tree_list (NULL_TREE, id));
5886 c_parser_consume_token (parser);
5887 if (c_parser_next_token_is (parser, CPP_COMMA))
5888 c_parser_consume_token (parser);
5892 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
5893 objc_declare_class (list);
5896 /* Parse an objc-alias-declaration.
5898 objc-alias-declaration:
5899 @compatibility_alias identifier identifier ;
5903 c_parser_objc_alias_declaration (c_parser *parser)
5906 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_ALIAS));
5907 c_parser_consume_token (parser);
5908 if (c_parser_next_token_is_not (parser, CPP_NAME))
5910 c_parser_error (parser, "expected identifier");
5911 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
5914 id1 = c_parser_peek_token (parser)->value;
5915 c_parser_consume_token (parser);
5916 if (c_parser_next_token_is_not (parser, CPP_NAME))
5918 c_parser_error (parser, "expected identifier");
5919 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
5922 id2 = c_parser_peek_token (parser)->value;
5923 c_parser_consume_token (parser);
5924 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
5925 objc_declare_alias (id1, id2);
5928 /* Parse an objc-protocol-definition.
5930 objc-protocol-definition:
5931 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
5932 @protocol identifier-list ;
5934 "@protocol identifier ;" should be resolved as "@protocol
5935 identifier-list ;": objc-methodprotolist may not start with a
5936 semicolon in the first alternative if objc-protocol-refs are
5940 c_parser_objc_protocol_definition (c_parser *parser)
5942 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_PROTOCOL));
5943 c_parser_consume_token (parser);
5944 if (c_parser_next_token_is_not (parser, CPP_NAME))
5946 c_parser_error (parser, "expected identifier");
5949 if (c_parser_peek_2nd_token (parser)->type == CPP_COMMA
5950 || c_parser_peek_2nd_token (parser)->type == CPP_SEMICOLON)
5952 tree list = NULL_TREE;
5953 /* Any identifiers, including those declared as type names, are
5958 if (c_parser_next_token_is_not (parser, CPP_NAME))
5960 c_parser_error (parser, "expected identifier");
5963 id = c_parser_peek_token (parser)->value;
5964 list = chainon (list, build_tree_list (NULL_TREE, id));
5965 c_parser_consume_token (parser);
5966 if (c_parser_next_token_is (parser, CPP_COMMA))
5967 c_parser_consume_token (parser);
5971 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
5972 objc_declare_protocols (list);
5976 tree id = c_parser_peek_token (parser)->value;
5977 tree proto = NULL_TREE;
5978 c_parser_consume_token (parser);
5979 if (c_parser_next_token_is (parser, CPP_LESS))
5980 proto = c_parser_objc_protocol_refs (parser);
5981 parser->objc_pq_context = true;
5982 objc_start_protocol (id, proto);
5983 c_parser_objc_methodprotolist (parser);
5984 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
5985 parser->objc_pq_context = false;
5986 objc_finish_interface ();
5990 /* Parse an objc-method-type.
5997 static enum tree_code
5998 c_parser_objc_method_type (c_parser *parser)
6000 switch (c_parser_peek_token (parser)->type)
6003 c_parser_consume_token (parser);
6006 c_parser_consume_token (parser);
6013 /* Parse an objc-method-definition.
6015 objc-method-definition:
6016 objc-method-type objc-method-decl ;[opt] compound-statement
6020 c_parser_objc_method_definition (c_parser *parser)
6022 enum tree_code type = c_parser_objc_method_type (parser);
6024 objc_set_method_type (type);
6025 parser->objc_pq_context = true;
6026 decl = c_parser_objc_method_decl (parser);
6027 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
6029 c_parser_consume_token (parser);
6030 pedwarn (OPT_pedantic,
6031 "%Hextra semicolon in method definition specified",
6032 &c_parser_peek_token (parser)->location);
6034 if (!c_parser_next_token_is (parser, CPP_OPEN_BRACE))
6036 c_parser_error (parser, "expected %<{%>");
6039 parser->objc_pq_context = false;
6040 objc_start_method_definition (decl);
6041 add_stmt (c_parser_compound_statement (parser));
6042 objc_finish_method_definition (current_function_decl);
6045 /* Parse an objc-methodprotolist.
6047 objc-methodprotolist:
6049 objc-methodprotolist objc-methodproto
6050 objc-methodprotolist declaration
6051 objc-methodprotolist ;
6053 The declaration is a data definition, which may be missing
6054 declaration specifiers under the same rules and diagnostics as
6055 other data definitions outside functions, and the stray semicolon
6056 is diagnosed the same way as a stray semicolon outside a
6060 c_parser_objc_methodprotolist (c_parser *parser)
6064 /* The list is terminated by @end. */
6065 switch (c_parser_peek_token (parser)->type)
6068 pedwarn (OPT_pedantic, "%HISO C does not allow extra %<;%> "
6069 "outside of a function",
6070 &c_parser_peek_token (parser)->location);
6071 c_parser_consume_token (parser);
6075 c_parser_objc_methodproto (parser);
6078 c_parser_pragma (parser, pragma_external);
6083 if (c_parser_next_token_is_keyword (parser, RID_AT_END))
6085 c_parser_declaration_or_fndef (parser, false, true, false, true);
6091 /* Parse an objc-methodproto.
6094 objc-method-type objc-method-decl ;
6098 c_parser_objc_methodproto (c_parser *parser)
6100 enum tree_code type = c_parser_objc_method_type (parser);
6102 objc_set_method_type (type);
6103 /* Remember protocol qualifiers in prototypes. */
6104 parser->objc_pq_context = true;
6105 decl = c_parser_objc_method_decl (parser);
6106 /* Forget protocol qualifiers here. */
6107 parser->objc_pq_context = false;
6108 objc_add_method_declaration (decl);
6109 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
6112 /* Parse an objc-method-decl.
6115 ( objc-type-name ) objc-selector
6117 ( objc-type-name ) objc-keyword-selector objc-optparmlist
6118 objc-keyword-selector objc-optparmlist
6120 objc-keyword-selector:
6122 objc-keyword-selector objc-keyword-decl
6125 objc-selector : ( objc-type-name ) identifier
6126 objc-selector : identifier
6127 : ( objc-type-name ) identifier
6131 objc-optparms objc-optellipsis
6135 objc-opt-parms , parameter-declaration
6143 c_parser_objc_method_decl (c_parser *parser)
6145 tree type = NULL_TREE;
6147 tree parms = NULL_TREE;
6148 bool ellipsis = false;
6150 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
6152 c_parser_consume_token (parser);
6153 type = c_parser_objc_type_name (parser);
6154 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6156 sel = c_parser_objc_selector (parser);
6157 /* If there is no selector, or a colon follows, we have an
6158 objc-keyword-selector. If there is a selector, and a colon does
6159 not follow, that selector ends the objc-method-decl. */
6160 if (!sel || c_parser_next_token_is (parser, CPP_COLON))
6163 tree list = NULL_TREE;
6166 tree atype = NULL_TREE, id, keyworddecl;
6167 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
6169 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
6171 c_parser_consume_token (parser);
6172 atype = c_parser_objc_type_name (parser);
6173 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6176 if (c_parser_next_token_is_not (parser, CPP_NAME))
6178 c_parser_error (parser, "expected identifier");
6179 return error_mark_node;
6181 id = c_parser_peek_token (parser)->value;
6182 c_parser_consume_token (parser);
6183 keyworddecl = objc_build_keyword_decl (tsel, atype, id);
6184 list = chainon (list, keyworddecl);
6185 tsel = c_parser_objc_selector (parser);
6186 if (!tsel && c_parser_next_token_is_not (parser, CPP_COLON))
6189 /* Parse the optional parameter list. Optional Objective-C
6190 method parameters follow the C syntax, and may include '...'
6191 to denote a variable number of arguments. */
6192 parms = make_node (TREE_LIST);
6193 while (c_parser_next_token_is (parser, CPP_COMMA))
6195 struct c_parm *parm;
6196 c_parser_consume_token (parser);
6197 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
6200 c_parser_consume_token (parser);
6203 parm = c_parser_parameter_declaration (parser, NULL_TREE);
6206 parms = chainon (parms,
6207 build_tree_list (NULL_TREE, grokparm (parm)));
6211 return objc_build_method_signature (type, sel, parms, ellipsis);
6214 /* Parse an objc-type-name.
6217 objc-type-qualifiers[opt] type-name
6218 objc-type-qualifiers[opt]
6220 objc-type-qualifiers:
6222 objc-type-qualifiers objc-type-qualifier
6224 objc-type-qualifier: one of
6225 in out inout bycopy byref oneway
6229 c_parser_objc_type_name (c_parser *parser)
6231 tree quals = NULL_TREE;
6232 struct c_type_name *type_name = NULL;
6233 tree type = NULL_TREE;
6236 c_token *token = c_parser_peek_token (parser);
6237 if (token->type == CPP_KEYWORD
6238 && (token->keyword == RID_IN
6239 || token->keyword == RID_OUT
6240 || token->keyword == RID_INOUT
6241 || token->keyword == RID_BYCOPY
6242 || token->keyword == RID_BYREF
6243 || token->keyword == RID_ONEWAY))
6245 quals = chainon (quals, build_tree_list (NULL_TREE, token->value));
6246 c_parser_consume_token (parser);
6251 if (c_parser_next_token_starts_typename (parser))
6252 type_name = c_parser_type_name (parser);
6254 type = groktypename (type_name);
6255 return build_tree_list (quals, type);
6258 /* Parse objc-protocol-refs.
6265 c_parser_objc_protocol_refs (c_parser *parser)
6267 tree list = NULL_TREE;
6268 gcc_assert (c_parser_next_token_is (parser, CPP_LESS));
6269 c_parser_consume_token (parser);
6270 /* Any identifiers, including those declared as type names, are OK
6275 if (c_parser_next_token_is_not (parser, CPP_NAME))
6277 c_parser_error (parser, "expected identifier");
6280 id = c_parser_peek_token (parser)->value;
6281 list = chainon (list, build_tree_list (NULL_TREE, id));
6282 c_parser_consume_token (parser);
6283 if (c_parser_next_token_is (parser, CPP_COMMA))
6284 c_parser_consume_token (parser);
6288 c_parser_require (parser, CPP_GREATER, "expected %<>%>");
6292 /* Parse an objc-try-catch-statement.
6294 objc-try-catch-statement:
6295 @try compound-statement objc-catch-list[opt]
6296 @try compound-statement objc-catch-list[opt] @finally compound-statement
6299 @catch ( parameter-declaration ) compound-statement
6300 objc-catch-list @catch ( parameter-declaration ) compound-statement
6304 c_parser_objc_try_catch_statement (c_parser *parser)
6308 gcc_assert (c_parser_next_token_is_keyword (parser, RID_TRY));
6309 c_parser_consume_token (parser);
6310 loc = c_parser_peek_token (parser)->location;
6311 stmt = c_parser_compound_statement (parser);
6312 objc_begin_try_stmt (loc, stmt);
6313 while (c_parser_next_token_is_keyword (parser, RID_CATCH))
6315 struct c_parm *parm;
6316 c_parser_consume_token (parser);
6317 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6319 parm = c_parser_parameter_declaration (parser, NULL_TREE);
6322 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6325 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6326 objc_begin_catch_clause (grokparm (parm));
6327 if (c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
6328 c_parser_compound_statement_nostart (parser);
6329 objc_finish_catch_clause ();
6331 if (c_parser_next_token_is_keyword (parser, RID_AT_FINALLY))
6335 c_parser_consume_token (parser);
6336 finloc = c_parser_peek_token (parser)->location;
6337 finstmt = c_parser_compound_statement (parser);
6338 objc_build_finally_clause (finloc, finstmt);
6340 objc_finish_try_stmt ();
6343 /* Parse an objc-synchronized-statement.
6345 objc-synchronized-statement:
6346 @synchronized ( expression ) compound-statement
6350 c_parser_objc_synchronized_statement (c_parser *parser)
6354 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_SYNCHRONIZED));
6355 c_parser_consume_token (parser);
6356 loc = c_parser_peek_token (parser)->location;
6357 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6359 expr = c_parser_expression (parser).value;
6360 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6363 expr = error_mark_node;
6364 stmt = c_parser_compound_statement (parser);
6365 objc_build_synchronized (loc, expr, stmt);
6368 /* Parse an objc-selector; return NULL_TREE without an error if the
6369 next token is not an objc-selector.
6374 enum struct union if else while do for switch case default
6375 break continue return goto asm sizeof typeof __alignof
6376 unsigned long const short volatile signed restrict _Complex
6377 in out inout bycopy byref oneway int char float double void _Bool
6379 ??? Why this selection of keywords but not, for example, storage
6380 class specifiers? */
6383 c_parser_objc_selector (c_parser *parser)
6385 c_token *token = c_parser_peek_token (parser);
6386 tree value = token->value;
6387 if (token->type == CPP_NAME)
6389 c_parser_consume_token (parser);
6392 if (token->type != CPP_KEYWORD)
6394 switch (token->keyword)
6435 c_parser_consume_token (parser);
6442 /* Parse an objc-selector-arg.
6446 objc-keywordname-list
6448 objc-keywordname-list:
6450 objc-keywordname-list objc-keywordname
6458 c_parser_objc_selector_arg (c_parser *parser)
6460 tree sel = c_parser_objc_selector (parser);
6461 tree list = NULL_TREE;
6462 if (sel && c_parser_next_token_is_not (parser, CPP_COLON))
6466 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
6468 list = chainon (list, build_tree_list (sel, NULL_TREE));
6469 sel = c_parser_objc_selector (parser);
6470 if (!sel && c_parser_next_token_is_not (parser, CPP_COLON))
6476 /* Parse an objc-receiver.
6485 c_parser_objc_receiver (c_parser *parser)
6487 if (c_parser_peek_token (parser)->type == CPP_NAME
6488 && (c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME
6489 || c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME))
6491 tree id = c_parser_peek_token (parser)->value;
6492 c_parser_consume_token (parser);
6493 return objc_get_class_reference (id);
6495 return c_parser_expression (parser).value;
6498 /* Parse objc-message-args.
6502 objc-keywordarg-list
6504 objc-keywordarg-list:
6506 objc-keywordarg-list objc-keywordarg
6509 objc-selector : objc-keywordexpr
6514 c_parser_objc_message_args (c_parser *parser)
6516 tree sel = c_parser_objc_selector (parser);
6517 tree list = NULL_TREE;
6518 if (sel && c_parser_next_token_is_not (parser, CPP_COLON))
6523 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
6525 keywordexpr = c_parser_objc_keywordexpr (parser);
6526 list = chainon (list, build_tree_list (sel, keywordexpr));
6527 sel = c_parser_objc_selector (parser);
6528 if (!sel && c_parser_next_token_is_not (parser, CPP_COLON))
6534 /* Parse an objc-keywordexpr.
6541 c_parser_objc_keywordexpr (c_parser *parser)
6543 tree list = c_parser_expr_list (parser, true);
6544 if (TREE_CHAIN (list) == NULL_TREE)
6546 /* Just return the expression, remove a level of
6548 return TREE_VALUE (list);
6552 /* We have a comma expression, we will collapse later. */
6558 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
6559 should be considered, statements. ALLOW_STMT is true if we're within
6560 the context of a function and such pragmas are to be allowed. Returns
6561 true if we actually parsed such a pragma. */
6564 c_parser_pragma (c_parser *parser, enum pragma_context context)
6568 id = c_parser_peek_token (parser)->pragma_kind;
6569 gcc_assert (id != PRAGMA_NONE);
6573 case PRAGMA_OMP_BARRIER:
6574 if (context != pragma_compound)
6576 if (context == pragma_stmt)
6577 c_parser_error (parser, "%<#pragma omp barrier%> may only be "
6578 "used in compound statements");
6581 c_parser_omp_barrier (parser);
6584 case PRAGMA_OMP_FLUSH:
6585 if (context != pragma_compound)
6587 if (context == pragma_stmt)
6588 c_parser_error (parser, "%<#pragma omp flush%> may only be "
6589 "used in compound statements");
6592 c_parser_omp_flush (parser);
6595 case PRAGMA_OMP_TASKWAIT:
6596 if (context != pragma_compound)
6598 if (context == pragma_stmt)
6599 c_parser_error (parser, "%<#pragma omp taskwait%> may only be "
6600 "used in compound statements");
6603 c_parser_omp_taskwait (parser);
6606 case PRAGMA_OMP_THREADPRIVATE:
6607 c_parser_omp_threadprivate (parser);
6610 case PRAGMA_OMP_SECTION:
6611 error ("%H%<#pragma omp section%> may only be used in "
6612 "%<#pragma omp sections%> construct",
6613 &c_parser_peek_token (parser)->location);
6614 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
6617 case PRAGMA_GCC_PCH_PREPROCESS:
6618 c_parser_error (parser, "%<#pragma GCC pch_preprocess%> must be first");
6619 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
6623 if (id < PRAGMA_FIRST_EXTERNAL)
6625 if (context == pragma_external)
6628 c_parser_error (parser, "expected declaration specifiers");
6629 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
6632 c_parser_omp_construct (parser);
6638 c_parser_consume_pragma (parser);
6639 c_invoke_pragma_handler (id);
6641 /* Skip to EOL, but suppress any error message. Those will have been
6642 generated by the handler routine through calling error, as opposed
6643 to calling c_parser_error. */
6644 parser->error = true;
6645 c_parser_skip_to_pragma_eol (parser);
6650 /* The interface the pragma parsers have to the lexer. */
6653 pragma_lex (tree *value)
6655 c_token *tok = c_parser_peek_token (the_parser);
6656 enum cpp_ttype ret = tok->type;
6658 *value = tok->value;
6659 if (ret == CPP_PRAGMA_EOL || ret == CPP_EOF)
6663 if (ret == CPP_KEYWORD)
6665 c_parser_consume_token (the_parser);
6672 c_parser_pragma_pch_preprocess (c_parser *parser)
6676 c_parser_consume_pragma (parser);
6677 if (c_parser_next_token_is (parser, CPP_STRING))
6679 name = c_parser_peek_token (parser)->value;
6680 c_parser_consume_token (parser);
6683 c_parser_error (parser, "expected string literal");
6684 c_parser_skip_to_pragma_eol (parser);
6687 c_common_pch_pragma (parse_in, TREE_STRING_POINTER (name));
6690 /* OpenMP 2.5 parsing routines. */
6692 /* Returns name of the next clause.
6693 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
6694 the token is not consumed. Otherwise appropriate pragma_omp_clause is
6695 returned and the token is consumed. */
6697 static pragma_omp_clause
6698 c_parser_omp_clause_name (c_parser *parser)
6700 pragma_omp_clause result = PRAGMA_OMP_CLAUSE_NONE;
6702 if (c_parser_next_token_is_keyword (parser, RID_IF))
6703 result = PRAGMA_OMP_CLAUSE_IF;
6704 else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT))
6705 result = PRAGMA_OMP_CLAUSE_DEFAULT;
6706 else if (c_parser_next_token_is (parser, CPP_NAME))
6708 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
6713 if (!strcmp ("collapse", p))
6714 result = PRAGMA_OMP_CLAUSE_COLLAPSE;
6715 else if (!strcmp ("copyin", p))
6716 result = PRAGMA_OMP_CLAUSE_COPYIN;
6717 else if (!strcmp ("copyprivate", p))
6718 result = PRAGMA_OMP_CLAUSE_COPYPRIVATE;
6721 if (!strcmp ("firstprivate", p))
6722 result = PRAGMA_OMP_CLAUSE_FIRSTPRIVATE;
6725 if (!strcmp ("lastprivate", p))
6726 result = PRAGMA_OMP_CLAUSE_LASTPRIVATE;
6729 if (!strcmp ("nowait", p))
6730 result = PRAGMA_OMP_CLAUSE_NOWAIT;
6731 else if (!strcmp ("num_threads", p))
6732 result = PRAGMA_OMP_CLAUSE_NUM_THREADS;
6735 if (!strcmp ("ordered", p))
6736 result = PRAGMA_OMP_CLAUSE_ORDERED;
6739 if (!strcmp ("private", p))
6740 result = PRAGMA_OMP_CLAUSE_PRIVATE;
6743 if (!strcmp ("reduction", p))
6744 result = PRAGMA_OMP_CLAUSE_REDUCTION;
6747 if (!strcmp ("schedule", p))
6748 result = PRAGMA_OMP_CLAUSE_SCHEDULE;
6749 else if (!strcmp ("shared", p))
6750 result = PRAGMA_OMP_CLAUSE_SHARED;
6753 if (!strcmp ("untied", p))
6754 result = PRAGMA_OMP_CLAUSE_UNTIED;
6759 if (result != PRAGMA_OMP_CLAUSE_NONE)
6760 c_parser_consume_token (parser);
6765 /* Validate that a clause of the given type does not already exist. */
6768 check_no_duplicate_clause (tree clauses, enum omp_clause_code code,
6773 for (c = clauses; c ; c = OMP_CLAUSE_CHAIN (c))
6774 if (OMP_CLAUSE_CODE (c) == code)
6776 error ("too many %qs clauses", name);
6784 variable-list , identifier
6786 If KIND is nonzero, create the appropriate node and install the decl
6787 in OMP_CLAUSE_DECL and add the node to the head of the list.
6789 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
6790 return the list created. */
6793 c_parser_omp_variable_list (c_parser *parser, enum omp_clause_code kind,
6796 if (c_parser_next_token_is_not (parser, CPP_NAME)
6797 || c_parser_peek_token (parser)->id_kind != C_ID_ID)
6798 c_parser_error (parser, "expected identifier");
6800 while (c_parser_next_token_is (parser, CPP_NAME)
6801 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
6803 tree t = lookup_name (c_parser_peek_token (parser)->value);
6806 undeclared_variable (c_parser_peek_token (parser)->value,
6807 c_parser_peek_token (parser)->location);
6808 else if (t == error_mark_node)
6812 tree u = build_omp_clause (kind);
6813 OMP_CLAUSE_DECL (u) = t;
6814 OMP_CLAUSE_CHAIN (u) = list;
6818 list = tree_cons (t, NULL_TREE, list);
6820 c_parser_consume_token (parser);
6822 if (c_parser_next_token_is_not (parser, CPP_COMMA))
6825 c_parser_consume_token (parser);
6831 /* Similarly, but expect leading and trailing parenthesis. This is a very
6832 common case for omp clauses. */
6835 c_parser_omp_var_list_parens (c_parser *parser, enum omp_clause_code kind,
6838 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6840 list = c_parser_omp_variable_list (parser, kind, list);
6841 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6847 collapse ( constant-expression ) */
6850 c_parser_omp_clause_collapse (c_parser *parser, tree list)
6852 tree c, num = error_mark_node;
6856 check_no_duplicate_clause (list, OMP_CLAUSE_COLLAPSE, "collapse");
6858 loc = c_parser_peek_token (parser)->location;
6859 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6861 num = c_parser_expr_no_commas (parser, NULL).value;
6862 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6864 if (num == error_mark_node)
6866 if (!INTEGRAL_TYPE_P (TREE_TYPE (num))
6867 || !host_integerp (num, 0)
6868 || (n = tree_low_cst (num, 0)) <= 0
6871 error ("%Hcollapse argument needs positive constant integer expression",
6875 c = build_omp_clause (OMP_CLAUSE_COLLAPSE);
6876 OMP_CLAUSE_COLLAPSE_EXPR (c) = num;
6877 OMP_CLAUSE_CHAIN (c) = list;
6882 copyin ( variable-list ) */
6885 c_parser_omp_clause_copyin (c_parser *parser, tree list)
6887 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYIN, list);
6891 copyprivate ( variable-list ) */
6894 c_parser_omp_clause_copyprivate (c_parser *parser, tree list)
6896 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYPRIVATE, list);
6900 default ( shared | none ) */
6903 c_parser_omp_clause_default (c_parser *parser, tree list)
6905 enum omp_clause_default_kind kind = OMP_CLAUSE_DEFAULT_UNSPECIFIED;
6908 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6910 if (c_parser_next_token_is (parser, CPP_NAME))
6912 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
6917 if (strcmp ("none", p) != 0)
6919 kind = OMP_CLAUSE_DEFAULT_NONE;
6923 if (strcmp ("shared", p) != 0)
6925 kind = OMP_CLAUSE_DEFAULT_SHARED;
6932 c_parser_consume_token (parser);
6937 c_parser_error (parser, "expected %<none%> or %<shared%>");
6939 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6941 if (kind == OMP_CLAUSE_DEFAULT_UNSPECIFIED)
6944 check_no_duplicate_clause (list, OMP_CLAUSE_DEFAULT, "default");
6945 c = build_omp_clause (OMP_CLAUSE_DEFAULT);
6946 OMP_CLAUSE_CHAIN (c) = list;
6947 OMP_CLAUSE_DEFAULT_KIND (c) = kind;
6953 firstprivate ( variable-list ) */
6956 c_parser_omp_clause_firstprivate (c_parser *parser, tree list)
6958 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_FIRSTPRIVATE, list);
6962 if ( expression ) */
6965 c_parser_omp_clause_if (c_parser *parser, tree list)
6967 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
6969 tree t = c_parser_paren_condition (parser);
6972 check_no_duplicate_clause (list, OMP_CLAUSE_IF, "if");
6974 c = build_omp_clause (OMP_CLAUSE_IF);
6975 OMP_CLAUSE_IF_EXPR (c) = t;
6976 OMP_CLAUSE_CHAIN (c) = list;
6980 c_parser_error (parser, "expected %<(%>");
6986 lastprivate ( variable-list ) */
6989 c_parser_omp_clause_lastprivate (c_parser *parser, tree list)
6991 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_LASTPRIVATE, list);
6998 c_parser_omp_clause_nowait (c_parser *parser ATTRIBUTE_UNUSED, tree list)
7002 check_no_duplicate_clause (list, OMP_CLAUSE_NOWAIT, "nowait");
7004 c = build_omp_clause (OMP_CLAUSE_NOWAIT);
7005 OMP_CLAUSE_CHAIN (c) = list;
7010 num_threads ( expression ) */
7013 c_parser_omp_clause_num_threads (c_parser *parser, tree list)
7015 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7017 location_t expr_loc = c_parser_peek_token (parser)->location;
7018 tree c, t = c_parser_expression (parser).value;
7020 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7022 if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
7024 c_parser_error (parser, "expected integer expression");
7028 /* Attempt to statically determine when the number isn't positive. */
7029 c = fold_build2 (LE_EXPR, boolean_type_node, t,
7030 build_int_cst (TREE_TYPE (t), 0));
7031 if (c == boolean_true_node)
7033 warning (0, "%H%<num_threads%> value must be positive", &expr_loc);
7034 t = integer_one_node;
7037 check_no_duplicate_clause (list, OMP_CLAUSE_NUM_THREADS, "num_threads");
7039 c = build_omp_clause (OMP_CLAUSE_NUM_THREADS);
7040 OMP_CLAUSE_NUM_THREADS_EXPR (c) = t;
7041 OMP_CLAUSE_CHAIN (c) = list;
7052 c_parser_omp_clause_ordered (c_parser *parser ATTRIBUTE_UNUSED, tree list)
7056 check_no_duplicate_clause (list, OMP_CLAUSE_ORDERED, "ordered");
7058 c = build_omp_clause (OMP_CLAUSE_ORDERED);
7059 OMP_CLAUSE_CHAIN (c) = list;
7064 private ( variable-list ) */
7067 c_parser_omp_clause_private (c_parser *parser, tree list)
7069 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_PRIVATE, list);
7073 reduction ( reduction-operator : variable-list )
7076 One of: + * - & ^ | && || */
7079 c_parser_omp_clause_reduction (c_parser *parser, tree list)
7081 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7083 enum tree_code code;
7085 switch (c_parser_peek_token (parser)->type)
7097 code = BIT_AND_EXPR;
7100 code = BIT_XOR_EXPR;
7103 code = BIT_IOR_EXPR;
7106 code = TRUTH_ANDIF_EXPR;
7109 code = TRUTH_ORIF_EXPR;
7112 c_parser_error (parser,
7113 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
7114 "%<^%>, %<|%>, %<&&%>, or %<||%>");
7115 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0);
7118 c_parser_consume_token (parser);
7119 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
7123 nl = c_parser_omp_variable_list (parser, OMP_CLAUSE_REDUCTION, list);
7124 for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
7125 OMP_CLAUSE_REDUCTION_CODE (c) = code;
7129 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7135 schedule ( schedule-kind )
7136 schedule ( schedule-kind , expression )
7139 static | dynamic | guided | runtime | auto
7143 c_parser_omp_clause_schedule (c_parser *parser, tree list)
7147 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7150 c = build_omp_clause (OMP_CLAUSE_SCHEDULE);
7152 if (c_parser_next_token_is (parser, CPP_NAME))
7154 tree kind = c_parser_peek_token (parser)->value;
7155 const char *p = IDENTIFIER_POINTER (kind);
7160 if (strcmp ("dynamic", p) != 0)
7162 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_DYNAMIC;
7166 if (strcmp ("guided", p) != 0)
7168 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_GUIDED;
7172 if (strcmp ("runtime", p) != 0)
7174 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_RUNTIME;
7181 else if (c_parser_next_token_is_keyword (parser, RID_STATIC))
7182 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_STATIC;
7183 else if (c_parser_next_token_is_keyword (parser, RID_AUTO))
7184 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_AUTO;
7188 c_parser_consume_token (parser);
7189 if (c_parser_next_token_is (parser, CPP_COMMA))
7192 c_parser_consume_token (parser);
7194 here = c_parser_peek_token (parser)->location;
7195 t = c_parser_expr_no_commas (parser, NULL).value;
7197 if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_RUNTIME)
7198 error ("%Hschedule %<runtime%> does not take "
7199 "a %<chunk_size%> parameter", &here);
7200 else if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_AUTO)
7201 error ("%Hschedule %<auto%> does not take "
7202 "a %<chunk_size%> parameter", &here);
7203 else if (TREE_CODE (TREE_TYPE (t)) == INTEGER_TYPE)
7204 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c) = t;
7206 c_parser_error (parser, "expected integer expression");
7208 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7211 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7212 "expected %<,%> or %<)%>");
7214 check_no_duplicate_clause (list, OMP_CLAUSE_SCHEDULE, "schedule");
7215 OMP_CLAUSE_CHAIN (c) = list;
7219 c_parser_error (parser, "invalid schedule kind");
7220 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0);
7225 shared ( variable-list ) */
7228 c_parser_omp_clause_shared (c_parser *parser, tree list)
7230 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_SHARED, list);
7237 c_parser_omp_clause_untied (c_parser *parser ATTRIBUTE_UNUSED, tree list)
7241 /* FIXME: Should we allow duplicates? */
7242 check_no_duplicate_clause (list, OMP_CLAUSE_UNTIED, "untied");
7244 c = build_omp_clause (OMP_CLAUSE_UNTIED);
7245 OMP_CLAUSE_CHAIN (c) = list;
7249 /* Parse all OpenMP clauses. The set clauses allowed by the directive
7250 is a bitmask in MASK. Return the list of clauses found; the result
7251 of clause default goes in *pdefault. */
7254 c_parser_omp_all_clauses (c_parser *parser, unsigned int mask,
7257 tree clauses = NULL;
7260 while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
7263 pragma_omp_clause c_kind;
7265 tree prev = clauses;
7267 if (!first && c_parser_next_token_is (parser, CPP_COMMA))
7268 c_parser_consume_token (parser);
7271 here = c_parser_peek_token (parser)->location;
7272 c_kind = c_parser_omp_clause_name (parser);
7276 case PRAGMA_OMP_CLAUSE_COLLAPSE:
7277 clauses = c_parser_omp_clause_collapse (parser, clauses);
7278 c_name = "collapse";
7280 case PRAGMA_OMP_CLAUSE_COPYIN:
7281 clauses = c_parser_omp_clause_copyin (parser, clauses);
7284 case PRAGMA_OMP_CLAUSE_COPYPRIVATE:
7285 clauses = c_parser_omp_clause_copyprivate (parser, clauses);
7286 c_name = "copyprivate";
7288 case PRAGMA_OMP_CLAUSE_DEFAULT:
7289 clauses = c_parser_omp_clause_default (parser, clauses);
7292 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE:
7293 clauses = c_parser_omp_clause_firstprivate (parser, clauses);
7294 c_name = "firstprivate";
7296 case PRAGMA_OMP_CLAUSE_IF:
7297 clauses = c_parser_omp_clause_if (parser, clauses);
7300 case PRAGMA_OMP_CLAUSE_LASTPRIVATE:
7301 clauses = c_parser_omp_clause_lastprivate (parser, clauses);
7302 c_name = "lastprivate";
7304 case PRAGMA_OMP_CLAUSE_NOWAIT:
7305 clauses = c_parser_omp_clause_nowait (parser, clauses);
7308 case PRAGMA_OMP_CLAUSE_NUM_THREADS:
7309 clauses = c_parser_omp_clause_num_threads (parser, clauses);
7310 c_name = "num_threads";
7312 case PRAGMA_OMP_CLAUSE_ORDERED:
7313 clauses = c_parser_omp_clause_ordered (parser, clauses);
7316 case PRAGMA_OMP_CLAUSE_PRIVATE:
7317 clauses = c_parser_omp_clause_private (parser, clauses);
7320 case PRAGMA_OMP_CLAUSE_REDUCTION:
7321 clauses = c_parser_omp_clause_reduction (parser, clauses);
7322 c_name = "reduction";
7324 case PRAGMA_OMP_CLAUSE_SCHEDULE:
7325 clauses = c_parser_omp_clause_schedule (parser, clauses);
7326 c_name = "schedule";
7328 case PRAGMA_OMP_CLAUSE_SHARED:
7329 clauses = c_parser_omp_clause_shared (parser, clauses);
7332 case PRAGMA_OMP_CLAUSE_UNTIED:
7333 clauses = c_parser_omp_clause_untied (parser, clauses);
7337 c_parser_error (parser, "expected %<#pragma omp%> clause");
7341 if (((mask >> c_kind) & 1) == 0 && !parser->error)
7343 /* Remove the invalid clause(s) from the list to avoid
7344 confusing the rest of the compiler. */
7346 error ("%H%qs is not valid for %qs", &here, c_name, where);
7351 c_parser_skip_to_pragma_eol (parser);
7353 return c_finish_omp_clauses (clauses);
7360 In practice, we're also interested in adding the statement to an
7361 outer node. So it is convenient if we work around the fact that
7362 c_parser_statement calls add_stmt. */
7365 c_parser_omp_structured_block (c_parser *parser)
7367 tree stmt = push_stmt_list ();
7368 c_parser_statement (parser);
7369 return pop_stmt_list (stmt);
7373 # pragma omp atomic new-line
7377 x binop= expr | x++ | ++x | x-- | --x
7379 +, *, -, /, &, ^, |, <<, >>
7381 where x is an lvalue expression with scalar type. */
7384 c_parser_omp_atomic (c_parser *parser)
7388 enum tree_code code;
7389 struct c_expr rhs_expr;
7391 c_parser_skip_to_pragma_eol (parser);
7393 lhs = c_parser_unary_expression (parser).value;
7394 switch (TREE_CODE (lhs))
7398 c_parser_skip_to_end_of_block_or_statement (parser);
7401 case PREINCREMENT_EXPR:
7402 case POSTINCREMENT_EXPR:
7403 lhs = TREE_OPERAND (lhs, 0);
7405 rhs = integer_one_node;
7408 case PREDECREMENT_EXPR:
7409 case POSTDECREMENT_EXPR:
7410 lhs = TREE_OPERAND (lhs, 0);
7412 rhs = integer_one_node;
7416 switch (c_parser_peek_token (parser)->type)
7422 code = TRUNC_DIV_EXPR;
7437 code = BIT_AND_EXPR;
7440 code = BIT_IOR_EXPR;
7443 code = BIT_XOR_EXPR;
7446 c_parser_error (parser,
7447 "invalid operator for %<#pragma omp atomic%>");
7451 c_parser_consume_token (parser);
7452 rhs_expr = c_parser_expression (parser);
7453 rhs_expr = default_function_array_conversion (rhs_expr);
7454 rhs = rhs_expr.value;
7457 stmt = c_finish_omp_atomic (code, lhs, rhs);
7458 if (stmt != error_mark_node)
7460 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7465 # pragma omp barrier new-line
7469 c_parser_omp_barrier (c_parser *parser)
7471 c_parser_consume_pragma (parser);
7472 c_parser_skip_to_pragma_eol (parser);
7474 c_finish_omp_barrier ();
7478 # pragma omp critical [(name)] new-line
7483 c_parser_omp_critical (c_parser *parser)
7485 tree stmt, name = NULL;
7487 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
7489 c_parser_consume_token (parser);
7490 if (c_parser_next_token_is (parser, CPP_NAME))
7492 name = c_parser_peek_token (parser)->value;
7493 c_parser_consume_token (parser);
7494 c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7497 c_parser_error (parser, "expected identifier");
7499 else if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
7500 c_parser_error (parser, "expected %<(%> or end of line");
7501 c_parser_skip_to_pragma_eol (parser);
7503 stmt = c_parser_omp_structured_block (parser);
7504 return c_finish_omp_critical (stmt, name);
7508 # pragma omp flush flush-vars[opt] new-line
7511 ( variable-list ) */
7514 c_parser_omp_flush (c_parser *parser)
7516 c_parser_consume_pragma (parser);
7517 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
7518 c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL);
7519 else if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
7520 c_parser_error (parser, "expected %<(%> or end of line");
7521 c_parser_skip_to_pragma_eol (parser);
7523 c_finish_omp_flush ();
7526 /* Parse the restricted form of the for statement allowed by OpenMP.
7527 The real trick here is to determine the loop control variable early
7528 so that we can push a new decl if necessary to make it private. */
7531 c_parser_omp_for_loop (c_parser *parser, tree clauses, tree *par_clauses)
7533 tree decl, cond, incr, save_break, save_cont, body, init, stmt, cl;
7534 tree declv, condv, incrv, initv, for_block = NULL, ret = NULL;
7536 bool fail = false, open_brace_parsed = false;
7537 int i, collapse = 1, nbraces = 0;
7539 for (cl = clauses; cl; cl = OMP_CLAUSE_CHAIN (cl))
7540 if (OMP_CLAUSE_CODE (cl) == OMP_CLAUSE_COLLAPSE)
7541 collapse = tree_low_cst (OMP_CLAUSE_COLLAPSE_EXPR (cl), 0);
7543 gcc_assert (collapse >= 1);
7545 declv = make_tree_vec (collapse);
7546 initv = make_tree_vec (collapse);
7547 condv = make_tree_vec (collapse);
7548 incrv = make_tree_vec (collapse);
7550 if (!c_parser_next_token_is_keyword (parser, RID_FOR))
7552 c_parser_error (parser, "for statement expected");
7555 loc = c_parser_peek_token (parser)->location;
7556 c_parser_consume_token (parser);
7558 for (i = 0; i < collapse; i++)
7562 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7565 /* Parse the initialization declaration or expression. */
7566 if (c_parser_next_token_starts_declspecs (parser))
7570 = tree_cons (NULL, c_begin_compound_stmt (true), for_block);
7571 c_parser_declaration_or_fndef (parser, true, true, true, true);
7572 decl = check_for_loop_decls ();
7575 if (DECL_INITIAL (decl) == error_mark_node)
7576 decl = error_mark_node;
7579 else if (c_parser_next_token_is (parser, CPP_NAME)
7580 && c_parser_peek_2nd_token (parser)->type == CPP_EQ)
7582 struct c_expr init_exp;
7584 decl = c_parser_postfix_expression (parser).value;
7586 c_parser_require (parser, CPP_EQ, "expected %<=%>");
7588 init_exp = c_parser_expr_no_commas (parser, NULL);
7589 init_exp = default_function_array_conversion (init_exp);
7590 init = build_modify_expr (decl, NOP_EXPR, init_exp.value);
7591 init = c_process_expr_stmt (init);
7593 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7598 c_parser_error (parser,
7599 "expected iteration declaration or initialization");
7600 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7606 /* Parse the loop condition. */
7608 if (c_parser_next_token_is_not (parser, CPP_SEMICOLON))
7610 cond = c_parser_expression_conv (parser).value;
7611 cond = c_objc_common_truthvalue_conversion (cond);
7612 if (CAN_HAVE_LOCATION_P (cond))
7613 SET_EXPR_LOCATION (cond, input_location);
7615 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7617 /* Parse the increment expression. */
7619 if (c_parser_next_token_is_not (parser, CPP_CLOSE_PAREN))
7620 incr = c_process_expr_stmt (c_parser_expression (parser).value);
7621 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7623 if (decl == NULL || decl == error_mark_node || init == error_mark_node)
7627 TREE_VEC_ELT (declv, i) = decl;
7628 TREE_VEC_ELT (initv, i) = init;
7629 TREE_VEC_ELT (condv, i) = cond;
7630 TREE_VEC_ELT (incrv, i) = incr;
7634 if (i == collapse - 1)
7637 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
7638 in between the collapsed for loops to be still considered perfectly
7639 nested. Hopefully the final version clarifies this.
7640 For now handle (multiple) {'s and empty statements. */
7643 if (c_parser_next_token_is_keyword (parser, RID_FOR))
7645 c_parser_consume_token (parser);
7648 else if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
7650 c_parser_consume_token (parser);
7654 && c_parser_next_token_is (parser, CPP_SEMICOLON))
7655 c_parser_consume_token (parser);
7658 c_parser_error (parser, "not enough perfectly nested loops");
7661 open_brace_parsed = true;
7671 nbraces += bracecount;
7674 save_break = c_break_label;
7675 c_break_label = size_one_node;
7676 save_cont = c_cont_label;
7677 c_cont_label = NULL_TREE;
7678 body = push_stmt_list ();
7680 if (open_brace_parsed)
7682 stmt = c_begin_compound_stmt (true);
7683 c_parser_compound_statement_nostart (parser);
7684 add_stmt (c_end_compound_stmt (stmt, true));
7687 add_stmt (c_parser_c99_block_statement (parser));
7689 add_stmt (build1 (LABEL_EXPR, void_type_node, c_cont_label));
7691 body = pop_stmt_list (body);
7692 c_break_label = save_break;
7693 c_cont_label = save_cont;
7697 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
7699 c_parser_consume_token (parser);
7702 else if (c_parser_next_token_is (parser, CPP_SEMICOLON))
7703 c_parser_consume_token (parser);
7706 c_parser_error (parser, "collapsed loops not perfectly nested");
7709 stmt = c_begin_compound_stmt (true);
7711 c_parser_compound_statement_nostart (parser);
7712 body = c_end_compound_stmt (stmt, true);
7719 /* Only bother calling c_finish_omp_for if we haven't already generated
7720 an error from the initialization parsing. */
7723 stmt = c_finish_omp_for (loc, declv, initv, condv, incrv, body, NULL);
7726 if (par_clauses != NULL)
7729 for (c = par_clauses; *c ; )
7730 if (OMP_CLAUSE_CODE (*c) != OMP_CLAUSE_FIRSTPRIVATE
7731 && OMP_CLAUSE_CODE (*c) != OMP_CLAUSE_LASTPRIVATE)
7732 c = &OMP_CLAUSE_CHAIN (*c);
7735 for (i = 0; i < collapse; i++)
7736 if (TREE_VEC_ELT (declv, i) == OMP_CLAUSE_DECL (*c))
7739 c = &OMP_CLAUSE_CHAIN (*c);
7740 else if (OMP_CLAUSE_CODE (*c) == OMP_CLAUSE_FIRSTPRIVATE)
7742 error ("%Hiteration variable %qD should not be firstprivate",
7743 &loc, OMP_CLAUSE_DECL (*c));
7744 *c = OMP_CLAUSE_CHAIN (*c);
7748 /* Copy lastprivate (decl) clause to OMP_FOR_CLAUSES,
7749 change it to shared (decl) in
7750 OMP_PARALLEL_CLAUSES. */
7751 tree l = build_omp_clause (OMP_CLAUSE_LASTPRIVATE);
7752 OMP_CLAUSE_DECL (l) = OMP_CLAUSE_DECL (*c);
7753 OMP_CLAUSE_CHAIN (l) = clauses;
7755 OMP_CLAUSE_SET_CODE (*c, OMP_CLAUSE_SHARED);
7759 OMP_FOR_CLAUSES (stmt) = clauses;
7766 stmt = c_end_compound_stmt (TREE_VALUE (for_block), true);
7768 for_block = TREE_CHAIN (for_block);
7774 #pragma omp for for-clause[optseq] new-line
7778 #define OMP_FOR_CLAUSE_MASK \
7779 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
7780 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
7781 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
7782 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
7783 | (1u << PRAGMA_OMP_CLAUSE_ORDERED) \
7784 | (1u << PRAGMA_OMP_CLAUSE_SCHEDULE) \
7785 | (1u << PRAGMA_OMP_CLAUSE_COLLAPSE) \
7786 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
7789 c_parser_omp_for (c_parser *parser)
7791 tree block, clauses, ret;
7793 clauses = c_parser_omp_all_clauses (parser, OMP_FOR_CLAUSE_MASK,
7796 block = c_begin_compound_stmt (true);
7797 ret = c_parser_omp_for_loop (parser, clauses, NULL);
7798 block = c_end_compound_stmt (block, true);
7805 # pragma omp master new-line
7810 c_parser_omp_master (c_parser *parser)
7812 c_parser_skip_to_pragma_eol (parser);
7813 return c_finish_omp_master (c_parser_omp_structured_block (parser));
7817 # pragma omp ordered new-line
7822 c_parser_omp_ordered (c_parser *parser)
7824 c_parser_skip_to_pragma_eol (parser);
7825 return c_finish_omp_ordered (c_parser_omp_structured_block (parser));
7831 { section-sequence }
7834 section-directive[opt] structured-block
7835 section-sequence section-directive structured-block */
7838 c_parser_omp_sections_scope (c_parser *parser)
7841 bool error_suppress = false;
7844 if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
7846 /* Avoid skipping until the end of the block. */
7847 parser->error = false;
7851 stmt = push_stmt_list ();
7853 loc = c_parser_peek_token (parser)->location;
7854 if (c_parser_peek_token (parser)->pragma_kind != PRAGMA_OMP_SECTION)
7856 substmt = push_stmt_list ();
7860 c_parser_statement (parser);
7862 if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_OMP_SECTION)
7864 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
7866 if (c_parser_next_token_is (parser, CPP_EOF))
7870 substmt = pop_stmt_list (substmt);
7871 substmt = build1 (OMP_SECTION, void_type_node, substmt);
7872 SET_EXPR_LOCATION (substmt, loc);
7878 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
7880 if (c_parser_next_token_is (parser, CPP_EOF))
7883 loc = c_parser_peek_token (parser)->location;
7884 if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_OMP_SECTION)
7886 c_parser_consume_pragma (parser);
7887 c_parser_skip_to_pragma_eol (parser);
7888 error_suppress = false;
7890 else if (!error_suppress)
7892 error ("%Hexpected %<#pragma omp section%> or %<}%>",
7894 error_suppress = true;
7897 substmt = c_parser_omp_structured_block (parser);
7898 substmt = build1 (OMP_SECTION, void_type_node, substmt);
7899 SET_EXPR_LOCATION (substmt, loc);
7902 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE,
7903 "expected %<#pragma omp section%> or %<}%>");
7905 substmt = pop_stmt_list (stmt);
7907 stmt = make_node (OMP_SECTIONS);
7908 TREE_TYPE (stmt) = void_type_node;
7909 OMP_SECTIONS_BODY (stmt) = substmt;
7911 return add_stmt (stmt);
7915 # pragma omp sections sections-clause[optseq] newline
7919 #define OMP_SECTIONS_CLAUSE_MASK \
7920 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
7921 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
7922 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
7923 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
7924 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
7927 c_parser_omp_sections (c_parser *parser)
7929 tree block, clauses, ret;
7931 clauses = c_parser_omp_all_clauses (parser, OMP_SECTIONS_CLAUSE_MASK,
7932 "#pragma omp sections");
7934 block = c_begin_compound_stmt (true);
7935 ret = c_parser_omp_sections_scope (parser);
7937 OMP_SECTIONS_CLAUSES (ret) = clauses;
7938 block = c_end_compound_stmt (block, true);
7945 # pragma parallel parallel-clause new-line
7946 # pragma parallel for parallel-for-clause new-line
7947 # pragma parallel sections parallel-sections-clause new-line
7950 #define OMP_PARALLEL_CLAUSE_MASK \
7951 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
7952 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
7953 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
7954 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
7955 | (1u << PRAGMA_OMP_CLAUSE_SHARED) \
7956 | (1u << PRAGMA_OMP_CLAUSE_COPYIN) \
7957 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
7958 | (1u << PRAGMA_OMP_CLAUSE_NUM_THREADS))
7961 c_parser_omp_parallel (c_parser *parser)
7963 enum pragma_kind p_kind = PRAGMA_OMP_PARALLEL;
7964 const char *p_name = "#pragma omp parallel";
7965 tree stmt, clauses, par_clause, ws_clause, block;
7966 unsigned int mask = OMP_PARALLEL_CLAUSE_MASK;
7968 if (c_parser_next_token_is_keyword (parser, RID_FOR))
7970 c_parser_consume_token (parser);
7971 p_kind = PRAGMA_OMP_PARALLEL_FOR;
7972 p_name = "#pragma omp parallel for";
7973 mask |= OMP_FOR_CLAUSE_MASK;
7974 mask &= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT);
7976 else if (c_parser_next_token_is (parser, CPP_NAME))
7978 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
7979 if (strcmp (p, "sections") == 0)
7981 c_parser_consume_token (parser);
7982 p_kind = PRAGMA_OMP_PARALLEL_SECTIONS;
7983 p_name = "#pragma omp parallel sections";
7984 mask |= OMP_SECTIONS_CLAUSE_MASK;
7985 mask &= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT);
7989 clauses = c_parser_omp_all_clauses (parser, mask, p_name);
7993 case PRAGMA_OMP_PARALLEL:
7994 block = c_begin_omp_parallel ();
7995 c_parser_statement (parser);
7996 stmt = c_finish_omp_parallel (clauses, block);
7999 case PRAGMA_OMP_PARALLEL_FOR:
8000 block = c_begin_omp_parallel ();
8001 c_split_parallel_clauses (clauses, &par_clause, &ws_clause);
8002 c_parser_omp_for_loop (parser, ws_clause, &par_clause);
8003 stmt = c_finish_omp_parallel (par_clause, block);
8004 OMP_PARALLEL_COMBINED (stmt) = 1;
8007 case PRAGMA_OMP_PARALLEL_SECTIONS:
8008 block = c_begin_omp_parallel ();
8009 c_split_parallel_clauses (clauses, &par_clause, &ws_clause);
8010 stmt = c_parser_omp_sections_scope (parser);
8012 OMP_SECTIONS_CLAUSES (stmt) = ws_clause;
8013 stmt = c_finish_omp_parallel (par_clause, block);
8014 OMP_PARALLEL_COMBINED (stmt) = 1;
8025 # pragma omp single single-clause[optseq] new-line
8029 #define OMP_SINGLE_CLAUSE_MASK \
8030 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8031 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8032 | (1u << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
8033 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
8036 c_parser_omp_single (c_parser *parser)
8038 tree stmt = make_node (OMP_SINGLE);
8039 TREE_TYPE (stmt) = void_type_node;
8041 OMP_SINGLE_CLAUSES (stmt)
8042 = c_parser_omp_all_clauses (parser, OMP_SINGLE_CLAUSE_MASK,
8043 "#pragma omp single");
8044 OMP_SINGLE_BODY (stmt) = c_parser_omp_structured_block (parser);
8046 return add_stmt (stmt);
8050 # pragma omp task task-clause[optseq] new-line
8053 #define OMP_TASK_CLAUSE_MASK \
8054 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
8055 | (1u << PRAGMA_OMP_CLAUSE_UNTIED) \
8056 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
8057 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8058 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8059 | (1u << PRAGMA_OMP_CLAUSE_SHARED))
8062 c_parser_omp_task (c_parser *parser)
8064 tree clauses, block;
8066 clauses = c_parser_omp_all_clauses (parser, OMP_TASK_CLAUSE_MASK,
8067 "#pragma omp task");
8069 block = c_begin_omp_task ();
8070 c_parser_statement (parser);
8071 return c_finish_omp_task (clauses, block);
8075 # pragma omp taskwait new-line
8079 c_parser_omp_taskwait (c_parser *parser)
8081 c_parser_consume_pragma (parser);
8082 c_parser_skip_to_pragma_eol (parser);
8084 c_finish_omp_taskwait ();
8087 /* Main entry point to parsing most OpenMP pragmas. */
8090 c_parser_omp_construct (c_parser *parser)
8092 enum pragma_kind p_kind;
8096 loc = c_parser_peek_token (parser)->location;
8097 p_kind = c_parser_peek_token (parser)->pragma_kind;
8098 c_parser_consume_pragma (parser);
8100 /* For all constructs below except #pragma omp atomic
8101 MUST_NOT_THROW catch handlers are needed when exceptions
8103 if (p_kind != PRAGMA_OMP_ATOMIC)
8104 c_maybe_initialize_eh ();
8108 case PRAGMA_OMP_ATOMIC:
8109 c_parser_omp_atomic (parser);
8111 case PRAGMA_OMP_CRITICAL:
8112 stmt = c_parser_omp_critical (parser);
8114 case PRAGMA_OMP_FOR:
8115 stmt = c_parser_omp_for (parser);
8117 case PRAGMA_OMP_MASTER:
8118 stmt = c_parser_omp_master (parser);
8120 case PRAGMA_OMP_ORDERED:
8121 stmt = c_parser_omp_ordered (parser);
8123 case PRAGMA_OMP_PARALLEL:
8124 stmt = c_parser_omp_parallel (parser);
8126 case PRAGMA_OMP_SECTIONS:
8127 stmt = c_parser_omp_sections (parser);
8129 case PRAGMA_OMP_SINGLE:
8130 stmt = c_parser_omp_single (parser);
8132 case PRAGMA_OMP_TASK:
8133 stmt = c_parser_omp_task (parser);
8140 SET_EXPR_LOCATION (stmt, loc);
8145 # pragma omp threadprivate (variable-list) */
8148 c_parser_omp_threadprivate (c_parser *parser)
8152 c_parser_consume_pragma (parser);
8153 vars = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL);
8155 /* Mark every variable in VARS to be assigned thread local storage. */
8156 for (t = vars; t; t = TREE_CHAIN (t))
8158 tree v = TREE_PURPOSE (t);
8160 /* If V had already been marked threadprivate, it doesn't matter
8161 whether it had been used prior to this point. */
8162 if (TREE_CODE (v) != VAR_DECL)
8163 error ("%qD is not a variable", v);
8164 else if (TREE_USED (v) && !C_DECL_THREADPRIVATE_P (v))
8165 error ("%qE declared %<threadprivate%> after first use", v);
8166 else if (! TREE_STATIC (v) && ! DECL_EXTERNAL (v))
8167 error ("automatic variable %qE cannot be %<threadprivate%>", v);
8168 else if (TREE_TYPE (v) == error_mark_node)
8170 else if (! COMPLETE_TYPE_P (TREE_TYPE (v)))
8171 error ("%<threadprivate%> %qE has incomplete type", v);
8174 if (! DECL_THREAD_LOCAL_P (v))
8176 DECL_TLS_MODEL (v) = decl_default_tls_model (v);
8177 /* If rtl has been already set for this var, call
8178 make_decl_rtl once again, so that encode_section_info
8179 has a chance to look at the new decl flags. */
8180 if (DECL_RTL_SET_P (v))
8183 C_DECL_THREADPRIVATE_P (v) = 1;
8187 c_parser_skip_to_pragma_eol (parser);
8191 /* Parse a single source file. */
8196 /* Use local storage to begin. If the first token is a pragma, parse it.
8197 If it is #pragma GCC pch_preprocess, then this will load a PCH file
8198 which will cause garbage collection. */
8201 memset (&tparser, 0, sizeof tparser);
8202 the_parser = &tparser;
8204 if (c_parser_peek_token (&tparser)->pragma_kind == PRAGMA_GCC_PCH_PREPROCESS)
8205 c_parser_pragma_pch_preprocess (&tparser);
8207 the_parser = GGC_NEW (c_parser);
8208 *the_parser = tparser;
8210 c_parser_translation_unit (the_parser);
8214 #include "gt-c-parser.h"