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 Free Software Foundation, Inc.
5 Parser actions based on the old Bison parser; structure somewhat
6 influenced by and fragments based on the C++ parser.
8 This file is part of GCC.
10 GCC is free software; you can redistribute it and/or modify it under
11 the terms of the GNU General Public License as published by the Free
12 Software Foundation; either version 3, or (at your option) any later
15 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
16 WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 You should have received a copy of the GNU General Public License
21 along with GCC; see the file COPYING3. If not see
22 <http://www.gnu.org/licenses/>. */
26 Make sure all relevant comments, and all relevant code from all
27 actions, brought over from old parser. Verify exact correspondence
30 Add testcases covering every input symbol in every state in old and
33 Include full syntax for GNU C, including erroneous cases accepted
34 with error messages, in syntax productions in comments.
36 Make more diagnostics in the front end generally take an explicit
37 location rather than implicitly using input_location. */
41 #include "coretypes.h"
45 #include "langhooks.h"
61 /* The reserved keyword table. */
65 ENUM_BITFIELD(rid
) rid
: 16;
66 unsigned int disable
: 16;
69 /* Disable mask. Keywords are disabled if (reswords[i].disable &
71 #define D_C89 0x01 /* not in C89 */
72 #define D_EXT 0x02 /* GCC extension */
73 #define D_EXT89 0x04 /* GCC extension incorporated in C99 */
74 #define D_OBJC 0x08 /* Objective C only */
76 static const struct resword reswords
[] =
78 { "_Bool", RID_BOOL
, 0 },
79 { "_Complex", RID_COMPLEX
, 0 },
80 { "_Decimal32", RID_DFLOAT32
, D_EXT
},
81 { "_Decimal64", RID_DFLOAT64
, D_EXT
},
82 { "_Decimal128", RID_DFLOAT128
, D_EXT
},
83 { "_Fract", RID_FRACT
, D_EXT
},
84 { "_Accum", RID_ACCUM
, D_EXT
},
85 { "_Sat", RID_SAT
, D_EXT
},
86 { "__FUNCTION__", RID_FUNCTION_NAME
, 0 },
87 { "__PRETTY_FUNCTION__", RID_PRETTY_FUNCTION_NAME
, 0 },
88 { "__alignof", RID_ALIGNOF
, 0 },
89 { "__alignof__", RID_ALIGNOF
, 0 },
90 { "__asm", RID_ASM
, 0 },
91 { "__asm__", RID_ASM
, 0 },
92 { "__attribute", RID_ATTRIBUTE
, 0 },
93 { "__attribute__", RID_ATTRIBUTE
, 0 },
94 { "__builtin_choose_expr", RID_CHOOSE_EXPR
, 0 },
95 { "__builtin_offsetof", RID_OFFSETOF
, 0 },
96 { "__builtin_types_compatible_p", RID_TYPES_COMPATIBLE_P
, 0 },
97 { "__builtin_va_arg", RID_VA_ARG
, 0 },
98 { "__complex", RID_COMPLEX
, 0 },
99 { "__complex__", RID_COMPLEX
, 0 },
100 { "__const", RID_CONST
, 0 },
101 { "__const__", RID_CONST
, 0 },
102 { "__extension__", RID_EXTENSION
, 0 },
103 { "__func__", RID_C99_FUNCTION_NAME
, 0 },
104 { "__imag", RID_IMAGPART
, 0 },
105 { "__imag__", RID_IMAGPART
, 0 },
106 { "__inline", RID_INLINE
, 0 },
107 { "__inline__", RID_INLINE
, 0 },
108 { "__label__", RID_LABEL
, 0 },
109 { "__real", RID_REALPART
, 0 },
110 { "__real__", RID_REALPART
, 0 },
111 { "__restrict", RID_RESTRICT
, 0 },
112 { "__restrict__", RID_RESTRICT
, 0 },
113 { "__signed", RID_SIGNED
, 0 },
114 { "__signed__", RID_SIGNED
, 0 },
115 { "__thread", RID_THREAD
, 0 },
116 { "__typeof", RID_TYPEOF
, 0 },
117 { "__typeof__", RID_TYPEOF
, 0 },
118 { "__volatile", RID_VOLATILE
, 0 },
119 { "__volatile__", RID_VOLATILE
, 0 },
120 { "asm", RID_ASM
, D_EXT
},
121 { "auto", RID_AUTO
, 0 },
122 { "break", RID_BREAK
, 0 },
123 { "case", RID_CASE
, 0 },
124 { "char", RID_CHAR
, 0 },
125 { "const", RID_CONST
, 0 },
126 { "continue", RID_CONTINUE
, 0 },
127 { "default", RID_DEFAULT
, 0 },
129 { "double", RID_DOUBLE
, 0 },
130 { "else", RID_ELSE
, 0 },
131 { "enum", RID_ENUM
, 0 },
132 { "extern", RID_EXTERN
, 0 },
133 { "float", RID_FLOAT
, 0 },
134 { "for", RID_FOR
, 0 },
135 { "goto", RID_GOTO
, 0 },
137 { "inline", RID_INLINE
, D_EXT89
},
138 { "int", RID_INT
, 0 },
139 { "long", RID_LONG
, 0 },
140 { "register", RID_REGISTER
, 0 },
141 { "restrict", RID_RESTRICT
, D_C89
},
142 { "return", RID_RETURN
, 0 },
143 { "short", RID_SHORT
, 0 },
144 { "signed", RID_SIGNED
, 0 },
145 { "sizeof", RID_SIZEOF
, 0 },
146 { "static", RID_STATIC
, 0 },
147 { "struct", RID_STRUCT
, 0 },
148 { "switch", RID_SWITCH
, 0 },
149 { "typedef", RID_TYPEDEF
, 0 },
150 { "typeof", RID_TYPEOF
, D_EXT
},
151 { "union", RID_UNION
, 0 },
152 { "unsigned", RID_UNSIGNED
, 0 },
153 { "void", RID_VOID
, 0 },
154 { "volatile", RID_VOLATILE
, 0 },
155 { "while", RID_WHILE
, 0 },
156 /* These Objective-C keywords are recognized only immediately after
158 { "class", RID_AT_CLASS
, D_OBJC
},
159 { "compatibility_alias", RID_AT_ALIAS
, D_OBJC
},
160 { "defs", RID_AT_DEFS
, D_OBJC
},
161 { "encode", RID_AT_ENCODE
, D_OBJC
},
162 { "end", RID_AT_END
, D_OBJC
},
163 { "implementation", RID_AT_IMPLEMENTATION
, D_OBJC
},
164 { "interface", RID_AT_INTERFACE
, D_OBJC
},
165 { "private", RID_AT_PRIVATE
, D_OBJC
},
166 { "protected", RID_AT_PROTECTED
, D_OBJC
},
167 { "protocol", RID_AT_PROTOCOL
, D_OBJC
},
168 { "public", RID_AT_PUBLIC
, D_OBJC
},
169 { "selector", RID_AT_SELECTOR
, D_OBJC
},
170 { "throw", RID_AT_THROW
, D_OBJC
},
171 { "try", RID_AT_TRY
, D_OBJC
},
172 { "catch", RID_AT_CATCH
, D_OBJC
},
173 { "finally", RID_AT_FINALLY
, D_OBJC
},
174 { "synchronized", RID_AT_SYNCHRONIZED
, D_OBJC
},
175 /* These are recognized only in protocol-qualifier context
177 { "bycopy", RID_BYCOPY
, D_OBJC
},
178 { "byref", RID_BYREF
, D_OBJC
},
179 { "in", RID_IN
, D_OBJC
},
180 { "inout", RID_INOUT
, D_OBJC
},
181 { "oneway", RID_ONEWAY
, D_OBJC
},
182 { "out", RID_OUT
, D_OBJC
},
184 #define N_reswords (sizeof reswords / sizeof (struct resword))
186 /* Initialization routine for this file. */
191 /* The only initialization required is of the reserved word
195 int mask
= (flag_isoc99
? 0 : D_C89
)
196 | (flag_no_asm
? (flag_isoc99
? D_EXT
: D_EXT
|D_EXT89
) : 0);
198 if (!c_dialect_objc ())
201 ridpointers
= GGC_CNEWVEC (tree
, (int) RID_MAX
);
202 for (i
= 0; i
< N_reswords
; i
++)
204 /* If a keyword is disabled, do not enter it into the table
205 and so create a canonical spelling that isn't a keyword. */
206 if (reswords
[i
].disable
& mask
)
209 id
= get_identifier (reswords
[i
].word
);
210 C_RID_CODE (id
) = reswords
[i
].rid
;
211 C_IS_RESERVED_WORD (id
) = 1;
212 ridpointers
[(int) reswords
[i
].rid
] = id
;
216 /* The C lexer intermediates between the lexer in cpplib and c-lex.c
217 and the C parser. Unlike the C++ lexer, the parser structure
218 stores the lexer information instead of using a separate structure.
219 Identifiers are separated into ordinary identifiers, type names,
220 keywords and some other Objective-C types of identifiers, and some
221 look-ahead is maintained.
223 ??? It might be a good idea to lex the whole file up front (as for
224 C++). It would then be possible to share more of the C and C++
225 lexer code, if desired. */
227 /* The following local token type is used. */
230 #define CPP_KEYWORD ((enum cpp_ttype) (N_TTYPES + 1))
232 /* More information about the type of a CPP_NAME token. */
233 typedef enum c_id_kind
{
234 /* An ordinary identifier. */
236 /* An identifier declared as a typedef name. */
238 /* An identifier declared as an Objective-C class name. */
240 /* Not an identifier. */
244 /* A single C token after string literal concatenation and conversion
245 of preprocessing tokens to tokens. */
246 typedef struct c_token
GTY (())
248 /* The kind of token. */
249 ENUM_BITFIELD (cpp_ttype
) type
: 8;
250 /* If this token is a CPP_NAME, this value indicates whether also
251 declared as some kind of type. Otherwise, it is C_ID_NONE. */
252 ENUM_BITFIELD (c_id_kind
) id_kind
: 8;
253 /* If this token is a keyword, this value indicates which keyword.
254 Otherwise, this value is RID_MAX. */
255 ENUM_BITFIELD (rid
) keyword
: 8;
256 /* If this token is a CPP_PRAGMA, this indicates the pragma that
257 was seen. Otherwise it is PRAGMA_NONE. */
258 ENUM_BITFIELD (pragma_kind
) pragma_kind
: 7;
259 /* True if this token is from a system header. */
260 BOOL_BITFIELD in_system_header
: 1;
261 /* The value associated with this token, if any. */
263 /* The location at which this token was found. */
267 /* A parser structure recording information about the state and
268 context of parsing. Includes lexer information with up to two
269 tokens of look-ahead; more are not needed for C. */
270 typedef struct c_parser
GTY(())
272 /* The look-ahead tokens. */
274 /* How many look-ahead tokens are available (0, 1 or 2). */
276 /* True if a syntax error is being recovered from; false otherwise.
277 c_parser_error sets this flag. It should clear this flag when
278 enough tokens have been consumed to recover from the error. */
279 BOOL_BITFIELD error
: 1;
280 /* True if we're processing a pragma, and shouldn't automatically
281 consume CPP_PRAGMA_EOL. */
282 BOOL_BITFIELD in_pragma
: 1;
283 /* True if we want to lex an untranslated string. */
284 BOOL_BITFIELD lex_untranslated_string
: 1;
285 /* Objective-C specific parser/lexer information. */
286 BOOL_BITFIELD objc_pq_context
: 1;
287 /* The following flag is needed to contextualize Objective-C lexical
288 analysis. In some cases (e.g., 'int NSObject;'), it is
289 undesirable to bind an identifier to an Objective-C class, even
290 if a class with that name exists. */
291 BOOL_BITFIELD objc_need_raw_identifier
: 1;
295 /* The actual parser and external interface. ??? Does this need to be
296 garbage-collected? */
298 static GTY (()) c_parser
*the_parser
;
301 /* Read in and lex a single token, storing it in *TOKEN. */
304 c_lex_one_token (c_parser
*parser
, c_token
*token
)
306 timevar_push (TV_LEX
);
308 token
->type
= c_lex_with_flags (&token
->value
, &token
->location
, NULL
,
309 (parser
->lex_untranslated_string
310 ? C_LEX_STRING_NO_TRANSLATE
: 0));
311 token
->id_kind
= C_ID_NONE
;
312 token
->keyword
= RID_MAX
;
313 token
->pragma_kind
= PRAGMA_NONE
;
314 token
->in_system_header
= in_system_header
;
322 bool objc_force_identifier
= parser
->objc_need_raw_identifier
;
323 if (c_dialect_objc ())
324 parser
->objc_need_raw_identifier
= false;
326 if (C_IS_RESERVED_WORD (token
->value
))
328 enum rid rid_code
= C_RID_CODE (token
->value
);
330 if (c_dialect_objc ())
332 if (!OBJC_IS_AT_KEYWORD (rid_code
)
333 && (!OBJC_IS_PQ_KEYWORD (rid_code
)
334 || parser
->objc_pq_context
))
336 /* Return the canonical spelling for this keyword. */
337 token
->value
= ridpointers
[(int) rid_code
];
338 token
->type
= CPP_KEYWORD
;
339 token
->keyword
= rid_code
;
345 /* Return the canonical spelling for this keyword. */
346 token
->value
= ridpointers
[(int) rid_code
];
347 token
->type
= CPP_KEYWORD
;
348 token
->keyword
= rid_code
;
353 decl
= lookup_name (token
->value
);
356 if (TREE_CODE (decl
) == TYPE_DECL
)
358 token
->id_kind
= C_ID_TYPENAME
;
362 else if (c_dialect_objc ())
364 tree objc_interface_decl
= objc_is_class_name (token
->value
);
365 /* Objective-C class names are in the same namespace as
366 variables and typedefs, and hence are shadowed by local
368 if (objc_interface_decl
369 && (global_bindings_p ()
370 || (!objc_force_identifier
&& !decl
)))
372 token
->value
= objc_interface_decl
;
373 token
->id_kind
= C_ID_CLASSNAME
;
377 token
->id_kind
= C_ID_ID
;
381 /* This only happens in Objective-C; it must be a keyword. */
382 token
->type
= CPP_KEYWORD
;
383 token
->keyword
= C_RID_CODE (token
->value
);
387 case CPP_CLOSE_PAREN
:
389 /* These tokens may affect the interpretation of any identifiers
390 following, if doing Objective-C. */
391 if (c_dialect_objc ())
392 parser
->objc_need_raw_identifier
= false;
395 /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */
396 token
->pragma_kind
= TREE_INT_CST_LOW (token
->value
);
402 timevar_pop (TV_LEX
);
405 /* Return a pointer to the next token from PARSER, reading it in if
408 static inline c_token
*
409 c_parser_peek_token (c_parser
*parser
)
411 if (parser
->tokens_avail
== 0)
413 c_lex_one_token (parser
, &parser
->tokens
[0]);
414 parser
->tokens_avail
= 1;
416 return &parser
->tokens
[0];
419 /* Return true if the next token from PARSER has the indicated
423 c_parser_next_token_is (c_parser
*parser
, enum cpp_ttype type
)
425 return c_parser_peek_token (parser
)->type
== type
;
428 /* Return true if the next token from PARSER does not have the
432 c_parser_next_token_is_not (c_parser
*parser
, enum cpp_ttype type
)
434 return !c_parser_next_token_is (parser
, type
);
437 /* Return true if the next token from PARSER is the indicated
441 c_parser_next_token_is_keyword (c_parser
*parser
, enum rid keyword
)
445 /* Peek at the next token. */
446 token
= c_parser_peek_token (parser
);
447 /* Check to see if it is the indicated keyword. */
448 return token
->keyword
== keyword
;
451 /* Return true if TOKEN can start a type name,
454 c_token_starts_typename (c_token
*token
)
459 switch (token
->id_kind
)
466 gcc_assert (c_dialect_objc ());
472 switch (token
->keyword
)
504 if (c_dialect_objc ())
512 /* Return true if the next token from PARSER can start a type name,
515 c_parser_next_token_starts_typename (c_parser
*parser
)
517 c_token
*token
= c_parser_peek_token (parser
);
518 return c_token_starts_typename (token
);
521 /* Return true if TOKEN can start declaration specifiers, false
524 c_token_starts_declspecs (c_token
*token
)
529 switch (token
->id_kind
)
536 gcc_assert (c_dialect_objc ());
542 switch (token
->keyword
)
581 if (c_dialect_objc ())
589 /* Return true if the next token from PARSER can start declaration
590 specifiers, false otherwise. */
592 c_parser_next_token_starts_declspecs (c_parser
*parser
)
594 c_token
*token
= c_parser_peek_token (parser
);
595 return c_token_starts_declspecs (token
);
598 /* Return a pointer to the next-but-one token from PARSER, reading it
599 in if necessary. The next token is already read in. */
602 c_parser_peek_2nd_token (c_parser
*parser
)
604 if (parser
->tokens_avail
>= 2)
605 return &parser
->tokens
[1];
606 gcc_assert (parser
->tokens_avail
== 1);
607 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
608 gcc_assert (parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
609 c_lex_one_token (parser
, &parser
->tokens
[1]);
610 parser
->tokens_avail
= 2;
611 return &parser
->tokens
[1];
614 /* Consume the next token from PARSER. */
617 c_parser_consume_token (c_parser
*parser
)
619 gcc_assert (parser
->tokens_avail
>= 1);
620 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
621 gcc_assert (!parser
->in_pragma
|| parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
622 gcc_assert (parser
->error
|| parser
->tokens
[0].type
!= CPP_PRAGMA
);
623 if (parser
->tokens_avail
== 2)
624 parser
->tokens
[0] = parser
->tokens
[1];
625 parser
->tokens_avail
--;
628 /* Expect the current token to be a #pragma. Consume it and remember
629 that we've begun parsing a pragma. */
632 c_parser_consume_pragma (c_parser
*parser
)
634 gcc_assert (!parser
->in_pragma
);
635 gcc_assert (parser
->tokens_avail
>= 1);
636 gcc_assert (parser
->tokens
[0].type
== CPP_PRAGMA
);
637 if (parser
->tokens_avail
== 2)
638 parser
->tokens
[0] = parser
->tokens
[1];
639 parser
->tokens_avail
--;
640 parser
->in_pragma
= true;
643 /* Update the globals input_location and in_system_header from
646 c_parser_set_source_position_from_token (c_token
*token
)
648 if (token
->type
!= CPP_EOF
)
650 input_location
= token
->location
;
651 in_system_header
= token
->in_system_header
;
655 /* Issue a diagnostic of the form
656 FILE:LINE: MESSAGE before TOKEN
657 where TOKEN is the next token in the input stream of PARSER.
658 MESSAGE (specified by the caller) is usually of the form "expected
661 Do not issue a diagnostic if still recovering from an error.
663 ??? This is taken from the C++ parser, but building up messages in
664 this way is not i18n-friendly and some other approach should be
668 c_parser_error (c_parser
*parser
, const char *gmsgid
)
670 c_token
*token
= c_parser_peek_token (parser
);
673 parser
->error
= true;
676 /* This diagnostic makes more sense if it is tagged to the line of
677 the token we just peeked at. */
678 c_parser_set_source_position_from_token (token
);
679 c_parse_error (gmsgid
,
680 /* Because c_parse_error does not understand
681 CPP_KEYWORD, keywords are treated like
683 (token
->type
== CPP_KEYWORD
? CPP_NAME
: token
->type
),
687 /* If the next token is of the indicated TYPE, consume it. Otherwise,
688 issue the error MSGID. If MSGID is NULL then a message has already
689 been produced and no message will be produced this time. Returns
690 true if found, false otherwise. */
693 c_parser_require (c_parser
*parser
,
697 if (c_parser_next_token_is (parser
, type
))
699 c_parser_consume_token (parser
);
704 c_parser_error (parser
, msgid
);
709 /* If the next token is the indicated keyword, consume it. Otherwise,
710 issue the error MSGID. Returns true if found, false otherwise. */
713 c_parser_require_keyword (c_parser
*parser
,
717 if (c_parser_next_token_is_keyword (parser
, keyword
))
719 c_parser_consume_token (parser
);
724 c_parser_error (parser
, msgid
);
729 /* Like c_parser_require, except that tokens will be skipped until the
730 desired token is found. An error message is still produced if the
731 next token is not as expected. If MSGID is NULL then a message has
732 already been produced and no message will be produced this
736 c_parser_skip_until_found (c_parser
*parser
,
740 unsigned nesting_depth
= 0;
742 if (c_parser_require (parser
, type
, msgid
))
745 /* Skip tokens until the desired token is found. */
748 /* Peek at the next token. */
749 c_token
*token
= c_parser_peek_token (parser
);
750 /* If we've reached the token we want, consume it and stop. */
751 if (token
->type
== type
&& !nesting_depth
)
753 c_parser_consume_token (parser
);
757 /* If we've run out of tokens, stop. */
758 if (token
->type
== CPP_EOF
)
760 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
762 if (token
->type
== CPP_OPEN_BRACE
763 || token
->type
== CPP_OPEN_PAREN
764 || token
->type
== CPP_OPEN_SQUARE
)
766 else if (token
->type
== CPP_CLOSE_BRACE
767 || token
->type
== CPP_CLOSE_PAREN
768 || token
->type
== CPP_CLOSE_SQUARE
)
770 if (nesting_depth
-- == 0)
773 /* Consume this token. */
774 c_parser_consume_token (parser
);
776 parser
->error
= false;
779 /* Skip tokens until the end of a parameter is found, but do not
780 consume the comma, semicolon or closing delimiter. */
783 c_parser_skip_to_end_of_parameter (c_parser
*parser
)
785 unsigned nesting_depth
= 0;
789 c_token
*token
= c_parser_peek_token (parser
);
790 if ((token
->type
== CPP_COMMA
|| token
->type
== CPP_SEMICOLON
)
793 /* If we've run out of tokens, stop. */
794 if (token
->type
== CPP_EOF
)
796 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
798 if (token
->type
== CPP_OPEN_BRACE
799 || token
->type
== CPP_OPEN_PAREN
800 || token
->type
== CPP_OPEN_SQUARE
)
802 else if (token
->type
== CPP_CLOSE_BRACE
803 || token
->type
== CPP_CLOSE_PAREN
804 || token
->type
== CPP_CLOSE_SQUARE
)
806 if (nesting_depth
-- == 0)
809 /* Consume this token. */
810 c_parser_consume_token (parser
);
812 parser
->error
= false;
815 /* Expect to be at the end of the pragma directive and consume an
816 end of line marker. */
819 c_parser_skip_to_pragma_eol (c_parser
*parser
)
821 gcc_assert (parser
->in_pragma
);
822 parser
->in_pragma
= false;
824 if (!c_parser_require (parser
, CPP_PRAGMA_EOL
, "expected end of line"))
827 c_token
*token
= c_parser_peek_token (parser
);
828 if (token
->type
== CPP_EOF
)
830 if (token
->type
== CPP_PRAGMA_EOL
)
832 c_parser_consume_token (parser
);
835 c_parser_consume_token (parser
);
838 parser
->error
= false;
841 /* Skip tokens until we have consumed an entire block, or until we
842 have consumed a non-nested ';'. */
845 c_parser_skip_to_end_of_block_or_statement (c_parser
*parser
)
847 unsigned nesting_depth
= 0;
848 bool save_error
= parser
->error
;
854 /* Peek at the next token. */
855 token
= c_parser_peek_token (parser
);
863 if (parser
->in_pragma
)
868 /* If the next token is a ';', we have reached the
869 end of the statement. */
872 /* Consume the ';'. */
873 c_parser_consume_token (parser
);
878 case CPP_CLOSE_BRACE
:
879 /* If the next token is a non-nested '}', then we have
880 reached the end of the current block. */
881 if (nesting_depth
== 0 || --nesting_depth
== 0)
883 c_parser_consume_token (parser
);
889 /* If it the next token is a '{', then we are entering a new
890 block. Consume the entire block. */
895 /* If we see a pragma, consume the whole thing at once. We
896 have some safeguards against consuming pragmas willy-nilly.
897 Normally, we'd expect to be here with parser->error set,
898 which disables these safeguards. But it's possible to get
899 here for secondary error recovery, after parser->error has
901 c_parser_consume_pragma (parser
);
902 c_parser_skip_to_pragma_eol (parser
);
903 parser
->error
= save_error
;
910 c_parser_consume_token (parser
);
914 parser
->error
= false;
917 /* Save the warning flags which are controlled by __extension__. */
920 disable_extension_diagnostics (void)
923 | (warn_pointer_arith
<< 1)
924 | (warn_traditional
<< 2)
927 warn_pointer_arith
= 0;
928 warn_traditional
= 0;
933 /* Restore the warning flags which are controlled by __extension__.
934 FLAGS is the return value from disable_extension_diagnostics. */
937 restore_extension_diagnostics (int flags
)
939 pedantic
= flags
& 1;
940 warn_pointer_arith
= (flags
>> 1) & 1;
941 warn_traditional
= (flags
>> 2) & 1;
942 flag_iso
= (flags
>> 3) & 1;
945 /* Possibly kinds of declarator to parse. */
946 typedef enum c_dtr_syn
{
947 /* A normal declarator with an identifier. */
949 /* An abstract declarator (maybe empty). */
951 /* A parameter declarator: may be either, but after a type name does
952 not redeclare a typedef name as an identifier if it can
953 alternatively be interpreted as a typedef name; see DR#009,
954 applied in C90 TC1, omitted from C99 and reapplied in C99 TC2
955 following DR#249. For example, given a typedef T, "int T" and
956 "int *T" are valid parameter declarations redeclaring T, while
957 "int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are
958 abstract declarators rather than involving redundant parentheses;
959 the same applies with attributes inside the parentheses before
964 static void c_parser_external_declaration (c_parser
*);
965 static void c_parser_asm_definition (c_parser
*);
966 static void c_parser_declaration_or_fndef (c_parser
*, bool, bool, bool, bool);
967 static void c_parser_declspecs (c_parser
*, struct c_declspecs
*, bool, bool,
969 static struct c_typespec
c_parser_enum_specifier (c_parser
*);
970 static struct c_typespec
c_parser_struct_or_union_specifier (c_parser
*);
971 static tree
c_parser_struct_declaration (c_parser
*);
972 static struct c_typespec
c_parser_typeof_specifier (c_parser
*);
973 static struct c_declarator
*c_parser_declarator (c_parser
*, bool, c_dtr_syn
,
975 static struct c_declarator
*c_parser_direct_declarator (c_parser
*, bool,
977 static struct c_declarator
*c_parser_direct_declarator_inner (c_parser
*,
979 struct c_declarator
*);
980 static struct c_arg_info
*c_parser_parms_declarator (c_parser
*, bool, tree
);
981 static struct c_arg_info
*c_parser_parms_list_declarator (c_parser
*, tree
);
982 static struct c_parm
*c_parser_parameter_declaration (c_parser
*, tree
);
983 static tree
c_parser_simple_asm_expr (c_parser
*);
984 static tree
c_parser_attributes (c_parser
*);
985 static struct c_type_name
*c_parser_type_name (c_parser
*);
986 static struct c_expr
c_parser_initializer (c_parser
*);
987 static struct c_expr
c_parser_braced_init (c_parser
*, tree
, bool);
988 static void c_parser_initelt (c_parser
*);
989 static void c_parser_initval (c_parser
*, struct c_expr
*);
990 static tree
c_parser_compound_statement (c_parser
*);
991 static void c_parser_compound_statement_nostart (c_parser
*);
992 static void c_parser_label (c_parser
*);
993 static void c_parser_statement (c_parser
*);
994 static void c_parser_statement_after_labels (c_parser
*);
995 static void c_parser_if_statement (c_parser
*);
996 static void c_parser_switch_statement (c_parser
*);
997 static void c_parser_while_statement (c_parser
*);
998 static void c_parser_do_statement (c_parser
*);
999 static void c_parser_for_statement (c_parser
*);
1000 static tree
c_parser_asm_statement (c_parser
*);
1001 static tree
c_parser_asm_operands (c_parser
*, bool);
1002 static tree
c_parser_asm_clobbers (c_parser
*);
1003 static struct c_expr
c_parser_expr_no_commas (c_parser
*, struct c_expr
*);
1004 static struct c_expr
c_parser_conditional_expression (c_parser
*,
1006 static struct c_expr
c_parser_binary_expression (c_parser
*, struct c_expr
*);
1007 static struct c_expr
c_parser_cast_expression (c_parser
*, struct c_expr
*);
1008 static struct c_expr
c_parser_unary_expression (c_parser
*);
1009 static struct c_expr
c_parser_sizeof_expression (c_parser
*);
1010 static struct c_expr
c_parser_alignof_expression (c_parser
*);
1011 static struct c_expr
c_parser_postfix_expression (c_parser
*);
1012 static struct c_expr
c_parser_postfix_expression_after_paren_type (c_parser
*,
1013 struct c_type_name
*);
1014 static struct c_expr
c_parser_postfix_expression_after_primary (c_parser
*,
1016 static struct c_expr
c_parser_expression (c_parser
*);
1017 static struct c_expr
c_parser_expression_conv (c_parser
*);
1018 static tree
c_parser_expr_list (c_parser
*, bool);
1019 static void c_parser_omp_construct (c_parser
*);
1020 static void c_parser_omp_threadprivate (c_parser
*);
1021 static void c_parser_omp_barrier (c_parser
*);
1022 static void c_parser_omp_flush (c_parser
*);
1024 enum pragma_context
{ pragma_external
, pragma_stmt
, pragma_compound
};
1025 static bool c_parser_pragma (c_parser
*, enum pragma_context
);
1027 /* These Objective-C parser functions are only ever called when
1028 compiling Objective-C. */
1029 static void c_parser_objc_class_definition (c_parser
*);
1030 static void c_parser_objc_class_instance_variables (c_parser
*);
1031 static void c_parser_objc_class_declaration (c_parser
*);
1032 static void c_parser_objc_alias_declaration (c_parser
*);
1033 static void c_parser_objc_protocol_definition (c_parser
*);
1034 static enum tree_code
c_parser_objc_method_type (c_parser
*);
1035 static void c_parser_objc_method_definition (c_parser
*);
1036 static void c_parser_objc_methodprotolist (c_parser
*);
1037 static void c_parser_objc_methodproto (c_parser
*);
1038 static tree
c_parser_objc_method_decl (c_parser
*);
1039 static tree
c_parser_objc_type_name (c_parser
*);
1040 static tree
c_parser_objc_protocol_refs (c_parser
*);
1041 static void c_parser_objc_try_catch_statement (c_parser
*);
1042 static void c_parser_objc_synchronized_statement (c_parser
*);
1043 static tree
c_parser_objc_selector (c_parser
*);
1044 static tree
c_parser_objc_selector_arg (c_parser
*);
1045 static tree
c_parser_objc_receiver (c_parser
*);
1046 static tree
c_parser_objc_message_args (c_parser
*);
1047 static tree
c_parser_objc_keywordexpr (c_parser
*);
1049 /* Parse a translation unit (C90 6.7, C99 6.9).
1052 external-declarations
1054 external-declarations:
1055 external-declaration
1056 external-declarations external-declaration
1065 c_parser_translation_unit (c_parser
*parser
)
1067 if (c_parser_next_token_is (parser
, CPP_EOF
))
1070 pedwarn ("%HISO C forbids an empty source file",
1071 &c_parser_peek_token (parser
)->location
);
1075 void *obstack_position
= obstack_alloc (&parser_obstack
, 0);
1079 c_parser_external_declaration (parser
);
1080 obstack_free (&parser_obstack
, obstack_position
);
1082 while (c_parser_next_token_is_not (parser
, CPP_EOF
));
1086 /* Parse an external declaration (C90 6.7, C99 6.9).
1088 external-declaration:
1094 external-declaration:
1097 __extension__ external-declaration
1101 external-declaration:
1102 objc-class-definition
1103 objc-class-declaration
1104 objc-alias-declaration
1105 objc-protocol-definition
1106 objc-method-definition
1111 c_parser_external_declaration (c_parser
*parser
)
1114 switch (c_parser_peek_token (parser
)->type
)
1117 switch (c_parser_peek_token (parser
)->keyword
)
1120 ext
= disable_extension_diagnostics ();
1121 c_parser_consume_token (parser
);
1122 c_parser_external_declaration (parser
);
1123 restore_extension_diagnostics (ext
);
1126 c_parser_asm_definition (parser
);
1128 case RID_AT_INTERFACE
:
1129 case RID_AT_IMPLEMENTATION
:
1130 gcc_assert (c_dialect_objc ());
1131 c_parser_objc_class_definition (parser
);
1134 gcc_assert (c_dialect_objc ());
1135 c_parser_objc_class_declaration (parser
);
1138 gcc_assert (c_dialect_objc ());
1139 c_parser_objc_alias_declaration (parser
);
1141 case RID_AT_PROTOCOL
:
1142 gcc_assert (c_dialect_objc ());
1143 c_parser_objc_protocol_definition (parser
);
1146 gcc_assert (c_dialect_objc ());
1147 c_parser_consume_token (parser
);
1148 objc_finish_implementation ();
1156 pedwarn ("%HISO C does not allow extra %<;%> outside of a function",
1157 &c_parser_peek_token (parser
)->location
);
1158 c_parser_consume_token (parser
);
1161 c_parser_pragma (parser
, pragma_external
);
1165 if (c_dialect_objc ())
1167 c_parser_objc_method_definition (parser
);
1170 /* Else fall through, and yield a syntax error trying to parse
1171 as a declaration or function definition. */
1174 /* A declaration or a function definition. We can only tell
1175 which after parsing the declaration specifiers, if any, and
1176 the first declarator. */
1177 c_parser_declaration_or_fndef (parser
, true, true, false, true);
1183 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1184 6.7, 6.9.1). If FNDEF_OK is true, a function definition is
1185 accepted; otherwise (old-style parameter declarations) only other
1186 declarations are accepted. If NESTED is true, we are inside a
1187 function or parsing old-style parameter declarations; any functions
1188 encountered are nested functions and declaration specifiers are
1189 required; otherwise we are at top level and functions are normal
1190 functions and declaration specifiers may be optional. If EMPTY_OK
1191 is true, empty declarations are OK (subject to all other
1192 constraints); otherwise (old-style parameter declarations) they are
1193 diagnosed. If START_ATTR_OK is true, the declaration specifiers
1194 may start with attributes; otherwise they may not.
1197 declaration-specifiers init-declarator-list[opt] ;
1199 function-definition:
1200 declaration-specifiers[opt] declarator declaration-list[opt]
1205 declaration-list declaration
1207 init-declarator-list:
1209 init-declarator-list , init-declarator
1212 declarator simple-asm-expr[opt] attributes[opt]
1213 declarator simple-asm-expr[opt] attributes[opt] = initializer
1217 nested-function-definition:
1218 declaration-specifiers declarator declaration-list[opt]
1221 The simple-asm-expr and attributes are GNU extensions.
1223 This function does not handle __extension__; that is handled in its
1224 callers. ??? Following the old parser, __extension__ may start
1225 external declarations, declarations in functions and declarations
1226 at the start of "for" loops, but not old-style parameter
1229 C99 requires declaration specifiers in a function definition; the
1230 absence is diagnosed through the diagnosis of implicit int. In GNU
1231 C we also allow but diagnose declarations without declaration
1232 specifiers, but only at top level (elsewhere they conflict with
1238 threadprivate-directive */
1241 c_parser_declaration_or_fndef (c_parser
*parser
, bool fndef_ok
, bool empty_ok
,
1242 bool nested
, bool start_attr_ok
)
1244 struct c_declspecs
*specs
;
1246 tree all_prefix_attrs
;
1247 bool diagnosed_no_specs
= false;
1248 location_t here
= c_parser_peek_token (parser
)->location
;
1250 specs
= build_null_declspecs ();
1251 c_parser_declspecs (parser
, specs
, true, true, start_attr_ok
);
1254 c_parser_skip_to_end_of_block_or_statement (parser
);
1257 if (nested
&& !specs
->declspecs_seen_p
)
1259 c_parser_error (parser
, "expected declaration specifiers");
1260 c_parser_skip_to_end_of_block_or_statement (parser
);
1263 finish_declspecs (specs
);
1264 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1270 shadow_tag_warned (specs
, 1);
1271 pedwarn ("%Hempty declaration", &here
);
1273 c_parser_consume_token (parser
);
1276 pending_xref_error ();
1277 prefix_attrs
= specs
->attrs
;
1278 all_prefix_attrs
= prefix_attrs
;
1279 specs
->attrs
= NULL_TREE
;
1282 struct c_declarator
*declarator
;
1285 /* Declaring either one or more declarators (in which case we
1286 should diagnose if there were no declaration specifiers) or a
1287 function definition (in which case the diagnostic for
1288 implicit int suffices). */
1289 declarator
= c_parser_declarator (parser
, specs
->type_seen_p
,
1290 C_DTR_NORMAL
, &dummy
);
1291 if (declarator
== NULL
)
1293 c_parser_skip_to_end_of_block_or_statement (parser
);
1296 if (c_parser_next_token_is (parser
, CPP_EQ
)
1297 || c_parser_next_token_is (parser
, CPP_COMMA
)
1298 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
1299 || c_parser_next_token_is_keyword (parser
, RID_ASM
)
1300 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1302 tree asm_name
= NULL_TREE
;
1303 tree postfix_attrs
= NULL_TREE
;
1304 if (!diagnosed_no_specs
&& !specs
->declspecs_seen_p
)
1306 diagnosed_no_specs
= true;
1307 pedwarn ("%Hdata definition has no type or storage class",
1310 /* Having seen a data definition, there cannot now be a
1311 function definition. */
1313 if (c_parser_next_token_is_keyword (parser
, RID_ASM
))
1314 asm_name
= c_parser_simple_asm_expr (parser
);
1315 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1316 postfix_attrs
= c_parser_attributes (parser
);
1317 if (c_parser_next_token_is (parser
, CPP_EQ
))
1321 c_parser_consume_token (parser
);
1322 /* The declaration of the variable is in effect while
1323 its initializer is parsed. */
1324 d
= start_decl (declarator
, specs
, true,
1325 chainon (postfix_attrs
, all_prefix_attrs
));
1327 d
= error_mark_node
;
1328 start_init (d
, asm_name
, global_bindings_p ());
1329 init
= c_parser_initializer (parser
);
1331 if (d
!= error_mark_node
)
1333 maybe_warn_string_init (TREE_TYPE (d
), init
);
1334 finish_decl (d
, init
.value
, asm_name
);
1339 tree d
= start_decl (declarator
, specs
, false,
1340 chainon (postfix_attrs
,
1343 finish_decl (d
, NULL_TREE
, asm_name
);
1345 if (c_parser_next_token_is (parser
, CPP_COMMA
))
1347 c_parser_consume_token (parser
);
1348 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1349 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
1352 all_prefix_attrs
= prefix_attrs
;
1355 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1357 c_parser_consume_token (parser
);
1362 c_parser_error (parser
, "expected %<,%> or %<;%>");
1363 c_parser_skip_to_end_of_block_or_statement (parser
);
1369 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, "
1370 "%<asm%> or %<__attribute__%>");
1371 c_parser_skip_to_end_of_block_or_statement (parser
);
1374 /* Function definition (nested or otherwise). */
1378 pedwarn ("%HISO C forbids nested functions", &here
);
1379 push_function_context ();
1381 if (!start_function (specs
, declarator
, all_prefix_attrs
))
1383 /* This can appear in many cases looking nothing like a
1384 function definition, so we don't give a more specific
1385 error suggesting there was one. */
1386 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
1387 "or %<__attribute__%>");
1389 pop_function_context ();
1392 /* Parse old-style parameter declarations. ??? Attributes are
1393 not allowed to start declaration specifiers here because of a
1394 syntax conflict between a function declaration with attribute
1395 suffix and a function definition with an attribute prefix on
1396 first old-style parameter declaration. Following the old
1397 parser, they are not accepted on subsequent old-style
1398 parameter declarations either. However, there is no
1399 ambiguity after the first declaration, nor indeed on the
1400 first as long as we don't allow postfix attributes after a
1401 declarator with a nonempty identifier list in a definition;
1402 and postfix attributes have never been accepted here in
1403 function definitions either. */
1404 while (c_parser_next_token_is_not (parser
, CPP_EOF
)
1405 && c_parser_next_token_is_not (parser
, CPP_OPEN_BRACE
))
1406 c_parser_declaration_or_fndef (parser
, false, false, true, false);
1407 DECL_SOURCE_LOCATION (current_function_decl
)
1408 = c_parser_peek_token (parser
)->location
;
1409 store_parm_decls ();
1410 fnbody
= c_parser_compound_statement (parser
);
1413 tree decl
= current_function_decl
;
1416 pop_function_context ();
1417 add_stmt (build_stmt (DECL_EXPR
, decl
));
1428 /* Parse an asm-definition (asm() outside a function body). This is a
1436 c_parser_asm_definition (c_parser
*parser
)
1438 tree asm_str
= c_parser_simple_asm_expr (parser
);
1440 cgraph_add_asm_node (asm_str
);
1441 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
1444 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
1445 6.7), adding them to SPECS (which may already include some).
1446 Storage class specifiers are accepted iff SCSPEC_OK; type
1447 specifiers are accepted iff TYPESPEC_OK; attributes are accepted at
1448 the start iff START_ATTR_OK.
1450 declaration-specifiers:
1451 storage-class-specifier declaration-specifiers[opt]
1452 type-specifier declaration-specifiers[opt]
1453 type-qualifier declaration-specifiers[opt]
1454 function-specifier declaration-specifiers[opt]
1456 Function specifiers (inline) are from C99, and are currently
1457 handled as storage class specifiers, as is __thread.
1459 C90 6.5.1, C99 6.7.1:
1460 storage-class-specifier:
1471 C90 6.5.2, C99 6.7.2:
1484 [_Imaginary removed in C99 TC2]
1485 struct-or-union-specifier
1489 (_Bool and _Complex are new in C99.)
1491 C90 6.5.3, C99 6.7.3:
1498 (restrict is new in C99.)
1502 declaration-specifiers:
1503 attributes declaration-specifiers[opt]
1505 storage-class-specifier:
1517 (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
1518 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
1523 class-name objc-protocol-refs[opt]
1524 typedef-name objc-protocol-refs
1529 c_parser_declspecs (c_parser
*parser
, struct c_declspecs
*specs
,
1530 bool scspec_ok
, bool typespec_ok
, bool start_attr_ok
)
1532 bool attrs_ok
= start_attr_ok
;
1533 bool seen_type
= specs
->type_seen_p
;
1534 while (c_parser_next_token_is (parser
, CPP_NAME
)
1535 || c_parser_next_token_is (parser
, CPP_KEYWORD
)
1536 || (c_dialect_objc () && c_parser_next_token_is (parser
, CPP_LESS
)))
1538 struct c_typespec t
;
1540 if (c_parser_next_token_is (parser
, CPP_NAME
))
1542 tree value
= c_parser_peek_token (parser
)->value
;
1543 c_id_kind kind
= c_parser_peek_token (parser
)->id_kind
;
1544 /* This finishes the specifiers unless a type name is OK, it
1545 is declared as a type name and a type name hasn't yet
1547 if (!typespec_ok
|| seen_type
1548 || (kind
!= C_ID_TYPENAME
&& kind
!= C_ID_CLASSNAME
))
1550 c_parser_consume_token (parser
);
1553 if (kind
== C_ID_TYPENAME
1554 && (!c_dialect_objc ()
1555 || c_parser_next_token_is_not (parser
, CPP_LESS
)))
1557 t
.kind
= ctsk_typedef
;
1558 /* For a typedef name, record the meaning, not the name.
1559 In case of 'foo foo, bar;'. */
1560 t
.spec
= lookup_name (value
);
1564 tree proto
= NULL_TREE
;
1565 gcc_assert (c_dialect_objc ());
1567 if (c_parser_next_token_is (parser
, CPP_LESS
))
1568 proto
= c_parser_objc_protocol_refs (parser
);
1569 t
.spec
= objc_get_protocol_qualified_type (value
, proto
);
1571 declspecs_add_type (specs
, t
);
1574 if (c_parser_next_token_is (parser
, CPP_LESS
))
1576 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
1577 nisse@lysator.liu.se. */
1579 gcc_assert (c_dialect_objc ());
1580 if (!typespec_ok
|| seen_type
)
1582 proto
= c_parser_objc_protocol_refs (parser
);
1584 t
.spec
= objc_get_protocol_qualified_type (NULL_TREE
, proto
);
1585 declspecs_add_type (specs
, t
);
1588 gcc_assert (c_parser_next_token_is (parser
, CPP_KEYWORD
));
1589 switch (c_parser_peek_token (parser
)->keyword
)
1601 /* TODO: Distinguish between function specifiers (inline)
1602 and storage class specifiers, either here or in
1603 declspecs_add_scspec. */
1604 declspecs_add_scspec (specs
, c_parser_peek_token (parser
)->value
);
1605 c_parser_consume_token (parser
);
1628 if (c_dialect_objc ())
1629 parser
->objc_need_raw_identifier
= true;
1630 t
.kind
= ctsk_resword
;
1631 t
.spec
= c_parser_peek_token (parser
)->value
;
1632 declspecs_add_type (specs
, t
);
1633 c_parser_consume_token (parser
);
1640 t
= c_parser_enum_specifier (parser
);
1641 declspecs_add_type (specs
, t
);
1649 t
= c_parser_struct_or_union_specifier (parser
);
1650 declspecs_add_type (specs
, t
);
1653 /* ??? The old parser rejected typeof after other type
1654 specifiers, but is a syntax error the best way of
1656 if (!typespec_ok
|| seen_type
)
1660 t
= c_parser_typeof_specifier (parser
);
1661 declspecs_add_type (specs
, t
);
1667 declspecs_add_qual (specs
, c_parser_peek_token (parser
)->value
);
1668 c_parser_consume_token (parser
);
1673 attrs
= c_parser_attributes (parser
);
1674 declspecs_add_attrs (specs
, attrs
);
1683 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
1686 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
1687 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
1688 enum attributes[opt] identifier
1690 The form with trailing comma is new in C99. The forms with
1691 attributes are GNU extensions. In GNU C, we accept any expression
1692 without commas in the syntax (assignment expressions, not just
1693 conditional expressions); assignment expressions will be diagnosed
1698 enumerator-list , enumerator
1701 enumeration-constant
1702 enumeration-constant = constant-expression
1705 static struct c_typespec
1706 c_parser_enum_specifier (c_parser
*parser
)
1708 struct c_typespec ret
;
1710 tree ident
= NULL_TREE
;
1711 location_t ident_loc
;
1712 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ENUM
));
1713 c_parser_consume_token (parser
);
1714 attrs
= c_parser_attributes (parser
);
1715 /* Set the location in case we create a decl now. */
1716 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
1717 if (c_parser_next_token_is (parser
, CPP_NAME
))
1719 ident
= c_parser_peek_token (parser
)->value
;
1720 ident_loc
= c_parser_peek_token (parser
)->location
;
1721 c_parser_consume_token (parser
);
1723 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
1725 /* Parse an enum definition. */
1726 struct c_enum_contents the_enum
;
1727 tree type
= start_enum (&the_enum
, ident
);
1729 /* We chain the enumerators in reverse order, then put them in
1730 forward order at the end. */
1731 tree values
= NULL_TREE
;
1732 c_parser_consume_token (parser
);
1740 location_t comma_loc
;
1741 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
1743 c_parser_error (parser
, "expected identifier");
1744 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
1745 values
= error_mark_node
;
1748 token
= c_parser_peek_token (parser
);
1749 enum_id
= token
->value
;
1750 /* Set the location in case we create a decl now. */
1751 c_parser_set_source_position_from_token (token
);
1752 c_parser_consume_token (parser
);
1753 if (c_parser_next_token_is (parser
, CPP_EQ
))
1755 c_parser_consume_token (parser
);
1756 enum_value
= c_parser_expr_no_commas (parser
, NULL
).value
;
1759 enum_value
= NULL_TREE
;
1760 enum_decl
= build_enumerator (&the_enum
, enum_id
, enum_value
);
1761 TREE_CHAIN (enum_decl
) = values
;
1764 if (c_parser_next_token_is (parser
, CPP_COMMA
))
1766 comma_loc
= c_parser_peek_token (parser
)->location
;
1768 c_parser_consume_token (parser
);
1770 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
1772 if (seen_comma
&& pedantic
&& !flag_isoc99
)
1773 pedwarn ("%Hcomma at end of enumerator list", &comma_loc
);
1774 c_parser_consume_token (parser
);
1779 c_parser_error (parser
, "expected %<,%> or %<}%>");
1780 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
1781 values
= error_mark_node
;
1785 postfix_attrs
= c_parser_attributes (parser
);
1786 ret
.spec
= finish_enum (type
, nreverse (values
),
1787 chainon (attrs
, postfix_attrs
));
1788 ret
.kind
= ctsk_tagdef
;
1793 c_parser_error (parser
, "expected %<{%>");
1794 ret
.spec
= error_mark_node
;
1795 ret
.kind
= ctsk_tagref
;
1798 ret
= parser_xref_tag (ENUMERAL_TYPE
, ident
);
1799 /* In ISO C, enumerated types can be referred to only if already
1801 if (pedantic
&& !COMPLETE_TYPE_P (ret
.spec
))
1804 pedwarn ("%HISO C forbids forward references to %<enum%> types",
1810 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
1812 struct-or-union-specifier:
1813 struct-or-union attributes[opt] identifier[opt]
1814 { struct-contents } attributes[opt]
1815 struct-or-union attributes[opt] identifier
1818 struct-declaration-list
1820 struct-declaration-list:
1821 struct-declaration ;
1822 struct-declaration-list struct-declaration ;
1829 struct-declaration-list struct-declaration
1831 struct-declaration-list:
1832 struct-declaration-list ;
1835 (Note that in the syntax here, unlike that in ISO C, the semicolons
1836 are included here rather than in struct-declaration, in order to
1837 describe the syntax with extra semicolons and missing semicolon at
1842 struct-declaration-list:
1843 @defs ( class-name )
1845 (Note this does not include a trailing semicolon, but can be
1846 followed by further declarations, and gets a pedwarn-if-pedantic
1847 when followed by a semicolon.) */
1849 static struct c_typespec
1850 c_parser_struct_or_union_specifier (c_parser
*parser
)
1852 struct c_typespec ret
;
1854 tree ident
= NULL_TREE
;
1855 enum tree_code code
;
1856 switch (c_parser_peek_token (parser
)->keyword
)
1867 c_parser_consume_token (parser
);
1868 attrs
= c_parser_attributes (parser
);
1869 /* Set the location in case we create a decl now. */
1870 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
1871 if (c_parser_next_token_is (parser
, CPP_NAME
))
1873 ident
= c_parser_peek_token (parser
)->value
;
1874 c_parser_consume_token (parser
);
1876 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
1878 /* Parse a struct or union definition. Start the scope of the
1879 tag before parsing components. */
1880 tree type
= start_struct (code
, ident
);
1882 /* We chain the components in reverse order, then put them in
1883 forward order at the end. Each struct-declaration may
1884 declare multiple components (comma-separated), so we must use
1885 chainon to join them, although when parsing each
1886 struct-declaration we can use TREE_CHAIN directly.
1888 The theory behind all this is that there will be more
1889 semicolon separated fields than comma separated fields, and
1890 so we'll be minimizing the number of node traversals required
1892 tree contents
= NULL_TREE
;
1893 c_parser_consume_token (parser
);
1894 /* Handle the Objective-C @defs construct,
1895 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
1896 if (c_parser_next_token_is_keyword (parser
, RID_AT_DEFS
))
1899 gcc_assert (c_dialect_objc ());
1900 c_parser_consume_token (parser
);
1901 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
1903 if (c_parser_next_token_is (parser
, CPP_NAME
)
1904 && c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
)
1906 name
= c_parser_peek_token (parser
)->value
;
1907 c_parser_consume_token (parser
);
1911 c_parser_error (parser
, "expected class name");
1912 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
1915 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
1917 contents
= nreverse (objc_get_class_ivars (name
));
1920 /* Parse the struct-declarations and semicolons. Problems with
1921 semicolons are diagnosed here; empty structures are diagnosed
1926 /* Parse any stray semicolon. */
1927 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1930 pedwarn ("%Hextra semicolon in struct or union specified",
1931 &c_parser_peek_token (parser
)->location
);
1932 c_parser_consume_token (parser
);
1935 /* Stop if at the end of the struct or union contents. */
1936 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
1938 c_parser_consume_token (parser
);
1941 /* Accept #pragmas at struct scope. */
1942 if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
1944 c_parser_pragma (parser
, pragma_external
);
1947 /* Parse some comma-separated declarations, but not the
1948 trailing semicolon if any. */
1949 decls
= c_parser_struct_declaration (parser
);
1950 contents
= chainon (decls
, contents
);
1951 /* If no semicolon follows, either we have a parse error or
1952 are at the end of the struct or union and should
1954 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1955 c_parser_consume_token (parser
);
1958 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
1959 pedwarn ("%Hno semicolon at end of struct or union",
1960 &c_parser_peek_token (parser
)->location
);
1963 c_parser_error (parser
, "expected %<;%>");
1964 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
1969 postfix_attrs
= c_parser_attributes (parser
);
1970 ret
.spec
= finish_struct (type
, nreverse (contents
),
1971 chainon (attrs
, postfix_attrs
));
1972 ret
.kind
= ctsk_tagdef
;
1977 c_parser_error (parser
, "expected %<{%>");
1978 ret
.spec
= error_mark_node
;
1979 ret
.kind
= ctsk_tagref
;
1982 ret
= parser_xref_tag (code
, ident
);
1986 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
1987 the trailing semicolon.
1990 specifier-qualifier-list struct-declarator-list
1992 specifier-qualifier-list:
1993 type-specifier specifier-qualifier-list[opt]
1994 type-qualifier specifier-qualifier-list[opt]
1995 attributes specifier-qualifier-list[opt]
1997 struct-declarator-list:
1999 struct-declarator-list , attributes[opt] struct-declarator
2002 declarator attributes[opt]
2003 declarator[opt] : constant-expression attributes[opt]
2008 __extension__ struct-declaration
2009 specifier-qualifier-list
2011 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
2012 of attributes where shown is a GNU extension. In GNU C, we accept
2013 any expression without commas in the syntax (assignment
2014 expressions, not just conditional expressions); assignment
2015 expressions will be diagnosed as non-constant. */
2018 c_parser_struct_declaration (c_parser
*parser
)
2020 struct c_declspecs
*specs
;
2022 tree all_prefix_attrs
;
2024 location_t decl_loc
;
2025 if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
2029 ext
= disable_extension_diagnostics ();
2030 c_parser_consume_token (parser
);
2031 decl
= c_parser_struct_declaration (parser
);
2032 restore_extension_diagnostics (ext
);
2035 specs
= build_null_declspecs ();
2036 decl_loc
= c_parser_peek_token (parser
)->location
;
2037 c_parser_declspecs (parser
, specs
, false, true, true);
2040 if (!specs
->declspecs_seen_p
)
2042 c_parser_error (parser
, "expected specifier-qualifier-list");
2045 finish_declspecs (specs
);
2046 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2049 if (!specs
->type_seen_p
)
2052 pedwarn ("%HISO C forbids member declarations with no members",
2054 shadow_tag_warned (specs
, pedantic
);
2059 /* Support for unnamed structs or unions as members of
2060 structs or unions (which is [a] useful and [b] supports
2063 ret
= grokfield (build_id_declarator (NULL_TREE
), specs
,
2066 decl_attributes (&ret
, attrs
, 0);
2070 pending_xref_error ();
2071 prefix_attrs
= specs
->attrs
;
2072 all_prefix_attrs
= prefix_attrs
;
2073 specs
->attrs
= NULL_TREE
;
2077 /* Declaring one or more declarators or un-named bit-fields. */
2078 struct c_declarator
*declarator
;
2080 if (c_parser_next_token_is (parser
, CPP_COLON
))
2081 declarator
= build_id_declarator (NULL_TREE
);
2083 declarator
= c_parser_declarator (parser
, specs
->type_seen_p
,
2084 C_DTR_NORMAL
, &dummy
);
2085 if (declarator
== NULL
)
2087 c_parser_skip_to_end_of_block_or_statement (parser
);
2090 if (c_parser_next_token_is (parser
, CPP_COLON
)
2091 || c_parser_next_token_is (parser
, CPP_COMMA
)
2092 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2093 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
)
2094 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2096 tree postfix_attrs
= NULL_TREE
;
2097 tree width
= NULL_TREE
;
2099 if (c_parser_next_token_is (parser
, CPP_COLON
))
2101 c_parser_consume_token (parser
);
2102 width
= c_parser_expr_no_commas (parser
, NULL
).value
;
2104 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2105 postfix_attrs
= c_parser_attributes (parser
);
2106 d
= grokfield (declarator
, specs
, width
, &all_prefix_attrs
);
2107 decl_attributes (&d
, chainon (postfix_attrs
,
2108 all_prefix_attrs
), 0);
2109 TREE_CHAIN (d
) = decls
;
2111 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2112 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
2115 all_prefix_attrs
= prefix_attrs
;
2116 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2117 c_parser_consume_token (parser
);
2118 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2119 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2121 /* Semicolon consumed in caller. */
2126 c_parser_error (parser
, "expected %<,%>, %<;%> or %<}%>");
2132 c_parser_error (parser
,
2133 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
2134 "%<__attribute__%>");
2141 /* Parse a typeof specifier (a GNU extension).
2144 typeof ( expression )
2145 typeof ( type-name )
2148 static struct c_typespec
2149 c_parser_typeof_specifier (c_parser
*parser
)
2151 struct c_typespec ret
;
2152 ret
.kind
= ctsk_typeof
;
2153 ret
.spec
= error_mark_node
;
2154 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TYPEOF
));
2155 c_parser_consume_token (parser
);
2158 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2164 if (c_parser_next_token_starts_typename (parser
))
2166 struct c_type_name
*type
= c_parser_type_name (parser
);
2171 ret
.spec
= groktypename (type
);
2172 pop_maybe_used (variably_modified_type_p (ret
.spec
, NULL_TREE
));
2178 location_t here
= c_parser_peek_token (parser
)->location
;
2179 struct c_expr expr
= c_parser_expression (parser
);
2182 if (TREE_CODE (expr
.value
) == COMPONENT_REF
2183 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
2184 error ("%H%<typeof%> applied to a bit-field", &here
);
2185 ret
.spec
= TREE_TYPE (expr
.value
);
2186 was_vm
= variably_modified_type_p (ret
.spec
, NULL_TREE
);
2187 /* This should be returned with the type so that when the type
2188 is evaluated, this can be evaluated. For now, we avoid
2189 evaluation when the context might. */
2190 if (!skip_evaluation
&& was_vm
)
2192 tree e
= expr
.value
;
2194 /* If the expression is not of a type to which we cannot assign a line
2195 number, wrap the thing in a no-op NOP_EXPR. */
2196 if (DECL_P (e
) || CONSTANT_CLASS_P (e
))
2197 e
= build1 (NOP_EXPR
, void_type_node
, e
);
2199 if (CAN_HAVE_LOCATION_P (e
))
2200 SET_EXPR_LOCATION (e
, input_location
);
2204 pop_maybe_used (was_vm
);
2206 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
2210 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
2211 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
2212 be redeclared; otherwise it may not. KIND indicates which kind of
2213 declarator is wanted. Returns a valid declarator except in the
2214 case of a syntax error in which case NULL is returned. *SEEN_ID is
2215 set to true if an identifier being declared is seen; this is used
2216 to diagnose bad forms of abstract array declarators and to
2217 determine whether an identifier list is syntactically permitted.
2220 pointer[opt] direct-declarator
2224 ( attributes[opt] declarator )
2225 direct-declarator array-declarator
2226 direct-declarator ( parameter-type-list )
2227 direct-declarator ( identifier-list[opt] )
2230 * type-qualifier-list[opt]
2231 * type-qualifier-list[opt] pointer
2233 type-qualifier-list:
2236 type-qualifier-list type-qualifier
2237 type-qualifier-list attributes
2239 parameter-type-list:
2241 parameter-list , ...
2244 parameter-declaration
2245 parameter-list , parameter-declaration
2247 parameter-declaration:
2248 declaration-specifiers declarator attributes[opt]
2249 declaration-specifiers abstract-declarator[opt] attributes[opt]
2253 identifier-list , identifier
2255 abstract-declarator:
2257 pointer[opt] direct-abstract-declarator
2259 direct-abstract-declarator:
2260 ( attributes[opt] abstract-declarator )
2261 direct-abstract-declarator[opt] array-declarator
2262 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
2267 direct-declarator ( parameter-forward-declarations
2268 parameter-type-list[opt] )
2270 direct-abstract-declarator:
2271 direct-abstract-declarator[opt] ( parameter-forward-declarations
2272 parameter-type-list[opt] )
2274 parameter-forward-declarations:
2276 parameter-forward-declarations parameter-list ;
2278 The uses of attributes shown above are GNU extensions.
2280 Some forms of array declarator are not included in C99 in the
2281 syntax for abstract declarators; these are disallowed elsewhere.
2282 This may be a defect (DR#289).
2284 This function also accepts an omitted abstract declarator as being
2285 an abstract declarator, although not part of the formal syntax. */
2287 static struct c_declarator
*
2288 c_parser_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
2291 /* Parse any initial pointer part. */
2292 if (c_parser_next_token_is (parser
, CPP_MULT
))
2294 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
2295 struct c_declarator
*inner
;
2296 c_parser_consume_token (parser
);
2297 c_parser_declspecs (parser
, quals_attrs
, false, false, true);
2298 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
2302 return make_pointer_declarator (quals_attrs
, inner
);
2304 /* Now we have a direct declarator, direct abstract declarator or
2305 nothing (which counts as a direct abstract declarator here). */
2306 return c_parser_direct_declarator (parser
, type_seen_p
, kind
, seen_id
);
2309 /* Parse a direct declarator or direct abstract declarator; arguments
2310 as c_parser_declarator. */
2312 static struct c_declarator
*
2313 c_parser_direct_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
2316 /* The direct declarator must start with an identifier (possibly
2317 omitted) or a parenthesized declarator (possibly abstract). In
2318 an ordinary declarator, initial parentheses must start a
2319 parenthesized declarator. In an abstract declarator or parameter
2320 declarator, they could start a parenthesized declarator or a
2321 parameter list. To tell which, the open parenthesis and any
2322 following attributes must be read. If a declaration specifier
2323 follows, then it is a parameter list; if the specifier is a
2324 typedef name, there might be an ambiguity about redeclaring it,
2325 which is resolved in the direction of treating it as a typedef
2326 name. If a close parenthesis follows, it is also an empty
2327 parameter list, as the syntax does not permit empty abstract
2328 declarators. Otherwise, it is a parenthesized declarator (in
2329 which case the analysis may be repeated inside it, recursively).
2331 ??? There is an ambiguity in a parameter declaration "int
2332 (__attribute__((foo)) x)", where x is not a typedef name: it
2333 could be an abstract declarator for a function, or declare x with
2334 parentheses. The proper resolution of this ambiguity needs
2335 documenting. At present we follow an accident of the old
2336 parser's implementation, whereby the first parameter must have
2337 some declaration specifiers other than just attributes. Thus as
2338 a parameter declaration it is treated as a parenthesized
2339 parameter named x, and as an abstract declarator it is
2342 ??? Also following the old parser, attributes inside an empty
2343 parameter list are ignored, making it a list not yielding a
2344 prototype, rather than giving an error or making it have one
2345 parameter with implicit type int.
2347 ??? Also following the old parser, typedef names may be
2348 redeclared in declarators, but not Objective-C class names. */
2350 if (kind
!= C_DTR_ABSTRACT
2351 && c_parser_next_token_is (parser
, CPP_NAME
)
2353 && c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
)
2354 || c_parser_peek_token (parser
)->id_kind
== C_ID_ID
))
2356 struct c_declarator
*inner
2357 = build_id_declarator (c_parser_peek_token (parser
)->value
);
2359 inner
->id_loc
= c_parser_peek_token (parser
)->location
;
2360 c_parser_consume_token (parser
);
2361 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
2364 if (kind
!= C_DTR_NORMAL
2365 && c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
2367 struct c_declarator
*inner
= build_id_declarator (NULL_TREE
);
2368 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
2371 /* Either we are at the end of an abstract declarator, or we have
2374 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
2377 struct c_declarator
*inner
;
2378 c_parser_consume_token (parser
);
2379 attrs
= c_parser_attributes (parser
);
2380 if (kind
!= C_DTR_NORMAL
2381 && (c_parser_next_token_starts_declspecs (parser
)
2382 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
)))
2384 struct c_arg_info
*args
2385 = c_parser_parms_declarator (parser
, kind
== C_DTR_NORMAL
,
2392 = build_function_declarator (args
,
2393 build_id_declarator (NULL_TREE
));
2394 return c_parser_direct_declarator_inner (parser
, *seen_id
,
2398 /* A parenthesized declarator. */
2399 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
2400 if (inner
!= NULL
&& attrs
!= NULL
)
2401 inner
= build_attrs_declarator (attrs
, inner
);
2402 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2404 c_parser_consume_token (parser
);
2408 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
2412 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2419 if (kind
== C_DTR_NORMAL
)
2421 c_parser_error (parser
, "expected identifier or %<(%>");
2425 return build_id_declarator (NULL_TREE
);
2429 /* Parse part of a direct declarator or direct abstract declarator,
2430 given that some (in INNER) has already been parsed; ID_PRESENT is
2431 true if an identifier is present, false for an abstract
2434 static struct c_declarator
*
2435 c_parser_direct_declarator_inner (c_parser
*parser
, bool id_present
,
2436 struct c_declarator
*inner
)
2438 /* Parse a sequence of array declarators and parameter lists. */
2439 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
2441 struct c_declarator
*declarator
;
2442 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
2446 c_parser_consume_token (parser
);
2447 c_parser_declspecs (parser
, quals_attrs
, false, false, true);
2448 static_seen
= c_parser_next_token_is_keyword (parser
, RID_STATIC
);
2450 c_parser_consume_token (parser
);
2451 if (static_seen
&& !quals_attrs
->declspecs_seen_p
)
2452 c_parser_declspecs (parser
, quals_attrs
, false, false, true);
2453 if (!quals_attrs
->declspecs_seen_p
)
2455 /* If "static" is present, there must be an array dimension.
2456 Otherwise, there may be a dimension, "*", or no
2461 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
2465 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
2470 else if (c_parser_next_token_is (parser
, CPP_MULT
))
2472 if (c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_SQUARE
)
2476 c_parser_consume_token (parser
);
2481 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
2487 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
2490 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
2491 c_parser_consume_token (parser
);
2494 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
2498 declarator
= build_array_declarator (dimen
, quals_attrs
, static_seen
,
2500 if (declarator
== NULL
)
2502 inner
= set_array_declarator_inner (declarator
, inner
, !id_present
);
2503 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
2505 else if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
2508 struct c_arg_info
*args
;
2509 c_parser_consume_token (parser
);
2510 attrs
= c_parser_attributes (parser
);
2511 args
= c_parser_parms_declarator (parser
, id_present
, attrs
);
2516 inner
= build_function_declarator (args
, inner
);
2517 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
2523 /* Parse a parameter list or identifier list, including the closing
2524 parenthesis but not the opening one. ATTRS are the attributes at
2525 the start of the list. ID_LIST_OK is true if an identifier list is
2526 acceptable; such a list must not have attributes at the start. */
2528 static struct c_arg_info
*
2529 c_parser_parms_declarator (c_parser
*parser
, bool id_list_ok
, tree attrs
)
2532 declare_parm_level ();
2533 /* If the list starts with an identifier, it is an identifier list.
2534 Otherwise, it is either a prototype list or an empty list. */
2537 && c_parser_next_token_is (parser
, CPP_NAME
)
2538 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
2540 tree list
= NULL_TREE
, *nextp
= &list
;
2541 while (c_parser_next_token_is (parser
, CPP_NAME
)
2542 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
2544 *nextp
= build_tree_list (NULL_TREE
,
2545 c_parser_peek_token (parser
)->value
);
2546 nextp
= & TREE_CHAIN (*nextp
);
2547 c_parser_consume_token (parser
);
2548 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
2550 c_parser_consume_token (parser
);
2551 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2553 c_parser_error (parser
, "expected identifier");
2557 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2559 struct c_arg_info
*ret
= XOBNEW (&parser_obstack
, struct c_arg_info
);
2564 ret
->pending_sizes
= 0;
2565 ret
->had_vla_unspec
= 0;
2566 c_parser_consume_token (parser
);
2572 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2580 struct c_arg_info
*ret
= c_parser_parms_list_declarator (parser
, attrs
);
2586 /* Parse a parameter list (possibly empty), including the closing
2587 parenthesis but not the opening one. ATTRS are the attributes at
2588 the start of the list. */
2590 static struct c_arg_info
*
2591 c_parser_parms_list_declarator (c_parser
*parser
, tree attrs
)
2593 bool good_parm
= false;
2594 /* ??? Following the old parser, forward parameter declarations may
2595 use abstract declarators, and if no real parameter declarations
2596 follow the forward declarations then this is not diagnosed. Also
2597 note as above that attributes are ignored as the only contents of
2598 the parentheses, or as the only contents after forward
2600 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2602 struct c_arg_info
*ret
= XOBNEW (&parser_obstack
, struct c_arg_info
);
2607 ret
->pending_sizes
= 0;
2608 ret
->had_vla_unspec
= 0;
2609 c_parser_consume_token (parser
);
2612 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
2614 struct c_arg_info
*ret
= XOBNEW (&parser_obstack
, struct c_arg_info
);
2618 ret
->pending_sizes
= 0;
2619 ret
->had_vla_unspec
= 0;
2620 /* Suppress -Wold-style-definition for this case. */
2621 ret
->types
= error_mark_node
;
2622 error ("%HISO C requires a named argument before %<...%>",
2623 &c_parser_peek_token (parser
)->location
);
2624 c_parser_consume_token (parser
);
2625 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2627 c_parser_consume_token (parser
);
2632 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2637 /* Nonempty list of parameters, either terminated with semicolon
2638 (forward declarations; recurse) or with close parenthesis (normal
2639 function) or with ", ... )" (variadic function). */
2642 /* Parse a parameter. */
2643 struct c_parm
*parm
= c_parser_parameter_declaration (parser
, attrs
);
2648 push_parm_decl (parm
);
2650 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2653 c_parser_consume_token (parser
);
2654 mark_forward_parm_decls ();
2655 new_attrs
= c_parser_attributes (parser
);
2656 return c_parser_parms_list_declarator (parser
, new_attrs
);
2658 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2660 c_parser_consume_token (parser
);
2662 return get_parm_info (false);
2665 struct c_arg_info
*ret
2666 = XOBNEW (&parser_obstack
, struct c_arg_info
);
2671 ret
->pending_sizes
= 0;
2672 ret
->had_vla_unspec
= 0;
2676 if (!c_parser_require (parser
, CPP_COMMA
,
2677 "expected %<;%>, %<,%> or %<)%>"))
2679 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2682 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
2684 c_parser_consume_token (parser
);
2685 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2687 c_parser_consume_token (parser
);
2689 return get_parm_info (true);
2692 struct c_arg_info
*ret
2693 = XOBNEW (&parser_obstack
, struct c_arg_info
);
2698 ret
->pending_sizes
= 0;
2699 ret
->had_vla_unspec
= 0;
2705 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2713 /* Parse a parameter declaration. ATTRS are the attributes at the
2714 start of the declaration if it is the first parameter. */
2716 static struct c_parm
*
2717 c_parser_parameter_declaration (c_parser
*parser
, tree attrs
)
2719 struct c_declspecs
*specs
;
2720 struct c_declarator
*declarator
;
2722 tree postfix_attrs
= NULL_TREE
;
2724 if (!c_parser_next_token_starts_declspecs (parser
))
2726 /* ??? In some Objective-C cases '...' isn't applicable so there
2727 should be a different message. */
2728 c_parser_error (parser
,
2729 "expected declaration specifiers or %<...%>");
2730 c_parser_skip_to_end_of_parameter (parser
);
2733 specs
= build_null_declspecs ();
2736 declspecs_add_attrs (specs
, attrs
);
2739 c_parser_declspecs (parser
, specs
, true, true, true);
2740 finish_declspecs (specs
);
2741 pending_xref_error ();
2742 prefix_attrs
= specs
->attrs
;
2743 specs
->attrs
= NULL_TREE
;
2744 declarator
= c_parser_declarator (parser
, specs
->type_seen_p
,
2745 C_DTR_PARM
, &dummy
);
2746 if (declarator
== NULL
)
2748 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
2751 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2752 postfix_attrs
= c_parser_attributes (parser
);
2753 return build_c_parm (specs
, chainon (postfix_attrs
, prefix_attrs
),
2757 /* Parse a string literal in an asm expression. It should not be
2758 translated, and wide string literals are an error although
2759 permitted by the syntax. This is a GNU extension.
2764 ??? At present, following the old parser, the caller needs to have
2765 set lex_untranslated_string to 1. It would be better to follow the
2766 C++ parser rather than using this kludge. */
2769 c_parser_asm_string_literal (c_parser
*parser
)
2772 if (c_parser_next_token_is (parser
, CPP_STRING
))
2774 str
= c_parser_peek_token (parser
)->value
;
2775 c_parser_consume_token (parser
);
2777 else if (c_parser_next_token_is (parser
, CPP_WSTRING
))
2779 error ("%Hwide string literal in %<asm%>",
2780 &c_parser_peek_token (parser
)->location
);
2781 str
= build_string (1, "");
2782 c_parser_consume_token (parser
);
2786 c_parser_error (parser
, "expected string literal");
2792 /* Parse a simple asm expression. This is used in restricted
2793 contexts, where a full expression with inputs and outputs does not
2794 make sense. This is a GNU extension.
2797 asm ( asm-string-literal )
2801 c_parser_simple_asm_expr (c_parser
*parser
)
2804 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
2805 /* ??? Follow the C++ parser rather than using the
2806 lex_untranslated_string kludge. */
2807 parser
->lex_untranslated_string
= true;
2808 c_parser_consume_token (parser
);
2809 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2811 parser
->lex_untranslated_string
= false;
2814 str
= c_parser_asm_string_literal (parser
);
2815 parser
->lex_untranslated_string
= false;
2816 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
2818 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2824 /* Parse (possibly empty) attributes. This is a GNU extension.
2828 attributes attribute
2831 __attribute__ ( ( attribute-list ) )
2835 attribute_list , attrib
2840 any-word ( identifier )
2841 any-word ( identifier , nonempty-expr-list )
2842 any-word ( expr-list )
2844 where the "identifier" must not be declared as a type, and
2845 "any-word" may be any identifier (including one declared as a
2846 type), a reserved word storage class specifier, type specifier or
2847 type qualifier. ??? This still leaves out most reserved keywords
2848 (following the old parser), shouldn't we include them, and why not
2849 allow identifiers declared as types to start the arguments? */
2852 c_parser_attributes (c_parser
*parser
)
2854 tree attrs
= NULL_TREE
;
2855 while (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2857 /* ??? Follow the C++ parser rather than using the
2858 lex_untranslated_string kludge. */
2859 parser
->lex_untranslated_string
= true;
2860 c_parser_consume_token (parser
);
2861 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2863 parser
->lex_untranslated_string
= false;
2866 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2868 parser
->lex_untranslated_string
= false;
2869 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2872 /* Parse the attribute list. */
2873 while (c_parser_next_token_is (parser
, CPP_COMMA
)
2874 || c_parser_next_token_is (parser
, CPP_NAME
)
2875 || c_parser_next_token_is (parser
, CPP_KEYWORD
))
2877 tree attr
, attr_name
, attr_args
;
2878 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2880 c_parser_consume_token (parser
);
2883 if (c_parser_next_token_is (parser
, CPP_KEYWORD
))
2885 /* ??? See comment above about what keywords are
2888 switch (c_parser_peek_token (parser
)->keyword
)
2926 attr_name
= c_parser_peek_token (parser
)->value
;
2927 c_parser_consume_token (parser
);
2928 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
2930 attr
= build_tree_list (attr_name
, NULL_TREE
);
2931 attrs
= chainon (attrs
, attr
);
2934 c_parser_consume_token (parser
);
2935 /* Parse the attribute contents. If they start with an
2936 identifier which is followed by a comma or close
2937 parenthesis, then the arguments start with that
2938 identifier; otherwise they are an expression list. */
2939 if (c_parser_next_token_is (parser
, CPP_NAME
)
2940 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
2941 && ((c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
)
2942 || (c_parser_peek_2nd_token (parser
)->type
2943 == CPP_CLOSE_PAREN
)))
2945 tree arg1
= c_parser_peek_token (parser
)->value
;
2946 c_parser_consume_token (parser
);
2947 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2948 attr_args
= build_tree_list (NULL_TREE
, arg1
);
2951 c_parser_consume_token (parser
);
2952 attr_args
= tree_cons (NULL_TREE
, arg1
,
2953 c_parser_expr_list (parser
, false));
2958 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2959 attr_args
= NULL_TREE
;
2961 attr_args
= c_parser_expr_list (parser
, false);
2963 attr
= build_tree_list (attr_name
, attr_args
);
2964 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2965 c_parser_consume_token (parser
);
2968 parser
->lex_untranslated_string
= false;
2969 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2973 attrs
= chainon (attrs
, attr
);
2975 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2976 c_parser_consume_token (parser
);
2979 parser
->lex_untranslated_string
= false;
2980 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2984 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2985 c_parser_consume_token (parser
);
2988 parser
->lex_untranslated_string
= false;
2989 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2993 parser
->lex_untranslated_string
= false;
2998 /* Parse a type name (C90 6.5.5, C99 6.7.6).
3001 specifier-qualifier-list abstract-declarator[opt]
3004 static struct c_type_name
*
3005 c_parser_type_name (c_parser
*parser
)
3007 struct c_declspecs
*specs
= build_null_declspecs ();
3008 struct c_declarator
*declarator
;
3009 struct c_type_name
*ret
;
3011 c_parser_declspecs (parser
, specs
, false, true, true);
3012 if (!specs
->declspecs_seen_p
)
3014 c_parser_error (parser
, "expected specifier-qualifier-list");
3017 pending_xref_error ();
3018 finish_declspecs (specs
);
3019 declarator
= c_parser_declarator (parser
, specs
->type_seen_p
,
3020 C_DTR_ABSTRACT
, &dummy
);
3021 if (declarator
== NULL
)
3023 ret
= XOBNEW (&parser_obstack
, struct c_type_name
);
3025 ret
->declarator
= declarator
;
3029 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
3032 assignment-expression
3033 { initializer-list }
3034 { initializer-list , }
3037 designation[opt] initializer
3038 initializer-list , designation[opt] initializer
3045 designator-list designator
3052 [ constant-expression ]
3064 [ constant-expression ... constant-expression ]
3066 Any expression without commas is accepted in the syntax for the
3067 constant-expressions, with non-constant expressions rejected later.
3069 This function is only used for top-level initializers; for nested
3070 ones, see c_parser_initval. */
3072 static struct c_expr
3073 c_parser_initializer (c_parser
*parser
)
3075 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
3076 return c_parser_braced_init (parser
, NULL_TREE
, false);
3080 ret
= c_parser_expr_no_commas (parser
, NULL
);
3081 if (TREE_CODE (ret
.value
) != STRING_CST
3082 && TREE_CODE (ret
.value
) != COMPOUND_LITERAL_EXPR
)
3083 ret
= default_function_array_conversion (ret
);
3088 /* Parse a braced initializer list. TYPE is the type specified for a
3089 compound literal, and NULL_TREE for other initializers and for
3090 nested braced lists. NESTED_P is true for nested braced lists,
3091 false for the list of a compound literal or the list that is the
3092 top-level initializer in a declaration. */
3094 static struct c_expr
3095 c_parser_braced_init (c_parser
*parser
, tree type
, bool nested_p
)
3097 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
3098 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
3099 c_parser_consume_token (parser
);
3101 push_init_level (0);
3103 really_start_incremental_init (type
);
3104 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3107 pedwarn ("%HISO C forbids empty initializer braces", &brace_loc
);
3111 /* Parse a non-empty initializer list, possibly with a trailing
3115 c_parser_initelt (parser
);
3118 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3119 c_parser_consume_token (parser
);
3122 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3126 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
3129 ret
.value
= error_mark_node
;
3130 ret
.original_code
= ERROR_MARK
;
3131 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
3134 c_parser_consume_token (parser
);
3135 return pop_init_level (0);
3138 /* Parse a nested initializer, including designators. */
3141 c_parser_initelt (c_parser
*parser
)
3143 /* Parse any designator or designator list. A single array
3144 designator may have the subsequent "=" omitted in GNU C, but a
3145 longer list or a structure member designator may not. */
3146 if (c_parser_next_token_is (parser
, CPP_NAME
)
3147 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
3149 /* Old-style structure member designator. */
3150 set_init_label (c_parser_peek_token (parser
)->value
);
3153 /* Use the colon as the error location. */
3154 pedwarn ("%Hobsolete use of designated initializer with %<:%>",
3155 &c_parser_peek_2nd_token (parser
)->location
);
3157 c_parser_consume_token (parser
);
3158 c_parser_consume_token (parser
);
3162 /* des_seen is 0 if there have been no designators, 1 if there
3163 has been a single array designator and 2 otherwise. */
3165 /* Location of a designator. */
3167 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
)
3168 || c_parser_next_token_is (parser
, CPP_DOT
))
3170 int des_prev
= des_seen
;
3172 des_loc
= c_parser_peek_token (parser
)->location
;
3175 if (c_parser_next_token_is (parser
, CPP_DOT
))
3178 c_parser_consume_token (parser
);
3179 if (c_parser_next_token_is (parser
, CPP_NAME
))
3181 set_init_label (c_parser_peek_token (parser
)->value
);
3182 c_parser_consume_token (parser
);
3187 init
.value
= error_mark_node
;
3188 init
.original_code
= ERROR_MARK
;
3189 c_parser_error (parser
, "expected identifier");
3190 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3191 process_init_element (init
);
3198 location_t ellipsis_loc
;
3199 /* ??? Following the old parser, [ objc-receiver
3200 objc-message-args ] is accepted as an initializer,
3201 being distinguished from a designator by what follows
3202 the first assignment expression inside the square
3203 brackets, but after a first array designator a
3204 subsequent square bracket is for Objective-C taken to
3205 start an expression, using the obsolete form of
3206 designated initializer without '=', rather than
3207 possibly being a second level of designation: in LALR
3208 terms, the '[' is shifted rather than reducing
3209 designator to designator-list. */
3210 if (des_prev
== 1 && c_dialect_objc ())
3212 des_seen
= des_prev
;
3215 if (des_prev
== 0 && c_dialect_objc ())
3217 /* This might be an array designator or an
3218 Objective-C message expression. If the former,
3219 continue parsing here; if the latter, parse the
3220 remainder of the initializer given the starting
3221 primary-expression. ??? It might make sense to
3222 distinguish when des_prev == 1 as well; see
3223 previous comment. */
3225 struct c_expr mexpr
;
3226 c_parser_consume_token (parser
);
3227 if (c_parser_peek_token (parser
)->type
== CPP_NAME
3228 && ((c_parser_peek_token (parser
)->id_kind
3230 || (c_parser_peek_token (parser
)->id_kind
3231 == C_ID_CLASSNAME
)))
3233 /* Type name receiver. */
3234 tree id
= c_parser_peek_token (parser
)->value
;
3235 c_parser_consume_token (parser
);
3236 rec
= objc_get_class_reference (id
);
3237 goto parse_message_args
;
3239 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
3240 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
)
3241 || c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3242 goto array_desig_after_first
;
3243 /* Expression receiver. So far only one part
3244 without commas has been parsed; there might be
3245 more of the expression. */
3247 while (c_parser_next_token_is (parser
, CPP_COMMA
))
3250 c_parser_consume_token (parser
);
3251 next
= c_parser_expr_no_commas (parser
, NULL
);
3252 next
= default_function_array_conversion (next
);
3253 rec
= build_compound_expr (rec
, next
.value
);
3256 /* Now parse the objc-message-args. */
3257 args
= c_parser_objc_message_args (parser
);
3258 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3261 = objc_build_message_expr (build_tree_list (rec
, args
));
3262 mexpr
.original_code
= ERROR_MARK
;
3263 /* Now parse and process the remainder of the
3264 initializer, starting with this message
3265 expression as a primary-expression. */
3266 c_parser_initval (parser
, &mexpr
);
3269 c_parser_consume_token (parser
);
3270 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
3271 array_desig_after_first
:
3272 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3274 ellipsis_loc
= c_parser_peek_token (parser
)->location
;
3275 c_parser_consume_token (parser
);
3276 second
= c_parser_expr_no_commas (parser
, NULL
).value
;
3280 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3282 c_parser_consume_token (parser
);
3283 set_init_index (first
, second
);
3284 if (pedantic
&& second
)
3285 pedwarn ("%HISO C forbids specifying range of "
3286 "elements to initialize", &ellipsis_loc
);
3289 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3295 if (c_parser_next_token_is (parser
, CPP_EQ
))
3297 if (pedantic
&& !flag_isoc99
)
3298 pedwarn ("%HISO C90 forbids specifying subobject "
3299 "to initialize", &des_loc
);
3300 c_parser_consume_token (parser
);
3307 pedwarn ("%Hobsolete use of designated initializer "
3309 &c_parser_peek_token (parser
)->location
);
3314 init
.value
= error_mark_node
;
3315 init
.original_code
= ERROR_MARK
;
3316 c_parser_error (parser
, "expected %<=%>");
3317 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3318 process_init_element (init
);
3324 c_parser_initval (parser
, NULL
);
3327 /* Parse a nested initializer; as c_parser_initializer but parses
3328 initializers within braced lists, after any designators have been
3329 applied. If AFTER is not NULL then it is an Objective-C message
3330 expression which is the primary-expression starting the
3334 c_parser_initval (c_parser
*parser
, struct c_expr
*after
)
3337 gcc_assert (!after
|| c_dialect_objc ());
3338 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
) && !after
)
3339 init
= c_parser_braced_init (parser
, NULL_TREE
, true);
3342 init
= c_parser_expr_no_commas (parser
, after
);
3343 if (init
.value
!= NULL_TREE
3344 && TREE_CODE (init
.value
) != STRING_CST
3345 && TREE_CODE (init
.value
) != COMPOUND_LITERAL_EXPR
)
3346 init
= default_function_array_conversion (init
);
3348 process_init_element (init
);
3351 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
3355 { block-item-list[opt] }
3356 { label-declarations block-item-list }
3360 block-item-list block-item
3372 { label-declarations block-item-list }
3375 __extension__ nested-declaration
3376 nested-function-definition
3380 label-declarations label-declaration
3383 __label__ identifier-list ;
3385 Allowing the mixing of declarations and code is new in C99. The
3386 GNU syntax also permits (not shown above) labels at the end of
3387 compound statements, which yield an error. We don't allow labels
3388 on declarations; this might seem like a natural extension, but
3389 there would be a conflict between attributes on the label and
3390 prefix attributes on the declaration. ??? The syntax follows the
3391 old parser in requiring something after label declarations.
3392 Although they are erroneous if the labels declared aren't defined,
3393 is it useful for the syntax to be this way?
3405 c_parser_compound_statement (c_parser
*parser
)
3408 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
3409 return error_mark_node
;
3410 stmt
= c_begin_compound_stmt (true);
3411 c_parser_compound_statement_nostart (parser
);
3412 return c_end_compound_stmt (stmt
, true);
3415 /* Parse a compound statement except for the opening brace. This is
3416 used for parsing both compound statements and statement expressions
3417 (which follow different paths to handling the opening). */
3420 c_parser_compound_statement_nostart (c_parser
*parser
)
3422 bool last_stmt
= false;
3423 bool last_label
= false;
3424 location_t label_loc
;
3425 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3427 c_parser_consume_token (parser
);
3430 if (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
3432 location_t err_loc
= c_parser_peek_token (parser
)->location
;
3433 /* Read zero or more forward-declarations for labels that nested
3434 functions can jump to. */
3435 while (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
3437 c_parser_consume_token (parser
);
3438 /* Any identifiers, including those declared as type names,
3443 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
3445 c_parser_error (parser
, "expected identifier");
3449 = declare_label (c_parser_peek_token (parser
)->value
);
3450 C_DECLARED_LABEL_FLAG (label
) = 1;
3451 add_stmt (build_stmt (DECL_EXPR
, label
));
3452 c_parser_consume_token (parser
);
3453 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3454 c_parser_consume_token (parser
);
3458 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
3461 pedwarn ("%HISO C forbids label declarations", &err_loc
);
3463 /* We must now have at least one statement, label or declaration. */
3464 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3466 c_parser_error (parser
, "expected declaration or statement");
3467 c_parser_consume_token (parser
);
3470 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
3472 location_t loc
= c_parser_peek_token (parser
)->location
;
3473 if (c_parser_next_token_is_keyword (parser
, RID_CASE
)
3474 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
3475 || (c_parser_next_token_is (parser
, CPP_NAME
)
3476 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
3478 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
3479 label_loc
= c_parser_peek_2nd_token (parser
)->location
;
3481 label_loc
= c_parser_peek_token (parser
)->location
;
3484 c_parser_label (parser
);
3486 else if (!last_label
3487 && c_parser_next_token_starts_declspecs (parser
))
3490 c_parser_declaration_or_fndef (parser
, true, true, true, true);
3492 && ((pedantic
&& !flag_isoc99
)
3493 || warn_declaration_after_statement
))
3494 pedwarn_c90 ("%HISO C90 forbids mixed declarations and code",
3498 else if (!last_label
3499 && c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
3501 /* __extension__ can start a declaration, but is also an
3502 unary operator that can start an expression. Consume all
3503 but the last of a possible series of __extension__ to
3505 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
3506 && (c_parser_peek_2nd_token (parser
)->keyword
3508 c_parser_consume_token (parser
);
3509 if (c_token_starts_declspecs (c_parser_peek_2nd_token (parser
)))
3512 ext
= disable_extension_diagnostics ();
3513 c_parser_consume_token (parser
);
3515 c_parser_declaration_or_fndef (parser
, true, true, true, true);
3516 /* Following the old parser, __extension__ does not
3517 disable this diagnostic. */
3518 restore_extension_diagnostics (ext
);
3520 && ((pedantic
&& !flag_isoc99
)
3521 || warn_declaration_after_statement
))
3522 pedwarn_c90 ("%HISO C90 forbids mixed declarations and code",
3529 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
3531 /* External pragmas, and some omp pragmas, are not associated
3532 with regular c code, and so are not to be considered statements
3533 syntactically. This ensures that the user doesn't put them
3534 places that would turn into syntax errors if the directive
3536 if (c_parser_pragma (parser
, pragma_compound
))
3537 last_label
= false, last_stmt
= true;
3539 else if (c_parser_next_token_is (parser
, CPP_EOF
))
3541 c_parser_error (parser
, "expected declaration or statement");
3549 c_parser_statement_after_labels (parser
);
3552 parser
->error
= false;
3555 error ("%Hlabel at end of compound statement", &label_loc
);
3556 c_parser_consume_token (parser
);
3559 /* Parse a label (C90 6.6.1, C99 6.8.1).
3562 identifier : attributes[opt]
3563 case constant-expression :
3569 case constant-expression ... constant-expression :
3571 The use of attributes on labels is a GNU extension. The syntax in
3572 GNU C accepts any expressions without commas, non-constant
3573 expressions being rejected later. */
3576 c_parser_label (c_parser
*parser
)
3578 location_t loc1
= c_parser_peek_token (parser
)->location
;
3579 tree label
= NULL_TREE
;
3580 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
3583 c_parser_consume_token (parser
);
3584 exp1
= c_parser_expr_no_commas (parser
, NULL
).value
;
3585 if (c_parser_next_token_is (parser
, CPP_COLON
))
3587 c_parser_consume_token (parser
);
3588 label
= do_case (exp1
, NULL_TREE
);
3590 else if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3592 c_parser_consume_token (parser
);
3593 exp2
= c_parser_expr_no_commas (parser
, NULL
).value
;
3594 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
3595 label
= do_case (exp1
, exp2
);
3598 c_parser_error (parser
, "expected %<:%> or %<...%>");
3600 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
3602 c_parser_consume_token (parser
);
3603 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
3604 label
= do_case (NULL_TREE
, NULL_TREE
);
3608 tree name
= c_parser_peek_token (parser
)->value
;
3611 location_t loc2
= c_parser_peek_token (parser
)->location
;
3612 gcc_assert (c_parser_next_token_is (parser
, CPP_NAME
));
3613 c_parser_consume_token (parser
);
3614 gcc_assert (c_parser_next_token_is (parser
, CPP_COLON
));
3615 c_parser_consume_token (parser
);
3616 attrs
= c_parser_attributes (parser
);
3617 tlab
= define_label (loc2
, name
);
3620 decl_attributes (&tlab
, attrs
, 0);
3621 label
= add_stmt (build_stmt (LABEL_EXPR
, tlab
));
3625 SET_EXPR_LOCATION (label
, loc1
);
3628 /* Parse a statement (C90 6.6, C99 6.8).
3633 expression-statement
3641 expression-statement:
3644 selection-statement:
3648 iteration-statement:
3657 return expression[opt] ;
3670 objc-throw-statement
3671 objc-try-catch-statement
3672 objc-synchronized-statement
3674 objc-throw-statement:
3688 parallel-for-construct
3689 parallel-sections-construct
3696 parallel-directive structured-block
3699 for-directive iteration-statement
3702 sections-directive section-scope
3705 single-directive structured-block
3707 parallel-for-construct:
3708 parallel-for-directive iteration-statement
3710 parallel-sections-construct:
3711 parallel-sections-directive section-scope
3714 master-directive structured-block
3717 critical-directive structured-block
3720 atomic-directive expression-statement
3723 ordered-directive structured-block */
3726 c_parser_statement (c_parser
*parser
)
3728 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
3729 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
3730 || (c_parser_next_token_is (parser
, CPP_NAME
)
3731 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
3732 c_parser_label (parser
);
3733 c_parser_statement_after_labels (parser
);
3736 /* Parse a statement, other than a labeled statement. */
3739 c_parser_statement_after_labels (c_parser
*parser
)
3741 location_t loc
= c_parser_peek_token (parser
)->location
;
3742 tree stmt
= NULL_TREE
;
3743 switch (c_parser_peek_token (parser
)->type
)
3745 case CPP_OPEN_BRACE
:
3746 add_stmt (c_parser_compound_statement (parser
));
3749 switch (c_parser_peek_token (parser
)->keyword
)
3752 c_parser_if_statement (parser
);
3755 c_parser_switch_statement (parser
);
3758 c_parser_while_statement (parser
);
3761 c_parser_do_statement (parser
);
3764 c_parser_for_statement (parser
);
3767 c_parser_consume_token (parser
);
3768 if (c_parser_next_token_is (parser
, CPP_NAME
))
3770 stmt
= c_finish_goto_label (c_parser_peek_token (parser
)->value
);
3771 c_parser_consume_token (parser
);
3773 else if (c_parser_next_token_is (parser
, CPP_MULT
))
3775 c_parser_consume_token (parser
);
3776 stmt
= c_finish_goto_ptr (c_parser_expression (parser
).value
);
3779 c_parser_error (parser
, "expected identifier or %<*%>");
3780 goto expect_semicolon
;
3782 c_parser_consume_token (parser
);
3783 stmt
= c_finish_bc_stmt (&c_cont_label
, false);
3784 goto expect_semicolon
;
3786 c_parser_consume_token (parser
);
3787 stmt
= c_finish_bc_stmt (&c_break_label
, true);
3788 goto expect_semicolon
;
3790 c_parser_consume_token (parser
);
3791 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3793 stmt
= c_finish_return (NULL_TREE
);
3794 c_parser_consume_token (parser
);
3798 stmt
= c_finish_return (c_parser_expression_conv (parser
).value
);
3799 goto expect_semicolon
;
3803 stmt
= c_parser_asm_statement (parser
);
3806 gcc_assert (c_dialect_objc ());
3807 c_parser_consume_token (parser
);
3808 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3810 stmt
= objc_build_throw_stmt (NULL_TREE
);
3811 c_parser_consume_token (parser
);
3816 = objc_build_throw_stmt (c_parser_expression (parser
).value
);
3817 goto expect_semicolon
;
3821 gcc_assert (c_dialect_objc ());
3822 c_parser_objc_try_catch_statement (parser
);
3824 case RID_AT_SYNCHRONIZED
:
3825 gcc_assert (c_dialect_objc ());
3826 c_parser_objc_synchronized_statement (parser
);
3833 c_parser_consume_token (parser
);
3835 case CPP_CLOSE_PAREN
:
3836 case CPP_CLOSE_SQUARE
:
3837 /* Avoid infinite loop in error recovery:
3838 c_parser_skip_until_found stops at a closing nesting
3839 delimiter without consuming it, but here we need to consume
3840 it to proceed further. */
3841 c_parser_error (parser
, "expected statement");
3842 c_parser_consume_token (parser
);
3845 c_parser_pragma (parser
, pragma_stmt
);
3849 if (c_parser_next_token_starts_declspecs (parser
))
3851 error ("%Ha label can only be part of a statement and "
3852 "a declaration is not a statement",
3853 &c_parser_peek_token (parser
)->location
);
3854 c_parser_declaration_or_fndef (parser
, /*fndef_ok*/ false,
3855 /*nested*/ true, /*empty_ok*/ false,
3856 /*start_attr_ok*/ true);
3859 stmt
= c_finish_expr_stmt (c_parser_expression_conv (parser
).value
);
3861 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
3864 /* Two cases cannot and do not have line numbers associated: If stmt
3865 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
3866 cannot hold line numbers. But that's OK because the statement
3867 will either be changed to a MODIFY_EXPR during gimplification of
3868 the statement expr, or discarded. If stmt was compound, but
3869 without new variables, we will have skipped the creation of a
3870 BIND and will have a bare STATEMENT_LIST. But that's OK because
3871 (recursively) all of the component statements should already have
3872 line numbers assigned. ??? Can we discard no-op statements
3874 if (stmt
&& CAN_HAVE_LOCATION_P (stmt
))
3875 SET_EXPR_LOCATION (stmt
, loc
);
3878 /* Parse a parenthesized condition from an if, do or while statement.
3884 c_parser_paren_condition (c_parser
*parser
)
3888 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3889 return error_mark_node
;
3890 loc
= c_parser_peek_token (parser
)->location
;
3891 cond
= c_objc_common_truthvalue_conversion
3892 (c_parser_expression_conv (parser
).value
);
3893 if (CAN_HAVE_LOCATION_P (cond
))
3894 SET_EXPR_LOCATION (cond
, loc
);
3895 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
3899 /* Parse a statement which is a block in C99. */
3902 c_parser_c99_block_statement (c_parser
*parser
)
3904 tree block
= c_begin_compound_stmt (flag_isoc99
);
3905 c_parser_statement (parser
);
3906 return c_end_compound_stmt (block
, flag_isoc99
);
3909 /* Parse the body of an if statement or the else half thereof. This
3910 is just parsing a statement but (a) it is a block in C99, (b) we
3911 track whether the body is an if statement for the sake of
3912 -Wparentheses warnings, (c) we handle an empty body specially for
3913 the sake of -Wempty-body warnings. */
3916 c_parser_if_body (c_parser
*parser
, bool *if_p
)
3918 tree block
= c_begin_compound_stmt (flag_isoc99
);
3919 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
3920 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
3921 || (c_parser_next_token_is (parser
, CPP_NAME
)
3922 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
3923 c_parser_label (parser
);
3924 *if_p
= c_parser_next_token_is_keyword (parser
, RID_IF
);
3925 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3926 add_stmt (build_empty_stmt ());
3927 c_parser_statement_after_labels (parser
);
3928 return c_end_compound_stmt (block
, flag_isoc99
);
3931 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
3934 if ( expression ) statement
3935 if ( expression ) statement else statement
3939 c_parser_if_statement (c_parser
*parser
)
3944 bool first_if
= false, second_if
= false;
3945 tree first_body
, second_body
;
3946 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_IF
));
3947 c_parser_consume_token (parser
);
3948 block
= c_begin_compound_stmt (flag_isoc99
);
3949 loc
= c_parser_peek_token (parser
)->location
;
3950 cond
= c_parser_paren_condition (parser
);
3951 first_body
= c_parser_if_body (parser
, &first_if
);
3952 if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
3954 c_parser_consume_token (parser
);
3955 second_body
= c_parser_if_body (parser
, &second_if
);
3958 second_body
= NULL_TREE
;
3959 c_finish_if_stmt (loc
, cond
, first_body
, second_body
, first_if
);
3960 add_stmt (c_end_compound_stmt (block
, flag_isoc99
));
3963 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
3966 switch (expression) statement
3970 c_parser_switch_statement (c_parser
*parser
)
3972 tree block
, expr
, body
, save_break
;
3973 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SWITCH
));
3974 c_parser_consume_token (parser
);
3975 block
= c_begin_compound_stmt (flag_isoc99
);
3976 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3978 expr
= c_parser_expression (parser
).value
;
3979 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
3982 expr
= error_mark_node
;
3983 c_start_case (expr
);
3984 save_break
= c_break_label
;
3985 c_break_label
= NULL_TREE
;
3986 body
= c_parser_c99_block_statement (parser
);
3987 c_finish_case (body
);
3989 add_stmt (build1 (LABEL_EXPR
, void_type_node
, c_break_label
));
3990 c_break_label
= save_break
;
3991 add_stmt (c_end_compound_stmt (block
, flag_isoc99
));
3994 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
3997 while (expression) statement
4001 c_parser_while_statement (c_parser
*parser
)
4003 tree block
, cond
, body
, save_break
, save_cont
;
4005 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_WHILE
));
4006 c_parser_consume_token (parser
);
4007 block
= c_begin_compound_stmt (flag_isoc99
);
4008 loc
= c_parser_peek_token (parser
)->location
;
4009 cond
= c_parser_paren_condition (parser
);
4010 save_break
= c_break_label
;
4011 c_break_label
= NULL_TREE
;
4012 save_cont
= c_cont_label
;
4013 c_cont_label
= NULL_TREE
;
4014 body
= c_parser_c99_block_statement (parser
);
4015 c_finish_loop (loc
, cond
, NULL
, body
, c_break_label
, c_cont_label
, true);
4016 add_stmt (c_end_compound_stmt (block
, flag_isoc99
));
4017 c_break_label
= save_break
;
4018 c_cont_label
= save_cont
;
4021 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
4024 do statement while ( expression ) ;
4028 c_parser_do_statement (c_parser
*parser
)
4030 tree block
, cond
, body
, save_break
, save_cont
, new_break
, new_cont
;
4032 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_DO
));
4033 c_parser_consume_token (parser
);
4034 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4035 warning (OPT_Wempty_body
,
4036 "%Hsuggest braces around empty body in %<do%> statement",
4037 &c_parser_peek_token (parser
)->location
);
4038 block
= c_begin_compound_stmt (flag_isoc99
);
4039 loc
= c_parser_peek_token (parser
)->location
;
4040 save_break
= c_break_label
;
4041 c_break_label
= NULL_TREE
;
4042 save_cont
= c_cont_label
;
4043 c_cont_label
= NULL_TREE
;
4044 body
= c_parser_c99_block_statement (parser
);
4045 c_parser_require_keyword (parser
, RID_WHILE
, "expected %<while%>");
4046 new_break
= c_break_label
;
4047 c_break_label
= save_break
;
4048 new_cont
= c_cont_label
;
4049 c_cont_label
= save_cont
;
4050 cond
= c_parser_paren_condition (parser
);
4051 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
4052 c_parser_skip_to_end_of_block_or_statement (parser
);
4053 c_finish_loop (loc
, cond
, NULL
, body
, new_break
, new_cont
, false);
4054 add_stmt (c_end_compound_stmt (block
, flag_isoc99
));
4057 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
4060 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
4061 for ( nested-declaration expression[opt] ; expression[opt] ) statement
4063 The form with a declaration is new in C99.
4065 ??? In accordance with the old parser, the declaration may be a
4066 nested function, which is then rejected in check_for_loop_decls,
4067 but does it make any sense for this to be included in the grammar?
4068 Note in particular that the nested function does not include a
4069 trailing ';', whereas the "declaration" production includes one.
4070 Also, can we reject bad declarations earlier and cheaper than
4071 check_for_loop_decls? */
4074 c_parser_for_statement (c_parser
*parser
)
4076 tree block
, cond
, incr
, save_break
, save_cont
, body
;
4078 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_FOR
));
4079 loc
= c_parser_peek_token (parser
)->location
;
4080 c_parser_consume_token (parser
);
4081 block
= c_begin_compound_stmt (flag_isoc99
);
4082 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4084 /* Parse the initialization declaration or expression. */
4085 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4087 c_parser_consume_token (parser
);
4088 c_finish_expr_stmt (NULL_TREE
);
4090 else if (c_parser_next_token_starts_declspecs (parser
))
4092 c_parser_declaration_or_fndef (parser
, true, true, true, true);
4093 check_for_loop_decls ();
4095 else if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
4097 /* __extension__ can start a declaration, but is also an
4098 unary operator that can start an expression. Consume all
4099 but the last of a possible series of __extension__ to
4101 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
4102 && (c_parser_peek_2nd_token (parser
)->keyword
4104 c_parser_consume_token (parser
);
4105 if (c_token_starts_declspecs (c_parser_peek_2nd_token (parser
)))
4108 ext
= disable_extension_diagnostics ();
4109 c_parser_consume_token (parser
);
4110 c_parser_declaration_or_fndef (parser
, true, true, true, true);
4111 restore_extension_diagnostics (ext
);
4112 check_for_loop_decls ();
4120 c_finish_expr_stmt (c_parser_expression (parser
).value
);
4121 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4123 /* Parse the loop condition. */
4124 loc
= c_parser_peek_token (parser
)->location
;
4125 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4127 c_parser_consume_token (parser
);
4132 tree ocond
= c_parser_expression_conv (parser
).value
;
4133 cond
= c_objc_common_truthvalue_conversion (ocond
);
4134 if (CAN_HAVE_LOCATION_P (cond
))
4135 SET_EXPR_LOCATION (cond
, loc
);
4136 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4138 /* Parse the increment expression. */
4139 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4140 incr
= c_process_expr_stmt (NULL_TREE
);
4142 incr
= c_process_expr_stmt (c_parser_expression (parser
).value
);
4143 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4147 cond
= error_mark_node
;
4148 incr
= error_mark_node
;
4150 save_break
= c_break_label
;
4151 c_break_label
= NULL_TREE
;
4152 save_cont
= c_cont_label
;
4153 c_cont_label
= NULL_TREE
;
4154 body
= c_parser_c99_block_statement (parser
);
4155 c_finish_loop (loc
, cond
, incr
, body
, c_break_label
, c_cont_label
, true);
4156 add_stmt (c_end_compound_stmt (block
, flag_isoc99
));
4157 c_break_label
= save_break
;
4158 c_cont_label
= save_cont
;
4161 /* Parse an asm statement, a GNU extension. This is a full-blown asm
4162 statement with inputs, outputs, clobbers, and volatile tag
4166 asm type-qualifier[opt] ( asm-argument ) ;
4170 asm-string-literal : asm-operands[opt]
4171 asm-string-literal : asm-operands[opt] : asm-operands[opt]
4172 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers
4174 Qualifiers other than volatile are accepted in the syntax but
4178 c_parser_asm_statement (c_parser
*parser
)
4180 tree quals
, str
, outputs
, inputs
, clobbers
, ret
;
4182 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
4183 c_parser_consume_token (parser
);
4184 if (c_parser_next_token_is_keyword (parser
, RID_VOLATILE
))
4186 quals
= c_parser_peek_token (parser
)->value
;
4187 c_parser_consume_token (parser
);
4189 else if (c_parser_next_token_is_keyword (parser
, RID_CONST
)
4190 || c_parser_next_token_is_keyword (parser
, RID_RESTRICT
))
4192 warning (0, "%H%E qualifier ignored on asm",
4193 &c_parser_peek_token (parser
)->location
,
4194 c_parser_peek_token (parser
)->value
);
4196 c_parser_consume_token (parser
);
4200 /* ??? Follow the C++ parser rather than using the
4201 lex_untranslated_string kludge. */
4202 parser
->lex_untranslated_string
= true;
4203 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4205 parser
->lex_untranslated_string
= false;
4208 str
= c_parser_asm_string_literal (parser
);
4209 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4212 outputs
= NULL_TREE
;
4214 clobbers
= NULL_TREE
;
4217 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%> or %<)%>"))
4219 parser
->lex_untranslated_string
= false;
4220 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4224 /* Parse outputs. */
4225 if (c_parser_next_token_is (parser
, CPP_COLON
)
4226 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4227 outputs
= NULL_TREE
;
4229 outputs
= c_parser_asm_operands (parser
, false);
4230 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4233 clobbers
= NULL_TREE
;
4236 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%> or %<)%>"))
4238 parser
->lex_untranslated_string
= false;
4239 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4243 if (c_parser_next_token_is (parser
, CPP_COLON
)
4244 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4247 inputs
= c_parser_asm_operands (parser
, true);
4248 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4250 clobbers
= NULL_TREE
;
4253 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%> or %<)%>"))
4255 parser
->lex_untranslated_string
= false;
4256 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4259 /* Parse clobbers. */
4260 clobbers
= c_parser_asm_clobbers (parser
);
4262 parser
->lex_untranslated_string
= false;
4263 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
4265 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4268 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
4269 c_parser_skip_to_end_of_block_or_statement (parser
);
4270 ret
= build_asm_stmt (quals
, build_asm_expr (str
, outputs
, inputs
,
4275 /* Parse asm operands, a GNU extension. If CONVERT_P (for inputs but
4276 not outputs), apply the default conversion of functions and arrays
4281 asm-operands , asm-operand
4284 asm-string-literal ( expression )
4285 [ identifier ] asm-string-literal ( expression )
4289 c_parser_asm_operands (c_parser
*parser
, bool convert_p
)
4291 tree list
= NULL_TREE
;
4296 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
4298 c_parser_consume_token (parser
);
4299 if (c_parser_next_token_is (parser
, CPP_NAME
))
4301 tree id
= c_parser_peek_token (parser
)->value
;
4302 c_parser_consume_token (parser
);
4303 name
= build_string (IDENTIFIER_LENGTH (id
),
4304 IDENTIFIER_POINTER (id
));
4308 c_parser_error (parser
, "expected identifier");
4309 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
4312 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4317 str
= c_parser_asm_string_literal (parser
);
4318 if (str
== NULL_TREE
)
4320 parser
->lex_untranslated_string
= false;
4321 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4323 parser
->lex_untranslated_string
= true;
4326 expr
= c_parser_expression (parser
);
4328 expr
= default_function_array_conversion (expr
);
4329 parser
->lex_untranslated_string
= true;
4330 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
4332 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4335 list
= chainon (list
, build_tree_list (build_tree_list (name
, str
),
4337 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4338 c_parser_consume_token (parser
);
4345 /* Parse asm clobbers, a GNU extension.
4349 asm-clobbers , asm-string-literal
4353 c_parser_asm_clobbers (c_parser
*parser
)
4355 tree list
= NULL_TREE
;
4358 tree str
= c_parser_asm_string_literal (parser
);
4360 list
= tree_cons (NULL_TREE
, str
, list
);
4363 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4364 c_parser_consume_token (parser
);
4371 /* Parse an expression other than a compound expression; that is, an
4372 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
4373 NULL then it is an Objective-C message expression which is the
4374 primary-expression starting the expression as an initializer.
4376 assignment-expression:
4377 conditional-expression
4378 unary-expression assignment-operator assignment-expression
4380 assignment-operator: one of
4381 = *= /= %= += -= <<= >>= &= ^= |=
4383 In GNU C we accept any conditional expression on the LHS and
4384 diagnose the invalid lvalue rather than producing a syntax
4387 static struct c_expr
4388 c_parser_expr_no_commas (c_parser
*parser
, struct c_expr
*after
)
4390 struct c_expr lhs
, rhs
, ret
;
4391 enum tree_code code
;
4392 gcc_assert (!after
|| c_dialect_objc ());
4393 lhs
= c_parser_conditional_expression (parser
, after
);
4394 switch (c_parser_peek_token (parser
)->type
)
4403 code
= TRUNC_DIV_EXPR
;
4406 code
= TRUNC_MOD_EXPR
;
4421 code
= BIT_AND_EXPR
;
4424 code
= BIT_XOR_EXPR
;
4427 code
= BIT_IOR_EXPR
;
4432 c_parser_consume_token (parser
);
4433 rhs
= c_parser_expr_no_commas (parser
, NULL
);
4434 rhs
= default_function_array_conversion (rhs
);
4435 ret
.value
= build_modify_expr (lhs
.value
, code
, rhs
.value
);
4436 if (code
== NOP_EXPR
)
4437 ret
.original_code
= MODIFY_EXPR
;
4440 TREE_NO_WARNING (ret
.value
) = 1;
4441 ret
.original_code
= ERROR_MARK
;
4446 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
4447 is not NULL then it is an Objective-C message expression which is
4448 the primary-expression starting the expression as an initializer.
4450 conditional-expression:
4451 logical-OR-expression
4452 logical-OR-expression ? expression : conditional-expression
4456 conditional-expression:
4457 logical-OR-expression ? : conditional-expression
4460 static struct c_expr
4461 c_parser_conditional_expression (c_parser
*parser
, struct c_expr
*after
)
4463 struct c_expr cond
, exp1
, exp2
, ret
;
4464 gcc_assert (!after
|| c_dialect_objc ());
4465 cond
= c_parser_binary_expression (parser
, after
);
4466 if (c_parser_next_token_is_not (parser
, CPP_QUERY
))
4468 cond
= default_function_array_conversion (cond
);
4469 c_parser_consume_token (parser
);
4470 if (c_parser_next_token_is (parser
, CPP_COLON
))
4473 pedwarn ("%HISO C forbids omitting the middle term of a ?: expression",
4474 &c_parser_peek_token (parser
)->location
);
4475 /* Make sure first operand is calculated only once. */
4476 exp1
.value
= save_expr (default_conversion (cond
.value
));
4477 cond
.value
= c_objc_common_truthvalue_conversion (exp1
.value
);
4478 skip_evaluation
+= cond
.value
== truthvalue_true_node
;
4483 = c_objc_common_truthvalue_conversion
4484 (default_conversion (cond
.value
));
4485 skip_evaluation
+= cond
.value
== truthvalue_false_node
;
4486 exp1
= c_parser_expression_conv (parser
);
4487 skip_evaluation
+= ((cond
.value
== truthvalue_true_node
)
4488 - (cond
.value
== truthvalue_false_node
));
4490 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4492 skip_evaluation
-= cond
.value
== truthvalue_true_node
;
4493 ret
.value
= error_mark_node
;
4494 ret
.original_code
= ERROR_MARK
;
4497 exp2
= c_parser_conditional_expression (parser
, NULL
);
4498 exp2
= default_function_array_conversion (exp2
);
4499 skip_evaluation
-= cond
.value
== truthvalue_true_node
;
4500 ret
.value
= build_conditional_expr (cond
.value
, exp1
.value
, exp2
.value
);
4501 ret
.original_code
= ERROR_MARK
;
4505 /* Parse a binary expression; that is, a logical-OR-expression (C90
4506 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
4507 an Objective-C message expression which is the primary-expression
4508 starting the expression as an initializer.
4510 multiplicative-expression:
4512 multiplicative-expression * cast-expression
4513 multiplicative-expression / cast-expression
4514 multiplicative-expression % cast-expression
4516 additive-expression:
4517 multiplicative-expression
4518 additive-expression + multiplicative-expression
4519 additive-expression - multiplicative-expression
4523 shift-expression << additive-expression
4524 shift-expression >> additive-expression
4526 relational-expression:
4528 relational-expression < shift-expression
4529 relational-expression > shift-expression
4530 relational-expression <= shift-expression
4531 relational-expression >= shift-expression
4533 equality-expression:
4534 relational-expression
4535 equality-expression == relational-expression
4536 equality-expression != relational-expression
4540 AND-expression & equality-expression
4542 exclusive-OR-expression:
4544 exclusive-OR-expression ^ AND-expression
4546 inclusive-OR-expression:
4547 exclusive-OR-expression
4548 inclusive-OR-expression | exclusive-OR-expression
4550 logical-AND-expression:
4551 inclusive-OR-expression
4552 logical-AND-expression && inclusive-OR-expression
4554 logical-OR-expression:
4555 logical-AND-expression
4556 logical-OR-expression || logical-AND-expression
4559 static struct c_expr
4560 c_parser_binary_expression (c_parser
*parser
, struct c_expr
*after
)
4562 /* A binary expression is parsed using operator-precedence parsing,
4563 with the operands being cast expressions. All the binary
4564 operators are left-associative. Thus a binary expression is of
4567 E0 op1 E1 op2 E2 ...
4569 which we represent on a stack. On the stack, the precedence
4570 levels are strictly increasing. When a new operator is
4571 encountered of higher precedence than that at the top of the
4572 stack, it is pushed; its LHS is the top expression, and its RHS
4573 is everything parsed until it is popped. When a new operator is
4574 encountered with precedence less than or equal to that at the top
4575 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
4576 by the result of the operation until the operator at the top of
4577 the stack has lower precedence than the new operator or there is
4578 only one element on the stack; then the top expression is the LHS
4579 of the new operator. In the case of logical AND and OR
4580 expressions, we also need to adjust skip_evaluation as
4581 appropriate when the operators are pushed and popped. */
4583 /* The precedence levels, where 0 is a dummy lowest level used for
4584 the bottom of the stack. */
4600 /* The expression at this stack level. */
4602 /* The precedence of the operator on its left, PREC_NONE at the
4603 bottom of the stack. */
4605 /* The operation on its left. */
4611 switch (stack[sp].op) \
4613 case TRUTH_ANDIF_EXPR: \
4614 skip_evaluation -= stack[sp - 1].expr.value == truthvalue_false_node; \
4616 case TRUTH_ORIF_EXPR: \
4617 skip_evaluation -= stack[sp - 1].expr.value == truthvalue_true_node; \
4622 stack[sp - 1].expr \
4623 = default_function_array_conversion (stack[sp - 1].expr); \
4625 = default_function_array_conversion (stack[sp].expr); \
4626 stack[sp - 1].expr = parser_build_binary_op (stack[sp].op, \
4627 stack[sp - 1].expr, \
4631 gcc_assert (!after
|| c_dialect_objc ());
4632 stack
[0].expr
= c_parser_cast_expression (parser
, after
);
4633 stack
[0].prec
= PREC_NONE
;
4638 enum tree_code ocode
;
4641 switch (c_parser_peek_token (parser
)->type
)
4649 ocode
= TRUNC_DIV_EXPR
;
4653 ocode
= TRUNC_MOD_EXPR
;
4665 ocode
= LSHIFT_EXPR
;
4669 ocode
= RSHIFT_EXPR
;
4683 case CPP_GREATER_EQ
:
4696 oprec
= PREC_BITAND
;
4697 ocode
= BIT_AND_EXPR
;
4700 oprec
= PREC_BITXOR
;
4701 ocode
= BIT_XOR_EXPR
;
4705 ocode
= BIT_IOR_EXPR
;
4708 oprec
= PREC_LOGAND
;
4709 ocode
= TRUTH_ANDIF_EXPR
;
4713 ocode
= TRUTH_ORIF_EXPR
;
4716 /* Not a binary operator, so end of the binary
4720 c_parser_consume_token (parser
);
4721 while (oprec
<= stack
[sp
].prec
)
4725 case TRUTH_ANDIF_EXPR
:
4727 = default_function_array_conversion (stack
[sp
].expr
);
4728 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
4729 (default_conversion (stack
[sp
].expr
.value
));
4730 skip_evaluation
+= stack
[sp
].expr
.value
== truthvalue_false_node
;
4732 case TRUTH_ORIF_EXPR
:
4734 = default_function_array_conversion (stack
[sp
].expr
);
4735 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
4736 (default_conversion (stack
[sp
].expr
.value
));
4737 skip_evaluation
+= stack
[sp
].expr
.value
== truthvalue_true_node
;
4743 stack
[sp
].expr
= c_parser_cast_expression (parser
, NULL
);
4744 stack
[sp
].prec
= oprec
;
4745 stack
[sp
].op
= ocode
;
4750 return stack
[0].expr
;
4754 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
4755 NULL then it is an Objective-C message expression which is the
4756 primary-expression starting the expression as an initializer.
4760 ( type-name ) unary-expression
4763 static struct c_expr
4764 c_parser_cast_expression (c_parser
*parser
, struct c_expr
*after
)
4766 gcc_assert (!after
|| c_dialect_objc ());
4768 return c_parser_postfix_expression_after_primary (parser
, *after
);
4769 /* If the expression begins with a parenthesized type name, it may
4770 be either a cast or a compound literal; we need to see whether
4771 the next character is '{' to tell the difference. If not, it is
4772 an unary expression. */
4773 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
4774 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
4776 struct c_type_name
*type_name
;
4779 c_parser_consume_token (parser
);
4780 type_name
= c_parser_type_name (parser
);
4781 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4782 if (type_name
== NULL
)
4784 ret
.value
= error_mark_node
;
4785 ret
.original_code
= ERROR_MARK
;
4789 /* Save casted types in the function's used types hash table. */
4790 used_types_insert (type_name
->specs
->type
);
4792 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4793 return c_parser_postfix_expression_after_paren_type (parser
,
4795 expr
= c_parser_cast_expression (parser
, NULL
);
4796 expr
= default_function_array_conversion (expr
);
4797 ret
.value
= c_cast_expr (type_name
, expr
.value
);
4798 ret
.original_code
= ERROR_MARK
;
4802 return c_parser_unary_expression (parser
);
4805 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
4811 unary-operator cast-expression
4812 sizeof unary-expression
4813 sizeof ( type-name )
4815 unary-operator: one of
4821 __alignof__ unary-expression
4822 __alignof__ ( type-name )
4825 unary-operator: one of
4826 __extension__ __real__ __imag__
4828 In addition, the GNU syntax treats ++ and -- as unary operators, so
4829 they may be applied to cast expressions with errors for non-lvalues
4832 static struct c_expr
4833 c_parser_unary_expression (c_parser
*parser
)
4836 struct c_expr ret
, op
;
4837 switch (c_parser_peek_token (parser
)->type
)
4840 c_parser_consume_token (parser
);
4841 op
= c_parser_cast_expression (parser
, NULL
);
4842 op
= default_function_array_conversion (op
);
4843 return parser_build_unary_op (PREINCREMENT_EXPR
, op
);
4844 case CPP_MINUS_MINUS
:
4845 c_parser_consume_token (parser
);
4846 op
= c_parser_cast_expression (parser
, NULL
);
4847 op
= default_function_array_conversion (op
);
4848 return parser_build_unary_op (PREDECREMENT_EXPR
, op
);
4850 c_parser_consume_token (parser
);
4851 return parser_build_unary_op (ADDR_EXPR
,
4852 c_parser_cast_expression (parser
, NULL
));
4854 c_parser_consume_token (parser
);
4855 op
= c_parser_cast_expression (parser
, NULL
);
4856 op
= default_function_array_conversion (op
);
4857 ret
.value
= build_indirect_ref (op
.value
, "unary *");
4858 ret
.original_code
= ERROR_MARK
;
4861 if (!c_dialect_objc () && !in_system_header
)
4862 warning (OPT_Wtraditional
,
4863 "%Htraditional C rejects the unary plus operator",
4864 &c_parser_peek_token (parser
)->location
);
4865 c_parser_consume_token (parser
);
4866 op
= c_parser_cast_expression (parser
, NULL
);
4867 op
= default_function_array_conversion (op
);
4868 return parser_build_unary_op (CONVERT_EXPR
, op
);
4870 c_parser_consume_token (parser
);
4871 op
= c_parser_cast_expression (parser
, NULL
);
4872 op
= default_function_array_conversion (op
);
4873 return parser_build_unary_op (NEGATE_EXPR
, op
);
4875 c_parser_consume_token (parser
);
4876 op
= c_parser_cast_expression (parser
, NULL
);
4877 op
= default_function_array_conversion (op
);
4878 return parser_build_unary_op (BIT_NOT_EXPR
, op
);
4880 c_parser_consume_token (parser
);
4881 op
= c_parser_cast_expression (parser
, NULL
);
4882 op
= default_function_array_conversion (op
);
4883 return parser_build_unary_op (TRUTH_NOT_EXPR
, op
);
4885 /* Refer to the address of a label as a pointer. */
4886 c_parser_consume_token (parser
);
4887 if (c_parser_next_token_is (parser
, CPP_NAME
))
4889 ret
.value
= finish_label_address_expr
4890 (c_parser_peek_token (parser
)->value
);
4891 c_parser_consume_token (parser
);
4895 c_parser_error (parser
, "expected identifier");
4896 ret
.value
= error_mark_node
;
4898 ret
.original_code
= ERROR_MARK
;
4901 switch (c_parser_peek_token (parser
)->keyword
)
4904 return c_parser_sizeof_expression (parser
);
4906 return c_parser_alignof_expression (parser
);
4908 c_parser_consume_token (parser
);
4909 ext
= disable_extension_diagnostics ();
4910 ret
= c_parser_cast_expression (parser
, NULL
);
4911 restore_extension_diagnostics (ext
);
4914 c_parser_consume_token (parser
);
4915 op
= c_parser_cast_expression (parser
, NULL
);
4916 op
= default_function_array_conversion (op
);
4917 return parser_build_unary_op (REALPART_EXPR
, op
);
4919 c_parser_consume_token (parser
);
4920 op
= c_parser_cast_expression (parser
, NULL
);
4921 op
= default_function_array_conversion (op
);
4922 return parser_build_unary_op (IMAGPART_EXPR
, op
);
4924 return c_parser_postfix_expression (parser
);
4927 return c_parser_postfix_expression (parser
);
4931 /* Parse a sizeof expression. */
4933 static struct c_expr
4934 c_parser_sizeof_expression (c_parser
*parser
)
4937 location_t expr_loc
;
4938 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SIZEOF
));
4939 c_parser_consume_token (parser
);
4942 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
4943 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
4945 /* Either sizeof ( type-name ) or sizeof unary-expression
4946 starting with a compound literal. */
4947 struct c_type_name
*type_name
;
4948 c_parser_consume_token (parser
);
4949 expr_loc
= c_parser_peek_token (parser
)->location
;
4950 type_name
= c_parser_type_name (parser
);
4951 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4952 if (type_name
== NULL
)
4957 ret
.value
= error_mark_node
;
4958 ret
.original_code
= ERROR_MARK
;
4961 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4963 expr
= c_parser_postfix_expression_after_paren_type (parser
,
4967 /* sizeof ( type-name ). */
4970 if (type_name
->declarator
->kind
== cdk_array
4971 && type_name
->declarator
->u
.array
.vla_unspec_p
)
4974 error ("%H%<[*]%> not allowed in other than a declaration",
4977 return c_expr_sizeof_type (type_name
);
4981 expr_loc
= c_parser_peek_token (parser
)->location
;
4982 expr
= c_parser_unary_expression (parser
);
4986 if (TREE_CODE (expr
.value
) == COMPONENT_REF
4987 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
4988 error ("%H%<sizeof%> applied to a bit-field", &expr_loc
);
4989 return c_expr_sizeof_expr (expr
);
4993 /* Parse an alignof expression. */
4995 static struct c_expr
4996 c_parser_alignof_expression (c_parser
*parser
)
4999 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNOF
));
5000 c_parser_consume_token (parser
);
5003 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
5004 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
5006 /* Either __alignof__ ( type-name ) or __alignof__
5007 unary-expression starting with a compound literal. */
5008 struct c_type_name
*type_name
;
5010 c_parser_consume_token (parser
);
5011 type_name
= c_parser_type_name (parser
);
5012 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5013 if (type_name
== NULL
)
5018 ret
.value
= error_mark_node
;
5019 ret
.original_code
= ERROR_MARK
;
5022 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5024 expr
= c_parser_postfix_expression_after_paren_type (parser
,
5028 /* alignof ( type-name ). */
5031 ret
.value
= c_alignof (groktypename (type_name
));
5032 ret
.original_code
= ERROR_MARK
;
5038 expr
= c_parser_unary_expression (parser
);
5042 ret
.value
= c_alignof_expr (expr
.value
);
5043 ret
.original_code
= ERROR_MARK
;
5048 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
5052 postfix-expression [ expression ]
5053 postfix-expression ( argument-expression-list[opt] )
5054 postfix-expression . identifier
5055 postfix-expression -> identifier
5056 postfix-expression ++
5057 postfix-expression --
5058 ( type-name ) { initializer-list }
5059 ( type-name ) { initializer-list , }
5061 argument-expression-list:
5063 argument-expression-list , argument-expression
5075 (treated as a keyword in GNU C)
5078 ( compound-statement )
5079 __builtin_va_arg ( assignment-expression , type-name )
5080 __builtin_offsetof ( type-name , offsetof-member-designator )
5081 __builtin_choose_expr ( assignment-expression ,
5082 assignment-expression ,
5083 assignment-expression )
5084 __builtin_types_compatible_p ( type-name , type-name )
5086 offsetof-member-designator:
5088 offsetof-member-designator . identifier
5089 offsetof-member-designator [ expression ]
5094 [ objc-receiver objc-message-args ]
5095 @selector ( objc-selector-arg )
5096 @protocol ( identifier )
5097 @encode ( type-name )
5101 static struct c_expr
5102 c_parser_postfix_expression (c_parser
*parser
)
5104 struct c_expr expr
, e1
, e2
, e3
;
5105 struct c_type_name
*t1
, *t2
;
5107 switch (c_parser_peek_token (parser
)->type
)
5112 expr
.value
= c_parser_peek_token (parser
)->value
;
5113 expr
.original_code
= ERROR_MARK
;
5114 c_parser_consume_token (parser
);
5118 expr
.value
= c_parser_peek_token (parser
)->value
;
5119 expr
.original_code
= STRING_CST
;
5120 c_parser_consume_token (parser
);
5122 case CPP_OBJC_STRING
:
5123 gcc_assert (c_dialect_objc ());
5125 = objc_build_string_object (c_parser_peek_token (parser
)->value
);
5126 expr
.original_code
= ERROR_MARK
;
5127 c_parser_consume_token (parser
);
5130 if (c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
5132 c_parser_error (parser
, "expected expression");
5133 expr
.value
= error_mark_node
;
5134 expr
.original_code
= ERROR_MARK
;
5138 tree id
= c_parser_peek_token (parser
)->value
;
5139 location_t loc
= c_parser_peek_token (parser
)->location
;
5140 c_parser_consume_token (parser
);
5141 expr
.value
= build_external_ref (id
,
5142 (c_parser_peek_token (parser
)->type
5143 == CPP_OPEN_PAREN
), loc
);
5144 expr
.original_code
= ERROR_MARK
;
5147 case CPP_OPEN_PAREN
:
5148 /* A parenthesized expression, statement expression or compound
5150 if (c_parser_peek_2nd_token (parser
)->type
== CPP_OPEN_BRACE
)
5152 /* A statement expression. */
5154 location_t here
= c_parser_peek_token (parser
)->location
;
5155 c_parser_consume_token (parser
);
5156 c_parser_consume_token (parser
);
5157 if (cur_stmt_list
== NULL
)
5159 error ("%Hbraced-group within expression allowed "
5160 "only inside a function", &here
);
5161 parser
->error
= true;
5162 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
5163 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5164 expr
.value
= error_mark_node
;
5165 expr
.original_code
= ERROR_MARK
;
5168 stmt
= c_begin_stmt_expr ();
5169 c_parser_compound_statement_nostart (parser
);
5170 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5173 pedwarn ("%HISO C forbids braced-groups within expressions",
5175 expr
.value
= c_finish_stmt_expr (stmt
);
5176 expr
.original_code
= ERROR_MARK
;
5178 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
5180 /* A compound literal. ??? Can we actually get here rather
5181 than going directly to
5182 c_parser_postfix_expression_after_paren_type from
5184 struct c_type_name
*type_name
;
5185 c_parser_consume_token (parser
);
5186 type_name
= c_parser_type_name (parser
);
5187 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5189 if (type_name
== NULL
)
5191 expr
.value
= error_mark_node
;
5192 expr
.original_code
= ERROR_MARK
;
5195 expr
= c_parser_postfix_expression_after_paren_type (parser
,
5200 /* A parenthesized expression. */
5201 c_parser_consume_token (parser
);
5202 expr
= c_parser_expression (parser
);
5203 if (TREE_CODE (expr
.value
) == MODIFY_EXPR
)
5204 TREE_NO_WARNING (expr
.value
) = 1;
5205 expr
.original_code
= ERROR_MARK
;
5206 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5211 switch (c_parser_peek_token (parser
)->keyword
)
5213 case RID_FUNCTION_NAME
:
5214 case RID_PRETTY_FUNCTION_NAME
:
5215 case RID_C99_FUNCTION_NAME
:
5216 expr
.value
= fname_decl (c_parser_peek_token (parser
)->keyword
,
5217 c_parser_peek_token (parser
)->value
);
5218 expr
.original_code
= ERROR_MARK
;
5219 c_parser_consume_token (parser
);
5222 c_parser_consume_token (parser
);
5223 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5225 expr
.value
= error_mark_node
;
5226 expr
.original_code
= ERROR_MARK
;
5229 e1
= c_parser_expr_no_commas (parser
, NULL
);
5230 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5232 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5233 expr
.value
= error_mark_node
;
5234 expr
.original_code
= ERROR_MARK
;
5237 t1
= c_parser_type_name (parser
);
5238 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5242 expr
.value
= error_mark_node
;
5243 expr
.original_code
= ERROR_MARK
;
5247 expr
.value
= build_va_arg (e1
.value
, groktypename (t1
));
5248 expr
.original_code
= ERROR_MARK
;
5252 c_parser_consume_token (parser
);
5253 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5255 expr
.value
= error_mark_node
;
5256 expr
.original_code
= ERROR_MARK
;
5259 t1
= c_parser_type_name (parser
);
5262 expr
.value
= error_mark_node
;
5263 expr
.original_code
= ERROR_MARK
;
5266 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5268 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5269 expr
.value
= error_mark_node
;
5270 expr
.original_code
= ERROR_MARK
;
5274 tree type
= groktypename (t1
);
5276 if (type
== error_mark_node
)
5277 offsetof_ref
= error_mark_node
;
5279 offsetof_ref
= build1 (INDIRECT_REF
, type
, null_pointer_node
);
5280 /* Parse the second argument to __builtin_offsetof. We
5281 must have one identifier, and beyond that we want to
5282 accept sub structure and sub array references. */
5283 if (c_parser_next_token_is (parser
, CPP_NAME
))
5285 offsetof_ref
= build_component_ref
5286 (offsetof_ref
, c_parser_peek_token (parser
)->value
);
5287 c_parser_consume_token (parser
);
5288 while (c_parser_next_token_is (parser
, CPP_DOT
)
5289 || c_parser_next_token_is (parser
,
5292 if (c_parser_next_token_is (parser
, CPP_DOT
))
5294 c_parser_consume_token (parser
);
5295 if (c_parser_next_token_is_not (parser
,
5298 c_parser_error (parser
, "expected identifier");
5301 offsetof_ref
= build_component_ref
5303 c_parser_peek_token (parser
)->value
);
5304 c_parser_consume_token (parser
);
5309 c_parser_consume_token (parser
);
5310 idx
= c_parser_expression (parser
).value
;
5311 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5313 offsetof_ref
= build_array_ref (offsetof_ref
, idx
);
5318 c_parser_error (parser
, "expected identifier");
5319 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5321 expr
.value
= fold_offsetof (offsetof_ref
, NULL_TREE
);
5322 expr
.original_code
= ERROR_MARK
;
5325 case RID_CHOOSE_EXPR
:
5326 c_parser_consume_token (parser
);
5327 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5329 expr
.value
= error_mark_node
;
5330 expr
.original_code
= ERROR_MARK
;
5333 loc
= c_parser_peek_token (parser
)->location
;
5334 e1
= c_parser_expr_no_commas (parser
, NULL
);
5335 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5337 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5338 expr
.value
= error_mark_node
;
5339 expr
.original_code
= ERROR_MARK
;
5342 e2
= c_parser_expr_no_commas (parser
, NULL
);
5343 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5345 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5346 expr
.value
= error_mark_node
;
5347 expr
.original_code
= ERROR_MARK
;
5350 e3
= c_parser_expr_no_commas (parser
, NULL
);
5351 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5356 c
= fold (e1
.value
);
5357 if (TREE_CODE (c
) != INTEGER_CST
)
5358 error ("%Hfirst argument to %<__builtin_choose_expr%> not"
5359 " a constant", &loc
);
5360 expr
= integer_zerop (c
) ? e3
: e2
;
5363 case RID_TYPES_COMPATIBLE_P
:
5364 c_parser_consume_token (parser
);
5365 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5367 expr
.value
= error_mark_node
;
5368 expr
.original_code
= ERROR_MARK
;
5371 t1
= c_parser_type_name (parser
);
5374 expr
.value
= error_mark_node
;
5375 expr
.original_code
= ERROR_MARK
;
5378 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5380 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5381 expr
.value
= error_mark_node
;
5382 expr
.original_code
= ERROR_MARK
;
5385 t2
= c_parser_type_name (parser
);
5388 expr
.value
= error_mark_node
;
5389 expr
.original_code
= ERROR_MARK
;
5392 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5397 e1
= TYPE_MAIN_VARIANT (groktypename (t1
));
5398 e2
= TYPE_MAIN_VARIANT (groktypename (t2
));
5400 expr
.value
= comptypes (e1
, e2
)
5401 ? build_int_cst (NULL_TREE
, 1)
5402 : build_int_cst (NULL_TREE
, 0);
5403 expr
.original_code
= ERROR_MARK
;
5406 case RID_AT_SELECTOR
:
5407 gcc_assert (c_dialect_objc ());
5408 c_parser_consume_token (parser
);
5409 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5411 expr
.value
= error_mark_node
;
5412 expr
.original_code
= ERROR_MARK
;
5416 tree sel
= c_parser_objc_selector_arg (parser
);
5417 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5419 expr
.value
= objc_build_selector_expr (sel
);
5420 expr
.original_code
= ERROR_MARK
;
5423 case RID_AT_PROTOCOL
:
5424 gcc_assert (c_dialect_objc ());
5425 c_parser_consume_token (parser
);
5426 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5428 expr
.value
= error_mark_node
;
5429 expr
.original_code
= ERROR_MARK
;
5432 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5434 c_parser_error (parser
, "expected identifier");
5435 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5436 expr
.value
= error_mark_node
;
5437 expr
.original_code
= ERROR_MARK
;
5441 tree id
= c_parser_peek_token (parser
)->value
;
5442 c_parser_consume_token (parser
);
5443 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5445 expr
.value
= objc_build_protocol_expr (id
);
5446 expr
.original_code
= ERROR_MARK
;
5450 /* Extension to support C-structures in the archiver. */
5451 gcc_assert (c_dialect_objc ());
5452 c_parser_consume_token (parser
);
5453 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5455 expr
.value
= error_mark_node
;
5456 expr
.original_code
= ERROR_MARK
;
5459 t1
= c_parser_type_name (parser
);
5462 expr
.value
= error_mark_node
;
5463 expr
.original_code
= ERROR_MARK
;
5464 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5467 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5470 tree type
= groktypename (t1
);
5471 expr
.value
= objc_build_encode_expr (type
);
5472 expr
.original_code
= ERROR_MARK
;
5476 c_parser_error (parser
, "expected expression");
5477 expr
.value
= error_mark_node
;
5478 expr
.original_code
= ERROR_MARK
;
5482 case CPP_OPEN_SQUARE
:
5483 if (c_dialect_objc ())
5485 tree receiver
, args
;
5486 c_parser_consume_token (parser
);
5487 receiver
= c_parser_objc_receiver (parser
);
5488 args
= c_parser_objc_message_args (parser
);
5489 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5491 expr
.value
= objc_build_message_expr (build_tree_list (receiver
,
5493 expr
.original_code
= ERROR_MARK
;
5496 /* Else fall through to report error. */
5498 c_parser_error (parser
, "expected expression");
5499 expr
.value
= error_mark_node
;
5500 expr
.original_code
= ERROR_MARK
;
5503 return c_parser_postfix_expression_after_primary (parser
, expr
);
5506 /* Parse a postfix expression after a parenthesized type name: the
5507 brace-enclosed initializer of a compound literal, possibly followed
5508 by some postfix operators. This is separate because it is not
5509 possible to tell until after the type name whether a cast
5510 expression has a cast or a compound literal, or whether the operand
5511 of sizeof is a parenthesized type name or starts with a compound
5514 static struct c_expr
5515 c_parser_postfix_expression_after_paren_type (c_parser
*parser
,
5516 struct c_type_name
*type_name
)
5521 location_t start_loc
;
5522 start_init (NULL_TREE
, NULL
, 0);
5523 type
= groktypename (type_name
);
5524 start_loc
= c_parser_peek_token (parser
)->location
;
5525 if (type
!= error_mark_node
&& C_TYPE_VARIABLE_SIZE (type
))
5527 error ("%Hcompound literal has variable size", &start_loc
);
5528 type
= error_mark_node
;
5530 init
= c_parser_braced_init (parser
, type
, false);
5532 maybe_warn_string_init (type
, init
);
5534 if (pedantic
&& !flag_isoc99
)
5535 pedwarn ("%HISO C90 forbids compound literals", &start_loc
);
5536 expr
.value
= build_compound_literal (type
, init
.value
);
5537 expr
.original_code
= ERROR_MARK
;
5538 return c_parser_postfix_expression_after_primary (parser
, expr
);
5541 /* Parse a postfix expression after the initial primary or compound
5542 literal; that is, parse a series of postfix operators. */
5544 static struct c_expr
5545 c_parser_postfix_expression_after_primary (c_parser
*parser
,
5548 tree ident
, idx
, exprlist
;
5551 switch (c_parser_peek_token (parser
)->type
)
5553 case CPP_OPEN_SQUARE
:
5554 /* Array reference. */
5555 c_parser_consume_token (parser
);
5556 idx
= c_parser_expression (parser
).value
;
5557 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5559 expr
.value
= build_array_ref (expr
.value
, idx
);
5560 expr
.original_code
= ERROR_MARK
;
5562 case CPP_OPEN_PAREN
:
5563 /* Function call. */
5564 c_parser_consume_token (parser
);
5565 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
5566 exprlist
= NULL_TREE
;
5568 exprlist
= c_parser_expr_list (parser
, true);
5569 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5571 expr
.value
= build_function_call (expr
.value
, exprlist
);
5572 expr
.original_code
= ERROR_MARK
;
5575 /* Structure element reference. */
5576 c_parser_consume_token (parser
);
5577 expr
= default_function_array_conversion (expr
);
5578 if (c_parser_next_token_is (parser
, CPP_NAME
))
5579 ident
= c_parser_peek_token (parser
)->value
;
5582 c_parser_error (parser
, "expected identifier");
5583 expr
.value
= error_mark_node
;
5584 expr
.original_code
= ERROR_MARK
;
5587 c_parser_consume_token (parser
);
5588 expr
.value
= build_component_ref (expr
.value
, ident
);
5589 expr
.original_code
= ERROR_MARK
;
5592 /* Structure element reference. */
5593 c_parser_consume_token (parser
);
5594 expr
= default_function_array_conversion (expr
);
5595 if (c_parser_next_token_is (parser
, CPP_NAME
))
5596 ident
= c_parser_peek_token (parser
)->value
;
5599 c_parser_error (parser
, "expected identifier");
5600 expr
.value
= error_mark_node
;
5601 expr
.original_code
= ERROR_MARK
;
5604 c_parser_consume_token (parser
);
5605 expr
.value
= build_component_ref (build_indirect_ref (expr
.value
,
5607 expr
.original_code
= ERROR_MARK
;
5610 /* Postincrement. */
5611 c_parser_consume_token (parser
);
5612 expr
= default_function_array_conversion (expr
);
5613 expr
.value
= build_unary_op (POSTINCREMENT_EXPR
, expr
.value
, 0);
5614 expr
.original_code
= ERROR_MARK
;
5616 case CPP_MINUS_MINUS
:
5617 /* Postdecrement. */
5618 c_parser_consume_token (parser
);
5619 expr
= default_function_array_conversion (expr
);
5620 expr
.value
= build_unary_op (POSTDECREMENT_EXPR
, expr
.value
, 0);
5621 expr
.original_code
= ERROR_MARK
;
5629 /* Parse an expression (C90 6.3.17, C99 6.5.17).
5632 assignment-expression
5633 expression , assignment-expression
5636 static struct c_expr
5637 c_parser_expression (c_parser
*parser
)
5640 expr
= c_parser_expr_no_commas (parser
, NULL
);
5641 while (c_parser_next_token_is (parser
, CPP_COMMA
))
5644 c_parser_consume_token (parser
);
5645 next
= c_parser_expr_no_commas (parser
, NULL
);
5646 next
= default_function_array_conversion (next
);
5647 expr
.value
= build_compound_expr (expr
.value
, next
.value
);
5648 expr
.original_code
= COMPOUND_EXPR
;
5653 /* Parse an expression and convert functions or arrays to
5656 static struct c_expr
5657 c_parser_expression_conv (c_parser
*parser
)
5660 expr
= c_parser_expression (parser
);
5661 expr
= default_function_array_conversion (expr
);
5665 /* Parse a non-empty list of expressions. If CONVERT_P, convert
5666 functions and arrays to pointers.
5669 assignment-expression
5670 nonempty-expr-list , assignment-expression
5674 c_parser_expr_list (c_parser
*parser
, bool convert_p
)
5678 expr
= c_parser_expr_no_commas (parser
, NULL
);
5680 expr
= default_function_array_conversion (expr
);
5681 ret
= cur
= build_tree_list (NULL_TREE
, expr
.value
);
5682 while (c_parser_next_token_is (parser
, CPP_COMMA
))
5684 c_parser_consume_token (parser
);
5685 expr
= c_parser_expr_no_commas (parser
, NULL
);
5687 expr
= default_function_array_conversion (expr
);
5688 cur
= TREE_CHAIN (cur
) = build_tree_list (NULL_TREE
, expr
.value
);
5694 /* Parse Objective-C-specific constructs. */
5696 /* Parse an objc-class-definition.
5698 objc-class-definition:
5699 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
5700 objc-class-instance-variables[opt] objc-methodprotolist @end
5701 @implementation identifier objc-superclass[opt]
5702 objc-class-instance-variables[opt]
5703 @interface identifier ( identifier ) objc-protocol-refs[opt]
5704 objc-methodprotolist @end
5705 @implementation identifier ( identifier )
5710 "@interface identifier (" must start "@interface identifier (
5711 identifier ) ...": objc-methodprotolist in the first production may
5712 not start with a parenthesized identifier as a declarator of a data
5713 definition with no declaration specifiers if the objc-superclass,
5714 objc-protocol-refs and objc-class-instance-variables are omitted. */
5717 c_parser_objc_class_definition (c_parser
*parser
)
5722 if (c_parser_next_token_is_keyword (parser
, RID_AT_INTERFACE
))
5724 else if (c_parser_next_token_is_keyword (parser
, RID_AT_IMPLEMENTATION
))
5728 c_parser_consume_token (parser
);
5729 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5731 c_parser_error (parser
, "expected identifier");
5734 id1
= c_parser_peek_token (parser
)->value
;
5735 c_parser_consume_token (parser
);
5736 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
5739 tree proto
= NULL_TREE
;
5740 c_parser_consume_token (parser
);
5741 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5743 c_parser_error (parser
, "expected identifier");
5744 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5747 id2
= c_parser_peek_token (parser
)->value
;
5748 c_parser_consume_token (parser
);
5749 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5752 objc_start_category_implementation (id1
, id2
);
5755 if (c_parser_next_token_is (parser
, CPP_LESS
))
5756 proto
= c_parser_objc_protocol_refs (parser
);
5757 objc_start_category_interface (id1
, id2
, proto
);
5758 c_parser_objc_methodprotolist (parser
);
5759 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
5760 objc_finish_interface ();
5763 if (c_parser_next_token_is (parser
, CPP_COLON
))
5765 c_parser_consume_token (parser
);
5766 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5768 c_parser_error (parser
, "expected identifier");
5771 superclass
= c_parser_peek_token (parser
)->value
;
5772 c_parser_consume_token (parser
);
5775 superclass
= NULL_TREE
;
5778 tree proto
= NULL_TREE
;
5779 if (c_parser_next_token_is (parser
, CPP_LESS
))
5780 proto
= c_parser_objc_protocol_refs (parser
);
5781 objc_start_class_interface (id1
, superclass
, proto
);
5784 objc_start_class_implementation (id1
, superclass
);
5785 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5786 c_parser_objc_class_instance_variables (parser
);
5789 objc_continue_interface ();
5790 c_parser_objc_methodprotolist (parser
);
5791 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
5792 objc_finish_interface ();
5796 objc_continue_implementation ();
5801 /* Parse objc-class-instance-variables.
5803 objc-class-instance-variables:
5804 { objc-instance-variable-decl-list[opt] }
5806 objc-instance-variable-decl-list:
5807 objc-visibility-spec
5808 objc-instance-variable-decl ;
5810 objc-instance-variable-decl-list objc-visibility-spec
5811 objc-instance-variable-decl-list objc-instance-variable-decl ;
5812 objc-instance-variable-decl-list ;
5814 objc-visibility-spec:
5819 objc-instance-variable-decl:
5824 c_parser_objc_class_instance_variables (c_parser
*parser
)
5826 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
5827 c_parser_consume_token (parser
);
5828 while (c_parser_next_token_is_not (parser
, CPP_EOF
))
5831 /* Parse any stray semicolon. */
5832 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5835 pedwarn ("%Hextra semicolon in struct or union specified",
5836 &c_parser_peek_token (parser
)->location
);
5837 c_parser_consume_token (parser
);
5840 /* Stop if at the end of the instance variables. */
5841 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
5843 c_parser_consume_token (parser
);
5846 /* Parse any objc-visibility-spec. */
5847 if (c_parser_next_token_is_keyword (parser
, RID_AT_PRIVATE
))
5849 c_parser_consume_token (parser
);
5850 objc_set_visibility (2);
5853 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROTECTED
))
5855 c_parser_consume_token (parser
);
5856 objc_set_visibility (0);
5859 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PUBLIC
))
5861 c_parser_consume_token (parser
);
5862 objc_set_visibility (1);
5865 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
5867 c_parser_pragma (parser
, pragma_external
);
5871 /* Parse some comma-separated declarations. */
5872 decls
= c_parser_struct_declaration (parser
);
5874 /* Comma-separated instance variables are chained together in
5875 reverse order; add them one by one. */
5876 tree ivar
= nreverse (decls
);
5877 for (; ivar
; ivar
= TREE_CHAIN (ivar
))
5878 objc_add_instance_variable (copy_node (ivar
));
5880 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5884 /* Parse an objc-class-declaration.
5886 objc-class-declaration:
5887 @class identifier-list ;
5891 c_parser_objc_class_declaration (c_parser
*parser
)
5893 tree list
= NULL_TREE
;
5894 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_CLASS
));
5895 c_parser_consume_token (parser
);
5896 /* Any identifiers, including those declared as type names, are OK
5901 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5903 c_parser_error (parser
, "expected identifier");
5906 id
= c_parser_peek_token (parser
)->value
;
5907 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
5908 c_parser_consume_token (parser
);
5909 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5910 c_parser_consume_token (parser
);
5914 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5915 objc_declare_class (list
);
5918 /* Parse an objc-alias-declaration.
5920 objc-alias-declaration:
5921 @compatibility_alias identifier identifier ;
5925 c_parser_objc_alias_declaration (c_parser
*parser
)
5928 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_ALIAS
));
5929 c_parser_consume_token (parser
);
5930 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5932 c_parser_error (parser
, "expected identifier");
5933 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
5936 id1
= c_parser_peek_token (parser
)->value
;
5937 c_parser_consume_token (parser
);
5938 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5940 c_parser_error (parser
, "expected identifier");
5941 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
5944 id2
= c_parser_peek_token (parser
)->value
;
5945 c_parser_consume_token (parser
);
5946 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5947 objc_declare_alias (id1
, id2
);
5950 /* Parse an objc-protocol-definition.
5952 objc-protocol-definition:
5953 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
5954 @protocol identifier-list ;
5956 "@protocol identifier ;" should be resolved as "@protocol
5957 identifier-list ;": objc-methodprotolist may not start with a
5958 semicolon in the first alternative if objc-protocol-refs are
5962 c_parser_objc_protocol_definition (c_parser
*parser
)
5964 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROTOCOL
));
5965 c_parser_consume_token (parser
);
5966 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5968 c_parser_error (parser
, "expected identifier");
5971 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
5972 || c_parser_peek_2nd_token (parser
)->type
== CPP_SEMICOLON
)
5974 tree list
= NULL_TREE
;
5975 /* Any identifiers, including those declared as type names, are
5980 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5982 c_parser_error (parser
, "expected identifier");
5985 id
= c_parser_peek_token (parser
)->value
;
5986 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
5987 c_parser_consume_token (parser
);
5988 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5989 c_parser_consume_token (parser
);
5993 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5994 objc_declare_protocols (list
);
5998 tree id
= c_parser_peek_token (parser
)->value
;
5999 tree proto
= NULL_TREE
;
6000 c_parser_consume_token (parser
);
6001 if (c_parser_next_token_is (parser
, CPP_LESS
))
6002 proto
= c_parser_objc_protocol_refs (parser
);
6003 parser
->objc_pq_context
= true;
6004 objc_start_protocol (id
, proto
);
6005 c_parser_objc_methodprotolist (parser
);
6006 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
6007 parser
->objc_pq_context
= false;
6008 objc_finish_interface ();
6012 /* Parse an objc-method-type.
6019 static enum tree_code
6020 c_parser_objc_method_type (c_parser
*parser
)
6022 switch (c_parser_peek_token (parser
)->type
)
6025 c_parser_consume_token (parser
);
6028 c_parser_consume_token (parser
);
6035 /* Parse an objc-method-definition.
6037 objc-method-definition:
6038 objc-method-type objc-method-decl ;[opt] compound-statement
6042 c_parser_objc_method_definition (c_parser
*parser
)
6044 enum tree_code type
= c_parser_objc_method_type (parser
);
6046 objc_set_method_type (type
);
6047 parser
->objc_pq_context
= true;
6048 decl
= c_parser_objc_method_decl (parser
);
6049 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
6051 c_parser_consume_token (parser
);
6053 pedwarn ("%Hextra semicolon in method definition specified",
6054 &c_parser_peek_token (parser
)->location
);
6056 if (!c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6058 c_parser_error (parser
, "expected %<{%>");
6061 parser
->objc_pq_context
= false;
6062 objc_start_method_definition (decl
);
6063 add_stmt (c_parser_compound_statement (parser
));
6064 objc_finish_method_definition (current_function_decl
);
6067 /* Parse an objc-methodprotolist.
6069 objc-methodprotolist:
6071 objc-methodprotolist objc-methodproto
6072 objc-methodprotolist declaration
6073 objc-methodprotolist ;
6075 The declaration is a data definition, which may be missing
6076 declaration specifiers under the same rules and diagnostics as
6077 other data definitions outside functions, and the stray semicolon
6078 is diagnosed the same way as a stray semicolon outside a
6082 c_parser_objc_methodprotolist (c_parser
*parser
)
6086 /* The list is terminated by @end. */
6087 switch (c_parser_peek_token (parser
)->type
)
6091 pedwarn ("%HISO C does not allow extra %<;%> "
6092 "outside of a function",
6093 &c_parser_peek_token (parser
)->location
);
6094 c_parser_consume_token (parser
);
6098 c_parser_objc_methodproto (parser
);
6101 c_parser_pragma (parser
, pragma_external
);
6106 if (c_parser_next_token_is_keyword (parser
, RID_AT_END
))
6108 c_parser_declaration_or_fndef (parser
, false, true, false, true);
6114 /* Parse an objc-methodproto.
6117 objc-method-type objc-method-decl ;
6121 c_parser_objc_methodproto (c_parser
*parser
)
6123 enum tree_code type
= c_parser_objc_method_type (parser
);
6125 objc_set_method_type (type
);
6126 /* Remember protocol qualifiers in prototypes. */
6127 parser
->objc_pq_context
= true;
6128 decl
= c_parser_objc_method_decl (parser
);
6129 /* Forget protocol qualifiers here. */
6130 parser
->objc_pq_context
= false;
6131 objc_add_method_declaration (decl
);
6132 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
6135 /* Parse an objc-method-decl.
6138 ( objc-type-name ) objc-selector
6140 ( objc-type-name ) objc-keyword-selector objc-optparmlist
6141 objc-keyword-selector objc-optparmlist
6143 objc-keyword-selector:
6145 objc-keyword-selector objc-keyword-decl
6148 objc-selector : ( objc-type-name ) identifier
6149 objc-selector : identifier
6150 : ( objc-type-name ) identifier
6154 objc-optparms objc-optellipsis
6158 objc-opt-parms , parameter-declaration
6166 c_parser_objc_method_decl (c_parser
*parser
)
6168 tree type
= NULL_TREE
;
6170 tree parms
= NULL_TREE
;
6171 bool ellipsis
= false;
6173 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
6175 c_parser_consume_token (parser
);
6176 type
= c_parser_objc_type_name (parser
);
6177 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6179 sel
= c_parser_objc_selector (parser
);
6180 /* If there is no selector, or a colon follows, we have an
6181 objc-keyword-selector. If there is a selector, and a colon does
6182 not follow, that selector ends the objc-method-decl. */
6183 if (!sel
|| c_parser_next_token_is (parser
, CPP_COLON
))
6186 tree list
= NULL_TREE
;
6189 tree atype
= NULL_TREE
, id
, keyworddecl
;
6190 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6192 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
6194 c_parser_consume_token (parser
);
6195 atype
= c_parser_objc_type_name (parser
);
6196 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6199 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6201 c_parser_error (parser
, "expected identifier");
6202 return error_mark_node
;
6204 id
= c_parser_peek_token (parser
)->value
;
6205 c_parser_consume_token (parser
);
6206 keyworddecl
= objc_build_keyword_decl (tsel
, atype
, id
);
6207 list
= chainon (list
, keyworddecl
);
6208 tsel
= c_parser_objc_selector (parser
);
6209 if (!tsel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6212 /* Parse the optional parameter list. Optional Objective-C
6213 method parameters follow the C syntax, and may include '...'
6214 to denote a variable number of arguments. */
6215 parms
= make_node (TREE_LIST
);
6216 while (c_parser_next_token_is (parser
, CPP_COMMA
))
6218 struct c_parm
*parm
;
6219 c_parser_consume_token (parser
);
6220 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
6223 c_parser_consume_token (parser
);
6226 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
6229 parms
= chainon (parms
,
6230 build_tree_list (NULL_TREE
, grokparm (parm
)));
6234 return objc_build_method_signature (type
, sel
, parms
, ellipsis
);
6237 /* Parse an objc-type-name.
6240 objc-type-qualifiers[opt] type-name
6241 objc-type-qualifiers[opt]
6243 objc-type-qualifiers:
6245 objc-type-qualifiers objc-type-qualifier
6247 objc-type-qualifier: one of
6248 in out inout bycopy byref oneway
6252 c_parser_objc_type_name (c_parser
*parser
)
6254 tree quals
= NULL_TREE
;
6255 struct c_type_name
*typename
= NULL
;
6256 tree type
= NULL_TREE
;
6259 c_token
*token
= c_parser_peek_token (parser
);
6260 if (token
->type
== CPP_KEYWORD
6261 && (token
->keyword
== RID_IN
6262 || token
->keyword
== RID_OUT
6263 || token
->keyword
== RID_INOUT
6264 || token
->keyword
== RID_BYCOPY
6265 || token
->keyword
== RID_BYREF
6266 || token
->keyword
== RID_ONEWAY
))
6268 quals
= chainon (quals
, build_tree_list (NULL_TREE
, token
->value
));
6269 c_parser_consume_token (parser
);
6274 if (c_parser_next_token_starts_typename (parser
))
6275 typename
= c_parser_type_name (parser
);
6277 type
= groktypename (typename
);
6278 return build_tree_list (quals
, type
);
6281 /* Parse objc-protocol-refs.
6288 c_parser_objc_protocol_refs (c_parser
*parser
)
6290 tree list
= NULL_TREE
;
6291 gcc_assert (c_parser_next_token_is (parser
, CPP_LESS
));
6292 c_parser_consume_token (parser
);
6293 /* Any identifiers, including those declared as type names, are OK
6298 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6300 c_parser_error (parser
, "expected identifier");
6303 id
= c_parser_peek_token (parser
)->value
;
6304 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
6305 c_parser_consume_token (parser
);
6306 if (c_parser_next_token_is (parser
, CPP_COMMA
))
6307 c_parser_consume_token (parser
);
6311 c_parser_require (parser
, CPP_GREATER
, "expected %<>%>");
6315 /* Parse an objc-try-catch-statement.
6317 objc-try-catch-statement:
6318 @try compound-statement objc-catch-list[opt]
6319 @try compound-statement objc-catch-list[opt] @finally compound-statement
6322 @catch ( parameter-declaration ) compound-statement
6323 objc-catch-list @catch ( parameter-declaration ) compound-statement
6327 c_parser_objc_try_catch_statement (c_parser
*parser
)
6331 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_TRY
));
6332 c_parser_consume_token (parser
);
6333 loc
= c_parser_peek_token (parser
)->location
;
6334 stmt
= c_parser_compound_statement (parser
);
6335 objc_begin_try_stmt (loc
, stmt
);
6336 while (c_parser_next_token_is_keyword (parser
, RID_AT_CATCH
))
6338 struct c_parm
*parm
;
6339 c_parser_consume_token (parser
);
6340 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6342 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
6345 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6348 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6349 objc_begin_catch_clause (grokparm (parm
));
6350 if (c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
6351 c_parser_compound_statement_nostart (parser
);
6352 objc_finish_catch_clause ();
6354 if (c_parser_next_token_is_keyword (parser
, RID_AT_FINALLY
))
6358 c_parser_consume_token (parser
);
6359 finloc
= c_parser_peek_token (parser
)->location
;
6360 finstmt
= c_parser_compound_statement (parser
);
6361 objc_build_finally_clause (finloc
, finstmt
);
6363 objc_finish_try_stmt ();
6366 /* Parse an objc-synchronized-statement.
6368 objc-synchronized-statement:
6369 @synchronized ( expression ) compound-statement
6373 c_parser_objc_synchronized_statement (c_parser
*parser
)
6377 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNCHRONIZED
));
6378 c_parser_consume_token (parser
);
6379 loc
= c_parser_peek_token (parser
)->location
;
6380 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6382 expr
= c_parser_expression (parser
).value
;
6383 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6386 expr
= error_mark_node
;
6387 stmt
= c_parser_compound_statement (parser
);
6388 objc_build_synchronized (loc
, expr
, stmt
);
6391 /* Parse an objc-selector; return NULL_TREE without an error if the
6392 next token is not an objc-selector.
6397 enum struct union if else while do for switch case default
6398 break continue return goto asm sizeof typeof __alignof
6399 unsigned long const short volatile signed restrict _Complex
6400 in out inout bycopy byref oneway int char float double void _Bool
6402 ??? Why this selection of keywords but not, for example, storage
6403 class specifiers? */
6406 c_parser_objc_selector (c_parser
*parser
)
6408 c_token
*token
= c_parser_peek_token (parser
);
6409 tree value
= token
->value
;
6410 if (token
->type
== CPP_NAME
)
6412 c_parser_consume_token (parser
);
6415 if (token
->type
!= CPP_KEYWORD
)
6417 switch (token
->keyword
)
6458 c_parser_consume_token (parser
);
6465 /* Parse an objc-selector-arg.
6469 objc-keywordname-list
6471 objc-keywordname-list:
6473 objc-keywordname-list objc-keywordname
6481 c_parser_objc_selector_arg (c_parser
*parser
)
6483 tree sel
= c_parser_objc_selector (parser
);
6484 tree list
= NULL_TREE
;
6485 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6489 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6491 list
= chainon (list
, build_tree_list (sel
, NULL_TREE
));
6492 sel
= c_parser_objc_selector (parser
);
6493 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6499 /* Parse an objc-receiver.
6508 c_parser_objc_receiver (c_parser
*parser
)
6510 if (c_parser_peek_token (parser
)->type
== CPP_NAME
6511 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
6512 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
6514 tree id
= c_parser_peek_token (parser
)->value
;
6515 c_parser_consume_token (parser
);
6516 return objc_get_class_reference (id
);
6518 return c_parser_expression (parser
).value
;
6521 /* Parse objc-message-args.
6525 objc-keywordarg-list
6527 objc-keywordarg-list:
6529 objc-keywordarg-list objc-keywordarg
6532 objc-selector : objc-keywordexpr
6537 c_parser_objc_message_args (c_parser
*parser
)
6539 tree sel
= c_parser_objc_selector (parser
);
6540 tree list
= NULL_TREE
;
6541 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6546 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6548 keywordexpr
= c_parser_objc_keywordexpr (parser
);
6549 list
= chainon (list
, build_tree_list (sel
, keywordexpr
));
6550 sel
= c_parser_objc_selector (parser
);
6551 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6557 /* Parse an objc-keywordexpr.
6564 c_parser_objc_keywordexpr (c_parser
*parser
)
6566 tree list
= c_parser_expr_list (parser
, true);
6567 if (TREE_CHAIN (list
) == NULL_TREE
)
6569 /* Just return the expression, remove a level of
6571 return TREE_VALUE (list
);
6575 /* We have a comma expression, we will collapse later. */
6581 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
6582 should be considered, statements. ALLOW_STMT is true if we're within
6583 the context of a function and such pragmas are to be allowed. Returns
6584 true if we actually parsed such a pragma. */
6587 c_parser_pragma (c_parser
*parser
, enum pragma_context context
)
6591 id
= c_parser_peek_token (parser
)->pragma_kind
;
6592 gcc_assert (id
!= PRAGMA_NONE
);
6596 case PRAGMA_OMP_BARRIER
:
6597 if (context
!= pragma_compound
)
6599 if (context
== pragma_stmt
)
6600 c_parser_error (parser
, "%<#pragma omp barrier%> may only be "
6601 "used in compound statements");
6604 c_parser_omp_barrier (parser
);
6607 case PRAGMA_OMP_FLUSH
:
6608 if (context
!= pragma_compound
)
6610 if (context
== pragma_stmt
)
6611 c_parser_error (parser
, "%<#pragma omp flush%> may only be "
6612 "used in compound statements");
6615 c_parser_omp_flush (parser
);
6618 case PRAGMA_OMP_THREADPRIVATE
:
6619 c_parser_omp_threadprivate (parser
);
6622 case PRAGMA_OMP_SECTION
:
6623 error ("%H%<#pragma omp section%> may only be used in "
6624 "%<#pragma omp sections%> construct",
6625 &c_parser_peek_token (parser
)->location
);
6626 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
6629 case PRAGMA_GCC_PCH_PREPROCESS
:
6630 c_parser_error (parser
, "%<#pragma GCC pch_preprocess%> must be first");
6631 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
6635 if (id
< PRAGMA_FIRST_EXTERNAL
)
6637 if (context
== pragma_external
)
6640 c_parser_error (parser
, "expected declaration specifiers");
6641 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
6644 c_parser_omp_construct (parser
);
6650 c_parser_consume_pragma (parser
);
6651 c_invoke_pragma_handler (id
);
6653 /* Skip to EOL, but suppress any error message. Those will have been
6654 generated by the handler routine through calling error, as opposed
6655 to calling c_parser_error. */
6656 parser
->error
= true;
6657 c_parser_skip_to_pragma_eol (parser
);
6662 /* The interface the pragma parsers have to the lexer. */
6665 pragma_lex (tree
*value
)
6667 c_token
*tok
= c_parser_peek_token (the_parser
);
6668 enum cpp_ttype ret
= tok
->type
;
6670 *value
= tok
->value
;
6671 if (ret
== CPP_PRAGMA_EOL
|| ret
== CPP_EOF
)
6675 if (ret
== CPP_KEYWORD
)
6677 c_parser_consume_token (the_parser
);
6684 c_parser_pragma_pch_preprocess (c_parser
*parser
)
6688 c_parser_consume_pragma (parser
);
6689 if (c_parser_next_token_is (parser
, CPP_STRING
))
6691 name
= c_parser_peek_token (parser
)->value
;
6692 c_parser_consume_token (parser
);
6695 c_parser_error (parser
, "expected string literal");
6696 c_parser_skip_to_pragma_eol (parser
);
6699 c_common_pch_pragma (parse_in
, TREE_STRING_POINTER (name
));
6702 /* OpenMP 2.5 parsing routines. */
6704 /* Returns name of the next clause.
6705 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
6706 the token is not consumed. Otherwise appropriate pragma_omp_clause is
6707 returned and the token is consumed. */
6709 static pragma_omp_clause
6710 c_parser_omp_clause_name (c_parser
*parser
)
6712 pragma_omp_clause result
= PRAGMA_OMP_CLAUSE_NONE
;
6714 if (c_parser_next_token_is_keyword (parser
, RID_IF
))
6715 result
= PRAGMA_OMP_CLAUSE_IF
;
6716 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
6717 result
= PRAGMA_OMP_CLAUSE_DEFAULT
;
6718 else if (c_parser_next_token_is (parser
, CPP_NAME
))
6720 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
6725 if (!strcmp ("copyin", p
))
6726 result
= PRAGMA_OMP_CLAUSE_COPYIN
;
6727 else if (!strcmp ("copyprivate", p
))
6728 result
= PRAGMA_OMP_CLAUSE_COPYPRIVATE
;
6731 if (!strcmp ("firstprivate", p
))
6732 result
= PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
;
6735 if (!strcmp ("lastprivate", p
))
6736 result
= PRAGMA_OMP_CLAUSE_LASTPRIVATE
;
6739 if (!strcmp ("nowait", p
))
6740 result
= PRAGMA_OMP_CLAUSE_NOWAIT
;
6741 else if (!strcmp ("num_threads", p
))
6742 result
= PRAGMA_OMP_CLAUSE_NUM_THREADS
;
6745 if (!strcmp ("ordered", p
))
6746 result
= PRAGMA_OMP_CLAUSE_ORDERED
;
6749 if (!strcmp ("private", p
))
6750 result
= PRAGMA_OMP_CLAUSE_PRIVATE
;
6753 if (!strcmp ("reduction", p
))
6754 result
= PRAGMA_OMP_CLAUSE_REDUCTION
;
6757 if (!strcmp ("schedule", p
))
6758 result
= PRAGMA_OMP_CLAUSE_SCHEDULE
;
6759 else if (!strcmp ("shared", p
))
6760 result
= PRAGMA_OMP_CLAUSE_SHARED
;
6765 if (result
!= PRAGMA_OMP_CLAUSE_NONE
)
6766 c_parser_consume_token (parser
);
6771 /* Validate that a clause of the given type does not already exist. */
6774 check_no_duplicate_clause (tree clauses
, enum tree_code code
, const char *name
)
6778 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
6779 if (OMP_CLAUSE_CODE (c
) == code
)
6781 error ("too many %qs clauses", name
);
6789 variable-list , identifier
6791 If KIND is nonzero, create the appropriate node and install the decl
6792 in OMP_CLAUSE_DECL and add the node to the head of the list.
6794 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
6795 return the list created. */
6798 c_parser_omp_variable_list (c_parser
*parser
, enum omp_clause_code kind
,
6801 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
6802 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
6803 c_parser_error (parser
, "expected identifier");
6805 while (c_parser_next_token_is (parser
, CPP_NAME
)
6806 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
6808 tree t
= lookup_name (c_parser_peek_token (parser
)->value
);
6811 undeclared_variable (c_parser_peek_token (parser
)->value
,
6812 c_parser_peek_token (parser
)->location
);
6813 else if (t
== error_mark_node
)
6817 tree u
= build_omp_clause (kind
);
6818 OMP_CLAUSE_DECL (u
) = t
;
6819 OMP_CLAUSE_CHAIN (u
) = list
;
6823 list
= tree_cons (t
, NULL_TREE
, list
);
6825 c_parser_consume_token (parser
);
6827 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
6830 c_parser_consume_token (parser
);
6836 /* Similarly, but expect leading and trailing parenthesis. This is a very
6837 common case for omp clauses. */
6840 c_parser_omp_var_list_parens (c_parser
*parser
, enum tree_code kind
, tree list
)
6842 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6844 list
= c_parser_omp_variable_list (parser
, kind
, list
);
6845 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6851 copyin ( variable-list ) */
6854 c_parser_omp_clause_copyin (c_parser
*parser
, tree list
)
6856 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYIN
, list
);
6860 copyprivate ( variable-list ) */
6863 c_parser_omp_clause_copyprivate (c_parser
*parser
, tree list
)
6865 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYPRIVATE
, list
);
6869 default ( shared | none ) */
6872 c_parser_omp_clause_default (c_parser
*parser
, tree list
)
6874 enum omp_clause_default_kind kind
= OMP_CLAUSE_DEFAULT_UNSPECIFIED
;
6877 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6879 if (c_parser_next_token_is (parser
, CPP_NAME
))
6881 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
6886 if (strcmp ("none", p
) != 0)
6888 kind
= OMP_CLAUSE_DEFAULT_NONE
;
6892 if (strcmp ("shared", p
) != 0)
6894 kind
= OMP_CLAUSE_DEFAULT_SHARED
;
6901 c_parser_consume_token (parser
);
6906 c_parser_error (parser
, "expected %<none%> or %<shared%>");
6908 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6910 if (kind
== OMP_CLAUSE_DEFAULT_UNSPECIFIED
)
6913 check_no_duplicate_clause (list
, OMP_CLAUSE_DEFAULT
, "default");
6914 c
= build_omp_clause (OMP_CLAUSE_DEFAULT
);
6915 OMP_CLAUSE_CHAIN (c
) = list
;
6916 OMP_CLAUSE_DEFAULT_KIND (c
) = kind
;
6922 firstprivate ( variable-list ) */
6925 c_parser_omp_clause_firstprivate (c_parser
*parser
, tree list
)
6927 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FIRSTPRIVATE
, list
);
6931 if ( expression ) */
6934 c_parser_omp_clause_if (c_parser
*parser
, tree list
)
6936 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
6938 tree t
= c_parser_paren_condition (parser
);
6941 check_no_duplicate_clause (list
, OMP_CLAUSE_IF
, "if");
6943 c
= build_omp_clause (OMP_CLAUSE_IF
);
6944 OMP_CLAUSE_IF_EXPR (c
) = t
;
6945 OMP_CLAUSE_CHAIN (c
) = list
;
6949 c_parser_error (parser
, "expected %<(%>");
6955 lastprivate ( variable-list ) */
6958 c_parser_omp_clause_lastprivate (c_parser
*parser
, tree list
)
6960 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_LASTPRIVATE
, list
);
6967 c_parser_omp_clause_nowait (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
6971 check_no_duplicate_clause (list
, OMP_CLAUSE_NOWAIT
, "nowait");
6973 c
= build_omp_clause (OMP_CLAUSE_NOWAIT
);
6974 OMP_CLAUSE_CHAIN (c
) = list
;
6979 num_threads ( expression ) */
6982 c_parser_omp_clause_num_threads (c_parser
*parser
, tree list
)
6984 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6986 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
6987 tree c
, t
= c_parser_expression (parser
).value
;
6989 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6991 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
6993 c_parser_error (parser
, "expected integer expression");
6997 /* Attempt to statically determine when the number isn't positive. */
6998 c
= fold_build2 (LE_EXPR
, boolean_type_node
, t
,
6999 build_int_cst (TREE_TYPE (t
), 0));
7000 if (c
== boolean_true_node
)
7002 warning (0, "%H%<num_threads%> value must be positive", &expr_loc
);
7003 t
= integer_one_node
;
7006 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_THREADS
, "num_threads");
7008 c
= build_omp_clause (OMP_CLAUSE_NUM_THREADS
);
7009 OMP_CLAUSE_NUM_THREADS_EXPR (c
) = t
;
7010 OMP_CLAUSE_CHAIN (c
) = list
;
7021 c_parser_omp_clause_ordered (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
7025 check_no_duplicate_clause (list
, OMP_CLAUSE_ORDERED
, "ordered");
7027 c
= build_omp_clause (OMP_CLAUSE_ORDERED
);
7028 OMP_CLAUSE_CHAIN (c
) = list
;
7033 private ( variable-list ) */
7036 c_parser_omp_clause_private (c_parser
*parser
, tree list
)
7038 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_PRIVATE
, list
);
7042 reduction ( reduction-operator : variable-list )
7045 One of: + * - & ^ | && || */
7048 c_parser_omp_clause_reduction (c_parser
*parser
, tree list
)
7050 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7052 enum tree_code code
;
7054 switch (c_parser_peek_token (parser
)->type
)
7066 code
= BIT_AND_EXPR
;
7069 code
= BIT_XOR_EXPR
;
7072 code
= BIT_IOR_EXPR
;
7075 code
= TRUTH_ANDIF_EXPR
;
7078 code
= TRUTH_ORIF_EXPR
;
7081 c_parser_error (parser
,
7082 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
7083 "%<^%>, %<|%>, %<&&%>, or %<||%>");
7084 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
7087 c_parser_consume_token (parser
);
7088 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
7092 nl
= c_parser_omp_variable_list (parser
, OMP_CLAUSE_REDUCTION
, list
);
7093 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
7094 OMP_CLAUSE_REDUCTION_CODE (c
) = code
;
7098 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7104 schedule ( schedule-kind )
7105 schedule ( schedule-kind , expression )
7108 static | dynamic | guided | runtime
7112 c_parser_omp_clause_schedule (c_parser
*parser
, tree list
)
7116 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7119 c
= build_omp_clause (OMP_CLAUSE_SCHEDULE
);
7121 if (c_parser_next_token_is (parser
, CPP_NAME
))
7123 tree kind
= c_parser_peek_token (parser
)->value
;
7124 const char *p
= IDENTIFIER_POINTER (kind
);
7129 if (strcmp ("dynamic", p
) != 0)
7131 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_DYNAMIC
;
7135 if (strcmp ("guided", p
) != 0)
7137 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_GUIDED
;
7141 if (strcmp ("runtime", p
) != 0)
7143 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_RUNTIME
;
7150 else if (c_parser_next_token_is_keyword (parser
, RID_STATIC
))
7151 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_STATIC
;
7155 c_parser_consume_token (parser
);
7156 if (c_parser_next_token_is (parser
, CPP_COMMA
))
7159 c_parser_consume_token (parser
);
7161 here
= c_parser_peek_token (parser
)->location
;
7162 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
7164 if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_RUNTIME
)
7165 error ("%Hschedule %<runtime%> does not take "
7166 "a %<chunk_size%> parameter", &here
);
7167 else if (TREE_CODE (TREE_TYPE (t
)) == INTEGER_TYPE
)
7168 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
) = t
;
7170 c_parser_error (parser
, "expected integer expression");
7172 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7175 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7176 "expected %<,%> or %<)%>");
7178 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
7179 OMP_CLAUSE_CHAIN (c
) = list
;
7183 c_parser_error (parser
, "invalid schedule kind");
7184 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
7189 shared ( variable-list ) */
7192 c_parser_omp_clause_shared (c_parser
*parser
, tree list
)
7194 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_SHARED
, list
);
7197 /* Parse all OpenMP clauses. The set clauses allowed by the directive
7198 is a bitmask in MASK. Return the list of clauses found; the result
7199 of clause default goes in *pdefault. */
7202 c_parser_omp_all_clauses (c_parser
*parser
, unsigned int mask
,
7205 tree clauses
= NULL
;
7207 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
7209 location_t here
= c_parser_peek_token (parser
)->location
;
7210 const pragma_omp_clause c_kind
= c_parser_omp_clause_name (parser
);
7212 tree prev
= clauses
;
7216 case PRAGMA_OMP_CLAUSE_COPYIN
:
7217 clauses
= c_parser_omp_clause_copyin (parser
, clauses
);
7220 case PRAGMA_OMP_CLAUSE_COPYPRIVATE
:
7221 clauses
= c_parser_omp_clause_copyprivate (parser
, clauses
);
7222 c_name
= "copyprivate";
7224 case PRAGMA_OMP_CLAUSE_DEFAULT
:
7225 clauses
= c_parser_omp_clause_default (parser
, clauses
);
7228 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
:
7229 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
7230 c_name
= "firstprivate";
7232 case PRAGMA_OMP_CLAUSE_IF
:
7233 clauses
= c_parser_omp_clause_if (parser
, clauses
);
7236 case PRAGMA_OMP_CLAUSE_LASTPRIVATE
:
7237 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
7238 c_name
= "lastprivate";
7240 case PRAGMA_OMP_CLAUSE_NOWAIT
:
7241 clauses
= c_parser_omp_clause_nowait (parser
, clauses
);
7244 case PRAGMA_OMP_CLAUSE_NUM_THREADS
:
7245 clauses
= c_parser_omp_clause_num_threads (parser
, clauses
);
7246 c_name
= "num_threads";
7248 case PRAGMA_OMP_CLAUSE_ORDERED
:
7249 clauses
= c_parser_omp_clause_ordered (parser
, clauses
);
7252 case PRAGMA_OMP_CLAUSE_PRIVATE
:
7253 clauses
= c_parser_omp_clause_private (parser
, clauses
);
7256 case PRAGMA_OMP_CLAUSE_REDUCTION
:
7257 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
7258 c_name
= "reduction";
7260 case PRAGMA_OMP_CLAUSE_SCHEDULE
:
7261 clauses
= c_parser_omp_clause_schedule (parser
, clauses
);
7262 c_name
= "schedule";
7264 case PRAGMA_OMP_CLAUSE_SHARED
:
7265 clauses
= c_parser_omp_clause_shared (parser
, clauses
);
7269 c_parser_error (parser
, "expected %<#pragma omp%> clause");
7273 if (((mask
>> c_kind
) & 1) == 0 && !parser
->error
)
7275 /* Remove the invalid clause(s) from the list to avoid
7276 confusing the rest of the compiler. */
7278 error ("%H%qs is not valid for %qs", &here
, c_name
, where
);
7283 c_parser_skip_to_pragma_eol (parser
);
7285 return c_finish_omp_clauses (clauses
);
7292 In practice, we're also interested in adding the statement to an
7293 outer node. So it is convenient if we work around the fact that
7294 c_parser_statement calls add_stmt. */
7297 c_parser_omp_structured_block (c_parser
*parser
)
7299 tree stmt
= push_stmt_list ();
7300 c_parser_statement (parser
);
7301 return pop_stmt_list (stmt
);
7305 # pragma omp atomic new-line
7309 x binop= expr | x++ | ++x | x-- | --x
7311 +, *, -, /, &, ^, |, <<, >>
7313 where x is an lvalue expression with scalar type. */
7316 c_parser_omp_atomic (c_parser
*parser
)
7320 enum tree_code code
;
7322 c_parser_skip_to_pragma_eol (parser
);
7324 lhs
= c_parser_unary_expression (parser
).value
;
7325 switch (TREE_CODE (lhs
))
7329 c_parser_skip_to_end_of_block_or_statement (parser
);
7332 case PREINCREMENT_EXPR
:
7333 case POSTINCREMENT_EXPR
:
7334 lhs
= TREE_OPERAND (lhs
, 0);
7336 rhs
= integer_one_node
;
7339 case PREDECREMENT_EXPR
:
7340 case POSTDECREMENT_EXPR
:
7341 lhs
= TREE_OPERAND (lhs
, 0);
7343 rhs
= integer_one_node
;
7347 switch (c_parser_peek_token (parser
)->type
)
7353 code
= TRUNC_DIV_EXPR
;
7368 code
= BIT_AND_EXPR
;
7371 code
= BIT_IOR_EXPR
;
7374 code
= BIT_XOR_EXPR
;
7377 c_parser_error (parser
,
7378 "invalid operator for %<#pragma omp atomic%>");
7382 c_parser_consume_token (parser
);
7383 rhs
= c_parser_expression (parser
).value
;
7386 stmt
= c_finish_omp_atomic (code
, lhs
, rhs
);
7387 if (stmt
!= error_mark_node
)
7389 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7394 # pragma omp barrier new-line
7398 c_parser_omp_barrier (c_parser
*parser
)
7400 c_parser_consume_pragma (parser
);
7401 c_parser_skip_to_pragma_eol (parser
);
7403 c_finish_omp_barrier ();
7407 # pragma omp critical [(name)] new-line
7412 c_parser_omp_critical (c_parser
*parser
)
7414 tree stmt
, name
= NULL
;
7416 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
7418 c_parser_consume_token (parser
);
7419 if (c_parser_next_token_is (parser
, CPP_NAME
))
7421 name
= c_parser_peek_token (parser
)->value
;
7422 c_parser_consume_token (parser
);
7423 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7426 c_parser_error (parser
, "expected identifier");
7428 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
7429 c_parser_error (parser
, "expected %<(%> or end of line");
7430 c_parser_skip_to_pragma_eol (parser
);
7432 stmt
= c_parser_omp_structured_block (parser
);
7433 return c_finish_omp_critical (stmt
, name
);
7437 # pragma omp flush flush-vars[opt] new-line
7440 ( variable-list ) */
7443 c_parser_omp_flush (c_parser
*parser
)
7445 c_parser_consume_pragma (parser
);
7446 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
7447 c_parser_omp_var_list_parens (parser
, 0, NULL
);
7448 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
7449 c_parser_error (parser
, "expected %<(%> or end of line");
7450 c_parser_skip_to_pragma_eol (parser
);
7452 c_finish_omp_flush ();
7455 /* Parse the restricted form of the for statment allowed by OpenMP.
7456 The real trick here is to determine the loop control variable early
7457 so that we can push a new decl if necessary to make it private. */
7460 c_parser_omp_for_loop (c_parser
*parser
)
7462 tree decl
, cond
, incr
, save_break
, save_cont
, body
, init
;
7465 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
))
7467 c_parser_error (parser
, "for statement expected");
7470 loc
= c_parser_peek_token (parser
)->location
;
7471 c_parser_consume_token (parser
);
7473 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7476 /* Parse the initialization declaration or expression. */
7477 if (c_parser_next_token_starts_declspecs (parser
))
7479 c_parser_declaration_or_fndef (parser
, true, true, true, true);
7480 decl
= check_for_loop_decls ();
7485 else if (c_parser_next_token_is (parser
, CPP_NAME
)
7486 && c_parser_peek_2nd_token (parser
)->type
== CPP_EQ
)
7488 decl
= c_parser_postfix_expression (parser
).value
;
7490 c_parser_require (parser
, CPP_EQ
, "expected %<=%>");
7492 init
= c_parser_expr_no_commas (parser
, NULL
).value
;
7493 init
= build_modify_expr (decl
, NOP_EXPR
, init
);
7494 init
= c_process_expr_stmt (init
);
7496 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7501 /* Parse the loop condition. */
7503 if (c_parser_next_token_is_not (parser
, CPP_SEMICOLON
))
7505 cond
= c_parser_expression_conv (parser
).value
;
7506 cond
= c_objc_common_truthvalue_conversion (cond
);
7507 if (CAN_HAVE_LOCATION_P (cond
))
7508 SET_EXPR_LOCATION (cond
, input_location
);
7510 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7512 /* Parse the increment expression. */
7514 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_PAREN
))
7515 incr
= c_process_expr_stmt (c_parser_expression (parser
).value
);
7516 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7519 save_break
= c_break_label
;
7520 c_break_label
= size_one_node
;
7521 save_cont
= c_cont_label
;
7522 c_cont_label
= NULL_TREE
;
7523 body
= push_stmt_list ();
7525 add_stmt (c_parser_c99_block_statement (parser
));
7527 add_stmt (build1 (LABEL_EXPR
, void_type_node
, c_cont_label
));
7529 body
= pop_stmt_list (body
);
7530 c_break_label
= save_break
;
7531 c_cont_label
= save_cont
;
7533 /* Only bother calling c_finish_omp_for if we havn't already generated
7534 an error from the initialization parsing. */
7535 if (decl
!= NULL
&& decl
!= error_mark_node
&& init
!= error_mark_node
)
7536 return c_finish_omp_for (loc
, decl
, init
, cond
, incr
, body
, NULL
);
7540 c_parser_error (parser
, "expected iteration declaration or initialization");
7541 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7542 decl
= init
= cond
= incr
= NULL_TREE
;
7547 #pragma omp for for-clause[optseq] new-line
7551 #define OMP_FOR_CLAUSE_MASK \
7552 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
7553 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
7554 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
7555 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
7556 | (1u << PRAGMA_OMP_CLAUSE_ORDERED) \
7557 | (1u << PRAGMA_OMP_CLAUSE_SCHEDULE) \
7558 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
7561 c_parser_omp_for (c_parser
*parser
)
7563 tree block
, clauses
, ret
;
7565 clauses
= c_parser_omp_all_clauses (parser
, OMP_FOR_CLAUSE_MASK
,
7568 block
= c_begin_compound_stmt (true);
7569 ret
= c_parser_omp_for_loop (parser
);
7571 OMP_FOR_CLAUSES (ret
) = clauses
;
7572 block
= c_end_compound_stmt (block
, true);
7579 # pragma omp master new-line
7584 c_parser_omp_master (c_parser
*parser
)
7586 c_parser_skip_to_pragma_eol (parser
);
7587 return c_finish_omp_master (c_parser_omp_structured_block (parser
));
7591 # pragma omp ordered new-line
7596 c_parser_omp_ordered (c_parser
*parser
)
7598 c_parser_skip_to_pragma_eol (parser
);
7599 return c_finish_omp_ordered (c_parser_omp_structured_block (parser
));
7605 { section-sequence }
7608 section-directive[opt] structured-block
7609 section-sequence section-directive structured-block */
7612 c_parser_omp_sections_scope (c_parser
*parser
)
7615 bool error_suppress
= false;
7618 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
7620 /* Avoid skipping until the end of the block. */
7621 parser
->error
= false;
7625 stmt
= push_stmt_list ();
7627 loc
= c_parser_peek_token (parser
)->location
;
7628 if (c_parser_peek_token (parser
)->pragma_kind
!= PRAGMA_OMP_SECTION
)
7630 substmt
= push_stmt_list ();
7634 c_parser_statement (parser
);
7636 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
7638 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
7640 if (c_parser_next_token_is (parser
, CPP_EOF
))
7644 substmt
= pop_stmt_list (substmt
);
7645 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
7646 SET_EXPR_LOCATION (substmt
, loc
);
7652 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
7654 if (c_parser_next_token_is (parser
, CPP_EOF
))
7657 loc
= c_parser_peek_token (parser
)->location
;
7658 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
7660 c_parser_consume_pragma (parser
);
7661 c_parser_skip_to_pragma_eol (parser
);
7662 error_suppress
= false;
7664 else if (!error_suppress
)
7666 error ("%Hexpected %<#pragma omp section%> or %<}%>",
7668 error_suppress
= true;
7671 substmt
= c_parser_omp_structured_block (parser
);
7672 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
7673 SET_EXPR_LOCATION (substmt
, loc
);
7676 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
,
7677 "expected %<#pragma omp section%> or %<}%>");
7679 substmt
= pop_stmt_list (stmt
);
7681 stmt
= make_node (OMP_SECTIONS
);
7682 TREE_TYPE (stmt
) = void_type_node
;
7683 OMP_SECTIONS_BODY (stmt
) = substmt
;
7685 return add_stmt (stmt
);
7689 # pragma omp sections sections-clause[optseq] newline
7693 #define OMP_SECTIONS_CLAUSE_MASK \
7694 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
7695 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
7696 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
7697 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
7698 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
7701 c_parser_omp_sections (c_parser
*parser
)
7703 tree block
, clauses
, ret
;
7705 clauses
= c_parser_omp_all_clauses (parser
, OMP_SECTIONS_CLAUSE_MASK
,
7706 "#pragma omp sections");
7708 block
= c_begin_compound_stmt (true);
7709 ret
= c_parser_omp_sections_scope (parser
);
7711 OMP_SECTIONS_CLAUSES (ret
) = clauses
;
7712 block
= c_end_compound_stmt (block
, true);
7719 # pragma parallel parallel-clause new-line
7720 # pragma parallel for parallel-for-clause new-line
7721 # pragma parallel sections parallel-sections-clause new-line
7724 #define OMP_PARALLEL_CLAUSE_MASK \
7725 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
7726 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
7727 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
7728 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
7729 | (1u << PRAGMA_OMP_CLAUSE_SHARED) \
7730 | (1u << PRAGMA_OMP_CLAUSE_COPYIN) \
7731 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
7732 | (1u << PRAGMA_OMP_CLAUSE_NUM_THREADS))
7735 c_parser_omp_parallel (c_parser
*parser
)
7737 enum pragma_kind p_kind
= PRAGMA_OMP_PARALLEL
;
7738 const char *p_name
= "#pragma omp parallel";
7739 tree stmt
, clauses
, par_clause
, ws_clause
, block
;
7740 unsigned int mask
= OMP_PARALLEL_CLAUSE_MASK
;
7742 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
7744 c_parser_consume_token (parser
);
7745 p_kind
= PRAGMA_OMP_PARALLEL_FOR
;
7746 p_name
= "#pragma omp parallel for";
7747 mask
|= OMP_FOR_CLAUSE_MASK
;
7748 mask
&= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT
);
7750 else if (c_parser_next_token_is (parser
, CPP_NAME
))
7752 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
7753 if (strcmp (p
, "sections") == 0)
7755 c_parser_consume_token (parser
);
7756 p_kind
= PRAGMA_OMP_PARALLEL_SECTIONS
;
7757 p_name
= "#pragma omp parallel sections";
7758 mask
|= OMP_SECTIONS_CLAUSE_MASK
;
7759 mask
&= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT
);
7763 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
);
7767 case PRAGMA_OMP_PARALLEL
:
7768 block
= c_begin_omp_parallel ();
7769 c_parser_statement (parser
);
7770 stmt
= c_finish_omp_parallel (clauses
, block
);
7773 case PRAGMA_OMP_PARALLEL_FOR
:
7774 block
= c_begin_omp_parallel ();
7775 c_split_parallel_clauses (clauses
, &par_clause
, &ws_clause
);
7776 stmt
= c_parser_omp_for_loop (parser
);
7778 OMP_FOR_CLAUSES (stmt
) = ws_clause
;
7779 stmt
= c_finish_omp_parallel (par_clause
, block
);
7780 OMP_PARALLEL_COMBINED (stmt
) = 1;
7783 case PRAGMA_OMP_PARALLEL_SECTIONS
:
7784 block
= c_begin_omp_parallel ();
7785 c_split_parallel_clauses (clauses
, &par_clause
, &ws_clause
);
7786 stmt
= c_parser_omp_sections_scope (parser
);
7788 OMP_SECTIONS_CLAUSES (stmt
) = ws_clause
;
7789 stmt
= c_finish_omp_parallel (par_clause
, block
);
7790 OMP_PARALLEL_COMBINED (stmt
) = 1;
7801 # pragma omp single single-clause[optseq] new-line
7805 #define OMP_SINGLE_CLAUSE_MASK \
7806 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
7807 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
7808 | (1u << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
7809 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
7812 c_parser_omp_single (c_parser
*parser
)
7814 tree stmt
= make_node (OMP_SINGLE
);
7815 TREE_TYPE (stmt
) = void_type_node
;
7817 OMP_SINGLE_CLAUSES (stmt
)
7818 = c_parser_omp_all_clauses (parser
, OMP_SINGLE_CLAUSE_MASK
,
7819 "#pragma omp single");
7820 OMP_SINGLE_BODY (stmt
) = c_parser_omp_structured_block (parser
);
7822 return add_stmt (stmt
);
7826 /* Main entry point to parsing most OpenMP pragmas. */
7829 c_parser_omp_construct (c_parser
*parser
)
7831 enum pragma_kind p_kind
;
7835 loc
= c_parser_peek_token (parser
)->location
;
7836 p_kind
= c_parser_peek_token (parser
)->pragma_kind
;
7837 c_parser_consume_pragma (parser
);
7839 /* For all constructs below except #pragma omp atomic
7840 MUST_NOT_THROW catch handlers are needed when exceptions
7842 if (p_kind
!= PRAGMA_OMP_ATOMIC
)
7843 c_maybe_initialize_eh ();
7847 case PRAGMA_OMP_ATOMIC
:
7848 c_parser_omp_atomic (parser
);
7850 case PRAGMA_OMP_CRITICAL
:
7851 stmt
= c_parser_omp_critical (parser
);
7853 case PRAGMA_OMP_FOR
:
7854 stmt
= c_parser_omp_for (parser
);
7856 case PRAGMA_OMP_MASTER
:
7857 stmt
= c_parser_omp_master (parser
);
7859 case PRAGMA_OMP_ORDERED
:
7860 stmt
= c_parser_omp_ordered (parser
);
7862 case PRAGMA_OMP_PARALLEL
:
7863 stmt
= c_parser_omp_parallel (parser
);
7865 case PRAGMA_OMP_SECTIONS
:
7866 stmt
= c_parser_omp_sections (parser
);
7868 case PRAGMA_OMP_SINGLE
:
7869 stmt
= c_parser_omp_single (parser
);
7876 SET_EXPR_LOCATION (stmt
, loc
);
7881 # pragma omp threadprivate (variable-list) */
7884 c_parser_omp_threadprivate (c_parser
*parser
)
7888 c_parser_consume_pragma (parser
);
7889 vars
= c_parser_omp_var_list_parens (parser
, 0, NULL
);
7891 /* Mark every variable in VARS to be assigned thread local storage. */
7892 for (t
= vars
; t
; t
= TREE_CHAIN (t
))
7894 tree v
= TREE_PURPOSE (t
);
7896 /* If V had already been marked threadprivate, it doesn't matter
7897 whether it had been used prior to this point. */
7898 if (TREE_USED (v
) && !C_DECL_THREADPRIVATE_P (v
))
7899 error ("%qE declared %<threadprivate%> after first use", v
);
7900 else if (! TREE_STATIC (v
) && ! DECL_EXTERNAL (v
))
7901 error ("automatic variable %qE cannot be %<threadprivate%>", v
);
7902 else if (! COMPLETE_TYPE_P (TREE_TYPE (v
)))
7903 error ("%<threadprivate%> %qE has incomplete type", v
);
7906 if (! DECL_THREAD_LOCAL_P (v
))
7908 DECL_TLS_MODEL (v
) = decl_default_tls_model (v
);
7909 /* If rtl has been already set for this var, call
7910 make_decl_rtl once again, so that encode_section_info
7911 has a chance to look at the new decl flags. */
7912 if (DECL_RTL_SET_P (v
))
7915 C_DECL_THREADPRIVATE_P (v
) = 1;
7919 c_parser_skip_to_pragma_eol (parser
);
7923 /* Parse a single source file. */
7928 /* Use local storage to begin. If the first token is a pragma, parse it.
7929 If it is #pragma GCC pch_preprocess, then this will load a PCH file
7930 which will cause garbage collection. */
7933 memset (&tparser
, 0, sizeof tparser
);
7934 the_parser
= &tparser
;
7936 if (c_parser_peek_token (&tparser
)->pragma_kind
== PRAGMA_GCC_PCH_PREPROCESS
)
7937 c_parser_pragma_pch_preprocess (&tparser
);
7939 the_parser
= GGC_NEW (c_parser
);
7940 *the_parser
= tparser
;
7942 c_parser_translation_unit (the_parser
);
7946 #include "gt-c-parser.h"