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 /* Return the canonical spelling for this keyword. */
245 token->value = ridpointers[(int) rid_code];
246 token->type = CPP_KEYWORD;
247 token->keyword = rid_code;
252 decl = lookup_name (token->value);
255 if (TREE_CODE (decl) == TYPE_DECL)
257 token->id_kind = C_ID_TYPENAME;
261 else if (c_dialect_objc ())
263 tree objc_interface_decl = objc_is_class_name (token->value);
264 /* Objective-C class names are in the same namespace as
265 variables and typedefs, and hence are shadowed by local
267 if (objc_interface_decl
268 && (global_bindings_p ()
269 || (!objc_force_identifier && !decl)))
271 token->value = objc_interface_decl;
272 token->id_kind = C_ID_CLASSNAME;
276 token->id_kind = C_ID_ID;
280 /* This only happens in Objective-C; it must be a keyword. */
281 token->type = CPP_KEYWORD;
282 token->keyword = C_RID_CODE (token->value);
286 case CPP_CLOSE_PAREN:
288 /* These tokens may affect the interpretation of any identifiers
289 following, if doing Objective-C. */
290 if (c_dialect_objc ())
291 parser->objc_need_raw_identifier = false;
294 /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */
295 token->pragma_kind = (enum pragma_kind) TREE_INT_CST_LOW (token->value);
301 timevar_pop (TV_LEX);
304 /* Return a pointer to the next token from PARSER, reading it in if
307 static inline c_token *
308 c_parser_peek_token (c_parser *parser)
310 if (parser->tokens_avail == 0)
312 c_lex_one_token (parser, &parser->tokens[0]);
313 parser->tokens_avail = 1;
315 return &parser->tokens[0];
318 /* Return true if the next token from PARSER has the indicated
322 c_parser_next_token_is (c_parser *parser, enum cpp_ttype type)
324 return c_parser_peek_token (parser)->type == type;
327 /* Return true if the next token from PARSER does not have the
331 c_parser_next_token_is_not (c_parser *parser, enum cpp_ttype type)
333 return !c_parser_next_token_is (parser, type);
336 /* Return true if the next token from PARSER is the indicated
340 c_parser_next_token_is_keyword (c_parser *parser, enum rid keyword)
342 return c_parser_peek_token (parser)->keyword == keyword;
345 /* Return true if TOKEN can start a type name,
348 c_token_starts_typename (c_token *token)
353 switch (token->id_kind)
360 gcc_assert (c_dialect_objc ());
366 switch (token->keyword)
398 if (c_dialect_objc ())
406 /* Return true if the next token from PARSER can start a type name,
409 c_parser_next_token_starts_typename (c_parser *parser)
411 c_token *token = c_parser_peek_token (parser);
412 return c_token_starts_typename (token);
415 /* Return true if TOKEN can start declaration specifiers, false
418 c_token_starts_declspecs (c_token *token)
423 switch (token->id_kind)
430 gcc_assert (c_dialect_objc ());
436 switch (token->keyword)
475 if (c_dialect_objc ())
483 /* Return true if the next token from PARSER can start declaration
484 specifiers, false otherwise. */
486 c_parser_next_token_starts_declspecs (c_parser *parser)
488 c_token *token = c_parser_peek_token (parser);
489 return c_token_starts_declspecs (token);
492 /* Return a pointer to the next-but-one token from PARSER, reading it
493 in if necessary. The next token is already read in. */
496 c_parser_peek_2nd_token (c_parser *parser)
498 if (parser->tokens_avail >= 2)
499 return &parser->tokens[1];
500 gcc_assert (parser->tokens_avail == 1);
501 gcc_assert (parser->tokens[0].type != CPP_EOF);
502 gcc_assert (parser->tokens[0].type != CPP_PRAGMA_EOL);
503 c_lex_one_token (parser, &parser->tokens[1]);
504 parser->tokens_avail = 2;
505 return &parser->tokens[1];
508 /* Consume the next token from PARSER. */
511 c_parser_consume_token (c_parser *parser)
513 gcc_assert (parser->tokens_avail >= 1);
514 gcc_assert (parser->tokens[0].type != CPP_EOF);
515 gcc_assert (!parser->in_pragma || parser->tokens[0].type != CPP_PRAGMA_EOL);
516 gcc_assert (parser->error || parser->tokens[0].type != CPP_PRAGMA);
517 if (parser->tokens_avail == 2)
518 parser->tokens[0] = parser->tokens[1];
519 parser->tokens_avail--;
522 /* Expect the current token to be a #pragma. Consume it and remember
523 that we've begun parsing a pragma. */
526 c_parser_consume_pragma (c_parser *parser)
528 gcc_assert (!parser->in_pragma);
529 gcc_assert (parser->tokens_avail >= 1);
530 gcc_assert (parser->tokens[0].type == CPP_PRAGMA);
531 if (parser->tokens_avail == 2)
532 parser->tokens[0] = parser->tokens[1];
533 parser->tokens_avail--;
534 parser->in_pragma = true;
537 /* Update the globals input_location and in_system_header from
540 c_parser_set_source_position_from_token (c_token *token)
542 if (token->type != CPP_EOF)
544 input_location = token->location;
548 /* Issue a diagnostic of the form
549 FILE:LINE: MESSAGE before TOKEN
550 where TOKEN is the next token in the input stream of PARSER.
551 MESSAGE (specified by the caller) is usually of the form "expected
554 Do not issue a diagnostic if still recovering from an error.
556 ??? This is taken from the C++ parser, but building up messages in
557 this way is not i18n-friendly and some other approach should be
561 c_parser_error (c_parser *parser, const char *gmsgid)
563 c_token *token = c_parser_peek_token (parser);
566 parser->error = true;
569 /* This diagnostic makes more sense if it is tagged to the line of
570 the token we just peeked at. */
571 c_parser_set_source_position_from_token (token);
572 c_parse_error (gmsgid,
573 /* Because c_parse_error does not understand
574 CPP_KEYWORD, keywords are treated like
576 (token->type == CPP_KEYWORD ? CPP_NAME : token->type),
580 /* If the next token is of the indicated TYPE, consume it. Otherwise,
581 issue the error MSGID. If MSGID is NULL then a message has already
582 been produced and no message will be produced this time. Returns
583 true if found, false otherwise. */
586 c_parser_require (c_parser *parser,
590 if (c_parser_next_token_is (parser, type))
592 c_parser_consume_token (parser);
597 c_parser_error (parser, msgid);
602 /* If the next token is the indicated keyword, consume it. Otherwise,
603 issue the error MSGID. Returns true if found, false otherwise. */
606 c_parser_require_keyword (c_parser *parser,
610 if (c_parser_next_token_is_keyword (parser, keyword))
612 c_parser_consume_token (parser);
617 c_parser_error (parser, msgid);
622 /* Like c_parser_require, except that tokens will be skipped until the
623 desired token is found. An error message is still produced if the
624 next token is not as expected. If MSGID is NULL then a message has
625 already been produced and no message will be produced this
629 c_parser_skip_until_found (c_parser *parser,
633 unsigned nesting_depth = 0;
635 if (c_parser_require (parser, type, msgid))
638 /* Skip tokens until the desired token is found. */
641 /* Peek at the next token. */
642 c_token *token = c_parser_peek_token (parser);
643 /* If we've reached the token we want, consume it and stop. */
644 if (token->type == type && !nesting_depth)
646 c_parser_consume_token (parser);
650 /* If we've run out of tokens, stop. */
651 if (token->type == CPP_EOF)
653 if (token->type == CPP_PRAGMA_EOL && parser->in_pragma)
655 if (token->type == CPP_OPEN_BRACE
656 || token->type == CPP_OPEN_PAREN
657 || token->type == CPP_OPEN_SQUARE)
659 else if (token->type == CPP_CLOSE_BRACE
660 || token->type == CPP_CLOSE_PAREN
661 || token->type == CPP_CLOSE_SQUARE)
663 if (nesting_depth-- == 0)
666 /* Consume this token. */
667 c_parser_consume_token (parser);
669 parser->error = false;
672 /* Skip tokens until the end of a parameter is found, but do not
673 consume the comma, semicolon or closing delimiter. */
676 c_parser_skip_to_end_of_parameter (c_parser *parser)
678 unsigned nesting_depth = 0;
682 c_token *token = c_parser_peek_token (parser);
683 if ((token->type == CPP_COMMA || token->type == CPP_SEMICOLON)
686 /* If we've run out of tokens, stop. */
687 if (token->type == CPP_EOF)
689 if (token->type == CPP_PRAGMA_EOL && parser->in_pragma)
691 if (token->type == CPP_OPEN_BRACE
692 || token->type == CPP_OPEN_PAREN
693 || token->type == CPP_OPEN_SQUARE)
695 else if (token->type == CPP_CLOSE_BRACE
696 || token->type == CPP_CLOSE_PAREN
697 || token->type == CPP_CLOSE_SQUARE)
699 if (nesting_depth-- == 0)
702 /* Consume this token. */
703 c_parser_consume_token (parser);
705 parser->error = false;
708 /* Expect to be at the end of the pragma directive and consume an
709 end of line marker. */
712 c_parser_skip_to_pragma_eol (c_parser *parser)
714 gcc_assert (parser->in_pragma);
715 parser->in_pragma = false;
717 if (!c_parser_require (parser, CPP_PRAGMA_EOL, "expected end of line"))
720 c_token *token = c_parser_peek_token (parser);
721 if (token->type == CPP_EOF)
723 if (token->type == CPP_PRAGMA_EOL)
725 c_parser_consume_token (parser);
728 c_parser_consume_token (parser);
731 parser->error = false;
734 /* Skip tokens until we have consumed an entire block, or until we
735 have consumed a non-nested ';'. */
738 c_parser_skip_to_end_of_block_or_statement (c_parser *parser)
740 unsigned nesting_depth = 0;
741 bool save_error = parser->error;
747 /* Peek at the next token. */
748 token = c_parser_peek_token (parser);
756 if (parser->in_pragma)
761 /* If the next token is a ';', we have reached the
762 end of the statement. */
765 /* Consume the ';'. */
766 c_parser_consume_token (parser);
771 case CPP_CLOSE_BRACE:
772 /* If the next token is a non-nested '}', then we have
773 reached the end of the current block. */
774 if (nesting_depth == 0 || --nesting_depth == 0)
776 c_parser_consume_token (parser);
782 /* If it the next token is a '{', then we are entering a new
783 block. Consume the entire block. */
788 /* If we see a pragma, consume the whole thing at once. We
789 have some safeguards against consuming pragmas willy-nilly.
790 Normally, we'd expect to be here with parser->error set,
791 which disables these safeguards. But it's possible to get
792 here for secondary error recovery, after parser->error has
794 c_parser_consume_pragma (parser);
795 c_parser_skip_to_pragma_eol (parser);
796 parser->error = save_error;
803 c_parser_consume_token (parser);
807 parser->error = false;
810 /* Save the warning flags which are controlled by __extension__. */
813 disable_extension_diagnostics (void)
816 | (warn_pointer_arith << 1)
817 | (warn_traditional << 2)
820 warn_pointer_arith = 0;
821 warn_traditional = 0;
826 /* Restore the warning flags which are controlled by __extension__.
827 FLAGS is the return value from disable_extension_diagnostics. */
830 restore_extension_diagnostics (int flags)
832 pedantic = flags & 1;
833 warn_pointer_arith = (flags >> 1) & 1;
834 warn_traditional = (flags >> 2) & 1;
835 flag_iso = (flags >> 3) & 1;
838 /* Possibly kinds of declarator to parse. */
839 typedef enum c_dtr_syn {
840 /* A normal declarator with an identifier. */
842 /* An abstract declarator (maybe empty). */
844 /* A parameter declarator: may be either, but after a type name does
845 not redeclare a typedef name as an identifier if it can
846 alternatively be interpreted as a typedef name; see DR#009,
847 applied in C90 TC1, omitted from C99 and reapplied in C99 TC2
848 following DR#249. For example, given a typedef T, "int T" and
849 "int *T" are valid parameter declarations redeclaring T, while
850 "int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are
851 abstract declarators rather than involving redundant parentheses;
852 the same applies with attributes inside the parentheses before
857 static void c_parser_external_declaration (c_parser *);
858 static void c_parser_asm_definition (c_parser *);
859 static void c_parser_declaration_or_fndef (c_parser *, bool, bool, bool, bool);
860 static void c_parser_declspecs (c_parser *, struct c_declspecs *, bool, bool,
862 static struct c_typespec c_parser_enum_specifier (c_parser *);
863 static struct c_typespec c_parser_struct_or_union_specifier (c_parser *);
864 static tree c_parser_struct_declaration (c_parser *);
865 static struct c_typespec c_parser_typeof_specifier (c_parser *);
866 static struct c_declarator *c_parser_declarator (c_parser *, bool, c_dtr_syn,
868 static struct c_declarator *c_parser_direct_declarator (c_parser *, bool,
870 static struct c_declarator *c_parser_direct_declarator_inner (c_parser *,
872 struct c_declarator *);
873 static struct c_arg_info *c_parser_parms_declarator (c_parser *, bool, tree);
874 static struct c_arg_info *c_parser_parms_list_declarator (c_parser *, tree);
875 static struct c_parm *c_parser_parameter_declaration (c_parser *, tree);
876 static tree c_parser_simple_asm_expr (c_parser *);
877 static tree c_parser_attributes (c_parser *);
878 static struct c_type_name *c_parser_type_name (c_parser *);
879 static struct c_expr c_parser_initializer (c_parser *);
880 static struct c_expr c_parser_braced_init (c_parser *, tree, bool);
881 static void c_parser_initelt (c_parser *);
882 static void c_parser_initval (c_parser *, struct c_expr *);
883 static tree c_parser_compound_statement (c_parser *);
884 static void c_parser_compound_statement_nostart (c_parser *);
885 static void c_parser_label (c_parser *);
886 static void c_parser_statement (c_parser *);
887 static void c_parser_statement_after_labels (c_parser *);
888 static void c_parser_if_statement (c_parser *);
889 static void c_parser_switch_statement (c_parser *);
890 static void c_parser_while_statement (c_parser *);
891 static void c_parser_do_statement (c_parser *);
892 static void c_parser_for_statement (c_parser *);
893 static tree c_parser_asm_statement (c_parser *);
894 static tree c_parser_asm_operands (c_parser *, bool);
895 static tree c_parser_asm_clobbers (c_parser *);
896 static struct c_expr c_parser_expr_no_commas (c_parser *, struct c_expr *);
897 static struct c_expr c_parser_conditional_expression (c_parser *,
899 static struct c_expr c_parser_binary_expression (c_parser *, struct c_expr *);
900 static struct c_expr c_parser_cast_expression (c_parser *, struct c_expr *);
901 static struct c_expr c_parser_unary_expression (c_parser *);
902 static struct c_expr c_parser_sizeof_expression (c_parser *);
903 static struct c_expr c_parser_alignof_expression (c_parser *);
904 static struct c_expr c_parser_postfix_expression (c_parser *);
905 static struct c_expr c_parser_postfix_expression_after_paren_type (c_parser *,
906 struct c_type_name *);
907 static struct c_expr c_parser_postfix_expression_after_primary (c_parser *,
909 static struct c_expr c_parser_expression (c_parser *);
910 static struct c_expr c_parser_expression_conv (c_parser *);
911 static tree c_parser_expr_list (c_parser *, bool);
912 static void c_parser_omp_construct (c_parser *);
913 static void c_parser_omp_threadprivate (c_parser *);
914 static void c_parser_omp_barrier (c_parser *);
915 static void c_parser_omp_flush (c_parser *);
916 static void c_parser_omp_taskwait (c_parser *);
918 enum pragma_context { pragma_external, pragma_stmt, pragma_compound };
919 static bool c_parser_pragma (c_parser *, enum pragma_context);
921 /* These Objective-C parser functions are only ever called when
922 compiling Objective-C. */
923 static void c_parser_objc_class_definition (c_parser *);
924 static void c_parser_objc_class_instance_variables (c_parser *);
925 static void c_parser_objc_class_declaration (c_parser *);
926 static void c_parser_objc_alias_declaration (c_parser *);
927 static void c_parser_objc_protocol_definition (c_parser *);
928 static enum tree_code c_parser_objc_method_type (c_parser *);
929 static void c_parser_objc_method_definition (c_parser *);
930 static void c_parser_objc_methodprotolist (c_parser *);
931 static void c_parser_objc_methodproto (c_parser *);
932 static tree c_parser_objc_method_decl (c_parser *);
933 static tree c_parser_objc_type_name (c_parser *);
934 static tree c_parser_objc_protocol_refs (c_parser *);
935 static void c_parser_objc_try_catch_statement (c_parser *);
936 static void c_parser_objc_synchronized_statement (c_parser *);
937 static tree c_parser_objc_selector (c_parser *);
938 static tree c_parser_objc_selector_arg (c_parser *);
939 static tree c_parser_objc_receiver (c_parser *);
940 static tree c_parser_objc_message_args (c_parser *);
941 static tree c_parser_objc_keywordexpr (c_parser *);
943 /* Parse a translation unit (C90 6.7, C99 6.9).
946 external-declarations
948 external-declarations:
950 external-declarations external-declaration
959 c_parser_translation_unit (c_parser *parser)
961 if (c_parser_next_token_is (parser, CPP_EOF))
963 pedwarn (OPT_pedantic, "%HISO C forbids an empty translation unit",
964 &c_parser_peek_token (parser)->location);
968 void *obstack_position = obstack_alloc (&parser_obstack, 0);
972 c_parser_external_declaration (parser);
973 obstack_free (&parser_obstack, obstack_position);
975 while (c_parser_next_token_is_not (parser, CPP_EOF));
979 /* Parse an external declaration (C90 6.7, C99 6.9).
981 external-declaration:
987 external-declaration:
990 __extension__ external-declaration
994 external-declaration:
995 objc-class-definition
996 objc-class-declaration
997 objc-alias-declaration
998 objc-protocol-definition
999 objc-method-definition
1004 c_parser_external_declaration (c_parser *parser)
1007 switch (c_parser_peek_token (parser)->type)
1010 switch (c_parser_peek_token (parser)->keyword)
1013 ext = disable_extension_diagnostics ();
1014 c_parser_consume_token (parser);
1015 c_parser_external_declaration (parser);
1016 restore_extension_diagnostics (ext);
1019 c_parser_asm_definition (parser);
1021 case RID_AT_INTERFACE:
1022 case RID_AT_IMPLEMENTATION:
1023 gcc_assert (c_dialect_objc ());
1024 c_parser_objc_class_definition (parser);
1027 gcc_assert (c_dialect_objc ());
1028 c_parser_objc_class_declaration (parser);
1031 gcc_assert (c_dialect_objc ());
1032 c_parser_objc_alias_declaration (parser);
1034 case RID_AT_PROTOCOL:
1035 gcc_assert (c_dialect_objc ());
1036 c_parser_objc_protocol_definition (parser);
1039 gcc_assert (c_dialect_objc ());
1040 c_parser_consume_token (parser);
1041 objc_finish_implementation ();
1048 pedwarn (OPT_pedantic,
1049 "%HISO C does not allow extra %<;%> outside of a function",
1050 &c_parser_peek_token (parser)->location);
1051 c_parser_consume_token (parser);
1054 c_parser_pragma (parser, pragma_external);
1058 if (c_dialect_objc ())
1060 c_parser_objc_method_definition (parser);
1063 /* Else fall through, and yield a syntax error trying to parse
1064 as a declaration or function definition. */
1067 /* A declaration or a function definition. We can only tell
1068 which after parsing the declaration specifiers, if any, and
1069 the first declarator. */
1070 c_parser_declaration_or_fndef (parser, true, true, false, true);
1076 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1077 6.7, 6.9.1). If FNDEF_OK is true, a function definition is
1078 accepted; otherwise (old-style parameter declarations) only other
1079 declarations are accepted. If NESTED is true, we are inside a
1080 function or parsing old-style parameter declarations; any functions
1081 encountered are nested functions and declaration specifiers are
1082 required; otherwise we are at top level and functions are normal
1083 functions and declaration specifiers may be optional. If EMPTY_OK
1084 is true, empty declarations are OK (subject to all other
1085 constraints); otherwise (old-style parameter declarations) they are
1086 diagnosed. If START_ATTR_OK is true, the declaration specifiers
1087 may start with attributes; otherwise they may not.
1090 declaration-specifiers init-declarator-list[opt] ;
1092 function-definition:
1093 declaration-specifiers[opt] declarator declaration-list[opt]
1098 declaration-list declaration
1100 init-declarator-list:
1102 init-declarator-list , init-declarator
1105 declarator simple-asm-expr[opt] attributes[opt]
1106 declarator simple-asm-expr[opt] attributes[opt] = initializer
1110 nested-function-definition:
1111 declaration-specifiers declarator declaration-list[opt]
1114 The simple-asm-expr and attributes are GNU extensions.
1116 This function does not handle __extension__; that is handled in its
1117 callers. ??? Following the old parser, __extension__ may start
1118 external declarations, declarations in functions and declarations
1119 at the start of "for" loops, but not old-style parameter
1122 C99 requires declaration specifiers in a function definition; the
1123 absence is diagnosed through the diagnosis of implicit int. In GNU
1124 C we also allow but diagnose declarations without declaration
1125 specifiers, but only at top level (elsewhere they conflict with
1131 threadprivate-directive */
1134 c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok, bool empty_ok,
1135 bool nested, bool start_attr_ok)
1137 struct c_declspecs *specs;
1139 tree all_prefix_attrs;
1140 bool diagnosed_no_specs = false;
1141 location_t here = c_parser_peek_token (parser)->location;
1143 specs = build_null_declspecs ();
1144 c_parser_declspecs (parser, specs, true, true, start_attr_ok);
1147 c_parser_skip_to_end_of_block_or_statement (parser);
1150 if (nested && !specs->declspecs_seen_p)
1152 c_parser_error (parser, "expected declaration specifiers");
1153 c_parser_skip_to_end_of_block_or_statement (parser);
1156 finish_declspecs (specs);
1157 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1163 shadow_tag_warned (specs, 1);
1164 pedwarn (0, "%Hempty declaration", &here);
1166 c_parser_consume_token (parser);
1169 pending_xref_error ();
1170 prefix_attrs = specs->attrs;
1171 all_prefix_attrs = prefix_attrs;
1172 specs->attrs = NULL_TREE;
1175 struct c_declarator *declarator;
1178 /* Declaring either one or more declarators (in which case we
1179 should diagnose if there were no declaration specifiers) or a
1180 function definition (in which case the diagnostic for
1181 implicit int suffices). */
1182 declarator = c_parser_declarator (parser, specs->type_seen_p,
1183 C_DTR_NORMAL, &dummy);
1184 if (declarator == NULL)
1186 c_parser_skip_to_end_of_block_or_statement (parser);
1189 if (c_parser_next_token_is (parser, CPP_EQ)
1190 || c_parser_next_token_is (parser, CPP_COMMA)
1191 || c_parser_next_token_is (parser, CPP_SEMICOLON)
1192 || c_parser_next_token_is_keyword (parser, RID_ASM)
1193 || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1195 tree asm_name = NULL_TREE;
1196 tree postfix_attrs = NULL_TREE;
1197 if (!diagnosed_no_specs && !specs->declspecs_seen_p)
1199 diagnosed_no_specs = true;
1200 pedwarn (0, "%Hdata definition has no type or storage class",
1203 /* Having seen a data definition, there cannot now be a
1204 function definition. */
1206 if (c_parser_next_token_is_keyword (parser, RID_ASM))
1207 asm_name = c_parser_simple_asm_expr (parser);
1208 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1209 postfix_attrs = c_parser_attributes (parser);
1210 if (c_parser_next_token_is (parser, CPP_EQ))
1214 c_parser_consume_token (parser);
1215 /* The declaration of the variable is in effect while
1216 its initializer is parsed. */
1217 d = start_decl (declarator, specs, true,
1218 chainon (postfix_attrs, all_prefix_attrs));
1220 d = error_mark_node;
1221 start_init (d, asm_name, global_bindings_p ());
1222 init = c_parser_initializer (parser);
1224 if (d != error_mark_node)
1226 maybe_warn_string_init (TREE_TYPE (d), init);
1227 finish_decl (d, init.value, asm_name);
1232 tree d = start_decl (declarator, specs, false,
1233 chainon (postfix_attrs,
1236 finish_decl (d, NULL_TREE, asm_name);
1238 if (c_parser_next_token_is (parser, CPP_COMMA))
1240 c_parser_consume_token (parser);
1241 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1242 all_prefix_attrs = chainon (c_parser_attributes (parser),
1245 all_prefix_attrs = prefix_attrs;
1248 else if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1250 c_parser_consume_token (parser);
1255 c_parser_error (parser, "expected %<,%> or %<;%>");
1256 c_parser_skip_to_end_of_block_or_statement (parser);
1262 c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, "
1263 "%<asm%> or %<__attribute__%>");
1264 c_parser_skip_to_end_of_block_or_statement (parser);
1267 /* Function definition (nested or otherwise). */
1270 pedwarn (OPT_pedantic, "%HISO C forbids nested functions", &here);
1271 c_push_function_context ();
1273 if (!start_function (specs, declarator, all_prefix_attrs))
1275 /* This can appear in many cases looking nothing like a
1276 function definition, so we don't give a more specific
1277 error suggesting there was one. */
1278 c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
1279 "or %<__attribute__%>");
1281 c_pop_function_context ();
1284 /* Parse old-style parameter declarations. ??? Attributes are
1285 not allowed to start declaration specifiers here because of a
1286 syntax conflict between a function declaration with attribute
1287 suffix and a function definition with an attribute prefix on
1288 first old-style parameter declaration. Following the old
1289 parser, they are not accepted on subsequent old-style
1290 parameter declarations either. However, there is no
1291 ambiguity after the first declaration, nor indeed on the
1292 first as long as we don't allow postfix attributes after a
1293 declarator with a nonempty identifier list in a definition;
1294 and postfix attributes have never been accepted here in
1295 function definitions either. */
1296 while (c_parser_next_token_is_not (parser, CPP_EOF)
1297 && c_parser_next_token_is_not (parser, CPP_OPEN_BRACE))
1298 c_parser_declaration_or_fndef (parser, false, false, true, false);
1299 DECL_SOURCE_LOCATION (current_function_decl)
1300 = c_parser_peek_token (parser)->location;
1301 store_parm_decls ();
1302 fnbody = c_parser_compound_statement (parser);
1305 tree decl = current_function_decl;
1308 c_pop_function_context ();
1309 add_stmt (build_stmt (DECL_EXPR, decl));
1320 /* Parse an asm-definition (asm() outside a function body). This is a
1328 c_parser_asm_definition (c_parser *parser)
1330 tree asm_str = c_parser_simple_asm_expr (parser);
1332 cgraph_add_asm_node (asm_str);
1333 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
1336 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
1337 6.7), adding them to SPECS (which may already include some).
1338 Storage class specifiers are accepted iff SCSPEC_OK; type
1339 specifiers are accepted iff TYPESPEC_OK; attributes are accepted at
1340 the start iff START_ATTR_OK.
1342 declaration-specifiers:
1343 storage-class-specifier declaration-specifiers[opt]
1344 type-specifier declaration-specifiers[opt]
1345 type-qualifier declaration-specifiers[opt]
1346 function-specifier declaration-specifiers[opt]
1348 Function specifiers (inline) are from C99, and are currently
1349 handled as storage class specifiers, as is __thread.
1351 C90 6.5.1, C99 6.7.1:
1352 storage-class-specifier:
1363 C90 6.5.2, C99 6.7.2:
1376 [_Imaginary removed in C99 TC2]
1377 struct-or-union-specifier
1381 (_Bool and _Complex are new in C99.)
1383 C90 6.5.3, C99 6.7.3:
1390 (restrict is new in C99.)
1394 declaration-specifiers:
1395 attributes declaration-specifiers[opt]
1397 storage-class-specifier:
1409 (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
1410 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
1415 class-name objc-protocol-refs[opt]
1416 typedef-name objc-protocol-refs
1421 c_parser_declspecs (c_parser *parser, struct c_declspecs *specs,
1422 bool scspec_ok, bool typespec_ok, bool start_attr_ok)
1424 bool attrs_ok = start_attr_ok;
1425 bool seen_type = specs->type_seen_p;
1426 while (c_parser_next_token_is (parser, CPP_NAME)
1427 || c_parser_next_token_is (parser, CPP_KEYWORD)
1428 || (c_dialect_objc () && c_parser_next_token_is (parser, CPP_LESS)))
1430 struct c_typespec t;
1432 if (c_parser_next_token_is (parser, CPP_NAME))
1434 tree value = c_parser_peek_token (parser)->value;
1435 c_id_kind kind = c_parser_peek_token (parser)->id_kind;
1436 /* This finishes the specifiers unless a type name is OK, it
1437 is declared as a type name and a type name hasn't yet
1439 if (!typespec_ok || seen_type
1440 || (kind != C_ID_TYPENAME && kind != C_ID_CLASSNAME))
1442 c_parser_consume_token (parser);
1445 if (kind == C_ID_TYPENAME
1446 && (!c_dialect_objc ()
1447 || c_parser_next_token_is_not (parser, CPP_LESS)))
1449 t.kind = ctsk_typedef;
1450 /* For a typedef name, record the meaning, not the name.
1451 In case of 'foo foo, bar;'. */
1452 t.spec = lookup_name (value);
1456 tree proto = NULL_TREE;
1457 gcc_assert (c_dialect_objc ());
1459 if (c_parser_next_token_is (parser, CPP_LESS))
1460 proto = c_parser_objc_protocol_refs (parser);
1461 t.spec = objc_get_protocol_qualified_type (value, proto);
1463 declspecs_add_type (specs, t);
1466 if (c_parser_next_token_is (parser, CPP_LESS))
1468 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
1469 nisse@lysator.liu.se. */
1471 gcc_assert (c_dialect_objc ());
1472 if (!typespec_ok || seen_type)
1474 proto = c_parser_objc_protocol_refs (parser);
1476 t.spec = objc_get_protocol_qualified_type (NULL_TREE, proto);
1477 declspecs_add_type (specs, t);
1480 gcc_assert (c_parser_next_token_is (parser, CPP_KEYWORD));
1481 switch (c_parser_peek_token (parser)->keyword)
1493 /* TODO: Distinguish between function specifiers (inline)
1494 and storage class specifiers, either here or in
1495 declspecs_add_scspec. */
1496 declspecs_add_scspec (specs, c_parser_peek_token (parser)->value);
1497 c_parser_consume_token (parser);
1520 if (c_dialect_objc ())
1521 parser->objc_need_raw_identifier = true;
1522 t.kind = ctsk_resword;
1523 t.spec = c_parser_peek_token (parser)->value;
1524 declspecs_add_type (specs, t);
1525 c_parser_consume_token (parser);
1532 t = c_parser_enum_specifier (parser);
1533 declspecs_add_type (specs, t);
1541 t = c_parser_struct_or_union_specifier (parser);
1542 declspecs_add_type (specs, t);
1545 /* ??? The old parser rejected typeof after other type
1546 specifiers, but is a syntax error the best way of
1548 if (!typespec_ok || seen_type)
1552 t = c_parser_typeof_specifier (parser);
1553 declspecs_add_type (specs, t);
1559 declspecs_add_qual (specs, c_parser_peek_token (parser)->value);
1560 c_parser_consume_token (parser);
1565 attrs = c_parser_attributes (parser);
1566 declspecs_add_attrs (specs, attrs);
1575 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
1578 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
1579 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
1580 enum attributes[opt] identifier
1582 The form with trailing comma is new in C99. The forms with
1583 attributes are GNU extensions. In GNU C, we accept any expression
1584 without commas in the syntax (assignment expressions, not just
1585 conditional expressions); assignment expressions will be diagnosed
1590 enumerator-list , enumerator
1593 enumeration-constant
1594 enumeration-constant = constant-expression
1597 static struct c_typespec
1598 c_parser_enum_specifier (c_parser *parser)
1600 struct c_typespec ret;
1602 tree ident = NULL_TREE;
1603 location_t ident_loc;
1604 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ENUM));
1605 c_parser_consume_token (parser);
1606 attrs = c_parser_attributes (parser);
1607 /* Set the location in case we create a decl now. */
1608 c_parser_set_source_position_from_token (c_parser_peek_token (parser));
1609 if (c_parser_next_token_is (parser, CPP_NAME))
1611 ident = c_parser_peek_token (parser)->value;
1612 ident_loc = c_parser_peek_token (parser)->location;
1613 c_parser_consume_token (parser);
1615 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
1617 /* Parse an enum definition. */
1618 struct c_enum_contents the_enum;
1619 tree type = start_enum (&the_enum, ident);
1621 /* We chain the enumerators in reverse order, then put them in
1622 forward order at the end. */
1623 tree values = NULL_TREE;
1624 c_parser_consume_token (parser);
1632 location_t comma_loc;
1633 if (c_parser_next_token_is_not (parser, CPP_NAME))
1635 c_parser_error (parser, "expected identifier");
1636 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
1637 values = error_mark_node;
1640 token = c_parser_peek_token (parser);
1641 enum_id = token->value;
1642 /* Set the location in case we create a decl now. */
1643 c_parser_set_source_position_from_token (token);
1644 c_parser_consume_token (parser);
1645 if (c_parser_next_token_is (parser, CPP_EQ))
1647 c_parser_consume_token (parser);
1648 enum_value = c_parser_expr_no_commas (parser, NULL).value;
1651 enum_value = NULL_TREE;
1652 enum_decl = build_enumerator (&the_enum, enum_id, enum_value);
1653 TREE_CHAIN (enum_decl) = values;
1656 if (c_parser_next_token_is (parser, CPP_COMMA))
1658 comma_loc = c_parser_peek_token (parser)->location;
1660 c_parser_consume_token (parser);
1662 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
1664 if (seen_comma && !flag_isoc99)
1665 pedwarn (OPT_pedantic, "%Hcomma at end of enumerator list",
1667 c_parser_consume_token (parser);
1672 c_parser_error (parser, "expected %<,%> or %<}%>");
1673 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
1674 values = error_mark_node;
1678 postfix_attrs = c_parser_attributes (parser);
1679 ret.spec = finish_enum (type, nreverse (values),
1680 chainon (attrs, postfix_attrs));
1681 ret.kind = ctsk_tagdef;
1686 c_parser_error (parser, "expected %<{%>");
1687 ret.spec = error_mark_node;
1688 ret.kind = ctsk_tagref;
1691 ret = parser_xref_tag (ENUMERAL_TYPE, ident);
1692 /* In ISO C, enumerated types can be referred to only if already
1694 if (pedantic && !COMPLETE_TYPE_P (ret.spec))
1697 pedwarn (OPT_pedantic,
1698 "%HISO C forbids forward references to %<enum%> types",
1704 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
1706 struct-or-union-specifier:
1707 struct-or-union attributes[opt] identifier[opt]
1708 { struct-contents } attributes[opt]
1709 struct-or-union attributes[opt] identifier
1712 struct-declaration-list
1714 struct-declaration-list:
1715 struct-declaration ;
1716 struct-declaration-list struct-declaration ;
1723 struct-declaration-list struct-declaration
1725 struct-declaration-list:
1726 struct-declaration-list ;
1729 (Note that in the syntax here, unlike that in ISO C, the semicolons
1730 are included here rather than in struct-declaration, in order to
1731 describe the syntax with extra semicolons and missing semicolon at
1736 struct-declaration-list:
1737 @defs ( class-name )
1739 (Note this does not include a trailing semicolon, but can be
1740 followed by further declarations, and gets a pedwarn-if-pedantic
1741 when followed by a semicolon.) */
1743 static struct c_typespec
1744 c_parser_struct_or_union_specifier (c_parser *parser)
1746 struct c_typespec ret;
1748 tree ident = NULL_TREE;
1749 enum tree_code code;
1750 switch (c_parser_peek_token (parser)->keyword)
1761 c_parser_consume_token (parser);
1762 attrs = c_parser_attributes (parser);
1763 /* Set the location in case we create a decl now. */
1764 c_parser_set_source_position_from_token (c_parser_peek_token (parser));
1765 if (c_parser_next_token_is (parser, CPP_NAME))
1767 ident = c_parser_peek_token (parser)->value;
1768 c_parser_consume_token (parser);
1770 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
1772 /* Parse a struct or union definition. Start the scope of the
1773 tag before parsing components. */
1774 tree type = start_struct (code, ident);
1776 /* We chain the components in reverse order, then put them in
1777 forward order at the end. Each struct-declaration may
1778 declare multiple components (comma-separated), so we must use
1779 chainon to join them, although when parsing each
1780 struct-declaration we can use TREE_CHAIN directly.
1782 The theory behind all this is that there will be more
1783 semicolon separated fields than comma separated fields, and
1784 so we'll be minimizing the number of node traversals required
1786 tree contents = NULL_TREE;
1787 c_parser_consume_token (parser);
1788 /* Handle the Objective-C @defs construct,
1789 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
1790 if (c_parser_next_token_is_keyword (parser, RID_AT_DEFS))
1793 gcc_assert (c_dialect_objc ());
1794 c_parser_consume_token (parser);
1795 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
1797 if (c_parser_next_token_is (parser, CPP_NAME)
1798 && c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME)
1800 name = c_parser_peek_token (parser)->value;
1801 c_parser_consume_token (parser);
1805 c_parser_error (parser, "expected class name");
1806 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
1809 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
1811 contents = nreverse (objc_get_class_ivars (name));
1814 /* Parse the struct-declarations and semicolons. Problems with
1815 semicolons are diagnosed here; empty structures are diagnosed
1820 /* Parse any stray semicolon. */
1821 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1823 pedwarn (OPT_pedantic,
1824 "%Hextra semicolon in struct or union specified",
1825 &c_parser_peek_token (parser)->location);
1826 c_parser_consume_token (parser);
1829 /* Stop if at the end of the struct or union contents. */
1830 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
1832 c_parser_consume_token (parser);
1835 /* Accept #pragmas at struct scope. */
1836 if (c_parser_next_token_is (parser, CPP_PRAGMA))
1838 c_parser_pragma (parser, pragma_external);
1841 /* Parse some comma-separated declarations, but not the
1842 trailing semicolon if any. */
1843 decls = c_parser_struct_declaration (parser);
1844 contents = chainon (decls, contents);
1845 /* If no semicolon follows, either we have a parse error or
1846 are at the end of the struct or union and should
1848 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1849 c_parser_consume_token (parser);
1852 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
1853 pedwarn (0, "%Hno semicolon at end of struct or union",
1854 &c_parser_peek_token (parser)->location);
1857 c_parser_error (parser, "expected %<;%>");
1858 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
1863 postfix_attrs = c_parser_attributes (parser);
1864 ret.spec = finish_struct (type, nreverse (contents),
1865 chainon (attrs, postfix_attrs));
1866 ret.kind = ctsk_tagdef;
1871 c_parser_error (parser, "expected %<{%>");
1872 ret.spec = error_mark_node;
1873 ret.kind = ctsk_tagref;
1876 ret = parser_xref_tag (code, ident);
1880 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
1881 the trailing semicolon.
1884 specifier-qualifier-list struct-declarator-list
1886 specifier-qualifier-list:
1887 type-specifier specifier-qualifier-list[opt]
1888 type-qualifier specifier-qualifier-list[opt]
1889 attributes specifier-qualifier-list[opt]
1891 struct-declarator-list:
1893 struct-declarator-list , attributes[opt] struct-declarator
1896 declarator attributes[opt]
1897 declarator[opt] : constant-expression attributes[opt]
1902 __extension__ struct-declaration
1903 specifier-qualifier-list
1905 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
1906 of attributes where shown is a GNU extension. In GNU C, we accept
1907 any expression without commas in the syntax (assignment
1908 expressions, not just conditional expressions); assignment
1909 expressions will be diagnosed as non-constant. */
1912 c_parser_struct_declaration (c_parser *parser)
1914 struct c_declspecs *specs;
1916 tree all_prefix_attrs;
1918 location_t decl_loc;
1919 if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
1923 ext = disable_extension_diagnostics ();
1924 c_parser_consume_token (parser);
1925 decl = c_parser_struct_declaration (parser);
1926 restore_extension_diagnostics (ext);
1929 specs = build_null_declspecs ();
1930 decl_loc = c_parser_peek_token (parser)->location;
1931 c_parser_declspecs (parser, specs, false, true, true);
1934 if (!specs->declspecs_seen_p)
1936 c_parser_error (parser, "expected specifier-qualifier-list");
1939 finish_declspecs (specs);
1940 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1943 if (!specs->type_seen_p)
1945 pedwarn (OPT_pedantic,
1946 "%HISO C forbids member declarations with no members",
1948 shadow_tag_warned (specs, pedantic);
1953 /* Support for unnamed structs or unions as members of
1954 structs or unions (which is [a] useful and [b] supports
1957 ret = grokfield (build_id_declarator (NULL_TREE), specs,
1960 decl_attributes (&ret, attrs, 0);
1964 pending_xref_error ();
1965 prefix_attrs = specs->attrs;
1966 all_prefix_attrs = prefix_attrs;
1967 specs->attrs = NULL_TREE;
1971 /* Declaring one or more declarators or un-named bit-fields. */
1972 struct c_declarator *declarator;
1974 if (c_parser_next_token_is (parser, CPP_COLON))
1975 declarator = build_id_declarator (NULL_TREE);
1977 declarator = c_parser_declarator (parser, specs->type_seen_p,
1978 C_DTR_NORMAL, &dummy);
1979 if (declarator == NULL)
1981 c_parser_skip_to_end_of_block_or_statement (parser);
1984 if (c_parser_next_token_is (parser, CPP_COLON)
1985 || c_parser_next_token_is (parser, CPP_COMMA)
1986 || c_parser_next_token_is (parser, CPP_SEMICOLON)
1987 || c_parser_next_token_is (parser, CPP_CLOSE_BRACE)
1988 || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1990 tree postfix_attrs = NULL_TREE;
1991 tree width = NULL_TREE;
1993 if (c_parser_next_token_is (parser, CPP_COLON))
1995 c_parser_consume_token (parser);
1996 width = c_parser_expr_no_commas (parser, NULL).value;
1998 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1999 postfix_attrs = c_parser_attributes (parser);
2000 d = grokfield (declarator, specs, width, &all_prefix_attrs);
2001 decl_attributes (&d, chainon (postfix_attrs,
2002 all_prefix_attrs), 0);
2003 TREE_CHAIN (d) = decls;
2005 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2006 all_prefix_attrs = chainon (c_parser_attributes (parser),
2009 all_prefix_attrs = prefix_attrs;
2010 if (c_parser_next_token_is (parser, CPP_COMMA))
2011 c_parser_consume_token (parser);
2012 else if (c_parser_next_token_is (parser, CPP_SEMICOLON)
2013 || c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2015 /* Semicolon consumed in caller. */
2020 c_parser_error (parser, "expected %<,%>, %<;%> or %<}%>");
2026 c_parser_error (parser,
2027 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
2028 "%<__attribute__%>");
2035 /* Parse a typeof specifier (a GNU extension).
2038 typeof ( expression )
2039 typeof ( type-name )
2042 static struct c_typespec
2043 c_parser_typeof_specifier (c_parser *parser)
2045 struct c_typespec ret;
2046 ret.kind = ctsk_typeof;
2047 ret.spec = error_mark_node;
2048 gcc_assert (c_parser_next_token_is_keyword (parser, RID_TYPEOF));
2049 c_parser_consume_token (parser);
2052 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2058 if (c_parser_next_token_starts_typename (parser))
2060 struct c_type_name *type = c_parser_type_name (parser);
2065 ret.spec = groktypename (type);
2066 pop_maybe_used (variably_modified_type_p (ret.spec, NULL_TREE));
2072 location_t here = c_parser_peek_token (parser)->location;
2073 struct c_expr expr = c_parser_expression (parser);
2076 if (TREE_CODE (expr.value) == COMPONENT_REF
2077 && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
2078 error ("%H%<typeof%> applied to a bit-field", &here);
2079 ret.spec = TREE_TYPE (expr.value);
2080 was_vm = variably_modified_type_p (ret.spec, NULL_TREE);
2081 /* This should be returned with the type so that when the type
2082 is evaluated, this can be evaluated. For now, we avoid
2083 evaluation when the context might. */
2084 if (!skip_evaluation && was_vm)
2086 tree e = expr.value;
2088 /* If the expression is not of a type to which we cannot assign a line
2089 number, wrap the thing in a no-op NOP_EXPR. */
2090 if (DECL_P (e) || CONSTANT_CLASS_P (e))
2091 e = build1 (NOP_EXPR, void_type_node, e);
2093 if (CAN_HAVE_LOCATION_P (e))
2094 SET_EXPR_LOCATION (e, input_location);
2098 pop_maybe_used (was_vm);
2100 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
2104 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
2105 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
2106 be redeclared; otherwise it may not. KIND indicates which kind of
2107 declarator is wanted. Returns a valid declarator except in the
2108 case of a syntax error in which case NULL is returned. *SEEN_ID is
2109 set to true if an identifier being declared is seen; this is used
2110 to diagnose bad forms of abstract array declarators and to
2111 determine whether an identifier list is syntactically permitted.
2114 pointer[opt] direct-declarator
2118 ( attributes[opt] declarator )
2119 direct-declarator array-declarator
2120 direct-declarator ( parameter-type-list )
2121 direct-declarator ( identifier-list[opt] )
2124 * type-qualifier-list[opt]
2125 * type-qualifier-list[opt] pointer
2127 type-qualifier-list:
2130 type-qualifier-list type-qualifier
2131 type-qualifier-list attributes
2133 parameter-type-list:
2135 parameter-list , ...
2138 parameter-declaration
2139 parameter-list , parameter-declaration
2141 parameter-declaration:
2142 declaration-specifiers declarator attributes[opt]
2143 declaration-specifiers abstract-declarator[opt] attributes[opt]
2147 identifier-list , identifier
2149 abstract-declarator:
2151 pointer[opt] direct-abstract-declarator
2153 direct-abstract-declarator:
2154 ( attributes[opt] abstract-declarator )
2155 direct-abstract-declarator[opt] array-declarator
2156 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
2161 direct-declarator ( parameter-forward-declarations
2162 parameter-type-list[opt] )
2164 direct-abstract-declarator:
2165 direct-abstract-declarator[opt] ( parameter-forward-declarations
2166 parameter-type-list[opt] )
2168 parameter-forward-declarations:
2170 parameter-forward-declarations parameter-list ;
2172 The uses of attributes shown above are GNU extensions.
2174 Some forms of array declarator are not included in C99 in the
2175 syntax for abstract declarators; these are disallowed elsewhere.
2176 This may be a defect (DR#289).
2178 This function also accepts an omitted abstract declarator as being
2179 an abstract declarator, although not part of the formal syntax. */
2181 static struct c_declarator *
2182 c_parser_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
2185 /* Parse any initial pointer part. */
2186 if (c_parser_next_token_is (parser, CPP_MULT))
2188 struct c_declspecs *quals_attrs = build_null_declspecs ();
2189 struct c_declarator *inner;
2190 c_parser_consume_token (parser);
2191 c_parser_declspecs (parser, quals_attrs, false, false, true);
2192 inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
2196 return make_pointer_declarator (quals_attrs, inner);
2198 /* Now we have a direct declarator, direct abstract declarator or
2199 nothing (which counts as a direct abstract declarator here). */
2200 return c_parser_direct_declarator (parser, type_seen_p, kind, seen_id);
2203 /* Parse a direct declarator or direct abstract declarator; arguments
2204 as c_parser_declarator. */
2206 static struct c_declarator *
2207 c_parser_direct_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
2210 /* The direct declarator must start with an identifier (possibly
2211 omitted) or a parenthesized declarator (possibly abstract). In
2212 an ordinary declarator, initial parentheses must start a
2213 parenthesized declarator. In an abstract declarator or parameter
2214 declarator, they could start a parenthesized declarator or a
2215 parameter list. To tell which, the open parenthesis and any
2216 following attributes must be read. If a declaration specifier
2217 follows, then it is a parameter list; if the specifier is a
2218 typedef name, there might be an ambiguity about redeclaring it,
2219 which is resolved in the direction of treating it as a typedef
2220 name. If a close parenthesis follows, it is also an empty
2221 parameter list, as the syntax does not permit empty abstract
2222 declarators. Otherwise, it is a parenthesized declarator (in
2223 which case the analysis may be repeated inside it, recursively).
2225 ??? There is an ambiguity in a parameter declaration "int
2226 (__attribute__((foo)) x)", where x is not a typedef name: it
2227 could be an abstract declarator for a function, or declare x with
2228 parentheses. The proper resolution of this ambiguity needs
2229 documenting. At present we follow an accident of the old
2230 parser's implementation, whereby the first parameter must have
2231 some declaration specifiers other than just attributes. Thus as
2232 a parameter declaration it is treated as a parenthesized
2233 parameter named x, and as an abstract declarator it is
2236 ??? Also following the old parser, attributes inside an empty
2237 parameter list are ignored, making it a list not yielding a
2238 prototype, rather than giving an error or making it have one
2239 parameter with implicit type int.
2241 ??? Also following the old parser, typedef names may be
2242 redeclared in declarators, but not Objective-C class names. */
2244 if (kind != C_DTR_ABSTRACT
2245 && c_parser_next_token_is (parser, CPP_NAME)
2247 && c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME)
2248 || c_parser_peek_token (parser)->id_kind == C_ID_ID))
2250 struct c_declarator *inner
2251 = build_id_declarator (c_parser_peek_token (parser)->value);
2253 inner->id_loc = c_parser_peek_token (parser)->location;
2254 c_parser_consume_token (parser);
2255 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2258 if (kind != C_DTR_NORMAL
2259 && c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
2261 struct c_declarator *inner = build_id_declarator (NULL_TREE);
2262 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2265 /* Either we are at the end of an abstract declarator, or we have
2268 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
2271 struct c_declarator *inner;
2272 c_parser_consume_token (parser);
2273 attrs = c_parser_attributes (parser);
2274 if (kind != C_DTR_NORMAL
2275 && (c_parser_next_token_starts_declspecs (parser)
2276 || c_parser_next_token_is (parser, CPP_CLOSE_PAREN)))
2278 struct c_arg_info *args
2279 = c_parser_parms_declarator (parser, kind == C_DTR_NORMAL,
2286 = build_function_declarator (args,
2287 build_id_declarator (NULL_TREE));
2288 return c_parser_direct_declarator_inner (parser, *seen_id,
2292 /* A parenthesized declarator. */
2293 inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
2294 if (inner != NULL && attrs != NULL)
2295 inner = build_attrs_declarator (attrs, inner);
2296 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2298 c_parser_consume_token (parser);
2302 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2306 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2313 if (kind == C_DTR_NORMAL)
2315 c_parser_error (parser, "expected identifier or %<(%>");
2319 return build_id_declarator (NULL_TREE);
2323 /* Parse part of a direct declarator or direct abstract declarator,
2324 given that some (in INNER) has already been parsed; ID_PRESENT is
2325 true if an identifier is present, false for an abstract
2328 static struct c_declarator *
2329 c_parser_direct_declarator_inner (c_parser *parser, bool id_present,
2330 struct c_declarator *inner)
2332 /* Parse a sequence of array declarators and parameter lists. */
2333 if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
2335 struct c_declarator *declarator;
2336 struct c_declspecs *quals_attrs = build_null_declspecs ();
2340 c_parser_consume_token (parser);
2341 c_parser_declspecs (parser, quals_attrs, false, false, true);
2342 static_seen = c_parser_next_token_is_keyword (parser, RID_STATIC);
2344 c_parser_consume_token (parser);
2345 if (static_seen && !quals_attrs->declspecs_seen_p)
2346 c_parser_declspecs (parser, quals_attrs, false, false, true);
2347 if (!quals_attrs->declspecs_seen_p)
2349 /* If "static" is present, there must be an array dimension.
2350 Otherwise, there may be a dimension, "*", or no
2355 dimen = c_parser_expr_no_commas (parser, NULL).value;
2359 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
2364 else if (c_parser_next_token_is (parser, CPP_MULT))
2366 if (c_parser_peek_2nd_token (parser)->type == CPP_CLOSE_SQUARE)
2370 c_parser_consume_token (parser);
2375 dimen = c_parser_expr_no_commas (parser, NULL).value;
2381 dimen = c_parser_expr_no_commas (parser, NULL).value;
2384 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
2385 c_parser_consume_token (parser);
2388 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
2392 declarator = build_array_declarator (dimen, quals_attrs, static_seen,
2394 if (declarator == NULL)
2396 inner = set_array_declarator_inner (declarator, inner);
2397 return c_parser_direct_declarator_inner (parser, id_present, inner);
2399 else if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
2402 struct c_arg_info *args;
2403 c_parser_consume_token (parser);
2404 attrs = c_parser_attributes (parser);
2405 args = c_parser_parms_declarator (parser, id_present, attrs);
2410 inner = build_function_declarator (args, inner);
2411 return c_parser_direct_declarator_inner (parser, id_present, inner);
2417 /* Parse a parameter list or identifier list, including the closing
2418 parenthesis but not the opening one. ATTRS are the attributes at
2419 the start of the list. ID_LIST_OK is true if an identifier list is
2420 acceptable; such a list must not have attributes at the start. */
2422 static struct c_arg_info *
2423 c_parser_parms_declarator (c_parser *parser, bool id_list_ok, tree attrs)
2426 declare_parm_level ();
2427 /* If the list starts with an identifier, it is an identifier list.
2428 Otherwise, it is either a prototype list or an empty list. */
2431 && c_parser_next_token_is (parser, CPP_NAME)
2432 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
2434 tree list = NULL_TREE, *nextp = &list;
2435 while (c_parser_next_token_is (parser, CPP_NAME)
2436 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
2438 *nextp = build_tree_list (NULL_TREE,
2439 c_parser_peek_token (parser)->value);
2440 nextp = & TREE_CHAIN (*nextp);
2441 c_parser_consume_token (parser);
2442 if (c_parser_next_token_is_not (parser, CPP_COMMA))
2444 c_parser_consume_token (parser);
2445 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2447 c_parser_error (parser, "expected identifier");
2451 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2453 struct c_arg_info *ret = XOBNEW (&parser_obstack, struct c_arg_info);
2458 ret->pending_sizes = 0;
2459 ret->had_vla_unspec = 0;
2460 c_parser_consume_token (parser);
2466 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2474 struct c_arg_info *ret = c_parser_parms_list_declarator (parser, attrs);
2480 /* Parse a parameter list (possibly empty), including the closing
2481 parenthesis but not the opening one. ATTRS are the attributes at
2482 the start of the list. */
2484 static struct c_arg_info *
2485 c_parser_parms_list_declarator (c_parser *parser, tree attrs)
2487 bool good_parm = false;
2488 /* ??? Following the old parser, forward parameter declarations may
2489 use abstract declarators, and if no real parameter declarations
2490 follow the forward declarations then this is not diagnosed. Also
2491 note as above that attributes are ignored as the only contents of
2492 the parentheses, or as the only contents after forward
2494 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2496 struct c_arg_info *ret = XOBNEW (&parser_obstack, struct c_arg_info);
2501 ret->pending_sizes = 0;
2502 ret->had_vla_unspec = 0;
2503 c_parser_consume_token (parser);
2506 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
2508 struct c_arg_info *ret = XOBNEW (&parser_obstack, struct c_arg_info);
2512 ret->pending_sizes = 0;
2513 ret->had_vla_unspec = 0;
2514 /* Suppress -Wold-style-definition for this case. */
2515 ret->types = error_mark_node;
2516 error ("%HISO C requires a named argument before %<...%>",
2517 &c_parser_peek_token (parser)->location);
2518 c_parser_consume_token (parser);
2519 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2521 c_parser_consume_token (parser);
2526 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2531 /* Nonempty list of parameters, either terminated with semicolon
2532 (forward declarations; recurse) or with close parenthesis (normal
2533 function) or with ", ... )" (variadic function). */
2536 /* Parse a parameter. */
2537 struct c_parm *parm = c_parser_parameter_declaration (parser, attrs);
2542 push_parm_decl (parm);
2544 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
2547 c_parser_consume_token (parser);
2548 mark_forward_parm_decls ();
2549 new_attrs = c_parser_attributes (parser);
2550 return c_parser_parms_list_declarator (parser, new_attrs);
2552 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2554 c_parser_consume_token (parser);
2556 return get_parm_info (false);
2559 struct c_arg_info *ret
2560 = XOBNEW (&parser_obstack, struct c_arg_info);
2565 ret->pending_sizes = 0;
2566 ret->had_vla_unspec = 0;
2570 if (!c_parser_require (parser, CPP_COMMA,
2571 "expected %<;%>, %<,%> or %<)%>"))
2573 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
2576 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
2578 c_parser_consume_token (parser);
2579 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2581 c_parser_consume_token (parser);
2583 return get_parm_info (true);
2586 struct c_arg_info *ret
2587 = XOBNEW (&parser_obstack, struct c_arg_info);
2592 ret->pending_sizes = 0;
2593 ret->had_vla_unspec = 0;
2599 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2607 /* Parse a parameter declaration. ATTRS are the attributes at the
2608 start of the declaration if it is the first parameter. */
2610 static struct c_parm *
2611 c_parser_parameter_declaration (c_parser *parser, tree attrs)
2613 struct c_declspecs *specs;
2614 struct c_declarator *declarator;
2616 tree postfix_attrs = NULL_TREE;
2618 if (!c_parser_next_token_starts_declspecs (parser))
2620 /* ??? In some Objective-C cases '...' isn't applicable so there
2621 should be a different message. */
2622 c_parser_error (parser,
2623 "expected declaration specifiers or %<...%>");
2624 c_parser_skip_to_end_of_parameter (parser);
2627 specs = build_null_declspecs ();
2630 declspecs_add_attrs (specs, attrs);
2633 c_parser_declspecs (parser, specs, true, true, true);
2634 finish_declspecs (specs);
2635 pending_xref_error ();
2636 prefix_attrs = specs->attrs;
2637 specs->attrs = NULL_TREE;
2638 declarator = c_parser_declarator (parser, specs->type_seen_p,
2639 C_DTR_PARM, &dummy);
2640 if (declarator == NULL)
2642 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
2645 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2646 postfix_attrs = c_parser_attributes (parser);
2647 return build_c_parm (specs, chainon (postfix_attrs, prefix_attrs),
2651 /* Parse a string literal in an asm expression. It should not be
2652 translated, and wide string literals are an error although
2653 permitted by the syntax. This is a GNU extension.
2658 ??? At present, following the old parser, the caller needs to have
2659 set lex_untranslated_string to 1. It would be better to follow the
2660 C++ parser rather than using this kludge. */
2663 c_parser_asm_string_literal (c_parser *parser)
2666 if (c_parser_next_token_is (parser, CPP_STRING))
2668 str = c_parser_peek_token (parser)->value;
2669 c_parser_consume_token (parser);
2671 else if (c_parser_next_token_is (parser, CPP_WSTRING))
2673 error ("%Hwide string literal in %<asm%>",
2674 &c_parser_peek_token (parser)->location);
2675 str = build_string (1, "");
2676 c_parser_consume_token (parser);
2680 c_parser_error (parser, "expected string literal");
2686 /* Parse a simple asm expression. This is used in restricted
2687 contexts, where a full expression with inputs and outputs does not
2688 make sense. This is a GNU extension.
2691 asm ( asm-string-literal )
2695 c_parser_simple_asm_expr (c_parser *parser)
2698 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
2699 /* ??? Follow the C++ parser rather than using the
2700 lex_untranslated_string kludge. */
2701 parser->lex_untranslated_string = true;
2702 c_parser_consume_token (parser);
2703 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2705 parser->lex_untranslated_string = false;
2708 str = c_parser_asm_string_literal (parser);
2709 parser->lex_untranslated_string = false;
2710 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
2712 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
2718 /* Parse (possibly empty) attributes. This is a GNU extension.
2722 attributes attribute
2725 __attribute__ ( ( attribute-list ) )
2729 attribute_list , attrib
2734 any-word ( identifier )
2735 any-word ( identifier , nonempty-expr-list )
2736 any-word ( expr-list )
2738 where the "identifier" must not be declared as a type, and
2739 "any-word" may be any identifier (including one declared as a
2740 type), a reserved word storage class specifier, type specifier or
2741 type qualifier. ??? This still leaves out most reserved keywords
2742 (following the old parser), shouldn't we include them, and why not
2743 allow identifiers declared as types to start the arguments? */
2746 c_parser_attributes (c_parser *parser)
2748 tree attrs = NULL_TREE;
2749 while (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2751 /* ??? Follow the C++ parser rather than using the
2752 lex_untranslated_string kludge. */
2753 parser->lex_untranslated_string = true;
2754 c_parser_consume_token (parser);
2755 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2757 parser->lex_untranslated_string = false;
2760 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2762 parser->lex_untranslated_string = false;
2763 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
2766 /* Parse the attribute list. */
2767 while (c_parser_next_token_is (parser, CPP_COMMA)
2768 || c_parser_next_token_is (parser, CPP_NAME)
2769 || c_parser_next_token_is (parser, CPP_KEYWORD))
2771 tree attr, attr_name, attr_args;
2772 if (c_parser_next_token_is (parser, CPP_COMMA))
2774 c_parser_consume_token (parser);
2777 if (c_parser_next_token_is (parser, CPP_KEYWORD))
2779 /* ??? See comment above about what keywords are
2782 switch (c_parser_peek_token (parser)->keyword)
2820 attr_name = c_parser_peek_token (parser)->value;
2821 c_parser_consume_token (parser);
2822 if (c_parser_next_token_is_not (parser, CPP_OPEN_PAREN))
2824 attr = build_tree_list (attr_name, NULL_TREE);
2825 attrs = chainon (attrs, attr);
2828 c_parser_consume_token (parser);
2829 /* Parse the attribute contents. If they start with an
2830 identifier which is followed by a comma or close
2831 parenthesis, then the arguments start with that
2832 identifier; otherwise they are an expression list. */
2833 if (c_parser_next_token_is (parser, CPP_NAME)
2834 && c_parser_peek_token (parser)->id_kind == C_ID_ID
2835 && ((c_parser_peek_2nd_token (parser)->type == CPP_COMMA)
2836 || (c_parser_peek_2nd_token (parser)->type
2837 == CPP_CLOSE_PAREN)))
2839 tree arg1 = c_parser_peek_token (parser)->value;
2840 c_parser_consume_token (parser);
2841 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2842 attr_args = build_tree_list (NULL_TREE, arg1);
2845 c_parser_consume_token (parser);
2846 attr_args = tree_cons (NULL_TREE, arg1,
2847 c_parser_expr_list (parser, false));
2852 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2853 attr_args = NULL_TREE;
2855 attr_args = c_parser_expr_list (parser, false);
2857 attr = build_tree_list (attr_name, attr_args);
2858 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2859 c_parser_consume_token (parser);
2862 parser->lex_untranslated_string = false;
2863 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2867 attrs = chainon (attrs, attr);
2869 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2870 c_parser_consume_token (parser);
2873 parser->lex_untranslated_string = false;
2874 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2878 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2879 c_parser_consume_token (parser);
2882 parser->lex_untranslated_string = false;
2883 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2887 parser->lex_untranslated_string = false;
2892 /* Parse a type name (C90 6.5.5, C99 6.7.6).
2895 specifier-qualifier-list abstract-declarator[opt]
2898 static struct c_type_name *
2899 c_parser_type_name (c_parser *parser)
2901 struct c_declspecs *specs = build_null_declspecs ();
2902 struct c_declarator *declarator;
2903 struct c_type_name *ret;
2905 c_parser_declspecs (parser, specs, false, true, true);
2906 if (!specs->declspecs_seen_p)
2908 c_parser_error (parser, "expected specifier-qualifier-list");
2911 pending_xref_error ();
2912 finish_declspecs (specs);
2913 declarator = c_parser_declarator (parser, specs->type_seen_p,
2914 C_DTR_ABSTRACT, &dummy);
2915 if (declarator == NULL)
2917 ret = XOBNEW (&parser_obstack, struct c_type_name);
2919 ret->declarator = declarator;
2923 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
2926 assignment-expression
2927 { initializer-list }
2928 { initializer-list , }
2931 designation[opt] initializer
2932 initializer-list , designation[opt] initializer
2939 designator-list designator
2946 [ constant-expression ]
2958 [ constant-expression ... constant-expression ]
2960 Any expression without commas is accepted in the syntax for the
2961 constant-expressions, with non-constant expressions rejected later.
2963 This function is only used for top-level initializers; for nested
2964 ones, see c_parser_initval. */
2966 static struct c_expr
2967 c_parser_initializer (c_parser *parser)
2969 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
2970 return c_parser_braced_init (parser, NULL_TREE, false);
2974 ret = c_parser_expr_no_commas (parser, NULL);
2975 if (TREE_CODE (ret.value) != STRING_CST
2976 && TREE_CODE (ret.value) != COMPOUND_LITERAL_EXPR)
2977 ret = default_function_array_conversion (ret);
2982 /* Parse a braced initializer list. TYPE is the type specified for a
2983 compound literal, and NULL_TREE for other initializers and for
2984 nested braced lists. NESTED_P is true for nested braced lists,
2985 false for the list of a compound literal or the list that is the
2986 top-level initializer in a declaration. */
2988 static struct c_expr
2989 c_parser_braced_init (c_parser *parser, tree type, bool nested_p)
2991 location_t brace_loc = c_parser_peek_token (parser)->location;
2992 gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE));
2993 c_parser_consume_token (parser);
2995 push_init_level (0);
2997 really_start_incremental_init (type);
2998 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3000 pedwarn (OPT_pedantic, "%HISO C forbids empty initializer braces",
3005 /* Parse a non-empty initializer list, possibly with a trailing
3009 c_parser_initelt (parser);
3012 if (c_parser_next_token_is (parser, CPP_COMMA))
3013 c_parser_consume_token (parser);
3016 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3020 if (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE))
3023 ret.value = error_mark_node;
3024 ret.original_code = ERROR_MARK;
3025 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, "expected %<}%>");
3028 c_parser_consume_token (parser);
3029 return pop_init_level (0);
3032 /* Parse a nested initializer, including designators. */
3035 c_parser_initelt (c_parser *parser)
3037 /* Parse any designator or designator list. A single array
3038 designator may have the subsequent "=" omitted in GNU C, but a
3039 longer list or a structure member designator may not. */
3040 if (c_parser_next_token_is (parser, CPP_NAME)
3041 && c_parser_peek_2nd_token (parser)->type == CPP_COLON)
3043 /* Old-style structure member designator. */
3044 set_init_label (c_parser_peek_token (parser)->value);
3045 /* Use the colon as the error location. */
3046 pedwarn (OPT_pedantic,
3047 "%Hobsolete use of designated initializer with %<:%>",
3048 &c_parser_peek_2nd_token (parser)->location);
3049 c_parser_consume_token (parser);
3050 c_parser_consume_token (parser);
3054 /* des_seen is 0 if there have been no designators, 1 if there
3055 has been a single array designator and 2 otherwise. */
3057 /* Location of a designator. */
3059 while (c_parser_next_token_is (parser, CPP_OPEN_SQUARE)
3060 || c_parser_next_token_is (parser, CPP_DOT))
3062 int des_prev = des_seen;
3064 des_loc = c_parser_peek_token (parser)->location;
3067 if (c_parser_next_token_is (parser, CPP_DOT))
3070 c_parser_consume_token (parser);
3071 if (c_parser_next_token_is (parser, CPP_NAME))
3073 set_init_label (c_parser_peek_token (parser)->value);
3074 c_parser_consume_token (parser);
3079 init.value = error_mark_node;
3080 init.original_code = ERROR_MARK;
3081 c_parser_error (parser, "expected identifier");
3082 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
3083 process_init_element (init);
3090 location_t ellipsis_loc;
3091 /* ??? Following the old parser, [ objc-receiver
3092 objc-message-args ] is accepted as an initializer,
3093 being distinguished from a designator by what follows
3094 the first assignment expression inside the square
3095 brackets, but after a first array designator a
3096 subsequent square bracket is for Objective-C taken to
3097 start an expression, using the obsolete form of
3098 designated initializer without '=', rather than
3099 possibly being a second level of designation: in LALR
3100 terms, the '[' is shifted rather than reducing
3101 designator to designator-list. */
3102 if (des_prev == 1 && c_dialect_objc ())
3104 des_seen = des_prev;
3107 if (des_prev == 0 && c_dialect_objc ())
3109 /* This might be an array designator or an
3110 Objective-C message expression. If the former,
3111 continue parsing here; if the latter, parse the
3112 remainder of the initializer given the starting
3113 primary-expression. ??? It might make sense to
3114 distinguish when des_prev == 1 as well; see
3115 previous comment. */
3117 struct c_expr mexpr;
3118 c_parser_consume_token (parser);
3119 if (c_parser_peek_token (parser)->type == CPP_NAME
3120 && ((c_parser_peek_token (parser)->id_kind
3122 || (c_parser_peek_token (parser)->id_kind
3123 == C_ID_CLASSNAME)))
3125 /* Type name receiver. */
3126 tree id = c_parser_peek_token (parser)->value;
3127 c_parser_consume_token (parser);
3128 rec = objc_get_class_reference (id);
3129 goto parse_message_args;
3131 first = c_parser_expr_no_commas (parser, NULL).value;
3132 if (c_parser_next_token_is (parser, CPP_ELLIPSIS)
3133 || c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3134 goto array_desig_after_first;
3135 /* Expression receiver. So far only one part
3136 without commas has been parsed; there might be
3137 more of the expression. */
3139 while (c_parser_next_token_is (parser, CPP_COMMA))
3142 c_parser_consume_token (parser);
3143 next = c_parser_expr_no_commas (parser, NULL);
3144 next = default_function_array_conversion (next);
3145 rec = build_compound_expr (rec, next.value);
3148 /* Now parse the objc-message-args. */
3149 args = c_parser_objc_message_args (parser);
3150 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
3153 = objc_build_message_expr (build_tree_list (rec, args));
3154 mexpr.original_code = ERROR_MARK;
3155 /* Now parse and process the remainder of the
3156 initializer, starting with this message
3157 expression as a primary-expression. */
3158 c_parser_initval (parser, &mexpr);
3161 c_parser_consume_token (parser);
3162 first = c_parser_expr_no_commas (parser, NULL).value;
3163 array_desig_after_first:
3164 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
3166 ellipsis_loc = c_parser_peek_token (parser)->location;
3167 c_parser_consume_token (parser);
3168 second = c_parser_expr_no_commas (parser, NULL).value;
3172 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3174 c_parser_consume_token (parser);
3175 set_init_index (first, second);
3177 pedwarn (OPT_pedantic,
3178 "%HISO C forbids specifying range of "
3179 "elements to initialize", &ellipsis_loc);
3182 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
3188 if (c_parser_next_token_is (parser, CPP_EQ))
3191 pedwarn (OPT_pedantic,
3192 "%HISO C90 forbids specifying subobject "
3193 "to initialize", &des_loc);
3194 c_parser_consume_token (parser);
3200 pedwarn (OPT_pedantic,
3201 "%Hobsolete use of designated initializer "
3203 &c_parser_peek_token (parser)->location);
3208 init.value = error_mark_node;
3209 init.original_code = ERROR_MARK;
3210 c_parser_error (parser, "expected %<=%>");
3211 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
3212 process_init_element (init);
3218 c_parser_initval (parser, NULL);
3221 /* Parse a nested initializer; as c_parser_initializer but parses
3222 initializers within braced lists, after any designators have been
3223 applied. If AFTER is not NULL then it is an Objective-C message
3224 expression which is the primary-expression starting the
3228 c_parser_initval (c_parser *parser, struct c_expr *after)
3231 gcc_assert (!after || c_dialect_objc ());
3232 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE) && !after)
3233 init = c_parser_braced_init (parser, NULL_TREE, true);
3236 init = c_parser_expr_no_commas (parser, after);
3237 if (init.value != NULL_TREE
3238 && TREE_CODE (init.value) != STRING_CST
3239 && TREE_CODE (init.value) != COMPOUND_LITERAL_EXPR)
3240 init = default_function_array_conversion (init);
3242 process_init_element (init);
3245 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
3249 { block-item-list[opt] }
3250 { label-declarations block-item-list }
3254 block-item-list block-item
3266 { label-declarations block-item-list }
3269 __extension__ nested-declaration
3270 nested-function-definition
3274 label-declarations label-declaration
3277 __label__ identifier-list ;
3279 Allowing the mixing of declarations and code is new in C99. The
3280 GNU syntax also permits (not shown above) labels at the end of
3281 compound statements, which yield an error. We don't allow labels
3282 on declarations; this might seem like a natural extension, but
3283 there would be a conflict between attributes on the label and
3284 prefix attributes on the declaration. ??? The syntax follows the
3285 old parser in requiring something after label declarations.
3286 Although they are erroneous if the labels declared aren't defined,
3287 is it useful for the syntax to be this way?
3299 c_parser_compound_statement (c_parser *parser)
3302 if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
3303 return error_mark_node;
3304 stmt = c_begin_compound_stmt (true);
3305 c_parser_compound_statement_nostart (parser);
3306 return c_end_compound_stmt (stmt, true);
3309 /* Parse a compound statement except for the opening brace. This is
3310 used for parsing both compound statements and statement expressions
3311 (which follow different paths to handling the opening). */
3314 c_parser_compound_statement_nostart (c_parser *parser)
3316 bool last_stmt = false;
3317 bool last_label = false;
3318 location_t label_loc;
3319 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3321 c_parser_consume_token (parser);
3324 if (c_parser_next_token_is_keyword (parser, RID_LABEL))
3326 location_t err_loc = c_parser_peek_token (parser)->location;
3327 /* Read zero or more forward-declarations for labels that nested
3328 functions can jump to. */
3329 while (c_parser_next_token_is_keyword (parser, RID_LABEL))
3331 c_parser_consume_token (parser);
3332 /* Any identifiers, including those declared as type names,
3337 if (c_parser_next_token_is_not (parser, CPP_NAME))
3339 c_parser_error (parser, "expected identifier");
3343 = declare_label (c_parser_peek_token (parser)->value);
3344 C_DECLARED_LABEL_FLAG (label) = 1;
3345 add_stmt (build_stmt (DECL_EXPR, label));
3346 c_parser_consume_token (parser);
3347 if (c_parser_next_token_is (parser, CPP_COMMA))
3348 c_parser_consume_token (parser);
3352 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
3354 pedwarn (OPT_pedantic, "%HISO C forbids label declarations", &err_loc);
3356 /* We must now have at least one statement, label or declaration. */
3357 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3359 c_parser_error (parser, "expected declaration or statement");
3360 c_parser_consume_token (parser);
3363 while (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE))
3365 location_t loc = c_parser_peek_token (parser)->location;
3366 if (c_parser_next_token_is_keyword (parser, RID_CASE)
3367 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
3368 || (c_parser_next_token_is (parser, CPP_NAME)
3369 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3371 if (c_parser_next_token_is_keyword (parser, RID_CASE))
3372 label_loc = c_parser_peek_2nd_token (parser)->location;
3374 label_loc = c_parser_peek_token (parser)->location;
3377 c_parser_label (parser);
3379 else if (!last_label
3380 && c_parser_next_token_starts_declspecs (parser))
3383 c_parser_declaration_or_fndef (parser, true, true, true, true);
3385 pedwarn_c90 ((pedantic && !flag_isoc99)
3387 : OPT_Wdeclaration_after_statement,
3388 "%HISO C90 forbids mixed declarations and code",
3392 else if (!last_label
3393 && c_parser_next_token_is_keyword (parser, RID_EXTENSION))
3395 /* __extension__ can start a declaration, but is also an
3396 unary operator that can start an expression. Consume all
3397 but the last of a possible series of __extension__ to
3399 while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD
3400 && (c_parser_peek_2nd_token (parser)->keyword
3402 c_parser_consume_token (parser);
3403 if (c_token_starts_declspecs (c_parser_peek_2nd_token (parser)))
3406 ext = disable_extension_diagnostics ();
3407 c_parser_consume_token (parser);
3409 c_parser_declaration_or_fndef (parser, true, true, true, true);
3410 /* Following the old parser, __extension__ does not
3411 disable this diagnostic. */
3412 restore_extension_diagnostics (ext);
3414 pedwarn_c90 ((pedantic && !flag_isoc99)
3416 : OPT_Wdeclaration_after_statement,
3417 "%HISO C90 forbids mixed declarations and code",
3424 else if (c_parser_next_token_is (parser, CPP_PRAGMA))
3426 /* External pragmas, and some omp pragmas, are not associated
3427 with regular c code, and so are not to be considered statements
3428 syntactically. This ensures that the user doesn't put them
3429 places that would turn into syntax errors if the directive
3431 if (c_parser_pragma (parser, pragma_compound))
3432 last_label = false, last_stmt = true;
3434 else if (c_parser_next_token_is (parser, CPP_EOF))
3436 c_parser_error (parser, "expected declaration or statement");
3439 else if (c_parser_next_token_is_keyword (parser, RID_ELSE))
3441 if (parser->in_if_block)
3443 error ("%H""expected %<}%> before %<else%>", &loc);
3448 error ("%H%<else%> without a previous %<if%>", &loc);
3449 c_parser_consume_token (parser);
3458 c_parser_statement_after_labels (parser);
3461 parser->error = false;
3464 error ("%Hlabel at end of compound statement", &label_loc);
3465 c_parser_consume_token (parser);
3468 /* Parse a label (C90 6.6.1, C99 6.8.1).
3471 identifier : attributes[opt]
3472 case constant-expression :
3478 case constant-expression ... constant-expression :
3480 The use of attributes on labels is a GNU extension. The syntax in
3481 GNU C accepts any expressions without commas, non-constant
3482 expressions being rejected later. */
3485 c_parser_label (c_parser *parser)
3487 location_t loc1 = c_parser_peek_token (parser)->location;
3488 tree label = NULL_TREE;
3489 if (c_parser_next_token_is_keyword (parser, RID_CASE))
3492 c_parser_consume_token (parser);
3493 exp1 = c_parser_expr_no_commas (parser, NULL).value;
3494 if (c_parser_next_token_is (parser, CPP_COLON))
3496 c_parser_consume_token (parser);
3497 label = do_case (exp1, NULL_TREE);
3499 else if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
3501 c_parser_consume_token (parser);
3502 exp2 = c_parser_expr_no_commas (parser, NULL).value;
3503 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
3504 label = do_case (exp1, exp2);
3507 c_parser_error (parser, "expected %<:%> or %<...%>");
3509 else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT))
3511 c_parser_consume_token (parser);
3512 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
3513 label = do_case (NULL_TREE, NULL_TREE);
3517 tree name = c_parser_peek_token (parser)->value;
3520 location_t loc2 = c_parser_peek_token (parser)->location;
3521 gcc_assert (c_parser_next_token_is (parser, CPP_NAME));
3522 c_parser_consume_token (parser);
3523 gcc_assert (c_parser_next_token_is (parser, CPP_COLON));
3524 c_parser_consume_token (parser);
3525 attrs = c_parser_attributes (parser);
3526 tlab = define_label (loc2, name);
3529 decl_attributes (&tlab, attrs, 0);
3530 label = add_stmt (build_stmt (LABEL_EXPR, tlab));
3535 SET_EXPR_LOCATION (label, loc1);
3536 if (c_parser_next_token_starts_declspecs (parser)
3537 && !(c_parser_next_token_is (parser, CPP_NAME)
3538 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3540 error ("%Ha label can only be part of a statement and "
3541 "a declaration is not a statement",
3542 &c_parser_peek_token (parser)->location);
3543 c_parser_declaration_or_fndef (parser, /*fndef_ok*/ false,
3544 /*nested*/ true, /*empty_ok*/ false,
3545 /*start_attr_ok*/ true);
3550 /* Parse a statement (C90 6.6, C99 6.8).
3555 expression-statement
3563 expression-statement:
3566 selection-statement:
3570 iteration-statement:
3579 return expression[opt] ;
3592 objc-throw-statement
3593 objc-try-catch-statement
3594 objc-synchronized-statement
3596 objc-throw-statement:
3610 parallel-for-construct
3611 parallel-sections-construct
3618 parallel-directive structured-block
3621 for-directive iteration-statement
3624 sections-directive section-scope
3627 single-directive structured-block
3629 parallel-for-construct:
3630 parallel-for-directive iteration-statement
3632 parallel-sections-construct:
3633 parallel-sections-directive section-scope
3636 master-directive structured-block
3639 critical-directive structured-block
3642 atomic-directive expression-statement
3645 ordered-directive structured-block */
3648 c_parser_statement (c_parser *parser)
3650 while (c_parser_next_token_is_keyword (parser, RID_CASE)
3651 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
3652 || (c_parser_next_token_is (parser, CPP_NAME)
3653 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3654 c_parser_label (parser);
3655 c_parser_statement_after_labels (parser);
3658 /* Parse a statement, other than a labeled statement. */
3661 c_parser_statement_after_labels (c_parser *parser)
3663 location_t loc = c_parser_peek_token (parser)->location;
3664 tree stmt = NULL_TREE;
3665 bool in_if_block = parser->in_if_block;
3666 parser->in_if_block = false;
3667 switch (c_parser_peek_token (parser)->type)
3669 case CPP_OPEN_BRACE:
3670 add_stmt (c_parser_compound_statement (parser));
3673 switch (c_parser_peek_token (parser)->keyword)
3676 c_parser_if_statement (parser);
3679 c_parser_switch_statement (parser);
3682 c_parser_while_statement (parser);
3685 c_parser_do_statement (parser);
3688 c_parser_for_statement (parser);
3691 c_parser_consume_token (parser);
3692 if (c_parser_next_token_is (parser, CPP_NAME))
3694 stmt = c_finish_goto_label (c_parser_peek_token (parser)->value);
3695 c_parser_consume_token (parser);
3697 else if (c_parser_next_token_is (parser, CPP_MULT))
3699 c_parser_consume_token (parser);
3700 stmt = c_finish_goto_ptr (c_parser_expression (parser).value);
3703 c_parser_error (parser, "expected identifier or %<*%>");
3704 goto expect_semicolon;
3706 c_parser_consume_token (parser);
3707 stmt = c_finish_bc_stmt (&c_cont_label, false);
3708 goto expect_semicolon;
3710 c_parser_consume_token (parser);
3711 stmt = c_finish_bc_stmt (&c_break_label, true);
3712 goto expect_semicolon;
3714 c_parser_consume_token (parser);
3715 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3717 stmt = c_finish_return (NULL_TREE);
3718 c_parser_consume_token (parser);
3722 stmt = c_finish_return (c_parser_expression_conv (parser).value);
3723 goto expect_semicolon;
3727 stmt = c_parser_asm_statement (parser);
3730 gcc_assert (c_dialect_objc ());
3731 c_parser_consume_token (parser);
3732 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3734 stmt = objc_build_throw_stmt (NULL_TREE);
3735 c_parser_consume_token (parser);
3740 = objc_build_throw_stmt (c_parser_expression (parser).value);
3741 goto expect_semicolon;
3745 gcc_assert (c_dialect_objc ());
3746 c_parser_objc_try_catch_statement (parser);
3748 case RID_AT_SYNCHRONIZED:
3749 gcc_assert (c_dialect_objc ());
3750 c_parser_objc_synchronized_statement (parser);
3757 c_parser_consume_token (parser);
3759 case CPP_CLOSE_PAREN:
3760 case CPP_CLOSE_SQUARE:
3761 /* Avoid infinite loop in error recovery:
3762 c_parser_skip_until_found stops at a closing nesting
3763 delimiter without consuming it, but here we need to consume
3764 it to proceed further. */
3765 c_parser_error (parser, "expected statement");
3766 c_parser_consume_token (parser);
3769 c_parser_pragma (parser, pragma_stmt);
3773 stmt = c_finish_expr_stmt (c_parser_expression_conv (parser).value);
3775 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
3778 /* Two cases cannot and do not have line numbers associated: If stmt
3779 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
3780 cannot hold line numbers. But that's OK because the statement
3781 will either be changed to a MODIFY_EXPR during gimplification of
3782 the statement expr, or discarded. If stmt was compound, but
3783 without new variables, we will have skipped the creation of a
3784 BIND and will have a bare STATEMENT_LIST. But that's OK because
3785 (recursively) all of the component statements should already have
3786 line numbers assigned. ??? Can we discard no-op statements
3788 if (stmt && CAN_HAVE_LOCATION_P (stmt))
3789 SET_EXPR_LOCATION (stmt, loc);
3791 parser->in_if_block = in_if_block;
3794 /* Parse a parenthesized condition from an if, do or while statement.
3800 c_parser_paren_condition (c_parser *parser)
3804 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3805 return error_mark_node;
3806 loc = c_parser_peek_token (parser)->location;
3807 cond = c_objc_common_truthvalue_conversion
3808 (c_parser_expression_conv (parser).value);
3809 if (CAN_HAVE_LOCATION_P (cond))
3810 SET_EXPR_LOCATION (cond, loc);
3811 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
3815 /* Parse a statement which is a block in C99. */
3818 c_parser_c99_block_statement (c_parser *parser)
3820 tree block = c_begin_compound_stmt (flag_isoc99);
3821 c_parser_statement (parser);
3822 return c_end_compound_stmt (block, flag_isoc99);
3825 /* Parse the body of an if statement. This is just parsing a
3826 statement but (a) it is a block in C99, (b) we track whether the
3827 body is an if statement for the sake of -Wparentheses warnings, (c)
3828 we handle an empty body specially for the sake of -Wempty-body
3829 warnings, and (d) we call parser_compound_statement directly
3830 because c_parser_statement_after_labels resets
3831 parser->in_if_block. */
3834 c_parser_if_body (c_parser *parser, bool *if_p)
3836 tree block = c_begin_compound_stmt (flag_isoc99);
3837 while (c_parser_next_token_is_keyword (parser, RID_CASE)
3838 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
3839 || (c_parser_next_token_is (parser, CPP_NAME)
3840 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3841 c_parser_label (parser);
3842 *if_p = c_parser_next_token_is_keyword (parser, RID_IF);
3843 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3845 add_stmt (build_empty_stmt ());
3846 c_parser_consume_token (parser);
3848 else if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
3849 add_stmt (c_parser_compound_statement (parser));
3851 c_parser_statement_after_labels (parser);
3852 return c_end_compound_stmt (block, flag_isoc99);
3855 /* Parse the else body of an if statement. This is just parsing a
3856 statement but (a) it is a block in C99, (b) we handle an empty body
3857 specially for the sake of -Wempty-body warnings. */
3860 c_parser_else_body (c_parser *parser)
3862 tree block = c_begin_compound_stmt (flag_isoc99);
3863 while (c_parser_next_token_is_keyword (parser, RID_CASE)
3864 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
3865 || (c_parser_next_token_is (parser, CPP_NAME)
3866 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3867 c_parser_label (parser);
3868 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3870 add_stmt (build_empty_stmt ());
3871 c_parser_consume_token (parser);
3874 c_parser_statement_after_labels (parser);
3875 return c_end_compound_stmt (block, flag_isoc99);
3878 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
3881 if ( expression ) statement
3882 if ( expression ) statement else statement
3886 c_parser_if_statement (c_parser *parser)
3891 bool first_if = false;
3892 tree first_body, second_body;
3895 gcc_assert (c_parser_next_token_is_keyword (parser, RID_IF));
3896 c_parser_consume_token (parser);
3897 block = c_begin_compound_stmt (flag_isoc99);
3898 loc = c_parser_peek_token (parser)->location;
3899 cond = c_parser_paren_condition (parser);
3900 in_if_block = parser->in_if_block;
3901 parser->in_if_block = true;
3902 first_body = c_parser_if_body (parser, &first_if);
3903 parser->in_if_block = in_if_block;
3904 if (c_parser_next_token_is_keyword (parser, RID_ELSE))
3906 c_parser_consume_token (parser);
3907 second_body = c_parser_else_body (parser);
3910 second_body = NULL_TREE;
3911 c_finish_if_stmt (loc, cond, first_body, second_body, first_if);
3912 add_stmt (c_end_compound_stmt (block, flag_isoc99));
3915 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
3918 switch (expression) statement
3922 c_parser_switch_statement (c_parser *parser)
3924 tree block, expr, body, save_break;
3925 gcc_assert (c_parser_next_token_is_keyword (parser, RID_SWITCH));
3926 c_parser_consume_token (parser);
3927 block = c_begin_compound_stmt (flag_isoc99);
3928 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3930 expr = c_parser_expression (parser).value;
3931 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
3934 expr = error_mark_node;
3935 c_start_case (expr);
3936 save_break = c_break_label;
3937 c_break_label = NULL_TREE;
3938 body = c_parser_c99_block_statement (parser);
3939 c_finish_case (body);
3941 add_stmt (build1 (LABEL_EXPR, void_type_node, c_break_label));
3942 c_break_label = save_break;
3943 add_stmt (c_end_compound_stmt (block, flag_isoc99));
3946 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
3949 while (expression) statement
3953 c_parser_while_statement (c_parser *parser)
3955 tree block, cond, body, save_break, save_cont;
3957 gcc_assert (c_parser_next_token_is_keyword (parser, RID_WHILE));
3958 c_parser_consume_token (parser);
3959 block = c_begin_compound_stmt (flag_isoc99);
3960 loc = c_parser_peek_token (parser)->location;
3961 cond = c_parser_paren_condition (parser);
3962 save_break = c_break_label;
3963 c_break_label = NULL_TREE;
3964 save_cont = c_cont_label;
3965 c_cont_label = NULL_TREE;
3966 body = c_parser_c99_block_statement (parser);
3967 c_finish_loop (loc, cond, NULL, body, c_break_label, c_cont_label, true);
3968 add_stmt (c_end_compound_stmt (block, flag_isoc99));
3969 c_break_label = save_break;
3970 c_cont_label = save_cont;
3973 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
3976 do statement while ( expression ) ;
3980 c_parser_do_statement (c_parser *parser)
3982 tree block, cond, body, save_break, save_cont, new_break, new_cont;
3984 gcc_assert (c_parser_next_token_is_keyword (parser, RID_DO));
3985 c_parser_consume_token (parser);
3986 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3987 warning (OPT_Wempty_body,
3988 "%Hsuggest braces around empty body in %<do%> statement",
3989 &c_parser_peek_token (parser)->location);
3990 block = c_begin_compound_stmt (flag_isoc99);
3991 loc = c_parser_peek_token (parser)->location;
3992 save_break = c_break_label;
3993 c_break_label = NULL_TREE;
3994 save_cont = c_cont_label;
3995 c_cont_label = NULL_TREE;
3996 body = c_parser_c99_block_statement (parser);
3997 c_parser_require_keyword (parser, RID_WHILE, "expected %<while%>");
3998 new_break = c_break_label;
3999 c_break_label = save_break;
4000 new_cont = c_cont_label;
4001 c_cont_label = save_cont;
4002 cond = c_parser_paren_condition (parser);
4003 if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
4004 c_parser_skip_to_end_of_block_or_statement (parser);
4005 c_finish_loop (loc, cond, NULL, body, new_break, new_cont, false);
4006 add_stmt (c_end_compound_stmt (block, flag_isoc99));
4009 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
4012 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
4013 for ( nested-declaration expression[opt] ; expression[opt] ) statement
4015 The form with a declaration is new in C99.
4017 ??? In accordance with the old parser, the declaration may be a
4018 nested function, which is then rejected in check_for_loop_decls,
4019 but does it make any sense for this to be included in the grammar?
4020 Note in particular that the nested function does not include a
4021 trailing ';', whereas the "declaration" production includes one.
4022 Also, can we reject bad declarations earlier and cheaper than
4023 check_for_loop_decls? */
4026 c_parser_for_statement (c_parser *parser)
4028 tree block, cond, incr, save_break, save_cont, body;
4030 gcc_assert (c_parser_next_token_is_keyword (parser, RID_FOR));
4031 loc = c_parser_peek_token (parser)->location;
4032 c_parser_consume_token (parser);
4033 block = c_begin_compound_stmt (flag_isoc99);
4034 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4036 /* Parse the initialization declaration or expression. */
4037 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4039 c_parser_consume_token (parser);
4040 c_finish_expr_stmt (NULL_TREE);
4042 else if (c_parser_next_token_starts_declspecs (parser))
4044 c_parser_declaration_or_fndef (parser, true, true, true, true);
4045 check_for_loop_decls ();
4047 else if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
4049 /* __extension__ can start a declaration, but is also an
4050 unary operator that can start an expression. Consume all
4051 but the last of a possible series of __extension__ to
4053 while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD
4054 && (c_parser_peek_2nd_token (parser)->keyword
4056 c_parser_consume_token (parser);
4057 if (c_token_starts_declspecs (c_parser_peek_2nd_token (parser)))
4060 ext = disable_extension_diagnostics ();
4061 c_parser_consume_token (parser);
4062 c_parser_declaration_or_fndef (parser, true, true, true, true);
4063 restore_extension_diagnostics (ext);
4064 check_for_loop_decls ();
4072 c_finish_expr_stmt (c_parser_expression (parser).value);
4073 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4075 /* Parse the loop condition. */
4076 loc = c_parser_peek_token (parser)->location;
4077 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4079 c_parser_consume_token (parser);
4084 tree ocond = c_parser_expression_conv (parser).value;
4085 cond = c_objc_common_truthvalue_conversion (ocond);
4086 if (CAN_HAVE_LOCATION_P (cond))
4087 SET_EXPR_LOCATION (cond, loc);
4088 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4090 /* Parse the increment expression. */
4091 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4092 incr = c_process_expr_stmt (NULL_TREE);
4094 incr = c_process_expr_stmt (c_parser_expression (parser).value);
4095 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4099 cond = error_mark_node;
4100 incr = error_mark_node;
4102 save_break = c_break_label;
4103 c_break_label = NULL_TREE;
4104 save_cont = c_cont_label;
4105 c_cont_label = NULL_TREE;
4106 body = c_parser_c99_block_statement (parser);
4107 c_finish_loop (loc, cond, incr, body, c_break_label, c_cont_label, true);
4108 add_stmt (c_end_compound_stmt (block, flag_isoc99));
4109 c_break_label = save_break;
4110 c_cont_label = save_cont;
4113 /* Parse an asm statement, a GNU extension. This is a full-blown asm
4114 statement with inputs, outputs, clobbers, and volatile tag
4118 asm type-qualifier[opt] ( asm-argument ) ;
4122 asm-string-literal : asm-operands[opt]
4123 asm-string-literal : asm-operands[opt] : asm-operands[opt]
4124 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers
4126 Qualifiers other than volatile are accepted in the syntax but
4130 c_parser_asm_statement (c_parser *parser)
4132 tree quals, str, outputs, inputs, clobbers, ret;
4134 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
4135 c_parser_consume_token (parser);
4136 if (c_parser_next_token_is_keyword (parser, RID_VOLATILE))
4138 quals = c_parser_peek_token (parser)->value;
4139 c_parser_consume_token (parser);
4141 else if (c_parser_next_token_is_keyword (parser, RID_CONST)
4142 || c_parser_next_token_is_keyword (parser, RID_RESTRICT))
4144 warning (0, "%H%E qualifier ignored on asm",
4145 &c_parser_peek_token (parser)->location,
4146 c_parser_peek_token (parser)->value);
4148 c_parser_consume_token (parser);
4152 /* ??? Follow the C++ parser rather than using the
4153 lex_untranslated_string kludge. */
4154 parser->lex_untranslated_string = true;
4155 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4157 parser->lex_untranslated_string = false;
4160 str = c_parser_asm_string_literal (parser);
4161 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4164 outputs = NULL_TREE;
4166 clobbers = NULL_TREE;
4169 if (!c_parser_require (parser, CPP_COLON, "expected %<:%> or %<)%>"))
4171 parser->lex_untranslated_string = false;
4172 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4176 /* Parse outputs. */
4177 if (c_parser_next_token_is (parser, CPP_COLON)
4178 || c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4179 outputs = NULL_TREE;
4181 outputs = c_parser_asm_operands (parser, false);
4182 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4185 clobbers = NULL_TREE;
4188 if (!c_parser_require (parser, CPP_COLON, "expected %<:%> or %<)%>"))
4190 parser->lex_untranslated_string = false;
4191 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4195 if (c_parser_next_token_is (parser, CPP_COLON)
4196 || c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4199 inputs = c_parser_asm_operands (parser, true);
4200 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4202 clobbers = NULL_TREE;
4205 if (!c_parser_require (parser, CPP_COLON, "expected %<:%> or %<)%>"))
4207 parser->lex_untranslated_string = false;
4208 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4211 /* Parse clobbers. */
4212 clobbers = c_parser_asm_clobbers (parser);
4214 parser->lex_untranslated_string = false;
4215 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
4217 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4220 if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
4221 c_parser_skip_to_end_of_block_or_statement (parser);
4222 ret = build_asm_stmt (quals, build_asm_expr (str, outputs, inputs,
4227 /* Parse asm operands, a GNU extension. If CONVERT_P (for inputs but
4228 not outputs), apply the default conversion of functions and arrays
4233 asm-operands , asm-operand
4236 asm-string-literal ( expression )
4237 [ identifier ] asm-string-literal ( expression )
4241 c_parser_asm_operands (c_parser *parser, bool convert_p)
4243 tree list = NULL_TREE;
4248 if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
4250 c_parser_consume_token (parser);
4251 if (c_parser_next_token_is (parser, CPP_NAME))
4253 tree id = c_parser_peek_token (parser)->value;
4254 c_parser_consume_token (parser);
4255 name = build_string (IDENTIFIER_LENGTH (id),
4256 IDENTIFIER_POINTER (id));
4260 c_parser_error (parser, "expected identifier");
4261 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
4264 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
4269 str = c_parser_asm_string_literal (parser);
4270 if (str == NULL_TREE)
4272 parser->lex_untranslated_string = false;
4273 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4275 parser->lex_untranslated_string = true;
4278 expr = c_parser_expression (parser);
4280 expr = default_function_array_conversion (expr);
4281 parser->lex_untranslated_string = true;
4282 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
4284 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4287 list = chainon (list, build_tree_list (build_tree_list (name, str),
4289 if (c_parser_next_token_is (parser, CPP_COMMA))
4290 c_parser_consume_token (parser);
4297 /* Parse asm clobbers, a GNU extension.
4301 asm-clobbers , asm-string-literal
4305 c_parser_asm_clobbers (c_parser *parser)
4307 tree list = NULL_TREE;
4310 tree str = c_parser_asm_string_literal (parser);
4312 list = tree_cons (NULL_TREE, str, list);
4315 if (c_parser_next_token_is (parser, CPP_COMMA))
4316 c_parser_consume_token (parser);
4323 /* Parse an expression other than a compound expression; that is, an
4324 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
4325 NULL then it is an Objective-C message expression which is the
4326 primary-expression starting the expression as an initializer.
4328 assignment-expression:
4329 conditional-expression
4330 unary-expression assignment-operator assignment-expression
4332 assignment-operator: one of
4333 = *= /= %= += -= <<= >>= &= ^= |=
4335 In GNU C we accept any conditional expression on the LHS and
4336 diagnose the invalid lvalue rather than producing a syntax
4339 static struct c_expr
4340 c_parser_expr_no_commas (c_parser *parser, struct c_expr *after)
4342 struct c_expr lhs, rhs, ret;
4343 enum tree_code code;
4344 gcc_assert (!after || c_dialect_objc ());
4345 lhs = c_parser_conditional_expression (parser, after);
4346 switch (c_parser_peek_token (parser)->type)
4355 code = TRUNC_DIV_EXPR;
4358 code = TRUNC_MOD_EXPR;
4373 code = BIT_AND_EXPR;
4376 code = BIT_XOR_EXPR;
4379 code = BIT_IOR_EXPR;
4384 c_parser_consume_token (parser);
4385 rhs = c_parser_expr_no_commas (parser, NULL);
4386 rhs = default_function_array_conversion (rhs);
4387 ret.value = build_modify_expr (lhs.value, code, rhs.value);
4388 if (code == NOP_EXPR)
4389 ret.original_code = MODIFY_EXPR;
4392 TREE_NO_WARNING (ret.value) = 1;
4393 ret.original_code = ERROR_MARK;
4398 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
4399 is not NULL then it is an Objective-C message expression which is
4400 the primary-expression starting the expression as an initializer.
4402 conditional-expression:
4403 logical-OR-expression
4404 logical-OR-expression ? expression : conditional-expression
4408 conditional-expression:
4409 logical-OR-expression ? : conditional-expression
4412 static struct c_expr
4413 c_parser_conditional_expression (c_parser *parser, struct c_expr *after)
4415 struct c_expr cond, exp1, exp2, ret;
4416 gcc_assert (!after || c_dialect_objc ());
4417 cond = c_parser_binary_expression (parser, after);
4418 if (c_parser_next_token_is_not (parser, CPP_QUERY))
4420 cond = default_function_array_conversion (cond);
4421 c_parser_consume_token (parser);
4422 if (c_parser_next_token_is (parser, CPP_COLON))
4424 pedwarn (OPT_pedantic,
4425 "%HISO C forbids omitting the middle term of a ?: expression",
4426 &c_parser_peek_token (parser)->location);
4427 /* Make sure first operand is calculated only once. */
4428 exp1.value = save_expr (default_conversion (cond.value));
4429 cond.value = c_objc_common_truthvalue_conversion (exp1.value);
4430 skip_evaluation += cond.value == truthvalue_true_node;
4435 = c_objc_common_truthvalue_conversion
4436 (default_conversion (cond.value));
4437 skip_evaluation += cond.value == truthvalue_false_node;
4438 exp1 = c_parser_expression_conv (parser);
4439 skip_evaluation += ((cond.value == truthvalue_true_node)
4440 - (cond.value == truthvalue_false_node));
4442 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
4444 skip_evaluation -= cond.value == truthvalue_true_node;
4445 ret.value = error_mark_node;
4446 ret.original_code = ERROR_MARK;
4449 exp2 = c_parser_conditional_expression (parser, NULL);
4450 exp2 = default_function_array_conversion (exp2);
4451 skip_evaluation -= cond.value == truthvalue_true_node;
4452 ret.value = build_conditional_expr (cond.value, exp1.value, exp2.value);
4453 ret.original_code = ERROR_MARK;
4457 /* Parse a binary expression; that is, a logical-OR-expression (C90
4458 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
4459 an Objective-C message expression which is the primary-expression
4460 starting the expression as an initializer.
4462 multiplicative-expression:
4464 multiplicative-expression * cast-expression
4465 multiplicative-expression / cast-expression
4466 multiplicative-expression % cast-expression
4468 additive-expression:
4469 multiplicative-expression
4470 additive-expression + multiplicative-expression
4471 additive-expression - multiplicative-expression
4475 shift-expression << additive-expression
4476 shift-expression >> additive-expression
4478 relational-expression:
4480 relational-expression < shift-expression
4481 relational-expression > shift-expression
4482 relational-expression <= shift-expression
4483 relational-expression >= shift-expression
4485 equality-expression:
4486 relational-expression
4487 equality-expression == relational-expression
4488 equality-expression != relational-expression
4492 AND-expression & equality-expression
4494 exclusive-OR-expression:
4496 exclusive-OR-expression ^ AND-expression
4498 inclusive-OR-expression:
4499 exclusive-OR-expression
4500 inclusive-OR-expression | exclusive-OR-expression
4502 logical-AND-expression:
4503 inclusive-OR-expression
4504 logical-AND-expression && inclusive-OR-expression
4506 logical-OR-expression:
4507 logical-AND-expression
4508 logical-OR-expression || logical-AND-expression
4511 static struct c_expr
4512 c_parser_binary_expression (c_parser *parser, struct c_expr *after)
4514 /* A binary expression is parsed using operator-precedence parsing,
4515 with the operands being cast expressions. All the binary
4516 operators are left-associative. Thus a binary expression is of
4519 E0 op1 E1 op2 E2 ...
4521 which we represent on a stack. On the stack, the precedence
4522 levels are strictly increasing. When a new operator is
4523 encountered of higher precedence than that at the top of the
4524 stack, it is pushed; its LHS is the top expression, and its RHS
4525 is everything parsed until it is popped. When a new operator is
4526 encountered with precedence less than or equal to that at the top
4527 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
4528 by the result of the operation until the operator at the top of
4529 the stack has lower precedence than the new operator or there is
4530 only one element on the stack; then the top expression is the LHS
4531 of the new operator. In the case of logical AND and OR
4532 expressions, we also need to adjust skip_evaluation as
4533 appropriate when the operators are pushed and popped. */
4535 /* The precedence levels, where 0 is a dummy lowest level used for
4536 the bottom of the stack. */
4552 /* The expression at this stack level. */
4554 /* The precedence of the operator on its left, PREC_NONE at the
4555 bottom of the stack. */
4557 /* The operation on its left. */
4563 switch (stack[sp].op) \
4565 case TRUTH_ANDIF_EXPR: \
4566 skip_evaluation -= stack[sp - 1].expr.value == truthvalue_false_node; \
4568 case TRUTH_ORIF_EXPR: \
4569 skip_evaluation -= stack[sp - 1].expr.value == truthvalue_true_node; \
4574 stack[sp - 1].expr \
4575 = default_function_array_conversion (stack[sp - 1].expr); \
4577 = default_function_array_conversion (stack[sp].expr); \
4578 stack[sp - 1].expr = parser_build_binary_op (stack[sp].op, \
4579 stack[sp - 1].expr, \
4583 gcc_assert (!after || c_dialect_objc ());
4584 stack[0].expr = c_parser_cast_expression (parser, after);
4585 stack[0].prec = PREC_NONE;
4590 enum tree_code ocode;
4593 switch (c_parser_peek_token (parser)->type)
4601 ocode = TRUNC_DIV_EXPR;
4605 ocode = TRUNC_MOD_EXPR;
4617 ocode = LSHIFT_EXPR;
4621 ocode = RSHIFT_EXPR;
4635 case CPP_GREATER_EQ:
4648 oprec = PREC_BITAND;
4649 ocode = BIT_AND_EXPR;
4652 oprec = PREC_BITXOR;
4653 ocode = BIT_XOR_EXPR;
4657 ocode = BIT_IOR_EXPR;
4660 oprec = PREC_LOGAND;
4661 ocode = TRUTH_ANDIF_EXPR;
4665 ocode = TRUTH_ORIF_EXPR;
4668 /* Not a binary operator, so end of the binary
4672 c_parser_consume_token (parser);
4673 while (oprec <= stack[sp].prec)
4677 case TRUTH_ANDIF_EXPR:
4679 = default_function_array_conversion (stack[sp].expr);
4680 stack[sp].expr.value = c_objc_common_truthvalue_conversion
4681 (default_conversion (stack[sp].expr.value));
4682 skip_evaluation += stack[sp].expr.value == truthvalue_false_node;
4684 case TRUTH_ORIF_EXPR:
4686 = default_function_array_conversion (stack[sp].expr);
4687 stack[sp].expr.value = c_objc_common_truthvalue_conversion
4688 (default_conversion (stack[sp].expr.value));
4689 skip_evaluation += stack[sp].expr.value == truthvalue_true_node;
4695 stack[sp].expr = c_parser_cast_expression (parser, NULL);
4696 stack[sp].prec = oprec;
4697 stack[sp].op = ocode;
4702 return stack[0].expr;
4706 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
4707 NULL then it is an Objective-C message expression which is the
4708 primary-expression starting the expression as an initializer.
4712 ( type-name ) unary-expression
4715 static struct c_expr
4716 c_parser_cast_expression (c_parser *parser, struct c_expr *after)
4718 gcc_assert (!after || c_dialect_objc ());
4720 return c_parser_postfix_expression_after_primary (parser, *after);
4721 /* If the expression begins with a parenthesized type name, it may
4722 be either a cast or a compound literal; we need to see whether
4723 the next character is '{' to tell the difference. If not, it is
4724 an unary expression. */
4725 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
4726 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
4728 struct c_type_name *type_name;
4731 c_parser_consume_token (parser);
4732 type_name = c_parser_type_name (parser);
4733 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4734 if (type_name == NULL)
4736 ret.value = error_mark_node;
4737 ret.original_code = ERROR_MARK;
4741 /* Save casted types in the function's used types hash table. */
4742 used_types_insert (type_name->specs->type);
4744 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
4745 return c_parser_postfix_expression_after_paren_type (parser,
4747 expr = c_parser_cast_expression (parser, NULL);
4748 expr = default_function_array_conversion (expr);
4749 ret.value = c_cast_expr (type_name, expr.value);
4750 ret.original_code = ERROR_MARK;
4754 return c_parser_unary_expression (parser);
4757 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
4763 unary-operator cast-expression
4764 sizeof unary-expression
4765 sizeof ( type-name )
4767 unary-operator: one of
4773 __alignof__ unary-expression
4774 __alignof__ ( type-name )
4777 unary-operator: one of
4778 __extension__ __real__ __imag__
4780 In addition, the GNU syntax treats ++ and -- as unary operators, so
4781 they may be applied to cast expressions with errors for non-lvalues
4784 static struct c_expr
4785 c_parser_unary_expression (c_parser *parser)
4788 struct c_expr ret, op;
4789 switch (c_parser_peek_token (parser)->type)
4792 c_parser_consume_token (parser);
4793 op = c_parser_cast_expression (parser, NULL);
4794 op = default_function_array_conversion (op);
4795 return parser_build_unary_op (PREINCREMENT_EXPR, op);
4796 case CPP_MINUS_MINUS:
4797 c_parser_consume_token (parser);
4798 op = c_parser_cast_expression (parser, NULL);
4799 op = default_function_array_conversion (op);
4800 return parser_build_unary_op (PREDECREMENT_EXPR, op);
4802 c_parser_consume_token (parser);
4803 return parser_build_unary_op (ADDR_EXPR,
4804 c_parser_cast_expression (parser, NULL));
4806 c_parser_consume_token (parser);
4807 op = c_parser_cast_expression (parser, NULL);
4808 op = default_function_array_conversion (op);
4809 ret.value = build_indirect_ref (op.value, "unary *");
4810 ret.original_code = ERROR_MARK;
4813 if (!c_dialect_objc () && !in_system_header)
4814 warning (OPT_Wtraditional,
4815 "%Htraditional C rejects the unary plus operator",
4816 &c_parser_peek_token (parser)->location);
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 (CONVERT_EXPR, op);
4822 c_parser_consume_token (parser);
4823 op = c_parser_cast_expression (parser, NULL);
4824 op = default_function_array_conversion (op);
4825 return parser_build_unary_op (NEGATE_EXPR, op);
4827 c_parser_consume_token (parser);
4828 op = c_parser_cast_expression (parser, NULL);
4829 op = default_function_array_conversion (op);
4830 return parser_build_unary_op (BIT_NOT_EXPR, op);
4832 c_parser_consume_token (parser);
4833 op = c_parser_cast_expression (parser, NULL);
4834 op = default_function_array_conversion (op);
4835 return parser_build_unary_op (TRUTH_NOT_EXPR, op);
4837 /* Refer to the address of a label as a pointer. */
4838 c_parser_consume_token (parser);
4839 if (c_parser_next_token_is (parser, CPP_NAME))
4841 ret.value = finish_label_address_expr
4842 (c_parser_peek_token (parser)->value);
4843 c_parser_consume_token (parser);
4847 c_parser_error (parser, "expected identifier");
4848 ret.value = error_mark_node;
4850 ret.original_code = ERROR_MARK;
4853 switch (c_parser_peek_token (parser)->keyword)
4856 return c_parser_sizeof_expression (parser);
4858 return c_parser_alignof_expression (parser);
4860 c_parser_consume_token (parser);
4861 ext = disable_extension_diagnostics ();
4862 ret = c_parser_cast_expression (parser, NULL);
4863 restore_extension_diagnostics (ext);
4866 c_parser_consume_token (parser);
4867 op = c_parser_cast_expression (parser, NULL);
4868 op = default_function_array_conversion (op);
4869 return parser_build_unary_op (REALPART_EXPR, op);
4871 c_parser_consume_token (parser);
4872 op = c_parser_cast_expression (parser, NULL);
4873 op = default_function_array_conversion (op);
4874 return parser_build_unary_op (IMAGPART_EXPR, op);
4876 return c_parser_postfix_expression (parser);
4879 return c_parser_postfix_expression (parser);
4883 /* Parse a sizeof expression. */
4885 static struct c_expr
4886 c_parser_sizeof_expression (c_parser *parser)
4889 location_t expr_loc;
4890 gcc_assert (c_parser_next_token_is_keyword (parser, RID_SIZEOF));
4891 c_parser_consume_token (parser);
4894 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
4895 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
4897 /* Either sizeof ( type-name ) or sizeof unary-expression
4898 starting with a compound literal. */
4899 struct c_type_name *type_name;
4900 c_parser_consume_token (parser);
4901 expr_loc = c_parser_peek_token (parser)->location;
4902 type_name = c_parser_type_name (parser);
4903 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4904 if (type_name == NULL)
4909 ret.value = error_mark_node;
4910 ret.original_code = ERROR_MARK;
4913 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
4915 expr = c_parser_postfix_expression_after_paren_type (parser,
4919 /* sizeof ( type-name ). */
4922 if (type_name->declarator->kind == cdk_array
4923 && type_name->declarator->u.array.vla_unspec_p)
4926 error ("%H%<[*]%> not allowed in other than a declaration",
4929 return c_expr_sizeof_type (type_name);
4933 expr_loc = c_parser_peek_token (parser)->location;
4934 expr = c_parser_unary_expression (parser);
4938 if (TREE_CODE (expr.value) == COMPONENT_REF
4939 && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
4940 error ("%H%<sizeof%> applied to a bit-field", &expr_loc);
4941 return c_expr_sizeof_expr (expr);
4945 /* Parse an alignof expression. */
4947 static struct c_expr
4948 c_parser_alignof_expression (c_parser *parser)
4951 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ALIGNOF));
4952 c_parser_consume_token (parser);
4955 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
4956 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
4958 /* Either __alignof__ ( type-name ) or __alignof__
4959 unary-expression starting with a compound literal. */
4960 struct c_type_name *type_name;
4962 c_parser_consume_token (parser);
4963 type_name = c_parser_type_name (parser);
4964 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4965 if (type_name == NULL)
4970 ret.value = error_mark_node;
4971 ret.original_code = ERROR_MARK;
4974 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
4976 expr = c_parser_postfix_expression_after_paren_type (parser,
4980 /* alignof ( type-name ). */
4983 ret.value = c_alignof (groktypename (type_name));
4984 ret.original_code = ERROR_MARK;
4990 expr = c_parser_unary_expression (parser);
4994 ret.value = c_alignof_expr (expr.value);
4995 ret.original_code = ERROR_MARK;
5000 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
5004 postfix-expression [ expression ]
5005 postfix-expression ( argument-expression-list[opt] )
5006 postfix-expression . identifier
5007 postfix-expression -> identifier
5008 postfix-expression ++
5009 postfix-expression --
5010 ( type-name ) { initializer-list }
5011 ( type-name ) { initializer-list , }
5013 argument-expression-list:
5015 argument-expression-list , argument-expression
5027 (treated as a keyword in GNU C)
5030 ( compound-statement )
5031 __builtin_va_arg ( assignment-expression , type-name )
5032 __builtin_offsetof ( type-name , offsetof-member-designator )
5033 __builtin_choose_expr ( assignment-expression ,
5034 assignment-expression ,
5035 assignment-expression )
5036 __builtin_types_compatible_p ( type-name , type-name )
5038 offsetof-member-designator:
5040 offsetof-member-designator . identifier
5041 offsetof-member-designator [ expression ]
5046 [ objc-receiver objc-message-args ]
5047 @selector ( objc-selector-arg )
5048 @protocol ( identifier )
5049 @encode ( type-name )
5053 static struct c_expr
5054 c_parser_postfix_expression (c_parser *parser)
5056 struct c_expr expr, e1, e2, e3;
5057 struct c_type_name *t1, *t2;
5059 switch (c_parser_peek_token (parser)->type)
5066 expr.value = c_parser_peek_token (parser)->value;
5067 expr.original_code = ERROR_MARK;
5068 c_parser_consume_token (parser);
5074 expr.value = c_parser_peek_token (parser)->value;
5075 expr.original_code = STRING_CST;
5076 c_parser_consume_token (parser);
5078 case CPP_OBJC_STRING:
5079 gcc_assert (c_dialect_objc ());
5081 = objc_build_string_object (c_parser_peek_token (parser)->value);
5082 expr.original_code = ERROR_MARK;
5083 c_parser_consume_token (parser);
5086 if (c_parser_peek_token (parser)->id_kind != C_ID_ID)
5088 c_parser_error (parser, "expected expression");
5089 expr.value = error_mark_node;
5090 expr.original_code = ERROR_MARK;
5094 tree id = c_parser_peek_token (parser)->value;
5095 location_t loc = c_parser_peek_token (parser)->location;
5096 c_parser_consume_token (parser);
5097 expr.value = build_external_ref (id,
5098 (c_parser_peek_token (parser)->type
5099 == CPP_OPEN_PAREN), loc);
5100 expr.original_code = ERROR_MARK;
5103 case CPP_OPEN_PAREN:
5104 /* A parenthesized expression, statement expression or compound
5106 if (c_parser_peek_2nd_token (parser)->type == CPP_OPEN_BRACE)
5108 /* A statement expression. */
5110 location_t here = c_parser_peek_token (parser)->location;
5111 c_parser_consume_token (parser);
5112 c_parser_consume_token (parser);
5113 if (cur_stmt_list == NULL)
5115 error ("%Hbraced-group within expression allowed "
5116 "only inside a function", &here);
5117 parser->error = true;
5118 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
5119 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5120 expr.value = error_mark_node;
5121 expr.original_code = ERROR_MARK;
5124 stmt = c_begin_stmt_expr ();
5125 c_parser_compound_statement_nostart (parser);
5126 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5128 pedwarn (OPT_pedantic,
5129 "%HISO C forbids braced-groups within expressions", &here);
5130 expr.value = c_finish_stmt_expr (stmt);
5131 expr.original_code = ERROR_MARK;
5133 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser)))
5135 /* A compound literal. ??? Can we actually get here rather
5136 than going directly to
5137 c_parser_postfix_expression_after_paren_type from
5139 struct c_type_name *type_name;
5140 c_parser_consume_token (parser);
5141 type_name = c_parser_type_name (parser);
5142 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5144 if (type_name == NULL)
5146 expr.value = error_mark_node;
5147 expr.original_code = ERROR_MARK;
5150 expr = c_parser_postfix_expression_after_paren_type (parser,
5155 /* A parenthesized expression. */
5156 c_parser_consume_token (parser);
5157 expr = c_parser_expression (parser);
5158 if (TREE_CODE (expr.value) == MODIFY_EXPR)
5159 TREE_NO_WARNING (expr.value) = 1;
5160 expr.original_code = ERROR_MARK;
5161 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5166 switch (c_parser_peek_token (parser)->keyword)
5168 case RID_FUNCTION_NAME:
5169 case RID_PRETTY_FUNCTION_NAME:
5170 case RID_C99_FUNCTION_NAME:
5171 expr.value = fname_decl (c_parser_peek_token (parser)->keyword,
5172 c_parser_peek_token (parser)->value);
5173 expr.original_code = ERROR_MARK;
5174 c_parser_consume_token (parser);
5177 c_parser_consume_token (parser);
5178 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5180 expr.value = error_mark_node;
5181 expr.original_code = ERROR_MARK;
5184 e1 = c_parser_expr_no_commas (parser, NULL);
5185 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5187 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5188 expr.value = error_mark_node;
5189 expr.original_code = ERROR_MARK;
5192 t1 = c_parser_type_name (parser);
5193 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5197 expr.value = error_mark_node;
5198 expr.original_code = ERROR_MARK;
5202 expr.value = build_va_arg (e1.value, groktypename (t1));
5203 expr.original_code = ERROR_MARK;
5207 c_parser_consume_token (parser);
5208 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5210 expr.value = error_mark_node;
5211 expr.original_code = ERROR_MARK;
5214 t1 = c_parser_type_name (parser);
5217 expr.value = error_mark_node;
5218 expr.original_code = ERROR_MARK;
5221 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5223 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5224 expr.value = error_mark_node;
5225 expr.original_code = ERROR_MARK;
5229 tree type = groktypename (t1);
5231 if (type == error_mark_node)
5232 offsetof_ref = error_mark_node;
5234 offsetof_ref = build1 (INDIRECT_REF, type, null_pointer_node);
5235 /* Parse the second argument to __builtin_offsetof. We
5236 must have one identifier, and beyond that we want to
5237 accept sub structure and sub array references. */
5238 if (c_parser_next_token_is (parser, CPP_NAME))
5240 offsetof_ref = build_component_ref
5241 (offsetof_ref, c_parser_peek_token (parser)->value);
5242 c_parser_consume_token (parser);
5243 while (c_parser_next_token_is (parser, CPP_DOT)
5244 || c_parser_next_token_is (parser,
5247 if (c_parser_next_token_is (parser, CPP_DOT))
5249 c_parser_consume_token (parser);
5250 if (c_parser_next_token_is_not (parser,
5253 c_parser_error (parser, "expected identifier");
5256 offsetof_ref = build_component_ref
5258 c_parser_peek_token (parser)->value);
5259 c_parser_consume_token (parser);
5264 c_parser_consume_token (parser);
5265 idx = c_parser_expression (parser).value;
5266 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
5268 offsetof_ref = build_array_ref (offsetof_ref, idx);
5273 c_parser_error (parser, "expected identifier");
5274 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5276 expr.value = fold_offsetof (offsetof_ref, NULL_TREE);
5277 expr.original_code = ERROR_MARK;
5280 case RID_CHOOSE_EXPR:
5281 c_parser_consume_token (parser);
5282 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5284 expr.value = error_mark_node;
5285 expr.original_code = ERROR_MARK;
5288 loc = c_parser_peek_token (parser)->location;
5289 e1 = c_parser_expr_no_commas (parser, NULL);
5290 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5292 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5293 expr.value = error_mark_node;
5294 expr.original_code = ERROR_MARK;
5297 e2 = c_parser_expr_no_commas (parser, NULL);
5298 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5300 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5301 expr.value = error_mark_node;
5302 expr.original_code = ERROR_MARK;
5305 e3 = c_parser_expr_no_commas (parser, NULL);
5306 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5311 c = fold (e1.value);
5312 if (TREE_CODE (c) != INTEGER_CST)
5313 error ("%Hfirst argument to %<__builtin_choose_expr%> not"
5314 " a constant", &loc);
5315 expr = integer_zerop (c) ? e3 : e2;
5318 case RID_TYPES_COMPATIBLE_P:
5319 c_parser_consume_token (parser);
5320 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5322 expr.value = error_mark_node;
5323 expr.original_code = ERROR_MARK;
5326 t1 = c_parser_type_name (parser);
5329 expr.value = error_mark_node;
5330 expr.original_code = ERROR_MARK;
5333 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5335 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5336 expr.value = error_mark_node;
5337 expr.original_code = ERROR_MARK;
5340 t2 = c_parser_type_name (parser);
5343 expr.value = error_mark_node;
5344 expr.original_code = ERROR_MARK;
5347 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5352 e1 = TYPE_MAIN_VARIANT (groktypename (t1));
5353 e2 = TYPE_MAIN_VARIANT (groktypename (t2));
5355 expr.value = comptypes (e1, e2)
5356 ? build_int_cst (NULL_TREE, 1)
5357 : build_int_cst (NULL_TREE, 0);
5358 expr.original_code = ERROR_MARK;
5361 case RID_AT_SELECTOR:
5362 gcc_assert (c_dialect_objc ());
5363 c_parser_consume_token (parser);
5364 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5366 expr.value = error_mark_node;
5367 expr.original_code = ERROR_MARK;
5371 tree sel = c_parser_objc_selector_arg (parser);
5372 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5374 expr.value = objc_build_selector_expr (sel);
5375 expr.original_code = ERROR_MARK;
5378 case RID_AT_PROTOCOL:
5379 gcc_assert (c_dialect_objc ());
5380 c_parser_consume_token (parser);
5381 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5383 expr.value = error_mark_node;
5384 expr.original_code = ERROR_MARK;
5387 if (c_parser_next_token_is_not (parser, CPP_NAME))
5389 c_parser_error (parser, "expected identifier");
5390 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5391 expr.value = error_mark_node;
5392 expr.original_code = ERROR_MARK;
5396 tree id = c_parser_peek_token (parser)->value;
5397 c_parser_consume_token (parser);
5398 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5400 expr.value = objc_build_protocol_expr (id);
5401 expr.original_code = ERROR_MARK;
5405 /* Extension to support C-structures in the archiver. */
5406 gcc_assert (c_dialect_objc ());
5407 c_parser_consume_token (parser);
5408 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5410 expr.value = error_mark_node;
5411 expr.original_code = ERROR_MARK;
5414 t1 = c_parser_type_name (parser);
5417 expr.value = error_mark_node;
5418 expr.original_code = ERROR_MARK;
5419 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5422 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5425 tree type = groktypename (t1);
5426 expr.value = objc_build_encode_expr (type);
5427 expr.original_code = ERROR_MARK;
5431 c_parser_error (parser, "expected expression");
5432 expr.value = error_mark_node;
5433 expr.original_code = ERROR_MARK;
5437 case CPP_OPEN_SQUARE:
5438 if (c_dialect_objc ())
5440 tree receiver, args;
5441 c_parser_consume_token (parser);
5442 receiver = c_parser_objc_receiver (parser);
5443 args = c_parser_objc_message_args (parser);
5444 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
5446 expr.value = objc_build_message_expr (build_tree_list (receiver,
5448 expr.original_code = ERROR_MARK;
5451 /* Else fall through to report error. */
5453 c_parser_error (parser, "expected expression");
5454 expr.value = error_mark_node;
5455 expr.original_code = ERROR_MARK;
5458 return c_parser_postfix_expression_after_primary (parser, expr);
5461 /* Parse a postfix expression after a parenthesized type name: the
5462 brace-enclosed initializer of a compound literal, possibly followed
5463 by some postfix operators. This is separate because it is not
5464 possible to tell until after the type name whether a cast
5465 expression has a cast or a compound literal, or whether the operand
5466 of sizeof is a parenthesized type name or starts with a compound
5469 static struct c_expr
5470 c_parser_postfix_expression_after_paren_type (c_parser *parser,
5471 struct c_type_name *type_name)
5476 location_t start_loc;
5477 start_init (NULL_TREE, NULL, 0);
5478 type = groktypename (type_name);
5479 start_loc = c_parser_peek_token (parser)->location;
5480 if (type != error_mark_node && C_TYPE_VARIABLE_SIZE (type))
5482 error ("%Hcompound literal has variable size", &start_loc);
5483 type = error_mark_node;
5485 init = c_parser_braced_init (parser, type, false);
5487 maybe_warn_string_init (type, init);
5490 pedwarn (OPT_pedantic, "%HISO C90 forbids compound literals",
5492 expr.value = build_compound_literal (type, init.value);
5493 expr.original_code = ERROR_MARK;
5494 return c_parser_postfix_expression_after_primary (parser, expr);
5497 /* Parse a postfix expression after the initial primary or compound
5498 literal; that is, parse a series of postfix operators. */
5500 static struct c_expr
5501 c_parser_postfix_expression_after_primary (c_parser *parser,
5504 tree ident, idx, exprlist;
5507 switch (c_parser_peek_token (parser)->type)
5509 case CPP_OPEN_SQUARE:
5510 /* Array reference. */
5511 c_parser_consume_token (parser);
5512 idx = c_parser_expression (parser).value;
5513 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
5515 expr.value = build_array_ref (expr.value, idx);
5516 expr.original_code = ERROR_MARK;
5518 case CPP_OPEN_PAREN:
5519 /* Function call. */
5520 c_parser_consume_token (parser);
5521 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
5522 exprlist = NULL_TREE;
5524 exprlist = c_parser_expr_list (parser, true);
5525 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5527 expr.value = build_function_call (expr.value, exprlist);
5528 expr.original_code = ERROR_MARK;
5529 if (warn_disallowed_functions)
5530 warn_if_disallowed_function_p (expr.value);
5533 /* Structure element reference. */
5534 c_parser_consume_token (parser);
5535 expr = default_function_array_conversion (expr);
5536 if (c_parser_next_token_is (parser, CPP_NAME))
5537 ident = c_parser_peek_token (parser)->value;
5540 c_parser_error (parser, "expected identifier");
5541 expr.value = error_mark_node;
5542 expr.original_code = ERROR_MARK;
5545 c_parser_consume_token (parser);
5546 expr.value = build_component_ref (expr.value, ident);
5547 expr.original_code = ERROR_MARK;
5550 /* Structure element reference. */
5551 c_parser_consume_token (parser);
5552 expr = default_function_array_conversion (expr);
5553 if (c_parser_next_token_is (parser, CPP_NAME))
5554 ident = c_parser_peek_token (parser)->value;
5557 c_parser_error (parser, "expected identifier");
5558 expr.value = error_mark_node;
5559 expr.original_code = ERROR_MARK;
5562 c_parser_consume_token (parser);
5563 expr.value = build_component_ref (build_indirect_ref (expr.value,
5565 expr.original_code = ERROR_MARK;
5568 /* Postincrement. */
5569 c_parser_consume_token (parser);
5570 expr = default_function_array_conversion (expr);
5571 expr.value = build_unary_op (POSTINCREMENT_EXPR, expr.value, 0);
5572 expr.original_code = ERROR_MARK;
5574 case CPP_MINUS_MINUS:
5575 /* Postdecrement. */
5576 c_parser_consume_token (parser);
5577 expr = default_function_array_conversion (expr);
5578 expr.value = build_unary_op (POSTDECREMENT_EXPR, expr.value, 0);
5579 expr.original_code = ERROR_MARK;
5587 /* Parse an expression (C90 6.3.17, C99 6.5.17).
5590 assignment-expression
5591 expression , assignment-expression
5594 static struct c_expr
5595 c_parser_expression (c_parser *parser)
5598 expr = c_parser_expr_no_commas (parser, NULL);
5599 while (c_parser_next_token_is (parser, CPP_COMMA))
5602 c_parser_consume_token (parser);
5603 next = c_parser_expr_no_commas (parser, NULL);
5604 next = default_function_array_conversion (next);
5605 expr.value = build_compound_expr (expr.value, next.value);
5606 expr.original_code = COMPOUND_EXPR;
5611 /* Parse an expression and convert functions or arrays to
5614 static struct c_expr
5615 c_parser_expression_conv (c_parser *parser)
5618 expr = c_parser_expression (parser);
5619 expr = default_function_array_conversion (expr);
5623 /* Parse a non-empty list of expressions. If CONVERT_P, convert
5624 functions and arrays to pointers.
5627 assignment-expression
5628 nonempty-expr-list , assignment-expression
5632 c_parser_expr_list (c_parser *parser, bool convert_p)
5636 expr = c_parser_expr_no_commas (parser, NULL);
5638 expr = default_function_array_conversion (expr);
5639 ret = cur = build_tree_list (NULL_TREE, expr.value);
5640 while (c_parser_next_token_is (parser, CPP_COMMA))
5642 c_parser_consume_token (parser);
5643 expr = c_parser_expr_no_commas (parser, NULL);
5645 expr = default_function_array_conversion (expr);
5646 cur = TREE_CHAIN (cur) = build_tree_list (NULL_TREE, expr.value);
5652 /* Parse Objective-C-specific constructs. */
5654 /* Parse an objc-class-definition.
5656 objc-class-definition:
5657 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
5658 objc-class-instance-variables[opt] objc-methodprotolist @end
5659 @implementation identifier objc-superclass[opt]
5660 objc-class-instance-variables[opt]
5661 @interface identifier ( identifier ) objc-protocol-refs[opt]
5662 objc-methodprotolist @end
5663 @implementation identifier ( identifier )
5668 "@interface identifier (" must start "@interface identifier (
5669 identifier ) ...": objc-methodprotolist in the first production may
5670 not start with a parenthesized identifier as a declarator of a data
5671 definition with no declaration specifiers if the objc-superclass,
5672 objc-protocol-refs and objc-class-instance-variables are omitted. */
5675 c_parser_objc_class_definition (c_parser *parser)
5680 if (c_parser_next_token_is_keyword (parser, RID_AT_INTERFACE))
5682 else if (c_parser_next_token_is_keyword (parser, RID_AT_IMPLEMENTATION))
5686 c_parser_consume_token (parser);
5687 if (c_parser_next_token_is_not (parser, CPP_NAME))
5689 c_parser_error (parser, "expected identifier");
5692 id1 = c_parser_peek_token (parser)->value;
5693 c_parser_consume_token (parser);
5694 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
5697 tree proto = NULL_TREE;
5698 c_parser_consume_token (parser);
5699 if (c_parser_next_token_is_not (parser, CPP_NAME))
5701 c_parser_error (parser, "expected identifier");
5702 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5705 id2 = c_parser_peek_token (parser)->value;
5706 c_parser_consume_token (parser);
5707 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5710 objc_start_category_implementation (id1, id2);
5713 if (c_parser_next_token_is (parser, CPP_LESS))
5714 proto = c_parser_objc_protocol_refs (parser);
5715 objc_start_category_interface (id1, id2, proto);
5716 c_parser_objc_methodprotolist (parser);
5717 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
5718 objc_finish_interface ();
5721 if (c_parser_next_token_is (parser, CPP_COLON))
5723 c_parser_consume_token (parser);
5724 if (c_parser_next_token_is_not (parser, CPP_NAME))
5726 c_parser_error (parser, "expected identifier");
5729 superclass = c_parser_peek_token (parser)->value;
5730 c_parser_consume_token (parser);
5733 superclass = NULL_TREE;
5736 tree proto = NULL_TREE;
5737 if (c_parser_next_token_is (parser, CPP_LESS))
5738 proto = c_parser_objc_protocol_refs (parser);
5739 objc_start_class_interface (id1, superclass, proto);
5742 objc_start_class_implementation (id1, superclass);
5743 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
5744 c_parser_objc_class_instance_variables (parser);
5747 objc_continue_interface ();
5748 c_parser_objc_methodprotolist (parser);
5749 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
5750 objc_finish_interface ();
5754 objc_continue_implementation ();
5759 /* Parse objc-class-instance-variables.
5761 objc-class-instance-variables:
5762 { objc-instance-variable-decl-list[opt] }
5764 objc-instance-variable-decl-list:
5765 objc-visibility-spec
5766 objc-instance-variable-decl ;
5768 objc-instance-variable-decl-list objc-visibility-spec
5769 objc-instance-variable-decl-list objc-instance-variable-decl ;
5770 objc-instance-variable-decl-list ;
5772 objc-visibility-spec:
5777 objc-instance-variable-decl:
5782 c_parser_objc_class_instance_variables (c_parser *parser)
5784 gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE));
5785 c_parser_consume_token (parser);
5786 while (c_parser_next_token_is_not (parser, CPP_EOF))
5789 /* Parse any stray semicolon. */
5790 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
5792 pedwarn (OPT_pedantic,
5793 "%Hextra semicolon in struct or union specified",
5794 &c_parser_peek_token (parser)->location);
5795 c_parser_consume_token (parser);
5798 /* Stop if at the end of the instance variables. */
5799 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
5801 c_parser_consume_token (parser);
5804 /* Parse any objc-visibility-spec. */
5805 if (c_parser_next_token_is_keyword (parser, RID_PRIVATE))
5807 c_parser_consume_token (parser);
5808 objc_set_visibility (2);
5811 else if (c_parser_next_token_is_keyword (parser, RID_PROTECTED))
5813 c_parser_consume_token (parser);
5814 objc_set_visibility (0);
5817 else if (c_parser_next_token_is_keyword (parser, RID_PUBLIC))
5819 c_parser_consume_token (parser);
5820 objc_set_visibility (1);
5823 else if (c_parser_next_token_is (parser, CPP_PRAGMA))
5825 c_parser_pragma (parser, pragma_external);
5829 /* Parse some comma-separated declarations. */
5830 decls = c_parser_struct_declaration (parser);
5832 /* Comma-separated instance variables are chained together in
5833 reverse order; add them one by one. */
5834 tree ivar = nreverse (decls);
5835 for (; ivar; ivar = TREE_CHAIN (ivar))
5836 objc_add_instance_variable (copy_node (ivar));
5838 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
5842 /* Parse an objc-class-declaration.
5844 objc-class-declaration:
5845 @class identifier-list ;
5849 c_parser_objc_class_declaration (c_parser *parser)
5851 tree list = NULL_TREE;
5852 gcc_assert (c_parser_next_token_is_keyword (parser, RID_CLASS));
5853 c_parser_consume_token (parser);
5854 /* Any identifiers, including those declared as type names, are OK
5859 if (c_parser_next_token_is_not (parser, CPP_NAME))
5861 c_parser_error (parser, "expected identifier");
5864 id = c_parser_peek_token (parser)->value;
5865 list = chainon (list, build_tree_list (NULL_TREE, id));
5866 c_parser_consume_token (parser);
5867 if (c_parser_next_token_is (parser, CPP_COMMA))
5868 c_parser_consume_token (parser);
5872 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
5873 objc_declare_class (list);
5876 /* Parse an objc-alias-declaration.
5878 objc-alias-declaration:
5879 @compatibility_alias identifier identifier ;
5883 c_parser_objc_alias_declaration (c_parser *parser)
5886 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_ALIAS));
5887 c_parser_consume_token (parser);
5888 if (c_parser_next_token_is_not (parser, CPP_NAME))
5890 c_parser_error (parser, "expected identifier");
5891 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
5894 id1 = c_parser_peek_token (parser)->value;
5895 c_parser_consume_token (parser);
5896 if (c_parser_next_token_is_not (parser, CPP_NAME))
5898 c_parser_error (parser, "expected identifier");
5899 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
5902 id2 = c_parser_peek_token (parser)->value;
5903 c_parser_consume_token (parser);
5904 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
5905 objc_declare_alias (id1, id2);
5908 /* Parse an objc-protocol-definition.
5910 objc-protocol-definition:
5911 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
5912 @protocol identifier-list ;
5914 "@protocol identifier ;" should be resolved as "@protocol
5915 identifier-list ;": objc-methodprotolist may not start with a
5916 semicolon in the first alternative if objc-protocol-refs are
5920 c_parser_objc_protocol_definition (c_parser *parser)
5922 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_PROTOCOL));
5923 c_parser_consume_token (parser);
5924 if (c_parser_next_token_is_not (parser, CPP_NAME))
5926 c_parser_error (parser, "expected identifier");
5929 if (c_parser_peek_2nd_token (parser)->type == CPP_COMMA
5930 || c_parser_peek_2nd_token (parser)->type == CPP_SEMICOLON)
5932 tree list = NULL_TREE;
5933 /* Any identifiers, including those declared as type names, are
5938 if (c_parser_next_token_is_not (parser, CPP_NAME))
5940 c_parser_error (parser, "expected identifier");
5943 id = c_parser_peek_token (parser)->value;
5944 list = chainon (list, build_tree_list (NULL_TREE, id));
5945 c_parser_consume_token (parser);
5946 if (c_parser_next_token_is (parser, CPP_COMMA))
5947 c_parser_consume_token (parser);
5951 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
5952 objc_declare_protocols (list);
5956 tree id = c_parser_peek_token (parser)->value;
5957 tree proto = NULL_TREE;
5958 c_parser_consume_token (parser);
5959 if (c_parser_next_token_is (parser, CPP_LESS))
5960 proto = c_parser_objc_protocol_refs (parser);
5961 parser->objc_pq_context = true;
5962 objc_start_protocol (id, proto);
5963 c_parser_objc_methodprotolist (parser);
5964 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
5965 parser->objc_pq_context = false;
5966 objc_finish_interface ();
5970 /* Parse an objc-method-type.
5977 static enum tree_code
5978 c_parser_objc_method_type (c_parser *parser)
5980 switch (c_parser_peek_token (parser)->type)
5983 c_parser_consume_token (parser);
5986 c_parser_consume_token (parser);
5993 /* Parse an objc-method-definition.
5995 objc-method-definition:
5996 objc-method-type objc-method-decl ;[opt] compound-statement
6000 c_parser_objc_method_definition (c_parser *parser)
6002 enum tree_code type = c_parser_objc_method_type (parser);
6004 objc_set_method_type (type);
6005 parser->objc_pq_context = true;
6006 decl = c_parser_objc_method_decl (parser);
6007 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
6009 c_parser_consume_token (parser);
6010 pedwarn (OPT_pedantic,
6011 "%Hextra semicolon in method definition specified",
6012 &c_parser_peek_token (parser)->location);
6014 if (!c_parser_next_token_is (parser, CPP_OPEN_BRACE))
6016 c_parser_error (parser, "expected %<{%>");
6019 parser->objc_pq_context = false;
6020 objc_start_method_definition (decl);
6021 add_stmt (c_parser_compound_statement (parser));
6022 objc_finish_method_definition (current_function_decl);
6025 /* Parse an objc-methodprotolist.
6027 objc-methodprotolist:
6029 objc-methodprotolist objc-methodproto
6030 objc-methodprotolist declaration
6031 objc-methodprotolist ;
6033 The declaration is a data definition, which may be missing
6034 declaration specifiers under the same rules and diagnostics as
6035 other data definitions outside functions, and the stray semicolon
6036 is diagnosed the same way as a stray semicolon outside a
6040 c_parser_objc_methodprotolist (c_parser *parser)
6044 /* The list is terminated by @end. */
6045 switch (c_parser_peek_token (parser)->type)
6048 pedwarn (OPT_pedantic, "%HISO C does not allow extra %<;%> "
6049 "outside of a function",
6050 &c_parser_peek_token (parser)->location);
6051 c_parser_consume_token (parser);
6055 c_parser_objc_methodproto (parser);
6058 c_parser_pragma (parser, pragma_external);
6063 if (c_parser_next_token_is_keyword (parser, RID_AT_END))
6065 c_parser_declaration_or_fndef (parser, false, true, false, true);
6071 /* Parse an objc-methodproto.
6074 objc-method-type objc-method-decl ;
6078 c_parser_objc_methodproto (c_parser *parser)
6080 enum tree_code type = c_parser_objc_method_type (parser);
6082 objc_set_method_type (type);
6083 /* Remember protocol qualifiers in prototypes. */
6084 parser->objc_pq_context = true;
6085 decl = c_parser_objc_method_decl (parser);
6086 /* Forget protocol qualifiers here. */
6087 parser->objc_pq_context = false;
6088 objc_add_method_declaration (decl);
6089 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
6092 /* Parse an objc-method-decl.
6095 ( objc-type-name ) objc-selector
6097 ( objc-type-name ) objc-keyword-selector objc-optparmlist
6098 objc-keyword-selector objc-optparmlist
6100 objc-keyword-selector:
6102 objc-keyword-selector objc-keyword-decl
6105 objc-selector : ( objc-type-name ) identifier
6106 objc-selector : identifier
6107 : ( objc-type-name ) identifier
6111 objc-optparms objc-optellipsis
6115 objc-opt-parms , parameter-declaration
6123 c_parser_objc_method_decl (c_parser *parser)
6125 tree type = NULL_TREE;
6127 tree parms = NULL_TREE;
6128 bool ellipsis = false;
6130 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
6132 c_parser_consume_token (parser);
6133 type = c_parser_objc_type_name (parser);
6134 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6136 sel = c_parser_objc_selector (parser);
6137 /* If there is no selector, or a colon follows, we have an
6138 objc-keyword-selector. If there is a selector, and a colon does
6139 not follow, that selector ends the objc-method-decl. */
6140 if (!sel || c_parser_next_token_is (parser, CPP_COLON))
6143 tree list = NULL_TREE;
6146 tree atype = NULL_TREE, id, keyworddecl;
6147 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
6149 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
6151 c_parser_consume_token (parser);
6152 atype = c_parser_objc_type_name (parser);
6153 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6156 if (c_parser_next_token_is_not (parser, CPP_NAME))
6158 c_parser_error (parser, "expected identifier");
6159 return error_mark_node;
6161 id = c_parser_peek_token (parser)->value;
6162 c_parser_consume_token (parser);
6163 keyworddecl = objc_build_keyword_decl (tsel, atype, id);
6164 list = chainon (list, keyworddecl);
6165 tsel = c_parser_objc_selector (parser);
6166 if (!tsel && c_parser_next_token_is_not (parser, CPP_COLON))
6169 /* Parse the optional parameter list. Optional Objective-C
6170 method parameters follow the C syntax, and may include '...'
6171 to denote a variable number of arguments. */
6172 parms = make_node (TREE_LIST);
6173 while (c_parser_next_token_is (parser, CPP_COMMA))
6175 struct c_parm *parm;
6176 c_parser_consume_token (parser);
6177 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
6180 c_parser_consume_token (parser);
6183 parm = c_parser_parameter_declaration (parser, NULL_TREE);
6186 parms = chainon (parms,
6187 build_tree_list (NULL_TREE, grokparm (parm)));
6191 return objc_build_method_signature (type, sel, parms, ellipsis);
6194 /* Parse an objc-type-name.
6197 objc-type-qualifiers[opt] type-name
6198 objc-type-qualifiers[opt]
6200 objc-type-qualifiers:
6202 objc-type-qualifiers objc-type-qualifier
6204 objc-type-qualifier: one of
6205 in out inout bycopy byref oneway
6209 c_parser_objc_type_name (c_parser *parser)
6211 tree quals = NULL_TREE;
6212 struct c_type_name *type_name = NULL;
6213 tree type = NULL_TREE;
6216 c_token *token = c_parser_peek_token (parser);
6217 if (token->type == CPP_KEYWORD
6218 && (token->keyword == RID_IN
6219 || token->keyword == RID_OUT
6220 || token->keyword == RID_INOUT
6221 || token->keyword == RID_BYCOPY
6222 || token->keyword == RID_BYREF
6223 || token->keyword == RID_ONEWAY))
6225 quals = chainon (quals, build_tree_list (NULL_TREE, token->value));
6226 c_parser_consume_token (parser);
6231 if (c_parser_next_token_starts_typename (parser))
6232 type_name = c_parser_type_name (parser);
6234 type = groktypename (type_name);
6235 return build_tree_list (quals, type);
6238 /* Parse objc-protocol-refs.
6245 c_parser_objc_protocol_refs (c_parser *parser)
6247 tree list = NULL_TREE;
6248 gcc_assert (c_parser_next_token_is (parser, CPP_LESS));
6249 c_parser_consume_token (parser);
6250 /* Any identifiers, including those declared as type names, are OK
6255 if (c_parser_next_token_is_not (parser, CPP_NAME))
6257 c_parser_error (parser, "expected identifier");
6260 id = c_parser_peek_token (parser)->value;
6261 list = chainon (list, build_tree_list (NULL_TREE, id));
6262 c_parser_consume_token (parser);
6263 if (c_parser_next_token_is (parser, CPP_COMMA))
6264 c_parser_consume_token (parser);
6268 c_parser_require (parser, CPP_GREATER, "expected %<>%>");
6272 /* Parse an objc-try-catch-statement.
6274 objc-try-catch-statement:
6275 @try compound-statement objc-catch-list[opt]
6276 @try compound-statement objc-catch-list[opt] @finally compound-statement
6279 @catch ( parameter-declaration ) compound-statement
6280 objc-catch-list @catch ( parameter-declaration ) compound-statement
6284 c_parser_objc_try_catch_statement (c_parser *parser)
6288 gcc_assert (c_parser_next_token_is_keyword (parser, RID_TRY));
6289 c_parser_consume_token (parser);
6290 loc = c_parser_peek_token (parser)->location;
6291 stmt = c_parser_compound_statement (parser);
6292 objc_begin_try_stmt (loc, stmt);
6293 while (c_parser_next_token_is_keyword (parser, RID_CATCH))
6295 struct c_parm *parm;
6296 c_parser_consume_token (parser);
6297 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6299 parm = c_parser_parameter_declaration (parser, NULL_TREE);
6302 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6305 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6306 objc_begin_catch_clause (grokparm (parm));
6307 if (c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
6308 c_parser_compound_statement_nostart (parser);
6309 objc_finish_catch_clause ();
6311 if (c_parser_next_token_is_keyword (parser, RID_AT_FINALLY))
6315 c_parser_consume_token (parser);
6316 finloc = c_parser_peek_token (parser)->location;
6317 finstmt = c_parser_compound_statement (parser);
6318 objc_build_finally_clause (finloc, finstmt);
6320 objc_finish_try_stmt ();
6323 /* Parse an objc-synchronized-statement.
6325 objc-synchronized-statement:
6326 @synchronized ( expression ) compound-statement
6330 c_parser_objc_synchronized_statement (c_parser *parser)
6334 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_SYNCHRONIZED));
6335 c_parser_consume_token (parser);
6336 loc = c_parser_peek_token (parser)->location;
6337 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6339 expr = c_parser_expression (parser).value;
6340 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6343 expr = error_mark_node;
6344 stmt = c_parser_compound_statement (parser);
6345 objc_build_synchronized (loc, expr, stmt);
6348 /* Parse an objc-selector; return NULL_TREE without an error if the
6349 next token is not an objc-selector.
6354 enum struct union if else while do for switch case default
6355 break continue return goto asm sizeof typeof __alignof
6356 unsigned long const short volatile signed restrict _Complex
6357 in out inout bycopy byref oneway int char float double void _Bool
6359 ??? Why this selection of keywords but not, for example, storage
6360 class specifiers? */
6363 c_parser_objc_selector (c_parser *parser)
6365 c_token *token = c_parser_peek_token (parser);
6366 tree value = token->value;
6367 if (token->type == CPP_NAME)
6369 c_parser_consume_token (parser);
6372 if (token->type != CPP_KEYWORD)
6374 switch (token->keyword)
6415 c_parser_consume_token (parser);
6422 /* Parse an objc-selector-arg.
6426 objc-keywordname-list
6428 objc-keywordname-list:
6430 objc-keywordname-list objc-keywordname
6438 c_parser_objc_selector_arg (c_parser *parser)
6440 tree sel = c_parser_objc_selector (parser);
6441 tree list = NULL_TREE;
6442 if (sel && c_parser_next_token_is_not (parser, CPP_COLON))
6446 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
6448 list = chainon (list, build_tree_list (sel, NULL_TREE));
6449 sel = c_parser_objc_selector (parser);
6450 if (!sel && c_parser_next_token_is_not (parser, CPP_COLON))
6456 /* Parse an objc-receiver.
6465 c_parser_objc_receiver (c_parser *parser)
6467 if (c_parser_peek_token (parser)->type == CPP_NAME
6468 && (c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME
6469 || c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME))
6471 tree id = c_parser_peek_token (parser)->value;
6472 c_parser_consume_token (parser);
6473 return objc_get_class_reference (id);
6475 return c_parser_expression (parser).value;
6478 /* Parse objc-message-args.
6482 objc-keywordarg-list
6484 objc-keywordarg-list:
6486 objc-keywordarg-list objc-keywordarg
6489 objc-selector : objc-keywordexpr
6494 c_parser_objc_message_args (c_parser *parser)
6496 tree sel = c_parser_objc_selector (parser);
6497 tree list = NULL_TREE;
6498 if (sel && c_parser_next_token_is_not (parser, CPP_COLON))
6503 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
6505 keywordexpr = c_parser_objc_keywordexpr (parser);
6506 list = chainon (list, build_tree_list (sel, keywordexpr));
6507 sel = c_parser_objc_selector (parser);
6508 if (!sel && c_parser_next_token_is_not (parser, CPP_COLON))
6514 /* Parse an objc-keywordexpr.
6521 c_parser_objc_keywordexpr (c_parser *parser)
6523 tree list = c_parser_expr_list (parser, true);
6524 if (TREE_CHAIN (list) == NULL_TREE)
6526 /* Just return the expression, remove a level of
6528 return TREE_VALUE (list);
6532 /* We have a comma expression, we will collapse later. */
6538 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
6539 should be considered, statements. ALLOW_STMT is true if we're within
6540 the context of a function and such pragmas are to be allowed. Returns
6541 true if we actually parsed such a pragma. */
6544 c_parser_pragma (c_parser *parser, enum pragma_context context)
6548 id = c_parser_peek_token (parser)->pragma_kind;
6549 gcc_assert (id != PRAGMA_NONE);
6553 case PRAGMA_OMP_BARRIER:
6554 if (context != pragma_compound)
6556 if (context == pragma_stmt)
6557 c_parser_error (parser, "%<#pragma omp barrier%> may only be "
6558 "used in compound statements");
6561 c_parser_omp_barrier (parser);
6564 case PRAGMA_OMP_FLUSH:
6565 if (context != pragma_compound)
6567 if (context == pragma_stmt)
6568 c_parser_error (parser, "%<#pragma omp flush%> may only be "
6569 "used in compound statements");
6572 c_parser_omp_flush (parser);
6575 case PRAGMA_OMP_TASKWAIT:
6576 if (context != pragma_compound)
6578 if (context == pragma_stmt)
6579 c_parser_error (parser, "%<#pragma omp taskwait%> may only be "
6580 "used in compound statements");
6583 c_parser_omp_taskwait (parser);
6586 case PRAGMA_OMP_THREADPRIVATE:
6587 c_parser_omp_threadprivate (parser);
6590 case PRAGMA_OMP_SECTION:
6591 error ("%H%<#pragma omp section%> may only be used in "
6592 "%<#pragma omp sections%> construct",
6593 &c_parser_peek_token (parser)->location);
6594 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
6597 case PRAGMA_GCC_PCH_PREPROCESS:
6598 c_parser_error (parser, "%<#pragma GCC pch_preprocess%> must be first");
6599 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
6603 if (id < PRAGMA_FIRST_EXTERNAL)
6605 if (context == pragma_external)
6608 c_parser_error (parser, "expected declaration specifiers");
6609 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
6612 c_parser_omp_construct (parser);
6618 c_parser_consume_pragma (parser);
6619 c_invoke_pragma_handler (id);
6621 /* Skip to EOL, but suppress any error message. Those will have been
6622 generated by the handler routine through calling error, as opposed
6623 to calling c_parser_error. */
6624 parser->error = true;
6625 c_parser_skip_to_pragma_eol (parser);
6630 /* The interface the pragma parsers have to the lexer. */
6633 pragma_lex (tree *value)
6635 c_token *tok = c_parser_peek_token (the_parser);
6636 enum cpp_ttype ret = tok->type;
6638 *value = tok->value;
6639 if (ret == CPP_PRAGMA_EOL || ret == CPP_EOF)
6643 if (ret == CPP_KEYWORD)
6645 c_parser_consume_token (the_parser);
6652 c_parser_pragma_pch_preprocess (c_parser *parser)
6656 c_parser_consume_pragma (parser);
6657 if (c_parser_next_token_is (parser, CPP_STRING))
6659 name = c_parser_peek_token (parser)->value;
6660 c_parser_consume_token (parser);
6663 c_parser_error (parser, "expected string literal");
6664 c_parser_skip_to_pragma_eol (parser);
6667 c_common_pch_pragma (parse_in, TREE_STRING_POINTER (name));
6670 /* OpenMP 2.5 parsing routines. */
6672 /* Returns name of the next clause.
6673 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
6674 the token is not consumed. Otherwise appropriate pragma_omp_clause is
6675 returned and the token is consumed. */
6677 static pragma_omp_clause
6678 c_parser_omp_clause_name (c_parser *parser)
6680 pragma_omp_clause result = PRAGMA_OMP_CLAUSE_NONE;
6682 if (c_parser_next_token_is_keyword (parser, RID_IF))
6683 result = PRAGMA_OMP_CLAUSE_IF;
6684 else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT))
6685 result = PRAGMA_OMP_CLAUSE_DEFAULT;
6686 else if (c_parser_next_token_is (parser, CPP_NAME))
6688 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
6693 if (!strcmp ("collapse", p))
6694 result = PRAGMA_OMP_CLAUSE_COLLAPSE;
6695 else if (!strcmp ("copyin", p))
6696 result = PRAGMA_OMP_CLAUSE_COPYIN;
6697 else if (!strcmp ("copyprivate", p))
6698 result = PRAGMA_OMP_CLAUSE_COPYPRIVATE;
6701 if (!strcmp ("firstprivate", p))
6702 result = PRAGMA_OMP_CLAUSE_FIRSTPRIVATE;
6705 if (!strcmp ("lastprivate", p))
6706 result = PRAGMA_OMP_CLAUSE_LASTPRIVATE;
6709 if (!strcmp ("nowait", p))
6710 result = PRAGMA_OMP_CLAUSE_NOWAIT;
6711 else if (!strcmp ("num_threads", p))
6712 result = PRAGMA_OMP_CLAUSE_NUM_THREADS;
6715 if (!strcmp ("ordered", p))
6716 result = PRAGMA_OMP_CLAUSE_ORDERED;
6719 if (!strcmp ("private", p))
6720 result = PRAGMA_OMP_CLAUSE_PRIVATE;
6723 if (!strcmp ("reduction", p))
6724 result = PRAGMA_OMP_CLAUSE_REDUCTION;
6727 if (!strcmp ("schedule", p))
6728 result = PRAGMA_OMP_CLAUSE_SCHEDULE;
6729 else if (!strcmp ("shared", p))
6730 result = PRAGMA_OMP_CLAUSE_SHARED;
6733 if (!strcmp ("untied", p))
6734 result = PRAGMA_OMP_CLAUSE_UNTIED;
6739 if (result != PRAGMA_OMP_CLAUSE_NONE)
6740 c_parser_consume_token (parser);
6745 /* Validate that a clause of the given type does not already exist. */
6748 check_no_duplicate_clause (tree clauses, enum omp_clause_code code,
6753 for (c = clauses; c ; c = OMP_CLAUSE_CHAIN (c))
6754 if (OMP_CLAUSE_CODE (c) == code)
6756 error ("too many %qs clauses", name);
6764 variable-list , identifier
6766 If KIND is nonzero, create the appropriate node and install the decl
6767 in OMP_CLAUSE_DECL and add the node to the head of the list.
6769 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
6770 return the list created. */
6773 c_parser_omp_variable_list (c_parser *parser, enum omp_clause_code kind,
6776 if (c_parser_next_token_is_not (parser, CPP_NAME)
6777 || c_parser_peek_token (parser)->id_kind != C_ID_ID)
6778 c_parser_error (parser, "expected identifier");
6780 while (c_parser_next_token_is (parser, CPP_NAME)
6781 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
6783 tree t = lookup_name (c_parser_peek_token (parser)->value);
6786 undeclared_variable (c_parser_peek_token (parser)->value,
6787 c_parser_peek_token (parser)->location);
6788 else if (t == error_mark_node)
6792 tree u = build_omp_clause (kind);
6793 OMP_CLAUSE_DECL (u) = t;
6794 OMP_CLAUSE_CHAIN (u) = list;
6798 list = tree_cons (t, NULL_TREE, list);
6800 c_parser_consume_token (parser);
6802 if (c_parser_next_token_is_not (parser, CPP_COMMA))
6805 c_parser_consume_token (parser);
6811 /* Similarly, but expect leading and trailing parenthesis. This is a very
6812 common case for omp clauses. */
6815 c_parser_omp_var_list_parens (c_parser *parser, enum omp_clause_code kind,
6818 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6820 list = c_parser_omp_variable_list (parser, kind, list);
6821 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6827 collapse ( constant-expression ) */
6830 c_parser_omp_clause_collapse (c_parser *parser, tree list)
6832 tree c, num = error_mark_node;
6836 check_no_duplicate_clause (list, OMP_CLAUSE_COLLAPSE, "collapse");
6838 loc = c_parser_peek_token (parser)->location;
6839 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6841 num = c_parser_expr_no_commas (parser, NULL).value;
6842 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6844 if (num == error_mark_node)
6846 if (!INTEGRAL_TYPE_P (TREE_TYPE (num))
6847 || !host_integerp (num, 0)
6848 || (n = tree_low_cst (num, 0)) <= 0
6851 error ("%Hcollapse argument needs positive constant integer expression",
6855 c = build_omp_clause (OMP_CLAUSE_COLLAPSE);
6856 OMP_CLAUSE_COLLAPSE_EXPR (c) = num;
6857 OMP_CLAUSE_CHAIN (c) = list;
6862 copyin ( variable-list ) */
6865 c_parser_omp_clause_copyin (c_parser *parser, tree list)
6867 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYIN, list);
6871 copyprivate ( variable-list ) */
6874 c_parser_omp_clause_copyprivate (c_parser *parser, tree list)
6876 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYPRIVATE, list);
6880 default ( shared | none ) */
6883 c_parser_omp_clause_default (c_parser *parser, tree list)
6885 enum omp_clause_default_kind kind = OMP_CLAUSE_DEFAULT_UNSPECIFIED;
6888 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6890 if (c_parser_next_token_is (parser, CPP_NAME))
6892 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
6897 if (strcmp ("none", p) != 0)
6899 kind = OMP_CLAUSE_DEFAULT_NONE;
6903 if (strcmp ("shared", p) != 0)
6905 kind = OMP_CLAUSE_DEFAULT_SHARED;
6912 c_parser_consume_token (parser);
6917 c_parser_error (parser, "expected %<none%> or %<shared%>");
6919 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6921 if (kind == OMP_CLAUSE_DEFAULT_UNSPECIFIED)
6924 check_no_duplicate_clause (list, OMP_CLAUSE_DEFAULT, "default");
6925 c = build_omp_clause (OMP_CLAUSE_DEFAULT);
6926 OMP_CLAUSE_CHAIN (c) = list;
6927 OMP_CLAUSE_DEFAULT_KIND (c) = kind;
6933 firstprivate ( variable-list ) */
6936 c_parser_omp_clause_firstprivate (c_parser *parser, tree list)
6938 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_FIRSTPRIVATE, list);
6942 if ( expression ) */
6945 c_parser_omp_clause_if (c_parser *parser, tree list)
6947 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
6949 tree t = c_parser_paren_condition (parser);
6952 check_no_duplicate_clause (list, OMP_CLAUSE_IF, "if");
6954 c = build_omp_clause (OMP_CLAUSE_IF);
6955 OMP_CLAUSE_IF_EXPR (c) = t;
6956 OMP_CLAUSE_CHAIN (c) = list;
6960 c_parser_error (parser, "expected %<(%>");
6966 lastprivate ( variable-list ) */
6969 c_parser_omp_clause_lastprivate (c_parser *parser, tree list)
6971 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_LASTPRIVATE, list);
6978 c_parser_omp_clause_nowait (c_parser *parser ATTRIBUTE_UNUSED, tree list)
6982 check_no_duplicate_clause (list, OMP_CLAUSE_NOWAIT, "nowait");
6984 c = build_omp_clause (OMP_CLAUSE_NOWAIT);
6985 OMP_CLAUSE_CHAIN (c) = list;
6990 num_threads ( expression ) */
6993 c_parser_omp_clause_num_threads (c_parser *parser, tree list)
6995 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6997 location_t expr_loc = c_parser_peek_token (parser)->location;
6998 tree c, t = c_parser_expression (parser).value;
7000 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7002 if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
7004 c_parser_error (parser, "expected integer expression");
7008 /* Attempt to statically determine when the number isn't positive. */
7009 c = fold_build2 (LE_EXPR, boolean_type_node, t,
7010 build_int_cst (TREE_TYPE (t), 0));
7011 if (c == boolean_true_node)
7013 warning (0, "%H%<num_threads%> value must be positive", &expr_loc);
7014 t = integer_one_node;
7017 check_no_duplicate_clause (list, OMP_CLAUSE_NUM_THREADS, "num_threads");
7019 c = build_omp_clause (OMP_CLAUSE_NUM_THREADS);
7020 OMP_CLAUSE_NUM_THREADS_EXPR (c) = t;
7021 OMP_CLAUSE_CHAIN (c) = list;
7032 c_parser_omp_clause_ordered (c_parser *parser ATTRIBUTE_UNUSED, tree list)
7036 check_no_duplicate_clause (list, OMP_CLAUSE_ORDERED, "ordered");
7038 c = build_omp_clause (OMP_CLAUSE_ORDERED);
7039 OMP_CLAUSE_CHAIN (c) = list;
7044 private ( variable-list ) */
7047 c_parser_omp_clause_private (c_parser *parser, tree list)
7049 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_PRIVATE, list);
7053 reduction ( reduction-operator : variable-list )
7056 One of: + * - & ^ | && || */
7059 c_parser_omp_clause_reduction (c_parser *parser, tree list)
7061 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7063 enum tree_code code;
7065 switch (c_parser_peek_token (parser)->type)
7077 code = BIT_AND_EXPR;
7080 code = BIT_XOR_EXPR;
7083 code = BIT_IOR_EXPR;
7086 code = TRUTH_ANDIF_EXPR;
7089 code = TRUTH_ORIF_EXPR;
7092 c_parser_error (parser,
7093 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
7094 "%<^%>, %<|%>, %<&&%>, or %<||%>");
7095 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0);
7098 c_parser_consume_token (parser);
7099 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
7103 nl = c_parser_omp_variable_list (parser, OMP_CLAUSE_REDUCTION, list);
7104 for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
7105 OMP_CLAUSE_REDUCTION_CODE (c) = code;
7109 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7115 schedule ( schedule-kind )
7116 schedule ( schedule-kind , expression )
7119 static | dynamic | guided | runtime | auto
7123 c_parser_omp_clause_schedule (c_parser *parser, tree list)
7127 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7130 c = build_omp_clause (OMP_CLAUSE_SCHEDULE);
7132 if (c_parser_next_token_is (parser, CPP_NAME))
7134 tree kind = c_parser_peek_token (parser)->value;
7135 const char *p = IDENTIFIER_POINTER (kind);
7140 if (strcmp ("dynamic", p) != 0)
7142 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_DYNAMIC;
7146 if (strcmp ("guided", p) != 0)
7148 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_GUIDED;
7152 if (strcmp ("runtime", p) != 0)
7154 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_RUNTIME;
7161 else if (c_parser_next_token_is_keyword (parser, RID_STATIC))
7162 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_STATIC;
7163 else if (c_parser_next_token_is_keyword (parser, RID_AUTO))
7164 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_AUTO;
7168 c_parser_consume_token (parser);
7169 if (c_parser_next_token_is (parser, CPP_COMMA))
7172 c_parser_consume_token (parser);
7174 here = c_parser_peek_token (parser)->location;
7175 t = c_parser_expr_no_commas (parser, NULL).value;
7177 if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_RUNTIME)
7178 error ("%Hschedule %<runtime%> does not take "
7179 "a %<chunk_size%> parameter", &here);
7180 else if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_AUTO)
7181 error ("%Hschedule %<auto%> does not take "
7182 "a %<chunk_size%> parameter", &here);
7183 else if (TREE_CODE (TREE_TYPE (t)) == INTEGER_TYPE)
7184 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c) = t;
7186 c_parser_error (parser, "expected integer expression");
7188 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7191 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7192 "expected %<,%> or %<)%>");
7194 check_no_duplicate_clause (list, OMP_CLAUSE_SCHEDULE, "schedule");
7195 OMP_CLAUSE_CHAIN (c) = list;
7199 c_parser_error (parser, "invalid schedule kind");
7200 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0);
7205 shared ( variable-list ) */
7208 c_parser_omp_clause_shared (c_parser *parser, tree list)
7210 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_SHARED, list);
7217 c_parser_omp_clause_untied (c_parser *parser ATTRIBUTE_UNUSED, tree list)
7221 /* FIXME: Should we allow duplicates? */
7222 check_no_duplicate_clause (list, OMP_CLAUSE_UNTIED, "untied");
7224 c = build_omp_clause (OMP_CLAUSE_UNTIED);
7225 OMP_CLAUSE_CHAIN (c) = list;
7229 /* Parse all OpenMP clauses. The set clauses allowed by the directive
7230 is a bitmask in MASK. Return the list of clauses found; the result
7231 of clause default goes in *pdefault. */
7234 c_parser_omp_all_clauses (c_parser *parser, unsigned int mask,
7237 tree clauses = NULL;
7240 while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
7243 pragma_omp_clause c_kind;
7245 tree prev = clauses;
7247 if (!first && c_parser_next_token_is (parser, CPP_COMMA))
7248 c_parser_consume_token (parser);
7251 here = c_parser_peek_token (parser)->location;
7252 c_kind = c_parser_omp_clause_name (parser);
7256 case PRAGMA_OMP_CLAUSE_COLLAPSE:
7257 clauses = c_parser_omp_clause_collapse (parser, clauses);
7258 c_name = "collapse";
7260 case PRAGMA_OMP_CLAUSE_COPYIN:
7261 clauses = c_parser_omp_clause_copyin (parser, clauses);
7264 case PRAGMA_OMP_CLAUSE_COPYPRIVATE:
7265 clauses = c_parser_omp_clause_copyprivate (parser, clauses);
7266 c_name = "copyprivate";
7268 case PRAGMA_OMP_CLAUSE_DEFAULT:
7269 clauses = c_parser_omp_clause_default (parser, clauses);
7272 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE:
7273 clauses = c_parser_omp_clause_firstprivate (parser, clauses);
7274 c_name = "firstprivate";
7276 case PRAGMA_OMP_CLAUSE_IF:
7277 clauses = c_parser_omp_clause_if (parser, clauses);
7280 case PRAGMA_OMP_CLAUSE_LASTPRIVATE:
7281 clauses = c_parser_omp_clause_lastprivate (parser, clauses);
7282 c_name = "lastprivate";
7284 case PRAGMA_OMP_CLAUSE_NOWAIT:
7285 clauses = c_parser_omp_clause_nowait (parser, clauses);
7288 case PRAGMA_OMP_CLAUSE_NUM_THREADS:
7289 clauses = c_parser_omp_clause_num_threads (parser, clauses);
7290 c_name = "num_threads";
7292 case PRAGMA_OMP_CLAUSE_ORDERED:
7293 clauses = c_parser_omp_clause_ordered (parser, clauses);
7296 case PRAGMA_OMP_CLAUSE_PRIVATE:
7297 clauses = c_parser_omp_clause_private (parser, clauses);
7300 case PRAGMA_OMP_CLAUSE_REDUCTION:
7301 clauses = c_parser_omp_clause_reduction (parser, clauses);
7302 c_name = "reduction";
7304 case PRAGMA_OMP_CLAUSE_SCHEDULE:
7305 clauses = c_parser_omp_clause_schedule (parser, clauses);
7306 c_name = "schedule";
7308 case PRAGMA_OMP_CLAUSE_SHARED:
7309 clauses = c_parser_omp_clause_shared (parser, clauses);
7312 case PRAGMA_OMP_CLAUSE_UNTIED:
7313 clauses = c_parser_omp_clause_untied (parser, clauses);
7317 c_parser_error (parser, "expected %<#pragma omp%> clause");
7321 if (((mask >> c_kind) & 1) == 0 && !parser->error)
7323 /* Remove the invalid clause(s) from the list to avoid
7324 confusing the rest of the compiler. */
7326 error ("%H%qs is not valid for %qs", &here, c_name, where);
7331 c_parser_skip_to_pragma_eol (parser);
7333 return c_finish_omp_clauses (clauses);
7340 In practice, we're also interested in adding the statement to an
7341 outer node. So it is convenient if we work around the fact that
7342 c_parser_statement calls add_stmt. */
7345 c_parser_omp_structured_block (c_parser *parser)
7347 tree stmt = push_stmt_list ();
7348 c_parser_statement (parser);
7349 return pop_stmt_list (stmt);
7353 # pragma omp atomic new-line
7357 x binop= expr | x++ | ++x | x-- | --x
7359 +, *, -, /, &, ^, |, <<, >>
7361 where x is an lvalue expression with scalar type. */
7364 c_parser_omp_atomic (c_parser *parser)
7368 enum tree_code code;
7369 struct c_expr rhs_expr;
7371 c_parser_skip_to_pragma_eol (parser);
7373 lhs = c_parser_unary_expression (parser).value;
7374 switch (TREE_CODE (lhs))
7378 c_parser_skip_to_end_of_block_or_statement (parser);
7381 case PREINCREMENT_EXPR:
7382 case POSTINCREMENT_EXPR:
7383 lhs = TREE_OPERAND (lhs, 0);
7385 rhs = integer_one_node;
7388 case PREDECREMENT_EXPR:
7389 case POSTDECREMENT_EXPR:
7390 lhs = TREE_OPERAND (lhs, 0);
7392 rhs = integer_one_node;
7396 switch (c_parser_peek_token (parser)->type)
7402 code = TRUNC_DIV_EXPR;
7417 code = BIT_AND_EXPR;
7420 code = BIT_IOR_EXPR;
7423 code = BIT_XOR_EXPR;
7426 c_parser_error (parser,
7427 "invalid operator for %<#pragma omp atomic%>");
7431 c_parser_consume_token (parser);
7432 rhs_expr = c_parser_expression (parser);
7433 rhs_expr = default_function_array_conversion (rhs_expr);
7434 rhs = rhs_expr.value;
7437 stmt = c_finish_omp_atomic (code, lhs, rhs);
7438 if (stmt != error_mark_node)
7440 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7445 # pragma omp barrier new-line
7449 c_parser_omp_barrier (c_parser *parser)
7451 c_parser_consume_pragma (parser);
7452 c_parser_skip_to_pragma_eol (parser);
7454 c_finish_omp_barrier ();
7458 # pragma omp critical [(name)] new-line
7463 c_parser_omp_critical (c_parser *parser)
7465 tree stmt, name = NULL;
7467 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
7469 c_parser_consume_token (parser);
7470 if (c_parser_next_token_is (parser, CPP_NAME))
7472 name = c_parser_peek_token (parser)->value;
7473 c_parser_consume_token (parser);
7474 c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7477 c_parser_error (parser, "expected identifier");
7479 else if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
7480 c_parser_error (parser, "expected %<(%> or end of line");
7481 c_parser_skip_to_pragma_eol (parser);
7483 stmt = c_parser_omp_structured_block (parser);
7484 return c_finish_omp_critical (stmt, name);
7488 # pragma omp flush flush-vars[opt] new-line
7491 ( variable-list ) */
7494 c_parser_omp_flush (c_parser *parser)
7496 c_parser_consume_pragma (parser);
7497 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
7498 c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL);
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 c_finish_omp_flush ();
7506 /* Parse the restricted form of the for statement allowed by OpenMP.
7507 The real trick here is to determine the loop control variable early
7508 so that we can push a new decl if necessary to make it private. */
7511 c_parser_omp_for_loop (c_parser *parser, tree clauses, tree *par_clauses)
7513 tree decl, cond, incr, save_break, save_cont, body, init, stmt, cl;
7514 tree declv, condv, incrv, initv, for_block = NULL, ret = NULL;
7516 bool fail = false, open_brace_parsed = false;
7517 int i, collapse = 1, nbraces = 0;
7519 for (cl = clauses; cl; cl = OMP_CLAUSE_CHAIN (cl))
7520 if (OMP_CLAUSE_CODE (cl) == OMP_CLAUSE_COLLAPSE)
7521 collapse = tree_low_cst (OMP_CLAUSE_COLLAPSE_EXPR (cl), 0);
7523 gcc_assert (collapse >= 1);
7525 declv = make_tree_vec (collapse);
7526 initv = make_tree_vec (collapse);
7527 condv = make_tree_vec (collapse);
7528 incrv = make_tree_vec (collapse);
7530 if (!c_parser_next_token_is_keyword (parser, RID_FOR))
7532 c_parser_error (parser, "for statement expected");
7535 loc = c_parser_peek_token (parser)->location;
7536 c_parser_consume_token (parser);
7538 for (i = 0; i < collapse; i++)
7542 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7545 /* Parse the initialization declaration or expression. */
7546 if (c_parser_next_token_starts_declspecs (parser))
7550 = tree_cons (NULL, c_begin_compound_stmt (true), for_block);
7551 c_parser_declaration_or_fndef (parser, true, true, true, true);
7552 decl = check_for_loop_decls ();
7555 if (DECL_INITIAL (decl) == error_mark_node)
7556 decl = error_mark_node;
7559 else if (c_parser_next_token_is (parser, CPP_NAME)
7560 && c_parser_peek_2nd_token (parser)->type == CPP_EQ)
7562 struct c_expr init_exp;
7564 decl = c_parser_postfix_expression (parser).value;
7566 c_parser_require (parser, CPP_EQ, "expected %<=%>");
7568 init_exp = c_parser_expr_no_commas (parser, NULL);
7569 init_exp = default_function_array_conversion (init_exp);
7570 init = build_modify_expr (decl, NOP_EXPR, init_exp.value);
7571 init = c_process_expr_stmt (init);
7573 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7578 c_parser_error (parser,
7579 "expected iteration declaration or initialization");
7580 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7586 /* Parse the loop condition. */
7588 if (c_parser_next_token_is_not (parser, CPP_SEMICOLON))
7590 cond = c_parser_expression_conv (parser).value;
7591 cond = c_objc_common_truthvalue_conversion (cond);
7592 if (CAN_HAVE_LOCATION_P (cond))
7593 SET_EXPR_LOCATION (cond, input_location);
7595 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7597 /* Parse the increment expression. */
7599 if (c_parser_next_token_is_not (parser, CPP_CLOSE_PAREN))
7600 incr = c_process_expr_stmt (c_parser_expression (parser).value);
7601 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7603 if (decl == NULL || decl == error_mark_node || init == error_mark_node)
7607 TREE_VEC_ELT (declv, i) = decl;
7608 TREE_VEC_ELT (initv, i) = init;
7609 TREE_VEC_ELT (condv, i) = cond;
7610 TREE_VEC_ELT (incrv, i) = incr;
7614 if (i == collapse - 1)
7617 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
7618 in between the collapsed for loops to be still considered perfectly
7619 nested. Hopefully the final version clarifies this.
7620 For now handle (multiple) {'s and empty statements. */
7623 if (c_parser_next_token_is_keyword (parser, RID_FOR))
7625 c_parser_consume_token (parser);
7628 else if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
7630 c_parser_consume_token (parser);
7634 && c_parser_next_token_is (parser, CPP_SEMICOLON))
7635 c_parser_consume_token (parser);
7638 c_parser_error (parser, "not enough perfectly nested loops");
7641 open_brace_parsed = true;
7651 nbraces += bracecount;
7654 save_break = c_break_label;
7655 c_break_label = size_one_node;
7656 save_cont = c_cont_label;
7657 c_cont_label = NULL_TREE;
7658 body = push_stmt_list ();
7660 if (open_brace_parsed)
7662 stmt = c_begin_compound_stmt (true);
7663 c_parser_compound_statement_nostart (parser);
7664 add_stmt (c_end_compound_stmt (stmt, true));
7667 add_stmt (c_parser_c99_block_statement (parser));
7669 add_stmt (build1 (LABEL_EXPR, void_type_node, c_cont_label));
7671 body = pop_stmt_list (body);
7672 c_break_label = save_break;
7673 c_cont_label = save_cont;
7677 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
7679 c_parser_consume_token (parser);
7682 else if (c_parser_next_token_is (parser, CPP_SEMICOLON))
7683 c_parser_consume_token (parser);
7686 c_parser_error (parser, "collapsed loops not perfectly nested");
7689 stmt = c_begin_compound_stmt (true);
7691 c_parser_compound_statement_nostart (parser);
7692 body = c_end_compound_stmt (stmt, true);
7699 /* Only bother calling c_finish_omp_for if we haven't already generated
7700 an error from the initialization parsing. */
7703 stmt = c_finish_omp_for (loc, declv, initv, condv, incrv, body, NULL);
7706 if (par_clauses != NULL)
7709 for (c = par_clauses; *c ; )
7710 if (OMP_CLAUSE_CODE (*c) != OMP_CLAUSE_FIRSTPRIVATE
7711 && OMP_CLAUSE_CODE (*c) != OMP_CLAUSE_LASTPRIVATE)
7712 c = &OMP_CLAUSE_CHAIN (*c);
7715 for (i = 0; i < collapse; i++)
7716 if (TREE_VEC_ELT (declv, i) == OMP_CLAUSE_DECL (*c))
7719 c = &OMP_CLAUSE_CHAIN (*c);
7720 else if (OMP_CLAUSE_CODE (*c) == OMP_CLAUSE_FIRSTPRIVATE)
7722 error ("%Hiteration variable %qD should not be firstprivate",
7723 &loc, OMP_CLAUSE_DECL (*c));
7724 *c = OMP_CLAUSE_CHAIN (*c);
7728 /* Copy lastprivate (decl) clause to OMP_FOR_CLAUSES,
7729 change it to shared (decl) in
7730 OMP_PARALLEL_CLAUSES. */
7731 tree l = build_omp_clause (OMP_CLAUSE_LASTPRIVATE);
7732 OMP_CLAUSE_DECL (l) = OMP_CLAUSE_DECL (*c);
7733 OMP_CLAUSE_CHAIN (l) = clauses;
7735 OMP_CLAUSE_SET_CODE (*c, OMP_CLAUSE_SHARED);
7739 OMP_FOR_CLAUSES (stmt) = clauses;
7746 stmt = c_end_compound_stmt (TREE_VALUE (for_block), true);
7748 for_block = TREE_CHAIN (for_block);
7754 #pragma omp for for-clause[optseq] new-line
7758 #define OMP_FOR_CLAUSE_MASK \
7759 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
7760 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
7761 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
7762 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
7763 | (1u << PRAGMA_OMP_CLAUSE_ORDERED) \
7764 | (1u << PRAGMA_OMP_CLAUSE_SCHEDULE) \
7765 | (1u << PRAGMA_OMP_CLAUSE_COLLAPSE) \
7766 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
7769 c_parser_omp_for (c_parser *parser)
7771 tree block, clauses, ret;
7773 clauses = c_parser_omp_all_clauses (parser, OMP_FOR_CLAUSE_MASK,
7776 block = c_begin_compound_stmt (true);
7777 ret = c_parser_omp_for_loop (parser, clauses, NULL);
7778 block = c_end_compound_stmt (block, true);
7785 # pragma omp master new-line
7790 c_parser_omp_master (c_parser *parser)
7792 c_parser_skip_to_pragma_eol (parser);
7793 return c_finish_omp_master (c_parser_omp_structured_block (parser));
7797 # pragma omp ordered new-line
7802 c_parser_omp_ordered (c_parser *parser)
7804 c_parser_skip_to_pragma_eol (parser);
7805 return c_finish_omp_ordered (c_parser_omp_structured_block (parser));
7811 { section-sequence }
7814 section-directive[opt] structured-block
7815 section-sequence section-directive structured-block */
7818 c_parser_omp_sections_scope (c_parser *parser)
7821 bool error_suppress = false;
7824 if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
7826 /* Avoid skipping until the end of the block. */
7827 parser->error = false;
7831 stmt = push_stmt_list ();
7833 loc = c_parser_peek_token (parser)->location;
7834 if (c_parser_peek_token (parser)->pragma_kind != PRAGMA_OMP_SECTION)
7836 substmt = push_stmt_list ();
7840 c_parser_statement (parser);
7842 if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_OMP_SECTION)
7844 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
7846 if (c_parser_next_token_is (parser, CPP_EOF))
7850 substmt = pop_stmt_list (substmt);
7851 substmt = build1 (OMP_SECTION, void_type_node, substmt);
7852 SET_EXPR_LOCATION (substmt, loc);
7858 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
7860 if (c_parser_next_token_is (parser, CPP_EOF))
7863 loc = c_parser_peek_token (parser)->location;
7864 if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_OMP_SECTION)
7866 c_parser_consume_pragma (parser);
7867 c_parser_skip_to_pragma_eol (parser);
7868 error_suppress = false;
7870 else if (!error_suppress)
7872 error ("%Hexpected %<#pragma omp section%> or %<}%>",
7874 error_suppress = true;
7877 substmt = c_parser_omp_structured_block (parser);
7878 substmt = build1 (OMP_SECTION, void_type_node, substmt);
7879 SET_EXPR_LOCATION (substmt, loc);
7882 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE,
7883 "expected %<#pragma omp section%> or %<}%>");
7885 substmt = pop_stmt_list (stmt);
7887 stmt = make_node (OMP_SECTIONS);
7888 TREE_TYPE (stmt) = void_type_node;
7889 OMP_SECTIONS_BODY (stmt) = substmt;
7891 return add_stmt (stmt);
7895 # pragma omp sections sections-clause[optseq] newline
7899 #define OMP_SECTIONS_CLAUSE_MASK \
7900 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
7901 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
7902 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
7903 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
7904 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
7907 c_parser_omp_sections (c_parser *parser)
7909 tree block, clauses, ret;
7911 clauses = c_parser_omp_all_clauses (parser, OMP_SECTIONS_CLAUSE_MASK,
7912 "#pragma omp sections");
7914 block = c_begin_compound_stmt (true);
7915 ret = c_parser_omp_sections_scope (parser);
7917 OMP_SECTIONS_CLAUSES (ret) = clauses;
7918 block = c_end_compound_stmt (block, true);
7925 # pragma parallel parallel-clause new-line
7926 # pragma parallel for parallel-for-clause new-line
7927 # pragma parallel sections parallel-sections-clause new-line
7930 #define OMP_PARALLEL_CLAUSE_MASK \
7931 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
7932 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
7933 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
7934 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
7935 | (1u << PRAGMA_OMP_CLAUSE_SHARED) \
7936 | (1u << PRAGMA_OMP_CLAUSE_COPYIN) \
7937 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
7938 | (1u << PRAGMA_OMP_CLAUSE_NUM_THREADS))
7941 c_parser_omp_parallel (c_parser *parser)
7943 enum pragma_kind p_kind = PRAGMA_OMP_PARALLEL;
7944 const char *p_name = "#pragma omp parallel";
7945 tree stmt, clauses, par_clause, ws_clause, block;
7946 unsigned int mask = OMP_PARALLEL_CLAUSE_MASK;
7948 if (c_parser_next_token_is_keyword (parser, RID_FOR))
7950 c_parser_consume_token (parser);
7951 p_kind = PRAGMA_OMP_PARALLEL_FOR;
7952 p_name = "#pragma omp parallel for";
7953 mask |= OMP_FOR_CLAUSE_MASK;
7954 mask &= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT);
7956 else if (c_parser_next_token_is (parser, CPP_NAME))
7958 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
7959 if (strcmp (p, "sections") == 0)
7961 c_parser_consume_token (parser);
7962 p_kind = PRAGMA_OMP_PARALLEL_SECTIONS;
7963 p_name = "#pragma omp parallel sections";
7964 mask |= OMP_SECTIONS_CLAUSE_MASK;
7965 mask &= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT);
7969 clauses = c_parser_omp_all_clauses (parser, mask, p_name);
7973 case PRAGMA_OMP_PARALLEL:
7974 block = c_begin_omp_parallel ();
7975 c_parser_statement (parser);
7976 stmt = c_finish_omp_parallel (clauses, block);
7979 case PRAGMA_OMP_PARALLEL_FOR:
7980 block = c_begin_omp_parallel ();
7981 c_split_parallel_clauses (clauses, &par_clause, &ws_clause);
7982 c_parser_omp_for_loop (parser, ws_clause, &par_clause);
7983 stmt = c_finish_omp_parallel (par_clause, block);
7984 OMP_PARALLEL_COMBINED (stmt) = 1;
7987 case PRAGMA_OMP_PARALLEL_SECTIONS:
7988 block = c_begin_omp_parallel ();
7989 c_split_parallel_clauses (clauses, &par_clause, &ws_clause);
7990 stmt = c_parser_omp_sections_scope (parser);
7992 OMP_SECTIONS_CLAUSES (stmt) = ws_clause;
7993 stmt = c_finish_omp_parallel (par_clause, block);
7994 OMP_PARALLEL_COMBINED (stmt) = 1;
8005 # pragma omp single single-clause[optseq] new-line
8009 #define OMP_SINGLE_CLAUSE_MASK \
8010 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8011 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8012 | (1u << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
8013 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
8016 c_parser_omp_single (c_parser *parser)
8018 tree stmt = make_node (OMP_SINGLE);
8019 TREE_TYPE (stmt) = void_type_node;
8021 OMP_SINGLE_CLAUSES (stmt)
8022 = c_parser_omp_all_clauses (parser, OMP_SINGLE_CLAUSE_MASK,
8023 "#pragma omp single");
8024 OMP_SINGLE_BODY (stmt) = c_parser_omp_structured_block (parser);
8026 return add_stmt (stmt);
8030 # pragma omp task task-clause[optseq] new-line
8033 #define OMP_TASK_CLAUSE_MASK \
8034 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
8035 | (1u << PRAGMA_OMP_CLAUSE_UNTIED) \
8036 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
8037 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8038 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8039 | (1u << PRAGMA_OMP_CLAUSE_SHARED))
8042 c_parser_omp_task (c_parser *parser)
8044 tree clauses, block;
8046 clauses = c_parser_omp_all_clauses (parser, OMP_TASK_CLAUSE_MASK,
8047 "#pragma omp task");
8049 block = c_begin_omp_task ();
8050 c_parser_statement (parser);
8051 return c_finish_omp_task (clauses, block);
8055 # pragma omp taskwait new-line
8059 c_parser_omp_taskwait (c_parser *parser)
8061 c_parser_consume_pragma (parser);
8062 c_parser_skip_to_pragma_eol (parser);
8064 c_finish_omp_taskwait ();
8067 /* Main entry point to parsing most OpenMP pragmas. */
8070 c_parser_omp_construct (c_parser *parser)
8072 enum pragma_kind p_kind;
8076 loc = c_parser_peek_token (parser)->location;
8077 p_kind = c_parser_peek_token (parser)->pragma_kind;
8078 c_parser_consume_pragma (parser);
8080 /* For all constructs below except #pragma omp atomic
8081 MUST_NOT_THROW catch handlers are needed when exceptions
8083 if (p_kind != PRAGMA_OMP_ATOMIC)
8084 c_maybe_initialize_eh ();
8088 case PRAGMA_OMP_ATOMIC:
8089 c_parser_omp_atomic (parser);
8091 case PRAGMA_OMP_CRITICAL:
8092 stmt = c_parser_omp_critical (parser);
8094 case PRAGMA_OMP_FOR:
8095 stmt = c_parser_omp_for (parser);
8097 case PRAGMA_OMP_MASTER:
8098 stmt = c_parser_omp_master (parser);
8100 case PRAGMA_OMP_ORDERED:
8101 stmt = c_parser_omp_ordered (parser);
8103 case PRAGMA_OMP_PARALLEL:
8104 stmt = c_parser_omp_parallel (parser);
8106 case PRAGMA_OMP_SECTIONS:
8107 stmt = c_parser_omp_sections (parser);
8109 case PRAGMA_OMP_SINGLE:
8110 stmt = c_parser_omp_single (parser);
8112 case PRAGMA_OMP_TASK:
8113 stmt = c_parser_omp_task (parser);
8120 SET_EXPR_LOCATION (stmt, loc);
8125 # pragma omp threadprivate (variable-list) */
8128 c_parser_omp_threadprivate (c_parser *parser)
8132 c_parser_consume_pragma (parser);
8133 vars = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL);
8135 /* Mark every variable in VARS to be assigned thread local storage. */
8136 for (t = vars; t; t = TREE_CHAIN (t))
8138 tree v = TREE_PURPOSE (t);
8140 /* If V had already been marked threadprivate, it doesn't matter
8141 whether it had been used prior to this point. */
8142 if (TREE_CODE (v) != VAR_DECL)
8143 error ("%qD is not a variable", v);
8144 else if (TREE_USED (v) && !C_DECL_THREADPRIVATE_P (v))
8145 error ("%qE declared %<threadprivate%> after first use", v);
8146 else if (! TREE_STATIC (v) && ! DECL_EXTERNAL (v))
8147 error ("automatic variable %qE cannot be %<threadprivate%>", v);
8148 else if (TREE_TYPE (v) == error_mark_node)
8150 else if (! COMPLETE_TYPE_P (TREE_TYPE (v)))
8151 error ("%<threadprivate%> %qE has incomplete type", v);
8154 if (! DECL_THREAD_LOCAL_P (v))
8156 DECL_TLS_MODEL (v) = decl_default_tls_model (v);
8157 /* If rtl has been already set for this var, call
8158 make_decl_rtl once again, so that encode_section_info
8159 has a chance to look at the new decl flags. */
8160 if (DECL_RTL_SET_P (v))
8163 C_DECL_THREADPRIVATE_P (v) = 1;
8167 c_parser_skip_to_pragma_eol (parser);
8171 /* Parse a single source file. */
8176 /* Use local storage to begin. If the first token is a pragma, parse it.
8177 If it is #pragma GCC pch_preprocess, then this will load a PCH file
8178 which will cause garbage collection. */
8181 memset (&tparser, 0, sizeof tparser);
8182 the_parser = &tparser;
8184 if (c_parser_peek_token (&tparser)->pragma_kind == PRAGMA_GCC_PCH_PREPROCESS)
8185 c_parser_pragma_pch_preprocess (&tparser);
8187 the_parser = GGC_NEW (c_parser);
8188 *the_parser = tparser;
8190 c_parser_translation_unit (the_parser);
8194 #include "gt-c-parser.h"