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 2, 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 COPYING. If not, write to the Free
22 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
27 Make sure all relevant comments, and all relevant code from all
28 actions, brought over from old parser. Verify exact correspondence
31 Add testcases covering every input symbol in every state in old and
34 Include full syntax for GNU C, including erroneous cases accepted
35 with error messages, in syntax productions in comments.
37 Make more diagnostics in the front end generally take an explicit
38 location rather than implicitly using input_location. */
42 #include "coretypes.h"
46 #include "langhooks.h"
62 /* The reserved keyword table. */
66 ENUM_BITFIELD(rid
) rid
: 16;
67 unsigned int disable
: 16;
70 /* Disable mask. Keywords are disabled if (reswords[i].disable &
72 #define D_C89 0x01 /* not in C89 */
73 #define D_EXT 0x02 /* GCC extension */
74 #define D_EXT89 0x04 /* GCC extension incorporated in C99 */
75 #define D_OBJC 0x08 /* Objective C only */
77 static const struct resword reswords
[] =
79 { "_Bool", RID_BOOL
, 0 },
80 { "_Complex", RID_COMPLEX
, 0 },
81 { "_Decimal32", RID_DFLOAT32
, D_EXT
},
82 { "_Decimal64", RID_DFLOAT64
, D_EXT
},
83 { "_Decimal128", RID_DFLOAT128
, D_EXT
},
84 { "__FUNCTION__", RID_FUNCTION_NAME
, 0 },
85 { "__PRETTY_FUNCTION__", RID_PRETTY_FUNCTION_NAME
, 0 },
86 { "__alignof", RID_ALIGNOF
, 0 },
87 { "__alignof__", RID_ALIGNOF
, 0 },
88 { "__asm", RID_ASM
, 0 },
89 { "__asm__", RID_ASM
, 0 },
90 { "__attribute", RID_ATTRIBUTE
, 0 },
91 { "__attribute__", RID_ATTRIBUTE
, 0 },
92 { "__builtin_choose_expr", RID_CHOOSE_EXPR
, 0 },
93 { "__builtin_offsetof", RID_OFFSETOF
, 0 },
94 { "__builtin_types_compatible_p", RID_TYPES_COMPATIBLE_P
, 0 },
95 { "__builtin_va_arg", RID_VA_ARG
, 0 },
96 { "__complex", RID_COMPLEX
, 0 },
97 { "__complex__", RID_COMPLEX
, 0 },
98 { "__const", RID_CONST
, 0 },
99 { "__const__", RID_CONST
, 0 },
100 { "__extension__", RID_EXTENSION
, 0 },
101 { "__func__", RID_C99_FUNCTION_NAME
, 0 },
102 { "__imag", RID_IMAGPART
, 0 },
103 { "__imag__", RID_IMAGPART
, 0 },
104 { "__inline", RID_INLINE
, 0 },
105 { "__inline__", RID_INLINE
, 0 },
106 { "__label__", RID_LABEL
, 0 },
107 { "__real", RID_REALPART
, 0 },
108 { "__real__", RID_REALPART
, 0 },
109 { "__restrict", RID_RESTRICT
, 0 },
110 { "__restrict__", RID_RESTRICT
, 0 },
111 { "__signed", RID_SIGNED
, 0 },
112 { "__signed__", RID_SIGNED
, 0 },
113 { "__thread", RID_THREAD
, 0 },
114 { "__typeof", RID_TYPEOF
, 0 },
115 { "__typeof__", RID_TYPEOF
, 0 },
116 { "__volatile", RID_VOLATILE
, 0 },
117 { "__volatile__", RID_VOLATILE
, 0 },
118 { "asm", RID_ASM
, D_EXT
},
119 { "auto", RID_AUTO
, 0 },
120 { "break", RID_BREAK
, 0 },
121 { "case", RID_CASE
, 0 },
122 { "char", RID_CHAR
, 0 },
123 { "const", RID_CONST
, 0 },
124 { "continue", RID_CONTINUE
, 0 },
125 { "default", RID_DEFAULT
, 0 },
127 { "double", RID_DOUBLE
, 0 },
128 { "else", RID_ELSE
, 0 },
129 { "enum", RID_ENUM
, 0 },
130 { "extern", RID_EXTERN
, 0 },
131 { "float", RID_FLOAT
, 0 },
132 { "for", RID_FOR
, 0 },
133 { "goto", RID_GOTO
, 0 },
135 { "inline", RID_INLINE
, D_EXT89
},
136 { "int", RID_INT
, 0 },
137 { "long", RID_LONG
, 0 },
138 { "register", RID_REGISTER
, 0 },
139 { "restrict", RID_RESTRICT
, D_C89
},
140 { "return", RID_RETURN
, 0 },
141 { "short", RID_SHORT
, 0 },
142 { "signed", RID_SIGNED
, 0 },
143 { "sizeof", RID_SIZEOF
, 0 },
144 { "static", RID_STATIC
, 0 },
145 { "struct", RID_STRUCT
, 0 },
146 { "switch", RID_SWITCH
, 0 },
147 { "typedef", RID_TYPEDEF
, 0 },
148 { "typeof", RID_TYPEOF
, D_EXT
},
149 { "union", RID_UNION
, 0 },
150 { "unsigned", RID_UNSIGNED
, 0 },
151 { "void", RID_VOID
, 0 },
152 { "volatile", RID_VOLATILE
, 0 },
153 { "while", RID_WHILE
, 0 },
154 /* These Objective-C keywords are recognized only immediately after
156 { "class", RID_AT_CLASS
, D_OBJC
},
157 { "compatibility_alias", RID_AT_ALIAS
, D_OBJC
},
158 { "defs", RID_AT_DEFS
, D_OBJC
},
159 { "encode", RID_AT_ENCODE
, D_OBJC
},
160 { "end", RID_AT_END
, D_OBJC
},
161 { "implementation", RID_AT_IMPLEMENTATION
, D_OBJC
},
162 { "interface", RID_AT_INTERFACE
, D_OBJC
},
163 { "private", RID_AT_PRIVATE
, D_OBJC
},
164 { "protected", RID_AT_PROTECTED
, D_OBJC
},
165 { "protocol", RID_AT_PROTOCOL
, D_OBJC
},
166 { "public", RID_AT_PUBLIC
, D_OBJC
},
167 { "selector", RID_AT_SELECTOR
, D_OBJC
},
168 { "throw", RID_AT_THROW
, D_OBJC
},
169 { "try", RID_AT_TRY
, D_OBJC
},
170 { "catch", RID_AT_CATCH
, D_OBJC
},
171 { "finally", RID_AT_FINALLY
, D_OBJC
},
172 { "synchronized", RID_AT_SYNCHRONIZED
, D_OBJC
},
173 /* These are recognized only in protocol-qualifier context
175 { "bycopy", RID_BYCOPY
, D_OBJC
},
176 { "byref", RID_BYREF
, D_OBJC
},
177 { "in", RID_IN
, D_OBJC
},
178 { "inout", RID_INOUT
, D_OBJC
},
179 { "oneway", RID_ONEWAY
, D_OBJC
},
180 { "out", RID_OUT
, D_OBJC
},
182 #define N_reswords (sizeof reswords / sizeof (struct resword))
184 /* Initialization routine for this file. */
189 /* The only initialization required is of the reserved word
193 int mask
= (flag_isoc99
? 0 : D_C89
)
194 | (flag_no_asm
? (flag_isoc99
? D_EXT
: D_EXT
|D_EXT89
) : 0);
196 if (!c_dialect_objc ())
199 ridpointers
= GGC_CNEWVEC (tree
, (int) RID_MAX
);
200 for (i
= 0; i
< N_reswords
; i
++)
202 /* If a keyword is disabled, do not enter it into the table
203 and so create a canonical spelling that isn't a keyword. */
204 if (reswords
[i
].disable
& mask
)
207 id
= get_identifier (reswords
[i
].word
);
208 C_RID_CODE (id
) = reswords
[i
].rid
;
209 C_IS_RESERVED_WORD (id
) = 1;
210 ridpointers
[(int) reswords
[i
].rid
] = id
;
214 /* The C lexer intermediates between the lexer in cpplib and c-lex.c
215 and the C parser. Unlike the C++ lexer, the parser structure
216 stores the lexer information instead of using a separate structure.
217 Identifiers are separated into ordinary identifiers, type names,
218 keywords and some other Objective-C types of identifiers, and some
219 look-ahead is maintained.
221 ??? It might be a good idea to lex the whole file up front (as for
222 C++). It would then be possible to share more of the C and C++
223 lexer code, if desired. */
225 /* The following local token type is used. */
228 #define CPP_KEYWORD ((enum cpp_ttype) (N_TTYPES + 1))
230 /* More information about the type of a CPP_NAME token. */
231 typedef enum c_id_kind
{
232 /* An ordinary identifier. */
234 /* An identifier declared as a typedef name. */
236 /* An identifier declared as an Objective-C class name. */
238 /* Not an identifier. */
242 /* A single C token after string literal concatenation and conversion
243 of preprocessing tokens to tokens. */
244 typedef struct c_token
GTY (())
246 /* The kind of token. */
247 ENUM_BITFIELD (cpp_ttype
) type
: 8;
248 /* If this token is a CPP_NAME, this value indicates whether also
249 declared as some kind of type. Otherwise, it is C_ID_NONE. */
250 ENUM_BITFIELD (c_id_kind
) id_kind
: 8;
251 /* If this token is a keyword, this value indicates which keyword.
252 Otherwise, this value is RID_MAX. */
253 ENUM_BITFIELD (rid
) keyword
: 8;
254 /* If this token is a CPP_PRAGMA, this indicates the pragma that
255 was seen. Otherwise it is PRAGMA_NONE. */
256 ENUM_BITFIELD (pragma_kind
) pragma_kind
: 7;
257 /* True if this token is from a system header. */
258 BOOL_BITFIELD in_system_header
: 1;
259 /* The value associated with this token, if any. */
261 /* The location at which this token was found. */
265 /* A parser structure recording information about the state and
266 context of parsing. Includes lexer information with up to two
267 tokens of look-ahead; more are not needed for C. */
268 typedef struct c_parser
GTY(())
270 /* The look-ahead tokens. */
272 /* How many look-ahead tokens are available (0, 1 or 2). */
274 /* True if a syntax error is being recovered from; false otherwise.
275 c_parser_error sets this flag. It should clear this flag when
276 enough tokens have been consumed to recover from the error. */
277 BOOL_BITFIELD error
: 1;
278 /* True if we're processing a pragma, and shouldn't automatically
279 consume CPP_PRAGMA_EOL. */
280 BOOL_BITFIELD in_pragma
: 1;
281 /* Objective-C specific parser/lexer information. */
282 BOOL_BITFIELD objc_pq_context
: 1;
283 /* The following flag is needed to contextualize Objective-C lexical
284 analysis. In some cases (e.g., 'int NSObject;'), it is
285 undesirable to bind an identifier to an Objective-C class, even
286 if a class with that name exists. */
287 BOOL_BITFIELD objc_need_raw_identifier
: 1;
291 /* The actual parser and external interface. ??? Does this need to be
292 garbage-collected? */
294 static GTY (()) c_parser
*the_parser
;
297 /* Read in and lex a single token, storing it in *TOKEN. */
300 c_lex_one_token (c_parser
*parser
, c_token
*token
)
302 timevar_push (TV_LEX
);
304 token
->type
= c_lex_with_flags (&token
->value
, &token
->location
, NULL
);
305 token
->id_kind
= C_ID_NONE
;
306 token
->keyword
= RID_MAX
;
307 token
->pragma_kind
= PRAGMA_NONE
;
308 token
->in_system_header
= in_system_header
;
316 bool objc_force_identifier
= parser
->objc_need_raw_identifier
;
317 if (c_dialect_objc ())
318 parser
->objc_need_raw_identifier
= false;
320 if (C_IS_RESERVED_WORD (token
->value
))
322 enum rid rid_code
= C_RID_CODE (token
->value
);
324 if (c_dialect_objc ())
326 if (!OBJC_IS_AT_KEYWORD (rid_code
)
327 && (!OBJC_IS_PQ_KEYWORD (rid_code
)
328 || parser
->objc_pq_context
))
330 /* Return the canonical spelling for this keyword. */
331 token
->value
= ridpointers
[(int) rid_code
];
332 token
->type
= CPP_KEYWORD
;
333 token
->keyword
= rid_code
;
339 /* Return the canonical spelling for this keyword. */
340 token
->value
= ridpointers
[(int) rid_code
];
341 token
->type
= CPP_KEYWORD
;
342 token
->keyword
= rid_code
;
347 decl
= lookup_name (token
->value
);
350 if (TREE_CODE (decl
) == TYPE_DECL
)
352 token
->id_kind
= C_ID_TYPENAME
;
356 else if (c_dialect_objc ())
358 tree objc_interface_decl
= objc_is_class_name (token
->value
);
359 /* Objective-C class names are in the same namespace as
360 variables and typedefs, and hence are shadowed by local
362 if (objc_interface_decl
363 && (global_bindings_p ()
364 || (!objc_force_identifier
&& !decl
)))
366 token
->value
= objc_interface_decl
;
367 token
->id_kind
= C_ID_CLASSNAME
;
371 token
->id_kind
= C_ID_ID
;
375 /* This only happens in Objective-C; it must be a keyword. */
376 token
->type
= CPP_KEYWORD
;
377 token
->keyword
= C_RID_CODE (token
->value
);
381 case CPP_CLOSE_PAREN
:
383 /* These tokens may affect the interpretation of any identifiers
384 following, if doing Objective-C. */
385 if (c_dialect_objc ())
386 parser
->objc_need_raw_identifier
= false;
389 /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */
390 token
->pragma_kind
= TREE_INT_CST_LOW (token
->value
);
396 timevar_pop (TV_LEX
);
399 /* Return a pointer to the next token from PARSER, reading it in if
402 static inline c_token
*
403 c_parser_peek_token (c_parser
*parser
)
405 if (parser
->tokens_avail
== 0)
407 c_lex_one_token (parser
, &parser
->tokens
[0]);
408 parser
->tokens_avail
= 1;
410 return &parser
->tokens
[0];
413 /* Return true if the next token from PARSER has the indicated
417 c_parser_next_token_is (c_parser
*parser
, enum cpp_ttype type
)
419 return c_parser_peek_token (parser
)->type
== type
;
422 /* Return true if the next token from PARSER does not have the
426 c_parser_next_token_is_not (c_parser
*parser
, enum cpp_ttype type
)
428 return !c_parser_next_token_is (parser
, type
);
431 /* Return true if the next token from PARSER is the indicated
435 c_parser_next_token_is_keyword (c_parser
*parser
, enum rid keyword
)
439 /* Peek at the next token. */
440 token
= c_parser_peek_token (parser
);
441 /* Check to see if it is the indicated keyword. */
442 return token
->keyword
== keyword
;
445 /* Return true if TOKEN can start a type name,
448 c_token_starts_typename (c_token
*token
)
453 switch (token
->id_kind
)
460 gcc_assert (c_dialect_objc ());
466 switch (token
->keyword
)
495 if (c_dialect_objc ())
503 /* Return true if the next token from PARSER can start a type name,
506 c_parser_next_token_starts_typename (c_parser
*parser
)
508 c_token
*token
= c_parser_peek_token (parser
);
509 return c_token_starts_typename (token
);
512 /* Return true if TOKEN can start declaration specifiers, false
515 c_token_starts_declspecs (c_token
*token
)
520 switch (token
->id_kind
)
527 gcc_assert (c_dialect_objc ());
533 switch (token
->keyword
)
569 if (c_dialect_objc ())
577 /* Return true if the next token from PARSER can start declaration
578 specifiers, false otherwise. */
580 c_parser_next_token_starts_declspecs (c_parser
*parser
)
582 c_token
*token
= c_parser_peek_token (parser
);
583 return c_token_starts_declspecs (token
);
586 /* Return a pointer to the next-but-one token from PARSER, reading it
587 in if necessary. The next token is already read in. */
590 c_parser_peek_2nd_token (c_parser
*parser
)
592 if (parser
->tokens_avail
>= 2)
593 return &parser
->tokens
[1];
594 gcc_assert (parser
->tokens_avail
== 1);
595 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
596 gcc_assert (parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
597 c_lex_one_token (parser
, &parser
->tokens
[1]);
598 parser
->tokens_avail
= 2;
599 return &parser
->tokens
[1];
602 /* Consume the next token from PARSER. */
605 c_parser_consume_token (c_parser
*parser
)
607 gcc_assert (parser
->tokens_avail
>= 1);
608 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
609 gcc_assert (!parser
->in_pragma
|| parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
610 gcc_assert (parser
->error
|| parser
->tokens
[0].type
!= CPP_PRAGMA
);
611 if (parser
->tokens_avail
== 2)
612 parser
->tokens
[0] = parser
->tokens
[1];
613 parser
->tokens_avail
--;
616 /* Expect the current token to be a #pragma. Consume it and remember
617 that we've begun parsing a pragma. */
620 c_parser_consume_pragma (c_parser
*parser
)
622 gcc_assert (!parser
->in_pragma
);
623 gcc_assert (parser
->tokens_avail
>= 1);
624 gcc_assert (parser
->tokens
[0].type
== CPP_PRAGMA
);
625 if (parser
->tokens_avail
== 2)
626 parser
->tokens
[0] = parser
->tokens
[1];
627 parser
->tokens_avail
--;
628 parser
->in_pragma
= true;
631 /* Update the globals input_location and in_system_header from
634 c_parser_set_source_position_from_token (c_token
*token
)
636 if (token
->type
!= CPP_EOF
)
638 input_location
= token
->location
;
639 in_system_header
= token
->in_system_header
;
643 /* Issue a diagnostic of the form
644 FILE:LINE: MESSAGE before TOKEN
645 where TOKEN is the next token in the input stream of PARSER.
646 MESSAGE (specified by the caller) is usually of the form "expected
649 Do not issue a diagnostic if still recovering from an error.
651 ??? This is taken from the C++ parser, but building up messages in
652 this way is not i18n-friendly and some other approach should be
656 c_parser_error (c_parser
*parser
, const char *gmsgid
)
658 c_token
*token
= c_parser_peek_token (parser
);
661 parser
->error
= true;
664 /* This diagnostic makes more sense if it is tagged to the line of
665 the token we just peeked at. */
666 c_parser_set_source_position_from_token (token
);
667 c_parse_error (gmsgid
,
668 /* Because c_parse_error does not understand
669 CPP_KEYWORD, keywords are treated like
671 (token
->type
== CPP_KEYWORD
? CPP_NAME
: token
->type
),
675 /* If the next token is of the indicated TYPE, consume it. Otherwise,
676 issue the error MSGID. If MSGID is NULL then a message has already
677 been produced and no message will be produced this time. Returns
678 true if found, false otherwise. */
681 c_parser_require (c_parser
*parser
,
685 if (c_parser_next_token_is (parser
, type
))
687 c_parser_consume_token (parser
);
692 c_parser_error (parser
, msgid
);
697 /* If the next token is the indicated keyword, consume it. Otherwise,
698 issue the error MSGID. Returns true if found, false otherwise. */
701 c_parser_require_keyword (c_parser
*parser
,
705 if (c_parser_next_token_is_keyword (parser
, keyword
))
707 c_parser_consume_token (parser
);
712 c_parser_error (parser
, msgid
);
717 /* Like c_parser_require, except that tokens will be skipped until the
718 desired token is found. An error message is still produced if the
719 next token is not as expected. If MSGID is NULL then a message has
720 already been produced and no message will be produced this
724 c_parser_skip_until_found (c_parser
*parser
,
728 unsigned nesting_depth
= 0;
730 if (c_parser_require (parser
, type
, msgid
))
733 /* Skip tokens until the desired token is found. */
736 /* Peek at the next token. */
737 c_token
*token
= c_parser_peek_token (parser
);
738 /* If we've reached the token we want, consume it and stop. */
739 if (token
->type
== type
&& !nesting_depth
)
741 c_parser_consume_token (parser
);
745 /* If we've run out of tokens, stop. */
746 if (token
->type
== CPP_EOF
)
748 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
750 if (token
->type
== CPP_OPEN_BRACE
751 || token
->type
== CPP_OPEN_PAREN
752 || token
->type
== CPP_OPEN_SQUARE
)
754 else if (token
->type
== CPP_CLOSE_BRACE
755 || token
->type
== CPP_CLOSE_PAREN
756 || token
->type
== CPP_CLOSE_SQUARE
)
758 if (nesting_depth
-- == 0)
761 /* Consume this token. */
762 c_parser_consume_token (parser
);
764 parser
->error
= false;
767 /* Skip tokens until the end of a parameter is found, but do not
768 consume the comma, semicolon or closing delimiter. */
771 c_parser_skip_to_end_of_parameter (c_parser
*parser
)
773 unsigned nesting_depth
= 0;
777 c_token
*token
= c_parser_peek_token (parser
);
778 if ((token
->type
== CPP_COMMA
|| token
->type
== CPP_SEMICOLON
)
781 /* If we've run out of tokens, stop. */
782 if (token
->type
== CPP_EOF
)
784 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
786 if (token
->type
== CPP_OPEN_BRACE
787 || token
->type
== CPP_OPEN_PAREN
788 || token
->type
== CPP_OPEN_SQUARE
)
790 else if (token
->type
== CPP_CLOSE_BRACE
791 || token
->type
== CPP_CLOSE_PAREN
792 || token
->type
== CPP_CLOSE_SQUARE
)
794 if (nesting_depth
-- == 0)
797 /* Consume this token. */
798 c_parser_consume_token (parser
);
800 parser
->error
= false;
803 /* Expect to be at the end of the pragma directive and consume an
804 end of line marker. */
807 c_parser_skip_to_pragma_eol (c_parser
*parser
)
809 gcc_assert (parser
->in_pragma
);
810 parser
->in_pragma
= false;
812 if (!c_parser_require (parser
, CPP_PRAGMA_EOL
, "expected end of line"))
815 c_token
*token
= c_parser_peek_token (parser
);
816 if (token
->type
== CPP_EOF
)
818 if (token
->type
== CPP_PRAGMA_EOL
)
820 c_parser_consume_token (parser
);
823 c_parser_consume_token (parser
);
826 parser
->error
= false;
829 /* Skip tokens until we have consumed an entire block, or until we
830 have consumed a non-nested ';'. */
833 c_parser_skip_to_end_of_block_or_statement (c_parser
*parser
)
835 unsigned nesting_depth
= 0;
836 bool save_error
= parser
->error
;
842 /* Peek at the next token. */
843 token
= c_parser_peek_token (parser
);
851 if (parser
->in_pragma
)
856 /* If the next token is a ';', we have reached the
857 end of the statement. */
860 /* Consume the ';'. */
861 c_parser_consume_token (parser
);
866 case CPP_CLOSE_BRACE
:
867 /* If the next token is a non-nested '}', then we have
868 reached the end of the current block. */
869 if (nesting_depth
== 0 || --nesting_depth
== 0)
871 c_parser_consume_token (parser
);
877 /* If it the next token is a '{', then we are entering a new
878 block. Consume the entire block. */
883 /* If we see a pragma, consume the whole thing at once. We
884 have some safeguards against consuming pragmas willy-nilly.
885 Normally, we'd expect to be here with parser->error set,
886 which disables these safeguards. But it's possible to get
887 here for secondary error recovery, after parser->error has
889 c_parser_consume_pragma (parser
);
890 c_parser_skip_to_pragma_eol (parser
);
891 parser
->error
= save_error
;
898 c_parser_consume_token (parser
);
902 parser
->error
= false;
905 /* Save the warning flags which are controlled by __extension__. */
908 disable_extension_diagnostics (void)
911 | (warn_pointer_arith
<< 1)
912 | (warn_traditional
<< 2)
915 warn_pointer_arith
= 0;
916 warn_traditional
= 0;
921 /* Restore the warning flags which are controlled by __extension__.
922 FLAGS is the return value from disable_extension_diagnostics. */
925 restore_extension_diagnostics (int flags
)
927 pedantic
= flags
& 1;
928 warn_pointer_arith
= (flags
>> 1) & 1;
929 warn_traditional
= (flags
>> 2) & 1;
930 flag_iso
= (flags
>> 3) & 1;
933 /* Possibly kinds of declarator to parse. */
934 typedef enum c_dtr_syn
{
935 /* A normal declarator with an identifier. */
937 /* An abstract declarator (maybe empty). */
939 /* A parameter declarator: may be either, but after a type name does
940 not redeclare a typedef name as an identifier if it can
941 alternatively be interpreted as a typedef name; see DR#009,
942 applied in C90 TC1, omitted from C99 and reapplied in C99 TC2
943 following DR#249. For example, given a typedef T, "int T" and
944 "int *T" are valid parameter declarations redeclaring T, while
945 "int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are
946 abstract declarators rather than involving redundant parentheses;
947 the same applies with attributes inside the parentheses before
952 static void c_parser_external_declaration (c_parser
*);
953 static void c_parser_asm_definition (c_parser
*);
954 static void c_parser_declaration_or_fndef (c_parser
*, bool, bool, bool, bool);
955 static void c_parser_declspecs (c_parser
*, struct c_declspecs
*, bool, bool,
957 static struct c_typespec
c_parser_enum_specifier (c_parser
*);
958 static struct c_typespec
c_parser_struct_or_union_specifier (c_parser
*);
959 static tree
c_parser_struct_declaration (c_parser
*);
960 static struct c_typespec
c_parser_typeof_specifier (c_parser
*);
961 static struct c_declarator
*c_parser_declarator (c_parser
*, bool, c_dtr_syn
,
963 static struct c_declarator
*c_parser_direct_declarator (c_parser
*, bool,
965 static struct c_declarator
*c_parser_direct_declarator_inner (c_parser
*,
967 struct c_declarator
*);
968 static struct c_arg_info
*c_parser_parms_declarator (c_parser
*, bool, tree
);
969 static struct c_arg_info
*c_parser_parms_list_declarator (c_parser
*, tree
);
970 static struct c_parm
*c_parser_parameter_declaration (c_parser
*, tree
);
971 static tree
c_parser_simple_asm_expr (c_parser
*);
972 static tree
c_parser_attributes (c_parser
*);
973 static struct c_type_name
*c_parser_type_name (c_parser
*);
974 static struct c_expr
c_parser_initializer (c_parser
*);
975 static struct c_expr
c_parser_braced_init (c_parser
*, tree
, bool);
976 static void c_parser_initelt (c_parser
*);
977 static void c_parser_initval (c_parser
*, struct c_expr
*);
978 static tree
c_parser_compound_statement (c_parser
*);
979 static void c_parser_compound_statement_nostart (c_parser
*);
980 static void c_parser_label (c_parser
*);
981 static void c_parser_statement (c_parser
*);
982 static void c_parser_statement_after_labels (c_parser
*);
983 static void c_parser_if_statement (c_parser
*);
984 static void c_parser_switch_statement (c_parser
*);
985 static void c_parser_while_statement (c_parser
*);
986 static void c_parser_do_statement (c_parser
*);
987 static void c_parser_for_statement (c_parser
*);
988 static tree
c_parser_asm_statement (c_parser
*);
989 static tree
c_parser_asm_operands (c_parser
*, bool);
990 static tree
c_parser_asm_clobbers (c_parser
*);
991 static struct c_expr
c_parser_expr_no_commas (c_parser
*, struct c_expr
*);
992 static struct c_expr
c_parser_conditional_expression (c_parser
*,
994 static struct c_expr
c_parser_binary_expression (c_parser
*, struct c_expr
*);
995 static struct c_expr
c_parser_cast_expression (c_parser
*, struct c_expr
*);
996 static struct c_expr
c_parser_unary_expression (c_parser
*);
997 static struct c_expr
c_parser_sizeof_expression (c_parser
*);
998 static struct c_expr
c_parser_alignof_expression (c_parser
*);
999 static struct c_expr
c_parser_postfix_expression (c_parser
*);
1000 static struct c_expr
c_parser_postfix_expression_after_paren_type (c_parser
*,
1001 struct c_type_name
*);
1002 static struct c_expr
c_parser_postfix_expression_after_primary (c_parser
*,
1004 static struct c_expr
c_parser_expression (c_parser
*);
1005 static struct c_expr
c_parser_expression_conv (c_parser
*);
1006 static tree
c_parser_expr_list (c_parser
*, bool);
1007 static void c_parser_omp_construct (c_parser
*);
1008 static void c_parser_omp_threadprivate (c_parser
*);
1009 static void c_parser_omp_barrier (c_parser
*);
1010 static void c_parser_omp_flush (c_parser
*);
1012 enum pragma_context
{ pragma_external
, pragma_stmt
, pragma_compound
};
1013 static bool c_parser_pragma (c_parser
*, enum pragma_context
);
1015 /* These Objective-C parser functions are only ever called when
1016 compiling Objective-C. */
1017 static void c_parser_objc_class_definition (c_parser
*);
1018 static void c_parser_objc_class_instance_variables (c_parser
*);
1019 static void c_parser_objc_class_declaration (c_parser
*);
1020 static void c_parser_objc_alias_declaration (c_parser
*);
1021 static void c_parser_objc_protocol_definition (c_parser
*);
1022 static enum tree_code
c_parser_objc_method_type (c_parser
*);
1023 static void c_parser_objc_method_definition (c_parser
*);
1024 static void c_parser_objc_methodprotolist (c_parser
*);
1025 static void c_parser_objc_methodproto (c_parser
*);
1026 static tree
c_parser_objc_method_decl (c_parser
*);
1027 static tree
c_parser_objc_type_name (c_parser
*);
1028 static tree
c_parser_objc_protocol_refs (c_parser
*);
1029 static void c_parser_objc_try_catch_statement (c_parser
*);
1030 static void c_parser_objc_synchronized_statement (c_parser
*);
1031 static tree
c_parser_objc_selector (c_parser
*);
1032 static tree
c_parser_objc_selector_arg (c_parser
*);
1033 static tree
c_parser_objc_receiver (c_parser
*);
1034 static tree
c_parser_objc_message_args (c_parser
*);
1035 static tree
c_parser_objc_keywordexpr (c_parser
*);
1037 /* Parse a translation unit (C90 6.7, C99 6.9).
1040 external-declarations
1042 external-declarations:
1043 external-declaration
1044 external-declarations external-declaration
1053 c_parser_translation_unit (c_parser
*parser
)
1055 if (c_parser_next_token_is (parser
, CPP_EOF
))
1058 pedwarn ("ISO C forbids an empty source file");
1062 void *obstack_position
= obstack_alloc (&parser_obstack
, 0);
1066 c_parser_external_declaration (parser
);
1067 obstack_free (&parser_obstack
, obstack_position
);
1069 while (c_parser_next_token_is_not (parser
, CPP_EOF
));
1073 /* Parse an external declaration (C90 6.7, C99 6.9).
1075 external-declaration:
1081 external-declaration:
1084 __extension__ external-declaration
1088 external-declaration:
1089 objc-class-definition
1090 objc-class-declaration
1091 objc-alias-declaration
1092 objc-protocol-definition
1093 objc-method-definition
1098 c_parser_external_declaration (c_parser
*parser
)
1101 switch (c_parser_peek_token (parser
)->type
)
1104 switch (c_parser_peek_token (parser
)->keyword
)
1107 ext
= disable_extension_diagnostics ();
1108 c_parser_consume_token (parser
);
1109 c_parser_external_declaration (parser
);
1110 restore_extension_diagnostics (ext
);
1113 c_parser_asm_definition (parser
);
1115 case RID_AT_INTERFACE
:
1116 case RID_AT_IMPLEMENTATION
:
1117 gcc_assert (c_dialect_objc ());
1118 c_parser_objc_class_definition (parser
);
1121 gcc_assert (c_dialect_objc ());
1122 c_parser_objc_class_declaration (parser
);
1125 gcc_assert (c_dialect_objc ());
1126 c_parser_objc_alias_declaration (parser
);
1128 case RID_AT_PROTOCOL
:
1129 gcc_assert (c_dialect_objc ());
1130 c_parser_objc_protocol_definition (parser
);
1133 gcc_assert (c_dialect_objc ());
1134 c_parser_consume_token (parser
);
1135 objc_finish_implementation ();
1143 pedwarn ("ISO C does not allow extra %<;%> outside of a function");
1144 c_parser_consume_token (parser
);
1147 c_parser_pragma (parser
, pragma_external
);
1151 if (c_dialect_objc ())
1153 c_parser_objc_method_definition (parser
);
1156 /* Else fall through, and yield a syntax error trying to parse
1157 as a declaration or function definition. */
1160 /* A declaration or a function definition. We can only tell
1161 which after parsing the declaration specifiers, if any, and
1162 the first declarator. */
1163 c_parser_declaration_or_fndef (parser
, true, true, false, true);
1169 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1170 6.7, 6.9.1). If FNDEF_OK is true, a function definition is
1171 accepted; otherwise (old-style parameter declarations) only other
1172 declarations are accepted. If NESTED is true, we are inside a
1173 function or parsing old-style parameter declarations; any functions
1174 encountered are nested functions and declaration specifiers are
1175 required; otherwise we are at top level and functions are normal
1176 functions and declaration specifiers may be optional. If EMPTY_OK
1177 is true, empty declarations are OK (subject to all other
1178 constraints); otherwise (old-style parameter declarations) they are
1179 diagnosed. If START_ATTR_OK is true, the declaration specifiers
1180 may start with attributes; otherwise they may not.
1183 declaration-specifiers init-declarator-list[opt] ;
1185 function-definition:
1186 declaration-specifiers[opt] declarator declaration-list[opt]
1191 declaration-list declaration
1193 init-declarator-list:
1195 init-declarator-list , init-declarator
1198 declarator simple-asm-expr[opt] attributes[opt]
1199 declarator simple-asm-expr[opt] attributes[opt] = initializer
1203 nested-function-definition:
1204 declaration-specifiers declarator declaration-list[opt]
1207 The simple-asm-expr and attributes are GNU extensions.
1209 This function does not handle __extension__; that is handled in its
1210 callers. ??? Following the old parser, __extension__ may start
1211 external declarations, declarations in functions and declarations
1212 at the start of "for" loops, but not old-style parameter
1215 C99 requires declaration specifiers in a function definition; the
1216 absence is diagnosed through the diagnosis of implicit int. In GNU
1217 C we also allow but diagnose declarations without declaration
1218 specifiers, but only at top level (elsewhere they conflict with
1224 threadprivate-directive */
1227 c_parser_declaration_or_fndef (c_parser
*parser
, bool fndef_ok
, bool empty_ok
,
1228 bool nested
, bool start_attr_ok
)
1230 struct c_declspecs
*specs
;
1232 tree all_prefix_attrs
;
1233 bool diagnosed_no_specs
= false;
1235 specs
= build_null_declspecs ();
1236 c_parser_declspecs (parser
, specs
, true, true, start_attr_ok
);
1239 c_parser_skip_to_end_of_block_or_statement (parser
);
1242 if (nested
&& !specs
->declspecs_seen_p
)
1244 c_parser_error (parser
, "expected declaration specifiers");
1245 c_parser_skip_to_end_of_block_or_statement (parser
);
1248 finish_declspecs (specs
);
1249 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1255 shadow_tag_warned (specs
, 1);
1256 pedwarn ("empty declaration");
1258 c_parser_consume_token (parser
);
1261 pending_xref_error ();
1262 prefix_attrs
= specs
->attrs
;
1263 all_prefix_attrs
= prefix_attrs
;
1264 specs
->attrs
= NULL_TREE
;
1267 struct c_declarator
*declarator
;
1270 /* Declaring either one or more declarators (in which case we
1271 should diagnose if there were no declaration specifiers) or a
1272 function definition (in which case the diagnostic for
1273 implicit int suffices). */
1274 declarator
= c_parser_declarator (parser
, specs
->type_seen_p
,
1275 C_DTR_NORMAL
, &dummy
);
1276 if (declarator
== NULL
)
1278 c_parser_skip_to_end_of_block_or_statement (parser
);
1281 if (c_parser_next_token_is (parser
, CPP_EQ
)
1282 || c_parser_next_token_is (parser
, CPP_COMMA
)
1283 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
1284 || c_parser_next_token_is_keyword (parser
, RID_ASM
)
1285 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1287 tree asm_name
= NULL_TREE
;
1288 tree postfix_attrs
= NULL_TREE
;
1289 if (!diagnosed_no_specs
&& !specs
->declspecs_seen_p
)
1291 diagnosed_no_specs
= true;
1292 pedwarn ("data definition has no type or storage class");
1294 /* Having seen a data definition, there cannot now be a
1295 function definition. */
1297 if (c_parser_next_token_is_keyword (parser
, RID_ASM
))
1298 asm_name
= c_parser_simple_asm_expr (parser
);
1299 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1300 postfix_attrs
= c_parser_attributes (parser
);
1301 if (c_parser_next_token_is (parser
, CPP_EQ
))
1305 c_parser_consume_token (parser
);
1306 /* The declaration of the variable is in effect while
1307 its initializer is parsed. */
1308 d
= start_decl (declarator
, specs
, true,
1309 chainon (postfix_attrs
, all_prefix_attrs
));
1311 d
= error_mark_node
;
1312 start_init (d
, asm_name
, global_bindings_p ());
1313 init
= c_parser_initializer (parser
);
1315 if (d
!= error_mark_node
)
1317 maybe_warn_string_init (TREE_TYPE (d
), init
);
1318 finish_decl (d
, init
.value
, asm_name
);
1323 tree d
= start_decl (declarator
, specs
, false,
1324 chainon (postfix_attrs
,
1327 finish_decl (d
, NULL_TREE
, asm_name
);
1329 if (c_parser_next_token_is (parser
, CPP_COMMA
))
1331 c_parser_consume_token (parser
);
1332 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1333 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
1336 all_prefix_attrs
= prefix_attrs
;
1339 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1341 c_parser_consume_token (parser
);
1346 c_parser_error (parser
, "expected %<,%> or %<;%>");
1347 c_parser_skip_to_end_of_block_or_statement (parser
);
1353 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, "
1354 "%<asm%> or %<__attribute__%>");
1355 c_parser_skip_to_end_of_block_or_statement (parser
);
1358 /* Function definition (nested or otherwise). */
1362 pedwarn ("ISO C forbids nested functions");
1363 push_function_context ();
1365 if (!start_function (specs
, declarator
, all_prefix_attrs
))
1367 /* This can appear in many cases looking nothing like a
1368 function definition, so we don't give a more specific
1369 error suggesting there was one. */
1370 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
1371 "or %<__attribute__%>");
1373 pop_function_context ();
1376 /* Parse old-style parameter declarations. ??? Attributes are
1377 not allowed to start declaration specifiers here because of a
1378 syntax conflict between a function declaration with attribute
1379 suffix and a function definition with an attribute prefix on
1380 first old-style parameter declaration. Following the old
1381 parser, they are not accepted on subsequent old-style
1382 parameter declarations either. However, there is no
1383 ambiguity after the first declaration, nor indeed on the
1384 first as long as we don't allow postfix attributes after a
1385 declarator with a nonempty identifier list in a definition;
1386 and postfix attributes have never been accepted here in
1387 function definitions either. */
1388 while (c_parser_next_token_is_not (parser
, CPP_EOF
)
1389 && c_parser_next_token_is_not (parser
, CPP_OPEN_BRACE
))
1390 c_parser_declaration_or_fndef (parser
, false, false, true, false);
1391 DECL_SOURCE_LOCATION (current_function_decl
)
1392 = c_parser_peek_token (parser
)->location
;
1393 store_parm_decls ();
1394 fnbody
= c_parser_compound_statement (parser
);
1397 tree decl
= current_function_decl
;
1400 pop_function_context ();
1401 add_stmt (build_stmt (DECL_EXPR
, decl
));
1412 /* Parse an asm-definition (asm() outside a function body). This is a
1420 c_parser_asm_definition (c_parser
*parser
)
1422 tree asm_str
= c_parser_simple_asm_expr (parser
);
1424 cgraph_add_asm_node (asm_str
);
1425 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
1428 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
1429 6.7), adding them to SPECS (which may already include some).
1430 Storage class specifiers are accepted iff SCSPEC_OK; type
1431 specifiers are accepted iff TYPESPEC_OK; attributes are accepted at
1432 the start iff START_ATTR_OK.
1434 declaration-specifiers:
1435 storage-class-specifier declaration-specifiers[opt]
1436 type-specifier declaration-specifiers[opt]
1437 type-qualifier declaration-specifiers[opt]
1438 function-specifier declaration-specifiers[opt]
1440 Function specifiers (inline) are from C99, and are currently
1441 handled as storage class specifiers, as is __thread.
1443 C90 6.5.1, C99 6.7.1:
1444 storage-class-specifier:
1455 C90 6.5.2, C99 6.7.2:
1468 [_Imaginary removed in C99 TC2]
1469 struct-or-union-specifier
1473 (_Bool and _Complex are new in C99.)
1475 C90 6.5.3, C99 6.7.3:
1482 (restrict is new in C99.)
1486 declaration-specifiers:
1487 attributes declaration-specifiers[opt]
1489 storage-class-specifier:
1501 class-name objc-protocol-refs[opt]
1502 typedef-name objc-protocol-refs
1507 c_parser_declspecs (c_parser
*parser
, struct c_declspecs
*specs
,
1508 bool scspec_ok
, bool typespec_ok
, bool start_attr_ok
)
1510 bool attrs_ok
= start_attr_ok
;
1511 bool seen_type
= specs
->type_seen_p
;
1512 while (c_parser_next_token_is (parser
, CPP_NAME
)
1513 || c_parser_next_token_is (parser
, CPP_KEYWORD
)
1514 || (c_dialect_objc () && c_parser_next_token_is (parser
, CPP_LESS
)))
1516 struct c_typespec t
;
1518 if (c_parser_next_token_is (parser
, CPP_NAME
))
1520 tree value
= c_parser_peek_token (parser
)->value
;
1521 c_id_kind kind
= c_parser_peek_token (parser
)->id_kind
;
1522 /* This finishes the specifiers unless a type name is OK, it
1523 is declared as a type name and a type name hasn't yet
1525 if (!typespec_ok
|| seen_type
1526 || (kind
!= C_ID_TYPENAME
&& kind
!= C_ID_CLASSNAME
))
1528 c_parser_consume_token (parser
);
1531 if (kind
== C_ID_TYPENAME
1532 && (!c_dialect_objc ()
1533 || c_parser_next_token_is_not (parser
, CPP_LESS
)))
1535 t
.kind
= ctsk_typedef
;
1536 /* For a typedef name, record the meaning, not the name.
1537 In case of 'foo foo, bar;'. */
1538 t
.spec
= lookup_name (value
);
1542 tree proto
= NULL_TREE
;
1543 gcc_assert (c_dialect_objc ());
1545 if (c_parser_next_token_is (parser
, CPP_LESS
))
1546 proto
= c_parser_objc_protocol_refs (parser
);
1547 t
.spec
= objc_get_protocol_qualified_type (value
, proto
);
1549 declspecs_add_type (specs
, t
);
1552 if (c_parser_next_token_is (parser
, CPP_LESS
))
1554 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
1555 nisse@lysator.liu.se. */
1557 gcc_assert (c_dialect_objc ());
1558 if (!typespec_ok
|| seen_type
)
1560 proto
= c_parser_objc_protocol_refs (parser
);
1562 t
.spec
= objc_get_protocol_qualified_type (NULL_TREE
, proto
);
1563 declspecs_add_type (specs
, t
);
1566 gcc_assert (c_parser_next_token_is (parser
, CPP_KEYWORD
));
1567 switch (c_parser_peek_token (parser
)->keyword
)
1579 /* TODO: Distinguish between function specifiers (inline)
1580 and storage class specifiers, either here or in
1581 declspecs_add_scspec. */
1582 declspecs_add_scspec (specs
, c_parser_peek_token (parser
)->value
);
1583 c_parser_consume_token (parser
);
1603 if (c_dialect_objc ())
1604 parser
->objc_need_raw_identifier
= true;
1605 t
.kind
= ctsk_resword
;
1606 t
.spec
= c_parser_peek_token (parser
)->value
;
1607 declspecs_add_type (specs
, t
);
1608 c_parser_consume_token (parser
);
1615 t
= c_parser_enum_specifier (parser
);
1616 declspecs_add_type (specs
, t
);
1624 t
= c_parser_struct_or_union_specifier (parser
);
1625 declspecs_add_type (specs
, t
);
1628 /* ??? The old parser rejected typeof after other type
1629 specifiers, but is a syntax error the best way of
1631 if (!typespec_ok
|| seen_type
)
1635 t
= c_parser_typeof_specifier (parser
);
1636 declspecs_add_type (specs
, t
);
1642 declspecs_add_qual (specs
, c_parser_peek_token (parser
)->value
);
1643 c_parser_consume_token (parser
);
1648 attrs
= c_parser_attributes (parser
);
1649 declspecs_add_attrs (specs
, attrs
);
1658 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
1661 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
1662 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
1663 enum attributes[opt] identifier
1665 The form with trailing comma is new in C99. The forms with
1666 attributes are GNU extensions. In GNU C, we accept any expression
1667 without commas in the syntax (assignment expressions, not just
1668 conditional expressions); assignment expressions will be diagnosed
1673 enumerator-list , enumerator
1676 enumeration-constant
1677 enumeration-constant = constant-expression
1680 static struct c_typespec
1681 c_parser_enum_specifier (c_parser
*parser
)
1683 struct c_typespec ret
;
1685 tree ident
= NULL_TREE
;
1686 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ENUM
));
1687 c_parser_consume_token (parser
);
1688 attrs
= c_parser_attributes (parser
);
1689 if (c_parser_next_token_is (parser
, CPP_NAME
))
1691 ident
= c_parser_peek_token (parser
)->value
;
1692 c_parser_consume_token (parser
);
1694 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
1696 /* Parse an enum definition. */
1697 struct c_enum_contents the_enum
;
1698 tree type
= start_enum (&the_enum
, ident
);
1700 /* We chain the enumerators in reverse order, then put them in
1701 forward order at the end. */
1702 tree values
= NULL_TREE
;
1703 c_parser_consume_token (parser
);
1710 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
1712 c_parser_error (parser
, "expected identifier");
1713 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
1714 values
= error_mark_node
;
1717 enum_id
= c_parser_peek_token (parser
)->value
;
1718 c_parser_consume_token (parser
);
1719 if (c_parser_next_token_is (parser
, CPP_EQ
))
1721 c_parser_consume_token (parser
);
1722 enum_value
= c_parser_expr_no_commas (parser
, NULL
).value
;
1725 enum_value
= NULL_TREE
;
1726 enum_decl
= build_enumerator (&the_enum
, enum_id
, enum_value
);
1727 TREE_CHAIN (enum_decl
) = values
;
1730 if (c_parser_next_token_is (parser
, CPP_COMMA
))
1733 c_parser_consume_token (parser
);
1735 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
1737 if (seen_comma
&& pedantic
&& !flag_isoc99
)
1738 pedwarn ("comma at end of enumerator list");
1739 c_parser_consume_token (parser
);
1744 c_parser_error (parser
, "expected %<,%> or %<}%>");
1745 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
1746 values
= error_mark_node
;
1750 postfix_attrs
= c_parser_attributes (parser
);
1751 ret
.spec
= finish_enum (type
, nreverse (values
),
1752 chainon (attrs
, postfix_attrs
));
1753 ret
.kind
= ctsk_tagdef
;
1758 c_parser_error (parser
, "expected %<{%>");
1759 ret
.spec
= error_mark_node
;
1760 ret
.kind
= ctsk_tagref
;
1763 ret
= parser_xref_tag (ENUMERAL_TYPE
, ident
);
1764 /* In ISO C, enumerated types can be referred to only if already
1766 if (pedantic
&& !COMPLETE_TYPE_P (ret
.spec
))
1767 pedwarn ("ISO C forbids forward references to %<enum%> types");
1771 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
1773 struct-or-union-specifier:
1774 struct-or-union attributes[opt] identifier[opt]
1775 { struct-contents } attributes[opt]
1776 struct-or-union attributes[opt] identifier
1779 struct-declaration-list
1781 struct-declaration-list:
1782 struct-declaration ;
1783 struct-declaration-list struct-declaration ;
1790 struct-declaration-list struct-declaration
1792 struct-declaration-list:
1793 struct-declaration-list ;
1796 (Note that in the syntax here, unlike that in ISO C, the semicolons
1797 are included here rather than in struct-declaration, in order to
1798 describe the syntax with extra semicolons and missing semicolon at
1803 struct-declaration-list:
1804 @defs ( class-name )
1806 (Note this does not include a trailing semicolon, but can be
1807 followed by further declarations, and gets a pedwarn-if-pedantic
1808 when followed by a semicolon.) */
1810 static struct c_typespec
1811 c_parser_struct_or_union_specifier (c_parser
*parser
)
1813 struct c_typespec ret
;
1815 tree ident
= NULL_TREE
;
1816 enum tree_code code
;
1817 switch (c_parser_peek_token (parser
)->keyword
)
1828 c_parser_consume_token (parser
);
1829 attrs
= c_parser_attributes (parser
);
1830 if (c_parser_next_token_is (parser
, CPP_NAME
))
1832 ident
= c_parser_peek_token (parser
)->value
;
1833 c_parser_consume_token (parser
);
1835 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
1837 /* Parse a struct or union definition. Start the scope of the
1838 tag before parsing components. */
1839 tree type
= start_struct (code
, ident
);
1841 /* We chain the components in reverse order, then put them in
1842 forward order at the end. Each struct-declaration may
1843 declare multiple components (comma-separated), so we must use
1844 chainon to join them, although when parsing each
1845 struct-declaration we can use TREE_CHAIN directly.
1847 The theory behind all this is that there will be more
1848 semicolon separated fields than comma separated fields, and
1849 so we'll be minimizing the number of node traversals required
1851 tree contents
= NULL_TREE
;
1852 c_parser_consume_token (parser
);
1853 /* Handle the Objective-C @defs construct,
1854 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
1855 if (c_parser_next_token_is_keyword (parser
, RID_AT_DEFS
))
1858 gcc_assert (c_dialect_objc ());
1859 c_parser_consume_token (parser
);
1860 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
1862 if (c_parser_next_token_is (parser
, CPP_NAME
)
1863 && c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
)
1865 name
= c_parser_peek_token (parser
)->value
;
1866 c_parser_consume_token (parser
);
1870 c_parser_error (parser
, "expected class name");
1871 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
1874 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
1876 contents
= nreverse (objc_get_class_ivars (name
));
1879 /* Parse the struct-declarations and semicolons. Problems with
1880 semicolons are diagnosed here; empty structures are diagnosed
1885 /* Parse any stray semicolon. */
1886 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1889 pedwarn ("extra semicolon in struct or union specified");
1890 c_parser_consume_token (parser
);
1893 /* Stop if at the end of the struct or union contents. */
1894 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
1896 c_parser_consume_token (parser
);
1899 /* Accept #pragmas at struct scope. */
1900 if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
1902 c_parser_pragma (parser
, pragma_external
);
1905 /* Parse some comma-separated declarations, but not the
1906 trailing semicolon if any. */
1907 decls
= c_parser_struct_declaration (parser
);
1908 contents
= chainon (decls
, contents
);
1909 /* If no semicolon follows, either we have a parse error or
1910 are at the end of the struct or union and should
1912 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1913 c_parser_consume_token (parser
);
1916 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
1917 pedwarn ("no semicolon at end of struct or union");
1920 c_parser_error (parser
, "expected %<;%>");
1921 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
1926 postfix_attrs
= c_parser_attributes (parser
);
1927 ret
.spec
= finish_struct (type
, nreverse (contents
),
1928 chainon (attrs
, postfix_attrs
));
1929 ret
.kind
= ctsk_tagdef
;
1934 c_parser_error (parser
, "expected %<{%>");
1935 ret
.spec
= error_mark_node
;
1936 ret
.kind
= ctsk_tagref
;
1939 ret
= parser_xref_tag (code
, ident
);
1943 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
1944 the trailing semicolon.
1947 specifier-qualifier-list struct-declarator-list
1949 specifier-qualifier-list:
1950 type-specifier specifier-qualifier-list[opt]
1951 type-qualifier specifier-qualifier-list[opt]
1952 attributes specifier-qualifier-list[opt]
1954 struct-declarator-list:
1956 struct-declarator-list , attributes[opt] struct-declarator
1959 declarator attributes[opt]
1960 declarator[opt] : constant-expression attributes[opt]
1965 __extension__ struct-declaration
1966 specifier-qualifier-list
1968 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
1969 of attributes where shown is a GNU extension. In GNU C, we accept
1970 any expression without commas in the syntax (assignment
1971 expressions, not just conditional expressions); assignment
1972 expressions will be diagnosed as non-constant. */
1975 c_parser_struct_declaration (c_parser
*parser
)
1977 struct c_declspecs
*specs
;
1979 tree all_prefix_attrs
;
1981 if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
1985 ext
= disable_extension_diagnostics ();
1986 c_parser_consume_token (parser
);
1987 decl
= c_parser_struct_declaration (parser
);
1988 restore_extension_diagnostics (ext
);
1991 specs
= build_null_declspecs ();
1992 c_parser_declspecs (parser
, specs
, false, true, true);
1995 if (!specs
->declspecs_seen_p
)
1997 c_parser_error (parser
, "expected specifier-qualifier-list");
2000 finish_declspecs (specs
);
2001 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2004 if (!specs
->type_seen_p
)
2007 pedwarn ("ISO C forbids member declarations with no members");
2008 shadow_tag_warned (specs
, pedantic
);
2013 /* Support for unnamed structs or unions as members of
2014 structs or unions (which is [a] useful and [b] supports
2016 ret
= grokfield (build_id_declarator (NULL_TREE
), specs
, NULL_TREE
);
2020 pending_xref_error ();
2021 prefix_attrs
= specs
->attrs
;
2022 all_prefix_attrs
= prefix_attrs
;
2023 specs
->attrs
= NULL_TREE
;
2027 /* Declaring one or more declarators or un-named bit-fields. */
2028 struct c_declarator
*declarator
;
2030 if (c_parser_next_token_is (parser
, CPP_COLON
))
2031 declarator
= build_id_declarator (NULL_TREE
);
2033 declarator
= c_parser_declarator (parser
, specs
->type_seen_p
,
2034 C_DTR_NORMAL
, &dummy
);
2035 if (declarator
== NULL
)
2037 c_parser_skip_to_end_of_block_or_statement (parser
);
2040 if (c_parser_next_token_is (parser
, CPP_COLON
)
2041 || c_parser_next_token_is (parser
, CPP_COMMA
)
2042 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2043 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
)
2044 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2046 tree postfix_attrs
= NULL_TREE
;
2047 tree width
= NULL_TREE
;
2049 if (c_parser_next_token_is (parser
, CPP_COLON
))
2051 c_parser_consume_token (parser
);
2052 width
= c_parser_expr_no_commas (parser
, NULL
).value
;
2054 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2055 postfix_attrs
= c_parser_attributes (parser
);
2056 d
= grokfield (declarator
, specs
, width
);
2057 decl_attributes (&d
, chainon (postfix_attrs
,
2058 all_prefix_attrs
), 0);
2059 TREE_CHAIN (d
) = decls
;
2061 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2062 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
2065 all_prefix_attrs
= prefix_attrs
;
2066 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2067 c_parser_consume_token (parser
);
2068 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2069 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2071 /* Semicolon consumed in caller. */
2076 c_parser_error (parser
, "expected %<,%>, %<;%> or %<}%>");
2082 c_parser_error (parser
,
2083 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
2084 "%<__attribute__%>");
2091 /* Parse a typeof specifier (a GNU extension).
2094 typeof ( expression )
2095 typeof ( type-name )
2098 static struct c_typespec
2099 c_parser_typeof_specifier (c_parser
*parser
)
2101 struct c_typespec ret
;
2102 ret
.kind
= ctsk_typeof
;
2103 ret
.spec
= error_mark_node
;
2104 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TYPEOF
));
2105 c_parser_consume_token (parser
);
2108 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2114 if (c_parser_next_token_starts_typename (parser
))
2116 struct c_type_name
*type
= c_parser_type_name (parser
);
2121 ret
.spec
= groktypename (type
);
2122 pop_maybe_used (variably_modified_type_p (ret
.spec
, NULL_TREE
));
2128 struct c_expr expr
= c_parser_expression (parser
);
2131 if (TREE_CODE (expr
.value
) == COMPONENT_REF
2132 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
2133 error ("%<typeof%> applied to a bit-field");
2134 ret
.spec
= TREE_TYPE (expr
.value
);
2135 was_vm
= variably_modified_type_p (ret
.spec
, NULL_TREE
);
2136 /* This should be returned with the type so that when the type
2137 is evaluated, this can be evaluated. For now, we avoid
2138 evaluation when the context might. */
2139 if (!skip_evaluation
&& was_vm
)
2141 tree e
= expr
.value
;
2143 /* If the expression is not of a type to which we cannot assign a line
2144 number, wrap the thing in a no-op NOP_EXPR. */
2145 if (DECL_P (e
) || CONSTANT_CLASS_P (e
))
2146 e
= build1 (NOP_EXPR
, void_type_node
, e
);
2148 if (CAN_HAVE_LOCATION_P (e
))
2149 SET_EXPR_LOCATION (e
, input_location
);
2153 pop_maybe_used (was_vm
);
2155 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
2159 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
2160 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
2161 be redeclared; otherwise it may not. KIND indicates which kind of
2162 declarator is wanted. Returns a valid declarator except in the
2163 case of a syntax error in which case NULL is returned. *SEEN_ID is
2164 set to true if an identifier being declared is seen; this is used
2165 to diagnose bad forms of abstract array declarators and to
2166 determine whether an identifier list is syntactically permitted.
2169 pointer[opt] direct-declarator
2173 ( attributes[opt] declarator )
2174 direct-declarator array-declarator
2175 direct-declarator ( parameter-type-list )
2176 direct-declarator ( identifier-list[opt] )
2179 * type-qualifier-list[opt]
2180 * type-qualifier-list[opt] pointer
2182 type-qualifier-list:
2185 type-qualifier-list type-qualifier
2186 type-qualifier-list attributes
2188 parameter-type-list:
2190 parameter-list , ...
2193 parameter-declaration
2194 parameter-list , parameter-declaration
2196 parameter-declaration:
2197 declaration-specifiers declarator attributes[opt]
2198 declaration-specifiers abstract-declarator[opt] attributes[opt]
2202 identifier-list , identifier
2204 abstract-declarator:
2206 pointer[opt] direct-abstract-declarator
2208 direct-abstract-declarator:
2209 ( attributes[opt] abstract-declarator )
2210 direct-abstract-declarator[opt] array-declarator
2211 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
2216 direct-declarator ( parameter-forward-declarations
2217 parameter-type-list[opt] )
2219 direct-abstract-declarator:
2220 direct-abstract-declarator[opt] ( parameter-forward-declarations
2221 parameter-type-list[opt] )
2223 parameter-forward-declarations:
2225 parameter-forward-declarations parameter-list ;
2227 The uses of attributes shown above are GNU extensions.
2229 Some forms of array declarator are not included in C99 in the
2230 syntax for abstract declarators; these are disallowed elsewhere.
2231 This may be a defect (DR#289).
2233 This function also accepts an omitted abstract declarator as being
2234 an abstract declarator, although not part of the formal syntax. */
2236 static struct c_declarator
*
2237 c_parser_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
2240 /* Parse any initial pointer part. */
2241 if (c_parser_next_token_is (parser
, CPP_MULT
))
2243 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
2244 struct c_declarator
*inner
;
2245 c_parser_consume_token (parser
);
2246 c_parser_declspecs (parser
, quals_attrs
, false, false, true);
2247 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
2251 return make_pointer_declarator (quals_attrs
, inner
);
2253 /* Now we have a direct declarator, direct abstract declarator or
2254 nothing (which counts as a direct abstract declarator here). */
2255 return c_parser_direct_declarator (parser
, type_seen_p
, kind
, seen_id
);
2258 /* Parse a direct declarator or direct abstract declarator; arguments
2259 as c_parser_declarator. */
2261 static struct c_declarator
*
2262 c_parser_direct_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
2265 /* The direct declarator must start with an identifier (possibly
2266 omitted) or a parenthesized declarator (possibly abstract). In
2267 an ordinary declarator, initial parentheses must start a
2268 parenthesized declarator. In an abstract declarator or parameter
2269 declarator, they could start a parenthesized declarator or a
2270 parameter list. To tell which, the open parenthesis and any
2271 following attributes must be read. If a declaration specifier
2272 follows, then it is a parameter list; if the specifier is a
2273 typedef name, there might be an ambiguity about redeclaring it,
2274 which is resolved in the direction of treating it as a typedef
2275 name. If a close parenthesis follows, it is also an empty
2276 parameter list, as the syntax does not permit empty abstract
2277 declarators. Otherwise, it is a parenthesized declarator (in
2278 which case the analysis may be repeated inside it, recursively).
2280 ??? There is an ambiguity in a parameter declaration "int
2281 (__attribute__((foo)) x)", where x is not a typedef name: it
2282 could be an abstract declarator for a function, or declare x with
2283 parentheses. The proper resolution of this ambiguity needs
2284 documenting. At present we follow an accident of the old
2285 parser's implementation, whereby the first parameter must have
2286 some declaration specifiers other than just attributes. Thus as
2287 a parameter declaration it is treated as a parenthesized
2288 parameter named x, and as an abstract declarator it is
2291 ??? Also following the old parser, attributes inside an empty
2292 parameter list are ignored, making it a list not yielding a
2293 prototype, rather than giving an error or making it have one
2294 parameter with implicit type int.
2296 ??? Also following the old parser, typedef names may be
2297 redeclared in declarators, but not Objective-C class names. */
2299 if (kind
!= C_DTR_ABSTRACT
2300 && c_parser_next_token_is (parser
, CPP_NAME
)
2302 && c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
)
2303 || c_parser_peek_token (parser
)->id_kind
== C_ID_ID
))
2305 struct c_declarator
*inner
2306 = build_id_declarator (c_parser_peek_token (parser
)->value
);
2308 inner
->id_loc
= c_parser_peek_token (parser
)->location
;
2309 c_parser_consume_token (parser
);
2310 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
2313 if (kind
!= C_DTR_NORMAL
2314 && c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
2316 struct c_declarator
*inner
= build_id_declarator (NULL_TREE
);
2317 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
2320 /* Either we are at the end of an abstract declarator, or we have
2323 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
2326 struct c_declarator
*inner
;
2327 c_parser_consume_token (parser
);
2328 attrs
= c_parser_attributes (parser
);
2329 if (kind
!= C_DTR_NORMAL
2330 && (c_parser_next_token_starts_declspecs (parser
)
2331 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
)))
2333 struct c_arg_info
*args
2334 = c_parser_parms_declarator (parser
, kind
== C_DTR_NORMAL
,
2341 = build_function_declarator (args
,
2342 build_id_declarator (NULL_TREE
));
2343 return c_parser_direct_declarator_inner (parser
, *seen_id
,
2347 /* A parenthesized declarator. */
2348 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
2349 if (inner
!= NULL
&& attrs
!= NULL
)
2350 inner
= build_attrs_declarator (attrs
, inner
);
2351 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2353 c_parser_consume_token (parser
);
2357 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
2361 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2368 if (kind
== C_DTR_NORMAL
)
2370 c_parser_error (parser
, "expected identifier or %<(%>");
2374 return build_id_declarator (NULL_TREE
);
2378 /* Parse part of a direct declarator or direct abstract declarator,
2379 given that some (in INNER) has already been parsed; ID_PRESENT is
2380 true if an identifier is present, false for an abstract
2383 static struct c_declarator
*
2384 c_parser_direct_declarator_inner (c_parser
*parser
, bool id_present
,
2385 struct c_declarator
*inner
)
2387 /* Parse a sequence of array declarators and parameter lists. */
2388 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
2390 struct c_declarator
*declarator
;
2391 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
2395 c_parser_consume_token (parser
);
2396 c_parser_declspecs (parser
, quals_attrs
, false, false, true);
2397 static_seen
= c_parser_next_token_is_keyword (parser
, RID_STATIC
);
2399 c_parser_consume_token (parser
);
2400 if (static_seen
&& !quals_attrs
->declspecs_seen_p
)
2401 c_parser_declspecs (parser
, quals_attrs
, false, false, true);
2402 if (!quals_attrs
->declspecs_seen_p
)
2404 /* If "static" is present, there must be an array dimension.
2405 Otherwise, there may be a dimension, "*", or no
2410 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
2414 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
2419 else if (c_parser_next_token_is (parser
, CPP_MULT
))
2421 if (c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_SQUARE
)
2425 c_parser_consume_token (parser
);
2430 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
2436 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
2439 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
2440 c_parser_consume_token (parser
);
2443 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
2447 declarator
= build_array_declarator (dimen
, quals_attrs
, static_seen
,
2449 if (declarator
== NULL
)
2451 inner
= set_array_declarator_inner (declarator
, inner
, !id_present
);
2452 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
2454 else if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
2457 struct c_arg_info
*args
;
2458 c_parser_consume_token (parser
);
2459 attrs
= c_parser_attributes (parser
);
2460 args
= c_parser_parms_declarator (parser
, id_present
, attrs
);
2465 inner
= build_function_declarator (args
, inner
);
2466 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
2472 /* Parse a parameter list or identifier list, including the closing
2473 parenthesis but not the opening one. ATTRS are the attributes at
2474 the start of the list. ID_LIST_OK is true if an identifier list is
2475 acceptable; such a list must not have attributes at the start. */
2477 static struct c_arg_info
*
2478 c_parser_parms_declarator (c_parser
*parser
, bool id_list_ok
, tree attrs
)
2481 declare_parm_level ();
2482 /* If the list starts with an identifier, it is an identifier list.
2483 Otherwise, it is either a prototype list or an empty list. */
2486 && c_parser_next_token_is (parser
, CPP_NAME
)
2487 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
2489 tree list
= NULL_TREE
, *nextp
= &list
;
2490 while (c_parser_next_token_is (parser
, CPP_NAME
)
2491 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
2493 *nextp
= build_tree_list (NULL_TREE
,
2494 c_parser_peek_token (parser
)->value
);
2495 nextp
= & TREE_CHAIN (*nextp
);
2496 c_parser_consume_token (parser
);
2497 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
2499 c_parser_consume_token (parser
);
2500 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2502 c_parser_error (parser
, "expected identifier");
2506 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2508 struct c_arg_info
*ret
= XOBNEW (&parser_obstack
, struct c_arg_info
);
2513 ret
->pending_sizes
= 0;
2514 ret
->had_vla_unspec
= 0;
2515 c_parser_consume_token (parser
);
2521 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2529 struct c_arg_info
*ret
= c_parser_parms_list_declarator (parser
, attrs
);
2535 /* Parse a parameter list (possibly empty), including the closing
2536 parenthesis but not the opening one. ATTRS are the attributes at
2537 the start of the list. */
2539 static struct c_arg_info
*
2540 c_parser_parms_list_declarator (c_parser
*parser
, tree attrs
)
2542 bool good_parm
= false;
2543 /* ??? Following the old parser, forward parameter declarations may
2544 use abstract declarators, and if no real parameter declarations
2545 follow the forward declarations then this is not diagnosed. Also
2546 note as above that attributes are ignored as the only contents of
2547 the parentheses, or as the only contents after forward
2549 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2551 struct c_arg_info
*ret
= XOBNEW (&parser_obstack
, struct c_arg_info
);
2556 ret
->pending_sizes
= 0;
2557 ret
->had_vla_unspec
= 0;
2558 c_parser_consume_token (parser
);
2561 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
2563 struct c_arg_info
*ret
= XOBNEW (&parser_obstack
, struct c_arg_info
);
2567 ret
->pending_sizes
= 0;
2568 ret
->had_vla_unspec
= 0;
2569 /* Suppress -Wold-style-definition for this case. */
2570 ret
->types
= error_mark_node
;
2571 error ("ISO C requires a named argument before %<...%>");
2572 c_parser_consume_token (parser
);
2573 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2575 c_parser_consume_token (parser
);
2580 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2585 /* Nonempty list of parameters, either terminated with semicolon
2586 (forward declarations; recurse) or with close parenthesis (normal
2587 function) or with ", ... )" (variadic function). */
2590 /* Parse a parameter. */
2591 struct c_parm
*parm
= c_parser_parameter_declaration (parser
, attrs
);
2596 push_parm_decl (parm
);
2598 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2601 c_parser_consume_token (parser
);
2602 mark_forward_parm_decls ();
2603 new_attrs
= c_parser_attributes (parser
);
2604 return c_parser_parms_list_declarator (parser
, new_attrs
);
2606 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2608 c_parser_consume_token (parser
);
2610 return get_parm_info (false);
2613 struct c_arg_info
*ret
2614 = XOBNEW (&parser_obstack
, struct c_arg_info
);
2619 ret
->pending_sizes
= 0;
2620 ret
->had_vla_unspec
= 0;
2624 if (!c_parser_require (parser
, CPP_COMMA
,
2625 "expected %<;%>, %<,%> or %<)%>"))
2627 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2630 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
2632 c_parser_consume_token (parser
);
2633 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2635 c_parser_consume_token (parser
);
2637 return get_parm_info (true);
2640 struct c_arg_info
*ret
2641 = XOBNEW (&parser_obstack
, struct c_arg_info
);
2646 ret
->pending_sizes
= 0;
2647 ret
->had_vla_unspec
= 0;
2653 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2661 /* Parse a parameter declaration. ATTRS are the attributes at the
2662 start of the declaration if it is the first parameter. */
2664 static struct c_parm
*
2665 c_parser_parameter_declaration (c_parser
*parser
, tree attrs
)
2667 struct c_declspecs
*specs
;
2668 struct c_declarator
*declarator
;
2670 tree postfix_attrs
= NULL_TREE
;
2672 if (!c_parser_next_token_starts_declspecs (parser
))
2674 /* ??? In some Objective-C cases '...' isn't applicable so there
2675 should be a different message. */
2676 c_parser_error (parser
,
2677 "expected declaration specifiers or %<...%>");
2678 c_parser_skip_to_end_of_parameter (parser
);
2681 specs
= build_null_declspecs ();
2684 declspecs_add_attrs (specs
, attrs
);
2687 c_parser_declspecs (parser
, specs
, true, true, true);
2688 finish_declspecs (specs
);
2689 pending_xref_error ();
2690 prefix_attrs
= specs
->attrs
;
2691 specs
->attrs
= NULL_TREE
;
2692 declarator
= c_parser_declarator (parser
, specs
->type_seen_p
,
2693 C_DTR_PARM
, &dummy
);
2694 if (declarator
== NULL
)
2696 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
2699 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2700 postfix_attrs
= c_parser_attributes (parser
);
2701 return build_c_parm (specs
, chainon (postfix_attrs
, prefix_attrs
),
2705 /* Parse a string literal in an asm expression. It should not be
2706 translated, and wide string literals are an error although
2707 permitted by the syntax. This is a GNU extension.
2712 ??? At present, following the old parser, the caller needs to have
2713 set c_lex_string_translate to 0. It would be better to follow the
2714 C++ parser rather than using the c_lex_string_translate kludge. */
2717 c_parser_asm_string_literal (c_parser
*parser
)
2720 if (c_parser_next_token_is (parser
, CPP_STRING
))
2722 str
= c_parser_peek_token (parser
)->value
;
2723 c_parser_consume_token (parser
);
2725 else if (c_parser_next_token_is (parser
, CPP_WSTRING
))
2727 error ("wide string literal in %<asm%>");
2728 str
= build_string (1, "");
2729 c_parser_consume_token (parser
);
2733 c_parser_error (parser
, "expected string literal");
2739 /* Parse a simple asm expression. This is used in restricted
2740 contexts, where a full expression with inputs and outputs does not
2741 make sense. This is a GNU extension.
2744 asm ( asm-string-literal )
2748 c_parser_simple_asm_expr (c_parser
*parser
)
2751 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
2752 /* ??? Follow the C++ parser rather than using the
2753 c_lex_string_translate kludge. */
2754 c_lex_string_translate
= 0;
2755 c_parser_consume_token (parser
);
2756 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2758 c_lex_string_translate
= 1;
2761 str
= c_parser_asm_string_literal (parser
);
2762 c_lex_string_translate
= 1;
2763 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
2765 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2771 /* Parse (possibly empty) attributes. This is a GNU extension.
2775 attributes attribute
2778 __attribute__ ( ( attribute-list ) )
2782 attribute_list , attrib
2787 any-word ( identifier )
2788 any-word ( identifier , nonempty-expr-list )
2789 any-word ( expr-list )
2791 where the "identifier" must not be declared as a type, and
2792 "any-word" may be any identifier (including one declared as a
2793 type), a reserved word storage class specifier, type specifier or
2794 type qualifier. ??? This still leaves out most reserved keywords
2795 (following the old parser), shouldn't we include them, and why not
2796 allow identifiers declared as types to start the arguments? */
2799 c_parser_attributes (c_parser
*parser
)
2801 tree attrs
= NULL_TREE
;
2802 while (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2804 /* ??? Follow the C++ parser rather than using the
2805 c_lex_string_translate kludge. */
2806 c_lex_string_translate
= 0;
2807 c_parser_consume_token (parser
);
2808 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2810 c_lex_string_translate
= 1;
2813 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2815 c_lex_string_translate
= 1;
2816 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2819 /* Parse the attribute list. */
2820 while (c_parser_next_token_is (parser
, CPP_COMMA
)
2821 || c_parser_next_token_is (parser
, CPP_NAME
)
2822 || c_parser_next_token_is (parser
, CPP_KEYWORD
))
2824 tree attr
, attr_name
, attr_args
;
2825 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2827 c_parser_consume_token (parser
);
2830 if (c_parser_next_token_is (parser
, CPP_KEYWORD
))
2832 /* ??? See comment above about what keywords are
2835 switch (c_parser_peek_token (parser
)->keyword
)
2870 attr_name
= c_parser_peek_token (parser
)->value
;
2871 c_parser_consume_token (parser
);
2872 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
2874 attr
= build_tree_list (attr_name
, NULL_TREE
);
2875 attrs
= chainon (attrs
, attr
);
2878 c_parser_consume_token (parser
);
2879 /* Parse the attribute contents. If they start with an
2880 identifier which is followed by a comma or close
2881 parenthesis, then the arguments start with that
2882 identifier; otherwise they are an expression list. */
2883 if (c_parser_next_token_is (parser
, CPP_NAME
)
2884 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
2885 && ((c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
)
2886 || (c_parser_peek_2nd_token (parser
)->type
2887 == CPP_CLOSE_PAREN
)))
2889 tree arg1
= c_parser_peek_token (parser
)->value
;
2890 c_parser_consume_token (parser
);
2891 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2892 attr_args
= build_tree_list (NULL_TREE
, arg1
);
2895 c_parser_consume_token (parser
);
2896 attr_args
= tree_cons (NULL_TREE
, arg1
,
2897 c_parser_expr_list (parser
, false));
2902 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2903 attr_args
= NULL_TREE
;
2905 attr_args
= c_parser_expr_list (parser
, false);
2907 attr
= build_tree_list (attr_name
, attr_args
);
2908 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2909 c_parser_consume_token (parser
);
2912 c_lex_string_translate
= 1;
2913 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2917 attrs
= chainon (attrs
, attr
);
2919 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2920 c_parser_consume_token (parser
);
2923 c_lex_string_translate
= 1;
2924 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2928 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2929 c_parser_consume_token (parser
);
2932 c_lex_string_translate
= 1;
2933 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2937 c_lex_string_translate
= 1;
2942 /* Parse a type name (C90 6.5.5, C99 6.7.6).
2945 specifier-qualifier-list abstract-declarator[opt]
2948 static struct c_type_name
*
2949 c_parser_type_name (c_parser
*parser
)
2951 struct c_declspecs
*specs
= build_null_declspecs ();
2952 struct c_declarator
*declarator
;
2953 struct c_type_name
*ret
;
2955 c_parser_declspecs (parser
, specs
, false, true, true);
2956 if (!specs
->declspecs_seen_p
)
2958 c_parser_error (parser
, "expected specifier-qualifier-list");
2961 pending_xref_error ();
2962 finish_declspecs (specs
);
2963 declarator
= c_parser_declarator (parser
, specs
->type_seen_p
,
2964 C_DTR_ABSTRACT
, &dummy
);
2965 if (declarator
== NULL
)
2967 ret
= XOBNEW (&parser_obstack
, struct c_type_name
);
2969 ret
->declarator
= declarator
;
2973 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
2976 assignment-expression
2977 { initializer-list }
2978 { initializer-list , }
2981 designation[opt] initializer
2982 initializer-list , designation[opt] initializer
2989 designator-list designator
2996 [ constant-expression ]
3008 [ constant-expression ... constant-expression ]
3010 Any expression without commas is accepted in the syntax for the
3011 constant-expressions, with non-constant expressions rejected later.
3013 This function is only used for top-level initializers; for nested
3014 ones, see c_parser_initval. */
3016 static struct c_expr
3017 c_parser_initializer (c_parser
*parser
)
3019 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
3020 return c_parser_braced_init (parser
, NULL_TREE
, false);
3024 ret
= c_parser_expr_no_commas (parser
, NULL
);
3025 if (TREE_CODE (ret
.value
) != STRING_CST
3026 && TREE_CODE (ret
.value
) != COMPOUND_LITERAL_EXPR
)
3027 ret
= default_function_array_conversion (ret
);
3032 /* Parse a braced initializer list. TYPE is the type specified for a
3033 compound literal, and NULL_TREE for other initializers and for
3034 nested braced lists. NESTED_P is true for nested braced lists,
3035 false for the list of a compound literal or the list that is the
3036 top-level initializer in a declaration. */
3038 static struct c_expr
3039 c_parser_braced_init (c_parser
*parser
, tree type
, bool nested_p
)
3041 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
3042 c_parser_consume_token (parser
);
3044 push_init_level (0);
3046 really_start_incremental_init (type
);
3047 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3050 pedwarn ("ISO C forbids empty initializer braces");
3054 /* Parse a non-empty initializer list, possibly with a trailing
3058 c_parser_initelt (parser
);
3061 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3062 c_parser_consume_token (parser
);
3065 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3069 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
3072 ret
.value
= error_mark_node
;
3073 ret
.original_code
= ERROR_MARK
;
3074 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
3077 c_parser_consume_token (parser
);
3078 return pop_init_level (0);
3081 /* Parse a nested initializer, including designators. */
3084 c_parser_initelt (c_parser
*parser
)
3086 /* Parse any designator or designator list. A single array
3087 designator may have the subsequent "=" omitted in GNU C, but a
3088 longer list or a structure member designator may not. */
3089 if (c_parser_next_token_is (parser
, CPP_NAME
)
3090 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
3092 /* Old-style structure member designator. */
3093 set_init_label (c_parser_peek_token (parser
)->value
);
3095 pedwarn ("obsolete use of designated initializer with %<:%>");
3096 c_parser_consume_token (parser
);
3097 c_parser_consume_token (parser
);
3101 /* des_seen is 0 if there have been no designators, 1 if there
3102 has been a single array designator and 2 otherwise. */
3104 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
)
3105 || c_parser_next_token_is (parser
, CPP_DOT
))
3107 int des_prev
= des_seen
;
3110 if (c_parser_next_token_is (parser
, CPP_DOT
))
3113 c_parser_consume_token (parser
);
3114 if (c_parser_next_token_is (parser
, CPP_NAME
))
3116 set_init_label (c_parser_peek_token (parser
)->value
);
3117 c_parser_consume_token (parser
);
3122 init
.value
= error_mark_node
;
3123 init
.original_code
= ERROR_MARK
;
3124 c_parser_error (parser
, "expected identifier");
3125 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3126 process_init_element (init
);
3133 /* ??? Following the old parser, [ objc-receiver
3134 objc-message-args ] is accepted as an initializer,
3135 being distinguished from a designator by what follows
3136 the first assignment expression inside the square
3137 brackets, but after a first array designator a
3138 subsequent square bracket is for Objective-C taken to
3139 start an expression, using the obsolete form of
3140 designated initializer without '=', rather than
3141 possibly being a second level of designation: in LALR
3142 terms, the '[' is shifted rather than reducing
3143 designator to designator-list. */
3144 if (des_prev
== 1 && c_dialect_objc ())
3146 des_seen
= des_prev
;
3149 if (des_prev
== 0 && c_dialect_objc ())
3151 /* This might be an array designator or an
3152 Objective-C message expression. If the former,
3153 continue parsing here; if the latter, parse the
3154 remainder of the initializer given the starting
3155 primary-expression. ??? It might make sense to
3156 distinguish when des_prev == 1 as well; see
3157 previous comment. */
3159 struct c_expr mexpr
;
3160 c_parser_consume_token (parser
);
3161 if (c_parser_peek_token (parser
)->type
== CPP_NAME
3162 && ((c_parser_peek_token (parser
)->id_kind
3164 || (c_parser_peek_token (parser
)->id_kind
3165 == C_ID_CLASSNAME
)))
3167 /* Type name receiver. */
3168 tree id
= c_parser_peek_token (parser
)->value
;
3169 c_parser_consume_token (parser
);
3170 rec
= objc_get_class_reference (id
);
3171 goto parse_message_args
;
3173 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
3174 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
)
3175 || c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3176 goto array_desig_after_first
;
3177 /* Expression receiver. So far only one part
3178 without commas has been parsed; there might be
3179 more of the expression. */
3181 while (c_parser_next_token_is (parser
, CPP_COMMA
))
3184 c_parser_consume_token (parser
);
3185 next
= c_parser_expr_no_commas (parser
, NULL
);
3186 next
= default_function_array_conversion (next
);
3187 rec
= build_compound_expr (rec
, next
.value
);
3190 /* Now parse the objc-message-args. */
3191 args
= c_parser_objc_message_args (parser
);
3192 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3195 = objc_build_message_expr (build_tree_list (rec
, args
));
3196 mexpr
.original_code
= ERROR_MARK
;
3197 /* Now parse and process the remainder of the
3198 initializer, starting with this message
3199 expression as a primary-expression. */
3200 c_parser_initval (parser
, &mexpr
);
3203 c_parser_consume_token (parser
);
3204 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
3205 array_desig_after_first
:
3206 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3208 c_parser_consume_token (parser
);
3209 second
= c_parser_expr_no_commas (parser
, NULL
).value
;
3213 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3215 c_parser_consume_token (parser
);
3216 set_init_index (first
, second
);
3217 if (pedantic
&& second
)
3218 pedwarn ("ISO C forbids specifying range of "
3219 "elements to initialize");
3222 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3228 if (c_parser_next_token_is (parser
, CPP_EQ
))
3230 if (pedantic
&& !flag_isoc99
)
3231 pedwarn ("ISO C90 forbids specifying subobject to initialize");
3232 c_parser_consume_token (parser
);
3239 pedwarn ("obsolete use of designated initializer "
3245 init
.value
= error_mark_node
;
3246 init
.original_code
= ERROR_MARK
;
3247 c_parser_error (parser
, "expected %<=%>");
3248 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3249 process_init_element (init
);
3255 c_parser_initval (parser
, NULL
);
3258 /* Parse a nested initializer; as c_parser_initializer but parses
3259 initializers within braced lists, after any designators have been
3260 applied. If AFTER is not NULL then it is an Objective-C message
3261 expression which is the primary-expression starting the
3265 c_parser_initval (c_parser
*parser
, struct c_expr
*after
)
3268 gcc_assert (!after
|| c_dialect_objc ());
3269 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
) && !after
)
3270 init
= c_parser_braced_init (parser
, NULL_TREE
, true);
3273 init
= c_parser_expr_no_commas (parser
, after
);
3274 if (init
.value
!= NULL_TREE
3275 && TREE_CODE (init
.value
) != STRING_CST
3276 && TREE_CODE (init
.value
) != COMPOUND_LITERAL_EXPR
)
3277 init
= default_function_array_conversion (init
);
3279 process_init_element (init
);
3282 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
3286 { block-item-list[opt] }
3287 { label-declarations block-item-list }
3291 block-item-list block-item
3303 { label-declarations block-item-list }
3306 __extension__ nested-declaration
3307 nested-function-definition
3311 label-declarations label-declaration
3314 __label__ identifier-list ;
3316 Allowing the mixing of declarations and code is new in C99. The
3317 GNU syntax also permits (not shown above) labels at the end of
3318 compound statements, which yield an error. We don't allow labels
3319 on declarations; this might seem like a natural extension, but
3320 there would be a conflict between attributes on the label and
3321 prefix attributes on the declaration. ??? The syntax follows the
3322 old parser in requiring something after label declarations.
3323 Although they are erroneous if the labels declared aren't defined,
3324 is it useful for the syntax to be this way?
3336 c_parser_compound_statement (c_parser
*parser
)
3339 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
3340 return error_mark_node
;
3341 stmt
= c_begin_compound_stmt (true);
3342 c_parser_compound_statement_nostart (parser
);
3343 return c_end_compound_stmt (stmt
, true);
3346 /* Parse a compound statement except for the opening brace. This is
3347 used for parsing both compound statements and statement expressions
3348 (which follow different paths to handling the opening). */
3351 c_parser_compound_statement_nostart (c_parser
*parser
)
3353 bool last_stmt
= false;
3354 bool last_label
= false;
3355 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3357 c_parser_consume_token (parser
);
3360 if (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
3362 /* Read zero or more forward-declarations for labels that nested
3363 functions can jump to. */
3364 while (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
3366 c_parser_consume_token (parser
);
3367 /* Any identifiers, including those declared as type names,
3372 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
3374 c_parser_error (parser
, "expected identifier");
3378 = declare_label (c_parser_peek_token (parser
)->value
);
3379 C_DECLARED_LABEL_FLAG (label
) = 1;
3380 add_stmt (build_stmt (DECL_EXPR
, label
));
3381 c_parser_consume_token (parser
);
3382 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3383 c_parser_consume_token (parser
);
3387 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
3389 /* ??? Locating this diagnostic on the token after the
3390 declarations end follows the old parser, but it might be
3391 better to locate it where the declarations start instead. */
3393 pedwarn ("ISO C forbids label declarations");
3395 /* We must now have at least one statement, label or declaration. */
3396 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3398 c_parser_error (parser
, "expected declaration or statement");
3399 c_parser_consume_token (parser
);
3402 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
3404 location_t loc
= c_parser_peek_token (parser
)->location
;
3405 if (c_parser_next_token_is_keyword (parser
, RID_CASE
)
3406 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
3407 || (c_parser_next_token_is (parser
, CPP_NAME
)
3408 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
3412 c_parser_label (parser
);
3414 else if (!last_label
3415 && c_parser_next_token_starts_declspecs (parser
))
3418 c_parser_declaration_or_fndef (parser
, true, true, true, true);
3420 && ((pedantic
&& !flag_isoc99
)
3421 || warn_declaration_after_statement
))
3422 pedwarn_c90 ("%HISO C90 forbids mixed declarations and code",
3426 else if (!last_label
3427 && c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
3429 /* __extension__ can start a declaration, but is also an
3430 unary operator that can start an expression. Consume all
3431 but the last of a possible series of __extension__ to
3433 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
3434 && (c_parser_peek_2nd_token (parser
)->keyword
3436 c_parser_consume_token (parser
);
3437 if (c_token_starts_declspecs (c_parser_peek_2nd_token (parser
)))
3440 ext
= disable_extension_diagnostics ();
3441 c_parser_consume_token (parser
);
3443 c_parser_declaration_or_fndef (parser
, true, true, true, true);
3444 /* Following the old parser, __extension__ does not
3445 disable this diagnostic. */
3446 restore_extension_diagnostics (ext
);
3448 && ((pedantic
&& !flag_isoc99
)
3449 || warn_declaration_after_statement
))
3450 pedwarn_c90 ("%HISO C90 forbids mixed declarations and code",
3457 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
3459 /* External pragmas, and some omp pragmas, are not associated
3460 with regular c code, and so are not to be considered statements
3461 syntactically. This ensures that the user doesn't put them
3462 places that would turn into syntax errors if the directive
3464 if (c_parser_pragma (parser
, pragma_compound
))
3465 last_label
= false, last_stmt
= true;
3467 else if (c_parser_next_token_is (parser
, CPP_EOF
))
3469 c_parser_error (parser
, "expected declaration or statement");
3477 c_parser_statement_after_labels (parser
);
3480 parser
->error
= false;
3483 error ("label at end of compound statement");
3484 c_parser_consume_token (parser
);
3487 /* Parse a label (C90 6.6.1, C99 6.8.1).
3490 identifier : attributes[opt]
3491 case constant-expression :
3497 case constant-expression ... constant-expression :
3499 The use of attributes on labels is a GNU extension. The syntax in
3500 GNU C accepts any expressions without commas, non-constant
3501 expressions being rejected later. */
3504 c_parser_label (c_parser
*parser
)
3506 location_t loc1
= c_parser_peek_token (parser
)->location
;
3507 tree label
= NULL_TREE
;
3508 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
3511 c_parser_consume_token (parser
);
3512 exp1
= c_parser_expr_no_commas (parser
, NULL
).value
;
3513 if (c_parser_next_token_is (parser
, CPP_COLON
))
3515 c_parser_consume_token (parser
);
3516 label
= do_case (exp1
, NULL_TREE
);
3518 else if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3520 c_parser_consume_token (parser
);
3521 exp2
= c_parser_expr_no_commas (parser
, NULL
).value
;
3522 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
3523 label
= do_case (exp1
, exp2
);
3526 c_parser_error (parser
, "expected %<:%> or %<...%>");
3528 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
3530 c_parser_consume_token (parser
);
3531 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
3532 label
= do_case (NULL_TREE
, NULL_TREE
);
3536 tree name
= c_parser_peek_token (parser
)->value
;
3540 gcc_assert (c_parser_next_token_is (parser
, CPP_NAME
));
3541 c_parser_consume_token (parser
);
3542 gcc_assert (c_parser_next_token_is (parser
, CPP_COLON
));
3543 loc2
= c_parser_peek_token (parser
)->location
;
3544 c_parser_consume_token (parser
);
3545 attrs
= c_parser_attributes (parser
);
3546 tlab
= define_label (loc2
, name
);
3549 decl_attributes (&tlab
, attrs
, 0);
3550 label
= add_stmt (build_stmt (LABEL_EXPR
, tlab
));
3554 SET_EXPR_LOCATION (label
, loc1
);
3557 /* Parse a statement (C90 6.6, C99 6.8).
3562 expression-statement
3570 expression-statement:
3573 selection-statement:
3577 iteration-statement:
3586 return expression[opt] ;
3599 objc-throw-statement
3600 objc-try-catch-statement
3601 objc-synchronized-statement
3603 objc-throw-statement:
3617 parallel-for-construct
3618 parallel-sections-construct
3625 parallel-directive structured-block
3628 for-directive iteration-statement
3631 sections-directive section-scope
3634 single-directive structured-block
3636 parallel-for-construct:
3637 parallel-for-directive iteration-statement
3639 parallel-sections-construct:
3640 parallel-sections-directive section-scope
3643 master-directive structured-block
3646 critical-directive structured-block
3649 atomic-directive expression-statement
3652 ordered-directive structured-block */
3655 c_parser_statement (c_parser
*parser
)
3657 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
3658 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
3659 || (c_parser_next_token_is (parser
, CPP_NAME
)
3660 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
3661 c_parser_label (parser
);
3662 c_parser_statement_after_labels (parser
);
3665 /* Parse a statement, other than a labeled statement. */
3668 c_parser_statement_after_labels (c_parser
*parser
)
3670 location_t loc
= c_parser_peek_token (parser
)->location
;
3671 tree stmt
= NULL_TREE
;
3672 switch (c_parser_peek_token (parser
)->type
)
3674 case CPP_OPEN_BRACE
:
3675 add_stmt (c_parser_compound_statement (parser
));
3678 switch (c_parser_peek_token (parser
)->keyword
)
3681 c_parser_if_statement (parser
);
3684 c_parser_switch_statement (parser
);
3687 c_parser_while_statement (parser
);
3690 c_parser_do_statement (parser
);
3693 c_parser_for_statement (parser
);
3696 c_parser_consume_token (parser
);
3697 if (c_parser_next_token_is (parser
, CPP_NAME
))
3699 stmt
= c_finish_goto_label (c_parser_peek_token (parser
)->value
);
3700 c_parser_consume_token (parser
);
3702 else if (c_parser_next_token_is (parser
, CPP_MULT
))
3704 c_parser_consume_token (parser
);
3705 stmt
= c_finish_goto_ptr (c_parser_expression (parser
).value
);
3708 c_parser_error (parser
, "expected identifier or %<*%>");
3709 goto expect_semicolon
;
3711 c_parser_consume_token (parser
);
3712 stmt
= c_finish_bc_stmt (&c_cont_label
, false);
3713 goto expect_semicolon
;
3715 c_parser_consume_token (parser
);
3716 stmt
= c_finish_bc_stmt (&c_break_label
, true);
3717 goto expect_semicolon
;
3719 c_parser_consume_token (parser
);
3720 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3722 stmt
= c_finish_return (NULL_TREE
);
3723 c_parser_consume_token (parser
);
3727 stmt
= c_finish_return (c_parser_expression_conv (parser
).value
);
3728 goto expect_semicolon
;
3732 stmt
= c_parser_asm_statement (parser
);
3735 gcc_assert (c_dialect_objc ());
3736 c_parser_consume_token (parser
);
3737 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3739 stmt
= objc_build_throw_stmt (NULL_TREE
);
3740 c_parser_consume_token (parser
);
3745 = objc_build_throw_stmt (c_parser_expression (parser
).value
);
3746 goto expect_semicolon
;
3750 gcc_assert (c_dialect_objc ());
3751 c_parser_objc_try_catch_statement (parser
);
3753 case RID_AT_SYNCHRONIZED
:
3754 gcc_assert (c_dialect_objc ());
3755 c_parser_objc_synchronized_statement (parser
);
3762 c_parser_consume_token (parser
);
3764 case CPP_CLOSE_PAREN
:
3765 case CPP_CLOSE_SQUARE
:
3766 /* Avoid infinite loop in error recovery:
3767 c_parser_skip_until_found stops at a closing nesting
3768 delimiter without consuming it, but here we need to consume
3769 it to proceed further. */
3770 c_parser_error (parser
, "expected statement");
3771 c_parser_consume_token (parser
);
3774 c_parser_pragma (parser
, pragma_stmt
);
3778 stmt
= c_finish_expr_stmt (c_parser_expression_conv (parser
).value
);
3780 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
3783 /* Two cases cannot and do not have line numbers associated: If stmt
3784 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
3785 cannot hold line numbers. But that's OK because the statement
3786 will either be changed to a MODIFY_EXPR during gimplification of
3787 the statement expr, or discarded. If stmt was compound, but
3788 without new variables, we will have skipped the creation of a
3789 BIND and will have a bare STATEMENT_LIST. But that's OK because
3790 (recursively) all of the component statements should already have
3791 line numbers assigned. ??? Can we discard no-op statements
3793 if (stmt
&& CAN_HAVE_LOCATION_P (stmt
))
3794 SET_EXPR_LOCATION (stmt
, loc
);
3797 /* Parse a parenthesized condition from an if, do or while statement.
3803 c_parser_paren_condition (c_parser
*parser
)
3807 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3808 return error_mark_node
;
3809 loc
= c_parser_peek_token (parser
)->location
;
3810 cond
= c_objc_common_truthvalue_conversion
3811 (c_parser_expression_conv (parser
).value
);
3812 if (CAN_HAVE_LOCATION_P (cond
))
3813 SET_EXPR_LOCATION (cond
, loc
);
3814 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
3818 /* Parse a statement which is a block in C99. */
3821 c_parser_c99_block_statement (c_parser
*parser
)
3823 tree block
= c_begin_compound_stmt (flag_isoc99
);
3824 c_parser_statement (parser
);
3825 return c_end_compound_stmt (block
, flag_isoc99
);
3828 /* Parse the body of an if statement or the else half thereof. This
3829 is just parsing a statement but (a) it is a block in C99, (b) we
3830 track whether the body is an if statement for the sake of
3831 -Wparentheses warnings, (c) we handle an empty body specially for
3832 the sake of -Wempty-body warnings. */
3835 c_parser_if_body (c_parser
*parser
, bool *if_p
)
3837 tree block
= c_begin_compound_stmt (flag_isoc99
);
3838 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
3839 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
3840 || (c_parser_next_token_is (parser
, CPP_NAME
)
3841 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
3842 c_parser_label (parser
);
3843 *if_p
= c_parser_next_token_is_keyword (parser
, RID_IF
);
3844 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3845 add_stmt (build_empty_stmt ());
3846 c_parser_statement_after_labels (parser
);
3847 return c_end_compound_stmt (block
, flag_isoc99
);
3850 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
3853 if ( expression ) statement
3854 if ( expression ) statement else statement
3858 c_parser_if_statement (c_parser
*parser
)
3863 bool first_if
= false, second_if
= false;
3864 tree first_body
, second_body
;
3865 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_IF
));
3866 c_parser_consume_token (parser
);
3867 block
= c_begin_compound_stmt (flag_isoc99
);
3868 loc
= c_parser_peek_token (parser
)->location
;
3869 cond
= c_parser_paren_condition (parser
);
3870 first_body
= c_parser_if_body (parser
, &first_if
);
3871 if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
3873 c_parser_consume_token (parser
);
3874 second_body
= c_parser_if_body (parser
, &second_if
);
3877 second_body
= NULL_TREE
;
3878 c_finish_if_stmt (loc
, cond
, first_body
, second_body
, first_if
);
3879 add_stmt (c_end_compound_stmt (block
, flag_isoc99
));
3882 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
3885 switch (expression) statement
3889 c_parser_switch_statement (c_parser
*parser
)
3891 tree block
, expr
, body
, save_break
;
3892 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SWITCH
));
3893 c_parser_consume_token (parser
);
3894 block
= c_begin_compound_stmt (flag_isoc99
);
3895 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3897 expr
= c_parser_expression (parser
).value
;
3898 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
3901 expr
= error_mark_node
;
3902 c_start_case (expr
);
3903 save_break
= c_break_label
;
3904 c_break_label
= NULL_TREE
;
3905 body
= c_parser_c99_block_statement (parser
);
3906 c_finish_case (body
);
3908 add_stmt (build1 (LABEL_EXPR
, void_type_node
, c_break_label
));
3909 c_break_label
= save_break
;
3910 add_stmt (c_end_compound_stmt (block
, flag_isoc99
));
3913 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
3916 while (expression) statement
3920 c_parser_while_statement (c_parser
*parser
)
3922 tree block
, cond
, body
, save_break
, save_cont
;
3924 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_WHILE
));
3925 c_parser_consume_token (parser
);
3926 block
= c_begin_compound_stmt (flag_isoc99
);
3927 loc
= c_parser_peek_token (parser
)->location
;
3928 cond
= c_parser_paren_condition (parser
);
3929 save_break
= c_break_label
;
3930 c_break_label
= NULL_TREE
;
3931 save_cont
= c_cont_label
;
3932 c_cont_label
= NULL_TREE
;
3933 body
= c_parser_c99_block_statement (parser
);
3934 c_finish_loop (loc
, cond
, NULL
, body
, c_break_label
, c_cont_label
, true);
3935 add_stmt (c_end_compound_stmt (block
, flag_isoc99
));
3936 c_break_label
= save_break
;
3937 c_cont_label
= save_cont
;
3940 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
3943 do statement while ( expression ) ;
3947 c_parser_do_statement (c_parser
*parser
)
3949 tree block
, cond
, body
, save_break
, save_cont
, new_break
, new_cont
;
3951 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_DO
));
3952 c_parser_consume_token (parser
);
3953 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3954 warning (OPT_Wempty_body
,
3955 "suggest braces around empty body in %<do%> statement");
3956 block
= c_begin_compound_stmt (flag_isoc99
);
3957 loc
= c_parser_peek_token (parser
)->location
;
3958 save_break
= c_break_label
;
3959 c_break_label
= NULL_TREE
;
3960 save_cont
= c_cont_label
;
3961 c_cont_label
= NULL_TREE
;
3962 body
= c_parser_c99_block_statement (parser
);
3963 c_parser_require_keyword (parser
, RID_WHILE
, "expected %<while%>");
3964 new_break
= c_break_label
;
3965 c_break_label
= save_break
;
3966 new_cont
= c_cont_label
;
3967 c_cont_label
= save_cont
;
3968 cond
= c_parser_paren_condition (parser
);
3969 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
3970 c_parser_skip_to_end_of_block_or_statement (parser
);
3971 c_finish_loop (loc
, cond
, NULL
, body
, new_break
, new_cont
, false);
3972 add_stmt (c_end_compound_stmt (block
, flag_isoc99
));
3975 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
3978 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
3979 for ( nested-declaration expression[opt] ; expression[opt] ) statement
3981 The form with a declaration is new in C99.
3983 ??? In accordance with the old parser, the declaration may be a
3984 nested function, which is then rejected in check_for_loop_decls,
3985 but does it make any sense for this to be included in the grammar?
3986 Note in particular that the nested function does not include a
3987 trailing ';', whereas the "declaration" production includes one.
3988 Also, can we reject bad declarations earlier and cheaper than
3989 check_for_loop_decls? */
3992 c_parser_for_statement (c_parser
*parser
)
3994 tree block
, cond
, incr
, save_break
, save_cont
, body
;
3996 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_FOR
));
3997 loc
= c_parser_peek_token (parser
)->location
;
3998 c_parser_consume_token (parser
);
3999 block
= c_begin_compound_stmt (flag_isoc99
);
4000 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4002 /* Parse the initialization declaration or expression. */
4003 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4005 c_parser_consume_token (parser
);
4006 c_finish_expr_stmt (NULL_TREE
);
4008 else if (c_parser_next_token_starts_declspecs (parser
))
4010 c_parser_declaration_or_fndef (parser
, true, true, true, true);
4011 check_for_loop_decls ();
4013 else if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
4015 /* __extension__ can start a declaration, but is also an
4016 unary operator that can start an expression. Consume all
4017 but the last of a possible series of __extension__ to
4019 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
4020 && (c_parser_peek_2nd_token (parser
)->keyword
4022 c_parser_consume_token (parser
);
4023 if (c_token_starts_declspecs (c_parser_peek_2nd_token (parser
)))
4026 ext
= disable_extension_diagnostics ();
4027 c_parser_consume_token (parser
);
4028 c_parser_declaration_or_fndef (parser
, true, true, true, true);
4029 restore_extension_diagnostics (ext
);
4030 check_for_loop_decls ();
4038 c_finish_expr_stmt (c_parser_expression (parser
).value
);
4039 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4041 /* Parse the loop condition. */
4042 loc
= c_parser_peek_token (parser
)->location
;
4043 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4045 c_parser_consume_token (parser
);
4050 tree ocond
= c_parser_expression_conv (parser
).value
;
4051 cond
= c_objc_common_truthvalue_conversion (ocond
);
4052 if (CAN_HAVE_LOCATION_P (cond
))
4053 SET_EXPR_LOCATION (cond
, loc
);
4054 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4056 /* Parse the increment expression. */
4057 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4058 incr
= c_process_expr_stmt (NULL_TREE
);
4060 incr
= c_process_expr_stmt (c_parser_expression (parser
).value
);
4061 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4065 cond
= error_mark_node
;
4066 incr
= error_mark_node
;
4068 save_break
= c_break_label
;
4069 c_break_label
= NULL_TREE
;
4070 save_cont
= c_cont_label
;
4071 c_cont_label
= NULL_TREE
;
4072 body
= c_parser_c99_block_statement (parser
);
4073 c_finish_loop (loc
, cond
, incr
, body
, c_break_label
, c_cont_label
, true);
4074 add_stmt (c_end_compound_stmt (block
, flag_isoc99
));
4075 c_break_label
= save_break
;
4076 c_cont_label
= save_cont
;
4079 /* Parse an asm statement, a GNU extension. This is a full-blown asm
4080 statement with inputs, outputs, clobbers, and volatile tag
4084 asm type-qualifier[opt] ( asm-argument ) ;
4088 asm-string-literal : asm-operands[opt]
4089 asm-string-literal : asm-operands[opt] : asm-operands[opt]
4090 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers
4092 Qualifiers other than volatile are accepted in the syntax but
4096 c_parser_asm_statement (c_parser
*parser
)
4098 tree quals
, str
, outputs
, inputs
, clobbers
, ret
;
4100 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
4101 c_parser_consume_token (parser
);
4102 if (c_parser_next_token_is_keyword (parser
, RID_VOLATILE
))
4104 quals
= c_parser_peek_token (parser
)->value
;
4105 c_parser_consume_token (parser
);
4107 else if (c_parser_next_token_is_keyword (parser
, RID_CONST
)
4108 || c_parser_next_token_is_keyword (parser
, RID_RESTRICT
))
4110 warning (0, "%E qualifier ignored on asm",
4111 c_parser_peek_token (parser
)->value
);
4113 c_parser_consume_token (parser
);
4117 /* ??? Follow the C++ parser rather than using the
4118 c_lex_string_translate kludge. */
4119 c_lex_string_translate
= 0;
4120 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4122 c_lex_string_translate
= 1;
4125 str
= c_parser_asm_string_literal (parser
);
4126 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4129 outputs
= NULL_TREE
;
4131 clobbers
= NULL_TREE
;
4134 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%> or %<)%>"))
4136 c_lex_string_translate
= 1;
4137 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4141 /* Parse outputs. */
4142 if (c_parser_next_token_is (parser
, CPP_COLON
)
4143 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4144 outputs
= NULL_TREE
;
4146 outputs
= c_parser_asm_operands (parser
, false);
4147 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4150 clobbers
= NULL_TREE
;
4153 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%> or %<)%>"))
4155 c_lex_string_translate
= 1;
4156 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4160 if (c_parser_next_token_is (parser
, CPP_COLON
)
4161 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4164 inputs
= c_parser_asm_operands (parser
, true);
4165 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4167 clobbers
= NULL_TREE
;
4170 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%> or %<)%>"))
4172 c_lex_string_translate
= 1;
4173 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4176 /* Parse clobbers. */
4177 clobbers
= c_parser_asm_clobbers (parser
);
4179 c_lex_string_translate
= 1;
4180 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
4182 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4185 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
4186 c_parser_skip_to_end_of_block_or_statement (parser
);
4187 ret
= build_asm_stmt (quals
, build_asm_expr (str
, outputs
, inputs
,
4192 /* Parse asm operands, a GNU extension. If CONVERT_P (for inputs but
4193 not outputs), apply the default conversion of functions and arrays
4198 asm-operands , asm-operand
4201 asm-string-literal ( expression )
4202 [ identifier ] asm-string-literal ( expression )
4206 c_parser_asm_operands (c_parser
*parser
, bool convert_p
)
4208 tree list
= NULL_TREE
;
4213 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
4215 c_parser_consume_token (parser
);
4216 if (c_parser_next_token_is (parser
, CPP_NAME
))
4218 tree id
= c_parser_peek_token (parser
)->value
;
4219 c_parser_consume_token (parser
);
4220 name
= build_string (IDENTIFIER_LENGTH (id
),
4221 IDENTIFIER_POINTER (id
));
4225 c_parser_error (parser
, "expected identifier");
4226 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
4229 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4234 str
= c_parser_asm_string_literal (parser
);
4235 if (str
== NULL_TREE
)
4237 c_lex_string_translate
= 1;
4238 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4240 c_lex_string_translate
= 0;
4243 expr
= c_parser_expression (parser
);
4245 expr
= default_function_array_conversion (expr
);
4246 c_lex_string_translate
= 0;
4247 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
4249 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4252 list
= chainon (list
, build_tree_list (build_tree_list (name
, str
),
4254 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4255 c_parser_consume_token (parser
);
4262 /* Parse asm clobbers, a GNU extension.
4266 asm-clobbers , asm-string-literal
4270 c_parser_asm_clobbers (c_parser
*parser
)
4272 tree list
= NULL_TREE
;
4275 tree str
= c_parser_asm_string_literal (parser
);
4277 list
= tree_cons (NULL_TREE
, str
, list
);
4280 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4281 c_parser_consume_token (parser
);
4288 /* Parse an expression other than a compound expression; that is, an
4289 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
4290 NULL then it is an Objective-C message expression which is the
4291 primary-expression starting the expression as an initializer.
4293 assignment-expression:
4294 conditional-expression
4295 unary-expression assignment-operator assignment-expression
4297 assignment-operator: one of
4298 = *= /= %= += -= <<= >>= &= ^= |=
4300 In GNU C we accept any conditional expression on the LHS and
4301 diagnose the invalid lvalue rather than producing a syntax
4304 static struct c_expr
4305 c_parser_expr_no_commas (c_parser
*parser
, struct c_expr
*after
)
4307 struct c_expr lhs
, rhs
, ret
;
4308 enum tree_code code
;
4309 gcc_assert (!after
|| c_dialect_objc ());
4310 lhs
= c_parser_conditional_expression (parser
, after
);
4311 switch (c_parser_peek_token (parser
)->type
)
4320 code
= TRUNC_DIV_EXPR
;
4323 code
= TRUNC_MOD_EXPR
;
4338 code
= BIT_AND_EXPR
;
4341 code
= BIT_XOR_EXPR
;
4344 code
= BIT_IOR_EXPR
;
4349 c_parser_consume_token (parser
);
4350 rhs
= c_parser_expr_no_commas (parser
, NULL
);
4351 rhs
= default_function_array_conversion (rhs
);
4352 ret
.value
= build_modify_expr (lhs
.value
, code
, rhs
.value
);
4353 if (code
== NOP_EXPR
)
4354 ret
.original_code
= MODIFY_EXPR
;
4357 TREE_NO_WARNING (ret
.value
) = 1;
4358 ret
.original_code
= ERROR_MARK
;
4363 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
4364 is not NULL then it is an Objective-C message expression which is
4365 the primary-expression starting the expression as an initializer.
4367 conditional-expression:
4368 logical-OR-expression
4369 logical-OR-expression ? expression : conditional-expression
4373 conditional-expression:
4374 logical-OR-expression ? : conditional-expression
4377 static struct c_expr
4378 c_parser_conditional_expression (c_parser
*parser
, struct c_expr
*after
)
4380 struct c_expr cond
, exp1
, exp2
, ret
;
4381 gcc_assert (!after
|| c_dialect_objc ());
4382 cond
= c_parser_binary_expression (parser
, after
);
4383 if (c_parser_next_token_is_not (parser
, CPP_QUERY
))
4385 cond
= default_function_array_conversion (cond
);
4386 c_parser_consume_token (parser
);
4387 if (c_parser_next_token_is (parser
, CPP_COLON
))
4390 pedwarn ("ISO C forbids omitting the middle term of a ?: expression");
4391 /* Make sure first operand is calculated only once. */
4392 exp1
.value
= save_expr (default_conversion (cond
.value
));
4393 cond
.value
= c_objc_common_truthvalue_conversion (exp1
.value
);
4394 skip_evaluation
+= cond
.value
== truthvalue_true_node
;
4399 = c_objc_common_truthvalue_conversion
4400 (default_conversion (cond
.value
));
4401 skip_evaluation
+= cond
.value
== truthvalue_false_node
;
4402 exp1
= c_parser_expression_conv (parser
);
4403 skip_evaluation
+= ((cond
.value
== truthvalue_true_node
)
4404 - (cond
.value
== truthvalue_false_node
));
4406 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4408 skip_evaluation
-= cond
.value
== truthvalue_true_node
;
4409 ret
.value
= error_mark_node
;
4410 ret
.original_code
= ERROR_MARK
;
4413 exp2
= c_parser_conditional_expression (parser
, NULL
);
4414 exp2
= default_function_array_conversion (exp2
);
4415 skip_evaluation
-= cond
.value
== truthvalue_true_node
;
4416 ret
.value
= build_conditional_expr (cond
.value
, exp1
.value
, exp2
.value
);
4417 ret
.original_code
= ERROR_MARK
;
4421 /* Parse a binary expression; that is, a logical-OR-expression (C90
4422 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
4423 an Objective-C message expression which is the primary-expression
4424 starting the expression as an initializer.
4426 multiplicative-expression:
4428 multiplicative-expression * cast-expression
4429 multiplicative-expression / cast-expression
4430 multiplicative-expression % cast-expression
4432 additive-expression:
4433 multiplicative-expression
4434 additive-expression + multiplicative-expression
4435 additive-expression - multiplicative-expression
4439 shift-expression << additive-expression
4440 shift-expression >> additive-expression
4442 relational-expression:
4444 relational-expression < shift-expression
4445 relational-expression > shift-expression
4446 relational-expression <= shift-expression
4447 relational-expression >= shift-expression
4449 equality-expression:
4450 relational-expression
4451 equality-expression == relational-expression
4452 equality-expression != relational-expression
4456 AND-expression & equality-expression
4458 exclusive-OR-expression:
4460 exclusive-OR-expression ^ AND-expression
4462 inclusive-OR-expression:
4463 exclusive-OR-expression
4464 inclusive-OR-expression | exclusive-OR-expression
4466 logical-AND-expression:
4467 inclusive-OR-expression
4468 logical-AND-expression && inclusive-OR-expression
4470 logical-OR-expression:
4471 logical-AND-expression
4472 logical-OR-expression || logical-AND-expression
4475 static struct c_expr
4476 c_parser_binary_expression (c_parser
*parser
, struct c_expr
*after
)
4478 /* A binary expression is parsed using operator-precedence parsing,
4479 with the operands being cast expressions. All the binary
4480 operators are left-associative. Thus a binary expression is of
4483 E0 op1 E1 op2 E2 ...
4485 which we represent on a stack. On the stack, the precedence
4486 levels are strictly increasing. When a new operator is
4487 encountered of higher precedence than that at the top of the
4488 stack, it is pushed; its LHS is the top expression, and its RHS
4489 is everything parsed until it is popped. When a new operator is
4490 encountered with precedence less than or equal to that at the top
4491 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
4492 by the result of the operation until the operator at the top of
4493 the stack has lower precedence than the new operator or there is
4494 only one element on the stack; then the top expression is the LHS
4495 of the new operator. In the case of logical AND and OR
4496 expressions, we also need to adjust skip_evaluation as
4497 appropriate when the operators are pushed and popped. */
4499 /* The precedence levels, where 0 is a dummy lowest level used for
4500 the bottom of the stack. */
4516 /* The expression at this stack level. */
4518 /* The precedence of the operator on its left, PREC_NONE at the
4519 bottom of the stack. */
4521 /* The operation on its left. */
4527 switch (stack[sp].op) \
4529 case TRUTH_ANDIF_EXPR: \
4530 skip_evaluation -= stack[sp - 1].expr.value == truthvalue_false_node; \
4532 case TRUTH_ORIF_EXPR: \
4533 skip_evaluation -= stack[sp - 1].expr.value == truthvalue_true_node; \
4538 stack[sp - 1].expr \
4539 = default_function_array_conversion (stack[sp - 1].expr); \
4541 = default_function_array_conversion (stack[sp].expr); \
4542 stack[sp - 1].expr = parser_build_binary_op (stack[sp].op, \
4543 stack[sp - 1].expr, \
4547 gcc_assert (!after
|| c_dialect_objc ());
4548 stack
[0].expr
= c_parser_cast_expression (parser
, after
);
4549 stack
[0].prec
= PREC_NONE
;
4554 enum tree_code ocode
;
4557 switch (c_parser_peek_token (parser
)->type
)
4565 ocode
= TRUNC_DIV_EXPR
;
4569 ocode
= TRUNC_MOD_EXPR
;
4581 ocode
= LSHIFT_EXPR
;
4585 ocode
= RSHIFT_EXPR
;
4599 case CPP_GREATER_EQ
:
4612 oprec
= PREC_BITAND
;
4613 ocode
= BIT_AND_EXPR
;
4616 oprec
= PREC_BITXOR
;
4617 ocode
= BIT_XOR_EXPR
;
4621 ocode
= BIT_IOR_EXPR
;
4624 oprec
= PREC_LOGAND
;
4625 ocode
= TRUTH_ANDIF_EXPR
;
4629 ocode
= TRUTH_ORIF_EXPR
;
4632 /* Not a binary operator, so end of the binary
4636 c_parser_consume_token (parser
);
4637 while (oprec
<= stack
[sp
].prec
)
4641 case TRUTH_ANDIF_EXPR
:
4643 = default_function_array_conversion (stack
[sp
].expr
);
4644 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
4645 (default_conversion (stack
[sp
].expr
.value
));
4646 skip_evaluation
+= stack
[sp
].expr
.value
== truthvalue_false_node
;
4648 case TRUTH_ORIF_EXPR
:
4650 = default_function_array_conversion (stack
[sp
].expr
);
4651 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
4652 (default_conversion (stack
[sp
].expr
.value
));
4653 skip_evaluation
+= stack
[sp
].expr
.value
== truthvalue_true_node
;
4659 stack
[sp
].expr
= c_parser_cast_expression (parser
, NULL
);
4660 stack
[sp
].prec
= oprec
;
4661 stack
[sp
].op
= ocode
;
4666 return stack
[0].expr
;
4670 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
4671 NULL then it is an Objective-C message expression which is the
4672 primary-expression starting the expression as an initializer.
4676 ( type-name ) unary-expression
4679 static struct c_expr
4680 c_parser_cast_expression (c_parser
*parser
, struct c_expr
*after
)
4682 gcc_assert (!after
|| c_dialect_objc ());
4684 return c_parser_postfix_expression_after_primary (parser
, *after
);
4685 /* If the expression begins with a parenthesized type name, it may
4686 be either a cast or a compound literal; we need to see whether
4687 the next character is '{' to tell the difference. If not, it is
4688 an unary expression. */
4689 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
4690 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
4692 struct c_type_name
*type_name
;
4695 c_parser_consume_token (parser
);
4696 type_name
= c_parser_type_name (parser
);
4697 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4698 if (type_name
== NULL
)
4700 ret
.value
= error_mark_node
;
4701 ret
.original_code
= ERROR_MARK
;
4705 /* Save casted types in the function's used types hash table. */
4706 used_types_insert (type_name
->specs
->type
);
4708 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4709 return c_parser_postfix_expression_after_paren_type (parser
,
4711 expr
= c_parser_cast_expression (parser
, NULL
);
4712 expr
= default_function_array_conversion (expr
);
4713 ret
.value
= c_cast_expr (type_name
, expr
.value
);
4714 ret
.original_code
= ERROR_MARK
;
4718 return c_parser_unary_expression (parser
);
4721 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
4727 unary-operator cast-expression
4728 sizeof unary-expression
4729 sizeof ( type-name )
4731 unary-operator: one of
4737 __alignof__ unary-expression
4738 __alignof__ ( type-name )
4741 unary-operator: one of
4742 __extension__ __real__ __imag__
4744 In addition, the GNU syntax treats ++ and -- as unary operators, so
4745 they may be applied to cast expressions with errors for non-lvalues
4748 static struct c_expr
4749 c_parser_unary_expression (c_parser
*parser
)
4752 struct c_expr ret
, op
;
4753 switch (c_parser_peek_token (parser
)->type
)
4756 c_parser_consume_token (parser
);
4757 op
= c_parser_cast_expression (parser
, NULL
);
4758 op
= default_function_array_conversion (op
);
4759 return parser_build_unary_op (PREINCREMENT_EXPR
, op
);
4760 case CPP_MINUS_MINUS
:
4761 c_parser_consume_token (parser
);
4762 op
= c_parser_cast_expression (parser
, NULL
);
4763 op
= default_function_array_conversion (op
);
4764 return parser_build_unary_op (PREDECREMENT_EXPR
, op
);
4766 c_parser_consume_token (parser
);
4767 return parser_build_unary_op (ADDR_EXPR
,
4768 c_parser_cast_expression (parser
, NULL
));
4770 c_parser_consume_token (parser
);
4771 op
= c_parser_cast_expression (parser
, NULL
);
4772 op
= default_function_array_conversion (op
);
4773 ret
.value
= build_indirect_ref (op
.value
, "unary *");
4774 ret
.original_code
= ERROR_MARK
;
4777 c_parser_consume_token (parser
);
4778 if (!c_dialect_objc () && !in_system_header
)
4779 warning (OPT_Wtraditional
,
4780 "traditional C rejects the unary plus operator");
4781 op
= c_parser_cast_expression (parser
, NULL
);
4782 op
= default_function_array_conversion (op
);
4783 return parser_build_unary_op (CONVERT_EXPR
, op
);
4785 c_parser_consume_token (parser
);
4786 op
= c_parser_cast_expression (parser
, NULL
);
4787 op
= default_function_array_conversion (op
);
4788 return parser_build_unary_op (NEGATE_EXPR
, op
);
4790 c_parser_consume_token (parser
);
4791 op
= c_parser_cast_expression (parser
, NULL
);
4792 op
= default_function_array_conversion (op
);
4793 return parser_build_unary_op (BIT_NOT_EXPR
, op
);
4795 c_parser_consume_token (parser
);
4796 op
= c_parser_cast_expression (parser
, NULL
);
4797 op
= default_function_array_conversion (op
);
4798 return parser_build_unary_op (TRUTH_NOT_EXPR
, op
);
4800 /* Refer to the address of a label as a pointer. */
4801 c_parser_consume_token (parser
);
4802 if (c_parser_next_token_is (parser
, CPP_NAME
))
4804 ret
.value
= finish_label_address_expr
4805 (c_parser_peek_token (parser
)->value
);
4806 c_parser_consume_token (parser
);
4810 c_parser_error (parser
, "expected identifier");
4811 ret
.value
= error_mark_node
;
4813 ret
.original_code
= ERROR_MARK
;
4816 switch (c_parser_peek_token (parser
)->keyword
)
4819 return c_parser_sizeof_expression (parser
);
4821 return c_parser_alignof_expression (parser
);
4823 c_parser_consume_token (parser
);
4824 ext
= disable_extension_diagnostics ();
4825 ret
= c_parser_cast_expression (parser
, NULL
);
4826 restore_extension_diagnostics (ext
);
4829 c_parser_consume_token (parser
);
4830 op
= c_parser_cast_expression (parser
, NULL
);
4831 op
= default_function_array_conversion (op
);
4832 return parser_build_unary_op (REALPART_EXPR
, op
);
4834 c_parser_consume_token (parser
);
4835 op
= c_parser_cast_expression (parser
, NULL
);
4836 op
= default_function_array_conversion (op
);
4837 return parser_build_unary_op (IMAGPART_EXPR
, op
);
4839 return c_parser_postfix_expression (parser
);
4842 return c_parser_postfix_expression (parser
);
4846 /* Parse a sizeof expression. */
4848 static struct c_expr
4849 c_parser_sizeof_expression (c_parser
*parser
)
4852 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SIZEOF
));
4853 c_parser_consume_token (parser
);
4856 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
4857 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
4859 /* Either sizeof ( type-name ) or sizeof unary-expression
4860 starting with a compound literal. */
4861 struct c_type_name
*type_name
;
4862 c_parser_consume_token (parser
);
4863 type_name
= c_parser_type_name (parser
);
4864 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4865 if (type_name
== NULL
)
4870 ret
.value
= error_mark_node
;
4871 ret
.original_code
= ERROR_MARK
;
4874 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4876 expr
= c_parser_postfix_expression_after_paren_type (parser
,
4880 /* sizeof ( type-name ). */
4883 if (type_name
->declarator
->kind
== cdk_array
4884 && type_name
->declarator
->u
.array
.vla_unspec_p
)
4887 error ("%<[*]%> not allowed in other than a declaration");
4889 return c_expr_sizeof_type (type_name
);
4893 expr
= c_parser_unary_expression (parser
);
4897 if (TREE_CODE (expr
.value
) == COMPONENT_REF
4898 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
4899 error ("%<sizeof%> applied to a bit-field");
4900 return c_expr_sizeof_expr (expr
);
4904 /* Parse an alignof expression. */
4906 static struct c_expr
4907 c_parser_alignof_expression (c_parser
*parser
)
4910 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNOF
));
4911 c_parser_consume_token (parser
);
4914 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
4915 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
4917 /* Either __alignof__ ( type-name ) or __alignof__
4918 unary-expression starting with a compound literal. */
4919 struct c_type_name
*type_name
;
4921 c_parser_consume_token (parser
);
4922 type_name
= c_parser_type_name (parser
);
4923 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4924 if (type_name
== NULL
)
4929 ret
.value
= error_mark_node
;
4930 ret
.original_code
= ERROR_MARK
;
4933 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4935 expr
= c_parser_postfix_expression_after_paren_type (parser
,
4939 /* alignof ( type-name ). */
4942 ret
.value
= c_alignof (groktypename (type_name
));
4943 ret
.original_code
= ERROR_MARK
;
4949 expr
= c_parser_unary_expression (parser
);
4953 ret
.value
= c_alignof_expr (expr
.value
);
4954 ret
.original_code
= ERROR_MARK
;
4959 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
4963 postfix-expression [ expression ]
4964 postfix-expression ( argument-expression-list[opt] )
4965 postfix-expression . identifier
4966 postfix-expression -> identifier
4967 postfix-expression ++
4968 postfix-expression --
4969 ( type-name ) { initializer-list }
4970 ( type-name ) { initializer-list , }
4972 argument-expression-list:
4974 argument-expression-list , argument-expression
4986 (treated as a keyword in GNU C)
4989 ( compound-statement )
4990 __builtin_va_arg ( assignment-expression , type-name )
4991 __builtin_offsetof ( type-name , offsetof-member-designator )
4992 __builtin_choose_expr ( assignment-expression ,
4993 assignment-expression ,
4994 assignment-expression )
4995 __builtin_types_compatible_p ( type-name , type-name )
4997 offsetof-member-designator:
4999 offsetof-member-designator . identifier
5000 offsetof-member-designator [ expression ]
5005 [ objc-receiver objc-message-args ]
5006 @selector ( objc-selector-arg )
5007 @protocol ( identifier )
5008 @encode ( type-name )
5012 static struct c_expr
5013 c_parser_postfix_expression (c_parser
*parser
)
5015 struct c_expr expr
, e1
, e2
, e3
;
5016 struct c_type_name
*t1
, *t2
;
5017 switch (c_parser_peek_token (parser
)->type
)
5022 expr
.value
= c_parser_peek_token (parser
)->value
;
5023 expr
.original_code
= ERROR_MARK
;
5024 c_parser_consume_token (parser
);
5028 expr
.value
= c_parser_peek_token (parser
)->value
;
5029 expr
.original_code
= STRING_CST
;
5030 c_parser_consume_token (parser
);
5032 case CPP_OBJC_STRING
:
5033 gcc_assert (c_dialect_objc ());
5035 = objc_build_string_object (c_parser_peek_token (parser
)->value
);
5036 expr
.original_code
= ERROR_MARK
;
5037 c_parser_consume_token (parser
);
5040 if (c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
5042 c_parser_error (parser
, "expected expression");
5043 expr
.value
= error_mark_node
;
5044 expr
.original_code
= ERROR_MARK
;
5048 tree id
= c_parser_peek_token (parser
)->value
;
5049 location_t loc
= c_parser_peek_token (parser
)->location
;
5050 c_parser_consume_token (parser
);
5051 expr
.value
= build_external_ref (id
,
5052 (c_parser_peek_token (parser
)->type
5053 == CPP_OPEN_PAREN
), loc
);
5054 expr
.original_code
= ERROR_MARK
;
5057 case CPP_OPEN_PAREN
:
5058 /* A parenthesized expression, statement expression or compound
5060 if (c_parser_peek_2nd_token (parser
)->type
== CPP_OPEN_BRACE
)
5062 /* A statement expression. */
5064 c_parser_consume_token (parser
);
5065 c_parser_consume_token (parser
);
5066 if (cur_stmt_list
== NULL
)
5068 error ("braced-group within expression allowed "
5069 "only inside a function");
5070 parser
->error
= true;
5071 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
5072 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5073 expr
.value
= error_mark_node
;
5074 expr
.original_code
= ERROR_MARK
;
5077 stmt
= c_begin_stmt_expr ();
5078 c_parser_compound_statement_nostart (parser
);
5079 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5082 pedwarn ("ISO C forbids braced-groups within expressions");
5083 expr
.value
= c_finish_stmt_expr (stmt
);
5084 expr
.original_code
= ERROR_MARK
;
5086 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
5088 /* A compound literal. ??? Can we actually get here rather
5089 than going directly to
5090 c_parser_postfix_expression_after_paren_type from
5092 struct c_type_name
*type_name
;
5093 c_parser_consume_token (parser
);
5094 type_name
= c_parser_type_name (parser
);
5095 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5097 if (type_name
== NULL
)
5099 expr
.value
= error_mark_node
;
5100 expr
.original_code
= ERROR_MARK
;
5103 expr
= c_parser_postfix_expression_after_paren_type (parser
,
5108 /* A parenthesized expression. */
5109 c_parser_consume_token (parser
);
5110 expr
= c_parser_expression (parser
);
5111 if (TREE_CODE (expr
.value
) == MODIFY_EXPR
)
5112 TREE_NO_WARNING (expr
.value
) = 1;
5113 expr
.original_code
= ERROR_MARK
;
5114 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5119 switch (c_parser_peek_token (parser
)->keyword
)
5121 case RID_FUNCTION_NAME
:
5122 case RID_PRETTY_FUNCTION_NAME
:
5123 case RID_C99_FUNCTION_NAME
:
5124 expr
.value
= fname_decl (c_parser_peek_token (parser
)->keyword
,
5125 c_parser_peek_token (parser
)->value
);
5126 expr
.original_code
= ERROR_MARK
;
5127 c_parser_consume_token (parser
);
5130 c_parser_consume_token (parser
);
5131 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5133 expr
.value
= error_mark_node
;
5134 expr
.original_code
= ERROR_MARK
;
5137 e1
= c_parser_expr_no_commas (parser
, NULL
);
5138 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5140 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5141 expr
.value
= error_mark_node
;
5142 expr
.original_code
= ERROR_MARK
;
5145 t1
= c_parser_type_name (parser
);
5146 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5150 expr
.value
= error_mark_node
;
5151 expr
.original_code
= ERROR_MARK
;
5155 expr
.value
= build_va_arg (e1
.value
, groktypename (t1
));
5156 expr
.original_code
= ERROR_MARK
;
5160 c_parser_consume_token (parser
);
5161 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5163 expr
.value
= error_mark_node
;
5164 expr
.original_code
= ERROR_MARK
;
5167 t1
= c_parser_type_name (parser
);
5170 expr
.value
= error_mark_node
;
5171 expr
.original_code
= ERROR_MARK
;
5174 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5176 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5177 expr
.value
= error_mark_node
;
5178 expr
.original_code
= ERROR_MARK
;
5182 tree type
= groktypename (t1
);
5184 if (type
== error_mark_node
)
5185 offsetof_ref
= error_mark_node
;
5187 offsetof_ref
= build1 (INDIRECT_REF
, type
, null_pointer_node
);
5188 /* Parse the second argument to __builtin_offsetof. We
5189 must have one identifier, and beyond that we want to
5190 accept sub structure and sub array references. */
5191 if (c_parser_next_token_is (parser
, CPP_NAME
))
5193 offsetof_ref
= build_component_ref
5194 (offsetof_ref
, c_parser_peek_token (parser
)->value
);
5195 c_parser_consume_token (parser
);
5196 while (c_parser_next_token_is (parser
, CPP_DOT
)
5197 || c_parser_next_token_is (parser
,
5200 if (c_parser_next_token_is (parser
, CPP_DOT
))
5202 c_parser_consume_token (parser
);
5203 if (c_parser_next_token_is_not (parser
,
5206 c_parser_error (parser
, "expected identifier");
5209 offsetof_ref
= build_component_ref
5211 c_parser_peek_token (parser
)->value
);
5212 c_parser_consume_token (parser
);
5217 c_parser_consume_token (parser
);
5218 idx
= c_parser_expression (parser
).value
;
5219 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5221 offsetof_ref
= build_array_ref (offsetof_ref
, idx
);
5226 c_parser_error (parser
, "expected identifier");
5227 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5229 expr
.value
= fold_offsetof (offsetof_ref
, NULL_TREE
);
5230 expr
.original_code
= ERROR_MARK
;
5233 case RID_CHOOSE_EXPR
:
5234 c_parser_consume_token (parser
);
5235 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5237 expr
.value
= error_mark_node
;
5238 expr
.original_code
= ERROR_MARK
;
5241 e1
= c_parser_expr_no_commas (parser
, NULL
);
5242 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5244 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5245 expr
.value
= error_mark_node
;
5246 expr
.original_code
= ERROR_MARK
;
5249 e2
= c_parser_expr_no_commas (parser
, NULL
);
5250 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5252 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5253 expr
.value
= error_mark_node
;
5254 expr
.original_code
= ERROR_MARK
;
5257 e3
= c_parser_expr_no_commas (parser
, NULL
);
5258 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5263 c
= fold (e1
.value
);
5264 if (TREE_CODE (c
) != INTEGER_CST
)
5265 error ("first argument to %<__builtin_choose_expr%> not"
5267 expr
= integer_zerop (c
) ? e3
: e2
;
5270 case RID_TYPES_COMPATIBLE_P
:
5271 c_parser_consume_token (parser
);
5272 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5274 expr
.value
= error_mark_node
;
5275 expr
.original_code
= ERROR_MARK
;
5278 t1
= c_parser_type_name (parser
);
5281 expr
.value
= error_mark_node
;
5282 expr
.original_code
= ERROR_MARK
;
5285 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5287 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5288 expr
.value
= error_mark_node
;
5289 expr
.original_code
= ERROR_MARK
;
5292 t2
= c_parser_type_name (parser
);
5295 expr
.value
= error_mark_node
;
5296 expr
.original_code
= ERROR_MARK
;
5299 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5304 e1
= TYPE_MAIN_VARIANT (groktypename (t1
));
5305 e2
= TYPE_MAIN_VARIANT (groktypename (t2
));
5307 expr
.value
= comptypes (e1
, e2
)
5308 ? build_int_cst (NULL_TREE
, 1)
5309 : build_int_cst (NULL_TREE
, 0);
5310 expr
.original_code
= ERROR_MARK
;
5313 case RID_AT_SELECTOR
:
5314 gcc_assert (c_dialect_objc ());
5315 c_parser_consume_token (parser
);
5316 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5318 expr
.value
= error_mark_node
;
5319 expr
.original_code
= ERROR_MARK
;
5323 tree sel
= c_parser_objc_selector_arg (parser
);
5324 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5326 expr
.value
= objc_build_selector_expr (sel
);
5327 expr
.original_code
= ERROR_MARK
;
5330 case RID_AT_PROTOCOL
:
5331 gcc_assert (c_dialect_objc ());
5332 c_parser_consume_token (parser
);
5333 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5335 expr
.value
= error_mark_node
;
5336 expr
.original_code
= ERROR_MARK
;
5339 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5341 c_parser_error (parser
, "expected identifier");
5342 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5343 expr
.value
= error_mark_node
;
5344 expr
.original_code
= ERROR_MARK
;
5348 tree id
= c_parser_peek_token (parser
)->value
;
5349 c_parser_consume_token (parser
);
5350 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5352 expr
.value
= objc_build_protocol_expr (id
);
5353 expr
.original_code
= ERROR_MARK
;
5357 /* Extension to support C-structures in the archiver. */
5358 gcc_assert (c_dialect_objc ());
5359 c_parser_consume_token (parser
);
5360 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5362 expr
.value
= error_mark_node
;
5363 expr
.original_code
= ERROR_MARK
;
5366 t1
= c_parser_type_name (parser
);
5369 expr
.value
= error_mark_node
;
5370 expr
.original_code
= ERROR_MARK
;
5371 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5374 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5377 tree type
= groktypename (t1
);
5378 expr
.value
= objc_build_encode_expr (type
);
5379 expr
.original_code
= ERROR_MARK
;
5383 c_parser_error (parser
, "expected expression");
5384 expr
.value
= error_mark_node
;
5385 expr
.original_code
= ERROR_MARK
;
5389 case CPP_OPEN_SQUARE
:
5390 if (c_dialect_objc ())
5392 tree receiver
, args
;
5393 c_parser_consume_token (parser
);
5394 receiver
= c_parser_objc_receiver (parser
);
5395 args
= c_parser_objc_message_args (parser
);
5396 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5398 expr
.value
= objc_build_message_expr (build_tree_list (receiver
,
5400 expr
.original_code
= ERROR_MARK
;
5403 /* Else fall through to report error. */
5405 c_parser_error (parser
, "expected expression");
5406 expr
.value
= error_mark_node
;
5407 expr
.original_code
= ERROR_MARK
;
5410 return c_parser_postfix_expression_after_primary (parser
, expr
);
5413 /* Parse a postfix expression after a parenthesized type name: the
5414 brace-enclosed initializer of a compound literal, possibly followed
5415 by some postfix operators. This is separate because it is not
5416 possible to tell until after the type name whether a cast
5417 expression has a cast or a compound literal, or whether the operand
5418 of sizeof is a parenthesized type name or starts with a compound
5421 static struct c_expr
5422 c_parser_postfix_expression_after_paren_type (c_parser
*parser
,
5423 struct c_type_name
*type_name
)
5428 start_init (NULL_TREE
, NULL
, 0);
5429 type
= groktypename (type_name
);
5430 if (type
!= error_mark_node
&& C_TYPE_VARIABLE_SIZE (type
))
5432 error ("compound literal has variable size");
5433 type
= error_mark_node
;
5435 init
= c_parser_braced_init (parser
, type
, false);
5437 maybe_warn_string_init (type
, init
);
5439 if (pedantic
&& !flag_isoc99
)
5440 pedwarn ("ISO C90 forbids compound literals");
5441 expr
.value
= build_compound_literal (type
, init
.value
);
5442 expr
.original_code
= ERROR_MARK
;
5443 return c_parser_postfix_expression_after_primary (parser
, expr
);
5446 /* Parse a postfix expression after the initial primary or compound
5447 literal; that is, parse a series of postfix operators. */
5449 static struct c_expr
5450 c_parser_postfix_expression_after_primary (c_parser
*parser
,
5453 tree ident
, idx
, exprlist
;
5456 switch (c_parser_peek_token (parser
)->type
)
5458 case CPP_OPEN_SQUARE
:
5459 /* Array reference. */
5460 c_parser_consume_token (parser
);
5461 idx
= c_parser_expression (parser
).value
;
5462 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5464 expr
.value
= build_array_ref (expr
.value
, idx
);
5465 expr
.original_code
= ERROR_MARK
;
5467 case CPP_OPEN_PAREN
:
5468 /* Function call. */
5469 c_parser_consume_token (parser
);
5470 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
5471 exprlist
= NULL_TREE
;
5473 exprlist
= c_parser_expr_list (parser
, true);
5474 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5476 expr
.value
= build_function_call (expr
.value
, exprlist
);
5477 expr
.original_code
= ERROR_MARK
;
5480 /* Structure element reference. */
5481 c_parser_consume_token (parser
);
5482 expr
= default_function_array_conversion (expr
);
5483 if (c_parser_next_token_is (parser
, CPP_NAME
))
5484 ident
= c_parser_peek_token (parser
)->value
;
5487 c_parser_error (parser
, "expected identifier");
5488 expr
.value
= error_mark_node
;
5489 expr
.original_code
= ERROR_MARK
;
5492 c_parser_consume_token (parser
);
5493 expr
.value
= build_component_ref (expr
.value
, ident
);
5494 expr
.original_code
= ERROR_MARK
;
5497 /* Structure element reference. */
5498 c_parser_consume_token (parser
);
5499 expr
= default_function_array_conversion (expr
);
5500 if (c_parser_next_token_is (parser
, CPP_NAME
))
5501 ident
= c_parser_peek_token (parser
)->value
;
5504 c_parser_error (parser
, "expected identifier");
5505 expr
.value
= error_mark_node
;
5506 expr
.original_code
= ERROR_MARK
;
5509 c_parser_consume_token (parser
);
5510 expr
.value
= build_component_ref (build_indirect_ref (expr
.value
,
5512 expr
.original_code
= ERROR_MARK
;
5515 /* Postincrement. */
5516 c_parser_consume_token (parser
);
5517 expr
= default_function_array_conversion (expr
);
5518 expr
.value
= build_unary_op (POSTINCREMENT_EXPR
, expr
.value
, 0);
5519 expr
.original_code
= ERROR_MARK
;
5521 case CPP_MINUS_MINUS
:
5522 /* Postdecrement. */
5523 c_parser_consume_token (parser
);
5524 expr
= default_function_array_conversion (expr
);
5525 expr
.value
= build_unary_op (POSTDECREMENT_EXPR
, expr
.value
, 0);
5526 expr
.original_code
= ERROR_MARK
;
5534 /* Parse an expression (C90 6.3.17, C99 6.5.17).
5537 assignment-expression
5538 expression , assignment-expression
5541 static struct c_expr
5542 c_parser_expression (c_parser
*parser
)
5545 expr
= c_parser_expr_no_commas (parser
, NULL
);
5546 while (c_parser_next_token_is (parser
, CPP_COMMA
))
5549 c_parser_consume_token (parser
);
5550 next
= c_parser_expr_no_commas (parser
, NULL
);
5551 next
= default_function_array_conversion (next
);
5552 expr
.value
= build_compound_expr (expr
.value
, next
.value
);
5553 expr
.original_code
= COMPOUND_EXPR
;
5558 /* Parse an expression and convert functions or arrays to
5561 static struct c_expr
5562 c_parser_expression_conv (c_parser
*parser
)
5565 expr
= c_parser_expression (parser
);
5566 expr
= default_function_array_conversion (expr
);
5570 /* Parse a non-empty list of expressions. If CONVERT_P, convert
5571 functions and arrays to pointers.
5574 assignment-expression
5575 nonempty-expr-list , assignment-expression
5579 c_parser_expr_list (c_parser
*parser
, bool convert_p
)
5583 expr
= c_parser_expr_no_commas (parser
, NULL
);
5585 expr
= default_function_array_conversion (expr
);
5586 ret
= cur
= build_tree_list (NULL_TREE
, expr
.value
);
5587 while (c_parser_next_token_is (parser
, CPP_COMMA
))
5589 c_parser_consume_token (parser
);
5590 expr
= c_parser_expr_no_commas (parser
, NULL
);
5592 expr
= default_function_array_conversion (expr
);
5593 cur
= TREE_CHAIN (cur
) = build_tree_list (NULL_TREE
, expr
.value
);
5599 /* Parse Objective-C-specific constructs. */
5601 /* Parse an objc-class-definition.
5603 objc-class-definition:
5604 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
5605 objc-class-instance-variables[opt] objc-methodprotolist @end
5606 @implementation identifier objc-superclass[opt]
5607 objc-class-instance-variables[opt]
5608 @interface identifier ( identifier ) objc-protocol-refs[opt]
5609 objc-methodprotolist @end
5610 @implementation identifier ( identifier )
5615 "@interface identifier (" must start "@interface identifier (
5616 identifier ) ...": objc-methodprotolist in the first production may
5617 not start with a parenthesized identifier as a declarator of a data
5618 definition with no declaration specifiers if the objc-superclass,
5619 objc-protocol-refs and objc-class-instance-variables are omitted. */
5622 c_parser_objc_class_definition (c_parser
*parser
)
5627 if (c_parser_next_token_is_keyword (parser
, RID_AT_INTERFACE
))
5629 else if (c_parser_next_token_is_keyword (parser
, RID_AT_IMPLEMENTATION
))
5633 c_parser_consume_token (parser
);
5634 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5636 c_parser_error (parser
, "expected identifier");
5639 id1
= c_parser_peek_token (parser
)->value
;
5640 c_parser_consume_token (parser
);
5641 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
5644 tree proto
= NULL_TREE
;
5645 c_parser_consume_token (parser
);
5646 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5648 c_parser_error (parser
, "expected identifier");
5649 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5652 id2
= c_parser_peek_token (parser
)->value
;
5653 c_parser_consume_token (parser
);
5654 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5657 objc_start_category_implementation (id1
, id2
);
5660 if (c_parser_next_token_is (parser
, CPP_LESS
))
5661 proto
= c_parser_objc_protocol_refs (parser
);
5662 objc_start_category_interface (id1
, id2
, proto
);
5663 c_parser_objc_methodprotolist (parser
);
5664 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
5665 objc_finish_interface ();
5668 if (c_parser_next_token_is (parser
, CPP_COLON
))
5670 c_parser_consume_token (parser
);
5671 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5673 c_parser_error (parser
, "expected identifier");
5676 superclass
= c_parser_peek_token (parser
)->value
;
5677 c_parser_consume_token (parser
);
5680 superclass
= NULL_TREE
;
5683 tree proto
= NULL_TREE
;
5684 if (c_parser_next_token_is (parser
, CPP_LESS
))
5685 proto
= c_parser_objc_protocol_refs (parser
);
5686 objc_start_class_interface (id1
, superclass
, proto
);
5689 objc_start_class_implementation (id1
, superclass
);
5690 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5691 c_parser_objc_class_instance_variables (parser
);
5694 objc_continue_interface ();
5695 c_parser_objc_methodprotolist (parser
);
5696 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
5697 objc_finish_interface ();
5701 objc_continue_implementation ();
5706 /* Parse objc-class-instance-variables.
5708 objc-class-instance-variables:
5709 { objc-instance-variable-decl-list[opt] }
5711 objc-instance-variable-decl-list:
5712 objc-visibility-spec
5713 objc-instance-variable-decl ;
5715 objc-instance-variable-decl-list objc-visibility-spec
5716 objc-instance-variable-decl-list objc-instance-variable-decl ;
5717 objc-instance-variable-decl-list ;
5719 objc-visibility-spec:
5724 objc-instance-variable-decl:
5729 c_parser_objc_class_instance_variables (c_parser
*parser
)
5731 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
5732 c_parser_consume_token (parser
);
5733 while (c_parser_next_token_is_not (parser
, CPP_EOF
))
5736 /* Parse any stray semicolon. */
5737 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5740 pedwarn ("extra semicolon in struct or union specified");
5741 c_parser_consume_token (parser
);
5744 /* Stop if at the end of the instance variables. */
5745 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
5747 c_parser_consume_token (parser
);
5750 /* Parse any objc-visibility-spec. */
5751 if (c_parser_next_token_is_keyword (parser
, RID_AT_PRIVATE
))
5753 c_parser_consume_token (parser
);
5754 objc_set_visibility (2);
5757 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROTECTED
))
5759 c_parser_consume_token (parser
);
5760 objc_set_visibility (0);
5763 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PUBLIC
))
5765 c_parser_consume_token (parser
);
5766 objc_set_visibility (1);
5769 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
5771 c_parser_pragma (parser
, pragma_external
);
5775 /* Parse some comma-separated declarations. */
5776 decls
= c_parser_struct_declaration (parser
);
5778 /* Comma-separated instance variables are chained together in
5779 reverse order; add them one by one. */
5780 tree ivar
= nreverse (decls
);
5781 for (; ivar
; ivar
= TREE_CHAIN (ivar
))
5782 objc_add_instance_variable (copy_node (ivar
));
5784 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5788 /* Parse an objc-class-declaration.
5790 objc-class-declaration:
5791 @class identifier-list ;
5795 c_parser_objc_class_declaration (c_parser
*parser
)
5797 tree list
= NULL_TREE
;
5798 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_CLASS
));
5799 c_parser_consume_token (parser
);
5800 /* Any identifiers, including those declared as type names, are OK
5805 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5807 c_parser_error (parser
, "expected identifier");
5810 id
= c_parser_peek_token (parser
)->value
;
5811 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
5812 c_parser_consume_token (parser
);
5813 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5814 c_parser_consume_token (parser
);
5818 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5819 objc_declare_class (list
);
5822 /* Parse an objc-alias-declaration.
5824 objc-alias-declaration:
5825 @compatibility_alias identifier identifier ;
5829 c_parser_objc_alias_declaration (c_parser
*parser
)
5832 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_ALIAS
));
5833 c_parser_consume_token (parser
);
5834 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5836 c_parser_error (parser
, "expected identifier");
5837 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
5840 id1
= c_parser_peek_token (parser
)->value
;
5841 c_parser_consume_token (parser
);
5842 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5844 c_parser_error (parser
, "expected identifier");
5845 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
5848 id2
= c_parser_peek_token (parser
)->value
;
5849 c_parser_consume_token (parser
);
5850 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5851 objc_declare_alias (id1
, id2
);
5854 /* Parse an objc-protocol-definition.
5856 objc-protocol-definition:
5857 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
5858 @protocol identifier-list ;
5860 "@protocol identifier ;" should be resolved as "@protocol
5861 identifier-list ;": objc-methodprotolist may not start with a
5862 semicolon in the first alternative if objc-protocol-refs are
5866 c_parser_objc_protocol_definition (c_parser
*parser
)
5868 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROTOCOL
));
5869 c_parser_consume_token (parser
);
5870 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5872 c_parser_error (parser
, "expected identifier");
5875 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
5876 || c_parser_peek_2nd_token (parser
)->type
== CPP_SEMICOLON
)
5878 tree list
= NULL_TREE
;
5879 /* Any identifiers, including those declared as type names, are
5884 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5886 c_parser_error (parser
, "expected identifier");
5889 id
= c_parser_peek_token (parser
)->value
;
5890 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
5891 c_parser_consume_token (parser
);
5892 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5893 c_parser_consume_token (parser
);
5897 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5898 objc_declare_protocols (list
);
5902 tree id
= c_parser_peek_token (parser
)->value
;
5903 tree proto
= NULL_TREE
;
5904 c_parser_consume_token (parser
);
5905 if (c_parser_next_token_is (parser
, CPP_LESS
))
5906 proto
= c_parser_objc_protocol_refs (parser
);
5907 parser
->objc_pq_context
= true;
5908 objc_start_protocol (id
, proto
);
5909 c_parser_objc_methodprotolist (parser
);
5910 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
5911 parser
->objc_pq_context
= false;
5912 objc_finish_interface ();
5916 /* Parse an objc-method-type.
5923 static enum tree_code
5924 c_parser_objc_method_type (c_parser
*parser
)
5926 switch (c_parser_peek_token (parser
)->type
)
5929 c_parser_consume_token (parser
);
5932 c_parser_consume_token (parser
);
5939 /* Parse an objc-method-definition.
5941 objc-method-definition:
5942 objc-method-type objc-method-decl ;[opt] compound-statement
5946 c_parser_objc_method_definition (c_parser
*parser
)
5948 enum tree_code type
= c_parser_objc_method_type (parser
);
5950 objc_set_method_type (type
);
5951 parser
->objc_pq_context
= true;
5952 decl
= c_parser_objc_method_decl (parser
);
5953 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5955 c_parser_consume_token (parser
);
5957 pedwarn ("extra semicolon in method definition specified");
5959 if (!c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5961 c_parser_error (parser
, "expected %<{%>");
5964 parser
->objc_pq_context
= false;
5965 objc_start_method_definition (decl
);
5966 add_stmt (c_parser_compound_statement (parser
));
5967 objc_finish_method_definition (current_function_decl
);
5970 /* Parse an objc-methodprotolist.
5972 objc-methodprotolist:
5974 objc-methodprotolist objc-methodproto
5975 objc-methodprotolist declaration
5976 objc-methodprotolist ;
5978 The declaration is a data definition, which may be missing
5979 declaration specifiers under the same rules and diagnostics as
5980 other data definitions outside functions, and the stray semicolon
5981 is diagnosed the same way as a stray semicolon outside a
5985 c_parser_objc_methodprotolist (c_parser
*parser
)
5989 /* The list is terminated by @end. */
5990 switch (c_parser_peek_token (parser
)->type
)
5994 pedwarn ("ISO C does not allow extra %<;%> outside of a function");
5995 c_parser_consume_token (parser
);
5999 c_parser_objc_methodproto (parser
);
6002 c_parser_pragma (parser
, pragma_external
);
6007 if (c_parser_next_token_is_keyword (parser
, RID_AT_END
))
6009 c_parser_declaration_or_fndef (parser
, false, true, false, true);
6015 /* Parse an objc-methodproto.
6018 objc-method-type objc-method-decl ;
6022 c_parser_objc_methodproto (c_parser
*parser
)
6024 enum tree_code type
= c_parser_objc_method_type (parser
);
6026 objc_set_method_type (type
);
6027 /* Remember protocol qualifiers in prototypes. */
6028 parser
->objc_pq_context
= true;
6029 decl
= c_parser_objc_method_decl (parser
);
6030 /* Forget protocol qualifiers here. */
6031 parser
->objc_pq_context
= false;
6032 objc_add_method_declaration (decl
);
6033 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
6036 /* Parse an objc-method-decl.
6039 ( objc-type-name ) objc-selector
6041 ( objc-type-name ) objc-keyword-selector objc-optparmlist
6042 objc-keyword-selector objc-optparmlist
6044 objc-keyword-selector:
6046 objc-keyword-selector objc-keyword-decl
6049 objc-selector : ( objc-type-name ) identifier
6050 objc-selector : identifier
6051 : ( objc-type-name ) identifier
6055 objc-optparms objc-optellipsis
6059 objc-opt-parms , parameter-declaration
6067 c_parser_objc_method_decl (c_parser
*parser
)
6069 tree type
= NULL_TREE
;
6071 tree parms
= NULL_TREE
;
6072 bool ellipsis
= false;
6074 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
6076 c_parser_consume_token (parser
);
6077 type
= c_parser_objc_type_name (parser
);
6078 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6080 sel
= c_parser_objc_selector (parser
);
6081 /* If there is no selector, or a colon follows, we have an
6082 objc-keyword-selector. If there is a selector, and a colon does
6083 not follow, that selector ends the objc-method-decl. */
6084 if (!sel
|| c_parser_next_token_is (parser
, CPP_COLON
))
6087 tree list
= NULL_TREE
;
6090 tree atype
= NULL_TREE
, id
, keyworddecl
;
6091 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6093 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
6095 c_parser_consume_token (parser
);
6096 atype
= c_parser_objc_type_name (parser
);
6097 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6100 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6102 c_parser_error (parser
, "expected identifier");
6103 return error_mark_node
;
6105 id
= c_parser_peek_token (parser
)->value
;
6106 c_parser_consume_token (parser
);
6107 keyworddecl
= objc_build_keyword_decl (tsel
, atype
, id
);
6108 list
= chainon (list
, keyworddecl
);
6109 tsel
= c_parser_objc_selector (parser
);
6110 if (!tsel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6113 /* Parse the optional parameter list. Optional Objective-C
6114 method parameters follow the C syntax, and may include '...'
6115 to denote a variable number of arguments. */
6116 parms
= make_node (TREE_LIST
);
6117 while (c_parser_next_token_is (parser
, CPP_COMMA
))
6119 struct c_parm
*parm
;
6120 c_parser_consume_token (parser
);
6121 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
6124 c_parser_consume_token (parser
);
6127 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
6130 parms
= chainon (parms
,
6131 build_tree_list (NULL_TREE
, grokparm (parm
)));
6135 return objc_build_method_signature (type
, sel
, parms
, ellipsis
);
6138 /* Parse an objc-type-name.
6141 objc-type-qualifiers[opt] type-name
6142 objc-type-qualifiers[opt]
6144 objc-type-qualifiers:
6146 objc-type-qualifiers objc-type-qualifier
6148 objc-type-qualifier: one of
6149 in out inout bycopy byref oneway
6153 c_parser_objc_type_name (c_parser
*parser
)
6155 tree quals
= NULL_TREE
;
6156 struct c_type_name
*typename
= NULL
;
6157 tree type
= NULL_TREE
;
6160 c_token
*token
= c_parser_peek_token (parser
);
6161 if (token
->type
== CPP_KEYWORD
6162 && (token
->keyword
== RID_IN
6163 || token
->keyword
== RID_OUT
6164 || token
->keyword
== RID_INOUT
6165 || token
->keyword
== RID_BYCOPY
6166 || token
->keyword
== RID_BYREF
6167 || token
->keyword
== RID_ONEWAY
))
6169 quals
= chainon (quals
, build_tree_list (NULL_TREE
, token
->value
));
6170 c_parser_consume_token (parser
);
6175 if (c_parser_next_token_starts_typename (parser
))
6176 typename
= c_parser_type_name (parser
);
6178 type
= groktypename (typename
);
6179 return build_tree_list (quals
, type
);
6182 /* Parse objc-protocol-refs.
6189 c_parser_objc_protocol_refs (c_parser
*parser
)
6191 tree list
= NULL_TREE
;
6192 gcc_assert (c_parser_next_token_is (parser
, CPP_LESS
));
6193 c_parser_consume_token (parser
);
6194 /* Any identifiers, including those declared as type names, are OK
6199 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6201 c_parser_error (parser
, "expected identifier");
6204 id
= c_parser_peek_token (parser
)->value
;
6205 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
6206 c_parser_consume_token (parser
);
6207 if (c_parser_next_token_is (parser
, CPP_COMMA
))
6208 c_parser_consume_token (parser
);
6212 c_parser_require (parser
, CPP_GREATER
, "expected %<>%>");
6216 /* Parse an objc-try-catch-statement.
6218 objc-try-catch-statement:
6219 @try compound-statement objc-catch-list[opt]
6220 @try compound-statement objc-catch-list[opt] @finally compound-statement
6223 @catch ( parameter-declaration ) compound-statement
6224 objc-catch-list @catch ( parameter-declaration ) compound-statement
6228 c_parser_objc_try_catch_statement (c_parser
*parser
)
6232 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_TRY
));
6233 c_parser_consume_token (parser
);
6234 loc
= c_parser_peek_token (parser
)->location
;
6235 stmt
= c_parser_compound_statement (parser
);
6236 objc_begin_try_stmt (loc
, stmt
);
6237 while (c_parser_next_token_is_keyword (parser
, RID_AT_CATCH
))
6239 struct c_parm
*parm
;
6240 c_parser_consume_token (parser
);
6241 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6243 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
6246 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6249 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6250 objc_begin_catch_clause (grokparm (parm
));
6251 if (c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
6252 c_parser_compound_statement_nostart (parser
);
6253 objc_finish_catch_clause ();
6255 if (c_parser_next_token_is_keyword (parser
, RID_AT_FINALLY
))
6259 c_parser_consume_token (parser
);
6260 finloc
= c_parser_peek_token (parser
)->location
;
6261 finstmt
= c_parser_compound_statement (parser
);
6262 objc_build_finally_clause (finloc
, finstmt
);
6264 objc_finish_try_stmt ();
6267 /* Parse an objc-synchronized-statement.
6269 objc-synchronized-statement:
6270 @synchronized ( expression ) compound-statement
6274 c_parser_objc_synchronized_statement (c_parser
*parser
)
6278 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNCHRONIZED
));
6279 c_parser_consume_token (parser
);
6280 loc
= c_parser_peek_token (parser
)->location
;
6281 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6283 expr
= c_parser_expression (parser
).value
;
6284 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6287 expr
= error_mark_node
;
6288 stmt
= c_parser_compound_statement (parser
);
6289 objc_build_synchronized (loc
, expr
, stmt
);
6292 /* Parse an objc-selector; return NULL_TREE without an error if the
6293 next token is not an objc-selector.
6298 enum struct union if else while do for switch case default
6299 break continue return goto asm sizeof typeof __alignof
6300 unsigned long const short volatile signed restrict _Complex
6301 in out inout bycopy byref oneway int char float double void _Bool
6303 ??? Why this selection of keywords but not, for example, storage
6304 class specifiers? */
6307 c_parser_objc_selector (c_parser
*parser
)
6309 c_token
*token
= c_parser_peek_token (parser
);
6310 tree value
= token
->value
;
6311 if (token
->type
== CPP_NAME
)
6313 c_parser_consume_token (parser
);
6316 if (token
->type
!= CPP_KEYWORD
)
6318 switch (token
->keyword
)
6359 c_parser_consume_token (parser
);
6366 /* Parse an objc-selector-arg.
6370 objc-keywordname-list
6372 objc-keywordname-list:
6374 objc-keywordname-list objc-keywordname
6382 c_parser_objc_selector_arg (c_parser
*parser
)
6384 tree sel
= c_parser_objc_selector (parser
);
6385 tree list
= NULL_TREE
;
6386 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6390 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6392 list
= chainon (list
, build_tree_list (sel
, NULL_TREE
));
6393 sel
= c_parser_objc_selector (parser
);
6394 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6400 /* Parse an objc-receiver.
6409 c_parser_objc_receiver (c_parser
*parser
)
6411 if (c_parser_peek_token (parser
)->type
== CPP_NAME
6412 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
6413 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
6415 tree id
= c_parser_peek_token (parser
)->value
;
6416 c_parser_consume_token (parser
);
6417 return objc_get_class_reference (id
);
6419 return c_parser_expression (parser
).value
;
6422 /* Parse objc-message-args.
6426 objc-keywordarg-list
6428 objc-keywordarg-list:
6430 objc-keywordarg-list objc-keywordarg
6433 objc-selector : objc-keywordexpr
6438 c_parser_objc_message_args (c_parser
*parser
)
6440 tree sel
= c_parser_objc_selector (parser
);
6441 tree list
= NULL_TREE
;
6442 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6447 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6449 keywordexpr
= c_parser_objc_keywordexpr (parser
);
6450 list
= chainon (list
, build_tree_list (sel
, keywordexpr
));
6451 sel
= c_parser_objc_selector (parser
);
6452 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6458 /* Parse an objc-keywordexpr.
6465 c_parser_objc_keywordexpr (c_parser
*parser
)
6467 tree list
= c_parser_expr_list (parser
, true);
6468 if (TREE_CHAIN (list
) == NULL_TREE
)
6470 /* Just return the expression, remove a level of
6472 return TREE_VALUE (list
);
6476 /* We have a comma expression, we will collapse later. */
6482 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
6483 should be considered, statements. ALLOW_STMT is true if we're within
6484 the context of a function and such pragmas are to be allowed. Returns
6485 true if we actually parsed such a pragma. */
6488 c_parser_pragma (c_parser
*parser
, enum pragma_context context
)
6492 id
= c_parser_peek_token (parser
)->pragma_kind
;
6493 gcc_assert (id
!= PRAGMA_NONE
);
6497 case PRAGMA_OMP_BARRIER
:
6498 if (context
!= pragma_compound
)
6500 if (context
== pragma_stmt
)
6501 c_parser_error (parser
, "%<#pragma omp barrier%> may only be "
6502 "used in compound statements");
6505 c_parser_omp_barrier (parser
);
6508 case PRAGMA_OMP_FLUSH
:
6509 if (context
!= pragma_compound
)
6511 if (context
== pragma_stmt
)
6512 c_parser_error (parser
, "%<#pragma omp flush%> may only be "
6513 "used in compound statements");
6516 c_parser_omp_flush (parser
);
6519 case PRAGMA_OMP_THREADPRIVATE
:
6520 c_parser_omp_threadprivate (parser
);
6523 case PRAGMA_OMP_SECTION
:
6524 error ("%<#pragma omp section%> may only be used in "
6525 "%<#pragma omp sections%> construct");
6526 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
6529 case PRAGMA_GCC_PCH_PREPROCESS
:
6530 c_parser_error (parser
, "%<#pragma GCC pch_preprocess%> must be first");
6531 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
6535 if (id
< PRAGMA_FIRST_EXTERNAL
)
6537 if (context
== pragma_external
)
6540 c_parser_error (parser
, "expected declaration specifiers");
6541 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
6544 c_parser_omp_construct (parser
);
6550 c_parser_consume_pragma (parser
);
6551 c_invoke_pragma_handler (id
);
6553 /* Skip to EOL, but suppress any error message. Those will have been
6554 generated by the handler routine through calling error, as opposed
6555 to calling c_parser_error. */
6556 parser
->error
= true;
6557 c_parser_skip_to_pragma_eol (parser
);
6562 /* The interface the pragma parsers have to the lexer. */
6565 pragma_lex (tree
*value
)
6567 c_token
*tok
= c_parser_peek_token (the_parser
);
6568 enum cpp_ttype ret
= tok
->type
;
6570 *value
= tok
->value
;
6571 if (ret
== CPP_PRAGMA_EOL
|| ret
== CPP_EOF
)
6575 if (ret
== CPP_KEYWORD
)
6577 c_parser_consume_token (the_parser
);
6584 c_parser_pragma_pch_preprocess (c_parser
*parser
)
6588 c_parser_consume_pragma (parser
);
6589 if (c_parser_next_token_is (parser
, CPP_STRING
))
6591 name
= c_parser_peek_token (parser
)->value
;
6592 c_parser_consume_token (parser
);
6595 c_parser_error (parser
, "expected string literal");
6596 c_parser_skip_to_pragma_eol (parser
);
6599 c_common_pch_pragma (parse_in
, TREE_STRING_POINTER (name
));
6602 /* OpenMP 2.5 parsing routines. */
6604 /* Returns name of the next clause.
6605 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
6606 the token is not consumed. Otherwise appropriate pragma_omp_clause is
6607 returned and the token is consumed. */
6609 static pragma_omp_clause
6610 c_parser_omp_clause_name (c_parser
*parser
)
6612 pragma_omp_clause result
= PRAGMA_OMP_CLAUSE_NONE
;
6614 if (c_parser_next_token_is_keyword (parser
, RID_IF
))
6615 result
= PRAGMA_OMP_CLAUSE_IF
;
6616 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
6617 result
= PRAGMA_OMP_CLAUSE_DEFAULT
;
6618 else if (c_parser_next_token_is (parser
, CPP_NAME
))
6620 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
6625 if (!strcmp ("copyin", p
))
6626 result
= PRAGMA_OMP_CLAUSE_COPYIN
;
6627 else if (!strcmp ("copyprivate", p
))
6628 result
= PRAGMA_OMP_CLAUSE_COPYPRIVATE
;
6631 if (!strcmp ("firstprivate", p
))
6632 result
= PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
;
6635 if (!strcmp ("lastprivate", p
))
6636 result
= PRAGMA_OMP_CLAUSE_LASTPRIVATE
;
6639 if (!strcmp ("nowait", p
))
6640 result
= PRAGMA_OMP_CLAUSE_NOWAIT
;
6641 else if (!strcmp ("num_threads", p
))
6642 result
= PRAGMA_OMP_CLAUSE_NUM_THREADS
;
6645 if (!strcmp ("ordered", p
))
6646 result
= PRAGMA_OMP_CLAUSE_ORDERED
;
6649 if (!strcmp ("private", p
))
6650 result
= PRAGMA_OMP_CLAUSE_PRIVATE
;
6653 if (!strcmp ("reduction", p
))
6654 result
= PRAGMA_OMP_CLAUSE_REDUCTION
;
6657 if (!strcmp ("schedule", p
))
6658 result
= PRAGMA_OMP_CLAUSE_SCHEDULE
;
6659 else if (!strcmp ("shared", p
))
6660 result
= PRAGMA_OMP_CLAUSE_SHARED
;
6665 if (result
!= PRAGMA_OMP_CLAUSE_NONE
)
6666 c_parser_consume_token (parser
);
6671 /* Validate that a clause of the given type does not already exist. */
6674 check_no_duplicate_clause (tree clauses
, enum tree_code code
, const char *name
)
6678 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
6679 if (OMP_CLAUSE_CODE (c
) == code
)
6681 error ("too many %qs clauses", name
);
6689 variable-list , identifier
6691 If KIND is nonzero, create the appropriate node and install the decl
6692 in OMP_CLAUSE_DECL and add the node to the head of the list.
6694 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
6695 return the list created. */
6698 c_parser_omp_variable_list (c_parser
*parser
, enum omp_clause_code kind
,
6701 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
6702 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
6703 c_parser_error (parser
, "expected identifier");
6705 while (c_parser_next_token_is (parser
, CPP_NAME
)
6706 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
6708 tree t
= lookup_name (c_parser_peek_token (parser
)->value
);
6711 undeclared_variable (c_parser_peek_token (parser
)->value
,
6712 c_parser_peek_token (parser
)->location
);
6713 else if (t
== error_mark_node
)
6717 tree u
= build_omp_clause (kind
);
6718 OMP_CLAUSE_DECL (u
) = t
;
6719 OMP_CLAUSE_CHAIN (u
) = list
;
6723 list
= tree_cons (t
, NULL_TREE
, list
);
6725 c_parser_consume_token (parser
);
6727 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
6730 c_parser_consume_token (parser
);
6736 /* Similarly, but expect leading and trailing parenthesis. This is a very
6737 common case for omp clauses. */
6740 c_parser_omp_var_list_parens (c_parser
*parser
, enum tree_code kind
, tree list
)
6742 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6744 list
= c_parser_omp_variable_list (parser
, kind
, list
);
6745 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6751 copyin ( variable-list ) */
6754 c_parser_omp_clause_copyin (c_parser
*parser
, tree list
)
6756 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYIN
, list
);
6760 copyprivate ( variable-list ) */
6763 c_parser_omp_clause_copyprivate (c_parser
*parser
, tree list
)
6765 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYPRIVATE
, list
);
6769 default ( shared | none ) */
6772 c_parser_omp_clause_default (c_parser
*parser
, tree list
)
6774 enum omp_clause_default_kind kind
= OMP_CLAUSE_DEFAULT_UNSPECIFIED
;
6777 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6779 if (c_parser_next_token_is (parser
, CPP_NAME
))
6781 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
6786 if (strcmp ("none", p
) != 0)
6788 kind
= OMP_CLAUSE_DEFAULT_NONE
;
6792 if (strcmp ("shared", p
) != 0)
6794 kind
= OMP_CLAUSE_DEFAULT_SHARED
;
6801 c_parser_consume_token (parser
);
6806 c_parser_error (parser
, "expected %<none%> or %<shared%>");
6808 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6810 if (kind
== OMP_CLAUSE_DEFAULT_UNSPECIFIED
)
6813 check_no_duplicate_clause (list
, OMP_CLAUSE_DEFAULT
, "default");
6814 c
= build_omp_clause (OMP_CLAUSE_DEFAULT
);
6815 OMP_CLAUSE_CHAIN (c
) = list
;
6816 OMP_CLAUSE_DEFAULT_KIND (c
) = kind
;
6822 firstprivate ( variable-list ) */
6825 c_parser_omp_clause_firstprivate (c_parser
*parser
, tree list
)
6827 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FIRSTPRIVATE
, list
);
6831 if ( expression ) */
6834 c_parser_omp_clause_if (c_parser
*parser
, tree list
)
6836 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
6838 tree t
= c_parser_paren_condition (parser
);
6841 check_no_duplicate_clause (list
, OMP_CLAUSE_IF
, "if");
6843 c
= build_omp_clause (OMP_CLAUSE_IF
);
6844 OMP_CLAUSE_IF_EXPR (c
) = t
;
6845 OMP_CLAUSE_CHAIN (c
) = list
;
6849 c_parser_error (parser
, "expected %<(%>");
6855 lastprivate ( variable-list ) */
6858 c_parser_omp_clause_lastprivate (c_parser
*parser
, tree list
)
6860 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_LASTPRIVATE
, list
);
6867 c_parser_omp_clause_nowait (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
6871 check_no_duplicate_clause (list
, OMP_CLAUSE_NOWAIT
, "nowait");
6873 c
= build_omp_clause (OMP_CLAUSE_NOWAIT
);
6874 OMP_CLAUSE_CHAIN (c
) = list
;
6879 num_threads ( expression ) */
6882 c_parser_omp_clause_num_threads (c_parser
*parser
, tree list
)
6884 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6886 tree c
, t
= c_parser_expression (parser
).value
;
6888 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6890 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
6892 c_parser_error (parser
, "expected integer expression");
6896 /* Attempt to statically determine when the number isn't positive. */
6897 c
= fold_build2 (LE_EXPR
, boolean_type_node
, t
,
6898 build_int_cst (TREE_TYPE (t
), 0));
6899 if (c
== boolean_true_node
)
6901 warning (0, "%<num_threads%> value must be positive");
6902 t
= integer_one_node
;
6905 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_THREADS
, "num_threads");
6907 c
= build_omp_clause (OMP_CLAUSE_NUM_THREADS
);
6908 OMP_CLAUSE_NUM_THREADS_EXPR (c
) = t
;
6909 OMP_CLAUSE_CHAIN (c
) = list
;
6920 c_parser_omp_clause_ordered (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
6924 check_no_duplicate_clause (list
, OMP_CLAUSE_ORDERED
, "ordered");
6926 c
= build_omp_clause (OMP_CLAUSE_ORDERED
);
6927 OMP_CLAUSE_CHAIN (c
) = list
;
6932 private ( variable-list ) */
6935 c_parser_omp_clause_private (c_parser
*parser
, tree list
)
6937 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_PRIVATE
, list
);
6941 reduction ( reduction-operator : variable-list )
6944 One of: + * - & ^ | && || */
6947 c_parser_omp_clause_reduction (c_parser
*parser
, tree list
)
6949 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6951 enum tree_code code
;
6953 switch (c_parser_peek_token (parser
)->type
)
6965 code
= BIT_AND_EXPR
;
6968 code
= BIT_XOR_EXPR
;
6971 code
= BIT_IOR_EXPR
;
6974 code
= TRUTH_ANDIF_EXPR
;
6977 code
= TRUTH_ORIF_EXPR
;
6980 c_parser_error (parser
,
6981 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
6982 "%<^%>, %<|%>, %<&&%>, or %<||%>");
6983 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
6986 c_parser_consume_token (parser
);
6987 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6991 nl
= c_parser_omp_variable_list (parser
, OMP_CLAUSE_REDUCTION
, list
);
6992 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
6993 OMP_CLAUSE_REDUCTION_CODE (c
) = code
;
6997 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7003 schedule ( schedule-kind )
7004 schedule ( schedule-kind , expression )
7007 static | dynamic | guided | runtime
7011 c_parser_omp_clause_schedule (c_parser
*parser
, tree list
)
7015 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7018 c
= build_omp_clause (OMP_CLAUSE_SCHEDULE
);
7020 if (c_parser_next_token_is (parser
, CPP_NAME
))
7022 tree kind
= c_parser_peek_token (parser
)->value
;
7023 const char *p
= IDENTIFIER_POINTER (kind
);
7028 if (strcmp ("dynamic", p
) != 0)
7030 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_DYNAMIC
;
7034 if (strcmp ("guided", p
) != 0)
7036 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_GUIDED
;
7040 if (strcmp ("runtime", p
) != 0)
7042 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_RUNTIME
;
7049 else if (c_parser_next_token_is_keyword (parser
, RID_STATIC
))
7050 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_STATIC
;
7054 c_parser_consume_token (parser
);
7055 if (c_parser_next_token_is (parser
, CPP_COMMA
))
7057 c_parser_consume_token (parser
);
7059 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
7061 if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_RUNTIME
)
7062 error ("schedule %<runtime%> does not take "
7063 "a %<chunk_size%> parameter");
7064 else if (TREE_CODE (TREE_TYPE (t
)) == INTEGER_TYPE
)
7065 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
) = t
;
7067 c_parser_error (parser
, "expected integer expression");
7069 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7072 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7073 "expected %<,%> or %<)%>");
7075 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
7076 OMP_CLAUSE_CHAIN (c
) = list
;
7080 c_parser_error (parser
, "invalid schedule kind");
7081 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
7086 shared ( variable-list ) */
7089 c_parser_omp_clause_shared (c_parser
*parser
, tree list
)
7091 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_SHARED
, list
);
7094 /* Parse all OpenMP clauses. The set clauses allowed by the directive
7095 is a bitmask in MASK. Return the list of clauses found; the result
7096 of clause default goes in *pdefault. */
7099 c_parser_omp_all_clauses (c_parser
*parser
, unsigned int mask
,
7102 tree clauses
= NULL
;
7104 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
7106 const pragma_omp_clause c_kind
= c_parser_omp_clause_name (parser
);
7108 tree prev
= clauses
;
7112 case PRAGMA_OMP_CLAUSE_COPYIN
:
7113 clauses
= c_parser_omp_clause_copyin (parser
, clauses
);
7116 case PRAGMA_OMP_CLAUSE_COPYPRIVATE
:
7117 clauses
= c_parser_omp_clause_copyprivate (parser
, clauses
);
7118 c_name
= "copyprivate";
7120 case PRAGMA_OMP_CLAUSE_DEFAULT
:
7121 clauses
= c_parser_omp_clause_default (parser
, clauses
);
7124 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
:
7125 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
7126 c_name
= "firstprivate";
7128 case PRAGMA_OMP_CLAUSE_IF
:
7129 clauses
= c_parser_omp_clause_if (parser
, clauses
);
7132 case PRAGMA_OMP_CLAUSE_LASTPRIVATE
:
7133 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
7134 c_name
= "lastprivate";
7136 case PRAGMA_OMP_CLAUSE_NOWAIT
:
7137 clauses
= c_parser_omp_clause_nowait (parser
, clauses
);
7140 case PRAGMA_OMP_CLAUSE_NUM_THREADS
:
7141 clauses
= c_parser_omp_clause_num_threads (parser
, clauses
);
7142 c_name
= "num_threads";
7144 case PRAGMA_OMP_CLAUSE_ORDERED
:
7145 clauses
= c_parser_omp_clause_ordered (parser
, clauses
);
7148 case PRAGMA_OMP_CLAUSE_PRIVATE
:
7149 clauses
= c_parser_omp_clause_private (parser
, clauses
);
7152 case PRAGMA_OMP_CLAUSE_REDUCTION
:
7153 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
7154 c_name
= "reduction";
7156 case PRAGMA_OMP_CLAUSE_SCHEDULE
:
7157 clauses
= c_parser_omp_clause_schedule (parser
, clauses
);
7158 c_name
= "schedule";
7160 case PRAGMA_OMP_CLAUSE_SHARED
:
7161 clauses
= c_parser_omp_clause_shared (parser
, clauses
);
7165 c_parser_error (parser
, "expected %<#pragma omp%> clause");
7169 if (((mask
>> c_kind
) & 1) == 0 && !parser
->error
)
7171 /* Remove the invalid clause(s) from the list to avoid
7172 confusing the rest of the compiler. */
7174 error ("%qs is not valid for %qs", c_name
, where
);
7179 c_parser_skip_to_pragma_eol (parser
);
7181 return c_finish_omp_clauses (clauses
);
7188 In practice, we're also interested in adding the statement to an
7189 outer node. So it is convenient if we work around the fact that
7190 c_parser_statement calls add_stmt. */
7193 c_parser_omp_structured_block (c_parser
*parser
)
7195 tree stmt
= push_stmt_list ();
7196 c_parser_statement (parser
);
7197 return pop_stmt_list (stmt
);
7201 # pragma omp atomic new-line
7205 x binop= expr | x++ | ++x | x-- | --x
7207 +, *, -, /, &, ^, |, <<, >>
7209 where x is an lvalue expression with scalar type. */
7212 c_parser_omp_atomic (c_parser
*parser
)
7216 enum tree_code code
;
7218 c_parser_skip_to_pragma_eol (parser
);
7220 lhs
= c_parser_unary_expression (parser
).value
;
7221 switch (TREE_CODE (lhs
))
7225 c_parser_skip_to_end_of_block_or_statement (parser
);
7228 case PREINCREMENT_EXPR
:
7229 case POSTINCREMENT_EXPR
:
7230 lhs
= TREE_OPERAND (lhs
, 0);
7232 rhs
= integer_one_node
;
7235 case PREDECREMENT_EXPR
:
7236 case POSTDECREMENT_EXPR
:
7237 lhs
= TREE_OPERAND (lhs
, 0);
7239 rhs
= integer_one_node
;
7243 switch (c_parser_peek_token (parser
)->type
)
7249 code
= TRUNC_DIV_EXPR
;
7264 code
= BIT_AND_EXPR
;
7267 code
= BIT_IOR_EXPR
;
7270 code
= BIT_XOR_EXPR
;
7273 c_parser_error (parser
,
7274 "invalid operator for %<#pragma omp atomic%>");
7278 c_parser_consume_token (parser
);
7279 rhs
= c_parser_expression (parser
).value
;
7282 stmt
= c_finish_omp_atomic (code
, lhs
, rhs
);
7283 if (stmt
!= error_mark_node
)
7285 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7290 # pragma omp barrier new-line
7294 c_parser_omp_barrier (c_parser
*parser
)
7296 c_parser_consume_pragma (parser
);
7297 c_parser_skip_to_pragma_eol (parser
);
7299 c_finish_omp_barrier ();
7303 # pragma omp critical [(name)] new-line
7308 c_parser_omp_critical (c_parser
*parser
)
7310 tree stmt
, name
= NULL
;
7312 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
7314 c_parser_consume_token (parser
);
7315 if (c_parser_next_token_is (parser
, CPP_NAME
))
7317 name
= c_parser_peek_token (parser
)->value
;
7318 c_parser_consume_token (parser
);
7319 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7322 c_parser_error (parser
, "expected identifier");
7324 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
7325 c_parser_error (parser
, "expected %<(%> or end of line");
7326 c_parser_skip_to_pragma_eol (parser
);
7328 stmt
= c_parser_omp_structured_block (parser
);
7329 return c_finish_omp_critical (stmt
, name
);
7333 # pragma omp flush flush-vars[opt] new-line
7336 ( variable-list ) */
7339 c_parser_omp_flush (c_parser
*parser
)
7341 c_parser_consume_pragma (parser
);
7342 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
7343 c_parser_omp_var_list_parens (parser
, 0, NULL
);
7344 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
7345 c_parser_error (parser
, "expected %<(%> or end of line");
7346 c_parser_skip_to_pragma_eol (parser
);
7348 c_finish_omp_flush ();
7351 /* Parse the restricted form of the for statment allowed by OpenMP.
7352 The real trick here is to determine the loop control variable early
7353 so that we can push a new decl if necessary to make it private. */
7356 c_parser_omp_for_loop (c_parser
*parser
)
7358 tree decl
, cond
, incr
, save_break
, save_cont
, body
, init
;
7361 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
))
7363 c_parser_error (parser
, "for statement expected");
7366 loc
= c_parser_peek_token (parser
)->location
;
7367 c_parser_consume_token (parser
);
7369 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7372 /* Parse the initialization declaration or expression. */
7373 if (c_parser_next_token_starts_declspecs (parser
))
7375 c_parser_declaration_or_fndef (parser
, true, true, true, true);
7376 decl
= check_for_loop_decls ();
7381 else if (c_parser_next_token_is (parser
, CPP_NAME
)
7382 && c_parser_peek_2nd_token (parser
)->type
== CPP_EQ
)
7384 decl
= c_parser_postfix_expression (parser
).value
;
7386 c_parser_require (parser
, CPP_EQ
, "expected %<=%>");
7388 init
= c_parser_expr_no_commas (parser
, NULL
).value
;
7389 init
= build_modify_expr (decl
, NOP_EXPR
, init
);
7390 init
= c_process_expr_stmt (init
);
7392 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7397 /* Parse the loop condition. */
7399 if (c_parser_next_token_is_not (parser
, CPP_SEMICOLON
))
7401 cond
= c_parser_expression_conv (parser
).value
;
7402 cond
= c_objc_common_truthvalue_conversion (cond
);
7403 if (CAN_HAVE_LOCATION_P (cond
))
7404 SET_EXPR_LOCATION (cond
, input_location
);
7406 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7408 /* Parse the increment expression. */
7410 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_PAREN
))
7411 incr
= c_process_expr_stmt (c_parser_expression (parser
).value
);
7412 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7415 save_break
= c_break_label
;
7416 c_break_label
= size_one_node
;
7417 save_cont
= c_cont_label
;
7418 c_cont_label
= NULL_TREE
;
7419 body
= push_stmt_list ();
7421 add_stmt (c_parser_c99_block_statement (parser
));
7423 add_stmt (build1 (LABEL_EXPR
, void_type_node
, c_cont_label
));
7425 body
= pop_stmt_list (body
);
7426 c_break_label
= save_break
;
7427 c_cont_label
= save_cont
;
7429 /* Only bother calling c_finish_omp_for if we havn't already generated
7430 an error from the initialization parsing. */
7431 if (decl
!= NULL
&& decl
!= error_mark_node
&& init
!= error_mark_node
)
7432 return c_finish_omp_for (loc
, decl
, init
, cond
, incr
, body
, NULL
);
7436 c_parser_error (parser
, "expected iteration declaration or initialization");
7437 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7438 decl
= init
= cond
= incr
= NULL_TREE
;
7443 #pragma omp for for-clause[optseq] new-line
7447 #define OMP_FOR_CLAUSE_MASK \
7448 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
7449 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
7450 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
7451 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
7452 | (1u << PRAGMA_OMP_CLAUSE_ORDERED) \
7453 | (1u << PRAGMA_OMP_CLAUSE_SCHEDULE) \
7454 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
7457 c_parser_omp_for (c_parser
*parser
)
7459 tree block
, clauses
, ret
;
7461 clauses
= c_parser_omp_all_clauses (parser
, OMP_FOR_CLAUSE_MASK
,
7464 block
= c_begin_compound_stmt (true);
7465 ret
= c_parser_omp_for_loop (parser
);
7467 OMP_FOR_CLAUSES (ret
) = clauses
;
7468 block
= c_end_compound_stmt (block
, true);
7475 # pragma omp master new-line
7480 c_parser_omp_master (c_parser
*parser
)
7482 c_parser_skip_to_pragma_eol (parser
);
7483 return c_finish_omp_master (c_parser_omp_structured_block (parser
));
7487 # pragma omp ordered new-line
7492 c_parser_omp_ordered (c_parser
*parser
)
7494 c_parser_skip_to_pragma_eol (parser
);
7495 return c_finish_omp_ordered (c_parser_omp_structured_block (parser
));
7501 { section-sequence }
7504 section-directive[opt] structured-block
7505 section-sequence section-directive structured-block */
7508 c_parser_omp_sections_scope (c_parser
*parser
)
7511 bool error_suppress
= false;
7514 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
7516 /* Avoid skipping until the end of the block. */
7517 parser
->error
= false;
7521 stmt
= push_stmt_list ();
7523 loc
= c_parser_peek_token (parser
)->location
;
7524 if (c_parser_peek_token (parser
)->pragma_kind
!= PRAGMA_OMP_SECTION
)
7526 substmt
= push_stmt_list ();
7530 c_parser_statement (parser
);
7532 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
7534 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
7536 if (c_parser_next_token_is (parser
, CPP_EOF
))
7540 substmt
= pop_stmt_list (substmt
);
7541 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
7542 SET_EXPR_LOCATION (substmt
, loc
);
7548 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
7550 if (c_parser_next_token_is (parser
, CPP_EOF
))
7553 loc
= c_parser_peek_token (parser
)->location
;
7554 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
7556 c_parser_consume_pragma (parser
);
7557 c_parser_skip_to_pragma_eol (parser
);
7558 error_suppress
= false;
7560 else if (!error_suppress
)
7562 error ("expected %<#pragma omp section%> or %<}%>");
7563 error_suppress
= true;
7566 substmt
= c_parser_omp_structured_block (parser
);
7567 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
7568 SET_EXPR_LOCATION (substmt
, loc
);
7571 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
,
7572 "expected %<#pragma omp section%> or %<}%>");
7574 substmt
= pop_stmt_list (stmt
);
7576 stmt
= make_node (OMP_SECTIONS
);
7577 TREE_TYPE (stmt
) = void_type_node
;
7578 OMP_SECTIONS_BODY (stmt
) = substmt
;
7580 return add_stmt (stmt
);
7584 # pragma omp sections sections-clause[optseq] newline
7588 #define OMP_SECTIONS_CLAUSE_MASK \
7589 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
7590 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
7591 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
7592 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
7593 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
7596 c_parser_omp_sections (c_parser
*parser
)
7598 tree block
, clauses
, ret
;
7600 clauses
= c_parser_omp_all_clauses (parser
, OMP_SECTIONS_CLAUSE_MASK
,
7601 "#pragma omp sections");
7603 block
= c_begin_compound_stmt (true);
7604 ret
= c_parser_omp_sections_scope (parser
);
7606 OMP_SECTIONS_CLAUSES (ret
) = clauses
;
7607 block
= c_end_compound_stmt (block
, true);
7614 # pragma parallel parallel-clause new-line
7615 # pragma parallel for parallel-for-clause new-line
7616 # pragma parallel sections parallel-sections-clause new-line
7619 #define OMP_PARALLEL_CLAUSE_MASK \
7620 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
7621 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
7622 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
7623 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
7624 | (1u << PRAGMA_OMP_CLAUSE_SHARED) \
7625 | (1u << PRAGMA_OMP_CLAUSE_COPYIN) \
7626 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
7627 | (1u << PRAGMA_OMP_CLAUSE_NUM_THREADS))
7630 c_parser_omp_parallel (c_parser
*parser
)
7632 enum pragma_kind p_kind
= PRAGMA_OMP_PARALLEL
;
7633 const char *p_name
= "#pragma omp parallel";
7634 tree stmt
, clauses
, par_clause
, ws_clause
, block
;
7635 unsigned int mask
= OMP_PARALLEL_CLAUSE_MASK
;
7637 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
7639 c_parser_consume_token (parser
);
7640 p_kind
= PRAGMA_OMP_PARALLEL_FOR
;
7641 p_name
= "#pragma omp parallel for";
7642 mask
|= OMP_FOR_CLAUSE_MASK
;
7643 mask
&= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT
);
7645 else if (c_parser_next_token_is (parser
, CPP_NAME
))
7647 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
7648 if (strcmp (p
, "sections") == 0)
7650 c_parser_consume_token (parser
);
7651 p_kind
= PRAGMA_OMP_PARALLEL_SECTIONS
;
7652 p_name
= "#pragma omp parallel sections";
7653 mask
|= OMP_SECTIONS_CLAUSE_MASK
;
7654 mask
&= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT
);
7658 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
);
7662 case PRAGMA_OMP_PARALLEL
:
7663 block
= c_begin_omp_parallel ();
7664 c_parser_statement (parser
);
7665 stmt
= c_finish_omp_parallel (clauses
, block
);
7668 case PRAGMA_OMP_PARALLEL_FOR
:
7669 block
= c_begin_omp_parallel ();
7670 c_split_parallel_clauses (clauses
, &par_clause
, &ws_clause
);
7671 stmt
= c_parser_omp_for_loop (parser
);
7673 OMP_FOR_CLAUSES (stmt
) = ws_clause
;
7674 stmt
= c_finish_omp_parallel (par_clause
, block
);
7675 OMP_PARALLEL_COMBINED (stmt
) = 1;
7678 case PRAGMA_OMP_PARALLEL_SECTIONS
:
7679 block
= c_begin_omp_parallel ();
7680 c_split_parallel_clauses (clauses
, &par_clause
, &ws_clause
);
7681 stmt
= c_parser_omp_sections_scope (parser
);
7683 OMP_SECTIONS_CLAUSES (stmt
) = ws_clause
;
7684 stmt
= c_finish_omp_parallel (par_clause
, block
);
7685 OMP_PARALLEL_COMBINED (stmt
) = 1;
7696 # pragma omp single single-clause[optseq] new-line
7700 #define OMP_SINGLE_CLAUSE_MASK \
7701 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
7702 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
7703 | (1u << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
7704 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
7707 c_parser_omp_single (c_parser
*parser
)
7709 tree stmt
= make_node (OMP_SINGLE
);
7710 TREE_TYPE (stmt
) = void_type_node
;
7712 OMP_SINGLE_CLAUSES (stmt
)
7713 = c_parser_omp_all_clauses (parser
, OMP_SINGLE_CLAUSE_MASK
,
7714 "#pragma omp single");
7715 OMP_SINGLE_BODY (stmt
) = c_parser_omp_structured_block (parser
);
7717 return add_stmt (stmt
);
7721 /* Main entry point to parsing most OpenMP pragmas. */
7724 c_parser_omp_construct (c_parser
*parser
)
7726 enum pragma_kind p_kind
;
7730 loc
= c_parser_peek_token (parser
)->location
;
7731 p_kind
= c_parser_peek_token (parser
)->pragma_kind
;
7732 c_parser_consume_pragma (parser
);
7734 /* For all constructs below except #pragma omp atomic
7735 MUST_NOT_THROW catch handlers are needed when exceptions
7737 if (p_kind
!= PRAGMA_OMP_ATOMIC
)
7738 c_maybe_initialize_eh ();
7742 case PRAGMA_OMP_ATOMIC
:
7743 c_parser_omp_atomic (parser
);
7745 case PRAGMA_OMP_CRITICAL
:
7746 stmt
= c_parser_omp_critical (parser
);
7748 case PRAGMA_OMP_FOR
:
7749 stmt
= c_parser_omp_for (parser
);
7751 case PRAGMA_OMP_MASTER
:
7752 stmt
= c_parser_omp_master (parser
);
7754 case PRAGMA_OMP_ORDERED
:
7755 stmt
= c_parser_omp_ordered (parser
);
7757 case PRAGMA_OMP_PARALLEL
:
7758 stmt
= c_parser_omp_parallel (parser
);
7760 case PRAGMA_OMP_SECTIONS
:
7761 stmt
= c_parser_omp_sections (parser
);
7763 case PRAGMA_OMP_SINGLE
:
7764 stmt
= c_parser_omp_single (parser
);
7771 SET_EXPR_LOCATION (stmt
, loc
);
7776 # pragma omp threadprivate (variable-list) */
7779 c_parser_omp_threadprivate (c_parser
*parser
)
7783 c_parser_consume_pragma (parser
);
7784 vars
= c_parser_omp_var_list_parens (parser
, 0, NULL
);
7786 /* Mark every variable in VARS to be assigned thread local storage. */
7787 for (t
= vars
; t
; t
= TREE_CHAIN (t
))
7789 tree v
= TREE_PURPOSE (t
);
7791 /* If V had already been marked threadprivate, it doesn't matter
7792 whether it had been used prior to this point. */
7793 if (TREE_USED (v
) && !C_DECL_THREADPRIVATE_P (v
))
7794 error ("%qE declared %<threadprivate%> after first use", v
);
7795 else if (! TREE_STATIC (v
) && ! DECL_EXTERNAL (v
))
7796 error ("automatic variable %qE cannot be %<threadprivate%>", v
);
7797 else if (! COMPLETE_TYPE_P (TREE_TYPE (v
)))
7798 error ("%<threadprivate%> %qE has incomplete type", v
);
7801 if (! DECL_THREAD_LOCAL_P (v
))
7803 DECL_TLS_MODEL (v
) = decl_default_tls_model (v
);
7804 /* If rtl has been already set for this var, call
7805 make_decl_rtl once again, so that encode_section_info
7806 has a chance to look at the new decl flags. */
7807 if (DECL_RTL_SET_P (v
))
7810 C_DECL_THREADPRIVATE_P (v
) = 1;
7814 c_parser_skip_to_pragma_eol (parser
);
7818 /* Parse a single source file. */
7823 /* Use local storage to begin. If the first token is a pragma, parse it.
7824 If it is #pragma GCC pch_preprocess, then this will load a PCH file
7825 which will cause garbage collection. */
7828 memset (&tparser
, 0, sizeof tparser
);
7829 the_parser
= &tparser
;
7831 if (c_parser_peek_token (&tparser
)->pragma_kind
== PRAGMA_GCC_PCH_PREPROCESS
)
7832 c_parser_pragma_pch_preprocess (&tparser
);
7834 the_parser
= GGC_NEW (c_parser
);
7835 *the_parser
= tparser
;
7837 c_parser_translation_unit (the_parser
);
7841 #include "gt-c-parser.h"