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 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 /* Objective-C specific parser/lexer information. */
64 static int objc_pq_context
= 0;
66 /* The following flag is needed to contextualize Objective-C lexical
67 analysis. In some cases (e.g., 'int NSObject;'), it is undesirable
68 to bind an identifier to an Objective-C class, even if a class with
70 static int objc_need_raw_identifier
= 0;
71 #define OBJC_NEED_RAW_IDENTIFIER(VAL) \
73 if (c_dialect_objc ()) \
74 objc_need_raw_identifier = VAL; \
77 /* The reserved keyword table. */
81 ENUM_BITFIELD(rid
) rid
: 16;
82 unsigned int disable
: 16;
85 /* Disable mask. Keywords are disabled if (reswords[i].disable &
87 #define D_C89 0x01 /* not in C89 */
88 #define D_EXT 0x02 /* GCC extension */
89 #define D_EXT89 0x04 /* GCC extension incorporated in C99 */
90 #define D_OBJC 0x08 /* Objective C only */
92 static const struct resword reswords
[] =
94 { "_Bool", RID_BOOL
, 0 },
95 { "_Complex", RID_COMPLEX
, 0 },
96 { "_Decimal32", RID_DFLOAT32
, D_EXT
},
97 { "_Decimal64", RID_DFLOAT64
, D_EXT
},
98 { "_Decimal128", RID_DFLOAT128
, D_EXT
},
99 { "__FUNCTION__", RID_FUNCTION_NAME
, 0 },
100 { "__PRETTY_FUNCTION__", RID_PRETTY_FUNCTION_NAME
, 0 },
101 { "__alignof", RID_ALIGNOF
, 0 },
102 { "__alignof__", RID_ALIGNOF
, 0 },
103 { "__asm", RID_ASM
, 0 },
104 { "__asm__", RID_ASM
, 0 },
105 { "__attribute", RID_ATTRIBUTE
, 0 },
106 { "__attribute__", RID_ATTRIBUTE
, 0 },
107 { "__builtin_choose_expr", RID_CHOOSE_EXPR
, 0 },
108 { "__builtin_offsetof", RID_OFFSETOF
, 0 },
109 { "__builtin_types_compatible_p", RID_TYPES_COMPATIBLE_P
, 0 },
110 { "__builtin_va_arg", RID_VA_ARG
, 0 },
111 { "__complex", RID_COMPLEX
, 0 },
112 { "__complex__", RID_COMPLEX
, 0 },
113 { "__const", RID_CONST
, 0 },
114 { "__const__", RID_CONST
, 0 },
115 { "__extension__", RID_EXTENSION
, 0 },
116 { "__func__", RID_C99_FUNCTION_NAME
, 0 },
117 { "__imag", RID_IMAGPART
, 0 },
118 { "__imag__", RID_IMAGPART
, 0 },
119 { "__inline", RID_INLINE
, 0 },
120 { "__inline__", RID_INLINE
, 0 },
121 { "__label__", RID_LABEL
, 0 },
122 { "__real", RID_REALPART
, 0 },
123 { "__real__", RID_REALPART
, 0 },
124 { "__restrict", RID_RESTRICT
, 0 },
125 { "__restrict__", RID_RESTRICT
, 0 },
126 { "__signed", RID_SIGNED
, 0 },
127 { "__signed__", RID_SIGNED
, 0 },
128 { "__thread", RID_THREAD
, 0 },
129 { "__typeof", RID_TYPEOF
, 0 },
130 { "__typeof__", RID_TYPEOF
, 0 },
131 { "__volatile", RID_VOLATILE
, 0 },
132 { "__volatile__", RID_VOLATILE
, 0 },
133 { "asm", RID_ASM
, D_EXT
},
134 { "auto", RID_AUTO
, 0 },
135 { "break", RID_BREAK
, 0 },
136 { "case", RID_CASE
, 0 },
137 { "char", RID_CHAR
, 0 },
138 { "const", RID_CONST
, 0 },
139 { "continue", RID_CONTINUE
, 0 },
140 { "default", RID_DEFAULT
, 0 },
142 { "double", RID_DOUBLE
, 0 },
143 { "else", RID_ELSE
, 0 },
144 { "enum", RID_ENUM
, 0 },
145 { "extern", RID_EXTERN
, 0 },
146 { "float", RID_FLOAT
, 0 },
147 { "for", RID_FOR
, 0 },
148 { "goto", RID_GOTO
, 0 },
150 { "inline", RID_INLINE
, D_EXT89
},
151 { "int", RID_INT
, 0 },
152 { "long", RID_LONG
, 0 },
153 { "register", RID_REGISTER
, 0 },
154 { "restrict", RID_RESTRICT
, D_C89
},
155 { "return", RID_RETURN
, 0 },
156 { "short", RID_SHORT
, 0 },
157 { "signed", RID_SIGNED
, 0 },
158 { "sizeof", RID_SIZEOF
, 0 },
159 { "static", RID_STATIC
, 0 },
160 { "struct", RID_STRUCT
, 0 },
161 { "switch", RID_SWITCH
, 0 },
162 { "typedef", RID_TYPEDEF
, 0 },
163 { "typeof", RID_TYPEOF
, D_EXT
},
164 { "union", RID_UNION
, 0 },
165 { "unsigned", RID_UNSIGNED
, 0 },
166 { "void", RID_VOID
, 0 },
167 { "volatile", RID_VOLATILE
, 0 },
168 { "while", RID_WHILE
, 0 },
169 /* These Objective-C keywords are recognized only immediately after
171 { "class", RID_AT_CLASS
, D_OBJC
},
172 { "compatibility_alias", RID_AT_ALIAS
, D_OBJC
},
173 { "defs", RID_AT_DEFS
, D_OBJC
},
174 { "encode", RID_AT_ENCODE
, D_OBJC
},
175 { "end", RID_AT_END
, D_OBJC
},
176 { "implementation", RID_AT_IMPLEMENTATION
, D_OBJC
},
177 { "interface", RID_AT_INTERFACE
, D_OBJC
},
178 { "private", RID_AT_PRIVATE
, D_OBJC
},
179 { "protected", RID_AT_PROTECTED
, D_OBJC
},
180 { "protocol", RID_AT_PROTOCOL
, D_OBJC
},
181 { "public", RID_AT_PUBLIC
, D_OBJC
},
182 { "selector", RID_AT_SELECTOR
, D_OBJC
},
183 { "throw", RID_AT_THROW
, D_OBJC
},
184 { "try", RID_AT_TRY
, D_OBJC
},
185 { "catch", RID_AT_CATCH
, D_OBJC
},
186 { "finally", RID_AT_FINALLY
, D_OBJC
},
187 { "synchronized", RID_AT_SYNCHRONIZED
, D_OBJC
},
188 /* These are recognized only in protocol-qualifier context
190 { "bycopy", RID_BYCOPY
, D_OBJC
},
191 { "byref", RID_BYREF
, D_OBJC
},
192 { "in", RID_IN
, D_OBJC
},
193 { "inout", RID_INOUT
, D_OBJC
},
194 { "oneway", RID_ONEWAY
, D_OBJC
},
195 { "out", RID_OUT
, D_OBJC
},
197 #define N_reswords (sizeof reswords / sizeof (struct resword))
199 /* Initialization routine for this file. */
204 /* The only initialization required is of the reserved word
208 int mask
= (flag_isoc99
? 0 : D_C89
)
209 | (flag_no_asm
? (flag_isoc99
? D_EXT
: D_EXT
|D_EXT89
) : 0);
211 if (!c_dialect_objc ())
214 ridpointers
= GGC_CNEWVEC (tree
, (int) RID_MAX
);
215 for (i
= 0; i
< N_reswords
; i
++)
217 /* If a keyword is disabled, do not enter it into the table
218 and so create a canonical spelling that isn't a keyword. */
219 if (reswords
[i
].disable
& mask
)
222 id
= get_identifier (reswords
[i
].word
);
223 C_RID_CODE (id
) = reswords
[i
].rid
;
224 C_IS_RESERVED_WORD (id
) = 1;
225 ridpointers
[(int) reswords
[i
].rid
] = id
;
229 /* The C lexer intermediates between the lexer in cpplib and c-lex.c
230 and the C parser. Unlike the C++ lexer, the parser structure
231 stores the lexer information instead of using a separate structure.
232 Identifiers are separated into ordinary identifiers, type names,
233 keywords and some other Objective-C types of identifiers, and some
234 look-ahead is maintained.
236 ??? It might be a good idea to lex the whole file up front (as for
237 C++). It would then be possible to share more of the C and C++
238 lexer code, if desired. */
240 /* The following local token type is used. */
243 #define CPP_KEYWORD ((enum cpp_ttype) (N_TTYPES + 1))
245 /* More information about the type of a CPP_NAME token. */
246 typedef enum c_id_kind
{
247 /* An ordinary identifier. */
249 /* An identifier declared as a typedef name. */
251 /* An identifier declared as an Objective-C class name. */
253 /* Not an identifier. */
257 /* A single C token after string literal concatenation and conversion
258 of preprocessing tokens to tokens. */
259 typedef struct c_token
GTY (())
261 /* The kind of token. */
262 ENUM_BITFIELD (cpp_ttype
) type
: 8;
263 /* If this token is a CPP_NAME, this value indicates whether also
264 declared as some kind of type. Otherwise, it is C_ID_NONE. */
265 ENUM_BITFIELD (c_id_kind
) id_kind
: 8;
266 /* If this token is a keyword, this value indicates which keyword.
267 Otherwise, this value is RID_MAX. */
268 ENUM_BITFIELD (rid
) keyword
: 8;
269 /* If this token is a CPP_PRAGMA, this indicates the pragma that
270 was seen. Otherwise it is PRAGMA_NONE. */
271 ENUM_BITFIELD (pragma_kind
) pragma_kind
: 7;
272 /* True if this token is from a system header. */
273 BOOL_BITFIELD in_system_header
: 1;
274 /* The value associated with this token, if any. */
276 /* The location at which this token was found. */
280 /* A parser structure recording information about the state and
281 context of parsing. Includes lexer information with up to two
282 tokens of look-ahead; more are not needed for C. */
283 typedef struct c_parser
GTY(())
285 /* The look-ahead tokens. */
287 /* How many look-ahead tokens are available (0, 1 or 2). */
289 /* True if a syntax error is being recovered from; false otherwise.
290 c_parser_error sets this flag. It should clear this flag when
291 enough tokens have been consumed to recover from the error. */
292 BOOL_BITFIELD error
: 1;
293 /* True if we're processing a pragma, and shouldn't automatically
294 consume CPP_PRAGMA_EOL. */
295 BOOL_BITFIELD in_pragma
: 1;
299 /* The actual parser and external interface. ??? Does this need to be
300 garbage-collected? */
302 static GTY (()) c_parser
*the_parser
;
305 /* Read in and lex a single token, storing it in *TOKEN. */
308 c_lex_one_token (c_token
*token
)
310 timevar_push (TV_LEX
);
312 token
->type
= c_lex_with_flags (&token
->value
, &token
->location
, NULL
);
313 token
->id_kind
= C_ID_NONE
;
314 token
->keyword
= RID_MAX
;
315 token
->pragma_kind
= PRAGMA_NONE
;
316 token
->in_system_header
= in_system_header
;
324 int objc_force_identifier
= objc_need_raw_identifier
;
325 OBJC_NEED_RAW_IDENTIFIER (0);
327 if (C_IS_RESERVED_WORD (token
->value
))
329 enum rid rid_code
= C_RID_CODE (token
->value
);
331 if (c_dialect_objc ())
333 if (!OBJC_IS_AT_KEYWORD (rid_code
)
334 && (!OBJC_IS_PQ_KEYWORD (rid_code
) || objc_pq_context
))
336 /* Return the canonical spelling for this keyword. */
337 token
->value
= ridpointers
[(int) rid_code
];
338 token
->type
= CPP_KEYWORD
;
339 token
->keyword
= rid_code
;
345 /* Return the canonical spelling for this keyword. */
346 token
->value
= ridpointers
[(int) rid_code
];
347 token
->type
= CPP_KEYWORD
;
348 token
->keyword
= rid_code
;
353 decl
= lookup_name (token
->value
);
356 if (TREE_CODE (decl
) == TYPE_DECL
)
358 token
->id_kind
= C_ID_TYPENAME
;
362 else if (c_dialect_objc ())
364 tree objc_interface_decl
= objc_is_class_name (token
->value
);
365 /* Objective-C class names are in the same namespace as
366 variables and typedefs, and hence are shadowed by local
368 if (objc_interface_decl
369 && (global_bindings_p ()
370 || (!objc_force_identifier
&& !decl
)))
372 token
->value
= objc_interface_decl
;
373 token
->id_kind
= C_ID_CLASSNAME
;
377 token
->id_kind
= C_ID_ID
;
381 /* This only happens in Objective-C; it must be a keyword. */
382 token
->type
= CPP_KEYWORD
;
383 token
->keyword
= C_RID_CODE (token
->value
);
387 case CPP_CLOSE_PAREN
:
389 /* These tokens may affect the interpretation of any identifiers
390 following, if doing Objective-C. */
391 OBJC_NEED_RAW_IDENTIFIER (0);
394 /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */
395 token
->pragma_kind
= TREE_INT_CST_LOW (token
->value
);
401 timevar_pop (TV_LEX
);
404 /* Return a pointer to the next token from PARSER, reading it in if
407 static inline c_token
*
408 c_parser_peek_token (c_parser
*parser
)
410 if (parser
->tokens_avail
== 0)
412 c_lex_one_token (&parser
->tokens
[0]);
413 parser
->tokens_avail
= 1;
415 return &parser
->tokens
[0];
418 /* Return true if the next token from PARSER has the indicated
422 c_parser_next_token_is (c_parser
*parser
, enum cpp_ttype type
)
424 return c_parser_peek_token (parser
)->type
== type
;
427 /* Return true if the next token from PARSER does not have the
431 c_parser_next_token_is_not (c_parser
*parser
, enum cpp_ttype type
)
433 return !c_parser_next_token_is (parser
, type
);
436 /* Return true if the next token from PARSER is the indicated
440 c_parser_next_token_is_keyword (c_parser
*parser
, enum rid keyword
)
444 /* Peek at the next token. */
445 token
= c_parser_peek_token (parser
);
446 /* Check to see if it is the indicated keyword. */
447 return token
->keyword
== keyword
;
450 /* Return true if TOKEN can start a type name,
453 c_token_starts_typename (c_token
*token
)
458 switch (token
->id_kind
)
465 gcc_assert (c_dialect_objc ());
471 switch (token
->keyword
)
500 if (c_dialect_objc ())
508 /* Return true if the next token from PARSER can start a type name,
511 c_parser_next_token_starts_typename (c_parser
*parser
)
513 c_token
*token
= c_parser_peek_token (parser
);
514 return c_token_starts_typename (token
);
517 /* Return true if TOKEN can start declaration specifiers, false
520 c_token_starts_declspecs (c_token
*token
)
525 switch (token
->id_kind
)
532 gcc_assert (c_dialect_objc ());
538 switch (token
->keyword
)
574 if (c_dialect_objc ())
582 /* Return true if the next token from PARSER can start declaration
583 specifiers, false otherwise. */
585 c_parser_next_token_starts_declspecs (c_parser
*parser
)
587 c_token
*token
= c_parser_peek_token (parser
);
588 return c_token_starts_declspecs (token
);
591 /* Return a pointer to the next-but-one token from PARSER, reading it
592 in if necessary. The next token is already read in. */
595 c_parser_peek_2nd_token (c_parser
*parser
)
597 if (parser
->tokens_avail
>= 2)
598 return &parser
->tokens
[1];
599 gcc_assert (parser
->tokens_avail
== 1);
600 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
601 gcc_assert (parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
602 c_lex_one_token (&parser
->tokens
[1]);
603 parser
->tokens_avail
= 2;
604 return &parser
->tokens
[1];
607 /* Consume the next token from PARSER. */
610 c_parser_consume_token (c_parser
*parser
)
612 gcc_assert (parser
->tokens_avail
>= 1);
613 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
614 gcc_assert (!parser
->in_pragma
|| parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
615 gcc_assert (parser
->error
|| parser
->tokens
[0].type
!= CPP_PRAGMA
);
616 if (parser
->tokens_avail
== 2)
617 parser
->tokens
[0] = parser
->tokens
[1];
618 parser
->tokens_avail
--;
621 /* Expect the current token to be a #pragma. Consume it and remember
622 that we've begun parsing a pragma. */
625 c_parser_consume_pragma (c_parser
*parser
)
627 gcc_assert (!parser
->in_pragma
);
628 gcc_assert (parser
->tokens_avail
>= 1);
629 gcc_assert (parser
->tokens
[0].type
== CPP_PRAGMA
);
630 if (parser
->tokens_avail
== 2)
631 parser
->tokens
[0] = parser
->tokens
[1];
632 parser
->tokens_avail
--;
633 parser
->in_pragma
= true;
636 /* Update the globals input_location and in_system_header from
639 c_parser_set_source_position_from_token (c_token
*token
)
641 if (token
->type
!= CPP_EOF
)
643 input_location
= token
->location
;
644 in_system_header
= token
->in_system_header
;
648 /* Issue a diagnostic of the form
649 FILE:LINE: MESSAGE before TOKEN
650 where TOKEN is the next token in the input stream of PARSER.
651 MESSAGE (specified by the caller) is usually of the form "expected
654 Do not issue a diagnostic if still recovering from an error.
656 ??? This is taken from the C++ parser, but building up messages in
657 this way is not i18n-friendly and some other approach should be
661 c_parser_error (c_parser
*parser
, const char *gmsgid
)
663 c_token
*token
= c_parser_peek_token (parser
);
666 parser
->error
= true;
669 /* This diagnostic makes more sense if it is tagged to the line of
670 the token we just peeked at. */
671 c_parser_set_source_position_from_token (token
);
672 c_parse_error (gmsgid
,
673 /* Because c_parse_error does not understand
674 CPP_KEYWORD, keywords are treated like
676 (token
->type
== CPP_KEYWORD
? CPP_NAME
: token
->type
),
680 /* If the next token is of the indicated TYPE, consume it. Otherwise,
681 issue the error MSGID. If MSGID is NULL then a message has already
682 been produced and no message will be produced this time. Returns
683 true if found, false otherwise. */
686 c_parser_require (c_parser
*parser
,
690 if (c_parser_next_token_is (parser
, type
))
692 c_parser_consume_token (parser
);
697 c_parser_error (parser
, msgid
);
702 /* If the next token is the indicated keyword, consume it. Otherwise,
703 issue the error MSGID. Returns true if found, false otherwise. */
706 c_parser_require_keyword (c_parser
*parser
,
710 if (c_parser_next_token_is_keyword (parser
, keyword
))
712 c_parser_consume_token (parser
);
717 c_parser_error (parser
, msgid
);
722 /* Like c_parser_require, except that tokens will be skipped until the
723 desired token is found. An error message is still produced if the
724 next token is not as expected. If MSGID is NULL then a message has
725 already been produced and no message will be produced this
729 c_parser_skip_until_found (c_parser
*parser
,
733 unsigned nesting_depth
= 0;
735 if (c_parser_require (parser
, type
, msgid
))
738 /* Skip tokens until the desired token is found. */
741 /* Peek at the next token. */
742 c_token
*token
= c_parser_peek_token (parser
);
743 /* If we've reached the token we want, consume it and stop. */
744 if (token
->type
== type
&& !nesting_depth
)
746 c_parser_consume_token (parser
);
750 /* If we've run out of tokens, stop. */
751 if (token
->type
== CPP_EOF
)
753 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
755 if (token
->type
== CPP_OPEN_BRACE
756 || token
->type
== CPP_OPEN_PAREN
757 || token
->type
== CPP_OPEN_SQUARE
)
759 else if (token
->type
== CPP_CLOSE_BRACE
760 || token
->type
== CPP_CLOSE_PAREN
761 || token
->type
== CPP_CLOSE_SQUARE
)
763 if (nesting_depth
-- == 0)
766 /* Consume this token. */
767 c_parser_consume_token (parser
);
769 parser
->error
= false;
772 /* Skip tokens until the end of a parameter is found, but do not
773 consume the comma, semicolon or closing delimiter. */
776 c_parser_skip_to_end_of_parameter (c_parser
*parser
)
778 unsigned nesting_depth
= 0;
782 c_token
*token
= c_parser_peek_token (parser
);
783 if ((token
->type
== CPP_COMMA
|| token
->type
== CPP_SEMICOLON
)
786 /* If we've run out of tokens, stop. */
787 if (token
->type
== CPP_EOF
)
789 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
791 if (token
->type
== CPP_OPEN_BRACE
792 || token
->type
== CPP_OPEN_PAREN
793 || token
->type
== CPP_OPEN_SQUARE
)
795 else if (token
->type
== CPP_CLOSE_BRACE
796 || token
->type
== CPP_CLOSE_PAREN
797 || token
->type
== CPP_CLOSE_SQUARE
)
799 if (nesting_depth
-- == 0)
802 /* Consume this token. */
803 c_parser_consume_token (parser
);
805 parser
->error
= false;
808 /* Expect to be at the end of the pragma directive and consume an
809 end of line marker. */
812 c_parser_skip_to_pragma_eol (c_parser
*parser
)
814 gcc_assert (parser
->in_pragma
);
815 parser
->in_pragma
= false;
817 if (!c_parser_require (parser
, CPP_PRAGMA_EOL
, "expected end of line"))
820 c_token
*token
= c_parser_peek_token (parser
);
821 if (token
->type
== CPP_EOF
)
823 if (token
->type
== CPP_PRAGMA_EOL
)
825 c_parser_consume_token (parser
);
828 c_parser_consume_token (parser
);
831 parser
->error
= false;
834 /* Skip tokens until we have consumed an entire block, or until we
835 have consumed a non-nested ';'. */
838 c_parser_skip_to_end_of_block_or_statement (c_parser
*parser
)
840 unsigned nesting_depth
= 0;
841 bool save_error
= parser
->error
;
847 /* Peek at the next token. */
848 token
= c_parser_peek_token (parser
);
856 if (parser
->in_pragma
)
861 /* If the next token is a ';', we have reached the
862 end of the statement. */
865 /* Consume the ';'. */
866 c_parser_consume_token (parser
);
871 case CPP_CLOSE_BRACE
:
872 /* If the next token is a non-nested '}', then we have
873 reached the end of the current block. */
874 if (nesting_depth
== 0 || --nesting_depth
== 0)
876 c_parser_consume_token (parser
);
882 /* If it the next token is a '{', then we are entering a new
883 block. Consume the entire block. */
888 /* If we see a pragma, consume the whole thing at once. We
889 have some safeguards against consuming pragmas willy-nilly.
890 Normally, we'd expect to be here with parser->error set,
891 which disables these safeguards. But it's possible to get
892 here for secondary error recovery, after parser->error has
894 c_parser_consume_pragma (parser
);
895 c_parser_skip_to_pragma_eol (parser
);
896 parser
->error
= save_error
;
903 c_parser_consume_token (parser
);
907 parser
->error
= false;
910 /* Save the warning flags which are controlled by __extension__. */
913 disable_extension_diagnostics (void)
916 | (warn_pointer_arith
<< 1)
917 | (warn_traditional
<< 2)
920 warn_pointer_arith
= 0;
921 warn_traditional
= 0;
926 /* Restore the warning flags which are controlled by __extension__.
927 FLAGS is the return value from disable_extension_diagnostics. */
930 restore_extension_diagnostics (int flags
)
932 pedantic
= flags
& 1;
933 warn_pointer_arith
= (flags
>> 1) & 1;
934 warn_traditional
= (flags
>> 2) & 1;
935 flag_iso
= (flags
>> 3) & 1;
938 /* Possibly kinds of declarator to parse. */
939 typedef enum c_dtr_syn
{
940 /* A normal declarator with an identifier. */
942 /* An abstract declarator (maybe empty). */
944 /* A parameter declarator: may be either, but after a type name does
945 not redeclare a typedef name as an identifier if it can
946 alternatively be interpreted as a typedef name; see DR#009,
947 applied in C90 TC1, omitted from C99 and reapplied in C99 TC2
948 following DR#249. For example, given a typedef T, "int T" and
949 "int *T" are valid parameter declarations redeclaring T, while
950 "int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are
951 abstract declarators rather than involving redundant parentheses;
952 the same applies with attributes inside the parentheses before
957 static void c_parser_external_declaration (c_parser
*);
958 static void c_parser_asm_definition (c_parser
*);
959 static void c_parser_declaration_or_fndef (c_parser
*, bool, bool, bool, bool);
960 static void c_parser_declspecs (c_parser
*, struct c_declspecs
*, bool, bool,
962 static struct c_typespec
c_parser_enum_specifier (c_parser
*);
963 static struct c_typespec
c_parser_struct_or_union_specifier (c_parser
*);
964 static tree
c_parser_struct_declaration (c_parser
*);
965 static struct c_typespec
c_parser_typeof_specifier (c_parser
*);
966 static struct c_declarator
*c_parser_declarator (c_parser
*, bool, c_dtr_syn
,
968 static struct c_declarator
*c_parser_direct_declarator (c_parser
*, bool,
970 static struct c_declarator
*c_parser_direct_declarator_inner (c_parser
*,
972 struct c_declarator
*);
973 static struct c_arg_info
*c_parser_parms_declarator (c_parser
*, bool, tree
);
974 static struct c_arg_info
*c_parser_parms_list_declarator (c_parser
*, tree
);
975 static struct c_parm
*c_parser_parameter_declaration (c_parser
*, tree
);
976 static tree
c_parser_simple_asm_expr (c_parser
*);
977 static tree
c_parser_attributes (c_parser
*);
978 static struct c_type_name
*c_parser_type_name (c_parser
*);
979 static struct c_expr
c_parser_initializer (c_parser
*);
980 static struct c_expr
c_parser_braced_init (c_parser
*, tree
, bool);
981 static void c_parser_initelt (c_parser
*);
982 static void c_parser_initval (c_parser
*, struct c_expr
*);
983 static tree
c_parser_compound_statement (c_parser
*);
984 static void c_parser_compound_statement_nostart (c_parser
*);
985 static void c_parser_label (c_parser
*);
986 static void c_parser_statement (c_parser
*);
987 static void c_parser_statement_after_labels (c_parser
*);
988 static void c_parser_if_statement (c_parser
*);
989 static void c_parser_switch_statement (c_parser
*);
990 static void c_parser_while_statement (c_parser
*);
991 static void c_parser_do_statement (c_parser
*);
992 static void c_parser_for_statement (c_parser
*);
993 static tree
c_parser_asm_statement (c_parser
*);
994 static tree
c_parser_asm_operands (c_parser
*, bool);
995 static tree
c_parser_asm_clobbers (c_parser
*);
996 static struct c_expr
c_parser_expr_no_commas (c_parser
*, struct c_expr
*);
997 static struct c_expr
c_parser_conditional_expression (c_parser
*,
999 static struct c_expr
c_parser_binary_expression (c_parser
*, struct c_expr
*);
1000 static struct c_expr
c_parser_cast_expression (c_parser
*, struct c_expr
*);
1001 static struct c_expr
c_parser_unary_expression (c_parser
*);
1002 static struct c_expr
c_parser_sizeof_expression (c_parser
*);
1003 static struct c_expr
c_parser_alignof_expression (c_parser
*);
1004 static struct c_expr
c_parser_postfix_expression (c_parser
*);
1005 static struct c_expr
c_parser_postfix_expression_after_paren_type (c_parser
*,
1006 struct c_type_name
*);
1007 static struct c_expr
c_parser_postfix_expression_after_primary (c_parser
*,
1009 static struct c_expr
c_parser_expression (c_parser
*);
1010 static struct c_expr
c_parser_expression_conv (c_parser
*);
1011 static tree
c_parser_expr_list (c_parser
*, bool);
1012 static void c_parser_omp_construct (c_parser
*);
1013 static void c_parser_omp_threadprivate (c_parser
*);
1014 static void c_parser_omp_barrier (c_parser
*);
1015 static void c_parser_omp_flush (c_parser
*);
1017 enum pragma_context
{ pragma_external
, pragma_stmt
, pragma_compound
};
1018 static bool c_parser_pragma (c_parser
*, enum pragma_context
);
1020 /* These Objective-C parser functions are only ever called when
1021 compiling Objective-C. */
1022 static void c_parser_objc_class_definition (c_parser
*);
1023 static void c_parser_objc_class_instance_variables (c_parser
*);
1024 static void c_parser_objc_class_declaration (c_parser
*);
1025 static void c_parser_objc_alias_declaration (c_parser
*);
1026 static void c_parser_objc_protocol_definition (c_parser
*);
1027 static enum tree_code
c_parser_objc_method_type (c_parser
*);
1028 static void c_parser_objc_method_definition (c_parser
*);
1029 static void c_parser_objc_methodprotolist (c_parser
*);
1030 static void c_parser_objc_methodproto (c_parser
*);
1031 static tree
c_parser_objc_method_decl (c_parser
*);
1032 static tree
c_parser_objc_type_name (c_parser
*);
1033 static tree
c_parser_objc_protocol_refs (c_parser
*);
1034 static void c_parser_objc_try_catch_statement (c_parser
*);
1035 static void c_parser_objc_synchronized_statement (c_parser
*);
1036 static tree
c_parser_objc_selector (c_parser
*);
1037 static tree
c_parser_objc_selector_arg (c_parser
*);
1038 static tree
c_parser_objc_receiver (c_parser
*);
1039 static tree
c_parser_objc_message_args (c_parser
*);
1040 static tree
c_parser_objc_keywordexpr (c_parser
*);
1042 /* Parse a translation unit (C90 6.7, C99 6.9).
1045 external-declarations
1047 external-declarations:
1048 external-declaration
1049 external-declarations external-declaration
1058 c_parser_translation_unit (c_parser
*parser
)
1060 if (c_parser_next_token_is (parser
, CPP_EOF
))
1063 pedwarn ("ISO C forbids an empty source file");
1067 void *obstack_position
= obstack_alloc (&parser_obstack
, 0);
1071 c_parser_external_declaration (parser
);
1072 obstack_free (&parser_obstack
, obstack_position
);
1074 while (c_parser_next_token_is_not (parser
, CPP_EOF
));
1078 /* Parse an external declaration (C90 6.7, C99 6.9).
1080 external-declaration:
1086 external-declaration:
1089 __extension__ external-declaration
1093 external-declaration:
1094 objc-class-definition
1095 objc-class-declaration
1096 objc-alias-declaration
1097 objc-protocol-definition
1098 objc-method-definition
1103 c_parser_external_declaration (c_parser
*parser
)
1106 switch (c_parser_peek_token (parser
)->type
)
1109 switch (c_parser_peek_token (parser
)->keyword
)
1112 ext
= disable_extension_diagnostics ();
1113 c_parser_consume_token (parser
);
1114 c_parser_external_declaration (parser
);
1115 restore_extension_diagnostics (ext
);
1118 c_parser_asm_definition (parser
);
1120 case RID_AT_INTERFACE
:
1121 case RID_AT_IMPLEMENTATION
:
1122 gcc_assert (c_dialect_objc ());
1123 c_parser_objc_class_definition (parser
);
1126 gcc_assert (c_dialect_objc ());
1127 c_parser_objc_class_declaration (parser
);
1130 gcc_assert (c_dialect_objc ());
1131 c_parser_objc_alias_declaration (parser
);
1133 case RID_AT_PROTOCOL
:
1134 gcc_assert (c_dialect_objc ());
1135 c_parser_objc_protocol_definition (parser
);
1138 gcc_assert (c_dialect_objc ());
1139 c_parser_consume_token (parser
);
1140 objc_finish_implementation ();
1148 pedwarn ("ISO C does not allow extra %<;%> outside of a function");
1149 c_parser_consume_token (parser
);
1152 c_parser_pragma (parser
, pragma_external
);
1156 if (c_dialect_objc ())
1158 c_parser_objc_method_definition (parser
);
1161 /* Else fall through, and yield a syntax error trying to parse
1162 as a declaration or function definition. */
1165 /* A declaration or a function definition. We can only tell
1166 which after parsing the declaration specifiers, if any, and
1167 the first declarator. */
1168 c_parser_declaration_or_fndef (parser
, true, true, false, true);
1174 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1175 6.7, 6.9.1). If FNDEF_OK is true, a function definition is
1176 accepted; otherwise (old-style parameter declarations) only other
1177 declarations are accepted. If NESTED is true, we are inside a
1178 function or parsing old-style parameter declarations; any functions
1179 encountered are nested functions and declaration specifiers are
1180 required; otherwise we are at top level and functions are normal
1181 functions and declaration specifiers may be optional. If EMPTY_OK
1182 is true, empty declarations are OK (subject to all other
1183 constraints); otherwise (old-style parameter declarations) they are
1184 diagnosed. If START_ATTR_OK is true, the declaration specifiers
1185 may start with attributes; otherwise they may not.
1188 declaration-specifiers init-declarator-list[opt] ;
1190 function-definition:
1191 declaration-specifiers[opt] declarator declaration-list[opt]
1196 declaration-list declaration
1198 init-declarator-list:
1200 init-declarator-list , init-declarator
1203 declarator simple-asm-expr[opt] attributes[opt]
1204 declarator simple-asm-expr[opt] attributes[opt] = initializer
1208 nested-function-definition:
1209 declaration-specifiers declarator declaration-list[opt]
1212 The simple-asm-expr and attributes are GNU extensions.
1214 This function does not handle __extension__; that is handled in its
1215 callers. ??? Following the old parser, __extension__ may start
1216 external declarations, declarations in functions and declarations
1217 at the start of "for" loops, but not old-style parameter
1220 C99 requires declaration specifiers in a function definition; the
1221 absence is diagnosed through the diagnosis of implicit int. In GNU
1222 C we also allow but diagnose declarations without declaration
1223 specifiers, but only at top level (elsewhere they conflict with
1229 threadprivate-directive */
1232 c_parser_declaration_or_fndef (c_parser
*parser
, bool fndef_ok
, bool empty_ok
,
1233 bool nested
, bool start_attr_ok
)
1235 struct c_declspecs
*specs
;
1237 tree all_prefix_attrs
;
1238 bool diagnosed_no_specs
= false;
1240 specs
= build_null_declspecs ();
1241 c_parser_declspecs (parser
, specs
, true, true, start_attr_ok
);
1244 c_parser_skip_to_end_of_block_or_statement (parser
);
1247 if (nested
&& !specs
->declspecs_seen_p
)
1249 c_parser_error (parser
, "expected declaration specifiers");
1250 c_parser_skip_to_end_of_block_or_statement (parser
);
1253 finish_declspecs (specs
);
1254 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1260 shadow_tag_warned (specs
, 1);
1261 pedwarn ("empty declaration");
1263 c_parser_consume_token (parser
);
1266 pending_xref_error ();
1267 prefix_attrs
= specs
->attrs
;
1268 all_prefix_attrs
= prefix_attrs
;
1269 specs
->attrs
= NULL_TREE
;
1272 struct c_declarator
*declarator
;
1275 /* Declaring either one or more declarators (in which case we
1276 should diagnose if there were no declaration specifiers) or a
1277 function definition (in which case the diagnostic for
1278 implicit int suffices). */
1279 declarator
= c_parser_declarator (parser
, specs
->type_seen_p
,
1280 C_DTR_NORMAL
, &dummy
);
1281 if (declarator
== NULL
)
1283 c_parser_skip_to_end_of_block_or_statement (parser
);
1286 if (c_parser_next_token_is (parser
, CPP_EQ
)
1287 || c_parser_next_token_is (parser
, CPP_COMMA
)
1288 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
1289 || c_parser_next_token_is_keyword (parser
, RID_ASM
)
1290 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1292 tree asm_name
= NULL_TREE
;
1293 tree postfix_attrs
= NULL_TREE
;
1294 if (!diagnosed_no_specs
&& !specs
->declspecs_seen_p
)
1296 diagnosed_no_specs
= true;
1297 pedwarn ("data definition has no type or storage class");
1299 /* Having seen a data definition, there cannot now be a
1300 function definition. */
1302 if (c_parser_next_token_is_keyword (parser
, RID_ASM
))
1303 asm_name
= c_parser_simple_asm_expr (parser
);
1304 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1305 postfix_attrs
= c_parser_attributes (parser
);
1306 if (c_parser_next_token_is (parser
, CPP_EQ
))
1310 c_parser_consume_token (parser
);
1311 /* The declaration of the variable is in effect while
1312 its initializer is parsed. */
1313 d
= start_decl (declarator
, specs
, true,
1314 chainon (postfix_attrs
, all_prefix_attrs
));
1316 d
= error_mark_node
;
1317 start_init (d
, asm_name
, global_bindings_p ());
1318 init
= c_parser_initializer (parser
);
1320 if (d
!= error_mark_node
)
1322 maybe_warn_string_init (TREE_TYPE (d
), init
);
1323 finish_decl (d
, init
.value
, asm_name
);
1328 tree d
= start_decl (declarator
, specs
, false,
1329 chainon (postfix_attrs
,
1332 finish_decl (d
, NULL_TREE
, asm_name
);
1334 if (c_parser_next_token_is (parser
, CPP_COMMA
))
1336 c_parser_consume_token (parser
);
1337 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1338 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
1341 all_prefix_attrs
= prefix_attrs
;
1344 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1346 c_parser_consume_token (parser
);
1351 c_parser_error (parser
, "expected %<,%> or %<;%>");
1352 c_parser_skip_to_end_of_block_or_statement (parser
);
1358 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, "
1359 "%<asm%> or %<__attribute__%>");
1360 c_parser_skip_to_end_of_block_or_statement (parser
);
1363 /* Function definition (nested or otherwise). */
1367 pedwarn ("ISO C forbids nested functions");
1368 push_function_context ();
1370 if (!start_function (specs
, declarator
, all_prefix_attrs
))
1372 /* This can appear in many cases looking nothing like a
1373 function definition, so we don't give a more specific
1374 error suggesting there was one. */
1375 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
1376 "or %<__attribute__%>");
1378 pop_function_context ();
1381 /* Parse old-style parameter declarations. ??? Attributes are
1382 not allowed to start declaration specifiers here because of a
1383 syntax conflict between a function declaration with attribute
1384 suffix and a function definition with an attribute prefix on
1385 first old-style parameter declaration. Following the old
1386 parser, they are not accepted on subsequent old-style
1387 parameter declarations either. However, there is no
1388 ambiguity after the first declaration, nor indeed on the
1389 first as long as we don't allow postfix attributes after a
1390 declarator with a nonempty identifier list in a definition;
1391 and postfix attributes have never been accepted here in
1392 function definitions either. */
1393 while (c_parser_next_token_is_not (parser
, CPP_EOF
)
1394 && c_parser_next_token_is_not (parser
, CPP_OPEN_BRACE
))
1395 c_parser_declaration_or_fndef (parser
, false, false, true, false);
1396 DECL_SOURCE_LOCATION (current_function_decl
)
1397 = c_parser_peek_token (parser
)->location
;
1398 store_parm_decls ();
1399 fnbody
= c_parser_compound_statement (parser
);
1402 tree decl
= current_function_decl
;
1405 pop_function_context ();
1406 add_stmt (build_stmt (DECL_EXPR
, decl
));
1417 /* Parse an asm-definition (asm() outside a function body). This is a
1425 c_parser_asm_definition (c_parser
*parser
)
1427 tree asm_str
= c_parser_simple_asm_expr (parser
);
1429 cgraph_add_asm_node (asm_str
);
1430 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
1433 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
1434 6.7), adding them to SPECS (which may already include some).
1435 Storage class specifiers are accepted iff SCSPEC_OK; type
1436 specifiers are accepted iff TYPESPEC_OK; attributes are accepted at
1437 the start iff START_ATTR_OK.
1439 declaration-specifiers:
1440 storage-class-specifier declaration-specifiers[opt]
1441 type-specifier declaration-specifiers[opt]
1442 type-qualifier declaration-specifiers[opt]
1443 function-specifier declaration-specifiers[opt]
1445 Function specifiers (inline) are from C99, and are currently
1446 handled as storage class specifiers, as is __thread.
1448 C90 6.5.1, C99 6.7.1:
1449 storage-class-specifier:
1460 C90 6.5.2, C99 6.7.2:
1473 [_Imaginary removed in C99 TC2]
1474 struct-or-union-specifier
1478 (_Bool and _Complex are new in C99.)
1480 C90 6.5.3, C99 6.7.3:
1487 (restrict is new in C99.)
1491 declaration-specifiers:
1492 attributes declaration-specifiers[opt]
1494 storage-class-specifier:
1506 class-name objc-protocol-refs[opt]
1507 typedef-name objc-protocol-refs
1512 c_parser_declspecs (c_parser
*parser
, struct c_declspecs
*specs
,
1513 bool scspec_ok
, bool typespec_ok
, bool start_attr_ok
)
1515 bool attrs_ok
= start_attr_ok
;
1516 bool seen_type
= specs
->type_seen_p
;
1517 while (c_parser_next_token_is (parser
, CPP_NAME
)
1518 || c_parser_next_token_is (parser
, CPP_KEYWORD
)
1519 || (c_dialect_objc () && c_parser_next_token_is (parser
, CPP_LESS
)))
1521 struct c_typespec t
;
1523 if (c_parser_next_token_is (parser
, CPP_NAME
))
1525 tree value
= c_parser_peek_token (parser
)->value
;
1526 c_id_kind kind
= c_parser_peek_token (parser
)->id_kind
;
1527 /* This finishes the specifiers unless a type name is OK, it
1528 is declared as a type name and a type name hasn't yet
1530 if (!typespec_ok
|| seen_type
1531 || (kind
!= C_ID_TYPENAME
&& kind
!= C_ID_CLASSNAME
))
1533 c_parser_consume_token (parser
);
1536 if (kind
== C_ID_TYPENAME
1537 && (!c_dialect_objc ()
1538 || c_parser_next_token_is_not (parser
, CPP_LESS
)))
1540 t
.kind
= ctsk_typedef
;
1541 /* For a typedef name, record the meaning, not the name.
1542 In case of 'foo foo, bar;'. */
1543 t
.spec
= lookup_name (value
);
1547 tree proto
= NULL_TREE
;
1548 gcc_assert (c_dialect_objc ());
1550 if (c_parser_next_token_is (parser
, CPP_LESS
))
1551 proto
= c_parser_objc_protocol_refs (parser
);
1552 t
.spec
= objc_get_protocol_qualified_type (value
, proto
);
1554 declspecs_add_type (specs
, t
);
1557 if (c_parser_next_token_is (parser
, CPP_LESS
))
1559 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
1560 nisse@lysator.liu.se. */
1562 gcc_assert (c_dialect_objc ());
1563 if (!typespec_ok
|| seen_type
)
1565 proto
= c_parser_objc_protocol_refs (parser
);
1567 t
.spec
= objc_get_protocol_qualified_type (NULL_TREE
, proto
);
1568 declspecs_add_type (specs
, t
);
1571 gcc_assert (c_parser_next_token_is (parser
, CPP_KEYWORD
));
1572 switch (c_parser_peek_token (parser
)->keyword
)
1584 /* TODO: Distinguish between function specifiers (inline)
1585 and storage class specifiers, either here or in
1586 declspecs_add_scspec. */
1587 declspecs_add_scspec (specs
, c_parser_peek_token (parser
)->value
);
1588 c_parser_consume_token (parser
);
1608 OBJC_NEED_RAW_IDENTIFIER (1);
1609 t
.kind
= ctsk_resword
;
1610 t
.spec
= c_parser_peek_token (parser
)->value
;
1611 declspecs_add_type (specs
, t
);
1612 c_parser_consume_token (parser
);
1619 t
= c_parser_enum_specifier (parser
);
1620 declspecs_add_type (specs
, t
);
1628 t
= c_parser_struct_or_union_specifier (parser
);
1629 declspecs_add_type (specs
, t
);
1632 /* ??? The old parser rejected typeof after other type
1633 specifiers, but is a syntax error the best way of
1635 if (!typespec_ok
|| seen_type
)
1639 t
= c_parser_typeof_specifier (parser
);
1640 declspecs_add_type (specs
, t
);
1646 declspecs_add_qual (specs
, c_parser_peek_token (parser
)->value
);
1647 c_parser_consume_token (parser
);
1652 attrs
= c_parser_attributes (parser
);
1653 declspecs_add_attrs (specs
, attrs
);
1662 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
1665 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
1666 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
1667 enum attributes[opt] identifier
1669 The form with trailing comma is new in C99. The forms with
1670 attributes are GNU extensions. In GNU C, we accept any expression
1671 without commas in the syntax (assignment expressions, not just
1672 conditional expressions); assignment expressions will be diagnosed
1677 enumerator-list , enumerator
1680 enumeration-constant
1681 enumeration-constant = constant-expression
1684 static struct c_typespec
1685 c_parser_enum_specifier (c_parser
*parser
)
1687 struct c_typespec ret
;
1689 tree ident
= NULL_TREE
;
1690 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ENUM
));
1691 c_parser_consume_token (parser
);
1692 attrs
= c_parser_attributes (parser
);
1693 if (c_parser_next_token_is (parser
, CPP_NAME
))
1695 ident
= c_parser_peek_token (parser
)->value
;
1696 c_parser_consume_token (parser
);
1698 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
1700 /* Parse an enum definition. */
1701 tree type
= start_enum (ident
);
1703 /* We chain the enumerators in reverse order, then put them in
1704 forward order at the end. */
1705 tree values
= NULL_TREE
;
1706 c_parser_consume_token (parser
);
1713 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
1715 c_parser_error (parser
, "expected identifier");
1716 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
1717 values
= error_mark_node
;
1720 enum_id
= c_parser_peek_token (parser
)->value
;
1721 c_parser_consume_token (parser
);
1722 if (c_parser_next_token_is (parser
, CPP_EQ
))
1724 c_parser_consume_token (parser
);
1725 enum_value
= c_parser_expr_no_commas (parser
, NULL
).value
;
1728 enum_value
= NULL_TREE
;
1729 enum_decl
= build_enumerator (enum_id
, enum_value
);
1730 TREE_CHAIN (enum_decl
) = values
;
1733 if (c_parser_next_token_is (parser
, CPP_COMMA
))
1736 c_parser_consume_token (parser
);
1738 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
1740 if (seen_comma
&& pedantic
&& !flag_isoc99
)
1741 pedwarn ("comma at end of enumerator list");
1742 c_parser_consume_token (parser
);
1747 c_parser_error (parser
, "expected %<,%> or %<}%>");
1748 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
1749 values
= error_mark_node
;
1753 postfix_attrs
= c_parser_attributes (parser
);
1754 ret
.spec
= finish_enum (type
, nreverse (values
),
1755 chainon (attrs
, postfix_attrs
));
1756 ret
.kind
= ctsk_tagdef
;
1761 c_parser_error (parser
, "expected %<{%>");
1762 ret
.spec
= error_mark_node
;
1763 ret
.kind
= ctsk_tagref
;
1766 ret
= parser_xref_tag (ENUMERAL_TYPE
, ident
);
1767 /* In ISO C, enumerated types can be referred to only if already
1769 if (pedantic
&& !COMPLETE_TYPE_P (ret
.spec
))
1770 pedwarn ("ISO C forbids forward references to %<enum%> types");
1774 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
1776 struct-or-union-specifier:
1777 struct-or-union attributes[opt] identifier[opt]
1778 { struct-contents } attributes[opt]
1779 struct-or-union attributes[opt] identifier
1782 struct-declaration-list
1784 struct-declaration-list:
1785 struct-declaration ;
1786 struct-declaration-list struct-declaration ;
1793 struct-declaration-list struct-declaration
1795 struct-declaration-list:
1796 struct-declaration-list ;
1799 (Note that in the syntax here, unlike that in ISO C, the semicolons
1800 are included here rather than in struct-declaration, in order to
1801 describe the syntax with extra semicolons and missing semicolon at
1806 struct-declaration-list:
1807 @defs ( class-name )
1809 (Note this does not include a trailing semicolon, but can be
1810 followed by further declarations, and gets a pedwarn-if-pedantic
1811 when followed by a semicolon.) */
1813 static struct c_typespec
1814 c_parser_struct_or_union_specifier (c_parser
*parser
)
1816 struct c_typespec ret
;
1818 tree ident
= NULL_TREE
;
1819 enum tree_code code
;
1820 switch (c_parser_peek_token (parser
)->keyword
)
1831 c_parser_consume_token (parser
);
1832 attrs
= c_parser_attributes (parser
);
1833 if (c_parser_next_token_is (parser
, CPP_NAME
))
1835 ident
= c_parser_peek_token (parser
)->value
;
1836 c_parser_consume_token (parser
);
1838 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
1840 /* Parse a struct or union definition. Start the scope of the
1841 tag before parsing components. */
1842 tree type
= start_struct (code
, ident
);
1844 /* We chain the components in reverse order, then put them in
1845 forward order at the end. Each struct-declaration may
1846 declare multiple components (comma-separated), so we must use
1847 chainon to join them, although when parsing each
1848 struct-declaration we can use TREE_CHAIN directly.
1850 The theory behind all this is that there will be more
1851 semicolon separated fields than comma separated fields, and
1852 so we'll be minimizing the number of node traversals required
1854 tree contents
= NULL_TREE
;
1855 c_parser_consume_token (parser
);
1856 /* Handle the Objective-C @defs construct,
1857 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
1858 if (c_parser_next_token_is_keyword (parser
, RID_AT_DEFS
))
1861 gcc_assert (c_dialect_objc ());
1862 c_parser_consume_token (parser
);
1863 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
1865 if (c_parser_next_token_is (parser
, CPP_NAME
)
1866 && c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
)
1868 name
= c_parser_peek_token (parser
)->value
;
1869 c_parser_consume_token (parser
);
1873 c_parser_error (parser
, "expected class name");
1874 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
1877 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
1879 contents
= nreverse (objc_get_class_ivars (name
));
1882 /* Parse the struct-declarations and semicolons. Problems with
1883 semicolons are diagnosed here; empty structures are diagnosed
1888 /* Parse any stray semicolon. */
1889 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1892 pedwarn ("extra semicolon in struct or union specified");
1893 c_parser_consume_token (parser
);
1896 /* Stop if at the end of the struct or union contents. */
1897 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
1899 c_parser_consume_token (parser
);
1902 /* Accept #pragmas at struct scope. */
1903 if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
1905 c_parser_pragma (parser
, pragma_external
);
1908 /* Parse some comma-separated declarations, but not the
1909 trailing semicolon if any. */
1910 decls
= c_parser_struct_declaration (parser
);
1911 contents
= chainon (decls
, contents
);
1912 /* If no semicolon follows, either we have a parse error or
1913 are at the end of the struct or union and should
1915 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1916 c_parser_consume_token (parser
);
1919 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
1920 pedwarn ("no semicolon at end of struct or union");
1923 c_parser_error (parser
, "expected %<;%>");
1924 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
1929 postfix_attrs
= c_parser_attributes (parser
);
1930 ret
.spec
= finish_struct (type
, nreverse (contents
),
1931 chainon (attrs
, postfix_attrs
));
1932 ret
.kind
= ctsk_tagdef
;
1937 c_parser_error (parser
, "expected %<{%>");
1938 ret
.spec
= error_mark_node
;
1939 ret
.kind
= ctsk_tagref
;
1942 ret
= parser_xref_tag (code
, ident
);
1946 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
1947 the trailing semicolon.
1950 specifier-qualifier-list struct-declarator-list
1952 specifier-qualifier-list:
1953 type-specifier specifier-qualifier-list[opt]
1954 type-qualifier specifier-qualifier-list[opt]
1955 attributes specifier-qualifier-list[opt]
1957 struct-declarator-list:
1959 struct-declarator-list , attributes[opt] struct-declarator
1962 declarator attributes[opt]
1963 declarator[opt] : constant-expression attributes[opt]
1968 __extension__ struct-declaration
1969 specifier-qualifier-list
1971 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
1972 of attributes where shown is a GNU extension. In GNU C, we accept
1973 any expression without commas in the syntax (assignment
1974 expressions, not just conditional expressions); assignment
1975 expressions will be diagnosed as non-constant. */
1978 c_parser_struct_declaration (c_parser
*parser
)
1980 struct c_declspecs
*specs
;
1982 tree all_prefix_attrs
;
1984 if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
1988 ext
= disable_extension_diagnostics ();
1989 c_parser_consume_token (parser
);
1990 decl
= c_parser_struct_declaration (parser
);
1991 restore_extension_diagnostics (ext
);
1994 specs
= build_null_declspecs ();
1995 c_parser_declspecs (parser
, specs
, false, true, true);
1998 if (!specs
->declspecs_seen_p
)
2000 c_parser_error (parser
, "expected specifier-qualifier-list");
2003 finish_declspecs (specs
);
2004 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2007 if (!specs
->type_seen_p
)
2010 pedwarn ("ISO C forbids member declarations with no members");
2011 shadow_tag_warned (specs
, pedantic
);
2016 /* Support for unnamed structs or unions as members of
2017 structs or unions (which is [a] useful and [b] supports
2019 ret
= grokfield (build_id_declarator (NULL_TREE
), specs
, NULL_TREE
);
2023 pending_xref_error ();
2024 prefix_attrs
= specs
->attrs
;
2025 all_prefix_attrs
= prefix_attrs
;
2026 specs
->attrs
= NULL_TREE
;
2030 /* Declaring one or more declarators or un-named bit-fields. */
2031 struct c_declarator
*declarator
;
2033 if (c_parser_next_token_is (parser
, CPP_COLON
))
2034 declarator
= build_id_declarator (NULL_TREE
);
2036 declarator
= c_parser_declarator (parser
, specs
->type_seen_p
,
2037 C_DTR_NORMAL
, &dummy
);
2038 if (declarator
== NULL
)
2040 c_parser_skip_to_end_of_block_or_statement (parser
);
2043 if (c_parser_next_token_is (parser
, CPP_COLON
)
2044 || c_parser_next_token_is (parser
, CPP_COMMA
)
2045 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2046 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
)
2047 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2049 tree postfix_attrs
= NULL_TREE
;
2050 tree width
= NULL_TREE
;
2052 if (c_parser_next_token_is (parser
, CPP_COLON
))
2054 c_parser_consume_token (parser
);
2055 width
= c_parser_expr_no_commas (parser
, NULL
).value
;
2057 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2058 postfix_attrs
= c_parser_attributes (parser
);
2059 d
= grokfield (declarator
, specs
, width
);
2060 decl_attributes (&d
, chainon (postfix_attrs
,
2061 all_prefix_attrs
), 0);
2062 TREE_CHAIN (d
) = decls
;
2064 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2065 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
2068 all_prefix_attrs
= prefix_attrs
;
2069 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2070 c_parser_consume_token (parser
);
2071 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2072 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2074 /* Semicolon consumed in caller. */
2079 c_parser_error (parser
, "expected %<,%>, %<;%> or %<}%>");
2085 c_parser_error (parser
,
2086 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
2087 "%<__attribute__%>");
2094 /* Parse a typeof specifier (a GNU extension).
2097 typeof ( expression )
2098 typeof ( type-name )
2101 static struct c_typespec
2102 c_parser_typeof_specifier (c_parser
*parser
)
2104 struct c_typespec ret
;
2105 ret
.kind
= ctsk_typeof
;
2106 ret
.spec
= error_mark_node
;
2107 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TYPEOF
));
2108 c_parser_consume_token (parser
);
2111 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2117 if (c_parser_next_token_starts_typename (parser
))
2119 struct c_type_name
*type
= c_parser_type_name (parser
);
2124 ret
.spec
= groktypename (type
);
2125 pop_maybe_used (variably_modified_type_p (ret
.spec
, NULL_TREE
));
2131 struct c_expr expr
= c_parser_expression (parser
);
2134 if (TREE_CODE (expr
.value
) == COMPONENT_REF
2135 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
2136 error ("%<typeof%> applied to a bit-field");
2137 ret
.spec
= TREE_TYPE (expr
.value
);
2138 was_vm
= variably_modified_type_p (ret
.spec
, NULL_TREE
);
2139 /* This should be returned with the type so that when the type
2140 is evaluated, this can be evaluated. For now, we avoid
2141 evaluation when the context might. */
2142 if (!skip_evaluation
&& was_vm
)
2144 tree e
= expr
.value
;
2146 /* If the expression is not of a type to which we cannot assign a line
2147 number, wrap the thing in a no-op NOP_EXPR. */
2148 if (DECL_P (e
) || CONSTANT_CLASS_P (e
))
2149 e
= build1 (NOP_EXPR
, void_type_node
, e
);
2151 if (CAN_HAVE_LOCATION_P (e
))
2152 SET_EXPR_LOCATION (e
, input_location
);
2156 pop_maybe_used (was_vm
);
2158 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
2162 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
2163 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
2164 be redeclared; otherwise it may not. KIND indicates which kind of
2165 declarator is wanted. Returns a valid declarator except in the
2166 case of a syntax error in which case NULL is returned. *SEEN_ID is
2167 set to true if an identifier being declared is seen; this is used
2168 to diagnose bad forms of abstract array declarators and to
2169 determine whether an identifier list is syntactically permitted.
2172 pointer[opt] direct-declarator
2176 ( attributes[opt] declarator )
2177 direct-declarator array-declarator
2178 direct-declarator ( parameter-type-list )
2179 direct-declarator ( identifier-list[opt] )
2182 * type-qualifier-list[opt]
2183 * type-qualifier-list[opt] pointer
2185 type-qualifier-list:
2188 type-qualifier-list type-qualifier
2189 type-qualifier-list attributes
2191 parameter-type-list:
2193 parameter-list , ...
2196 parameter-declaration
2197 parameter-list , parameter-declaration
2199 parameter-declaration:
2200 declaration-specifiers declarator attributes[opt]
2201 declaration-specifiers abstract-declarator[opt] attributes[opt]
2205 identifier-list , identifier
2207 abstract-declarator:
2209 pointer[opt] direct-abstract-declarator
2211 direct-abstract-declarator:
2212 ( attributes[opt] abstract-declarator )
2213 direct-abstract-declarator[opt] array-declarator
2214 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
2219 direct-declarator ( parameter-forward-declarations
2220 parameter-type-list[opt] )
2222 direct-abstract-declarator:
2223 direct-abstract-declarator[opt] ( parameter-forward-declarations
2224 parameter-type-list[opt] )
2226 parameter-forward-declarations:
2228 parameter-forward-declarations parameter-list ;
2230 The uses of attributes shown above are GNU extensions.
2232 Some forms of array declarator are not included in C99 in the
2233 syntax for abstract declarators; these are disallowed elsewhere.
2234 This may be a defect (DR#289).
2236 This function also accepts an omitted abstract declarator as being
2237 an abstract declarator, although not part of the formal syntax. */
2239 static struct c_declarator
*
2240 c_parser_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
2243 /* Parse any initial pointer part. */
2244 if (c_parser_next_token_is (parser
, CPP_MULT
))
2246 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
2247 struct c_declarator
*inner
;
2248 c_parser_consume_token (parser
);
2249 c_parser_declspecs (parser
, quals_attrs
, false, false, true);
2250 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
2254 return make_pointer_declarator (quals_attrs
, inner
);
2256 /* Now we have a direct declarator, direct abstract declarator or
2257 nothing (which counts as a direct abstract declarator here). */
2258 return c_parser_direct_declarator (parser
, type_seen_p
, kind
, seen_id
);
2261 /* Parse a direct declarator or direct abstract declarator; arguments
2262 as c_parser_declarator. */
2264 static struct c_declarator
*
2265 c_parser_direct_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
2268 /* The direct declarator must start with an identifier (possibly
2269 omitted) or a parenthesized declarator (possibly abstract). In
2270 an ordinary declarator, initial parentheses must start a
2271 parenthesized declarator. In an abstract declarator or parameter
2272 declarator, they could start a parenthesized declarator or a
2273 parameter list. To tell which, the open parenthesis and any
2274 following attributes must be read. If a declaration specifier
2275 follows, then it is a parameter list; if the specifier is a
2276 typedef name, there might be an ambiguity about redeclaring it,
2277 which is resolved in the direction of treating it as a typedef
2278 name. If a close parenthesis follows, it is also an empty
2279 parameter list, as the syntax does not permit empty abstract
2280 declarators. Otherwise, it is a parenthesized declarator (in
2281 which case the analysis may be repeated inside it, recursively).
2283 ??? There is an ambiguity in a parameter declaration "int
2284 (__attribute__((foo)) x)", where x is not a typedef name: it
2285 could be an abstract declarator for a function, or declare x with
2286 parentheses. The proper resolution of this ambiguity needs
2287 documenting. At present we follow an accident of the old
2288 parser's implementation, whereby the first parameter must have
2289 some declaration specifiers other than just attributes. Thus as
2290 a parameter declaration it is treated as a parenthesized
2291 parameter named x, and as an abstract declarator it is
2294 ??? Also following the old parser, attributes inside an empty
2295 parameter list are ignored, making it a list not yielding a
2296 prototype, rather than giving an error or making it have one
2297 parameter with implicit type int.
2299 ??? Also following the old parser, typedef names may be
2300 redeclared in declarators, but not Objective-C class names. */
2302 if (kind
!= C_DTR_ABSTRACT
2303 && c_parser_next_token_is (parser
, CPP_NAME
)
2305 && c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
)
2306 || c_parser_peek_token (parser
)->id_kind
== C_ID_ID
))
2308 struct c_declarator
*inner
2309 = build_id_declarator (c_parser_peek_token (parser
)->value
);
2311 inner
->id_loc
= c_parser_peek_token (parser
)->location
;
2312 c_parser_consume_token (parser
);
2313 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
2316 if (kind
!= C_DTR_NORMAL
2317 && c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
2319 struct c_declarator
*inner
= build_id_declarator (NULL_TREE
);
2320 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
2323 /* Either we are at the end of an abstract declarator, or we have
2326 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
2329 struct c_declarator
*inner
;
2330 c_parser_consume_token (parser
);
2331 attrs
= c_parser_attributes (parser
);
2332 if (kind
!= C_DTR_NORMAL
2333 && (c_parser_next_token_starts_declspecs (parser
)
2334 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
)))
2336 struct c_arg_info
*args
2337 = c_parser_parms_declarator (parser
, kind
== C_DTR_NORMAL
,
2344 = build_function_declarator (args
,
2345 build_id_declarator (NULL_TREE
));
2346 return c_parser_direct_declarator_inner (parser
, *seen_id
,
2350 /* A parenthesized declarator. */
2351 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
2352 if (inner
!= NULL
&& attrs
!= NULL
)
2353 inner
= build_attrs_declarator (attrs
, inner
);
2354 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2356 c_parser_consume_token (parser
);
2360 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
2364 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2371 if (kind
== C_DTR_NORMAL
)
2373 c_parser_error (parser
, "expected identifier or %<(%>");
2377 return build_id_declarator (NULL_TREE
);
2381 /* Parse part of a direct declarator or direct abstract declarator,
2382 given that some (in INNER) has already been parsed; ID_PRESENT is
2383 true if an identifier is present, false for an abstract
2386 static struct c_declarator
*
2387 c_parser_direct_declarator_inner (c_parser
*parser
, bool id_present
,
2388 struct c_declarator
*inner
)
2390 /* Parse a sequence of array declarators and parameter lists. */
2391 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
2393 struct c_declarator
*declarator
;
2394 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
2398 c_parser_consume_token (parser
);
2399 c_parser_declspecs (parser
, quals_attrs
, false, false, true);
2400 static_seen
= c_parser_next_token_is_keyword (parser
, RID_STATIC
);
2402 c_parser_consume_token (parser
);
2403 if (static_seen
&& !quals_attrs
->declspecs_seen_p
)
2404 c_parser_declspecs (parser
, quals_attrs
, false, false, true);
2405 if (!quals_attrs
->declspecs_seen_p
)
2407 /* If "static" is present, there must be an array dimension.
2408 Otherwise, there may be a dimension, "*", or no
2413 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
2417 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
2422 else if (c_parser_next_token_is (parser
, CPP_MULT
))
2424 if (c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_SQUARE
)
2428 c_parser_consume_token (parser
);
2433 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
2439 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
2442 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
2443 c_parser_consume_token (parser
);
2446 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
2450 declarator
= build_array_declarator (dimen
, quals_attrs
, static_seen
,
2452 if (declarator
== NULL
)
2454 inner
= set_array_declarator_inner (declarator
, inner
, !id_present
);
2455 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
2457 else if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
2460 struct c_arg_info
*args
;
2461 c_parser_consume_token (parser
);
2462 attrs
= c_parser_attributes (parser
);
2463 args
= c_parser_parms_declarator (parser
, id_present
, attrs
);
2468 inner
= build_function_declarator (args
, inner
);
2469 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
2475 /* Parse a parameter list or identifier list, including the closing
2476 parenthesis but not the opening one. ATTRS are the attributes at
2477 the start of the list. ID_LIST_OK is true if an identifier list is
2478 acceptable; such a list must not have attributes at the start. */
2480 static struct c_arg_info
*
2481 c_parser_parms_declarator (c_parser
*parser
, bool id_list_ok
, tree attrs
)
2484 declare_parm_level ();
2485 /* If the list starts with an identifier, it is an identifier list.
2486 Otherwise, it is either a prototype list or an empty list. */
2489 && c_parser_next_token_is (parser
, CPP_NAME
)
2490 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
2492 tree list
= NULL_TREE
, *nextp
= &list
;
2493 while (c_parser_next_token_is (parser
, CPP_NAME
)
2494 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
2496 *nextp
= build_tree_list (NULL_TREE
,
2497 c_parser_peek_token (parser
)->value
);
2498 nextp
= & TREE_CHAIN (*nextp
);
2499 c_parser_consume_token (parser
);
2500 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
2502 c_parser_consume_token (parser
);
2503 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2505 c_parser_error (parser
, "expected identifier");
2509 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2511 struct c_arg_info
*ret
= XOBNEW (&parser_obstack
, struct c_arg_info
);
2516 ret
->pending_sizes
= 0;
2517 ret
->had_vla_unspec
= 0;
2518 c_parser_consume_token (parser
);
2524 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2532 struct c_arg_info
*ret
= c_parser_parms_list_declarator (parser
, attrs
);
2538 /* Parse a parameter list (possibly empty), including the closing
2539 parenthesis but not the opening one. ATTRS are the attributes at
2540 the start of the list. */
2542 static struct c_arg_info
*
2543 c_parser_parms_list_declarator (c_parser
*parser
, tree attrs
)
2545 bool good_parm
= false;
2546 /* ??? Following the old parser, forward parameter declarations may
2547 use abstract declarators, and if no real parameter declarations
2548 follow the forward declarations then this is not diagnosed. Also
2549 note as above that attributes are ignored as the only contents of
2550 the parentheses, or as the only contents after forward
2552 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2554 struct c_arg_info
*ret
= XOBNEW (&parser_obstack
, struct c_arg_info
);
2559 ret
->pending_sizes
= 0;
2560 ret
->had_vla_unspec
= 0;
2561 c_parser_consume_token (parser
);
2564 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
2566 struct c_arg_info
*ret
= XOBNEW (&parser_obstack
, struct c_arg_info
);
2570 ret
->pending_sizes
= 0;
2571 ret
->had_vla_unspec
= 0;
2572 /* Suppress -Wold-style-definition for this case. */
2573 ret
->types
= error_mark_node
;
2574 error ("ISO C requires a named argument before %<...%>");
2575 c_parser_consume_token (parser
);
2576 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2578 c_parser_consume_token (parser
);
2583 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2588 /* Nonempty list of parameters, either terminated with semicolon
2589 (forward declarations; recurse) or with close parenthesis (normal
2590 function) or with ", ... )" (variadic function). */
2593 /* Parse a parameter. */
2594 struct c_parm
*parm
= c_parser_parameter_declaration (parser
, attrs
);
2599 push_parm_decl (parm
);
2601 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2604 c_parser_consume_token (parser
);
2605 mark_forward_parm_decls ();
2606 new_attrs
= c_parser_attributes (parser
);
2607 return c_parser_parms_list_declarator (parser
, new_attrs
);
2609 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2611 c_parser_consume_token (parser
);
2613 return get_parm_info (false);
2616 struct c_arg_info
*ret
2617 = XOBNEW (&parser_obstack
, struct c_arg_info
);
2622 ret
->pending_sizes
= 0;
2623 ret
->had_vla_unspec
= 0;
2627 if (!c_parser_require (parser
, CPP_COMMA
,
2628 "expected %<;%>, %<,%> or %<)%>"))
2630 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2633 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
2635 c_parser_consume_token (parser
);
2636 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2638 c_parser_consume_token (parser
);
2640 return get_parm_info (true);
2643 struct c_arg_info
*ret
2644 = XOBNEW (&parser_obstack
, struct c_arg_info
);
2649 ret
->pending_sizes
= 0;
2650 ret
->had_vla_unspec
= 0;
2656 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2664 /* Parse a parameter declaration. ATTRS are the attributes at the
2665 start of the declaration if it is the first parameter. */
2667 static struct c_parm
*
2668 c_parser_parameter_declaration (c_parser
*parser
, tree attrs
)
2670 struct c_declspecs
*specs
;
2671 struct c_declarator
*declarator
;
2673 tree postfix_attrs
= NULL_TREE
;
2675 if (!c_parser_next_token_starts_declspecs (parser
))
2677 /* ??? In some Objective-C cases '...' isn't applicable so there
2678 should be a different message. */
2679 c_parser_error (parser
,
2680 "expected declaration specifiers or %<...%>");
2681 c_parser_skip_to_end_of_parameter (parser
);
2684 specs
= build_null_declspecs ();
2687 declspecs_add_attrs (specs
, attrs
);
2690 c_parser_declspecs (parser
, specs
, true, true, true);
2691 finish_declspecs (specs
);
2692 pending_xref_error ();
2693 prefix_attrs
= specs
->attrs
;
2694 specs
->attrs
= NULL_TREE
;
2695 declarator
= c_parser_declarator (parser
, specs
->type_seen_p
,
2696 C_DTR_PARM
, &dummy
);
2697 if (declarator
== NULL
)
2699 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
2702 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2703 postfix_attrs
= c_parser_attributes (parser
);
2704 return build_c_parm (specs
, chainon (postfix_attrs
, prefix_attrs
),
2708 /* Parse a string literal in an asm expression. It should not be
2709 translated, and wide string literals are an error although
2710 permitted by the syntax. This is a GNU extension.
2715 ??? At present, following the old parser, the caller needs to have
2716 set c_lex_string_translate to 0. It would be better to follow the
2717 C++ parser rather than using the c_lex_string_translate kludge. */
2720 c_parser_asm_string_literal (c_parser
*parser
)
2723 if (c_parser_next_token_is (parser
, CPP_STRING
))
2725 str
= c_parser_peek_token (parser
)->value
;
2726 c_parser_consume_token (parser
);
2728 else if (c_parser_next_token_is (parser
, CPP_WSTRING
))
2730 error ("wide string literal in %<asm%>");
2731 str
= build_string (1, "");
2732 c_parser_consume_token (parser
);
2736 c_parser_error (parser
, "expected string literal");
2742 /* Parse a simple asm expression. This is used in restricted
2743 contexts, where a full expression with inputs and outputs does not
2744 make sense. This is a GNU extension.
2747 asm ( asm-string-literal )
2751 c_parser_simple_asm_expr (c_parser
*parser
)
2754 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
2755 /* ??? Follow the C++ parser rather than using the
2756 c_lex_string_translate kludge. */
2757 c_lex_string_translate
= 0;
2758 c_parser_consume_token (parser
);
2759 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2761 c_lex_string_translate
= 1;
2764 str
= c_parser_asm_string_literal (parser
);
2765 c_lex_string_translate
= 1;
2766 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
2768 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2774 /* Parse (possibly empty) attributes. This is a GNU extension.
2778 attributes attribute
2781 __attribute__ ( ( attribute-list ) )
2785 attribute_list , attrib
2790 any-word ( identifier )
2791 any-word ( identifier , nonempty-expr-list )
2792 any-word ( expr-list )
2794 where the "identifier" must not be declared as a type, and
2795 "any-word" may be any identifier (including one declared as a
2796 type), a reserved word storage class specifier, type specifier or
2797 type qualifier. ??? This still leaves out most reserved keywords
2798 (following the old parser), shouldn't we include them, and why not
2799 allow identifiers declared as types to start the arguments? */
2802 c_parser_attributes (c_parser
*parser
)
2804 tree attrs
= NULL_TREE
;
2805 while (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2807 /* ??? Follow the C++ parser rather than using the
2808 c_lex_string_translate kludge. */
2809 c_lex_string_translate
= 0;
2810 c_parser_consume_token (parser
);
2811 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2813 c_lex_string_translate
= 1;
2816 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2818 c_lex_string_translate
= 1;
2819 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2822 /* Parse the attribute list. */
2823 while (c_parser_next_token_is (parser
, CPP_COMMA
)
2824 || c_parser_next_token_is (parser
, CPP_NAME
)
2825 || c_parser_next_token_is (parser
, CPP_KEYWORD
))
2827 tree attr
, attr_name
, attr_args
;
2828 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2830 c_parser_consume_token (parser
);
2833 if (c_parser_next_token_is (parser
, CPP_KEYWORD
))
2835 /* ??? See comment above about what keywords are
2838 switch (c_parser_peek_token (parser
)->keyword
)
2873 attr_name
= c_parser_peek_token (parser
)->value
;
2874 c_parser_consume_token (parser
);
2875 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
2877 attr
= build_tree_list (attr_name
, NULL_TREE
);
2878 attrs
= chainon (attrs
, attr
);
2881 c_parser_consume_token (parser
);
2882 /* Parse the attribute contents. If they start with an
2883 identifier which is followed by a comma or close
2884 parenthesis, then the arguments start with that
2885 identifier; otherwise they are an expression list. */
2886 if (c_parser_next_token_is (parser
, CPP_NAME
)
2887 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
2888 && ((c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
)
2889 || (c_parser_peek_2nd_token (parser
)->type
2890 == CPP_CLOSE_PAREN
)))
2892 tree arg1
= c_parser_peek_token (parser
)->value
;
2893 c_parser_consume_token (parser
);
2894 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2895 attr_args
= build_tree_list (NULL_TREE
, arg1
);
2898 c_parser_consume_token (parser
);
2899 attr_args
= tree_cons (NULL_TREE
, arg1
,
2900 c_parser_expr_list (parser
, false));
2905 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2906 attr_args
= NULL_TREE
;
2908 attr_args
= c_parser_expr_list (parser
, false);
2910 attr
= build_tree_list (attr_name
, attr_args
);
2911 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2912 c_parser_consume_token (parser
);
2915 c_lex_string_translate
= 1;
2916 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2920 attrs
= chainon (attrs
, attr
);
2922 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2923 c_parser_consume_token (parser
);
2926 c_lex_string_translate
= 1;
2927 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2931 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2932 c_parser_consume_token (parser
);
2935 c_lex_string_translate
= 1;
2936 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2940 c_lex_string_translate
= 1;
2945 /* Parse a type name (C90 6.5.5, C99 6.7.6).
2948 specifier-qualifier-list abstract-declarator[opt]
2951 static struct c_type_name
*
2952 c_parser_type_name (c_parser
*parser
)
2954 struct c_declspecs
*specs
= build_null_declspecs ();
2955 struct c_declarator
*declarator
;
2956 struct c_type_name
*ret
;
2958 c_parser_declspecs (parser
, specs
, false, true, true);
2959 if (!specs
->declspecs_seen_p
)
2961 c_parser_error (parser
, "expected specifier-qualifier-list");
2964 pending_xref_error ();
2965 finish_declspecs (specs
);
2966 declarator
= c_parser_declarator (parser
, specs
->type_seen_p
,
2967 C_DTR_ABSTRACT
, &dummy
);
2968 if (declarator
== NULL
)
2970 ret
= XOBNEW (&parser_obstack
, struct c_type_name
);
2972 ret
->declarator
= declarator
;
2976 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
2979 assignment-expression
2980 { initializer-list }
2981 { initializer-list , }
2984 designation[opt] initializer
2985 initializer-list , designation[opt] initializer
2992 designator-list designator
2999 [ constant-expression ]
3011 [ constant-expression ... constant-expression ]
3013 Any expression without commas is accepted in the syntax for the
3014 constant-expressions, with non-constant expressions rejected later.
3016 This function is only used for top-level initializers; for nested
3017 ones, see c_parser_initval. */
3019 static struct c_expr
3020 c_parser_initializer (c_parser
*parser
)
3022 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
3023 return c_parser_braced_init (parser
, NULL_TREE
, false);
3027 ret
= c_parser_expr_no_commas (parser
, NULL
);
3028 if (TREE_CODE (ret
.value
) != STRING_CST
3029 && TREE_CODE (ret
.value
) != COMPOUND_LITERAL_EXPR
)
3030 ret
= default_function_array_conversion (ret
);
3035 /* Parse a braced initializer list. TYPE is the type specified for a
3036 compound literal, and NULL_TREE for other initializers and for
3037 nested braced lists. NESTED_P is true for nested braced lists,
3038 false for the list of a compound literal or the list that is the
3039 top-level initializer in a declaration. */
3041 static struct c_expr
3042 c_parser_braced_init (c_parser
*parser
, tree type
, bool nested_p
)
3044 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
3045 c_parser_consume_token (parser
);
3047 push_init_level (0);
3049 really_start_incremental_init (type
);
3050 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3053 pedwarn ("ISO C forbids empty initializer braces");
3057 /* Parse a non-empty initializer list, possibly with a trailing
3061 c_parser_initelt (parser
);
3064 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3065 c_parser_consume_token (parser
);
3068 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3072 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
3075 ret
.value
= error_mark_node
;
3076 ret
.original_code
= ERROR_MARK
;
3077 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
3080 c_parser_consume_token (parser
);
3081 return pop_init_level (0);
3084 /* Parse a nested initializer, including designators. */
3087 c_parser_initelt (c_parser
*parser
)
3089 /* Parse any designator or designator list. A single array
3090 designator may have the subsequent "=" omitted in GNU C, but a
3091 longer list or a structure member designator may not. */
3092 if (c_parser_next_token_is (parser
, CPP_NAME
)
3093 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
3095 /* Old-style structure member designator. */
3096 set_init_label (c_parser_peek_token (parser
)->value
);
3098 pedwarn ("obsolete use of designated initializer with %<:%>");
3099 c_parser_consume_token (parser
);
3100 c_parser_consume_token (parser
);
3104 /* des_seen is 0 if there have been no designators, 1 if there
3105 has been a single array designator and 2 otherwise. */
3107 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
)
3108 || c_parser_next_token_is (parser
, CPP_DOT
))
3110 int des_prev
= des_seen
;
3113 if (c_parser_next_token_is (parser
, CPP_DOT
))
3116 c_parser_consume_token (parser
);
3117 if (c_parser_next_token_is (parser
, CPP_NAME
))
3119 set_init_label (c_parser_peek_token (parser
)->value
);
3120 c_parser_consume_token (parser
);
3125 init
.value
= error_mark_node
;
3126 init
.original_code
= ERROR_MARK
;
3127 c_parser_error (parser
, "expected identifier");
3128 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3129 process_init_element (init
);
3136 /* ??? Following the old parser, [ objc-receiver
3137 objc-message-args ] is accepted as an initializer,
3138 being distinguished from a designator by what follows
3139 the first assignment expression inside the square
3140 brackets, but after a first array designator a
3141 subsequent square bracket is for Objective-C taken to
3142 start an expression, using the obsolete form of
3143 designated initializer without '=', rather than
3144 possibly being a second level of designation: in LALR
3145 terms, the '[' is shifted rather than reducing
3146 designator to designator-list. */
3147 if (des_prev
== 1 && c_dialect_objc ())
3149 des_seen
= des_prev
;
3152 if (des_prev
== 0 && c_dialect_objc ())
3154 /* This might be an array designator or an
3155 Objective-C message expression. If the former,
3156 continue parsing here; if the latter, parse the
3157 remainder of the initializer given the starting
3158 primary-expression. ??? It might make sense to
3159 distinguish when des_prev == 1 as well; see
3160 previous comment. */
3162 struct c_expr mexpr
;
3163 c_parser_consume_token (parser
);
3164 if (c_parser_peek_token (parser
)->type
== CPP_NAME
3165 && ((c_parser_peek_token (parser
)->id_kind
3167 || (c_parser_peek_token (parser
)->id_kind
3168 == C_ID_CLASSNAME
)))
3170 /* Type name receiver. */
3171 tree id
= c_parser_peek_token (parser
)->value
;
3172 c_parser_consume_token (parser
);
3173 rec
= objc_get_class_reference (id
);
3174 goto parse_message_args
;
3176 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
3177 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
)
3178 || c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3179 goto array_desig_after_first
;
3180 /* Expression receiver. So far only one part
3181 without commas has been parsed; there might be
3182 more of the expression. */
3184 while (c_parser_next_token_is (parser
, CPP_COMMA
))
3187 c_parser_consume_token (parser
);
3188 next
= c_parser_expr_no_commas (parser
, NULL
);
3189 next
= default_function_array_conversion (next
);
3190 rec
= build_compound_expr (rec
, next
.value
);
3193 /* Now parse the objc-message-args. */
3194 args
= c_parser_objc_message_args (parser
);
3195 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3198 = objc_build_message_expr (build_tree_list (rec
, args
));
3199 mexpr
.original_code
= ERROR_MARK
;
3200 /* Now parse and process the remainder of the
3201 initializer, starting with this message
3202 expression as a primary-expression. */
3203 c_parser_initval (parser
, &mexpr
);
3206 c_parser_consume_token (parser
);
3207 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
3208 array_desig_after_first
:
3209 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3211 c_parser_consume_token (parser
);
3212 second
= c_parser_expr_no_commas (parser
, NULL
).value
;
3216 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3218 c_parser_consume_token (parser
);
3219 set_init_index (first
, second
);
3220 if (pedantic
&& second
)
3221 pedwarn ("ISO C forbids specifying range of "
3222 "elements to initialize");
3225 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3231 if (c_parser_next_token_is (parser
, CPP_EQ
))
3233 if (pedantic
&& !flag_isoc99
)
3234 pedwarn ("ISO C90 forbids specifying subobject to initialize");
3235 c_parser_consume_token (parser
);
3242 pedwarn ("obsolete use of designated initializer "
3248 init
.value
= error_mark_node
;
3249 init
.original_code
= ERROR_MARK
;
3250 c_parser_error (parser
, "expected %<=%>");
3251 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3252 process_init_element (init
);
3258 c_parser_initval (parser
, NULL
);
3261 /* Parse a nested initializer; as c_parser_initializer but parses
3262 initializers within braced lists, after any designators have been
3263 applied. If AFTER is not NULL then it is an Objective-C message
3264 expression which is the primary-expression starting the
3268 c_parser_initval (c_parser
*parser
, struct c_expr
*after
)
3271 gcc_assert (!after
|| c_dialect_objc ());
3272 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
) && !after
)
3273 init
= c_parser_braced_init (parser
, NULL_TREE
, true);
3276 init
= c_parser_expr_no_commas (parser
, after
);
3277 if (init
.value
!= NULL_TREE
3278 && TREE_CODE (init
.value
) != STRING_CST
3279 && TREE_CODE (init
.value
) != COMPOUND_LITERAL_EXPR
)
3280 init
= default_function_array_conversion (init
);
3282 process_init_element (init
);
3285 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
3289 { block-item-list[opt] }
3290 { label-declarations block-item-list }
3294 block-item-list block-item
3306 { label-declarations block-item-list }
3309 __extension__ nested-declaration
3310 nested-function-definition
3314 label-declarations label-declaration
3317 __label__ identifier-list ;
3319 Allowing the mixing of declarations and code is new in C99. The
3320 GNU syntax also permits (not shown above) labels at the end of
3321 compound statements, which yield an error. We don't allow labels
3322 on declarations; this might seem like a natural extension, but
3323 there would be a conflict between attributes on the label and
3324 prefix attributes on the declaration. ??? The syntax follows the
3325 old parser in requiring something after label declarations.
3326 Although they are erroneous if the labels declared aren't defined,
3327 is it useful for the syntax to be this way?
3339 c_parser_compound_statement (c_parser
*parser
)
3342 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
3343 return error_mark_node
;
3344 stmt
= c_begin_compound_stmt (true);
3345 c_parser_compound_statement_nostart (parser
);
3346 return c_end_compound_stmt (stmt
, true);
3349 /* Parse a compound statement except for the opening brace. This is
3350 used for parsing both compound statements and statement expressions
3351 (which follow different paths to handling the opening). */
3354 c_parser_compound_statement_nostart (c_parser
*parser
)
3356 bool last_stmt
= false;
3357 bool last_label
= false;
3358 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3360 c_parser_consume_token (parser
);
3363 if (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
3365 /* Read zero or more forward-declarations for labels that nested
3366 functions can jump to. */
3367 while (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
3369 c_parser_consume_token (parser
);
3370 /* Any identifiers, including those declared as type names,
3375 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
3377 c_parser_error (parser
, "expected identifier");
3381 = declare_label (c_parser_peek_token (parser
)->value
);
3382 C_DECLARED_LABEL_FLAG (label
) = 1;
3383 add_stmt (build_stmt (DECL_EXPR
, label
));
3384 c_parser_consume_token (parser
);
3385 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3386 c_parser_consume_token (parser
);
3390 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
3392 /* ??? Locating this diagnostic on the token after the
3393 declarations end follows the old parser, but it might be
3394 better to locate it where the declarations start instead. */
3396 pedwarn ("ISO C forbids label declarations");
3398 /* We must now have at least one statement, label or declaration. */
3399 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3401 c_parser_error (parser
, "expected declaration or statement");
3402 c_parser_consume_token (parser
);
3405 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
3407 location_t loc
= c_parser_peek_token (parser
)->location
;
3408 if (c_parser_next_token_is_keyword (parser
, RID_CASE
)
3409 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
3410 || (c_parser_next_token_is (parser
, CPP_NAME
)
3411 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
3415 c_parser_label (parser
);
3417 else if (!last_label
3418 && c_parser_next_token_starts_declspecs (parser
))
3421 c_parser_declaration_or_fndef (parser
, true, true, true, true);
3423 && ((pedantic
&& !flag_isoc99
)
3424 || warn_declaration_after_statement
))
3425 pedwarn_c90 ("%HISO C90 forbids mixed declarations and code",
3429 else if (!last_label
3430 && c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
3432 /* __extension__ can start a declaration, but is also an
3433 unary operator that can start an expression. Consume all
3434 but the last of a possible series of __extension__ to
3436 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
3437 && (c_parser_peek_2nd_token (parser
)->keyword
3439 c_parser_consume_token (parser
);
3440 if (c_token_starts_declspecs (c_parser_peek_2nd_token (parser
)))
3443 ext
= disable_extension_diagnostics ();
3444 c_parser_consume_token (parser
);
3446 c_parser_declaration_or_fndef (parser
, true, true, true, true);
3447 /* Following the old parser, __extension__ does not
3448 disable this diagnostic. */
3449 restore_extension_diagnostics (ext
);
3451 && ((pedantic
&& !flag_isoc99
)
3452 || warn_declaration_after_statement
))
3453 pedwarn_c90 ("%HISO C90 forbids mixed declarations and code",
3460 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
3462 /* External pragmas, and some omp pragmas, are not associated
3463 with regular c code, and so are not to be considered statements
3464 syntactically. This ensures that the user doesn't put them
3465 places that would turn into syntax errors if the directive
3467 if (c_parser_pragma (parser
, pragma_compound
))
3468 last_label
= false, last_stmt
= true;
3470 else if (c_parser_next_token_is (parser
, CPP_EOF
))
3472 c_parser_error (parser
, "expected declaration or statement");
3480 c_parser_statement_after_labels (parser
);
3483 parser
->error
= false;
3486 error ("label at end of compound statement");
3487 c_parser_consume_token (parser
);
3490 /* Parse a label (C90 6.6.1, C99 6.8.1).
3493 identifier : attributes[opt]
3494 case constant-expression :
3500 case constant-expression ... constant-expression :
3502 The use of attributes on labels is a GNU extension. The syntax in
3503 GNU C accepts any expressions without commas, non-constant
3504 expressions being rejected later. */
3507 c_parser_label (c_parser
*parser
)
3509 location_t loc1
= c_parser_peek_token (parser
)->location
;
3510 tree label
= NULL_TREE
;
3511 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
3514 c_parser_consume_token (parser
);
3515 exp1
= c_parser_expr_no_commas (parser
, NULL
).value
;
3516 if (c_parser_next_token_is (parser
, CPP_COLON
))
3518 c_parser_consume_token (parser
);
3519 label
= do_case (exp1
, NULL_TREE
);
3521 else if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3523 c_parser_consume_token (parser
);
3524 exp2
= c_parser_expr_no_commas (parser
, NULL
).value
;
3525 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
3526 label
= do_case (exp1
, exp2
);
3529 c_parser_error (parser
, "expected %<:%> or %<...%>");
3531 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
3533 c_parser_consume_token (parser
);
3534 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
3535 label
= do_case (NULL_TREE
, NULL_TREE
);
3539 tree name
= c_parser_peek_token (parser
)->value
;
3543 gcc_assert (c_parser_next_token_is (parser
, CPP_NAME
));
3544 c_parser_consume_token (parser
);
3545 gcc_assert (c_parser_next_token_is (parser
, CPP_COLON
));
3546 loc2
= c_parser_peek_token (parser
)->location
;
3547 c_parser_consume_token (parser
);
3548 attrs
= c_parser_attributes (parser
);
3549 tlab
= define_label (loc2
, name
);
3552 decl_attributes (&tlab
, attrs
, 0);
3553 label
= add_stmt (build_stmt (LABEL_EXPR
, tlab
));
3557 SET_EXPR_LOCATION (label
, loc1
);
3560 /* Parse a statement (C90 6.6, C99 6.8).
3565 expression-statement
3573 expression-statement:
3576 selection-statement:
3580 iteration-statement:
3589 return expression[opt] ;
3602 objc-throw-statement
3603 objc-try-catch-statement
3604 objc-synchronized-statement
3606 objc-throw-statement:
3620 parallel-for-construct
3621 parallel-sections-construct
3628 parallel-directive structured-block
3631 for-directive iteration-statement
3634 sections-directive section-scope
3637 single-directive structured-block
3639 parallel-for-construct:
3640 parallel-for-directive iteration-statement
3642 parallel-sections-construct:
3643 parallel-sections-directive section-scope
3646 master-directive structured-block
3649 critical-directive structured-block
3652 atomic-directive expression-statement
3655 ordered-directive structured-block */
3658 c_parser_statement (c_parser
*parser
)
3660 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
3661 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
3662 || (c_parser_next_token_is (parser
, CPP_NAME
)
3663 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
3664 c_parser_label (parser
);
3665 c_parser_statement_after_labels (parser
);
3668 /* Parse a statement, other than a labeled statement. */
3671 c_parser_statement_after_labels (c_parser
*parser
)
3673 location_t loc
= c_parser_peek_token (parser
)->location
;
3674 tree stmt
= NULL_TREE
;
3675 switch (c_parser_peek_token (parser
)->type
)
3677 case CPP_OPEN_BRACE
:
3678 add_stmt (c_parser_compound_statement (parser
));
3681 switch (c_parser_peek_token (parser
)->keyword
)
3684 c_parser_if_statement (parser
);
3687 c_parser_switch_statement (parser
);
3690 c_parser_while_statement (parser
);
3693 c_parser_do_statement (parser
);
3696 c_parser_for_statement (parser
);
3699 c_parser_consume_token (parser
);
3700 if (c_parser_next_token_is (parser
, CPP_NAME
))
3702 stmt
= c_finish_goto_label (c_parser_peek_token (parser
)->value
);
3703 c_parser_consume_token (parser
);
3705 else if (c_parser_next_token_is (parser
, CPP_MULT
))
3707 c_parser_consume_token (parser
);
3708 stmt
= c_finish_goto_ptr (c_parser_expression (parser
).value
);
3711 c_parser_error (parser
, "expected identifier or %<*%>");
3712 goto expect_semicolon
;
3714 c_parser_consume_token (parser
);
3715 stmt
= c_finish_bc_stmt (&c_cont_label
, false);
3716 goto expect_semicolon
;
3718 c_parser_consume_token (parser
);
3719 stmt
= c_finish_bc_stmt (&c_break_label
, true);
3720 goto expect_semicolon
;
3722 c_parser_consume_token (parser
);
3723 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3725 stmt
= c_finish_return (NULL_TREE
);
3726 c_parser_consume_token (parser
);
3730 stmt
= c_finish_return (c_parser_expression_conv (parser
).value
);
3731 goto expect_semicolon
;
3735 stmt
= c_parser_asm_statement (parser
);
3738 gcc_assert (c_dialect_objc ());
3739 c_parser_consume_token (parser
);
3740 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3742 stmt
= objc_build_throw_stmt (NULL_TREE
);
3743 c_parser_consume_token (parser
);
3748 = objc_build_throw_stmt (c_parser_expression (parser
).value
);
3749 goto expect_semicolon
;
3753 gcc_assert (c_dialect_objc ());
3754 c_parser_objc_try_catch_statement (parser
);
3756 case RID_AT_SYNCHRONIZED
:
3757 gcc_assert (c_dialect_objc ());
3758 c_parser_objc_synchronized_statement (parser
);
3765 c_parser_consume_token (parser
);
3767 case CPP_CLOSE_PAREN
:
3768 case CPP_CLOSE_SQUARE
:
3769 /* Avoid infinite loop in error recovery:
3770 c_parser_skip_until_found stops at a closing nesting
3771 delimiter without consuming it, but here we need to consume
3772 it to proceed further. */
3773 c_parser_error (parser
, "expected statement");
3774 c_parser_consume_token (parser
);
3777 c_parser_pragma (parser
, pragma_stmt
);
3781 stmt
= c_finish_expr_stmt (c_parser_expression_conv (parser
).value
);
3783 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
3786 /* Two cases cannot and do not have line numbers associated: If stmt
3787 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
3788 cannot hold line numbers. But that's OK because the statement
3789 will either be changed to a MODIFY_EXPR during gimplification of
3790 the statement expr, or discarded. If stmt was compound, but
3791 without new variables, we will have skipped the creation of a
3792 BIND and will have a bare STATEMENT_LIST. But that's OK because
3793 (recursively) all of the component statements should already have
3794 line numbers assigned. ??? Can we discard no-op statements
3796 if (stmt
&& CAN_HAVE_LOCATION_P (stmt
))
3797 SET_EXPR_LOCATION (stmt
, loc
);
3800 /* Parse a parenthesized condition from an if, do or while statement.
3806 c_parser_paren_condition (c_parser
*parser
)
3810 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3811 return error_mark_node
;
3812 loc
= c_parser_peek_token (parser
)->location
;
3813 cond
= c_objc_common_truthvalue_conversion
3814 (c_parser_expression_conv (parser
).value
);
3815 if (CAN_HAVE_LOCATION_P (cond
))
3816 SET_EXPR_LOCATION (cond
, loc
);
3817 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
3821 /* Parse a statement which is a block in C99. */
3824 c_parser_c99_block_statement (c_parser
*parser
)
3826 tree block
= c_begin_compound_stmt (flag_isoc99
);
3827 c_parser_statement (parser
);
3828 return c_end_compound_stmt (block
, flag_isoc99
);
3831 /* Parse the body of an if statement or the else half thereof. This
3832 is just parsing a statement but (a) it is a block in C99, (b) we
3833 track whether the body is an if statement for the sake of
3834 -Wparentheses warnings, (c) we handle an empty body specially for
3835 the sake of -Wempty-body warnings. */
3838 c_parser_if_body (c_parser
*parser
, bool *if_p
)
3840 tree block
= c_begin_compound_stmt (flag_isoc99
);
3841 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
3842 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
3843 || (c_parser_next_token_is (parser
, CPP_NAME
)
3844 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
3845 c_parser_label (parser
);
3846 *if_p
= c_parser_next_token_is_keyword (parser
, RID_IF
);
3847 if (warn_empty_body
&& c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3848 add_stmt (build_empty_stmt ());
3849 c_parser_statement_after_labels (parser
);
3850 return c_end_compound_stmt (block
, flag_isoc99
);
3853 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
3856 if ( expression ) statement
3857 if ( expression ) statement else statement
3861 c_parser_if_statement (c_parser
*parser
)
3866 bool first_if
= false, second_if
= false;
3867 tree first_body
, second_body
;
3868 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_IF
));
3869 c_parser_consume_token (parser
);
3870 block
= c_begin_compound_stmt (flag_isoc99
);
3871 loc
= c_parser_peek_token (parser
)->location
;
3872 cond
= c_parser_paren_condition (parser
);
3873 first_body
= c_parser_if_body (parser
, &first_if
);
3874 if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
3876 c_parser_consume_token (parser
);
3877 second_body
= c_parser_if_body (parser
, &second_if
);
3880 second_body
= NULL_TREE
;
3881 c_finish_if_stmt (loc
, cond
, first_body
, second_body
, first_if
);
3882 add_stmt (c_end_compound_stmt (block
, flag_isoc99
));
3885 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
3888 switch (expression) statement
3892 c_parser_switch_statement (c_parser
*parser
)
3894 tree block
, expr
, body
, save_break
;
3895 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SWITCH
));
3896 c_parser_consume_token (parser
);
3897 block
= c_begin_compound_stmt (flag_isoc99
);
3898 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3900 expr
= c_parser_expression (parser
).value
;
3901 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
3904 expr
= error_mark_node
;
3905 c_start_case (expr
);
3906 save_break
= c_break_label
;
3907 c_break_label
= NULL_TREE
;
3908 body
= c_parser_c99_block_statement (parser
);
3909 c_finish_case (body
);
3911 add_stmt (build1 (LABEL_EXPR
, void_type_node
, c_break_label
));
3912 c_break_label
= save_break
;
3913 add_stmt (c_end_compound_stmt (block
, flag_isoc99
));
3916 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
3919 while (expression) statement
3923 c_parser_while_statement (c_parser
*parser
)
3925 tree block
, cond
, body
, save_break
, save_cont
;
3927 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_WHILE
));
3928 c_parser_consume_token (parser
);
3929 block
= c_begin_compound_stmt (flag_isoc99
);
3930 loc
= c_parser_peek_token (parser
)->location
;
3931 cond
= c_parser_paren_condition (parser
);
3932 save_break
= c_break_label
;
3933 c_break_label
= NULL_TREE
;
3934 save_cont
= c_cont_label
;
3935 c_cont_label
= NULL_TREE
;
3936 body
= c_parser_c99_block_statement (parser
);
3937 c_finish_loop (loc
, cond
, NULL
, body
, c_break_label
, c_cont_label
, true);
3938 add_stmt (c_end_compound_stmt (block
, flag_isoc99
));
3939 c_break_label
= save_break
;
3940 c_cont_label
= save_cont
;
3943 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
3946 do statement while ( expression ) ;
3950 c_parser_do_statement (c_parser
*parser
)
3952 tree block
, cond
, body
, save_break
, save_cont
, new_break
, new_cont
;
3954 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_DO
));
3955 c_parser_consume_token (parser
);
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 objc_pq_context
= 1;
5908 objc_start_protocol (id
, proto
);
5909 c_parser_objc_methodprotolist (parser
);
5910 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
5911 objc_pq_context
= 0;
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 objc_pq_context
= 1;
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 objc_pq_context
= 0;
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 objc_pq_context
= 1;
6029 decl
= c_parser_objc_method_decl (parser
);
6030 /* Forget protocol qualifiers here. */
6031 objc_pq_context
= 0;
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 if (!targetm
.have_tls
)
7787 sorry ("threadprivate variables not supported in this target");
7789 /* Mark every variable in VARS to be assigned thread local storage. */
7790 for (t
= vars
; t
; t
= TREE_CHAIN (t
))
7792 tree v
= TREE_PURPOSE (t
);
7794 /* If V had already been marked threadprivate, it doesn't matter
7795 whether it had been used prior to this point. */
7796 if (TREE_USED (v
) && !C_DECL_THREADPRIVATE_P (v
))
7797 error ("%qE declared %<threadprivate%> after first use", v
);
7798 else if (! TREE_STATIC (v
) && ! DECL_EXTERNAL (v
))
7799 error ("automatic variable %qE cannot be %<threadprivate%>", v
);
7800 else if (! COMPLETE_TYPE_P (TREE_TYPE (v
)))
7801 error ("%<threadprivate%> %qE has incomplete type", v
);
7804 if (! DECL_THREAD_LOCAL_P (v
))
7806 DECL_TLS_MODEL (v
) = decl_default_tls_model (v
);
7807 /* If rtl has been already set for this var, call
7808 make_decl_rtl once again, so that encode_section_info
7809 has a chance to look at the new decl flags. */
7810 if (DECL_RTL_SET_P (v
))
7813 C_DECL_THREADPRIVATE_P (v
) = 1;
7817 c_parser_skip_to_pragma_eol (parser
);
7821 /* Parse a single source file. */
7826 /* Use local storage to begin. If the first token is a pragma, parse it.
7827 If it is #pragma GCC pch_preprocess, then this will load a PCH file
7828 which will cause garbage collection. */
7831 memset (&tparser
, 0, sizeof tparser
);
7832 the_parser
= &tparser
;
7834 if (c_parser_peek_token (&tparser
)->pragma_kind
== PRAGMA_GCC_PCH_PREPROCESS
)
7835 c_parser_pragma_pch_preprocess (&tparser
);
7837 the_parser
= GGC_NEW (c_parser
);
7838 *the_parser
= tparser
;
7840 c_parser_translation_unit (the_parser
);
7844 #include "gt-c-parser.h"